LibWeb: Add Event.initEvent

Used by YouTube after creating an event with Document.createEvent
This commit is contained in:
Luke 2021-04-10 20:11:04 +01:00 committed by Andreas Kling
parent 8da14bf880
commit fc9abee84b
3 changed files with 29 additions and 0 deletions

View file

@ -56,4 +56,27 @@ void Event::set_cancelled_flag()
m_cancelled = true;
}
// https://dom.spec.whatwg.org/#concept-event-initialize
void Event::initialize(const String& type, bool bubbles, bool cancelable)
{
m_initialized = true;
m_stop_propagation = false;
m_stop_immediate_propagation = false;
m_cancelled = false;
m_is_trusted = false;
m_target = nullptr;
m_type = type;
m_bubbles = bubbles;
m_cancelable = cancelable;
}
// https://dom.spec.whatwg.org/#dom-event-initevent
void Event::init_event(const String& type, bool bubbles, bool cancelable)
{
if (m_dispatch)
return;
initialize(type, bubbles, cancelable);
}
}

View file

@ -154,6 +154,8 @@ public:
m_stop_immediate_propagation = true;
}
void init_event(const String&, bool, bool);
protected:
explicit Event(const FlyString& type)
: m_type(type)
@ -161,6 +163,8 @@ protected:
{
}
void initialize(const String&, bool, bool);
private:
FlyString m_type;
RefPtr<EventTarget> m_target;

View file

@ -23,4 +23,6 @@ interface Event {
readonly attribute boolean isTrusted;
undefined initEvent(DOMString type, optional boolean bubbles = false, optional boolean cancelable = false);
};