Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(31)

Side by Side Diff: ash/common/wm/overview/window_selector.cc

Issue 2699033002: Replace WmWindowObserver with aura::WindowObserver. (Closed)
Patch Set: Check for null images in ShelfWindowWatcher. Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ash/common/wm/overview/window_selector.h ('k') | ash/common/wm/overview/window_selector_item.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_selector.h" 5 #include "ash/common/wm/overview/window_selector.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 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 232
233 WindowSelector::~WindowSelector() { 233 WindowSelector::~WindowSelector() {
234 RemoveAllObservers(); 234 RemoveAllObservers();
235 } 235 }
236 236
237 // NOTE: The work done in Init() is not done in the constructor because it may 237 // NOTE: The work done in Init() is not done in the constructor because it may
238 // cause other, unrelated classes, (ie PanelLayoutManager) to make indirect 238 // cause other, unrelated classes, (ie PanelLayoutManager) to make indirect
239 // calls to restoring_minimized_windows() on a partially constructed object. 239 // calls to restoring_minimized_windows() on a partially constructed object.
240 void WindowSelector::Init(const WindowList& windows) { 240 void WindowSelector::Init(const WindowList& windows) {
241 if (restore_focus_window_) 241 if (restore_focus_window_)
242 restore_focus_window_->AddObserver(this); 242 restore_focus_window_->aura_window()->AddObserver(this);
243 243
244 WmShell* shell = WmShell::Get(); 244 WmShell* shell = WmShell::Get();
245 245
246 std::vector<WmWindow*> root_windows = shell->GetAllRootWindows(); 246 std::vector<WmWindow*> root_windows = shell->GetAllRootWindows();
247 std::sort(root_windows.begin(), root_windows.end(), 247 std::sort(root_windows.begin(), root_windows.end(),
248 [](const WmWindow* a, const WmWindow* b) { 248 [](const WmWindow* a, const WmWindow* b) {
249 // Since we don't know if windows are vertically or horizontally 249 // Since we don't know if windows are vertically or horizontally
250 // oriented we use both x and y position. This may be confusing 250 // oriented we use both x and y position. This may be confusing
251 // if you have 3 or more monitors which are not strictly 251 // if you have 3 or more monitors which are not strictly
252 // horizontal or vertical but that case is not yet supported. 252 // horizontal or vertical but that case is not yet supported.
253 return (a->GetBoundsInScreen().x() + a->GetBoundsInScreen().y()) < 253 return (a->GetBoundsInScreen().x() + a->GetBoundsInScreen().y()) <
254 (b->GetBoundsInScreen().x() + b->GetBoundsInScreen().y()); 254 (b->GetBoundsInScreen().x() + b->GetBoundsInScreen().y());
255 }); 255 });
256 256
257 for (WmWindow* root : root_windows) { 257 for (WmWindow* root : root_windows) {
258 // Observed switchable containers for newly created windows on all root 258 // Observed switchable containers for newly created windows on all root
259 // windows. 259 // windows.
260 for (size_t i = 0; i < wm::kSwitchableWindowContainerIdsLength; ++i) { 260 for (size_t i = 0; i < wm::kSwitchableWindowContainerIdsLength; ++i) {
261 WmWindow* container = 261 WmWindow* container =
262 root->GetChildByShellWindowId(wm::kSwitchableWindowContainerIds[i]); 262 root->GetChildByShellWindowId(wm::kSwitchableWindowContainerIds[i]);
263 container->AddObserver(this); 263 container->aura_window()->AddObserver(this);
264 observed_windows_.insert(container); 264 observed_windows_.insert(container);
265 } 265 }
266 266
267 // Hide the callout widgets for panels. It is safe to call this for 267 // Hide the callout widgets for panels. It is safe to call this for
268 // root windows that don't contain any panel windows. 268 // root windows that don't contain any panel windows.
269 PanelLayoutManager::Get(root)->SetShowCalloutWidgets(false); 269 PanelLayoutManager::Get(root)->SetShowCalloutWidgets(false);
270 270
271 std::unique_ptr<WindowGrid> grid(new WindowGrid(root, windows, this)); 271 std::unique_ptr<WindowGrid> grid(new WindowGrid(root, windows, this));
272 if (grid->empty()) 272 if (grid->empty())
273 continue; 273 continue;
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 remaining_items); 365 remaining_items);
366 } 366 }
367 367
368 // Clearing the window list resets the ignored_by_shelf flag on the windows. 368 // Clearing the window list resets the ignored_by_shelf flag on the windows.
369 grid_list_.clear(); 369 grid_list_.clear();
370 UpdateShelfVisibility(); 370 UpdateShelfVisibility();
371 } 371 }
372 372
373 void WindowSelector::RemoveAllObservers() { 373 void WindowSelector::RemoveAllObservers() {
374 for (WmWindow* window : observed_windows_) 374 for (WmWindow* window : observed_windows_)
375 window->RemoveObserver(this); 375 window->aura_window()->RemoveObserver(this);
376 376
377 WmShell::Get()->RemoveActivationObserver(this); 377 WmShell::Get()->RemoveActivationObserver(this);
378 display::Screen::GetScreen()->RemoveObserver(this); 378 display::Screen::GetScreen()->RemoveObserver(this);
379 if (restore_focus_window_) 379 if (restore_focus_window_)
380 restore_focus_window_->RemoveObserver(this); 380 restore_focus_window_->aura_window()->RemoveObserver(this);
381 } 381 }
382 382
383 void WindowSelector::CancelSelection() { 383 void WindowSelector::CancelSelection() {
384 delegate_->OnSelectionEnded(); 384 delegate_->OnSelectionEnded();
385 } 385 }
386 386
387 void WindowSelector::OnGridEmpty(WindowGrid* grid) { 387 void WindowSelector::OnGridEmpty(WindowGrid* grid) {
388 size_t index = 0; 388 size_t index = 0;
389 for (auto iter = grid_list_.begin(); iter != grid_list_.end(); ++iter) { 389 for (auto iter = grid_list_.begin(); iter != grid_list_.end(); ++iter) {
390 if (grid == (*iter).get()) { 390 if (grid == (*iter).get()) {
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 // TODO(flackr): Keep window selection active on remaining displays. 508 // TODO(flackr): Keep window selection active on remaining displays.
509 CancelSelection(); 509 CancelSelection();
510 } 510 }
511 511
512 void WindowSelector::OnDisplayMetricsChanged(const display::Display& display, 512 void WindowSelector::OnDisplayMetricsChanged(const display::Display& display,
513 uint32_t metrics) { 513 uint32_t metrics) {
514 PositionWindows(/* animate */ false); 514 PositionWindows(/* animate */ false);
515 RepositionTextFilterOnDisplayMetricsChange(); 515 RepositionTextFilterOnDisplayMetricsChange();
516 } 516 }
517 517
518 void WindowSelector::OnWindowTreeChanged(WmWindow* window, 518 void WindowSelector::OnWindowHierarchyChanged(
519 const TreeChangeParams& params) { 519 const HierarchyChangeParams& params) {
520 // Only care about newly added children of |observed_windows_|. 520 // Only care about newly added children of |observed_windows_|.
521 if (!observed_windows_.count(window) || 521 if (!observed_windows_.count(WmWindow::Get(params.receiver)) ||
522 !observed_windows_.count(params.new_parent)) { 522 !observed_windows_.count(WmWindow::Get(params.new_parent))) {
523 return; 523 return;
524 } 524 }
525 525
526 WmWindow* new_window = params.target; 526 WmWindow* new_window = WmWindow::Get(params.target);
527 if (!IsSelectable(new_window)) 527 if (!IsSelectable(new_window))
528 return; 528 return;
529 529
530 for (size_t i = 0; i < wm::kSwitchableWindowContainerIdsLength; ++i) { 530 for (size_t i = 0; i < wm::kSwitchableWindowContainerIdsLength; ++i) {
531 if (new_window->GetParent()->GetShellWindowId() == 531 if (new_window->GetParent()->GetShellWindowId() ==
532 wm::kSwitchableWindowContainerIds[i] && 532 wm::kSwitchableWindowContainerIds[i] &&
533 !new_window->GetTransientParent()) { 533 !new_window->GetTransientParent()) {
534 // The new window is in one of the switchable containers, abort overview. 534 // The new window is in one of the switchable containers, abort overview.
535 CancelSelection(); 535 CancelSelection();
536 return; 536 return;
537 } 537 }
538 } 538 }
539 } 539 }
540 540
541 void WindowSelector::OnWindowDestroying(WmWindow* window) { 541 void WindowSelector::OnWindowDestroying(aura::Window* window) {
542 window->RemoveObserver(this); 542 window->RemoveObserver(this);
543 observed_windows_.erase(window); 543 observed_windows_.erase(WmWindow::Get(window));
544 if (window == restore_focus_window_) 544 if (WmWindow::Get(window) == restore_focus_window_)
545 restore_focus_window_ = nullptr; 545 restore_focus_window_ = nullptr;
546 } 546 }
547 547
548 void WindowSelector::OnWindowActivated(WmWindow* gained_active, 548 void WindowSelector::OnWindowActivated(WmWindow* gained_active,
549 WmWindow* lost_active) { 549 WmWindow* lost_active) {
550 if (ignore_activations_ || !gained_active || 550 if (ignore_activations_ || !gained_active ||
551 gained_active == GetTextFilterWidgetWindow()) { 551 gained_active == GetTextFilterWidgetWindow()) {
552 return; 552 return;
553 } 553 }
554 554
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
649 if (!restore_focus_window_) 649 if (!restore_focus_window_)
650 return; 650 return;
651 if (focus) { 651 if (focus) {
652 base::AutoReset<bool> restoring_focus(&ignore_activations_, true); 652 base::AutoReset<bool> restoring_focus(&ignore_activations_, true);
653 restore_focus_window_->Activate(); 653 restore_focus_window_->Activate();
654 } 654 }
655 // If the window is in the observed_windows_ list it needs to continue to be 655 // If the window is in the observed_windows_ list it needs to continue to be
656 // observed. 656 // observed.
657 if (observed_windows_.find(restore_focus_window_) == 657 if (observed_windows_.find(restore_focus_window_) ==
658 observed_windows_.end()) { 658 observed_windows_.end()) {
659 restore_focus_window_->RemoveObserver(this); 659 restore_focus_window_->aura_window()->RemoveObserver(this);
660 } 660 }
661 restore_focus_window_ = nullptr; 661 restore_focus_window_ = nullptr;
662 } 662 }
663 663
664 void WindowSelector::Move(Direction direction, bool animate) { 664 void WindowSelector::Move(Direction direction, bool animate) {
665 // Direction to move if moving past the end of a display. 665 // Direction to move if moving past the end of a display.
666 int display_direction = (direction == RIGHT || direction == DOWN) ? 1 : -1; 666 int display_direction = (direction == RIGHT || direction == DOWN) ? 1 : -1;
667 667
668 // If this is the first move and it's going backwards, start on the last 668 // If this is the first move and it's going backwards, start on the last
669 // display. 669 // display.
670 if (display_direction == -1 && !grid_list_.empty() && 670 if (display_direction == -1 && !grid_list_.empty() &&
671 !grid_list_[selected_grid_index_]->is_selecting()) { 671 !grid_list_[selected_grid_index_]->is_selecting()) {
672 selected_grid_index_ = grid_list_.size() - 1; 672 selected_grid_index_ = grid_list_.size() - 1;
673 } 673 }
674 674
675 // Keep calling Move() on the grids until one of them reports no overflow or 675 // Keep calling Move() on the grids until one of them reports no overflow or
676 // we made a full cycle on all the grids. 676 // we made a full cycle on all the grids.
677 for (size_t i = 0; i <= grid_list_.size() && 677 for (size_t i = 0; i <= grid_list_.size() &&
678 grid_list_[selected_grid_index_]->Move(direction, animate); 678 grid_list_[selected_grid_index_]->Move(direction, animate);
679 i++) { 679 i++) {
680 selected_grid_index_ = 680 selected_grid_index_ =
681 (selected_grid_index_ + display_direction + grid_list_.size()) % 681 (selected_grid_index_ + display_direction + grid_list_.size()) %
682 grid_list_.size(); 682 grid_list_.size();
683 } 683 }
684 } 684 }
685 685
686 } // namespace ash 686 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/wm/overview/window_selector.h ('k') | ash/common/wm/overview/window_selector_item.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698