1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 06:04:57 +00:00

LibWeb: Add an empty DataTransfer IDL implementation

This does not implement any of the IDL methods, but GitHub requires the
interface exists to upload files via an <input type="file"> element.
Their JS handles uploads via this element and via drag-and-drop in one
function, and check if the uploaded file is `instanceof DataTransfer` to
decide how to handle it.
This commit is contained in:
Timothy Flynn 2024-03-13 15:35:39 -04:00 committed by Andreas Kling
parent 7681772b9f
commit c2ef506b4a
7 changed files with 84 additions and 0 deletions

View file

@ -24,6 +24,7 @@ source_set("HTML") {
"CloseEvent.cpp",
"DOMParser.cpp",
"DOMStringMap.cpp",
"DataTransfer.cpp",
"Dates.cpp",
"DecodedImageData.cpp",
"DocumentState.cpp",

View file

@ -113,6 +113,7 @@ standard_idl_files = [
"//Userland/Libraries/LibWeb/HTML/CustomElements/CustomElementRegistry.idl",
"//Userland/Libraries/LibWeb/HTML/DOMParser.idl",
"//Userland/Libraries/LibWeb/HTML/DOMStringMap.idl",
"//Userland/Libraries/LibWeb/HTML/DataTransfer.idl",
"//Userland/Libraries/LibWeb/HTML/ErrorEvent.idl",
"//Userland/Libraries/LibWeb/HTML/FormDataEvent.idl",
"//Userland/Libraries/LibWeb/HTML/History.idl",

View file

@ -260,6 +260,7 @@ set(SOURCES
HTML/DocumentState.cpp
HTML/DOMParser.cpp
HTML/DOMStringMap.cpp
HTML/DataTransfer.cpp
HTML/ErrorEvent.cpp
HTML/EventHandler.cpp
HTML/EventLoop/EventLoop.cpp

View file

@ -0,0 +1,33 @@
/*
* Copyright (c) 2024, Tim Flynn <trflynn89@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibJS/Runtime/Realm.h>
#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/HTML/DataTransfer.h>
namespace Web::HTML {
JS_DEFINE_ALLOCATOR(DataTransfer);
JS::NonnullGCPtr<DataTransfer> DataTransfer::construct_impl(JS::Realm& realm)
{
return realm.heap().allocate<DataTransfer>(realm, realm);
}
DataTransfer::DataTransfer(JS::Realm& realm)
: PlatformObject(realm)
{
}
DataTransfer::~DataTransfer() = default;
void DataTransfer::initialize(JS::Realm& realm)
{
Base::initialize(realm);
set_prototype(&Bindings::ensure_web_prototype<Bindings::DataTransferPrototype>(realm, "DataTransfer"_fly_string));
}
}

View file

@ -0,0 +1,28 @@
/*
* Copyright (c) 2024, Tim Flynn <trflynn89@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibJS/Forward.h>
#include <LibWeb/Bindings/PlatformObject.h>
namespace Web::HTML {
class DataTransfer : public Bindings::PlatformObject {
WEB_PLATFORM_OBJECT(DataTransfer, Bindings::PlatformObject);
JS_DECLARE_ALLOCATOR(DataTransfer);
public:
static JS::NonnullGCPtr<DataTransfer> construct_impl(JS::Realm&);
virtual ~DataTransfer() override;
private:
DataTransfer(JS::Realm&);
virtual void initialize(JS::Realm&) override;
};
}

View file

@ -0,0 +1,19 @@
// https://html.spec.whatwg.org/multipage/dnd.html#datatransfer
[Exposed=Window]
interface DataTransfer {
constructor();
// FIXME: attribute DOMString dropEffect;
// FIXME: attribute DOMString effectAllowed;
// FIXME: [SameObject] readonly attribute DataTransferItemList items;
// FIXME: undefined setDragImage(Element image, long x, long y);
// old interface
// FIXME: readonly attribute FrozenArray<DOMString> types;
// FIXME: DOMString getData(DOMString format);
// FIXME: undefined setData(DOMString format, DOMString data);
// FIXME: undefined clearData(optional DOMString format);
// FIXME: [SameObject] readonly attribute FileList files;
};

View file

@ -97,6 +97,7 @@ libweb_js_bindings(HTML/CloseEvent)
libweb_js_bindings(HTML/CustomElements/CustomElementRegistry)
libweb_js_bindings(HTML/DOMParser)
libweb_js_bindings(HTML/DOMStringMap)
libweb_js_bindings(HTML/DataTransfer)
libweb_js_bindings(HTML/ErrorEvent)
libweb_js_bindings(HTML/FormDataEvent)
libweb_js_bindings(HTML/History)