mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-22 20:45:14 +00:00
LibWeb: Implement "has element in select scope" per-spec
The HTML Specification is quite tricky in this case. Usually "have a particular element in <x> scope" mentions "consisting of the following element types:", but in this case it's "consisting of all element types except the following:" Thanks to @AtkinsSJ for spotting this difference
This commit is contained in:
parent
1d55437a76
commit
e154c2c2ca
Notes:
sideshowbarker
2024-07-17 17:00:55 +09:00
Author: https://github.com/skyrising Commit: https://github.com/SerenityOS/serenity/commit/e154c2c2ca Pull-request: https://github.com/SerenityOS/serenity/pull/13164 Issue: https://github.com/SerenityOS/serenity/issues/12658 Reviewed-by: https://github.com/Hendiadyoin1
1 changed files with 22 additions and 1 deletions
|
@ -68,9 +68,30 @@ bool StackOfOpenElements::has_in_list_item_scope(const FlyString& tag_name) cons
|
|||
return has_in_scope_impl(tag_name, list);
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/parsing.html#has-an-element-in-select-scope
|
||||
// The stack of open elements is said to have a particular element in select scope
|
||||
// when it has that element in the specific scope consisting of all element types except the following:
|
||||
// - optgroup in the HTML namespace
|
||||
// - option in the HTML namespace
|
||||
// NOTE: In this case it's "all element types _except_"
|
||||
bool StackOfOpenElements::has_in_select_scope(const FlyString& tag_name) const
|
||||
{
|
||||
return has_in_scope_impl(tag_name, { "option", "optgroup" });
|
||||
// https://html.spec.whatwg.org/multipage/parsing.html#has-an-element-in-the-specific-scope
|
||||
for (ssize_t i = m_elements.size() - 1; i >= 0; --i) {
|
||||
// 1. Initialize node to be the current node (the bottommost node of the stack).
|
||||
auto& node = m_elements.at(i);
|
||||
// 2. If node is the target node, terminate in a match state.
|
||||
if (node.local_name() == tag_name)
|
||||
return true;
|
||||
// 3. Otherwise, if node is one of the element types in list, terminate in a failure state.
|
||||
// NOTE: Here "list" refers to all elements except option and optgroup
|
||||
if (node.local_name() != HTML::TagNames::option && node.local_name() != HTML::TagNames::optgroup)
|
||||
return false;
|
||||
// 4. Otherwise, set node to the previous entry in the stack of open elements and return to step 2.
|
||||
}
|
||||
// [4.] (This will never fail, since the loop will always terminate in the previous step if the top of the stack
|
||||
// — an html element — is reached.)
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
||||
bool StackOfOpenElements::contains(const DOM::Element& element) const
|
||||
|
|
Loading…
Add table
Reference in a new issue