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 #include "chrome/browser/chromeos/login/existing_user_view.h" | 5 #include "chrome/browser/chromeos/login/existing_user_view.h" |
6 | 6 |
7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
8 #include "chrome/browser/chromeos/login/helper.h" | 8 #include "base/utf_string_conversions.h" |
9 #include "chrome/browser/chromeos/login/user_controller.h" | 9 #include "chrome/browser/chromeos/login/user_controller.h" |
10 #include "chrome/browser/chromeos/login/textfield_with_margin.h" | 10 #include "chrome/browser/chromeos/login/textfield_with_margin.h" |
11 #include "chrome/browser/chromeos/login/wizard_accessibility_helper.h" | 11 #include "chrome/browser/chromeos/login/wizard_accessibility_helper.h" |
12 #include "grit/generated_resources.h" | 12 #include "grit/generated_resources.h" |
13 #include "views/background.h" | 13 #include "views/background.h" |
14 #include "views/focus/focus_manager.h" | 14 #include "views/focus/focus_manager.h" |
15 #include "views/fill_layout.h" | 15 #include "views/fill_layout.h" |
16 | 16 |
17 namespace chromeos { | 17 namespace chromeos { |
18 | 18 |
19 // Colors for gradient background. These should be consistent with border | 19 // Colors for gradient background. These should be consistent with border |
20 // window background so textfield border is not visible to the user. | 20 // window background so textfield border is not visible to the user. |
21 // The background is needed for password textfield to imitate its borders | 21 // The background is needed for password textfield to imitate its borders |
22 // transparency correctly. | 22 // transparency correctly. |
23 const SkColor kBackgroundColorTop = SkColorSetRGB(209, 213, 216); | 23 const SkColor kBackgroundColorTop = SkColorSetRGB(209, 213, 216); |
24 const SkColor kBackgroundColorBottom = SkColorSetRGB(205, 210, 213); | 24 const SkColor kBackgroundColorBottom = SkColorSetRGB(205, 210, 213); |
25 | 25 |
26 // Textfield with custom processing for Tab/Shift+Tab to select entries. | 26 // Textfield with custom processing for Tab/Shift+Tab to select entries. |
27 class UserEntryTextfield : public TextfieldWithMargin { | 27 class UserEntryTextfield : public TextfieldWithMargin { |
28 public: | 28 public: |
29 UserEntryTextfield(UserController* controller, | 29 UserEntryTextfield(UserController* controller, |
30 views::Textfield::StyleFlags style) | 30 views::Textfield::StyleFlags style) |
31 : TextfieldWithMargin(style), | 31 : TextfieldWithMargin(style), |
32 controller_(controller) {} | 32 controller_(controller) {} |
33 | 33 |
34 // Overridden from views::View: | 34 // Overridden from views::View: |
35 virtual bool OnKeyPressed(const views::KeyEvent& e) { | 35 virtual bool OnKeyPressed(const views::KeyEvent& e) { |
36 if (e.GetKeyCode() == app::VKEY_TAB) { | 36 if (e.GetKeyCode() == app::VKEY_TAB) { |
37 int index = controller_->user_index() + (e.IsShiftDown() ? -1 : 1); | 37 controller_->SelectUserRelative(e.IsShiftDown() ? -1 : 1); |
38 controller_->SelectUser(index); | |
39 return true; | 38 return true; |
40 } else { | 39 } else { |
41 return false; | 40 return false; |
42 } | 41 } |
43 } | 42 } |
44 | 43 |
45 virtual bool SkipDefaultKeyEventProcessing(const views::KeyEvent& e) { | 44 virtual bool SkipDefaultKeyEventProcessing(const views::KeyEvent& e) { |
46 if (e.GetKeyCode() == app::VKEY_TAB) | 45 if (e.GetKeyCode() == app::VKEY_TAB) |
47 return true; | 46 return true; |
48 else | 47 else |
49 return views::Textfield::SkipDefaultKeyEventProcessing(e); | 48 return views::Textfield::SkipDefaultKeyEventProcessing(e); |
50 } | 49 } |
51 | 50 |
52 private: | 51 private: |
53 UserController* controller_; | 52 UserController* controller_; |
54 | 53 |
55 DISALLOW_COPY_AND_ASSIGN(UserEntryTextfield); | 54 DISALLOW_COPY_AND_ASSIGN(UserEntryTextfield); |
56 }; | 55 }; |
57 | 56 |
58 | 57 |
59 ExistingUserView::ExistingUserView(UserController* uc) | 58 ExistingUserView::ExistingUserView(UserController* user_controller) |
60 : accel_login_off_the_record_( | 59 : ThrobberHost(this), |
60 user_controller_(user_controller), | |
61 password_field_(NULL), | |
62 accel_login_off_the_record_( | |
61 views::Accelerator(app::VKEY_B, false, false, true)), | 63 views::Accelerator(app::VKEY_B, false, false, true)), |
62 password_field_(NULL), | |
63 user_controller_(uc), | |
64 accel_enable_accessibility_( | 64 accel_enable_accessibility_( |
65 WizardAccessibilityHelper::GetAccelerator()) { | 65 WizardAccessibilityHelper::GetAccelerator()) { |
66 AddAccelerator(accel_login_off_the_record_); | 66 AddAccelerator(accel_login_off_the_record_); |
67 AddAccelerator(accel_enable_accessibility_); | 67 AddAccelerator(accel_enable_accessibility_); |
68 } | 68 } |
69 | 69 |
70 void ExistingUserView::RecreateFields() { | 70 void ExistingUserView::RecreateFields() { |
71 if (password_field_ == NULL) { | 71 if (password_field_ == NULL) { |
72 SetLayoutManager(new views::FillLayout); | 72 SetLayoutManager(new views::FillLayout); |
73 password_field_ = new UserEntryTextfield(user_controller_, | 73 password_field_ = new UserEntryTextfield(user_controller_, |
74 views::Textfield::STYLE_PASSWORD); | 74 views::Textfield::STYLE_PASSWORD); |
75 password_field_->set_background( | 75 password_field_->set_background( |
76 views::Background::CreateVerticalGradientBackground( | 76 views::Background::CreateVerticalGradientBackground( |
77 kBackgroundColorTop, kBackgroundColorBottom)); | 77 kBackgroundColorTop, kBackgroundColorBottom)); |
78 password_field_->SetFocusable(true); | 78 password_field_->SetFocusable(true); |
79 password_field_->SetController(user_controller_); | 79 password_field_->SetController(this); |
80 AddChildView(password_field_); | 80 AddChildView(password_field_); |
81 } | 81 } |
82 password_field_->set_text_to_display_when_empty( | 82 password_field_->set_text_to_display_when_empty( |
83 l10n_util::GetStringUTF16(IDS_LOGIN_POD_EMPTY_PASSWORD_TEXT)); | 83 l10n_util::GetStringUTF16(IDS_LOGIN_POD_EMPTY_PASSWORD_TEXT)); |
84 Layout(); | 84 Layout(); |
85 SchedulePaint(); | 85 SchedulePaint(); |
86 } | 86 } |
87 | 87 |
88 bool ExistingUserView::AcceleratorPressed( | 88 bool ExistingUserView::AcceleratorPressed( |
89 const views::Accelerator& accelerator) { | 89 const views::Accelerator& accelerator) { |
90 if (accelerator == accel_login_off_the_record_) { | 90 if (accelerator == accel_login_off_the_record_) { |
91 user_controller_->OnLoginOffTheRecord(); | 91 user_controller_->OnLoginOffTheRecord(); |
92 return true; | 92 return true; |
93 } else if (accelerator == accel_enable_accessibility_) { | 93 } else if (accelerator == accel_enable_accessibility_) { |
94 WizardAccessibilityHelper::GetInstance()->EnableAccessibility(this); | 94 WizardAccessibilityHelper::GetInstance()->EnableAccessibility(this); |
95 return true; | 95 return true; |
96 } | 96 } |
97 return false; | 97 return false; |
98 } | 98 } |
99 | 99 |
100 bool ExistingUserView::HandleKeystroke( | |
101 views::Textfield* sender, | |
102 const views::Textfield::Keystroke& keystroke) { | |
103 if (keystroke.GetKeyboardCode() == app::VKEY_RETURN) { | |
104 user_controller_->OnLogin("", UTF16ToUTF8(password_field_->text())); | |
105 } else if (keystroke.GetKeyboardCode() == app::VKEY_LEFT) { | |
106 user_controller_->SelectUserRelative(-1); | |
107 } else if (keystroke.GetKeyboardCode() == app::VKEY_RIGHT) { | |
108 user_controller_->SelectUserRelative(1); | |
109 } else { | |
110 user_controller_->ClearErrors(); | |
111 return false; | |
112 } | |
113 | |
whywhat
2010/12/13 16:10:55
This blank line is not needed imho.
altimofeev
2010/12/14 11:15:21
Done.
| |
114 return true; | |
115 } | |
116 | |
117 void ExistingUserView::ContentsChanged(views::Textfield* sender, | |
118 const string16& new_contents) { | |
119 } | |
120 | |
121 void ExistingUserView::EnableInputControls(bool enabled) { | |
122 password_field_->SetEnabled(enabled); | |
123 } | |
124 | |
125 void ExistingUserView::ClearAndFocusControls() { | |
126 ClearAndFocusPassword(); | |
127 } | |
128 | |
129 void ExistingUserView::ClearAndFocusPassword() { | |
130 password_field_->SetText(string16()); | |
131 FocusPasswordField(); | |
132 } | |
133 | |
100 void ExistingUserView::ViewHierarchyChanged(bool is_add, | 134 void ExistingUserView::ViewHierarchyChanged(bool is_add, |
101 views::View* parent, | 135 views::View* parent, |
102 views::View* child) { | 136 views::View* child) { |
103 if (is_add && this == child) | 137 if (is_add && this == child) |
104 WizardAccessibilityHelper::GetInstance()->MaybeEnableAccessibility(this); | 138 WizardAccessibilityHelper::GetInstance()->MaybeEnableAccessibility(this); |
105 } | 139 } |
106 | 140 |
107 void ExistingUserView::FocusPasswordField() { | 141 void ExistingUserView::FocusPasswordField() { |
108 if (GetFocusManager()) { | 142 password_field_->RequestFocus(); |
109 password_field()->RequestFocus(); | 143 } |
110 } | 144 |
145 gfx::Rect ExistingUserView::GetMainInputScreenBounds() const { | |
146 return password_field_->GetScreenBounds(); | |
111 } | 147 } |
112 | 148 |
113 void ExistingUserView::OnLocaleChanged() { | 149 void ExistingUserView::OnLocaleChanged() { |
114 RecreateFields(); | 150 RecreateFields(); |
115 } | 151 } |
116 | 152 |
117 } // namespace chromeos | 153 } // namespace chromeos |
OLD | NEW |