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/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/XInput.h> | 8 #include <X11/extensions/XInput.h> |
9 #include <X11/extensions/XInput2.h> | 9 #include <X11/extensions/XInput2.h> |
10 #include <string.h> | 10 #include <string.h> |
11 | 11 |
12 #include "base/command_line.h" | |
12 #include "base/logging.h" | 13 #include "base/logging.h" |
13 #include "base/message_pump_x.h" | 14 #include "base/message_pump_x.h" |
14 #include "ui/base/keycodes/keyboard_code_conversion_x.h" | 15 #include "ui/base/keycodes/keyboard_code_conversion_x.h" |
16 #include "ui/base/ui_base_switches.h" | |
15 #include "ui/base/touch/touch_factory.h" | 17 #include "ui/base/touch/touch_factory.h" |
16 #include "ui/base/x/x11_util.h" | 18 #include "ui/base/x/x11_util.h" |
17 #include "ui/gfx/point.h" | 19 #include "ui/gfx/point.h" |
20 #include "ui/gfx/monitor.h" | |
21 #include "ui/gfx/rect.h" | |
22 #include "ui/gfx/screen.h" | |
18 | 23 |
19 // Copied from xserver-properties.h | 24 // Copied from xserver-properties.h |
20 #define AXIS_LABEL_PROP_REL_HWHEEL "Rel Horiz Wheel" | 25 #define AXIS_LABEL_PROP_REL_HWHEEL "Rel Horiz Wheel" |
21 #define AXIS_LABEL_PROP_REL_WHEEL "Rel Vert Wheel" | 26 #define AXIS_LABEL_PROP_REL_WHEEL "Rel Vert Wheel" |
22 | 27 |
23 // CMT specific timings | 28 // CMT specific timings |
24 #define AXIS_LABEL_PROP_ABS_START_TIME "Abs Start Timestamp" | 29 #define AXIS_LABEL_PROP_ABS_START_TIME "Abs Start Timestamp" |
25 #define AXIS_LABEL_PROP_ABS_END_TIME "Abs End Timestamp" | 30 #define AXIS_LABEL_PROP_ABS_END_TIME "Abs End Timestamp" |
26 | 31 |
27 // Fling properties | 32 // Fling properties |
(...skipping 640 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
668 static_cast<XIDeviceEvent*>(native_event->xcookie.data); | 673 static_cast<XIDeviceEvent*>(native_event->xcookie.data); |
669 return base::TimeDelta::FromMilliseconds(xide->time); | 674 return base::TimeDelta::FromMilliseconds(xide->time); |
670 } | 675 } |
671 break; | 676 break; |
672 } | 677 } |
673 } | 678 } |
674 NOTREACHED(); | 679 NOTREACHED(); |
675 return base::TimeDelta(); | 680 return base::TimeDelta(); |
676 } | 681 } |
677 | 682 |
683 #if defined(USE_XI2_MT) | |
684 gfx::Point CalibrateTouchCoordinates( | |
sadrul
2012/05/04 14:02:56
This should be inside the anonymous namespace abov
Mr4D (OOO till 08-26)
2012/05/04 15:01:06
Done.
| |
685 const XIDeviceEvent* xievent) { | |
686 int x = static_cast<int>(xievent->event_x); | |
687 int y = static_cast<int>(xievent->event_y); | |
688 if (CommandLine::ForCurrentProcess()->HasSwitch( | |
689 switches::kDisableTouchCalibration)) | |
690 return gfx::Point(x, y); | |
691 // TODO(skuhne): Find a new home for these hardware dependent touch | |
692 // constants. | |
693 // Note: These values have been found to be correct for the device I was | |
694 // testing with. I have the feeling that the DPI resolution of the bezel is | |
695 // less then the dpi resolution over the visible part - which would explain | |
696 // why the small value (50) is so wide compared to the entire area. | |
697 gfx::Rect bounds = gfx::Screen::GetPrimaryMonitor().bounds_in_pixel(); | |
sadrul
2012/05/04 14:02:56
Perhaps using GetMonitorNearestPoint would be bett
Mr4D (OOO till 08-26)
2012/05/04 15:01:06
First I thought this is a good idea, but then I th
| |
698 int kLeftBorder = 50; | |
sadrul
2012/05/04 14:02:56
const these
Mr4D (OOO till 08-26)
2012/05/04 15:01:06
Done.
| |
699 int kRightBorder = 50; | |
700 int kBottomBorder = 50; | |
701 int kTopBorder = 0; | |
702 int resolution_x = bounds.width(); | |
703 int resolution_y = bounds.height(); | |
704 // The "grace area" (10% in this case) is to make it easier for the user to | |
705 // navigate to the corner. | |
706 double kGraceAreaFraction = 0.1; | |
707 // Offset the x position to the real | |
708 x -= kLeftBorder; | |
709 // Check if we are in the grace area of the left side. | |
710 // Note: We might not want to do this when the gesture is locked? | |
711 if (x < 0 && x > -kLeftBorder * kGraceAreaFraction) | |
712 x = 0; | |
713 // Check if we are in the grace area of the right side. | |
714 // Note: We might not want to do this when the gesture is locked? | |
715 if (x > resolution_x - kLeftBorder && | |
716 x < resolution_x - kLeftBorder + kRightBorder * kGraceAreaFraction) | |
717 x = resolution_x - kLeftBorder; | |
718 // Scale the screen area back to the full resolution of the screen. | |
719 x = (x * resolution_x) / (resolution_x - (kRightBorder + kLeftBorder)); | |
720 // Offset the x position to the real | |
sadrul
2012/05/04 14:02:56
the y position
Mr4D (OOO till 08-26)
2012/05/04 15:01:06
Done.
| |
721 y -= kTopBorder; | |
722 // Check if we are in the grace area of the left side. | |
723 // Note: We might not want to do this when the gesture is locked? | |
724 if (y < 0 && y > -kTopBorder * kGraceAreaFraction) | |
725 y = 0; | |
726 // Check if we are in the grace area of the right side. | |
727 // Note: We might not want to do this when the gesture is locked? | |
728 if (y > resolution_y - kTopBorder && | |
729 y < resolution_y - kTopBorder + kBottomBorder * kGraceAreaFraction) | |
730 y = resolution_y - kTopBorder; | |
731 // Scale the screen area back to the full resolution of the screen. | |
732 y = (y * resolution_y) / (resolution_y - (kBottomBorder + kTopBorder)); | |
733 // Set the modified coordinate back to the event. | |
734 return gfx::Point(x, y); | |
735 } | |
736 #endif | |
737 | |
678 gfx::Point EventLocationFromNative(const base::NativeEvent& native_event) { | 738 gfx::Point EventLocationFromNative(const base::NativeEvent& native_event) { |
679 switch (native_event->type) { | 739 switch (native_event->type) { |
680 case ButtonPress: | 740 case ButtonPress: |
681 case ButtonRelease: | 741 case ButtonRelease: |
682 return gfx::Point(native_event->xbutton.x, native_event->xbutton.y); | 742 return gfx::Point(native_event->xbutton.x, native_event->xbutton.y); |
683 case MotionNotify: | 743 case MotionNotify: |
684 return gfx::Point(native_event->xmotion.x, native_event->xmotion.y); | 744 return gfx::Point(native_event->xmotion.x, native_event->xmotion.y); |
685 case GenericEvent: { | 745 case GenericEvent: { |
686 XIDeviceEvent* xievent = | 746 XIDeviceEvent* xievent = |
687 static_cast<XIDeviceEvent*>(native_event->xcookie.data); | 747 static_cast<XIDeviceEvent*>(native_event->xcookie.data); |
688 | 748 |
689 #if defined(USE_XI2_MT) | 749 #if defined(USE_XI2_MT) |
690 // Touch event valuators aren't coordinates. | 750 // Touch event valuators aren't coordinates. |
691 // Return the |event_x|/|event_y| directly as event's position. | 751 // Return the |event_x|/|event_y| directly as event's position. |
692 if (xievent->evtype == XI_TouchBegin || | 752 if (xievent->evtype == XI_TouchBegin || |
693 xievent->evtype == XI_TouchUpdate || | 753 xievent->evtype == XI_TouchUpdate || |
694 xievent->evtype == XI_TouchEnd) | 754 xievent->evtype == XI_TouchEnd) |
695 return gfx::Point(static_cast<int>(xievent->event_x), | 755 // Note: Touch events are always touch screen events. |
696 static_cast<int>(xievent->event_y)); | 756 return CalibrateTouchCoordinates(xievent); |
697 #endif | 757 #endif |
698 // Read the position from the valuators, because the location reported in | 758 // Read the position from the valuators, because the location reported in |
699 // event_x/event_y seems to be different (and doesn't match for events | 759 // event_x/event_y seems to be different (and doesn't match for events |
700 // coming from slave device and master device) from the values in the | 760 // coming from slave device and master device) from the values in the |
701 // valuators. See more on crbug.com/103981. The position in the valuators | 761 // valuators. See more on crbug.com/103981. The position in the valuators |
702 // is in the global screen coordinates. But it is necessary to convert it | 762 // is in the global screen coordinates. But it is necessary to convert it |
703 // into the window's coordinates. If the valuator is not set, that means | 763 // into the window's coordinates. If the valuator is not set, that means |
704 // the value hasn't changed, and so we can use the value from | 764 // the value hasn't changed, and so we can use the value from |
705 // event_x/event_y (which are in the window's coordinates). | 765 // event_x/event_y (which are in the window's coordinates). |
706 double* valuators = xievent->valuators.values; | 766 double* valuators = xievent->valuators.values; |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
871 noop->xclient.format = 8; | 931 noop->xclient.format = 8; |
872 DCHECK(!noop->xclient.display); | 932 DCHECK(!noop->xclient.display); |
873 } | 933 } |
874 // Make sure we use atom from current xdisplay, which may | 934 // Make sure we use atom from current xdisplay, which may |
875 // change during the test. | 935 // change during the test. |
876 noop->xclient.message_type = GetNoopEventAtom(); | 936 noop->xclient.message_type = GetNoopEventAtom(); |
877 return noop; | 937 return noop; |
878 } | 938 } |
879 | 939 |
880 } // namespace ui | 940 } // namespace ui |
OLD | NEW |