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_SHELF_SHELF_WINDOW_WATCHER_H_ | 5 #ifndef ASH_SHELF_SHELF_WINDOW_WATCHER_H_ |
6 #define ASH_SHELF_SHELF_WINDOW_WATCHER_H_ | 6 #define ASH_SHELF_SHELF_WINDOW_WATCHER_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include "ash/common/wm_activation_observer.h" |
9 | 9 #include "ash/common/wm_window_observer.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "base/scoped_observer.h" | 11 #include "base/scoped_observer.h" |
12 #include "ui/aura/window_observer.h" | |
13 #include "ui/display/display_observer.h" | 12 #include "ui/display/display_observer.h" |
14 #include "ui/wm/public/activation_change_observer.h" | |
15 | |
16 namespace aura { | |
17 | |
18 class Window; | |
19 | |
20 namespace client { | |
21 class ActivationClient; | |
22 } | |
23 | |
24 } // namespace aura | |
25 | 13 |
26 namespace ash { | 14 namespace ash { |
27 | 15 |
28 class ShelfModel; | 16 class ShelfModel; |
29 class WmWindow; | 17 class WmWindow; |
30 | 18 |
31 // ShelfWindowWatcher creates and handles a ShelfItem for windows that have | 19 // ShelfWindowWatcher creates and handles a ShelfItem for windows in the default |
32 // a ShelfItemDetails property in the default container. | 20 // container that have a ShelfItemDetails property (e.g. the task manager |
33 class ShelfWindowWatcher : public aura::client::ActivationChangeObserver, | 21 // dialog or the OS settings window). It adds the ShelfItem when the window is |
34 public aura::WindowObserver, | 22 // added to the default container and maintains it until the window is closed, |
| 23 // even if the window is transiently reparented (e.g. during a drag). |
| 24 class ShelfWindowWatcher : public WmActivationObserver, |
35 public display::DisplayObserver { | 25 public display::DisplayObserver { |
36 public: | 26 public: |
37 explicit ShelfWindowWatcher(ShelfModel* model); | 27 explicit ShelfWindowWatcher(ShelfModel* model); |
38 ~ShelfWindowWatcher() override; | 28 ~ShelfWindowWatcher() override; |
39 | 29 |
40 private: | 30 private: |
41 class RootWindowObserver : public aura::WindowObserver { | 31 // Observes for windows being added to a root window's default container. |
| 32 class ContainerWindowObserver : public WmWindowObserver { |
42 public: | 33 public: |
43 explicit RootWindowObserver(ShelfWindowWatcher* window_watcher); | 34 explicit ContainerWindowObserver(ShelfWindowWatcher* window_watcher); |
44 ~RootWindowObserver() override; | 35 ~ContainerWindowObserver() override; |
45 | 36 |
46 private: | 37 private: |
47 // aura::WindowObserver overrides: | 38 // WmWindowObserver: |
48 void OnWindowDestroying(aura::Window* window) override; | 39 void OnWindowTreeChanged(WmWindow* window, |
| 40 const TreeChangeParams& params) override; |
| 41 void OnWindowDestroying(WmWindow* window) override; |
49 | 42 |
50 // Owned by Shell. | |
51 ShelfWindowWatcher* window_watcher_; | 43 ShelfWindowWatcher* window_watcher_; |
52 | 44 |
53 DISALLOW_COPY_AND_ASSIGN(RootWindowObserver); | 45 DISALLOW_COPY_AND_ASSIGN(ContainerWindowObserver); |
54 }; | 46 }; |
55 | 47 |
56 // Used to track windows that are removed. See description of | 48 // Observes individual user windows to detect when they are closed or when |
57 // ShelfWindowWatcher::StartObservingRemovedWindow() for more details. | 49 // they have ShelfItemDetails changed. |
58 class RemovedWindowObserver : public aura::WindowObserver { | 50 class UserWindowObserver : public WmWindowObserver { |
59 public: | 51 public: |
60 explicit RemovedWindowObserver(ShelfWindowWatcher* window_watcher); | 52 explicit UserWindowObserver(ShelfWindowWatcher* window_watcher); |
61 ~RemovedWindowObserver() override; | 53 ~UserWindowObserver() override; |
62 | 54 |
63 private: | 55 private: |
64 // aura::WindowObserver overrides: | 56 // WmWindowObserver: |
65 void OnWindowParentChanged(aura::Window* window, | 57 void OnWindowPropertyChanged(WmWindow* window, |
66 aura::Window* parent) override; | 58 WmWindowProperty property) override; |
67 void OnWindowDestroyed(aura::Window* window) override; | 59 void OnWindowDestroying(WmWindow* window) override; |
68 | 60 |
69 // Owned by Shell. | |
70 ShelfWindowWatcher* window_watcher_; | 61 ShelfWindowWatcher* window_watcher_; |
71 | 62 |
72 DISALLOW_COPY_AND_ASSIGN(RemovedWindowObserver); | 63 DISALLOW_COPY_AND_ASSIGN(UserWindowObserver); |
73 }; | 64 }; |
74 | 65 |
75 // Creates a ShelfItem for |window| that has ShelfItemDetails. | 66 // Creates a ShelfItem for |window| that has ShelfItemDetails. |
76 void AddShelfItem(aura::Window* window); | 67 void AddShelfItem(WmWindow* window); |
77 | 68 |
78 // Removes a ShelfItem for |window|. | 69 // Removes a ShelfItem for |window|. |
79 void RemoveShelfItem(aura::Window* window); | 70 void RemoveShelfItem(WmWindow* window); |
80 | |
81 // Adds observer to default container and ActivationClient of | |
82 // |root_window_wm|. | |
83 void OnRootWindowAdded(WmWindow* root_window_wm); | |
84 | |
85 // Removes observer from ActivationClient of |root_window|. | |
86 void OnRootWindowRemoved(aura::Window* root_window); | |
87 | 71 |
88 // Updates the status of ShelfItem for |window|. | 72 // Updates the status of ShelfItem for |window|. |
89 void UpdateShelfItemStatus(aura::Window* window, bool is_active); | 73 void UpdateShelfItemStatus(WmWindow* window, bool is_active); |
90 | 74 |
91 // Returns the index of ShelfItem associated with |window|. | 75 // Returns the index of ShelfItem associated with |window|. |
92 int GetShelfItemIndexForWindow(aura::Window* window) const; | 76 int GetShelfItemIndexForWindow(WmWindow* window) const; |
93 | 77 |
94 // Used when a window is removed. During the dragging a window may be removed | 78 // Cleans up observers on |container|. |
95 // and when the drag completes added back. When this happens we don't want to | 79 void OnContainerWindowDestroying(WmWindow* container); |
96 // remove the shelf item. StartObservingRemovedWindow, if necessary, attaches | |
97 // an observer. When done, FinishObservingRemovedWindow() is invoked. | |
98 void StartObservingRemovedWindow(aura::Window* window); | |
99 | 80 |
100 // Stop observing |window| by RemovedWindowObserver and remove an item | 81 // Adds a shelf item for new windows added to the default container that have |
101 // associated with |window|. | 82 // a ShelfItemDetails property. |
102 void FinishObservingRemovedWindow(aura::Window* window); | 83 void OnUserWindowAdded(WmWindow* window); |
103 | 84 |
104 // aura::client::ActivationChangeObserver overrides: | 85 // Adds, updates or removes the shelf item based on a property change. |
105 void OnWindowActivated( | 86 void OnUserWindowShelfItemDetailsChanged(WmWindow* window); |
106 aura::client::ActivationChangeObserver::ActivationReason reason, | |
107 aura::Window* gained_active, | |
108 aura::Window* lost_active) override; | |
109 | 87 |
110 // aura::WindowObserver overrides: | 88 // Removes the shelf item when a window closes. |
111 void OnWindowAdded(aura::Window* window) override; | 89 void OnUserWindowDestroying(WmWindow* window); |
112 void OnWillRemoveWindow(aura::Window* window) override; | 90 |
113 void OnWindowDestroying(aura::Window* window) override; | 91 // WmActivationObserver: |
114 void OnWindowPropertyChanged(aura::Window* window, | 92 void OnWindowActivated(WmWindow* gained_active, |
115 const void* key, | 93 WmWindow* lost_active) override; |
116 intptr_t old) override; | |
117 | 94 |
118 // display::DisplayObserver overrides: | 95 // display::DisplayObserver overrides: |
119 void OnDisplayAdded(const display::Display& display) override; | 96 void OnDisplayAdded(const display::Display& display) override; |
120 void OnDisplayRemoved(const display::Display& old_display) override; | 97 void OnDisplayRemoved(const display::Display& old_display) override; |
121 void OnDisplayMetricsChanged(const display::Display& display, | 98 void OnDisplayMetricsChanged(const display::Display& display, |
122 uint32_t metrics) override; | 99 uint32_t metrics) override; |
123 | 100 |
124 // Owned by Shell. | |
125 ShelfModel* model_; | 101 ShelfModel* model_; |
126 | 102 |
127 RootWindowObserver root_window_observer_; | 103 ContainerWindowObserver container_window_observer_; |
| 104 UserWindowObserver user_window_observer_; |
128 | 105 |
129 RemovedWindowObserver removed_window_observer_; | 106 ScopedObserver<WmWindow, ContainerWindowObserver> observed_container_windows_; |
130 | 107 ScopedObserver<WmWindow, UserWindowObserver> observed_user_windows_; |
131 // Holds all observed windows. | |
132 ScopedObserver<aura::Window, aura::WindowObserver> observed_windows_; | |
133 | |
134 // Holds all observed root windows. | |
135 ScopedObserver<aura::Window, aura::WindowObserver> observed_root_windows_; | |
136 | |
137 // Holds removed windows that has an item from default container. | |
138 ScopedObserver<aura::Window, aura::WindowObserver> observed_removed_windows_; | |
139 | 108 |
140 DISALLOW_COPY_AND_ASSIGN(ShelfWindowWatcher); | 109 DISALLOW_COPY_AND_ASSIGN(ShelfWindowWatcher); |
141 }; | 110 }; |
142 | 111 |
143 } // namespace ash | 112 } // namespace ash |
144 | 113 |
145 #endif // ASH_SHELF_SHELF_WINDOW_WATCHER_H_ | 114 #endif // ASH_SHELF_SHELF_WINDOW_WATCHER_H_ |
OLD | NEW |