| 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/common/shelf/shelf_constants.h" | 11 #include "ash/common/shelf/shelf_constants.h" |
| 11 #include "ash/common/shelf/shelf_item_delegate_manager.h" | 12 #include "ash/common/shelf/shelf_item_delegate_manager.h" |
| 12 #include "ash/common/shelf/shelf_model.h" | 13 #include "ash/common/shelf/shelf_model.h" |
| 13 #include "ash/common/shell_window_ids.h" | 14 #include "ash/common/shell_window_ids.h" |
| 14 #include "ash/common/wm/window_state.h" | 15 #include "ash/common/wm/window_state.h" |
| 15 #include "ash/display/window_tree_host_manager.h" | 16 #include "ash/display/window_tree_host_manager.h" |
| 16 #include "ash/shelf/shelf_util.h" | 17 #include "ash/shelf/shelf_util.h" |
| 17 #include "ash/shelf/shelf_window_watcher_item_delegate.h" | 18 #include "ash/shelf/shelf_window_watcher_item_delegate.h" |
| 18 #include "ash/shell.h" | 19 #include "ash/shell.h" |
| 19 #include "ash/wm/window_state_aura.h" | 20 #include "ash/wm/window_state_aura.h" |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 : model_(model), | 110 : model_(model), |
| 110 item_delegate_manager_(item_delegate_manager), | 111 item_delegate_manager_(item_delegate_manager), |
| 111 root_window_observer_(this), | 112 root_window_observer_(this), |
| 112 removed_window_observer_(this), | 113 removed_window_observer_(this), |
| 113 observed_windows_(this), | 114 observed_windows_(this), |
| 114 observed_root_windows_(&root_window_observer_), | 115 observed_root_windows_(&root_window_observer_), |
| 115 observed_removed_windows_(&removed_window_observer_), | 116 observed_removed_windows_(&removed_window_observer_), |
| 116 observed_activation_clients_(this) { | 117 observed_activation_clients_(this) { |
| 117 // We can't assume all RootWindows have the same ActivationClient. | 118 // We can't assume all RootWindows have the same ActivationClient. |
| 118 // Add a RootWindow and its ActivationClient to the observed list. | 119 // Add a RootWindow and its ActivationClient to the observed list. |
| 119 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); | 120 for (aura::Window* root : Shell::GetAllRootWindows()) |
| 120 for (aura::Window::Windows::const_iterator it = root_windows.begin(); | 121 OnRootWindowAdded(WmWindowAura::Get(root)); |
| 121 it != root_windows.end(); ++it) | |
| 122 OnRootWindowAdded(*it); | |
| 123 | 122 |
| 124 display::Screen::GetScreen()->AddObserver(this); | 123 display::Screen::GetScreen()->AddObserver(this); |
| 125 } | 124 } |
| 126 | 125 |
| 127 ShelfWindowWatcher::~ShelfWindowWatcher() { | 126 ShelfWindowWatcher::~ShelfWindowWatcher() { |
| 128 display::Screen::GetScreen()->RemoveObserver(this); | 127 display::Screen::GetScreen()->RemoveObserver(this); |
| 129 } | 128 } |
| 130 | 129 |
| 131 void ShelfWindowWatcher::AddShelfItem(aura::Window* window) { | 130 void ShelfWindowWatcher::AddShelfItem(aura::Window* window) { |
| 132 const ShelfItemDetails* item_details = | 131 const ShelfItemDetails* item_details = |
| 133 GetShelfItemDetailsForWindow(window); | 132 GetShelfItemDetailsForWindow(window); |
| 134 ShelfItem item; | 133 ShelfItem item; |
| 135 ShelfID id = model_->next_id(); | 134 ShelfID id = model_->next_id(); |
| 136 item.status = wm::IsActiveWindow(window) ? STATUS_ACTIVE: STATUS_RUNNING; | 135 item.status = wm::IsActiveWindow(window) ? STATUS_ACTIVE: STATUS_RUNNING; |
| 137 SetShelfItemDetailsForShelfItem(&item, *item_details); | 136 SetShelfItemDetailsForShelfItem(&item, *item_details); |
| 138 SetShelfIDForWindow(id, window); | 137 SetShelfIDForWindow(id, window); |
| 139 std::unique_ptr<ShelfItemDelegate> item_delegate( | 138 std::unique_ptr<ShelfItemDelegate> item_delegate( |
| 140 new ShelfWindowWatcherItemDelegate(window)); | 139 new ShelfWindowWatcherItemDelegate(window)); |
| 141 // |item_delegate| is owned by |item_delegate_manager_|. | 140 // |item_delegate| is owned by |item_delegate_manager_|. |
| 142 item_delegate_manager_->SetShelfItemDelegate(id, std::move(item_delegate)); | 141 item_delegate_manager_->SetShelfItemDelegate(id, std::move(item_delegate)); |
| 143 model_->Add(item); | 142 model_->Add(item); |
| 144 } | 143 } |
| 145 | 144 |
| 146 void ShelfWindowWatcher::RemoveShelfItem(aura::Window* window) { | 145 void ShelfWindowWatcher::RemoveShelfItem(aura::Window* window) { |
| 147 model_->RemoveItemAt(model_->ItemIndexByID(GetShelfIDForWindow(window))); | 146 model_->RemoveItemAt(model_->ItemIndexByID(GetShelfIDForWindow(window))); |
| 148 SetShelfIDForWindow(kInvalidShelfID, window); | 147 SetShelfIDForWindow(kInvalidShelfID, window); |
| 149 } | 148 } |
| 150 | 149 |
| 151 void ShelfWindowWatcher::OnRootWindowAdded(aura::Window* root_window) { | 150 void ShelfWindowWatcher::OnRootWindowAdded(WmWindow* root_window_wm) { |
| 151 aura::Window* root_window = WmWindowAura::GetAuraWindow(root_window_wm); |
| 152 // |observed_activation_clients_| can have the same ActivationClient multiple | 152 // |observed_activation_clients_| can have the same ActivationClient multiple |
| 153 // times - which would be handled by the |observed_activation_clients_|. | 153 // times - which would be handled by the |observed_activation_clients_|. |
| 154 observed_activation_clients_.Add( | 154 observed_activation_clients_.Add( |
| 155 aura::client::GetActivationClient(root_window)); | 155 aura::client::GetActivationClient(root_window)); |
| 156 observed_root_windows_.Add(root_window); | 156 observed_root_windows_.Add(root_window); |
| 157 | 157 |
| 158 aura::Window* default_container = Shell::GetContainer( | 158 aura::Window* default_container = Shell::GetContainer( |
| 159 root_window, | 159 root_window, |
| 160 kShellWindowId_DefaultContainer); | 160 kShellWindowId_DefaultContainer); |
| 161 observed_windows_.Add(default_container); | 161 observed_windows_.Add(default_container); |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 | 271 |
| 272 void ShelfWindowWatcher::OnDisplayAdded(const display::Display& new_display) { | 272 void ShelfWindowWatcher::OnDisplayAdded(const display::Display& new_display) { |
| 273 // Add a new RootWindow and its ActivationClient to observed list. | 273 // Add a new RootWindow and its ActivationClient to observed list. |
| 274 aura::Window* root_window = Shell::GetInstance() | 274 aura::Window* root_window = Shell::GetInstance() |
| 275 ->window_tree_host_manager() | 275 ->window_tree_host_manager() |
| 276 ->GetRootWindowForDisplayId(new_display.id()); | 276 ->GetRootWindowForDisplayId(new_display.id()); |
| 277 | 277 |
| 278 // When the primary root window's display get removed, the existing root | 278 // When the primary root window's display get removed, the existing root |
| 279 // window is taken over by the new display and the observer is already set. | 279 // window is taken over by the new display and the observer is already set. |
| 280 if (!observed_root_windows_.IsObserving(root_window)) | 280 if (!observed_root_windows_.IsObserving(root_window)) |
| 281 OnRootWindowAdded(root_window); | 281 OnRootWindowAdded(WmWindowAura::Get(root_window)); |
| 282 } | 282 } |
| 283 | 283 |
| 284 void ShelfWindowWatcher::OnDisplayRemoved(const display::Display& old_display) { | 284 void ShelfWindowWatcher::OnDisplayRemoved(const display::Display& old_display) { |
| 285 // When this is called, RootWindow of |old_display| is already removed. | 285 // When this is called, RootWindow of |old_display| is already removed. |
| 286 // Instead, we remove an observer from RootWindow and ActivationClient in the | 286 // Instead, we remove an observer from RootWindow and ActivationClient in the |
| 287 // OnRootWindowDestroyed(). | 287 // OnRootWindowDestroyed(). |
| 288 // Do nothing here. | 288 // Do nothing here. |
| 289 } | 289 } |
| 290 | 290 |
| 291 void ShelfWindowWatcher::OnDisplayMetricsChanged(const display::Display&, | 291 void ShelfWindowWatcher::OnDisplayMetricsChanged(const display::Display&, |
| 292 uint32_t) {} | 292 uint32_t) {} |
| 293 | 293 |
| 294 } // namespace ash | 294 } // namespace ash |
| OLD | NEW |