| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 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. | 3 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc.
All rights reserved. |
| 4 * | 4 * |
| 5 * This library is free software; you can redistribute it and/or | 5 * This library is free software; you can redistribute it and/or |
| 6 * modify it under the terms of the GNU Library General Public | 6 * modify it under the terms of the GNU Library General Public |
| 7 * License as published by the Free Software Foundation; either | 7 * License as published by the Free Software Foundation; either |
| 8 * version 2 of the License, or (at your option) any later version. | 8 * version 2 of the License, or (at your option) any later version. |
| 9 * | 9 * |
| 10 * This library is distributed in the hope that it will be useful, | 10 * This library is distributed in the hope that it will be useful, |
| 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 * Library General Public License for more details. | 13 * Library General Public License for more details. |
| 14 * | 14 * |
| 15 * You should have received a copy of the GNU Library General Public License | 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 | 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, | 17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 18 * Boston, MA 02110-1301, USA. | 18 * Boston, MA 02110-1301, USA. |
| 19 * | 19 * |
| 20 */ | 20 */ |
| 21 | 21 |
| 22 #ifndef RuleFeature_h | 22 #ifndef RuleFeature_h |
| 23 #define RuleFeature_h | 23 #define RuleFeature_h |
| 24 | 24 |
| 25 #include "core/CoreExport.h" | 25 #include "core/CoreExport.h" |
| 26 #include "core/css/CSSSelector.h" | 26 #include "core/css/CSSSelector.h" |
| 27 #include "core/css/invalidation/DescendantInvalidationSet.h" | 27 #include "core/css/invalidation/InvalidationData.h" |
| 28 #include "wtf/Forward.h" | 28 #include "wtf/Forward.h" |
| 29 #include "wtf/HashSet.h" | 29 #include "wtf/HashSet.h" |
| 30 #include "wtf/text/AtomicStringHash.h" | 30 #include "wtf/text/AtomicStringHash.h" |
| 31 | 31 |
| 32 namespace blink { | 32 namespace blink { |
| 33 | 33 |
| 34 class QualifiedName; | 34 class QualifiedName; |
| 35 class RuleData; | 35 class RuleData; |
| 36 class SpaceSplitString; | 36 class SpaceSplitString; |
| 37 class StyleRule; | 37 class StyleRule; |
| 38 | 38 |
| 39 struct RuleFeature { | 39 struct RuleFeature { |
| 40 ALLOW_ONLY_INLINE_ALLOCATION(); | 40 ALLOW_ONLY_INLINE_ALLOCATION(); |
| 41 public: | 41 public: |
| 42 RuleFeature(StyleRule*, unsigned selectorIndex, bool hasDocumentSecurityOrig
in); | 42 RuleFeature(StyleRule*, unsigned selectorIndex, bool hasDocumentSecurityOrig
in); |
| 43 | 43 |
| 44 DECLARE_TRACE(); | 44 DECLARE_TRACE(); |
| 45 | 45 |
| 46 RawPtrWillBeMember<StyleRule> rule; | 46 RawPtrWillBeMember<StyleRule> rule; |
| 47 unsigned selectorIndex; | 47 unsigned selectorIndex; |
| 48 bool hasDocumentSecurityOrigin; | 48 bool hasDocumentSecurityOrigin; |
| 49 }; | 49 }; |
| 50 | 50 |
| 51 using InvalidationSetVector = WillBeHeapVector<RefPtrWillBeMember<DescendantInva
lidationSet>, 8>; | |
| 52 | |
| 53 class CORE_EXPORT RuleFeatureSet { | 51 class CORE_EXPORT RuleFeatureSet { |
| 54 DISALLOW_ALLOCATION(); | 52 DISALLOW_ALLOCATION(); |
| 55 public: | 53 public: |
| 56 RuleFeatureSet(); | 54 RuleFeatureSet(); |
| 57 ~RuleFeatureSet(); | 55 ~RuleFeatureSet(); |
| 58 | 56 |
| 59 void add(const RuleFeatureSet&); | 57 void add(const RuleFeatureSet&); |
| 60 void clear(); | 58 void clear(); |
| 61 | 59 |
| 62 void collectFeaturesFromRuleData(const RuleData&); | 60 void collectFeaturesFromRuleData(const RuleData&); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 75 } | 73 } |
| 76 | 74 |
| 77 bool hasSelectorForClass(const AtomicString& classValue) const | 75 bool hasSelectorForClass(const AtomicString& classValue) const |
| 78 { | 76 { |
| 79 ASSERT(!classValue.isEmpty()); | 77 ASSERT(!classValue.isEmpty()); |
| 80 return m_classInvalidationSets.contains(classValue); | 78 return m_classInvalidationSets.contains(classValue); |
| 81 } | 79 } |
| 82 | 80 |
| 83 bool hasSelectorForId(const AtomicString& idValue) const { return m_idInvali
dationSets.contains(idValue); } | 81 bool hasSelectorForId(const AtomicString& idValue) const { return m_idInvali
dationSets.contains(idValue); } |
| 84 | 82 |
| 85 void collectInvalidationSetsForClass(InvalidationSetVector&, Element&, const
AtomicString& className) const; | 83 // Collect descendant and sibling invalidation sets. |
| 86 void collectInvalidationSetsForId(InvalidationSetVector&, Element&, const At
omicString& id) const; | 84 void collectInvalidationSetsForClass(InvalidationSetVector&, InvalidationSet
Vector&, Element&, const AtomicString& className) const; |
| 87 void collectInvalidationSetsForAttribute(InvalidationSetVector&, Element&, c
onst QualifiedName& attributeName) const; | 85 void collectInvalidationSetsForId(InvalidationSetVector&, InvalidationSetVec
tor&, Element&, const AtomicString& id) const; |
| 88 void collectInvalidationSetsForPseudoClass(InvalidationSetVector&, Element&,
CSSSelector::PseudoType) const; | 86 void collectInvalidationSetsForAttribute(InvalidationSetVector&, Invalidatio
nSetVector&, Element&, const QualifiedName& attributeName) const; |
| 87 void collectInvalidationSetsForPseudoClass(InvalidationSetVector&, Invalidat
ionSetVector&, Element&, CSSSelector::PseudoType) const; |
| 89 | 88 |
| 90 bool hasIdsInSelectors() const | 89 bool hasIdsInSelectors() const |
| 91 { | 90 { |
| 92 return m_idInvalidationSets.size() > 0; | 91 return m_idInvalidationSets.size() > 0; |
| 93 } | 92 } |
| 94 | 93 |
| 95 DECLARE_TRACE(); | 94 DECLARE_TRACE(); |
| 96 | 95 |
| 97 WillBeHeapVector<RuleFeature> siblingRules; | 96 WillBeHeapVector<RuleFeature> siblingRules; |
| 98 WillBeHeapVector<RuleFeature> uncommonAttributeRules; | 97 WillBeHeapVector<RuleFeature> uncommonAttributeRules; |
| 99 | 98 |
| 100 protected: | 99 protected: |
| 101 DescendantInvalidationSet* invalidationSetForSelector(const CSSSelector&); | 100 DescendantInvalidationSet* invalidationSetForSelector(const CSSSelector&, In
validateType); |
| 102 | 101 |
| 103 private: | 102 private: |
| 104 using InvalidationSetMap = WillBeHeapHashMap<AtomicString, RefPtrWillBeMembe
r<DescendantInvalidationSet>>; | 103 using InvalidationSetMap = WillBeHeapHashMap<AtomicString, RefPtrWillBeMembe
r<InvalidationData>>; |
| 105 using PseudoTypeInvalidationSetMap = WillBeHeapHashMap<CSSSelector::PseudoTy
pe, RefPtrWillBeMember<DescendantInvalidationSet>, WTF::IntHash<unsigned>, WTF::
UnsignedWithZeroKeyHashTraits<unsigned>>; | 104 using PseudoTypeInvalidationSetMap = WillBeHeapHashMap<CSSSelector::PseudoTy
pe, RefPtrWillBeMember<InvalidationData>, WTF::IntHash<unsigned>, WTF::UnsignedW
ithZeroKeyHashTraits<unsigned>>; |
| 106 | 105 |
| 107 struct FeatureMetadata { | 106 struct FeatureMetadata { |
| 108 DISALLOW_ALLOCATION(); | 107 DISALLOW_ALLOCATION(); |
| 109 FeatureMetadata() | 108 FeatureMetadata() |
| 110 : usesFirstLineRules(false) | 109 : usesFirstLineRules(false) |
| 111 , usesWindowInactiveSelector(false) | 110 , usesWindowInactiveSelector(false) |
| 112 , foundSiblingSelector(false) | 111 , foundSiblingSelector(false) |
| 113 , maxDirectAdjacentSelectors(0) | 112 , maxDirectAdjacentSelectors(0) |
| 114 { } | 113 { } |
| 115 void add(const FeatureMetadata& other); | 114 void add(const FeatureMetadata& other); |
| 116 void clear(); | 115 void clear(); |
| 117 | 116 |
| 118 bool usesFirstLineRules; | 117 bool usesFirstLineRules; |
| 119 bool usesWindowInactiveSelector; | 118 bool usesWindowInactiveSelector; |
| 120 bool foundSiblingSelector; | 119 bool foundSiblingSelector; |
| 121 unsigned maxDirectAdjacentSelectors; | 120 unsigned maxDirectAdjacentSelectors; |
| 122 }; | 121 }; |
| 123 | 122 |
| 124 void collectFeaturesFromSelector(const CSSSelector&, FeatureMetadata&); | 123 void collectFeaturesFromSelector(const CSSSelector&, FeatureMetadata&); |
| 125 | 124 |
| 126 DescendantInvalidationSet& ensureClassInvalidationSet(const AtomicString& cl
assName); | 125 template<class Map> |
| 127 DescendantInvalidationSet& ensureAttributeInvalidationSet(const AtomicString
& attributeName); | 126 static InvalidationData& ensureInvalidationData(Map&, const typename Map::Ke
yType&); |
| 128 DescendantInvalidationSet& ensureIdInvalidationSet(const AtomicString& attri
buteName); | 127 |
| 129 DescendantInvalidationSet& ensurePseudoInvalidationSet(CSSSelector::PseudoTy
pe); | 128 InvalidationData& ensureClassInvalidationData(const AtomicString& className)
{ return ensureInvalidationData(m_classInvalidationSets, className); } |
| 129 InvalidationData& ensureAttributeInvalidationData(const AtomicString& attrib
uteName) { return ensureInvalidationData(m_attributeInvalidationSets, attributeN
ame); } |
| 130 InvalidationData& ensureIdInvalidationData(const AtomicString& id) { return
ensureInvalidationData(m_idInvalidationSets, id); } |
| 131 InvalidationData& ensurePseudoInvalidationData(CSSSelector::PseudoType pseud
oType) { return ensureInvalidationData(m_pseudoInvalidationSets, pseudoType); } |
| 132 |
| 133 DescendantInvalidationSet& ensureClassInvalidationSet(const AtomicString& cl
assName, InvalidateType type) { return ensureClassInvalidationData(className).en
sureInvalidationSet(type); } |
| 134 DescendantInvalidationSet& ensureAttributeInvalidationSet(const AtomicString
& attributeName, InvalidateType type) { return ensureAttributeInvalidationData(a
ttributeName).ensureInvalidationSet(type); } |
| 135 DescendantInvalidationSet& ensureIdInvalidationSet(const AtomicString& id, I
nvalidateType type) { return ensureIdInvalidationData(id).ensureInvalidationSet(
type); } |
| 136 DescendantInvalidationSet& ensurePseudoInvalidationSet(CSSSelector::PseudoTy
pe pseudoType, InvalidateType type) { return ensurePseudoInvalidationData(pseudo
Type).ensureInvalidationSet(type); } |
| 130 | 137 |
| 131 void updateInvalidationSets(const RuleData&); | 138 void updateInvalidationSets(const RuleData&); |
| 132 void updateInvalidationSetsForContentAttribute(const RuleData&); | 139 void updateInvalidationSetsForContentAttribute(const RuleData&); |
| 133 | 140 |
| 134 struct InvalidationSetFeatures { | 141 struct InvalidationSetFeatures { |
| 135 DISALLOW_ALLOCATION(); | 142 DISALLOW_ALLOCATION(); |
| 136 InvalidationSetFeatures() | 143 InvalidationSetFeatures() |
| 137 : customPseudoElement(false) | 144 : maxDirectAdjacentSelectors(std::numeric_limits<unsigned>::max()) |
| 145 , customPseudoElement(false) |
| 138 , hasBeforeOrAfter(false) | 146 , hasBeforeOrAfter(false) |
| 139 , treeBoundaryCrossing(false) | 147 , treeBoundaryCrossing(false) |
| 140 , adjacent(false) | 148 , adjacent(false) |
| 141 , insertionPointCrossing(false) | 149 , insertionPointCrossing(false) |
| 142 , forceSubtree(false) | 150 , forceSubtree(false) |
| 143 { } | 151 { } |
| 144 | 152 |
| 145 bool useSubtreeInvalidation() const { return forceSubtree || adjacent; } | |
| 146 | |
| 147 Vector<AtomicString> classes; | 153 Vector<AtomicString> classes; |
| 148 Vector<AtomicString> attributes; | 154 Vector<AtomicString> attributes; |
| 149 AtomicString id; | 155 AtomicString id; |
| 150 AtomicString tagName; | 156 AtomicString tagName; |
| 157 unsigned maxDirectAdjacentSelectors; |
| 151 bool customPseudoElement; | 158 bool customPseudoElement; |
| 152 bool hasBeforeOrAfter; | 159 bool hasBeforeOrAfter; |
| 153 bool treeBoundaryCrossing; | 160 bool treeBoundaryCrossing; |
| 154 bool adjacent; | 161 bool adjacent; |
| 155 bool insertionPointCrossing; | 162 bool insertionPointCrossing; |
| 156 bool forceSubtree; | 163 bool forceSubtree; |
| 157 }; | 164 }; |
| 158 | 165 |
| 159 static bool extractInvalidationSetFeature(const CSSSelector&, InvalidationSe
tFeatures&); | 166 static bool extractInvalidationSetFeature(const CSSSelector&, InvalidationSe
tFeatures&); |
| 160 | 167 |
| 161 enum UseFeaturesType { UseFeatures, ForceSubtree }; | 168 enum UseFeaturesType { UseFeatures, ForceSubtree }; |
| 162 | 169 |
| 163 std::pair<const CSSSelector*, UseFeaturesType> extractInvalidationSetFeature
s(const CSSSelector&, InvalidationSetFeatures&, bool negated); | 170 std::pair<const CSSSelector*, UseFeaturesType> extractInvalidationSetFeature
s(const CSSSelector&, InvalidationSetFeatures&, bool negated); |
| 164 | 171 |
| 165 void addFeaturesToInvalidationSet(DescendantInvalidationSet&, const Invalida
tionSetFeatures&); | 172 void addFeaturesToInvalidationSet(DescendantInvalidationSet&, const Invalida
tionSetFeatures&); |
| 166 void addFeaturesToInvalidationSets(const CSSSelector&, InvalidationSetFeatur
es&); | 173 void addFeaturesToInvalidationSets(const CSSSelector*, InvalidationSetFeatur
es*, InvalidationSetFeatures&); |
| 167 | 174 |
| 168 void addClassToInvalidationSet(const AtomicString& className, Element&); | 175 void addClassToInvalidationSet(const AtomicString& className, Element&); |
| 169 | 176 |
| 170 FeatureMetadata m_metadata; | 177 FeatureMetadata m_metadata; |
| 171 InvalidationSetMap m_classInvalidationSets; | 178 InvalidationSetMap m_classInvalidationSets; |
| 172 InvalidationSetMap m_attributeInvalidationSets; | 179 InvalidationSetMap m_attributeInvalidationSets; |
| 173 InvalidationSetMap m_idInvalidationSets; | 180 InvalidationSetMap m_idInvalidationSets; |
| 174 PseudoTypeInvalidationSetMap m_pseudoInvalidationSets; | 181 PseudoTypeInvalidationSetMap m_pseudoInvalidationSets; |
| 182 |
| 183 friend class RuleFeatureSetTest; |
| 175 }; | 184 }; |
| 176 | 185 |
| 186 template<class Map> |
| 187 InvalidationData& RuleFeatureSet::ensureInvalidationData(Map& map, const typenam
e Map::KeyType& key) |
| 188 { |
| 189 typename Map::AddResult addResult = map.add(key, nullptr); |
| 190 if (addResult.isNewEntry) |
| 191 addResult.storedValue->value = InvalidationData::create(); |
| 192 return *addResult.storedValue->value; |
| 193 } |
| 194 |
| 177 } // namespace blink | 195 } // namespace blink |
| 178 | 196 |
| 179 WTF_ALLOW_MOVE_AND_INIT_WITH_MEM_FUNCTIONS(blink::RuleFeature); | 197 WTF_ALLOW_MOVE_AND_INIT_WITH_MEM_FUNCTIONS(blink::RuleFeature); |
| 180 | 198 |
| 181 #endif // RuleFeature_h | 199 #endif // RuleFeature_h |
| OLD | NEW |