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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 original_transform_(window->GetTargetTransform()), | 263 original_transform_(window->GetTargetTransform()), |
262 original_opacity_(window->GetTargetOpacity()), | 264 original_opacity_(window->GetTargetOpacity()), |
263 weak_ptr_factory_(this) {} | 265 weak_ptr_factory_(this) {} |
264 | 266 |
265 ScopedTransformOverviewWindow::~ScopedTransformOverviewWindow() {} | 267 ScopedTransformOverviewWindow::~ScopedTransformOverviewWindow() {} |
266 | 268 |
267 void ScopedTransformOverviewWindow::RestoreWindow() { | 269 void ScopedTransformOverviewWindow::RestoreWindow() { |
268 ScopedAnimationSettings animation_settings_list; | 270 ScopedAnimationSettings animation_settings_list; |
269 BeginScopedAnimation(OverviewAnimationType::OVERVIEW_ANIMATION_RESTORE_WINDOW, | 271 BeginScopedAnimation(OverviewAnimationType::OVERVIEW_ANIMATION_RESTORE_WINDOW, |
270 &animation_settings_list); | 272 &animation_settings_list); |
271 SetTransform(window()->GetRootWindow(), original_transform_, 0); | 273 SetTransform(window()->GetRootWindow(), original_transform_, |
| 274 false /* use_mask */, false /* use_shape */, 0); |
272 | 275 |
273 std::unique_ptr<ScopedOverviewAnimationSettings> animation_settings = | 276 std::unique_ptr<ScopedOverviewAnimationSettings> animation_settings = |
274 CreateScopedOverviewAnimationSettings( | 277 CreateScopedOverviewAnimationSettings( |
275 OverviewAnimationType::OVERVIEW_ANIMATION_LAY_OUT_SELECTOR_ITEMS, | 278 OverviewAnimationType::OVERVIEW_ANIMATION_LAY_OUT_SELECTOR_ITEMS, |
276 window_); | 279 window_); |
277 gfx::Transform transform; | 280 gfx::Transform transform; |
278 if ((original_visibility_ == ORIGINALLY_MINIMIZED && | 281 if ((original_visibility_ == ORIGINALLY_MINIMIZED && |
279 window_->GetShowState() != ui::SHOW_STATE_MINIMIZED) || | 282 window_->GetShowState() != ui::SHOW_STATE_MINIMIZED) || |
280 (original_visibility_ == ORIGINALLY_DOCKED_MINIMIZED && | 283 (original_visibility_ == ORIGINALLY_DOCKED_MINIMIZED && |
281 window_->GetWindowState()->GetStateType() != | 284 window_->GetWindowState()->GetStateType() != |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
410 gfx::Transform transform; | 413 gfx::Transform transform; |
411 transform.Translate(dst_rect.x() - src_rect.x(), dst_rect.y() - src_rect.y()); | 414 transform.Translate(dst_rect.x() - src_rect.x(), dst_rect.y() - src_rect.y()); |
412 transform.Scale(static_cast<float>(dst_rect.width()) / src_rect.width(), | 415 transform.Scale(static_cast<float>(dst_rect.width()) / src_rect.width(), |
413 static_cast<float>(dst_rect.height()) / src_rect.height()); | 416 static_cast<float>(dst_rect.height()) / src_rect.height()); |
414 return transform; | 417 return transform; |
415 } | 418 } |
416 | 419 |
417 void ScopedTransformOverviewWindow::SetTransform( | 420 void ScopedTransformOverviewWindow::SetTransform( |
418 WmWindow* root_window, | 421 WmWindow* root_window, |
419 const gfx::Transform& transform, | 422 const gfx::Transform& transform, |
| 423 bool use_mask, |
| 424 bool use_shape, |
420 float radius) { | 425 float radius) { |
421 DCHECK(overview_started_); | 426 DCHECK(overview_started_); |
422 | 427 |
423 if (ash::MaterialDesignController::IsOverviewMaterial() && | 428 if (ash::MaterialDesignController::IsOverviewMaterial() && |
424 &transform != &original_transform_) { | 429 &transform != &original_transform_) { |
425 if (!mask_) { | 430 if (use_mask && !mask_) { |
426 mask_.reset(new OverviewContentMask(radius)); | 431 mask_.reset(new OverviewContentMask()); |
427 mask_->layer()->SetFillsBoundsOpaquely(false); | 432 mask_->layer()->SetFillsBoundsOpaquely(false); |
428 window()->GetLayer()->SetMaskLayer(mask_->layer()); | 433 window()->GetLayer()->SetMaskLayer(mask_->layer()); |
429 } | 434 } |
430 gfx::Rect bounds(GetTargetBoundsInScreen().size()); | |
431 mask_->layer()->SetBounds(bounds); | |
432 mask_->set_radius(radius); | |
433 window()->GetLayer()->SchedulePaint(bounds); | |
434 | |
435 if (!determined_original_window_shape_) { | 435 if (!determined_original_window_shape_) { |
436 determined_original_window_shape_ = true; | 436 determined_original_window_shape_ = true; |
437 SkRegion* window_shape = window()->GetLayer()->alpha_shape(); | 437 SkRegion* window_shape = window()->GetLayer()->alpha_shape(); |
438 if (!original_window_shape_ && window_shape) | 438 if (!original_window_shape_ && window_shape) |
439 original_window_shape_.reset(new SkRegion(*window_shape)); | 439 original_window_shape_.reset(new SkRegion(*window_shape)); |
440 } | 440 } |
| 441 gfx::Rect bounds(GetTargetBoundsInScreen().size()); |
441 const int inset = | 442 const int inset = |
442 window()->GetIntProperty(WmWindowProperty::TOP_VIEW_INSET); | 443 (use_mask || use_shape) |
443 if (inset > 0) { | 444 ? window()->GetIntProperty(WmWindowProperty::TOP_VIEW_INSET) |
| 445 : 0; |
| 446 if (mask_) { |
| 447 // Mask layer is used both to hide the window header and to use rounded |
| 448 // corners. Its layout needs to be update when setting a transform. |
| 449 mask_->layer()->SetBounds(bounds); |
| 450 mask_->set_inset(inset); |
| 451 mask_->set_radius(radius); |
| 452 window()->GetLayer()->SchedulePaint(bounds); |
| 453 } else if (inset > 0) { |
| 454 // Alpha shape is only used to to hide the window header and only when |
| 455 // not using a mask layer. |
444 bounds.Inset(0, inset, 0, 0); | 456 bounds.Inset(0, inset, 0, 0); |
445 SkRegion* region = new SkRegion; | 457 SkRegion* region = new SkRegion; |
446 region->setRect(RectToSkIRect(bounds)); | 458 region->setRect(RectToSkIRect(bounds)); |
447 if (original_window_shape_) | 459 if (original_window_shape_) |
448 region->op(*original_window_shape_, SkRegion::kIntersect_Op); | 460 region->op(*original_window_shape_, SkRegion::kIntersect_Op); |
449 window()->GetLayer()->SetAlphaShape(base::WrapUnique(region)); | 461 window()->GetLayer()->SetAlphaShape(base::WrapUnique(region)); |
450 window()->SetMasksToBounds(true); | 462 window()->SetMasksToBounds(true); |
451 } | 463 } |
452 } | 464 } |
453 | 465 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
495 if (parent_window) | 507 if (parent_window) |
496 parent_window->CloseWidget(); | 508 parent_window->CloseWidget(); |
497 } | 509 } |
498 | 510 |
499 // static | 511 // static |
500 void ScopedTransformOverviewWindow::SetImmediateCloseForTests() { | 512 void ScopedTransformOverviewWindow::SetImmediateCloseForTests() { |
501 immediate_close_for_tests = true; | 513 immediate_close_for_tests = true; |
502 } | 514 } |
503 | 515 |
504 } // namespace ash | 516 } // namespace ash |
OLD | NEW |