Chromium Code Reviews| Index: ui/base/events/event.cc |
| diff --git a/ui/base/events/event.cc b/ui/base/events/event.cc |
| index f29e84e394f6e01a97336966993ffa2ae1b4cbbb..ec97dc25c164835d347ce914720efa26aba853a9 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/stringprintf.h" |
| +#include "base/strings/string_split.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" |
| @@ -414,6 +418,89 @@ const int MouseWheelEvent::kWheelDelta = 120; |
| const int MouseWheelEvent::kWheelDelta = 53; |
| #endif |
| +#if defined(USE_XI2_MT) |
| +//////////////////////////////////////////////////////////////////////////////// |
| +// TouchCoordinatesCalibrator |
| + |
| +TouchCoordinatesCalibrator::TouchCoordinatesCalibrator() |
| + : left_(0), |
| + right_(0), |
| + top_(0), |
| + bottom_(0) { |
| + std::vector<std::string> parts; |
| + base::SplitString(CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| + switches::kTouchCalibration), ',', &parts); |
|
oshima
2013/03/14 01:23:27
please sync. This function is replaced by Tokenize
ynovikov
2013/03/14 20:27:04
Done.
|
| + if (parts.size() >= 4) { |
| + if (!base::StringToInt(parts[0], &left_)) |
| + DLOG(ERROR) << "Incorrect left border calibration value passed."; |
| + if (!base::StringToInt(parts[1], &right_)) |
| + DLOG(ERROR) << "Incorrect right border calibration value passed."; |
| + if (!base::StringToInt(parts[2], &top_)) |
| + DLOG(ERROR) << "Incorrect top border calibration value passed."; |
| + if (!base::StringToInt(parts[3], &bottom_)) |
| + DLOG(ERROR) << "Incorrect bottom border calibration value passed."; |
|
sadrul
2013/03/14 00:20:13
Should you check for valid (non-negative) values f
ynovikov
2013/03/14 20:27:04
Done.
I don't think negative values are invalid. I
|
| + } |
| +} |
| + |
| +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_ && !right_ && !top_ && !bottom_) |
| + 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_ || right_) { |
| + // Offset the x position to the real |
| + x -= left_; |
| + // 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_ * 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_ && |
| + x < resolution_x - left_ + right_ * kGraceAreaFraction) |
| + x = resolution_x - left_; |
| + // Scale the screen area back to the full resolution of the screen. |
| + x = (x * resolution_x) / (resolution_x - (right_ + left_)); |
| + } |
| + if (top_ || bottom_) { |
| + // When there is a top bezel we add our border, |
| + y -= top_; |
| + |
| + // 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_ * 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_ && |
| + y < resolution_y - top_ + bottom_ * kGraceAreaFraction) |
| + y = resolution_y - top_; |
| + // Scale the screen area back to the full resolution of the screen. |
| + y = (y * resolution_y) / (resolution_y - (bottom_ + top_)); |
| + } |
| + |
| + // Set the modified coordinate back to the event. |
| + if (event->root_location() == event->location()) |
| + // Usually those will be equal, |
| + // if not, I am not sure what the correct value should be. |
| + event->set_root_location(gfx::Point(x, y)); |
|
sadrul
2013/03/14 00:20:13
Use braces
ynovikov
2013/03/14 20:27:04
Done.
|
| + event->set_location(gfx::Point(x, y)); |
| +} |
| +#endif |
|
sadrul
2013/03/14 00:20:13
#endif // defined(USE_XI2_MT)
ynovikov
2013/03/14 20:27:04
Done.
|
| + |
| //////////////////////////////////////////////////////////////////////////////// |
| // TouchEvent |
| @@ -463,6 +550,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; |