mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-02 14:19:48 +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
|
dropEffect: none
|
||||||
effectAllowed: none
|
effectAllowed: none
|
||||||
stringItem: [object DataTransferItem], types=custom-type
|
length=0, types=
|
||||||
fileItem: [object DataTransferItem], types=custom-type,Files
|
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}`);
|
println(`effectAllowed: ${dataTransfer.effectAllowed}`);
|
||||||
|
|
||||||
let dataTransferItemList = dataTransfer.items;
|
let dataTransferItemList = dataTransfer.items;
|
||||||
|
println(`length=${dataTransferItemList.length}, types=${dataTransfer.types}`);
|
||||||
|
|
||||||
let stringItem = dataTransferItemList.add("well hello friends", "custom-type");
|
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 {
|
try {
|
||||||
dataTransferItemList.add("well hello friends", "custom-type");
|
dataTransferItemList.add("well hello friends", "custom-type");
|
||||||
|
@ -20,6 +22,7 @@
|
||||||
});
|
});
|
||||||
|
|
||||||
let fileItem = dataTransferItemList.add(file);
|
let fileItem = dataTransferItemList.add(file);
|
||||||
println(`fileItem: ${fileItem}, types=${dataTransfer.types}`);
|
println(`fileItem: ${fileItem}`);
|
||||||
|
println(`length=${dataTransferItemList.length}, types=${dataTransfer.types}`);
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -260,6 +260,13 @@ bool DataTransfer::contains_item_with_type(DragDataStoreItem::Kind kind, String
|
||||||
return false;
|
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
|
// https://html.spec.whatwg.org/multipage/dnd.html#concept-datatransfer-types
|
||||||
void DataTransfer::update_data_transfer_types_list()
|
void DataTransfer::update_data_transfer_types_list()
|
||||||
{
|
{
|
||||||
|
|
|
@ -61,6 +61,7 @@ public:
|
||||||
|
|
||||||
JS::NonnullGCPtr<DataTransferItem> add_item(DragDataStoreItem item);
|
JS::NonnullGCPtr<DataTransferItem> add_item(DragDataStoreItem item);
|
||||||
bool contains_item_with_type(DragDataStoreItem::Kind, String const& type) const;
|
bool contains_item_with_type(DragDataStoreItem::Kind, String const& type) const;
|
||||||
|
size_t length() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DataTransfer(JS::Realm&, NonnullRefPtr<DragDataStore>);
|
DataTransfer(JS::Realm&, NonnullRefPtr<DragDataStore>);
|
||||||
|
|
|
@ -41,6 +41,14 @@ void DataTransferItemList::visit_edges(JS::Cell::Visitor& visitor)
|
||||||
visitor.visit(m_data_transfer);
|
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
|
// https://html.spec.whatwg.org/multipage/dnd.html#dom-datatransferitemlist-add
|
||||||
WebIDL::ExceptionOr<JS::GCPtr<DataTransferItem>> DataTransferItemList::add(String const& data, String const& type)
|
WebIDL::ExceptionOr<JS::GCPtr<DataTransferItem>> DataTransferItemList::add(String const& data, String const& type)
|
||||||
{
|
{
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#include <LibJS/Forward.h>
|
#include <LibJS/Forward.h>
|
||||||
#include <LibWeb/Bindings/PlatformObject.h>
|
#include <LibWeb/Bindings/PlatformObject.h>
|
||||||
#include <LibWeb/WebIDL/ExceptionOr.h>
|
#include <LibWeb/WebIDL/ExceptionOr.h>
|
||||||
|
#include <LibWeb/WebIDL/Types.h>
|
||||||
|
|
||||||
namespace Web::HTML {
|
namespace Web::HTML {
|
||||||
|
|
||||||
|
@ -21,6 +22,8 @@ public:
|
||||||
static JS::NonnullGCPtr<DataTransferItemList> create(JS::Realm&, JS::NonnullGCPtr<DataTransfer>);
|
static JS::NonnullGCPtr<DataTransferItemList> create(JS::Realm&, JS::NonnullGCPtr<DataTransfer>);
|
||||||
virtual ~DataTransferItemList() override;
|
virtual ~DataTransferItemList() override;
|
||||||
|
|
||||||
|
WebIDL::UnsignedLong length() const;
|
||||||
|
|
||||||
WebIDL::ExceptionOr<JS::GCPtr<DataTransferItem>> add(String const& data, String const& type);
|
WebIDL::ExceptionOr<JS::GCPtr<DataTransferItem>> add(String const& data, String const& type);
|
||||||
JS::GCPtr<DataTransferItem> add(JS::NonnullGCPtr<FileAPI::File>);
|
JS::GCPtr<DataTransferItem> add(JS::NonnullGCPtr<FileAPI::File>);
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
// https://html.spec.whatwg.org/multipage/dnd.html#datatransferitemlist
|
// https://html.spec.whatwg.org/multipage/dnd.html#datatransferitemlist
|
||||||
[Exposed=Window]
|
[Exposed=Window]
|
||||||
interface DataTransferItemList {
|
interface DataTransferItemList {
|
||||||
[FIXME] readonly attribute unsigned long length;
|
readonly attribute unsigned long length;
|
||||||
[FIXME] getter DataTransferItem (unsigned long index);
|
[FIXME] getter DataTransferItem (unsigned long index);
|
||||||
DataTransferItem? add(DOMString data, DOMString type);
|
DataTransferItem? add(DOMString data, DOMString type);
|
||||||
DataTransferItem? add(File data);
|
DataTransferItem? add(File data);
|
||||||
|
|
|
@ -48,6 +48,7 @@ public:
|
||||||
|
|
||||||
void add_item(DragDataStoreItem item) { m_item_list.append(move(item)); }
|
void add_item(DragDataStoreItem item) { m_item_list.append(move(item)); }
|
||||||
ReadonlySpan<DragDataStoreItem> item_list() const { return m_item_list; }
|
ReadonlySpan<DragDataStoreItem> item_list() const { return m_item_list; }
|
||||||
|
size_t size() const { return m_item_list.size(); }
|
||||||
bool has_text_item() const;
|
bool has_text_item() const;
|
||||||
|
|
||||||
Mode mode() const { return m_mode; }
|
Mode mode() const { return m_mode; }
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue