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 #endif | 10 #endif |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 | 140 |
141 Event::Event(EventType type, base::TimeDelta time_stamp, int flags) | 141 Event::Event(EventType type, base::TimeDelta time_stamp, int flags) |
142 : type_(type), | 142 : type_(type), |
143 time_stamp_(time_stamp), | 143 time_stamp_(time_stamp), |
144 flags_(flags), | 144 flags_(flags), |
145 native_event_(base::NativeEvent()), | 145 native_event_(base::NativeEvent()), |
146 delete_native_event_(false), | 146 delete_native_event_(false), |
147 cancelable_(true), | 147 cancelable_(true), |
148 target_(NULL), | 148 target_(NULL), |
149 phase_(EP_PREDISPATCH), | 149 phase_(EP_PREDISPATCH), |
150 result_(ER_UNHANDLED) { | 150 result_(ER_UNHANDLED), |
| 151 source_device_id_(ED_UNKNOWN_DEVICE) { |
151 if (type_ < ET_LAST) | 152 if (type_ < ET_LAST) |
152 name_ = EventTypeName(type_); | 153 name_ = EventTypeName(type_); |
153 } | 154 } |
154 | 155 |
155 Event::Event(const base::NativeEvent& native_event, | 156 Event::Event(const base::NativeEvent& native_event, |
156 EventType type, | 157 EventType type, |
157 int flags) | 158 int flags) |
158 : type_(type), | 159 : type_(type), |
159 time_stamp_(EventTimeFromNative(native_event)), | 160 time_stamp_(EventTimeFromNative(native_event)), |
160 flags_(flags), | 161 flags_(flags), |
161 native_event_(native_event), | 162 native_event_(native_event), |
162 delete_native_event_(false), | 163 delete_native_event_(false), |
163 cancelable_(true), | 164 cancelable_(true), |
164 target_(NULL), | 165 target_(NULL), |
165 phase_(EP_PREDISPATCH), | 166 phase_(EP_PREDISPATCH), |
166 result_(ER_UNHANDLED) { | 167 result_(ER_UNHANDLED), |
| 168 source_device_id_(ED_UNKNOWN_DEVICE) { |
167 base::TimeDelta delta = EventTimeForNow() - time_stamp_; | 169 base::TimeDelta delta = EventTimeForNow() - time_stamp_; |
168 if (type_ < ET_LAST) | 170 if (type_ < ET_LAST) |
169 name_ = EventTypeName(type_); | 171 name_ = EventTypeName(type_); |
170 UMA_HISTOGRAM_CUSTOM_COUNTS("Event.Latency.Browser", | 172 UMA_HISTOGRAM_CUSTOM_COUNTS("Event.Latency.Browser", |
171 delta.InMicroseconds(), 1, 1000000, 100); | 173 delta.InMicroseconds(), 1, 1000000, 100); |
172 std::string name_for_event = | 174 std::string name_for_event = |
173 base::StringPrintf("Event.Latency.Browser.%s", name_.c_str()); | 175 base::StringPrintf("Event.Latency.Browser.%s", name_.c_str()); |
174 base::HistogramBase* counter_for_type = | 176 base::HistogramBase* counter_for_type = |
175 base::Histogram::FactoryGet( | 177 base::Histogram::FactoryGet( |
176 name_for_event, | 178 name_for_event, |
177 1, | 179 1, |
178 1000000, | 180 1000000, |
179 100, | 181 100, |
180 base::HistogramBase::kUmaTargetedHistogramFlag); | 182 base::HistogramBase::kUmaTargetedHistogramFlag); |
181 counter_for_type->Add(delta.InMicroseconds()); | 183 counter_for_type->Add(delta.InMicroseconds()); |
| 184 |
| 185 #if defined(USE_X11) |
| 186 if (native_event->type == GenericEvent) { |
| 187 XIDeviceEvent* xiev = |
| 188 static_cast<XIDeviceEvent*>(native_event->xcookie.data); |
| 189 source_device_id_ = xiev->deviceid; |
| 190 } |
| 191 #endif |
182 } | 192 } |
183 | 193 |
184 Event::Event(const Event& copy) | 194 Event::Event(const Event& copy) |
185 : type_(copy.type_), | 195 : type_(copy.type_), |
186 time_stamp_(copy.time_stamp_), | 196 time_stamp_(copy.time_stamp_), |
187 latency_(copy.latency_), | 197 latency_(copy.latency_), |
188 flags_(copy.flags_), | 198 flags_(copy.flags_), |
189 native_event_(CopyNativeEvent(copy.native_event_)), | 199 native_event_(CopyNativeEvent(copy.native_event_)), |
190 delete_native_event_(true), | 200 delete_native_event_(true), |
191 cancelable_(true), | 201 cancelable_(true), |
192 target_(NULL), | 202 target_(NULL), |
193 phase_(EP_PREDISPATCH), | 203 phase_(EP_PREDISPATCH), |
194 result_(ER_UNHANDLED) { | 204 result_(ER_UNHANDLED), |
| 205 source_device_id_(copy.source_device_id_) { |
195 if (type_ < ET_LAST) | 206 if (type_ < ET_LAST) |
196 name_ = EventTypeName(type_); | 207 name_ = EventTypeName(type_); |
197 } | 208 } |
198 | 209 |
199 void Event::SetType(EventType type) { | 210 void Event::SetType(EventType type) { |
200 if (type_ < ET_LAST) | 211 if (type_ < ET_LAST) |
201 name_ = std::string(); | 212 name_ = std::string(); |
202 type_ = type; | 213 type_ = type; |
203 if (type_ < ET_LAST) | 214 if (type_ < ET_LAST) |
204 name_ = EventTypeName(type_); | 215 name_ = EventTypeName(type_); |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
421 | 432 |
422 //////////////////////////////////////////////////////////////////////////////// | 433 //////////////////////////////////////////////////////////////////////////////// |
423 // TouchEvent | 434 // TouchEvent |
424 | 435 |
425 TouchEvent::TouchEvent(const base::NativeEvent& native_event) | 436 TouchEvent::TouchEvent(const base::NativeEvent& native_event) |
426 : LocatedEvent(native_event), | 437 : LocatedEvent(native_event), |
427 touch_id_(GetTouchId(native_event)), | 438 touch_id_(GetTouchId(native_event)), |
428 radius_x_(GetTouchRadiusX(native_event)), | 439 radius_x_(GetTouchRadiusX(native_event)), |
429 radius_y_(GetTouchRadiusY(native_event)), | 440 radius_y_(GetTouchRadiusY(native_event)), |
430 rotation_angle_(GetTouchAngle(native_event)), | 441 rotation_angle_(GetTouchAngle(native_event)), |
431 force_(GetTouchForce(native_event)), | 442 force_(GetTouchForce(native_event)) { |
432 source_device_id_(-1) { | |
433 latency()->AddLatencyNumberWithTimestamp( | 443 latency()->AddLatencyNumberWithTimestamp( |
434 INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, | 444 INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, |
435 0, | 445 0, |
436 0, | 446 0, |
437 base::TimeTicks::FromInternalValue(time_stamp().ToInternalValue()), | 447 base::TimeTicks::FromInternalValue(time_stamp().ToInternalValue()), |
438 1); | 448 1); |
439 | 449 |
440 #if defined(USE_X11) | |
441 XIDeviceEvent* xiev = static_cast<XIDeviceEvent*>(native_event->xcookie.data); | |
442 source_device_id_ = xiev->deviceid; | |
443 #endif | |
444 | |
445 latency()->AddLatencyNumber(INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0); | 450 latency()->AddLatencyNumber(INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0); |
446 } | 451 } |
447 | 452 |
448 TouchEvent::TouchEvent(EventType type, | 453 TouchEvent::TouchEvent(EventType type, |
449 const gfx::PointF& location, | 454 const gfx::PointF& location, |
450 int touch_id, | 455 int touch_id, |
451 base::TimeDelta time_stamp) | 456 base::TimeDelta time_stamp) |
452 : LocatedEvent(type, location, location, time_stamp, 0), | 457 : LocatedEvent(type, location, location, time_stamp, 0), |
453 touch_id_(touch_id), | 458 touch_id_(touch_id), |
454 radius_x_(0.0f), | 459 radius_x_(0.0f), |
455 radius_y_(0.0f), | 460 radius_y_(0.0f), |
456 rotation_angle_(0.0f), | 461 rotation_angle_(0.0f), |
457 force_(0.0f), | 462 force_(0.0f) { |
458 source_device_id_(-1) { | |
459 latency()->AddLatencyNumber(INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0); | 463 latency()->AddLatencyNumber(INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0); |
460 } | 464 } |
461 | 465 |
462 TouchEvent::TouchEvent(EventType type, | 466 TouchEvent::TouchEvent(EventType type, |
463 const gfx::PointF& location, | 467 const gfx::PointF& location, |
464 int flags, | 468 int flags, |
465 int touch_id, | 469 int touch_id, |
466 base::TimeDelta time_stamp, | 470 base::TimeDelta time_stamp, |
467 float radius_x, | 471 float radius_x, |
468 float radius_y, | 472 float radius_y, |
469 float angle, | 473 float angle, |
470 float force) | 474 float force) |
471 : LocatedEvent(type, location, location, time_stamp, flags), | 475 : LocatedEvent(type, location, location, time_stamp, flags), |
472 touch_id_(touch_id), | 476 touch_id_(touch_id), |
473 radius_x_(radius_x), | 477 radius_x_(radius_x), |
474 radius_y_(radius_y), | 478 radius_y_(radius_y), |
475 rotation_angle_(angle), | 479 rotation_angle_(angle), |
476 force_(force), | 480 force_(force) { |
477 source_device_id_(-1) { | |
478 latency()->AddLatencyNumber(INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0); | 481 latency()->AddLatencyNumber(INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0); |
479 } | 482 } |
480 | 483 |
481 TouchEvent::~TouchEvent() { | 484 TouchEvent::~TouchEvent() { |
482 // In ctor TouchEvent(native_event) we call GetTouchId() which in X11 | 485 // In ctor TouchEvent(native_event) we call GetTouchId() which in X11 |
483 // platform setups the tracking_id to slot mapping. So in dtor here, | 486 // platform setups the tracking_id to slot mapping. So in dtor here, |
484 // if this touch event is a release event, we clear the mapping accordingly. | 487 // if this touch event is a release event, we clear the mapping accordingly. |
485 if (HasNativeEvent()) | 488 if (HasNativeEvent()) |
486 ClearTouchIdIfReleased(native_event()); | 489 ClearTouchIdIfReleased(native_event()); |
487 } | 490 } |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
583 return character_; | 586 return character_; |
584 | 587 |
585 #if defined(OS_WIN) | 588 #if defined(OS_WIN) |
586 return (native_event().message == WM_CHAR) ? key_code_ : | 589 return (native_event().message == WM_CHAR) ? key_code_ : |
587 GetCharacterFromKeyCode(key_code_, flags()); | 590 GetCharacterFromKeyCode(key_code_, flags()); |
588 #elif defined(USE_X11) | 591 #elif defined(USE_X11) |
589 if (!native_event()) | 592 if (!native_event()) |
590 return GetCharacterFromKeyCode(key_code_, flags()); | 593 return GetCharacterFromKeyCode(key_code_, flags()); |
591 | 594 |
592 DCHECK(native_event()->type == KeyPress || | 595 DCHECK(native_event()->type == KeyPress || |
593 native_event()->type == KeyRelease); | 596 native_event()->type == KeyRelease || |
| 597 (native_event()->type == GenericEvent && |
| 598 (native_event()->xgeneric.evtype == XI_KeyPress || |
| 599 native_event()->xgeneric.evtype == XI_KeyRelease))); |
594 | 600 |
595 // When a control key is held, prefer ASCII characters to non ASCII | 601 // When a control key is held, prefer ASCII characters to non ASCII |
596 // characters in order to use it for shortcut keys. GetCharacterFromKeyCode | 602 // characters in order to use it for shortcut keys. GetCharacterFromKeyCode |
597 // returns 'a' for VKEY_A even if the key is actually bound to 'à' in X11. | 603 // returns 'a' for VKEY_A even if the key is actually bound to 'à' in X11. |
598 // GetCharacterFromXEvent returns 'à' in that case. | 604 // GetCharacterFromXEvent returns 'à' in that case. |
599 return IsControlDown() ? | 605 return IsControlDown() ? |
600 GetCharacterFromKeyCode(key_code_, flags()) : | 606 GetCharacterFromKeyCode(key_code_, flags()) : |
601 GetCharacterFromXEvent(native_event()); | 607 GetCharacterFromXEvent(native_event()); |
602 #else | 608 #else |
603 if (native_event()) { | 609 if (native_event()) { |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
755 int GestureEvent::GetLowestTouchId() const { | 761 int GestureEvent::GetLowestTouchId() const { |
756 if (touch_ids_bitfield_ == 0) | 762 if (touch_ids_bitfield_ == 0) |
757 return -1; | 763 return -1; |
758 int i = -1; | 764 int i = -1; |
759 // Find the index of the least significant 1 bit | 765 // Find the index of the least significant 1 bit |
760 while (!(1 << ++i & touch_ids_bitfield_)); | 766 while (!(1 << ++i & touch_ids_bitfield_)); |
761 return i; | 767 return i; |
762 } | 768 } |
763 | 769 |
764 } // namespace ui | 770 } // namespace ui |
OLD | NEW |