LibWeb: Implement popover property and attribute

The popover property now reflects the attribute.

It cannot currently use the Reflect IDL concept because the empty string
value is special cased.
This commit is contained in:
Luke Warlow
2024-07-01 19:55:33 +01:00
committed by Andreas Kling
parent 197f57f5d2
commit a9669639ce
5 changed files with 34 additions and 2 deletions

View File

@@ -645,6 +645,34 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<ElementInternals>> HTMLElement::attach_inte
return { internals };
}
// https://html.spec.whatwg.org/multipage/popover.html#dom-popover
Optional<String> HTMLElement::popover() const
{
// FIXME: This should probably be `Reflect` in the IDL.
// The popover IDL attribute must reflect the popover attribute, limited to only known values.
auto value = get_attribute(HTML::AttributeNames::popover);
if (!value.has_value())
return {};
if (value.value().is_empty() || value.value().equals_ignoring_ascii_case("auto"sv))
return "auto"_string;
return "manual"_string;
}
// https://html.spec.whatwg.org/multipage/popover.html#dom-popover
WebIDL::ExceptionOr<void> HTMLElement::set_popover(Optional<String> value)
{
// FIXME: This should probably be `Reflect` in the IDL.
// The popover IDL attribute must reflect the popover attribute, limited to only known values.
if (value.has_value())
return set_attribute(HTML::AttributeNames::popover, value.release_value());
remove_attribute(HTML::AttributeNames::popover);
return {};
}
void HTMLElement::did_receive_focus()
{
if (m_content_editable_state != ContentEditableState::True)