| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "ash/common/wm/overview/window_selector_item.h" | 5 #include "ash/common/wm/overview/window_selector_item.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "ash/common/material_design/material_design_controller.h" | 10 #include "ash/common/material_design/material_design_controller.h" |
| 11 #include "ash/common/metrics/user_metrics_action.h" | 11 #include "ash/common/metrics/user_metrics_action.h" |
| 12 #include "ash/common/strings/grit/ash_strings.h" | 12 #include "ash/common/strings/grit/ash_strings.h" |
| 13 #include "ash/common/wm/overview/cleanup_animation_observer.h" | 13 #include "ash/common/wm/overview/cleanup_animation_observer.h" |
| 14 #include "ash/common/wm/overview/overview_animation_type.h" | 14 #include "ash/common/wm/overview/overview_animation_type.h" |
| 15 #include "ash/common/wm/overview/scoped_overview_animation_settings.h" | 15 #include "ash/common/wm/overview/scoped_overview_animation_settings.h" |
| 16 #include "ash/common/wm/overview/scoped_overview_animation_settings_factory.h" | 16 #include "ash/common/wm/overview/scoped_overview_animation_settings_factory.h" |
| 17 #include "ash/common/wm/overview/scoped_transform_overview_window.h" | 17 #include "ash/common/wm/overview/scoped_transform_overview_window.h" |
| 18 #include "ash/common/wm/overview/window_selector.h" | 18 #include "ash/common/wm/overview/window_selector.h" |
| 19 #include "ash/common/wm/overview/window_selector_controller.h" | 19 #include "ash/common/wm/overview/window_selector_controller.h" |
| 20 #include "ash/common/wm/window_state.h" | 20 #include "ash/common/wm/window_state.h" |
| 21 #include "ash/common/wm_lookup.h" | |
| 22 #include "ash/common/wm_shell.h" | 21 #include "ash/common/wm_shell.h" |
| 23 #include "ash/common/wm_window.h" | 22 #include "ash/common/wm_window.h" |
| 24 #include "ash/common/wm_window_property.h" | 23 #include "ash/common/wm_window_property.h" |
| 25 #include "ash/public/cpp/shell_window_ids.h" | 24 #include "ash/public/cpp/shell_window_ids.h" |
| 26 #include "ash/resources/vector_icons/vector_icons.h" | 25 #include "ash/resources/vector_icons/vector_icons.h" |
| 27 #include "ash/root_window_controller.h" | 26 #include "ash/root_window_controller.h" |
| 28 #include "base/auto_reset.h" | 27 #include "base/auto_reset.h" |
| 29 #include "base/strings/string_util.h" | 28 #include "base/strings/string_util.h" |
| 30 #include "base/strings/utf_string_conversions.h" | 29 #include "base/strings/utf_string_conversions.h" |
| 31 #include "base/time/time.h" | 30 #include "base/time/time.h" |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 static const int kExitFadeInMilliseconds = 30; | 101 static const int kExitFadeInMilliseconds = 30; |
| 103 | 102 |
| 104 // Before closing a window animate both the window and the caption to shrink by | 103 // Before closing a window animate both the window and the caption to shrink by |
| 105 // this fraction of size. | 104 // this fraction of size. |
| 106 static const float kPreCloseScale = 0.02f; | 105 static const float kPreCloseScale = 0.02f; |
| 107 | 106 |
| 108 // Convenience method to fade in a Window with predefined animation settings. | 107 // Convenience method to fade in a Window with predefined animation settings. |
| 109 // Note: The fade in animation will occur after a delay where the delay is how | 108 // Note: The fade in animation will occur after a delay where the delay is how |
| 110 // long the lay out animations take. | 109 // long the lay out animations take. |
| 111 void SetupFadeInAfterLayout(views::Widget* widget) { | 110 void SetupFadeInAfterLayout(views::Widget* widget) { |
| 112 WmWindow* window = WmLookup::Get()->GetWindowForWidget(widget); | 111 WmWindow* window = WmWindow::Get(widget->GetNativeWindow()); |
| 113 window->SetOpacity(0.0f); | 112 window->SetOpacity(0.0f); |
| 114 std::unique_ptr<ScopedOverviewAnimationSettings> | 113 std::unique_ptr<ScopedOverviewAnimationSettings> |
| 115 scoped_overview_animation_settings = | 114 scoped_overview_animation_settings = |
| 116 ScopedOverviewAnimationSettingsFactory::Get() | 115 ScopedOverviewAnimationSettingsFactory::Get() |
| 117 ->CreateOverviewAnimationSettings( | 116 ->CreateOverviewAnimationSettings( |
| 118 OverviewAnimationType:: | 117 OverviewAnimationType:: |
| 119 OVERVIEW_ANIMATION_ENTER_OVERVIEW_MODE_FADE_IN, | 118 OVERVIEW_ANIMATION_ENTER_OVERVIEW_MODE_FADE_IN, |
| 120 window); | 119 window); |
| 121 window->SetOpacity(1.0f); | 120 window->SetOpacity(1.0f); |
| 122 } | 121 } |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 const char* GetClassName() const override { return "RoundedContainerView"; } | 280 const char* GetClassName() const override { return "RoundedContainerView"; } |
| 282 | 281 |
| 283 private: | 282 private: |
| 284 // gfx::AnimationDelegate: | 283 // gfx::AnimationDelegate: |
| 285 void AnimationEnded(const gfx::Animation* animation) override { | 284 void AnimationEnded(const gfx::Animation* animation) override { |
| 286 initial_color_ = target_color_; | 285 initial_color_ = target_color_; |
| 287 // Tabbed browser windows show the overview mode header behind the window | 286 // Tabbed browser windows show the overview mode header behind the window |
| 288 // during the initial animation. Once the initial fade-in completes and the | 287 // during the initial animation. Once the initial fade-in completes and the |
| 289 // overview header is fully exposed update stacking to keep the label above | 288 // overview header is fully exposed update stacking to keep the label above |
| 290 // the item which prevents input events from reaching the window. | 289 // the item which prevents input events from reaching the window. |
| 291 WmWindow* widget_window = WmLookup::Get()->GetWindowForWidget(GetWidget()); | 290 WmWindow* widget_window = WmWindow::Get(GetWidget()->GetNativeWindow()); |
| 292 if (widget_window && item_window_) | 291 if (widget_window && item_window_) |
| 293 widget_window->GetParent()->StackChildAbove(widget_window, item_window_); | 292 widget_window->GetParent()->StackChildAbove(widget_window, item_window_); |
| 294 item_window_ = nullptr; | 293 item_window_ = nullptr; |
| 295 } | 294 } |
| 296 | 295 |
| 297 void AnimationProgressed(const gfx::Animation* animation) override { | 296 void AnimationProgressed(const gfx::Animation* animation) override { |
| 298 current_value_ = animation_->CurrentValueBetween(0, 255); | 297 current_value_ = animation_->CurrentValueBetween(0, 255); |
| 299 SchedulePaint(); | 298 SchedulePaint(); |
| 300 } | 299 } |
| 301 | 300 |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 445 transform_window_.EnsureVisible(); | 444 transform_window_.EnsureVisible(); |
| 446 } | 445 } |
| 447 | 446 |
| 448 void WindowSelectorItem::Shutdown() { | 447 void WindowSelectorItem::Shutdown() { |
| 449 if (transform_window_.GetTopInset()) { | 448 if (transform_window_.GetTopInset()) { |
| 450 // Activating a window (even when it is the window that was active before | 449 // Activating a window (even when it is the window that was active before |
| 451 // overview) results in stacking it at the top. Maintain the label window | 450 // overview) results in stacking it at the top. Maintain the label window |
| 452 // stacking position above the item to make the header transformation more | 451 // stacking position above the item to make the header transformation more |
| 453 // gradual upon exiting the overview mode. | 452 // gradual upon exiting the overview mode. |
| 454 WmWindow* widget_window = | 453 WmWindow* widget_window = |
| 455 WmLookup::Get()->GetWindowForWidget(item_widget_.get()); | 454 WmWindow::Get(item_widget_.get()->GetNativeWindow()); |
| 456 | 455 |
| 457 // |widget_window| was originally created in the same container as the | 456 // |widget_window| was originally created in the same container as the |
| 458 // |transform_window_| but when closing overview the |transform_window_| | 457 // |transform_window_| but when closing overview the |transform_window_| |
| 459 // could have been reparented if a drag was active. Only change stacking | 458 // could have been reparented if a drag was active. Only change stacking |
| 460 // if the windows still belong to the same container. | 459 // if the windows still belong to the same container. |
| 461 if (widget_window->GetParent() == transform_window_.window()->GetParent()) { | 460 if (widget_window->GetParent() == transform_window_.window()->GetParent()) { |
| 462 widget_window->GetParent()->StackChildAbove(widget_window, | 461 widget_window->GetParent()->StackChildAbove(widget_window, |
| 463 transform_window_.window()); | 462 transform_window_.window()); |
| 464 } | 463 } |
| 465 } | 464 } |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 620 params_label.accept_events = true; | 619 params_label.accept_events = true; |
| 621 item_widget_.reset(new views::Widget); | 620 item_widget_.reset(new views::Widget); |
| 622 root_window_->GetRootWindowController() | 621 root_window_->GetRootWindowController() |
| 623 ->ConfigureWidgetInitParamsForContainer( | 622 ->ConfigureWidgetInitParamsForContainer( |
| 624 item_widget_.get(), | 623 item_widget_.get(), |
| 625 transform_window_.window()->GetParent()->GetShellWindowId(), | 624 transform_window_.window()->GetParent()->GetShellWindowId(), |
| 626 ¶ms_label); | 625 ¶ms_label); |
| 627 item_widget_->set_focus_on_creation(false); | 626 item_widget_->set_focus_on_creation(false); |
| 628 item_widget_->Init(params_label); | 627 item_widget_->Init(params_label); |
| 629 WmWindow* widget_window = | 628 WmWindow* widget_window = |
| 630 WmLookup::Get()->GetWindowForWidget(item_widget_.get()); | 629 WmWindow::Get(item_widget_.get()->GetNativeWindow()); |
| 631 if (transform_window_.GetTopInset()) { | 630 if (transform_window_.GetTopInset()) { |
| 632 // For windows with headers the overview header fades in above the | 631 // For windows with headers the overview header fades in above the |
| 633 // original window header. | 632 // original window header. |
| 634 widget_window->GetParent()->StackChildAbove(widget_window, | 633 widget_window->GetParent()->StackChildAbove(widget_window, |
| 635 transform_window_.window()); | 634 transform_window_.window()); |
| 636 } else { | 635 } else { |
| 637 // For tabbed windows the overview header slides from behind. The stacking | 636 // For tabbed windows the overview header slides from behind. The stacking |
| 638 // is then corrected when the animation completes. | 637 // is then corrected when the animation completes. |
| 639 widget_window->GetParent()->StackChildBelow(widget_window, | 638 widget_window->GetParent()->StackChildBelow(widget_window, |
| 640 transform_window_.window()); | 639 transform_window_.window()); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 686 background_view_->AnimateColor(gfx::Tween::EASE_OUT, | 685 background_view_->AnimateColor(gfx::Tween::EASE_OUT, |
| 687 kExitFadeInMilliseconds); | 686 kExitFadeInMilliseconds); |
| 688 background_view_->set_color(kLabelExitColor); | 687 background_view_->set_color(kLabelExitColor); |
| 689 } | 688 } |
| 690 } | 689 } |
| 691 if (!label_view_->visible()) { | 690 if (!label_view_->visible()) { |
| 692 label_view_->SetVisible(true); | 691 label_view_->SetVisible(true); |
| 693 SetupFadeInAfterLayout(item_widget_.get()); | 692 SetupFadeInAfterLayout(item_widget_.get()); |
| 694 } | 693 } |
| 695 WmWindow* widget_window = | 694 WmWindow* widget_window = |
| 696 WmLookup::Get()->GetWindowForWidget(item_widget_.get()); | 695 WmWindow::Get(item_widget_.get()->GetNativeWindow()); |
| 697 std::unique_ptr<ScopedOverviewAnimationSettings> animation_settings = | 696 std::unique_ptr<ScopedOverviewAnimationSettings> animation_settings = |
| 698 ScopedOverviewAnimationSettingsFactory::Get() | 697 ScopedOverviewAnimationSettingsFactory::Get() |
| 699 ->CreateOverviewAnimationSettings(animation_type, widget_window); | 698 ->CreateOverviewAnimationSettings(animation_type, widget_window); |
| 700 // |widget_window| covers both the transformed window and the header | 699 // |widget_window| covers both the transformed window and the header |
| 701 // as well as the gap between the windows to prevent events from reaching | 700 // as well as the gap between the windows to prevent events from reaching |
| 702 // the window including its sizing borders. | 701 // the window including its sizing borders. |
| 703 if (mode != HeaderFadeInMode::ENTER) { | 702 if (mode != HeaderFadeInMode::ENTER) { |
| 704 label_rect.set_height(close_button_->GetPreferredSize().height() + | 703 label_rect.set_height(close_button_->GetPreferredSize().height() + |
| 705 transformed_window_bounds.height()); | 704 transformed_window_bounds.height()); |
| 706 } | 705 } |
| 707 label_rect.Inset(-kWindowSelectorMargin, -kWindowSelectorMargin); | 706 label_rect.Inset(-kWindowSelectorMargin, -kWindowSelectorMargin); |
| 708 widget_window->SetBounds(label_rect); | 707 widget_window->SetBounds(label_rect); |
| 709 gfx::Transform label_transform; | 708 gfx::Transform label_transform; |
| 710 label_transform.Translate(transformed_window_bounds.x(), | 709 label_transform.Translate(transformed_window_bounds.x(), |
| 711 transformed_window_bounds.y()); | 710 transformed_window_bounds.y()); |
| 712 widget_window->SetTransform(label_transform); | 711 widget_window->SetTransform(label_transform); |
| 713 } | 712 } |
| 714 | 713 |
| 715 void WindowSelectorItem::AnimateOpacity(float opacity, | 714 void WindowSelectorItem::AnimateOpacity(float opacity, |
| 716 OverviewAnimationType animation_type) { | 715 OverviewAnimationType animation_type) { |
| 717 DCHECK_GE(opacity, 0.f); | 716 DCHECK_GE(opacity, 0.f); |
| 718 DCHECK_LE(opacity, 1.f); | 717 DCHECK_LE(opacity, 1.f); |
| 719 ScopedTransformOverviewWindow::ScopedAnimationSettings animation_settings; | 718 ScopedTransformOverviewWindow::ScopedAnimationSettings animation_settings; |
| 720 transform_window_.BeginScopedAnimation(animation_type, &animation_settings); | 719 transform_window_.BeginScopedAnimation(animation_type, &animation_settings); |
| 721 transform_window_.SetOpacity(opacity); | 720 transform_window_.SetOpacity(opacity); |
| 722 | 721 |
| 723 const float header_opacity = selected_ ? 0.f : kHeaderOpacity * opacity; | 722 const float header_opacity = selected_ ? 0.f : kHeaderOpacity * opacity; |
| 724 WmWindow* widget_window = | 723 WmWindow* widget_window = |
| 725 WmLookup::Get()->GetWindowForWidget(item_widget_.get()); | 724 WmWindow::Get(item_widget_.get()->GetNativeWindow()); |
| 726 std::unique_ptr<ScopedOverviewAnimationSettings> animation_settings_label = | 725 std::unique_ptr<ScopedOverviewAnimationSettings> animation_settings_label = |
| 727 ScopedOverviewAnimationSettingsFactory::Get() | 726 ScopedOverviewAnimationSettingsFactory::Get() |
| 728 ->CreateOverviewAnimationSettings(animation_type, widget_window); | 727 ->CreateOverviewAnimationSettings(animation_type, widget_window); |
| 729 widget_window->SetOpacity(header_opacity); | 728 widget_window->SetOpacity(header_opacity); |
| 730 } | 729 } |
| 731 | 730 |
| 732 void WindowSelectorItem::UpdateAccessibilityName() { | 731 void WindowSelectorItem::UpdateAccessibilityName() { |
| 733 caption_container_view_->listener_button()->SetAccessibleName( | 732 caption_container_view_->listener_button()->SetAccessibleName( |
| 734 GetWindow()->GetTitle()); | 733 GetWindow()->GetTitle()); |
| 735 } | 734 } |
| 736 | 735 |
| 737 void WindowSelectorItem::FadeOut(std::unique_ptr<views::Widget> widget) { | 736 void WindowSelectorItem::FadeOut(std::unique_ptr<views::Widget> widget) { |
| 738 widget->SetOpacity(1.f); | 737 widget->SetOpacity(1.f); |
| 739 | 738 |
| 740 // Fade out the widget. This animation continues past the lifetime of |this|. | 739 // Fade out the widget. This animation continues past the lifetime of |this|. |
| 741 WmWindow* widget_window = WmLookup::Get()->GetWindowForWidget(widget.get()); | 740 WmWindow* widget_window = WmWindow::Get(widget.get()->GetNativeWindow()); |
| 742 std::unique_ptr<ScopedOverviewAnimationSettings> animation_settings = | 741 std::unique_ptr<ScopedOverviewAnimationSettings> animation_settings = |
| 743 ScopedOverviewAnimationSettingsFactory::Get() | 742 ScopedOverviewAnimationSettingsFactory::Get() |
| 744 ->CreateOverviewAnimationSettings( | 743 ->CreateOverviewAnimationSettings( |
| 745 OverviewAnimationType:: | 744 OverviewAnimationType:: |
| 746 OVERVIEW_ANIMATION_EXIT_OVERVIEW_MODE_FADE_OUT, | 745 OVERVIEW_ANIMATION_EXIT_OVERVIEW_MODE_FADE_OUT, |
| 747 widget_window); | 746 widget_window); |
| 748 // CleanupAnimationObserver will delete itself (and the widget) when the | 747 // CleanupAnimationObserver will delete itself (and the widget) when the |
| 749 // opacity animation is complete. | 748 // opacity animation is complete. |
| 750 // Ownership over the observer is passed to the window_selector_->delegate() | 749 // Ownership over the observer is passed to the window_selector_->delegate() |
| 751 // which has longer lifetime so that animations can continue even after the | 750 // which has longer lifetime so that animations can continue even after the |
| 752 // overview mode is shut down. | 751 // overview mode is shut down. |
| 753 views::Widget* widget_ptr = widget.get(); | 752 views::Widget* widget_ptr = widget.get(); |
| 754 std::unique_ptr<CleanupAnimationObserver> observer( | 753 std::unique_ptr<CleanupAnimationObserver> observer( |
| 755 new CleanupAnimationObserver(std::move(widget))); | 754 new CleanupAnimationObserver(std::move(widget))); |
| 756 animation_settings->AddObserver(observer.get()); | 755 animation_settings->AddObserver(observer.get()); |
| 757 window_selector_->delegate()->AddDelayedAnimationObserver( | 756 window_selector_->delegate()->AddDelayedAnimationObserver( |
| 758 std::move(observer)); | 757 std::move(observer)); |
| 759 widget_ptr->SetOpacity(0.f); | 758 widget_ptr->SetOpacity(0.f); |
| 760 } | 759 } |
| 761 | 760 |
| 762 gfx::SlideAnimation* WindowSelectorItem::GetBackgroundViewAnimation() { | 761 gfx::SlideAnimation* WindowSelectorItem::GetBackgroundViewAnimation() { |
| 763 return background_view_ ? background_view_->animation() : nullptr; | 762 return background_view_ ? background_view_->animation() : nullptr; |
| 764 } | 763 } |
| 765 | 764 |
| 766 WmWindow* WindowSelectorItem::GetOverviewWindowForMinimizedStateForTest() { | 765 WmWindow* WindowSelectorItem::GetOverviewWindowForMinimizedStateForTest() { |
| 767 return transform_window_.GetOverviewWindowForMinimizedState(); | 766 return transform_window_.GetOverviewWindowForMinimizedState(); |
| 768 } | 767 } |
| 769 | 768 |
| 770 } // namespace ash | 769 } // namespace ash |
| OLD | NEW |