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