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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 | 88 |
89 TouchEventManager::~TouchEventManager() | 89 TouchEventManager::~TouchEventManager() |
90 { | 90 { |
91 } | 91 } |
92 | 92 |
93 WebInputEventResult TouchEventManager::dispatchTouchEvents( | 93 WebInputEventResult TouchEventManager::dispatchTouchEvents( |
94 const PlatformTouchEvent& event, | 94 const PlatformTouchEvent& event, |
95 const HeapVector<TouchInfo>& touchInfos, | 95 const HeapVector<TouchInfo>& touchInfos, |
96 bool allTouchesReleased) | 96 bool allTouchesReleased) |
97 { | 97 { |
98 bool touchStartOrFirstTouchMove = false; | |
99 if (event.type() == PlatformEvent::TouchStart) { | |
100 m_waitingForFirstTouchMove = true; | |
101 touchStartOrFirstTouchMove = true; | |
102 } else if (event.type() == PlatformEvent::TouchMove) { | |
103 touchStartOrFirstTouchMove = m_waitingForFirstTouchMove; | |
104 m_waitingForFirstTouchMove = false; | |
105 } | |
106 | |
107 // Build up the lists to use for the |touches|, |targetTouches| and | 98 // Build up the lists to use for the |touches|, |targetTouches| and |
108 // |changedTouches| attributes in the JS event. See | 99 // |changedTouches| attributes in the JS event. See |
109 // http://www.w3.org/TR/touch-events/#touchevent-interface for how these | 100 // http://www.w3.org/TR/touch-events/#touchevent-interface for how these |
110 // lists fit together. | 101 // lists fit together. |
111 | 102 |
112 // Holds the complete set of touches on the screen. | 103 // Holds the complete set of touches on the screen. |
113 TouchList* touches = TouchList::create(); | 104 TouchList* touches = TouchList::create(); |
114 | 105 |
115 // A different view on the 'touches' list above, filtered and grouped by | 106 // A different view on the 'touches' list above, filtered and grouped by |
116 // event target. Used for the |targetTouches| list in the JS event. | 107 // event target. Used for the |targetTouches| list in the JS event. |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 for (unsigned state = 0; state != PlatformTouchPoint::TouchStateEnd; ++state
) { | 170 for (unsigned state = 0; state != PlatformTouchPoint::TouchStateEnd; ++state
) { |
180 if (!changedTouches[state].m_touches) | 171 if (!changedTouches[state].m_touches) |
181 continue; | 172 continue; |
182 | 173 |
183 const AtomicString& eventName(touchEventNameForTouchPointState(static_ca
st<PlatformTouchPoint::TouchState>(state))); | 174 const AtomicString& eventName(touchEventNameForTouchPointState(static_ca
st<PlatformTouchPoint::TouchState>(state))); |
184 for (const auto& eventTarget : changedTouches[state].m_targets) { | 175 for (const auto& eventTarget : changedTouches[state].m_targets) { |
185 EventTarget* touchEventTarget = eventTarget; | 176 EventTarget* touchEventTarget = eventTarget; |
186 TouchEvent* touchEvent = TouchEvent::create( | 177 TouchEvent* touchEvent = TouchEvent::create( |
187 touches, touchesByTarget.get(touchEventTarget), changedTouches[s
tate].m_touches.get(), | 178 touches, touchesByTarget.get(touchEventTarget), changedTouches[s
tate].m_touches.get(), |
188 eventName, touchEventTarget->toNode()->document().domWindow(), | 179 eventName, touchEventTarget->toNode()->document().domWindow(), |
189 event.getModifiers(), event.cancelable(), event.causesScrollingI
fUncanceled(), touchStartOrFirstTouchMove, event.timestamp()); | 180 event.getModifiers(), event.cancelable(), event.causesScrollingI
fUncanceled(), event.touchStartOrFirstTouchMove(), event.timestamp()); |
190 | 181 |
191 DispatchEventResult domDispatchResult = touchEventTarget->dispatchEv
ent(touchEvent); | 182 DispatchEventResult domDispatchResult = touchEventTarget->dispatchEv
ent(touchEvent); |
192 | 183 |
193 // Only report for top level documents with a single touch on | 184 // Only report for top level documents with a single touch on |
194 // touch-start or the first touch-move. | 185 // touch-start or the first touch-move. |
195 if (touchStartOrFirstTouchMove && touchInfos.size() == 1 && event.ca
ncelable() && m_frame->isMainFrame()) { | 186 if (event.touchStartOrFirstTouchMove() && touchInfos.size() == 1 &&
m_frame->isMainFrame()) { |
196 | 187 |
197 // Record the disposition and latency of touch starts and first
touch moves before and after the page is fully loaded respectively. | 188 // Record the disposition and latency of touch starts and first
touch moves before and after the page is fully loaded respectively. |
198 int64_t latencyInMicros = static_cast<int64_t>((monotonicallyInc
reasingTime() - event.timestamp()) * 1000000.0); | 189 int64_t latencyInMicros = static_cast<int64_t>((monotonicallyInc
reasingTime() - event.timestamp()) * 1000000.0); |
199 if (m_frame->document()->isLoadCompleted()) { | 190 if (event.cancelable()) { |
200 DEFINE_STATIC_LOCAL(EnumerationHistogram, touchDispositionsA
fterPageLoadHistogram, ("Event.Touch.TouchDispositionsAfterPageLoad", TouchEvent
DispatchResultTypeMax)); | 191 if (m_frame->document()->isLoadCompleted()) { |
201 touchDispositionsAfterPageLoadHistogram.count((domDispatchRe
sult != DispatchEventResult::NotCanceled) ? HandledTouches : UnhandledTouches); | 192 DEFINE_STATIC_LOCAL(EnumerationHistogram, touchDispositi
onsAfterPageLoadHistogram, ("Event.Touch.TouchDispositionsAfterPageLoad", TouchE
ventDispatchResultTypeMax)); |
| 193 touchDispositionsAfterPageLoadHistogram.count((domDispat
chResult != DispatchEventResult::NotCanceled) ? HandledTouches : UnhandledTouche
s); |
202 | 194 |
203 DEFINE_STATIC_LOCAL(CustomCountHistogram, eventLatencyAfterP
ageLoadHistogram, ("Event.Touch.TouchLatencyAfterPageLoad", 1, 100000000, 50)); | 195 DEFINE_STATIC_LOCAL(CustomCountHistogram, eventLatencyAf
terPageLoadHistogram, ("Event.Touch.TouchLatencyAfterPageLoad", 1, 100000000, 50
)); |
204 eventLatencyAfterPageLoadHistogram.count(latencyInMicros); | 196 eventLatencyAfterPageLoadHistogram.count(latencyInMicros
); |
205 } else { | 197 } else { |
206 DEFINE_STATIC_LOCAL(EnumerationHistogram, touchDispositionsB
eforePageLoadHistogram, ("Event.Touch.TouchDispositionsBeforePageLoad", TouchEve
ntDispatchResultTypeMax)); | 198 DEFINE_STATIC_LOCAL(EnumerationHistogram, touchDispositi
onsBeforePageLoadHistogram, ("Event.Touch.TouchDispositionsBeforePageLoad", Touc
hEventDispatchResultTypeMax)); |
207 touchDispositionsBeforePageLoadHistogram.count((domDispatchR
esult != DispatchEventResult::NotCanceled) ? HandledTouches : UnhandledTouches); | 199 touchDispositionsBeforePageLoadHistogram.count((domDispa
tchResult != DispatchEventResult::NotCanceled) ? HandledTouches : UnhandledTouch
es); |
208 | 200 |
209 DEFINE_STATIC_LOCAL(CustomCountHistogram, eventLatencyBefore
PageLoadHistogram, ("Event.Touch.TouchLatencyBeforePageLoad", 1, 100000000, 50))
; | 201 DEFINE_STATIC_LOCAL(CustomCountHistogram, eventLatencyBe
forePageLoadHistogram, ("Event.Touch.TouchLatencyBeforePageLoad", 1, 100000000,
50)); |
210 eventLatencyBeforePageLoadHistogram.count(latencyInMicros); | 202 eventLatencyBeforePageLoadHistogram.count(latencyInMicro
s); |
| 203 } |
| 204 // Report the touch disposition there is no active fling ani
mation. |
| 205 DEFINE_STATIC_LOCAL(EnumerationHistogram, touchDispositionsO
utsideFlingHistogram, ("Event.Touch.TouchDispositionsOutsideFling2", TouchEventD
ispatchResultTypeMax)); |
| 206 touchDispositionsOutsideFlingHistogram.count((domDispatchRes
ult != DispatchEventResult::NotCanceled) ? HandledTouches : UnhandledTouches); |
211 } | 207 } |
212 | 208 |
213 // Report the touch disposition, split by whether there is an ac
tive fling animation. | 209 // Report the touch disposition when there is an active fling an
imation. |
214 if (event.type() == PlatformEvent::TouchStart) { | 210 if (event.dispatchType() == PlatformEvent::ListenersForcedNonBlo
ckingDueToFling) { |
215 if (event.dispatchedDuringFling()) { | 211 DEFINE_STATIC_LOCAL(EnumerationHistogram, touchDispositionsD
uringFlingHistogram, ("Event.Touch.TouchDispositionsDuringFling2", TouchEventDis
patchResultTypeMax)); |
216 DEFINE_STATIC_LOCAL(EnumerationHistogram, touchDispositi
onsDuringFlingHistogram, ("Event.Touch.TouchDispositionsDuringFling", TouchEvent
DispatchResultTypeMax)); | 212 touchDispositionsDuringFlingHistogram.count(touchEvent->prev
entDefaultCalledOnUncancelableEvent() ? HandledTouches : UnhandledTouches); |
217 touchDispositionsDuringFlingHistogram.count((domDispatch
Result != DispatchEventResult::NotCanceled) ? HandledTouches : UnhandledTouches)
; | |
218 } else { | |
219 DEFINE_STATIC_LOCAL(EnumerationHistogram, touchDispositi
onsOutsideFlingHistogram, ("Event.Touch.TouchDispositionsOutsideFling", TouchEve
ntDispatchResultTypeMax)); | |
220 touchDispositionsOutsideFlingHistogram.count((domDispatc
hResult != DispatchEventResult::NotCanceled) ? HandledTouches : UnhandledTouches
); | |
221 } | |
222 } | 213 } |
223 } | 214 } |
224 eventResult = EventHandler::mergeEventResult(eventResult, | 215 eventResult = EventHandler::mergeEventResult(eventResult, |
225 EventHandler::toWebInputEventResult(domDispatchResult)); | 216 EventHandler::toWebInputEventResult(domDispatchResult)); |
226 } | 217 } |
227 } | 218 } |
228 | 219 |
229 if (allTouchesReleased) | 220 if (allTouchesReleased) |
230 m_touchScrollStarted = false; | 221 m_touchScrollStarted = false; |
231 | 222 |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
491 return dispatchTouchEvents(event, touchInfos, allTouchesReleased); | 482 return dispatchTouchEvents(event, touchInfos, allTouchesReleased); |
492 } | 483 } |
493 | 484 |
494 void TouchEventManager::clear() | 485 void TouchEventManager::clear() |
495 { | 486 { |
496 m_touchSequenceDocument.clear(); | 487 m_touchSequenceDocument.clear(); |
497 m_touchSequenceUserGestureToken.clear(); | 488 m_touchSequenceUserGestureToken.clear(); |
498 m_targetForTouchID.clear(); | 489 m_targetForTouchID.clear(); |
499 m_regionForTouchID.clear(); | 490 m_regionForTouchID.clear(); |
500 m_touchPressed = false; | 491 m_touchPressed = false; |
501 m_waitingForFirstTouchMove = false; | |
502 m_touchScrollStarted = false; | 492 m_touchScrollStarted = false; |
503 m_currentEvent = PlatformEvent::NoType; | 493 m_currentEvent = PlatformEvent::NoType; |
504 } | 494 } |
505 | 495 |
506 bool TouchEventManager::isAnyTouchActive() const | 496 bool TouchEventManager::isAnyTouchActive() const |
507 { | 497 { |
508 return m_touchPressed; | 498 return m_touchPressed; |
509 } | 499 } |
510 | 500 |
511 DEFINE_TRACE(TouchEventManager) | 501 DEFINE_TRACE(TouchEventManager) |
(...skipping 21 matching lines...) Expand all Loading... |
533 feature = UseCounter::TouchEndDuringScrollUserGestureUtilized; | 523 feature = UseCounter::TouchEndDuringScrollUserGestureUtilized; |
534 break; | 524 break; |
535 default: | 525 default: |
536 NOTREACHED(); | 526 NOTREACHED(); |
537 return; | 527 return; |
538 } | 528 } |
539 Deprecation::countDeprecation(m_frame, feature); | 529 Deprecation::countDeprecation(m_frame, feature); |
540 } | 530 } |
541 | 531 |
542 } // namespace blink | 532 } // namespace blink |
OLD | NEW |