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/launcher/launcher_icon_observer.h"
13 #include "ash/shelf/shelf_layout_manager_observer.h"
14 #include "ash/shell_observer.h"
15 #include "base/basictypes.h"
16 #include "base/compiler_specific.h"
17 #include "base/memory/scoped_ptr.h"
18 #include "base/memory/weak_ptr.h"
19 #include "ui/aura/client/activation_change_observer.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"
41 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 ash::LauncherIconObserver
,
56 public ash::ShellObserver
,
57 public aura::WindowObserver
,
58 public aura::client::ActivationChangeObserver
,
59 public keyboard::KeyboardControllerObserver
,
60 public DisplayController::Observer
,
61 public ShelfLayoutManagerObserver
{
63 explicit PanelLayoutManager(aura::Window
* panel_container
);
64 virtual ~PanelLayoutManager();
66 // Call Shutdown() before deleting children of panel_container.
69 void StartDragging(aura::Window
* panel
);
70 void FinishDragging();
72 void ToggleMinimize(aura::Window
* panel
);
74 ash::Launcher
* launcher() { return launcher_
; }
75 void SetLauncher(ash::Launcher
* launcher
);
77 // Overridden from aura::LayoutManager:
78 virtual void OnWindowResized() OVERRIDE
;
79 virtual void OnWindowAddedToLayout(aura::Window
* child
) OVERRIDE
;
80 virtual void OnWillRemoveWindowFromLayout(aura::Window
* child
) OVERRIDE
;
81 virtual void OnWindowRemovedFromLayout(aura::Window
* child
) OVERRIDE
;
82 virtual void OnChildWindowVisibilityChanged(aura::Window
* child
,
83 bool visibile
) OVERRIDE
;
84 virtual void SetChildBounds(aura::Window
* child
,
85 const gfx::Rect
& requested_bounds
) OVERRIDE
;
87 // Overridden from ash::LauncherIconObserver
88 virtual void OnLauncherIconPositionsChanged() OVERRIDE
;
90 // Overridden from ash::ShellObserver
91 virtual void OnShelfAlignmentChanged(aura::RootWindow
* root_window
) OVERRIDE
;
93 // Overridden from aura::WindowObserver
94 virtual void OnWindowPropertyChanged(aura::Window
* window
,
96 intptr_t old
) OVERRIDE
;
97 virtual void OnWindowVisibilityChanged(aura::Window
* window
,
98 bool visible
) OVERRIDE
;
100 // Overridden from aura::client::ActivationChangeObserver
101 virtual void OnWindowActivated(aura::Window
* gained_active
,
102 aura::Window
* lost_active
) OVERRIDE
;
104 // Overridden from DisplayController::Observer
105 virtual void OnDisplayConfigurationChanged() OVERRIDE
;
107 // Overridden from ShelfLayoutManagerObserver
108 virtual void WillChangeVisibilityState(
109 ShelfVisibilityState new_state
) OVERRIDE
;
112 friend class PanelLayoutManagerTest
;
113 friend class PanelWindowResizerTest
;
114 friend class DockedWindowResizerTest
;
115 friend class DockedWindowLayoutManagerTest
;
117 views::Widget
* CreateCalloutWidget();
120 PanelInfo() : window(NULL
), callout_widget(NULL
), slide_in(false) {}
122 bool operator==(const aura::Window
* other_window
) const {
123 return window
== other_window
;
126 // A weak pointer to the panel window.
127 aura::Window
* window
;
128 // The callout widget for this panel. This pointer must be managed
129 // manually as this structure is used in a std::list. See
130 // http://www.chromium.org/developers/smart-pointer-guidelines
131 PanelCalloutWidget
* callout_widget
;
133 // True on new and restored panel windows until the panel has been
134 // positioned. The first time Relayout is called the panel will slide into
135 // position and this will be set to false.
139 typedef std::list
<PanelInfo
> PanelList
;
141 void MinimizePanel(aura::Window
* panel
);
142 void RestorePanel(aura::Window
* panel
);
144 // Called whenever the panel layout might change.
147 // Called whenever the panel stacking order needs to be updated (e.g. focus
148 // changes or a panel is moved).
149 void UpdateStacking(aura::Window
* active_panel
);
151 // Update the callout arrows for all managed panels.
152 void UpdateCallouts();
154 // Overridden from keyboard::KeyboardControllerObserver:
155 virtual void OnKeyboardBoundsChanging(
156 const gfx::Rect
& keyboard_bounds
) OVERRIDE
;
158 // Parent window associated with this layout manager.
159 aura::Window
* panel_container_
;
160 // Protect against recursive calls to OnWindowAddedToLayout().
162 // Protect against recursive calls to Relayout().
164 // Ordered list of unowned pointers to panel windows.
165 PanelList panel_windows_
;
166 // The panel being dragged.
167 aura::Window
* dragged_panel_
;
168 // The launcher we are observing for launcher icon changes.
170 // The shelf layout manager being observed for visibility changes.
171 ShelfLayoutManager
* shelf_layout_manager_
;
172 // Tracks the visibility of the shelf. Defaults to false when there is no
175 // The last active panel. Used to maintain stacking order even if no panels
176 // are currently focused.
177 aura::Window
* last_active_panel_
;
178 base::WeakPtrFactory
<PanelLayoutManager
> weak_factory_
;
180 DISALLOW_COPY_AND_ASSIGN(PanelLayoutManager
);
183 } // namespace internal
186 #endif // ASH_WM_PANELS_PANEL_LAYOUT_MANAGER_H_