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_constants.h" | 5 #include "ui/events/x/events_x.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 #include <string.h> | 8 #include <string.h> |
9 #include <X11/extensions/XInput.h> | 9 #include <X11/extensions/XInput.h> |
10 #include <X11/extensions/XInput2.h> | 10 #include <X11/extensions/XInput2.h> |
11 #include <X11/Xlib.h> | 11 #include <X11/Xlib.h> |
12 #include <X11/Xutil.h> | 12 #include <X11/Xutil.h> |
13 #include <X11/XKBlib.h> | 13 #include <X11/XKBlib.h> |
14 | 14 |
15 #include "base/logging.h" | 15 #include "base/logging.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 return ShiftMask; | 52 return ShiftMask; |
53 case ui::VKEY_MENU: | 53 case ui::VKEY_MENU: |
54 return Mod1Mask; | 54 return Mod1Mask; |
55 case ui::VKEY_CAPITAL: | 55 case ui::VKEY_CAPITAL: |
56 return LockMask; | 56 return LockMask; |
57 default: | 57 default: |
58 return 0; | 58 return 0; |
59 } | 59 } |
60 } | 60 } |
61 | 61 |
62 void UpdateStateFromXEvent(const base::NativeEvent& native_event) { | 62 void UpdateStateFromXEvent(const XEvent* native_event) { |
63 ui::KeyboardCode keyboard_code = ui::KeyboardCodeFromNative(native_event); | 63 ui::KeyboardCode keyboard_code = ui::KeyboardCodeFromNative(native_event); |
64 unsigned int mask = StateFromKeyboardCode(keyboard_code); | 64 unsigned int mask = StateFromKeyboardCode(keyboard_code); |
65 // Floating device can't access the modifer state from master device. | 65 // Floating device can't access the modifer state from master device. |
66 // We need to track the states of modifier keys in a singleton for | 66 // We need to track the states of modifier keys in a singleton for |
67 // floating devices such as touch screen. Issue 106426 is one example | 67 // floating devices such as touch screen. Issue 106426 is one example |
68 // of why we need the modifier states for floating device. | 68 // of why we need the modifier states for floating device. |
69 switch (native_event->type) { | 69 switch (native_event->type) { |
70 case KeyPress: | 70 case KeyPress: |
71 state_ = native_event->xkey.state | mask; | 71 state_ = native_event->xkey.state | mask; |
72 break; | 72 break; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 | 106 |
107 unsigned int state_; | 107 unsigned int state_; |
108 | 108 |
109 DISALLOW_COPY_AND_ASSIGN(XModifierStateWatcher); | 109 DISALLOW_COPY_AND_ASSIGN(XModifierStateWatcher); |
110 }; | 110 }; |
111 | 111 |
112 // Detects if a touch event is a driver-generated 'special event'. | 112 // Detects if a touch event is a driver-generated 'special event'. |
113 // A 'special event' is a touch event with maximum radius and pressure at | 113 // A 'special event' is a touch event with maximum radius and pressure at |
114 // location (0, 0). | 114 // location (0, 0). |
115 // This needs to be done in a cleaner way: http://crbug.com/169256 | 115 // This needs to be done in a cleaner way: http://crbug.com/169256 |
116 bool TouchEventIsGeneratedHack(const base::NativeEvent& native_event) { | 116 bool TouchEventIsGeneratedHack(const XEvent* native_event) { |
117 XIDeviceEvent* event = | 117 XIDeviceEvent* event = |
118 static_cast<XIDeviceEvent*>(native_event->xcookie.data); | 118 static_cast<XIDeviceEvent*>(native_event->xcookie.data); |
119 CHECK(event->evtype == XI_TouchBegin || | 119 CHECK(event->evtype == XI_TouchBegin || |
120 event->evtype == XI_TouchUpdate || | 120 event->evtype == XI_TouchUpdate || |
121 event->evtype == XI_TouchEnd); | 121 event->evtype == XI_TouchEnd); |
122 | 122 |
123 // Force is normalized to [0, 1]. | 123 // Force is normalized to [0, 1]. |
124 if (ui::GetTouchForce(native_event) < 1.0f) | 124 if (ui::GetTouchForce(native_event) < 1.0f) |
125 return false; | 125 return false; |
126 | 126 |
(...skipping 30 matching lines...) Expand all Loading... |
157 flags |= ui::EF_ALTGR_DOWN; | 157 flags |= ui::EF_ALTGR_DOWN; |
158 if (state & Button1Mask) | 158 if (state & Button1Mask) |
159 flags |= ui::EF_LEFT_MOUSE_BUTTON; | 159 flags |= ui::EF_LEFT_MOUSE_BUTTON; |
160 if (state & Button2Mask) | 160 if (state & Button2Mask) |
161 flags |= ui::EF_MIDDLE_MOUSE_BUTTON; | 161 flags |= ui::EF_MIDDLE_MOUSE_BUTTON; |
162 if (state & Button3Mask) | 162 if (state & Button3Mask) |
163 flags |= ui::EF_RIGHT_MOUSE_BUTTON; | 163 flags |= ui::EF_RIGHT_MOUSE_BUTTON; |
164 return flags; | 164 return flags; |
165 } | 165 } |
166 | 166 |
167 int GetEventFlagsFromXKeyEvent(XEvent* xevent) { | 167 int GetEventFlagsFromXKeyEvent(const XEvent* xevent) { |
168 DCHECK(xevent->type == KeyPress || xevent->type == KeyRelease); | 168 DCHECK(xevent->type == KeyPress || xevent->type == KeyRelease); |
169 | 169 |
170 #if defined(OS_CHROMEOS) | 170 #if defined(OS_CHROMEOS) |
171 const int ime_fabricated_flag = 0; | 171 const int ime_fabricated_flag = 0; |
172 #else | 172 #else |
173 // XIM fabricates key events for the character compositions by XK_Multi_key. | 173 // XIM fabricates key events for the character compositions by XK_Multi_key. |
174 // For example, when a user hits XK_Multi_key, XK_apostrophe, and XK_e in | 174 // For example, when a user hits XK_Multi_key, XK_apostrophe, and XK_e in |
175 // order to input "é", then XIM generates a key event with keycode=0 and | 175 // order to input "é", then XIM generates a key event with keycode=0 and |
176 // state=0 for the composition, and the sequence of X11 key events will be | 176 // state=0 for the composition, and the sequence of X11 key events will be |
177 // XK_Multi_key, XK_apostrophe, **NoSymbol**, and XK_e. If the user used | 177 // XK_Multi_key, XK_apostrophe, **NoSymbol**, and XK_e. If the user used |
178 // shift key and/or caps lock key, state can be ShiftMask, LockMask or both. | 178 // shift key and/or caps lock key, state can be ShiftMask, LockMask or both. |
179 // | 179 // |
180 // We have to send these fabricated key events to XIM so it can correctly | 180 // We have to send these fabricated key events to XIM so it can correctly |
181 // handle the character compositions. | 181 // handle the character compositions. |
182 const unsigned int shift_lock_mask = ShiftMask | LockMask; | 182 const unsigned int shift_lock_mask = ShiftMask | LockMask; |
183 const bool fabricated_by_xim = | 183 const bool fabricated_by_xim = |
184 xevent->xkey.keycode == 0 && | 184 xevent->xkey.keycode == 0 && |
185 (xevent->xkey.state & ~shift_lock_mask) == 0; | 185 (xevent->xkey.state & ~shift_lock_mask) == 0; |
186 const int ime_fabricated_flag = | 186 const int ime_fabricated_flag = |
187 fabricated_by_xim ? ui::EF_IME_FABRICATED_KEY : 0; | 187 fabricated_by_xim ? ui::EF_IME_FABRICATED_KEY : 0; |
188 #endif | 188 #endif |
189 | 189 |
| 190 KeySym key = XLookupKeysym(const_cast<XKeyEvent*>(&xevent->xkey), 0); |
| 191 |
190 return GetEventFlagsFromXState(xevent->xkey.state) | | 192 return GetEventFlagsFromXState(xevent->xkey.state) | |
191 (xevent->xkey.send_event ? ui::EF_FINAL : 0) | | 193 (xevent->xkey.send_event ? ui::EF_FINAL : 0) | |
192 (IsKeypadKey(XLookupKeysym(&xevent->xkey, 0)) ? ui::EF_NUMPAD_KEY : 0) | | 194 (IsKeypadKey(key) ? ui::EF_NUMPAD_KEY : 0) | |
193 (IsFunctionKey(XLookupKeysym(&xevent->xkey, 0)) ? | 195 (IsFunctionKey(key) ? ui::EF_FUNCTION_KEY : 0) | ime_fabricated_flag; |
194 ui::EF_FUNCTION_KEY : 0) | | |
195 ime_fabricated_flag; | |
196 } | 196 } |
197 | 197 |
198 int GetEventFlagsFromXGenericEvent(XEvent* xevent) { | 198 int GetEventFlagsFromXGenericEvent(const XEvent* xevent) { |
199 DCHECK(xevent->type == GenericEvent); | 199 DCHECK(xevent->type == GenericEvent); |
200 XIDeviceEvent* xievent = static_cast<XIDeviceEvent*>(xevent->xcookie.data); | 200 const XIDeviceEvent* xievent = |
| 201 static_cast<const XIDeviceEvent*>(xevent->xcookie.data); |
201 DCHECK((xievent->evtype == XI_KeyPress) || | 202 DCHECK((xievent->evtype == XI_KeyPress) || |
202 (xievent->evtype == XI_KeyRelease)); | 203 (xievent->evtype == XI_KeyRelease)); |
203 return GetEventFlagsFromXState(xievent->mods.effective) | | 204 return GetEventFlagsFromXState(xievent->mods.effective) | |
204 (xevent->xkey.send_event ? ui::EF_FINAL : 0) | | 205 (xevent->xkey.send_event ? ui::EF_FINAL : 0) | |
205 (IsKeypadKey( | 206 (IsKeypadKey( |
206 XkbKeycodeToKeysym(xievent->display, xievent->detail, 0, 0)) | 207 XkbKeycodeToKeysym(xievent->display, xievent->detail, 0, 0)) |
207 ? ui::EF_NUMPAD_KEY | 208 ? ui::EF_NUMPAD_KEY |
208 : 0); | 209 : 0); |
209 } | 210 } |
210 | 211 |
(...skipping 23 matching lines...) Expand all Loading... |
234 for (int i = 0; i < 8 * xievent->buttons.mask_len; i++) { | 235 for (int i = 0; i < 8 * xievent->buttons.mask_len; i++) { |
235 if (XIMaskIsSet(xievent->buttons.mask, i)) { | 236 if (XIMaskIsSet(xievent->buttons.mask, i)) { |
236 int button = (xievent->sourceid == xievent->deviceid) ? | 237 int button = (xievent->sourceid == xievent->deviceid) ? |
237 ui::DeviceDataManagerX11::GetInstance()->GetMappedButton(i) : i; | 238 ui::DeviceDataManagerX11::GetInstance()->GetMappedButton(i) : i; |
238 buttonflags |= GetEventFlagsForButton(button); | 239 buttonflags |= GetEventFlagsForButton(button); |
239 } | 240 } |
240 } | 241 } |
241 return buttonflags; | 242 return buttonflags; |
242 } | 243 } |
243 | 244 |
244 ui::EventType GetTouchEventType(const base::NativeEvent& native_event) { | 245 ui::EventType GetTouchEventType(const XEvent* native_event) { |
245 XIDeviceEvent* event = | 246 XIDeviceEvent* event = |
246 static_cast<XIDeviceEvent*>(native_event->xcookie.data); | 247 static_cast<XIDeviceEvent*>(native_event->xcookie.data); |
247 switch(event->evtype) { | 248 switch(event->evtype) { |
248 case XI_TouchBegin: | 249 case XI_TouchBegin: |
249 return TouchEventIsGeneratedHack(native_event) ? ui::ET_UNKNOWN : | 250 return TouchEventIsGeneratedHack(native_event) ? ui::ET_UNKNOWN : |
250 ui::ET_TOUCH_PRESSED; | 251 ui::ET_TOUCH_PRESSED; |
251 case XI_TouchUpdate: | 252 case XI_TouchUpdate: |
252 return TouchEventIsGeneratedHack(native_event) ? ui::ET_UNKNOWN : | 253 return TouchEventIsGeneratedHack(native_event) ? ui::ET_UNKNOWN : |
253 ui::ET_TOUCH_MOVED; | 254 ui::ET_TOUCH_MOVED; |
254 case XI_TouchEnd: | 255 case XI_TouchEnd: |
(...skipping 13 matching lines...) Expand all Loading... |
268 if (!(event->flags & XIPointerEmulated) && | 269 if (!(event->flags & XIPointerEmulated) && |
269 GetButtonMaskForX2Event(event)) | 270 GetButtonMaskForX2Event(event)) |
270 return ui::ET_TOUCH_MOVED; | 271 return ui::ET_TOUCH_MOVED; |
271 return ui::ET_UNKNOWN; | 272 return ui::ET_UNKNOWN; |
272 default: | 273 default: |
273 NOTREACHED(); | 274 NOTREACHED(); |
274 } | 275 } |
275 return ui::ET_UNKNOWN; | 276 return ui::ET_UNKNOWN; |
276 } | 277 } |
277 | 278 |
278 double GetTouchParamFromXEvent(XEvent* xev, | 279 double GetTouchParamFromXEvent(const XEvent* xev, |
279 ui::DeviceDataManagerX11::DataType val, | 280 ui::DeviceDataManagerX11::DataType val, |
280 double default_value) { | 281 double default_value) { |
281 ui::DeviceDataManagerX11::GetInstance()->GetEventData( | 282 ui::DeviceDataManagerX11::GetInstance()->GetEventData( |
282 *xev, val, &default_value); | 283 *xev, val, &default_value); |
283 return default_value; | 284 return default_value; |
284 } | 285 } |
285 | 286 |
286 void ScaleTouchRadius(XEvent* xev, double* radius) { | 287 void ScaleTouchRadius(const XEvent* xev, double* radius) { |
287 DCHECK_EQ(GenericEvent, xev->type); | 288 DCHECK_EQ(GenericEvent, xev->type); |
288 XIDeviceEvent* xiev = static_cast<XIDeviceEvent*>(xev->xcookie.data); | 289 XIDeviceEvent* xiev = static_cast<XIDeviceEvent*>(xev->xcookie.data); |
289 ui::DeviceDataManagerX11::GetInstance()->ApplyTouchRadiusScale( | 290 ui::DeviceDataManagerX11::GetInstance()->ApplyTouchRadiusScale( |
290 xiev->sourceid, radius); | 291 xiev->sourceid, radius); |
291 } | 292 } |
292 | 293 |
| 294 #if defined(USE_X11) |
293 unsigned int UpdateX11EventFlags(int ui_flags, unsigned int old_x_flags) { | 295 unsigned int UpdateX11EventFlags(int ui_flags, unsigned int old_x_flags) { |
294 static struct { | 296 static struct { |
295 int ui; | 297 int ui; |
296 int x; | 298 int x; |
297 } flags[] = { | 299 } flags[] = { |
298 {ui::EF_CONTROL_DOWN, ControlMask}, | 300 {ui::EF_CONTROL_DOWN, ControlMask}, |
299 {ui::EF_SHIFT_DOWN, ShiftMask}, | 301 {ui::EF_SHIFT_DOWN, ShiftMask}, |
300 {ui::EF_ALT_DOWN, Mod1Mask}, | 302 {ui::EF_ALT_DOWN, Mod1Mask}, |
301 {ui::EF_CAPS_LOCK_DOWN, LockMask}, | 303 {ui::EF_CAPS_LOCK_DOWN, LockMask}, |
302 {ui::EF_ALTGR_DOWN, Mod5Mask}, | 304 {ui::EF_ALTGR_DOWN, Mod5Mask}, |
(...skipping 20 matching lines...) Expand all Loading... |
323 return Button1; | 325 return Button1; |
324 case ui::EF_MIDDLE_MOUSE_BUTTON: | 326 case ui::EF_MIDDLE_MOUSE_BUTTON: |
325 return Button2; | 327 return Button2; |
326 case ui::EF_RIGHT_MOUSE_BUTTON: | 328 case ui::EF_RIGHT_MOUSE_BUTTON: |
327 return Button3; | 329 return Button3; |
328 default: | 330 default: |
329 return old_x_button; | 331 return old_x_button; |
330 } | 332 } |
331 NOTREACHED(); | 333 NOTREACHED(); |
332 } | 334 } |
| 335 #endif |
333 | 336 |
334 bool GetGestureTimes(const base::NativeEvent& native_event, | 337 bool GetGestureTimes(const XEvent* native_event, |
335 double* start_time, | 338 double* start_time, |
336 double* end_time) { | 339 double* end_time) { |
337 if (!ui::DeviceDataManagerX11::GetInstance()->HasGestureTimes(native_event)) | 340 if (!ui::DeviceDataManagerX11::GetInstance()->HasGestureTimes(native_event)) |
338 return false; | 341 return false; |
339 | 342 |
340 double start_time_, end_time_; | 343 double start_time_, end_time_; |
341 if (!start_time) | 344 if (!start_time) |
342 start_time = &start_time_; | 345 start_time = &start_time_; |
343 if (!end_time) | 346 if (!end_time) |
344 end_time = &end_time_; | 347 end_time = &end_time_; |
345 | 348 |
346 ui::DeviceDataManagerX11::GetInstance()->GetGestureTimes( | 349 ui::DeviceDataManagerX11::GetInstance()->GetGestureTimes( |
347 native_event, start_time, end_time); | 350 native_event, start_time, end_time); |
348 return true; | 351 return true; |
349 } | 352 } |
350 | 353 |
351 } // namespace | 354 } // namespace |
352 | 355 |
353 namespace ui { | 356 namespace ui { |
354 | 357 |
355 void UpdateDeviceList() { | 358 void UpdateDeviceList() { |
356 XDisplay* display = gfx::GetXDisplay(); | 359 XDisplay* display = gfx::GetXDisplay(); |
357 DeviceListCacheX11::GetInstance()->UpdateDeviceList(display); | 360 DeviceListCacheX11::GetInstance()->UpdateDeviceList(display); |
358 TouchFactory::GetInstance()->UpdateDeviceList(display); | 361 TouchFactory::GetInstance()->UpdateDeviceList(display); |
359 DeviceDataManagerX11::GetInstance()->UpdateDeviceList(display); | 362 DeviceDataManagerX11::GetInstance()->UpdateDeviceList(display); |
360 } | 363 } |
361 | 364 |
362 EventType EventTypeFromNative(const base::NativeEvent& native_event) { | 365 EventType EventTypeFromNative(const XEvent* native_event) { |
363 // Allow the DeviceDataManager to block the event. If blocked return | 366 // Allow the DeviceDataManager to block the event. If blocked return |
364 // ET_UNKNOWN as the type so this event will not be further processed. | 367 // ET_UNKNOWN as the type so this event will not be further processed. |
365 // NOTE: During some events unittests there is no device data manager. | 368 // NOTE: During some events unittests there is no device data manager. |
366 if (DeviceDataManager::HasInstance() && | 369 if (DeviceDataManager::HasInstance() && |
367 static_cast<DeviceDataManagerX11*>(DeviceDataManager::GetInstance())-> | 370 static_cast<DeviceDataManagerX11*>(DeviceDataManager::GetInstance())-> |
368 IsEventBlocked(native_event)) { | 371 IsEventBlocked(native_event)) { |
369 return ET_UNKNOWN; | 372 return ET_UNKNOWN; |
370 } | 373 } |
371 | 374 |
372 switch (native_event->type) { | 375 switch (native_event->type) { |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
451 case XI_KeyRelease: | 454 case XI_KeyRelease: |
452 return ET_KEY_RELEASED; | 455 return ET_KEY_RELEASED; |
453 } | 456 } |
454 } | 457 } |
455 default: | 458 default: |
456 break; | 459 break; |
457 } | 460 } |
458 return ET_UNKNOWN; | 461 return ET_UNKNOWN; |
459 } | 462 } |
460 | 463 |
461 int EventFlagsFromNative(const base::NativeEvent& native_event) { | 464 int EventFlagsFromNative(const XEvent* native_event) { |
462 switch (native_event->type) { | 465 switch (native_event->type) { |
463 case KeyPress: | 466 case KeyPress: |
464 case KeyRelease: { | 467 case KeyRelease: { |
465 XModifierStateWatcher::GetInstance()->UpdateStateFromXEvent(native_event); | 468 XModifierStateWatcher::GetInstance()->UpdateStateFromXEvent(native_event); |
466 return GetEventFlagsFromXKeyEvent(native_event); | 469 return GetEventFlagsFromXKeyEvent(native_event); |
467 } | 470 } |
468 case ButtonPress: | 471 case ButtonPress: |
469 case ButtonRelease: { | 472 case ButtonRelease: { |
470 int flags = GetEventFlagsFromXState(native_event->xbutton.state); | 473 int flags = GetEventFlagsFromXState(native_event->xbutton.state); |
471 const EventType type = EventTypeFromNative(native_event); | 474 const EventType type = EventTypeFromNative(native_event); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
516 XModifierStateWatcher::GetInstance()->UpdateStateFromXEvent( | 519 XModifierStateWatcher::GetInstance()->UpdateStateFromXEvent( |
517 native_event); | 520 native_event); |
518 return GetEventFlagsFromXGenericEvent(native_event); | 521 return GetEventFlagsFromXGenericEvent(native_event); |
519 } | 522 } |
520 } | 523 } |
521 } | 524 } |
522 } | 525 } |
523 return 0; | 526 return 0; |
524 } | 527 } |
525 | 528 |
526 base::TimeDelta EventTimeFromNative(const base::NativeEvent& native_event) { | 529 base::TimeDelta EventTimeFromNative(const XEvent* native_event) { |
527 switch(native_event->type) { | 530 switch(native_event->type) { |
528 case KeyPress: | 531 case KeyPress: |
529 case KeyRelease: | 532 case KeyRelease: |
530 return base::TimeDelta::FromMilliseconds(native_event->xkey.time); | 533 return base::TimeDelta::FromMilliseconds(native_event->xkey.time); |
531 case ButtonPress: | 534 case ButtonPress: |
532 case ButtonRelease: | 535 case ButtonRelease: |
533 return base::TimeDelta::FromMilliseconds(native_event->xbutton.time); | 536 return base::TimeDelta::FromMilliseconds(native_event->xbutton.time); |
534 break; | 537 break; |
535 case MotionNotify: | 538 case MotionNotify: |
536 return base::TimeDelta::FromMilliseconds(native_event->xmotion.time); | 539 return base::TimeDelta::FromMilliseconds(native_event->xmotion.time); |
(...skipping 18 matching lines...) Expand all Loading... |
555 static_cast<XIDeviceEvent*>(native_event->xcookie.data); | 558 static_cast<XIDeviceEvent*>(native_event->xcookie.data); |
556 return base::TimeDelta::FromMilliseconds(xide->time); | 559 return base::TimeDelta::FromMilliseconds(xide->time); |
557 } | 560 } |
558 break; | 561 break; |
559 } | 562 } |
560 } | 563 } |
561 NOTREACHED(); | 564 NOTREACHED(); |
562 return base::TimeDelta(); | 565 return base::TimeDelta(); |
563 } | 566 } |
564 | 567 |
565 gfx::Point EventLocationFromNative(const base::NativeEvent& native_event) { | 568 gfx::Point EventLocationFromNative(const XEvent* native_event) { |
566 switch (native_event->type) { | 569 switch (native_event->type) { |
567 case EnterNotify: | 570 case EnterNotify: |
568 case LeaveNotify: | 571 case LeaveNotify: |
569 return gfx::Point(native_event->xcrossing.x, native_event->xcrossing.y); | 572 return gfx::Point(native_event->xcrossing.x, native_event->xcrossing.y); |
570 case ButtonPress: | 573 case ButtonPress: |
571 case ButtonRelease: | 574 case ButtonRelease: |
572 return gfx::Point(native_event->xbutton.x, native_event->xbutton.y); | 575 return gfx::Point(native_event->xbutton.x, native_event->xbutton.y); |
573 case MotionNotify: | 576 case MotionNotify: |
574 return gfx::Point(native_event->xmotion.x, native_event->xmotion.y); | 577 return gfx::Point(native_event->xmotion.x, native_event->xmotion.y); |
575 case GenericEvent: { | 578 case GenericEvent: { |
(...skipping 12 matching lines...) Expand all Loading... |
588 default: | 591 default: |
589 break; | 592 break; |
590 } | 593 } |
591 #endif // defined(OS_CHROMEOS) | 594 #endif // defined(OS_CHROMEOS) |
592 return gfx::Point(static_cast<int>(x), static_cast<int>(y)); | 595 return gfx::Point(static_cast<int>(x), static_cast<int>(y)); |
593 } | 596 } |
594 } | 597 } |
595 return gfx::Point(); | 598 return gfx::Point(); |
596 } | 599 } |
597 | 600 |
598 gfx::Point EventSystemLocationFromNative( | 601 gfx::Point EventSystemLocationFromNative(const XEvent* native_event) { |
599 const base::NativeEvent& native_event) { | |
600 switch (native_event->type) { | 602 switch (native_event->type) { |
601 case EnterNotify: | 603 case EnterNotify: |
602 case LeaveNotify: { | 604 case LeaveNotify: { |
603 return gfx::Point(native_event->xcrossing.x_root, | 605 return gfx::Point(native_event->xcrossing.x_root, |
604 native_event->xcrossing.y_root); | 606 native_event->xcrossing.y_root); |
605 } | 607 } |
606 case ButtonPress: | 608 case ButtonPress: |
607 case ButtonRelease: { | 609 case ButtonRelease: { |
608 return gfx::Point(native_event->xbutton.x_root, | 610 return gfx::Point(native_event->xbutton.x_root, |
609 native_event->xbutton.y_root); | 611 native_event->xbutton.y_root); |
610 } | 612 } |
611 case MotionNotify: { | 613 case MotionNotify: { |
612 return gfx::Point(native_event->xmotion.x_root, | 614 return gfx::Point(native_event->xmotion.x_root, |
613 native_event->xmotion.y_root); | 615 native_event->xmotion.y_root); |
614 } | 616 } |
615 case GenericEvent: { | 617 case GenericEvent: { |
616 XIDeviceEvent* xievent = | 618 XIDeviceEvent* xievent = |
617 static_cast<XIDeviceEvent*>(native_event->xcookie.data); | 619 static_cast<XIDeviceEvent*>(native_event->xcookie.data); |
618 return gfx::Point(xievent->root_x, xievent->root_y); | 620 return gfx::Point(xievent->root_x, xievent->root_y); |
619 } | 621 } |
620 } | 622 } |
621 | 623 |
622 return gfx::Point(); | 624 return gfx::Point(); |
623 } | 625 } |
624 | 626 |
625 int EventButtonFromNative(const base::NativeEvent& native_event) { | 627 int EventButtonFromNative(const XEvent* native_event) { |
626 CHECK_EQ(GenericEvent, native_event->type); | 628 CHECK_EQ(GenericEvent, native_event->type); |
627 XIDeviceEvent* xievent = | 629 XIDeviceEvent* xievent = |
628 static_cast<XIDeviceEvent*>(native_event->xcookie.data); | 630 static_cast<XIDeviceEvent*>(native_event->xcookie.data); |
629 int button = xievent->detail; | 631 int button = xievent->detail; |
630 | 632 |
631 return (xievent->sourceid == xievent->deviceid) ? | 633 return (xievent->sourceid == xievent->deviceid) ? |
632 DeviceDataManagerX11::GetInstance()->GetMappedButton(button) : button; | 634 DeviceDataManagerX11::GetInstance()->GetMappedButton(button) : button; |
633 } | 635 } |
634 | 636 |
635 KeyboardCode KeyboardCodeFromNative(const base::NativeEvent& native_event) { | 637 KeyboardCode KeyboardCodeFromNative(const XEvent* native_event) { |
636 return KeyboardCodeFromXKeyEvent(native_event); | 638 return KeyboardCodeFromXKeyEvent(native_event); |
637 } | 639 } |
638 | 640 |
639 const char* CodeFromNative(const base::NativeEvent& native_event) { | 641 const char* CodeFromNative(const XEvent* native_event) { |
640 return CodeFromXEvent(native_event); | 642 return CodeFromXEvent(native_event); |
641 } | 643 } |
642 | 644 |
643 uint32 PlatformKeycodeFromNative(const base::NativeEvent& native_event) { | 645 uint32 PlatformKeycodeFromNative(const XEvent* native_event) { |
644 XKeyEvent* xkey = NULL; | 646 const XKeyEvent* xkey = NULL; |
645 XEvent xkey_from_xi2; | 647 XEvent xkey_from_xi2; |
646 switch (native_event->type) { | 648 switch (native_event->type) { |
647 case KeyPress: | 649 case KeyPress: |
648 case KeyRelease: | 650 case KeyRelease: |
649 xkey = &native_event->xkey; | 651 xkey = &native_event->xkey; |
650 break; | 652 break; |
651 case GenericEvent: { | 653 case GenericEvent: { |
652 XIDeviceEvent* xievent = | 654 XIDeviceEvent* xievent = |
653 static_cast<XIDeviceEvent*>(native_event->xcookie.data); | 655 static_cast<XIDeviceEvent*>(native_event->xcookie.data); |
654 switch (xievent->evtype) { | 656 switch (xievent->evtype) { |
655 case XI_KeyPress: | 657 case XI_KeyPress: |
656 case XI_KeyRelease: | 658 case XI_KeyRelease: |
657 // Build an XKeyEvent corresponding to the XI2 event, | 659 // Build an XKeyEvent corresponding to the XI2 event, |
658 // so that we can call XLookupString on it. | 660 // so that we can call XLookupString on it. |
659 InitXKeyEventFromXIDeviceEvent(*native_event, &xkey_from_xi2); | 661 InitXKeyEventFromXIDeviceEvent(*native_event, &xkey_from_xi2); |
660 xkey = &xkey_from_xi2.xkey; | 662 xkey = &xkey_from_xi2.xkey; |
661 break; | 663 break; |
662 default: | 664 default: |
663 NOTREACHED(); | 665 NOTREACHED(); |
664 break; | 666 break; |
665 } | 667 } |
666 break; | 668 break; |
667 } | 669 } |
668 default: | 670 default: |
669 NOTREACHED(); | 671 NOTREACHED(); |
670 break; | 672 break; |
671 } | 673 } |
672 KeySym keysym = XK_VoidSymbol; | 674 KeySym keysym = XK_VoidSymbol; |
673 if (xkey) | 675 if (xkey) |
674 XLookupString(xkey, NULL, 0, &keysym, NULL); | 676 XLookupString(const_cast<XKeyEvent*>(xkey), NULL, 0, &keysym, NULL); |
675 return keysym; | 677 return keysym; |
676 } | 678 } |
677 | 679 |
678 bool IsCharFromNative(const base::NativeEvent& native_event) { | 680 bool IsCharFromNative(const XEvent* native_event) { |
679 return false; | 681 return false; |
680 } | 682 } |
681 | 683 |
682 int GetChangedMouseButtonFlagsFromNative( | 684 int GetChangedMouseButtonFlagsFromNative(const XEvent* native_event) { |
683 const base::NativeEvent& native_event) { | |
684 switch (native_event->type) { | 685 switch (native_event->type) { |
685 case ButtonPress: | 686 case ButtonPress: |
686 case ButtonRelease: | 687 case ButtonRelease: |
687 return GetEventFlagsFromXState(native_event->xbutton.state); | 688 return GetEventFlagsFromXState(native_event->xbutton.state); |
688 case GenericEvent: { | 689 case GenericEvent: { |
689 XIDeviceEvent* xievent = | 690 XIDeviceEvent* xievent = |
690 static_cast<XIDeviceEvent*>(native_event->xcookie.data); | 691 static_cast<XIDeviceEvent*>(native_event->xcookie.data); |
691 switch (xievent->evtype) { | 692 switch (xievent->evtype) { |
692 case XI_ButtonPress: | 693 case XI_ButtonPress: |
693 case XI_ButtonRelease: | 694 case XI_ButtonRelease: |
694 return GetEventFlagsForButton(EventButtonFromNative(native_event)); | 695 return GetEventFlagsForButton(EventButtonFromNative(native_event)); |
695 default: | 696 default: |
696 break; | 697 break; |
697 } | 698 } |
698 } | 699 } |
699 default: | 700 default: |
700 break; | 701 break; |
701 } | 702 } |
702 return 0; | 703 return 0; |
703 } | 704 } |
704 | 705 |
705 gfx::Vector2d GetMouseWheelOffset(const base::NativeEvent& native_event) { | 706 gfx::Vector2d GetMouseWheelOffset(const XEvent* native_event) { |
706 float x_offset, y_offset; | 707 float x_offset, y_offset; |
707 if (GetScrollOffsets( | 708 if (GetScrollOffsets( |
708 native_event, &x_offset, &y_offset, NULL, NULL, NULL)) { | 709 native_event, &x_offset, &y_offset, NULL, NULL, NULL)) { |
709 return gfx::Vector2d(static_cast<int>(x_offset), | 710 return gfx::Vector2d(static_cast<int>(x_offset), |
710 static_cast<int>(y_offset)); | 711 static_cast<int>(y_offset)); |
711 } | 712 } |
712 | 713 |
713 int button = native_event->type == GenericEvent ? | 714 int button = native_event->type == GenericEvent ? |
714 EventButtonFromNative(native_event) : native_event->xbutton.button; | 715 EventButtonFromNative(native_event) : native_event->xbutton.button; |
715 | 716 |
716 switch (button) { | 717 switch (button) { |
717 case 4: | 718 case 4: |
718 return gfx::Vector2d(0, kWheelScrollAmount); | 719 return gfx::Vector2d(0, kWheelScrollAmount); |
719 case 5: | 720 case 5: |
720 return gfx::Vector2d(0, -kWheelScrollAmount); | 721 return gfx::Vector2d(0, -kWheelScrollAmount); |
721 case 6: | 722 case 6: |
722 return gfx::Vector2d(kWheelScrollAmount, 0); | 723 return gfx::Vector2d(kWheelScrollAmount, 0); |
723 case 7: | 724 case 7: |
724 return gfx::Vector2d(-kWheelScrollAmount, 0); | 725 return gfx::Vector2d(-kWheelScrollAmount, 0); |
725 default: | 726 default: |
726 return gfx::Vector2d(); | 727 return gfx::Vector2d(); |
727 } | 728 } |
728 } | 729 } |
729 | 730 |
730 base::NativeEvent CopyNativeEvent(const base::NativeEvent& event) { | 731 XEvent* CopyNativeEvent(const XEvent* event) { |
731 if (!event || event->type == GenericEvent) | 732 if (!event || event->type == GenericEvent) |
732 return NULL; | 733 return NULL; |
733 XEvent* copy = new XEvent; | 734 XEvent* copy = new XEvent; |
734 *copy = *event; | 735 *copy = *event; |
735 return copy; | 736 return copy; |
736 } | 737 } |
737 | 738 |
738 void ReleaseCopiedNativeEvent(const base::NativeEvent& event) { | 739 void ReleaseCopiedNativeEvent(const XEvent* event) { |
739 delete event; | 740 delete event; |
740 } | 741 } |
741 | 742 |
742 void IncrementTouchIdRefCount(const base::NativeEvent& xev) { | 743 void IncrementTouchIdRefCount(const XEvent* xev) { |
743 ui::DeviceDataManagerX11* manager = ui::DeviceDataManagerX11::GetInstance(); | 744 ui::DeviceDataManagerX11* manager = ui::DeviceDataManagerX11::GetInstance(); |
744 double tracking_id; | 745 double tracking_id; |
745 if (!manager->GetEventData( | 746 if (!manager->GetEventData( |
746 *xev, ui::DeviceDataManagerX11::DT_TOUCH_TRACKING_ID, &tracking_id)) { | 747 *xev, ui::DeviceDataManagerX11::DT_TOUCH_TRACKING_ID, &tracking_id)) { |
747 return; | 748 return; |
748 } | 749 } |
749 | 750 |
750 ui::TouchFactory* factory = ui::TouchFactory::GetInstance(); | 751 ui::TouchFactory* factory = ui::TouchFactory::GetInstance(); |
751 factory->AcquireSlotForTrackingID(tracking_id); | 752 factory->AcquireSlotForTrackingID(tracking_id); |
752 } | 753 } |
753 | 754 |
754 void ClearTouchIdIfReleased(const base::NativeEvent& xev) { | 755 void ClearTouchIdIfReleased(const XEvent* xev) { |
755 ui::EventType type = ui::EventTypeFromNative(xev); | 756 ui::EventType type = ui::EventTypeFromNative(xev); |
756 if (type == ui::ET_TOUCH_CANCELLED || | 757 if (type == ui::ET_TOUCH_CANCELLED || |
757 type == ui::ET_TOUCH_RELEASED) { | 758 type == ui::ET_TOUCH_RELEASED) { |
758 ui::TouchFactory* factory = ui::TouchFactory::GetInstance(); | 759 ui::TouchFactory* factory = ui::TouchFactory::GetInstance(); |
759 ui::DeviceDataManagerX11* manager = ui::DeviceDataManagerX11::GetInstance(); | 760 ui::DeviceDataManagerX11* manager = ui::DeviceDataManagerX11::GetInstance(); |
760 double tracking_id; | 761 double tracking_id; |
761 if (manager->GetEventData( | 762 if (manager->GetEventData( |
762 *xev, ui::DeviceDataManagerX11::DT_TOUCH_TRACKING_ID, &tracking_id)) { | 763 *xev, ui::DeviceDataManagerX11::DT_TOUCH_TRACKING_ID, &tracking_id)) { |
763 factory->ReleaseSlotForTrackingID(tracking_id); | 764 factory->ReleaseSlotForTrackingID(tracking_id); |
764 } | 765 } |
765 } | 766 } |
766 } | 767 } |
767 | 768 |
768 int GetTouchId(const base::NativeEvent& xev) { | 769 int GetTouchId(const XEvent* xev) { |
769 double slot = 0; | 770 double slot = 0; |
770 ui::DeviceDataManagerX11* manager = ui::DeviceDataManagerX11::GetInstance(); | 771 ui::DeviceDataManagerX11* manager = ui::DeviceDataManagerX11::GetInstance(); |
771 double tracking_id; | 772 double tracking_id; |
772 if (!manager->GetEventData( | 773 if (!manager->GetEventData( |
773 *xev, ui::DeviceDataManagerX11::DT_TOUCH_TRACKING_ID, &tracking_id)) { | 774 *xev, ui::DeviceDataManagerX11::DT_TOUCH_TRACKING_ID, &tracking_id)) { |
774 LOG(ERROR) << "Could not get the tracking ID for the event. Using 0."; | 775 LOG(ERROR) << "Could not get the tracking ID for the event. Using 0."; |
775 } else { | 776 } else { |
776 ui::TouchFactory* factory = ui::TouchFactory::GetInstance(); | 777 ui::TouchFactory* factory = ui::TouchFactory::GetInstance(); |
777 slot = factory->GetSlotForTrackingID(tracking_id); | 778 slot = factory->GetSlotForTrackingID(tracking_id); |
778 } | 779 } |
779 return slot; | 780 return slot; |
780 } | 781 } |
781 | 782 |
782 float GetTouchRadiusX(const base::NativeEvent& native_event) { | 783 float GetTouchRadiusX(const XEvent* native_event) { |
783 double radius = GetTouchParamFromXEvent(native_event, | 784 double radius = GetTouchParamFromXEvent(native_event, |
784 ui::DeviceDataManagerX11::DT_TOUCH_MAJOR, 0.0) / 2.0; | 785 ui::DeviceDataManagerX11::DT_TOUCH_MAJOR, 0.0) / 2.0; |
785 ScaleTouchRadius(native_event, &radius); | 786 ScaleTouchRadius(native_event, &radius); |
786 return radius; | 787 return radius; |
787 } | 788 } |
788 | 789 |
789 float GetTouchRadiusY(const base::NativeEvent& native_event) { | 790 float GetTouchRadiusY(const XEvent* native_event) { |
790 double radius = GetTouchParamFromXEvent(native_event, | 791 double radius = GetTouchParamFromXEvent(native_event, |
791 ui::DeviceDataManagerX11::DT_TOUCH_MINOR, 0.0) / 2.0; | 792 ui::DeviceDataManagerX11::DT_TOUCH_MINOR, 0.0) / 2.0; |
792 ScaleTouchRadius(native_event, &radius); | 793 ScaleTouchRadius(native_event, &radius); |
793 return radius; | 794 return radius; |
794 } | 795 } |
795 | 796 |
796 float GetTouchAngle(const base::NativeEvent& native_event) { | 797 float GetTouchAngle(const XEvent* native_event) { |
797 return GetTouchParamFromXEvent(native_event, | 798 return GetTouchParamFromXEvent(native_event, |
798 ui::DeviceDataManagerX11::DT_TOUCH_ORIENTATION, 0.0) / 2.0; | 799 ui::DeviceDataManagerX11::DT_TOUCH_ORIENTATION, 0.0) / 2.0; |
799 } | 800 } |
800 | 801 |
801 float GetTouchForce(const base::NativeEvent& native_event) { | 802 float GetTouchForce(const XEvent* native_event) { |
802 double force = 0.0; | 803 double force = 0.0; |
803 force = GetTouchParamFromXEvent(native_event, | 804 force = GetTouchParamFromXEvent(native_event, |
804 ui::DeviceDataManagerX11::DT_TOUCH_PRESSURE, 0.0); | 805 ui::DeviceDataManagerX11::DT_TOUCH_PRESSURE, 0.0); |
805 unsigned int deviceid = | 806 unsigned int deviceid = |
806 static_cast<XIDeviceEvent*>(native_event->xcookie.data)->sourceid; | 807 static_cast<XIDeviceEvent*>(native_event->xcookie.data)->sourceid; |
807 // Force is normalized to fall into [0, 1] | 808 // Force is normalized to fall into [0, 1] |
808 if (!ui::DeviceDataManagerX11::GetInstance()->NormalizeData( | 809 if (!ui::DeviceDataManagerX11::GetInstance()->NormalizeData( |
809 deviceid, ui::DeviceDataManagerX11::DT_TOUCH_PRESSURE, &force)) | 810 deviceid, ui::DeviceDataManagerX11::DT_TOUCH_PRESSURE, &force)) |
810 force = 0.0; | 811 force = 0.0; |
811 return force; | 812 return force; |
812 } | 813 } |
813 | 814 |
814 bool GetScrollOffsets(const base::NativeEvent& native_event, | 815 bool GetScrollOffsets(const XEvent* native_event, |
815 float* x_offset, | 816 float* x_offset, |
816 float* y_offset, | 817 float* y_offset, |
817 float* x_offset_ordinal, | 818 float* x_offset_ordinal, |
818 float* y_offset_ordinal, | 819 float* y_offset_ordinal, |
819 int* finger_count) { | 820 int* finger_count) { |
820 if (!DeviceDataManagerX11::GetInstance()->IsScrollEvent(native_event)) | 821 if (!DeviceDataManagerX11::GetInstance()->IsScrollEvent(native_event)) |
821 return false; | 822 return false; |
822 | 823 |
823 // Temp values to prevent passing NULLs to DeviceDataManager. | 824 // Temp values to prevent passing NULLs to DeviceDataManager. |
824 float x_offset_, y_offset_; | 825 float x_offset_, y_offset_; |
(...skipping 11 matching lines...) Expand all Loading... |
836 finger_count = &finger_count_; | 837 finger_count = &finger_count_; |
837 | 838 |
838 DeviceDataManagerX11::GetInstance()->GetScrollOffsets( | 839 DeviceDataManagerX11::GetInstance()->GetScrollOffsets( |
839 native_event, | 840 native_event, |
840 x_offset, y_offset, | 841 x_offset, y_offset, |
841 x_offset_ordinal, y_offset_ordinal, | 842 x_offset_ordinal, y_offset_ordinal, |
842 finger_count); | 843 finger_count); |
843 return true; | 844 return true; |
844 } | 845 } |
845 | 846 |
846 bool GetFlingData(const base::NativeEvent& native_event, | 847 bool GetFlingData(const XEvent* native_event, |
847 float* vx, | 848 float* vx, |
848 float* vy, | 849 float* vy, |
849 float* vx_ordinal, | 850 float* vx_ordinal, |
850 float* vy_ordinal, | 851 float* vy_ordinal, |
851 bool* is_cancel) { | 852 bool* is_cancel) { |
852 if (!DeviceDataManagerX11::GetInstance()->IsFlingEvent(native_event)) | 853 if (!DeviceDataManagerX11::GetInstance()->IsFlingEvent(native_event)) |
853 return false; | 854 return false; |
854 | 855 |
855 float vx_, vy_; | 856 float vx_, vy_; |
856 float vx_ordinal_, vy_ordinal_; | 857 float vx_ordinal_, vy_ordinal_; |
857 bool is_cancel_; | 858 bool is_cancel_; |
858 if (!vx) | 859 if (!vx) |
859 vx = &vx_; | 860 vx = &vx_; |
860 if (!vy) | 861 if (!vy) |
861 vy = &vy_; | 862 vy = &vy_; |
862 if (!vx_ordinal) | 863 if (!vx_ordinal) |
863 vx_ordinal = &vx_ordinal_; | 864 vx_ordinal = &vx_ordinal_; |
864 if (!vy_ordinal) | 865 if (!vy_ordinal) |
865 vy_ordinal = &vy_ordinal_; | 866 vy_ordinal = &vy_ordinal_; |
866 if (!is_cancel) | 867 if (!is_cancel) |
867 is_cancel = &is_cancel_; | 868 is_cancel = &is_cancel_; |
868 | 869 |
869 DeviceDataManagerX11::GetInstance()->GetFlingData( | 870 DeviceDataManagerX11::GetInstance()->GetFlingData( |
870 native_event, vx, vy, vx_ordinal, vy_ordinal, is_cancel); | 871 native_event, vx, vy, vx_ordinal, vy_ordinal, is_cancel); |
871 return true; | 872 return true; |
872 } | 873 } |
873 | 874 |
| 875 #if defined(USE_X11) |
874 void UpdateX11EventForFlags(Event* event) { | 876 void UpdateX11EventForFlags(Event* event) { |
875 XEvent* xev = event->native_event(); | 877 XEvent* xev = event->native_event(); |
876 if (!xev) | 878 if (!xev) |
877 return; | 879 return; |
878 switch (xev->type) { | 880 switch (xev->type) { |
879 case KeyPress: | 881 case KeyPress: |
880 case KeyRelease: | 882 case KeyRelease: |
881 xev->xkey.state = UpdateX11EventFlags(event->flags(), xev->xkey.state); | 883 xev->xkey.state = UpdateX11EventFlags(event->flags(), xev->xkey.state); |
882 break; | 884 break; |
883 case ButtonPress: | 885 case ButtonPress: |
(...skipping 28 matching lines...) Expand all Loading... |
912 CHECK(xievent && (xievent->evtype == XI_ButtonPress || | 914 CHECK(xievent && (xievent->evtype == XI_ButtonPress || |
913 xievent->evtype == XI_ButtonRelease)); | 915 xievent->evtype == XI_ButtonRelease)); |
914 xievent->detail = | 916 xievent->detail = |
915 UpdateX11EventButton(event->changed_button_flags(), xievent->detail); | 917 UpdateX11EventButton(event->changed_button_flags(), xievent->detail); |
916 break; | 918 break; |
917 } | 919 } |
918 default: | 920 default: |
919 break; | 921 break; |
920 } | 922 } |
921 } | 923 } |
| 924 #endif |
| 925 |
| 926 #if defined(USE_OZONE) && !defined(USE_X11) |
| 927 |
| 928 base::NativeEvent TranslateXI2Event(XEvent* xev) { |
| 929 XIDeviceEvent* xievent = static_cast<XIDeviceEvent*>(xev->xcookie.data); |
| 930 EventType event_type = EventTypeFromNative(xev); |
| 931 gfx::PointF location = gfx::PointF(xievent->event_x, xievent->event_y); |
| 932 gfx::PointF root_location = gfx::PointF(xievent->root_x, xievent->root_y); |
| 933 int flags = EventFlagsFromNative(xev); |
| 934 switch (event_type) { |
| 935 case ET_KEY_PRESSED: |
| 936 case ET_KEY_RELEASED: |
| 937 return new KeyEvent(event_type, KeyboardCodeFromNative(xev), flags); |
| 938 case ET_MOUSE_PRESSED: |
| 939 case ET_MOUSE_MOVED: |
| 940 case ET_MOUSE_DRAGGED: |
| 941 case ET_MOUSE_RELEASED: |
| 942 return new MouseEvent(event_type, location, root_location, flags, |
| 943 GetChangedMouseButtonFlagsFromNative(xev)); |
| 944 case ET_MOUSEWHEEL: |
| 945 return new MouseWheelEvent(GetMouseWheelOffset(xev), location, |
| 946 root_location, flags, |
| 947 GetChangedMouseButtonFlagsFromNative(xev)); |
| 948 case ET_SCROLL_FLING_START: |
| 949 case ET_SCROLL_FLING_CANCEL: { |
| 950 float x_offset, y_offset, x_offset_ordinal, y_offset_ordinal; |
| 951 GetFlingData(xev, &x_offset, &y_offset, &x_offset_ordinal, |
| 952 &y_offset_ordinal, nullptr); |
| 953 return new ScrollEvent(event_type, location, EventTimeFromNative(xev), |
| 954 flags, x_offset, y_offset, x_offset_ordinal, |
| 955 y_offset_ordinal, 0); |
| 956 } |
| 957 case ET_SCROLL: { |
| 958 float x_offset, y_offset, x_offset_ordinal, y_offset_ordinal; |
| 959 int finger_count; |
| 960 GetScrollOffsets(xev, &x_offset, &y_offset, &x_offset_ordinal, |
| 961 &y_offset_ordinal, &finger_count); |
| 962 return new ScrollEvent(event_type, location, EventTimeFromNative(xev), |
| 963 flags, x_offset, y_offset, x_offset_ordinal, |
| 964 y_offset_ordinal, finger_count); |
| 965 } |
| 966 case ET_TOUCH_MOVED: |
| 967 case ET_TOUCH_PRESSED: |
| 968 case ET_TOUCH_CANCELLED: |
| 969 case ET_TOUCH_RELEASED: |
| 970 return new TouchEvent(event_type, location, GetTouchId(xev), |
| 971 EventTimeFromNative(xev)); |
| 972 case ET_UNKNOWN: |
| 973 return nullptr; |
| 974 default: |
| 975 break; |
| 976 } |
| 977 return nullptr; |
| 978 } |
| 979 |
| 980 base::NativeEvent TranslateXEventToNativeEvent(XEvent* xev) { |
| 981 int flags = EventFlagsFromNative(xev); |
| 982 switch (xev->type) { |
| 983 case LeaveNotify: |
| 984 case EnterNotify: |
| 985 // EnterNotify creates ET_MOUSE_MOVED. Mark as synthesized as this is |
| 986 // not real mouse move event. |
| 987 // int flags = GetEventFlagsFromXState(xev->xcrossing.state); |
| 988 if (xev->type == EnterNotify) |
| 989 flags |= EF_IS_SYNTHESIZED; |
| 990 return new MouseEvent( |
| 991 ET_MOUSE_MOVED, gfx::PointF(xev->xcrossing.x, xev->xcrossing.y), |
| 992 gfx::PointF(xev->xcrossing.x_root, xev->xcrossing.y_root), flags, 0); |
| 993 |
| 994 case KeyPress: |
| 995 case KeyRelease: |
| 996 return new KeyEvent(EventTypeFromNative(xev), KeyboardCodeFromNative(xev), |
| 997 flags); |
| 998 |
| 999 case ButtonPress: |
| 1000 case ButtonRelease: { |
| 1001 gfx::PointF location = gfx::PointF(xev->xbutton.x, xev->xbutton.y); |
| 1002 gfx::PointF root_location = |
| 1003 gfx::PointF(xev->xbutton.x_root, xev->xbutton.y_root); |
| 1004 switch (EventTypeFromNative(xev)) { |
| 1005 case ET_MOUSEWHEEL: |
| 1006 return new MouseWheelEvent(GetMouseWheelOffset(xev), location, |
| 1007 root_location, flags, 0); |
| 1008 case ET_MOUSE_PRESSED: |
| 1009 case ET_MOUSE_RELEASED: |
| 1010 return new MouseEvent(EventTypeFromNative(xev), location, |
| 1011 root_location, flags, |
| 1012 GetChangedMouseButtonFlagsFromNative(xev)); |
| 1013 case ET_UNKNOWN: |
| 1014 // No event is created for X11-release events for mouse-wheel |
| 1015 // buttons. |
| 1016 break; |
| 1017 default: |
| 1018 NOTREACHED(); |
| 1019 } |
| 1020 break; |
| 1021 } |
| 1022 |
| 1023 case FocusOut: |
| 1024 case Expose: |
| 1025 case ConfigureNotify: |
| 1026 case ClientMessage: |
| 1027 return new CustomEvent(ET_X_RAW_EVENT, base::TimeDelta(), xev); |
| 1028 |
| 1029 case GenericEvent: |
| 1030 return TranslateXI2Event(xev); |
| 1031 } |
| 1032 return nullptr; |
| 1033 } |
| 1034 #endif |
922 | 1035 |
923 } // namespace ui | 1036 } // namespace ui |
OLD | NEW |