mirror of
https://github.com/fergalmoran/ladybird.git
synced 2025-12-22 09:19:03 +00:00
LibWeb/UIEvents: Implement InputEvent
This commit is contained in:
committed by
Andreas Kling
parent
60d9c3929c
commit
9fce70069d
@@ -7,6 +7,7 @@ source_set("UIEvents") {
|
|||||||
sources = [
|
sources = [
|
||||||
"EventNames.cpp",
|
"EventNames.cpp",
|
||||||
"FocusEvent.cpp",
|
"FocusEvent.cpp",
|
||||||
|
"InputEvent.cpp",
|
||||||
"KeyboardEvent.cpp",
|
"KeyboardEvent.cpp",
|
||||||
"MouseEvent.cpp",
|
"MouseEvent.cpp",
|
||||||
"PointerEvent.cpp",
|
"PointerEvent.cpp",
|
||||||
|
|||||||
@@ -331,6 +331,7 @@ standard_idl_files = [
|
|||||||
"//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/FocusEvent.idl",
|
"//Userland/Libraries/LibWeb/UIEvents/FocusEvent.idl",
|
||||||
|
"//Userland/Libraries/LibWeb/UIEvents/InputEvent.idl",
|
||||||
"//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",
|
||||||
|
|||||||
@@ -197,6 +197,7 @@ IdleDeadline
|
|||||||
Image
|
Image
|
||||||
ImageBitmap
|
ImageBitmap
|
||||||
ImageData
|
ImageData
|
||||||
|
InputEvent
|
||||||
Int16Array
|
Int16Array
|
||||||
Int32Array
|
Int32Array
|
||||||
Int8Array
|
Int8Array
|
||||||
|
|||||||
@@ -707,6 +707,7 @@ set(SOURCES
|
|||||||
Selection/Selection.cpp
|
Selection/Selection.cpp
|
||||||
UIEvents/EventNames.cpp
|
UIEvents/EventNames.cpp
|
||||||
UIEvents/FocusEvent.cpp
|
UIEvents/FocusEvent.cpp
|
||||||
|
UIEvents/InputEvent.cpp
|
||||||
UIEvents/KeyboardEvent.cpp
|
UIEvents/KeyboardEvent.cpp
|
||||||
UIEvents/MouseEvent.cpp
|
UIEvents/MouseEvent.cpp
|
||||||
UIEvents/PointerEvent.cpp
|
UIEvents/PointerEvent.cpp
|
||||||
|
|||||||
@@ -726,6 +726,7 @@ class SVGTitleElement;
|
|||||||
}
|
}
|
||||||
|
|
||||||
namespace Web::UIEvents {
|
namespace Web::UIEvents {
|
||||||
|
class InputEvent;
|
||||||
class KeyboardEvent;
|
class KeyboardEvent;
|
||||||
class MouseEvent;
|
class MouseEvent;
|
||||||
class PointerEvent;
|
class PointerEvent;
|
||||||
|
|||||||
36
Userland/Libraries/LibWeb/UIEvents/InputEvent.cpp
Normal file
36
Userland/Libraries/LibWeb/UIEvents/InputEvent.cpp
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2024, Jamie Mansfield <jmansfield@cadixdev.org>
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <LibWeb/Bindings/InputEventPrototype.h>
|
||||||
|
#include <LibWeb/Bindings/Intrinsics.h>
|
||||||
|
#include <LibWeb/UIEvents/InputEvent.h>
|
||||||
|
|
||||||
|
namespace Web::UIEvents {
|
||||||
|
|
||||||
|
JS_DEFINE_ALLOCATOR(InputEvent);
|
||||||
|
|
||||||
|
WebIDL::ExceptionOr<JS::NonnullGCPtr<InputEvent>> InputEvent::construct_impl(JS::Realm& realm, FlyString const& event_name, InputEventInit const& event_init)
|
||||||
|
{
|
||||||
|
return realm.heap().allocate<InputEvent>(realm, realm, event_name, event_init);
|
||||||
|
}
|
||||||
|
|
||||||
|
InputEvent::InputEvent(JS::Realm& realm, FlyString const& event_name, InputEventInit const& event_init)
|
||||||
|
: UIEvent(realm, event_name, event_init)
|
||||||
|
, m_data(event_init.data)
|
||||||
|
, m_is_composing(event_init.is_composing)
|
||||||
|
, m_input_type(event_init.input_type)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
InputEvent::~InputEvent() = default;
|
||||||
|
|
||||||
|
void InputEvent::initialize(JS::Realm& realm)
|
||||||
|
{
|
||||||
|
Base::initialize(realm);
|
||||||
|
WEB_SET_PROTOTYPE_FOR_INTERFACE(InputEvent);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
47
Userland/Libraries/LibWeb/UIEvents/InputEvent.h
Normal file
47
Userland/Libraries/LibWeb/UIEvents/InputEvent.h
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
* 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 InputEventInit : public UIEventInit {
|
||||||
|
Optional<String> data;
|
||||||
|
bool is_composing { false };
|
||||||
|
String input_type {};
|
||||||
|
};
|
||||||
|
|
||||||
|
class InputEvent final : public UIEvent {
|
||||||
|
WEB_PLATFORM_OBJECT(InputEvent, UIEvent);
|
||||||
|
JS_DECLARE_ALLOCATOR(InputEvent);
|
||||||
|
|
||||||
|
public:
|
||||||
|
static WebIDL::ExceptionOr<JS::NonnullGCPtr<InputEvent>> construct_impl(JS::Realm&, FlyString const& event_name, InputEventInit const& event_init);
|
||||||
|
|
||||||
|
virtual ~InputEvent() override;
|
||||||
|
|
||||||
|
// https://w3c.github.io/uievents/#dom-inputevent-data
|
||||||
|
Optional<String> data() const { return m_data; }
|
||||||
|
|
||||||
|
// https://w3c.github.io/uievents/#dom-inputevent-iscomposing
|
||||||
|
bool is_composing() const { return m_is_composing; }
|
||||||
|
|
||||||
|
// https://w3c.github.io/uievents/#dom-inputevent-inputtype
|
||||||
|
String input_type() const { return m_input_type; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
InputEvent(JS::Realm&, FlyString const& event_name, InputEventInit const&);
|
||||||
|
|
||||||
|
virtual void initialize(JS::Realm&) override;
|
||||||
|
|
||||||
|
Optional<String> m_data;
|
||||||
|
bool m_is_composing;
|
||||||
|
String m_input_type;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
17
Userland/Libraries/LibWeb/UIEvents/InputEvent.idl
Normal file
17
Userland/Libraries/LibWeb/UIEvents/InputEvent.idl
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
#import <UIEvents/UIEvent.idl>
|
||||||
|
|
||||||
|
// https://w3c.github.io/uievents/#inputevent
|
||||||
|
[Exposed=Window]
|
||||||
|
interface InputEvent : UIEvent {
|
||||||
|
constructor(DOMString type, optional InputEventInit eventInitDict = {});
|
||||||
|
readonly attribute USVString? data;
|
||||||
|
readonly attribute boolean isComposing;
|
||||||
|
readonly attribute DOMString inputType;
|
||||||
|
};
|
||||||
|
|
||||||
|
// https://w3c.github.io/uievents/#dictdef-inputeventinit
|
||||||
|
dictionary InputEventInit : UIEventInit {
|
||||||
|
DOMString? data = null;
|
||||||
|
boolean isComposing = false;
|
||||||
|
DOMString inputType = "";
|
||||||
|
};
|
||||||
@@ -317,6 +317,7 @@ 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/FocusEvent)
|
libweb_js_bindings(UIEvents/FocusEvent)
|
||||||
|
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)
|
||||||
|
|||||||
Reference in New Issue
Block a user