mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-24 10:12:25 -05:00
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:
parent
5c9287aa99
commit
c82fec0a8c
Notes:
github-actions[bot]
2024-08-22 12:22:50 +00:00
Author: https://github.com/trflynn89 Commit: https://github.com/LadybirdBrowser/ladybird/commit/c82fec0a8cc Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1158 Reviewed-by: https://github.com/shannonbooth
2 changed files with 23 additions and 2 deletions
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue