diff --git a/Userland/Libraries/LibWeb/HTML/AttributeNames.h b/Userland/Libraries/LibWeb/HTML/AttributeNames.h index e38d21f6a66714..9ac71456de80fa 100644 --- a/Userland/Libraries/LibWeb/HTML/AttributeNames.h +++ b/Userland/Libraries/LibWeb/HTML/AttributeNames.h @@ -214,6 +214,7 @@ namespace AttributeNames { __ENUMERATE_HTML_ATTRIBUTE(ping) \ __ENUMERATE_HTML_ATTRIBUTE(placeholder) \ __ENUMERATE_HTML_ATTRIBUTE(playsinline) \ + __ENUMERATE_HTML_ATTRIBUTE(popover) \ __ENUMERATE_HTML_ATTRIBUTE(poster) \ __ENUMERATE_HTML_ATTRIBUTE(preload) \ __ENUMERATE_HTML_ATTRIBUTE(readonly) \ diff --git a/Userland/Libraries/LibWeb/HTML/HTMLElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLElement.cpp index 1d3e02113f2660..a91cb8251be56d 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLElement.cpp @@ -681,6 +681,34 @@ WebIDL::ExceptionOr> HTMLElement::attach_inte return { internals }; } +// https://html.spec.whatwg.org/multipage/popover.html#dom-popover +Optional 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 HTMLElement::set_popover(Optional 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) diff --git a/Userland/Libraries/LibWeb/HTML/HTMLElement.h b/Userland/Libraries/LibWeb/HTML/HTMLElement.h index e44a93e8f0073d..230c7d85ede76a 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLElement.h @@ -77,6 +77,9 @@ class HTMLElement WebIDL::ExceptionOr> attach_internals(); + WebIDL::ExceptionOr set_popover(Optional value); + Optional popover() const; + protected: HTMLElement(DOM::Document&, DOM::QualifiedName); diff --git a/Userland/Libraries/LibWeb/HTML/HTMLElement.idl b/Userland/Libraries/LibWeb/HTML/HTMLElement.idl index d4031754f234d5..299668a2fbcdc1 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLElement.idl +++ b/Userland/Libraries/LibWeb/HTML/HTMLElement.idl @@ -35,7 +35,7 @@ interface HTMLElement : Element { [FIXME] undefined showPopover(); [FIXME] undefined hidePopover(); [FIXME] boolean togglePopover(optional boolean force); - [FIXME, CEReactions] attribute DOMString? popover; + [CEReactions] attribute DOMString? popover; // https://drafts.csswg.org/cssom-view/#extensions-to-the-htmlelement-interface readonly attribute Element? offsetParent;