| 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 #ifndef ASH_WM_OVERVIEW_SCOPED_TRANSFORM_OVERVIEW_WINDOW_H_ | 5 #ifndef ASH_WM_OVERVIEW_SCOPED_TRANSFORM_OVERVIEW_WINDOW_H_ |
| 6 #define ASH_WM_OVERVIEW_SCOPED_TRANSFORM_OVERVIEW_WINDOW_H_ | 6 #define ASH_WM_OVERVIEW_SCOPED_TRANSFORM_OVERVIEW_WINDOW_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "ash/ash_export.h" | 11 #include "ash/ash_export.h" |
| 12 #include "ash/wm/overview/overview_animation_type.h" | 12 #include "ash/wm/overview/overview_animation_type.h" |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
| 15 #include "third_party/skia/include/core/SkColor.h" | 15 #include "third_party/skia/include/core/SkColor.h" |
| 16 #include "ui/events/event_handler.h" | 16 #include "ui/events/event_handler.h" |
| 17 #include "ui/gfx/geometry/size.h" | 17 #include "ui/gfx/geometry/size.h" |
| 18 #include "ui/gfx/transform.h" | 18 #include "ui/gfx/transform.h" |
| 19 | 19 |
| 20 class SkRegion; | 20 class SkRegion; |
| 21 | 21 |
| 22 namespace aura { |
| 23 class Window; |
| 24 } |
| 25 |
| 22 namespace gfx { | 26 namespace gfx { |
| 23 class Rect; | 27 class Rect; |
| 24 } | 28 } |
| 25 | 29 |
| 26 namespace views { | 30 namespace views { |
| 27 class Widget; | 31 class Widget; |
| 28 } | 32 } |
| 29 | 33 |
| 30 namespace ash { | 34 namespace ash { |
| 31 | 35 |
| 32 class ScopedOverviewAnimationSettings; | 36 class ScopedOverviewAnimationSettings; |
| 33 class WmWindow; | |
| 34 | 37 |
| 35 // Manages a window, and it's transient children, in the overview mode. This | 38 // Manages a window, and its transient children, in the overview mode. This |
| 36 // class allows transforming the windows with a helper to determine the best | 39 // class allows transforming the windows with a helper to determine the best |
| 37 // fit in certain bounds. The window's state is restored on destruction of this | 40 // fit in certain bounds. The window's state is restored when this object is |
| 38 // object. | 41 // destroyed. |
| 39 class ASH_EXPORT ScopedTransformOverviewWindow : public ui::EventHandler { | 42 class ASH_EXPORT ScopedTransformOverviewWindow : public ui::EventHandler { |
| 40 public: | 43 public: |
| 41 class OverviewContentMask; | 44 class OverviewContentMask; |
| 42 using ScopedAnimationSettings = | 45 using ScopedAnimationSettings = |
| 43 std::vector<std::unique_ptr<ScopedOverviewAnimationSettings>>; | 46 std::vector<std::unique_ptr<ScopedOverviewAnimationSettings>>; |
| 44 | 47 |
| 45 // Calculates and returns an optimal scale ratio. With MD this is only | 48 // Calculates and returns an optimal scale ratio. This is only taking into |
| 46 // taking into account |size.height()| as the width can vary. Without MD this | 49 // account |size.height()| as the width can vary. |
| 47 // returns the scale that allows the item to fully fit within |size|. | |
| 48 static float GetItemScale(const gfx::Size& source, | 50 static float GetItemScale(const gfx::Size& source, |
| 49 const gfx::Size& target, | 51 const gfx::Size& target, |
| 50 int top_view_inset, | 52 int top_view_inset, |
| 51 int title_height); | 53 int title_height); |
| 52 | 54 |
| 53 // Returns |rect| having been shrunk to fit within |bounds| (preserving the | 55 // Returns |rect| having been shrunk to fit within |bounds| (preserving the |
| 54 // aspect ratio). Takes into account a window header that is |top_view_inset| | 56 // aspect ratio). Takes into account a window header that is |top_view_inset| |
| 55 // tall in the original window getting replaced by a window caption that is | 57 // tall in the original window getting replaced by a window caption that is |
| 56 // |title_height| tall in transformed window. | 58 // |title_height| tall in the transformed window. |
| 57 static gfx::Rect ShrinkRectToFitPreservingAspectRatio(const gfx::Rect& rect, | 59 static gfx::Rect ShrinkRectToFitPreservingAspectRatio(const gfx::Rect& rect, |
| 58 const gfx::Rect& bounds, | 60 const gfx::Rect& bounds, |
| 59 int top_view_inset, | 61 int top_view_inset, |
| 60 int title_height); | 62 int title_height); |
| 61 | 63 |
| 62 // Returns the transform turning |src_rect| into |dst_rect|. | 64 // Returns the transform turning |src_rect| into |dst_rect|. |
| 63 static gfx::Transform GetTransformForRect(const gfx::Rect& src_rect, | 65 static gfx::Transform GetTransformForRect(const gfx::Rect& src_rect, |
| 64 const gfx::Rect& dst_rect); | 66 const gfx::Rect& dst_rect); |
| 65 | 67 |
| 66 explicit ScopedTransformOverviewWindow(WmWindow* window); | 68 explicit ScopedTransformOverviewWindow(aura::Window* window); |
| 67 ~ScopedTransformOverviewWindow() override; | 69 ~ScopedTransformOverviewWindow() override; |
| 68 | 70 |
| 69 // Starts an animation sequence which will use animation settings specified by | 71 // Starts an animation sequence which will use animation settings specified by |
| 70 // |animation_type|. The |animation_settings| container is populated with | 72 // |animation_type|. The |animation_settings| container is populated with |
| 71 // scoped entities and the container should be destroyed at the end of the | 73 // scoped entities and the container should be destroyed at the end of the |
| 72 // animation sequence. | 74 // animation sequence. |
| 73 // | 75 // |
| 74 // Example: | 76 // Example: |
| 75 // ScopedTransformOverviewWindow overview_window(window); | 77 // ScopedTransformOverviewWindow overview_window(window); |
| 76 // ScopedTransformOverviewWindow::ScopedAnimationSettings scoped_settings; | 78 // ScopedTransformOverviewWindow::ScopedAnimationSettings scoped_settings; |
| 77 // overview_window.BeginScopedAnimation( | 79 // overview_window.BeginScopedAnimation( |
| 78 // OverviewAnimationType::OVERVIEW_ANIMATION_SELECTOR_ITEM_SCROLL_CANCEL, | 80 // OverviewAnimationType::OVERVIEW_ANIMATION_SELECTOR_ITEM_SCROLL_CANCEL, |
| 79 // &animation_settings); | 81 // &animation_settings); |
| 80 // // Calls to SetTransform & SetOpacity will use the same animation settings | 82 // // Calls to SetTransform & SetOpacity will use the same animation settings |
| 81 // // until scoped_settings is destroyed. | 83 // // until scoped_settings is destroyed. |
| 82 // overview_window.SetTransform(root_window, new_transform); | 84 // overview_window.SetTransform(root_window, new_transform); |
| 83 // overview_window.SetOpacity(1); | 85 // overview_window.SetOpacity(1); |
| 84 void BeginScopedAnimation(OverviewAnimationType animation_type, | 86 void BeginScopedAnimation(OverviewAnimationType animation_type, |
| 85 ScopedAnimationSettings* animation_settings); | 87 ScopedAnimationSettings* animation_settings); |
| 86 | 88 |
| 87 // Returns true if this window selector window contains the |target|. | 89 // Returns true if this window selector window contains the |target|. |
| 88 bool Contains(const WmWindow* target) const; | 90 bool Contains(const aura::Window* target) const; |
| 89 | 91 |
| 90 // Returns the original target bounds of all transformed windows. | 92 // Returns the original target bounds of all transformed windows. |
| 91 gfx::Rect GetTargetBoundsInScreen() const; | 93 gfx::Rect GetTargetBoundsInScreen() const; |
| 92 | 94 |
| 93 // Calculates the bounds of a |window_| after being transformed to the | 95 // Calculates the bounds of a |window_| after being transformed to the |
| 94 // selector's space. Those bounds are a union of all regular (normal and | 96 // selector's space. Those bounds are a union of all regular (normal and |
| 95 // panel) windows in the |window_|'s transient hierarchy. The returned Rect is | 97 // panel) windows in the |window_|'s transient hierarchy. The returned Rect is |
| 96 // in virtual screen coordinates. The returned bounds are adjusted to allow | 98 // in virtual screen coordinates. The returned bounds are adjusted to allow |
| 97 // the original |window_|'s header to be hidden. | 99 // the original |window_|'s header to be hidden. |
| 98 gfx::Rect GetTransformedBounds() const; | 100 gfx::Rect GetTransformedBounds() const; |
| 99 | 101 |
| 100 // Returns TOP_VIEW_COLOR property of |window_| unless there are transient | 102 // Returns TOP_VIEW_COLOR property of |window_| unless there are transient |
| 101 // ancestors in which case returns SK_ColorTRANSPARENT. | 103 // ancestors, in which case returns SK_ColorTRANSPARENT. |
| 102 SkColor GetTopColor() const; | 104 SkColor GetTopColor() const; |
| 103 | 105 |
| 104 // Returns TOP_VIEW_INSET property of |window_| unless there are transient | 106 // Returns TOP_VIEW_INSET property of |window_| unless there are transient |
| 105 // ancestors in which case returns 0. | 107 // ancestors, in which case returns 0. |
| 106 int GetTopInset() const; | 108 int GetTopInset() const; |
| 107 | 109 |
| 108 // Restores and animates the managed window to it's non overview mode state. | 110 // Restores and animates the managed window to its non overview mode state. |
| 109 void RestoreWindow(); | 111 void RestoreWindow(); |
| 110 | 112 |
| 111 // Informs the ScopedTransformOverviewWindow that the window being watched was | 113 // Informs the ScopedTransformOverviewWindow that the window being watched was |
| 112 // destroyed. This resets the internal window pointer. | 114 // destroyed. This resets the internal window pointer. |
| 113 void OnWindowDestroyed(); | 115 void OnWindowDestroyed(); |
| 114 | 116 |
| 115 // Prepares for overview mode by doing any necessary actions before entering. | 117 // Prepares for overview mode by doing any necessary actions before entering. |
| 116 void PrepareForOverview(); | 118 void PrepareForOverview(); |
| 117 | 119 |
| 118 // Applies the |transform| to the overview window and all of its transient | 120 // Applies the |transform| to the overview window and all of its transient |
| 119 // children. | 121 // children. |
| 120 void SetTransform(WmWindow* root_window, const gfx::Transform& transform); | 122 void SetTransform(aura::Window* root_window, const gfx::Transform& transform); |
| 121 | 123 |
| 122 // Set's the opacity of the managed windows. | 124 // Sets the opacity of the managed windows. |
| 123 void SetOpacity(float opacity); | 125 void SetOpacity(float opacity); |
| 124 | 126 |
| 125 // Hides the window header whose size is given in |TOP_VIEW_INSET| | 127 // Hides the window header whose size is given in |TOP_VIEW_INSET| window |
| 126 // window property. | 128 // property. |
| 127 void HideHeader(); | 129 void HideHeader(); |
| 128 | 130 |
| 129 // Shows the window header that is hidden by HideHeader(). | 131 // Shows the window header that is hidden by HideHeader(). |
| 130 void ShowHeader(); | 132 void ShowHeader(); |
| 131 | 133 |
| 132 // Creates/Deletes a mirror window for minimized windows. | 134 // Creates/Deletes a mirror window for minimized windows. |
| 133 void UpdateMirrorWindowForMinimizedState(); | 135 void UpdateMirrorWindowForMinimizedState(); |
| 134 | 136 |
| 135 WmWindow* window() const { return window_; } | 137 aura::Window* window() const { return window_; } |
| 136 | 138 |
| 137 // Closes the transient root of the window managed by |this|. | 139 // Closes the transient root of the window managed by |this|. |
| 138 void Close(); | 140 void Close(); |
| 139 | 141 |
| 140 // Returns the window used to show the content in overview mdoe. | 142 // Returns the window used to show the content in overview mode. |
| 141 // For minmiezd window, this will be a window that hosts mirrored layers. | 143 // For minimized window this will be a window that hosts mirrored layers. |
| 142 WmWindow* GetOverviewWindow() const; | 144 aura::Window* GetOverviewWindow() const; |
| 143 | 145 |
| 144 // Ensures that a window is visible by setting its opacity to 1. | 146 // Ensures that a window is visible by setting its opacity to 1. |
| 145 void EnsureVisible(); | 147 void EnsureVisible(); |
| 146 | 148 |
| 147 // Returns the window created for minimized window, or nullptr | 149 // Returns an overview window created for minimized window, or nullptr if it |
| 148 // if it does not exit. | 150 // does not exist. |
| 149 WmWindow* GetOverviewWindowForMinimizedState() const; | 151 aura::Window* GetOverviewWindowForMinimizedState() const; |
| 150 | 152 |
| 151 // ui::EventHandler: | 153 // ui::EventHandler: |
| 152 void OnGestureEvent(ui::GestureEvent* event) override; | 154 void OnGestureEvent(ui::GestureEvent* event) override; |
| 153 void OnMouseEvent(ui::MouseEvent* event) override; | 155 void OnMouseEvent(ui::MouseEvent* event) override; |
| 154 | 156 |
| 155 private: | 157 private: |
| 156 friend class WindowSelectorTest; | 158 friend class WindowSelectorTest; |
| 157 | 159 |
| 158 // Closes the window managed by |this|. | 160 // Closes the window managed by |this|. |
| 159 void CloseWidget(); | 161 void CloseWidget(); |
| 160 | 162 |
| 161 void CreateMirrorWindowForMinimizedState(); | 163 void CreateMirrorWindowForMinimizedState(); |
| 162 | 164 |
| 163 // Makes Close() execute synchronously when used in tests. | 165 // Makes Close() execute synchronously when used in tests. |
| 164 static void SetImmediateCloseForTests(); | 166 static void SetImmediateCloseForTests(); |
| 165 | 167 |
| 166 // A weak pointer to the real window in the overview. | 168 // A weak pointer to the real window in the overview. |
| 167 WmWindow* window_; | 169 aura::Window* window_; |
| 168 | 170 |
| 169 // Original window shape, if it was set on a window. | 171 // Original |window_|'s shape, if it was set on the window. |
| 170 std::unique_ptr<SkRegion> original_window_shape_; | 172 std::unique_ptr<SkRegion> original_window_shape_; |
| 171 | 173 |
| 172 // True after the |original_window_shape_| has been set or after it has | 174 // True after the |original_window_shape_| has been set or after it has |
| 173 // been determined that window shape was not originally set on the |window_|. | 175 // been determined that window shape was not originally set on the |window_|. |
| 174 bool determined_original_window_shape_; | 176 bool determined_original_window_shape_; |
| 175 | 177 |
| 176 // Tracks if this window was ignored by the shelf. | 178 // Tracks if this window was ignored by the shelf. |
| 177 bool ignored_by_shelf_; | 179 bool ignored_by_shelf_; |
| 178 | 180 |
| 179 // True if the window has been transformed for overview mode. | 181 // True if the window has been transformed for overview mode. |
| 180 bool overview_started_; | 182 bool overview_started_; |
| 181 | 183 |
| 182 // The original transform of the window before entering overview mode. | 184 // The original transform of the window before entering overview mode. |
| 183 gfx::Transform original_transform_; | 185 gfx::Transform original_transform_; |
| 184 | 186 |
| 185 // The original opacity of the window before entering overview mode. | 187 // The original opacity of the window before entering overview mode. |
| 186 float original_opacity_; | 188 float original_opacity_; |
| 187 | 189 |
| 188 // A window that holds the content for minimized window. | 190 // A widget that holds the content for the minimized window. |
| 189 std::unique_ptr<views::Widget> minimized_widget_; | 191 std::unique_ptr<views::Widget> minimized_widget_; |
| 190 | 192 |
| 191 base::WeakPtrFactory<ScopedTransformOverviewWindow> weak_ptr_factory_; | 193 base::WeakPtrFactory<ScopedTransformOverviewWindow> weak_ptr_factory_; |
| 192 | 194 |
| 193 DISALLOW_COPY_AND_ASSIGN(ScopedTransformOverviewWindow); | 195 DISALLOW_COPY_AND_ASSIGN(ScopedTransformOverviewWindow); |
| 194 }; | 196 }; |
| 195 | 197 |
| 196 } // namespace ash | 198 } // namespace ash |
| 197 | 199 |
| 198 #endif // ASH_WM_OVERVIEW_SCOPED_TRANSFORM_OVERVIEW_WINDOW_H_ | 200 #endif // ASH_WM_OVERVIEW_SCOPED_TRANSFORM_OVERVIEW_WINDOW_H_ |
| OLD | NEW |