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/window_tree_host_manager.h"
16 #include "ash/focus_cycler.h"
17 #include "ash/gpu_support.h"
18 #include "ash/ime_control_delegate.h"
19 #include "ash/magnifier/magnification_controller.h"
20 #include "ash/magnifier/partial_magnification_controller.h"
21 #include "ash/media_delegate.h"
22 #include "ash/multi_profile_uma.h"
23 #include "ash/new_window_delegate.h"
24 #include "ash/root_window_controller.h"
25 #include "ash/rotator/screen_rotation_animator.h"
26 #include "ash/rotator/window_rotation.h"
27 #include "ash/screenshot_delegate.h"
28 #include "ash/session/session_state_delegate.h"
29 #include "ash/shelf/shelf.h"
30 #include "ash/shelf/shelf_delegate.h"
31 #include "ash/shelf/shelf_model.h"
32 #include "ash/shelf/shelf_widget.h"
33 #include "ash/shell.h"
34 #include "ash/shell_delegate.h"
35 #include "ash/shell_window_ids.h"
36 #include "ash/system/brightness_control_delegate.h"
37 #include "ash/system/keyboard_brightness/keyboard_brightness_control_delegate.h"
38 #include "ash/system/status_area_widget.h"
39 #include "ash/system/system_notifier.h"
40 #include "ash/system/tray/system_tray.h"
41 #include "ash/system/tray/system_tray_delegate.h"
42 #include "ash/system/tray/system_tray_notifier.h"
43 #include "ash/system/web_notification/web_notification_tray.h"
44 #include "ash/touch/touch_hud_debug.h"
45 #include "ash/utility/partial_screenshot_controller.h"
46 #include "ash/volume_control_delegate.h"
47 #include "ash/wm/maximize_mode/maximize_mode_controller.h"
48 #include "ash/wm/mru_window_tracker.h"
49 #include "ash/wm/overview/window_selector_controller.h"
50 #include "ash/wm/power_button_controller.h"
51 #include "ash/wm/window_cycle_controller.h"
52 #include "ash/wm/window_state.h"
53 #include "ash/wm/window_util.h"
54 #include "ash/wm/wm_event.h"
55 #include "base/bind.h"
56 #include "base/command_line.h"
57 #include "base/metrics/histogram_macros.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/base/l10n/l10n_util.h"
63 #include "ui/base/resource/resource_bundle.h"
64 #include "ui/compositor/layer.h"
65 #include "ui/compositor/layer_animation_sequence.h"
66 #include "ui/compositor/layer_animator.h"
67 #include "ui/events/event.h"
68 #include "ui/events/keycodes/keyboard_codes.h"
69 #include "ui/gfx/screen.h"
70 #include "ui/message_center/message_center.h"
71 #include "ui/message_center/notification.h"
72 #include "ui/message_center/notifier_settings.h"
73 #include "ui/views/controls/webview/webview.h"
75 #if defined(OS_CHROMEOS)
76 #include "ash/system/chromeos/keyboard_brightness_controller.h"
77 #include "base/sys_info.h"
78 #include "ui/base/ime/chromeos/ime_keyboard.h"
79 #include "ui/base/ime/chromeos/input_method_manager.h"
80 #endif // defined(OS_CHROMEOS)
85 using base::UserMetricsAction
;
87 // The notification delegate that will be used to open the keyboard shortcut
88 // help page when the notification is clicked.
89 class DeprecatedAcceleratorNotificationDelegate
90 : public message_center::NotificationDelegate
{
92 DeprecatedAcceleratorNotificationDelegate() {}
94 // message_center::NotificationDelegate:
95 bool HasClickedListener() override
{ return true; }
97 void Click() override
{
98 Shell::GetInstance()->delegate()->OpenKeyboardShortcutHelpPage();
102 // Private destructor since NotificationDelegate is ref-counted.
103 ~DeprecatedAcceleratorNotificationDelegate() override
{}
105 DISALLOW_COPY_AND_ASSIGN(DeprecatedAcceleratorNotificationDelegate
);
108 ui::Accelerator
CreateAccelerator(ui::KeyboardCode keycode
,
110 bool trigger_on_press
) {
111 ui::Accelerator
accelerator(keycode
, modifiers
);
112 accelerator
.set_type(trigger_on_press
? ui::ET_KEY_PRESSED
113 : ui::ET_KEY_RELEASED
);
117 void ShowDeprecatedAcceleratorNotification(const char* const notification_id
,
119 const base::string16 message
= l10n_util::GetStringUTF16(message_id
);
120 scoped_ptr
<message_center::Notification
> notification(
121 new message_center::Notification(
122 message_center::NOTIFICATION_TYPE_SIMPLE
, notification_id
,
123 base::string16(), message
,
124 Shell::GetInstance()->delegate()->GetDeprecatedAcceleratorImage(),
125 base::string16(), GURL(),
126 message_center::NotifierId(
127 message_center::NotifierId::SYSTEM_COMPONENT
,
128 system_notifier::kNotifierDeprecatedAccelerator
),
129 message_center::RichNotificationData(),
130 new DeprecatedAcceleratorNotificationDelegate
));
131 message_center::MessageCenter::Get()->AddNotification(notification
.Pass());
134 void RecordUmaHistogram(const char* histogram_name
,
135 DeprecatedAcceleratorUsage sample
) {
136 auto histogram
= base::LinearHistogram::FactoryGet(
137 histogram_name
, 1, DEPRECATED_USAGE_COUNT
, DEPRECATED_USAGE_COUNT
+ 1,
138 base::HistogramBase::kUmaTargetedHistogramFlag
);
139 histogram
->Add(sample
);
142 void HandleCycleBackwardMRU(const ui::Accelerator
& accelerator
) {
143 if (accelerator
.key_code() == ui::VKEY_TAB
)
144 base::RecordAction(base::UserMetricsAction("Accel_PrevWindow_Tab"));
146 Shell::GetInstance()->window_cycle_controller()->HandleCycleWindow(
147 WindowCycleController::BACKWARD
);
150 void HandleCycleForwardMRU(const ui::Accelerator
& accelerator
) {
151 if (accelerator
.key_code() == ui::VKEY_TAB
)
152 base::RecordAction(base::UserMetricsAction("Accel_NextWindow_Tab"));
154 Shell::GetInstance()->window_cycle_controller()->HandleCycleWindow(
155 WindowCycleController::FORWARD
);
158 void HandleRotatePaneFocus(Shell::Direction direction
) {
159 Shell
* shell
= Shell::GetInstance();
161 // TODO(stevet): Not sure if this is the same as IDC_FOCUS_NEXT_PANE.
162 case Shell::FORWARD
: {
163 base::RecordAction(UserMetricsAction("Accel_Focus_Next_Pane"));
164 shell
->focus_cycler()->RotateFocus(FocusCycler::FORWARD
);
167 case Shell::BACKWARD
: {
168 base::RecordAction(UserMetricsAction("Accel_Focus_Previous_Pane"));
169 shell
->focus_cycler()->RotateFocus(FocusCycler::BACKWARD
);
175 void HandleFocusShelf() {
176 Shell
* shell
= Shell::GetInstance();
177 base::RecordAction(base::UserMetricsAction("Accel_Focus_Shelf"));
178 shell
->focus_cycler()->FocusWidget(
179 Shelf::ForPrimaryDisplay()->shelf_widget());
182 void HandleLaunchAppN(int n
) {
183 base::RecordAction(UserMetricsAction("Accel_Launch_App"));
184 Shelf::ForPrimaryDisplay()->LaunchAppIndexAt(n
);
187 void HandleLaunchLastApp() {
188 base::RecordAction(UserMetricsAction("Accel_Launch_Last_App"));
189 Shelf::ForPrimaryDisplay()->LaunchAppIndexAt(-1);
192 bool CanHandleMagnifyScreen() {
193 Shell
* shell
= Shell::GetInstance();
194 return shell
->magnification_controller()->IsEnabled() ||
195 shell
->partial_magnification_controller()->is_enabled();
198 // Magnify the screen
199 void HandleMagnifyScreen(int delta_index
) {
200 if (ash::Shell::GetInstance()->magnification_controller()->IsEnabled()) {
201 // TODO(yoshiki): Move the following logic to MagnificationController.
203 ash::Shell::GetInstance()->magnification_controller()->GetScale();
204 // Calculate rounded logarithm (base kMagnificationScaleFactor) of scale.
205 int scale_index
= std::floor(
206 std::log(scale
) / std::log(ui::kMagnificationScaleFactor
) + 0.5);
208 int new_scale_index
= std::max(0, std::min(8, scale_index
+ delta_index
));
210 ash::Shell::GetInstance()->magnification_controller()->SetScale(
211 std::pow(ui::kMagnificationScaleFactor
, new_scale_index
), true);
212 } else if (ash::Shell::GetInstance()->
213 partial_magnification_controller()->is_enabled()) {
214 float scale
= delta_index
> 0 ? kDefaultPartialMagnifiedScale
: 1;
215 ash::Shell::GetInstance()->partial_magnification_controller()->
220 void HandleMediaNextTrack() {
221 Shell::GetInstance()->media_delegate()->HandleMediaNextTrack();
224 void HandleMediaPlayPause() {
225 Shell::GetInstance()->media_delegate()->HandleMediaPlayPause();
228 void HandleMediaPrevTrack() {
229 Shell::GetInstance()->media_delegate()->HandleMediaPrevTrack();
232 bool CanHandleNewIncognitoWindow() {
233 return Shell::GetInstance()->delegate()->IsIncognitoAllowed();
236 void HandleNewIncognitoWindow() {
237 base::RecordAction(UserMetricsAction("Accel_New_Incognito_Window"));
238 Shell::GetInstance()->new_window_delegate()->NewWindow(
239 true /* is_incognito */);
242 void HandleNewTab(const ui::Accelerator
& accelerator
) {
243 if (accelerator
.key_code() == ui::VKEY_T
)
244 base::RecordAction(base::UserMetricsAction("Accel_NewTab_T"));
245 Shell::GetInstance()->new_window_delegate()->NewTab();
248 void HandleNewWindow() {
249 base::RecordAction(base::UserMetricsAction("Accel_New_Window"));
250 Shell::GetInstance()->new_window_delegate()->NewWindow(
251 false /* is_incognito */);
254 bool CanHandleNextIme(ImeControlDelegate
* ime_control_delegate
,
255 const ui::Accelerator
& previous_accelerator
) {
256 // This check is necessary e.g. not to process the Shift+Alt+
257 // ET_KEY_RELEASED accelerator for Chrome OS (see ash/accelerators/
258 // accelerator_controller.cc) when Shift+Alt+Tab is pressed and then Tab
260 ui::KeyboardCode previous_key_code
= previous_accelerator
.key_code();
261 if (previous_accelerator
.type() == ui::ET_KEY_RELEASED
&&
262 // Workaround for crbug.com/139556. CJK IME users tend to press
263 // Enter (or Space) and Shift+Alt almost at the same time to commit
264 // an IME string and then switch from the IME to the English layout.
265 // This workaround allows the user to trigger NEXT_IME even if the
266 // user presses Shift+Alt before releasing Enter.
267 // TODO(nona|mazda): Fix crbug.com/139556 in a cleaner way.
268 previous_key_code
!= ui::VKEY_RETURN
&&
269 previous_key_code
!= ui::VKEY_SPACE
) {
270 // We totally ignore this accelerator.
271 // TODO(mazda): Fix crbug.com/158217
274 return ime_control_delegate
&& ime_control_delegate
->CanCycleIme();
277 void HandleNextIme(ImeControlDelegate
* ime_control_delegate
) {
278 base::RecordAction(UserMetricsAction("Accel_Next_Ime"));
279 ime_control_delegate
->HandleNextIme();
282 void HandleOpenFeedbackPage() {
283 base::RecordAction(UserMetricsAction("Accel_Open_Feedback_Page"));
284 ash::Shell::GetInstance()->new_window_delegate()->OpenFeedbackPage();
287 bool CanHandlePreviousIme(ImeControlDelegate
* ime_control_delegate
) {
288 return ime_control_delegate
&& ime_control_delegate
->CanCycleIme();
291 void HandlePreviousIme(ImeControlDelegate
* ime_control_delegate
,
292 const ui::Accelerator
& accelerator
) {
293 base::RecordAction(UserMetricsAction("Accel_Previous_Ime"));
294 if (accelerator
.type() == ui::ET_KEY_PRESSED
)
295 ime_control_delegate
->HandlePreviousIme();
296 // Else: consume the Ctrl+Space ET_KEY_RELEASED event but do not do anything.
299 void HandleRestoreTab() {
300 base::RecordAction(base::UserMetricsAction("Accel_Restore_Tab"));
301 Shell::GetInstance()->new_window_delegate()->RestoreTab();
304 gfx::Display::Rotation
GetNextRotation(gfx::Display::Rotation current
) {
306 case gfx::Display::ROTATE_0
:
307 return gfx::Display::ROTATE_90
;
308 case gfx::Display::ROTATE_90
:
309 return gfx::Display::ROTATE_180
;
310 case gfx::Display::ROTATE_180
:
311 return gfx::Display::ROTATE_270
;
312 case gfx::Display::ROTATE_270
:
313 return gfx::Display::ROTATE_0
;
315 NOTREACHED() << "Unknown rotation:" << current
;
316 return gfx::Display::ROTATE_0
;
319 // Rotates the screen.
320 void HandleRotateScreen() {
321 if (Shell::GetInstance()->display_manager()->IsInUnifiedMode())
324 base::RecordAction(UserMetricsAction("Accel_Rotate_Window"));
325 gfx::Point point
= Shell::GetScreen()->GetCursorScreenPoint();
326 gfx::Display display
= Shell::GetScreen()->GetDisplayNearestPoint(point
);
327 const DisplayInfo
& display_info
=
328 Shell::GetInstance()->display_manager()->GetDisplayInfo(display
.id());
329 ash::ScreenRotationAnimator(display
.id())
330 .Rotate(GetNextRotation(display_info
.GetActiveRotation()),
331 gfx::Display::ROTATION_SOURCE_USER
);
334 // Rotate the active window.
335 void HandleRotateActiveWindow() {
336 base::RecordAction(UserMetricsAction("Accel_Rotate_Window"));
337 aura::Window
* active_window
= wm::GetActiveWindow();
339 // The rotation animation bases its target transform on the current
340 // rotation and position. Since there could be an animation in progress
341 // right now, queue this animation so when it starts it picks up a neutral
342 // rotation and position. Use replace so we only enqueue one at a time.
343 active_window
->layer()->GetAnimator()->
344 set_preemption_strategy(ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS
);
345 active_window
->layer()->GetAnimator()->StartAnimation(
346 new ui::LayerAnimationSequence(
347 new ash::WindowRotation(360, active_window
->layer())));
351 void HandleShowKeyboardOverlay() {
352 base::RecordAction(UserMetricsAction("Accel_Show_Keyboard_Overlay"));
353 ash::Shell::GetInstance()->new_window_delegate()->ShowKeyboardOverlay();
356 bool CanHandleShowMessageCenterBubble() {
357 RootWindowController
* controller
=
358 RootWindowController::ForTargetRootWindow();
359 StatusAreaWidget
* status_area_widget
=
360 controller
->shelf()->status_area_widget();
361 return status_area_widget
&&
362 status_area_widget
->web_notification_tray()->visible();
365 void HandleShowMessageCenterBubble() {
366 base::RecordAction(UserMetricsAction("Accel_Show_Message_Center_Bubble"));
367 RootWindowController
* controller
=
368 RootWindowController::ForTargetRootWindow();
369 StatusAreaWidget
* status_area_widget
=
370 controller
->shelf()->status_area_widget();
371 if (status_area_widget
) {
372 WebNotificationTray
* notification_tray
=
373 status_area_widget
->web_notification_tray();
374 if (notification_tray
->visible())
375 notification_tray
->ShowMessageCenterBubble();
379 void HandleShowSystemTrayBubble() {
380 base::RecordAction(UserMetricsAction("Accel_Show_System_Tray_Bubble"));
381 RootWindowController
* controller
=
382 RootWindowController::ForTargetRootWindow();
383 if (!controller
->GetSystemTray()->HasSystemBubble())
384 controller
->GetSystemTray()->ShowDefaultView(BUBBLE_CREATE_NEW
);
387 void HandleShowTaskManager() {
388 base::RecordAction(UserMetricsAction("Accel_Show_Task_Manager"));
389 Shell::GetInstance()->new_window_delegate()->ShowTaskManager();
392 bool CanHandleSwitchIme(ImeControlDelegate
* ime_control_delegate
,
393 const ui::Accelerator
& accelerator
) {
394 return ime_control_delegate
&&
395 ime_control_delegate
->CanSwitchIme(accelerator
);
398 void HandleSwitchIme(ImeControlDelegate
* ime_control_delegate
,
399 const ui::Accelerator
& accelerator
) {
400 base::RecordAction(UserMetricsAction("Accel_Switch_Ime"));
401 ime_control_delegate
->HandleSwitchIme(accelerator
);
404 void HandleTakePartialScreenshot(ScreenshotDelegate
* screenshot_delegate
) {
405 base::RecordAction(UserMetricsAction("Accel_Take_Partial_Screenshot"));
406 DCHECK(screenshot_delegate
);
408 ->partial_screenshot_controller()
409 ->StartPartialScreenshotSession(screenshot_delegate
);
412 void HandleTakeScreenshot(ScreenshotDelegate
* screenshot_delegate
) {
413 base::RecordAction(UserMetricsAction("Accel_Take_Screenshot"));
414 DCHECK(screenshot_delegate
);
415 if (screenshot_delegate
->CanTakeScreenshot())
416 screenshot_delegate
->HandleTakeScreenshotForAllRootWindows();
419 bool CanHandleToggleAppList(const ui::Accelerator
& accelerator
,
420 const ui::Accelerator
& previous_accelerator
) {
421 if (accelerator
.key_code() == ui::VKEY_LWIN
) {
422 // If something else was pressed between the Search key (LWIN)
423 // being pressed and released, then ignore the release of the
425 if (previous_accelerator
.type() != ui::ET_KEY_PRESSED
||
426 previous_accelerator
.key_code() != ui::VKEY_LWIN
) {
430 // When spoken feedback is enabled, we should neither toggle the list nor
431 // consume the key since Search+Shift is one of the shortcuts the a11y
432 // feature uses. crbug.com/132296
433 if (Shell::GetInstance()
434 ->accessibility_delegate()
435 ->IsSpokenFeedbackEnabled()) {
442 void HandleToggleAppList(const ui::Accelerator
& accelerator
) {
443 if (accelerator
.key_code() == ui::VKEY_LWIN
)
444 base::RecordAction(base::UserMetricsAction("Accel_Search_LWin"));
445 ash::Shell::GetInstance()->ToggleAppList(NULL
);
448 void HandleToggleFullscreen(const ui::Accelerator
& accelerator
) {
449 if (accelerator
.key_code() == ui::VKEY_MEDIA_LAUNCH_APP2
)
450 base::RecordAction(UserMetricsAction("Accel_Fullscreen_F4"));
451 accelerators::ToggleFullscreen();
454 void HandleToggleOverview() {
455 base::RecordAction(base::UserMetricsAction("Accel_Overview_F5"));
456 Shell::GetInstance()->window_selector_controller()->ToggleOverview();
459 bool CanHandleWindowSnapOrDock() {
460 wm::WindowState
* window_state
= wm::GetActiveWindowState();
461 // Disable window snapping shortcut key for full screen window due to
462 // http://crbug.com/135487.
463 return (window_state
&& window_state
->IsUserPositionable() &&
464 !window_state
->IsFullscreen());
467 void HandleWindowSnapOrDock(AcceleratorAction action
) {
468 if (action
== WINDOW_CYCLE_SNAP_DOCK_LEFT
)
469 base::RecordAction(UserMetricsAction("Accel_Window_Snap_Left"));
471 base::RecordAction(UserMetricsAction("Accel_Window_Snap_Right"));
473 const wm::WMEvent
event(action
== WINDOW_CYCLE_SNAP_DOCK_LEFT
?
474 wm::WM_EVENT_CYCLE_SNAP_DOCK_LEFT
:
475 wm::WM_EVENT_CYCLE_SNAP_DOCK_RIGHT
);
476 wm::GetActiveWindowState()->OnWMEvent(&event
);
479 void HandleWindowMinimize() {
481 base::UserMetricsAction("Accel_Toggle_Minimized_Minus"));
482 accelerators::ToggleMinimized();
485 bool CanHandlePositionCenter() {
486 // Docked windows do not support centering.
487 wm::WindowState
* window_state
= wm::GetActiveWindowState();
488 return (window_state
&& !window_state
->IsDocked());
491 void HandlePositionCenter() {
492 base::RecordAction(UserMetricsAction("Accel_Window_Position_Center"));
493 wm::CenterWindow(wm::GetActiveWindow());
496 #if defined(OS_CHROMEOS)
497 void HandleBrightnessDown(BrightnessControlDelegate
* delegate
,
498 const ui::Accelerator
& accelerator
) {
500 delegate
->HandleBrightnessDown(accelerator
);
503 void HandleBrightnessUp(BrightnessControlDelegate
* delegate
,
504 const ui::Accelerator
& accelerator
) {
506 delegate
->HandleBrightnessUp(accelerator
);
509 bool CanHandleDisableCapsLock(const ui::Accelerator
& previous_accelerator
) {
510 ui::KeyboardCode previous_key_code
= previous_accelerator
.key_code();
511 if (previous_accelerator
.type() == ui::ET_KEY_RELEASED
||
512 (previous_key_code
!= ui::VKEY_LSHIFT
&&
513 previous_key_code
!= ui::VKEY_SHIFT
&&
514 previous_key_code
!= ui::VKEY_RSHIFT
)) {
515 // If something else was pressed between the Shift key being pressed
516 // and released, then ignore the release of the Shift key.
519 chromeos::input_method::InputMethodManager
* ime
=
520 chromeos::input_method::InputMethodManager::Get();
521 chromeos::input_method::ImeKeyboard
* keyboard
=
522 ime
? ime
->GetImeKeyboard() : NULL
;
523 return (keyboard
&& keyboard
->CapsLockIsEnabled());
526 void HandleDisableCapsLock() {
527 base::RecordAction(UserMetricsAction("Accel_Disable_Caps_Lock"));
528 chromeos::input_method::InputMethodManager
* ime
=
529 chromeos::input_method::InputMethodManager::Get();
530 ime
->GetImeKeyboard()->SetCapsLockEnabled(false);
533 void HandleKeyboardBrightnessDown(KeyboardBrightnessControlDelegate
* delegate
,
534 const ui::Accelerator
& accelerator
) {
536 delegate
->HandleKeyboardBrightnessDown(accelerator
);
539 void HandleKeyboardBrightnessUp(KeyboardBrightnessControlDelegate
* delegate
,
540 const ui::Accelerator
& accelerator
) {
542 delegate
->HandleKeyboardBrightnessUp(accelerator
);
546 base::RecordAction(UserMetricsAction("Accel_LockScreen_L"));
547 Shell::GetInstance()->session_state_delegate()->LockScreen();
551 base::RecordAction(UserMetricsAction("Accel_Open_Crosh"));
553 Shell::GetInstance()->new_window_delegate()->OpenCrosh();
556 void HandleFileManager() {
557 base::RecordAction(UserMetricsAction("Accel_Open_File_Manager"));
559 Shell::GetInstance()->new_window_delegate()->OpenFileManager();
562 void HandleGetHelp() {
563 Shell::GetInstance()->new_window_delegate()->OpenGetHelp();
566 bool CanHandleSilenceSpokenFeedback() {
567 AccessibilityDelegate
* delegate
=
568 Shell::GetInstance()->accessibility_delegate();
569 return delegate
->IsSpokenFeedbackEnabled();
572 void HandleSilenceSpokenFeedback() {
573 base::RecordAction(UserMetricsAction("Accel_Silence_Spoken_Feedback"));
574 Shell::GetInstance()->accessibility_delegate()->SilenceSpokenFeedback();
577 void HandleSwapPrimaryDisplay() {
578 base::RecordAction(UserMetricsAction("Accel_Swap_Primary_Display"));
579 Shell::GetInstance()->window_tree_host_manager()->SwapPrimaryDisplay();
582 bool CanHandleCycleUser() {
583 Shell
* shell
= Shell::GetInstance();
584 return shell
->delegate()->IsMultiProfilesEnabled() &&
585 shell
->session_state_delegate()->NumberOfLoggedInUsers() > 1;
588 void HandleCycleUser(SessionStateDelegate::CycleUser cycle_user
) {
589 MultiProfileUMA::RecordSwitchActiveUser(
590 MultiProfileUMA::SWITCH_ACTIVE_USER_BY_ACCELERATOR
);
591 switch (cycle_user
) {
592 case SessionStateDelegate::CYCLE_TO_NEXT_USER
:
593 base::RecordAction(UserMetricsAction("Accel_Switch_To_Next_User"));
595 case SessionStateDelegate::CYCLE_TO_PREVIOUS_USER
:
596 base::RecordAction(UserMetricsAction("Accel_Switch_To_Previous_User"));
599 Shell::GetInstance()->session_state_delegate()->CycleActiveUser(cycle_user
);
602 bool CanHandleToggleCapsLock(const ui::Accelerator
& accelerator
,
603 const ui::Accelerator
& previous_accelerator
) {
604 if (accelerator
.key_code() == ui::VKEY_LWIN
) {
605 // If something else was pressed between the Search key (LWIN)
606 // being pressed and released, then ignore the release of the
608 // TODO(danakj): Releasing Alt first breaks this: crbug.com/166495
609 if (previous_accelerator
.type() == ui::ET_KEY_RELEASED
||
610 previous_accelerator
.key_code() != ui::VKEY_LWIN
)
613 chromeos::input_method::InputMethodManager
* ime
=
614 chromeos::input_method::InputMethodManager::Get();
615 return ime
&& ime
->GetImeKeyboard();
618 void HandleToggleCapsLock() {
619 base::RecordAction(UserMetricsAction("Accel_Toggle_Caps_Lock"));
620 chromeos::input_method::InputMethodManager
* ime
=
621 chromeos::input_method::InputMethodManager::Get();
622 chromeos::input_method::ImeKeyboard
* keyboard
= ime
->GetImeKeyboard();
623 keyboard
->SetCapsLockEnabled(!keyboard
->CapsLockIsEnabled());
626 void HandleToggleMirrorMode() {
627 base::RecordAction(UserMetricsAction("Accel_Toggle_Mirror_Mode"));
628 Shell::GetInstance()->window_tree_host_manager()->ToggleMirrorMode();
631 void HandleToggleSpokenFeedback() {
632 base::RecordAction(UserMetricsAction("Accel_Toggle_Spoken_Feedback"));
634 Shell::GetInstance()->accessibility_delegate()->
635 ToggleSpokenFeedback(ui::A11Y_NOTIFICATION_SHOW
);
638 bool CanHandleToggleTouchViewTesting() {
639 return base::CommandLine::ForCurrentProcess()->HasSwitch(
640 switches::kAshEnableTouchViewTesting
);
643 void HandleToggleTouchViewTesting() {
644 // TODO(skuhne): This is only temporary! Remove this!
645 MaximizeModeController
* controller
= Shell::GetInstance()->
646 maximize_mode_controller();
647 controller
->EnableMaximizeModeWindowManager(
648 !controller
->IsMaximizeModeWindowManagerEnabled());
651 bool CanHandleTouchHud() {
652 return RootWindowController::ForTargetRootWindow()->touch_hud_debug();
655 void HandleTouchHudClear() {
656 RootWindowController::ForTargetRootWindow()->touch_hud_debug()->Clear();
659 void HandleTouchHudModeChange() {
660 RootWindowController
* controller
=
661 RootWindowController::ForTargetRootWindow();
662 controller
->touch_hud_debug()->ChangeToNextMode();
665 void HandleVolumeDown(const ui::Accelerator
& accelerator
) {
666 VolumeControlDelegate
* volume_delegate
=
667 Shell::GetInstance()->system_tray_delegate()->GetVolumeControlDelegate();
669 volume_delegate
->HandleVolumeDown(accelerator
);
672 void HandleVolumeMute(const ui::Accelerator
& accelerator
) {
673 VolumeControlDelegate
* volume_delegate
=
674 Shell::GetInstance()->system_tray_delegate()->GetVolumeControlDelegate();
676 volume_delegate
->HandleVolumeMute(accelerator
);
679 void HandleVolumeUp(const ui::Accelerator
& accelerator
) {
680 VolumeControlDelegate
* volume_delegate
=
681 Shell::GetInstance()->system_tray_delegate()->GetVolumeControlDelegate();
683 volume_delegate
->HandleVolumeUp(accelerator
);
686 #endif // defined(OS_CHROMEOS)
690 ////////////////////////////////////////////////////////////////////////////////
691 // AcceleratorController, public:
693 AcceleratorController::AcceleratorController()
694 : accelerator_manager_(new ui::AcceleratorManager
),
695 accelerator_history_(new ui::AcceleratorHistory
) {
699 AcceleratorController::~AcceleratorController() {
702 void AcceleratorController::Register(const ui::Accelerator
& accelerator
,
703 ui::AcceleratorTarget
* target
) {
704 accelerator_manager_
->Register(accelerator
,
705 ui::AcceleratorManager::kNormalPriority
,
709 void AcceleratorController::Unregister(const ui::Accelerator
& accelerator
,
710 ui::AcceleratorTarget
* target
) {
711 accelerator_manager_
->Unregister(accelerator
, target
);
714 void AcceleratorController::UnregisterAll(ui::AcceleratorTarget
* target
) {
715 accelerator_manager_
->UnregisterAll(target
);
718 bool AcceleratorController::Process(const ui::Accelerator
& accelerator
) {
719 if (ime_control_delegate_
) {
720 return accelerator_manager_
->Process(
721 ime_control_delegate_
->RemapAccelerator(accelerator
));
723 return accelerator_manager_
->Process(accelerator
);
726 bool AcceleratorController::IsRegistered(
727 const ui::Accelerator
& accelerator
) const {
728 return accelerator_manager_
->GetCurrentTarget(accelerator
) != NULL
;
731 bool AcceleratorController::IsPreferred(
732 const ui::Accelerator
& accelerator
) const {
733 const ui::Accelerator remapped_accelerator
= ime_control_delegate_
.get() ?
734 ime_control_delegate_
->RemapAccelerator(accelerator
) : accelerator
;
736 std::map
<ui::Accelerator
, AcceleratorAction
>::const_iterator iter
=
737 accelerators_
.find(remapped_accelerator
);
738 if (iter
== accelerators_
.end())
739 return false; // not an accelerator.
741 return preferred_actions_
.find(iter
->second
) != preferred_actions_
.end();
744 bool AcceleratorController::IsReserved(
745 const ui::Accelerator
& accelerator
) const {
746 const ui::Accelerator remapped_accelerator
= ime_control_delegate_
.get() ?
747 ime_control_delegate_
->RemapAccelerator(accelerator
) : accelerator
;
749 std::map
<ui::Accelerator
, AcceleratorAction
>::const_iterator iter
=
750 accelerators_
.find(remapped_accelerator
);
751 if (iter
== accelerators_
.end())
752 return false; // not an accelerator.
754 return reserved_actions_
.find(iter
->second
) != reserved_actions_
.end();
757 bool AcceleratorController::IsDeprecated(
758 const ui::Accelerator
& accelerator
) const {
759 return deprecated_accelerators_
.count(accelerator
) != 0;
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 RegisterDeprecatedAccelerators();
839 if (debug::DebugAcceleratorsEnabled()) {
840 RegisterAccelerators(kDebugAcceleratorData
, kDebugAcceleratorDataLength
);
841 // All debug accelerators are reserved.
842 for (size_t i
= 0; i
< kDebugAcceleratorDataLength
; ++i
)
843 reserved_actions_
.insert(kDebugAcceleratorData
[i
].action
);
846 #if defined(OS_CHROMEOS)
847 keyboard_brightness_control_delegate_
.reset(
848 new KeyboardBrightnessController());
852 void AcceleratorController::RegisterAccelerators(
853 const AcceleratorData accelerators
[],
854 size_t accelerators_length
) {
855 for (size_t i
= 0; i
< accelerators_length
; ++i
) {
856 ui::Accelerator accelerator
=
857 CreateAccelerator(accelerators
[i
].keycode
, accelerators
[i
].modifiers
,
858 accelerators
[i
].trigger_on_press
);
859 Register(accelerator
, this);
860 accelerators_
.insert(
861 std::make_pair(accelerator
, accelerators
[i
].action
));
865 void AcceleratorController::RegisterDeprecatedAccelerators() {
866 #if defined(OS_CHROMEOS)
867 for (size_t i
= 0; i
< kDeprecatedAcceleratorsLength
; ++i
) {
868 const DeprecatedAcceleratorData
* data
= &kDeprecatedAccelerators
[i
];
869 const AcceleratorAction action
= data
->deprecated_accelerator
.action
;
870 const ui::Accelerator deprecated_accelerator
=
871 CreateAccelerator(data
->deprecated_accelerator
.keycode
,
872 data
->deprecated_accelerator
.modifiers
,
873 data
->deprecated_accelerator
.trigger_on_press
);
875 Register(deprecated_accelerator
, this);
876 actions_with_deprecations_
[action
] = data
;
877 accelerators_
[deprecated_accelerator
] = action
;
878 deprecated_accelerators_
.insert(deprecated_accelerator
);
880 #endif // defined(OS_CHROMEOS)
883 bool AcceleratorController::CanPerformAction(
884 AcceleratorAction action
,
885 const ui::Accelerator
& accelerator
) {
886 if (nonrepeatable_actions_
.find(action
) != nonrepeatable_actions_
.end() &&
887 accelerator
.IsRepeat()) {
891 // Handling the deprecated accelerators.
892 auto itr
= actions_with_deprecations_
.find(action
);
893 if (itr
!= actions_with_deprecations_
.end()) {
894 const DeprecatedAcceleratorData
* data
= itr
->second
;
895 if (deprecated_accelerators_
.count(accelerator
)) {
896 // This accelerator has been deprecated and should be treated according
897 // to its |DeprecatedAcceleratorData|.
900 RecordUmaHistogram(data
->uma_histogram_name
, DEPRECATED_USED
);
902 // We always display the notification as long as this entry exists.
903 ShowDeprecatedAcceleratorNotification(data
->uma_histogram_name
,
904 data
->notification_message_id
);
906 if (!data
->deprecated_enabled
)
909 // This is a new accelerator replacing the old deprecated one.
910 // Record UMA stats and proceed normally.
911 RecordUmaHistogram(data
->uma_histogram_name
, NEW_USED
);
915 AcceleratorProcessingRestriction restriction
=
916 GetAcceleratorProcessingRestriction(action
);
917 if (restriction
!= RESTRICTION_NONE
)
918 return restriction
== RESTRICTION_PREVENT_PROCESSING_AND_PROPAGATION
;
920 const ui::Accelerator
& previous_accelerator
=
921 accelerator_history_
->previous_accelerator();
923 // True should be returned if running |action| does something. Otherwise,
924 // false should be returned to give the web contents a chance at handling the
927 case DEBUG_PRINT_LAYER_HIERARCHY
:
928 case DEBUG_PRINT_VIEW_HIERARCHY
:
929 case DEBUG_PRINT_WINDOW_HIERARCHY
:
930 case DEBUG_TOGGLE_DESKTOP_BACKGROUND_MODE
:
931 case DEBUG_TOGGLE_DEVICE_SCALE_FACTOR
:
932 case DEBUG_TOGGLE_ROOT_WINDOW_FULL_SCREEN
:
933 case DEBUG_TOGGLE_SHOW_DEBUG_BORDERS
:
934 case DEBUG_TOGGLE_SHOW_FPS_COUNTER
:
935 case DEBUG_TOGGLE_SHOW_PAINT_RECTS
:
936 return debug::DebugAcceleratorsEnabled();
937 case MAGNIFY_SCREEN_ZOOM_IN
:
938 case MAGNIFY_SCREEN_ZOOM_OUT
:
939 return CanHandleMagnifyScreen();
940 case NEW_INCOGNITO_WINDOW
:
941 return CanHandleNewIncognitoWindow();
943 return CanHandleNextIme(ime_control_delegate_
.get(),
944 previous_accelerator
);
946 return CanHandlePreviousIme(ime_control_delegate_
.get());
950 return accelerators::IsInternalDisplayZoomEnabled();
951 case SHOW_MESSAGE_CENTER_BUBBLE
:
952 return CanHandleShowMessageCenterBubble();
954 return CanHandleSwitchIme(ime_control_delegate_
.get(), accelerator
);
955 case TOGGLE_APP_LIST
:
956 return CanHandleToggleAppList(accelerator
, previous_accelerator
);
957 case WINDOW_CYCLE_SNAP_DOCK_LEFT
:
958 case WINDOW_CYCLE_SNAP_DOCK_RIGHT
:
959 return CanHandleWindowSnapOrDock();
960 case WINDOW_POSITION_CENTER
:
961 return CanHandlePositionCenter();
962 #if defined(OS_CHROMEOS)
963 case DEBUG_ADD_REMOVE_DISPLAY
:
964 case DEBUG_TOGGLE_UNIFIED_DESKTOP
:
965 return debug::DebugAcceleratorsEnabled();
966 case DISABLE_CAPS_LOCK
:
967 return CanHandleDisableCapsLock(previous_accelerator
);
968 case SILENCE_SPOKEN_FEEDBACK
:
969 return CanHandleSilenceSpokenFeedback();
970 case SWITCH_TO_PREVIOUS_USER
:
971 case SWITCH_TO_NEXT_USER
:
972 return CanHandleCycleUser();
973 case TOGGLE_CAPS_LOCK
:
974 return CanHandleToggleCapsLock(accelerator
, previous_accelerator
);
975 case TOGGLE_TOUCH_VIEW_TESTING
:
976 return CanHandleToggleTouchViewTesting();
977 case TOUCH_HUD_CLEAR
:
978 case TOUCH_HUD_MODE_CHANGE
:
979 return CanHandleTouchHud();
982 case CYCLE_BACKWARD_MRU
:
983 case CYCLE_FORWARD_MRU
:
985 case FOCUS_NEXT_PANE
:
986 case FOCUS_PREVIOUS_PANE
:
996 case LAUNCH_LAST_APP
:
997 case MEDIA_NEXT_TRACK
:
998 case MEDIA_PLAY_PAUSE
:
999 case MEDIA_PREV_TRACK
:
1002 case OPEN_FEEDBACK_PAGE
:
1003 case PRINT_UI_HIERARCHIES
:
1007 case SHOW_KEYBOARD_OVERLAY
:
1008 case SHOW_SYSTEM_TRAY_BUBBLE
:
1009 case SHOW_TASK_MANAGER
:
1010 case TAKE_PARTIAL_SCREENSHOT
:
1011 case TAKE_SCREENSHOT
:
1012 case TOGGLE_FULLSCREEN
:
1013 case TOGGLE_MAXIMIZED
:
1014 case TOGGLE_OVERVIEW
:
1015 case WINDOW_MINIMIZE
:
1016 #if defined(OS_CHROMEOS)
1017 case BRIGHTNESS_DOWN
:
1019 case DISABLE_GPU_WATCHDOG
:
1020 case KEYBOARD_BRIGHTNESS_DOWN
:
1021 case KEYBOARD_BRIGHTNESS_UP
:
1026 case OPEN_FILE_MANAGER
:
1029 case POWER_RELEASED
:
1030 case SWAP_PRIMARY_DISPLAY
:
1031 case TOGGLE_MIRROR_MODE
:
1032 case TOGGLE_SPOKEN_FEEDBACK
:
1034 case TOUCH_HUD_PROJECTION_TOGGLE
:
1039 case DUMMY_FOR_RESERVED
:
1046 void AcceleratorController::PerformAction(AcceleratorAction action
,
1047 const ui::Accelerator
& accelerator
) {
1048 AcceleratorProcessingRestriction restriction
=
1049 GetAcceleratorProcessingRestriction(action
);
1050 if (restriction
!= RESTRICTION_NONE
)
1053 // If your accelerator invokes more than one line of code, please either
1054 // implement it in your module's controller code (like TOGGLE_MIRROR_MODE
1055 // below) or pull it into a HandleFoo() function above.
1057 case CYCLE_BACKWARD_MRU
:
1058 HandleCycleBackwardMRU(accelerator
);
1060 case CYCLE_FORWARD_MRU
:
1061 HandleCycleForwardMRU(accelerator
);
1063 case DEBUG_PRINT_LAYER_HIERARCHY
:
1064 case DEBUG_PRINT_VIEW_HIERARCHY
:
1065 case DEBUG_PRINT_WINDOW_HIERARCHY
:
1066 case DEBUG_TOGGLE_DESKTOP_BACKGROUND_MODE
:
1067 case DEBUG_TOGGLE_DEVICE_SCALE_FACTOR
:
1068 case DEBUG_TOGGLE_ROOT_WINDOW_FULL_SCREEN
:
1069 case DEBUG_TOGGLE_SHOW_DEBUG_BORDERS
:
1070 case DEBUG_TOGGLE_SHOW_FPS_COUNTER
:
1071 case DEBUG_TOGGLE_SHOW_PAINT_RECTS
:
1072 debug::PerformDebugActionIfEnabled(action
);
1075 // UMA metrics are recorded in the handler.
1076 exit_warning_handler_
.HandleAccelerator();
1078 case FOCUS_NEXT_PANE
:
1079 HandleRotatePaneFocus(Shell::FORWARD
);
1081 case FOCUS_PREVIOUS_PANE
:
1082 HandleRotatePaneFocus(Shell::BACKWARD
);
1088 HandleLaunchAppN(0);
1091 HandleLaunchAppN(1);
1094 HandleLaunchAppN(2);
1097 HandleLaunchAppN(3);
1100 HandleLaunchAppN(4);
1103 HandleLaunchAppN(5);
1106 HandleLaunchAppN(6);
1109 HandleLaunchAppN(7);
1111 case LAUNCH_LAST_APP
:
1112 HandleLaunchLastApp();
1114 case MAGNIFY_SCREEN_ZOOM_IN
:
1115 HandleMagnifyScreen(1);
1117 case MAGNIFY_SCREEN_ZOOM_OUT
:
1118 HandleMagnifyScreen(-1);
1120 case MEDIA_NEXT_TRACK
:
1121 HandleMediaNextTrack();
1123 case MEDIA_PLAY_PAUSE
:
1124 HandleMediaPlayPause();
1126 case MEDIA_PREV_TRACK
:
1127 HandleMediaPrevTrack();
1129 case NEW_INCOGNITO_WINDOW
:
1130 HandleNewIncognitoWindow();
1133 HandleNewTab(accelerator
);
1139 HandleNextIme(ime_control_delegate_
.get());
1141 case OPEN_FEEDBACK_PAGE
:
1142 HandleOpenFeedbackPage();
1145 HandlePreviousIme(ime_control_delegate_
.get(), accelerator
);
1147 case PRINT_UI_HIERARCHIES
:
1148 debug::PrintUIHierarchies();
1154 HandleRotateScreen();
1157 HandleRotateActiveWindow();
1160 accelerators::ZoomInternalDisplay(false /* down */);
1162 case SCALE_UI_RESET
:
1163 accelerators::ResetInternalDisplayZoom();
1166 accelerators::ZoomInternalDisplay(true /* up */);
1168 case SHOW_KEYBOARD_OVERLAY
:
1169 HandleShowKeyboardOverlay();
1171 case SHOW_MESSAGE_CENTER_BUBBLE
:
1172 HandleShowMessageCenterBubble();
1174 case SHOW_SYSTEM_TRAY_BUBBLE
:
1175 HandleShowSystemTrayBubble();
1177 case SHOW_TASK_MANAGER
:
1178 HandleShowTaskManager();
1181 HandleSwitchIme(ime_control_delegate_
.get(), accelerator
);
1183 case TAKE_PARTIAL_SCREENSHOT
:
1184 HandleTakePartialScreenshot(screenshot_delegate_
.get());
1186 case TAKE_SCREENSHOT
:
1187 HandleTakeScreenshot(screenshot_delegate_
.get());
1189 case TOGGLE_APP_LIST
:
1190 HandleToggleAppList(accelerator
);
1192 case TOGGLE_FULLSCREEN
:
1193 HandleToggleFullscreen(accelerator
);
1195 case TOGGLE_MAXIMIZED
:
1196 accelerators::ToggleMaximized();
1198 case TOGGLE_OVERVIEW
:
1199 HandleToggleOverview();
1201 case WINDOW_CYCLE_SNAP_DOCK_LEFT
:
1202 case WINDOW_CYCLE_SNAP_DOCK_RIGHT
:
1203 HandleWindowSnapOrDock(action
);
1205 case WINDOW_MINIMIZE
:
1206 HandleWindowMinimize();
1208 case WINDOW_POSITION_CENTER
:
1209 HandlePositionCenter();
1211 #if defined(OS_CHROMEOS)
1212 case BRIGHTNESS_DOWN
:
1213 HandleBrightnessDown(brightness_control_delegate_
.get(), accelerator
);
1216 HandleBrightnessUp(brightness_control_delegate_
.get(), accelerator
);
1218 case DEBUG_ADD_REMOVE_DISPLAY
:
1219 debug::PerformDebugActionIfEnabled(action
);
1221 case DEBUG_TOGGLE_UNIFIED_DESKTOP
:
1222 debug::PerformDebugActionIfEnabled(action
);
1224 case DISABLE_CAPS_LOCK
:
1225 HandleDisableCapsLock();
1227 case DISABLE_GPU_WATCHDOG
:
1228 Shell::GetInstance()->gpu_support()->DisableGpuWatchdog();
1230 case KEYBOARD_BRIGHTNESS_DOWN
:
1231 HandleKeyboardBrightnessDown(keyboard_brightness_control_delegate_
.get(),
1234 case KEYBOARD_BRIGHTNESS_UP
:
1235 HandleKeyboardBrightnessUp(keyboard_brightness_control_delegate_
.get(),
1240 Shell::GetInstance()->power_button_controller()->
1241 OnLockButtonEvent(action
== LOCK_PRESSED
, base::TimeTicks());
1249 case OPEN_FILE_MANAGER
:
1250 HandleFileManager();
1255 case POWER_PRESSED
: // fallthrough
1256 case POWER_RELEASED
:
1257 if (!base::SysInfo::IsRunningOnChromeOS()) {
1258 // There is no powerd, the Chrome OS power manager, in linux desktop,
1259 // so call the PowerButtonController here.
1260 Shell::GetInstance()->power_button_controller()->
1261 OnPowerButtonEvent(action
== POWER_PRESSED
, base::TimeTicks());
1263 // We don't do anything with these at present on the device,
1264 // (power button events are reported to us from powerm via
1265 // D-BUS), but we consume them to prevent them from getting
1266 // passed to apps -- see http://crbug.com/146609.
1268 case SILENCE_SPOKEN_FEEDBACK
:
1269 HandleSilenceSpokenFeedback();
1271 case SWAP_PRIMARY_DISPLAY
:
1272 HandleSwapPrimaryDisplay();
1274 case SWITCH_TO_NEXT_USER
:
1275 HandleCycleUser(SessionStateDelegate::CYCLE_TO_NEXT_USER
);
1277 case SWITCH_TO_PREVIOUS_USER
:
1278 HandleCycleUser(SessionStateDelegate::CYCLE_TO_PREVIOUS_USER
);
1280 case TOGGLE_CAPS_LOCK
:
1281 HandleToggleCapsLock();
1283 case TOGGLE_MIRROR_MODE
:
1284 HandleToggleMirrorMode();
1286 case TOGGLE_SPOKEN_FEEDBACK
:
1287 HandleToggleSpokenFeedback();
1289 case TOGGLE_TOUCH_VIEW_TESTING
:
1290 HandleToggleTouchViewTesting();
1293 Shell::GetInstance()->system_tray_notifier()->NotifyRequestToggleWifi();
1295 case TOUCH_HUD_CLEAR
:
1296 HandleTouchHudClear();
1298 case TOUCH_HUD_MODE_CHANGE
:
1299 HandleTouchHudModeChange();
1301 case TOUCH_HUD_PROJECTION_TOGGLE
:
1302 accelerators::ToggleTouchHudProjection();
1305 HandleVolumeDown(accelerator
);
1308 HandleVolumeMute(accelerator
);
1311 HandleVolumeUp(accelerator
);
1314 case DUMMY_FOR_RESERVED
:
1321 bool AcceleratorController::ShouldActionConsumeKeyEvent(
1322 AcceleratorAction action
) {
1323 #if defined(OS_CHROMEOS)
1324 if (action
== SILENCE_SPOKEN_FEEDBACK
)
1328 // Adding new exceptions is *STRONGLY* discouraged.
1332 AcceleratorController::AcceleratorProcessingRestriction
1333 AcceleratorController::GetAcceleratorProcessingRestriction(int action
) {
1334 ash::Shell
* shell
= ash::Shell::GetInstance();
1335 if (!shell
->session_state_delegate()->IsActiveUserSessionStarted() &&
1336 actions_allowed_at_login_screen_
.find(action
) ==
1337 actions_allowed_at_login_screen_
.end()) {
1338 return RESTRICTION_PREVENT_PROCESSING
;
1340 if (shell
->session_state_delegate()->IsScreenLocked() &&
1341 actions_allowed_at_lock_screen_
.find(action
) ==
1342 actions_allowed_at_lock_screen_
.end()) {
1343 return RESTRICTION_PREVENT_PROCESSING
;
1345 if (shell
->delegate()->IsRunningInForcedAppMode() &&
1346 actions_allowed_in_app_mode_
.find(action
) ==
1347 actions_allowed_in_app_mode_
.end()) {
1348 return RESTRICTION_PREVENT_PROCESSING
;
1350 if (shell
->IsSystemModalWindowOpen() &&
1351 actions_allowed_at_modal_window_
.find(action
) ==
1352 actions_allowed_at_modal_window_
.end()) {
1353 // Note we prevent the shortcut from propagating so it will not
1354 // be passed to the modal window. This is important for things like
1355 // Alt+Tab that would cause an undesired effect in the modal window by
1356 // cycling through its window elements.
1357 return RESTRICTION_PREVENT_PROCESSING_AND_PROPAGATION
;
1359 if (shell
->mru_window_tracker()->BuildMruWindowList().empty() &&
1360 actions_needing_window_
.find(action
) != actions_needing_window_
.end()) {
1361 Shell::GetInstance()->accessibility_delegate()->TriggerAccessibilityAlert(
1362 ui::A11Y_ALERT_WINDOW_NEEDED
);
1363 return RESTRICTION_PREVENT_PROCESSING_AND_PROPAGATION
;
1365 return RESTRICTION_NONE
;
1368 void AcceleratorController::SetKeyboardBrightnessControlDelegate(
1369 scoped_ptr
<KeyboardBrightnessControlDelegate
>
1370 keyboard_brightness_control_delegate
) {
1371 keyboard_brightness_control_delegate_
=
1372 keyboard_brightness_control_delegate
.Pass();