-
-
Notifications
You must be signed in to change notification settings - Fork 980
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LibWeb/UIEvents: Implement CompositionEvent
- Loading branch information
1 parent
3a08dbe
commit d04d658
Showing
10 changed files
with
123 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,6 +51,7 @@ Clipboard | |
CloseEvent | ||
CloseWatcher | ||
Comment | ||
CompositionEvent | ||
CountQueuingStrategy | ||
Crypto | ||
CryptoKey | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = ""; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters