SelectorEngine.cpp 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492
  1. /*
  2. * Copyright (c) 2018-2022, Andreas Kling <kling@serenityos.org>
  3. * Copyright (c) 2021-2023, Sam Atkins <atkinssj@serenityos.org>
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #include <LibWeb/CSS/Parser/Parser.h>
  8. #include <LibWeb/CSS/SelectorEngine.h>
  9. #include <LibWeb/DOM/Document.h>
  10. #include <LibWeb/DOM/Element.h>
  11. #include <LibWeb/DOM/Text.h>
  12. #include <LibWeb/HTML/AttributeNames.h>
  13. #include <LibWeb/HTML/HTMLAnchorElement.h>
  14. #include <LibWeb/HTML/HTMLAreaElement.h>
  15. #include <LibWeb/HTML/HTMLButtonElement.h>
  16. #include <LibWeb/HTML/HTMLFieldSetElement.h>
  17. #include <LibWeb/HTML/HTMLHtmlElement.h>
  18. #include <LibWeb/HTML/HTMLInputElement.h>
  19. #include <LibWeb/HTML/HTMLMediaElement.h>
  20. #include <LibWeb/HTML/HTMLOptGroupElement.h>
  21. #include <LibWeb/HTML/HTMLOptionElement.h>
  22. #include <LibWeb/HTML/HTMLProgressElement.h>
  23. #include <LibWeb/HTML/HTMLSelectElement.h>
  24. #include <LibWeb/HTML/HTMLTextAreaElement.h>
  25. #include <LibWeb/Infra/Strings.h>
  26. namespace Web::SelectorEngine {
  27. // https://drafts.csswg.org/selectors-4/#the-lang-pseudo
  28. static inline bool matches_lang_pseudo_class(DOM::Element const& element, Vector<FlyString> const& languages)
  29. {
  30. FlyString element_language;
  31. for (auto const* e = &element; e; e = e->parent_element()) {
  32. auto lang = e->attribute(HTML::AttributeNames::lang);
  33. if (!lang.is_null()) {
  34. element_language = FlyString::from_deprecated_fly_string(lang).release_value_but_fixme_should_propagate_errors();
  35. break;
  36. }
  37. }
  38. if (element_language.is_empty())
  39. return false;
  40. // FIXME: This is ad-hoc. Implement a proper language range matching algorithm as recommended by BCP47.
  41. for (auto const& language : languages) {
  42. if (language.is_empty())
  43. return false;
  44. if (language == "*"sv)
  45. return true;
  46. if (!element_language.to_string().contains('-'))
  47. return Infra::is_ascii_case_insensitive_match(element_language, language);
  48. auto parts = element_language.to_string().split_limit('-', 2).release_value_but_fixme_should_propagate_errors();
  49. return Infra::is_ascii_case_insensitive_match(parts[0], language);
  50. }
  51. return false;
  52. }
  53. // https://html.spec.whatwg.org/multipage/semantics-other.html#selector-link
  54. static inline bool matches_link_pseudo_class(DOM::Element const& element)
  55. {
  56. // All a elements that have an href attribute, and all area elements that have an href attribute, must match one of :link and :visited.
  57. if (!is<HTML::HTMLAnchorElement>(element) && !is<HTML::HTMLAreaElement>(element))
  58. return false;
  59. return element.has_attribute(HTML::AttributeNames::href);
  60. }
  61. static inline bool matches_hover_pseudo_class(DOM::Element const& element)
  62. {
  63. auto* hovered_node = element.document().hovered_node();
  64. if (!hovered_node)
  65. return false;
  66. if (&element == hovered_node)
  67. return true;
  68. return element.is_ancestor_of(*hovered_node);
  69. }
  70. // https://html.spec.whatwg.org/multipage/semantics-other.html#selector-checked
  71. static inline bool matches_checked_pseudo_class(DOM::Element const& element)
  72. {
  73. // The :checked pseudo-class must match any element falling into one of the following categories:
  74. // - input elements whose type attribute is in the Checkbox state and whose checkedness state is true
  75. // - input elements whose type attribute is in the Radio Button state and whose checkedness state is true
  76. if (is<HTML::HTMLInputElement>(element)) {
  77. auto const& input_element = static_cast<HTML::HTMLInputElement const&>(element);
  78. switch (input_element.type_state()) {
  79. case HTML::HTMLInputElement::TypeAttributeState::Checkbox:
  80. case HTML::HTMLInputElement::TypeAttributeState::RadioButton:
  81. return static_cast<HTML::HTMLInputElement const&>(element).checked();
  82. default:
  83. return false;
  84. }
  85. }
  86. // - option elements whose selectedness is true
  87. if (is<HTML::HTMLOptionElement>(element)) {
  88. return static_cast<HTML::HTMLOptionElement const&>(element).selected();
  89. }
  90. return false;
  91. }
  92. // https://html.spec.whatwg.org/multipage/semantics-other.html#selector-indeterminate
  93. static inline bool matches_indeterminate_pseudo_class(DOM::Element const& element)
  94. {
  95. // The :indeterminate pseudo-class must match any element falling into one of the following categories:
  96. // - input elements whose type attribute is in the Checkbox state and whose indeterminate IDL attribute is set to true
  97. // FIXME: - input elements whose type attribute is in the Radio Button state and whose radio button group contains no input elements whose checkedness state is true.
  98. if (is<HTML::HTMLInputElement>(element)) {
  99. auto const& input_element = static_cast<HTML::HTMLInputElement const&>(element);
  100. switch (input_element.type_state()) {
  101. case HTML::HTMLInputElement::TypeAttributeState::Checkbox:
  102. return input_element.indeterminate();
  103. default:
  104. return false;
  105. }
  106. }
  107. // - progress elements with no value content attribute
  108. if (is<HTML::HTMLProgressElement>(element)) {
  109. return !element.has_attribute(HTML::AttributeNames::value);
  110. }
  111. return false;
  112. }
  113. static inline bool matches_attribute(CSS::Selector::SimpleSelector::Attribute const& attribute, DOM::Element const& element)
  114. {
  115. if (attribute.match_type == CSS::Selector::SimpleSelector::Attribute::MatchType::HasAttribute) {
  116. // Early way out in case of an attribute existence selector.
  117. return element.has_attribute(attribute.name.to_string().to_deprecated_string());
  118. }
  119. auto const case_insensitive_match = (attribute.case_type == CSS::Selector::SimpleSelector::Attribute::CaseType::CaseInsensitiveMatch);
  120. auto const case_sensitivity = case_insensitive_match
  121. ? CaseSensitivity::CaseInsensitive
  122. : CaseSensitivity::CaseSensitive;
  123. switch (attribute.match_type) {
  124. case CSS::Selector::SimpleSelector::Attribute::MatchType::ExactValueMatch:
  125. return case_insensitive_match
  126. ? Infra::is_ascii_case_insensitive_match(element.attribute(attribute.name.to_string().to_deprecated_string()), attribute.value)
  127. : element.attribute(attribute.name.to_string().to_deprecated_string()) == attribute.value.to_deprecated_string();
  128. case CSS::Selector::SimpleSelector::Attribute::MatchType::ContainsWord: {
  129. if (attribute.value.is_empty()) {
  130. // This selector is always false is match value is empty.
  131. return false;
  132. }
  133. auto const view = element.attribute(attribute.name.to_string().to_deprecated_string()).split_view(' ');
  134. auto const size = view.size();
  135. for (size_t i = 0; i < size; ++i) {
  136. auto const value = view.at(i);
  137. if (case_insensitive_match
  138. ? Infra::is_ascii_case_insensitive_match(value, attribute.value)
  139. : value == attribute.value) {
  140. return true;
  141. }
  142. }
  143. return false;
  144. }
  145. case CSS::Selector::SimpleSelector::Attribute::MatchType::ContainsString:
  146. return !attribute.value.is_empty()
  147. && element.attribute(attribute.name.to_string().to_deprecated_string()).contains(attribute.value, case_sensitivity);
  148. case CSS::Selector::SimpleSelector::Attribute::MatchType::StartsWithSegment: {
  149. auto const element_attr_value = element.attribute(attribute.name.to_string().to_deprecated_string());
  150. if (element_attr_value.is_empty()) {
  151. // If the attribute value on element is empty, the selector is true
  152. // if the match value is also empty and false otherwise.
  153. return attribute.value.is_empty();
  154. }
  155. if (attribute.value.is_empty()) {
  156. return false;
  157. }
  158. auto segments = element_attr_value.split_view('-');
  159. return case_insensitive_match
  160. ? Infra::is_ascii_case_insensitive_match(segments.first(), attribute.value)
  161. : segments.first() == attribute.value;
  162. }
  163. case CSS::Selector::SimpleSelector::Attribute::MatchType::StartsWithString:
  164. return !attribute.value.is_empty()
  165. && element.attribute(attribute.name.to_string().to_deprecated_string()).starts_with(attribute.value, case_sensitivity);
  166. case CSS::Selector::SimpleSelector::Attribute::MatchType::EndsWithString:
  167. return !attribute.value.is_empty()
  168. && element.attribute(attribute.name.to_string().to_deprecated_string()).ends_with(attribute.value, case_sensitivity);
  169. default:
  170. break;
  171. }
  172. return false;
  173. }
  174. static inline DOM::Element const* previous_sibling_with_same_tag_name(DOM::Element const& element)
  175. {
  176. for (auto const* sibling = element.previous_element_sibling(); sibling; sibling = sibling->previous_element_sibling()) {
  177. if (sibling->tag_name() == element.tag_name())
  178. return sibling;
  179. }
  180. return nullptr;
  181. }
  182. static inline DOM::Element const* next_sibling_with_same_tag_name(DOM::Element const& element)
  183. {
  184. for (auto const* sibling = element.next_element_sibling(); sibling; sibling = sibling->next_element_sibling()) {
  185. if (sibling->tag_name() == element.tag_name())
  186. return sibling;
  187. }
  188. return nullptr;
  189. }
  190. static inline bool matches_pseudo_class(CSS::Selector::SimpleSelector::PseudoClass const& pseudo_class, DOM::Element const& element, JS::GCPtr<DOM::ParentNode const> scope)
  191. {
  192. switch (pseudo_class.type) {
  193. case CSS::Selector::SimpleSelector::PseudoClass::Type::Link:
  194. return matches_link_pseudo_class(element);
  195. case CSS::Selector::SimpleSelector::PseudoClass::Type::Visited:
  196. // FIXME: Maybe match this selector sometimes?
  197. return false;
  198. case CSS::Selector::SimpleSelector::PseudoClass::Type::Active:
  199. return element.is_active();
  200. case CSS::Selector::SimpleSelector::PseudoClass::Type::Hover:
  201. return matches_hover_pseudo_class(element);
  202. case CSS::Selector::SimpleSelector::PseudoClass::Type::Focus:
  203. return element.is_focused();
  204. case CSS::Selector::SimpleSelector::PseudoClass::Type::FocusWithin: {
  205. auto* focused_element = element.document().focused_element();
  206. return focused_element && element.is_inclusive_ancestor_of(*focused_element);
  207. }
  208. case CSS::Selector::SimpleSelector::PseudoClass::Type::FirstChild:
  209. return !element.previous_element_sibling();
  210. case CSS::Selector::SimpleSelector::PseudoClass::Type::LastChild:
  211. return !element.next_element_sibling();
  212. case CSS::Selector::SimpleSelector::PseudoClass::Type::OnlyChild:
  213. return !(element.previous_element_sibling() || element.next_element_sibling());
  214. case CSS::Selector::SimpleSelector::PseudoClass::Type::Empty: {
  215. if (!element.has_children())
  216. return true;
  217. if (element.first_child_of_type<DOM::Element>())
  218. return false;
  219. // NOTE: CSS Selectors level 4 changed ":empty" to also match whitespace-only text nodes.
  220. // However, none of the major browser supports this yet, so let's just hang back until they do.
  221. bool has_nonempty_text_child = false;
  222. element.for_each_child_of_type<DOM::Text>([&](auto const& text_child) {
  223. if (!text_child.data().is_empty()) {
  224. has_nonempty_text_child = true;
  225. return IterationDecision::Break;
  226. }
  227. return IterationDecision::Continue;
  228. });
  229. return !has_nonempty_text_child;
  230. }
  231. case CSS::Selector::SimpleSelector::PseudoClass::Type::Root:
  232. return is<HTML::HTMLHtmlElement>(element);
  233. case CSS::Selector::SimpleSelector::PseudoClass::Type::Host:
  234. // FIXME: Implement :host selector.
  235. return false;
  236. case CSS::Selector::SimpleSelector::PseudoClass::Type::Scope:
  237. return scope ? &element == scope : is<HTML::HTMLHtmlElement>(element);
  238. case CSS::Selector::SimpleSelector::PseudoClass::Type::FirstOfType:
  239. return !previous_sibling_with_same_tag_name(element);
  240. case CSS::Selector::SimpleSelector::PseudoClass::Type::LastOfType:
  241. return !next_sibling_with_same_tag_name(element);
  242. case CSS::Selector::SimpleSelector::PseudoClass::Type::OnlyOfType:
  243. return !previous_sibling_with_same_tag_name(element) && !next_sibling_with_same_tag_name(element);
  244. case CSS::Selector::SimpleSelector::PseudoClass::Type::Lang:
  245. return matches_lang_pseudo_class(element, pseudo_class.languages);
  246. case CSS::Selector::SimpleSelector::PseudoClass::Type::Disabled:
  247. // https://html.spec.whatwg.org/multipage/semantics-other.html#selector-disabled
  248. // The :disabled pseudo-class must match any element that is actually disabled.
  249. return element.is_actually_disabled();
  250. case CSS::Selector::SimpleSelector::PseudoClass::Type::Enabled:
  251. // https://html.spec.whatwg.org/multipage/semantics-other.html#selector-enabled
  252. // The :enabled pseudo-class must match any button, input, select, textarea, optgroup, option, fieldset element, or form-associated custom element that is not actually disabled.
  253. return (is<HTML::HTMLButtonElement>(element) || is<HTML::HTMLInputElement>(element) || is<HTML::HTMLSelectElement>(element) || is<HTML::HTMLTextAreaElement>(element) || is<HTML::HTMLOptGroupElement>(element) || is<HTML::HTMLOptionElement>(element) || is<HTML::HTMLFieldSetElement>(element))
  254. && !element.is_actually_disabled();
  255. case CSS::Selector::SimpleSelector::PseudoClass::Type::Checked:
  256. return matches_checked_pseudo_class(element);
  257. case CSS::Selector::SimpleSelector::PseudoClass::Type::Indeterminate:
  258. return matches_indeterminate_pseudo_class(element);
  259. case CSS::Selector::SimpleSelector::PseudoClass::Type::Defined:
  260. return element.is_defined();
  261. case CSS::Selector::SimpleSelector::PseudoClass::Type::Is:
  262. case CSS::Selector::SimpleSelector::PseudoClass::Type::Where:
  263. for (auto& selector : pseudo_class.argument_selector_list) {
  264. if (matches(selector, element))
  265. return true;
  266. }
  267. return false;
  268. case CSS::Selector::SimpleSelector::PseudoClass::Type::Not:
  269. for (auto& selector : pseudo_class.argument_selector_list) {
  270. if (matches(selector, element))
  271. return false;
  272. }
  273. return true;
  274. case CSS::Selector::SimpleSelector::PseudoClass::Type::NthChild:
  275. case CSS::Selector::SimpleSelector::PseudoClass::Type::NthLastChild:
  276. case CSS::Selector::SimpleSelector::PseudoClass::Type::NthOfType:
  277. case CSS::Selector::SimpleSelector::PseudoClass::Type::NthLastOfType: {
  278. auto const step_size = pseudo_class.nth_child_pattern.step_size;
  279. auto const offset = pseudo_class.nth_child_pattern.offset;
  280. if (step_size == 0 && offset == 0)
  281. return false; // "If both a and b are equal to zero, the pseudo-class represents no element in the document tree."
  282. auto const* parent = element.parent_element();
  283. if (!parent)
  284. return false;
  285. auto matches_selector_list = [](CSS::SelectorList const& list, DOM::Element const& element) {
  286. if (list.is_empty())
  287. return true;
  288. for (auto const& child_selector : list) {
  289. if (matches(child_selector, element)) {
  290. return true;
  291. }
  292. }
  293. return false;
  294. };
  295. int index = 1;
  296. switch (pseudo_class.type) {
  297. case CSS::Selector::SimpleSelector::PseudoClass::Type::NthChild: {
  298. if (!matches_selector_list(pseudo_class.argument_selector_list, element))
  299. return false;
  300. for (auto* child = parent->first_child_of_type<DOM::Element>(); child && child != &element; child = child->next_element_sibling()) {
  301. if (matches_selector_list(pseudo_class.argument_selector_list, *child))
  302. ++index;
  303. }
  304. break;
  305. }
  306. case CSS::Selector::SimpleSelector::PseudoClass::Type::NthLastChild: {
  307. if (!matches_selector_list(pseudo_class.argument_selector_list, element))
  308. return false;
  309. for (auto* child = parent->last_child_of_type<DOM::Element>(); child && child != &element; child = child->previous_element_sibling()) {
  310. if (matches_selector_list(pseudo_class.argument_selector_list, *child))
  311. ++index;
  312. }
  313. break;
  314. }
  315. case CSS::Selector::SimpleSelector::PseudoClass::Type::NthOfType: {
  316. for (auto* child = previous_sibling_with_same_tag_name(element); child; child = previous_sibling_with_same_tag_name(*child))
  317. ++index;
  318. break;
  319. }
  320. case CSS::Selector::SimpleSelector::PseudoClass::Type::NthLastOfType: {
  321. for (auto* child = next_sibling_with_same_tag_name(element); child; child = next_sibling_with_same_tag_name(*child))
  322. ++index;
  323. break;
  324. }
  325. default:
  326. VERIFY_NOT_REACHED();
  327. }
  328. // When "step_size == -1", selector represents first "offset" elements in document tree.
  329. if (step_size == -1)
  330. return !(offset <= 0 || index > offset);
  331. // When "step_size == 1", selector represents last "offset" elements in document tree.
  332. if (step_size == 1)
  333. return !(offset < 0 || index < offset);
  334. // When "step_size == 0", selector picks only the "offset" element.
  335. if (step_size == 0)
  336. return index == offset;
  337. // If both are negative, nothing can match.
  338. if (step_size < 0 && offset < 0)
  339. return false;
  340. // Like "a % b", but handles negative integers correctly.
  341. auto const canonical_modulo = [](int a, int b) -> int {
  342. int c = a % b;
  343. if ((c < 0 && b > 0) || (c > 0 && b < 0)) {
  344. c += b;
  345. }
  346. return c;
  347. };
  348. // When "step_size < 0", we start at "offset" and count backwards.
  349. if (step_size < 0)
  350. return index <= offset && canonical_modulo(index - offset, -step_size) == 0;
  351. // Otherwise, we start at "offset" and count forwards.
  352. return index >= offset && canonical_modulo(index - offset, step_size) == 0;
  353. }
  354. case CSS::Selector::SimpleSelector::PseudoClass::Type::Playing: {
  355. if (!is<HTML::HTMLMediaElement>(element))
  356. return false;
  357. auto const& media_element = static_cast<HTML::HTMLMediaElement const&>(element);
  358. return !media_element.paused();
  359. }
  360. case CSS::Selector::SimpleSelector::PseudoClass::Type::Paused: {
  361. if (!is<HTML::HTMLMediaElement>(element))
  362. return false;
  363. auto const& media_element = static_cast<HTML::HTMLMediaElement const&>(element);
  364. return media_element.paused();
  365. }
  366. case CSS::Selector::SimpleSelector::PseudoClass::Type::Seeking: {
  367. if (!is<HTML::HTMLMediaElement>(element))
  368. return false;
  369. auto const& media_element = static_cast<HTML::HTMLMediaElement const&>(element);
  370. return media_element.seeking();
  371. }
  372. case CSS::Selector::SimpleSelector::PseudoClass::Type::Muted: {
  373. if (!is<HTML::HTMLMediaElement>(element))
  374. return false;
  375. auto const& media_element = static_cast<HTML::HTMLMediaElement const&>(element);
  376. return media_element.muted();
  377. }
  378. case CSS::Selector::SimpleSelector::PseudoClass::Type::VolumeLocked: {
  379. // FIXME: Currently we don't allow the user to specify an override volume, so this is always false.
  380. // Once we do, implement this!
  381. return false;
  382. }
  383. }
  384. return false;
  385. }
  386. static inline bool matches(CSS::Selector::SimpleSelector const& component, DOM::Element const& element, JS::GCPtr<DOM::ParentNode const> scope)
  387. {
  388. switch (component.type) {
  389. case CSS::Selector::SimpleSelector::Type::Universal:
  390. return true;
  391. case CSS::Selector::SimpleSelector::Type::Id:
  392. return component.name() == element.attribute(HTML::AttributeNames::id).view();
  393. case CSS::Selector::SimpleSelector::Type::Class:
  394. return element.has_class(component.name());
  395. case CSS::Selector::SimpleSelector::Type::TagName:
  396. // See https://html.spec.whatwg.org/multipage/semantics-other.html#case-sensitivity-of-selectors
  397. if (element.document().document_type() == DOM::Document::Type::HTML)
  398. return component.lowercase_name() == element.local_name().view();
  399. return Infra::is_ascii_case_insensitive_match(component.name(), element.local_name());
  400. case CSS::Selector::SimpleSelector::Type::Attribute:
  401. return matches_attribute(component.attribute(), element);
  402. case CSS::Selector::SimpleSelector::Type::PseudoClass:
  403. return matches_pseudo_class(component.pseudo_class(), element, scope);
  404. case CSS::Selector::SimpleSelector::Type::PseudoElement:
  405. // Pseudo-element matching/not-matching is handled in the top level matches().
  406. return true;
  407. default:
  408. VERIFY_NOT_REACHED();
  409. }
  410. }
  411. static inline bool matches(CSS::Selector const& selector, int component_list_index, DOM::Element const& element, JS::GCPtr<DOM::ParentNode const> scope)
  412. {
  413. auto& relative_selector = selector.compound_selectors()[component_list_index];
  414. for (auto& simple_selector : relative_selector.simple_selectors) {
  415. if (!matches(simple_selector, element, scope))
  416. return false;
  417. }
  418. switch (relative_selector.combinator) {
  419. case CSS::Selector::Combinator::None:
  420. return true;
  421. case CSS::Selector::Combinator::Descendant:
  422. VERIFY(component_list_index != 0);
  423. for (auto* ancestor = element.parent(); ancestor; ancestor = ancestor->parent()) {
  424. if (!is<DOM::Element>(*ancestor))
  425. continue;
  426. if (matches(selector, component_list_index - 1, static_cast<DOM::Element const&>(*ancestor), scope))
  427. return true;
  428. }
  429. return false;
  430. case CSS::Selector::Combinator::ImmediateChild:
  431. VERIFY(component_list_index != 0);
  432. if (!element.parent() || !is<DOM::Element>(*element.parent()))
  433. return false;
  434. return matches(selector, component_list_index - 1, static_cast<DOM::Element const&>(*element.parent()), scope);
  435. case CSS::Selector::Combinator::NextSibling:
  436. VERIFY(component_list_index != 0);
  437. if (auto* sibling = element.previous_element_sibling())
  438. return matches(selector, component_list_index - 1, *sibling, scope);
  439. return false;
  440. case CSS::Selector::Combinator::SubsequentSibling:
  441. VERIFY(component_list_index != 0);
  442. for (auto* sibling = element.previous_element_sibling(); sibling; sibling = sibling->previous_element_sibling()) {
  443. if (matches(selector, component_list_index - 1, *sibling, scope))
  444. return true;
  445. }
  446. return false;
  447. case CSS::Selector::Combinator::Column:
  448. TODO();
  449. }
  450. VERIFY_NOT_REACHED();
  451. }
  452. bool matches(CSS::Selector const& selector, DOM::Element const& element, Optional<CSS::Selector::PseudoElement> pseudo_element, JS::GCPtr<DOM::ParentNode const> scope)
  453. {
  454. VERIFY(!selector.compound_selectors().is_empty());
  455. if (pseudo_element.has_value() && selector.pseudo_element() != pseudo_element)
  456. return false;
  457. if (!pseudo_element.has_value() && selector.pseudo_element().has_value())
  458. return false;
  459. return matches(selector, selector.compound_selectors().size() - 1, element, scope);
  460. }
  461. }