#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "third_party/blink/renderer/core/css/selector_checker.h"
#include "base/auto_reset.h"
#include "third_party/blink/public/mojom/input/focus_type.mojom-blink.h"
#include "third_party/blink/renderer/core/css/check_pseudo_has_argument_context.h"
#include "third_party/blink/renderer/core/css/check_pseudo_has_cache_scope.h"
#include "third_party/blink/renderer/core/css/css_selector_list.h"
#include "third_party/blink/renderer/core/css/part_names.h"
#include "third_party/blink/renderer/core/css/post_style_update_scope.h"
#include "third_party/blink/renderer/core/css/style_engine.h"
#include "third_party/blink/renderer/core/css/style_rule.h"
#include "third_party/blink/renderer/core/css/style_scope_data.h"
#include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/dom/element.h"
#include "third_party/blink/renderer/core/dom/element_traversal.h"
#include "third_party/blink/renderer/core/dom/flat_tree_traversal.h"
#include "third_party/blink/renderer/core/dom/node_computed_style.h"
#include "third_party/blink/renderer/core/dom/nth_index_cache.h"
#include "third_party/blink/renderer/core/dom/popover_data.h"
#include "third_party/blink/renderer/core/dom/scroll_marker_pseudo_element.h"
#include "third_party/blink/renderer/core/dom/shadow_root.h"
#include "third_party/blink/renderer/core/dom/slot_assignment_engine.h"
#include "third_party/blink/renderer/core/dom/text.h"
#include "third_party/blink/renderer/core/editing/frame_selection.h"
#include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/core/frame/picture_in_picture_controller.h"
#include "third_party/blink/renderer/core/frame/settings.h"
#include "third_party/blink/renderer/core/fullscreen/fullscreen.h"
#include "third_party/blink/renderer/core/html/custom/element_internals.h"
#include "third_party/blink/renderer/core/html/forms/html_button_element.h"
#include "third_party/blink/renderer/core/html/forms/html_field_set_element.h"
#include "third_party/blink/renderer/core/html/forms/html_form_control_element.h"
#include "third_party/blink/renderer/core/html/forms/html_input_element.h"
#include "third_party/blink/renderer/core/html/forms/html_option_element.h"
#include "third_party/blink/renderer/core/html/forms/html_select_element.h"
#include "third_party/blink/renderer/core/html/html_details_element.h"
#include "third_party/blink/renderer/core/html/html_dialog_element.h"
#include "third_party/blink/renderer/core/html/html_document.h"
#include "third_party/blink/renderer/core/html/html_frame_element_base.h"
#include "third_party/blink/renderer/core/html/html_permission_element.h"
#include "third_party/blink/renderer/core/html/html_slot_element.h"
#include "third_party/blink/renderer/core/html/media/html_audio_element.h"
#include "third_party/blink/renderer/core/html/media/html_video_element.h"
#include "third_party/blink/renderer/core/html/parser/html_parser_idioms.h"
#include "third_party/blink/renderer/core/html/shadow/shadow_element_names.h"
#include "third_party/blink/renderer/core/html/track/vtt/vtt_element.h"
#include "third_party/blink/renderer/core/html_names.h"
#include "third_party/blink/renderer/core/layout/custom_scrollbar.h"
#include "third_party/blink/renderer/core/page/focus_controller.h"
#include "third_party/blink/renderer/core/page/page.h"
#include "third_party/blink/renderer/core/page/scrolling/fragment_anchor.h"
#include "third_party/blink/renderer/core/page/spatial_navigation.h"
#include "third_party/blink/renderer/core/page/spatial_navigation_controller.h"
#include "third_party/blink/renderer/core/probe/core_probes.h"
#include "third_party/blink/renderer/core/scroll/scrollable_area.h"
#include "third_party/blink/renderer/core/scroll/scrollbar_theme.h"
#include "third_party/blink/renderer/core/style/computed_style.h"
#include "third_party/blink/renderer/core/svg/svg_element.h"
#include "third_party/blink/renderer/core/view_transition/view_transition.h"
#include "third_party/blink/renderer/core/view_transition/view_transition_utils.h"
#include "third_party/blink/renderer/platform/runtime_enabled_features.h"
namespace blink {
static bool IsFrameFocused(const Element& element) { … }
static bool MatchesSpatialNavigationFocusPseudoClass(const Element& element) { … }
static bool MatchesHasDatalistPseudoClass(const Element& element) { … }
static bool MatchesListBoxPseudoClass(const Element& element) { … }
static bool MatchesMultiSelectFocusPseudoClass(const Element& element) { … }
static bool MatchesTagName(const Element& element,
const QualifiedName& tag_q_name) { … }
static Element* ParentElement(
const SelectorChecker::SelectorCheckingContext& context) { … }
static const HTMLSlotElement* FindSlotElementInScope(
const SelectorChecker::SelectorCheckingContext& context) { … }
static inline bool NextSelectorExceedsScope(
const SelectorChecker::SelectorCheckingContext& context) { … }
static bool ShouldMatchHoverOrActive(
const SelectorChecker::SelectorCheckingContext& context) { … }
static bool Impacts(const SelectorChecker::SelectorCheckingContext& context,
SelectorChecker::Impact impact) { … }
static bool ImpactsSubject(
const SelectorChecker::SelectorCheckingContext& context) { … }
static bool ImpactsNonSubject(
const SelectorChecker::SelectorCheckingContext& context) { … }
static bool IsFirstChild(const Element& element) { … }
static bool IsLastChild(const Element& element) { … }
static bool IsFirstOfType(const Element& element, const QualifiedName& type) { … }
static bool IsLastOfType(const Element& element, const QualifiedName& type) { … }
static void DisallowMatchVisited(
SelectorChecker::SelectorCheckingContext& context) { … }
bool SelectorChecker::Match(const SelectorCheckingContext& context,
MatchResult& result) const { … }
SelectorChecker::MatchStatus SelectorChecker::MatchSelector(
const SelectorCheckingContext& context,
MatchResult& result) const { … }
static inline SelectorChecker::SelectorCheckingContext
PrepareNextContextForRelation(
const SelectorChecker::SelectorCheckingContext& context) { … }
SelectorChecker::MatchStatus SelectorChecker::MatchForSubSelector(
const SelectorCheckingContext& context,
MatchResult& result) const { … }
SelectorChecker::MatchStatus SelectorChecker::MatchForScopeActivation(
const SelectorCheckingContext& context,
MatchResult& result) const { … }
SelectorChecker::MatchStatus SelectorChecker::MatchForRelation(
const SelectorCheckingContext& context,
MatchResult& result) const { … }
static bool AttributeValueMatches(const Attribute& attribute_item,
CSSSelector::MatchType match,
const AtomicString& selector_value,
TextCaseSensitivity case_sensitivity) { … }
static bool AnyAttributeMatches(Element& element,
CSSSelector::MatchType match,
const CSSSelector& selector) { … }
ALWAYS_INLINE bool SelectorChecker::CheckOne(
const SelectorCheckingContext& context,
MatchResult& result) const { … }
bool SelectorChecker::CheckPseudoNot(const SelectorCheckingContext& context,
MatchResult& result) const { … }
bool SelectorChecker::MatchesAnyInList(const SelectorCheckingContext& context,
const CSSSelector* selector_list,
MatchResult& result) const { … }
namespace {
Element* TraverseToParent(Element* element) { … }
Element* TraverseToPreviousSibling(Element* element) { … }
inline bool CacheMatchedElementsAndReturnMatchedResultForIndirectRelation(
Element* has_anchor_element,
HeapVector<Member<Element>>& has_argument_leftmost_compound_matches,
CheckPseudoHasCacheScope::Context& cache_scope_context,
Element* (*next)(Element*)) { … }
inline bool CacheMatchedElementsAndReturnMatchedResultForDirectRelation(
Element* has_anchor_element,
HeapVector<Member<Element>>& has_argument_leftmost_compound_matches,
CheckPseudoHasCacheScope::Context& cache_scope_context,
Element* (*next)(Element*)) { … }
inline bool CacheMatchedElementsAndReturnMatchedResult(
CSSSelector::RelationType leftmost_relation,
Element* has_anchor_element,
HeapVector<Member<Element>>& has_argument_leftmost_compound_matches,
CheckPseudoHasCacheScope::Context& cache_scope_context) { … }
inline bool ContextForSubjectHasInMatchesArgument(
const SelectorChecker::SelectorCheckingContext& has_checking_context) { … }
uint8_t SetHasAnchorElementAsCheckedAndGetOldResult(
const SelectorChecker::SelectorCheckingContext& has_checking_context,
CheckPseudoHasCacheScope::Context& cache_scope_context) { … }
void SetAffectedByHasFlagsForElementAtDepth(
CheckPseudoHasArgumentContext& argument_context,
Element* element,
int depth) { … }
void SetAffectedByHasFlagsForHasAnchorElement(
CheckPseudoHasArgumentContext& argument_context,
Element* has_anchor_element) { … }
void SetAffectedByHasFlagsForHasAnchorSiblings(
CheckPseudoHasArgumentContext& argument_context,
Element* has_anchor_element) { … }
void SetAffectedByHasForArgumentMatchedElement(
CheckPseudoHasArgumentContext& argument_context,
Element* has_anchor_element,
Element* argument_matched_element,
int argument_matched_depth) { … }
bool SkipCheckingHasArgument(
CheckPseudoHasArgumentContext& context,
CheckPseudoHasArgumentTraversalIterator& iterator) { … }
void AddElementIdentifierHashesInTraversalScopeAndSetAffectedByHasFlags(
CheckPseudoHasFastRejectFilter& fast_reject_filter,
Element& has_anchor_element,
CheckPseudoHasArgumentContext& argument_context,
bool update_affected_by_has_flags) { … }
void SetAllElementsInTraversalScopeAsChecked(
Element* has_anchor_element,
CheckPseudoHasArgumentContext& argument_context,
CheckPseudoHasCacheScope::Context& cache_scope_context) { … }
enum EarlyBreakOnHasArgumentChecking { … };
EarlyBreakOnHasArgumentChecking CheckEarlyBreakForHasArgument(
const SelectorChecker::SelectorCheckingContext& context,
Element* has_anchor_element,
CheckPseudoHasArgumentContext& argument_context,
CheckPseudoHasCacheScope::Context& cache_scope_context,
bool& update_affected_by_has_flags) { … }
bool MatchesExternalSVGUseTarget(Element& element) { … }
}
bool SelectorChecker::CheckPseudoHas(const SelectorCheckingContext& context,
MatchResult& result) const { … }
bool SelectorChecker::CheckPseudoClass(const SelectorCheckingContext& context,
MatchResult& result) const { … }
static bool MatchesUAShadowElement(Element& element, const AtomicString& id) { … }
bool SelectorChecker::CheckPseudoAutofill(CSSSelector::PseudoType pseudo_type,
Element& element) const { … }
bool SelectorChecker::CheckPseudoElement(const SelectorCheckingContext& context,
MatchResult& result) const { … }
bool SelectorChecker::CheckPseudoHost(const SelectorCheckingContext& context,
MatchResult& result) const { … }
bool SelectorChecker::CheckPseudoScope(const SelectorCheckingContext& context,
MatchResult& result) const { … }
bool SelectorChecker::CheckScrollbarPseudoClass(
const SelectorCheckingContext& context,
MatchResult& result) const { … }
bool SelectorChecker::MatchesSelectorFragmentAnchorPseudoClass(
const Element& element) { … }
bool SelectorChecker::MatchesFocusPseudoClass(const Element& element,
bool has_scroll_marker_pseudo) { … }
bool SelectorChecker::MatchesFocusVisiblePseudoClass(const Element& element) { … }
namespace {
StyleScopeActivations& DefaultActivations(const ContainerNode* scope) { … }
const Element* ActivationCeiling(const StyleScopeActivation& activation) { … }
bool HasImplicitRoot(const StyleScope& style_scope, Element& element) { … }
}
const StyleScopeActivations& SelectorChecker::EnsureActivations(
const SelectorCheckingContext& context,
const StyleScope& style_scope) const { … }
const StyleScopeActivations* SelectorChecker::CalculateActivations(
Element& element,
const StyleScope& style_scope,
const StyleScopeActivations& outer_activations,
StyleScopeFrame* style_scope_frame,
bool match_visited) const { … }
bool SelectorChecker::MatchesWithScope(Element& element,
const CSSSelector& selector_list,
const ContainerNode* scope,
bool match_visited,
MatchFlags& match_flags) const { … }
bool SelectorChecker::ElementIsScopingLimit(
const StyleScope& style_scope,
const StyleScopeActivation& activation,
Element& element,
bool match_visited,
MatchFlags& match_flags) const { … }
}