LibWeb: Implement KeyboardEvent.initKeyboardEvent

This commit is contained in:
Jamie Mansfield 2024-07-17 11:48:27 +01:00 committed by Tim Ledbetter
commit 3845d174e3
Notes: sideshowbarker 2024-07-18 02:43:43 +09:00
3 changed files with 28 additions and 0 deletions

View file

@ -683,6 +683,29 @@ bool KeyboardEvent::get_modifier_state(String const& key_arg) const
return false; 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 thiss 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> KeyboardEvent::create(JS::Realm& realm, FlyString const& event_name, KeyboardEventInit const& event_init) JS::NonnullGCPtr<KeyboardEvent> KeyboardEvent::create(JS::Realm& realm, FlyString const& event_name, KeyboardEventInit const& event_init)
{ {
return realm.heap().allocate<KeyboardEvent>(realm, realm, event_name, event_init); return realm.heap().allocate<KeyboardEvent>(realm, realm, event_name, event_init);

View file

@ -62,6 +62,8 @@ public:
virtual u32 which() const override { return m_key_code; } 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: private:
KeyboardEvent(JS::Realm&, FlyString const& event_name, KeyboardEventInit const& event_init); KeyboardEvent(JS::Realm&, FlyString const& event_name, KeyboardEventInit const& event_init);

View file

@ -29,6 +29,9 @@ interface KeyboardEvent : UIEvent {
boolean getModifierState(DOMString keyArg); 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 // https://www.w3.org/TR/uievents/#dictdef-keyboardeventinit