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