| 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 #ifndef ASH_COMMON_SHELF_SHELF_WINDOW_WATCHER_H_ | 5 #ifndef ASH_COMMON_SHELF_SHELF_WINDOW_WATCHER_H_ |
| 6 #define ASH_COMMON_SHELF_SHELF_WINDOW_WATCHER_H_ | 6 #define ASH_COMMON_SHELF_SHELF_WINDOW_WATCHER_H_ |
| 7 | 7 |
| 8 #include <set> | 8 #include <set> |
| 9 | 9 |
| 10 #include "ash/common/wm_activation_observer.h" | |
| 11 #include "ash/common/wm_window_observer.h" | |
| 12 #include "base/macros.h" | 10 #include "base/macros.h" |
| 13 #include "base/scoped_observer.h" | 11 #include "base/scoped_observer.h" |
| 12 #include "ui/aura/window_observer.h" |
| 14 #include "ui/display/display_observer.h" | 13 #include "ui/display/display_observer.h" |
| 14 #include "ui/wm/public/activation_change_observer.h" |
| 15 | 15 |
| 16 namespace ash { | 16 namespace ash { |
| 17 | 17 |
| 18 class ShelfModel; | 18 class ShelfModel; |
| 19 class WmWindow; | |
| 20 | 19 |
| 21 // ShelfWindowWatcher creates and handles a ShelfItem for windows in the default | 20 // ShelfWindowWatcher creates and handles a ShelfItem for windows in the default |
| 22 // container and panels in the panel container that have a valid ShelfItemType | 21 // container and panels in the panel container that have a valid ShelfItemType |
| 23 // property (e.g. the task manager dialog or the OS settings window). It adds | 22 // property (e.g. the task manager dialog or the OS settings window). It adds |
| 24 // the ShelfItem when the window is added to the default container and maintains | 23 // the ShelfItem when the window is added to the default container and maintains |
| 25 // it until the window is closed, even if the window is transiently reparented | 24 // it until the window is closed, even if the window is transiently reparented |
| 26 // (e.g. during a drag). | 25 // (e.g. during a drag). |
| 27 class ShelfWindowWatcher : public WmActivationObserver, | 26 class ShelfWindowWatcher : public aura::client::ActivationChangeObserver, |
| 28 public display::DisplayObserver { | 27 public display::DisplayObserver { |
| 29 public: | 28 public: |
| 30 explicit ShelfWindowWatcher(ShelfModel* model); | 29 explicit ShelfWindowWatcher(ShelfModel* model); |
| 31 ~ShelfWindowWatcher() override; | 30 ~ShelfWindowWatcher() override; |
| 32 | 31 |
| 33 private: | 32 private: |
| 34 // Observes for windows being added to a root window's default container. | 33 // Observes for windows being added to a root window's default container. |
| 35 class ContainerWindowObserver : public WmWindowObserver { | 34 class ContainerWindowObserver : public aura::WindowObserver { |
| 36 public: | 35 public: |
| 37 explicit ContainerWindowObserver(ShelfWindowWatcher* window_watcher); | 36 explicit ContainerWindowObserver(ShelfWindowWatcher* window_watcher); |
| 38 ~ContainerWindowObserver() override; | 37 ~ContainerWindowObserver() override; |
| 39 | 38 |
| 40 private: | 39 private: |
| 41 // WmWindowObserver: | 40 // aura::WindowObserver: |
| 42 void OnWindowTreeChanged(WmWindow* window, | 41 void OnWindowHierarchyChanged(const HierarchyChangeParams& params) override; |
| 43 const TreeChangeParams& params) override; | 42 void OnWindowDestroying(aura::Window* window) override; |
| 44 void OnWindowDestroying(WmWindow* window) override; | |
| 45 | 43 |
| 46 ShelfWindowWatcher* window_watcher_; | 44 ShelfWindowWatcher* window_watcher_; |
| 47 | 45 |
| 48 DISALLOW_COPY_AND_ASSIGN(ContainerWindowObserver); | 46 DISALLOW_COPY_AND_ASSIGN(ContainerWindowObserver); |
| 49 }; | 47 }; |
| 50 | 48 |
| 51 // Observes individual user windows to detect when they are closed or when | 49 // Observes individual user windows to detect when they are closed or when |
| 52 // their shelf item properties have changed. | 50 // their shelf item properties have changed. |
| 53 class UserWindowObserver : public WmWindowObserver { | 51 class UserWindowObserver : public aura::WindowObserver { |
| 54 public: | 52 public: |
| 55 explicit UserWindowObserver(ShelfWindowWatcher* window_watcher); | 53 explicit UserWindowObserver(ShelfWindowWatcher* window_watcher); |
| 56 ~UserWindowObserver() override; | 54 ~UserWindowObserver() override; |
| 57 | 55 |
| 58 private: | 56 private: |
| 59 // WmWindowObserver: | 57 // aura::WindowObserver: |
| 60 void OnWindowPropertyChanged(WmWindow* window, | 58 void OnWindowPropertyChanged(aura::Window* window, |
| 61 WmWindowProperty property) override; | 59 const void* key, |
| 62 void OnWindowDestroying(WmWindow* window) override; | 60 intptr_t old) override; |
| 63 void OnWindowVisibilityChanged(WmWindow* window, bool visible) override; | 61 void OnWindowDestroying(aura::Window* window) override; |
| 64 void OnWindowTitleChanged(WmWindow* window) override; | 62 void OnWindowVisibilityChanged(aura::Window* window, bool visible) override; |
| 63 void OnWindowTitleChanged(aura::Window* window) override; |
| 65 | 64 |
| 66 ShelfWindowWatcher* window_watcher_; | 65 ShelfWindowWatcher* window_watcher_; |
| 67 | 66 |
| 68 DISALLOW_COPY_AND_ASSIGN(UserWindowObserver); | 67 DISALLOW_COPY_AND_ASSIGN(UserWindowObserver); |
| 69 }; | 68 }; |
| 70 | 69 |
| 71 // Creates a ShelfItem for |window|. | 70 // Creates a ShelfItem for |window|. |
| 72 void AddShelfItem(WmWindow* window); | 71 void AddShelfItem(aura::Window* window); |
| 73 | 72 |
| 74 // Removes a ShelfItem for |window|. | 73 // Removes a ShelfItem for |window|. |
| 75 void RemoveShelfItem(WmWindow* window); | 74 void RemoveShelfItem(aura::Window* window); |
| 76 | 75 |
| 77 // Returns the index of ShelfItem associated with |window|, or -1 if none. | 76 // Returns the index of ShelfItem associated with |window|, or -1 if none. |
| 78 int GetShelfItemIndexForWindow(WmWindow* window) const; | 77 int GetShelfItemIndexForWindow(aura::Window* window) const; |
| 79 | 78 |
| 80 // Cleans up observers on |container|. | 79 // Cleans up observers on |container|. |
| 81 void OnContainerWindowDestroying(WmWindow* container); | 80 void OnContainerWindowDestroying(aura::Window* container); |
| 82 | 81 |
| 83 // Adds a shelf item for new windows added to the default container that have | 82 // Adds a shelf item for new windows added to the default container that have |
| 84 // a valid ShelfItemType property value. | 83 // a valid ShelfItemType property value. |
| 85 void OnUserWindowAdded(WmWindow* window); | 84 void OnUserWindowAdded(aura::Window* window); |
| 86 | 85 |
| 87 // Adds, updates or removes the shelf item based on a property change. | 86 // Adds, updates or removes the shelf item based on a property change. |
| 88 void OnUserWindowPropertyChanged(WmWindow* window); | 87 void OnUserWindowPropertyChanged(aura::Window* window); |
| 89 | 88 |
| 90 // Removes the shelf item when a window closes. | 89 // Removes the shelf item when a window closes. |
| 91 void OnUserWindowDestroying(WmWindow* window); | 90 void OnUserWindowDestroying(aura::Window* window); |
| 92 | 91 |
| 93 // WmActivationObserver: | 92 // aura::client::ActivationChangeObserver: |
| 94 void OnWindowActivated(WmWindow* gained_active, | 93 void OnWindowActivated(ActivationReason reason, |
| 95 WmWindow* lost_active) override; | 94 aura::Window* gained_active, |
| 95 aura::Window* lost_active) override; |
| 96 | 96 |
| 97 // display::DisplayObserver overrides: | 97 // display::DisplayObserver overrides: |
| 98 void OnDisplayAdded(const display::Display& display) override; | 98 void OnDisplayAdded(const display::Display& display) override; |
| 99 void OnDisplayRemoved(const display::Display& old_display) override; | 99 void OnDisplayRemoved(const display::Display& old_display) override; |
| 100 void OnDisplayMetricsChanged(const display::Display& display, | 100 void OnDisplayMetricsChanged(const display::Display& display, |
| 101 uint32_t metrics) override; | 101 uint32_t metrics) override; |
| 102 | 102 |
| 103 ShelfModel* model_; | 103 ShelfModel* model_; |
| 104 | 104 |
| 105 ContainerWindowObserver container_window_observer_; | 105 ContainerWindowObserver container_window_observer_; |
| 106 UserWindowObserver user_window_observer_; | 106 UserWindowObserver user_window_observer_; |
| 107 | 107 |
| 108 ScopedObserver<WmWindow, ContainerWindowObserver> observed_container_windows_; | 108 ScopedObserver<aura::Window, ContainerWindowObserver> |
| 109 ScopedObserver<WmWindow, UserWindowObserver> observed_user_windows_; | 109 observed_container_windows_; |
| 110 ScopedObserver<aura::Window, UserWindowObserver> observed_user_windows_; |
| 110 | 111 |
| 111 // The set of windows with shelf items managed by this ShelfWindowWatcher. | 112 // The set of windows with shelf items managed by this ShelfWindowWatcher. |
| 112 std::set<WmWindow*> user_windows_with_items_; | 113 std::set<aura::Window*> user_windows_with_items_; |
| 113 | 114 |
| 114 DISALLOW_COPY_AND_ASSIGN(ShelfWindowWatcher); | 115 DISALLOW_COPY_AND_ASSIGN(ShelfWindowWatcher); |
| 115 }; | 116 }; |
| 116 | 117 |
| 117 } // namespace ash | 118 } // namespace ash |
| 118 | 119 |
| 119 #endif // ASH_COMMON_SHELF_SHELF_WINDOW_WATCHER_H_ | 120 #endif // ASH_COMMON_SHELF_SHELF_WINDOW_WATCHER_H_ |
| OLD | NEW |