Diff
Modified: trunk/LayoutTests/ChangeLog (87866 => 87867)
--- trunk/LayoutTests/ChangeLog 2011-06-02 00:46:41 UTC (rev 87866)
+++ trunk/LayoutTests/ChangeLog 2011-06-02 00:53:01 UTC (rev 87867)
@@ -1,3 +1,18 @@
+2011-06-01 Julien Chaffraix <[email protected]>
+
+ Reviewed by Simon Fraser.
+
+ CSSStyleSheet#insertRule doesn't work well with imported stylesheets
+ https://bugs.webkit.org/show_bug.cgi?id=56981
+
+ Test that a combination of insertRule and @import works properly.
+
+ * fast/css/import-and-insert-rule-no-update-expected.txt: Added.
+ * fast/css/import-and-insert-rule-no-update.html: Added.
+ * fast/css/resources/red.css: Added.
+ (div):
+ * fast/css/resources/redimport.css: Added.
+
2011-06-01 Abhishek Arya <[email protected]>
Reviewed by Alexey Proskuryakov.
Added: trunk/LayoutTests/fast/css/import-and-insert-rule-no-update-expected.txt (0 => 87867)
--- trunk/LayoutTests/fast/css/import-and-insert-rule-no-update-expected.txt (rev 0)
+++ trunk/LayoutTests/fast/css/import-and-insert-rule-no-update-expected.txt 2011-06-02 00:53:01 UTC (rev 87867)
@@ -0,0 +1,3 @@
+Test for bug 56981: CSSStyleSheet#insertRule doesn't work well with imported stylesheets
+You should see one PASS below.
+PASS
Added: trunk/LayoutTests/fast/css/import-and-insert-rule-no-update.html (0 => 87867)
--- trunk/LayoutTests/fast/css/import-and-insert-rule-no-update.html (rev 0)
+++ trunk/LayoutTests/fast/css/import-and-insert-rule-no-update.html 2011-06-02 00:53:01 UTC (rev 87867)
@@ -0,0 +1,42 @@
+<!DOCTYPE html>
+<html><head>
+<link rel="stylesheet" href=""
+</head><body>
+<div>Test for bug <a href="" CSSStyleSheet#insertRule doesn't work well with imported stylesheets</div>
+<div>You should see one PASS below.</div>
+<div id="testArea"></div>
+<script>
+if (window.layoutTestController) {
+ layoutTestController.dumpAsText();
+ layoutTestController.waitUntilDone();
+}
+
+var remainingTests = 20;
+
+function test() {
+ try {
+ var testArea = document.getElementById("testArea");
+ if (getComputedStyle(testArea).backgroundColor == "rgb(0, 128, 0)") {
+ testArea.innerHTML = 'PASS';
+ remainingTests = 0;
+ } else {
+ if (--remainingTests)
+ testArea.innerHTML = 'FAIL, backgroundColor was ' + getComputedStyle(testArea).backgroundColor;
+ }
+ } catch (e) {
+ testArea.innerHTML = 'FAIL, exception raised (' + e.message + ')';
+ remainingTests = 0;
+ }
+ if (!remainingTests)
+ window.setTimeout(test, 25);
+ if (window.layoutTestController)
+ layoutTestController.notifyDone();
+}
+
+window._onload_ = function() {
+ document.styleSheets[0].insertRule('@import "green.css";', 1);
+ // We need to wait some time to let the stylesheet load before testing.
+ window.setTimeout(test, 25);
+};
+</script>
+</body></html>
Added: trunk/LayoutTests/fast/css/resources/red.css (0 => 87867)
--- trunk/LayoutTests/fast/css/resources/red.css (rev 0)
+++ trunk/LayoutTests/fast/css/resources/red.css 2011-06-02 00:53:01 UTC (rev 87867)
@@ -0,0 +1 @@
+div { background-color: red }
Added: trunk/LayoutTests/fast/css/resources/redimport.css (0 => 87867)
--- trunk/LayoutTests/fast/css/resources/redimport.css (rev 0)
+++ trunk/LayoutTests/fast/css/resources/redimport.css 2011-06-02 00:53:01 UTC (rev 87867)
@@ -0,0 +1 @@
+@import url(red.css);
Modified: trunk/Source/WebCore/ChangeLog (87866 => 87867)
--- trunk/Source/WebCore/ChangeLog 2011-06-02 00:46:41 UTC (rev 87866)
+++ trunk/Source/WebCore/ChangeLog 2011-06-02 00:53:01 UTC (rev 87867)
@@ -1,3 +1,49 @@
+2011-06-01 Julien Chaffraix <[email protected]>
+
+ Reviewed by Simon Fraser.
+
+ CSSStyleSheet#insertRule doesn't work well with imported stylesheets
+ https://bugs.webkit.org/show_bug.cgi?id=56981
+
+ Test: fast/css/import-and-insert-rule-no-update.html
+
+ The bug arises from the fact that <link> element did not know about a programmatically
+ loading sheet (using insertRule and @import) and would thus never call removePendingSheet.
+ This is needed to make sure our style selector contains an up-to-date list of stylesheets.
+
+ The gist of the patch adds a way for style sheet owner element to know if we are
+ programmatically loading a style sheet. This is needed as <link> keeps the information
+ about that last loaded stylesheet.
+
+ * css/CSSImportRule.cpp:
+ (WebCore::CSSImportRule::insertedIntoParent): Call startLoadingDynamicSheet
+ on our parent style sheet instead of directly adding a pending style sheet.
+
+ * css/CSSStyleSheet.cpp:
+ (WebCore::CSSStyleSheet::startLoadingDynamicSheet): Call startLoadingDynamicSheet
+ on our owner element if we have one.
+
+ * css/CSSStyleSheet.h:
+ * dom/Node.h:
+ (WebCore::Node::startLoadingDynamicSheet): Added common implementation of
+ startLoadingDynamicSheet, which should never be called.
+
+ * dom/StyleElement.cpp:
+ (WebCore::StyleElement::startLoadingDynamicSheet):
+ * dom/StyleElement.h:
+ Common implementation of startLoadingDynamicSheet for style elements.
+
+ * html/HTMLLinkElement.cpp:
+ (WebCore::HTMLLinkElement::startLoadingDynamicSheet):
+ * html/HTMLLinkElement.h:
+ Use the HTMLLinkElement plumbing to make sure we call addRemovePendingSheet.
+
+ * html/HTMLStyleElement.h:
+ (WebCore::HTMLStyleElement::startLoadingDynamicSheet):
+ * svg/SVGStyleElement.h:
+ (WebCore::SVGStyleElement::startLoadingDynamicSheet):
+ Forward the call to StyleElement.
+
2011-06-01 Levi Weintraub <[email protected]>
Reviewed by Eric Seidel.
Modified: trunk/Source/WebCore/css/CSSImportRule.cpp (87866 => 87867)
--- trunk/Source/WebCore/css/CSSImportRule.cpp 2011-06-02 00:46:41 UTC (rev 87866)
+++ trunk/Source/WebCore/css/CSSImportRule.cpp 2011-06-02 00:53:01 UTC (rev 87867)
@@ -144,7 +144,7 @@
// removed from the pending sheet count, so let the doc know
// the sheet being imported is pending.
if (parentSheet && parentSheet->loadCompleted() && root == parentSheet)
- parentSheet->document()->addPendingSheet();
+ parentSheet->startLoadingDynamicSheet();
m_loading = true;
m_cachedSheet->addClient(this);
}
Modified: trunk/Source/WebCore/css/CSSStyleSheet.cpp (87866 => 87867)
--- trunk/Source/WebCore/css/CSSStyleSheet.cpp 2011-06-02 00:46:41 UTC (rev 87866)
+++ trunk/Source/WebCore/css/CSSStyleSheet.cpp 2011-06-02 00:53:01 UTC (rev 87867)
@@ -230,6 +230,12 @@
m_loadCompleted = ownerNode() ? ownerNode()->sheetLoaded() : true;
}
+void CSSStyleSheet::startLoadingDynamicSheet()
+{
+ if (Node* owner = ownerNode())
+ owner->startLoadingDynamicSheet();
+}
+
Document* CSSStyleSheet::document()
{
StyleBase* styleObject = this;
Modified: trunk/Source/WebCore/css/CSSStyleSheet.h (87866 => 87867)
--- trunk/Source/WebCore/css/CSSStyleSheet.h 2011-06-02 00:46:41 UTC (rev 87866)
+++ trunk/Source/WebCore/css/CSSStyleSheet.h 2011-06-02 00:53:01 UTC (rev 87867)
@@ -86,6 +86,7 @@
virtual bool isLoading();
virtual void checkLoaded();
+ void startLoadingDynamicSheet();
Document* document();
Modified: trunk/Source/WebCore/dom/Node.h (87866 => 87867)
--- trunk/Source/WebCore/dom/Node.h 2011-06-02 00:46:41 UTC (rev 87866)
+++ trunk/Source/WebCore/dom/Node.h 2011-06-02 00:53:01 UTC (rev 87867)
@@ -283,6 +283,7 @@
// For <link> and <style> elements.
virtual bool sheetLoaded() { return true; }
+ virtual void startLoadingDynamicSheet() { ASSERT_NOT_REACHED(); }
bool hasID() const { return getFlag(HasIDFlag); }
bool hasClass() const { return getFlag(HasClassFlag); }
Modified: trunk/Source/WebCore/dom/StyleElement.cpp (87866 => 87867)
--- trunk/Source/WebCore/dom/StyleElement.cpp 2011-06-02 00:46:41 UTC (rev 87866)
+++ trunk/Source/WebCore/dom/StyleElement.cpp 2011-06-02 00:53:01 UTC (rev 87867)
@@ -182,4 +182,10 @@
return true;
}
+void StyleElement::startLoadingDynamicSheet(Document* document)
+{
+ ASSERT(document);
+ document->addPendingSheet();
}
+
+}
Modified: trunk/Source/WebCore/dom/StyleElement.h (87866 => 87867)
--- trunk/Source/WebCore/dom/StyleElement.h 2011-06-02 00:46:41 UTC (rev 87866)
+++ trunk/Source/WebCore/dom/StyleElement.h 2011-06-02 00:53:01 UTC (rev 87867)
@@ -41,6 +41,7 @@
bool isLoading() const;
bool sheetLoaded(Document*);
+ void startLoadingDynamicSheet(Document*);
void insertedIntoDocument(Document*, Element*);
void removedFromDocument(Document*, Element*);
Modified: trunk/Source/WebCore/html/HTMLLinkElement.cpp (87866 => 87867)
--- trunk/Source/WebCore/html/HTMLLinkElement.cpp 2011-06-02 00:46:41 UTC (rev 87866)
+++ trunk/Source/WebCore/html/HTMLLinkElement.cpp 2011-06-02 00:53:01 UTC (rev 87867)
@@ -472,6 +472,13 @@
return false;
}
+void HTMLLinkElement::startLoadingDynamicSheet()
+{
+ // We don't support multiple blocking sheets.
+ ASSERT(m_pendingSheetType < Blocking);
+ addPendingSheet(Blocking);
+}
+
bool HTMLLinkElement::isURLAttribute(Attribute *attr) const
{
return attr->name() == hrefAttr;
Modified: trunk/Source/WebCore/html/HTMLLinkElement.h (87866 => 87867)
--- trunk/Source/WebCore/html/HTMLLinkElement.h 2011-06-02 00:46:41 UTC (rev 87866)
+++ trunk/Source/WebCore/html/HTMLLinkElement.h 2011-06-02 00:53:01 UTC (rev 87867)
@@ -101,6 +101,7 @@
virtual void notifyFinished(CachedResource*);
#endif
virtual bool sheetLoaded();
+ virtual void startLoadingDynamicSheet();
bool isAlternate() const { return m_disabledState == Unset && m_relAttribute.m_isAlternate; }
Modified: trunk/Source/WebCore/html/HTMLStyleElement.h (87866 => 87867)
--- trunk/Source/WebCore/html/HTMLStyleElement.h 2011-06-02 00:46:41 UTC (rev 87866)
+++ trunk/Source/WebCore/html/HTMLStyleElement.h 2011-06-02 00:53:01 UTC (rev 87867)
@@ -55,6 +55,7 @@
virtual bool isLoading() const { return StyleElement::isLoading(); }
virtual bool sheetLoaded() { return StyleElement::sheetLoaded(document()); }
+ virtual void startLoadingDynamicSheet() { StyleElement::startLoadingDynamicSheet(document()); }
virtual void addSubresourceAttributeURLs(ListHashSet<KURL>&) const;
Modified: trunk/Source/WebCore/svg/SVGStyleElement.h (87866 => 87867)
--- trunk/Source/WebCore/svg/SVGStyleElement.h 2011-06-02 00:46:41 UTC (rev 87866)
+++ trunk/Source/WebCore/svg/SVGStyleElement.h 2011-06-02 00:53:01 UTC (rev 87867)
@@ -59,6 +59,7 @@
virtual bool isLoading() const { return StyleElement::isLoading(); }
virtual bool sheetLoaded() { return StyleElement::sheetLoaded(document()); }
+ virtual void startLoadingDynamicSheet() { StyleElement::startLoadingDynamicSheet(document()); }
};
} // namespace WebCore