diff options
author | skuhne@chromium.org <skuhne@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-10-23 19:23:36 +0000 |
---|---|---|
committer | skuhne@chromium.org <skuhne@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-10-23 19:23:36 +0000 |
commit | bca8f6ca9ee11a4f10d77dea5d35ba95ae0e9826 (patch) | |
tree | 46679d018eb209c3d72b47447be660a8f603ebc2 /ui/base/x | |
parent | 761815425c25c85eabfa5c3fc50fd41b5cc6f9af (diff) | |
download | chromium_src-bca8f6ca9ee11a4f10d77dea5d35ba95ae0e9826.zip chromium_src-bca8f6ca9ee11a4f10d77dea5d35ba95ae0e9826.tar.gz chromium_src-bca8f6ca9ee11a4f10d77dea5d35ba95ae0e9826.tar.bz2 |
Adding command line flags for calibration
BUG=144639
Review URL: https://chromiumcodereview.appspot.com/11190056
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@163639 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/base/x')
-rw-r--r-- | ui/base/x/events_x.cc | 98 |
1 files changed, 67 insertions, 31 deletions
diff --git a/ui/base/x/events_x.cc b/ui/base/x/events_x.cc index f958012..afa9123 100644 --- a/ui/base/x/events_x.cc +++ b/ui/base/x/events_x.cc @@ -13,6 +13,8 @@ #include "base/logging.h" #include "base/memory/singleton.h" #include "base/message_pump_aurax11.h" +#include "base/string_split.h" +#include "base/string_number_conversions.h" #include "ui/base/keycodes/keyboard_code_conversion_x.h" #include "ui/base/touch/touch_factory.h" #include "ui/base/ui_base_switches.h" @@ -66,6 +68,17 @@ const char* kCMTCachedAtoms[] = { NULL }; +#if defined(USE_XI2_MT) +// If the calibration values were read, if this is true. +bool calibration_values_read = false; + +// The (positive) calibration values for the four border sides. +int left_border_touch_calibration = 0; +int top_border_touch_calibration = 0; +int right_border_touch_calibration = 0; +int bottom_border_touch_calibration = 0; +#endif + // A class to support the detection of scroll events, using X11 valuators. class CMTEventData { public: @@ -589,57 +602,80 @@ Atom GetNoopEventAtom() { } #if defined(USE_XI2_MT) + +void ReadTouchCalibrationValues() { + calibration_values_read = true; + + 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."; + } +} + 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::kEnableTouchCalibration)) + + if (!calibration_values_read) + ReadTouchCalibrationValues(); + + if (!left_border_touch_calibration && !right_border_touch_calibration && + !top_border_touch_calibration && !bottom_border_touch_calibration) return gfx::Point(x, y); - // Temporarily disabling the calibration for X. - bool calibration_x = CommandLine::ForCurrentProcess()->HasSwitch( - switches::kEnableTouchCalibrationX); + gfx::Rect bounds = gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().bounds_in_pixel(); - const int kLeftBorder = 40; - const int kRightBorder = 40; - const int kBottomBorder = 30; - // A negative border offset will scale the top portion over the top area - // and a positive number will cut off n pixels. - 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; - if (calibration_x) { + if (left_border_touch_calibration || right_border_touch_calibration) { // Offset the x position to the real - x -= kLeftBorder; + 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 > -kLeftBorder * kGraceAreaFraction) + 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 - kLeftBorder && - x < resolution_x - kLeftBorder + kRightBorder * kGraceAreaFraction) - x = resolution_x - kLeftBorder; + 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. - x = (x * resolution_x) / (resolution_x - (kRightBorder + kLeftBorder)); + y = (y * resolution_y) / (resolution_y - (bottom_border_touch_calibration + + top_border_touch_calibration)); } - // When there is a top bezel we add our border, - y -= kTopBorder; - // and increase the sensitivity there. - if (kTopBorder < 0 && y < -2 * kTopBorder) - y /= 2; - - // 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); } |