summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2022-02-16 22:15:17 +0100
committerAndreas Kling <kling@serenityos.org>2022-02-16 22:21:45 +0100
commit9521f719440d3ecbb5f06dbd86ca646f14bf862b (patch)
treeaee6e32e883c4ad11af2fe6030f76a77c3ce729d /Userland
parente76e8e22b524da92b3404747b975f1c985ceff68 (diff)
downloadserenity-9521f719440d3ecbb5f06dbd86ca646f14bf862b.zip
LibWeb: Support "useCapture" parameter to add/removeEventListener
This is not a complete implementation of API, since we're also supposed to accept an options dictionary as the third argument. However, a lot of web content uses the boolean variant, and it's trivial to support.
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibWeb/DOM/EventTarget.cpp8
-rw-r--r--Userland/Libraries/LibWeb/DOM/EventTarget.h4
-rw-r--r--Userland/Libraries/LibWeb/DOM/EventTarget.idl4
3 files changed, 8 insertions, 8 deletions
diff --git a/Userland/Libraries/LibWeb/DOM/EventTarget.cpp b/Userland/Libraries/LibWeb/DOM/EventTarget.cpp
index 2c14ab95a0..d2debd03db 100644
--- a/Userland/Libraries/LibWeb/DOM/EventTarget.cpp
+++ b/Userland/Libraries/LibWeb/DOM/EventTarget.cpp
@@ -46,10 +46,10 @@ EventTarget::~EventTarget()
}
// https://dom.spec.whatwg.org/#dom-eventtarget-addeventlistener
-void EventTarget::add_event_listener(FlyString const& type, RefPtr<IDLEventListener> callback)
+void EventTarget::add_event_listener(FlyString const& type, RefPtr<IDLEventListener> callback, bool use_capture)
{
// FIXME: 1. Let capture, passive, once, and signal be the result of flattening more options.
- bool capture = false;
+ bool capture = use_capture;
bool passive = false;
bool once = false;
RefPtr<AbortSignal> signal = nullptr;
@@ -96,10 +96,10 @@ void EventTarget::add_an_event_listener(NonnullRefPtr<DOMEventListener> listener
}
// https://dom.spec.whatwg.org/#dom-eventtarget-removeeventlistener
-void EventTarget::remove_event_listener(FlyString const& type, RefPtr<IDLEventListener> callback)
+void EventTarget::remove_event_listener(FlyString const& type, RefPtr<IDLEventListener> callback, bool use_capture)
{
// FIXME: 1. Let capture be the result of flattening options.
- bool capture = false;
+ bool capture = use_capture;
// 2. If thisโ€™s event listener list contains an event listener whose type is type, callback is callback, and capture is capture,
// then remove an event listener with this and that event listener.
diff --git a/Userland/Libraries/LibWeb/DOM/EventTarget.h b/Userland/Libraries/LibWeb/DOM/EventTarget.h
index 59531200ae..db138efa4b 100644
--- a/Userland/Libraries/LibWeb/DOM/EventTarget.h
+++ b/Userland/Libraries/LibWeb/DOM/EventTarget.h
@@ -30,8 +30,8 @@ public:
virtual bool is_focusable() const { return false; }
- void add_event_listener(FlyString const& type, RefPtr<IDLEventListener> callback);
- void remove_event_listener(FlyString const& type, RefPtr<IDLEventListener> callback);
+ void add_event_listener(FlyString const& type, RefPtr<IDLEventListener> callback, bool use_capture = false);
+ void remove_event_listener(FlyString const& type, RefPtr<IDLEventListener> callback, bool use_capture = false);
virtual bool dispatch_event(NonnullRefPtr<Event>);
ExceptionOr<bool> dispatch_event_binding(NonnullRefPtr<Event>);
diff --git a/Userland/Libraries/LibWeb/DOM/EventTarget.idl b/Userland/Libraries/LibWeb/DOM/EventTarget.idl
index eb7f45fc87..74b005c182 100644
--- a/Userland/Libraries/LibWeb/DOM/EventTarget.idl
+++ b/Userland/Libraries/LibWeb/DOM/EventTarget.idl
@@ -1,8 +1,8 @@
interface EventTarget {
// FIXME: Both of these should take in options
- undefined addEventListener(DOMString type, EventListener? callback);
- undefined removeEventListener(DOMString type, EventListener? callback);
+ undefined addEventListener(DOMString type, EventListener? callback, optional boolean useCapture = false);
+ undefined removeEventListener(DOMString type, EventListener? callback, optional boolean useCapture = false);
[ImplementedAs=dispatch_event_binding] boolean dispatchEvent(Event event);