| 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 "ui/aura/window.h" | 11 #include "ui/aura/window.h" |
| 12 | 12 |
| 13 namespace ash { | 13 namespace ash { |
| 14 namespace shell { | 14 namespace shell { |
| 15 | 15 |
| 16 class WindowWatcher::WorkspaceWindowWatcher : public aura::WindowObserver { |
| 17 public: |
| 18 explicit WorkspaceWindowWatcher(WindowWatcher* watcher) : watcher_(watcher) { |
| 19 watcher_->window_->AddObserver(this); |
| 20 for (size_t i = 0; i < watcher_->window_->children().size(); ++i) |
| 21 watcher_->window_->children()[i]->AddObserver(watcher_); |
| 22 } |
| 23 |
| 24 virtual ~WorkspaceWindowWatcher() { |
| 25 watcher_->window_->RemoveObserver(this); |
| 26 for (size_t i = 0; i < watcher_->window_->children().size(); ++i) |
| 27 watcher_->window_->children()[i]->RemoveObserver(watcher_); |
| 28 } |
| 29 |
| 30 virtual void OnWindowAdded(aura::Window* new_window) OVERRIDE { |
| 31 new_window->AddObserver(watcher_); |
| 32 } |
| 33 |
| 34 virtual void OnWillRemoveWindow(aura::Window* window) OVERRIDE { |
| 35 DCHECK(window->children().empty()); |
| 36 window->RemoveObserver(watcher_); |
| 37 } |
| 38 |
| 39 private: |
| 40 WindowWatcher* watcher_; |
| 41 |
| 42 DISALLOW_COPY_AND_ASSIGN(WorkspaceWindowWatcher); |
| 43 }; |
| 44 |
| 16 WindowWatcher::WindowWatcher() | 45 WindowWatcher::WindowWatcher() |
| 17 : window_(ash::Shell::GetInstance()->launcher()->window_container()), | 46 : window_(ash::Shell::GetInstance()->launcher()->window_container()), |
| 18 panel_container_(ash::Shell::GetContainer( | 47 panel_container_(ash::Shell::GetContainer( |
| 19 Shell::GetPrimaryRootWindow(), | 48 Shell::GetPrimaryRootWindow(), |
| 20 internal::kShellWindowId_PanelContainer)) { | 49 internal::kShellWindowId_PanelContainer)) { |
| 21 window_->AddObserver(this); | 50 workspace_window_watcher_.reset(new WorkspaceWindowWatcher(this)); |
| 22 panel_container_->AddObserver(this); | 51 panel_container_->AddObserver(this); |
| 23 } | 52 } |
| 24 | 53 |
| 25 WindowWatcher::~WindowWatcher() { | 54 WindowWatcher::~WindowWatcher() { |
| 26 window_->RemoveObserver(this); | |
| 27 panel_container_->RemoveObserver(this); | 55 panel_container_->RemoveObserver(this); |
| 28 } | 56 } |
| 29 | 57 |
| 30 aura::Window* WindowWatcher::GetWindowByID(ash::LauncherID id) { | 58 aura::Window* WindowWatcher::GetWindowByID(ash::LauncherID id) { |
| 31 IDToWindow::const_iterator i = id_to_window_.find(id); | 59 IDToWindow::const_iterator i = id_to_window_.find(id); |
| 32 return i != id_to_window_.end() ? i->second : NULL; | 60 return i != id_to_window_.end() ? i->second : NULL; |
| 33 } | 61 } |
| 34 | 62 |
| 35 ash::LauncherID WindowWatcher::GetIDByWindow(aura::Window* window) const { | 63 ash::LauncherID WindowWatcher::GetIDByWindow(aura::Window* window) const { |
| 36 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... |
| 77 DCHECK_NE(-1, index); | 105 DCHECK_NE(-1, index); |
| 78 model->RemoveItemAt(index); | 106 model->RemoveItemAt(index); |
| 79 id_to_window_.erase(i); | 107 id_to_window_.erase(i); |
| 80 break; | 108 break; |
| 81 } | 109 } |
| 82 } | 110 } |
| 83 } | 111 } |
| 84 | 112 |
| 85 } // namespace shell | 113 } // namespace shell |
| 86 } // namespace ash | 114 } // namespace ash |
| OLD | NEW |