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_PANEL_LAYOUT_MANAGER_H_
6 #define ASH_WM_PANEL_LAYOUT_MANAGER_H_
10 #include "ash/ash_export.h"
11 #include "ash/launcher/launcher_icon_observer.h"
12 #include "base/basictypes.h"
13 #include "base/compiler_specific.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/memory/weak_ptr.h"
16 #include "ui/aura/client/activation_change_observer.h"
17 #include "ui/aura/layout_manager.h"
18 #include "ui/aura/window_observer.h"
37 // PanelLayoutManager is responsible for organizing panels within the
38 // workspace. It is associated with a specific container window (i.e.
39 // kShellWindowId_PanelContainer) and controls the layout of any windows
40 // added to that container.
42 // The constructor takes a |panel_container| argument which is expected to set
43 // its layout manager to this instance, e.g.:
44 // panel_container->SetLayoutManager(new PanelLayoutManager(panel_container));
46 class ASH_EXPORT PanelLayoutManager
47 : public aura::LayoutManager
,
48 public ash::LauncherIconObserver
,
49 public aura::WindowObserver
,
50 public aura::client::ActivationChangeObserver
{
52 explicit PanelLayoutManager(aura::Window
* panel_container
);
53 virtual ~PanelLayoutManager();
55 void StartDragging(aura::Window
* panel
);
56 void FinishDragging();
58 void ToggleMinimize(aura::Window
* panel
);
60 void SetLauncher(ash::Launcher
* launcher
);
62 // Overridden from aura::LayoutManager:
63 virtual void OnWindowResized() OVERRIDE
;
64 virtual void OnWindowAddedToLayout(aura::Window
* child
) OVERRIDE
;
65 virtual void OnWillRemoveWindowFromLayout(aura::Window
* child
) OVERRIDE
;
66 virtual void OnWindowRemovedFromLayout(aura::Window
* child
) OVERRIDE
;
67 virtual void OnChildWindowVisibilityChanged(aura::Window
* child
,
68 bool visibile
) OVERRIDE
;
69 virtual void SetChildBounds(aura::Window
* child
,
70 const gfx::Rect
& requested_bounds
) OVERRIDE
;
72 // Overridden from ash::LauncherIconObserver
73 virtual void OnLauncherIconPositionsChanged() OVERRIDE
;
75 // Overridden from aura::WindowObserver
76 virtual void OnWindowPropertyChanged(aura::Window
* window
,
78 intptr_t old
) OVERRIDE
;
80 // Overridden from aura::client::ActivationChangeObserver
81 virtual void OnWindowActivated(aura::Window
* gained_active
,
82 aura::Window
* lost_active
) OVERRIDE
;
85 friend class PanelLayoutManagerTest
;
87 typedef std::list
<aura::Window
*> PanelList
;
89 void MinimizePanel(aura::Window
* panel
);
90 void RestorePanel(aura::Window
* panel
);
92 // Called whenever the panel layout might change.
95 // Called whenever the panel stacking order needs to be updated (e.g. focus
96 // changes or a panel is moved).
97 void UpdateStacking(aura::Window
* active_panel
);
99 // Trigger a delayed task to update the callout. We use this because
100 // otherwise, ShadowController::OnWindowPropertyChanged may be invoked after
101 // we've already updated the callout, causing the drop shadow to be stacked on
102 // top of the callout rather than the other way around.
103 // TODO(dcheng): Possibly a bug in the shadow controller. If a window is
104 // focused but not stacked at the top, I don't think its shadow should be
105 // drawn on top of "higher" windows.
106 void UpdateCallout(aura::Window
* active_window
);
108 // Don't call this directly. Only UpdateCallout() should call this method.
109 void ShowCalloutHelper(aura::Window
* active_panel
);
112 views::Widget
* callout_widget() const { return callout_widget_
.get(); }
114 // Parent window associated with this layout manager.
115 aura::Window
* panel_container_
;
116 // Protect against recursive calls to Relayout().
118 // Ordered list of unowned pointers to panel windows.
119 PanelList panel_windows_
;
120 // The panel being dragged.
121 aura::Window
* dragged_panel_
;
122 // The launcher we are observing for launcher icon changes.
124 // The last active panel. Used to maintain stacking even if no panels are
125 // currently focused.
126 aura::Window
* last_active_panel_
;
127 // Manage the callout for the focused panel, if any.
128 scoped_ptr
<views::Widget
> callout_widget_
;
129 base::WeakPtrFactory
<PanelLayoutManager
> weak_factory_
;
131 DISALLOW_COPY_AND_ASSIGN(PanelLayoutManager
);
134 } // namespace internal
137 #endif // ASH_WM_PANEL_LAYOUT_MANAGER_H_