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