chromium/third_party/blink/renderer/core/css/rule_set.cc

/*
 * Copyright (C) 1999 Lars Knoll ([email protected])
 *           (C) 2004-2005 Allan Sandfeld Jensen ([email protected])
 * Copyright (C) 2006, 2007 Nicholas Shanks ([email protected])
 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All
 * rights reserved.
 * Copyright (C) 2007 Alexey Proskuryakov <[email protected]>
 * Copyright (C) 2007, 2008 Eric Seidel <[email protected]>
 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved.
 * (http://www.torchmobile.com/)
 * Copyright (c) 2011, Code Aurora Forum. All rights reserved.
 * Copyright (C) Research In Motion Limited 2011. All rights reserved.
 * Copyright (C) 2012 Google Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public License
 * along with this library; see the file COPYING.LIB.  If not, write to
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 */

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/351564777): Remove this and convert code to safer constructs.
#pragma allow_unsafe_buffers
#endif

#include "third_party/blink/renderer/core/css/rule_set.h"

#include <memory>
#include <type_traits>
#include <vector>

#include "base/containers/contains.h"
#include "base/substring_set_matcher/substring_set_matcher.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/blink/renderer/core/css/css_font_selector.h"
#include "third_party/blink/renderer/core/css/css_selector.h"
#include "third_party/blink/renderer/core/css/css_selector_list.h"
#include "third_party/blink/renderer/core/css/robin_hood_map-inl.h"
#include "third_party/blink/renderer/core/css/seeker.h"
#include "third_party/blink/renderer/core/css/selector_checker-inl.h"
#include "third_party/blink/renderer/core/css/selector_checker.h"
#include "third_party/blink/renderer/core/css/selector_filter.h"
#include "third_party/blink/renderer/core/css/style_rule_import.h"
#include "third_party/blink/renderer/core/css/style_rule_nested_declarations.h"
#include "third_party/blink/renderer/core/css/style_sheet_contents.h"
#include "third_party/blink/renderer/core/html/shadow/shadow_element_names.h"
#include "third_party/blink/renderer/core/html/track/text_track_cue.h"
#include "third_party/blink/renderer/core/html_names.h"
#include "third_party/blink/renderer/core/inspector/invalidation_set_to_selector_map.h"
#include "third_party/blink/renderer/core/style/computed_style_constants.h"
#include "third_party/blink/renderer/platform/instrumentation/tracing/trace_event.h"
#include "third_party/blink/renderer/platform/weborigin/security_origin.h"

MatcherStringPattern;
SubstringSetMatcher;

namespace blink {

template <class T>
static void AddRuleToIntervals(const T* value,
                               unsigned position,
                               HeapVector<RuleSet::Interval<T>>& intervals);

static void UnmarkAsCoveredByBucketing(CSSSelector& selector);

static inline ValidPropertyFilter DetermineValidPropertyFilter(
    const AddRuleFlags add_rule_flags,
    const CSSSelector& selector) {}

static bool SelectorListHasLinkOrVisited(const CSSSelector* selector_list) {}

static bool StyleScopeHasLinkOrVisited(const StyleScope* style_scope) {}

static unsigned DetermineLinkMatchType(const AddRuleFlags add_rule_flags,
                                       const CSSSelector& selector,
                                       const StyleScope* style_scope) {}

RuleData::RuleData(StyleRule* rule,
                   unsigned selector_index,
                   unsigned position,
                   const StyleScope* style_scope,
                   AddRuleFlags add_rule_flags,
                   Vector<unsigned>& bloom_hash_backing)
    :{}

void RuleData::ComputeEntirelyCoveredByBucketing() {}

void RuleData::ResetEntirelyCoveredByBucketing() {}

void RuleData::ComputeBloomFilterHashes(const StyleScope* style_scope,
                                        Vector<unsigned>& bloom_hash_backing) {}

void RuleData::MovedToDifferentRuleSet(const Vector<unsigned>& old_backing,
                                       Vector<unsigned>& new_backing,
                                       unsigned new_position) {}

void RuleSet::AddToRuleSet(const AtomicString& key,
                           RuleMap& map,
                           const RuleData& rule_data) {}

void RuleSet::AddToRuleSet(HeapVector<RuleData>& rules,
                           const RuleData& rule_data) {}

static void ExtractSelectorValues(const CSSSelector* selector,
                                  AtomicString& id,
                                  AtomicString& class_name,
                                  AtomicString& attr_name,
                                  AtomicString& attr_value,
                                  bool& is_exact_attr,
                                  AtomicString& custom_pseudo_element_name,
                                  AtomicString& tag_name,
                                  AtomicString& part_name,
                                  AtomicString& picker_name,
                                  CSSSelector::PseudoType& pseudo_type) {}

// For a (possibly compound) selector, extract the values used for determining
// its buckets (e.g. for “.foo[baz]”, will return foo for class_name and
// baz for attr_name). Returns the last subselector in the group, which is also
// the one given the highest priority.
static const CSSSelector* ExtractBestSelectorValues(
    const CSSSelector& component,
    AtomicString& id,
    AtomicString& class_name,
    AtomicString& attr_name,
    AtomicString& attr_value,
    bool& is_exact_attr,
    AtomicString& custom_pseudo_element_name,
    AtomicString& tag_name,
    AtomicString& part_name,
    AtomicString& picker_name,
    CSSSelector::PseudoType& pseudo_type) {}

template <class Func>
static void MarkAsCoveredByBucketing(CSSSelector& selector,
                                     Func&& should_mark_func) {}

static void UnmarkAsCoveredByBucketing(CSSSelector& selector) {}

template <RuleSet::BucketCoverage bucket_coverage>
void RuleSet::FindBestRuleSetAndAdd(CSSSelector& component,
                                    const RuleData& rule_data) {}

void RuleSet::AddRule(StyleRule* rule,
                      unsigned selector_index,
                      AddRuleFlags add_rule_flags,
                      const ContainerQuery* container_query,
                      const CascadeLayer* cascade_layer,
                      const StyleScope* style_scope) {}

void RuleSet::AddRuleToLayerIntervals(const CascadeLayer* cascade_layer,
                                      unsigned position) {}

// Similar to AddRuleToLayerIntervals, but for container queries and @style
// scopes.
template <class T>
static void AddRuleToIntervals(const T* value,
                               unsigned position,
                               HeapVector<RuleSet::Interval<T>>& intervals) {}

void RuleSet::AddPageRule(StyleRulePage* rule) {}

void RuleSet::AddFontFaceRule(StyleRuleFontFace* rule) {}

void RuleSet::AddKeyframesRule(StyleRuleKeyframes* rule) {}

void RuleSet::AddPropertyRule(StyleRuleProperty* rule) {}

void RuleSet::AddCounterStyleRule(StyleRuleCounterStyle* rule) {}

void RuleSet::AddFontPaletteValuesRule(StyleRuleFontPaletteValues* rule) {}

void RuleSet::AddFontFeatureValuesRule(StyleRuleFontFeatureValues* rule) {}

void RuleSet::AddPositionTryRule(StyleRulePositionTry* rule) {}

void RuleSet::AddFunctionRule(StyleRuleFunction* rule) {}

void RuleSet::AddViewTransitionRule(StyleRuleViewTransition* rule) {}

void RuleSet::AddChildRules(StyleRule* parent_rule,
                            const HeapVector<Member<StyleRuleBase>>& rules,
                            const MediaQueryEvaluator& medium,
                            AddRuleFlags add_rule_flags,
                            const ContainerQuery* container_query,
                            CascadeLayer* cascade_layer,
                            const StyleScope* style_scope,
                            bool within_mixin) {}

bool RuleSet::MatchMediaForAddRules(const MediaQueryEvaluator& evaluator,
                                    const MediaQuerySet* media_queries) {}

void RuleSet::AddRulesFromSheet(StyleSheetContents* sheet,
                                const MediaQueryEvaluator& medium,
                                CascadeLayer* cascade_layer) {}

// If there's a reference to the parent selector (implicit or explicit)
// somewhere in the selector, use that to find the parent StyleRule.
// If not, it's not relevant what the parent is anyway.
const StyleRule* FindParentIfUsed(const CSSSelector* selector) {}

// Whether we should include the given rule (coming from a RuleSet)
// in a diff rule set, based on the list on “only_include” (which are
// the ones that have been modified). This is nominally only a simple
// membership test, but we also need to take into account nested rules;
// if a parent rule of ours has been modified, we need to also include
// this rule.
static bool IncludeRule(const StyleRule* style_rule,
                        const HeapHashSet<Member<StyleRule>>& only_include) {}

void RuleSet::NewlyAddedFromDifferentRuleSet(const RuleData& old_rule_data,
                                             const StyleScope* style_scope,
                                             const RuleSet& old_rule_set,
                                             RuleData& new_rule_data) {}

void RuleSet::AddFilteredRulesFromOtherBucket(
    const RuleSet& other,
    const HeapVector<RuleData>& src,
    const HeapHashSet<Member<StyleRule>>& only_include,
    HeapVector<RuleData>* dst) {}

void RuleSet::AddFilteredRulesFromOtherSet(
    const RuleSet& other,
    const HeapHashSet<Member<StyleRule>>& only_include) {}

void RuleSet::AddStyleRule(StyleRule* style_rule,
                           StyleRule* parent_rule,
                           const MediaQueryEvaluator& medium,
                           AddRuleFlags add_rule_flags,
                           bool within_mixin,
                           const ContainerQuery* container_query,
                           CascadeLayer* cascade_layer,
                           const StyleScope* style_scope) {}

CascadeLayer* RuleSet::GetOrAddSubLayer(CascadeLayer* cascade_layer,
                                        const StyleRuleBase::LayerName& name) {}

bool RuleMap::Add(const AtomicString& key, const RuleData& rule_data) {}

void RuleMap::Compact() {}

void RuleMap::Uncompact() {}

// See RuleSet::AddFilteredRulesFromOtherSet().
void RuleMap::AddFilteredRulesFromOtherSet(
    const RuleMap& other,
    const HeapHashSet<Member<StyleRule>>& only_include,
    const RuleSet& old_rule_set,
    RuleSet& new_rule_set) {}

static wtf_size_t GetMinimumRulesetSizeForSubstringMatcher() {}

bool RuleSet::CanIgnoreEntireList(base::span<const RuleData> list,
                                  const AtomicString& key,
                                  const AtomicString& value) const {}

void RuleSet::CreateSubstringMatchers(
    RuleMap& attr_map,
    RuleSet::SubstringMatcherMap& substring_matcher_map) {}

void RuleSet::CompactRules() {}

#if EXPENSIVE_DCHECKS_ARE_ON()

namespace {

// Rules that depend on visited link status may be added twice to the same
// bucket (with different LinkMatchTypes).
bool AllowSamePosition(const RuleData& current, const RuleData& previous) {}

template <class RuleList>
bool IsRuleListSorted(const RuleList& rules) {}

}  // namespace

void RuleSet::AssertRuleListsSorted() const {}

#endif  // EXPENSIVE_DCHECKS_ARE_ON()

bool RuleSet::DidMediaQueryResultsChange(
    const MediaQueryEvaluator& evaluator) const {}

const CascadeLayer* RuleSet::GetLayerForTest(const RuleData& rule) const {}

void RuleData::Trace(Visitor* visitor) const {}

template <class T>
void RuleSet::Interval<T>::Trace(Visitor* visitor) const {}

void RuleSet::Trace(Visitor* visitor) const {}

#if DCHECK_IS_ON()
void RuleSet::Show() const {}
#endif  // DCHECK_IS_ON()

}  // namespace blink