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

Side by Side Diff: ash/common/shelf/shelf_window_watcher.cc

Issue 2618333004: Add ShelfWindowWatcher support for pre-existing windows. (Closed)
Patch Set: Address comments. Created 3 years, 11 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 | « no previous file | ash/common/shelf/shelf_window_watcher_unittest.cc » ('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/shelf/shelf_window_watcher.h" 5 #include "ash/common/shelf/shelf_window_watcher.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 9
10 #include "ash/common/shelf/shelf_constants.h" 10 #include "ash/common/shelf/shelf_constants.h"
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 111
112 //////////////////////////////////////////////////////////////////////////////// 112 ////////////////////////////////////////////////////////////////////////////////
113 113
114 ShelfWindowWatcher::ShelfWindowWatcher(ShelfModel* model) 114 ShelfWindowWatcher::ShelfWindowWatcher(ShelfModel* model)
115 : model_(model), 115 : model_(model),
116 container_window_observer_(this), 116 container_window_observer_(this),
117 user_window_observer_(this), 117 user_window_observer_(this),
118 observed_container_windows_(&container_window_observer_), 118 observed_container_windows_(&container_window_observer_),
119 observed_user_windows_(&user_window_observer_) { 119 observed_user_windows_(&user_window_observer_) {
120 WmShell::Get()->AddActivationObserver(this); 120 WmShell::Get()->AddActivationObserver(this);
121 for (WmWindow* root : WmShell::Get()->GetAllRootWindows()) { 121 for (const auto& display : display::Screen::GetScreen()->GetAllDisplays())
122 observed_container_windows_.Add( 122 OnDisplayAdded(display);
123 root->GetChildByShellWindowId(kShellWindowId_DefaultContainer));
124 observed_container_windows_.Add(
125 root->GetChildByShellWindowId(kShellWindowId_PanelContainer));
126 }
127
128 display::Screen::GetScreen()->AddObserver(this); 123 display::Screen::GetScreen()->AddObserver(this);
129 } 124 }
130 125
131 ShelfWindowWatcher::~ShelfWindowWatcher() { 126 ShelfWindowWatcher::~ShelfWindowWatcher() {
132 display::Screen::GetScreen()->RemoveObserver(this); 127 display::Screen::GetScreen()->RemoveObserver(this);
133 WmShell::Get()->RemoveActivationObserver(this); 128 WmShell::Get()->RemoveActivationObserver(this);
134 } 129 }
135 130
136 void ShelfWindowWatcher::AddShelfItem(WmWindow* window) { 131 void ShelfWindowWatcher::AddShelfItem(WmWindow* window) {
137 user_windows_with_items_.insert(window); 132 user_windows_with_items_.insert(window);
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 WmWindow* lost_active) { 206 WmWindow* lost_active) {
212 if (gained_active && user_windows_with_items_.count(gained_active) > 0) 207 if (gained_active && user_windows_with_items_.count(gained_active) > 0)
213 OnUserWindowPropertyChanged(gained_active); 208 OnUserWindowPropertyChanged(gained_active);
214 if (lost_active && user_windows_with_items_.count(lost_active) > 0) 209 if (lost_active && user_windows_with_items_.count(lost_active) > 0)
215 OnUserWindowPropertyChanged(lost_active); 210 OnUserWindowPropertyChanged(lost_active);
216 } 211 }
217 212
218 void ShelfWindowWatcher::OnDisplayAdded(const display::Display& new_display) { 213 void ShelfWindowWatcher::OnDisplayAdded(const display::Display& new_display) {
219 WmWindow* root = WmShell::Get()->GetRootWindowForDisplayId(new_display.id()); 214 WmWindow* root = WmShell::Get()->GetRootWindowForDisplayId(new_display.id());
220 215
221 // When the primary root window's display get removed, the existing root 216 // When the primary root window's display is removed, the existing root window
222 // window is taken over by the new display and the observer is already set. 217 // is taken over by the new display, and the observer is already set.
223 WmWindow* default_container = 218 WmWindow* default_container =
224 root->GetChildByShellWindowId(kShellWindowId_DefaultContainer); 219 root->GetChildByShellWindowId(kShellWindowId_DefaultContainer);
225 if (!observed_container_windows_.IsObserving(default_container)) 220 if (!observed_container_windows_.IsObserving(default_container)) {
221 for (WmWindow* window : default_container->GetChildren())
222 OnUserWindowAdded(window);
226 observed_container_windows_.Add(default_container); 223 observed_container_windows_.Add(default_container);
224 }
227 WmWindow* panel_container = 225 WmWindow* panel_container =
228 root->GetChildByShellWindowId(kShellWindowId_PanelContainer); 226 root->GetChildByShellWindowId(kShellWindowId_PanelContainer);
229 if (!observed_container_windows_.IsObserving(panel_container)) 227 if (!observed_container_windows_.IsObserving(panel_container)) {
228 for (WmWindow* window : panel_container->GetChildren())
229 OnUserWindowAdded(window);
230 observed_container_windows_.Add(panel_container); 230 observed_container_windows_.Add(panel_container);
231 }
231 } 232 }
232 233
233 void ShelfWindowWatcher::OnDisplayRemoved(const display::Display& old_display) { 234 void ShelfWindowWatcher::OnDisplayRemoved(const display::Display& old_display) {
234 } 235 }
235 236
236 void ShelfWindowWatcher::OnDisplayMetricsChanged(const display::Display&, 237 void ShelfWindowWatcher::OnDisplayMetricsChanged(const display::Display&,
237 uint32_t) {} 238 uint32_t) {}
238 239
239 } // namespace ash 240 } // namespace ash
OLDNEW
« no previous file with comments | « no previous file | ash/common/shelf/shelf_window_watcher_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698