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

Unified Diff: sky/engine/core/dom/TreeScopeStyleSheetCollection.cpp

Issue 774953002: Always Reconstruct when stylesheets change. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years 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 | « sky/engine/core/dom/TreeScopeStyleSheetCollection.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sky/engine/core/dom/TreeScopeStyleSheetCollection.cpp
diff --git a/sky/engine/core/dom/TreeScopeStyleSheetCollection.cpp b/sky/engine/core/dom/TreeScopeStyleSheetCollection.cpp
index 94835076fa80998662eefd41a77532b42fb02381..0d0c39264f70d9cb049b3eff5d333a9f7f0a765e 100644
--- a/sky/engine/core/dom/TreeScopeStyleSheetCollection.cpp
+++ b/sky/engine/core/dom/TreeScopeStyleSheetCollection.cpp
@@ -29,7 +29,6 @@
#include "sky/engine/core/css/CSSStyleSheet.h"
#include "sky/engine/core/css/StyleSheetContents.h"
-#include "sky/engine/core/css/invalidation/StyleSheetInvalidationAnalysis.h"
#include "sky/engine/core/css/resolver/StyleResolver.h"
#include "sky/engine/core/dom/Element.h"
#include "sky/engine/core/dom/StyleEngine.h"
@@ -60,92 +59,6 @@ void TreeScopeStyleSheetCollection::removeStyleSheetCandidateNode(Node* node, Co
m_styleSheetCandidateNodes.remove(node);
}
-TreeScopeStyleSheetCollection::StyleResolverUpdateType TreeScopeStyleSheetCollection::compareStyleSheets(const Vector<RefPtr<CSSStyleSheet> >& oldStyleSheets, const Vector<RefPtr<CSSStyleSheet> >& newStylesheets, Vector<RawPtr<StyleSheetContents> >& addedSheets)
-{
- unsigned newStyleSheetCount = newStylesheets.size();
- unsigned oldStyleSheetCount = oldStyleSheets.size();
- ASSERT(newStyleSheetCount >= oldStyleSheetCount);
-
- if (!newStyleSheetCount)
- return Reconstruct;
-
- unsigned newIndex = 0;
- for (unsigned oldIndex = 0; oldIndex < oldStyleSheetCount; ++oldIndex) {
- while (oldStyleSheets[oldIndex] != newStylesheets[newIndex]) {
- addedSheets.append(newStylesheets[newIndex]->contents());
- if (++newIndex == newStyleSheetCount)
- return Reconstruct;
- }
- if (++newIndex == newStyleSheetCount)
- return Reconstruct;
- }
- bool hasInsertions = !addedSheets.isEmpty();
- while (newIndex < newStyleSheetCount) {
- addedSheets.append(newStylesheets[newIndex]->contents());
- ++newIndex;
- }
- // 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.
- return hasInsertions ? Reset : Additive;
-}
-
-static bool findFontFaceRulesFromStyleSheetContents(const Vector<RawPtr<StyleSheetContents> >& sheets, Vector<RawPtr<const StyleRuleFontFace> >& fontFaceRules)
-{
- bool hasFontFaceRule = false;
-
- for (unsigned i = 0; i < sheets.size(); ++i) {
- ASSERT(sheets[i]);
- if (sheets[i]->hasFontFaceRule()) {
- // FIXME: We don't need this for styles in shadow tree.
- sheets[i]->findFontFaceRules(fontFaceRules);
- hasFontFaceRule = true;
- }
- }
- return hasFontFaceRule;
-}
-
-void TreeScopeStyleSheetCollection::analyzeStyleSheetChange(StyleResolverUpdateMode updateMode, const StyleSheetCollection& newCollection, StyleSheetChange& change)
-{
- if (updateMode != AnalyzedStyleUpdate)
- return;
-
- // Find out which stylesheets are new.
- Vector<RawPtr<StyleSheetContents> > addedSheets;
- if (m_activeAuthorStyleSheets.size() <= newCollection.activeAuthorStyleSheets().size()) {
- change.styleResolverUpdateType = compareStyleSheets(m_activeAuthorStyleSheets, newCollection.activeAuthorStyleSheets(), addedSheets);
- } else {
- StyleResolverUpdateType updateType = compareStyleSheets(newCollection.activeAuthorStyleSheets(), m_activeAuthorStyleSheets, addedSheets);
- if (updateType != Additive) {
- change.styleResolverUpdateType = updateType;
- } else {
- change.styleResolverUpdateType = Reset;
- // If @font-face is removed, needs full style recalc.
- if (findFontFaceRulesFromStyleSheetContents(addedSheets, change.fontFaceRulesToRemove))
- return;
- }
- }
-
- // FIXME: If styleResolverUpdateType is Reconstruct, we should return early here since
- // we need to recalc the whole document. It's wrong to use StyleSheetInvalidationAnalysis since
- // it only looks at the addedSheets.
-
- // No point in doing the analysis work if we're just going to recalc the whole document anyways.
- // This needs to be done after the compareStyleSheets calls above to ensure we don't throw away
- // the StyleResolver if we don't need to.
- if (document().hasPendingForcedStyleRecalc())
- return;
-
- // 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 (document().hasNodesWithPlaceholderStyle())
- return;
- StyleSheetInvalidationAnalysis invalidationAnalysis(addedSheets);
- if (invalidationAnalysis.dirtiesAllStyle())
- return;
- invalidationAnalysis.invalidateStyle(document());
- change.requiresFullStyleRecalc = false;
- return;
-}
-
void TreeScopeStyleSheetCollection::clearMediaQueryRuleSetStyleSheets()
{
for (size_t i = 0; i < m_activeAuthorStyleSheets.size(); ++i) {
« no previous file with comments | « sky/engine/core/dom/TreeScopeStyleSheetCollection.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698