From e22d9dc360d123b5b3c847a9ec882da220dc8e66 Mon Sep 17 00:00:00 2001 From: Idan Horowitz Date: Wed, 29 Sep 2021 01:43:24 +0300 Subject: [PATCH] LibWeb: Add the missing EventInit property to Event constructor --- Userland/Libraries/LibWeb/DOM/Event.h | 24 +++++++++++++++++++----- Userland/Libraries/LibWeb/DOM/Event.idl | 9 +++++++-- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/Userland/Libraries/LibWeb/DOM/Event.h b/Userland/Libraries/LibWeb/DOM/Event.h index 1da8eadc4e..85c1e9aa58 100644 --- a/Userland/Libraries/LibWeb/DOM/Event.h +++ b/Userland/Libraries/LibWeb/DOM/Event.h @@ -13,6 +13,12 @@ namespace Web::DOM { +struct EventInit { + bool bubbles { false }; + bool cancelable { false }; + bool composed { false }; +}; + class Event : public RefCounted , public Bindings::Wrappable { @@ -41,13 +47,13 @@ public: using Path = Vector; - static NonnullRefPtr create(const FlyString& event_name) + static NonnullRefPtr create(const FlyString& event_name, EventInit const& event_init = {}) { - return adopt_ref(*new Event(event_name)); + return adopt_ref(*new Event(event_name, event_init)); } - static NonnullRefPtr create_with_global_object(Bindings::WindowObject&, const FlyString& event_name) + static NonnullRefPtr create_with_global_object(Bindings::WindowObject&, const FlyString& event_name, EventInit const& event_init) { - return Event::create(event_name); + return Event::create(event_name, event_init); } virtual ~Event() { } @@ -137,11 +143,19 @@ public: void init_event(const String&, bool, bool); protected: - explicit Event(const FlyString& type) + explicit Event(FlyString const& type) : m_type(type) , m_initialized(true) { } + Event(FlyString const& type, EventInit const& event_init) + : m_type(type) + , m_bubbles(event_init.bubbles) + , m_cancelable(event_init.cancelable) + , m_composed(event_init.composed) + , m_initialized(true) + { + } void initialize(const String&, bool, bool); diff --git a/Userland/Libraries/LibWeb/DOM/Event.idl b/Userland/Libraries/LibWeb/DOM/Event.idl index 1b998c6e11..18d45c0d49 100644 --- a/Userland/Libraries/LibWeb/DOM/Event.idl +++ b/Userland/Libraries/LibWeb/DOM/Event.idl @@ -1,7 +1,6 @@ interface Event { - // FIXME: second parameter: 'optional EventInit eventInitDict = {}' - constructor(DOMString type); + constructor(DOMString type, optional EventInit eventInitDict = {}); readonly attribute DOMString type; readonly attribute EventTarget? target; @@ -26,3 +25,9 @@ interface Event { undefined initEvent(DOMString type, optional boolean bubbles = false, optional boolean cancelable = false); }; + +dictionary EventInit { + boolean bubbles = false; + boolean cancelable = false; + boolean composed = false; +};