Skip to content

Commit

Permalink
LibWeb/UIEvents: Implement TextEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
jamierocks committed Oct 5, 2024
1 parent b6ac9bf commit 4218f05
Show file tree
Hide file tree
Showing 10 changed files with 102 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ source_set("UIEvents") {
"KeyboardEvent.cpp",
"MouseEvent.cpp",
"PointerEvent.cpp",
"TextEvent.cpp",
"UIEvent.cpp",
"WheelEvent.cpp",
]
Expand Down
1 change: 1 addition & 0 deletions Meta/gn/secondary/Userland/Libraries/LibWeb/idl_files.gni
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions Tests/LibWeb/Text/expected/all-window-properties.txt
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@ SyntaxError
Text
TextDecoder
TextEncoder
TextEvent
TextMetrics
TextTrack
TextTrackCue
Expand Down
1 change: 1 addition & 0 deletions Userland/Libraries/LibWeb/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,7 @@ set(SOURCES
UIEvents/KeyboardEvent.cpp
UIEvents/MouseEvent.cpp
UIEvents/PointerEvent.cpp
UIEvents/TextEvent.cpp
UIEvents/UIEvent.cpp
UIEvents/WheelEvent.cpp
UserTiming/PerformanceMark.cpp
Expand Down
3 changes: 2 additions & 1 deletion Userland/Libraries/LibWeb/DOM/Document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@
#include <LibWeb/UIEvents/FocusEvent.h>
#include <LibWeb/UIEvents/KeyboardEvent.h>
#include <LibWeb/UIEvents/MouseEvent.h>
#include <LibWeb/UIEvents/TextEvent.h>
#include <LibWeb/WebIDL/AbstractOperations.h>
#include <LibWeb/WebIDL/DOMException.h>
#include <LibWeb/WebIDL/ExceptionOr.h>
Expand Down Expand Up @@ -1781,7 +1782,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<Event>> 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)
Expand Down
1 change: 1 addition & 0 deletions Userland/Libraries/LibWeb/Forward.h
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,7 @@ class InputEvent;
class KeyboardEvent;
class MouseEvent;
class PointerEvent;
class TextEvent;
class UIEvent;
}

Expand Down
51 changes: 51 additions & 0 deletions Userland/Libraries/LibWeb/UIEvents/TextEvent.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright (c) 2024, Jamie Mansfield <[email protected]>
*
* SPDX-License-Identifier: BSD-2-Clause
*/

#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/Bindings/TextEventPrototype.h>
#include <LibWeb/UIEvents/TextEvent.h>

namespace Web::UIEvents {

JS_DEFINE_ALLOCATOR(TextEvent);

JS::NonnullGCPtr<TextEvent> TextEvent::create(JS::Realm& realm, FlyString const& event_name)
{
return realm.heap().allocate<TextEvent>(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;
}

}
35 changes: 35 additions & 0 deletions Userland/Libraries/LibWeb/UIEvents/TextEvent.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright (c) 2024, Jamie Mansfield <[email protected]>
*
* SPDX-License-Identifier: BSD-2-Clause
*/

#pragma once

#include <LibWeb/UIEvents/UIEvent.h>

namespace Web::UIEvents {

class TextEvent final : public UIEvent {
WEB_PLATFORM_OBJECT(TextEvent, UIEvent);
JS_DECLARE_ALLOCATOR(TextEvent);

public:
[[nodiscard]] static JS::NonnullGCPtr<TextEvent> 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;
};

}
8 changes: 8 additions & 0 deletions Userland/Libraries/LibWeb/UIEvents/TextEvent.idl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#import <UIEvents/UIEvent.idl>

// 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");
};
1 change: 1 addition & 0 deletions Userland/Libraries/LibWeb/idl_files.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,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)
Expand Down

0 comments on commit 4218f05

Please sign in to comment.