| 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" |
| 11 #include "ash/common/shelf/shelf_constants.h" | 11 #include "ash/common/shelf/shelf_constants.h" |
| 12 #include "ash/common/shelf/shelf_item_delegate_manager.h" | |
| 13 #include "ash/common/shelf/shelf_model.h" | 12 #include "ash/common/shelf/shelf_model.h" |
| 14 #include "ash/common/shell_window_ids.h" | 13 #include "ash/common/shell_window_ids.h" |
| 15 #include "ash/common/wm/window_state.h" | 14 #include "ash/common/wm/window_state.h" |
| 16 #include "ash/display/window_tree_host_manager.h" | 15 #include "ash/display/window_tree_host_manager.h" |
| 17 #include "ash/shelf/shelf_util.h" | 16 #include "ash/shelf/shelf_util.h" |
| 18 #include "ash/shelf/shelf_window_watcher_item_delegate.h" | 17 #include "ash/shelf/shelf_window_watcher_item_delegate.h" |
| 19 #include "ash/shell.h" | 18 #include "ash/shell.h" |
| 20 #include "ash/wm/window_state_aura.h" | 19 #include "ash/wm/window_state_aura.h" |
| 21 #include "ash/wm/window_util.h" | 20 #include "ash/wm/window_util.h" |
| 22 #include "ui/aura/window.h" | 21 #include "ui/aura/window.h" |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 // and stop observing this |window|. | 92 // and stop observing this |window|. |
| 94 window_watcher_->FinishObservingRemovedWindow(window); | 93 window_watcher_->FinishObservingRemovedWindow(window); |
| 95 } | 94 } |
| 96 | 95 |
| 97 void ShelfWindowWatcher::RemovedWindowObserver::OnWindowDestroyed( | 96 void ShelfWindowWatcher::RemovedWindowObserver::OnWindowDestroyed( |
| 98 aura::Window* window) { | 97 aura::Window* window) { |
| 99 DCHECK(HasShelfItemForWindow(window)); | 98 DCHECK(HasShelfItemForWindow(window)); |
| 100 window_watcher_->FinishObservingRemovedWindow(window); | 99 window_watcher_->FinishObservingRemovedWindow(window); |
| 101 } | 100 } |
| 102 | 101 |
| 103 ShelfWindowWatcher::ShelfWindowWatcher( | 102 ShelfWindowWatcher::ShelfWindowWatcher(ShelfModel* model) |
| 104 ShelfModel* model, | |
| 105 ShelfItemDelegateManager* item_delegate_manager) | |
| 106 : model_(model), | 103 : model_(model), |
| 107 item_delegate_manager_(item_delegate_manager), | |
| 108 root_window_observer_(this), | 104 root_window_observer_(this), |
| 109 removed_window_observer_(this), | 105 removed_window_observer_(this), |
| 110 observed_windows_(this), | 106 observed_windows_(this), |
| 111 observed_root_windows_(&root_window_observer_), | 107 observed_root_windows_(&root_window_observer_), |
| 112 observed_removed_windows_(&removed_window_observer_), | 108 observed_removed_windows_(&removed_window_observer_), |
| 113 observed_activation_clients_(this) { | 109 observed_activation_clients_(this) { |
| 114 // We can't assume all RootWindows have the same ActivationClient. | 110 // We can't assume all RootWindows have the same ActivationClient. |
| 115 // Add a RootWindow and its ActivationClient to the observed list. | 111 // Add a RootWindow and its ActivationClient to the observed list. |
| 116 for (aura::Window* root : Shell::GetAllRootWindows()) | 112 for (aura::Window* root : Shell::GetAllRootWindows()) |
| 117 OnRootWindowAdded(WmWindowAura::Get(root)); | 113 OnRootWindowAdded(WmWindowAura::Get(root)); |
| 118 | 114 |
| 119 display::Screen::GetScreen()->AddObserver(this); | 115 display::Screen::GetScreen()->AddObserver(this); |
| 120 } | 116 } |
| 121 | 117 |
| 122 ShelfWindowWatcher::~ShelfWindowWatcher() { | 118 ShelfWindowWatcher::~ShelfWindowWatcher() { |
| 123 display::Screen::GetScreen()->RemoveObserver(this); | 119 display::Screen::GetScreen()->RemoveObserver(this); |
| 124 } | 120 } |
| 125 | 121 |
| 126 void ShelfWindowWatcher::AddShelfItem(aura::Window* window) { | 122 void ShelfWindowWatcher::AddShelfItem(aura::Window* window) { |
| 127 const ShelfItemDetails* item_details = GetShelfItemDetailsForWindow(window); | 123 const ShelfItemDetails* item_details = GetShelfItemDetailsForWindow(window); |
| 128 ShelfItem item; | 124 ShelfItem item; |
| 129 ShelfID id = model_->next_id(); | 125 ShelfID id = model_->next_id(); |
| 130 item.status = wm::IsActiveWindow(window) ? STATUS_ACTIVE : STATUS_RUNNING; | 126 item.status = wm::IsActiveWindow(window) ? STATUS_ACTIVE : STATUS_RUNNING; |
| 131 SetShelfItemDetailsForShelfItem(&item, *item_details); | 127 SetShelfItemDetailsForShelfItem(&item, *item_details); |
| 132 SetShelfIDForWindow(id, window); | 128 SetShelfIDForWindow(id, window); |
| 133 std::unique_ptr<ShelfItemDelegate> item_delegate( | 129 std::unique_ptr<ShelfItemDelegate> item_delegate( |
| 134 new ShelfWindowWatcherItemDelegate(window)); | 130 new ShelfWindowWatcherItemDelegate(window)); |
| 135 // |item_delegate| is owned by |item_delegate_manager_|. | 131 model_->SetShelfItemDelegate(id, std::move(item_delegate)); |
| 136 item_delegate_manager_->SetShelfItemDelegate(id, std::move(item_delegate)); | |
| 137 model_->Add(item); | 132 model_->Add(item); |
| 138 } | 133 } |
| 139 | 134 |
| 140 void ShelfWindowWatcher::RemoveShelfItem(aura::Window* window) { | 135 void ShelfWindowWatcher::RemoveShelfItem(aura::Window* window) { |
| 141 model_->RemoveItemAt(model_->ItemIndexByID(GetShelfIDForWindow(window))); | 136 model_->RemoveItemAt(model_->ItemIndexByID(GetShelfIDForWindow(window))); |
| 142 SetShelfIDForWindow(kInvalidShelfID, window); | 137 SetShelfIDForWindow(kInvalidShelfID, window); |
| 143 } | 138 } |
| 144 | 139 |
| 145 void ShelfWindowWatcher::OnRootWindowAdded(WmWindow* root_window_wm) { | 140 void ShelfWindowWatcher::OnRootWindowAdded(WmWindow* root_window_wm) { |
| 146 aura::Window* root_window = WmWindowAura::GetAuraWindow(root_window_wm); | 141 aura::Window* root_window = WmWindowAura::GetAuraWindow(root_window_wm); |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 // When this is called, RootWindow of |old_display| is already removed. | 272 // When this is called, RootWindow of |old_display| is already removed. |
| 278 // Instead, we remove an observer from RootWindow and ActivationClient in the | 273 // Instead, we remove an observer from RootWindow and ActivationClient in the |
| 279 // OnRootWindowDestroyed(). | 274 // OnRootWindowDestroyed(). |
| 280 // Do nothing here. | 275 // Do nothing here. |
| 281 } | 276 } |
| 282 | 277 |
| 283 void ShelfWindowWatcher::OnDisplayMetricsChanged(const display::Display&, | 278 void ShelfWindowWatcher::OnDisplayMetricsChanged(const display::Display&, |
| 284 uint32_t) {} | 279 uint32_t) {} |
| 285 | 280 |
| 286 } // namespace ash | 281 } // namespace ash |
| OLD | NEW |