Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / ash / shelf / shelf_window_watcher.h
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/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"
16
17 namespace aura {
18
19 class Window;
20
21 namespace client {
22 class ActivationClient;
23 }
24
25 }  // namespace aura
26
27 namespace ash {
28
29 class ShelfModel;
30 class ShelfItemDelegateManager;
31
32 namespace internal {
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 {
38  public:
39   ShelfWindowWatcher(ShelfModel* model,
40                      ShelfItemDelegateManager* item_delegate_manager);
41   virtual ~ShelfWindowWatcher();
42
43  private:
44   class RootWindowObserver : public aura::WindowObserver {
45    public:
46     explicit RootWindowObserver(ShelfWindowWatcher* window_watcher);
47     virtual ~RootWindowObserver();
48
49    private:
50     // aura::WindowObserver overrides:
51     virtual void OnWindowDestroying(aura::Window* window) OVERRIDE;
52
53     // Owned by Shell.
54     ShelfWindowWatcher* window_watcher_;
55
56     DISALLOW_COPY_AND_ASSIGN(RootWindowObserver);
57   };
58
59   // Used to track windows that are removed. See description of
60   // ShelfWindowWatcher::StartObservingRemovedWindow() for more details.
61   class RemovedWindowObserver : public aura::WindowObserver {
62    public:
63     explicit RemovedWindowObserver(ShelfWindowWatcher* window_watcher);
64     virtual ~RemovedWindowObserver();
65
66    private:
67     // aura::WindowObserver overrides:
68     virtual void OnWindowParentChanged(aura::Window* window,
69                                        aura::Window* parent) OVERRIDE;
70     virtual void OnWindowDestroyed(aura::Window* window) OVERRIDE;
71
72     // Owned by Shell.
73     ShelfWindowWatcher* window_watcher_;
74
75     DISALLOW_COPY_AND_ASSIGN(RemovedWindowObserver);
76   };
77
78   // Creates a ShelfItem for |window| that has ShelfItemDetails.
79   void AddShelfItem(aura::Window* window);
80
81   // Removes a ShelfItem for |window|.
82   void RemoveShelfItem(aura::Window* window);
83
84   // Adds observer to default container and ActivationClient of |root_window|.
85   void OnRootWindowAdded(aura::Window* root_window);
86
87   // Removes observer from ActivationClient of |root_window|.
88   void OnRootWindowRemoved(aura::Window* root_window);
89
90   // Updates the status of ShelfItem for |window|.
91   void UpdateShelfItemStatus(aura::Window* window, bool is_active);
92
93   // Returns the index of ShelfItem associated with |window|.
94   int GetShelfItemIndexForWindow(aura::Window* window) const;
95
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);
101
102   // Stop observing |window| by RemovedWindowObserver and remove an item
103   // associated with |window|.
104   void FinishObservingRemovedWindow(aura::Window* window);
105
106   // aura::client::ActivationChangeObserver overrides:
107   virtual void OnWindowActivated(aura::Window* gained_active,
108                                  aura::Window* lost_active) OVERRIDE;
109
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,
115                                        const void* key,
116                                        intptr_t old) OVERRIDE;
117
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;
122
123   // Owned by Shell.
124   ShelfModel* model_;
125   ShelfItemDelegateManager* item_delegate_manager_;
126
127   RootWindowObserver root_window_observer_;
128
129   RemovedWindowObserver removed_window_observer_;
130
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
140   // Holds all observed activation clients.
141   ScopedObserverWithDuplicatedSources<aura::client::ActivationClient,
142       aura::client::ActivationChangeObserver> observed_activation_clients_;
143
144   DISALLOW_COPY_AND_ASSIGN(ShelfWindowWatcher);
145 };
146
147 }  // namespace internal
148 }  // namespace ash
149
150 #endif  // ASH_SHELF_SHELF_WINDOW_WATCHER_H_