mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-05-11 21:52:53 +00:00
LibWeb: Implement the DataTransferItemList indexed getter
This commit is contained in:
parent
843f8f04a5
commit
ceb9e30d42
Notes:
github-actions[bot]
2024-08-22 12:22:27 +00:00
Author: https://github.com/trflynn89
Commit: ceb9e30d42
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1158
Reviewed-by: https://github.com/shannonbooth
6 changed files with 36 additions and 1 deletions
|
@ -12,6 +12,10 @@
|
||||||
println(`stringItem: ${stringItem}`);
|
println(`stringItem: ${stringItem}`);
|
||||||
println(`length=${dataTransferItemList.length}, types=${dataTransfer.types}`);
|
println(`length=${dataTransferItemList.length}, types=${dataTransfer.types}`);
|
||||||
|
|
||||||
|
if (dataTransferItemList[0] !== stringItem) {
|
||||||
|
println("FAILED");
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
dataTransferItemList.add("well hello friends", "custom-type");
|
dataTransferItemList.add("well hello friends", "custom-type");
|
||||||
println("FAILED");
|
println("FAILED");
|
||||||
|
@ -24,5 +28,13 @@
|
||||||
let fileItem = dataTransferItemList.add(file);
|
let fileItem = dataTransferItemList.add(file);
|
||||||
println(`fileItem: ${fileItem}`);
|
println(`fileItem: ${fileItem}`);
|
||||||
println(`length=${dataTransferItemList.length}, types=${dataTransfer.types}`);
|
println(`length=${dataTransferItemList.length}, types=${dataTransfer.types}`);
|
||||||
|
|
||||||
|
if (dataTransferItemList[1] !== fileItem) {
|
||||||
|
println("FAILED");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dataTransferItemList[2] !== undefined) {
|
||||||
|
println("FAILED");
|
||||||
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -260,6 +260,12 @@ bool DataTransfer::contains_item_with_type(DragDataStoreItem::Kind kind, String
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JS::NonnullGCPtr<DataTransferItem> DataTransfer::item(size_t index) const
|
||||||
|
{
|
||||||
|
VERIFY(index < m_item_list.size());
|
||||||
|
return m_item_list[index];
|
||||||
|
}
|
||||||
|
|
||||||
size_t DataTransfer::length() const
|
size_t DataTransfer::length() const
|
||||||
{
|
{
|
||||||
if (m_associated_drag_data_store)
|
if (m_associated_drag_data_store)
|
||||||
|
|
|
@ -61,6 +61,7 @@ public:
|
||||||
|
|
||||||
JS::NonnullGCPtr<DataTransferItem> add_item(DragDataStoreItem item);
|
JS::NonnullGCPtr<DataTransferItem> add_item(DragDataStoreItem item);
|
||||||
bool contains_item_with_type(DragDataStoreItem::Kind, String const& type) const;
|
bool contains_item_with_type(DragDataStoreItem::Kind, String const& type) const;
|
||||||
|
JS::NonnullGCPtr<DataTransferItem> item(size_t index) const;
|
||||||
size_t length() const;
|
size_t length() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#include <LibWeb/Bindings/Intrinsics.h>
|
#include <LibWeb/Bindings/Intrinsics.h>
|
||||||
#include <LibWeb/FileAPI/File.h>
|
#include <LibWeb/FileAPI/File.h>
|
||||||
#include <LibWeb/HTML/DataTransfer.h>
|
#include <LibWeb/HTML/DataTransfer.h>
|
||||||
|
#include <LibWeb/HTML/DataTransferItem.h>
|
||||||
#include <LibWeb/HTML/DataTransferItemList.h>
|
#include <LibWeb/HTML/DataTransferItemList.h>
|
||||||
#include <LibWeb/Infra/Strings.h>
|
#include <LibWeb/Infra/Strings.h>
|
||||||
|
|
||||||
|
@ -25,6 +26,7 @@ DataTransferItemList::DataTransferItemList(JS::Realm& realm, JS::NonnullGCPtr<Da
|
||||||
: PlatformObject(realm)
|
: PlatformObject(realm)
|
||||||
, m_data_transfer(data_transfer)
|
, m_data_transfer(data_transfer)
|
||||||
{
|
{
|
||||||
|
m_legacy_platform_object_flags = LegacyPlatformObjectFlags { .supports_indexed_properties = true };
|
||||||
}
|
}
|
||||||
|
|
||||||
DataTransferItemList::~DataTransferItemList() = default;
|
DataTransferItemList::~DataTransferItemList() = default;
|
||||||
|
@ -108,4 +110,16 @@ JS::GCPtr<DataTransferItem> DataTransferItemList::add(JS::NonnullGCPtr<FileAPI::
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/multipage/dnd.html#dom-datatransferitemlist-item
|
||||||
|
Optional<JS::Value> DataTransferItemList::item_value(size_t index) const
|
||||||
|
{
|
||||||
|
// To determine the value of an indexed property i of a DataTransferItemList object, the user agent must return a
|
||||||
|
// DataTransferItem object representing the ith item in the drag data store. The same object must be returned each
|
||||||
|
// time a particular item is obtained from this DataTransferItemList object. The DataTransferItem object must be
|
||||||
|
// associated with the same DataTransfer object as the DataTransferItemList object when it is first created.
|
||||||
|
if (index < m_data_transfer->length())
|
||||||
|
return m_data_transfer->item(index);
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,6 +33,8 @@ private:
|
||||||
virtual void initialize(JS::Realm&) override;
|
virtual void initialize(JS::Realm&) override;
|
||||||
virtual void visit_edges(JS::Cell::Visitor&) override;
|
virtual void visit_edges(JS::Cell::Visitor&) override;
|
||||||
|
|
||||||
|
virtual Optional<JS::Value> item_value(size_t index) const override;
|
||||||
|
|
||||||
JS::NonnullGCPtr<DataTransfer> m_data_transfer;
|
JS::NonnullGCPtr<DataTransfer> m_data_transfer;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
[Exposed=Window]
|
[Exposed=Window]
|
||||||
interface DataTransferItemList {
|
interface DataTransferItemList {
|
||||||
readonly attribute unsigned long length;
|
readonly attribute unsigned long length;
|
||||||
[FIXME] getter DataTransferItem (unsigned long index);
|
getter DataTransferItem (unsigned long index);
|
||||||
DataTransferItem? add(DOMString data, DOMString type);
|
DataTransferItem? add(DOMString data, DOMString type);
|
||||||
DataTransferItem? add(File data);
|
DataTransferItem? add(File data);
|
||||||
[FIXME] undefined remove(unsigned long index);
|
[FIXME] undefined remove(unsigned long index);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue