| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/shell/window_watcher.h" | 5 #include "ash/shell/window_watcher.h" |
| 6 | 6 |
| 7 #include "ash/launcher/launcher.h" | 7 #include "ash/launcher/launcher.h" |
| 8 #include "ash/launcher/launcher_model.h" | 8 #include "ash/launcher/launcher_model.h" |
| 9 #include "ash/shell.h" | 9 #include "ash/shell.h" |
| 10 #include "ash/shell_window_ids.h" | 10 #include "ash/shell_window_ids.h" |
| 11 #include "ash/wm/workspace_controller.h" | |
| 12 #include "ui/aura/window.h" | 11 #include "ui/aura/window.h" |
| 13 | 12 |
| 14 namespace ash { | 13 namespace ash { |
| 15 namespace shell { | 14 namespace shell { |
| 16 | 15 |
| 17 class WindowWatcher::WorkspaceWindowWatcher : public aura::WindowObserver { | 16 class WindowWatcher::WorkspaceWindowWatcher : public aura::WindowObserver { |
| 18 public: | 17 public: |
| 19 explicit WorkspaceWindowWatcher(WindowWatcher* watcher) : watcher_(watcher) { | 18 explicit WorkspaceWindowWatcher(WindowWatcher* watcher) : watcher_(watcher) { |
| 20 watcher_->window_->AddObserver(this); | 19 watcher_->window_->AddObserver(this); |
| 21 for (size_t i = 0; i < watcher_->window_->children().size(); ++i) | 20 for (size_t i = 0; i < watcher_->window_->children().size(); ++i) |
| (...skipping 19 matching lines...) Expand all Loading... |
| 41 WindowWatcher* watcher_; | 40 WindowWatcher* watcher_; |
| 42 | 41 |
| 43 DISALLOW_COPY_AND_ASSIGN(WorkspaceWindowWatcher); | 42 DISALLOW_COPY_AND_ASSIGN(WorkspaceWindowWatcher); |
| 44 }; | 43 }; |
| 45 | 44 |
| 46 WindowWatcher::WindowWatcher() | 45 WindowWatcher::WindowWatcher() |
| 47 : window_(ash::Shell::GetInstance()->launcher()->window_container()), | 46 : window_(ash::Shell::GetInstance()->launcher()->window_container()), |
| 48 panel_container_(ash::Shell::GetContainer( | 47 panel_container_(ash::Shell::GetContainer( |
| 49 Shell::GetPrimaryRootWindow(), | 48 Shell::GetPrimaryRootWindow(), |
| 50 internal::kShellWindowId_PanelContainer)) { | 49 internal::kShellWindowId_PanelContainer)) { |
| 51 if (internal::WorkspaceController::IsWorkspace2Enabled()) | 50 workspace_window_watcher_.reset(new WorkspaceWindowWatcher(this)); |
| 52 workspace_window_watcher_.reset(new WorkspaceWindowWatcher(this)); | |
| 53 else | |
| 54 window_->AddObserver(this); | |
| 55 panel_container_->AddObserver(this); | 51 panel_container_->AddObserver(this); |
| 56 } | 52 } |
| 57 | 53 |
| 58 WindowWatcher::~WindowWatcher() { | 54 WindowWatcher::~WindowWatcher() { |
| 59 if (!internal::WorkspaceController::IsWorkspace2Enabled()) | |
| 60 window_->RemoveObserver(this); | |
| 61 panel_container_->RemoveObserver(this); | 55 panel_container_->RemoveObserver(this); |
| 62 } | 56 } |
| 63 | 57 |
| 64 aura::Window* WindowWatcher::GetWindowByID(ash::LauncherID id) { | 58 aura::Window* WindowWatcher::GetWindowByID(ash::LauncherID id) { |
| 65 IDToWindow::const_iterator i = id_to_window_.find(id); | 59 IDToWindow::const_iterator i = id_to_window_.find(id); |
| 66 return i != id_to_window_.end() ? i->second : NULL; | 60 return i != id_to_window_.end() ? i->second : NULL; |
| 67 } | 61 } |
| 68 | 62 |
| 69 ash::LauncherID WindowWatcher::GetIDByWindow(aura::Window* window) const { | 63 ash::LauncherID WindowWatcher::GetIDByWindow(aura::Window* window) const { |
| 70 for (IDToWindow::const_iterator i = id_to_window_.begin(); | 64 for (IDToWindow::const_iterator i = id_to_window_.begin(); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 DCHECK_NE(-1, index); | 105 DCHECK_NE(-1, index); |
| 112 model->RemoveItemAt(index); | 106 model->RemoveItemAt(index); |
| 113 id_to_window_.erase(i); | 107 id_to_window_.erase(i); |
| 114 break; | 108 break; |
| 115 } | 109 } |
| 116 } | 110 } |
| 117 } | 111 } |
| 118 | 112 |
| 119 } // namespace shell | 113 } // namespace shell |
| 120 } // namespace ash | 114 } // namespace ash |
| OLD | NEW |