| 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/event_constants.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> |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 private: | 102 private: |
| 103 friend struct DefaultSingletonTraits<XModifierStateWatcher>; | 103 friend struct DefaultSingletonTraits<XModifierStateWatcher>; |
| 104 | 104 |
| 105 XModifierStateWatcher() : state_(0) { } | 105 XModifierStateWatcher() : state_(0) { } |
| 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 #if defined(USE_XI2_MT) | |
| 113 // Detects if a touch event is a driver-generated 'special event'. | 112 // Detects if a touch event is a driver-generated 'special event'. |
| 114 // 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 |
| 115 // location (0, 0). | 114 // location (0, 0). |
| 116 // 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 |
| 117 bool TouchEventIsGeneratedHack(const base::NativeEvent& native_event) { | 116 bool TouchEventIsGeneratedHack(const base::NativeEvent& native_event) { |
| 118 XIDeviceEvent* event = | 117 XIDeviceEvent* event = |
| 119 static_cast<XIDeviceEvent*>(native_event->xcookie.data); | 118 static_cast<XIDeviceEvent*>(native_event->xcookie.data); |
| 120 CHECK(event->evtype == XI_TouchBegin || | 119 CHECK(event->evtype == XI_TouchBegin || |
| 121 event->evtype == XI_TouchUpdate || | 120 event->evtype == XI_TouchUpdate || |
| 122 event->evtype == XI_TouchEnd); | 121 event->evtype == XI_TouchEnd); |
| 123 | 122 |
| 124 // Force is normalized to [0, 1]. | 123 // Force is normalized to [0, 1]. |
| 125 if (ui::GetTouchForce(native_event) < 1.0f) | 124 if (ui::GetTouchForce(native_event) < 1.0f) |
| 126 return false; | 125 return false; |
| 127 | 126 |
| 128 if (ui::EventLocationFromNative(native_event) != gfx::Point()) | 127 if (ui::EventLocationFromNative(native_event) != gfx::Point()) |
| 129 return false; | 128 return false; |
| 130 | 129 |
| 131 // Radius is in pixels, and the valuator is the diameter in pixels. | 130 // Radius is in pixels, and the valuator is the diameter in pixels. |
| 132 double radius = ui::GetTouchRadiusX(native_event), min, max; | 131 double radius = ui::GetTouchRadiusX(native_event), min, max; |
| 133 unsigned int deviceid = | 132 unsigned int deviceid = |
| 134 static_cast<XIDeviceEvent*>(native_event->xcookie.data)->sourceid; | 133 static_cast<XIDeviceEvent*>(native_event->xcookie.data)->sourceid; |
| 135 if (!ui::DeviceDataManagerX11::GetInstance()->GetDataRange( | 134 if (!ui::DeviceDataManagerX11::GetInstance()->GetDataRange( |
| 136 deviceid, ui::DeviceDataManagerX11::DT_TOUCH_MAJOR, &min, &max)) { | 135 deviceid, ui::DeviceDataManagerX11::DT_TOUCH_MAJOR, &min, &max)) { |
| 137 return false; | 136 return false; |
| 138 } | 137 } |
| 139 | 138 |
| 140 return radius * 2 == max; | 139 return radius * 2 == max; |
| 141 } | 140 } |
| 142 #endif | |
| 143 | 141 |
| 144 int GetEventFlagsFromXState(unsigned int state) { | 142 int GetEventFlagsFromXState(unsigned int state) { |
| 145 int flags = 0; | 143 int flags = 0; |
| 146 if (state & ControlMask) | 144 if (state & ControlMask) |
| 147 flags |= ui::EF_CONTROL_DOWN; | 145 flags |= ui::EF_CONTROL_DOWN; |
| 148 if (state & ShiftMask) | 146 if (state & ShiftMask) |
| 149 flags |= ui::EF_SHIFT_DOWN; | 147 flags |= ui::EF_SHIFT_DOWN; |
| 150 if (state & Mod1Mask) | 148 if (state & Mod1Mask) |
| 151 flags |= ui::EF_ALT_DOWN; | 149 flags |= ui::EF_ALT_DOWN; |
| 152 if (state & LockMask) | 150 if (state & LockMask) |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 ui::DeviceDataManagerX11::GetInstance()->GetMappedButton(i) : i; | 237 ui::DeviceDataManagerX11::GetInstance()->GetMappedButton(i) : i; |
| 240 buttonflags |= GetEventFlagsForButton(button); | 238 buttonflags |= GetEventFlagsForButton(button); |
| 241 } | 239 } |
| 242 } | 240 } |
| 243 return buttonflags; | 241 return buttonflags; |
| 244 } | 242 } |
| 245 | 243 |
| 246 ui::EventType GetTouchEventType(const base::NativeEvent& native_event) { | 244 ui::EventType GetTouchEventType(const base::NativeEvent& native_event) { |
| 247 XIDeviceEvent* event = | 245 XIDeviceEvent* event = |
| 248 static_cast<XIDeviceEvent*>(native_event->xcookie.data); | 246 static_cast<XIDeviceEvent*>(native_event->xcookie.data); |
| 249 #if defined(USE_XI2_MT) | |
| 250 switch(event->evtype) { | 247 switch(event->evtype) { |
| 251 case XI_TouchBegin: | 248 case XI_TouchBegin: |
| 252 return TouchEventIsGeneratedHack(native_event) ? ui::ET_UNKNOWN : | 249 return TouchEventIsGeneratedHack(native_event) ? ui::ET_UNKNOWN : |
| 253 ui::ET_TOUCH_PRESSED; | 250 ui::ET_TOUCH_PRESSED; |
| 254 case XI_TouchUpdate: | 251 case XI_TouchUpdate: |
| 255 return TouchEventIsGeneratedHack(native_event) ? ui::ET_UNKNOWN : | 252 return TouchEventIsGeneratedHack(native_event) ? ui::ET_UNKNOWN : |
| 256 ui::ET_TOUCH_MOVED; | 253 ui::ET_TOUCH_MOVED; |
| 257 case XI_TouchEnd: | 254 case XI_TouchEnd: |
| 258 return TouchEventIsGeneratedHack(native_event) ? ui::ET_TOUCH_CANCELLED : | 255 return TouchEventIsGeneratedHack(native_event) ? ui::ET_TOUCH_CANCELLED : |
| 259 ui::ET_TOUCH_RELEASED; | 256 ui::ET_TOUCH_RELEASED; |
| 260 } | 257 } |
| 261 #endif // defined(USE_XI2_MT) | |
| 262 | 258 |
| 263 DCHECK(ui::TouchFactory::GetInstance()->IsTouchDevice(event->sourceid)); | 259 DCHECK(ui::TouchFactory::GetInstance()->IsTouchDevice(event->sourceid)); |
| 264 switch (event->evtype) { | 260 switch (event->evtype) { |
| 265 case XI_ButtonPress: | 261 case XI_ButtonPress: |
| 266 return ui::ET_TOUCH_PRESSED; | 262 return ui::ET_TOUCH_PRESSED; |
| 267 case XI_ButtonRelease: | 263 case XI_ButtonRelease: |
| 268 return ui::ET_TOUCH_RELEASED; | 264 return ui::ET_TOUCH_RELEASED; |
| 269 case XI_Motion: | 265 case XI_Motion: |
| 270 // Should not convert any emulated Motion event from touch device to | 266 // Should not convert any emulated Motion event from touch device to |
| 271 // touch event. | 267 // touch event. |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 480 case EnterNotify: | 476 case EnterNotify: |
| 481 case LeaveNotify: | 477 case LeaveNotify: |
| 482 return GetEventFlagsFromXState(native_event->xcrossing.state); | 478 return GetEventFlagsFromXState(native_event->xcrossing.state); |
| 483 case MotionNotify: | 479 case MotionNotify: |
| 484 return GetEventFlagsFromXState(native_event->xmotion.state); | 480 return GetEventFlagsFromXState(native_event->xmotion.state); |
| 485 case GenericEvent: { | 481 case GenericEvent: { |
| 486 XIDeviceEvent* xievent = | 482 XIDeviceEvent* xievent = |
| 487 static_cast<XIDeviceEvent*>(native_event->xcookie.data); | 483 static_cast<XIDeviceEvent*>(native_event->xcookie.data); |
| 488 | 484 |
| 489 switch (xievent->evtype) { | 485 switch (xievent->evtype) { |
| 490 #if defined(USE_XI2_MT) | |
| 491 case XI_TouchBegin: | 486 case XI_TouchBegin: |
| 492 case XI_TouchUpdate: | 487 case XI_TouchUpdate: |
| 493 case XI_TouchEnd: | 488 case XI_TouchEnd: |
| 494 return GetButtonMaskForX2Event(xievent) | | 489 return GetButtonMaskForX2Event(xievent) | |
| 495 GetEventFlagsFromXState(xievent->mods.effective) | | 490 GetEventFlagsFromXState(xievent->mods.effective) | |
| 496 GetEventFlagsFromXState( | 491 GetEventFlagsFromXState( |
| 497 XModifierStateWatcher::GetInstance()->state()); | 492 XModifierStateWatcher::GetInstance()->state()); |
| 498 break; | 493 break; |
| 499 #endif | |
| 500 case XI_ButtonPress: | 494 case XI_ButtonPress: |
| 501 case XI_ButtonRelease: { | 495 case XI_ButtonRelease: { |
| 502 const bool touch = | 496 const bool touch = |
| 503 TouchFactory::GetInstance()->IsTouchDevice(xievent->sourceid); | 497 TouchFactory::GetInstance()->IsTouchDevice(xievent->sourceid); |
| 504 int flags = GetButtonMaskForX2Event(xievent) | | 498 int flags = GetButtonMaskForX2Event(xievent) | |
| 505 GetEventFlagsFromXState(xievent->mods.effective); | 499 GetEventFlagsFromXState(xievent->mods.effective); |
| 506 if (touch) { | 500 if (touch) { |
| 507 flags |= GetEventFlagsFromXState( | 501 flags |= GetEventFlagsFromXState( |
| 508 XModifierStateWatcher::GetInstance()->state()); | 502 XModifierStateWatcher::GetInstance()->state()); |
| 509 } | 503 } |
| (...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 920 xievent->detail = | 914 xievent->detail = |
| 921 UpdateX11EventButton(event->changed_button_flags(), xievent->detail); | 915 UpdateX11EventButton(event->changed_button_flags(), xievent->detail); |
| 922 break; | 916 break; |
| 923 } | 917 } |
| 924 default: | 918 default: |
| 925 break; | 919 break; |
| 926 } | 920 } |
| 927 } | 921 } |
| 928 | 922 |
| 929 } // namespace ui | 923 } // namespace ui |
| OLD | NEW |