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_DEFAULT_WINDOW_RESIZER_H_ |
6 #define ASH_WM_WINDOW_RESIZER_H_ | 6 #define ASH_WM_DEFAULT_WINDOW_RESIZER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "ash/ash_export.h" | 9 #include "ash/wm/window_resizer.h" |
10 #include "base/basictypes.h" | 10 #include "base/compiler_specific.h" |
11 #include "ui/gfx/rect.h" | |
12 | |
13 namespace aura { | |
14 class Window; | |
15 } | |
16 | 11 |
17 namespace ash { | 12 namespace ash { |
18 | 13 |
19 namespace internal { | 14 namespace internal { |
20 class RootWindowEventFilter; | 15 class RootWindowEventFilter; |
21 } | 16 } |
22 | 17 |
23 // WindowResizer is used by ToplevelWindowEventFilter to handle dragging, | 18 // WindowResizer is used by ToplevelWindowEventFilter to handle dragging, moving |
24 // moving or resizing a window. | 19 // or resizing a window. All coordinates passed to this are in the parent |
25 class ASH_EXPORT WindowResizer { | 20 // windows coordiantes. |
| 21 class ASH_EXPORT DefaultWindowResizer : public WindowResizer { |
26 public: | 22 public: |
27 // Constants to identify the type of resize. | 23 // Constants to identify the type of resize. |
28 static const int kBoundsChange_None; | 24 static const int kBoundsChange_None; |
29 static const int kBoundsChange_Repositions; | 25 static const int kBoundsChange_Repositions; |
30 static const int kBoundsChange_Resizes; | 26 static const int kBoundsChange_Resizes; |
31 | 27 |
32 // Used to indicate which direction the resize occurs in. | 28 // Used to indicate which direction the resize occurs in. |
33 static const int kBoundsChangeDirection_None; | 29 static const int kBoundsChangeDirection_None; |
34 static const int kBoundsChangeDirection_Horizontal; | 30 static const int kBoundsChangeDirection_Horizontal; |
35 static const int kBoundsChangeDirection_Vertical; | 31 static const int kBoundsChangeDirection_Vertical; |
36 | 32 |
37 WindowResizer(aura::Window* window, | 33 virtual ~DefaultWindowResizer(); |
38 const gfx::Point& location, | |
39 int window_component, | |
40 int grid_size); | |
41 virtual ~WindowResizer(); | |
42 | 34 |
43 // Returns a bitmask of the kBoundsChange_ values. | 35 // Creates a new DefaultWindowResizer. The caller takes ownership of the |
44 static int GetBoundsChangeForWindowComponent(int component); | 36 // returned object. Returns NULL if not resizable. |
45 | 37 static DefaultWindowResizer* Create(aura::Window* window, |
46 // Returns a location >= |location| that is aligned to fall on increments of | 38 const gfx::Point& location, |
47 // |grid_size|. | 39 int window_component, |
48 static int AlignToGrid(int location, int grid_size); | 40 int grid_size); |
49 | |
50 // Invoked to drag/move/resize the window. |location| is in the coordinates | |
51 // of the window supplied to the constructor. | |
52 void Drag(const gfx::Point& location); | |
53 | |
54 // Invoked to complete the drag. | |
55 virtual void CompleteDrag(); | |
56 | |
57 // Reverts the drag. | |
58 virtual void RevertDrag(); | |
59 | 41 |
60 // Returns true if the drag will result in changing the window in anyway. | 42 // Returns true if the drag will result in changing the window in anyway. |
61 bool is_resizable() const { return is_resizable_; } | 43 bool is_resizable() const { return details_.is_resizable; } |
62 | 44 |
63 // See description above members for details. | 45 // WindowResizer overides: |
64 const gfx::Rect& initial_bounds() const { return initial_bounds_; } | 46 virtual void Drag(const gfx::Point& location) OVERRIDE; |
65 const gfx::Point& initial_location_in_parent() const { | 47 virtual void CompleteDrag() OVERRIDE; |
66 return initial_location_in_parent_; | 48 virtual void RevertDrag() OVERRIDE; |
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 | |
74 protected: | |
75 // Returns the bounds to give to the window once the mouse has moved to | |
76 // |location|. | |
77 virtual gfx::Rect GetBoundsForDrag(const gfx::Point& location); | |
78 | |
79 // Returns the final bounds. This differs from current bounds if a grid_size | |
80 // was specified. | |
81 virtual gfx::Rect GetFinalBounds(); | |
82 | 49 |
83 private: | 50 private: |
84 // Returns the new origin of the window. The arguments are the difference | 51 explicit DefaultWindowResizer(const Details& details); |
85 // between the current location and the initial location. | |
86 gfx::Point GetOriginForDrag(int delta_x, int delta_y) const; | |
87 | 52 |
88 // Returns the size of the window for the drag. | 53 const Details details_; |
89 gfx::Size GetSizeForDrag(int* delta_x, int* delta_y) const; | |
90 | |
91 // Returns the width of the window. | |
92 int GetWidthForDrag(int min_width, int* delta_x) const; | |
93 | |
94 // Returns the height of the drag. | |
95 int GetHeightForDrag(int min_height, int* delta_y) const; | |
96 | |
97 // The window we're resizing. | |
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 | 54 |
124 // Set to true once Drag() is invoked and the bounds of the window change. | 55 // Set to true once Drag() is invoked and the bounds of the window change. |
125 bool did_move_or_resize_; | 56 bool did_move_or_resize_; |
126 | 57 |
127 internal::RootWindowEventFilter* root_filter_; | 58 internal::RootWindowEventFilter* root_filter_; |
128 | 59 |
129 DISALLOW_COPY_AND_ASSIGN(WindowResizer); | 60 DISALLOW_COPY_AND_ASSIGN(DefaultWindowResizer); |
130 }; | 61 }; |
131 | 62 |
132 } // namespace aura | 63 } // namespace aura |
133 | 64 |
134 #endif // ASH_WM_WINDOW_RESIZER_H_ | 65 #endif // ASH_WM_DEFAULT_WINDOW_RESIZER_H_ |
OLD | NEW |