2020-01-18 09:38:21 +01:00
|
|
|
/*
|
2024-10-04 13:19:50 +02:00
|
|
|
* Copyright (c) 2018-2024, Andreas Kling <andreas@ladybird.org>
|
2020-01-18 09:38:21 +01:00
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 09:38:21 +01:00
|
|
|
*/
|
|
|
|
|
|
2019-10-08 15:33:58 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
2026-01-04 10:59:52 +01:00
|
|
|
#include <AK/HashMap.h>
|
2020-03-07 10:32:51 +01:00
|
|
|
#include <LibWeb/CSS/Selector.h>
|
2020-07-26 19:37:56 +02:00
|
|
|
#include <LibWeb/DOM/Element.h>
|
2019-10-08 15:33:58 +02:00
|
|
|
|
2020-07-26 19:37:56 +02:00
|
|
|
namespace Web::SelectorEngine {
|
2020-03-07 10:27:02 +01:00
|
|
|
|
2024-07-13 09:19:30 -07:00
|
|
|
enum class SelectorKind {
|
|
|
|
|
Normal,
|
|
|
|
|
Relative,
|
|
|
|
|
};
|
|
|
|
|
|
2026-01-04 10:59:52 +01:00
|
|
|
enum class HasMatchResult : u8 {
|
|
|
|
|
Matched,
|
|
|
|
|
NotMatched,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct HasResultCacheKey {
|
|
|
|
|
CSS::Selector const* selector;
|
|
|
|
|
GC::Ptr<DOM::Element const> element;
|
|
|
|
|
|
2026-01-06 00:36:34 +01:00
|
|
|
void visit_edges(GC::Cell::Visitor& visitor)
|
|
|
|
|
{
|
|
|
|
|
visitor.visit(element);
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-04 10:59:52 +01:00
|
|
|
bool operator==(HasResultCacheKey const&) const = default;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct HasResultCacheKeyTraits : Traits<HasResultCacheKey> {
|
|
|
|
|
static unsigned hash(HasResultCacheKey const& key)
|
|
|
|
|
{
|
|
|
|
|
return pair_int_hash(ptr_hash(key.selector), ptr_hash(key.element.ptr()));
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
using HasResultCache = HashMap<HasResultCacheKey, HasMatchResult, HasResultCacheKeyTraits>;
|
|
|
|
|
|
2025-01-03 20:39:25 +03:00
|
|
|
struct MatchContext {
|
|
|
|
|
GC::Ptr<CSS::CSSStyleSheet const> style_sheet_for_rule {};
|
2025-01-29 03:31:46 +01:00
|
|
|
GC::Ptr<DOM::Element const> subject {};
|
2025-12-09 13:42:53 +00:00
|
|
|
GC::Ptr<DOM::Element const> slotted_element {}; // Only set when matching a ::slotted() pseudo-element
|
|
|
|
|
GC::Ptr<DOM::Element const> part_owning_parent {}; // Only set temporarily when matching a ::part() pseudo-element
|
2025-01-29 03:31:46 +01:00
|
|
|
bool collect_per_element_selector_involvement_metadata { false };
|
2025-04-17 13:39:30 +02:00
|
|
|
CSS::PseudoClassBitmap attempted_pseudo_class_matches {};
|
2026-01-04 10:59:52 +01:00
|
|
|
HasResultCache* has_result_cache { nullptr };
|
2025-01-03 20:39:25 +03:00
|
|
|
};
|
|
|
|
|
|
2025-03-20 16:56:46 +00:00
|
|
|
bool matches(CSS::Selector const&, DOM::Element const&, GC::Ptr<DOM::Element const> shadow_host, MatchContext& context, Optional<CSS::PseudoElement> = {}, GC::Ptr<DOM::ParentNode const> scope = {}, SelectorKind selector_kind = SelectorKind::Normal, GC::Ptr<DOM::Element const> anchor = nullptr);
|
2020-03-07 10:27:02 +01:00
|
|
|
|
|
|
|
|
}
|