1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 05:37:34 +00:00

LibWeb: Add the missing EventInit property to Event constructor

This commit is contained in:
Idan Horowitz 2021-09-29 01:43:24 +03:00
parent 071a358ffb
commit e22d9dc360
2 changed files with 26 additions and 7 deletions

View file

@ -13,6 +13,12 @@
namespace Web::DOM { namespace Web::DOM {
struct EventInit {
bool bubbles { false };
bool cancelable { false };
bool composed { false };
};
class Event class Event
: public RefCounted<Event> : public RefCounted<Event>
, public Bindings::Wrappable { , public Bindings::Wrappable {
@ -41,13 +47,13 @@ public:
using Path = Vector<PathEntry>; using Path = Vector<PathEntry>;
static NonnullRefPtr<Event> create(const FlyString& event_name) static NonnullRefPtr<Event> 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<Event> create_with_global_object(Bindings::WindowObject&, const FlyString& event_name) static NonnullRefPtr<Event> 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() { } virtual ~Event() { }
@ -137,11 +143,19 @@ public:
void init_event(const String&, bool, bool); void init_event(const String&, bool, bool);
protected: protected:
explicit Event(const FlyString& type) explicit Event(FlyString const& type)
: m_type(type) : m_type(type)
, m_initialized(true) , 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); void initialize(const String&, bool, bool);

View file

@ -1,7 +1,6 @@
interface Event { interface Event {
// FIXME: second parameter: 'optional EventInit eventInitDict = {}' constructor(DOMString type, optional EventInit eventInitDict = {});
constructor(DOMString type);
readonly attribute DOMString type; readonly attribute DOMString type;
readonly attribute EventTarget? target; readonly attribute EventTarget? target;
@ -26,3 +25,9 @@ interface Event {
undefined initEvent(DOMString type, optional boolean bubbles = false, optional boolean cancelable = false); undefined initEvent(DOMString type, optional boolean bubbles = false, optional boolean cancelable = false);
}; };
dictionary EventInit {
boolean bubbles = false;
boolean cancelable = false;
boolean composed = false;
};