mirror of
https://github.com/fergalmoran/ladybird.git
synced 2025-12-22 09:19:03 +00:00
LibWeb: Implement HTML DragEvent class
This just defines the class, drag events aren't actually fired yet.
This commit is contained in:
@@ -44,6 +44,7 @@ static bool is_platform_object(Type const& type)
|
|||||||
"CanvasRenderingContext2D"sv,
|
"CanvasRenderingContext2D"sv,
|
||||||
"CloseWatcher"sv,
|
"CloseWatcher"sv,
|
||||||
"CryptoKey"sv,
|
"CryptoKey"sv,
|
||||||
|
"DataTransfer"sv,
|
||||||
"Document"sv,
|
"Document"sv,
|
||||||
"DocumentType"sv,
|
"DocumentType"sv,
|
||||||
"DOMRectReadOnly"sv,
|
"DOMRectReadOnly"sv,
|
||||||
|
|||||||
@@ -76,6 +76,7 @@ Document
|
|||||||
DocumentFragment
|
DocumentFragment
|
||||||
DocumentTimeline
|
DocumentTimeline
|
||||||
DocumentType
|
DocumentType
|
||||||
|
DragEvent
|
||||||
DynamicsCompressorNode
|
DynamicsCompressorNode
|
||||||
Element
|
Element
|
||||||
ElementInternals
|
ElementInternals
|
||||||
|
|||||||
@@ -267,12 +267,13 @@ set(SOURCES
|
|||||||
HTML/CustomElements/CustomElementName.cpp
|
HTML/CustomElements/CustomElementName.cpp
|
||||||
HTML/CustomElements/CustomElementReactionNames.cpp
|
HTML/CustomElements/CustomElementReactionNames.cpp
|
||||||
HTML/CustomElements/CustomElementRegistry.cpp
|
HTML/CustomElements/CustomElementRegistry.cpp
|
||||||
|
HTML/DataTransfer.cpp
|
||||||
HTML/Dates.cpp
|
HTML/Dates.cpp
|
||||||
HTML/DecodedImageData.cpp
|
HTML/DecodedImageData.cpp
|
||||||
HTML/DocumentState.cpp
|
HTML/DocumentState.cpp
|
||||||
HTML/DOMParser.cpp
|
HTML/DOMParser.cpp
|
||||||
HTML/DOMStringMap.cpp
|
HTML/DOMStringMap.cpp
|
||||||
HTML/DataTransfer.cpp
|
HTML/DragEvent.cpp
|
||||||
HTML/ElementInternals.cpp
|
HTML/ElementInternals.cpp
|
||||||
HTML/ErrorEvent.cpp
|
HTML/ErrorEvent.cpp
|
||||||
HTML/EventHandler.cpp
|
HTML/EventHandler.cpp
|
||||||
|
|||||||
@@ -355,6 +355,7 @@ class DecodedImageData;
|
|||||||
class DocumentState;
|
class DocumentState;
|
||||||
class DOMParser;
|
class DOMParser;
|
||||||
class DOMStringMap;
|
class DOMStringMap;
|
||||||
|
class DragEvent;
|
||||||
class ElementInternals;
|
class ElementInternals;
|
||||||
class ErrorEvent;
|
class ErrorEvent;
|
||||||
class EventHandler;
|
class EventHandler;
|
||||||
|
|||||||
39
Userland/Libraries/LibWeb/HTML/DragEvent.cpp
Normal file
39
Userland/Libraries/LibWeb/HTML/DragEvent.cpp
Normal 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
41
Userland/Libraries/LibWeb/HTML/DragEvent.h
Normal file
41
Userland/Libraries/LibWeb/HTML/DragEvent.h
Normal 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;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
14
Userland/Libraries/LibWeb/HTML/DragEvent.idl
Normal file
14
Userland/Libraries/LibWeb/HTML/DragEvent.idl
Normal 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;
|
||||||
|
};
|
||||||
@@ -100,9 +100,10 @@ libweb_js_bindings(HTML/CanvasRenderingContext2D)
|
|||||||
libweb_js_bindings(HTML/CloseEvent)
|
libweb_js_bindings(HTML/CloseEvent)
|
||||||
libweb_js_bindings(HTML/CloseWatcher)
|
libweb_js_bindings(HTML/CloseWatcher)
|
||||||
libweb_js_bindings(HTML/CustomElements/CustomElementRegistry)
|
libweb_js_bindings(HTML/CustomElements/CustomElementRegistry)
|
||||||
|
libweb_js_bindings(HTML/DataTransfer)
|
||||||
libweb_js_bindings(HTML/DOMParser)
|
libweb_js_bindings(HTML/DOMParser)
|
||||||
libweb_js_bindings(HTML/DOMStringMap)
|
libweb_js_bindings(HTML/DOMStringMap)
|
||||||
libweb_js_bindings(HTML/DataTransfer)
|
libweb_js_bindings(HTML/DragEvent)
|
||||||
libweb_js_bindings(HTML/ElementInternals)
|
libweb_js_bindings(HTML/ElementInternals)
|
||||||
libweb_js_bindings(HTML/ErrorEvent)
|
libweb_js_bindings(HTML/ErrorEvent)
|
||||||
libweb_js_bindings(HTML/EventSource)
|
libweb_js_bindings(HTML/EventSource)
|
||||||
|
|||||||
Reference in New Issue
Block a user