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/desktop_delegate.h" | 17 #include "ui/aura/desktop_delegate.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/screen_rotation.h" |
24 #include "ui/aura/toplevel_window_container.h" | 25 #include "ui/aura/toplevel_window_container.h" |
25 #include "ui/aura/window.h" | 26 #include "ui/aura/window.h" |
26 #include "ui/aura/window_delegate.h" | 27 #include "ui/aura/window_delegate.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" |
| 30 #include "ui/gfx/compositor/layer_animation_sequence.h" |
| 31 #include "ui/gfx/compositor/layer_animator.h" |
| 32 #include "ui/gfx/interpolated_transform.h" |
29 | 33 |
30 using std::string; | 34 using std::string; |
31 using std::vector; | 35 using std::vector; |
32 | 36 |
33 namespace aura { | 37 namespace aura { |
34 | 38 |
35 namespace { | 39 namespace { |
36 | 40 |
37 // Default bounds for the host window. | 41 // Default bounds for the host window. |
38 static const int kDefaultHostWindowX = 200; | 42 static const int kDefaultHostWindowX = 200; |
39 static const int kDefaultHostWindowY = 200; | 43 static const int kDefaultHostWindowY = 200; |
40 static const int kDefaultHostWindowWidth = 1280; | 44 static const int kDefaultHostWindowWidth = 1280; |
41 static const int kDefaultHostWindowHeight = 1024; | 45 static const int kDefaultHostWindowHeight = 1024; |
42 | 46 |
| 47 #if !defined(NDEBUG) |
| 48 // Converts degrees to an angle in the range [-180, 180). |
| 49 int NormalizeAngle(int degrees) { |
| 50 while (degrees <= -180) degrees += 360; |
| 51 while (degrees > 180) degrees -= 360; |
| 52 return degrees; |
| 53 } |
| 54 |
| 55 static int SymmetricRound(float x) { |
| 56 return static_cast<int>( |
| 57 x > 0 |
| 58 ? std::floor(x + 0.5f) |
| 59 : std::ceil(x - 0.5f)); |
| 60 } |
| 61 #endif |
| 62 |
43 class DefaultDesktopDelegate : public DesktopDelegate { | 63 class DefaultDesktopDelegate : public DesktopDelegate { |
44 public: | 64 public: |
45 explicit DefaultDesktopDelegate(Desktop* desktop) : desktop_(desktop) {} | 65 explicit DefaultDesktopDelegate(Desktop* desktop) : desktop_(desktop) {} |
46 virtual ~DefaultDesktopDelegate() {} | 66 virtual ~DefaultDesktopDelegate() {} |
47 | 67 |
48 private: | 68 private: |
49 virtual void AddChildToDefaultParent(Window* window) OVERRIDE { | 69 virtual void AddChildToDefaultParent(Window* window) OVERRIDE { |
50 desktop_->AddChild(window); | 70 desktop_->AddChild(window); |
51 } | 71 } |
52 | 72 |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 } | 272 } |
253 if (target && target->delegate()) { | 273 if (target && target->delegate()) { |
254 MouseEvent translated_event(*event, this, target); | 274 MouseEvent translated_event(*event, this, target); |
255 return ProcessMouseEvent(target, &translated_event); | 275 return ProcessMouseEvent(target, &translated_event); |
256 } | 276 } |
257 return false; | 277 return false; |
258 } | 278 } |
259 | 279 |
260 bool Desktop::DispatchKeyEvent(KeyEvent* event) { | 280 bool Desktop::DispatchKeyEvent(KeyEvent* event) { |
261 #if !defined(NDEBUG) | 281 #if !defined(NDEBUG) |
262 // Press Home key to rotate the screen. Primarily used for testing. | |
263 if (event->type() == ui::ET_KEY_PRESSED && | 282 if (event->type() == ui::ET_KEY_PRESSED && |
264 (event->flags() & ui::EF_CONTROL_DOWN) && | 283 (event->flags() & ui::EF_SHIFT_DOWN) && |
265 event->key_code() == ui::VKEY_HOME) { | 284 (event->flags() & ui::EF_ALT_DOWN) && |
266 ui::Transform transform; | 285 event->is_char()) { |
267 static int count = 0; | 286 |
268 gfx::Size size = host_->GetSize(); | 287 bool should_rotate = true; |
269 switch (count) { | 288 int new_degrees = 0; |
270 case 0: | 289 switch (event->key_code()) { |
271 transform.ConcatRotate(-90.0f); | 290 case ui::VKEY_UP: new_degrees = 0; break; |
272 transform.ConcatTranslate(0, size.height()); | 291 case ui::VKEY_DOWN: new_degrees = 180; break; |
273 break; | 292 case ui::VKEY_RIGHT: new_degrees = 90; break; |
274 case 1: | 293 case ui::VKEY_LEFT: new_degrees = -90; break; |
275 transform.ConcatRotate(180.0f); | 294 default: should_rotate = false; break; |
276 transform.ConcatTranslate(size.width(), size.height()); | |
277 break; | |
278 case 2: | |
279 transform.ConcatRotate(90.0f); | |
280 transform.ConcatTranslate(size.width(), 0); | |
281 break; | |
282 } | 295 } |
283 layer()->SetAnimation(CreateDefaultAnimation()); | 296 |
284 SetTransform(transform); | 297 if (should_rotate) { |
285 count = (count + 1) % 4; | 298 float rotation = 0.0f; |
286 return true; | 299 int degrees = 0; |
| 300 const ui::Transform& transform = layer()->GetTargetTransform(); |
| 301 if (ui::InterpolatedTransform::FactorTRS(transform, |
| 302 NULL, &rotation, NULL)) |
| 303 degrees = NormalizeAngle(new_degrees - SymmetricRound(rotation)); |
| 304 |
| 305 if (degrees != 0) { |
| 306 layer()->GetAnimator()->set_preemption_strategy( |
| 307 ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS); |
| 308 layer()->GetAnimator()->ScheduleAnimationElement( |
| 309 new ScreenRotation(degrees)); |
| 310 return true; |
| 311 } |
| 312 } |
287 } | 313 } |
288 #endif | 314 #endif |
289 | 315 |
290 if (focused_window_) { | 316 if (focused_window_) { |
291 KeyEvent translated_event(*event); | 317 KeyEvent translated_event(*event); |
292 return ProcessKeyEvent(focused_window_, &translated_event); | 318 return ProcessKeyEvent(focused_window_, &translated_event); |
293 } | 319 } |
294 return false; | 320 return false; |
295 } | 321 } |
296 | 322 |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
435 if (capture_window_ && capture_window_->delegate()) | 461 if (capture_window_ && capture_window_->delegate()) |
436 capture_window_->delegate()->OnCaptureLost(); | 462 capture_window_->delegate()->OnCaptureLost(); |
437 capture_window_ = NULL; | 463 capture_window_ = NULL; |
438 } | 464 } |
439 | 465 |
440 void Desktop::SetTransform(const ui::Transform& transform) { | 466 void Desktop::SetTransform(const ui::Transform& transform) { |
441 Window::SetTransform(transform); | 467 Window::SetTransform(transform); |
442 | 468 |
443 // If the layer is not animating, then we need to update the host size | 469 // If the layer is not animating, then we need to update the host size |
444 // immediately. | 470 // immediately. |
445 if (!layer()->has_animation()) | 471 if (!layer()->GetAnimator()->is_animating()) |
446 OnHostResized(host_->GetSize()); | 472 OnHostResized(host_->GetSize()); |
447 } | 473 } |
448 | 474 |
449 void Desktop::HandleMouseMoved(const MouseEvent& event, Window* target) { | 475 void Desktop::HandleMouseMoved(const MouseEvent& event, Window* target) { |
450 if (target == mouse_moved_handler_) | 476 if (target == mouse_moved_handler_) |
451 return; | 477 return; |
452 | 478 |
453 // Send an exited event. | 479 // Send an exited event. |
454 if (mouse_moved_handler_ && mouse_moved_handler_->delegate()) { | 480 if (mouse_moved_handler_ && mouse_moved_handler_->delegate()) { |
455 MouseEvent translated_event(event, this, mouse_moved_handler_, | 481 MouseEvent translated_event(event, this, mouse_moved_handler_, |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
524 } | 550 } |
525 | 551 |
526 internal::FocusManager* Desktop::GetFocusManager() { | 552 internal::FocusManager* Desktop::GetFocusManager() { |
527 return this; | 553 return this; |
528 } | 554 } |
529 | 555 |
530 Desktop* Desktop::GetDesktop() { | 556 Desktop* Desktop::GetDesktop() { |
531 return this; | 557 return this; |
532 } | 558 } |
533 | 559 |
534 void Desktop::OnLayerAnimationEnded(const ui::Animation* animation) { | 560 void Desktop::OnLayerAnimationEnded( |
| 561 const ui::LayerAnimationSequence* animation) { |
535 OnHostResized(host_->GetSize()); | 562 OnHostResized(host_->GetSize()); |
536 } | 563 } |
537 | 564 |
538 void Desktop::SetFocusedWindow(Window* focused_window) { | 565 void Desktop::SetFocusedWindow(Window* focused_window) { |
539 if (focused_window == focused_window_ || | 566 if (focused_window == focused_window_ || |
540 (focused_window && !focused_window->CanFocus())) { | 567 (focused_window && !focused_window->CanFocus())) { |
541 return; | 568 return; |
542 } | 569 } |
543 if (focused_window_ && focused_window_->delegate()) | 570 if (focused_window_ && focused_window_->delegate()) |
544 focused_window_->delegate()->OnBlur(); | 571 focused_window_->delegate()->OnBlur(); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
576 base::StringToInt(parts[1], &parsed_height) && parsed_height > 0) { | 603 base::StringToInt(parts[1], &parsed_height) && parsed_height > 0) { |
577 bounds.set_size(gfx::Size(parsed_width, parsed_height)); | 604 bounds.set_size(gfx::Size(parsed_width, parsed_height)); |
578 } else if (use_fullscreen_host_window_) { | 605 } else if (use_fullscreen_host_window_) { |
579 bounds = gfx::Rect(DesktopHost::GetNativeDisplaySize()); | 606 bounds = gfx::Rect(DesktopHost::GetNativeDisplaySize()); |
580 } | 607 } |
581 | 608 |
582 return bounds; | 609 return bounds; |
583 } | 610 } |
584 | 611 |
585 } // namespace aura | 612 } // namespace aura |
OLD | NEW |