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 #include "ui/base/event.h" | 5 #include "ui/base/event.h" |
6 | 6 |
7 #if defined(USE_X11) | 7 #if defined(USE_X11) |
8 #include <X11/Xlib.h> | 8 #include <X11/Xlib.h> |
9 #endif | 9 #endif |
10 | 10 |
(...skipping 21 matching lines...) Expand all Loading... |
32 NOTREACHED() << | 32 NOTREACHED() << |
33 "Don't know how to copy base::NativeEvent for this platform"; | 33 "Don't know how to copy base::NativeEvent for this platform"; |
34 return NULL; | 34 return NULL; |
35 #endif | 35 #endif |
36 } | 36 } |
37 | 37 |
38 } // namespace | 38 } // namespace |
39 | 39 |
40 namespace ui { | 40 namespace ui { |
41 | 41 |
| 42 //////////////////////////////////////////////////////////////////////////////// |
| 43 // Event |
| 44 |
42 Event::~Event() { | 45 Event::~Event() { |
43 #if defined(USE_X11) | 46 #if defined(USE_X11) |
44 if (delete_native_event_) | 47 if (delete_native_event_) |
45 delete native_event_; | 48 delete native_event_; |
46 #endif | 49 #endif |
47 } | 50 } |
48 | 51 |
49 bool Event::HasNativeEvent() const { | 52 bool Event::HasNativeEvent() const { |
50 base::NativeEvent null_event; | 53 base::NativeEvent null_event; |
51 std::memset(&null_event, 0, sizeof(null_event)); | 54 std::memset(&null_event, 0, sizeof(null_event)); |
(...skipping 13 matching lines...) Expand all Loading... |
65 int flags) | 68 int flags) |
66 : type_(type), | 69 : type_(type), |
67 time_stamp_(EventTimeFromNative(native_event)), | 70 time_stamp_(EventTimeFromNative(native_event)), |
68 flags_(flags), | 71 flags_(flags), |
69 delete_native_event_(false) { | 72 delete_native_event_(false) { |
70 InitWithNativeEvent(native_event); | 73 InitWithNativeEvent(native_event); |
71 } | 74 } |
72 | 75 |
73 Event::Event(const Event& copy) | 76 Event::Event(const Event& copy) |
74 : native_event_(copy.native_event_), | 77 : native_event_(copy.native_event_), |
75 ui_native_event_(copy.ui_native_event_), | |
76 type_(copy.type_), | 78 type_(copy.type_), |
77 time_stamp_(copy.time_stamp_), | 79 time_stamp_(copy.time_stamp_), |
78 flags_(copy.flags_), | 80 flags_(copy.flags_), |
79 delete_native_event_(false) { | 81 delete_native_event_(false) { |
80 } | 82 } |
81 | 83 |
82 void Event::Init() { | 84 void Event::Init() { |
83 std::memset(&native_event_, 0, sizeof(native_event_)); | 85 std::memset(&native_event_, 0, sizeof(native_event_)); |
84 std::memset(&ui_native_event_, 0, sizeof(ui_native_event_)); | |
85 } | 86 } |
86 | 87 |
87 void Event::InitWithNativeEvent(const base::NativeEvent& native_event) { | 88 void Event::InitWithNativeEvent(const base::NativeEvent& native_event) { |
88 native_event_ = native_event; | 89 native_event_ = native_event; |
89 std::memset(&ui_native_event_, 0, sizeof(ui_native_event_)); | |
90 } | 90 } |
91 | 91 |
| 92 //////////////////////////////////////////////////////////////////////////////// |
| 93 // LocatedEvent |
| 94 |
92 LocatedEvent::~LocatedEvent() { | 95 LocatedEvent::~LocatedEvent() { |
93 } | 96 } |
94 | 97 |
95 LocatedEvent::LocatedEvent(const base::NativeEvent& native_event) | 98 LocatedEvent::LocatedEvent(const base::NativeEvent& native_event) |
96 : Event(native_event, | 99 : Event(native_event, |
97 EventTypeFromNative(native_event), | 100 EventTypeFromNative(native_event), |
98 EventFlagsFromNative(native_event)), | 101 EventFlagsFromNative(native_event)), |
99 location_(EventLocationFromNative(native_event)), | 102 location_(EventLocationFromNative(native_event)), |
100 root_location_(location_) { | 103 root_location_(location_) { |
101 } | 104 } |
(...skipping 15 matching lines...) Expand all Loading... |
117 | 120 |
118 void LocatedEvent::UpdateForRootTransform(const Transform& root_transform) { | 121 void LocatedEvent::UpdateForRootTransform(const Transform& root_transform) { |
119 // Transform has to be done at root level. | 122 // Transform has to be done at root level. |
120 DCHECK_EQ(root_location_.x(), location_.x()); | 123 DCHECK_EQ(root_location_.x(), location_.x()); |
121 DCHECK_EQ(root_location_.y(), location_.y()); | 124 DCHECK_EQ(root_location_.y(), location_.y()); |
122 gfx::Point3f p(location_); | 125 gfx::Point3f p(location_); |
123 root_transform.TransformPointReverse(p); | 126 root_transform.TransformPointReverse(p); |
124 root_location_ = location_ = p.AsPoint(); | 127 root_location_ = location_ = p.AsPoint(); |
125 } | 128 } |
126 | 129 |
| 130 //////////////////////////////////////////////////////////////////////////////// |
| 131 // MouseEvent |
| 132 |
127 MouseEvent::MouseEvent(const base::NativeEvent& native_event) | 133 MouseEvent::MouseEvent(const base::NativeEvent& native_event) |
128 : LocatedEvent(native_event), | 134 : LocatedEvent(native_event), |
129 changed_button_flags_( | 135 changed_button_flags_( |
130 GetChangedMouseButtonFlagsFromNative(native_event)) { | 136 GetChangedMouseButtonFlagsFromNative(native_event)) { |
131 if (type() == ET_MOUSE_PRESSED) | 137 if (type() == ET_MOUSE_PRESSED) |
132 SetClickCount(GetRepeatCount(*this)); | 138 SetClickCount(GetRepeatCount(*this)); |
133 } | 139 } |
134 | 140 |
135 MouseEvent::MouseEvent(EventType type, | 141 MouseEvent::MouseEvent(EventType type, |
136 const gfx::Point& location, | 142 const gfx::Point& location, |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 f &= ~EF_IS_DOUBLE_CLICK; | 229 f &= ~EF_IS_DOUBLE_CLICK; |
224 f |= EF_IS_TRIPLE_CLICK; | 230 f |= EF_IS_TRIPLE_CLICK; |
225 break; | 231 break; |
226 } | 232 } |
227 set_flags(f); | 233 set_flags(f); |
228 } | 234 } |
229 | 235 |
230 MouseEvent::MouseEvent(const MouseEvent& model) : LocatedEvent(model) { | 236 MouseEvent::MouseEvent(const MouseEvent& model) : LocatedEvent(model) { |
231 } | 237 } |
232 | 238 |
233 MouseWheelEvent::MouseWheelEvent(const NativeEvent& native_event) | 239 //////////////////////////////////////////////////////////////////////////////// |
234 #if defined(USE_AURA) | 240 // MouseWheelEvent |
235 : MouseEvent(static_cast<const MouseEvent&>(*native_event)), | 241 |
236 offset_(GetMouseWheelOffset(native_event->native_event())) { | 242 MouseWheelEvent::MouseWheelEvent(const base::NativeEvent& native_event) |
237 #else | |
238 : MouseEvent(native_event), | 243 : MouseEvent(native_event), |
239 offset_(GetMouseWheelOffset(native_event)) { | 244 offset_(GetMouseWheelOffset(native_event)) { |
240 #endif | 245 } |
| 246 |
| 247 MouseWheelEvent::MouseWheelEvent(const MouseEvent& mouse_event) |
| 248 : MouseEvent(mouse_event), |
| 249 offset_(GetMouseWheelOffset(mouse_event.native_event())) { |
241 } | 250 } |
242 | 251 |
243 MouseWheelEvent::MouseWheelEvent(const ScrollEvent& scroll_event) | 252 MouseWheelEvent::MouseWheelEvent(const ScrollEvent& scroll_event) |
244 : MouseEvent(scroll_event), | 253 : MouseEvent(scroll_event), |
245 offset_(scroll_event.y_offset()) { | 254 offset_(scroll_event.y_offset()) { |
246 set_type(ET_MOUSEWHEEL); | 255 set_type(ET_MOUSEWHEEL); |
247 } | 256 } |
248 | 257 |
249 #if defined(OS_WIN) | 258 #if defined(OS_WIN) |
250 // This value matches windows WHEEL_DELTA. | 259 // This value matches windows WHEEL_DELTA. |
251 // static | 260 // static |
252 const int MouseWheelEvent::kWheelDelta = 120; | 261 const int MouseWheelEvent::kWheelDelta = 120; |
253 #else | 262 #else |
254 // This value matches GTK+ wheel scroll amount. | 263 // This value matches GTK+ wheel scroll amount. |
255 const int MouseWheelEvent::kWheelDelta = 53; | 264 const int MouseWheelEvent::kWheelDelta = 53; |
256 #endif | 265 #endif |
257 | 266 |
| 267 //////////////////////////////////////////////////////////////////////////////// |
| 268 // TouchEvent |
| 269 |
258 TouchEvent::TouchEvent(const base::NativeEvent& native_event) | 270 TouchEvent::TouchEvent(const base::NativeEvent& native_event) |
259 : LocatedEvent(native_event), | 271 : LocatedEvent(native_event), |
260 touch_id_(GetTouchId(native_event)), | 272 touch_id_(GetTouchId(native_event)), |
261 radius_x_(GetTouchRadiusX(native_event)), | 273 radius_x_(GetTouchRadiusX(native_event)), |
262 radius_y_(GetTouchRadiusY(native_event)), | 274 radius_y_(GetTouchRadiusY(native_event)), |
263 rotation_angle_(GetTouchAngle(native_event)), | 275 rotation_angle_(GetTouchAngle(native_event)), |
264 force_(GetTouchForce(native_event)) { | 276 force_(GetTouchForce(native_event)) { |
265 } | 277 } |
266 | 278 |
267 TouchEvent::TouchEvent(EventType type, | 279 TouchEvent::TouchEvent(EventType type, |
(...skipping 15 matching lines...) Expand all Loading... |
283 void TouchEvent::UpdateForRootTransform(const Transform& root_transform) { | 295 void TouchEvent::UpdateForRootTransform(const Transform& root_transform) { |
284 LocatedEvent::UpdateForRootTransform(root_transform); | 296 LocatedEvent::UpdateForRootTransform(root_transform); |
285 gfx::Point3f scale; | 297 gfx::Point3f scale; |
286 InterpolatedTransform::FactorTRS(root_transform, NULL, NULL, &scale); | 298 InterpolatedTransform::FactorTRS(root_transform, NULL, NULL, &scale); |
287 if (scale.x()) | 299 if (scale.x()) |
288 radius_x_ /= scale.x(); | 300 radius_x_ /= scale.x(); |
289 if (scale.y()) | 301 if (scale.y()) |
290 radius_y_ /= scale.y(); | 302 radius_y_ /= scale.y(); |
291 } | 303 } |
292 | 304 |
| 305 //////////////////////////////////////////////////////////////////////////////// |
| 306 // TestTouchEvent |
| 307 |
293 TestTouchEvent::TestTouchEvent(EventType type, | 308 TestTouchEvent::TestTouchEvent(EventType type, |
294 int x, | 309 int x, |
295 int y, | 310 int y, |
296 int flags, | 311 int flags, |
297 int touch_id, | 312 int touch_id, |
298 float radius_x, | 313 float radius_x, |
299 float radius_y, | 314 float radius_y, |
300 float angle, | 315 float angle, |
301 float force) | 316 float force) |
302 : TouchEvent(type, gfx::Point(x, y), touch_id, base::TimeDelta()) { | 317 : TouchEvent(type, gfx::Point(x, y), touch_id, base::TimeDelta()) { |
303 set_flags(flags); | 318 set_flags(flags); |
304 set_radius(radius_x, radius_y); | 319 set_radius(radius_x, radius_y); |
305 set_rotation_angle(angle); | 320 set_rotation_angle(angle); |
306 set_force(force); | 321 set_force(force); |
307 } | 322 } |
308 | 323 |
| 324 //////////////////////////////////////////////////////////////////////////////// |
| 325 // KeyEvent |
| 326 |
309 KeyEvent::KeyEvent(const base::NativeEvent& native_event, bool is_char) | 327 KeyEvent::KeyEvent(const base::NativeEvent& native_event, bool is_char) |
310 : Event(native_event, | 328 : Event(native_event, |
311 EventTypeFromNative(native_event), | 329 EventTypeFromNative(native_event), |
312 EventFlagsFromNative(native_event)), | 330 EventFlagsFromNative(native_event)), |
313 key_code_(KeyboardCodeFromNative(native_event)), | 331 key_code_(KeyboardCodeFromNative(native_event)), |
314 is_char_(is_char), | 332 is_char_(is_char), |
315 character_(0), | 333 character_(0), |
316 unmodified_character_(0) { | 334 unmodified_character_(0) { |
317 } | 335 } |
318 | 336 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
381 } | 399 } |
382 | 400 |
383 KeyEvent* KeyEvent::Copy() { | 401 KeyEvent* KeyEvent::Copy() { |
384 KeyEvent* copy = new KeyEvent(::CopyNativeEvent(native_event()), is_char()); | 402 KeyEvent* copy = new KeyEvent(::CopyNativeEvent(native_event()), is_char()); |
385 #if defined(USE_X11) | 403 #if defined(USE_X11) |
386 copy->set_delete_native_event(true); | 404 copy->set_delete_native_event(true); |
387 #endif | 405 #endif |
388 return copy; | 406 return copy; |
389 } | 407 } |
390 | 408 |
| 409 //////////////////////////////////////////////////////////////////////////////// |
| 410 // TranslatedKeyEvent |
| 411 |
391 TranslatedKeyEvent::TranslatedKeyEvent(const base::NativeEvent& native_event, | 412 TranslatedKeyEvent::TranslatedKeyEvent(const base::NativeEvent& native_event, |
392 bool is_char) | 413 bool is_char) |
393 : KeyEvent(native_event, is_char) { | 414 : KeyEvent(native_event, is_char) { |
394 set_type(type() == ET_KEY_PRESSED ? | 415 set_type(type() == ET_KEY_PRESSED ? |
395 ET_TRANSLATED_KEY_PRESS : ET_TRANSLATED_KEY_RELEASE); | 416 ET_TRANSLATED_KEY_PRESS : ET_TRANSLATED_KEY_RELEASE); |
396 } | 417 } |
397 | 418 |
398 TranslatedKeyEvent::TranslatedKeyEvent(bool is_press, | 419 TranslatedKeyEvent::TranslatedKeyEvent(bool is_press, |
399 KeyboardCode key_code, | 420 KeyboardCode key_code, |
400 int flags) | 421 int flags) |
401 : KeyEvent((is_press ? ET_TRANSLATED_KEY_PRESS : ET_TRANSLATED_KEY_RELEASE), | 422 : KeyEvent((is_press ? ET_TRANSLATED_KEY_PRESS : ET_TRANSLATED_KEY_RELEASE), |
402 key_code, | 423 key_code, |
403 flags) { | 424 flags) { |
404 } | 425 } |
405 | 426 |
406 void TranslatedKeyEvent::ConvertToKeyEvent() { | 427 void TranslatedKeyEvent::ConvertToKeyEvent() { |
407 set_type(type() == ET_TRANSLATED_KEY_PRESS ? | 428 set_type(type() == ET_TRANSLATED_KEY_PRESS ? |
408 ET_KEY_PRESSED : ET_KEY_RELEASED); | 429 ET_KEY_PRESSED : ET_KEY_RELEASED); |
409 } | 430 } |
410 | 431 |
| 432 //////////////////////////////////////////////////////////////////////////////// |
| 433 // ScrollEvent |
| 434 |
411 ScrollEvent::ScrollEvent(const base::NativeEvent& native_event) | 435 ScrollEvent::ScrollEvent(const base::NativeEvent& native_event) |
412 : MouseEvent(native_event) { | 436 : MouseEvent(native_event) { |
413 if (type() == ET_SCROLL) { | 437 if (type() == ET_SCROLL) { |
414 GetScrollOffsets(native_event, &x_offset_, &y_offset_); | 438 GetScrollOffsets(native_event, &x_offset_, &y_offset_); |
415 double start, end; | 439 double start, end; |
416 GetGestureTimes(native_event, &start, &end); | 440 GetGestureTimes(native_event, &start, &end); |
417 } else if (type() == ET_SCROLL_FLING_START) { | 441 } else if (type() == ET_SCROLL_FLING_START) { |
418 bool is_cancel; | 442 bool is_cancel; |
419 GetFlingData(native_event, &x_offset_, &y_offset_, &is_cancel); | 443 GetFlingData(native_event, &x_offset_, &y_offset_, &is_cancel); |
420 } | 444 } |
421 } | 445 } |
422 | 446 |
| 447 //////////////////////////////////////////////////////////////////////////////// |
| 448 // GestureEvent |
| 449 |
423 GestureEvent::GestureEvent(EventType type, | 450 GestureEvent::GestureEvent(EventType type, |
424 int x, | 451 int x, |
425 int y, | 452 int y, |
426 int flags, | 453 int flags, |
427 base::TimeDelta time_stamp, | 454 base::TimeDelta time_stamp, |
428 const GestureEventDetails& details, | 455 const GestureEventDetails& details, |
429 unsigned int touch_ids_bitfield) | 456 unsigned int touch_ids_bitfield) |
430 : LocatedEvent(type, gfx::Point(x, y), gfx::Point(x, y), flags), | 457 : LocatedEvent(type, gfx::Point(x, y), gfx::Point(x, y), flags), |
431 details_(details), | 458 details_(details), |
432 touch_ids_bitfield_(touch_ids_bitfield) { | 459 touch_ids_bitfield_(touch_ids_bitfield) { |
433 set_time_stamp(time_stamp); | 460 set_time_stamp(time_stamp); |
434 } | 461 } |
435 | 462 |
436 GestureEvent::~GestureEvent() { | 463 GestureEvent::~GestureEvent() { |
437 } | 464 } |
438 | 465 |
439 int GestureEvent::GetLowestTouchId() const { | 466 int GestureEvent::GetLowestTouchId() const { |
440 if (touch_ids_bitfield_ == 0) | 467 if (touch_ids_bitfield_ == 0) |
441 return -1; | 468 return -1; |
442 int i = -1; | 469 int i = -1; |
443 // Find the index of the least significant 1 bit | 470 // Find the index of the least significant 1 bit |
444 while (!(1 << ++i & touch_ids_bitfield_)); | 471 while (!(1 << ++i & touch_ids_bitfield_)); |
445 return i; | 472 return i; |
446 } | 473 } |
447 | 474 |
448 } // namespace ui | 475 } // namespace ui |
OLD | NEW |