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

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

Issue 2726823003: Remove WmLookup. (Closed)
Patch Set: Remove wm_lookup. Created 3 years, 9 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>
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
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, &params); 247 widget, kShellWindowId_WallpaperContainer, &params);
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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 =
311 WmLookup::Get()->GetWindowForWidget(shield_widget_.get()); 310 WmWindow::Get(shield_widget_.get()->GetNativeWindow());
312 ui::ScopedLayerAnimationSettings animation_settings( 311 ui::ScopedLayerAnimationSettings animation_settings(
313 widget_window->GetLayer()->GetAnimator()); 312 widget_window->GetLayer()->GetAnimator());
314 animation_settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds( 313 animation_settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds(
315 kOverviewSelectorTransitionMilliseconds)); 314 kOverviewSelectorTransitionMilliseconds));
316 animation_settings.SetTweenType(gfx::Tween::EASE_OUT); 315 animation_settings.SetTweenType(gfx::Tween::EASE_OUT);
317 animation_settings.SetPreemptionStrategy( 316 animation_settings.SetPreemptionStrategy(
318 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); 317 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
319 // CleanupAnimationObserver will delete itself (and the shield widget) when 318 // CleanupAnimationObserver will delete itself (and the shield widget) when
320 // the opacity animation is complete. 319 // the opacity animation is complete.
321 // Ownership over the observer is passed to the window_selector_->delegate() 320 // Ownership over the observer is passed to the window_selector_->delegate()
(...skipping 15 matching lines...) Expand all
337 window->PrepareForOverview(); 336 window->PrepareForOverview();
338 prepared_for_overview_ = true; 337 prepared_for_overview_ = true;
339 } 338 }
340 339
341 void WindowGrid::PositionWindows(bool animate) { 340 void WindowGrid::PositionWindows(bool animate) {
342 if (window_selector_->is_shut_down() || window_list_.empty()) 341 if (window_selector_->is_shut_down() || window_list_.empty())
343 return; 342 return;
344 DCHECK(shield_widget_.get()); 343 DCHECK(shield_widget_.get());
345 // Keep the background shield widget covering the whole screen. 344 // Keep the background shield widget covering the whole screen.
346 WmWindow* widget_window = 345 WmWindow* widget_window =
347 WmLookup::Get()->GetWindowForWidget(shield_widget_.get()); 346 WmWindow::Get(shield_widget_.get()->GetNativeWindow());
348 const gfx::Rect bounds = widget_window->GetParent()->GetBounds(); 347 const gfx::Rect bounds = widget_window->GetParent()->GetBounds();
349 widget_window->SetBounds(bounds); 348 widget_window->SetBounds(bounds);
350 gfx::Rect total_bounds = 349 gfx::Rect total_bounds =
351 root_window_->ConvertRectToScreen(wm::GetDisplayWorkAreaBoundsInParent( 350 root_window_->ConvertRectToScreen(wm::GetDisplayWorkAreaBoundsInParent(
352 root_window_->GetChildByShellWindowId( 351 root_window_->GetChildByShellWindowId(
353 kShellWindowId_DefaultContainer))); 352 kShellWindowId_DefaultContainer)));
354 // Windows occupy vertically centered area with additional vertical insets. 353 // Windows occupy vertically centered area with additional vertical insets.
355 int horizontal_inset = 354 int horizontal_inset =
356 gfx::ToFlooredInt(std::min(kOverviewInsetRatio * total_bounds.width(), 355 gfx::ToFlooredInt(std::min(kOverviewInsetRatio * total_bounds.width(),
357 kOverviewInsetRatio * total_bounds.height())); 356 kOverviewInsetRatio * total_bounds.height()));
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
553 selector_shadow_.reset(); 552 selector_shadow_.reset();
554 } 553 }
555 } 554 }
556 } 555 }
557 } 556 }
558 557
559 void WindowGrid::WindowClosing(WindowSelectorItem* window) { 558 void WindowGrid::WindowClosing(WindowSelectorItem* window) {
560 if (!selection_widget_ || SelectedWindow() != window) 559 if (!selection_widget_ || SelectedWindow() != window)
561 return; 560 return;
562 WmWindow* selection_widget_window = 561 WmWindow* selection_widget_window =
563 WmLookup::Get()->GetWindowForWidget(selection_widget_.get()); 562 WmWindow::Get(selection_widget_.get()->GetNativeWindow());
564 std::unique_ptr<ScopedOverviewAnimationSettings> animation_settings_label = 563 std::unique_ptr<ScopedOverviewAnimationSettings> animation_settings_label =
565 ScopedOverviewAnimationSettingsFactory::Get() 564 ScopedOverviewAnimationSettingsFactory::Get()
566 ->CreateOverviewAnimationSettings( 565 ->CreateOverviewAnimationSettings(
567 OverviewAnimationType::OVERVIEW_ANIMATION_CLOSING_SELECTOR_ITEM, 566 OverviewAnimationType::OVERVIEW_ANIMATION_CLOSING_SELECTOR_ITEM,
568 selection_widget_window); 567 selection_widget_window);
569 selection_widget_->SetOpacity(0.f); 568 selection_widget_->SetOpacity(0.f);
570 } 569 }
571 570
572 void WindowGrid::OnWindowDestroying(aura::Window* window) { 571 void WindowGrid::OnWindowDestroying(aura::Window* window) {
573 window_observer_.Remove(window); 572 window_observer_.Remove(window);
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
646 // assumption is no longer valid. 645 // assumption is no longer valid.
647 const float initial_opacity = 646 const float initial_opacity =
648 (WmShelf::ForWindow(root_window_)->GetBackgroundType() == 647 (WmShelf::ForWindow(root_window_)->GetBackgroundType() ==
649 SHELF_BACKGROUND_MAXIMIZED) 648 SHELF_BACKGROUND_MAXIMIZED)
650 ? 1.f 649 ? 1.f
651 : 0.f; 650 : 0.f;
652 shield_widget_.reset( 651 shield_widget_.reset(
653 CreateBackgroundWidget(root_window_, ui::LAYER_SOLID_COLOR, kShieldColor, 652 CreateBackgroundWidget(root_window_, ui::LAYER_SOLID_COLOR, kShieldColor,
654 0, 0, SK_ColorTRANSPARENT, initial_opacity)); 653 0, 0, SK_ColorTRANSPARENT, initial_opacity));
655 WmWindow* widget_window = 654 WmWindow* widget_window =
656 WmLookup::Get()->GetWindowForWidget(shield_widget_.get()); 655 WmWindow::Get(shield_widget_.get()->GetNativeWindow());
657 const gfx::Rect bounds = widget_window->GetParent()->GetBounds(); 656 const gfx::Rect bounds = widget_window->GetParent()->GetBounds();
658 widget_window->SetBounds(bounds); 657 widget_window->SetBounds(bounds);
659 widget_window->SetName("OverviewModeShield"); 658 widget_window->SetName("OverviewModeShield");
660 659
661 ui::ScopedLayerAnimationSettings animation_settings( 660 ui::ScopedLayerAnimationSettings animation_settings(
662 widget_window->GetLayer()->GetAnimator()); 661 widget_window->GetLayer()->GetAnimator());
663 animation_settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds( 662 animation_settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds(
664 kOverviewSelectorTransitionMilliseconds)); 663 kOverviewSelectorTransitionMilliseconds));
665 animation_settings.SetTweenType(gfx::Tween::EASE_OUT); 664 animation_settings.SetTweenType(gfx::Tween::EASE_OUT);
666 animation_settings.SetPreemptionStrategy( 665 animation_settings.SetPreemptionStrategy(
667 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); 666 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
668 shield_widget_->SetOpacity(kShieldOpacity); 667 shield_widget_->SetOpacity(kShieldOpacity);
669 } 668 }
670 669
671 void WindowGrid::InitSelectionWidget(WindowSelector::Direction direction) { 670 void WindowGrid::InitSelectionWidget(WindowSelector::Direction direction) {
672 selection_widget_.reset(CreateBackgroundWidget( 671 selection_widget_.reset(CreateBackgroundWidget(
673 root_window_, ui::LAYER_TEXTURED, kWindowSelectionColor, 672 root_window_, ui::LAYER_TEXTURED, kWindowSelectionColor,
674 kWindowSelectionBorderThickness, kWindowSelectionRadius, 673 kWindowSelectionBorderThickness, kWindowSelectionRadius,
675 kWindowSelectionBorderColor, 0.f)); 674 kWindowSelectionBorderColor, 0.f));
676 WmWindow* widget_window = 675 WmWindow* widget_window =
677 WmLookup::Get()->GetWindowForWidget(selection_widget_.get()); 676 WmWindow::Get(selection_widget_.get()->GetNativeWindow());
678 const gfx::Rect target_bounds = 677 const gfx::Rect target_bounds =
679 root_window_->ConvertRectFromScreen(SelectedWindow()->target_bounds()); 678 root_window_->ConvertRectFromScreen(SelectedWindow()->target_bounds());
680 gfx::Vector2d fade_out_direction = 679 gfx::Vector2d fade_out_direction =
681 GetSlideVectorForFadeIn(direction, target_bounds); 680 GetSlideVectorForFadeIn(direction, target_bounds);
682 widget_window->SetBounds(target_bounds - fade_out_direction); 681 widget_window->SetBounds(target_bounds - fade_out_direction);
683 widget_window->SetName("OverviewModeSelector"); 682 widget_window->SetName("OverviewModeSelector");
684 683
685 selector_shadow_.reset(new ::wm::Shadow()); 684 selector_shadow_.reset(new ::wm::Shadow());
686 selector_shadow_->Init(::wm::ShadowElevation::LARGE); 685 selector_shadow_->Init(::wm::ShadowElevation::LARGE);
687 selector_shadow_->layer()->SetVisible(true); 686 selector_shadow_->layer()->SetVisible(true);
688 selection_widget_->GetLayer()->SetMasksToBounds(false); 687 selection_widget_->GetLayer()->SetMasksToBounds(false);
689 selection_widget_->GetLayer()->Add(selector_shadow_->layer()); 688 selection_widget_->GetLayer()->Add(selector_shadow_->layer());
690 selector_shadow_->SetContentBounds(gfx::Rect(target_bounds.size())); 689 selector_shadow_->SetContentBounds(gfx::Rect(target_bounds.size()));
691 } 690 }
692 691
693 void WindowGrid::MoveSelectionWidget(WindowSelector::Direction direction, 692 void WindowGrid::MoveSelectionWidget(WindowSelector::Direction direction,
694 bool recreate_selection_widget, 693 bool recreate_selection_widget,
695 bool out_of_bounds, 694 bool out_of_bounds,
696 bool animate) { 695 bool animate) {
697 // If the selection widget is already active, fade it out in the selection 696 // If the selection widget is already active, fade it out in the selection
698 // direction. 697 // direction.
699 if (selection_widget_ && (recreate_selection_widget || out_of_bounds)) { 698 if (selection_widget_ && (recreate_selection_widget || out_of_bounds)) {
700 // Animate the old selection widget and then destroy it. 699 // Animate the old selection widget and then destroy it.
701 views::Widget* old_selection = selection_widget_.get(); 700 views::Widget* old_selection = selection_widget_.get();
702 WmWindow* old_selection_window = 701 WmWindow* old_selection_window =
703 WmLookup::Get()->GetWindowForWidget(old_selection); 702 WmWindow::Get(old_selection->GetNativeWindow());
704 gfx::Vector2d fade_out_direction = 703 gfx::Vector2d fade_out_direction =
705 GetSlideVectorForFadeIn(direction, old_selection_window->GetBounds()); 704 GetSlideVectorForFadeIn(direction, old_selection_window->GetBounds());
706 705
707 ui::ScopedLayerAnimationSettings animation_settings( 706 ui::ScopedLayerAnimationSettings animation_settings(
708 old_selection_window->GetLayer()->GetAnimator()); 707 old_selection_window->GetLayer()->GetAnimator());
709 animation_settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds( 708 animation_settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds(
710 kOverviewSelectorTransitionMilliseconds)); 709 kOverviewSelectorTransitionMilliseconds));
711 animation_settings.SetPreemptionStrategy( 710 animation_settings.SetPreemptionStrategy(
712 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); 711 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
713 animation_settings.SetTweenType(gfx::Tween::FAST_OUT_LINEAR_IN); 712 animation_settings.SetTweenType(gfx::Tween::FAST_OUT_LINEAR_IN);
(...skipping 23 matching lines...) Expand all
737 // The selection widget is moved to the newly selected item in the same 736 // The selection widget is moved to the newly selected item in the same
738 // grid. 737 // grid.
739 MoveSelectionWidgetToTarget(animate); 738 MoveSelectionWidgetToTarget(animate);
740 } 739 }
741 740
742 void WindowGrid::MoveSelectionWidgetToTarget(bool animate) { 741 void WindowGrid::MoveSelectionWidgetToTarget(bool animate) {
743 gfx::Rect bounds = 742 gfx::Rect bounds =
744 root_window_->ConvertRectFromScreen(SelectedWindow()->target_bounds()); 743 root_window_->ConvertRectFromScreen(SelectedWindow()->target_bounds());
745 if (animate) { 744 if (animate) {
746 WmWindow* selection_widget_window = 745 WmWindow* selection_widget_window =
747 WmLookup::Get()->GetWindowForWidget(selection_widget_.get()); 746 WmWindow::Get(selection_widget_.get()->GetNativeWindow());
748 ui::ScopedLayerAnimationSettings animation_settings( 747 ui::ScopedLayerAnimationSettings animation_settings(
749 selection_widget_window->GetLayer()->GetAnimator()); 748 selection_widget_window->GetLayer()->GetAnimator());
750 animation_settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds( 749 animation_settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds(
751 kOverviewSelectorTransitionMilliseconds)); 750 kOverviewSelectorTransitionMilliseconds));
752 animation_settings.SetTweenType(gfx::Tween::EASE_IN_OUT); 751 animation_settings.SetTweenType(gfx::Tween::EASE_IN_OUT);
753 animation_settings.SetPreemptionStrategy( 752 animation_settings.SetPreemptionStrategy(
754 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); 753 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
755 selection_widget_->SetBounds(bounds); 754 selection_widget_->SetBounds(bounds);
756 selection_widget_->SetOpacity(1.f); 755 selection_widget_->SetOpacity(1.f);
757 756
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
840 *min_right = left; 839 *min_right = left;
841 if (*max_right < left) 840 if (*max_right < left)
842 *max_right = left; 841 *max_right = left;
843 } 842 }
844 *max_bottom = top + height; 843 *max_bottom = top + height;
845 } 844 }
846 return windows_fit; 845 return windows_fit;
847 } 846 }
848 847
849 } // namespace ash 848 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698