Chromium Code Reviews| 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/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 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 264 } else { | 265 } else { |
| 265 DEFINE_STATIC_LOCAL(EnumerationHistogram, touchDispositi onsOutsideFlingHistogram, ("Event.Touch.TouchDispositionsOutsideFling", TouchEve ntDispatchResultTypeMax)); | 266 DEFINE_STATIC_LOCAL(EnumerationHistogram, touchDispositi onsOutsideFlingHistogram, ("Event.Touch.TouchDispositionsOutsideFling", TouchEve ntDispatchResultTypeMax)); |
| 266 touchDispositionsOutsideFlingHistogram.count((domDispatc hResult != DispatchEventResult::NotCanceled) ? HandledTouches : UnhandledTouches ); | 267 touchDispositionsOutsideFlingHistogram.count((domDispatc hResult != DispatchEventResult::NotCanceled) ? HandledTouches : UnhandledTouches ); |
| 267 } | 268 } |
| 268 } | 269 } |
| 269 } | 270 } |
| 270 eventResult = EventHandler::mergeEventResult(eventResult, | 271 eventResult = EventHandler::mergeEventResult(eventResult, |
| 271 EventHandler::toWebInputEventResult(domDispatchResult)); | 272 EventHandler::toWebInputEventResult(domDispatchResult)); |
| 272 } | 273 } |
| 273 } | 274 } |
| 275 | |
| 276 if (allTouchesReleased) | |
| 277 m_touchScrollStarted = false; | |
| 278 | |
| 274 return eventResult; | 279 return eventResult; |
| 275 } | 280 } |
| 276 | 281 |
| 277 void TouchEventManager::updateTargetAndRegionMapsForTouchStarts( | 282 void TouchEventManager::updateTargetAndRegionMapsForTouchStarts( |
| 278 HeapVector<TouchInfo>& touchInfos) | 283 HeapVector<TouchInfo>& touchInfos) |
| 279 { | 284 { |
| 280 for (auto& touchInfo : touchInfos) { | 285 for (auto& touchInfo : touchInfos) { |
| 281 // Touch events implicitly capture to the touched node, and don't change | 286 // Touch events implicitly capture to the touched node, and don't change |
| 282 // active/hover states themselves (Gesture events do). So we only need | 287 // active/hover states themselves (Gesture events do). So we only need |
| 283 // to hit-test on touchstart and when the target could be different than | 288 // 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 Loading... | |
| 453 m_touchSequenceUserGestureToken.clear(); | 458 m_touchSequenceUserGestureToken.clear(); |
| 454 } | 459 } |
| 455 return false; | 460 return false; |
| 456 } | 461 } |
| 457 | 462 |
| 458 setAllPropertiesOfTouchInfos(touchInfos); | 463 setAllPropertiesOfTouchInfos(touchInfos); |
| 459 | 464 |
| 460 return true; | 465 return true; |
| 461 } | 466 } |
| 462 | 467 |
| 468 class CurrentEventHolder { | |
| 469 // Always stack allocated to ensure lifetime doesn't exceed that of target | |
| 470 DISALLOW_NEW(); | |
| 471 public: | |
| 472 CurrentEventHolder(PlatformEvent::EventType& target, PlatformEvent::EventTyp e value) | |
| 473 : m_target(target) | |
| 474 { | |
| 475 m_target = value; | |
| 476 } | |
| 477 ~CurrentEventHolder() | |
| 478 { | |
| 479 m_target = PlatformEvent::NoType; | |
| 480 } | |
| 481 private: | |
| 482 PlatformEvent::EventType& m_target; | |
| 483 }; | |
| 484 | |
| 463 WebInputEventResult TouchEventManager::handleTouchEvent( | 485 WebInputEventResult TouchEventManager::handleTouchEvent( |
| 464 const PlatformTouchEvent& event, | 486 const PlatformTouchEvent& event, |
| 465 HeapVector<TouchInfo>& touchInfos) | 487 HeapVector<TouchInfo>& touchInfos) |
| 466 { | 488 { |
| 489 // Track the current event for the scope of this function. | |
| 490 CurrentEventHolder holder(m_currentEvent, event.type()); | |
|
dtapuska
2016/05/24 14:54:27
Can we not use base/auto_reset.h ? base/macros.h i
Rick Byers
2016/05/24 20:29:21
macros.h is the only include from base we currentl
| |
| 491 | |
| 467 if (!reHitTestTouchPointsIfNeeded(event, touchInfos)) | 492 if (!reHitTestTouchPointsIfNeeded(event, touchInfos)) |
| 468 return WebInputEventResult::NotHandled; | 493 return WebInputEventResult::NotHandled; |
| 469 | 494 |
| 470 // Note that the disposition of any pointer events affects only the generati on of touch | 495 // Note that the disposition of any pointer events affects only the generati on of touch |
| 471 // events. If all pointer events were handled (and hence no touch events wer e fired), that | 496 // events. If all pointer events were handled (and hence no touch events wer e fired), that |
| 472 // is still equivalent to the touch events going unhandled because pointer e vent handler | 497 // is still equivalent to the touch events going unhandled because pointer e vent handler |
| 473 // don't block scroll gesture generation. | 498 // don't block scroll gesture generation. |
| 474 | 499 |
| 475 // TODO(crbug.com/507408): If PE handlers always call preventDefault, we won 't see TEs until after | 500 // TODO(crbug.com/507408): If PE handlers always call preventDefault, we won 't see TEs until after |
| 476 // scrolling starts because the scrolling would suppress upcoming PEs. This sudden "break" in TE | 501 // scrolling starts because the scrolling would suppress upcoming PEs. This sudden "break" in TE |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 497 if (m_touchSequenceDocument && m_touchSequenceDocument->frame()) { | 522 if (m_touchSequenceDocument && m_touchSequenceDocument->frame()) { |
| 498 SecurityOrigin* securityOrigin = m_touchSequenceDocument->frame()->secur ityContext()->getSecurityOrigin(); | 523 SecurityOrigin* securityOrigin = m_touchSequenceDocument->frame()->secur ityContext()->getSecurityOrigin(); |
| 499 Frame* top = m_frame->tree().top(); | 524 Frame* top = m_frame->tree().top(); |
| 500 if (top && securityOrigin->canAccess(top->securityContext()->getSecurity Origin())) | 525 if (top && securityOrigin->canAccess(top->securityContext()->getSecurity Origin())) |
| 501 isSameOrigin = true; | 526 isSameOrigin = true; |
| 502 } | 527 } |
| 503 | 528 |
| 504 OwnPtr<UserGestureIndicator> gestureIndicator; | 529 OwnPtr<UserGestureIndicator> gestureIndicator; |
| 505 if (isTap || isSameOrigin) { | 530 if (isTap || isSameOrigin) { |
| 506 UserGestureUtilizedCallback* callback = 0; | 531 UserGestureUtilizedCallback* callback = 0; |
| 507 if (!isTap) { | 532 if (event.type() == PlatformEvent::TouchStart |
| 508 // This is some other touch event that we currently consider a user gesture. So | 533 || event.type() == PlatformEvent::TouchMove |
| 509 // use a UserGestureUtilizedCallback to get metrics. | 534 || (event.type() == PlatformEvent::TouchEnd && m_touchScrollStarted) ) { |
| 510 callback = &m_touchSequenceDocument->frame()->eventHandler(); | 535 // These are cases we'd like to migrate to not hold a user gesture. |
|
mustaq
2016/05/24 15:54:06
The two comment lines seem to describe separate po
Rick Byers
2016/05/24 20:29:21
Done.
| |
| 536 // Collect metrics in userGestureUtilized(). | |
| 537 callback = this; | |
| 511 } | 538 } |
| 512 | |
| 513 if (m_touchSequenceUserGestureToken) | 539 if (m_touchSequenceUserGestureToken) |
| 514 gestureIndicator = adoptPtr(new UserGestureIndicator(m_touchSequence UserGestureToken.release(), callback)); | 540 gestureIndicator = adoptPtr(new UserGestureIndicator(m_touchSequence UserGestureToken.release(), callback)); |
| 515 else | 541 else |
| 516 gestureIndicator = adoptPtr(new UserGestureIndicator(DefinitelyProce ssingUserGesture, callback)); | 542 gestureIndicator = adoptPtr(new UserGestureIndicator(DefinitelyProce ssingUserGesture, callback)); |
| 517 m_touchSequenceUserGestureToken = UserGestureIndicator::currentToken(); | 543 m_touchSequenceUserGestureToken = UserGestureIndicator::currentToken(); |
| 518 } | 544 } |
| 519 | 545 |
| 520 return dispatchTouchEvents(event, touchInfos, allTouchesReleased); | 546 return dispatchTouchEvents(event, touchInfos, allTouchesReleased); |
| 521 } | 547 } |
| 522 | 548 |
| 523 void TouchEventManager::clear() | 549 void TouchEventManager::clear() |
| 524 { | 550 { |
| 525 m_touchSequenceDocument.clear(); | 551 m_touchSequenceDocument.clear(); |
| 526 m_touchSequenceUserGestureToken.clear(); | 552 m_touchSequenceUserGestureToken.clear(); |
| 527 m_targetForTouchID.clear(); | 553 m_targetForTouchID.clear(); |
| 528 m_regionForTouchID.clear(); | 554 m_regionForTouchID.clear(); |
| 529 m_touchPressed = false; | 555 m_touchPressed = false; |
| 530 m_waitingForFirstTouchMove = false; | 556 m_waitingForFirstTouchMove = false; |
| 557 m_touchScrollStarted = false; | |
| 558 m_currentEvent = PlatformEvent::NoType; | |
| 531 } | 559 } |
| 532 | 560 |
| 533 bool TouchEventManager::isAnyTouchActive() const | 561 bool TouchEventManager::isAnyTouchActive() const |
| 534 { | 562 { |
| 535 return m_touchPressed; | 563 return m_touchPressed; |
| 536 } | 564 } |
| 537 | 565 |
| 538 DEFINE_TRACE(TouchEventManager) | 566 DEFINE_TRACE(TouchEventManager) |
| 539 { | 567 { |
| 540 visitor->trace(m_frame); | 568 visitor->trace(m_frame); |
| 541 visitor->trace(m_touchSequenceDocument); | 569 visitor->trace(m_touchSequenceDocument); |
| 542 visitor->trace(m_targetForTouchID); | 570 visitor->trace(m_targetForTouchID); |
| 543 } | 571 } |
| 544 | 572 |
| 573 void TouchEventManager::userGestureUtilized() | |
| 574 { | |
| 575 // This is invoked for UserGestureIndicators created in TouchEventManger::ha ndleTouchEvent which perhaps | |
| 576 // represent touch actions which shouldn't be considered a user-gesture. Tr igger a UseCounter based | |
| 577 // on the touch event that's currently being dispatched. | |
| 578 UseCounter::Feature feature; | |
| 579 | |
| 580 switch (m_currentEvent) { | |
| 581 case PlatformEvent::TouchStart: | |
| 582 feature = UseCounter::TouchStartUserGestureUtilized; | |
| 583 break; | |
| 584 case PlatformEvent::TouchMove: | |
| 585 feature = UseCounter::TouchMoveUserGestureUtilized; | |
| 586 break; | |
| 587 case PlatformEvent::TouchEnd: | |
| 588 feature = UseCounter::TouchEndDuringScrollUserGestureUtilized; | |
| 589 break; | |
| 590 default: | |
| 591 NOTREACHED(); | |
| 592 return; | |
| 593 } | |
| 594 Deprecation::countDeprecation(m_frame, feature); | |
| 595 } | |
| 596 | |
| 545 } // namespace blink | 597 } // namespace blink |
| OLD | NEW |