OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef ASH_SHELF_SHELF_WINDOW_WATCHER_H_ | |
6 #define ASH_SHELF_SHELF_WINDOW_WATCHER_H_ | |
7 | |
8 #include "ash/common/wm_activation_observer.h" | |
9 #include "ash/common/wm_window_observer.h" | |
10 #include "base/macros.h" | |
11 #include "base/scoped_observer.h" | |
12 #include "ui/display/display_observer.h" | |
13 | |
14 namespace ash { | |
15 | |
16 class ShelfModel; | |
17 class WmWindow; | |
18 | |
19 // ShelfWindowWatcher creates and handles a ShelfItem for windows in the default | |
20 // container that have a ShelfItemDetails property (e.g. the task manager | |
21 // dialog or the OS settings window). It adds the ShelfItem when the window is | |
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, | |
25 public display::DisplayObserver { | |
26 public: | |
27 explicit ShelfWindowWatcher(ShelfModel* model); | |
28 ~ShelfWindowWatcher() override; | |
29 | |
30 private: | |
31 // Observes for windows being added to a root window's default container. | |
32 class ContainerWindowObserver : public WmWindowObserver { | |
33 public: | |
34 explicit ContainerWindowObserver(ShelfWindowWatcher* window_watcher); | |
35 ~ContainerWindowObserver() override; | |
36 | |
37 private: | |
38 // WmWindowObserver: | |
39 void OnWindowTreeChanged(WmWindow* window, | |
40 const TreeChangeParams& params) override; | |
41 void OnWindowDestroying(WmWindow* window) override; | |
42 | |
43 ShelfWindowWatcher* window_watcher_; | |
44 | |
45 DISALLOW_COPY_AND_ASSIGN(ContainerWindowObserver); | |
46 }; | |
47 | |
48 // Observes individual user windows to detect when they are closed or when | |
49 // they have ShelfItemDetails changed. | |
50 class UserWindowObserver : public WmWindowObserver { | |
51 public: | |
52 explicit UserWindowObserver(ShelfWindowWatcher* window_watcher); | |
53 ~UserWindowObserver() override; | |
54 | |
55 private: | |
56 // WmWindowObserver: | |
57 void OnWindowPropertyChanged(WmWindow* window, | |
58 WmWindowProperty property) override; | |
59 void OnWindowDestroying(WmWindow* window) override; | |
60 | |
61 ShelfWindowWatcher* window_watcher_; | |
62 | |
63 DISALLOW_COPY_AND_ASSIGN(UserWindowObserver); | |
64 }; | |
65 | |
66 // Creates a ShelfItem for |window| that has ShelfItemDetails. | |
67 void AddShelfItem(WmWindow* window); | |
68 | |
69 // Removes a ShelfItem for |window|. | |
70 void RemoveShelfItem(WmWindow* window); | |
71 | |
72 // Updates the status of ShelfItem for |window|. | |
73 void UpdateShelfItemStatus(WmWindow* window, bool is_active); | |
74 | |
75 // Returns the index of ShelfItem associated with |window|. | |
76 int GetShelfItemIndexForWindow(WmWindow* window) const; | |
77 | |
78 // Cleans up observers on |container|. | |
79 void OnContainerWindowDestroying(WmWindow* container); | |
80 | |
81 // Adds a shelf item for new windows added to the default container that have | |
82 // a ShelfItemDetails property. | |
83 void OnUserWindowAdded(WmWindow* window); | |
84 | |
85 // Adds, updates or removes the shelf item based on a property change. | |
86 void OnUserWindowShelfItemDetailsChanged(WmWindow* window); | |
87 | |
88 // Removes the shelf item when a window closes. | |
89 void OnUserWindowDestroying(WmWindow* window); | |
90 | |
91 // WmActivationObserver: | |
92 void OnWindowActivated(WmWindow* gained_active, | |
93 WmWindow* lost_active) override; | |
94 | |
95 // display::DisplayObserver overrides: | |
96 void OnDisplayAdded(const display::Display& display) override; | |
97 void OnDisplayRemoved(const display::Display& old_display) override; | |
98 void OnDisplayMetricsChanged(const display::Display& display, | |
99 uint32_t metrics) override; | |
100 | |
101 ShelfModel* model_; | |
102 | |
103 ContainerWindowObserver container_window_observer_; | |
104 UserWindowObserver user_window_observer_; | |
105 | |
106 ScopedObserver<WmWindow, ContainerWindowObserver> observed_container_windows_; | |
107 ScopedObserver<WmWindow, UserWindowObserver> observed_user_windows_; | |
108 | |
109 DISALLOW_COPY_AND_ASSIGN(ShelfWindowWatcher); | |
110 }; | |
111 | |
112 } // namespace ash | |
113 | |
114 #endif // ASH_SHELF_SHELF_WINDOW_WATCHER_H_ | |
OLD | NEW |