Fix data races on |SharedMemoryDataConsumerHandle::Context::notification_task_runner_|
[chromium-blink-merge.git] / ash / accelerators / accelerator_controller.cc
blob8f1d9477b775d5e515cc4969996b7b603e89d145
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"
7 #include <algorithm>
8 #include <cmath>
9 #include <string>
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)
77 namespace ash {
78 namespace {
80 using base::UserMetricsAction;
82 void HandleCycleBackwardMRU(const ui::Accelerator& accelerator) {
83 if (accelerator.key_code() == ui::VKEY_TAB)
84 base::RecordAction(base::UserMetricsAction("Accel_PrevWindow_Tab"));
86 Shell::GetInstance()->window_cycle_controller()->HandleCycleWindow(
87 WindowCycleController::BACKWARD);
90 void HandleCycleForwardMRU(const ui::Accelerator& accelerator) {
91 if (accelerator.key_code() == ui::VKEY_TAB)
92 base::RecordAction(base::UserMetricsAction("Accel_NextWindow_Tab"));
94 Shell::GetInstance()->window_cycle_controller()->HandleCycleWindow(
95 WindowCycleController::FORWARD);
98 void HandleRotatePaneFocus(Shell::Direction direction) {
99 Shell* shell = Shell::GetInstance();
100 switch (direction) {
101 // TODO(stevet): Not sure if this is the same as IDC_FOCUS_NEXT_PANE.
102 case Shell::FORWARD: {
103 base::RecordAction(UserMetricsAction("Accel_Focus_Next_Pane"));
104 shell->focus_cycler()->RotateFocus(FocusCycler::FORWARD);
105 break;
107 case Shell::BACKWARD: {
108 base::RecordAction(UserMetricsAction("Accel_Focus_Previous_Pane"));
109 shell->focus_cycler()->RotateFocus(FocusCycler::BACKWARD);
110 break;
115 void HandleFocusShelf() {
116 Shell* shell = Shell::GetInstance();
117 base::RecordAction(base::UserMetricsAction("Accel_Focus_Shelf"));
118 shell->focus_cycler()->FocusWidget(
119 Shelf::ForPrimaryDisplay()->shelf_widget());
122 void HandleLaunchAppN(int n) {
123 base::RecordAction(UserMetricsAction("Accel_Launch_App"));
124 Shelf::ForPrimaryDisplay()->LaunchAppIndexAt(n);
127 void HandleLaunchLastApp() {
128 base::RecordAction(UserMetricsAction("Accel_Launch_Last_App"));
129 Shelf::ForPrimaryDisplay()->LaunchAppIndexAt(-1);
132 bool CanHandleMagnifyScreen() {
133 Shell* shell = Shell::GetInstance();
134 return shell->magnification_controller()->IsEnabled() ||
135 shell->partial_magnification_controller()->is_enabled();
138 // Magnify the screen
139 void HandleMagnifyScreen(int delta_index) {
140 if (ash::Shell::GetInstance()->magnification_controller()->IsEnabled()) {
141 // TODO(yoshiki): Move the following logic to MagnificationController.
142 float scale =
143 ash::Shell::GetInstance()->magnification_controller()->GetScale();
144 // Calculate rounded logarithm (base kMagnificationScaleFactor) of scale.
145 int scale_index = std::floor(
146 std::log(scale) / std::log(ui::kMagnificationScaleFactor) + 0.5);
148 int new_scale_index = std::max(0, std::min(8, scale_index + delta_index));
150 ash::Shell::GetInstance()->magnification_controller()->SetScale(
151 std::pow(ui::kMagnificationScaleFactor, new_scale_index), true);
152 } else if (ash::Shell::GetInstance()->
153 partial_magnification_controller()->is_enabled()) {
154 float scale = delta_index > 0 ? kDefaultPartialMagnifiedScale : 1;
155 ash::Shell::GetInstance()->partial_magnification_controller()->
156 SetScale(scale);
160 void HandleMediaNextTrack() {
161 Shell::GetInstance()->media_delegate()->HandleMediaNextTrack();
164 void HandleMediaPlayPause() {
165 Shell::GetInstance()->media_delegate()->HandleMediaPlayPause();
168 void HandleMediaPrevTrack() {
169 Shell::GetInstance()->media_delegate()->HandleMediaPrevTrack();
172 bool CanHandleNewIncognitoWindow() {
173 return Shell::GetInstance()->delegate()->IsIncognitoAllowed();
176 void HandleNewIncognitoWindow() {
177 base::RecordAction(UserMetricsAction("Accel_New_Incognito_Window"));
178 Shell::GetInstance()->new_window_delegate()->NewWindow(
179 true /* is_incognito */);
182 void HandleNewTab(const ui::Accelerator& accelerator) {
183 if (accelerator.key_code() == ui::VKEY_T)
184 base::RecordAction(base::UserMetricsAction("Accel_NewTab_T"));
185 Shell::GetInstance()->new_window_delegate()->NewTab();
188 void HandleNewWindow() {
189 base::RecordAction(base::UserMetricsAction("Accel_New_Window"));
190 Shell::GetInstance()->new_window_delegate()->NewWindow(
191 false /* is_incognito */);
194 bool CanHandleNextIme(ImeControlDelegate* ime_control_delegate,
195 const ui::Accelerator& previous_accelerator) {
196 // This check is necessary e.g. not to process the Shift+Alt+
197 // ET_KEY_RELEASED accelerator for Chrome OS (see ash/accelerators/
198 // accelerator_controller.cc) when Shift+Alt+Tab is pressed and then Tab
199 // is released.
200 ui::KeyboardCode previous_key_code = previous_accelerator.key_code();
201 if (previous_accelerator.type() == ui::ET_KEY_RELEASED &&
202 // Workaround for crbug.com/139556. CJK IME users tend to press
203 // Enter (or Space) and Shift+Alt almost at the same time to commit
204 // an IME string and then switch from the IME to the English layout.
205 // This workaround allows the user to trigger NEXT_IME even if the
206 // user presses Shift+Alt before releasing Enter.
207 // TODO(nona|mazda): Fix crbug.com/139556 in a cleaner way.
208 previous_key_code != ui::VKEY_RETURN &&
209 previous_key_code != ui::VKEY_SPACE) {
210 // We totally ignore this accelerator.
211 // TODO(mazda): Fix crbug.com/158217
212 return false;
214 return ime_control_delegate && ime_control_delegate->CanCycleIme();
217 void HandleNextIme(ImeControlDelegate* ime_control_delegate) {
218 base::RecordAction(UserMetricsAction("Accel_Next_Ime"));
219 ime_control_delegate->HandleNextIme();
222 void HandleOpenFeedbackPage() {
223 base::RecordAction(UserMetricsAction("Accel_Open_Feedback_Page"));
224 ash::Shell::GetInstance()->new_window_delegate()->OpenFeedbackPage();
227 bool CanHandlePreviousIme(ImeControlDelegate* ime_control_delegate) {
228 return ime_control_delegate && ime_control_delegate->CanCycleIme();
231 void HandlePreviousIme(ImeControlDelegate* ime_control_delegate,
232 const ui::Accelerator& accelerator) {
233 base::RecordAction(UserMetricsAction("Accel_Previous_Ime"));
234 if (accelerator.type() == ui::ET_KEY_PRESSED)
235 ime_control_delegate->HandlePreviousIme();
236 // Else: consume the Ctrl+Space ET_KEY_RELEASED event but do not do anything.
239 void HandleRestoreTab() {
240 base::RecordAction(base::UserMetricsAction("Accel_Restore_Tab"));
241 Shell::GetInstance()->new_window_delegate()->RestoreTab();
244 gfx::Display::Rotation GetNextRotation(gfx::Display::Rotation current) {
245 switch (current) {
246 case gfx::Display::ROTATE_0:
247 return gfx::Display::ROTATE_90;
248 case gfx::Display::ROTATE_90:
249 return gfx::Display::ROTATE_180;
250 case gfx::Display::ROTATE_180:
251 return gfx::Display::ROTATE_270;
252 case gfx::Display::ROTATE_270:
253 return gfx::Display::ROTATE_0;
255 NOTREACHED() << "Unknown rotation:" << current;
256 return gfx::Display::ROTATE_0;
259 // Rotates the screen.
260 void HandleRotateScreen() {
261 base::RecordAction(UserMetricsAction("Accel_Rotate_Window"));
262 gfx::Point point = Shell::GetScreen()->GetCursorScreenPoint();
263 gfx::Display display = Shell::GetScreen()->GetDisplayNearestPoint(point);
264 const DisplayInfo& display_info =
265 Shell::GetInstance()->display_manager()->GetDisplayInfo(display.id());
266 ash::ScreenRotationAnimator(display.id())
267 .Rotate(GetNextRotation(display_info.GetActiveRotation()),
268 gfx::Display::ROTATION_SOURCE_USER);
271 // Rotate the active window.
272 void HandleRotateActiveWindow() {
273 base::RecordAction(UserMetricsAction("Accel_Rotate_Window"));
274 aura::Window* active_window = wm::GetActiveWindow();
275 if (active_window) {
276 // The rotation animation bases its target transform on the current
277 // rotation and position. Since there could be an animation in progress
278 // right now, queue this animation so when it starts it picks up a neutral
279 // rotation and position. Use replace so we only enqueue one at a time.
280 active_window->layer()->GetAnimator()->
281 set_preemption_strategy(ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS);
282 active_window->layer()->GetAnimator()->StartAnimation(
283 new ui::LayerAnimationSequence(
284 new ash::WindowRotation(360, active_window->layer())));
288 bool CanHandleScaleReset() {
289 DisplayManager* display_manager = Shell::GetInstance()->display_manager();
290 int64 display_id = display_manager->GetDisplayIdForUIScaling();
291 return (display_id != gfx::Display::kInvalidDisplayID &&
292 display_manager->GetDisplayInfo(display_id).configured_ui_scale() !=
293 1.0f);
296 void HandleScaleReset() {
297 base::RecordAction(UserMetricsAction("Accel_Scale_Ui_Reset"));
298 DisplayManager* display_manager = Shell::GetInstance()->display_manager();
299 int64 display_id = display_manager->GetDisplayIdForUIScaling();
300 display_manager->SetDisplayUIScale(display_id, 1.0f);
303 bool CanHandleScaleUI() {
304 DisplayManager* display_manager = Shell::GetInstance()->display_manager();
305 int64 display_id = display_manager->GetDisplayIdForUIScaling();
306 return display_id != gfx::Display::kInvalidDisplayID;
309 void HandleScaleUI(bool up) {
310 DisplayManager* display_manager = Shell::GetInstance()->display_manager();
311 int64 display_id = display_manager->GetDisplayIdForUIScaling();
313 if (up) {
314 base::RecordAction(UserMetricsAction("Accel_Scale_Ui_Up"));
315 } else {
316 base::RecordAction(UserMetricsAction("Accel_Scale_Ui_Down"));
319 const DisplayInfo& display_info = display_manager->GetDisplayInfo(display_id);
320 float next_scale = GetNextUIScale(display_info, up);
321 display_manager->SetDisplayUIScale(display_id, next_scale);
324 void HandleShowKeyboardOverlay() {
325 base::RecordAction(UserMetricsAction("Accel_Show_Keyboard_Overlay"));
326 ash::Shell::GetInstance()->new_window_delegate()->ShowKeyboardOverlay();
329 bool CanHandleShowMessageCenterBubble() {
330 RootWindowController* controller =
331 RootWindowController::ForTargetRootWindow();
332 StatusAreaWidget* status_area_widget =
333 controller->shelf()->status_area_widget();
334 return status_area_widget &&
335 status_area_widget->web_notification_tray()->visible();
338 void HandleShowMessageCenterBubble() {
339 base::RecordAction(UserMetricsAction("Accel_Show_Message_Center_Bubble"));
340 RootWindowController* controller =
341 RootWindowController::ForTargetRootWindow();
342 StatusAreaWidget* status_area_widget =
343 controller->shelf()->status_area_widget();
344 if (status_area_widget) {
345 WebNotificationTray* notification_tray =
346 status_area_widget->web_notification_tray();
347 if (notification_tray->visible())
348 notification_tray->ShowMessageCenterBubble();
352 void HandleShowSystemTrayBubble() {
353 base::RecordAction(UserMetricsAction("Accel_Show_System_Tray_Bubble"));
354 RootWindowController* controller =
355 RootWindowController::ForTargetRootWindow();
356 if (!controller->GetSystemTray()->HasSystemBubble())
357 controller->GetSystemTray()->ShowDefaultView(BUBBLE_CREATE_NEW);
360 void HandleShowTaskManager() {
361 base::RecordAction(UserMetricsAction("Accel_Show_Task_Manager"));
362 Shell::GetInstance()->new_window_delegate()->ShowTaskManager();
365 bool CanHandleSwitchIme(ImeControlDelegate* ime_control_delegate,
366 const ui::Accelerator& accelerator) {
367 return ime_control_delegate &&
368 ime_control_delegate->CanSwitchIme(accelerator);
371 void HandleSwitchIme(ImeControlDelegate* ime_control_delegate,
372 const ui::Accelerator& accelerator) {
373 base::RecordAction(UserMetricsAction("Accel_Switch_Ime"));
374 ime_control_delegate->HandleSwitchIme(accelerator);
377 void HandleTakePartialScreenshot(ScreenshotDelegate* screenshot_delegate) {
378 base::RecordAction(UserMetricsAction("Accel_Take_Partial_Screenshot"));
379 DCHECK(screenshot_delegate);
380 Shell::GetInstance()
381 ->partial_screenshot_controller()
382 ->StartPartialScreenshotSession(screenshot_delegate);
385 void HandleTakeScreenshot(ScreenshotDelegate* screenshot_delegate) {
386 base::RecordAction(UserMetricsAction("Accel_Take_Screenshot"));
387 DCHECK(screenshot_delegate);
388 if (screenshot_delegate->CanTakeScreenshot())
389 screenshot_delegate->HandleTakeScreenshotForAllRootWindows();
392 bool CanHandleToggleAppList(const ui::Accelerator& accelerator,
393 const ui::Accelerator& previous_accelerator) {
394 if (accelerator.key_code() == ui::VKEY_LWIN) {
395 // If something else was pressed between the Search key (LWIN)
396 // being pressed and released, then ignore the release of the
397 // Search key.
398 if (previous_accelerator.type() != ui::ET_KEY_PRESSED ||
399 previous_accelerator.key_code() != ui::VKEY_LWIN) {
400 return false;
403 // When spoken feedback is enabled, we should neither toggle the list nor
404 // consume the key since Search+Shift is one of the shortcuts the a11y
405 // feature uses. crbug.com/132296
406 if (Shell::GetInstance()
407 ->accessibility_delegate()
408 ->IsSpokenFeedbackEnabled()) {
409 return false;
412 return true;
415 void HandleToggleAppList(const ui::Accelerator& accelerator) {
416 if (accelerator.key_code() == ui::VKEY_LWIN)
417 base::RecordAction(base::UserMetricsAction("Accel_Search_LWin"));
418 ash::Shell::GetInstance()->ToggleAppList(NULL);
421 void HandleToggleFullscreen(const ui::Accelerator& accelerator) {
422 if (accelerator.key_code() == ui::VKEY_MEDIA_LAUNCH_APP2)
423 base::RecordAction(UserMetricsAction("Accel_Fullscreen_F4"));
424 accelerators::ToggleFullscreen();
427 void HandleToggleOverview() {
428 base::RecordAction(base::UserMetricsAction("Accel_Overview_F5"));
429 Shell::GetInstance()->window_selector_controller()->ToggleOverview();
432 bool CanHandleWindowSnapOrDock() {
433 wm::WindowState* window_state = wm::GetActiveWindowState();
434 // Disable window snapping shortcut key for full screen window due to
435 // http://crbug.com/135487.
436 return (window_state && window_state->IsUserPositionable() &&
437 !window_state->IsFullscreen());
440 void HandleWindowSnapOrDock(AcceleratorAction action) {
441 if (action == WINDOW_CYCLE_SNAP_DOCK_LEFT)
442 base::RecordAction(UserMetricsAction("Accel_Window_Snap_Left"));
443 else
444 base::RecordAction(UserMetricsAction("Accel_Window_Snap_Right"));
446 const wm::WMEvent event(action == WINDOW_CYCLE_SNAP_DOCK_LEFT ?
447 wm::WM_EVENT_CYCLE_SNAP_DOCK_LEFT :
448 wm::WM_EVENT_CYCLE_SNAP_DOCK_RIGHT);
449 wm::GetActiveWindowState()->OnWMEvent(&event);
452 void HandleWindowMinimize() {
453 base::RecordAction(
454 base::UserMetricsAction("Accel_Toggle_Minimized_Minus"));
455 accelerators::ToggleMinimized();
458 bool CanHandlePositionCenter() {
459 // Docked windows do not support centering.
460 wm::WindowState* window_state = wm::GetActiveWindowState();
461 return (window_state && !window_state->IsDocked());
464 void HandlePositionCenter() {
465 base::RecordAction(UserMetricsAction("Accel_Window_Position_Center"));
466 wm::CenterWindow(wm::GetActiveWindow());
469 #if defined(OS_CHROMEOS)
470 void HandleBrightnessDown(BrightnessControlDelegate* delegate,
471 const ui::Accelerator& accelerator) {
472 if (delegate)
473 delegate->HandleBrightnessDown(accelerator);
476 void HandleBrightnessUp(BrightnessControlDelegate* delegate,
477 const ui::Accelerator& accelerator) {
478 if (delegate)
479 delegate->HandleBrightnessUp(accelerator);
482 bool CanHandleDisableCapsLock(const ui::Accelerator& previous_accelerator) {
483 ui::KeyboardCode previous_key_code = previous_accelerator.key_code();
484 if (previous_accelerator.type() == ui::ET_KEY_RELEASED ||
485 (previous_key_code != ui::VKEY_LSHIFT &&
486 previous_key_code != ui::VKEY_SHIFT &&
487 previous_key_code != ui::VKEY_RSHIFT)) {
488 // If something else was pressed between the Shift key being pressed
489 // and released, then ignore the release of the Shift key.
490 return false;
492 chromeos::input_method::InputMethodManager* ime =
493 chromeos::input_method::InputMethodManager::Get();
494 chromeos::input_method::ImeKeyboard* keyboard =
495 ime ? ime->GetImeKeyboard() : NULL;
496 return (keyboard && keyboard->CapsLockIsEnabled());
499 void HandleDisableCapsLock() {
500 base::RecordAction(UserMetricsAction("Accel_Disable_Caps_Lock"));
501 chromeos::input_method::InputMethodManager* ime =
502 chromeos::input_method::InputMethodManager::Get();
503 ime->GetImeKeyboard()->SetCapsLockEnabled(false);
506 void HandleKeyboardBrightnessDown(KeyboardBrightnessControlDelegate* delegate,
507 const ui::Accelerator& accelerator) {
508 if (delegate)
509 delegate->HandleKeyboardBrightnessDown(accelerator);
512 void HandleKeyboardBrightnessUp(KeyboardBrightnessControlDelegate* delegate,
513 const ui::Accelerator& accelerator) {
514 if (delegate)
515 delegate->HandleKeyboardBrightnessUp(accelerator);
518 void HandleLock() {
519 base::RecordAction(UserMetricsAction("Accel_LockScreen_L"));
520 Shell::GetInstance()->session_state_delegate()->LockScreen();
523 void HandleCrosh() {
524 base::RecordAction(UserMetricsAction("Accel_Open_Crosh"));
526 Shell::GetInstance()->new_window_delegate()->OpenCrosh();
529 void HandleFileManager() {
530 base::RecordAction(UserMetricsAction("Accel_Open_File_Manager"));
532 Shell::GetInstance()->new_window_delegate()->OpenFileManager();
535 void HandleGetHelp() {
536 Shell::GetInstance()->new_window_delegate()->OpenGetHelp();
539 bool CanHandleSilenceSpokenFeedback() {
540 AccessibilityDelegate* delegate =
541 Shell::GetInstance()->accessibility_delegate();
542 return delegate->IsSpokenFeedbackEnabled();
545 void HandleSilenceSpokenFeedback() {
546 base::RecordAction(UserMetricsAction("Accel_Silence_Spoken_Feedback"));
547 Shell::GetInstance()->accessibility_delegate()->SilenceSpokenFeedback();
550 void HandleSwapPrimaryDisplay() {
551 base::RecordAction(UserMetricsAction("Accel_Swap_Primary_Display"));
552 Shell::GetInstance()->display_controller()->SwapPrimaryDisplay();
555 bool CanHandleCycleUser() {
556 Shell* shell = Shell::GetInstance();
557 return shell->delegate()->IsMultiProfilesEnabled() &&
558 shell->session_state_delegate()->NumberOfLoggedInUsers() > 1;
561 void HandleCycleUser(SessionStateDelegate::CycleUser cycle_user) {
562 MultiProfileUMA::RecordSwitchActiveUser(
563 MultiProfileUMA::SWITCH_ACTIVE_USER_BY_ACCELERATOR);
564 switch (cycle_user) {
565 case SessionStateDelegate::CYCLE_TO_NEXT_USER:
566 base::RecordAction(UserMetricsAction("Accel_Switch_To_Next_User"));
567 break;
568 case SessionStateDelegate::CYCLE_TO_PREVIOUS_USER:
569 base::RecordAction(UserMetricsAction("Accel_Switch_To_Previous_User"));
570 break;
572 Shell::GetInstance()->session_state_delegate()->CycleActiveUser(cycle_user);
575 bool CanHandleToggleCapsLock(const ui::Accelerator& accelerator,
576 const ui::Accelerator& previous_accelerator) {
577 if (accelerator.key_code() == ui::VKEY_LWIN) {
578 // If something else was pressed between the Search key (LWIN)
579 // being pressed and released, then ignore the release of the
580 // Search key.
581 // TODO(danakj): Releasing Alt first breaks this: crbug.com/166495
582 if (previous_accelerator.type() == ui::ET_KEY_RELEASED ||
583 previous_accelerator.key_code() != ui::VKEY_LWIN)
584 return false;
586 chromeos::input_method::InputMethodManager* ime =
587 chromeos::input_method::InputMethodManager::Get();
588 return ime && ime->GetImeKeyboard();
591 void HandleToggleCapsLock() {
592 base::RecordAction(UserMetricsAction("Accel_Toggle_Caps_Lock"));
593 chromeos::input_method::InputMethodManager* ime =
594 chromeos::input_method::InputMethodManager::Get();
595 chromeos::input_method::ImeKeyboard* keyboard = ime->GetImeKeyboard();
596 keyboard->SetCapsLockEnabled(!keyboard->CapsLockIsEnabled());
599 void HandleToggleMirrorMode() {
600 base::RecordAction(UserMetricsAction("Accel_Toggle_Mirror_Mode"));
601 Shell::GetInstance()->display_controller()->ToggleMirrorMode();
604 void HandleToggleSpokenFeedback() {
605 base::RecordAction(UserMetricsAction("Accel_Toggle_Spoken_Feedback"));
607 Shell::GetInstance()->accessibility_delegate()->
608 ToggleSpokenFeedback(ui::A11Y_NOTIFICATION_SHOW);
611 bool CanHandleToggleTouchViewTesting() {
612 return base::CommandLine::ForCurrentProcess()->HasSwitch(
613 switches::kAshEnableTouchViewTesting);
616 void HandleToggleTouchViewTesting() {
617 // TODO(skuhne): This is only temporary! Remove this!
618 MaximizeModeController* controller = Shell::GetInstance()->
619 maximize_mode_controller();
620 controller->EnableMaximizeModeWindowManager(
621 !controller->IsMaximizeModeWindowManagerEnabled());
624 bool CanHandleTouchHud() {
625 return RootWindowController::ForTargetRootWindow()->touch_hud_debug();
628 void HandleTouchHudClear() {
629 RootWindowController::ForTargetRootWindow()->touch_hud_debug()->Clear();
632 void HandleTouchHudModeChange() {
633 RootWindowController* controller =
634 RootWindowController::ForTargetRootWindow();
635 controller->touch_hud_debug()->ChangeToNextMode();
638 void HandleVolumeDown(const ui::Accelerator& accelerator) {
639 VolumeControlDelegate* volume_delegate =
640 Shell::GetInstance()->system_tray_delegate()->GetVolumeControlDelegate();
641 if (volume_delegate)
642 volume_delegate->HandleVolumeDown(accelerator);
645 void HandleVolumeMute(const ui::Accelerator& accelerator) {
646 VolumeControlDelegate* volume_delegate =
647 Shell::GetInstance()->system_tray_delegate()->GetVolumeControlDelegate();
648 if (volume_delegate)
649 volume_delegate->HandleVolumeMute(accelerator);
652 void HandleVolumeUp(const ui::Accelerator& accelerator) {
653 VolumeControlDelegate* volume_delegate =
654 Shell::GetInstance()->system_tray_delegate()->GetVolumeControlDelegate();
655 if (volume_delegate)
656 volume_delegate->HandleVolumeUp(accelerator);
659 #endif // defined(OS_CHROMEOS)
661 } // namespace
663 ////////////////////////////////////////////////////////////////////////////////
664 // AcceleratorController, public:
666 AcceleratorController::AcceleratorController()
667 : accelerator_manager_(new ui::AcceleratorManager),
668 accelerator_history_(new ui::AcceleratorHistory) {
669 Init();
672 AcceleratorController::~AcceleratorController() {
675 void AcceleratorController::Register(const ui::Accelerator& accelerator,
676 ui::AcceleratorTarget* target) {
677 accelerator_manager_->Register(accelerator,
678 ui::AcceleratorManager::kNormalPriority,
679 target);
682 void AcceleratorController::Unregister(const ui::Accelerator& accelerator,
683 ui::AcceleratorTarget* target) {
684 accelerator_manager_->Unregister(accelerator, target);
687 void AcceleratorController::UnregisterAll(ui::AcceleratorTarget* target) {
688 accelerator_manager_->UnregisterAll(target);
691 bool AcceleratorController::Process(const ui::Accelerator& accelerator) {
692 if (ime_control_delegate_) {
693 return accelerator_manager_->Process(
694 ime_control_delegate_->RemapAccelerator(accelerator));
696 return accelerator_manager_->Process(accelerator);
699 bool AcceleratorController::IsRegistered(
700 const ui::Accelerator& accelerator) const {
701 return accelerator_manager_->GetCurrentTarget(accelerator) != NULL;
704 bool AcceleratorController::IsPreferred(
705 const ui::Accelerator& accelerator) const {
706 const ui::Accelerator remapped_accelerator = ime_control_delegate_.get() ?
707 ime_control_delegate_->RemapAccelerator(accelerator) : accelerator;
709 std::map<ui::Accelerator, AcceleratorAction>::const_iterator iter =
710 accelerators_.find(remapped_accelerator);
711 if (iter == accelerators_.end())
712 return false; // not an accelerator.
714 return preferred_actions_.find(iter->second) != preferred_actions_.end();
717 bool AcceleratorController::IsReserved(
718 const ui::Accelerator& accelerator) const {
719 const ui::Accelerator remapped_accelerator = ime_control_delegate_.get() ?
720 ime_control_delegate_->RemapAccelerator(accelerator) : accelerator;
722 std::map<ui::Accelerator, AcceleratorAction>::const_iterator iter =
723 accelerators_.find(remapped_accelerator);
724 if (iter == accelerators_.end())
725 return false; // not an accelerator.
727 return reserved_actions_.find(iter->second) != reserved_actions_.end();
730 bool AcceleratorController::PerformActionIfEnabled(AcceleratorAction action) {
731 if (CanPerformAction(action, ui::Accelerator())) {
732 PerformAction(action, ui::Accelerator());
733 return true;
735 return false;
738 AcceleratorController::AcceleratorProcessingRestriction
739 AcceleratorController::GetCurrentAcceleratorRestriction() {
740 return GetAcceleratorProcessingRestriction(-1);
743 void AcceleratorController::SetBrightnessControlDelegate(
744 scoped_ptr<BrightnessControlDelegate> brightness_control_delegate) {
745 brightness_control_delegate_ = brightness_control_delegate.Pass();
748 void AcceleratorController::SetImeControlDelegate(
749 scoped_ptr<ImeControlDelegate> ime_control_delegate) {
750 ime_control_delegate_ = ime_control_delegate.Pass();
753 void AcceleratorController::SetScreenshotDelegate(
754 scoped_ptr<ScreenshotDelegate> screenshot_delegate) {
755 screenshot_delegate_ = screenshot_delegate.Pass();
758 ////////////////////////////////////////////////////////////////////////////////
759 // AcceleratorController, ui::AcceleratorTarget implementation:
761 bool AcceleratorController::AcceleratorPressed(
762 const ui::Accelerator& accelerator) {
763 std::map<ui::Accelerator, AcceleratorAction>::const_iterator it =
764 accelerators_.find(accelerator);
765 DCHECK(it != accelerators_.end());
766 AcceleratorAction action = it->second;
767 if (CanPerformAction(action, accelerator)) {
768 PerformAction(action, accelerator);
769 return ShouldActionConsumeKeyEvent(action);
771 return false;
774 bool AcceleratorController::CanHandleAccelerators() const {
775 return true;
778 ///////////////////////////////////////////////////////////////////////////////
779 // AcceleratorController, private:
781 void AcceleratorController::Init() {
782 for (size_t i = 0; i < kActionsAllowedAtLoginOrLockScreenLength; ++i) {
783 actions_allowed_at_login_screen_.insert(
784 kActionsAllowedAtLoginOrLockScreen[i]);
785 actions_allowed_at_lock_screen_.insert(
786 kActionsAllowedAtLoginOrLockScreen[i]);
788 for (size_t i = 0; i < kActionsAllowedAtLockScreenLength; ++i)
789 actions_allowed_at_lock_screen_.insert(kActionsAllowedAtLockScreen[i]);
790 for (size_t i = 0; i < kActionsAllowedAtModalWindowLength; ++i)
791 actions_allowed_at_modal_window_.insert(kActionsAllowedAtModalWindow[i]);
792 for (size_t i = 0; i < kPreferredActionsLength; ++i)
793 preferred_actions_.insert(kPreferredActions[i]);
794 for (size_t i = 0; i < kReservedActionsLength; ++i)
795 reserved_actions_.insert(kReservedActions[i]);
796 for (size_t i = 0; i < kNonrepeatableActionsLength; ++i)
797 nonrepeatable_actions_.insert(kNonrepeatableActions[i]);
798 for (size_t i = 0; i < kActionsAllowedInAppModeLength; ++i)
799 actions_allowed_in_app_mode_.insert(kActionsAllowedInAppMode[i]);
800 for (size_t i = 0; i < kActionsNeedingWindowLength; ++i)
801 actions_needing_window_.insert(kActionsNeedingWindow[i]);
803 RegisterAccelerators(kAcceleratorData, kAcceleratorDataLength);
805 if (debug::DebugAcceleratorsEnabled()) {
806 RegisterAccelerators(kDebugAcceleratorData, kDebugAcceleratorDataLength);
807 // All debug accelerators are reserved.
808 for (size_t i = 0; i < kDebugAcceleratorDataLength; ++i)
809 reserved_actions_.insert(kDebugAcceleratorData[i].action);
812 #if defined(OS_CHROMEOS)
813 keyboard_brightness_control_delegate_.reset(
814 new KeyboardBrightnessController());
815 #endif
818 void AcceleratorController::RegisterAccelerators(
819 const AcceleratorData accelerators[],
820 size_t accelerators_length) {
821 for (size_t i = 0; i < accelerators_length; ++i) {
822 ui::Accelerator accelerator(accelerators[i].keycode,
823 accelerators[i].modifiers);
824 accelerator.set_type(accelerators[i].trigger_on_press ?
825 ui::ET_KEY_PRESSED : ui::ET_KEY_RELEASED);
826 Register(accelerator, this);
827 accelerators_.insert(
828 std::make_pair(accelerator, accelerators[i].action));
832 bool AcceleratorController::CanPerformAction(
833 AcceleratorAction action,
834 const ui::Accelerator& accelerator) {
835 if (nonrepeatable_actions_.find(action) != nonrepeatable_actions_.end() &&
836 accelerator.IsRepeat()) {
837 return false;
840 AcceleratorProcessingRestriction restriction =
841 GetAcceleratorProcessingRestriction(action);
842 if (restriction != RESTRICTION_NONE)
843 return restriction == RESTRICTION_PREVENT_PROCESSING_AND_PROPAGATION;
845 const ui::Accelerator& previous_accelerator =
846 accelerator_history_->previous_accelerator();
848 // True should be returned if running |action| does something. Otherwise,
849 // false should be returned to give the web contents a chance at handling the
850 // accelerator.
851 switch (action) {
852 case DEBUG_PRINT_LAYER_HIERARCHY:
853 case DEBUG_PRINT_VIEW_HIERARCHY:
854 case DEBUG_PRINT_WINDOW_HIERARCHY:
855 case DEBUG_TOGGLE_DESKTOP_BACKGROUND_MODE:
856 case DEBUG_TOGGLE_DEVICE_SCALE_FACTOR:
857 case DEBUG_TOGGLE_ROOT_WINDOW_FULL_SCREEN:
858 case DEBUG_TOGGLE_SHOW_DEBUG_BORDERS:
859 case DEBUG_TOGGLE_SHOW_FPS_COUNTER:
860 case DEBUG_TOGGLE_SHOW_PAINT_RECTS:
861 return debug::DebugAcceleratorsEnabled();
862 case MAGNIFY_SCREEN_ZOOM_IN:
863 case MAGNIFY_SCREEN_ZOOM_OUT:
864 return CanHandleMagnifyScreen();
865 case NEW_INCOGNITO_WINDOW:
866 return CanHandleNewIncognitoWindow();
867 case NEXT_IME:
868 return CanHandleNextIme(ime_control_delegate_.get(),
869 previous_accelerator);
870 case PREVIOUS_IME:
871 return CanHandlePreviousIme(ime_control_delegate_.get());
872 case SCALE_UI_RESET:
873 return CanHandleScaleReset();
874 case SCALE_UI_UP:
875 case SCALE_UI_DOWN:
876 return CanHandleScaleUI();
877 case SHOW_MESSAGE_CENTER_BUBBLE:
878 return CanHandleShowMessageCenterBubble();
879 case SWITCH_IME:
880 return CanHandleSwitchIme(ime_control_delegate_.get(), accelerator);
881 case TOGGLE_APP_LIST:
882 return CanHandleToggleAppList(accelerator, previous_accelerator);
883 case WINDOW_CYCLE_SNAP_DOCK_LEFT:
884 case WINDOW_CYCLE_SNAP_DOCK_RIGHT:
885 return CanHandleWindowSnapOrDock();
886 case WINDOW_POSITION_CENTER:
887 return CanHandlePositionCenter();
888 #if defined(OS_CHROMEOS)
889 case DEBUG_ADD_REMOVE_DISPLAY:
890 return debug::DebugAcceleratorsEnabled();
891 case DISABLE_CAPS_LOCK:
892 return CanHandleDisableCapsLock(previous_accelerator);
893 case SILENCE_SPOKEN_FEEDBACK:
894 return CanHandleSilenceSpokenFeedback();
895 case SWITCH_TO_PREVIOUS_USER:
896 case SWITCH_TO_NEXT_USER:
897 return CanHandleCycleUser();
898 case TOGGLE_CAPS_LOCK:
899 return CanHandleToggleCapsLock(accelerator, previous_accelerator);
900 case TOGGLE_TOUCH_VIEW_TESTING:
901 return CanHandleToggleTouchViewTesting();
902 case TOUCH_HUD_CLEAR:
903 case TOUCH_HUD_MODE_CHANGE:
904 return CanHandleTouchHud();
905 #endif
907 case CYCLE_BACKWARD_MRU:
908 case CYCLE_FORWARD_MRU:
909 case EXIT:
910 case FOCUS_NEXT_PANE:
911 case FOCUS_PREVIOUS_PANE:
912 case FOCUS_SHELF:
913 case LAUNCH_APP_0:
914 case LAUNCH_APP_1:
915 case LAUNCH_APP_2:
916 case LAUNCH_APP_3:
917 case LAUNCH_APP_4:
918 case LAUNCH_APP_5:
919 case LAUNCH_APP_6:
920 case LAUNCH_APP_7:
921 case LAUNCH_LAST_APP:
922 case MEDIA_NEXT_TRACK:
923 case MEDIA_PLAY_PAUSE:
924 case MEDIA_PREV_TRACK:
925 case NEW_TAB:
926 case NEW_WINDOW:
927 case OPEN_FEEDBACK_PAGE:
928 case PRINT_UI_HIERARCHIES:
929 case RESTORE_TAB:
930 case ROTATE_SCREEN:
931 case ROTATE_WINDOW:
932 case SHOW_KEYBOARD_OVERLAY:
933 case SHOW_SYSTEM_TRAY_BUBBLE:
934 case SHOW_TASK_MANAGER:
935 case TAKE_PARTIAL_SCREENSHOT:
936 case TAKE_SCREENSHOT:
937 case TOGGLE_FULLSCREEN:
938 case TOGGLE_MAXIMIZED:
939 case TOGGLE_OVERVIEW:
940 case WINDOW_MINIMIZE:
941 #if defined(OS_CHROMEOS)
942 case BRIGHTNESS_DOWN:
943 case BRIGHTNESS_UP:
944 case DISABLE_GPU_WATCHDOG:
945 case KEYBOARD_BRIGHTNESS_DOWN:
946 case KEYBOARD_BRIGHTNESS_UP:
947 case LOCK_PRESSED:
948 case LOCK_RELEASED:
949 case LOCK_SCREEN:
950 case OPEN_CROSH:
951 case OPEN_FILE_MANAGER:
952 case OPEN_GET_HELP:
953 case POWER_PRESSED:
954 case POWER_RELEASED:
955 case SWAP_PRIMARY_DISPLAY:
956 case TOGGLE_MIRROR_MODE:
957 case TOGGLE_SPOKEN_FEEDBACK:
958 case TOGGLE_WIFI:
959 case TOUCH_HUD_PROJECTION_TOGGLE:
960 case VOLUME_DOWN:
961 case VOLUME_MUTE:
962 case VOLUME_UP:
963 #else
964 case DUMMY_FOR_RESERVED:
965 #endif
966 return true;
968 return false;
971 void AcceleratorController::PerformAction(AcceleratorAction action,
972 const ui::Accelerator& accelerator) {
973 AcceleratorProcessingRestriction restriction =
974 GetAcceleratorProcessingRestriction(action);
975 if (restriction != RESTRICTION_NONE)
976 return;
978 // If your accelerator invokes more than one line of code, please either
979 // implement it in your module's controller code (like TOGGLE_MIRROR_MODE
980 // below) or pull it into a HandleFoo() function above.
981 switch (action) {
982 case CYCLE_BACKWARD_MRU:
983 HandleCycleBackwardMRU(accelerator);
984 break;
985 case CYCLE_FORWARD_MRU:
986 HandleCycleForwardMRU(accelerator);
987 break;
988 case DEBUG_PRINT_LAYER_HIERARCHY:
989 case DEBUG_PRINT_VIEW_HIERARCHY:
990 case DEBUG_PRINT_WINDOW_HIERARCHY:
991 case DEBUG_TOGGLE_DESKTOP_BACKGROUND_MODE:
992 case DEBUG_TOGGLE_DEVICE_SCALE_FACTOR:
993 case DEBUG_TOGGLE_ROOT_WINDOW_FULL_SCREEN:
994 case DEBUG_TOGGLE_SHOW_DEBUG_BORDERS:
995 case DEBUG_TOGGLE_SHOW_FPS_COUNTER:
996 case DEBUG_TOGGLE_SHOW_PAINT_RECTS:
997 debug::PerformDebugActionIfEnabled(action);
998 break;
999 case EXIT:
1000 // UMA metrics are recorded in the handler.
1001 exit_warning_handler_.HandleAccelerator();
1002 break;
1003 case FOCUS_NEXT_PANE:
1004 HandleRotatePaneFocus(Shell::FORWARD);
1005 break;
1006 case FOCUS_PREVIOUS_PANE:
1007 HandleRotatePaneFocus(Shell::BACKWARD);
1008 break;
1009 case FOCUS_SHELF:
1010 HandleFocusShelf();
1011 break;
1012 case LAUNCH_APP_0:
1013 HandleLaunchAppN(0);
1014 break;
1015 case LAUNCH_APP_1:
1016 HandleLaunchAppN(1);
1017 break;
1018 case LAUNCH_APP_2:
1019 HandleLaunchAppN(2);
1020 break;
1021 case LAUNCH_APP_3:
1022 HandleLaunchAppN(3);
1023 break;
1024 case LAUNCH_APP_4:
1025 HandleLaunchAppN(4);
1026 break;
1027 case LAUNCH_APP_5:
1028 HandleLaunchAppN(5);
1029 break;
1030 case LAUNCH_APP_6:
1031 HandleLaunchAppN(6);
1032 break;
1033 case LAUNCH_APP_7:
1034 HandleLaunchAppN(7);
1035 break;
1036 case LAUNCH_LAST_APP:
1037 HandleLaunchLastApp();
1038 break;
1039 case MAGNIFY_SCREEN_ZOOM_IN:
1040 HandleMagnifyScreen(1);
1041 break;
1042 case MAGNIFY_SCREEN_ZOOM_OUT:
1043 HandleMagnifyScreen(-1);
1044 break;
1045 case MEDIA_NEXT_TRACK:
1046 HandleMediaNextTrack();
1047 break;
1048 case MEDIA_PLAY_PAUSE:
1049 HandleMediaPlayPause();
1050 break;
1051 case MEDIA_PREV_TRACK:
1052 HandleMediaPrevTrack();
1053 break;
1054 case NEW_INCOGNITO_WINDOW:
1055 HandleNewIncognitoWindow();
1056 break;
1057 case NEW_TAB:
1058 HandleNewTab(accelerator);
1059 break;
1060 case NEW_WINDOW:
1061 HandleNewWindow();
1062 break;
1063 case NEXT_IME:
1064 HandleNextIme(ime_control_delegate_.get());
1065 break;
1066 case OPEN_FEEDBACK_PAGE:
1067 HandleOpenFeedbackPage();
1068 break;
1069 case PREVIOUS_IME:
1070 HandlePreviousIme(ime_control_delegate_.get(), accelerator);
1071 break;
1072 case PRINT_UI_HIERARCHIES:
1073 debug::PrintUIHierarchies();
1074 break;
1075 case RESTORE_TAB:
1076 HandleRestoreTab();
1077 break;
1078 case ROTATE_SCREEN:
1079 HandleRotateScreen();
1080 break;
1081 case ROTATE_WINDOW:
1082 HandleRotateActiveWindow();
1083 break;
1084 case SCALE_UI_DOWN:
1085 HandleScaleUI(false /* down */);
1086 break;
1087 case SCALE_UI_RESET:
1088 HandleScaleReset();
1089 break;
1090 case SCALE_UI_UP:
1091 HandleScaleUI(true /* up */);
1092 break;
1093 case SHOW_KEYBOARD_OVERLAY:
1094 HandleShowKeyboardOverlay();
1095 break;
1096 case SHOW_MESSAGE_CENTER_BUBBLE:
1097 HandleShowMessageCenterBubble();
1098 break;
1099 case SHOW_SYSTEM_TRAY_BUBBLE:
1100 HandleShowSystemTrayBubble();
1101 break;
1102 case SHOW_TASK_MANAGER:
1103 HandleShowTaskManager();
1104 break;
1105 case SWITCH_IME:
1106 HandleSwitchIme(ime_control_delegate_.get(), accelerator);
1107 break;
1108 case TAKE_PARTIAL_SCREENSHOT:
1109 HandleTakePartialScreenshot(screenshot_delegate_.get());
1110 break;
1111 case TAKE_SCREENSHOT:
1112 HandleTakeScreenshot(screenshot_delegate_.get());
1113 break;
1114 case TOGGLE_APP_LIST:
1115 HandleToggleAppList(accelerator);
1116 break;
1117 case TOGGLE_FULLSCREEN:
1118 HandleToggleFullscreen(accelerator);
1119 break;
1120 case TOGGLE_MAXIMIZED:
1121 accelerators::ToggleMaximized();
1122 break;
1123 case TOGGLE_OVERVIEW:
1124 HandleToggleOverview();
1125 break;
1126 case WINDOW_CYCLE_SNAP_DOCK_LEFT:
1127 case WINDOW_CYCLE_SNAP_DOCK_RIGHT:
1128 HandleWindowSnapOrDock(action);
1129 break;
1130 case WINDOW_MINIMIZE:
1131 HandleWindowMinimize();
1132 break;
1133 case WINDOW_POSITION_CENTER:
1134 HandlePositionCenter();
1135 break;
1136 #if defined(OS_CHROMEOS)
1137 case BRIGHTNESS_DOWN:
1138 HandleBrightnessDown(brightness_control_delegate_.get(), accelerator);
1139 break;
1140 case BRIGHTNESS_UP:
1141 HandleBrightnessUp(brightness_control_delegate_.get(), accelerator);
1142 break;
1143 case DEBUG_ADD_REMOVE_DISPLAY:
1144 debug::PerformDebugActionIfEnabled(action);
1145 break;
1146 case DISABLE_CAPS_LOCK:
1147 HandleDisableCapsLock();
1148 break;
1149 case DISABLE_GPU_WATCHDOG:
1150 Shell::GetInstance()->gpu_support()->DisableGpuWatchdog();
1151 break;
1152 case KEYBOARD_BRIGHTNESS_DOWN:
1153 HandleKeyboardBrightnessDown(keyboard_brightness_control_delegate_.get(),
1154 accelerator);
1155 break;
1156 case KEYBOARD_BRIGHTNESS_UP:
1157 HandleKeyboardBrightnessUp(keyboard_brightness_control_delegate_.get(),
1158 accelerator);
1159 break;
1160 case LOCK_PRESSED:
1161 case LOCK_RELEASED:
1162 Shell::GetInstance()->power_button_controller()->
1163 OnLockButtonEvent(action == LOCK_PRESSED, base::TimeTicks());
1164 break;
1165 case LOCK_SCREEN:
1166 HandleLock();
1167 break;
1168 case OPEN_CROSH:
1169 HandleCrosh();
1170 break;
1171 case OPEN_FILE_MANAGER:
1172 HandleFileManager();
1173 break;
1174 case OPEN_GET_HELP:
1175 HandleGetHelp();
1176 break;
1177 case POWER_PRESSED: // fallthrough
1178 case POWER_RELEASED:
1179 if (!base::SysInfo::IsRunningOnChromeOS()) {
1180 // There is no powerd, the Chrome OS power manager, in linux desktop,
1181 // so call the PowerButtonController here.
1182 Shell::GetInstance()->power_button_controller()->
1183 OnPowerButtonEvent(action == POWER_PRESSED, base::TimeTicks());
1185 // We don't do anything with these at present on the device,
1186 // (power button events are reported to us from powerm via
1187 // D-BUS), but we consume them to prevent them from getting
1188 // passed to apps -- see http://crbug.com/146609.
1189 break;
1190 case SILENCE_SPOKEN_FEEDBACK:
1191 HandleSilenceSpokenFeedback();
1192 break;
1193 case SWAP_PRIMARY_DISPLAY:
1194 HandleSwapPrimaryDisplay();
1195 break;
1196 case SWITCH_TO_NEXT_USER:
1197 HandleCycleUser(SessionStateDelegate::CYCLE_TO_NEXT_USER);
1198 break;
1199 case SWITCH_TO_PREVIOUS_USER:
1200 HandleCycleUser(SessionStateDelegate::CYCLE_TO_PREVIOUS_USER);
1201 break;
1202 case TOGGLE_CAPS_LOCK:
1203 HandleToggleCapsLock();
1204 break;
1205 case TOGGLE_MIRROR_MODE:
1206 HandleToggleMirrorMode();
1207 break;
1208 case TOGGLE_SPOKEN_FEEDBACK:
1209 HandleToggleSpokenFeedback();
1210 break;
1211 case TOGGLE_TOUCH_VIEW_TESTING:
1212 HandleToggleTouchViewTesting();
1213 break;
1214 case TOGGLE_WIFI:
1215 Shell::GetInstance()->system_tray_notifier()->NotifyRequestToggleWifi();
1216 break;
1217 case TOUCH_HUD_CLEAR:
1218 HandleTouchHudClear();
1219 break;
1220 case TOUCH_HUD_MODE_CHANGE:
1221 HandleTouchHudModeChange();
1222 break;
1223 case TOUCH_HUD_PROJECTION_TOGGLE:
1224 accelerators::ToggleTouchHudProjection();
1225 break;
1226 case VOLUME_DOWN:
1227 HandleVolumeDown(accelerator);
1228 break;
1229 case VOLUME_MUTE:
1230 HandleVolumeMute(accelerator);
1231 break;
1232 case VOLUME_UP:
1233 HandleVolumeUp(accelerator);
1234 break;
1235 #else
1236 case DUMMY_FOR_RESERVED:
1237 NOTREACHED();
1238 break;
1239 #endif
1243 bool AcceleratorController::ShouldActionConsumeKeyEvent(
1244 AcceleratorAction action) {
1245 #if defined(OS_CHROMEOS)
1246 if (action == SILENCE_SPOKEN_FEEDBACK)
1247 return false;
1248 #endif
1250 // Adding new exceptions is *STRONGLY* discouraged.
1251 return true;
1254 AcceleratorController::AcceleratorProcessingRestriction
1255 AcceleratorController::GetAcceleratorProcessingRestriction(int action) {
1256 ash::Shell* shell = ash::Shell::GetInstance();
1257 if (!shell->session_state_delegate()->IsActiveUserSessionStarted() &&
1258 actions_allowed_at_login_screen_.find(action) ==
1259 actions_allowed_at_login_screen_.end()) {
1260 return RESTRICTION_PREVENT_PROCESSING;
1262 if (shell->session_state_delegate()->IsScreenLocked() &&
1263 actions_allowed_at_lock_screen_.find(action) ==
1264 actions_allowed_at_lock_screen_.end()) {
1265 return RESTRICTION_PREVENT_PROCESSING;
1267 if (shell->delegate()->IsRunningInForcedAppMode() &&
1268 actions_allowed_in_app_mode_.find(action) ==
1269 actions_allowed_in_app_mode_.end()) {
1270 return RESTRICTION_PREVENT_PROCESSING;
1272 if (shell->IsSystemModalWindowOpen() &&
1273 actions_allowed_at_modal_window_.find(action) ==
1274 actions_allowed_at_modal_window_.end()) {
1275 // Note we prevent the shortcut from propagating so it will not
1276 // be passed to the modal window. This is important for things like
1277 // Alt+Tab that would cause an undesired effect in the modal window by
1278 // cycling through its window elements.
1279 return RESTRICTION_PREVENT_PROCESSING_AND_PROPAGATION;
1281 if (shell->mru_window_tracker()->BuildMruWindowList().empty() &&
1282 actions_needing_window_.find(action) != actions_needing_window_.end()) {
1283 Shell::GetInstance()->accessibility_delegate()->TriggerAccessibilityAlert(
1284 ui::A11Y_ALERT_WINDOW_NEEDED);
1285 return RESTRICTION_PREVENT_PROCESSING_AND_PROPAGATION;
1287 return RESTRICTION_NONE;
1290 void AcceleratorController::SetKeyboardBrightnessControlDelegate(
1291 scoped_ptr<KeyboardBrightnessControlDelegate>
1292 keyboard_brightness_control_delegate) {
1293 keyboard_brightness_control_delegate_ =
1294 keyboard_brightness_control_delegate.Pass();
1297 } // namespace ash