Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(399)

Unified Diff: ui/base/x/events_x.cc

Issue 10306014: Calibrating touch input (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« ui/base/ui_base_switches.cc ('K') | « ui/base/ui_base_switches.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/base/x/events_x.cc
diff --git a/ui/base/x/events_x.cc b/ui/base/x/events_x.cc
index 61fb9443c6c29e189540203e40fdba6b86831f1a..8c0d7de92e63f0bdc32e6397e31206f00682e131 100644
--- a/ui/base/x/events_x.cc
+++ b/ui/base/x/events_x.cc
@@ -9,12 +9,17 @@
#include <X11/extensions/XInput2.h>
#include <string.h>
+#include "base/command_line.h"
#include "base/logging.h"
#include "base/message_pump_x.h"
#include "ui/base/keycodes/keyboard_code_conversion_x.h"
+#include "ui/base/ui_base_switches.h"
#include "ui/base/touch/touch_factory.h"
#include "ui/base/x/x11_util.h"
#include "ui/gfx/point.h"
+#include "ui/gfx/monitor.h"
+#include "ui/gfx/rect.h"
+#include "ui/gfx/screen.h"
// Copied from xserver-properties.h
#define AXIS_LABEL_PROP_REL_HWHEEL "Rel Horiz Wheel"
@@ -675,6 +680,61 @@ base::TimeDelta EventTimeFromNative(const base::NativeEvent& native_event) {
return base::TimeDelta();
}
+#if defined(USE_XI2_MT)
+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.
+ const XIDeviceEvent* xievent) {
+ int x = static_cast<int>(xievent->event_x);
+ int y = static_cast<int>(xievent->event_y);
+ if (CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kDisableTouchCalibration))
+ return gfx::Point(x, y);
+ // TODO(skuhne): Find a new home for these hardware dependent touch
+ // constants.
+ // Note: These values have been found to be correct for the device I was
+ // testing with. I have the feeling that the DPI resolution of the bezel is
+ // less then the dpi resolution over the visible part - which would explain
+ // why the small value (50) is so wide compared to the entire area.
+ 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
+ int kLeftBorder = 50;
sadrul 2012/05/04 14:02:56 const these
Mr4D (OOO till 08-26) 2012/05/04 15:01:06 Done.
+ int kRightBorder = 50;
+ int kBottomBorder = 50;
+ int kTopBorder = 0;
+ int resolution_x = bounds.width();
+ int resolution_y = bounds.height();
+ // The "grace area" (10% in this case) is to make it easier for the user to
+ // navigate to the corner.
+ double kGraceAreaFraction = 0.1;
+ // Offset the x position to the real
+ x -= kLeftBorder;
+ // Check if we are in the grace area of the left side.
+ // Note: We might not want to do this when the gesture is locked?
+ if (x < 0 && x > -kLeftBorder * kGraceAreaFraction)
+ x = 0;
+ // Check if we are in the grace area of the right side.
+ // Note: We might not want to do this when the gesture is locked?
+ if (x > resolution_x - kLeftBorder &&
+ x < resolution_x - kLeftBorder + kRightBorder * kGraceAreaFraction)
+ x = resolution_x - kLeftBorder;
+ // Scale the screen area back to the full resolution of the screen.
+ x = (x * resolution_x) / (resolution_x - (kRightBorder + kLeftBorder));
+ // 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.
+ y -= kTopBorder;
+ // Check if we are in the grace area of the left side.
+ // Note: We might not want to do this when the gesture is locked?
+ if (y < 0 && y > -kTopBorder * kGraceAreaFraction)
+ y = 0;
+ // Check if we are in the grace area of the right side.
+ // Note: We might not want to do this when the gesture is locked?
+ if (y > resolution_y - kTopBorder &&
+ y < resolution_y - kTopBorder + kBottomBorder * kGraceAreaFraction)
+ y = resolution_y - kTopBorder;
+ // Scale the screen area back to the full resolution of the screen.
+ y = (y * resolution_y) / (resolution_y - (kBottomBorder + kTopBorder));
+ // Set the modified coordinate back to the event.
+ return gfx::Point(x, y);
+}
+#endif
+
gfx::Point EventLocationFromNative(const base::NativeEvent& native_event) {
switch (native_event->type) {
case ButtonPress:
@@ -692,8 +752,8 @@ gfx::Point EventLocationFromNative(const base::NativeEvent& native_event) {
if (xievent->evtype == XI_TouchBegin ||
xievent->evtype == XI_TouchUpdate ||
xievent->evtype == XI_TouchEnd)
- return gfx::Point(static_cast<int>(xievent->event_x),
- static_cast<int>(xievent->event_y));
+ // Note: Touch events are always touch screen events.
+ return CalibrateTouchCoordinates(xievent);
#endif
// Read the position from the valuators, because the location reported in
// event_x/event_y seems to be different (and doesn't match for events
« ui/base/ui_base_switches.cc ('K') | « ui/base/ui_base_switches.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698