Reland: Collect active stylesheets and and apply asynchronously.
This CL enables asynchronously updating the lists of active stylesheets
applying any style changes using rule set invalidations. This means we
more often avoid full style recalcs when we add or remove stylesheets
from the document as well as when the evaluation of media queries
change.
In general, we now alway compare new and old stylesheets by comparing
their rulesets and schedule style invalidations for removed and added
rulesets.
When media queries changes, we used to give completely in and
recalculate all style once we discovered a media query changed its
evaluation. With this patch, we clear rule sets for sheets which
contain media queries which means we will invalidate rules for the sets
before and after the query change. This can be further refined by only
clearing rule sets when the sheets has a media query which actually did
change evaluation, and also just schedule invalidations for rules which
are inside @media rules.
TreeScopeStyleSheetCollectionTest.cpp is removed as it is replaced by
ActiveStyleSheetsTest.cpp which landed earlier.
updateActiveStyle() has been added a few places where
ensureStyleResolver() previously caused active stylesheets to be up-to-
date. ensureStyleResolver() is now merely a method which creates the
StyleResolver if necessary and returns it.
There are some cleanups and code removal which needs to be done after
this CL, but I have left those out to make this CL as small as
possible. For instance resolverChanged(), which synchronously updated
the active stylesheets, has an empty implementation instead of
including a lot of removals in this CL. The code for lazy-appending
stylesheets in StyleResolver is still there, but not in use.
R=meade@chromium.org
BUG=567021
Committed: https://crrev.com/9fb5b60edfb769134733009f9447bad3eaf347b0
Review-Url: https://codereview.chromium.org/2557533005
Cr-Original-Commit-Position: refs/heads/master@{#438148}
Cr-Commit-Position: refs/heads/master@{#439092}
diff --git a/third_party/WebKit/LayoutTests/animations/add-keyframes-in-shadow-recalc.html b/third_party/WebKit/LayoutTests/animations/add-keyframes-in-shadow-recalc.html
index ef481a3..14637774 100644
--- a/third_party/WebKit/LayoutTests/animations/add-keyframes-in-shadow-recalc.html
+++ b/third_party/WebKit/LayoutTests/animations/add-keyframes-in-shadow-recalc.html
@@ -21,10 +21,7 @@
to { color: orange }
}`));
root.appendChild(sheet);
- // TODO(rune@opera.com): This count should be 1 when async stylesheet
- // update with RuleSet invalidations land. Currently we always do a
- // subtree recalc for stylesheet mutations in shadow trees.
- assert_equals(internals.updateStyleAndReturnAffectedElementCount(), 5,
+ assert_equals(internals.updateStyleAndReturnAffectedElementCount(), 1,
"Recalc for shadow tree, including host and inserted style element.");
}, "Check that adding @keyframes does not cause a style recalc of the host element when no animations are running.");
</script>
diff --git a/third_party/WebKit/LayoutTests/fast/css/modify-stylesheet-minimal-recalc-style-expected.txt b/third_party/WebKit/LayoutTests/fast/css/modify-stylesheet-minimal-recalc-style-expected.txt
index 7479a4b..3901898c 100644
--- a/third_party/WebKit/LayoutTests/fast/css/modify-stylesheet-minimal-recalc-style-expected.txt
+++ b/third_party/WebKit/LayoutTests/fast/css/modify-stylesheet-minimal-recalc-style-expected.txt
@@ -2,11 +2,11 @@
PASS internals.updateStyleAndReturnAffectedElementCount() is 6
PASS internals.updateStyleAndReturnAffectedElementCount() is 6
PASS internals.updateStyleAndReturnAffectedElementCount() is 6
-PASS internals.updateStyleAndReturnAffectedElementCount() is 43
+PASS internals.updateStyleAndReturnAffectedElementCount() is 6
PASS getComputedStyle(document.querySelector('.foo')).color is "rgb(0, 0, 0)"
PASS getComputedStyle(document.querySelector('.baz')).color is "rgb(255, 0, 0)"
PASS getComputedStyle(document.querySelector('.bar')).color is "rgb(0, 0, 0)"
-PASS internals.updateStyleAndReturnAffectedElementCount() is 59
+PASS internals.updateStyleAndReturnAffectedElementCount() is 6
PASS getComputedStyle(document.querySelector('.foo')).color is "rgb(255, 0, 0)"
PASS getComputedStyle(document.querySelector('.baz')).color is "rgb(255, 0, 0)"
PASS getComputedStyle(document.querySelector('.bar')).color is "rgb(0, 0, 0)"
diff --git a/third_party/WebKit/LayoutTests/fast/css/modify-stylesheet-minimal-recalc-style.html b/third_party/WebKit/LayoutTests/fast/css/modify-stylesheet-minimal-recalc-style.html
index 40814c5..f8b755fb 100644
--- a/third_party/WebKit/LayoutTests/fast/css/modify-stylesheet-minimal-recalc-style.html
+++ b/third_party/WebKit/LayoutTests/fast/css/modify-stylesheet-minimal-recalc-style.html
@@ -56,8 +56,7 @@
// Test deleteRule
forceRecalc();
sheet.sheet.deleteRule(0); // Deletes .bar rule.
- // FIXME: Ideally we'd do StyleInvalidationAnalysis here and only recalc 3 bar's, 3 baz's + documentElement
- shouldBe("internals.updateStyleAndReturnAffectedElementCount()", "43");
+ shouldBe("internals.updateStyleAndReturnAffectedElementCount()", "6");
shouldBe("getComputedStyle(document.querySelector('.foo')).color", '"rgb(0, 0, 0)"');
shouldBe("getComputedStyle(document.querySelector('.baz')).color", '"rgb(255, 0, 0)"');
@@ -66,8 +65,7 @@
// Test insertRule
forceRecalc();
sheet.sheet.insertRule(".foo { color: red; }", 0);
- // FIXME: Ideally we'd do StyleInvalidationAnalysis here and only recalc 3 foo's, 3 baz's + documentElement
- shouldBe("internals.updateStyleAndReturnAffectedElementCount()", "59");
+ shouldBe("internals.updateStyleAndReturnAffectedElementCount()", "6");
shouldBe("getComputedStyle(document.querySelector('.foo')).color", '"rgb(255, 0, 0)"');
shouldBe("getComputedStyle(document.querySelector('.baz')).color", '"rgb(255, 0, 0)"');
diff --git a/third_party/WebKit/Source/core/BUILD.gn b/third_party/WebKit/Source/core/BUILD.gn
index f94c378..a89dafa 100644
--- a/third_party/WebKit/Source/core/BUILD.gn
+++ b/third_party/WebKit/Source/core/BUILD.gn
@@ -1087,7 +1087,6 @@
"dom/StyleEngineTest.cpp",
"dom/SuspendableObjectTest.cpp",
"dom/TextTest.cpp",
- "dom/TreeScopeStyleSheetCollectionTest.cpp",
"dom/TreeScopeTest.cpp",
"dom/URLSearchParamsTest.cpp",
"dom/custom/CustomElementDefinitionTest.cpp",
diff --git a/third_party/WebKit/Source/core/css/FontFaceSet.cpp b/third_party/WebKit/Source/core/css/FontFaceSet.cpp
index c9c97e5..0be1e5f 100644
--- a/third_party/WebKit/Source/core/css/FontFaceSet.cpp
+++ b/third_party/WebKit/Source/core/css/FontFaceSet.cpp
@@ -310,9 +310,9 @@
const HeapListHashSet<Member<FontFace>>& FontFaceSet::cssConnectedFontFaceList()
const {
- Document* d = document();
- d->ensureStyleResolver(); // Flush pending style changes.
- return d->styleEngine()
+ Document* document = this->document();
+ document->updateActiveStyle();
+ return document->styleEngine()
.fontSelector()
->fontFaceCache()
->cssConnectedFontFaces();
@@ -467,6 +467,7 @@
style->font().update(style->font().getFontSelector());
+ document()->updateActiveStyle();
document()->ensureStyleResolver().computeFont(style.get(), *parsedStyle);
font = style->font();
diff --git a/third_party/WebKit/Source/core/css/StyleSheetContents.cpp b/third_party/WebKit/Source/core/css/StyleSheetContents.cpp
index 2efb448..42715a55 100644
--- a/third_party/WebKit/Source/core/css/StyleSheetContents.cpp
+++ b/third_party/WebKit/Source/core/css/StyleSheetContents.cpp
@@ -617,10 +617,14 @@
return *m_ruleSet.get();
}
-static void clearResolvers(HeapHashSet<WeakMember<CSSStyleSheet>>& clients) {
+static void setNeedsActiveStyleUpdateForClients(
+ HeapHashSet<WeakMember<CSSStyleSheet>>& clients) {
for (const auto& sheet : clients) {
- if (Document* document = sheet->ownerDocument())
- document->styleEngine().clearResolver();
+ Document* document = sheet->ownerDocument();
+ Node* node = sheet->ownerNode();
+ if (!document || !node || !node->isConnected())
+ continue;
+ document->styleEngine().setNeedsActiveStyleUpdate(node->treeScope());
}
}
@@ -628,18 +632,12 @@
if (StyleSheetContents* parentSheet = parentStyleSheet())
parentSheet->clearRuleSet();
- // Don't want to clear the StyleResolver if the RuleSet hasn't been created
- // since we only clear the StyleResolver so that it's members are properly
- // updated in ScopedStyleResolver::addRulesFromSheet.
if (!m_ruleSet)
return;
- // Clearing the ruleSet means we need to recreate the styleResolver data
- // structures. See the StyleResolver calls in
- // ScopedStyleResolver::addRulesFromSheet.
- clearResolvers(m_loadingClients);
- clearResolvers(m_completedClients);
m_ruleSet.clear();
+ setNeedsActiveStyleUpdateForClients(m_loadingClients);
+ setNeedsActiveStyleUpdateForClients(m_completedClients);
}
static void removeFontFaceRules(HeapHashSet<WeakMember<CSSStyleSheet>>& clients,
diff --git a/third_party/WebKit/Source/core/css/resolver/StyleResolver.cpp b/third_party/WebKit/Source/core/css/resolver/StyleResolver.cpp
index 663da08f..e53a77ce 100644
--- a/third_party/WebKit/Source/core/css/resolver/StyleResolver.cpp
+++ b/third_party/WebKit/Source/core/css/resolver/StyleResolver.cpp
@@ -1635,6 +1635,7 @@
}
void StyleResolver::notifyResizeForViewportUnits() {
+ document().styleEngine().updateActiveStyle();
m_matchedPropertiesCache.clearViewportDependent();
}
diff --git a/third_party/WebKit/Source/core/dom/Document.cpp b/third_party/WebKit/Source/core/dom/Document.cpp
index a8551c08..ada10d8 100644
--- a/third_party/WebKit/Source/core/dom/Document.cpp
+++ b/third_party/WebKit/Source/core/dom/Document.cpp
@@ -570,8 +570,11 @@
}
void Document::mediaQueryAffectingValueChanged() {
- m_evaluateMediaQueriesOnStyleRecalc = true;
styleEngine().mediaQueryAffectingValueChanged();
+ if (needsLayoutTreeUpdate())
+ m_evaluateMediaQueriesOnStyleRecalc = true;
+ else
+ evaluateMediaQueryList();
InspectorInstrumentation::mediaQueryResultChanged(this);
}
@@ -2227,8 +2230,9 @@
if (bodyElement && !bodyElement->layoutObject() &&
m_pendingSheetLayout == NoLayoutWithPendingSheets) {
m_pendingSheetLayout = DidLayoutWithPendingSheets;
- styleEngine().resolverChanged(FullStyleUpdate);
- } else if (m_hasNodesWithPlaceholderStyle) {
+ styleEngine().markAllTreeScopesDirty();
+ }
+ if (m_hasNodesWithPlaceholderStyle) {
// If new nodes have been added or style recalc has been done with style
// sheets still pending, some nodes may not have had their real style
// calculated yet. Normally this gets cleaned when style sheets arrive
diff --git a/third_party/WebKit/Source/core/dom/DocumentStyleSheetCollection.cpp b/third_party/WebKit/Source/core/dom/DocumentStyleSheetCollection.cpp
index fa84e9e..1bd57326 100644
--- a/third_party/WebKit/Source/core/dom/DocumentStyleSheetCollection.cpp
+++ b/third_party/WebKit/Source/core/dom/DocumentStyleSheetCollection.cpp
@@ -45,7 +45,6 @@
}
void DocumentStyleSheetCollection::collectStyleSheetsFromCandidates(
- StyleEngine& engine,
DocumentStyleSheetCollector& collector) {
for (Node* n : m_styleSheetCandidateNodes) {
StyleSheetCandidate candidate(*n);
@@ -70,64 +69,37 @@
continue;
collector.appendSheetForList(sheet);
- if (candidate.canBeActivated(engine.preferredStylesheetSetName()))
- collector.appendActiveStyleSheet(toCSSStyleSheet(sheet));
+ if (!candidate.canBeActivated(
+ document().styleEngine().preferredStylesheetSetName()))
+ continue;
+
+ CSSStyleSheet* cssSheet = toCSSStyleSheet(sheet);
+ collector.appendActiveStyleSheet(std::make_pair(
+ cssSheet, document().styleEngine().ruleSetForSheet(*cssSheet)));
}
}
void DocumentStyleSheetCollection::collectStyleSheets(
- StyleEngine& engine,
DocumentStyleSheetCollector& collector) {
- DCHECK_EQ(&document().styleEngine(), &engine);
- collector.appendActiveStyleSheets(engine.injectedAuthorStyleSheets());
- collectStyleSheetsFromCandidates(engine, collector);
- if (engine.inspectorStyleSheet())
- collector.appendActiveStyleSheet(engine.inspectorStyleSheet());
+ for (auto& sheet : document().styleEngine().injectedAuthorStyleSheets()) {
+ collector.appendActiveStyleSheet(std::make_pair(
+ sheet, document().styleEngine().ruleSetForSheet(*sheet)));
+ }
+ collectStyleSheetsFromCandidates(collector);
+ if (CSSStyleSheet* inspectorSheet =
+ document().styleEngine().inspectorStyleSheet()) {
+ collector.appendActiveStyleSheet(std::make_pair(
+ inspectorSheet,
+ document().styleEngine().ruleSetForSheet(*inspectorSheet)));
+ }
}
-void DocumentStyleSheetCollection::updateActiveStyleSheets(
- StyleEngine& engine,
- StyleResolverUpdateMode updateMode) {
+void DocumentStyleSheetCollection::updateActiveStyleSheets() {
// StyleSheetCollection is GarbageCollected<>, allocate it on the heap.
StyleSheetCollection* collection = StyleSheetCollection::create();
ActiveDocumentStyleSheetCollector collector(*collection);
- collectStyleSheets(engine, collector);
-
- StyleSheetChange change;
- analyzeStyleSheetChange(updateMode, collection->activeAuthorStyleSheets(),
- change);
-
- if (change.styleResolverUpdateType == Reconstruct) {
- engine.clearMasterResolver();
- // TODO(rune@opera.com): The following depends on whether StyleRuleFontFace
- // was modified or not. We should only remove modified/removed @font-face
- // rules, or @font-face rules from removed stylesheets. We currently avoid
- // clearing the font cache when we have had an analyzed update and no
- // @font-face rules were removed, in which case requiresFullStyleRecalc will
- // be false.
- if (change.requiresFullStyleRecalc)
- engine.clearFontCache();
- } else if (StyleResolver* styleResolver = engine.resolver()) {
- if (change.styleResolverUpdateType != Additive) {
- DCHECK_EQ(change.styleResolverUpdateType, Reset);
- engine.resetAuthorStyle(treeScope());
- engine.removeFontFaceRules(change.fontFaceRulesToRemove);
- styleResolver->removePendingAuthorStyleSheets(m_activeAuthorStyleSheets);
- styleResolver->lazyAppendAuthorStyleSheets(
- 0, collection->activeAuthorStyleSheets());
- } else {
- styleResolver->lazyAppendAuthorStyleSheets(
- m_activeAuthorStyleSheets.size(),
- collection->activeAuthorStyleSheets());
- }
- }
- if (change.requiresFullStyleRecalc)
- document().setNeedsStyleRecalc(
- SubtreeStyleChange, StyleChangeReasonForTracing::create(
- StyleChangeReason::ActiveStylesheetsUpdate));
-
- collection->swap(*this);
- collection->dispose();
+ collectStyleSheets(collector);
+ applyActiveStyleSheetChanges(*collection);
}
void DocumentStyleSheetCollection::collectViewportRules(
diff --git a/third_party/WebKit/Source/core/dom/DocumentStyleSheetCollection.h b/third_party/WebKit/Source/core/dom/DocumentStyleSheetCollection.h
index 5219819..7d4fe51 100644
--- a/third_party/WebKit/Source/core/dom/DocumentStyleSheetCollection.h
+++ b/third_party/WebKit/Source/core/dom/DocumentStyleSheetCollection.h
@@ -36,7 +36,6 @@
namespace blink {
class DocumentStyleSheetCollector;
-class StyleEngine;
class TreeScope;
class ViewportStyleResolver;
@@ -49,8 +48,8 @@
return new DocumentStyleSheetCollection(treeScope);
}
- void updateActiveStyleSheets(StyleEngine&, StyleResolverUpdateMode);
- void collectStyleSheets(StyleEngine&, DocumentStyleSheetCollector&);
+ void updateActiveStyleSheets();
+ void collectStyleSheets(DocumentStyleSheetCollector&);
void collectViewportRules(ViewportStyleResolver&);
DEFINE_INLINE_VIRTUAL_TRACE() {
@@ -60,8 +59,7 @@
private:
explicit DocumentStyleSheetCollection(TreeScope&);
- void collectStyleSheetsFromCandidates(StyleEngine&,
- DocumentStyleSheetCollector&);
+ void collectStyleSheetsFromCandidates(DocumentStyleSheetCollector&);
};
} // namespace blink
diff --git a/third_party/WebKit/Source/core/dom/DocumentStyleSheetCollector.cpp b/third_party/WebKit/Source/core/dom/DocumentStyleSheetCollector.cpp
index 7a032525..17abbb9d 100644
--- a/third_party/WebKit/Source/core/dom/DocumentStyleSheetCollector.cpp
+++ b/third_party/WebKit/Source/core/dom/DocumentStyleSheetCollector.cpp
@@ -30,6 +30,7 @@
#include "core/css/CSSStyleSheet.h"
#include "core/css/StyleSheet.h"
+#include "core/dom/Document.h"
#include "core/dom/DocumentStyleSheetCollection.h"
namespace blink {
@@ -44,13 +45,8 @@
DocumentStyleSheetCollector::~DocumentStyleSheetCollector() {}
-void DocumentStyleSheetCollector::appendActiveStyleSheets(
- const HeapVector<TraceWrapperMember<CSSStyleSheet>>& sheets) {
- DCHECK(m_collection);
- m_collection->appendActiveStyleSheets(sheets);
-}
-
-void DocumentStyleSheetCollector::appendActiveStyleSheet(CSSStyleSheet* sheet) {
+void DocumentStyleSheetCollector::appendActiveStyleSheet(
+ const ActiveStyleSheet& sheet) {
DCHECK(m_collection);
m_collection->appendActiveStyleSheet(sheet);
}
diff --git a/third_party/WebKit/Source/core/dom/DocumentStyleSheetCollector.h b/third_party/WebKit/Source/core/dom/DocumentStyleSheetCollector.h
index a97fb6a..baff8778 100644
--- a/third_party/WebKit/Source/core/dom/DocumentStyleSheetCollector.h
+++ b/third_party/WebKit/Source/core/dom/DocumentStyleSheetCollector.h
@@ -28,13 +28,13 @@
#define DocumentStyleSheetCollector_h
#include "bindings/core/v8/TraceWrapperMember.h"
+#include "core/css/ActiveStyleSheets.h"
#include "platform/heap/Handle.h"
#include "wtf/HashSet.h"
#include "wtf/Vector.h"
namespace blink {
-class CSSStyleSheet;
class Document;
class StyleSheet;
class StyleSheetCollection;
@@ -53,9 +53,7 @@
HeapHashSet<Member<Document>>*);
~DocumentStyleSheetCollector();
- void appendActiveStyleSheets(
- const HeapVector<TraceWrapperMember<CSSStyleSheet>>&);
- void appendActiveStyleSheet(CSSStyleSheet*);
+ void appendActiveStyleSheet(const ActiveStyleSheet&);
void appendSheetForList(StyleSheet*);
bool hasVisited(Document* document) const {
diff --git a/third_party/WebKit/Source/core/dom/ShadowTreeStyleSheetCollection.cpp b/third_party/WebKit/Source/core/dom/ShadowTreeStyleSheetCollection.cpp
index 29dad5f..7f735dd 100644
--- a/third_party/WebKit/Source/core/dom/ShadowTreeStyleSheetCollection.cpp
+++ b/third_party/WebKit/Source/core/dom/ShadowTreeStyleSheetCollection.cpp
@@ -47,7 +47,6 @@
: TreeScopeStyleSheetCollection(shadowRoot) {}
void ShadowTreeStyleSheetCollection::collectStyleSheets(
- StyleEngine& engine,
StyleSheetCollection& collection) {
for (Node* n : m_styleSheetCandidateNodes) {
StyleSheetCandidate candidate(*n);
@@ -58,46 +57,19 @@
continue;
collection.appendSheetForList(sheet);
- if (candidate.canBeActivated(nullAtom))
- collection.appendActiveStyleSheet(toCSSStyleSheet(sheet));
+ if (candidate.canBeActivated(nullAtom)) {
+ CSSStyleSheet* cssSheet = toCSSStyleSheet(sheet);
+ collection.appendActiveStyleSheet(std::make_pair(
+ cssSheet, document().styleEngine().ruleSetForSheet(*cssSheet)));
+ }
}
}
-void ShadowTreeStyleSheetCollection::updateActiveStyleSheets(
- StyleEngine& engine,
- StyleResolverUpdateMode updateMode) {
+void ShadowTreeStyleSheetCollection::updateActiveStyleSheets() {
// StyleSheetCollection is GarbageCollected<>, allocate it on the heap.
StyleSheetCollection* collection = StyleSheetCollection::create();
- collectStyleSheets(engine, *collection);
-
- StyleSheetChange change;
- analyzeStyleSheetChange(updateMode, collection->activeAuthorStyleSheets(),
- change);
-
- if (StyleResolver* styleResolver = engine.resolver()) {
- if (change.styleResolverUpdateType != Additive) {
- // We should not destroy StyleResolver when we find any stylesheet update
- // in a shadow tree. In this case, we will reset rulesets created from
- // style elements in the shadow tree.
- engine.resetAuthorStyle(treeScope());
- styleResolver->removePendingAuthorStyleSheets(m_activeAuthorStyleSheets);
- styleResolver->lazyAppendAuthorStyleSheets(
- 0, collection->activeAuthorStyleSheets());
- } else {
- styleResolver->lazyAppendAuthorStyleSheets(
- m_activeAuthorStyleSheets.size(),
- collection->activeAuthorStyleSheets());
- }
- }
- if (change.requiresFullStyleRecalc)
- toShadowRoot(treeScope().rootNode())
- .host()
- .setNeedsStyleRecalc(SubtreeStyleChange,
- StyleChangeReasonForTracing::create(
- StyleChangeReason::ActiveStylesheetsUpdate));
-
- collection->swap(*this);
- collection->dispose();
+ collectStyleSheets(*collection);
+ applyActiveStyleSheetChanges(*collection);
}
} // namespace blink
diff --git a/third_party/WebKit/Source/core/dom/ShadowTreeStyleSheetCollection.h b/third_party/WebKit/Source/core/dom/ShadowTreeStyleSheetCollection.h
index db5f32c1..d86803b 100644
--- a/third_party/WebKit/Source/core/dom/ShadowTreeStyleSheetCollection.h
+++ b/third_party/WebKit/Source/core/dom/ShadowTreeStyleSheetCollection.h
@@ -36,7 +36,6 @@
class ShadowRoot;
class StyleSheetCollection;
-class StyleEngine;
class ShadowTreeStyleSheetCollection final
: public TreeScopeStyleSheetCollection {
@@ -44,9 +43,7 @@
public:
explicit ShadowTreeStyleSheetCollection(ShadowRoot&);
-
- void updateActiveStyleSheets(StyleEngine&, StyleResolverUpdateMode);
-
+ void updateActiveStyleSheets();
bool isShadowTreeStyleSheetCollection() const final { return true; }
DEFINE_INLINE_VIRTUAL_TRACE() {
@@ -54,7 +51,7 @@
}
private:
- void collectStyleSheets(StyleEngine&, StyleSheetCollection&);
+ void collectStyleSheets(StyleSheetCollection&);
};
DEFINE_TYPE_CASTS(ShadowTreeStyleSheetCollection,
diff --git a/third_party/WebKit/Source/core/dom/StyleEngine.cpp b/third_party/WebKit/Source/core/dom/StyleEngine.cpp
index a84beae..82e9aae 100644
--- a/third_party/WebKit/Source/core/dom/StyleEngine.cpp
+++ b/third_party/WebKit/Source/core/dom/StyleEngine.cpp
@@ -151,7 +151,10 @@
StyleSheetContents::create(CSSParserContext(*m_document, nullptr));
m_inspectorStyleSheet = CSSStyleSheet::create(contents, *m_document);
markDocumentDirty();
- resolverChanged(AnalyzedStyleUpdate);
+ // TODO(rune@opera.com): Making the active stylesheets up-to-date here is
+ // required by some inspector tests, at least. I theory this should not be
+ // necessary. Need to investigate to figure out if/why.
+ updateActiveStyle();
return *m_inspectorStyleSheet;
}
@@ -267,13 +270,14 @@
ShadowTreeStyleSheetCollection* collection =
toShadowTreeStyleSheetCollection(styleSheetCollectionFor(*treeScope));
DCHECK(collection);
- collection->clearMediaQueryRuleSetStyleSheets();
+ if (collection->mediaQueryAffectingValueChanged())
+ setNeedsActiveStyleUpdate(*treeScope);
}
}
void StyleEngine::mediaQueryAffectingValueChanged() {
- resolverChanged(FullStyleUpdate);
- documentStyleSheetCollection().clearMediaQueryRuleSetStyleSheets();
+ if (documentStyleSheetCollection().mediaQueryAffectingValueChanged())
+ setNeedsActiveStyleUpdate(document());
mediaQueryAffectingValueChanged(m_activeTreeScopes);
if (m_resolver)
m_resolver->updateMediaType();
@@ -285,19 +289,18 @@
HeapVector<Member<StyleSheet>> sheetsForList;
ImportedDocumentStyleSheetCollector subcollector(parentCollector,
sheetsForList);
- documentStyleSheetCollection().collectStyleSheets(*this, subcollector);
+ documentStyleSheetCollection().collectStyleSheets(subcollector);
documentStyleSheetCollection().swapSheetsForSheetList(sheetsForList);
}
void StyleEngine::updateActiveStyleSheetsInShadow(
- StyleResolverUpdateMode updateMode,
TreeScope* treeScope,
UnorderedTreeScopeSet& treeScopesRemoved) {
DCHECK_NE(treeScope, m_document);
ShadowTreeStyleSheetCollection* collection =
toShadowTreeStyleSheetCollection(styleSheetCollectionFor(*treeScope));
DCHECK(collection);
- collection->updateActiveStyleSheets(*this, updateMode);
+ collection->updateActiveStyleSheets();
if (!collection->hasStyleSheetCandidateNodes()) {
treeScopesRemoved.add(treeScope);
// When removing TreeScope from ActiveTreeScopes,
@@ -306,29 +309,28 @@
}
}
-void StyleEngine::updateActiveStyleSheets(StyleResolverUpdateMode updateMode) {
+void StyleEngine::updateActiveStyleSheets() {
+ if (!needsActiveStyleSheetUpdate())
+ return;
+
DCHECK(isMaster());
DCHECK(!document().inStyleRecalc());
-
- if (!document().isActive())
- return;
+ DCHECK(document().isActive());
TRACE_EVENT0("blink,blink_style", "StyleEngine::updateActiveStyleSheets");
if (shouldUpdateDocumentStyleSheetCollection())
- documentStyleSheetCollection().updateActiveStyleSheets(*this, updateMode);
+ documentStyleSheetCollection().updateActiveStyleSheets();
if (shouldUpdateShadowTreeStyleSheetCollection()) {
UnorderedTreeScopeSet treeScopesRemoved;
if (m_allTreeScopesDirty) {
for (TreeScope* treeScope : m_activeTreeScopes)
- updateActiveStyleSheetsInShadow(updateMode, treeScope,
- treeScopesRemoved);
+ updateActiveStyleSheetsInShadow(treeScope, treeScopesRemoved);
} else {
for (TreeScope* treeScope : m_dirtyTreeScopes)
- updateActiveStyleSheetsInShadow(updateMode, treeScope,
- treeScopesRemoved);
+ updateActiveStyleSheetsInShadow(treeScope, treeScopesRemoved);
}
for (TreeScope* treeScope : treeScopesRemoved)
m_activeTreeScopes.remove(treeScope);
@@ -341,31 +343,31 @@
m_allTreeScopesDirty = false;
}
-void StyleEngine::updateActiveStyleSheets() {
- // TODO(rune@opera.com): collect ActiveStyleSheets here.
-}
-
void StyleEngine::updateViewport() {
if (m_viewportResolver)
m_viewportResolver->updateViewport(documentStyleSheetCollection());
}
bool StyleEngine::needsActiveStyleUpdate() const {
- return m_viewportResolver && m_viewportResolver->needsUpdate();
+ return (m_viewportResolver && m_viewportResolver->needsUpdate()) ||
+ needsActiveStyleSheetUpdate() || m_globalRuleSet.isDirty();
}
void StyleEngine::updateActiveStyle() {
+ DCHECK(document().isActive());
updateViewport();
updateActiveStyleSheets();
m_globalRuleSet.update(document());
}
-const HeapVector<Member<CSSStyleSheet>>
-StyleEngine::activeStyleSheetsForInspector() const {
+const ActiveStyleSheetVector StyleEngine::activeStyleSheetsForInspector() {
+ if (document().isActive())
+ updateActiveStyle();
+
if (m_activeTreeScopes.isEmpty())
return documentStyleSheetCollection().activeAuthorStyleSheets();
- HeapVector<Member<CSSStyleSheet>> activeStyleSheets;
+ ActiveStyleSheetVector activeStyleSheets;
activeStyleSheets.appendVector(
documentStyleSheetCollection().activeAuthorStyleSheets());
@@ -382,12 +384,6 @@
}
void StyleEngine::shadowRootRemovedFromDocument(ShadowRoot* shadowRoot) {
- if (StyleResolver* styleResolver = resolver()) {
- if (TreeScopeStyleSheetCollection* collection =
- styleSheetCollectionFor(*shadowRoot))
- styleResolver->removePendingAuthorStyleSheets(
- collection->activeAuthorStyleSheets());
- }
m_styleSheetCollectionMap.remove(shadowRoot);
m_activeTreeScopes.remove(shadowRoot);
m_dirtyTreeScopes.remove(shadowRoot);
@@ -414,28 +410,6 @@
treeScope.clearScopedStyleResolver();
}
-void StyleEngine::finishAppendAuthorStyleSheets() {
- m_globalRuleSet.markDirty();
- m_globalRuleSet.update(document());
-
- if (!document().layoutViewItem().isNull() &&
- document().layoutViewItem().style())
- document().layoutViewItem().style()->font().update(fontSelector());
-}
-
-void StyleEngine::appendActiveAuthorStyleSheets() {
- DCHECK(isMaster());
-
- m_resolver->appendAuthorStyleSheets(
- documentStyleSheetCollection().activeAuthorStyleSheets());
- for (TreeScope* treeScope : m_activeTreeScopes) {
- if (TreeScopeStyleSheetCollection* collection =
- m_styleSheetCollectionMap.get(treeScope))
- m_resolver->appendAuthorStyleSheets(
- collection->activeAuthorStyleSheets());
- }
-}
-
void StyleEngine::setRuleUsageTracker(StyleRuleUsageTracker* tracker) {
m_tracker = tracker;
@@ -455,13 +429,7 @@
void StyleEngine::createResolver() {
m_resolver = StyleResolver::create(*m_document);
-
m_resolver->setRuleUsageTracker(m_tracker);
-
- // A scoped style resolver for document will be created during
- // appendActiveAuthorStyleSheets if needed.
- appendActiveAuthorStyleSheets();
- finishAppendAuthorStyleSheets();
}
void StyleEngine::clearResolver() {
@@ -494,41 +462,12 @@
}
}
-void StyleEngine::clearMasterResolver() {
- if (Document* master = this->master())
- master->styleEngine().clearResolver();
-}
-
void StyleEngine::didDetach() {
clearResolver();
m_viewportResolver = nullptr;
m_mediaQueryEvaluator = nullptr;
}
-bool StyleEngine::shouldClearResolver() const {
- return !m_didCalculateResolver && !haveScriptBlockingStylesheetsLoaded();
-}
-
-void StyleEngine::resolverChanged(StyleResolverUpdateMode mode) {
- if (!isMaster()) {
- if (Document* master = this->master())
- master->styleEngine().resolverChanged(mode);
- return;
- }
-
- // Don't bother updating, since we haven't loaded all our style info yet
- // and haven't calculated the style selector for the first time.
- if (!document().isActive() || shouldClearResolver()) {
- clearResolver();
- return;
- }
-
- if (mode == FullStyleUpdate)
- markAllTreeScopesDirty();
- m_didCalculateResolver = true;
- updateActiveStyleSheets(mode);
-}
-
void StyleEngine::clearFontCache() {
if (m_fontSelector)
m_fontSelector->fontFaceCache()->clearCSSConnected();
diff --git a/third_party/WebKit/Source/core/dom/StyleEngine.h b/third_party/WebKit/Source/core/dom/StyleEngine.h
index 390bcd8..9cd0ab1 100644
--- a/third_party/WebKit/Source/core/dom/StyleEngine.h
+++ b/third_party/WebKit/Source/core/dom/StyleEngine.h
@@ -99,7 +99,7 @@
}
CSSStyleSheet* inspectorStyleSheet() const { return m_inspectorStyleSheet; }
- const HeapVector<Member<CSSStyleSheet>> activeStyleSheetsForInspector() const;
+ const ActiveStyleSheetVector activeStyleSheetsForInspector();
bool needsActiveStyleUpdate() const;
void setNeedsActiveStyleUpdate(TreeScope&);
@@ -121,7 +121,6 @@
RuleSet* ruleSetForSheet(CSSStyleSheet&);
void mediaQueryAffectingValueChanged();
void updateStyleSheetsInImport(DocumentStyleSheetCollector& parentCollector);
- void updateActiveStyleSheets(StyleResolverUpdateMode);
void updateActiveStyle();
void markAllTreeScopesDirty() { m_allTreeScopesDirty = true; }
@@ -183,20 +182,13 @@
StyleResolver& ensureResolver() {
updateActiveStyle();
- if (!m_resolver) {
+ if (!m_resolver)
createResolver();
- } else if (m_resolver->hasPendingAuthorStyleSheets()) {
- m_resolver->appendPendingAuthorStyleSheets();
- finishAppendAuthorStyleSheets();
- } else if (m_globalRuleSet.isDirty()) {
- m_globalRuleSet.update(document());
- }
return *m_resolver;
}
bool hasResolver() const { return m_resolver; }
void clearResolver();
- void clearMasterResolver();
StyleInvalidator& styleInvalidator() { return m_styleInvalidator; }
bool mediaQueryAffectedByViewportChange();
@@ -216,8 +208,7 @@
void updateGenericFontFamilySettings();
void didDetach();
- bool shouldClearResolver() const;
- void resolverChanged(StyleResolverUpdateMode);
+ void resolverChanged(StyleResolverUpdateMode) {}
CSSStyleSheet* createSheet(Element&,
const String& text,
@@ -298,8 +289,6 @@
}
void createResolver();
- void appendActiveAuthorStyleSheets();
- void finishAppendAuthorStyleSheets();
CSSStyleSheet* parseSheet(Element&,
const String& text,
@@ -316,7 +305,6 @@
}
void updateActiveStyleSheetsInShadow(
- StyleResolverUpdateMode,
TreeScope*,
UnorderedTreeScopeSet& treeScopesRemoved);
@@ -348,9 +336,9 @@
Member<StyleRuleUsageTracker> m_tracker;
- typedef HeapHashMap<WeakMember<TreeScope>,
- Member<ShadowTreeStyleSheetCollection>>
- StyleSheetCollectionMap;
+ using StyleSheetCollectionMap =
+ HeapHashMap<WeakMember<TreeScope>,
+ Member<ShadowTreeStyleSheetCollection>>;
StyleSheetCollectionMap m_styleSheetCollectionMap;
bool m_documentScopeDirty = true;
@@ -366,7 +354,6 @@
bool m_usesRemUnits = false;
bool m_ignorePendingStylesheets = false;
- bool m_didCalculateResolver = false;
Member<StyleResolver> m_resolver;
Member<ViewportStyleResolver> m_viewportResolver;
diff --git a/third_party/WebKit/Source/core/dom/StyleEngineTest.cpp b/third_party/WebKit/Source/core/dom/StyleEngineTest.cpp
index 0d586c7..c784df4 100644
--- a/third_party/WebKit/Source/core/dom/StyleEngineTest.cpp
+++ b/third_party/WebKit/Source/core/dom/StyleEngineTest.cpp
@@ -339,8 +339,7 @@
document().view()->updateAllLifecyclePhases();
unsigned afterCount = styleEngine().styleForElementCount();
- // TODO(rune@opera.com): Should be 1u for ruleset based invalidations.
- EXPECT_EQ(8u, afterCount - beforeCount);
+ EXPECT_EQ(1u, afterCount - beforeCount);
ASSERT_TRUE(t1->computedStyle());
EXPECT_EQ(makeRGB(0, 128, 0),
@@ -366,8 +365,7 @@
document().view()->updateAllLifecyclePhases();
unsigned afterCount = styleEngine().styleForElementCount();
- // TODO(rune@opera.com): Should be 0 for ruleset based invalidations.
- EXPECT_EQ(8u, afterCount - beforeCount);
+ EXPECT_EQ(0u, afterCount - beforeCount);
ASSERT_TRUE(t1->computedStyle());
EXPECT_EQ(makeRGB(0, 128, 0),
diff --git a/third_party/WebKit/Source/core/dom/StyleSheetCollection.cpp b/third_party/WebKit/Source/core/dom/StyleSheetCollection.cpp
index 3359f33..7a0dfe34 100644
--- a/third_party/WebKit/Source/core/dom/StyleSheetCollection.cpp
+++ b/third_party/WebKit/Source/core/dom/StyleSheetCollection.cpp
@@ -29,6 +29,7 @@
#include "core/dom/StyleSheetCollection.h"
#include "core/css/CSSStyleSheet.h"
+#include "core/css/RuleSet.h"
namespace blink {
@@ -52,20 +53,9 @@
::blink::swap(m_styleSheetsForStyleSheetList, sheets, this);
}
-void StyleSheetCollection::appendActiveStyleSheet(CSSStyleSheet* sheet) {
- m_activeAuthorStyleSheets.push_back(sheet);
-}
-
-void StyleSheetCollection::appendActiveStyleSheets(
- const HeapVector<Member<CSSStyleSheet>>& sheets) {
- m_activeAuthorStyleSheets.appendVector(sheets);
-}
-
-void StyleSheetCollection::appendActiveStyleSheets(
- const HeapVector<TraceWrapperMember<CSSStyleSheet>>& sheets) {
- for (CSSStyleSheet* sheet : sheets) {
- m_activeAuthorStyleSheets.push_back(sheet);
- }
+void StyleSheetCollection::appendActiveStyleSheet(
+ const ActiveStyleSheet& activeSheet) {
+ m_activeAuthorStyleSheets.push_back(activeSheet);
}
void StyleSheetCollection::appendSheetForList(StyleSheet* sheet) {
diff --git a/third_party/WebKit/Source/core/dom/StyleSheetCollection.h b/third_party/WebKit/Source/core/dom/StyleSheetCollection.h
index d79f04b..947009e 100644
--- a/third_party/WebKit/Source/core/dom/StyleSheetCollection.h
+++ b/third_party/WebKit/Source/core/dom/StyleSheetCollection.h
@@ -33,13 +33,13 @@
#include "bindings/core/v8/ScriptWrappable.h"
#include "bindings/core/v8/TraceWrapperMember.h"
#include "core/CoreExport.h"
+#include "core/css/ActiveStyleSheets.h"
#include "platform/heap/Handle.h"
#include "wtf/Allocator.h"
#include "wtf/Vector.h"
namespace blink {
-class CSSStyleSheet;
class StyleSheet;
class CORE_EXPORT StyleSheetCollection
@@ -53,7 +53,7 @@
static StyleSheetCollection* create() { return new StyleSheetCollection; }
- const HeapVector<Member<CSSStyleSheet>>& activeAuthorStyleSheets() const {
+ const ActiveStyleSheetVector& activeAuthorStyleSheets() const {
return m_activeAuthorStyleSheets;
}
const HeapVector<TraceWrapperMember<StyleSheet>>&
@@ -63,10 +63,7 @@
void swap(StyleSheetCollection&);
void swapSheetsForSheetList(HeapVector<Member<StyleSheet>>&);
- void appendActiveStyleSheet(CSSStyleSheet*);
- void appendActiveStyleSheets(const HeapVector<Member<CSSStyleSheet>>&);
- void appendActiveStyleSheets(
- const HeapVector<TraceWrapperMember<CSSStyleSheet>>&);
+ void appendActiveStyleSheet(const ActiveStyleSheet&);
void appendSheetForList(StyleSheet*);
DECLARE_VIRTUAL_TRACE();
@@ -78,7 +75,7 @@
StyleSheetCollection();
HeapVector<TraceWrapperMember<StyleSheet>> m_styleSheetsForStyleSheetList;
- HeapVector<Member<CSSStyleSheet>> m_activeAuthorStyleSheets;
+ ActiveStyleSheetVector m_activeAuthorStyleSheets;
};
} // namespace blink
diff --git a/third_party/WebKit/Source/core/dom/TreeScopeStyleSheetCollection.cpp b/third_party/WebKit/Source/core/dom/TreeScopeStyleSheetCollection.cpp
index a643306..9188247 100644
--- a/third_party/WebKit/Source/core/dom/TreeScopeStyleSheetCollection.cpp
+++ b/third_party/WebKit/Source/core/dom/TreeScopeStyleSheetCollection.cpp
@@ -28,10 +28,10 @@
#include "core/dom/TreeScopeStyleSheetCollection.h"
+#include "core/css/ActiveStyleSheets.h"
#include "core/css/CSSStyleSheet.h"
#include "core/css/StyleRuleImport.h"
#include "core/css/StyleSheetContents.h"
-#include "core/css/invalidation/StyleSheetInvalidationAnalysis.h"
#include "core/css/resolver/StyleResolver.h"
#include "core/dom/Element.h"
#include "core/dom/StyleEngine.h"
@@ -42,139 +42,31 @@
TreeScopeStyleSheetCollection::TreeScopeStyleSheetCollection(
TreeScope& treeScope)
- : m_treeScope(treeScope), m_hadActiveLoadingStylesheet(false) {}
+ : m_treeScope(treeScope) {}
void TreeScopeStyleSheetCollection::addStyleSheetCandidateNode(Node& node) {
- if (!node.isConnected())
- return;
-
- m_styleSheetCandidateNodes.add(&node);
+ if (node.isConnected())
+ m_styleSheetCandidateNodes.add(&node);
}
-TreeScopeStyleSheetCollection::StyleResolverUpdateType
-TreeScopeStyleSheetCollection::compareStyleSheets(
- const HeapVector<Member<CSSStyleSheet>>& oldStyleSheets,
- const HeapVector<Member<CSSStyleSheet>>& newStylesheets,
- HeapVector<Member<StyleSheetContents>>& addedSheets) {
- unsigned newStyleSheetCount = newStylesheets.size();
- unsigned oldStyleSheetCount = oldStyleSheets.size();
- DCHECK_GE(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;
-}
-
-bool TreeScopeStyleSheetCollection::activeLoadingStyleSheetLoaded(
- const HeapVector<Member<CSSStyleSheet>>& newStyleSheets) {
- // 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;
- for (const auto& sheet : newStyleSheets) {
- if (sheet->isLoading())
- hasActiveLoadingStylesheet = true;
- }
- if (m_hadActiveLoadingStylesheet && !hasActiveLoadingStylesheet) {
- m_hadActiveLoadingStylesheet = false;
- return true;
- }
- m_hadActiveLoadingStylesheet = hasActiveLoadingStylesheet;
- return false;
-}
-
-static bool findFontFaceRulesFromStyleSheetContents(
- const HeapVector<Member<StyleSheetContents>>& sheets,
- HeapVector<Member<const StyleRuleFontFace>>& fontFaceRules) {
- bool hasFontFaceRule = false;
-
- for (const auto& sheet : sheets) {
- DCHECK(sheet);
- if (sheet->hasFontFaceRule()) {
- // FIXME: We don't need this for styles in shadow tree.
- sheet->findFontFaceRules(fontFaceRules);
- hasFontFaceRule = true;
- }
- }
- return hasFontFaceRule;
-}
-
-void TreeScopeStyleSheetCollection::analyzeStyleSheetChange(
- StyleResolverUpdateMode updateMode,
- const HeapVector<Member<CSSStyleSheet>>& newActiveAuthorStyleSheets,
- StyleSheetChange& change) {
- if (activeLoadingStyleSheetLoaded(newActiveAuthorStyleSheets))
- return;
-
- if (updateMode != AnalyzedStyleUpdate)
- return;
-
- // Find out which stylesheets are new.
- HeapVector<Member<StyleSheetContents>> addedSheets;
- if (m_activeAuthorStyleSheets.size() <= newActiveAuthorStyleSheets.size()) {
- change.styleResolverUpdateType = compareStyleSheets(
- m_activeAuthorStyleSheets, newActiveAuthorStyleSheets, addedSheets);
- } else {
- StyleResolverUpdateType updateType = compareStyleSheets(
- newActiveAuthorStyleSheets, 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().body() || document().hasNodesWithPlaceholderStyle())
- return;
- StyleSheetInvalidationAnalysis invalidationAnalysis(*m_treeScope,
- addedSheets);
- if (invalidationAnalysis.dirtiesAllStyle())
- return;
- invalidationAnalysis.invalidateStyle();
- change.requiresFullStyleRecalc = false;
- return;
-}
-
-void TreeScopeStyleSheetCollection::clearMediaQueryRuleSetStyleSheets() {
- for (const auto& sheet : m_activeAuthorStyleSheets) {
- StyleSheetContents* contents = sheet->contents();
+bool TreeScopeStyleSheetCollection::mediaQueryAffectingValueChanged() {
+ bool needsActiveStyleUpdate = false;
+ for (const auto& activeSheet : m_activeAuthorStyleSheets) {
+ if (activeSheet.first->mediaQueries())
+ needsActiveStyleUpdate = true;
+ StyleSheetContents* contents = activeSheet.first->contents();
if (contents->hasMediaQueries())
contents->clearRuleSet();
}
+ return needsActiveStyleUpdate;
+}
+
+void TreeScopeStyleSheetCollection::applyActiveStyleSheetChanges(
+ StyleSheetCollection& newCollection) {
+ document().styleEngine().applyRuleSetChanges(
+ treeScope(), activeAuthorStyleSheets(),
+ newCollection.activeAuthorStyleSheets());
+ newCollection.swap(*this);
}
DEFINE_TRACE(TreeScopeStyleSheetCollection) {
diff --git a/third_party/WebKit/Source/core/dom/TreeScopeStyleSheetCollection.h b/third_party/WebKit/Source/core/dom/TreeScopeStyleSheetCollection.h
index 40fdf9e..1d05a18 100644
--- a/third_party/WebKit/Source/core/dom/TreeScopeStyleSheetCollection.h
+++ b/third_party/WebKit/Source/core/dom/TreeScopeStyleSheetCollection.h
@@ -31,20 +31,14 @@
#define TreeScopeStyleSheetCollection_h
#include "core/CoreExport.h"
-#include "core/dom/Document.h"
#include "core/dom/DocumentOrderedList.h"
#include "core/dom/StyleSheetCollection.h"
#include "core/dom/TreeScope.h"
-#include "wtf/HashMap.h"
-#include "wtf/ListHashSet.h"
-#include "wtf/Vector.h"
-#include "wtf/text/WTFString.h"
namespace blink {
+class Document;
class Node;
-class StyleSheetContents;
-class StyleRuleFontFace;
class CORE_EXPORT TreeScopeStyleSheetCollection : public StyleSheetCollection {
public:
@@ -56,7 +50,7 @@
return !m_styleSheetCandidateNodes.isEmpty();
}
- void clearMediaQueryRuleSetStyleSheets();
+ bool mediaQueryAffectingValueChanged();
virtual bool isShadowTreeStyleSheetCollection() const { return false; }
@@ -68,39 +62,13 @@
Document& document() const { return treeScope().document(); }
TreeScope& treeScope() const { return *m_treeScope; }
- enum StyleResolverUpdateType { Reconstruct, Reset, Additive };
+ void applyActiveStyleSheetChanges(StyleSheetCollection&);
- class StyleSheetChange {
- STACK_ALLOCATED();
-
- public:
- StyleResolverUpdateType styleResolverUpdateType;
- bool requiresFullStyleRecalc;
- HeapVector<Member<const StyleRuleFontFace>> fontFaceRulesToRemove;
-
- StyleSheetChange()
- : styleResolverUpdateType(Reconstruct), requiresFullStyleRecalc(true) {}
- };
-
- void analyzeStyleSheetChange(StyleResolverUpdateMode,
- const HeapVector<Member<CSSStyleSheet>>&,
- StyleSheetChange&);
+ Member<TreeScope> m_treeScope;
+ DocumentOrderedList m_styleSheetCandidateNodes;
private:
- static StyleResolverUpdateType compareStyleSheets(
- const HeapVector<Member<CSSStyleSheet>>& oldStyleSheets,
- const HeapVector<Member<CSSStyleSheet>>& newStylesheets,
- HeapVector<Member<StyleSheetContents>>& addedSheets);
- bool activeLoadingStyleSheetLoaded(
- const HeapVector<Member<CSSStyleSheet>>& newStyleSheets);
-
friend class TreeScopeStyleSheetCollectionTest;
-
- protected:
- Member<TreeScope> m_treeScope;
- bool m_hadActiveLoadingStylesheet;
-
- DocumentOrderedList m_styleSheetCandidateNodes;
};
} // namespace blink
diff --git a/third_party/WebKit/Source/core/dom/TreeScopeStyleSheetCollectionTest.cpp b/third_party/WebKit/Source/core/dom/TreeScopeStyleSheetCollectionTest.cpp
deleted file mode 100644
index 4d1ba76..0000000
--- a/third_party/WebKit/Source/core/dom/TreeScopeStyleSheetCollectionTest.cpp
+++ /dev/null
@@ -1,152 +0,0 @@
-// Copyright 2015 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "core/dom/TreeScopeStyleSheetCollection.h"
-
-#include "core/css/CSSStyleSheet.h"
-#include "core/css/StyleSheetContents.h"
-#include "core/css/parser/CSSParserMode.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-namespace blink {
-
-class TreeScopeStyleSheetCollectionTest : public testing::Test {
- protected:
- using SheetVector = HeapVector<Member<CSSStyleSheet>>;
- using ContentsVector = HeapVector<Member<StyleSheetContents>>;
-
- enum UpdateType {
- Reconstruct = TreeScopeStyleSheetCollection::Reconstruct,
- Reset = TreeScopeStyleSheetCollection::Reset,
- Additive = TreeScopeStyleSheetCollection::Additive
- };
-
- static CSSStyleSheet* createSheet() {
- return CSSStyleSheet::create(StyleSheetContents::create(
- CSSParserContext(HTMLStandardMode, nullptr)));
- }
-
- static void compareStyleSheets(const SheetVector& oldStyleSheets,
- const SheetVector& newStyleSheets,
- const ContentsVector& expAddedSheets,
- UpdateType testUpdateType) {
- ContentsVector addedSheets;
- UpdateType updateType = static_cast<UpdateType>(
- TreeScopeStyleSheetCollection::compareStyleSheets(
- oldStyleSheets, newStyleSheets, addedSheets));
- EXPECT_EQ(testUpdateType, updateType);
- EXPECT_EQ(expAddedSheets.size(), addedSheets.size());
- if (expAddedSheets.size() == addedSheets.size()) {
- for (unsigned i = 0; i < addedSheets.size(); i++)
- EXPECT_EQ(expAddedSheets.at(i), addedSheets.at(i));
- }
- }
-};
-
-TEST_F(TreeScopeStyleSheetCollectionTest, CompareStyleSheetsAppend) {
- CSSStyleSheet* sheet1 = createSheet();
- CSSStyleSheet* sheet2 = createSheet();
-
- ContentsVector added;
- SheetVector previous;
- SheetVector current;
-
- previous.append(sheet1);
-
- current.append(sheet1);
- current.append(sheet2);
-
- added.append(sheet2->contents());
-
- compareStyleSheets(previous, current, added, Additive);
-}
-
-TEST_F(TreeScopeStyleSheetCollectionTest, CompareStyleSheetsPrepend) {
- CSSStyleSheet* sheet1 = createSheet();
- CSSStyleSheet* sheet2 = createSheet();
-
- ContentsVector added;
- SheetVector previous;
- SheetVector current;
-
- previous.append(sheet2);
-
- current.append(sheet1);
- current.append(sheet2);
-
- added.append(sheet1->contents());
-
- compareStyleSheets(previous, current, added, Reconstruct);
-}
-
-TEST_F(TreeScopeStyleSheetCollectionTest, CompareStyleSheetsInsert) {
- CSSStyleSheet* sheet1 = createSheet();
- CSSStyleSheet* sheet2 = createSheet();
- CSSStyleSheet* sheet3 = createSheet();
-
- ContentsVector added;
- SheetVector previous;
- SheetVector current;
-
- previous.append(sheet1);
- previous.append(sheet3);
-
- current.append(sheet1);
- current.append(sheet2);
- current.append(sheet3);
-
- added.append(sheet2->contents());
-
- compareStyleSheets(previous, current, added, Reconstruct);
-}
-
-TEST_F(TreeScopeStyleSheetCollectionTest, CompareStyleSheetsRemove) {
- CSSStyleSheet* sheet1 = createSheet();
- CSSStyleSheet* sheet2 = createSheet();
- CSSStyleSheet* sheet3 = createSheet();
-
- ContentsVector added;
- SheetVector previous;
- SheetVector current;
-
- previous.append(sheet1);
- previous.append(sheet2);
- previous.append(sheet3);
-
- current.append(sheet1);
- current.append(sheet3);
-
- added.append(sheet2->contents());
-
- // This is really the same as Insert.
- // TreeScopeStyleSheetCollection::compareStyleSheets will assert if you pass
- // an array that is longer as the first parameter.
- compareStyleSheets(current, previous, added, Reconstruct);
-}
-
-TEST_F(TreeScopeStyleSheetCollectionTest, CompareStyleSheetsInsertRemove) {
- CSSStyleSheet* sheet1 = createSheet();
- CSSStyleSheet* sheet2 = createSheet();
- CSSStyleSheet* sheet3 = createSheet();
-
- ContentsVector added;
- SheetVector previous;
- SheetVector current;
-
- previous.append(sheet1);
- previous.append(sheet2);
-
- current.append(sheet2);
- current.append(sheet3);
-
- // TODO(rune@opera.com): This is clearly wrong. We add sheet3 and remove
- // sheet1 and compareStyleSheets returns sheet2 and sheet3 as added
- // (crbug/475858).
- added.append(sheet2->contents());
- added.append(sheet3->contents());
-
- compareStyleSheets(previous, current, added, Reconstruct);
-}
-
-} // namespace blink
diff --git a/third_party/WebKit/Source/core/frame/FrameView.cpp b/third_party/WebKit/Source/core/frame/FrameView.cpp
index 9938c0c..0a62802 100644
--- a/third_party/WebKit/Source/core/frame/FrameView.cpp
+++ b/third_party/WebKit/Source/core/frame/FrameView.cpp
@@ -30,7 +30,6 @@
#include "core/MediaTypeNames.h"
#include "core/animation/DocumentAnimations.h"
#include "core/css/FontFaceSet.h"
-#include "core/css/resolver/StyleResolver.h"
#include "core/dom/AXObjectCache.h"
#include "core/dom/DOMNodeIds.h"
#include "core/dom/ElementVisibilityObserver.h"
@@ -38,6 +37,7 @@
#include "core/dom/IntersectionObserverCallback.h"
#include "core/dom/IntersectionObserverController.h"
#include "core/dom/IntersectionObserverInit.h"
+#include "core/dom/StyleChangeReason.h"
#include "core/dom/TaskRunnerHelper.h"
#include "core/editing/EditingUtilities.h"
#include "core/editing/FrameSelection.h"
@@ -1476,6 +1476,10 @@
setMediaType(m_mediaTypeWhenNotPrinting);
m_mediaTypeWhenNotPrinting = nullAtom;
}
+
+ m_frame->document()->setNeedsStyleRecalc(
+ SubtreeStyleChange,
+ StyleChangeReasonForTracing::create(StyleChangeReason::StyleSheetChange));
}
bool FrameView::contentsInCompositedLayer() const {
diff --git a/third_party/WebKit/Source/core/frame/LocalFrame.cpp b/third_party/WebKit/Source/core/frame/LocalFrame.cpp
index 5c4e213..3d7b6ae 100644
--- a/third_party/WebKit/Source/core/frame/LocalFrame.cpp
+++ b/third_party/WebKit/Source/core/frame/LocalFrame.cpp
@@ -704,6 +704,9 @@
void LocalFrame::deviceScaleFactorChanged() {
document()->mediaQueryAffectingValueChanged();
+ document()->setNeedsStyleRecalc(
+ SubtreeStyleChange,
+ StyleChangeReasonForTracing::create(StyleChangeReason::Zoom));
for (Frame* child = tree().firstChild(); child;
child = child->tree().nextSibling()) {
if (child->isLocalFrame())
diff --git a/third_party/WebKit/Source/core/inspector/InspectorCSSAgent.cpp b/third_party/WebKit/Source/core/inspector/InspectorCSSAgent.cpp
index 223fad62..52d7c2de 100644
--- a/third_party/WebKit/Source/core/inspector/InspectorCSSAgent.cpp
+++ b/third_party/WebKit/Source/core/inspector/InspectorCSSAgent.cpp
@@ -1784,12 +1784,9 @@
void InspectorCSSAgent::collectAllDocumentStyleSheets(
Document* document,
HeapVector<Member<CSSStyleSheet>>& result) {
- const HeapVector<Member<CSSStyleSheet>> activeStyleSheets =
- document->styleEngine().activeStyleSheetsForInspector();
- for (const auto& style : activeStyleSheets) {
- CSSStyleSheet* styleSheet = style.get();
- InspectorCSSAgent::collectStyleSheets(styleSheet, result);
- }
+ for (const auto& style :
+ document->styleEngine().activeStyleSheetsForInspector())
+ InspectorCSSAgent::collectStyleSheets(style.first, result);
}
// static