Index: Source/core/css/resolver/StyleResolver.cpp |
diff --git a/Source/core/css/resolver/StyleResolver.cpp b/Source/core/css/resolver/StyleResolver.cpp |
index 57f33842d5b36cd49c3ec1a293008548b1376e85..b9f3a54aba58637c15ec50a070720997ba60aeed 100644 |
--- a/Source/core/css/resolver/StyleResolver.cpp |
+++ b/Source/core/css/resolver/StyleResolver.cpp |
@@ -187,13 +187,18 @@ void StyleResolver::removePendingAuthorStyleSheets(const WillBeHeapVector<RefPtr |
void StyleResolver::appendCSSStyleSheet(CSSStyleSheet& cssSheet) |
{ |
ASSERT(!cssSheet.disabled()); |
- if (cssSheet.mediaQueries() && !m_medium->eval(cssSheet.mediaQueries(), &m_viewportDependentMediaQueryResults)) |
- return; |
+ ASSERT(cssSheet.ownerDocument()); |
+ ASSERT(cssSheet.ownerNode()); |
+ ASSERT(isHTMLStyleElement(cssSheet.ownerNode()) || isSVGStyleElement(cssSheet.ownerNode()) || cssSheet.ownerNode()->treeScope() == cssSheet.ownerDocument()); |
- TreeScope* treeScope = ScopedStyleResolver::treeScopeFor(document(), &cssSheet); |
- if (!treeScope) |
+ if (cssSheet.mediaQueries() && !m_medium->eval(cssSheet.mediaQueries(), &m_viewportDependentMediaQueryResults)) |
return; |
+ TreeScope* treeScope = &cssSheet.ownerNode()->treeScope(); |
+ // Sheets in the document scope of HTML imports apply to the main document |
+ // (m_document), so we override it for all document scoped sheets. |
+ if (treeScope->rootNode().isDocumentNode()) |
+ treeScope = m_document; |
treeScope->ensureScopedStyleResolver().appendCSSStyleSheet(cssSheet, *m_medium); |
} |