| 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 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 new RoundedRectView(border_radius, SK_ColorTRANSPARENT); | 255 new RoundedRectView(border_radius, SK_ColorTRANSPARENT); |
| 256 content_view->set_background(new BackgroundWith1PxBorder( | 256 content_view->set_background(new BackgroundWith1PxBorder( |
| 257 background_color, border_color, border_thickness, border_radius)); | 257 background_color, border_color, border_thickness, border_radius)); |
| 258 widget->SetContentsView(content_view); | 258 widget->SetContentsView(content_view); |
| 259 widget_window->GetParent()->StackChildAtTop(widget_window); | 259 widget_window->GetParent()->StackChildAtTop(widget_window); |
| 260 widget->Show(); | 260 widget->Show(); |
| 261 widget_window->SetOpacity(initial_opacity); | 261 widget_window->SetOpacity(initial_opacity); |
| 262 return widget; | 262 return widget; |
| 263 } | 263 } |
| 264 | 264 |
| 265 bool IsMinimizedStateType(wm::WindowStateType type) { |
| 266 return type == wm::WINDOW_STATE_TYPE_DOCKED_MINIMIZED || |
| 267 type == wm::WINDOW_STATE_TYPE_MINIMIZED; |
| 268 } |
| 269 |
| 265 } // namespace | 270 } // namespace |
| 266 | 271 |
| 267 WindowGrid::WindowGrid(WmWindow* root_window, | 272 WindowGrid::WindowGrid(WmWindow* root_window, |
| 268 const std::vector<WmWindow*>& windows, | 273 const std::vector<WmWindow*>& windows, |
| 269 WindowSelector* window_selector) | 274 WindowSelector* window_selector) |
| 270 : root_window_(root_window), | 275 : root_window_(root_window), |
| 271 window_selector_(window_selector), | 276 window_selector_(window_selector), |
| 272 window_observer_(this), | 277 window_observer_(this), |
| 278 window_state_observer_(this), |
| 273 selected_index_(0), | 279 selected_index_(0), |
| 274 num_columns_(0), | 280 num_columns_(0), |
| 275 prepared_for_overview_(false) { | 281 prepared_for_overview_(false) { |
| 276 std::vector<WmWindow*> windows_in_root; | 282 std::vector<WmWindow*> windows_in_root; |
| 277 for (auto* window : windows) { | 283 for (auto* window : windows) { |
| 278 if (window->GetRootWindow() == root_window) | 284 if (window->GetRootWindow() == root_window) |
| 279 windows_in_root.push_back(window); | 285 windows_in_root.push_back(window); |
| 280 } | 286 } |
| 281 | 287 |
| 282 for (auto* window : windows_in_root) { | 288 for (auto* window : windows_in_root) { |
| 283 window_observer_.Add(window); | 289 window_observer_.Add(window); |
| 290 window_state_observer_.Add(window->GetWindowState()); |
| 284 window_list_.push_back(new WindowSelectorItem(window, window_selector_)); | 291 window_list_.push_back(new WindowSelectorItem(window, window_selector_)); |
| 285 } | 292 } |
| 286 } | 293 } |
| 287 | 294 |
| 288 WindowGrid::~WindowGrid() {} | 295 WindowGrid::~WindowGrid() {} |
| 289 | 296 |
| 290 void WindowGrid::Shutdown() { | 297 void WindowGrid::Shutdown() { |
| 291 for (auto iter = window_list_.begin(); iter != window_list_.end(); ++iter) | 298 for (auto iter = window_list_.begin(); iter != window_list_.end(); ++iter) |
| 292 (*iter)->Shutdown(); | 299 (*iter)->Shutdown(); |
| 293 | 300 |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 551 std::unique_ptr<ScopedOverviewAnimationSettings> animation_settings_label = | 558 std::unique_ptr<ScopedOverviewAnimationSettings> animation_settings_label = |
| 552 ScopedOverviewAnimationSettingsFactory::Get() | 559 ScopedOverviewAnimationSettingsFactory::Get() |
| 553 ->CreateOverviewAnimationSettings( | 560 ->CreateOverviewAnimationSettings( |
| 554 OverviewAnimationType::OVERVIEW_ANIMATION_CLOSING_SELECTOR_ITEM, | 561 OverviewAnimationType::OVERVIEW_ANIMATION_CLOSING_SELECTOR_ITEM, |
| 555 selection_widget_window); | 562 selection_widget_window); |
| 556 selection_widget_->SetOpacity(0.f); | 563 selection_widget_->SetOpacity(0.f); |
| 557 } | 564 } |
| 558 | 565 |
| 559 void WindowGrid::OnWindowDestroying(WmWindow* window) { | 566 void WindowGrid::OnWindowDestroying(WmWindow* window) { |
| 560 window_observer_.Remove(window); | 567 window_observer_.Remove(window); |
| 568 window_state_observer_.Remove(window->GetWindowState()); |
| 561 ScopedVector<WindowSelectorItem>::iterator iter = | 569 ScopedVector<WindowSelectorItem>::iterator iter = |
| 562 std::find_if(window_list_.begin(), window_list_.end(), | 570 std::find_if(window_list_.begin(), window_list_.end(), |
| 563 WindowSelectorItemComparator(window)); | 571 WindowSelectorItemComparator(window)); |
| 564 | 572 |
| 565 DCHECK(iter != window_list_.end()); | 573 DCHECK(iter != window_list_.end()); |
| 566 | 574 |
| 567 size_t removed_index = iter - window_list_.begin(); | 575 size_t removed_index = iter - window_list_.begin(); |
| 568 window_list_.erase(iter); | 576 window_list_.erase(iter); |
| 569 | 577 |
| 570 if (empty()) { | 578 if (empty()) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 583 if (send_focus_alert) | 591 if (send_focus_alert) |
| 584 SelectedWindow()->SendAccessibleSelectionEvent(); | 592 SelectedWindow()->SendAccessibleSelectionEvent(); |
| 585 } | 593 } |
| 586 | 594 |
| 587 PositionWindows(true); | 595 PositionWindows(true); |
| 588 } | 596 } |
| 589 | 597 |
| 590 void WindowGrid::OnWindowBoundsChanged(WmWindow* window, | 598 void WindowGrid::OnWindowBoundsChanged(WmWindow* window, |
| 591 const gfx::Rect& old_bounds, | 599 const gfx::Rect& old_bounds, |
| 592 const gfx::Rect& new_bounds) { | 600 const gfx::Rect& new_bounds) { |
| 593 // During preparation, window bounds can change (e.g. by unminimizing a | 601 // During preparation, window bounds can change. Ignore bounds |
| 594 // window). Ignore bounds change notifications in this case; we'll reposition | 602 // change notifications in this case; we'll reposition soon. |
| 595 // soon. | |
| 596 if (!prepared_for_overview_) | 603 if (!prepared_for_overview_) |
| 597 return; | 604 return; |
| 598 | 605 |
| 599 auto iter = std::find_if(window_list_.begin(), window_list_.end(), | 606 auto iter = std::find_if(window_list_.begin(), window_list_.end(), |
| 600 WindowSelectorItemComparator(window)); | 607 WindowSelectorItemComparator(window)); |
| 601 DCHECK(iter != window_list_.end()); | 608 DCHECK(iter != window_list_.end()); |
| 602 | 609 |
| 603 // Immediately finish any active bounds animation. | 610 // Immediately finish any active bounds animation. |
| 604 window->StopAnimatingProperty(ui::LayerAnimationElement::BOUNDS); | 611 window->StopAnimatingProperty(ui::LayerAnimationElement::BOUNDS); |
| 605 PositionWindows(false); | 612 PositionWindows(false); |
| 606 } | 613 } |
| 607 | 614 |
| 615 void WindowGrid::OnPostWindowStateTypeChange(wm::WindowState* window_state, |
| 616 wm::WindowStateType old_type) { |
| 617 // During preparation, window state can change, e.g. updating shelf |
| 618 // visibility may show the temporarily hidden (minimized) panels. |
| 619 if (!prepared_for_overview_) |
| 620 return; |
| 621 |
| 622 wm::WindowStateType new_type = window_state->GetStateType(); |
| 623 if (IsMinimizedStateType(old_type) == IsMinimizedStateType(new_type)) |
| 624 return; |
| 625 |
| 626 auto iter = std::find_if(window_list_.begin(), window_list_.end(), |
| 627 [window_state](WindowSelectorItem* item) { |
| 628 return item->Contains(window_state->window()); |
| 629 }); |
| 630 if (iter != window_list_.end()) { |
| 631 (*iter)->OnMinimizedStateChanged(); |
| 632 PositionWindows(false); |
| 633 } |
| 634 } |
| 635 |
| 608 void WindowGrid::InitShieldWidget() { | 636 void WindowGrid::InitShieldWidget() { |
| 609 // TODO(varkha): The code assumes that SHELF_BACKGROUND_MAXIMIZED is | 637 // TODO(varkha): The code assumes that SHELF_BACKGROUND_MAXIMIZED is |
| 610 // synonymous with a black shelf background. Update this code if that | 638 // synonymous with a black shelf background. Update this code if that |
| 611 // assumption is no longer valid. | 639 // assumption is no longer valid. |
| 612 const float initial_opacity = | 640 const float initial_opacity = |
| 613 (WmShelf::ForWindow(root_window_)->GetBackgroundType() == | 641 (WmShelf::ForWindow(root_window_)->GetBackgroundType() == |
| 614 SHELF_BACKGROUND_MAXIMIZED) | 642 SHELF_BACKGROUND_MAXIMIZED) |
| 615 ? 1.f | 643 ? 1.f |
| 616 : 0.f; | 644 : 0.f; |
| 617 shield_widget_.reset(CreateBackgroundWidget( | 645 shield_widget_.reset(CreateBackgroundWidget( |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 804 *min_right = left; | 832 *min_right = left; |
| 805 if (*max_right < left) | 833 if (*max_right < left) |
| 806 *max_right = left; | 834 *max_right = left; |
| 807 } | 835 } |
| 808 *max_bottom = top + height; | 836 *max_bottom = top + height; |
| 809 } | 837 } |
| 810 return windows_fit; | 838 return windows_fit; |
| 811 } | 839 } |
| 812 | 840 |
| 813 } // namespace ash | 841 } // namespace ash |
| OLD | NEW |