LibWeb/HTML: Properly get the attr-associated element

This replaces ad-hoc implementations of the get the attr-associated
element steps with a call to the proper implementation. This fixes
issue #8585.
This commit is contained in:
Glenn Skrzypczak
2026-03-24 10:47:25 +01:00
committed by Jelle Raaijmakers
parent 4110a05684
commit 88167149f6
Notes: github-actions[bot] 2026-03-25 22:15:22 +00:00
5 changed files with 36 additions and 31 deletions

View File

@@ -183,20 +183,7 @@ void HTMLButtonElement::activation_behavior(DOM::Event const& event)
}
// 4. Let target be the result of running element's get the commandfor-associated element.
// AD-HOC: Target needs to be an HTML Element in the following steps.
GC::Ptr<HTMLElement> target = as_if<HTMLElement>(m_command_for_element.ptr());
if (!target) {
auto target_id = attribute(AttributeNames::commandfor);
if (target_id.has_value()) {
root().for_each_in_inclusive_subtree_of_type<HTMLElement>([&](auto& candidate) {
if (candidate.attribute(HTML::AttributeNames::id) == target_id.value()) {
target = &candidate;
return TraversalDecision::Break;
}
return TraversalDecision::Continue;
});
}
}
auto target = get_the_attribute_associated_element(AttributeNames::commandfor, m_command_for_element);
// 5. If target is not null:
if (target) {