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/material_design/material_design_controller.h" | 14 #include "ash/common/material_design/material_design_controller.h" |
15 #include "ash/common/shelf/shelf_types.h" | |
16 #include "ash/common/shelf/wm_shelf.h" | |
15 #include "ash/common/shell_window_ids.h" | 17 #include "ash/common/shell_window_ids.h" |
16 #include "ash/common/wm/overview/scoped_overview_animation_settings.h" | 18 #include "ash/common/wm/overview/scoped_overview_animation_settings.h" |
17 #include "ash/common/wm/overview/scoped_overview_animation_settings_factory.h" | 19 #include "ash/common/wm/overview/scoped_overview_animation_settings_factory.h" |
18 #include "ash/common/wm/overview/scoped_transform_overview_window.h" | 20 #include "ash/common/wm/overview/scoped_transform_overview_window.h" |
19 #include "ash/common/wm/overview/window_selector.h" | 21 #include "ash/common/wm/overview/window_selector.h" |
20 #include "ash/common/wm/overview/window_selector_item.h" | 22 #include "ash/common/wm/overview/window_selector_item.h" |
21 #include "ash/common/wm/window_state.h" | 23 #include "ash/common/wm/window_state.h" |
22 #include "ash/common/wm/wm_screen_util.h" | 24 #include "ash/common/wm/wm_screen_util.h" |
23 #include "ash/common/wm_lookup.h" | 25 #include "ash/common/wm_lookup.h" |
24 #include "ash/common/wm_root_window_controller.h" | 26 #include "ash/common/wm_root_window_controller.h" |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
92 // area of them based on the number of window_list. | 94 // area of them based on the number of window_list. |
93 const float kCardAspectRatio = 4.0f / 3.0f; | 95 const float kCardAspectRatio = 4.0f / 3.0f; |
94 | 96 |
95 // The minimum number of cards along the major axis (i.e. horizontally on a | 97 // The minimum number of cards along the major axis (i.e. horizontally on a |
96 // landscape orientation). | 98 // landscape orientation). |
97 const int kMinCardsMajor = 3; | 99 const int kMinCardsMajor = 3; |
98 | 100 |
99 const int kOverviewSelectorTransitionMilliseconds = 250; | 101 const int kOverviewSelectorTransitionMilliseconds = 250; |
100 | 102 |
101 // The color and opacity of the screen shield in overview. | 103 // The color and opacity of the screen shield in overview. |
102 const SkColor kShieldColor = SkColorSetARGB(178, 0, 0, 0); | 104 const SkColor kShieldColor = SkColorSetARGB(255, 0, 0, 0); |
105 const float kShieldOpacity = 0.7f; | |
103 | 106 |
104 // The color and opacity of the overview selector. | 107 // The color and opacity of the overview selector. |
105 const SkColor kWindowSelectionColor = SkColorSetARGB(128, 0, 0, 0); | 108 const SkColor kWindowSelectionColor = SkColorSetARGB(128, 0, 0, 0); |
106 const SkColor kWindowSelectionColorMD = SkColorSetARGB(51, 255, 255, 255); | 109 const SkColor kWindowSelectionColorMD = SkColorSetARGB(51, 255, 255, 255); |
107 const SkColor kWindowSelectionBorderColor = SkColorSetARGB(38, 255, 255, 255); | 110 const SkColor kWindowSelectionBorderColor = SkColorSetARGB(38, 255, 255, 255); |
108 const SkColor kWindowSelectionBorderColorMD = SkColorSetARGB(76, 255, 255, 255); | 111 const SkColor kWindowSelectionBorderColorMD = SkColorSetARGB(76, 255, 255, 255); |
109 | 112 |
110 // Border thickness of overview selector. | 113 // Border thickness of overview selector. |
111 const int kWindowSelectionBorderThickness = 2; | 114 const int kWindowSelectionBorderThickness = 2; |
112 const int kWindowSelectionBorderThicknessMD = 1; | 115 const int kWindowSelectionBorderThicknessMD = 1; |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
346 } | 349 } |
347 if (swap_index > i) | 350 if (swap_index > i) |
348 std::swap((*items)[i], (*items)[swap_index]); | 351 std::swap((*items)[i], (*items)[swap_index]); |
349 } | 352 } |
350 } | 353 } |
351 | 354 |
352 // Creates and returns a background translucent widget parented in | 355 // Creates and returns a background translucent widget parented in |
353 // |root_window|'s default container and having |background_color|. | 356 // |root_window|'s default container and having |background_color|. |
354 // When |border_thickness| is non-zero, a border is created having | 357 // When |border_thickness| is non-zero, a border is created having |
355 // |border_color|, otherwise |border_color| parameter is ignored. | 358 // |border_color|, otherwise |border_color| parameter is ignored. |
359 // The new background widget starts with |initial_opacity| and then fades in. | |
356 views::Widget* CreateBackgroundWidget(WmWindow* root_window, | 360 views::Widget* CreateBackgroundWidget(WmWindow* root_window, |
357 SkColor background_color, | 361 SkColor background_color, |
358 int border_thickness, | 362 int border_thickness, |
359 int border_radius, | 363 int border_radius, |
360 SkColor border_color) { | 364 SkColor border_color, |
365 float initial_opacity) { | |
361 views::Widget* widget = new views::Widget; | 366 views::Widget* widget = new views::Widget; |
362 views::Widget::InitParams params; | 367 views::Widget::InitParams params; |
363 params.type = views::Widget::InitParams::TYPE_POPUP; | 368 params.type = views::Widget::InitParams::TYPE_POPUP; |
364 params.keep_on_top = false; | 369 params.keep_on_top = false; |
365 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 370 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
366 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; | 371 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; |
367 params.accept_events = false; | 372 params.accept_events = false; |
368 widget->set_focus_on_creation(false); | 373 widget->set_focus_on_creation(false); |
369 // Parenting in kShellWindowId_DesktopBackgroundContainer allows proper | 374 // Parenting in kShellWindowId_DesktopBackgroundContainer allows proper |
370 // layering of the shield and selection widgets. Since that container is | 375 // layering of the shield and selection widgets. Since that container is |
(...skipping 17 matching lines...) Expand all Loading... | |
388 content_view->set_background( | 393 content_view->set_background( |
389 views::Background::CreateSolidBackground(background_color)); | 394 views::Background::CreateSolidBackground(background_color)); |
390 if (border_thickness) { | 395 if (border_thickness) { |
391 content_view->SetBorder( | 396 content_view->SetBorder( |
392 views::Border::CreateSolidBorder(border_thickness, border_color)); | 397 views::Border::CreateSolidBorder(border_thickness, border_color)); |
393 } | 398 } |
394 } | 399 } |
395 widget->SetContentsView(content_view); | 400 widget->SetContentsView(content_view); |
396 widget_window->GetParent()->StackChildAtTop(widget_window); | 401 widget_window->GetParent()->StackChildAtTop(widget_window); |
397 widget->Show(); | 402 widget->Show(); |
398 // New background widget starts with 0 opacity and then fades in. | 403 widget_window->SetOpacity(initial_opacity); |
399 widget_window->SetOpacity(0.f); | |
400 return widget; | 404 return widget; |
401 } | 405 } |
402 | 406 |
403 } // namespace | 407 } // namespace |
404 | 408 |
405 WindowGrid::WindowGrid(WmWindow* root_window, | 409 WindowGrid::WindowGrid(WmWindow* root_window, |
406 const std::vector<WmWindow*>& windows, | 410 const std::vector<WmWindow*>& windows, |
407 WindowSelector* window_selector) | 411 WindowSelector* window_selector) |
408 : root_window_(root_window), | 412 : root_window_(root_window), |
409 window_selector_(window_selector), | 413 window_selector_(window_selector), |
(...skipping 16 matching lines...) Expand all Loading... | |
426 for (auto* window : windows_in_root) { | 430 for (auto* window : windows_in_root) { |
427 window->AddObserver(this); | 431 window->AddObserver(this); |
428 observed_windows_.insert(window); | 432 observed_windows_.insert(window); |
429 window_list_.push_back(new WindowSelectorItem(window, window_selector_)); | 433 window_list_.push_back(new WindowSelectorItem(window, window_selector_)); |
430 } | 434 } |
431 } | 435 } |
432 | 436 |
433 WindowGrid::~WindowGrid() { | 437 WindowGrid::~WindowGrid() { |
434 for (WmWindow* window : observed_windows_) | 438 for (WmWindow* window : observed_windows_) |
435 window->RemoveObserver(this); | 439 window->RemoveObserver(this); |
440 | |
441 // Fade out the shield widget. This animation continues past the lifetime | |
442 // of |this|. | |
443 WmWindow* widget_window = | |
444 WmLookup::Get()->GetWindowForWidget(shield_widget_.get()); | |
445 ui::ScopedLayerAnimationSettings animation_settings( | |
446 widget_window->GetLayer()->GetAnimator()); | |
447 animation_settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds( | |
448 kOverviewSelectorTransitionMilliseconds)); | |
449 animation_settings.SetTweenType(gfx::Tween::EASE_IN); | |
450 animation_settings.SetPreemptionStrategy( | |
451 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | |
452 // CleanupWidgetAfterAnimationObserver will delete itself (and the | |
453 // shield widget) when the opacity animation is complete. | |
454 views::Widget* shield_widget = shield_widget_.get(); | |
455 animation_settings.AddObserver( | |
456 new CleanupWidgetAfterAnimationObserver(std::move(shield_widget_))); | |
457 shield_widget->SetOpacity(0.f); | |
436 } | 458 } |
437 | 459 |
438 void WindowGrid::PrepareForOverview() { | 460 void WindowGrid::PrepareForOverview() { |
439 if (ash::MaterialDesignController::IsOverviewMaterial()) | 461 if (ash::MaterialDesignController::IsOverviewMaterial()) |
440 InitShieldWidget(); | 462 InitShieldWidget(); |
441 for (auto iter = window_list_.begin(); iter != window_list_.end(); ++iter) | 463 for (auto iter = window_list_.begin(); iter != window_list_.end(); ++iter) |
442 (*iter)->PrepareForOverview(); | 464 (*iter)->PrepareForOverview(); |
443 } | 465 } |
444 | 466 |
445 void WindowGrid::PositionWindowsMD(bool animate) { | 467 void WindowGrid::PositionWindowsMD(bool animate) { |
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
785 | 807 |
786 if (ash::MaterialDesignController::IsOverviewMaterial()) { | 808 if (ash::MaterialDesignController::IsOverviewMaterial()) { |
787 PositionWindows(false); | 809 PositionWindows(false); |
788 return; | 810 return; |
789 } | 811 } |
790 // Recompute the transform for the window. | 812 // Recompute the transform for the window. |
791 (*iter)->RecomputeWindowTransforms(); | 813 (*iter)->RecomputeWindowTransforms(); |
792 } | 814 } |
793 | 815 |
794 void WindowGrid::InitShieldWidget() { | 816 void WindowGrid::InitShieldWidget() { |
795 shield_widget_.reset(CreateBackgroundWidget(root_window_, kShieldColor, 0, 0, | 817 const float initial_opacity = |
796 SK_ColorTRANSPARENT)); | 818 (root_window_->GetRootWindowController() |
819 ->GetShelf() | |
820 ->GetBackgroundType() == SHELF_BACKGROUND_MAXIMIZED) | |
bruthig
2016/07/12 20:43:37
nit: This is currently based on some assumptions i
varkha
2016/07/12 20:50:09
Done.
| |
821 ? 1.f | |
822 : 0.f; | |
823 shield_widget_.reset(CreateBackgroundWidget( | |
824 root_window_, kShieldColor, 0, 0, SK_ColorTRANSPARENT, initial_opacity)); | |
797 | 825 |
798 WmWindow* widget_window = | 826 WmWindow* widget_window = |
799 WmLookup::Get()->GetWindowForWidget(shield_widget_.get()); | 827 WmLookup::Get()->GetWindowForWidget(shield_widget_.get()); |
800 const gfx::Rect bounds = widget_window->GetParent()->GetBounds(); | 828 const gfx::Rect bounds = widget_window->GetParent()->GetBounds(); |
801 widget_window->SetBounds(bounds); | 829 widget_window->SetBounds(bounds); |
802 | 830 |
803 ui::ScopedLayerAnimationSettings animation_settings( | 831 ui::ScopedLayerAnimationSettings animation_settings( |
804 widget_window->GetLayer()->GetAnimator()); | 832 widget_window->GetLayer()->GetAnimator()); |
805 animation_settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds( | 833 animation_settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds( |
806 kOverviewSelectorTransitionMilliseconds)); | 834 kOverviewSelectorTransitionMilliseconds)); |
807 animation_settings.SetTweenType(gfx::Tween::LINEAR_OUT_SLOW_IN); | 835 animation_settings.SetTweenType(gfx::Tween::LINEAR_OUT_SLOW_IN); |
808 animation_settings.SetPreemptionStrategy( | 836 animation_settings.SetPreemptionStrategy( |
809 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | 837 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); |
810 shield_widget_->SetOpacity(1.f); | 838 shield_widget_->SetOpacity(kShieldOpacity); |
811 } | 839 } |
812 | 840 |
813 void WindowGrid::InitSelectionWidget(WindowSelector::Direction direction) { | 841 void WindowGrid::InitSelectionWidget(WindowSelector::Direction direction) { |
814 const bool material = ash::MaterialDesignController::IsOverviewMaterial(); | 842 const bool material = ash::MaterialDesignController::IsOverviewMaterial(); |
815 const int border_thickness = material ? kWindowSelectionBorderThicknessMD | 843 const int border_thickness = material ? kWindowSelectionBorderThicknessMD |
816 : kWindowSelectionBorderThickness; | 844 : kWindowSelectionBorderThickness; |
817 const int border_color = | 845 const int border_color = |
818 material ? kWindowSelectionBorderColorMD : kWindowSelectionBorderColor; | 846 material ? kWindowSelectionBorderColorMD : kWindowSelectionBorderColor; |
819 const int selection_color = | 847 const int selection_color = |
820 material ? kWindowSelectionColorMD : kWindowSelectionColor; | 848 material ? kWindowSelectionColorMD : kWindowSelectionColor; |
821 const int border_radius = | 849 const int border_radius = |
822 material ? kWindowSelectionRadiusMD : kWindowSelectionRadius; | 850 material ? kWindowSelectionRadiusMD : kWindowSelectionRadius; |
823 selection_widget_.reset(CreateBackgroundWidget(root_window_, selection_color, | 851 selection_widget_.reset( |
824 border_thickness, | 852 CreateBackgroundWidget(root_window_, selection_color, border_thickness, |
825 border_radius, border_color)); | 853 border_radius, border_color, 0.f)); |
826 | 854 |
827 WmWindow* widget_window = | 855 WmWindow* widget_window = |
828 WmLookup::Get()->GetWindowForWidget(selection_widget_.get()); | 856 WmLookup::Get()->GetWindowForWidget(selection_widget_.get()); |
829 const gfx::Rect target_bounds = | 857 const gfx::Rect target_bounds = |
830 root_window_->ConvertRectFromScreen(SelectedWindow()->target_bounds()); | 858 root_window_->ConvertRectFromScreen(SelectedWindow()->target_bounds()); |
831 gfx::Vector2d fade_out_direction = | 859 gfx::Vector2d fade_out_direction = |
832 GetSlideVectorForFadeIn(direction, target_bounds); | 860 GetSlideVectorForFadeIn(direction, target_bounds); |
833 widget_window->SetBounds(target_bounds - fade_out_direction); | 861 widget_window->SetBounds(target_bounds - fade_out_direction); |
834 } | 862 } |
835 | 863 |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
961 *min_right = left; | 989 *min_right = left; |
962 if (*max_right < left) | 990 if (*max_right < left) |
963 *max_right = left; | 991 *max_right = left; |
964 } | 992 } |
965 *max_bottom = top + height; | 993 *max_bottom = top + height; |
966 } | 994 } |
967 return windows_fit; | 995 return windows_fit; |
968 } | 996 } |
969 | 997 |
970 } // namespace ash | 998 } // namespace ash |
OLD | NEW |