Index: Source/core/dom/DocumentStyleSheetCollection.cpp |
diff --git a/Source/core/dom/DocumentStyleSheetCollection.cpp b/Source/core/dom/DocumentStyleSheetCollection.cpp |
index 4735ab200294a4817fdd4094c5eec8d4ab3a72e1..75cf467b03e3fe78bcccb52730429fa2c541285c 100644 |
--- a/Source/core/dom/DocumentStyleSheetCollection.cpp |
+++ b/Source/core/dom/DocumentStyleSheetCollection.cpp |
@@ -351,11 +351,10 @@ void DocumentStyleSheetCollection::collectActiveStyleSheets(Vector<RefPtr<StyleS |
} |
} |
-void DocumentStyleSheetCollection::analyzeStyleSheetChange(UpdateFlag updateFlag, const Vector<RefPtr<CSSStyleSheet> >& newStylesheets, StyleResolverUpdateType& styleResolverUpdateType, bool& requiresFullStyleRecalc) |
+DocumentStyleSheetCollection::UpdateAction DocumentStyleSheetCollection::analyzeStyleSheetChange(StyleResolverUpdateMode updateMode, const Vector<RefPtr<CSSStyleSheet> >& newStylesheets, bool& requiresFullStyleRecalc) |
{ |
- styleResolverUpdateType = Reconstruct; |
- requiresFullStyleRecalc = true; |
- |
+ // FIXME: Updating the active loading sheet state shouldn't be in this method. |
+ |
// Stylesheets of <style> elements that @import stylesheets are active but loading. We need to trigger a full recalc when such loads are done. |
bool hasActiveLoadingStylesheet = false; |
unsigned newStylesheetCount = newStylesheets.size(); |
@@ -365,29 +364,29 @@ void DocumentStyleSheetCollection::analyzeStyleSheetChange(UpdateFlag updateFlag |
} |
if (m_hadActiveLoadingStylesheet && !hasActiveLoadingStylesheet) { |
m_hadActiveLoadingStylesheet = false; |
- return; |
+ return Reconstruct; |
} |
m_hadActiveLoadingStylesheet = hasActiveLoadingStylesheet; |
- if (updateFlag != OptimizedUpdate) |
- return; |
+ if (updateMode != OptimizedStyleUpdate) |
+ return Reconstruct; |
if (!m_document->styleResolverIfExists()) |
- return; |
+ return Reconstruct; |
// Find out which stylesheets are new. |
unsigned oldStylesheetCount = m_activeAuthorStyleSheets.size(); |
if (newStylesheetCount < oldStylesheetCount) |
- return; |
+ return Reconstruct; |
Vector<StyleSheetContents*> addedSheets; |
unsigned newIndex = 0; |
for (unsigned oldIndex = 0; oldIndex < oldStylesheetCount; ++oldIndex) { |
if (newIndex >= newStylesheetCount) |
- return; |
+ return Reconstruct; |
while (m_activeAuthorStyleSheets[oldIndex] != newStylesheets[newIndex]) { |
addedSheets.append(newStylesheets[newIndex]->contents()); |
++newIndex; |
if (newIndex == newStylesheetCount) |
- return; |
+ return Reconstruct; |
} |
++newIndex; |
} |
@@ -396,18 +395,23 @@ void DocumentStyleSheetCollection::analyzeStyleSheetChange(UpdateFlag updateFlag |
addedSheets.append(newStylesheets[newIndex]->contents()); |
++newIndex; |
} |
+ |
+ // If we don't have a body yet it's unlikely there's enough nodes to warrant |
+ // doing analysis. If there's place holder styles we do a full recalc to turn |
+ // them into real styles. |
+ // |
+ // FIXME: It's not clear why analysis isn't safe for placeholder styles. |
+ if (m_document->body() && !m_document->hasNodesWithPlaceholderStyle()) { |
+ StyleInvalidationAnalysis invalidationAnalysis(addedSheets); |
+ if (!invalidationAnalysis.dirtiesAllStyle()) { |
+ invalidationAnalysis.invalidateStyle(m_document); |
+ requiresFullStyleRecalc = false; |
+ } |
+ } |
+ |
// If all new sheets were added at the end of the list we can just add them to existing StyleResolver. |
// If there were insertions we need to re-add all the stylesheets so rules are ordered correctly. |
- styleResolverUpdateType = hasInsertions ? Reset : Additive; |
- |
- // If we are already parsing the body and so may have significant amount of elements, put some effort into trying to avoid style recalcs. |
- if (!m_document->body() || m_document->hasNodesWithPlaceholderStyle()) |
- return; |
- StyleInvalidationAnalysis invalidationAnalysis(addedSheets); |
- if (invalidationAnalysis.dirtiesAllStyle()) |
- return; |
- invalidationAnalysis.invalidateStyle(m_document); |
- requiresFullStyleRecalc = false; |
+ return hasInsertions ? Reset : Append; |
} |
static bool styleSheetsUseRemUnits(const Vector<RefPtr<CSSStyleSheet> >& sheets) |
@@ -438,7 +442,7 @@ static void collectActiveCSSStyleSheetsFromSeamlessParents(Vector<RefPtr<CSSStyl |
sheets.append(seamlessParentIFrame->document()->styleSheetCollection()->activeAuthorStyleSheets()); |
} |
-bool DocumentStyleSheetCollection::updateActiveStyleSheets(UpdateFlag updateFlag) |
+bool DocumentStyleSheetCollection::updateActiveStyleSheets(StyleResolverUpdateMode updateMode) |
{ |
if (m_document->inStyleRecalc()) { |
// SVG <use> element may manage to invalidate style selector in the middle of a style recalc. |
@@ -447,8 +451,8 @@ bool DocumentStyleSheetCollection::updateActiveStyleSheets(UpdateFlag updateFlag |
m_needsUpdateActiveStylesheetsOnStyleRecalc = true; |
m_document->scheduleForcedStyleRecalc(); |
return false; |
- |
} |
+ |
if (!m_document->renderer() || !m_document->attached()) |
return false; |
@@ -461,23 +465,24 @@ bool DocumentStyleSheetCollection::updateActiveStyleSheets(UpdateFlag updateFlag |
collectActiveCSSStyleSheetsFromSeamlessParents(activeCSSStyleSheets, m_document); |
filterEnabledCSSStyleSheets(activeCSSStyleSheets, activeStyleSheets); |
- StyleResolverUpdateType styleResolverUpdateType; |
- bool requiresFullStyleRecalc; |
- analyzeStyleSheetChange(updateFlag, activeCSSStyleSheets, styleResolverUpdateType, requiresFullStyleRecalc); |
+ bool requiresFullStyleRecalc = true; |
+ UpdateAction action = analyzeStyleSheetChange(updateMode, activeCSSStyleSheets, requiresFullStyleRecalc); |
- if (styleResolverUpdateType == Reconstruct) |
+ switch (action) { |
+ case Reconstruct: |
m_document->clearStyleResolver(); |
- else { |
- StyleResolver* styleResolver = m_document->styleResolver(); |
- if (styleResolverUpdateType == Reset) { |
- styleResolver->ruleSets().resetAuthorStyle(); |
- styleResolver->appendAuthorStyleSheets(0, activeCSSStyleSheets); |
- } else { |
- ASSERT(styleResolverUpdateType == Additive); |
- styleResolver->appendAuthorStyleSheets(m_activeAuthorStyleSheets.size(), activeCSSStyleSheets); |
- } |
+ break; |
+ case Reset: |
+ m_document->styleResolver()->ruleSets().resetAuthorStyle(); |
+ m_document->styleResolver()->appendAuthorStyleSheets(0, activeCSSStyleSheets); |
resetCSSFeatureFlags(); |
+ break; |
+ case Append: |
+ m_document->styleResolver()->appendAuthorStyleSheets(m_activeAuthorStyleSheets.size(), activeCSSStyleSheets); |
+ resetCSSFeatureFlags(); |
+ break; |
} |
+ |
m_activeAuthorStyleSheets.swap(activeCSSStyleSheets); |
InspectorInstrumentation::activeStyleSheetsUpdated(m_document, activeStyleSheets); |
m_styleSheetsForStyleSheetList.swap(activeStyleSheets); |