Updating XTBs based on .GRDs from branch master
[chromium-blink-merge.git] / ash / shelf / shelf_window_watcher.h
blobc9ffcbf7db9ec2136d7dff3039027f14b9e23e1f
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.
5 #ifndef ASH_SHELF_SHELF_WINDOW_WATCHER_H_
6 #define ASH_SHELF_SHELF_WINDOW_WATCHER_H_
8 #include "ash/shelf/scoped_observer_with_duplicated_sources.h"
9 #include "base/basictypes.h"
10 #include "base/compiler_specific.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/scoped_observer.h"
13 #include "ui/aura/window_observer.h"
14 #include "ui/gfx/display_observer.h"
15 #include "ui/wm/public/activation_change_observer.h"
17 namespace aura {
19 class Window;
21 namespace client {
22 class ActivationClient;
25 } // namespace aura
27 namespace ash {
29 class ShelfModel;
30 class ShelfItemDelegateManager;
32 // ShelfWindowWatcher creates and handles a ShelfItem for windows that have
33 // a ShelfItemDetails property in the default container.
34 class ShelfWindowWatcher : public aura::client::ActivationChangeObserver,
35 public aura::WindowObserver,
36 public gfx::DisplayObserver {
37 public:
38 ShelfWindowWatcher(ShelfModel* model,
39 ShelfItemDelegateManager* item_delegate_manager);
40 ~ShelfWindowWatcher() override;
42 private:
43 class RootWindowObserver : public aura::WindowObserver {
44 public:
45 explicit RootWindowObserver(ShelfWindowWatcher* window_watcher);
46 ~RootWindowObserver() override;
48 private:
49 // aura::WindowObserver overrides:
50 void OnWindowDestroying(aura::Window* window) override;
52 // Owned by Shell.
53 ShelfWindowWatcher* window_watcher_;
55 DISALLOW_COPY_AND_ASSIGN(RootWindowObserver);
58 // Used to track windows that are removed. See description of
59 // ShelfWindowWatcher::StartObservingRemovedWindow() for more details.
60 class RemovedWindowObserver : public aura::WindowObserver {
61 public:
62 explicit RemovedWindowObserver(ShelfWindowWatcher* window_watcher);
63 ~RemovedWindowObserver() override;
65 private:
66 // aura::WindowObserver overrides:
67 void OnWindowParentChanged(aura::Window* window,
68 aura::Window* parent) override;
69 void OnWindowDestroyed(aura::Window* window) override;
71 // Owned by Shell.
72 ShelfWindowWatcher* window_watcher_;
74 DISALLOW_COPY_AND_ASSIGN(RemovedWindowObserver);
77 // Creates a ShelfItem for |window| that has ShelfItemDetails.
78 void AddShelfItem(aura::Window* window);
80 // Removes a ShelfItem for |window|.
81 void RemoveShelfItem(aura::Window* window);
83 // Adds observer to default container and ActivationClient of |root_window|.
84 void OnRootWindowAdded(aura::Window* root_window);
86 // Removes observer from ActivationClient of |root_window|.
87 void OnRootWindowRemoved(aura::Window* root_window);
89 // Updates the status of ShelfItem for |window|.
90 void UpdateShelfItemStatus(aura::Window* window, bool is_active);
92 // Returns the index of ShelfItem associated with |window|.
93 int GetShelfItemIndexForWindow(aura::Window* window) const;
95 // Used when a window is removed. During the dragging a window may be removed
96 // and when the drag completes added back. When this happens we don't want to
97 // remove the shelf item. StartObservingRemovedWindow, if necessary, attaches
98 // an observer. When done, FinishObservingRemovedWindow() is invoked.
99 void StartObservingRemovedWindow(aura::Window* window);
101 // Stop observing |window| by RemovedWindowObserver and remove an item
102 // associated with |window|.
103 void FinishObservingRemovedWindow(aura::Window* window);
105 // aura::client::ActivationChangeObserver overrides:
106 void OnWindowActivated(
107 aura::client::ActivationChangeObserver::ActivationReason reason,
108 aura::Window* gained_active,
109 aura::Window* lost_active) override;
111 // aura::WindowObserver overrides:
112 void OnWindowAdded(aura::Window* window) override;
113 void OnWillRemoveWindow(aura::Window* window) override;
114 void OnWindowDestroying(aura::Window* window) override;
115 void OnWindowPropertyChanged(aura::Window* window,
116 const void* key,
117 intptr_t old) override;
119 // gfx::DisplayObserver overrides:
120 void OnDisplayAdded(const gfx::Display& display) override;
121 void OnDisplayRemoved(const gfx::Display& old_display) override;
122 void OnDisplayMetricsChanged(const gfx::Display& display,
123 uint32_t metrics) override;
125 // Owned by Shell.
126 ShelfModel* model_;
127 ShelfItemDelegateManager* item_delegate_manager_;
129 RootWindowObserver root_window_observer_;
131 RemovedWindowObserver removed_window_observer_;
133 // Holds all observed windows.
134 ScopedObserver<aura::Window, aura::WindowObserver> observed_windows_;
136 // Holds all observed root windows.
137 ScopedObserver<aura::Window, aura::WindowObserver> observed_root_windows_;
139 // Holds removed windows that has an item from default container.
140 ScopedObserver<aura::Window, aura::WindowObserver> observed_removed_windows_;
142 // Holds all observed activation clients.
143 ScopedObserverWithDuplicatedSources<aura::client::ActivationClient,
144 aura::client::ActivationChangeObserver> observed_activation_clients_;
146 DISALLOW_COPY_AND_ASSIGN(ShelfWindowWatcher);
149 } // namespace ash
151 #endif // ASH_SHELF_SHELF_WINDOW_WATCHER_H_