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

Side by Side Diff: ash/wm/workspace/workspace_window_resizer.h

Issue 9706059: Centralizes snap sizing and implements spec'd behavior. Three resize (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Better comments Created 8 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « ash/wm/workspace/snap_sizer.cc ('k') | ash/wm/workspace/workspace_window_resizer.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #pragma once 7 #pragma once
8 8
9 #include <vector> 9 #include <vector>
10 10
11 #include "ash/wm/window_resizer.h" 11 #include "ash/wm/window_resizer.h"
12 #include "base/compiler_specific.h" 12 #include "base/compiler_specific.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 14
15 namespace ash { 15 namespace ash {
16 namespace internal { 16 namespace internal {
17 17
18 class PhantomWindowController; 18 class PhantomWindowController;
19 class RootWindowEventFilter; 19 class RootWindowEventFilter;
20 class SnapSizer;
20 21
21 // WindowResizer implementation for workspaces. This enforces that windows are 22 // WindowResizer implementation for workspaces. This enforces that windows are
22 // not allowed to vertically move or resize outside of the work area. As windows 23 // not allowed to vertically move or resize outside of the work area. As windows
23 // are moved outside the work area they are shrunk. We remember the height of 24 // are moved outside the work area they are shrunk. We remember the height of
24 // the window before it was moved so that if the window is again moved up we 25 // the window before it was moved so that if the window is again moved up we
25 // attempt to restore the old height. 26 // attempt to restore the old height.
26 class ASH_EXPORT WorkspaceWindowResizer : public WindowResizer { 27 class ASH_EXPORT WorkspaceWindowResizer : public WindowResizer {
27 public: 28 public:
28 // Used when the window is dragged against the edge of the screen.
29 enum EdgeType {
30 LEFT_EDGE,
31 RIGHT_EDGE
32 };
33
34 // When dragging an attached window this is the min size we'll make sure is 29 // When dragging an attached window this is the min size we'll make sure is
35 // visibile. In the vertical direction we take the max of this and that from 30 // visible. In the vertical direction we take the max of this and that from
36 // the delegate. 31 // the delegate.
37 static const int kMinOnscreenSize; 32 static const int kMinOnscreenSize;
38 33
39 virtual ~WorkspaceWindowResizer(); 34 virtual ~WorkspaceWindowResizer();
40 35
41 // Returns the bounds for a window along the specified edge.
42 static gfx::Rect GetBoundsForWindowAlongEdge(
43 aura::Window* window,
44 EdgeType edge,
45 int grid_size);
46
47 static WorkspaceWindowResizer* Create( 36 static WorkspaceWindowResizer* Create(
48 aura::Window* window, 37 aura::Window* window,
49 const gfx::Point& location, 38 const gfx::Point& location,
50 int window_component, 39 int window_component,
51 int grid_size, 40 int grid_size,
52 const std::vector<aura::Window*>& attached_windows); 41 const std::vector<aura::Window*>& attached_windows);
53 42
54 // Returns true if the drag will result in changing the window in anyway. 43 // Returns true if the drag will result in changing the window in anyway.
55 bool is_resizable() const { return details_.is_resizable; } 44 bool is_resizable() const { return details_.is_resizable; }
56 45
57 const gfx::Point& initial_location_in_parent() const { 46 const gfx::Point& initial_location_in_parent() const {
58 return details_.initial_location_in_parent; 47 return details_.initial_location_in_parent;
59 } 48 }
60 49
61 // Overridden from WindowResizer: 50 // Overridden from WindowResizer:
62 virtual void Drag(const gfx::Point& location) OVERRIDE; 51 virtual void Drag(const gfx::Point& location) OVERRIDE;
63 virtual void CompleteDrag() OVERRIDE; 52 virtual void CompleteDrag() OVERRIDE;
64 virtual void RevertDrag() OVERRIDE; 53 virtual void RevertDrag() OVERRIDE;
65 54
66 private: 55 private:
67 WorkspaceWindowResizer(const Details& details, 56 WorkspaceWindowResizer(const Details& details,
68 const std::vector<aura::Window*>& attached_windows); 57 const std::vector<aura::Window*>& attached_windows);
69 58
70 private: 59 private:
71 // Location of the phanton window. 60 // Type of snapping.
72 enum PhantomType { 61 enum SnapType {
73 TYPE_LEFT_EDGE, 62 // Snap to the left/right edge of the screen.
74 TYPE_RIGHT_EDGE, 63 SNAP_LEFT_EDGE,
75 TYPE_DESTINATION, 64 SNAP_RIGHT_EDGE,
76 TYPE_NONE
77 };
78 65
79 // Type and bounds of the phantom window. 66 // Snap to the final bounds. Used when there is a grid.
80 struct PhantomPlacement { 67 SNAP_DESTINATION,
81 PhantomPlacement();
82 ~PhantomPlacement();
83 68
84 PhantomType type; 69 // No snap position.
85 gfx::Rect bounds; 70 SNAP_NONE
86 }; 71 };
87 72
88 // Returns the final bounds to place the window at. This differs from 73 // Returns the final bounds to place the window at. This differs from
89 // the current if there is a grid. 74 // the current if there is a grid.
90 gfx::Rect GetFinalBounds() const; 75 gfx::Rect GetFinalBounds() const;
91 76
92 // Lays out the attached windows. |bounds| is the bounds of the main window. 77 // Lays out the attached windows. |bounds| is the bounds of the main window.
93 void LayoutAttachedWindowsHorizontally(const gfx::Rect& bounds); 78 void LayoutAttachedWindowsHorizontally(const gfx::Rect& bounds);
94 void LayoutAttachedWindowsVertically(const gfx::Rect& bounds); 79 void LayoutAttachedWindowsVertically(const gfx::Rect& bounds);
95 80
(...skipping 13 matching lines...) Expand all
109 bool TouchesRightSideOfScreen() const; 94 bool TouchesRightSideOfScreen() const;
110 95
111 // Returns a coordinate along the primary axis. Used to share code for 96 // Returns a coordinate along the primary axis. Used to share code for
112 // left/right multi window resize and top/bottom resize. 97 // left/right multi window resize and top/bottom resize.
113 int PrimaryAxisSize(const gfx::Size& size) const; 98 int PrimaryAxisSize(const gfx::Size& size) const;
114 int PrimaryAxisCoordinate(int x, int y) const; 99 int PrimaryAxisCoordinate(int x, int y) const;
115 100
116 // Updates the bounds of the phantom window. 101 // Updates the bounds of the phantom window.
117 void UpdatePhantomWindow(const gfx::Point& location); 102 void UpdatePhantomWindow(const gfx::Point& location);
118 103
119 // Updates |phantom_placement_| when type is one of TYPE_LEFT_EDGE or 104 // Returns the SnapType for the specified point. SNAP_NONE is used if no
120 // TYPE_RIGHT_EDGE. 105 // snapping should be used.
121 void UpdatePhantomWindowBoundsAlongEdge( 106 SnapType GetSnapType(const gfx::Point& location) const;
122 const PhantomPlacement& last_placement);
123
124 // Returns a PhantomPlacement for the specified point. TYPE_NONE is used if
125 // the location doesn't have a valid phantom location.
126 PhantomPlacement GetPhantomPlacement(const gfx::Point& location);
127 107
128 aura::Window* window() const { return details_.window; } 108 aura::Window* window() const { return details_.window; }
129 109
130 const Details details_; 110 const Details details_;
131 111
132 // True if the window size (height) should be constrained. 112 // True if the window size (height) should be constrained.
133 const bool constrain_size_; 113 const bool constrain_size_;
134 114
135 const std::vector<aura::Window*> attached_windows_; 115 const std::vector<aura::Window*> attached_windows_;
136 116
(...skipping 18 matching lines...) Expand all
155 // Sum of sizes in |min_size_|. 135 // Sum of sizes in |min_size_|.
156 int total_min_; 136 int total_min_;
157 137
158 // Sum of the sizes in |initial_size_|. 138 // Sum of the sizes in |initial_size_|.
159 int total_initial_size_; 139 int total_initial_size_;
160 140
161 // Gives a previews of where the the window will end up. Only used if there 141 // Gives a previews of where the the window will end up. Only used if there
162 // is a grid and the caption is being dragged. 142 // is a grid and the caption is being dragged.
163 scoped_ptr<PhantomWindowController> phantom_window_controller_; 143 scoped_ptr<PhantomWindowController> phantom_window_controller_;
164 144
165 // Last PhantomPlacement. 145 // Used to determine the target position of a snap.
166 PhantomPlacement phantom_placement_; 146 scoped_ptr<SnapSizer> snap_sizer_;
147
148 // Last SnapType.
149 SnapType snap_type_;
167 150
168 // Number of mouse moves since the last bounds change. Only used for phantom 151 // Number of mouse moves since the last bounds change. Only used for phantom
169 // placement to track when the mouse is moved while pushed against the edge of 152 // placement to track when the mouse is moved while pushed against the edge of
170 // the screen. 153 // the screen.
171 int num_mouse_moves_since_bounds_change_; 154 int num_mouse_moves_since_bounds_change_;
172 155
173 DISALLOW_COPY_AND_ASSIGN(WorkspaceWindowResizer); 156 DISALLOW_COPY_AND_ASSIGN(WorkspaceWindowResizer);
174 }; 157 };
175 158
176 } // namespace internal 159 } // namespace internal
177 } // namespace ash 160 } // namespace ash
178 161
179 #endif // ASH_WM_WORKSPACE_WINDOW_RESIZER_H_ 162 #endif // ASH_WM_WORKSPACE_WINDOW_RESIZER_H_
OLDNEW
« no previous file with comments | « ash/wm/workspace/snap_sizer.cc ('k') | ash/wm/workspace/workspace_window_resizer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698