| 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_WINDOW_RESIZER_H_ | 5 #ifndef ASH_WM_WORKSPACE_WINDOW_RESIZER_H_ |
| 6 #define ASH_WM_WORKSPACE_WINDOW_RESIZER_H_ | 6 #define ASH_WM_WORKSPACE_WINDOW_RESIZER_H_ |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "ash/wm/window_resizer.h" | 10 #include "ash/wm/window_resizer.h" |
| 11 #include "ash/wm/workspace/magnetism_matcher.h" | 11 #include "ash/wm/workspace/magnetism_matcher.h" |
| 12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 13 #include "base/gtest_prod_util.h" | 13 #include "base/gtest_prod_util.h" |
| 14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "ui/aura/window_tracker.h" | 15 #include "ui/aura/window_tracker.h" |
| 16 | 16 |
| 17 namespace aura { | 17 namespace aura { |
| 18 class RootWindow; | 18 class RootWindow; |
| 19 } // namespace aura | 19 } // namespace aura |
| 20 | 20 |
| 21 namespace ui { | 21 namespace ui { |
| 22 class Layer; | 22 class Layer; |
| 23 } // namespace ui | 23 } // namespace ui |
| 24 | 24 |
| 25 namespace ash { | 25 namespace ash { |
| 26 namespace internal { | 26 namespace internal { |
| 27 | 27 |
| 28 class DragWindowController; |
| 28 class PhantomWindowController; | 29 class PhantomWindowController; |
| 29 class SnapSizer; | 30 class SnapSizer; |
| 30 class WindowSize; | 31 class WindowSize; |
| 31 | 32 |
| 32 // WindowResizer implementation for workspaces. This enforces that windows are | 33 // WindowResizer implementation for workspaces. This enforces that windows are |
| 33 // not allowed to vertically move or resize outside of the work area. As windows | 34 // not allowed to vertically move or resize outside of the work area. As windows |
| 34 // are moved outside the work area they are shrunk. We remember the height of | 35 // are moved outside the work area they are shrunk. We remember the height of |
| 35 // the window before it was moved so that if the window is again moved up we | 36 // the window before it was moved so that if the window is again moved up we |
| 36 // attempt to restore the old height. | 37 // attempt to restore the old height. |
| 37 class ASH_EXPORT WorkspaceWindowResizer : public WindowResizer { | 38 class ASH_EXPORT WorkspaceWindowResizer : public WindowResizer { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 int event_flags) OVERRIDE; | 70 int event_flags) OVERRIDE; |
| 70 virtual void CompleteDrag(int event_flags) OVERRIDE; | 71 virtual void CompleteDrag(int event_flags) OVERRIDE; |
| 71 virtual void RevertDrag() OVERRIDE; | 72 virtual void RevertDrag() OVERRIDE; |
| 72 virtual aura::Window* GetTarget() OVERRIDE; | 73 virtual aura::Window* GetTarget() OVERRIDE; |
| 73 | 74 |
| 74 private: | 75 private: |
| 75 WorkspaceWindowResizer(const Details& details, | 76 WorkspaceWindowResizer(const Details& details, |
| 76 const std::vector<aura::Window*>& attached_windows); | 77 const std::vector<aura::Window*>& attached_windows); |
| 77 | 78 |
| 78 private: | 79 private: |
| 79 FRIEND_TEST_ALL_PREFIXES(WorkspaceWindowResizerTest, PhantomStyle); | 80 FRIEND_TEST_ALL_PREFIXES(WorkspaceWindowResizerTest, DragWindowController); |
| 80 FRIEND_TEST_ALL_PREFIXES(WorkspaceWindowResizerTest, CancelSnapPhantom); | 81 FRIEND_TEST_ALL_PREFIXES(WorkspaceWindowResizerTest, CancelSnapPhantom); |
| 81 FRIEND_TEST_ALL_PREFIXES(WorkspaceWindowResizerTest, PhantomSnapMaxSize); | 82 FRIEND_TEST_ALL_PREFIXES(WorkspaceWindowResizerTest, PhantomSnapMaxSize); |
| 82 | 83 |
| 83 // Type of snapping. | 84 // Type of snapping. |
| 84 enum SnapType { | 85 enum SnapType { |
| 85 // Snap to the left/right edge of the screen. | 86 // Snap to the left/right edge of the screen. |
| 86 SNAP_LEFT_EDGE, | 87 SNAP_LEFT_EDGE, |
| 87 SNAP_RIGHT_EDGE, | 88 SNAP_RIGHT_EDGE, |
| 88 | 89 |
| 89 // No snap position. | 90 // No snap position. |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 // left/right multi window resize and top/bottom resize. | 162 // left/right multi window resize and top/bottom resize. |
| 162 int PrimaryAxisSize(const gfx::Size& size) const; | 163 int PrimaryAxisSize(const gfx::Size& size) const; |
| 163 int PrimaryAxisCoordinate(int x, int y) const; | 164 int PrimaryAxisCoordinate(int x, int y) const; |
| 164 | 165 |
| 165 // Updates the bounds of the phantom window for window snapping. | 166 // Updates the bounds of the phantom window for window snapping. |
| 166 void UpdateSnapPhantomWindow(const gfx::Point& location, | 167 void UpdateSnapPhantomWindow(const gfx::Point& location, |
| 167 const gfx::Rect& bounds); | 168 const gfx::Rect& bounds); |
| 168 | 169 |
| 169 // Updates the bounds of the phantom window for window dragging. Set true on | 170 // Updates the bounds of the phantom window for window dragging. Set true on |
| 170 // |in_original_root| if the pointer is still in |window()->GetRootWindow()|. | 171 // |in_original_root| if the pointer is still in |window()->GetRootWindow()|. |
| 171 void UpdateDragPhantomWindow(const gfx::Rect& bounds, bool in_original_root); | 172 void UpdateDragWindow(const gfx::Rect& bounds, bool in_original_root); |
| 172 | 173 |
| 173 // Restacks the windows z-order position so that one of the windows is at the | 174 // Restacks the windows z-order position so that one of the windows is at the |
| 174 // top of the z-order, and the rest directly underneath it. | 175 // top of the z-order, and the rest directly underneath it. |
| 175 void RestackWindows(); | 176 void RestackWindows(); |
| 176 | 177 |
| 177 // Returns the SnapType for the specified point. SNAP_NONE is used if no | 178 // Returns the SnapType for the specified point. SNAP_NONE is used if no |
| 178 // snapping should be used. | 179 // snapping should be used. |
| 179 SnapType GetSnapType(const gfx::Point& location) const; | 180 SnapType GetSnapType(const gfx::Point& location) const; |
| 180 | 181 |
| 181 // Returns true if we should allow the mouse pointer to warp. | 182 // Returns true if we should allow the mouse pointer to warp. |
| 182 bool ShouldAllowMouseWarp() const; | 183 bool ShouldAllowMouseWarp() const; |
| 183 | 184 |
| 184 // Recreates a fresh layer for window() and all its child windows. | |
| 185 void RecreateWindowLayers(); | |
| 186 | |
| 187 aura::Window* window() const { return details_.window; } | 185 aura::Window* window() const { return details_.window; } |
| 188 | 186 |
| 189 const Details details_; | 187 const Details details_; |
| 190 | 188 |
| 191 const std::vector<aura::Window*> attached_windows_; | 189 const std::vector<aura::Window*> attached_windows_; |
| 192 | 190 |
| 193 // Set to true once Drag() is invoked and the bounds of the window change. | 191 // Set to true once Drag() is invoked and the bounds of the window change. |
| 194 bool did_move_or_resize_; | 192 bool did_move_or_resize_; |
| 195 | 193 |
| 196 // The initial size of each of the windows in |attached_windows_| along the | 194 // The initial size of each of the windows in |attached_windows_| along the |
| 197 // primary axis. | 195 // primary axis. |
| 198 std::vector<int> initial_size_; | 196 std::vector<int> initial_size_; |
| 199 | 197 |
| 200 // Sum of the minimum sizes of the attached windows. | 198 // Sum of the minimum sizes of the attached windows. |
| 201 int total_min_; | 199 int total_min_; |
| 202 | 200 |
| 203 // Sum of the sizes in |initial_size_|. | 201 // Sum of the sizes in |initial_size_|. |
| 204 int total_initial_size_; | 202 int total_initial_size_; |
| 205 | 203 |
| 206 // Gives a previews of where the the window will end up. Only used if there | 204 // Gives a previews of where the the window will end up. Only used if there |
| 207 // is a grid and the caption is being dragged. | 205 // is a grid and the caption is being dragged. |
| 208 scoped_ptr<PhantomWindowController> snap_phantom_window_controller_; | 206 scoped_ptr<PhantomWindowController> snap_phantom_window_controller_; |
| 209 | 207 |
| 210 // Shows a semi-transparent image of the window being dragged. | 208 // Shows a semi-transparent image of the window being dragged. |
| 211 scoped_ptr<PhantomWindowController> drag_phantom_window_controller_; | 209 scoped_ptr<DragWindowController> drag_window_controller_; |
| 212 | 210 |
| 213 // Used to determine the target position of a snap. | 211 // Used to determine the target position of a snap. |
| 214 scoped_ptr<SnapSizer> snap_sizer_; | 212 scoped_ptr<SnapSizer> snap_sizer_; |
| 215 | 213 |
| 216 // Last SnapType. | 214 // Last SnapType. |
| 217 SnapType snap_type_; | 215 SnapType snap_type_; |
| 218 | 216 |
| 219 // Number of mouse moves since the last bounds change. Only used for phantom | 217 // Number of mouse moves since the last bounds change. Only used for phantom |
| 220 // placement to track when the mouse is moved while pushed against the edge of | 218 // placement to track when the mouse is moved while pushed against the edge of |
| 221 // the screen. | 219 // the screen. |
| 222 int num_mouse_moves_since_bounds_change_; | 220 int num_mouse_moves_since_bounds_change_; |
| 223 | 221 |
| 224 // The mouse location passed to Drag(). | 222 // The mouse location passed to Drag(). |
| 225 gfx::Point last_mouse_location_; | 223 gfx::Point last_mouse_location_; |
| 226 | 224 |
| 227 // The copy of window()->layer() and its children. This object is the owner of | |
| 228 // the layer. | |
| 229 ui::Layer* layer_; | |
| 230 | |
| 231 // If non-NULL the destructor sets this to true. Used to determine if this has | 225 // If non-NULL the destructor sets this to true. Used to determine if this has |
| 232 // been deleted. | 226 // been deleted. |
| 233 bool* destroyed_; | 227 bool* destroyed_; |
| 234 | 228 |
| 235 // Window the drag has magnetically attached to. | 229 // Window the drag has magnetically attached to. |
| 236 aura::Window* magnetism_window_; | 230 aura::Window* magnetism_window_; |
| 237 | 231 |
| 238 // Used to verify |magnetism_window_| is still valid. | 232 // Used to verify |magnetism_window_| is still valid. |
| 239 aura::WindowTracker window_tracker_; | 233 aura::WindowTracker window_tracker_; |
| 240 | 234 |
| 241 // If |magnetism_window_| is non-NULL this indicates how the two windows | 235 // If |magnetism_window_| is non-NULL this indicates how the two windows |
| 242 // should attach. | 236 // should attach. |
| 243 MatchedEdge magnetism_edge_; | 237 MatchedEdge magnetism_edge_; |
| 244 | 238 |
| 245 DISALLOW_COPY_AND_ASSIGN(WorkspaceWindowResizer); | 239 DISALLOW_COPY_AND_ASSIGN(WorkspaceWindowResizer); |
| 246 }; | 240 }; |
| 247 | 241 |
| 248 } // namespace internal | 242 } // namespace internal |
| 249 } // namespace ash | 243 } // namespace ash |
| 250 | 244 |
| 251 #endif // ASH_WM_WORKSPACE_WINDOW_RESIZER_H_ | 245 #endif // ASH_WM_WORKSPACE_WINDOW_RESIZER_H_ |
| OLD | NEW |