mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-09 09:39:39 +00:00
LibWeb: Implement the translate attribute
This commit is contained in:
parent
4b3715ccba
commit
279913a223
Notes:
github-actions[bot]
2025-05-23 12:35:07 +00:00
Author: https://github.com/Calme1709
Commit: 279913a223
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4855
Reviewed-by: https://github.com/gmta ✅
24 changed files with 399 additions and 1 deletions
|
@ -3327,6 +3327,36 @@ IntersectionObserver::IntersectionObserverRegistration& Element::get_intersectio
|
|||
return *registration_iterator;
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/dom.html#translation-mode
|
||||
Element::TranslationMode Element::translation_mode() const
|
||||
{
|
||||
// Each element (even non-HTML elements) has a translation mode, which is in either the translate-enabled state or
|
||||
// the no-translate state.
|
||||
|
||||
// If an HTML element's translate attribute is in the Yes state, then the element's translation mode is in the
|
||||
// translate-enabled state;
|
||||
// NOTE: The attribute is in the Yes state if the attribute is present and its value is the empty string or is a
|
||||
// ASCII-case-insensitive match for "yes".
|
||||
auto maybe_translate_attribute = attribute(HTML::AttributeNames::translate);
|
||||
if (maybe_translate_attribute.has_value() && (maybe_translate_attribute.value().is_empty() || maybe_translate_attribute.value().equals_ignoring_ascii_case("yes"sv)))
|
||||
return TranslationMode::TranslateEnabled;
|
||||
|
||||
// otherwise, if the element's translate attribute is in the No state, then the element's translation mode is in
|
||||
// the no-translate state.
|
||||
if (maybe_translate_attribute.has_value() && maybe_translate_attribute.value().equals_ignoring_ascii_case("no"sv)) {
|
||||
return TranslationMode::NoTranslate;
|
||||
}
|
||||
|
||||
// Otherwise, either the element's translate attribute is in the Inherit state, or the element is not an HTML
|
||||
// element and thus does not have a translate attribute; in either case, the element's translation mode is in the
|
||||
// same state as its parent element's, if any.
|
||||
if (auto parent = parent_element())
|
||||
return parent->translation_mode();
|
||||
|
||||
// or in the translate-enabled state, if the element's parent element is null
|
||||
return TranslationMode::TranslateEnabled;
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/dom.html#the-directionality
|
||||
Element::Directionality Element::directionality() const
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue