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/client/activation_change_observer.h"
14 #include "ui/aura/window_observer.h"
15 #include "ui/gfx/display_observer.h"
22 class ActivationClient
;
30 class ShelfItemDelegateManager
;
33 // ShelfWindowWatcher creates and handles a ShelfItem for windows that have
34 // a ShelfItemDetails property in the default container.
35 class ShelfWindowWatcher
: public aura::client::ActivationChangeObserver
,
36 public aura::WindowObserver
,
37 public gfx::DisplayObserver
{
39 ShelfWindowWatcher(ShelfModel
* model
,
40 ShelfItemDelegateManager
* item_delegate_manager
);
41 virtual ~ShelfWindowWatcher();
44 class RootWindowObserver
: public aura::WindowObserver
{
46 explicit RootWindowObserver(ShelfWindowWatcher
* window_watcher
);
47 virtual ~RootWindowObserver();
50 // aura::WindowObserver overrides:
51 virtual void OnWindowDestroying(aura::Window
* window
) OVERRIDE
;
54 ShelfWindowWatcher
* window_watcher_
;
56 DISALLOW_COPY_AND_ASSIGN(RootWindowObserver
);
59 // Used to track windows that are removed. See description of
60 // ShelfWindowWatcher::StartObservingRemovedWindow() for more details.
61 class RemovedWindowObserver
: public aura::WindowObserver
{
63 explicit RemovedWindowObserver(ShelfWindowWatcher
* window_watcher
);
64 virtual ~RemovedWindowObserver();
67 // aura::WindowObserver overrides:
68 virtual void OnWindowParentChanged(aura::Window
* window
,
69 aura::Window
* parent
) OVERRIDE
;
70 virtual void OnWindowDestroyed(aura::Window
* window
) OVERRIDE
;
73 ShelfWindowWatcher
* window_watcher_
;
75 DISALLOW_COPY_AND_ASSIGN(RemovedWindowObserver
);
78 // Creates a ShelfItem for |window| that has ShelfItemDetails.
79 void AddShelfItem(aura::Window
* window
);
81 // Removes a ShelfItem for |window|.
82 void RemoveShelfItem(aura::Window
* window
);
84 // Adds observer to default container and ActivationClient of |root_window|.
85 void OnRootWindowAdded(aura::Window
* root_window
);
87 // Removes observer from ActivationClient of |root_window|.
88 void OnRootWindowRemoved(aura::Window
* root_window
);
90 // Updates the status of ShelfItem for |window|.
91 void UpdateShelfItemStatus(aura::Window
* window
, bool is_active
);
93 // Returns the index of ShelfItem associated with |window|.
94 int GetShelfItemIndexForWindow(aura::Window
* window
) const;
96 // Used when a window is removed. During the dragging a window may be removed
97 // and when the drag completes added back. When this happens we don't want to
98 // remove the shelf item. StartObservingRemovedWindow, if necessary, attaches
99 // an observer. When done, FinishObservingRemovedWindow() is invoked.
100 void StartObservingRemovedWindow(aura::Window
* window
);
102 // Stop observing |window| by RemovedWindowObserver and remove an item
103 // associated with |window|.
104 void FinishObservingRemovedWindow(aura::Window
* window
);
106 // aura::client::ActivationChangeObserver overrides:
107 virtual void OnWindowActivated(aura::Window
* gained_active
,
108 aura::Window
* lost_active
) OVERRIDE
;
110 // aura::WindowObserver overrides:
111 virtual void OnWindowAdded(aura::Window
* window
) OVERRIDE
;
112 virtual void OnWillRemoveWindow(aura::Window
* window
) OVERRIDE
;
113 virtual void OnWindowDestroying(aura::Window
* window
) OVERRIDE
;
114 virtual void OnWindowPropertyChanged(aura::Window
* window
,
116 intptr_t old
) OVERRIDE
;
118 // gfx::DisplayObserver overrides:
119 virtual void OnDisplayBoundsChanged(const gfx::Display
& display
) OVERRIDE
;
120 virtual void OnDisplayAdded(const gfx::Display
& display
) OVERRIDE
;
121 virtual void OnDisplayRemoved(const gfx::Display
& old_display
) OVERRIDE
;
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 internal
150 #endif // ASH_SHELF_SHELF_WINDOW_WATCHER_H_