Implement DataTransfer and related interfaces (#34205)

* add datatransfer interfaces

Signed-off-by: Gae24 <96017547+Gae24@users.noreply.github.com>

* implement DataTransfer interface

implemented Constructor, setter and getter for drop_effect and effect_allowed, Items and SetDragImage

Signed-off-by: Gae24 <96017547+Gae24@users.noreply.github.com>

* implement DataTransferItem interface

Implemented Kind, Type, GetAsString, GetAsFile.
Marked DataTransfer as weakReferenceable to access its field
inside DataTransferItemList and DataTransferItem.
Signed-off-by: Gae24 <96017547+Gae24@users.noreply.github.com>

* implement DataTransferItemList interface

implemented Lenght, Getter, Add, Remove, Clear
Signed-off-by: Gae24 <96017547+Gae24@users.noreply.github.com>

* added DataTransfer's old interface

Signed-off-by: Gae24 <96017547+Gae24@users.noreply.github.com>

* DataTransfer: implemented GetData, SetData, SetData

Signed-off-by: Gae24 <96017547+Gae24@users.noreply.github.com>

* set Weakref to DataTransfer in DataTransferItemList and DataTransferItem

Signed-off-by: Gae24 <96017547+Gae24@users.noreply.github.com>

* DataTransfer: implemented Types and Files

Signed-off-by: Gae24 <96017547+Gae24@users.noreply.github.com>

* cleanup get_data, set_data, clear_data

Signed-off-by: Gae24 <96017547+Gae24@users.noreply.github.com>

* fix clippy warning

Signed-off-by: Gae24 <96017547+Gae24@users.noreply.github.com>

* add drag data store

Signed-off-by: Gae24 <96017547+Gae24@users.noreply.github.com>

* fix DataTransfer's Types() behaviour

Signed-off-by: Gae24 <96017547+Gae24@users.noreply.github.com>

* DataTransferItem: use the underlying drag data store

Signed-off-by: Gae24 <96017547+Gae24@users.noreply.github.com>

* fix DataTransferItemList's getter and remove

Signed-off-by: Gae24 <96017547+Gae24@users.noreply.github.com>

* fix clippy warnings

Signed-off-by: Gae24 <96017547+Gae24@users.noreply.github.com>

* update test expectations

Signed-off-by: Gae24 <96017547+Gae24@users.noreply.github.com>

---------

Signed-off-by: Gae24 <96017547+Gae24@users.noreply.github.com>
This commit is contained in:
Gae24 2024-11-25 11:49:04 +01:00 committed by GitHub
parent 810a91ecac
commit c9e3d3e25e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
19 changed files with 873 additions and 146 deletions

View file

@ -0,0 +1,66 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use std::rc::Rc;
use dom_struct::dom_struct;
use crate::dom::bindings::callback::ExceptionHandling;
use crate::dom::bindings::codegen::Bindings::DataTransferItemBinding::{
DataTransferItemMethods, FunctionStringCallback,
};
use crate::dom::bindings::reflector::{reflect_dom_object, DomObject, Reflector};
use crate::dom::bindings::root::DomRoot;
use crate::dom::bindings::str::DOMString;
use crate::dom::file::File;
use crate::dom::globalscope::GlobalScope;
use crate::drag_data_store::Kind;
#[dom_struct]
pub struct DataTransferItem {
reflector_: Reflector,
#[ignore_malloc_size_of = "TODO"]
#[no_trace]
item: Kind,
}
impl DataTransferItem {
fn new_inherited(item: Kind) -> DataTransferItem {
DataTransferItem {
reflector_: Reflector::new(),
item,
}
}
pub fn new(global: &GlobalScope, item: Kind) -> DomRoot<DataTransferItem> {
reflect_dom_object(Box::new(DataTransferItem::new_inherited(item)), global)
}
}
impl DataTransferItemMethods<crate::DomTypeHolder> for DataTransferItem {
/// <https://html.spec.whatwg.org/multipage/#dom-datatransferitem-kind>
fn Kind(&self) -> DOMString {
match self.item {
Kind::Text(_) => DOMString::from("string"),
Kind::File(_) => DOMString::from("file"),
}
}
/// <https://html.spec.whatwg.org/multipage/#dom-datatransferitem-type>
fn Type(&self) -> DOMString {
self.item.type_()
}
/// <https://html.spec.whatwg.org/multipage/#dom-datatransferitem-getasstring>
fn GetAsString(&self, callback: Option<Rc<FunctionStringCallback>>) {
if let (Some(callback), Some(data)) = (callback, self.item.as_string()) {
let _ = callback.Call__(data, ExceptionHandling::Report);
}
}
/// <https://html.spec.whatwg.org/multipage/#dom-datatransferitem-getasfile>
fn GetAsFile(&self) -> Option<DomRoot<File>> {
self.item.as_file(&self.global())
}
}