OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 VIEWS_EVENTS_EVENT_H_ | 5 #ifndef VIEWS_EVENTS_EVENT_H_ |
6 #define VIEWS_EVENTS_EVENT_H_ | 6 #define VIEWS_EVENTS_EVENT_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/time.h" | 10 #include "base/time.h" |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 type_ == ui::ET_TOUCH_PRESSED || | 76 type_ == ui::ET_TOUCH_PRESSED || |
77 type_ == ui::ET_TOUCH_MOVED || | 77 type_ == ui::ET_TOUCH_MOVED || |
78 type_ == ui::ET_TOUCH_STATIONARY || | 78 type_ == ui::ET_TOUCH_STATIONARY || |
79 type_ == ui::ET_TOUCH_CANCELLED; | 79 type_ == ui::ET_TOUCH_CANCELLED; |
80 } | 80 } |
81 #endif | 81 #endif |
82 | 82 |
83 #if defined(OS_WIN) | 83 #if defined(OS_WIN) |
84 // Returns the EventFlags in terms of windows flags. | 84 // Returns the EventFlags in terms of windows flags. |
85 int GetWindowsFlags() const; | 85 int GetWindowsFlags() const; |
86 | |
87 // Convert windows flags to views::Event flags | |
88 static int ConvertWindowsFlags(uint32 win_flags); | |
89 #elif defined(OS_LINUX) | 86 #elif defined(OS_LINUX) |
90 // Convert the state member on a GdkEvent to views::Event flags | 87 // Convert the state member on a GdkEvent to views::Event flags |
91 static int GetFlagsFromGdkState(unsigned int state); | 88 static int GetFlagsFromGdkState(unsigned int state); |
92 #endif | 89 #endif |
93 | 90 |
94 protected: | 91 protected: |
95 Event(ui::EventType type, int flags); | 92 Event(ui::EventType type, int flags); |
96 Event(NativeEvent native_event, ui::EventType type, int flags); | 93 Event(NativeEvent native_event, ui::EventType type, int flags); |
97 // Because the world is complicated, sometimes we have two different kinds of | 94 // Because the world is complicated, sometimes we have two different kinds of |
98 // NativeEvent in play in the same executable. See native_types.h for the tale | 95 // NativeEvent in play in the same executable. See native_types.h for the tale |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 // position in the screen. | 127 // position in the screen. |
131 // | 128 // |
132 //////////////////////////////////////////////////////////////////////////////// | 129 //////////////////////////////////////////////////////////////////////////////// |
133 class LocatedEvent : public Event { | 130 class LocatedEvent : public Event { |
134 public: | 131 public: |
135 int x() const { return location_.x(); } | 132 int x() const { return location_.x(); } |
136 int y() const { return location_.y(); } | 133 int y() const { return location_.y(); } |
137 const gfx::Point& location() const { return location_; } | 134 const gfx::Point& location() const { return location_; } |
138 | 135 |
139 protected: | 136 protected: |
140 // This constructor is to allow converting the location of an event from the | |
141 // widget's coordinate system to the RootView's coordinate system. | |
142 LocatedEvent(const LocatedEvent& model, RootView* root); | |
143 | |
144 explicit LocatedEvent(NativeEvent native_event); | 137 explicit LocatedEvent(NativeEvent native_event); |
145 LocatedEvent(NativeEvent2 native_event_2, FromNativeEvent2 from_native); | 138 LocatedEvent(NativeEvent2 native_event_2, FromNativeEvent2 from_native); |
146 | 139 |
147 // TODO(msw): Kill this legacy constructor when we update MouseEvent??? | 140 // TODO(msw): Kill this legacy constructor when we update uses. |
148 // Simple initialization from cracked metadata. | 141 // Simple initialization from cracked metadata. |
149 LocatedEvent(ui::EventType type, const gfx::Point& location, int flags); | 142 LocatedEvent(ui::EventType type, const gfx::Point& location, int flags); |
150 | 143 |
151 // Create a new LocatedEvent which is identical to the provided model. | 144 // Create a new LocatedEvent which is identical to the provided model. |
152 // If source / target views are provided, the model location will be converted | 145 // If source / target views are provided, the model location will be converted |
153 // from 'source' coordinate system to 'target' coordinate system | 146 // from |source| coordinate system to |target| coordinate system. |
154 LocatedEvent(const LocatedEvent& model, View* source, View* target); | 147 LocatedEvent(const LocatedEvent& model, View* source, View* target); |
155 | 148 |
156 private: | 149 // This constructor is to allow converting the location of an event from the |
| 150 // widget's coordinate system to the RootView's coordinate system. |
| 151 LocatedEvent(const LocatedEvent& model, RootView* root); |
| 152 |
157 gfx::Point location_; | 153 gfx::Point location_; |
158 }; | 154 }; |
159 | 155 |
160 //////////////////////////////////////////////////////////////////////////////// | 156 //////////////////////////////////////////////////////////////////////////////// |
161 // | 157 // |
162 // MouseEvent class | 158 // MouseEvent class |
163 // | 159 // |
164 // A mouse event is used for any input event related to the mouse. | 160 // A mouse event is used for any input event related to the mouse. |
165 // | 161 // |
166 //////////////////////////////////////////////////////////////////////////////// | 162 //////////////////////////////////////////////////////////////////////////////// |
167 class MouseEvent : public LocatedEvent { | 163 class MouseEvent : public LocatedEvent { |
168 public: | 164 public: |
| 165 explicit MouseEvent(NativeEvent native_event); |
| 166 MouseEvent(NativeEvent2 native_event_2, FromNativeEvent2 from_native); |
| 167 |
| 168 // Create a new MouseEvent which is identical to the provided model. |
| 169 // If source / target views are provided, the model location will be converted |
| 170 // from |source| coordinate system to |target| coordinate system. |
| 171 MouseEvent(const MouseEvent& model, View* source, View* target); |
| 172 |
| 173 // TODO(msw): Kill this legacy constructor when we update uses. |
169 // Create a new mouse event | 174 // Create a new mouse event |
170 MouseEvent(ui::EventType type, int x, int y, int flags) | 175 MouseEvent(ui::EventType type, int x, int y, int flags) |
171 : LocatedEvent(type, gfx::Point(x, y), flags) { | 176 : LocatedEvent(type, gfx::Point(x, y), flags) { |
172 } | 177 } |
173 | 178 |
174 // Create a new mouse event from a type and a point. If from / to views | 179 // TODO(msw): Kill this legacy constructor when we update uses. |
175 // are provided, the point will be converted from 'from' coordinate system to | 180 // Create a new mouse event from a type and a point. If source / target views |
176 // 'to' coordinate system. | 181 // are provided, the point will be converted from |source| coordinate system |
| 182 // to |target| coordinate system. |
177 MouseEvent(ui::EventType type, | 183 MouseEvent(ui::EventType type, |
178 View* from, | 184 View* source, |
179 View* to, | 185 View* target, |
180 const gfx::Point &l, | 186 const gfx::Point &l, |
181 int flags); | 187 int flags); |
182 | 188 |
183 // Create a new MouseEvent which is identical to the provided model. | |
184 // If from / to views are provided, the model location will be converted | |
185 // from 'from' coordinate system to 'to' coordinate system | |
186 MouseEvent(const MouseEvent& model, View* from, View* to); | |
187 | |
188 #if defined(TOUCH_UI) | |
189 // Create a mouse event from an X mouse event. | |
190 explicit MouseEvent(XEvent* xevent); | |
191 #endif | |
192 | |
193 // Conveniences to quickly test what button is down | 189 // Conveniences to quickly test what button is down |
194 bool IsOnlyLeftMouseButton() const { | 190 bool IsOnlyLeftMouseButton() const { |
195 return (flags() & ui::EF_LEFT_BUTTON_DOWN) && | 191 return (flags() & ui::EF_LEFT_BUTTON_DOWN) && |
196 !(flags() & (ui::EF_MIDDLE_BUTTON_DOWN | ui::EF_RIGHT_BUTTON_DOWN)); | 192 !(flags() & (ui::EF_MIDDLE_BUTTON_DOWN | ui::EF_RIGHT_BUTTON_DOWN)); |
197 } | 193 } |
198 | 194 |
199 bool IsLeftMouseButton() const { | 195 bool IsLeftMouseButton() const { |
200 return (flags() & ui::EF_LEFT_BUTTON_DOWN) != 0; | 196 return (flags() & ui::EF_LEFT_BUTTON_DOWN) != 0; |
201 } | 197 } |
202 | 198 |
203 bool IsOnlyMiddleMouseButton() const { | 199 bool IsOnlyMiddleMouseButton() const { |
204 return (flags() & ui::EF_MIDDLE_BUTTON_DOWN) && | 200 return (flags() & ui::EF_MIDDLE_BUTTON_DOWN) && |
205 !(flags() & (ui::EF_LEFT_BUTTON_DOWN | ui::EF_RIGHT_BUTTON_DOWN)); | 201 !(flags() & (ui::EF_LEFT_BUTTON_DOWN | ui::EF_RIGHT_BUTTON_DOWN)); |
206 } | 202 } |
207 | 203 |
208 bool IsMiddleMouseButton() const { | 204 bool IsMiddleMouseButton() const { |
209 return (flags() & ui::EF_MIDDLE_BUTTON_DOWN) != 0; | 205 return (flags() & ui::EF_MIDDLE_BUTTON_DOWN) != 0; |
210 } | 206 } |
211 | 207 |
212 bool IsOnlyRightMouseButton() const { | 208 bool IsOnlyRightMouseButton() const { |
213 return (flags() & ui::EF_RIGHT_BUTTON_DOWN) && | 209 return (flags() & ui::EF_RIGHT_BUTTON_DOWN) && |
214 !(flags() & (ui::EF_LEFT_BUTTON_DOWN | ui::EF_MIDDLE_BUTTON_DOWN)); | 210 !(flags() & (ui::EF_LEFT_BUTTON_DOWN | ui::EF_MIDDLE_BUTTON_DOWN)); |
215 } | 211 } |
216 | 212 |
217 bool IsRightMouseButton() const { | 213 bool IsRightMouseButton() const { |
218 return (flags() & ui::EF_RIGHT_BUTTON_DOWN) != 0; | 214 return (flags() & ui::EF_RIGHT_BUTTON_DOWN) != 0; |
219 } | 215 } |
220 | 216 |
| 217 protected: |
| 218 MouseEvent(const MouseEvent& model, RootView* root) |
| 219 : LocatedEvent(model, root) { |
| 220 } |
| 221 |
221 private: | 222 private: |
222 friend class RootView; | 223 friend class RootView; |
223 | 224 |
224 MouseEvent(const MouseEvent& model, RootView* root) | |
225 : LocatedEvent(model, root) { | |
226 } | |
227 | |
228 DISALLOW_COPY_AND_ASSIGN(MouseEvent); | 225 DISALLOW_COPY_AND_ASSIGN(MouseEvent); |
229 }; | 226 }; |
230 | 227 |
231 #if defined(TOUCH_UI) | 228 #if defined(TOUCH_UI) |
232 //////////////////////////////////////////////////////////////////////////////// | 229 //////////////////////////////////////////////////////////////////////////////// |
233 // | 230 // |
234 // TouchEvent class | 231 // TouchEvent class |
235 // | 232 // |
236 // A touch event is generated by touch screen and advanced track | 233 // A touch event is generated by touch screen and advanced track |
237 // pad devices. There is a deliberate direct correspondence between | 234 // pad devices. There is a deliberate direct correspondence between |
238 // TouchEvent and PlatformTouchPoint. | 235 // TouchEvent and PlatformTouchPoint. |
239 // | 236 // |
240 //////////////////////////////////////////////////////////////////////////////// | 237 //////////////////////////////////////////////////////////////////////////////// |
241 class TouchEvent : public LocatedEvent { | 238 class TouchEvent : public LocatedEvent { |
242 public: | 239 public: |
| 240 explicit TouchEvent(NativeEvent native_event); |
| 241 TouchEvent(NativeEvent2 native_event_2, FromNativeEvent2 from_native); |
| 242 |
243 // Create a new touch event. | 243 // Create a new touch event. |
244 TouchEvent(ui::EventType type, int x, int y, int flags, int touch_id); | 244 TouchEvent(ui::EventType type, int x, int y, int flags, int touch_id); |
245 | 245 |
246 // Create a new touch event from a type and a point. If from / to views | 246 // Create a new touch event from a type and a point. If from / to views |
247 // are provided, the point will be converted from 'from' coordinate system to | 247 // are provided, the point will be converted from 'source' coordinate system |
248 // 'to' coordinate system. | 248 // to 'target' coordinate system. |
249 TouchEvent(ui::EventType type, | 249 TouchEvent(ui::EventType type, |
250 View* from, | 250 View* source, |
251 View* to, | 251 View* target, |
252 const gfx::Point& l, | 252 const gfx::Point& l, |
253 int flags, | 253 int flags, |
254 int touch_id); | 254 int touch_id); |
255 | 255 |
256 // Create a new TouchEvent which is identical to the provided model. | 256 // Create a new TouchEvent which is identical to the provided model. |
257 // If from / to views are provided, the model location will be converted | 257 // If source / target views are provided, the model location will be converted |
258 // from 'from' coordinate system to 'to' coordinate system. | 258 // from |source| coordinate system to |target| coordinate system. |
259 TouchEvent(const TouchEvent& model, View* from, View* to); | 259 TouchEvent(const TouchEvent& model, View* source, View* target); |
260 | |
261 #if defined(HAVE_XINPUT2) | |
262 explicit TouchEvent(XEvent* xev); | |
263 #endif | |
264 | 260 |
265 bool identity() const { return touch_id_; } | 261 bool identity() const { return touch_id_; } |
266 | 262 |
267 private: | 263 private: |
268 friend class RootView; | 264 friend class RootView; |
269 | 265 |
270 TouchEvent(const TouchEvent& model, RootView* root) | 266 TouchEvent(const TouchEvent& model, RootView* root) |
271 : LocatedEvent(model, root), | 267 : LocatedEvent(model, root), |
272 touch_id_(model.touch_id_) { | 268 touch_id_(model.touch_id_) { |
273 } | 269 } |
274 | 270 |
275 // The identity (typically finger) of the touch starting at 0 and incrementing | 271 // The identity (typically finger) of the touch starting at 0 and incrementing |
276 // for each separable additional touch that the hardware can detect. | 272 // for each separable additional touch that the hardware can detect. |
277 const int touch_id_; | 273 const int touch_id_; |
278 | 274 |
279 DISALLOW_COPY_AND_ASSIGN(TouchEvent); | 275 DISALLOW_COPY_AND_ASSIGN(TouchEvent); |
280 }; | 276 }; |
281 #endif | 277 #endif |
282 | 278 |
283 //////////////////////////////////////////////////////////////////////////////// | 279 //////////////////////////////////////////////////////////////////////////////// |
284 // KeyEvent class | 280 // KeyEvent class |
285 // | 281 // |
286 // KeyEvent encapsulates keyboard input events - key press and release. | 282 // KeyEvent encapsulates keyboard input events - key press and release. |
287 // | 283 // |
| 284 //////////////////////////////////////////////////////////////////////////////// |
288 class KeyEvent : public Event { | 285 class KeyEvent : public Event { |
289 public: | 286 public: |
290 explicit KeyEvent(NativeEvent native_event); | 287 explicit KeyEvent(NativeEvent native_event); |
291 KeyEvent(NativeEvent2 native_event_2, FromNativeEvent2 from_native); | 288 KeyEvent(NativeEvent2 native_event_2, FromNativeEvent2 from_native); |
292 | 289 |
293 // Creates a new KeyEvent synthetically (i.e. not in response to an input | 290 // Creates a new KeyEvent synthetically (i.e. not in response to an input |
294 // event from the host environment). This is typically only used in testing as | 291 // event from the host environment). This is typically only used in testing as |
295 // some metadata obtainable from the underlying native event is not present. | 292 // some metadata obtainable from the underlying native event is not present. |
296 // TODO(beng): see if we can kill this. | 293 // TODO(beng): see if we can kill this. |
297 KeyEvent(ui::EventType type, | 294 KeyEvent(ui::EventType type, |
298 ui::KeyboardCode key_code, | 295 ui::KeyboardCode key_code, |
299 int event_flags); | 296 int event_flags); |
300 | 297 |
301 ui::KeyboardCode key_code() const { return key_code_; } | 298 ui::KeyboardCode key_code() const { return key_code_; } |
302 | 299 |
303 private: | 300 private: |
304 ui::KeyboardCode key_code_; | 301 ui::KeyboardCode key_code_; |
305 | 302 |
306 DISALLOW_COPY_AND_ASSIGN(KeyEvent); | 303 DISALLOW_COPY_AND_ASSIGN(KeyEvent); |
307 }; | 304 }; |
308 | 305 |
309 //////////////////////////////////////////////////////////////////////////////// | 306 //////////////////////////////////////////////////////////////////////////////// |
310 // | 307 // |
311 // MouseWheelEvent class | 308 // MouseWheelEvent class |
312 // | 309 // |
313 // A MouseWheelEvent is used to propagate mouse wheel user events. | 310 // A MouseWheelEvent is used to propagate mouse wheel user events. |
314 // Note: e.GetOffset() > 0 means scroll up / left. | 311 // Note: e.GetOffset() > 0 means scroll up / left. |
315 // | 312 // |
316 //////////////////////////////////////////////////////////////////////////////// | 313 //////////////////////////////////////////////////////////////////////////////// |
317 class MouseWheelEvent : public LocatedEvent { | 314 class MouseWheelEvent : public MouseEvent { |
318 public: | 315 public: |
319 // See |offset| for details. | 316 // See |offset| for details. |
320 static const int kWheelDelta; | 317 static const int kWheelDelta; |
321 | 318 |
322 explicit MouseWheelEvent(NativeEvent native_event); | 319 explicit MouseWheelEvent(NativeEvent native_event); |
323 MouseWheelEvent(NativeEvent2 native_event_2, FromNativeEvent2 from_native); | 320 MouseWheelEvent(NativeEvent2 native_event_2, FromNativeEvent2 from_native); |
324 | 321 |
325 // The amount to scroll. This is in multiples of kWheelDelta. | 322 // The amount to scroll. This is in multiples of kWheelDelta. |
326 int offset() const { return offset_; } | 323 int offset() const { return offset_; } |
327 | 324 |
328 private: | 325 private: |
329 friend class RootView; | 326 friend class RootView; |
330 | 327 |
331 MouseWheelEvent(const MouseWheelEvent& model, RootView* root) | 328 MouseWheelEvent(const MouseWheelEvent& model, RootView* root) |
332 : LocatedEvent(model, root), | 329 : MouseEvent(model, root), |
333 offset_(model.offset_) { | 330 offset_(model.offset_) { |
334 } | 331 } |
335 | 332 |
336 int offset_; | 333 int offset_; |
337 | 334 |
338 DISALLOW_COPY_AND_ASSIGN(MouseWheelEvent); | 335 DISALLOW_COPY_AND_ASSIGN(MouseWheelEvent); |
339 }; | 336 }; |
340 | 337 |
341 //////////////////////////////////////////////////////////////////////////////// | 338 //////////////////////////////////////////////////////////////////////////////// |
342 // | 339 // |
(...skipping 23 matching lines...) Expand all Loading... |
366 | 363 |
367 // Bitmask of supported ui::DragDropTypes::DragOperation by the source. | 364 // Bitmask of supported ui::DragDropTypes::DragOperation by the source. |
368 int source_operations_; | 365 int source_operations_; |
369 | 366 |
370 DISALLOW_COPY_AND_ASSIGN(DropTargetEvent); | 367 DISALLOW_COPY_AND_ASSIGN(DropTargetEvent); |
371 }; | 368 }; |
372 | 369 |
373 } // namespace views | 370 } // namespace views |
374 | 371 |
375 #endif // VIEWS_EVENTS_EVENT_H_ | 372 #endif // VIEWS_EVENTS_EVENT_H_ |
OLD | NEW |