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

Side by Side Diff: ash/common/wm/overview/window_grid.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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/window_grid.h" 5 #include "ash/common/wm/overview/window_grid.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <functional> 8 #include <functional>
9 #include <set> 9 #include <set>
10 #include <utility> 10 #include <utility>
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 } 401 }
402 402
403 if (!ash::MaterialDesignController::IsOverviewMaterial() && 403 if (!ash::MaterialDesignController::IsOverviewMaterial() &&
404 base::CommandLine::ForCurrentProcess()->HasSwitch( 404 base::CommandLine::ForCurrentProcess()->HasSwitch(
405 switches::kAshEnableStableOverviewOrder)) { 405 switches::kAshEnableStableOverviewOrder)) {
406 // Reorder windows to try to minimize movement to target overview positions. 406 // Reorder windows to try to minimize movement to target overview positions.
407 // This also creates a stable window ordering. 407 // This also creates a stable window ordering.
408 ReorderItemsGreedyLeastMovement(&windows_in_root, root_window_, 408 ReorderItemsGreedyLeastMovement(&windows_in_root, root_window_,
409 window_selector_->text_filter_bottom()); 409 window_selector_->text_filter_bottom());
410 } 410 }
411 PrepareForUsingMasksOrShapes(windows_in_root.size());
bruthig 2016/08/30 17:57:33 Correct me if I'm wrong but there is no need for t
varkha 2016/09/02 11:22:51 There is since this is dependent on number of wind
411 for (auto* window : windows_in_root) { 412 for (auto* window : windows_in_root) {
412 window->AddObserver(this); 413 window->AddObserver(this);
413 observed_windows_.insert(window); 414 observed_windows_.insert(window);
414 window_list_.push_back(new WindowSelectorItem(window, window_selector_)); 415 window_list_.push_back(new WindowSelectorItem(window, window_selector_));
415 } 416 }
416 } 417 }
417 418
418 WindowGrid::~WindowGrid() { 419 WindowGrid::~WindowGrid() {
419 for (WmWindow* window : observed_windows_) 420 for (WmWindow* window : observed_windows_)
420 window->RemoveObserver(this); 421 window->RemoveObserver(this);
421 } 422 }
422 423
423 void WindowGrid::Shutdown() { 424 void WindowGrid::Shutdown() {
424 if (shield_widget_) { 425 if (shield_widget_) {
425 // Fade out the shield widget. This animation continues past the lifetime 426 // Fade out the shield widget. This animation continues past the lifetime
426 // of |this|. 427 // of |this|.
427 WmWindow* widget_window = 428 WmWindow* widget_window =
428 WmLookup::Get()->GetWindowForWidget(shield_widget_.get()); 429 WmLookup::Get()->GetWindowForWidget(shield_widget_.get());
429 ui::ScopedLayerAnimationSettings animation_settings( 430 ui::ScopedLayerAnimationSettings animation_settings(
430 widget_window->GetLayer()->GetAnimator()); 431 widget_window->GetLayer()->GetAnimator());
431 animation_settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds( 432 animation_settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds(
432 kOverviewSelectorTransitionMilliseconds)); 433 kOverviewSelectorTransitionMilliseconds));
433 animation_settings.SetTweenType(gfx::Tween::EASE_IN); 434 animation_settings.SetTweenType(gfx::Tween::EASE_IN_2);
434 animation_settings.SetPreemptionStrategy( 435 animation_settings.SetPreemptionStrategy(
435 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); 436 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
436 // CleanupAnimationObserver will delete itself (and the shield widget) when 437 // CleanupAnimationObserver will delete itself (and the shield widget) when
437 // the opacity animation is complete. 438 // the opacity animation is complete.
438 // Ownership over the observer is passed to the window_selector_->delegate() 439 // Ownership over the observer is passed to the window_selector_->delegate()
439 // which has longer lifetime so that animations can continue even after the 440 // which has longer lifetime so that animations can continue even after the
440 // overview mode is shut down. 441 // overview mode is shut down.
441 views::Widget* shield_widget = shield_widget_.get(); 442 views::Widget* shield_widget = shield_widget_.get();
442 std::unique_ptr<CleanupAnimationObserver> observer( 443 std::unique_ptr<CleanupAnimationObserver> observer(
443 new CleanupAnimationObserver(std::move(shield_widget_))); 444 new CleanupAnimationObserver(std::move(shield_widget_)));
444 animation_settings.AddObserver(observer.get()); 445 animation_settings.AddObserver(observer.get());
445 window_selector_->delegate()->AddDelayedAnimationObserver( 446 window_selector_->delegate()->AddDelayedAnimationObserver(
446 std::move(observer)); 447 std::move(observer));
447 shield_widget->SetOpacity(0.f); 448 shield_widget->SetOpacity(0.f);
448 } 449 }
449 } 450 }
450 451
451 void WindowGrid::PrepareForOverview() { 452 void WindowGrid::PrepareForOverview() {
452 if (ash::MaterialDesignController::IsOverviewMaterial()) 453 if (ash::MaterialDesignController::IsOverviewMaterial())
453 InitShieldWidget(); 454 InitShieldWidget();
454 for (auto iter = window_list_.begin(); iter != window_list_.end(); ++iter) 455 for (auto iter = window_list_.begin(); iter != window_list_.end(); ++iter)
455 (*iter)->PrepareForOverview(); 456 (*iter)->PrepareForOverview();
456 } 457 }
457 458
458 void WindowGrid::PositionWindowsMD(bool animate) { 459 void WindowGrid::PositionWindowsMD(bool animate) {
459 if (window_list_.empty()) 460 if (window_list_.empty())
460 return; 461 return;
461 462 PrepareForUsingMasksOrShapes(window_list_.size());
462 const int kUnlimited = -1;
463 const size_t windows_count = window_list_.size();
464 const base::CommandLine* command_line =
465 base::CommandLine::ForCurrentProcess();
466 int windows_to_use_masks = kMaxWindowsCountToHideHeaderWithMasks;
467 if (command_line->HasSwitch(switches::kAshMaxWindowsToUseMaskInOverview) &&
468 (!base::StringToInt(command_line->GetSwitchValueASCII(
469 switches::kAshMaxWindowsToUseMaskInOverview),
470 &windows_to_use_masks) ||
471 windows_to_use_masks <= kUnlimited)) {
472 windows_to_use_masks = kMaxWindowsCountToHideHeaderWithMasks;
473 }
474 int windows_to_use_shapes = kUnlimited;
475 if (command_line->HasSwitch(switches::kAshMaxWindowsToUseShapeInOverview) &&
476 (!base::StringToInt(command_line->GetSwitchValueASCII(
477 switches::kAshMaxWindowsToUseShapeInOverview),
478 &windows_to_use_shapes) ||
479 windows_to_use_shapes <= kUnlimited)) {
480 windows_to_use_shapes = kUnlimited;
481 }
482 WindowSelectorItem::set_use_mask(windows_to_use_masks <= kUnlimited ||
483 static_cast<int>(windows_count) <=
484 windows_to_use_masks);
485 WindowSelectorItem::set_use_shape(windows_to_use_shapes <= kUnlimited ||
486 static_cast<int>(windows_count) <=
487 windows_to_use_shapes);
488
489 gfx::Rect total_bounds = 463 gfx::Rect total_bounds =
490 root_window_->ConvertRectToScreen(wm::GetDisplayWorkAreaBoundsInParent( 464 root_window_->ConvertRectToScreen(wm::GetDisplayWorkAreaBoundsInParent(
491 root_window_->GetChildByShellWindowId( 465 root_window_->GetChildByShellWindowId(
492 kShellWindowId_DefaultContainer))); 466 kShellWindowId_DefaultContainer)));
493 // Windows occupy vertically centered area with additional vertical insets. 467 // Windows occupy vertically centered area with additional vertical insets.
494 int horizontal_inset = 468 int horizontal_inset =
495 gfx::ToFlooredInt(std::min(kOverviewInsetRatio * total_bounds.width(), 469 gfx::ToFlooredInt(std::min(kOverviewInsetRatio * total_bounds.width(),
496 kOverviewInsetRatio * total_bounds.height())); 470 kOverviewInsetRatio * total_bounds.height()));
497 int vertical_inset = 471 int vertical_inset =
498 horizontal_inset + 472 horizontal_inset +
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
587 // |right_bound| was reverted. Perform one last pass to position the |rects|. 561 // |right_bound| was reverted. Perform one last pass to position the |rects|.
588 if (make_last_adjustment) { 562 if (make_last_adjustment) {
589 gfx::Rect overview_bounds(total_bounds); 563 gfx::Rect overview_bounds(total_bounds);
590 overview_bounds.set_width(right_bound - total_bounds.x()); 564 overview_bounds.set_width(right_bound - total_bounds.x());
591 FitWindowRectsInBounds(overview_bounds, 565 FitWindowRectsInBounds(overview_bounds,
592 std::min(kMaxHeight + 2 * kWindowMarginMD, height), 566 std::min(kMaxHeight + 2 * kWindowMarginMD, height),
593 &rects, &max_bottom, &min_right, &max_right); 567 &rects, &max_bottom, &min_right, &max_right);
594 } 568 }
595 // Position the windows centering the left-aligned rows vertically. 569 // Position the windows centering the left-aligned rows vertically.
596 gfx::Vector2d offset(0, (total_bounds.bottom() - max_bottom) / 2); 570 gfx::Vector2d offset(0, (total_bounds.bottom() - max_bottom) / 2);
597 for (size_t i = 0; i < windows_count; ++i) { 571 for (size_t i = 0; i < window_list_.size(); ++i) {
598 window_list_[i]->SetBounds( 572 window_list_[i]->SetBounds(
599 rects[i] + offset, 573 rects[i] + offset,
600 animate 574 animate
601 ? OverviewAnimationType::OVERVIEW_ANIMATION_LAY_OUT_SELECTOR_ITEMS 575 ? OverviewAnimationType::OVERVIEW_ANIMATION_LAY_OUT_SELECTOR_ITEMS
602 : OverviewAnimationType::OVERVIEW_ANIMATION_NONE); 576 : OverviewAnimationType::OVERVIEW_ANIMATION_NONE);
603 } 577 }
604 578
605 // If the selection widget is active, reposition it without any animation. 579 // If the selection widget is active, reposition it without any animation.
606 if (selection_widget_) 580 if (selection_widget_)
607 MoveSelectionWidgetToTarget(animate); 581 MoveSelectionWidgetToTarget(animate);
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
852 WmWindow* widget_window = 826 WmWindow* widget_window =
853 WmLookup::Get()->GetWindowForWidget(shield_widget_.get()); 827 WmLookup::Get()->GetWindowForWidget(shield_widget_.get());
854 const gfx::Rect bounds = widget_window->GetParent()->GetBounds(); 828 const gfx::Rect bounds = widget_window->GetParent()->GetBounds();
855 widget_window->SetBounds(bounds); 829 widget_window->SetBounds(bounds);
856 widget_window->SetName("OverviewModeShield"); 830 widget_window->SetName("OverviewModeShield");
857 831
858 ui::ScopedLayerAnimationSettings animation_settings( 832 ui::ScopedLayerAnimationSettings animation_settings(
859 widget_window->GetLayer()->GetAnimator()); 833 widget_window->GetLayer()->GetAnimator());
860 animation_settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds( 834 animation_settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds(
861 kOverviewSelectorTransitionMilliseconds)); 835 kOverviewSelectorTransitionMilliseconds));
862 animation_settings.SetTweenType(gfx::Tween::LINEAR_OUT_SLOW_IN); 836 animation_settings.SetTweenType(gfx::Tween::EASE_IN);
863 animation_settings.SetPreemptionStrategy( 837 animation_settings.SetPreemptionStrategy(
864 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); 838 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
865 shield_widget_->SetOpacity(kShieldOpacity); 839 shield_widget_->SetOpacity(kShieldOpacity);
866 } 840 }
867 841
868 void WindowGrid::InitSelectionWidget(WindowSelector::Direction direction) { 842 void WindowGrid::InitSelectionWidget(WindowSelector::Direction direction) {
869 const bool material = ash::MaterialDesignController::IsOverviewMaterial(); 843 const bool material = ash::MaterialDesignController::IsOverviewMaterial();
870 const int border_thickness = material ? kWindowSelectionBorderThicknessMD 844 const int border_thickness = material ? kWindowSelectionBorderThicknessMD
871 : kWindowSelectionBorderThickness; 845 : kWindowSelectionBorderThickness;
872 const int border_color = 846 const int border_color =
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
1052 if (*min_right > left) 1026 if (*min_right > left)
1053 *min_right = left; 1027 *min_right = left;
1054 if (*max_right < left) 1028 if (*max_right < left)
1055 *max_right = left; 1029 *max_right = left;
1056 } 1030 }
1057 *max_bottom = top + height; 1031 *max_bottom = top + height;
1058 } 1032 }
1059 return windows_fit; 1033 return windows_fit;
1060 } 1034 }
1061 1035
1036 void WindowGrid::PrepareForUsingMasksOrShapes(size_t windows_count) const {
1037 const int kUnlimited = -1;
1038 const base::CommandLine* command_line =
1039 base::CommandLine::ForCurrentProcess();
1040 int windows_to_use_masks = kMaxWindowsCountToHideHeaderWithMasks;
1041 if (command_line->HasSwitch(switches::kAshMaxWindowsToUseMaskInOverview) &&
1042 (!base::StringToInt(command_line->GetSwitchValueASCII(
1043 switches::kAshMaxWindowsToUseMaskInOverview),
1044 &windows_to_use_masks) ||
1045 windows_to_use_masks <= kUnlimited)) {
1046 windows_to_use_masks = kMaxWindowsCountToHideHeaderWithMasks;
bruthig 2016/08/30 17:57:33 You could consider adding a warning when the comme
varkha 2016/09/02 11:22:51 This flag was temporary scaffolding and Will be re
1047 }
1048 int windows_to_use_shapes = kUnlimited;
1049 if (command_line->HasSwitch(switches::kAshMaxWindowsToUseShapeInOverview) &&
bruthig 2016/08/30 17:57:33 Consider wrapping this duplicate logic in a helper
varkha 2016/09/02 11:22:51 Ditto, will keep this in mind.
1050 (!base::StringToInt(command_line->GetSwitchValueASCII(
1051 switches::kAshMaxWindowsToUseShapeInOverview),
1052 &windows_to_use_shapes) ||
1053 windows_to_use_shapes <= kUnlimited)) {
1054 windows_to_use_shapes = kUnlimited;
1055 }
1056 WindowSelectorItem::set_use_mask(windows_to_use_masks <= kUnlimited ||
1057 static_cast<int>(windows_count) <=
1058 windows_to_use_masks);
1059 WindowSelectorItem::set_use_shape(windows_to_use_shapes <= kUnlimited ||
1060 static_cast<int>(windows_count) <=
1061 windows_to_use_shapes);
1062 }
1063
1062 } // namespace ash 1064 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698