Oilpan: fix build after r202625.
[chromium-blink-merge.git] / third_party / WebKit / Source / core / css / RuleFeature.h
blobfc89ae7331f956176b10e943d99e499710c8695f
1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 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.
22 #ifndef RuleFeature_h
23 #define RuleFeature_h
25 #include "core/CoreExport.h"
26 #include "core/css/CSSSelector.h"
27 #include "core/css/invalidation/InvalidationSet.h"
28 #include "wtf/Forward.h"
29 #include "wtf/HashSet.h"
30 #include "wtf/text/AtomicStringHash.h"
32 namespace blink {
34 class QualifiedName;
35 class RuleData;
36 class SpaceSplitString;
37 class StyleRule;
39 struct RuleFeature {
40 ALLOW_ONLY_INLINE_ALLOCATION();
41 public:
42 RuleFeature(StyleRule*, unsigned selectorIndex, bool hasDocumentSecurityOrigin);
44 DECLARE_TRACE();
46 RawPtrWillBeMember<StyleRule> rule;
47 unsigned selectorIndex;
48 bool hasDocumentSecurityOrigin;
51 using InvalidationSetVector = WillBeHeapVector<RefPtrWillBeMember<InvalidationSet>, 8>;
53 class CORE_EXPORT RuleFeatureSet {
54 DISALLOW_ALLOCATION();
55 public:
56 RuleFeatureSet();
57 ~RuleFeatureSet();
59 void add(const RuleFeatureSet&);
60 void clear();
62 void collectFeaturesFromRuleData(const RuleData&);
64 bool usesSiblingRules() const { return !siblingRules.isEmpty(); }
65 bool usesFirstLineRules() const { return m_metadata.usesFirstLineRules; }
66 bool usesWindowInactiveSelector() const { return m_metadata.usesWindowInactiveSelector; }
68 unsigned maxDirectAdjacentSelectors() const { return m_metadata.maxDirectAdjacentSelectors; }
69 void setMaxDirectAdjacentSelectors(unsigned value) { m_metadata.maxDirectAdjacentSelectors = std::max(value, m_metadata.maxDirectAdjacentSelectors); }
71 bool hasSelectorForAttribute(const AtomicString& attributeName) const
73 ASSERT(!attributeName.isEmpty());
74 return m_attributeInvalidationSets.contains(attributeName);
77 bool hasSelectorForClass(const AtomicString& classValue) const
79 ASSERT(!classValue.isEmpty());
80 return m_classInvalidationSets.contains(classValue);
83 bool hasSelectorForId(const AtomicString& idValue) const { return m_idInvalidationSets.contains(idValue); }
85 void collectInvalidationSetsForClass(InvalidationSetVector&, Element&, const AtomicString& className) const;
86 void collectInvalidationSetsForId(InvalidationSetVector&, Element&, const AtomicString& id) const;
87 void collectInvalidationSetsForAttribute(InvalidationSetVector&, Element&, const QualifiedName& attributeName) const;
88 void collectInvalidationSetsForPseudoClass(InvalidationSetVector&, Element&, CSSSelector::PseudoType) const;
90 bool hasIdsInSelectors() const
92 return m_idInvalidationSets.size() > 0;
95 DECLARE_TRACE();
97 WillBeHeapVector<RuleFeature> siblingRules;
98 WillBeHeapVector<RuleFeature> uncommonAttributeRules;
100 protected:
101 InvalidationSet* invalidationSetForSelector(const CSSSelector&);
103 private:
104 using InvalidationSetMap = WillBeHeapHashMap<AtomicString, RefPtrWillBeMember<InvalidationSet>>;
105 using PseudoTypeInvalidationSetMap = WillBeHeapHashMap<CSSSelector::PseudoType, RefPtrWillBeMember<InvalidationSet>, WTF::IntHash<unsigned>, WTF::UnsignedWithZeroKeyHashTraits<unsigned>>;
107 struct FeatureMetadata {
108 DISALLOW_ALLOCATION();
109 FeatureMetadata()
110 : usesFirstLineRules(false)
111 , usesWindowInactiveSelector(false)
112 , foundSiblingSelector(false)
113 , maxDirectAdjacentSelectors(0)
115 void add(const FeatureMetadata& other);
116 void clear();
118 bool usesFirstLineRules;
119 bool usesWindowInactiveSelector;
120 bool foundSiblingSelector;
121 unsigned maxDirectAdjacentSelectors;
124 void collectFeaturesFromSelector(const CSSSelector&, FeatureMetadata&);
126 InvalidationSet& ensureClassInvalidationSet(const AtomicString& className);
127 InvalidationSet& ensureAttributeInvalidationSet(const AtomicString& attributeName);
128 InvalidationSet& ensureIdInvalidationSet(const AtomicString& attributeName);
129 InvalidationSet& ensurePseudoInvalidationSet(CSSSelector::PseudoType);
131 void updateInvalidationSets(const RuleData&);
132 void updateInvalidationSetsForContentAttribute(const RuleData&);
134 struct InvalidationSetFeatures {
135 DISALLOW_ALLOCATION();
136 InvalidationSetFeatures()
137 : customPseudoElement(false)
138 , hasBeforeOrAfter(false)
139 , treeBoundaryCrossing(false)
140 , adjacent(false)
141 , insertionPointCrossing(false)
142 , forceSubtree(false)
145 bool useSubtreeInvalidation() const { return forceSubtree || adjacent; }
147 Vector<AtomicString> classes;
148 Vector<AtomicString> attributes;
149 AtomicString id;
150 AtomicString tagName;
151 bool customPseudoElement;
152 bool hasBeforeOrAfter;
153 bool treeBoundaryCrossing;
154 bool adjacent;
155 bool insertionPointCrossing;
156 bool forceSubtree;
159 static bool extractInvalidationSetFeature(const CSSSelector&, InvalidationSetFeatures&);
161 enum UseFeaturesType { UseFeatures, ForceSubtree };
163 std::pair<const CSSSelector*, UseFeaturesType> extractInvalidationSetFeatures(const CSSSelector&, InvalidationSetFeatures&, bool negated);
165 void addFeaturesToInvalidationSet(InvalidationSet&, const InvalidationSetFeatures&);
166 void addFeaturesToInvalidationSets(const CSSSelector&, InvalidationSetFeatures&);
168 void addClassToInvalidationSet(const AtomicString& className, Element&);
170 FeatureMetadata m_metadata;
171 InvalidationSetMap m_classInvalidationSets;
172 InvalidationSetMap m_attributeInvalidationSets;
173 InvalidationSetMap m_idInvalidationSets;
174 PseudoTypeInvalidationSetMap m_pseudoInvalidationSets;
177 } // namespace blink
179 WTF_ALLOW_MOVE_AND_INIT_WITH_MEM_FUNCTIONS(blink::RuleFeature);
181 #endif // RuleFeature_h