mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-28 11:49:44 +00:00
LibWeb: Implement the DataTransferItemList length attribute
This commit is contained in:
parent
74d9cfbf2a
commit
843f8f04a5
Notes:
github-actions[bot]
2024-08-22 12:22:32 +00:00
Author: https://github.com/trflynn89
Commit: 843f8f04a5
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1158
Reviewed-by: https://github.com/shannonbooth
8 changed files with 31 additions and 5 deletions
|
@ -1,4 +1,7 @@
|
|||
dropEffect: none
|
||||
effectAllowed: none
|
||||
stringItem: [object DataTransferItem], types=custom-type
|
||||
fileItem: [object DataTransferItem], types=custom-type,Files
|
||||
length=0, types=
|
||||
stringItem: [object DataTransferItem]
|
||||
length=1, types=custom-type
|
||||
fileItem: [object DataTransferItem]
|
||||
length=2, types=custom-type,Files
|
||||
|
|
|
@ -6,9 +6,11 @@
|
|||
println(`effectAllowed: ${dataTransfer.effectAllowed}`);
|
||||
|
||||
let dataTransferItemList = dataTransfer.items;
|
||||
println(`length=${dataTransferItemList.length}, types=${dataTransfer.types}`);
|
||||
|
||||
let stringItem = dataTransferItemList.add("well hello friends", "custom-type");
|
||||
println(`stringItem: ${stringItem}, types=${dataTransfer.types}`);
|
||||
println(`stringItem: ${stringItem}`);
|
||||
println(`length=${dataTransferItemList.length}, types=${dataTransfer.types}`);
|
||||
|
||||
try {
|
||||
dataTransferItemList.add("well hello friends", "custom-type");
|
||||
|
@ -20,6 +22,7 @@
|
|||
});
|
||||
|
||||
let fileItem = dataTransferItemList.add(file);
|
||||
println(`fileItem: ${fileItem}, types=${dataTransfer.types}`);
|
||||
println(`fileItem: ${fileItem}`);
|
||||
println(`length=${dataTransferItemList.length}, types=${dataTransfer.types}`);
|
||||
});
|
||||
</script>
|
||||
|
|
|
@ -260,6 +260,13 @@ bool DataTransfer::contains_item_with_type(DragDataStoreItem::Kind kind, String
|
|||
return false;
|
||||
}
|
||||
|
||||
size_t DataTransfer::length() const
|
||||
{
|
||||
if (m_associated_drag_data_store)
|
||||
return m_associated_drag_data_store->size();
|
||||
return 0;
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/dnd.html#concept-datatransfer-types
|
||||
void DataTransfer::update_data_transfer_types_list()
|
||||
{
|
||||
|
|
|
@ -61,6 +61,7 @@ public:
|
|||
|
||||
JS::NonnullGCPtr<DataTransferItem> add_item(DragDataStoreItem item);
|
||||
bool contains_item_with_type(DragDataStoreItem::Kind, String const& type) const;
|
||||
size_t length() const;
|
||||
|
||||
private:
|
||||
DataTransfer(JS::Realm&, NonnullRefPtr<DragDataStore>);
|
||||
|
|
|
@ -41,6 +41,14 @@ void DataTransferItemList::visit_edges(JS::Cell::Visitor& visitor)
|
|||
visitor.visit(m_data_transfer);
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/dnd.html#dom-datatransferitemlist-length
|
||||
WebIDL::UnsignedLong DataTransferItemList::length() const
|
||||
{
|
||||
// The length attribute must return zero if the object is in the disabled mode; otherwise it must return the number
|
||||
// of items in the drag data store item list.
|
||||
return m_data_transfer->length();
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/dnd.html#dom-datatransferitemlist-add
|
||||
WebIDL::ExceptionOr<JS::GCPtr<DataTransferItem>> DataTransferItemList::add(String const& data, String const& type)
|
||||
{
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include <LibJS/Forward.h>
|
||||
#include <LibWeb/Bindings/PlatformObject.h>
|
||||
#include <LibWeb/WebIDL/ExceptionOr.h>
|
||||
#include <LibWeb/WebIDL/Types.h>
|
||||
|
||||
namespace Web::HTML {
|
||||
|
||||
|
@ -21,6 +22,8 @@ public:
|
|||
static JS::NonnullGCPtr<DataTransferItemList> create(JS::Realm&, JS::NonnullGCPtr<DataTransfer>);
|
||||
virtual ~DataTransferItemList() override;
|
||||
|
||||
WebIDL::UnsignedLong length() const;
|
||||
|
||||
WebIDL::ExceptionOr<JS::GCPtr<DataTransferItem>> add(String const& data, String const& type);
|
||||
JS::GCPtr<DataTransferItem> add(JS::NonnullGCPtr<FileAPI::File>);
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
// https://html.spec.whatwg.org/multipage/dnd.html#datatransferitemlist
|
||||
[Exposed=Window]
|
||||
interface DataTransferItemList {
|
||||
[FIXME] readonly attribute unsigned long length;
|
||||
readonly attribute unsigned long length;
|
||||
[FIXME] getter DataTransferItem (unsigned long index);
|
||||
DataTransferItem? add(DOMString data, DOMString type);
|
||||
DataTransferItem? add(File data);
|
||||
|
|
|
@ -48,6 +48,7 @@ public:
|
|||
|
||||
void add_item(DragDataStoreItem item) { m_item_list.append(move(item)); }
|
||||
ReadonlySpan<DragDataStoreItem> item_list() const { return m_item_list; }
|
||||
size_t size() const { return m_item_list.size(); }
|
||||
bool has_text_item() const;
|
||||
|
||||
Mode mode() const { return m_mode; }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue