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_WINDOW_RESIZER_H_ | 5 #ifndef ASH_WM_WINDOW_RESIZER_H_ |
6 #define ASH_WM_WINDOW_RESIZER_H_ | 6 #define ASH_WM_WINDOW_RESIZER_H_ |
7 | 7 |
8 #include "ash/ash_export.h" | 8 #include "ash/ash_export.h" |
| 9 #include "ash/wm/drag_details.h" |
| 10 #include "ash/wm/window_state.h" |
9 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
10 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
11 #include "ui/aura/client/window_move_client.h" | 13 #include "ui/aura/client/window_move_client.h" |
12 #include "ui/gfx/rect.h" | 14 #include "ui/gfx/rect.h" |
13 | 15 |
14 namespace aura { | 16 namespace aura { |
15 class Window; | 17 class Window; |
16 } | 18 } |
17 | 19 |
18 namespace ash { | 20 namespace ash { |
19 namespace wm { | |
20 class WindowState; | |
21 } | |
22 | 21 |
23 // WindowResizer is used by ToplevelWindowEventFilter to handle dragging, moving | 22 // WindowResizer is used by ToplevelWindowEventFilter to handle dragging, moving |
24 // or resizing a window. All coordinates passed to this are in the parent | 23 // or resizing a window. All coordinates passed to this are in the parent |
25 // windows coordinates. | 24 // windows coordinates. |
26 class ASH_EXPORT WindowResizer { | 25 class ASH_EXPORT WindowResizer { |
27 public: | 26 public: |
28 // Constants to identify the type of resize. | 27 // Constants to identify the type of resize. |
29 static const int kBoundsChange_None; | 28 static const int kBoundsChange_None; |
30 static const int kBoundsChange_Repositions; | 29 static const int kBoundsChange_Repositions; |
31 static const int kBoundsChange_Resizes; | 30 static const int kBoundsChange_Resizes; |
32 | 31 |
33 // Used to indicate which direction the resize occurs in. | 32 // Used to indicate which direction the resize occurs in. |
34 static const int kBoundsChangeDirection_None; | 33 static const int kBoundsChangeDirection_None; |
35 static const int kBoundsChangeDirection_Horizontal; | 34 static const int kBoundsChangeDirection_Horizontal; |
36 static const int kBoundsChangeDirection_Vertical; | 35 static const int kBoundsChangeDirection_Vertical; |
37 | 36 |
38 WindowResizer(); | 37 WindowResizer(); |
| 38 WindowResizer(wm::WindowState* window_state); |
39 virtual ~WindowResizer(); | 39 virtual ~WindowResizer(); |
40 | 40 |
41 // Returns a bitmask of the kBoundsChange_ values. | 41 // Returns a bitmask of the kBoundsChange_ values. |
42 static int GetBoundsChangeForWindowComponent(int component); | 42 static int GetBoundsChangeForWindowComponent(int component); |
43 | 43 |
| 44 // Returns a bitmask of the kBoundsChange_ values. |
| 45 static int GetPositionChangeDirectionForWindowComponent(int window_component); |
| 46 |
44 // Invoked to drag/move/resize the window. |location| is in the coordinates | 47 // Invoked to drag/move/resize the window. |location| is in the coordinates |
45 // of the window supplied to the constructor. |event_flags| is the event | 48 // of the window supplied to the constructor. |event_flags| is the event |
46 // flags from the event. | 49 // flags from the event. |
47 virtual void Drag(const gfx::Point& location, int event_flags) = 0; | 50 virtual void Drag(const gfx::Point& location, int event_flags) = 0; |
48 | 51 |
49 // Invoked to complete the drag. | 52 // Invoked to complete the drag. |
50 virtual void CompleteDrag() = 0; | 53 virtual void CompleteDrag() = 0; |
51 | 54 |
52 // Reverts the drag. | 55 // Reverts the drag. |
53 virtual void RevertDrag() = 0; | 56 virtual void RevertDrag() = 0; |
54 | 57 |
55 // Returns the target window the resizer was created for. | 58 // Returns the target window the resizer was created for. |
56 virtual aura::Window* GetTarget() = 0; | 59 aura::Window* GetTarget() const { |
| 60 return window_state_ ? window_state_->window() : NULL; |
| 61 } |
57 | 62 |
58 // See comment for |Details::initial_location_in_parent|. | 63 // See comment for |DragDetails::initial_location_in_parent|. |
59 virtual const gfx::Point& GetInitialLocation() const = 0; | 64 const gfx::Point& GetInitialLocation() const { |
| 65 return window_state_->drag_details()->initial_location_in_parent; |
| 66 } |
| 67 |
| 68 // Drag parameters established when drag starts. |
| 69 const DragDetails& details() const { return *window_state_->drag_details(); } |
60 | 70 |
61 protected: | 71 protected: |
62 struct Details { | 72 gfx::Rect CalculateBoundsForDrag(const gfx::Point& location); |
63 Details(); | |
64 Details(aura::Window* window, | |
65 const gfx::Point& location, | |
66 int window_component, | |
67 aura::client::WindowMoveSource source); | |
68 ~Details(); | |
69 | |
70 // The window we're resizing. | |
71 // TODO(oshima): replace this with accessor method to | |
72 // |window_state->window()|. | |
73 aura::Window* window; | |
74 | |
75 // The ash window state for the |window| above. | |
76 wm::WindowState* window_state; | |
77 | |
78 // Initial bounds of the window in parent coordinates. | |
79 gfx::Rect initial_bounds_in_parent; | |
80 | |
81 // Restore bounds (in screen coordinates) of the window before the drag | |
82 // started. Only set if the window is normal and is being dragged. | |
83 gfx::Rect restore_bounds; | |
84 | |
85 // Location passed to the constructor, in |window->parent()|'s coordinates. | |
86 gfx::Point initial_location_in_parent; | |
87 | |
88 // Initial opacity of the window. | |
89 float initial_opacity; | |
90 | |
91 // The component the user pressed on. | |
92 int window_component; | |
93 | |
94 // Bitmask of the |kBoundsChange_| constants. | |
95 int bounds_change; | |
96 | |
97 // Bitmask of the |kBoundsChangeDirection_| constants. | |
98 int position_change_direction; | |
99 | |
100 // Bitmask of the |kBoundsChangeDirection_| constants. | |
101 int size_change_direction; | |
102 | |
103 // Will the drag actually modify the window? | |
104 bool is_resizable; | |
105 | |
106 // Source of the event initiating the drag. | |
107 aura::client::WindowMoveSource source; | |
108 }; | |
109 | |
110 static gfx::Rect CalculateBoundsForDrag(const Details& details, | |
111 const gfx::Point& location); | |
112 | |
113 static gfx::Rect AdjustBoundsToGrid(const gfx::Rect& bounds, | |
114 int grid_size); | |
115 | 73 |
116 static bool IsBottomEdge(int component); | 74 static bool IsBottomEdge(int component); |
117 | 75 |
| 76 // WindowState of the drag target. |
| 77 wm::WindowState* window_state_; |
| 78 |
118 private: | 79 private: |
119 // In case of touch resizing, adjusts deltas so that the border is positioned | 80 // In case of touch resizing, adjusts deltas so that the border is positioned |
120 // just under the touch point. | 81 // just under the touch point. |
121 static void AdjustDeltaForTouchResize(const Details& details, | 82 void AdjustDeltaForTouchResize(int* delta_x, int* delta_y); |
122 int* delta_x, | |
123 int* delta_y); | |
124 | 83 |
125 // Returns the new origin of the window. The arguments are the difference | 84 // Returns the new origin of the window. The arguments are the difference |
126 // between the current location and the initial location. | 85 // between the current location and the initial location. |
127 static gfx::Point GetOriginForDrag(const Details& details, | 86 gfx::Point GetOriginForDrag(int delta_x, int delta_y); |
128 int delta_x, | |
129 int delta_y); | |
130 | 87 |
131 // Returns the size of the window for the drag. | 88 // Returns the size of the window for the drag. |
132 static gfx::Size GetSizeForDrag(const Details& details, | 89 gfx::Size GetSizeForDrag(int* delta_x, int* delta_y); |
133 int* delta_x, | |
134 int* delta_y); | |
135 | 90 |
136 // Returns the width of the window. | 91 // Returns the width of the window. |
137 static int GetWidthForDrag(const Details& details, | 92 int GetWidthForDrag(int min_width, int* delta_x); |
138 int min_width, | |
139 int* delta_x); | |
140 | 93 |
141 // Returns the height of the drag. | 94 // Returns the height of the drag. |
142 static int GetHeightForDrag(const Details& details, | 95 int GetHeightForDrag(int min_height, int* delta_y); |
143 int min_height, | |
144 int* delta_y); | |
145 }; | 96 }; |
146 | 97 |
147 // Creates a WindowResizer for |window|. This can return a scoped_ptr | 98 // Creates a WindowResizer for |window|. This can return a scoped_ptr |
148 // initialized with NULL if |window| should not be resized nor dragged. | 99 // initialized with NULL if |window| should not be resized nor dragged. |
149 ASH_EXPORT scoped_ptr<WindowResizer> CreateWindowResizer( | 100 ASH_EXPORT scoped_ptr<WindowResizer> CreateWindowResizer( |
150 aura::Window* window, | 101 aura::Window* window, |
151 const gfx::Point& point_in_parent, | 102 const gfx::Point& point_in_parent, |
152 int window_component, | 103 int window_component, |
153 aura::client::WindowMoveSource source); | 104 aura::client::WindowMoveSource source); |
154 | 105 |
155 } // namespace ash | 106 } // namespace ash |
156 | 107 |
157 #endif // ASH_WM_WINDOW_RESIZER_H_ | 108 #endif // ASH_WM_WINDOW_RESIZER_H_ |
OLD | NEW |