mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-04 15:19:42 +00:00
LibWeb: Implement the DataTransferItem kind and type attributes
This commit is contained in:
parent
ceb9e30d42
commit
001d8384e5
Notes:
github-actions[bot]
2024-08-22 12:22:21 +00:00
Author: https://github.com/trflynn89
Commit: 001d8384e5
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1158
Reviewed-by: https://github.com/shannonbooth
7 changed files with 65 additions and 6 deletions
|
@ -40,4 +40,49 @@ void DataTransferItem::visit_edges(JS::Cell::Visitor& visitor)
|
|||
visitor.visit(m_data_transfer);
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/dnd.html#dom-datatransferitem-kind
|
||||
String DataTransferItem::kind() const
|
||||
{
|
||||
// The kind attribute must return the empty string if the DataTransferItem object is in the disabled mode; otherwise
|
||||
// it must return the string given in the cell from the second column of the following table from the row whose cell
|
||||
// in the first column contains the drag data item kind of the item represented by the DataTransferItem object:
|
||||
//
|
||||
// Kind | String
|
||||
// ---------------
|
||||
// Text | "string"
|
||||
// File | "file"
|
||||
if (!mode().has_value())
|
||||
return {};
|
||||
|
||||
auto const& item = m_data_transfer->drag_data(*m_item_index);
|
||||
|
||||
switch (item.kind) {
|
||||
case DragDataStoreItem::Kind::Text:
|
||||
return "string"_string;
|
||||
case DragDataStoreItem::Kind::File:
|
||||
return "file"_string;
|
||||
}
|
||||
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/dnd.html#dom-datatransferitem-type
|
||||
String DataTransferItem::type() const
|
||||
{
|
||||
// The type attribute must return the empty string if the DataTransferItem object is in the disabled mode; otherwise
|
||||
// it must return the drag data item type string of the item represented by the DataTransferItem object.
|
||||
if (!mode().has_value())
|
||||
return {};
|
||||
|
||||
auto const& item = m_data_transfer->drag_data(*m_item_index);
|
||||
return item.type_string;
|
||||
}
|
||||
|
||||
Optional<DragDataStore::Mode> DataTransferItem::mode() const
|
||||
{
|
||||
if (!m_item_index.has_value())
|
||||
return {};
|
||||
return m_data_transfer->mode();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue