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

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

Issue 2087153003: Moves common code in ash/wm/overview to ash/common/wm/overview (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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
« no previous file with comments | « ash/common/wm/overview/window_grid.h ('k') | ash/common/wm/overview/window_selector.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/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/shell_window_ids.h" 15 #include "ash/common/shell_window_ids.h"
16 #include "ash/common/wm/overview/scoped_transform_overview_window.h"
17 #include "ash/common/wm/overview/window_selector.h"
18 #include "ash/common/wm/overview/window_selector_item.h"
16 #include "ash/common/wm/window_state.h" 19 #include "ash/common/wm/window_state.h"
17 #include "ash/common/wm/wm_screen_util.h" 20 #include "ash/common/wm/wm_screen_util.h"
18 #include "ash/common/wm_lookup.h" 21 #include "ash/common/wm_lookup.h"
19 #include "ash/common/wm_root_window_controller.h" 22 #include "ash/common/wm_root_window_controller.h"
20 #include "ash/common/wm_window.h" 23 #include "ash/common/wm_window.h"
21 #include "ash/wm/overview/scoped_transform_overview_window.h"
22 #include "ash/wm/overview/window_selector.h"
23 #include "ash/wm/overview/window_selector_item.h"
24 #include "base/command_line.h" 24 #include "base/command_line.h"
25 #include "base/i18n/string_search.h" 25 #include "base/i18n/string_search.h"
26 #include "base/memory/scoped_vector.h" 26 #include "base/memory/scoped_vector.h"
27 #include "third_party/skia/include/core/SkColor.h" 27 #include "third_party/skia/include/core/SkColor.h"
28 #include "third_party/skia/include/pathops/SkPathOps.h" 28 #include "third_party/skia/include/pathops/SkPathOps.h"
29 #include "ui/compositor/layer_animation_observer.h" 29 #include "ui/compositor/layer_animation_observer.h"
30 #include "ui/compositor/scoped_layer_animation_settings.h" 30 #include "ui/compositor/scoped_layer_animation_settings.h"
31 #include "ui/gfx/animation/tween.h" 31 #include "ui/gfx/animation/tween.h"
32 #include "ui/gfx/canvas.h" 32 #include "ui/gfx/canvas.h"
33 #include "ui/gfx/geometry/safe_integer_conversions.h" 33 #include "ui/gfx/geometry/safe_integer_conversions.h"
(...skipping 26 matching lines...) Expand all
60 private: 60 private:
61 std::unique_ptr<views::Widget> widget_; 61 std::unique_ptr<views::Widget> widget_;
62 62
63 DISALLOW_COPY_AND_ASSIGN(CleanupWidgetAfterAnimationObserver); 63 DISALLOW_COPY_AND_ASSIGN(CleanupWidgetAfterAnimationObserver);
64 }; 64 };
65 65
66 CleanupWidgetAfterAnimationObserver::CleanupWidgetAfterAnimationObserver( 66 CleanupWidgetAfterAnimationObserver::CleanupWidgetAfterAnimationObserver(
67 std::unique_ptr<views::Widget> widget) 67 std::unique_ptr<views::Widget> widget)
68 : widget_(std::move(widget)) {} 68 : widget_(std::move(widget)) {}
69 69
70 CleanupWidgetAfterAnimationObserver::~CleanupWidgetAfterAnimationObserver() { 70 CleanupWidgetAfterAnimationObserver::~CleanupWidgetAfterAnimationObserver() {}
71 }
72 71
73 void CleanupWidgetAfterAnimationObserver::OnImplicitAnimationsCompleted() { 72 void CleanupWidgetAfterAnimationObserver::OnImplicitAnimationsCompleted() {
74 delete this; 73 delete this;
75 } 74 }
76 75
77 // A comparator for locating a given target window. 76 // A comparator for locating a given target window.
78 struct WindowSelectorItemComparator { 77 struct WindowSelectorItemComparator {
79 explicit WindowSelectorItemComparator(const WmWindow* target_window) 78 explicit WindowSelectorItemComparator(const WmWindow* target_window)
80 : target(target_window) {} 79 : target(target_window) {}
81 80
(...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after
589 &item_size); 588 &item_size);
590 num_columns_ = std::min(static_cast<int>(window_list_.size()), 589 num_columns_ = std::min(static_cast<int>(window_list_.size()),
591 bounding_rect.width() / item_size.width()); 590 bounding_rect.width() / item_size.width());
592 for (size_t i = 0; i < window_list_.size(); ++i) { 591 for (size_t i = 0; i < window_list_.size(); ++i) {
593 gfx::Transform transform; 592 gfx::Transform transform;
594 int column = i % num_columns_; 593 int column = i % num_columns_;
595 int row = i / num_columns_; 594 int row = i / num_columns_;
596 gfx::Rect target_bounds(item_size.width() * column + bounding_rect.x(), 595 gfx::Rect target_bounds(item_size.width() * column + bounding_rect.x(),
597 item_size.height() * row + bounding_rect.y(), 596 item_size.height() * row + bounding_rect.y(),
598 item_size.width(), item_size.height()); 597 item_size.width(), item_size.height());
599 window_list_[i]->SetBounds(target_bounds, animate ? 598 window_list_[i]->SetBounds(
600 OverviewAnimationType::OVERVIEW_ANIMATION_LAY_OUT_SELECTOR_ITEMS : 599 target_bounds,
601 OverviewAnimationType::OVERVIEW_ANIMATION_NONE); 600 animate
601 ? OverviewAnimationType::OVERVIEW_ANIMATION_LAY_OUT_SELECTOR_ITEMS
602 : OverviewAnimationType::OVERVIEW_ANIMATION_NONE);
602 } 603 }
603 604
604 // If the selection widget is active, reposition it without any animation. 605 // If the selection widget is active, reposition it without any animation.
605 if (selection_widget_) 606 if (selection_widget_)
606 MoveSelectionWidgetToTarget(animate); 607 MoveSelectionWidgetToTarget(animate);
607 } 608 }
608 609
609 bool WindowGrid::Move(WindowSelector::Direction direction, bool animate) { 610 bool WindowGrid::Move(WindowSelector::Direction direction, bool animate) {
610 bool recreate_selection_widget = false; 611 bool recreate_selection_widget = false;
611 bool out_of_bounds = false; 612 bool out_of_bounds = false;
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
684 } 685 }
685 if (material) { 686 if (material) {
686 if (!out_of_bounds && SelectedWindow()) { 687 if (!out_of_bounds && SelectedWindow()) {
687 if (SelectedWindow()->target_bounds().y() != old_bounds.y()) 688 if (SelectedWindow()->target_bounds().y() != old_bounds.y())
688 recreate_selection_widget = true; 689 recreate_selection_widget = true;
689 } 690 }
690 } 691 }
691 changed_selection_index = true; 692 changed_selection_index = true;
692 } 693 }
693 694
694 MoveSelectionWidget(direction, recreate_selection_widget, 695 MoveSelectionWidget(direction, recreate_selection_widget, out_of_bounds,
695 out_of_bounds, animate); 696 animate);
696 697
697 // Make the new selected window header fully transparent. 698 // Make the new selected window header fully transparent.
698 if (SelectedWindow()) 699 if (SelectedWindow())
699 SelectedWindow()->SetSelected(true); 700 SelectedWindow()->SetSelected(true);
700 return out_of_bounds; 701 return out_of_bounds;
701 } 702 }
702 703
703 WindowSelectorItem* WindowGrid::SelectedWindow() const { 704 WindowSelectorItem* WindowGrid::SelectedWindow() const {
704 if (!selection_widget_) 705 if (!selection_widget_)
705 return nullptr; 706 return nullptr;
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
806 material ? kWindowSelectionRadiusMD : kWindowSelectionRadius; 807 material ? kWindowSelectionRadiusMD : kWindowSelectionRadius;
807 selection_widget_.reset(CreateBackgroundWidget(root_window_, selection_color, 808 selection_widget_.reset(CreateBackgroundWidget(root_window_, selection_color,
808 border_thickness, 809 border_thickness,
809 border_radius, border_color)); 810 border_radius, border_color));
810 811
811 WmWindow* widget_window = 812 WmWindow* widget_window =
812 WmLookup::Get()->GetWindowForWidget(selection_widget_.get()); 813 WmLookup::Get()->GetWindowForWidget(selection_widget_.get());
813 const gfx::Rect target_bounds = 814 const gfx::Rect target_bounds =
814 root_window_->ConvertRectFromScreen(SelectedWindow()->target_bounds()); 815 root_window_->ConvertRectFromScreen(SelectedWindow()->target_bounds());
815 gfx::Vector2d fade_out_direction = 816 gfx::Vector2d fade_out_direction =
816 GetSlideVectorForFadeIn(direction, target_bounds); 817 GetSlideVectorForFadeIn(direction, target_bounds);
817 widget_window->SetBounds(target_bounds - fade_out_direction); 818 widget_window->SetBounds(target_bounds - fade_out_direction);
818 } 819 }
819 820
820 void WindowGrid::MoveSelectionWidget(WindowSelector::Direction direction, 821 void WindowGrid::MoveSelectionWidget(WindowSelector::Direction direction,
821 bool recreate_selection_widget, 822 bool recreate_selection_widget,
822 bool out_of_bounds, 823 bool out_of_bounds,
823 bool animate) { 824 bool animate) {
824 // If the selection widget is already active, fade it out in the selection 825 // If the selection widget is already active, fade it out in the selection
825 // direction. 826 // direction.
826 if (selection_widget_ && (recreate_selection_widget || out_of_bounds)) { 827 if (selection_widget_ && (recreate_selection_widget || out_of_bounds)) {
827 // Animate the old selection widget and then destroy it. 828 // Animate the old selection widget and then destroy it.
828 views::Widget* old_selection = selection_widget_.get(); 829 views::Widget* old_selection = selection_widget_.get();
829 WmWindow* old_selection_window = 830 WmWindow* old_selection_window =
830 WmLookup::Get()->GetWindowForWidget(old_selection); 831 WmLookup::Get()->GetWindowForWidget(old_selection);
831 gfx::Vector2d fade_out_direction = 832 gfx::Vector2d fade_out_direction =
832 GetSlideVectorForFadeIn(direction, old_selection_window->GetBounds()); 833 GetSlideVectorForFadeIn(direction, old_selection_window->GetBounds());
833 834
834 ui::ScopedLayerAnimationSettings animation_settings( 835 ui::ScopedLayerAnimationSettings animation_settings(
835 old_selection_window->GetLayer()->GetAnimator()); 836 old_selection_window->GetLayer()->GetAnimator());
836 animation_settings.SetTransitionDuration( 837 animation_settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds(
837 base::TimeDelta::FromMilliseconds( 838 kOverviewSelectorTransitionMilliseconds));
838 kOverviewSelectorTransitionMilliseconds));
839 animation_settings.SetPreemptionStrategy( 839 animation_settings.SetPreemptionStrategy(
840 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); 840 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
841 animation_settings.SetTweenType(gfx::Tween::FAST_OUT_LINEAR_IN); 841 animation_settings.SetTweenType(gfx::Tween::FAST_OUT_LINEAR_IN);
842 // CleanupWidgetAfterAnimationObserver will delete itself (and the 842 // CleanupWidgetAfterAnimationObserver will delete itself (and the
843 // widget) when the movement animation is complete. 843 // widget) when the movement animation is complete.
844 animation_settings.AddObserver( 844 animation_settings.AddObserver(
845 new CleanupWidgetAfterAnimationObserver(std::move(selection_widget_))); 845 new CleanupWidgetAfterAnimationObserver(std::move(selection_widget_)));
846 old_selection->SetOpacity(0.f); 846 old_selection->SetOpacity(0.f);
847 old_selection_window->SetBounds(old_selection_window->GetBounds() + 847 old_selection_window->SetBounds(old_selection_window->GetBounds() +
848 fade_out_direction); 848 fade_out_direction);
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
945 *min_right = left; 945 *min_right = left;
946 if (*max_right < left) 946 if (*max_right < left)
947 *max_right = left; 947 *max_right = left;
948 } 948 }
949 *max_bottom = top + height; 949 *max_bottom = top + height;
950 } 950 }
951 return windows_fit; 951 return windows_fit;
952 } 952 }
953 953
954 } // namespace ash 954 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/wm/overview/window_grid.h ('k') | ash/common/wm/overview/window_selector.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698