mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-21 09:41:53 +00:00
LibWeb: Implement DataTransferItemList.prototype.add()
This commit is contained in:
parent
b3bfd02e64
commit
74d9cfbf2a
Notes:
github-actions[bot]
2024-08-22 12:22:38 +00:00
Author: https://github.com/trflynn89
Commit: 74d9cfbf2a
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1158
Reviewed-by: https://github.com/shannonbooth
8 changed files with 126 additions and 3 deletions
|
@ -220,12 +220,46 @@ JS::NonnullGCPtr<FileAPI::FileList> DataTransfer::files() const
|
|||
return files;
|
||||
}
|
||||
|
||||
Optional<DragDataStore::Mode> DataTransfer::mode() const
|
||||
{
|
||||
if (m_associated_drag_data_store)
|
||||
return m_associated_drag_data_store->mode();
|
||||
return {};
|
||||
}
|
||||
|
||||
void DataTransfer::disassociate_with_drag_data_store()
|
||||
{
|
||||
m_associated_drag_data_store.clear();
|
||||
update_data_transfer_types_list();
|
||||
}
|
||||
|
||||
JS::NonnullGCPtr<DataTransferItem> DataTransfer::add_item(DragDataStoreItem item)
|
||||
{
|
||||
auto& realm = this->realm();
|
||||
|
||||
VERIFY(m_associated_drag_data_store);
|
||||
m_associated_drag_data_store->add_item(move(item));
|
||||
|
||||
auto data_transfer_item = DataTransferItem::create(realm, *this, m_associated_drag_data_store->size() - 1);
|
||||
m_item_list.append(data_transfer_item);
|
||||
|
||||
update_data_transfer_types_list();
|
||||
|
||||
return data_transfer_item;
|
||||
}
|
||||
|
||||
bool DataTransfer::contains_item_with_type(DragDataStoreItem::Kind kind, String const& type) const
|
||||
{
|
||||
VERIFY(m_associated_drag_data_store);
|
||||
|
||||
for (auto const& item : m_associated_drag_data_store->item_list()) {
|
||||
if (item.kind == kind && item.type_string.equals_ignoring_ascii_case(type))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/dnd.html#concept-datatransfer-types
|
||||
void DataTransfer::update_data_transfer_types_list()
|
||||
{
|
||||
|
@ -259,5 +293,4 @@ void DataTransfer::update_data_transfer_types_list()
|
|||
// 3. Set the DataTransfer object's types array to the result of creating a frozen array from L.
|
||||
m_types = move(types);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue