| 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 explicit OverviewContentMask(float radius); | 183 explicit OverviewContentMask(); |
| 184 ~OverviewContentMask() override; | 184 ~OverviewContentMask() override; |
| 185 | 185 |
| 186 void set_radius(float radius) { radius_ = radius; } | 186 void set_radius(float radius) { radius_ = radius; } |
| 187 void set_inset(int inset) { inset_ = inset; } |
| 187 ui::Layer* layer() { return &layer_; } | 188 ui::Layer* layer() { return &layer_; } |
| 188 | 189 |
| 189 // Overridden from LayerDelegate. | 190 // Overridden from LayerDelegate. |
| 190 void OnPaintLayer(const ui::PaintContext& context) override; | 191 void OnPaintLayer(const ui::PaintContext& context) override; |
| 191 void OnDelegatedFrameDamage(const gfx::Rect& damage_rect_in_dip) override {} | 192 void OnDelegatedFrameDamage(const gfx::Rect& damage_rect_in_dip) override {} |
| 192 void OnDeviceScaleFactorChanged(float device_scale_factor) override; | 193 void OnDeviceScaleFactorChanged(float device_scale_factor) override; |
| 193 base::Closure PrepareForLayerBoundsChange() override; | 194 base::Closure PrepareForLayerBoundsChange() override; |
| 194 | 195 |
| 195 private: | 196 private: |
| 196 ui::Layer layer_; | 197 ui::Layer layer_; |
| 197 float radius_; | 198 float radius_; |
| 199 int inset_; |
| 198 | 200 |
| 199 DISALLOW_COPY_AND_ASSIGN(OverviewContentMask); | 201 DISALLOW_COPY_AND_ASSIGN(OverviewContentMask); |
| 200 }; | 202 }; |
| 201 | 203 |
| 202 ScopedTransformOverviewWindow::OverviewContentMask::OverviewContentMask( | 204 ScopedTransformOverviewWindow::OverviewContentMask::OverviewContentMask() |
| 203 float radius) | 205 : layer_(ui::LAYER_TEXTURED), radius_(0), inset_(0) { |
| 204 : layer_(ui::LAYER_TEXTURED), radius_(radius) { | |
| 205 layer_.set_delegate(this); | 206 layer_.set_delegate(this); |
| 206 } | 207 } |
| 207 | 208 |
| 208 ScopedTransformOverviewWindow::OverviewContentMask::~OverviewContentMask() { | 209 ScopedTransformOverviewWindow::OverviewContentMask::~OverviewContentMask() { |
| 209 layer_.set_delegate(nullptr); | 210 layer_.set_delegate(nullptr); |
| 210 } | 211 } |
| 211 | 212 |
| 212 void ScopedTransformOverviewWindow::OverviewContentMask::OnPaintLayer( | 213 void ScopedTransformOverviewWindow::OverviewContentMask::OnPaintLayer( |
| 213 const ui::PaintContext& context) { | 214 const ui::PaintContext& context) { |
| 214 ui::PaintRecorder recorder(context, layer()->size()); | 215 ui::PaintRecorder recorder(context, layer()->size()); |
| 215 gfx::Rect bounds(layer()->bounds().size()); | 216 gfx::Rect bounds(layer()->bounds().size()); |
| 217 bounds.Inset(0, inset_, 0, 0); |
| 216 | 218 |
| 217 // Tile a window into an area, rounding the bottom corners. | 219 // Tile a window into an area, rounding the bottom corners. |
| 218 const SkRect rect = gfx::RectToSkRect(bounds); | 220 const SkRect rect = gfx::RectToSkRect(bounds); |
| 219 const SkScalar corner_radius_scalar = SkIntToScalar(radius_); | 221 const SkScalar corner_radius_scalar = SkIntToScalar(radius_); |
| 220 SkScalar radii[8] = {0, | 222 SkScalar radii[8] = {0, |
| 221 0, // top-left | 223 0, // top-left |
| 222 0, | 224 0, |
| 223 0, // top-right | 225 0, // top-right |
| 224 corner_radius_scalar, | 226 corner_radius_scalar, |
| 225 corner_radius_scalar, // bottom-right | 227 corner_radius_scalar, // bottom-right |
| (...skipping 29 matching lines...) Expand all Loading... |
| 255 original_transform_(window->GetTargetTransform()), | 257 original_transform_(window->GetTargetTransform()), |
| 256 original_opacity_(window->GetTargetOpacity()), | 258 original_opacity_(window->GetTargetOpacity()), |
| 257 weak_ptr_factory_(this) {} | 259 weak_ptr_factory_(this) {} |
| 258 | 260 |
| 259 ScopedTransformOverviewWindow::~ScopedTransformOverviewWindow() {} | 261 ScopedTransformOverviewWindow::~ScopedTransformOverviewWindow() {} |
| 260 | 262 |
| 261 void ScopedTransformOverviewWindow::RestoreWindow() { | 263 void ScopedTransformOverviewWindow::RestoreWindow() { |
| 262 ScopedAnimationSettings animation_settings_list; | 264 ScopedAnimationSettings animation_settings_list; |
| 263 BeginScopedAnimation(OverviewAnimationType::OVERVIEW_ANIMATION_RESTORE_WINDOW, | 265 BeginScopedAnimation(OverviewAnimationType::OVERVIEW_ANIMATION_RESTORE_WINDOW, |
| 264 &animation_settings_list); | 266 &animation_settings_list); |
| 265 SetTransform(window()->GetRootWindow(), original_transform_, 0); | 267 SetTransform(window()->GetRootWindow(), original_transform_, |
| 268 false /* use_mask */, false /* use_shape */, 0); |
| 266 | 269 |
| 267 std::unique_ptr<ScopedOverviewAnimationSettings> animation_settings = | 270 std::unique_ptr<ScopedOverviewAnimationSettings> animation_settings = |
| 268 CreateScopedOverviewAnimationSettings( | 271 CreateScopedOverviewAnimationSettings( |
| 269 OverviewAnimationType::OVERVIEW_ANIMATION_LAY_OUT_SELECTOR_ITEMS, | 272 OverviewAnimationType::OVERVIEW_ANIMATION_LAY_OUT_SELECTOR_ITEMS, |
| 270 window_); | 273 window_); |
| 271 gfx::Transform transform; | 274 gfx::Transform transform; |
| 272 if (minimized_ && window_->GetShowState() != ui::SHOW_STATE_MINIMIZED) { | 275 if (minimized_ && window_->GetShowState() != ui::SHOW_STATE_MINIMIZED) { |
| 273 // Setting opacity 0 and visible false ensures that the property change | 276 // Setting opacity 0 and visible false ensures that the property change |
| 274 // to SHOW_STATE_MINIMIZED will not animate the window from its original | 277 // to SHOW_STATE_MINIMIZED will not animate the window from its original |
| 275 // bounds to the minimized position. | 278 // bounds to the minimized position. |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 395 gfx::Transform transform; | 398 gfx::Transform transform; |
| 396 transform.Translate(dst_rect.x() - src_rect.x(), dst_rect.y() - src_rect.y()); | 399 transform.Translate(dst_rect.x() - src_rect.x(), dst_rect.y() - src_rect.y()); |
| 397 transform.Scale(static_cast<float>(dst_rect.width()) / src_rect.width(), | 400 transform.Scale(static_cast<float>(dst_rect.width()) / src_rect.width(), |
| 398 static_cast<float>(dst_rect.height()) / src_rect.height()); | 401 static_cast<float>(dst_rect.height()) / src_rect.height()); |
| 399 return transform; | 402 return transform; |
| 400 } | 403 } |
| 401 | 404 |
| 402 void ScopedTransformOverviewWindow::SetTransform( | 405 void ScopedTransformOverviewWindow::SetTransform( |
| 403 WmWindow* root_window, | 406 WmWindow* root_window, |
| 404 const gfx::Transform& transform, | 407 const gfx::Transform& transform, |
| 408 bool use_mask, |
| 409 bool use_shape, |
| 405 float radius) { | 410 float radius) { |
| 406 DCHECK(overview_started_); | 411 DCHECK(overview_started_); |
| 407 | 412 |
| 408 if (ash::MaterialDesignController::IsOverviewMaterial() && | 413 if (ash::MaterialDesignController::IsOverviewMaterial() && |
| 409 &transform != &original_transform_) { | 414 &transform != &original_transform_) { |
| 410 if (!mask_) { | 415 if (use_mask && !mask_) { |
| 411 mask_.reset(new OverviewContentMask(radius)); | 416 mask_.reset(new OverviewContentMask()); |
| 412 mask_->layer()->SetFillsBoundsOpaquely(false); | 417 mask_->layer()->SetFillsBoundsOpaquely(false); |
| 413 window()->GetLayer()->SetMaskLayer(mask_->layer()); | 418 window()->GetLayer()->SetMaskLayer(mask_->layer()); |
| 414 } | 419 } |
| 415 gfx::Rect bounds(GetTargetBoundsInScreen().size()); | |
| 416 mask_->layer()->SetBounds(bounds); | |
| 417 mask_->set_radius(radius); | |
| 418 window()->GetLayer()->SchedulePaint(bounds); | |
| 419 | |
| 420 if (!determined_original_window_shape_) { | 420 if (!determined_original_window_shape_) { |
| 421 determined_original_window_shape_ = true; | 421 determined_original_window_shape_ = true; |
| 422 SkRegion* window_shape = window()->GetLayer()->alpha_shape(); | 422 SkRegion* window_shape = window()->GetLayer()->alpha_shape(); |
| 423 if (!original_window_shape_ && window_shape) | 423 if (!original_window_shape_ && window_shape) |
| 424 original_window_shape_.reset(new SkRegion(*window_shape)); | 424 original_window_shape_.reset(new SkRegion(*window_shape)); |
| 425 } | 425 } |
| 426 gfx::Rect bounds(GetTargetBoundsInScreen().size()); |
| 426 const int inset = | 427 const int inset = |
| 427 window()->GetIntProperty(WmWindowProperty::TOP_VIEW_INSET); | 428 (use_mask || use_shape) |
| 428 if (inset > 0) { | 429 ? window()->GetIntProperty(WmWindowProperty::TOP_VIEW_INSET) |
| 430 : 0; |
| 431 if (mask_) { |
| 432 // Mask layer is used both to hide the window header and to use rounded |
| 433 // corners. Its layout needs to be update when setting a transform. |
| 434 mask_->layer()->SetBounds(bounds); |
| 435 mask_->set_inset(inset); |
| 436 mask_->set_radius(radius); |
| 437 window()->GetLayer()->SchedulePaint(bounds); |
| 438 } else if (inset > 0) { |
| 439 // Alpha shape is only used to to hide the window header and only when |
| 440 // not using a mask layer. |
| 429 bounds.Inset(0, inset, 0, 0); | 441 bounds.Inset(0, inset, 0, 0); |
| 430 SkRegion* region = new SkRegion; | 442 SkRegion* region = new SkRegion; |
| 431 region->setRect(RectToSkIRect(bounds)); | 443 region->setRect(RectToSkIRect(bounds)); |
| 432 if (original_window_shape_) | 444 if (original_window_shape_) |
| 433 region->op(*original_window_shape_, SkRegion::kIntersect_Op); | 445 region->op(*original_window_shape_, SkRegion::kIntersect_Op); |
| 434 window()->GetLayer()->SetAlphaShape(base::WrapUnique(region)); | 446 window()->GetLayer()->SetAlphaShape(base::WrapUnique(region)); |
| 435 window()->SetMasksToBounds(true); | 447 window()->SetMasksToBounds(true); |
| 436 } | 448 } |
| 437 } | 449 } |
| 438 | 450 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 480 if (parent_window) | 492 if (parent_window) |
| 481 parent_window->CloseWidget(); | 493 parent_window->CloseWidget(); |
| 482 } | 494 } |
| 483 | 495 |
| 484 // static | 496 // static |
| 485 void ScopedTransformOverviewWindow::SetImmediateCloseForTests() { | 497 void ScopedTransformOverviewWindow::SetImmediateCloseForTests() { |
| 486 immediate_close_for_tests = true; | 498 immediate_close_for_tests = true; |
| 487 } | 499 } |
| 488 | 500 |
| 489 } // namespace ash | 501 } // namespace ash |
| OLD | NEW |