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 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 return widget; | 385 return widget; |
386 } | 386 } |
387 | 387 |
388 } // namespace | 388 } // namespace |
389 | 389 |
390 WindowGrid::WindowGrid(WmWindow* root_window, | 390 WindowGrid::WindowGrid(WmWindow* root_window, |
391 const std::vector<WmWindow*>& windows, | 391 const std::vector<WmWindow*>& windows, |
392 WindowSelector* window_selector) | 392 WindowSelector* window_selector) |
393 : root_window_(root_window), | 393 : root_window_(root_window), |
394 window_selector_(window_selector), | 394 window_selector_(window_selector), |
| 395 window_observer_(this), |
395 selected_index_(0), | 396 selected_index_(0), |
396 num_columns_(0) { | 397 num_columns_(0), |
| 398 prepared_for_overview_(false) { |
397 std::vector<WmWindow*> windows_in_root; | 399 std::vector<WmWindow*> windows_in_root; |
398 for (auto* window : windows) { | 400 for (auto* window : windows) { |
399 if (window->GetRootWindow() == root_window) | 401 if (window->GetRootWindow() == root_window) |
400 windows_in_root.push_back(window); | 402 windows_in_root.push_back(window); |
401 } | 403 } |
402 | 404 |
403 if (!ash::MaterialDesignController::IsOverviewMaterial() && | 405 if (!ash::MaterialDesignController::IsOverviewMaterial() && |
404 base::CommandLine::ForCurrentProcess()->HasSwitch( | 406 base::CommandLine::ForCurrentProcess()->HasSwitch( |
405 switches::kAshEnableStableOverviewOrder)) { | 407 switches::kAshEnableStableOverviewOrder)) { |
406 // Reorder windows to try to minimize movement to target overview positions. | 408 // Reorder windows to try to minimize movement to target overview positions. |
407 // This also creates a stable window ordering. | 409 // This also creates a stable window ordering. |
408 ReorderItemsGreedyLeastMovement(&windows_in_root, root_window_, | 410 ReorderItemsGreedyLeastMovement(&windows_in_root, root_window_, |
409 window_selector_->text_filter_bottom()); | 411 window_selector_->text_filter_bottom()); |
410 } | 412 } |
411 for (auto* window : windows_in_root) { | 413 for (auto* window : windows_in_root) { |
412 window->AddObserver(this); | 414 window_observer_.Add(window); |
413 observed_windows_.insert(window); | |
414 window_list_.push_back(new WindowSelectorItem(window, window_selector_)); | 415 window_list_.push_back(new WindowSelectorItem(window, window_selector_)); |
415 } | 416 } |
416 } | 417 } |
417 | 418 |
418 WindowGrid::~WindowGrid() { | 419 WindowGrid::~WindowGrid() {} |
419 for (WmWindow* window : observed_windows_) | |
420 window->RemoveObserver(this); | |
421 } | |
422 | 420 |
423 void WindowGrid::Shutdown() { | 421 void WindowGrid::Shutdown() { |
424 if (shield_widget_) { | 422 if (shield_widget_) { |
425 // Fade out the shield widget. This animation continues past the lifetime | 423 // Fade out the shield widget. This animation continues past the lifetime |
426 // of |this|. | 424 // of |this|. |
427 WmWindow* widget_window = | 425 WmWindow* widget_window = |
428 WmLookup::Get()->GetWindowForWidget(shield_widget_.get()); | 426 WmLookup::Get()->GetWindowForWidget(shield_widget_.get()); |
429 ui::ScopedLayerAnimationSettings animation_settings( | 427 ui::ScopedLayerAnimationSettings animation_settings( |
430 widget_window->GetLayer()->GetAnimator()); | 428 widget_window->GetLayer()->GetAnimator()); |
431 animation_settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds( | 429 animation_settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds( |
(...skipping 14 matching lines...) Expand all Loading... |
446 std::move(observer)); | 444 std::move(observer)); |
447 shield_widget->SetOpacity(0.f); | 445 shield_widget->SetOpacity(0.f); |
448 } | 446 } |
449 } | 447 } |
450 | 448 |
451 void WindowGrid::PrepareForOverview() { | 449 void WindowGrid::PrepareForOverview() { |
452 if (ash::MaterialDesignController::IsOverviewMaterial()) | 450 if (ash::MaterialDesignController::IsOverviewMaterial()) |
453 InitShieldWidget(); | 451 InitShieldWidget(); |
454 for (auto iter = window_list_.begin(); iter != window_list_.end(); ++iter) | 452 for (auto iter = window_list_.begin(); iter != window_list_.end(); ++iter) |
455 (*iter)->PrepareForOverview(); | 453 (*iter)->PrepareForOverview(); |
| 454 prepared_for_overview_ = true; |
456 } | 455 } |
457 | 456 |
458 void WindowGrid::PositionWindowsMD(bool animate) { | 457 void WindowGrid::PositionWindowsMD(bool animate) { |
459 if (window_list_.empty()) | 458 if (window_list_.empty()) |
460 return; | 459 return; |
461 | 460 |
462 const int kUnlimited = -1; | 461 const int kUnlimited = -1; |
463 const size_t windows_count = window_list_.size(); | 462 const size_t windows_count = window_list_.size(); |
464 const base::CommandLine* command_line = | 463 const base::CommandLine* command_line = |
465 base::CommandLine::ForCurrentProcess(); | 464 base::CommandLine::ForCurrentProcess(); |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
780 WmLookup::Get()->GetWindowForWidget(selection_widget_.get()); | 779 WmLookup::Get()->GetWindowForWidget(selection_widget_.get()); |
781 std::unique_ptr<ScopedOverviewAnimationSettings> animation_settings_label = | 780 std::unique_ptr<ScopedOverviewAnimationSettings> animation_settings_label = |
782 ScopedOverviewAnimationSettingsFactory::Get() | 781 ScopedOverviewAnimationSettingsFactory::Get() |
783 ->CreateOverviewAnimationSettings( | 782 ->CreateOverviewAnimationSettings( |
784 OverviewAnimationType::OVERVIEW_ANIMATION_CLOSING_SELECTOR_ITEM, | 783 OverviewAnimationType::OVERVIEW_ANIMATION_CLOSING_SELECTOR_ITEM, |
785 selection_widget_window); | 784 selection_widget_window); |
786 selection_widget_->SetOpacity(0.f); | 785 selection_widget_->SetOpacity(0.f); |
787 } | 786 } |
788 | 787 |
789 void WindowGrid::OnWindowDestroying(WmWindow* window) { | 788 void WindowGrid::OnWindowDestroying(WmWindow* window) { |
790 window->RemoveObserver(this); | 789 window_observer_.Remove(window); |
791 observed_windows_.erase(window); | |
792 ScopedVector<WindowSelectorItem>::iterator iter = | 790 ScopedVector<WindowSelectorItem>::iterator iter = |
793 std::find_if(window_list_.begin(), window_list_.end(), | 791 std::find_if(window_list_.begin(), window_list_.end(), |
794 WindowSelectorItemComparator(window)); | 792 WindowSelectorItemComparator(window)); |
795 | 793 |
796 DCHECK(iter != window_list_.end()); | 794 DCHECK(iter != window_list_.end()); |
797 | 795 |
798 size_t removed_index = iter - window_list_.begin(); | 796 size_t removed_index = iter - window_list_.begin(); |
799 window_list_.erase(iter); | 797 window_list_.erase(iter); |
800 | 798 |
801 if (empty()) { | 799 if (empty()) { |
(...skipping 12 matching lines...) Expand all Loading... |
814 if (send_focus_alert) | 812 if (send_focus_alert) |
815 SelectedWindow()->SendAccessibleSelectionEvent(); | 813 SelectedWindow()->SendAccessibleSelectionEvent(); |
816 } | 814 } |
817 | 815 |
818 PositionWindows(true); | 816 PositionWindows(true); |
819 } | 817 } |
820 | 818 |
821 void WindowGrid::OnWindowBoundsChanged(WmWindow* window, | 819 void WindowGrid::OnWindowBoundsChanged(WmWindow* window, |
822 const gfx::Rect& old_bounds, | 820 const gfx::Rect& old_bounds, |
823 const gfx::Rect& new_bounds) { | 821 const gfx::Rect& new_bounds) { |
| 822 // During preparation, window bounds can change (e.g. by unminimizing a |
| 823 // window). Ignore bounds change notifications in this case; we'll reposition |
| 824 // soon. |
| 825 if (!prepared_for_overview_) |
| 826 return; |
| 827 |
824 auto iter = std::find_if(window_list_.begin(), window_list_.end(), | 828 auto iter = std::find_if(window_list_.begin(), window_list_.end(), |
825 WindowSelectorItemComparator(window)); | 829 WindowSelectorItemComparator(window)); |
826 DCHECK(iter != window_list_.end()); | 830 DCHECK(iter != window_list_.end()); |
827 | 831 |
828 // Immediately finish any active bounds animation. | 832 // Immediately finish any active bounds animation. |
829 window->StopAnimatingProperty(ui::LayerAnimationElement::BOUNDS); | 833 window->StopAnimatingProperty(ui::LayerAnimationElement::BOUNDS); |
830 | 834 |
831 if (ash::MaterialDesignController::IsOverviewMaterial()) { | 835 if (ash::MaterialDesignController::IsOverviewMaterial()) { |
832 PositionWindows(false); | 836 PositionWindows(false); |
833 return; | 837 return; |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1051 *min_right = left; | 1055 *min_right = left; |
1052 if (*max_right < left) | 1056 if (*max_right < left) |
1053 *max_right = left; | 1057 *max_right = left; |
1054 } | 1058 } |
1055 *max_bottom = top + height; | 1059 *max_bottom = top + height; |
1056 } | 1060 } |
1057 return windows_fit; | 1061 return windows_fit; |
1058 } | 1062 } |
1059 | 1063 |
1060 } // namespace ash | 1064 } // namespace ash |
OLD | NEW |