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

Side by Side Diff: ui/aura_shell/shell_accelerator_controller.cc

Issue 8689003: Register global accelerators and add placeholders for handling them. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add TakeScreenshot and issue comments Created 9 years 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "ui/aura_shell/shell_accelerator_controller.h" 5 #include "ui/aura_shell/shell_accelerator_controller.h"
6 6
7 #include "base/logging.h"
7 #include "ui/aura/desktop.h" 8 #include "ui/aura/desktop.h"
8 #include "ui/aura/event.h" 9 #include "ui/aura/event.h"
9 #include "ui/aura_shell/shell.h" 10 #include "ui/aura_shell/shell.h"
10 #include "ui/base/accelerators/accelerator.h" 11 #include "ui/base/accelerators/accelerator.h"
11 #include "ui/base/accelerators/accelerator_manager.h" 12 #include "ui/base/accelerators/accelerator_manager.h"
12 #include "ui/gfx/compositor/layer_animation_sequence.h" 13 #include "ui/gfx/compositor/layer_animation_sequence.h"
13 #include "ui/gfx/compositor/layer_animator.h" 14 #include "ui/gfx/compositor/layer_animator.h"
14 #include "ui/gfx/compositor/screen_rotation.h" 15 #include "ui/gfx/compositor/screen_rotation.h"
15 16
16 namespace { 17 namespace {
17 18
19 enum AcceleratorAction {
20 CYCLE_BACKWARD,
21 CYCLE_FORWRARD,
Daniel Erat 2011/11/30 16:25:31 typo: FORWRARD -> FORWARD
mazda 2011/11/30 18:36:41 Oh... Thanks again.
22 TAKE_SCREENSHOT,
23 #if !defined(NDEBUG)
24 ROTATE_SCREEN,
25 TOGGLE_DESKTOP_FULL_SCREEN,
26 #endif
27 };
28
18 // Acceleraters handled by ShellAcceleratorController. 29 // Acceleraters handled by ShellAcceleratorController.
19 struct AcceleratorData { 30 struct AcceleratorData {
20 ui::KeyboardCode keycode; 31 ui::KeyboardCode keycode;
21 bool shift; 32 bool shift;
22 bool ctrl; 33 bool ctrl;
23 bool alt; 34 bool alt;
35 AcceleratorAction action;
24 } kAcceleratorData[] = { 36 } kAcceleratorData[] = {
25 { ui::VKEY_F11, false, false, false }, 37 { ui::VKEY_TAB, true, false, true, CYCLE_BACKWARD },
26 { ui::VKEY_HOME, false, true, false }, 38 { ui::VKEY_TAB, false, false, true, CYCLE_FORWRARD },
39 { ui::VKEY_F5, false, true, false, TAKE_SCREENSHOT },
40 { ui::VKEY_PRINT, false, false, false, TAKE_SCREENSHOT },
41 #if !defined(NDEBUG)
42 { ui::VKEY_HOME, false, true, false, ROTATE_SCREEN },
43 { ui::VKEY_F11, false, true, false, TOGGLE_DESKTOP_FULL_SCREEN },
44 #endif
27 }; 45 };
28 46
29 // Registers the accelerators with ShellAcceleratorController. 47 bool CycleBackward() {
Daniel Erat 2011/11/30 16:25:31 do we really need return values for all of these,
mazda 2011/11/30 18:36:41 Right. It's mostly for convenience of using them i
Daniel Erat 2011/11/30 20:47:36 I'd be more okay with the return values if these m
30 void RegisterAccelerators(aura_shell::ShellAcceleratorController* controller) { 48 // TODO(mazda): http://crbug.com/105204
31 for (size_t i = 0; i < arraysize(kAcceleratorData); ++i) { 49 NOTIMPLEMENTED();
32 controller->Register(ui::Accelerator(kAcceleratorData[i].keycode, 50 return false;
33 kAcceleratorData[i].shift, 51 }
34 kAcceleratorData[i].ctrl, 52
35 kAcceleratorData[i].alt), 53 bool CycleForwrard() {
36 controller); 54 // TODO(mazda): http://crbug.com/105204
37 } 55 NOTIMPLEMENTED();
56 return false;
57 }
58
59 bool TakeScreenshot() {
60 // TODO(mazda): http://crbug.com/105198
61 NOTIMPLEMENTED();
62 return false;
38 } 63 }
39 64
40 #if !defined(NDEBUG) 65 #if !defined(NDEBUG)
41 // Rotates the screen. 66 // Rotates the screen.
42 void RotateScreen() { 67 bool RotateScreen() {
43 static int i = 0; 68 static int i = 0;
44 int delta = 0; 69 int delta = 0;
45 switch (i) { 70 switch (i) {
46 case 0: delta = 90; break; 71 case 0: delta = 90; break;
47 case 1: delta = 90; break; 72 case 1: delta = 90; break;
48 case 2: delta = 90; break; 73 case 2: delta = 90; break;
49 case 3: delta = 90; break; 74 case 3: delta = 90; break;
50 case 4: delta = -90; break; 75 case 4: delta = -90; break;
51 case 5: delta = -90; break; 76 case 5: delta = -90; break;
52 case 6: delta = -90; break; 77 case 6: delta = -90; break;
53 case 7: delta = -90; break; 78 case 7: delta = -90; break;
54 case 8: delta = -90; break; 79 case 8: delta = -90; break;
55 case 9: delta = 180; break; 80 case 9: delta = 180; break;
56 case 10: delta = 180; break; 81 case 10: delta = 180; break;
57 case 11: delta = 90; break; 82 case 11: delta = 90; break;
58 case 12: delta = 180; break; 83 case 12: delta = 180; break;
59 case 13: delta = 180; break; 84 case 13: delta = 180; break;
60 } 85 }
61 i = (i + 1) % 14; 86 i = (i + 1) % 14;
62 aura::Desktop::GetInstance()->layer()->GetAnimator()->set_preemption_strategy( 87 aura::Desktop::GetInstance()->layer()->GetAnimator()->set_preemption_strategy(
63 ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS); 88 ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS);
64 scoped_ptr<ui::LayerAnimationSequence> screen_rotation( 89 scoped_ptr<ui::LayerAnimationSequence> screen_rotation(
65 new ui::LayerAnimationSequence(new ui::ScreenRotation(delta))); 90 new ui::LayerAnimationSequence(new ui::ScreenRotation(delta)));
66 screen_rotation->AddObserver(aura::Desktop::GetInstance()); 91 screen_rotation->AddObserver(aura::Desktop::GetInstance());
67 aura::Desktop::GetInstance()->layer()->GetAnimator()->ScheduleAnimation( 92 aura::Desktop::GetInstance()->layer()->GetAnimator()->ScheduleAnimation(
68 screen_rotation.release()); 93 screen_rotation.release());
94 return true;
95 }
96
97 bool ToggleDesktopFullScreen() {
98 aura::Desktop::GetInstance()->ToggleFullScreen();
99 return true;
69 } 100 }
70 #endif 101 #endif
71 102
72 } // namespace 103 } // namespace
73 104
74 namespace aura_shell { 105 namespace aura_shell {
75 106
76 //////////////////////////////////////////////////////////////////////////////// 107 ////////////////////////////////////////////////////////////////////////////////
77 // ShellAcceleratorController, public: 108 // ShellAcceleratorController, public:
78 109
79 ShellAcceleratorController::ShellAcceleratorController() 110 ShellAcceleratorController::ShellAcceleratorController()
80 : accelerator_manager_(new ui::AcceleratorManager) { 111 : accelerator_manager_(new ui::AcceleratorManager) {
81 RegisterAccelerators(this); 112 Init();
82 } 113 }
83 114
84 ShellAcceleratorController::~ShellAcceleratorController() { 115 ShellAcceleratorController::~ShellAcceleratorController() {
85 } 116 }
86 117
118 void ShellAcceleratorController::Init() {
119 for (size_t i = 0; i < arraysize(kAcceleratorData); ++i) {
120 ui::Accelerator accelerator(kAcceleratorData[i].keycode,
121 kAcceleratorData[i].shift,
122 kAcceleratorData[i].ctrl,
123 kAcceleratorData[i].alt);
124 Register(accelerator, this);
125 accelerators_.insert(std::make_pair(accelerator,
126 kAcceleratorData[i].action));
127 }
128 }
129
87 void ShellAcceleratorController::Register( 130 void ShellAcceleratorController::Register(
88 const ui::Accelerator& accelerator, 131 const ui::Accelerator& accelerator,
89 ui::AcceleratorTarget* target) { 132 ui::AcceleratorTarget* target) {
90 accelerator_manager_->Register(accelerator, target); 133 accelerator_manager_->Register(accelerator, target);
91 } 134 }
92 135
93 void ShellAcceleratorController::Unregister( 136 void ShellAcceleratorController::Unregister(
94 const ui::Accelerator& accelerator, 137 const ui::Accelerator& accelerator,
95 ui::AcceleratorTarget* target) { 138 ui::AcceleratorTarget* target) {
96 accelerator_manager_->Unregister(accelerator, target); 139 accelerator_manager_->Unregister(accelerator, target);
97 } 140 }
98 141
99 void ShellAcceleratorController::UnregisterAll( 142 void ShellAcceleratorController::UnregisterAll(
100 ui::AcceleratorTarget* target) { 143 ui::AcceleratorTarget* target) {
101 accelerator_manager_->UnregisterAll(target); 144 accelerator_manager_->UnregisterAll(target);
102 } 145 }
103 146
104 bool ShellAcceleratorController::Process(const ui::Accelerator& accelerator) { 147 bool ShellAcceleratorController::Process(const ui::Accelerator& accelerator) {
105 return accelerator_manager_->Process(accelerator); 148 return accelerator_manager_->Process(accelerator);
106 } 149 }
107 150
108 //////////////////////////////////////////////////////////////////////////////// 151 ////////////////////////////////////////////////////////////////////////////////
109 // ShellAcceleratorController, ui::AcceleratorTarget implementation: 152 // ShellAcceleratorController, ui::AcceleratorTarget implementation:
110 153
111 bool ShellAcceleratorController::AcceleratorPressed( 154 bool ShellAcceleratorController::AcceleratorPressed(
112 const ui::Accelerator& accelerator) { 155 const ui::Accelerator& accelerator) {
156 std::map<ui::Accelerator, int>::const_iterator i =
157 accelerators_.find(accelerator);
158 DCHECK(i != accelerators_.end());
159 switch (static_cast<AcceleratorAction>(i->second)) {
160 case CYCLE_BACKWARD:
161 return CycleBackward();
162 case CYCLE_FORWRARD:
163 return CycleForwrard();
164 case TAKE_SCREENSHOT:
165 return TakeScreenshot();
113 #if !defined(NDEBUG) 166 #if !defined(NDEBUG)
114 if (accelerator.key_code() == ui::VKEY_F11) { 167 case ROTATE_SCREEN:
115 aura::Desktop::GetInstance()->ToggleFullScreen(); 168 return RotateScreen();
116 return true; 169 case TOGGLE_DESKTOP_FULL_SCREEN:
117 } else if (accelerator.key_code() == ui::VKEY_HOME && 170 return ToggleDesktopFullScreen();
118 accelerator.IsCtrlDown()) { 171 #endif
119 RotateScreen(); 172 default:
120 return true; 173 NOTREACHED();
121 } 174 }
122 #endif
123 return false; 175 return false;
124 } 176 }
125 177
126 } // namespace aura_shell 178 } // namespace aura_shell
OLDNEW
« no previous file with comments | « ui/aura_shell/shell_accelerator_controller.h ('k') | ui/aura_shell/shell_accelerator_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698