Add some more polish to ensure the ypos estimate is right. Correct the clearing...
authorhyatt <hyatt@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 12 Feb 2004 01:33:51 +0000 (01:33 +0000)
committerhyatt <hyatt@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 12 Feb 2004 01:33:51 +0000 (01:33 +0000)
their top margins do not get added in when they clear the float because of having a large width.

        Reviewed by kocienda

        * khtml/rendering/render_block.cpp:
        (khtml::RenderBlock::layoutBlockChildren):
        * layout-tests/fast/block/margin-collapse/101-expected.txt: Added.
        * layout-tests/fast/block/margin-collapse/101.html: Added.
        * layout-tests/fast/block/margin-collapse/102-expected.txt: Added.
        * layout-tests/fast/block/margin-collapse/102.html: Added.

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

LayoutTests/fast/block/margin-collapse/101-expected.txt [new file with mode: 0644]
LayoutTests/fast/block/margin-collapse/101.html [new file with mode: 0644]
LayoutTests/fast/block/margin-collapse/102-expected.txt [new file with mode: 0644]
LayoutTests/fast/block/margin-collapse/102.html [new file with mode: 0644]
WebCore/ChangeLog-2005-08-23
WebCore/khtml/rendering/render_block.cpp

diff --git a/LayoutTests/fast/block/margin-collapse/101-expected.txt b/LayoutTests/fast/block/margin-collapse/101-expected.txt
new file mode 100644 (file)
index 0000000..1c68d6b
--- /dev/null
@@ -0,0 +1,12 @@
+layer at (0,0) size 800x600
+  RenderCanvas at (0,0) size 800x600
+layer at (0,0) size 800x363
+  RenderBlock {HTML} at (0,0) size 800x363
+    RenderBody {BODY} at (8,8) size 784x347
+      RenderBlock {DIV} at (0,0) size 385x347
+        RenderBlock {P} at (0,0) size 385x40 [border: (2px solid #0000FF)]
+          RenderText {TEXT} at (2,2) size 365x36
+            text run at (2,2) width 146: "There should be only 2"
+            text run at (148,2) width 219: "em between this paragraph and the"
+            text run at (2,20) width 85: "image below."
+        RenderImage {IMG} at (0,72) size 395x275
diff --git a/LayoutTests/fast/block/margin-collapse/101.html b/LayoutTests/fast/block/margin-collapse/101.html
new file mode 100644 (file)
index 0000000..900650a
--- /dev/null
@@ -0,0 +1,32 @@
+<html xmlns="http://www.w3.org/1999/xhtml">
+  <head>
+
+    <title>Jeffrey Zeldman Presents: The Daily Report</title>
+
+<style>
+        
+#bravefourhundred {
+       width: 385px;
+}
+
+img {
+    display: block;
+    margin-top: 1em;
+}
+
+p { border: 2px solid blue; margin-bottom: 2em; }
+</style>
+
+
+
+  </head>
+
+<body>
+<div id="bravefourhundred">
+
+<p>There should be only 2em between this paragraph and the
+image below.</p>
+
+<img width="395" height="275" border="0"></div>
+</body>
+</html>
diff --git a/LayoutTests/fast/block/margin-collapse/102-expected.txt b/LayoutTests/fast/block/margin-collapse/102-expected.txt
new file mode 100644 (file)
index 0000000..6f97ea7
--- /dev/null
@@ -0,0 +1,12 @@
+layer at (0,0) size 800x600
+  RenderCanvas at (0,0) size 800x600
+layer at (0,0) size 800x427
+  RenderBlock {HTML} at (0,0) size 800x427
+    RenderBody {BODY} at (8,8) size 784x411
+      RenderBlock {DIV} at (0,0) size 385x411
+        RenderBlock {DIV} at (0,0) size 385x36
+          RenderText {TEXT} at (0,0) size 364x36
+            text run at (0,0) width 364: "There should be no vertical space between the two blocks"
+            text run at (0,18) width 43: "below."
+        RenderBlock (floating) {DIV} at (0,36) size 100x100 [bgcolor=#008000]
+        RenderImage {IMG} at (0,136) size 395x275 [bgcolor=#FFFF00]
diff --git a/LayoutTests/fast/block/margin-collapse/102.html b/LayoutTests/fast/block/margin-collapse/102.html
new file mode 100644 (file)
index 0000000..03a8e12
--- /dev/null
@@ -0,0 +1,32 @@
+<html xmlns="http://www.w3.org/1999/xhtml">
+  <head>
+
+    <title>Jeffrey Zeldman Presents: The Daily Report</title>
+
+<style>
+        
+#bravefourhundred {
+       width: 385px;
+}
+
+img {
+    margin-top:1em;
+    display: block;
+    background-color:yellow;
+}
+
+.foo { float:left;width:100px; height:100px;background-color:green }
+
+</style>
+
+
+
+  </head>
+
+<body>
+<div id="bravefourhundred">
+<div>There should be no vertical space between the two blocks below.</div>
+<div class="foo"></div><img width="395" height="275" border="0">
+</div>
+</body>
+</html>
index 7e94546eac6f2f3dadb768c0fa81520a726b1604..a87efeb9ee9bc4a48d200fa4bbe532edeebdb1c9 100644 (file)
@@ -1,3 +1,17 @@
+2004-02-11  David Hyatt  <hyatt@apple.com>
+
+       Add some more polish to ensure the ypos estimate is right.  Correct the clearing of images so that
+       their top margins do not get added in when they clear the float because of having a large width.
+       
+        Reviewed by kocienda
+
+        * khtml/rendering/render_block.cpp:
+        (khtml::RenderBlock::layoutBlockChildren):
+        * layout-tests/fast/block/margin-collapse/101-expected.txt: Added.
+        * layout-tests/fast/block/margin-collapse/101.html: Added.
+        * layout-tests/fast/block/margin-collapse/102-expected.txt: Added.
+        * layout-tests/fast/block/margin-collapse/102.html: Added.
+
 2004-02-11  David Hyatt  <hyatt@apple.com>
 
        Fix for 3556702, margin collapsing gets disabled when images spill out of the containing block.
index 17d9266c37d639b84ffe08f6e7ad0097f5f9e49d..9fab63b73f7bd31301e3092ad037e5c8ab74fcac 100644 (file)
@@ -743,26 +743,8 @@ void RenderBlock::layoutBlockChildren( bool relayoutChildren )
             }
         }
         
-        // Note this occurs after the test for positioning and floating above, since
-        // we want to ensure that we don't artificially increase our height because of
-        // a positioned or floating child.
-        if (child->avoidsFloats() && style()->width().isFixed() && child->minWidth() > lineWidth(m_height)) {
-            m_height = kMax(m_height, floatBottom());
-            shouldCollapseChild = false;
-            clearOccurred = true;
-        }
-
-        // take care in case we inherited floats
-        if (child && floatBottom() > m_height)
-            child->setChildNeedsLayout(true);
-        
         child->calcVerticalMargins();
 
-        //kdDebug(0) << "margin = " << margin << " yPos = " << m_height << endl;
-
-        int oldChildX = child->xPos();
-        int oldChildY = child->yPos();
-        
         // Try to guess our correct y position.  In most cases this guess will
         // be correct.  Only if we're wrong (when we compute the real y position)
         // will we have to relayout.
@@ -778,7 +760,30 @@ void RenderBlock::layoutBlockChildren( bool relayoutChildren )
         }
         else if (!canCollapseTopWithChildren || !topMarginContributor)
             yPosEstimate += child->marginTop();
+        
+        // Note this occurs after the test for positioning and floating above, since
+        // we want to ensure that we don't artificially increase our height because of
+        // a positioned or floating child.
+        int fb = floatBottom();
+        if (child->avoidsFloats() && style()->width().isFixed() && child->minWidth() > lineWidth(m_height)) {
+            if (fb > m_height) {
+                m_height = yPosEstimate = fb;
+                shouldCollapseChild = false;
+                clearOccurred = true;
+                prevFlow = 0;
+                prevBlock = 0;
+            }
+        }
 
+        // take care in case we inherited floats
+        if (fb > m_height)
+            child->setChildNeedsLayout(true);
+
+        //kdDebug(0) << "margin = " << margin << " yPos = " << m_height << endl;
+
+        int oldChildX = child->xPos();
+        int oldChildY = child->yPos();
+        
         // Go ahead and position the child as though it didn't collapse with the top.
         child->setPos(child->xPos(), yPosEstimate);
         child->layoutIfNeeded();