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.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
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
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
25 #include "core/css/invalidation/DescendantInvalidationSet.h"
26 #include "wtf/Forward.h"
27 #include "wtf/HashSet.h"
28 #include "wtf/text/AtomicStringHash.h"
33 class CSSSelectorList;
39 class SpaceSplitString;
43 RuleFeature(StyleRule* rule, unsigned selectorIndex, bool hasDocumentSecurityOrigin)
45 , selectorIndex(selectorIndex)
46 , hasDocumentSecurityOrigin(hasDocumentSecurityOrigin)
50 unsigned selectorIndex;
51 bool hasDocumentSecurityOrigin;
54 class RuleFeatureSet {
58 void add(const RuleFeatureSet&);
61 void collectFeaturesFromSelector(const CSSSelector&);
62 void collectFeaturesFromRuleData(const RuleData&);
64 bool usesSiblingRules() const { return !siblingRules.isEmpty(); }
65 bool usesFirstLineRules() const { return m_metadata.usesFirstLineRules; }
67 unsigned maxDirectAdjacentSelectors() const { return m_metadata.maxDirectAdjacentSelectors; }
68 void setMaxDirectAdjacentSelectors(unsigned value) { m_metadata.maxDirectAdjacentSelectors = std::max(value, m_metadata.maxDirectAdjacentSelectors); }
70 inline bool hasSelectorForAttribute(const AtomicString& attributeName) const
72 ASSERT(!attributeName.isEmpty());
73 return m_attributeInvalidationSets.get(attributeName);
76 inline bool hasSelectorForClass(const AtomicString& classValue) const
78 ASSERT(!classValue.isEmpty());
79 return m_classInvalidationSets.get(classValue);
82 inline bool hasSelectorForId(const AtomicString& idValue) const
84 return m_metadata.idsInRules.contains(idValue);
87 void scheduleStyleInvalidationForClassChange(const SpaceSplitString& changedClasses, Element*);
88 void scheduleStyleInvalidationForClassChange(const SpaceSplitString& oldClasses, const SpaceSplitString& newClasses, Element*);
90 void scheduleStyleInvalidationForAttributeChange(const QualifiedName& attributeName, Element*);
92 // Clears all style invalidation state for the passed node.
93 void clearStyleInvalidation(Node*);
95 int hasIdsInSelectors() const
97 return m_metadata.idsInRules.size() > 0;
100 // Marks the given attribute name as "appearing in a selector". Used for
101 // CSS properties such as content: ... attr(...) ...
102 // FIXME: record these internally to this class instead calls from StyleResolver to here.
103 void addContentAttr(const AtomicString& attributeName);
105 Vector<RuleFeature> siblingRules;
106 Vector<RuleFeature> uncommonAttributeRules;
108 typedef Vector<RefPtr<DescendantInvalidationSet> > InvalidationList;
109 typedef HashMap<Element*, OwnPtr<InvalidationList> > PendingInvalidationMap;
111 PendingInvalidationMap& pendingInvalidationMap();
114 typedef HashMap<AtomicString, RefPtr<DescendantInvalidationSet> > InvalidationSetMap;
116 struct FeatureMetadata {
118 : usesFirstLineRules(false)
119 , foundSiblingSelector(false)
120 , maxDirectAdjacentSelectors(0)
122 void add(const FeatureMetadata& other);
125 bool usesFirstLineRules;
126 bool foundSiblingSelector;
127 unsigned maxDirectAdjacentSelectors;
128 HashSet<AtomicString> idsInRules;
131 enum InvalidationSetMode {
134 UseSubtreeStyleChange
137 static InvalidationSetMode invalidationSetModeForSelector(const CSSSelector&);
139 void collectFeaturesFromSelector(const CSSSelector&, FeatureMetadata&, InvalidationSetMode);
140 void collectFeaturesFromSelectorList(const CSSSelectorList*, FeatureMetadata&, InvalidationSetMode);
142 DescendantInvalidationSet& ensureClassInvalidationSet(const AtomicString& className);
143 DescendantInvalidationSet& ensureAttributeInvalidationSet(const AtomicString& attributeName);
144 DescendantInvalidationSet* invalidationSetForSelector(const CSSSelector&);
146 InvalidationSetMode updateInvalidationSets(const CSSSelector&);
148 struct InvalidationSetFeatures {
149 Vector<AtomicString> classes;
150 Vector<AtomicString> attributes;
152 AtomicString tagName;
155 static void extractInvalidationSetFeature(const CSSSelector&, InvalidationSetFeatures&);
156 const CSSSelector* extractInvalidationSetFeatures(const CSSSelector&, InvalidationSetFeatures&);
157 void addFeaturesToInvalidationSets(const CSSSelector&, const InvalidationSetFeatures&);
159 void addClassToInvalidationSet(const AtomicString& className, Element*);
161 InvalidationList& ensurePendingInvalidationList(Element*);
163 FeatureMetadata m_metadata;
164 InvalidationSetMap m_classInvalidationSets;
165 InvalidationSetMap m_attributeInvalidationSets;
167 PendingInvalidationMap m_pendingInvalidationMap;
169 bool m_targetedStyleRecalcEnabled;
173 } // namespace WebCore
175 #endif // RuleFeature_h