| 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; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 } | 75 } |
| 76 | 76 |
| 77 bool hasSelectorForClass(const AtomicString& classValue) const | 77 bool hasSelectorForClass(const AtomicString& classValue) const |
| 78 { | 78 { |
| 79 ASSERT(!classValue.isEmpty()); | 79 ASSERT(!classValue.isEmpty()); |
| 80 return m_classInvalidationSets.contains(classValue); | 80 return m_classInvalidationSets.contains(classValue); |
| 81 } | 81 } |
| 82 | 82 |
| 83 bool hasSelectorForId(const AtomicString& idValue) const { return m_idInvali
dationSets.contains(idValue); } | 83 bool hasSelectorForId(const AtomicString& idValue) const { return m_idInvali
dationSets.contains(idValue); } |
| 84 | 84 |
| 85 void collectInvalidationSetsForClass(InvalidationSetVector&, Element&, const
AtomicString& className) const; | 85 // Collect descendant and sibling invalidation sets. |
| 86 void collectInvalidationSetsForId(InvalidationSetVector&, Element&, const At
omicString& id) const; | 86 void collectInvalidationSetsForClass(InvalidationSetVector&, InvalidationSet
Vector&, Element&, const AtomicString& className) const; |
| 87 void collectInvalidationSetsForAttribute(InvalidationSetVector&, Element&, c
onst QualifiedName& attributeName) const; | 87 void collectInvalidationSetsForId(InvalidationSetVector&, InvalidationSetVec
tor&, Element&, const AtomicString& id) const; |
| 88 void collectInvalidationSetsForPseudoClass(InvalidationSetVector&, Element&,
CSSSelector::PseudoType) const; | 88 void collectInvalidationSetsForAttribute(InvalidationSetVector&, Invalidatio
nSetVector&, Element&, const QualifiedName& attributeName) const; |
| 89 void collectInvalidationSetsForPseudoClass(InvalidationSetVector&, Invalidat
ionSetVector&, Element&, CSSSelector::PseudoType) const; |
| 89 | 90 |
| 90 bool hasIdsInSelectors() const | 91 bool hasIdsInSelectors() const |
| 91 { | 92 { |
| 92 return m_idInvalidationSets.size() > 0; | 93 return m_idInvalidationSets.size() > 0; |
| 93 } | 94 } |
| 94 | 95 |
| 95 DECLARE_TRACE(); | 96 DECLARE_TRACE(); |
| 96 | 97 |
| 97 WillBeHeapVector<RuleFeature> siblingRules; | 98 WillBeHeapVector<RuleFeature> siblingRules; |
| 98 WillBeHeapVector<RuleFeature> uncommonAttributeRules; | 99 WillBeHeapVector<RuleFeature> uncommonAttributeRules; |
| 99 | 100 |
| 100 protected: | 101 protected: |
| 101 DescendantInvalidationSet* invalidationSetForSelector(const CSSSelector&); | 102 DescendantInvalidationSet* invalidationSetForSelector(const CSSSelector&, In
validateType); |
| 102 | 103 |
| 103 private: | 104 private: |
| 104 using InvalidationSetMap = WillBeHeapHashMap<AtomicString, RefPtrWillBeMembe
r<DescendantInvalidationSet>>; | 105 using InvalidationSetMap = WillBeHeapHashMap<AtomicString, RefPtrWillBeMembe
r<InvalidationData>>; |
| 105 using PseudoTypeInvalidationSetMap = WillBeHeapHashMap<CSSSelector::PseudoTy
pe, RefPtrWillBeMember<DescendantInvalidationSet>, WTF::IntHash<unsigned>, WTF::
UnsignedWithZeroKeyHashTraits<unsigned>>; | 106 using PseudoTypeInvalidationSetMap = WillBeHeapHashMap<CSSSelector::PseudoTy
pe, RefPtrWillBeMember<InvalidationData>, WTF::IntHash<unsigned>, WTF::UnsignedW
ithZeroKeyHashTraits<unsigned>>; |
| 106 | 107 |
| 107 struct FeatureMetadata { | 108 struct FeatureMetadata { |
| 108 DISALLOW_ALLOCATION(); | 109 DISALLOW_ALLOCATION(); |
| 109 FeatureMetadata() | 110 FeatureMetadata() |
| 110 : usesFirstLineRules(false) | 111 : usesFirstLineRules(false) |
| 111 , usesWindowInactiveSelector(false) | 112 , usesWindowInactiveSelector(false) |
| 112 , foundSiblingSelector(false) | 113 , foundSiblingSelector(false) |
| 113 , maxDirectAdjacentSelectors(0) | 114 , maxDirectAdjacentSelectors(0) |
| 114 { } | 115 { } |
| 115 void add(const FeatureMetadata& other); | 116 void add(const FeatureMetadata& other); |
| 116 void clear(); | 117 void clear(); |
| 117 | 118 |
| 118 bool usesFirstLineRules; | 119 bool usesFirstLineRules; |
| 119 bool usesWindowInactiveSelector; | 120 bool usesWindowInactiveSelector; |
| 120 bool foundSiblingSelector; | 121 bool foundSiblingSelector; |
| 121 unsigned maxDirectAdjacentSelectors; | 122 unsigned maxDirectAdjacentSelectors; |
| 122 }; | 123 }; |
| 123 | 124 |
| 124 void collectFeaturesFromSelector(const CSSSelector&, FeatureMetadata&); | 125 void collectFeaturesFromSelector(const CSSSelector&, FeatureMetadata&); |
| 125 | 126 |
| 126 DescendantInvalidationSet& ensureClassInvalidationSet(const AtomicString& cl
assName); | 127 template<class Map> |
| 127 DescendantInvalidationSet& ensureAttributeInvalidationSet(const AtomicString
& attributeName); | 128 static InvalidationData& ensureInvalidationData(Map&, const typename Map::Ke
yType&); |
| 128 DescendantInvalidationSet& ensureIdInvalidationSet(const AtomicString& attri
buteName); | 129 |
| 129 DescendantInvalidationSet& ensurePseudoInvalidationSet(CSSSelector::PseudoTy
pe); | 130 InvalidationData& ensureClassInvalidationData(const AtomicString& className)
{ return ensureInvalidationData(m_classInvalidationSets, className); } |
| 131 InvalidationData& ensureAttributeInvalidationData(const AtomicString& attrib
uteName) { return ensureInvalidationData(m_attributeInvalidationSets, attributeN
ame); } |
| 132 InvalidationData& ensureIdInvalidationData(const AtomicString& id) { return
ensureInvalidationData(m_idInvalidationSets, id); } |
| 133 InvalidationData& ensurePseudoInvalidationData(CSSSelector::PseudoType pseud
oType) { return ensureInvalidationData(m_pseudoInvalidationSets, pseudoType); } |
| 134 |
| 135 DescendantInvalidationSet& ensureClassInvalidationSet(const AtomicString& cl
assName, InvalidateType type) { return ensureClassInvalidationData(className).en
sureInvalidationSet(type); } |
| 136 DescendantInvalidationSet& ensureAttributeInvalidationSet(const AtomicString
& attributeName, InvalidateType type) { return ensureAttributeInvalidationData(a
ttributeName).ensureInvalidationSet(type); } |
| 137 DescendantInvalidationSet& ensureIdInvalidationSet(const AtomicString& id, I
nvalidateType type) { return ensureIdInvalidationData(id).ensureInvalidationSet(
type); } |
| 138 DescendantInvalidationSet& ensurePseudoInvalidationSet(CSSSelector::PseudoTy
pe pseudoType, InvalidateType type) { return ensurePseudoInvalidationData(pseudo
Type).ensureInvalidationSet(type); } |
| 130 | 139 |
| 131 void updateInvalidationSets(const RuleData&); | 140 void updateInvalidationSets(const RuleData&); |
| 132 void updateInvalidationSetsForContentAttribute(const RuleData&); | 141 void updateInvalidationSetsForContentAttribute(const RuleData&); |
| 133 | 142 |
| 134 struct InvalidationSetFeatures { | 143 struct InvalidationSetFeatures { |
| 135 DISALLOW_ALLOCATION(); | 144 DISALLOW_ALLOCATION(); |
| 136 InvalidationSetFeatures() | 145 InvalidationSetFeatures() |
| 137 : customPseudoElement(false) | 146 : maxDirectAdjacentSelectors(std::numeric_limits<unsigned>::max()) |
| 147 , customPseudoElement(false) |
| 138 , hasBeforeOrAfter(false) | 148 , hasBeforeOrAfter(false) |
| 139 , treeBoundaryCrossing(false) | 149 , treeBoundaryCrossing(false) |
| 140 , adjacent(false) | 150 , adjacent(false) |
| 141 , insertionPointCrossing(false) | 151 , insertionPointCrossing(false) |
| 142 , forceSubtree(false) | 152 , forceSubtree(false) |
| 143 { } | 153 { } |
| 144 | 154 |
| 145 bool useSubtreeInvalidation() const { return forceSubtree || adjacent; } | |
| 146 | |
| 147 Vector<AtomicString> classes; | 155 Vector<AtomicString> classes; |
| 148 Vector<AtomicString> attributes; | 156 Vector<AtomicString> attributes; |
| 149 AtomicString id; | 157 AtomicString id; |
| 150 AtomicString tagName; | 158 AtomicString tagName; |
| 159 unsigned maxDirectAdjacentSelectors; |
| 151 bool customPseudoElement; | 160 bool customPseudoElement; |
| 152 bool hasBeforeOrAfter; | 161 bool hasBeforeOrAfter; |
| 153 bool treeBoundaryCrossing; | 162 bool treeBoundaryCrossing; |
| 154 bool adjacent; | 163 bool adjacent; |
| 155 bool insertionPointCrossing; | 164 bool insertionPointCrossing; |
| 156 bool forceSubtree; | 165 bool forceSubtree; |
| 157 }; | 166 }; |
| 158 | 167 |
| 159 static bool extractInvalidationSetFeature(const CSSSelector&, InvalidationSe
tFeatures&); | 168 static bool extractInvalidationSetFeature(const CSSSelector&, InvalidationSe
tFeatures&); |
| 160 | 169 |
| 161 enum UseFeaturesType { UseFeatures, ForceSubtree }; | 170 enum UseFeaturesType { UseFeatures, ForceSubtree }; |
| 162 | 171 |
| 163 std::pair<const CSSSelector*, UseFeaturesType> extractInvalidationSetFeature
s(const CSSSelector&, InvalidationSetFeatures&, bool negated); | 172 std::pair<const CSSSelector*, UseFeaturesType> extractInvalidationSetFeature
s(const CSSSelector&, InvalidationSetFeatures&, bool negated); |
| 164 | 173 |
| 165 void addFeaturesToInvalidationSet(DescendantInvalidationSet&, const Invalida
tionSetFeatures&); | 174 void addFeaturesToInvalidationSet(DescendantInvalidationSet&, const Invalida
tionSetFeatures&); |
| 166 void addFeaturesToInvalidationSets(const CSSSelector&, InvalidationSetFeatur
es&); | 175 void addFeaturesToInvalidationSets(const CSSSelector*, InvalidationSetFeatur
es&); |
| 167 | 176 |
| 168 void addClassToInvalidationSet(const AtomicString& className, Element&); | 177 void addClassToInvalidationSet(const AtomicString& className, Element&); |
| 169 | 178 |
| 170 FeatureMetadata m_metadata; | 179 FeatureMetadata m_metadata; |
| 171 InvalidationSetMap m_classInvalidationSets; | 180 InvalidationSetMap m_classInvalidationSets; |
| 172 InvalidationSetMap m_attributeInvalidationSets; | 181 InvalidationSetMap m_attributeInvalidationSets; |
| 173 InvalidationSetMap m_idInvalidationSets; | 182 InvalidationSetMap m_idInvalidationSets; |
| 174 PseudoTypeInvalidationSetMap m_pseudoInvalidationSets; | 183 PseudoTypeInvalidationSetMap m_pseudoInvalidationSets; |
| 184 |
| 185 friend class RuleFeatureSetTest; |
| 175 }; | 186 }; |
| 176 | 187 |
| 188 template<class Map> |
| 189 InvalidationData& RuleFeatureSet::ensureInvalidationData(Map& map, const typenam
e Map::KeyType& key) |
| 190 { |
| 191 typename Map::AddResult addResult = map.add(key, nullptr); |
| 192 if (addResult.isNewEntry) |
| 193 addResult.storedValue->value = InvalidationData::create(); |
| 194 return *addResult.storedValue->value; |
| 195 } |
| 196 |
| 177 } // namespace blink | 197 } // namespace blink |
| 178 | 198 |
| 179 WTF_ALLOW_MOVE_AND_INIT_WITH_MEM_FUNCTIONS(blink::RuleFeature); | 199 WTF_ALLOW_MOVE_AND_INIT_WITH_MEM_FUNCTIONS(blink::RuleFeature); |
| 180 | 200 |
| 181 #endif // RuleFeature_h | 201 #endif // RuleFeature_h |
| OLD | NEW |