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

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

Issue 8465021: Add ShellAcceleratorController that managers global keyboard accelerators. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Move AcceleratorPressed to Shell from Desktop Created 9 years, 1 month 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
« ui/aura_shell/shell.h ('K') | « ui/aura_shell/shell.h ('k') | no next file » | 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) 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.h" 5 #include "ui/aura_shell/shell.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "ui/aura/aura_switches.h" 9 #include "ui/aura/aura_switches.h"
10 #include "ui/aura/desktop.h" 10 #include "ui/aura/desktop.h"
11 #include "ui/aura/window.h" 11 #include "ui/aura/window.h"
12 #include "ui/aura/window_types.h" 12 #include "ui/aura/window_types.h"
13 #include "ui/aura_shell/default_container_event_filter.h" 13 #include "ui/aura_shell/default_container_event_filter.h"
14 #include "ui/aura_shell/default_container_layout_manager.h" 14 #include "ui/aura_shell/default_container_layout_manager.h"
15 #include "ui/aura_shell/desktop_event_filter.h" 15 #include "ui/aura_shell/desktop_event_filter.h"
16 #include "ui/aura_shell/desktop_layout_manager.h" 16 #include "ui/aura_shell/desktop_layout_manager.h"
17 #include "ui/aura_shell/launcher/launcher.h" 17 #include "ui/aura_shell/launcher/launcher.h"
18 #include "ui/aura_shell/shelf_layout_controller.h" 18 #include "ui/aura_shell/shelf_layout_controller.h"
19 #include "ui/aura_shell/shell_delegate.h" 19 #include "ui/aura_shell/shell_delegate.h"
20 #include "ui/aura_shell/shell_factory.h" 20 #include "ui/aura_shell/shell_factory.h"
21 #include "ui/aura_shell/shell_window_ids.h" 21 #include "ui/aura_shell/shell_window_ids.h"
22 #include "ui/aura_shell/stacking_controller.h" 22 #include "ui/aura_shell/stacking_controller.h"
23 #include "ui/aura_shell/toplevel_layout_manager.h" 23 #include "ui/aura_shell/toplevel_layout_manager.h"
24 #include "ui/aura_shell/toplevel_window_event_filter.h" 24 #include "ui/aura_shell/toplevel_window_event_filter.h"
25 #include "ui/aura_shell/workspace_controller.h" 25 #include "ui/aura_shell/workspace_controller.h"
26 #include "ui/base/accelerator_manager.h"
26 #include "ui/gfx/compositor/layer.h" 27 #include "ui/gfx/compositor/layer.h"
27 #include "ui/gfx/compositor/layer_animator.h" 28 #include "ui/gfx/compositor/layer_animator.h"
28 #include "views/widget/native_widget_aura.h" 29 #include "views/widget/native_widget_aura.h"
29 #include "views/widget/widget.h" 30 #include "views/widget/widget.h"
30 31
31 namespace aura_shell { 32 namespace aura_shell {
32 33
33 namespace { 34 namespace {
34 35
35 using views::Widget; 36 using views::Widget;
36 37
38 // Acceleraters handled by Shell.
39 struct AcceleratorData {
40 ui::KeyboardCode keycode;
41 bool shift;
42 bool ctrl;
43 bool alt;
44 } kAcceleratorData[] = {
45 { ui::VKEY_F11, false, false, false },
46 { ui::VKEY_HOME, false, true, false },
47 };
48
37 // Creates each of the special window containers that holds windows of various 49 // Creates each of the special window containers that holds windows of various
38 // types in the shell UI. They are added to |containers| from back to front in 50 // types in the shell UI. They are added to |containers| from back to front in
39 // the z-index. 51 // the z-index.
40 void CreateSpecialContainers(aura::Window::Windows* containers) { 52 void CreateSpecialContainers(aura::Window::Windows* containers) {
41 aura::Window* background_container = new aura::Window(NULL); 53 aura::Window* background_container = new aura::Window(NULL);
42 background_container->set_id( 54 background_container->set_id(
43 internal::kShellWindowId_DesktopBackgroundContainer); 55 internal::kShellWindowId_DesktopBackgroundContainer);
44 containers->push_back(background_container); 56 containers->push_back(background_container);
45 57
46 aura::Window* default_container = new aura::Window(NULL); 58 aura::Window* default_container = new aura::Window(NULL);
(...skipping 20 matching lines...) Expand all
67 79
68 aura::Window* status_container = new aura::Window(NULL); 80 aura::Window* status_container = new aura::Window(NULL);
69 status_container->set_id(internal::kShellWindowId_StatusContainer); 81 status_container->set_id(internal::kShellWindowId_StatusContainer);
70 containers->push_back(status_container); 82 containers->push_back(status_container);
71 83
72 aura::Window* menu_container = new aura::Window(NULL); 84 aura::Window* menu_container = new aura::Window(NULL);
73 menu_container->set_id(internal::kShellWindowId_MenusAndTooltipsContainer); 85 menu_container->set_id(internal::kShellWindowId_MenusAndTooltipsContainer);
74 containers->push_back(menu_container); 86 containers->push_back(menu_container);
75 } 87 }
76 88
89 void RegisterAccelerators(Shell* shell) {
90 ui::AcceleratorManager* accelerator_manager = shell->accelerator_manager();
91 for (size_t i = 0; i < arraysize(kAcceleratorData); ++i) {
92 accelerator_manager->Register(ui::Accelerator(kAcceleratorData[i].keycode,
93 kAcceleratorData[i].shift,
94 kAcceleratorData[i].ctrl,
95 kAcceleratorData[i].alt),
96 shell);
97 }
98 }
99
77 } // namespace 100 } // namespace
78 101
79 // static 102 // static
80 Shell* Shell::instance_ = NULL; 103 Shell* Shell::instance_ = NULL;
81 104
82 //////////////////////////////////////////////////////////////////////////////// 105 ////////////////////////////////////////////////////////////////////////////////
83 // Shell, public: 106 // Shell, public:
84 107
85 Shell::Shell(ShellDelegate* delegate) 108 Shell::Shell(ShellDelegate* delegate)
86 : ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)), 109 : ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)),
87 delegate_(delegate) { 110 delegate_(delegate),
111 accelerator_manager_(new ui::AcceleratorManager) {
88 aura::Desktop::GetInstance()->SetEventFilter( 112 aura::Desktop::GetInstance()->SetEventFilter(
89 new internal::DesktopEventFilter); 113 new internal::DesktopEventFilter);
90 aura::Desktop::GetInstance()->SetStackingClient( 114 aura::Desktop::GetInstance()->SetStackingClient(
91 new internal::StackingController); 115 new internal::StackingController);
92 } 116 }
93 117
94 Shell::~Shell() { 118 Shell::~Shell() {
95 DCHECK(instance_ == this); 119 DCHECK(instance_ == this);
96 instance_ = NULL; 120 instance_ = NULL;
97 121
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 184
161 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAuraWindows)) { 185 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAuraWindows)) {
162 EnableWorkspaceManager(); 186 EnableWorkspaceManager();
163 } else { 187 } else {
164 internal::ToplevelLayoutManager* toplevel_layout_manager = 188 internal::ToplevelLayoutManager* toplevel_layout_manager =
165 new internal::ToplevelLayoutManager(); 189 new internal::ToplevelLayoutManager();
166 default_container->SetLayoutManager(toplevel_layout_manager); 190 default_container->SetLayoutManager(toplevel_layout_manager);
167 toplevel_layout_manager->set_shelf(shelf_layout_controller_.get()); 191 toplevel_layout_manager->set_shelf(shelf_layout_controller_.get());
168 } 192 }
169 193
194 RegisterAccelerators(this);
195
170 // Force a layout. 196 // Force a layout.
171 desktop_layout->OnWindowResized(); 197 desktop_layout->OnWindowResized();
172 } 198 }
173 199
174 aura::Window* Shell::GetContainer(int container_id) { 200 aura::Window* Shell::GetContainer(int container_id) {
175 return const_cast<aura::Window*>( 201 return const_cast<aura::Window*>(
176 const_cast<const aura_shell::Shell*>(this)->GetContainer(container_id)); 202 const_cast<const aura_shell::Shell*>(this)->GetContainer(container_id));
177 } 203 }
178 204
179 const aura::Window* Shell::GetContainer(int container_id) const { 205 const aura::Window* Shell::GetContainer(int container_id) const {
180 return aura::Desktop::GetInstance()->GetChildById(container_id); 206 return aura::Desktop::GetInstance()->GetChildById(container_id);
181 } 207 }
182 208
183 void Shell::ToggleOverview() { 209 void Shell::ToggleOverview() {
184 if (workspace_controller_.get()) 210 if (workspace_controller_.get())
185 workspace_controller_->ToggleOverview(); 211 workspace_controller_->ToggleOverview();
186 } 212 }
187 213
214 bool Shell::AcceleratorPressed(const ui::Accelerator& accelerator) {
215 #if !defined(NDEBUG)
216 if (accelerator.key_code() == ui::VKEY_F11) {
217 aura::Desktop::GetInstance()->ToggleFullScreen();
218 return true;
219 } else if (accelerator.key_code() == ui::VKEY_HOME &&
220 accelerator.IsCtrlDown()) {
221 aura::Desktop::GetInstance()->Rotate();
222 return true;
223 }
224 #endif
225 return false;
226 }
227
188 //////////////////////////////////////////////////////////////////////////////// 228 ////////////////////////////////////////////////////////////////////////////////
189 // Shell, private: 229 // Shell, private:
190 230
191 void Shell::EnableWorkspaceManager() { 231 void Shell::EnableWorkspaceManager() {
192 aura::Window* default_container = 232 aura::Window* default_container =
193 GetContainer(internal::kShellWindowId_DefaultContainer); 233 GetContainer(internal::kShellWindowId_DefaultContainer);
194 234
195 workspace_controller_.reset( 235 workspace_controller_.reset(
196 new internal::WorkspaceController(default_container)); 236 new internal::WorkspaceController(default_container));
197 workspace_controller_->SetLauncherModel(launcher_->model()); 237 workspace_controller_->SetLauncherModel(launcher_->model());
198 default_container->SetEventFilter( 238 default_container->SetEventFilter(
199 new internal::DefaultContainerEventFilter(default_container)); 239 new internal::DefaultContainerEventFilter(default_container));
200 default_container->SetLayoutManager( 240 default_container->SetLayoutManager(
201 new internal::DefaultContainerLayoutManager( 241 new internal::DefaultContainerLayoutManager(
202 workspace_controller_->workspace_manager())); 242 workspace_controller_->workspace_manager()));
203 } 243 }
204 244
205 } // namespace aura_shell 245 } // namespace aura_shell
OLDNEW
« ui/aura_shell/shell.h ('K') | « ui/aura_shell/shell.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698