| 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_WM_WORKSPACE_WORKSPACE_WINDOW_RESIZER_H_ | 5 #ifndef ASH_WM_WORKSPACE_WORKSPACE_WINDOW_RESIZER_H_ |
| 6 #define ASH_WM_WORKSPACE_WORKSPACE_WINDOW_RESIZER_H_ | 6 #define ASH_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/wm/common/wm_window_tracker.h" |
| 13 #include "ash/wm/window_resizer.h" | 14 #include "ash/wm/window_resizer.h" |
| 14 #include "ash/wm/workspace/magnetism_matcher.h" | 15 #include "ash/wm/workspace/magnetism_matcher.h" |
| 15 #include "base/compiler_specific.h" | 16 #include "base/compiler_specific.h" |
| 16 #include "base/macros.h" | 17 #include "base/macros.h" |
| 17 #include "base/memory/weak_ptr.h" | 18 #include "base/memory/weak_ptr.h" |
| 18 #include "ui/aura/window_tracker.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 } | 29 } |
| 29 | 30 |
| 30 // WindowResizer implementation for workspaces. This enforces that windows are | 31 // WindowResizer implementation for workspaces. This enforces that windows are |
| 31 // 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 |
| 32 // 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 |
| 33 // 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 |
| 34 // attempt to restore the old height. | 35 // attempt to restore the old height. |
| 35 class ASH_EXPORT WorkspaceWindowResizer : public WindowResizer { | 36 class ASH_EXPORT WorkspaceWindowResizer : public WindowResizer { |
| 36 public: | 37 public: |
| 37 // 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... |
| 48 static const int kScreenEdgeInset; | 49 static const int kScreenEdgeInset; |
| 49 | 50 |
| 50 // 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 |
| 51 // to move or resize beyond that edge. | 52 // to move or resize beyond that edge. |
| 52 static const int kStickyDistancePixels; | 53 static const int kStickyDistancePixels; |
| 53 | 54 |
| 54 ~WorkspaceWindowResizer() override; | 55 ~WorkspaceWindowResizer() override; |
| 55 | 56 |
| 56 static WorkspaceWindowResizer* Create( | 57 static WorkspaceWindowResizer* Create( |
| 57 wm::WindowState* window_state, | 58 wm::WindowState* window_state, |
| 58 const std::vector<aura::Window*>& attached_windows); | 59 const std::vector<wm::WmWindow*>& attached_windows); |
| 59 | 60 |
| 60 // WindowResizer: | 61 // WindowResizer: |
| 61 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; |
| 62 void CompleteDrag() override; | 63 void CompleteDrag() override; |
| 63 void RevertDrag() override; | 64 void RevertDrag() override; |
| 64 | 65 |
| 65 private: | 66 private: |
| 66 friend class WorkspaceWindowResizerTest; | 67 friend class WorkspaceWindowResizerTest; |
| 67 | 68 |
| 68 // 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. |
| 69 enum SnapType { SNAP_LEFT, SNAP_RIGHT, SNAP_NONE }; | 70 enum SnapType { SNAP_LEFT, SNAP_RIGHT, SNAP_NONE }; |
| 70 | 71 |
| 71 WorkspaceWindowResizer(wm::WindowState* window_state, | 72 WorkspaceWindowResizer(wm::WindowState* window_state, |
| 72 const std::vector<aura::Window*>& attached_windows); | 73 const std::vector<wm::WmWindow*>& attached_windows); |
| 73 | 74 |
| 74 // 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. |
| 75 void LayoutAttachedWindows(gfx::Rect* bounds); | 76 void LayoutAttachedWindows(gfx::Rect* bounds); |
| 76 | 77 |
| 77 // 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 |
| 78 // window has been resized (along the primary axis) by |delta|. | 79 // window has been resized (along the primary axis) by |delta|. |
| 79 // |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 |
| 80 // 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 |
| 81 // 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). |
| 82 // Populates |sizes| with the desired sizes of the attached windows, and | 83 // Populates |sizes| with the desired sizes of the attached windows, and |
| (...skipping 71 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 | 155 // Returns true if |bounds_in_parent| are valid bounds for snapped state type |
| 155 // |snapped_type|. | 156 // |snapped_type|. |
| 156 bool AreBoundsValidSnappedBounds(wm::WindowStateType snapped_type, | 157 bool AreBoundsValidSnappedBounds(wm::WindowStateType snapped_type, |
| 157 const gfx::Rect& bounds_in_parent) const; | 158 const gfx::Rect& bounds_in_parent) const; |
| 158 | 159 |
| 159 // Docks or undocks the dragged window. | 160 // Docks or undocks the dragged window. |
| 160 void SetDraggedWindowDocked(bool should_dock); | 161 void SetDraggedWindowDocked(bool should_dock); |
| 161 | 162 |
| 162 wm::WindowState* window_state() { return window_state_; } | 163 wm::WindowState* window_state() { return window_state_; } |
| 163 | 164 |
| 164 const std::vector<aura::Window*> attached_windows_; | 165 const std::vector<wm::WmWindow*> attached_windows_; |
| 166 |
| 167 wm::WmGlobals* globals_; |
| 165 | 168 |
| 166 // Returns the currently used instance for test. | 169 // Returns the currently used instance for test. |
| 167 static WorkspaceWindowResizer* GetInstanceForTest(); | 170 static WorkspaceWindowResizer* GetInstanceForTest(); |
| 168 | 171 |
| 169 bool did_lock_cursor_; | 172 bool did_lock_cursor_; |
| 170 | 173 |
| 171 // Set to true once Drag() is invoked and the bounds of the window change. | 174 // Set to true once Drag() is invoked and the bounds of the window change. |
| 172 bool did_move_or_resize_; | 175 bool did_move_or_resize_; |
| 173 | 176 |
| 174 // True if the window initially had |bounds_changed_by_user_| set in state. | 177 // True if the window initially had |bounds_changed_by_user_| set in state. |
| (...skipping 22 matching lines...) Expand all Loading... |
| 197 | 200 |
| 198 // Number of mouse moves since the last bounds change. Only used for phantom | 201 // Number of mouse moves since the last bounds change. Only used for phantom |
| 199 // placement to track when the mouse is moved while pushed against the edge of | 202 // placement to track when the mouse is moved while pushed against the edge of |
| 200 // the screen. | 203 // the screen. |
| 201 int num_mouse_moves_since_bounds_change_; | 204 int num_mouse_moves_since_bounds_change_; |
| 202 | 205 |
| 203 // The mouse location passed to Drag(). | 206 // The mouse location passed to Drag(). |
| 204 gfx::Point last_mouse_location_; | 207 gfx::Point last_mouse_location_; |
| 205 | 208 |
| 206 // Window the drag has magnetically attached to. | 209 // Window the drag has magnetically attached to. |
| 207 aura::Window* magnetism_window_; | 210 wm::WmWindow* magnetism_window_; |
| 208 | 211 |
| 209 // Used to verify |magnetism_window_| is still valid. | 212 // Used to verify |magnetism_window_| is still valid. |
| 210 aura::WindowTracker window_tracker_; | 213 wm::WmWindowTracker window_tracker_; |
| 211 | 214 |
| 212 // If |magnetism_window_| is non-NULL this indicates how the two windows | 215 // If |magnetism_window_| is non-NULL this indicates how the two windows |
| 213 // should attach. | 216 // should attach. |
| 214 MatchedEdge magnetism_edge_; | 217 MatchedEdge magnetism_edge_; |
| 215 | 218 |
| 216 // Dock container window layout manager. | 219 // Dock container window layout manager. |
| 217 DockedWindowLayoutManager* dock_layout_; | 220 DockedWindowLayoutManager* dock_layout_; |
| 218 | 221 |
| 219 // Used to determine if this has been deleted during a drag such as when a tab | 222 // Used to determine if this has been deleted during a drag such as when a tab |
| 220 // gets dragged into another browser window. | 223 // gets dragged into another browser window. |
| 221 base::WeakPtrFactory<WorkspaceWindowResizer> weak_ptr_factory_; | 224 base::WeakPtrFactory<WorkspaceWindowResizer> weak_ptr_factory_; |
| 222 | 225 |
| 223 DISALLOW_COPY_AND_ASSIGN(WorkspaceWindowResizer); | 226 DISALLOW_COPY_AND_ASSIGN(WorkspaceWindowResizer); |
| 224 }; | 227 }; |
| 225 | 228 |
| 226 } // namespace ash | 229 } // namespace ash |
| 227 | 230 |
| 228 #endif // ASH_WM_WORKSPACE_WORKSPACE_WINDOW_RESIZER_H_ | 231 #endif // ASH_WM_WORKSPACE_WORKSPACE_WINDOW_RESIZER_H_ |
| OLD | NEW |