| 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/common/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/material_design/material_design_controller.h" | 10 #include "ash/common/material_design/material_design_controller.h" |
| 11 #include "ash/common/wm/overview/scoped_overview_animation_settings.h" |
| 12 #include "ash/common/wm/overview/scoped_overview_animation_settings_factory.h" |
| 13 #include "ash/common/wm/overview/window_selector_item.h" |
| 11 #include "ash/common/wm/window_state.h" | 14 #include "ash/common/wm/window_state.h" |
| 12 #include "ash/common/wm_window.h" | 15 #include "ash/common/wm_window.h" |
| 13 #include "ash/common/wm_window_property.h" | 16 #include "ash/common/wm_window_property.h" |
| 14 #include "ash/wm/overview/scoped_overview_animation_settings.h" | |
| 15 #include "ash/wm/overview/scoped_overview_animation_settings_factory.h" | |
| 16 #include "ash/wm/overview/window_selector_item.h" | |
| 17 #include "base/macros.h" | 17 #include "base/macros.h" |
| 18 #include "third_party/skia/include/core/SkPaint.h" | 18 #include "third_party/skia/include/core/SkPaint.h" |
| 19 #include "third_party/skia/include/core/SkPath.h" | 19 #include "third_party/skia/include/core/SkPath.h" |
| 20 #include "third_party/skia/include/core/SkRect.h" | 20 #include "third_party/skia/include/core/SkRect.h" |
| 21 #include "ui/compositor/layer.h" | 21 #include "ui/compositor/layer.h" |
| 22 #include "ui/compositor/layer_delegate.h" | 22 #include "ui/compositor/layer_delegate.h" |
| 23 #include "ui/compositor/paint_recorder.h" | 23 #include "ui/compositor/paint_recorder.h" |
| 24 #include "ui/gfx/geometry/rect.h" | 24 #include "ui/gfx/geometry/rect.h" |
| 25 #include "ui/gfx/geometry/safe_integer_conversions.h" | 25 #include "ui/gfx/geometry/safe_integer_conversions.h" |
| 26 #include "ui/gfx/transform_util.h" | 26 #include "ui/gfx/transform_util.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 51 } | 51 } |
| 52 | 52 |
| 53 // An iterator class that traverses a WmWindow and all of its transient | 53 // An iterator class that traverses a WmWindow and all of its transient |
| 54 // descendants. | 54 // descendants. |
| 55 class TransientDescendantIterator { | 55 class TransientDescendantIterator { |
| 56 public: | 56 public: |
| 57 // Creates an empty iterator. | 57 // Creates an empty iterator. |
| 58 TransientDescendantIterator(); | 58 TransientDescendantIterator(); |
| 59 | 59 |
| 60 // Copy constructor required for iterator purposes. | 60 // Copy constructor required for iterator purposes. |
| 61 TransientDescendantIterator( | 61 TransientDescendantIterator(const TransientDescendantIterator& other) = |
| 62 const TransientDescendantIterator& other) = default; | 62 default; |
| 63 | 63 |
| 64 // Iterates over |root_window| and all of its transient descendants. | 64 // Iterates over |root_window| and all of its transient descendants. |
| 65 // Note |root_window| must not have a transient parent. | 65 // Note |root_window| must not have a transient parent. |
| 66 explicit TransientDescendantIterator(WmWindow* root_window); | 66 explicit TransientDescendantIterator(WmWindow* root_window); |
| 67 | 67 |
| 68 // Prefix increment operator. This assumes there are more items (i.e. | 68 // Prefix increment operator. This assumes there are more items (i.e. |
| 69 // *this != TransientDescendantIterator()). | 69 // *this != TransientDescendantIterator()). |
| 70 const TransientDescendantIterator& operator++(); | 70 const TransientDescendantIterator& operator++(); |
| 71 | 71 |
| 72 // Comparison for STL-based loops. | 72 // Comparison for STL-based loops. |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 // Explicit assignment operator defined because an explicit copy constructor | 104 // Explicit assignment operator defined because an explicit copy constructor |
| 105 // is needed and therefore the DISALLOW_COPY_AND_ASSIGN macro cannot be used. | 105 // is needed and therefore the DISALLOW_COPY_AND_ASSIGN macro cannot be used. |
| 106 TransientDescendantIteratorRange& operator=( | 106 TransientDescendantIteratorRange& operator=( |
| 107 const TransientDescendantIteratorRange& other) = default; | 107 const TransientDescendantIteratorRange& other) = default; |
| 108 | 108 |
| 109 TransientDescendantIterator begin_; | 109 TransientDescendantIterator begin_; |
| 110 TransientDescendantIterator end_; | 110 TransientDescendantIterator end_; |
| 111 }; | 111 }; |
| 112 | 112 |
| 113 TransientDescendantIterator::TransientDescendantIterator() | 113 TransientDescendantIterator::TransientDescendantIterator() |
| 114 : current_window_(nullptr) { | 114 : current_window_(nullptr) {} |
| 115 } | |
| 116 | 115 |
| 117 TransientDescendantIterator::TransientDescendantIterator(WmWindow* root_window) | 116 TransientDescendantIterator::TransientDescendantIterator(WmWindow* root_window) |
| 118 : current_window_(root_window) { | 117 : current_window_(root_window) { |
| 119 DCHECK(!root_window->GetTransientParent()); | 118 DCHECK(!root_window->GetTransientParent()); |
| 120 } | 119 } |
| 121 | 120 |
| 122 // Performs a pre-order traversal of the transient descendants. | 121 // Performs a pre-order traversal of the transient descendants. |
| 123 const TransientDescendantIterator& | 122 const TransientDescendantIterator& TransientDescendantIterator::operator++() { |
| 124 TransientDescendantIterator::operator++() { | |
| 125 DCHECK(current_window_); | 123 DCHECK(current_window_); |
| 126 | 124 |
| 127 const WmWindows transient_children = current_window_->GetTransientChildren(); | 125 const WmWindows transient_children = current_window_->GetTransientChildren(); |
| 128 | 126 |
| 129 if (!transient_children.empty()) { | 127 if (!transient_children.empty()) { |
| 130 current_window_ = transient_children.front(); | 128 current_window_ = transient_children.front(); |
| 131 } else { | 129 } else { |
| 132 while (current_window_) { | 130 while (current_window_) { |
| 133 WmWindow* parent = current_window_->GetTransientParent(); | 131 WmWindow* parent = current_window_->GetTransientParent(); |
| 134 if (!parent) { | 132 if (!parent) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 153 const TransientDescendantIterator& other) const { | 151 const TransientDescendantIterator& other) const { |
| 154 return current_window_ != other.current_window_; | 152 return current_window_ != other.current_window_; |
| 155 } | 153 } |
| 156 | 154 |
| 157 WmWindow* TransientDescendantIterator::operator*() const { | 155 WmWindow* TransientDescendantIterator::operator*() const { |
| 158 return current_window_; | 156 return current_window_; |
| 159 } | 157 } |
| 160 | 158 |
| 161 TransientDescendantIteratorRange::TransientDescendantIteratorRange( | 159 TransientDescendantIteratorRange::TransientDescendantIteratorRange( |
| 162 const TransientDescendantIterator& begin) | 160 const TransientDescendantIterator& begin) |
| 163 : begin_(begin) { | 161 : begin_(begin) {} |
| 164 } | |
| 165 | 162 |
| 166 TransientDescendantIteratorRange GetTransientTreeIterator(WmWindow* window) { | 163 TransientDescendantIteratorRange GetTransientTreeIterator(WmWindow* window) { |
| 167 return TransientDescendantIteratorRange( | 164 return TransientDescendantIteratorRange( |
| 168 TransientDescendantIterator(GetTransientRoot(window))); | 165 TransientDescendantIterator(GetTransientRoot(window))); |
| 169 } | 166 } |
| 170 | 167 |
| 171 } // namespace | 168 } // namespace |
| 172 | 169 |
| 173 // Mask layer that clips the window's original header in overview mode. | 170 // Mask layer that clips the window's original header in overview mode. |
| 174 // Only used with Material Design. | 171 // Only used with Material Design. |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 } | 241 } |
| 245 | 242 |
| 246 ScopedTransformOverviewWindow::ScopedTransformOverviewWindow(WmWindow* window) | 243 ScopedTransformOverviewWindow::ScopedTransformOverviewWindow(WmWindow* window) |
| 247 : window_(window), | 244 : window_(window), |
| 248 minimized_(window->GetShowState() == ui::SHOW_STATE_MINIMIZED), | 245 minimized_(window->GetShowState() == ui::SHOW_STATE_MINIMIZED), |
| 249 ignored_by_shelf_(window->GetWindowState()->ignored_by_shelf()), | 246 ignored_by_shelf_(window->GetWindowState()->ignored_by_shelf()), |
| 250 overview_started_(false), | 247 overview_started_(false), |
| 251 original_transform_(window->GetTargetTransform()), | 248 original_transform_(window->GetTargetTransform()), |
| 252 original_opacity_(window->GetTargetOpacity()) {} | 249 original_opacity_(window->GetTargetOpacity()) {} |
| 253 | 250 |
| 254 ScopedTransformOverviewWindow::~ScopedTransformOverviewWindow() { | 251 ScopedTransformOverviewWindow::~ScopedTransformOverviewWindow() {} |
| 255 } | |
| 256 | 252 |
| 257 void ScopedTransformOverviewWindow::RestoreWindow() { | 253 void ScopedTransformOverviewWindow::RestoreWindow() { |
| 258 if (ash::MaterialDesignController::IsOverviewMaterial()) { | 254 if (ash::MaterialDesignController::IsOverviewMaterial()) { |
| 259 window()->GetLayer()->SetMaskLayer(nullptr); | 255 window()->GetLayer()->SetMaskLayer(nullptr); |
| 260 mask_.reset(); | 256 mask_.reset(); |
| 261 } | 257 } |
| 262 | 258 |
| 263 ScopedAnimationSettings animation_settings_list; | 259 ScopedAnimationSettings animation_settings_list; |
| 264 BeginScopedAnimation( | 260 BeginScopedAnimation(OverviewAnimationType::OVERVIEW_ANIMATION_RESTORE_WINDOW, |
| 265 OverviewAnimationType::OVERVIEW_ANIMATION_RESTORE_WINDOW, | 261 &animation_settings_list); |
| 266 &animation_settings_list); | |
| 267 SetTransform(window()->GetRootWindow(), original_transform_, 0); | 262 SetTransform(window()->GetRootWindow(), original_transform_, 0); |
| 268 | 263 |
| 269 std::unique_ptr<ScopedOverviewAnimationSettings> animation_settings = | 264 std::unique_ptr<ScopedOverviewAnimationSettings> animation_settings = |
| 270 CreateScopedOverviewAnimationSettings( | 265 CreateScopedOverviewAnimationSettings( |
| 271 OverviewAnimationType::OVERVIEW_ANIMATION_LAY_OUT_SELECTOR_ITEMS, | 266 OverviewAnimationType::OVERVIEW_ANIMATION_LAY_OUT_SELECTOR_ITEMS, |
| 272 window_); | 267 window_); |
| 273 gfx::Transform transform; | 268 gfx::Transform transform; |
| 274 if (minimized_ && window_->GetShowState() != ui::SHOW_STATE_MINIMIZED) { | 269 if (minimized_ && window_->GetShowState() != ui::SHOW_STATE_MINIMIZED) { |
| 275 // Setting opacity 0 and visible false ensures that the property change | 270 // Setting opacity 0 and visible false ensures that the property change |
| 276 // to SHOW_STATE_MINIMIZED will not animate the window from its original | 271 // to SHOW_STATE_MINIMIZED will not animate the window from its original |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 374 bounds.height() - vertical_offset); | 369 bounds.height() - vertical_offset); |
| 375 return gfx::Rect(bounds.x() + horizontal_offset, bounds.y() + vertical_offset, | 370 return gfx::Rect(bounds.x() + horizontal_offset, bounds.y() + vertical_offset, |
| 376 width, height); | 371 width, height); |
| 377 } | 372 } |
| 378 | 373 |
| 379 gfx::Transform ScopedTransformOverviewWindow::GetTransformForRect( | 374 gfx::Transform ScopedTransformOverviewWindow::GetTransformForRect( |
| 380 const gfx::Rect& src_rect, | 375 const gfx::Rect& src_rect, |
| 381 const gfx::Rect& dst_rect) { | 376 const gfx::Rect& dst_rect) { |
| 382 DCHECK(!src_rect.IsEmpty()); | 377 DCHECK(!src_rect.IsEmpty()); |
| 383 gfx::Transform transform; | 378 gfx::Transform transform; |
| 384 transform.Translate(dst_rect.x() - src_rect.x(), | 379 transform.Translate(dst_rect.x() - src_rect.x(), dst_rect.y() - src_rect.y()); |
| 385 dst_rect.y() - src_rect.y()); | |
| 386 transform.Scale(static_cast<float>(dst_rect.width()) / src_rect.width(), | 380 transform.Scale(static_cast<float>(dst_rect.width()) / src_rect.width(), |
| 387 static_cast<float>(dst_rect.height()) / src_rect.height()); | 381 static_cast<float>(dst_rect.height()) / src_rect.height()); |
| 388 return transform; | 382 return transform; |
| 389 } | 383 } |
| 390 | 384 |
| 391 void ScopedTransformOverviewWindow::SetTransform( | 385 void ScopedTransformOverviewWindow::SetTransform( |
| 392 WmWindow* root_window, | 386 WmWindow* root_window, |
| 393 const gfx::Transform& transform, | 387 const gfx::Transform& transform, |
| 394 int radius) { | 388 int radius) { |
| 395 DCHECK(overview_started_); | 389 DCHECK(overview_started_); |
| 396 | 390 |
| 397 if (ash::MaterialDesignController::IsOverviewMaterial()) { | 391 if (ash::MaterialDesignController::IsOverviewMaterial()) { |
| 398 mask_.reset(new OverviewContentMask( | 392 mask_.reset(new OverviewContentMask( |
| 399 window()->GetIntProperty(WmWindowProperty::TOP_VIEW_INSET), radius)); | 393 window()->GetIntProperty(WmWindowProperty::TOP_VIEW_INSET), radius)); |
| 400 mask_->layer()->SetBounds(GetTargetBoundsInScreen()); | 394 mask_->layer()->SetBounds(GetTargetBoundsInScreen()); |
| 401 window()->GetLayer()->SetMaskLayer(mask_->layer()); | 395 window()->GetLayer()->SetMaskLayer(mask_->layer()); |
| 402 } | 396 } |
| 403 | 397 |
| 404 gfx::Point target_origin(GetTargetBoundsInScreen().origin()); | 398 gfx::Point target_origin(GetTargetBoundsInScreen().origin()); |
| 405 | 399 |
| 406 for (const auto& window : GetTransientTreeIterator(window_)) { | 400 for (const auto& window : GetTransientTreeIterator(window_)) { |
| 407 WmWindow* parent_window = window->GetParent(); | 401 WmWindow* parent_window = window->GetParent(); |
| 408 gfx::Point original_origin = | 402 gfx::Point original_origin = |
| 409 parent_window->ConvertRectToScreen(window->GetTargetBounds()).origin(); | 403 parent_window->ConvertRectToScreen(window->GetTargetBounds()).origin(); |
| 410 gfx::Transform new_transform = TransformAboutPivot( | 404 gfx::Transform new_transform = |
| 411 gfx::Point(target_origin.x() - original_origin.x(), | 405 TransformAboutPivot(gfx::Point(target_origin.x() - original_origin.x(), |
| 412 target_origin.y() - original_origin.y()), | 406 target_origin.y() - original_origin.y()), |
| 413 transform); | 407 transform); |
| 414 window->SetTransform(new_transform); | 408 window->SetTransform(new_transform); |
| 415 } | 409 } |
| 416 } | 410 } |
| 417 | 411 |
| 418 void ScopedTransformOverviewWindow::SetOpacity(float opacity) { | 412 void ScopedTransformOverviewWindow::SetOpacity(float opacity) { |
| 419 for (const auto& window : GetTransientTreeIterator(window_)) { | 413 for (const auto& window : GetTransientTreeIterator(window_)) { |
| 420 window->SetOpacity(opacity); | 414 window->SetOpacity(opacity); |
| 421 } | 415 } |
| 422 } | 416 } |
| 423 | 417 |
| 424 void ScopedTransformOverviewWindow::Close() { | 418 void ScopedTransformOverviewWindow::Close() { |
| 425 GetTransientRoot(window_)->CloseWidget(); | 419 GetTransientRoot(window_)->CloseWidget(); |
| 426 } | 420 } |
| 427 | 421 |
| 428 void ScopedTransformOverviewWindow::PrepareForOverview() { | 422 void ScopedTransformOverviewWindow::PrepareForOverview() { |
| 429 DCHECK(!overview_started_); | 423 DCHECK(!overview_started_); |
| 430 overview_started_ = true; | 424 overview_started_ = true; |
| 431 window_->GetWindowState()->set_ignored_by_shelf(true); | 425 window_->GetWindowState()->set_ignored_by_shelf(true); |
| 432 ShowWindowIfMinimized(); | 426 ShowWindowIfMinimized(); |
| 433 } | 427 } |
| 434 | 428 |
| 435 } // namespace ash | 429 } // namespace ash |
| OLD | NEW |