Chromium Code Reviews| Index: third_party/WebKit/Source/core/events/TouchEvent.cpp |
| diff --git a/third_party/WebKit/Source/core/events/TouchEvent.cpp b/third_party/WebKit/Source/core/events/TouchEvent.cpp |
| index 721ec81f34e7ac66bfebdc6348c896a6b6a0f4ac..6ad2ef4b299ff99be59516900cf69666ecacda3c 100644 |
| --- a/third_party/WebKit/Source/core/events/TouchEvent.cpp |
| +++ b/third_party/WebKit/Source/core/events/TouchEvent.cpp |
| @@ -30,23 +30,145 @@ |
| #include "bindings/core/v8/ScriptState.h" |
| #include "core/events/EventDispatcher.h" |
| #include "core/frame/FrameConsole.h" |
| +#include "core/frame/FrameView.h" |
| #include "core/frame/LocalDOMWindow.h" |
| #include "core/inspector/ConsoleMessage.h" |
| +#include "platform/Histogram.h" |
| namespace blink { |
| +namespace { |
| + |
| +// These offsets change indicies into the ListenerHistogram |
| +// enumeration. The addition of a series of offsets then |
| +// produces the resulting ListenerHistogram value. |
| +// TODO(dtapuska): Remove all of these histogram counts once |
| +// https://crbug.com/599609 is fixed. |
| +const size_t kTouchTargetHistogramRootScrollerOffset = 6; |
| +const size_t kTouchTargetHistogramScrollableDocumentOffset = 3; |
| +const size_t kTouchTargetHistogramAlreadyHandledOffset = 0; |
| +const size_t kTouchTargetHistogramNotHandledOffset = 1; |
| +const size_t kTouchTargetHistogramHandledOffset = 2; |
| +const size_t kCapturingOffset = 0; |
| +const size_t kAtTargetOffset = 12; |
| +const size_t kBubblingOffset = 24; |
| + |
| +enum TouchTargetAndDispatchResultType { |
| + // The following enums represent state captured during the CAPTURING_PHASE. |
| + CapturingNonRootScrollerNonScrollableAlreadyHandled, // Non-root-scroller, non-scrollable document, already handled. |
| + CapturingNonRootScrollerNonScrollableNotHandled, // Non-root-scroller, non-scrollable document, not handled. |
| + CapturingNonRootScrollerNonScrollableHandled, // Non-root-scroller, non-scrollable document, handled application. |
| + CapturingNonRootScrollerScrollableDocumentAlreadyHandled, // Non-root-scroller, scrollable document, already handled. |
| + CapturingNonRootScrollerScrollableDocumentNotHandled, // Non-root-scroller, scrollable document, not handled. |
| + CapturingNonRootScrollerScrollableDocumentHandled, // Non-root-scroller, scrollable document, handled application. |
| + CapturingRootScrollerNonScrollableAlreadyHandled, // Root-scroller, non-scrollable document, already handled. |
| + CapturingRootScrollerNonScrollableNotHandled, // Root-scroller, non-scrollable document, not handled. |
| + CapturingRootScrollerNonScrollableHandled, // Root-scroller, non-scrollable document, handled. |
| + CapturingRootScrollerScrollableDocumentAlreadyHandled, // Root-scroller, scrollable document, already handled. |
| + CapturingRootScrollerScrollableDocumentNotHandled, // Root-scroller, scrollable document, not handled. |
| + CapturingRootScrollerScrollableDocumentHandled, // Root-scroller, scrollable document, handled. |
| + |
| + // The following enums represent state captured during the AT_TARGET phase. |
| + NonRootScrollerNonScrollableAlreadyHandled, // Non-root-scroller, non-scrollable document, already handled. |
| + NonRootScrollerNonScrollableNotHandled, // Non-root-scroller, non-scrollable document, not handled. |
| + NonRootScrollerNonScrollableHandled, // Non-root-scroller, non-scrollable document, handled application. |
| + NonRootScrollerScrollableDocumentAlreadyHandled, // Non-root-scroller, scrollable document, already handled. |
| + NonRootScrollerScrollableDocumentNotHandled, // Non-root-scroller, scrollable document, not handled. |
| + NonRootScrollerScrollableDocumentHandled, // Non-root-scroller, scrollable document, handled application. |
| + RootScrollerNonScrollableAlreadyHandled, // Root-scroller, non-scrollable document, already handled. |
| + RootScrollerNonScrollableNotHandled, // Root-scroller, non-scrollable document, not handled. |
| + RootScrollerNonScrollableHandled, // Root-scroller, non-scrollable document, handled. |
| + RootScrollerScrollableDocumentAlreadyHandled, // Root-scroller, scrollable document, already handled. |
| + RootScrollerScrollableDocumentNotHandled, // Root-scroller, scrollable document, not handled. |
| + RootScrollerScrollableDocumentHandled, // Root-scroller, scrollable document, handled. |
| + |
| + // The following enums represent state captured during the BUBBLING_PHASE. |
| + BubblingNonRootScrollerNonScrollableAlreadyHandled, // Non-root-scroller, non-scrollable document, already handled. |
| + BubblingNonRootScrollerNonScrollableNotHandled, // Non-root-scroller, non-scrollable document, not handled. |
| + BubblingNonRootScrollerNonScrollableHandled, // Non-root-scroller, non-scrollable document, handled application. |
| + BubblingNonRootScrollerScrollableDocumentAlreadyHandled, // Non-root-scroller, scrollable document, already handled. |
| + BubblingNonRootScrollerScrollableDocumentNotHandled, // Non-root-scroller, scrollable document, not handled. |
| + BubblingNonRootScrollerScrollableDocumentHandled, // Non-root-scroller, scrollable document, handled application. |
| + BubblingRootScrollerNonScrollableAlreadyHandled, // Root-scroller, non-scrollable document, already handled. |
| + BubblingRootScrollerNonScrollableNotHandled, // Root-scroller, non-scrollable document, not handled. |
| + BubblingRootScrollerNonScrollableHandled, // Root-scroller, non-scrollable document, handled. |
| + BubblingRootScrollerScrollableDocumentAlreadyHandled, // Root-scroller, scrollable document, already handled. |
| + BubblingRootScrollerScrollableDocumentNotHandled, // Root-scroller, scrollable document, not handled. |
| + BubblingRootScrollerScrollableDocumentHandled, // Root-scroller, scrollable document, handled. |
| + TouchTargetAndDispatchResultTypeMax, |
| +}; |
| + |
| +void logTouchTargetHistogram(EventTarget* eventTarget, unsigned short phase, bool defaultPreventedBeforeCurrentTarget, bool defaultPrevented) |
| +{ |
| + int result = 0; |
| + Document* document = nullptr; |
| + |
| + switch (phase) { |
| + default: |
| + case Event::NONE: |
| + return; |
| + case Event::CAPTURING_PHASE: |
| + result += kCapturingOffset; |
| + break; |
| + case Event::AT_TARGET: |
| + result += kAtTargetOffset; |
| + break; |
| + case Event::BUBBLING_PHASE: |
| + result += kBubblingOffset; |
| + break; |
| + } |
| + |
| + if (const LocalDOMWindow* domWindow = eventTarget->toLocalDOMWindow()) { |
| + // Treat the window as a root scroller as well. |
| + document = domWindow->document(); |
| + result += kTouchTargetHistogramRootScrollerOffset; |
| + } else if (Node* node = eventTarget->toNode()) { |
| + // Report if the target node is the document or body. |
| + if (node->isDocumentNode() || node->document().documentElement() == node || node->document().body() == node) { |
| + result += kTouchTargetHistogramRootScrollerOffset; |
| + } |
| + document = &node->document(); |
| + } |
| + |
| + if (document) { |
| + FrameView* view = document->view(); |
| + if (view && view->isScrollable()) |
| + result += kTouchTargetHistogramScrollableDocumentOffset; |
| + } |
| + |
| + if (defaultPreventedBeforeCurrentTarget) |
| + result += kTouchTargetHistogramAlreadyHandledOffset; |
| + else if (defaultPrevented) |
| + result += kTouchTargetHistogramHandledOffset; |
| + else |
| + result += kTouchTargetHistogramNotHandledOffset; |
| + |
| + DEFINE_STATIC_LOCAL(EnumerationHistogram, rootDocumentListenerHistogram, ("Event.Touch.TargetAndDispatchResult2", TouchTargetAndDispatchResultTypeMax)); |
| + rootDocumentListenerHistogram.count(static_cast<TouchTargetAndDispatchResultType>(result)); |
| +} |
| + |
| +} // namespace |
| + |
| TouchEvent::TouchEvent() |
| + : m_causesScrollingIfUncanceled(false) |
| + , m_firstTouchMoveOrStart(false) |
| + , m_defaultPreventedBeforeCurrentTarget(false) |
| { |
| } |
| TouchEvent::TouchEvent(TouchList* touches, TouchList* targetTouches, |
| TouchList* changedTouches, const AtomicString& type, |
| AbstractView* view, |
| - PlatformEvent::Modifiers modifiers, bool cancelable, bool causesScrollingIfUncanceled, |
| + PlatformEvent::Modifiers modifiers, bool cancelable, bool causesScrollingIfUncanceled, bool firstTouchMoveOrStart, |
| double platformTimeStamp) |
| // Pass a sourceCapabilities including the ability to fire touchevents when creating this touchevent, which is always created from input device capabilities from EventHandler. |
| : UIEventWithKeyState(type, true, cancelable, view, 0, modifiers, platformTimeStamp, InputDeviceCapabilities::firesTouchEventsSourceCapabilities()), |
| - m_touches(touches), m_targetTouches(targetTouches), m_changedTouches(changedTouches), m_causesScrollingIfUncanceled(causesScrollingIfUncanceled) |
| + m_touches(touches), |
| + m_targetTouches(targetTouches), |
| + m_changedTouches(changedTouches), |
| + m_causesScrollingIfUncanceled(causesScrollingIfUncanceled), |
| + m_firstTouchMoveOrStart(firstTouchMoveOrStart), |
| + m_defaultPreventedBeforeCurrentTarget(false) |
| { |
| } |
| @@ -55,6 +177,9 @@ TouchEvent::TouchEvent(const AtomicString& type, const TouchEventInit& initializ |
| , m_touches(TouchList::create(initializer.touches())) |
| , m_targetTouches(TouchList::create(initializer.targetTouches())) |
| , m_changedTouches(TouchList::create(initializer.changedTouches())) |
| + , m_causesScrollingIfUncanceled(false) |
| + , m_firstTouchMoveOrStart(false) |
| + , m_defaultPreventedBeforeCurrentTarget(false) |
| { |
| } |
| @@ -109,6 +234,18 @@ void TouchEvent::preventDefault() |
| } |
| } |
| +void TouchEvent::doneDispatchingEventAtCurrentTarget() |
| +{ |
| + // Do not log for non-cancelable events, events that don't block |
| + // scrolling, have more than one touch point or aren't on the main frame. |
|
Rick Byers
2016/05/19 16:30:51
this all makes sense to me except the "aren't on t
dtapuska
2016/05/19 18:14:23
Yes I've updated the histogram description.
|
| + if (!cancelable() || !m_firstTouchMoveOrStart || !(m_touches && m_touches->length() == 1) || !(view() && view()->frame() && view()->frame()->isMainFrame())) |
| + return; |
| + |
| + bool canceled = defaultPrevented(); |
| + logTouchTargetHistogram(currentTarget(), eventPhase(), m_defaultPreventedBeforeCurrentTarget, canceled); |
| + m_defaultPreventedBeforeCurrentTarget = canceled; |
| +} |
| + |
| EventDispatchMediator* TouchEvent::createMediator() |
| { |
| return TouchEventDispatchMediator::create(this); |