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/Xlib.h> | 7 #include <X11/Xlib.h> |
8 #include <X11/extensions/XInput2.h> | 8 #include <X11/extensions/XInput2.h> |
9 #include <string.h> | 9 #include <string.h> |
10 | 10 |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "ui/base/keycodes/keyboard_code_conversion_x.h" | 12 #include "ui/base/keycodes/keyboard_code_conversion_x.h" |
13 #include "ui/base/touch/touch_factory.h" | 13 #include "ui/base/touch/touch_factory.h" |
| 14 #include "ui/base/x/scroll_factory.h" |
14 #include "ui/base/x/x11_util.h" | 15 #include "ui/base/x/x11_util.h" |
15 #include "ui/gfx/point.h" | 16 #include "ui/gfx/point.h" |
16 | 17 |
17 #if !defined(TOOLKIT_USES_GTK) | 18 #if !defined(TOOLKIT_USES_GTK) |
18 #include "base/message_pump_x.h" | 19 #include "base/message_pump_x.h" |
19 #endif | 20 #endif |
20 | 21 |
21 namespace { | 22 namespace { |
22 | 23 |
23 // Scroll amount for each wheelscroll event. 53 is also the value used for GTK+. | 24 // Scroll amount for each wheelscroll event. 53 is also the value used for GTK+. |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 return ET_MOUSE_MOVED; | 186 return ET_MOUSE_MOVED; |
186 case EnterNotify: | 187 case EnterNotify: |
187 return ET_MOUSE_ENTERED; | 188 return ET_MOUSE_ENTERED; |
188 case LeaveNotify: | 189 case LeaveNotify: |
189 return ET_MOUSE_EXITED; | 190 return ET_MOUSE_EXITED; |
190 case GenericEvent: { | 191 case GenericEvent: { |
191 XIDeviceEvent* xievent = | 192 XIDeviceEvent* xievent = |
192 static_cast<XIDeviceEvent*>(native_event->xcookie.data); | 193 static_cast<XIDeviceEvent*>(native_event->xcookie.data); |
193 if (TouchFactory::GetInstance()->IsTouchDevice(xievent->sourceid)) | 194 if (TouchFactory::GetInstance()->IsTouchDevice(xievent->sourceid)) |
194 return GetTouchEventType(native_event); | 195 return GetTouchEventType(native_event); |
195 int button = EventButtonFromNative(native_event); | |
196 switch (xievent->evtype) { | 196 switch (xievent->evtype) { |
197 case XI_ButtonPress: | 197 case XI_ButtonPress: |
198 if (button >= kMinWheelButton && | 198 case XI_ButtonRelease: { |
199 button <= kMaxWheelButton) | 199 int button = EventButtonFromNative(native_event); |
| 200 if (button >= kMinWheelButton && button <= kMaxWheelButton) |
200 return ET_MOUSEWHEEL; | 201 return ET_MOUSEWHEEL; |
201 return ET_MOUSE_PRESSED; | 202 return xievent->evtype == XI_ButtonPress ? |
202 case XI_ButtonRelease: | 203 ET_MOUSE_PRESSED : ET_MOUSE_RELEASED; |
203 if (button >= kMinWheelButton && | 204 } |
204 button <= kMaxWheelButton) | |
205 return ET_MOUSEWHEEL; | |
206 return ET_MOUSE_RELEASED; | |
207 case XI_Motion: | 205 case XI_Motion: |
208 return GetButtonMaskForX2Event(xievent) ? | 206 if (GetScrollOffsets(native_event, NULL, NULL)) |
209 ET_MOUSE_DRAGGED : ET_MOUSE_MOVED; | 207 return ET_SCROLL; |
| 208 else if (GetButtonMaskForX2Event(xievent)) |
| 209 return ET_MOUSE_DRAGGED; |
| 210 else |
| 211 return ET_MOUSE_MOVED; |
210 } | 212 } |
211 } | 213 } |
212 default: | 214 default: |
213 break; | 215 break; |
214 } | 216 } |
215 return ET_UNKNOWN; | 217 return ET_UNKNOWN; |
216 } | 218 } |
217 | 219 |
218 int EventFlagsFromNative(const base::NativeEvent& native_event) { | 220 int EventFlagsFromNative(const base::NativeEvent& native_event) { |
219 switch (native_event->type) { | 221 switch (native_event->type) { |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
398 0.0); | 400 0.0); |
399 unsigned int deviceid = | 401 unsigned int deviceid = |
400 static_cast<XIDeviceEvent*>(native_event->xcookie.data)->sourceid; | 402 static_cast<XIDeviceEvent*>(native_event->xcookie.data)->sourceid; |
401 // Force is normalized to fall into [0, 1] | 403 // Force is normalized to fall into [0, 1] |
402 if (!ui::TouchFactory::GetInstance()->NormalizeTouchParam( | 404 if (!ui::TouchFactory::GetInstance()->NormalizeTouchParam( |
403 deviceid, ui::TouchFactory::TP_PRESSURE, &force)) | 405 deviceid, ui::TouchFactory::TP_PRESSURE, &force)) |
404 force = 0.0; | 406 force = 0.0; |
405 return force; | 407 return force; |
406 } | 408 } |
407 | 409 |
| 410 bool GetScrollOffsets(const base::NativeEvent& native_event, |
| 411 float* x_offset, |
| 412 float* y_offset) { |
| 413 return ui::ScrollFactory::GetInstance()->GetScrollOffsets( |
| 414 *native_event, x_offset, y_offset); |
| 415 } |
| 416 |
408 base::NativeEvent CreateNoopEvent() { | 417 base::NativeEvent CreateNoopEvent() { |
409 static XEvent* noop = NULL; | 418 static XEvent* noop = NULL; |
410 if (!noop) { | 419 if (!noop) { |
411 noop = new XEvent(); | 420 noop = new XEvent(); |
412 memset(noop, 0, sizeof(XEvent)); | 421 memset(noop, 0, sizeof(XEvent)); |
413 noop->xclient.type = ClientMessage; | 422 noop->xclient.type = ClientMessage; |
414 noop->xclient.window = None; | 423 noop->xclient.window = None; |
415 noop->xclient.format = 8; | 424 noop->xclient.format = 8; |
416 DCHECK(!noop->xclient.display); | 425 DCHECK(!noop->xclient.display); |
417 } | 426 } |
418 // TODO(oshima): Remove ifdef once gtk is removed from views. | 427 // TODO(oshima): Remove ifdef once gtk is removed from views. |
419 #if defined(TOOLKIT_USES_GTK) | 428 #if defined(TOOLKIT_USES_GTK) |
420 NOTREACHED(); | 429 NOTREACHED(); |
421 #else | 430 #else |
422 // Make sure we use atom from current xdisplay, which may | 431 // Make sure we use atom from current xdisplay, which may |
423 // change during the test. | 432 // change during the test. |
424 noop->xclient.message_type = XInternAtom( | 433 noop->xclient.message_type = XInternAtom( |
425 base::MessagePumpX::GetDefaultXDisplay(), | 434 base::MessagePumpX::GetDefaultXDisplay(), |
426 "noop", False); | 435 "noop", False); |
427 #endif | 436 #endif |
428 return noop; | 437 return noop; |
429 } | 438 } |
430 | 439 |
431 } // namespace ui | 440 } // namespace ui |
OLD | NEW |