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

Unified Diff: ui/base/events/event.cc

Issue 12087124: Disable touch calibration on external touchscreen. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fix Win compilation take 2 + rebase Created 7 years, 11 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
Index: ui/base/events/event.cc
diff --git a/ui/base/events/event.cc b/ui/base/events/event.cc
index c06b6046b72742f7e74112865ed623dac099717b..4512ce8058ba45a223e341e03b9501e9a609eff0 100644
--- a/ui/base/events/event.cc
+++ b/ui/base/events/event.cc
@@ -11,10 +11,14 @@
#include <cmath>
#include <cstring>
+#include "base/command_line.h"
#include "base/metrics/histogram.h"
+#include "base/string_number_conversions.h"
+#include "base/string_split.h"
#include "base/stringprintf.h"
#include "ui/base/events/event_utils.h"
#include "ui/base/keycodes/keyboard_code_conversion.h"
+#include "ui/base/ui_base_switches.h"
#include "ui/gfx/point3_f.h"
#include "ui/gfx/point_conversions.h"
#include "ui/gfx/transform.h"
@@ -406,6 +410,91 @@ const int MouseWheelEvent::kWheelDelta = 120;
const int MouseWheelEvent::kWheelDelta = 53;
#endif
+#if defined(USE_XI2_MT)
+////////////////////////////////////////////////////////////////////////////////
+// TouchCoordinatesCalibrator
+
+TouchCoordinatesCalibrator::TouchCoordinatesCalibrator()
+ : left_border_touch_calibration(0),
+ right_border_touch_calibration(0),
+ top_border_touch_calibration(0),
+ bottom_border_touch_calibration(0) {
+ std::vector<std::string> parts;
+ base::SplitString(CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
+ switches::kTouchCalibration), ',', &parts);
+ if (parts.size() >= 4) {
+ if (!base::StringToInt(parts[0], &left_border_touch_calibration))
+ DLOG(ERROR) << "Incorrect left border calibration value passed.";
+ if (!base::StringToInt(parts[1], &right_border_touch_calibration))
+ DLOG(ERROR) << "Incorrect right border calibration value passed.";
+ if (!base::StringToInt(parts[2], &top_border_touch_calibration))
+ DLOG(ERROR) << "Incorrect top border calibration value passed.";
+ if (!base::StringToInt(parts[3], &bottom_border_touch_calibration))
+ DLOG(ERROR) << "Incorrect bottom border calibration value passed.";
+ }
+}
+
+TouchCoordinatesCalibrator* TouchCoordinatesCalibrator::GetInstance() {
+ return Singleton<TouchCoordinatesCalibrator>::get();
+}
+
+void TouchCoordinatesCalibrator::Calibrate(TouchEvent& event,
+ const gfx::Rect& bounds) {
+ int x = event.x();
+ int y = event.y();
+
+ if (!left_border_touch_calibration && !right_border_touch_calibration &&
+ !top_border_touch_calibration && !bottom_border_touch_calibration)
+ return;
+
+ 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;
+ if (left_border_touch_calibration || right_border_touch_calibration) {
+ // Offset the x position to the real
+ x -= left_border_touch_calibration;
+ // 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 > -left_border_touch_calibration * 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 - left_border_touch_calibration &&
+ x < resolution_x - left_border_touch_calibration +
+ right_border_touch_calibration * kGraceAreaFraction)
+ x = resolution_x - left_border_touch_calibration;
+ // Scale the screen area back to the full resolution of the screen.
+ x = (x * resolution_x) / (resolution_x - (right_border_touch_calibration +
+ left_border_touch_calibration));
+ }
+ if (top_border_touch_calibration || bottom_border_touch_calibration) {
+ // When there is a top bezel we add our border,
+ y -= top_border_touch_calibration;
+
+ // Check if we are in the grace area of the top side.
+ // Note: We might not want to do this when the gesture is locked?
+ if (y < 0 && y > -top_border_touch_calibration * kGraceAreaFraction)
+ y = 0;
+
+ // Check if we are in the grace area of the bottom side.
+ // Note: We might not want to do this when the gesture is locked?
+ if (y > resolution_y - top_border_touch_calibration &&
+ y < resolution_y - top_border_touch_calibration +
+ bottom_border_touch_calibration * kGraceAreaFraction)
+ y = resolution_y - top_border_touch_calibration;
+ // Scale the screen area back to the full resolution of the screen.
+ y = (y * resolution_y) / (resolution_y - (bottom_border_touch_calibration +
+ top_border_touch_calibration));
+ }
+ // Set the modified coordinate back to the event.
+ if (event.root_location() == event.location())
+ event.set_root_location(gfx::Point(x, y));
+ event.set_location(gfx::Point(x, y));
+}
+#endif
+
////////////////////////////////////////////////////////////////////////////////
// TouchEvent
@@ -455,6 +544,12 @@ void TouchEvent::Relocate(const gfx::Point& origin) {
root_location_ -= origin.OffsetFromOrigin();
}
+#if defined(USE_XI2_MT)
+void TouchEvent::Calibrate(const gfx::Rect& bounds) {
+ TouchCoordinatesCalibrator::GetInstance()->Calibrate(*this, bounds);
+}
+#endif
+
void TouchEvent::UpdateForRootTransform(const gfx::Transform& root_transform) {
LocatedEvent::UpdateForRootTransform(root_transform);
gfx::DecomposedTransform decomp;
« ui/base/events/event.h ('K') | « ui/base/events/event.h ('k') | ui/base/x/events_x.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698