diff --git a/Meta/gn/secondary/Userland/Libraries/LibWeb/UIEvents/BUILD.gn b/Meta/gn/secondary/Userland/Libraries/LibWeb/UIEvents/BUILD.gn index 5b39283cc32..92ceb7125e3 100644 --- a/Meta/gn/secondary/Userland/Libraries/LibWeb/UIEvents/BUILD.gn +++ b/Meta/gn/secondary/Userland/Libraries/LibWeb/UIEvents/BUILD.gn @@ -12,6 +12,7 @@ source_set("UIEvents") { "KeyboardEvent.cpp", "MouseEvent.cpp", "PointerEvent.cpp", + "TextEvent.cpp", "UIEvent.cpp", "WheelEvent.cpp", ] diff --git a/Meta/gn/secondary/Userland/Libraries/LibWeb/idl_files.gni b/Meta/gn/secondary/Userland/Libraries/LibWeb/idl_files.gni index 37c22ba9fa0..3609728c9cf 100644 --- a/Meta/gn/secondary/Userland/Libraries/LibWeb/idl_files.gni +++ b/Meta/gn/secondary/Userland/Libraries/LibWeb/idl_files.gni @@ -336,6 +336,7 @@ standard_idl_files = [ "//Userland/Libraries/LibWeb/UIEvents/KeyboardEvent.idl", "//Userland/Libraries/LibWeb/UIEvents/MouseEvent.idl", "//Userland/Libraries/LibWeb/UIEvents/PointerEvent.idl", + "//Userland/Libraries/LibWeb/UIEvents/TextEvent.idl", "//Userland/Libraries/LibWeb/UIEvents/UIEvent.idl", "//Userland/Libraries/LibWeb/UIEvents/WheelEvent.idl", "//Userland/Libraries/LibWeb/UserTiming/PerformanceMark.idl", diff --git a/Tests/LibWeb/Text/expected/all-window-properties.txt b/Tests/LibWeb/Text/expected/all-window-properties.txt index 4c1c08acff3..b7e6bc14f84 100644 --- a/Tests/LibWeb/Text/expected/all-window-properties.txt +++ b/Tests/LibWeb/Text/expected/all-window-properties.txt @@ -346,6 +346,7 @@ SyntaxError Text TextDecoder TextEncoder +TextEvent TextMetrics TextTrack TextTrackCue diff --git a/Userland/Libraries/LibWeb/CMakeLists.txt b/Userland/Libraries/LibWeb/CMakeLists.txt index 9221e158cd5..cee90b3da34 100644 --- a/Userland/Libraries/LibWeb/CMakeLists.txt +++ b/Userland/Libraries/LibWeb/CMakeLists.txt @@ -712,6 +712,7 @@ set(SOURCES UIEvents/KeyboardEvent.cpp UIEvents/MouseEvent.cpp UIEvents/PointerEvent.cpp + UIEvents/TextEvent.cpp UIEvents/UIEvent.cpp UIEvents/WheelEvent.cpp UserTiming/PerformanceMark.cpp diff --git a/Userland/Libraries/LibWeb/DOM/Document.cpp b/Userland/Libraries/LibWeb/DOM/Document.cpp index 6000830c639..563d481deef 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.cpp +++ b/Userland/Libraries/LibWeb/DOM/Document.cpp @@ -133,6 +133,7 @@ #include #include #include +#include #include #include #include @@ -1784,7 +1785,7 @@ WebIDL::ExceptionOr> Document::create_event(StringView i } else if (Infra::is_ascii_case_insensitive_match(interface, "svgevents"sv)) { event = Event::create(realm, FlyString {}); } else if (Infra::is_ascii_case_insensitive_match(interface, "textevent"sv)) { - event = Event::create(realm, FlyString {}); // FIXME: Create TextEvent + event = UIEvents::TextEvent::create(realm, FlyString {}); } else if (Infra::is_ascii_case_insensitive_match(interface, "touchevent"sv)) { event = Event::create(realm, FlyString {}); // FIXME: Create TouchEvent } else if (Infra::is_ascii_case_insensitive_match(interface, "uievent"sv) diff --git a/Userland/Libraries/LibWeb/Forward.h b/Userland/Libraries/LibWeb/Forward.h index 3be2b929d4c..65c50bfc798 100644 --- a/Userland/Libraries/LibWeb/Forward.h +++ b/Userland/Libraries/LibWeb/Forward.h @@ -731,6 +731,7 @@ class InputEvent; class KeyboardEvent; class MouseEvent; class PointerEvent; +class TextEvent; class UIEvent; } diff --git a/Userland/Libraries/LibWeb/UIEvents/TextEvent.cpp b/Userland/Libraries/LibWeb/UIEvents/TextEvent.cpp new file mode 100644 index 00000000000..2d33317d450 --- /dev/null +++ b/Userland/Libraries/LibWeb/UIEvents/TextEvent.cpp @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2024, Jamie Mansfield + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include +#include +#include + +namespace Web::UIEvents { + +JS_DEFINE_ALLOCATOR(TextEvent); + +JS::NonnullGCPtr TextEvent::create(JS::Realm& realm, FlyString const& event_name) +{ + return realm.heap().allocate(realm, realm, event_name); +} + +TextEvent::TextEvent(JS::Realm& realm, FlyString const& event_name) + : UIEvent(realm, event_name) +{ +} + +TextEvent::~TextEvent() = default; + +void TextEvent::initialize(JS::Realm& realm) +{ + Base::initialize(realm); + WEB_SET_PROTOTYPE_FOR_INTERFACE(TextEvent); +} + +// https://w3c.github.io/uievents/#dom-textevent-inittextevent +void TextEvent::init_text_event(String const& type, bool bubbles, bool cancelable, HTML::Window* view, String const& data) +{ + // Initializes attributes of a TextEvent 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_data = data; +} + +} diff --git a/Userland/Libraries/LibWeb/UIEvents/TextEvent.h b/Userland/Libraries/LibWeb/UIEvents/TextEvent.h new file mode 100644 index 00000000000..884e340ea0c --- /dev/null +++ b/Userland/Libraries/LibWeb/UIEvents/TextEvent.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024, Jamie Mansfield + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include + +namespace Web::UIEvents { + +class TextEvent final : public UIEvent { + WEB_PLATFORM_OBJECT(TextEvent, UIEvent); + JS_DECLARE_ALLOCATOR(TextEvent); + +public: + [[nodiscard]] static JS::NonnullGCPtr create(JS::Realm&, FlyString const& event_name); + + virtual ~TextEvent() override; + + // https://w3c.github.io/uievents/#dom-textevent-data + String data() const { return m_data; } + + void init_text_event(String const& type, bool bubbles, bool cancelable, HTML::Window* view, String const& data); + +private: + TextEvent(JS::Realm&, FlyString const& event_name); + + virtual void initialize(JS::Realm&) override; + + String m_data; +}; + +} diff --git a/Userland/Libraries/LibWeb/UIEvents/TextEvent.idl b/Userland/Libraries/LibWeb/UIEvents/TextEvent.idl new file mode 100644 index 00000000000..d50e8cc0d66 --- /dev/null +++ b/Userland/Libraries/LibWeb/UIEvents/TextEvent.idl @@ -0,0 +1,8 @@ +#import + +// https://w3c.github.io/uievents/#textevent +[Exposed=Window] +interface TextEvent : UIEvent { + readonly attribute DOMString data; + undefined initTextEvent(DOMString type, optional boolean bubbles = false, optional boolean cancelable = false, optional Window? view = null, optional DOMString data = "undefined"); +}; diff --git a/Userland/Libraries/LibWeb/idl_files.cmake b/Userland/Libraries/LibWeb/idl_files.cmake index 1fc0ae4aeca..19f61e53f2a 100644 --- a/Userland/Libraries/LibWeb/idl_files.cmake +++ b/Userland/Libraries/LibWeb/idl_files.cmake @@ -322,6 +322,7 @@ libweb_js_bindings(UIEvents/InputEvent) libweb_js_bindings(UIEvents/KeyboardEvent) libweb_js_bindings(UIEvents/MouseEvent) libweb_js_bindings(UIEvents/PointerEvent) +libweb_js_bindings(UIEvents/TextEvent) libweb_js_bindings(UIEvents/UIEvent) libweb_js_bindings(UIEvents/WheelEvent) libweb_js_bindings(UserTiming/PerformanceMark)