mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-07 08:39:22 +00:00
LibWeb: Implement the DataTransfer effect attributes
This commit is contained in:
parent
9e98e63559
commit
3674e037f3
Notes:
github-actions[bot]
2024-08-19 11:30:50 +00:00
Author: https://github.com/trflynn89
Commit: 3674e037f3
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1111
4 changed files with 91 additions and 2 deletions
|
@ -13,6 +13,14 @@ namespace Web::HTML {
|
|||
|
||||
JS_DEFINE_ALLOCATOR(DataTransfer);
|
||||
|
||||
namespace DataTransferEffect {
|
||||
|
||||
#define __ENUMERATE_DATA_TRANSFER_EFFECT(name) FlyString name = #name##_fly_string;
|
||||
ENUMERATE_DATA_TRANSFER_EFFECTS
|
||||
#undef __ENUMERATE_DATA_TRANSFER_EFFECT
|
||||
|
||||
}
|
||||
|
||||
JS::NonnullGCPtr<DataTransfer> DataTransfer::construct_impl(JS::Realm& realm)
|
||||
{
|
||||
return realm.heap().allocate<DataTransfer>(realm, realm);
|
||||
|
@ -31,4 +39,42 @@ void DataTransfer::initialize(JS::Realm& realm)
|
|||
WEB_SET_PROTOTYPE_FOR_INTERFACE(DataTransfer);
|
||||
}
|
||||
|
||||
void DataTransfer::set_drop_effect(String const& drop_effect)
|
||||
{
|
||||
set_drop_effect(FlyString { drop_effect });
|
||||
}
|
||||
|
||||
void DataTransfer::set_drop_effect(FlyString drop_effect)
|
||||
{
|
||||
using namespace DataTransferEffect;
|
||||
|
||||
// On setting, if the new value is one of "none", "copy", "link", or "move", then the attribute's current value must
|
||||
// be set to the new value. Other values must be ignored.
|
||||
if (drop_effect.is_one_of(none, copy, link, move))
|
||||
m_drop_effect = AK::move(drop_effect);
|
||||
}
|
||||
|
||||
void DataTransfer::set_effect_allowed(String const& effect_allowed)
|
||||
{
|
||||
set_effect_allowed(FlyString { effect_allowed });
|
||||
}
|
||||
|
||||
void DataTransfer::set_effect_allowed(FlyString effect_allowed)
|
||||
{
|
||||
// On setting, if drag data store's mode is the read/write mode and the new value is one of "none", "copy", "copyLink",
|
||||
// "copyMove", "link", "linkMove", "move", "all", or "uninitialized", then the attribute's current value must be set
|
||||
// to the new value. Otherwise, it must be left unchanged.
|
||||
if (m_associated_drag_data_store.has_value() && m_associated_drag_data_store->mode() == DragDataStore::Mode::ReadWrite)
|
||||
set_effect_allowed_internal(move(effect_allowed));
|
||||
}
|
||||
|
||||
void DataTransfer::set_effect_allowed_internal(FlyString effect_allowed)
|
||||
{
|
||||
// AD-HOC: We need to be able to set the effectAllowed attribute internally regardless of the state of the drag data store.
|
||||
using namespace DataTransferEffect;
|
||||
|
||||
if (effect_allowed.is_one_of(none, copy, copyLink, copyMove, link, linkMove, move, all, uninitialized))
|
||||
m_effect_allowed = AK::move(effect_allowed);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue