Commit 97c98f16 authored by rune's avatar rune Committed by Commit bot

Use master StyleEngine to evaluate MQ in html imports.

The StyleEngine for html import documents does not have a Frame which
means size media queries will always evaluate to true. We incorrectly
replaced a passed-in master document StyleEngine with the StyleEngine
from the DocumentStyleSheetCollection in https://crrev.com/90d4ea3d
That was wrong for evaluating media queries.

R=meade@chromium.org
BUG=677963

Review-Url: https://codereview.chromium.org/2618803002
Cr-Commit-Position: refs/heads/master@{#441899}
parent afe1dc47
<!DOCTYPE html>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<link rel="import" href="data:text/html,<style>@media (max-width: 0px){div{background:red}}</style>">
<div></div>
<script>
test(() => {
assert_equals(getComputedStyle(document.querySelector("div")).backgroundColor, "rgba(0, 0, 0, 0)");
}, "(max-width: 0px) media query in import document should not evaluate to true.");
</script>
...@@ -45,6 +45,7 @@ DocumentStyleSheetCollection::DocumentStyleSheetCollection(TreeScope& treeScope) ...@@ -45,6 +45,7 @@ DocumentStyleSheetCollection::DocumentStyleSheetCollection(TreeScope& treeScope)
} }
void DocumentStyleSheetCollection::collectStyleSheetsFromCandidates( void DocumentStyleSheetCollection::collectStyleSheetsFromCandidates(
StyleEngine& masterEngine,
DocumentStyleSheetCollector& collector) { DocumentStyleSheetCollector& collector) {
for (Node* n : m_styleSheetCandidateNodes) { for (Node* n : m_styleSheetCandidateNodes) {
StyleSheetCandidate candidate(*n); StyleSheetCandidate candidate(*n);
...@@ -57,7 +58,9 @@ void DocumentStyleSheetCollection::collectStyleSheetsFromCandidates( ...@@ -57,7 +58,9 @@ void DocumentStyleSheetCollection::collectStyleSheetsFromCandidates(
if (collector.hasVisited(document)) if (collector.hasVisited(document))
continue; continue;
collector.willVisit(document); collector.willVisit(document);
document->styleEngine().updateStyleSheetsInImport(collector);
document->styleEngine().updateStyleSheetsInImport(masterEngine,
collector);
continue; continue;
} }
...@@ -74,18 +77,19 @@ void DocumentStyleSheetCollection::collectStyleSheetsFromCandidates( ...@@ -74,18 +77,19 @@ void DocumentStyleSheetCollection::collectStyleSheetsFromCandidates(
continue; continue;
CSSStyleSheet* cssSheet = toCSSStyleSheet(sheet); CSSStyleSheet* cssSheet = toCSSStyleSheet(sheet);
collector.appendActiveStyleSheet(std::make_pair( collector.appendActiveStyleSheet(
cssSheet, document().styleEngine().ruleSetForSheet(*cssSheet))); std::make_pair(cssSheet, masterEngine.ruleSetForSheet(*cssSheet)));
} }
} }
void DocumentStyleSheetCollection::collectStyleSheets( void DocumentStyleSheetCollection::collectStyleSheets(
StyleEngine& masterEngine,
DocumentStyleSheetCollector& collector) { DocumentStyleSheetCollector& collector) {
for (auto& sheet : document().styleEngine().injectedAuthorStyleSheets()) { for (auto& sheet : document().styleEngine().injectedAuthorStyleSheets()) {
collector.appendActiveStyleSheet(std::make_pair( collector.appendActiveStyleSheet(std::make_pair(
sheet, document().styleEngine().ruleSetForSheet(*sheet))); sheet, document().styleEngine().ruleSetForSheet(*sheet)));
} }
collectStyleSheetsFromCandidates(collector); collectStyleSheetsFromCandidates(masterEngine, collector);
if (CSSStyleSheet* inspectorSheet = if (CSSStyleSheet* inspectorSheet =
document().styleEngine().inspectorStyleSheet()) { document().styleEngine().inspectorStyleSheet()) {
collector.appendActiveStyleSheet(std::make_pair( collector.appendActiveStyleSheet(std::make_pair(
...@@ -94,11 +98,12 @@ void DocumentStyleSheetCollection::collectStyleSheets( ...@@ -94,11 +98,12 @@ void DocumentStyleSheetCollection::collectStyleSheets(
} }
} }
void DocumentStyleSheetCollection::updateActiveStyleSheets() { void DocumentStyleSheetCollection::updateActiveStyleSheets(
StyleEngine& masterEngine) {
// StyleSheetCollection is GarbageCollected<>, allocate it on the heap. // StyleSheetCollection is GarbageCollected<>, allocate it on the heap.
StyleSheetCollection* collection = StyleSheetCollection::create(); StyleSheetCollection* collection = StyleSheetCollection::create();
ActiveDocumentStyleSheetCollector collector(*collection); ActiveDocumentStyleSheetCollector collector(*collection);
collectStyleSheets(collector); collectStyleSheets(masterEngine, collector);
applyActiveStyleSheetChanges(*collection); applyActiveStyleSheetChanges(*collection);
} }
......
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
namespace blink { namespace blink {
class DocumentStyleSheetCollector; class DocumentStyleSheetCollector;
class StyleEngine;
class TreeScope; class TreeScope;
class ViewportStyleResolver; class ViewportStyleResolver;
...@@ -48,8 +49,9 @@ class DocumentStyleSheetCollection final ...@@ -48,8 +49,9 @@ class DocumentStyleSheetCollection final
return new DocumentStyleSheetCollection(treeScope); return new DocumentStyleSheetCollection(treeScope);
} }
void updateActiveStyleSheets(); void updateActiveStyleSheets(StyleEngine& masterEngine);
void collectStyleSheets(DocumentStyleSheetCollector&); void collectStyleSheets(StyleEngine& masterEngine,
DocumentStyleSheetCollector&);
void collectViewportRules(ViewportStyleResolver&); void collectViewportRules(ViewportStyleResolver&);
DEFINE_INLINE_VIRTUAL_TRACE() { DEFINE_INLINE_VIRTUAL_TRACE() {
...@@ -59,7 +61,8 @@ class DocumentStyleSheetCollection final ...@@ -59,7 +61,8 @@ class DocumentStyleSheetCollection final
private: private:
explicit DocumentStyleSheetCollection(TreeScope&); explicit DocumentStyleSheetCollection(TreeScope&);
void collectStyleSheetsFromCandidates(DocumentStyleSheetCollector&); void collectStyleSheetsFromCandidates(StyleEngine& masterEngine,
DocumentStyleSheetCollector&);
}; };
} // namespace blink } // namespace blink
......
...@@ -47,6 +47,7 @@ ShadowTreeStyleSheetCollection::ShadowTreeStyleSheetCollection( ...@@ -47,6 +47,7 @@ ShadowTreeStyleSheetCollection::ShadowTreeStyleSheetCollection(
: TreeScopeStyleSheetCollection(shadowRoot) {} : TreeScopeStyleSheetCollection(shadowRoot) {}
void ShadowTreeStyleSheetCollection::collectStyleSheets( void ShadowTreeStyleSheetCollection::collectStyleSheets(
StyleEngine& masterEngine,
StyleSheetCollection& collection) { StyleSheetCollection& collection) {
for (Node* n : m_styleSheetCandidateNodes) { for (Node* n : m_styleSheetCandidateNodes) {
StyleSheetCandidate candidate(*n); StyleSheetCandidate candidate(*n);
...@@ -59,16 +60,17 @@ void ShadowTreeStyleSheetCollection::collectStyleSheets( ...@@ -59,16 +60,17 @@ void ShadowTreeStyleSheetCollection::collectStyleSheets(
collection.appendSheetForList(sheet); collection.appendSheetForList(sheet);
if (candidate.canBeActivated(nullAtom)) { if (candidate.canBeActivated(nullAtom)) {
CSSStyleSheet* cssSheet = toCSSStyleSheet(sheet); CSSStyleSheet* cssSheet = toCSSStyleSheet(sheet);
collection.appendActiveStyleSheet(std::make_pair( collection.appendActiveStyleSheet(
cssSheet, document().styleEngine().ruleSetForSheet(*cssSheet))); std::make_pair(cssSheet, masterEngine.ruleSetForSheet(*cssSheet)));
} }
} }
} }
void ShadowTreeStyleSheetCollection::updateActiveStyleSheets() { void ShadowTreeStyleSheetCollection::updateActiveStyleSheets(
StyleEngine& masterEngine) {
// StyleSheetCollection is GarbageCollected<>, allocate it on the heap. // StyleSheetCollection is GarbageCollected<>, allocate it on the heap.
StyleSheetCollection* collection = StyleSheetCollection::create(); StyleSheetCollection* collection = StyleSheetCollection::create();
collectStyleSheets(*collection); collectStyleSheets(masterEngine, *collection);
applyActiveStyleSheetChanges(*collection); applyActiveStyleSheetChanges(*collection);
} }
......
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
namespace blink { namespace blink {
class ShadowRoot; class ShadowRoot;
class StyleEngine;
class StyleSheetCollection; class StyleSheetCollection;
class ShadowTreeStyleSheetCollection final class ShadowTreeStyleSheetCollection final
...@@ -43,7 +44,7 @@ class ShadowTreeStyleSheetCollection final ...@@ -43,7 +44,7 @@ class ShadowTreeStyleSheetCollection final
public: public:
explicit ShadowTreeStyleSheetCollection(ShadowRoot&); explicit ShadowTreeStyleSheetCollection(ShadowRoot&);
void updateActiveStyleSheets(); void updateActiveStyleSheets(StyleEngine& masterEngine);
bool isShadowTreeStyleSheetCollection() const final { return true; } bool isShadowTreeStyleSheetCollection() const final { return true; }
DEFINE_INLINE_VIRTUAL_TRACE() { DEFINE_INLINE_VIRTUAL_TRACE() {
...@@ -51,7 +52,7 @@ class ShadowTreeStyleSheetCollection final ...@@ -51,7 +52,7 @@ class ShadowTreeStyleSheetCollection final
} }
private: private:
void collectStyleSheets(StyleSheetCollection&); void collectStyleSheets(StyleEngine& masterEngine, StyleSheetCollection&);
}; };
DEFINE_TYPE_CASTS(ShadowTreeStyleSheetCollection, DEFINE_TYPE_CASTS(ShadowTreeStyleSheetCollection,
......
...@@ -278,12 +278,13 @@ void StyleEngine::mediaQueryAffectingValueChanged() { ...@@ -278,12 +278,13 @@ void StyleEngine::mediaQueryAffectingValueChanged() {
} }
void StyleEngine::updateStyleSheetsInImport( void StyleEngine::updateStyleSheetsInImport(
StyleEngine& masterEngine,
DocumentStyleSheetCollector& parentCollector) { DocumentStyleSheetCollector& parentCollector) {
DCHECK(!isMaster()); DCHECK(!isMaster());
HeapVector<Member<StyleSheet>> sheetsForList; HeapVector<Member<StyleSheet>> sheetsForList;
ImportedDocumentStyleSheetCollector subcollector(parentCollector, ImportedDocumentStyleSheetCollector subcollector(parentCollector,
sheetsForList); sheetsForList);
documentStyleSheetCollection().collectStyleSheets(subcollector); documentStyleSheetCollection().collectStyleSheets(masterEngine, subcollector);
documentStyleSheetCollection().swapSheetsForSheetList(sheetsForList); documentStyleSheetCollection().swapSheetsForSheetList(sheetsForList);
} }
...@@ -294,7 +295,7 @@ void StyleEngine::updateActiveStyleSheetsInShadow( ...@@ -294,7 +295,7 @@ void StyleEngine::updateActiveStyleSheetsInShadow(
ShadowTreeStyleSheetCollection* collection = ShadowTreeStyleSheetCollection* collection =
toShadowTreeStyleSheetCollection(styleSheetCollectionFor(*treeScope)); toShadowTreeStyleSheetCollection(styleSheetCollectionFor(*treeScope));
DCHECK(collection); DCHECK(collection);
collection->updateActiveStyleSheets(); collection->updateActiveStyleSheets(*this);
if (!collection->hasStyleSheetCandidateNodes()) { if (!collection->hasStyleSheetCandidateNodes()) {
treeScopesRemoved.add(treeScope); treeScopesRemoved.add(treeScope);
// When removing TreeScope from ActiveTreeScopes, // When removing TreeScope from ActiveTreeScopes,
...@@ -314,7 +315,7 @@ void StyleEngine::updateActiveStyleSheets() { ...@@ -314,7 +315,7 @@ void StyleEngine::updateActiveStyleSheets() {
TRACE_EVENT0("blink,blink_style", "StyleEngine::updateActiveStyleSheets"); TRACE_EVENT0("blink,blink_style", "StyleEngine::updateActiveStyleSheets");
if (shouldUpdateDocumentStyleSheetCollection()) if (shouldUpdateDocumentStyleSheetCollection())
documentStyleSheetCollection().updateActiveStyleSheets(); documentStyleSheetCollection().updateActiveStyleSheets(*this);
if (shouldUpdateShadowTreeStyleSheetCollection()) { if (shouldUpdateShadowTreeStyleSheetCollection()) {
UnorderedTreeScopeSet treeScopesRemoved; UnorderedTreeScopeSet treeScopesRemoved;
......
...@@ -120,7 +120,8 @@ class CORE_EXPORT StyleEngine final ...@@ -120,7 +120,8 @@ class CORE_EXPORT StyleEngine final
RuleSet* ruleSetForSheet(CSSStyleSheet&); RuleSet* ruleSetForSheet(CSSStyleSheet&);
void mediaQueryAffectingValueChanged(); void mediaQueryAffectingValueChanged();
void updateStyleSheetsInImport(DocumentStyleSheetCollector& parentCollector); void updateStyleSheetsInImport(StyleEngine& masterEngine,
DocumentStyleSheetCollector& parentCollector);
void updateActiveStyle(); void updateActiveStyle();
void markAllTreeScopesDirty() { m_allTreeScopesDirty = true; } void markAllTreeScopesDirty() { m_allTreeScopesDirty = true; }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment