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/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 #ifdef USE_WEBKIT_COMPOSITOR | 31 #ifdef USE_WEBKIT_COMPOSITOR |
35 #include "ui/gfx/compositor/compositor_cc.h" | 32 #include "ui/gfx/compositor/compositor_cc.h" |
36 #endif | 33 #endif |
37 | 34 |
38 using std::string; | 35 using std::string; |
39 using std::vector; | 36 using std::vector; |
40 | 37 |
41 namespace aura { | 38 namespace aura { |
42 | 39 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 | 89 |
93 void GetEventFiltersToNotify(Window* target, EventFilters* filters) { | 90 void GetEventFiltersToNotify(Window* target, EventFilters* filters) { |
94 Window* window = target->parent(); | 91 Window* window = target->parent(); |
95 while (window) { | 92 while (window) { |
96 if (window->event_filter()) | 93 if (window->event_filter()) |
97 filters->push_back(window->event_filter()); | 94 filters->push_back(window->event_filter()); |
98 window = window->parent(); | 95 window = window->parent(); |
99 } | 96 } |
100 } | 97 } |
101 | 98 |
102 #if !defined(NDEBUG) | |
103 bool MaybeFullScreen(DesktopHost* host, KeyEvent* event) { | |
104 if (event->key_code() == ui::VKEY_F11) { | |
105 host->ToggleFullScreen(); | |
106 return true; | |
107 } | |
108 return false; | |
109 } | |
110 | |
111 bool MaybeRotate(Desktop* desktop, KeyEvent* event) { | |
112 if ((event->flags() & ui::EF_CONTROL_DOWN) && | |
113 event->key_code() == ui::VKEY_HOME) { | |
114 static int i = 0; | |
115 int delta = 0; | |
116 switch (i) { | |
117 case 0: delta = 90; break; | |
118 case 1: delta = 90; break; | |
119 case 2: delta = 90; break; | |
120 case 3: delta = 90; break; | |
121 case 4: delta = -90; break; | |
122 case 5: delta = -90; break; | |
123 case 6: delta = -90; break; | |
124 case 7: delta = -90; break; | |
125 case 8: delta = -90; break; | |
126 case 9: delta = 180; break; | |
127 case 10: delta = 180; break; | |
128 case 11: delta = 90; break; | |
129 case 12: delta = 180; break; | |
130 case 13: delta = 180; break; | |
131 } | |
132 i = (i + 1) % 14; | |
133 desktop->layer()->GetAnimator()->set_preemption_strategy( | |
134 ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS); | |
135 scoped_ptr<ui::LayerAnimationSequence> screen_rotation( | |
136 new ui::LayerAnimationSequence(new ui::ScreenRotation(delta))); | |
137 screen_rotation->AddObserver(desktop); | |
138 desktop->layer()->GetAnimator()->ScheduleAnimation( | |
139 screen_rotation.release()); | |
140 return true; | |
141 } | |
142 return false; | |
143 } | |
144 #endif | |
145 | |
146 } // namespace | 99 } // namespace |
147 | 100 |
148 Desktop* Desktop::instance_ = NULL; | 101 Desktop* Desktop::instance_ = NULL; |
149 bool Desktop::use_fullscreen_host_window_ = false; | 102 bool Desktop::use_fullscreen_host_window_ = false; |
150 | 103 |
151 Desktop::Desktop() | 104 Desktop::Desktop() |
152 : Window(NULL), | 105 : Window(NULL), |
153 host_(aura::DesktopHost::Create(GetInitialHostWindowBounds())), | 106 host_(aura::DesktopHost::Create(GetInitialHostWindowBounds())), |
154 ALLOW_THIS_IN_INITIALIZER_LIST( | 107 ALLOW_THIS_IN_INITIALIZER_LIST( |
155 stacking_client_(new DefaultStackingClient(this))), | 108 stacking_client_(new DefaultStackingClient(this))), |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 Window::ConvertPointToWindow(this, target, &location_in_window); | 231 Window::ConvertPointToWindow(this, target, &location_in_window); |
279 if (IsNonClientLocation(target, location_in_window)) | 232 if (IsNonClientLocation(target, location_in_window)) |
280 flags |= ui::EF_IS_NON_CLIENT; | 233 flags |= ui::EF_IS_NON_CLIENT; |
281 MouseEvent translated_event(*event, this, target, event->type(), flags); | 234 MouseEvent translated_event(*event, this, target, event->type(), flags); |
282 return ProcessMouseEvent(target, &translated_event); | 235 return ProcessMouseEvent(target, &translated_event); |
283 } | 236 } |
284 return false; | 237 return false; |
285 } | 238 } |
286 | 239 |
287 bool Desktop::DispatchKeyEvent(KeyEvent* event) { | 240 bool Desktop::DispatchKeyEvent(KeyEvent* event) { |
288 #if !defined(NDEBUG) | |
289 // TODO(beng): replace this hack with global keyboard event handlers. | |
290 if (event->type() == ui::ET_KEY_PRESSED) { | |
291 if (MaybeFullScreen(host_.get(), event) || MaybeRotate(this, event)) | |
292 return true; | |
293 } | |
294 #endif | |
295 | |
296 if (focused_window_) { | 241 if (focused_window_) { |
297 KeyEvent translated_event(*event); | 242 KeyEvent translated_event(*event); |
298 return ProcessKeyEvent(focused_window_, &translated_event); | 243 return ProcessKeyEvent(focused_window_, &translated_event); |
299 } | 244 } |
300 return false; | 245 return false; |
301 } | 246 } |
302 | 247 |
303 bool Desktop::DispatchTouchEvent(TouchEvent* event) { | 248 bool Desktop::DispatchTouchEvent(TouchEvent* event) { |
304 event->UpdateForTransform(layer()->transform()); | 249 event->UpdateForTransform(layer()->transform()); |
305 bool handled = false; | 250 bool handled = false; |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
463 | 408 |
464 void Desktop::SetTransform(const ui::Transform& transform) { | 409 void Desktop::SetTransform(const ui::Transform& transform) { |
465 Window::SetTransform(transform); | 410 Window::SetTransform(transform); |
466 | 411 |
467 // If the layer is not animating, then we need to update the host size | 412 // If the layer is not animating, then we need to update the host size |
468 // immediately. | 413 // immediately. |
469 if (!layer()->GetAnimator()->is_animating()) | 414 if (!layer()->GetAnimator()->is_animating()) |
470 OnHostResized(host_->GetSize()); | 415 OnHostResized(host_->GetSize()); |
471 } | 416 } |
472 | 417 |
| 418 #if !defined(NDEBUG) |
| 419 void Desktop::ToggleFullScreen() { |
| 420 host_->ToggleFullScreen(); |
| 421 } |
| 422 #endif |
| 423 |
473 void Desktop::HandleMouseMoved(const MouseEvent& event, Window* target) { | 424 void Desktop::HandleMouseMoved(const MouseEvent& event, Window* target) { |
474 if (target == mouse_moved_handler_) | 425 if (target == mouse_moved_handler_) |
475 return; | 426 return; |
476 | 427 |
477 // Send an exited event. | 428 // Send an exited event. |
478 if (mouse_moved_handler_ && mouse_moved_handler_->delegate()) { | 429 if (mouse_moved_handler_ && mouse_moved_handler_->delegate()) { |
479 MouseEvent translated_event(event, this, mouse_moved_handler_, | 430 MouseEvent translated_event(event, this, mouse_moved_handler_, |
480 ui::ET_MOUSE_EXITED, event.flags()); | 431 ui::ET_MOUSE_EXITED, event.flags()); |
481 ProcessMouseEvent(mouse_moved_handler_, &translated_event); | 432 ProcessMouseEvent(mouse_moved_handler_, &translated_event); |
482 } | 433 } |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
629 base::StringToInt(parts[1], &parsed_height) && parsed_height > 0) { | 580 base::StringToInt(parts[1], &parsed_height) && parsed_height > 0) { |
630 bounds.set_size(gfx::Size(parsed_width, parsed_height)); | 581 bounds.set_size(gfx::Size(parsed_width, parsed_height)); |
631 } else if (use_fullscreen_host_window_) { | 582 } else if (use_fullscreen_host_window_) { |
632 bounds = gfx::Rect(DesktopHost::GetNativeDisplaySize()); | 583 bounds = gfx::Rect(DesktopHost::GetNativeDisplaySize()); |
633 } | 584 } |
634 | 585 |
635 return bounds; | 586 return bounds; |
636 } | 587 } |
637 | 588 |
638 } // namespace aura | 589 } // namespace aura |
OLD | NEW |