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

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

Issue 2239233002: [ash-md] Fades overview header in and out (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: [ash-md] Fades overview header in and out (rebase) Created 4 years, 3 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 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 original_opacity_(window->GetTargetOpacity()), 264 original_opacity_(window->GetTargetOpacity()),
265 weak_ptr_factory_(this) {} 265 weak_ptr_factory_(this) {}
266 266
267 ScopedTransformOverviewWindow::~ScopedTransformOverviewWindow() {} 267 ScopedTransformOverviewWindow::~ScopedTransformOverviewWindow() {}
268 268
269 void ScopedTransformOverviewWindow::RestoreWindow() { 269 void ScopedTransformOverviewWindow::RestoreWindow() {
270 ScopedAnimationSettings animation_settings_list; 270 ScopedAnimationSettings animation_settings_list;
271 BeginScopedAnimation(OverviewAnimationType::OVERVIEW_ANIMATION_RESTORE_WINDOW, 271 BeginScopedAnimation(OverviewAnimationType::OVERVIEW_ANIMATION_RESTORE_WINDOW,
272 &animation_settings_list); 272 &animation_settings_list);
273 SetTransform(window()->GetRootWindow(), original_transform_, 273 SetTransform(window()->GetRootWindow(), original_transform_,
274 false /* use_mask */, false /* use_shape */, 0); 274 false /* use_mask */);
275 set_overview_transform(original_transform_);
275 276
276 std::unique_ptr<ScopedOverviewAnimationSettings> animation_settings = 277 std::unique_ptr<ScopedOverviewAnimationSettings> animation_settings =
277 CreateScopedOverviewAnimationSettings( 278 CreateScopedOverviewAnimationSettings(
278 OverviewAnimationType::OVERVIEW_ANIMATION_LAY_OUT_SELECTOR_ITEMS, 279 OverviewAnimationType::OVERVIEW_ANIMATION_LAY_OUT_SELECTOR_ITEMS,
279 window_); 280 window_);
280 gfx::Transform transform; 281 gfx::Transform transform;
281 if ((original_visibility_ == ORIGINALLY_MINIMIZED && 282 if ((original_visibility_ == ORIGINALLY_MINIMIZED &&
282 window_->GetShowState() != ui::SHOW_STATE_MINIMIZED) || 283 window_->GetShowState() != ui::SHOW_STATE_MINIMIZED) ||
283 (original_visibility_ == ORIGINALLY_DOCKED_MINIMIZED && 284 (original_visibility_ == ORIGINALLY_DOCKED_MINIMIZED &&
284 window_->GetWindowState()->GetStateType() != 285 window_->GetWindowState()->GetStateType() !=
285 wm::WINDOW_STATE_TYPE_DOCKED_MINIMIZED)) { 286 wm::WINDOW_STATE_TYPE_DOCKED_MINIMIZED)) {
286 // Setting opacity 0 and visible false ensures that the property change 287 // Setting opacity 0 and visible false ensures that the property change
287 // to SHOW_STATE_MINIMIZED will not animate the window from its original 288 // to SHOW_STATE_MINIMIZED will not animate the window from its original
288 // bounds to the minimized position. 289 // bounds to the minimized position.
289 // Hiding the window needs to be done before the target opacity is 0, 290 // Hiding the window needs to be done before the target opacity is 0,
290 // otherwise the layer's visibility will not be updated 291 // otherwise the layer's visibility will not be updated
291 // (See VisibilityController::UpdateLayerVisibility). 292 // (See VisibilityController::UpdateLayerVisibility).
292 window_->Hide(); 293 window_->Hide();
293 window_->SetOpacity(0); 294 window_->SetOpacity(0);
294 window_->SetShowState(ui::SHOW_STATE_MINIMIZED); 295 window_->SetShowState(ui::SHOW_STATE_MINIMIZED);
295 } 296 }
296 window_->GetWindowState()->set_ignored_by_shelf(ignored_by_shelf_); 297 window_->GetWindowState()->set_ignored_by_shelf(ignored_by_shelf_);
297 SetOpacity(original_opacity_); 298 SetOpacity(original_opacity_);
298 299
299 if (ash::MaterialDesignController::IsOverviewMaterial()) { 300 if (ash::MaterialDesignController::IsOverviewMaterial())
300 ui::Layer* layer = window()->GetLayer(); 301 ShowHeaderAndResetShape();
bruthig 2016/09/02 16:00:12 AFAICT it is not guaranteed that HideHeaderAndSetS
varkha 2016/09/08 00:09:50 Done. Added a comment in the header since I think
301 layer->SetMaskLayer(nullptr);
302 mask_.reset();
303
304 if (original_window_shape_) {
305 layer->SetAlphaShape(
306 base::MakeUnique<SkRegion>(*original_window_shape_.get()));
307 } else {
308 layer->SetAlphaShape(nullptr);
309 }
310 window()->SetMasksToBounds(false);
311 }
312 } 302 }
313 303
314 void ScopedTransformOverviewWindow::BeginScopedAnimation( 304 void ScopedTransformOverviewWindow::BeginScopedAnimation(
315 OverviewAnimationType animation_type, 305 OverviewAnimationType animation_type,
316 ScopedAnimationSettings* animation_settings) { 306 ScopedAnimationSettings* animation_settings) {
317 for (auto* window : GetTransientTreeIterator(window_)) { 307 for (auto* window : GetTransientTreeIterator(window_)) {
318 animation_settings->push_back( 308 animation_settings->push_back(
319 CreateScopedOverviewAnimationSettings(animation_type, window)); 309 CreateScopedOverviewAnimationSettings(animation_type, window));
320 } 310 }
321 } 311 }
(...skipping 16 matching lines...) Expand all
338 continue; 328 continue;
339 } 329 }
340 bounds.Union( 330 bounds.Union(
341 window->GetParent()->ConvertRectToScreen(window->GetTargetBounds())); 331 window->GetParent()->ConvertRectToScreen(window->GetTargetBounds()));
342 } 332 }
343 return bounds; 333 return bounds;
344 } 334 }
345 335
346 gfx::Rect ScopedTransformOverviewWindow::GetTransformedBounds( 336 gfx::Rect ScopedTransformOverviewWindow::GetTransformedBounds(
347 bool hide_header) const { 337 bool hide_header) const {
338 if (window_->GetWindowState()->IsMinimized())
339 return window_->GetMinimizeAnimationTargetBoundsInScreen();
340
348 const bool material = ash::MaterialDesignController::IsOverviewMaterial(); 341 const bool material = ash::MaterialDesignController::IsOverviewMaterial();
349 const int top_inset = hide_header ? GetTopInset() : 0; 342 const int top_inset = hide_header ? GetTopInset() : 0;
350 gfx::Rect bounds; 343 gfx::Rect bounds;
351 for (auto* window : GetTransientTreeIterator(window_)) { 344 for (auto* window : GetTransientTreeIterator(window_)) {
352 // Ignore other window types when computing bounding box of window 345 // Ignore other window types when computing bounding box of window
353 // selector target item. 346 // selector target item.
354 if (window != window_ && 347 if (window != window_ &&
355 (!material || (window->GetType() != ui::wm::WINDOW_TYPE_NORMAL && 348 (!material || (window->GetType() != ui::wm::WINDOW_TYPE_NORMAL &&
356 window->GetType() != ui::wm::WINDOW_TYPE_PANEL))) { 349 window->GetType() != ui::wm::WINDOW_TYPE_PANEL))) {
357 continue; 350 continue;
(...skipping 12 matching lines...) Expand all
370 header_bounds.set_height(top_inset); 363 header_bounds.set_height(top_inset);
371 new_transform.TransformRect(&header_bounds); 364 new_transform.TransformRect(&header_bounds);
372 window_bounds.Inset(0, gfx::ToCeiledInt(header_bounds.height()), 0, 0); 365 window_bounds.Inset(0, gfx::ToCeiledInt(header_bounds.height()), 0, 0);
373 } 366 }
374 bounds.Union(window->GetParent()->ConvertRectToScreen( 367 bounds.Union(window->GetParent()->ConvertRectToScreen(
375 ToEnclosingRect(window_bounds))); 368 ToEnclosingRect(window_bounds)));
376 } 369 }
377 return bounds; 370 return bounds;
378 } 371 }
379 372
373 SkColor ScopedTransformOverviewWindow::GetTopColor() const {
374 for (auto* window : GetTransientTreeIterator(window_)) {
375 // If there are regular windows in the transient ancestor tree, all those
376 // windows are shown in the same overview item and the header is not masked.
377 if (window != window_ && (window->GetType() == ui::wm::WINDOW_TYPE_NORMAL ||
378 window->GetType() == ui::wm::WINDOW_TYPE_PANEL)) {
379 return SK_ColorTRANSPARENT;
380 }
381 }
382 return static_cast<SkColor>(
383 window_->GetIntProperty(WmWindowProperty::TOP_VIEW_COLOR));
384 }
385
380 int ScopedTransformOverviewWindow::GetTopInset() const { 386 int ScopedTransformOverviewWindow::GetTopInset() const {
381 for (auto* window : GetTransientTreeIterator(window_)) { 387 for (auto* window : GetTransientTreeIterator(window_)) {
382 // If there are regular windows in the transient ancestor tree, all those 388 // If there are regular windows in the transient ancestor tree, all those
383 // windows are shown in the same overview item and the header is not masked. 389 // windows are shown in the same overview item and the header is not masked.
384 if (window != window_ && (window->GetType() == ui::wm::WINDOW_TYPE_NORMAL || 390 if (window != window_ && (window->GetType() == ui::wm::WINDOW_TYPE_NORMAL ||
385 window->GetType() == ui::wm::WINDOW_TYPE_PANEL)) { 391 window->GetType() == ui::wm::WINDOW_TYPE_PANEL)) {
386 return 0; 392 return 0;
387 } 393 }
388 } 394 }
389 return window_->GetIntProperty(WmWindowProperty::TOP_VIEW_INSET); 395 return window_->GetIntProperty(WmWindowProperty::TOP_VIEW_INSET);
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
459 gfx::Transform transform; 465 gfx::Transform transform;
460 transform.Translate(dst_rect.x() - src_rect.x(), dst_rect.y() - src_rect.y()); 466 transform.Translate(dst_rect.x() - src_rect.x(), dst_rect.y() - src_rect.y());
461 transform.Scale(static_cast<float>(dst_rect.width()) / src_rect.width(), 467 transform.Scale(static_cast<float>(dst_rect.width()) / src_rect.width(),
462 static_cast<float>(dst_rect.height()) / src_rect.height()); 468 static_cast<float>(dst_rect.height()) / src_rect.height());
463 return transform; 469 return transform;
464 } 470 }
465 471
466 void ScopedTransformOverviewWindow::SetTransform( 472 void ScopedTransformOverviewWindow::SetTransform(
467 WmWindow* root_window, 473 WmWindow* root_window,
468 const gfx::Transform& transform, 474 const gfx::Transform& transform,
469 bool use_mask, 475 bool use_mask) {
470 bool use_shape,
471 float radius) {
472 DCHECK(overview_started_); 476 DCHECK(overview_started_);
473 477
474 if (ash::MaterialDesignController::IsOverviewMaterial() && 478 if (ash::MaterialDesignController::IsOverviewMaterial() &&
475 &transform != &original_transform_) { 479 &transform != &original_transform_) {
476 if (use_mask && !mask_) { 480 if (use_mask && !mask_) {
477 mask_.reset(new OverviewContentMask()); 481 mask_.reset(new OverviewContentMask());
478 mask_->layer()->SetFillsBoundsOpaquely(false); 482 mask_->layer()->SetFillsBoundsOpaquely(false);
479 window()->GetLayer()->SetMaskLayer(mask_->layer()); 483 window()->GetLayer()->SetMaskLayer(mask_->layer());
480 } 484 }
481 if (!determined_original_window_shape_) { 485 if (!determined_original_window_shape_) {
482 determined_original_window_shape_ = true; 486 determined_original_window_shape_ = true;
483 SkRegion* window_shape = window()->GetLayer()->alpha_shape(); 487 SkRegion* window_shape = window()->GetLayer()->alpha_shape();
484 if (!original_window_shape_ && window_shape) 488 if (!original_window_shape_ && window_shape)
485 original_window_shape_.reset(new SkRegion(*window_shape)); 489 original_window_shape_.reset(new SkRegion(*window_shape));
486 } 490 }
487 gfx::Rect bounds(GetTargetBoundsInScreen().size());
488 const int inset = (use_mask || use_shape) ? GetTopInset() : 0;
489 if (mask_) {
490 // Mask layer is used both to hide the window header and to use rounded
491 // corners. Its layout needs to be update when setting a transform.
492 mask_->layer()->SetBounds(bounds);
493 mask_->set_inset(inset);
494 mask_->set_radius(radius);
495 window()->GetLayer()->SchedulePaint(bounds);
496 } else if (inset > 0) {
497 // Alpha shape is only used to to hide the window header and only when
498 // not using a mask layer.
499 bounds.Inset(0, inset, 0, 0);
500 SkRegion* region = new SkRegion;
501 region->setRect(RectToSkIRect(bounds));
502 if (original_window_shape_)
503 region->op(*original_window_shape_, SkRegion::kIntersect_Op);
504 window()->GetLayer()->SetAlphaShape(base::WrapUnique(region));
505 window()->SetMasksToBounds(true);
506 }
507 } 491 }
508 492
509 gfx::Point target_origin(GetTargetBoundsInScreen().origin()); 493 gfx::Point target_origin(GetTargetBoundsInScreen().origin());
510 494
511 for (auto* window : GetTransientTreeIterator(window_)) { 495 for (auto* window : GetTransientTreeIterator(window_)) {
512 WmWindow* parent_window = window->GetParent(); 496 WmWindow* parent_window = window->GetParent();
513 gfx::Point original_origin = 497 gfx::Point original_origin =
514 parent_window->ConvertRectToScreen(window->GetTargetBounds()).origin(); 498 parent_window->ConvertRectToScreen(window->GetTargetBounds()).origin();
515 gfx::Transform new_transform = 499 gfx::Transform new_transform =
516 TransformAboutPivot(gfx::Point(target_origin.x() - original_origin.x(), 500 TransformAboutPivot(gfx::Point(target_origin.x() - original_origin.x(),
517 target_origin.y() - original_origin.y()), 501 target_origin.y() - original_origin.y()),
518 transform); 502 transform);
519 window->SetTransform(new_transform); 503 window->SetTransform(new_transform);
520 } 504 }
521 } 505 }
522 506
523 void ScopedTransformOverviewWindow::SetOpacity(float opacity) { 507 void ScopedTransformOverviewWindow::SetOpacity(float opacity) {
524 for (auto* window : GetTransientTreeIterator(window_)) { 508 for (auto* window : GetTransientTreeIterator(window_)) {
525 window->SetOpacity(opacity); 509 window->SetOpacity(opacity);
526 } 510 }
527 } 511 }
528 512
513 void ScopedTransformOverviewWindow::HideHeaderAndSetShape(bool use_mask,
514 bool use_shape,
515 int radius) {
516 gfx::Rect bounds(GetTargetBoundsInScreen().size());
517 const int inset = (use_mask || use_shape) ? GetTopInset() : 0;
518 if (mask_) {
519 // Mask layer is used both to hide the window header and to use rounded
520 // corners. Its layout needs to be updated when setting a transform.
521 mask_->layer()->SetBounds(bounds);
522 mask_->set_inset(inset);
523 mask_->set_radius(radius);
524 window()->GetLayer()->SchedulePaint(bounds);
525 } else if (inset > 0) {
526 // Alpha shape is only used to hide the window header and only when not
527 // using a mask layer.
528 bounds.Inset(0, inset, 0, 0);
529 SkRegion* region = new SkRegion;
530 region->setRect(RectToSkIRect(bounds));
531 if (original_window_shape_)
532 region->op(*original_window_shape_, SkRegion::kIntersect_Op);
533 window()->GetLayer()->SetAlphaShape(base::WrapUnique(region));
534 window()->SetMasksToBounds(true);
535 }
536 }
537
538 void ScopedTransformOverviewWindow::ShowHeaderAndResetShape() {
539 ui::Layer* layer = window()->GetLayer();
540 layer->SetMaskLayer(nullptr);
541 mask_.reset();
542
543 if (original_window_shape_) {
544 layer->SetAlphaShape(
545 base::MakeUnique<SkRegion>(*original_window_shape_.get()));
546 } else {
547 layer->SetAlphaShape(nullptr);
548 }
549 window()->SetMasksToBounds(false);
550 }
551
529 void ScopedTransformOverviewWindow::Close() { 552 void ScopedTransformOverviewWindow::Close() {
530 if (immediate_close_for_tests || 553 if (immediate_close_for_tests ||
531 !ash::MaterialDesignController::IsOverviewMaterial()) { 554 !ash::MaterialDesignController::IsOverviewMaterial()) {
532 CloseWidget(); 555 CloseWidget();
533 return; 556 return;
534 } 557 }
535 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 558 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
536 FROM_HERE, base::Bind(&ScopedTransformOverviewWindow::CloseWidget, 559 FROM_HERE, base::Bind(&ScopedTransformOverviewWindow::CloseWidget,
537 weak_ptr_factory_.GetWeakPtr()), 560 weak_ptr_factory_.GetWeakPtr()),
538 base::TimeDelta::FromMilliseconds(kCloseWindowDelayInMilliseconds)); 561 base::TimeDelta::FromMilliseconds(kCloseWindowDelayInMilliseconds));
(...skipping 11 matching lines...) Expand all
550 if (parent_window) 573 if (parent_window)
551 parent_window->CloseWidget(); 574 parent_window->CloseWidget();
552 } 575 }
553 576
554 // static 577 // static
555 void ScopedTransformOverviewWindow::SetImmediateCloseForTests() { 578 void ScopedTransformOverviewWindow::SetImmediateCloseForTests() {
556 immediate_close_for_tests = true; 579 immediate_close_for_tests = true;
557 } 580 }
558 581
559 } // namespace ash 582 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698