2
* Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3
* Copyright (C) 2003-2011, 2014 Apple Inc. All rights reserved.
5
* This library is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU Library General Public
7
* License as published by the Free Software Foundation; either
8
* version 2 of the License, or (at your option) any later version.
10
* This library is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
* Library General Public License for more details.
15
* You should have received a copy of the GNU Library General Public License
16
* along with this library; see the file COPYING.LIB. If not, write to
17
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18
* Boston, MA 02110-1301, USA.
24
#include "CSSSelector.h"
25
#include <wtf/Forward.h>
26
#include <wtf/HashMap.h>
27
#include <wtf/HashSet.h>
28
#include <wtf/text/AtomString.h>
29
#include <wtf/text/AtomStringHash.h>
39
enum class MatchElement : uint8_t { Subject, Parent, Ancestor, DirectSibling, IndirectSibling, AnySibling, ParentSibling, AncestorSibling, Host };
40
constexpr unsigned matchElementCount = static_cast<unsigned>(MatchElement::Host) + 1;
43
RuleFeature(const RuleData&, Optional<MatchElement> = WTF::nullopt);
45
RefPtr<const StyleRule> styleRule;
46
uint16_t selectorIndex; // Keep in sync with RuleData's selectorIndex size.
47
uint16_t selectorListIndex; // Keep in sync with RuleData's selectorListIndex size.
48
Optional<MatchElement> matchElement { };
50
static_assert(sizeof(RuleFeature) <= 16, "RuleFeature is a frquently alocated object. Keep it small.");
52
struct RuleFeatureWithInvalidationSelector : public RuleFeature {
53
RuleFeatureWithInvalidationSelector(const RuleData& data, Optional<MatchElement> matchElement = WTF::nullopt, const CSSSelector* invalidationSelector = nullptr)
54
: RuleFeature(data, WTFMove(matchElement))
55
, invalidationSelector(invalidationSelector)
58
const CSSSelector* invalidationSelector { nullptr };
61
struct RuleFeatureSet {
62
void add(const RuleFeatureSet&);
65
void collectFeatures(const RuleData&);
66
void registerContentAttribute(const AtomString&);
68
HashSet<AtomString> idsInRules;
69
HashSet<AtomString> idsMatchingAncestorsInRules;
70
HashSet<AtomString> attributeCanonicalLocalNamesInRules;
71
HashSet<AtomString> attributeLocalNamesInRules;
72
HashSet<AtomString> contentAttributeNamesInRules;
73
Vector<RuleFeature> siblingRules;
74
Vector<RuleFeature> uncommonAttributeRules;
76
HashMap<AtomString, std::unique_ptr<Vector<RuleFeature>>> classRules;
77
HashMap<AtomString, std::unique_ptr<Vector<RuleFeatureWithInvalidationSelector>>> attributeRules;
78
HashSet<AtomString> classesAffectingHost;
79
HashSet<AtomString> attributesAffectingHost;
81
bool usesFirstLineRules { false };
82
bool usesFirstLetterRules { false };
85
static MatchElement computeNextMatchElement(MatchElement, CSSSelector::RelationType);
86
static MatchElement computeSubSelectorMatchElement(MatchElement, const CSSSelector&);
88
struct SelectorFeatures {
89
bool hasSiblingSelector { false };
91
Vector<std::pair<AtomString, MatchElement>, 32> classes;
92
Vector<std::pair<const CSSSelector*, MatchElement>, 32> attributes;
94
void recursivelyCollectFeaturesFromSelector(SelectorFeatures&, const CSSSelector&, MatchElement = MatchElement::Subject);
98
} // namespace WebCore