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

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: Filter @viewport and @font-face in lazyAppend 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/SiblingTraversalStrategies.h" 33 #include "core/css/SiblingTraversalStrategies.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 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 // their dependency on Document* instead of grabbing one through StyleResolv er. 210 // their dependency on Document* instead of grabbing one through StyleResolv er.
210 Document& document() { return m_document; } 211 Document& document() { return m_document; }
211 212
212 // FIXME: It could be better to call m_ruleSets.appendAuthorStyleSheets() di rectly after we factor StyleRsolver further. 213 // FIXME: It could be better to call m_ruleSets.appendAuthorStyleSheets() di rectly after we factor StyleRsolver further.
213 // https://bugs.webkit.org/show_bug.cgi?id=108890 214 // https://bugs.webkit.org/show_bug.cgi?id=108890
214 void appendAuthorStyleSheets(unsigned firstNew, const Vector<RefPtr<CSSStyle Sheet> >&); 215 void appendAuthorStyleSheets(unsigned firstNew, const Vector<RefPtr<CSSStyle Sheet> >&);
215 void resetAuthorStyle(const ContainerNode*); 216 void resetAuthorStyle(const ContainerNode*);
216 void resetAtHostRules(const ShadowRoot*); 217 void resetAtHostRules(const ShadowRoot*);
217 void finishAppendAuthorStyleSheets(); 218 void finishAppendAuthorStyleSheets();
218 219
220 void lazyAppendAuthorStyleSheets(unsigned firstNew, const Vector<RefPtr<CSSS tyleSheet> >&);
221 void removePendingAuthorStyleSheets(const Vector<RefPtr<CSSStyleSheet> >&);
222 void appendPendingAuthorStyleSheets();
223 bool hasPendingAuthorStyleSheets() const { return m_pendingStyleSheets.size( ) > 0 || m_needCollectFeatures; }
224
219 DocumentRuleSets& ruleSets() { return m_ruleSets; } 225 DocumentRuleSets& ruleSets() { return m_ruleSets; }
220 const DocumentRuleSets& ruleSets() const { return m_ruleSets; } 226 const DocumentRuleSets& ruleSets() const { return m_ruleSets; }
221 SelectorFilter& selectorFilter() { return m_selectorFilter; } 227 SelectorFilter& selectorFilter() { return m_selectorFilter; }
222 228
223 void setBuildScopedStyleTreeInDocumentOrder(bool enabled) { m_styleTree.setB uildInDocumentOrder(enabled); } 229 void setBuildScopedStyleTreeInDocumentOrder(bool enabled) { m_styleTree.setB uildInDocumentOrder(enabled); }
224 bool buildScopedStyleTreeInDocumentOrder() const { return m_styleTree.buildI nDocumentOrder(); } 230 bool buildScopedStyleTreeInDocumentOrder() const { return m_styleTree.buildI nDocumentOrder(); }
225 231
226 ScopedStyleResolver* ensureScopedStyleResolver(const ContainerNode* scope) 232 ScopedStyleResolver* ensureScopedStyleResolver(const ContainerNode* scope)
227 { 233 {
228 return m_styleTree.ensureScopedStyleResolver(scope ? *scope : document() ); 234 return m_styleTree.ensureScopedStyleResolver(scope ? *scope : document() );
(...skipping 28 matching lines...) Expand all
257 263
258 // FIXME: Rename to reflect the purpose, like didChangeFontSize or something . 264 // FIXME: Rename to reflect the purpose, like didChangeFontSize or something .
259 void invalidateMatchedPropertiesCache(); 265 void invalidateMatchedPropertiesCache();
260 266
261 // Exposed for RenderStyle::isStyleAvilable(). 267 // Exposed for RenderStyle::isStyleAvilable().
262 static RenderStyle* styleNotYetAvailable() { return s_styleNotYetAvailable; } 268 static RenderStyle* styleNotYetAvailable() { return s_styleNotYetAvailable; }
263 269
264 // FIXME: StyleResolver should not have this member or method. 270 // FIXME: StyleResolver should not have this member or method.
265 InspectorCSSOMWrappers& inspectorCSSOMWrappers() { return m_inspectorCSSOMWr appers; } 271 InspectorCSSOMWrappers& inspectorCSSOMWrappers() { return m_inspectorCSSOMWr appers; }
266 272
267 const RuleFeatureSet& ruleFeatureSet() const { return m_features; } 273 const RuleFeatureSet& ruleFeatureSet() const { return m_features; }
eseidel 2013/11/06 01:39:10 I'm confused. This can now be stale right? Don't
tasak 2013/11/06 05:42:26 I left the method for fast-path, e.g. Document::cr
274 const RuleFeatureSet& ensureRuleFeatureSet()
275 {
276 if (hasPendingAuthorStyleSheets())
277 appendPendingAuthorStyleSheets(); // slow path.
278 return m_features;
279 }
268 280
269 StyleSharingList& styleSharingList() { return m_styleSharingList; } 281 StyleSharingList& styleSharingList() { return m_styleSharingList; }
270 282
271 bool hasRulesForId(const AtomicString&) const; 283 bool hasRulesForId(const AtomicString&) const;
272 284
273 void addToStyleSharingList(Element*); 285 void addToStyleSharingList(Element*);
274 void clearStyleSharingList(); 286 void clearStyleSharingList();
275 287
276 #ifdef STYLE_STATS 288 #ifdef STYLE_STATS
277 ALWAYS_INLINE static StyleSharingStats& styleSharingStats() { return m_style SharingStats; } 289 ALWAYS_INLINE static StyleSharingStats& styleSharingStats() { return m_style SharingStats; }
278 #endif 290 #endif
279 291
280 private: 292 private:
281 // FontSelectorClient implementation. 293 // FontSelectorClient implementation.
282 virtual void fontsNeedUpdate(FontSelector*); 294 virtual void fontsNeedUpdate(FontSelector*);
283 295
284 private: 296 private:
285 // FIXME: This should probably go away, folded into FontBuilder. 297 // FIXME: This should probably go away, folded into FontBuilder.
286 void updateFont(StyleResolverState&); 298 void updateFont(StyleResolverState&);
287 299
300 void filterFontFaceAndViewportRules(const Vector<RefPtr<StyleRuleBase> >& ru les, bool& needsResolveViewport);
301 void filterFontFaceAndViewportRulesFromSheet(StyleSheetContents*, bool& need sResolveViewport);
302 bool filterFontFaceAndViewportRulesFromAuthorStyleSheets(unsigned firstNew, const Vector<RefPtr<CSSStyleSheet> >& styleSheets);
303
288 void collectPseudoRulesForElement(Element*, ElementRuleCollector&, PseudoId, unsigned rulesToInclude); 304 void collectPseudoRulesForElement(Element*, ElementRuleCollector&, PseudoId, unsigned rulesToInclude);
289 void matchUARules(ElementRuleCollector&, RuleSet*); 305 void matchUARules(ElementRuleCollector&, RuleSet*);
290 void matchAuthorRules(Element*, ElementRuleCollector&, bool includeEmptyRule s); 306 void matchAuthorRules(Element*, ElementRuleCollector&, bool includeEmptyRule s);
291 void matchAuthorRulesForShadowHost(Element*, ElementRuleCollector&, bool inc ludeEmptyRules, Vector<ScopedStyleResolver*, 8>& resolvers, Vector<ScopedStyleRe solver*, 8>& resolversInShadowTree); 307 void matchAuthorRulesForShadowHost(Element*, ElementRuleCollector&, bool inc ludeEmptyRules, Vector<ScopedStyleResolver*, 8>& resolvers, Vector<ScopedStyleRe solver*, 8>& resolversInShadowTree);
292 void matchHostRules(Element*, ScopedStyleResolver*, ElementRuleCollector&, b ool includeEmptyRules); 308 void matchHostRules(Element*, ScopedStyleResolver*, ElementRuleCollector&, b ool includeEmptyRules);
293 void matchAllRules(StyleResolverState&, ElementRuleCollector&, bool matchAut horAndUserStyles, bool includeSMILProperties); 309 void matchAllRules(StyleResolverState&, ElementRuleCollector&, bool matchAut horAndUserStyles, bool includeSMILProperties);
294 void matchUARules(ElementRuleCollector&); 310 void matchUARules(ElementRuleCollector&);
295 void matchUserRules(ElementRuleCollector&, bool includeEmptyRules); 311 void matchUserRules(ElementRuleCollector&, bool includeEmptyRules);
296 void collectFeatures(); 312 void collectFeatures();
297 void collectTreeBoundaryCrossingRules(ElementRuleCollector&, bool includeEmp tyRules); 313 void collectTreeBoundaryCrossingRules(ElementRuleCollector&, bool includeEmp tyRules);
314 void resetRuleFeatures();
298 315
299 bool fastRejectSelector(const RuleData&) const; 316 bool fastRejectSelector(const RuleData&) const;
300 317
301 void applyMatchedProperties(StyleResolverState&, const MatchResult&); 318 void applyMatchedProperties(StyleResolverState&, const MatchResult&);
302 319
303 enum StyleApplicationPass { 320 enum StyleApplicationPass {
304 VariableDefinitions, 321 VariableDefinitions,
305 AnimationProperties, 322 AnimationProperties,
306 HighPriorityProperties, 323 HighPriorityProperties,
307 LowPriorityProperties 324 LowPriorityProperties
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 360
344 Document& m_document; 361 Document& m_document;
345 SelectorFilter m_selectorFilter; 362 SelectorFilter m_selectorFilter;
346 363
347 bool m_matchAuthorAndUserStyles; 364 bool m_matchAuthorAndUserStyles;
348 365
349 RefPtr<CSSFontSelector> m_fontSelector; 366 RefPtr<CSSFontSelector> m_fontSelector;
350 367
351 RefPtr<ViewportStyleResolver> m_viewportStyleResolver; 368 RefPtr<ViewportStyleResolver> m_viewportStyleResolver;
352 369
370 ListHashSet<CSSStyleSheet*, 16> m_pendingStyleSheets;
371
353 ScopedStyleTree m_styleTree; 372 ScopedStyleTree m_styleTree;
354 373
355 // FIXME: The entire logic of collecting features on StyleResolver, as well astransferring them 374 // FIXME: The entire logic of collecting features on StyleResolver, as well astransferring them
356 // between various parts of machinery smells wrong. This needs to be better somehow. 375 // between various parts of machinery smells wrong. This needs to be better somehow.
357 RuleFeatureSet m_features; 376 RuleFeatureSet m_features;
358 OwnPtr<RuleSet> m_siblingRuleSet; 377 OwnPtr<RuleSet> m_siblingRuleSet;
359 OwnPtr<RuleSet> m_uncommonAttributeRuleSet; 378 OwnPtr<RuleSet> m_uncommonAttributeRuleSet;
379 bool m_needCollectFeatures;
360 380
361 InspectorCSSOMWrappers m_inspectorCSSOMWrappers; 381 InspectorCSSOMWrappers m_inspectorCSSOMWrappers;
362 382
363 StyleResourceLoader m_styleResourceLoader; 383 StyleResourceLoader m_styleResourceLoader;
364 384
365 StyleSharingList m_styleSharingList; 385 StyleSharingList m_styleSharingList;
366 386
367 #ifdef STYLE_STATS 387 #ifdef STYLE_STATS
368 static StyleSharingStats m_styleSharingStats; 388 static StyleSharingStats m_styleSharingStats;
369 #endif 389 #endif
370 }; 390 };
371 391
372 inline bool checkRegionSelector(const CSSSelector* regionSelector, Element* regi onElement) 392 inline bool checkRegionSelector(const CSSSelector* regionSelector, Element* regi onElement)
373 { 393 {
374 if (!regionSelector || !regionElement) 394 if (!regionSelector || !regionElement)
375 return false; 395 return false;
376 396
377 SelectorChecker selectorChecker(regionElement->document(), SelectorChecker:: QueryingRules); 397 SelectorChecker selectorChecker(regionElement->document(), SelectorChecker:: QueryingRules);
378 for (const CSSSelector* s = regionSelector; s; s = CSSSelectorList::next(s)) { 398 for (const CSSSelector* s = regionSelector; s; s = CSSSelectorList::next(s)) {
379 SelectorChecker::SelectorCheckingContext selectorCheckingContext(s, regi onElement, SelectorChecker::VisitedMatchDisabled); 399 SelectorChecker::SelectorCheckingContext selectorCheckingContext(s, regi onElement, SelectorChecker::VisitedMatchDisabled);
380 PseudoId ignoreDynamicPseudo = NOPSEUDO; 400 PseudoId ignoreDynamicPseudo = NOPSEUDO;
381 if (selectorChecker.match(selectorCheckingContext, ignoreDynamicPseudo, DOMSiblingTraversalStrategy()) == SelectorChecker::SelectorMatches) 401 if (selectorChecker.match(selectorCheckingContext, ignoreDynamicPseudo, DOMSiblingTraversalStrategy()) == SelectorChecker::SelectorMatches)
382 return true; 402 return true;
383 } 403 }
384 return false; 404 return false;
385 } 405 }
386 406
407 inline bool isDocumentScope(const ContainerNode* scope)
408 {
409 return !scope || scope->isDocumentNode();
410 }
411
412 inline void appendPendingStyleSheetsIfNeeded(StyleResolver* styleResolver)
413 {
414 if (!styleResolver || !styleResolver->hasPendingAuthorStyleSheets())
415 return;
416 styleResolver->appendPendingAuthorStyleSheets();
417 }
418
387 } // namespace WebCore 419 } // namespace WebCore
388 420
389 #endif // StyleResolver_h 421 #endif // StyleResolver_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698