OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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_WORKSPACE_WORKSPACE_WINDOW_RESIZER_H_ | 5 #ifndef ASH_COMMON_WM_WORKSPACE_WORKSPACE_WINDOW_RESIZER_H_ |
6 #define ASH_COMMON_WM_WORKSPACE_WORKSPACE_WINDOW_RESIZER_H_ | 6 #define ASH_COMMON_WM_WORKSPACE_WORKSPACE_WINDOW_RESIZER_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "ash/common/wm/window_resizer.h" | 13 #include "ash/common/wm/window_resizer.h" |
14 #include "ash/common/wm/wm_window_tracker.h" | |
15 #include "ash/common/wm/workspace/magnetism_matcher.h" | 14 #include "ash/common/wm/workspace/magnetism_matcher.h" |
| 15 #include "ash/common/wm_window_tracker.h" |
16 #include "base/compiler_specific.h" | 16 #include "base/compiler_specific.h" |
17 #include "base/macros.h" | 17 #include "base/macros.h" |
18 #include "base/memory/weak_ptr.h" | 18 #include "base/memory/weak_ptr.h" |
19 | 19 |
20 namespace ash { | 20 namespace ash { |
21 class DockedWindowLayoutManager; | 21 class DockedWindowLayoutManager; |
22 class PhantomWindowController; | 22 class PhantomWindowController; |
23 class TwoStepEdgeCycler; | 23 class TwoStepEdgeCycler; |
24 class WindowSize; | 24 class WindowSize; |
25 | 25 |
26 namespace wm { | 26 namespace wm { |
27 class WindowState; | 27 class WindowState; |
28 class WmGlobals; | 28 class WmShell; |
29 } | 29 } |
30 | 30 |
31 // WindowResizer implementation for workspaces. This enforces that windows are | 31 // WindowResizer implementation for workspaces. This enforces that windows are |
32 // not allowed to vertically move or resize outside of the work area. As windows | 32 // not allowed to vertically move or resize outside of the work area. As windows |
33 // are moved outside the work area they are shrunk. We remember the height of | 33 // are moved outside the work area they are shrunk. We remember the height of |
34 // the window before it was moved so that if the window is again moved up we | 34 // the window before it was moved so that if the window is again moved up we |
35 // attempt to restore the old height. | 35 // attempt to restore the old height. |
36 class ASH_EXPORT WorkspaceWindowResizer : public WindowResizer { | 36 class ASH_EXPORT WorkspaceWindowResizer : public WindowResizer { |
37 public: | 37 public: |
38 // When dragging an attached window this is the min size we'll make sure is | 38 // When dragging an attached window this is the min size we'll make sure is |
(...skipping 10 matching lines...) Expand all Loading... |
49 static const int kScreenEdgeInset; | 49 static const int kScreenEdgeInset; |
50 | 50 |
51 // Distance in pixels that the cursor must move past an edge for a window | 51 // Distance in pixels that the cursor must move past an edge for a window |
52 // to move or resize beyond that edge. | 52 // to move or resize beyond that edge. |
53 static const int kStickyDistancePixels; | 53 static const int kStickyDistancePixels; |
54 | 54 |
55 ~WorkspaceWindowResizer() override; | 55 ~WorkspaceWindowResizer() override; |
56 | 56 |
57 static WorkspaceWindowResizer* Create( | 57 static WorkspaceWindowResizer* Create( |
58 wm::WindowState* window_state, | 58 wm::WindowState* window_state, |
59 const std::vector<wm::WmWindow*>& attached_windows); | 59 const std::vector<WmWindow*>& attached_windows); |
60 | 60 |
61 // WindowResizer: | 61 // WindowResizer: |
62 void Drag(const gfx::Point& location_in_parent, int event_flags) override; | 62 void Drag(const gfx::Point& location_in_parent, int event_flags) override; |
63 void CompleteDrag() override; | 63 void CompleteDrag() override; |
64 void RevertDrag() override; | 64 void RevertDrag() override; |
65 | 65 |
66 private: | 66 private: |
67 friend class WorkspaceWindowResizerTest; | 67 friend class WorkspaceWindowResizerTest; |
68 | 68 |
69 // The edge to which the window should be snapped at the end of the drag. | 69 // The edge to which the window should be snapped at the end of the drag. |
70 enum SnapType { SNAP_LEFT, SNAP_RIGHT, SNAP_NONE }; | 70 enum SnapType { SNAP_LEFT, SNAP_RIGHT, SNAP_NONE }; |
71 | 71 |
72 WorkspaceWindowResizer(wm::WindowState* window_state, | 72 WorkspaceWindowResizer(wm::WindowState* window_state, |
73 const std::vector<wm::WmWindow*>& attached_windows); | 73 const std::vector<WmWindow*>& attached_windows); |
74 | 74 |
75 // Lays out the attached windows. |bounds| is the bounds of the main window. | 75 // Lays out the attached windows. |bounds| is the bounds of the main window. |
76 void LayoutAttachedWindows(gfx::Rect* bounds); | 76 void LayoutAttachedWindows(gfx::Rect* bounds); |
77 | 77 |
78 // Calculates the new sizes of the attached windows, given that the main | 78 // Calculates the new sizes of the attached windows, given that the main |
79 // window has been resized (along the primary axis) by |delta|. | 79 // window has been resized (along the primary axis) by |delta|. |
80 // |available_size| is the maximum length of the space that the attached | 80 // |available_size| is the maximum length of the space that the attached |
81 // windows are allowed to occupy (ie: the distance between the right/bottom | 81 // windows are allowed to occupy (ie: the distance between the right/bottom |
82 // edge of the primary window and the right/bottom of the desktop area). | 82 // edge of the primary window and the right/bottom of the desktop area). |
83 // Populates |sizes| with the desired sizes of the attached windows, and | 83 // Populates |sizes| with the desired sizes of the attached windows, and |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 // Returns true if |bounds_in_parent| are valid bounds for snapped state type | 154 // Returns true if |bounds_in_parent| are valid bounds for snapped state type |
155 // |snapped_type|. | 155 // |snapped_type|. |
156 bool AreBoundsValidSnappedBounds(wm::WindowStateType snapped_type, | 156 bool AreBoundsValidSnappedBounds(wm::WindowStateType snapped_type, |
157 const gfx::Rect& bounds_in_parent) const; | 157 const gfx::Rect& bounds_in_parent) const; |
158 | 158 |
159 // Docks or undocks the dragged window. | 159 // Docks or undocks the dragged window. |
160 void SetDraggedWindowDocked(bool should_dock); | 160 void SetDraggedWindowDocked(bool should_dock); |
161 | 161 |
162 wm::WindowState* window_state() { return window_state_; } | 162 wm::WindowState* window_state() { return window_state_; } |
163 | 163 |
164 const std::vector<wm::WmWindow*> attached_windows_; | 164 const std::vector<WmWindow*> attached_windows_; |
165 | 165 |
166 wm::WmGlobals* globals_; | 166 WmShell* shell_; |
167 | 167 |
168 // Returns the currently used instance for test. | 168 // Returns the currently used instance for test. |
169 static WorkspaceWindowResizer* GetInstanceForTest(); | 169 static WorkspaceWindowResizer* GetInstanceForTest(); |
170 | 170 |
171 bool did_lock_cursor_; | 171 bool did_lock_cursor_; |
172 | 172 |
173 // Set to true once Drag() is invoked and the bounds of the window change. | 173 // Set to true once Drag() is invoked and the bounds of the window change. |
174 bool did_move_or_resize_; | 174 bool did_move_or_resize_; |
175 | 175 |
176 // True if the window initially had |bounds_changed_by_user_| set in state. | 176 // True if the window initially had |bounds_changed_by_user_| set in state. |
(...skipping 22 matching lines...) Expand all Loading... |
199 | 199 |
200 // Number of mouse moves since the last bounds change. Only used for phantom | 200 // Number of mouse moves since the last bounds change. Only used for phantom |
201 // placement to track when the mouse is moved while pushed against the edge of | 201 // placement to track when the mouse is moved while pushed against the edge of |
202 // the screen. | 202 // the screen. |
203 int num_mouse_moves_since_bounds_change_; | 203 int num_mouse_moves_since_bounds_change_; |
204 | 204 |
205 // The mouse location passed to Drag(). | 205 // The mouse location passed to Drag(). |
206 gfx::Point last_mouse_location_; | 206 gfx::Point last_mouse_location_; |
207 | 207 |
208 // Window the drag has magnetically attached to. | 208 // Window the drag has magnetically attached to. |
209 wm::WmWindow* magnetism_window_; | 209 WmWindow* magnetism_window_; |
210 | 210 |
211 // Used to verify |magnetism_window_| is still valid. | 211 // Used to verify |magnetism_window_| is still valid. |
212 wm::WmWindowTracker window_tracker_; | 212 WmWindowTracker window_tracker_; |
213 | 213 |
214 // If |magnetism_window_| is non-NULL this indicates how the two windows | 214 // If |magnetism_window_| is non-NULL this indicates how the two windows |
215 // should attach. | 215 // should attach. |
216 MatchedEdge magnetism_edge_; | 216 MatchedEdge magnetism_edge_; |
217 | 217 |
218 // Dock container window layout manager. | 218 // Dock container window layout manager. |
219 DockedWindowLayoutManager* dock_layout_; | 219 DockedWindowLayoutManager* dock_layout_; |
220 | 220 |
221 // Used to determine if this has been deleted during a drag such as when a tab | 221 // Used to determine if this has been deleted during a drag such as when a tab |
222 // gets dragged into another browser window. | 222 // gets dragged into another browser window. |
223 base::WeakPtrFactory<WorkspaceWindowResizer> weak_ptr_factory_; | 223 base::WeakPtrFactory<WorkspaceWindowResizer> weak_ptr_factory_; |
224 | 224 |
225 DISALLOW_COPY_AND_ASSIGN(WorkspaceWindowResizer); | 225 DISALLOW_COPY_AND_ASSIGN(WorkspaceWindowResizer); |
226 }; | 226 }; |
227 | 227 |
228 } // namespace ash | 228 } // namespace ash |
229 | 229 |
230 #endif // ASH_COMMON_WM_WORKSPACE_WORKSPACE_WINDOW_RESIZER_H_ | 230 #endif // ASH_COMMON_WM_WORKSPACE_WORKSPACE_WINDOW_RESIZER_H_ |
OLD | NEW |