Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(607)

Side by Side Diff: ash/common/wm/dock/docked_window_layout_manager.h

Issue 2035543004: Shuffles and renames ash/common/wm classes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: random changes for chrome tests Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef ASH_COMMON_WM_DOCK_DOCKED_WINDOW_LAYOUT_MANAGER_H_ 5 #ifndef ASH_COMMON_WM_DOCK_DOCKED_WINDOW_LAYOUT_MANAGER_H_
6 #define ASH_COMMON_WM_DOCK_DOCKED_WINDOW_LAYOUT_MANAGER_H_ 6 #define ASH_COMMON_WM_DOCK_DOCKED_WINDOW_LAYOUT_MANAGER_H_
7 7
8 #include <memory> 8 #include <memory>
9 9
10 #include "ash/ash_export.h" 10 #include "ash/ash_export.h"
11 #include "ash/common/wm/dock/dock_types.h" 11 #include "ash/common/wm/dock/dock_types.h"
12 #include "ash/common/wm/dock/docked_window_layout_manager_observer.h" 12 #include "ash/common/wm/dock/docked_window_layout_manager_observer.h"
13 #include "ash/common/wm/window_state_observer.h" 13 #include "ash/common/wm/window_state_observer.h"
14 #include "ash/common/wm/wm_activation_observer.h"
15 #include "ash/common/wm/wm_root_window_controller_observer.h"
16 #include "ash/common/wm/wm_snap_to_pixel_layout_manager.h" 14 #include "ash/common/wm/wm_snap_to_pixel_layout_manager.h"
17 #include "ash/common/wm/wm_window_observer.h" 15 #include "ash/common/wm_activation_observer.h"
16 #include "ash/common/wm_root_window_controller_observer.h"
17 #include "ash/common/wm_window_observer.h"
18 #include "base/compiler_specific.h" 18 #include "base/compiler_specific.h"
19 #include "base/macros.h" 19 #include "base/macros.h"
20 #include "base/observer_list.h" 20 #include "base/observer_list.h"
21 #include "base/time/time.h" 21 #include "base/time/time.h"
22 #include "ui/gfx/geometry/rect.h" 22 #include "ui/gfx/geometry/rect.h"
23 #include "ui/keyboard/keyboard_controller_observer.h" 23 #include "ui/keyboard/keyboard_controller_observer.h"
24 24
25 namespace ash { 25 namespace ash {
26 class DockedBackgroundWidget; 26 class DockedBackgroundWidget;
27 class DockedWindowLayoutManagerObserver; 27 class DockedWindowLayoutManagerObserver;
28 class DockedWindowResizerTest; 28 class DockedWindowResizerTest;
29 class Shelf; 29 class Shelf;
30 class WmRootWindowController;
30 31
31 namespace wm { 32 namespace wm {
32 class WmRootWindowController;
33 class WmShelf; 33 class WmShelf;
34 } 34 }
35 35
36 // DockedWindowLayoutManager is responsible for organizing windows when they are 36 // DockedWindowLayoutManager is responsible for organizing windows when they are
37 // docked to the side of a screen. It is associated with a specific container 37 // docked to the side of a screen. It is associated with a specific container
38 // window (i.e. kShellWindowId_DockedContainer) and controls the layout of any 38 // window (i.e. kShellWindowId_DockedContainer) and controls the layout of any
39 // windows added to that container. 39 // windows added to that container.
40 // 40 //
41 // The constructor takes a |dock_container| argument which is expected to set 41 // The constructor takes a |dock_container| argument which is expected to set
42 // its layout manager to this instance, e.g.: 42 // its layout manager to this instance, e.g.:
43 // dock_container->SetLayoutManager( 43 // dock_container->SetLayoutManager(
44 // new DockedWindowLayoutManager(dock_container)); 44 // new DockedWindowLayoutManager(dock_container));
45 // 45 //
46 // TODO(varkha): extend BaseLayoutManager instead of LayoutManager to inherit 46 // TODO(varkha): extend BaseLayoutManager instead of LayoutManager to inherit
47 // common functionality. 47 // common functionality.
48 class ASH_EXPORT DockedWindowLayoutManager 48 class ASH_EXPORT DockedWindowLayoutManager
49 : public wm::WmSnapToPixelLayoutManager, 49 : public wm::WmSnapToPixelLayoutManager,
50 public wm::WmRootWindowControllerObserver, 50 public WmRootWindowControllerObserver,
51 public wm::WmWindowObserver, 51 public WmWindowObserver,
52 public wm::WmActivationObserver, 52 public WmActivationObserver,
53 public keyboard::KeyboardControllerObserver, 53 public keyboard::KeyboardControllerObserver,
54 public wm::WindowStateObserver { 54 public wm::WindowStateObserver {
55 public: 55 public:
56 // Maximum width of the docked windows area. 56 // Maximum width of the docked windows area.
57 static const int kMaxDockWidth; 57 static const int kMaxDockWidth;
58 58
59 // Minimum width of the docked windows area. 59 // Minimum width of the docked windows area.
60 static const int kMinDockWidth; 60 static const int kMinDockWidth;
61 61
62 explicit DockedWindowLayoutManager(wm::WmWindow* dock_container); 62 explicit DockedWindowLayoutManager(WmWindow* dock_container);
63 ~DockedWindowLayoutManager() override; 63 ~DockedWindowLayoutManager() override;
64 64
65 // Returns the DockedWindowLayoutManager in the specified hierarchy. This 65 // Returns the DockedWindowLayoutManager in the specified hierarchy. This
66 // searches from the root of |window|. 66 // searches from the root of |window|.
67 static DockedWindowLayoutManager* Get(wm::WmWindow* window); 67 static DockedWindowLayoutManager* Get(WmWindow* window);
68 68
69 // Disconnects observers before container windows get destroyed. 69 // Disconnects observers before container windows get destroyed.
70 void Shutdown(); 70 void Shutdown();
71 71
72 // Management of the observer list. 72 // Management of the observer list.
73 virtual void AddObserver(DockedWindowLayoutManagerObserver* observer); 73 virtual void AddObserver(DockedWindowLayoutManagerObserver* observer);
74 virtual void RemoveObserver(DockedWindowLayoutManagerObserver* observer); 74 virtual void RemoveObserver(DockedWindowLayoutManagerObserver* observer);
75 75
76 // Called by a DockedWindowResizer to update which window is being dragged. 76 // Called by a DockedWindowResizer to update which window is being dragged.
77 // Starts observing the window unless it is a child. 77 // Starts observing the window unless it is a child.
78 void StartDragging(wm::WmWindow* window); 78 void StartDragging(WmWindow* window);
79 79
80 // Called by a DockedWindowResizer when a dragged window is docked. 80 // Called by a DockedWindowResizer when a dragged window is docked.
81 void DockDraggedWindow(wm::WmWindow* window); 81 void DockDraggedWindow(WmWindow* window);
82 82
83 // Called by a DockedWindowResizer when a dragged window is no longer docked. 83 // Called by a DockedWindowResizer when a dragged window is no longer docked.
84 void UndockDraggedWindow(); 84 void UndockDraggedWindow();
85 85
86 // Called by a DockedWindowResizer when a window is no longer being dragged. 86 // Called by a DockedWindowResizer when a window is no longer being dragged.
87 // Stops observing the window unless it is a child. 87 // Stops observing the window unless it is a child.
88 // Records |action| by |source| in UMA. 88 // Records |action| by |source| in UMA.
89 void FinishDragging(DockedAction action, DockedActionSource source); 89 void FinishDragging(DockedAction action, DockedActionSource source);
90 90
91 // Checks the rules and possibly updates the docked layout to match 91 // Checks the rules and possibly updates the docked layout to match
92 // the |alignment|. May not apply the |alignment| when 92 // the |alignment|. May not apply the |alignment| when
93 // the current shelf alignment conflicts. Never clears the |alignment_|. 93 // the current shelf alignment conflicts. Never clears the |alignment_|.
94 void MaybeSetDesiredDockedAlignment(DockedAlignment alignment); 94 void MaybeSetDesiredDockedAlignment(DockedAlignment alignment);
95 95
96 wm::WmShelf* shelf() { return shelf_; } 96 wm::WmShelf* shelf() { return shelf_; }
97 void SetShelf(wm::WmShelf* shelf); 97 void SetShelf(wm::WmShelf* shelf);
98 98
99 // Calculates if a window is touching the screen edges and returns edge. 99 // Calculates if a window is touching the screen edges and returns edge.
100 DockedAlignment GetAlignmentOfWindow(const wm::WmWindow* window) const; 100 DockedAlignment GetAlignmentOfWindow(const WmWindow* window) const;
101 101
102 // Used to snap docked windows to the side of screen during drag. 102 // Used to snap docked windows to the side of screen during drag.
103 DockedAlignment CalculateAlignment() const; 103 DockedAlignment CalculateAlignment() const;
104 104
105 void set_preferred_alignment(DockedAlignment preferred_alignment) { 105 void set_preferred_alignment(DockedAlignment preferred_alignment) {
106 preferred_alignment_ = preferred_alignment; 106 preferred_alignment_ = preferred_alignment;
107 } 107 }
108 108
109 void set_event_source(DockedActionSource event_source) { 109 void set_event_source(DockedActionSource event_source) {
110 event_source_ = event_source; 110 event_source_ = event_source;
111 } 111 }
112 112
113 // Returns true when a window can be docked. Windows cannot be docked at the 113 // Returns true when a window can be docked. Windows cannot be docked at the
114 // edge used by the shelf or the edge opposite from existing dock. 114 // edge used by the shelf or the edge opposite from existing dock.
115 bool CanDockWindow(wm::WmWindow* window, DockedAlignment desired_alignment); 115 bool CanDockWindow(WmWindow* window, DockedAlignment desired_alignment);
116 116
117 wm::WmWindow* dock_container() const { return dock_container_; } 117 WmWindow* dock_container() const { return dock_container_; }
118 118
119 // Returns current bounding rectangle of docked windows area. 119 // Returns current bounding rectangle of docked windows area.
120 const gfx::Rect& docked_bounds() const { return docked_bounds_; } 120 const gfx::Rect& docked_bounds() const { return docked_bounds_; }
121 121
122 // Returns last known coordinates of |dragged_window_| after Relayout. 122 // Returns last known coordinates of |dragged_window_| after Relayout.
123 const gfx::Rect dragged_bounds() const { return dragged_bounds_; } 123 const gfx::Rect dragged_bounds() const { return dragged_bounds_; }
124 124
125 // Returns true if currently dragged window is docked at the screen edge. 125 // Returns true if currently dragged window is docked at the screen edge.
126 bool is_dragged_window_docked() const { return is_dragged_window_docked_; } 126 bool is_dragged_window_docked() const { return is_dragged_window_docked_; }
127 127
128 // Updates docked layout when shelf bounds change. 128 // Updates docked layout when shelf bounds change.
129 void OnShelfBoundsChanged(); 129 void OnShelfBoundsChanged();
130 130
131 // SnapLayoutManager: 131 // SnapLayoutManager:
132 void OnWindowResized() override; 132 void OnWindowResized() override;
133 void OnWindowAddedToLayout(wm::WmWindow* child) override; 133 void OnWindowAddedToLayout(WmWindow* child) override;
134 void OnWillRemoveWindowFromLayout(wm::WmWindow* child) override {} 134 void OnWillRemoveWindowFromLayout(WmWindow* child) override {}
135 void OnWindowRemovedFromLayout(wm::WmWindow* child) override; 135 void OnWindowRemovedFromLayout(WmWindow* child) override;
136 void OnChildWindowVisibilityChanged(wm::WmWindow* child, 136 void OnChildWindowVisibilityChanged(WmWindow* child, bool visibile) override;
137 bool visibile) override; 137 void SetChildBounds(WmWindow* child,
138 void SetChildBounds(wm::WmWindow* child,
139 const gfx::Rect& requested_bounds) override; 138 const gfx::Rect& requested_bounds) override;
140 139
141 // wm::WmRootWindowControllerObserver: 140 // WmRootWindowControllerObserver:
142 void OnWorkAreaChanged() override; 141 void OnWorkAreaChanged() override;
143 void OnFullscreenStateChanged(bool is_fullscreen) override; 142 void OnFullscreenStateChanged(bool is_fullscreen) override;
144 void OnShelfAlignmentChanged() override; 143 void OnShelfAlignmentChanged() override;
145 144
146 // wm::WindowStateObserver: 145 // wm::WindowStateObserver:
147 void OnPreWindowStateTypeChange(wm::WindowState* window_state, 146 void OnPreWindowStateTypeChange(wm::WindowState* window_state,
148 wm::WindowStateType old_type) override; 147 wm::WindowStateType old_type) override;
149 148
150 // wm::WmWindowObserver: 149 // WmWindowObserver:
151 void OnWindowBoundsChanged(wm::WmWindow* window, 150 void OnWindowBoundsChanged(WmWindow* window,
152 const gfx::Rect& old_bounds, 151 const gfx::Rect& old_bounds,
153 const gfx::Rect& new_bounds) override; 152 const gfx::Rect& new_bounds) override;
154 void OnWindowVisibilityChanging(wm::WmWindow* window, bool visible) override; 153 void OnWindowVisibilityChanging(WmWindow* window, bool visible) override;
155 void OnWindowDestroying(wm::WmWindow* window) override; 154 void OnWindowDestroying(WmWindow* window) override;
156 155
157 // wm::WmActivationObserver: 156 // WmActivationObserver:
158 void OnWindowActivated(wm::WmWindow* gained_active, 157 void OnWindowActivated(WmWindow* gained_active,
159 wm::WmWindow* lost_active) override; 158 WmWindow* lost_active) override;
160 159
161 private: 160 private:
162 struct CompareMinimumHeight; 161 struct CompareMinimumHeight;
163 struct CompareWindowPos; 162 struct CompareWindowPos;
164 class ShelfWindowObserver; 163 class ShelfWindowObserver;
165 struct WindowWithHeight; 164 struct WindowWithHeight;
166 165
167 friend class DockedWindowLayoutManagerTest; 166 friend class DockedWindowLayoutManagerTest;
168 friend class DockedWindowResizerTest; 167 friend class DockedWindowResizerTest;
169 168
170 // Width of the gap between the docked windows and a workspace. 169 // Width of the gap between the docked windows and a workspace.
171 static const int kMinDockGap; 170 static const int kMinDockGap;
172 171
173 // Ideal (starting) width of the dock. 172 // Ideal (starting) width of the dock.
174 static const int kIdealWidth; 173 static const int kIdealWidth;
175 174
176 // Returns the alignment of the docked windows other than the |child|. 175 // Returns the alignment of the docked windows other than the |child|.
177 DockedAlignment CalculateAlignmentExcept(const wm::WmWindow* child) const; 176 DockedAlignment CalculateAlignmentExcept(const WmWindow* child) const;
178 177
179 // Determines if the |alignment| is applicable taking into account 178 // Determines if the |alignment| is applicable taking into account
180 // the shelf alignment. 179 // the shelf alignment.
181 bool IsDockedAlignmentValid(DockedAlignment alignment) const; 180 bool IsDockedAlignmentValid(DockedAlignment alignment) const;
182 181
183 // Keep at most kMaxVisibleWindows visible in the dock and minimize the rest 182 // Keep at most kMaxVisibleWindows visible in the dock and minimize the rest
184 // (except for |child|). 183 // (except for |child|).
185 void MaybeMinimizeChildrenExcept(wm::WmWindow* child); 184 void MaybeMinimizeChildrenExcept(WmWindow* child);
186 185
187 // Minimize / restore window and relayout. 186 // Minimize / restore window and relayout.
188 void MinimizeDockedWindow(wm::WindowState* window_state); 187 void MinimizeDockedWindow(wm::WindowState* window_state);
189 void RestoreDockedWindow(wm::WindowState* window_state); 188 void RestoreDockedWindow(wm::WindowState* window_state);
190 189
191 // Record user-initiated |action| by |source| in UMA metrics. 190 // Record user-initiated |action| by |source| in UMA metrics.
192 void RecordUmaAction(DockedAction action, DockedActionSource source); 191 void RecordUmaAction(DockedAction action, DockedActionSource source);
193 192
194 // Updates |docked_width_| and UMA histograms. 193 // Updates |docked_width_| and UMA histograms.
195 void UpdateDockedWidth(int width); 194 void UpdateDockedWidth(int width);
196 195
197 // Updates docked layout state when a window gets inside the dock. 196 // Updates docked layout state when a window gets inside the dock.
198 void OnDraggedWindowDocked(wm::WmWindow* window); 197 void OnDraggedWindowDocked(WmWindow* window);
199 198
200 // Updates docked layout state when a window gets outside the dock. 199 // Updates docked layout state when a window gets outside the dock.
201 void OnDraggedWindowUndocked(); 200 void OnDraggedWindowUndocked();
202 201
203 // Returns true if there are any windows currently docked. 202 // Returns true if there are any windows currently docked.
204 bool IsAnyWindowDocked(); 203 bool IsAnyWindowDocked();
205 204
206 // Returns DOCKED_ALIGNMENT_LEFT if the |window|'s left edge is closer to 205 // Returns DOCKED_ALIGNMENT_LEFT if the |window|'s left edge is closer to
207 // the |dock_container_|'s left edge than the |window|'s right edge to 206 // the |dock_container_|'s left edge than the |window|'s right edge to
208 // the |dock_container_|'s right edge. Returns DOCKED_ALIGNMENT_RIGHT 207 // the |dock_container_|'s right edge. Returns DOCKED_ALIGNMENT_RIGHT
209 // otherwise. 208 // otherwise.
210 DockedAlignment GetEdgeNearestWindow(const wm::WmWindow* window) const; 209 DockedAlignment GetEdgeNearestWindow(const WmWindow* window) const;
211 210
212 // Called whenever the window layout might change. 211 // Called whenever the window layout might change.
213 void Relayout(); 212 void Relayout();
214 213
215 // Calculates target heights (and fills it in |visible_windows| array) such 214 // Calculates target heights (and fills it in |visible_windows| array) such
216 // that the vertical space is fairly distributed among the windows taking 215 // that the vertical space is fairly distributed among the windows taking
217 // into account their minimum and maximum size. Returns free vertical space 216 // into account their minimum and maximum size. Returns free vertical space
218 // (positive value) that remains after resizing all windows or deficit 217 // (positive value) that remains after resizing all windows or deficit
219 // (negative value) if not all the windows fit. 218 // (negative value) if not all the windows fit.
220 int CalculateWindowHeightsAndRemainingRoom( 219 int CalculateWindowHeightsAndRemainingRoom(
(...skipping 12 matching lines...) Expand all
233 int available_room, 232 int available_room,
234 std::vector<WindowWithHeight>* visible_windows); 233 std::vector<WindowWithHeight>* visible_windows);
235 234
236 // Updates |docked_bounds_| and workspace insets when bounds of docked windows 235 // Updates |docked_bounds_| and workspace insets when bounds of docked windows
237 // area change. Passing |reason| to observers allows selectively skipping 236 // area change. Passing |reason| to observers allows selectively skipping
238 // notifications. 237 // notifications.
239 void UpdateDockBounds(DockedWindowLayoutManagerObserver::Reason reason); 238 void UpdateDockBounds(DockedWindowLayoutManagerObserver::Reason reason);
240 239
241 // Called whenever the window stacking order needs to be updated (e.g. focus 240 // Called whenever the window stacking order needs to be updated (e.g. focus
242 // changes or a window is moved). 241 // changes or a window is moved).
243 void UpdateStacking(wm::WmWindow* active_window); 242 void UpdateStacking(WmWindow* active_window);
244 243
245 // keyboard::KeyboardControllerObserver: 244 // keyboard::KeyboardControllerObserver:
246 void OnKeyboardBoundsChanging(const gfx::Rect& keyboard_bounds) override; 245 void OnKeyboardBoundsChanging(const gfx::Rect& keyboard_bounds) override;
247 246
248 // Parent window associated with this layout manager. 247 // Parent window associated with this layout manager.
249 wm::WmWindow* dock_container_; 248 WmWindow* dock_container_;
250 249
251 wm::WmRootWindowController* root_window_controller_; 250 WmRootWindowController* root_window_controller_;
252 251
253 // Protect against recursive calls to Relayout(). 252 // Protect against recursive calls to Relayout().
254 bool in_layout_; 253 bool in_layout_;
255 254
256 // A window that is being dragged (whether docked or not). 255 // A window that is being dragged (whether docked or not).
257 // Windows are tracked by docked layout manager only if they are docked; 256 // Windows are tracked by docked layout manager only if they are docked;
258 // however we need to know if a window is being dragged in order to avoid 257 // however we need to know if a window is being dragged in order to avoid
259 // positioning it or even considering it for layout. 258 // positioning it or even considering it for layout.
260 wm::WmWindow* dragged_window_; 259 WmWindow* dragged_window_;
261 260
262 // True if the window being dragged is currently docked. 261 // True if the window being dragged is currently docked.
263 bool is_dragged_window_docked_; 262 bool is_dragged_window_docked_;
264 263
265 // Previously docked windows use a more relaxed dragging sorting algorithm 264 // Previously docked windows use a more relaxed dragging sorting algorithm
266 // that uses assumption that a window starts being dragged out of position 265 // that uses assumption that a window starts being dragged out of position
267 // that was previously established in Relayout. This allows easier reordering. 266 // that was previously established in Relayout. This allows easier reordering.
268 bool is_dragged_from_dock_; 267 bool is_dragged_from_dock_;
269 268
270 // The shelf to respond to alignment changes. 269 // The shelf to respond to alignment changes.
(...skipping 14 matching lines...) Expand all
285 DockedAlignment alignment_; 284 DockedAlignment alignment_;
286 285
287 // The preferred alignment of the next window to be added to docked layout. 286 // The preferred alignment of the next window to be added to docked layout.
288 DockedAlignment preferred_alignment_; 287 DockedAlignment preferred_alignment_;
289 288
290 // The current event source 289 // The current event source
291 DockedActionSource event_source_; 290 DockedActionSource event_source_;
292 291
293 // The last active window. Used to maintain stacking order even if no windows 292 // The last active window. Used to maintain stacking order even if no windows
294 // are currently focused. 293 // are currently focused.
295 wm::WmWindow* last_active_window_; 294 WmWindow* last_active_window_;
296 295
297 // Timestamp of the last user-initiated action that changed docked state. 296 // Timestamp of the last user-initiated action that changed docked state.
298 // Used in UMA metrics. 297 // Used in UMA metrics.
299 base::Time last_action_time_; 298 base::Time last_action_time_;
300 299
301 // Observes shelf for bounds changes. 300 // Observes shelf for bounds changes.
302 std::unique_ptr<ShelfWindowObserver> shelf_observer_; 301 std::unique_ptr<ShelfWindowObserver> shelf_observer_;
303 302
304 // Widget used to paint a background for the docked area. 303 // Widget used to paint a background for the docked area.
305 std::unique_ptr<DockedBackgroundWidget> background_widget_; 304 std::unique_ptr<DockedBackgroundWidget> background_widget_;
306 305
307 // Observers of dock bounds changes. 306 // Observers of dock bounds changes.
308 base::ObserverList<DockedWindowLayoutManagerObserver> observer_list_; 307 base::ObserverList<DockedWindowLayoutManagerObserver> observer_list_;
309 308
310 DISALLOW_COPY_AND_ASSIGN(DockedWindowLayoutManager); 309 DISALLOW_COPY_AND_ASSIGN(DockedWindowLayoutManager);
311 }; 310 };
312 311
313 } // namespace ash 312 } // namespace ash
314 313
315 #endif // ASH_COMMON_WM_DOCK_DOCKED_WINDOW_LAYOUT_MANAGER_H_ 314 #endif // ASH_COMMON_WM_DOCK_DOCKED_WINDOW_LAYOUT_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698