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

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: Rebase and non-const ref passed back 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 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 case WebInputEvent::MouseLeave: 494 case WebInputEvent::MouseLeave:
476 case WebInputEvent::ContextMenu: 495 case WebInputEvent::ContextMenu:
477 case WebInputEvent::GestureScrollBegin: 496 case WebInputEvent::GestureScrollBegin:
478 case WebInputEvent::GestureScrollEnd: 497 case WebInputEvent::GestureScrollEnd:
479 case WebInputEvent::GestureShowPress: 498 case WebInputEvent::GestureShowPress:
480 case WebInputEvent::GestureTapUnconfirmed: 499 case WebInputEvent::GestureTapUnconfirmed:
481 case WebInputEvent::GestureTapDown: 500 case WebInputEvent::GestureTapDown:
482 case WebInputEvent::GestureTapCancel: 501 case WebInputEvent::GestureTapCancel:
483 case WebInputEvent::GesturePinchBegin: 502 case WebInputEvent::GesturePinchBegin:
484 case WebInputEvent::GesturePinchEnd: 503 case WebInputEvent::GesturePinchEnd:
504 return false;
505
506 // TouchCancel and TouchScrollStarted should always be non-blocking.
485 case WebInputEvent::TouchCancel: 507 case WebInputEvent::TouchCancel:
486 case WebInputEvent::TouchScrollStarted: 508 case WebInputEvent::TouchScrollStarted:
509 DCHECK_NE(WebInputEvent::Blocking,
510 static_cast<const WebTouchEvent&>(event).dispatchType);
487 return false; 511 return false;
512
513 // Touch start and touch end indicate whether they are non-blocking
514 // (aka uncancelable) on the event.
488 case WebInputEvent::TouchStart: 515 case WebInputEvent::TouchStart:
489 case WebInputEvent::TouchEnd: 516 case WebInputEvent::TouchEnd:
490 return static_cast<const WebTouchEvent&>(event).cancelable; 517 return static_cast<const WebTouchEvent&>(event).dispatchType ==
518 WebInputEvent::Blocking;
519
520 // Touch move events may be non-blocking but are always explicitly
521 // acknowledge by the renderer so they block the event stream.
522 case WebInputEvent::TouchMove:
491 default: 523 default:
492 return true; 524 return true;
493 } 525 }
494 } 526 }
495 527
496 uint32_t WebInputEventTraits::GetUniqueTouchEventId( 528 uint32_t WebInputEventTraits::GetUniqueTouchEventId(
497 const WebInputEvent& event) { 529 const WebInputEvent& event) {
498 if (WebInputEvent::isTouchEventType(event.type)) { 530 if (WebInputEvent::isTouchEventType(event.type)) {
499 return static_cast<const WebTouchEvent&>(event).uniqueTouchEventId; 531 return static_cast<const WebTouchEvent&>(event).uniqueTouchEventId;
500 } 532 }
501 return 0U; 533 return 0U;
502 } 534 }
503 535
504 } // namespace content 536 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698