OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "athena/wm/window_overview_mode.h" | 5 #include "athena/wm/window_overview_mode.h" |
6 | 6 |
7 #include <complex> | 7 #include <complex> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "athena/wm/overview_toolbar.h" | 10 #include "athena/wm/overview_toolbar.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 // |split| is set if this window is one of the two split windows in split-view | 47 // |split| is set if this window is one of the two split windows in split-view |
48 // mode. | 48 // mode. |
49 bool split; | 49 bool split; |
50 }; | 50 }; |
51 | 51 |
52 } // namespace | 52 } // namespace |
53 | 53 |
54 DECLARE_WINDOW_PROPERTY_TYPE(WindowOverviewState*); | 54 DECLARE_WINDOW_PROPERTY_TYPE(WindowOverviewState*); |
55 DEFINE_OWNED_WINDOW_PROPERTY_KEY(WindowOverviewState, | 55 DEFINE_OWNED_WINDOW_PROPERTY_KEY(WindowOverviewState, |
56 kWindowOverviewState, | 56 kWindowOverviewState, |
57 NULL); | 57 nullptr); |
58 | 58 |
59 namespace athena { | 59 namespace athena { |
60 | 60 |
61 namespace { | 61 namespace { |
62 | 62 |
63 const float kOverviewDefaultScale = 0.75f; | 63 const float kOverviewDefaultScale = 0.75f; |
64 | 64 |
65 gfx::Transform GetTransformForSplitWindow(aura::Window* window, float scale) { | 65 gfx::Transform GetTransformForSplitWindow(aura::Window* window, float scale) { |
66 const float kScrollWindowPositionInOverview = 0.65f; | 66 const float kScrollWindowPositionInOverview = 0.65f; |
67 int x_translate = window->bounds().width() * (1 - scale) / 2; | 67 int x_translate = window->bounds().width() * (1 - scale) / 2; |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 SplitViewController* split_view_controller, | 290 SplitViewController* split_view_controller, |
291 WindowOverviewModeDelegate* delegate) | 291 WindowOverviewModeDelegate* delegate) |
292 : container_(container), | 292 : container_(container), |
293 window_list_provider_(window_list_provider), | 293 window_list_provider_(window_list_provider), |
294 split_view_controller_(split_view_controller), | 294 split_view_controller_(split_view_controller), |
295 delegate_(delegate), | 295 delegate_(delegate), |
296 scoped_targeter_(new aura::ScopedWindowTargeter( | 296 scoped_targeter_(new aura::ScopedWindowTargeter( |
297 container, | 297 container, |
298 scoped_ptr<ui::EventTargeter>( | 298 scoped_ptr<ui::EventTargeter>( |
299 new StaticWindowTargeter(container)))), | 299 new StaticWindowTargeter(container)))), |
300 dragged_window_(NULL) { | 300 dragged_window_(nullptr) { |
301 CHECK(delegate_); | 301 CHECK(delegate_); |
302 container_->set_target_handler(this); | 302 container_->set_target_handler(this); |
303 | 303 |
304 // Prepare the desired transforms for all the windows, and set the initial | 304 // Prepare the desired transforms for all the windows, and set the initial |
305 // state on the windows. | 305 // state on the windows. |
306 ComputeTerminalStatesForAllWindows(); | 306 ComputeTerminalStatesForAllWindows(); |
307 SetInitialWindowStates(); | 307 SetInitialWindowStates(); |
308 | 308 |
309 window_list_provider_->AddObserver(this); | 309 window_list_provider_->AddObserver(this); |
310 } | 310 } |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
418 aura::Window* SelectWindowAt(ui::LocatedEvent* event) { | 418 aura::Window* SelectWindowAt(ui::LocatedEvent* event) { |
419 CHECK_EQ(container_, event->target()); | 419 CHECK_EQ(container_, event->target()); |
420 // Find the old targeter to find the target of the event. | 420 // Find the old targeter to find the target of the event. |
421 ui::EventTarget* window = container_; | 421 ui::EventTarget* window = container_; |
422 ui::EventTargeter* targeter = scoped_targeter_->old_targeter(); | 422 ui::EventTargeter* targeter = scoped_targeter_->old_targeter(); |
423 while (!targeter && window->GetParentTarget()) { | 423 while (!targeter && window->GetParentTarget()) { |
424 window = window->GetParentTarget(); | 424 window = window->GetParentTarget(); |
425 targeter = window->GetEventTargeter(); | 425 targeter = window->GetEventTargeter(); |
426 } | 426 } |
427 if (!targeter) | 427 if (!targeter) |
428 return NULL; | 428 return nullptr; |
429 aura::Window* target = static_cast<aura::Window*>( | 429 aura::Window* target = static_cast<aura::Window*>( |
430 targeter->FindTargetForLocatedEvent(container_, event)); | 430 targeter->FindTargetForLocatedEvent(container_, event)); |
431 while (target && target->parent() != container_) | 431 while (target && target->parent() != container_) |
432 target = target->parent(); | 432 target = target->parent(); |
433 aura::Window* transient_parent = | 433 aura::Window* transient_parent = |
434 target ? wm::GetTransientParent(target) : NULL; | 434 target ? wm::GetTransientParent(target) : nullptr; |
435 return transient_parent ? transient_parent : target; | 435 return transient_parent ? transient_parent : target; |
436 } | 436 } |
437 | 437 |
438 // Scroll the window list by |delta_y| amount. |delta_y| is negative when | 438 // Scroll the window list by |delta_y| amount. |delta_y| is negative when |
439 // scrolling up; and positive when scrolling down. | 439 // scrolling up; and positive when scrolling down. |
440 void DoScroll(float delta_y) { | 440 void DoScroll(float delta_y) { |
441 const float kEpsilon = 1e-3f; | 441 const float kEpsilon = 1e-3f; |
442 float delta_y_p = std::abs(delta_y) / GetScrollableHeight(); | 442 float delta_y_p = std::abs(delta_y) / GetScrollableHeight(); |
443 const aura::Window::Windows& windows = | 443 const aura::Window::Windows& windows = |
444 window_list_provider_->GetWindowList(); | 444 window_list_provider_->GetWindowList(); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
501 } | 501 } |
502 | 502 |
503 void RemoveAnimationObserver() { | 503 void RemoveAnimationObserver() { |
504 ui::Compositor* compositor = container_->GetHost()->compositor(); | 504 ui::Compositor* compositor = container_->GetHost()->compositor(); |
505 if (compositor->HasAnimationObserver(this)) | 505 if (compositor->HasAnimationObserver(this)) |
506 compositor->RemoveAnimationObserver(this); | 506 compositor->RemoveAnimationObserver(this); |
507 } | 507 } |
508 | 508 |
509 aura::Window* GetSplitWindowDropTarget(const ui::GestureEvent& event) const { | 509 aura::Window* GetSplitWindowDropTarget(const ui::GestureEvent& event) const { |
510 if (!split_view_controller_->IsSplitViewModeActive()) | 510 if (!split_view_controller_->IsSplitViewModeActive()) |
511 return NULL; | 511 return nullptr; |
512 CHECK(dragged_window_); | 512 CHECK(dragged_window_); |
513 CHECK_NE(split_view_controller_->left_window(), dragged_window_); | 513 CHECK_NE(split_view_controller_->left_window(), dragged_window_); |
514 CHECK_NE(split_view_controller_->right_window(), dragged_window_); | 514 CHECK_NE(split_view_controller_->right_window(), dragged_window_); |
515 aura::Window* window = split_view_controller_->left_window(); | 515 aura::Window* window = split_view_controller_->left_window(); |
516 if (GetTransformedBounds(window).Contains(event.location())) | 516 if (GetTransformedBounds(window).Contains(event.location())) |
517 return window; | 517 return window; |
518 window = split_view_controller_->right_window(); | 518 window = split_view_controller_->right_window(); |
519 if (GetTransformedBounds(window).Contains(event.location())) | 519 if (GetTransformedBounds(window).Contains(event.location())) |
520 return window; | 520 return window; |
521 return NULL; | 521 return nullptr; |
522 } | 522 } |
523 | 523 |
524 void DragWindow(const ui::GestureEvent& event) { | 524 void DragWindow(const ui::GestureEvent& event) { |
525 CHECK(dragged_window_); | 525 CHECK(dragged_window_); |
526 CHECK_EQ(ui::ET_GESTURE_SCROLL_UPDATE, event.type()); | 526 CHECK_EQ(ui::ET_GESTURE_SCROLL_UPDATE, event.type()); |
527 CHECK(overview_toolbar_); | 527 CHECK(overview_toolbar_); |
528 gfx::Vector2dF dragged_distance = | 528 gfx::Vector2dF dragged_distance = |
529 dragged_start_location_ - event.location(); | 529 dragged_start_location_ - event.location(); |
530 WindowOverviewState* dragged_state = | 530 WindowOverviewState* dragged_state = |
531 dragged_window_->GetProperty(kWindowOverviewState); | 531 dragged_window_->GetProperty(kWindowOverviewState); |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
624 float transform_x = 0.f; | 624 float transform_x = 0.f; |
625 if (gesture.location().x() > dragged_start_location_.x()) | 625 if (gesture.location().x() > dragged_start_location_.x()) |
626 transform_x = container_->bounds().right() - transformed_bounds.x(); | 626 transform_x = container_->bounds().right() - transformed_bounds.x(); |
627 else | 627 else |
628 transform_x = -(transformed_bounds.x() + transformed_bounds.width()); | 628 transform_x = -(transformed_bounds.x() + transformed_bounds.width()); |
629 transform.Translate(transform_x / kOverviewDefaultScale, 0); | 629 transform.Translate(transform_x / kOverviewDefaultScale, 0); |
630 | 630 |
631 setter.SetOpacity(kMinOpacity); | 631 setter.SetOpacity(kMinOpacity); |
632 } | 632 } |
633 delete dragged_window_; | 633 delete dragged_window_; |
634 dragged_window_ = NULL; | 634 dragged_window_ = nullptr; |
635 } | 635 } |
636 | 636 |
637 void RestoreDragWindow() { | 637 void RestoreDragWindow() { |
638 CHECK(dragged_window_); | 638 CHECK(dragged_window_); |
639 WindowOverviewState* dragged_state = | 639 WindowOverviewState* dragged_state = |
640 dragged_window_->GetProperty(kWindowOverviewState); | 640 dragged_window_->GetProperty(kWindowOverviewState); |
641 CHECK(dragged_state); | 641 CHECK(dragged_state); |
642 | 642 |
643 AnimateTransientGroupSetter setter(dragged_window_); | 643 AnimateTransientGroupSetter setter(dragged_window_); |
644 setter.SetTransform(GetTransformForState(dragged_window_, dragged_state)); | 644 setter.SetTransform(GetTransformForState(dragged_window_, dragged_state)); |
645 setter.SetOpacity(1.0f); | 645 setter.SetOpacity(1.0f); |
646 dragged_window_ = NULL; | 646 dragged_window_ = nullptr; |
647 } | 647 } |
648 | 648 |
649 void EndDragWindow(const ui::GestureEvent& gesture) { | 649 void EndDragWindow(const ui::GestureEvent& gesture) { |
650 CHECK(dragged_window_); | 650 CHECK(dragged_window_); |
651 CHECK(overview_toolbar_); | 651 CHECK(overview_toolbar_); |
652 OverviewToolbar::ActionType action = overview_toolbar_->current_action(); | 652 OverviewToolbar::ActionType action = overview_toolbar_->current_action(); |
653 overview_toolbar_.reset(); | 653 overview_toolbar_.reset(); |
654 if (action == OverviewToolbar::ACTION_TYPE_SPLIT) { | 654 if (action == OverviewToolbar::ACTION_TYPE_SPLIT) { |
655 delegate_->OnSelectSplitViewWindow(NULL, | 655 delegate_->OnSelectSplitViewWindow( |
656 dragged_window_, | 656 nullptr, dragged_window_, dragged_window_); |
657 dragged_window_); | |
658 return; | 657 return; |
659 } | 658 } |
660 | 659 |
661 // If the window is dropped on one of the left/right windows in split-mode, | 660 // If the window is dropped on one of the left/right windows in split-mode, |
662 // then switch that window. | 661 // then switch that window. |
663 aura::Window* split_drop = GetSplitWindowDropTarget(gesture); | 662 aura::Window* split_drop = GetSplitWindowDropTarget(gesture); |
664 if (split_drop) { | 663 if (split_drop) { |
665 aura::Window* left = split_view_controller_->left_window(); | 664 aura::Window* left = split_view_controller_->left_window(); |
666 aura::Window* right = split_view_controller_->right_window(); | 665 aura::Window* right = split_view_controller_->right_window(); |
667 if (left == split_drop) | 666 if (left == split_drop) |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
726 std::abs(gesture->details().scroll_y_hint()) * 2) { | 725 std::abs(gesture->details().scroll_y_hint()) * 2) { |
727 dragged_start_location_ = gesture->location(); | 726 dragged_start_location_ = gesture->location(); |
728 dragged_window_ = SelectWindowAt(gesture); | 727 dragged_window_ = SelectWindowAt(gesture); |
729 if (split_view_controller_->IsSplitViewModeActive() && | 728 if (split_view_controller_->IsSplitViewModeActive() && |
730 (dragged_window_ == split_view_controller_->left_window() || | 729 (dragged_window_ == split_view_controller_->left_window() || |
731 dragged_window_ == split_view_controller_->right_window())) { | 730 dragged_window_ == split_view_controller_->right_window())) { |
732 // TODO(sad): Allow closing the left/right window. Closing one of | 731 // TODO(sad): Allow closing the left/right window. Closing one of |
733 // these windows will terminate the split-view mode. Until then, do | 732 // these windows will terminate the split-view mode. Until then, do |
734 // not allow closing these (since otherwise it gets into an undefined | 733 // not allow closing these (since otherwise it gets into an undefined |
735 // state). | 734 // state). |
736 dragged_window_ = NULL; | 735 dragged_window_ = nullptr; |
737 } | 736 } |
738 | 737 |
739 if (dragged_window_) { | 738 if (dragged_window_) { |
740 // Show the toolbar (for closing a window, or going into split-view | 739 // Show the toolbar (for closing a window, or going into split-view |
741 // mode). If already in split-view mode, then do not show the 'Split' | 740 // mode). If already in split-view mode, then do not show the 'Split' |
742 // option. | 741 // option. |
743 overview_toolbar_.reset(new OverviewToolbar(container_)); | 742 overview_toolbar_.reset(new OverviewToolbar(container_)); |
744 if (!split_view_controller_->CanActivateSplitViewMode()) { | 743 if (!split_view_controller_->CanActivateSplitViewMode()) { |
745 overview_toolbar_->DisableAction( | 744 overview_toolbar_->DisableAction( |
746 OverviewToolbar::ACTION_TYPE_SPLIT); | 745 OverviewToolbar::ACTION_TYPE_SPLIT); |
(...skipping 17 matching lines...) Expand all Loading... |
764 CreateFlingerFor(*gesture); | 763 CreateFlingerFor(*gesture); |
765 AddAnimationObserver(); | 764 AddAnimationObserver(); |
766 } | 765 } |
767 gesture->SetHandled(); | 766 gesture->SetHandled(); |
768 } else if (gesture->type() == ui::ET_GESTURE_TAP_DOWN) { | 767 } else if (gesture->type() == ui::ET_GESTURE_TAP_DOWN) { |
769 if (fling_) { | 768 if (fling_) { |
770 fling_.reset(); | 769 fling_.reset(); |
771 RemoveAnimationObserver(); | 770 RemoveAnimationObserver(); |
772 gesture->SetHandled(); | 771 gesture->SetHandled(); |
773 } | 772 } |
774 dragged_window_ = NULL; | 773 dragged_window_ = nullptr; |
775 } | 774 } |
776 } | 775 } |
777 | 776 |
778 // ui::CompositorAnimationObserver: | 777 // ui::CompositorAnimationObserver: |
779 virtual void OnAnimationStep(base::TimeTicks timestamp) override { | 778 virtual void OnAnimationStep(base::TimeTicks timestamp) override { |
780 CHECK(fling_); | 779 CHECK(fling_); |
781 gfx::Vector2dF delta; | 780 gfx::Vector2dF delta; |
782 bool fling_active = fling_->ComputeScrollDeltaAtTime(timestamp, &delta); | 781 bool fling_active = fling_->ComputeScrollDeltaAtTime(timestamp, &delta); |
783 | 782 |
784 if (!delta.IsZero()) | 783 if (!delta.IsZero()) |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
859 aura::Window* container, | 858 aura::Window* container, |
860 WindowListProvider* window_list_provider, | 859 WindowListProvider* window_list_provider, |
861 SplitViewController* split_view_controller, | 860 SplitViewController* split_view_controller, |
862 WindowOverviewModeDelegate* delegate) { | 861 WindowOverviewModeDelegate* delegate) { |
863 return scoped_ptr<WindowOverviewMode>( | 862 return scoped_ptr<WindowOverviewMode>( |
864 new WindowOverviewModeImpl(container, window_list_provider, | 863 new WindowOverviewModeImpl(container, window_list_provider, |
865 split_view_controller, delegate)); | 864 split_view_controller, delegate)); |
866 } | 865 } |
867 | 866 |
868 } // namespace athena | 867 } // namespace athena |
OLD | NEW |