LibWeb: Implement the DataTransferItemList indexed getter

This commit is contained in:
Timothy Flynn 2024-08-21 10:04:16 -04:00 committed by Andreas Kling
parent 843f8f04a5
commit ceb9e30d42
Notes: github-actions[bot] 2024-08-22 12:22:27 +00:00
6 changed files with 36 additions and 1 deletions

View file

@ -9,6 +9,7 @@
#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/FileAPI/File.h>
#include <LibWeb/HTML/DataTransfer.h>
#include <LibWeb/HTML/DataTransferItem.h>
#include <LibWeb/HTML/DataTransferItemList.h>
#include <LibWeb/Infra/Strings.h>
@ -25,6 +26,7 @@ DataTransferItemList::DataTransferItemList(JS::Realm& realm, JS::NonnullGCPtr<Da
: PlatformObject(realm)
, m_data_transfer(data_transfer)
{
m_legacy_platform_object_flags = LegacyPlatformObjectFlags { .supports_indexed_properties = true };
}
DataTransferItemList::~DataTransferItemList() = default;
@ -108,4 +110,16 @@ JS::GCPtr<DataTransferItem> DataTransferItemList::add(JS::NonnullGCPtr<FileAPI::
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 {};
}
}