LibWeb: Implement the HTMLOutputElement.htmlFor attribute

This returns a DOMTokenList that reflects the `for` attribute.
This commit is contained in:
Tim Ledbetter 2024-05-16 18:54:42 +01:00 committed by Andreas Kling
parent acc1fa3c62
commit 3dc86747f0
Notes: sideshowbarker 2024-07-17 03:03:37 +09:00
5 changed files with 61 additions and 1 deletions

View file

@ -6,6 +6,7 @@
#include <LibWeb/Bindings/HTMLOutputElementPrototype.h>
#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/DOM/DOMTokenList.h>
#include <LibWeb/HTML/HTMLOutputElement.h>
namespace Web::HTML {
@ -25,6 +26,29 @@ void HTMLOutputElement::initialize(JS::Realm& realm)
WEB_SET_PROTOTYPE_FOR_INTERFACE(HTMLOutputElement);
}
void HTMLOutputElement::visit_edges(Cell::Visitor& visitor)
{
Base::visit_edges(visitor);
visitor.visit(m_html_for);
}
void HTMLOutputElement::form_associated_element_attribute_changed(FlyString const& name, Optional<String> const& value)
{
if (name == HTML::AttributeNames::for_) {
if (m_html_for)
m_html_for->associated_attribute_changed(value.value_or(String {}));
}
}
// https://html.spec.whatwg.org/multipage/form-elements.html#dom-output-htmlfor
JS::NonnullGCPtr<DOM::DOMTokenList> HTMLOutputElement::html_for()
{
// The htmlFor IDL attribute must reflect the for content attribute.
if (!m_html_for)
m_html_for = DOM::DOMTokenList::create(*this, HTML::AttributeNames::for_);
return *m_html_for;
}
// https://html.spec.whatwg.org/multipage/form-elements.html#dom-output-defaultvalue
String HTMLOutputElement::default_value() const
{