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

Side by Side Diff: Source/core/css/RuleSet.cpp

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 * (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com) 3 * (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com)
4 * Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.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 r ights reserved. 5 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All r ights reserved.
6 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org> 6 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org>
7 * Copyright (C) 2007, 2008 Eric Seidel <eric@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.t orchmobile.com/) 8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/)
9 * Copyright (c) 2011, Code Aurora Forum. All rights reserved. 9 * Copyright (c) 2011, Code Aurora Forum. All rights reserved.
10 * Copyright (C) Research In Motion Limited 2011. All rights reserved. 10 * Copyright (C) Research In Motion Limited 2011. All rights reserved.
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 #include "core/css/resolver/StyleResolver.h" 45 #include "core/css/resolver/StyleResolver.h"
46 #include "core/html/track/TextTrackCue.h" 46 #include "core/html/track/TextTrackCue.h"
47 #include "weborigin/SecurityOrigin.h" 47 #include "weborigin/SecurityOrigin.h"
48 48
49 namespace WebCore { 49 namespace WebCore {
50 50
51 using namespace HTMLNames; 51 using namespace HTMLNames;
52 52
53 // ----------------------------------------------------------------- 53 // -----------------------------------------------------------------
54 54
55 static inline bool isDocumentScope(const ContainerNode* scope)
56 {
57 return !scope || scope->isDocumentNode();
58 }
59
60 static inline bool isScopingNodeInShadowTree(const ContainerNode* scopingNode) 55 static inline bool isScopingNodeInShadowTree(const ContainerNode* scopingNode)
61 { 56 {
62 return scopingNode && scopingNode->isInShadowTree(); 57 return scopingNode && scopingNode->isInShadowTree();
63 } 58 }
64 59
65 static inline bool isSelectorMatchingHTMLBasedOnRuleHash(const CSSSelector* sele ctor) 60 static inline bool isSelectorMatchingHTMLBasedOnRuleHash(const CSSSelector* sele ctor)
66 { 61 {
67 ASSERT(selector); 62 ASSERT(selector);
68 if (selector->m_match == CSSSelector::Tag) { 63 if (selector->m_match == CSSSelector::Tag) {
69 const AtomicString& selectorNamespace = selector->tagQName().namespaceUR I(); 64 const AtomicString& selectorNamespace = selector->tagQName().namespaceUR I();
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 resolver->ruleSets().treeBoundaryCrossingRules().addRule(sty leRule, selectorIndex, const_cast<ContainerNode*>(scope), addRuleFlags); 372 resolver->ruleSets().treeBoundaryCrossingRules().addRule(sty leRule, selectorIndex, const_cast<ContainerNode*>(scope), addRuleFlags);
378 } else 373 } else
379 addRule(styleRule, selectorIndex, addRuleFlags); 374 addRule(styleRule, selectorIndex, addRuleFlags);
380 } 375 }
381 } else if (rule->isPageRule()) 376 } else if (rule->isPageRule())
382 addPageRule(static_cast<StyleRulePage*>(rule)); 377 addPageRule(static_cast<StyleRulePage*>(rule));
383 else if (rule->isMediaRule()) { 378 else if (rule->isMediaRule()) {
384 StyleRuleMedia* mediaRule = static_cast<StyleRuleMedia*>(rule); 379 StyleRuleMedia* mediaRule = static_cast<StyleRuleMedia*>(rule);
385 if ((!mediaRule->mediaQueries() || medium.eval(mediaRule->mediaQueri es(), resolver->viewportDependentMediaQueryResults()))) 380 if ((!mediaRule->mediaQueries() || medium.eval(mediaRule->mediaQueri es(), resolver->viewportDependentMediaQueryResults())))
386 addChildRules(mediaRule->childRules(), medium, resolver, scope, hasDocumentSecurityOrigin, addRuleFlags); 381 addChildRules(mediaRule->childRules(), medium, resolver, scope, hasDocumentSecurityOrigin, addRuleFlags);
387 } else if (rule->isFontFaceRule() && resolver) { 382 } else if (rule->isFontFaceRule() && resolver && !(addRuleFlags & RuleSk ipsFontFaceAndViewportRule)) {
388 // Add this font face to our set. 383 // Add this font face to our set.
389 // FIXME(BUG 72461): We don't add @font-face rules of scoped style s heets for the moment. 384 // FIXME(BUG 72461): We don't add @font-face rules of scoped style s heets for the moment.
390 if (!isDocumentScope(scope)) 385 if (!isDocumentScope(scope))
391 continue; 386 continue;
392 const StyleRuleFontFace* fontFaceRule = static_cast<StyleRuleFontFac e*>(rule); 387 const StyleRuleFontFace* fontFaceRule = static_cast<StyleRuleFontFac e*>(rule);
393 resolver->fontSelector()->addFontFaceRule(fontFaceRule); 388 resolver->fontSelector()->addFontFaceRule(fontFaceRule);
394 resolver->invalidateMatchedPropertiesCache(); 389 resolver->invalidateMatchedPropertiesCache();
395 } else if (rule->isKeyframesRule() && resolver) { 390 } else if (rule->isKeyframesRule() && resolver) {
396 resolver->ensureScopedStyleResolver(scope)->addKeyframeStyle(static_ cast<StyleRuleKeyframes*>(rule)); 391 resolver->ensureScopedStyleResolver(scope)->addKeyframeStyle(static_ cast<StyleRuleKeyframes*>(rule));
397 } else if (rule->isRegionRule() && resolver) { 392 } else if (rule->isRegionRule() && resolver) {
398 // FIXME (BUG 72472): We don't add @-webkit-region rules of scoped s tyle sheets for the moment. 393 // FIXME (BUG 72472): We don't add @-webkit-region rules of scoped s tyle sheets for the moment.
399 addRegionRule(static_cast<StyleRuleRegion*>(rule), hasDocumentSecuri tyOrigin, scope); 394 addRegionRule(static_cast<StyleRuleRegion*>(rule), hasDocumentSecuri tyOrigin, scope);
400 } else if (rule->isHostRule() && resolver) { 395 } else if (rule->isHostRule() && resolver) {
401 if (!isScopingNodeInShadowTree(scope)) 396 if (!isScopingNodeInShadowTree(scope))
402 continue; 397 continue;
403 bool enabled = resolver->buildScopedStyleTreeInDocumentOrder(); 398 bool enabled = resolver->buildScopedStyleTreeInDocumentOrder();
404 resolver->setBuildScopedStyleTreeInDocumentOrder(false); 399 resolver->setBuildScopedStyleTreeInDocumentOrder(false);
405 resolver->ensureScopedStyleResolver(scope->shadowHost())->addHostRul e(static_cast<StyleRuleHost*>(rule), hasDocumentSecurityOrigin, scope); 400 resolver->ensureScopedStyleResolver(scope->shadowHost())->addHostRul e(static_cast<StyleRuleHost*>(rule), hasDocumentSecurityOrigin, scope);
406 resolver->setBuildScopedStyleTreeInDocumentOrder(enabled); 401 resolver->setBuildScopedStyleTreeInDocumentOrder(enabled);
407 } else if (rule->isViewportRule()) { 402 } else if (rule->isViewportRule() && !(addRuleFlags & RuleSkipsFontFaceA ndViewportRule)) {
eseidel 2013/11/06 01:39:10 The double negative reads a bit odd. But I guess
tasak 2013/11/06 05:42:26 Yes, 0 means "no special handling". The 0 is used
408 // @viewport should not be scoped. 403 // @viewport should not be scoped.
409 if (!isDocumentScope(scope)) 404 if (!isDocumentScope(scope))
410 continue; 405 continue;
411 addViewportRule(static_cast<StyleRuleViewport*>(rule)); 406 addViewportRule(static_cast<StyleRuleViewport*>(rule));
412 } 407 }
413 else if (rule->isSupportsRule() && static_cast<StyleRuleSupports*>(rule) ->conditionIsSupported()) 408 else if (rule->isSupportsRule() && static_cast<StyleRuleSupports*>(rule) ->conditionIsSupported())
414 addChildRules(static_cast<StyleRuleSupports*>(rule)->childRules(), m edium, resolver, scope, hasDocumentSecurityOrigin, addRuleFlags); 409 addChildRules(static_cast<StyleRuleSupports*>(rule)->childRules(), m edium, resolver, scope, hasDocumentSecurityOrigin, addRuleFlags);
415 } 410 }
416 } 411 }
417 412
418 void RuleSet::addRulesFromSheet(StyleSheetContents* sheet, const MediaQueryEvalu ator& medium, StyleResolver* resolver, const ContainerNode* scope) 413 void RuleSet::addRulesFromSheet(StyleSheetContents* sheet, const MediaQueryEvalu ator& medium, StyleResolver* resolver, const ContainerNode* scope, bool processF ontFaceAndViewportRule)
419 { 414 {
420 ASSERT(sheet); 415 ASSERT(sheet);
421 416
422 const Vector<RefPtr<StyleRuleImport> >& importRules = sheet->importRules(); 417 const Vector<RefPtr<StyleRuleImport> >& importRules = sheet->importRules();
423 for (unsigned i = 0; i < importRules.size(); ++i) { 418 for (unsigned i = 0; i < importRules.size(); ++i) {
424 StyleRuleImport* importRule = importRules[i].get(); 419 StyleRuleImport* importRule = importRules[i].get();
425 if (importRule->styleSheet() && (!importRule->mediaQueries() || medium.e val(importRule->mediaQueries(), resolver->viewportDependentMediaQueryResults())) ) 420 if (importRule->styleSheet() && (!importRule->mediaQueries() || medium.e val(importRule->mediaQueries(), resolver->viewportDependentMediaQueryResults())) )
426 addRulesFromSheet(importRule->styleSheet(), medium, resolver, scope) ; 421 addRulesFromSheet(importRule->styleSheet(), medium, resolver, scope, processFontFaceAndViewportRule);
427 } 422 }
428 423
429 bool hasDocumentSecurityOrigin = resolver && resolver->document().securityOr igin()->canRequest(sheet->baseURL()); 424 bool hasDocumentSecurityOrigin = resolver && resolver->document().securityOr igin()->canRequest(sheet->baseURL());
430 AddRuleFlags addRuleFlags = static_cast<AddRuleFlags>((hasDocumentSecurityOr igin ? RuleHasDocumentSecurityOrigin : 0) | (!scope ? RuleCanUseFastCheckSelecto r : 0)); 425 AddRuleFlags addRuleFlags = static_cast<AddRuleFlags>((hasDocumentSecurityOr igin ? RuleHasDocumentSecurityOrigin : 0) | (!scope ? RuleCanUseFastCheckSelecto r : 0) | (processFontFaceAndViewportRule ? 0 : RuleSkipsFontFaceAndViewportRule) );
431 426
432 addChildRules(sheet->childRules(), medium, resolver, scope, hasDocumentSecur ityOrigin, addRuleFlags); 427 addChildRules(sheet->childRules(), medium, resolver, scope, hasDocumentSecur ityOrigin, addRuleFlags);
433 } 428 }
434 429
435 void RuleSet::addStyleRule(StyleRule* rule, AddRuleFlags addRuleFlags) 430 void RuleSet::addStyleRule(StyleRule* rule, AddRuleFlags addRuleFlags)
436 { 431 {
437 for (size_t selectorIndex = 0; selectorIndex != kNotFound; selectorIndex = r ule->selectorList().indexOfNextSelectorAfter(selectorIndex)) 432 for (size_t selectorIndex = 0; selectorIndex != kNotFound; selectorIndex = r ule->selectorList().indexOfNextSelectorAfter(selectorIndex))
438 addRule(rule, selectorIndex, addRuleFlags); 433 addRule(rule, selectorIndex, addRuleFlags);
439 } 434 }
440 435
(...skipping 25 matching lines...) Expand all
466 compactPendingRules(pendingRules->shadowPseudoElementRules, m_shadowPseudoEl ementRules); 461 compactPendingRules(pendingRules->shadowPseudoElementRules, m_shadowPseudoEl ementRules);
467 m_linkPseudoClassRules.shrinkToFit(); 462 m_linkPseudoClassRules.shrinkToFit();
468 m_cuePseudoRules.shrinkToFit(); 463 m_cuePseudoRules.shrinkToFit();
469 m_focusPseudoClassRules.shrinkToFit(); 464 m_focusPseudoClassRules.shrinkToFit();
470 m_universalRules.shrinkToFit(); 465 m_universalRules.shrinkToFit();
471 m_pageRules.shrinkToFit(); 466 m_pageRules.shrinkToFit();
472 m_viewportRules.shrinkToFit(); 467 m_viewportRules.shrinkToFit();
473 } 468 }
474 469
475 } // namespace WebCore 470 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698