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

Side by Side Diff: Source/core/css/invalidation/StyleSheetInvalidationAnalysis.cpp

Issue 325663003: Remove scoped styles (retry) (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Fix layout test (and expectation) Created 6 years, 6 months 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) 2012 Apple Inc. All rights reserved. 2 * Copyright (C) 2012 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 const StyleRule* styleRule = toStyleRule(rule); 85 const StyleRule* styleRule = toStyleRule(rule);
86 const CSSSelectorList& selectorList = styleRule->selectorList(); 86 const CSSSelectorList& selectorList = styleRule->selectorList();
87 for (size_t selectorIndex = 0; selectorIndex != kNotFound; selectorIndex = selectorList.indexOfNextSelectorAfter(selectorIndex)) { 87 for (size_t selectorIndex = 0; selectorIndex != kNotFound; selectorIndex = selectorList.indexOfNextSelectorAfter(selectorIndex)) {
88 if (selectorList.hasShadowDistributedAt(selectorIndex)) 88 if (selectorList.hasShadowDistributedAt(selectorIndex))
89 return true; 89 return true;
90 } 90 }
91 } 91 }
92 return false; 92 return false;
93 } 93 }
94 94
95 static Node* determineScopingNodeForStyleScoped(HTMLStyleElement* ownerElement, StyleSheetContents* styleSheetContents) 95 static Node* determineScopingNodeForStyleInShadow(HTMLStyleElement* ownerElement , StyleSheetContents* styleSheetContents)
96 { 96 {
97 ASSERT(ownerElement && ownerElement->isRegisteredAsScoped()); 97 ASSERT(ownerElement && ownerElement->isInShadowTree());
98 98
99 if (ownerElement->isInShadowTree()) { 99 if (hasDistributedRule(styleSheetContents)) {
100 if (hasDistributedRule(styleSheetContents)) { 100 ContainerNode* scope = ownerElement;
101 ContainerNode* scope = ownerElement; 101 do {
102 do { 102 scope = scope->containingShadowRoot()->shadowHost();
103 scope = scope->containingShadowRoot()->shadowHost(); 103 } while (scope->isInShadowTree());
104 } while (scope->isInShadowTree()); 104 return scope;
105
106 return scope;
107 }
108 if (ownerElement->isRegisteredAsScoped())
109 return ownerElement->containingShadowRoot()->shadowHost();
110 } 105 }
111 106
112 return ownerElement->isRegisteredInShadowRoot() ? ownerElement->containingSh adowRoot()->shadowHost() : ownerElement->parentNode(); 107 return ownerElement->containingShadowRoot()->shadowHost();
113 } 108 }
114 109
115 static bool ruleAdditionMightRequireDocumentStyleRecalc(StyleRuleBase* rule) 110 static bool ruleAdditionMightRequireDocumentStyleRecalc(StyleRuleBase* rule)
116 { 111 {
117 // This funciton is conservative. We only return false when we know that 112 // This funciton is conservative. We only return false when we know that
118 // the added @rule can't require style recalcs. 113 // the added @rule can't require style recalcs.
119 switch (rule->type()) { 114 switch (rule->type()) {
120 case StyleRule::Import: // Whatever we import should do its own analysis, we don't need to invalidate the document here! 115 case StyleRule::Import: // Whatever we import should do its own analysis, we don't need to invalidate the document here!
121 case StyleRule::Keyframes: // Keyframes never cause style invalidations and are handled during sheet insertion. 116 case StyleRule::Keyframes: // Keyframes never cause style invalidations and are handled during sheet insertion.
122 case StyleRule::Page: // Page rules apply only during printing, we force a f ull-recalc before printing. 117 case StyleRule::Page: // Page rules apply only during printing, we force a f ull-recalc before printing.
(...skipping 27 matching lines...) Expand all
150 const WillBeHeapVector<RefPtrWillBeMember<StyleRuleImport> >& importRules = styleSheetContents->importRules(); 145 const WillBeHeapVector<RefPtrWillBeMember<StyleRuleImport> >& importRules = styleSheetContents->importRules();
151 for (unsigned i = 0; i < importRules.size(); ++i) { 146 for (unsigned i = 0; i < importRules.size(); ++i) {
152 if (!importRules[i]->styleSheet()) 147 if (!importRules[i]->styleSheet())
153 continue; 148 continue;
154 analyzeStyleSheet(importRules[i]->styleSheet()); 149 analyzeStyleSheet(importRules[i]->styleSheet());
155 if (m_dirtiesAllStyle) 150 if (m_dirtiesAllStyle)
156 return; 151 return;
157 } 152 }
158 if (styleSheetContents->hasSingleOwnerNode()) { 153 if (styleSheetContents->hasSingleOwnerNode()) {
159 Node* ownerNode = styleSheetContents->singleOwnerNode(); 154 Node* ownerNode = styleSheetContents->singleOwnerNode();
160 if (isHTMLStyleElement(ownerNode) && toHTMLStyleElement(*ownerNode).isRe gisteredAsScoped()) { 155 if (isHTMLStyleElement(ownerNode) && toHTMLStyleElement(*ownerNode).isIn ShadowTree()) {
161 m_scopingNodes.append(determineScopingNodeForStyleScoped(toHTMLStyle Element(ownerNode), styleSheetContents)); 156 m_scopingNodes.append(determineScopingNodeForStyleInShadow(toHTMLSty leElement(ownerNode), styleSheetContents));
162 return; 157 return;
163 } 158 }
164 } 159 }
165 160
166 const WillBeHeapVector<RefPtrWillBeMember<StyleRuleBase> >& rules = styleShe etContents->childRules(); 161 const WillBeHeapVector<RefPtrWillBeMember<StyleRuleBase> >& rules = styleShe etContents->childRules();
167 for (unsigned i = 0; i < rules.size(); i++) { 162 for (unsigned i = 0; i < rules.size(); i++) {
168 StyleRuleBase* rule = rules[i].get(); 163 StyleRuleBase* rule = rules[i].get();
169 if (!rule->isStyleRule()) { 164 if (!rule->isStyleRule()) {
170 if (ruleAdditionMightRequireDocumentStyleRecalc(rule)) { 165 if (ruleAdditionMightRequireDocumentStyleRecalc(rule)) {
171 m_dirtiesAllStyle = true; 166 m_dirtiesAllStyle = true;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 element->setNeedsStyleRecalc(SubtreeStyleChange); 207 element->setNeedsStyleRecalc(SubtreeStyleChange);
213 // The whole subtree is now invalidated, we can skip to the next sib ling. 208 // The whole subtree is now invalidated, we can skip to the next sib ling.
214 element = ElementTraversal::nextSkippingChildren(*element); 209 element = ElementTraversal::nextSkippingChildren(*element);
215 continue; 210 continue;
216 } 211 }
217 element = ElementTraversal::next(*element); 212 element = ElementTraversal::next(*element);
218 } 213 }
219 } 214 }
220 215
221 } 216 }
OLDNEW
« no previous file with comments | « LayoutTests/fast/dom/shadow/style-scoped-not-enabled-expected.txt ('k') | Source/core/css/resolver/ScopedStyleResolver.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698