| 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 : ThrobberHost(this), |
| 47 submit_button_(NULL), |
| 48 user_controller_(uc), | 48 user_controller_(uc), |
| 49 accel_enable_accessibility_( | 49 accel_enable_accessibility_( |
| 50 WizardAccessibilityHelper::GetAccelerator()), | 50 WizardAccessibilityHelper::GetAccelerator()), |
| 51 accel_login_off_the_record_( | 51 accel_login_off_the_record_( |
| 52 views::Accelerator(app::VKEY_B, false, false, true)), | 52 views::Accelerator(app::VKEY_B, false, false, true)), |
| 53 accel_previous_pod_by_arrow_( | 53 accel_previous_pod_by_arrow_( |
| 54 views::Accelerator(app::VKEY_LEFT, false, false, false)), | 54 views::Accelerator(app::VKEY_LEFT, false, false, false)), |
| 55 accel_next_pod_by_arrow_( | 55 accel_next_pod_by_arrow_( |
| 56 views::Accelerator(app::VKEY_RIGHT, false, false, false)) { | 56 views::Accelerator(app::VKEY_RIGHT, false, false, false)) { |
| 57 AddAccelerator(accel_enable_accessibility_); | 57 AddAccelerator(accel_enable_accessibility_); |
| 58 AddAccelerator(accel_login_off_the_record_); | 58 AddAccelerator(accel_login_off_the_record_); |
| 59 AddAccelerator(accel_previous_pod_by_arrow_); | 59 AddAccelerator(accel_previous_pod_by_arrow_); |
| 60 AddAccelerator(accel_next_pod_by_arrow_); | 60 AddAccelerator(accel_next_pod_by_arrow_); |
| 61 } | 61 } |
| 62 | 62 |
| 63 void GuestUserView::RecreateFields() { | 63 void GuestUserView::RecreateFields() { |
| 64 delete submit_button_; | 64 delete submit_button_; |
| 65 submit_button_ = new UserEntryButton( | 65 submit_button_ = new UserEntryButton( |
| 66 this, |
| 66 user_controller_, | 67 user_controller_, |
| 67 l10n_util::GetString(IDS_ENTER_GUEST_SESSION_BUTTON)); | 68 l10n_util::GetString(IDS_ENTER_GUEST_SESSION_BUTTON)); |
| 68 AddChildView(submit_button_); | 69 AddChildView(submit_button_); |
| 69 Layout(); | 70 Layout(); |
| 70 SchedulePaint(); | 71 SchedulePaint(); |
| 71 } | 72 } |
| 72 | 73 |
| 73 void GuestUserView::FocusSignInButton() { | 74 void GuestUserView::FocusSignInButton() { |
| 74 if (GetFocusManager()) | 75 submit_button_->RequestFocus(); |
| 75 submit_button_->RequestFocus(); | |
| 76 } | 76 } |
| 77 | 77 |
| 78 bool GuestUserView::AcceleratorPressed( | 78 bool GuestUserView::AcceleratorPressed( |
| 79 const views::Accelerator& accelerator) { | 79 const views::Accelerator& accelerator) { |
| 80 if (accelerator == accel_login_off_the_record_) | 80 if (accelerator == accel_login_off_the_record_) |
| 81 user_controller_->OnLoginOffTheRecord(); | 81 user_controller_->OnLoginOffTheRecord(); |
| 82 else if (accelerator == accel_enable_accessibility_) | 82 else if (accelerator == accel_enable_accessibility_) |
| 83 WizardAccessibilityHelper::GetInstance()->EnableAccessibility(this); | 83 WizardAccessibilityHelper::GetInstance()->EnableAccessibility(this); |
| 84 else if (accelerator == accel_previous_pod_by_arrow_) | 84 else if (accelerator == accel_previous_pod_by_arrow_) |
| 85 user_controller_->SelectUser(user_controller_->user_index() - 1); | 85 user_controller_->SelectUserRelative(-1); |
| 86 else if (accelerator == accel_next_pod_by_arrow_) | 86 else if (accelerator == accel_next_pod_by_arrow_) |
| 87 user_controller_->SelectUser(user_controller_->user_index() + 1); | 87 user_controller_->SelectUserRelative(1); |
| 88 else | 88 else |
| 89 return false; | 89 return false; |
| 90 return true; | 90 return true; |
| 91 } | 91 } |
| 92 | 92 |
| 93 void GuestUserView::ButtonPressed( |
| 94 views::Button* sender, const views::Event& event) { |
| 95 DCHECK(sender == submit_button_); |
| 96 user_controller_->OnLoginOffTheRecord(); |
| 97 } |
| 98 |
| 99 void GuestUserView::EnableInputControls(bool enabled) { |
| 100 submit_button_->SetEnabled(enabled); |
| 101 } |
| 102 |
| 93 void GuestUserView::ViewHierarchyChanged(bool is_add, | 103 void GuestUserView::ViewHierarchyChanged(bool is_add, |
| 94 views::View* parent, | 104 views::View* parent, |
| 95 views::View* child) { | 105 views::View* child) { |
| 96 if (is_add && this == child) | 106 if (is_add && this == child) |
| 97 WizardAccessibilityHelper::GetInstance()->MaybeEnableAccessibility(this); | 107 WizardAccessibilityHelper::GetInstance()->MaybeEnableAccessibility(this); |
| 98 } | 108 } |
| 99 | 109 |
| 100 void GuestUserView::OnLocaleChanged() { | 110 void GuestUserView::OnLocaleChanged() { |
| 101 RecreateFields(); | 111 RecreateFields(); |
| 102 } | 112 } |
| 103 | 113 |
| 104 void GuestUserView::Layout() { | 114 void GuestUserView::Layout() { |
| 105 gfx::Size submit_button_size = submit_button_->GetPreferredSize(); | 115 gfx::Size submit_button_size = submit_button_->GetPreferredSize(); |
| 106 int submit_button_x = (width() - submit_button_size.width()) / 2; | 116 int submit_button_x = (width() - submit_button_size.width()) / 2; |
| 107 int submit_button_y = (height() - submit_button_size.height()) / 2; | 117 int submit_button_y = (height() - submit_button_size.height()) / 2; |
| 108 submit_button_->SetBounds(submit_button_x, | 118 submit_button_->SetBounds(submit_button_x, |
| 109 submit_button_y, | 119 submit_button_y, |
| 110 submit_button_size.width(), | 120 submit_button_size.width(), |
| 111 submit_button_size.height()); | 121 submit_button_size.height()); |
| 112 } | 122 } |
| 113 | 123 |
| 124 void GuestUserView::ClearAndFocusControls() { |
| 125 } |
| 126 |
| 127 void GuestUserView::ClearAndFocusPassword() { |
| 128 } |
| 129 |
| 130 gfx::Rect GuestUserView::GetMainInputScreenBounds() const { |
| 131 NOTREACHED(); |
| 132 return gfx::Rect(); |
| 133 } |
| 134 |
| 114 } // namespace chromeos | 135 } // namespace chromeos |
| OLD | NEW |