| 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 #include "wtf/Vector.h" | 45 #include "wtf/Vector.h" |
| 46 | 46 |
| 47 using namespace WTF; | 47 using namespace WTF; |
| 48 | 48 |
| 49 namespace blink { | 49 namespace blink { |
| 50 namespace { | 50 namespace { |
| 51 | 51 |
| 52 void setDefaultEventListenerOptionsLegacy(EventListenerOptions& options, bool us
eCapture) | 52 void setDefaultEventListenerOptionsLegacy(EventListenerOptions& options, bool us
eCapture) |
| 53 { | 53 { |
| 54 options.setCapture(useCapture); | 54 options.setCapture(useCapture); |
| 55 } |
| 56 |
| 57 void setDefaultAddEventListenerOptionsLegacy(AddEventListenerOptions& options, b
ool useCapture) |
| 58 { |
| 59 setDefaultEventListenerOptionsLegacy(options, useCapture); |
| 55 options.setPassive(false); | 60 options.setPassive(false); |
| 56 } | 61 } |
| 57 | 62 |
| 58 void setDefaultEventListenerOptions(EventListenerOptions& options) | 63 void setDefaultEventListenerOptions(EventListenerOptions& options) |
| 59 { | 64 { |
| 60 // The default for capture is based on whether the eventListenerOptions | 65 // The default for capture is based on whether the eventListenerOptions |
| 61 // runtime setting is enabled. That is | 66 // runtime setting is enabled. That is |
| 62 // addEventListener('type', function(e) {}, {}); | 67 // addEventListener('type', function(e) {}, {}); |
| 63 // behaves differently under the setting. With the setting off | 68 // behaves differently under the setting. With the setting off |
| 64 // capture is true; with the setting on capture is false. | 69 // capture is true; with the setting on capture is false. |
| 65 if (!options.hasCapture()) | 70 if (!options.hasCapture()) |
| 66 options.setCapture(!RuntimeEnabledFeatures::eventListenerOptionsEnabled(
)); | 71 options.setCapture(!RuntimeEnabledFeatures::eventListenerOptionsEnabled(
)); |
| 72 } |
| 73 |
| 74 void setDefaultAddEventListenerOptions(AddEventListenerOptions& options) |
| 75 { |
| 76 setDefaultEventListenerOptions(options); |
| 67 if (!options.hasPassive()) | 77 if (!options.hasPassive()) |
| 68 options.setPassive(false); | 78 options.setPassive(false); |
| 69 } | 79 } |
| 70 | 80 |
| 71 } // namespace | 81 } // namespace |
| 72 | 82 |
| 73 EventTargetData::EventTargetData() | 83 EventTargetData::EventTargetData() |
| 74 { | 84 { |
| 75 } | 85 } |
| 76 | 86 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 | 128 |
| 119 inline LocalDOMWindow* EventTarget::executingWindow() | 129 inline LocalDOMWindow* EventTarget::executingWindow() |
| 120 { | 130 { |
| 121 if (ExecutionContext* context = getExecutionContext()) | 131 if (ExecutionContext* context = getExecutionContext()) |
| 122 return context->executingWindow(); | 132 return context->executingWindow(); |
| 123 return nullptr; | 133 return nullptr; |
| 124 } | 134 } |
| 125 | 135 |
| 126 bool EventTarget::addEventListener(const AtomicString& eventType, EventListener*
listener, bool useCapture) | 136 bool EventTarget::addEventListener(const AtomicString& eventType, EventListener*
listener, bool useCapture) |
| 127 { | 137 { |
| 128 EventListenerOptions options; | 138 AddEventListenerOptions options; |
| 129 setDefaultEventListenerOptionsLegacy(options, useCapture); | 139 setDefaultAddEventListenerOptionsLegacy(options, useCapture); |
| 130 return addEventListenerInternal(eventType, listener, options); | 140 return addEventListenerInternal(eventType, listener, options); |
| 131 } | 141 } |
| 132 | 142 |
| 133 bool EventTarget::addEventListener(const AtomicString& eventType, EventListener*
listener, const EventListenerOptionsOrBoolean& optionsUnion) | 143 bool EventTarget::addEventListener(const AtomicString& eventType, EventListener*
listener, const AddEventListenerOptionsOrBoolean& optionsUnion) |
| 134 { | 144 { |
| 135 if (optionsUnion.isBoolean()) | 145 if (optionsUnion.isBoolean()) |
| 136 return addEventListener(eventType, listener, optionsUnion.getAsBoolean()
); | 146 return addEventListener(eventType, listener, optionsUnion.getAsBoolean()
); |
| 137 if (optionsUnion.isEventListenerOptions()) { | 147 if (optionsUnion.isAddEventListenerOptions()) { |
| 138 EventListenerOptions options = optionsUnion.getAsEventListenerOptions(); | 148 AddEventListenerOptions options = optionsUnion.getAsAddEventListenerOpti
ons(); |
| 139 return addEventListener(eventType, listener, options); | 149 return addEventListener(eventType, listener, options); |
| 140 } | 150 } |
| 141 return addEventListener(eventType, listener); | 151 return addEventListener(eventType, listener); |
| 142 } | 152 } |
| 143 | 153 |
| 144 bool EventTarget::addEventListener(const AtomicString& eventType, EventListener*
listener, EventListenerOptions& options) | 154 bool EventTarget::addEventListener(const AtomicString& eventType, EventListener*
listener, AddEventListenerOptions& options) |
| 145 { | 155 { |
| 146 setDefaultEventListenerOptions(options); | 156 setDefaultAddEventListenerOptions(options); |
| 147 return addEventListenerInternal(eventType, listener, options); | 157 return addEventListenerInternal(eventType, listener, options); |
| 148 } | 158 } |
| 149 | 159 |
| 150 bool EventTarget::addEventListenerInternal(const AtomicString& eventType, EventL
istener* listener, const EventListenerOptions& options) | 160 bool EventTarget::addEventListenerInternal(const AtomicString& eventType, EventL
istener* listener, const AddEventListenerOptions& options) |
| 151 { | 161 { |
| 152 if (!listener) | 162 if (!listener) |
| 153 return false; | 163 return false; |
| 154 | 164 |
| 155 V8DOMActivityLogger* activityLogger = V8DOMActivityLogger::currentActivityLo
ggerIfIsolatedWorld(); | 165 V8DOMActivityLogger* activityLogger = V8DOMActivityLogger::currentActivityLo
ggerIfIsolatedWorld(); |
| 156 if (activityLogger) { | 166 if (activityLogger) { |
| 157 Vector<String> argv; | 167 Vector<String> argv; |
| 158 argv.append(toNode() ? toNode()->nodeName() : interfaceName()); | 168 argv.append(toNode() ? toNode()->nodeName() : interfaceName()); |
| 159 argv.append(eventType); | 169 argv.append(eventType); |
| 160 activityLogger->logEvent("blinkAddEventListener", argv.size(), argv.data
()); | 170 activityLogger->logEvent("blinkAddEventListener", argv.size(), argv.data
()); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 190 bool EventTarget::removeEventListenerInternal(const AtomicString& eventType, Eve
ntListener* listener, const EventListenerOptions& options) | 200 bool EventTarget::removeEventListenerInternal(const AtomicString& eventType, Eve
ntListener* listener, const EventListenerOptions& options) |
| 191 { | 201 { |
| 192 if (!listener) | 202 if (!listener) |
| 193 return false; | 203 return false; |
| 194 | 204 |
| 195 EventTargetData* d = eventTargetData(); | 205 EventTargetData* d = eventTargetData(); |
| 196 if (!d) | 206 if (!d) |
| 197 return false; | 207 return false; |
| 198 | 208 |
| 199 size_t indexOfRemovedListener; | 209 size_t indexOfRemovedListener; |
| 210 RegisteredEventListener registeredListener; |
| 200 | 211 |
| 201 if (!d->eventListenerMap.remove(eventType, listener, options, indexOfRemoved
Listener)) | 212 if (!d->eventListenerMap.remove(eventType, listener, options, indexOfRemoved
Listener, ®isteredListener)) |
| 202 return false; | 213 return false; |
| 203 | 214 |
| 204 // Notify firing events planning to invoke the listener at 'index' that | 215 // Notify firing events planning to invoke the listener at 'index' that |
| 205 // they have one less listener to invoke. | 216 // they have one less listener to invoke. |
| 206 if (!d->firingEventIterators) | 217 if (d->firingEventIterators) { |
| 207 return true; | 218 for (size_t i = 0; i < d->firingEventIterators->size(); ++i) { |
| 208 for (size_t i = 0; i < d->firingEventIterators->size(); ++i) { | 219 FiringEventIterator& firingIterator = d->firingEventIterators->at(i)
; |
| 209 FiringEventIterator& firingIterator = d->firingEventIterators->at(i); | 220 if (eventType != firingIterator.eventType) |
| 210 if (eventType != firingIterator.eventType) | 221 continue; |
| 211 continue; | |
| 212 | 222 |
| 213 if (indexOfRemovedListener >= firingIterator.end) | 223 if (indexOfRemovedListener >= firingIterator.end) |
| 214 continue; | 224 continue; |
| 215 | 225 |
| 216 --firingIterator.end; | 226 --firingIterator.end; |
| 217 // Note that when firing an event listener, | 227 // Note that when firing an event listener, |
| 218 // firingIterator.iterator indicates the next event listener | 228 // firingIterator.iterator indicates the next event listener |
| 219 // that would fire, not the currently firing event | 229 // that would fire, not the currently firing event |
| 220 // listener. See EventTarget::fireEventListeners. | 230 // listener. See EventTarget::fireEventListeners. |
| 221 if (indexOfRemovedListener < firingIterator.iterator) | 231 if (indexOfRemovedListener < firingIterator.iterator) |
| 222 --firingIterator.iterator; | 232 --firingIterator.iterator; |
| 233 } |
| 223 } | 234 } |
| 235 removedEventListener(eventType, registeredListener); |
| 236 return true; |
| 237 } |
| 224 | 238 |
| 225 return true; | 239 void EventTarget::removedEventListener(const AtomicString& eventType, const Regi
steredEventListener& registeredListener) |
| 240 { |
| 226 } | 241 } |
| 227 | 242 |
| 228 bool EventTarget::setAttributeEventListener(const AtomicString& eventType, Event
Listener* listener) | 243 bool EventTarget::setAttributeEventListener(const AtomicString& eventType, Event
Listener* listener) |
| 229 { | 244 { |
| 230 clearAttributeEventListener(eventType); | 245 clearAttributeEventListener(eventType); |
| 231 if (!listener) | 246 if (!listener) |
| 232 return false; | 247 return false; |
| 233 return addEventListener(eventType, listener, false); | 248 return addEventListener(eventType, listener, false); |
| 234 } | 249 } |
| 235 | 250 |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 490 // they have one less listener to invoke. | 505 // they have one less listener to invoke. |
| 491 if (d->firingEventIterators) { | 506 if (d->firingEventIterators) { |
| 492 for (size_t i = 0; i < d->firingEventIterators->size(); ++i) { | 507 for (size_t i = 0; i < d->firingEventIterators->size(); ++i) { |
| 493 d->firingEventIterators->at(i).iterator = 0; | 508 d->firingEventIterators->at(i).iterator = 0; |
| 494 d->firingEventIterators->at(i).end = 0; | 509 d->firingEventIterators->at(i).end = 0; |
| 495 } | 510 } |
| 496 } | 511 } |
| 497 } | 512 } |
| 498 | 513 |
| 499 } // namespace blink | 514 } // namespace blink |
| OLD | NEW |