| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef ASH_WM_OVERVIEW_SCOPED_TRANSFORM_OVERVIEW_WINDOW_H_ | |
| 6 #define ASH_WM_OVERVIEW_SCOPED_TRANSFORM_OVERVIEW_WINDOW_H_ | |
| 7 | |
| 8 #include <memory> | |
| 9 #include <vector> | |
| 10 | |
| 11 #include "ash/ash_export.h" | |
| 12 #include "ash/wm/overview/overview_animation_type.h" | |
| 13 #include "base/macros.h" | |
| 14 #include "ui/gfx/geometry/size.h" | |
| 15 #include "ui/gfx/transform.h" | |
| 16 | |
| 17 namespace gfx { | |
| 18 class Rect; | |
| 19 } | |
| 20 | |
| 21 namespace ash { | |
| 22 | |
| 23 class ScopedOverviewAnimationSettings; | |
| 24 class WmWindow; | |
| 25 | |
| 26 // Manages a window, and it's transient children, in the overview mode. This | |
| 27 // class allows transforming the windows with a helper to determine the best | |
| 28 // fit in certain bounds. The window's state is restored on destruction of this | |
| 29 // object. | |
| 30 class ASH_EXPORT ScopedTransformOverviewWindow { | |
| 31 public: | |
| 32 using ScopedAnimationSettings = | |
| 33 std::vector<std::unique_ptr<ScopedOverviewAnimationSettings>>; | |
| 34 | |
| 35 // Calculates and returns an optimal scale ratio. With MD this is only | |
| 36 // taking into account |size.height()| as the width can vary. Without MD this | |
| 37 // returns the scale that allows the item to fully fit within |size|. | |
| 38 static float GetItemScale(const gfx::Size& source, | |
| 39 const gfx::Size& target, | |
| 40 int top_view_inset, | |
| 41 int title_height); | |
| 42 | |
| 43 // Returns |rect| having been shrunk to fit within |bounds| (preserving the | |
| 44 // aspect ratio). Takes into account a window header that is |top_view_inset| | |
| 45 // tall in the original window getting replaced by a window caption that is | |
| 46 // |title_height| tall in transformed window. | |
| 47 static gfx::Rect ShrinkRectToFitPreservingAspectRatio(const gfx::Rect& rect, | |
| 48 const gfx::Rect& bounds, | |
| 49 int top_view_inset, | |
| 50 int title_height); | |
| 51 | |
| 52 // Returns the transform turning |src_rect| into |dst_rect|. | |
| 53 static gfx::Transform GetTransformForRect(const gfx::Rect& src_rect, | |
| 54 const gfx::Rect& dst_rect); | |
| 55 | |
| 56 explicit ScopedTransformOverviewWindow(WmWindow* window); | |
| 57 ~ScopedTransformOverviewWindow(); | |
| 58 | |
| 59 gfx::Transform get_overview_transform() const { return overview_transform_; } | |
| 60 | |
| 61 void set_overview_transform(const gfx::Transform& transform) { | |
| 62 overview_transform_ = transform; | |
| 63 } | |
| 64 | |
| 65 // Starts an animation sequence which will use animation settings specified by | |
| 66 // |animation_type|. The |animation_settings| container is populated with | |
| 67 // scoped entities and the container should be destroyed at the end of the | |
| 68 // animation sequence. | |
| 69 // | |
| 70 // Example: | |
| 71 // ScopedTransformOverviewWindow overview_window(window); | |
| 72 // ScopedTransformOverviewWindow::ScopedAnimationSettings scoped_settings; | |
| 73 // overview_window.BeginScopedAnimation( | |
| 74 // OverviewAnimationType::OVERVIEW_ANIMATION_SELECTOR_ITEM_SCROLL_CANCEL, | |
| 75 // &animation_settings); | |
| 76 // // Calls to SetTransform & SetOpacity will use the same animation settings | |
| 77 // // until scoped_settings is destroyed. | |
| 78 // overview_window.SetTransform(root_window, new_transform); | |
| 79 // overview_window.SetOpacity(1); | |
| 80 void BeginScopedAnimation( | |
| 81 OverviewAnimationType animation_type, | |
| 82 ScopedAnimationSettings* animation_settings); | |
| 83 | |
| 84 // Returns true if this window selector window contains the |target|. | |
| 85 bool Contains(const WmWindow* target) const; | |
| 86 | |
| 87 // Returns the original target bounds of all transformed windows. | |
| 88 gfx::Rect GetTargetBoundsInScreen() const; | |
| 89 | |
| 90 // Restores and animates the managed window to it's non overview mode state. | |
| 91 void RestoreWindow(); | |
| 92 | |
| 93 // Forces the managed window to be shown (ie not hidden or minimized) when | |
| 94 // calling RestoreWindow(). | |
| 95 void ShowWindowOnExit(); | |
| 96 | |
| 97 // Informs the ScopedTransformOverviewWindow that the window being watched was | |
| 98 // destroyed. This resets the internal window pointer. | |
| 99 void OnWindowDestroyed(); | |
| 100 | |
| 101 // Prepares for overview mode by doing any necessary actions before entering. | |
| 102 void PrepareForOverview(); | |
| 103 | |
| 104 // Applies the |transform| to the overview window and all of its transient | |
| 105 // children. With Material Design creates a mask layer with the bottom edge | |
| 106 // using rounded corners of |radius|. | |
| 107 void SetTransform(WmWindow* root_window, | |
| 108 const gfx::Transform& transform, | |
| 109 int radius); | |
| 110 | |
| 111 // Set's the opacity of the managed windows. | |
| 112 void SetOpacity(float opacity); | |
| 113 | |
| 114 WmWindow* window() const { return window_; } | |
| 115 | |
| 116 // Closes the transient root of the window managed by |this|. | |
| 117 void Close(); | |
| 118 | |
| 119 private: | |
| 120 class OverviewContentMask; | |
| 121 | |
| 122 // Shows the window if it was minimized. | |
| 123 void ShowWindowIfMinimized(); | |
| 124 | |
| 125 // A weak pointer to the real window in the overview. | |
| 126 WmWindow* window_; | |
| 127 | |
| 128 // Mask layer that hides the original window header. | |
| 129 std::unique_ptr<OverviewContentMask> mask_; | |
| 130 | |
| 131 // If true, the window was minimized and should be restored if the window | |
| 132 // was not selected. | |
| 133 bool minimized_; | |
| 134 | |
| 135 // Tracks if this window was ignored by the shelf. | |
| 136 bool ignored_by_shelf_; | |
| 137 | |
| 138 // True if the window has been transformed for overview mode. | |
| 139 bool overview_started_; | |
| 140 | |
| 141 // The original transform of the window before entering overview mode. | |
| 142 gfx::Transform original_transform_; | |
| 143 | |
| 144 // Keeps track of the original transform used when |this| has been positioned | |
| 145 // during SelectorItem layout. | |
| 146 gfx::Transform overview_transform_; | |
| 147 | |
| 148 // The original opacity of the window before entering overview mode. | |
| 149 float original_opacity_; | |
| 150 | |
| 151 DISALLOW_COPY_AND_ASSIGN(ScopedTransformOverviewWindow); | |
| 152 }; | |
| 153 | |
| 154 } // namespace ash | |
| 155 | |
| 156 #endif // ASH_WM_OVERVIEW_SCOPED_TRANSFORM_OVERVIEW_WINDOW_H_ | |
| OLD | NEW |