diff --git a/Userland/Libraries/LibWeb/UIEvents/KeyboardEvent.cpp b/Userland/Libraries/LibWeb/UIEvents/KeyboardEvent.cpp index 67a48a8451c..6bdba5c9caf 100644 --- a/Userland/Libraries/LibWeb/UIEvents/KeyboardEvent.cpp +++ b/Userland/Libraries/LibWeb/UIEvents/KeyboardEvent.cpp @@ -683,6 +683,29 @@ bool KeyboardEvent::get_modifier_state(String const& key_arg) const return false; } +// https://w3c.github.io/uievents/#dom-keyboardevent-initkeyboardevent +void KeyboardEvent::init_keyboard_event(String const& type, bool bubbles, bool cancelable, HTML::Window* view, String const& key, WebIDL::UnsignedLong location, bool ctrl_key, bool alt_key, bool shift_key, bool meta_key) +{ + // Initializes attributes of a KeyboardEvent object. This method has the same behavior as UIEvent.initUIEvent(). + // The value of detail remains undefined. + + // 1. If this’s dispatch flag is set, then return. + if (dispatched()) + return; + + // 2. Initialize this with type, bubbles, and cancelable. + initialize_event(type, bubbles, cancelable); + + // Implementation Defined: Initialise other values. + m_view = view; + m_key = key; + m_location = location; + m_ctrl_key = ctrl_key; + m_alt_key = alt_key; + m_shift_key = shift_key; + m_meta_key = meta_key; +} + JS::NonnullGCPtr KeyboardEvent::create(JS::Realm& realm, FlyString const& event_name, KeyboardEventInit const& event_init) { return realm.heap().allocate(realm, realm, event_name, event_init); diff --git a/Userland/Libraries/LibWeb/UIEvents/KeyboardEvent.h b/Userland/Libraries/LibWeb/UIEvents/KeyboardEvent.h index acc523a8465..f03b722b0f3 100644 --- a/Userland/Libraries/LibWeb/UIEvents/KeyboardEvent.h +++ b/Userland/Libraries/LibWeb/UIEvents/KeyboardEvent.h @@ -62,6 +62,8 @@ public: virtual u32 which() const override { return m_key_code; } + void init_keyboard_event(String const& type, bool bubbles, bool cancelable, HTML::Window* view, String const& key, WebIDL::UnsignedLong location, bool ctrl_key, bool alt_key, bool shift_key, bool meta_key); + private: KeyboardEvent(JS::Realm&, FlyString const& event_name, KeyboardEventInit const& event_init); diff --git a/Userland/Libraries/LibWeb/UIEvents/KeyboardEvent.idl b/Userland/Libraries/LibWeb/UIEvents/KeyboardEvent.idl index eb540336e79..3d035c5bd55 100644 --- a/Userland/Libraries/LibWeb/UIEvents/KeyboardEvent.idl +++ b/Userland/Libraries/LibWeb/UIEvents/KeyboardEvent.idl @@ -29,6 +29,9 @@ interface KeyboardEvent : UIEvent { boolean getModifierState(DOMString keyArg); + // https://w3c.github.io/uievents/#dom-keyboardevent-initkeyboardevent + undefined initKeyboardEvent(DOMString typeArg, optional boolean bubblesArg = false, optional boolean cancelableArg = false, optional Window? viewArg = null, optional DOMString keyArg = "", optional unsigned long locationArg = 0, optional boolean ctrlKey = false, optional boolean altKey = false, optional boolean shiftKey = false, optional boolean metaKey = false); + }; // https://www.w3.org/TR/uievents/#dictdef-keyboardeventinit