Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2008, The Android Open Source Project | 2 * Copyright 2008, The Android Open Source Project |
| 3 * Copyright (C) 2012 Research In Motion Limited. All rights reserved. | 3 * Copyright (C) 2012 Research In Motion Limited. All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above copyright | 10 * * Redistributions in binary form must reproduce the above copyright |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 25 */ | 25 */ |
| 26 | 26 |
| 27 #include "core/events/TouchEvent.h" | 27 #include "core/events/TouchEvent.h" |
| 28 | 28 |
| 29 #include "bindings/core/v8/DOMWrapperWorld.h" | 29 #include "bindings/core/v8/DOMWrapperWorld.h" |
| 30 #include "bindings/core/v8/ScriptState.h" | 30 #include "bindings/core/v8/ScriptState.h" |
| 31 #include "core/events/EventDispatcher.h" | 31 #include "core/events/EventDispatcher.h" |
| 32 #include "core/frame/FrameConsole.h" | 32 #include "core/frame/FrameConsole.h" |
| 33 #include "core/frame/FrameView.h" | |
| 33 #include "core/frame/LocalDOMWindow.h" | 34 #include "core/frame/LocalDOMWindow.h" |
| 34 #include "core/inspector/ConsoleMessage.h" | 35 #include "core/inspector/ConsoleMessage.h" |
| 36 #include "platform/Histogram.h" | |
| 35 | 37 |
| 36 namespace blink { | 38 namespace blink { |
| 37 | 39 |
| 40 namespace { | |
| 41 | |
| 42 // These offsets change indicies into the ListenerHistogram | |
| 43 // enumeration. The addition of a series of offsets then | |
| 44 // produces the resulting ListenerHistogram value. | |
| 45 const size_t kTouchTargetHistogramRootScrollerOffset = 6; | |
| 46 const size_t kTouchTargetHistogramScrollableDocumentOffset = 3; | |
| 47 const size_t kTouchTargetHistogramAlreadyHandledOffset = 0; | |
| 48 const size_t kTouchTargetHistogramNotHandledOffset = 1; | |
| 49 const size_t kTouchTargetHistogramHandledOffset = 2; | |
| 50 const size_t kCapturingOffset = 0; | |
| 51 const size_t kAtTargetOffset = 12; | |
| 52 const size_t kBubblingOffset = 24; | |
| 53 | |
| 54 enum TouchTargetAndDispatchResultType { | |
| 55 CapturingNonRootScrollerNonScrollableAlreadyHandled, // Non-root-scroller, n on-scrollable document, already handled. | |
| 56 CapturingNonRootScrollerNonScrollableNotHandled, // Non-root-scroller, non-s crollable document, not handled. | |
| 57 CapturingNonRootScrollerNonScrollableHandled, // Non-root-scroller, non-scro llable document, handled application. | |
| 58 CapturingNonRootScrollerScrollableDocumentAlreadyHandled, // Non-root-scroll er, scrollable document, already handled. | |
| 59 CapturingNonRootScrollerScrollableDocumentNotHandled, // Non-root-scroller, scrollable document, not handled. | |
| 60 CapturingNonRootScrollerScrollableDocumentHandled, // Non-root-scroller, scr ollable document, handled application. | |
| 61 CapturingRootScrollerNonScrollableAlreadyHandled, // Root-scroller, non-scro llable document, already handled. | |
| 62 CapturingRootScrollerNonScrollableNotHandled, // Root-scroller, non-scrollab le document, not handled. | |
| 63 CapturingRootScrollerNonScrollableHandled, // Root-scroller, non-scrollable document, handled. | |
| 64 CapturingRootScrollerScrollableDocumentAlreadyHandled, // Root-scroller, scr ollable document, already handled. | |
| 65 CapturingRootScrollerScrollableDocumentNotHandled, // Root-scroller, scrolla ble document, not handled. | |
| 66 CapturingRootScrollerScrollableDocumentHandled, // Root-scroller, scrollable document, handled. | |
| 67 | |
| 68 NonRootScrollerNonScrollableAlreadyHandled, // Non-root-scroller, non-scroll able document, already handled. | |
| 69 NonRootScrollerNonScrollableNotHandled, // Non-root-scroller, non-scrollable document, not handled. | |
| 70 NonRootScrollerNonScrollableHandled, // Non-root-scroller, non-scrollable do cument, handled application. | |
| 71 NonRootScrollerScrollableDocumentAlreadyHandled, // Non-root-scroller, scrol lable document, already handled. | |
| 72 NonRootScrollerScrollableDocumentNotHandled, // Non-root-scroller, scrollabl e document, not handled. | |
| 73 NonRootScrollerScrollableDocumentHandled, // Non-root-scroller, scrollable d ocument, handled application. | |
| 74 RootScrollerNonScrollableAlreadyHandled, // Root-scroller, non-scrollable do cument, already handled. | |
| 75 RootScrollerNonScrollableNotHandled, // Root-scroller, non-scrollable docume nt, not handled. | |
| 76 RootScrollerNonScrollableHandled, // Root-scroller, non-scrollable document, handled. | |
| 77 RootScrollerScrollableDocumentAlreadyHandled, // Root-scroller, scrollable d ocument, already handled. | |
| 78 RootScrollerScrollableDocumentNotHandled, // Root-scroller, scrollable docum ent, not handled. | |
| 79 RootScrollerScrollableDocumentHandled, // Root-scroller, scrollable document , handled. | |
| 80 | |
| 81 BubblingNonRootScrollerNonScrollableAlreadyHandled, // Non-root-scroller, no n-scrollable document, already handled. | |
| 82 BubblingNonRootScrollerNonScrollableNotHandled, // Non-root-scroller, non-sc rollable document, not handled. | |
| 83 BubblingNonRootScrollerNonScrollableHandled, // Non-root-scroller, non-scrol lable document, handled application. | |
| 84 BubblingNonRootScrollerScrollableDocumentAlreadyHandled, // Non-root-scrolle r, scrollable document, already handled. | |
| 85 BubblingNonRootScrollerScrollableDocumentNotHandled, // Non-root-scroller, s crollable document, not handled. | |
| 86 BubblingNonRootScrollerScrollableDocumentHandled, // Non-root-scroller, scro llable document, handled application. | |
| 87 BubblingRootScrollerNonScrollableAlreadyHandled, // Root-scroller, non-scrol lable document, already handled. | |
| 88 BubblingRootScrollerNonScrollableNotHandled, // Root-scroller, non-scrollabl e document, not handled. | |
| 89 BubblingRootScrollerNonScrollableHandled, // Root-scroller, non-scrollable d ocument, handled. | |
| 90 BubblingRootScrollerScrollableDocumentAlreadyHandled, // Root-scroller, scro llable document, already handled. | |
| 91 BubblingRootScrollerScrollableDocumentNotHandled, // Root-scroller, scrollab le document, not handled. | |
| 92 BubblingRootScrollerScrollableDocumentHandled, // Root-scroller, scrollable document, handled. | |
| 93 TouchTargetAndDispatchResultTypeMax, | |
| 94 }; | |
| 95 | |
| 96 void logTouchTargetHistogram(EventTarget* eventTarget, unsigned short phase, boo l wasCanceled, bool isCanceled) | |
|
tdresser
2016/05/17 14:56:54
wasCancelled could use a bit more detail.
wasCan
dtapuska
2016/05/17 20:50:13
Done.
| |
| 97 { | |
| 98 int result = 0; | |
| 99 Document* document = nullptr; | |
| 100 | |
| 101 switch (phase) { | |
| 102 default: | |
| 103 case Event::NONE: | |
| 104 return; | |
| 105 case Event::CAPTURING_PHASE: | |
| 106 result += kCapturingOffset; | |
| 107 break; | |
| 108 case Event::AT_TARGET: | |
| 109 result += kAtTargetOffset; | |
| 110 break; | |
| 111 case Event::BUBBLING_PHASE: | |
| 112 result += kBubblingOffset; | |
| 113 break; | |
| 114 } | |
| 115 | |
| 116 if (const LocalDOMWindow* domWindow = eventTarget->toLocalDOMWindow()) { | |
| 117 // Treat the window as a root scroller as well. | |
| 118 document = domWindow->document(); | |
| 119 result += kTouchTargetHistogramRootScrollerOffset; | |
| 120 } else if (Node* node = eventTarget->toNode()) { | |
| 121 // Report if the target node is the document or body. | |
| 122 if (node->isDocumentNode() || node->document().documentElement() == node || node->document().body() == node) { | |
| 123 result += kTouchTargetHistogramRootScrollerOffset; | |
| 124 } | |
| 125 document = &node->document(); | |
| 126 } | |
| 127 | |
| 128 if (document) { | |
| 129 FrameView* view = document->view(); | |
| 130 if (view && view->isScrollable()) | |
| 131 result += kTouchTargetHistogramScrollableDocumentOffset; | |
| 132 } | |
| 133 | |
| 134 if (wasCanceled) | |
| 135 result += kTouchTargetHistogramAlreadyHandledOffset; | |
| 136 else if (isCanceled) | |
| 137 result += kTouchTargetHistogramHandledOffset; | |
| 138 else | |
| 139 result += kTouchTargetHistogramNotHandledOffset; | |
| 140 | |
| 141 DEFINE_STATIC_LOCAL(EnumerationHistogram, rootDocumentListenerHistogram, ("E vent.Touch.TargetAndDispatchResult2", TouchTargetAndDispatchResultTypeMax)); | |
| 142 rootDocumentListenerHistogram.count(static_cast<TouchTargetAndDispatchResult Type>(result)); | |
| 143 } | |
| 144 | |
| 145 } // namespace | |
| 146 | |
| 38 TouchEvent::TouchEvent() | 147 TouchEvent::TouchEvent() |
| 39 { | 148 { |
| 40 } | 149 } |
| 41 | 150 |
| 42 TouchEvent::TouchEvent(TouchList* touches, TouchList* targetTouches, | 151 TouchEvent::TouchEvent(TouchList* touches, TouchList* targetTouches, |
| 43 TouchList* changedTouches, const AtomicString& type, | 152 TouchList* changedTouches, const AtomicString& type, |
| 44 AbstractView* view, | 153 AbstractView* view, |
| 45 PlatformEvent::Modifiers modifiers, bool cancelable, bool causesScrollingIfU ncanceled, | 154 PlatformEvent::Modifiers modifiers, bool cancelable, bool causesScrollingIfU ncanceled, |
| 46 double platformTimeStamp) | 155 double platformTimeStamp) |
| 47 // Pass a sourceCapabilities including the ability to fire touchevents when creating this touchevent, which is always created from input device capabilities from EventHandler. | 156 // Pass a sourceCapabilities including the ability to fire touchevents when creating this touchevent, which is always created from input device capabilities from EventHandler. |
| 48 : UIEventWithKeyState(type, true, cancelable, view, 0, modifiers, platformTi meStamp, InputDeviceCapabilities::firesTouchEventsSourceCapabilities()), | 157 : UIEventWithKeyState(type, true, cancelable, view, 0, modifiers, platformTi meStamp, InputDeviceCapabilities::firesTouchEventsSourceCapabilities()), |
| 49 m_touches(touches), m_targetTouches(targetTouches), m_changedTouches(changed Touches), m_causesScrollingIfUncanceled(causesScrollingIfUncanceled) | 158 m_touches(touches), |
| 159 m_targetTouches(targetTouches), | |
| 160 m_changedTouches(changedTouches), | |
| 161 m_causesScrollingIfUncanceled(causesScrollingIfUncanceled), | |
| 162 m_previousDefaultPrevented(false) | |
| 50 { | 163 { |
| 51 } | 164 } |
| 52 | 165 |
| 53 TouchEvent::TouchEvent(const AtomicString& type, const TouchEventInit& initializ er) | 166 TouchEvent::TouchEvent(const AtomicString& type, const TouchEventInit& initializ er) |
| 54 : UIEventWithKeyState(type, initializer) | 167 : UIEventWithKeyState(type, initializer) |
| 55 , m_touches(TouchList::create(initializer.touches())) | 168 , m_touches(TouchList::create(initializer.touches())) |
| 56 , m_targetTouches(TouchList::create(initializer.targetTouches())) | 169 , m_targetTouches(TouchList::create(initializer.targetTouches())) |
| 57 , m_changedTouches(TouchList::create(initializer.changedTouches())) | 170 , m_changedTouches(TouchList::create(initializer.changedTouches())) |
| 58 { | 171 { |
| 59 } | 172 } |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 102 | 215 |
| 103 // A common developer error is to wait too long before attempting to stop | 216 // A common developer error is to wait too long before attempting to stop |
| 104 // scrolling by consuming a touchmove event. Generate a warning if this | 217 // scrolling by consuming a touchmove event. Generate a warning if this |
| 105 // event is uncancelable. | 218 // event is uncancelable. |
| 106 if (!cancelable() && view() && view()->isLocalDOMWindow() && view()->frame() ) { | 219 if (!cancelable() && view() && view()->isLocalDOMWindow() && view()->frame() ) { |
| 107 toLocalDOMWindow(view())->frame()->console().addMessage(ConsoleMessage:: create(JSMessageSource, WarningMessageLevel, | 220 toLocalDOMWindow(view())->frame()->console().addMessage(ConsoleMessage:: create(JSMessageSource, WarningMessageLevel, |
| 108 "Ignored attempt to cancel a " + type() + " event with cancelable=fa lse, for example because scrolling is in progress and cannot be interrupted.")); | 221 "Ignored attempt to cancel a " + type() + " event with cancelable=fa lse, for example because scrolling is in progress and cannot be interrupted.")); |
| 109 } | 222 } |
| 110 } | 223 } |
| 111 | 224 |
| 225 void TouchEvent::doneDispatchedEventAtCurrentTarget() | |
| 226 { | |
| 227 bool preventDefaulted = defaultPrevented(); | |
| 228 logTouchTargetHistogram(currentTarget(), eventPhase(), m_previousDefaultPrev ented, preventDefaulted); | |
| 229 m_previousDefaultPrevented = preventDefaulted; | |
| 230 } | |
| 231 | |
| 112 EventDispatchMediator* TouchEvent::createMediator() | 232 EventDispatchMediator* TouchEvent::createMediator() |
| 113 { | 233 { |
| 114 return TouchEventDispatchMediator::create(this); | 234 return TouchEventDispatchMediator::create(this); |
| 115 } | 235 } |
| 116 | 236 |
| 117 DEFINE_TRACE(TouchEvent) | 237 DEFINE_TRACE(TouchEvent) |
| 118 { | 238 { |
| 119 visitor->trace(m_touches); | 239 visitor->trace(m_touches); |
| 120 visitor->trace(m_targetTouches); | 240 visitor->trace(m_targetTouches); |
| 121 visitor->trace(m_changedTouches); | 241 visitor->trace(m_changedTouches); |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 137 return toTouchEvent(EventDispatchMediator::event()); | 257 return toTouchEvent(EventDispatchMediator::event()); |
| 138 } | 258 } |
| 139 | 259 |
| 140 DispatchEventResult TouchEventDispatchMediator::dispatchEvent(EventDispatcher& d ispatcher) const | 260 DispatchEventResult TouchEventDispatchMediator::dispatchEvent(EventDispatcher& d ispatcher) const |
| 141 { | 261 { |
| 142 event().eventPath().adjustForTouchEvent(event()); | 262 event().eventPath().adjustForTouchEvent(event()); |
| 143 return dispatcher.dispatch(); | 263 return dispatcher.dispatch(); |
| 144 } | 264 } |
| 145 | 265 |
| 146 } // namespace blink | 266 } // namespace blink |
| OLD | NEW |