mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-29 04:09:13 +00:00
LibWeb/HTML: Implement DataTransferItem.webkitGetAsEntry()
This commit is contained in:
parent
169163b002
commit
2e9aec984c
Notes:
github-actions[bot]
2024-08-24 12:54:04 +00:00
Author: https://github.com/jamierocks
Commit: 2e9aec984c
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1172
Reviewed-by: https://github.com/trflynn89
5 changed files with 34 additions and 0 deletions
|
@ -7,3 +7,4 @@ stringItemAsString: data=well hello friends
|
||||||
fileItem: kind=file, type=text/plain
|
fileItem: kind=file, type=text/plain
|
||||||
length=2, types=custom-type,Files
|
length=2, types=custom-type,Files
|
||||||
fileItemAsFile: name=file.txt, type=text/plain
|
fileItemAsFile: name=file.txt, type=text/plain
|
||||||
|
fileItemAsEntry: name=file.txt, file=true, directory=false
|
||||||
|
|
|
@ -40,6 +40,9 @@
|
||||||
let fileItemAsFile = fileItem.getAsFile();
|
let fileItemAsFile = fileItem.getAsFile();
|
||||||
println(`fileItemAsFile: name=${fileItemAsFile.name}, type=${fileItemAsFile.type}`);
|
println(`fileItemAsFile: name=${fileItemAsFile.name}, type=${fileItemAsFile.type}`);
|
||||||
|
|
||||||
|
let fileItemAsEntry = fileItem.webkitGetAsEntry();
|
||||||
|
println(`fileItemAsEntry: name=${fileItemAsEntry.name}, file=${fileItemAsEntry.isFile}, directory=${fileItemAsEntry.isDirectory}`);
|
||||||
|
|
||||||
if (dataTransferItemList[1] !== fileItem) {
|
if (dataTransferItemList[1] !== fileItem) {
|
||||||
println("FAILED");
|
println("FAILED");
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2024, Tim Flynn <trflynn89@serenityos.org>
|
* Copyright (c) 2024, Tim Flynn <trflynn89@serenityos.org>
|
||||||
|
* Copyright (c) 2024, Jamie Mansfield <jmansfield@cadixdev.org>
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
@ -148,4 +149,26 @@ JS::GCPtr<FileAPI::File> DataTransferItem::get_as_file() const
|
||||||
return MUST(FileAPI::File::create(realm, { JS::make_handle(blob) }, file_name, move(options)));
|
return MUST(FileAPI::File::create(realm, { JS::make_handle(blob) }, file_name, move(options)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://wicg.github.io/entries-api/#dom-datatransferitem-webkitgetasentry
|
||||||
|
JS::GCPtr<EntriesAPI::FileSystemEntry> DataTransferItem::webkit_get_as_entry() const
|
||||||
|
{
|
||||||
|
auto& realm = this->realm();
|
||||||
|
|
||||||
|
// 1. Let store be this's DataTransfer object’s drag data store.
|
||||||
|
|
||||||
|
// 2. If store’s drag data store mode is not read/write mode or read-only mode, return null and abort these steps
|
||||||
|
if (mode() != DragDataStore::Mode::ReadWrite && mode() != DragDataStore::Mode::ReadOnly)
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
// 3. Let item be the item in store’s drag data store item list that this represents.
|
||||||
|
auto const& item = m_data_transfer->drag_data(*m_item_index);
|
||||||
|
|
||||||
|
// 4. If item’s kind is not File, then return null and abort these steps.
|
||||||
|
if (item.kind != DragDataStoreItem::Kind::File)
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
// 5. Return a new FileSystemEntry object representing the entry.
|
||||||
|
return EntriesAPI::FileSystemEntry::create(realm, EntriesAPI::EntryType::File, item.file_name);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#include <AK/Optional.h>
|
#include <AK/Optional.h>
|
||||||
#include <LibJS/Forward.h>
|
#include <LibJS/Forward.h>
|
||||||
#include <LibWeb/Bindings/PlatformObject.h>
|
#include <LibWeb/Bindings/PlatformObject.h>
|
||||||
|
#include <LibWeb/EntriesAPI/FileSystemEntry.h>
|
||||||
#include <LibWeb/HTML/DragDataStore.h>
|
#include <LibWeb/HTML/DragDataStore.h>
|
||||||
|
|
||||||
namespace Web::HTML {
|
namespace Web::HTML {
|
||||||
|
@ -28,6 +29,8 @@ public:
|
||||||
void get_as_string(JS::GCPtr<WebIDL::CallbackType>) const;
|
void get_as_string(JS::GCPtr<WebIDL::CallbackType>) const;
|
||||||
JS::GCPtr<FileAPI::File> get_as_file() const;
|
JS::GCPtr<FileAPI::File> get_as_file() const;
|
||||||
|
|
||||||
|
JS::GCPtr<EntriesAPI::FileSystemEntry> webkit_get_as_entry() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DataTransferItem(JS::Realm&, JS::NonnullGCPtr<DataTransfer>, size_t item_index);
|
DataTransferItem(JS::Realm&, JS::NonnullGCPtr<DataTransfer>, size_t item_index);
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
#import <EntriesAPI/FileSystemEntry.idl>
|
||||||
#import <FileAPI/File.idl>
|
#import <FileAPI/File.idl>
|
||||||
|
|
||||||
callback FunctionStringCallback = undefined (DOMString data);
|
callback FunctionStringCallback = undefined (DOMString data);
|
||||||
|
@ -9,4 +10,7 @@ interface DataTransferItem {
|
||||||
readonly attribute DOMString type;
|
readonly attribute DOMString type;
|
||||||
undefined getAsString(FunctionStringCallback? _callback);
|
undefined getAsString(FunctionStringCallback? _callback);
|
||||||
File? getAsFile();
|
File? getAsFile();
|
||||||
|
|
||||||
|
// https://wicg.github.io/entries-api/#dom-datatransferitem-webkitgetasentry
|
||||||
|
FileSystemEntry? webkitGetAsEntry();
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue