OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "views/events/event.h" | 5 #include "views/events/event.h" |
6 | 6 |
7 #include <gdk/gdk.h> | 7 #include <gdk/gdk.h> |
8 #include <gdk/gdkx.h> | 8 #include <gdk/gdkx.h> |
9 #include <X11/extensions/XInput2.h> | 9 #include <X11/extensions/XInput2.h> |
10 #include <X11/Xlib.h> | 10 #include <X11/Xlib.h> |
11 | 11 |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
14 #include "ui/base/keycodes/keyboard_code_conversion_x.h" | 14 #include "ui/base/keycodes/keyboard_code_conversion_x.h" |
15 #include "views/touchui/touch_factory.h" | 15 #include "ui/base/touch/touch_factory.h" |
16 #include "views/widget/root_view.h" | 16 #include "views/widget/root_view.h" |
17 | 17 |
18 namespace views { | 18 namespace views { |
19 | 19 |
20 namespace { | 20 namespace { |
21 | 21 |
22 // Scroll amount for each wheelscroll event. 53 is also the value used for GTK+. | |
23 static int kWheelScrollAmount = 53; | |
24 | |
25 int GetEventFlagsFromXState(unsigned int state) { | |
26 int flags = 0; | |
27 if (state & ControlMask) | |
28 flags |= ui::EF_CONTROL_DOWN; | |
29 if (state & ShiftMask) | |
30 flags |= ui::EF_SHIFT_DOWN; | |
31 if (state & Mod1Mask) | |
32 flags |= ui::EF_ALT_DOWN; | |
33 if (state & LockMask) | |
34 flags |= ui::EF_CAPS_LOCK_DOWN; | |
35 if (state & Button1Mask) | |
36 flags |= ui::EF_LEFT_BUTTON_DOWN; | |
37 if (state & Button2Mask) | |
38 flags |= ui::EF_MIDDLE_BUTTON_DOWN; | |
39 if (state & Button3Mask) | |
40 flags |= ui::EF_RIGHT_BUTTON_DOWN; | |
41 | |
42 return flags; | |
43 } | |
44 | |
45 // Get the event flag for the button in XButtonEvent. During a ButtonPress | |
46 // event, |state| in XButtonEvent does not include the button that has just been | |
47 // pressed. Instead |state| contains flags for the buttons (if any) that had | |
48 // already been pressed before the current button, and |button| stores the most | |
49 // current pressed button. So, if you press down left mouse button, and while | |
50 // pressing it down, press down the right mouse button, then for the latter | |
51 // event, |state| would have Button1Mask set but not Button3Mask, and |button| | |
52 // would be 3. | |
53 int GetEventFlagsForButton(int button) { | |
54 switch (button) { | |
55 case 1: | |
56 return ui::EF_LEFT_BUTTON_DOWN; | |
57 case 2: | |
58 return ui::EF_MIDDLE_BUTTON_DOWN; | |
59 case 3: | |
60 return ui::EF_RIGHT_BUTTON_DOWN; | |
61 } | |
62 | |
63 DLOG(WARNING) << "Unexpected button (" << button << ") received."; | |
64 return 0; | |
65 } | |
66 | |
67 int GetButtonMaskForX2Event(XIDeviceEvent* xievent) { | |
68 int buttonflags = 0; | |
69 | |
70 for (int i = 0; i < 8 * xievent->buttons.mask_len; i++) { | |
71 if (XIMaskIsSet(xievent->buttons.mask, i)) { | |
72 buttonflags |= GetEventFlagsForButton(i); | |
73 } | |
74 } | |
75 | |
76 return buttonflags; | |
77 } | |
78 | |
79 ui::EventType GetTouchEventType(XEvent* xev) { | |
80 #if defined(USE_XI2_MT) | |
81 XIEvent* event = static_cast<XIEvent*>(xev->xcookie.data); | |
82 switch(event->evtype) { | |
83 case XI_TouchBegin: | |
84 return ui::ET_TOUCH_PRESSED; | |
85 case XI_TouchUpdate: | |
86 return ui::ET_TOUCH_MOVED; | |
87 case XI_TouchEnd: | |
88 return ui::ET_TOUCH_RELEASED; | |
89 } | |
90 | |
91 return ui::ET_UNKNOWN; | |
92 #else | |
93 XGenericEventCookie* cookie = &xev->xcookie; | |
94 DCHECK_EQ(cookie->evtype, XI_Motion); | |
95 | |
96 // Note: We will not generate a _STATIONARY event here. It will be created, | |
97 // when necessary, by a RWHVV. | |
98 // TODO(sad): When should _CANCELLED be generated? | |
99 | |
100 TouchFactory* factory = TouchFactory::GetInstance(); | |
101 float slot; | |
102 if (!factory->ExtractTouchParam(*xev, TouchFactory::TP_SLOT_ID, &slot)) | |
103 return ui::ET_UNKNOWN; | |
104 | |
105 if (!factory->IsSlotUsed(slot)) { | |
106 // This is a new touch point. | |
107 return ui::ET_TOUCH_PRESSED; | |
108 } | |
109 | |
110 float tracking; | |
111 if (!factory->ExtractTouchParam(*xev, TouchFactory::TP_TRACKING_ID, | |
112 &tracking)) | |
113 return ui::ET_UNKNOWN; | |
114 | |
115 if (tracking == 0l) { | |
116 // The touch point has been released. | |
117 return ui::ET_TOUCH_RELEASED; | |
118 } | |
119 | |
120 return ui::ET_TOUCH_MOVED; | |
121 #endif // defined(USE_XI2_MT) | |
122 } | |
123 | |
124 int GetTouchIDFromXEvent(XEvent* xev) { | 22 int GetTouchIDFromXEvent(XEvent* xev) { |
125 float id = 0; | 23 float id = 0; |
126 #if defined(USE_XI2_MT) | 24 #if defined(USE_XI2_MT) |
127 // TODO(ningxin.hu@gmail.com): Make the id always start from 0 for a new | 25 // TODO(ningxin.hu@gmail.com): Make the id always start from 0 for a new |
128 // touch-sequence when TRACKING_ID is used to extract the touch id. | 26 // touch-sequence when TRACKING_ID is used to extract the touch id. |
129 TouchFactory::TouchParam tp = TouchFactory::TP_TRACKING_ID; | 27 ui::TouchFactory::TouchParam tp = ui::TouchFactory::TP_TRACKING_ID; |
130 #else | 28 #else |
131 TouchFactory::TouchParam tp = TouchFactory::TP_SLOT_ID; | 29 ui::TouchFactory::TouchParam tp = ui::TouchFactory::TP_SLOT_ID; |
132 #endif | 30 #endif |
133 if (!TouchFactory::GetInstance()->ExtractTouchParam( | 31 if (!ui::TouchFactory::GetInstance()->ExtractTouchParam(*xev, tp, &id)) |
134 *xev, tp, &id)) | |
135 LOG(ERROR) << "Could not get the touch ID for the event. Using 0."; | 32 LOG(ERROR) << "Could not get the touch ID for the event. Using 0."; |
136 return id; | 33 return id; |
137 } | 34 } |
138 | 35 |
139 ui::EventType EventTypeFromNative(NativeEvent2 native_event) { | |
140 switch (native_event->type) { | |
141 case KeyPress: | |
142 return ui::ET_KEY_PRESSED; | |
143 case KeyRelease: | |
144 return ui::ET_KEY_RELEASED; | |
145 case ButtonPress: | |
146 if (native_event->xbutton.button == 4 || | |
147 native_event->xbutton.button == 5) | |
148 return ui::ET_MOUSEWHEEL; | |
149 return ui::ET_MOUSE_PRESSED; | |
150 case ButtonRelease: | |
151 if (native_event->xbutton.button == 4 || | |
152 native_event->xbutton.button == 5) | |
153 return ui::ET_MOUSEWHEEL; | |
154 return ui::ET_MOUSE_RELEASED; | |
155 case MotionNotify: | |
156 if (native_event->xmotion.state & | |
157 (Button1Mask | Button2Mask | Button3Mask)) | |
158 return ui::ET_MOUSE_DRAGGED; | |
159 return ui::ET_MOUSE_MOVED; | |
160 case GenericEvent: { | |
161 XIDeviceEvent* xievent = | |
162 static_cast<XIDeviceEvent*>(native_event->xcookie.data); | |
163 if (TouchFactory::GetInstance()->IsTouchDevice(xievent->sourceid)) | |
164 return GetTouchEventType(native_event); | |
165 switch (xievent->evtype) { | |
166 case XI_ButtonPress: | |
167 return (xievent->detail == 4 || xievent->detail == 5) ? | |
168 ui::ET_MOUSEWHEEL : ui::ET_MOUSE_PRESSED; | |
169 case XI_ButtonRelease: | |
170 return (xievent->detail == 4 || xievent->detail == 5) ? | |
171 ui::ET_MOUSEWHEEL : ui::ET_MOUSE_RELEASED; | |
172 case XI_Motion: | |
173 return GetButtonMaskForX2Event(xievent) ? ui::ET_MOUSE_DRAGGED : | |
174 ui::ET_MOUSE_MOVED; | |
175 } | |
176 } | |
177 default: | |
178 NOTREACHED(); | |
179 break; | |
180 } | |
181 return ui::ET_UNKNOWN; | |
182 } | |
183 | |
184 int GetMouseWheelOffset(XEvent* xev) { | |
185 if (xev->type == GenericEvent) { | |
186 XIDeviceEvent* xiev = static_cast<XIDeviceEvent*>(xev->xcookie.data); | |
187 return xiev->detail == 4 ? kWheelScrollAmount : -kWheelScrollAmount; | |
188 } | |
189 return xev->xbutton.button == 4 ? kWheelScrollAmount : -kWheelScrollAmount; | |
190 } | |
191 | |
192 gfx::Point GetEventLocation(XEvent* xev) { | |
193 switch (xev->type) { | |
194 case ButtonPress: | |
195 case ButtonRelease: | |
196 return gfx::Point(xev->xbutton.x, xev->xbutton.y); | |
197 | |
198 case MotionNotify: | |
199 return gfx::Point(xev->xmotion.x, xev->xmotion.y); | |
200 | |
201 case GenericEvent: { | |
202 XIDeviceEvent* xievent = | |
203 static_cast<XIDeviceEvent*>(xev->xcookie.data); | |
204 return gfx::Point(static_cast<int>(xievent->event_x), | |
205 static_cast<int>(xievent->event_y)); | |
206 } | |
207 } | |
208 | |
209 return gfx::Point(); | |
210 } | |
211 | |
212 int GetLocatedEventFlags(XEvent* xev) { | |
213 switch (xev->type) { | |
214 case ButtonPress: | |
215 case ButtonRelease: | |
216 return GetEventFlagsFromXState(xev->xbutton.state) | | |
217 GetEventFlagsForButton(xev->xbutton.button); | |
218 | |
219 case MotionNotify: | |
220 return GetEventFlagsFromXState(xev->xmotion.state); | |
221 | |
222 case GenericEvent: { | |
223 XIDeviceEvent* xievent = static_cast<XIDeviceEvent*>(xev->xcookie.data); | |
224 bool touch = | |
225 TouchFactory::GetInstance()->IsTouchDevice(xievent->sourceid); | |
226 switch (xievent->evtype) { | |
227 case XI_ButtonPress: | |
228 case XI_ButtonRelease: | |
229 return GetButtonMaskForX2Event(xievent) | | |
230 GetEventFlagsFromXState(xievent->mods.effective) | | |
231 (touch ? 0 : GetEventFlagsForButton(xievent->detail)); | |
232 | |
233 case XI_Motion: | |
234 return GetButtonMaskForX2Event(xievent) | | |
235 GetEventFlagsFromXState(xievent->mods.effective); | |
236 } | |
237 } | |
238 } | |
239 | |
240 return 0; | |
241 } | |
242 | |
243 uint16 GetCharacterFromXKeyEvent(XKeyEvent* key) { | 36 uint16 GetCharacterFromXKeyEvent(XKeyEvent* key) { |
244 char buf[6]; | 37 char buf[6]; |
245 int bytes_written = XLookupString(key, buf, 6, NULL, NULL); | 38 int bytes_written = XLookupString(key, buf, 6, NULL, NULL); |
246 DCHECK_LE(bytes_written, 6); | 39 DCHECK_LE(bytes_written, 6); |
247 | 40 |
248 string16 result; | 41 string16 result; |
249 return (bytes_written > 0 && UTF8ToUTF16(buf, bytes_written, &result) && | 42 return (bytes_written > 0 && UTF8ToUTF16(buf, bytes_written, &result) && |
250 result.length() == 1) ? result[0] : 0; | 43 result.length() == 1) ? result[0] : 0; |
251 } | 44 } |
252 | 45 |
253 float GetTouchParamFromXEvent(XEvent* xev, | 46 float GetTouchParamFromXEvent(XEvent* xev, |
254 TouchFactory::TouchParam tp, | 47 ui::TouchFactory::TouchParam tp, |
255 float default_value) { | 48 float default_value) { |
256 TouchFactory::GetInstance()->ExtractTouchParam(*xev, tp, &default_value); | 49 ui::TouchFactory::GetInstance()->ExtractTouchParam(*xev, tp, &default_value); |
257 return default_value; | 50 return default_value; |
258 } | 51 } |
259 | 52 |
260 float GetTouchForceFromXEvent(XEvent* xev) { | 53 float GetTouchForceFromXEvent(XEvent* xev) { |
261 float force = 0.0; | 54 float force = 0.0; |
262 force = GetTouchParamFromXEvent(xev, TouchFactory::TP_PRESSURE, 0.0); | 55 force = GetTouchParamFromXEvent(xev, ui::TouchFactory::TP_PRESSURE, 0.0); |
263 unsigned int deviceid = | 56 unsigned int deviceid = |
264 static_cast<XIDeviceEvent*>(xev->xcookie.data)->sourceid; | 57 static_cast<XIDeviceEvent*>(xev->xcookie.data)->sourceid; |
265 // Force is normalized to fall into [0, 1] | 58 // Force is normalized to fall into [0, 1] |
266 if (!TouchFactory::GetInstance()->NormalizeTouchParam( | 59 if (!ui::TouchFactory::GetInstance()->NormalizeTouchParam( |
267 deviceid, TouchFactory::TP_PRESSURE, &force)) | 60 deviceid, ui::TouchFactory::TP_PRESSURE, &force)) |
268 force = 0.0; | 61 force = 0.0; |
269 return force; | 62 return force; |
270 } | 63 } |
271 | 64 |
272 // The following two functions are copied from event_gtk.cc. These will be | 65 // The following two functions are copied from event_gtk.cc. These will be |
273 // removed when GTK dependency is removed. | 66 // removed when GTK dependency is removed. |
| 67 #if defined(TOOLKIT_USES_GTK) |
274 uint16 GetCharacterFromGdkKeyval(guint keyval) { | 68 uint16 GetCharacterFromGdkKeyval(guint keyval) { |
275 guint32 ch = gdk_keyval_to_unicode(keyval); | 69 guint32 ch = gdk_keyval_to_unicode(keyval); |
276 | 70 |
277 // We only support BMP characters. | 71 // We only support BMP characters. |
278 return ch < 0xFFFE ? static_cast<uint16>(ch) : 0; | 72 return ch < 0xFFFE ? static_cast<uint16>(ch) : 0; |
279 } | 73 } |
280 | 74 |
281 GdkEventKey* GetGdkEventKeyFromNative(NativeEvent native_event) { | 75 GdkEventKey* GetGdkEventKeyFromNative(GdkEvent* gdk_event) { |
282 DCHECK(native_event->type == GDK_KEY_PRESS || | 76 DCHECK(gdk_event->type == GDK_KEY_PRESS || |
283 native_event->type == GDK_KEY_RELEASE); | 77 gdk_event->type == GDK_KEY_RELEASE); |
284 return &native_event->key; | 78 return &gdk_event->key; |
285 } | 79 } |
| 80 #endif |
286 | 81 |
287 } // namespace | 82 } // namespace |
288 | 83 |
289 //////////////////////////////////////////////////////////////////////////////// | 84 //////////////////////////////////////////////////////////////////////////////// |
290 // Event, private: | |
291 | |
292 void Event::InitWithNativeEvent2(NativeEvent2 native_event_2, | |
293 FromNativeEvent2) { | |
294 native_event_ = NULL; | |
295 // TODO(beng): remove once we rid views of Gtk/Gdk. | |
296 native_event_2_ = native_event_2; | |
297 } | |
298 | |
299 //////////////////////////////////////////////////////////////////////////////// | |
300 // LocatedEvent, protected: | |
301 | |
302 LocatedEvent::LocatedEvent(NativeEvent2 native_event_2, | |
303 FromNativeEvent2 from_native) | |
304 : Event(native_event_2, | |
305 EventTypeFromNative(native_event_2), | |
306 GetLocatedEventFlags(native_event_2), | |
307 from_native), | |
308 location_(GetEventLocation(native_event_2)) { | |
309 } | |
310 | |
311 //////////////////////////////////////////////////////////////////////////////// | |
312 // KeyEvent, public: | 85 // KeyEvent, public: |
313 | 86 |
314 KeyEvent::KeyEvent(NativeEvent2 native_event_2, FromNativeEvent2 from_native) | |
315 : Event(native_event_2, | |
316 EventTypeFromNative(native_event_2), | |
317 GetEventFlagsFromXState(native_event_2->xkey.state), | |
318 from_native), | |
319 key_code_(ui::KeyboardCodeFromXKeyEvent(native_event_2)), | |
320 character_(0), | |
321 unmodified_character_(0) { | |
322 } | |
323 | |
324 uint16 KeyEvent::GetCharacter() const { | 87 uint16 KeyEvent::GetCharacter() const { |
325 if (character_) | 88 if (character_) |
326 return character_; | 89 return character_; |
327 | 90 |
328 if (!native_event_2()) { | 91 if (!native_event()) { |
| 92 #if defined(TOOLKIT_USES_GTK) |
329 // This event may have been created from a Gdk event. | 93 // This event may have been created from a Gdk event. |
330 if (IsControlDown() || !native_event()) | 94 if (!IsControlDown() && gdk_event()) { |
331 return GetCharacterFromKeyCode(key_code_, flags()); | 95 uint16 ch = GetCharacterFromGdkKeyval( |
332 | 96 GetGdkEventKeyFromNative(gdk_event())->keyval); |
333 uint16 ch = GetCharacterFromGdkKeyval( | 97 if (ch) |
334 GetGdkEventKeyFromNative(native_event())->keyval); | 98 return ch; |
335 return ch ? ch : GetCharacterFromKeyCode(key_code_, flags()); | 99 } |
| 100 #endif |
| 101 return GetCharacterFromKeyCode(key_code_, flags()); |
336 } | 102 } |
337 | 103 |
338 DCHECK(native_event_2()->type == KeyPress || | 104 DCHECK(native_event()->type == KeyPress || |
339 native_event_2()->type == KeyRelease); | 105 native_event()->type == KeyRelease); |
340 | 106 |
341 uint16 ch = GetCharacterFromXKeyEvent(&native_event_2()->xkey); | 107 uint16 ch = GetCharacterFromXKeyEvent(&native_event()->xkey); |
342 return ch ? ch : GetCharacterFromKeyCode(key_code_, flags()); | 108 return ch ? ch : GetCharacterFromKeyCode(key_code_, flags()); |
343 } | 109 } |
344 | 110 |
345 uint16 KeyEvent::GetUnmodifiedCharacter() const { | 111 uint16 KeyEvent::GetUnmodifiedCharacter() const { |
346 if (unmodified_character_) | 112 if (unmodified_character_) |
347 return unmodified_character_; | 113 return unmodified_character_; |
348 | 114 |
349 if (!native_event_2()) { | 115 if (!native_event()) { |
| 116 #if defined(TOOLKIT_USES_GTK) |
350 // This event may have been created from a Gdk event. | 117 // This event may have been created from a Gdk event. |
351 if (!native_event()) | 118 if (gdk_event()) { |
352 return GetCharacterFromKeyCode(key_code_, flags() & ui::EF_SHIFT_DOWN); | 119 GdkEventKey* key = GetGdkEventKeyFromNative(gdk_event()); |
353 | 120 |
354 GdkEventKey* key = GetGdkEventKeyFromNative(native_event()); | 121 static const guint kIgnoredModifiers = |
| 122 GDK_CONTROL_MASK | GDK_LOCK_MASK | GDK_MOD1_MASK | GDK_MOD2_MASK | |
| 123 GDK_MOD3_MASK | GDK_MOD4_MASK | GDK_MOD5_MASK | GDK_SUPER_MASK | |
| 124 GDK_HYPER_MASK | GDK_META_MASK; |
355 | 125 |
356 static const guint kIgnoredModifiers = | 126 // We can't use things like (key->state & GDK_SHIFT_MASK), as it may mask |
357 GDK_CONTROL_MASK | GDK_LOCK_MASK | GDK_MOD1_MASK | GDK_MOD2_MASK | | 127 // out bits used by X11 or Gtk internally. |
358 GDK_MOD3_MASK | GDK_MOD4_MASK | GDK_MOD5_MASK | GDK_SUPER_MASK | | 128 GdkModifierType modifiers = |
359 GDK_HYPER_MASK | GDK_META_MASK; | 129 static_cast<GdkModifierType>(key->state & ~kIgnoredModifiers); |
360 | 130 guint keyval = 0; |
361 // We can't use things like (key->state & GDK_SHIFT_MASK), as it may mask | 131 if (gdk_keymap_translate_keyboard_state(NULL, key->hardware_keycode, |
362 // out bits used by X11 or Gtk internally. | 132 modifiers, key->group, &keyval, NULL, NULL, NULL)) { |
363 GdkModifierType modifiers = | 133 uint16 ch = GetCharacterFromGdkKeyval(keyval); |
364 static_cast<GdkModifierType>(key->state & ~kIgnoredModifiers); | 134 if (ch) |
365 guint keyval = 0; | 135 return ch; |
366 uint16 ch = 0; | 136 } |
367 if (gdk_keymap_translate_keyboard_state(NULL, key->hardware_keycode, | |
368 modifiers, key->group, &keyval, | |
369 NULL, NULL, NULL)) { | |
370 ch = GetCharacterFromGdkKeyval(keyval); | |
371 } | 137 } |
372 | 138 #endif |
373 return ch ? ch : | 139 return GetCharacterFromKeyCode(key_code_, flags() & ui::EF_SHIFT_DOWN); |
374 GetCharacterFromKeyCode(key_code_, flags() & ui::EF_SHIFT_DOWN); | |
375 } | 140 } |
376 | 141 |
377 DCHECK(native_event_2()->type == KeyPress || | 142 DCHECK(native_event()->type == KeyPress || |
378 native_event_2()->type == KeyRelease); | 143 native_event()->type == KeyRelease); |
379 | 144 |
380 XKeyEvent key = native_event_2()->xkey; | 145 XKeyEvent key = native_event()->xkey; |
381 | 146 |
382 static const unsigned int kIgnoredModifiers = ControlMask | LockMask | | 147 static const unsigned int kIgnoredModifiers = ControlMask | LockMask | |
383 Mod1Mask | Mod2Mask | Mod3Mask | Mod4Mask | Mod5Mask; | 148 Mod1Mask | Mod2Mask | Mod3Mask | Mod4Mask | Mod5Mask; |
384 | 149 |
385 // We can't use things like (key.state & ShiftMask), as it may mask out bits | 150 // We can't use things like (key.state & ShiftMask), as it may mask out bits |
386 // used by X11 internally. | 151 // used by X11 internally. |
387 key.state &= ~kIgnoredModifiers; | 152 key.state &= ~kIgnoredModifiers; |
388 uint16 ch = GetCharacterFromXKeyEvent(&key); | 153 uint16 ch = GetCharacterFromXKeyEvent(&key); |
389 return ch ? ch : | 154 return ch ? ch : |
390 GetCharacterFromKeyCode(key_code_, flags() & ui::EF_SHIFT_DOWN); | 155 GetCharacterFromKeyCode(key_code_, flags() & ui::EF_SHIFT_DOWN); |
391 } | 156 } |
392 | 157 |
393 //////////////////////////////////////////////////////////////////////////////// | 158 //////////////////////////////////////////////////////////////////////////////// |
394 // MouseEvent, public: | |
395 | |
396 MouseEvent::MouseEvent(NativeEvent2 native_event_2, | |
397 FromNativeEvent2 from_native) | |
398 : LocatedEvent(native_event_2, from_native) { | |
399 } | |
400 | |
401 //////////////////////////////////////////////////////////////////////////////// | |
402 // MouseWheelEvent, public: | |
403 | |
404 MouseWheelEvent::MouseWheelEvent(NativeEvent2 native_event_2, | |
405 FromNativeEvent2 from_native) | |
406 : MouseEvent(native_event_2, from_native), | |
407 offset_(GetMouseWheelOffset(native_event_2)) { | |
408 } | |
409 | |
410 //////////////////////////////////////////////////////////////////////////////// | |
411 // TouchEvent, public: | 159 // TouchEvent, public: |
412 | 160 |
413 TouchEvent::TouchEvent(NativeEvent2 native_event_2, | 161 TouchEvent::TouchEvent(const ui::NativeEvent& native_event) |
414 FromNativeEvent2 from_native) | 162 : LocatedEvent(native_event), |
415 : LocatedEvent(native_event_2, from_native), | 163 touch_id_(GetTouchIDFromXEvent(native_event)), |
416 touch_id_(GetTouchIDFromXEvent(native_event_2)), | 164 radius_x_(GetTouchParamFromXEvent(native_event, |
417 radius_x_(GetTouchParamFromXEvent(native_event_2, | 165 ui::TouchFactory::TP_TOUCH_MAJOR, |
418 TouchFactory::TP_TOUCH_MAJOR, | |
419 2.0) / 2.0), | 166 2.0) / 2.0), |
420 radius_y_(GetTouchParamFromXEvent(native_event_2, | 167 radius_y_(GetTouchParamFromXEvent(native_event, |
421 TouchFactory::TP_TOUCH_MINOR, | 168 ui::TouchFactory::TP_TOUCH_MINOR, |
422 2.0) / 2.0), | 169 2.0) / 2.0), |
423 rotation_angle_(GetTouchParamFromXEvent(native_event_2, | 170 rotation_angle_(GetTouchParamFromXEvent(native_event, |
424 TouchFactory::TP_ORIENTATION, | 171 ui::TouchFactory::TP_ORIENTATION, |
425 0.0)), | 172 0.0)), |
426 force_(GetTouchForceFromXEvent(native_event_2)) { | 173 force_(GetTouchForceFromXEvent(native_event)) { |
427 #if !defined(USE_XI2_MT) | 174 #if !defined(USE_XI2_MT) |
428 if (type() == ui::ET_TOUCH_PRESSED || type() == ui::ET_TOUCH_RELEASED) { | 175 if (type() == ui::ET_TOUCH_PRESSED || type() == ui::ET_TOUCH_RELEASED) { |
429 TouchFactory* factory = TouchFactory::GetInstance(); | 176 ui::TouchFactory* factory = ui::TouchFactory::GetInstance(); |
430 float slot; | 177 float slot; |
431 if (factory->ExtractTouchParam(*native_event_2, | 178 if (factory->ExtractTouchParam(*native_event, |
432 TouchFactory::TP_SLOT_ID, &slot)) { | 179 ui::TouchFactory::TP_SLOT_ID, &slot)) { |
433 factory->SetSlotUsed(slot, type() == ui::ET_TOUCH_PRESSED); | 180 factory->SetSlotUsed(slot, type() == ui::ET_TOUCH_PRESSED); |
434 } | 181 } |
435 } | 182 } |
436 #endif | 183 #endif |
437 } | 184 } |
438 | 185 |
439 } // namespace views | 186 } // namespace views |
OLD | NEW |