Title: [94492] trunk
Revision
94492
Author
[email protected]
Date
2011-09-03 11:28:57 -0700 (Sat, 03 Sep 2011)

Log Message

div align="center" rendering problem
https://bugs.webkit.org/show_bug.cgi?id=4860

Reviewed by David Hyatt.

Source/WebCore:

When an inline element with absolute position was the sole or first child of a render block with
centred alignment, it wasn't obeying its parent's alignment. However it would obey the
alignment if it was preceded by some text. The problem was that the element's render object
was getting skipped as leading white space, so it was not included in a normal line block in
a bidi run. Instead, its position was getting set by RenderBlockLineLayout::setStaticPositions()
which does not pay attention to alignment. Preceding the element with some text allowed the object
to get included in a Bidi run and so get a linebox which would get properly aligned.

The fix is to get RenderBlockLineLayout::setStaticPositions() to obey the alignment specified by
the object's container. This allows WebKit to get the same result on the test as Firefox and IE.
Opera has the same bug as unpatched WebKit.

Tests: fast/css/bug4860-absolute-block-child-does-not-inherit-alignment.html
       - Ensure positioned block elements inherit alignment.
       fast/css/bug4860-absolute-inline-child-inherits-alignment.html
       - Ensure positioned inline elements inherit alignment.
       fast/inline/absolute-positioned-inline-in-centred-block.html
       - Ensure positioned inline element that's the sole or first child of a rendered block
         obeys parents alignment.
       fast/inline/absolute-positioned-block-in-centred-block.html
       - As above, but a positioned block should not inherit alignment.

* rendering/RenderBlock.h:
* rendering/RenderBlockLineLayout.cpp:
(WebCore::RenderBlock::updateLogicalWidthForAlignment):
(WebCore::RenderBlock::computeInlineDirectionPositionsForLine): Move the alignment check to updateLogicalWidthForAlignment.
(WebCore::setStaticPositions): use startAlignedOffsetForLine and use startAlignedOffsetForBlock
(WebCore::RenderBlock::startAlignedOffsetForLine): New function, find the aligned offset using updateLogicalWidthForAlignment

LayoutTests:

* fast/css/bug4860-absolute-block-child-does-not-inherit-alignment-expected.png: Added.
* fast/css/bug4860-absolute-block-child-does-not-inherit-alignment-expected.txt: Added.
* fast/css/bug4860-absolute-block-child-does-not-inherit-alignment.html: Added.
* fast/css/bug4860-absolute-inline-child-inherits-alignment-expected.png: Added.
* fast/css/bug4860-absolute-inline-child-inherits-alignment-expected.txt: Added.
* fast/css/bug4860-absolute-inline-child-inherits-alignment.html: Added.
* fast/inline/absolute-positioned-block-in-centred-block-expected.png: Added.
* fast/inline/absolute-positioned-block-in-centred-block-expected.txt: Added.
* fast/inline/absolute-positioned-block-in-centred-block.html: Added.
* fast/inline/absolute-positioned-inline-in-centred-block-expected.png: Added.
* fast/inline/absolute-positioned-inline-in-centred-block-expected.txt: Added.
* fast/inline/absolute-positioned-inline-in-centred-block.html: Added.
* platform/chromium-linux/fast/repaint/block-layout-inline-children-float-positioned-expected.png:
* platform/chromium-linux/fast/repaint/block-layout-inline-children-float-positioned-expected.txt:
  Both of these two tests were based on the incorrect behaviour of ignoring the alignment specified
  by the container of an element absolute position when there was no text preceding the element.
  The updated results agree with Firefox and IE.
* fast/css/absolute-child-with-percent-height-inside-relative-parent-expected.txt:
* platform/chromium-win/fast/css/absolute-child-with-percent-height-inside-relative-parent-expected.png:
  This test expected the wrong alignment of the red block - it should be centred, not aligned to the left.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (94491 => 94492)


--- trunk/LayoutTests/ChangeLog	2011-09-03 18:18:04 UTC (rev 94491)
+++ trunk/LayoutTests/ChangeLog	2011-09-03 18:28:57 UTC (rev 94492)
@@ -1,3 +1,50 @@
+2011-08-27  Robert Hogan  <[email protected]>
+
+        div align="center" rendering problem
+        https://bugs.webkit.org/show_bug.cgi?id=4860
+
+        Reviewed by David Hyatt.
+
+        * fast/css/bug4860-absolute-block-child-does-not-inherit-alignment-expected.png: Added.
+        * fast/css/bug4860-absolute-block-child-does-not-inherit-alignment-expected.txt: Added.
+        * fast/css/bug4860-absolute-block-child-does-not-inherit-alignment.html: Added.
+        * fast/css/bug4860-absolute-inline-child-inherits-alignment-expected.png: Added.
+        * fast/css/bug4860-absolute-inline-child-inherits-alignment-expected.txt: Added.
+        * fast/css/bug4860-absolute-inline-child-inherits-alignment.html: Added.
+        * fast/inline/absolute-positioned-block-in-centred-block-expected.png: Added.
+        * fast/inline/absolute-positioned-block-in-centred-block-expected.txt: Added.
+        * fast/inline/absolute-positioned-block-in-centred-block.html: Added.
+        * fast/inline/absolute-positioned-inline-in-centred-block-expected.png: Added.
+        * fast/inline/absolute-positioned-inline-in-centred-block-expected.txt: Added.
+        * fast/inline/absolute-positioned-inline-in-centred-block.html: Added.
+        * platform/chromium-linux/fast/repaint/block-layout-inline-children-float-positioned-expected.png:
+        * platform/chromium-linux/fast/repaint/block-layout-inline-children-float-positioned-expected.txt:
+          Both of these two tests were based on the incorrect behaviour of ignoring the alignment specified
+          by the container of an element absolute position when there was no text preceding the element.
+          The updated results agree with Firefox and IE.
+        * fast/css/absolute-child-with-percent-height-inside-relative-parent-expected.txt:
+        * platform/chromium-win/fast/css/absolute-child-with-percent-height-inside-relative-parent-expected.png:
+          This test expected the wrong alignment of the red block - it should be centred, not aligned to the left.
+
+2011-07-25  Robert Hogan  <[email protected]>
+
+        div align="center" rendering problem
+        https://bugs.webkit.org/show_bug.cgi?id=4860
+
+        Reviewed by David Hyatt.
+
+        * fast/inline/absolute-positioned-block-in-centred-block-expected.png: Added.
+        * fast/inline/absolute-positioned-block-in-centred-block-expected.txt: Added.
+        * fast/inline/absolute-positioned-block-in-centred-block.html: Added.
+        * fast/inline/absolute-positioned-inline-in-centred-block-expected.png: Added.
+        * fast/inline/absolute-positioned-inline-in-centred-block-expected.txt: Added.
+        * fast/inline/absolute-positioned-inline-in-centred-block.html: Added.
+        * platform/chromium-linux/fast/repaint/block-layout-inline-children-float-positioned-expected.png:
+        * platform/chromium-linux/fast/repaint/block-layout-inline-children-float-positioned-expected.txt:
+          Both of these two tests were based on the incorrect behaviour of ignoring the alignment specified
+          by the container of an element absolute position when there was no text preceding the element.
+          The updated results agree with Firefox and IE.
+
 2011-09-03  Yuta Kitamura  <[email protected]>
 
         WebSocket: Send ArrayBuffer as WebSocket binary message

Modified: trunk/LayoutTests/fast/css/absolute-child-with-percent-height-inside-relative-parent-expected.txt (94491 => 94492)


--- trunk/LayoutTests/fast/css/absolute-child-with-percent-height-inside-relative-parent-expected.txt	2011-09-03 18:18:04 UTC (rev 94491)
+++ trunk/LayoutTests/fast/css/absolute-child-with-percent-height-inside-relative-parent-expected.txt	2011-09-03 18:28:57 UTC (rev 94492)
@@ -6,7 +6,7 @@
       RenderText {#text} at (0,0) size 0x0
 layer at (87,8) size 627x230
   RenderBlock (relative positioned) {DIV} at (79,0) size 627x230 [bgcolor=#0000FF]
-layer at (87,8) size 501x230
-  RenderBlock (positioned) {DIV} at (0,0) size 501x230 [bgcolor=#FF0000]
+layer at (154,8) size 501x230
+  RenderBlock (positioned) {DIV} at (67,0) size 501x230 [bgcolor=#FF0000]
     RenderImage {IMG} at (51,0) size 400x230
     RenderText {#text} at (0,0) size 0x0

Added: trunk/LayoutTests/fast/css/bug4860-absolute-block-child-does-not-inherit-alignment-expected.png


(Binary files differ)
Property changes on: trunk/LayoutTests/fast/css/bug4860-absolute-block-child-does-not-inherit-alignment-expected.png ___________________________________________________________________

Added: svn:mime-type

Added: trunk/LayoutTests/fast/css/bug4860-absolute-block-child-does-not-inherit-alignment-expected.txt (0 => 94492)


--- trunk/LayoutTests/fast/css/bug4860-absolute-block-child-does-not-inherit-alignment-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/css/bug4860-absolute-block-child-does-not-inherit-alignment-expected.txt	2011-09-03 18:28:57 UTC (rev 94492)
@@ -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
+layer at (8,8) size 627x200
+  RenderBlock (relative positioned) {DIV} at (0,0) size 627x200 [bgcolor=#0000FF]
+layer at (8,8) size 501x200
+  RenderBlock (positioned) {DIV} at (0,0) size 501x200 [bgcolor=#FF0000]
Property changes on: trunk/LayoutTests/fast/css/bug4860-absolute-block-child-does-not-inherit-alignment-expected.txt
___________________________________________________________________

Added: svn:eol-style

Added: trunk/LayoutTests/fast/css/bug4860-absolute-block-child-does-not-inherit-alignment.html (0 => 94492)


--- trunk/LayoutTests/fast/css/bug4860-absolute-block-child-does-not-inherit-alignment.html	                        (rev 0)
+++ trunk/LayoutTests/fast/css/bug4860-absolute-block-child-does-not-inherit-alignment.html	2011-09-03 18:28:57 UTC (rev 94492)
@@ -0,0 +1,20 @@
+<html>
+<head>
+    <style type="text/css">
+        body {text-align:center;}
+        body * {
+            width: 80%;
+        }
+        body > div {background: blue;}
+        body > div > div {background: red;}
+    </style>
+</head>
+<!--A block with a block display type does not inherit alignment from its parent.
+    The red block should be aligned to the left.-->
+ <body>
+  <div style="position:relative;padding-bottom:200px;">
+   <div style="height: 100%;position:absolute;">
+   </div>
+  </div>
+ </body>
+</html>
Property changes on: trunk/LayoutTests/fast/css/bug4860-absolute-block-child-does-not-inherit-alignment.html
___________________________________________________________________

Added: svn:eol-style

Added: trunk/LayoutTests/fast/css/bug4860-absolute-inline-child-inherits-alignment-expected.png


(Binary files differ)
Property changes on: trunk/LayoutTests/fast/css/bug4860-absolute-inline-child-inherits-alignment-expected.png ___________________________________________________________________

Added: svn:mime-type

Added: trunk/LayoutTests/fast/css/bug4860-absolute-inline-child-inherits-alignment-expected.txt (0 => 94492)


--- trunk/LayoutTests/fast/css/bug4860-absolute-inline-child-inherits-alignment-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/css/bug4860-absolute-inline-child-inherits-alignment-expected.txt	2011-09-03 18:28:57 UTC (rev 94492)
@@ -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
+layer at (8,8) size 627x200
+  RenderBlock (relative positioned) {DIV} at (0,0) size 627x200 [bgcolor=#0000FF]
+layer at (75,8) size 501x200
+  RenderBlock (positioned) {DIV} at (67,0) size 501x200 [bgcolor=#FF0000]
Property changes on: trunk/LayoutTests/fast/css/bug4860-absolute-inline-child-inherits-alignment-expected.txt
___________________________________________________________________

Added: svn:eol-style

Added: trunk/LayoutTests/fast/css/bug4860-absolute-inline-child-inherits-alignment.html (0 => 94492)


--- trunk/LayoutTests/fast/css/bug4860-absolute-inline-child-inherits-alignment.html	                        (rev 0)
+++ trunk/LayoutTests/fast/css/bug4860-absolute-inline-child-inherits-alignment.html	2011-09-03 18:28:57 UTC (rev 94492)
@@ -0,0 +1,20 @@
+<html>
+<head>
+    <style type="text/css">
+        body {text-align:center;}
+        body * {
+            width: 80%;
+        }
+        body > div {background: blue;}
+        body > div > div {background: red;}
+    </style>
+</head>
+<!--A block with an inline display type inherits alignment from its parent.
+    The red block should be centred.-->
+ <body>
+  <div style="position:relative;padding-bottom:200px;">
+   <div style="height: 100%;position:absolute; display: inline-block;">
+   </div>
+  </div>
+ </body>
+</html>
Property changes on: trunk/LayoutTests/fast/css/bug4860-absolute-inline-child-inherits-alignment.html
___________________________________________________________________

Added: svn:eol-style

Added: trunk/LayoutTests/fast/inline/absolute-positioned-block-in-centred-block-expected.png


(Binary files differ)
Property changes on: trunk/LayoutTests/fast/inline/absolute-positioned-block-in-centred-block-expected.png ___________________________________________________________________

Added: svn:mime-type

Added: trunk/LayoutTests/fast/inline/absolute-positioned-block-in-centred-block-expected.txt (0 => 94492)


--- trunk/LayoutTests/fast/inline/absolute-positioned-block-in-centred-block-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/inline/absolute-positioned-block-in-centred-block-expected.txt	2011-09-03 18:28:57 UTC (rev 94492)
@@ -0,0 +1,8 @@
+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 784x0
+layer at (-142,540) size 200x50 backgroundClip at (0,0) size 800x600 clip at (0,0) size 800x600 outlineClip at (0,0) size 800x600
+  RenderBlock (positioned) {DIV} at (-142,540) size 200x50 [bgcolor=#0000FF]
Property changes on: trunk/LayoutTests/fast/inline/absolute-positioned-block-in-centred-block-expected.txt
___________________________________________________________________

Added: svn:eol-style

Added: trunk/LayoutTests/fast/inline/absolute-positioned-block-in-centred-block.html (0 => 94492)


--- trunk/LayoutTests/fast/inline/absolute-positioned-block-in-centred-block.html	                        (rev 0)
+++ trunk/LayoutTests/fast/inline/absolute-positioned-block-in-centred-block.html	2011-09-03 18:28:57 UTC (rev 94492)
@@ -0,0 +1,12 @@
+<html>
+<head>
+<!--An absolute positioned block should not obey the alignment of its parent block.
+    The blue block should be 150 pixels off the left of the page.
+    https://bugs.webkit.org/show_bug.cgi?id=4860-->
+</head>
+<body>
+<div align="center">
+<div style="position:absolute; bottom:10px; width:200px; height:50px; margin-left:-150px; background:blue;"></div>
+</div>
+
+</body></html>
\ No newline at end of file
Property changes on: trunk/LayoutTests/fast/inline/absolute-positioned-block-in-centred-block.html
___________________________________________________________________

Added: svn:eol-style

Added: trunk/LayoutTests/fast/inline/absolute-positioned-inline-in-centred-block-expected.png


(Binary files differ)
Property changes on: trunk/LayoutTests/fast/inline/absolute-positioned-inline-in-centred-block-expected.png ___________________________________________________________________

Added: svn:mime-type

Added: trunk/LayoutTests/fast/inline/absolute-positioned-inline-in-centred-block-expected.txt (0 => 94492)


--- trunk/LayoutTests/fast/inline/absolute-positioned-inline-in-centred-block-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/inline/absolute-positioned-inline-in-centred-block-expected.txt	2011-09-03 18:28:57 UTC (rev 94492)
@@ -0,0 +1,10 @@
+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 784x0
+layer at (101,562) size 297x28
+  RenderBlock (positioned) {FONT} at (101,562) size 297x28
+    RenderText {#text} at (0,0) size 297x27
+      text run at (0,0) width 297: "Hello World, And Stuff!"
Property changes on: trunk/LayoutTests/fast/inline/absolute-positioned-inline-in-centred-block-expected.txt
___________________________________________________________________

Added: svn:eol-style

Added: trunk/LayoutTests/fast/inline/absolute-positioned-inline-in-centred-block.html (0 => 94492)


--- trunk/LayoutTests/fast/inline/absolute-positioned-inline-in-centred-block.html	                        (rev 0)
+++ trunk/LayoutTests/fast/inline/absolute-positioned-inline-in-centred-block.html	2011-09-03 18:28:57 UTC (rev 94492)
@@ -0,0 +1,11 @@
+<html>
+<head>
+<!-- An absolute-positioned inline element, with no leading text, should still obey the alignment of its parent block.
+    'Hello World, And Stuff!' should be aligned 150 pixels to the left of the center.
+    https://bugs.webkit.org/show_bug.cgi?id=4860-->
+</head>
+<body>
+<div align="center">
+<font style="font-size:24px; font-variant:small-caps;letter-spacing:2px; position:absolute; bottom:10px; margin-left:-150px">Hello World, And Stuff!</font>
+</div>
+</body></html>
\ No newline at end of file
Property changes on: trunk/LayoutTests/fast/inline/absolute-positioned-inline-in-centred-block.html
___________________________________________________________________

Added: svn:eol-style

Modified: trunk/LayoutTests/platform/chromium-linux/fast/repaint/block-layout-inline-children-float-positioned-expected.png


(Binary files differ)

Modified: trunk/LayoutTests/platform/chromium-linux/fast/repaint/block-layout-inline-children-float-positioned-expected.txt (94491 => 94492)


--- trunk/LayoutTests/platform/chromium-linux/fast/repaint/block-layout-inline-children-float-positioned-expected.txt	2011-09-03 18:18:04 UTC (rev 94491)
+++ trunk/LayoutTests/platform/chromium-linux/fast/repaint/block-layout-inline-children-float-positioned-expected.txt	2011-09-03 18:28:57 UTC (rev 94492)
@@ -14,7 +14,7 @@
           RenderBlock (floating) {SPAN} at (324,1) size 277x20
             RenderText {#text} at (0,0) size 277x19
               text run at (0,0) width 277: "the quick brown fox jumped over the lazy dog"
-layer at (1,37) size 277x20
-  RenderBlock (positioned) {SPAN} at (1,37) size 277x20
+layer at (162,37) size 277x20
+  RenderBlock (positioned) {SPAN} at (162,37) size 277x20
     RenderText {#text} at (0,0) size 277x19
       text run at (0,0) width 277: "the quick brown fox jumped over the lazy dog"

Modified: trunk/LayoutTests/platform/chromium-win/fast/css/absolute-child-with-percent-height-inside-relative-parent-expected.png


(Binary files differ)

Modified: trunk/Source/WebCore/ChangeLog (94491 => 94492)


--- trunk/Source/WebCore/ChangeLog	2011-09-03 18:18:04 UTC (rev 94491)
+++ trunk/Source/WebCore/ChangeLog	2011-09-03 18:28:57 UTC (rev 94492)
@@ -1,3 +1,39 @@
+2011-08-27  Robert Hogan  <[email protected]>
+
+        div align="center" rendering problem
+        https://bugs.webkit.org/show_bug.cgi?id=4860
+
+        Reviewed by David Hyatt.
+
+        When an inline element with absolute position was the sole or first child of a render block with
+        centred alignment, it wasn't obeying its parent's alignment. However it would obey the
+        alignment if it was preceded by some text. The problem was that the element's render object
+        was getting skipped as leading white space, so it was not included in a normal line block in
+        a bidi run. Instead, its position was getting set by RenderBlockLineLayout::setStaticPositions()
+        which does not pay attention to alignment. Preceding the element with some text allowed the object
+        to get included in a Bidi run and so get a linebox which would get properly aligned.
+
+        The fix is to get RenderBlockLineLayout::setStaticPositions() to obey the alignment specified by
+        the object's container. This allows WebKit to get the same result on the test as Firefox and IE.
+        Opera has the same bug as unpatched WebKit.
+
+        Tests: fast/css/bug4860-absolute-block-child-does-not-inherit-alignment.html
+               - Ensure positioned block elements inherit alignment.
+               fast/css/bug4860-absolute-inline-child-inherits-alignment.html
+               - Ensure positioned inline elements inherit alignment.
+               fast/inline/absolute-positioned-inline-in-centred-block.html
+               - Ensure positioned inline element that's the sole or first child of a rendered block
+                 obeys parents alignment.
+               fast/inline/absolute-positioned-block-in-centred-block.html
+               - As above, but a positioned block should not inherit alignment.
+
+        * rendering/RenderBlock.h:
+        * rendering/RenderBlockLineLayout.cpp:
+        (WebCore::RenderBlock::updateLogicalWidthForAlignment):
+        (WebCore::RenderBlock::computeInlineDirectionPositionsForLine): Move the alignment check to updateLogicalWidthForAlignment.
+        (WebCore::setStaticPositions): use startAlignedOffsetForLine and use startAlignedOffsetForBlock
+        (WebCore::RenderBlock::startAlignedOffsetForLine): New function, find the aligned offset using updateLogicalWidthForAlignment
+
 2011-09-03  Andreas Kling  <[email protected]>
 
         Remove two unused functions from Element.

Modified: trunk/Source/WebCore/rendering/RenderBlock.h (94491 => 94492)


--- trunk/Source/WebCore/rendering/RenderBlock.h	2011-09-03 18:18:04 UTC (rev 94491)
+++ trunk/Source/WebCore/rendering/RenderBlock.h	2011-09-03 18:28:57 UTC (rev 94492)
@@ -129,6 +129,7 @@
     LayoutUnit logicalRightOffsetForLine(LayoutUnit position, bool firstLine) const { return logicalRightOffsetForLine(position, logicalRightOffsetForContent(), firstLine); }
     LayoutUnit logicalLeftOffsetForLine(LayoutUnit position, bool firstLine) const { return logicalLeftOffsetForLine(position, logicalLeftOffsetForContent(), firstLine); }
     LayoutUnit startOffsetForLine(LayoutUnit position, bool firstLine) const { return style()->isLeftToRightDirection() ? logicalLeftOffsetForLine(position, firstLine) : logicalRightOffsetForLine(position, firstLine); }
+    LayoutUnit startAlignedOffsetForLine(RenderBox* child, LayoutUnit position, bool firstLine);
     LayoutUnit textIndentOffset() const;
 
     virtual VisiblePosition positionForPoint(const LayoutPoint&);
@@ -223,6 +224,8 @@
     LayoutUnit collapsedMarginBeforeForChild(RenderBox* child) const;
     LayoutUnit collapsedMarginAfterForChild(RenderBox* child) const;
 
+    void updateLogicalWidthForAlignment(const ETextAlign&, BidiRun* trailingSpaceRun, float& logicalLeft, float& totalLogicalWidth, float& availableLogicalWidth, int expansionOpportunityCount);
+
     virtual void updateFirstLetter();
 
     class MarginValues {

Modified: trunk/Source/WebCore/rendering/RenderBlockLineLayout.cpp (94491 => 94492)


--- trunk/Source/WebCore/rendering/RenderBlockLineLayout.cpp	2011-09-03 18:18:04 UTC (rev 94491)
+++ trunk/Source/WebCore/rendering/RenderBlockLineLayout.cpp	2011-09-03 18:28:57 UTC (rev 94492)
@@ -549,6 +549,57 @@
     }
 }
 
+void RenderBlock::updateLogicalWidthForAlignment(const ETextAlign& textAlign, BidiRun* trailingSpaceRun, float& logicalLeft, float& totalLogicalWidth, float& availableLogicalWidth, int expansionOpportunityCount)
+{
+    // Armed with the total width of the line (without justification),
+    // we now examine our text-align property in order to determine where to position the
+    // objects horizontally. The total width of the line can be increased if we end up
+    // justifying text.
+    switch (textAlign) {
+    case LEFT:
+    case WEBKIT_LEFT:
+        updateLogicalWidthForLeftAlignedBlock(style()->isLeftToRightDirection(), trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth);
+        break;
+    case JUSTIFY:
+        adjustInlineDirectionLineBounds(expansionOpportunityCount, logicalLeft, availableLogicalWidth);
+        if (expansionOpportunityCount) {
+            if (trailingSpaceRun) {
+                totalLogicalWidth -= trailingSpaceRun->m_box->logicalWidth();
+                trailingSpaceRun->m_box->setLogicalWidth(0);
+            }
+            break;
+        }
+        // fall through
+    case TAAUTO:
+        // for right to left fall through to right aligned
+        if (style()->isLeftToRightDirection()) {
+            if (totalLogicalWidth > availableLogicalWidth && trailingSpaceRun)
+                trailingSpaceRun->m_box->setLogicalWidth(max<float>(0, trailingSpaceRun->m_box->logicalWidth() - totalLogicalWidth + availableLogicalWidth));
+            break;
+        }
+    case RIGHT:
+    case WEBKIT_RIGHT:
+        updateLogicalWidthForRightAlignedBlock(style()->isLeftToRightDirection(), trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth);
+        break;
+    case CENTER:
+    case WEBKIT_CENTER:
+        updateLogicalWidthForCenterAlignedBlock(style()->isLeftToRightDirection(), trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth);
+        break;
+    case TASTART:
+        if (style()->isLeftToRightDirection())
+            updateLogicalWidthForLeftAlignedBlock(style()->isLeftToRightDirection(), trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth);
+        else
+            updateLogicalWidthForRightAlignedBlock(style()->isLeftToRightDirection(), trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth);
+        break;
+    case TAEND:
+        if (style()->isLeftToRightDirection())
+            updateLogicalWidthForRightAlignedBlock(style()->isLeftToRightDirection(), trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth);
+        else
+            updateLogicalWidthForLeftAlignedBlock(style()->isLeftToRightDirection(), trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth);
+        break;
+    }
+}
+
 void RenderBlock::computeInlineDirectionPositionsForLine(RootInlineBox* lineBox, const LineInfo& lineInfo, BidiRun* firstRun, BidiRun* trailingSpaceRun, bool reachedEnd,
                                                          GlyphOverflowAndFallbackFontsMap& textBoxDataMap, VerticalPositionCache& verticalPositionCache)
 {
@@ -605,53 +656,7 @@
         expansionOpportunityCount--;
     }
 
-    // Armed with the total width of the line (without justification),
-    // we now examine our text-align property in order to determine where to position the
-    // objects horizontally.  The total width of the line can be increased if we end up
-    // justifying text.
-    switch (textAlign) {
-        case LEFT:
-        case WEBKIT_LEFT:
-            updateLogicalWidthForLeftAlignedBlock(style()->isLeftToRightDirection(), trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth);
-            break;
-        case JUSTIFY:
-            adjustInlineDirectionLineBounds(expansionOpportunityCount, logicalLeft, availableLogicalWidth);
-            if (expansionOpportunityCount) {
-                if (trailingSpaceRun) {
-                    totalLogicalWidth -= trailingSpaceRun->m_box->logicalWidth();
-                    trailingSpaceRun->m_box->setLogicalWidth(0);
-                }
-                break;
-            }
-            // fall through
-        case TAAUTO:
-            // for right to left fall through to right aligned
-            if (style()->isLeftToRightDirection()) {
-                if (totalLogicalWidth > availableLogicalWidth && trailingSpaceRun)
-                    trailingSpaceRun->m_box->setLogicalWidth(max<float>(0, trailingSpaceRun->m_box->logicalWidth() - totalLogicalWidth + availableLogicalWidth));
-                break;
-            }
-        case RIGHT:
-        case WEBKIT_RIGHT:
-            updateLogicalWidthForRightAlignedBlock(style()->isLeftToRightDirection(), trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth);
-            break;
-        case CENTER:
-        case WEBKIT_CENTER:
-            updateLogicalWidthForCenterAlignedBlock(style()->isLeftToRightDirection(), trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth);
-            break;
-        case TASTART:
-            if (style()->isLeftToRightDirection())
-                updateLogicalWidthForLeftAlignedBlock(style()->isLeftToRightDirection(), trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth);
-            else
-                updateLogicalWidthForRightAlignedBlock(style()->isLeftToRightDirection(), trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth);
-            break;
-        case TAEND:
-            if (style()->isLeftToRightDirection())
-                updateLogicalWidthForRightAlignedBlock(style()->isLeftToRightDirection(), trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth);
-            else
-                updateLogicalWidthForLeftAlignedBlock(style()->isLeftToRightDirection(), trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth);
-            break;
-    }
+    updateLogicalWidthForAlignment(textAlign, trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth, expansionOpportunityCount);
 
     computeExpansionForJustifiedText(firstRun, trailingSpaceRun, expansionOpportunities, expansionOpportunityCount, totalLogicalWidth, availableLogicalWidth);
 
@@ -711,12 +716,12 @@
         // A relative positioned inline encloses us. In this case, we also have to determine our
         // position as though we were an inline. Set |staticInlinePosition| and |staticBlockPosition| on the relative positioned
         // inline so that we can obtain the value later.
-        toRenderInline(containerBlock)->layer()->setStaticInlinePosition(block->startOffsetForLine(blockHeight, false));
+        toRenderInline(containerBlock)->layer()->setStaticInlinePosition(block->startAlignedOffsetForLine(child, blockHeight, false));
         toRenderInline(containerBlock)->layer()->setStaticBlockPosition(blockHeight);
     }
 
     if (child->style()->isOriginalDisplayInlineType())
-        child->layer()->setStaticInlinePosition(block->startOffsetForLine(blockHeight, false));
+        child->layer()->setStaticInlinePosition(block->startAlignedOffsetForLine(child, blockHeight, false));
     else
         child->layer()->setStaticInlinePosition(block->borderAndPaddingStart());
     child->layer()->setStaticBlockPosition(blockHeight);
@@ -2598,4 +2603,21 @@
     return true;
 }
 
+LayoutUnit RenderBlock::startAlignedOffsetForLine(RenderBox* child, LayoutUnit position, bool firstLine)
+{
+    ETextAlign textAlign = style()->textAlign();
+
+    if (textAlign == TAAUTO)
+        return startOffsetForLine(position, firstLine);
+
+    // updateLogicalWidthForAlignment() handles the direction of the block so no need to consider it here
+    float logicalLeft;
+    float availableLogicalWidth;
+    logicalLeft = logicalLeftOffsetForLine(logicalHeight(), false);
+    availableLogicalWidth = logicalRightOffsetForLine(logicalHeight(), false) - logicalLeft;
+    float totalLogicalWidth = logicalWidthForChild(child);
+    updateLogicalWidthForAlignment(textAlign, 0l, logicalLeft, totalLogicalWidth, availableLogicalWidth, 0);
+    return logicalLeft;
 }
+
+}
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to