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 11 matching lines...) Expand all Loading... |
22 #include "ui/gfx/transform_util.h" | 22 #include "ui/gfx/transform_util.h" |
23 | 23 |
24 #if defined(USE_X11) | 24 #if defined(USE_X11) |
25 #include "ui/events/keycodes/keyboard_code_conversion_x.h" | 25 #include "ui/events/keycodes/keyboard_code_conversion_x.h" |
26 #elif defined(USE_OZONE) | 26 #elif defined(USE_OZONE) |
27 #include "ui/events/keycodes/keyboard_code_conversion.h" | 27 #include "ui/events/keycodes/keyboard_code_conversion.h" |
28 #endif | 28 #endif |
29 | 29 |
30 namespace { | 30 namespace { |
31 | 31 |
32 base::NativeEvent CopyNativeEvent(const base::NativeEvent& event) { | |
33 #if defined(USE_X11) | |
34 if (!event || event->type == GenericEvent) | |
35 return NULL; | |
36 XEvent* copy = new XEvent; | |
37 *copy = *event; | |
38 return copy; | |
39 #elif defined(OS_WIN) | |
40 return event; | |
41 #elif defined(USE_OZONE) | |
42 return NULL; | |
43 #else | |
44 NOTREACHED() << | |
45 "Don't know how to copy base::NativeEvent for this platform"; | |
46 return NULL; | |
47 #endif | |
48 } | |
49 | |
50 std::string EventTypeName(ui::EventType type) { | 32 std::string EventTypeName(ui::EventType type) { |
51 #define RETURN_IF_TYPE(t) if (type == ui::t) return #t | 33 #define RETURN_IF_TYPE(t) if (type == ui::t) return #t |
52 #define CASE_TYPE(t) case ui::t: return #t | 34 #define CASE_TYPE(t) case ui::t: return #t |
53 switch (type) { | 35 switch (type) { |
54 CASE_TYPE(ET_UNKNOWN); | 36 CASE_TYPE(ET_UNKNOWN); |
55 CASE_TYPE(ET_MOUSE_PRESSED); | 37 CASE_TYPE(ET_MOUSE_PRESSED); |
56 CASE_TYPE(ET_MOUSE_DRAGGED); | 38 CASE_TYPE(ET_MOUSE_DRAGGED); |
57 CASE_TYPE(ET_MOUSE_RELEASED); | 39 CASE_TYPE(ET_MOUSE_RELEASED); |
58 CASE_TYPE(ET_MOUSE_MOVED); | 40 CASE_TYPE(ET_MOUSE_MOVED); |
59 CASE_TYPE(ET_MOUSE_ENTERED); | 41 CASE_TYPE(ET_MOUSE_ENTERED); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 } | 94 } |
113 | 95 |
114 } // namespace | 96 } // namespace |
115 | 97 |
116 namespace ui { | 98 namespace ui { |
117 | 99 |
118 //////////////////////////////////////////////////////////////////////////////// | 100 //////////////////////////////////////////////////////////////////////////////// |
119 // Event | 101 // Event |
120 | 102 |
121 Event::~Event() { | 103 Event::~Event() { |
122 #if defined(USE_X11) | 104 if (!delete_native_event_) |
123 if (delete_native_event_) | 105 return; |
124 delete native_event_; | 106 ReleaseCopiedNativeEvent(native_event_); |
125 #endif | |
126 } | 107 } |
127 | 108 |
128 bool Event::HasNativeEvent() const { | 109 bool Event::HasNativeEvent() const { |
129 base::NativeEvent null_event; | 110 base::NativeEvent null_event; |
130 std::memset(&null_event, 0, sizeof(null_event)); | 111 std::memset(&null_event, 0, sizeof(null_event)); |
131 return !!std::memcmp(&native_event_, &null_event, sizeof(null_event)); | 112 return !!std::memcmp(&native_event_, &null_event, sizeof(null_event)); |
132 } | 113 } |
133 | 114 |
134 void Event::StopPropagation() { | 115 void Event::StopPropagation() { |
135 // TODO(sad): Re-enable these checks once View uses dispatcher to dispatch | 116 // TODO(sad): Re-enable these checks once View uses dispatcher to dispatch |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 base::HistogramBase::kUmaTargetedHistogramFlag); | 172 base::HistogramBase::kUmaTargetedHistogramFlag); |
192 counter_for_type->Add(delta.InMicroseconds()); | 173 counter_for_type->Add(delta.InMicroseconds()); |
193 InitWithNativeEvent(native_event); | 174 InitWithNativeEvent(native_event); |
194 } | 175 } |
195 | 176 |
196 Event::Event(const Event& copy) | 177 Event::Event(const Event& copy) |
197 : type_(copy.type_), | 178 : type_(copy.type_), |
198 time_stamp_(copy.time_stamp_), | 179 time_stamp_(copy.time_stamp_), |
199 latency_(copy.latency_), | 180 latency_(copy.latency_), |
200 flags_(copy.flags_), | 181 flags_(copy.flags_), |
201 native_event_(::CopyNativeEvent(copy.native_event_)), | 182 native_event_(CopyNativeEvent(copy.native_event_)), |
202 delete_native_event_(false), | 183 delete_native_event_(false), |
203 cancelable_(true), | 184 cancelable_(true), |
204 target_(NULL), | 185 target_(NULL), |
205 phase_(EP_PREDISPATCH), | 186 phase_(EP_PREDISPATCH), |
206 result_(ER_UNHANDLED) { | 187 result_(ER_UNHANDLED) { |
207 if (type_ < ET_LAST) | 188 if (type_ < ET_LAST) |
208 name_ = EventTypeName(type_); | 189 name_ = EventTypeName(type_); |
209 #if defined(USE_X11) | 190 #if defined(USE_X11) || defined(OS_MACOSX) |
210 if (native_event_) | 191 if (native_event_) |
211 delete_native_event_ = true; | 192 delete_native_event_ = true; |
212 #endif | 193 #endif |
213 } | 194 } |
214 | 195 |
215 void Event::SetType(EventType type) { | 196 void Event::SetType(EventType type) { |
216 if (type_ < ET_LAST) | 197 if (type_ < ET_LAST) |
217 name_ = std::string(); | 198 name_ = std::string(); |
218 type_ = type; | 199 type_ = type; |
219 if (type_ < ET_LAST) | 200 if (type_ < ET_LAST) |
(...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
731 int GestureEvent::GetLowestTouchId() const { | 712 int GestureEvent::GetLowestTouchId() const { |
732 if (touch_ids_bitfield_ == 0) | 713 if (touch_ids_bitfield_ == 0) |
733 return -1; | 714 return -1; |
734 int i = -1; | 715 int i = -1; |
735 // Find the index of the least significant 1 bit | 716 // Find the index of the least significant 1 bit |
736 while (!(1 << ++i & touch_ids_bitfield_)); | 717 while (!(1 << ++i & touch_ids_bitfield_)); |
737 return i; | 718 return i; |
738 } | 719 } |
739 | 720 |
740 } // namespace ui | 721 } // namespace ui |
OLD | NEW |