Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(243)

Side by Side Diff: ash/wm/overview/scoped_transform_overview_window.cc

Issue 2012343002: Converts overview to use common ash types (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: feedback Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ash/wm/overview/scoped_transform_overview_window.h ('k') | ash/wm/overview/window_grid.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/screen_util.h"
11 #include "ash/shell_window_ids.h"
12 #include "ash/wm/common/window_state.h" 10 #include "ash/wm/common/window_state.h"
11 #include "ash/wm/common/wm_window.h"
13 #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"
14 #include "ash/wm/overview/window_selector_item.h" 14 #include "ash/wm/overview/window_selector_item.h"
15 #include "ash/wm/window_state_aura.h"
16 #include "ash/wm/window_util.h"
17 #include "base/macros.h" 15 #include "base/macros.h"
18 #include "ui/aura/client/aura_constants.h" 16 #include "ui/gfx/geometry/rect.h"
19 #include "ui/aura/client/screen_position_client.h"
20 #include "ui/aura/window.h"
21 #include "ui/compositor/scoped_layer_animation_settings.h"
22 #include "ui/gfx/animation/tween.h"
23 #include "ui/gfx/transform_util.h" 17 #include "ui/gfx/transform_util.h"
24 #include "ui/views/widget/widget.h" 18
25 #include "ui/wm/core/window_animations.h" 19 using WmWindows = std::vector<ash::wm::WmWindow*>;
26 #include "ui/wm/core/window_util.h"
27 20
28 namespace ash { 21 namespace ash {
29 22
30 namespace { 23 namespace {
31 24
32 // 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.
33 const float kRestoreWindowOpacity = 1.0f; 26 const float kRestoreWindowOpacity = 1.0f;
34 27
35 aura::Window* GetTransientRoot(aura::Window* window) { 28 wm::WmWindow* GetTransientRoot(wm::WmWindow* window) {
36 while (::wm::GetTransientParent(window)) 29 while (window->GetTransientParent())
37 window = ::wm::GetTransientParent(window); 30 window = window->GetTransientParent();
38 return window; 31 return window;
39 } 32 }
40 33
41 // An iterator class that traverses an aura::Window and all of it's transient 34 std::unique_ptr<ScopedOverviewAnimationSettings>
35 CreateScopedOverviewAnimationSettings(OverviewAnimationType animation_type,
36 wm::WmWindow* window) {
37 return ScopedOverviewAnimationSettingsFactory::Get()
38 ->CreateOverviewAnimationSettings(animation_type, window);
39 }
40
41 // An iterator class that traverses a wm::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(aura::Window* root_window); 54 explicit TransientDescendantIterator(wm::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 aura::Window* operator*() const; 64 wm::WmWindow* operator*() const;
65 65
66 private: 66 private:
67 // The current window that |this| refers to. A NULL |current_window_| denotes
68 // an empty iterator and is used as the last possible value in the traversal.
69 aura::Window* current_window_;
70
71 // Explicit assignment operator defined because an explicit copy constructor 67 // Explicit assignment operator defined because an explicit copy constructor
72 // 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.
73 TransientDescendantIterator& operator=( 69 TransientDescendantIterator& operator=(
74 const TransientDescendantIterator& other) = default; 70 const TransientDescendantIterator& other) = default;
71
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.
74 wm::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.
85 TransientDescendantIteratorRange( 85 TransientDescendantIteratorRange(
86 const TransientDescendantIteratorRange& other) = default; 86 const TransientDescendantIteratorRange& other) = default;
87 87
88 const TransientDescendantIterator& begin() const { return begin_; } 88 const TransientDescendantIterator& begin() const { return begin_; }
89 const TransientDescendantIterator& end() const { return end_; } 89 const TransientDescendantIterator& end() const { return end_; }
90 90
91 private: 91 private:
92 TransientDescendantIterator begin_;
93 TransientDescendantIterator end_;
94
95 // Explicit assignment operator defined because an explicit copy constructor 92 // Explicit assignment operator defined because an explicit copy constructor
96 // is needed and therefore the DISALLOW_COPY_AND_ASSIGN macro cannot be used. 93 // is needed and therefore the DISALLOW_COPY_AND_ASSIGN macro cannot be used.
97 TransientDescendantIteratorRange& operator=( 94 TransientDescendantIteratorRange& operator=(
98 const TransientDescendantIteratorRange& other) = default; 95 const TransientDescendantIteratorRange& other) = default;
96
97 TransientDescendantIterator begin_;
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(
106 aura::Window* root_window) 106 wm::WmWindow* root_window)
107 : current_window_(root_window) { 107 : current_window_(root_window) {
108 DCHECK(!::wm::GetTransientParent(root_window)); 108 DCHECK(!root_window->GetTransientParent());
109 } 109 }
110 110
111 // Performs a pre-order traversal of the transient descendants. 111 // Performs a pre-order traversal of the transient descendants.
112 const TransientDescendantIterator& 112 const TransientDescendantIterator&
113 TransientDescendantIterator::operator++() { 113 TransientDescendantIterator::operator++() {
114 DCHECK(current_window_); 114 DCHECK(current_window_);
115 115
116 const aura::Window::Windows& transient_children = 116 const WmWindows transient_children = current_window_->GetTransientChildren();
117 ::wm::GetTransientChildren(current_window_);
118 117
119 if (transient_children.size() > 0) { 118 if (!transient_children.empty()) {
120 current_window_ = transient_children.front(); 119 current_window_ = transient_children.front();
121 } else { 120 } else {
122 while (current_window_) { 121 while (current_window_) {
123 aura::Window* parent = ::wm::GetTransientParent(current_window_); 122 wm::WmWindow* parent = current_window_->GetTransientParent();
124 if (!parent) { 123 if (!parent) {
125 current_window_ = nullptr; 124 current_window_ = nullptr;
126 break; 125 break;
127 } 126 }
128 const aura::Window::Windows& transient_siblings = 127 const WmWindows transient_siblings = parent->GetTransientChildren();
129 ::wm::GetTransientChildren(parent); 128 auto iter = std::find(transient_siblings.begin(),
130 aura::Window::Windows::const_iterator iter = std::find( 129 transient_siblings.end(), current_window_);
131 transient_siblings.begin(),
132 transient_siblings.end(),
133 current_window_);
134 ++iter; 130 ++iter;
135 if (iter != transient_siblings.end()) { 131 if (iter != transient_siblings.end()) {
136 current_window_ = *iter; 132 current_window_ = *iter;
137 break; 133 break;
138 } 134 }
139 current_window_ = ::wm::GetTransientParent(current_window_); 135 current_window_ = current_window_->GetTransientParent();
140 } 136 }
141 } 137 }
142 return *this; 138 return *this;
143 } 139 }
144 140
145 bool TransientDescendantIterator::operator!=( 141 bool TransientDescendantIterator::operator!=(
146 const TransientDescendantIterator& other) const { 142 const TransientDescendantIterator& other) const {
147 return current_window_ != other.current_window_; 143 return current_window_ != other.current_window_;
148 } 144 }
149 145
150 aura::Window* TransientDescendantIterator::operator*() const { 146 wm::WmWindow* TransientDescendantIterator::operator*() const {
151 return current_window_; 147 return current_window_;
152 } 148 }
153 149
154 TransientDescendantIteratorRange::TransientDescendantIteratorRange( 150 TransientDescendantIteratorRange::TransientDescendantIteratorRange(
155 const TransientDescendantIterator& begin) 151 const TransientDescendantIterator& begin)
156 : begin_(begin) { 152 : begin_(begin) {
157 } 153 }
158 154
159 TransientDescendantIteratorRange GetTransientTreeIterator( 155 TransientDescendantIteratorRange GetTransientTreeIterator(
160 aura::Window* window) { 156 wm::WmWindow* window) {
161 return TransientDescendantIteratorRange( 157 return TransientDescendantIteratorRange(
162 TransientDescendantIterator(GetTransientRoot(window))); 158 TransientDescendantIterator(GetTransientRoot(window)));
163 } 159 }
164 160
165 } // namespace 161 } // namespace
166 162
167 ScopedTransformOverviewWindow::ScopedTransformOverviewWindow( 163 ScopedTransformOverviewWindow::ScopedTransformOverviewWindow(
168 aura::Window* window) 164 wm::WmWindow* window)
169 : window_(window), 165 : window_(window),
170 minimized_(window->GetProperty(aura::client::kShowStateKey) == 166 minimized_(window->GetShowState() == ui::SHOW_STATE_MINIMIZED),
171 ui::SHOW_STATE_MINIMIZED), 167 ignored_by_shelf_(window->GetWindowState()->ignored_by_shelf()),
172 ignored_by_shelf_(wm::GetWindowState(window)->ignored_by_shelf()),
173 overview_started_(false), 168 overview_started_(false),
174 original_transform_(window->layer()->GetTargetTransform()), 169 original_transform_(window->GetTargetTransform()),
175 original_opacity_(window->layer()->GetTargetOpacity()) { 170 original_opacity_(window->GetTargetOpacity()) {}
176 DCHECK(window_);
177 }
178 171
179 ScopedTransformOverviewWindow::~ScopedTransformOverviewWindow() { 172 ScopedTransformOverviewWindow::~ScopedTransformOverviewWindow() {
180 } 173 }
181 174
182 void ScopedTransformOverviewWindow::RestoreWindow() { 175 void ScopedTransformOverviewWindow::RestoreWindow() {
183 ScopedAnimationSettings animation_settings_list; 176 ScopedAnimationSettings animation_settings_list;
184 BeginScopedAnimation( 177 BeginScopedAnimation(
185 OverviewAnimationType::OVERVIEW_ANIMATION_RESTORE_WINDOW, 178 OverviewAnimationType::OVERVIEW_ANIMATION_RESTORE_WINDOW,
186 &animation_settings_list); 179 &animation_settings_list);
187 SetTransform(window()->GetRootWindow(), original_transform_); 180 SetTransform(window()->GetRootWindow(), original_transform_);
188 181
189 ScopedOverviewAnimationSettings animation_settings( 182 std::unique_ptr<ScopedOverviewAnimationSettings> animation_settings =
190 OverviewAnimationType::OVERVIEW_ANIMATION_LAY_OUT_SELECTOR_ITEMS, 183 CreateScopedOverviewAnimationSettings(
191 window_); 184 OverviewAnimationType::OVERVIEW_ANIMATION_LAY_OUT_SELECTOR_ITEMS,
185 window_);
192 gfx::Transform transform; 186 gfx::Transform transform;
193 if (minimized_ && window_->GetProperty(aura::client::kShowStateKey) != 187 if (minimized_ && window_->GetShowState() != ui::SHOW_STATE_MINIMIZED) {
194 ui::SHOW_STATE_MINIMIZED) {
195 // Setting opacity 0 and visible false ensures that the property change 188 // Setting opacity 0 and visible false ensures that the property change
196 // to SHOW_STATE_MINIMIZED will not animate the window from its original 189 // to SHOW_STATE_MINIMIZED will not animate the window from its original
197 // bounds to the minimized position. 190 // bounds to the minimized position.
198 // Hiding the window needs to be done before the target opacity is 0, 191 // Hiding the window needs to be done before the target opacity is 0,
199 // otherwise the layer's visibility will not be updated 192 // otherwise the layer's visibility will not be updated
200 // (See VisibilityController::UpdateLayerVisibility). 193 // (See VisibilityController::UpdateLayerVisibility).
201 window_->Hide(); 194 window_->Hide();
202 window_->layer()->SetOpacity(0); 195 window_->SetOpacity(0);
203 window_->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MINIMIZED); 196 window_->SetShowState(ui::SHOW_STATE_MINIMIZED);
204 } 197 }
205 wm::GetWindowState(window_)->set_ignored_by_shelf(ignored_by_shelf_); 198 window_->GetWindowState()->set_ignored_by_shelf(ignored_by_shelf_);
206 SetOpacity(original_opacity_); 199 SetOpacity(original_opacity_);
207 } 200 }
208 201
209 void ScopedTransformOverviewWindow::BeginScopedAnimation( 202 void ScopedTransformOverviewWindow::BeginScopedAnimation(
210 OverviewAnimationType animation_type, 203 OverviewAnimationType animation_type,
211 ScopedAnimationSettings* animation_settings) { 204 ScopedAnimationSettings* animation_settings) {
212 for (const auto& window : GetTransientTreeIterator(window_)) { 205 for (const auto& window : GetTransientTreeIterator(window_)) {
213 animation_settings->push_back( 206 animation_settings->push_back(
214 new ScopedOverviewAnimationSettings(animation_type, window)); 207 CreateScopedOverviewAnimationSettings(animation_type, window));
215 } 208 }
216 } 209 }
217 210
218 bool ScopedTransformOverviewWindow::Contains(const aura::Window* target) const { 211 bool ScopedTransformOverviewWindow::Contains(const wm::WmWindow* target) const {
219 for (const auto& window : GetTransientTreeIterator(window_)) { 212 for (const auto& window : GetTransientTreeIterator(window_)) {
220 if (window->Contains(target)) 213 if (window->Contains(target))
221 return true; 214 return true;
222 } 215 }
223 return false; 216 return false;
224 } 217 }
225 218
226 gfx::Rect ScopedTransformOverviewWindow::GetTargetBoundsInScreen() const { 219 gfx::Rect ScopedTransformOverviewWindow::GetTargetBoundsInScreen() const {
227 gfx::Rect bounds; 220 gfx::Rect bounds;
228 for (const auto& window : GetTransientTreeIterator(window_)) { 221 for (const auto& window : GetTransientTreeIterator(window_)) {
229 // Ignore other window types when computing bounding box of window 222 // Ignore other window types when computing bounding box of window
230 // selector target item. 223 // selector target item.
231 if (window != window_ && window->type() != ui::wm::WINDOW_TYPE_NORMAL && 224 if (window != window_ && window->GetType() != ui::wm::WINDOW_TYPE_NORMAL &&
232 window->type() != ui::wm::WINDOW_TYPE_PANEL) { 225 window->GetType() != ui::wm::WINDOW_TYPE_PANEL) {
233 continue; 226 continue;
234 } 227 }
235 bounds.Union(ScreenUtil::ConvertRectToScreen(window->parent(), 228 bounds.Union(
236 window->GetTargetBounds())); 229 window->GetParent()->ConvertRectToScreen(window->GetTargetBounds()));
237 } 230 }
238 return bounds; 231 return bounds;
239 } 232 }
240 233
241 void ScopedTransformOverviewWindow::ShowWindowIfMinimized() { 234 void ScopedTransformOverviewWindow::ShowWindowIfMinimized() {
242 if (minimized_ && window_->GetProperty(aura::client::kShowStateKey) == 235 if (minimized_ && window_->GetShowState() == ui::SHOW_STATE_MINIMIZED)
243 ui::SHOW_STATE_MINIMIZED) {
244 window_->Show(); 236 window_->Show();
245 }
246 } 237 }
247 238
248 void ScopedTransformOverviewWindow::ShowWindowOnExit() { 239 void ScopedTransformOverviewWindow::ShowWindowOnExit() {
249 if (minimized_) { 240 if (minimized_) {
250 minimized_ = false; 241 minimized_ = false;
251 original_transform_ = gfx::Transform(); 242 original_transform_ = gfx::Transform();
252 original_opacity_ = kRestoreWindowOpacity; 243 original_opacity_ = kRestoreWindowOpacity;
253 } 244 }
254 } 245 }
255 246
(...skipping 27 matching lines...) Expand all
283 DCHECK(!src_rect.IsEmpty()); 274 DCHECK(!src_rect.IsEmpty());
284 gfx::Transform transform; 275 gfx::Transform transform;
285 transform.Translate(dst_rect.x() - src_rect.x(), 276 transform.Translate(dst_rect.x() - src_rect.x(),
286 dst_rect.y() - src_rect.y()); 277 dst_rect.y() - src_rect.y());
287 transform.Scale(static_cast<float>(dst_rect.width()) / src_rect.width(), 278 transform.Scale(static_cast<float>(dst_rect.width()) / src_rect.width(),
288 static_cast<float>(dst_rect.height()) / src_rect.height()); 279 static_cast<float>(dst_rect.height()) / src_rect.height());
289 return transform; 280 return transform;
290 } 281 }
291 282
292 void ScopedTransformOverviewWindow::SetTransform( 283 void ScopedTransformOverviewWindow::SetTransform(
293 aura::Window* root_window, 284 wm::WmWindow* root_window,
294 const gfx::Transform& transform) { 285 const gfx::Transform& transform) {
295 DCHECK(overview_started_); 286 DCHECK(overview_started_);
296 287
297 gfx::Point target_origin(GetTargetBoundsInScreen().origin()); 288 gfx::Point target_origin(GetTargetBoundsInScreen().origin());
298 289
299 for (const auto& window : GetTransientTreeIterator(window_)) { 290 for (const auto& window : GetTransientTreeIterator(window_)) {
300 aura::Window* parent_window = window->parent(); 291 wm::WmWindow* parent_window = window->GetParent();
301 gfx::Point original_origin = ScreenUtil::ConvertRectToScreen( 292 gfx::Point original_origin =
302 parent_window, window->GetTargetBounds()).origin(); 293 parent_window->ConvertRectToScreen(window->GetTargetBounds()).origin();
303 gfx::Transform new_transform = TransformAboutPivot( 294 gfx::Transform new_transform = TransformAboutPivot(
304 gfx::Point(target_origin.x() - original_origin.x(), 295 gfx::Point(target_origin.x() - original_origin.x(),
305 target_origin.y() - original_origin.y()), 296 target_origin.y() - original_origin.y()),
306 transform); 297 transform);
307 window->SetTransform(new_transform); 298 window->SetTransform(new_transform);
308 } 299 }
309 } 300 }
310 301
311 void ScopedTransformOverviewWindow::SetOpacity(float opacity) { 302 void ScopedTransformOverviewWindow::SetOpacity(float opacity) {
312 for (const auto& window : GetTransientTreeIterator(window_)) { 303 for (const auto& window : GetTransientTreeIterator(window_)) {
313 window->layer()->SetOpacity(opacity); 304 window->SetOpacity(opacity);
314 } 305 }
315 } 306 }
316 307
317 void ScopedTransformOverviewWindow::Close() { 308 void ScopedTransformOverviewWindow::Close() {
318 aura::Window* window = GetTransientRoot(window_); 309 GetTransientRoot(window_)->CloseWidget();
319 views::Widget::GetWidgetForNativeView(window)->Close();
320 } 310 }
321 311
322 void ScopedTransformOverviewWindow::PrepareForOverview() { 312 void ScopedTransformOverviewWindow::PrepareForOverview() {
323 DCHECK(!overview_started_); 313 DCHECK(!overview_started_);
324 overview_started_ = true; 314 overview_started_ = true;
325 wm::GetWindowState(window_)->set_ignored_by_shelf(true); 315 window_->GetWindowState()->set_ignored_by_shelf(true);
326 ShowWindowIfMinimized(); 316 ShowWindowIfMinimized();
327 } 317 }
328 318
329 } // namespace ash 319 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/overview/scoped_transform_overview_window.h ('k') | ash/wm/overview/window_grid.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698