mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-07 08:39:22 +00:00
LibWeb/UIEvents: Implement TextEvent
This commit is contained in:
parent
86e20ea246
commit
f610a12671
Notes:
github-actions[bot]
2024-10-08 09:46:36 +00:00
Author: https://github.com/jamierocks
Commit: f610a12671
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/701
Reviewed-by: https://github.com/ADKaster
Reviewed-by: https://github.com/AtkinsSJ
Reviewed-by: https://github.com/tcl3
10 changed files with 102 additions and 1 deletions
|
@ -12,6 +12,7 @@ source_set("UIEvents") {
|
||||||
"KeyboardEvent.cpp",
|
"KeyboardEvent.cpp",
|
||||||
"MouseEvent.cpp",
|
"MouseEvent.cpp",
|
||||||
"PointerEvent.cpp",
|
"PointerEvent.cpp",
|
||||||
|
"TextEvent.cpp",
|
||||||
"UIEvent.cpp",
|
"UIEvent.cpp",
|
||||||
"WheelEvent.cpp",
|
"WheelEvent.cpp",
|
||||||
]
|
]
|
||||||
|
|
|
@ -336,6 +336,7 @@ standard_idl_files = [
|
||||||
"//Userland/Libraries/LibWeb/UIEvents/KeyboardEvent.idl",
|
"//Userland/Libraries/LibWeb/UIEvents/KeyboardEvent.idl",
|
||||||
"//Userland/Libraries/LibWeb/UIEvents/MouseEvent.idl",
|
"//Userland/Libraries/LibWeb/UIEvents/MouseEvent.idl",
|
||||||
"//Userland/Libraries/LibWeb/UIEvents/PointerEvent.idl",
|
"//Userland/Libraries/LibWeb/UIEvents/PointerEvent.idl",
|
||||||
|
"//Userland/Libraries/LibWeb/UIEvents/TextEvent.idl",
|
||||||
"//Userland/Libraries/LibWeb/UIEvents/UIEvent.idl",
|
"//Userland/Libraries/LibWeb/UIEvents/UIEvent.idl",
|
||||||
"//Userland/Libraries/LibWeb/UIEvents/WheelEvent.idl",
|
"//Userland/Libraries/LibWeb/UIEvents/WheelEvent.idl",
|
||||||
"//Userland/Libraries/LibWeb/UserTiming/PerformanceMark.idl",
|
"//Userland/Libraries/LibWeb/UserTiming/PerformanceMark.idl",
|
||||||
|
|
|
@ -346,6 +346,7 @@ SyntaxError
|
||||||
Text
|
Text
|
||||||
TextDecoder
|
TextDecoder
|
||||||
TextEncoder
|
TextEncoder
|
||||||
|
TextEvent
|
||||||
TextMetrics
|
TextMetrics
|
||||||
TextTrack
|
TextTrack
|
||||||
TextTrackCue
|
TextTrackCue
|
||||||
|
|
|
@ -712,6 +712,7 @@ set(SOURCES
|
||||||
UIEvents/KeyboardEvent.cpp
|
UIEvents/KeyboardEvent.cpp
|
||||||
UIEvents/MouseEvent.cpp
|
UIEvents/MouseEvent.cpp
|
||||||
UIEvents/PointerEvent.cpp
|
UIEvents/PointerEvent.cpp
|
||||||
|
UIEvents/TextEvent.cpp
|
||||||
UIEvents/UIEvent.cpp
|
UIEvents/UIEvent.cpp
|
||||||
UIEvents/WheelEvent.cpp
|
UIEvents/WheelEvent.cpp
|
||||||
UserTiming/PerformanceMark.cpp
|
UserTiming/PerformanceMark.cpp
|
||||||
|
|
|
@ -133,6 +133,7 @@
|
||||||
#include <LibWeb/UIEvents/FocusEvent.h>
|
#include <LibWeb/UIEvents/FocusEvent.h>
|
||||||
#include <LibWeb/UIEvents/KeyboardEvent.h>
|
#include <LibWeb/UIEvents/KeyboardEvent.h>
|
||||||
#include <LibWeb/UIEvents/MouseEvent.h>
|
#include <LibWeb/UIEvents/MouseEvent.h>
|
||||||
|
#include <LibWeb/UIEvents/TextEvent.h>
|
||||||
#include <LibWeb/WebIDL/AbstractOperations.h>
|
#include <LibWeb/WebIDL/AbstractOperations.h>
|
||||||
#include <LibWeb/WebIDL/DOMException.h>
|
#include <LibWeb/WebIDL/DOMException.h>
|
||||||
#include <LibWeb/WebIDL/ExceptionOr.h>
|
#include <LibWeb/WebIDL/ExceptionOr.h>
|
||||||
|
@ -1784,7 +1785,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<Event>> Document::create_event(StringView i
|
||||||
} else if (Infra::is_ascii_case_insensitive_match(interface, "svgevents"sv)) {
|
} else if (Infra::is_ascii_case_insensitive_match(interface, "svgevents"sv)) {
|
||||||
event = Event::create(realm, FlyString {});
|
event = Event::create(realm, FlyString {});
|
||||||
} else if (Infra::is_ascii_case_insensitive_match(interface, "textevent"sv)) {
|
} 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)) {
|
} else if (Infra::is_ascii_case_insensitive_match(interface, "touchevent"sv)) {
|
||||||
event = Event::create(realm, FlyString {}); // FIXME: Create TouchEvent
|
event = Event::create(realm, FlyString {}); // FIXME: Create TouchEvent
|
||||||
} else if (Infra::is_ascii_case_insensitive_match(interface, "uievent"sv)
|
} else if (Infra::is_ascii_case_insensitive_match(interface, "uievent"sv)
|
||||||
|
|
|
@ -731,6 +731,7 @@ class InputEvent;
|
||||||
class KeyboardEvent;
|
class KeyboardEvent;
|
||||||
class MouseEvent;
|
class MouseEvent;
|
||||||
class PointerEvent;
|
class PointerEvent;
|
||||||
|
class TextEvent;
|
||||||
class UIEvent;
|
class UIEvent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
51
Userland/Libraries/LibWeb/UIEvents/TextEvent.cpp
Normal file
51
Userland/Libraries/LibWeb/UIEvents/TextEvent.cpp
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2024, Jamie Mansfield <jmansfield@cadixdev.org>
|
||||||
|
*
|
||||||
|
* 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
Userland/Libraries/LibWeb/UIEvents/TextEvent.h
Normal file
35
Userland/Libraries/LibWeb/UIEvents/TextEvent.h
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2024, Jamie Mansfield <jmansfield@cadixdev.org>
|
||||||
|
*
|
||||||
|
* 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
Userland/Libraries/LibWeb/UIEvents/TextEvent.idl
Normal file
8
Userland/Libraries/LibWeb/UIEvents/TextEvent.idl
Normal file
|
@ -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");
|
||||||
|
};
|
|
@ -322,6 +322,7 @@ libweb_js_bindings(UIEvents/InputEvent)
|
||||||
libweb_js_bindings(UIEvents/KeyboardEvent)
|
libweb_js_bindings(UIEvents/KeyboardEvent)
|
||||||
libweb_js_bindings(UIEvents/MouseEvent)
|
libweb_js_bindings(UIEvents/MouseEvent)
|
||||||
libweb_js_bindings(UIEvents/PointerEvent)
|
libweb_js_bindings(UIEvents/PointerEvent)
|
||||||
|
libweb_js_bindings(UIEvents/TextEvent)
|
||||||
libweb_js_bindings(UIEvents/UIEvent)
|
libweb_js_bindings(UIEvents/UIEvent)
|
||||||
libweb_js_bindings(UIEvents/WheelEvent)
|
libweb_js_bindings(UIEvents/WheelEvent)
|
||||||
libweb_js_bindings(UserTiming/PerformanceMark)
|
libweb_js_bindings(UserTiming/PerformanceMark)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue