WebCore:
authorantti <antti@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 29 Aug 2007 22:46:41 +0000 (22:46 +0000)
committerantti <antti@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 29 Aug 2007 22:46:41 +0000 (22:46 +0000)
        Reviewed by Mitz.

        Fix <rdar://problem/5425951>
        REGRESSION: change to updateLayoutIgnorePendingStylesheets causes SAP Portal page to render wrong

        If new nodes have been added or style recalc has been done with style sheets still pending, some nodes
        may not have had their real style calculated yet. Normally this state gets cleaned when style sheets arrive
        but in updateLayoutIgnorePendingStylesheets() we need to do full style recalc to get up-to-date style immediatly.

        Added a document flag to track if there are any nodes that did not have their real style calculated due to
        pending stylesheets.

        Test: fast/dynamic/style-access-late-stylesheet-load.html

        * css/CSSStyleSelector.cpp:
        (WebCore::CSSStyleSelector::styleForElement):
        * dom/Document.cpp:
        (WebCore::Document::Document):
        (WebCore::Document::recalcStyle):
        (WebCore::Document::updateLayoutIgnorePendingStylesheets):
        * dom/Document.h:
        (WebCore::Document::setHasNodesWithPlaceholderStyle):

LayoutTests:

        Reviewed by Mitz.

        Test for <rdar://problem/5425951>
        REGRESSION: change to updateLayoutIgnorePendingStylesheets causes SAP Portal page to render wrong

        * fast/dynamic/style-access-late-stylesheet-load-expected.txt: Added.
        * fast/dynamic/style-access-late-stylesheet-load.html: Added.

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

LayoutTests/ChangeLog
LayoutTests/fast/dynamic/style-access-late-stylesheet-load-expected.txt [new file with mode: 0644]
LayoutTests/fast/dynamic/style-access-late-stylesheet-load.html [new file with mode: 0644]
WebCore/ChangeLog
WebCore/css/CSSStyleSelector.cpp
WebCore/dom/Document.cpp
WebCore/dom/Document.h

index 9dd572c4da00de8e4b2da38d6051800a1a341145..f6c3a55620f4ac235e52cbb69c8779654e0a72a7 100644 (file)
@@ -1,3 +1,13 @@
+2007-08-29  Antti Koivisto  <antti@apple.com>
+
+        Reviewed by Mitz.
+        
+        Test for <rdar://problem/5425951>
+        REGRESSION: change to updateLayoutIgnorePendingStylesheets causes SAP Portal page to render wrong
+
+        * fast/dynamic/style-access-late-stylesheet-load-expected.txt: Added.
+        * fast/dynamic/style-access-late-stylesheet-load.html: Added.
+
 2007-08-28  Sam Weinig  <sam@webkit.org>
 
         Reviewed by Darin.
diff --git a/LayoutTests/fast/dynamic/style-access-late-stylesheet-load-expected.txt b/LayoutTests/fast/dynamic/style-access-late-stylesheet-load-expected.txt
new file mode 100644 (file)
index 0000000..967c53c
--- /dev/null
@@ -0,0 +1,2 @@
+Test that offsetWidth and similar get up to date style information even if a new stylesheet load is started at late stage of document rendering
+PASS
diff --git a/LayoutTests/fast/dynamic/style-access-late-stylesheet-load.html b/LayoutTests/fast/dynamic/style-access-late-stylesheet-load.html
new file mode 100644 (file)
index 0000000..c517fe0
--- /dev/null
@@ -0,0 +1,24 @@
+<html>
+<head>
+<script>  
+if (window.layoutTestController)
+    layoutTestController.dumpAsText();
+</script>
+<style>
+#test { position: absolute; width: 100px; height: 100px }
+</style>
+</head>
+<body>
+Test that offsetWidth and similar get up to date style information even if a new stylesheet load is started at late stage of document rendering
+<link rel=stylesheet href="data:text/css,blah">
+<div id=console></div>
+<div id=test></div>
+
+<script>
+var test = document.getElementById('test');
+var console = document.getElementById('console');
+console.innerHTML = ((test.offsetWidth == 100) ? "<span style='color:green'>PASS</span> " :  "<span style='color:red'>FAIL</span> ");
+</script>
+
+</body>
+</html>
index 5f3ee71b603a18ba3755352df1c51fb2224d9800..209594a86e944c5b9d2cda92925622122804db15 100644 (file)
@@ -1,3 +1,28 @@
+2007-08-29  Antti Koivisto  <antti@apple.com>
+
+        Reviewed by Mitz.
+        
+        Fix <rdar://problem/5425951>
+        REGRESSION: change to updateLayoutIgnorePendingStylesheets causes SAP Portal page to render wrong
+        
+        If new nodes have been added or style recalc has been done with style sheets still pending, some nodes 
+        may not have had their real style calculated yet. Normally this state gets cleaned when style sheets arrive 
+        but in updateLayoutIgnorePendingStylesheets() we need to do full style recalc to get up-to-date style immediatly.
+        
+        Added a document flag to track if there are any nodes that did not have their real style calculated due to
+        pending stylesheets.
+
+        Test: fast/dynamic/style-access-late-stylesheet-load.html
+
+        * css/CSSStyleSelector.cpp:
+        (WebCore::CSSStyleSelector::styleForElement):
+        * dom/Document.cpp:
+        (WebCore::Document::Document):
+        (WebCore::Document::recalcStyle):
+        (WebCore::Document::updateLayoutIgnorePendingStylesheets):
+        * dom/Document.h:
+        (WebCore::Document::setHasNodesWithPlaceholderStyle):
+
 2007-08-29  Alice Liu  <alice.liu@apple.com>
 
         Reviewed by Maciej.
index a0a39fc6429fcfc5e866fee6815411f8f83216eb..7172533b38e495b39e443acdf2af99adfac0a676 100644 (file)
@@ -793,6 +793,7 @@ RenderStyle* CSSStyleSelector::styleForElement(Element* e, RenderStyle* defaultP
             styleNotYetAvailable->font().update();
         }
         styleNotYetAvailable->ref();
+        e->document()->setHasNodesWithPlaceholderStyle();
         return styleNotYetAvailable;
     }
     
index 9c4cf8b97f02619e5cf97a9ba270e0aa78abb508..7527fb154deb97caa5547b9c55ab58b80d9e8e48 100644 (file)
@@ -318,6 +318,7 @@ Document::Document(DOMImplementation* impl, Frame* frame, bool isXHTML)
     m_didCalculateStyleSelector = false;
     m_pendingStylesheets = 0;
     m_ignorePendingStylesheets = false;
+    m_hasNodesWithPlaceholderStyle = false;
     m_pendingSheetLayout = NoLayoutWithPendingSheets;
 
     m_cssTarget = 0;
@@ -986,6 +987,9 @@ void Document::recalcStyle(StyleChange change)
         goto bail_out;
 
     if (change == Force) {
+        // style selector may set this again during recalc
+        m_hasNodesWithPlaceholderStyle = false;
+        
         RenderStyle* oldStyle = renderer()->style();
         if (oldStyle)
             oldStyle->ref();
@@ -1098,7 +1102,11 @@ void Document::updateLayoutIgnorePendingStylesheets()
         if (body() && !body()->renderer() && m_pendingSheetLayout == NoLayoutWithPendingSheets) {
             m_pendingSheetLayout = DidLayoutWithPendingSheets;
             updateStyleSelector();
-        }
+        } else if (m_hasNodesWithPlaceholderStyle)
+            // If new nodes have been added or style recalc has been done with style sheets still pending, some nodes 
+            // may not have had their real style calculated yet. Normally this gets cleaned when style sheets arrive 
+            // but here we need up-to-date style immediatly.
+            recalcStyle(Force);
     }
 
     updateLayout();
index 15e0bd33551d35593fdfb8e31598a636716e10fe..978e507e9d5a3ead07418984e503ec25de2eb7c3 100644 (file)
@@ -640,6 +640,8 @@ public:
     enum PendingSheetLayout { NoLayoutWithPendingSheets, DidLayoutWithPendingSheets, IgnoreLayoutWithPendingSheets };
 
     bool didLayoutWithPendingStylesheets() const { return m_pendingSheetLayout == DidLayoutWithPendingSheets; }
+    
+    void setHasNodesWithPlaceholderStyle() { m_hasNodesWithPlaceholderStyle = true; }
 
     String iconURL();
     void setIconURL(const String& iconURL, const String& type);
@@ -695,6 +697,8 @@ private:
     // to track that this happened so that we can do a full repaint when the stylesheets
     // do eventually load.
     PendingSheetLayout m_pendingSheetLayout;
+    
+    bool m_hasNodesWithPlaceholderStyle;
 
     RefPtr<CSSStyleSheet> m_elemSheet;