OLD | NEW |
---|---|
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/accelerator_manager.h" | |
26 #include "ui/base/hit_test.h" | 27 #include "ui/base/hit_test.h" |
27 #include "ui/gfx/compositor/compositor.h" | 28 #include "ui/gfx/compositor/compositor.h" |
28 #include "ui/gfx/compositor/layer.h" | 29 #include "ui/gfx/compositor/layer.h" |
29 #include "ui/gfx/compositor/layer_animation_sequence.h" | 30 #include "ui/gfx/compositor/layer_animation_sequence.h" |
30 #include "ui/gfx/compositor/layer_animator.h" | 31 #include "ui/gfx/compositor/layer_animator.h" |
31 #include "ui/gfx/compositor/screen_rotation.h" | 32 #include "ui/gfx/compositor/screen_rotation.h" |
32 #include "ui/gfx/interpolated_transform.h" | 33 #include "ui/gfx/interpolated_transform.h" |
33 | 34 |
34 using std::string; | 35 using std::string; |
35 using std::vector; | 36 using std::vector; |
36 | 37 |
37 namespace aura { | 38 namespace aura { |
38 | 39 |
39 namespace { | 40 namespace { |
40 | 41 |
41 // Default bounds for the host window. | 42 // Default bounds for the host window. |
42 static const int kDefaultHostWindowX = 200; | 43 static const int kDefaultHostWindowX = 200; |
43 static const int kDefaultHostWindowY = 200; | 44 static const int kDefaultHostWindowY = 200; |
44 static const int kDefaultHostWindowWidth = 1280; | 45 static const int kDefaultHostWindowWidth = 1280; |
45 static const int kDefaultHostWindowHeight = 1024; | 46 static const int kDefaultHostWindowHeight = 1024; |
46 | 47 |
48 // Acceleraters handled by Desktop. | |
49 struct AcceleratorData { | |
50 ui::KeyboardCode keycode; | |
51 bool shift; | |
52 bool ctrl; | |
53 bool alt; | |
54 } kAcceleratorData[] = { | |
55 { ui::VKEY_F11, false, false, false }, | |
56 { ui::VKEY_HOME, false, true, false }, | |
57 }; | |
58 | |
47 // Returns true if |target| has a non-client (frame) component at |location|, | 59 // Returns true if |target| has a non-client (frame) component at |location|, |
48 // in window coordinates. | 60 // in window coordinates. |
49 bool IsNonClientLocation(Window* target, const gfx::Point& location) { | 61 bool IsNonClientLocation(Window* target, const gfx::Point& location) { |
50 if (!target->delegate()) | 62 if (!target->delegate()) |
51 return false; | 63 return false; |
52 int hit_test_code = target->delegate()->GetNonClientComponent(location); | 64 int hit_test_code = target->delegate()->GetNonClientComponent(location); |
53 return hit_test_code != HTCLIENT && hit_test_code != HTNOWHERE; | 65 return hit_test_code != HTCLIENT && hit_test_code != HTNOWHERE; |
54 } | 66 } |
55 | 67 |
56 class DefaultStackingClient : public StackingClient { | 68 class DefaultStackingClient : public StackingClient { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
89 void GetEventFiltersToNotify(Window* target, EventFilters* filters) { | 101 void GetEventFiltersToNotify(Window* target, EventFilters* filters) { |
90 Window* window = target->parent(); | 102 Window* window = target->parent(); |
91 while (window) { | 103 while (window) { |
92 if (window->event_filter()) | 104 if (window->event_filter()) |
93 filters->push_back(window->event_filter()); | 105 filters->push_back(window->event_filter()); |
94 window = window->parent(); | 106 window = window->parent(); |
95 } | 107 } |
96 } | 108 } |
97 | 109 |
98 #if !defined(NDEBUG) | 110 #if !defined(NDEBUG) |
99 bool MaybeFullScreen(DesktopHost* host, KeyEvent* event) { | 111 bool FullScreen(DesktopHost* host) { |
100 if (event->key_code() == ui::VKEY_F11) { | 112 host->ToggleFullScreen(); |
101 host->ToggleFullScreen(); | 113 return true; |
102 return true; | |
103 } | |
104 return false; | |
105 } | 114 } |
106 | 115 |
107 bool MaybeRotate(Desktop* desktop, KeyEvent* event) { | 116 bool Rotate(Desktop* desktop) { |
108 if ((event->flags() & ui::EF_CONTROL_DOWN) && | 117 static int i = 0; |
109 event->key_code() == ui::VKEY_HOME) { | 118 int delta = 0; |
110 static int i = 0; | 119 switch (i) { |
111 int delta = 0; | 120 case 0: delta = 90; break; |
112 switch (i) { | 121 case 1: delta = 90; break; |
113 case 0: delta = 90; break; | 122 case 2: delta = 90; break; |
114 case 1: delta = 90; break; | 123 case 3: delta = 90; break; |
115 case 2: delta = 90; break; | 124 case 4: delta = -90; break; |
116 case 3: delta = 90; break; | 125 case 5: delta = -90; break; |
117 case 4: delta = -90; break; | 126 case 6: delta = -90; break; |
118 case 5: delta = -90; break; | 127 case 7: delta = -90; break; |
119 case 6: delta = -90; break; | 128 case 8: delta = -90; break; |
120 case 7: delta = -90; break; | 129 case 9: delta = 180; break; |
121 case 8: delta = -90; break; | 130 case 10: delta = 180; break; |
122 case 9: delta = 180; break; | 131 case 11: delta = 90; break; |
123 case 10: delta = 180; break; | 132 case 12: delta = 180; break; |
124 case 11: delta = 90; break; | 133 case 13: delta = 180; 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 } | 134 } |
138 return false; | 135 i = (i + 1) % 14; |
136 desktop->layer()->GetAnimator()->set_preemption_strategy( | |
137 ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS); | |
138 scoped_ptr<ui::LayerAnimationSequence> screen_rotation( | |
139 new ui::LayerAnimationSequence(new ui::ScreenRotation(delta))); | |
140 screen_rotation->AddObserver(desktop); | |
141 desktop->layer()->GetAnimator()->ScheduleAnimation( | |
142 screen_rotation.release()); | |
143 return true; | |
139 } | 144 } |
140 #endif | 145 #endif |
141 | 146 |
142 } // namespace | 147 } // namespace |
143 | 148 |
144 Desktop* Desktop::instance_ = NULL; | 149 Desktop* Desktop::instance_ = NULL; |
145 bool Desktop::use_fullscreen_host_window_ = false; | 150 bool Desktop::use_fullscreen_host_window_ = false; |
146 | 151 |
147 Desktop::Desktop() | 152 Desktop::Desktop() |
148 : Window(NULL), | 153 : Window(NULL), |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
267 Window::ConvertPointToWindow(this, target, &location_in_window); | 272 Window::ConvertPointToWindow(this, target, &location_in_window); |
268 if (IsNonClientLocation(target, location_in_window)) | 273 if (IsNonClientLocation(target, location_in_window)) |
269 flags |= ui::EF_IS_NON_CLIENT; | 274 flags |= ui::EF_IS_NON_CLIENT; |
270 MouseEvent translated_event(*event, this, target, event->type(), flags); | 275 MouseEvent translated_event(*event, this, target, event->type(), flags); |
271 return ProcessMouseEvent(target, &translated_event); | 276 return ProcessMouseEvent(target, &translated_event); |
272 } | 277 } |
273 return false; | 278 return false; |
274 } | 279 } |
275 | 280 |
276 bool Desktop::DispatchKeyEvent(KeyEvent* event) { | 281 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_) { | 282 if (focused_window_) { |
286 KeyEvent translated_event(*event); | 283 KeyEvent translated_event(*event); |
287 return ProcessKeyEvent(focused_window_, &translated_event); | 284 return ProcessKeyEvent(focused_window_, &translated_event); |
288 } | 285 } |
289 return false; | 286 return false; |
290 } | 287 } |
291 | 288 |
292 bool Desktop::DispatchTouchEvent(TouchEvent* event) { | 289 bool Desktop::DispatchTouchEvent(TouchEvent* event) { |
293 event->UpdateForTransform(layer()->transform()); | 290 event->UpdateForTransform(layer()->transform()); |
294 bool handled = false; | 291 bool handled = false; |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
404 } | 401 } |
405 | 402 |
406 void Desktop::RemoveObserver(DesktopObserver* observer) { | 403 void Desktop::RemoveObserver(DesktopObserver* observer) { |
407 observers_.RemoveObserver(observer); | 404 observers_.RemoveObserver(observer); |
408 } | 405 } |
409 | 406 |
410 bool Desktop::IsMouseButtonDown() const { | 407 bool Desktop::IsMouseButtonDown() const { |
411 return mouse_button_flags_ != 0; | 408 return mouse_button_flags_ != 0; |
412 } | 409 } |
413 | 410 |
411 bool Desktop::AcceleratorPressed(const ui::Accelerator& accelerator) { | |
Ben Goodger (Google)
2011/11/15 16:28:09
We should just move this to the shell now that you
mazda
2011/11/16 05:40:08
Done.
| |
412 #if !defined(NDEBUG) | |
413 if (accelerator.key_code() == ui::VKEY_F11) { | |
414 return FullScreen(host_.get()); | |
415 } else if (accelerator.key_code() == ui::VKEY_HOME && | |
416 accelerator.IsCtrlDown()) { | |
417 return Rotate(this); | |
418 } | |
419 #endif | |
420 return false; | |
421 } | |
422 | |
423 void Desktop::RegisterAccelerators( | |
424 ui::AcceleratorManager* accelerator_manager) { | |
425 for (size_t i = 0; i < arraysize(kAcceleratorData); ++i) { | |
426 accelerator_manager->Register(ui::Accelerator(kAcceleratorData[i].keycode, | |
427 kAcceleratorData[i].shift, | |
428 kAcceleratorData[i].ctrl, | |
429 kAcceleratorData[i].alt), | |
430 aura::Desktop::GetInstance()); | |
431 } | |
432 } | |
433 | |
414 void Desktop::SetCapture(Window* window) { | 434 void Desktop::SetCapture(Window* window) { |
415 if (capture_window_ == window) | 435 if (capture_window_ == window) |
416 return; | 436 return; |
417 | 437 |
418 if (capture_window_ && capture_window_->delegate()) | 438 if (capture_window_ && capture_window_->delegate()) |
419 capture_window_->delegate()->OnCaptureLost(); | 439 capture_window_->delegate()->OnCaptureLost(); |
420 capture_window_ = window; | 440 capture_window_ = window; |
421 | 441 |
422 if (capture_window_) { | 442 if (capture_window_) { |
423 // Make all subsequent mouse events and touch go to the capture window. We | 443 // Make all subsequent mouse events and touch go to the capture window. We |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
604 base::StringToInt(parts[1], &parsed_height) && parsed_height > 0) { | 624 base::StringToInt(parts[1], &parsed_height) && parsed_height > 0) { |
605 bounds.set_size(gfx::Size(parsed_width, parsed_height)); | 625 bounds.set_size(gfx::Size(parsed_width, parsed_height)); |
606 } else if (use_fullscreen_host_window_) { | 626 } else if (use_fullscreen_host_window_) { |
607 bounds = gfx::Rect(DesktopHost::GetNativeDisplaySize()); | 627 bounds = gfx::Rect(DesktopHost::GetNativeDisplaySize()); |
608 } | 628 } |
609 | 629 |
610 return bounds; | 630 return bounds; |
611 } | 631 } |
612 | 632 |
613 } // namespace aura | 633 } // namespace aura |
OLD | NEW |