mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-08 09:09:43 +00:00
LibWeb/UIEvents: Implement CompositionEvent
This commit is contained in:
parent
9fce70069d
commit
86e20ea246
Notes:
github-actions[bot]
2024-10-08 09:46:42 +00:00
Author: https://github.com/jamierocks
Commit: 86e20ea246
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 123 additions and 2 deletions
|
@ -5,6 +5,7 @@ source_set("UIEvents") {
|
||||||
"//Userland/", # For LibGUI needing WindowServer types
|
"//Userland/", # For LibGUI needing WindowServer types
|
||||||
]
|
]
|
||||||
sources = [
|
sources = [
|
||||||
|
"CompositionEvent.cpp",
|
||||||
"EventNames.cpp",
|
"EventNames.cpp",
|
||||||
"FocusEvent.cpp",
|
"FocusEvent.cpp",
|
||||||
"InputEvent.cpp",
|
"InputEvent.cpp",
|
||||||
|
|
|
@ -330,6 +330,7 @@ standard_idl_files = [
|
||||||
"//Userland/Libraries/LibWeb/SVG/SVGTransformList.idl",
|
"//Userland/Libraries/LibWeb/SVG/SVGTransformList.idl",
|
||||||
"//Userland/Libraries/LibWeb/SVG/SVGTSpanElement.idl",
|
"//Userland/Libraries/LibWeb/SVG/SVGTSpanElement.idl",
|
||||||
"//Userland/Libraries/LibWeb/SVG/SVGUseElement.idl",
|
"//Userland/Libraries/LibWeb/SVG/SVGUseElement.idl",
|
||||||
|
"//Userland/Libraries/LibWeb/UIEvents/CompositionEvent.idl",
|
||||||
"//Userland/Libraries/LibWeb/UIEvents/FocusEvent.idl",
|
"//Userland/Libraries/LibWeb/UIEvents/FocusEvent.idl",
|
||||||
"//Userland/Libraries/LibWeb/UIEvents/InputEvent.idl",
|
"//Userland/Libraries/LibWeb/UIEvents/InputEvent.idl",
|
||||||
"//Userland/Libraries/LibWeb/UIEvents/KeyboardEvent.idl",
|
"//Userland/Libraries/LibWeb/UIEvents/KeyboardEvent.idl",
|
||||||
|
|
|
@ -58,6 +58,7 @@ ClipboardEvent
|
||||||
CloseEvent
|
CloseEvent
|
||||||
CloseWatcher
|
CloseWatcher
|
||||||
Comment
|
Comment
|
||||||
|
CompositionEvent
|
||||||
CountQueuingStrategy
|
CountQueuingStrategy
|
||||||
Crypto
|
Crypto
|
||||||
CryptoKey
|
CryptoKey
|
||||||
|
|
|
@ -705,6 +705,7 @@ set(SOURCES
|
||||||
SVG/TagNames.cpp
|
SVG/TagNames.cpp
|
||||||
SVG/ViewBox.cpp
|
SVG/ViewBox.cpp
|
||||||
Selection/Selection.cpp
|
Selection/Selection.cpp
|
||||||
|
UIEvents/CompositionEvent.cpp
|
||||||
UIEvents/EventNames.cpp
|
UIEvents/EventNames.cpp
|
||||||
UIEvents/FocusEvent.cpp
|
UIEvents/FocusEvent.cpp
|
||||||
UIEvents/InputEvent.cpp
|
UIEvents/InputEvent.cpp
|
||||||
|
|
|
@ -128,6 +128,7 @@
|
||||||
#include <LibWeb/SVG/SVGStyleElement.h>
|
#include <LibWeb/SVG/SVGStyleElement.h>
|
||||||
#include <LibWeb/SVG/SVGTitleElement.h>
|
#include <LibWeb/SVG/SVGTitleElement.h>
|
||||||
#include <LibWeb/Selection/Selection.h>
|
#include <LibWeb/Selection/Selection.h>
|
||||||
|
#include <LibWeb/UIEvents/CompositionEvent.h>
|
||||||
#include <LibWeb/UIEvents/EventNames.h>
|
#include <LibWeb/UIEvents/EventNames.h>
|
||||||
#include <LibWeb/UIEvents/FocusEvent.h>
|
#include <LibWeb/UIEvents/FocusEvent.h>
|
||||||
#include <LibWeb/UIEvents/KeyboardEvent.h>
|
#include <LibWeb/UIEvents/KeyboardEvent.h>
|
||||||
|
@ -1753,7 +1754,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<Event>> Document::create_event(StringView i
|
||||||
if (Infra::is_ascii_case_insensitive_match(interface, "beforeunloadevent"sv)) {
|
if (Infra::is_ascii_case_insensitive_match(interface, "beforeunloadevent"sv)) {
|
||||||
event = BeforeUnloadEvent::create(realm, FlyString {});
|
event = BeforeUnloadEvent::create(realm, FlyString {});
|
||||||
} else if (Infra::is_ascii_case_insensitive_match(interface, "compositionevent"sv)) {
|
} else if (Infra::is_ascii_case_insensitive_match(interface, "compositionevent"sv)) {
|
||||||
event = Event::create(realm, FlyString {}); // FIXME: Create CompositionEvent
|
event = UIEvents::CompositionEvent::create(realm, String {});
|
||||||
} else if (Infra::is_ascii_case_insensitive_match(interface, "customevent"sv)) {
|
} else if (Infra::is_ascii_case_insensitive_match(interface, "customevent"sv)) {
|
||||||
event = CustomEvent::create(realm, FlyString {});
|
event = CustomEvent::create(realm, FlyString {});
|
||||||
} else if (Infra::is_ascii_case_insensitive_match(interface, "devicemotionevent"sv)) {
|
} else if (Infra::is_ascii_case_insensitive_match(interface, "devicemotionevent"sv)) {
|
||||||
|
@ -1783,7 +1784,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 CompositionEvent
|
event = Event::create(realm, FlyString {}); // FIXME: Create TextEvent
|
||||||
} 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)
|
||||||
|
|
|
@ -726,6 +726,7 @@ class SVGTitleElement;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace Web::UIEvents {
|
namespace Web::UIEvents {
|
||||||
|
class CompositionEvent;
|
||||||
class InputEvent;
|
class InputEvent;
|
||||||
class KeyboardEvent;
|
class KeyboardEvent;
|
||||||
class MouseEvent;
|
class MouseEvent;
|
||||||
|
|
57
Userland/Libraries/LibWeb/UIEvents/CompositionEvent.cpp
Normal file
57
Userland/Libraries/LibWeb/UIEvents/CompositionEvent.cpp
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2024, Jamie Mansfield <jmansfield@cadixdev.org>
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <LibWeb/Bindings/CompositionEventPrototype.h>
|
||||||
|
#include <LibWeb/Bindings/Intrinsics.h>
|
||||||
|
#include <LibWeb/UIEvents/CompositionEvent.h>
|
||||||
|
|
||||||
|
namespace Web::UIEvents {
|
||||||
|
|
||||||
|
JS_DEFINE_ALLOCATOR(CompositionEvent);
|
||||||
|
|
||||||
|
JS::NonnullGCPtr<CompositionEvent> CompositionEvent::create(JS::Realm& realm, FlyString const& event_name, CompositionEventInit const& event_init)
|
||||||
|
{
|
||||||
|
return realm.heap().allocate<CompositionEvent>(realm, realm, event_name, event_init);
|
||||||
|
}
|
||||||
|
|
||||||
|
WebIDL::ExceptionOr<JS::NonnullGCPtr<CompositionEvent>> CompositionEvent::construct_impl(JS::Realm& realm, FlyString const& event_name, CompositionEventInit const& event_init)
|
||||||
|
{
|
||||||
|
return realm.heap().allocate<CompositionEvent>(realm, realm, event_name, event_init);
|
||||||
|
}
|
||||||
|
|
||||||
|
CompositionEvent::CompositionEvent(JS::Realm& realm, FlyString const& event_name, CompositionEventInit const& event_init)
|
||||||
|
: UIEvent(realm, event_name, event_init)
|
||||||
|
, m_data(event_init.data)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
CompositionEvent::~CompositionEvent() = default;
|
||||||
|
|
||||||
|
void CompositionEvent::initialize(JS::Realm& realm)
|
||||||
|
{
|
||||||
|
Base::initialize(realm);
|
||||||
|
WEB_SET_PROTOTYPE_FOR_INTERFACE(CompositionEvent);
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://w3c.github.io/uievents/#dom-compositionevent-initcompositionevent
|
||||||
|
void CompositionEvent::init_composition_event(String const& type, bool bubbles, bool cancelable, HTML::Window* view, String const& data)
|
||||||
|
{
|
||||||
|
// Initializes attributes of a CompositionEvent 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
40
Userland/Libraries/LibWeb/UIEvents/CompositionEvent.h
Normal file
40
Userland/Libraries/LibWeb/UIEvents/CompositionEvent.h
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2024, Jamie Mansfield <jmansfield@cadixdev.org>
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <LibWeb/UIEvents/UIEvent.h>
|
||||||
|
|
||||||
|
namespace Web::UIEvents {
|
||||||
|
|
||||||
|
struct CompositionEventInit : public UIEventInit {
|
||||||
|
String data;
|
||||||
|
};
|
||||||
|
|
||||||
|
class CompositionEvent final : public UIEvent {
|
||||||
|
WEB_PLATFORM_OBJECT(CompositionEvent, UIEvent);
|
||||||
|
JS_DECLARE_ALLOCATOR(CompositionEvent);
|
||||||
|
|
||||||
|
public:
|
||||||
|
[[nodiscard]] static JS::NonnullGCPtr<CompositionEvent> create(JS::Realm&, FlyString const& event_name, CompositionEventInit const& = {});
|
||||||
|
static WebIDL::ExceptionOr<JS::NonnullGCPtr<CompositionEvent>> construct_impl(JS::Realm&, FlyString const& event_name, CompositionEventInit const& event_init);
|
||||||
|
|
||||||
|
virtual ~CompositionEvent() override;
|
||||||
|
|
||||||
|
// https://w3c.github.io/uievents/#dom-compositionevent-data
|
||||||
|
String data() const { return m_data; }
|
||||||
|
|
||||||
|
void init_composition_event(String const& type, bool bubbles, bool cancelable, HTML::Window* view, String const& data);
|
||||||
|
|
||||||
|
private:
|
||||||
|
CompositionEvent(JS::Realm&, FlyString const& event_name, CompositionEventInit const&);
|
||||||
|
|
||||||
|
virtual void initialize(JS::Realm&) override;
|
||||||
|
|
||||||
|
String m_data;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
17
Userland/Libraries/LibWeb/UIEvents/CompositionEvent.idl
Normal file
17
Userland/Libraries/LibWeb/UIEvents/CompositionEvent.idl
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
#import <UIEvents/UIEvent.idl>
|
||||||
|
|
||||||
|
// https://w3c.github.io/uievents/#compositionevent
|
||||||
|
[Exposed=Window]
|
||||||
|
interface CompositionEvent : UIEvent {
|
||||||
|
constructor(DOMString type, optional CompositionEventInit eventInitDict = {});
|
||||||
|
readonly attribute USVString data;
|
||||||
|
|
||||||
|
// https://w3c.github.io/uievents/#dom-compositionevent-initcompositionevent
|
||||||
|
// FIXME: The spec uses WindowProxy rather than Window (see https://github.com/w3c/uievents/pull/379).
|
||||||
|
undefined initCompositionEvent(DOMString typeArg, optional boolean bubblesArg = false, optional boolean cancelableArg = false, optional Window? viewArg = null, optional DOMString dataArg = "");
|
||||||
|
};
|
||||||
|
|
||||||
|
// https://w3c.github.io/uievents/#dictdef-compositioneventinit
|
||||||
|
dictionary CompositionEventInit : UIEventInit {
|
||||||
|
DOMString data = "";
|
||||||
|
};
|
|
@ -316,6 +316,7 @@ libweb_js_bindings(SVG/SVGTSpanElement)
|
||||||
libweb_js_bindings(SVG/SVGUseElement)
|
libweb_js_bindings(SVG/SVGUseElement)
|
||||||
libweb_js_bindings(Selection/Selection)
|
libweb_js_bindings(Selection/Selection)
|
||||||
libweb_js_bindings(StorageAPI/StorageManager)
|
libweb_js_bindings(StorageAPI/StorageManager)
|
||||||
|
libweb_js_bindings(UIEvents/CompositionEvent)
|
||||||
libweb_js_bindings(UIEvents/FocusEvent)
|
libweb_js_bindings(UIEvents/FocusEvent)
|
||||||
libweb_js_bindings(UIEvents/InputEvent)
|
libweb_js_bindings(UIEvents/InputEvent)
|
||||||
libweb_js_bindings(UIEvents/KeyboardEvent)
|
libweb_js_bindings(UIEvents/KeyboardEvent)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue