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/events/event.h" | 5 #include "ui/events/event.h" |
6 | 6 |
7 #if defined(USE_X11) | 7 #if defined(USE_X11) |
8 #include <X11/extensions/XInput2.h> | 8 #include <X11/extensions/XInput2.h> |
9 #include <X11/Xlib.h> | 9 #include <X11/Xlib.h> |
10 #include <X11/keysym.h> | 10 #include <X11/keysym.h> |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 const unsigned int kAllStateMask = | 101 const unsigned int kAllStateMask = |
102 Button1Mask | Button2Mask | Button3Mask | Button4Mask | Button5Mask | | 102 Button1Mask | Button2Mask | Button3Mask | Button4Mask | Button5Mask | |
103 Mod1Mask | Mod2Mask | Mod3Mask | Mod4Mask | Mod5Mask | ShiftMask | | 103 Mod1Mask | Mod2Mask | Mod3Mask | Mod4Mask | Mod5Mask | ShiftMask | |
104 LockMask | ControlMask | AnyModifier; | 104 LockMask | ControlMask | AnyModifier; |
105 return event && (event->xkey.state & ~kAllStateMask) != 0; | 105 return event && (event->xkey.state & ~kAllStateMask) != 0; |
106 #else | 106 #else |
107 return false; | 107 return false; |
108 #endif | 108 #endif |
109 } | 109 } |
110 | 110 |
| 111 unsigned long long get_next_touch_event_id() { |
| 112 static unsigned long long id = 0; |
| 113 return id++; |
| 114 } |
| 115 |
111 } // namespace | 116 } // namespace |
112 | 117 |
113 namespace ui { | 118 namespace ui { |
114 | 119 |
115 //////////////////////////////////////////////////////////////////////////////// | 120 //////////////////////////////////////////////////////////////////////////////// |
116 // Event | 121 // Event |
117 | 122 |
118 // static | 123 // static |
119 scoped_ptr<Event> Event::Clone(const Event& event) { | 124 scoped_ptr<Event> Event::Clone(const Event& event) { |
120 if (event.IsKeyEvent()) { | 125 if (event.IsKeyEvent()) { |
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
507 gfx::ToRoundedInt(SkMScalarToFloat(offset_.y() * decomp.scale[1]))); | 512 gfx::ToRoundedInt(SkMScalarToFloat(offset_.y() * decomp.scale[1]))); |
508 } | 513 } |
509 } | 514 } |
510 | 515 |
511 //////////////////////////////////////////////////////////////////////////////// | 516 //////////////////////////////////////////////////////////////////////////////// |
512 // TouchEvent | 517 // TouchEvent |
513 | 518 |
514 TouchEvent::TouchEvent(const base::NativeEvent& native_event) | 519 TouchEvent::TouchEvent(const base::NativeEvent& native_event) |
515 : LocatedEvent(native_event), | 520 : LocatedEvent(native_event), |
516 touch_id_(GetTouchId(native_event)), | 521 touch_id_(GetTouchId(native_event)), |
| 522 unique_event_id_(get_next_touch_event_id()), |
517 radius_x_(GetTouchRadiusX(native_event)), | 523 radius_x_(GetTouchRadiusX(native_event)), |
518 radius_y_(GetTouchRadiusY(native_event)), | 524 radius_y_(GetTouchRadiusY(native_event)), |
519 rotation_angle_(GetTouchAngle(native_event)), | 525 rotation_angle_(GetTouchAngle(native_event)), |
520 force_(GetTouchForce(native_event)) { | 526 force_(GetTouchForce(native_event)) { |
521 latency()->AddLatencyNumberWithTimestamp( | 527 latency()->AddLatencyNumberWithTimestamp( |
522 INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, | 528 INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, |
523 0, | 529 0, |
524 0, | 530 0, |
525 base::TimeTicks::FromInternalValue(time_stamp().ToInternalValue()), | 531 base::TimeTicks::FromInternalValue(time_stamp().ToInternalValue()), |
526 1); | 532 1); |
527 | 533 |
528 latency()->AddLatencyNumber(INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0); | 534 latency()->AddLatencyNumber(INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0); |
529 | 535 |
530 if (type() == ET_TOUCH_PRESSED) | 536 if (type() == ET_TOUCH_PRESSED) |
531 IncrementTouchIdRefCount(native_event); | 537 IncrementTouchIdRefCount(native_event); |
532 } | 538 } |
533 | 539 |
534 TouchEvent::TouchEvent(EventType type, | 540 TouchEvent::TouchEvent(EventType type, |
535 const gfx::PointF& location, | 541 const gfx::PointF& location, |
536 int touch_id, | 542 int touch_id, |
537 base::TimeDelta time_stamp) | 543 base::TimeDelta time_stamp) |
538 : LocatedEvent(type, location, location, time_stamp, 0), | 544 : LocatedEvent(type, location, location, time_stamp, 0), |
539 touch_id_(touch_id), | 545 touch_id_(touch_id), |
| 546 unique_event_id_(get_next_touch_event_id()), |
540 radius_x_(0.0f), | 547 radius_x_(0.0f), |
541 radius_y_(0.0f), | 548 radius_y_(0.0f), |
542 rotation_angle_(0.0f), | 549 rotation_angle_(0.0f), |
543 force_(0.0f) { | 550 force_(0.0f) { |
544 latency()->AddLatencyNumber(INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0); | 551 latency()->AddLatencyNumber(INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0); |
545 } | 552 } |
546 | 553 |
547 TouchEvent::TouchEvent(EventType type, | 554 TouchEvent::TouchEvent(EventType type, |
548 const gfx::PointF& location, | 555 const gfx::PointF& location, |
549 int flags, | 556 int flags, |
550 int touch_id, | 557 int touch_id, |
551 base::TimeDelta time_stamp, | 558 base::TimeDelta time_stamp, |
552 float radius_x, | 559 float radius_x, |
553 float radius_y, | 560 float radius_y, |
554 float angle, | 561 float angle, |
555 float force) | 562 float force) |
556 : LocatedEvent(type, location, location, time_stamp, flags), | 563 : LocatedEvent(type, location, location, time_stamp, flags), |
557 touch_id_(touch_id), | 564 touch_id_(touch_id), |
| 565 unique_event_id_(get_next_touch_event_id()), |
558 radius_x_(radius_x), | 566 radius_x_(radius_x), |
559 radius_y_(radius_y), | 567 radius_y_(radius_y), |
560 rotation_angle_(angle), | 568 rotation_angle_(angle), |
561 force_(force) { | 569 force_(force) { |
562 latency()->AddLatencyNumber(INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0); | 570 latency()->AddLatencyNumber(INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0); |
563 } | 571 } |
564 | 572 |
565 TouchEvent::~TouchEvent() { | 573 TouchEvent::~TouchEvent() { |
566 // In ctor TouchEvent(native_event) we call GetTouchId() which in X11 | 574 // In ctor TouchEvent(native_event) we call GetTouchId() which in X11 |
567 // platform setups the tracking_id to slot mapping. So in dtor here, | 575 // platform setups the tracking_id to slot mapping. So in dtor here, |
568 // if this touch event is a release event, we clear the mapping accordingly. | 576 // if this touch event is a release event, we clear the mapping accordingly. |
569 if (HasNativeEvent()) | 577 if (HasNativeEvent()) |
570 ClearTouchIdIfReleased(native_event()); | 578 ClearTouchIdIfReleased(native_event()); |
571 } | 579 } |
572 | 580 |
573 void TouchEvent::UpdateForRootTransform( | 581 void TouchEvent::UpdateForRootTransform( |
574 const gfx::Transform& inverted_root_transform) { | 582 const gfx::Transform& inverted_root_transform) { |
575 LocatedEvent::UpdateForRootTransform(inverted_root_transform); | 583 LocatedEvent::UpdateForRootTransform(inverted_root_transform); |
576 gfx::DecomposedTransform decomp; | 584 gfx::DecomposedTransform decomp; |
577 bool success = gfx::DecomposeTransform(&decomp, inverted_root_transform); | 585 bool success = gfx::DecomposeTransform(&decomp, inverted_root_transform); |
578 DCHECK(success); | 586 DCHECK(success); |
579 if (decomp.scale[0]) | 587 if (decomp.scale[0]) |
580 radius_x_ *= decomp.scale[0]; | 588 radius_x_ *= decomp.scale[0]; |
581 if (decomp.scale[1]) | 589 if (decomp.scale[1]) |
582 radius_y_ *= decomp.scale[1]; | 590 radius_y_ *= decomp.scale[1]; |
583 } | 591 } |
584 | 592 |
| 593 void TouchEvent::DisableSynchronousHandling() { |
| 594 DispatcherApi dispatcher_api(this); |
| 595 dispatcher_api.set_result( |
| 596 static_cast<EventResult>(result() | ER_DISABLE_SYNC_HANDLING)); |
| 597 } |
| 598 |
585 //////////////////////////////////////////////////////////////////////////////// | 599 //////////////////////////////////////////////////////////////////////////////// |
586 // KeyEvent | 600 // KeyEvent |
587 | 601 |
588 // static | 602 // static |
589 KeyEvent* KeyEvent::last_key_event_ = NULL; | 603 KeyEvent* KeyEvent::last_key_event_ = NULL; |
590 | 604 |
591 // static | 605 // static |
592 bool KeyEvent::IsRepeated(const KeyEvent& event) { | 606 bool KeyEvent::IsRepeated(const KeyEvent& event) { |
593 // A safe guard in case if there were continous key pressed events that are | 607 // A safe guard in case if there were continous key pressed events that are |
594 // not auto repeat. | 608 // not auto repeat. |
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
979 gfx::PointF(x, y), | 993 gfx::PointF(x, y), |
980 time_stamp, | 994 time_stamp, |
981 flags | EF_FROM_TOUCH), | 995 flags | EF_FROM_TOUCH), |
982 details_(details) { | 996 details_(details) { |
983 } | 997 } |
984 | 998 |
985 GestureEvent::~GestureEvent() { | 999 GestureEvent::~GestureEvent() { |
986 } | 1000 } |
987 | 1001 |
988 } // namespace ui | 1002 } // namespace ui |
OLD | NEW |