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

Unified Diff: ui/events/x/events_x.cc

Issue 1586653002: ui: Fix TouchEvent PointerDetails creation from NativeEvent (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use 1.0 consitently for default touch radius (change on Mac and stub.) Created 4 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/events/x/events_x.cc
diff --git a/ui/events/x/events_x.cc b/ui/events/x/events_x.cc
index 5a23b08129b9f4e28ce215287fdc358bf48e25ec..50855b1891df312c0e86633c89d4da8695e3518f 100644
--- a/ui/events/x/events_x.cc
+++ b/ui/events/x/events_x.cc
@@ -112,6 +112,52 @@ class XModifierStateWatcher{
DISALLOW_COPY_AND_ASSIGN(XModifierStateWatcher);
};
+double GetTouchParamFromXEvent(XEvent* xev,
+ ui::DeviceDataManagerX11::DataType val,
+ double default_value) {
+ ui::DeviceDataManagerX11::GetInstance()->GetEventData(*xev, val,
+ &default_value);
+ return default_value;
+}
+
+void ScaleTouchRadius(XEvent* xev, double* radius) {
+ DCHECK_EQ(GenericEvent, xev->type);
+ XIDeviceEvent* xiev = static_cast<XIDeviceEvent*>(xev->xcookie.data);
+ ui::DeviceDataManagerX11::GetInstance()->ApplyTouchRadiusScale(xiev->sourceid,
+ radius);
+}
+
+float GetTouchRadiusX(const base::NativeEvent& native_event) {
+ double radius =
+ GetTouchParamFromXEvent(native_event,
+ ui::DeviceDataManagerX11::DT_TOUCH_MAJOR, 0.0) /
+ 2.0;
+ ScaleTouchRadius(native_event, &radius);
+ return radius;
+}
+
+float GetTouchRadiusY(const base::NativeEvent& native_event) {
+ double radius =
+ GetTouchParamFromXEvent(native_event,
+ ui::DeviceDataManagerX11::DT_TOUCH_MINOR, 0.0) /
+ 2.0;
+ ScaleTouchRadius(native_event, &radius);
+ return radius;
+}
+
+float GetTouchForce(const base::NativeEvent& native_event) {
+ double force = 0.0;
+ force = GetTouchParamFromXEvent(
+ native_event, ui::DeviceDataManagerX11::DT_TOUCH_PRESSURE, 0.0);
+ unsigned int deviceid =
+ static_cast<XIDeviceEvent*>(native_event->xcookie.data)->sourceid;
+ // Force is normalized to fall into [0, 1]
+ if (!ui::DeviceDataManagerX11::GetInstance()->NormalizeData(
+ deviceid, ui::DeviceDataManagerX11::DT_TOUCH_PRESSURE, &force))
+ force = 0.0;
+ return force;
+}
+
// Detects if a touch event is a driver-generated 'special event'.
// A 'special event' is a touch event with maximum radius and pressure at
// location (0, 0).
@@ -124,14 +170,14 @@ bool TouchEventIsGeneratedHack(const base::NativeEvent& native_event) {
event->evtype == XI_TouchEnd);
// Force is normalized to [0, 1].
- if (ui::GetTouchForce(native_event) < 1.0f)
+ if (GetTouchForce(native_event) < 1.0f)
return false;
if (ui::EventLocationFromNative(native_event) != gfx::Point())
return false;
// Radius is in pixels, and the valuator is the diameter in pixels.
- double radius = ui::GetTouchRadiusX(native_event), min, max;
+ double radius = GetTouchRadiusX(native_event), min, max;
unsigned int deviceid =
static_cast<XIDeviceEvent*>(native_event->xcookie.data)->sourceid;
if (!ui::DeviceDataManagerX11::GetInstance()->GetDataRange(
@@ -279,21 +325,6 @@ ui::EventType GetTouchEventType(const base::NativeEvent& native_event) {
return ui::ET_UNKNOWN;
}
-double GetTouchParamFromXEvent(XEvent* xev,
- ui::DeviceDataManagerX11::DataType val,
- double default_value) {
- ui::DeviceDataManagerX11::GetInstance()->GetEventData(
- *xev, val, &default_value);
- return default_value;
-}
-
-void ScaleTouchRadius(XEvent* xev, double* radius) {
- DCHECK_EQ(GenericEvent, xev->type);
- XIDeviceEvent* xiev = static_cast<XIDeviceEvent*>(xev->xcookie.data);
- ui::DeviceDataManagerX11::GetInstance()->ApplyTouchRadiusScale(
- xiev->sourceid, radius);
-}
-
unsigned int UpdateX11EventFlags(int ui_flags, unsigned int old_x_flags) {
static struct {
int ui;
@@ -752,36 +783,19 @@ int GetTouchId(const base::NativeEvent& xev) {
return slot;
}
-float GetTouchRadiusX(const base::NativeEvent& native_event) {
- double radius = GetTouchParamFromXEvent(native_event,
- ui::DeviceDataManagerX11::DT_TOUCH_MAJOR, 0.0) / 2.0;
- ScaleTouchRadius(native_event, &radius);
- return radius;
-}
-
-float GetTouchRadiusY(const base::NativeEvent& native_event) {
- double radius = GetTouchParamFromXEvent(native_event,
- ui::DeviceDataManagerX11::DT_TOUCH_MINOR, 0.0) / 2.0;
- ScaleTouchRadius(native_event, &radius);
- return radius;
-}
float GetTouchAngle(const base::NativeEvent& native_event) {
return GetTouchParamFromXEvent(native_event,
ui::DeviceDataManagerX11::DT_TOUCH_ORIENTATION, 0.0) / 2.0;
}
-float GetTouchForce(const base::NativeEvent& native_event) {
- double force = 0.0;
- force = GetTouchParamFromXEvent(native_event,
- ui::DeviceDataManagerX11::DT_TOUCH_PRESSURE, 0.0);
- unsigned int deviceid =
- static_cast<XIDeviceEvent*>(native_event->xcookie.data)->sourceid;
- // Force is normalized to fall into [0, 1]
- if (!ui::DeviceDataManagerX11::GetInstance()->NormalizeData(
- deviceid, ui::DeviceDataManagerX11::DT_TOUCH_PRESSURE, &force))
- force = 0.0;
- return force;
+PointerDetails GetTouchPointerDetailsFromNative(
+ const base::NativeEvent& native_event) {
+ return PointerDetails(
+ EventPointerType::POINTER_TYPE_TOUCH, GetTouchRadiusX(native_event),
+ GetTouchRadiusY(native_event), GetTouchForce(native_event),
+ /* tilt_x */ 0.f,
+ /* tilt_y */ 0.f);
}
bool GetScrollOffsets(const base::NativeEvent& native_event,

Powered by Google App Engine
This is Rietveld 408576698