| 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/wm/overview/cleanup_animation_observer.h" | 12 #include "ash/common/wm/overview/cleanup_animation_observer.h" |
| 13 #include "ash/common/wm/overview/overview_animation_type.h" | 13 #include "ash/common/wm/overview/overview_animation_type.h" |
| 14 #include "ash/common/wm/overview/scoped_overview_animation_settings.h" | 14 #include "ash/common/wm/overview/scoped_overview_animation_settings.h" |
| 15 #include "ash/common/wm/overview/scoped_overview_animation_settings_factory.h" | 15 #include "ash/common/wm/overview/scoped_overview_animation_settings_factory.h" |
| 16 #include "ash/common/wm/overview/scoped_transform_overview_window.h" | 16 #include "ash/common/wm/overview/scoped_transform_overview_window.h" |
| 17 #include "ash/common/wm/overview/window_selector.h" | 17 #include "ash/common/wm/overview/window_selector.h" |
| 18 #include "ash/common/wm/overview/window_selector_controller.h" | 18 #include "ash/common/wm/overview/window_selector_controller.h" |
| 19 #include "ash/common/wm/window_state.h" | 19 #include "ash/common/wm/window_state.h" |
| 20 #include "ash/common/wm_lookup.h" | |
| 21 #include "ash/common/wm_shell.h" | 20 #include "ash/common/wm_shell.h" |
| 22 #include "ash/common/wm_window.h" | 21 #include "ash/common/wm_window.h" |
| 23 #include "ash/common/wm_window_property.h" | 22 #include "ash/common/wm_window_property.h" |
| 24 #include "ash/public/cpp/shell_window_ids.h" | 23 #include "ash/public/cpp/shell_window_ids.h" |
| 25 #include "ash/resources/vector_icons/vector_icons.h" | 24 #include "ash/resources/vector_icons/vector_icons.h" |
| 26 #include "ash/root_window_controller.h" | 25 #include "ash/root_window_controller.h" |
| 27 #include "ash/strings/grit/ash_strings.h" | 26 #include "ash/strings/grit/ash_strings.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" |
| (...skipping 71 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 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 444 void WindowSelectorItem::EnsureVisible() { | 443 void WindowSelectorItem::EnsureVisible() { |
| 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 = WmWindow::Get(item_widget_->GetNativeWindow()); |
| 455 WmLookup::Get()->GetWindowForWidget(item_widget_.get()); | |
| 456 | 454 |
| 457 // |widget_window| was originally created in the same container as the | 455 // |widget_window| was originally created in the same container as the |
| 458 // |transform_window_| but when closing overview the |transform_window_| | 456 // |transform_window_| but when closing overview the |transform_window_| |
| 459 // could have been reparented if a drag was active. Only change stacking | 457 // could have been reparented if a drag was active. Only change stacking |
| 460 // if the windows still belong to the same container. | 458 // if the windows still belong to the same container. |
| 461 if (widget_window->GetParent() == transform_window_.window()->GetParent()) { | 459 if (widget_window->GetParent() == transform_window_.window()->GetParent()) { |
| 462 widget_window->GetParent()->StackChildAbove(widget_window, | 460 widget_window->GetParent()->StackChildAbove(widget_window, |
| 463 transform_window_.window()); | 461 transform_window_.window()); |
| 464 } | 462 } |
| 465 } | 463 } |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 619 views::Widget::InitParams::Activatable::ACTIVATABLE_DEFAULT; | 617 views::Widget::InitParams::Activatable::ACTIVATABLE_DEFAULT; |
| 620 params_label.accept_events = true; | 618 params_label.accept_events = true; |
| 621 item_widget_.reset(new views::Widget); | 619 item_widget_.reset(new views::Widget); |
| 622 root_window_->GetRootWindowController() | 620 root_window_->GetRootWindowController() |
| 623 ->ConfigureWidgetInitParamsForContainer( | 621 ->ConfigureWidgetInitParamsForContainer( |
| 624 item_widget_.get(), | 622 item_widget_.get(), |
| 625 transform_window_.window()->GetParent()->GetShellWindowId(), | 623 transform_window_.window()->GetParent()->GetShellWindowId(), |
| 626 ¶ms_label); | 624 ¶ms_label); |
| 627 item_widget_->set_focus_on_creation(false); | 625 item_widget_->set_focus_on_creation(false); |
| 628 item_widget_->Init(params_label); | 626 item_widget_->Init(params_label); |
| 629 WmWindow* widget_window = | 627 WmWindow* widget_window = WmWindow::Get(item_widget_->GetNativeWindow()); |
| 630 WmLookup::Get()->GetWindowForWidget(item_widget_.get()); | |
| 631 if (transform_window_.GetTopInset()) { | 628 if (transform_window_.GetTopInset()) { |
| 632 // For windows with headers the overview header fades in above the | 629 // For windows with headers the overview header fades in above the |
| 633 // original window header. | 630 // original window header. |
| 634 widget_window->GetParent()->StackChildAbove(widget_window, | 631 widget_window->GetParent()->StackChildAbove(widget_window, |
| 635 transform_window_.window()); | 632 transform_window_.window()); |
| 636 } else { | 633 } else { |
| 637 // For tabbed windows the overview header slides from behind. The stacking | 634 // For tabbed windows the overview header slides from behind. The stacking |
| 638 // is then corrected when the animation completes. | 635 // is then corrected when the animation completes. |
| 639 widget_window->GetParent()->StackChildBelow(widget_window, | 636 widget_window->GetParent()->StackChildBelow(widget_window, |
| 640 transform_window_.window()); | 637 transform_window_.window()); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 685 // the Shutdown() is called. | 682 // the Shutdown() is called. |
| 686 background_view_->AnimateColor(gfx::Tween::EASE_OUT, | 683 background_view_->AnimateColor(gfx::Tween::EASE_OUT, |
| 687 kExitFadeInMilliseconds); | 684 kExitFadeInMilliseconds); |
| 688 background_view_->set_color(kLabelExitColor); | 685 background_view_->set_color(kLabelExitColor); |
| 689 } | 686 } |
| 690 } | 687 } |
| 691 if (!label_view_->visible()) { | 688 if (!label_view_->visible()) { |
| 692 label_view_->SetVisible(true); | 689 label_view_->SetVisible(true); |
| 693 SetupFadeInAfterLayout(item_widget_.get()); | 690 SetupFadeInAfterLayout(item_widget_.get()); |
| 694 } | 691 } |
| 695 WmWindow* widget_window = | 692 WmWindow* widget_window = WmWindow::Get(item_widget_->GetNativeWindow()); |
| 696 WmLookup::Get()->GetWindowForWidget(item_widget_.get()); | |
| 697 std::unique_ptr<ScopedOverviewAnimationSettings> animation_settings = | 693 std::unique_ptr<ScopedOverviewAnimationSettings> animation_settings = |
| 698 ScopedOverviewAnimationSettingsFactory::Get() | 694 ScopedOverviewAnimationSettingsFactory::Get() |
| 699 ->CreateOverviewAnimationSettings(animation_type, widget_window); | 695 ->CreateOverviewAnimationSettings(animation_type, widget_window); |
| 700 // |widget_window| covers both the transformed window and the header | 696 // |widget_window| covers both the transformed window and the header |
| 701 // as well as the gap between the windows to prevent events from reaching | 697 // as well as the gap between the windows to prevent events from reaching |
| 702 // the window including its sizing borders. | 698 // the window including its sizing borders. |
| 703 if (mode != HeaderFadeInMode::ENTER) { | 699 if (mode != HeaderFadeInMode::ENTER) { |
| 704 label_rect.set_height(close_button_->GetPreferredSize().height() + | 700 label_rect.set_height(close_button_->GetPreferredSize().height() + |
| 705 transformed_window_bounds.height()); | 701 transformed_window_bounds.height()); |
| 706 } | 702 } |
| 707 label_rect.Inset(-kWindowSelectorMargin, -kWindowSelectorMargin); | 703 label_rect.Inset(-kWindowSelectorMargin, -kWindowSelectorMargin); |
| 708 widget_window->SetBounds(label_rect); | 704 widget_window->SetBounds(label_rect); |
| 709 gfx::Transform label_transform; | 705 gfx::Transform label_transform; |
| 710 label_transform.Translate(transformed_window_bounds.x(), | 706 label_transform.Translate(transformed_window_bounds.x(), |
| 711 transformed_window_bounds.y()); | 707 transformed_window_bounds.y()); |
| 712 widget_window->SetTransform(label_transform); | 708 widget_window->SetTransform(label_transform); |
| 713 } | 709 } |
| 714 | 710 |
| 715 void WindowSelectorItem::AnimateOpacity(float opacity, | 711 void WindowSelectorItem::AnimateOpacity(float opacity, |
| 716 OverviewAnimationType animation_type) { | 712 OverviewAnimationType animation_type) { |
| 717 DCHECK_GE(opacity, 0.f); | 713 DCHECK_GE(opacity, 0.f); |
| 718 DCHECK_LE(opacity, 1.f); | 714 DCHECK_LE(opacity, 1.f); |
| 719 ScopedTransformOverviewWindow::ScopedAnimationSettings animation_settings; | 715 ScopedTransformOverviewWindow::ScopedAnimationSettings animation_settings; |
| 720 transform_window_.BeginScopedAnimation(animation_type, &animation_settings); | 716 transform_window_.BeginScopedAnimation(animation_type, &animation_settings); |
| 721 transform_window_.SetOpacity(opacity); | 717 transform_window_.SetOpacity(opacity); |
| 722 | 718 |
| 723 const float header_opacity = selected_ ? 0.f : kHeaderOpacity * opacity; | 719 const float header_opacity = selected_ ? 0.f : kHeaderOpacity * opacity; |
| 724 WmWindow* widget_window = | 720 WmWindow* widget_window = WmWindow::Get(item_widget_->GetNativeWindow()); |
| 725 WmLookup::Get()->GetWindowForWidget(item_widget_.get()); | |
| 726 std::unique_ptr<ScopedOverviewAnimationSettings> animation_settings_label = | 721 std::unique_ptr<ScopedOverviewAnimationSettings> animation_settings_label = |
| 727 ScopedOverviewAnimationSettingsFactory::Get() | 722 ScopedOverviewAnimationSettingsFactory::Get() |
| 728 ->CreateOverviewAnimationSettings(animation_type, widget_window); | 723 ->CreateOverviewAnimationSettings(animation_type, widget_window); |
| 729 widget_window->SetOpacity(header_opacity); | 724 widget_window->SetOpacity(header_opacity); |
| 730 } | 725 } |
| 731 | 726 |
| 732 void WindowSelectorItem::UpdateAccessibilityName() { | 727 void WindowSelectorItem::UpdateAccessibilityName() { |
| 733 caption_container_view_->listener_button()->SetAccessibleName( | 728 caption_container_view_->listener_button()->SetAccessibleName( |
| 734 GetWindow()->GetTitle()); | 729 GetWindow()->GetTitle()); |
| 735 } | 730 } |
| 736 | 731 |
| 737 void WindowSelectorItem::FadeOut(std::unique_ptr<views::Widget> widget) { | 732 void WindowSelectorItem::FadeOut(std::unique_ptr<views::Widget> widget) { |
| 738 widget->SetOpacity(1.f); | 733 widget->SetOpacity(1.f); |
| 739 | 734 |
| 740 // Fade out the widget. This animation continues past the lifetime of |this|. | 735 // Fade out the widget. This animation continues past the lifetime of |this|. |
| 741 WmWindow* widget_window = WmLookup::Get()->GetWindowForWidget(widget.get()); | 736 WmWindow* widget_window = WmWindow::Get(widget->GetNativeWindow()); |
| 742 std::unique_ptr<ScopedOverviewAnimationSettings> animation_settings = | 737 std::unique_ptr<ScopedOverviewAnimationSettings> animation_settings = |
| 743 ScopedOverviewAnimationSettingsFactory::Get() | 738 ScopedOverviewAnimationSettingsFactory::Get() |
| 744 ->CreateOverviewAnimationSettings( | 739 ->CreateOverviewAnimationSettings( |
| 745 OverviewAnimationType:: | 740 OverviewAnimationType:: |
| 746 OVERVIEW_ANIMATION_EXIT_OVERVIEW_MODE_FADE_OUT, | 741 OVERVIEW_ANIMATION_EXIT_OVERVIEW_MODE_FADE_OUT, |
| 747 widget_window); | 742 widget_window); |
| 748 // CleanupAnimationObserver will delete itself (and the widget) when the | 743 // CleanupAnimationObserver will delete itself (and the widget) when the |
| 749 // opacity animation is complete. | 744 // opacity animation is complete. |
| 750 // Ownership over the observer is passed to the window_selector_->delegate() | 745 // Ownership over the observer is passed to the window_selector_->delegate() |
| 751 // which has longer lifetime so that animations can continue even after the | 746 // which has longer lifetime so that animations can continue even after the |
| 752 // overview mode is shut down. | 747 // overview mode is shut down. |
| 753 views::Widget* widget_ptr = widget.get(); | 748 views::Widget* widget_ptr = widget.get(); |
| 754 std::unique_ptr<CleanupAnimationObserver> observer( | 749 std::unique_ptr<CleanupAnimationObserver> observer( |
| 755 new CleanupAnimationObserver(std::move(widget))); | 750 new CleanupAnimationObserver(std::move(widget))); |
| 756 animation_settings->AddObserver(observer.get()); | 751 animation_settings->AddObserver(observer.get()); |
| 757 window_selector_->delegate()->AddDelayedAnimationObserver( | 752 window_selector_->delegate()->AddDelayedAnimationObserver( |
| 758 std::move(observer)); | 753 std::move(observer)); |
| 759 widget_ptr->SetOpacity(0.f); | 754 widget_ptr->SetOpacity(0.f); |
| 760 } | 755 } |
| 761 | 756 |
| 762 gfx::SlideAnimation* WindowSelectorItem::GetBackgroundViewAnimation() { | 757 gfx::SlideAnimation* WindowSelectorItem::GetBackgroundViewAnimation() { |
| 763 return background_view_ ? background_view_->animation() : nullptr; | 758 return background_view_ ? background_view_->animation() : nullptr; |
| 764 } | 759 } |
| 765 | 760 |
| 766 WmWindow* WindowSelectorItem::GetOverviewWindowForMinimizedStateForTest() { | 761 WmWindow* WindowSelectorItem::GetOverviewWindowForMinimizedStateForTest() { |
| 767 return transform_window_.GetOverviewWindowForMinimizedState(); | 762 return transform_window_.GetOverviewWindowForMinimizedState(); |
| 768 } | 763 } |
| 769 | 764 |
| 770 } // namespace ash | 765 } // namespace ash |
| OLD | NEW |