| 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/InvalidationSet.h" | 27 #include "core/css/invalidation/InvalidationData.h" |
| 28 #include "platform/heap/Handle.h" | 28 #include "platform/heap/Handle.h" |
| 29 #include "wtf/Forward.h" | 29 #include "wtf/Forward.h" |
| 30 #include "wtf/HashSet.h" | 30 #include "wtf/HashSet.h" |
| 31 #include "wtf/text/AtomicStringHash.h" | 31 #include "wtf/text/AtomicStringHash.h" |
| 32 | 32 |
| 33 namespace blink { | 33 namespace blink { |
| 34 | 34 |
| 35 struct InvalidationLists; |
| 35 class QualifiedName; | 36 class QualifiedName; |
| 36 class RuleData; | 37 class RuleData; |
| 37 class SpaceSplitString; | 38 class SpaceSplitString; |
| 38 class StyleRule; | 39 class StyleRule; |
| 39 | 40 |
| 40 struct RuleFeature { | 41 struct RuleFeature { |
| 41 ALLOW_ONLY_INLINE_ALLOCATION(); | 42 ALLOW_ONLY_INLINE_ALLOCATION(); |
| 42 public: | 43 public: |
| 43 RuleFeature(StyleRule*, unsigned selectorIndex, bool hasDocumentSecurityOrig
in); | 44 RuleFeature(StyleRule*, unsigned selectorIndex, bool hasDocumentSecurityOrig
in); |
| 44 | 45 |
| 45 DECLARE_TRACE(); | 46 DECLARE_TRACE(); |
| 46 | 47 |
| 47 RawPtrWillBeMember<StyleRule> rule; | 48 RawPtrWillBeMember<StyleRule> rule; |
| 48 unsigned selectorIndex; | 49 unsigned selectorIndex; |
| 49 bool hasDocumentSecurityOrigin; | 50 bool hasDocumentSecurityOrigin; |
| 50 }; | 51 }; |
| 51 | 52 |
| 52 using InvalidationSetVector = Vector<RefPtr<InvalidationSet>, 8>; | |
| 53 | |
| 54 class CORE_EXPORT RuleFeatureSet { | 53 class CORE_EXPORT RuleFeatureSet { |
| 55 DISALLOW_ALLOCATION(); | 54 DISALLOW_ALLOCATION(); |
| 56 public: | 55 public: |
| 57 RuleFeatureSet(); | 56 RuleFeatureSet(); |
| 58 ~RuleFeatureSet(); | 57 ~RuleFeatureSet(); |
| 59 | 58 |
| 60 void add(const RuleFeatureSet&); | 59 void add(const RuleFeatureSet&); |
| 61 void clear(); | 60 void clear(); |
| 62 | 61 |
| 63 void collectFeaturesFromRuleData(const RuleData&); | 62 void collectFeaturesFromRuleData(const RuleData&); |
| 64 | 63 |
| 65 bool usesSiblingRules() const { return !siblingRules.isEmpty(); } | 64 bool usesSiblingRules() const { return !siblingRules.isEmpty(); } |
| 66 bool usesFirstLineRules() const { return m_metadata.usesFirstLineRules; } | 65 bool usesFirstLineRules() const { return m_metadata.usesFirstLineRules; } |
| 67 bool usesWindowInactiveSelector() const { return m_metadata.usesWindowInacti
veSelector; } | 66 bool usesWindowInactiveSelector() const { return m_metadata.usesWindowInacti
veSelector; } |
| 68 | 67 |
| 69 unsigned maxDirectAdjacentSelectors() const { return m_metadata.maxDirectAdj
acentSelectors; } | 68 unsigned maxDirectAdjacentSelectors() const { return m_metadata.maxDirectAdj
acentSelectors; } |
| 70 void setMaxDirectAdjacentSelectors(unsigned value) { m_metadata.maxDirectAd
jacentSelectors = std::max(value, m_metadata.maxDirectAdjacentSelectors); } | |
| 71 | 69 |
| 72 bool hasSelectorForAttribute(const AtomicString& attributeName) const | 70 bool hasSelectorForAttribute(const AtomicString& attributeName) const |
| 73 { | 71 { |
| 74 ASSERT(!attributeName.isEmpty()); | 72 ASSERT(!attributeName.isEmpty()); |
| 75 return m_attributeInvalidationSets.contains(attributeName); | 73 return m_attributeInvalidationSets.contains(attributeName); |
| 76 } | 74 } |
| 77 | 75 |
| 78 bool hasSelectorForClass(const AtomicString& classValue) const | 76 bool hasSelectorForClass(const AtomicString& classValue) const |
| 79 { | 77 { |
| 80 ASSERT(!classValue.isEmpty()); | 78 ASSERT(!classValue.isEmpty()); |
| 81 return m_classInvalidationSets.contains(classValue); | 79 return m_classInvalidationSets.contains(classValue); |
| 82 } | 80 } |
| 83 | 81 |
| 84 bool hasSelectorForId(const AtomicString& idValue) const { return m_idInvali
dationSets.contains(idValue); } | 82 bool hasSelectorForId(const AtomicString& idValue) const { return m_idInvali
dationSets.contains(idValue); } |
| 85 | 83 |
| 86 void collectInvalidationSetsForClass(InvalidationSetVector&, Element&, const
AtomicString& className) const; | 84 // Collect descendant and sibling invalidation sets. |
| 87 void collectInvalidationSetsForId(InvalidationSetVector&, Element&, const At
omicString& id) const; | 85 void collectInvalidationSetsForClass(InvalidationLists&, Element&, const Ato
micString& className) const; |
| 88 void collectInvalidationSetsForAttribute(InvalidationSetVector&, Element&, c
onst QualifiedName& attributeName) const; | 86 void collectInvalidationSetsForId(InvalidationLists&, Element&, const Atomic
String& id) const; |
| 89 void collectInvalidationSetsForPseudoClass(InvalidationSetVector&, Element&,
CSSSelector::PseudoType) const; | 87 void collectInvalidationSetsForAttribute(InvalidationLists&, Element&, const
QualifiedName& attributeName) const; |
| 88 void collectInvalidationSetsForPseudoClass(InvalidationLists&, Element&, CSS
Selector::PseudoType) const; |
| 90 | 89 |
| 91 bool hasIdsInSelectors() const | 90 bool hasIdsInSelectors() const |
| 92 { | 91 { |
| 93 return m_idInvalidationSets.size() > 0; | 92 return m_idInvalidationSets.size() > 0; |
| 94 } | 93 } |
| 95 | 94 |
| 96 DECLARE_TRACE(); | 95 DECLARE_TRACE(); |
| 97 | 96 |
| 98 WillBeHeapVector<RuleFeature> siblingRules; | 97 WillBeHeapVector<RuleFeature> siblingRules; |
| 99 WillBeHeapVector<RuleFeature> uncommonAttributeRules; | 98 WillBeHeapVector<RuleFeature> uncommonAttributeRules; |
| 100 | 99 |
| 101 protected: | 100 protected: |
| 102 InvalidationSet* invalidationSetForSelector(const CSSSelector&); | 101 InvalidationSet* invalidationSetForSelector(const CSSSelector&, Invalidation
Type); |
| 103 | 102 |
| 104 private: | 103 private: |
| 105 using InvalidationSetMap = HashMap<AtomicString, RefPtr<InvalidationSet>>; | 104 using InvalidationSetMap = HashMap<AtomicString, RefPtr<InvalidationData>>; |
| 106 using PseudoTypeInvalidationSetMap = HashMap<CSSSelector::PseudoType, RefPtr
<InvalidationSet>, WTF::IntHash<unsigned>, WTF::UnsignedWithZeroKeyHashTraits<un
signed>>; | 105 using PseudoTypeInvalidationSetMap = HashMap<CSSSelector::PseudoType, RefPtr
<InvalidationData>, WTF::IntHash<unsigned>, WTF::UnsignedWithZeroKeyHashTraits<u
nsigned>>; |
| 107 | 106 |
| 108 struct FeatureMetadata { | 107 struct FeatureMetadata { |
| 109 DISALLOW_ALLOCATION(); | 108 DISALLOW_ALLOCATION(); |
| 110 FeatureMetadata() | 109 FeatureMetadata() |
| 111 : usesFirstLineRules(false) | 110 : usesFirstLineRules(false) |
| 112 , usesWindowInactiveSelector(false) | 111 , usesWindowInactiveSelector(false) |
| 113 , foundSiblingSelector(false) | 112 , foundSiblingSelector(false) |
| 114 , maxDirectAdjacentSelectors(0) | 113 , maxDirectAdjacentSelectors(0) |
| 115 { } | 114 { } |
| 116 void add(const FeatureMetadata& other); | 115 void add(const FeatureMetadata& other); |
| 117 void clear(); | 116 void clear(); |
| 118 | 117 |
| 119 bool usesFirstLineRules; | 118 bool usesFirstLineRules; |
| 120 bool usesWindowInactiveSelector; | 119 bool usesWindowInactiveSelector; |
| 121 bool foundSiblingSelector; | 120 bool foundSiblingSelector; |
| 122 unsigned maxDirectAdjacentSelectors; | 121 unsigned maxDirectAdjacentSelectors; |
| 123 }; | 122 }; |
| 124 | 123 |
| 125 void collectFeaturesFromSelector(const CSSSelector&, FeatureMetadata&); | 124 void collectFeaturesFromSelector(const CSSSelector&, FeatureMetadata&); |
| 126 | 125 |
| 127 InvalidationSet& ensureClassInvalidationSet(const AtomicString& className); | 126 InvalidationData& ensureClassInvalidationData(const AtomicString& className)
; |
| 128 InvalidationSet& ensureAttributeInvalidationSet(const AtomicString& attribut
eName); | 127 InvalidationData& ensureAttributeInvalidationData(const AtomicString& attrib
uteName); |
| 129 InvalidationSet& ensureIdInvalidationSet(const AtomicString& attributeName); | 128 InvalidationData& ensureIdInvalidationData(const AtomicString& id); |
| 130 InvalidationSet& ensurePseudoInvalidationSet(CSSSelector::PseudoType); | 129 InvalidationData& ensurePseudoInvalidationData(CSSSelector::PseudoType); |
| 130 |
| 131 InvalidationSet& ensureClassInvalidationSet(const AtomicString& className, I
nvalidationType type) { return ensureClassInvalidationData(className).ensureInva
lidationSet(type); } |
| 132 InvalidationSet& ensureAttributeInvalidationSet(const AtomicString& attribut
eName, InvalidationType type) { return ensureAttributeInvalidationData(attribute
Name).ensureInvalidationSet(type); } |
| 133 InvalidationSet& ensureIdInvalidationSet(const AtomicString& id, Invalidatio
nType type) { return ensureIdInvalidationData(id).ensureInvalidationSet(type); } |
| 134 InvalidationSet& ensurePseudoInvalidationSet(CSSSelector::PseudoType pseudoT
ype, InvalidationType type) { return ensurePseudoInvalidationData(pseudoType).en
sureInvalidationSet(type); } |
| 131 | 135 |
| 132 void updateInvalidationSets(const RuleData&); | 136 void updateInvalidationSets(const RuleData&); |
| 133 void updateInvalidationSetsForContentAttribute(const RuleData&); | 137 void updateInvalidationSetsForContentAttribute(const RuleData&); |
| 134 | 138 |
| 135 struct InvalidationSetFeatures { | 139 struct InvalidationSetFeatures { |
| 136 DISALLOW_ALLOCATION(); | 140 DISALLOW_ALLOCATION(); |
| 137 InvalidationSetFeatures() | 141 InvalidationSetFeatures() |
| 138 : customPseudoElement(false) | 142 : maxDirectAdjacentSelectors(std::numeric_limits<unsigned>::max()) |
| 143 , customPseudoElement(false) |
| 139 , hasBeforeOrAfter(false) | 144 , hasBeforeOrAfter(false) |
| 140 , treeBoundaryCrossing(false) | 145 , treeBoundaryCrossing(false) |
| 141 , adjacent(false) | 146 , adjacent(false) |
| 142 , insertionPointCrossing(false) | 147 , insertionPointCrossing(false) |
| 143 , forceSubtree(false) | 148 , forceSubtree(false) |
| 144 { } | 149 { } |
| 145 | 150 |
| 146 bool useSubtreeInvalidation() const { return forceSubtree || adjacent; } | |
| 147 | |
| 148 Vector<AtomicString> classes; | 151 Vector<AtomicString> classes; |
| 149 Vector<AtomicString> attributes; | 152 Vector<AtomicString> attributes; |
| 150 AtomicString id; | 153 AtomicString id; |
| 151 AtomicString tagName; | 154 AtomicString tagName; |
| 155 unsigned maxDirectAdjacentSelectors; |
| 152 bool customPseudoElement; | 156 bool customPseudoElement; |
| 153 bool hasBeforeOrAfter; | 157 bool hasBeforeOrAfter; |
| 154 bool treeBoundaryCrossing; | 158 bool treeBoundaryCrossing; |
| 155 bool adjacent; | 159 bool adjacent; |
| 156 bool insertionPointCrossing; | 160 bool insertionPointCrossing; |
| 157 bool forceSubtree; | 161 bool forceSubtree; |
| 158 }; | 162 }; |
| 159 | 163 |
| 160 static bool extractInvalidationSetFeature(const CSSSelector&, InvalidationSe
tFeatures&); | 164 static bool extractInvalidationSetFeature(const CSSSelector&, InvalidationSe
tFeatures&); |
| 161 | 165 |
| 162 enum UseFeaturesType { UseFeatures, ForceSubtree }; | 166 enum UseFeaturesType { UseFeatures, ForceSubtree }; |
| 163 | 167 |
| 164 std::pair<const CSSSelector*, UseFeaturesType> extractInvalidationSetFeature
s(const CSSSelector&, InvalidationSetFeatures&, bool negated); | 168 std::pair<const CSSSelector*, UseFeaturesType> extractInvalidationSetFeature
s(const CSSSelector&, InvalidationSetFeatures&, bool negated); |
| 165 | 169 |
| 166 void addFeaturesToInvalidationSet(InvalidationSet&, const InvalidationSetFea
tures&); | 170 void addFeaturesToInvalidationSet(InvalidationSet&, const InvalidationSetFea
tures&); |
| 167 void addFeaturesToInvalidationSets(const CSSSelector&, InvalidationSetFeatur
es&); | 171 void addFeaturesToInvalidationSets(const CSSSelector*, InvalidationSetFeatur
es* siblingFeatures, InvalidationSetFeatures& descendantFeatures); |
| 168 | 172 |
| 169 void addClassToInvalidationSet(const AtomicString& className, Element&); | 173 void addClassToInvalidationSet(const AtomicString& className, Element&); |
| 170 | 174 |
| 171 FeatureMetadata m_metadata; | 175 FeatureMetadata m_metadata; |
| 172 InvalidationSetMap m_classInvalidationSets; | 176 InvalidationSetMap m_classInvalidationSets; |
| 173 InvalidationSetMap m_attributeInvalidationSets; | 177 InvalidationSetMap m_attributeInvalidationSets; |
| 174 InvalidationSetMap m_idInvalidationSets; | 178 InvalidationSetMap m_idInvalidationSets; |
| 175 PseudoTypeInvalidationSetMap m_pseudoInvalidationSets; | 179 PseudoTypeInvalidationSetMap m_pseudoInvalidationSets; |
| 180 |
| 181 friend class RuleFeatureSetTest; |
| 176 }; | 182 }; |
| 177 | 183 |
| 178 } // namespace blink | 184 } // namespace blink |
| 179 | 185 |
| 180 WTF_ALLOW_MOVE_AND_INIT_WITH_MEM_FUNCTIONS(blink::RuleFeature); | 186 WTF_ALLOW_MOVE_AND_INIT_WITH_MEM_FUNCTIONS(blink::RuleFeature); |
| 181 | 187 |
| 182 #endif // RuleFeature_h | 188 #endif // RuleFeature_h |
| OLD | NEW |