Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(554)

Side by Side Diff: Source/core/css/resolver/StyleResolver.h

Issue 42543007: StyleResolver should update RuleSets lazily. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebased Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 22 matching lines...) Expand all
33 #include "core/css/TreeBoundaryCrossingRules.h" 33 #include "core/css/TreeBoundaryCrossingRules.h"
34 #include "core/css/resolver/MatchedPropertiesCache.h" 34 #include "core/css/resolver/MatchedPropertiesCache.h"
35 #include "core/css/resolver/ScopedStyleResolver.h" 35 #include "core/css/resolver/ScopedStyleResolver.h"
36 #include "core/css/resolver/StyleBuilder.h" 36 #include "core/css/resolver/StyleBuilder.h"
37 #include "core/css/resolver/StyleResolverIncludes.h" 37 #include "core/css/resolver/StyleResolverIncludes.h"
38 #include "core/css/resolver/StyleResolverState.h" 38 #include "core/css/resolver/StyleResolverState.h"
39 #include "core/css/resolver/StyleResourceLoader.h" 39 #include "core/css/resolver/StyleResourceLoader.h"
40 #include "wtf/Deque.h" 40 #include "wtf/Deque.h"
41 #include "wtf/HashMap.h" 41 #include "wtf/HashMap.h"
42 #include "wtf/HashSet.h" 42 #include "wtf/HashSet.h"
43 #include "wtf/ListHashSet.h"
43 #include "wtf/RefPtr.h" 44 #include "wtf/RefPtr.h"
44 #include "wtf/Vector.h" 45 #include "wtf/Vector.h"
45 46
46 namespace WebCore { 47 namespace WebCore {
47 48
48 class CSSAnimationUpdate; 49 class CSSAnimationUpdate;
49 class CSSFontSelector; 50 class CSSFontSelector;
50 class CSSRuleList; 51 class CSSRuleList;
51 class CSSSelector; 52 class CSSSelector;
52 class CSSStyleSheet; 53 class CSSStyleSheet;
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 // FIXME: It could be better to call appendAuthorStyleSheets() directly afte r we factor StyleResolver further. 139 // FIXME: It could be better to call appendAuthorStyleSheets() directly afte r we factor StyleResolver further.
139 // https://bugs.webkit.org/show_bug.cgi?id=108890 140 // https://bugs.webkit.org/show_bug.cgi?id=108890
140 void appendAuthorStyleSheets(unsigned firstNew, const Vector<RefPtr<CSSStyle Sheet> >&); 141 void appendAuthorStyleSheets(unsigned firstNew, const Vector<RefPtr<CSSStyle Sheet> >&);
141 void resetAuthorStyle(const ContainerNode*); 142 void resetAuthorStyle(const ContainerNode*);
142 void resetAtHostRules(const ShadowRoot*); 143 void resetAtHostRules(const ShadowRoot*);
143 void finishAppendAuthorStyleSheets(); 144 void finishAppendAuthorStyleSheets();
144 145
145 TreeBoundaryCrossingRules& treeBoundaryCrossingRules() { return m_treeBounda ryCrossingRules; } 146 TreeBoundaryCrossingRules& treeBoundaryCrossingRules() { return m_treeBounda ryCrossingRules; }
146 void processScopedRules(const RuleSet& authorRules, const KURL&, const Conta inerNode* scope = 0); 147 void processScopedRules(const RuleSet& authorRules, const KURL&, const Conta inerNode* scope = 0);
147 148
149 void lazyAppendAuthorStyleSheets(unsigned firstNew, const Vector<RefPtr<CSSS tyleSheet> >&);
150 void removePendingAuthorStyleSheets(const Vector<RefPtr<CSSStyleSheet> >&);
151 void appendPendingAuthorStyleSheets();
152 bool hasPendingAuthorStyleSheets() const { return m_pendingStyleSheets.size( ) > 0 || m_needCollectFeatures; }
153
148 SelectorFilter& selectorFilter() { return m_selectorFilter; } 154 SelectorFilter& selectorFilter() { return m_selectorFilter; }
149 155
150 void setBuildScopedStyleTreeInDocumentOrder(bool enabled) { m_styleTree.setB uildInDocumentOrder(enabled); } 156 void setBuildScopedStyleTreeInDocumentOrder(bool enabled) { m_styleTree.setB uildInDocumentOrder(enabled); }
151 bool buildScopedStyleTreeInDocumentOrder() const { return m_styleTree.buildI nDocumentOrder(); } 157 bool buildScopedStyleTreeInDocumentOrder() const { return m_styleTree.buildI nDocumentOrder(); }
152 bool styleTreeHasOnlyScopedResolverForDocument() const { return m_styleTree. hasOnlyScopedResolverForDocument(); } 158 bool styleTreeHasOnlyScopedResolverForDocument() const { return m_styleTree. hasOnlyScopedResolverForDocument(); }
153 ScopedStyleResolver* styleTreeScopedStyleResolverForDocument() const { retur n m_styleTree.scopedStyleResolverForDocument(); } 159 ScopedStyleResolver* styleTreeScopedStyleResolverForDocument() const { retur n m_styleTree.scopedStyleResolverForDocument(); }
154 160
155 ScopedStyleResolver* ensureScopedStyleResolver(const ContainerNode* scope) 161 ScopedStyleResolver* ensureScopedStyleResolver(const ContainerNode* scope)
156 { 162 {
157 return m_styleTree.ensureScopedStyleResolver(scope ? *scope : document() ); 163 return m_styleTree.ensureScopedStyleResolver(scope ? *scope : document() );
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 197
192 // FIXME: Rename to reflect the purpose, like didChangeFontSize or something . 198 // FIXME: Rename to reflect the purpose, like didChangeFontSize or something .
193 void invalidateMatchedPropertiesCache(); 199 void invalidateMatchedPropertiesCache();
194 200
195 // Exposed for RenderStyle::isStyleAvilable(). 201 // Exposed for RenderStyle::isStyleAvilable().
196 static RenderStyle* styleNotYetAvailable() { return s_styleNotYetAvailable; } 202 static RenderStyle* styleNotYetAvailable() { return s_styleNotYetAvailable; }
197 203
198 // FIXME: StyleResolver should not have this member or method. 204 // FIXME: StyleResolver should not have this member or method.
199 InspectorCSSOMWrappers& inspectorCSSOMWrappers() { return m_inspectorCSSOMWr appers; } 205 InspectorCSSOMWrappers& inspectorCSSOMWrappers() { return m_inspectorCSSOMWr appers; }
200 206
201 const RuleFeatureSet& ruleFeatureSet() const { return m_features; } 207 const RuleFeatureSet& ensureRuleFeatureSet()
208 {
209 if (hasPendingAuthorStyleSheets())
210 appendPendingAuthorStyleSheets();
211 return m_features;
212 }
202 213
203 StyleSharingList& styleSharingList() { return m_styleSharingList; } 214 StyleSharingList& styleSharingList() { return m_styleSharingList; }
204 215
205 bool hasRulesForId(const AtomicString&) const; 216 bool hasRulesForId(const AtomicString&) const;
206 217
207 void addToStyleSharingList(Element&); 218 void addToStyleSharingList(Element&);
208 void clearStyleSharingList(); 219 void clearStyleSharingList();
209 220
210 StyleResolverStats* stats() { return m_styleResolverStats.get(); } 221 StyleResolverStats* stats() { return m_styleResolverStats.get(); }
211 StyleResolverStats* statsTotals() { return m_styleResolverStatsTotals.get(); } 222 StyleResolverStats* statsTotals() { return m_styleResolverStatsTotals.get(); }
212 enum StatsReportType { ReportDefaultStats, ReportSlowStats }; 223 enum StatsReportType { ReportDefaultStats, ReportSlowStats };
213 void enableStats(StatsReportType = ReportDefaultStats); 224 void enableStats(StatsReportType = ReportDefaultStats);
214 void disableStats(); 225 void disableStats();
215 void printStats(); 226 void printStats();
216 227
217 private: 228 private:
218 // FontSelectorClient implementation. 229 // FontSelectorClient implementation.
219 virtual void fontsNeedUpdate(FontSelector*); 230 virtual void fontsNeedUpdate(FontSelector*);
220 231
221 private: 232 private:
222 void initWatchedSelectorRules(const Vector<RefPtr<StyleRule> >& watchedSelec tors); 233 void initWatchedSelectorRules(const Vector<RefPtr<StyleRule> >& watchedSelec tors);
223 234
224 // FIXME: This should probably go away, folded into FontBuilder. 235 // FIXME: This should probably go away, folded into FontBuilder.
225 void updateFont(StyleResolverState&); 236 void updateFont(StyleResolverState&);
226 237
238 void filterViewportRules(const Vector<RefPtr<StyleRuleBase> >& rules, bool& needsResolveViewport);
239 void filterViewportRulesFromSheet(StyleSheetContents*, bool& needsResolveVie wport);
240 bool filterViewportRulesFromAuthorStyleSheets(unsigned firstNew, const Vecto r<RefPtr<CSSStyleSheet> >& styleSheets);
241
227 void collectPseudoRulesForElement(Element*, ElementRuleCollector&, PseudoId, unsigned rulesToInclude); 242 void collectPseudoRulesForElement(Element*, ElementRuleCollector&, PseudoId, unsigned rulesToInclude);
228 void matchUARules(ElementRuleCollector&, RuleSet*); 243 void matchUARules(ElementRuleCollector&, RuleSet*);
229 void matchAuthorRules(Element*, ElementRuleCollector&, bool includeEmptyRule s); 244 void matchAuthorRules(Element*, ElementRuleCollector&, bool includeEmptyRule s);
230 void matchAuthorRulesForShadowHost(Element*, ElementRuleCollector&, bool inc ludeEmptyRules, Vector<ScopedStyleResolver*, 8>& resolvers, Vector<ScopedStyleRe solver*, 8>& resolversInShadowTree); 245 void matchAuthorRulesForShadowHost(Element*, ElementRuleCollector&, bool inc ludeEmptyRules, Vector<ScopedStyleResolver*, 8>& resolvers, Vector<ScopedStyleRe solver*, 8>& resolversInShadowTree);
231 void matchHostRules(Element*, ScopedStyleResolver*, ElementRuleCollector&, b ool includeEmptyRules); 246 void matchHostRules(Element*, ScopedStyleResolver*, ElementRuleCollector&, b ool includeEmptyRules);
232 void matchAllRules(StyleResolverState&, ElementRuleCollector&, bool includeS MILProperties); 247 void matchAllRules(StyleResolverState&, ElementRuleCollector&, bool includeS MILProperties);
233 void matchUARules(ElementRuleCollector&); 248 void matchUARules(ElementRuleCollector&);
234 // FIXME: watched selectors should be implemented using injected author styl esheets: http://crbug.com/316960 249 // FIXME: watched selectors should be implemented using injected author styl esheets: http://crbug.com/316960
235 void matchWatchSelectorRules(ElementRuleCollector&); 250 void matchWatchSelectorRules(ElementRuleCollector&);
236 void collectFeatures(); 251 void collectFeatures();
237 void collectTreeBoundaryCrossingRules(Element*, ElementRuleCollector&, bool includeEmptyRules); 252 void collectTreeBoundaryCrossingRules(Element*, ElementRuleCollector&, bool includeEmptyRules);
253 void resetRuleFeatures();
238 254
239 bool fastRejectSelector(const RuleData&) const; 255 bool fastRejectSelector(const RuleData&) const;
240 256
241 void applyMatchedProperties(StyleResolverState&, const MatchResult&, Element * animatingElement); 257 void applyMatchedProperties(StyleResolverState&, const MatchResult&, Element * animatingElement);
242 258
243 enum StyleApplicationPass { 259 enum StyleApplicationPass {
244 VariableDefinitions, 260 VariableDefinitions,
245 AnimationProperties, 261 AnimationProperties,
246 HighPriorityProperties, 262 HighPriorityProperties,
247 LowPriorityProperties 263 LowPriorityProperties
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 295
280 RefPtr<RenderStyle> m_rootDefaultStyle; 296 RefPtr<RenderStyle> m_rootDefaultStyle;
281 297
282 Document& m_document; 298 Document& m_document;
283 SelectorFilter m_selectorFilter; 299 SelectorFilter m_selectorFilter;
284 300
285 RefPtr<CSSFontSelector> m_fontSelector; 301 RefPtr<CSSFontSelector> m_fontSelector;
286 302
287 RefPtr<ViewportStyleResolver> m_viewportStyleResolver; 303 RefPtr<ViewportStyleResolver> m_viewportStyleResolver;
288 304
305 ListHashSet<CSSStyleSheet*, 16> m_pendingStyleSheets;
306
289 ScopedStyleTree m_styleTree; 307 ScopedStyleTree m_styleTree;
290 308
291 // FIXME: The entire logic of collecting features on StyleResolver, as well astransferring them 309 // FIXME: The entire logic of collecting features on StyleResolver, as well astransferring them
292 // between various parts of machinery smells wrong. This needs to be better somehow. 310 // between various parts of machinery smells wrong. This needs to be better somehow.
293 RuleFeatureSet m_features; 311 RuleFeatureSet m_features;
294 OwnPtr<RuleSet> m_siblingRuleSet; 312 OwnPtr<RuleSet> m_siblingRuleSet;
295 OwnPtr<RuleSet> m_uncommonAttributeRuleSet; 313 OwnPtr<RuleSet> m_uncommonAttributeRuleSet;
314
296 // FIXME: watched selectors should be implemented using injected author styl esheets: http://crbug.com/316960 315 // FIXME: watched selectors should be implemented using injected author styl esheets: http://crbug.com/316960
297 OwnPtr<RuleSet> m_watchedSelectorsRules; 316 OwnPtr<RuleSet> m_watchedSelectorsRules;
298 TreeBoundaryCrossingRules m_treeBoundaryCrossingRules; 317 TreeBoundaryCrossingRules m_treeBoundaryCrossingRules;
299 318
319 bool m_needCollectFeatures;
320
300 InspectorCSSOMWrappers m_inspectorCSSOMWrappers; 321 InspectorCSSOMWrappers m_inspectorCSSOMWrappers;
301 322
302 StyleResourceLoader m_styleResourceLoader; 323 StyleResourceLoader m_styleResourceLoader;
303 324
304 StyleSharingList m_styleSharingList; 325 StyleSharingList m_styleSharingList;
305 326
306 OwnPtr<StyleResolverStats> m_styleResolverStats; 327 OwnPtr<StyleResolverStats> m_styleResolverStats;
307 OwnPtr<StyleResolverStats> m_styleResolverStatsTotals; 328 OwnPtr<StyleResolverStats> m_styleResolverStatsTotals;
308 unsigned m_styleResolverStatsSequence; 329 unsigned m_styleResolverStatsSequence;
309 }; 330 };
310 331
311 inline bool checkRegionSelector(const CSSSelector* regionSelector, Element* regi onElement) 332 inline bool checkRegionSelector(const CSSSelector* regionSelector, Element* regi onElement)
312 { 333 {
313 if (!regionSelector || !regionElement) 334 if (!regionSelector || !regionElement)
314 return false; 335 return false;
315 336
316 SelectorChecker selectorChecker(regionElement->document(), SelectorChecker:: QueryingRules); 337 SelectorChecker selectorChecker(regionElement->document(), SelectorChecker:: QueryingRules);
317 for (const CSSSelector* s = regionSelector; s; s = CSSSelectorList::next(s)) { 338 for (const CSSSelector* s = regionSelector; s; s = CSSSelectorList::next(s)) {
318 SelectorChecker::SelectorCheckingContext selectorCheckingContext(s, regi onElement, SelectorChecker::VisitedMatchDisabled); 339 SelectorChecker::SelectorCheckingContext selectorCheckingContext(s, regi onElement, SelectorChecker::VisitedMatchDisabled);
319 PseudoId ignoreDynamicPseudo = NOPSEUDO; 340 PseudoId ignoreDynamicPseudo = NOPSEUDO;
320 if (selectorChecker.match(selectorCheckingContext, ignoreDynamicPseudo, DOMSiblingTraversalStrategy()) == SelectorChecker::SelectorMatches) 341 if (selectorChecker.match(selectorCheckingContext, ignoreDynamicPseudo, DOMSiblingTraversalStrategy()) == SelectorChecker::SelectorMatches)
321 return true; 342 return true;
322 } 343 }
323 return false; 344 return false;
324 } 345 }
325 346
347 inline bool isDocumentScope(const ContainerNode* scope)
348 {
349 return !scope || scope->isDocumentNode();
350 }
351
352 inline void appendPendingStyleSheetsIfNeeded(StyleResolver* styleResolver)
353 {
354 if (!styleResolver || !styleResolver->hasPendingAuthorStyleSheets())
355 return;
356 styleResolver->appendPendingAuthorStyleSheets();
357 }
358
326 } // namespace WebCore 359 } // namespace WebCore
327 360
328 #endif // StyleResolver_h 361 #endif // StyleResolver_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698