OLD | NEW |
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/shelf/shelf_window_watcher.h" | 5 #include "ash/shelf/shelf_window_watcher.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "ash/aura/wm_window_aura.h" | 10 #include "ash/aura/wm_window_aura.h" |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 bool IsDragging(aura::Window* window) { | 49 bool IsDragging(aura::Window* window) { |
50 return ash::wm::GetWindowState(window)->is_dragged(); | 50 return ash::wm::GetWindowState(window)->is_dragged(); |
51 } | 51 } |
52 | 52 |
53 } // namespace | 53 } // namespace |
54 | 54 |
55 namespace ash { | 55 namespace ash { |
56 | 56 |
57 ShelfWindowWatcher::RootWindowObserver::RootWindowObserver( | 57 ShelfWindowWatcher::RootWindowObserver::RootWindowObserver( |
58 ShelfWindowWatcher* window_watcher) | 58 ShelfWindowWatcher* window_watcher) |
59 : window_watcher_(window_watcher) { | 59 : window_watcher_(window_watcher) {} |
60 } | |
61 | 60 |
62 ShelfWindowWatcher::RootWindowObserver::~RootWindowObserver() { | 61 ShelfWindowWatcher::RootWindowObserver::~RootWindowObserver() {} |
63 } | |
64 | 62 |
65 void ShelfWindowWatcher::RootWindowObserver::OnWindowDestroying( | 63 void ShelfWindowWatcher::RootWindowObserver::OnWindowDestroying( |
66 aura::Window* window) { | 64 aura::Window* window) { |
67 window_watcher_->OnRootWindowRemoved(window); | 65 window_watcher_->OnRootWindowRemoved(window); |
68 } | 66 } |
69 | 67 |
70 ShelfWindowWatcher::RemovedWindowObserver::RemovedWindowObserver( | 68 ShelfWindowWatcher::RemovedWindowObserver::RemovedWindowObserver( |
71 ShelfWindowWatcher* window_watcher) | 69 ShelfWindowWatcher* window_watcher) |
72 : window_watcher_(window_watcher) { | 70 : window_watcher_(window_watcher) {} |
73 } | |
74 | 71 |
75 ShelfWindowWatcher::RemovedWindowObserver::~RemovedWindowObserver() { | 72 ShelfWindowWatcher::RemovedWindowObserver::~RemovedWindowObserver() {} |
76 } | |
77 | 73 |
78 void ShelfWindowWatcher::RemovedWindowObserver::OnWindowParentChanged( | 74 void ShelfWindowWatcher::RemovedWindowObserver::OnWindowParentChanged( |
79 aura::Window* window, | 75 aura::Window* window, |
80 aura::Window* parent) { | 76 aura::Window* parent) { |
81 // When |parent| is NULL, this |window| will be destroyed. In that case, its | 77 // When |parent| is NULL, this |window| will be destroyed. In that case, its |
82 // item will be removed at OnWindowDestroyed(). | 78 // item will be removed at OnWindowDestroyed(). |
83 if (!parent) | 79 if (!parent) |
84 return; | 80 return; |
85 | 81 |
86 // When |parent| is changed from default container to docked container | 82 // When |parent| is changed from default container to docked container |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 OnRootWindowAdded(WmWindowAura::Get(root)); | 117 OnRootWindowAdded(WmWindowAura::Get(root)); |
122 | 118 |
123 display::Screen::GetScreen()->AddObserver(this); | 119 display::Screen::GetScreen()->AddObserver(this); |
124 } | 120 } |
125 | 121 |
126 ShelfWindowWatcher::~ShelfWindowWatcher() { | 122 ShelfWindowWatcher::~ShelfWindowWatcher() { |
127 display::Screen::GetScreen()->RemoveObserver(this); | 123 display::Screen::GetScreen()->RemoveObserver(this); |
128 } | 124 } |
129 | 125 |
130 void ShelfWindowWatcher::AddShelfItem(aura::Window* window) { | 126 void ShelfWindowWatcher::AddShelfItem(aura::Window* window) { |
131 const ShelfItemDetails* item_details = | 127 const ShelfItemDetails* item_details = GetShelfItemDetailsForWindow(window); |
132 GetShelfItemDetailsForWindow(window); | |
133 ShelfItem item; | 128 ShelfItem item; |
134 ShelfID id = model_->next_id(); | 129 ShelfID id = model_->next_id(); |
135 item.status = wm::IsActiveWindow(window) ? STATUS_ACTIVE: STATUS_RUNNING; | 130 item.status = wm::IsActiveWindow(window) ? STATUS_ACTIVE : STATUS_RUNNING; |
136 SetShelfItemDetailsForShelfItem(&item, *item_details); | 131 SetShelfItemDetailsForShelfItem(&item, *item_details); |
137 SetShelfIDForWindow(id, window); | 132 SetShelfIDForWindow(id, window); |
138 std::unique_ptr<ShelfItemDelegate> item_delegate( | 133 std::unique_ptr<ShelfItemDelegate> item_delegate( |
139 new ShelfWindowWatcherItemDelegate(window)); | 134 new ShelfWindowWatcherItemDelegate(window)); |
140 // |item_delegate| is owned by |item_delegate_manager_|. | 135 // |item_delegate| is owned by |item_delegate_manager_|. |
141 item_delegate_manager_->SetShelfItemDelegate(id, std::move(item_delegate)); | 136 item_delegate_manager_->SetShelfItemDelegate(id, std::move(item_delegate)); |
142 model_->Add(item); | 137 model_->Add(item); |
143 } | 138 } |
144 | 139 |
145 void ShelfWindowWatcher::RemoveShelfItem(aura::Window* window) { | 140 void ShelfWindowWatcher::RemoveShelfItem(aura::Window* window) { |
146 model_->RemoveItemAt(model_->ItemIndexByID(GetShelfIDForWindow(window))); | 141 model_->RemoveItemAt(model_->ItemIndexByID(GetShelfIDForWindow(window))); |
147 SetShelfIDForWindow(kInvalidShelfID, window); | 142 SetShelfIDForWindow(kInvalidShelfID, window); |
148 } | 143 } |
149 | 144 |
150 void ShelfWindowWatcher::OnRootWindowAdded(WmWindow* root_window_wm) { | 145 void ShelfWindowWatcher::OnRootWindowAdded(WmWindow* root_window_wm) { |
151 aura::Window* root_window = WmWindowAura::GetAuraWindow(root_window_wm); | 146 aura::Window* root_window = WmWindowAura::GetAuraWindow(root_window_wm); |
152 // |observed_activation_clients_| can have the same ActivationClient multiple | 147 // |observed_activation_clients_| can have the same ActivationClient multiple |
153 // times - which would be handled by the |observed_activation_clients_|. | 148 // times - which would be handled by the |observed_activation_clients_|. |
154 observed_activation_clients_.Add( | 149 observed_activation_clients_.Add( |
155 aura::client::GetActivationClient(root_window)); | 150 aura::client::GetActivationClient(root_window)); |
156 observed_root_windows_.Add(root_window); | 151 observed_root_windows_.Add(root_window); |
157 | 152 |
158 aura::Window* default_container = Shell::GetContainer( | 153 aura::Window* default_container = |
159 root_window, | 154 Shell::GetContainer(root_window, kShellWindowId_DefaultContainer); |
160 kShellWindowId_DefaultContainer); | |
161 observed_windows_.Add(default_container); | 155 observed_windows_.Add(default_container); |
162 for (size_t i = 0; i < default_container->children().size(); ++i) | 156 for (size_t i = 0; i < default_container->children().size(); ++i) |
163 observed_windows_.Add(default_container->children()[i]); | 157 observed_windows_.Add(default_container->children()[i]); |
164 } | 158 } |
165 | 159 |
166 void ShelfWindowWatcher::OnRootWindowRemoved(aura::Window* root_window) { | 160 void ShelfWindowWatcher::OnRootWindowRemoved(aura::Window* root_window) { |
167 observed_root_windows_.Remove(root_window); | 161 observed_root_windows_.Remove(root_window); |
168 observed_activation_clients_.Remove( | 162 observed_activation_clients_.Remove( |
169 aura::client::GetActivationClient(root_window)); | 163 aura::client::GetActivationClient(root_window)); |
170 } | 164 } |
171 | 165 |
172 void ShelfWindowWatcher::UpdateShelfItemStatus(aura::Window* window, | 166 void ShelfWindowWatcher::UpdateShelfItemStatus(aura::Window* window, |
173 bool is_active) { | 167 bool is_active) { |
174 int index = GetShelfItemIndexForWindow(window); | 168 int index = GetShelfItemIndexForWindow(window); |
175 DCHECK_GE(index, 0); | 169 DCHECK_GE(index, 0); |
176 | 170 |
177 ShelfItem item = model_->items()[index]; | 171 ShelfItem item = model_->items()[index]; |
178 item.status = is_active ? STATUS_ACTIVE : STATUS_RUNNING; | 172 item.status = is_active ? STATUS_ACTIVE : STATUS_RUNNING; |
179 model_->Set(index, item); | 173 model_->Set(index, item); |
180 } | 174 } |
181 | 175 |
182 int ShelfWindowWatcher::GetShelfItemIndexForWindow( | 176 int ShelfWindowWatcher::GetShelfItemIndexForWindow(aura::Window* window) const { |
183 aura::Window* window) const { | |
184 return model_->ItemIndexByID(GetShelfIDForWindow(window)); | 177 return model_->ItemIndexByID(GetShelfIDForWindow(window)); |
185 } | 178 } |
186 | 179 |
187 void ShelfWindowWatcher::StartObservingRemovedWindow(aura::Window* window) { | 180 void ShelfWindowWatcher::StartObservingRemovedWindow(aura::Window* window) { |
188 observed_removed_windows_.Add(window); | 181 observed_removed_windows_.Add(window); |
189 } | 182 } |
190 | 183 |
191 void ShelfWindowWatcher::FinishObservingRemovedWindow(aura::Window* window) { | 184 void ShelfWindowWatcher::FinishObservingRemovedWindow(aura::Window* window) { |
192 observed_removed_windows_.Remove(window); | 185 observed_removed_windows_.Remove(window); |
193 RemoveShelfItem(window); | 186 RemoveShelfItem(window); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 if (reinterpret_cast<ShelfItemDetails*>(old) != NULL) | 244 if (reinterpret_cast<ShelfItemDetails*>(old) != NULL) |
252 RemoveShelfItem(window); | 245 RemoveShelfItem(window); |
253 return; | 246 return; |
254 } | 247 } |
255 | 248 |
256 // When ShelfItemDetails is changed, update ShelfItem. | 249 // When ShelfItemDetails is changed, update ShelfItem. |
257 if (HasShelfItemForWindow(window)) { | 250 if (HasShelfItemForWindow(window)) { |
258 int index = GetShelfItemIndexForWindow(window); | 251 int index = GetShelfItemIndexForWindow(window); |
259 DCHECK_GE(index, 0); | 252 DCHECK_GE(index, 0); |
260 ShelfItem item = model_->items()[index]; | 253 ShelfItem item = model_->items()[index]; |
261 const ShelfItemDetails* details = | 254 const ShelfItemDetails* details = GetShelfItemDetailsForWindow(window); |
262 GetShelfItemDetailsForWindow(window); | |
263 SetShelfItemDetailsForShelfItem(&item, *details); | 255 SetShelfItemDetailsForShelfItem(&item, *details); |
264 model_->Set(index, item); | 256 model_->Set(index, item); |
265 return; | 257 return; |
266 } | 258 } |
267 | 259 |
268 // Creates a new ShelfItem for |window|. | 260 // Creates a new ShelfItem for |window|. |
269 AddShelfItem(window); | 261 AddShelfItem(window); |
270 } | 262 } |
271 | 263 |
272 void ShelfWindowWatcher::OnDisplayAdded(const display::Display& new_display) { | 264 void ShelfWindowWatcher::OnDisplayAdded(const display::Display& new_display) { |
(...skipping 12 matching lines...) Expand all Loading... |
285 // When this is called, RootWindow of |old_display| is already removed. | 277 // When this is called, RootWindow of |old_display| is already removed. |
286 // Instead, we remove an observer from RootWindow and ActivationClient in the | 278 // Instead, we remove an observer from RootWindow and ActivationClient in the |
287 // OnRootWindowDestroyed(). | 279 // OnRootWindowDestroyed(). |
288 // Do nothing here. | 280 // Do nothing here. |
289 } | 281 } |
290 | 282 |
291 void ShelfWindowWatcher::OnDisplayMetricsChanged(const display::Display&, | 283 void ShelfWindowWatcher::OnDisplayMetricsChanged(const display::Display&, |
292 uint32_t) {} | 284 uint32_t) {} |
293 | 285 |
294 } // namespace ash | 286 } // namespace ash |
OLD | NEW |