OLD | NEW |
1 | 1 |
2 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
3 // Use of this source code is governed by a BSD-style license that can be | 3 // Use of this source code is governed by a BSD-style license that can be |
4 // found in the LICENSE file. | 4 // found in the LICENSE file. |
5 | 5 |
6 #ifndef UI_VIEWS_EVENTS_EVENT_H_ | 6 #ifndef UI_VIEWS_EVENTS_EVENT_H_ |
7 #define UI_VIEWS_EVENTS_EVENT_H_ | 7 #define UI_VIEWS_EVENTS_EVENT_H_ |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 namespace views { | 26 namespace views { |
27 | 27 |
28 class View; | 28 class View; |
29 | 29 |
30 namespace internal { | 30 namespace internal { |
31 class RootView; | 31 class RootView; |
32 } | 32 } |
33 | 33 |
34 //////////////////////////////////////////////////////////////////////////////// | 34 //////////////////////////////////////////////////////////////////////////////// |
35 // | 35 // |
36 // LocatedEvent class | |
37 // | |
38 // A generic event that is used for any events that is located at a specific | |
39 // position in the screen. | |
40 // | |
41 //////////////////////////////////////////////////////////////////////////////// | |
42 class VIEWS_EXPORT LocatedEvent : public ui::Event { | |
43 public: | |
44 int x() const { return location_.x(); } | |
45 int y() const { return location_.y(); } | |
46 const gfx::Point& location() const { return location_; } | |
47 | |
48 protected: | |
49 explicit LocatedEvent(const ui::NativeEvent& native_event); | |
50 | |
51 // TODO(msw): Kill this legacy constructor when we update uses. | |
52 // Simple initialization from cracked metadata. | |
53 LocatedEvent(ui::EventType type, const gfx::Point& location, int flags); | |
54 | |
55 // Create a new LocatedEvent which is identical to the provided model. | |
56 // If source / target views are provided, the model location will be converted | |
57 // from |source| coordinate system to |target| coordinate system. | |
58 LocatedEvent(const LocatedEvent& model, View* source, View* target); | |
59 | |
60 // This constructor is to allow converting the location of an event from the | |
61 // widget's coordinate system to the RootView's coordinate system. | |
62 LocatedEvent(const LocatedEvent& model, View* root); | |
63 | |
64 gfx::Point location_; | |
65 }; | |
66 | |
67 //////////////////////////////////////////////////////////////////////////////// | |
68 // | |
69 // MouseEvent class | 36 // MouseEvent class |
70 // | 37 // |
71 // A mouse event is used for any input event related to the mouse. | 38 // A mouse event is used for any input event related to the mouse. |
72 // | 39 // |
73 //////////////////////////////////////////////////////////////////////////////// | 40 //////////////////////////////////////////////////////////////////////////////// |
74 class VIEWS_EXPORT MouseEvent : public LocatedEvent { | 41 class VIEWS_EXPORT MouseEvent : public ui::LocatedEvent { |
75 public: | 42 public: |
76 explicit MouseEvent(const ui::NativeEvent& native_event); | 43 explicit MouseEvent(const ui::NativeEvent& native_event); |
77 // Create a new MouseEvent which is identical to the provided model. | 44 // Create a new MouseEvent which is identical to the provided model. |
78 // If source / target views are provided, the model location will be converted | 45 // If source / target views are provided, the model location will be converted |
79 // from |source| coordinate system to |target| coordinate system. | 46 // from |source| coordinate system to |target| coordinate system. |
80 MouseEvent(const MouseEvent& model, View* source, View* target); | 47 MouseEvent(const MouseEvent& model, View* source, View* target); |
81 | 48 |
82 // TODO(msw): Kill this legacy constructor when we update uses. | 49 // TODO(msw): Kill this legacy constructor when we update uses. |
83 // Create a new mouse event | 50 // Create a new mouse event |
84 MouseEvent(ui::EventType type, int x, int y, int flags) | 51 MouseEvent(ui::EventType type, int x, int y, int flags) |
85 : LocatedEvent(type, gfx::Point(x, y), flags) { | 52 : LocatedEvent(type, gfx::Point(x, y), gfx::Point(x, y), flags) { |
86 } | 53 } |
87 | 54 |
88 // Conveniences to quickly test what button is down | 55 // Conveniences to quickly test what button is down |
89 bool IsOnlyLeftMouseButton() const { | 56 bool IsOnlyLeftMouseButton() const { |
90 return (flags() & ui::EF_LEFT_MOUSE_BUTTON) && | 57 return (flags() & ui::EF_LEFT_MOUSE_BUTTON) && |
91 !(flags() & (ui::EF_MIDDLE_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON)); | 58 !(flags() & (ui::EF_MIDDLE_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON)); |
92 } | 59 } |
93 | 60 |
94 bool IsLeftMouseButton() const { | 61 bool IsLeftMouseButton() const { |
95 return (flags() & ui::EF_LEFT_MOUSE_BUTTON) != 0; | 62 return (flags() & ui::EF_LEFT_MOUSE_BUTTON) != 0; |
96 } | 63 } |
97 | 64 |
98 bool IsOnlyMiddleMouseButton() const { | 65 bool IsOnlyMiddleMouseButton() const { |
99 return (flags() & ui::EF_MIDDLE_MOUSE_BUTTON) && | 66 return (flags() & ui::EF_MIDDLE_MOUSE_BUTTON) && |
100 !(flags() & (ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON)); | 67 !(flags() & (ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON)); |
101 } | 68 } |
102 | 69 |
103 bool IsMiddleMouseButton() const { | 70 bool IsMiddleMouseButton() const { |
104 return (flags() & ui::EF_MIDDLE_MOUSE_BUTTON) != 0; | 71 return (flags() & ui::EF_MIDDLE_MOUSE_BUTTON) != 0; |
105 } | 72 } |
106 | 73 |
107 bool IsOnlyRightMouseButton() const { | 74 bool IsOnlyRightMouseButton() const { |
108 return (flags() & ui::EF_RIGHT_MOUSE_BUTTON) && | 75 return (flags() & ui::EF_RIGHT_MOUSE_BUTTON) && |
109 !(flags() & (ui::EF_LEFT_MOUSE_BUTTON | ui::EF_MIDDLE_MOUSE_BUTTON)); | 76 !(flags() & (ui::EF_LEFT_MOUSE_BUTTON | ui::EF_MIDDLE_MOUSE_BUTTON)); |
110 } | 77 } |
111 | 78 |
112 bool IsRightMouseButton() const { | 79 bool IsRightMouseButton() const { |
113 return (flags() & ui::EF_RIGHT_MOUSE_BUTTON) != 0; | 80 return (flags() & ui::EF_RIGHT_MOUSE_BUTTON) != 0; |
114 } | 81 } |
115 | |
116 protected: | |
117 MouseEvent(const MouseEvent& model, View* root) | |
118 : LocatedEvent(model, root) { | |
119 } | |
120 | |
121 private: | |
122 friend class internal::RootView; | |
123 }; | 82 }; |
124 | 83 |
125 //////////////////////////////////////////////////////////////////////////////// | 84 //////////////////////////////////////////////////////////////////////////////// |
126 // | 85 // |
127 // TouchEvent class | 86 // TouchEvent class |
128 // | 87 // |
129 // A touch event is generated by touch screen and advanced track | 88 // A touch event is generated by touch screen and advanced track |
130 // pad devices. There is a deliberate direct correspondence between | 89 // pad devices. There is a deliberate direct correspondence between |
131 // TouchEvent and PlatformTouchPoint. | 90 // TouchEvent and PlatformTouchPoint. |
132 // | 91 // |
133 //////////////////////////////////////////////////////////////////////////////// | 92 //////////////////////////////////////////////////////////////////////////////// |
134 class VIEWS_EXPORT TouchEvent : public LocatedEvent { | 93 class VIEWS_EXPORT TouchEvent : public ui::LocatedEvent { |
135 public: | 94 public: |
136 explicit TouchEvent(const ui::NativeEvent& native_event); | 95 explicit TouchEvent(const ui::NativeEvent& native_event); |
137 | 96 |
138 // Create a new touch event. | 97 // Create a new touch event. |
139 TouchEvent(ui::EventType type, | 98 TouchEvent(ui::EventType type, |
140 int x, | 99 int x, |
141 int y, | 100 int y, |
142 int flags, | 101 int flags, |
143 int touch_id, | 102 int touch_id, |
144 float radius_x, | 103 float radius_x, |
145 float radius_y, | 104 float radius_y, |
146 float angle, | 105 float angle, |
147 float force); | 106 float force); |
148 | 107 |
149 // Create a new TouchEvent which is identical to the provided model. | 108 // Create a new TouchEvent which is identical to the provided model. |
150 // If source / target views are provided, the model location will be converted | 109 // If source / target views are provided, the model location will be converted |
151 // from |source| coordinate system to |target| coordinate system. | 110 // from |source| coordinate system to |target| coordinate system. |
152 TouchEvent(const TouchEvent& model, View* source, View* target); | 111 TouchEvent(const TouchEvent& model, View* source, View* target); |
153 | 112 |
154 virtual ~TouchEvent(); | 113 virtual ~TouchEvent(); |
155 | 114 |
156 int identity() const { return touch_id_; } | 115 int identity() const { return touch_id_; } |
157 | 116 |
158 float radius_x() const { return radius_x_; } | 117 float radius_x() const { return radius_x_; } |
159 float radius_y() const { return radius_y_; } | 118 float radius_y() const { return radius_y_; } |
160 float rotation_angle() const { return rotation_angle_; } | 119 float rotation_angle() const { return rotation_angle_; } |
161 float force() const { return force_; } | 120 float force() const { return force_; } |
162 | 121 |
163 private: | 122 private: |
164 friend class internal::RootView; | |
165 | |
166 TouchEvent(const TouchEvent& model, View* root); | |
167 | |
168 // The identity (typically finger) of the touch starting at 0 and incrementing | 123 // The identity (typically finger) of the touch starting at 0 and incrementing |
169 // for each separable additional touch that the hardware can detect. | 124 // for each separable additional touch that the hardware can detect. |
170 const int touch_id_; | 125 const int touch_id_; |
171 | 126 |
172 // Radius of the X (major) axis of the touch ellipse. 1.0 if unknown. | 127 // Radius of the X (major) axis of the touch ellipse. 1.0 if unknown. |
173 const float radius_x_; | 128 const float radius_x_; |
174 | 129 |
175 // Radius of the Y (minor) axis of the touch ellipse. 1.0 if unknown. | 130 // Radius of the Y (minor) axis of the touch ellipse. 1.0 if unknown. |
176 const float radius_y_; | 131 const float radius_y_; |
177 | 132 |
(...skipping 21 matching lines...) Expand all Loading... |
199 // See |offset| for details. | 154 // See |offset| for details. |
200 static const int kWheelDelta; | 155 static const int kWheelDelta; |
201 | 156 |
202 explicit MouseWheelEvent(const ui::NativeEvent& native_event); | 157 explicit MouseWheelEvent(const ui::NativeEvent& native_event); |
203 explicit MouseWheelEvent(const ScrollEvent& scroll_event); | 158 explicit MouseWheelEvent(const ScrollEvent& scroll_event); |
204 | 159 |
205 // The amount to scroll. This is in multiples of kWheelDelta. | 160 // The amount to scroll. This is in multiples of kWheelDelta. |
206 int offset() const { return offset_; } | 161 int offset() const { return offset_; } |
207 | 162 |
208 private: | 163 private: |
209 friend class internal::RootView; | |
210 | |
211 MouseWheelEvent(const MouseWheelEvent& model, View* root) | |
212 : MouseEvent(model, root), | |
213 offset_(model.offset_) { | |
214 } | |
215 | |
216 int offset_; | 164 int offset_; |
217 | 165 |
218 DISALLOW_COPY_AND_ASSIGN(MouseWheelEvent); | 166 DISALLOW_COPY_AND_ASSIGN(MouseWheelEvent); |
219 }; | 167 }; |
220 | 168 |
221 //////////////////////////////////////////////////////////////////////////////// | 169 //////////////////////////////////////////////////////////////////////////////// |
222 // | 170 // |
223 // DropTargetEvent class | 171 // DropTargetEvent class |
224 // | 172 // |
225 // A DropTargetEvent is sent to the view the mouse is over during a drag and | 173 // A DropTargetEvent is sent to the view the mouse is over during a drag and |
226 // drop operation. | 174 // drop operation. |
227 // | 175 // |
228 //////////////////////////////////////////////////////////////////////////////// | 176 //////////////////////////////////////////////////////////////////////////////// |
229 class VIEWS_EXPORT DropTargetEvent : public LocatedEvent { | 177 class VIEWS_EXPORT DropTargetEvent : public ui::LocatedEvent { |
230 public: | 178 public: |
231 DropTargetEvent(const ui::OSExchangeData& data, | 179 DropTargetEvent(const ui::OSExchangeData& data, |
232 int x, | 180 int x, |
233 int y, | 181 int y, |
234 int source_operations) | 182 int source_operations) |
235 : LocatedEvent(ui::ET_DROP_TARGET_EVENT, gfx::Point(x, y), 0), | 183 : LocatedEvent( |
| 184 ui::ET_DROP_TARGET_EVENT, gfx::Point(x, y), gfx::Point(x, y), 0), |
236 data_(data), | 185 data_(data), |
237 source_operations_(source_operations) { | 186 source_operations_(source_operations) { |
238 // TODO(msw): Hook up key state flags for CTRL + drag and drop, etc. | 187 // TODO(msw): Hook up key state flags for CTRL + drag and drop, etc. |
239 } | 188 } |
240 | 189 |
241 const ui::OSExchangeData& data() const { return data_; } | 190 const ui::OSExchangeData& data() const { return data_; } |
242 int source_operations() const { return source_operations_; } | 191 int source_operations() const { return source_operations_; } |
243 | 192 |
244 private: | 193 private: |
245 // Data associated with the drag/drop session. | 194 // Data associated with the drag/drop session. |
246 const ui::OSExchangeData& data_; | 195 const ui::OSExchangeData& data_; |
247 | 196 |
248 // Bitmask of supported ui::DragDropTypes::DragOperation by the source. | 197 // Bitmask of supported ui::DragDropTypes::DragOperation by the source. |
249 int source_operations_; | 198 int source_operations_; |
250 | 199 |
251 DISALLOW_COPY_AND_ASSIGN(DropTargetEvent); | 200 DISALLOW_COPY_AND_ASSIGN(DropTargetEvent); |
252 }; | 201 }; |
253 | 202 |
254 class VIEWS_EXPORT ScrollEvent : public MouseEvent { | 203 class VIEWS_EXPORT ScrollEvent : public MouseEvent { |
255 public: | 204 public: |
256 explicit ScrollEvent(const ui::NativeEvent& native_event); | 205 explicit ScrollEvent(const ui::NativeEvent& native_event); |
257 | 206 |
258 float x_offset() const { return x_offset_; } | 207 float x_offset() const { return x_offset_; } |
259 float y_offset() const { return y_offset_; } | 208 float y_offset() const { return y_offset_; } |
260 | 209 |
261 private: | 210 private: |
262 friend class internal::RootView; | |
263 | |
264 ScrollEvent(const ScrollEvent& model, View* root) | |
265 : MouseEvent(model, root), | |
266 x_offset_(model.x_offset()), | |
267 y_offset_(model.y_offset()) { | |
268 } | |
269 | |
270 float x_offset_; | 211 float x_offset_; |
271 float y_offset_; | 212 float y_offset_; |
272 | 213 |
273 DISALLOW_COPY_AND_ASSIGN(ScrollEvent); | 214 DISALLOW_COPY_AND_ASSIGN(ScrollEvent); |
274 }; | 215 }; |
275 | 216 |
276 //////////////////////////////////////////////////////////////////////////////// | 217 //////////////////////////////////////////////////////////////////////////////// |
277 // GestureEvent class | 218 // GestureEvent class |
278 // | 219 // |
279 //////////////////////////////////////////////////////////////////////////////// | 220 //////////////////////////////////////////////////////////////////////////////// |
280 class VIEWS_EXPORT GestureEvent : public LocatedEvent { | 221 class VIEWS_EXPORT GestureEvent : public ui::LocatedEvent { |
281 public: | 222 public: |
282 explicit GestureEvent(const ui::NativeEvent& native_event); | 223 explicit GestureEvent(const ui::NativeEvent& native_event); |
283 | 224 |
284 // Create a new GestureEvent which is identical to the provided model. | 225 // Create a new GestureEvent which is identical to the provided model. |
285 // If source / target views are provided, the model location will be converted | 226 // If source / target views are provided, the model location will be converted |
286 // from |source| coordinate system to |target| coordinate system. | 227 // from |source| coordinate system to |target| coordinate system. |
287 GestureEvent(const GestureEvent& model, View* source, View* target); | 228 GestureEvent(const GestureEvent& model, View* source, View* target); |
288 | 229 |
289 virtual ~GestureEvent(); | 230 virtual ~GestureEvent(); |
290 | 231 |
291 const ui::GestureEventDetails& details() const { return details_; } | 232 const ui::GestureEventDetails& details() const { return details_; } |
292 | 233 |
293 protected: | 234 protected: |
294 GestureEvent(ui::EventType type, int x, int y, int flags); | 235 GestureEvent(ui::EventType type, int x, int y, int flags); |
295 | 236 |
296 private: | 237 private: |
297 friend class internal::RootView; | |
298 | |
299 GestureEvent(const GestureEvent& model, View* root); | |
300 | |
301 ui::GestureEventDetails details_; | 238 ui::GestureEventDetails details_; |
302 | 239 |
303 DISALLOW_COPY_AND_ASSIGN(GestureEvent); | 240 DISALLOW_COPY_AND_ASSIGN(GestureEvent); |
304 }; | 241 }; |
305 | 242 |
306 class VIEWS_EXPORT GestureEventForTest : public GestureEvent { | 243 class VIEWS_EXPORT GestureEventForTest : public GestureEvent { |
307 public: | 244 public: |
308 GestureEventForTest(ui::EventType type, int x, int y, int flags); | 245 GestureEventForTest(ui::EventType type, int x, int y, int flags); |
309 | 246 |
310 private: | 247 private: |
311 DISALLOW_COPY_AND_ASSIGN(GestureEventForTest); | 248 DISALLOW_COPY_AND_ASSIGN(GestureEventForTest); |
312 }; | 249 }; |
313 | 250 |
314 #if defined(OS_WIN) | 251 #if defined(OS_WIN) |
315 int GetModifiersFromKeyState(); | 252 int GetModifiersFromKeyState(); |
316 #endif | 253 #endif |
317 | 254 |
318 } // namespace views | 255 } // namespace views |
319 | 256 |
320 #endif // UI_VIEWS_EVENTS_EVENT_H_ | 257 #endif // UI_VIEWS_EVENTS_EVENT_H_ |
OLD | NEW |