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
.rotation()));
301 // Rotate the active window.
302 void HandleRotateActiveWindow() {
303 base::RecordAction(UserMetricsAction("Accel_Rotate_Window"));
304 aura::Window
* active_window
= wm::GetActiveWindow();
306 // The rotation animation bases its target transform on the current
307 // rotation and position. Since there could be an animation in progress
308 // right now, queue this animation so when it starts it picks up a neutral
309 // rotation and position. Use replace so we only enqueue one at a time.
310 active_window
->layer()->GetAnimator()->
311 set_preemption_strategy(ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS
);
312 active_window
->layer()->GetAnimator()->StartAnimation(
313 new ui::LayerAnimationSequence(
314 new ash::WindowRotation(360, active_window
->layer())));
318 bool CanHandleScaleReset() {
319 DisplayManager
* display_manager
= Shell::GetInstance()->display_manager();
320 int64 display_id
= display_manager
->GetDisplayIdForUIScaling();
321 return (display_id
!= gfx::Display::kInvalidDisplayID
&&
322 display_manager
->GetDisplayInfo(display_id
).configured_ui_scale() !=
326 void HandleScaleReset() {
327 base::RecordAction(UserMetricsAction("Accel_Scale_Ui_Reset"));
328 DisplayManager
* display_manager
= Shell::GetInstance()->display_manager();
329 int64 display_id
= display_manager
->GetDisplayIdForUIScaling();
330 display_manager
->SetDisplayUIScale(display_id
, 1.0f
);
333 bool CanHandleScaleUI() {
334 DisplayManager
* display_manager
= Shell::GetInstance()->display_manager();
335 int64 display_id
= display_manager
->GetDisplayIdForUIScaling();
336 return display_id
!= gfx::Display::kInvalidDisplayID
;
339 void HandleScaleUI(bool up
) {
340 DisplayManager
* display_manager
= Shell::GetInstance()->display_manager();
341 int64 display_id
= display_manager
->GetDisplayIdForUIScaling();
344 base::RecordAction(UserMetricsAction("Accel_Scale_Ui_Up"));
346 base::RecordAction(UserMetricsAction("Accel_Scale_Ui_Down"));
349 const DisplayInfo
& display_info
= display_manager
->GetDisplayInfo(display_id
);
350 float next_scale
= GetNextUIScale(display_info
, up
);
351 display_manager
->SetDisplayUIScale(display_id
, next_scale
);
354 void HandleShowKeyboardOverlay() {
355 base::RecordAction(UserMetricsAction("Accel_Show_Keyboard_Overlay"));
356 ash::Shell::GetInstance()->new_window_delegate()->ShowKeyboardOverlay();
359 bool CanHandleShowMessageCenterBubble() {
360 RootWindowController
* controller
=
361 RootWindowController::ForTargetRootWindow();
362 StatusAreaWidget
* status_area_widget
=
363 controller
->shelf()->status_area_widget();
364 return status_area_widget
&&
365 status_area_widget
->web_notification_tray()->visible();
368 void HandleShowMessageCenterBubble() {
369 base::RecordAction(UserMetricsAction("Accel_Show_Message_Center_Bubble"));
370 RootWindowController
* controller
=
371 RootWindowController::ForTargetRootWindow();
372 StatusAreaWidget
* status_area_widget
=
373 controller
->shelf()->status_area_widget();
374 if (status_area_widget
) {
375 WebNotificationTray
* notification_tray
=
376 status_area_widget
->web_notification_tray();
377 if (notification_tray
->visible())
378 notification_tray
->ShowMessageCenterBubble();
382 void HandleShowSystemTrayBubble() {
383 base::RecordAction(UserMetricsAction("Accel_Show_System_Tray_Bubble"));
384 RootWindowController
* controller
=
385 RootWindowController::ForTargetRootWindow();
386 if (!controller
->GetSystemTray()->HasSystemBubble())
387 controller
->GetSystemTray()->ShowDefaultView(BUBBLE_CREATE_NEW
);
390 void HandleShowTaskManager() {
391 base::RecordAction(UserMetricsAction("Accel_Show_Task_Manager"));
392 Shell::GetInstance()->new_window_delegate()->ShowTaskManager();
395 bool CanHandleSwitchIme(ImeControlDelegate
* ime_control_delegate
,
396 const ui::Accelerator
& accelerator
) {
397 return ime_control_delegate
&&
398 ime_control_delegate
->CanSwitchIme(accelerator
);
401 void HandleSwitchIme(ImeControlDelegate
* ime_control_delegate
,
402 const ui::Accelerator
& accelerator
) {
403 base::RecordAction(UserMetricsAction("Accel_Switch_Ime"));
404 ime_control_delegate
->HandleSwitchIme(accelerator
);
407 void HandleTakePartialScreenshot(ScreenshotDelegate
* screenshot_delegate
) {
408 base::RecordAction(UserMetricsAction("Accel_Take_Partial_Screenshot"));
409 DCHECK(screenshot_delegate
);
411 ->partial_screenshot_controller()
412 ->StartPartialScreenshotSession(screenshot_delegate
);
415 void HandleTakeScreenshot(ScreenshotDelegate
* screenshot_delegate
) {
416 base::RecordAction(UserMetricsAction("Accel_Take_Screenshot"));
417 DCHECK(screenshot_delegate
);
418 if (screenshot_delegate
->CanTakeScreenshot())
419 screenshot_delegate
->HandleTakeScreenshotForAllRootWindows();
422 bool CanHandleToggleAppList(const ui::Accelerator
& accelerator
,
423 const ui::Accelerator
& previous_accelerator
) {
424 if (accelerator
.key_code() == ui::VKEY_LWIN
) {
425 // If something else was pressed between the Search key (LWIN)
426 // being pressed and released, then ignore the release of the
428 if (previous_accelerator
.type() != ui::ET_KEY_PRESSED
||
429 previous_accelerator
.key_code() != ui::VKEY_LWIN
) {
433 // When spoken feedback is enabled, we should neither toggle the list nor
434 // consume the key since Search+Shift is one of the shortcuts the a11y
435 // feature uses. crbug.com/132296
436 if (Shell::GetInstance()
437 ->accessibility_delegate()
438 ->IsSpokenFeedbackEnabled()) {
445 void HandleToggleAppList(const ui::Accelerator
& accelerator
) {
446 if (accelerator
.key_code() == ui::VKEY_LWIN
)
447 base::RecordAction(base::UserMetricsAction("Accel_Search_LWin"));
448 ash::Shell::GetInstance()->ToggleAppList(NULL
);
451 void HandleToggleFullscreen(const ui::Accelerator
& accelerator
) {
452 if (accelerator
.key_code() == ui::VKEY_MEDIA_LAUNCH_APP2
)
453 base::RecordAction(UserMetricsAction("Accel_Fullscreen_F4"));
454 accelerators::ToggleFullscreen();
457 void HandleToggleOverview() {
458 base::RecordAction(base::UserMetricsAction("Accel_Overview_F5"));
459 Shell::GetInstance()->window_selector_controller()->ToggleOverview();
462 bool CanHandleWindowSnapOrDock() {
463 wm::WindowState
* window_state
= wm::GetActiveWindowState();
464 // Disable window snapping shortcut key for full screen window due to
465 // http://crbug.com/135487.
466 return (window_state
&&
467 (window_state
->window()->type() == ui::wm::WINDOW_TYPE_NORMAL
||
468 window_state
->window()->type() == ui::wm::WINDOW_TYPE_PANEL
) &&
469 !window_state
->IsFullscreen());
472 void HandleWindowSnapOrDock(AcceleratorAction action
) {
473 if (action
== WINDOW_CYCLE_SNAP_DOCK_LEFT
)
474 base::RecordAction(UserMetricsAction("Accel_Window_Snap_Left"));
476 base::RecordAction(UserMetricsAction("Accel_Window_Snap_Right"));
478 const wm::WMEvent
event(action
== WINDOW_CYCLE_SNAP_DOCK_LEFT
?
479 wm::WM_EVENT_CYCLE_SNAP_DOCK_LEFT
:
480 wm::WM_EVENT_CYCLE_SNAP_DOCK_RIGHT
);
481 wm::GetActiveWindowState()->OnWMEvent(&event
);
484 void HandleWindowMinimize() {
486 base::UserMetricsAction("Accel_Toggle_Minimized_Minus"));
487 accelerators::ToggleMinimized();
490 bool CanHandlePositionCenter() {
491 // Docked windows do not support centering.
492 wm::WindowState
* window_state
= wm::GetActiveWindowState();
493 return (window_state
&& !window_state
->IsDocked());
496 void HandlePositionCenter() {
497 base::RecordAction(UserMetricsAction("Accel_Window_Position_Center"));
498 wm::CenterWindow(wm::GetActiveWindow());
501 #if defined(OS_CHROMEOS)
502 void HandleBrightnessDown(BrightnessControlDelegate
* delegate
,
503 const ui::Accelerator
& accelerator
) {
505 delegate
->HandleBrightnessDown(accelerator
);
508 void HandleBrightnessUp(BrightnessControlDelegate
* delegate
,
509 const ui::Accelerator
& accelerator
) {
511 delegate
->HandleBrightnessUp(accelerator
);
514 bool CanHandleDisableCapsLock(const ui::Accelerator
& previous_accelerator
) {
515 ui::KeyboardCode previous_key_code
= previous_accelerator
.key_code();
516 if (previous_accelerator
.type() == ui::ET_KEY_RELEASED
||
517 (previous_key_code
!= ui::VKEY_LSHIFT
&&
518 previous_key_code
!= ui::VKEY_SHIFT
&&
519 previous_key_code
!= ui::VKEY_RSHIFT
)) {
520 // If something else was pressed between the Shift key being pressed
521 // and released, then ignore the release of the Shift key.
524 chromeos::input_method::InputMethodManager
* ime
=
525 chromeos::input_method::InputMethodManager::Get();
526 chromeos::input_method::ImeKeyboard
* keyboard
=
527 ime
? ime
->GetImeKeyboard() : NULL
;
528 return (keyboard
&& keyboard
->CapsLockIsEnabled());
531 void HandleDisableCapsLock() {
532 base::RecordAction(UserMetricsAction("Accel_Disable_Caps_Lock"));
533 chromeos::input_method::InputMethodManager
* ime
=
534 chromeos::input_method::InputMethodManager::Get();
535 ime
->GetImeKeyboard()->SetCapsLockEnabled(false);
538 void HandleKeyboardBrightnessDown(KeyboardBrightnessControlDelegate
* delegate
,
539 const ui::Accelerator
& accelerator
) {
541 delegate
->HandleKeyboardBrightnessDown(accelerator
);
544 void HandleKeyboardBrightnessUp(KeyboardBrightnessControlDelegate
* delegate
,
545 const ui::Accelerator
& accelerator
) {
547 delegate
->HandleKeyboardBrightnessUp(accelerator
);
551 base::RecordAction(UserMetricsAction("Accel_LockScreen_L"));
552 Shell::GetInstance()->session_state_delegate()->LockScreen();
556 base::RecordAction(UserMetricsAction("Accel_Open_Crosh"));
558 Shell::GetInstance()->new_window_delegate()->OpenCrosh();
561 void HandleFileManager() {
562 base::RecordAction(UserMetricsAction("Accel_Open_File_Manager"));
564 Shell::GetInstance()->new_window_delegate()->OpenFileManager();
567 void HandleGetHelp() {
568 Shell::GetInstance()->new_window_delegate()->OpenGetHelp();
571 bool CanHandleSilenceSpokenFeedback() {
572 AccessibilityDelegate
* delegate
=
573 Shell::GetInstance()->accessibility_delegate();
574 return delegate
->IsSpokenFeedbackEnabled();
577 void HandleSilenceSpokenFeedback() {
578 base::RecordAction(UserMetricsAction("Accel_Silence_Spoken_Feedback"));
579 Shell::GetInstance()->accessibility_delegate()->SilenceSpokenFeedback();
582 void HandleSwapPrimaryDisplay() {
583 base::RecordAction(UserMetricsAction("Accel_Swap_Primary_Display"));
584 Shell::GetInstance()->display_controller()->SwapPrimaryDisplay();
587 bool CanHandleCycleUser() {
588 Shell
* shell
= Shell::GetInstance();
589 return shell
->delegate()->IsMultiProfilesEnabled() &&
590 shell
->session_state_delegate()->NumberOfLoggedInUsers() > 1;
593 void HandleCycleUser(SessionStateDelegate::CycleUser cycle_user
) {
594 MultiProfileUMA::RecordSwitchActiveUser(
595 MultiProfileUMA::SWITCH_ACTIVE_USER_BY_ACCELERATOR
);
596 switch (cycle_user
) {
597 case SessionStateDelegate::CYCLE_TO_NEXT_USER
:
598 base::RecordAction(UserMetricsAction("Accel_Switch_To_Next_User"));
600 case SessionStateDelegate::CYCLE_TO_PREVIOUS_USER
:
601 base::RecordAction(UserMetricsAction("Accel_Switch_To_Previous_User"));
604 Shell::GetInstance()->session_state_delegate()->CycleActiveUser(cycle_user
);
607 bool CanHandleToggleCapsLock(const ui::Accelerator
& accelerator
,
608 const ui::Accelerator
& previous_accelerator
) {
609 if (accelerator
.key_code() == ui::VKEY_LWIN
) {
610 // If something else was pressed between the Search key (LWIN)
611 // being pressed and released, then ignore the release of the
613 // TODO(danakj): Releasing Alt first breaks this: crbug.com/166495
614 if (previous_accelerator
.type() == ui::ET_KEY_RELEASED
||
615 previous_accelerator
.key_code() != ui::VKEY_LWIN
)
618 chromeos::input_method::InputMethodManager
* ime
=
619 chromeos::input_method::InputMethodManager::Get();
620 return ime
&& ime
->GetImeKeyboard();
623 void HandleToggleCapsLock() {
624 base::RecordAction(UserMetricsAction("Accel_Toggle_Caps_Lock"));
625 chromeos::input_method::InputMethodManager
* ime
=
626 chromeos::input_method::InputMethodManager::Get();
627 chromeos::input_method::ImeKeyboard
* keyboard
= ime
->GetImeKeyboard();
628 keyboard
->SetCapsLockEnabled(!keyboard
->CapsLockIsEnabled());
631 void HandleToggleMirrorMode() {
632 base::RecordAction(UserMetricsAction("Accel_Toggle_Mirror_Mode"));
633 Shell::GetInstance()->display_controller()->ToggleMirrorMode();
636 void HandleToggleSpokenFeedback() {
637 base::RecordAction(UserMetricsAction("Accel_Toggle_Spoken_Feedback"));
639 Shell::GetInstance()->accessibility_delegate()->
640 ToggleSpokenFeedback(ui::A11Y_NOTIFICATION_SHOW
);
643 bool CanHandleToggleTouchViewTesting() {
644 return base::CommandLine::ForCurrentProcess()->HasSwitch(
645 switches::kAshEnableTouchViewTesting
);
648 void HandleToggleTouchViewTesting() {
649 // TODO(skuhne): This is only temporary! Remove this!
650 MaximizeModeController
* controller
= Shell::GetInstance()->
651 maximize_mode_controller();
652 controller
->EnableMaximizeModeWindowManager(
653 !controller
->IsMaximizeModeWindowManagerEnabled());
656 bool CanHandleTouchHud() {
657 return RootWindowController::ForTargetRootWindow()->touch_hud_debug();
660 void HandleTouchHudClear() {
661 RootWindowController::ForTargetRootWindow()->touch_hud_debug()->Clear();
664 void HandleTouchHudModeChange() {
665 RootWindowController
* controller
=
666 RootWindowController::ForTargetRootWindow();
667 controller
->touch_hud_debug()->ChangeToNextMode();
670 void HandleVolumeDown(const ui::Accelerator
& accelerator
) {
671 VolumeControlDelegate
* volume_delegate
=
672 Shell::GetInstance()->system_tray_delegate()->GetVolumeControlDelegate();
674 volume_delegate
->HandleVolumeDown(accelerator
);
677 void HandleVolumeMute(const ui::Accelerator
& accelerator
) {
678 VolumeControlDelegate
* volume_delegate
=
679 Shell::GetInstance()->system_tray_delegate()->GetVolumeControlDelegate();
681 volume_delegate
->HandleVolumeMute(accelerator
);
684 void HandleVolumeUp(const ui::Accelerator
& accelerator
) {
685 VolumeControlDelegate
* volume_delegate
=
686 Shell::GetInstance()->system_tray_delegate()->GetVolumeControlDelegate();
688 volume_delegate
->HandleVolumeUp(accelerator
);
691 #endif // defined(OS_CHROMEOS)
695 ////////////////////////////////////////////////////////////////////////////////
696 // AcceleratorController, public:
698 AcceleratorController::AcceleratorController()
699 : accelerator_manager_(new ui::AcceleratorManager
),
700 accelerator_history_(new ui::AcceleratorHistory
) {
704 AcceleratorController::~AcceleratorController() {
707 void AcceleratorController::Register(const ui::Accelerator
& accelerator
,
708 ui::AcceleratorTarget
* target
) {
709 accelerator_manager_
->Register(accelerator
,
710 ui::AcceleratorManager::kNormalPriority
,
714 void AcceleratorController::Unregister(const ui::Accelerator
& accelerator
,
715 ui::AcceleratorTarget
* target
) {
716 accelerator_manager_
->Unregister(accelerator
, target
);
719 void AcceleratorController::UnregisterAll(ui::AcceleratorTarget
* target
) {
720 accelerator_manager_
->UnregisterAll(target
);
723 bool AcceleratorController::Process(const ui::Accelerator
& accelerator
) {
724 if (ime_control_delegate_
) {
725 return accelerator_manager_
->Process(
726 ime_control_delegate_
->RemapAccelerator(accelerator
));
728 return accelerator_manager_
->Process(accelerator
);
731 bool AcceleratorController::IsRegistered(
732 const ui::Accelerator
& accelerator
) const {
733 return accelerator_manager_
->GetCurrentTarget(accelerator
) != NULL
;
736 bool AcceleratorController::IsPreferred(
737 const ui::Accelerator
& accelerator
) const {
738 const ui::Accelerator remapped_accelerator
= ime_control_delegate_
.get() ?
739 ime_control_delegate_
->RemapAccelerator(accelerator
) : accelerator
;
741 std::map
<ui::Accelerator
, AcceleratorAction
>::const_iterator iter
=
742 accelerators_
.find(remapped_accelerator
);
743 if (iter
== accelerators_
.end())
744 return false; // not an accelerator.
746 return preferred_actions_
.find(iter
->second
) != preferred_actions_
.end();
749 bool AcceleratorController::IsReserved(
750 const ui::Accelerator
& accelerator
) const {
751 const ui::Accelerator remapped_accelerator
= ime_control_delegate_
.get() ?
752 ime_control_delegate_
->RemapAccelerator(accelerator
) : accelerator
;
754 std::map
<ui::Accelerator
, AcceleratorAction
>::const_iterator iter
=
755 accelerators_
.find(remapped_accelerator
);
756 if (iter
== accelerators_
.end())
757 return false; // not an accelerator.
759 return reserved_actions_
.find(iter
->second
) != reserved_actions_
.end();
762 bool AcceleratorController::PerformActionIfEnabled(AcceleratorAction action
) {
763 if (CanPerformAction(action
, ui::Accelerator())) {
764 PerformAction(action
, ui::Accelerator());
770 AcceleratorController::AcceleratorProcessingRestriction
771 AcceleratorController::GetCurrentAcceleratorRestriction() {
772 return GetAcceleratorProcessingRestriction(-1);
775 void AcceleratorController::SetBrightnessControlDelegate(
776 scoped_ptr
<BrightnessControlDelegate
> brightness_control_delegate
) {
777 brightness_control_delegate_
= brightness_control_delegate
.Pass();
780 void AcceleratorController::SetImeControlDelegate(
781 scoped_ptr
<ImeControlDelegate
> ime_control_delegate
) {
782 ime_control_delegate_
= ime_control_delegate
.Pass();
785 void AcceleratorController::SetScreenshotDelegate(
786 scoped_ptr
<ScreenshotDelegate
> screenshot_delegate
) {
787 screenshot_delegate_
= screenshot_delegate
.Pass();
790 ////////////////////////////////////////////////////////////////////////////////
791 // AcceleratorController, ui::AcceleratorTarget implementation:
793 bool AcceleratorController::AcceleratorPressed(
794 const ui::Accelerator
& accelerator
) {
795 std::map
<ui::Accelerator
, AcceleratorAction
>::const_iterator it
=
796 accelerators_
.find(accelerator
);
797 DCHECK(it
!= accelerators_
.end());
798 AcceleratorAction action
= it
->second
;
799 if (CanPerformAction(action
, accelerator
)) {
800 PerformAction(action
, accelerator
);
801 return ShouldActionConsumeKeyEvent(action
);
806 bool AcceleratorController::CanHandleAccelerators() const {
810 ///////////////////////////////////////////////////////////////////////////////
811 // AcceleratorController, private:
813 void AcceleratorController::Init() {
814 for (size_t i
= 0; i
< kActionsAllowedAtLoginOrLockScreenLength
; ++i
) {
815 actions_allowed_at_login_screen_
.insert(
816 kActionsAllowedAtLoginOrLockScreen
[i
]);
817 actions_allowed_at_lock_screen_
.insert(
818 kActionsAllowedAtLoginOrLockScreen
[i
]);
820 for (size_t i
= 0; i
< kActionsAllowedAtLockScreenLength
; ++i
)
821 actions_allowed_at_lock_screen_
.insert(kActionsAllowedAtLockScreen
[i
]);
822 for (size_t i
= 0; i
< kActionsAllowedAtModalWindowLength
; ++i
)
823 actions_allowed_at_modal_window_
.insert(kActionsAllowedAtModalWindow
[i
]);
824 for (size_t i
= 0; i
< kPreferredActionsLength
; ++i
)
825 preferred_actions_
.insert(kPreferredActions
[i
]);
826 for (size_t i
= 0; i
< kReservedActionsLength
; ++i
)
827 reserved_actions_
.insert(kReservedActions
[i
]);
828 for (size_t i
= 0; i
< kNonrepeatableActionsLength
; ++i
)
829 nonrepeatable_actions_
.insert(kNonrepeatableActions
[i
]);
830 for (size_t i
= 0; i
< kActionsAllowedInAppModeLength
; ++i
)
831 actions_allowed_in_app_mode_
.insert(kActionsAllowedInAppMode
[i
]);
832 for (size_t i
= 0; i
< kActionsNeedingWindowLength
; ++i
)
833 actions_needing_window_
.insert(kActionsNeedingWindow
[i
]);
835 RegisterAccelerators(kAcceleratorData
, kAcceleratorDataLength
);
837 if (debug::DebugAcceleratorsEnabled()) {
838 RegisterAccelerators(kDebugAcceleratorData
, kDebugAcceleratorDataLength
);
839 // All debug accelerators are reserved.
840 for (size_t i
= 0; i
< kDebugAcceleratorDataLength
; ++i
)
841 reserved_actions_
.insert(kDebugAcceleratorData
[i
].action
);
844 #if defined(OS_CHROMEOS)
845 keyboard_brightness_control_delegate_
.reset(
846 new KeyboardBrightnessController());
850 void AcceleratorController::RegisterAccelerators(
851 const AcceleratorData accelerators
[],
852 size_t accelerators_length
) {
853 for (size_t i
= 0; i
< accelerators_length
; ++i
) {
854 ui::Accelerator
accelerator(accelerators
[i
].keycode
,
855 accelerators
[i
].modifiers
);
856 accelerator
.set_type(accelerators
[i
].trigger_on_press
?
857 ui::ET_KEY_PRESSED
: ui::ET_KEY_RELEASED
);
858 Register(accelerator
, this);
859 accelerators_
.insert(
860 std::make_pair(accelerator
, accelerators
[i
].action
));
864 bool AcceleratorController::CanPerformAction(
865 AcceleratorAction action
,
866 const ui::Accelerator
& accelerator
) {
867 if (nonrepeatable_actions_
.find(action
) != nonrepeatable_actions_
.end() &&
868 accelerator
.IsRepeat()) {
872 AcceleratorProcessingRestriction restriction
=
873 GetAcceleratorProcessingRestriction(action
);
874 if (restriction
!= RESTRICTION_NONE
)
875 return restriction
== RESTRICTION_PREVENT_PROCESSING_AND_PROPAGATION
;
877 const ui::Accelerator
& previous_accelerator
=
878 accelerator_history_
->previous_accelerator();
880 // True should be returned if running |action| does something. Otherwise,
881 // false should be returned to give the web contents a chance at handling the
884 case ACCESSIBLE_FOCUS_NEXT
:
885 case ACCESSIBLE_FOCUS_PREVIOUS
:
886 return CanHandleAccessibleFocusCycle();
887 case DEBUG_PRINT_LAYER_HIERARCHY
:
888 case DEBUG_PRINT_VIEW_HIERARCHY
:
889 case DEBUG_PRINT_WINDOW_HIERARCHY
:
890 case DEBUG_TOGGLE_DESKTOP_BACKGROUND_MODE
:
891 case DEBUG_TOGGLE_DEVICE_SCALE_FACTOR
:
892 case DEBUG_TOGGLE_ROOT_WINDOW_FULL_SCREEN
:
893 case DEBUG_TOGGLE_SHOW_DEBUG_BORDERS
:
894 case DEBUG_TOGGLE_SHOW_FPS_COUNTER
:
895 case DEBUG_TOGGLE_SHOW_PAINT_RECTS
:
896 return debug::DebugAcceleratorsEnabled();
897 case MAGNIFY_SCREEN_ZOOM_IN
:
898 case MAGNIFY_SCREEN_ZOOM_OUT
:
899 return CanHandleMagnifyScreen();
900 case NEW_INCOGNITO_WINDOW
:
901 return CanHandleNewIncognitoWindow();
903 return CanHandleNextIme(ime_control_delegate_
.get(),
904 previous_accelerator
);
906 return CanHandlePreviousIme(ime_control_delegate_
.get());
908 return CanHandleScaleReset();
911 return CanHandleScaleUI();
912 case SHOW_MESSAGE_CENTER_BUBBLE
:
913 return CanHandleShowMessageCenterBubble();
915 return CanHandleSwitchIme(ime_control_delegate_
.get(), accelerator
);
916 case TOGGLE_APP_LIST
:
917 return CanHandleToggleAppList(accelerator
, previous_accelerator
);
918 case WINDOW_CYCLE_SNAP_DOCK_LEFT
:
919 case WINDOW_CYCLE_SNAP_DOCK_RIGHT
:
920 return CanHandleWindowSnapOrDock();
921 case WINDOW_POSITION_CENTER
:
922 return CanHandlePositionCenter();
923 #if defined(OS_CHROMEOS)
924 case DEBUG_ADD_REMOVE_DISPLAY
:
925 return debug::DebugAcceleratorsEnabled();
926 case DISABLE_CAPS_LOCK
:
927 return CanHandleDisableCapsLock(previous_accelerator
);
928 case SILENCE_SPOKEN_FEEDBACK
:
929 return CanHandleSilenceSpokenFeedback();
930 case SWITCH_TO_PREVIOUS_USER
:
931 case SWITCH_TO_NEXT_USER
:
932 return CanHandleCycleUser();
933 case TOGGLE_CAPS_LOCK
:
934 return CanHandleToggleCapsLock(accelerator
, previous_accelerator
);
935 case TOGGLE_TOUCH_VIEW_TESTING
:
936 return CanHandleToggleTouchViewTesting();
937 case TOUCH_HUD_CLEAR
:
938 case TOUCH_HUD_MODE_CHANGE
:
939 return CanHandleTouchHud();
942 case CYCLE_BACKWARD_MRU
:
943 case CYCLE_FORWARD_MRU
:
945 case FOCUS_NEXT_PANE
:
946 case FOCUS_PREVIOUS_PANE
:
956 case LAUNCH_LAST_APP
:
957 case MEDIA_NEXT_TRACK
:
958 case MEDIA_PLAY_PAUSE
:
959 case MEDIA_PREV_TRACK
:
962 case OPEN_FEEDBACK_PAGE
:
963 case PRINT_UI_HIERARCHIES
:
967 case SHOW_KEYBOARD_OVERLAY
:
968 case SHOW_SYSTEM_TRAY_BUBBLE
:
969 case SHOW_TASK_MANAGER
:
970 case TAKE_PARTIAL_SCREENSHOT
:
971 case TAKE_SCREENSHOT
:
972 case TOGGLE_FULLSCREEN
:
973 case TOGGLE_MAXIMIZED
:
974 case TOGGLE_OVERVIEW
:
975 case WINDOW_MINIMIZE
:
976 #if defined(OS_CHROMEOS)
977 case BRIGHTNESS_DOWN
:
979 case DISABLE_GPU_WATCHDOG
:
980 case KEYBOARD_BRIGHTNESS_DOWN
:
981 case KEYBOARD_BRIGHTNESS_UP
:
986 case OPEN_FILE_MANAGER
:
990 case SWAP_PRIMARY_DISPLAY
:
991 case TOGGLE_MIRROR_MODE
:
992 case TOGGLE_SPOKEN_FEEDBACK
:
994 case TOUCH_HUD_PROJECTION_TOGGLE
:
999 case DUMMY_FOR_RESERVED
:
1006 void AcceleratorController::PerformAction(AcceleratorAction action
,
1007 const ui::Accelerator
& accelerator
) {
1008 AcceleratorProcessingRestriction restriction
=
1009 GetAcceleratorProcessingRestriction(action
);
1010 if (restriction
!= RESTRICTION_NONE
)
1013 // If your accelerator invokes more than one line of code, please either
1014 // implement it in your module's controller code (like TOGGLE_MIRROR_MODE
1015 // below) or pull it into a HandleFoo() function above.
1017 case ACCESSIBLE_FOCUS_NEXT
:
1018 HandleAccessibleFocusCycle(false);
1020 case ACCESSIBLE_FOCUS_PREVIOUS
:
1021 HandleAccessibleFocusCycle(true);
1023 case CYCLE_BACKWARD_MRU
:
1024 HandleCycleBackwardMRU(accelerator
);
1026 case CYCLE_FORWARD_MRU
:
1027 HandleCycleForwardMRU(accelerator
);
1029 case DEBUG_PRINT_LAYER_HIERARCHY
:
1030 case DEBUG_PRINT_VIEW_HIERARCHY
:
1031 case DEBUG_PRINT_WINDOW_HIERARCHY
:
1032 case DEBUG_TOGGLE_DESKTOP_BACKGROUND_MODE
:
1033 case DEBUG_TOGGLE_DEVICE_SCALE_FACTOR
:
1034 case DEBUG_TOGGLE_ROOT_WINDOW_FULL_SCREEN
:
1035 case DEBUG_TOGGLE_SHOW_DEBUG_BORDERS
:
1036 case DEBUG_TOGGLE_SHOW_FPS_COUNTER
:
1037 case DEBUG_TOGGLE_SHOW_PAINT_RECTS
:
1038 debug::PerformDebugActionIfEnabled(action
);
1041 // UMA metrics are recorded in the handler.
1042 exit_warning_handler_
.HandleAccelerator();
1044 case FOCUS_NEXT_PANE
:
1045 HandleRotatePaneFocus(Shell::FORWARD
);
1047 case FOCUS_PREVIOUS_PANE
:
1048 HandleRotatePaneFocus(Shell::BACKWARD
);
1054 HandleLaunchAppN(0);
1057 HandleLaunchAppN(1);
1060 HandleLaunchAppN(2);
1063 HandleLaunchAppN(3);
1066 HandleLaunchAppN(4);
1069 HandleLaunchAppN(5);
1072 HandleLaunchAppN(6);
1075 HandleLaunchAppN(7);
1077 case LAUNCH_LAST_APP
:
1078 HandleLaunchLastApp();
1080 case MAGNIFY_SCREEN_ZOOM_IN
:
1081 HandleMagnifyScreen(1);
1083 case MAGNIFY_SCREEN_ZOOM_OUT
:
1084 HandleMagnifyScreen(-1);
1086 case MEDIA_NEXT_TRACK
:
1087 HandleMediaNextTrack();
1089 case MEDIA_PLAY_PAUSE
:
1090 HandleMediaPlayPause();
1092 case MEDIA_PREV_TRACK
:
1093 HandleMediaPrevTrack();
1095 case NEW_INCOGNITO_WINDOW
:
1096 HandleNewIncognitoWindow();
1099 HandleNewTab(accelerator
);
1105 HandleNextIme(ime_control_delegate_
.get());
1107 case OPEN_FEEDBACK_PAGE
:
1108 HandleOpenFeedbackPage();
1111 HandlePreviousIme(ime_control_delegate_
.get(), accelerator
);
1113 case PRINT_UI_HIERARCHIES
:
1114 debug::PrintUIHierarchies();
1120 HandleRotateScreen();
1123 HandleRotateActiveWindow();
1126 HandleScaleUI(false /* down */);
1128 case SCALE_UI_RESET
:
1132 HandleScaleUI(true /* up */);
1134 case SHOW_KEYBOARD_OVERLAY
:
1135 HandleShowKeyboardOverlay();
1137 case SHOW_MESSAGE_CENTER_BUBBLE
:
1138 HandleShowMessageCenterBubble();
1140 case SHOW_SYSTEM_TRAY_BUBBLE
:
1141 HandleShowSystemTrayBubble();
1143 case SHOW_TASK_MANAGER
:
1144 HandleShowTaskManager();
1147 HandleSwitchIme(ime_control_delegate_
.get(), accelerator
);
1149 case TAKE_PARTIAL_SCREENSHOT
:
1150 HandleTakePartialScreenshot(screenshot_delegate_
.get());
1152 case TAKE_SCREENSHOT
:
1153 HandleTakeScreenshot(screenshot_delegate_
.get());
1155 case TOGGLE_APP_LIST
:
1156 HandleToggleAppList(accelerator
);
1158 case TOGGLE_FULLSCREEN
:
1159 HandleToggleFullscreen(accelerator
);
1161 case TOGGLE_MAXIMIZED
:
1162 accelerators::ToggleMaximized();
1164 case TOGGLE_OVERVIEW
:
1165 HandleToggleOverview();
1167 case WINDOW_CYCLE_SNAP_DOCK_LEFT
:
1168 case WINDOW_CYCLE_SNAP_DOCK_RIGHT
:
1169 HandleWindowSnapOrDock(action
);
1171 case WINDOW_MINIMIZE
:
1172 HandleWindowMinimize();
1174 case WINDOW_POSITION_CENTER
:
1175 HandlePositionCenter();
1177 #if defined(OS_CHROMEOS)
1178 case BRIGHTNESS_DOWN
:
1179 HandleBrightnessDown(brightness_control_delegate_
.get(), accelerator
);
1182 HandleBrightnessUp(brightness_control_delegate_
.get(), accelerator
);
1184 case DEBUG_ADD_REMOVE_DISPLAY
:
1185 debug::PerformDebugActionIfEnabled(action
);
1187 case DISABLE_CAPS_LOCK
:
1188 HandleDisableCapsLock();
1190 case DISABLE_GPU_WATCHDOG
:
1191 Shell::GetInstance()->gpu_support()->DisableGpuWatchdog();
1193 case KEYBOARD_BRIGHTNESS_DOWN
:
1194 HandleKeyboardBrightnessDown(keyboard_brightness_control_delegate_
.get(),
1197 case KEYBOARD_BRIGHTNESS_UP
:
1198 HandleKeyboardBrightnessUp(keyboard_brightness_control_delegate_
.get(),
1203 Shell::GetInstance()->power_button_controller()->
1204 OnLockButtonEvent(action
== LOCK_PRESSED
, base::TimeTicks());
1212 case OPEN_FILE_MANAGER
:
1213 HandleFileManager();
1218 case POWER_PRESSED
: // fallthrough
1219 case POWER_RELEASED
:
1220 if (!base::SysInfo::IsRunningOnChromeOS()) {
1221 // There is no powerd, the Chrome OS power manager, in linux desktop,
1222 // so call the PowerButtonController here.
1223 Shell::GetInstance()->power_button_controller()->
1224 OnPowerButtonEvent(action
== POWER_PRESSED
, base::TimeTicks());
1226 // We don't do anything with these at present on the device,
1227 // (power button events are reported to us from powerm via
1228 // D-BUS), but we consume them to prevent them from getting
1229 // passed to apps -- see http://crbug.com/146609.
1231 case SILENCE_SPOKEN_FEEDBACK
:
1232 HandleSilenceSpokenFeedback();
1234 case SWAP_PRIMARY_DISPLAY
:
1235 HandleSwapPrimaryDisplay();
1237 case SWITCH_TO_NEXT_USER
:
1238 HandleCycleUser(SessionStateDelegate::CYCLE_TO_NEXT_USER
);
1240 case SWITCH_TO_PREVIOUS_USER
:
1241 HandleCycleUser(SessionStateDelegate::CYCLE_TO_PREVIOUS_USER
);
1243 case TOGGLE_CAPS_LOCK
:
1244 HandleToggleCapsLock();
1246 case TOGGLE_MIRROR_MODE
:
1247 HandleToggleMirrorMode();
1249 case TOGGLE_SPOKEN_FEEDBACK
:
1250 HandleToggleSpokenFeedback();
1252 case TOGGLE_TOUCH_VIEW_TESTING
:
1253 HandleToggleTouchViewTesting();
1256 Shell::GetInstance()->system_tray_notifier()->NotifyRequestToggleWifi();
1258 case TOUCH_HUD_CLEAR
:
1259 HandleTouchHudClear();
1261 case TOUCH_HUD_MODE_CHANGE
:
1262 HandleTouchHudModeChange();
1264 case TOUCH_HUD_PROJECTION_TOGGLE
:
1265 accelerators::ToggleTouchHudProjection();
1268 HandleVolumeDown(accelerator
);
1271 HandleVolumeMute(accelerator
);
1274 HandleVolumeUp(accelerator
);
1277 case DUMMY_FOR_RESERVED
:
1284 bool AcceleratorController::ShouldActionConsumeKeyEvent(
1285 AcceleratorAction action
) {
1286 #if defined(OS_CHROMEOS)
1287 if (action
== SILENCE_SPOKEN_FEEDBACK
)
1291 // Adding new exceptions is *STRONGLY* discouraged.
1295 AcceleratorController::AcceleratorProcessingRestriction
1296 AcceleratorController::GetAcceleratorProcessingRestriction(int action
) {
1297 ash::Shell
* shell
= ash::Shell::GetInstance();
1298 if (!shell
->session_state_delegate()->IsActiveUserSessionStarted() &&
1299 actions_allowed_at_login_screen_
.find(action
) ==
1300 actions_allowed_at_login_screen_
.end()) {
1301 return RESTRICTION_PREVENT_PROCESSING
;
1303 if (shell
->session_state_delegate()->IsScreenLocked() &&
1304 actions_allowed_at_lock_screen_
.find(action
) ==
1305 actions_allowed_at_lock_screen_
.end()) {
1306 return RESTRICTION_PREVENT_PROCESSING
;
1308 if (shell
->delegate()->IsRunningInForcedAppMode() &&
1309 actions_allowed_in_app_mode_
.find(action
) ==
1310 actions_allowed_in_app_mode_
.end()) {
1311 return RESTRICTION_PREVENT_PROCESSING
;
1313 if (shell
->IsSystemModalWindowOpen() &&
1314 actions_allowed_at_modal_window_
.find(action
) ==
1315 actions_allowed_at_modal_window_
.end()) {
1316 // Note we prevent the shortcut from propagating so it will not
1317 // be passed to the modal window. This is important for things like
1318 // Alt+Tab that would cause an undesired effect in the modal window by
1319 // cycling through its window elements.
1320 return RESTRICTION_PREVENT_PROCESSING_AND_PROPAGATION
;
1322 if (shell
->mru_window_tracker()->BuildMruWindowList().empty() &&
1323 actions_needing_window_
.find(action
) != actions_needing_window_
.end()) {
1324 Shell::GetInstance()->accessibility_delegate()->TriggerAccessibilityAlert(
1325 ui::A11Y_ALERT_WINDOW_NEEDED
);
1326 return RESTRICTION_PREVENT_PROCESSING_AND_PROPAGATION
;
1328 return RESTRICTION_NONE
;
1331 void AcceleratorController::SetKeyboardBrightnessControlDelegate(
1332 scoped_ptr
<KeyboardBrightnessControlDelegate
>
1333 keyboard_brightness_control_delegate
) {
1334 keyboard_brightness_control_delegate_
=
1335 keyboard_brightness_control_delegate
.Pass();