blob: 3958bc1ec359c7c63e6936bd9ac0428c44a6260a [file] [log] [blame]
morrita@google.com3b321b52012-10-05 06:15:20 +00001/*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com)
4 * Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com)
5 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All rights reserved.
6 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org>
7 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org>
8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/)
9 * Copyright (c) 2011, Code Aurora Forum. All rights reserved.
10 * Copyright (C) Research In Motion Limited 2011. All rights reserved.
11 * Copyright (C) 2012 Google Inc. All rights reserved.
12 *
13 * This library is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU Library General Public
15 * License as published by the Free Software Foundation; either
16 * version 2 of the License, or (at your option) any later version.
17 *
18 * This library is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 * Library General Public License for more details.
22 *
23 * You should have received a copy of the GNU Library General Public License
24 * along with this library; see the file COPYING.LIB. If not, write to
25 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
26 * Boston, MA 02110-1301, USA.
27 */
28
29#include "config.h"
30#include "RuleSet.h"
31
32#include "CSSFontSelector.h"
33#include "CSSSelector.h"
34#include "CSSSelectorList.h"
35#include "HTMLNames.h"
36#include "MediaQueryEvaluator.h"
37#include "SecurityOrigin.h"
38#include "SelectorChecker.h"
dglazkov@chromium.org4e8caa32012-12-24 05:05:13 +000039#include "SelectorFilter.h"
morrita@google.com3b321b52012-10-05 06:15:20 +000040#include "StyleResolver.h"
41#include "StyleRule.h"
42#include "StyleRuleImport.h"
43#include "StyleSheetContents.h"
44#include "WebCoreMemoryInstrumentation.h"
45#include "WebKitCSSKeyframesRule.h"
46#include <wtf/MemoryInstrumentationHashMap.h>
47#include <wtf/MemoryInstrumentationHashSet.h>
48#include <wtf/MemoryInstrumentationVector.h>
49
commit-queue@webkit.org0bcebbe2013-01-23 05:50:15 +000050#if ENABLE(VIDEO_TRACK)
51#include "TextTrackCue.h"
52#endif
53
morrita@google.com3b321b52012-10-05 06:15:20 +000054namespace WebCore {
55
56using namespace HTMLNames;
57
58// -----------------------------------------------------------------
59
60static inline bool isSelectorMatchingHTMLBasedOnRuleHash(const CSSSelector* selector)
61{
akling@apple.com48d56042013-01-22 00:45:14 +000062 ASSERT(selector);
63 if (selector->m_match == CSSSelector::Tag) {
64 const AtomicString& selectorNamespace = selector->tagQName().namespaceURI();
65 if (selectorNamespace != starAtom && selectorNamespace != xhtmlNamespaceURI)
66 return false;
67 if (selector->relation() == CSSSelector::SubSelector)
68 return isSelectorMatchingHTMLBasedOnRuleHash(selector->tagHistory());
morrita@google.com3b321b52012-10-05 06:15:20 +000069 return true;
akling@apple.com48d56042013-01-22 00:45:14 +000070 }
morrita@google.com3b321b52012-10-05 06:15:20 +000071 if (SelectorChecker::isCommonPseudoClassSelector(selector))
72 return true;
73 return selector->m_match == CSSSelector::Id || selector->m_match == CSSSelector::Class;
74}
75
76static inline bool selectorListContainsUncommonAttributeSelector(const CSSSelector* selector)
77{
78 CSSSelectorList* selectorList = selector->selectorList();
79 if (!selectorList)
80 return false;
akling@apple.com48d56042013-01-22 00:45:14 +000081 for (CSSSelector* selector = selectorList->first(); selector; selector = CSSSelectorList::next(selector)) {
82 for (CSSSelector* component = selector; component; component = component->tagHistory()) {
83 if (component->isAttributeSelector())
84 return true;
85 }
morrita@google.com3b321b52012-10-05 06:15:20 +000086 }
87 return false;
88}
89
90static inline bool isCommonAttributeSelectorAttribute(const QualifiedName& attribute)
91{
92 // These are explicitly tested for equality in canShareStyleWithElement.
93 return attribute == typeAttr || attribute == readonlyAttr;
94}
95
96static inline bool containsUncommonAttributeSelector(const CSSSelector* selector)
97{
98 for (; selector; selector = selector->tagHistory()) {
99 // Allow certain common attributes (used in the default style) in the selectors that match the current element.
100 if (selector->isAttributeSelector() && !isCommonAttributeSelectorAttribute(selector->attribute()))
101 return true;
102 if (selectorListContainsUncommonAttributeSelector(selector))
103 return true;
104 if (selector->relation() != CSSSelector::SubSelector) {
105 selector = selector->tagHistory();
106 break;
107 }
108 }
109
110 for (; selector; selector = selector->tagHistory()) {
111 if (selector->isAttributeSelector())
112 return true;
113 if (selectorListContainsUncommonAttributeSelector(selector))
114 return true;
115 }
116 return false;
117}
118
commit-queue@webkit.org085528c2013-01-18 18:22:46 +0000119static inline PropertyWhitelistType determinePropertyWhitelistType(const AddRuleFlags addRuleFlags, const CSSSelector* selector)
120{
121 if (addRuleFlags & RuleIsInRegionRule)
122 return PropertyWhitelistRegion;
123#if ENABLE(VIDEO_TRACK)
akling@apple.com48d56042013-01-22 00:45:14 +0000124 for (const CSSSelector* component = selector; component; component = component->tagHistory()) {
commit-queue@webkit.org0bcebbe2013-01-23 05:50:15 +0000125 if (component->pseudoType() == CSSSelector::PseudoCue || (component->m_match != CSSSelector::Tag && component->value() == TextTrackCue::cueShadowPseudoId()))
akling@apple.com48d56042013-01-22 00:45:14 +0000126 return PropertyWhitelistCue;
127 }
commit-queue@webkit.org0bcebbe2013-01-23 05:50:15 +0000128#else
129 UNUSED_PARAM(selector);
commit-queue@webkit.org085528c2013-01-18 18:22:46 +0000130#endif
131 return PropertyWhitelistNone;
132}
133
tasak@google.com4a7bee52012-10-26 11:33:22 +0000134RuleData::RuleData(StyleRule* rule, unsigned selectorIndex, unsigned position, AddRuleFlags addRuleFlags)
morrita@google.com3b321b52012-10-05 06:15:20 +0000135 : m_rule(rule)
136 , m_selectorIndex(selectorIndex)
137 , m_position(position)
tasak@google.com4a7bee52012-10-26 11:33:22 +0000138 , m_hasFastCheckableSelector((addRuleFlags & RuleCanUseFastCheckSelector) && SelectorChecker::isFastCheckableSelector(selector()))
commit-queue@webkit.org085528c2013-01-18 18:22:46 +0000139 , m_specificity(selector()->specificity())
morrita@google.com3b321b52012-10-05 06:15:20 +0000140 , m_hasMultipartSelector(!!selector()->tagHistory())
141 , m_hasRightmostSelectorMatchingHTMLBasedOnRuleHash(isSelectorMatchingHTMLBasedOnRuleHash(selector()))
142 , m_containsUncommonAttributeSelector(WebCore::containsUncommonAttributeSelector(selector()))
143 , m_linkMatchType(SelectorChecker::determineLinkMatchType(selector()))
tasak@google.com4a7bee52012-10-26 11:33:22 +0000144 , m_hasDocumentSecurityOrigin(addRuleFlags & RuleHasDocumentSecurityOrigin)
commit-queue@webkit.org085528c2013-01-18 18:22:46 +0000145 , m_propertyWhitelistType(determinePropertyWhitelistType(addRuleFlags, selector()))
morrita@google.com3b321b52012-10-05 06:15:20 +0000146{
147 ASSERT(m_position == position);
148 ASSERT(m_selectorIndex == selectorIndex);
dglazkov@chromium.org4e8caa32012-12-24 05:05:13 +0000149 SelectorFilter::collectIdentifierHashes(selector(), m_descendantSelectorIdentifierHashes, maximumIdentifierCount);
morrita@google.com3b321b52012-10-05 06:15:20 +0000150}
151
152void RuleData::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const
153{
154 MemoryClassInfo info(memoryObjectInfo, this, WebCoreMemoryTypes::CSS);
loislo@chromium.org771ab1f2013-01-14 08:21:49 +0000155 info.addMember(m_rule);
morrita@google.com3b321b52012-10-05 06:15:20 +0000156}
157
158static void reportAtomRuleMap(MemoryClassInfo* info, const RuleSet::AtomRuleMap& atomicRuleMap)
159{
160 info->addMember(atomicRuleMap);
161 for (RuleSet::AtomRuleMap::const_iterator it = atomicRuleMap.begin(); it != atomicRuleMap.end(); ++it)
benjamin@webkit.orgee554052012-10-07 23:12:07 +0000162 info->addMember(*it->value);
morrita@google.com3b321b52012-10-05 06:15:20 +0000163}
164
165void RuleSet::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const
166{
167 MemoryClassInfo info(memoryObjectInfo, this, WebCoreMemoryTypes::CSS);
168 reportAtomRuleMap(&info, m_idRules);
169 reportAtomRuleMap(&info, m_classRules);
170 reportAtomRuleMap(&info, m_tagRules);
171 reportAtomRuleMap(&info, m_shadowPseudoElementRules);
172 info.addMember(m_linkPseudoClassRules);
commit-queue@webkit.org7db073d2012-12-18 00:01:39 +0000173#if ENABLE(VIDEO_TRACK)
174 info.addMember(m_cuePseudoRules);
175#endif
morrita@google.com3b321b52012-10-05 06:15:20 +0000176 info.addMember(m_focusPseudoClassRules);
177 info.addMember(m_universalRules);
178 info.addMember(m_pageRules);
179 info.addMember(m_regionSelectorsAndRuleSets);
loislo@chromium.org771ab1f2013-01-14 08:21:49 +0000180 info.addMember(m_features);
morrita@google.com3b321b52012-10-05 06:15:20 +0000181}
182
183void RuleSet::RuleSetSelectorPair::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const
184{
185 MemoryClassInfo info(memoryObjectInfo, this, WebCoreMemoryTypes::CSS);
186 info.addMember(ruleSet);
loislo@chromium.org771ab1f2013-01-14 08:21:49 +0000187 info.addMember(selector);
morrita@google.com3b321b52012-10-05 06:15:20 +0000188}
189
morrita@google.com3b321b52012-10-05 06:15:20 +0000190static void collectFeaturesFromRuleData(RuleFeatureSet& features, const RuleData& ruleData)
191{
192 bool foundSiblingSelector = false;
193 for (CSSSelector* selector = ruleData.selector(); selector; selector = selector->tagHistory()) {
shinyak@chromium.orgade81c32012-11-09 06:17:31 +0000194 features.collectFeaturesFromSelector(selector);
morrita@google.com3b321b52012-10-05 06:15:20 +0000195
196 if (CSSSelectorList* selectorList = selector->selectorList()) {
197 for (CSSSelector* subSelector = selectorList->first(); subSelector; subSelector = CSSSelectorList::next(subSelector)) {
198 if (!foundSiblingSelector && selector->isSiblingSelector())
199 foundSiblingSelector = true;
shinyak@chromium.orgade81c32012-11-09 06:17:31 +0000200 features.collectFeaturesFromSelector(subSelector);
morrita@google.com3b321b52012-10-05 06:15:20 +0000201 }
202 } else if (!foundSiblingSelector && selector->isSiblingSelector())
203 foundSiblingSelector = true;
204 }
205 if (foundSiblingSelector)
206 features.siblingRules.append(RuleFeature(ruleData.rule(), ruleData.selectorIndex(), ruleData.hasDocumentSecurityOrigin()));
207 if (ruleData.containsUncommonAttributeSelector())
208 features.uncommonAttributeRules.append(RuleFeature(ruleData.rule(), ruleData.selectorIndex(), ruleData.hasDocumentSecurityOrigin()));
209}
210
211void RuleSet::addToRuleSet(AtomicStringImpl* key, AtomRuleMap& map, const RuleData& ruleData)
212{
213 if (!key)
214 return;
benjamin@webkit.orgee554052012-10-07 23:12:07 +0000215 OwnPtr<Vector<RuleData> >& rules = map.add(key, nullptr).iterator->value;
morrita@google.com3b321b52012-10-05 06:15:20 +0000216 if (!rules)
217 rules = adoptPtr(new Vector<RuleData>);
218 rules->append(ruleData);
219}
220
akling@apple.com48d56042013-01-22 00:45:14 +0000221bool RuleSet::findBestRuleSetAndAdd(const CSSSelector* component, RuleData& ruleData)
morrita@google.com3b321b52012-10-05 06:15:20 +0000222{
akling@apple.com48d56042013-01-22 00:45:14 +0000223 if (component->m_match == CSSSelector::Id) {
224 addToRuleSet(component->value().impl(), m_idRules, ruleData);
225 return true;
morrita@google.com3b321b52012-10-05 06:15:20 +0000226 }
akling@apple.com48d56042013-01-22 00:45:14 +0000227 if (component->m_match == CSSSelector::Class) {
228 addToRuleSet(component->value().impl(), m_classRules, ruleData);
229 return true;
morrita@google.com3b321b52012-10-05 06:15:20 +0000230 }
akling@apple.com48d56042013-01-22 00:45:14 +0000231 if (component->isCustomPseudoElement()) {
232 addToRuleSet(component->value().impl(), m_shadowPseudoElementRules, ruleData);
233 return true;
morrita@google.com3b321b52012-10-05 06:15:20 +0000234 }
commit-queue@webkit.org7db073d2012-12-18 00:01:39 +0000235#if ENABLE(VIDEO_TRACK)
akling@apple.com48d56042013-01-22 00:45:14 +0000236 if (component->pseudoType() == CSSSelector::PseudoCue) {
commit-queue@webkit.org7db073d2012-12-18 00:01:39 +0000237 m_cuePseudoRules.append(ruleData);
akling@apple.com48d56042013-01-22 00:45:14 +0000238 return true;
commit-queue@webkit.org7db073d2012-12-18 00:01:39 +0000239 }
240#endif
akling@apple.com48d56042013-01-22 00:45:14 +0000241 if (SelectorChecker::isCommonPseudoClassSelector(component)) {
242 switch (component->pseudoType()) {
morrita@google.com3b321b52012-10-05 06:15:20 +0000243 case CSSSelector::PseudoLink:
244 case CSSSelector::PseudoVisited:
245 case CSSSelector::PseudoAnyLink:
246 m_linkPseudoClassRules.append(ruleData);
akling@apple.com48d56042013-01-22 00:45:14 +0000247 return true;
morrita@google.com3b321b52012-10-05 06:15:20 +0000248 case CSSSelector::PseudoFocus:
249 m_focusPseudoClassRules.append(ruleData);
akling@apple.com48d56042013-01-22 00:45:14 +0000250 return true;
morrita@google.com3b321b52012-10-05 06:15:20 +0000251 default:
252 ASSERT_NOT_REACHED();
akling@apple.com48d56042013-01-22 00:45:14 +0000253 return true;
morrita@google.com3b321b52012-10-05 06:15:20 +0000254 }
morrita@google.com3b321b52012-10-05 06:15:20 +0000255 }
akling@apple.com48d56042013-01-22 00:45:14 +0000256
257 if (component->m_match == CSSSelector::Tag) {
258 if (component->tagQName().localName() != starAtom) {
259 // If this is part of a subselector chain, recurse ahead to find a narrower set (ID/class.)
260 if (component->relation() == CSSSelector::SubSelector
261 && (component->tagHistory()->m_match == CSSSelector::Class || component->tagHistory()->m_match == CSSSelector::Id || SelectorChecker::isCommonPseudoClassSelector(component->tagHistory()))
262 && findBestRuleSetAndAdd(component->tagHistory(), ruleData))
263 return true;
264
265 addToRuleSet(component->tagQName().localName().impl(), m_tagRules, ruleData);
266 return true;
267 }
morrita@google.com3b321b52012-10-05 06:15:20 +0000268 }
akling@apple.com48d56042013-01-22 00:45:14 +0000269 return false;
270}
271
272void RuleSet::addRule(StyleRule* rule, unsigned selectorIndex, AddRuleFlags addRuleFlags)
273{
274 RuleData ruleData(rule, selectorIndex, m_ruleCount++, addRuleFlags);
275 collectFeaturesFromRuleData(m_features, ruleData);
276
277 if (!findBestRuleSetAndAdd(ruleData.selector(), ruleData)) {
278 // If we didn't find a specialized map to stick it in, file under universal rules.
279 m_universalRules.append(ruleData);
280 }
morrita@google.com3b321b52012-10-05 06:15:20 +0000281}
282
283void RuleSet::addPageRule(StyleRulePage* rule)
284{
285 m_pageRules.append(rule);
286}
287
288void RuleSet::addRegionRule(StyleRuleRegion* regionRule, bool hasDocumentSecurityOrigin)
289{
290 OwnPtr<RuleSet> regionRuleSet = RuleSet::create();
291 // The region rule set should take into account the position inside the parent rule set.
292 // Otherwise, the rules inside region block might be incorrectly positioned before other similar rules from
293 // the stylesheet that contains the region block.
294 regionRuleSet->m_ruleCount = m_ruleCount;
295
296 // Collect the region rules into a rule set
commit-queue@webkit.org104b5ab2013-01-14 09:49:56 +0000297 // FIXME: Should this add other types of rules? (i.e. use addChildRules() directly?)
morrita@google.com3b321b52012-10-05 06:15:20 +0000298 const Vector<RefPtr<StyleRuleBase> >& childRules = regionRule->childRules();
tasak@google.com4a7bee52012-10-26 11:33:22 +0000299 AddRuleFlags addRuleFlags = hasDocumentSecurityOrigin ? RuleHasDocumentSecurityOrigin : RuleHasNoSpecialState;
300 addRuleFlags = static_cast<AddRuleFlags>(addRuleFlags | RuleCanUseFastCheckSelector | RuleIsInRegionRule);
morrita@google.com3b321b52012-10-05 06:15:20 +0000301 for (unsigned i = 0; i < childRules.size(); ++i) {
302 StyleRuleBase* regionStylingRule = childRules[i].get();
303 if (regionStylingRule->isStyleRule())
tasak@google.com4a7bee52012-10-26 11:33:22 +0000304 regionRuleSet->addStyleRule(static_cast<StyleRule*>(regionStylingRule), addRuleFlags);
morrita@google.com3b321b52012-10-05 06:15:20 +0000305 }
306 // Update the "global" rule count so that proper order is maintained
307 m_ruleCount = regionRuleSet->m_ruleCount;
308
309 m_regionSelectorsAndRuleSets.append(RuleSetSelectorPair(regionRule->selectorList().first(), regionRuleSet.release()));
310}
311
commit-queue@webkit.org104b5ab2013-01-14 09:49:56 +0000312void RuleSet::addChildRules(const Vector<RefPtr<StyleRuleBase> >& rules, const MediaQueryEvaluator& medium, StyleResolver* resolver, const ContainerNode* scope, bool hasDocumentSecurityOrigin, AddRuleFlags addRuleFlags)
morrita@google.com3b321b52012-10-05 06:15:20 +0000313{
morrita@google.com3b321b52012-10-05 06:15:20 +0000314 for (unsigned i = 0; i < rules.size(); ++i) {
315 StyleRuleBase* rule = rules[i].get();
316
morrita@google.com3b321b52012-10-05 06:15:20 +0000317 if (rule->isStyleRule())
tasak@google.com4a7bee52012-10-26 11:33:22 +0000318 addStyleRule(static_cast<StyleRule*>(rule), addRuleFlags);
morrita@google.com3b321b52012-10-05 06:15:20 +0000319 else if (rule->isPageRule())
320 addPageRule(static_cast<StyleRulePage*>(rule));
321 else if (rule->isMediaRule()) {
322 StyleRuleMedia* mediaRule = static_cast<StyleRuleMedia*>(rule);
commit-queue@webkit.org104b5ab2013-01-14 09:49:56 +0000323 if ((!mediaRule->mediaQueries() || medium.eval(mediaRule->mediaQueries(), resolver)))
324 addChildRules(mediaRule->childRules(), medium, resolver, scope, hasDocumentSecurityOrigin, addRuleFlags);
morrita@google.com3b321b52012-10-05 06:15:20 +0000325 } else if (rule->isFontFaceRule() && resolver) {
326 // Add this font face to our set.
327 // FIXME(BUG 72461): We don't add @font-face rules of scoped style sheets for the moment.
328 if (scope)
329 continue;
330 const StyleRuleFontFace* fontFaceRule = static_cast<StyleRuleFontFace*>(rule);
331 resolver->fontSelector()->addFontFaceRule(fontFaceRule);
332 resolver->invalidateMatchedPropertiesCache();
333 } else if (rule->isKeyframesRule() && resolver) {
334 // FIXME (BUG 72462): We don't add @keyframe rules of scoped style sheets for the moment.
335 if (scope)
336 continue;
337 resolver->addKeyframeStyle(static_cast<StyleRuleKeyframes*>(rule));
338 }
339#if ENABLE(CSS_REGIONS)
340 else if (rule->isRegionRule() && resolver) {
341 // FIXME (BUG 72472): We don't add @-webkit-region rules of scoped style sheets for the moment.
342 if (scope)
343 continue;
344 addRegionRule(static_cast<StyleRuleRegion*>(rule), hasDocumentSecurityOrigin);
345 }
346#endif
tasak@google.com4a7bee52012-10-26 11:33:22 +0000347#if ENABLE(SHADOW_DOM)
348 else if (rule->isHostRule())
349 resolver->addHostRule(static_cast<StyleRuleHost*>(rule), hasDocumentSecurityOrigin, scope);
350#endif
commit-queue@webkit.orgdaa81a42012-11-19 16:37:01 +0000351#if ENABLE(CSS_DEVICE_ADAPTATION)
352 else if (rule->isViewportRule() && resolver) {
353 // @viewport should not be scoped.
354 if (scope)
355 continue;
356 resolver->viewportStyleResolver()->addViewportRule(static_cast<StyleRuleViewport*>(rule));
357 }
358#endif
commit-queue@webkit.org03dd24f2013-01-16 11:30:50 +0000359#if ENABLE(CSS3_CONDITIONAL_RULES)
360 else if (rule->isSupportsRule() && static_cast<StyleRuleSupports*>(rule)->conditionIsSupported())
361 addChildRules(static_cast<StyleRuleSupports*>(rule)->childRules(), medium, resolver, scope, hasDocumentSecurityOrigin, addRuleFlags);
362#endif
morrita@google.com3b321b52012-10-05 06:15:20 +0000363 }
commit-queue@webkit.org104b5ab2013-01-14 09:49:56 +0000364}
365
366void RuleSet::addRulesFromSheet(StyleSheetContents* sheet, const MediaQueryEvaluator& medium, StyleResolver* resolver, const ContainerNode* scope)
367{
368 ASSERT(sheet);
369
370 const Vector<RefPtr<StyleRuleImport> >& importRules = sheet->importRules();
371 for (unsigned i = 0; i < importRules.size(); ++i) {
372 StyleRuleImport* importRule = importRules[i].get();
373 if (importRule->styleSheet() && (!importRule->mediaQueries() || medium.eval(importRule->mediaQueries(), resolver)))
374 addRulesFromSheet(importRule->styleSheet(), medium, resolver, scope);
375 }
376
377 bool hasDocumentSecurityOrigin = resolver && resolver->document()->securityOrigin()->canRequest(sheet->baseURL());
378 AddRuleFlags addRuleFlags = static_cast<AddRuleFlags>((hasDocumentSecurityOrigin ? RuleHasDocumentSecurityOrigin : 0) | (!scope ? RuleCanUseFastCheckSelector : 0));
379
380 addChildRules(sheet->childRules(), medium, resolver, scope, hasDocumentSecurityOrigin, addRuleFlags);
381
morrita@google.com3b321b52012-10-05 06:15:20 +0000382 if (m_autoShrinkToFitEnabled)
383 shrinkToFit();
384}
385
tasak@google.com4a7bee52012-10-26 11:33:22 +0000386void RuleSet::addStyleRule(StyleRule* rule, AddRuleFlags addRuleFlags)
morrita@google.com3b321b52012-10-05 06:15:20 +0000387{
388 for (size_t selectorIndex = 0; selectorIndex != notFound; selectorIndex = rule->selectorList().indexOfNextSelectorAfter(selectorIndex))
tasak@google.com4a7bee52012-10-26 11:33:22 +0000389 addRule(rule, selectorIndex, addRuleFlags);
morrita@google.com3b321b52012-10-05 06:15:20 +0000390}
391
392static inline void shrinkMapVectorsToFit(RuleSet::AtomRuleMap& map)
393{
394 RuleSet::AtomRuleMap::iterator end = map.end();
395 for (RuleSet::AtomRuleMap::iterator it = map.begin(); it != end; ++it)
benjamin@webkit.orgee554052012-10-07 23:12:07 +0000396 it->value->shrinkToFit();
morrita@google.com3b321b52012-10-05 06:15:20 +0000397}
398
399void RuleSet::shrinkToFit()
400{
401 shrinkMapVectorsToFit(m_idRules);
402 shrinkMapVectorsToFit(m_classRules);
403 shrinkMapVectorsToFit(m_tagRules);
404 shrinkMapVectorsToFit(m_shadowPseudoElementRules);
405 m_linkPseudoClassRules.shrinkToFit();
commit-queue@webkit.org7db073d2012-12-18 00:01:39 +0000406#if ENABLE(VIDEO_TRACK)
407 m_cuePseudoRules.shrinkToFit();
408#endif
morrita@google.com3b321b52012-10-05 06:15:20 +0000409 m_focusPseudoClassRules.shrinkToFit();
410 m_universalRules.shrinkToFit();
411 m_pageRules.shrinkToFit();
412}
413
414} // namespace WebCore