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