OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_USER_CONTROLLER_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_USER_CONTROLLER_H_ |
6 #define CHROME_BROWSER_CHROMEOS_LOGIN_USER_CONTROLLER_H_ | 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_USER_CONTROLLER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/string16.h" | 11 #include "base/string16.h" |
12 #include "base/task.h" | 12 #include "base/task.h" |
13 #include "chrome/browser/chromeos/login/new_user_view.h" | 13 #include "chrome/browser/chromeos/login/new_user_view.h" |
14 #include "chrome/browser/chromeos/login/user_manager.h" | 14 #include "chrome/browser/chromeos/login/user_manager.h" |
15 #include "chrome/browser/chromeos/login/user_view.h" | 15 #include "chrome/browser/chromeos/login/user_view.h" |
16 #include "chrome/browser/chromeos/wm_ipc.h" | 16 #include "chrome/browser/chromeos/wm_ipc.h" |
17 #include "chrome/common/notification_observer.h" | 17 #include "chrome/common/notification_observer.h" |
18 #include "chrome/common/notification_registrar.h" | 18 #include "chrome/common/notification_registrar.h" |
19 #include "testing/gtest/include/gtest/gtest_prod.h" | 19 #include "testing/gtest/include/gtest/gtest_prod.h" |
20 #include "views/controls/button/button.h" | 20 #include "views/controls/button/button.h" |
21 #include "views/controls/textfield/textfield.h" | 21 #include "views/controls/textfield/textfield.h" |
22 #include "views/widget/widget_delegate.h" | 22 #include "views/widget/widget_delegate.h" |
23 namespace views { | 23 namespace views { |
24 class WidgetGtk; | 24 class WidgetGtk; |
25 } | 25 } |
26 | 26 |
27 namespace chromeos { | 27 namespace chromeos { |
28 | 28 |
29 class ExistingUserView; | 29 class ThrobberManager; |
30 class GuestUserView; | |
31 class UserView; | |
32 | 30 |
33 // UserController manages the set of windows needed to login a single existing | 31 // UserController manages the set of windows needed to login a single existing |
34 // user or first time login for a new user. ExistingUserController creates | 32 // user or first time login for a new user. ExistingUserController creates |
35 // the nececessary set of UserControllers. | 33 // the nececessary set of UserControllers. |
36 class UserController : public views::ButtonListener, | 34 class UserController : public views::WidgetDelegate, |
37 public views::Textfield::Controller, | |
38 public views::WidgetDelegate, | |
39 public NewUserView::Delegate, | 35 public NewUserView::Delegate, |
40 public NotificationObserver, | 36 public NotificationObserver, |
41 public UserView::Delegate { | 37 public UserView::Delegate { |
42 public: | 38 public: |
43 class Delegate { | 39 class Delegate { |
44 public: | 40 public: |
45 virtual void Login(UserController* source, | 41 virtual void Login(UserController* source, |
46 const string16& password) = 0; | 42 const string16& password) = 0; |
47 virtual void LoginOffTheRecord() = 0; | 43 virtual void LoginOffTheRecord() = 0; |
48 virtual void ClearErrors() = 0; | 44 virtual void ClearErrors() = 0; |
(...skipping 24 matching lines...) Expand all Loading... |
73 void Init(int index, int total_user_count, bool need_browse_without_signin); | 69 void Init(int index, int total_user_count, bool need_browse_without_signin); |
74 | 70 |
75 // Update border window parameters to notify window manager about new numbers. | 71 // Update border window parameters to notify window manager about new numbers. |
76 // |index| of this user and |total_user_count| of users. | 72 // |index| of this user and |total_user_count| of users. |
77 void UpdateUserCount(int index, int total_user_count); | 73 void UpdateUserCount(int index, int total_user_count); |
78 | 74 |
79 int user_index() const { return user_index_; } | 75 int user_index() const { return user_index_; } |
80 bool is_user_selected() const { return is_user_selected_; } | 76 bool is_user_selected() const { return is_user_selected_; } |
81 bool is_new_user() const { return is_new_user_; } | 77 bool is_new_user() const { return is_new_user_; } |
82 bool is_guest() const { return is_guest_; } | 78 bool is_guest() const { return is_guest_; } |
83 NewUserView* new_user_view() const { return new_user_view_; } | |
84 | 79 |
85 const UserManager::User& user() const { return user_; } | 80 const UserManager::User& user() const { return user_; } |
86 | 81 |
87 // Enables or disables tooltip with user's email. | 82 // Enables or disables tooltip with user's email. |
88 void EnableNameTooltip(bool enable); | 83 void EnableNameTooltip(bool enable); |
89 | 84 |
90 // Resets password text and sets the enabled state of the password. | |
91 void ClearAndEnablePassword(); | |
92 | |
93 // Called when user view is activated (OnUserSelected). | 85 // Called when user view is activated (OnUserSelected). |
94 void ClearAndEnableFields(); | 86 void ClearAndEnableFields(); |
95 | 87 |
96 // Returns bounds of password field in screen coordinates. | 88 // Called when user view is activated (OnUserSelected). |
97 // For new user it returns username coordinates. | 89 void ClearAndEnablePassword(); |
98 gfx::Rect GetScreenBounds() const; | |
99 | 90 |
100 // Get widget that contains all controls. | 91 // Get widget that contains all controls. |
101 views::WidgetGtk* controls_window() { | 92 views::WidgetGtk* controls_window() { |
102 return controls_window_; | 93 return controls_window_; |
103 } | 94 } |
104 | 95 |
105 // ButtonListener: | 96 // Returns bounds of the main input field in the screen coordinates (e.g. |
106 virtual void ButtonPressed(views::Button* sender, const views::Event& event); | 97 // these bounds could be used to choose positions for the error bubble). |
| 98 gfx::Rect GetMainInputScreenBounds() const; |
107 | 99 |
108 // Textfield::Controller: | 100 // Starts/Stops throbber. |
109 virtual void ContentsChanged(views::Textfield* sender, | 101 void StartThrobber(); |
110 const string16& new_contents); | 102 void StopThrobber(); |
111 virtual bool HandleKeystroke(views::Textfield* sender, | |
112 const views::Textfield::Keystroke& keystroke); | |
113 | 103 |
114 // views::WidgetDelegate: | 104 // views::WidgetDelegate: |
115 virtual void IsActiveChanged(bool active); | 105 virtual void IsActiveChanged(bool active); |
116 | 106 |
117 // NotificationObserver implementation. | 107 // NotificationObserver implementation. |
118 virtual void Observe(NotificationType type, | 108 virtual void Observe(NotificationType type, |
119 const NotificationSource& source, | 109 const NotificationSource& source, |
120 const NotificationDetails& details); | 110 const NotificationDetails& details); |
121 | 111 |
122 // NewUserView::Delegate | 112 // NewUserView::Delegate |
123 virtual void OnLogin(const std::string& username, | 113 virtual void OnLogin(const std::string& username, |
124 const std::string& password); | 114 const std::string& password); |
125 virtual void OnCreateAccount(); | 115 virtual void OnCreateAccount(); |
126 virtual void OnLoginOffTheRecord(); | 116 virtual void OnLoginOffTheRecord(); |
127 virtual void AddStartUrl(const GURL& start_url) { | 117 virtual void AddStartUrl(const GURL& start_url) { |
128 delegate_->AddStartUrl(start_url); | 118 delegate_->AddStartUrl(start_url); |
129 } | 119 } |
130 virtual void ClearErrors(); | 120 virtual void ClearErrors(); |
131 virtual void NavigateAway(); | 121 virtual void NavigateAway(); |
132 virtual void SetStatusAreaEnabled(bool enable) { | 122 virtual void SetStatusAreaEnabled(bool enable) { |
133 delegate_->SetStatusAreaEnabled(enable); | 123 delegate_->SetStatusAreaEnabled(enable); |
134 } | 124 } |
135 | 125 |
136 // UserView::Delegate implementation: | 126 // UserView::Delegate implementation: |
137 virtual void OnRemoveUser(); | 127 virtual void OnRemoveUser(); |
138 | 128 |
139 // Selects user entry with specified |index|. | 129 // Selects user relative to the current user. |
140 void SelectUser(int index); | 130 void SelectUserRelative(int shift); |
141 | |
142 // Sets focus on password field. | |
143 void FocusPasswordField(); | |
144 | 131 |
145 // Padding between the user windows. | 132 // Padding between the user windows. |
146 static const int kPadding; | 133 static const int kPadding; |
147 | 134 |
148 // Max size needed when an entry is not selected. | 135 // Max size needed when an entry is not selected. |
149 static const int kUnselectedSize; | 136 static const int kUnselectedSize; |
150 static const int kNewUserUnselectedSize; | 137 static const int kNewUserUnselectedSize; |
151 | 138 |
152 private: | 139 private: |
153 FRIEND_TEST(UserControllerTest, GetNameTooltip); | 140 FRIEND_TEST(UserControllerTest, GetNameTooltip); |
154 | 141 |
155 // Invoked when the user wants to login. Forwards the call to the delegate. | |
156 void Login(); | |
157 | |
158 // Performs common setup for login windows. | 142 // Performs common setup for login windows. |
159 void ConfigureLoginWindow(views::WidgetGtk* window, | 143 void ConfigureLoginWindow(views::WidgetGtk* window, |
160 int index, | 144 int index, |
161 const gfx::Rect& bounds, | 145 const gfx::Rect& bounds, |
162 chromeos::WmIpcWindowType type, | 146 chromeos::WmIpcWindowType type, |
163 views::View* contents_view); | 147 views::View* contents_view); |
164 views::WidgetGtk* CreateControlsWindow(int index, | 148 views::WidgetGtk* CreateControlsWindow(int index, |
165 int* width, int* height, | 149 int* width, int* height, |
166 bool need_guest_link); | 150 bool need_guest_link); |
167 views::WidgetGtk* CreateImageWindow(int index); | 151 views::WidgetGtk* CreateImageWindow(int index); |
168 views::WidgetGtk* CreateLabelWindow(int index, WmIpcWindowType type); | 152 views::WidgetGtk* CreateLabelWindow(int index, WmIpcWindowType type); |
169 void CreateBorderWindow(int index, | 153 void CreateBorderWindow(int index, |
170 int total_user_count, | 154 int total_user_count, |
171 int controls_width, int controls_height); | 155 int controls_width, int controls_height); |
172 | 156 |
173 // Sets specified image on the image window. If image's size is less than | 157 // Sets specified image on the image window. If image's size is less than |
174 // 75% of window size, image size is preserved to avoid blur. Otherwise, | 158 // 75% of window size, image size is preserved to avoid blur. Otherwise, |
175 // the image is resized to fit window size precisely. Image view repaints | 159 // the image is resized to fit window size precisely. Image view repaints |
176 // itself. | 160 // itself. |
177 void SetImage(const SkBitmap& image); | 161 void SetImage(const SkBitmap& image); |
178 | 162 |
179 // Sets the enabled state of the password field to |enable|. | |
180 void SetPasswordEnabled(bool enable); | |
181 | |
182 // Returns tooltip text for user name. | 163 // Returns tooltip text for user name. |
183 std::wstring GetNameTooltip() const; | 164 std::wstring GetNameTooltip() const; |
184 | 165 |
185 // User index within all the users. | 166 // User index within all the users. |
186 int user_index_; | 167 int user_index_; |
187 | 168 |
188 // Is this user selected now? | 169 // Is this user selected now? |
189 bool is_user_selected_; | 170 bool is_user_selected_; |
190 | 171 |
191 // Is this the new user pod? | 172 // Is this the new user pod? |
(...skipping 17 matching lines...) Expand all Loading... |
209 // A window is used to represent the individual chunks. | 190 // A window is used to represent the individual chunks. |
210 views::WidgetGtk* controls_window_; | 191 views::WidgetGtk* controls_window_; |
211 views::WidgetGtk* image_window_; | 192 views::WidgetGtk* image_window_; |
212 views::WidgetGtk* border_window_; | 193 views::WidgetGtk* border_window_; |
213 views::WidgetGtk* label_window_; | 194 views::WidgetGtk* label_window_; |
214 views::WidgetGtk* unselected_label_window_; | 195 views::WidgetGtk* unselected_label_window_; |
215 | 196 |
216 // View that shows user image on image window. | 197 // View that shows user image on image window. |
217 UserView* user_view_; | 198 UserView* user_view_; |
218 | 199 |
219 // View that is used for new user login. | |
220 NewUserView* new_user_view_; | |
221 | |
222 // View that is used for existing user login. | |
223 ExistingUserView* existing_user_view_; | |
224 | |
225 // View that is used for guest user login. | |
226 GuestUserView* guest_user_view_; | |
227 | |
228 // Views that show display name of the user. | 200 // Views that show display name of the user. |
229 views::Label* label_view_; | 201 views::Label* label_view_; |
230 views::Label* unselected_label_view_; | 202 views::Label* unselected_label_view_; |
231 | 203 |
| 204 // Input controls which are used for username and password. |
| 205 UserInput* user_input_; |
| 206 |
| 207 // Throbber host that can show a throbber. |
| 208 ThrobberHostView* throbber_host_; |
| 209 |
232 NotificationRegistrar registrar_; | 210 NotificationRegistrar registrar_; |
233 | 211 |
234 ScopedRunnableMethodFactory<UserController> method_factory_; | 212 ScopedRunnableMethodFactory<UserController> method_factory_; |
235 | 213 |
236 DISALLOW_COPY_AND_ASSIGN(UserController); | 214 DISALLOW_COPY_AND_ASSIGN(UserController); |
237 }; | 215 }; |
238 | 216 |
239 } // namespace chromeos | 217 } // namespace chromeos |
240 | 218 |
241 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_USER_CONTROLLER_H_ | 219 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_USER_CONTROLLER_H_ |
OLD | NEW |