Chromium Code Reviews| Index: third_party/WebKit/Source/core/events/EventTarget.cpp |
| diff --git a/third_party/WebKit/Source/core/events/EventTarget.cpp b/third_party/WebKit/Source/core/events/EventTarget.cpp |
| index 9343640919d92e56a123d487d2708f822532bacc..7bb410acef51a779ff86236af07f7fff661506fb 100644 |
| --- a/third_party/WebKit/Source/core/events/EventTarget.cpp |
| +++ b/third_party/WebKit/Source/core/events/EventTarget.cpp |
| @@ -38,6 +38,7 @@ |
| #include "core/events/Event.h" |
| #include "core/inspector/InspectorInstrumentation.h" |
| #include "core/frame/LocalDOMWindow.h" |
| +#include "core/frame/Settings.h" |
| #include "core/frame/UseCounter.h" |
| #include "platform/EventDispatchForbiddenScope.h" |
| #include "wtf/StdLibExtras.h" |
| @@ -49,21 +50,14 @@ using namespace WTF; |
| namespace blink { |
| namespace { |
| -void setDefaultEventListenerOptionsLegacy(EventListenerOptions& options, bool useCapture) |
| +Settings* windowSettings(LocalDOMWindow* executingWindow) |
| { |
| - options.setCapture(useCapture); |
| -} |
| - |
| -void setDefaultAddEventListenerOptionsLegacy(AddEventListenerOptions& options, bool useCapture) |
| -{ |
| - setDefaultEventListenerOptionsLegacy(options, useCapture); |
| - options.setPassive(false); |
| -} |
| - |
| -void setDefaultAddEventListenerOptions(AddEventListenerOptions& options) |
| -{ |
| - if (!options.hasPassive()) |
| - options.setPassive(false); |
| + if (executingWindow) { |
| + if (LocalFrame* frame = executingWindow->frame()) { |
| + return frame->settings(); |
| + } |
| + } |
| + return nullptr; |
| } |
| } // namespace |
| @@ -121,10 +115,41 @@ inline LocalDOMWindow* EventTarget::executingWindow() |
| return nullptr; |
| } |
| +void EventTarget::setDefaultAddEventListenerOptions(AddEventListenerOptions& options) |
| +{ |
| + if (Settings* settings = windowSettings(executingWindow())) { |
| + switch (settings->passiveListenerDefault()) { |
| + case PassiveListenerDefault::False: |
| + if (!options.hasPassive()) |
| + options.setPassive(false); |
| + break; |
| + case PassiveListenerDefault::True: |
| + if (!options.hasPassive()) |
| + options.setPassive(true); |
| + break; |
| + case PassiveListenerDefault::ForceAllTrue: |
| + options.setPassive(true); |
| + break; |
| + case PassiveListenerDefault::DocumentTrue: |
| + if (!options.hasPassive()) { |
| + if (Node* node = toNode()) { |
| + if (node->isDocumentNode() || static_cast<Node*>(node->document().documentElement()) == node || static_cast<Node*>(node->document().body()) == node) { |
|
Rick Byers
2016/05/09 21:48:48
the static_casts aren't actually necessary here, a
dtapuska
2016/05/11 20:01:10
I've tried it; I do recall one build bot complaini
|
| + options.setPassive(true); |
| + } |
| + } else if (toLocalDOMWindow()) { |
| + options.setPassive(true); |
| + } |
| + } |
| + break; |
| + } |
| + } |
| +} |
| + |
| bool EventTarget::addEventListener(const AtomicString& eventType, EventListener* listener, bool useCapture) |
| { |
| AddEventListenerOptions options; |
| - setDefaultAddEventListenerOptionsLegacy(options, useCapture); |
| + options.setCapture(useCapture); |
| + setDefaultAddEventListenerOptions(options); |
| return addEventListenerInternal(eventType, listener, options); |
| } |
| @@ -172,7 +197,7 @@ void EventTarget::addedEventListener(const AtomicString& eventType, RegisteredEv |
| bool EventTarget::removeEventListener(const AtomicString& eventType, const EventListener* listener, bool useCapture) |
| { |
| EventListenerOptions options; |
| - setDefaultEventListenerOptionsLegacy(options, useCapture); |
| + options.setCapture(useCapture); |
| return removeEventListenerInternal(eventType, listener, options); |
| } |