Commit 5084a6ab authored by morrita@chromium.org's avatar morrita@chromium.org

[import] The first <link rel=import> should win in the cascading order computation.

Before this change, stylesheets in imports are ordered based on
<link>s that "own" these imports. The ownership however is an
implementation detail and shouldn't be observable.

With this change, it takes only the tree order of <link>s into account.
The ownership no longer plays any role.

BUG=346878
TEST=import-style-tree-order-dedup.html
R=esprehn@chromium.org, dglazkov@chromium.org

Review URL: https://codereview.chromium.org/179873020

git-svn-id: svn://svn.chromium.org/blink/trunk@168351 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 376a8159
PASS colorOf(target1) is 'rgb(0, 128, 0)'
PASS colorOf(target2) is 'rgb(255, 0, 0)'
PASS colorOf(target3) is 'rgb(255, 0, 0)'
PASS colorOf(target1) is 'rgb(0, 128, 0)'
PASS colorOf(target2) is 'rgb(0, 0, 255)'
PASS colorOf(target3) is 'rgb(255, 0, 0)'
PASS colorOf(target1) is 'rgb(0, 128, 0)'
PASS colorOf(target2) is 'rgb(0, 0, 255)'
PASS colorOf(target3) is 'rgb(255, 0, 0)'
PASS successfullyParsed is true
TEST COMPLETE
Hello! Hello! Hello!
<!DOCTYPE html>
<body>
<script src="../../../resources/js-test.js"></script>
<link id="owningLink" rel="import" href="resources/style-target-blue.html">
<style id="styleRed">
.target1, .target2, .target3 {
color: red;
}
</style>
<link id="sharedLink" rel="import" href="resources/style-target-blue.html">
<style id="styleGreen">
.target1 {
color: green;
}
</style>
<div id="placeholder"></div>
<span id="target1" class="target1">Hello!</span>
<span id="target2" class="target2">Hello!</span>
<span id="target3" class="target3">Hello!</span>
<script>
function colorOf(element)
{
return window.getComputedStyle(element).color;
}
// owninigLink, styleRed, styleGreen
shouldBe("colorOf(target1)", "'rgb(0, 128, 0)'");
shouldBe("colorOf(target2)", "'rgb(255, 0, 0)'");
shouldBe("colorOf(target3)", "'rgb(255, 0, 0)'");
var owningLinkElement = document.getElementById("owningLink");
document.body.removeChild(owningLinkElement);
// styleRed, sharedLink, styleGreen
shouldBe("colorOf(target1)", "'rgb(0, 128, 0)'");
shouldBe("colorOf(target2)", "'rgb(0, 0, 255)'");
shouldBe("colorOf(target3)", "'rgb(255, 0, 0)'");
document.body.insertBefore(owningLinkElement, placeholder);
// styleRed, sharedLink, styleGreen - owningLinkElement shouldn't affect others
shouldBe("colorOf(target1)", "'rgb(0, 128, 0)'");
shouldBe("colorOf(target2)", "'rgb(0, 0, 255)'");
shouldBe("colorOf(target3)", "'rgb(255, 0, 0)'");
</script>
</body>
<!DOCTYPE html>
<html>
<style>
.target1, .target2 {
color: blue;
}
</style>
</html>
......@@ -81,6 +81,9 @@ void DocumentStyleSheetCollection::collectStyleSheetsFromCandidates(StyleEngine*
Document* document = candidate.importedDocument();
if (!document)
continue;
if (collector.hasVisited(document))
continue;
collector.willVisit(document);
document->styleEngine()->updateStyleSheetsInImport(collector);
continue;
}
......
......@@ -33,9 +33,10 @@
namespace WebCore {
DocumentStyleSheetCollector::DocumentStyleSheetCollector(Vector<RefPtr<StyleSheet> >& sheetsForList, Vector<RefPtr<CSSStyleSheet> >& activeList)
DocumentStyleSheetCollector::DocumentStyleSheetCollector(Vector<RefPtr<StyleSheet> >& sheetsForList, Vector<RefPtr<CSSStyleSheet> >& activeList, HashSet<Document*>& visitedDocuments)
: m_styleSheetsForStyleSheetList(sheetsForList)
, m_activeAuthorStyleSheets(activeList)
, m_visitedDocuments(visitedDocuments)
{
}
......@@ -59,12 +60,12 @@ void DocumentStyleSheetCollector::appendSheetForList(StyleSheet* sheet)
}
ActiveDocumentStyleSheetCollector::ActiveDocumentStyleSheetCollector(StyleSheetCollection& collection)
: DocumentStyleSheetCollector(collection.m_styleSheetsForStyleSheetList, collection.m_activeAuthorStyleSheets)
: DocumentStyleSheetCollector(collection.m_styleSheetsForStyleSheetList, collection.m_activeAuthorStyleSheets, m_visitedDocuments)
{
}
ImportedDocumentStyleSheetCollector::ImportedDocumentStyleSheetCollector(DocumentStyleSheetCollector& collector, Vector<RefPtr<StyleSheet> >& sheetForList)
: DocumentStyleSheetCollector(sheetForList, collector.m_activeAuthorStyleSheets)
: DocumentStyleSheetCollector(sheetForList, collector.m_activeAuthorStyleSheets, collector.m_visitedDocuments)
{
}
......
......@@ -27,12 +27,14 @@
#ifndef DocumentStyleSheetCollector_h
#define DocumentStyleSheetCollector_h
#include "wtf/HashSet.h"
#include "wtf/RefPtr.h"
#include "wtf/Vector.h"
namespace WebCore {
class CSSStyleSheet;
class Document;
class StyleSheet;
class StyleSheetCollection;
......@@ -40,21 +42,27 @@ class DocumentStyleSheetCollector {
public:
friend class ImportedDocumentStyleSheetCollector;
DocumentStyleSheetCollector(Vector<RefPtr<StyleSheet> >& sheetsForList, Vector<RefPtr<CSSStyleSheet> >& activeList);
DocumentStyleSheetCollector(Vector<RefPtr<StyleSheet> >& sheetsForList, Vector<RefPtr<CSSStyleSheet> >& activeList, HashSet<Document*>&);
~DocumentStyleSheetCollector();
void appendActiveStyleSheets(const Vector<RefPtr<CSSStyleSheet> >&);
void appendActiveStyleSheet(CSSStyleSheet*);
void appendSheetForList(StyleSheet*);
bool hasVisited(Document* document) const { return m_visitedDocuments.contains(document); }
void willVisit(Document* document) { m_visitedDocuments.add(document); }
private:
Vector<RefPtr<StyleSheet> >& m_styleSheetsForStyleSheetList;
Vector<RefPtr<CSSStyleSheet> >& m_activeAuthorStyleSheets;
HashSet<Document*>& m_visitedDocuments;
};
class ActiveDocumentStyleSheetCollector FINAL : public DocumentStyleSheetCollector {
public:
ActiveDocumentStyleSheetCollector(StyleSheetCollection&);
private:
HashSet<Document*> m_visitedDocuments;
};
class ImportedDocumentStyleSheetCollector FINAL : public DocumentStyleSheetCollector {
......
......@@ -58,12 +58,7 @@ bool StyleSheetCandidate::isImport() const
Document* StyleSheetCandidate::importedDocument() const
{
ASSERT(isImport());
// The stylesheet update traversal shouldn't go into shared import
// to prevent it from stepping into cycle.
HTMLLinkElement& element = toHTMLLinkElement(m_node);
if (!element.importOwnsLoader())
return 0;
return element.import();
return toHTMLLinkElement(m_node).import();
}
bool StyleSheetCandidate::isAlternate() const
......
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