Skip to content

Commit

Permalink
LibWeb/UIEvents: Implement CompositionEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
jamierocks committed Jul 18, 2024
1 parent 3a08dbe commit d04d658
Show file tree
Hide file tree
Showing 10 changed files with 123 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ source_set("UIEvents") {
"//Userland/", # For LibGUI needing WindowServer types
]
sources = [
"CompositionEvent.cpp",
"EventNames.cpp",
"FocusEvent.cpp",
"InputEvent.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 @@ -306,6 +306,7 @@ standard_idl_files = [
"//Userland/Libraries/LibWeb/SVG/SVGTransformList.idl",
"//Userland/Libraries/LibWeb/SVG/SVGTSpanElement.idl",
"//Userland/Libraries/LibWeb/SVG/SVGUseElement.idl",
"//Userland/Libraries/LibWeb/UIEvents/CompositionEvent.idl",
"//Userland/Libraries/LibWeb/UIEvents/FocusEvent.idl",
"//Userland/Libraries/LibWeb/UIEvents/InputEvent.idl",
"//Userland/Libraries/LibWeb/UIEvents/KeyboardEvent.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 @@ -51,6 +51,7 @@ Clipboard
CloseEvent
CloseWatcher
Comment
CompositionEvent
CountQueuingStrategy
Crypto
CryptoKey
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 @@ -666,6 +666,7 @@ set(SOURCES
SVG/TagNames.cpp
SVG/ViewBox.cpp
Selection/Selection.cpp
UIEvents/CompositionEvent.cpp
UIEvents/EventNames.cpp
UIEvents/FocusEvent.cpp
UIEvents/InputEvent.cpp
Expand Down
5 changes: 3 additions & 2 deletions Userland/Libraries/LibWeb/DOM/Document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@
#include <LibWeb/SVG/SVGTitleElement.h>
#include <LibWeb/SVG/TagNames.h>
#include <LibWeb/Selection/Selection.h>
#include <LibWeb/UIEvents/CompositionEvent.h>
#include <LibWeb/UIEvents/EventNames.h>
#include <LibWeb/UIEvents/FocusEvent.h>
#include <LibWeb/UIEvents/KeyboardEvent.h>
Expand Down Expand Up @@ -1678,7 +1679,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<Event>> Document::create_event(StringView i
if (Infra::is_ascii_case_insensitive_match(interface, "beforeunloadevent"sv)) {
event = Event::create(realm, FlyString {}); // FIXME: Create BeforeUnloadEvent
} 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)) {
event = CustomEvent::create(realm, FlyString {});
} else if (Infra::is_ascii_case_insensitive_match(interface, "devicemotionevent"sv)) {
Expand Down Expand Up @@ -1708,7 +1709,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 CompositionEvent
event = Event::create(realm, FlyString {}); // FIXME: Create TextEvent
} 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 @@ -684,6 +684,7 @@ class SVGTitleElement;
}

namespace Web::UIEvents {
class CompositionEvent;
class InputEvent;
class KeyboardEvent;
class MouseEvent;
Expand Down
57 changes: 57 additions & 0 deletions Userland/Libraries/LibWeb/UIEvents/CompositionEvent.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright (c) 2024, Jamie Mansfield <[email protected]>
*
* 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 changes: 40 additions & 0 deletions Userland/Libraries/LibWeb/UIEvents/CompositionEvent.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright (c) 2024, Jamie Mansfield <[email protected]>
*
* 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 changes: 17 additions & 0 deletions Userland/Libraries/LibWeb/UIEvents/CompositionEvent.idl
Original file line number Diff line number Diff line change
@@ -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 (spec bug?).
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 = "";
};
1 change: 1 addition & 0 deletions Userland/Libraries/LibWeb/idl_files.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ libweb_js_bindings(SVG/SVGTransformList)
libweb_js_bindings(SVG/SVGTSpanElement)
libweb_js_bindings(SVG/SVGUseElement)
libweb_js_bindings(Selection/Selection)
libweb_js_bindings(UIEvents/CompositionEvent)
libweb_js_bindings(UIEvents/FocusEvent)
libweb_js_bindings(UIEvents/InputEvent)
libweb_js_bindings(UIEvents/KeyboardEvent)
Expand Down

0 comments on commit d04d658

Please sign in to comment.