Chromium Code Reviews| 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/gfx/point.h" | 14 #include "ui/gfx/point.h" |
| 15 | 15 |
| 16 #if !defined(TOOLKIT_USES_GTK) | 16 #if !defined(TOOLKIT_USES_GTK) |
| 17 #include "base/message_pump_x.h" | 17 #include "base/message_pump_x.h" |
| 18 #endif | 18 #endif |
| 19 | 19 |
| 20 namespace { | 20 namespace { |
| 21 | 21 |
| 22 // Scroll amount for each wheelscroll event. 53 is also the value used for GTK+. | 22 // Scroll amount for each wheelscroll event. 53 is also the value used for GTK+. |
| 23 static const int kWheelScrollAmount = 53; | 23 static const int kWheelScrollAmount = 53; |
| 24 | 24 |
| 25 static const int kMinWheelButton = 4; | 25 static const int kMinWheelButton = 4; |
| 26 #if defined(OS_CHROMEOS) | 26 #if defined(OS_CHROMEOS) |
| 27 // TODO(davemoore) For now use the button to decide how much to scroll by | |
|
Daniel Erat
2011/12/05 23:47:15
nit: add trailing period
| |
| 28 // When we go to XI2 scroll events this won't be necessary. If this doesn't | |
| 29 // happen for some reason we can better detect which devices are touchpads. | |
| 30 static const int kTouchpadScrollAmount = 3; | |
| 27 // Chrome OS also uses buttons 8 and 9 for scrolling. | 31 // Chrome OS also uses buttons 8 and 9 for scrolling. |
| 28 static const int kMaxWheelButton = 9; | 32 static const int kMaxWheelButton = 9; |
| 29 #else | 33 #else |
| 30 static const int kMaxWheelButton = 7; | 34 static const int kMaxWheelButton = 7; |
| 31 #endif | 35 #endif |
| 32 | 36 |
| 33 int GetEventFlagsFromXState(unsigned int state) { | 37 int GetEventFlagsFromXState(unsigned int state) { |
| 34 int flags = 0; | 38 int flags = 0; |
| 35 if (state & ControlMask) | 39 if (state & ControlMask) |
| 36 flags |= ui::EF_CONTROL_DOWN; | 40 flags |= ui::EF_CONTROL_DOWN; |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 305 if (native_event->type == GenericEvent) { | 309 if (native_event->type == GenericEvent) { |
| 306 XIDeviceEvent* xiev = | 310 XIDeviceEvent* xiev = |
| 307 static_cast<XIDeviceEvent*>(native_event->xcookie.data); | 311 static_cast<XIDeviceEvent*>(native_event->xcookie.data); |
| 308 button = xiev->detail; | 312 button = xiev->detail; |
| 309 } else { | 313 } else { |
| 310 button = native_event->xbutton.button; | 314 button = native_event->xbutton.button; |
| 311 } | 315 } |
| 312 switch (button) { | 316 switch (button) { |
| 313 case 4: | 317 case 4: |
| 314 #if defined(OS_CHROMEOS) | 318 #if defined(OS_CHROMEOS) |
| 319 return kTouchpadScrollAmount; | |
| 315 case 8: | 320 case 8: |
| 316 #endif | 321 #endif |
| 317 return kWheelScrollAmount; | 322 return kWheelScrollAmount; |
| 318 | 323 |
| 319 case 5: | 324 case 5: |
| 320 #if defined(OS_CHROMEOS) | 325 #if defined(OS_CHROMEOS) |
| 326 return -kTouchpadScrollAmount; | |
| 321 case 9: | 327 case 9: |
| 322 #endif | 328 #endif |
| 323 return -kWheelScrollAmount; | 329 return -kWheelScrollAmount; |
| 324 | 330 |
| 325 default: | 331 default: |
| 326 // TODO(derat): Do something for horizontal scrolls (buttons 6 and 7)? | 332 // TODO(derat): Do something for horizontal scrolls (buttons 6 and 7)? |
| 327 return 0; | 333 return 0; |
| 328 } | 334 } |
| 329 } | 335 } |
| 330 | 336 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 398 // Make sure we use atom from current xdisplay, which may | 404 // Make sure we use atom from current xdisplay, which may |
| 399 // change during the test. | 405 // change during the test. |
| 400 noop->xclient.message_type = XInternAtom( | 406 noop->xclient.message_type = XInternAtom( |
| 401 base::MessagePumpX::GetDefaultXDisplay(), | 407 base::MessagePumpX::GetDefaultXDisplay(), |
| 402 "noop", False); | 408 "noop", False); |
| 403 #endif | 409 #endif |
| 404 return noop; | 410 return noop; |
| 405 } | 411 } |
| 406 | 412 |
| 407 } // namespace ui | 413 } // namespace ui |
| OLD | NEW |