Reviewed by hyatt.
authorrwlbuis <rwlbuis@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 11 Nov 2006 15:49:45 +0000 (15:49 +0000)
committerrwlbuis <rwlbuis@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 11 Nov 2006 15:49:45 +0000 (15:49 +0000)
        http://bugzilla.opendarwin.org/show_bug.cgi?id=10893
        InsertRule can not handle @import statements

        Allow @import as part of a css rule.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@17730 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/fast/dom/css-insert-import-rule-expected.txt [new file with mode: 0644]
LayoutTests/fast/dom/css-insert-import-rule.html [new file with mode: 0644]
LayoutTests/fast/dom/resources/css-insert-import-rule-red.css [new file with mode: 0644]
WebCore/ChangeLog
WebCore/css/CSSGrammar.y
WebCore/css/CSSImportRule.cpp
WebCore/css/CSSStyleSheet.cpp
WebCore/css/CSSStyleSheet.h

index fd598769e9adc01cc0a60cfa2163302c63440e83..fadd9bb1150737e9dfe87a86610918753a478e35 100644 (file)
@@ -1,3 +1,15 @@
+2006-11-11  Rob Buis  <buis@kde.org>
+
+        Reviewed by hyatt.
+
+        Testcase for:
+        http://bugzilla.opendarwin.org/show_bug.cgi?id=10893
+        InsertRule can not handle @import statements
+
+        * fast/dom/css-insert-import-rule-expected.txt: Added.
+        * fast/dom/css-insert-import-rule.html: Added.
+        * fast/dom/resources/css-insert-import-rule-red.css: Added.
+
 2006-11-11  Graham Dennis  <graham.dennis@gmail.com>
 
         Reviewed by mitz.
diff --git a/LayoutTests/fast/dom/css-insert-import-rule-expected.txt b/LayoutTests/fast/dom/css-insert-import-rule-expected.txt
new file mode 100644 (file)
index 0000000..7ce690f
--- /dev/null
@@ -0,0 +1,6 @@
+layer at (0,0) size 800x600
+  RenderView at (0,0) size 800x600
+layer at (0,0) size 800x600
+  RenderBlock {HTML} at (0,0) size 800x600
+    RenderBody {BODY} at (8,8) size 784x584
+      RenderBlock {DIV} at (0,0) size 100x100 [bgcolor=#008000]
diff --git a/LayoutTests/fast/dom/css-insert-import-rule.html b/LayoutTests/fast/dom/css-insert-import-rule.html
new file mode 100644 (file)
index 0000000..cf99a5c
--- /dev/null
@@ -0,0 +1,19 @@
+<head>
+<style>
+@import url("resources/css-insert-import-rule-red.css");
+div {
+    width: 100px;
+    height: 100px;
+}
+</style>
+
+<script>
+function test() {
+  document.styleSheets[0].insertRule('@import url("resources/css-insert-import-rule.css");', 0);
+}
+</script>
+
+</head>
+<body onload="test()";>
+<div></div>
+</body>
diff --git a/LayoutTests/fast/dom/resources/css-insert-import-rule-red.css b/LayoutTests/fast/dom/resources/css-insert-import-rule-red.css
new file mode 100644 (file)
index 0000000..a340a21
--- /dev/null
@@ -0,0 +1,3 @@
+div {
+     background-color: red;
+}
index 5163db7b60aea0cb52e989f4064795fa56b06d45..77a932cdd15d783e381846c38884511ca7c35a0a 100644 (file)
@@ -1,3 +1,21 @@
+2006-11-11  Rob Buis  <buis@kde.org>
+
+        Reviewed by hyatt.
+
+        http://bugzilla.opendarwin.org/show_bug.cgi?id=10893
+        InsertRule can not handle @import statements
+
+        Allow @import as part of a css rule.
+
+        * css/CSSGrammar.y:
+        * css/CSSImportRule.cpp:
+        (WebCore::CSSImportRule::insertedIntoParent):
+        * css/CSSStyleSheet.cpp:
+        (WebCore::CSSStyleSheet::CSSStyleSheet):
+        (WebCore::CSSStyleSheet::checkLoaded):
+        * css/CSSStyleSheet.h:
+        (WebCore::CSSStyleSheet::loadCompleted):
+
 2006-11-11  Alexey Proskuryakov  <ap@webkit.org>
 
         Attempt to fix Qt build.
index 4f95fa032d196bbb491f91d88791e25dbcade9cc..fe7dcc501c10a66487109d675dac58d572f15d53 100644 (file)
@@ -228,6 +228,7 @@ static int cssyylex(YYSTYPE *yylval) { return CSSParser::current()->lex(yylval);
 
 %type <rule> charset
 %type <rule> ruleset
+%type <rule> ruleset_or_import
 %type <rule> media
 %type <rule> import
 %type <rule> page
@@ -297,8 +298,13 @@ stylesheet:
   | webkit_mediaquery maybe_space
   ;
 
+ruleset_or_import:
+   ruleset |
+   import
+;
+
 webkit_rule:
-    WEBKIT_RULE_SYM '{' maybe_space ruleset maybe_space '}' {
+    WEBKIT_RULE_SYM '{' maybe_space ruleset_or_import maybe_space '}' {
         static_cast<CSSParser*>(parser)->rule = $4;
     }
 ;
index 2c442d2bc644318636b1e72e951851ff3c786850..ec10c89a608c3f7351feeebb142ff9a79665d928 100644 (file)
@@ -26,6 +26,7 @@
 #include "CachedCSSStyleSheet.h"
 #include "CSSStyleSheet.h"
 #include "DocLoader.h"
+#include "Document.h"
 #include "KURL.h"
 #include "MediaList.h"
 
@@ -100,6 +101,11 @@ void CSSImportRule::insertedIntoParent()
     
     m_cachedSheet = docLoader->requestCSSStyleSheet(absHref, parentSheet->charset());
     if (m_cachedSheet) {
+        // if the import rule is issued dynamically, the sheet may be
+        // removed from the pending sheet count, so let the doc know
+        // the sheet being imported is pending.
+        if (parentSheet && parentSheet->loadCompleted())
+            parentSheet->doc()->addPendingSheet();
         m_loading = true;
         m_cachedSheet->ref(this);
     }
index 97b0d198a08443a983407796ff2d3dd114c72ad8..76338e43846bb2131fc1f6b162ecaf07aba8a681 100644 (file)
@@ -37,6 +37,7 @@ CSSStyleSheet::CSSStyleSheet(CSSStyleSheet* parentSheet, const String& href, con
     , m_doc(parentSheet ? parentSheet->doc() : 0)
     , m_namespaces(0)
     , m_charset(charset)
+    , m_loadCompleted(false)
 {
 }
 
@@ -45,6 +46,7 @@ CSSStyleSheet::CSSStyleSheet(Node *parentNode, const String& href, const String&
     , m_doc(parentNode->document())
     , m_namespaces(0)
     , m_charset(charset)
+    , m_loadCompleted(false)
 {
 }
 
@@ -53,6 +55,7 @@ CSSStyleSheet::CSSStyleSheet(CSSRule *ownerRule, const String& href, const Strin
     , m_doc(0)
     , m_namespaces(0)
     , m_charset(charset)
+    , m_loadCompleted(false)
 {
 }
 
@@ -169,6 +172,7 @@ void CSSStyleSheet::checkLoaded()
         parent()->checkLoaded();
     if (m_parentNode)
         m_parentNode->sheetLoaded();
+    m_loadCompleted = true;
 }
 
 DocLoader *CSSStyleSheet::docLoader()
index e875b6a844e21e89519ba23573031c8c8f0ce795..96fc78fd0b77a48adb34ea3a67814ae48e2214aa 100644 (file)
@@ -70,10 +70,13 @@ public:
     Document* doc() { return m_doc; }
     const String& charset() const { return m_charset; }
 
+    bool loadCompleted() const { return m_loadCompleted; }
+
 protected:
     Document* m_doc;
     CSSNamespace* m_namespaces;
     String m_charset;
+    bool m_loadCompleted;
 };
 
 } // namespace