| 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/guest_user_view.h" | 5 #include "chrome/browser/chromeos/login/guest_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" | |
| 9 #include "chrome/browser/chromeos/login/user_controller.h" | 8 #include "chrome/browser/chromeos/login/user_controller.h" |
| 10 #include "chrome/browser/chromeos/login/wizard_accessibility_helper.h" | 9 #include "chrome/browser/chromeos/login/wizard_accessibility_helper.h" |
| 11 #include "grit/generated_resources.h" | 10 #include "grit/generated_resources.h" |
| 12 | 11 |
| 13 namespace chromeos { | 12 namespace chromeos { |
| 14 | 13 |
| 15 // Button with custom processing for Tab/Shift+Tab to select entries. | 14 // Button with custom processing for Tab/Shift+Tab to select entries. |
| 16 class UserEntryButton : public login::WideButton { | 15 class UserEntryButton : public login::WideButton { |
| 17 public: | 16 public: |
| 18 UserEntryButton(UserController* controller, | 17 UserEntryButton(views::ButtonListener* button_listener, |
| 18 UserController* user_controller, |
| 19 const std::wstring& label) | 19 const std::wstring& label) |
| 20 : WideButton(controller, label), | 20 : WideButton(button_listener, label), |
| 21 controller_(controller) {} | 21 user_controller_(user_controller) {} |
| 22 | 22 |
| 23 // Overridden from views::View: | 23 // Overridden from views::View: |
| 24 virtual bool OnKeyPressed(const views::KeyEvent& e) { | 24 virtual bool OnKeyPressed(const views::KeyEvent& e) { |
| 25 if (e.GetKeyCode() == app::VKEY_TAB) { | 25 if (e.GetKeyCode() == app::VKEY_TAB) { |
| 26 int index = controller_->user_index() + (e.IsShiftDown() ? -1 : 1); | 26 user_controller_->SelectUserRelative(e.IsShiftDown() ? -1 : 1); |
| 27 controller_->SelectUser(index); | |
| 28 return true; | 27 return true; |
| 29 } | 28 } |
| 30 return WideButton::OnKeyPressed(e); | 29 return WideButton::OnKeyPressed(e); |
| 31 } | 30 } |
| 32 | 31 |
| 33 virtual bool SkipDefaultKeyEventProcessing(const views::KeyEvent& e) { | 32 virtual bool SkipDefaultKeyEventProcessing(const views::KeyEvent& e) { |
| 34 if (e.GetKeyCode() == app::VKEY_TAB) | 33 if (e.GetKeyCode() == app::VKEY_TAB) |
| 35 return true; | 34 return true; |
| 36 return WideButton::SkipDefaultKeyEventProcessing(e); | 35 return WideButton::SkipDefaultKeyEventProcessing(e); |
| 37 } | 36 } |
| 38 | 37 |
| 39 private: | 38 private: |
| 40 UserController* controller_; | 39 UserController* user_controller_; |
| 41 | 40 |
| 42 DISALLOW_COPY_AND_ASSIGN(UserEntryButton); | 41 DISALLOW_COPY_AND_ASSIGN(UserEntryButton); |
| 43 }; | 42 }; |
| 44 | 43 |
| 45 | 44 |
| 46 GuestUserView::GuestUserView(UserController* uc) | 45 GuestUserView::GuestUserView(UserController* uc) |
| 47 : submit_button_(NULL), | 46 : submit_button_(NULL), |
| 48 user_controller_(uc), | 47 user_controller_(uc), |
| 49 accel_enable_accessibility_( | 48 accel_enable_accessibility_( |
| 50 WizardAccessibilityHelper::GetAccelerator()), | 49 WizardAccessibilityHelper::GetAccelerator()), |
| 51 accel_login_off_the_record_( | 50 accel_login_off_the_record_( |
| 52 views::Accelerator(app::VKEY_B, false, false, true)), | 51 views::Accelerator(app::VKEY_B, false, false, true)), |
| 53 accel_previous_pod_by_arrow_( | 52 accel_previous_pod_by_arrow_( |
| 54 views::Accelerator(app::VKEY_LEFT, false, false, false)), | 53 views::Accelerator(app::VKEY_LEFT, false, false, false)), |
| 55 accel_next_pod_by_arrow_( | 54 accel_next_pod_by_arrow_( |
| 56 views::Accelerator(app::VKEY_RIGHT, false, false, false)) { | 55 views::Accelerator(app::VKEY_RIGHT, false, false, false)) { |
| 57 AddAccelerator(accel_enable_accessibility_); | 56 AddAccelerator(accel_enable_accessibility_); |
| 58 AddAccelerator(accel_login_off_the_record_); | 57 AddAccelerator(accel_login_off_the_record_); |
| 59 AddAccelerator(accel_previous_pod_by_arrow_); | 58 AddAccelerator(accel_previous_pod_by_arrow_); |
| 60 AddAccelerator(accel_next_pod_by_arrow_); | 59 AddAccelerator(accel_next_pod_by_arrow_); |
| 61 } | 60 } |
| 62 | 61 |
| 63 void GuestUserView::RecreateFields() { | 62 void GuestUserView::RecreateFields() { |
| 64 delete submit_button_; | 63 delete submit_button_; |
| 65 submit_button_ = new UserEntryButton( | 64 submit_button_ = new UserEntryButton( |
| 65 this, |
| 66 user_controller_, | 66 user_controller_, |
| 67 l10n_util::GetString(IDS_ENTER_GUEST_SESSION_BUTTON)); | 67 l10n_util::GetString(IDS_ENTER_GUEST_SESSION_BUTTON)); |
| 68 AddChildView(submit_button_); | 68 AddChildView(submit_button_); |
| 69 Layout(); | 69 Layout(); |
| 70 SchedulePaint(); | 70 SchedulePaint(); |
| 71 } | 71 } |
| 72 | 72 |
| 73 void GuestUserView::FocusSignInButton() { | 73 void GuestUserView::FocusSignInButton() { |
| 74 if (GetFocusManager()) | 74 submit_button_->RequestFocus(); |
| 75 submit_button_->RequestFocus(); | |
| 76 } | 75 } |
| 77 | 76 |
| 78 bool GuestUserView::AcceleratorPressed( | 77 bool GuestUserView::AcceleratorPressed( |
| 79 const views::Accelerator& accelerator) { | 78 const views::Accelerator& accelerator) { |
| 80 if (accelerator == accel_login_off_the_record_) | 79 if (accelerator == accel_login_off_the_record_) |
| 81 user_controller_->OnLoginOffTheRecord(); | 80 user_controller_->OnLoginOffTheRecord(); |
| 82 else if (accelerator == accel_enable_accessibility_) | 81 else if (accelerator == accel_enable_accessibility_) |
| 83 WizardAccessibilityHelper::GetInstance()->EnableAccessibility(this); | 82 WizardAccessibilityHelper::GetInstance()->EnableAccessibility(this); |
| 84 else if (accelerator == accel_previous_pod_by_arrow_) | 83 else if (accelerator == accel_previous_pod_by_arrow_) |
| 85 user_controller_->SelectUser(user_controller_->user_index() - 1); | 84 user_controller_->SelectUserRelative(-1); |
| 86 else if (accelerator == accel_next_pod_by_arrow_) | 85 else if (accelerator == accel_next_pod_by_arrow_) |
| 87 user_controller_->SelectUser(user_controller_->user_index() + 1); | 86 user_controller_->SelectUserRelative(1); |
| 88 else | 87 else |
| 89 return false; | 88 return false; |
| 90 return true; | 89 return true; |
| 91 } | 90 } |
| 92 | 91 |
| 92 void GuestUserView::ButtonPressed( |
| 93 views::Button* sender, const views::Event& event) { |
| 94 DCHECK(sender == submit_button_); |
| 95 user_controller_->OnLoginOffTheRecord(); |
| 96 } |
| 97 |
| 98 void GuestUserView::EnableInputControls(bool enabled) { |
| 99 submit_button_->SetEnabled(enabled); |
| 100 } |
| 101 |
| 93 void GuestUserView::ViewHierarchyChanged(bool is_add, | 102 void GuestUserView::ViewHierarchyChanged(bool is_add, |
| 94 views::View* parent, | 103 views::View* parent, |
| 95 views::View* child) { | 104 views::View* child) { |
| 96 if (is_add && this == child) | 105 if (is_add && this == child) |
| 97 WizardAccessibilityHelper::GetInstance()->MaybeEnableAccessibility(this); | 106 WizardAccessibilityHelper::GetInstance()->MaybeEnableAccessibility(this); |
| 98 } | 107 } |
| 99 | 108 |
| 100 void GuestUserView::OnLocaleChanged() { | 109 void GuestUserView::OnLocaleChanged() { |
| 101 RecreateFields(); | 110 RecreateFields(); |
| 102 } | 111 } |
| 103 | 112 |
| 104 void GuestUserView::Layout() { | 113 void GuestUserView::Layout() { |
| 105 gfx::Size submit_button_size = submit_button_->GetPreferredSize(); | 114 gfx::Size submit_button_size = submit_button_->GetPreferredSize(); |
| 106 int submit_button_x = (width() - submit_button_size.width()) / 2; | 115 int submit_button_x = (width() - submit_button_size.width()) / 2; |
| 107 int submit_button_y = (height() - submit_button_size.height()) / 2; | 116 int submit_button_y = (height() - submit_button_size.height()) / 2; |
| 108 submit_button_->SetBounds(submit_button_x, | 117 submit_button_->SetBounds(submit_button_x, |
| 109 submit_button_y, | 118 submit_button_y, |
| 110 submit_button_size.width(), | 119 submit_button_size.width(), |
| 111 submit_button_size.height()); | 120 submit_button_size.height()); |
| 112 } | 121 } |
| 113 | 122 |
| 123 void GuestUserView::ClearAndFocusControls() { |
| 124 } |
| 125 |
| 126 void GuestUserView::ClearAndFocusPassword() { |
| 127 } |
| 128 |
| 129 gfx::Rect GuestUserView::GetMainInputScreenBounds() const { |
| 130 NOTREACHED(); |
| 131 return gfx::Rect(); |
| 132 } |
| 133 |
| 114 } // namespace chromeos | 134 } // namespace chromeos |
| OLD | NEW |