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

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

Issue 27537009: Avoid always style recalc when removing stylesheets. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Add the virtual/* versions of add-keyframes to TestExpectations Created 7 years, 2 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
« no previous file with comments | « LayoutTests/animations/add-keyframes.html ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 112
113 return scope; 113 return scope;
114 } 114 }
115 if (ownerElement->isRegisteredAsScoped() && hasAtHostRule(styleSheetCont ents)) 115 if (ownerElement->isRegisteredAsScoped() && hasAtHostRule(styleSheetCont ents))
116 return ownerElement->containingShadowRoot()->shadowHost(); 116 return ownerElement->containingShadowRoot()->shadowHost();
117 } 117 }
118 118
119 return ownerElement->isRegisteredInShadowRoot() ? ownerElement->containingSh adowRoot()->shadowHost() : ownerElement->parentNode(); 119 return ownerElement->isRegisteredInShadowRoot() ? ownerElement->containingSh adowRoot()->shadowHost() : ownerElement->parentNode();
120 } 120 }
121 121
122 static bool ruleAdditionMightRequireDocumentStyleRecalc(StyleRuleBase* rule)
123 {
124 // This funciton is conservative. We only return false when we know that
125 // the added @rule can't require style recalcs.
126 switch (rule->type()) {
127 case StyleRule::Import: // Whatever we import should do its own analysis, we don't need to invalidate the document here!
128 case StyleRule::Keyframes: // Keyframes never cause style invalidations and are handled during sheet insertion.
129 case StyleRule::Page: // Page rules apply only during printing, we force a f ull-recalc before printing.
130 return false;
131
132 case StyleRule::Media: // If the media rule doesn't apply, we could avoid re calc.
133 case StyleRule::FontFace: // If the fonts aren't in use, we could avoid reca lc.
134 case StyleRule::Supports: // If we evaluated the supports-clause we could av oid recalc.
135 case StyleRule::Viewport: // If the viewport doesn't match, we could avoid r ecalcing.
136 // FIXME: Unclear if any of the rest need to cause style recalc:
137 case StyleRule::Region:
138 case StyleRule::Filter:
139 case StyleRule::HostInternal:
140 return true;
141
142 // These should all be impossible to reach:
143 case StyleRule::Unknown:
144 case StyleRule::Charset:
145 case StyleRule::Keyframe:
146 case StyleRule::Style:
147 break;
148 }
149 ASSERT_NOT_REACHED();
150 return true;
151 }
152
122 void StyleInvalidationAnalysis::analyzeStyleSheet(StyleSheetContents* styleSheet Contents) 153 void StyleInvalidationAnalysis::analyzeStyleSheet(StyleSheetContents* styleSheet Contents)
123 { 154 {
124 ASSERT(!styleSheetContents->isLoading()); 155 ASSERT(!styleSheetContents->isLoading());
125 156
126 // See if all rules on the sheet are scoped to some specific ids or classes. 157 // See if all rules on the sheet are scoped to some specific ids or classes.
127 // Then test if we actually have any of those in the tree at the moment. 158 // Then test if we actually have any of those in the tree at the moment.
128 const Vector<RefPtr<StyleRuleImport> >& importRules = styleSheetContents->im portRules(); 159 const Vector<RefPtr<StyleRuleImport> >& importRules = styleSheetContents->im portRules();
129 for (unsigned i = 0; i < importRules.size(); ++i) { 160 for (unsigned i = 0; i < importRules.size(); ++i) {
130 if (!importRules[i]->styleSheet()) 161 if (!importRules[i]->styleSheet())
131 continue; 162 continue;
132 analyzeStyleSheet(importRules[i]->styleSheet()); 163 analyzeStyleSheet(importRules[i]->styleSheet());
133 if (m_dirtiesAllStyle) 164 if (m_dirtiesAllStyle)
134 return; 165 return;
135 } 166 }
136 if (styleSheetContents->hasSingleOwnerNode()) { 167 if (styleSheetContents->hasSingleOwnerNode()) {
137 Node* ownerNode = styleSheetContents->singleOwnerNode(); 168 Node* ownerNode = styleSheetContents->singleOwnerNode();
138 if (ownerNode && ownerNode->hasTagName(HTMLNames::styleTag) && toHTMLSty leElement(ownerNode)->isRegisteredAsScoped()) { 169 if (ownerNode && ownerNode->hasTagName(HTMLNames::styleTag) && toHTMLSty leElement(ownerNode)->isRegisteredAsScoped()) {
139 m_scopingNodes.append(determineScopingNodeForStyleScoped(toHTMLStyle Element(ownerNode), styleSheetContents)); 170 m_scopingNodes.append(determineScopingNodeForStyleScoped(toHTMLStyle Element(ownerNode), styleSheetContents));
140 return; 171 return;
141 } 172 }
142 } 173 }
143 174
144 const Vector<RefPtr<StyleRuleBase> >& rules = styleSheetContents->childRules (); 175 const Vector<RefPtr<StyleRuleBase> >& rules = styleSheetContents->childRules ();
145 for (unsigned i = 0; i < rules.size(); i++) { 176 for (unsigned i = 0; i < rules.size(); i++) {
146 StyleRuleBase* rule = rules[i].get(); 177 StyleRuleBase* rule = rules[i].get();
147 if (!rule->isStyleRule()) { 178 if (!rule->isStyleRule()) {
148 // FIXME: Media rules and maybe some others could be allowed. 179 if (ruleAdditionMightRequireDocumentStyleRecalc(rule)) {
149 m_dirtiesAllStyle = true; 180 m_dirtiesAllStyle = true;
150 return; 181 return;
182 }
183 continue;
151 } 184 }
152 StyleRule* styleRule = toStyleRule(rule); 185 StyleRule* styleRule = toStyleRule(rule);
153 if (!determineSelectorScopes(styleRule->selectorList(), m_idScopes, m_cl assScopes)) { 186 if (!determineSelectorScopes(styleRule->selectorList(), m_idScopes, m_cl assScopes)) {
154 m_dirtiesAllStyle = true; 187 m_dirtiesAllStyle = true;
155 return; 188 return;
156 } 189 }
157 } 190 }
158 } 191 }
159 192
160 static bool elementMatchesSelectorScopes(const Element* element, const HashSet<S tringImpl*>& idScopes, const HashSet<StringImpl*>& classScopes) 193 static bool elementMatchesSelectorScopes(const Element* element, const HashSet<S tringImpl*>& idScopes, const HashSet<StringImpl*>& classScopes)
(...skipping 27 matching lines...) Expand all
188 element->setNeedsStyleRecalc(); 221 element->setNeedsStyleRecalc();
189 // The whole subtree is now invalidated, we can skip to the next sib ling. 222 // The whole subtree is now invalidated, we can skip to the next sib ling.
190 element = ElementTraversal::nextSkippingChildren(element); 223 element = ElementTraversal::nextSkippingChildren(element);
191 continue; 224 continue;
192 } 225 }
193 element = ElementTraversal::next(element); 226 element = ElementTraversal::next(element);
194 } 227 }
195 } 228 }
196 229
197 } 230 }
OLDNEW
« no previous file with comments | « LayoutTests/animations/add-keyframes.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698