OLD | NEW |
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/Deprecation.h" |
10 #include "core/frame/EventHandlerRegistry.h" | 10 #include "core/frame/EventHandlerRegistry.h" |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 event.causesScrollingIfUncanceled(), | 194 event.causesScrollingIfUncanceled(), |
195 event.touchStartOrFirstTouchMove(), event.timestamp()); | 195 event.touchStartOrFirstTouchMove(), event.timestamp()); |
196 | 196 |
197 DispatchEventResult domDispatchResult = | 197 DispatchEventResult domDispatchResult = |
198 touchEventTarget->dispatchEvent(touchEvent); | 198 touchEventTarget->dispatchEvent(touchEvent); |
199 | 199 |
200 // Only report for top level documents with a single touch on | 200 // Only report for top level documents with a single touch on |
201 // touch-start or the first touch-move. | 201 // touch-start or the first touch-move. |
202 if (event.touchStartOrFirstTouchMove() && touchInfos.size() == 1 && | 202 if (event.touchStartOrFirstTouchMove() && touchInfos.size() == 1 && |
203 m_frame->isMainFrame()) { | 203 m_frame->isMainFrame()) { |
204 // Record the disposition and latency of touch starts and first touch mo
ves before and after the page is fully loaded respectively. | 204 // Record the disposition and latency of touch starts and first touch |
| 205 // moves before and after the page is fully loaded respectively. |
205 int64_t latencyInMicros = static_cast<int64_t>( | 206 int64_t latencyInMicros = static_cast<int64_t>( |
206 (monotonicallyIncreasingTime() - event.timestamp()) * 1000000.0); | 207 (monotonicallyIncreasingTime() - event.timestamp()) * 1000000.0); |
207 if (event.cancelable()) { | 208 if (event.cancelable()) { |
208 if (m_frame->document()->isLoadCompleted()) { | 209 if (m_frame->document()->isLoadCompleted()) { |
209 DEFINE_STATIC_LOCAL(EnumerationHistogram, | 210 DEFINE_STATIC_LOCAL(EnumerationHistogram, |
210 touchDispositionsAfterPageLoadHistogram, | 211 touchDispositionsAfterPageLoadHistogram, |
211 ("Event.Touch.TouchDispositionsAfterPageLoad", | 212 ("Event.Touch.TouchDispositionsAfterPageLoad", |
212 TouchEventDispatchResultTypeMax)); | 213 TouchEventDispatchResultTypeMax)); |
213 touchDispositionsAfterPageLoadHistogram.count( | 214 touchDispositionsAfterPageLoadHistogram.count( |
214 (domDispatchResult != DispatchEventResult::NotCanceled) | 215 (domDispatchResult != DispatchEventResult::NotCanceled) |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
363 // No hittest is performed on move or stationary, since the target | 364 // No hittest is performed on move or stationary, since the target |
364 // is not allowed to change anyway. | 365 // is not allowed to change anyway. |
365 touchNode = m_targetForTouchID.get(touchInfo.point.id()); | 366 touchNode = m_targetForTouchID.get(touchInfo.point.id()); |
366 regionID = m_regionForTouchID.get(touchInfo.point.id()); | 367 regionID = m_regionForTouchID.get(touchInfo.point.id()); |
367 } | 368 } |
368 | 369 |
369 LocalFrame* targetFrame = nullptr; | 370 LocalFrame* targetFrame = nullptr; |
370 bool knownTarget = false; | 371 bool knownTarget = false; |
371 if (touchNode) { | 372 if (touchNode) { |
372 Document& doc = touchNode->document(); | 373 Document& doc = touchNode->document(); |
373 // If the target node has moved to a new document while it was being touch
ed, | 374 // If the target node has moved to a new document while it was being |
374 // we can't send events to the new document because that could leak nodes | 375 // touched, we can't send events to the new document because that could |
375 // from one document to another. See http://crbug.com/394339. | 376 // leak nodes from one document to another. See http://crbug.com/394339. |
376 if (&doc == m_touchSequenceDocument.get()) { | 377 if (&doc == m_touchSequenceDocument.get()) { |
377 targetFrame = doc.frame(); | 378 targetFrame = doc.frame(); |
378 knownTarget = true; | 379 knownTarget = true; |
379 } | 380 } |
380 } | 381 } |
381 if (!knownTarget) { | 382 if (!knownTarget) { |
382 // If we don't have a target registered for the point it means we've | 383 // If we don't have a target registered for the point it means we've |
383 // missed our opportunity to do a hit test for it (due to some | 384 // missed our opportunity to do a hit test for it (due to some |
384 // optimization that prevented blink from ever seeing the | 385 // optimization that prevented blink from ever seeing the |
385 // touchstart), or that the touch started outside the active touch | 386 // touchstart), or that the touch started outside the active touch |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
430 // have some tests that violate this, ClusterFuzz could trigger it, and | 431 // have some tests that violate this, ClusterFuzz could trigger it, and |
431 // there may be cases where the browser doesn't reliably release all | 432 // there may be cases where the browser doesn't reliably release all |
432 // touches. http://crbug.com/345372 tracks this. | 433 // touches. http://crbug.com/345372 tracks this. |
433 m_touchSequenceDocument.clear(); | 434 m_touchSequenceDocument.clear(); |
434 m_touchSequenceUserGestureToken.clear(); | 435 m_touchSequenceUserGestureToken.clear(); |
435 } | 436 } |
436 | 437 |
437 ASSERT(m_frame->view()); | 438 ASSERT(m_frame->view()); |
438 if (m_touchSequenceDocument && (!m_touchSequenceDocument->frame() || | 439 if (m_touchSequenceDocument && (!m_touchSequenceDocument->frame() || |
439 !m_touchSequenceDocument->frame()->view())) { | 440 !m_touchSequenceDocument->frame()->view())) { |
440 // If the active touch document has no frame or view, it's probably being de
stroyed | 441 // If the active touch document has no frame or view, it's probably being |
441 // so we can't dispatch events. | 442 // destroyed so we can't dispatch events. |
442 return false; | 443 return false; |
443 } | 444 } |
444 | 445 |
445 updateTargetAndRegionMapsForTouchStarts(touchInfos); | 446 updateTargetAndRegionMapsForTouchStarts(touchInfos); |
446 | 447 |
447 m_touchPressed = !allTouchesReleased; | 448 m_touchPressed = !allTouchesReleased; |
448 | 449 |
449 // If there's no document receiving touch events, or no handlers on the | 450 // If there's no document receiving touch events, or no handlers on the |
450 // document set to receive the events, then we can skip all the rest of | 451 // document set to receive the events, then we can skip all the rest of |
451 // this work. | 452 // this work. |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
491 if (!reHitTestTouchPointsIfNeeded(event, touchInfos)) | 492 if (!reHitTestTouchPointsIfNeeded(event, touchInfos)) |
492 return WebInputEventResult::NotHandled; | 493 return WebInputEventResult::NotHandled; |
493 | 494 |
494 bool allTouchesReleased = true; | 495 bool allTouchesReleased = true; |
495 for (const auto& point : event.touchPoints()) { | 496 for (const auto& point : event.touchPoints()) { |
496 if (point.state() != PlatformTouchPoint::TouchReleased && | 497 if (point.state() != PlatformTouchPoint::TouchReleased && |
497 point.state() != PlatformTouchPoint::TouchCancelled) | 498 point.state() != PlatformTouchPoint::TouchCancelled) |
498 allTouchesReleased = false; | 499 allTouchesReleased = false; |
499 } | 500 } |
500 | 501 |
501 // Whether a touch should be considered a "user gesture" or not is a tricky qu
estion. | 502 // Whether a touch should be considered a "user gesture" or not is a tricky |
| 503 // question. |
502 // https://docs.google.com/document/d/1oF1T3O7_E4t1PYHV6gyCwHxOi3ystm0eSL5xZu7
nvOg/edit# | 504 // https://docs.google.com/document/d/1oF1T3O7_E4t1PYHV6gyCwHxOi3ystm0eSL5xZu7
nvOg/edit# |
503 | 505 |
504 // The touchend corresponding to a tap is always a user gesture. | 506 // The touchend corresponding to a tap is always a user gesture. |
505 bool isTap = | 507 bool isTap = |
506 event.touchPoints().size() == 1 && | 508 event.touchPoints().size() == 1 && |
507 event.touchPoints()[0].state() == PlatformTouchPoint::TouchReleased && | 509 event.touchPoints()[0].state() == PlatformTouchPoint::TouchReleased && |
508 !event.causesScrollingIfUncanceled(); | 510 !event.causesScrollingIfUncanceled(); |
509 | 511 |
510 // For now, disallow dragging as a user gesture when the events are being sent
to a | 512 // For now, disallow dragging as a user gesture when the events are being sent |
511 // cross-origin iframe (crbug.com/582140). | 513 // to a cross-origin iframe (crbug.com/582140). |
512 bool isSameOrigin = false; | 514 bool isSameOrigin = false; |
513 if (m_touchSequenceDocument && m_touchSequenceDocument->frame()) { | 515 if (m_touchSequenceDocument && m_touchSequenceDocument->frame()) { |
514 SecurityOrigin* securityOrigin = m_touchSequenceDocument->frame() | 516 SecurityOrigin* securityOrigin = m_touchSequenceDocument->frame() |
515 ->securityContext() | 517 ->securityContext() |
516 ->getSecurityOrigin(); | 518 ->getSecurityOrigin(); |
517 Frame* top = m_frame->tree().top(); | 519 Frame* top = m_frame->tree().top(); |
518 if (top && | 520 if (top && |
519 securityOrigin->canAccess(top->securityContext()->getSecurityOrigin())) | 521 securityOrigin->canAccess(top->securityContext()->getSecurityOrigin())) |
520 isSameOrigin = true; | 522 isSameOrigin = true; |
521 } | 523 } |
(...skipping 17 matching lines...) Expand all Loading... |
539 m_touchSequenceUserGestureToken = UserGestureIndicator::currentToken(); | 541 m_touchSequenceUserGestureToken = UserGestureIndicator::currentToken(); |
540 } | 542 } |
541 | 543 |
542 return dispatchTouchEvents(event, touchInfos, allTouchesReleased); | 544 return dispatchTouchEvents(event, touchInfos, allTouchesReleased); |
543 } | 545 } |
544 | 546 |
545 bool TouchEventManager::isAnyTouchActive() const { | 547 bool TouchEventManager::isAnyTouchActive() const { |
546 return m_touchPressed; | 548 return m_touchPressed; |
547 } | 549 } |
548 | 550 |
549 | |
550 void TouchEventManager::userGestureUtilized() { | 551 void TouchEventManager::userGestureUtilized() { |
551 // This is invoked for UserGestureIndicators created in TouchEventManger::hand
leTouchEvent which perhaps | 552 // This is invoked for UserGestureIndicators created in |
552 // represent touch actions which shouldn't be considered a user-gesture. Trig
ger a UseCounter based | 553 // TouchEventManger::handleTouchEvent which perhaps represent touch actions |
| 554 // which shouldn't be considered a user-gesture. Trigger a UseCounter based |
553 // on the touch event that's currently being dispatched. | 555 // on the touch event that's currently being dispatched. |
554 UseCounter::Feature feature; | 556 UseCounter::Feature feature; |
555 | 557 |
556 switch (m_currentEvent) { | 558 switch (m_currentEvent) { |
557 case PlatformEvent::TouchStart: | 559 case PlatformEvent::TouchStart: |
558 feature = UseCounter::TouchStartUserGestureUtilized; | 560 feature = UseCounter::TouchStartUserGestureUtilized; |
559 break; | 561 break; |
560 case PlatformEvent::TouchMove: | 562 case PlatformEvent::TouchMove: |
561 feature = UseCounter::TouchMoveUserGestureUtilized; | 563 feature = UseCounter::TouchMoveUserGestureUtilized; |
562 break; | 564 break; |
563 case PlatformEvent::TouchEnd: | 565 case PlatformEvent::TouchEnd: |
564 feature = UseCounter::TouchEndDuringScrollUserGestureUtilized; | 566 feature = UseCounter::TouchEndDuringScrollUserGestureUtilized; |
565 break; | 567 break; |
566 default: | 568 default: |
567 NOTREACHED(); | 569 NOTREACHED(); |
568 return; | 570 return; |
569 } | 571 } |
570 Deprecation::countDeprecation(m_frame, feature); | 572 Deprecation::countDeprecation(m_frame, feature); |
571 } | 573 } |
572 | 574 |
573 } // namespace blink | 575 } // namespace blink |
OLD | NEW |