OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ash/system/chromeos/tray_caps_lock.h" | 5 #include "ash/system/chromeos/tray_caps_lock.h" |
6 | 6 |
7 #include "ash/metrics/user_metrics_recorder.h" | 7 #include "ash/metrics/user_metrics_recorder.h" |
8 #include "ash/shell.h" | 8 #include "ash/shell.h" |
9 #include "ash/system/tray/actionable_view.h" | 9 #include "ash/system/tray/actionable_view.h" |
10 #include "ash/system/tray/fixed_sized_image_view.h" | 10 #include "ash/system/tray/fixed_sized_image_view.h" |
11 #include "ash/system/tray/system_tray_notifier.h" | 11 #include "ash/system/tray/system_tray_notifier.h" |
12 #include "ash/system/tray/tray_constants.h" | 12 #include "ash/system/tray/tray_constants.h" |
13 #include "base/sys_info.h" | 13 #include "base/sys_info.h" |
| 14 #include "chromeos/ime/ime_keyboard.h" |
14 #include "chromeos/ime/input_method_manager.h" | 15 #include "chromeos/ime/input_method_manager.h" |
15 #include "chromeos/ime/xkeyboard.h" | |
16 #include "grit/ash_resources.h" | 16 #include "grit/ash_resources.h" |
17 #include "grit/ash_strings.h" | 17 #include "grit/ash_strings.h" |
18 #include "ui/accessibility/ax_view_state.h" | 18 #include "ui/accessibility/ax_view_state.h" |
19 #include "ui/base/resource/resource_bundle.h" | 19 #include "ui/base/resource/resource_bundle.h" |
20 #include "ui/gfx/image/image.h" | 20 #include "ui/gfx/image/image.h" |
21 #include "ui/views/controls/image_view.h" | 21 #include "ui/views/controls/image_view.h" |
22 #include "ui/views/controls/label.h" | 22 #include "ui/views/controls/label.h" |
23 #include "ui/views/layout/box_layout.h" | 23 #include "ui/views/layout/box_layout.h" |
24 #include "ui/views/widget/widget.h" | 24 #include "ui/views/widget/widget.h" |
25 | 25 |
26 namespace ash { | 26 namespace ash { |
27 namespace { | 27 namespace { |
28 | 28 |
29 bool CapsLockIsEnabled() { | 29 bool CapsLockIsEnabled() { |
30 chromeos::input_method::InputMethodManager* ime = | 30 chromeos::input_method::InputMethodManager* ime = |
31 chromeos::input_method::InputMethodManager::Get(); | 31 chromeos::input_method::InputMethodManager::Get(); |
32 return (ime && ime->GetXKeyboard()) ? ime->GetXKeyboard()->CapsLockIsEnabled() | 32 return (ime && ime->GetImeKeyboard()) |
33 : false; | 33 ? ime->GetImeKeyboard()->CapsLockIsEnabled() |
| 34 : false; |
34 } | 35 } |
35 | 36 |
36 } | 37 } |
37 | 38 |
38 class CapsLockDefaultView : public ActionableView { | 39 class CapsLockDefaultView : public ActionableView { |
39 public: | 40 public: |
40 CapsLockDefaultView() | 41 CapsLockDefaultView() |
41 : text_label_(new views::Label), | 42 : text_label_(new views::Label), |
42 shortcut_label_(new views::Label) { | 43 shortcut_label_(new views::Label) { |
43 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal, | 44 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal, |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 text_size.height())); | 102 text_size.height())); |
102 } | 103 } |
103 | 104 |
104 virtual void GetAccessibleState(ui::AXViewState* state) OVERRIDE { | 105 virtual void GetAccessibleState(ui::AXViewState* state) OVERRIDE { |
105 state->role = ui::AX_ROLE_BUTTON; | 106 state->role = ui::AX_ROLE_BUTTON; |
106 state->name = text_label_->text(); | 107 state->name = text_label_->text(); |
107 } | 108 } |
108 | 109 |
109 // Overridden from ActionableView: | 110 // Overridden from ActionableView: |
110 virtual bool PerformAction(const ui::Event& event) OVERRIDE { | 111 virtual bool PerformAction(const ui::Event& event) OVERRIDE { |
111 chromeos::input_method::XKeyboard* xkeyboard = | 112 chromeos::input_method::ImeKeyboard* keyboard = |
112 chromeos::input_method::InputMethodManager::Get()->GetXKeyboard(); | 113 chromeos::input_method::InputMethodManager::Get()->GetImeKeyboard(); |
113 Shell::GetInstance()->metrics()->RecordUserMetricsAction( | 114 Shell::GetInstance()->metrics()->RecordUserMetricsAction( |
114 xkeyboard->CapsLockIsEnabled() ? | 115 keyboard->CapsLockIsEnabled() ? |
115 ash::UMA_STATUS_AREA_CAPS_LOCK_DISABLED_BY_CLICK : | 116 ash::UMA_STATUS_AREA_CAPS_LOCK_DISABLED_BY_CLICK : |
116 ash::UMA_STATUS_AREA_CAPS_LOCK_ENABLED_BY_CLICK); | 117 ash::UMA_STATUS_AREA_CAPS_LOCK_ENABLED_BY_CLICK); |
117 xkeyboard->SetCapsLockEnabled(!xkeyboard->CapsLockIsEnabled()); | 118 keyboard->SetCapsLockEnabled(!keyboard->CapsLockIsEnabled()); |
118 return true; | 119 return true; |
119 } | 120 } |
120 | 121 |
121 views::Label* text_label_; | 122 views::Label* text_label_; |
122 views::Label* shortcut_label_; | 123 views::Label* shortcut_label_; |
123 | 124 |
124 DISALLOW_COPY_AND_ASSIGN(CapsLockDefaultView); | 125 DISALLOW_COPY_AND_ASSIGN(CapsLockDefaultView); |
125 }; | 126 }; |
126 | 127 |
127 TrayCapsLock::TrayCapsLock(SystemTray* system_tray) | 128 TrayCapsLock::TrayCapsLock(SystemTray* system_tray) |
128 : TrayImageItem(system_tray, IDR_AURA_UBER_TRAY_CAPS_LOCK), | 129 : TrayImageItem(system_tray, IDR_AURA_UBER_TRAY_CAPS_LOCK), |
129 default_(NULL), | 130 default_(NULL), |
130 detailed_(NULL), | 131 detailed_(NULL), |
131 caps_lock_enabled_(CapsLockIsEnabled()), | 132 caps_lock_enabled_(CapsLockIsEnabled()), |
132 message_shown_(false) { | 133 message_shown_(false) { |
133 // Since keyboard handling differs between ChromeOS and Linux we need to | 134 // Since keyboard handling differs between ChromeOS and Linux we need to |
134 // use different observers depending on the two platforms. | 135 // use different observers depending on the two platforms. |
135 if (base::SysInfo::IsRunningOnChromeOS()) { | 136 if (base::SysInfo::IsRunningOnChromeOS()) { |
136 chromeos::input_method::XKeyboard* xkeyboard = | 137 chromeos::input_method::ImeKeyboard* keyboard = |
137 chromeos::input_method::InputMethodManager::Get()->GetXKeyboard(); | 138 chromeos::input_method::InputMethodManager::Get()->GetImeKeyboard(); |
138 xkeyboard->AddObserver(this); | 139 keyboard->AddObserver(this); |
139 } else { | 140 } else { |
140 Shell::GetInstance()->PrependPreTargetHandler(this); | 141 Shell::GetInstance()->PrependPreTargetHandler(this); |
141 } | 142 } |
142 } | 143 } |
143 | 144 |
144 TrayCapsLock::~TrayCapsLock() { | 145 TrayCapsLock::~TrayCapsLock() { |
145 // Since keyboard handling differs between ChromeOS and Linux we need to | 146 // Since keyboard handling differs between ChromeOS and Linux we need to |
146 // use different observers depending on the two platforms. | 147 // use different observers depending on the two platforms. |
147 if (base::SysInfo::IsRunningOnChromeOS()) { | 148 if (base::SysInfo::IsRunningOnChromeOS()) { |
148 chromeos::input_method::XKeyboard* xkeyboard = | 149 chromeos::input_method::ImeKeyboard* keyboard = |
149 chromeos::input_method::InputMethodManager::Get()->GetXKeyboard(); | 150 chromeos::input_method::InputMethodManager::Get()->GetImeKeyboard(); |
150 xkeyboard->RemoveObserver(this); | 151 keyboard->RemoveObserver(this); |
151 } else { | 152 } else { |
152 Shell::GetInstance()->RemovePreTargetHandler(this); | 153 Shell::GetInstance()->RemovePreTargetHandler(this); |
153 } | 154 } |
154 } | 155 } |
155 | 156 |
156 void TrayCapsLock::OnCapsLockChanged(bool enabled) { | 157 void TrayCapsLock::OnCapsLockChanged(bool enabled) { |
157 caps_lock_enabled_ = enabled; | 158 caps_lock_enabled_ = enabled; |
158 | 159 |
159 if (tray_view()) | 160 if (tray_view()) |
160 tray_view()->SetVisible(caps_lock_enabled_); | 161 tray_view()->SetVisible(caps_lock_enabled_); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 | 225 |
225 void TrayCapsLock::DestroyDefaultView() { | 226 void TrayCapsLock::DestroyDefaultView() { |
226 default_ = NULL; | 227 default_ = NULL; |
227 } | 228 } |
228 | 229 |
229 void TrayCapsLock::DestroyDetailedView() { | 230 void TrayCapsLock::DestroyDetailedView() { |
230 detailed_ = NULL; | 231 detailed_ = NULL; |
231 } | 232 } |
232 | 233 |
233 } // namespace ash | 234 } // namespace ash |
OLD | NEW |