| 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/wm/overview/window_grid.h" | 5 #include "ash/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 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 } | 250 } |
| 251 | 251 |
| 252 bool IsMinimizedStateType(wm::WindowStateType type) { | 252 bool IsMinimizedStateType(wm::WindowStateType type) { |
| 253 return type == wm::WINDOW_STATE_TYPE_MINIMIZED; | 253 return type == wm::WINDOW_STATE_TYPE_MINIMIZED; |
| 254 } | 254 } |
| 255 | 255 |
| 256 } // namespace | 256 } // namespace |
| 257 | 257 |
| 258 WindowGrid::WindowGrid(aura::Window* root_window, | 258 WindowGrid::WindowGrid(aura::Window* root_window, |
| 259 const std::vector<aura::Window*>& windows, | 259 const std::vector<aura::Window*>& windows, |
| 260 WindowSelector* window_selector, | 260 WindowSelector* window_selector) |
| 261 const gfx::Rect& bounds_in_screen) | |
| 262 : root_window_(root_window), | 261 : root_window_(root_window), |
| 263 window_selector_(window_selector), | 262 window_selector_(window_selector), |
| 264 window_observer_(this), | 263 window_observer_(this), |
| 265 window_state_observer_(this), | 264 window_state_observer_(this), |
| 266 selected_index_(0), | 265 selected_index_(0), |
| 267 num_columns_(0), | 266 num_columns_(0), |
| 268 prepared_for_overview_(false), | 267 prepared_for_overview_(false) { |
| 269 bounds_(bounds_in_screen) { | |
| 270 aura::Window::Windows windows_in_root; | 268 aura::Window::Windows windows_in_root; |
| 271 for (auto* window : windows) { | 269 for (auto* window : windows) { |
| 272 if (window->GetRootWindow() == root_window) | 270 if (window->GetRootWindow() == root_window) |
| 273 windows_in_root.push_back(window); | 271 windows_in_root.push_back(window); |
| 274 } | 272 } |
| 275 | 273 |
| 276 for (auto* window : windows_in_root) { | 274 for (auto* window : windows_in_root) { |
| 277 window_observer_.Add(window); | 275 window_observer_.Add(window); |
| 278 window_state_observer_.Add(wm::GetWindowState(window)); | 276 window_state_observer_.Add(wm::GetWindowState(window)); |
| 279 window_list_.push_back( | 277 window_list_.push_back( |
| 280 base::MakeUnique<WindowSelectorItem>(window, window_selector_, this)); | 278 base::MakeUnique<WindowSelectorItem>(window, window_selector_)); |
| 281 } | 279 } |
| 282 } | 280 } |
| 283 | 281 |
| 284 WindowGrid::~WindowGrid() {} | 282 WindowGrid::~WindowGrid() {} |
| 285 | 283 |
| 286 void WindowGrid::Shutdown() { | 284 void WindowGrid::Shutdown() { |
| 287 for (const auto& window : window_list_) | 285 for (const auto& window : window_list_) |
| 288 window->Shutdown(); | 286 window->Shutdown(); |
| 289 | 287 |
| 290 if (shield_widget_) { | 288 if (shield_widget_) { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 321 } | 319 } |
| 322 | 320 |
| 323 void WindowGrid::PositionWindows(bool animate) { | 321 void WindowGrid::PositionWindows(bool animate) { |
| 324 if (window_selector_->is_shut_down() || window_list_.empty()) | 322 if (window_selector_->is_shut_down() || window_list_.empty()) |
| 325 return; | 323 return; |
| 326 DCHECK(shield_widget_.get()); | 324 DCHECK(shield_widget_.get()); |
| 327 // Keep the background shield widget covering the whole screen. | 325 // Keep the background shield widget covering the whole screen. |
| 328 aura::Window* widget_window = shield_widget_->GetNativeWindow(); | 326 aura::Window* widget_window = shield_widget_->GetNativeWindow(); |
| 329 const gfx::Rect bounds = widget_window->parent()->bounds(); | 327 const gfx::Rect bounds = widget_window->parent()->bounds(); |
| 330 widget_window->SetBounds(bounds); | 328 widget_window->SetBounds(bounds); |
| 331 | 329 gfx::Rect total_bounds = ScreenUtil::GetDisplayWorkAreaBoundsInParent( |
| 332 gfx::Rect total_bounds = bounds_; | 330 root_window_->GetChildById(kShellWindowId_DefaultContainer)); |
| 331 ::wm::ConvertRectToScreen(root_window_, &total_bounds); |
| 333 // Windows occupy vertically centered area with additional vertical insets. | 332 // Windows occupy vertically centered area with additional vertical insets. |
| 334 int horizontal_inset = | 333 int horizontal_inset = |
| 335 gfx::ToFlooredInt(std::min(kOverviewInsetRatio * total_bounds.width(), | 334 gfx::ToFlooredInt(std::min(kOverviewInsetRatio * total_bounds.width(), |
| 336 kOverviewInsetRatio * total_bounds.height())); | 335 kOverviewInsetRatio * total_bounds.height())); |
| 337 int vertical_inset = | 336 int vertical_inset = |
| 338 horizontal_inset + | 337 horizontal_inset + |
| 339 kOverviewVerticalInset * (total_bounds.height() - 2 * horizontal_inset); | 338 kOverviewVerticalInset * (total_bounds.height() - 2 * horizontal_inset); |
| 340 total_bounds.Inset(std::max(0, horizontal_inset - kWindowMargin), | 339 total_bounds.Inset(std::max(0, horizontal_inset - kWindowMargin), |
| 341 std::max(0, vertical_inset - kWindowMargin)); | 340 std::max(0, vertical_inset - kWindowMargin)); |
| 342 std::vector<gfx::Rect> rects; | 341 std::vector<gfx::Rect> rects; |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 512 } | 511 } |
| 513 | 512 |
| 514 bool WindowGrid::Contains(const aura::Window* window) const { | 513 bool WindowGrid::Contains(const aura::Window* window) const { |
| 515 for (const auto& window_item : window_list_) { | 514 for (const auto& window_item : window_list_) { |
| 516 if (window_item->Contains(window)) | 515 if (window_item->Contains(window)) |
| 517 return true; | 516 return true; |
| 518 } | 517 } |
| 519 return false; | 518 return false; |
| 520 } | 519 } |
| 521 | 520 |
| 522 void WindowGrid::RemoveItem(WindowSelectorItem* selector_item) { | |
| 523 auto iter = | |
| 524 std::find_if(window_list_.begin(), window_list_.end(), | |
| 525 [selector_item](std::unique_ptr<WindowSelectorItem>& item) { | |
| 526 return (item.get() == selector_item); | |
| 527 }); | |
| 528 if (iter != window_list_.end()) { | |
| 529 window_observer_.Remove(selector_item->GetWindow()); | |
| 530 window_state_observer_.Remove( | |
| 531 wm::GetWindowState(selector_item->GetWindow())); | |
| 532 window_list_.erase(iter); | |
| 533 } | |
| 534 } | |
| 535 | |
| 536 void WindowGrid::FilterItems(const base::string16& pattern) { | 521 void WindowGrid::FilterItems(const base::string16& pattern) { |
| 537 base::i18n::FixedPatternStringSearchIgnoringCaseAndAccents finder(pattern); | 522 base::i18n::FixedPatternStringSearchIgnoringCaseAndAccents finder(pattern); |
| 538 for (const auto& window : window_list_) { | 523 for (const auto& window : window_list_) { |
| 539 if (finder.Search(window->GetWindow()->GetTitle(), nullptr, nullptr)) { | 524 if (finder.Search(window->GetWindow()->GetTitle(), nullptr, nullptr)) { |
| 540 window->SetDimmed(false); | 525 window->SetDimmed(false); |
| 541 } else { | 526 } else { |
| 542 window->SetDimmed(true); | 527 window->SetDimmed(true); |
| 543 if (selection_widget_ && SelectedWindow() == window.get()) { | 528 if (selection_widget_ && SelectedWindow() == window.get()) { |
| 544 SelectedWindow()->SetSelected(false); | 529 SelectedWindow()->SetSelected(false); |
| 545 selection_widget_.reset(); | 530 selection_widget_.reset(); |
| 546 selector_shadow_.reset(); | 531 selector_shadow_.reset(); |
| 547 } | 532 } |
| 548 } | 533 } |
| 549 } | 534 } |
| 550 } | 535 } |
| 551 | 536 |
| 552 void WindowGrid::WindowClosing(WindowSelectorItem* window) { | 537 void WindowGrid::WindowClosing(WindowSelectorItem* window) { |
| 553 if (!selection_widget_ || SelectedWindow() != window) | 538 if (!selection_widget_ || SelectedWindow() != window) |
| 554 return; | 539 return; |
| 555 aura::Window* selection_widget_window = selection_widget_->GetNativeWindow(); | 540 aura::Window* selection_widget_window = selection_widget_->GetNativeWindow(); |
| 556 ScopedOverviewAnimationSettings animation_settings_label( | 541 ScopedOverviewAnimationSettings animation_settings_label( |
| 557 OverviewAnimationType::OVERVIEW_ANIMATION_CLOSING_SELECTOR_ITEM, | 542 OverviewAnimationType::OVERVIEW_ANIMATION_CLOSING_SELECTOR_ITEM, |
| 558 selection_widget_window); | 543 selection_widget_window); |
| 559 selection_widget_->SetOpacity(0.f); | 544 selection_widget_->SetOpacity(0.f); |
| 560 } | 545 } |
| 561 | 546 |
| 562 void WindowGrid::SetBoundsAndUpdatePositions(const gfx::Rect& bounds) { | |
| 563 bounds_ = bounds; | |
| 564 PositionWindows(true /* animate */); | |
| 565 } | |
| 566 | |
| 567 void WindowGrid::OnWindowDestroying(aura::Window* window) { | 547 void WindowGrid::OnWindowDestroying(aura::Window* window) { |
| 568 window_observer_.Remove(window); | 548 window_observer_.Remove(window); |
| 569 window_state_observer_.Remove(wm::GetWindowState(window)); | 549 window_state_observer_.Remove(wm::GetWindowState(window)); |
| 570 auto iter = std::find_if(window_list_.begin(), window_list_.end(), | 550 auto iter = std::find_if(window_list_.begin(), window_list_.end(), |
| 571 [window](std::unique_ptr<WindowSelectorItem>& item) { | 551 [window](std::unique_ptr<WindowSelectorItem>& item) { |
| 572 return item->GetWindow() == window; | 552 return item->GetWindow() == window; |
| 573 }); | 553 }); |
| 574 DCHECK(iter != window_list_.end()); | 554 DCHECK(iter != window_list_.end()); |
| 575 | 555 |
| 576 size_t removed_index = iter - window_list_.begin(); | 556 size_t removed_index = iter - window_list_.begin(); |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 835 *min_right = left; | 815 *min_right = left; |
| 836 if (*max_right < left) | 816 if (*max_right < left) |
| 837 *max_right = left; | 817 *max_right = left; |
| 838 } | 818 } |
| 839 *max_bottom = top + height; | 819 *max_bottom = top + height; |
| 840 } | 820 } |
| 841 return windows_fit; | 821 return windows_fit; |
| 842 } | 822 } |
| 843 | 823 |
| 844 } // namespace ash | 824 } // namespace ash |
| OLD | NEW |