15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/accelerators/accelerator_controller.h"
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <algorithm>
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <cmath>
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <string>
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)#include "ash/accelerators/accelerator_commands.h"
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/accelerators/accelerator_table.h"
1368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)#include "ash/accelerators/debug_commands.h"
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/ash_switches.h"
15c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "ash/debug.h"
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/display/display_controller.h"
172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ash/display/display_manager.h"
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/focus_cycler.h"
195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ash/gpu_support.h"
20a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch#include "ash/host/ash_window_tree_host.h"
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/ime_control_delegate.h"
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/magnifier/magnification_controller.h"
232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ash/magnifier/partial_magnification_controller.h"
240f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)#include "ash/media_delegate.h"
254e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "ash/multi_profile_uma.h"
261e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "ash/new_window_delegate.h"
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/root_window_controller.h"
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/rotator/screen_rotation.h"
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/screenshot_delegate.h"
305c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu#include "ash/session/session_state_delegate.h"
315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ash/shelf/shelf.h"
32a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "ash/shelf/shelf_delegate.h"
33f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "ash/shelf/shelf_model.h"
342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ash/shelf/shelf_widget.h"
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/shell.h"
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/shell_delegate.h"
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/shell_window_ids.h"
384e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "ash/system/brightness_control_delegate.h"
395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/system/keyboard_brightness/keyboard_brightness_control_delegate.h"
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/system/status_area_widget.h"
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/system/tray/system_tray.h"
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/system/tray/system_tray_delegate.h"
4390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "ash/system/tray/system_tray_notifier.h"
442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ash/system/web_notification/web_notification_tray.h"
45eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "ash/touch/touch_hud_debug.h"
465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/volume_control_delegate.h"
47f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)#include "ash/wm/maximize_mode/maximize_mode_controller.h"
48f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "ash/wm/mru_window_tracker.h"
493551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "ash/wm/overview/window_selector_controller.h"
505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/wm/partial_screenshot_view.h"
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/wm/power_button_controller.h"
52cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "ash/wm/window_cycle_controller.h"
5368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)#include "ash/wm/window_state.h"
545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/wm/window_util.h"
55a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "ash/wm/wm_event.h"
565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/bind.h"
575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/command_line.h"
585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "base/metrics/user_metrics.h"
595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/aura/env.h"
60a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "ui/aura/window_event_dispatcher.h"
615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/base/accelerators/accelerator.h"
625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/base/accelerators/accelerator_manager.h"
635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/compositor/debug_utils.h"
645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/compositor/layer.h"
655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/compositor/layer_animation_sequence.h"
665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/compositor/layer_animator.h"
67d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#include "ui/events/event.h"
68d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#include "ui/events/keycodes/keyboard_codes.h"
695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/gfx/screen.h"
70c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "ui/views/controls/webview/webview.h"
715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/views/debug_utils.h"
725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/views/widget/widget.h"
735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined(OS_CHROMEOS)
755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/system/chromeos/keyboard_brightness_controller.h"
764e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "base/sys_info.h"
77a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch#include "chromeos/ime/ime_keyboard.h"
78a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "chromeos/ime/input_method_manager.h"
795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif  // defined(OS_CHROMEOS)
805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace ash {
825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace {
835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)using base::UserMetricsAction;
852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool DebugShortcutsEnabled() {
875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined(NDEBUG)
885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return CommandLine::ForCurrentProcess()->HasSwitch(
895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)          switches::kAshDebugShortcuts);
905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#else
915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return true;
925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
95a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)bool HandleAccessibleFocusCycle(bool reverse) {
96a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  if (reverse) {
975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    base::RecordAction(UserMetricsAction("Accel_Accessible_Focus_Previous"));
98a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  } else {
995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    base::RecordAction(UserMetricsAction("Accel_Accessible_Focus_Next"));
100a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  }
101a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
102a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  if (!Shell::GetInstance()->accessibility_delegate()->
103a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      IsSpokenFeedbackEnabled()) {
104a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    return false;
105a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  }
106a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  aura::Window* active_window = ash::wm::GetActiveWindow();
107a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  if (!active_window)
108a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    return false;
109a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  views::Widget* widget =
110a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      views::Widget::GetWidgetForNativeWindow(active_window);
111a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  if (!widget)
112a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    return false;
113a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  views::FocusManager* focus_manager = widget->GetFocusManager();
114a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  if (!focus_manager)
115a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    return false;
116a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  views::View* view = focus_manager->GetFocusedView();
117a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  if (!view)
118a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    return false;
119a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  if (!strcmp(view->GetClassName(), views::WebView::kViewClassName))
120a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    return false;
121a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
122a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  focus_manager->AdvanceFocus(reverse);
123a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  return true;
124a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)}
125a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
126a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)bool HandleCycleBackwardMRU(const ui::Accelerator& accelerator) {
12758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  if (accelerator.key_code() == ui::VKEY_TAB)
1285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    base::RecordAction(base::UserMetricsAction("Accel_PrevWindow_Tab"));
12958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
130cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  Shell::GetInstance()->window_cycle_controller()->HandleCycleWindow(
131cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)      WindowCycleController::BACKWARD);
132a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  return true;
133ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch}
134ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch
135a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)bool HandleCycleForwardMRU(const ui::Accelerator& accelerator) {
13658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  if (accelerator.key_code() == ui::VKEY_TAB)
1375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    base::RecordAction(base::UserMetricsAction("Accel_NextWindow_Tab"));
13858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
139cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  Shell::GetInstance()->window_cycle_controller()->HandleCycleWindow(
140cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)      WindowCycleController::FORWARD);
141a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  return true;
142a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)}
143a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
144a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)bool ToggleOverview(const ui::Accelerator& accelerator) {
145a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  base::RecordAction(base::UserMetricsAction("Accel_Overview_F5"));
146a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  Shell::GetInstance()->window_selector_controller()->ToggleOverview();
147a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  return true;
148c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)}
149c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1501320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tuccibool HandleFocusShelf() {
151a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  Shell* shell = Shell::GetInstance();
1521320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  base::RecordAction(base::UserMetricsAction("Accel_Focus_Shelf"));
153a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  return shell->focus_cycler()->FocusWidget(
1545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      Shelf::ForPrimaryDisplay()->shelf_widget());
155a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)}
156a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
157a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)bool HandleLaunchAppN(int n) {
1585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  base::RecordAction(UserMetricsAction("Accel_Launch_App"));
1595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  Shelf::ForPrimaryDisplay()->LaunchAppIndexAt(n);
160c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  return true;
161c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)}
162c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
163a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)bool HandleLaunchLastApp() {
1645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  base::RecordAction(UserMetricsAction("Accel_Launch_Last_App"));
1655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  Shelf::ForPrimaryDisplay()->LaunchAppIndexAt(-1);
166a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  return true;
1675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
1685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
169a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// Magnify the screen
170a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)bool HandleMagnifyScreen(int delta_index) {
171a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  if (ash::Shell::GetInstance()->magnification_controller()->IsEnabled()) {
172a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    // TODO(yoshiki): Move the following logic to MagnificationController.
173a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    float scale =
174a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)        ash::Shell::GetInstance()->magnification_controller()->GetScale();
175a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    // Calculate rounded logarithm (base kMagnificationScaleFactor) of scale.
176a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    int scale_index =
177a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)        std::floor(std::log(scale) / std::log(kMagnificationScaleFactor) + 0.5);
178a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
179a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    int new_scale_index = std::max(0, std::min(8, scale_index + delta_index));
180a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
181a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    ash::Shell::GetInstance()->magnification_controller()->
182a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)        SetScale(std::pow(kMagnificationScaleFactor, new_scale_index), true);
183a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  } else if (ash::Shell::GetInstance()->
184a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)             partial_magnification_controller()->is_enabled()) {
185a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    float scale = delta_index > 0 ? kDefaultPartialMagnifiedScale : 1;
186a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    ash::Shell::GetInstance()->partial_magnification_controller()->
187a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)        SetScale(scale);
188a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  }
189a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
1905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return true;
1915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
1925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
193a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)bool HandleMediaNextTrack() {
194a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  Shell::GetInstance()->media_delegate()->HandleMediaNextTrack();
1955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return true;
1965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
1975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
198a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)bool HandleMediaPlayPause() {
199a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  Shell::GetInstance()->media_delegate()->HandleMediaPlayPause();
2005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return true;
2015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
203a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)bool HandleMediaPrevTrack() {
204a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  Shell::GetInstance()->media_delegate()->HandleMediaPrevTrack();
2055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return true;
2065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
208a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)bool HandleNewIncognitoWindow() {
2095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  base::RecordAction(UserMetricsAction("Accel_New_Incognito_Window"));
210a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  bool incognito_allowed =
211a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    Shell::GetInstance()->delegate()->IsIncognitoAllowed();
212a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  if (incognito_allowed)
213a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    Shell::GetInstance()->new_window_delegate()->NewWindow(
214a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)        true /* is_incognito */);
215a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  return incognito_allowed;
216a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)}
217a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
218a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)bool HandleNewTab(ui::KeyboardCode key_code) {
219a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  if (key_code == ui::VKEY_T)
2205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    base::RecordAction(base::UserMetricsAction("Accel_NewTab_T"));
221a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  Shell::GetInstance()->new_window_delegate()->NewTab();
222a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  return true;
223a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)}
224a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
225a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)bool HandleNewWindow() {
2265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  base::RecordAction(base::UserMetricsAction("Accel_New_Window"));
227a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  Shell::GetInstance()->new_window_delegate()->NewWindow(
228a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      false /* is_incognito */);
229a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  return true;
230a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)}
231a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
232116680a4aac90f2aa7413d9095a592090648e557Ben Murdochvoid HandleNextIme(ImeControlDelegate* ime_control_delegate,
233a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)                   ui::EventType previous_event_type,
234a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)                   ui::KeyboardCode previous_key_code) {
235a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // This check is necessary e.g. not to process the Shift+Alt+
236a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // ET_KEY_RELEASED accelerator for Chrome OS (see ash/accelerators/
237a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // accelerator_controller.cc) when Shift+Alt+Tab is pressed and then Tab
238a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // is released.
239a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  if (previous_event_type == ui::ET_KEY_RELEASED &&
240a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      // Workaround for crbug.com/139556. CJK IME users tend to press
241a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      // Enter (or Space) and Shift+Alt almost at the same time to commit
242a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      // an IME string and then switch from the IME to the English layout.
243a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      // This workaround allows the user to trigger NEXT_IME even if the
244a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      // user presses Shift+Alt before releasing Enter.
245a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      // TODO(nona|mazda): Fix crbug.com/139556 in a cleaner way.
246a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      previous_key_code != ui::VKEY_RETURN &&
247a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      previous_key_code != ui::VKEY_SPACE) {
248a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    // We totally ignore this accelerator.
249a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    // TODO(mazda): Fix crbug.com/158217
250116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    return;
251a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  }
2525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  base::RecordAction(UserMetricsAction("Accel_Next_Ime"));
253a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  if (ime_control_delegate)
254116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    ime_control_delegate->HandleNextIme();
255a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)}
256a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
257a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)bool HandleOpenFeedbackPage() {
2585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  base::RecordAction(UserMetricsAction("Accel_Open_Feedback_Page"));
259a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  ash::Shell::GetInstance()->new_window_delegate()->OpenFeedbackPage();
26068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  return true;
26168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)}
26268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)
263a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)bool HandlePositionCenter() {
2645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  base::RecordAction(UserMetricsAction("Accel_Window_Position_Center"));
265a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  aura::Window* window = wm::GetActiveWindow();
266a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // Docked windows do not support centering and ignore accelerator.
267a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  if (window && !wm::GetWindowState(window)->IsDocked()) {
268a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    wm::CenterWindow(window);
269a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    return true;
270a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  }
271a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  return false;
272a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)}
273a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
274a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)bool HandlePreviousIme(ImeControlDelegate* ime_control_delegate,
275a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)                       const ui::Accelerator& accelerator) {
2765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  base::RecordAction(UserMetricsAction("Accel_Previous_Ime"));
277a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  if (ime_control_delegate)
278a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    return ime_control_delegate->HandlePreviousIme(accelerator);
279a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  return false;
280a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)}
281a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
282a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)bool HandleRestoreTab() {
2835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  base::RecordAction(base::UserMetricsAction("Accel_Restore_Tab"));
284a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  Shell::GetInstance()->new_window_delegate()->RestoreTab();
285a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  return true;
286a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)}
2875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool HandleRotatePaneFocus(Shell::Direction direction) {
289c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  Shell* shell = Shell::GetInstance();
290c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  switch (direction) {
291a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    // TODO(stevet): Not sure if this is the same as IDC_FOCUS_NEXT_PANE.
292a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    case Shell::FORWARD: {
2935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      base::RecordAction(UserMetricsAction("Accel_Focus_Next_Pane"));
294c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch      shell->focus_cycler()->RotateFocus(FocusCycler::FORWARD);
295c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      break;
296a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    }
297a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    case Shell::BACKWARD: {
2985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      base::RecordAction(UserMetricsAction("Accel_Focus_Previous_Pane"));
299c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch      shell->focus_cycler()->RotateFocus(FocusCycler::BACKWARD);
300c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      break;
301a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    }
3025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
3035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return true;
3045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
3055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Rotate the active window.
3072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)bool HandleRotateActiveWindow() {
3085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  base::RecordAction(UserMetricsAction("Accel_Rotate_Window"));
3092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  aura::Window* active_window = wm::GetActiveWindow();
3102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (active_window) {
3115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // The rotation animation bases its target transform on the current
3125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // rotation and position. Since there could be an animation in progress
3135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // right now, queue this animation so when it starts it picks up a neutral
3145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // rotation and position. Use replace so we only enqueue one at a time.
3152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    active_window->layer()->GetAnimator()->
3165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        set_preemption_strategy(ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS);
3172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    active_window->layer()->GetAnimator()->StartAnimation(
3182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        new ui::LayerAnimationSequence(
3192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)            new ash::ScreenRotation(360, active_window->layer())));
3205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
3215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return true;
3225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
3235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)gfx::Display::Rotation GetNextRotation(gfx::Display::Rotation current) {
3252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  switch (current) {
3262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    case gfx::Display::ROTATE_0:
3272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      return gfx::Display::ROTATE_90;
3282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    case gfx::Display::ROTATE_90:
3292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      return gfx::Display::ROTATE_180;
3302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    case gfx::Display::ROTATE_180:
3312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      return gfx::Display::ROTATE_270;
3322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    case gfx::Display::ROTATE_270:
3332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      return gfx::Display::ROTATE_0;
3342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
3352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  NOTREACHED() << "Unknown rotation:" << current;
3362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  return gfx::Display::ROTATE_0;
3372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
3382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
339a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// Rotates the screen.
340a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)bool HandleRotateScreen() {
3415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  base::RecordAction(UserMetricsAction("Accel_Rotate_Window"));
342a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  gfx::Point point = Shell::GetScreen()->GetCursorScreenPoint();
343a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  gfx::Display display = Shell::GetScreen()->GetDisplayNearestPoint(point);
344a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  const DisplayInfo& display_info =
345a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      Shell::GetInstance()->display_manager()->GetDisplayInfo(display.id());
346a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  Shell::GetInstance()->display_manager()->SetDisplayRotation(
347a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      display.id(), GetNextRotation(display_info.rotation()));
348a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  return true;
349a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)}
350a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
351a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)bool HandleScaleReset() {
352c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  DisplayManager* display_manager = Shell::GetInstance()->display_manager();
353a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  int64 display_id = display_manager->GetDisplayIdForUIScaling();
354a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  if (display_id == gfx::Display::kInvalidDisplayID)
355a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    return false;
356a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
3575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  base::RecordAction(UserMetricsAction("Accel_Scale_Ui_Reset"));
358a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
359a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  display_manager->SetDisplayUIScale(display_id, 1.0f);
360a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  return true;
361a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)}
362a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
3632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)bool HandleScaleUI(bool up) {
364c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  DisplayManager* display_manager = Shell::GetInstance()->display_manager();
365c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  int64 display_id = display_manager->GetDisplayIdForUIScaling();
366c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  if (display_id == gfx::Display::kInvalidDisplayID)
367c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    return false;
368a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
369a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  if (up) {
3705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    base::RecordAction(UserMetricsAction("Accel_Scale_Ui_Up"));
371a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  } else {
3725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    base::RecordAction(UserMetricsAction("Accel_Scale_Ui_Down"));
373a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  }
374a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
375c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  const DisplayInfo& display_info = display_manager->GetDisplayInfo(display_id);
376c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  float next_scale = DisplayManager::GetNextUIScale(display_info, up);
377c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  display_manager->SetDisplayUIScale(display_id, next_scale);
378c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  return true;
379c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)}
380c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
381c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch#if defined(OS_CHROMEOS)
382a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)bool HandleSwapPrimaryDisplay() {
3835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  base::RecordAction(UserMetricsAction("Accel_Swap_Primary_Display"));
384a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  Shell::GetInstance()->display_controller()->SwapPrimaryDisplay();
385a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  return true;
386a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)}
387c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch#endif
388a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
389a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)bool HandleShowKeyboardOverlay() {
3905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  base::RecordAction(UserMetricsAction("Accel_Show_Keyboard_Overlay"));
391a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  ash::Shell::GetInstance()->new_window_delegate()->ShowKeyboardOverlay();
392a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
393a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  return true;
394a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)}
395a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
396a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)void HandleShowMessageCenterBubble() {
3975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  base::RecordAction(UserMetricsAction("Accel_Show_Message_Center_Bubble"));
398c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  RootWindowController* controller =
399c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch      RootWindowController::ForTargetRootWindow();
400c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  StatusAreaWidget* status_area_widget =
401c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch      controller->shelf()->status_area_widget();
402a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  if (status_area_widget) {
403a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    WebNotificationTray* notification_tray =
404a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      status_area_widget->web_notification_tray();
405a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    if (notification_tray->visible())
406a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      notification_tray->ShowMessageCenterBubble();
407a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  }
408a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)}
409a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
410a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)bool HandleShowSystemTrayBubble() {
4115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  base::RecordAction(UserMetricsAction("Accel_Show_System_Tray_Bubble"));
412c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  RootWindowController* controller =
413c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch      RootWindowController::ForTargetRootWindow();
414a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  if (!controller->GetSystemTray()->HasSystemBubble()) {
415a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    controller->GetSystemTray()->ShowDefaultView(BUBBLE_CREATE_NEW);
416a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    return true;
417a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  }
418a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  return false;
419a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)}
420a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
421a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)bool HandleShowTaskManager() {
4225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  base::RecordAction(UserMetricsAction("Accel_Show_Task_Manager"));
423a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  Shell::GetInstance()->new_window_delegate()->ShowTaskManager();
424a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  return true;
425a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)}
426a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
427c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch#if defined(OS_CHROMEOS)
428a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)void HandleSilenceSpokenFeedback() {
4295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  base::RecordAction(UserMetricsAction("Accel_Silence_Spoken_Feedback"));
430a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
431a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  AccessibilityDelegate* delegate =
432a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      Shell::GetInstance()->accessibility_delegate();
433a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  if (!delegate->IsSpokenFeedbackEnabled())
434a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    return;
435a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  delegate->SilenceSpokenFeedback();
436a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)}
437c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch#endif
438a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
439a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)bool HandleSwitchIme(ImeControlDelegate* ime_control_delegate,
440a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)                     const ui::Accelerator& accelerator) {
4415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  base::RecordAction(UserMetricsAction("Accel_Switch_Ime"));
442a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  if (ime_control_delegate)
443a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    return ime_control_delegate->HandleSwitchIme(accelerator);
444a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  return false;
445a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)}
446a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
447a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)bool HandleTakePartialScreenshot(ScreenshotDelegate* screenshot_delegate) {
4485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  base::RecordAction(UserMetricsAction("Accel_Take_Partial_Screenshot"));
449a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  if (screenshot_delegate) {
450a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    ash::PartialScreenshotView::StartPartialScreenshot(
451a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)        screenshot_delegate);
452a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  }
453a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // Return true to prevent propagation of the key event because
454a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // this key combination is reserved for partial screenshot.
455a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  return true;
456a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)}
457a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
458a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)bool HandleTakeScreenshot(ScreenshotDelegate* screenshot_delegate) {
4595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  base::RecordAction(UserMetricsAction("Accel_Take_Screenshot"));
460a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  if (screenshot_delegate &&
461a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      screenshot_delegate->CanTakeScreenshot()) {
462a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    screenshot_delegate->HandleTakeScreenshotForAllRootWindows();
463a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  }
464a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // Return true to prevent propagation of the key event.
465a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  return true;
466a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)}
467a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
468a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)bool HandleToggleAppList(ui::KeyboardCode key_code,
469a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)                         ui::EventType previous_event_type,
470a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)                         ui::KeyboardCode previous_key_code,
471a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)                         const ui::Accelerator& accelerator) {
472a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // If something else was pressed between the Search key (LWIN)
473a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // being pressed and released, then ignore the release of the
474a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // Search key.
475a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  if (key_code == ui::VKEY_LWIN &&
476a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      (previous_event_type == ui::ET_KEY_RELEASED ||
477a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)       previous_key_code != ui::VKEY_LWIN))
478c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    return false;
479a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  if (key_code == ui::VKEY_LWIN)
4805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    base::RecordAction(base::UserMetricsAction("Accel_Search_LWin"));
481a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // When spoken feedback is enabled, we should neither toggle the list nor
482a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // consume the key since Search+Shift is one of the shortcuts the a11y
483a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // feature uses. crbug.com/132296
484a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  DCHECK_EQ(ui::VKEY_LWIN, accelerator.key_code());
485a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  if (Shell::GetInstance()->accessibility_delegate()->
486a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      IsSpokenFeedbackEnabled())
487a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    return false;
488a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  ash::Shell::GetInstance()->ToggleAppList(NULL);
4892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  return true;
4902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
4912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
492a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)bool HandleToggleFullscreen(ui::KeyboardCode key_code) {
493a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  if (key_code == ui::VKEY_MEDIA_LAUNCH_APP2) {
4945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    base::RecordAction(UserMetricsAction("Accel_Fullscreen_F4"));
495a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  }
496a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  accelerators::ToggleFullscreen();
4975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return true;
4985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
4995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool HandleToggleRootWindowFullScreen() {
501a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  Shell::GetPrimaryRootWindowController()->ash_host()->ToggleFullScreen();
5025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return true;
5035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
5045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
505a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)bool HandleWindowSnap(int action) {
506a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  wm::WindowState* window_state = wm::GetActiveWindowState();
507a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // Disable window snapping shortcut key for full screen window due to
508a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // http://crbug.com/135487.
509a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  if (!window_state ||
5105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      window_state->window()->type() != ui::wm::WINDOW_TYPE_NORMAL ||
5116d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)      window_state->IsFullscreen() ||
5126d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)      !window_state->CanSnap()) {
513a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    return false;
514a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  }
5152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
516a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  if (action == WINDOW_SNAP_LEFT) {
5175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    base::RecordAction(UserMetricsAction("Accel_Window_Snap_Left"));
518a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  } else {
5195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    base::RecordAction(UserMetricsAction("Accel_Window_Snap_Right"));
5202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
521a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  const wm::WMEvent event(action == WINDOW_SNAP_LEFT ?
522a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)                          wm::WM_EVENT_SNAP_LEFT : wm::WM_EVENT_SNAP_RIGHT);
523a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  window_state->OnWMEvent(&event);
5245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return true;
5255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
5265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
527a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)bool HandleWindowMinimize() {
5285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  base::RecordAction(
5295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      base::UserMetricsAction("Accel_Toggle_Minimized_Minus"));
530a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  return accelerators::ToggleMinimized();
531a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)}
532a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
533a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#if defined(OS_CHROMEOS)
534a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)bool HandleAddRemoveDisplay() {
5355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  base::RecordAction(UserMetricsAction("Accel_Add_Remove_Display"));
536a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  Shell::GetInstance()->display_manager()->AddRemoveDisplay();
5375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return true;
5385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
5395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
540a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)bool HandleCrosh() {
5415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  base::RecordAction(UserMetricsAction("Accel_Open_Crosh"));
542a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
543a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  Shell::GetInstance()->new_window_delegate()->OpenCrosh();
5445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return true;
5455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
5465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
547a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)bool HandleFileManager() {
5485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  base::RecordAction(UserMetricsAction("Accel_Open_File_Manager"));
549a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
550a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  Shell::GetInstance()->new_window_delegate()->OpenFileManager();
551a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  return true;
552a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)}
553a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
554a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)bool HandleLock(ui::KeyboardCode key_code) {
5555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  base::RecordAction(UserMetricsAction("Accel_LockScreen_L"));
556a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  Shell::GetInstance()->session_state_delegate()->LockScreen();
557a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  return true;
558a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)}
559a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
560a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)bool HandleCycleUser(SessionStateDelegate::CycleUser cycle_user) {
561a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  if (!Shell::GetInstance()->delegate()->IsMultiProfilesEnabled())
562a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    return false;
563a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  ash::SessionStateDelegate* delegate =
564a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      ash::Shell::GetInstance()->session_state_delegate();
565a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  if (delegate->NumberOfLoggedInUsers() <= 1)
566a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    return false;
567a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  MultiProfileUMA::RecordSwitchActiveUser(
568a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      MultiProfileUMA::SWITCH_ACTIVE_USER_BY_ACCELERATOR);
569a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  switch (cycle_user) {
570a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    case SessionStateDelegate::CYCLE_TO_NEXT_USER:
5715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      base::RecordAction(UserMetricsAction("Accel_Switch_To_Next_User"));
572a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      break;
573a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    case SessionStateDelegate::CYCLE_TO_PREVIOUS_USER:
5745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      base::RecordAction(UserMetricsAction("Accel_Switch_To_Previous_User"));
575a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      break;
576a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  }
577a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  delegate->CycleActiveUser(cycle_user);
578a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  return true;
579a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)}
580a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
581a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)bool HandleToggleMirrorMode() {
5825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  base::RecordAction(UserMetricsAction("Accel_Toggle_Mirror_Mode"));
583a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  Shell::GetInstance()->display_controller()->ToggleMirrorMode();
584a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  return true;
585a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)}
586a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
587a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)bool HandleToggleSpokenFeedback() {
5885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  base::RecordAction(UserMetricsAction("Accel_Toggle_Spoken_Feedback"));
589a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
590a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  Shell::GetInstance()->accessibility_delegate()->
591a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      ToggleSpokenFeedback(A11Y_NOTIFICATION_SHOW);
592a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  return true;
593a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)}
594a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
595a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)bool HandleToggleTouchViewTesting() {
596a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // TODO(skuhne): This is only temporary! Remove this!
597a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  if (CommandLine::ForCurrentProcess()->HasSwitch(
598a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)          switches::kAshEnableTouchViewTesting)) {
599f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)    MaximizeModeController* controller = Shell::GetInstance()->
600f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)        maximize_mode_controller();
601f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)    controller->EnableMaximizeModeWindowManager(
602f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)        !controller->IsMaximizeModeWindowManagerEnabled());
603a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    return true;
604a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  }
605a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  return false;
606a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)}
607a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
608a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)bool HandleTouchHudClear() {
609c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  RootWindowController* controller =
610c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch      RootWindowController::ForTargetRootWindow();
611a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  if (controller->touch_hud_debug()) {
612a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    controller->touch_hud_debug()->Clear();
613a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    return true;
614a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  }
615a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  return false;
616a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)}
617a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
618a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)bool HandleTouchHudModeChange() {
619c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  RootWindowController* controller =
620c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch      RootWindowController::ForTargetRootWindow();
621a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  if (controller->touch_hud_debug()) {
622a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    controller->touch_hud_debug()->ChangeToNextMode();
623a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    return true;
624a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  }
625a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  return false;
626a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)}
627a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
628a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)bool HandleTouchHudProjectToggle() {
6295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  base::RecordAction(UserMetricsAction("Accel_Touch_Hud_Clear"));
630a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  bool enabled = Shell::GetInstance()->is_touch_hud_projection_enabled();
631a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  Shell::GetInstance()->SetTouchHudProjectionEnabled(!enabled);
6325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return true;
6335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
6345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
635a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)bool HandleDisableCapsLock(ui::KeyboardCode key_code,
636a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)                           ui::EventType previous_event_type,
637a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)                           ui::KeyboardCode previous_key_code) {
638a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  if (previous_event_type == ui::ET_KEY_RELEASED ||
639a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      (previous_key_code != ui::VKEY_LSHIFT &&
640a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)       previous_key_code != ui::VKEY_SHIFT &&
641a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)       previous_key_code != ui::VKEY_RSHIFT)) {
642a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    // If something else was pressed between the Shift key being pressed
643a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    // and released, then ignore the release of the Shift key.
644a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    return false;
645a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  }
646a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  base::RecordAction(UserMetricsAction("Accel_Disable_Caps_Lock"));
647a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  chromeos::input_method::InputMethodManager* ime =
648a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      chromeos::input_method::InputMethodManager::Get();
649a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  chromeos::input_method::ImeKeyboard* keyboard =
650a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch      ime ? ime->GetImeKeyboard() : NULL;
651a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  if (keyboard && keyboard->CapsLockIsEnabled()) {
652a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch    keyboard->SetCapsLockEnabled(false);
653a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    return true;
654a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  }
655a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  return false;
656a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)}
657a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
658a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)bool HandleToggleCapsLock(ui::KeyboardCode key_code,
659a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)                          ui::EventType previous_event_type,
660a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)                          ui::KeyboardCode previous_key_code) {
661a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  if (key_code == ui::VKEY_LWIN) {
662a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    // If something else was pressed between the Search key (LWIN)
663a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    // being pressed and released, then ignore the release of the
664a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    // Search key.
665a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    // TODO(danakj): Releasing Alt first breaks this: crbug.com/166495
666a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    if (previous_event_type == ui::ET_KEY_RELEASED ||
667a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)        previous_key_code != ui::VKEY_LWIN)
668a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      return false;
669a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  }
670a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  base::RecordAction(UserMetricsAction("Accel_Toggle_Caps_Lock"));
671a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  chromeos::input_method::InputMethodManager* ime =
672a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      chromeos::input_method::InputMethodManager::Get();
673a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  chromeos::input_method::ImeKeyboard* keyboard =
674a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch      ime ? ime->GetImeKeyboard() : NULL;
675a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  if (keyboard)
676a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch    keyboard->SetCapsLockEnabled(!keyboard->CapsLockIsEnabled());
677a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  return true;
678a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)}
679a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
680a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#endif  // defined(OS_CHROMEOS)
681a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
682a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// Debug print methods.
683a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
6845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool HandlePrintLayerHierarchy() {
685f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  aura::Window::Windows root_windows = Shell::GetAllRootWindows();
6865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  for (size_t i = 0; i < root_windows.size(); ++i) {
687f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    ui::PrintLayerHierarchy(
688f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)        root_windows[i]->layer(),
689a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)        root_windows[i]->GetHost()->dispatcher()->GetLastMouseLocationInRoot());
6905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
6915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return true;
6925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
6935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool HandlePrintViewHierarchy() {
6952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  aura::Window* active_window = ash::wm::GetActiveWindow();
6962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (!active_window)
6975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return true;
6985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  views::Widget* browser_widget =
6992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      views::Widget::GetWidgetForNativeWindow(active_window);
7002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (!browser_widget)
7012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return true;
7025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  views::PrintViewHierarchy(browser_widget->GetRootView());
7035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return true;
7045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
7055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void PrintWindowHierarchy(aura::Window* window,
7072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                          int indent,
7082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                          std::ostringstream* out) {
7095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  std::string indent_str(indent, ' ');
7102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  std::string name(window->name());
7112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (name.empty())
7122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    name = "\"\"";
7132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  *out << indent_str << name << " (" << window << ")"
7142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)       << " type=" << window->type()
7152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)       << (wm::IsActiveWindow(window) ? " [active] " : " ")
7162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)       << (window->IsVisible() ? " visible " : " ")
7172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)       << window->bounds().ToString()
7182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)       << '\n';
7192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
7205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  for (size_t i = 0; i < window->children().size(); ++i)
7212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    PrintWindowHierarchy(window->children()[i], indent + 3, out);
7225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
7235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool HandlePrintWindowHierarchy() {
7255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Shell::RootWindowControllerList controllers =
7265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      Shell::GetAllRootWindowControllers();
7275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  for (size_t i = 0; i < controllers.size(); ++i) {
7282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    std::ostringstream out;
7292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    out << "RootWindow " << i << ":\n";
730a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch    PrintWindowHierarchy(controllers[i]->GetRootWindow(), 0, &out);
7312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    // Error so logs can be collected from end-users.
7322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    LOG(ERROR) << out.str();
7335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
7345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return true;
7355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
7365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)bool HandlePrintUIHierarchies() {
7382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // This is a separate command so the user only has to hit one key to generate
7392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // all the logs. Developers use the individual dumps repeatedly, so keep
7402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // those as separate commands to avoid spamming their logs.
7412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  HandlePrintLayerHierarchy();
7422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  HandlePrintWindowHierarchy();
7432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  HandlePrintViewHierarchy();
7442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  return true;
7452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
7465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
74746d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)class AutoSet {
74846d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) public:
74946d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  AutoSet(ui::Accelerator* scoped, ui::Accelerator new_value)
75046d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)      : scoped_(scoped), new_value_(new_value) {}
75146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  ~AutoSet() { *scoped_ = new_value_; }
7525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
75346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) private:
75446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  ui::Accelerator* scoped_;
75546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  const ui::Accelerator new_value_;
7565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
75746d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(AutoSet);
75846d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)};
7595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
76046d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)}  // namespace
7615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)////////////////////////////////////////////////////////////////////////////////
7635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// AcceleratorController, public:
7645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)AcceleratorController::AcceleratorController()
7665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    : accelerator_manager_(new ui::AcceleratorManager) {
7675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Init();
7685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
7695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)AcceleratorController::~AcceleratorController() {
7715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
7725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void AcceleratorController::Init() {
77446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  previous_accelerator_.set_type(ui::ET_UNKNOWN);
7755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  for (size_t i = 0; i < kActionsAllowedAtLoginOrLockScreenLength; ++i) {
7765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    actions_allowed_at_login_screen_.insert(
7775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        kActionsAllowedAtLoginOrLockScreen[i]);
7785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    actions_allowed_at_lock_screen_.insert(
7795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        kActionsAllowedAtLoginOrLockScreen[i]);
7805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
7815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  for (size_t i = 0; i < kActionsAllowedAtLockScreenLength; ++i)
7825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    actions_allowed_at_lock_screen_.insert(kActionsAllowedAtLockScreen[i]);
7835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  for (size_t i = 0; i < kActionsAllowedAtModalWindowLength; ++i)
7845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    actions_allowed_at_modal_window_.insert(kActionsAllowedAtModalWindow[i]);
7851320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  for (size_t i = 0; i < kPreferredActionsLength; ++i)
7861320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    preferred_actions_.insert(kPreferredActions[i]);
7875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  for (size_t i = 0; i < kReservedActionsLength; ++i)
7885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    reserved_actions_.insert(kReservedActions[i]);
7895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  for (size_t i = 0; i < kNonrepeatableActionsLength; ++i)
7905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    nonrepeatable_actions_.insert(kNonrepeatableActions[i]);
7912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  for (size_t i = 0; i < kActionsAllowedInAppModeLength; ++i)
7922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    actions_allowed_in_app_mode_.insert(kActionsAllowedInAppMode[i]);
793f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  for (size_t i = 0; i < kActionsNeedingWindowLength; ++i)
794f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    actions_needing_window_.insert(kActionsNeedingWindow[i]);
7955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  RegisterAccelerators(kAcceleratorData, kAcceleratorDataLength);
7975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
798c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#if !defined(NDEBUG)
799c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  RegisterAccelerators(kDesktopAcceleratorData, kDesktopAcceleratorDataLength);
800c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#endif
801c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
80290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  if (DebugShortcutsEnabled()) {
8035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    RegisterAccelerators(kDebugAcceleratorData, kDebugAcceleratorDataLength);
80490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    for (size_t i = 0; i < kReservedDebugActionsLength; ++i)
80590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      reserved_actions_.insert(kReservedDebugActions[i]);
80690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  }
8075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined(OS_CHROMEOS)
8095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  keyboard_brightness_control_delegate_.reset(
8105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      new KeyboardBrightnessController());
8115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
8125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
8135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void AcceleratorController::Register(const ui::Accelerator& accelerator,
8155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                     ui::AcceleratorTarget* target) {
8165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  accelerator_manager_->Register(accelerator,
8175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                 ui::AcceleratorManager::kNormalPriority,
8185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                 target);
8195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
8205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void AcceleratorController::Unregister(const ui::Accelerator& accelerator,
8225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                       ui::AcceleratorTarget* target) {
8235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  accelerator_manager_->Unregister(accelerator, target);
8245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
8255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void AcceleratorController::UnregisterAll(ui::AcceleratorTarget* target) {
8275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  accelerator_manager_->UnregisterAll(target);
8285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
8295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool AcceleratorController::Process(const ui::Accelerator& accelerator) {
83146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  AutoSet auto_set(&previous_accelerator_, accelerator);
83246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
833c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  if (ime_control_delegate_) {
8345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return accelerator_manager_->Process(
8355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        ime_control_delegate_->RemapAccelerator(accelerator));
8365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
8375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return accelerator_manager_->Process(accelerator);
8385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
8395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool AcceleratorController::IsRegistered(
8415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const ui::Accelerator& accelerator) const {
8425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return accelerator_manager_->GetCurrentTarget(accelerator) != NULL;
8435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
8445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8451320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tuccibool AcceleratorController::IsPreferred(
8461320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    const ui::Accelerator& accelerator) const {
8471320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  const ui::Accelerator remapped_accelerator = ime_control_delegate_.get() ?
8481320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      ime_control_delegate_->RemapAccelerator(accelerator) : accelerator;
8491320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
8501320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  std::map<ui::Accelerator, int>::const_iterator iter =
8511320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      accelerators_.find(remapped_accelerator);
8521320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  if (iter == accelerators_.end())
8531320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    return false;  // not an accelerator.
8541320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
8551320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  return preferred_actions_.find(iter->second) != preferred_actions_.end();
8561320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci}
8571320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
8581320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tuccibool AcceleratorController::IsReserved(
8595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const ui::Accelerator& accelerator) const {
8605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const ui::Accelerator remapped_accelerator = ime_control_delegate_.get() ?
8615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      ime_control_delegate_->RemapAccelerator(accelerator) : accelerator;
8625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  std::map<ui::Accelerator, int>::const_iterator iter =
8645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      accelerators_.find(remapped_accelerator);
8655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (iter == accelerators_.end())
8665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return false;  // not an accelerator.
8675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return reserved_actions_.find(iter->second) != reserved_actions_.end();
8695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
8705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool AcceleratorController::PerformAction(int action,
8725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                          const ui::Accelerator& accelerator) {
8735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ash::Shell* shell = ash::Shell::GetInstance();
874116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  AcceleratorProcessingRestriction restriction =
875116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      GetAcceleratorProcessingRestriction(action);
876116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  if (restriction != RESTRICTION_NONE)
877116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    return restriction == RESTRICTION_PREVENT_PROCESSING_AND_PROPAGATION;
8782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
8795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const ui::KeyboardCode key_code = accelerator.key_code();
8805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // PerformAction() is performed from gesture controllers and passes
8815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // empty Accelerator() instance as the second argument. Such events
8825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // should never be suspended.
8835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const bool gesture_event = key_code == ui::VKEY_UNKNOWN;
8845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Ignore accelerators invoked as repeated (while holding a key for a long
8855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // time, if their handling is nonrepeatable.
8865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (nonrepeatable_actions_.find(action) != nonrepeatable_actions_.end() &&
88746d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)      accelerator.IsRepeat() && !gesture_event) {
8885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return true;
8895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
8905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Type of the previous accelerator. Used by NEXT_IME and DISABLE_CAPS_LOCK.
89146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  const ui::EventType previous_event_type = previous_accelerator_.type();
89246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  const ui::KeyboardCode previous_key_code = previous_accelerator_.key_code();
8935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // You *MUST* return true when some action is performed. Otherwise, this
8955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // function might be called *twice*, via BrowserView::PreHandleKeyboardEvent
8965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // and BrowserView::HandleKeyboardEvent, for a single accelerator press.
89758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  //
89858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // If your accelerator invokes more than one line of code, please either
89958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // implement it in your module's controller code (like TOGGLE_MIRROR_MODE
90058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // below) or pull it into a HandleFoo() function above.
9015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  switch (action) {
902c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    case ACCESSIBLE_FOCUS_NEXT:
903c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      return HandleAccessibleFocusCycle(false);
904c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    case ACCESSIBLE_FOCUS_PREVIOUS:
905c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      return HandleAccessibleFocusCycle(true);
9065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    case CYCLE_BACKWARD_MRU:
907a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      return HandleCycleBackwardMRU(accelerator);
9085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    case CYCLE_FORWARD_MRU:
909a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      return HandleCycleForwardMRU(accelerator);
910a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    case TOGGLE_OVERVIEW:
911a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      return ToggleOverview(accelerator);
9125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined(OS_CHROMEOS)
91390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    case ADD_REMOVE_DISPLAY:
914a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      return HandleAddRemoveDisplay();
91590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    case TOGGLE_MIRROR_MODE:
916a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      return HandleToggleMirrorMode();
9175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    case LOCK_SCREEN:
918a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      return HandleLock(key_code);
9192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    case OPEN_FILE_MANAGER:
9204e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)      return HandleFileManager();
9215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    case OPEN_CROSH:
9225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      return HandleCrosh();
923c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    case SILENCE_SPOKEN_FEEDBACK:
924c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      HandleSilenceSpokenFeedback();
925c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      break;
9265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    case SWAP_PRIMARY_DISPLAY:
927a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      return HandleSwapPrimaryDisplay();
92868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)    case SWITCH_TO_NEXT_USER:
929a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      return HandleCycleUser(SessionStateDelegate::CYCLE_TO_NEXT_USER);
930a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    case SWITCH_TO_PREVIOUS_USER:
931a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      return HandleCycleUser(SessionStateDelegate::CYCLE_TO_PREVIOUS_USER);
9325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    case TOGGLE_SPOKEN_FEEDBACK:
9335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      return HandleToggleSpokenFeedback();
934a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    case TOGGLE_TOUCH_VIEW_TESTING:
935a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      return HandleToggleTouchViewTesting();
9365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    case TOGGLE_WIFI:
93790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      Shell::GetInstance()->system_tray_notifier()->NotifyRequestToggleWifi();
9382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      return true;
939a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    case TOUCH_HUD_CLEAR:
940a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      return HandleTouchHudClear();
941a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    case TOUCH_HUD_MODE_CHANGE:
942a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      return HandleTouchHudModeChange();
943a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    case TOUCH_HUD_PROJECTION_TOGGLE:
944a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      return HandleTouchHudProjectToggle();
9452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    case DISABLE_GPU_WATCHDOG:
9465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      Shell::GetInstance()->gpu_support()->DisableGpuWatchdog();
9475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      return true;
948a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    case DISABLE_CAPS_LOCK:
949a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      return HandleDisableCapsLock(
950a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)          key_code, previous_event_type, previous_key_code);
951a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    case TOGGLE_CAPS_LOCK:
952a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      return HandleToggleCapsLock(
953a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)          key_code, previous_event_type, previous_key_code);
954a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#endif  // OS_CHROMEOS
9555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    case OPEN_FEEDBACK_PAGE:
956a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      return HandleOpenFeedbackPage();
9575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    case EXIT:
95890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      // UMA metrics are recorded in the handler.
95990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      exit_warning_handler_.HandleAccelerator();
9605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      return true;
961a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    case NEW_INCOGNITO_WINDOW:
962a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      return HandleNewIncognitoWindow();
9635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    case NEW_TAB:
964