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

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: Address 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,
22 #if !defined(NDEBUG)
23 ROTATE_SCREEN,
24 TOGGLE_FULL_SCREEN,
Daniel Erat 2011/11/29 16:46:00 i don't understand why we need the fullscreen acti
mazda 2011/11/30 14:56:10 This action is a bit different from the fullscreen
Daniel Erat 2011/11/30 16:25:31 Thanks, makes more sense now.
25 #endif
26 };
27
18 // Acceleraters handled by ShellAcceleratorController. 28 // Acceleraters handled by ShellAcceleratorController.
19 struct AcceleratorData { 29 struct AcceleratorData {
20 ui::KeyboardCode keycode; 30 ui::KeyboardCode keycode;
21 bool shift; 31 bool shift;
22 bool ctrl; 32 bool ctrl;
23 bool alt; 33 bool alt;
34 AcceleratorAction action;
24 } kAcceleratorData[] = { 35 } kAcceleratorData[] = {
25 { ui::VKEY_F11, false, false, false }, 36 { ui::VKEY_TAB, true, false, true, CYCLE_BACKWARD },
26 { ui::VKEY_HOME, false, true, false }, 37 { ui::VKEY_TAB, false, false, true, CYCLE_FORWRARD },
38 #if !defined(NDEBUG)
39 { ui::VKEY_HOME, false, true, false, ROTATE_SCREEN },
40 { ui::VKEY_F11, false, false, false, TOGGLE_FULL_SCREEN },
41 #endif
27 }; 42 };
28 43
29 // Registers the accelerators with ShellAcceleratorController. 44 bool CycleBackward() {
30 void RegisterAccelerators(aura_shell::ShellAcceleratorController* controller) { 45 NOTIMPLEMENTED();
31 for (size_t i = 0; i < arraysize(kAcceleratorData); ++i) { 46 return false;
32 controller->Register(ui::Accelerator(kAcceleratorData[i].keycode, 47 }
33 kAcceleratorData[i].shift, 48
34 kAcceleratorData[i].ctrl, 49 bool CycleForwrard() {
35 kAcceleratorData[i].alt), 50 NOTIMPLEMENTED();
36 controller); 51 return false;
37 }
38 } 52 }
39 53
40 #if !defined(NDEBUG) 54 #if !defined(NDEBUG)
41 // Rotates the screen. 55 // Rotates the screen.
42 void RotateScreen() { 56 bool RotateScreen() {
43 static int i = 0; 57 static int i = 0;
44 int delta = 0; 58 int delta = 0;
45 switch (i) { 59 switch (i) {
46 case 0: delta = 90; break; 60 case 0: delta = 90; break;
47 case 1: delta = 90; break; 61 case 1: delta = 90; break;
48 case 2: delta = 90; break; 62 case 2: delta = 90; break;
49 case 3: delta = 90; break; 63 case 3: delta = 90; break;
50 case 4: delta = -90; break; 64 case 4: delta = -90; break;
51 case 5: delta = -90; break; 65 case 5: delta = -90; break;
52 case 6: delta = -90; break; 66 case 6: delta = -90; break;
53 case 7: delta = -90; break; 67 case 7: delta = -90; break;
54 case 8: delta = -90; break; 68 case 8: delta = -90; break;
55 case 9: delta = 180; break; 69 case 9: delta = 180; break;
56 case 10: delta = 180; break; 70 case 10: delta = 180; break;
57 case 11: delta = 90; break; 71 case 11: delta = 90; break;
58 case 12: delta = 180; break; 72 case 12: delta = 180; break;
59 case 13: delta = 180; break; 73 case 13: delta = 180; break;
60 } 74 }
61 i = (i + 1) % 14; 75 i = (i + 1) % 14;
62 aura::Desktop::GetInstance()->layer()->GetAnimator()->set_preemption_strategy( 76 aura::Desktop::GetInstance()->layer()->GetAnimator()->set_preemption_strategy(
63 ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS); 77 ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS);
64 scoped_ptr<ui::LayerAnimationSequence> screen_rotation( 78 scoped_ptr<ui::LayerAnimationSequence> screen_rotation(
65 new ui::LayerAnimationSequence(new ui::ScreenRotation(delta))); 79 new ui::LayerAnimationSequence(new ui::ScreenRotation(delta)));
66 screen_rotation->AddObserver(aura::Desktop::GetInstance()); 80 screen_rotation->AddObserver(aura::Desktop::GetInstance());
67 aura::Desktop::GetInstance()->layer()->GetAnimator()->ScheduleAnimation( 81 aura::Desktop::GetInstance()->layer()->GetAnimator()->ScheduleAnimation(
68 screen_rotation.release()); 82 screen_rotation.release());
83 return true;
84 }
85
86 bool ToggleFullScreen() {
87 aura::Desktop::GetInstance()->ToggleFullScreen();
88 return true;
69 } 89 }
70 #endif 90 #endif
71 91
72 } // namespace 92 } // namespace
73 93
74 namespace aura_shell { 94 namespace aura_shell {
75 95
76 //////////////////////////////////////////////////////////////////////////////// 96 ////////////////////////////////////////////////////////////////////////////////
77 // ShellAcceleratorController, public: 97 // ShellAcceleratorController, public:
78 98
79 ShellAcceleratorController::ShellAcceleratorController() 99 ShellAcceleratorController::ShellAcceleratorController()
80 : accelerator_manager_(new ui::AcceleratorManager) { 100 : accelerator_manager_(new ui::AcceleratorManager) {
81 RegisterAccelerators(this); 101 Init();
82 } 102 }
83 103
84 ShellAcceleratorController::~ShellAcceleratorController() { 104 ShellAcceleratorController::~ShellAcceleratorController() {
85 } 105 }
86 106
107 void ShellAcceleratorController::Init() {
108 for (size_t i = 0; i < arraysize(kAcceleratorData); ++i) {
109 ui::Accelerator accelerator(kAcceleratorData[i].keycode,
110 kAcceleratorData[i].shift,
111 kAcceleratorData[i].ctrl,
112 kAcceleratorData[i].alt);
113 Register(accelerator, this);
114 accelerators_.insert(std::make_pair(accelerator,
115 kAcceleratorData[i].action));
116 }
117 }
118
87 void ShellAcceleratorController::Register( 119 void ShellAcceleratorController::Register(
88 const ui::Accelerator& accelerator, 120 const ui::Accelerator& accelerator,
89 ui::AcceleratorTarget* target) { 121 ui::AcceleratorTarget* target) {
90 accelerator_manager_->Register(accelerator, target); 122 accelerator_manager_->Register(accelerator, target);
91 } 123 }
92 124
93 void ShellAcceleratorController::Unregister( 125 void ShellAcceleratorController::Unregister(
94 const ui::Accelerator& accelerator, 126 const ui::Accelerator& accelerator,
95 ui::AcceleratorTarget* target) { 127 ui::AcceleratorTarget* target) {
96 accelerator_manager_->Unregister(accelerator, target); 128 accelerator_manager_->Unregister(accelerator, target);
97 } 129 }
98 130
99 void ShellAcceleratorController::UnregisterAll( 131 void ShellAcceleratorController::UnregisterAll(
100 ui::AcceleratorTarget* target) { 132 ui::AcceleratorTarget* target) {
101 accelerator_manager_->UnregisterAll(target); 133 accelerator_manager_->UnregisterAll(target);
102 } 134 }
103 135
104 bool ShellAcceleratorController::Process(const ui::Accelerator& accelerator) { 136 bool ShellAcceleratorController::Process(const ui::Accelerator& accelerator) {
105 return accelerator_manager_->Process(accelerator); 137 return accelerator_manager_->Process(accelerator);
106 } 138 }
107 139
108 //////////////////////////////////////////////////////////////////////////////// 140 ////////////////////////////////////////////////////////////////////////////////
109 // ShellAcceleratorController, ui::AcceleratorTarget implementation: 141 // ShellAcceleratorController, ui::AcceleratorTarget implementation:
110 142
111 bool ShellAcceleratorController::AcceleratorPressed( 143 bool ShellAcceleratorController::AcceleratorPressed(
112 const ui::Accelerator& accelerator) { 144 const ui::Accelerator& accelerator) {
145 std::map<ui::Accelerator, int>::const_iterator i =
146 accelerators_.find(accelerator);
147 DCHECK(i != accelerators_.end());
148 switch (static_cast<AcceleratorAction>(i->second)) {
149 case CYCLE_BACKWARD:
150 return CycleBackward();
151 case CYCLE_FORWRARD:
152 return CycleForwrard();
113 #if !defined(NDEBUG) 153 #if !defined(NDEBUG)
114 if (accelerator.key_code() == ui::VKEY_F11) { 154 case ROTATE_SCREEN:
115 aura::Desktop::GetInstance()->ToggleFullScreen(); 155 return RotateScreen();
116 return true; 156 case TOGGLE_FULL_SCREEN:
117 } else if (accelerator.key_code() == ui::VKEY_HOME && 157 return ToggleFullScreen();
118 accelerator.IsCtrlDown()) { 158 #endif
119 RotateScreen(); 159 default:
120 return true; 160 NOTREACHED();
121 } 161 }
122 #endif
123 return false; 162 return false;
124 } 163 }
125 164
126 } // namespace aura_shell 165 } // 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