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