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 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "ash/ash_export.h" | 9 #include "ash/ash_export.h" |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "ui/gfx/rect.h" | 11 #include "ui/gfx/rect.h" |
12 | 12 |
13 namespace aura { | 13 namespace aura { |
14 class Window; | 14 class Window; |
15 } | 15 } |
16 | 16 |
17 namespace ash { | 17 namespace ash { |
18 | 18 |
19 namespace internal { | 19 // WindowResizer is used by ToplevelWindowEventFilter to handle dragging, moving |
20 class RootWindowEventFilter; | 20 // or resizing a window. All coordinates passed to this are in the parent |
21 } | 21 // windows coordinates. |
22 | |
23 // WindowResizer is used by ToplevelWindowEventFilter to handle dragging, | |
24 // moving or resizing a window. | |
25 class ASH_EXPORT WindowResizer { | 22 class ASH_EXPORT WindowResizer { |
26 public: | 23 public: |
27 // Constants to identify the type of resize. | 24 // Constants to identify the type of resize. |
28 static const int kBoundsChange_None; | 25 static const int kBoundsChange_None; |
29 static const int kBoundsChange_Repositions; | 26 static const int kBoundsChange_Repositions; |
30 static const int kBoundsChange_Resizes; | 27 static const int kBoundsChange_Resizes; |
31 | 28 |
32 // Used to indicate which direction the resize occurs in. | 29 // Used to indicate which direction the resize occurs in. |
33 static const int kBoundsChangeDirection_None; | 30 static const int kBoundsChangeDirection_None; |
34 static const int kBoundsChangeDirection_Horizontal; | 31 static const int kBoundsChangeDirection_Horizontal; |
35 static const int kBoundsChangeDirection_Vertical; | 32 static const int kBoundsChangeDirection_Vertical; |
36 | 33 |
37 WindowResizer(aura::Window* window, | 34 WindowResizer(); |
38 const gfx::Point& location, | |
39 int window_component, | |
40 int grid_size); | |
41 virtual ~WindowResizer(); | 35 virtual ~WindowResizer(); |
42 | 36 |
43 // Returns a bitmask of the kBoundsChange_ values. | 37 // Returns a bitmask of the kBoundsChange_ values. |
44 static int GetBoundsChangeForWindowComponent(int component); | 38 static int GetBoundsChangeForWindowComponent(int component); |
45 | 39 |
46 // Returns a location >= |location| that is aligned to fall on increments of | 40 // Returns a location >= |location| that is aligned to fall on increments of |
47 // |grid_size|. | 41 // |grid_size|. |
48 static int AlignToGrid(int location, int grid_size); | 42 static int AlignToGrid(int location, int grid_size); |
49 | 43 |
50 // Invoked to drag/move/resize the window. |location| is in the coordinates | 44 // Invoked to drag/move/resize the window. |location| is in the coordinates |
51 // of the window supplied to the constructor. | 45 // of the window supplied to the constructor. |
52 void Drag(const gfx::Point& location); | 46 virtual void Drag(const gfx::Point& location) = 0; |
53 | 47 |
54 // Invoked to complete the drag. | 48 // Invoked to complete the drag. |
55 virtual void CompleteDrag(); | 49 virtual void CompleteDrag() = 0; |
56 | 50 |
57 // Reverts the drag. | 51 // Reverts the drag. |
58 virtual void RevertDrag(); | 52 virtual void RevertDrag() = 0; |
59 | |
60 // Returns true if the drag will result in changing the window in anyway. | |
61 bool is_resizable() const { return is_resizable_; } | |
62 | |
63 // See description above members for details. | |
64 const gfx::Rect& initial_bounds() const { return initial_bounds_; } | |
65 const gfx::Point& initial_location_in_parent() const { | |
66 return initial_location_in_parent_; | |
67 } | |
68 int window_component() const { return window_component_; } | |
69 aura::Window* window() const { return window_; } | |
70 int grid_size() const { return grid_size_; } | |
71 bool did_move_or_resize() const { return did_move_or_resize_; } | |
72 int bounds_change() const { return bounds_change_; } | |
73 | 53 |
74 protected: | 54 protected: |
75 // Returns the bounds to give to the window once the mouse has moved to | 55 struct Details { |
76 // |location|. | 56 Details(); |
77 virtual gfx::Rect GetBoundsForDrag(const gfx::Point& location); | 57 Details(aura::Window* window, |
| 58 const gfx::Point& location, |
| 59 int window_component, |
| 60 int grid_size); |
| 61 ~Details(); |
78 | 62 |
79 // Returns the final bounds. This differs from current bounds if a grid_size | 63 // The window we're resizing. |
80 // was specified. | 64 aura::Window* window; |
81 virtual gfx::Rect GetFinalBounds(); | 65 |
| 66 // Initial bounds of the window. |
| 67 gfx::Rect initial_bounds; |
| 68 |
| 69 // Location passed to the constructor, in |window->parent()|'s coordinates. |
| 70 gfx::Point initial_location_in_parent; |
| 71 |
| 72 // The component the user pressed on. |
| 73 int window_component; |
| 74 |
| 75 // Bitmask of the |kBoundsChange_| constants. |
| 76 int bounds_change; |
| 77 |
| 78 // Bitmask of the |kBoundsChangeDirection_| constants. |
| 79 int position_change_direction; |
| 80 |
| 81 // Bitmask of the |kBoundsChangeDirection_| constants. |
| 82 int size_change_direction; |
| 83 |
| 84 // Will the drag actually modify the window? |
| 85 bool is_resizable; |
| 86 |
| 87 // Size of the grid. |
| 88 int grid_size; |
| 89 }; |
| 90 |
| 91 static gfx::Rect CalculateBoundsForDrag( |
| 92 const Details& details, |
| 93 const gfx::Point& location); |
| 94 |
| 95 static gfx::Rect AdjustBoundsToGrid(const Details& details); |
| 96 |
| 97 static bool IsBottomEdge(int component); |
82 | 98 |
83 private: | 99 private: |
84 // Returns the new origin of the window. The arguments are the difference | 100 // Returns the new origin of the window. The arguments are the difference |
85 // between the current location and the initial location. | 101 // between the current location and the initial location. |
86 gfx::Point GetOriginForDrag(int delta_x, int delta_y) const; | 102 static gfx::Point GetOriginForDrag(const Details& details, |
| 103 int delta_x, |
| 104 int delta_y); |
87 | 105 |
88 // Returns the size of the window for the drag. | 106 // Returns the size of the window for the drag. |
89 gfx::Size GetSizeForDrag(int* delta_x, int* delta_y) const; | 107 static gfx::Size GetSizeForDrag(const Details& details, |
| 108 int* delta_x, |
| 109 int* delta_y); |
90 | 110 |
91 // Returns the width of the window. | 111 // Returns the width of the window. |
92 int GetWidthForDrag(int min_width, int* delta_x) const; | 112 static int GetWidthForDrag(const Details& details, |
| 113 int min_width, |
| 114 int* delta_x); |
93 | 115 |
94 // Returns the height of the drag. | 116 // Returns the height of the drag. |
95 int GetHeightForDrag(int min_height, int* delta_y) const; | 117 static int GetHeightForDrag(const Details& details, |
96 | 118 int min_height, |
97 // The window we're resizing. | 119 int* delta_y); |
98 aura::Window* window_; | |
99 | |
100 // Initial bounds of the window. | |
101 const gfx::Rect initial_bounds_; | |
102 | |
103 // Location passed to the constructor, in |window->parent()|'s coordinates. | |
104 const gfx::Point initial_location_in_parent_; | |
105 | |
106 // The component the user pressed on. | |
107 const int window_component_; | |
108 | |
109 // Bitmask of the |kBoundsChange_| constants. | |
110 const int bounds_change_; | |
111 | |
112 // Bitmask of the |kBoundsChangeDirection_| constants. | |
113 const int position_change_direction_; | |
114 | |
115 // Bitmask of the |kBoundsChangeDirection_| constants. | |
116 const int size_change_direction_; | |
117 | |
118 // Will the drag actually modify the window? | |
119 const bool is_resizable_; | |
120 | |
121 // Size of the grid. | |
122 const int grid_size_; | |
123 | |
124 // Set to true once Drag() is invoked and the bounds of the window change. | |
125 bool did_move_or_resize_; | |
126 | |
127 internal::RootWindowEventFilter* root_filter_; | |
128 | |
129 DISALLOW_COPY_AND_ASSIGN(WindowResizer); | |
130 }; | 120 }; |
131 | 121 |
132 } // namespace aura | 122 } // namespace aura |
133 | 123 |
134 #endif // ASH_WM_WINDOW_RESIZER_H_ | 124 #endif // ASH_WM_WINDOW_RESIZER_H_ |
OLD | NEW |