Chromium Code Reviews| 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 gfx::Rect GetScreenBounds(); |
|
whywhat
2010/12/09 16:20:18
const?
altimofeev
2010/12/10 16:37:40
Done.
| |
| 106 virtual void ButtonPressed(views::Button* sender, const views::Event& event); | |
| 107 | 97 |
| 108 // Textfield::Controller: | 98 // Starts/Stops throbber. |
| 109 virtual void ContentsChanged(views::Textfield* sender, | 99 void StartThrobber(); |
| 110 const string16& new_contents); | 100 void StopThrobber(); |
| 111 virtual bool HandleKeystroke(views::Textfield* sender, | |
| 112 const views::Textfield::Keystroke& keystroke); | |
| 113 | 101 |
| 114 // views::WidgetDelegate: | 102 // views::WidgetDelegate: |
| 115 virtual void IsActiveChanged(bool active); | 103 virtual void IsActiveChanged(bool active); |
| 116 | 104 |
| 117 // NotificationObserver implementation. | 105 // NotificationObserver implementation. |
| 118 virtual void Observe(NotificationType type, | 106 virtual void Observe(NotificationType type, |
| 119 const NotificationSource& source, | 107 const NotificationSource& source, |
| 120 const NotificationDetails& details); | 108 const NotificationDetails& details); |
| 121 | 109 |
| 122 // NewUserView::Delegate | 110 // NewUserView::Delegate |
| 123 virtual void OnLogin(const std::string& username, | 111 virtual void OnLogin(const std::string& username, |
| 124 const std::string& password); | 112 const std::string& password); |
| 125 virtual void OnCreateAccount(); | 113 virtual void OnCreateAccount(); |
| 126 virtual void OnLoginOffTheRecord(); | 114 virtual void OnLoginOffTheRecord(); |
| 127 virtual void AddStartUrl(const GURL& start_url) { | 115 virtual void AddStartUrl(const GURL& start_url) { |
| 128 delegate_->AddStartUrl(start_url); | 116 delegate_->AddStartUrl(start_url); |
| 129 } | 117 } |
| 130 virtual void ClearErrors(); | 118 virtual void ClearErrors(); |
| 131 virtual void NavigateAway(); | 119 virtual void NavigateAway(); |
| 132 virtual void SetStatusAreaEnabled(bool enable) { | 120 virtual void SetStatusAreaEnabled(bool enable) { |
| 133 delegate_->SetStatusAreaEnabled(enable); | 121 delegate_->SetStatusAreaEnabled(enable); |
| 134 } | 122 } |
| 135 | 123 |
| 136 // UserView::Delegate implementation: | 124 // UserView::Delegate implementation: |
| 137 virtual void OnRemoveUser(); | 125 virtual void OnRemoveUser(); |
| 138 | 126 |
| 139 // Selects user entry with specified |index|. | 127 // Selects user relative to the current user. |
| 140 void SelectUser(int index); | 128 void SelectUserRelative(int shift); |
| 141 | |
| 142 // Sets focus on password field. | |
| 143 void FocusPasswordField(); | |
| 144 | 129 |
| 145 // Padding between the user windows. | 130 // Padding between the user windows. |
| 146 static const int kPadding; | 131 static const int kPadding; |
| 147 | 132 |
| 148 // Max size needed when an entry is not selected. | 133 // Max size needed when an entry is not selected. |
| 149 static const int kUnselectedSize; | 134 static const int kUnselectedSize; |
| 150 static const int kNewUserUnselectedSize; | 135 static const int kNewUserUnselectedSize; |
| 151 | 136 |
| 152 private: | 137 private: |
| 153 FRIEND_TEST(UserControllerTest, GetNameTooltip); | 138 FRIEND_TEST(UserControllerTest, GetNameTooltip); |
| 154 | 139 |
| 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. | 140 // Performs common setup for login windows. |
| 159 void ConfigureLoginWindow(views::WidgetGtk* window, | 141 void ConfigureLoginWindow(views::WidgetGtk* window, |
| 160 int index, | 142 int index, |
| 161 const gfx::Rect& bounds, | 143 const gfx::Rect& bounds, |
| 162 chromeos::WmIpcWindowType type, | 144 chromeos::WmIpcWindowType type, |
| 163 views::View* contents_view); | 145 views::View* contents_view); |
| 164 views::WidgetGtk* CreateControlsWindow(int index, | 146 views::WidgetGtk* CreateControlsWindow(int index, |
| 165 int* width, int* height, | 147 int* width, int* height, |
| 166 bool need_guest_link); | 148 bool need_guest_link); |
| 167 views::WidgetGtk* CreateImageWindow(int index); | 149 views::WidgetGtk* CreateImageWindow(int index); |
| 168 views::WidgetGtk* CreateLabelWindow(int index, WmIpcWindowType type); | 150 views::WidgetGtk* CreateLabelWindow(int index, WmIpcWindowType type); |
| 169 void CreateBorderWindow(int index, | 151 void CreateBorderWindow(int index, |
| 170 int total_user_count, | 152 int total_user_count, |
| 171 int controls_width, int controls_height); | 153 int controls_width, int controls_height); |
| 172 | 154 |
| 173 // Sets specified image on the image window. If image's size is less than | 155 // 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, | 156 // 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 | 157 // the image is resized to fit window size precisely. Image view repaints |
| 176 // itself. | 158 // itself. |
| 177 void SetImage(const SkBitmap& image); | 159 void SetImage(const SkBitmap& image); |
| 178 | 160 |
| 179 // Sets the enabled state of the password field to |enable|. | |
| 180 void SetPasswordEnabled(bool enable); | |
| 181 | |
| 182 // Returns tooltip text for user name. | 161 // Returns tooltip text for user name. |
| 183 std::wstring GetNameTooltip() const; | 162 std::wstring GetNameTooltip() const; |
| 184 | 163 |
| 185 // User index within all the users. | 164 // User index within all the users. |
| 186 int user_index_; | 165 int user_index_; |
| 187 | 166 |
| 188 // Is this user selected now? | 167 // Is this user selected now? |
| 189 bool is_user_selected_; | 168 bool is_user_selected_; |
| 190 | 169 |
| 191 // Is this the new user pod? | 170 // Is this the new user pod? |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 209 // A window is used to represent the individual chunks. | 188 // A window is used to represent the individual chunks. |
| 210 views::WidgetGtk* controls_window_; | 189 views::WidgetGtk* controls_window_; |
| 211 views::WidgetGtk* image_window_; | 190 views::WidgetGtk* image_window_; |
| 212 views::WidgetGtk* border_window_; | 191 views::WidgetGtk* border_window_; |
| 213 views::WidgetGtk* label_window_; | 192 views::WidgetGtk* label_window_; |
| 214 views::WidgetGtk* unselected_label_window_; | 193 views::WidgetGtk* unselected_label_window_; |
| 215 | 194 |
| 216 // View that shows user image on image window. | 195 // View that shows user image on image window. |
| 217 UserView* user_view_; | 196 UserView* user_view_; |
| 218 | 197 |
| 219 // View that is used for new user login. | 198 // Input controls which are used for username and password. |
| 220 NewUserView* new_user_view_; | 199 UserInput* user_input_; |
| 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 | 200 |
| 228 // Views that show display name of the user. | 201 // Views that show display name of the user. |
| 229 views::Label* label_view_; | 202 views::Label* label_view_; |
| 230 views::Label* unselected_label_view_; | 203 views::Label* unselected_label_view_; |
| 231 | 204 |
| 205 scoped_ptr<ThrobberManager> throbber_manager_; | |
| 206 | |
| 232 NotificationRegistrar registrar_; | 207 NotificationRegistrar registrar_; |
| 233 | 208 |
| 234 ScopedRunnableMethodFactory<UserController> method_factory_; | 209 ScopedRunnableMethodFactory<UserController> method_factory_; |
| 235 | 210 |
| 236 DISALLOW_COPY_AND_ASSIGN(UserController); | 211 DISALLOW_COPY_AND_ASSIGN(UserController); |
| 237 }; | 212 }; |
| 238 | 213 |
| 239 } // namespace chromeos | 214 } // namespace chromeos |
| 240 | 215 |
| 241 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_USER_CONTROLLER_H_ | 216 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_USER_CONTROLLER_H_ |
| OLD | NEW |