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