| 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/display/window_tree_host_manager.h" | 10 #include "ash/display/window_tree_host_manager.h" |
| 11 #include "ash/shelf/shelf_constants.h" | 11 #include "ash/shelf/shelf_constants.h" |
| 12 #include "ash/shelf/shelf_item_delegate_manager.h" | 12 #include "ash/shelf/shelf_item_delegate_manager.h" |
| 13 #include "ash/shelf/shelf_model.h" | 13 #include "ash/shelf/shelf_model.h" |
| 14 #include "ash/shelf/shelf_util.h" | 14 #include "ash/shelf/shelf_util.h" |
| 15 #include "ash/shelf/shelf_window_watcher_item_delegate.h" | 15 #include "ash/shelf/shelf_window_watcher_item_delegate.h" |
| 16 #include "ash/shell.h" | 16 #include "ash/shell.h" |
| 17 #include "ash/shell_window_ids.h" | 17 #include "ash/shell_window_ids.h" |
| 18 #include "ash/wm/common/window_state.h" | 18 #include "ash/wm/common/window_state.h" |
| 19 #include "ash/wm/window_state_aura.h" | 19 #include "ash/wm/window_state_aura.h" |
| 20 #include "ash/wm/window_util.h" | 20 #include "ash/wm/window_util.h" |
| 21 #include "ui/aura/window.h" | 21 #include "ui/aura/window.h" |
| 22 #include "ui/base/resource/resource_bundle.h" | 22 #include "ui/base/resource/resource_bundle.h" |
| 23 #include "ui/display/screen.h" |
| 23 #include "ui/gfx/image/image_skia.h" | 24 #include "ui/gfx/image/image_skia.h" |
| 24 #include "ui/gfx/screen.h" | |
| 25 #include "ui/wm/public/activation_client.h" | 25 #include "ui/wm/public/activation_client.h" |
| 26 | 26 |
| 27 namespace { | 27 namespace { |
| 28 | 28 |
| 29 // Sets ShelfItem property by using the value of |details|. | 29 // Sets ShelfItem property by using the value of |details|. |
| 30 void SetShelfItemDetailsForShelfItem(ash::ShelfItem* item, | 30 void SetShelfItemDetailsForShelfItem(ash::ShelfItem* item, |
| 31 const ash::ShelfItemDetails& details) { | 31 const ash::ShelfItemDetails& details) { |
| 32 item->type = details.type; | 32 item->type = details.type; |
| 33 if (details.image_resource_id != ash::kInvalidImageResourceID) { | 33 if (details.image_resource_id != ash::kInvalidImageResourceID) { |
| 34 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 34 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 observed_root_windows_(&root_window_observer_), | 114 observed_root_windows_(&root_window_observer_), |
| 115 observed_removed_windows_(&removed_window_observer_), | 115 observed_removed_windows_(&removed_window_observer_), |
| 116 observed_activation_clients_(this) { | 116 observed_activation_clients_(this) { |
| 117 // We can't assume all RootWindows have the same ActivationClient. | 117 // We can't assume all RootWindows have the same ActivationClient. |
| 118 // Add a RootWindow and its ActivationClient to the observed list. | 118 // Add a RootWindow and its ActivationClient to the observed list. |
| 119 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); | 119 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); |
| 120 for (aura::Window::Windows::const_iterator it = root_windows.begin(); | 120 for (aura::Window::Windows::const_iterator it = root_windows.begin(); |
| 121 it != root_windows.end(); ++it) | 121 it != root_windows.end(); ++it) |
| 122 OnRootWindowAdded(*it); | 122 OnRootWindowAdded(*it); |
| 123 | 123 |
| 124 gfx::Screen::GetScreen()->AddObserver(this); | 124 display::Screen::GetScreen()->AddObserver(this); |
| 125 } | 125 } |
| 126 | 126 |
| 127 ShelfWindowWatcher::~ShelfWindowWatcher() { | 127 ShelfWindowWatcher::~ShelfWindowWatcher() { |
| 128 gfx::Screen::GetScreen()->RemoveObserver(this); | 128 display::Screen::GetScreen()->RemoveObserver(this); |
| 129 } | 129 } |
| 130 | 130 |
| 131 void ShelfWindowWatcher::AddShelfItem(aura::Window* window) { | 131 void ShelfWindowWatcher::AddShelfItem(aura::Window* window) { |
| 132 const ShelfItemDetails* item_details = | 132 const ShelfItemDetails* item_details = |
| 133 GetShelfItemDetailsForWindow(window); | 133 GetShelfItemDetailsForWindow(window); |
| 134 ShelfItem item; | 134 ShelfItem item; |
| 135 ShelfID id = model_->next_id(); | 135 ShelfID id = model_->next_id(); |
| 136 item.status = wm::IsActiveWindow(window) ? STATUS_ACTIVE: STATUS_RUNNING; | 136 item.status = wm::IsActiveWindow(window) ? STATUS_ACTIVE: STATUS_RUNNING; |
| 137 SetShelfItemDetailsForShelfItem(&item, *item_details); | 137 SetShelfItemDetailsForShelfItem(&item, *item_details); |
| 138 SetShelfIDForWindow(id, window); | 138 SetShelfIDForWindow(id, window); |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 GetShelfItemDetailsForWindow(window); | 262 GetShelfItemDetailsForWindow(window); |
| 263 SetShelfItemDetailsForShelfItem(&item, *details); | 263 SetShelfItemDetailsForShelfItem(&item, *details); |
| 264 model_->Set(index, item); | 264 model_->Set(index, item); |
| 265 return; | 265 return; |
| 266 } | 266 } |
| 267 | 267 |
| 268 // Creates a new ShelfItem for |window|. | 268 // Creates a new ShelfItem for |window|. |
| 269 AddShelfItem(window); | 269 AddShelfItem(window); |
| 270 } | 270 } |
| 271 | 271 |
| 272 void ShelfWindowWatcher::OnDisplayAdded(const gfx::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(root_window); |
| 282 } | 282 } |
| 283 | 283 |
| 284 void ShelfWindowWatcher::OnDisplayRemoved(const gfx::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 gfx::Display&, | 291 void ShelfWindowWatcher::OnDisplayMetricsChanged(const display::Display&, |
| 292 uint32_t) { | 292 uint32_t) {} |
| 293 } | |
| 294 | 293 |
| 295 } // namespace ash | 294 } // namespace ash |
| OLD | NEW |