mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 15:28:11 +00:00
LibWeb: Switch to new CSS Parser :^)
Change all the places that were including the deprecated parser, to include the new one instead, and then delete the old parser code. `ParentNode::query_selector[_all]()` now treat their input as a comma-separated list of selectors, instead of just one, and return elements that match any of the selectors in that list. This is according to these specs: - querySelector/querySelectorAll: https://dom.spec.whatwg.org/#ref-for-dom-parentnode-queryselector%E2%91%A0 - selector matching algorithm: https://www.w3.org/TR/selectors-4/#match-against-tree
This commit is contained in:
parent
4065eb169c
commit
3bd14941c7
13 changed files with 37 additions and 2074 deletions
|
@ -4,7 +4,7 @@
|
|||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibWeb/CSS/Parser/DeprecatedCSSParser.h>
|
||||
#include <LibWeb/CSS/Parser/Parser.h>
|
||||
#include <LibWeb/CSS/SelectorEngine.h>
|
||||
#include <LibWeb/DOM/ParentNode.h>
|
||||
#include <LibWeb/Dump.h>
|
||||
|
@ -13,17 +13,22 @@ namespace Web::DOM {
|
|||
|
||||
RefPtr<Element> ParentNode::query_selector(const StringView& selector_text)
|
||||
{
|
||||
auto selector = parse_selector(CSS::DeprecatedParsingContext(*this), selector_text);
|
||||
if (!selector)
|
||||
auto maybe_selectors = parse_selector(CSS::ParsingContext(*this), selector_text);
|
||||
if (!maybe_selectors.has_value())
|
||||
return {};
|
||||
|
||||
dump_selector(*selector);
|
||||
auto selectors = maybe_selectors.value();
|
||||
|
||||
for (auto& selector : selectors)
|
||||
dump_selector(selector);
|
||||
|
||||
RefPtr<Element> result;
|
||||
for_each_in_inclusive_subtree_of_type<Element>([&](auto& element) {
|
||||
if (SelectorEngine::matches(*selector, element)) {
|
||||
result = element;
|
||||
return IterationDecision::Break;
|
||||
for (auto& selector : selectors) {
|
||||
if (SelectorEngine::matches(selector, element)) {
|
||||
result = element;
|
||||
return IterationDecision::Break;
|
||||
}
|
||||
}
|
||||
return IterationDecision::Continue;
|
||||
});
|
||||
|
@ -33,16 +38,21 @@ RefPtr<Element> ParentNode::query_selector(const StringView& selector_text)
|
|||
|
||||
NonnullRefPtrVector<Element> ParentNode::query_selector_all(const StringView& selector_text)
|
||||
{
|
||||
auto selector = parse_selector(CSS::DeprecatedParsingContext(*this), selector_text);
|
||||
if (!selector)
|
||||
auto maybe_selectors = parse_selector(CSS::ParsingContext(*this), selector_text);
|
||||
if (!maybe_selectors.has_value())
|
||||
return {};
|
||||
|
||||
dump_selector(*selector);
|
||||
auto selectors = maybe_selectors.value();
|
||||
|
||||
for (auto& selector : selectors)
|
||||
dump_selector(selector);
|
||||
|
||||
NonnullRefPtrVector<Element> elements;
|
||||
for_each_in_inclusive_subtree_of_type<Element>([&](auto& element) {
|
||||
if (SelectorEngine::matches(*selector, element)) {
|
||||
elements.append(element);
|
||||
for (auto& selector : selectors) {
|
||||
if (SelectorEngine::matches(selector, element)) {
|
||||
elements.append(element);
|
||||
}
|
||||
}
|
||||
return IterationDecision::Continue;
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue