diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp b/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp index 5af3d976bfe..c6ab4f25766 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp @@ -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, diff --git a/Tests/LibWeb/Text/expected/all-window-properties.txt b/Tests/LibWeb/Text/expected/all-window-properties.txt index 0890ce11ffc..c93511af9a1 100644 --- a/Tests/LibWeb/Text/expected/all-window-properties.txt +++ b/Tests/LibWeb/Text/expected/all-window-properties.txt @@ -76,6 +76,7 @@ Document DocumentFragment DocumentTimeline DocumentType +DragEvent DynamicsCompressorNode Element ElementInternals diff --git a/Userland/Libraries/LibWeb/CMakeLists.txt b/Userland/Libraries/LibWeb/CMakeLists.txt index 44b4cbe81ff..1fddaa780b7 100644 --- a/Userland/Libraries/LibWeb/CMakeLists.txt +++ b/Userland/Libraries/LibWeb/CMakeLists.txt @@ -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 diff --git a/Userland/Libraries/LibWeb/Forward.h b/Userland/Libraries/LibWeb/Forward.h index 194f9449cec..ff8f4ffacb3 100644 --- a/Userland/Libraries/LibWeb/Forward.h +++ b/Userland/Libraries/LibWeb/Forward.h @@ -355,6 +355,7 @@ class DecodedImageData; class DocumentState; class DOMParser; class DOMStringMap; +class DragEvent; class ElementInternals; class ErrorEvent; class EventHandler; diff --git a/Userland/Libraries/LibWeb/HTML/DragEvent.cpp b/Userland/Libraries/LibWeb/HTML/DragEvent.cpp new file mode 100644 index 00000000000..da89bd2a8c9 --- /dev/null +++ b/Userland/Libraries/LibWeb/HTML/DragEvent.cpp @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024, Maciej + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include +#include +#include + +namespace Web::HTML { + +JS_DEFINE_ALLOCATOR(DragEvent); + +JS::NonnullGCPtr 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(realm, realm, event_name, event_init, page_x, page_y, offset_x, offset_y); +} + +WebIDL::ExceptionOr> 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); +} + +} diff --git a/Userland/Libraries/LibWeb/HTML/DragEvent.h b/Userland/Libraries/LibWeb/HTML/DragEvent.h new file mode 100644 index 00000000000..a4522ff0eaa --- /dev/null +++ b/Userland/Libraries/LibWeb/HTML/DragEvent.h @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024, Maciej + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include +#include +#include +#include + +namespace Web::HTML { + +struct DragEventInit : public UIEvents::MouseEventInit { + JS::GCPtr 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 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> construct_impl(JS::Realm&, FlyString const& event_name, DragEventInit const& event_init); + + virtual ~DragEvent() override; + + JS::GCPtr 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 m_data_transfer; +}; + +} diff --git a/Userland/Libraries/LibWeb/HTML/DragEvent.idl b/Userland/Libraries/LibWeb/HTML/DragEvent.idl new file mode 100644 index 00000000000..cb442d53cfa --- /dev/null +++ b/Userland/Libraries/LibWeb/HTML/DragEvent.idl @@ -0,0 +1,14 @@ +#import +#import + +// 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; +}; diff --git a/Userland/Libraries/LibWeb/idl_files.cmake b/Userland/Libraries/LibWeb/idl_files.cmake index 21590d1f944..58746b7c66a 100644 --- a/Userland/Libraries/LibWeb/idl_files.cmake +++ b/Userland/Libraries/LibWeb/idl_files.cmake @@ -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)