summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorskuhne@chromium.org <skuhne@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-05-07 22:44:58 +0000
committerskuhne@chromium.org <skuhne@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-05-07 22:44:58 +0000
commit9b75ac5386e0ba975f36f706be8a0fd78d7c4e8a (patch)
treec44f6ee0fcc64d21ccaf1f989c6e972234550a24
parentc6c8cfeedfc02c9fc9d09b8a0bd07a6d6275b624 (diff)
downloadchromium_src-9b75ac5386e0ba975f36f706be8a0fd78d7c4e8a.zip
chromium_src-9b75ac5386e0ba975f36f706be8a0fd78d7c4e8a.tar.gz
chromium_src-9b75ac5386e0ba975f36f706be8a0fd78d7c4e8a.tar.bz2
Calibrating touch input
BUG=116890 TEST=None, manually tested Review URL: https://chromiumcodereview.appspot.com/10306014 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@135747 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--ui/aura/root_window.cc11
-rw-r--r--ui/base/ui_base_switches.cc6
-rw-r--r--ui/base/ui_base_switches.h1
-rw-r--r--ui/base/x/events_x.cc64
4 files changed, 77 insertions, 5 deletions
diff --git a/ui/aura/root_window.cc b/ui/aura/root_window.cc
index 8481d40..3c67f34 100644
--- a/ui/aura/root_window.cc
+++ b/ui/aura/root_window.cc
@@ -311,6 +311,7 @@ bool RootWindow::DispatchTouchEvent(TouchEvent* event) {
// root window.
target = this;
} else {
+ // We only come here when the first contact was within the root window.
if (!target)
target = GetEventHandlerForPoint(event->location());
if (!target)
@@ -659,7 +660,10 @@ ui::TouchStatus RootWindow::ProcessTouchEvent(Window* target,
return ui::TOUCH_STATUS_UNKNOWN;
EventFilters filters;
- GetEventFiltersToNotify(target->parent(), &filters);
+ if (target == this)
+ GetEventFiltersToNotify(target, &filters);
+ else
+ GetEventFiltersToNotify(target->parent(), &filters);
for (EventFilters::const_reverse_iterator it = filters.rbegin(),
rend = filters.rend();
it != rend; ++it) {
@@ -668,7 +672,10 @@ ui::TouchStatus RootWindow::ProcessTouchEvent(Window* target,
return status;
}
- return target->delegate()->OnTouchEvent(event);
+ if (target->delegate())
+ return target->delegate()->OnTouchEvent(event);
+
+ return ui::TOUCH_STATUS_UNKNOWN;
}
ui::GestureStatus RootWindow::ProcessGestureEvent(Window* target,
diff --git a/ui/base/ui_base_switches.cc b/ui/base/ui_base_switches.cc
index d1a2597..67ef448 100644
--- a/ui/base/ui_base_switches.cc
+++ b/ui/base/ui_base_switches.cc
@@ -8,7 +8,10 @@ namespace switches {
// The default device scale factor to apply to the browser UI and
// the contents in the absence of a viewport meta tag.
-const char kDefaultDeviceScaleFactor[] = "default-device-scale-factor";
+const char kDefaultDeviceScaleFactor[] = "default-device-scale-factor";
+
+// Enable touch screen calibration.
+const char kDisableTouchCalibration[] = "disable-touch-calibration";
// Enable support for touch events.
const char kEnableTouchEvents[] = "enable-touch-events";
@@ -28,6 +31,7 @@ const char kNoMessageBox[] = "no-message-box";
// Enables UI changes that make it easier to use with a touchscreen.
const char kTouchOptimizedUI[] = "touch-optimized-ui";
+
#if defined(OS_MACOSX)
const char kDisableCompositedCoreAnimationPlugins[] =
"disable-composited-core-animation-plugins";
diff --git a/ui/base/ui_base_switches.h b/ui/base/ui_base_switches.h
index b67b2b8..14b4fc7 100644
--- a/ui/base/ui_base_switches.h
+++ b/ui/base/ui_base_switches.h
@@ -14,6 +14,7 @@
namespace switches {
UI_EXPORT extern const char kDefaultDeviceScaleFactor[];
+UI_EXPORT extern const char kDisableTouchCalibration[];
UI_EXPORT extern const char kEnableTouchEvents[];
UI_EXPORT extern const char kLang[];
UI_EXPORT extern const char kLocalePak[];
diff --git a/ui/base/x/events_x.cc b/ui/base/x/events_x.cc
index 61fb944..1a0a146 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"
@@ -511,6 +516,61 @@ Atom GetNoopEventAtom() {
"noop", False);
}
+#if defined(USE_XI2_MT)
+gfx::Point CalibrateTouchCoordinates(
+ 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();
+ const int kLeftBorder = 50;
+ const int kRightBorder = 50;
+ const int kBottomBorder = 50;
+ const int kTopBorder = 0;
+ const int resolution_x = bounds.width();
+ const 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.
+ const 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 y position to the real
+ 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 // defined(USE_XI2_MT)
+
} // namespace
namespace ui {
@@ -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