https://bugs.webkit.org/show_bug.cgi?id=46923
authorhyatt@apple.com <hyatt@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 30 Sep 2010 18:54:16 +0000 (18:54 +0000)
committerhyatt@apple.com <hyatt@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 30 Sep 2010 18:54:16 +0000 (18:54 +0000)
Reviewed by Simon Fraser.

Make determineLogicalLeftPositionForChild block-flow-aware.  Rewrite the function so that there aren't
completely separate LTR/RTL cases.

Added fast/blockflow/inline-direction-positioning.html

WebCore:

* rendering/RenderBlock.cpp:
(WebCore::RenderBlock::determineLogicalLeftPositionForChild):
(WebCore::RenderBlock::setLogicalLeftForChild):
* rendering/RenderBlock.h:
(WebCore::RenderBlock::logicalWidthForChild):
(WebCore::RenderBlock::logicalRightOffsetForContent):
(WebCore::RenderBlock::logicalLeftOffsetForContent):

LayoutTests:

* fast/blockflow/inline-direction-positioning.html: Added.
* platform/mac/fast/blockflow/inline-direction-positioning-expected.checksum: Added.
* platform/mac/fast/blockflow/inline-direction-positioning-expected.png: Added.
* platform/mac/fast/blockflow/inline-direction-positioning-expected.txt: Added.

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

LayoutTests/ChangeLog
LayoutTests/fast/blockflow/inline-direction-positioning.html [new file with mode: 0644]
LayoutTests/platform/mac/fast/blockflow/inline-direction-positioning-expected.checksum [new file with mode: 0644]
LayoutTests/platform/mac/fast/blockflow/inline-direction-positioning-expected.png [new file with mode: 0644]
LayoutTests/platform/mac/fast/blockflow/inline-direction-positioning-expected.txt [new file with mode: 0644]
WebCore/ChangeLog
WebCore/rendering/RenderBlock.cpp
WebCore/rendering/RenderBlock.h

index e64a476..904e0fd 100644 (file)
@@ -1,3 +1,19 @@
+2010-09-30  David Hyatt  <hyatt@apple.com>
+
+        Reviewed by Simon Fraser.
+
+        https://bugs.webkit.org/show_bug.cgi?id=46923
+        
+        Make determineLogicalLeftPositionForChild block-flow-aware.  Rewrite the function so that there aren't
+        completely separate LTR/RTL cases.
+
+        Added fast/blockflow/inline-direction-positioning.html
+
+        * fast/blockflow/inline-direction-positioning.html: Added.
+        * platform/mac/fast/blockflow/inline-direction-positioning-expected.checksum: Added.
+        * platform/mac/fast/blockflow/inline-direction-positioning-expected.png: Added.
+        * platform/mac/fast/blockflow/inline-direction-positioning-expected.txt: Added.
+
 2010-09-29  Adam Roben  <aroben@apple.com>
 
         Add test for color:8 media queries
diff --git a/LayoutTests/fast/blockflow/inline-direction-positioning.html b/LayoutTests/fast/blockflow/inline-direction-positioning.html
new file mode 100644 (file)
index 0000000..65f8fdf
--- /dev/null
@@ -0,0 +1,9 @@
+<html>
+<body>
+<div style="border:2px solid black;width:600px;">
+<div style="-webkit-writing-mode: tb-lr; writing-mode:tb-lr; width:100px; height:100px; margin-left:50px; background-color:green"></div>
+</div>
+
+<div style="border:2px solid black;width:600px;direction:rtl">
+<div style="-webkit-writing-mode: tb-lr; writing-mode:tb-lr; width:100px; height:100px; margin-right:50px; background-color:green"></div>
+</div>
diff --git a/LayoutTests/platform/mac/fast/blockflow/inline-direction-positioning-expected.checksum b/LayoutTests/platform/mac/fast/blockflow/inline-direction-positioning-expected.checksum
new file mode 100644 (file)
index 0000000..15f7527
--- /dev/null
@@ -0,0 +1 @@
+1355ed7c54d51dc216c8de007897aa7e
\ No newline at end of file
diff --git a/LayoutTests/platform/mac/fast/blockflow/inline-direction-positioning-expected.png b/LayoutTests/platform/mac/fast/blockflow/inline-direction-positioning-expected.png
new file mode 100644 (file)
index 0000000..00e44b3
Binary files /dev/null and b/LayoutTests/platform/mac/fast/blockflow/inline-direction-positioning-expected.png differ
diff --git a/LayoutTests/platform/mac/fast/blockflow/inline-direction-positioning-expected.txt b/LayoutTests/platform/mac/fast/blockflow/inline-direction-positioning-expected.txt
new file mode 100644 (file)
index 0000000..60392c8
--- /dev/null
@@ -0,0 +1,9 @@
+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 604x154 [border: (2px solid #000000)]
+        RenderBlock {DIV} at (52,52) size 100x100 [bgcolor=#008000]
+      RenderBlock {DIV} at (0,154) size 604x154 [border: (2px solid #000000)]
+        RenderBlock {DIV} at (452,2) size 100x100 [bgcolor=#008000]
index 4f0bbfc..c087e27 100644 (file)
@@ -1,3 +1,22 @@
+2010-09-30  David Hyatt  <hyatt@apple.com>
+
+        Reviewed by Simon Fraser.
+
+        https://bugs.webkit.org/show_bug.cgi?id=46923
+        
+        Make determineLogicalLeftPositionForChild block-flow-aware.  Rewrite the function so that there aren't
+        completely separate LTR/RTL cases.
+
+        Added fast/blockflow/inline-direction-positioning.html
+
+        * rendering/RenderBlock.cpp:
+        (WebCore::RenderBlock::determineLogicalLeftPositionForChild):
+        (WebCore::RenderBlock::setLogicalLeftForChild):
+        * rendering/RenderBlock.h:
+        (WebCore::RenderBlock::logicalWidthForChild):
+        (WebCore::RenderBlock::logicalRightOffsetForContent):
+        (WebCore::RenderBlock::logicalLeftOffsetForContent):
+
 2010-09-29  Adam Roben  <aroben@apple.com>
 
         Fix color media queries on Windows
index ba2d9c9..6119af7 100644 (file)
@@ -1645,54 +1645,33 @@ int RenderBlock::estimateLogicalTopPosition(RenderBox* child, const MarginInfo&
 
 void RenderBlock::determineLogicalLeftPositionForChild(RenderBox* child)
 {
-    int xPos = borderLeft() + paddingLeft();
-    if (style()->direction() == LTR) {
-        // Add in our left margin.
-        int chPos = xPos + child->marginLeft();
+    int startPosition = borderStart() + paddingStart();
+    int totalAvailableLogicalWidth = borderAndPaddingLogicalWidth() + availableLogicalWidth();
+
+    // Add in our start margin.
+    int childMarginStart = marginStartForChild(child);
+    int newPosition = startPosition + childMarginStart;
         
-        // Some objects (e.g., tables, horizontal rules, overflow:auto blocks) avoid floats.  They need
-        // to shift over as necessary to dodge any floats that might get in the way.
-        if (child->avoidsFloats()) {
-            int leftOff = logicalLeftOffsetForLine(height(), false);
-            if (style()->textAlign() != WEBKIT_CENTER && child->style()->marginLeft().type() != Auto) {
-                if (child->marginLeft() < 0)
-                    leftOff += child->marginLeft();
-                chPos = max(chPos, leftOff); // Let the float sit in the child's margin if it can fit.
-            }
-            else if (leftOff != xPos) {
-                // The object is shifting right. The object might be centered, so we need to
-                // recalculate our horizontal margins. Note that the containing block content
-                // width computation will take into account the delta between |leftOff| and |xPos|
-                // so that we can just pass the content width in directly to the |computeMarginsInContainingBlockInlineDirection|
-                // function.
-                child->computeInlineDirectionMargins(this, availableLogicalWidthForLine(child->y(), false), child->width());
-                chPos = leftOff + child->marginLeft();
-            }
-        }
-        view()->addLayoutDelta(IntSize(child->x() - chPos, 0));
-        child->setLocation(chPos, child->y());
-    } else {
-        xPos += availableLogicalWidth();
-        int chPos = xPos - (child->width() + child->marginRight());
-        if (child->avoidsFloats()) {
-            int rightOff = logicalRightOffsetForLine(height(), false);
-            if (style()->textAlign() != WEBKIT_CENTER && child->style()->marginRight().type() != Auto) {
-                if (child->marginRight() < 0)
-                    rightOff -= child->marginRight();
-                chPos = min(chPos, rightOff - child->width()); // Let the float sit in the child's margin if it can fit.
-            } else if (rightOff != xPos) {
-                // The object is shifting left. The object might be centered, so we need to
-                // recalculate our horizontal margins. Note that the containing block content
-                // width computation will take into account the delta between |rightOff| and |xPos|
-                // so that we can just pass the content width in directly to the |computeInlineDirectionMargins|
-                // function.
-                child->computeInlineDirectionMargins(this, availableLogicalWidthForLine(child->y(), false), child->width());
-                chPos = rightOff - child->marginRight() - child->width();
-            }
+    // Some objects (e.g., tables, horizontal rules, overflow:auto blocks) avoid floats.  They need
+    // to shift over as necessary to dodge any floats that might get in the way.
+    if (child->avoidsFloats()) {
+        int startOff = style()->direction() == LTR ? logicalLeftOffsetForLine(logicalHeight(), false) : totalAvailableLogicalWidth - logicalRightOffsetForLine(logicalHeight(), false);
+        if (style()->textAlign() != WEBKIT_CENTER && !child->style()->marginStartUsing(style()).isAuto()) {
+            if (childMarginStart < 0)
+                startOff += childMarginStart;
+            newPosition = max(newPosition, startOff); // Let the float sit in the child's margin if it can fit.
+        } else if (startOff != startPosition) {
+            // The object is shifting to the "end" side of the block. The object might be centered, so we need to
+            // recalculate our inline direction margins. Note that the containing block content
+            // width computation will take into account the delta between |startOff| and |startPosition|
+            // so that we can just pass the content width in directly to the |computeMarginsInContainingBlockInlineDirection|
+            // function.
+            child->computeInlineDirectionMargins(this, availableLogicalWidthForLine(logicalTopForChild(child), false), logicalWidthForChild(child));
+            newPosition = startOff + marginStartForChild(child);
         }
-        view()->addLayoutDelta(IntSize(child->x() - chPos, 0));
-        child->setLocation(chPos, child->y());
     }
+
+    setLogicalLeftForChild(child, style()->direction() == LTR ? newPosition : totalAvailableLogicalWidth - newPosition - logicalWidthForChild(child));
 }
 
 void RenderBlock::setCollapsedBottomMargin(const MarginInfo& marginInfo)
@@ -1733,6 +1712,17 @@ void RenderBlock::handleAfterSideOfBlock(int top, int bottom, MarginInfo& margin
     setCollapsedBottomMargin(marginInfo);
 }
 
+void RenderBlock::setLogicalLeftForChild(RenderBox* child, int logicalLeft)
+{
+    if (style()->isVerticalBlockFlow()) {
+        view()->addLayoutDelta(IntSize(child->x() - logicalLeft, 0));
+        child->setLocation(logicalLeft, child->y());
+    } else {
+        view()->addLayoutDelta(IntSize(0, child->y() - logicalLeft));
+        child->setLocation(child->x(), logicalLeft);
+    }
+}
+
 void RenderBlock::setLogicalTopForChild(RenderBox* child, int logicalTop)
 {
     if (style()->isVerticalBlockFlow()) {
@@ -3219,11 +3209,6 @@ HashSet<RenderBox*>* RenderBlock::percentHeightDescendants() const
     return gPercentHeightDescendantsMap ? gPercentHeightDescendantsMap->get(this) : 0;
 }
 
-int RenderBlock::logicalLeftOffsetForContent() const
-{
-    return borderLeft() + paddingLeft();
-}
-
 int RenderBlock::logicalLeftOffsetForLine(int y, int fixedOffset, bool applyTextIndent, int* heightRemaining) const
 {
     int left = fixedOffset;
@@ -3252,11 +3237,6 @@ int RenderBlock::logicalLeftOffsetForLine(int y, int fixedOffset, bool applyText
     return left;
 }
 
-int RenderBlock::logicalRightOffsetForContent() const
-{
-    return borderLeft() + paddingLeft() + availableLogicalWidth();
-}
-
 int RenderBlock::logicalRightOffsetForLine(int y, int fixedOffset, bool applyTextIndent, int* heightRemaining) const
 {
     int right = fixedOffset;
index 5926e7e..752dc73 100644 (file)
@@ -105,7 +105,7 @@ public:
     int availableLogicalWidthForLine(int position, bool firstLine) const;
     int logicalRightOffsetForLine(int position, bool firstLine) const { return logicalRightOffsetForLine(position, logicalRightOffsetForContent(), firstLine); }
     int logicalLeftOffsetForLine(int position, bool firstLine) const { return logicalLeftOffsetForLine(position, logicalLeftOffsetForContent(), firstLine); }
-    
+
     virtual int lowestPosition(bool includeOverflowInterior = true, bool includeSelf = true) const;
     virtual int rightmostPosition(bool includeOverflowInterior = true, bool includeSelf = true) const;
     virtual int leftmostPosition(bool includeOverflowInterior = true, bool includeSelf = true) const;
@@ -170,8 +170,11 @@ public:
     void setPageY(int y);
 
     // Accessors for logical width/height and margins in the containing block's block-flow direction.
+    int logicalWidthForChild(RenderBox* child) { return style()->isVerticalBlockFlow() ? child->width() : child->height(); }
     int logicalHeightForChild(RenderBox* child) { return style()->isVerticalBlockFlow() ? child->height() : child->width(); }
     int logicalTopForChild(RenderBox* child) { return style()->isVerticalBlockFlow() ? child->y() : child->x(); }
+    void setLogicalLeftForChild(RenderBox* child, int logicalLeft);
+    void setLogicalTopForChild(RenderBox* child, int logicalTop);
     int marginBeforeForChild(RenderBoxModelObject* child) const;
     int marginAfterForChild(RenderBoxModelObject* child) const;
     int marginStartForChild(RenderBoxModelObject* child) const;
@@ -234,8 +237,8 @@ protected:
     virtual void paint(PaintInfo&, int tx, int ty);
     virtual void paintObject(PaintInfo&, int tx, int ty);
 
-    int logicalRightOffsetForContent() const;
-    int logicalLeftOffsetForContent() const;
+    int logicalRightOffsetForContent() const { return style()->isVerticalBlockFlow() ? borderLeft() + paddingLeft() + availableLogicalWidth() : borderTop() + paddingTop() + availableLogicalWidth(); }
+    int logicalLeftOffsetForContent() const { return style()->isVerticalBlockFlow() ? borderLeft() + paddingLeft() : borderTop() + paddingTop(); }
     int logicalRightOffsetForLine(int position, int fixedOffset, bool applyTextIndent = true, int* logicalHeightRemaining = 0) const;
     int logicalLeftOffsetForLine(int position, int fixedOffset, bool applyTextIndent = true, int* logicalHeightRemaining = 0) const;
 
@@ -584,7 +587,6 @@ private:
     void determineLogicalLeftPositionForChild(RenderBox* child);
     void handleAfterSideOfBlock(int top, int bottom, MarginInfo&);
     void setCollapsedBottomMargin(const MarginInfo&);
-    void setLogicalTopForChild(RenderBox* child, int logicalTop);
     // End helper functions and structs used by layoutBlockChildren.
 
     // Pagination routines.