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: ui/aura/desktop.cc

Issue 8465021: Add ShellAcceleratorController that managers global keyboard accelerators. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Address tfarina's comments 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
« no previous file with comments | « ui/aura/desktop.h ('k') | ui/aura_shell/aura_shell.gyp » ('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) 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/desktop.h" 5 #include "ui/aura/desktop.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/message_loop.h" 13 #include "base/message_loop.h"
14 #include "base/string_number_conversions.h" 14 #include "base/string_number_conversions.h"
15 #include "base/string_split.h" 15 #include "base/string_split.h"
16 #include "ui/aura/aura_switches.h" 16 #include "ui/aura/aura_switches.h"
17 #include "ui/aura/client/stacking_client.h" 17 #include "ui/aura/client/stacking_client.h"
18 #include "ui/aura/desktop_host.h" 18 #include "ui/aura/desktop_host.h"
19 #include "ui/aura/desktop_observer.h" 19 #include "ui/aura/desktop_observer.h"
20 #include "ui/aura/event.h" 20 #include "ui/aura/event.h"
21 #include "ui/aura/event_filter.h" 21 #include "ui/aura/event_filter.h"
22 #include "ui/aura/focus_manager.h" 22 #include "ui/aura/focus_manager.h"
23 #include "ui/aura/screen_aura.h" 23 #include "ui/aura/screen_aura.h"
24 #include "ui/aura/window.h" 24 #include "ui/aura/window.h"
25 #include "ui/aura/window_delegate.h" 25 #include "ui/aura/window_delegate.h"
26 #include "ui/base/hit_test.h" 26 #include "ui/base/hit_test.h"
27 #include "ui/gfx/compositor/compositor.h" 27 #include "ui/gfx/compositor/compositor.h"
28 #include "ui/gfx/compositor/layer.h" 28 #include "ui/gfx/compositor/layer.h"
29 #include "ui/gfx/compositor/layer_animation_sequence.h"
30 #include "ui/gfx/compositor/layer_animator.h" 29 #include "ui/gfx/compositor/layer_animator.h"
31 #include "ui/gfx/compositor/screen_rotation.h"
32 #include "ui/gfx/interpolated_transform.h"
33 30
34 using std::string; 31 using std::string;
35 using std::vector; 32 using std::vector;
36 33
37 namespace aura { 34 namespace aura {
38 35
39 namespace { 36 namespace {
40 37
41 // Default bounds for the host window. 38 // Default bounds for the host window.
42 static const int kDefaultHostWindowX = 200; 39 static const int kDefaultHostWindowX = 200;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 85
89 void GetEventFiltersToNotify(Window* target, EventFilters* filters) { 86 void GetEventFiltersToNotify(Window* target, EventFilters* filters) {
90 Window* window = target->parent(); 87 Window* window = target->parent();
91 while (window) { 88 while (window) {
92 if (window->event_filter()) 89 if (window->event_filter())
93 filters->push_back(window->event_filter()); 90 filters->push_back(window->event_filter());
94 window = window->parent(); 91 window = window->parent();
95 } 92 }
96 } 93 }
97 94
98 #if !defined(NDEBUG)
99 bool MaybeFullScreen(DesktopHost* host, KeyEvent* event) {
100 if (event->key_code() == ui::VKEY_F11) {
101 host->ToggleFullScreen();
102 return true;
103 }
104 return false;
105 }
106
107 bool MaybeRotate(Desktop* desktop, KeyEvent* event) {
108 if ((event->flags() & ui::EF_CONTROL_DOWN) &&
109 event->key_code() == ui::VKEY_HOME) {
110 static int i = 0;
111 int delta = 0;
112 switch (i) {
113 case 0: delta = 90; break;
114 case 1: delta = 90; break;
115 case 2: delta = 90; break;
116 case 3: delta = 90; break;
117 case 4: delta = -90; break;
118 case 5: delta = -90; break;
119 case 6: delta = -90; break;
120 case 7: delta = -90; break;
121 case 8: delta = -90; break;
122 case 9: delta = 180; break;
123 case 10: delta = 180; break;
124 case 11: delta = 90; break;
125 case 12: delta = 180; break;
126 case 13: delta = 180; break;
127 }
128 i = (i + 1) % 14;
129 desktop->layer()->GetAnimator()->set_preemption_strategy(
130 ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS);
131 scoped_ptr<ui::LayerAnimationSequence> screen_rotation(
132 new ui::LayerAnimationSequence(new ui::ScreenRotation(delta)));
133 screen_rotation->AddObserver(desktop);
134 desktop->layer()->GetAnimator()->ScheduleAnimation(
135 screen_rotation.release());
136 return true;
137 }
138 return false;
139 }
140 #endif
141
142 } // namespace 95 } // namespace
143 96
144 Desktop* Desktop::instance_ = NULL; 97 Desktop* Desktop::instance_ = NULL;
145 bool Desktop::use_fullscreen_host_window_ = false; 98 bool Desktop::use_fullscreen_host_window_ = false;
146 99
147 Desktop::Desktop() 100 Desktop::Desktop()
148 : Window(NULL), 101 : Window(NULL),
149 host_(aura::DesktopHost::Create(GetInitialHostWindowBounds())), 102 host_(aura::DesktopHost::Create(GetInitialHostWindowBounds())),
150 ALLOW_THIS_IN_INITIALIZER_LIST( 103 ALLOW_THIS_IN_INITIALIZER_LIST(
151 stacking_client_(new DefaultStackingClient(this))), 104 stacking_client_(new DefaultStackingClient(this))),
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 Window::ConvertPointToWindow(this, target, &location_in_window); 220 Window::ConvertPointToWindow(this, target, &location_in_window);
268 if (IsNonClientLocation(target, location_in_window)) 221 if (IsNonClientLocation(target, location_in_window))
269 flags |= ui::EF_IS_NON_CLIENT; 222 flags |= ui::EF_IS_NON_CLIENT;
270 MouseEvent translated_event(*event, this, target, event->type(), flags); 223 MouseEvent translated_event(*event, this, target, event->type(), flags);
271 return ProcessMouseEvent(target, &translated_event); 224 return ProcessMouseEvent(target, &translated_event);
272 } 225 }
273 return false; 226 return false;
274 } 227 }
275 228
276 bool Desktop::DispatchKeyEvent(KeyEvent* event) { 229 bool Desktop::DispatchKeyEvent(KeyEvent* event) {
277 #if !defined(NDEBUG)
278 // TODO(beng): replace this hack with global keyboard event handlers.
279 if (event->type() == ui::ET_KEY_PRESSED) {
280 if (MaybeFullScreen(host_.get(), event) || MaybeRotate(this, event))
281 return true;
282 }
283 #endif
284
285 if (focused_window_) { 230 if (focused_window_) {
286 KeyEvent translated_event(*event); 231 KeyEvent translated_event(*event);
287 return ProcessKeyEvent(focused_window_, &translated_event); 232 return ProcessKeyEvent(focused_window_, &translated_event);
288 } 233 }
289 return false; 234 return false;
290 } 235 }
291 236
292 bool Desktop::DispatchTouchEvent(TouchEvent* event) { 237 bool Desktop::DispatchTouchEvent(TouchEvent* event) {
293 event->UpdateForTransform(layer()->transform()); 238 event->UpdateForTransform(layer()->transform());
294 bool handled = false; 239 bool handled = false;
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 385
441 void Desktop::SetTransform(const ui::Transform& transform) { 386 void Desktop::SetTransform(const ui::Transform& transform) {
442 Window::SetTransform(transform); 387 Window::SetTransform(transform);
443 388
444 // If the layer is not animating, then we need to update the host size 389 // If the layer is not animating, then we need to update the host size
445 // immediately. 390 // immediately.
446 if (!layer()->GetAnimator()->is_animating()) 391 if (!layer()->GetAnimator()->is_animating())
447 OnHostResized(host_->GetSize()); 392 OnHostResized(host_->GetSize());
448 } 393 }
449 394
395 #if !defined(NDEBUG)
396 void Desktop::ToggleFullScreen() {
397 host_->ToggleFullScreen();
398 }
399 #endif
400
450 void Desktop::HandleMouseMoved(const MouseEvent& event, Window* target) { 401 void Desktop::HandleMouseMoved(const MouseEvent& event, Window* target) {
451 if (target == mouse_moved_handler_) 402 if (target == mouse_moved_handler_)
452 return; 403 return;
453 404
454 // Send an exited event. 405 // Send an exited event.
455 if (mouse_moved_handler_ && mouse_moved_handler_->delegate()) { 406 if (mouse_moved_handler_ && mouse_moved_handler_->delegate()) {
456 MouseEvent translated_event(event, this, mouse_moved_handler_, 407 MouseEvent translated_event(event, this, mouse_moved_handler_,
457 ui::ET_MOUSE_EXITED, event.flags()); 408 ui::ET_MOUSE_EXITED, event.flags());
458 ProcessMouseEvent(mouse_moved_handler_, &translated_event); 409 ProcessMouseEvent(mouse_moved_handler_, &translated_event);
459 } 410 }
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
606 base::StringToInt(parts[1], &parsed_height) && parsed_height > 0) { 557 base::StringToInt(parts[1], &parsed_height) && parsed_height > 0) {
607 bounds.set_size(gfx::Size(parsed_width, parsed_height)); 558 bounds.set_size(gfx::Size(parsed_width, parsed_height));
608 } else if (use_fullscreen_host_window_) { 559 } else if (use_fullscreen_host_window_) {
609 bounds = gfx::Rect(DesktopHost::GetNativeDisplaySize()); 560 bounds = gfx::Rect(DesktopHost::GetNativeDisplaySize());
610 } 561 }
611 562
612 return bounds; 563 return bounds;
613 } 564 }
614 565
615 } // namespace aura 566 } // namespace aura
OLDNEW
« no previous file with comments | « ui/aura/desktop.h ('k') | ui/aura_shell/aura_shell.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698