mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-12 19:19:30 +00:00
LibWeb: Implement the DataTransfer items attribute
This commit is contained in:
parent
34ad67e056
commit
1b70362954
Notes:
github-actions[bot]
2024-08-22 12:23:05 +00:00
Author: https://github.com/trflynn89
Commit: 1b70362954
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1158
Reviewed-by: https://github.com/shannonbooth
5 changed files with 43 additions and 3 deletions
|
@ -12,6 +12,7 @@
|
||||||
#include <LibWeb/FileAPI/File.h>
|
#include <LibWeb/FileAPI/File.h>
|
||||||
#include <LibWeb/FileAPI/FileList.h>
|
#include <LibWeb/FileAPI/FileList.h>
|
||||||
#include <LibWeb/HTML/DataTransfer.h>
|
#include <LibWeb/HTML/DataTransfer.h>
|
||||||
|
#include <LibWeb/HTML/DataTransferItemList.h>
|
||||||
#include <LibWeb/Infra/Strings.h>
|
#include <LibWeb/Infra/Strings.h>
|
||||||
|
|
||||||
namespace Web::HTML {
|
namespace Web::HTML {
|
||||||
|
@ -44,6 +45,12 @@ void DataTransfer::initialize(JS::Realm& realm)
|
||||||
WEB_SET_PROTOTYPE_FOR_INTERFACE(DataTransfer);
|
WEB_SET_PROTOTYPE_FOR_INTERFACE(DataTransfer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DataTransfer::visit_edges(JS::Cell::Visitor& visitor)
|
||||||
|
{
|
||||||
|
Base::visit_edges(visitor);
|
||||||
|
visitor.visit(m_items);
|
||||||
|
}
|
||||||
|
|
||||||
void DataTransfer::set_drop_effect(String const& drop_effect)
|
void DataTransfer::set_drop_effect(String const& drop_effect)
|
||||||
{
|
{
|
||||||
set_drop_effect(FlyString { drop_effect });
|
set_drop_effect(FlyString { drop_effect });
|
||||||
|
@ -82,6 +89,15 @@ void DataTransfer::set_effect_allowed_internal(FlyString effect_allowed)
|
||||||
m_effect_allowed = AK::move(effect_allowed);
|
m_effect_allowed = AK::move(effect_allowed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/multipage/dnd.html#dom-datatransfer-items
|
||||||
|
JS::NonnullGCPtr<DataTransferItemList> DataTransfer::items()
|
||||||
|
{
|
||||||
|
// The items attribute must return a DataTransferItemList object associated with the DataTransfer object.
|
||||||
|
if (!m_items)
|
||||||
|
m_items = DataTransferItemList::create(realm(), *this);
|
||||||
|
return *m_items;
|
||||||
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/dnd.html#dom-datatransfer-types
|
// https://html.spec.whatwg.org/multipage/dnd.html#dom-datatransfer-types
|
||||||
ReadonlySpan<String> DataTransfer::types() const
|
ReadonlySpan<String> DataTransfer::types() const
|
||||||
{
|
{
|
||||||
|
|
|
@ -49,6 +49,8 @@ public:
|
||||||
void set_effect_allowed(FlyString);
|
void set_effect_allowed(FlyString);
|
||||||
void set_effect_allowed_internal(FlyString);
|
void set_effect_allowed_internal(FlyString);
|
||||||
|
|
||||||
|
JS::NonnullGCPtr<DataTransferItemList> items();
|
||||||
|
|
||||||
ReadonlySpan<String> types() const;
|
ReadonlySpan<String> types() const;
|
||||||
String get_data(String const& format) const;
|
String get_data(String const& format) const;
|
||||||
JS::NonnullGCPtr<FileAPI::FileList> files() const;
|
JS::NonnullGCPtr<FileAPI::FileList> files() const;
|
||||||
|
@ -60,6 +62,7 @@ private:
|
||||||
DataTransfer(JS::Realm&);
|
DataTransfer(JS::Realm&);
|
||||||
|
|
||||||
virtual void initialize(JS::Realm&) override;
|
virtual void initialize(JS::Realm&) override;
|
||||||
|
virtual void visit_edges(JS::Cell::Visitor&) override;
|
||||||
|
|
||||||
void update_data_transfer_types_list();
|
void update_data_transfer_types_list();
|
||||||
|
|
||||||
|
@ -69,6 +72,9 @@ private:
|
||||||
// https://html.spec.whatwg.org/multipage/dnd.html#dom-datatransfer-effectallowed
|
// https://html.spec.whatwg.org/multipage/dnd.html#dom-datatransfer-effectallowed
|
||||||
FlyString m_effect_allowed { DataTransferEffect::none };
|
FlyString m_effect_allowed { DataTransferEffect::none };
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/multipage/dnd.html#dom-datatransfer-items
|
||||||
|
JS::GCPtr<DataTransferItemList> m_items;
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/dnd.html#concept-datatransfer-types
|
// https://html.spec.whatwg.org/multipage/dnd.html#concept-datatransfer-types
|
||||||
Vector<String> m_types;
|
Vector<String> m_types;
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#import <FileAPI/FileList.idl>
|
#import <FileAPI/FileList.idl>
|
||||||
|
#import <HTML/DataTransferItemList.idl>
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/dnd.html#datatransfer
|
// https://html.spec.whatwg.org/multipage/dnd.html#datatransfer
|
||||||
[Exposed=Window]
|
[Exposed=Window]
|
||||||
|
@ -8,7 +9,7 @@ interface DataTransfer {
|
||||||
attribute DOMString dropEffect;
|
attribute DOMString dropEffect;
|
||||||
attribute DOMString effectAllowed;
|
attribute DOMString effectAllowed;
|
||||||
|
|
||||||
[FIXME, SameObject] readonly attribute DataTransferItemList items;
|
[SameObject] readonly attribute DataTransferItemList items;
|
||||||
|
|
||||||
[FIXME] undefined setDragImage(Element image, long x, long y);
|
[FIXME] undefined setDragImage(Element image, long x, long y);
|
||||||
|
|
||||||
|
|
|
@ -7,14 +7,21 @@
|
||||||
#include <LibJS/Runtime/Realm.h>
|
#include <LibJS/Runtime/Realm.h>
|
||||||
#include <LibWeb/Bindings/DataTransferItemListPrototype.h>
|
#include <LibWeb/Bindings/DataTransferItemListPrototype.h>
|
||||||
#include <LibWeb/Bindings/Intrinsics.h>
|
#include <LibWeb/Bindings/Intrinsics.h>
|
||||||
|
#include <LibWeb/HTML/DataTransfer.h>
|
||||||
#include <LibWeb/HTML/DataTransferItemList.h>
|
#include <LibWeb/HTML/DataTransferItemList.h>
|
||||||
|
|
||||||
namespace Web::HTML {
|
namespace Web::HTML {
|
||||||
|
|
||||||
JS_DEFINE_ALLOCATOR(DataTransferItemList);
|
JS_DEFINE_ALLOCATOR(DataTransferItemList);
|
||||||
|
|
||||||
DataTransferItemList::DataTransferItemList(JS::Realm& realm)
|
JS::NonnullGCPtr<DataTransferItemList> DataTransferItemList::create(JS::Realm& realm, JS::NonnullGCPtr<DataTransfer> data_transfer)
|
||||||
|
{
|
||||||
|
return realm.heap().allocate<DataTransferItemList>(realm, realm, data_transfer);
|
||||||
|
}
|
||||||
|
|
||||||
|
DataTransferItemList::DataTransferItemList(JS::Realm& realm, JS::NonnullGCPtr<DataTransfer> data_transfer)
|
||||||
: PlatformObject(realm)
|
: PlatformObject(realm)
|
||||||
|
, m_data_transfer(data_transfer)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,4 +33,10 @@ void DataTransferItemList::initialize(JS::Realm& realm)
|
||||||
WEB_SET_PROTOTYPE_FOR_INTERFACE(DataTransferItemList);
|
WEB_SET_PROTOTYPE_FOR_INTERFACE(DataTransferItemList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DataTransferItemList::visit_edges(JS::Cell::Visitor& visitor)
|
||||||
|
{
|
||||||
|
Base::visit_edges(visitor);
|
||||||
|
visitor.visit(m_data_transfer);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,12 +17,16 @@ class DataTransferItemList : public Bindings::PlatformObject {
|
||||||
JS_DECLARE_ALLOCATOR(DataTransferItemList);
|
JS_DECLARE_ALLOCATOR(DataTransferItemList);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
static JS::NonnullGCPtr<DataTransferItemList> create(JS::Realm&, JS::NonnullGCPtr<DataTransfer>);
|
||||||
virtual ~DataTransferItemList() override;
|
virtual ~DataTransferItemList() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DataTransferItemList(JS::Realm&);
|
DataTransferItemList(JS::Realm&, JS::NonnullGCPtr<DataTransfer>);
|
||||||
|
|
||||||
virtual void initialize(JS::Realm&) override;
|
virtual void initialize(JS::Realm&) override;
|
||||||
|
virtual void visit_edges(JS::Cell::Visitor&) override;
|
||||||
|
|
||||||
|
JS::NonnullGCPtr<DataTransfer> m_data_transfer;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue