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 "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.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 // WindowResizer is used by ToplevelWindowEventFilter to handle dragging, moving | 19 // WindowResizer is used by ToplevelWindowEventFilter to handle dragging, moving |
20 // or resizing a window. All coordinates passed to this are in the parent | 20 // or resizing a window. All coordinates passed to this are in the parent |
21 // windows coordinates. | 21 // windows coordinates. |
22 class ASH_EXPORT WindowResizer { | 22 class ASH_EXPORT WindowResizer { |
23 public: | 23 public: |
24 // Constants to identify the type of resize. | |
25 static const int kBoundsChange_None; | |
26 static const int kBoundsChange_Repositions; | |
27 static const int kBoundsChange_Resizes; | |
28 | |
29 // Used to indicate which direction the resize occurs in. | |
30 static const int kBoundsChangeDirection_None; | |
31 static const int kBoundsChangeDirection_Horizontal; | |
32 static const int kBoundsChangeDirection_Vertical; | |
33 | |
34 WindowResizer(); | |
35 virtual ~WindowResizer(); | |
36 | |
37 // Returns a bitmask of the kBoundsChange_ values. | |
38 static int GetBoundsChangeForWindowComponent(int component); | |
39 | |
40 // Invoked to drag/move/resize the window. |location| is in the coordinates | |
41 // of the window supplied to the constructor. |event_flags| is the event | |
42 // flags from the event. | |
43 virtual void Drag(const gfx::Point& location, int event_flags) = 0; | |
44 | |
45 // Invoked to complete the drag. | |
46 virtual void CompleteDrag(int event_flags) = 0; | |
47 | |
48 // Reverts the drag. | |
49 virtual void RevertDrag() = 0; | |
50 | |
51 // Returns the target window the resizer was created for. | |
52 virtual aura::Window* GetTarget() = 0; | |
53 | |
54 protected: | |
55 struct Details { | 24 struct Details { |
sky
2012/12/04 15:58:53
Why do you need to expose all this?
mazda
2012/12/04 18:44:41
I needed to create Details in CreateWindowResizer
sky
2012/12/04 22:39:43
Yes please.
| |
56 Details(); | 25 Details(); |
57 Details(aura::Window* window, | 26 Details(aura::Window* window, |
58 const gfx::Point& location, | 27 const gfx::Point& location, |
59 int window_component); | 28 int window_component); |
60 ~Details(); | 29 ~Details(); |
61 | 30 |
62 // The window we're resizing. | 31 // The window we're resizing. |
63 aura::Window* window; | 32 aura::Window* window; |
64 | 33 |
65 // Initial bounds of the window in parent coordinates. | 34 // Initial bounds of the window in parent coordinates. |
(...skipping 18 matching lines...) Expand all Loading... | |
84 // Bitmask of the |kBoundsChangeDirection_| constants. | 53 // Bitmask of the |kBoundsChangeDirection_| constants. |
85 int position_change_direction; | 54 int position_change_direction; |
86 | 55 |
87 // Bitmask of the |kBoundsChangeDirection_| constants. | 56 // Bitmask of the |kBoundsChangeDirection_| constants. |
88 int size_change_direction; | 57 int size_change_direction; |
89 | 58 |
90 // Will the drag actually modify the window? | 59 // Will the drag actually modify the window? |
91 bool is_resizable; | 60 bool is_resizable; |
92 }; | 61 }; |
93 | 62 |
63 // Constants to identify the type of resize. | |
64 static const int kBoundsChange_None; | |
65 static const int kBoundsChange_Repositions; | |
66 static const int kBoundsChange_Resizes; | |
67 | |
68 // Used to indicate which direction the resize occurs in. | |
69 static const int kBoundsChangeDirection_None; | |
70 static const int kBoundsChangeDirection_Horizontal; | |
71 static const int kBoundsChangeDirection_Vertical; | |
72 | |
73 WindowResizer(); | |
74 virtual ~WindowResizer(); | |
75 | |
76 // Returns a bitmask of the kBoundsChange_ values. | |
77 static int GetBoundsChangeForWindowComponent(int component); | |
78 | |
79 // Invoked to drag/move/resize the window. |location| is in the coordinates | |
80 // of the window supplied to the constructor. |event_flags| is the event | |
81 // flags from the event. | |
82 virtual void Drag(const gfx::Point& location, int event_flags) = 0; | |
83 | |
84 // Invoked to complete the drag. | |
85 virtual void CompleteDrag(int event_flags) = 0; | |
86 | |
87 // Reverts the drag. | |
88 virtual void RevertDrag() = 0; | |
89 | |
90 // Returns the target window the resizer was created for. | |
91 virtual aura::Window* GetTarget() = 0; | |
92 | |
93 protected: | |
94 static gfx::Rect CalculateBoundsForDrag(const Details& details, | 94 static gfx::Rect CalculateBoundsForDrag(const Details& details, |
95 const gfx::Point& location); | 95 const gfx::Point& location); |
96 | 96 |
97 static gfx::Rect AdjustBoundsToGrid(const gfx::Rect& bounds, | 97 static gfx::Rect AdjustBoundsToGrid(const gfx::Rect& bounds, |
98 int grid_size); | 98 int grid_size); |
99 | 99 |
100 static bool IsBottomEdge(int component); | 100 static bool IsBottomEdge(int component); |
101 | 101 |
102 private: | 102 private: |
103 // Returns the new origin of the window. The arguments are the difference | 103 // Returns the new origin of the window. The arguments are the difference |
(...skipping 13 matching lines...) Expand all Loading... | |
117 int* delta_x); | 117 int* delta_x); |
118 | 118 |
119 // Returns the height of the drag. | 119 // Returns the height of the drag. |
120 static int GetHeightForDrag(const Details& details, | 120 static int GetHeightForDrag(const Details& details, |
121 int min_height, | 121 int min_height, |
122 int* delta_y); | 122 int* delta_y); |
123 }; | 123 }; |
124 | 124 |
125 // Creates a WindowResizer for |window|. This can return a scoped_ptr | 125 // Creates a WindowResizer for |window|. This can return a scoped_ptr |
126 // initialized with NULL if |window| should not be resized nor dragged. | 126 // initialized with NULL if |window| should not be resized nor dragged. |
127 scoped_ptr<WindowResizer> CreateWindowResizer( | 127 ASH_EXPORT scoped_ptr<WindowResizer> CreateWindowResizer( |
128 aura::Window* window, | 128 aura::Window* window, |
129 const gfx::Point& point_in_parent, | 129 const gfx::Point& point_in_parent, |
130 int window_component); | 130 int window_component); |
131 | 131 |
132 } // namespace aura | 132 } // namespace aura |
133 | 133 |
134 #endif // ASH_WM_WINDOW_RESIZER_H_ | 134 #endif // ASH_WM_WINDOW_RESIZER_H_ |
OLD | NEW |