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

Side by Side Diff: third_party/WebKit/Source/core/input/TouchEventManager.cpp

Issue 2027473002: Deprecate use of user gestures during scroll-related touch events (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2743
Patch Set: Created 4 years, 6 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "core/input/TouchEventManager.h" 5 #include "core/input/TouchEventManager.h"
6 6
7 #include "core/dom/Document.h" 7 #include "core/dom/Document.h"
8 #include "core/events/TouchEvent.h" 8 #include "core/events/TouchEvent.h"
9 #include "core/frame/Deprecation.h"
9 #include "core/frame/EventHandlerRegistry.h" 10 #include "core/frame/EventHandlerRegistry.h"
10 #include "core/frame/FrameHost.h" 11 #include "core/frame/FrameHost.h"
11 #include "core/frame/FrameView.h" 12 #include "core/frame/FrameView.h"
12 #include "core/html/HTMLCanvasElement.h" 13 #include "core/html/HTMLCanvasElement.h"
13 #include "core/input/EventHandler.h" 14 #include "core/input/EventHandler.h"
14 #include "core/input/TouchActionUtil.h" 15 #include "core/input/TouchActionUtil.h"
15 #include "core/page/ChromeClient.h" 16 #include "core/page/ChromeClient.h"
16 #include "core/page/Page.h" 17 #include "core/page/Page.h"
17 #include "platform/Histogram.h" 18 #include "platform/Histogram.h"
18 #include "platform/PlatformTouchEvent.h" 19 #include "platform/PlatformTouchEvent.h"
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 } else { 216 } else {
216 DEFINE_STATIC_LOCAL(EnumerationHistogram, touchDispositi onsOutsideFlingHistogram, ("Event.Touch.TouchDispositionsOutsideFling", TouchEve ntDispatchResultTypeMax)); 217 DEFINE_STATIC_LOCAL(EnumerationHistogram, touchDispositi onsOutsideFlingHistogram, ("Event.Touch.TouchDispositionsOutsideFling", TouchEve ntDispatchResultTypeMax));
217 touchDispositionsOutsideFlingHistogram.count((domDispatc hResult != DispatchEventResult::NotCanceled) ? HandledTouches : UnhandledTouches ); 218 touchDispositionsOutsideFlingHistogram.count((domDispatc hResult != DispatchEventResult::NotCanceled) ? HandledTouches : UnhandledTouches );
218 } 219 }
219 } 220 }
220 } 221 }
221 eventResult = EventHandler::mergeEventResult(eventResult, 222 eventResult = EventHandler::mergeEventResult(eventResult,
222 EventHandler::toWebInputEventResult(domDispatchResult)); 223 EventHandler::toWebInputEventResult(domDispatchResult));
223 } 224 }
224 } 225 }
226
227 if (allTouchesReleased)
228 m_touchScrollStarted = false;
229
225 return eventResult; 230 return eventResult;
226 } 231 }
227 232
228 void TouchEventManager::updateTargetAndRegionMapsForTouchStarts( 233 void TouchEventManager::updateTargetAndRegionMapsForTouchStarts(
229 HeapVector<TouchInfo>& touchInfos) 234 HeapVector<TouchInfo>& touchInfos)
230 { 235 {
231 for (auto& touchInfo : touchInfos) { 236 for (auto& touchInfo : touchInfos) {
232 // Touch events implicitly capture to the touched node, and don't change 237 // Touch events implicitly capture to the touched node, and don't change
233 // active/hover states themselves (Gesture events do). So we only need 238 // active/hover states themselves (Gesture events do). So we only need
234 // to hit-test on touchstart and when the target could be different than 239 // to hit-test on touchstart and when the target could be different than
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 m_touchSequenceUserGestureToken.clear(); 409 m_touchSequenceUserGestureToken.clear();
405 } 410 }
406 return false; 411 return false;
407 } 412 }
408 413
409 setAllPropertiesOfTouchInfos(touchInfos); 414 setAllPropertiesOfTouchInfos(touchInfos);
410 415
411 return true; 416 return true;
412 } 417 }
413 418
419 // TODO(rbyers): Replace with AutoReset as base/WTF unification permits.
420 class CurrentEventHolder {
421 // Always stack allocated to ensure lifetime doesn't exceed that of target
422 DISALLOW_NEW();
423 public:
424 CurrentEventHolder(PlatformEvent::EventType& target, PlatformEvent::EventTyp e value)
425 : m_target(target)
426 {
427 m_target = value;
428 }
429 ~CurrentEventHolder()
430 {
431 m_target = PlatformEvent::NoType;
432 }
433 private:
434 PlatformEvent::EventType& m_target;
435 };
436
414 WebInputEventResult TouchEventManager::handleTouchEvent( 437 WebInputEventResult TouchEventManager::handleTouchEvent(
415 const PlatformTouchEvent& event, 438 const PlatformTouchEvent& event,
416 HeapVector<TouchInfo>& touchInfos) 439 HeapVector<TouchInfo>& touchInfos)
417 { 440 {
441 // Track the current event for the scope of this function.
442 CurrentEventHolder holder(m_currentEvent, event.type());
443
418 if (!reHitTestTouchPointsIfNeeded(event, touchInfos)) 444 if (!reHitTestTouchPointsIfNeeded(event, touchInfos))
419 return WebInputEventResult::NotHandled; 445 return WebInputEventResult::NotHandled;
420 446
421 // Note that the disposition of any pointer events affects only the generati on of touch 447 // Note that the disposition of any pointer events affects only the generati on of touch
422 // events. If all pointer events were handled (and hence no touch events wer e fired), that 448 // events. If all pointer events were handled (and hence no touch events wer e fired), that
423 // is still equivalent to the touch events going unhandled because pointer e vent handler 449 // is still equivalent to the touch events going unhandled because pointer e vent handler
424 // don't block scroll gesture generation. 450 // don't block scroll gesture generation.
425 451
426 // TODO(crbug.com/507408): If PE handlers always call preventDefault, we won 't see TEs until after 452 // TODO(crbug.com/507408): If PE handlers always call preventDefault, we won 't see TEs until after
427 // scrolling starts because the scrolling would suppress upcoming PEs. This sudden "break" in TE 453 // scrolling starts because the scrolling would suppress upcoming PEs. This sudden "break" in TE
(...skipping 20 matching lines...) Expand all
448 if (m_touchSequenceDocument && m_touchSequenceDocument->frame()) { 474 if (m_touchSequenceDocument && m_touchSequenceDocument->frame()) {
449 SecurityOrigin* securityOrigin = m_touchSequenceDocument->frame()->secur ityContext()->getSecurityOrigin(); 475 SecurityOrigin* securityOrigin = m_touchSequenceDocument->frame()->secur ityContext()->getSecurityOrigin();
450 Frame* top = m_frame->tree().top(); 476 Frame* top = m_frame->tree().top();
451 if (top && securityOrigin->canAccess(top->securityContext()->getSecurity Origin())) 477 if (top && securityOrigin->canAccess(top->securityContext()->getSecurity Origin()))
452 isSameOrigin = true; 478 isSameOrigin = true;
453 } 479 }
454 480
455 OwnPtr<UserGestureIndicator> gestureIndicator; 481 OwnPtr<UserGestureIndicator> gestureIndicator;
456 if (isTap || isSameOrigin) { 482 if (isTap || isSameOrigin) {
457 UserGestureUtilizedCallback* callback = 0; 483 UserGestureUtilizedCallback* callback = 0;
458 if (!isTap) { 484 // These are cases we'd like to migrate to not hold a user gesture.
459 // This is some other touch event that we currently consider a user gesture. So 485 if (event.type() == PlatformEvent::TouchStart
460 // use a UserGestureUtilizedCallback to get metrics. 486 || event.type() == PlatformEvent::TouchMove
461 callback = &m_touchSequenceDocument->frame()->eventHandler(); 487 || (event.type() == PlatformEvent::TouchEnd && m_touchScrollStarted) ) {
488 // Collect metrics in userGestureUtilized().
489 callback = this;
462 } 490 }
463
464 if (m_touchSequenceUserGestureToken) 491 if (m_touchSequenceUserGestureToken)
465 gestureIndicator = adoptPtr(new UserGestureIndicator(m_touchSequence UserGestureToken.release(), callback)); 492 gestureIndicator = adoptPtr(new UserGestureIndicator(m_touchSequence UserGestureToken.release(), callback));
466 else 493 else
467 gestureIndicator = adoptPtr(new UserGestureIndicator(DefinitelyProce ssingUserGesture, callback)); 494 gestureIndicator = adoptPtr(new UserGestureIndicator(DefinitelyProce ssingUserGesture, callback));
468 m_touchSequenceUserGestureToken = UserGestureIndicator::currentToken(); 495 m_touchSequenceUserGestureToken = UserGestureIndicator::currentToken();
469 } 496 }
470 497
471 return dispatchTouchEvents(event, touchInfos, allTouchesReleased); 498 return dispatchTouchEvents(event, touchInfos, allTouchesReleased);
472 } 499 }
473 500
474 void TouchEventManager::clear() 501 void TouchEventManager::clear()
475 { 502 {
476 m_touchSequenceDocument.clear(); 503 m_touchSequenceDocument.clear();
477 m_touchSequenceUserGestureToken.clear(); 504 m_touchSequenceUserGestureToken.clear();
478 m_targetForTouchID.clear(); 505 m_targetForTouchID.clear();
479 m_regionForTouchID.clear(); 506 m_regionForTouchID.clear();
480 m_touchPressed = false; 507 m_touchPressed = false;
481 m_waitingForFirstTouchMove = false; 508 m_waitingForFirstTouchMove = false;
509 m_touchScrollStarted = false;
510 m_currentEvent = PlatformEvent::NoType;
482 } 511 }
483 512
484 bool TouchEventManager::isAnyTouchActive() const 513 bool TouchEventManager::isAnyTouchActive() const
485 { 514 {
486 return m_touchPressed; 515 return m_touchPressed;
487 } 516 }
488 517
489 DEFINE_TRACE(TouchEventManager) 518 DEFINE_TRACE(TouchEventManager)
490 { 519 {
491 visitor->trace(m_frame); 520 visitor->trace(m_frame);
492 visitor->trace(m_touchSequenceDocument); 521 visitor->trace(m_touchSequenceDocument);
493 visitor->trace(m_targetForTouchID); 522 visitor->trace(m_targetForTouchID);
494 } 523 }
495 524
525 void TouchEventManager::userGestureUtilized()
526 {
527 // This is invoked for UserGestureIndicators created in TouchEventManger::ha ndleTouchEvent which perhaps
528 // represent touch actions which shouldn't be considered a user-gesture. Tr igger a UseCounter based
529 // on the touch event that's currently being dispatched.
530 UseCounter::Feature feature;
531
532 switch (m_currentEvent) {
533 case PlatformEvent::TouchStart:
534 feature = UseCounter::TouchStartUserGestureUtilized;
535 break;
536 case PlatformEvent::TouchMove:
537 feature = UseCounter::TouchMoveUserGestureUtilized;
538 break;
539 case PlatformEvent::TouchEnd:
540 feature = UseCounter::TouchEndDuringScrollUserGestureUtilized;
541 break;
542 default:
543 NOTREACHED();
544 return;
545 }
546 Deprecation::countDeprecation(m_frame, feature);
547 }
548
496 } // namespace blink 549 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/input/TouchEventManager.h ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698