| 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> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "ash/common/ash_switches.h" | 13 #include "ash/common/ash_switches.h" |
| 14 #include "ash/common/shelf/wm_shelf.h" | 14 #include "ash/common/shelf/wm_shelf.h" |
| 15 #include "ash/common/wm/overview/cleanup_animation_observer.h" | 15 #include "ash/common/wm/overview/cleanup_animation_observer.h" |
| 16 #include "ash/common/wm/overview/scoped_overview_animation_settings.h" | 16 #include "ash/common/wm/overview/scoped_overview_animation_settings.h" |
| 17 #include "ash/common/wm/overview/scoped_overview_animation_settings_factory.h" | 17 #include "ash/common/wm/overview/scoped_overview_animation_settings_factory.h" |
| 18 #include "ash/common/wm/overview/window_selector.h" | 18 #include "ash/common/wm/overview/window_selector.h" |
| 19 #include "ash/common/wm/overview/window_selector_delegate.h" | 19 #include "ash/common/wm/overview/window_selector_delegate.h" |
| 20 #include "ash/common/wm/overview/window_selector_item.h" | 20 #include "ash/common/wm/overview/window_selector_item.h" |
| 21 #include "ash/common/wm/window_state.h" | 21 #include "ash/common/wm/window_state.h" |
| 22 #include "ash/common/wm/wm_screen_util.h" | 22 #include "ash/common/wm/wm_screen_util.h" |
| 23 #include "ash/common/wm_lookup.h" | |
| 24 #include "ash/common/wm_window.h" | 23 #include "ash/common/wm_window.h" |
| 25 #include "ash/public/cpp/shelf_types.h" | 24 #include "ash/public/cpp/shelf_types.h" |
| 26 #include "ash/public/cpp/shell_window_ids.h" | 25 #include "ash/public/cpp/shell_window_ids.h" |
| 27 #include "ash/root_window_controller.h" | 26 #include "ash/root_window_controller.h" |
| 28 #include "ash/wm/window_state_aura.h" | 27 #include "ash/wm/window_state_aura.h" |
| 29 #include "base/command_line.h" | 28 #include "base/command_line.h" |
| 30 #include "base/i18n/string_search.h" | 29 #include "base/i18n/string_search.h" |
| 31 #include "base/memory/ptr_util.h" | 30 #include "base/memory/ptr_util.h" |
| 32 #include "base/strings/string_number_conversions.h" | 31 #include "base/strings/string_number_conversions.h" |
| 33 #include "third_party/skia/include/core/SkColor.h" | 32 #include "third_party/skia/include/core/SkColor.h" |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 params.layer_type = layer_type; | 239 params.layer_type = layer_type; |
| 241 params.accept_events = false; | 240 params.accept_events = false; |
| 242 widget->set_focus_on_creation(false); | 241 widget->set_focus_on_creation(false); |
| 243 // Parenting in kShellWindowId_WallpaperContainer allows proper layering of | 242 // Parenting in kShellWindowId_WallpaperContainer allows proper layering of |
| 244 // the shield and selection widgets. Since that container is created with | 243 // the shield and selection widgets. Since that container is created with |
| 245 // USE_LOCAL_COORDINATES BoundsInScreenBehavior local bounds in |root_window_| | 244 // USE_LOCAL_COORDINATES BoundsInScreenBehavior local bounds in |root_window_| |
| 246 // need to be provided. | 245 // need to be provided. |
| 247 root_window->GetRootWindowController()->ConfigureWidgetInitParamsForContainer( | 246 root_window->GetRootWindowController()->ConfigureWidgetInitParamsForContainer( |
| 248 widget, kShellWindowId_WallpaperContainer, ¶ms); | 247 widget, kShellWindowId_WallpaperContainer, ¶ms); |
| 249 widget->Init(params); | 248 widget->Init(params); |
| 250 WmWindow* widget_window = WmLookup::Get()->GetWindowForWidget(widget); | 249 WmWindow* widget_window = WmWindow::Get(widget->GetNativeWindow()); |
| 251 // Disable the "bounce in" animation when showing the window. | 250 // Disable the "bounce in" animation when showing the window. |
| 252 widget_window->SetVisibilityAnimationTransition(::wm::ANIMATE_NONE); | 251 widget_window->SetVisibilityAnimationTransition(::wm::ANIMATE_NONE); |
| 253 // The background widget should not activate the shelf when passing under it. | 252 // The background widget should not activate the shelf when passing under it. |
| 254 widget_window->GetWindowState()->set_ignored_by_shelf(true); | 253 widget_window->GetWindowState()->set_ignored_by_shelf(true); |
| 255 if (params.layer_type == ui::LAYER_SOLID_COLOR) { | 254 if (params.layer_type == ui::LAYER_SOLID_COLOR) { |
| 256 widget_window->GetLayer()->SetColor(background_color); | 255 widget_window->GetLayer()->SetColor(background_color); |
| 257 } else { | 256 } else { |
| 258 views::View* content_view = | 257 views::View* content_view = |
| 259 new RoundedRectView(border_radius, SK_ColorTRANSPARENT); | 258 new RoundedRectView(border_radius, SK_ColorTRANSPARENT); |
| 260 content_view->set_background(new BackgroundWith1PxBorder( | 259 content_view->set_background(new BackgroundWith1PxBorder( |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 | 299 |
| 301 WindowGrid::~WindowGrid() {} | 300 WindowGrid::~WindowGrid() {} |
| 302 | 301 |
| 303 void WindowGrid::Shutdown() { | 302 void WindowGrid::Shutdown() { |
| 304 for (const auto& window : window_list_) | 303 for (const auto& window : window_list_) |
| 305 window->Shutdown(); | 304 window->Shutdown(); |
| 306 | 305 |
| 307 if (shield_widget_) { | 306 if (shield_widget_) { |
| 308 // Fade out the shield widget. This animation continues past the lifetime | 307 // Fade out the shield widget. This animation continues past the lifetime |
| 309 // of |this|. | 308 // of |this|. |
| 310 WmWindow* widget_window = | 309 WmWindow* widget_window = WmWindow::Get(shield_widget_->GetNativeWindow()); |
| 311 WmLookup::Get()->GetWindowForWidget(shield_widget_.get()); | |
| 312 ui::ScopedLayerAnimationSettings animation_settings( | 310 ui::ScopedLayerAnimationSettings animation_settings( |
| 313 widget_window->GetLayer()->GetAnimator()); | 311 widget_window->GetLayer()->GetAnimator()); |
| 314 animation_settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds( | 312 animation_settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds( |
| 315 kOverviewSelectorTransitionMilliseconds)); | 313 kOverviewSelectorTransitionMilliseconds)); |
| 316 animation_settings.SetTweenType(gfx::Tween::EASE_OUT); | 314 animation_settings.SetTweenType(gfx::Tween::EASE_OUT); |
| 317 animation_settings.SetPreemptionStrategy( | 315 animation_settings.SetPreemptionStrategy( |
| 318 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | 316 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); |
| 319 // CleanupAnimationObserver will delete itself (and the shield widget) when | 317 // CleanupAnimationObserver will delete itself (and the shield widget) when |
| 320 // the opacity animation is complete. | 318 // the opacity animation is complete. |
| 321 // Ownership over the observer is passed to the window_selector_->delegate() | 319 // Ownership over the observer is passed to the window_selector_->delegate() |
| (...skipping 14 matching lines...) Expand all Loading... |
| 336 for (const auto& window : window_list_) | 334 for (const auto& window : window_list_) |
| 337 window->PrepareForOverview(); | 335 window->PrepareForOverview(); |
| 338 prepared_for_overview_ = true; | 336 prepared_for_overview_ = true; |
| 339 } | 337 } |
| 340 | 338 |
| 341 void WindowGrid::PositionWindows(bool animate) { | 339 void WindowGrid::PositionWindows(bool animate) { |
| 342 if (window_selector_->is_shut_down() || window_list_.empty()) | 340 if (window_selector_->is_shut_down() || window_list_.empty()) |
| 343 return; | 341 return; |
| 344 DCHECK(shield_widget_.get()); | 342 DCHECK(shield_widget_.get()); |
| 345 // Keep the background shield widget covering the whole screen. | 343 // Keep the background shield widget covering the whole screen. |
| 346 WmWindow* widget_window = | 344 WmWindow* widget_window = WmWindow::Get(shield_widget_->GetNativeWindow()); |
| 347 WmLookup::Get()->GetWindowForWidget(shield_widget_.get()); | |
| 348 const gfx::Rect bounds = widget_window->GetParent()->GetBounds(); | 345 const gfx::Rect bounds = widget_window->GetParent()->GetBounds(); |
| 349 widget_window->SetBounds(bounds); | 346 widget_window->SetBounds(bounds); |
| 350 gfx::Rect total_bounds = | 347 gfx::Rect total_bounds = |
| 351 root_window_->ConvertRectToScreen(wm::GetDisplayWorkAreaBoundsInParent( | 348 root_window_->ConvertRectToScreen(wm::GetDisplayWorkAreaBoundsInParent( |
| 352 root_window_->GetChildByShellWindowId( | 349 root_window_->GetChildByShellWindowId( |
| 353 kShellWindowId_DefaultContainer))); | 350 kShellWindowId_DefaultContainer))); |
| 354 // Windows occupy vertically centered area with additional vertical insets. | 351 // Windows occupy vertically centered area with additional vertical insets. |
| 355 int horizontal_inset = | 352 int horizontal_inset = |
| 356 gfx::ToFlooredInt(std::min(kOverviewInsetRatio * total_bounds.width(), | 353 gfx::ToFlooredInt(std::min(kOverviewInsetRatio * total_bounds.width(), |
| 357 kOverviewInsetRatio * total_bounds.height())); | 354 kOverviewInsetRatio * total_bounds.height())); |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 553 selector_shadow_.reset(); | 550 selector_shadow_.reset(); |
| 554 } | 551 } |
| 555 } | 552 } |
| 556 } | 553 } |
| 557 } | 554 } |
| 558 | 555 |
| 559 void WindowGrid::WindowClosing(WindowSelectorItem* window) { | 556 void WindowGrid::WindowClosing(WindowSelectorItem* window) { |
| 560 if (!selection_widget_ || SelectedWindow() != window) | 557 if (!selection_widget_ || SelectedWindow() != window) |
| 561 return; | 558 return; |
| 562 WmWindow* selection_widget_window = | 559 WmWindow* selection_widget_window = |
| 563 WmLookup::Get()->GetWindowForWidget(selection_widget_.get()); | 560 WmWindow::Get(selection_widget_->GetNativeWindow()); |
| 564 std::unique_ptr<ScopedOverviewAnimationSettings> animation_settings_label = | 561 std::unique_ptr<ScopedOverviewAnimationSettings> animation_settings_label = |
| 565 ScopedOverviewAnimationSettingsFactory::Get() | 562 ScopedOverviewAnimationSettingsFactory::Get() |
| 566 ->CreateOverviewAnimationSettings( | 563 ->CreateOverviewAnimationSettings( |
| 567 OverviewAnimationType::OVERVIEW_ANIMATION_CLOSING_SELECTOR_ITEM, | 564 OverviewAnimationType::OVERVIEW_ANIMATION_CLOSING_SELECTOR_ITEM, |
| 568 selection_widget_window); | 565 selection_widget_window); |
| 569 selection_widget_->SetOpacity(0.f); | 566 selection_widget_->SetOpacity(0.f); |
| 570 } | 567 } |
| 571 | 568 |
| 572 void WindowGrid::OnWindowDestroying(aura::Window* window) { | 569 void WindowGrid::OnWindowDestroying(aura::Window* window) { |
| 573 window_observer_.Remove(window); | 570 window_observer_.Remove(window); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 645 // synonymous with a black shelf background. Update this code if that | 642 // synonymous with a black shelf background. Update this code if that |
| 646 // assumption is no longer valid. | 643 // assumption is no longer valid. |
| 647 const float initial_opacity = | 644 const float initial_opacity = |
| 648 (WmShelf::ForWindow(root_window_)->GetBackgroundType() == | 645 (WmShelf::ForWindow(root_window_)->GetBackgroundType() == |
| 649 SHELF_BACKGROUND_MAXIMIZED) | 646 SHELF_BACKGROUND_MAXIMIZED) |
| 650 ? 1.f | 647 ? 1.f |
| 651 : 0.f; | 648 : 0.f; |
| 652 shield_widget_.reset( | 649 shield_widget_.reset( |
| 653 CreateBackgroundWidget(root_window_, ui::LAYER_SOLID_COLOR, kShieldColor, | 650 CreateBackgroundWidget(root_window_, ui::LAYER_SOLID_COLOR, kShieldColor, |
| 654 0, 0, SK_ColorTRANSPARENT, initial_opacity)); | 651 0, 0, SK_ColorTRANSPARENT, initial_opacity)); |
| 655 WmWindow* widget_window = | 652 WmWindow* widget_window = WmWindow::Get(shield_widget_->GetNativeWindow()); |
| 656 WmLookup::Get()->GetWindowForWidget(shield_widget_.get()); | |
| 657 const gfx::Rect bounds = widget_window->GetParent()->GetBounds(); | 653 const gfx::Rect bounds = widget_window->GetParent()->GetBounds(); |
| 658 widget_window->SetBounds(bounds); | 654 widget_window->SetBounds(bounds); |
| 659 widget_window->SetName("OverviewModeShield"); | 655 widget_window->SetName("OverviewModeShield"); |
| 660 | 656 |
| 661 ui::ScopedLayerAnimationSettings animation_settings( | 657 ui::ScopedLayerAnimationSettings animation_settings( |
| 662 widget_window->GetLayer()->GetAnimator()); | 658 widget_window->GetLayer()->GetAnimator()); |
| 663 animation_settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds( | 659 animation_settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds( |
| 664 kOverviewSelectorTransitionMilliseconds)); | 660 kOverviewSelectorTransitionMilliseconds)); |
| 665 animation_settings.SetTweenType(gfx::Tween::EASE_OUT); | 661 animation_settings.SetTweenType(gfx::Tween::EASE_OUT); |
| 666 animation_settings.SetPreemptionStrategy( | 662 animation_settings.SetPreemptionStrategy( |
| 667 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | 663 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); |
| 668 shield_widget_->SetOpacity(kShieldOpacity); | 664 shield_widget_->SetOpacity(kShieldOpacity); |
| 669 } | 665 } |
| 670 | 666 |
| 671 void WindowGrid::InitSelectionWidget(WindowSelector::Direction direction) { | 667 void WindowGrid::InitSelectionWidget(WindowSelector::Direction direction) { |
| 672 selection_widget_.reset(CreateBackgroundWidget( | 668 selection_widget_.reset(CreateBackgroundWidget( |
| 673 root_window_, ui::LAYER_TEXTURED, kWindowSelectionColor, | 669 root_window_, ui::LAYER_TEXTURED, kWindowSelectionColor, |
| 674 kWindowSelectionBorderThickness, kWindowSelectionRadius, | 670 kWindowSelectionBorderThickness, kWindowSelectionRadius, |
| 675 kWindowSelectionBorderColor, 0.f)); | 671 kWindowSelectionBorderColor, 0.f)); |
| 676 WmWindow* widget_window = | 672 WmWindow* widget_window = WmWindow::Get(selection_widget_->GetNativeWindow()); |
| 677 WmLookup::Get()->GetWindowForWidget(selection_widget_.get()); | |
| 678 const gfx::Rect target_bounds = | 673 const gfx::Rect target_bounds = |
| 679 root_window_->ConvertRectFromScreen(SelectedWindow()->target_bounds()); | 674 root_window_->ConvertRectFromScreen(SelectedWindow()->target_bounds()); |
| 680 gfx::Vector2d fade_out_direction = | 675 gfx::Vector2d fade_out_direction = |
| 681 GetSlideVectorForFadeIn(direction, target_bounds); | 676 GetSlideVectorForFadeIn(direction, target_bounds); |
| 682 widget_window->SetBounds(target_bounds - fade_out_direction); | 677 widget_window->SetBounds(target_bounds - fade_out_direction); |
| 683 widget_window->SetName("OverviewModeSelector"); | 678 widget_window->SetName("OverviewModeSelector"); |
| 684 | 679 |
| 685 selector_shadow_.reset(new ::wm::Shadow()); | 680 selector_shadow_.reset(new ::wm::Shadow()); |
| 686 selector_shadow_->Init(::wm::ShadowElevation::LARGE); | 681 selector_shadow_->Init(::wm::ShadowElevation::LARGE); |
| 687 selector_shadow_->layer()->SetVisible(true); | 682 selector_shadow_->layer()->SetVisible(true); |
| 688 selection_widget_->GetLayer()->SetMasksToBounds(false); | 683 selection_widget_->GetLayer()->SetMasksToBounds(false); |
| 689 selection_widget_->GetLayer()->Add(selector_shadow_->layer()); | 684 selection_widget_->GetLayer()->Add(selector_shadow_->layer()); |
| 690 selector_shadow_->SetContentBounds(gfx::Rect(target_bounds.size())); | 685 selector_shadow_->SetContentBounds(gfx::Rect(target_bounds.size())); |
| 691 } | 686 } |
| 692 | 687 |
| 693 void WindowGrid::MoveSelectionWidget(WindowSelector::Direction direction, | 688 void WindowGrid::MoveSelectionWidget(WindowSelector::Direction direction, |
| 694 bool recreate_selection_widget, | 689 bool recreate_selection_widget, |
| 695 bool out_of_bounds, | 690 bool out_of_bounds, |
| 696 bool animate) { | 691 bool animate) { |
| 697 // If the selection widget is already active, fade it out in the selection | 692 // If the selection widget is already active, fade it out in the selection |
| 698 // direction. | 693 // direction. |
| 699 if (selection_widget_ && (recreate_selection_widget || out_of_bounds)) { | 694 if (selection_widget_ && (recreate_selection_widget || out_of_bounds)) { |
| 700 // Animate the old selection widget and then destroy it. | 695 // Animate the old selection widget and then destroy it. |
| 701 views::Widget* old_selection = selection_widget_.get(); | 696 views::Widget* old_selection = selection_widget_.get(); |
| 702 WmWindow* old_selection_window = | 697 WmWindow* old_selection_window = |
| 703 WmLookup::Get()->GetWindowForWidget(old_selection); | 698 WmWindow::Get(old_selection->GetNativeWindow()); |
| 704 gfx::Vector2d fade_out_direction = | 699 gfx::Vector2d fade_out_direction = |
| 705 GetSlideVectorForFadeIn(direction, old_selection_window->GetBounds()); | 700 GetSlideVectorForFadeIn(direction, old_selection_window->GetBounds()); |
| 706 | 701 |
| 707 ui::ScopedLayerAnimationSettings animation_settings( | 702 ui::ScopedLayerAnimationSettings animation_settings( |
| 708 old_selection_window->GetLayer()->GetAnimator()); | 703 old_selection_window->GetLayer()->GetAnimator()); |
| 709 animation_settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds( | 704 animation_settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds( |
| 710 kOverviewSelectorTransitionMilliseconds)); | 705 kOverviewSelectorTransitionMilliseconds)); |
| 711 animation_settings.SetPreemptionStrategy( | 706 animation_settings.SetPreemptionStrategy( |
| 712 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | 707 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); |
| 713 animation_settings.SetTweenType(gfx::Tween::FAST_OUT_LINEAR_IN); | 708 animation_settings.SetTweenType(gfx::Tween::FAST_OUT_LINEAR_IN); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 737 // The selection widget is moved to the newly selected item in the same | 732 // The selection widget is moved to the newly selected item in the same |
| 738 // grid. | 733 // grid. |
| 739 MoveSelectionWidgetToTarget(animate); | 734 MoveSelectionWidgetToTarget(animate); |
| 740 } | 735 } |
| 741 | 736 |
| 742 void WindowGrid::MoveSelectionWidgetToTarget(bool animate) { | 737 void WindowGrid::MoveSelectionWidgetToTarget(bool animate) { |
| 743 gfx::Rect bounds = | 738 gfx::Rect bounds = |
| 744 root_window_->ConvertRectFromScreen(SelectedWindow()->target_bounds()); | 739 root_window_->ConvertRectFromScreen(SelectedWindow()->target_bounds()); |
| 745 if (animate) { | 740 if (animate) { |
| 746 WmWindow* selection_widget_window = | 741 WmWindow* selection_widget_window = |
| 747 WmLookup::Get()->GetWindowForWidget(selection_widget_.get()); | 742 WmWindow::Get(selection_widget_->GetNativeWindow()); |
| 748 ui::ScopedLayerAnimationSettings animation_settings( | 743 ui::ScopedLayerAnimationSettings animation_settings( |
| 749 selection_widget_window->GetLayer()->GetAnimator()); | 744 selection_widget_window->GetLayer()->GetAnimator()); |
| 750 animation_settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds( | 745 animation_settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds( |
| 751 kOverviewSelectorTransitionMilliseconds)); | 746 kOverviewSelectorTransitionMilliseconds)); |
| 752 animation_settings.SetTweenType(gfx::Tween::EASE_IN_OUT); | 747 animation_settings.SetTweenType(gfx::Tween::EASE_IN_OUT); |
| 753 animation_settings.SetPreemptionStrategy( | 748 animation_settings.SetPreemptionStrategy( |
| 754 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | 749 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); |
| 755 selection_widget_->SetBounds(bounds); | 750 selection_widget_->SetBounds(bounds); |
| 756 selection_widget_->SetOpacity(1.f); | 751 selection_widget_->SetOpacity(1.f); |
| 757 | 752 |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 840 *min_right = left; | 835 *min_right = left; |
| 841 if (*max_right < left) | 836 if (*max_right < left) |
| 842 *max_right = left; | 837 *max_right = left; |
| 843 } | 838 } |
| 844 *max_bottom = top + height; | 839 *max_bottom = top + height; |
| 845 } | 840 } |
| 846 return windows_fit; | 841 return windows_fit; |
| 847 } | 842 } |
| 848 | 843 |
| 849 } // namespace ash | 844 } // namespace ash |
| OLD | NEW |