#include "third_party/blink/renderer/core/css/selector_query.h"
#include <memory>
#include <utility>
#include "base/memory/ptr_util.h"
#include "third_party/blink/public/mojom/use_counter/metrics/web_feature.mojom-blink.h"
#include "third_party/blink/renderer/core/css/check_pseudo_has_cache_scope.h"
#include "third_party/blink/renderer/core/css/parser/css_parser.h"
#include "third_party/blink/renderer/core/css/parser/css_selector_parser.h"
#include "third_party/blink/renderer/core/css/selector_checker.h"
#include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/dom/element_traversal.h"
#include "third_party/blink/renderer/core/dom/node.h"
#include "third_party/blink/renderer/core/dom/nth_index_cache.h"
#include "third_party/blink/renderer/core/dom/shadow_root.h"
#include "third_party/blink/renderer/core/dom/static_node_list.h"
#include "third_party/blink/renderer/core/html/html_document.h"
#include "third_party/blink/renderer/core/html_names.h"
#include "third_party/blink/renderer/platform/bindings/exception_state.h"
#include "third_party/blink/renderer/platform/heap/garbage_collected.h"
namespace blink {
#if DCHECK_IS_ON() || defined(RELEASE_QUERY_STATS)
static SelectorQuery::QueryStats& CurrentQueryStats() { … }
SelectorQuery::QueryStats SelectorQuery::LastQueryStats() { … }
#define QUERY_STATS_INCREMENT(name) …
#define QUERY_STATS_RESET() …
#else
#define QUERY_STATS_INCREMENT …
#define QUERY_STATS_RESET …
#endif
struct SingleElementSelectorQueryTrait { … };
struct AllElementsSelectorQueryTrait { … };
inline bool SelectorMatches(const CSSSelector& selector,
Element& element,
const ContainerNode& root_node,
const SelectorChecker& checker) { … }
bool SelectorQuery::Matches(Element& target_element) const { … }
Element* SelectorQuery::Closest(Element& target_element) const { … }
StaticElementList* SelectorQuery::QueryAll(ContainerNode& root_node) const { … }
Element* SelectorQuery::QueryFirst(ContainerNode& root_node) const { … }
template <typename SelectorQueryTrait>
static void CollectElementsByClassName(
ContainerNode& root_node,
const AtomicString& class_name,
const CSSSelector* selector,
typename SelectorQueryTrait::OutputType& output) { … }
inline bool MatchesTagName(const QualifiedName& tag_name,
const Element& element) { … }
template <typename SelectorQueryTrait>
static void CollectElementsByTagName(
ContainerNode& root_node,
const QualifiedName& tag_name,
typename SelectorQueryTrait::OutputType& output) { … }
static bool AttributeValueMatchesExact(const Attribute& attribute_item,
const AtomicString& selector_value,
TextCaseSensitivity case_sensitivity) { … }
static bool NeedsSynchronizeAttribute(const QualifiedName& qname,
bool is_html_doc) { … }
template <typename SelectorQueryTrait>
static void CollectElementsByAttributeExact(
ContainerNode& root_node,
const CSSSelector& selector,
typename SelectorQueryTrait::OutputType& output) { … }
inline bool AncestorHasClassName(ContainerNode& root_node,
const AtomicString& class_name) { … }
template <typename SelectorQueryTrait>
void SelectorQuery::FindTraverseRootsAndExecute(
ContainerNode& root_node,
typename SelectorQueryTrait::OutputType& output) const { … }
template <typename SelectorQueryTrait>
void SelectorQuery::ExecuteForTraverseRoot(
ContainerNode& traverse_root,
ContainerNode& root_node,
typename SelectorQueryTrait::OutputType& output) const { … }
bool SelectorQuery::SelectorListMatches(ContainerNode& root_node,
Element& element) const { … }
template <typename SelectorQueryTrait>
void SelectorQuery::ExecuteSlow(
ContainerNode& root_node,
typename SelectorQueryTrait::OutputType& output) const { … }
template <typename SelectorQueryTrait>
void SelectorQuery::ExecuteWithId(
ContainerNode& root_node,
typename SelectorQueryTrait::OutputType& output) const { … }
template <typename SelectorQueryTrait>
void SelectorQuery::Execute(
ContainerNode& root_node,
typename SelectorQueryTrait::OutputType& output) const { … }
std::unique_ptr<SelectorQuery> SelectorQuery::Adopt(
CSSSelectorList* selector_list) { … }
SelectorQuery::SelectorQuery(CSSSelectorList* selector_list)
: … { … }
SelectorQuery* SelectorQueryCache::Add(const AtomicString& selectors,
const Document& document,
ExceptionState& exception_state) { … }
void SelectorQueryCache::Invalidate() { … }
}