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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « LayoutTests/animations/add-keyframes.html ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/css/StyleInvalidationAnalysis.cpp
diff --git a/Source/core/css/StyleInvalidationAnalysis.cpp b/Source/core/css/StyleInvalidationAnalysis.cpp
index 6fa9e012a57def7e8c70ec8efc8d40377ad1733d..b0053cb64e92f05ec0d5ee0d934b6e2ad697408b 100644
--- a/Source/core/css/StyleInvalidationAnalysis.cpp
+++ b/Source/core/css/StyleInvalidationAnalysis.cpp
@@ -119,6 +119,37 @@ static Node* determineScopingNodeForStyleScoped(HTMLStyleElement* ownerElement,
return ownerElement->isRegisteredInShadowRoot() ? ownerElement->containingShadowRoot()->shadowHost() : ownerElement->parentNode();
}
+static bool ruleAdditionMightRequireDocumentStyleRecalc(StyleRuleBase* rule)
+{
+ // This funciton is conservative. We only return false when we know that
+ // the added @rule can't require style recalcs.
+ switch (rule->type()) {
+ case StyleRule::Import: // Whatever we import should do its own analysis, we don't need to invalidate the document here!
+ case StyleRule::Keyframes: // Keyframes never cause style invalidations and are handled during sheet insertion.
+ case StyleRule::Page: // Page rules apply only during printing, we force a full-recalc before printing.
+ return false;
+
+ case StyleRule::Media: // If the media rule doesn't apply, we could avoid recalc.
+ case StyleRule::FontFace: // If the fonts aren't in use, we could avoid recalc.
+ case StyleRule::Supports: // If we evaluated the supports-clause we could avoid recalc.
+ case StyleRule::Viewport: // If the viewport doesn't match, we could avoid recalcing.
+ // FIXME: Unclear if any of the rest need to cause style recalc:
+ case StyleRule::Region:
+ case StyleRule::Filter:
+ case StyleRule::HostInternal:
+ return true;
+
+ // These should all be impossible to reach:
+ case StyleRule::Unknown:
+ case StyleRule::Charset:
+ case StyleRule::Keyframe:
+ case StyleRule::Style:
+ break;
+ }
+ ASSERT_NOT_REACHED();
+ return true;
+}
+
void StyleInvalidationAnalysis::analyzeStyleSheet(StyleSheetContents* styleSheetContents)
{
ASSERT(!styleSheetContents->isLoading());
@@ -145,9 +176,11 @@ void StyleInvalidationAnalysis::analyzeStyleSheet(StyleSheetContents* styleSheet
for (unsigned i = 0; i < rules.size(); i++) {
StyleRuleBase* rule = rules[i].get();
if (!rule->isStyleRule()) {
- // FIXME: Media rules and maybe some others could be allowed.
- m_dirtiesAllStyle = true;
- return;
+ if (ruleAdditionMightRequireDocumentStyleRecalc(rule)) {
+ m_dirtiesAllStyle = true;
+ return;
+ }
+ continue;
}
StyleRule* styleRule = toStyleRule(rule);
if (!determineSelectorScopes(styleRule->selectorList(), m_idScopes, m_classScopes)) {
« 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