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

Side by Side Diff: content/common/input/web_input_event_traits.cc

Issue 1218663006: Use new WebTouchPoint field names. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 5 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "content/common/input/web_input_event_traits.h" 5 #include "content/common/input/web_input_event_traits.h"
6 6
7 #include <bitset> 7 #include <bitset>
8 #include <limits> 8 #include <limits>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 event.data.scrollUpdate.deltaY, 87 event.data.scrollUpdate.deltaY,
88 event.data.scrollUpdate.velocityX, 88 event.data.scrollUpdate.velocityX,
89 event.data.scrollUpdate.velocityY, 89 event.data.scrollUpdate.velocityY,
90 event.data.scrollUpdate.previousUpdateInSequencePrevented); 90 event.data.scrollUpdate.previousUpdateInSequencePrevented);
91 } 91 }
92 92
93 void ApppendTouchPointDetails(const WebTouchPoint& point, std::string* result) { 93 void ApppendTouchPointDetails(const WebTouchPoint& point, std::string* result) {
94 StringAppendF(result, 94 StringAppendF(result,
95 " (ID: %d, State: %d, ScreenPos: (%f, %f), Pos: (%f, %f)," 95 " (ID: %d, State: %d, ScreenPos: (%f, %f), Pos: (%f, %f),"
96 " Radius: (%f, %f), Rot: %f, Force: %f),\n", 96 " Radius: (%f, %f), Rot: %f, Force: %f),\n",
97 point.id, 97 point.pointerId,
98 point.state, 98 point.state,
99 point.screenPosition.x, 99 point.screenPosition.x,
100 point.screenPosition.y, 100 point.screenPosition.y,
101 point.position.x, 101 point.position.x,
102 point.position.y, 102 point.position.y,
103 point.radiusX, 103 point.width,
104 point.radiusY, 104 point.height,
105 point.rotationAngle, 105 point.rotationAngle,
106 point.force); 106 point.pressure);
107 } 107 }
108 108
109 void ApppendEventDetails(const WebTouchEvent& event, std::string* result) { 109 void ApppendEventDetails(const WebTouchEvent& event, std::string* result) {
110 StringAppendF(result, 110 StringAppendF(result,
111 "{\n Touches: %u, Cancelable: %d, CausesScrolling: %d," 111 "{\n Touches: %u, Cancelable: %d, CausesScrolling: %d,"
112 " uniqueTouchEventId: %u\n[\n", 112 " uniqueTouchEventId: %u\n[\n",
113 event.touchesLength, event.cancelable, 113 event.touchesLength, event.cancelable,
114 event.causesScrollingIfUncanceled, event.uniqueTouchEventId); 114 event.causesScrollingIfUncanceled, event.uniqueTouchEventId);
115 for (unsigned i = 0; i < event.touchesLength; ++i) 115 for (unsigned i = 0; i < event.touchesLength; ++i)
116 ApppendTouchPointDetails(event.touches[i], result); 116 ApppendTouchPointDetails(event.touches[i], result);
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 GetAccelerationRatio(event->deltaX, unaccelerated_x); 185 GetAccelerationRatio(event->deltaX, unaccelerated_x);
186 event->accelerationRatioY = 186 event->accelerationRatioY =
187 GetAccelerationRatio(event->deltaY, unaccelerated_y); 187 GetAccelerationRatio(event->deltaY, unaccelerated_y);
188 DCHECK_GE(event_to_coalesce.timeStampSeconds, event->timeStampSeconds); 188 DCHECK_GE(event_to_coalesce.timeStampSeconds, event->timeStampSeconds);
189 event->timeStampSeconds = event_to_coalesce.timeStampSeconds; 189 event->timeStampSeconds = event_to_coalesce.timeStampSeconds;
190 } 190 }
191 191
192 // Returns |kInvalidTouchIndex| iff |event| lacks a touch with an ID of |id|. 192 // Returns |kInvalidTouchIndex| iff |event| lacks a touch with an ID of |id|.
193 int GetIndexOfTouchID(const WebTouchEvent& event, int id) { 193 int GetIndexOfTouchID(const WebTouchEvent& event, int id) {
194 for (unsigned i = 0; i < event.touchesLength; ++i) { 194 for (unsigned i = 0; i < event.touchesLength; ++i) {
195 if (event.touches[i].id == id) 195 if (event.touches[i].pointerId == id)
196 return i; 196 return i;
197 } 197 }
198 return kInvalidTouchIndex; 198 return kInvalidTouchIndex;
199 } 199 }
200 200
201 bool CanCoalesce(const WebTouchEvent& event_to_coalesce, 201 bool CanCoalesce(const WebTouchEvent& event_to_coalesce,
202 const WebTouchEvent& event) { 202 const WebTouchEvent& event) {
203 if (event.type != event_to_coalesce.type || 203 if (event.type != event_to_coalesce.type ||
204 event.type != WebInputEvent::TouchMove || 204 event.type != WebInputEvent::TouchMove ||
205 event.modifiers != event_to_coalesce.modifiers || 205 event.modifiers != event_to_coalesce.modifiers ||
206 event.touchesLength != event_to_coalesce.touchesLength || 206 event.touchesLength != event_to_coalesce.touchesLength ||
207 event.touchesLength > WebTouchEvent::touchesLengthCap) 207 event.touchesLength > WebTouchEvent::touchesLengthCap)
208 return false; 208 return false;
209 209
210 static_assert(WebTouchEvent::touchesLengthCap <= sizeof(int32_t) * 8U, 210 static_assert(WebTouchEvent::touchesLengthCap <= sizeof(int32_t) * 8U,
211 "suboptimal touchesLengthCap size"); 211 "suboptimal touchesLengthCap size");
212 // Ensure that we have a 1-to-1 mapping of pointer ids between touches. 212 // Ensure that we have a 1-to-1 mapping of pointer ids between touches.
213 std::bitset<WebTouchEvent::touchesLengthCap> unmatched_event_touches( 213 std::bitset<WebTouchEvent::touchesLengthCap> unmatched_event_touches(
214 (1 << event.touchesLength) - 1); 214 (1 << event.touchesLength) - 1);
215 for (unsigned i = 0; i < event_to_coalesce.touchesLength; ++i) { 215 for (unsigned i = 0; i < event_to_coalesce.touchesLength; ++i) {
216 int event_touch_index = 216 int event_touch_index =
217 GetIndexOfTouchID(event, event_to_coalesce.touches[i].id); 217 GetIndexOfTouchID(event, event_to_coalesce.touches[i].pointerId);
218 if (event_touch_index == kInvalidTouchIndex) 218 if (event_touch_index == kInvalidTouchIndex)
219 return false; 219 return false;
220 if (!unmatched_event_touches[event_touch_index]) 220 if (!unmatched_event_touches[event_touch_index])
221 return false; 221 return false;
222 unmatched_event_touches[event_touch_index] = false; 222 unmatched_event_touches[event_touch_index] = false;
223 } 223 }
224 return unmatched_event_touches.none(); 224 return unmatched_event_touches.none();
225 } 225 }
226 226
227 void Coalesce(const WebTouchEvent& event_to_coalesce, WebTouchEvent* event) { 227 void Coalesce(const WebTouchEvent& event_to_coalesce, WebTouchEvent* event) {
228 DCHECK(CanCoalesce(event_to_coalesce, *event)); 228 DCHECK(CanCoalesce(event_to_coalesce, *event));
229 // The WebTouchPoints include absolute position information. So it is 229 // The WebTouchPoints include absolute position information. So it is
230 // sufficient to simply replace the previous event with the new event-> 230 // sufficient to simply replace the previous event with the new event->
231 // However, it is necessary to make sure that all the points have the 231 // However, it is necessary to make sure that all the points have the
232 // correct state, i.e. the touch-points that moved in the last event, but 232 // correct state, i.e. the touch-points that moved in the last event, but
233 // didn't change in the current event, will have Stationary state. It is 233 // didn't change in the current event, will have Stationary state. It is
234 // necessary to change them back to Moved state. 234 // necessary to change them back to Moved state.
235 WebTouchEvent old_event = *event; 235 WebTouchEvent old_event = *event;
236 *event = event_to_coalesce; 236 *event = event_to_coalesce;
237 for (unsigned i = 0; i < event->touchesLength; ++i) { 237 for (unsigned i = 0; i < event->touchesLength; ++i) {
238 int i_old = GetIndexOfTouchID(old_event, event->touches[i].id); 238 int i_old = GetIndexOfTouchID(old_event, event->touches[i].pointerId);
239 if (old_event.touches[i_old].state == blink::WebTouchPoint::StateMoved) 239 if (old_event.touches[i_old].state == blink::WebTouchPoint::StateMoved)
240 event->touches[i].state = blink::WebTouchPoint::StateMoved; 240 event->touches[i].state = blink::WebTouchPoint::StateMoved;
241 } 241 }
242 event->causesScrollingIfUncanceled |= old_event.causesScrollingIfUncanceled; 242 event->causesScrollingIfUncanceled |= old_event.causesScrollingIfUncanceled;
243 } 243 }
244 244
245 bool CanCoalesce(const WebGestureEvent& event_to_coalesce, 245 bool CanCoalesce(const WebGestureEvent& event_to_coalesce,
246 const WebGestureEvent& event) { 246 const WebGestureEvent& event) {
247 if (event.type != event_to_coalesce.type || 247 if (event.type != event_to_coalesce.type ||
248 event.sourceDevice != event_to_coalesce.sourceDevice || 248 event.sourceDevice != event_to_coalesce.sourceDevice ||
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
488 } 488 }
489 489
490 uint32 WebInputEventTraits::GetUniqueTouchEventId(const WebInputEvent& event) { 490 uint32 WebInputEventTraits::GetUniqueTouchEventId(const WebInputEvent& event) {
491 if (WebInputEvent::isTouchEventType(event.type)) { 491 if (WebInputEvent::isTouchEventType(event.type)) {
492 return static_cast<const WebTouchEvent&>(event).uniqueTouchEventId; 492 return static_cast<const WebTouchEvent&>(event).uniqueTouchEventId;
493 } 493 }
494 return 0U; 494 return 0U;
495 } 495 }
496 496
497 } // namespace content 497 } // namespace content
OLDNEW
« no previous file with comments | « content/common/input/touch_event_stream_validator.cc ('k') | content/common/input/web_input_event_traits_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698