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/analyzer/DescendantInvalidationSet.h"
26 #include "wtf/Forward.h"
27 #include "wtf/HashSet.h"
28 #include "wtf/text/AtomicStringHash.h"
34 class CSSSelectorList;
38 RuleFeature(StyleRule* rule, unsigned selectorIndex, bool hasDocumentSecurityOrigin)
40 , selectorIndex(selectorIndex)
41 , hasDocumentSecurityOrigin(hasDocumentSecurityOrigin)
45 unsigned selectorIndex;
46 bool hasDocumentSecurityOrigin;
49 class RuleFeatureSet {
53 void add(const RuleFeatureSet&);
56 void collectFeaturesFromSelector(const CSSSelector*);
57 void collectFeaturesFromRuleData(const RuleData&);
59 bool usesSiblingRules() const { return !siblingRules.isEmpty(); }
60 bool usesFirstLineRules() const { return m_metadata.usesFirstLineRules; }
62 unsigned maxDirectAdjacentSelectors() const { return m_metadata.maxDirectAdjacentSelectors; }
63 void setMaxDirectAdjacentSelectors(unsigned value) { m_metadata.maxDirectAdjacentSelectors = std::max(value, m_metadata.maxDirectAdjacentSelectors); }
65 inline bool hasSelectorForAttribute(const AtomicString& attributeName) const
67 ASSERT(!attributeName.isEmpty());
68 return m_metadata.attrsInRules.contains(attributeName);
71 inline bool hasSelectorForClass(const AtomicString& classValue) const
73 ASSERT(!classValue.isEmpty());
74 return m_metadata.classesInRules.contains(classValue);
77 inline bool hasSelectorForId(const AtomicString& idValue) const
79 return m_metadata.idsInRules.contains(idValue);
82 int hasIdsInSelectors() const
84 return m_metadata.idsInRules.size() > 0;
87 // Marks the given attribute name as "appearing in a selector". Used for
88 // CSS properties such as content: ... attr(...) ...
89 void addAttributeInASelector(const AtomicString& attributeName);
91 Vector<RuleFeature> siblingRules;
92 Vector<RuleFeature> uncommonAttributeRules;
95 typedef HashMap<AtomicString, RefPtr<DescendantInvalidationSet> > InvalidationSetMap;
96 struct FeatureMetadata {
98 : usesFirstLineRules(false)
99 , foundSiblingSelector(false)
100 , maxDirectAdjacentSelectors(0)
102 void add(const FeatureMetadata& other);
105 bool usesFirstLineRules;
106 bool foundSiblingSelector;
107 unsigned maxDirectAdjacentSelectors;
108 HashSet<AtomicString> idsInRules;
109 HashSet<AtomicString> classesInRules;
110 HashSet<AtomicString> attrsInRules;
113 void collectFeaturesFromSelector(const CSSSelector*, FeatureMetadata&);
114 void collectFeaturesFromSelectorList(const CSSSelectorList*, FeatureMetadata&);
115 DescendantInvalidationSet& ensureClassInvalidationSet(const AtomicString& className);
116 bool updateClassInvalidationSets(const CSSSelector*);
118 InvalidationSetMap m_classInvalidationSets;
119 FeatureMetadata m_metadata;
122 } // namespace WebCore
124 #endif // RuleFeature_h