| 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/EventHandlerRegistry.h" | 9 #include "core/frame/EventHandlerRegistry.h" |
| 10 #include "core/frame/FrameHost.h" | 10 #include "core/frame/FrameHost.h" |
| (...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 460 | 460 |
| 461 bool allTouchesReleased = true; | 461 bool allTouchesReleased = true; |
| 462 for (const auto& point : event.touchPoints()) { | 462 for (const auto& point : event.touchPoints()) { |
| 463 if (point.state() != PlatformTouchPoint::TouchReleased | 463 if (point.state() != PlatformTouchPoint::TouchReleased |
| 464 && point.state() != PlatformTouchPoint::TouchCancelled) | 464 && point.state() != PlatformTouchPoint::TouchCancelled) |
| 465 allTouchesReleased = false; | 465 allTouchesReleased = false; |
| 466 } | 466 } |
| 467 | 467 |
| 468 // Whether a touch should be considered a "user gesture" or not is a tricky
question. | 468 // Whether a touch should be considered a "user gesture" or not is a tricky
question. |
| 469 // https://docs.google.com/document/d/1oF1T3O7_E4t1PYHV6gyCwHxOi3ystm0eSL5xZ
u7nvOg/edit# | 469 // https://docs.google.com/document/d/1oF1T3O7_E4t1PYHV6gyCwHxOi3ystm0eSL5xZ
u7nvOg/edit# |
| 470 // TODO(rbyers): Disable user gesture in some cases but retain logging for n
ow (crbug.com/582140). | 470 |
| 471 // The touchend corresponding to a tap is always a user gesture. |
| 472 bool isTap = event.touchPoints().size() == 1 |
| 473 && event.touchPoints()[0].state() == PlatformTouchPoint::TouchReleased |
| 474 && !event.causesScrollingIfUncanceled(); |
| 475 |
| 476 // For now, disallow dragging as a user gesture when the events are being se
nt to a |
| 477 // cross-origin iframe (crbug.com/582140). |
| 478 bool isSameOrigin = false; |
| 479 if (m_touchSequenceDocument && m_touchSequenceDocument->frame()) { |
| 480 SecurityOrigin* securityOrigin = m_touchSequenceDocument->frame()->secur
ityContext()->getSecurityOrigin(); |
| 481 Frame* top = m_frame->tree().top(); |
| 482 if (top && securityOrigin->canAccess(top->securityContext()->getSecurity
Origin())) |
| 483 isSameOrigin = true; |
| 484 } |
| 485 |
| 471 OwnPtr<UserGestureIndicator> gestureIndicator; | 486 OwnPtr<UserGestureIndicator> gestureIndicator; |
| 472 if (event.touchPoints().size() == 1 | 487 if (isTap || isSameOrigin) { |
| 473 && event.touchPoints()[0].state() == PlatformTouchPoint::TouchReleased | 488 UserGestureUtilizedCallback* callback = 0; |
| 474 && !event.causesScrollingIfUncanceled()) { | 489 if (!isTap) { |
| 475 // This is a touchend corresponding to a tap, definitely a user gesture.
So don't supply | 490 // This is some other touch event that we currently consider a user
gesture. So |
| 476 // a UserGestureUtilizedCallback. | 491 // use a UserGestureUtilizedCallback to get metrics. |
| 477 gestureIndicator = adoptPtr(new UserGestureIndicator(DefinitelyProcessin
gUserGesture)); | 492 callback = &m_touchSequenceDocument->frame()->eventHandler(); |
| 478 } else { | 493 } |
| 479 // This is some other touch event that perhaps shouldn't be considered a
user gesture. So | 494 |
| 480 // use a UserGestureUtilizedCallback to get metrics / deprecation warnin
gs. | |
| 481 if (m_touchSequenceUserGestureToken) | 495 if (m_touchSequenceUserGestureToken) |
| 482 gestureIndicator = adoptPtr(new UserGestureIndicator(m_touchSequence
UserGestureToken.release(), &m_touchSequenceDocument->frame()->eventHandler())); | 496 gestureIndicator = adoptPtr(new UserGestureIndicator(m_touchSequence
UserGestureToken.release(), callback)); |
| 483 else | 497 else |
| 484 gestureIndicator = adoptPtr(new UserGestureIndicator(DefinitelyProce
ssingUserGesture, &m_touchSequenceDocument->frame()->eventHandler())); | 498 gestureIndicator = adoptPtr(new UserGestureIndicator(DefinitelyProce
ssingUserGesture, callback)); |
| 485 m_touchSequenceUserGestureToken = UserGestureIndicator::currentToken(); | 499 m_touchSequenceUserGestureToken = UserGestureIndicator::currentToken(); |
| 486 } | 500 } |
| 487 | 501 |
| 488 return dispatchTouchEvents(event, touchInfos, allTouchesReleased); | 502 return dispatchTouchEvents(event, touchInfos, allTouchesReleased); |
| 489 } | 503 } |
| 490 | 504 |
| 491 void TouchEventManager::clear() | 505 void TouchEventManager::clear() |
| 492 { | 506 { |
| 493 m_touchSequenceDocument.clear(); | 507 m_touchSequenceDocument.clear(); |
| 494 m_touchSequenceUserGestureToken.clear(); | 508 m_touchSequenceUserGestureToken.clear(); |
| 495 m_targetForTouchID.clear(); | 509 m_targetForTouchID.clear(); |
| 496 m_regionForTouchID.clear(); | 510 m_regionForTouchID.clear(); |
| 497 m_touchPressed = false; | 511 m_touchPressed = false; |
| 498 m_waitingForFirstTouchMove = false; | 512 m_waitingForFirstTouchMove = false; |
| 499 } | 513 } |
| 500 | 514 |
| 501 bool TouchEventManager::isAnyTouchActive() const | 515 bool TouchEventManager::isAnyTouchActive() const |
| 502 { | 516 { |
| 503 return m_touchPressed; | 517 return m_touchPressed; |
| 504 } | 518 } |
| 505 | 519 |
| 506 DEFINE_TRACE(TouchEventManager) | 520 DEFINE_TRACE(TouchEventManager) |
| 507 { | 521 { |
| 508 visitor->trace(m_frame); | 522 visitor->trace(m_frame); |
| 509 visitor->trace(m_touchSequenceDocument); | 523 visitor->trace(m_touchSequenceDocument); |
| 510 visitor->trace(m_targetForTouchID); | 524 visitor->trace(m_targetForTouchID); |
| 511 } | 525 } |
| 512 | 526 |
| 513 } // namespace blink | 527 } // namespace blink |
| OLD | NEW |