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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/events/event_constants.h" 5 #include "ui/events/event_constants.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <string.h> 8 #include <string.h>
9 #include <X11/extensions/XInput.h> 9 #include <X11/extensions/XInput.h>
10 #include <X11/extensions/XInput2.h> 10 #include <X11/extensions/XInput2.h>
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 private: 105 private:
106 friend struct base::DefaultSingletonTraits<XModifierStateWatcher>; 106 friend struct base::DefaultSingletonTraits<XModifierStateWatcher>;
107 107
108 XModifierStateWatcher() : state_(0) { } 108 XModifierStateWatcher() : state_(0) { }
109 109
110 unsigned int state_; 110 unsigned int state_;
111 111
112 DISALLOW_COPY_AND_ASSIGN(XModifierStateWatcher); 112 DISALLOW_COPY_AND_ASSIGN(XModifierStateWatcher);
113 }; 113 };
114 114
115 double GetTouchParamFromXEvent(XEvent* xev,
116 ui::DeviceDataManagerX11::DataType val,
117 double default_value) {
118 ui::DeviceDataManagerX11::GetInstance()->GetEventData(*xev, val,
119 &default_value);
120 return default_value;
121 }
122
123 void ScaleTouchRadius(XEvent* xev, double* radius) {
124 DCHECK_EQ(GenericEvent, xev->type);
125 XIDeviceEvent* xiev = static_cast<XIDeviceEvent*>(xev->xcookie.data);
126 ui::DeviceDataManagerX11::GetInstance()->ApplyTouchRadiusScale(xiev->sourceid,
127 radius);
128 }
129
130 float GetTouchRadiusX(const base::NativeEvent& native_event) {
131 double radius =
132 GetTouchParamFromXEvent(native_event,
133 ui::DeviceDataManagerX11::DT_TOUCH_MAJOR, 0.0) /
134 2.0;
135 ScaleTouchRadius(native_event, &radius);
136 return radius;
137 }
138
139 float GetTouchRadiusY(const base::NativeEvent& native_event) {
140 double radius =
141 GetTouchParamFromXEvent(native_event,
142 ui::DeviceDataManagerX11::DT_TOUCH_MINOR, 0.0) /
143 2.0;
144 ScaleTouchRadius(native_event, &radius);
145 return radius;
146 }
147
148 float GetTouchForce(const base::NativeEvent& native_event) {
149 double force = 0.0;
150 force = GetTouchParamFromXEvent(
151 native_event, ui::DeviceDataManagerX11::DT_TOUCH_PRESSURE, 0.0);
152 unsigned int deviceid =
153 static_cast<XIDeviceEvent*>(native_event->xcookie.data)->sourceid;
154 // Force is normalized to fall into [0, 1]
155 if (!ui::DeviceDataManagerX11::GetInstance()->NormalizeData(
156 deviceid, ui::DeviceDataManagerX11::DT_TOUCH_PRESSURE, &force))
157 force = 0.0;
158 return force;
159 }
160
115 // Detects if a touch event is a driver-generated 'special event'. 161 // Detects if a touch event is a driver-generated 'special event'.
116 // A 'special event' is a touch event with maximum radius and pressure at 162 // A 'special event' is a touch event with maximum radius and pressure at
117 // location (0, 0). 163 // location (0, 0).
118 // This needs to be done in a cleaner way: http://crbug.com/169256 164 // This needs to be done in a cleaner way: http://crbug.com/169256
119 bool TouchEventIsGeneratedHack(const base::NativeEvent& native_event) { 165 bool TouchEventIsGeneratedHack(const base::NativeEvent& native_event) {
120 XIDeviceEvent* event = 166 XIDeviceEvent* event =
121 static_cast<XIDeviceEvent*>(native_event->xcookie.data); 167 static_cast<XIDeviceEvent*>(native_event->xcookie.data);
122 CHECK(event->evtype == XI_TouchBegin || 168 CHECK(event->evtype == XI_TouchBegin ||
123 event->evtype == XI_TouchUpdate || 169 event->evtype == XI_TouchUpdate ||
124 event->evtype == XI_TouchEnd); 170 event->evtype == XI_TouchEnd);
125 171
126 // Force is normalized to [0, 1]. 172 // Force is normalized to [0, 1].
127 if (ui::GetTouchForce(native_event) < 1.0f) 173 if (GetTouchForce(native_event) < 1.0f)
128 return false; 174 return false;
129 175
130 if (ui::EventLocationFromNative(native_event) != gfx::Point()) 176 if (ui::EventLocationFromNative(native_event) != gfx::Point())
131 return false; 177 return false;
132 178
133 // Radius is in pixels, and the valuator is the diameter in pixels. 179 // Radius is in pixels, and the valuator is the diameter in pixels.
134 double radius = ui::GetTouchRadiusX(native_event), min, max; 180 double radius = GetTouchRadiusX(native_event), min, max;
135 unsigned int deviceid = 181 unsigned int deviceid =
136 static_cast<XIDeviceEvent*>(native_event->xcookie.data)->sourceid; 182 static_cast<XIDeviceEvent*>(native_event->xcookie.data)->sourceid;
137 if (!ui::DeviceDataManagerX11::GetInstance()->GetDataRange( 183 if (!ui::DeviceDataManagerX11::GetInstance()->GetDataRange(
138 deviceid, ui::DeviceDataManagerX11::DT_TOUCH_MAJOR, &min, &max)) { 184 deviceid, ui::DeviceDataManagerX11::DT_TOUCH_MAJOR, &min, &max)) {
139 return false; 185 return false;
140 } 186 }
141 187
142 return radius * 2 == max; 188 return radius * 2 == max;
143 } 189 }
144 190
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 if (!(event->flags & XIPointerEmulated) && 318 if (!(event->flags & XIPointerEmulated) &&
273 GetButtonMaskForX2Event(event)) 319 GetButtonMaskForX2Event(event))
274 return ui::ET_TOUCH_MOVED; 320 return ui::ET_TOUCH_MOVED;
275 return ui::ET_UNKNOWN; 321 return ui::ET_UNKNOWN;
276 default: 322 default:
277 NOTREACHED(); 323 NOTREACHED();
278 } 324 }
279 return ui::ET_UNKNOWN; 325 return ui::ET_UNKNOWN;
280 } 326 }
281 327
282 double GetTouchParamFromXEvent(XEvent* xev,
283 ui::DeviceDataManagerX11::DataType val,
284 double default_value) {
285 ui::DeviceDataManagerX11::GetInstance()->GetEventData(
286 *xev, val, &default_value);
287 return default_value;
288 }
289
290 void ScaleTouchRadius(XEvent* xev, double* radius) {
291 DCHECK_EQ(GenericEvent, xev->type);
292 XIDeviceEvent* xiev = static_cast<XIDeviceEvent*>(xev->xcookie.data);
293 ui::DeviceDataManagerX11::GetInstance()->ApplyTouchRadiusScale(
294 xiev->sourceid, radius);
295 }
296
297 unsigned int UpdateX11EventFlags(int ui_flags, unsigned int old_x_flags) { 328 unsigned int UpdateX11EventFlags(int ui_flags, unsigned int old_x_flags) {
298 static struct { 329 static struct {
299 int ui; 330 int ui;
300 int x; 331 int x;
301 } flags[] = { 332 } flags[] = {
302 {ui::EF_SHIFT_DOWN, ShiftMask}, 333 {ui::EF_SHIFT_DOWN, ShiftMask},
303 {ui::EF_CAPS_LOCK_ON, LockMask}, 334 {ui::EF_CAPS_LOCK_ON, LockMask},
304 {ui::EF_CONTROL_DOWN, ControlMask}, 335 {ui::EF_CONTROL_DOWN, ControlMask},
305 {ui::EF_ALT_DOWN, Mod1Mask}, 336 {ui::EF_ALT_DOWN, Mod1Mask},
306 {ui::EF_NUM_LOCK_ON, Mod2Mask}, 337 {ui::EF_NUM_LOCK_ON, Mod2Mask},
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after
745 if (!manager->GetEventData( 776 if (!manager->GetEventData(
746 *xev, ui::DeviceDataManagerX11::DT_TOUCH_TRACKING_ID, &tracking_id)) { 777 *xev, ui::DeviceDataManagerX11::DT_TOUCH_TRACKING_ID, &tracking_id)) {
747 LOG(ERROR) << "Could not get the tracking ID for the event. Using 0."; 778 LOG(ERROR) << "Could not get the tracking ID for the event. Using 0.";
748 } else { 779 } else {
749 ui::TouchFactory* factory = ui::TouchFactory::GetInstance(); 780 ui::TouchFactory* factory = ui::TouchFactory::GetInstance();
750 slot = factory->GetSlotForTrackingID(tracking_id); 781 slot = factory->GetSlotForTrackingID(tracking_id);
751 } 782 }
752 return slot; 783 return slot;
753 } 784 }
754 785
755 float GetTouchRadiusX(const base::NativeEvent& native_event) {
756 double radius = GetTouchParamFromXEvent(native_event,
757 ui::DeviceDataManagerX11::DT_TOUCH_MAJOR, 0.0) / 2.0;
758 ScaleTouchRadius(native_event, &radius);
759 return radius;
760 }
761
762 float GetTouchRadiusY(const base::NativeEvent& native_event) {
763 double radius = GetTouchParamFromXEvent(native_event,
764 ui::DeviceDataManagerX11::DT_TOUCH_MINOR, 0.0) / 2.0;
765 ScaleTouchRadius(native_event, &radius);
766 return radius;
767 }
768 786
769 float GetTouchAngle(const base::NativeEvent& native_event) { 787 float GetTouchAngle(const base::NativeEvent& native_event) {
770 return GetTouchParamFromXEvent(native_event, 788 return GetTouchParamFromXEvent(native_event,
771 ui::DeviceDataManagerX11::DT_TOUCH_ORIENTATION, 0.0) / 2.0; 789 ui::DeviceDataManagerX11::DT_TOUCH_ORIENTATION, 0.0) / 2.0;
772 } 790 }
773 791
774 float GetTouchForce(const base::NativeEvent& native_event) { 792 PointerDetails GetTouchPointerDetailsFromNative(
775 double force = 0.0; 793 const base::NativeEvent& native_event) {
776 force = GetTouchParamFromXEvent(native_event, 794 return PointerDetails(
777 ui::DeviceDataManagerX11::DT_TOUCH_PRESSURE, 0.0); 795 EventPointerType::POINTER_TYPE_TOUCH, GetTouchRadiusX(native_event),
778 unsigned int deviceid = 796 GetTouchRadiusY(native_event), GetTouchForce(native_event),
779 static_cast<XIDeviceEvent*>(native_event->xcookie.data)->sourceid; 797 /* tilt_x */ 0.f,
780 // Force is normalized to fall into [0, 1] 798 /* tilt_y */ 0.f);
781 if (!ui::DeviceDataManagerX11::GetInstance()->NormalizeData(
782 deviceid, ui::DeviceDataManagerX11::DT_TOUCH_PRESSURE, &force))
783 force = 0.0;
784 return force;
785 } 799 }
786 800
787 bool GetScrollOffsets(const base::NativeEvent& native_event, 801 bool GetScrollOffsets(const base::NativeEvent& native_event,
788 float* x_offset, 802 float* x_offset,
789 float* y_offset, 803 float* y_offset,
790 float* x_offset_ordinal, 804 float* x_offset_ordinal,
791 float* y_offset_ordinal, 805 float* y_offset_ordinal,
792 int* finger_count) { 806 int* finger_count) {
793 if (DeviceDataManagerX11::GetInstance()->IsScrollEvent(native_event)) { 807 if (DeviceDataManagerX11::GetInstance()->IsScrollEvent(native_event)) {
794 // Temp values to prevent passing NULLs to DeviceDataManager. 808 // Temp values to prevent passing NULLs to DeviceDataManager.
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
895 xievent->detail = 909 xievent->detail =
896 UpdateX11EventButton(event->changed_button_flags(), xievent->detail); 910 UpdateX11EventButton(event->changed_button_flags(), xievent->detail);
897 break; 911 break;
898 } 912 }
899 default: 913 default:
900 break; 914 break;
901 } 915 }
902 } 916 }
903 917
904 } // namespace ui 918 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698