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.
5 #ifndef ASH_WM_PANELS_PANEL_LAYOUT_MANAGER_H_
6 #define ASH_WM_PANELS_PANEL_LAYOUT_MANAGER_H_
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"
40 class PanelCalloutWidget
;
42 class ShelfLayoutManager
;
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.
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));
53 class ASH_EXPORT PanelLayoutManager
54 : public aura::LayoutManager
,
55 public ShelfIconObserver
,
57 public aura::WindowObserver
,
58 public wm::WindowStateObserver
,
59 public aura::client::ActivationChangeObserver
,
60 public keyboard::KeyboardControllerObserver
,
61 public DisplayController::Observer
,
62 public ShelfLayoutManagerObserver
{
64 explicit PanelLayoutManager(aura::Window
* panel_container
);
65 virtual ~PanelLayoutManager();
67 // Call Shutdown() before deleting children of panel_container.
70 void StartDragging(aura::Window
* panel
);
71 void FinishDragging();
73 void ToggleMinimize(aura::Window
* panel
);
75 // Returns the callout widget (arrow) for |panel|.
76 views::Widget
* GetCalloutWidgetForPanel(aura::Window
* panel
);
78 Shelf
* shelf() { return shelf_
; }
79 void SetShelf(Shelf
* shelf
);
81 // Overridden from aura::LayoutManager:
82 virtual void OnWindowResized() OVERRIDE
;
83 virtual void OnWindowAddedToLayout(aura::Window
* child
) OVERRIDE
;
84 virtual void OnWillRemoveWindowFromLayout(aura::Window
* child
) OVERRIDE
;
85 virtual void OnWindowRemovedFromLayout(aura::Window
* child
) OVERRIDE
;
86 virtual void OnChildWindowVisibilityChanged(aura::Window
* child
,
87 bool visibile
) OVERRIDE
;
88 virtual void SetChildBounds(aura::Window
* child
,
89 const gfx::Rect
& requested_bounds
) OVERRIDE
;
91 // Overridden from ShelfIconObserver
92 virtual void OnShelfIconPositionsChanged() OVERRIDE
;
94 // Overridden from ShellObserver
95 virtual void OnShelfAlignmentChanged(aura::Window
* root_window
) OVERRIDE
;
97 // Overridden from aura::WindowObserver
98 virtual void OnWindowPropertyChanged(aura::Window
* window
,
100 intptr_t old
) OVERRIDE
;
102 // Overridden from ash::wm::WindowStateObserver
103 virtual void OnPostWindowStateTypeChange(
104 wm::WindowState
* window_state
,
105 wm::WindowStateType old_type
) OVERRIDE
;
107 // Overridden from aura::client::ActivationChangeObserver
108 virtual void OnWindowActivated(aura::Window
* gained_active
,
109 aura::Window
* lost_active
) OVERRIDE
;
111 // Overridden from DisplayController::Observer
112 virtual void OnDisplayConfigurationChanged() OVERRIDE
;
114 // Overridden from ShelfLayoutManagerObserver
115 virtual void WillChangeVisibilityState(
116 ShelfVisibilityState new_state
) OVERRIDE
;
119 friend class PanelLayoutManagerTest
;
120 friend class PanelWindowResizerTest
;
121 friend class DockedWindowResizerTest
;
122 friend class DockedWindowLayoutManagerTest
;
123 friend class WorkspaceControllerTest
;
125 views::Widget
* CreateCalloutWidget();
128 PanelInfo() : window(NULL
), callout_widget(NULL
), slide_in(false) {}
130 bool operator==(const aura::Window
* other_window
) const {
131 return window
== other_window
;
134 // A weak pointer to the panel window.
135 aura::Window
* window
;
136 // The callout widget for this panel. This pointer must be managed
137 // manually as this structure is used in a std::list. See
138 // http://www.chromium.org/developers/smart-pointer-guidelines
139 PanelCalloutWidget
* callout_widget
;
141 // True on new and restored panel windows until the panel has been
142 // positioned. The first time Relayout is called the panel will be shown,
143 // and slide into position and this will be set to false.
147 typedef std::list
<PanelInfo
> PanelList
;
149 void MinimizePanel(aura::Window
* panel
);
150 void RestorePanel(aura::Window
* panel
);
152 // Called whenever the panel layout might change.
155 // Called whenever the panel stacking order needs to be updated (e.g. focus
156 // changes or a panel is moved).
157 void UpdateStacking(aura::Window
* active_panel
);
159 // Update the callout arrows for all managed panels.
160 void UpdateCallouts();
162 // Overridden from keyboard::KeyboardControllerObserver:
163 virtual void OnKeyboardBoundsChanging(
164 const gfx::Rect
& keyboard_bounds
) OVERRIDE
;
166 // Parent window associated with this layout manager.
167 aura::Window
* panel_container_
;
168 // Protect against recursive calls to OnWindowAddedToLayout().
170 // Protect against recursive calls to Relayout().
172 // Ordered list of unowned pointers to panel windows.
173 PanelList panel_windows_
;
174 // The panel being dragged.
175 aura::Window
* dragged_panel_
;
176 // The shelf we are observing for shelf icon changes.
178 // The shelf layout manager being observed for visibility changes.
179 ShelfLayoutManager
* shelf_layout_manager_
;
181 // When not NULL, the shelf is hidden (i.e. full screen) and this tracks the
182 // set of panel windows which have been temporarily hidden and need to be
183 // restored when the shelf becomes visible again.
184 scoped_ptr
<aura::WindowTracker
> restore_windows_on_shelf_visible_
;
186 // The last active panel. Used to maintain stacking order even if no panels
187 // are currently focused.
188 aura::Window
* last_active_panel_
;
189 base::WeakPtrFactory
<PanelLayoutManager
> weak_factory_
;
191 DISALLOW_COPY_AND_ASSIGN(PanelLayoutManager
);
196 #endif // ASH_WM_PANELS_PANEL_LAYOUT_MANAGER_H_