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 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
253 } | 253 } |
254 | 254 |
255 bool IsMinimizedStateType(wm::WindowStateType type) { | 255 bool IsMinimizedStateType(wm::WindowStateType type) { |
256 return type == wm::WINDOW_STATE_TYPE_MINIMIZED; | 256 return type == wm::WINDOW_STATE_TYPE_MINIMIZED; |
257 } | 257 } |
258 | 258 |
259 } // namespace | 259 } // namespace |
260 | 260 |
261 WindowGrid::WindowGrid(aura::Window* root_window, | 261 WindowGrid::WindowGrid(aura::Window* root_window, |
262 const std::vector<aura::Window*>& windows, | 262 const std::vector<aura::Window*>& windows, |
263 WindowSelector* window_selector) | 263 WindowSelector* window_selector, |
264 const gfx::Rect& bounds_in_screen) | |
264 : root_window_(root_window), | 265 : root_window_(root_window), |
265 window_selector_(window_selector), | 266 window_selector_(window_selector), |
266 window_observer_(this), | 267 window_observer_(this), |
267 window_state_observer_(this), | 268 window_state_observer_(this), |
268 selected_index_(0), | 269 selected_index_(0), |
269 num_columns_(0), | 270 num_columns_(0), |
270 prepared_for_overview_(false) { | 271 prepared_for_overview_(false), |
272 bounds_(bounds_in_screen) { | |
271 aura::Window::Windows windows_in_root; | 273 aura::Window::Windows windows_in_root; |
272 for (auto* window : windows) { | 274 for (auto* window : windows) { |
273 if (window->GetRootWindow() == root_window) | 275 if (window->GetRootWindow() == root_window) |
274 windows_in_root.push_back(window); | 276 windows_in_root.push_back(window); |
275 } | 277 } |
276 | 278 |
277 for (auto* window : windows_in_root) { | 279 for (auto* window : windows_in_root) { |
278 window_observer_.Add(window); | 280 window_observer_.Add(window); |
279 window_state_observer_.Add(wm::GetWindowState(window)); | 281 window_state_observer_.Add(wm::GetWindowState(window)); |
280 window_list_.push_back( | 282 window_list_.push_back( |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
322 } | 324 } |
323 | 325 |
324 void WindowGrid::PositionWindows(bool animate) { | 326 void WindowGrid::PositionWindows(bool animate) { |
325 if (window_selector_->is_shut_down() || window_list_.empty()) | 327 if (window_selector_->is_shut_down() || window_list_.empty()) |
326 return; | 328 return; |
327 DCHECK(shield_widget_.get()); | 329 DCHECK(shield_widget_.get()); |
328 // Keep the background shield widget covering the whole screen. | 330 // Keep the background shield widget covering the whole screen. |
329 aura::Window* widget_window = shield_widget_->GetNativeWindow(); | 331 aura::Window* widget_window = shield_widget_->GetNativeWindow(); |
330 const gfx::Rect bounds = widget_window->parent()->bounds(); | 332 const gfx::Rect bounds = widget_window->parent()->bounds(); |
331 widget_window->SetBounds(bounds); | 333 widget_window->SetBounds(bounds); |
332 gfx::Rect total_bounds = ScreenUtil::GetDisplayWorkAreaBoundsInParent( | 334 |
333 root_window_->GetChildById(kShellWindowId_DefaultContainer)); | 335 gfx::Rect total_bounds = bounds_; |
334 ::wm::ConvertRectToScreen(root_window_, &total_bounds); | |
335 // Windows occupy vertically centered area with additional vertical insets. | 336 // Windows occupy vertically centered area with additional vertical insets. |
336 int horizontal_inset = | 337 int horizontal_inset = |
337 gfx::ToFlooredInt(std::min(kOverviewInsetRatio * total_bounds.width(), | 338 gfx::ToFlooredInt(std::min(kOverviewInsetRatio * total_bounds.width(), |
338 kOverviewInsetRatio * total_bounds.height())); | 339 kOverviewInsetRatio * total_bounds.height())); |
339 int vertical_inset = | 340 int vertical_inset = |
340 horizontal_inset + | 341 horizontal_inset + |
341 kOverviewVerticalInset * (total_bounds.height() - 2 * horizontal_inset); | 342 kOverviewVerticalInset * (total_bounds.height() - 2 * horizontal_inset); |
342 total_bounds.Inset(std::max(0, horizontal_inset - kWindowMargin), | 343 total_bounds.Inset(std::max(0, horizontal_inset - kWindowMargin), |
343 std::max(0, vertical_inset - kWindowMargin)); | 344 std::max(0, vertical_inset - kWindowMargin)); |
344 std::vector<gfx::Rect> rects; | 345 std::vector<gfx::Rect> rects; |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
514 } | 515 } |
515 | 516 |
516 bool WindowGrid::Contains(const aura::Window* window) const { | 517 bool WindowGrid::Contains(const aura::Window* window) const { |
517 for (const auto& window_item : window_list_) { | 518 for (const auto& window_item : window_list_) { |
518 if (window_item->Contains(window)) | 519 if (window_item->Contains(window)) |
519 return true; | 520 return true; |
520 } | 521 } |
521 return false; | 522 return false; |
522 } | 523 } |
523 | 524 |
525 void WindowGrid::RemoveItem(WindowSelectorItem* selector_item) { | |
526 auto iter = | |
527 std::find_if(window_list_.begin(), window_list_.end(), | |
528 [selector_item](std::unique_ptr<WindowSelectorItem>& item) { | |
529 return item->Contains(selector_item->GetWindow()); | |
oshima
2017/06/14 00:19:27
why this isn't simple == ?
xdai1
2017/06/15 22:11:41
Done.
oshima
2017/06/16 01:20:57
Actually, we should double check with +varkha@.
xdai1
2017/06/20 22:10:00
varkha@, as suggested by oshima@, could you help t
varkha
2017/06/21 01:51:52
I am not sure why this has Contains in the first p
| |
530 }); | |
531 if (iter != window_list_.end()) { | |
532 window_observer_.Remove(selector_item->GetWindow()); | |
533 window_state_observer_.Remove( | |
534 wm::GetWindowState(selector_item->GetWindow())); | |
535 window_list_.erase(iter); | |
536 } | |
537 } | |
538 | |
524 void WindowGrid::FilterItems(const base::string16& pattern) { | 539 void WindowGrid::FilterItems(const base::string16& pattern) { |
525 base::i18n::FixedPatternStringSearchIgnoringCaseAndAccents finder(pattern); | 540 base::i18n::FixedPatternStringSearchIgnoringCaseAndAccents finder(pattern); |
526 for (const auto& window : window_list_) { | 541 for (const auto& window : window_list_) { |
527 if (finder.Search(window->GetWindow()->GetTitle(), nullptr, nullptr)) { | 542 if (finder.Search(window->GetWindow()->GetTitle(), nullptr, nullptr)) { |
528 window->SetDimmed(false); | 543 window->SetDimmed(false); |
529 } else { | 544 } else { |
530 window->SetDimmed(true); | 545 window->SetDimmed(true); |
531 if (selection_widget_ && SelectedWindow() == window.get()) { | 546 if (selection_widget_ && SelectedWindow() == window.get()) { |
532 SelectedWindow()->SetSelected(false); | 547 SelectedWindow()->SetSelected(false); |
533 selection_widget_.reset(); | 548 selection_widget_.reset(); |
534 selector_shadow_.reset(); | 549 selector_shadow_.reset(); |
535 } | 550 } |
536 } | 551 } |
537 } | 552 } |
538 } | 553 } |
539 | 554 |
540 void WindowGrid::WindowClosing(WindowSelectorItem* window) { | 555 void WindowGrid::WindowClosing(WindowSelectorItem* window) { |
541 if (!selection_widget_ || SelectedWindow() != window) | 556 if (!selection_widget_ || SelectedWindow() != window) |
542 return; | 557 return; |
543 aura::Window* selection_widget_window = selection_widget_->GetNativeWindow(); | 558 aura::Window* selection_widget_window = selection_widget_->GetNativeWindow(); |
544 ScopedOverviewAnimationSettings animation_settings_label( | 559 ScopedOverviewAnimationSettings animation_settings_label( |
545 OverviewAnimationType::OVERVIEW_ANIMATION_CLOSING_SELECTOR_ITEM, | 560 OverviewAnimationType::OVERVIEW_ANIMATION_CLOSING_SELECTOR_ITEM, |
546 selection_widget_window); | 561 selection_widget_window); |
547 selection_widget_->SetOpacity(0.f); | 562 selection_widget_->SetOpacity(0.f); |
548 } | 563 } |
549 | 564 |
565 void WindowGrid::SetBoundsInScreen(const gfx::Rect bounds) { | |
566 bounds_ = bounds; | |
567 PositionWindows(true); | |
568 } | |
569 | |
550 void WindowGrid::OnWindowDestroying(aura::Window* window) { | 570 void WindowGrid::OnWindowDestroying(aura::Window* window) { |
551 window_observer_.Remove(window); | 571 window_observer_.Remove(window); |
552 window_state_observer_.Remove(wm::GetWindowState(window)); | 572 window_state_observer_.Remove(wm::GetWindowState(window)); |
553 auto iter = std::find_if(window_list_.begin(), window_list_.end(), | 573 auto iter = std::find_if(window_list_.begin(), window_list_.end(), |
554 [window](std::unique_ptr<WindowSelectorItem>& item) { | 574 [window](std::unique_ptr<WindowSelectorItem>& item) { |
555 return item->GetWindow() == window; | 575 return item->GetWindow() == window; |
556 }); | 576 }); |
557 DCHECK(iter != window_list_.end()); | 577 DCHECK(iter != window_list_.end()); |
558 | 578 |
559 size_t removed_index = iter - window_list_.begin(); | 579 size_t removed_index = iter - window_list_.begin(); |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
818 *min_right = left; | 838 *min_right = left; |
819 if (*max_right < left) | 839 if (*max_right < left) |
820 *max_right = left; | 840 *max_right = left; |
821 } | 841 } |
822 *max_bottom = top + height; | 842 *max_bottom = top + height; |
823 } | 843 } |
824 return windows_fit; | 844 return windows_fit; |
825 } | 845 } |
826 | 846 |
827 } // namespace ash | 847 } // namespace ash |
OLD | NEW |