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, |
(...skipping 11 matching lines...) Expand all Loading... |
22 #ifndef RuleFeature_h | 22 #ifndef RuleFeature_h |
23 #define RuleFeature_h | 23 #define RuleFeature_h |
24 | 24 |
25 #include "core/css/analyzer/DescendantInvalidationSet.h" | 25 #include "core/css/analyzer/DescendantInvalidationSet.h" |
26 #include "wtf/Forward.h" | 26 #include "wtf/Forward.h" |
27 #include "wtf/HashSet.h" | 27 #include "wtf/HashSet.h" |
28 #include "wtf/text/AtomicStringHash.h" | 28 #include "wtf/text/AtomicStringHash.h" |
29 | 29 |
30 namespace WebCore { | 30 namespace WebCore { |
31 | 31 |
| 32 class Document; |
| 33 class ShadowRoot; |
32 class StyleRule; | 34 class StyleRule; |
33 class CSSSelector; | 35 class CSSSelector; |
34 class CSSSelectorList; | 36 class CSSSelectorList; |
35 class RuleData; | 37 class RuleData; |
| 38 class SpaceSplitString; |
36 | 39 |
37 struct RuleFeature { | 40 struct RuleFeature { |
38 RuleFeature(StyleRule* rule, unsigned selectorIndex, bool hasDocumentSecurit
yOrigin) | 41 RuleFeature(StyleRule* rule, unsigned selectorIndex, bool hasDocumentSecurit
yOrigin) |
39 : rule(rule) | 42 : rule(rule) |
40 , selectorIndex(selectorIndex) | 43 , selectorIndex(selectorIndex) |
41 , hasDocumentSecurityOrigin(hasDocumentSecurityOrigin) | 44 , hasDocumentSecurityOrigin(hasDocumentSecurityOrigin) |
42 { | 45 { |
43 } | 46 } |
44 StyleRule* rule; | 47 StyleRule* rule; |
45 unsigned selectorIndex; | 48 unsigned selectorIndex; |
46 bool hasDocumentSecurityOrigin; | 49 bool hasDocumentSecurityOrigin; |
47 }; | 50 }; |
48 | 51 |
49 class RuleFeatureSet { | 52 class RuleFeatureSet { |
50 public: | 53 public: |
51 RuleFeatureSet() { } | 54 RuleFeatureSet(); |
52 | 55 |
53 void add(const RuleFeatureSet&); | 56 void add(const RuleFeatureSet&); |
54 void clear(); | 57 void clear(); |
55 | 58 |
56 void collectFeaturesFromSelector(const CSSSelector*); | 59 void collectFeaturesFromSelector(const CSSSelector*); |
57 void collectFeaturesFromRuleData(const RuleData&); | 60 void collectFeaturesFromRuleData(const RuleData&); |
58 | 61 |
59 bool usesSiblingRules() const { return !siblingRules.isEmpty(); } | 62 bool usesSiblingRules() const { return !siblingRules.isEmpty(); } |
60 bool usesFirstLineRules() const { return m_metadata.usesFirstLineRules; } | 63 bool usesFirstLineRules() const { return m_metadata.usesFirstLineRules; } |
61 | 64 |
(...skipping 10 matching lines...) Expand all Loading... |
72 { | 75 { |
73 ASSERT(!classValue.isEmpty()); | 76 ASSERT(!classValue.isEmpty()); |
74 return m_metadata.classesInRules.contains(classValue); | 77 return m_metadata.classesInRules.contains(classValue); |
75 } | 78 } |
76 | 79 |
77 inline bool hasSelectorForId(const AtomicString& idValue) const | 80 inline bool hasSelectorForId(const AtomicString& idValue) const |
78 { | 81 { |
79 return m_metadata.idsInRules.contains(idValue); | 82 return m_metadata.idsInRules.contains(idValue); |
80 } | 83 } |
81 | 84 |
| 85 // If a class changed on the element, this method should be called in order
to schedule style recalc. |
| 86 void scheduleStyleInvalidationForClassChange(const SpaceSplitString& changed
Classes, Element*); |
| 87 void scheduleStyleInvalidationForClassChange(const SpaceSplitString& oldClas
ses, const SpaceSplitString& newClasses, Element*); |
| 88 |
| 89 // Computes which elements in the document need style recalculation. |
| 90 void computeStyleInvalidation(Document&); |
| 91 |
82 int hasIdsInSelectors() const | 92 int hasIdsInSelectors() const |
83 { | 93 { |
84 return m_metadata.idsInRules.size() > 0; | 94 return m_metadata.idsInRules.size() > 0; |
85 } | 95 } |
86 | 96 |
87 // Marks the given attribute name as "appearing in a selector". Used for | 97 // Marks the given attribute name as "appearing in a selector". Used for |
88 // CSS properties such as content: ... attr(...) ... | 98 // CSS properties such as content: ... attr(...) ... |
89 void addAttributeInASelector(const AtomicString& attributeName); | 99 void addAttributeInASelector(const AtomicString& attributeName); |
90 | 100 |
91 Vector<RuleFeature> siblingRules; | 101 Vector<RuleFeature> siblingRules; |
92 Vector<RuleFeature> uncommonAttributeRules; | 102 Vector<RuleFeature> uncommonAttributeRules; |
93 | 103 |
94 private: | 104 private: |
95 typedef HashMap<AtomicString, RefPtr<DescendantInvalidationSet> > Invalidati
onSetMap; | 105 typedef HashMap<AtomicString, RefPtr<DescendantInvalidationSet> > Invalidati
onSetMap; |
| 106 typedef Vector<DescendantInvalidationSet*> InvalidationList; |
| 107 typedef HashMap<Element*, InvalidationList*> PendingInvalidationMap; |
96 struct FeatureMetadata { | 108 struct FeatureMetadata { |
97 FeatureMetadata() | 109 FeatureMetadata() |
98 : usesFirstLineRules(false) | 110 : usesFirstLineRules(false) |
99 , foundSiblingSelector(false) | 111 , foundSiblingSelector(false) |
100 , maxDirectAdjacentSelectors(0) | 112 , maxDirectAdjacentSelectors(0) |
101 { } | 113 { } |
102 void add(const FeatureMetadata& other); | 114 void add(const FeatureMetadata& other); |
103 void clear(); | 115 void clear(); |
104 | 116 |
105 bool usesFirstLineRules; | 117 bool usesFirstLineRules; |
106 bool foundSiblingSelector; | 118 bool foundSiblingSelector; |
107 unsigned maxDirectAdjacentSelectors; | 119 unsigned maxDirectAdjacentSelectors; |
108 HashSet<AtomicString> idsInRules; | 120 HashSet<AtomicString> idsInRules; |
109 HashSet<AtomicString> classesInRules; | 121 HashSet<AtomicString> classesInRules; |
110 HashSet<AtomicString> attrsInRules; | 122 HashSet<AtomicString> attrsInRules; |
111 }; | 123 }; |
112 | 124 |
| 125 // These return true if setNeedsStyleRecalc() should be run on the Element,
as a fallback. |
| 126 bool scheduleStyleInvalidationForClassChangeInternal(const SpaceSplitString&
changedClasses, Element*); |
| 127 bool scheduleStyleInvalidationForClassChangeInternal(const SpaceSplitString&
oldClasses, const SpaceSplitString& newClasses, Element*); |
| 128 |
113 void collectFeaturesFromSelector(const CSSSelector*, FeatureMetadata&); | 129 void collectFeaturesFromSelector(const CSSSelector*, FeatureMetadata&); |
114 void collectFeaturesFromSelectorList(const CSSSelectorList*, FeatureMetadata
&); | 130 void collectFeaturesFromSelectorList(const CSSSelectorList*, FeatureMetadata
&); |
| 131 |
115 DescendantInvalidationSet& ensureClassInvalidationSet(const AtomicString& cl
assName); | 132 DescendantInvalidationSet& ensureClassInvalidationSet(const AtomicString& cl
assName); |
116 bool updateClassInvalidationSets(const CSSSelector*); | 133 bool updateClassInvalidationSets(const CSSSelector*); |
117 | 134 |
| 135 void addClassToInvalidationSet(const AtomicString& className, Element*); |
| 136 |
| 137 bool computeStyleInvalidationInternal(Element*, Vector<AtomicString>&, bool
foundInvalidationSet); |
| 138 bool computeStyleInvalidationForChildren(Element*, Vector<AtomicString>& inv
alidationClasses, bool foundInvalidationSet); |
| 139 |
| 140 InvalidationList& ensurePendingInvalidationList(Element*); |
| 141 |
| 142 FeatureMetadata m_metadata; |
118 InvalidationSetMap m_classInvalidationSets; | 143 InvalidationSetMap m_classInvalidationSets; |
119 FeatureMetadata m_metadata; | 144 PendingInvalidationMap m_pendingInvalidationMap; |
| 145 |
| 146 bool m_targetedStyleRecalcEnabled; |
120 }; | 147 }; |
121 | 148 |
122 } // namespace WebCore | 149 } // namespace WebCore |
123 | 150 |
124 #endif // RuleFeature_h | 151 #endif // RuleFeature_h |
OLD | NEW |