usb_gadget: Switch to official Google product IDs.
[chromium-blink-merge.git] / ash / shelf / shelf_window_watcher.h
blobda16e54f7da0833730ebef7a4b9ea7afdfcf1a41
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 virtual ~ShelfWindowWatcher();
42 private:
43 class RootWindowObserver : public aura::WindowObserver {
44 public:
45 explicit RootWindowObserver(ShelfWindowWatcher* window_watcher);
46 virtual ~RootWindowObserver();
48 private:
49 // aura::WindowObserver overrides:
50 virtual 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 virtual ~RemovedWindowObserver();
65 private:
66 // aura::WindowObserver overrides:
67 virtual void OnWindowParentChanged(aura::Window* window,
68 aura::Window* parent) OVERRIDE;
69 virtual 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 virtual void OnWindowActivated(aura::Window* gained_active,
107 aura::Window* lost_active) OVERRIDE;
109 // aura::WindowObserver overrides:
110 virtual void OnWindowAdded(aura::Window* window) OVERRIDE;
111 virtual void OnWillRemoveWindow(aura::Window* window) OVERRIDE;
112 virtual void OnWindowDestroying(aura::Window* window) OVERRIDE;
113 virtual void OnWindowPropertyChanged(aura::Window* window,
114 const void* key,
115 intptr_t old) OVERRIDE;
117 // gfx::DisplayObserver overrides:
118 virtual void OnDisplayAdded(const gfx::Display& display) OVERRIDE;
119 virtual void OnDisplayRemoved(const gfx::Display& old_display) OVERRIDE;
120 virtual void OnDisplayMetricsChanged(const gfx::Display& display,
121 uint32_t metrics) OVERRIDE;
123 // Owned by Shell.
124 ShelfModel* model_;
125 ShelfItemDelegateManager* item_delegate_manager_;
127 RootWindowObserver root_window_observer_;
129 RemovedWindowObserver removed_window_observer_;
131 // Holds all observed windows.
132 ScopedObserver<aura::Window, aura::WindowObserver> observed_windows_;
134 // Holds all observed root windows.
135 ScopedObserver<aura::Window, aura::WindowObserver> observed_root_windows_;
137 // Holds removed windows that has an item from default container.
138 ScopedObserver<aura::Window, aura::WindowObserver> observed_removed_windows_;
140 // Holds all observed activation clients.
141 ScopedObserverWithDuplicatedSources<aura::client::ActivationClient,
142 aura::client::ActivationChangeObserver> observed_activation_clients_;
144 DISALLOW_COPY_AND_ASSIGN(ShelfWindowWatcher);
147 } // namespace ash
149 #endif // ASH_SHELF_SHELF_WINDOW_WATCHER_H_