OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/accelerators/accelerator_controller.h" | 5 #include "ash/accelerators/accelerator_controller_delegate_aura.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cmath> | 8 #include <cmath> |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
11 | 11 |
12 #include "ash/accelerators/accelerator_commands.h" | 12 #include "ash/accelerators/accelerator_commands_aura.h" |
13 #include "ash/accelerators/debug_commands.h" | |
14 #include "ash/common/accessibility_delegate.h" | 13 #include "ash/common/accessibility_delegate.h" |
15 #include "ash/common/accessibility_types.h" | 14 #include "ash/common/accessibility_types.h" |
16 #include "ash/common/ash_switches.h" | 15 #include "ash/common/ash_switches.h" |
17 #include "ash/common/focus_cycler.h" | 16 #include "ash/common/focus_cycler.h" |
18 #include "ash/common/gpu_support.h" | 17 #include "ash/common/gpu_support.h" |
19 #include "ash/common/media_delegate.h" | |
20 #include "ash/common/multi_profile_uma.h" | |
21 #include "ash/common/session/session_state_delegate.h" | 18 #include "ash/common/session/session_state_delegate.h" |
22 #include "ash/common/shelf/shelf_model.h" | |
23 #include "ash/common/shell_delegate.h" | 19 #include "ash/common/shell_delegate.h" |
24 #include "ash/common/shell_window_ids.h" | 20 #include "ash/common/shell_window_ids.h" |
25 #include "ash/common/system/brightness_control_delegate.h" | |
26 #include "ash/common/system/keyboard_brightness_control_delegate.h" | |
27 #include "ash/common/system/status_area_widget.h" | 21 #include "ash/common/system/status_area_widget.h" |
28 #include "ash/common/system/system_notifier.h" | 22 #include "ash/common/system/system_notifier.h" |
29 #include "ash/common/system/tray/system_tray.h" | 23 #include "ash/common/system/tray/system_tray.h" |
30 #include "ash/common/system/tray/system_tray_delegate.h" | |
31 #include "ash/common/system/tray/system_tray_notifier.h" | |
32 #include "ash/common/system/volume_control_delegate.h" | |
33 #include "ash/common/system/web_notification/web_notification_tray.h" | 24 #include "ash/common/system/web_notification/web_notification_tray.h" |
34 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h" | 25 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h" |
35 #include "ash/common/wm/mru_window_tracker.h" | |
36 #include "ash/common/wm/overview/window_selector_controller.h" | |
37 #include "ash/common/wm/window_cycle_controller.h" | |
38 #include "ash/common/wm/window_state.h" | 26 #include "ash/common/wm/window_state.h" |
39 #include "ash/common/wm/wm_event.h" | 27 #include "ash/common/wm/wm_event.h" |
40 #include "ash/common/wm_shell.h" | 28 #include "ash/common/wm_shell.h" |
41 #include "ash/debug.h" | 29 #include "ash/debug.h" |
42 #include "ash/display/window_tree_host_manager.h" | 30 #include "ash/display/window_tree_host_manager.h" |
43 #include "ash/ime_control_delegate.h" | |
44 #include "ash/magnifier/magnification_controller.h" | 31 #include "ash/magnifier/magnification_controller.h" |
45 #include "ash/magnifier/partial_magnification_controller.h" | 32 #include "ash/magnifier/partial_magnification_controller.h" |
46 #include "ash/new_window_delegate.h" | 33 #include "ash/new_window_delegate.h" |
47 #include "ash/root_window_controller.h" | 34 #include "ash/root_window_controller.h" |
48 #include "ash/rotator/screen_rotation_animator.h" | 35 #include "ash/rotator/screen_rotation_animator.h" |
49 #include "ash/rotator/window_rotation.h" | 36 #include "ash/rotator/window_rotation.h" |
50 #include "ash/screen_util.h" | 37 #include "ash/screen_util.h" |
51 #include "ash/screenshot_delegate.h" | 38 #include "ash/screenshot_delegate.h" |
52 #include "ash/shelf/shelf.h" | 39 #include "ash/shelf/shelf.h" |
53 #include "ash/shelf/shelf_delegate.h" | |
54 #include "ash/shelf/shelf_widget.h" | 40 #include "ash/shelf/shelf_widget.h" |
55 #include "ash/shell.h" | 41 #include "ash/shell.h" |
56 #include "ash/touch/touch_hud_debug.h" | 42 #include "ash/touch/touch_hud_debug.h" |
57 #include "ash/utility/screenshot_controller.h" | 43 #include "ash/utility/screenshot_controller.h" |
58 #include "ash/wm/power_button_controller.h" | 44 #include "ash/wm/power_button_controller.h" |
59 #include "ash/wm/window_state_aura.h" | 45 #include "ash/wm/window_state_aura.h" |
60 #include "ash/wm/window_util.h" | 46 #include "ash/wm/window_util.h" |
61 #include "base/bind.h" | |
62 #include "base/command_line.h" | |
63 #include "base/metrics/histogram_macros.h" | 47 #include "base/metrics/histogram_macros.h" |
64 #include "base/metrics/user_metrics.h" | 48 #include "base/metrics/user_metrics.h" |
65 #include "base/strings/string_split.h" | 49 #include "base/strings/string_split.h" |
66 #include "base/strings/utf_string_conversions.h" | 50 #include "base/strings/utf_string_conversions.h" |
67 #include "ui/aura/env.h" | |
68 #include "ui/base/accelerators/accelerator.h" | 51 #include "ui/base/accelerators/accelerator.h" |
69 #include "ui/base/accelerators/accelerator_manager.h" | |
70 #include "ui/base/l10n/l10n_util.h" | 52 #include "ui/base/l10n/l10n_util.h" |
71 #include "ui/base/resource/resource_bundle.h" | |
72 #include "ui/compositor/layer.h" | 53 #include "ui/compositor/layer.h" |
73 #include "ui/compositor/layer_animation_sequence.h" | 54 #include "ui/compositor/layer_animation_sequence.h" |
74 #include "ui/compositor/layer_animator.h" | 55 #include "ui/compositor/layer_animator.h" |
75 #include "ui/display/screen.h" | 56 #include "ui/display/screen.h" |
76 #include "ui/events/event.h" | 57 #include "ui/events/event.h" |
77 #include "ui/events/keycodes/keyboard_codes.h" | 58 #include "ui/events/keycodes/keyboard_codes.h" |
78 #include "ui/message_center/message_center.h" | 59 #include "ui/message_center/message_center.h" |
79 #include "ui/message_center/notification.h" | 60 #include "ui/message_center/notification.h" |
80 #include "ui/message_center/notifier_settings.h" | 61 #include "ui/message_center/notifier_settings.h" |
81 | 62 |
82 #if defined(OS_CHROMEOS) | 63 #if defined(OS_CHROMEOS) |
83 #include "ash/display/display_configuration_controller.h" | 64 #include "ash/display/display_configuration_controller.h" |
84 #include "base/sys_info.h" | 65 #include "base/sys_info.h" |
85 #include "chromeos/dbus/dbus_thread_manager.h" | |
86 #include "chromeos/dbus/power_manager_client.h" | |
87 #include "ui/base/ime/chromeos/ime_keyboard.h" | |
88 #include "ui/base/ime/chromeos/input_method_manager.h" | |
89 #endif // defined(OS_CHROMEOS) | 66 #endif // defined(OS_CHROMEOS) |
90 | 67 |
91 namespace ash { | 68 namespace ash { |
92 namespace { | 69 namespace { |
93 | 70 |
94 using base::UserMetricsAction; | 71 using base::UserMetricsAction; |
95 | 72 |
96 // The notification delegate that will be used to open the keyboard shortcut | 73 // The notification delegate that will be used to open the keyboard shortcut |
97 // help page when the notification is clicked. | 74 // help page when the notification is clicked. |
98 class DeprecatedAcceleratorNotificationDelegate | 75 class DeprecatedAcceleratorNotificationDelegate |
99 : public message_center::NotificationDelegate { | 76 : public message_center::NotificationDelegate { |
100 public: | 77 public: |
101 DeprecatedAcceleratorNotificationDelegate() {} | 78 DeprecatedAcceleratorNotificationDelegate() {} |
102 | 79 |
103 // message_center::NotificationDelegate: | 80 // message_center::NotificationDelegate: |
104 bool HasClickedListener() override { return true; } | 81 bool HasClickedListener() override { return true; } |
105 | 82 |
106 void Click() override { | 83 void Click() override { |
107 if (!WmShell::Get()->GetSessionStateDelegate()->IsUserSessionBlocked()) | 84 if (!WmShell::Get()->GetSessionStateDelegate()->IsUserSessionBlocked()) |
108 WmShell::Get()->delegate()->OpenKeyboardShortcutHelpPage(); | 85 WmShell::Get()->delegate()->OpenKeyboardShortcutHelpPage(); |
109 } | 86 } |
110 | 87 |
111 private: | 88 private: |
112 // Private destructor since NotificationDelegate is ref-counted. | 89 // Private destructor since NotificationDelegate is ref-counted. |
113 ~DeprecatedAcceleratorNotificationDelegate() override {} | 90 ~DeprecatedAcceleratorNotificationDelegate() override {} |
114 | 91 |
115 DISALLOW_COPY_AND_ASSIGN(DeprecatedAcceleratorNotificationDelegate); | 92 DISALLOW_COPY_AND_ASSIGN(DeprecatedAcceleratorNotificationDelegate); |
116 }; | 93 }; |
117 | 94 |
118 ui::Accelerator CreateAccelerator(ui::KeyboardCode keycode, | |
119 int modifiers, | |
120 bool trigger_on_press) { | |
121 ui::Accelerator accelerator(keycode, modifiers); | |
122 accelerator.set_type(trigger_on_press ? ui::ET_KEY_PRESSED | |
123 : ui::ET_KEY_RELEASED); | |
124 return accelerator; | |
125 } | |
126 | |
127 // Ensures that there are no word breaks at the "+"s in the shortcut texts such | 95 // Ensures that there are no word breaks at the "+"s in the shortcut texts such |
128 // as "Ctrl+Shift+Space". | 96 // as "Ctrl+Shift+Space". |
129 void EnsureNoWordBreaks(base::string16* shortcut_text) { | 97 void EnsureNoWordBreaks(base::string16* shortcut_text) { |
130 std::vector<base::string16> keys = | 98 std::vector<base::string16> keys = |
131 base::SplitString(*shortcut_text, base::ASCIIToUTF16("+"), | 99 base::SplitString(*shortcut_text, base::ASCIIToUTF16("+"), |
132 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); | 100 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
133 | 101 |
134 if (keys.size() < 2U) | 102 if (keys.size() < 2U) |
135 return; | 103 return; |
136 | 104 |
(...skipping 16 matching lines...) Expand all Loading... |
153 int old_shortcut_id, | 121 int old_shortcut_id, |
154 int new_shortcut_id) { | 122 int new_shortcut_id) { |
155 base::string16 old_shortcut = l10n_util::GetStringUTF16(old_shortcut_id); | 123 base::string16 old_shortcut = l10n_util::GetStringUTF16(old_shortcut_id); |
156 base::string16 new_shortcut = l10n_util::GetStringUTF16(new_shortcut_id); | 124 base::string16 new_shortcut = l10n_util::GetStringUTF16(new_shortcut_id); |
157 EnsureNoWordBreaks(&old_shortcut); | 125 EnsureNoWordBreaks(&old_shortcut); |
158 EnsureNoWordBreaks(&new_shortcut); | 126 EnsureNoWordBreaks(&new_shortcut); |
159 | 127 |
160 return l10n_util::GetStringFUTF16(message_id, new_shortcut, old_shortcut); | 128 return l10n_util::GetStringFUTF16(message_id, new_shortcut, old_shortcut); |
161 } | 129 } |
162 | 130 |
163 void ShowDeprecatedAcceleratorNotification(const char* const notification_id, | |
164 int message_id, | |
165 int old_shortcut_id, | |
166 int new_shortcut_id) { | |
167 const base::string16 message = | |
168 GetNotificationText(message_id, old_shortcut_id, new_shortcut_id); | |
169 std::unique_ptr<message_center::Notification> notification( | |
170 new message_center::Notification( | |
171 message_center::NOTIFICATION_TYPE_SIMPLE, notification_id, | |
172 base::string16(), message, | |
173 WmShell::Get()->delegate()->GetDeprecatedAcceleratorImage(), | |
174 base::string16(), GURL(), | |
175 message_center::NotifierId( | |
176 message_center::NotifierId::SYSTEM_COMPONENT, | |
177 system_notifier::kNotifierDeprecatedAccelerator), | |
178 message_center::RichNotificationData(), | |
179 new DeprecatedAcceleratorNotificationDelegate)); | |
180 message_center::MessageCenter::Get()->AddNotification( | |
181 std::move(notification)); | |
182 } | |
183 | |
184 void RecordUmaHistogram(const char* histogram_name, | |
185 DeprecatedAcceleratorUsage sample) { | |
186 auto* histogram = base::LinearHistogram::FactoryGet( | |
187 histogram_name, 1, DEPRECATED_USAGE_COUNT, DEPRECATED_USAGE_COUNT + 1, | |
188 base::HistogramBase::kUmaTargetedHistogramFlag); | |
189 histogram->Add(sample); | |
190 } | |
191 | |
192 void HandleCycleBackwardMRU(const ui::Accelerator& accelerator) { | |
193 if (accelerator.key_code() == ui::VKEY_TAB) | |
194 base::RecordAction(base::UserMetricsAction("Accel_PrevWindow_Tab")); | |
195 | |
196 WmShell::Get()->window_cycle_controller()->HandleCycleWindow( | |
197 WindowCycleController::BACKWARD); | |
198 } | |
199 | |
200 void HandleCycleForwardMRU(const ui::Accelerator& accelerator) { | |
201 if (accelerator.key_code() == ui::VKEY_TAB) | |
202 base::RecordAction(base::UserMetricsAction("Accel_NextWindow_Tab")); | |
203 | |
204 WmShell::Get()->window_cycle_controller()->HandleCycleWindow( | |
205 WindowCycleController::FORWARD); | |
206 } | |
207 | |
208 void HandleRotatePaneFocus(FocusCycler::Direction direction) { | |
209 switch (direction) { | |
210 // TODO(stevet): Not sure if this is the same as IDC_FOCUS_NEXT_PANE. | |
211 case FocusCycler::FORWARD: { | |
212 base::RecordAction(UserMetricsAction("Accel_Focus_Next_Pane")); | |
213 break; | |
214 } | |
215 case FocusCycler::BACKWARD: { | |
216 base::RecordAction(UserMetricsAction("Accel_Focus_Previous_Pane")); | |
217 break; | |
218 } | |
219 } | |
220 WmShell::Get()->focus_cycler()->RotateFocus(direction); | |
221 } | |
222 | |
223 void HandleFocusShelf() { | 131 void HandleFocusShelf() { |
224 base::RecordAction(base::UserMetricsAction("Accel_Focus_Shelf")); | 132 base::RecordAction(UserMetricsAction("Accel_Focus_Shelf")); |
225 WmShell::Get()->focus_cycler()->FocusWidget( | 133 WmShell::Get()->focus_cycler()->FocusWidget( |
226 Shelf::ForPrimaryDisplay()->shelf_widget()); | 134 Shelf::ForPrimaryDisplay()->shelf_widget()); |
227 } | 135 } |
228 | 136 |
229 void HandleLaunchAppN(int n) { | 137 void HandleLaunchAppN(int n) { |
230 base::RecordAction(UserMetricsAction("Accel_Launch_App")); | 138 base::RecordAction(UserMetricsAction("Accel_Launch_App")); |
231 Shelf::ForPrimaryDisplay()->LaunchAppIndexAt(n); | 139 Shelf::ForPrimaryDisplay()->LaunchAppIndexAt(n); |
232 } | 140 } |
233 | 141 |
234 void HandleLaunchLastApp() { | 142 void HandleLaunchLastApp() { |
(...skipping 21 matching lines...) Expand all Loading... |
256 Shell::GetInstance()->magnification_controller()->SetScale( | 164 Shell::GetInstance()->magnification_controller()->SetScale( |
257 std::pow(kMagnificationScaleFactor, new_scale_index), true); | 165 std::pow(kMagnificationScaleFactor, new_scale_index), true); |
258 } else if (Shell::GetInstance() | 166 } else if (Shell::GetInstance() |
259 ->partial_magnification_controller() | 167 ->partial_magnification_controller() |
260 ->is_enabled()) { | 168 ->is_enabled()) { |
261 float scale = delta_index > 0 ? kDefaultPartialMagnifiedScale : 1; | 169 float scale = delta_index > 0 ? kDefaultPartialMagnifiedScale : 1; |
262 Shell::GetInstance()->partial_magnification_controller()->SetScale(scale); | 170 Shell::GetInstance()->partial_magnification_controller()->SetScale(scale); |
263 } | 171 } |
264 } | 172 } |
265 | 173 |
266 void HandleMediaNextTrack() { | |
267 WmShell::Get()->media_delegate()->HandleMediaNextTrack(); | |
268 } | |
269 | |
270 void HandleMediaPlayPause() { | |
271 WmShell::Get()->media_delegate()->HandleMediaPlayPause(); | |
272 } | |
273 | |
274 void HandleMediaPrevTrack() { | |
275 WmShell::Get()->media_delegate()->HandleMediaPrevTrack(); | |
276 } | |
277 | |
278 bool CanHandleNewIncognitoWindow() { | 174 bool CanHandleNewIncognitoWindow() { |
279 return WmShell::Get()->delegate()->IsIncognitoAllowed(); | 175 return WmShell::Get()->delegate()->IsIncognitoAllowed(); |
280 } | 176 } |
281 | 177 |
282 void HandleNewIncognitoWindow() { | 178 void HandleNewIncognitoWindow() { |
283 base::RecordAction(UserMetricsAction("Accel_New_Incognito_Window")); | 179 base::RecordAction(UserMetricsAction("Accel_New_Incognito_Window")); |
284 Shell::GetInstance()->new_window_delegate()->NewWindow( | 180 Shell::GetInstance()->new_window_delegate()->NewWindow( |
285 true /* is_incognito */); | 181 true /* is_incognito */); |
286 } | 182 } |
287 | 183 |
288 void HandleNewTab(const ui::Accelerator& accelerator) { | 184 void HandleNewTab(const ui::Accelerator& accelerator) { |
289 if (accelerator.key_code() == ui::VKEY_T) | 185 if (accelerator.key_code() == ui::VKEY_T) |
290 base::RecordAction(base::UserMetricsAction("Accel_NewTab_T")); | 186 base::RecordAction(UserMetricsAction("Accel_NewTab_T")); |
291 Shell::GetInstance()->new_window_delegate()->NewTab(); | 187 Shell::GetInstance()->new_window_delegate()->NewTab(); |
292 } | 188 } |
293 | 189 |
294 void HandleNewWindow() { | 190 void HandleNewWindow() { |
295 base::RecordAction(base::UserMetricsAction("Accel_New_Window")); | 191 base::RecordAction(UserMetricsAction("Accel_New_Window")); |
296 Shell::GetInstance()->new_window_delegate()->NewWindow( | 192 Shell::GetInstance()->new_window_delegate()->NewWindow( |
297 false /* is_incognito */); | 193 false /* is_incognito */); |
298 } | 194 } |
299 | 195 |
300 bool CanHandleNextIme(ImeControlDelegate* ime_control_delegate) { | |
301 return ime_control_delegate && ime_control_delegate->CanCycleIme(); | |
302 } | |
303 | |
304 // We must avoid showing the Deprecated NEXT_IME notification erronously. | |
305 bool ShouldShowDeprecatedNextImeNotification( | |
306 const ui::Accelerator& previous_accelerator) { | |
307 // We only show the deprecation notification if the previous accelerator key | |
308 // is ONLY either Shift, or Alt. | |
309 const ui::KeyboardCode previous_key_code = previous_accelerator.key_code(); | |
310 switch (previous_key_code) { | |
311 case ui::VKEY_SHIFT: | |
312 case ui::VKEY_LSHIFT: | |
313 case ui::VKEY_RSHIFT: | |
314 case ui::VKEY_MENU: | |
315 case ui::VKEY_LMENU: | |
316 case ui::VKEY_RMENU: | |
317 return true; | |
318 | |
319 default: | |
320 return false; | |
321 } | |
322 } | |
323 | |
324 void HandleNextIme(ImeControlDelegate* ime_control_delegate) { | |
325 base::RecordAction(UserMetricsAction("Accel_Next_Ime")); | |
326 ime_control_delegate->HandleNextIme(); | |
327 } | |
328 | |
329 void HandleOpenFeedbackPage() { | 196 void HandleOpenFeedbackPage() { |
330 base::RecordAction(UserMetricsAction("Accel_Open_Feedback_Page")); | 197 base::RecordAction(UserMetricsAction("Accel_Open_Feedback_Page")); |
331 Shell::GetInstance()->new_window_delegate()->OpenFeedbackPage(); | 198 Shell::GetInstance()->new_window_delegate()->OpenFeedbackPage(); |
332 } | 199 } |
333 | 200 |
334 bool CanHandlePreviousIme(ImeControlDelegate* ime_control_delegate) { | |
335 return ime_control_delegate && ime_control_delegate->CanCycleIme(); | |
336 } | |
337 | |
338 void HandlePreviousIme(ImeControlDelegate* ime_control_delegate, | |
339 const ui::Accelerator& accelerator) { | |
340 base::RecordAction(UserMetricsAction("Accel_Previous_Ime")); | |
341 if (accelerator.type() == ui::ET_KEY_PRESSED) | |
342 ime_control_delegate->HandlePreviousIme(); | |
343 // Else: consume the Ctrl+Space ET_KEY_RELEASED event but do not do anything. | |
344 } | |
345 | |
346 void HandleRestoreTab() { | 201 void HandleRestoreTab() { |
347 base::RecordAction(base::UserMetricsAction("Accel_Restore_Tab")); | 202 base::RecordAction(UserMetricsAction("Accel_Restore_Tab")); |
348 Shell::GetInstance()->new_window_delegate()->RestoreTab(); | 203 Shell::GetInstance()->new_window_delegate()->RestoreTab(); |
349 } | 204 } |
350 | 205 |
351 display::Display::Rotation GetNextRotation(display::Display::Rotation current) { | 206 display::Display::Rotation GetNextRotation(display::Display::Rotation current) { |
352 switch (current) { | 207 switch (current) { |
353 case display::Display::ROTATE_0: | 208 case display::Display::ROTATE_0: |
354 return display::Display::ROTATE_90; | 209 return display::Display::ROTATE_90; |
355 case display::Display::ROTATE_90: | 210 case display::Display::ROTATE_90: |
356 return display::Display::ROTATE_180; | 211 return display::Display::ROTATE_180; |
357 case display::Display::ROTATE_180: | 212 case display::Display::ROTATE_180: |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
430 RootWindowController::ForTargetRootWindow(); | 285 RootWindowController::ForTargetRootWindow(); |
431 if (!controller->GetSystemTray()->HasSystemBubble()) | 286 if (!controller->GetSystemTray()->HasSystemBubble()) |
432 controller->GetSystemTray()->ShowDefaultView(BUBBLE_CREATE_NEW); | 287 controller->GetSystemTray()->ShowDefaultView(BUBBLE_CREATE_NEW); |
433 } | 288 } |
434 | 289 |
435 void HandleShowTaskManager() { | 290 void HandleShowTaskManager() { |
436 base::RecordAction(UserMetricsAction("Accel_Show_Task_Manager")); | 291 base::RecordAction(UserMetricsAction("Accel_Show_Task_Manager")); |
437 Shell::GetInstance()->new_window_delegate()->ShowTaskManager(); | 292 Shell::GetInstance()->new_window_delegate()->ShowTaskManager(); |
438 } | 293 } |
439 | 294 |
440 bool CanHandleSwitchIme(ImeControlDelegate* ime_control_delegate, | |
441 const ui::Accelerator& accelerator) { | |
442 return ime_control_delegate && | |
443 ime_control_delegate->CanSwitchIme(accelerator); | |
444 } | |
445 | |
446 void HandleSwitchIme(ImeControlDelegate* ime_control_delegate, | |
447 const ui::Accelerator& accelerator) { | |
448 base::RecordAction(UserMetricsAction("Accel_Switch_Ime")); | |
449 ime_control_delegate->HandleSwitchIme(accelerator); | |
450 } | |
451 | |
452 void HandleTakeWindowScreenshot(ScreenshotDelegate* screenshot_delegate) { | 295 void HandleTakeWindowScreenshot(ScreenshotDelegate* screenshot_delegate) { |
453 base::RecordAction(UserMetricsAction("Accel_Take_Window_Screenshot")); | 296 base::RecordAction(UserMetricsAction("Accel_Take_Window_Screenshot")); |
454 DCHECK(screenshot_delegate); | 297 DCHECK(screenshot_delegate); |
455 Shell::GetInstance()->screenshot_controller()->StartWindowScreenshotSession( | 298 Shell::GetInstance()->screenshot_controller()->StartWindowScreenshotSession( |
456 screenshot_delegate); | 299 screenshot_delegate); |
457 } | 300 } |
458 | 301 |
459 void HandleTakePartialScreenshot(ScreenshotDelegate* screenshot_delegate) { | 302 void HandleTakePartialScreenshot(ScreenshotDelegate* screenshot_delegate) { |
460 base::RecordAction(UserMetricsAction("Accel_Take_Partial_Screenshot")); | 303 base::RecordAction(UserMetricsAction("Accel_Take_Partial_Screenshot")); |
461 DCHECK(screenshot_delegate); | 304 DCHECK(screenshot_delegate); |
(...skipping 23 matching lines...) Expand all Loading... |
485 // consume the key since Search+Shift is one of the shortcuts the a11y | 328 // consume the key since Search+Shift is one of the shortcuts the a11y |
486 // feature uses. crbug.com/132296 | 329 // feature uses. crbug.com/132296 |
487 if (WmShell::Get()->accessibility_delegate()->IsSpokenFeedbackEnabled()) | 330 if (WmShell::Get()->accessibility_delegate()->IsSpokenFeedbackEnabled()) |
488 return false; | 331 return false; |
489 } | 332 } |
490 return true; | 333 return true; |
491 } | 334 } |
492 | 335 |
493 void HandleToggleAppList(const ui::Accelerator& accelerator) { | 336 void HandleToggleAppList(const ui::Accelerator& accelerator) { |
494 if (accelerator.key_code() == ui::VKEY_LWIN) | 337 if (accelerator.key_code() == ui::VKEY_LWIN) |
495 base::RecordAction(base::UserMetricsAction("Accel_Search_LWin")); | 338 base::RecordAction(UserMetricsAction("Accel_Search_LWin")); |
496 Shell::GetInstance()->ToggleAppList(NULL); | 339 Shell::GetInstance()->ToggleAppList(nullptr); |
497 } | |
498 | |
499 void HandleToggleFullscreen(const ui::Accelerator& accelerator) { | |
500 if (accelerator.key_code() == ui::VKEY_MEDIA_LAUNCH_APP2) | |
501 base::RecordAction(UserMetricsAction("Accel_Fullscreen_F4")); | |
502 accelerators::ToggleFullscreen(); | |
503 } | |
504 | |
505 void HandleToggleOverview() { | |
506 base::RecordAction(base::UserMetricsAction("Accel_Overview_F5")); | |
507 WmShell::Get()->window_selector_controller()->ToggleOverview(); | |
508 } | |
509 | |
510 bool CanHandleWindowSnapOrDock() { | |
511 wm::WindowState* window_state = wm::GetActiveWindowState(); | |
512 // Disable window snapping shortcut key for full screen window due to | |
513 // http://crbug.com/135487. | |
514 return (window_state && window_state->IsUserPositionable() && | |
515 !window_state->IsFullscreen()); | |
516 } | |
517 | |
518 void HandleWindowSnapOrDock(AcceleratorAction action) { | |
519 if (action == WINDOW_CYCLE_SNAP_DOCK_LEFT) | |
520 base::RecordAction(UserMetricsAction("Accel_Window_Snap_Left")); | |
521 else | |
522 base::RecordAction(UserMetricsAction("Accel_Window_Snap_Right")); | |
523 | |
524 const wm::WMEvent event(action == WINDOW_CYCLE_SNAP_DOCK_LEFT | |
525 ? wm::WM_EVENT_CYCLE_SNAP_DOCK_LEFT | |
526 : wm::WM_EVENT_CYCLE_SNAP_DOCK_RIGHT); | |
527 wm::GetActiveWindowState()->OnWMEvent(&event); | |
528 } | |
529 | |
530 void HandleWindowMinimize() { | |
531 base::RecordAction(base::UserMetricsAction("Accel_Toggle_Minimized_Minus")); | |
532 accelerators::ToggleMinimized(); | |
533 } | |
534 | |
535 bool CanHandlePositionCenter() { | |
536 // Docked windows do not support centering. | |
537 wm::WindowState* window_state = wm::GetActiveWindowState(); | |
538 return (window_state && !window_state->IsDocked()); | |
539 } | |
540 | |
541 void HandlePositionCenter() { | |
542 base::RecordAction(UserMetricsAction("Accel_Window_Position_Center")); | |
543 wm::CenterWindow(wm::GetActiveWindow()); | |
544 } | 340 } |
545 | 341 |
546 bool CanHandleUnpin() { | 342 bool CanHandleUnpin() { |
547 wm::WindowState* window_state = wm::GetActiveWindowState(); | 343 wm::WindowState* window_state = wm::GetActiveWindowState(); |
548 return window_state && window_state->IsPinned(); | 344 return window_state && window_state->IsPinned(); |
549 } | 345 } |
550 | 346 |
551 void HandleUnpin() { | |
552 accelerators::Unpin(); | |
553 } | |
554 | |
555 #if defined(OS_CHROMEOS) | 347 #if defined(OS_CHROMEOS) |
556 bool CanHandleDisableCapsLock(const ui::Accelerator& previous_accelerator) { | |
557 ui::KeyboardCode previous_key_code = previous_accelerator.key_code(); | |
558 if (previous_accelerator.type() == ui::ET_KEY_RELEASED || | |
559 (previous_key_code != ui::VKEY_LSHIFT && | |
560 previous_key_code != ui::VKEY_SHIFT && | |
561 previous_key_code != ui::VKEY_RSHIFT)) { | |
562 // If something else was pressed between the Shift key being pressed | |
563 // and released, then ignore the release of the Shift key. | |
564 return false; | |
565 } | |
566 chromeos::input_method::InputMethodManager* ime = | |
567 chromeos::input_method::InputMethodManager::Get(); | |
568 chromeos::input_method::ImeKeyboard* keyboard = | |
569 ime ? ime->GetImeKeyboard() : NULL; | |
570 return (keyboard && keyboard->CapsLockIsEnabled()); | |
571 } | |
572 | |
573 void HandleDisableCapsLock() { | |
574 base::RecordAction(UserMetricsAction("Accel_Disable_Caps_Lock")); | |
575 chromeos::input_method::InputMethodManager* ime = | |
576 chromeos::input_method::InputMethodManager::Get(); | |
577 ime->GetImeKeyboard()->SetCapsLockEnabled(false); | |
578 } | |
579 | |
580 bool CanHandleLock() { | |
581 return WmShell::Get()->GetSessionStateDelegate()->CanLockScreen(); | |
582 } | |
583 | |
584 void HandleLock() { | |
585 base::RecordAction(UserMetricsAction("Accel_LockScreen_L")); | |
586 WmShell::Get()->GetSessionStateDelegate()->LockScreen(); | |
587 } | |
588 | |
589 void HandleSuspend() { | |
590 base::RecordAction(UserMetricsAction("Accel_Suspend")); | |
591 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->RequestSuspend(); | |
592 } | |
593 | |
594 void HandleCrosh() { | 348 void HandleCrosh() { |
595 base::RecordAction(UserMetricsAction("Accel_Open_Crosh")); | 349 base::RecordAction(UserMetricsAction("Accel_Open_Crosh")); |
596 | 350 |
597 Shell::GetInstance()->new_window_delegate()->OpenCrosh(); | 351 Shell::GetInstance()->new_window_delegate()->OpenCrosh(); |
598 } | 352 } |
599 | 353 |
600 void HandleFileManager() { | 354 void HandleFileManager() { |
601 base::RecordAction(UserMetricsAction("Accel_Open_File_Manager")); | 355 base::RecordAction(UserMetricsAction("Accel_Open_File_Manager")); |
602 | 356 |
603 Shell::GetInstance()->new_window_delegate()->OpenFileManager(); | 357 Shell::GetInstance()->new_window_delegate()->OpenFileManager(); |
604 } | 358 } |
605 | 359 |
606 void HandleGetHelp() { | 360 void HandleGetHelp() { |
607 Shell::GetInstance()->new_window_delegate()->OpenGetHelp(); | 361 Shell::GetInstance()->new_window_delegate()->OpenGetHelp(); |
608 } | 362 } |
609 | 363 |
610 void HandleSwapPrimaryDisplay() { | 364 void HandleSwapPrimaryDisplay() { |
611 base::RecordAction(UserMetricsAction("Accel_Swap_Primary_Display")); | 365 base::RecordAction(UserMetricsAction("Accel_Swap_Primary_Display")); |
612 Shell::GetInstance()->display_configuration_controller()->SetPrimaryDisplayId( | 366 Shell::GetInstance()->display_configuration_controller()->SetPrimaryDisplayId( |
613 ScreenUtil::GetSecondaryDisplay().id(), true /* user_action */); | 367 ScreenUtil::GetSecondaryDisplay().id(), true /* user_action */); |
614 } | 368 } |
615 | 369 |
616 bool CanHandleCycleUser() { | |
617 return WmShell::Get()->delegate()->IsMultiProfilesEnabled() && | |
618 WmShell::Get()->GetSessionStateDelegate()->NumberOfLoggedInUsers() > 1; | |
619 } | |
620 | |
621 void HandleCycleUser(SessionStateDelegate::CycleUser cycle_user) { | |
622 MultiProfileUMA::RecordSwitchActiveUser( | |
623 MultiProfileUMA::SWITCH_ACTIVE_USER_BY_ACCELERATOR); | |
624 switch (cycle_user) { | |
625 case SessionStateDelegate::CYCLE_TO_NEXT_USER: | |
626 base::RecordAction(UserMetricsAction("Accel_Switch_To_Next_User")); | |
627 break; | |
628 case SessionStateDelegate::CYCLE_TO_PREVIOUS_USER: | |
629 base::RecordAction(UserMetricsAction("Accel_Switch_To_Previous_User")); | |
630 break; | |
631 } | |
632 WmShell::Get()->GetSessionStateDelegate()->CycleActiveUser(cycle_user); | |
633 } | |
634 | |
635 bool CanHandleToggleCapsLock(const ui::Accelerator& accelerator, | |
636 const ui::Accelerator& previous_accelerator) { | |
637 if (accelerator.key_code() == ui::VKEY_LWIN) { | |
638 // If something else was pressed between the Search key (LWIN) | |
639 // being pressed and released, then ignore the release of the | |
640 // Search key. | |
641 // TODO(danakj): Releasing Alt first breaks this: crbug.com/166495 | |
642 if (previous_accelerator.type() == ui::ET_KEY_RELEASED || | |
643 previous_accelerator.key_code() != ui::VKEY_LWIN) | |
644 return false; | |
645 } | |
646 chromeos::input_method::InputMethodManager* ime = | |
647 chromeos::input_method::InputMethodManager::Get(); | |
648 return ime && ime->GetImeKeyboard(); | |
649 } | |
650 | |
651 void HandleToggleCapsLock() { | |
652 base::RecordAction(UserMetricsAction("Accel_Toggle_Caps_Lock")); | |
653 chromeos::input_method::InputMethodManager* ime = | |
654 chromeos::input_method::InputMethodManager::Get(); | |
655 chromeos::input_method::ImeKeyboard* keyboard = ime->GetImeKeyboard(); | |
656 keyboard->SetCapsLockEnabled(!keyboard->CapsLockIsEnabled()); | |
657 } | |
658 | |
659 void HandleToggleMirrorMode() { | 370 void HandleToggleMirrorMode() { |
660 base::RecordAction(UserMetricsAction("Accel_Toggle_Mirror_Mode")); | 371 base::RecordAction(UserMetricsAction("Accel_Toggle_Mirror_Mode")); |
661 bool mirror = !Shell::GetInstance()->display_manager()->IsInMirrorMode(); | 372 bool mirror = !Shell::GetInstance()->display_manager()->IsInMirrorMode(); |
662 Shell::GetInstance()->display_configuration_controller()->SetMirrorMode( | 373 Shell::GetInstance()->display_configuration_controller()->SetMirrorMode( |
663 mirror, true /* user_action */); | 374 mirror, true /* user_action */); |
664 } | 375 } |
665 | 376 |
666 void HandleToggleSpokenFeedback() { | |
667 base::RecordAction(UserMetricsAction("Accel_Toggle_Spoken_Feedback")); | |
668 | |
669 WmShell::Get()->accessibility_delegate()->ToggleSpokenFeedback( | |
670 A11Y_NOTIFICATION_SHOW); | |
671 } | |
672 | |
673 bool CanHandleTouchHud() { | 377 bool CanHandleTouchHud() { |
674 return RootWindowController::ForTargetRootWindow()->touch_hud_debug(); | 378 return RootWindowController::ForTargetRootWindow()->touch_hud_debug(); |
675 } | 379 } |
676 | 380 |
677 void HandleTouchHudClear() { | 381 void HandleTouchHudClear() { |
678 RootWindowController::ForTargetRootWindow()->touch_hud_debug()->Clear(); | 382 RootWindowController::ForTargetRootWindow()->touch_hud_debug()->Clear(); |
679 } | 383 } |
680 | 384 |
681 void HandleTouchHudModeChange() { | 385 void HandleTouchHudModeChange() { |
682 RootWindowController* controller = | 386 RootWindowController* controller = |
683 RootWindowController::ForTargetRootWindow(); | 387 RootWindowController::ForTargetRootWindow(); |
684 controller->touch_hud_debug()->ChangeToNextMode(); | 388 controller->touch_hud_debug()->ChangeToNextMode(); |
685 } | 389 } |
686 | 390 |
687 void HandleVolumeDown(const ui::Accelerator& accelerator) { | |
688 VolumeControlDelegate* volume_delegate = | |
689 WmShell::Get()->system_tray_delegate()->GetVolumeControlDelegate(); | |
690 if (volume_delegate) | |
691 volume_delegate->HandleVolumeDown(accelerator); | |
692 } | |
693 | |
694 void HandleVolumeMute(const ui::Accelerator& accelerator) { | |
695 VolumeControlDelegate* volume_delegate = | |
696 WmShell::Get()->system_tray_delegate()->GetVolumeControlDelegate(); | |
697 if (volume_delegate) | |
698 volume_delegate->HandleVolumeMute(accelerator); | |
699 } | |
700 | |
701 void HandleVolumeUp(const ui::Accelerator& accelerator) { | |
702 VolumeControlDelegate* volume_delegate = | |
703 WmShell::Get()->system_tray_delegate()->GetVolumeControlDelegate(); | |
704 if (volume_delegate) | |
705 volume_delegate->HandleVolumeUp(accelerator); | |
706 } | |
707 | |
708 #endif // defined(OS_CHROMEOS) | 391 #endif // defined(OS_CHROMEOS) |
709 | 392 |
710 } // namespace | 393 } // namespace |
711 | 394 |
712 //////////////////////////////////////////////////////////////////////////////// | 395 AcceleratorControllerDelegateAura::AcceleratorControllerDelegateAura() {} |
713 // AcceleratorController, public: | |
714 | 396 |
715 AcceleratorController::AcceleratorController() | 397 AcceleratorControllerDelegateAura::~AcceleratorControllerDelegateAura() {} |
716 : accelerator_manager_(new ui::AcceleratorManager), | 398 |
717 accelerator_history_(new ui::AcceleratorHistory) { | 399 void AcceleratorControllerDelegateAura::SetScreenshotDelegate( |
718 Init(); | 400 std::unique_ptr<ScreenshotDelegate> screenshot_delegate) { |
| 401 screenshot_delegate_ = std::move(screenshot_delegate); |
719 } | 402 } |
720 | 403 |
721 AcceleratorController::~AcceleratorController() {} | 404 bool AcceleratorControllerDelegateAura::HandlesAction( |
| 405 AcceleratorAction action) { |
| 406 switch (action) { |
| 407 case FOCUS_SHELF: |
| 408 case LAUNCH_APP_0: |
| 409 case LAUNCH_APP_1: |
| 410 case LAUNCH_APP_2: |
| 411 case LAUNCH_APP_3: |
| 412 case LAUNCH_APP_4: |
| 413 case LAUNCH_APP_5: |
| 414 case LAUNCH_APP_6: |
| 415 case LAUNCH_APP_7: |
| 416 case LAUNCH_LAST_APP: |
| 417 case MAGNIFY_SCREEN_ZOOM_IN: |
| 418 case MAGNIFY_SCREEN_ZOOM_OUT: |
| 419 case NEW_INCOGNITO_WINDOW: |
| 420 case NEW_TAB: |
| 421 case NEW_WINDOW: |
| 422 case OPEN_FEEDBACK_PAGE: |
| 423 case RESTORE_TAB: |
| 424 case ROTATE_SCREEN: |
| 425 case ROTATE_WINDOW: |
| 426 case SCALE_UI_DOWN: |
| 427 case SCALE_UI_RESET: |
| 428 case SCALE_UI_UP: |
| 429 case SHOW_KEYBOARD_OVERLAY: |
| 430 case SHOW_MESSAGE_CENTER_BUBBLE: |
| 431 case SHOW_SYSTEM_TRAY_BUBBLE: |
| 432 case SHOW_TASK_MANAGER: |
| 433 case TAKE_PARTIAL_SCREENSHOT: |
| 434 case TAKE_SCREENSHOT: |
| 435 case TAKE_WINDOW_SCREENSHOT: |
| 436 case TOGGLE_APP_LIST: |
| 437 case UNPIN: |
| 438 return true; |
722 | 439 |
723 void AcceleratorController::Register(const ui::Accelerator& accelerator, | 440 #if defined(OS_CHROMEOS) |
724 ui::AcceleratorTarget* target) { | 441 case DISABLE_GPU_WATCHDOG: |
725 accelerator_manager_->Register( | 442 case LOCK_PRESSED: |
726 accelerator, ui::AcceleratorManager::kNormalPriority, target); | 443 case LOCK_RELEASED: |
727 } | 444 case OPEN_CROSH: |
| 445 case OPEN_FILE_MANAGER: |
| 446 case OPEN_GET_HELP: |
| 447 case POWER_PRESSED: |
| 448 case POWER_RELEASED: |
| 449 case SWAP_PRIMARY_DISPLAY: |
| 450 case TOGGLE_MIRROR_MODE: |
| 451 case TOUCH_HUD_CLEAR: |
| 452 case TOUCH_HUD_MODE_CHANGE: |
| 453 case TOUCH_HUD_PROJECTION_TOGGLE: |
| 454 return true; |
| 455 #endif |
728 | 456 |
729 void AcceleratorController::Unregister(const ui::Accelerator& accelerator, | 457 default: |
730 ui::AcceleratorTarget* target) { | 458 break; |
731 accelerator_manager_->Unregister(accelerator, target); | |
732 } | |
733 | |
734 void AcceleratorController::UnregisterAll(ui::AcceleratorTarget* target) { | |
735 accelerator_manager_->UnregisterAll(target); | |
736 } | |
737 | |
738 bool AcceleratorController::Process(const ui::Accelerator& accelerator) { | |
739 return accelerator_manager_->Process(accelerator); | |
740 } | |
741 | |
742 bool AcceleratorController::IsRegistered( | |
743 const ui::Accelerator& accelerator) const { | |
744 return accelerator_manager_->IsRegistered(accelerator); | |
745 } | |
746 | |
747 bool AcceleratorController::IsPreferred( | |
748 const ui::Accelerator& accelerator) const { | |
749 std::map<ui::Accelerator, AcceleratorAction>::const_iterator iter = | |
750 accelerators_.find(accelerator); | |
751 if (iter == accelerators_.end()) | |
752 return false; // not an accelerator. | |
753 | |
754 return preferred_actions_.find(iter->second) != preferred_actions_.end(); | |
755 } | |
756 | |
757 bool AcceleratorController::IsReserved( | |
758 const ui::Accelerator& accelerator) const { | |
759 std::map<ui::Accelerator, AcceleratorAction>::const_iterator iter = | |
760 accelerators_.find(accelerator); | |
761 if (iter == accelerators_.end()) | |
762 return false; // not an accelerator. | |
763 | |
764 return reserved_actions_.find(iter->second) != reserved_actions_.end(); | |
765 } | |
766 | |
767 bool AcceleratorController::IsDeprecated( | |
768 const ui::Accelerator& accelerator) const { | |
769 return deprecated_accelerators_.count(accelerator) != 0; | |
770 } | |
771 | |
772 bool AcceleratorController::PerformActionIfEnabled(AcceleratorAction action) { | |
773 if (CanPerformAction(action, ui::Accelerator())) { | |
774 PerformAction(action, ui::Accelerator()); | |
775 return true; | |
776 } | 459 } |
777 return false; | 460 return false; |
778 } | 461 } |
779 | 462 |
780 AcceleratorController::AcceleratorProcessingRestriction | 463 bool AcceleratorControllerDelegateAura::CanPerformAction( |
781 AcceleratorController::GetCurrentAcceleratorRestriction() { | |
782 return GetAcceleratorProcessingRestriction(-1); | |
783 } | |
784 | |
785 void AcceleratorController::SetImeControlDelegate( | |
786 std::unique_ptr<ImeControlDelegate> ime_control_delegate) { | |
787 ime_control_delegate_ = std::move(ime_control_delegate); | |
788 } | |
789 | |
790 void AcceleratorController::SetScreenshotDelegate( | |
791 std::unique_ptr<ScreenshotDelegate> screenshot_delegate) { | |
792 screenshot_delegate_ = std::move(screenshot_delegate); | |
793 } | |
794 | |
795 bool AcceleratorController::ShouldCloseMenuAndRepostAccelerator( | |
796 const ui::Accelerator& accelerator) const { | |
797 auto itr = accelerators_.find(accelerator); | |
798 if (itr == accelerators_.end()) | |
799 return false; // Menu shouldn't be closed for an invalid accelerator. | |
800 | |
801 AcceleratorAction action = itr->second; | |
802 return actions_keeping_menu_open_.count(action) == 0; | |
803 } | |
804 | |
805 //////////////////////////////////////////////////////////////////////////////// | |
806 // AcceleratorController, ui::AcceleratorTarget implementation: | |
807 | |
808 bool AcceleratorController::AcceleratorPressed( | |
809 const ui::Accelerator& accelerator) { | |
810 std::map<ui::Accelerator, AcceleratorAction>::const_iterator it = | |
811 accelerators_.find(accelerator); | |
812 DCHECK(it != accelerators_.end()); | |
813 AcceleratorAction action = it->second; | |
814 if (CanPerformAction(action, accelerator)) { | |
815 // Handling the deprecated accelerators (if any) only if action can be | |
816 // performed. | |
817 auto itr = actions_with_deprecations_.find(action); | |
818 if (itr != actions_with_deprecations_.end()) { | |
819 const DeprecatedAcceleratorData* data = itr->second; | |
820 if (deprecated_accelerators_.count(accelerator)) { | |
821 // This accelerator has been deprecated and should be treated according | |
822 // to its |DeprecatedAcceleratorData|. | |
823 | |
824 // Record UMA stats. | |
825 RecordUmaHistogram(data->uma_histogram_name, DEPRECATED_USED); | |
826 | |
827 // We always display the notification as long as this entry exists, | |
828 // except for NEXT_IME, we must check to avoid showing it for the wrong | |
829 // shortcut, as Alt+Shift is tricky and trigger the action on release. | |
830 if (action != NEXT_IME || | |
831 (action == NEXT_IME && | |
832 ShouldShowDeprecatedNextImeNotification( | |
833 accelerator_history_->previous_accelerator()))) { | |
834 ShowDeprecatedAcceleratorNotification( | |
835 data->uma_histogram_name, data->notification_message_id, | |
836 data->old_shortcut_id, data->new_shortcut_id); | |
837 } | |
838 | |
839 if (!data->deprecated_enabled) | |
840 return false; | |
841 } else { | |
842 // This is a new accelerator replacing the old deprecated one. | |
843 // Record UMA stats and proceed normally. | |
844 RecordUmaHistogram(data->uma_histogram_name, NEW_USED); | |
845 } | |
846 } | |
847 | |
848 PerformAction(action, accelerator); | |
849 return ShouldActionConsumeKeyEvent(action); | |
850 } | |
851 return false; | |
852 } | |
853 | |
854 bool AcceleratorController::CanHandleAccelerators() const { | |
855 return true; | |
856 } | |
857 | |
858 /////////////////////////////////////////////////////////////////////////////// | |
859 // AcceleratorController, private: | |
860 | |
861 void AcceleratorController::Init() { | |
862 for (size_t i = 0; i < kActionsAllowedAtLoginOrLockScreenLength; ++i) { | |
863 actions_allowed_at_login_screen_.insert( | |
864 kActionsAllowedAtLoginOrLockScreen[i]); | |
865 actions_allowed_at_lock_screen_.insert( | |
866 kActionsAllowedAtLoginOrLockScreen[i]); | |
867 } | |
868 for (size_t i = 0; i < kActionsAllowedAtLockScreenLength; ++i) | |
869 actions_allowed_at_lock_screen_.insert(kActionsAllowedAtLockScreen[i]); | |
870 for (size_t i = 0; i < kActionsAllowedAtModalWindowLength; ++i) | |
871 actions_allowed_at_modal_window_.insert(kActionsAllowedAtModalWindow[i]); | |
872 for (size_t i = 0; i < kPreferredActionsLength; ++i) | |
873 preferred_actions_.insert(kPreferredActions[i]); | |
874 for (size_t i = 0; i < kReservedActionsLength; ++i) | |
875 reserved_actions_.insert(kReservedActions[i]); | |
876 for (size_t i = 0; i < kRepeatableActionsLength; ++i) | |
877 repeatable_actions_.insert(kRepeatableActions[i]); | |
878 for (size_t i = 0; i < kActionsAllowedInAppModeOrPinnedModeLength; ++i) { | |
879 actions_allowed_in_app_mode_.insert( | |
880 kActionsAllowedInAppModeOrPinnedMode[i]); | |
881 actions_allowed_in_pinned_mode_.insert( | |
882 kActionsAllowedInAppModeOrPinnedMode[i]); | |
883 } | |
884 for (size_t i = 0; i < kActionsAllowedInPinnedModeLength; ++i) | |
885 actions_allowed_in_pinned_mode_.insert(kActionsAllowedInPinnedMode[i]); | |
886 for (size_t i = 0; i < kActionsNeedingWindowLength; ++i) | |
887 actions_needing_window_.insert(kActionsNeedingWindow[i]); | |
888 for (size_t i = 0; i < kActionsKeepingMenuOpenLength; ++i) | |
889 actions_keeping_menu_open_.insert(kActionsKeepingMenuOpen[i]); | |
890 | |
891 RegisterAccelerators(kAcceleratorData, kAcceleratorDataLength); | |
892 | |
893 RegisterDeprecatedAccelerators(); | |
894 | |
895 if (debug::DebugAcceleratorsEnabled()) { | |
896 RegisterAccelerators(kDebugAcceleratorData, kDebugAcceleratorDataLength); | |
897 // All debug accelerators are reserved. | |
898 for (size_t i = 0; i < kDebugAcceleratorDataLength; ++i) | |
899 reserved_actions_.insert(kDebugAcceleratorData[i].action); | |
900 } | |
901 } | |
902 | |
903 void AcceleratorController::RegisterAccelerators( | |
904 const AcceleratorData accelerators[], | |
905 size_t accelerators_length) { | |
906 for (size_t i = 0; i < accelerators_length; ++i) { | |
907 ui::Accelerator accelerator = | |
908 CreateAccelerator(accelerators[i].keycode, accelerators[i].modifiers, | |
909 accelerators[i].trigger_on_press); | |
910 Register(accelerator, this); | |
911 accelerators_.insert(std::make_pair(accelerator, accelerators[i].action)); | |
912 } | |
913 } | |
914 | |
915 void AcceleratorController::RegisterDeprecatedAccelerators() { | |
916 #if defined(OS_CHROMEOS) | |
917 for (size_t i = 0; i < kDeprecatedAcceleratorsDataLength; ++i) { | |
918 const DeprecatedAcceleratorData* data = &kDeprecatedAcceleratorsData[i]; | |
919 actions_with_deprecations_[data->action] = data; | |
920 } | |
921 | |
922 for (size_t i = 0; i < kDeprecatedAcceleratorsLength; ++i) { | |
923 const AcceleratorData& accelerator_data = kDeprecatedAccelerators[i]; | |
924 const ui::Accelerator deprecated_accelerator = | |
925 CreateAccelerator(accelerator_data.keycode, accelerator_data.modifiers, | |
926 accelerator_data.trigger_on_press); | |
927 | |
928 Register(deprecated_accelerator, this); | |
929 accelerators_[deprecated_accelerator] = accelerator_data.action; | |
930 deprecated_accelerators_.insert(deprecated_accelerator); | |
931 } | |
932 #endif // defined(OS_CHROMEOS) | |
933 } | |
934 | |
935 bool AcceleratorController::CanPerformAction( | |
936 AcceleratorAction action, | 464 AcceleratorAction action, |
937 const ui::Accelerator& accelerator) { | 465 const ui::Accelerator& accelerator, |
938 if (accelerator.IsRepeat() && !repeatable_actions_.count(action)) | 466 const ui::Accelerator& previous_accelerator) { |
939 return false; | |
940 | |
941 AcceleratorProcessingRestriction restriction = | |
942 GetAcceleratorProcessingRestriction(action); | |
943 if (restriction != RESTRICTION_NONE) | |
944 return restriction == RESTRICTION_PREVENT_PROCESSING_AND_PROPAGATION; | |
945 | |
946 const ui::Accelerator& previous_accelerator = | |
947 accelerator_history_->previous_accelerator(); | |
948 | |
949 // True should be returned if running |action| does something. Otherwise, | |
950 // false should be returned to give the web contents a chance at handling the | |
951 // accelerator. | |
952 switch (action) { | 467 switch (action) { |
953 case DEBUG_PRINT_LAYER_HIERARCHY: | |
954 case DEBUG_PRINT_VIEW_HIERARCHY: | |
955 case DEBUG_PRINT_WINDOW_HIERARCHY: | |
956 case DEBUG_TOGGLE_DESKTOP_BACKGROUND_MODE: | |
957 case DEBUG_TOGGLE_DEVICE_SCALE_FACTOR: | |
958 case DEBUG_TOGGLE_ROOT_WINDOW_FULL_SCREEN: | |
959 case DEBUG_TOGGLE_SHOW_DEBUG_BORDERS: | |
960 case DEBUG_TOGGLE_SHOW_FPS_COUNTER: | |
961 case DEBUG_TOGGLE_SHOW_PAINT_RECTS: | |
962 return debug::DebugAcceleratorsEnabled(); | |
963 case MAGNIFY_SCREEN_ZOOM_IN: | 468 case MAGNIFY_SCREEN_ZOOM_IN: |
964 case MAGNIFY_SCREEN_ZOOM_OUT: | 469 case MAGNIFY_SCREEN_ZOOM_OUT: |
965 return CanHandleMagnifyScreen(); | 470 return CanHandleMagnifyScreen(); |
966 case NEW_INCOGNITO_WINDOW: | 471 case NEW_INCOGNITO_WINDOW: |
967 return CanHandleNewIncognitoWindow(); | 472 return CanHandleNewIncognitoWindow(); |
968 case NEXT_IME: | 473 case SCALE_UI_DOWN: |
969 return CanHandleNextIme(ime_control_delegate_.get()); | |
970 case PREVIOUS_IME: | |
971 return CanHandlePreviousIme(ime_control_delegate_.get()); | |
972 case SCALE_UI_RESET: | 474 case SCALE_UI_RESET: |
973 case SCALE_UI_UP: | 475 case SCALE_UI_UP: |
974 case SCALE_UI_DOWN: | |
975 return accelerators::IsInternalDisplayZoomEnabled(); | 476 return accelerators::IsInternalDisplayZoomEnabled(); |
976 case SHOW_MESSAGE_CENTER_BUBBLE: | 477 case SHOW_MESSAGE_CENTER_BUBBLE: |
977 return CanHandleShowMessageCenterBubble(); | 478 return CanHandleShowMessageCenterBubble(); |
978 case SWITCH_IME: | |
979 return CanHandleSwitchIme(ime_control_delegate_.get(), accelerator); | |
980 case TOGGLE_APP_LIST: | 479 case TOGGLE_APP_LIST: |
981 return CanHandleToggleAppList(accelerator, previous_accelerator); | 480 return CanHandleToggleAppList(accelerator, previous_accelerator); |
982 case WINDOW_CYCLE_SNAP_DOCK_LEFT: | |
983 case WINDOW_CYCLE_SNAP_DOCK_RIGHT: | |
984 return CanHandleWindowSnapOrDock(); | |
985 case WINDOW_POSITION_CENTER: | |
986 return CanHandlePositionCenter(); | |
987 case UNPIN: | 481 case UNPIN: |
988 return CanHandleUnpin(); | 482 return CanHandleUnpin(); |
989 #if defined(OS_CHROMEOS) | 483 |
990 case DEBUG_ADD_REMOVE_DISPLAY: | 484 // Following are always enabled: |
991 case DEBUG_SHOW_TOAST: | |
992 case DEBUG_TOGGLE_TOUCH_PAD: | |
993 case DEBUG_TOGGLE_TOUCH_SCREEN: | |
994 case DEBUG_TOGGLE_TOUCH_VIEW: | |
995 case DEBUG_TOGGLE_UNIFIED_DESKTOP: | |
996 return debug::DebugAcceleratorsEnabled(); | |
997 case DISABLE_CAPS_LOCK: | |
998 return CanHandleDisableCapsLock(previous_accelerator); | |
999 case LOCK_SCREEN: | |
1000 return CanHandleLock(); | |
1001 case SWITCH_TO_PREVIOUS_USER: | |
1002 case SWITCH_TO_NEXT_USER: | |
1003 return CanHandleCycleUser(); | |
1004 case TOGGLE_CAPS_LOCK: | |
1005 return CanHandleToggleCapsLock(accelerator, previous_accelerator); | |
1006 case TOUCH_HUD_CLEAR: | |
1007 case TOUCH_HUD_MODE_CHANGE: | |
1008 return CanHandleTouchHud(); | |
1009 case SWAP_PRIMARY_DISPLAY: | |
1010 return display::Screen::GetScreen()->GetNumDisplays() > 1; | |
1011 #endif | |
1012 case CYCLE_BACKWARD_MRU: | |
1013 case CYCLE_FORWARD_MRU: | |
1014 case EXIT: | |
1015 case FOCUS_NEXT_PANE: | |
1016 case FOCUS_PREVIOUS_PANE: | |
1017 case FOCUS_SHELF: | 485 case FOCUS_SHELF: |
1018 case LAUNCH_APP_0: | 486 case LAUNCH_APP_0: |
1019 case LAUNCH_APP_1: | 487 case LAUNCH_APP_1: |
1020 case LAUNCH_APP_2: | 488 case LAUNCH_APP_2: |
1021 case LAUNCH_APP_3: | 489 case LAUNCH_APP_3: |
1022 case LAUNCH_APP_4: | 490 case LAUNCH_APP_4: |
1023 case LAUNCH_APP_5: | 491 case LAUNCH_APP_5: |
1024 case LAUNCH_APP_6: | 492 case LAUNCH_APP_6: |
1025 case LAUNCH_APP_7: | 493 case LAUNCH_APP_7: |
1026 case LAUNCH_LAST_APP: | 494 case LAUNCH_LAST_APP: |
1027 case MEDIA_NEXT_TRACK: | |
1028 case MEDIA_PLAY_PAUSE: | |
1029 case MEDIA_PREV_TRACK: | |
1030 case NEW_TAB: | 495 case NEW_TAB: |
1031 case NEW_WINDOW: | 496 case NEW_WINDOW: |
1032 case OPEN_FEEDBACK_PAGE: | 497 case OPEN_FEEDBACK_PAGE: |
1033 case PRINT_UI_HIERARCHIES: | |
1034 case RESTORE_TAB: | 498 case RESTORE_TAB: |
1035 case ROTATE_SCREEN: | 499 case ROTATE_SCREEN: |
1036 case ROTATE_WINDOW: | 500 case ROTATE_WINDOW: |
1037 case SHOW_KEYBOARD_OVERLAY: | 501 case SHOW_KEYBOARD_OVERLAY: |
1038 case SHOW_SYSTEM_TRAY_BUBBLE: | 502 case SHOW_SYSTEM_TRAY_BUBBLE: |
1039 case SHOW_TASK_MANAGER: | 503 case SHOW_TASK_MANAGER: |
1040 case TAKE_WINDOW_SCREENSHOT: | |
1041 case TAKE_PARTIAL_SCREENSHOT: | 504 case TAKE_PARTIAL_SCREENSHOT: |
1042 case TAKE_SCREENSHOT: | 505 case TAKE_SCREENSHOT: |
1043 case TOGGLE_FULLSCREEN: | 506 case TAKE_WINDOW_SCREENSHOT: |
1044 case TOGGLE_MAXIMIZED: | 507 return true; |
1045 case TOGGLE_OVERVIEW: | 508 |
1046 case WINDOW_MINIMIZE: | |
1047 #if defined(OS_CHROMEOS) | 509 #if defined(OS_CHROMEOS) |
1048 case BRIGHTNESS_DOWN: | 510 case SWAP_PRIMARY_DISPLAY: |
1049 case BRIGHTNESS_UP: | 511 return display::Screen::GetScreen()->GetNumDisplays() > 1; |
| 512 case TOUCH_HUD_CLEAR: |
| 513 case TOUCH_HUD_MODE_CHANGE: |
| 514 return CanHandleTouchHud(); |
| 515 |
| 516 // Following are always enabled. |
1050 case DISABLE_GPU_WATCHDOG: | 517 case DISABLE_GPU_WATCHDOG: |
1051 case KEYBOARD_BRIGHTNESS_DOWN: | |
1052 case KEYBOARD_BRIGHTNESS_UP: | |
1053 case LOCK_PRESSED: | 518 case LOCK_PRESSED: |
1054 case LOCK_RELEASED: | 519 case LOCK_RELEASED: |
1055 case OPEN_CROSH: | 520 case OPEN_CROSH: |
1056 case OPEN_FILE_MANAGER: | 521 case OPEN_FILE_MANAGER: |
1057 case OPEN_GET_HELP: | 522 case OPEN_GET_HELP: |
1058 case POWER_PRESSED: | 523 case POWER_PRESSED: |
1059 case POWER_RELEASED: | 524 case POWER_RELEASED: |
1060 case SUSPEND: | |
1061 case TOGGLE_MIRROR_MODE: | 525 case TOGGLE_MIRROR_MODE: |
1062 case TOGGLE_SPOKEN_FEEDBACK: | |
1063 case TOGGLE_WIFI: | |
1064 case TOUCH_HUD_PROJECTION_TOGGLE: | 526 case TOUCH_HUD_PROJECTION_TOGGLE: |
1065 case VOLUME_DOWN: | 527 return true; |
1066 case VOLUME_MUTE: | |
1067 case VOLUME_UP: | |
1068 #else | |
1069 case DUMMY_FOR_RESERVED: | |
1070 #endif | 528 #endif |
1071 return true; | 529 |
| 530 default: |
| 531 NOTREACHED(); |
| 532 break; |
1072 } | 533 } |
1073 return false; | 534 return false; |
1074 } | 535 } |
1075 | 536 |
1076 void AcceleratorController::PerformAction(AcceleratorAction action, | 537 void AcceleratorControllerDelegateAura::PerformAction( |
1077 const ui::Accelerator& accelerator) { | 538 AcceleratorAction action, |
1078 AcceleratorProcessingRestriction restriction = | 539 const ui::Accelerator& accelerator) { |
1079 GetAcceleratorProcessingRestriction(action); | |
1080 if (restriction != RESTRICTION_NONE) | |
1081 return; | |
1082 | |
1083 // If your accelerator invokes more than one line of code, please either | |
1084 // implement it in your module's controller code (like TOGGLE_MIRROR_MODE | |
1085 // below) or pull it into a HandleFoo() function above. | |
1086 switch (action) { | 540 switch (action) { |
1087 case CYCLE_BACKWARD_MRU: | |
1088 HandleCycleBackwardMRU(accelerator); | |
1089 break; | |
1090 case CYCLE_FORWARD_MRU: | |
1091 HandleCycleForwardMRU(accelerator); | |
1092 break; | |
1093 case DEBUG_PRINT_LAYER_HIERARCHY: | |
1094 case DEBUG_PRINT_VIEW_HIERARCHY: | |
1095 case DEBUG_PRINT_WINDOW_HIERARCHY: | |
1096 case DEBUG_TOGGLE_DESKTOP_BACKGROUND_MODE: | |
1097 case DEBUG_TOGGLE_DEVICE_SCALE_FACTOR: | |
1098 case DEBUG_TOGGLE_ROOT_WINDOW_FULL_SCREEN: | |
1099 case DEBUG_TOGGLE_SHOW_DEBUG_BORDERS: | |
1100 case DEBUG_TOGGLE_SHOW_FPS_COUNTER: | |
1101 case DEBUG_TOGGLE_SHOW_PAINT_RECTS: | |
1102 debug::PerformDebugActionIfEnabled(action); | |
1103 break; | |
1104 case EXIT: | |
1105 // UMA metrics are recorded in the handler. | |
1106 exit_warning_handler_.HandleAccelerator(); | |
1107 break; | |
1108 case FOCUS_NEXT_PANE: | |
1109 HandleRotatePaneFocus(FocusCycler::FORWARD); | |
1110 break; | |
1111 case FOCUS_PREVIOUS_PANE: | |
1112 HandleRotatePaneFocus(FocusCycler::BACKWARD); | |
1113 break; | |
1114 case FOCUS_SHELF: | 541 case FOCUS_SHELF: |
1115 HandleFocusShelf(); | 542 HandleFocusShelf(); |
1116 break; | 543 break; |
1117 case LAUNCH_APP_0: | 544 case LAUNCH_APP_0: |
1118 HandleLaunchAppN(0); | 545 HandleLaunchAppN(0); |
1119 break; | 546 break; |
1120 case LAUNCH_APP_1: | 547 case LAUNCH_APP_1: |
1121 HandleLaunchAppN(1); | 548 HandleLaunchAppN(1); |
1122 break; | 549 break; |
1123 case LAUNCH_APP_2: | 550 case LAUNCH_APP_2: |
(...skipping 16 matching lines...) Expand all Loading... |
1140 break; | 567 break; |
1141 case LAUNCH_LAST_APP: | 568 case LAUNCH_LAST_APP: |
1142 HandleLaunchLastApp(); | 569 HandleLaunchLastApp(); |
1143 break; | 570 break; |
1144 case MAGNIFY_SCREEN_ZOOM_IN: | 571 case MAGNIFY_SCREEN_ZOOM_IN: |
1145 HandleMagnifyScreen(1); | 572 HandleMagnifyScreen(1); |
1146 break; | 573 break; |
1147 case MAGNIFY_SCREEN_ZOOM_OUT: | 574 case MAGNIFY_SCREEN_ZOOM_OUT: |
1148 HandleMagnifyScreen(-1); | 575 HandleMagnifyScreen(-1); |
1149 break; | 576 break; |
1150 case MEDIA_NEXT_TRACK: | |
1151 HandleMediaNextTrack(); | |
1152 break; | |
1153 case MEDIA_PLAY_PAUSE: | |
1154 HandleMediaPlayPause(); | |
1155 break; | |
1156 case MEDIA_PREV_TRACK: | |
1157 HandleMediaPrevTrack(); | |
1158 break; | |
1159 case NEW_INCOGNITO_WINDOW: | 577 case NEW_INCOGNITO_WINDOW: |
1160 HandleNewIncognitoWindow(); | 578 HandleNewIncognitoWindow(); |
1161 break; | 579 break; |
1162 case NEW_TAB: | 580 case NEW_TAB: |
1163 HandleNewTab(accelerator); | 581 HandleNewTab(accelerator); |
1164 break; | 582 break; |
1165 case NEW_WINDOW: | 583 case NEW_WINDOW: |
1166 HandleNewWindow(); | 584 HandleNewWindow(); |
1167 break; | 585 break; |
1168 case NEXT_IME: | |
1169 HandleNextIme(ime_control_delegate_.get()); | |
1170 break; | |
1171 case OPEN_FEEDBACK_PAGE: | 586 case OPEN_FEEDBACK_PAGE: |
1172 HandleOpenFeedbackPage(); | 587 HandleOpenFeedbackPage(); |
1173 break; | 588 break; |
1174 case PREVIOUS_IME: | |
1175 HandlePreviousIme(ime_control_delegate_.get(), accelerator); | |
1176 break; | |
1177 case PRINT_UI_HIERARCHIES: | |
1178 debug::PrintUIHierarchies(); | |
1179 break; | |
1180 case RESTORE_TAB: | 589 case RESTORE_TAB: |
1181 HandleRestoreTab(); | 590 HandleRestoreTab(); |
1182 break; | 591 break; |
1183 case ROTATE_SCREEN: | 592 case ROTATE_SCREEN: |
1184 HandleRotateScreen(); | 593 HandleRotateScreen(); |
1185 break; | 594 break; |
1186 case ROTATE_WINDOW: | 595 case ROTATE_WINDOW: |
1187 HandleRotateActiveWindow(); | 596 HandleRotateActiveWindow(); |
1188 break; | 597 break; |
1189 case SCALE_UI_DOWN: | 598 case SCALE_UI_DOWN: |
(...skipping 10 matching lines...) Expand all Loading... |
1200 break; | 609 break; |
1201 case SHOW_MESSAGE_CENTER_BUBBLE: | 610 case SHOW_MESSAGE_CENTER_BUBBLE: |
1202 HandleShowMessageCenterBubble(); | 611 HandleShowMessageCenterBubble(); |
1203 break; | 612 break; |
1204 case SHOW_SYSTEM_TRAY_BUBBLE: | 613 case SHOW_SYSTEM_TRAY_BUBBLE: |
1205 HandleShowSystemTrayBubble(); | 614 HandleShowSystemTrayBubble(); |
1206 break; | 615 break; |
1207 case SHOW_TASK_MANAGER: | 616 case SHOW_TASK_MANAGER: |
1208 HandleShowTaskManager(); | 617 HandleShowTaskManager(); |
1209 break; | 618 break; |
1210 case SWITCH_IME: | |
1211 HandleSwitchIme(ime_control_delegate_.get(), accelerator); | |
1212 break; | |
1213 case TAKE_WINDOW_SCREENSHOT: | |
1214 HandleTakeWindowScreenshot(screenshot_delegate_.get()); | |
1215 break; | |
1216 case TAKE_PARTIAL_SCREENSHOT: | 619 case TAKE_PARTIAL_SCREENSHOT: |
1217 HandleTakePartialScreenshot(screenshot_delegate_.get()); | 620 HandleTakePartialScreenshot(screenshot_delegate_.get()); |
1218 break; | 621 break; |
1219 case TAKE_SCREENSHOT: | 622 case TAKE_SCREENSHOT: |
1220 HandleTakeScreenshot(screenshot_delegate_.get()); | 623 HandleTakeScreenshot(screenshot_delegate_.get()); |
1221 break; | 624 break; |
| 625 case TAKE_WINDOW_SCREENSHOT: |
| 626 HandleTakeWindowScreenshot(screenshot_delegate_.get()); |
| 627 break; |
1222 case TOGGLE_APP_LIST: | 628 case TOGGLE_APP_LIST: |
1223 HandleToggleAppList(accelerator); | 629 HandleToggleAppList(accelerator); |
1224 break; | 630 break; |
1225 case TOGGLE_FULLSCREEN: | |
1226 HandleToggleFullscreen(accelerator); | |
1227 break; | |
1228 case TOGGLE_MAXIMIZED: | |
1229 accelerators::ToggleMaximized(); | |
1230 break; | |
1231 case TOGGLE_OVERVIEW: | |
1232 HandleToggleOverview(); | |
1233 break; | |
1234 case WINDOW_CYCLE_SNAP_DOCK_LEFT: | |
1235 case WINDOW_CYCLE_SNAP_DOCK_RIGHT: | |
1236 HandleWindowSnapOrDock(action); | |
1237 break; | |
1238 case WINDOW_MINIMIZE: | |
1239 HandleWindowMinimize(); | |
1240 break; | |
1241 case WINDOW_POSITION_CENTER: | |
1242 HandlePositionCenter(); | |
1243 break; | |
1244 case UNPIN: | 631 case UNPIN: |
1245 HandleUnpin(); | 632 accelerators::Unpin(); |
1246 break; | 633 break; |
1247 #if defined(OS_CHROMEOS) | 634 #if defined(OS_CHROMEOS) |
1248 case BRIGHTNESS_DOWN: { | |
1249 BrightnessControlDelegate* delegate = | |
1250 WmShell::Get()->brightness_control_delegate(); | |
1251 if (delegate) | |
1252 delegate->HandleBrightnessDown(accelerator); | |
1253 break; | |
1254 } | |
1255 case BRIGHTNESS_UP: { | |
1256 BrightnessControlDelegate* delegate = | |
1257 WmShell::Get()->brightness_control_delegate(); | |
1258 if (delegate) | |
1259 delegate->HandleBrightnessUp(accelerator); | |
1260 break; | |
1261 } | |
1262 case DEBUG_ADD_REMOVE_DISPLAY: | |
1263 case DEBUG_SHOW_TOAST: | |
1264 case DEBUG_TOGGLE_TOUCH_PAD: | |
1265 case DEBUG_TOGGLE_TOUCH_SCREEN: | |
1266 case DEBUG_TOGGLE_TOUCH_VIEW: | |
1267 case DEBUG_TOGGLE_UNIFIED_DESKTOP: | |
1268 debug::PerformDebugActionIfEnabled(action); | |
1269 break; | |
1270 case DISABLE_CAPS_LOCK: | |
1271 HandleDisableCapsLock(); | |
1272 break; | |
1273 case DISABLE_GPU_WATCHDOG: | 635 case DISABLE_GPU_WATCHDOG: |
1274 Shell::GetInstance()->gpu_support()->DisableGpuWatchdog(); | 636 Shell::GetInstance()->gpu_support()->DisableGpuWatchdog(); |
1275 break; | 637 break; |
1276 case KEYBOARD_BRIGHTNESS_DOWN: { | |
1277 KeyboardBrightnessControlDelegate* delegate = | |
1278 WmShell::Get()->keyboard_brightness_control_delegate(); | |
1279 if (delegate) | |
1280 delegate->HandleKeyboardBrightnessDown(accelerator); | |
1281 break; | |
1282 } | |
1283 case KEYBOARD_BRIGHTNESS_UP: { | |
1284 KeyboardBrightnessControlDelegate* delegate = | |
1285 WmShell::Get()->keyboard_brightness_control_delegate(); | |
1286 if (delegate) | |
1287 delegate->HandleKeyboardBrightnessUp(accelerator); | |
1288 break; | |
1289 } | |
1290 case LOCK_PRESSED: | 638 case LOCK_PRESSED: |
1291 case LOCK_RELEASED: | 639 case LOCK_RELEASED: |
1292 Shell::GetInstance()->power_button_controller()->OnLockButtonEvent( | 640 Shell::GetInstance()->power_button_controller()->OnLockButtonEvent( |
1293 action == LOCK_PRESSED, base::TimeTicks()); | 641 action == LOCK_PRESSED, base::TimeTicks()); |
1294 break; | 642 break; |
1295 case LOCK_SCREEN: | |
1296 HandleLock(); | |
1297 break; | |
1298 case OPEN_CROSH: | 643 case OPEN_CROSH: |
1299 HandleCrosh(); | 644 HandleCrosh(); |
1300 break; | 645 break; |
1301 case OPEN_FILE_MANAGER: | 646 case OPEN_FILE_MANAGER: |
1302 HandleFileManager(); | 647 HandleFileManager(); |
1303 break; | 648 break; |
1304 case OPEN_GET_HELP: | 649 case OPEN_GET_HELP: |
1305 HandleGetHelp(); | 650 HandleGetHelp(); |
1306 break; | 651 break; |
1307 case POWER_PRESSED: // fallthrough | 652 case POWER_PRESSED: // fallthrough |
1308 case POWER_RELEASED: | 653 case POWER_RELEASED: |
1309 if (!base::SysInfo::IsRunningOnChromeOS()) { | 654 if (!base::SysInfo::IsRunningOnChromeOS()) { |
1310 // There is no powerd, the Chrome OS power manager, in linux desktop, | 655 // There is no powerd, the Chrome OS power manager, in linux desktop, |
1311 // so call the PowerButtonController here. | 656 // so call the PowerButtonController here. |
1312 Shell::GetInstance()->power_button_controller()->OnPowerButtonEvent( | 657 Shell::GetInstance()->power_button_controller()->OnPowerButtonEvent( |
1313 action == POWER_PRESSED, base::TimeTicks()); | 658 action == POWER_PRESSED, base::TimeTicks()); |
1314 } | 659 } |
1315 // We don't do anything with these at present on the device, | 660 // We don't do anything with these at present on the device, |
1316 // (power button events are reported to us from powerm via | 661 // (power button events are reported to us from powerm via |
1317 // D-BUS), but we consume them to prevent them from getting | 662 // D-BUS), but we consume them to prevent them from getting |
1318 // passed to apps -- see http://crbug.com/146609. | 663 // passed to apps -- see http://crbug.com/146609. |
1319 break; | 664 break; |
1320 case SUSPEND: | |
1321 HandleSuspend(); | |
1322 break; | |
1323 case SWAP_PRIMARY_DISPLAY: | 665 case SWAP_PRIMARY_DISPLAY: |
1324 HandleSwapPrimaryDisplay(); | 666 HandleSwapPrimaryDisplay(); |
1325 break; | 667 break; |
1326 case SWITCH_TO_NEXT_USER: | |
1327 HandleCycleUser(SessionStateDelegate::CYCLE_TO_NEXT_USER); | |
1328 break; | |
1329 case SWITCH_TO_PREVIOUS_USER: | |
1330 HandleCycleUser(SessionStateDelegate::CYCLE_TO_PREVIOUS_USER); | |
1331 break; | |
1332 case TOGGLE_CAPS_LOCK: | |
1333 HandleToggleCapsLock(); | |
1334 break; | |
1335 case TOGGLE_MIRROR_MODE: | 668 case TOGGLE_MIRROR_MODE: |
1336 HandleToggleMirrorMode(); | 669 HandleToggleMirrorMode(); |
1337 break; | 670 break; |
1338 case TOGGLE_SPOKEN_FEEDBACK: | |
1339 HandleToggleSpokenFeedback(); | |
1340 break; | |
1341 case TOGGLE_WIFI: | |
1342 WmShell::Get()->system_tray_notifier()->NotifyRequestToggleWifi(); | |
1343 break; | |
1344 case TOUCH_HUD_CLEAR: | 671 case TOUCH_HUD_CLEAR: |
1345 HandleTouchHudClear(); | 672 HandleTouchHudClear(); |
1346 break; | 673 break; |
1347 case TOUCH_HUD_MODE_CHANGE: | 674 case TOUCH_HUD_MODE_CHANGE: |
1348 HandleTouchHudModeChange(); | 675 HandleTouchHudModeChange(); |
1349 break; | 676 break; |
1350 case TOUCH_HUD_PROJECTION_TOGGLE: | 677 case TOUCH_HUD_PROJECTION_TOGGLE: |
1351 accelerators::ToggleTouchHudProjection(); | 678 accelerators::ToggleTouchHudProjection(); |
1352 break; | 679 break; |
1353 case VOLUME_DOWN: | 680 #endif |
1354 HandleVolumeDown(accelerator); | 681 default: |
1355 break; | 682 break; |
1356 case VOLUME_MUTE: | |
1357 HandleVolumeMute(accelerator); | |
1358 break; | |
1359 case VOLUME_UP: | |
1360 HandleVolumeUp(accelerator); | |
1361 break; | |
1362 #else | |
1363 case DUMMY_FOR_RESERVED: | |
1364 NOTREACHED(); | |
1365 break; | |
1366 #endif | |
1367 } | 683 } |
1368 } | 684 } |
1369 | 685 |
1370 bool AcceleratorController::ShouldActionConsumeKeyEvent( | 686 void AcceleratorControllerDelegateAura::ShowDeprecatedAcceleratorNotification( |
1371 AcceleratorAction action) { | 687 const char* const notification_id, |
1372 // Adding new exceptions is *STRONGLY* discouraged. | 688 int message_id, |
1373 return true; | 689 int old_shortcut_id, |
1374 } | 690 int new_shortcut_id) { |
1375 | 691 const base::string16 message = |
1376 AcceleratorController::AcceleratorProcessingRestriction | 692 GetNotificationText(message_id, old_shortcut_id, new_shortcut_id); |
1377 AcceleratorController::GetAcceleratorProcessingRestriction(int action) { | 693 std::unique_ptr<message_center::Notification> notification( |
1378 if (WmShell::Get()->IsPinned() && | 694 new message_center::Notification( |
1379 actions_allowed_in_pinned_mode_.find(action) == | 695 message_center::NOTIFICATION_TYPE_SIMPLE, notification_id, |
1380 actions_allowed_in_pinned_mode_.end()) { | 696 base::string16(), message, |
1381 return RESTRICTION_PREVENT_PROCESSING_AND_PROPAGATION; | 697 WmShell::Get()->delegate()->GetDeprecatedAcceleratorImage(), |
1382 } | 698 base::string16(), GURL(), |
1383 WmShell* wm_shell = WmShell::Get(); | 699 message_center::NotifierId( |
1384 if (!wm_shell->GetSessionStateDelegate()->IsActiveUserSessionStarted() && | 700 message_center::NotifierId::SYSTEM_COMPONENT, |
1385 actions_allowed_at_login_screen_.find(action) == | 701 system_notifier::kNotifierDeprecatedAccelerator), |
1386 actions_allowed_at_login_screen_.end()) { | 702 message_center::RichNotificationData(), |
1387 return RESTRICTION_PREVENT_PROCESSING; | 703 new DeprecatedAcceleratorNotificationDelegate)); |
1388 } | 704 message_center::MessageCenter::Get()->AddNotification( |
1389 if (wm_shell->GetSessionStateDelegate()->IsScreenLocked() && | 705 std::move(notification)); |
1390 actions_allowed_at_lock_screen_.find(action) == | |
1391 actions_allowed_at_lock_screen_.end()) { | |
1392 return RESTRICTION_PREVENT_PROCESSING; | |
1393 } | |
1394 if (wm_shell->delegate()->IsRunningInForcedAppMode() && | |
1395 actions_allowed_in_app_mode_.find(action) == | |
1396 actions_allowed_in_app_mode_.end()) { | |
1397 return RESTRICTION_PREVENT_PROCESSING; | |
1398 } | |
1399 if (WmShell::Get()->IsSystemModalWindowOpen() && | |
1400 actions_allowed_at_modal_window_.find(action) == | |
1401 actions_allowed_at_modal_window_.end()) { | |
1402 // Note we prevent the shortcut from propagating so it will not | |
1403 // be passed to the modal window. This is important for things like | |
1404 // Alt+Tab that would cause an undesired effect in the modal window by | |
1405 // cycling through its window elements. | |
1406 return RESTRICTION_PREVENT_PROCESSING_AND_PROPAGATION; | |
1407 } | |
1408 if (wm_shell->mru_window_tracker()->BuildMruWindowList().empty() && | |
1409 actions_needing_window_.find(action) != actions_needing_window_.end()) { | |
1410 wm_shell->accessibility_delegate()->TriggerAccessibilityAlert( | |
1411 A11Y_ALERT_WINDOW_NEEDED); | |
1412 return RESTRICTION_PREVENT_PROCESSING_AND_PROPAGATION; | |
1413 } | |
1414 return RESTRICTION_NONE; | |
1415 } | 706 } |
1416 | 707 |
1417 } // namespace ash | 708 } // namespace ash |
OLD | NEW |