Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(230)

Side by Side Diff: ash/accelerators/accelerator_controller.cc

Issue 9124021: Adds Ctrl-Shift-Q support inside AppList (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Removed extraneous import Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | ash/accelerators/accelerator_controller_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ash/accelerators/accelerator_controller.h" 5 #include "ash/accelerators/accelerator_controller.h"
6 6
7 #include "ash/caps_lock_delegate.h" 7 #include "ash/caps_lock_delegate.h"
8 #include "ash/launcher/launcher.h" 8 #include "ash/launcher/launcher.h"
9 #include "ash/launcher/launcher_model.h" 9 #include "ash/launcher/launcher_model.h"
10 #include "ash/screenshot_delegate.h" 10 #include "ash/screenshot_delegate.h"
11 #include "ash/shell.h" 11 #include "ash/shell.h"
12 #include "ash/shell_delegate.h"
12 #include "ash/shell_window_ids.h" 13 #include "ash/shell_window_ids.h"
13 #include "ash/wm/window_cycle_controller.h" 14 #include "ash/wm/window_cycle_controller.h"
14 #include "ui/aura/event.h" 15 #include "ui/aura/event.h"
15 #include "ui/aura/root_window.h" 16 #include "ui/aura/root_window.h"
16 #include "ui/base/accelerators/accelerator.h" 17 #include "ui/base/accelerators/accelerator.h"
17 #include "ui/base/accelerators/accelerator_manager.h" 18 #include "ui/base/accelerators/accelerator_manager.h"
18 #include "ui/gfx/compositor/debug_utils.h" 19 #include "ui/gfx/compositor/debug_utils.h"
19 #include "ui/gfx/compositor/layer_animation_sequence.h" 20 #include "ui/gfx/compositor/layer_animation_sequence.h"
20 #include "ui/gfx/compositor/layer_animator.h" 21 #include "ui/gfx/compositor/layer_animator.h"
21 #include "ui/gfx/compositor/screen_rotation.h" 22 #include "ui/gfx/compositor/screen_rotation.h"
22 23
23 namespace { 24 namespace {
24 25
25 enum AcceleratorAction { 26 enum AcceleratorAction {
26 CYCLE_BACKWARD, 27 CYCLE_BACKWARD,
27 CYCLE_FORWARD, 28 CYCLE_FORWARD,
29 EXIT,
28 TAKE_SCREENSHOT, 30 TAKE_SCREENSHOT,
29 TOGGLE_CAPS_LOCK, 31 TOGGLE_CAPS_LOCK,
30 #if !defined(NDEBUG) 32 #if !defined(NDEBUG)
31 ROTATE_SCREEN, 33 ROTATE_SCREEN,
32 PRINT_LAYER_HIERARCHY, 34 PRINT_LAYER_HIERARCHY,
33 TOGGLE_ROOT_WINDOW_FULL_SCREEN, 35 TOGGLE_ROOT_WINDOW_FULL_SCREEN,
34 #endif 36 #endif
35 }; 37 };
36 38
37 // Accelerators handled by AcceleratorController. 39 // Accelerators handled by AcceleratorController.
38 struct AcceleratorData { 40 struct AcceleratorData {
39 ui::KeyboardCode keycode; 41 ui::KeyboardCode keycode;
40 bool shift; 42 bool shift;
41 bool ctrl; 43 bool ctrl;
42 bool alt; 44 bool alt;
43 AcceleratorAction action; 45 AcceleratorAction action;
44 } kAcceleratorData[] = { 46 } kAcceleratorData[] = {
45 { ui::VKEY_TAB, false, false, true, CYCLE_FORWARD }, 47 { ui::VKEY_TAB, false, false, true, CYCLE_FORWARD },
46 { ui::VKEY_TAB, true, false, true, CYCLE_BACKWARD }, 48 { ui::VKEY_TAB, true, false, true, CYCLE_BACKWARD },
47 { ui::VKEY_F5, false, false, false, CYCLE_FORWARD }, 49 { ui::VKEY_F5, false, false, false, CYCLE_FORWARD },
50 { ui::VKEY_Q, true, true, false, EXIT },
48 { ui::VKEY_F5, true, false, false, CYCLE_BACKWARD }, 51 { ui::VKEY_F5, true, false, false, CYCLE_BACKWARD },
49 { ui::VKEY_F5, false, true, false, TAKE_SCREENSHOT }, 52 { ui::VKEY_F5, false, true, false, TAKE_SCREENSHOT },
50 { ui::VKEY_PRINT, false, false, false, TAKE_SCREENSHOT }, 53 { ui::VKEY_PRINT, false, false, false, TAKE_SCREENSHOT },
51 // On Chrome OS, Search key is mapped to LWIN. 54 // On Chrome OS, Search key is mapped to LWIN.
52 { ui::VKEY_LWIN, true, false, false, TOGGLE_CAPS_LOCK }, 55 { ui::VKEY_LWIN, true, false, false, TOGGLE_CAPS_LOCK },
53 #if !defined(NDEBUG) 56 #if !defined(NDEBUG)
54 { ui::VKEY_HOME, false, true, false, ROTATE_SCREEN }, 57 { ui::VKEY_HOME, false, true, false, ROTATE_SCREEN },
55 { ui::VKEY_F11, false, true, false, TOGGLE_ROOT_WINDOW_FULL_SCREEN }, 58 { ui::VKEY_F11, false, true, false, TOGGLE_ROOT_WINDOW_FULL_SCREEN },
56 { ui::VKEY_L, false, false, true, PRINT_LAYER_HIERARCHY }, 59 { ui::VKEY_L, false, false, true, PRINT_LAYER_HIERARCHY },
57 // For testing on systems where Alt-Tab is already mapped. 60 // For testing on systems where Alt-Tab is already mapped.
58 { ui::VKEY_W, false, false, true, CYCLE_FORWARD }, 61 { ui::VKEY_W, false, false, true, CYCLE_FORWARD },
59 { ui::VKEY_W, true, false, true, CYCLE_BACKWARD }, 62 { ui::VKEY_W, true, false, true, CYCLE_BACKWARD },
60 #endif 63 #endif
61 }; 64 };
62 65
63 bool HandleCycleWindow(ash::WindowCycleController::Direction direction, 66 bool HandleCycleWindow(ash::WindowCycleController::Direction direction,
64 bool is_alt_down) { 67 bool is_alt_down) {
65 ash::Shell::GetInstance()-> 68 ash::Shell::GetInstance()->
66 window_cycle_controller()->HandleCycleWindow(direction, is_alt_down); 69 window_cycle_controller()->HandleCycleWindow(direction, is_alt_down);
67 // Always report we handled the key, even if the window didn't change. 70 // Always report we handled the key, even if the window didn't change.
68 return true; 71 return true;
69 } 72 }
70 73
74 bool HandleExit() {
75 ash::ShellDelegate* delegate = ash::Shell::GetInstance()->delegate();
76 if (!delegate)
77 return false;
78 delegate->Exit();
79 return true;
80 }
81
71 #if !defined(NDEBUG) 82 #if !defined(NDEBUG)
72 // Rotates the screen. 83 // Rotates the screen.
73 bool HandleRotateScreen() { 84 bool HandleRotateScreen() {
74 static int i = 0; 85 static int i = 0;
75 int delta = 0; 86 int delta = 0;
76 switch (i) { 87 switch (i) {
77 case 0: delta = 90; break; 88 case 0: delta = 90; break;
78 case 1: delta = 90; break; 89 case 1: delta = 90; break;
79 case 2: delta = 90; break; 90 case 2: delta = 90; break;
80 case 3: delta = 90; break; 91 case 3: delta = 90; break;
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 std::map<ui::Accelerator, int>::const_iterator it = 190 std::map<ui::Accelerator, int>::const_iterator it =
180 accelerators_.find(accelerator); 191 accelerators_.find(accelerator);
181 DCHECK(it != accelerators_.end()); 192 DCHECK(it != accelerators_.end());
182 switch (static_cast<AcceleratorAction>(it->second)) { 193 switch (static_cast<AcceleratorAction>(it->second)) {
183 case CYCLE_BACKWARD: 194 case CYCLE_BACKWARD:
184 return HandleCycleWindow(WindowCycleController::BACKWARD, 195 return HandleCycleWindow(WindowCycleController::BACKWARD,
185 accelerator.IsAltDown()); 196 accelerator.IsAltDown());
186 case CYCLE_FORWARD: 197 case CYCLE_FORWARD:
187 return HandleCycleWindow(WindowCycleController::FORWARD, 198 return HandleCycleWindow(WindowCycleController::FORWARD,
188 accelerator.IsAltDown()); 199 accelerator.IsAltDown());
200 case EXIT:
201 return HandleExit();
189 case TAKE_SCREENSHOT: 202 case TAKE_SCREENSHOT:
190 if (screenshot_delegate_.get()) 203 if (screenshot_delegate_.get())
191 screenshot_delegate_->HandleTakeScreenshot(); 204 screenshot_delegate_->HandleTakeScreenshot();
192 // Return true to prevent propagation of the key event. 205 // Return true to prevent propagation of the key event.
193 return true; 206 return true;
194 case TOGGLE_CAPS_LOCK: 207 case TOGGLE_CAPS_LOCK:
195 if (caps_lock_delegate_.get()) 208 if (caps_lock_delegate_.get())
196 return caps_lock_delegate_->HandleToggleCapsLock(); 209 return caps_lock_delegate_->HandleToggleCapsLock();
197 break; 210 break;
198 #if !defined(NDEBUG) 211 #if !defined(NDEBUG)
199 case ROTATE_SCREEN: 212 case ROTATE_SCREEN:
200 return HandleRotateScreen(); 213 return HandleRotateScreen();
201 case TOGGLE_ROOT_WINDOW_FULL_SCREEN: 214 case TOGGLE_ROOT_WINDOW_FULL_SCREEN:
202 return HandleToggleRootWindowFullScreen(); 215 return HandleToggleRootWindowFullScreen();
203 case PRINT_LAYER_HIERARCHY: 216 case PRINT_LAYER_HIERARCHY:
204 return HandlePrintLayerHierarchy(); 217 return HandlePrintLayerHierarchy();
205 #endif 218 #endif
206 default: 219 default:
207 NOTREACHED() << "Unhandled action " << it->second;; 220 NOTREACHED() << "Unhandled action " << it->second;;
208 } 221 }
209 return false; 222 return false;
210 } 223 }
211 224
212 bool AcceleratorController::CanHandleAccelerators() const { 225 bool AcceleratorController::CanHandleAccelerators() const {
213 return true; 226 return true;
214 } 227 }
215 228
216 } // namespace ash 229 } // namespace ash
OLDNEW
« no previous file with comments | « no previous file | ash/accelerators/accelerator_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698