1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_USER_CONTROLLER_H_ 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_USER_CONTROLLER_H_ 7 #pragma once 8 9 #include <string> 10 11 #include "base/compiler_specific.h" 12 #include "base/string16.h" 13 #include "base/task.h" 14 #include "chrome/browser/chromeos/login/new_user_view.h" 15 #include "chrome/browser/chromeos/login/user_manager.h" 16 #include "chrome/browser/chromeos/login/user_view.h" 17 #include "chrome/browser/chromeos/wm_ipc.h" 18 #include "testing/gtest/include/gtest/gtest_prod.h" 19 #include "views/controls/button/button.h" 20 #include "views/controls/textfield/textfield.h" 21 #include "views/widget/widget_delegate.h" 22 23 namespace views { 24 class WidgetGtk; 25 } 26 27 namespace chromeos { 28 29 class ThrobberManager; 30 31 // UserController manages the set of windows needed to login a single existing 32 // user or first time login for a new user. ExistingUserController creates 33 // the nececessary set of UserControllers. 34 class UserController : public views::WidgetDelegate, 35 public NewUserView::Delegate, 36 public UserView::Delegate { 37 public: 38 class Delegate { 39 public: 40 virtual void CreateAccount() = 0; 41 virtual void Login(UserController* source, 42 const string16& password) = 0; 43 virtual void LoginAsGuest() = 0; 44 virtual void ClearErrors() = 0; 45 virtual void OnUserSelected(UserController* source) = 0; 46 virtual void RemoveUser(UserController* source) = 0; 47 48 // Selects user entry with specified |index|. 49 // Does nothing if current user is already selected. 50 virtual void SelectUser(int index) = 0; 51 52 // Switch to the enterprise enrollment screen (if applicable). 53 virtual void StartEnterpriseEnrollment() = 0; 54 55 protected: 56 virtual ~Delegate() {} 57 }; 58 59 // Creates a UserController representing new user or guest login. 60 UserController(Delegate* delegate, bool is_guest); 61 62 // Creates a UserController for the specified user. 63 UserController(Delegate* delegate, const UserManager::User& user); 64 65 ~UserController(); 66 67 // Initializes the UserController, creating the set of windows/controls. 68 // |index| is the index of this user, and |total_user_count| the total 69 // number of users. 70 void Init(int index, int total_user_count, bool need_browse_without_signin); 71 72 int user_index() const { return user_index_; } 73 bool is_new_user() const { return is_new_user_; } 74 bool is_guest() const { return is_guest_; } 75 bool is_owner() const { return is_owner_; } 76 77 const UserManager::User& user() const { return user_; } 78 79 // Get widget that contains all controls. 80 views::WidgetGtk* controls_window() { 81 return controls_window_; 82 } 83 84 // Called when user view is activated (OnUserSelected). 85 void ClearAndEnableFields(); 86 87 // Called when user view is activated (OnUserSelected). 88 void ClearAndEnablePassword(); 89 90 // Enables or disables tooltip with user's email. 91 void EnableNameTooltip(bool enable); 92 93 // Called when user image has been changed. 94 void OnUserImageChanged(UserManager::User* user); 95 96 // Returns bounds of the main input field in the screen coordinates (e.g. 97 // these bounds could be used to choose positions for the error bubble). 98 gfx::Rect GetMainInputScreenBounds() const; 99 100 // Selects user relative to the current user. 101 void SelectUserRelative(int shift); 102 103 // Starts/Stops throbber. 104 void StartThrobber(); 105 void StopThrobber(); 106 107 // Update border window parameters to notify window manager about new numbers. 108 // |index| of this user and |total_user_count| of users. 109 void UpdateUserCount(int index, int total_user_count); 110 111 // Returns the label for the user which should be spoken when accessibility is 112 // enabled. 113 std::string GetAccessibleUserLabel(); 114 115 // views::WidgetDelegate implementation: 116 virtual void OnWidgetActivated(bool active) OVERRIDE; 117 118 // NewUserView::Delegate implementation: 119 virtual void OnLogin(const std::string& username, 120 const std::string& password) OVERRIDE; 121 virtual void OnLoginAsGuest() OVERRIDE; 122 virtual void OnCreateAccount() OVERRIDE; 123 virtual void OnStartEnterpriseEnrollment() OVERRIDE; 124 virtual void ClearErrors() OVERRIDE; 125 virtual void NavigateAway() OVERRIDE; 126 127 // UserView::Delegate implementation: 128 virtual void OnRemoveUser() OVERRIDE; 129 virtual bool IsUserSelected() const OVERRIDE { return is_user_selected_; } 130 131 // UsernameView::Delegate implementation: 132 virtual void OnLocaleChanged() OVERRIDE; 133 134 // Padding between the user windows. 135 static const int kPadding; 136 137 // Max size needed when an entry is not selected. 138 static const int kUnselectedSize; 139 static const int kNewUserUnselectedSize; 140 141 private: 142 FRIEND_TEST(UserControllerTest, GetNameTooltip); 143 144 // Performs common setup for login windows. 145 void ConfigureLoginWindow(views::WidgetGtk* window, 146 int index, 147 const gfx::Rect& bounds, 148 chromeos::WmIpcWindowType type, 149 views::View* contents_view); 150 views::WidgetGtk* CreateControlsWindow(int index, 151 int* width, int* height, 152 bool need_guest_link); 153 views::WidgetGtk* CreateImageWindow(int index); 154 views::WidgetGtk* CreateLabelWindow(int index, WmIpcWindowType type); 155 gfx::Font GetLabelFont(); 156 gfx::Font GetUnselectedLabelFont(); 157 void CreateBorderWindow(int index, 158 int total_user_count, 159 int controls_width, int controls_height); 160 161 // Returns tooltip text for user name. 162 std::wstring GetNameTooltip() const; 163 164 // User index within all the users. 165 int user_index_; 166 167 // Is this user selected now? 168 bool is_user_selected_; 169 170 // Is this the new user pod? 171 const bool is_new_user_; 172 173 // Is this the guest pod? 174 const bool is_guest_; 175 176 // Is this user the owner? 177 const bool is_owner_; 178 179 // Should we show tooltips above user image and label to help distinguish 180 // users with the same display name. 181 bool show_name_tooltip_; 182 183 // If is_new_user_ and is_guest_ are false, this is the user being shown. 184 UserManager::User user_; 185 186 Delegate* delegate_; 187 188 // A window is used to represent the individual chunks. 189 views::WidgetGtk* controls_window_; 190 views::WidgetGtk* image_window_; 191 views::Widget* border_window_; 192 views::WidgetGtk* label_window_; 193 views::WidgetGtk* unselected_label_window_; 194 195 // View that shows user image on image window. 196 UserView* user_view_; 197 198 // Views that show display name of the user. 199 views::Label* label_view_; 200 views::Label* unselected_label_view_; 201 202 // Input controls which are used for username and password. 203 UserInput* user_input_; 204 205 // Throbber host that can show a throbber. 206 ThrobberHostView* throbber_host_; 207 208 // Whether name tooltip is enabled. 209 bool name_tooltip_enabled_; 210 211 DISALLOW_COPY_AND_ASSIGN(UserController); 212 }; 213 214 } // namespace chromeos 215 216 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_USER_CONTROLLER_H_ 217