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