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

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

Issue 2129213003: [ash-md] Hides frame headers in overview mode not using a mask (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: [ash-md] Hides frame headers in overview mode not using a mask (using SetAlphaShape) Created 4 years, 5 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
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/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
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 OverviewContentMask(float radius);
tdanderson 2016/07/09 21:23:21 Make this constructor explicit
varkha 2016/07/09 22:00:17 Done.
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 15 matching lines...) Expand all
243 // Redrawing will take care of scale factor change. 240 // Redrawing will take care of scale factor change.
244 } 241 }
245 242
246 base::Closure ScopedTransformOverviewWindow::OverviewContentMask:: 243 base::Closure ScopedTransformOverviewWindow::OverviewContentMask::
247 PrepareForLayerBoundsChange() { 244 PrepareForLayerBoundsChange() {
248 return base::Closure(); 245 return base::Closure();
249 } 246 }
250 247
251 ScopedTransformOverviewWindow::ScopedTransformOverviewWindow(WmWindow* window) 248 ScopedTransformOverviewWindow::ScopedTransformOverviewWindow(WmWindow* window)
252 : window_(window), 249 : window_(window),
250 alpha_shape_set_(false),
253 minimized_(window->GetShowState() == ui::SHOW_STATE_MINIMIZED), 251 minimized_(window->GetShowState() == ui::SHOW_STATE_MINIMIZED),
254 ignored_by_shelf_(window->GetWindowState()->ignored_by_shelf()), 252 ignored_by_shelf_(window->GetWindowState()->ignored_by_shelf()),
255 overview_started_(false), 253 overview_started_(false),
256 original_transform_(window->GetTargetTransform()), 254 original_transform_(window->GetTargetTransform()),
257 original_opacity_(window->GetTargetOpacity()), 255 original_opacity_(window->GetTargetOpacity()),
258 weak_ptr_factory_(this) {} 256 weak_ptr_factory_(this) {}
259 257
260 ScopedTransformOverviewWindow::~ScopedTransformOverviewWindow() {} 258 ScopedTransformOverviewWindow::~ScopedTransformOverviewWindow() {}
261 259
262 void ScopedTransformOverviewWindow::RestoreWindow() { 260 void ScopedTransformOverviewWindow::RestoreWindow() {
263 if (ash::MaterialDesignController::IsOverviewMaterial()) {
264 window()->GetLayer()->SetMaskLayer(nullptr);
265 mask_.reset();
266 }
267
268 ScopedAnimationSettings animation_settings_list; 261 ScopedAnimationSettings animation_settings_list;
269 BeginScopedAnimation(OverviewAnimationType::OVERVIEW_ANIMATION_RESTORE_WINDOW, 262 BeginScopedAnimation(OverviewAnimationType::OVERVIEW_ANIMATION_RESTORE_WINDOW,
270 &animation_settings_list); 263 &animation_settings_list);
271 SetTransform(window()->GetRootWindow(), original_transform_, 0); 264 SetTransform(window()->GetRootWindow(), original_transform_, 0);
272 265
273 std::unique_ptr<ScopedOverviewAnimationSettings> animation_settings = 266 std::unique_ptr<ScopedOverviewAnimationSettings> animation_settings =
274 CreateScopedOverviewAnimationSettings( 267 CreateScopedOverviewAnimationSettings(
275 OverviewAnimationType::OVERVIEW_ANIMATION_LAY_OUT_SELECTOR_ITEMS, 268 OverviewAnimationType::OVERVIEW_ANIMATION_LAY_OUT_SELECTOR_ITEMS,
276 window_); 269 window_);
277 gfx::Transform transform; 270 gfx::Transform transform;
278 if (minimized_ && window_->GetShowState() != ui::SHOW_STATE_MINIMIZED) { 271 if (minimized_ && window_->GetShowState() != ui::SHOW_STATE_MINIMIZED) {
279 // Setting opacity 0 and visible false ensures that the property change 272 // Setting opacity 0 and visible false ensures that the property change
280 // to SHOW_STATE_MINIMIZED will not animate the window from its original 273 // to SHOW_STATE_MINIMIZED will not animate the window from its original
281 // bounds to the minimized position. 274 // bounds to the minimized position.
282 // Hiding the window needs to be done before the target opacity is 0, 275 // Hiding the window needs to be done before the target opacity is 0,
283 // otherwise the layer's visibility will not be updated 276 // otherwise the layer's visibility will not be updated
284 // (See VisibilityController::UpdateLayerVisibility). 277 // (See VisibilityController::UpdateLayerVisibility).
285 window_->Hide(); 278 window_->Hide();
286 window_->SetOpacity(0); 279 window_->SetOpacity(0);
287 window_->SetShowState(ui::SHOW_STATE_MINIMIZED); 280 window_->SetShowState(ui::SHOW_STATE_MINIMIZED);
288 } 281 }
289 window_->GetWindowState()->set_ignored_by_shelf(ignored_by_shelf_); 282 window_->GetWindowState()->set_ignored_by_shelf(ignored_by_shelf_);
290 SetOpacity(original_opacity_); 283 SetOpacity(original_opacity_);
284
285 if (ash::MaterialDesignController::IsOverviewMaterial()) {
286 ui::Layer* layer = window()->GetLayer();
287 layer->SetMaskLayer(nullptr);
288 mask_.reset();
289
290 if (original_alpha_shape_) {
291 layer->SetAlphaShape(
292 base::WrapUnique(new SkRegion(*original_alpha_shape_.get())));
293 } else {
294 layer->SetAlphaShape(nullptr);
295 }
296 window()->SetMasksToBounds(false);
297 alpha_shape_set_ = false;
298 }
291 } 299 }
292 300
293 void ScopedTransformOverviewWindow::BeginScopedAnimation( 301 void ScopedTransformOverviewWindow::BeginScopedAnimation(
294 OverviewAnimationType animation_type, 302 OverviewAnimationType animation_type,
295 ScopedAnimationSettings* animation_settings) { 303 ScopedAnimationSettings* animation_settings) {
296 for (auto* window : GetTransientTreeIterator(window_)) { 304 for (auto* window : GetTransientTreeIterator(window_)) {
297 animation_settings->push_back( 305 animation_settings->push_back(
298 CreateScopedOverviewAnimationSettings(animation_type, window)); 306 CreateScopedOverviewAnimationSettings(animation_type, window));
299 } 307 }
300 } 308 }
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 gfx::Transform transform; 395 gfx::Transform transform;
388 transform.Translate(dst_rect.x() - src_rect.x(), dst_rect.y() - src_rect.y()); 396 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(), 397 transform.Scale(static_cast<float>(dst_rect.width()) / src_rect.width(),
390 static_cast<float>(dst_rect.height()) / src_rect.height()); 398 static_cast<float>(dst_rect.height()) / src_rect.height());
391 return transform; 399 return transform;
392 } 400 }
393 401
394 void ScopedTransformOverviewWindow::SetTransform( 402 void ScopedTransformOverviewWindow::SetTransform(
395 WmWindow* root_window, 403 WmWindow* root_window,
396 const gfx::Transform& transform, 404 const gfx::Transform& transform,
397 int radius) { 405 float radius) {
398 DCHECK(overview_started_); 406 DCHECK(overview_started_);
399 407
400 if (ash::MaterialDesignController::IsOverviewMaterial() && !mask_) { 408 if (ash::MaterialDesignController::IsOverviewMaterial() &&
401 mask_.reset(new OverviewContentMask( 409 &transform != &original_transform_) {
tdanderson 2016/07/09 21:23:21 Hmm, shouldn't all of SetTransform() be a no-op i
varkha 2016/07/09 22:00:17 No. This method is used to both set the transform
402 window()->GetIntProperty(WmWindowProperty::TOP_VIEW_INSET), radius)); 410 gfx::Rect bounds(GetTargetBoundsInScreen().size());
403 mask_->layer()->SetBounds(GetTargetBoundsInScreen()); 411 mask_.reset(new OverviewContentMask(radius));
412 mask_->layer()->SetBounds(bounds);
tdanderson 2016/07/09 21:23:21 I don't understand why you're setting bounds with
varkha 2016/07/09 22:00:17 This is for a mask layer - my understanding is tha
404 window()->GetLayer()->SetMaskLayer(mask_->layer()); 413 window()->GetLayer()->SetMaskLayer(mask_->layer());
414
415 if (!alpha_shape_set_) {
tdanderson 2016/07/09 21:23:21 I don't think you need |alpha_shape_set_| at all.
varkha 2016/07/09 22:00:17 Done.
416 if (window()->GetLayer()->alpha_shape())
tdanderson 2016/07/09 21:23:21 {} since call to reset() spans two lines
varkha 2016/07/09 22:00:17 Done.
417 original_alpha_shape_.reset(
418 new SkRegion(*window()->GetLayer()->alpha_shape()));
419 window()->SetMasksToBounds(true);
420 alpha_shape_set_ = true;
421 }
422 bounds.Inset(0, window()->GetIntProperty(WmWindowProperty::TOP_VIEW_INSET),
423 0, 0);
424 SkRegion* region = new SkRegion;
425 region->setRect(RectToSkIRect(bounds));
426 if (original_alpha_shape_)
427 region->op(*original_alpha_shape_, SkRegion::kIntersect_Op);
428 window()->GetLayer()->SetAlphaShape(base::WrapUnique(region));
varkha 2016/07/09 21:07:32 Self review: this could be done only for windows t
varkha 2016/07/09 22:00:17 Done.
405 } 429 }
406 430
407 gfx::Point target_origin(GetTargetBoundsInScreen().origin()); 431 gfx::Point target_origin(GetTargetBoundsInScreen().origin());
408 432
409 for (auto* window : GetTransientTreeIterator(window_)) { 433 for (auto* window : GetTransientTreeIterator(window_)) {
410 WmWindow* parent_window = window->GetParent(); 434 WmWindow* parent_window = window->GetParent();
411 gfx::Point original_origin = 435 gfx::Point original_origin =
412 parent_window->ConvertRectToScreen(window->GetTargetBounds()).origin(); 436 parent_window->ConvertRectToScreen(window->GetTargetBounds()).origin();
413 gfx::Transform new_transform = 437 gfx::Transform new_transform =
414 TransformAboutPivot(gfx::Point(target_origin.x() - original_origin.x(), 438 TransformAboutPivot(gfx::Point(target_origin.x() - original_origin.x(),
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
448 if (parent_window) 472 if (parent_window)
449 parent_window->CloseWidget(); 473 parent_window->CloseWidget();
450 } 474 }
451 475
452 // static 476 // static
453 void ScopedTransformOverviewWindow::SetImmediateCloseForTests() { 477 void ScopedTransformOverviewWindow::SetImmediateCloseForTests() {
454 immediate_close_for_tests = true; 478 immediate_close_for_tests = true;
455 } 479 }
456 480
457 } // namespace ash 481 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698