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

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

Issue 8561012: Add ShellAcceleratorController that manages global keyboard accelerators (2nd try). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase 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
« no previous file with comments | « ui/aura_shell/shell_accelerator_controller.h ('k') | ui/aura_shell/shell_accelerator_filter.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "ui/aura_shell/shell_accelerator_controller.h"
6
7 #include "ui/aura/desktop.h"
8 #include "ui/aura/event.h"
9 #include "ui/aura_shell/shell.h"
10 #include "ui/base/accelerator_manager.h"
11 #include "ui/base/models/accelerator.h"
12 #include "ui/gfx/compositor/layer_animation_sequence.h"
13 #include "ui/gfx/compositor/layer_animator.h"
14 #include "ui/gfx/compositor/screen_rotation.h"
15
16 namespace {
17
18 // Acceleraters handled by ShellAcceleratorController.
19 struct AcceleratorData {
20 ui::KeyboardCode keycode;
21 bool shift;
22 bool ctrl;
23 bool alt;
24 } kAcceleratorData[] = {
25 { ui::VKEY_F11, false, false, false },
26 { ui::VKEY_HOME, false, true, false },
27 };
28
29 // Registers the accelerators with ShellAcceleratorController.
30 void RegisterAccelerators(aura_shell::ShellAcceleratorController* controller) {
31 for (size_t i = 0; i < arraysize(kAcceleratorData); ++i) {
32 controller->Register(ui::Accelerator(kAcceleratorData[i].keycode,
33 kAcceleratorData[i].shift,
34 kAcceleratorData[i].ctrl,
35 kAcceleratorData[i].alt),
36 controller);
37 }
38 }
39
40 #if !defined(NDEBUG)
41 // Rotates the screen.
42 void RotateScreen() {
43 static int i = 0;
44 int delta = 0;
45 switch (i) {
46 case 0: delta = 90; break;
47 case 1: delta = 90; break;
48 case 2: delta = 90; break;
49 case 3: delta = 90; break;
50 case 4: delta = -90; break;
51 case 5: delta = -90; break;
52 case 6: delta = -90; break;
53 case 7: delta = -90; break;
54 case 8: delta = -90; break;
55 case 9: delta = 180; break;
56 case 10: delta = 180; break;
57 case 11: delta = 90; break;
58 case 12: delta = 180; break;
59 case 13: delta = 180; break;
60 }
61 i = (i + 1) % 14;
62 aura::Desktop::GetInstance()->layer()->GetAnimator()->set_preemption_strategy(
63 ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS);
64 scoped_ptr<ui::LayerAnimationSequence> screen_rotation(
65 new ui::LayerAnimationSequence(new ui::ScreenRotation(delta)));
66 screen_rotation->AddObserver(aura::Desktop::GetInstance());
67 aura::Desktop::GetInstance()->layer()->GetAnimator()->ScheduleAnimation(
68 screen_rotation.release());
69 }
70 #endif
71
72 } // namespace
73
74 namespace aura_shell {
75
76 ////////////////////////////////////////////////////////////////////////////////
77 // ShellAcceleratorController, public:
78
79 ShellAcceleratorController::ShellAcceleratorController()
80 : accelerator_manager_(new ui::AcceleratorManager) {
81 RegisterAccelerators(this);
82 }
83
84 ShellAcceleratorController::~ShellAcceleratorController() {
85 }
86
87 void ShellAcceleratorController::Register(
88 const ui::Accelerator& accelerator,
89 ui::AcceleratorTarget* target) {
90 accelerator_manager_->Register(accelerator, target);
91 }
92
93 void ShellAcceleratorController::Unregister(
94 const ui::Accelerator& accelerator,
95 ui::AcceleratorTarget* target) {
96 accelerator_manager_->Unregister(accelerator, target);
97 }
98
99 void ShellAcceleratorController::UnregisterAll(
100 ui::AcceleratorTarget* target) {
101 accelerator_manager_->UnregisterAll(target);
102 }
103
104 bool ShellAcceleratorController::Process(const ui::Accelerator& accelerator) {
105 return accelerator_manager_->Process(accelerator);
106 }
107
108 ////////////////////////////////////////////////////////////////////////////////
109 // ShellAcceleratorController, ui::AcceleratorTarget implementation:
110
111 bool ShellAcceleratorController::AcceleratorPressed(
112 const ui::Accelerator& accelerator) {
113 #if !defined(NDEBUG)
114 if (accelerator.key_code() == ui::VKEY_F11) {
115 aura::Desktop::GetInstance()->ToggleFullScreen();
116 return true;
117 } else if (accelerator.key_code() == ui::VKEY_HOME &&
118 accelerator.IsCtrlDown()) {
119 RotateScreen();
120 return true;
121 }
122 #endif
123 return false;
124 }
125
126 } // namespace aura_shell
OLDNEW
« no previous file with comments | « ui/aura_shell/shell_accelerator_controller.h ('k') | ui/aura_shell/shell_accelerator_filter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698