| 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/MediaQueryEvaluator.h" |
| 27 #include "core/css/invalidation/InvalidationSet.h" | 28 #include "core/css/invalidation/InvalidationSet.h" |
| 28 #include "platform/heap/Handle.h" | 29 #include "platform/heap/Handle.h" |
| 29 #include "wtf/Forward.h" | 30 #include "wtf/Forward.h" |
| 30 #include "wtf/HashSet.h" | 31 #include "wtf/HashSet.h" |
| 31 #include "wtf/text/AtomicStringHash.h" | 32 #include "wtf/text/AtomicStringHash.h" |
| 32 | 33 |
| 33 namespace blink { | 34 namespace blink { |
| 34 | 35 |
| 35 struct InvalidationLists; | 36 struct InvalidationLists; |
| 36 class QualifiedName; | 37 class QualifiedName; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 void add(const RuleFeatureSet&); | 69 void add(const RuleFeatureSet&); |
| 69 void clear(); | 70 void clear(); |
| 70 | 71 |
| 71 enum SelectorPreMatch { SelectorNeverMatches, SelectorMayMatch }; | 72 enum SelectorPreMatch { SelectorNeverMatches, SelectorMayMatch }; |
| 72 | 73 |
| 73 SelectorPreMatch collectFeaturesFromRuleData(const RuleData&); | 74 SelectorPreMatch collectFeaturesFromRuleData(const RuleData&); |
| 74 | 75 |
| 75 bool usesSiblingRules() const { return !siblingRules.isEmpty(); } | 76 bool usesSiblingRules() const { return !siblingRules.isEmpty(); } |
| 76 bool usesFirstLineRules() const { return m_metadata.usesFirstLineRules; } | 77 bool usesFirstLineRules() const { return m_metadata.usesFirstLineRules; } |
| 77 bool usesWindowInactiveSelector() const { return m_metadata.usesWindowInacti
veSelector; } | 78 bool usesWindowInactiveSelector() const { return m_metadata.usesWindowInacti
veSelector; } |
| 79 bool needsFullRecalcForRuleSetInvalidation() const { return m_metadata.needs
FullRecalcForRuleSetInvalidation; } |
| 78 | 80 |
| 79 unsigned maxDirectAdjacentSelectors() const { return m_metadata.maxDirectAdj
acentSelectors; } | 81 unsigned maxDirectAdjacentSelectors() const { return m_metadata.maxDirectAdj
acentSelectors; } |
| 80 | 82 |
| 81 bool hasSelectorForAttribute(const AtomicString& attributeName) const | 83 bool hasSelectorForAttribute(const AtomicString& attributeName) const |
| 82 { | 84 { |
| 83 ASSERT(!attributeName.isEmpty()); | 85 ASSERT(!attributeName.isEmpty()); |
| 84 return m_attributeInvalidationSets.contains(attributeName); | 86 return m_attributeInvalidationSets.contains(attributeName); |
| 85 } | 87 } |
| 86 | 88 |
| 87 bool hasSelectorForClass(const AtomicString& classValue) const | 89 bool hasSelectorForClass(const AtomicString& classValue) const |
| (...skipping 12 matching lines...) Expand all Loading... |
| 100 | 102 |
| 101 bool hasIdsInSelectors() const | 103 bool hasIdsInSelectors() const |
| 102 { | 104 { |
| 103 return m_idInvalidationSets.size() > 0; | 105 return m_idInvalidationSets.size() > 0; |
| 104 } | 106 } |
| 105 | 107 |
| 106 DECLARE_TRACE(); | 108 DECLARE_TRACE(); |
| 107 | 109 |
| 108 HeapVector<RuleFeature> siblingRules; | 110 HeapVector<RuleFeature> siblingRules; |
| 109 HeapVector<RuleFeature> uncommonAttributeRules; | 111 HeapVector<RuleFeature> uncommonAttributeRules; |
| 112 MediaQueryResultList viewportDependentMediaQueryResults; |
| 113 MediaQueryResultList deviceDependentMediaQueryResults; |
| 110 | 114 |
| 111 protected: | 115 protected: |
| 112 InvalidationSet* invalidationSetForSelector(const CSSSelector&, Invalidation
Type); | 116 InvalidationSet* invalidationSetForSelector(const CSSSelector&, Invalidation
Type); |
| 113 | 117 |
| 114 private: | 118 private: |
| 115 // Each map entry is either a DescendantInvalidationSet or SiblingInvalidati
onSet. | 119 // Each map entry is either a DescendantInvalidationSet or SiblingInvalidati
onSet. |
| 116 // When both are needed, we store the SiblingInvalidationSet, and use it to
hold the DescendantInvalidationSet. | 120 // When both are needed, we store the SiblingInvalidationSet, and use it to
hold the DescendantInvalidationSet. |
| 117 using InvalidationSetMap = HashMap<AtomicString, RefPtr<InvalidationSet>>; | 121 using InvalidationSetMap = HashMap<AtomicString, RefPtr<InvalidationSet>>; |
| 118 using PseudoTypeInvalidationSetMap = HashMap<CSSSelector::PseudoType, RefPtr
<InvalidationSet>, WTF::IntHash<unsigned>, WTF::UnsignedWithZeroKeyHashTraits<un
signed>>; | 122 using PseudoTypeInvalidationSetMap = HashMap<CSSSelector::PseudoType, RefPtr
<InvalidationSet>, WTF::IntHash<unsigned>, WTF::UnsignedWithZeroKeyHashTraits<un
signed>>; |
| 119 | 123 |
| 120 struct FeatureMetadata { | 124 struct FeatureMetadata { |
| 121 DISALLOW_NEW(); | 125 DISALLOW_NEW(); |
| 122 void add(const FeatureMetadata& other); | 126 void add(const FeatureMetadata& other); |
| 123 void clear(); | 127 void clear(); |
| 124 | 128 |
| 125 bool usesFirstLineRules = false; | 129 bool usesFirstLineRules = false; |
| 126 bool usesWindowInactiveSelector = false; | 130 bool usesWindowInactiveSelector = false; |
| 127 bool foundSiblingSelector = false; | 131 bool foundSiblingSelector = false; |
| 128 bool foundInsertionPointCrossing = false; | 132 bool foundInsertionPointCrossing = false; |
| 133 bool needsFullRecalcForRuleSetInvalidation = false; |
| 129 unsigned maxDirectAdjacentSelectors = 0; | 134 unsigned maxDirectAdjacentSelectors = 0; |
| 130 }; | 135 }; |
| 131 | 136 |
| 132 SelectorPreMatch collectFeaturesFromSelector(const CSSSelector&, FeatureMeta
data&); | 137 SelectorPreMatch collectFeaturesFromSelector(const CSSSelector&, FeatureMeta
data&); |
| 133 | 138 |
| 134 InvalidationSet& ensureClassInvalidationSet(const AtomicString& className, I
nvalidationType); | 139 InvalidationSet& ensureClassInvalidationSet(const AtomicString& className, I
nvalidationType); |
| 135 InvalidationSet& ensureAttributeInvalidationSet(const AtomicString& attribut
eName, InvalidationType); | 140 InvalidationSet& ensureAttributeInvalidationSet(const AtomicString& attribut
eName, InvalidationType); |
| 136 InvalidationSet& ensureIdInvalidationSet(const AtomicString& id, Invalidatio
nType); | 141 InvalidationSet& ensureIdInvalidationSet(const AtomicString& id, Invalidatio
nType); |
| 137 InvalidationSet& ensurePseudoInvalidationSet(CSSSelector::PseudoType, Invali
dationType); | 142 InvalidationSet& ensurePseudoInvalidationSet(CSSSelector::PseudoType, Invali
dationType); |
| 138 | 143 |
| 139 void updateInvalidationSets(const RuleData&); | 144 void updateInvalidationSets(const RuleData&); |
| 140 void updateInvalidationSetsForContentAttribute(const RuleData&); | 145 void updateInvalidationSetsForContentAttribute(const RuleData&); |
| 141 | 146 |
| 142 struct InvalidationSetFeatures { | 147 struct InvalidationSetFeatures { |
| 143 DISALLOW_NEW(); | 148 DISALLOW_NEW(); |
| 144 | 149 |
| 145 Vector<AtomicString> classes; | 150 Vector<AtomicString> classes; |
| 146 Vector<AtomicString> attributes; | 151 Vector<AtomicString> attributes; |
| 147 AtomicString id; | 152 AtomicString id; |
| 148 AtomicString tagName; | 153 AtomicString tagName; |
| 149 unsigned maxDirectAdjacentSelectors = UINT_MAX; | 154 unsigned maxDirectAdjacentSelectors = UINT_MAX; |
| 150 bool customPseudoElement = false; | 155 bool customPseudoElement = false; |
| 151 bool hasBeforeOrAfter = false; | 156 bool hasBeforeOrAfter = false; |
| 152 bool treeBoundaryCrossing = false; | 157 bool treeBoundaryCrossing = false; |
| 153 bool adjacent = false; | 158 bool adjacent = false; |
| 154 bool insertionPointCrossing = false; | 159 bool insertionPointCrossing = false; |
| 155 bool forceSubtree = false; | 160 bool forceSubtree = false; |
| 156 bool contentPseudoCrossing = false; | 161 bool contentPseudoCrossing = false; |
| 157 bool invalidatesSlotted = false; | 162 bool invalidatesSlotted = false; |
| 163 bool containsIdClassAttributeOrTypeInScope = false; |
| 158 }; | 164 }; |
| 159 | 165 |
| 160 static bool extractInvalidationSetFeature(const CSSSelector&, InvalidationSe
tFeatures&); | 166 static bool extractInvalidationSetFeature(const CSSSelector&, InvalidationSe
tFeatures&); |
| 161 | 167 |
| 162 enum UseFeaturesType { UseFeatures, ForceSubtree }; | 168 enum UseFeaturesType { UseFeatures, ForceSubtree }; |
| 163 | 169 |
| 164 enum PositionType { Subject, Ancestor }; | 170 enum PositionType { Subject, Ancestor }; |
| 165 std::pair<const CSSSelector*, UseFeaturesType> extractInvalidationSetFeature
s(const CSSSelector&, InvalidationSetFeatures&, PositionType, CSSSelector::Pseud
oType = CSSSelector::PseudoUnknown); | 171 std::pair<const CSSSelector*, UseFeaturesType> extractInvalidationSetFeature
s(const CSSSelector&, InvalidationSetFeatures&, PositionType, CSSSelector::Pseud
oType = CSSSelector::PseudoUnknown); |
| 166 | 172 |
| 167 void addFeaturesToInvalidationSet(InvalidationSet&, const InvalidationSetFea
tures&); | 173 void addFeaturesToInvalidationSet(InvalidationSet&, const InvalidationSetFea
tures&); |
| 168 void addFeaturesToInvalidationSets(const CSSSelector*, InvalidationSetFeatur
es* siblingFeatures, InvalidationSetFeatures& descendantFeatures); | 174 void addFeaturesToInvalidationSets(const CSSSelector*, InvalidationSetFeatur
es* siblingFeatures, InvalidationSetFeatures& descendantFeatures); |
| 169 | 175 |
| 170 void addClassToInvalidationSet(const AtomicString& className, Element&); | 176 void addClassToInvalidationSet(const AtomicString& className, Element&); |
| 171 | 177 |
| 172 FeatureMetadata m_metadata; | 178 FeatureMetadata m_metadata; |
| 173 InvalidationSetMap m_classInvalidationSets; | 179 InvalidationSetMap m_classInvalidationSets; |
| 174 InvalidationSetMap m_attributeInvalidationSets; | 180 InvalidationSetMap m_attributeInvalidationSets; |
| 175 InvalidationSetMap m_idInvalidationSets; | 181 InvalidationSetMap m_idInvalidationSets; |
| 176 PseudoTypeInvalidationSetMap m_pseudoInvalidationSets; | 182 PseudoTypeInvalidationSetMap m_pseudoInvalidationSets; |
| 177 | 183 |
| 178 friend class RuleFeatureSetTest; | 184 friend class RuleFeatureSetTest; |
| 179 }; | 185 }; |
| 180 | 186 |
| 181 } // namespace blink | 187 } // namespace blink |
| 182 | 188 |
| 183 #endif // RuleFeature_h | 189 #endif // RuleFeature_h |
| OLD | NEW |