| 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/wm/overview/window_selector_item.h" | 5 #include "ash/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/metrics/user_metrics_action.h" | 10 #include "ash/metrics/user_metrics_action.h" |
| 11 #include "ash/public/cpp/shell_window_ids.h" | 11 #include "ash/public/cpp/shell_window_ids.h" |
| 12 #include "ash/resources/vector_icons/vector_icons.h" | 12 #include "ash/resources/vector_icons/vector_icons.h" |
| 13 #include "ash/root_window_controller.h" | 13 #include "ash/root_window_controller.h" |
| 14 #include "ash/shell_port.h" | 14 #include "ash/shell_port.h" |
| 15 #include "ash/strings/grit/ash_strings.h" | 15 #include "ash/strings/grit/ash_strings.h" |
| 16 #include "ash/wm/overview/cleanup_animation_observer.h" | 16 #include "ash/wm/overview/cleanup_animation_observer.h" |
| 17 #include "ash/wm/overview/overview_animation_type.h" | 17 #include "ash/wm/overview/overview_animation_type.h" |
| 18 #include "ash/wm/overview/scoped_overview_animation_settings.h" | 18 #include "ash/wm/overview/scoped_overview_animation_settings.h" |
| 19 #include "ash/wm/overview/scoped_overview_animation_settings_factory.h" | |
| 20 #include "ash/wm/overview/scoped_transform_overview_window.h" | 19 #include "ash/wm/overview/scoped_transform_overview_window.h" |
| 21 #include "ash/wm/overview/window_selector.h" | 20 #include "ash/wm/overview/window_selector.h" |
| 22 #include "ash/wm/overview/window_selector_controller.h" | 21 #include "ash/wm/overview/window_selector_controller.h" |
| 23 #include "ash/wm/window_state.h" | 22 #include "ash/wm/window_state.h" |
| 24 #include "ash/wm_window.h" | 23 #include "ash/wm_window.h" |
| 25 #include "base/auto_reset.h" | 24 #include "base/auto_reset.h" |
| 26 #include "base/strings/string_util.h" | 25 #include "base/strings/string_util.h" |
| 27 #include "base/strings/utf_string_conversions.h" | 26 #include "base/strings/utf_string_conversions.h" |
| 28 #include "base/time/time.h" | 27 #include "base/time/time.h" |
| 29 #include "ui/base/l10n/l10n_util.h" | 28 #include "ui/base/l10n/l10n_util.h" |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 // Before closing a window animate both the window and the caption to shrink by | 101 // Before closing a window animate both the window and the caption to shrink by |
| 103 // this fraction of size. | 102 // this fraction of size. |
| 104 static const float kPreCloseScale = 0.02f; | 103 static const float kPreCloseScale = 0.02f; |
| 105 | 104 |
| 106 // Convenience method to fade in a Window with predefined animation settings. | 105 // Convenience method to fade in a Window with predefined animation settings. |
| 107 // Note: The fade in animation will occur after a delay where the delay is how | 106 // Note: The fade in animation will occur after a delay where the delay is how |
| 108 // long the lay out animations take. | 107 // long the lay out animations take. |
| 109 void SetupFadeInAfterLayout(views::Widget* widget) { | 108 void SetupFadeInAfterLayout(views::Widget* widget) { |
| 110 aura::Window* window = widget->GetNativeWindow(); | 109 aura::Window* window = widget->GetNativeWindow(); |
| 111 window->layer()->SetOpacity(0.0f); | 110 window->layer()->SetOpacity(0.0f); |
| 112 std::unique_ptr<ScopedOverviewAnimationSettings> | 111 ScopedOverviewAnimationSettings scoped_overview_animation_settings( |
| 113 scoped_overview_animation_settings = | 112 OverviewAnimationType::OVERVIEW_ANIMATION_ENTER_OVERVIEW_MODE_FADE_IN, |
| 114 ScopedOverviewAnimationSettingsFactory::Get() | 113 window); |
| 115 ->CreateOverviewAnimationSettings( | |
| 116 OverviewAnimationType:: | |
| 117 OVERVIEW_ANIMATION_ENTER_OVERVIEW_MODE_FADE_IN, | |
| 118 window); | |
| 119 window->layer()->SetOpacity(1.0f); | 114 window->layer()->SetOpacity(1.0f); |
| 120 } | 115 } |
| 121 | 116 |
| 122 // A Button that has a listener and listens to mouse clicks on the visible part | 117 // A Button that has a listener and listens to mouse clicks on the visible part |
| 123 // of an overview window. | 118 // of an overview window. |
| 124 class ShieldButton : public views::CustomButton { | 119 class ShieldButton : public views::CustomButton { |
| 125 public: | 120 public: |
| 126 ShieldButton(views::ButtonListener* listener, const base::string16& name) | 121 ShieldButton(views::ButtonListener* listener, const base::string16& name) |
| 127 : views::CustomButton(listener) { | 122 : views::CustomButton(listener) { |
| 128 SetAccessibleName(name); | 123 SetAccessibleName(name); |
| (...skipping 552 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 681 background_view_->AnimateColor(gfx::Tween::EASE_OUT, | 676 background_view_->AnimateColor(gfx::Tween::EASE_OUT, |
| 682 kExitFadeInMilliseconds); | 677 kExitFadeInMilliseconds); |
| 683 background_view_->set_color(kLabelExitColor); | 678 background_view_->set_color(kLabelExitColor); |
| 684 } | 679 } |
| 685 } | 680 } |
| 686 if (!label_view_->visible()) { | 681 if (!label_view_->visible()) { |
| 687 label_view_->SetVisible(true); | 682 label_view_->SetVisible(true); |
| 688 SetupFadeInAfterLayout(item_widget_.get()); | 683 SetupFadeInAfterLayout(item_widget_.get()); |
| 689 } | 684 } |
| 690 aura::Window* widget_window = item_widget_->GetNativeWindow(); | 685 aura::Window* widget_window = item_widget_->GetNativeWindow(); |
| 691 std::unique_ptr<ScopedOverviewAnimationSettings> animation_settings = | 686 ScopedOverviewAnimationSettings animation_settings(animation_type, |
| 692 ScopedOverviewAnimationSettingsFactory::Get() | 687 widget_window); |
| 693 ->CreateOverviewAnimationSettings(animation_type, widget_window); | |
| 694 // |widget_window| covers both the transformed window and the header | 688 // |widget_window| covers both the transformed window and the header |
| 695 // as well as the gap between the windows to prevent events from reaching | 689 // as well as the gap between the windows to prevent events from reaching |
| 696 // the window including its sizing borders. | 690 // the window including its sizing borders. |
| 697 if (mode != HeaderFadeInMode::ENTER) { | 691 if (mode != HeaderFadeInMode::ENTER) { |
| 698 label_rect.set_height(close_button_->GetPreferredSize().height() + | 692 label_rect.set_height(close_button_->GetPreferredSize().height() + |
| 699 transformed_window_bounds.height()); | 693 transformed_window_bounds.height()); |
| 700 } | 694 } |
| 701 label_rect.Inset(-kWindowSelectorMargin, -kWindowSelectorMargin); | 695 label_rect.Inset(-kWindowSelectorMargin, -kWindowSelectorMargin); |
| 702 widget_window->SetBounds(label_rect); | 696 widget_window->SetBounds(label_rect); |
| 703 gfx::Transform label_transform; | 697 gfx::Transform label_transform; |
| 704 label_transform.Translate(transformed_window_bounds.x(), | 698 label_transform.Translate(transformed_window_bounds.x(), |
| 705 transformed_window_bounds.y()); | 699 transformed_window_bounds.y()); |
| 706 widget_window->SetTransform(label_transform); | 700 widget_window->SetTransform(label_transform); |
| 707 } | 701 } |
| 708 | 702 |
| 709 void WindowSelectorItem::AnimateOpacity(float opacity, | 703 void WindowSelectorItem::AnimateOpacity(float opacity, |
| 710 OverviewAnimationType animation_type) { | 704 OverviewAnimationType animation_type) { |
| 711 DCHECK_GE(opacity, 0.f); | 705 DCHECK_GE(opacity, 0.f); |
| 712 DCHECK_LE(opacity, 1.f); | 706 DCHECK_LE(opacity, 1.f); |
| 713 ScopedTransformOverviewWindow::ScopedAnimationSettings animation_settings; | 707 ScopedTransformOverviewWindow::ScopedAnimationSettings animation_settings; |
| 714 transform_window_.BeginScopedAnimation(animation_type, &animation_settings); | 708 transform_window_.BeginScopedAnimation(animation_type, &animation_settings); |
| 715 transform_window_.SetOpacity(opacity); | 709 transform_window_.SetOpacity(opacity); |
| 716 | 710 |
| 717 const float header_opacity = selected_ ? 0.f : kHeaderOpacity * opacity; | 711 const float header_opacity = selected_ ? 0.f : kHeaderOpacity * opacity; |
| 718 aura::Window* widget_window = item_widget_->GetNativeWindow(); | 712 aura::Window* widget_window = item_widget_->GetNativeWindow(); |
| 719 std::unique_ptr<ScopedOverviewAnimationSettings> animation_settings_label = | 713 ScopedOverviewAnimationSettings animation_settings_label(animation_type, |
| 720 ScopedOverviewAnimationSettingsFactory::Get() | 714 widget_window); |
| 721 ->CreateOverviewAnimationSettings(animation_type, widget_window); | |
| 722 widget_window->layer()->SetOpacity(header_opacity); | 715 widget_window->layer()->SetOpacity(header_opacity); |
| 723 } | 716 } |
| 724 | 717 |
| 725 void WindowSelectorItem::UpdateAccessibilityName() { | 718 void WindowSelectorItem::UpdateAccessibilityName() { |
| 726 caption_container_view_->listener_button()->SetAccessibleName( | 719 caption_container_view_->listener_button()->SetAccessibleName( |
| 727 GetWindow()->GetTitle()); | 720 GetWindow()->GetTitle()); |
| 728 } | 721 } |
| 729 | 722 |
| 730 void WindowSelectorItem::FadeOut(std::unique_ptr<views::Widget> widget) { | 723 void WindowSelectorItem::FadeOut(std::unique_ptr<views::Widget> widget) { |
| 731 widget->SetOpacity(1.f); | 724 widget->SetOpacity(1.f); |
| 732 | 725 |
| 733 // Fade out the widget. This animation continues past the lifetime of |this|. | 726 // Fade out the widget. This animation continues past the lifetime of |this|. |
| 734 aura::Window* widget_window = widget->GetNativeWindow(); | 727 aura::Window* widget_window = widget->GetNativeWindow(); |
| 735 std::unique_ptr<ScopedOverviewAnimationSettings> animation_settings = | 728 ScopedOverviewAnimationSettings animation_settings( |
| 736 ScopedOverviewAnimationSettingsFactory::Get() | 729 OverviewAnimationType::OVERVIEW_ANIMATION_EXIT_OVERVIEW_MODE_FADE_OUT, |
| 737 ->CreateOverviewAnimationSettings( | 730 widget_window); |
| 738 OverviewAnimationType:: | |
| 739 OVERVIEW_ANIMATION_EXIT_OVERVIEW_MODE_FADE_OUT, | |
| 740 widget_window); | |
| 741 // CleanupAnimationObserver will delete itself (and the widget) when the | 731 // CleanupAnimationObserver will delete itself (and the widget) when the |
| 742 // opacity animation is complete. | 732 // opacity animation is complete. |
| 743 // Ownership over the observer is passed to the window_selector_->delegate() | 733 // Ownership over the observer is passed to the window_selector_->delegate() |
| 744 // which has longer lifetime so that animations can continue even after the | 734 // which has longer lifetime so that animations can continue even after the |
| 745 // overview mode is shut down. | 735 // overview mode is shut down. |
| 746 views::Widget* widget_ptr = widget.get(); | 736 views::Widget* widget_ptr = widget.get(); |
| 747 std::unique_ptr<CleanupAnimationObserver> observer( | 737 std::unique_ptr<CleanupAnimationObserver> observer( |
| 748 new CleanupAnimationObserver(std::move(widget))); | 738 new CleanupAnimationObserver(std::move(widget))); |
| 749 animation_settings->AddObserver(observer.get()); | 739 animation_settings.AddObserver(observer.get()); |
| 750 window_selector_->delegate()->AddDelayedAnimationObserver( | 740 window_selector_->delegate()->AddDelayedAnimationObserver( |
| 751 std::move(observer)); | 741 std::move(observer)); |
| 752 widget_ptr->SetOpacity(0.f); | 742 widget_ptr->SetOpacity(0.f); |
| 753 } | 743 } |
| 754 | 744 |
| 755 gfx::SlideAnimation* WindowSelectorItem::GetBackgroundViewAnimation() { | 745 gfx::SlideAnimation* WindowSelectorItem::GetBackgroundViewAnimation() { |
| 756 return background_view_ ? background_view_->animation() : nullptr; | 746 return background_view_ ? background_view_->animation() : nullptr; |
| 757 } | 747 } |
| 758 | 748 |
| 759 aura::Window* WindowSelectorItem::GetOverviewWindowForMinimizedStateForTest() { | 749 aura::Window* WindowSelectorItem::GetOverviewWindowForMinimizedStateForTest() { |
| 760 return transform_window_.GetOverviewWindowForMinimizedState(); | 750 return transform_window_.GetOverviewWindowForMinimizedState(); |
| 761 } | 751 } |
| 762 | 752 |
| 763 } // namespace ash | 753 } // namespace ash |
| OLD | NEW |