OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) | 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) |
4 * (C) 2001 Dirk Mueller (mueller@kde.org) | 4 * (C) 2001 Dirk Mueller (mueller@kde.org) |
5 * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved. | 5 * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved. |
6 * Copyright (C) 2006 Alexey Proskuryakov (ap@webkit.org) | 6 * Copyright (C) 2006 Alexey Proskuryakov (ap@webkit.org) |
7 * (C) 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org> | 7 * (C) 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org> |
8 * | 8 * |
9 * Redistribution and use in source and binary forms, with or without | 9 * Redistribution and use in source and binary forms, with or without |
10 * modification, are permitted provided that the following conditions | 10 * modification, are permitted provided that the following conditions |
(...skipping 28 matching lines...) Expand all Loading... | |
39 #include "core/editing/Editor.h" | 39 #include "core/editing/Editor.h" |
40 #include "core/events/Event.h" | 40 #include "core/events/Event.h" |
41 #include "core/events/EventUtil.h" | 41 #include "core/events/EventUtil.h" |
42 #include "core/frame/FrameHost.h" | 42 #include "core/frame/FrameHost.h" |
43 #include "core/frame/LocalDOMWindow.h" | 43 #include "core/frame/LocalDOMWindow.h" |
44 #include "core/frame/Settings.h" | 44 #include "core/frame/Settings.h" |
45 #include "core/frame/UseCounter.h" | 45 #include "core/frame/UseCounter.h" |
46 #include "core/inspector/ConsoleMessage.h" | 46 #include "core/inspector/ConsoleMessage.h" |
47 #include "core/inspector/InspectorInstrumentation.h" | 47 #include "core/inspector/InspectorInstrumentation.h" |
48 #include "platform/EventDispatchForbiddenScope.h" | 48 #include "platform/EventDispatchForbiddenScope.h" |
49 #include "platform/Histogram.h" | |
49 #include "wtf/PtrUtil.h" | 50 #include "wtf/PtrUtil.h" |
50 #include "wtf/StdLibExtras.h" | 51 #include "wtf/StdLibExtras.h" |
51 #include "wtf/Threading.h" | 52 #include "wtf/Threading.h" |
52 #include "wtf/Vector.h" | 53 #include "wtf/Vector.h" |
53 #include <memory> | 54 #include <memory> |
54 | 55 |
55 using namespace WTF; | 56 using namespace WTF; |
56 | 57 |
57 namespace blink { | 58 namespace blink { |
58 namespace { | 59 namespace { |
59 | 60 |
61 enum PassiveForcedListenerResultType { | |
62 PreventDefaultNotCalled, | |
63 DocumentLevelTouchPreventDefaultCalled, | |
64 PassiveForcedListenerResultTypeMax | |
65 }; | |
66 | |
60 Settings* windowSettings(LocalDOMWindow* executingWindow) | 67 Settings* windowSettings(LocalDOMWindow* executingWindow) |
61 { | 68 { |
62 if (executingWindow) { | 69 if (executingWindow) { |
63 if (LocalFrame* frame = executingWindow->frame()) { | 70 if (LocalFrame* frame = executingWindow->frame()) { |
64 return frame->settings(); | 71 return frame->settings(); |
65 } | 72 } |
66 } | 73 } |
67 return nullptr; | 74 return nullptr; |
68 } | 75 } |
69 | 76 |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
183 return nullptr; | 190 return nullptr; |
184 } | 191 } |
185 | 192 |
186 inline LocalDOMWindow* EventTarget::executingWindow() | 193 inline LocalDOMWindow* EventTarget::executingWindow() |
187 { | 194 { |
188 if (ExecutionContext* context = getExecutionContext()) | 195 if (ExecutionContext* context = getExecutionContext()) |
189 return context->executingWindow(); | 196 return context->executingWindow(); |
190 return nullptr; | 197 return nullptr; |
191 } | 198 } |
192 | 199 |
193 void EventTarget::setDefaultAddEventListenerOptions(const AtomicString& eventTyp e, AddEventListenerOptions& options) | 200 void EventTarget::setDefaultAddEventListenerOptions(const AtomicString& eventTyp e, AddEventListenerOptionsResolved& options) |
194 { | 201 { |
195 if (!isScrollBlockingEvent(eventType)) { | 202 if (!isScrollBlockingEvent(eventType)) { |
196 if (!options.hasPassive()) | 203 if (!options.hasPassive()) |
197 options.setPassive(false); | 204 options.setPassive(false); |
198 return; | 205 return; |
199 } | 206 } |
200 | 207 |
201 if (LocalDOMWindow* executingWindow = this->executingWindow()) { | 208 if (LocalDOMWindow* executingWindow = this->executingWindow()) { |
202 if (options.hasPassive()) { | 209 if (options.hasPassive()) { |
203 UseCounter::count(executingWindow->document(), options.passive() ? U seCounter::AddEventListenerPassiveTrue : UseCounter::AddEventListenerPassiveFals e); | 210 UseCounter::count(executingWindow->document(), options.passive() ? U seCounter::AddEventListenerPassiveTrue : UseCounter::AddEventListenerPassiveFals e); |
204 } | 211 } |
205 } | 212 } |
206 | 213 |
207 if (RuntimeEnabledFeatures::passiveDocumentEventListenersEnabled() && isTouc hScrollBlockingEvent(eventType)) { | 214 if (RuntimeEnabledFeatures::passiveDocumentEventListenersEnabled() && isTouc hScrollBlockingEvent(eventType)) { |
208 if (!options.hasPassive()) { | 215 if (!options.hasPassive()) { |
209 if (Node* node = toNode()) { | 216 if (Node* node = toNode()) { |
210 if (node->isDocumentNode() || node->document().documentElement() == node || node->document().body() == node) { | 217 if (node->isDocumentNode() || node->document().documentElement() == node || node->document().body() == node) { |
211 options.setPassive(true); | 218 options.setPassive(true); |
219 options.setPassiveForcedForDocumentTarget(true); | |
212 return; | 220 return; |
213 } | 221 } |
214 } else if (toLocalDOMWindow()) { | 222 } else if (toLocalDOMWindow()) { |
215 options.setPassive(true); | 223 options.setPassive(true); |
224 options.setPassiveForcedForDocumentTarget(true); | |
216 return; | 225 return; |
217 } | 226 } |
218 } | 227 } |
219 } | 228 } |
220 | 229 |
221 if (Settings* settings = windowSettings(executingWindow())) { | 230 if (Settings* settings = windowSettings(executingWindow())) { |
222 switch (settings->passiveListenerDefault()) { | 231 switch (settings->passiveListenerDefault()) { |
223 case PassiveListenerDefault::False: | 232 case PassiveListenerDefault::False: |
224 if (!options.hasPassive()) | 233 if (!options.hasPassive()) |
225 options.setPassive(false); | 234 options.setPassive(false); |
226 break; | 235 break; |
227 case PassiveListenerDefault::True: | 236 case PassiveListenerDefault::True: |
228 if (!options.hasPassive()) | 237 if (!options.hasPassive()) |
229 options.setPassive(true); | 238 options.setPassive(true); |
230 break; | 239 break; |
231 case PassiveListenerDefault::ForceAllTrue: | 240 case PassiveListenerDefault::ForceAllTrue: |
232 options.setPassive(true); | 241 options.setPassive(true); |
233 break; | 242 break; |
234 } | 243 } |
235 } else { | 244 } else { |
236 if (!options.hasPassive()) | 245 if (!options.hasPassive()) |
237 options.setPassive(false); | 246 options.setPassive(false); |
238 } | 247 } |
239 } | 248 } |
240 | 249 |
241 bool EventTarget::addEventListener(const AtomicString& eventType, EventListener* listener, bool useCapture) | 250 bool EventTarget::addEventListener(const AtomicString& eventType, EventListener* listener, bool useCapture) |
242 { | 251 { |
243 AddEventListenerOptions options; | 252 AddEventListenerOptionsResolved options; |
244 options.setCapture(useCapture); | 253 options.setCapture(useCapture); |
245 setDefaultAddEventListenerOptions(eventType, options); | 254 setDefaultAddEventListenerOptions(eventType, options); |
246 return addEventListenerInternal(eventType, listener, options); | 255 return addEventListenerInternal(eventType, listener, options); |
247 } | 256 } |
248 | 257 |
249 bool EventTarget::addEventListener(const AtomicString& eventType, EventListener* listener, const AddEventListenerOptionsOrBoolean& optionsUnion) | 258 bool EventTarget::addEventListener(const AtomicString& eventType, EventListener* listener, const AddEventListenerOptionsOrBoolean& optionsUnion) |
250 { | 259 { |
251 if (optionsUnion.isBoolean()) | 260 if (optionsUnion.isBoolean()) |
252 return addEventListener(eventType, listener, optionsUnion.getAsBoolean() ); | 261 return addEventListener(eventType, listener, optionsUnion.getAsBoolean() ); |
253 if (optionsUnion.isAddEventListenerOptions()) { | 262 if (optionsUnion.isAddEventListenerOptions()) { |
254 AddEventListenerOptions options = optionsUnion.getAsAddEventListenerOpti ons(); | 263 AddEventListenerOptionsResolved options = optionsUnion.getAsAddEventList enerOptions(); |
255 return addEventListener(eventType, listener, options); | 264 return addEventListener(eventType, listener, options); |
256 } | 265 } |
257 return addEventListener(eventType, listener); | 266 return addEventListener(eventType, listener); |
258 } | 267 } |
259 | 268 |
260 bool EventTarget::addEventListener(const AtomicString& eventType, EventListener* listener, AddEventListenerOptions& options) | 269 bool EventTarget::addEventListener(const AtomicString& eventType, EventListener* listener, AddEventListenerOptionsResolved& options) |
261 { | 270 { |
262 setDefaultAddEventListenerOptions(eventType, options); | 271 setDefaultAddEventListenerOptions(eventType, options); |
263 return addEventListenerInternal(eventType, listener, options); | 272 return addEventListenerInternal(eventType, listener, options); |
264 } | 273 } |
265 | 274 |
266 bool EventTarget::addEventListenerInternal(const AtomicString& eventType, EventL istener* listener, const AddEventListenerOptions& options) | 275 bool EventTarget::addEventListenerInternal(const AtomicString& eventType, EventL istener* listener, const AddEventListenerOptionsResolved& options) |
267 { | 276 { |
268 if (!listener) | 277 if (!listener) |
269 return false; | 278 return false; |
270 | 279 |
271 V8DOMActivityLogger* activityLogger = V8DOMActivityLogger::currentActivityLo ggerIfIsolatedWorld(); | 280 V8DOMActivityLogger* activityLogger = V8DOMActivityLogger::currentActivityLo ggerIfIsolatedWorld(); |
272 if (activityLogger) { | 281 if (activityLogger) { |
273 Vector<String> argv; | 282 Vector<String> argv; |
274 argv.append(toNode() ? toNode()->nodeName() : interfaceName()); | 283 argv.append(toNode() ? toNode()->nodeName() : interfaceName()); |
275 argv.append(eventType); | 284 argv.append(eventType); |
276 activityLogger->logEvent("blinkAddEventListener", argv.size(), argv.data ()); | 285 activityLogger->logEvent("blinkAddEventListener", argv.size(), argv.data ()); |
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
590 continue; | 599 continue; |
591 if (event->eventPhase() == Event::BUBBLING_PHASE && registeredListener.c apture()) | 600 if (event->eventPhase() == Event::BUBBLING_PHASE && registeredListener.c apture()) |
592 continue; | 601 continue; |
593 | 602 |
594 // If stopImmediatePropagation has been called, we just break out immedi ately, without | 603 // If stopImmediatePropagation has been called, we just break out immedi ately, without |
595 // handling any more events on this target. | 604 // handling any more events on this target. |
596 if (event->immediatePropagationStopped()) | 605 if (event->immediatePropagationStopped()) |
597 break; | 606 break; |
598 | 607 |
599 event->setHandlingPassive(registeredListener.passive()); | 608 event->setHandlingPassive(registeredListener.passive()); |
609 bool passiveForced = registeredListener.passiveForcedForDocumentTarget() ; | |
600 | 610 |
601 InspectorInstrumentation::NativeBreakpoint nativeBreakpoint(context, thi s, event); | 611 InspectorInstrumentation::NativeBreakpoint nativeBreakpoint(context, thi s, event); |
602 | 612 |
603 EventListener* listener = registeredListener.listener(); | 613 EventListener* listener = registeredListener.listener(); |
604 | 614 |
605 // To match Mozilla, the AT_TARGET phase fires both capturing and bubbli ng | 615 // To match Mozilla, the AT_TARGET phase fires both capturing and bubbli ng |
606 // event listeners, even though that violates some versions of the DOM s pec. | 616 // event listeners, even though that violates some versions of the DOM s pec. |
607 listener->handleEvent(context, event); | 617 listener->handleEvent(context, event); |
608 firedListener = true; | 618 firedListener = true; |
609 | 619 |
610 // If we're about to report this event listener as blocking, make sure i t wasn't | 620 // If we're about to report this event listener as blocking, make sure i t wasn't |
611 // removed while handling the event. | 621 // removed while handling the event. |
612 if (shouldReportBlockedEvent && i > 0 && entry[i - 1].listener() == list ener | 622 if (shouldReportBlockedEvent && i > 0 && entry[i - 1].listener() == list ener |
613 && !entry[i - 1].passive() && !entry[i - 1].blockedEventWarningEmitt ed() && !event->defaultPrevented()) { | 623 && !entry[i - 1].passive() && !entry[i - 1].blockedEventWarningEmitt ed() && !event->defaultPrevented()) { |
614 reportBlockedEvent(context, event, &entry[i - 1], now - event->platf ormTimeStamp()); | 624 reportBlockedEvent(context, event, &entry[i - 1], now - event->platf ormTimeStamp()); |
615 } | 625 } |
616 | 626 |
627 if (passiveForced) { | |
628 DEFINE_STATIC_LOCAL(EnumerationHistogram, passiveForcedHistogram, (" Event.PassiveForcedEventDispatchBreakage", PassiveForcedListenerResultTypeMax)); | |
tdresser
2016/07/08 17:37:11
How much work would it be to add a histogram test
dtapuska
2016/07/08 19:03:53
Added :-)
| |
629 PassiveForcedListenerResultType breakageType = PreventDefaultNotCall ed; | |
630 if (event->preventDefaultCalledDuringPassive()) | |
631 breakageType = DocumentLevelTouchPreventDefaultCalled; | |
632 | |
633 passiveForcedHistogram.count(breakageType); | |
634 } | |
635 | |
617 event->setHandlingPassive(false); | 636 event->setHandlingPassive(false); |
618 | 637 |
619 RELEASE_ASSERT(i <= size); | 638 RELEASE_ASSERT(i <= size); |
620 } | 639 } |
621 d->firingEventIterators->removeLast(); | 640 d->firingEventIterators->removeLast(); |
622 return firedListener; | 641 return firedListener; |
623 } | 642 } |
624 | 643 |
625 DispatchEventResult EventTarget::dispatchEventResult(const Event& event) | 644 DispatchEventResult EventTarget::dispatchEventResult(const Event& event) |
626 { | 645 { |
(...skipping 29 matching lines...) Expand all Loading... | |
656 // they have one less listener to invoke. | 675 // they have one less listener to invoke. |
657 if (d->firingEventIterators) { | 676 if (d->firingEventIterators) { |
658 for (size_t i = 0; i < d->firingEventIterators->size(); ++i) { | 677 for (size_t i = 0; i < d->firingEventIterators->size(); ++i) { |
659 d->firingEventIterators->at(i).iterator = 0; | 678 d->firingEventIterators->at(i).iterator = 0; |
660 d->firingEventIterators->at(i).end = 0; | 679 d->firingEventIterators->at(i).end = 0; |
661 } | 680 } |
662 } | 681 } |
663 } | 682 } |
664 | 683 |
665 } // namespace blink | 684 } // namespace blink |
OLD | NEW |