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
3 // found in the LICENSE file.
5 #include "ash/accelerators/accelerator_controller.h"
11 #include "ash/accelerators/accelerator_commands.h"
12 #include "ash/accelerators/debug_commands.h"
13 #include "ash/ash_switches.h"
14 #include "ash/debug.h"
15 #include "ash/display/display_controller.h"
16 #include "ash/display/display_manager.h"
17 #include "ash/display/display_util.h"
18 #include "ash/focus_cycler.h"
19 #include "ash/gpu_support.h"
20 #include "ash/ime_control_delegate.h"
21 #include "ash/magnifier/magnification_controller.h"
22 #include "ash/magnifier/partial_magnification_controller.h"
23 #include "ash/media_delegate.h"
24 #include "ash/multi_profile_uma.h"
25 #include "ash/new_window_delegate.h"
26 #include "ash/root_window_controller.h"
27 #include "ash/rotator/screen_rotation_animator.h"
28 #include "ash/rotator/window_rotation.h"
29 #include "ash/screenshot_delegate.h"
30 #include "ash/session/session_state_delegate.h"
31 #include "ash/shelf/shelf.h"
32 #include "ash/shelf/shelf_delegate.h"
33 #include "ash/shelf/shelf_model.h"
34 #include "ash/shelf/shelf_widget.h"
35 #include "ash/shell.h"
36 #include "ash/shell_delegate.h"
37 #include "ash/shell_window_ids.h"
38 #include "ash/system/brightness_control_delegate.h"
39 #include "ash/system/keyboard_brightness/keyboard_brightness_control_delegate.h"
40 #include "ash/system/status_area_widget.h"
41 #include "ash/system/tray/system_tray.h"
42 #include "ash/system/tray/system_tray_delegate.h"
43 #include "ash/system/tray/system_tray_notifier.h"
44 #include "ash/system/web_notification/web_notification_tray.h"
45 #include "ash/touch/touch_hud_debug.h"
46 #include "ash/utility/partial_screenshot_controller.h"
47 #include "ash/volume_control_delegate.h"
48 #include "ash/wm/maximize_mode/maximize_mode_controller.h"
49 #include "ash/wm/mru_window_tracker.h"
50 #include "ash/wm/overview/window_selector_controller.h"
51 #include "ash/wm/power_button_controller.h"
52 #include "ash/wm/window_cycle_controller.h"
53 #include "ash/wm/window_state.h"
54 #include "ash/wm/window_util.h"
55 #include "ash/wm/wm_event.h"
56 #include "base/bind.h"
57 #include "base/command_line.h"
58 #include "base/metrics/user_metrics.h"
59 #include "ui/aura/env.h"
60 #include "ui/base/accelerators/accelerator.h"
61 #include "ui/base/accelerators/accelerator_manager.h"
62 #include "ui/compositor/layer.h"
63 #include "ui/compositor/layer_animation_sequence.h"
64 #include "ui/compositor/layer_animator.h"
65 #include "ui/events/event.h"
66 #include "ui/events/keycodes/keyboard_codes.h"
67 #include "ui/gfx/screen.h"
68 #include "ui/views/controls/webview/webview.h"
70 #if defined(OS_CHROMEOS)
71 #include "ash/system/chromeos/keyboard_brightness_controller.h"
72 #include "base/sys_info.h"
73 #include "ui/base/ime/chromeos/ime_keyboard.h"
74 #include "ui/base/ime/chromeos/input_method_manager.h"
75 #endif // defined(OS_CHROMEOS)
80 using base::UserMetricsAction
;
82 bool CanHandleAccessibleFocusCycle() {
83 if (!Shell::GetInstance()->accessibility_delegate()->
84 IsSpokenFeedbackEnabled()) {
87 aura::Window
* active_window
= ash::wm::GetActiveWindow();
90 views::Widget
* widget
=
91 views::Widget::GetWidgetForNativeWindow(active_window
);
94 views::FocusManager
* focus_manager
= widget
->GetFocusManager();
97 views::View
* view
= focus_manager
->GetFocusedView();
98 return view
&& strcmp(view
->GetClassName(), views::WebView::kViewClassName
);
101 void HandleAccessibleFocusCycle(bool reverse
) {
103 base::RecordAction(UserMetricsAction("Accel_Accessible_Focus_Previous"));
105 base::RecordAction(UserMetricsAction("Accel_Accessible_Focus_Next"));
107 aura::Window
* active_window
= ash::wm::GetActiveWindow();
108 views::Widget
* widget
=
109 views::Widget::GetWidgetForNativeWindow(active_window
);
110 widget
->GetFocusManager()->AdvanceFocus(reverse
);
113 void HandleCycleBackwardMRU(const ui::Accelerator
& accelerator
) {
114 if (accelerator
.key_code() == ui::VKEY_TAB
)
115 base::RecordAction(base::UserMetricsAction("Accel_PrevWindow_Tab"));
117 Shell::GetInstance()->window_cycle_controller()->HandleCycleWindow(
118 WindowCycleController::BACKWARD
);
121 void HandleCycleForwardMRU(const ui::Accelerator
& accelerator
) {
122 if (accelerator
.key_code() == ui::VKEY_TAB
)
123 base::RecordAction(base::UserMetricsAction("Accel_NextWindow_Tab"));
125 Shell::GetInstance()->window_cycle_controller()->HandleCycleWindow(
126 WindowCycleController::FORWARD
);
129 void HandleRotatePaneFocus(Shell::Direction direction
) {
130 Shell
* shell
= Shell::GetInstance();
132 // TODO(stevet): Not sure if this is the same as IDC_FOCUS_NEXT_PANE.
133 case Shell::FORWARD
: {
134 base::RecordAction(UserMetricsAction("Accel_Focus_Next_Pane"));
135 shell
->focus_cycler()->RotateFocus(FocusCycler::FORWARD
);
138 case Shell::BACKWARD
: {
139 base::RecordAction(UserMetricsAction("Accel_Focus_Previous_Pane"));
140 shell
->focus_cycler()->RotateFocus(FocusCycler::BACKWARD
);
146 void HandleFocusShelf() {
147 Shell
* shell
= Shell::GetInstance();
148 base::RecordAction(base::UserMetricsAction("Accel_Focus_Shelf"));
149 shell
->focus_cycler()->FocusWidget(
150 Shelf::ForPrimaryDisplay()->shelf_widget());
153 void HandleLaunchAppN(int n
) {
154 base::RecordAction(UserMetricsAction("Accel_Launch_App"));
155 Shelf::ForPrimaryDisplay()->LaunchAppIndexAt(n
);
158 void HandleLaunchLastApp() {
159 base::RecordAction(UserMetricsAction("Accel_Launch_Last_App"));
160 Shelf::ForPrimaryDisplay()->LaunchAppIndexAt(-1);
163 bool CanHandleMagnifyScreen() {
164 Shell
* shell
= Shell::GetInstance();
165 return shell
->magnification_controller()->IsEnabled() ||
166 shell
->partial_magnification_controller()->is_enabled();
169 // Magnify the screen
170 void HandleMagnifyScreen(int delta_index
) {
171 if (ash::Shell::GetInstance()->magnification_controller()->IsEnabled()) {
172 // TODO(yoshiki): Move the following logic to MagnificationController.
174 ash::Shell::GetInstance()->magnification_controller()->GetScale();
175 // Calculate rounded logarithm (base kMagnificationScaleFactor) of scale.
176 int scale_index
= std::floor(
177 std::log(scale
) / std::log(ui::kMagnificationScaleFactor
) + 0.5);
179 int new_scale_index
= std::max(0, std::min(8, scale_index
+ delta_index
));
181 ash::Shell::GetInstance()->magnification_controller()->SetScale(
182 std::pow(ui::kMagnificationScaleFactor
, new_scale_index
), true);
183 } else if (ash::Shell::GetInstance()->
184 partial_magnification_controller()->is_enabled()) {
185 float scale
= delta_index
> 0 ? kDefaultPartialMagnifiedScale
: 1;
186 ash::Shell::GetInstance()->partial_magnification_controller()->
191 void HandleMediaNextTrack() {
192 Shell::GetInstance()->media_delegate()->HandleMediaNextTrack();
195 void HandleMediaPlayPause() {
196 Shell::GetInstance()->media_delegate()->HandleMediaPlayPause();
199 void HandleMediaPrevTrack() {
200 Shell::GetInstance()->media_delegate()->HandleMediaPrevTrack();
203 bool CanHandleNewIncognitoWindow() {
204 return Shell::GetInstance()->delegate()->IsIncognitoAllowed();
207 void HandleNewIncognitoWindow() {
208 base::RecordAction(UserMetricsAction("Accel_New_Incognito_Window"));
209 Shell::GetInstance()->new_window_delegate()->NewWindow(
210 true /* is_incognito */);
213 void HandleNewTab(const ui::Accelerator
& accelerator
) {
214 if (accelerator
.key_code() == ui::VKEY_T
)
215 base::RecordAction(base::UserMetricsAction("Accel_NewTab_T"));
216 Shell::GetInstance()->new_window_delegate()->NewTab();
219 void HandleNewWindow() {
220 base::RecordAction(base::UserMetricsAction("Accel_New_Window"));
221 Shell::GetInstance()->new_window_delegate()->NewWindow(
222 false /* is_incognito */);
225 bool CanHandleNextIme(ImeControlDelegate
* ime_control_delegate
,
226 const ui::Accelerator
& previous_accelerator
) {
227 // This check is necessary e.g. not to process the Shift+Alt+
228 // ET_KEY_RELEASED accelerator for Chrome OS (see ash/accelerators/
229 // accelerator_controller.cc) when Shift+Alt+Tab is pressed and then Tab
231 ui::KeyboardCode previous_key_code
= previous_accelerator
.key_code();
232 if (previous_accelerator
.type() == ui::ET_KEY_RELEASED
&&
233 // Workaround for crbug.com/139556. CJK IME users tend to press
234 // Enter (or Space) and Shift+Alt almost at the same time to commit
235 // an IME string and then switch from the IME to the English layout.
236 // This workaround allows the user to trigger NEXT_IME even if the
237 // user presses Shift+Alt before releasing Enter.
238 // TODO(nona|mazda): Fix crbug.com/139556 in a cleaner way.
239 previous_key_code
!= ui::VKEY_RETURN
&&
240 previous_key_code
!= ui::VKEY_SPACE
) {
241 // We totally ignore this accelerator.
242 // TODO(mazda): Fix crbug.com/158217
245 return ime_control_delegate
&& ime_control_delegate
->CanCycleIme();
248 void HandleNextIme(ImeControlDelegate
* ime_control_delegate
) {
249 base::RecordAction(UserMetricsAction("Accel_Next_Ime"));
250 ime_control_delegate
->HandleNextIme();
253 void HandleOpenFeedbackPage() {
254 base::RecordAction(UserMetricsAction("Accel_Open_Feedback_Page"));
255 ash::Shell::GetInstance()->new_window_delegate()->OpenFeedbackPage();
258 bool CanHandlePreviousIme(ImeControlDelegate
* ime_control_delegate
) {
259 return ime_control_delegate
&& ime_control_delegate
->CanCycleIme();
262 void HandlePreviousIme(ImeControlDelegate
* ime_control_delegate
,
263 const ui::Accelerator
& accelerator
) {
264 base::RecordAction(UserMetricsAction("Accel_Previous_Ime"));
265 if (accelerator
.type() == ui::ET_KEY_PRESSED
)
266 ime_control_delegate
->HandlePreviousIme();
267 // Else: consume the Ctrl+Space ET_KEY_RELEASED event but do not do anything.
270 void HandleRestoreTab() {
271 base::RecordAction(base::UserMetricsAction("Accel_Restore_Tab"));
272 Shell::GetInstance()->new_window_delegate()->RestoreTab();
275 gfx::Display::Rotation
GetNextRotation(gfx::Display::Rotation current
) {
277 case gfx::Display::ROTATE_0
:
278 return gfx::Display::ROTATE_90
;
279 case gfx::Display::ROTATE_90
:
280 return gfx::Display::ROTATE_180
;
281 case gfx::Display::ROTATE_180
:
282 return gfx::Display::ROTATE_270
;
283 case gfx::Display::ROTATE_270
:
284 return gfx::Display::ROTATE_0
;
286 NOTREACHED() << "Unknown rotation:" << current
;
287 return gfx::Display::ROTATE_0
;
290 // Rotates the screen.
291 void HandleRotateScreen() {
292 base::RecordAction(UserMetricsAction("Accel_Rotate_Window"));
293 gfx::Point point
= Shell::GetScreen()->GetCursorScreenPoint();
294 gfx::Display display
= Shell::GetScreen()->GetDisplayNearestPoint(point
);
295 const DisplayInfo
& display_info
=
296 Shell::GetInstance()->display_manager()->GetDisplayInfo(display
.id());
297 ash::ScreenRotationAnimator(display
.id())
298 .Rotate(GetNextRotation(display_info
.GetActiveRotation()),
299 gfx::Display::ROTATION_SOURCE_USER
);
302 // Rotate the active window.
303 void HandleRotateActiveWindow() {
304 base::RecordAction(UserMetricsAction("Accel_Rotate_Window"));
305 aura::Window
* active_window
= wm::GetActiveWindow();
307 // The rotation animation bases its target transform on the current
308 // rotation and position. Since there could be an animation in progress
309 // right now, queue this animation so when it starts it picks up a neutral
310 // rotation and position. Use replace so we only enqueue one at a time.
311 active_window
->layer()->GetAnimator()->
312 set_preemption_strategy(ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS
);
313 active_window
->layer()->GetAnimator()->StartAnimation(
314 new ui::LayerAnimationSequence(
315 new ash::WindowRotation(360, active_window
->layer())));
319 bool CanHandleScaleReset() {
320 DisplayManager
* display_manager
= Shell::GetInstance()->display_manager();
321 int64 display_id
= display_manager
->GetDisplayIdForUIScaling();
322 return (display_id
!= gfx::Display::kInvalidDisplayID
&&
323 display_manager
->GetDisplayInfo(display_id
).configured_ui_scale() !=
327 void HandleScaleReset() {
328 base::RecordAction(UserMetricsAction("Accel_Scale_Ui_Reset"));
329 DisplayManager
* display_manager
= Shell::GetInstance()->display_manager();
330 int64 display_id
= display_manager
->GetDisplayIdForUIScaling();
331 display_manager
->SetDisplayUIScale(display_id
, 1.0f
);
334 bool CanHandleScaleUI() {
335 DisplayManager
* display_manager
= Shell::GetInstance()->display_manager();
336 int64 display_id
= display_manager
->GetDisplayIdForUIScaling();
337 return display_id
!= gfx::Display::kInvalidDisplayID
;
340 void HandleScaleUI(bool up
) {
341 DisplayManager
* display_manager
= Shell::GetInstance()->display_manager();
342 int64 display_id
= display_manager
->GetDisplayIdForUIScaling();
345 base::RecordAction(UserMetricsAction("Accel_Scale_Ui_Up"));
347 base::RecordAction(UserMetricsAction("Accel_Scale_Ui_Down"));
350 const DisplayInfo
& display_info
= display_manager
->GetDisplayInfo(display_id
);
351 float next_scale
= GetNextUIScale(display_info
, up
);
352 display_manager
->SetDisplayUIScale(display_id
, next_scale
);
355 void HandleShowKeyboardOverlay() {
356 base::RecordAction(UserMetricsAction("Accel_Show_Keyboard_Overlay"));
357 ash::Shell::GetInstance()->new_window_delegate()->ShowKeyboardOverlay();
360 bool CanHandleShowMessageCenterBubble() {
361 RootWindowController
* controller
=
362 RootWindowController::ForTargetRootWindow();
363 StatusAreaWidget
* status_area_widget
=
364 controller
->shelf()->status_area_widget();
365 return status_area_widget
&&
366 status_area_widget
->web_notification_tray()->visible();
369 void HandleShowMessageCenterBubble() {
370 base::RecordAction(UserMetricsAction("Accel_Show_Message_Center_Bubble"));
371 RootWindowController
* controller
=
372 RootWindowController::ForTargetRootWindow();
373 StatusAreaWidget
* status_area_widget
=
374 controller
->shelf()->status_area_widget();
375 if (status_area_widget
) {
376 WebNotificationTray
* notification_tray
=
377 status_area_widget
->web_notification_tray();
378 if (notification_tray
->visible())
379 notification_tray
->ShowMessageCenterBubble();
383 void HandleShowSystemTrayBubble() {
384 base::RecordAction(UserMetricsAction("Accel_Show_System_Tray_Bubble"));
385 RootWindowController
* controller
=
386 RootWindowController::ForTargetRootWindow();
387 if (!controller
->GetSystemTray()->HasSystemBubble())
388 controller
->GetSystemTray()->ShowDefaultView(BUBBLE_CREATE_NEW
);
391 void HandleShowTaskManager() {
392 base::RecordAction(UserMetricsAction("Accel_Show_Task_Manager"));
393 Shell::GetInstance()->new_window_delegate()->ShowTaskManager();
396 bool CanHandleSwitchIme(ImeControlDelegate
* ime_control_delegate
,
397 const ui::Accelerator
& accelerator
) {
398 return ime_control_delegate
&&
399 ime_control_delegate
->CanSwitchIme(accelerator
);
402 void HandleSwitchIme(ImeControlDelegate
* ime_control_delegate
,
403 const ui::Accelerator
& accelerator
) {
404 base::RecordAction(UserMetricsAction("Accel_Switch_Ime"));
405 ime_control_delegate
->HandleSwitchIme(accelerator
);
408 void HandleTakePartialScreenshot(ScreenshotDelegate
* screenshot_delegate
) {
409 base::RecordAction(UserMetricsAction("Accel_Take_Partial_Screenshot"));
410 DCHECK(screenshot_delegate
);
412 ->partial_screenshot_controller()
413 ->StartPartialScreenshotSession(screenshot_delegate
);
416 void HandleTakeScreenshot(ScreenshotDelegate
* screenshot_delegate
) {
417 base::RecordAction(UserMetricsAction("Accel_Take_Screenshot"));
418 DCHECK(screenshot_delegate
);
419 if (screenshot_delegate
->CanTakeScreenshot())
420 screenshot_delegate
->HandleTakeScreenshotForAllRootWindows();
423 bool CanHandleToggleAppList(const ui::Accelerator
& accelerator
,
424 const ui::Accelerator
& previous_accelerator
) {
425 if (accelerator
.key_code() == ui::VKEY_LWIN
) {
426 // If something else was pressed between the Search key (LWIN)
427 // being pressed and released, then ignore the release of the
429 if (previous_accelerator
.type() != ui::ET_KEY_PRESSED
||
430 previous_accelerator
.key_code() != ui::VKEY_LWIN
) {
434 // When spoken feedback is enabled, we should neither toggle the list nor
435 // consume the key since Search+Shift is one of the shortcuts the a11y
436 // feature uses. crbug.com/132296
437 if (Shell::GetInstance()
438 ->accessibility_delegate()
439 ->IsSpokenFeedbackEnabled()) {
446 void HandleToggleAppList(const ui::Accelerator
& accelerator
) {
447 if (accelerator
.key_code() == ui::VKEY_LWIN
)
448 base::RecordAction(base::UserMetricsAction("Accel_Search_LWin"));
449 ash::Shell::GetInstance()->ToggleAppList(NULL
);
452 void HandleToggleFullscreen(const ui::Accelerator
& accelerator
) {
453 if (accelerator
.key_code() == ui::VKEY_MEDIA_LAUNCH_APP2
)
454 base::RecordAction(UserMetricsAction("Accel_Fullscreen_F4"));
455 accelerators::ToggleFullscreen();
458 void HandleToggleOverview() {
459 base::RecordAction(base::UserMetricsAction("Accel_Overview_F5"));
460 Shell::GetInstance()->window_selector_controller()->ToggleOverview();
463 bool CanHandleWindowSnapOrDock() {
464 wm::WindowState
* window_state
= wm::GetActiveWindowState();
465 // Disable window snapping shortcut key for full screen window due to
466 // http://crbug.com/135487.
467 return (window_state
&&
468 (window_state
->window()->type() == ui::wm::WINDOW_TYPE_NORMAL
||
469 window_state
->window()->type() == ui::wm::WINDOW_TYPE_PANEL
) &&
470 !window_state
->IsFullscreen());
473 void HandleWindowSnapOrDock(AcceleratorAction action
) {
474 if (action
== WINDOW_CYCLE_SNAP_DOCK_LEFT
)
475 base::RecordAction(UserMetricsAction("Accel_Window_Snap_Left"));
477 base::RecordAction(UserMetricsAction("Accel_Window_Snap_Right"));
479 const wm::WMEvent
event(action
== WINDOW_CYCLE_SNAP_DOCK_LEFT
?
480 wm::WM_EVENT_CYCLE_SNAP_DOCK_LEFT
:
481 wm::WM_EVENT_CYCLE_SNAP_DOCK_RIGHT
);
482 wm::GetActiveWindowState()->OnWMEvent(&event
);
485 void HandleWindowMinimize() {
487 base::UserMetricsAction("Accel_Toggle_Minimized_Minus"));
488 accelerators::ToggleMinimized();
491 bool CanHandlePositionCenter() {
492 // Docked windows do not support centering.
493 wm::WindowState
* window_state
= wm::GetActiveWindowState();
494 return (window_state
&& !window_state
->IsDocked());
497 void HandlePositionCenter() {
498 base::RecordAction(UserMetricsAction("Accel_Window_Position_Center"));
499 wm::CenterWindow(wm::GetActiveWindow());
502 #if defined(OS_CHROMEOS)
503 void HandleBrightnessDown(BrightnessControlDelegate
* delegate
,
504 const ui::Accelerator
& accelerator
) {
506 delegate
->HandleBrightnessDown(accelerator
);
509 void HandleBrightnessUp(BrightnessControlDelegate
* delegate
,
510 const ui::Accelerator
& accelerator
) {
512 delegate
->HandleBrightnessUp(accelerator
);
515 bool CanHandleDisableCapsLock(const ui::Accelerator
& previous_accelerator
) {
516 ui::KeyboardCode previous_key_code
= previous_accelerator
.key_code();
517 if (previous_accelerator
.type() == ui::ET_KEY_RELEASED
||
518 (previous_key_code
!= ui::VKEY_LSHIFT
&&
519 previous_key_code
!= ui::VKEY_SHIFT
&&
520 previous_key_code
!= ui::VKEY_RSHIFT
)) {
521 // If something else was pressed between the Shift key being pressed
522 // and released, then ignore the release of the Shift key.
525 chromeos::input_method::InputMethodManager
* ime
=
526 chromeos::input_method::InputMethodManager::Get();
527 chromeos::input_method::ImeKeyboard
* keyboard
=
528 ime
? ime
->GetImeKeyboard() : NULL
;
529 return (keyboard
&& keyboard
->CapsLockIsEnabled());
532 void HandleDisableCapsLock() {
533 base::RecordAction(UserMetricsAction("Accel_Disable_Caps_Lock"));
534 chromeos::input_method::InputMethodManager
* ime
=
535 chromeos::input_method::InputMethodManager::Get();
536 ime
->GetImeKeyboard()->SetCapsLockEnabled(false);
539 void HandleKeyboardBrightnessDown(KeyboardBrightnessControlDelegate
* delegate
,
540 const ui::Accelerator
& accelerator
) {
542 delegate
->HandleKeyboardBrightnessDown(accelerator
);
545 void HandleKeyboardBrightnessUp(KeyboardBrightnessControlDelegate
* delegate
,
546 const ui::Accelerator
& accelerator
) {
548 delegate
->HandleKeyboardBrightnessUp(accelerator
);
552 base::RecordAction(UserMetricsAction("Accel_LockScreen_L"));
553 Shell::GetInstance()->session_state_delegate()->LockScreen();
557 base::RecordAction(UserMetricsAction("Accel_Open_Crosh"));
559 Shell::GetInstance()->new_window_delegate()->OpenCrosh();
562 void HandleFileManager() {
563 base::RecordAction(UserMetricsAction("Accel_Open_File_Manager"));
565 Shell::GetInstance()->new_window_delegate()->OpenFileManager();
568 void HandleGetHelp() {
569 Shell::GetInstance()->new_window_delegate()->OpenGetHelp();
572 bool CanHandleSilenceSpokenFeedback() {
573 AccessibilityDelegate
* delegate
=
574 Shell::GetInstance()->accessibility_delegate();
575 return delegate
->IsSpokenFeedbackEnabled();
578 void HandleSilenceSpokenFeedback() {
579 base::RecordAction(UserMetricsAction("Accel_Silence_Spoken_Feedback"));
580 Shell::GetInstance()->accessibility_delegate()->SilenceSpokenFeedback();
583 void HandleSwapPrimaryDisplay() {
584 base::RecordAction(UserMetricsAction("Accel_Swap_Primary_Display"));
585 Shell::GetInstance()->display_controller()->SwapPrimaryDisplay();
588 bool CanHandleCycleUser() {
589 Shell
* shell
= Shell::GetInstance();
590 return shell
->delegate()->IsMultiProfilesEnabled() &&
591 shell
->session_state_delegate()->NumberOfLoggedInUsers() > 1;
594 void HandleCycleUser(SessionStateDelegate::CycleUser cycle_user
) {
595 MultiProfileUMA::RecordSwitchActiveUser(
596 MultiProfileUMA::SWITCH_ACTIVE_USER_BY_ACCELERATOR
);
597 switch (cycle_user
) {
598 case SessionStateDelegate::CYCLE_TO_NEXT_USER
:
599 base::RecordAction(UserMetricsAction("Accel_Switch_To_Next_User"));
601 case SessionStateDelegate::CYCLE_TO_PREVIOUS_USER
:
602 base::RecordAction(UserMetricsAction("Accel_Switch_To_Previous_User"));
605 Shell::GetInstance()->session_state_delegate()->CycleActiveUser(cycle_user
);
608 bool CanHandleToggleCapsLock(const ui::Accelerator
& accelerator
,
609 const ui::Accelerator
& previous_accelerator
) {
610 if (accelerator
.key_code() == ui::VKEY_LWIN
) {
611 // If something else was pressed between the Search key (LWIN)
612 // being pressed and released, then ignore the release of the
614 // TODO(danakj): Releasing Alt first breaks this: crbug.com/166495
615 if (previous_accelerator
.type() == ui::ET_KEY_RELEASED
||
616 previous_accelerator
.key_code() != ui::VKEY_LWIN
)
619 chromeos::input_method::InputMethodManager
* ime
=
620 chromeos::input_method::InputMethodManager::Get();
621 return ime
&& ime
->GetImeKeyboard();
624 void HandleToggleCapsLock() {
625 base::RecordAction(UserMetricsAction("Accel_Toggle_Caps_Lock"));
626 chromeos::input_method::InputMethodManager
* ime
=
627 chromeos::input_method::InputMethodManager::Get();
628 chromeos::input_method::ImeKeyboard
* keyboard
= ime
->GetImeKeyboard();
629 keyboard
->SetCapsLockEnabled(!keyboard
->CapsLockIsEnabled());
632 void HandleToggleMirrorMode() {
633 base::RecordAction(UserMetricsAction("Accel_Toggle_Mirror_Mode"));
634 Shell::GetInstance()->display_controller()->ToggleMirrorMode();
637 void HandleToggleSpokenFeedback() {
638 base::RecordAction(UserMetricsAction("Accel_Toggle_Spoken_Feedback"));
640 Shell::GetInstance()->accessibility_delegate()->
641 ToggleSpokenFeedback(ui::A11Y_NOTIFICATION_SHOW
);
644 bool CanHandleToggleTouchViewTesting() {
645 return base::CommandLine::ForCurrentProcess()->HasSwitch(
646 switches::kAshEnableTouchViewTesting
);
649 void HandleToggleTouchViewTesting() {
650 // TODO(skuhne): This is only temporary! Remove this!
651 MaximizeModeController
* controller
= Shell::GetInstance()->
652 maximize_mode_controller();
653 controller
->EnableMaximizeModeWindowManager(
654 !controller
->IsMaximizeModeWindowManagerEnabled());
657 bool CanHandleTouchHud() {
658 return RootWindowController::ForTargetRootWindow()->touch_hud_debug();
661 void HandleTouchHudClear() {
662 RootWindowController::ForTargetRootWindow()->touch_hud_debug()->Clear();
665 void HandleTouchHudModeChange() {
666 RootWindowController
* controller
=
667 RootWindowController::ForTargetRootWindow();
668 controller
->touch_hud_debug()->ChangeToNextMode();
671 void HandleVolumeDown(const ui::Accelerator
& accelerator
) {
672 VolumeControlDelegate
* volume_delegate
=
673 Shell::GetInstance()->system_tray_delegate()->GetVolumeControlDelegate();
675 volume_delegate
->HandleVolumeDown(accelerator
);
678 void HandleVolumeMute(const ui::Accelerator
& accelerator
) {
679 VolumeControlDelegate
* volume_delegate
=
680 Shell::GetInstance()->system_tray_delegate()->GetVolumeControlDelegate();
682 volume_delegate
->HandleVolumeMute(accelerator
);
685 void HandleVolumeUp(const ui::Accelerator
& accelerator
) {
686 VolumeControlDelegate
* volume_delegate
=
687 Shell::GetInstance()->system_tray_delegate()->GetVolumeControlDelegate();
689 volume_delegate
->HandleVolumeUp(accelerator
);
692 #endif // defined(OS_CHROMEOS)
696 ////////////////////////////////////////////////////////////////////////////////
697 // AcceleratorController, public:
699 AcceleratorController::AcceleratorController()
700 : accelerator_manager_(new ui::AcceleratorManager
),
701 accelerator_history_(new ui::AcceleratorHistory
) {
705 AcceleratorController::~AcceleratorController() {
708 void AcceleratorController::Register(const ui::Accelerator
& accelerator
,
709 ui::AcceleratorTarget
* target
) {
710 accelerator_manager_
->Register(accelerator
,
711 ui::AcceleratorManager::kNormalPriority
,
715 void AcceleratorController::Unregister(const ui::Accelerator
& accelerator
,
716 ui::AcceleratorTarget
* target
) {
717 accelerator_manager_
->Unregister(accelerator
, target
);
720 void AcceleratorController::UnregisterAll(ui::AcceleratorTarget
* target
) {
721 accelerator_manager_
->UnregisterAll(target
);
724 bool AcceleratorController::Process(const ui::Accelerator
& accelerator
) {
725 if (ime_control_delegate_
) {
726 return accelerator_manager_
->Process(
727 ime_control_delegate_
->RemapAccelerator(accelerator
));
729 return accelerator_manager_
->Process(accelerator
);
732 bool AcceleratorController::IsRegistered(
733 const ui::Accelerator
& accelerator
) const {
734 return accelerator_manager_
->GetCurrentTarget(accelerator
) != NULL
;
737 bool AcceleratorController::IsPreferred(
738 const ui::Accelerator
& accelerator
) const {
739 const ui::Accelerator remapped_accelerator
= ime_control_delegate_
.get() ?
740 ime_control_delegate_
->RemapAccelerator(accelerator
) : accelerator
;
742 std::map
<ui::Accelerator
, AcceleratorAction
>::const_iterator iter
=
743 accelerators_
.find(remapped_accelerator
);
744 if (iter
== accelerators_
.end())
745 return false; // not an accelerator.
747 return preferred_actions_
.find(iter
->second
) != preferred_actions_
.end();
750 bool AcceleratorController::IsReserved(
751 const ui::Accelerator
& accelerator
) const {
752 const ui::Accelerator remapped_accelerator
= ime_control_delegate_
.get() ?
753 ime_control_delegate_
->RemapAccelerator(accelerator
) : accelerator
;
755 std::map
<ui::Accelerator
, AcceleratorAction
>::const_iterator iter
=
756 accelerators_
.find(remapped_accelerator
);
757 if (iter
== accelerators_
.end())
758 return false; // not an accelerator.
760 return reserved_actions_
.find(iter
->second
) != reserved_actions_
.end();
763 bool AcceleratorController::PerformActionIfEnabled(AcceleratorAction action
) {
764 if (CanPerformAction(action
, ui::Accelerator())) {
765 PerformAction(action
, ui::Accelerator());
771 AcceleratorController::AcceleratorProcessingRestriction
772 AcceleratorController::GetCurrentAcceleratorRestriction() {
773 return GetAcceleratorProcessingRestriction(-1);
776 void AcceleratorController::SetBrightnessControlDelegate(
777 scoped_ptr
<BrightnessControlDelegate
> brightness_control_delegate
) {
778 brightness_control_delegate_
= brightness_control_delegate
.Pass();
781 void AcceleratorController::SetImeControlDelegate(
782 scoped_ptr
<ImeControlDelegate
> ime_control_delegate
) {
783 ime_control_delegate_
= ime_control_delegate
.Pass();
786 void AcceleratorController::SetScreenshotDelegate(
787 scoped_ptr
<ScreenshotDelegate
> screenshot_delegate
) {
788 screenshot_delegate_
= screenshot_delegate
.Pass();
791 ////////////////////////////////////////////////////////////////////////////////
792 // AcceleratorController, ui::AcceleratorTarget implementation:
794 bool AcceleratorController::AcceleratorPressed(
795 const ui::Accelerator
& accelerator
) {
796 std::map
<ui::Accelerator
, AcceleratorAction
>::const_iterator it
=
797 accelerators_
.find(accelerator
);
798 DCHECK(it
!= accelerators_
.end());
799 AcceleratorAction action
= it
->second
;
800 if (CanPerformAction(action
, accelerator
)) {
801 PerformAction(action
, accelerator
);
802 return ShouldActionConsumeKeyEvent(action
);
807 bool AcceleratorController::CanHandleAccelerators() const {
811 ///////////////////////////////////////////////////////////////////////////////
812 // AcceleratorController, private:
814 void AcceleratorController::Init() {
815 for (size_t i
= 0; i
< kActionsAllowedAtLoginOrLockScreenLength
; ++i
) {
816 actions_allowed_at_login_screen_
.insert(
817 kActionsAllowedAtLoginOrLockScreen
[i
]);
818 actions_allowed_at_lock_screen_
.insert(
819 kActionsAllowedAtLoginOrLockScreen
[i
]);
821 for (size_t i
= 0; i
< kActionsAllowedAtLockScreenLength
; ++i
)
822 actions_allowed_at_lock_screen_
.insert(kActionsAllowedAtLockScreen
[i
]);
823 for (size_t i
= 0; i
< kActionsAllowedAtModalWindowLength
; ++i
)
824 actions_allowed_at_modal_window_
.insert(kActionsAllowedAtModalWindow
[i
]);
825 for (size_t i
= 0; i
< kPreferredActionsLength
; ++i
)
826 preferred_actions_
.insert(kPreferredActions
[i
]);
827 for (size_t i
= 0; i
< kReservedActionsLength
; ++i
)
828 reserved_actions_
.insert(kReservedActions
[i
]);
829 for (size_t i
= 0; i
< kNonrepeatableActionsLength
; ++i
)
830 nonrepeatable_actions_
.insert(kNonrepeatableActions
[i
]);
831 for (size_t i
= 0; i
< kActionsAllowedInAppModeLength
; ++i
)
832 actions_allowed_in_app_mode_
.insert(kActionsAllowedInAppMode
[i
]);
833 for (size_t i
= 0; i
< kActionsNeedingWindowLength
; ++i
)
834 actions_needing_window_
.insert(kActionsNeedingWindow
[i
]);
836 RegisterAccelerators(kAcceleratorData
, kAcceleratorDataLength
);
838 if (debug::DebugAcceleratorsEnabled()) {
839 RegisterAccelerators(kDebugAcceleratorData
, kDebugAcceleratorDataLength
);
840 // All debug accelerators are reserved.
841 for (size_t i
= 0; i
< kDebugAcceleratorDataLength
; ++i
)
842 reserved_actions_
.insert(kDebugAcceleratorData
[i
].action
);
845 #if defined(OS_CHROMEOS)
846 keyboard_brightness_control_delegate_
.reset(
847 new KeyboardBrightnessController());
851 void AcceleratorController::RegisterAccelerators(
852 const AcceleratorData accelerators
[],
853 size_t accelerators_length
) {
854 for (size_t i
= 0; i
< accelerators_length
; ++i
) {
855 ui::Accelerator
accelerator(accelerators
[i
].keycode
,
856 accelerators
[i
].modifiers
);
857 accelerator
.set_type(accelerators
[i
].trigger_on_press
?
858 ui::ET_KEY_PRESSED
: ui::ET_KEY_RELEASED
);
859 Register(accelerator
, this);
860 accelerators_
.insert(
861 std::make_pair(accelerator
, accelerators
[i
].action
));
865 bool AcceleratorController::CanPerformAction(
866 AcceleratorAction action
,
867 const ui::Accelerator
& accelerator
) {
868 if (nonrepeatable_actions_
.find(action
) != nonrepeatable_actions_
.end() &&
869 accelerator
.IsRepeat()) {
873 AcceleratorProcessingRestriction restriction
=
874 GetAcceleratorProcessingRestriction(action
);
875 if (restriction
!= RESTRICTION_NONE
)
876 return restriction
== RESTRICTION_PREVENT_PROCESSING_AND_PROPAGATION
;
878 const ui::Accelerator
& previous_accelerator
=
879 accelerator_history_
->previous_accelerator();
881 // True should be returned if running |action| does something. Otherwise,
882 // false should be returned to give the web contents a chance at handling the
885 case ACCESSIBLE_FOCUS_NEXT
:
886 case ACCESSIBLE_FOCUS_PREVIOUS
:
887 return CanHandleAccessibleFocusCycle();
888 case DEBUG_PRINT_LAYER_HIERARCHY
:
889 case DEBUG_PRINT_VIEW_HIERARCHY
:
890 case DEBUG_PRINT_WINDOW_HIERARCHY
:
891 case DEBUG_TOGGLE_DESKTOP_BACKGROUND_MODE
:
892 case DEBUG_TOGGLE_DEVICE_SCALE_FACTOR
:
893 case DEBUG_TOGGLE_ROOT_WINDOW_FULL_SCREEN
:
894 case DEBUG_TOGGLE_SHOW_DEBUG_BORDERS
:
895 case DEBUG_TOGGLE_SHOW_FPS_COUNTER
:
896 case DEBUG_TOGGLE_SHOW_PAINT_RECTS
:
897 return debug::DebugAcceleratorsEnabled();
898 case MAGNIFY_SCREEN_ZOOM_IN
:
899 case MAGNIFY_SCREEN_ZOOM_OUT
:
900 return CanHandleMagnifyScreen();
901 case NEW_INCOGNITO_WINDOW
:
902 return CanHandleNewIncognitoWindow();
904 return CanHandleNextIme(ime_control_delegate_
.get(),
905 previous_accelerator
);
907 return CanHandlePreviousIme(ime_control_delegate_
.get());
909 return CanHandleScaleReset();
912 return CanHandleScaleUI();
913 case SHOW_MESSAGE_CENTER_BUBBLE
:
914 return CanHandleShowMessageCenterBubble();
916 return CanHandleSwitchIme(ime_control_delegate_
.get(), accelerator
);
917 case TOGGLE_APP_LIST
:
918 return CanHandleToggleAppList(accelerator
, previous_accelerator
);
919 case WINDOW_CYCLE_SNAP_DOCK_LEFT
:
920 case WINDOW_CYCLE_SNAP_DOCK_RIGHT
:
921 return CanHandleWindowSnapOrDock();
922 case WINDOW_POSITION_CENTER
:
923 return CanHandlePositionCenter();
924 #if defined(OS_CHROMEOS)
925 case DEBUG_ADD_REMOVE_DISPLAY
:
926 return debug::DebugAcceleratorsEnabled();
927 case DISABLE_CAPS_LOCK
:
928 return CanHandleDisableCapsLock(previous_accelerator
);
929 case SILENCE_SPOKEN_FEEDBACK
:
930 return CanHandleSilenceSpokenFeedback();
931 case SWITCH_TO_PREVIOUS_USER
:
932 case SWITCH_TO_NEXT_USER
:
933 return CanHandleCycleUser();
934 case TOGGLE_CAPS_LOCK
:
935 return CanHandleToggleCapsLock(accelerator
, previous_accelerator
);
936 case TOGGLE_TOUCH_VIEW_TESTING
:
937 return CanHandleToggleTouchViewTesting();
938 case TOUCH_HUD_CLEAR
:
939 case TOUCH_HUD_MODE_CHANGE
:
940 return CanHandleTouchHud();
943 case CYCLE_BACKWARD_MRU
:
944 case CYCLE_FORWARD_MRU
:
946 case FOCUS_NEXT_PANE
:
947 case FOCUS_PREVIOUS_PANE
:
957 case LAUNCH_LAST_APP
:
958 case MEDIA_NEXT_TRACK
:
959 case MEDIA_PLAY_PAUSE
:
960 case MEDIA_PREV_TRACK
:
963 case OPEN_FEEDBACK_PAGE
:
964 case PRINT_UI_HIERARCHIES
:
968 case SHOW_KEYBOARD_OVERLAY
:
969 case SHOW_SYSTEM_TRAY_BUBBLE
:
970 case SHOW_TASK_MANAGER
:
971 case TAKE_PARTIAL_SCREENSHOT
:
972 case TAKE_SCREENSHOT
:
973 case TOGGLE_FULLSCREEN
:
974 case TOGGLE_MAXIMIZED
:
975 case TOGGLE_OVERVIEW
:
976 case WINDOW_MINIMIZE
:
977 #if defined(OS_CHROMEOS)
978 case BRIGHTNESS_DOWN
:
980 case DISABLE_GPU_WATCHDOG
:
981 case KEYBOARD_BRIGHTNESS_DOWN
:
982 case KEYBOARD_BRIGHTNESS_UP
:
987 case OPEN_FILE_MANAGER
:
991 case SWAP_PRIMARY_DISPLAY
:
992 case TOGGLE_MIRROR_MODE
:
993 case TOGGLE_SPOKEN_FEEDBACK
:
995 case TOUCH_HUD_PROJECTION_TOGGLE
:
1000 case DUMMY_FOR_RESERVED
:
1007 void AcceleratorController::PerformAction(AcceleratorAction action
,
1008 const ui::Accelerator
& accelerator
) {
1009 AcceleratorProcessingRestriction restriction
=
1010 GetAcceleratorProcessingRestriction(action
);
1011 if (restriction
!= RESTRICTION_NONE
)
1014 // If your accelerator invokes more than one line of code, please either
1015 // implement it in your module's controller code (like TOGGLE_MIRROR_MODE
1016 // below) or pull it into a HandleFoo() function above.
1018 case ACCESSIBLE_FOCUS_NEXT
:
1019 HandleAccessibleFocusCycle(false);
1021 case ACCESSIBLE_FOCUS_PREVIOUS
:
1022 HandleAccessibleFocusCycle(true);
1024 case CYCLE_BACKWARD_MRU
:
1025 HandleCycleBackwardMRU(accelerator
);
1027 case CYCLE_FORWARD_MRU
:
1028 HandleCycleForwardMRU(accelerator
);
1030 case DEBUG_PRINT_LAYER_HIERARCHY
:
1031 case DEBUG_PRINT_VIEW_HIERARCHY
:
1032 case DEBUG_PRINT_WINDOW_HIERARCHY
:
1033 case DEBUG_TOGGLE_DESKTOP_BACKGROUND_MODE
:
1034 case DEBUG_TOGGLE_DEVICE_SCALE_FACTOR
:
1035 case DEBUG_TOGGLE_ROOT_WINDOW_FULL_SCREEN
:
1036 case DEBUG_TOGGLE_SHOW_DEBUG_BORDERS
:
1037 case DEBUG_TOGGLE_SHOW_FPS_COUNTER
:
1038 case DEBUG_TOGGLE_SHOW_PAINT_RECTS
:
1039 debug::PerformDebugActionIfEnabled(action
);
1042 // UMA metrics are recorded in the handler.
1043 exit_warning_handler_
.HandleAccelerator();
1045 case FOCUS_NEXT_PANE
:
1046 HandleRotatePaneFocus(Shell::FORWARD
);
1048 case FOCUS_PREVIOUS_PANE
:
1049 HandleRotatePaneFocus(Shell::BACKWARD
);
1055 HandleLaunchAppN(0);
1058 HandleLaunchAppN(1);
1061 HandleLaunchAppN(2);
1064 HandleLaunchAppN(3);
1067 HandleLaunchAppN(4);
1070 HandleLaunchAppN(5);
1073 HandleLaunchAppN(6);
1076 HandleLaunchAppN(7);
1078 case LAUNCH_LAST_APP
:
1079 HandleLaunchLastApp();
1081 case MAGNIFY_SCREEN_ZOOM_IN
:
1082 HandleMagnifyScreen(1);
1084 case MAGNIFY_SCREEN_ZOOM_OUT
:
1085 HandleMagnifyScreen(-1);
1087 case MEDIA_NEXT_TRACK
:
1088 HandleMediaNextTrack();
1090 case MEDIA_PLAY_PAUSE
:
1091 HandleMediaPlayPause();
1093 case MEDIA_PREV_TRACK
:
1094 HandleMediaPrevTrack();
1096 case NEW_INCOGNITO_WINDOW
:
1097 HandleNewIncognitoWindow();
1100 HandleNewTab(accelerator
);
1106 HandleNextIme(ime_control_delegate_
.get());
1108 case OPEN_FEEDBACK_PAGE
:
1109 HandleOpenFeedbackPage();
1112 HandlePreviousIme(ime_control_delegate_
.get(), accelerator
);
1114 case PRINT_UI_HIERARCHIES
:
1115 debug::PrintUIHierarchies();
1121 HandleRotateScreen();
1124 HandleRotateActiveWindow();
1127 HandleScaleUI(false /* down */);
1129 case SCALE_UI_RESET
:
1133 HandleScaleUI(true /* up */);
1135 case SHOW_KEYBOARD_OVERLAY
:
1136 HandleShowKeyboardOverlay();
1138 case SHOW_MESSAGE_CENTER_BUBBLE
:
1139 HandleShowMessageCenterBubble();
1141 case SHOW_SYSTEM_TRAY_BUBBLE
:
1142 HandleShowSystemTrayBubble();
1144 case SHOW_TASK_MANAGER
:
1145 HandleShowTaskManager();
1148 HandleSwitchIme(ime_control_delegate_
.get(), accelerator
);
1150 case TAKE_PARTIAL_SCREENSHOT
:
1151 HandleTakePartialScreenshot(screenshot_delegate_
.get());
1153 case TAKE_SCREENSHOT
:
1154 HandleTakeScreenshot(screenshot_delegate_
.get());
1156 case TOGGLE_APP_LIST
:
1157 HandleToggleAppList(accelerator
);
1159 case TOGGLE_FULLSCREEN
:
1160 HandleToggleFullscreen(accelerator
);
1162 case TOGGLE_MAXIMIZED
:
1163 accelerators::ToggleMaximized();
1165 case TOGGLE_OVERVIEW
:
1166 HandleToggleOverview();
1168 case WINDOW_CYCLE_SNAP_DOCK_LEFT
:
1169 case WINDOW_CYCLE_SNAP_DOCK_RIGHT
:
1170 HandleWindowSnapOrDock(action
);
1172 case WINDOW_MINIMIZE
:
1173 HandleWindowMinimize();
1175 case WINDOW_POSITION_CENTER
:
1176 HandlePositionCenter();
1178 #if defined(OS_CHROMEOS)
1179 case BRIGHTNESS_DOWN
:
1180 HandleBrightnessDown(brightness_control_delegate_
.get(), accelerator
);
1183 HandleBrightnessUp(brightness_control_delegate_
.get(), accelerator
);
1185 case DEBUG_ADD_REMOVE_DISPLAY
:
1186 debug::PerformDebugActionIfEnabled(action
);
1188 case DISABLE_CAPS_LOCK
:
1189 HandleDisableCapsLock();
1191 case DISABLE_GPU_WATCHDOG
:
1192 Shell::GetInstance()->gpu_support()->DisableGpuWatchdog();
1194 case KEYBOARD_BRIGHTNESS_DOWN
:
1195 HandleKeyboardBrightnessDown(keyboard_brightness_control_delegate_
.get(),
1198 case KEYBOARD_BRIGHTNESS_UP
:
1199 HandleKeyboardBrightnessUp(keyboard_brightness_control_delegate_
.get(),
1204 Shell::GetInstance()->power_button_controller()->
1205 OnLockButtonEvent(action
== LOCK_PRESSED
, base::TimeTicks());
1213 case OPEN_FILE_MANAGER
:
1214 HandleFileManager();
1219 case POWER_PRESSED
: // fallthrough
1220 case POWER_RELEASED
:
1221 if (!base::SysInfo::IsRunningOnChromeOS()) {
1222 // There is no powerd, the Chrome OS power manager, in linux desktop,
1223 // so call the PowerButtonController here.
1224 Shell::GetInstance()->power_button_controller()->
1225 OnPowerButtonEvent(action
== POWER_PRESSED
, base::TimeTicks());
1227 // We don't do anything with these at present on the device,
1228 // (power button events are reported to us from powerm via
1229 // D-BUS), but we consume them to prevent them from getting
1230 // passed to apps -- see http://crbug.com/146609.
1232 case SILENCE_SPOKEN_FEEDBACK
:
1233 HandleSilenceSpokenFeedback();
1235 case SWAP_PRIMARY_DISPLAY
:
1236 HandleSwapPrimaryDisplay();
1238 case SWITCH_TO_NEXT_USER
:
1239 HandleCycleUser(SessionStateDelegate::CYCLE_TO_NEXT_USER
);
1241 case SWITCH_TO_PREVIOUS_USER
:
1242 HandleCycleUser(SessionStateDelegate::CYCLE_TO_PREVIOUS_USER
);
1244 case TOGGLE_CAPS_LOCK
:
1245 HandleToggleCapsLock();
1247 case TOGGLE_MIRROR_MODE
:
1248 HandleToggleMirrorMode();
1250 case TOGGLE_SPOKEN_FEEDBACK
:
1251 HandleToggleSpokenFeedback();
1253 case TOGGLE_TOUCH_VIEW_TESTING
:
1254 HandleToggleTouchViewTesting();
1257 Shell::GetInstance()->system_tray_notifier()->NotifyRequestToggleWifi();
1259 case TOUCH_HUD_CLEAR
:
1260 HandleTouchHudClear();
1262 case TOUCH_HUD_MODE_CHANGE
:
1263 HandleTouchHudModeChange();
1265 case TOUCH_HUD_PROJECTION_TOGGLE
:
1266 accelerators::ToggleTouchHudProjection();
1269 HandleVolumeDown(accelerator
);
1272 HandleVolumeMute(accelerator
);
1275 HandleVolumeUp(accelerator
);
1278 case DUMMY_FOR_RESERVED
:
1285 bool AcceleratorController::ShouldActionConsumeKeyEvent(
1286 AcceleratorAction action
) {
1287 #if defined(OS_CHROMEOS)
1288 if (action
== SILENCE_SPOKEN_FEEDBACK
)
1292 // Adding new exceptions is *STRONGLY* discouraged.
1296 AcceleratorController::AcceleratorProcessingRestriction
1297 AcceleratorController::GetAcceleratorProcessingRestriction(int action
) {
1298 ash::Shell
* shell
= ash::Shell::GetInstance();
1299 if (!shell
->session_state_delegate()->IsActiveUserSessionStarted() &&
1300 actions_allowed_at_login_screen_
.find(action
) ==
1301 actions_allowed_at_login_screen_
.end()) {
1302 return RESTRICTION_PREVENT_PROCESSING
;
1304 if (shell
->session_state_delegate()->IsScreenLocked() &&
1305 actions_allowed_at_lock_screen_
.find(action
) ==
1306 actions_allowed_at_lock_screen_
.end()) {
1307 return RESTRICTION_PREVENT_PROCESSING
;
1309 if (shell
->delegate()->IsRunningInForcedAppMode() &&
1310 actions_allowed_in_app_mode_
.find(action
) ==
1311 actions_allowed_in_app_mode_
.end()) {
1312 return RESTRICTION_PREVENT_PROCESSING
;
1314 if (shell
->IsSystemModalWindowOpen() &&
1315 actions_allowed_at_modal_window_
.find(action
) ==
1316 actions_allowed_at_modal_window_
.end()) {
1317 // Note we prevent the shortcut from propagating so it will not
1318 // be passed to the modal window. This is important for things like
1319 // Alt+Tab that would cause an undesired effect in the modal window by
1320 // cycling through its window elements.
1321 return RESTRICTION_PREVENT_PROCESSING_AND_PROPAGATION
;
1323 if (shell
->mru_window_tracker()->BuildMruWindowList().empty() &&
1324 actions_needing_window_
.find(action
) != actions_needing_window_
.end()) {
1325 Shell::GetInstance()->accessibility_delegate()->TriggerAccessibilityAlert(
1326 ui::A11Y_ALERT_WINDOW_NEEDED
);
1327 return RESTRICTION_PREVENT_PROCESSING_AND_PROPAGATION
;
1329 return RESTRICTION_NONE
;
1332 void AcceleratorController::SetKeyboardBrightnessControlDelegate(
1333 scoped_ptr
<KeyboardBrightnessControlDelegate
>
1334 keyboard_brightness_control_delegate
) {
1335 keyboard_brightness_control_delegate_
=
1336 keyboard_brightness_control_delegate
.Pass();