| 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/platform/platform_event_utils.h" | 5 #include "ui/events/event_constants.h" |
| 6 | 6 |
| 7 #include <string.h> | 7 #include <string.h> |
| 8 #include <X11/extensions/XInput.h> | 8 #include <X11/extensions/XInput.h> |
| 9 #include <X11/extensions/XInput2.h> | 9 #include <X11/extensions/XInput2.h> |
| 10 #include <X11/XKBlib.h> | 10 #include <X11/XKBlib.h> |
| 11 #include <X11/Xlib.h> | 11 #include <X11/Xlib.h> |
| 12 #include <X11/Xutil.h> | 12 #include <X11/Xutil.h> |
| 13 #include <cmath> | 13 #include <cmath> |
| 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" |
| 18 #include "ui/events/devices/x11/device_list_cache_x11.h" |
| 19 #include "ui/events/devices/x11/touch_factory_x11.h" |
| 17 #include "ui/events/event.h" | 20 #include "ui/events/event.h" |
| 18 #include "ui/events/event_constants.h" | |
| 19 #include "ui/events/event_utils.h" | 21 #include "ui/events/event_utils.h" |
| 20 #include "ui/events/platform/x11/device_data_manager_x11.h" | 22 #include "ui/events/keycodes/keyboard_code_conversion_x.h" |
| 21 #include "ui/events/platform/x11/device_list_cache_x.h" | |
| 22 #include "ui/events/platform/x11/keyboard_code_conversion_x11.h" | |
| 23 #include "ui/events/platform/x11/touch_factory_x11.h" | |
| 24 #include "ui/gfx/display.h" | 23 #include "ui/gfx/display.h" |
| 25 #include "ui/gfx/point.h" | 24 #include "ui/gfx/geometry/point.h" |
| 26 #include "ui/gfx/rect.h" | 25 #include "ui/gfx/geometry/rect.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 namespace { | 30 namespace { |
| 31 | 31 |
| 32 // Scroll amount for each wheelscroll event. 53 is also the value used for GTK+. | 32 // Scroll amount for each wheelscroll event. 53 is also the value used for GTK+. |
| 33 const int kWheelScrollAmount = 53; | 33 const int kWheelScrollAmount = 53; |
| 34 | 34 |
| 35 const int kMinWheelButton = 4; | 35 const int kMinWheelButton = 4; |
| 36 const int kMaxWheelButton = 7; | 36 const int kMaxWheelButton = 7; |
| 37 | 37 |
| 38 // A class to track current modifier state on master device. Only track ctrl, | 38 // 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 | 39 // alt, shift and caps lock keys currently. The tracked state can then be used |
| 40 // by floating device. | 40 // by floating device. |
| 41 class XModifierStateWatcher { | 41 class XModifierStateWatcher{ |
| 42 public: | 42 public: |
| 43 static XModifierStateWatcher* GetInstance() { | 43 static XModifierStateWatcher* GetInstance() { |
| 44 return Singleton<XModifierStateWatcher>::get(); | 44 return Singleton<XModifierStateWatcher>::get(); |
| 45 } | 45 } |
| 46 | 46 |
| 47 int StateFromKeyboardCode(ui::KeyboardCode keyboard_code) { | 47 int StateFromKeyboardCode(ui::KeyboardCode keyboard_code) { |
| 48 switch (keyboard_code) { | 48 switch (keyboard_code) { |
| 49 case ui::VKEY_CONTROL: | 49 case ui::VKEY_CONTROL: |
| 50 return ControlMask; | 50 return ControlMask; |
| 51 case ui::VKEY_SHIFT: | 51 case ui::VKEY_SHIFT: |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 } | 95 } |
| 96 } | 96 } |
| 97 | 97 |
| 98 // Returns the current modifer state in master device. It only contains the | 98 // Returns the current modifer state in master device. It only contains the |
| 99 // state of ctrl, shift, alt and caps lock keys. | 99 // state of ctrl, shift, alt and caps lock keys. |
| 100 unsigned int state() { return state_; } | 100 unsigned int state() { return state_; } |
| 101 | 101 |
| 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 || event->evtype == XI_TouchUpdate || | 119 CHECK(event->evtype == XI_TouchBegin || |
| 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 |
| 127 if (ui::EventLocationFromNative(native_event) != gfx::Point()) | 127 if (ui::EventLocationFromNative(native_event) != gfx::Point()) |
| 128 return false; | 128 return false; |
| 129 | 129 |
| 130 // 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. |
| 131 double radius = ui::GetTouchRadiusX(native_event), min, max; | 131 double radius = ui::GetTouchRadiusX(native_event), min, max; |
| 132 unsigned int deviceid = | 132 unsigned int deviceid = |
| 133 static_cast<XIDeviceEvent*>(native_event->xcookie.data)->sourceid; | 133 static_cast<XIDeviceEvent*>(native_event->xcookie.data)->sourceid; |
| 134 if (!ui::DeviceDataManagerX11::GetInstance()->GetDataRange( | 134 if (!ui::DeviceDataManagerX11::GetInstance()->GetDataRange( |
| 135 deviceid, ui::DeviceDataManagerX11::DT_TOUCH_MAJOR, &min, &max)) { | 135 deviceid, ui::DeviceDataManagerX11::DT_TOUCH_MAJOR, &min, &max)) { |
| 136 return false; | 136 return false; |
| 137 } | 137 } |
| 138 | 138 |
| 139 return radius * 2 == max; | 139 return radius * 2 == max; |
| 140 } | 140 } |
| 141 #endif | |
| 142 | 141 |
| 143 int GetEventFlagsFromXState(unsigned int state) { | 142 int GetEventFlagsFromXState(unsigned int state) { |
| 144 int flags = 0; | 143 int flags = 0; |
| 145 if (state & ControlMask) | 144 if (state & ControlMask) |
| 146 flags |= ui::EF_CONTROL_DOWN; | 145 flags |= ui::EF_CONTROL_DOWN; |
| 147 if (state & ShiftMask) | 146 if (state & ShiftMask) |
| 148 flags |= ui::EF_SHIFT_DOWN; | 147 flags |= ui::EF_SHIFT_DOWN; |
| 149 if (state & Mod1Mask) | 148 if (state & Mod1Mask) |
| 150 flags |= ui::EF_ALT_DOWN; | 149 flags |= ui::EF_ALT_DOWN; |
| 151 if (state & LockMask) | 150 if (state & LockMask) |
| 152 flags |= ui::EF_CAPS_LOCK_DOWN; | 151 flags |= ui::EF_CAPS_LOCK_DOWN; |
| 153 if (state & Mod3Mask) | 152 if (state & Mod3Mask) |
| 154 flags |= ui::EF_MOD3_DOWN; | 153 flags |= ui::EF_MOD3_DOWN; |
| 155 if (state & Mod4Mask) | 154 if (state & Mod4Mask) |
| 156 flags |= ui::EF_COMMAND_DOWN; | 155 flags |= ui::EF_COMMAND_DOWN; |
| 157 if (state & Mod5Mask) | 156 if (state & Mod5Mask) |
| 158 flags |= ui::EF_ALTGR_DOWN; | 157 flags |= ui::EF_ALTGR_DOWN; |
| 159 if (state & Button1Mask) | 158 if (state & Button1Mask) |
| 160 flags |= ui::EF_LEFT_MOUSE_BUTTON; | 159 flags |= ui::EF_LEFT_MOUSE_BUTTON; |
| 161 if (state & Button2Mask) | 160 if (state & Button2Mask) |
| 162 flags |= ui::EF_MIDDLE_MOUSE_BUTTON; | 161 flags |= ui::EF_MIDDLE_MOUSE_BUTTON; |
| 163 if (state & Button3Mask) | 162 if (state & Button3Mask) |
| 164 flags |= ui::EF_RIGHT_MOUSE_BUTTON; | 163 flags |= ui::EF_RIGHT_MOUSE_BUTTON; |
| 164 // There are no masks for EF_BACK_MOUSE_BUTTON and |
| 165 // EF_FORWARD_MOUSE_BUTTON. |
| 165 return flags; | 166 return flags; |
| 166 } | 167 } |
| 167 | 168 |
| 168 int GetEventFlagsFromXKeyEvent(XEvent* xevent) { | 169 int GetEventFlagsFromXKeyEvent(XEvent* xevent) { |
| 169 DCHECK(xevent->type == KeyPress || xevent->type == KeyRelease); | 170 DCHECK(xevent->type == KeyPress || xevent->type == KeyRelease); |
| 170 | 171 |
| 171 #if defined(OS_CHROMEOS) | 172 #if defined(OS_CHROMEOS) |
| 172 const int ime_fabricated_flag = 0; | 173 const int ime_fabricated_flag = 0; |
| 173 #else | 174 #else |
| 174 // XIM fabricates key events for the character compositions by XK_Multi_key. | 175 // XIM fabricates key events for the character compositions by XK_Multi_key. |
| 175 // For example, when a user hits XK_Multi_key, XK_apostrophe, and XK_e in | 176 // For example, when a user hits XK_Multi_key, XK_apostrophe, and XK_e in |
| 176 // order to input "é", then XIM generates a key event with keycode=0 and | 177 // order to input "é", then XIM generates a key event with keycode=0 and |
| 177 // state=0 for the composition, and the sequence of X11 key events will be | 178 // state=0 for the composition, and the sequence of X11 key events will be |
| 178 // XK_Multi_key, XK_apostrophe, **NoSymbol**, and XK_e. If the user used | 179 // XK_Multi_key, XK_apostrophe, **NoSymbol**, and XK_e. If the user used |
| 179 // shift key and/or caps lock key, state can be ShiftMask, LockMask or both. | 180 // shift key and/or caps lock key, state can be ShiftMask, LockMask or both. |
| 180 // | 181 // |
| 181 // We have to send these fabricated key events to XIM so it can correctly | 182 // We have to send these fabricated key events to XIM so it can correctly |
| 182 // handle the character compositions. | 183 // handle the character compositions. |
| 183 const unsigned int shift_lock_mask = ShiftMask | LockMask; | 184 const unsigned int shift_lock_mask = ShiftMask | LockMask; |
| 184 const bool fabricated_by_xim = | 185 const bool fabricated_by_xim = |
| 185 xevent->xkey.keycode == 0 && (xevent->xkey.state & ~shift_lock_mask) == 0; | 186 xevent->xkey.keycode == 0 && |
| 187 (xevent->xkey.state & ~shift_lock_mask) == 0; |
| 186 const int ime_fabricated_flag = | 188 const int ime_fabricated_flag = |
| 187 fabricated_by_xim ? ui::EF_IME_FABRICATED_KEY : 0; | 189 fabricated_by_xim ? ui::EF_IME_FABRICATED_KEY : 0; |
| 188 #endif | 190 #endif |
| 189 | 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 | 194 ime_fabricated_flag; |
| 193 : 0) | | |
| 194 (IsFunctionKey(XLookupKeysym(&xevent->xkey, 0)) ? ui::EF_FUNCTION_KEY | |
| 195 : 0) | | |
| 196 ime_fabricated_flag; | |
| 197 } | 195 } |
| 198 | 196 |
| 199 int GetEventFlagsFromXGenericEvent(XEvent* xevent) { | 197 int GetEventFlagsFromXGenericEvent(XEvent* xevent) { |
| 200 DCHECK(xevent->type == GenericEvent); | 198 DCHECK(xevent->type == GenericEvent); |
| 201 XIDeviceEvent* xievent = static_cast<XIDeviceEvent*>(xevent->xcookie.data); | 199 XIDeviceEvent* xievent = static_cast<XIDeviceEvent*>(xevent->xcookie.data); |
| 202 DCHECK((xievent->evtype == XI_KeyPress) || | 200 DCHECK((xievent->evtype == XI_KeyPress) || |
| 203 (xievent->evtype == XI_KeyRelease)); | 201 (xievent->evtype == XI_KeyRelease)); |
| 204 return GetEventFlagsFromXState(xievent->mods.effective) | | 202 return GetEventFlagsFromXState(xievent->mods.effective) | |
| 205 (xevent->xkey.send_event ? ui::EF_FINAL : 0) | | 203 (xevent->xkey.send_event ? ui::EF_FINAL : 0); |
| 206 (IsKeypadKey( | |
| 207 XkbKeycodeToKeysym(xievent->display, xievent->detail, 0, 0)) | |
| 208 ? ui::EF_NUMPAD_KEY | |
| 209 : 0); | |
| 210 } | 204 } |
| 211 | 205 |
| 212 // Get the event flag for the button in XButtonEvent. During a ButtonPress | 206 // Get the event flag for the button in XButtonEvent. During a ButtonPress |
| 213 // event, |state| in XButtonEvent does not include the button that has just been | 207 // event, |state| in XButtonEvent does not include the button that has just been |
| 214 // pressed. Instead |state| contains flags for the buttons (if any) that had | 208 // pressed. Instead |state| contains flags for the buttons (if any) that had |
| 215 // already been pressed before the current button, and |button| stores the most | 209 // already been pressed before the current button, and |button| stores the most |
| 216 // current pressed button. So, if you press down left mouse button, and while | 210 // current pressed button. So, if you press down left mouse button, and while |
| 217 // pressing it down, press down the right mouse button, then for the latter | 211 // pressing it down, press down the right mouse button, then for the latter |
| 218 // event, |state| would have Button1Mask set but not Button3Mask, and |button| | 212 // event, |state| would have Button1Mask set but not Button3Mask, and |button| |
| 219 // would be 3. | 213 // would be 3. |
| 220 int GetEventFlagsForButton(int button) { | 214 int GetEventFlagsForButton(int button) { |
| 221 switch (button) { | 215 switch (button) { |
| 222 case 1: | 216 case 1: |
| 223 return ui::EF_LEFT_MOUSE_BUTTON; | 217 return ui::EF_LEFT_MOUSE_BUTTON; |
| 224 case 2: | 218 case 2: |
| 225 return ui::EF_MIDDLE_MOUSE_BUTTON; | 219 return ui::EF_MIDDLE_MOUSE_BUTTON; |
| 226 case 3: | 220 case 3: |
| 227 return ui::EF_RIGHT_MOUSE_BUTTON; | 221 return ui::EF_RIGHT_MOUSE_BUTTON; |
| 222 case 8: |
| 223 return ui::EF_BACK_MOUSE_BUTTON; |
| 224 case 9: |
| 225 return ui::EF_FORWARD_MOUSE_BUTTON; |
| 228 default: | 226 default: |
| 229 return 0; | 227 return 0; |
| 230 } | 228 } |
| 231 } | 229 } |
| 232 | 230 |
| 233 int GetButtonMaskForX2Event(XIDeviceEvent* xievent) { | 231 int GetButtonMaskForX2Event(XIDeviceEvent* xievent) { |
| 234 int buttonflags = 0; | 232 int buttonflags = 0; |
| 235 for (int i = 0; i < 8 * xievent->buttons.mask_len; i++) { | 233 for (int i = 0; i < 8 * xievent->buttons.mask_len; i++) { |
| 236 if (XIMaskIsSet(xievent->buttons.mask, i)) { | 234 if (XIMaskIsSet(xievent->buttons.mask, i)) { |
| 237 int button = | 235 int button = (xievent->sourceid == xievent->deviceid) ? |
| 238 (xievent->sourceid == xievent->deviceid) | 236 ui::DeviceDataManagerX11::GetInstance()->GetMappedButton(i) : i; |
| 239 ? ui::DeviceDataManagerX11::GetInstance()->GetMappedButton(i) | |
| 240 : i; | |
| 241 buttonflags |= GetEventFlagsForButton(button); | 237 buttonflags |= GetEventFlagsForButton(button); |
| 242 } | 238 } |
| 243 } | 239 } |
| 244 return buttonflags; | 240 return buttonflags; |
| 245 } | 241 } |
| 246 | 242 |
| 247 ui::EventType GetTouchEventType(const base::NativeEvent& native_event) { | 243 ui::EventType GetTouchEventType(const base::NativeEvent& native_event) { |
| 248 XIDeviceEvent* event = | 244 XIDeviceEvent* event = |
| 249 static_cast<XIDeviceEvent*>(native_event->xcookie.data); | 245 static_cast<XIDeviceEvent*>(native_event->xcookie.data); |
| 250 #if defined(USE_XI2_MT) | 246 switch(event->evtype) { |
| 251 switch (event->evtype) { | |
| 252 case XI_TouchBegin: | 247 case XI_TouchBegin: |
| 253 return TouchEventIsGeneratedHack(native_event) ? ui::ET_UNKNOWN | 248 return TouchEventIsGeneratedHack(native_event) ? ui::ET_UNKNOWN : |
| 254 : ui::ET_TOUCH_PRESSED; | 249 ui::ET_TOUCH_PRESSED; |
| 255 case XI_TouchUpdate: | 250 case XI_TouchUpdate: |
| 256 return TouchEventIsGeneratedHack(native_event) ? ui::ET_UNKNOWN | 251 return TouchEventIsGeneratedHack(native_event) ? ui::ET_UNKNOWN : |
| 257 : ui::ET_TOUCH_MOVED; | 252 ui::ET_TOUCH_MOVED; |
| 258 case XI_TouchEnd: | 253 case XI_TouchEnd: |
| 259 return TouchEventIsGeneratedHack(native_event) ? ui::ET_TOUCH_CANCELLED | 254 return TouchEventIsGeneratedHack(native_event) ? ui::ET_TOUCH_CANCELLED : |
| 260 : ui::ET_TOUCH_RELEASED; | 255 ui::ET_TOUCH_RELEASED; |
| 261 } | 256 } |
| 262 #endif // defined(USE_XI2_MT) | |
| 263 | 257 |
| 264 DCHECK(ui::TouchFactory::GetInstance()->IsTouchDevice(event->sourceid)); | 258 DCHECK(ui::TouchFactory::GetInstance()->IsTouchDevice(event->sourceid)); |
| 265 switch (event->evtype) { | 259 switch (event->evtype) { |
| 266 case XI_ButtonPress: | 260 case XI_ButtonPress: |
| 267 return ui::ET_TOUCH_PRESSED; | 261 return ui::ET_TOUCH_PRESSED; |
| 268 case XI_ButtonRelease: | 262 case XI_ButtonRelease: |
| 269 return ui::ET_TOUCH_RELEASED; | 263 return ui::ET_TOUCH_RELEASED; |
| 270 case XI_Motion: | 264 case XI_Motion: |
| 271 // Should not convert any emulated Motion event from touch device to | 265 // Should not convert any emulated Motion event from touch device to |
| 272 // touch event. | 266 // touch event. |
| 273 if (!(event->flags & XIPointerEmulated) && GetButtonMaskForX2Event(event)) | 267 if (!(event->flags & XIPointerEmulated) && |
| 268 GetButtonMaskForX2Event(event)) |
| 274 return ui::ET_TOUCH_MOVED; | 269 return ui::ET_TOUCH_MOVED; |
| 275 return ui::ET_UNKNOWN; | 270 return ui::ET_UNKNOWN; |
| 276 default: | 271 default: |
| 277 NOTREACHED(); | 272 NOTREACHED(); |
| 278 } | 273 } |
| 279 return ui::ET_UNKNOWN; | 274 return ui::ET_UNKNOWN; |
| 280 } | 275 } |
| 281 | 276 |
| 282 double GetTouchParamFromXEvent(XEvent* xev, | 277 double GetTouchParamFromXEvent(XEvent* xev, |
| 283 ui::DeviceDataManagerX11::DataType val, | 278 ui::DeviceDataManagerX11::DataType val, |
| 284 double default_value) { | 279 double default_value) { |
| 285 ui::DeviceDataManagerX11::GetInstance()->GetEventData(*xev, val, | 280 ui::DeviceDataManagerX11::GetInstance()->GetEventData( |
| 286 &default_value); | 281 *xev, val, &default_value); |
| 287 return default_value; | 282 return default_value; |
| 288 } | 283 } |
| 289 | 284 |
| 290 void ScaleTouchRadius(XEvent* xev, double* radius) { | 285 void ScaleTouchRadius(XEvent* xev, double* radius) { |
| 291 DCHECK_EQ(GenericEvent, xev->type); | 286 DCHECK_EQ(GenericEvent, xev->type); |
| 292 XIDeviceEvent* xiev = static_cast<XIDeviceEvent*>(xev->xcookie.data); | 287 XIDeviceEvent* xiev = static_cast<XIDeviceEvent*>(xev->xcookie.data); |
| 293 ui::DeviceDataManagerX11::GetInstance()->ApplyTouchRadiusScale(xiev->sourceid, | 288 ui::DeviceDataManagerX11::GetInstance()->ApplyTouchRadiusScale( |
| 294 radius); | 289 xiev->sourceid, radius); |
| 290 } |
| 291 |
| 292 unsigned int UpdateX11EventFlags(int ui_flags, unsigned int old_x_flags) { |
| 293 static struct { |
| 294 int ui; |
| 295 int x; |
| 296 } flags[] = { |
| 297 {ui::EF_CONTROL_DOWN, ControlMask}, |
| 298 {ui::EF_SHIFT_DOWN, ShiftMask}, |
| 299 {ui::EF_ALT_DOWN, Mod1Mask}, |
| 300 {ui::EF_CAPS_LOCK_DOWN, LockMask}, |
| 301 {ui::EF_ALTGR_DOWN, Mod5Mask}, |
| 302 {ui::EF_COMMAND_DOWN, Mod4Mask}, |
| 303 {ui::EF_MOD3_DOWN, Mod3Mask}, |
| 304 {ui::EF_LEFT_MOUSE_BUTTON, Button1Mask}, |
| 305 {ui::EF_MIDDLE_MOUSE_BUTTON, Button2Mask}, |
| 306 {ui::EF_RIGHT_MOUSE_BUTTON, Button3Mask}, |
| 307 }; |
| 308 unsigned int new_x_flags = old_x_flags; |
| 309 for (size_t i = 0; i < arraysize(flags); ++i) { |
| 310 if (ui_flags & flags[i].ui) |
| 311 new_x_flags |= flags[i].x; |
| 312 else |
| 313 new_x_flags &= ~flags[i].x; |
| 314 } |
| 315 return new_x_flags; |
| 316 } |
| 317 |
| 318 unsigned int UpdateX11EventButton(int ui_flag, unsigned int old_x_button) { |
| 319 switch (ui_flag) { |
| 320 case ui::EF_LEFT_MOUSE_BUTTON: |
| 321 return Button1; |
| 322 case ui::EF_MIDDLE_MOUSE_BUTTON: |
| 323 return Button2; |
| 324 case ui::EF_RIGHT_MOUSE_BUTTON: |
| 325 return Button3; |
| 326 default: |
| 327 return old_x_button; |
| 328 } |
| 329 NOTREACHED(); |
| 295 } | 330 } |
| 296 | 331 |
| 297 bool GetGestureTimes(const base::NativeEvent& native_event, | 332 bool GetGestureTimes(const base::NativeEvent& native_event, |
| 298 double* start_time, | 333 double* start_time, |
| 299 double* end_time) { | 334 double* end_time) { |
| 300 if (!ui::DeviceDataManagerX11::GetInstance()->HasGestureTimes(native_event)) | 335 if (!ui::DeviceDataManagerX11::GetInstance()->HasGestureTimes(native_event)) |
| 301 return false; | 336 return false; |
| 302 | 337 |
| 303 double start_time_, end_time_; | 338 double start_time_, end_time_; |
| 304 if (!start_time) | 339 if (!start_time) |
| 305 start_time = &start_time_; | 340 start_time = &start_time_; |
| 306 if (!end_time) | 341 if (!end_time) |
| 307 end_time = &end_time_; | 342 end_time = &end_time_; |
| 308 | 343 |
| 309 ui::DeviceDataManagerX11::GetInstance()->GetGestureTimes( | 344 ui::DeviceDataManagerX11::GetInstance()->GetGestureTimes( |
| 310 native_event, start_time, end_time); | 345 native_event, start_time, end_time); |
| 311 return true; | 346 return true; |
| 312 } | 347 } |
| 313 | 348 |
| 314 } // namespace | 349 } // namespace |
| 315 | 350 |
| 316 namespace ui { | 351 namespace ui { |
| 317 | 352 |
| 318 void UpdateDeviceList() { | 353 void UpdateDeviceList() { |
| 319 XDisplay* display = gfx::GetXDisplay(); | 354 XDisplay* display = gfx::GetXDisplay(); |
| 320 DeviceListCacheX::GetInstance()->UpdateDeviceList(display); | 355 DeviceListCacheX11::GetInstance()->UpdateDeviceList(display); |
| 321 TouchFactory::GetInstance()->UpdateDeviceList(display); | 356 TouchFactory::GetInstance()->UpdateDeviceList(display); |
| 322 DeviceDataManagerX11::GetInstance()->UpdateDeviceList(display); | 357 DeviceDataManagerX11::GetInstance()->UpdateDeviceList(display); |
| 323 } | 358 } |
| 324 | 359 |
| 325 EventType EventTypeFromNative(const base::NativeEvent& native_event) { | 360 EventType EventTypeFromNative(const base::NativeEvent& native_event) { |
| 326 // Allow the DeviceDataManager to block the event. If blocked return | 361 // Allow the DeviceDataManager to block the event. If blocked return |
| 327 // ET_UNKNOWN as the type so this event will not be further processed. | 362 // ET_UNKNOWN as the type so this event will not be further processed. |
| 328 // NOTE: During some events unittests there is no device data manager. | 363 // NOTE: During some events unittests there is no device data manager. |
| 329 if (DeviceDataManager::HasInstance() && | 364 if (DeviceDataManager::HasInstance() && |
| 330 static_cast<DeviceDataManagerX11*>(DeviceDataManager::GetInstance()) | 365 static_cast<DeviceDataManagerX11*>(DeviceDataManager::GetInstance())-> |
| 331 ->IsEventBlocked(native_event)) { | 366 IsEventBlocked(native_event)) { |
| 332 return ET_UNKNOWN; | 367 return ET_UNKNOWN; |
| 333 } | 368 } |
| 334 | 369 |
| 335 switch (native_event->type) { | 370 switch (native_event->type) { |
| 336 case KeyPress: | 371 case KeyPress: |
| 337 return ET_KEY_PRESSED; | 372 return ET_KEY_PRESSED; |
| 338 case KeyRelease: | 373 case KeyRelease: |
| 339 return ET_KEY_RELEASED; | 374 return ET_KEY_RELEASED; |
| 340 case ButtonPress: | 375 case ButtonPress: |
| 341 if (static_cast<int>(native_event->xbutton.button) >= kMinWheelButton && | 376 if (static_cast<int>(native_event->xbutton.button) >= kMinWheelButton && |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 400 if (GetFlingData(native_event, NULL, NULL, NULL, NULL, &is_cancel)) | 435 if (GetFlingData(native_event, NULL, NULL, NULL, NULL, &is_cancel)) |
| 401 return is_cancel ? ET_SCROLL_FLING_CANCEL : ET_SCROLL_FLING_START; | 436 return is_cancel ? ET_SCROLL_FLING_CANCEL : ET_SCROLL_FLING_START; |
| 402 if (devices->IsScrollEvent(native_event)) { | 437 if (devices->IsScrollEvent(native_event)) { |
| 403 return devices->IsTouchpadXInputEvent(native_event) ? ET_SCROLL | 438 return devices->IsTouchpadXInputEvent(native_event) ? ET_SCROLL |
| 404 : ET_MOUSEWHEEL; | 439 : ET_MOUSEWHEEL; |
| 405 } | 440 } |
| 406 if (devices->IsCMTMetricsEvent(native_event)) | 441 if (devices->IsCMTMetricsEvent(native_event)) |
| 407 return ET_UMA_DATA; | 442 return ET_UMA_DATA; |
| 408 if (GetButtonMaskForX2Event(xievent)) | 443 if (GetButtonMaskForX2Event(xievent)) |
| 409 return ET_MOUSE_DRAGGED; | 444 return ET_MOUSE_DRAGGED; |
| 445 if (DeviceDataManagerX11::GetInstance()->HasEventData( |
| 446 xievent, DeviceDataManagerX11::DT_CMT_SCROLL_X) || |
| 447 DeviceDataManagerX11::GetInstance()->HasEventData( |
| 448 xievent, DeviceDataManagerX11::DT_CMT_SCROLL_Y)) { |
| 449 // Don't produce mouse move events for mousewheel scrolls. |
| 450 return ET_UNKNOWN; |
| 451 } |
| 452 |
| 410 return ET_MOUSE_MOVED; | 453 return ET_MOUSE_MOVED; |
| 411 } | 454 } |
| 412 case XI_KeyPress: | 455 case XI_KeyPress: |
| 413 return ET_KEY_PRESSED; | 456 return ET_KEY_PRESSED; |
| 414 case XI_KeyRelease: | 457 case XI_KeyRelease: |
| 415 return ET_KEY_RELEASED; | 458 return ET_KEY_RELEASED; |
| 416 } | 459 } |
| 417 } | 460 } |
| 418 default: | 461 default: |
| 419 break; | 462 break; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 439 case EnterNotify: | 482 case EnterNotify: |
| 440 case LeaveNotify: | 483 case LeaveNotify: |
| 441 return GetEventFlagsFromXState(native_event->xcrossing.state); | 484 return GetEventFlagsFromXState(native_event->xcrossing.state); |
| 442 case MotionNotify: | 485 case MotionNotify: |
| 443 return GetEventFlagsFromXState(native_event->xmotion.state); | 486 return GetEventFlagsFromXState(native_event->xmotion.state); |
| 444 case GenericEvent: { | 487 case GenericEvent: { |
| 445 XIDeviceEvent* xievent = | 488 XIDeviceEvent* xievent = |
| 446 static_cast<XIDeviceEvent*>(native_event->xcookie.data); | 489 static_cast<XIDeviceEvent*>(native_event->xcookie.data); |
| 447 | 490 |
| 448 switch (xievent->evtype) { | 491 switch (xievent->evtype) { |
| 449 #if defined(USE_XI2_MT) | |
| 450 case XI_TouchBegin: | 492 case XI_TouchBegin: |
| 451 case XI_TouchUpdate: | 493 case XI_TouchUpdate: |
| 452 case XI_TouchEnd: | 494 case XI_TouchEnd: |
| 453 return GetButtonMaskForX2Event(xievent) | | 495 return GetButtonMaskForX2Event(xievent) | |
| 454 GetEventFlagsFromXState(xievent->mods.effective) | | 496 GetEventFlagsFromXState(xievent->mods.effective) | |
| 455 GetEventFlagsFromXState( | 497 GetEventFlagsFromXState( |
| 456 XModifierStateWatcher::GetInstance()->state()); | 498 XModifierStateWatcher::GetInstance()->state()); |
| 457 break; | 499 break; |
| 458 #endif | |
| 459 case XI_ButtonPress: | 500 case XI_ButtonPress: |
| 460 case XI_ButtonRelease: { | 501 case XI_ButtonRelease: { |
| 461 const bool touch = | 502 const bool touch = |
| 462 TouchFactory::GetInstance()->IsTouchDevice(xievent->sourceid); | 503 TouchFactory::GetInstance()->IsTouchDevice(xievent->sourceid); |
| 463 int flags = GetButtonMaskForX2Event(xievent) | | 504 int flags = GetButtonMaskForX2Event(xievent) | |
| 464 GetEventFlagsFromXState(xievent->mods.effective); | 505 GetEventFlagsFromXState(xievent->mods.effective); |
| 465 if (touch) { | 506 if (touch) { |
| 466 flags |= GetEventFlagsFromXState( | 507 flags |= GetEventFlagsFromXState( |
| 467 XModifierStateWatcher::GetInstance()->state()); | 508 XModifierStateWatcher::GetInstance()->state()); |
| 468 } | 509 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 482 native_event); | 523 native_event); |
| 483 return GetEventFlagsFromXGenericEvent(native_event); | 524 return GetEventFlagsFromXGenericEvent(native_event); |
| 484 } | 525 } |
| 485 } | 526 } |
| 486 } | 527 } |
| 487 } | 528 } |
| 488 return 0; | 529 return 0; |
| 489 } | 530 } |
| 490 | 531 |
| 491 base::TimeDelta EventTimeFromNative(const base::NativeEvent& native_event) { | 532 base::TimeDelta EventTimeFromNative(const base::NativeEvent& native_event) { |
| 492 switch (native_event->type) { | 533 switch(native_event->type) { |
| 493 case KeyPress: | 534 case KeyPress: |
| 494 case KeyRelease: | 535 case KeyRelease: |
| 495 return base::TimeDelta::FromMilliseconds(native_event->xkey.time); | 536 return base::TimeDelta::FromMilliseconds(native_event->xkey.time); |
| 496 case ButtonPress: | 537 case ButtonPress: |
| 497 case ButtonRelease: | 538 case ButtonRelease: |
| 498 return base::TimeDelta::FromMilliseconds(native_event->xbutton.time); | 539 return base::TimeDelta::FromMilliseconds(native_event->xbutton.time); |
| 499 break; | 540 break; |
| 500 case MotionNotify: | 541 case MotionNotify: |
| 501 return base::TimeDelta::FromMilliseconds(native_event->xmotion.time); | 542 return base::TimeDelta::FromMilliseconds(native_event->xmotion.time); |
| 502 break; | 543 break; |
| 503 case EnterNotify: | 544 case EnterNotify: |
| 504 case LeaveNotify: | 545 case LeaveNotify: |
| 505 return base::TimeDelta::FromMilliseconds(native_event->xcrossing.time); | 546 return base::TimeDelta::FromMilliseconds(native_event->xcrossing.time); |
| 506 break; | 547 break; |
| 507 case GenericEvent: { | 548 case GenericEvent: { |
| 508 double start, end; | 549 double start, end; |
| 509 double touch_timestamp; | 550 double touch_timestamp; |
| 510 if (GetGestureTimes(native_event, &start, &end)) { | 551 if (GetGestureTimes(native_event, &start, &end)) { |
| 511 // If the driver supports gesture times, use them. | 552 // If the driver supports gesture times, use them. |
| 512 return base::TimeDelta::FromMicroseconds(end * 1000000); | 553 return base::TimeDelta::FromMicroseconds(end * 1000000); |
| 513 } else if (DeviceDataManagerX11::GetInstance()->GetEventData( | 554 } else if (DeviceDataManagerX11::GetInstance()->GetEventData( |
| 514 *native_event, | 555 *native_event, |
| 515 DeviceDataManagerX11::DT_TOUCH_RAW_TIMESTAMP, | 556 DeviceDataManagerX11::DT_TOUCH_RAW_TIMESTAMP, |
| 516 &touch_timestamp)) { | 557 &touch_timestamp)) { |
| 517 return base::TimeDelta::FromMicroseconds(touch_timestamp * 1000000); | 558 return base::TimeDelta::FromMicroseconds(touch_timestamp * 1000000); |
| 518 } else { | 559 } else { |
| 519 XIDeviceEvent* xide = | 560 XIDeviceEvent* xide = |
| 520 static_cast<XIDeviceEvent*>(native_event->xcookie.data); | 561 static_cast<XIDeviceEvent*>(native_event->xcookie.data); |
| 521 return base::TimeDelta::FromMilliseconds(xide->time); | 562 return base::TimeDelta::FromMilliseconds(xide->time); |
| 522 } | 563 } |
| 523 break; | 564 break; |
| 524 } | 565 } |
| 525 } | 566 } |
| 526 NOTREACHED(); | 567 NOTREACHED(); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 586 | 627 |
| 587 return gfx::Point(); | 628 return gfx::Point(); |
| 588 } | 629 } |
| 589 | 630 |
| 590 int EventButtonFromNative(const base::NativeEvent& native_event) { | 631 int EventButtonFromNative(const base::NativeEvent& native_event) { |
| 591 CHECK_EQ(GenericEvent, native_event->type); | 632 CHECK_EQ(GenericEvent, native_event->type); |
| 592 XIDeviceEvent* xievent = | 633 XIDeviceEvent* xievent = |
| 593 static_cast<XIDeviceEvent*>(native_event->xcookie.data); | 634 static_cast<XIDeviceEvent*>(native_event->xcookie.data); |
| 594 int button = xievent->detail; | 635 int button = xievent->detail; |
| 595 | 636 |
| 596 return (xievent->sourceid == xievent->deviceid) | 637 return (xievent->sourceid == xievent->deviceid) ? |
| 597 ? DeviceDataManagerX11::GetInstance()->GetMappedButton(button) | 638 DeviceDataManagerX11::GetInstance()->GetMappedButton(button) : button; |
| 598 : button; | |
| 599 } | 639 } |
| 600 | 640 |
| 601 KeyboardCode KeyboardCodeFromNative(const base::NativeEvent& native_event) { | 641 KeyboardCode KeyboardCodeFromNative(const base::NativeEvent& native_event) { |
| 602 return KeyboardCodeFromXKeyEvent(native_event); | 642 return KeyboardCodeFromXKeyEvent(native_event); |
| 603 } | 643 } |
| 604 | 644 |
| 605 const char* CodeFromNative(const base::NativeEvent& native_event) { | 645 DomCode CodeFromNative(const base::NativeEvent& native_event) { |
| 606 return CodeFromXEvent(native_event); | 646 return CodeFromXEvent(native_event); |
| 607 } | 647 } |
| 608 | 648 |
| 609 uint32 PlatformKeycodeFromNative(const base::NativeEvent& native_event) { | 649 uint32 PlatformKeycodeFromNative(const base::NativeEvent& native_event) { |
| 610 XKeyEvent* xkey = NULL; | 650 XKeyEvent* xkey = NULL; |
| 611 XEvent xkey_from_xi2; | 651 XEvent xkey_from_xi2; |
| 612 switch (native_event->type) { | 652 switch (native_event->type) { |
| 613 case KeyPress: | 653 case KeyPress: |
| 614 case KeyRelease: | 654 case KeyRelease: |
| 615 xkey = &native_event->xkey; | 655 xkey = &native_event->xkey; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 643 | 683 |
| 644 bool IsCharFromNative(const base::NativeEvent& native_event) { | 684 bool IsCharFromNative(const base::NativeEvent& native_event) { |
| 645 return false; | 685 return false; |
| 646 } | 686 } |
| 647 | 687 |
| 648 int GetChangedMouseButtonFlagsFromNative( | 688 int GetChangedMouseButtonFlagsFromNative( |
| 649 const base::NativeEvent& native_event) { | 689 const base::NativeEvent& native_event) { |
| 650 switch (native_event->type) { | 690 switch (native_event->type) { |
| 651 case ButtonPress: | 691 case ButtonPress: |
| 652 case ButtonRelease: | 692 case ButtonRelease: |
| 653 return GetEventFlagsFromXState(native_event->xbutton.state); | 693 return GetEventFlagsForButton(native_event->xbutton.button); |
| 654 case GenericEvent: { | 694 case GenericEvent: { |
| 655 XIDeviceEvent* xievent = | 695 XIDeviceEvent* xievent = |
| 656 static_cast<XIDeviceEvent*>(native_event->xcookie.data); | 696 static_cast<XIDeviceEvent*>(native_event->xcookie.data); |
| 657 switch (xievent->evtype) { | 697 switch (xievent->evtype) { |
| 658 case XI_ButtonPress: | 698 case XI_ButtonPress: |
| 659 case XI_ButtonRelease: | 699 case XI_ButtonRelease: |
| 660 return GetEventFlagsForButton(EventButtonFromNative(native_event)); | 700 return GetEventFlagsForButton(EventButtonFromNative(native_event)); |
| 661 default: | 701 default: |
| 662 break; | 702 break; |
| 663 } | 703 } |
| 664 } | 704 } |
| 665 default: | 705 default: |
| 666 break; | 706 break; |
| 667 } | 707 } |
| 668 return 0; | 708 return 0; |
| 669 } | 709 } |
| 670 | 710 |
| 671 gfx::Vector2d GetMouseWheelOffset(const base::NativeEvent& native_event) { | 711 gfx::Vector2d GetMouseWheelOffset(const base::NativeEvent& native_event) { |
| 672 float x_offset, y_offset; | 712 float x_offset, y_offset; |
| 673 if (GetScrollOffsets(native_event, &x_offset, &y_offset, NULL, NULL, NULL)) { | 713 if (GetScrollOffsets( |
| 714 native_event, &x_offset, &y_offset, NULL, NULL, NULL)) { |
| 674 return gfx::Vector2d(static_cast<int>(x_offset), | 715 return gfx::Vector2d(static_cast<int>(x_offset), |
| 675 static_cast<int>(y_offset)); | 716 static_cast<int>(y_offset)); |
| 676 } | 717 } |
| 677 | 718 |
| 678 int button = native_event->type == GenericEvent | 719 int button = native_event->type == GenericEvent ? |
| 679 ? EventButtonFromNative(native_event) | 720 EventButtonFromNative(native_event) : native_event->xbutton.button; |
| 680 : native_event->xbutton.button; | |
| 681 | 721 |
| 682 switch (button) { | 722 switch (button) { |
| 683 case 4: | 723 case 4: |
| 684 return gfx::Vector2d(0, kWheelScrollAmount); | 724 return gfx::Vector2d(0, kWheelScrollAmount); |
| 685 case 5: | 725 case 5: |
| 686 return gfx::Vector2d(0, -kWheelScrollAmount); | 726 return gfx::Vector2d(0, -kWheelScrollAmount); |
| 687 case 6: | 727 case 6: |
| 688 return gfx::Vector2d(kWheelScrollAmount, 0); | 728 return gfx::Vector2d(kWheelScrollAmount, 0); |
| 689 case 7: | 729 case 7: |
| 690 return gfx::Vector2d(-kWheelScrollAmount, 0); | 730 return gfx::Vector2d(-kWheelScrollAmount, 0); |
| 691 default: | 731 default: |
| 692 return gfx::Vector2d(); | 732 return gfx::Vector2d(); |
| 693 } | 733 } |
| 694 } | 734 } |
| 695 | 735 |
| 696 void IncrementTouchIdRefCount(const base::NativeEvent& xev) { | 736 base::NativeEvent CopyNativeEvent(const base::NativeEvent& event) { |
| 697 ui::DeviceDataManagerX11* manager = ui::DeviceDataManagerX11::GetInstance(); | 737 if (!event || event->type == GenericEvent) |
| 698 double tracking_id; | 738 return NULL; |
| 699 if (!manager->GetEventData( | 739 XEvent* copy = new XEvent; |
| 700 *xev, ui::DeviceDataManagerX11::DT_TOUCH_TRACKING_ID, &tracking_id)) { | 740 *copy = *event; |
| 701 return; | 741 return copy; |
| 702 } | 742 } |
| 703 | 743 |
| 704 ui::TouchFactory* factory = ui::TouchFactory::GetInstance(); | 744 void ReleaseCopiedNativeEvent(const base::NativeEvent& event) { |
| 705 factory->AcquireSlotForTrackingID(tracking_id); | 745 delete event; |
| 706 } | 746 } |
| 707 | 747 |
| 708 void ClearTouchIdIfReleased(const base::NativeEvent& xev) { | 748 void ClearTouchIdIfReleased(const base::NativeEvent& xev) { |
| 709 ui::EventType type = ui::EventTypeFromNative(xev); | 749 ui::EventType type = ui::EventTypeFromNative(xev); |
| 710 if (type == ui::ET_TOUCH_CANCELLED || type == ui::ET_TOUCH_RELEASED) { | 750 if (type == ui::ET_TOUCH_CANCELLED || |
| 751 type == ui::ET_TOUCH_RELEASED) { |
| 711 ui::TouchFactory* factory = ui::TouchFactory::GetInstance(); | 752 ui::TouchFactory* factory = ui::TouchFactory::GetInstance(); |
| 712 ui::DeviceDataManagerX11* manager = ui::DeviceDataManagerX11::GetInstance(); | 753 ui::DeviceDataManagerX11* manager = ui::DeviceDataManagerX11::GetInstance(); |
| 713 double tracking_id; | 754 double tracking_id; |
| 714 if (manager->GetEventData(*xev, | 755 if (manager->GetEventData( |
| 715 ui::DeviceDataManagerX11::DT_TOUCH_TRACKING_ID, | 756 *xev, ui::DeviceDataManagerX11::DT_TOUCH_TRACKING_ID, &tracking_id)) { |
| 716 &tracking_id)) { | |
| 717 factory->ReleaseSlotForTrackingID(tracking_id); | 757 factory->ReleaseSlotForTrackingID(tracking_id); |
| 718 } | 758 } |
| 719 } | 759 } |
| 720 } | 760 } |
| 721 | 761 |
| 722 int GetTouchId(const base::NativeEvent& xev) { | 762 int GetTouchId(const base::NativeEvent& xev) { |
| 723 double slot = 0; | 763 double slot = 0; |
| 724 ui::DeviceDataManagerX11* manager = ui::DeviceDataManagerX11::GetInstance(); | 764 ui::DeviceDataManagerX11* manager = ui::DeviceDataManagerX11::GetInstance(); |
| 725 double tracking_id; | 765 double tracking_id; |
| 726 if (!manager->GetEventData( | 766 if (!manager->GetEventData( |
| 727 *xev, ui::DeviceDataManagerX11::DT_TOUCH_TRACKING_ID, &tracking_id)) { | 767 *xev, ui::DeviceDataManagerX11::DT_TOUCH_TRACKING_ID, &tracking_id)) { |
| 728 LOG(ERROR) << "Could not get the tracking ID for the event. Using 0."; | 768 LOG(ERROR) << "Could not get the tracking ID for the event. Using 0."; |
| 729 } else { | 769 } else { |
| 730 ui::TouchFactory* factory = ui::TouchFactory::GetInstance(); | 770 ui::TouchFactory* factory = ui::TouchFactory::GetInstance(); |
| 731 slot = factory->GetSlotForTrackingID(tracking_id); | 771 slot = factory->GetSlotForTrackingID(tracking_id); |
| 732 } | 772 } |
| 733 return slot; | 773 return slot; |
| 734 } | 774 } |
| 735 | 775 |
| 736 float GetTouchRadiusX(const base::NativeEvent& native_event) { | 776 float GetTouchRadiusX(const base::NativeEvent& native_event) { |
| 737 double radius = | 777 double radius = GetTouchParamFromXEvent(native_event, |
| 738 GetTouchParamFromXEvent(native_event, | 778 ui::DeviceDataManagerX11::DT_TOUCH_MAJOR, 0.0) / 2.0; |
| 739 ui::DeviceDataManagerX11::DT_TOUCH_MAJOR, 0.0) / | |
| 740 2.0; | |
| 741 ScaleTouchRadius(native_event, &radius); | 779 ScaleTouchRadius(native_event, &radius); |
| 742 return radius; | 780 return radius; |
| 743 } | 781 } |
| 744 | 782 |
| 745 float GetTouchRadiusY(const base::NativeEvent& native_event) { | 783 float GetTouchRadiusY(const base::NativeEvent& native_event) { |
| 746 double radius = | 784 double radius = GetTouchParamFromXEvent(native_event, |
| 747 GetTouchParamFromXEvent(native_event, | 785 ui::DeviceDataManagerX11::DT_TOUCH_MINOR, 0.0) / 2.0; |
| 748 ui::DeviceDataManagerX11::DT_TOUCH_MINOR, 0.0) / | |
| 749 2.0; | |
| 750 ScaleTouchRadius(native_event, &radius); | 786 ScaleTouchRadius(native_event, &radius); |
| 751 return radius; | 787 return radius; |
| 752 } | 788 } |
| 753 | 789 |
| 754 float GetTouchAngle(const base::NativeEvent& native_event) { | 790 float GetTouchAngle(const base::NativeEvent& native_event) { |
| 755 return GetTouchParamFromXEvent(native_event, | 791 return GetTouchParamFromXEvent(native_event, |
| 756 ui::DeviceDataManagerX11::DT_TOUCH_ORIENTATION, | 792 ui::DeviceDataManagerX11::DT_TOUCH_ORIENTATION, 0.0) / 2.0; |
| 757 0.0) / | |
| 758 2.0; | |
| 759 } | 793 } |
| 760 | 794 |
| 761 float GetTouchForce(const base::NativeEvent& native_event) { | 795 float GetTouchForce(const base::NativeEvent& native_event) { |
| 762 double force = 0.0; | 796 double force = 0.0; |
| 763 force = GetTouchParamFromXEvent( | 797 force = GetTouchParamFromXEvent(native_event, |
| 764 native_event, ui::DeviceDataManagerX11::DT_TOUCH_PRESSURE, 0.0); | 798 ui::DeviceDataManagerX11::DT_TOUCH_PRESSURE, 0.0); |
| 765 unsigned int deviceid = | 799 unsigned int deviceid = |
| 766 static_cast<XIDeviceEvent*>(native_event->xcookie.data)->sourceid; | 800 static_cast<XIDeviceEvent*>(native_event->xcookie.data)->sourceid; |
| 767 // Force is normalized to fall into [0, 1] | 801 // Force is normalized to fall into [0, 1] |
| 768 if (!ui::DeviceDataManagerX11::GetInstance()->NormalizeData( | 802 if (!ui::DeviceDataManagerX11::GetInstance()->NormalizeData( |
| 769 deviceid, ui::DeviceDataManagerX11::DT_TOUCH_PRESSURE, &force)) | 803 deviceid, ui::DeviceDataManagerX11::DT_TOUCH_PRESSURE, &force)) |
| 770 force = 0.0; | 804 force = 0.0; |
| 771 return force; | 805 return force; |
| 772 } | 806 } |
| 773 | 807 |
| 774 bool GetScrollOffsets(const base::NativeEvent& native_event, | 808 bool GetScrollOffsets(const base::NativeEvent& native_event, |
| 775 float* x_offset, | 809 float* x_offset, |
| 776 float* y_offset, | 810 float* y_offset, |
| 777 float* x_offset_ordinal, | 811 float* x_offset_ordinal, |
| 778 float* y_offset_ordinal, | 812 float* y_offset_ordinal, |
| 779 int* finger_count) { | 813 int* finger_count) { |
| 780 if (!DeviceDataManagerX11::GetInstance()->IsScrollEvent(native_event)) | 814 if (!DeviceDataManagerX11::GetInstance()->IsScrollEvent(native_event)) |
| 781 return false; | 815 return false; |
| 782 | 816 |
| 783 // Temp values to prevent passing NULLs to DeviceDataManager. | 817 // Temp values to prevent passing NULLs to DeviceDataManager. |
| 784 float x_offset_, y_offset_; | 818 float x_offset_, y_offset_; |
| 785 float x_offset_ordinal_, y_offset_ordinal_; | 819 float x_offset_ordinal_, y_offset_ordinal_; |
| 786 int finger_count_; | 820 int finger_count_; |
| 787 if (!x_offset) | 821 if (!x_offset) |
| 788 x_offset = &x_offset_; | 822 x_offset = &x_offset_; |
| 789 if (!y_offset) | 823 if (!y_offset) |
| 790 y_offset = &y_offset_; | 824 y_offset = &y_offset_; |
| 791 if (!x_offset_ordinal) | 825 if (!x_offset_ordinal) |
| 792 x_offset_ordinal = &x_offset_ordinal_; | 826 x_offset_ordinal = &x_offset_ordinal_; |
| 793 if (!y_offset_ordinal) | 827 if (!y_offset_ordinal) |
| 794 y_offset_ordinal = &y_offset_ordinal_; | 828 y_offset_ordinal = &y_offset_ordinal_; |
| 795 if (!finger_count) | 829 if (!finger_count) |
| 796 finger_count = &finger_count_; | 830 finger_count = &finger_count_; |
| 797 | 831 |
| 798 DeviceDataManagerX11::GetInstance()->GetScrollOffsets( | 832 DeviceDataManagerX11::GetInstance()->GetScrollOffsets( |
| 799 native_event, x_offset, y_offset, x_offset_ordinal, y_offset_ordinal, | 833 native_event, |
| 834 x_offset, y_offset, |
| 835 x_offset_ordinal, y_offset_ordinal, |
| 800 finger_count); | 836 finger_count); |
| 801 return true; | 837 return true; |
| 802 } | 838 } |
| 803 | 839 |
| 804 bool GetFlingData(const base::NativeEvent& native_event, | 840 bool GetFlingData(const base::NativeEvent& native_event, |
| 805 float* vx, | 841 float* vx, |
| 806 float* vy, | 842 float* vy, |
| 807 float* vx_ordinal, | 843 float* vx_ordinal, |
| 808 float* vy_ordinal, | 844 float* vy_ordinal, |
| 809 bool* is_cancel) { | 845 bool* is_cancel) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 822 if (!vy_ordinal) | 858 if (!vy_ordinal) |
| 823 vy_ordinal = &vy_ordinal_; | 859 vy_ordinal = &vy_ordinal_; |
| 824 if (!is_cancel) | 860 if (!is_cancel) |
| 825 is_cancel = &is_cancel_; | 861 is_cancel = &is_cancel_; |
| 826 | 862 |
| 827 DeviceDataManagerX11::GetInstance()->GetFlingData( | 863 DeviceDataManagerX11::GetInstance()->GetFlingData( |
| 828 native_event, vx, vy, vx_ordinal, vy_ordinal, is_cancel); | 864 native_event, vx, vy, vx_ordinal, vy_ordinal, is_cancel); |
| 829 return true; | 865 return true; |
| 830 } | 866 } |
| 831 | 867 |
| 868 void UpdateX11EventForFlags(Event* event) { |
| 869 XEvent* xev = event->native_event(); |
| 870 if (!xev) |
| 871 return; |
| 872 switch (xev->type) { |
| 873 case KeyPress: |
| 874 case KeyRelease: |
| 875 xev->xkey.state = UpdateX11EventFlags(event->flags(), xev->xkey.state); |
| 876 break; |
| 877 case ButtonPress: |
| 878 case ButtonRelease: |
| 879 xev->xbutton.state = |
| 880 UpdateX11EventFlags(event->flags(), xev->xbutton.state); |
| 881 break; |
| 882 case GenericEvent: { |
| 883 XIDeviceEvent* xievent = static_cast<XIDeviceEvent*>(xev->xcookie.data); |
| 884 DCHECK(xievent); |
| 885 xievent->mods.effective = |
| 886 UpdateX11EventFlags(event->flags(), xievent->mods.effective); |
| 887 break; |
| 888 } |
| 889 default: |
| 890 break; |
| 891 } |
| 892 } |
| 893 |
| 894 void UpdateX11EventForChangedButtonFlags(MouseEvent* event) { |
| 895 XEvent* xev = event->native_event(); |
| 896 if (!xev) |
| 897 return; |
| 898 switch (xev->type) { |
| 899 case ButtonPress: |
| 900 case ButtonRelease: |
| 901 xev->xbutton.button = UpdateX11EventButton(event->changed_button_flags(), |
| 902 xev->xbutton.button); |
| 903 break; |
| 904 case GenericEvent: { |
| 905 XIDeviceEvent* xievent = static_cast<XIDeviceEvent*>(xev->xcookie.data); |
| 906 CHECK(xievent && (xievent->evtype == XI_ButtonPress || |
| 907 xievent->evtype == XI_ButtonRelease)); |
| 908 xievent->detail = |
| 909 UpdateX11EventButton(event->changed_button_flags(), xievent->detail); |
| 910 break; |
| 911 } |
| 912 default: |
| 913 break; |
| 914 } |
| 915 } |
| 916 |
| 832 } // namespace ui | 917 } // namespace ui |
| OLD | NEW |