LibWeb: Add a factory method to create a DataTransferItem

A DataTransferItem is associated with a DataTransfer, and points to an
item in the drag data store. We don't yet support removing items from
the store, but when we do, we will clear the index stored here to set
the DataTransferItem's mode to "disabled".
This commit is contained in:
Timothy Flynn 2024-08-21 08:54:11 -04:00 committed by Andreas Kling
parent 5c9287aa99
commit c82fec0a8c
Notes: github-actions[bot] 2024-08-22 12:22:50 +00:00
2 changed files with 23 additions and 2 deletions

View file

@ -7,14 +7,22 @@
#include <LibJS/Runtime/Realm.h>
#include <LibWeb/Bindings/DataTransferItemPrototype.h>
#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/HTML/DataTransfer.h>
#include <LibWeb/HTML/DataTransferItem.h>
namespace Web::HTML {
JS_DEFINE_ALLOCATOR(DataTransferItem);
DataTransferItem::DataTransferItem(JS::Realm& realm)
JS::NonnullGCPtr<DataTransferItem> DataTransferItem::create(JS::Realm& realm, JS::NonnullGCPtr<DataTransfer> data_transfer, size_t item_index)
{
return realm.heap().allocate<DataTransferItem>(realm, realm, data_transfer, item_index);
}
DataTransferItem::DataTransferItem(JS::Realm& realm, JS::NonnullGCPtr<DataTransfer> data_transfer, size_t item_index)
: PlatformObject(realm)
, m_data_transfer(data_transfer)
, m_item_index(item_index)
{
}
@ -26,4 +34,10 @@ void DataTransferItem::initialize(JS::Realm& realm)
WEB_SET_PROTOTYPE_FOR_INTERFACE(DataTransferItem);
}
void DataTransferItem::visit_edges(JS::Cell::Visitor& visitor)
{
Base::visit_edges(visitor);
visitor.visit(m_data_transfer);
}
}

View file

@ -6,8 +6,10 @@
#pragma once
#include <AK/Optional.h>
#include <LibJS/Forward.h>
#include <LibWeb/Bindings/PlatformObject.h>
#include <LibWeb/HTML/DragDataStore.h>
namespace Web::HTML {
@ -17,12 +19,17 @@ class DataTransferItem : public Bindings::PlatformObject {
JS_DECLARE_ALLOCATOR(DataTransferItem);
public:
static JS::NonnullGCPtr<DataTransferItem> create(JS::Realm&, JS::NonnullGCPtr<DataTransfer>, size_t item_index);
virtual ~DataTransferItem() override;
private:
DataTransferItem(JS::Realm&);
DataTransferItem(JS::Realm&, JS::NonnullGCPtr<DataTransfer>, size_t item_index);
virtual void initialize(JS::Realm&) override;
virtual void visit_edges(JS::Cell::Visitor&) override;
JS::NonnullGCPtr<DataTransfer> m_data_transfer;
Optional<size_t> m_item_index;
};
}