Selaa lähdekoodia

LibWeb: Add an empty DataTransferItem IDL implementation

Timothy Flynn 11 kuukautta sitten
vanhempi
commit
9e3c6921ab

+ 1 - 0
Tests/LibWeb/Text/expected/all-window-properties.txt

@@ -74,6 +74,7 @@ DOMStringList
 DOMStringMap
 DOMStringMap
 DOMTokenList
 DOMTokenList
 DataTransfer
 DataTransfer
+DataTransferItem
 DataView
 DataView
 Date
 Date
 DisposableStack
 DisposableStack

+ 1 - 0
Userland/Libraries/LibWeb/CMakeLists.txt

@@ -275,6 +275,7 @@ set(SOURCES
     HTML/CustomElements/CustomElementReactionNames.cpp
     HTML/CustomElements/CustomElementReactionNames.cpp
     HTML/CustomElements/CustomElementRegistry.cpp
     HTML/CustomElements/CustomElementRegistry.cpp
     HTML/DataTransfer.cpp
     HTML/DataTransfer.cpp
+    HTML/DataTransferItem.cpp
     HTML/Dates.cpp
     HTML/Dates.cpp
     HTML/DecodedImageData.cpp
     HTML/DecodedImageData.cpp
     HTML/DedicatedWorkerGlobalScope.cpp
     HTML/DedicatedWorkerGlobalScope.cpp

+ 1 - 0
Userland/Libraries/LibWeb/Forward.h

@@ -353,6 +353,7 @@ class CloseWatcher;
 class CloseWatcherManager;
 class CloseWatcherManager;
 class CustomElementDefinition;
 class CustomElementDefinition;
 class CustomElementRegistry;
 class CustomElementRegistry;
+class DataTransferItem;
 class DecodedImageData;
 class DecodedImageData;
 class DocumentState;
 class DocumentState;
 class DOMParser;
 class DOMParser;

+ 34 - 0
Userland/Libraries/LibWeb/HTML/DataTransferItem.cpp

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

+ 29 - 0
Userland/Libraries/LibWeb/HTML/DataTransferItem.h

@@ -0,0 +1,29 @@
+/*
+ * 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 {
+
+// https://html.spec.whatwg.org/multipage/dnd.html#the-datatransferitem-interface
+class DataTransferItem : public Bindings::PlatformObject {
+    WEB_PLATFORM_OBJECT(DataTransferItem, Bindings::PlatformObject);
+    JS_DECLARE_ALLOCATOR(DataTransferItem);
+
+public:
+    static JS::NonnullGCPtr<DataTransferItem> construct_impl(JS::Realm&);
+    virtual ~DataTransferItem() override;
+
+private:
+    DataTransferItem(JS::Realm&);
+
+    virtual void initialize(JS::Realm&) override;
+};
+
+}

+ 12 - 0
Userland/Libraries/LibWeb/HTML/DataTransferItem.idl

@@ -0,0 +1,12 @@
+#import <FileAPI/File.idl>
+
+callback FunctionStringCallback = undefined (DOMString data);
+
+// https://html.spec.whatwg.org/multipage/dnd.html#datatransferitem
+[Exposed=Window]
+interface DataTransferItem {
+    [FIXME] readonly attribute DOMString kind;
+    [FIXME] readonly attribute DOMString type;
+    [FIXME] undefined getAsString(FunctionStringCallback? _callback);
+    [FIXME] File? getAsFile();
+};

+ 1 - 0
Userland/Libraries/LibWeb/idl_files.cmake

@@ -102,6 +102,7 @@ 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/DataTransfer)
+libweb_js_bindings(HTML/DataTransferItem)
 libweb_js_bindings(HTML/DedicatedWorkerGlobalScope GLOBAL)
 libweb_js_bindings(HTML/DedicatedWorkerGlobalScope GLOBAL)
 libweb_js_bindings(HTML/DOMParser)
 libweb_js_bindings(HTML/DOMParser)
 libweb_js_bindings(HTML/DOMStringList)
 libweb_js_bindings(HTML/DOMStringList)