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/scoped_transform_overview_window.h" | 5 #include "ash/wm/overview/scoped_transform_overview_window.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "ash/common/wm/window_state.h" | 10 #include "ash/common/wm/window_state.h" |
11 #include "ash/common/wm/wm_window.h" | 11 #include "ash/common/wm_window.h" |
12 #include "ash/wm/overview/scoped_overview_animation_settings.h" | 12 #include "ash/wm/overview/scoped_overview_animation_settings.h" |
13 #include "ash/wm/overview/scoped_overview_animation_settings_factory.h" | 13 #include "ash/wm/overview/scoped_overview_animation_settings_factory.h" |
14 #include "ash/wm/overview/window_selector_item.h" | 14 #include "ash/wm/overview/window_selector_item.h" |
15 #include "base/macros.h" | 15 #include "base/macros.h" |
16 #include "ui/gfx/geometry/rect.h" | 16 #include "ui/gfx/geometry/rect.h" |
17 #include "ui/gfx/transform_util.h" | 17 #include "ui/gfx/transform_util.h" |
18 | 18 |
19 using WmWindows = std::vector<ash::wm::WmWindow*>; | 19 using WmWindows = std::vector<ash::WmWindow*>; |
20 | 20 |
21 namespace ash { | 21 namespace ash { |
22 | 22 |
23 namespace { | 23 namespace { |
24 | 24 |
25 // The opacity level that windows will be set to when they are restored. | 25 // The opacity level that windows will be set to when they are restored. |
26 const float kRestoreWindowOpacity = 1.0f; | 26 const float kRestoreWindowOpacity = 1.0f; |
27 | 27 |
28 wm::WmWindow* GetTransientRoot(wm::WmWindow* window) { | 28 WmWindow* GetTransientRoot(WmWindow* window) { |
29 while (window->GetTransientParent()) | 29 while (window->GetTransientParent()) |
30 window = window->GetTransientParent(); | 30 window = window->GetTransientParent(); |
31 return window; | 31 return window; |
32 } | 32 } |
33 | 33 |
34 std::unique_ptr<ScopedOverviewAnimationSettings> | 34 std::unique_ptr<ScopedOverviewAnimationSettings> |
35 CreateScopedOverviewAnimationSettings(OverviewAnimationType animation_type, | 35 CreateScopedOverviewAnimationSettings(OverviewAnimationType animation_type, |
36 wm::WmWindow* window) { | 36 WmWindow* window) { |
37 return ScopedOverviewAnimationSettingsFactory::Get() | 37 return ScopedOverviewAnimationSettingsFactory::Get() |
38 ->CreateOverviewAnimationSettings(animation_type, window); | 38 ->CreateOverviewAnimationSettings(animation_type, window); |
39 } | 39 } |
40 | 40 |
41 // An iterator class that traverses a wm::WmWindow and all of its transient | 41 // An iterator class that traverses a WmWindow and all of its transient |
42 // descendants. | 42 // descendants. |
43 class TransientDescendantIterator { | 43 class TransientDescendantIterator { |
44 public: | 44 public: |
45 // Creates an empty iterator. | 45 // Creates an empty iterator. |
46 TransientDescendantIterator(); | 46 TransientDescendantIterator(); |
47 | 47 |
48 // Copy constructor required for iterator purposes. | 48 // Copy constructor required for iterator purposes. |
49 TransientDescendantIterator( | 49 TransientDescendantIterator( |
50 const TransientDescendantIterator& other) = default; | 50 const TransientDescendantIterator& other) = default; |
51 | 51 |
52 // Iterates over |root_window| and all of its transient descendants. | 52 // Iterates over |root_window| and all of its transient descendants. |
53 // Note |root_window| must not have a transient parent. | 53 // Note |root_window| must not have a transient parent. |
54 explicit TransientDescendantIterator(wm::WmWindow* root_window); | 54 explicit TransientDescendantIterator(WmWindow* root_window); |
55 | 55 |
56 // Prefix increment operator. This assumes there are more items (i.e. | 56 // Prefix increment operator. This assumes there are more items (i.e. |
57 // *this != TransientDescendantIterator()). | 57 // *this != TransientDescendantIterator()). |
58 const TransientDescendantIterator& operator++(); | 58 const TransientDescendantIterator& operator++(); |
59 | 59 |
60 // Comparison for STL-based loops. | 60 // Comparison for STL-based loops. |
61 bool operator!=(const TransientDescendantIterator& other) const; | 61 bool operator!=(const TransientDescendantIterator& other) const; |
62 | 62 |
63 // Dereference operator for STL-compatible iterators. | 63 // Dereference operator for STL-compatible iterators. |
64 wm::WmWindow* operator*() const; | 64 WmWindow* operator*() const; |
65 | 65 |
66 private: | 66 private: |
67 // Explicit assignment operator defined because an explicit copy constructor | 67 // Explicit assignment operator defined because an explicit copy constructor |
68 // is needed and therefore the DISALLOW_COPY_AND_ASSIGN macro cannot be used. | 68 // is needed and therefore the DISALLOW_COPY_AND_ASSIGN macro cannot be used. |
69 TransientDescendantIterator& operator=( | 69 TransientDescendantIterator& operator=( |
70 const TransientDescendantIterator& other) = default; | 70 const TransientDescendantIterator& other) = default; |
71 | 71 |
72 // The current window that |this| refers to. A null |current_window_| denotes | 72 // The current window that |this| refers to. A null |current_window_| denotes |
73 // an empty iterator and is used as the last possible value in the traversal. | 73 // an empty iterator and is used as the last possible value in the traversal. |
74 wm::WmWindow* current_window_; | 74 WmWindow* current_window_; |
75 }; | 75 }; |
76 | 76 |
77 // Provides a virtual container implementing begin() and end() for a sequence of | 77 // Provides a virtual container implementing begin() and end() for a sequence of |
78 // TransientDescendantIterators. This can be used in range-based for loops. | 78 // TransientDescendantIterators. This can be used in range-based for loops. |
79 class TransientDescendantIteratorRange { | 79 class TransientDescendantIteratorRange { |
80 public: | 80 public: |
81 explicit TransientDescendantIteratorRange( | 81 explicit TransientDescendantIteratorRange( |
82 const TransientDescendantIterator& begin); | 82 const TransientDescendantIterator& begin); |
83 | 83 |
84 // Copy constructor required for iterator purposes. | 84 // Copy constructor required for iterator purposes. |
(...skipping 10 matching lines...) Expand all Loading... |
95 const TransientDescendantIteratorRange& other) = default; | 95 const TransientDescendantIteratorRange& other) = default; |
96 | 96 |
97 TransientDescendantIterator begin_; | 97 TransientDescendantIterator begin_; |
98 TransientDescendantIterator end_; | 98 TransientDescendantIterator end_; |
99 }; | 99 }; |
100 | 100 |
101 TransientDescendantIterator::TransientDescendantIterator() | 101 TransientDescendantIterator::TransientDescendantIterator() |
102 : current_window_(nullptr) { | 102 : current_window_(nullptr) { |
103 } | 103 } |
104 | 104 |
105 TransientDescendantIterator::TransientDescendantIterator( | 105 TransientDescendantIterator::TransientDescendantIterator(WmWindow* root_window) |
106 wm::WmWindow* root_window) | |
107 : current_window_(root_window) { | 106 : current_window_(root_window) { |
108 DCHECK(!root_window->GetTransientParent()); | 107 DCHECK(!root_window->GetTransientParent()); |
109 } | 108 } |
110 | 109 |
111 // Performs a pre-order traversal of the transient descendants. | 110 // Performs a pre-order traversal of the transient descendants. |
112 const TransientDescendantIterator& | 111 const TransientDescendantIterator& |
113 TransientDescendantIterator::operator++() { | 112 TransientDescendantIterator::operator++() { |
114 DCHECK(current_window_); | 113 DCHECK(current_window_); |
115 | 114 |
116 const WmWindows transient_children = current_window_->GetTransientChildren(); | 115 const WmWindows transient_children = current_window_->GetTransientChildren(); |
117 | 116 |
118 if (!transient_children.empty()) { | 117 if (!transient_children.empty()) { |
119 current_window_ = transient_children.front(); | 118 current_window_ = transient_children.front(); |
120 } else { | 119 } else { |
121 while (current_window_) { | 120 while (current_window_) { |
122 wm::WmWindow* parent = current_window_->GetTransientParent(); | 121 WmWindow* parent = current_window_->GetTransientParent(); |
123 if (!parent) { | 122 if (!parent) { |
124 current_window_ = nullptr; | 123 current_window_ = nullptr; |
125 break; | 124 break; |
126 } | 125 } |
127 const WmWindows transient_siblings = parent->GetTransientChildren(); | 126 const WmWindows transient_siblings = parent->GetTransientChildren(); |
128 auto iter = std::find(transient_siblings.begin(), | 127 auto iter = std::find(transient_siblings.begin(), |
129 transient_siblings.end(), current_window_); | 128 transient_siblings.end(), current_window_); |
130 ++iter; | 129 ++iter; |
131 if (iter != transient_siblings.end()) { | 130 if (iter != transient_siblings.end()) { |
132 current_window_ = *iter; | 131 current_window_ = *iter; |
133 break; | 132 break; |
134 } | 133 } |
135 current_window_ = current_window_->GetTransientParent(); | 134 current_window_ = current_window_->GetTransientParent(); |
136 } | 135 } |
137 } | 136 } |
138 return *this; | 137 return *this; |
139 } | 138 } |
140 | 139 |
141 bool TransientDescendantIterator::operator!=( | 140 bool TransientDescendantIterator::operator!=( |
142 const TransientDescendantIterator& other) const { | 141 const TransientDescendantIterator& other) const { |
143 return current_window_ != other.current_window_; | 142 return current_window_ != other.current_window_; |
144 } | 143 } |
145 | 144 |
146 wm::WmWindow* TransientDescendantIterator::operator*() const { | 145 WmWindow* TransientDescendantIterator::operator*() const { |
147 return current_window_; | 146 return current_window_; |
148 } | 147 } |
149 | 148 |
150 TransientDescendantIteratorRange::TransientDescendantIteratorRange( | 149 TransientDescendantIteratorRange::TransientDescendantIteratorRange( |
151 const TransientDescendantIterator& begin) | 150 const TransientDescendantIterator& begin) |
152 : begin_(begin) { | 151 : begin_(begin) { |
153 } | 152 } |
154 | 153 |
155 TransientDescendantIteratorRange GetTransientTreeIterator( | 154 TransientDescendantIteratorRange GetTransientTreeIterator(WmWindow* window) { |
156 wm::WmWindow* window) { | |
157 return TransientDescendantIteratorRange( | 155 return TransientDescendantIteratorRange( |
158 TransientDescendantIterator(GetTransientRoot(window))); | 156 TransientDescendantIterator(GetTransientRoot(window))); |
159 } | 157 } |
160 | 158 |
161 } // namespace | 159 } // namespace |
162 | 160 |
163 ScopedTransformOverviewWindow::ScopedTransformOverviewWindow( | 161 ScopedTransformOverviewWindow::ScopedTransformOverviewWindow(WmWindow* window) |
164 wm::WmWindow* window) | |
165 : window_(window), | 162 : window_(window), |
166 minimized_(window->GetShowState() == ui::SHOW_STATE_MINIMIZED), | 163 minimized_(window->GetShowState() == ui::SHOW_STATE_MINIMIZED), |
167 ignored_by_shelf_(window->GetWindowState()->ignored_by_shelf()), | 164 ignored_by_shelf_(window->GetWindowState()->ignored_by_shelf()), |
168 overview_started_(false), | 165 overview_started_(false), |
169 original_transform_(window->GetTargetTransform()), | 166 original_transform_(window->GetTargetTransform()), |
170 original_opacity_(window->GetTargetOpacity()) {} | 167 original_opacity_(window->GetTargetOpacity()) {} |
171 | 168 |
172 ScopedTransformOverviewWindow::~ScopedTransformOverviewWindow() { | 169 ScopedTransformOverviewWindow::~ScopedTransformOverviewWindow() { |
173 } | 170 } |
174 | 171 |
(...skipping 26 matching lines...) Expand all Loading... |
201 | 198 |
202 void ScopedTransformOverviewWindow::BeginScopedAnimation( | 199 void ScopedTransformOverviewWindow::BeginScopedAnimation( |
203 OverviewAnimationType animation_type, | 200 OverviewAnimationType animation_type, |
204 ScopedAnimationSettings* animation_settings) { | 201 ScopedAnimationSettings* animation_settings) { |
205 for (const auto& window : GetTransientTreeIterator(window_)) { | 202 for (const auto& window : GetTransientTreeIterator(window_)) { |
206 animation_settings->push_back( | 203 animation_settings->push_back( |
207 CreateScopedOverviewAnimationSettings(animation_type, window)); | 204 CreateScopedOverviewAnimationSettings(animation_type, window)); |
208 } | 205 } |
209 } | 206 } |
210 | 207 |
211 bool ScopedTransformOverviewWindow::Contains(const wm::WmWindow* target) const { | 208 bool ScopedTransformOverviewWindow::Contains(const WmWindow* target) const { |
212 for (const auto& window : GetTransientTreeIterator(window_)) { | 209 for (const auto& window : GetTransientTreeIterator(window_)) { |
213 if (window->Contains(target)) | 210 if (window->Contains(target)) |
214 return true; | 211 return true; |
215 } | 212 } |
216 return false; | 213 return false; |
217 } | 214 } |
218 | 215 |
219 gfx::Rect ScopedTransformOverviewWindow::GetTargetBoundsInScreen() const { | 216 gfx::Rect ScopedTransformOverviewWindow::GetTargetBoundsInScreen() const { |
220 gfx::Rect bounds; | 217 gfx::Rect bounds; |
221 for (const auto& window : GetTransientTreeIterator(window_)) { | 218 for (const auto& window : GetTransientTreeIterator(window_)) { |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 DCHECK(!src_rect.IsEmpty()); | 271 DCHECK(!src_rect.IsEmpty()); |
275 gfx::Transform transform; | 272 gfx::Transform transform; |
276 transform.Translate(dst_rect.x() - src_rect.x(), | 273 transform.Translate(dst_rect.x() - src_rect.x(), |
277 dst_rect.y() - src_rect.y()); | 274 dst_rect.y() - src_rect.y()); |
278 transform.Scale(static_cast<float>(dst_rect.width()) / src_rect.width(), | 275 transform.Scale(static_cast<float>(dst_rect.width()) / src_rect.width(), |
279 static_cast<float>(dst_rect.height()) / src_rect.height()); | 276 static_cast<float>(dst_rect.height()) / src_rect.height()); |
280 return transform; | 277 return transform; |
281 } | 278 } |
282 | 279 |
283 void ScopedTransformOverviewWindow::SetTransform( | 280 void ScopedTransformOverviewWindow::SetTransform( |
284 wm::WmWindow* root_window, | 281 WmWindow* root_window, |
285 const gfx::Transform& transform) { | 282 const gfx::Transform& transform) { |
286 DCHECK(overview_started_); | 283 DCHECK(overview_started_); |
287 | 284 |
288 gfx::Point target_origin(GetTargetBoundsInScreen().origin()); | 285 gfx::Point target_origin(GetTargetBoundsInScreen().origin()); |
289 | 286 |
290 for (const auto& window : GetTransientTreeIterator(window_)) { | 287 for (const auto& window : GetTransientTreeIterator(window_)) { |
291 wm::WmWindow* parent_window = window->GetParent(); | 288 WmWindow* parent_window = window->GetParent(); |
292 gfx::Point original_origin = | 289 gfx::Point original_origin = |
293 parent_window->ConvertRectToScreen(window->GetTargetBounds()).origin(); | 290 parent_window->ConvertRectToScreen(window->GetTargetBounds()).origin(); |
294 gfx::Transform new_transform = TransformAboutPivot( | 291 gfx::Transform new_transform = TransformAboutPivot( |
295 gfx::Point(target_origin.x() - original_origin.x(), | 292 gfx::Point(target_origin.x() - original_origin.x(), |
296 target_origin.y() - original_origin.y()), | 293 target_origin.y() - original_origin.y()), |
297 transform); | 294 transform); |
298 window->SetTransform(new_transform); | 295 window->SetTransform(new_transform); |
299 } | 296 } |
300 } | 297 } |
301 | 298 |
302 void ScopedTransformOverviewWindow::SetOpacity(float opacity) { | 299 void ScopedTransformOverviewWindow::SetOpacity(float opacity) { |
303 for (const auto& window : GetTransientTreeIterator(window_)) { | 300 for (const auto& window : GetTransientTreeIterator(window_)) { |
304 window->SetOpacity(opacity); | 301 window->SetOpacity(opacity); |
305 } | 302 } |
306 } | 303 } |
307 | 304 |
308 void ScopedTransformOverviewWindow::Close() { | 305 void ScopedTransformOverviewWindow::Close() { |
309 GetTransientRoot(window_)->CloseWidget(); | 306 GetTransientRoot(window_)->CloseWidget(); |
310 } | 307 } |
311 | 308 |
312 void ScopedTransformOverviewWindow::PrepareForOverview() { | 309 void ScopedTransformOverviewWindow::PrepareForOverview() { |
313 DCHECK(!overview_started_); | 310 DCHECK(!overview_started_); |
314 overview_started_ = true; | 311 overview_started_ = true; |
315 window_->GetWindowState()->set_ignored_by_shelf(true); | 312 window_->GetWindowState()->set_ignored_by_shelf(true); |
316 ShowWindowIfMinimized(); | 313 ShowWindowIfMinimized(); |
317 } | 314 } |
318 | 315 |
319 } // namespace ash | 316 } // namespace ash |
OLD | NEW |