diff --git a/Meta/gn/secondary/Userland/Libraries/LibWeb/UIEvents/BUILD.gn b/Meta/gn/secondary/Userland/Libraries/LibWeb/UIEvents/BUILD.gn index c8559c8a05b..3526c39fe13 100644 --- a/Meta/gn/secondary/Userland/Libraries/LibWeb/UIEvents/BUILD.gn +++ b/Meta/gn/secondary/Userland/Libraries/LibWeb/UIEvents/BUILD.gn @@ -7,6 +7,7 @@ source_set("UIEvents") { sources = [ "EventNames.cpp", "FocusEvent.cpp", + "InputEvent.cpp", "KeyboardEvent.cpp", "MouseEvent.cpp", "PointerEvent.cpp", diff --git a/Meta/gn/secondary/Userland/Libraries/LibWeb/idl_files.gni b/Meta/gn/secondary/Userland/Libraries/LibWeb/idl_files.gni index 9876e5489c4..e66d72960b1 100644 --- a/Meta/gn/secondary/Userland/Libraries/LibWeb/idl_files.gni +++ b/Meta/gn/secondary/Userland/Libraries/LibWeb/idl_files.gni @@ -331,6 +331,7 @@ standard_idl_files = [ "//Userland/Libraries/LibWeb/SVG/SVGTSpanElement.idl", "//Userland/Libraries/LibWeb/SVG/SVGUseElement.idl", "//Userland/Libraries/LibWeb/UIEvents/FocusEvent.idl", + "//Userland/Libraries/LibWeb/UIEvents/InputEvent.idl", "//Userland/Libraries/LibWeb/UIEvents/KeyboardEvent.idl", "//Userland/Libraries/LibWeb/UIEvents/MouseEvent.idl", "//Userland/Libraries/LibWeb/UIEvents/PointerEvent.idl", diff --git a/Tests/LibWeb/Text/expected/all-window-properties.txt b/Tests/LibWeb/Text/expected/all-window-properties.txt index e4484c041c2..9f8b4721681 100644 --- a/Tests/LibWeb/Text/expected/all-window-properties.txt +++ b/Tests/LibWeb/Text/expected/all-window-properties.txt @@ -197,6 +197,7 @@ IdleDeadline Image ImageBitmap ImageData +InputEvent Int16Array Int32Array Int8Array diff --git a/Userland/Libraries/LibWeb/CMakeLists.txt b/Userland/Libraries/LibWeb/CMakeLists.txt index d68a98f17ed..3af260e28d2 100644 --- a/Userland/Libraries/LibWeb/CMakeLists.txt +++ b/Userland/Libraries/LibWeb/CMakeLists.txt @@ -707,6 +707,7 @@ set(SOURCES Selection/Selection.cpp UIEvents/EventNames.cpp UIEvents/FocusEvent.cpp + UIEvents/InputEvent.cpp UIEvents/KeyboardEvent.cpp UIEvents/MouseEvent.cpp UIEvents/PointerEvent.cpp diff --git a/Userland/Libraries/LibWeb/Forward.h b/Userland/Libraries/LibWeb/Forward.h index 7e84b46edc8..67fd8f3455a 100644 --- a/Userland/Libraries/LibWeb/Forward.h +++ b/Userland/Libraries/LibWeb/Forward.h @@ -726,6 +726,7 @@ class SVGTitleElement; } namespace Web::UIEvents { +class InputEvent; class KeyboardEvent; class MouseEvent; class PointerEvent; diff --git a/Userland/Libraries/LibWeb/UIEvents/InputEvent.cpp b/Userland/Libraries/LibWeb/UIEvents/InputEvent.cpp new file mode 100644 index 00000000000..77e79eca52a --- /dev/null +++ b/Userland/Libraries/LibWeb/UIEvents/InputEvent.cpp @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024, Jamie Mansfield + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include +#include +#include + +namespace Web::UIEvents { + +JS_DEFINE_ALLOCATOR(InputEvent); + +WebIDL::ExceptionOr> InputEvent::construct_impl(JS::Realm& realm, FlyString const& event_name, InputEventInit const& event_init) +{ + return realm.heap().allocate(realm, realm, event_name, event_init); +} + +InputEvent::InputEvent(JS::Realm& realm, FlyString const& event_name, InputEventInit const& event_init) + : UIEvent(realm, event_name, event_init) + , m_data(event_init.data) + , m_is_composing(event_init.is_composing) + , m_input_type(event_init.input_type) +{ +} + +InputEvent::~InputEvent() = default; + +void InputEvent::initialize(JS::Realm& realm) +{ + Base::initialize(realm); + WEB_SET_PROTOTYPE_FOR_INTERFACE(InputEvent); +} + +} diff --git a/Userland/Libraries/LibWeb/UIEvents/InputEvent.h b/Userland/Libraries/LibWeb/UIEvents/InputEvent.h new file mode 100644 index 00000000000..7fa2c0d01cf --- /dev/null +++ b/Userland/Libraries/LibWeb/UIEvents/InputEvent.h @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2024, Jamie Mansfield + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include + +namespace Web::UIEvents { + +struct InputEventInit : public UIEventInit { + Optional data; + bool is_composing { false }; + String input_type {}; +}; + +class InputEvent final : public UIEvent { + WEB_PLATFORM_OBJECT(InputEvent, UIEvent); + JS_DECLARE_ALLOCATOR(InputEvent); + +public: + static WebIDL::ExceptionOr> construct_impl(JS::Realm&, FlyString const& event_name, InputEventInit const& event_init); + + virtual ~InputEvent() override; + + // https://w3c.github.io/uievents/#dom-inputevent-data + Optional data() const { return m_data; } + + // https://w3c.github.io/uievents/#dom-inputevent-iscomposing + bool is_composing() const { return m_is_composing; } + + // https://w3c.github.io/uievents/#dom-inputevent-inputtype + String input_type() const { return m_input_type; } + +private: + InputEvent(JS::Realm&, FlyString const& event_name, InputEventInit const&); + + virtual void initialize(JS::Realm&) override; + + Optional m_data; + bool m_is_composing; + String m_input_type; +}; + +} diff --git a/Userland/Libraries/LibWeb/UIEvents/InputEvent.idl b/Userland/Libraries/LibWeb/UIEvents/InputEvent.idl new file mode 100644 index 00000000000..75d4c8cbf74 --- /dev/null +++ b/Userland/Libraries/LibWeb/UIEvents/InputEvent.idl @@ -0,0 +1,17 @@ +#import + +// https://w3c.github.io/uievents/#inputevent +[Exposed=Window] +interface InputEvent : UIEvent { + constructor(DOMString type, optional InputEventInit eventInitDict = {}); + readonly attribute USVString? data; + readonly attribute boolean isComposing; + readonly attribute DOMString inputType; +}; + +// https://w3c.github.io/uievents/#dictdef-inputeventinit +dictionary InputEventInit : UIEventInit { + DOMString? data = null; + boolean isComposing = false; + DOMString inputType = ""; +}; diff --git a/Userland/Libraries/LibWeb/idl_files.cmake b/Userland/Libraries/LibWeb/idl_files.cmake index 14b5086932f..af8b194a0fc 100644 --- a/Userland/Libraries/LibWeb/idl_files.cmake +++ b/Userland/Libraries/LibWeb/idl_files.cmake @@ -317,6 +317,7 @@ libweb_js_bindings(SVG/SVGUseElement) libweb_js_bindings(Selection/Selection) libweb_js_bindings(StorageAPI/StorageManager) libweb_js_bindings(UIEvents/FocusEvent) +libweb_js_bindings(UIEvents/InputEvent) libweb_js_bindings(UIEvents/KeyboardEvent) libweb_js_bindings(UIEvents/MouseEvent) libweb_js_bindings(UIEvents/PointerEvent)