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