Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / ash / wm / panels / panel_layout_manager.h
1 // Copyright (c) 2012 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_WM_PANELS_PANEL_LAYOUT_MANAGER_H_
6 #define ASH_WM_PANELS_PANEL_LAYOUT_MANAGER_H_
7
8 #include <list>
9
10 #include "ash/ash_export.h"
11 #include "ash/display/display_controller.h"
12 #include "ash/shelf/shelf_icon_observer.h"
13 #include "ash/shelf/shelf_layout_manager_observer.h"
14 #include "ash/shell_observer.h"
15 #include "ash/wm/window_state_observer.h"
16 #include "base/basictypes.h"
17 #include "base/compiler_specific.h"
18 #include "base/memory/scoped_ptr.h"
19 #include "base/memory/weak_ptr.h"
20 #include "ui/aura/layout_manager.h"
21 #include "ui/aura/window_observer.h"
22 #include "ui/keyboard/keyboard_controller.h"
23 #include "ui/keyboard/keyboard_controller_observer.h"
24 #include "ui/wm/public/activation_change_observer.h"
25
26 namespace aura {
27 class Window;
28 class WindowTracker;
29 }
30
31 namespace gfx {
32 class Rect;
33 }
34
35 namespace views {
36 class Widget;
37 }
38
39 namespace ash {
40 class PanelCalloutWidget;
41 class Shelf;
42 class ShelfLayoutManager;
43
44 // PanelLayoutManager is responsible for organizing panels within the
45 // workspace. It is associated with a specific container window (i.e.
46 // kShellWindowId_PanelContainer) and controls the layout of any windows
47 // added to that container.
48 //
49 // The constructor takes a |panel_container| argument which is expected to set
50 // its layout manager to this instance, e.g.:
51 // panel_container->SetLayoutManager(new PanelLayoutManager(panel_container));
52
53 class ASH_EXPORT PanelLayoutManager
54     : public aura::LayoutManager,
55       public ShelfIconObserver,
56       public ShellObserver,
57       public aura::WindowObserver,
58       public wm::WindowStateObserver,
59       public aura::client::ActivationChangeObserver,
60       public keyboard::KeyboardControllerObserver,
61       public DisplayController::Observer,
62       public ShelfLayoutManagerObserver {
63  public:
64   explicit PanelLayoutManager(aura::Window* panel_container);
65   ~PanelLayoutManager() override;
66
67   // Call Shutdown() before deleting children of panel_container.
68   void Shutdown();
69
70   void StartDragging(aura::Window* panel);
71   void FinishDragging();
72
73   void ToggleMinimize(aura::Window* panel);
74
75   // Hide / Show the panel callout widgets.
76   void SetShowCalloutWidgets(bool show);
77
78   // Returns the callout widget (arrow) for |panel|.
79   views::Widget* GetCalloutWidgetForPanel(aura::Window* panel);
80
81   Shelf* shelf() { return shelf_; }
82   void SetShelf(Shelf* shelf);
83
84   // Overridden from aura::LayoutManager:
85   void OnWindowResized() override;
86   void OnWindowAddedToLayout(aura::Window* child) override;
87   void OnWillRemoveWindowFromLayout(aura::Window* child) override;
88   void OnWindowRemovedFromLayout(aura::Window* child) override;
89   void OnChildWindowVisibilityChanged(aura::Window* child,
90                                       bool visibile) override;
91   void SetChildBounds(aura::Window* child,
92                       const gfx::Rect& requested_bounds) override;
93
94   // Overridden from ShelfIconObserver
95   void OnShelfIconPositionsChanged() override;
96
97   // Overridden from ShellObserver
98   void OnShelfAlignmentChanged(aura::Window* root_window) override;
99
100   // Overridden from aura::WindowObserver
101   void OnWindowPropertyChanged(aura::Window* window,
102                                const void* key,
103                                intptr_t old) override;
104
105   // Overridden from ash::wm::WindowStateObserver
106   void OnPostWindowStateTypeChange(wm::WindowState* window_state,
107                                    wm::WindowStateType old_type) override;
108
109   // Overridden from aura::client::ActivationChangeObserver
110   void OnWindowActivated(aura::Window* gained_active,
111                          aura::Window* lost_active) override;
112
113   // Overridden from DisplayController::Observer
114   void OnDisplayConfigurationChanged() override;
115
116   // Overridden from ShelfLayoutManagerObserver
117   void WillChangeVisibilityState(ShelfVisibilityState new_state) override;
118
119  private:
120   friend class PanelLayoutManagerTest;
121   friend class PanelWindowResizerTest;
122   friend class DockedWindowResizerTest;
123   friend class DockedWindowLayoutManagerTest;
124   friend class WorkspaceControllerTest;
125   friend class AcceleratorControllerTest;
126
127   views::Widget* CreateCalloutWidget();
128
129   struct PanelInfo{
130     PanelInfo() : window(NULL), callout_widget(NULL), slide_in(false) {}
131
132     bool operator==(const aura::Window* other_window) const {
133       return window == other_window;
134     }
135
136     // A weak pointer to the panel window.
137     aura::Window* window;
138     // The callout widget for this panel. This pointer must be managed
139     // manually as this structure is used in a std::list. See
140     // http://www.chromium.org/developers/smart-pointer-guidelines
141     PanelCalloutWidget* callout_widget;
142
143     // True on new and restored panel windows until the panel has been
144     // positioned. The first time Relayout is called the panel will be shown,
145     // and slide into position and this will be set to false.
146     bool slide_in;
147   };
148
149   typedef std::list<PanelInfo> PanelList;
150
151   void MinimizePanel(aura::Window* panel);
152   void RestorePanel(aura::Window* panel);
153
154   // Called whenever the panel layout might change.
155   void Relayout();
156
157   // Called whenever the panel stacking order needs to be updated (e.g. focus
158   // changes or a panel is moved).
159   void UpdateStacking(aura::Window* active_panel);
160
161   // Update the callout arrows for all managed panels.
162   void UpdateCallouts();
163
164   // Overridden from keyboard::KeyboardControllerObserver:
165   void OnKeyboardBoundsChanging(const gfx::Rect& keyboard_bounds) override;
166
167   // Parent window associated with this layout manager.
168   aura::Window* panel_container_;
169   // Protect against recursive calls to OnWindowAddedToLayout().
170   bool in_add_window_;
171   // Protect against recursive calls to Relayout().
172   bool in_layout_;
173   // Indicates if the panel callout widget should be created.
174   bool show_callout_widgets_;
175   // Ordered list of unowned pointers to panel windows.
176   PanelList panel_windows_;
177   // The panel being dragged.
178   aura::Window* dragged_panel_;
179   // The shelf we are observing for shelf icon changes.
180   Shelf* shelf_;
181   // The shelf layout manager being observed for visibility changes.
182   ShelfLayoutManager* shelf_layout_manager_;
183
184   // When not NULL, the shelf is hidden (i.e. full screen) and this tracks the
185   // set of panel windows which have been temporarily hidden and need to be
186   // restored when the shelf becomes visible again.
187   scoped_ptr<aura::WindowTracker> restore_windows_on_shelf_visible_;
188
189   // The last active panel. Used to maintain stacking order even if no panels
190   // are currently focused.
191   aura::Window* last_active_panel_;
192   base::WeakPtrFactory<PanelLayoutManager> weak_factory_;
193
194   DISALLOW_COPY_AND_ASSIGN(PanelLayoutManager);
195 };
196
197 }  // namespace ash
198
199 #endif  // ASH_WM_PANELS_PANEL_LAYOUT_MANAGER_H_