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

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

Issue 1888163003: Articulate the cancel behavior in the WebTouchEvent. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix unit tests Created 4 years, 8 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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 point.radiusX, 104 point.radiusX,
105 point.radiusY, 105 point.radiusY,
106 point.rotationAngle, 106 point.rotationAngle,
107 point.force, 107 point.force,
108 point.tiltX, 108 point.tiltX,
109 point.tiltY); 109 point.tiltY);
110 } 110 }
111 111
112 void ApppendEventDetails(const WebTouchEvent& event, std::string* result) { 112 void ApppendEventDetails(const WebTouchEvent& event, std::string* result) {
113 StringAppendF(result, 113 StringAppendF(result,
114 "{\n Touches: %u, Cancelable: %d, CausesScrolling: %d," 114 "{\n Touches: %u, DispatchType: %d, CausesScrolling: %d,"
115 " uniqueTouchEventId: %u\n[\n", 115 " uniqueTouchEventId: %u\n[\n",
116 event.touchesLength, event.cancelable, 116 event.touchesLength, event.dispatchType,
117 event.movedBeyondSlopRegion, event.uniqueTouchEventId); 117 event.movedBeyondSlopRegion, event.uniqueTouchEventId);
118 for (unsigned i = 0; i < event.touchesLength; ++i) 118 for (unsigned i = 0; i < event.touchesLength; ++i)
119 ApppendTouchPointDetails(event.touches[i], result); 119 ApppendTouchPointDetails(event.touches[i], result);
120 result->append(" ]\n}"); 120 result->append(" ]\n}");
121 } 121 }
122 122
123 bool CanCoalesce(const WebKeyboardEvent& event_to_coalesce, 123 bool CanCoalesce(const WebKeyboardEvent& event_to_coalesce,
124 const WebKeyboardEvent& event) { 124 const WebKeyboardEvent& event) {
125 return false; 125 return false;
126 } 126 }
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 192
193 // Returns |kInvalidTouchIndex| iff |event| lacks a touch with an ID of |id|. 193 // Returns |kInvalidTouchIndex| iff |event| lacks a touch with an ID of |id|.
194 int GetIndexOfTouchID(const WebTouchEvent& event, int id) { 194 int GetIndexOfTouchID(const WebTouchEvent& event, int id) {
195 for (unsigned i = 0; i < event.touchesLength; ++i) { 195 for (unsigned i = 0; i < event.touchesLength; ++i) {
196 if (event.touches[i].id == id) 196 if (event.touches[i].id == id)
197 return i; 197 return i;
198 } 198 }
199 return kInvalidTouchIndex; 199 return kInvalidTouchIndex;
200 } 200 }
201 201
202 WebInputEvent::DispatchType MergeDispatchTypes(
203 WebInputEvent::DispatchType type_1,
204 WebInputEvent::DispatchType type_2) {
205 static_assert(WebInputEvent::DispatchType::Blocking <
206 WebInputEvent::DispatchType::EventNonBlocking,
207 "Enum not ordered correctly");
208 static_assert(WebInputEvent::DispatchType::EventNonBlocking <
209 WebInputEvent::DispatchType::ListenersNonBlockingPassive,
210 "Enum not ordered correctly");
211 static_assert(
212 WebInputEvent::DispatchType::ListenersNonBlockingPassive <
213 WebInputEvent::DispatchType::ListenersForcedNonBlockingPassive,
214 "Enum not ordered correctly");
215 return static_cast<WebInputEvent::DispatchType>(
216 std::min(static_cast<int>(type_1), static_cast<int>(type_2)));
217 }
218
202 bool CanCoalesce(const WebTouchEvent& event_to_coalesce, 219 bool CanCoalesce(const WebTouchEvent& event_to_coalesce,
203 const WebTouchEvent& event) { 220 const WebTouchEvent& event) {
204 if (event.type != event_to_coalesce.type || 221 if (event.type != event_to_coalesce.type ||
205 event.type != WebInputEvent::TouchMove || 222 event.type != WebInputEvent::TouchMove ||
206 event.modifiers != event_to_coalesce.modifiers || 223 event.modifiers != event_to_coalesce.modifiers ||
207 event.touchesLength != event_to_coalesce.touchesLength || 224 event.touchesLength != event_to_coalesce.touchesLength ||
208 event.touchesLength > WebTouchEvent::touchesLengthCap) 225 event.touchesLength > WebTouchEvent::touchesLengthCap)
209 return false; 226 return false;
210 227
211 static_assert(WebTouchEvent::touchesLengthCap <= sizeof(int32_t) * 8U, 228 static_assert(WebTouchEvent::touchesLengthCap <= sizeof(int32_t) * 8U,
(...skipping 22 matching lines...) Expand all
234 // didn't change in the current event, will have Stationary state. It is 251 // didn't change in the current event, will have Stationary state. It is
235 // necessary to change them back to Moved state. 252 // necessary to change them back to Moved state.
236 WebTouchEvent old_event = *event; 253 WebTouchEvent old_event = *event;
237 *event = event_to_coalesce; 254 *event = event_to_coalesce;
238 for (unsigned i = 0; i < event->touchesLength; ++i) { 255 for (unsigned i = 0; i < event->touchesLength; ++i) {
239 int i_old = GetIndexOfTouchID(old_event, event->touches[i].id); 256 int i_old = GetIndexOfTouchID(old_event, event->touches[i].id);
240 if (old_event.touches[i_old].state == blink::WebTouchPoint::StateMoved) 257 if (old_event.touches[i_old].state == blink::WebTouchPoint::StateMoved)
241 event->touches[i].state = blink::WebTouchPoint::StateMoved; 258 event->touches[i].state = blink::WebTouchPoint::StateMoved;
242 } 259 }
243 event->movedBeyondSlopRegion |= old_event.movedBeyondSlopRegion; 260 event->movedBeyondSlopRegion |= old_event.movedBeyondSlopRegion;
261 event->dispatchType = MergeDispatchTypes(old_event.dispatchType,
262 event_to_coalesce.dispatchType);
244 } 263 }
245 264
246 bool CanCoalesce(const WebGestureEvent& event_to_coalesce, 265 bool CanCoalesce(const WebGestureEvent& event_to_coalesce,
247 const WebGestureEvent& event) { 266 const WebGestureEvent& event) {
248 if (event.type != event_to_coalesce.type || 267 if (event.type != event_to_coalesce.type ||
249 event.sourceDevice != event_to_coalesce.sourceDevice || 268 event.sourceDevice != event_to_coalesce.sourceDevice ||
250 event.modifiers != event_to_coalesce.modifiers) 269 event.modifiers != event_to_coalesce.modifiers)
251 return false; 270 return false;
252 271
253 if (event.type == WebInputEvent::GestureScrollUpdate) 272 if (event.type == WebInputEvent::GestureScrollUpdate)
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 case WebInputEvent::MouseLeave: 493 case WebInputEvent::MouseLeave:
475 case WebInputEvent::ContextMenu: 494 case WebInputEvent::ContextMenu:
476 case WebInputEvent::GestureScrollBegin: 495 case WebInputEvent::GestureScrollBegin:
477 case WebInputEvent::GestureScrollEnd: 496 case WebInputEvent::GestureScrollEnd:
478 case WebInputEvent::GestureShowPress: 497 case WebInputEvent::GestureShowPress:
479 case WebInputEvent::GestureTapUnconfirmed: 498 case WebInputEvent::GestureTapUnconfirmed:
480 case WebInputEvent::GestureTapDown: 499 case WebInputEvent::GestureTapDown:
481 case WebInputEvent::GestureTapCancel: 500 case WebInputEvent::GestureTapCancel:
482 case WebInputEvent::GesturePinchBegin: 501 case WebInputEvent::GesturePinchBegin:
483 case WebInputEvent::GesturePinchEnd: 502 case WebInputEvent::GesturePinchEnd:
503 return false;
504
505 // Touch cancel should always be non-blocking.
484 case WebInputEvent::TouchCancel: 506 case WebInputEvent::TouchCancel:
507 DCHECK_NE(WebInputEvent::Blocking,
508 static_cast<const WebTouchEvent&>(event).dispatchType);
485 return false; 509 return false;
510
511 // Touch start and touch end indicate whether they are non-blocking
512 // (aka uncancelable) on the event.
486 case WebInputEvent::TouchStart: 513 case WebInputEvent::TouchStart:
487 case WebInputEvent::TouchEnd: 514 case WebInputEvent::TouchEnd:
488 return static_cast<const WebTouchEvent&>(event).cancelable; 515 return static_cast<const WebTouchEvent&>(event).dispatchType ==
516 WebInputEvent::Blocking;
517
518 // Touch move events may be non-blocking but are always explicitly
519 // acknowledge by the renderer so they block the event stream.
520 case WebInputEvent::TouchMove:
489 default: 521 default:
490 return true; 522 return true;
491 } 523 }
492 } 524 }
493 525
494 uint32_t WebInputEventTraits::GetUniqueTouchEventId( 526 uint32_t WebInputEventTraits::GetUniqueTouchEventId(
495 const WebInputEvent& event) { 527 const WebInputEvent& event) {
496 if (WebInputEvent::isTouchEventType(event.type)) { 528 if (WebInputEvent::isTouchEventType(event.type)) {
497 return static_cast<const WebTouchEvent&>(event).uniqueTouchEventId; 529 return static_cast<const WebTouchEvent&>(event).uniqueTouchEventId;
498 } 530 }
499 return 0U; 531 return 0U;
500 } 532 }
501 533
502 } // namespace content 534 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698