| 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/common/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" |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 TransientDescendantIterator(GetTransientRoot(window))); | 173 TransientDescendantIterator(GetTransientRoot(window))); |
| 174 } | 174 } |
| 175 | 175 |
| 176 } // namespace | 176 } // namespace |
| 177 | 177 |
| 178 // Mask layer that clips the window's original header in overview mode. | 178 // Mask layer that clips the window's original header in overview mode. |
| 179 // Only used with Material Design. | 179 // Only used with Material Design. |
| 180 class ScopedTransformOverviewWindow::OverviewContentMask | 180 class ScopedTransformOverviewWindow::OverviewContentMask |
| 181 : public ui::LayerDelegate { | 181 : public ui::LayerDelegate { |
| 182 public: | 182 public: |
| 183 OverviewContentMask(int inset, int radius); | 183 explicit OverviewContentMask(float radius); |
| 184 ~OverviewContentMask() override; | 184 ~OverviewContentMask() override; |
| 185 | 185 |
| 186 ui::Layer* layer() { return &layer_; } | 186 ui::Layer* layer() { return &layer_; } |
| 187 | 187 |
| 188 // Overridden from LayerDelegate. | 188 // Overridden from LayerDelegate. |
| 189 void OnPaintLayer(const ui::PaintContext& context) override; | 189 void OnPaintLayer(const ui::PaintContext& context) override; |
| 190 void OnDelegatedFrameDamage(const gfx::Rect& damage_rect_in_dip) override {} | 190 void OnDelegatedFrameDamage(const gfx::Rect& damage_rect_in_dip) override {} |
| 191 void OnDeviceScaleFactorChanged(float device_scale_factor) override; | 191 void OnDeviceScaleFactorChanged(float device_scale_factor) override; |
| 192 base::Closure PrepareForLayerBoundsChange() override; | 192 base::Closure PrepareForLayerBoundsChange() override; |
| 193 | 193 |
| 194 private: | 194 private: |
| 195 ui::Layer layer_; | 195 ui::Layer layer_; |
| 196 int inset_; | 196 float radius_; |
| 197 int radius_; | |
| 198 | 197 |
| 199 DISALLOW_COPY_AND_ASSIGN(OverviewContentMask); | 198 DISALLOW_COPY_AND_ASSIGN(OverviewContentMask); |
| 200 }; | 199 }; |
| 201 | 200 |
| 202 ScopedTransformOverviewWindow::OverviewContentMask::OverviewContentMask( | 201 ScopedTransformOverviewWindow::OverviewContentMask::OverviewContentMask( |
| 203 int inset, | 202 float radius) |
| 204 int radius) | 203 : layer_(ui::LAYER_TEXTURED), radius_(radius) { |
| 205 : layer_(ui::LAYER_TEXTURED), inset_(inset), radius_(radius) { | |
| 206 layer_.set_delegate(this); | 204 layer_.set_delegate(this); |
| 207 } | 205 } |
| 208 | 206 |
| 209 ScopedTransformOverviewWindow::OverviewContentMask::~OverviewContentMask() { | 207 ScopedTransformOverviewWindow::OverviewContentMask::~OverviewContentMask() { |
| 210 layer_.set_delegate(nullptr); | 208 layer_.set_delegate(nullptr); |
| 211 } | 209 } |
| 212 | 210 |
| 213 void ScopedTransformOverviewWindow::OverviewContentMask::OnPaintLayer( | 211 void ScopedTransformOverviewWindow::OverviewContentMask::OnPaintLayer( |
| 214 const ui::PaintContext& context) { | 212 const ui::PaintContext& context) { |
| 215 ui::PaintRecorder recorder(context, layer()->size()); | 213 ui::PaintRecorder recorder(context, layer()->size()); |
| 216 gfx::Rect bounds(layer()->bounds().size()); | 214 gfx::Rect bounds(layer()->bounds().size()); |
| 217 bounds.Inset(0, inset_, 0, 0); | |
| 218 | 215 |
| 219 // Tile a window into an area, rounding the bottom corners. | 216 // Tile a window into an area, rounding the bottom corners. |
| 220 const SkRect rect = gfx::RectToSkRect(bounds); | 217 const SkRect rect = gfx::RectToSkRect(bounds); |
| 221 const SkScalar corner_radius_scalar = SkIntToScalar(radius_); | 218 const SkScalar corner_radius_scalar = SkIntToScalar(radius_); |
| 222 SkScalar radii[8] = {0, | 219 SkScalar radii[8] = {0, |
| 223 0, // top-left | 220 0, // top-left |
| 224 0, | 221 0, |
| 225 0, // top-right | 222 0, // top-right |
| 226 corner_radius_scalar, | 223 corner_radius_scalar, |
| 227 corner_radius_scalar, // bottom-right | 224 corner_radius_scalar, // bottom-right |
| (...skipping 25 matching lines...) Expand all Loading... |
| 253 minimized_(window->GetShowState() == ui::SHOW_STATE_MINIMIZED), | 250 minimized_(window->GetShowState() == ui::SHOW_STATE_MINIMIZED), |
| 254 ignored_by_shelf_(window->GetWindowState()->ignored_by_shelf()), | 251 ignored_by_shelf_(window->GetWindowState()->ignored_by_shelf()), |
| 255 overview_started_(false), | 252 overview_started_(false), |
| 256 original_transform_(window->GetTargetTransform()), | 253 original_transform_(window->GetTargetTransform()), |
| 257 original_opacity_(window->GetTargetOpacity()), | 254 original_opacity_(window->GetTargetOpacity()), |
| 258 weak_ptr_factory_(this) {} | 255 weak_ptr_factory_(this) {} |
| 259 | 256 |
| 260 ScopedTransformOverviewWindow::~ScopedTransformOverviewWindow() {} | 257 ScopedTransformOverviewWindow::~ScopedTransformOverviewWindow() {} |
| 261 | 258 |
| 262 void ScopedTransformOverviewWindow::RestoreWindow() { | 259 void ScopedTransformOverviewWindow::RestoreWindow() { |
| 263 if (ash::MaterialDesignController::IsOverviewMaterial()) { | |
| 264 window()->GetLayer()->SetMaskLayer(nullptr); | |
| 265 mask_.reset(); | |
| 266 } | |
| 267 | |
| 268 ScopedAnimationSettings animation_settings_list; | 260 ScopedAnimationSettings animation_settings_list; |
| 269 BeginScopedAnimation(OverviewAnimationType::OVERVIEW_ANIMATION_RESTORE_WINDOW, | 261 BeginScopedAnimation(OverviewAnimationType::OVERVIEW_ANIMATION_RESTORE_WINDOW, |
| 270 &animation_settings_list); | 262 &animation_settings_list); |
| 271 SetTransform(window()->GetRootWindow(), original_transform_, 0); | 263 SetTransform(window()->GetRootWindow(), original_transform_, 0); |
| 272 | 264 |
| 273 std::unique_ptr<ScopedOverviewAnimationSettings> animation_settings = | 265 std::unique_ptr<ScopedOverviewAnimationSettings> animation_settings = |
| 274 CreateScopedOverviewAnimationSettings( | 266 CreateScopedOverviewAnimationSettings( |
| 275 OverviewAnimationType::OVERVIEW_ANIMATION_LAY_OUT_SELECTOR_ITEMS, | 267 OverviewAnimationType::OVERVIEW_ANIMATION_LAY_OUT_SELECTOR_ITEMS, |
| 276 window_); | 268 window_); |
| 277 gfx::Transform transform; | 269 gfx::Transform transform; |
| 278 if (minimized_ && window_->GetShowState() != ui::SHOW_STATE_MINIMIZED) { | 270 if (minimized_ && window_->GetShowState() != ui::SHOW_STATE_MINIMIZED) { |
| 279 // Setting opacity 0 and visible false ensures that the property change | 271 // Setting opacity 0 and visible false ensures that the property change |
| 280 // to SHOW_STATE_MINIMIZED will not animate the window from its original | 272 // to SHOW_STATE_MINIMIZED will not animate the window from its original |
| 281 // bounds to the minimized position. | 273 // bounds to the minimized position. |
| 282 // Hiding the window needs to be done before the target opacity is 0, | 274 // Hiding the window needs to be done before the target opacity is 0, |
| 283 // otherwise the layer's visibility will not be updated | 275 // otherwise the layer's visibility will not be updated |
| 284 // (See VisibilityController::UpdateLayerVisibility). | 276 // (See VisibilityController::UpdateLayerVisibility). |
| 285 window_->Hide(); | 277 window_->Hide(); |
| 286 window_->SetOpacity(0); | 278 window_->SetOpacity(0); |
| 287 window_->SetShowState(ui::SHOW_STATE_MINIMIZED); | 279 window_->SetShowState(ui::SHOW_STATE_MINIMIZED); |
| 288 } | 280 } |
| 289 window_->GetWindowState()->set_ignored_by_shelf(ignored_by_shelf_); | 281 window_->GetWindowState()->set_ignored_by_shelf(ignored_by_shelf_); |
| 290 SetOpacity(original_opacity_); | 282 SetOpacity(original_opacity_); |
| 283 |
| 284 if (ash::MaterialDesignController::IsOverviewMaterial()) { |
| 285 ui::Layer* layer = window()->GetLayer(); |
| 286 layer->SetMaskLayer(nullptr); |
| 287 mask_.reset(); |
| 288 |
| 289 if (original_window_shape_) { |
| 290 layer->SetAlphaShape( |
| 291 base::WrapUnique(new SkRegion(*original_window_shape_.get()))); |
| 292 } else { |
| 293 layer->SetAlphaShape(nullptr); |
| 294 } |
| 295 window()->SetMasksToBounds(false); |
| 296 } |
| 291 } | 297 } |
| 292 | 298 |
| 293 void ScopedTransformOverviewWindow::BeginScopedAnimation( | 299 void ScopedTransformOverviewWindow::BeginScopedAnimation( |
| 294 OverviewAnimationType animation_type, | 300 OverviewAnimationType animation_type, |
| 295 ScopedAnimationSettings* animation_settings) { | 301 ScopedAnimationSettings* animation_settings) { |
| 296 for (auto* window : GetTransientTreeIterator(window_)) { | 302 for (auto* window : GetTransientTreeIterator(window_)) { |
| 297 animation_settings->push_back( | 303 animation_settings->push_back( |
| 298 CreateScopedOverviewAnimationSettings(animation_type, window)); | 304 CreateScopedOverviewAnimationSettings(animation_type, window)); |
| 299 } | 305 } |
| 300 } | 306 } |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 387 gfx::Transform transform; | 393 gfx::Transform transform; |
| 388 transform.Translate(dst_rect.x() - src_rect.x(), dst_rect.y() - src_rect.y()); | 394 transform.Translate(dst_rect.x() - src_rect.x(), dst_rect.y() - src_rect.y()); |
| 389 transform.Scale(static_cast<float>(dst_rect.width()) / src_rect.width(), | 395 transform.Scale(static_cast<float>(dst_rect.width()) / src_rect.width(), |
| 390 static_cast<float>(dst_rect.height()) / src_rect.height()); | 396 static_cast<float>(dst_rect.height()) / src_rect.height()); |
| 391 return transform; | 397 return transform; |
| 392 } | 398 } |
| 393 | 399 |
| 394 void ScopedTransformOverviewWindow::SetTransform( | 400 void ScopedTransformOverviewWindow::SetTransform( |
| 395 WmWindow* root_window, | 401 WmWindow* root_window, |
| 396 const gfx::Transform& transform, | 402 const gfx::Transform& transform, |
| 397 int radius) { | 403 float radius) { |
| 398 DCHECK(overview_started_); | 404 DCHECK(overview_started_); |
| 399 | 405 |
| 400 if (ash::MaterialDesignController::IsOverviewMaterial() && !mask_) { | 406 if (ash::MaterialDesignController::IsOverviewMaterial() && |
| 401 mask_.reset(new OverviewContentMask( | 407 &transform != &original_transform_) { |
| 402 window()->GetIntProperty(WmWindowProperty::TOP_VIEW_INSET), radius)); | 408 gfx::Rect bounds(GetTargetBoundsInScreen().size()); |
| 403 mask_->layer()->SetBounds(GetTargetBoundsInScreen()); | 409 mask_.reset(new OverviewContentMask(radius)); |
| 410 mask_->layer()->SetFillsBoundsOpaquely(false); |
| 411 mask_->layer()->SetBounds(bounds); |
| 404 window()->GetLayer()->SetMaskLayer(mask_->layer()); | 412 window()->GetLayer()->SetMaskLayer(mask_->layer()); |
| 413 |
| 414 SkRegion* window_shape = window()->GetLayer()->alpha_shape(); |
| 415 if (!original_window_shape_ && window_shape) |
| 416 original_window_shape_.reset(new SkRegion(*window_shape)); |
| 417 const int inset = |
| 418 window()->GetIntProperty(WmWindowProperty::TOP_VIEW_INSET); |
| 419 if (inset > 0) { |
| 420 bounds.Inset(0, inset, 0, 0); |
| 421 SkRegion* region = new SkRegion; |
| 422 region->setRect(RectToSkIRect(bounds)); |
| 423 if (original_window_shape_) |
| 424 region->op(*original_window_shape_, SkRegion::kIntersect_Op); |
| 425 window()->GetLayer()->SetAlphaShape(base::WrapUnique(region)); |
| 426 window()->SetMasksToBounds(true); |
| 427 } |
| 405 } | 428 } |
| 406 | 429 |
| 407 gfx::Point target_origin(GetTargetBoundsInScreen().origin()); | 430 gfx::Point target_origin(GetTargetBoundsInScreen().origin()); |
| 408 | 431 |
| 409 for (auto* window : GetTransientTreeIterator(window_)) { | 432 for (auto* window : GetTransientTreeIterator(window_)) { |
| 410 WmWindow* parent_window = window->GetParent(); | 433 WmWindow* parent_window = window->GetParent(); |
| 411 gfx::Point original_origin = | 434 gfx::Point original_origin = |
| 412 parent_window->ConvertRectToScreen(window->GetTargetBounds()).origin(); | 435 parent_window->ConvertRectToScreen(window->GetTargetBounds()).origin(); |
| 413 gfx::Transform new_transform = | 436 gfx::Transform new_transform = |
| 414 TransformAboutPivot(gfx::Point(target_origin.x() - original_origin.x(), | 437 TransformAboutPivot(gfx::Point(target_origin.x() - original_origin.x(), |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 448 if (parent_window) | 471 if (parent_window) |
| 449 parent_window->CloseWidget(); | 472 parent_window->CloseWidget(); |
| 450 } | 473 } |
| 451 | 474 |
| 452 // static | 475 // static |
| 453 void ScopedTransformOverviewWindow::SetImmediateCloseForTests() { | 476 void ScopedTransformOverviewWindow::SetImmediateCloseForTests() { |
| 454 immediate_close_for_tests = true; | 477 immediate_close_for_tests = true; |
| 455 } | 478 } |
| 456 | 479 |
| 457 } // namespace ash | 480 } // namespace ash |
| OLD | NEW |