summaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authormiletus@chromium.org <miletus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-05-23 21:34:49 +0000
committermiletus@chromium.org <miletus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-05-23 21:34:49 +0000
commita76456e47738cf47ee3a20cbd749bfed53976931 (patch)
tree8cec3270770f0bc969b11c135a454cdf1b9c07a0 /ui
parent4af42b08b927fa0b422962b497e3456d2839cb39 (diff)
downloadchromium_src-a76456e47738cf47ee3a20cbd749bfed53976931.zip
chromium_src-a76456e47738cf47ee3a20cbd749bfed53976931.tar.gz
chromium_src-a76456e47738cf47ee3a20cbd749bfed53976931.tar.bz2
Use double precision for touch event valuator
Touch event's "Touch Timestamp" valuator loses precision if stored in float. So we change ExtractValuator() to store the extracted valuator in double type. BUG=None. TEST=Make sure the touch timestamp from Chrome side is exactly the same as they are set in kernel evdev. Review URL: https://chromiumcodereview.appspot.com/15792002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@201890 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
-rw-r--r--ui/base/x/events_x.cc18
-rw-r--r--ui/base/x/valuators.cc12
-rw-r--r--ui/base/x/valuators.h14
3 files changed, 22 insertions, 22 deletions
diff --git a/ui/base/x/events_x.cc b/ui/base/x/events_x.cc
index 31862b3..6c50da0 100644
--- a/ui/base/x/events_x.cc
+++ b/ui/base/x/events_x.cc
@@ -537,7 +537,7 @@ bool TouchEventIsGeneratedHack(const base::NativeEvent& native_event) {
return false;
// Radius is in pixels, and the valuator is the diameter in pixels.
- float radius = ui::GetTouchRadiusX(native_event), min, max;
+ double radius = ui::GetTouchRadiusX(native_event), min, max;
unsigned int deviceid =
static_cast<XIDeviceEvent*>(native_event->xcookie.data)->sourceid;
if (!ui::ValuatorTracker::GetInstance()->GetValuatorRange(
@@ -647,7 +647,7 @@ ui::EventType GetTouchEventType(const base::NativeEvent& native_event) {
ui::ValuatorTracker* valuators = ui::ValuatorTracker::GetInstance();
- float slot;
+ double slot;
if (!valuators->ExtractValuator(
*native_event, ui::ValuatorTracker::VAL_SLOT_ID, &slot))
return ui::ET_UNKNOWN;
@@ -657,7 +657,7 @@ ui::EventType GetTouchEventType(const base::NativeEvent& native_event) {
return ui::ET_TOUCH_PRESSED;
}
- float tracking;
+ double tracking;
if (!valuators->ExtractValuator(
*native_event, ui::ValuatorTracker::VAL_TRACKING_ID, &tracking))
return ui::ET_UNKNOWN;
@@ -671,9 +671,9 @@ ui::EventType GetTouchEventType(const base::NativeEvent& native_event) {
#endif // defined(USE_XI2_MT)
}
-float GetTouchParamFromXEvent(XEvent* xev,
+double GetTouchParamFromXEvent(XEvent* xev,
ui::ValuatorTracker::Valuator val,
- float default_value) {
+ double default_value) {
ui::ValuatorTracker::GetInstance()->ExtractValuator(
*xev, val, &default_value);
return default_value;
@@ -845,7 +845,7 @@ base::TimeDelta EventTimeFromNative(const base::NativeEvent& native_event) {
break;
case GenericEvent: {
double start, end;
- float touch_timestamp;
+ double touch_timestamp;
if (GetGestureTimes(native_event, &start, &end)) {
// If the driver supports gesture times, use them.
return base::TimeDelta::FromMicroseconds(end * 1000000);
@@ -1021,7 +1021,7 @@ gfx::Vector2d GetMouseWheelOffset(const base::NativeEvent& native_event) {
}
int GetTouchId(const base::NativeEvent& xev) {
- float slot = 0;
+ double slot = 0;
ui::TouchFactory* factory = ui::TouchFactory::GetInstance();
XIDeviceEvent* xievent = static_cast<XIDeviceEvent*>(xev->xcookie.data);
if (!factory->IsMultiTouchDevice(xievent->sourceid)) {
@@ -1033,7 +1033,7 @@ int GetTouchId(const base::NativeEvent& xev) {
ui::ValuatorTracker* valuators = ui::ValuatorTracker::GetInstance();
#if defined(USE_XI2_MT)
- float tracking_id;
+ double tracking_id;
if (!valuators->ExtractValuator(
*xev, ui::ValuatorTracker::VAL_TRACKING_ID, &tracking_id)) {
LOG(ERROR) << "Could not get the slot ID for the event. Using 0.";
@@ -1069,7 +1069,7 @@ float GetTouchAngle(const base::NativeEvent& native_event) {
}
float GetTouchForce(const base::NativeEvent& native_event) {
- float force = 0.0;
+ double force = 0.0;
force = GetTouchParamFromXEvent(native_event,
ui::ValuatorTracker::VAL_PRESSURE, 0.0);
unsigned int deviceid =
diff --git a/ui/base/x/valuators.cc b/ui/base/x/valuators.cc
index 1be3b9b..da0490e 100644
--- a/ui/base/x/valuators.cc
+++ b/ui/base/x/valuators.cc
@@ -96,7 +96,7 @@ ValuatorTracker* ValuatorTracker::GetInstance() {
bool ValuatorTracker::ExtractValuator(const XEvent& xev,
Valuator val,
- float* value) {
+ double* value) {
XIDeviceEvent* xiev = static_cast<XIDeviceEvent*>(xev.xcookie.data);
if (xiev->sourceid >= kMaxDeviceNum || xiev->deviceid >= kMaxDeviceNum)
return false;
@@ -129,9 +129,9 @@ bool ValuatorTracker::ExtractValuator(const XEvent& xev,
bool ValuatorTracker::NormalizeValuator(unsigned int deviceid,
Valuator val,
- float* value) {
- float max_value;
- float min_value;
+ double* value) {
+ double max_value;
+ double min_value;
if (GetValuatorRange(deviceid, val, &min_value, &max_value)) {
*value = (*value - min_value) / (max_value - min_value);
DCHECK(*value >= 0.0 && *value <= 1.0);
@@ -142,8 +142,8 @@ bool ValuatorTracker::NormalizeValuator(unsigned int deviceid,
bool ValuatorTracker::GetValuatorRange(unsigned int deviceid,
Valuator val,
- float* min,
- float* max) {
+ double* min,
+ double* max) {
if (valuator_lookup_[deviceid][val] >= 0) {
*min = valuator_min_[deviceid][val];
*max = valuator_max_[deviceid][val];
diff --git a/ui/base/x/valuators.h b/ui/base/x/valuators.h
index c2003d6..6a3168a 100644
--- a/ui/base/x/valuators.h
+++ b/ui/base/x/valuators.h
@@ -67,20 +67,20 @@ class UI_EXPORT ValuatorTracker {
// Extract the Valuator from the XEvent. Return true and the value is set
// if the Valuator is found, false and value unchanged if the Valuator
// is not found.
- bool ExtractValuator(const XEvent& xev, Valuator val, float* value);
+ bool ExtractValuator(const XEvent& xev, Valuator val, double* value);
// Normalize the Valuator with value on deviceid to fall into [0, 1].
// *value = (*value - min_value_of_tp) / (max_value_of_tp - min_value_of_tp)
// Returns true and sets the normalized value in|value| if normalization is
// successful. Returns false and |value| is unchanged otherwise.
- bool NormalizeValuator(unsigned int deviceid, Valuator val, float* value);
+ bool NormalizeValuator(unsigned int deviceid, Valuator val, double* value);
// Extract the range of the Valuator. Return true if the range is available
// and written into min & max, false if the range is not available.
bool GetValuatorRange(unsigned int deviceid,
Valuator val,
- float* min,
- float* max);
+ double* min,
+ double* max);
// Sets up the internal bookkeeping of the valuator information. It currently
// does this for touch devices only.
@@ -101,13 +101,13 @@ class UI_EXPORT ValuatorTracker {
// Index table to find the min & max value of the Valuator on a specific
// device.
- int valuator_min_[kMaxDeviceNum][VAL_LAST_ENTRY];
- int valuator_max_[kMaxDeviceNum][VAL_LAST_ENTRY];
+ double valuator_min_[kMaxDeviceNum][VAL_LAST_ENTRY];
+ double valuator_max_[kMaxDeviceNum][VAL_LAST_ENTRY];
// Table to keep track of the last seen value for the specified valuator for
// a device. Defaults to 0 if the valuator was not specified in an earlier
// event.
- float last_seen_valuator_[kMaxDeviceNum][VAL_LAST_ENTRY];
+ double last_seen_valuator_[kMaxDeviceNum][VAL_LAST_ENTRY];
DISALLOW_COPY_AND_ASSIGN(ValuatorTracker);
};