LibWeb: Implement HTML DragEvent class

This just defines the class, drag events aren't actually fired yet.
This commit is contained in:
Maciej 2024-07-08 18:33:12 +02:00 committed by Tim Ledbetter
parent 34cd0cfa2e
commit 65d8d205ee
Notes: sideshowbarker 2024-07-17 05:58:46 +09:00
8 changed files with 101 additions and 2 deletions

View file

@ -44,6 +44,7 @@ static bool is_platform_object(Type const& type)
"CanvasRenderingContext2D"sv,
"CloseWatcher"sv,
"CryptoKey"sv,
"DataTransfer"sv,
"Document"sv,
"DocumentType"sv,
"DOMRectReadOnly"sv,

View file

@ -76,6 +76,7 @@ Document
DocumentFragment
DocumentTimeline
DocumentType
DragEvent
DynamicsCompressorNode
Element
ElementInternals

View file

@ -267,12 +267,13 @@ set(SOURCES
HTML/CustomElements/CustomElementName.cpp
HTML/CustomElements/CustomElementReactionNames.cpp
HTML/CustomElements/CustomElementRegistry.cpp
HTML/DataTransfer.cpp
HTML/Dates.cpp
HTML/DecodedImageData.cpp
HTML/DocumentState.cpp
HTML/DOMParser.cpp
HTML/DOMStringMap.cpp
HTML/DataTransfer.cpp
HTML/DragEvent.cpp
HTML/ElementInternals.cpp
HTML/ErrorEvent.cpp
HTML/EventHandler.cpp

View file

@ -355,6 +355,7 @@ class DecodedImageData;
class DocumentState;
class DOMParser;
class DOMStringMap;
class DragEvent;
class ElementInternals;
class ErrorEvent;
class EventHandler;

View file

@ -0,0 +1,39 @@
/*
* Copyright (c) 2024, Maciej <sppmacd@pm.me>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/Bindings/DragEventPrototype.h>
#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/HTML/DragEvent.h>
namespace Web::HTML {
JS_DEFINE_ALLOCATOR(DragEvent);
JS::NonnullGCPtr<DragEvent> DragEvent::create(JS::Realm& realm, FlyString const& event_name, DragEventInit const& event_init, double page_x, double page_y, double offset_x, double offset_y)
{
return realm.heap().allocate<DragEvent>(realm, realm, event_name, event_init, page_x, page_y, offset_x, offset_y);
}
WebIDL::ExceptionOr<JS::NonnullGCPtr<DragEvent>> DragEvent::construct_impl(JS::Realm& realm, FlyString const& event_name, DragEventInit const& event_init)
{
return create(realm, event_name, event_init);
}
DragEvent::DragEvent(JS::Realm& realm, FlyString const& event_name, DragEventInit const& event_init, double page_x, double page_y, double offset_x, double offset_y)
: MouseEvent(realm, event_name, event_init, page_x, page_y, offset_x, offset_y)
, m_data_transfer(event_init.data_transfer)
{
}
DragEvent::~DragEvent() = default;
void DragEvent::initialize(JS::Realm& realm)
{
Base::initialize(realm);
WEB_SET_PROTOTYPE_FOR_INTERFACE(DragEvent);
}
}

View file

@ -0,0 +1,41 @@
/*
* Copyright (c) 2024, Maciej <sppmacd@pm.me>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/FlyString.h>
#include <LibWeb/DOM/Event.h>
#include <LibWeb/HTML/DataTransfer.h>
#include <LibWeb/UIEvents/MouseEvent.h>
namespace Web::HTML {
struct DragEventInit : public UIEvents::MouseEventInit {
JS::GCPtr<DataTransfer> data_transfer;
};
// https://html.spec.whatwg.org/multipage/dnd.html#the-dragevent-interface
class DragEvent : public UIEvents::MouseEvent {
WEB_PLATFORM_OBJECT(DragEvent, UIEvents::MouseEvent);
JS_DECLARE_ALLOCATOR(DragEvent);
public:
[[nodiscard]] static JS::NonnullGCPtr<DragEvent> create(JS::Realm&, FlyString const& event_name, DragEventInit const& event_init = {}, double page_x = 0, double page_y = 0, double offset_x = 0, double offset_y = 0);
static WebIDL::ExceptionOr<JS::NonnullGCPtr<DragEvent>> construct_impl(JS::Realm&, FlyString const& event_name, DragEventInit const& event_init);
virtual ~DragEvent() override;
JS::GCPtr<DataTransfer> data_transfer() { return m_data_transfer; }
private:
DragEvent(JS::Realm&, FlyString const& event_name, DragEventInit const& event_init, double page_x, double page_y, double offset_x, double offset_y);
virtual void initialize(JS::Realm&) override;
JS::GCPtr<DataTransfer> m_data_transfer;
};
}

View file

@ -0,0 +1,14 @@
#import <UIEvents/MouseEvent.idl>
#import <HTML/DataTransfer.idl>
// https://html.spec.whatwg.org/multipage/dnd.html#the-dragevent-interface
[Exposed=Window]
interface DragEvent : MouseEvent {
constructor(DOMString type, optional DragEventInit eventInitDict = {});
readonly attribute DataTransfer? dataTransfer;
};
dictionary DragEventInit : MouseEventInit {
DataTransfer? dataTransfer = null;
};

View file

@ -100,9 +100,10 @@ libweb_js_bindings(HTML/CanvasRenderingContext2D)
libweb_js_bindings(HTML/CloseEvent)
libweb_js_bindings(HTML/CloseWatcher)
libweb_js_bindings(HTML/CustomElements/CustomElementRegistry)
libweb_js_bindings(HTML/DataTransfer)
libweb_js_bindings(HTML/DOMParser)
libweb_js_bindings(HTML/DOMStringMap)
libweb_js_bindings(HTML/DataTransfer)
libweb_js_bindings(HTML/DragEvent)
libweb_js_bindings(HTML/ElementInternals)
libweb_js_bindings(HTML/ErrorEvent)
libweb_js_bindings(HTML/EventSource)