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 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
128 | 128 |
129 Event::Event(EventType type, base::TimeDelta time_stamp, int flags) | 129 Event::Event(EventType type, base::TimeDelta time_stamp, int flags) |
130 : type_(type), | 130 : type_(type), |
131 time_stamp_(time_stamp), | 131 time_stamp_(time_stamp), |
132 flags_(flags), | 132 flags_(flags), |
133 native_event_(base::NativeEvent()), | 133 native_event_(base::NativeEvent()), |
134 delete_native_event_(false), | 134 delete_native_event_(false), |
135 cancelable_(true), | 135 cancelable_(true), |
136 target_(NULL), | 136 target_(NULL), |
137 phase_(EP_PREDISPATCH), | 137 phase_(EP_PREDISPATCH), |
138 result_(ER_UNHANDLED) { | 138 result_(ER_UNHANDLED), |
139 source_device_id_(ED_UNKNOWN_DEVICE) { | |
139 if (type_ < ET_LAST) | 140 if (type_ < ET_LAST) |
140 name_ = EventTypeName(type_); | 141 name_ = EventTypeName(type_); |
141 } | 142 } |
142 | 143 |
143 Event::Event(const base::NativeEvent& native_event, | 144 Event::Event(const base::NativeEvent& native_event, |
144 EventType type, | 145 EventType type, |
145 int flags) | 146 int flags) |
146 : type_(type), | 147 : type_(type), |
147 time_stamp_(EventTimeFromNative(native_event)), | 148 time_stamp_(EventTimeFromNative(native_event)), |
148 flags_(flags), | 149 flags_(flags), |
149 native_event_(native_event), | 150 native_event_(native_event), |
150 delete_native_event_(false), | 151 delete_native_event_(false), |
151 cancelable_(true), | 152 cancelable_(true), |
152 target_(NULL), | 153 target_(NULL), |
153 phase_(EP_PREDISPATCH), | 154 phase_(EP_PREDISPATCH), |
154 result_(ER_UNHANDLED) { | 155 result_(ER_UNHANDLED), |
156 source_device_id_(ED_UNKNOWN_DEVICE) { | |
155 base::TimeDelta delta = EventTimeForNow() - time_stamp_; | 157 base::TimeDelta delta = EventTimeForNow() - time_stamp_; |
156 if (type_ < ET_LAST) | 158 if (type_ < ET_LAST) |
157 name_ = EventTypeName(type_); | 159 name_ = EventTypeName(type_); |
158 UMA_HISTOGRAM_CUSTOM_COUNTS("Event.Latency.Browser", | 160 UMA_HISTOGRAM_CUSTOM_COUNTS("Event.Latency.Browser", |
159 delta.InMicroseconds(), 1, 1000000, 100); | 161 delta.InMicroseconds(), 1, 1000000, 100); |
160 std::string name_for_event = | 162 std::string name_for_event = |
161 base::StringPrintf("Event.Latency.Browser.%s", name_.c_str()); | 163 base::StringPrintf("Event.Latency.Browser.%s", name_.c_str()); |
162 base::HistogramBase* counter_for_type = | 164 base::HistogramBase* counter_for_type = |
163 base::Histogram::FactoryGet( | 165 base::Histogram::FactoryGet( |
164 name_for_event, | 166 name_for_event, |
165 1, | 167 1, |
166 1000000, | 168 1000000, |
167 100, | 169 100, |
168 base::HistogramBase::kUmaTargetedHistogramFlag); | 170 base::HistogramBase::kUmaTargetedHistogramFlag); |
169 counter_for_type->Add(delta.InMicroseconds()); | 171 counter_for_type->Add(delta.InMicroseconds()); |
172 | |
173 #if defined(USE_X11) | |
174 if (native_event->type == GenericEvent) { | |
175 XIDeviceEvent* xiev = | |
176 static_cast<XIDeviceEvent*>(native_event->xcookie.data); | |
177 source_device_id_ = xiev->deviceid; | |
178 } | |
179 #endif | |
170 } | 180 } |
171 | 181 |
172 Event::Event(const Event& copy) | 182 Event::Event(const Event& copy) |
173 : type_(copy.type_), | 183 : type_(copy.type_), |
174 time_stamp_(copy.time_stamp_), | 184 time_stamp_(copy.time_stamp_), |
175 latency_(copy.latency_), | 185 latency_(copy.latency_), |
176 flags_(copy.flags_), | 186 flags_(copy.flags_), |
177 native_event_(CopyNativeEvent(copy.native_event_)), | 187 native_event_(CopyNativeEvent(copy.native_event_)), |
178 delete_native_event_(true), | 188 delete_native_event_(true), |
179 cancelable_(true), | 189 cancelable_(true), |
180 target_(NULL), | 190 target_(NULL), |
181 phase_(EP_PREDISPATCH), | 191 phase_(EP_PREDISPATCH), |
182 result_(ER_UNHANDLED) { | 192 result_(ER_UNHANDLED), |
193 source_device_id_(copy.source_device_id_) { | |
183 if (type_ < ET_LAST) | 194 if (type_ < ET_LAST) |
184 name_ = EventTypeName(type_); | 195 name_ = EventTypeName(type_); |
185 } | 196 } |
186 | 197 |
187 void Event::SetType(EventType type) { | 198 void Event::SetType(EventType type) { |
188 if (type_ < ET_LAST) | 199 if (type_ < ET_LAST) |
189 name_ = std::string(); | 200 name_ = std::string(); |
190 type_ = type; | 201 type_ = type; |
191 if (type_ < ET_LAST) | 202 if (type_ < ET_LAST) |
192 name_ = EventTypeName(type_); | 203 name_ = EventTypeName(type_); |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
399 | 410 |
400 //////////////////////////////////////////////////////////////////////////////// | 411 //////////////////////////////////////////////////////////////////////////////// |
401 // TouchEvent | 412 // TouchEvent |
402 | 413 |
403 TouchEvent::TouchEvent(const base::NativeEvent& native_event) | 414 TouchEvent::TouchEvent(const base::NativeEvent& native_event) |
404 : LocatedEvent(native_event), | 415 : LocatedEvent(native_event), |
405 touch_id_(GetTouchId(native_event)), | 416 touch_id_(GetTouchId(native_event)), |
406 radius_x_(GetTouchRadiusX(native_event)), | 417 radius_x_(GetTouchRadiusX(native_event)), |
407 radius_y_(GetTouchRadiusY(native_event)), | 418 radius_y_(GetTouchRadiusY(native_event)), |
408 rotation_angle_(GetTouchAngle(native_event)), | 419 rotation_angle_(GetTouchAngle(native_event)), |
409 force_(GetTouchForce(native_event)), | 420 force_(GetTouchForce(native_event)) { |
410 source_device_id_(-1) { | |
411 latency()->AddLatencyNumberWithTimestamp( | 421 latency()->AddLatencyNumberWithTimestamp( |
412 INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, | 422 INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, |
413 0, | 423 0, |
414 0, | 424 0, |
415 base::TimeTicks::FromInternalValue(time_stamp().ToInternalValue()), | 425 base::TimeTicks::FromInternalValue(time_stamp().ToInternalValue()), |
416 1); | 426 1); |
417 | 427 |
418 #if defined(USE_X11) | |
419 XIDeviceEvent* xiev = static_cast<XIDeviceEvent*>(native_event->xcookie.data); | |
420 source_device_id_ = xiev->deviceid; | |
421 #endif | |
422 | |
423 latency()->AddLatencyNumber(INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0); | 428 latency()->AddLatencyNumber(INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0); |
424 } | 429 } |
425 | 430 |
426 TouchEvent::TouchEvent(EventType type, | 431 TouchEvent::TouchEvent(EventType type, |
427 const gfx::PointF& location, | 432 const gfx::PointF& location, |
428 int touch_id, | 433 int touch_id, |
429 base::TimeDelta time_stamp) | 434 base::TimeDelta time_stamp) |
430 : LocatedEvent(type, location, location, time_stamp, 0), | 435 : LocatedEvent(type, location, location, time_stamp, 0), |
431 touch_id_(touch_id), | 436 touch_id_(touch_id), |
432 radius_x_(0.0f), | 437 radius_x_(0.0f), |
433 radius_y_(0.0f), | 438 radius_y_(0.0f), |
434 rotation_angle_(0.0f), | 439 rotation_angle_(0.0f), |
435 force_(0.0f), | 440 force_(0.0f) { |
436 source_device_id_(-1) { | |
437 latency()->AddLatencyNumber(INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0); | 441 latency()->AddLatencyNumber(INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0); |
438 } | 442 } |
439 | 443 |
440 TouchEvent::TouchEvent(EventType type, | 444 TouchEvent::TouchEvent(EventType type, |
441 const gfx::PointF& location, | 445 const gfx::PointF& location, |
442 int flags, | 446 int flags, |
443 int touch_id, | 447 int touch_id, |
444 base::TimeDelta time_stamp, | 448 base::TimeDelta time_stamp, |
445 float radius_x, | 449 float radius_x, |
446 float radius_y, | 450 float radius_y, |
447 float angle, | 451 float angle, |
448 float force) | 452 float force) |
449 : LocatedEvent(type, location, location, time_stamp, flags), | 453 : LocatedEvent(type, location, location, time_stamp, flags), |
450 touch_id_(touch_id), | 454 touch_id_(touch_id), |
451 radius_x_(radius_x), | 455 radius_x_(radius_x), |
452 radius_y_(radius_y), | 456 radius_y_(radius_y), |
453 rotation_angle_(angle), | 457 rotation_angle_(angle), |
454 force_(force), | 458 force_(force) { |
455 source_device_id_(-1) { | |
456 latency()->AddLatencyNumber(INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0); | 459 latency()->AddLatencyNumber(INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0); |
457 } | 460 } |
458 | 461 |
459 TouchEvent::~TouchEvent() { | 462 TouchEvent::~TouchEvent() { |
460 // In ctor TouchEvent(native_event) we call GetTouchId() which in X11 | 463 // In ctor TouchEvent(native_event) we call GetTouchId() which in X11 |
461 // platform setups the tracking_id to slot mapping. So in dtor here, | 464 // platform setups the tracking_id to slot mapping. So in dtor here, |
462 // if this touch event is a release event, we clear the mapping accordingly. | 465 // if this touch event is a release event, we clear the mapping accordingly. |
463 if (HasNativeEvent()) | 466 if (HasNativeEvent()) |
464 ClearTouchIdIfReleased(native_event()); | 467 ClearTouchIdIfReleased(native_event()); |
465 } | 468 } |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
557 return character_; | 560 return character_; |
558 | 561 |
559 #if defined(OS_WIN) | 562 #if defined(OS_WIN) |
560 return (native_event().message == WM_CHAR) ? key_code_ : | 563 return (native_event().message == WM_CHAR) ? key_code_ : |
561 GetCharacterFromKeyCode(key_code_, flags()); | 564 GetCharacterFromKeyCode(key_code_, flags()); |
562 #elif defined(USE_X11) | 565 #elif defined(USE_X11) |
563 if (!native_event()) | 566 if (!native_event()) |
564 return GetCharacterFromKeyCode(key_code_, flags()); | 567 return GetCharacterFromKeyCode(key_code_, flags()); |
565 | 568 |
566 DCHECK(native_event()->type == KeyPress || | 569 DCHECK(native_event()->type == KeyPress || |
567 native_event()->type == KeyRelease); | 570 native_event()->type == KeyRelease || |
571 native_event()->type == GenericEvent); | |
sadrul
2014/06/26 12:34:20
Also add a check that native_event()->xgeneric.evt
kpschoedel
2014/06/26 17:24:10
Done.
| |
568 | 572 |
569 // When a control key is held, prefer ASCII characters to non ASCII | 573 // When a control key is held, prefer ASCII characters to non ASCII |
570 // characters in order to use it for shortcut keys. GetCharacterFromKeyCode | 574 // characters in order to use it for shortcut keys. GetCharacterFromKeyCode |
571 // returns 'a' for VKEY_A even if the key is actually bound to 'à' in X11. | 575 // returns 'a' for VKEY_A even if the key is actually bound to 'à' in X11. |
572 // GetCharacterFromXEvent returns 'à' in that case. | 576 // GetCharacterFromXEvent returns 'à' in that case. |
573 return IsControlDown() ? | 577 return IsControlDown() ? |
574 GetCharacterFromKeyCode(key_code_, flags()) : | 578 GetCharacterFromKeyCode(key_code_, flags()) : |
575 GetCharacterFromXEvent(native_event()); | 579 GetCharacterFromXEvent(native_event()); |
576 #else | 580 #else |
577 if (native_event()) { | 581 if (native_event()) { |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
729 int GestureEvent::GetLowestTouchId() const { | 733 int GestureEvent::GetLowestTouchId() const { |
730 if (touch_ids_bitfield_ == 0) | 734 if (touch_ids_bitfield_ == 0) |
731 return -1; | 735 return -1; |
732 int i = -1; | 736 int i = -1; |
733 // Find the index of the least significant 1 bit | 737 // Find the index of the least significant 1 bit |
734 while (!(1 << ++i & touch_ids_bitfield_)); | 738 while (!(1 << ++i & touch_ids_bitfield_)); |
735 return i; | 739 return i; |
736 } | 740 } |
737 | 741 |
738 } // namespace ui | 742 } // namespace ui |
OLD | NEW |