OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/base/events.h" | 5 #include "ui/base/events.h" |
6 | 6 |
7 #include <X11/extensions/XInput2.h> | 7 #include <X11/extensions/XInput2.h> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "ui/base/keycodes/keyboard_code_conversion_x.h" | 10 #include "ui/base/keycodes/keyboard_code_conversion_x.h" |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
240 gfx::Point EventLocationFromNative(const base::NativeEvent& native_event) { | 240 gfx::Point EventLocationFromNative(const base::NativeEvent& native_event) { |
241 switch (native_event->type) { | 241 switch (native_event->type) { |
242 case ButtonPress: | 242 case ButtonPress: |
243 case ButtonRelease: | 243 case ButtonRelease: |
244 return gfx::Point(native_event->xbutton.x, native_event->xbutton.y); | 244 return gfx::Point(native_event->xbutton.x, native_event->xbutton.y); |
245 case MotionNotify: | 245 case MotionNotify: |
246 return gfx::Point(native_event->xmotion.x, native_event->xmotion.y); | 246 return gfx::Point(native_event->xmotion.x, native_event->xmotion.y); |
247 case GenericEvent: { | 247 case GenericEvent: { |
248 XIDeviceEvent* xievent = | 248 XIDeviceEvent* xievent = |
249 static_cast<XIDeviceEvent*>(native_event->xcookie.data); | 249 static_cast<XIDeviceEvent*>(native_event->xcookie.data); |
250 return gfx::Point(static_cast<int>(xievent->event_x), | 250 |
251 static_cast<int>(xievent->event_y)); | 251 if (xievent->sourceid == xievent->deviceid) { |
252 // This event is coming from a slave device. Read the position from the | |
253 // valuators, because the events reported for a slave device seems to be | |
254 // behind the master device by one event. See more on crbug.com/103981. | |
255 // The position in the valuators is in the global screen coordinates. | |
256 // But it is necessary to convert it into the window's coordinates. | |
257 // Prepare to be revolted. | |
sadrul
2011/11/21 01:30:29
It's not all that bad, really.
| |
258 double x = xievent->valuators.values[0] - (xievent->root_x - | |
259 xievent->event_x); | |
260 double y = xievent->valuators.values[1] - (xievent->root_y - | |
261 xievent->event_y); | |
262 return gfx::Point(static_cast<int>(x), static_cast<int>(y)); | |
263 } else { | |
264 return gfx::Point(static_cast<int>(xievent->event_x), | |
265 static_cast<int>(xievent->event_y)); | |
266 } | |
252 } | 267 } |
253 } | 268 } |
254 return gfx::Point(); | 269 return gfx::Point(); |
255 } | 270 } |
256 | 271 |
257 KeyboardCode KeyboardCodeFromNative(const base::NativeEvent& native_event) { | 272 KeyboardCode KeyboardCodeFromNative(const base::NativeEvent& native_event) { |
258 return KeyboardCodeFromXKeyEvent(native_event); | 273 return KeyboardCodeFromXKeyEvent(native_event); |
259 } | 274 } |
260 | 275 |
261 bool IsMouseEvent(const base::NativeEvent& native_event) { | 276 bool IsMouseEvent(const base::NativeEvent& native_event) { |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
348 unsigned int deviceid = | 363 unsigned int deviceid = |
349 static_cast<XIDeviceEvent*>(native_event->xcookie.data)->sourceid; | 364 static_cast<XIDeviceEvent*>(native_event->xcookie.data)->sourceid; |
350 // Force is normalized to fall into [0, 1] | 365 // Force is normalized to fall into [0, 1] |
351 if (!ui::TouchFactory::GetInstance()->NormalizeTouchParam( | 366 if (!ui::TouchFactory::GetInstance()->NormalizeTouchParam( |
352 deviceid, ui::TouchFactory::TP_PRESSURE, &force)) | 367 deviceid, ui::TouchFactory::TP_PRESSURE, &force)) |
353 force = 0.0; | 368 force = 0.0; |
354 return force; | 369 return force; |
355 } | 370 } |
356 | 371 |
357 } // namespace ui | 372 } // namespace ui |
OLD | NEW |