[SCM] WebKit Debian packaging branch, debian/experimental, updated. upstream/1.3.3-9427-gc2be6fc

hyatt at apple.com hyatt at apple.com
Wed Dec 22 16:08:55 UTC 2010


The following commit has been merged in the debian/experimental branch:
commit 5e48ff5eb8bf1895943293f2ba0a698ed63e1842
Author: hyatt at apple.com <hyatt at apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Fri Nov 19 00:43:29 2010 +0000

    https://bugs.webkit.org/show_bug.cgi?id=49717
    
    Reviewed by Dan Bernstein.
    
    Implement better behavior for the logical height and block direction spacing of ruby text and ruby
    base text.
    
    Added six new tests: ruby-auto-line-expansion.html (one version for each of the four writing modes) to
    test ruby text accommodation and quirks-mode-ruby-spacing.html / quirks-mode-ruby-spacing-bt.html to test
    that ruby doesn't reset line-height.
    
    * css/html.css:
    Remove the line-height:normal rule for <ruby>  This behavior was incorrect, since a <ruby> on a line
    by itself in quirks mode would cause the overall line-height of the enclosing block to not be honored.
    
    * rendering/InlineBox.h:
    (WebCore::InlineBox::adjustBlockDirectionPosition):
    Add adjustBlockDirectionPosition as a shorthand for calling adjustPosition with the correct delta (x or y)
    depending on orientation.
    
    * rendering/InlineFlowBox.cpp:
    (WebCore::InlineFlowBox::placeBoxesInBlockDirection):
    placeBoxesInBlockDirection now looks for Ruby runs, and when it encounters them it sets a flag, containsRuby,
    to true.  This flag is stored as a bit on the RootInlineBox and lets us know whether we need to do a later
    crawl of the line boxes after they are positioned to see if all the Ruby texts fit or not.
    
    Add the notion of a lineTop and lineBottom that include margins, since flipped lines writing modes (lr and bt)
    mess up the flipping otherwise.  These new variables are lineTopIncludingMargins and lineBottomIncludingMargins.
    This is only relevant for replaced elements, since the block direction margins of inline flows are always 0.
    
    Because RenderRubyRun is implemented as an inline-block (this is probably not a behavior we want to keep long-term),
    the line-height is propagated into the inline-block, and it ends up being counted as part of the overall lineTop
    and lineBottom since it is inside the inline-block's height.  To prevent this from happening, we have to fake it
    as though RenderRubyRun was just a normal inline.  We look at the line boxes of the ruby base and we push lineTop/Bottom
    in by the leading on either side so that it isn't counted as part of lineTop and lineBottom.  This enables the later
    Ruby code that examines the spacing between lines to not be fooled into thinking it can't intrude into an inline-block's
    interior on a previous line.
    
    (WebCore::InlineFlowBox::computeBlockDirectionRubyAdjustment):
    This function computes the amount that a line box has to be moved in order to accommodate all of the Ruby texts on the
    line.  With tb and rl writing modes, the Ruby is trying to fit between the current line and a previous line, and so
    we're checking some highest previous position and computing the amount we have to move.
    
    For lr and bt writing modes, the lines are flipped relative to the block direction, so we are computing how much we have
    to move the *following* line based off a lowest position.
    
    In all writing modes we will allow Ruby text to intrude into the padding of a block.
    
    * rendering/InlineFlowBox.h:
    * rendering/RenderBlock.cpp:
    (WebCore::RenderBlock::layoutBlockChildren):
    Ruby text is now considered a special child that should be excluded from normal layout, margin collapsing and height
    computations.  Rename the layoutLegend function to be more generalized and make it apply to both Ruby text and to
    legends.  This means that the RenderRubyRun computes its logical height without any regard for the ruby text.
    
    * rendering/RenderBlock.h:
    (WebCore::RenderBlock::layoutSpecialExcludedChild):
    layoutSpecialExcludedChild is the new version of layoutLegend and it is implemented by RenderFieldset and RenderRubyRun.
    
    * rendering/RenderBlockLineLayout.cpp:
    (WebCore::RenderBlock::layoutInlineChildren):
    When we hit the end of line layout, if we're in lr or bt writing modes, we have to potentially grow the height of the block
    to accommodate ruby text along the bottom side of the line.  We call computeBlockDirectionRubyAdjustment here in flipped lines
    writing mode only, and then we increase the logical height of the block if necessary.
    
    * rendering/RenderFieldset.cpp:
    (WebCore::RenderFieldset::layoutSpecialExcludedChild):
    * rendering/RenderFieldset.h:
    No changes here other than the function rename.
    
    * rendering/RenderRubyRun.cpp:
    (WebCore::RenderRubyRun::staticCreateRubyRun):
    Remove the hack that locked RenderRubyRun's writing mode to tb or rl, since it didn't really work anyway, and it isn't necessary
    now that RenderRubyRun has its own layout method.
    
    (WebCore::RenderRubyRun::layoutSpecialExcludedChild):
    RenderRubyRun lays out the ruby text here but doesn't do anything with its placement yet.  We wait until the base is positioned
    and then handled positioning the RenderRubyText at the end of RenderRubyRun's layout method.
    
    (WebCore::RenderRubyRun::layout):
    * rendering/RenderRubyRun.h:
    RenderRubyRun now has its own layout method that calls the base class to get the RenderRubyBase positioned and then moves the
    RenderRubyText such that its bottommost line box's bottom and the RenderRubyBase's topmost line box's line top are flush with
    one another.  The RenderRubyText will commonly be positioned at a negative coordinate now and spill out of the RenderRubyRun
    as overflow.
    
    * rendering/RootInlineBox.cpp:
    (WebCore::RootInlineBox::RootInlineBox):
    Added the m_containsRuby bit for performance to avoid the extra pass to try to accommodate ruby texts when none are present.
    
    (WebCore::RootInlineBox::adjustPosition):
    Fixed a bug in adjustPosition where the lineTop, lineBottom and blockLogicalHeight values were always being augmented by dy
    even in vertical writing modes (where dx needed to be used instead).
    
    WebCore:
    
    (WebCore::RootInlineBox::alignBoxesInBlockDirection):
    (WebCore::RootInlineBox::blockDirectionRubyAdjustment):
    * rendering/RootInlineBox.h:
    (WebCore::RootInlineBox::containsRuby):
    RootInlineBox now calls blockDirectionRubyAdjustment to determine the amount of additional spacing that has to exist between
    the lines in order to accommodate all Ruby texts, and then it does adjustPosition to move the new line by the amount required.
    
    LayoutTests:
    
    (WebCore::RootInlineBox::alignBoxesInBlockDirection):
    (WebCore::RootInlineBox::blockDirectionRubyAdjustment):
    * rendering/RootInlineBox.h:
    (WebCore::RootInlineBox::containsRuby):
    RootInlineBox now calls blockDirectionRubyAdjustment to determine the amount of additional spacing that has to exist between
    the lines in order to accommodate all Ruby texts, and then it does adjustPosition to move the new line by the amount required.
    
    * fast/ruby/ruby-line-height-expected.txt:
    * platform/mac/fast/blockflow/japanese-ruby-horizontal-bt-expected.checksum:
    * platform/mac/fast/blockflow/japanese-ruby-horizontal-bt-expected.png:
    * platform/mac/fast/blockflow/japanese-ruby-horizontal-bt-expected.txt:
    * platform/mac/fast/blockflow/japanese-ruby-vertical-lr-expected.checksum:
    * platform/mac/fast/blockflow/japanese-ruby-vertical-lr-expected.png:
    * platform/mac/fast/blockflow/japanese-ruby-vertical-lr-expected.txt:
    * platform/mac/fast/blockflow/japanese-ruby-vertical-rl-expected.checksum:
    * platform/mac/fast/blockflow/japanese-ruby-vertical-rl-expected.png:
    * platform/mac/fast/blockflow/japanese-ruby-vertical-rl-expected.txt:
    * platform/mac/fast/repaint/repaint-across-writing-mode-boundary-expected.checksum:
    * platform/mac/fast/repaint/repaint-across-writing-mode-boundary-expected.png:
    * platform/mac/fast/ruby/quirks-mode-ruby-spacing-bt-expected.checksum: Added.
    * platform/mac/fast/ruby/quirks-mode-ruby-spacing-bt-expected.png: Added.
    * platform/mac/fast/ruby/quirks-mode-ruby-spacing-bt-expected.txt: Added.
    * platform/mac/fast/ruby/quirks-mode-ruby-spacing-expected.checksum: Added.
    * platform/mac/fast/ruby/quirks-mode-ruby-spacing-expected.png: Added.
    * platform/mac/fast/ruby/quirks-mode-ruby-spacing-expected.txt: Added.
    * platform/mac/fast/ruby/ruby-auto-line-expansion-bt-expected.checksum: Added.
    * platform/mac/fast/ruby/ruby-auto-line-expansion-bt-expected.png: Added.
    * platform/mac/fast/ruby/ruby-auto-line-expansion-bt-expected.txt: Added.
    * platform/mac/fast/ruby/ruby-auto-line-expansion-expected.checksum: Added.
    * platform/mac/fast/ruby/ruby-auto-line-expansion-expected.png: Added.
    * platform/mac/fast/ruby/ruby-auto-line-expansion-expected.txt: Added.
    * platform/mac/fast/ruby/ruby-auto-line-expansion-lr-expected.checksum: Added.
    * platform/mac/fast/ruby/ruby-auto-line-expansion-lr-expected.png: Added.
    * platform/mac/fast/ruby/ruby-auto-line-expansion-lr-expected.txt: Added.
    * platform/mac/fast/ruby/ruby-auto-line-expansion-rl-expected.checksum: Added.
    * platform/mac/fast/ruby/ruby-auto-line-expansion-rl-expected.png: Added.
    * platform/mac/fast/ruby/ruby-auto-line-expansion-rl-expected.txt: Added.
    * platform/mac/fast/ruby/ruby-beforeafter-expected.txt:
    * platform/mac/fast/ruby/ruby-empty-rt-expected.txt:
    * platform/mac/fast/ruby/ruby-length-expected.txt:
    * platform/mac/fast/ruby/ruby-run-break-expected.checksum:
    * platform/mac/fast/ruby/ruby-run-break-expected.png:
    * platform/mac/fast/ruby/ruby-run-break-expected.txt:
    * platform/mac/fast/ruby/ruby-runs-expected.txt:
    * platform/mac/fast/ruby/ruby-runs-spans-expected.txt:
    * platform/mac/fast/ruby/ruby-simple-expected.txt:
    * platform/mac/fast/ruby/ruby-simple-rp-expected.txt:
    * platform/mac/fast/ruby/ruby-trailing-expected.txt:
    * platform/mac/fast/ruby/rubyDOM-insert-rt-expected.txt:
    * platform/mac/fast/ruby/rubyDOM-insert-text1-expected.txt:
    * platform/mac/fast/ruby/rubyDOM-insert-text2-expected.txt:
    * platform/mac/fast/ruby/rubyDOM-insert-text3-expected.txt:
    * platform/mac/fast/ruby/rubyDOM-remove-rt1-expected.txt:
    * platform/mac/fast/ruby/rubyDOM-remove-rt2-expected.txt:
    * platform/mac/fast/ruby/rubyDOM-remove-text1-expected.txt:
    * platform/mac/fast/ruby/rubyDOM-remove-text2-expected.txt:
    
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@72347 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog
index a51afba..c354346 100644
--- a/LayoutTests/ChangeLog
+++ b/LayoutTests/ChangeLog
@@ -1,3 +1,156 @@
+2010-11-18  Dave Hyatt  <hyatt at apple.com>
+
+        Reviewed by Dan Bernstein.
+
+        https://bugs.webkit.org/show_bug.cgi?id=49717
+        
+        Implement better behavior for the logical height and block direction spacing of ruby text and ruby
+        base text.
+
+        Added six new tests: ruby-auto-line-expansion.html (one version for each of the four writing modes) to
+        test ruby text accommodation and quirks-mode-ruby-spacing.html / quirks-mode-ruby-spacing-bt.html to test
+        that ruby doesn't reset line-height.
+
+        * css/html.css:
+        Remove the line-height:normal rule for <ruby>  This behavior was incorrect, since a <ruby> on a line
+        by itself in quirks mode would cause the overall line-height of the enclosing block to not be honored.
+
+        * rendering/InlineBox.h:
+        (WebCore::InlineBox::adjustBlockDirectionPosition):
+        Add adjustBlockDirectionPosition as a shorthand for calling adjustPosition with the correct delta (x or y)
+        depending on orientation.
+        
+        * rendering/InlineFlowBox.cpp:
+        (WebCore::InlineFlowBox::placeBoxesInBlockDirection):
+        placeBoxesInBlockDirection now looks for Ruby runs, and when it encounters them it sets a flag, containsRuby,
+        to true.  This flag is stored as a bit on the RootInlineBox and lets us know whether we need to do a later
+        crawl of the line boxes after they are positioned to see if all the Ruby texts fit or not.
+        
+        Add the notion of a lineTop and lineBottom that include margins, since flipped lines writing modes (lr and bt)
+        mess up the flipping otherwise.  These new variables are lineTopIncludingMargins and lineBottomIncludingMargins.
+        This is only relevant for replaced elements, since the block direction margins of inline flows are always 0.
+        
+        Because RenderRubyRun is implemented as an inline-block (this is probably not a behavior we want to keep long-term),
+        the line-height is propagated into the inline-block, and it ends up being counted as part of the overall lineTop
+        and lineBottom since it is inside the inline-block's height.  To prevent this from happening, we have to fake it
+        as though RenderRubyRun was just a normal inline.  We look at the line boxes of the ruby base and we push lineTop/Bottom
+        in by the leading on either side so that it isn't counted as part of lineTop and lineBottom.  This enables the later
+        Ruby code that examines the spacing between lines to not be fooled into thinking it can't intrude into an inline-block's
+        interior on a previous line.
+
+        (WebCore::InlineFlowBox::computeBlockDirectionRubyAdjustment):
+        This function computes the amount that a line box has to be moved in order to accommodate all of the Ruby texts on the
+        line.  With tb and rl writing modes, the Ruby is trying to fit between the current line and a previous line, and so
+        we're checking some highest previous position and computing the amount we have to move.
+        
+        For lr and bt writing modes, the lines are flipped relative to the block direction, so we are computing how much we have
+        to move the *following* line based off a lowest position.
+        
+        In all writing modes we will allow Ruby text to intrude into the padding of a block.
+        
+        * rendering/InlineFlowBox.h:
+        * rendering/RenderBlock.cpp:
+        (WebCore::RenderBlock::layoutBlockChildren):
+        Ruby text is now considered a special child that should be excluded from normal layout, margin collapsing and height
+        computations.  Rename the layoutLegend function to be more generalized and make it apply to both Ruby text and to
+        legends.  This means that the RenderRubyRun computes its logical height without any regard for the ruby text.
+
+        * rendering/RenderBlock.h:
+        (WebCore::RenderBlock::layoutSpecialExcludedChild):
+        layoutSpecialExcludedChild is the new version of layoutLegend and it is implemented by RenderFieldset and RenderRubyRun.
+
+        * rendering/RenderBlockLineLayout.cpp:
+        (WebCore::RenderBlock::layoutInlineChildren):
+        When we hit the end of line layout, if we're in lr or bt writing modes, we have to potentially grow the height of the block
+        to accommodate ruby text along the bottom side of the line.  We call computeBlockDirectionRubyAdjustment here in flipped lines
+        writing mode only, and then we increase the logical height of the block if necessary.
+
+        * rendering/RenderFieldset.cpp:
+        (WebCore::RenderFieldset::layoutSpecialExcludedChild):
+        * rendering/RenderFieldset.h:
+        No changes here other than the function rename.
+
+        * rendering/RenderRubyRun.cpp:
+        (WebCore::RenderRubyRun::staticCreateRubyRun):
+        Remove the hack that locked RenderRubyRun's writing mode to tb or rl, since it didn't really work anyway, and it isn't necessary
+        now that RenderRubyRun has its own layout method.
+    
+        (WebCore::RenderRubyRun::layoutSpecialExcludedChild):
+        RenderRubyRun lays out the ruby text here but doesn't do anything with its placement yet.  We wait until the base is positioned
+        and then handled positioning the RenderRubyText at the end of RenderRubyRun's layout method. 
+
+        (WebCore::RenderRubyRun::layout):
+        * rendering/RenderRubyRun.h:
+        RenderRubyRun now has its own layout method that calls the base class to get the RenderRubyBase positioned and then moves the
+        RenderRubyText such that its bottommost line box's bottom and the RenderRubyBase's topmost line box's line top are flush with
+        one another.  The RenderRubyText will commonly be positioned at a negative coordinate now and spill out of the RenderRubyRun
+        as overflow.
+
+        * rendering/RootInlineBox.cpp:
+        (WebCore::RootInlineBox::RootInlineBox):
+        Added the m_containsRuby bit for performance to avoid the extra pass to try to accommodate ruby texts when none are present.
+
+        (WebCore::RootInlineBox::adjustPosition):
+        Fixed a bug in adjustPosition where the lineTop, lineBottom and blockLogicalHeight values were always being augmented by dy
+        even in vertical writing modes (where dx needed to be used instead).
+
+        (WebCore::RootInlineBox::alignBoxesInBlockDirection):
+        (WebCore::RootInlineBox::blockDirectionRubyAdjustment):
+        * rendering/RootInlineBox.h:
+        (WebCore::RootInlineBox::containsRuby):
+        RootInlineBox now calls blockDirectionRubyAdjustment to determine the amount of additional spacing that has to exist between
+        the lines in order to accommodate all Ruby texts, and then it does adjustPosition to move the new line by the amount required.
+
+        * fast/ruby/ruby-line-height-expected.txt:
+        * platform/mac/fast/blockflow/japanese-ruby-horizontal-bt-expected.checksum:
+        * platform/mac/fast/blockflow/japanese-ruby-horizontal-bt-expected.png:
+        * platform/mac/fast/blockflow/japanese-ruby-horizontal-bt-expected.txt:
+        * platform/mac/fast/blockflow/japanese-ruby-vertical-lr-expected.checksum:
+        * platform/mac/fast/blockflow/japanese-ruby-vertical-lr-expected.png:
+        * platform/mac/fast/blockflow/japanese-ruby-vertical-lr-expected.txt:
+        * platform/mac/fast/blockflow/japanese-ruby-vertical-rl-expected.checksum:
+        * platform/mac/fast/blockflow/japanese-ruby-vertical-rl-expected.png:
+        * platform/mac/fast/blockflow/japanese-ruby-vertical-rl-expected.txt:
+        * platform/mac/fast/repaint/repaint-across-writing-mode-boundary-expected.checksum:
+        * platform/mac/fast/repaint/repaint-across-writing-mode-boundary-expected.png:
+        * platform/mac/fast/ruby/quirks-mode-ruby-spacing-bt-expected.checksum: Added.
+        * platform/mac/fast/ruby/quirks-mode-ruby-spacing-bt-expected.png: Added.
+        * platform/mac/fast/ruby/quirks-mode-ruby-spacing-bt-expected.txt: Added.
+        * platform/mac/fast/ruby/quirks-mode-ruby-spacing-expected.checksum: Added.
+        * platform/mac/fast/ruby/quirks-mode-ruby-spacing-expected.png: Added.
+        * platform/mac/fast/ruby/quirks-mode-ruby-spacing-expected.txt: Added.
+        * platform/mac/fast/ruby/ruby-auto-line-expansion-bt-expected.checksum: Added.
+        * platform/mac/fast/ruby/ruby-auto-line-expansion-bt-expected.png: Added.
+        * platform/mac/fast/ruby/ruby-auto-line-expansion-bt-expected.txt: Added.
+        * platform/mac/fast/ruby/ruby-auto-line-expansion-expected.checksum: Added.
+        * platform/mac/fast/ruby/ruby-auto-line-expansion-expected.png: Added.
+        * platform/mac/fast/ruby/ruby-auto-line-expansion-expected.txt: Added.
+        * platform/mac/fast/ruby/ruby-auto-line-expansion-lr-expected.checksum: Added.
+        * platform/mac/fast/ruby/ruby-auto-line-expansion-lr-expected.png: Added.
+        * platform/mac/fast/ruby/ruby-auto-line-expansion-lr-expected.txt: Added.
+        * platform/mac/fast/ruby/ruby-auto-line-expansion-rl-expected.checksum: Added.
+        * platform/mac/fast/ruby/ruby-auto-line-expansion-rl-expected.png: Added.
+        * platform/mac/fast/ruby/ruby-auto-line-expansion-rl-expected.txt: Added.
+        * platform/mac/fast/ruby/ruby-beforeafter-expected.txt:
+        * platform/mac/fast/ruby/ruby-empty-rt-expected.txt:
+        * platform/mac/fast/ruby/ruby-length-expected.txt:
+        * platform/mac/fast/ruby/ruby-run-break-expected.checksum:
+        * platform/mac/fast/ruby/ruby-run-break-expected.png:
+        * platform/mac/fast/ruby/ruby-run-break-expected.txt:
+        * platform/mac/fast/ruby/ruby-runs-expected.txt:
+        * platform/mac/fast/ruby/ruby-runs-spans-expected.txt:
+        * platform/mac/fast/ruby/ruby-simple-expected.txt:
+        * platform/mac/fast/ruby/ruby-simple-rp-expected.txt:
+        * platform/mac/fast/ruby/ruby-trailing-expected.txt:
+        * platform/mac/fast/ruby/rubyDOM-insert-rt-expected.txt:
+        * platform/mac/fast/ruby/rubyDOM-insert-text1-expected.txt:
+        * platform/mac/fast/ruby/rubyDOM-insert-text2-expected.txt:
+        * platform/mac/fast/ruby/rubyDOM-insert-text3-expected.txt:
+        * platform/mac/fast/ruby/rubyDOM-remove-rt1-expected.txt:
+        * platform/mac/fast/ruby/rubyDOM-remove-rt2-expected.txt:
+        * platform/mac/fast/ruby/rubyDOM-remove-text1-expected.txt:
+        * platform/mac/fast/ruby/rubyDOM-remove-text2-expected.txt:
+
 2010-11-18  David Levin  <levin at chromium.org>
 
         [chromium] Test baseline updates.
diff --git a/LayoutTests/fast/ruby/ruby-line-height-expected.txt b/LayoutTests/fast/ruby/ruby-line-height-expected.txt
index a8411c2..c2697e9 100644
--- a/LayoutTests/fast/ruby/ruby-line-height-expected.txt
+++ b/LayoutTests/fast/ruby/ruby-line-height-expected.txt
@@ -6,7 +6,7 @@ On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE
 PASS [object HTMLParagraphElement] is non-null.
 PASS getLineHeight('p') is "48px"
 PASS [object HTMLElement] is non-null.
-PASS getLineHeight('r') is "normal"
+FAIL getLineHeight('r') should be normal. Was 48px.
 PASS [object HTMLElement] is non-null.
 PASS getLineHeight('t') is "normal"
 PASS successfullyParsed is true
diff --git a/LayoutTests/platform/mac/fast/blockflow/japanese-ruby-horizontal-bt-expected.checksum b/LayoutTests/platform/mac/fast/blockflow/japanese-ruby-horizontal-bt-expected.checksum
index 2b9e8f5..50832c1 100644
--- a/LayoutTests/platform/mac/fast/blockflow/japanese-ruby-horizontal-bt-expected.checksum
+++ b/LayoutTests/platform/mac/fast/blockflow/japanese-ruby-horizontal-bt-expected.checksum
@@ -1 +1 @@
-abb029bd26dd5a6e0d4b11cb99f60f2a
\ No newline at end of file
+379bad77d1b1e78af23545395ec7539e
\ No newline at end of file
diff --git a/LayoutTests/platform/mac/fast/blockflow/japanese-ruby-horizontal-bt-expected.png b/LayoutTests/platform/mac/fast/blockflow/japanese-ruby-horizontal-bt-expected.png
index ce910f0..6306130 100644
Binary files a/LayoutTests/platform/mac/fast/blockflow/japanese-ruby-horizontal-bt-expected.png and b/LayoutTests/platform/mac/fast/blockflow/japanese-ruby-horizontal-bt-expected.png differ
diff --git a/LayoutTests/platform/mac/fast/blockflow/japanese-ruby-horizontal-bt-expected.txt b/LayoutTests/platform/mac/fast/blockflow/japanese-ruby-horizontal-bt-expected.txt
index ad0891a..a246625 100644
--- a/LayoutTests/platform/mac/fast/blockflow/japanese-ruby-horizontal-bt-expected.txt
+++ b/LayoutTests/platform/mac/fast/blockflow/japanese-ruby-horizontal-bt-expected.txt
@@ -1,23 +1,23 @@
 layer at (0,0) size 800x600
   RenderView at (0,0) size 800x600
-layer at (0,468) size 800x132
-  RenderBlock {HTML} at (0,0) size 800x132 [border: (10px solid #800000)]
-    RenderBody {BODY} at (18,18) size 764x96
+layer at (0,490) size 800x110
+  RenderBlock {HTML} at (0,0) size 800x110 [border: (10px solid #800000)]
+    RenderBody {BODY} at (18,18) size 764x74
       RenderText {#text} at (0,10) size 226x40
         text run at (0,10) width 226: "\x{653B}\x{6BBB} \x{6A5F}\x{52D5}\x{968A} "
       RenderRuby (inline) {RUBY} at (0,0) size 216x40
-        RenderRubyRun (anonymous) at (226,0) size 96x96
-          RenderRubyText {RT} at (0,0) size 96x36
+        RenderRubyRun (anonymous) at (226,0) size 96x60
+          RenderRubyText {RT} at (0,44) size 96x36
             RenderText {#text} at (0,6) size 96x24
               text run at (0,6) width 96: "\x{3053}\x{3046}\x{304B}\x{304F}"
-          RenderRubyBase (anonymous) at (0,36) size 96x60
+          RenderRubyBase (anonymous) at (0,0) size 96x60
             RenderText {#text} at (8,10) size 80x40
               text run at (8,10) width 80: "\x{653B}\x{6BBB}"
-        RenderRubyRun (anonymous) at (322,0) size 120x96
-          RenderRubyText {RT} at (0,0) size 120x36
+        RenderRubyRun (anonymous) at (322,0) size 120x60
+          RenderRubyText {RT} at (0,44) size 120x36
             RenderText {#text} at (0,6) size 120x24
               text run at (0,6) width 120: "\x{304D}\x{3069}\x{3046}\x{305F}\x{3044}"
-          RenderRubyBase (anonymous) at (0,36) size 120x60
+          RenderRubyBase (anonymous) at (0,0) size 120x60
             RenderText {#text} at (0,10) size 120x40
               text run at (0,10) width 120: "\x{6A5F}\x{52D5}\x{968A}"
       RenderText {#text} at (0,0) size 0x0
diff --git a/LayoutTests/platform/mac/fast/blockflow/japanese-ruby-vertical-lr-expected.checksum b/LayoutTests/platform/mac/fast/blockflow/japanese-ruby-vertical-lr-expected.checksum
index 10ec8f8..b30809a 100644
--- a/LayoutTests/platform/mac/fast/blockflow/japanese-ruby-vertical-lr-expected.checksum
+++ b/LayoutTests/platform/mac/fast/blockflow/japanese-ruby-vertical-lr-expected.checksum
@@ -1 +1 @@
-b536de010a0a8998fcce5715d2cbf8bf
\ No newline at end of file
+dca3a00532b0cbc83ae14bba62d3c7d4
\ No newline at end of file
diff --git a/LayoutTests/platform/mac/fast/blockflow/japanese-ruby-vertical-lr-expected.png b/LayoutTests/platform/mac/fast/blockflow/japanese-ruby-vertical-lr-expected.png
index c4feb0d..b51cd8c 100644
Binary files a/LayoutTests/platform/mac/fast/blockflow/japanese-ruby-vertical-lr-expected.png and b/LayoutTests/platform/mac/fast/blockflow/japanese-ruby-vertical-lr-expected.png differ
diff --git a/LayoutTests/platform/mac/fast/blockflow/japanese-ruby-vertical-lr-expected.txt b/LayoutTests/platform/mac/fast/blockflow/japanese-ruby-vertical-lr-expected.txt
index b44d8f2..d1bb540 100644
--- a/LayoutTests/platform/mac/fast/blockflow/japanese-ruby-vertical-lr-expected.txt
+++ b/LayoutTests/platform/mac/fast/blockflow/japanese-ruby-vertical-lr-expected.txt
@@ -1,23 +1,23 @@
 layer at (0,0) size 800x600
   RenderView at (0,0) size 800x600
-layer at (0,0) size 132x600
-  RenderBlock {HTML} at (0,0) size 132x600 [border: (10px solid #800000)]
-    RenderBody {BODY} at (18,18) size 96x564
+layer at (0,0) size 110x600
+  RenderBlock {HTML} at (0,0) size 110x600 [border: (10px solid #800000)]
+    RenderBody {BODY} at (18,18) size 74x564
       RenderText {#text} at (10,0) size 40x228
         text run at (10,0) width 228: "\x{653B}\x{6BBB} \x{6A5F}\x{52D5}\x{968A} "
       RenderRuby (inline) {RUBY} at (0,0) size 40x225
-        RenderRubyRun (anonymous) at (0,228) size 96x100
-          RenderRubyText {RT} at (0,0) size 36x100
+        RenderRubyRun (anonymous) at (0,228) size 60x100
+          RenderRubyText {RT} at (44,0) size 36x100
             RenderText {#text} at (6,0) size 24x100
               text run at (6,0) width 100: "\x{3053}\x{3046}\x{304B}\x{304F}"
-          RenderRubyBase (anonymous) at (36,0) size 60x100
+          RenderRubyBase (anonymous) at (0,0) size 60x100
             RenderText {#text} at (10,9) size 40x82
               text run at (10,9) width 82: "\x{653B}\x{6BBB}"
-        RenderRubyRun (anonymous) at (0,328) size 96x125
-          RenderRubyText {RT} at (0,0) size 36x125
+        RenderRubyRun (anonymous) at (0,328) size 60x125
+          RenderRubyText {RT} at (44,0) size 36x125
             RenderText {#text} at (6,0) size 24x125
               text run at (6,0) width 125: "\x{304D}\x{3069}\x{3046}\x{305F}\x{3044}"
-          RenderRubyBase (anonymous) at (36,0) size 60x125
+          RenderRubyBase (anonymous) at (0,0) size 60x125
             RenderText {#text} at (10,1) size 40x123
               text run at (10,1) width 123: "\x{6A5F}\x{52D5}\x{968A}"
       RenderText {#text} at (0,0) size 0x0
diff --git a/LayoutTests/platform/mac/fast/blockflow/japanese-ruby-vertical-rl-expected.checksum b/LayoutTests/platform/mac/fast/blockflow/japanese-ruby-vertical-rl-expected.checksum
index 671c430..6c0bb50 100644
--- a/LayoutTests/platform/mac/fast/blockflow/japanese-ruby-vertical-rl-expected.checksum
+++ b/LayoutTests/platform/mac/fast/blockflow/japanese-ruby-vertical-rl-expected.checksum
@@ -1 +1 @@
-19c108cb9b514aa7b28fc376b16a7ba8
\ No newline at end of file
+97d2a39320396bf1a273932028033a1f
\ No newline at end of file
diff --git a/LayoutTests/platform/mac/fast/blockflow/japanese-ruby-vertical-rl-expected.png b/LayoutTests/platform/mac/fast/blockflow/japanese-ruby-vertical-rl-expected.png
index 75ef35b..cfe3f03 100644
Binary files a/LayoutTests/platform/mac/fast/blockflow/japanese-ruby-vertical-rl-expected.png and b/LayoutTests/platform/mac/fast/blockflow/japanese-ruby-vertical-rl-expected.png differ
diff --git a/LayoutTests/platform/mac/fast/blockflow/japanese-ruby-vertical-rl-expected.txt b/LayoutTests/platform/mac/fast/blockflow/japanese-ruby-vertical-rl-expected.txt
index a490a6b..b237a6b 100644
--- a/LayoutTests/platform/mac/fast/blockflow/japanese-ruby-vertical-rl-expected.txt
+++ b/LayoutTests/platform/mac/fast/blockflow/japanese-ruby-vertical-rl-expected.txt
@@ -1,23 +1,23 @@
 layer at (0,0) size 800x600
   RenderView at (0,0) size 800x600
-layer at (668,0) size 132x600
-  RenderBlock {HTML} at (0,0) size 132x600 [border: (10px solid #800000)]
-    RenderBody {BODY} at (18,18) size 96x564
-      RenderText {#text} at (46,0) size 40x228
-        text run at (46,0) width 228: "\x{653B}\x{6BBB} \x{6A5F}\x{52D5}\x{968A} "
+layer at (690,0) size 110x600
+  RenderBlock {HTML} at (0,0) size 110x600 [border: (10px solid #800000)]
+    RenderBody {BODY} at (18,18) size 74x564
+      RenderText {#text} at (24,0) size 40x228
+        text run at (24,0) width 228: "\x{653B}\x{6BBB} \x{6A5F}\x{52D5}\x{968A} "
       RenderRuby (inline) {RUBY} at (0,0) size 40x225
-        RenderRubyRun (anonymous) at (0,228) size 96x100
-          RenderRubyText {RT} at (0,0) size 36x100
+        RenderRubyRun (anonymous) at (14,228) size 60x100
+          RenderRubyText {RT} at (-20,0) size 36x100
             RenderText {#text} at (6,0) size 24x100
               text run at (6,0) width 100: "\x{3053}\x{3046}\x{304B}\x{304F}"
-          RenderRubyBase (anonymous) at (36,0) size 60x100
+          RenderRubyBase (anonymous) at (0,0) size 60x100
             RenderText {#text} at (10,9) size 40x82
               text run at (10,9) width 82: "\x{653B}\x{6BBB}"
-        RenderRubyRun (anonymous) at (0,328) size 96x125
-          RenderRubyText {RT} at (0,0) size 36x125
+        RenderRubyRun (anonymous) at (14,328) size 60x125
+          RenderRubyText {RT} at (-20,0) size 36x125
             RenderText {#text} at (6,0) size 24x125
               text run at (6,0) width 125: "\x{304D}\x{3069}\x{3046}\x{305F}\x{3044}"
-          RenderRubyBase (anonymous) at (36,0) size 60x125
+          RenderRubyBase (anonymous) at (0,0) size 60x125
             RenderText {#text} at (10,1) size 40x123
               text run at (10,1) width 123: "\x{6A5F}\x{52D5}\x{968A}"
       RenderText {#text} at (0,0) size 0x0
diff --git a/LayoutTests/platform/mac/fast/ruby/quirks-mode-ruby-spacing-bt-expected.checksum b/LayoutTests/platform/mac/fast/ruby/quirks-mode-ruby-spacing-bt-expected.checksum
new file mode 100644
index 0000000..9981791
--- /dev/null
+++ b/LayoutTests/platform/mac/fast/ruby/quirks-mode-ruby-spacing-bt-expected.checksum
@@ -0,0 +1 @@
+c6d242bfe96bec83e35f2dc47b91545a
\ No newline at end of file
diff --git a/LayoutTests/platform/mac/fast/ruby/quirks-mode-ruby-spacing-bt-expected.png b/LayoutTests/platform/mac/fast/ruby/quirks-mode-ruby-spacing-bt-expected.png
new file mode 100644
index 0000000..5314d0c
Binary files /dev/null and b/LayoutTests/platform/mac/fast/ruby/quirks-mode-ruby-spacing-bt-expected.png differ
diff --git a/LayoutTests/platform/mac/fast/ruby/quirks-mode-ruby-spacing-bt-expected.txt b/LayoutTests/platform/mac/fast/ruby/quirks-mode-ruby-spacing-bt-expected.txt
new file mode 100644
index 0000000..d57ec93
--- /dev/null
+++ b/LayoutTests/platform/mac/fast/ruby/quirks-mode-ruby-spacing-bt-expected.txt
@@ -0,0 +1,83 @@
+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 (anonymous) at (0,0) size 784x36
+        RenderText {#text} at (0,0) size 767x36
+          text run at (0,0) width 618: "This test is checking to make sure that ruby elements properly inherit line-height and don't reset it. "
+          text run at (618,0) width 149: "There should be double"
+          text run at (0,18) width 208: "spacing between all lines below. "
+          text run at (208,18) width 261: "The three blocks should line up perfectly."
+      RenderBlock {DIV} at (0,36) size 784x170
+        RenderBlock {DIV} at (2,2) size 80x166 [border: (1px solid #000000)]
+          RenderText {#text} at (3,10) size 64x18
+            text run at (3,10) width 64: "Line One."
+          RenderBR {BR} at (67,14) size 0x0
+          RenderText {#text} at (3,42) size 67x18
+            text run at (3,42) width 67: "Line Two."
+          RenderBR {BR} at (70,46) size 0x0
+          RenderRuby (inline) {RUBY} at (0,0) size 74x18
+            RenderRubyRun (anonymous) at (3,67) size 74x32
+              RenderRubyText {RT} at (0,25) size 74x13
+                RenderText {#text} at (34,0) size 5x13
+                  text run at (34,0) width 5: "3"
+              RenderRubyBase (anonymous) at (0,0) size 74x32
+                RenderText {#text} at (0,7) size 74x18
+                  text run at (0,7) width 74: "Line Three."
+          RenderBR {BR} at (77,78) size 0x0
+          RenderRuby (inline) {RUBY} at (0,0) size 67x18
+            RenderRubyRun (anonymous) at (3,99) size 67x32
+              RenderRubyText {RT} at (0,25) size 67x13
+                RenderText {#text} at (31,0) size 5x13
+                  text run at (31,0) width 5: "4"
+              RenderRubyBase (anonymous) at (0,0) size 67x32
+                RenderText {#text} at (0,7) size 67x18
+                  text run at (0,7) width 67: "Line Four."
+          RenderBR {BR} at (70,110) size 0x0
+          RenderText {#text} at (3,138) size 65x18
+            text run at (3,138) width 65: "Line Five."
+        RenderText {#text} at (84,152) size 4x18
+          text run at (84,152) width 4: " "
+        RenderBlock {DIV} at (90,2) size 80x166 [border: (1px solid #000000)]
+          RenderText {#text} at (3,10) size 64x18
+            text run at (3,10) width 64: "Line One."
+          RenderBR {BR} at (67,14) size 0x0
+          RenderText {#text} at (3,42) size 67x18
+            text run at (3,42) width 67: "Line Two."
+          RenderBR {BR} at (70,46) size 0x0
+          RenderText {#text} at (3,74) size 74x18
+            text run at (3,74) width 74: "Line Three."
+          RenderBR {BR} at (77,78) size 0x0
+          RenderText {#text} at (3,106) size 67x18
+            text run at (3,106) width 67: "Line Four."
+          RenderBR {BR} at (70,110) size 0x0
+          RenderText {#text} at (3,138) size 65x18
+            text run at (3,138) width 65: "Line Five."
+        RenderText {#text} at (172,152) size 4x18
+          text run at (172,152) width 4: " "
+        RenderBlock {DIV} at (178,2) size 80x166 [border: (1px solid #000000)]
+          RenderRuby (inline) {RUBY} at (0,0) size 64x18
+            RenderRubyRun (anonymous) at (3,3) size 64x32
+              RenderRubyBase (anonymous) at (0,0) size 64x32
+                RenderText {#text} at (0,7) size 64x18
+                  text run at (0,7) width 64: "Line One."
+          RenderBR {BR} at (67,14) size 0x0
+          RenderText {#text} at (3,42) size 67x18
+            text run at (3,42) width 67: "Line Two."
+          RenderBR {BR} at (70,46) size 0x0
+          RenderRuby (inline) {RUBY} at (0,0) size 74x18
+            RenderRubyRun (anonymous) at (3,67) size 74x32
+              RenderRubyBase (anonymous) at (0,0) size 74x32
+                RenderText {#text} at (0,7) size 74x18
+                  text run at (0,7) width 74: "Line Three."
+          RenderBR {BR} at (77,78) size 0x0
+          RenderRuby (inline) {RUBY} at (0,0) size 67x18
+            RenderRubyRun (anonymous) at (3,99) size 67x32
+              RenderRubyBase (anonymous) at (0,0) size 67x32
+                RenderText {#text} at (0,7) size 67x18
+                  text run at (0,7) width 67: "Line Four."
+          RenderBR {BR} at (70,110) size 0x0
+          RenderText {#text} at (3,138) size 65x18
+            text run at (3,138) width 65: "Line Five."
+        RenderText {#text} at (0,0) size 0x0
diff --git a/LayoutTests/platform/mac/fast/ruby/quirks-mode-ruby-spacing-expected.checksum b/LayoutTests/platform/mac/fast/ruby/quirks-mode-ruby-spacing-expected.checksum
new file mode 100644
index 0000000..fa365cc
--- /dev/null
+++ b/LayoutTests/platform/mac/fast/ruby/quirks-mode-ruby-spacing-expected.checksum
@@ -0,0 +1 @@
+19d7f18d4409f3d77a9de5055279d211
\ No newline at end of file
diff --git a/LayoutTests/platform/mac/fast/ruby/quirks-mode-ruby-spacing-expected.png b/LayoutTests/platform/mac/fast/ruby/quirks-mode-ruby-spacing-expected.png
new file mode 100644
index 0000000..277679b
Binary files /dev/null and b/LayoutTests/platform/mac/fast/ruby/quirks-mode-ruby-spacing-expected.png differ
diff --git a/LayoutTests/platform/mac/fast/ruby/quirks-mode-ruby-spacing-expected.txt b/LayoutTests/platform/mac/fast/ruby/quirks-mode-ruby-spacing-expected.txt
new file mode 100644
index 0000000..0d48fec
--- /dev/null
+++ b/LayoutTests/platform/mac/fast/ruby/quirks-mode-ruby-spacing-expected.txt
@@ -0,0 +1,80 @@
+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
+      RenderText {#text} at (0,0) size 767x36
+        text run at (0,0) width 618: "This test is checking to make sure that ruby elements properly inherit line-height and don't reset it. "
+        text run at (618,0) width 149: "There should be double"
+        text run at (0,18) width 208: "spacing between all lines below. "
+        text run at (208,18) width 265: "The three blocks should line up perfectly. "
+      RenderBlock {DIV} at (475,20) size 80x166 [border: (1px solid #000000)]
+        RenderText {#text} at (3,10) size 64x18
+          text run at (3,10) width 64: "Line One."
+        RenderBR {BR} at (67,24) size 0x0
+        RenderText {#text} at (3,42) size 67x18
+          text run at (3,42) width 67: "Line Two."
+        RenderBR {BR} at (70,56) size 0x0
+        RenderRuby (inline) {RUBY} at (0,0) size 74x18
+          RenderRubyRun (anonymous) at (3,67) size 74x32
+            RenderRubyText {RT} at (0,-6) size 74x13
+              RenderText {#text} at (34,0) size 5x13
+                text run at (34,0) width 5: "3"
+            RenderRubyBase (anonymous) at (0,0) size 74x32
+              RenderText {#text} at (0,7) size 74x18
+                text run at (0,7) width 74: "Line Three."
+        RenderBR {BR} at (77,88) size 0x0
+        RenderRuby (inline) {RUBY} at (0,0) size 67x18
+          RenderRubyRun (anonymous) at (3,99) size 67x32
+            RenderRubyText {RT} at (0,-6) size 67x13
+              RenderText {#text} at (31,0) size 5x13
+                text run at (31,0) width 5: "4"
+            RenderRubyBase (anonymous) at (0,0) size 67x32
+              RenderText {#text} at (0,7) size 67x18
+                text run at (0,7) width 67: "Line Four."
+        RenderBR {BR} at (70,120) size 0x0
+        RenderText {#text} at (3,138) size 65x18
+          text run at (3,138) width 65: "Line Five."
+      RenderText {#text} at (557,18) size 4x18
+        text run at (557,18) width 4: " "
+      RenderBlock {DIV} at (563,20) size 80x166 [border: (1px solid #000000)]
+        RenderText {#text} at (3,10) size 64x18
+          text run at (3,10) width 64: "Line One."
+        RenderBR {BR} at (67,24) size 0x0
+        RenderText {#text} at (3,42) size 67x18
+          text run at (3,42) width 67: "Line Two."
+        RenderBR {BR} at (70,56) size 0x0
+        RenderText {#text} at (3,74) size 74x18
+          text run at (3,74) width 74: "Line Three."
+        RenderBR {BR} at (77,88) size 0x0
+        RenderText {#text} at (3,106) size 67x18
+          text run at (3,106) width 67: "Line Four."
+        RenderBR {BR} at (70,120) size 0x0
+        RenderText {#text} at (3,138) size 65x18
+          text run at (3,138) width 65: "Line Five."
+      RenderText {#text} at (645,18) size 4x18
+        text run at (645,18) width 4: " "
+      RenderBlock {DIV} at (651,20) size 80x166 [border: (1px solid #000000)]
+        RenderRuby (inline) {RUBY} at (0,0) size 64x18
+          RenderRubyRun (anonymous) at (3,3) size 64x32
+            RenderRubyBase (anonymous) at (0,0) size 64x32
+              RenderText {#text} at (0,7) size 64x18
+                text run at (0,7) width 64: "Line One."
+        RenderBR {BR} at (67,24) size 0x0
+        RenderText {#text} at (3,42) size 67x18
+          text run at (3,42) width 67: "Line Two."
+        RenderBR {BR} at (70,56) size 0x0
+        RenderRuby (inline) {RUBY} at (0,0) size 74x18
+          RenderRubyRun (anonymous) at (3,67) size 74x32
+            RenderRubyBase (anonymous) at (0,0) size 74x32
+              RenderText {#text} at (0,7) size 74x18
+                text run at (0,7) width 74: "Line Three."
+        RenderBR {BR} at (77,88) size 0x0
+        RenderRuby (inline) {RUBY} at (0,0) size 67x18
+          RenderRubyRun (anonymous) at (3,99) size 67x32
+            RenderRubyBase (anonymous) at (0,0) size 67x32
+              RenderText {#text} at (0,7) size 67x18
+                text run at (0,7) width 67: "Line Four."
+        RenderBR {BR} at (70,120) size 0x0
+        RenderText {#text} at (3,138) size 65x18
+          text run at (3,138) width 65: "Line Five."
diff --git a/LayoutTests/platform/mac/fast/ruby/ruby-auto-line-expansion-bt-expected.checksum b/LayoutTests/platform/mac/fast/ruby/ruby-auto-line-expansion-bt-expected.checksum
new file mode 100644
index 0000000..1330341
--- /dev/null
+++ b/LayoutTests/platform/mac/fast/ruby/ruby-auto-line-expansion-bt-expected.checksum
@@ -0,0 +1 @@
+a97a1d8cac5780510fd87c5ee5e60ba7
\ No newline at end of file
diff --git a/LayoutTests/platform/mac/fast/ruby/ruby-auto-line-expansion-bt-expected.png b/LayoutTests/platform/mac/fast/ruby/ruby-auto-line-expansion-bt-expected.png
new file mode 100644
index 0000000..75dfada
Binary files /dev/null and b/LayoutTests/platform/mac/fast/ruby/ruby-auto-line-expansion-bt-expected.png differ
diff --git a/LayoutTests/platform/mac/fast/ruby/ruby-auto-line-expansion-bt-expected.txt b/LayoutTests/platform/mac/fast/ruby/ruby-auto-line-expansion-bt-expected.txt
new file mode 100644
index 0000000..1eaea25
--- /dev/null
+++ b/LayoutTests/platform/mac/fast/ruby/ruby-auto-line-expansion-bt-expected.txt
@@ -0,0 +1,34 @@
+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 784x220
+        RenderBlock {DIV} at (2,2) size 80x194 [border: (1px solid #000000)]
+          RenderText {#text} at (3,10) size 64x18
+            text run at (3,10) width 64: "Line One."
+          RenderBR {BR} at (67,14) size 0x0
+          RenderText {#text} at (3,42) size 67x18
+            text run at (3,42) width 67: "Line Two."
+          RenderBR {BR} at (70,46) size 0x0
+          RenderRuby (inline) {RUBY} at (0,0) size 74x18
+            RenderRubyRun (anonymous) at (3,67) size 74x32
+              RenderRubyText {RT} at (0,25) size 74x28
+                RenderText {#text} at (31,0) size 12x28
+                  text run at (31,0) width 12: "3"
+              RenderRubyBase (anonymous) at (0,0) size 74x32
+                RenderText {#text} at (0,7) size 74x18
+                  text run at (0,7) width 74: "Line Three."
+          RenderBR {BR} at (77,78) size 0x0
+          RenderRuby (inline) {RUBY} at (0,0) size 67x18
+            RenderRubyRun (anonymous) at (3,113) size 67x32
+              RenderRubyText {RT} at (0,25) size 67x28
+                RenderText {#text} at (27,0) size 12x28
+                  text run at (27,0) width 12: "4"
+              RenderRubyBase (anonymous) at (0,0) size 67x32
+                RenderText {#text} at (0,7) size 67x18
+                  text run at (0,7) width 67: "Line Four."
+          RenderBR {BR} at (70,124) size 0x0
+          RenderText {#text} at (3,166) size 65x18
+            text run at (3,166) width 65: "Line Five."
+        RenderText {#text} at (0,0) size 0x0
diff --git a/LayoutTests/platform/mac/fast/ruby/ruby-auto-line-expansion-expected.checksum b/LayoutTests/platform/mac/fast/ruby/ruby-auto-line-expansion-expected.checksum
new file mode 100644
index 0000000..c4e575c
--- /dev/null
+++ b/LayoutTests/platform/mac/fast/ruby/ruby-auto-line-expansion-expected.checksum
@@ -0,0 +1 @@
+2568bf3fef0e8f3c794d475c83812b14
\ No newline at end of file
diff --git a/LayoutTests/platform/mac/fast/ruby/ruby-auto-line-expansion-expected.png b/LayoutTests/platform/mac/fast/ruby/ruby-auto-line-expansion-expected.png
new file mode 100644
index 0000000..3137659
Binary files /dev/null and b/LayoutTests/platform/mac/fast/ruby/ruby-auto-line-expansion-expected.png differ
diff --git a/LayoutTests/platform/mac/fast/ruby/ruby-auto-line-expansion-expected.txt b/LayoutTests/platform/mac/fast/ruby/ruby-auto-line-expansion-expected.txt
new file mode 100644
index 0000000..3eae5cd
--- /dev/null
+++ b/LayoutTests/platform/mac/fast/ruby/ruby-auto-line-expansion-expected.txt
@@ -0,0 +1,33 @@
+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 (2,2) size 80x194 [border: (1px solid #000000)]
+        RenderText {#text} at (3,10) size 64x18
+          text run at (3,10) width 64: "Line One."
+        RenderBR {BR} at (67,24) size 0x0
+        RenderText {#text} at (3,42) size 67x18
+          text run at (3,42) width 67: "Line Two."
+        RenderBR {BR} at (70,56) size 0x0
+        RenderRuby (inline) {RUBY} at (0,0) size 74x18
+          RenderRubyRun (anonymous) at (3,81) size 74x32
+            RenderRubyText {RT} at (0,-21) size 74x28
+              RenderText {#text} at (31,0) size 12x28
+                text run at (31,0) width 12: "3"
+            RenderRubyBase (anonymous) at (0,0) size 74x32
+              RenderText {#text} at (0,7) size 74x18
+                text run at (0,7) width 74: "Line Three."
+        RenderBR {BR} at (77,102) size 0x0
+        RenderRuby (inline) {RUBY} at (0,0) size 67x18
+          RenderRubyRun (anonymous) at (3,127) size 67x32
+            RenderRubyText {RT} at (0,-21) size 67x28
+              RenderText {#text} at (27,0) size 12x28
+                text run at (27,0) width 12: "4"
+            RenderRubyBase (anonymous) at (0,0) size 67x32
+              RenderText {#text} at (0,7) size 67x18
+                text run at (0,7) width 67: "Line Four."
+        RenderBR {BR} at (70,148) size 0x0
+        RenderText {#text} at (3,166) size 65x18
+          text run at (3,166) width 65: "Line Five."
+      RenderText {#text} at (0,0) size 0x0
diff --git a/LayoutTests/platform/mac/fast/ruby/ruby-auto-line-expansion-lr-expected.checksum b/LayoutTests/platform/mac/fast/ruby/ruby-auto-line-expansion-lr-expected.checksum
new file mode 100644
index 0000000..bad09e4
--- /dev/null
+++ b/LayoutTests/platform/mac/fast/ruby/ruby-auto-line-expansion-lr-expected.checksum
@@ -0,0 +1 @@
+8ffe9a0b180c00583efba470c2367024
\ No newline at end of file
diff --git a/LayoutTests/platform/mac/fast/ruby/ruby-auto-line-expansion-lr-expected.png b/LayoutTests/platform/mac/fast/ruby/ruby-auto-line-expansion-lr-expected.png
new file mode 100644
index 0000000..526094a
Binary files /dev/null and b/LayoutTests/platform/mac/fast/ruby/ruby-auto-line-expansion-lr-expected.png differ
diff --git a/LayoutTests/platform/mac/fast/ruby/ruby-auto-line-expansion-lr-expected.txt b/LayoutTests/platform/mac/fast/ruby/ruby-auto-line-expansion-lr-expected.txt
new file mode 100644
index 0000000..0693a31
--- /dev/null
+++ b/LayoutTests/platform/mac/fast/ruby/ruby-auto-line-expansion-lr-expected.txt
@@ -0,0 +1,34 @@
+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 198x220
+        RenderBlock {DIV} at (2,2) size 194x80 [border: (1px solid #000000)]
+          RenderText {#text} at (10,3) size 18x64
+            text run at (10,3) width 64: "Line One."
+          RenderBR {BR} at (14,67) size 0x0
+          RenderText {#text} at (42,3) size 18x67
+            text run at (42,3) width 67: "Line Two."
+          RenderBR {BR} at (46,70) size 0x0
+          RenderRuby (inline) {RUBY} at (0,0) size 18x74
+            RenderRubyRun (anonymous) at (67,3) size 32x74
+              RenderRubyText {RT} at (25,0) size 28x74
+                RenderText {#text} at (0,31) size 28x12
+                  text run at (0,31) width 12: "3"
+              RenderRubyBase (anonymous) at (0,0) size 32x74
+                RenderText {#text} at (7,0) size 18x74
+                  text run at (7,0) width 74: "Line Three."
+          RenderBR {BR} at (78,77) size 0x0
+          RenderRuby (inline) {RUBY} at (0,0) size 18x67
+            RenderRubyRun (anonymous) at (113,3) size 32x67
+              RenderRubyText {RT} at (25,0) size 28x67
+                RenderText {#text} at (0,27) size 28x12
+                  text run at (0,27) width 12: "4"
+              RenderRubyBase (anonymous) at (0,0) size 32x67
+                RenderText {#text} at (7,0) size 18x67
+                  text run at (7,0) width 67: "Line Four."
+          RenderBR {BR} at (124,70) size 0x0
+          RenderText {#text} at (166,3) size 18x65
+            text run at (166,3) width 65: "Line Five."
+        RenderText {#text} at (0,0) size 0x0
diff --git a/LayoutTests/platform/mac/fast/ruby/ruby-auto-line-expansion-rl-expected.checksum b/LayoutTests/platform/mac/fast/ruby/ruby-auto-line-expansion-rl-expected.checksum
new file mode 100644
index 0000000..d0f08f3
--- /dev/null
+++ b/LayoutTests/platform/mac/fast/ruby/ruby-auto-line-expansion-rl-expected.checksum
@@ -0,0 +1 @@
+b7e05520bb84031e68fe8e8af1aade78
\ No newline at end of file
diff --git a/LayoutTests/platform/mac/fast/ruby/ruby-auto-line-expansion-rl-expected.png b/LayoutTests/platform/mac/fast/ruby/ruby-auto-line-expansion-rl-expected.png
new file mode 100644
index 0000000..32386e4
Binary files /dev/null and b/LayoutTests/platform/mac/fast/ruby/ruby-auto-line-expansion-rl-expected.png differ
diff --git a/LayoutTests/platform/mac/fast/ruby/ruby-auto-line-expansion-rl-expected.txt b/LayoutTests/platform/mac/fast/ruby/ruby-auto-line-expansion-rl-expected.txt
new file mode 100644
index 0000000..29ca8aa
--- /dev/null
+++ b/LayoutTests/platform/mac/fast/ruby/ruby-auto-line-expansion-rl-expected.txt
@@ -0,0 +1,34 @@
+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 198x220
+        RenderBlock {DIV} at (2,2) size 194x80 [border: (1px solid #000000)]
+          RenderText {#text} at (10,3) size 18x64
+            text run at (10,3) width 64: "Line One."
+          RenderBR {BR} at (24,67) size 0x0
+          RenderText {#text} at (42,3) size 18x67
+            text run at (42,3) width 67: "Line Two."
+          RenderBR {BR} at (56,70) size 0x0
+          RenderRuby (inline) {RUBY} at (0,0) size 18x74
+            RenderRubyRun (anonymous) at (81,3) size 32x74
+              RenderRubyText {RT} at (-21,0) size 28x74
+                RenderText {#text} at (0,31) size 28x12
+                  text run at (0,31) width 12: "3"
+              RenderRubyBase (anonymous) at (0,0) size 32x74
+                RenderText {#text} at (7,0) size 18x74
+                  text run at (7,0) width 74: "Line Three."
+          RenderBR {BR} at (102,77) size 0x0
+          RenderRuby (inline) {RUBY} at (0,0) size 18x67
+            RenderRubyRun (anonymous) at (127,3) size 32x67
+              RenderRubyText {RT} at (-21,0) size 28x67
+                RenderText {#text} at (0,27) size 28x12
+                  text run at (0,27) width 12: "4"
+              RenderRubyBase (anonymous) at (0,0) size 32x67
+                RenderText {#text} at (7,0) size 18x67
+                  text run at (7,0) width 67: "Line Four."
+          RenderBR {BR} at (148,70) size 0x0
+          RenderText {#text} at (166,3) size 18x65
+            text run at (166,3) width 65: "Line Five."
+        RenderText {#text} at (0,0) size 0x0
diff --git a/LayoutTests/platform/mac/fast/ruby/ruby-beforeafter-expected.txt b/LayoutTests/platform/mac/fast/ruby/ruby-beforeafter-expected.txt
index 8affb34..8d40f0b 100644
--- a/LayoutTests/platform/mac/fast/ruby/ruby-beforeafter-expected.txt
+++ b/LayoutTests/platform/mac/fast/ruby/ruby-beforeafter-expected.txt
@@ -14,11 +14,11 @@ layer at (0,0) size 800x600
           RenderInline (generated) at (0,0) size 50x18
             RenderText at (29,13) size 50x18
               text run at (29,13) width 50: "[before]"
-          RenderRubyRun (anonymous) at (79,0) size 36x31
-            RenderRubyText {RT} at (0,0) size 36x13
+          RenderRubyRun (anonymous) at (79,13) size 36x18
+            RenderRubyText {RT} at (0,-13) size 36x13
               RenderText {#text} at (0,0) size 36x13
                 text run at (0,0) width 36: "long text"
-            RenderRubyBase (anonymous) at (0,13) size 36x18
+            RenderRubyBase (anonymous) at (0,0) size 36x18
               RenderText {#text} at (14,0) size 8x18
                 text run at (14,0) width 8: "b"
         RenderText {#text} at (115,13) size 27x18
@@ -30,11 +30,11 @@ layer at (0,0) size 800x600
         RenderText {#text} at (0,13) size 29x18
           text run at (0,13) width 29: "Foo "
         RenderRuby (inline) {RUBY} at (0,0) size 74x18
-          RenderRubyRun (anonymous) at (29,0) size 36x31
-            RenderRubyText {RT} at (0,0) size 36x13
+          RenderRubyRun (anonymous) at (29,13) size 36x18
+            RenderRubyText {RT} at (0,-13) size 36x13
               RenderText {#text} at (0,0) size 36x13
                 text run at (0,0) width 36: "long text"
-            RenderRubyBase (anonymous) at (0,13) size 36x18
+            RenderRubyBase (anonymous) at (0,0) size 36x18
               RenderText {#text} at (14,0) size 8x18
                 text run at (14,0) width 8: "b"
           RenderInline (generated) at (0,0) size 38x18
@@ -52,11 +52,11 @@ layer at (0,0) size 800x600
           RenderInline (generated) at (0,0) size 50x18
             RenderText at (29,13) size 50x18
               text run at (29,13) width 50: "[before]"
-          RenderRubyRun (anonymous) at (79,0) size 36x31
-            RenderRubyText {RT} at (0,0) size 36x13
+          RenderRubyRun (anonymous) at (79,13) size 36x18
+            RenderRubyText {RT} at (0,-13) size 36x13
               RenderText {#text} at (0,0) size 36x13
                 text run at (0,0) width 36: "long text"
-            RenderRubyBase (anonymous) at (0,13) size 36x18
+            RenderRubyBase (anonymous) at (0,0) size 36x18
               RenderText {#text} at (14,0) size 8x18
                 text run at (14,0) width 8: "b"
           RenderInline (generated) at (0,0) size 38x18
diff --git a/LayoutTests/platform/mac/fast/ruby/ruby-empty-rt-expected.txt b/LayoutTests/platform/mac/fast/ruby/ruby-empty-rt-expected.txt
index 781b379..ef17a02 100644
--- a/LayoutTests/platform/mac/fast/ruby/ruby-empty-rt-expected.txt
+++ b/LayoutTests/platform/mac/fast/ruby/ruby-empty-rt-expected.txt
@@ -13,15 +13,15 @@ layer at (0,0) size 800x600
         RenderText {#text} at (0,13) size 82x18
           text run at (0,13) width 82: "<ruby> uses "
         RenderRuby (inline) {RUBY} at (0,0) size 42x18
-          RenderRubyRun (anonymous) at (82,0) size 27x31
-            RenderRubyText {RT} at (0,0) size 27x13
+          RenderRubyRun (anonymous) at (82,13) size 27x18
+            RenderRubyText {RT} at (0,-13) size 27x13
               RenderText {#text} at (4,0) size 18x13
                 text run at (4,0) width 18: "ruby"
-            RenderRubyBase (anonymous) at (0,13) size 27x18
+            RenderRubyBase (anonymous) at (0,0) size 27x18
               RenderText {#text} at (0,0) size 27x18
                 text run at (0,0) width 27: "<rt>"
-          RenderRubyRun (anonymous) at (109,17) size 15x13
-            RenderRubyText {RT} at (0,0) size 15x13
+          RenderRubyRun (anonymous) at (109,30) size 15x0
+            RenderRubyText {RT} at (0,-13) size 15x13
               RenderText {#text} at (0,0) size 15x13
                 text run at (0,0) width 15: "text"
         RenderText {#text} at (124,13) size 163x18
diff --git a/LayoutTests/platform/mac/fast/ruby/ruby-length-expected.txt b/LayoutTests/platform/mac/fast/ruby/ruby-length-expected.txt
index 7cd308a..476382b 100644
--- a/LayoutTests/platform/mac/fast/ruby/ruby-length-expected.txt
+++ b/LayoutTests/platform/mac/fast/ruby/ruby-length-expected.txt
@@ -12,21 +12,21 @@ layer at (0,0) size 800x600
       RenderText {#text} at (0,67) size 155x18
         text run at (0,67) width 155: "<ruby> is defined in the "
       RenderRuby (inline) {RUBY} at (0,0) size 184x18
-        RenderRubyRun (anonymous) at (155,54) size 184x31
-          RenderRubyText {RT} at (0,0) size 184x13
+        RenderRubyRun (anonymous) at (155,67) size 184x18
+          RenderRubyText {RT} at (0,-13) size 184x13
             RenderText {#text} at (75,0) size 33x13
               text run at (75,0) width 33: "HTML5"
-          RenderRubyBase (anonymous) at (0,13) size 184x18
+          RenderRubyBase (anonymous) at (0,0) size 184x18
             RenderText {#text} at (0,0) size 184x18
               text run at (0,0) width 184: "Hypertext Markup Language"
       RenderText {#text} at (339,67) size 31x18
         text run at (339,67) width 31: " and "
       RenderRuby (inline) {RUBY} at (0,0) size 94x18
-        RenderRubyRun (anonymous) at (370,54) size 94x31
-          RenderRubyText {RT} at (0,0) size 94x13
+        RenderRubyRun (anonymous) at (370,67) size 94x18
+          RenderRubyText {RT} at (0,-13) size 94x13
             RenderText {#text} at (0,0) size 94x13
               text run at (0,0) width 94: "Cascading Style Sheets"
-          RenderRubyBase (anonymous) at (0,13) size 94x18
+          RenderRubyBase (anonymous) at (0,0) size 94x18
             RenderText {#text} at (28,0) size 37x18
               text run at (28,0) width 37: "CSS3"
       RenderText {#text} at (464,67) size 42x18
diff --git a/LayoutTests/platform/mac/fast/ruby/ruby-run-break-expected.checksum b/LayoutTests/platform/mac/fast/ruby/ruby-run-break-expected.checksum
index 47ac312..80261ab 100644
--- a/LayoutTests/platform/mac/fast/ruby/ruby-run-break-expected.checksum
+++ b/LayoutTests/platform/mac/fast/ruby/ruby-run-break-expected.checksum
@@ -1 +1 @@
-b98c751a1ca9468907689fb225a64bfe
\ No newline at end of file
+27f7d7991b93ee477dd583444d034219
\ No newline at end of file
diff --git a/LayoutTests/platform/mac/fast/ruby/ruby-run-break-expected.png b/LayoutTests/platform/mac/fast/ruby/ruby-run-break-expected.png
index 43afe27..f6f57b6 100644
Binary files a/LayoutTests/platform/mac/fast/ruby/ruby-run-break-expected.png and b/LayoutTests/platform/mac/fast/ruby/ruby-run-break-expected.png differ
diff --git a/LayoutTests/platform/mac/fast/ruby/ruby-run-break-expected.txt b/LayoutTests/platform/mac/fast/ruby/ruby-run-break-expected.txt
index 36acd17..f48182d 100644
--- a/LayoutTests/platform/mac/fast/ruby/ruby-run-break-expected.txt
+++ b/LayoutTests/platform/mac/fast/ruby/ruby-run-break-expected.txt
@@ -11,44 +11,44 @@ layer at (0,0) size 800x600
           text run at (0,36) width 110: "on the other line. "
         RenderBR {BR} at (110,50) size 0x0
         RenderBR {BR} at (0,54) size 0x18
-      RenderBlock {DIV} at (0,72) size 284x86 [border: (2px solid #0000FF)]
-        RenderText {#text} at (12,25) size 155x18
-          text run at (12,25) width 155: "<ruby> is defined in the "
+      RenderBlock {DIV} at (0,72) size 284x76 [border: (2px solid #0000FF)]
+        RenderText {#text} at (12,15) size 155x18
+          text run at (12,15) width 155: "<ruby> is defined in the "
         RenderRuby (inline) {RUBY} at (0,0) size 228x49
-          RenderRubyRun (anonymous) at (167,12) size 24x31
-            RenderRubyText {RT} at (0,0) size 24x13
+          RenderRubyRun (anonymous) at (167,15) size 24x18
+            RenderRubyText {RT} at (0,-13) size 24x13
               RenderText {#text} at (0,0) size 24x13
                 text run at (0,0) width 24: "Hyper"
-            RenderRubyBase (anonymous) at (0,13) size 24x18
+            RenderRubyBase (anonymous) at (0,0) size 24x18
               RenderText {#text} at (6,0) size 12x18
                 text run at (6,0) width 12: "H"
-          RenderRubyRun (anonymous) at (191,12) size 18x31
-            RenderRubyText {RT} at (0,0) size 18x13
+          RenderRubyRun (anonymous) at (191,15) size 18x18
+            RenderRubyText {RT} at (0,-13) size 18x13
               RenderText {#text} at (0,0) size 18x13
                 text run at (0,0) width 18: "Text"
-            RenderRubyBase (anonymous) at (0,13) size 18x18
+            RenderRubyBase (anonymous) at (0,0) size 18x18
               RenderText {#text} at (4,0) size 10x18
                 text run at (4,0) width 10: "T"
-          RenderRubyRun (anonymous) at (209,12) size 31x31
-            RenderRubyText {RT} at (0,0) size 31x13
+          RenderRubyRun (anonymous) at (209,15) size 31x18
+            RenderRubyText {RT} at (0,-13) size 31x13
               RenderText {#text} at (0,0) size 31x13
                 text run at (0,0) width 31: "Markup"
-            RenderRubyBase (anonymous) at (0,13) size 31x18
+            RenderRubyBase (anonymous) at (0,0) size 31x18
               RenderText {#text} at (8,0) size 14x18
                 text run at (8,0) width 14: "M"
-          RenderRubyRun (anonymous) at (12,43) size 38x31
-            RenderRubyText {RT} at (0,0) size 38x13
+          RenderRubyRun (anonymous) at (12,46) size 38x18
+            RenderRubyText {RT} at (0,-13) size 38x13
               RenderText {#text} at (0,0) size 38x13
                 text run at (0,0) width 38: "Language"
-            RenderRubyBase (anonymous) at (0,13) size 38x18
+            RenderRubyBase (anonymous) at (0,0) size 38x18
               RenderText {#text} at (14,0) size 10x18
                 text run at (14,0) width 10: "L"
-          RenderRubyRun (anonymous) at (50,43) size 30x31
-            RenderRubyText {RT} at (0,0) size 30x13
+          RenderRubyRun (anonymous) at (50,46) size 30x18
+            RenderRubyText {RT} at (0,-13) size 30x13
               RenderText {#text} at (0,0) size 30x13
                 text run at (0,0) width 30: "Level 5"
-            RenderRubyBase (anonymous) at (0,13) size 30x18
+            RenderRubyBase (anonymous) at (0,0) size 30x18
               RenderText {#text} at (11,0) size 8x18
                 text run at (11,0) width 8: "5"
-        RenderText {#text} at (80,56) size 42x18
-          text run at (80,56) width 42: " specs."
+        RenderText {#text} at (80,46) size 42x18
+          text run at (80,46) width 42: " specs."
diff --git a/LayoutTests/platform/mac/fast/ruby/ruby-runs-expected.txt b/LayoutTests/platform/mac/fast/ruby/ruby-runs-expected.txt
index 705fb83..353b409 100644
--- a/LayoutTests/platform/mac/fast/ruby/ruby-runs-expected.txt
+++ b/LayoutTests/platform/mac/fast/ruby/ruby-runs-expected.txt
@@ -12,39 +12,39 @@ layer at (0,0) size 800x600
         RenderText {#text} at (0,13) size 155x18
           text run at (0,13) width 155: "<ruby> is defined in the "
         RenderRuby (inline) {RUBY} at (0,0) size 141x18
-          RenderRubyRun (anonymous) at (155,0) size 24x31
-            RenderRubyText {RT} at (0,0) size 24x13
+          RenderRubyRun (anonymous) at (155,13) size 24x18
+            RenderRubyText {RT} at (0,-13) size 24x13
               RenderText {#text} at (0,0) size 24x13
                 text run at (0,0) width 24: "Hyper"
-            RenderRubyBase (anonymous) at (0,13) size 24x18
+            RenderRubyBase (anonymous) at (0,0) size 24x18
               RenderText {#text} at (6,0) size 12x18
                 text run at (6,0) width 12: "H"
-          RenderRubyRun (anonymous) at (179,0) size 18x31
-            RenderRubyText {RT} at (0,0) size 18x13
+          RenderRubyRun (anonymous) at (179,13) size 18x18
+            RenderRubyText {RT} at (0,-13) size 18x13
               RenderText {#text} at (0,0) size 18x13
                 text run at (0,0) width 18: "Text"
-            RenderRubyBase (anonymous) at (0,13) size 18x18
+            RenderRubyBase (anonymous) at (0,0) size 18x18
               RenderText {#text} at (4,0) size 10x18
                 text run at (4,0) width 10: "T"
-          RenderRubyRun (anonymous) at (197,0) size 31x31
-            RenderRubyText {RT} at (0,0) size 31x13
+          RenderRubyRun (anonymous) at (197,13) size 31x18
+            RenderRubyText {RT} at (0,-13) size 31x13
               RenderText {#text} at (0,0) size 31x13
                 text run at (0,0) width 31: "Markup"
-            RenderRubyBase (anonymous) at (0,13) size 31x18
+            RenderRubyBase (anonymous) at (0,0) size 31x18
               RenderText {#text} at (8,0) size 14x18
                 text run at (8,0) width 14: "M"
-          RenderRubyRun (anonymous) at (228,0) size 38x31
-            RenderRubyText {RT} at (0,0) size 38x13
+          RenderRubyRun (anonymous) at (228,13) size 38x18
+            RenderRubyText {RT} at (0,-13) size 38x13
               RenderText {#text} at (0,0) size 38x13
                 text run at (0,0) width 38: "Language"
-            RenderRubyBase (anonymous) at (0,13) size 38x18
+            RenderRubyBase (anonymous) at (0,0) size 38x18
               RenderText {#text} at (14,0) size 10x18
                 text run at (14,0) width 10: "L"
-          RenderRubyRun (anonymous) at (266,0) size 30x31
-            RenderRubyText {RT} at (0,0) size 30x13
+          RenderRubyRun (anonymous) at (266,13) size 30x18
+            RenderRubyText {RT} at (0,-13) size 30x13
               RenderText {#text} at (0,0) size 30x13
                 text run at (0,0) width 30: "Level 5"
-            RenderRubyBase (anonymous) at (0,13) size 30x18
+            RenderRubyBase (anonymous) at (0,0) size 30x18
               RenderText {#text} at (11,0) size 8x18
                 text run at (11,0) width 8: "5"
         RenderText {#text} at (296,13) size 42x18
diff --git a/LayoutTests/platform/mac/fast/ruby/ruby-runs-spans-expected.txt b/LayoutTests/platform/mac/fast/ruby/ruby-runs-spans-expected.txt
index 751d568..c327b47 100644
--- a/LayoutTests/platform/mac/fast/ruby/ruby-runs-spans-expected.txt
+++ b/LayoutTests/platform/mac/fast/ruby/ruby-runs-spans-expected.txt
@@ -10,19 +10,19 @@ layer at (0,0) size 800x600
         RenderText {#text} at (0,13) size 155x18
           text run at (0,13) width 155: "<ruby> is defined in the "
         RenderRuby (inline) {RUBY} at (0,0) size 142x18
-          RenderRubyRun (anonymous) at (155,0) size 42x31
-            RenderRubyText {RT} at (0,0) size 42x13
+          RenderRubyRun (anonymous) at (155,13) size 42x18
+            RenderRubyText {RT} at (0,-13) size 42x13
               RenderText {#text} at (0,0) size 42x13
                 text run at (0,0) width 42: "Hyper-text"
-            RenderRubyBase (anonymous) at (0,13) size 42x18
+            RenderRubyBase (anonymous) at (0,0) size 42x18
               RenderInline {SPAN} at (0,0) size 22x18
                 RenderText {#text} at (10,0) size 22x18
                   text run at (10,0) width 22: "HT"
-          RenderRubyRun (anonymous) at (197,0) size 100x31
-            RenderRubyText {RT} at (0,0) size 100x13
+          RenderRubyRun (anonymous) at (197,13) size 100x18
+            RenderRubyText {RT} at (0,-13) size 100x13
               RenderText {#text} at (0,0) size 100x13
                 text run at (0,0) width 100: "Markup Language Lvl. 5"
-            RenderRubyBase (anonymous) at (0,13) size 100x18
+            RenderRubyBase (anonymous) at (0,0) size 100x18
               RenderInline {SPAN} at (0,0) size 14x18
                 RenderText {#text} at (34,0) size 14x18
                   text run at (34,0) width 14: "M"
diff --git a/LayoutTests/platform/mac/fast/ruby/ruby-simple-expected.txt b/LayoutTests/platform/mac/fast/ruby/ruby-simple-expected.txt
index f9bddc6..d723512 100644
--- a/LayoutTests/platform/mac/fast/ruby/ruby-simple-expected.txt
+++ b/LayoutTests/platform/mac/fast/ruby/ruby-simple-expected.txt
@@ -12,11 +12,11 @@ layer at (0,0) size 800x600
         RenderText {#text} at (0,13) size 161x18
           text run at (0,13) width 161: "Ruby is often used in the "
         RenderRuby (inline) {RUBY} at (0,0) size 117x18
-          RenderRubyRun (anonymous) at (161,0) size 117x31
-            RenderRubyText {RT} at (0,0) size 117x13
+          RenderRubyRun (anonymous) at (161,13) size 117x18
+            RenderRubyText {RT} at (0,-13) size 117x13
               RenderText {#text} at (41,0) size 35x13
                 text run at (41,0) width 35: "Nihongo"
-            RenderRubyBase (anonymous) at (0,13) size 117x18
+            RenderRubyBase (anonymous) at (0,0) size 117x18
               RenderText {#text} at (0,0) size 117x18
                 text run at (0,0) width 117: "Japanese language"
         RenderText {#text} at (278,13) size 4x18
diff --git a/LayoutTests/platform/mac/fast/ruby/ruby-simple-rp-expected.txt b/LayoutTests/platform/mac/fast/ruby/ruby-simple-rp-expected.txt
index 0c1289a..7423a4b 100644
--- a/LayoutTests/platform/mac/fast/ruby/ruby-simple-rp-expected.txt
+++ b/LayoutTests/platform/mac/fast/ruby/ruby-simple-rp-expected.txt
@@ -14,11 +14,11 @@ layer at (0,0) size 800x600
         RenderText {#text} at (0,13) size 161x18
           text run at (0,13) width 161: "Ruby is often used in the "
         RenderRuby (inline) {RUBY} at (0,0) size 117x18
-          RenderRubyRun (anonymous) at (161,0) size 117x31
-            RenderRubyText {RT} at (0,0) size 117x13
+          RenderRubyRun (anonymous) at (161,13) size 117x18
+            RenderRubyText {RT} at (0,-13) size 117x13
               RenderText {#text} at (41,0) size 35x13
                 text run at (41,0) width 35: "Nihongo"
-            RenderRubyBase (anonymous) at (0,13) size 117x18
+            RenderRubyBase (anonymous) at (0,0) size 117x18
               RenderText {#text} at (0,0) size 117x18
                 text run at (0,0) width 117: "Japanese language"
         RenderText {#text} at (278,13) size 4x18
diff --git a/LayoutTests/platform/mac/fast/ruby/ruby-trailing-expected.txt b/LayoutTests/platform/mac/fast/ruby/ruby-trailing-expected.txt
index 199de8d..cf40aa4 100644
--- a/LayoutTests/platform/mac/fast/ruby/ruby-trailing-expected.txt
+++ b/LayoutTests/platform/mac/fast/ruby/ruby-trailing-expected.txt
@@ -13,11 +13,11 @@ layer at (0,0) size 800x600
         RenderText {#text} at (0,13) size 155x18
           text run at (0,13) width 155: "<ruby> is defined in the "
         RenderRuby (inline) {RUBY} at (0,0) size 125x18
-          RenderRubyRun (anonymous) at (155,0) size 117x31
-            RenderRubyText {RT} at (0,0) size 117x13
+          RenderRubyRun (anonymous) at (155,13) size 117x18
+            RenderRubyText {RT} at (0,-13) size 117x13
               RenderText {#text} at (0,0) size 117x13
                 text run at (0,0) width 117: "Hyper-text Markup Language"
-            RenderRubyBase (anonymous) at (0,13) size 117x18
+            RenderRubyBase (anonymous) at (0,0) size 117x18
               RenderText {#text} at (35,0) size 46x18
                 text run at (35,0) width 46: "HTML"
           RenderRubyRun (anonymous) at (272,13) size 8x18
diff --git a/LayoutTests/platform/mac/fast/ruby/rubyDOM-insert-rt-expected.txt b/LayoutTests/platform/mac/fast/ruby/rubyDOM-insert-rt-expected.txt
index 745b991..8de7a55 100644
--- a/LayoutTests/platform/mac/fast/ruby/rubyDOM-insert-rt-expected.txt
+++ b/LayoutTests/platform/mac/fast/ruby/rubyDOM-insert-rt-expected.txt
@@ -16,19 +16,19 @@ layer at (0,0) size 800x600
         RenderText {#text} at (0,13) size 155x18
           text run at (0,13) width 155: "<ruby> is defined in the "
         RenderRuby (inline) {RUBY} at (0,0) size 122x18
-          RenderRubyRun (anonymous) at (155,0) size 42x31
-            RenderRubyText {RT} at (0,0) size 42x13
+          RenderRubyRun (anonymous) at (155,13) size 42x18
+            RenderRubyText {RT} at (0,-13) size 42x13
               RenderText {#text} at (0,0) size 42x13
                 text run at (0,0) width 42: "Hyper-text"
-            RenderRubyBase (anonymous) at (0,13) size 42x18
+            RenderRubyBase (anonymous) at (0,0) size 42x18
               RenderInline {SPAN} at (0,0) size 22x18
                 RenderText {#text} at (10,0) size 22x18
                   text run at (10,0) width 22: "HT"
-          RenderRubyRun (anonymous) at (197,0) size 72x31
-            RenderRubyText {RT} at (0,0) size 72x13
+          RenderRubyRun (anonymous) at (197,13) size 72x18
+            RenderRubyText {RT} at (0,-13) size 72x13
               RenderText {#text} at (0,0) size 72x13
                 text run at (0,0) width 72: "Markup Language"
-            RenderRubyBase (anonymous) at (0,13) size 72x18
+            RenderRubyBase (anonymous) at (0,0) size 72x18
               RenderInline {SPAN} at (0,0) size 24x18
                 RenderText {#text} at (24,0) size 24x18
                   text run at (24,0) width 24: "ML"
@@ -42,19 +42,19 @@ layer at (0,0) size 800x600
         RenderText {#text} at (0,13) size 155x18
           text run at (0,13) width 155: "<ruby> is defined in the "
         RenderRuby (inline) {RUBY} at (0,0) size 122x18
-          RenderRubyRun (anonymous) at (155,0) size 42x31
-            RenderRubyText {RT} at (0,0) size 42x13
+          RenderRubyRun (anonymous) at (155,13) size 42x18
+            RenderRubyText {RT} at (0,-13) size 42x13
               RenderText {#text} at (0,0) size 42x13
                 text run at (0,0) width 42: "Hyper-text"
-            RenderRubyBase (anonymous) at (0,13) size 42x18
+            RenderRubyBase (anonymous) at (0,0) size 42x18
               RenderInline {SPAN} at (0,0) size 22x18
                 RenderText {#text} at (10,0) size 22x18
                   text run at (10,0) width 22: "HT"
-          RenderRubyRun (anonymous) at (197,0) size 72x31
-            RenderRubyText {RT} at (0,0) size 72x13
+          RenderRubyRun (anonymous) at (197,13) size 72x18
+            RenderRubyText {RT} at (0,-13) size 72x13
               RenderText {#text} at (0,0) size 72x13
                 text run at (0,0) width 72: "Markup Language"
-            RenderRubyBase (anonymous) at (0,13) size 72x18
+            RenderRubyBase (anonymous) at (0,0) size 72x18
               RenderInline {SPAN} at (0,0) size 24x18
                 RenderText {#text} at (24,0) size 24x18
                   text run at (24,0) width 24: "ML"
diff --git a/LayoutTests/platform/mac/fast/ruby/rubyDOM-insert-text1-expected.txt b/LayoutTests/platform/mac/fast/ruby/rubyDOM-insert-text1-expected.txt
index 6778b81..3df425c 100644
--- a/LayoutTests/platform/mac/fast/ruby/rubyDOM-insert-text1-expected.txt
+++ b/LayoutTests/platform/mac/fast/ruby/rubyDOM-insert-text1-expected.txt
@@ -16,18 +16,18 @@ layer at (0,0) size 800x600
         RenderText {#text} at (0,13) size 155x18
           text run at (0,13) width 155: "<ruby> is defined in the "
         RenderRuby (inline) {RUBY} at (0,0) size 122x18
-          RenderRubyRun (anonymous) at (155,0) size 42x31
-            RenderRubyText {RT} at (0,0) size 42x13
+          RenderRubyRun (anonymous) at (155,13) size 42x18
+            RenderRubyText {RT} at (0,-13) size 42x13
               RenderText {#text} at (0,0) size 42x13
                 text run at (0,0) width 42: "Hyper-text"
-            RenderRubyBase (anonymous) at (0,13) size 42x18
+            RenderRubyBase (anonymous) at (0,0) size 42x18
               RenderText {#text} at (10,0) size 22x18
                 text run at (10,0) width 22: "HT"
-          RenderRubyRun (anonymous) at (197,0) size 72x31
-            RenderRubyText {RT} at (0,0) size 72x13
+          RenderRubyRun (anonymous) at (197,13) size 72x18
+            RenderRubyText {RT} at (0,-13) size 72x13
               RenderText {#text} at (0,0) size 72x13
                 text run at (0,0) width 72: "Markup Language"
-            RenderRubyBase (anonymous) at (0,13) size 72x18
+            RenderRubyBase (anonymous) at (0,0) size 72x18
               RenderText {#text} at (24,0) size 24x18
                 text run at (24,0) width 24: "ML"
           RenderRubyRun (anonymous) at (269,13) size 8x18
@@ -40,18 +40,18 @@ layer at (0,0) size 800x600
         RenderText {#text} at (0,13) size 155x18
           text run at (0,13) width 155: "<ruby> is defined in the "
         RenderRuby (inline) {RUBY} at (0,0) size 122x18
-          RenderRubyRun (anonymous) at (155,0) size 42x31
-            RenderRubyText {RT} at (0,0) size 42x13
+          RenderRubyRun (anonymous) at (155,13) size 42x18
+            RenderRubyText {RT} at (0,-13) size 42x13
               RenderText {#text} at (0,0) size 42x13
                 text run at (0,0) width 42: "Hyper-text"
-            RenderRubyBase (anonymous) at (0,13) size 42x18
+            RenderRubyBase (anonymous) at (0,0) size 42x18
               RenderText {#text} at (10,0) size 22x18
                 text run at (10,0) width 22: "HT"
-          RenderRubyRun (anonymous) at (197,0) size 72x31
-            RenderRubyText {RT} at (0,0) size 72x13
+          RenderRubyRun (anonymous) at (197,13) size 72x18
+            RenderRubyText {RT} at (0,-13) size 72x13
               RenderText {#text} at (0,0) size 72x13
                 text run at (0,0) width 72: "Markup Language"
-            RenderRubyBase (anonymous) at (0,13) size 72x18
+            RenderRubyBase (anonymous) at (0,0) size 72x18
               RenderText {#text} at (24,0) size 24x18
                 text run at (24,0) width 24: "ML"
           RenderRubyRun (anonymous) at (269,13) size 8x18
diff --git a/LayoutTests/platform/mac/fast/ruby/rubyDOM-insert-text2-expected.txt b/LayoutTests/platform/mac/fast/ruby/rubyDOM-insert-text2-expected.txt
index 5c9b9f0..0f79fa2 100644
--- a/LayoutTests/platform/mac/fast/ruby/rubyDOM-insert-text2-expected.txt
+++ b/LayoutTests/platform/mac/fast/ruby/rubyDOM-insert-text2-expected.txt
@@ -17,11 +17,11 @@ layer at (0,0) size 800x600
         RenderText {#text} at (0,13) size 155x18
           text run at (0,13) width 155: "<ruby> is defined in the "
         RenderRuby (inline) {RUBY} at (0,0) size 125x18
-          RenderRubyRun (anonymous) at (155,0) size 117x31
-            RenderRubyText {RT} at (0,0) size 117x13
+          RenderRubyRun (anonymous) at (155,13) size 117x18
+            RenderRubyText {RT} at (0,-13) size 117x13
               RenderText {#text} at (0,0) size 117x13
                 text run at (0,0) width 117: "Hyper-text Markup Language"
-            RenderRubyBase (anonymous) at (0,13) size 117x18
+            RenderRubyBase (anonymous) at (0,0) size 117x18
               RenderInline {SPAN} at (0,0) size 22x18
                 RenderText {#text} at (35,0) size 22x18
                   text run at (35,0) width 22: "HT"
@@ -37,11 +37,11 @@ layer at (0,0) size 800x600
         RenderText {#text} at (0,13) size 155x18
           text run at (0,13) width 155: "<ruby> is defined in the "
         RenderRuby (inline) {RUBY} at (0,0) size 125x18
-          RenderRubyRun (anonymous) at (155,0) size 117x31
-            RenderRubyText {RT} at (0,0) size 117x13
+          RenderRubyRun (anonymous) at (155,13) size 117x18
+            RenderRubyText {RT} at (0,-13) size 117x13
               RenderText {#text} at (0,0) size 117x13
                 text run at (0,0) width 117: "Hyper-text Markup Language"
-            RenderRubyBase (anonymous) at (0,13) size 117x18
+            RenderRubyBase (anonymous) at (0,0) size 117x18
               RenderText {#text} at (35,0) size 46x18
                 text run at (35,0) width 46: "HTML"
               RenderInline {SPAN} at (0,0) size 0x18
diff --git a/LayoutTests/platform/mac/fast/ruby/rubyDOM-insert-text3-expected.txt b/LayoutTests/platform/mac/fast/ruby/rubyDOM-insert-text3-expected.txt
index d97bc5a..517490e 100644
--- a/LayoutTests/platform/mac/fast/ruby/rubyDOM-insert-text3-expected.txt
+++ b/LayoutTests/platform/mac/fast/ruby/rubyDOM-insert-text3-expected.txt
@@ -16,11 +16,11 @@ layer at (0,0) size 800x600
         RenderText {#text} at (0,13) size 155x18
           text run at (0,13) width 155: "<ruby> is defined in the "
         RenderRuby (inline) {RUBY} at (0,0) size 125x18
-          RenderRubyRun (anonymous) at (155,0) size 117x31
-            RenderRubyText {RT} at (0,0) size 117x13
+          RenderRubyRun (anonymous) at (155,13) size 117x18
+            RenderRubyText {RT} at (0,-13) size 117x13
               RenderText {#text} at (0,0) size 117x13
                 text run at (0,0) width 117: "Hyper-text Markup Language"
-            RenderRubyBase (anonymous) at (0,13) size 117x18
+            RenderRubyBase (anonymous) at (0,0) size 117x18
               RenderText {#text} at (35,0) size 22x18
                 text run at (35,0) width 22: "HT"
               RenderInline {SPAN} at (0,0) size 24x18
@@ -36,11 +36,11 @@ layer at (0,0) size 800x600
         RenderText {#text} at (0,13) size 155x18
           text run at (0,13) width 155: "<ruby> is defined in the "
         RenderRuby (inline) {RUBY} at (0,0) size 125x18
-          RenderRubyRun (anonymous) at (155,0) size 117x31
-            RenderRubyText {RT} at (0,0) size 117x13
+          RenderRubyRun (anonymous) at (155,13) size 117x18
+            RenderRubyText {RT} at (0,-13) size 117x13
               RenderText {#text} at (0,0) size 117x13
                 text run at (0,0) width 117: "Hyper-text Markup Language"
-            RenderRubyBase (anonymous) at (0,13) size 117x18
+            RenderRubyBase (anonymous) at (0,0) size 117x18
               RenderText {#text} at (35,0) size 22x18
                 text run at (35,0) width 22: "HT"
               RenderInline {SPAN} at (0,0) size 24x18
diff --git a/LayoutTests/platform/mac/fast/ruby/rubyDOM-remove-rt1-expected.txt b/LayoutTests/platform/mac/fast/ruby/rubyDOM-remove-rt1-expected.txt
index e54e7d8..7fa0cff 100644
--- a/LayoutTests/platform/mac/fast/ruby/rubyDOM-remove-rt1-expected.txt
+++ b/LayoutTests/platform/mac/fast/ruby/rubyDOM-remove-rt1-expected.txt
@@ -16,11 +16,11 @@ layer at (0,0) size 800x600
         RenderText {#text} at (0,13) size 155x18
           text run at (0,13) width 155: "<ruby> is defined in the "
         RenderRuby (inline) {RUBY} at (0,0) size 125x18
-          RenderRubyRun (anonymous) at (155,0) size 117x31
-            RenderRubyText {RT} at (0,0) size 117x13
+          RenderRubyRun (anonymous) at (155,13) size 117x18
+            RenderRubyText {RT} at (0,-13) size 117x13
               RenderText {#text} at (0,0) size 117x13
                 text run at (0,0) width 117: "Hyper-text Markup Language"
-            RenderRubyBase (anonymous) at (0,13) size 117x18
+            RenderRubyBase (anonymous) at (0,0) size 117x18
               RenderText {#text} at (35,0) size 46x18
                 text run at (35,0) width 46: "HTML"
           RenderRubyRun (anonymous) at (272,13) size 8x18
@@ -33,11 +33,11 @@ layer at (0,0) size 800x600
         RenderText {#text} at (0,13) size 155x18
           text run at (0,13) width 155: "<ruby> is defined in the "
         RenderRuby (inline) {RUBY} at (0,0) size 125x18
-          RenderRubyRun (anonymous) at (155,0) size 117x31
-            RenderRubyText {RT} at (0,0) size 117x13
+          RenderRubyRun (anonymous) at (155,13) size 117x18
+            RenderRubyText {RT} at (0,-13) size 117x13
               RenderText {#text} at (0,0) size 117x13
                 text run at (0,0) width 117: "Hyper-text Markup Language"
-            RenderRubyBase (anonymous) at (0,13) size 117x18
+            RenderRubyBase (anonymous) at (0,0) size 117x18
               RenderText {#text} at (35,0) size 46x18
                 text run at (35,0) width 46: "HTML"
           RenderRubyRun (anonymous) at (272,13) size 8x18
diff --git a/LayoutTests/platform/mac/fast/ruby/rubyDOM-remove-rt2-expected.txt b/LayoutTests/platform/mac/fast/ruby/rubyDOM-remove-rt2-expected.txt
index 1de0864..72bae32 100644
--- a/LayoutTests/platform/mac/fast/ruby/rubyDOM-remove-rt2-expected.txt
+++ b/LayoutTests/platform/mac/fast/ruby/rubyDOM-remove-rt2-expected.txt
@@ -17,11 +17,11 @@ layer at (0,0) size 800x600
         RenderText {#text} at (0,13) size 155x18
           text run at (0,13) width 155: "<ruby> is defined in the "
         RenderRuby (inline) {RUBY} at (0,0) size 125x18
-          RenderRubyRun (anonymous) at (155,0) size 117x31
-            RenderRubyText {RT} at (0,0) size 117x13
+          RenderRubyRun (anonymous) at (155,13) size 117x18
+            RenderRubyText {RT} at (0,-13) size 117x13
               RenderText {#text} at (0,0) size 117x13
                 text run at (0,0) width 117: "Hyper-text Markup Language"
-            RenderRubyBase (anonymous) at (0,13) size 117x18
+            RenderRubyBase (anonymous) at (0,0) size 117x18
               RenderText {#text} at (35,0) size 22x18
                 text run at (35,0) width 22: "HT"
               RenderText {#text} at (57,0) size 24x18
@@ -36,11 +36,11 @@ layer at (0,0) size 800x600
         RenderText {#text} at (0,13) size 155x18
           text run at (0,13) width 155: "<ruby> is defined in the "
         RenderRuby (inline) {RUBY} at (0,0) size 125x18
-          RenderRubyRun (anonymous) at (155,0) size 117x31
-            RenderRubyText {RT} at (0,0) size 117x13
+          RenderRubyRun (anonymous) at (155,13) size 117x18
+            RenderRubyText {RT} at (0,-13) size 117x13
               RenderText {#text} at (0,0) size 117x13
                 text run at (0,0) width 117: "Hyper-text Markup Language"
-            RenderRubyBase (anonymous) at (0,13) size 117x18
+            RenderRubyBase (anonymous) at (0,0) size 117x18
               RenderText {#text} at (35,0) size 46x18
                 text run at (35,0) width 46: "HTML"
           RenderRubyRun (anonymous) at (272,13) size 8x18
diff --git a/LayoutTests/platform/mac/fast/ruby/rubyDOM-remove-text1-expected.txt b/LayoutTests/platform/mac/fast/ruby/rubyDOM-remove-text1-expected.txt
index 69cd32a..a0ade39 100644
--- a/LayoutTests/platform/mac/fast/ruby/rubyDOM-remove-text1-expected.txt
+++ b/LayoutTests/platform/mac/fast/ruby/rubyDOM-remove-text1-expected.txt
@@ -16,11 +16,11 @@ layer at (0,0) size 800x600
         RenderText {#text} at (0,13) size 155x18
           text run at (0,13) width 155: "<ruby> is defined in the "
         RenderRuby (inline) {RUBY} at (0,0) size 125x18
-          RenderRubyRun (anonymous) at (155,0) size 117x31
-            RenderRubyText {RT} at (0,0) size 117x13
+          RenderRubyRun (anonymous) at (155,13) size 117x18
+            RenderRubyText {RT} at (0,-13) size 117x13
               RenderText {#text} at (0,0) size 117x13
                 text run at (0,0) width 117: "Hyper-text Markup Language"
-            RenderRubyBase (anonymous) at (0,13) size 117x18
+            RenderRubyBase (anonymous) at (0,0) size 117x18
               RenderInline {SPAN} at (0,0) size 46x18
                 RenderText {#text} at (35,0) size 46x18
                   text run at (35,0) width 46: "HTML"
@@ -34,11 +34,11 @@ layer at (0,0) size 800x600
         RenderText {#text} at (0,13) size 155x18
           text run at (0,13) width 155: "<ruby> is defined in the "
         RenderRuby (inline) {RUBY} at (0,0) size 125x18
-          RenderRubyRun (anonymous) at (155,0) size 117x31
-            RenderRubyText {RT} at (0,0) size 117x13
+          RenderRubyRun (anonymous) at (155,13) size 117x18
+            RenderRubyText {RT} at (0,-13) size 117x13
               RenderText {#text} at (0,0) size 117x13
                 text run at (0,0) width 117: "Hyper-text Markup Language"
-            RenderRubyBase (anonymous) at (0,13) size 117x18
+            RenderRubyBase (anonymous) at (0,0) size 117x18
               RenderInline {SPAN} at (0,0) size 46x18
                 RenderText {#text} at (35,0) size 46x18
                   text run at (35,0) width 46: "HTML"
diff --git a/LayoutTests/platform/mac/fast/ruby/rubyDOM-remove-text2-expected.txt b/LayoutTests/platform/mac/fast/ruby/rubyDOM-remove-text2-expected.txt
index ef25b30..b5876e9 100644
--- a/LayoutTests/platform/mac/fast/ruby/rubyDOM-remove-text2-expected.txt
+++ b/LayoutTests/platform/mac/fast/ruby/rubyDOM-remove-text2-expected.txt
@@ -16,11 +16,11 @@ layer at (0,0) size 800x600
         RenderText {#text} at (0,0) size 155x18
           text run at (0,0) width 155: "<ruby> is defined in the "
         RenderRuby (inline) {RUBY} at (0,0) size 125x18
-          RenderRubyRun (anonymous) at (155,4) size 117x13
-            RenderRubyText {RT} at (0,0) size 117x13
+          RenderRubyRun (anonymous) at (155,17) size 117x0
+            RenderRubyText {RT} at (0,-13) size 117x13
               RenderText {#text} at (0,0) size 117x13
                 text run at (0,0) width 117: "Hyper-text Markup Language"
-            RenderRubyBase (anonymous) at (0,13) size 117x0
+            RenderRubyBase (anonymous) at (0,0) size 117x0
           RenderRubyRun (anonymous) at (272,0) size 8x18
             RenderRubyBase (anonymous) at (0,0) size 8x18
               RenderText {#text} at (0,0) size 8x18
@@ -31,8 +31,8 @@ layer at (0,0) size 800x600
         RenderText {#text} at (0,0) size 155x18
           text run at (0,0) width 155: "<ruby> is defined in the "
         RenderRuby (inline) {RUBY} at (0,0) size 125x18
-          RenderRubyRun (anonymous) at (155,4) size 117x13
-            RenderRubyText {RT} at (0,0) size 117x13
+          RenderRubyRun (anonymous) at (155,17) size 117x0
+            RenderRubyText {RT} at (0,-13) size 117x13
               RenderText {#text} at (0,0) size 117x13
                 text run at (0,0) width 117: "Hyper-text Markup Language"
           RenderRubyRun (anonymous) at (272,0) size 8x18
diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index 963b02c..71cce69 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,106 @@
+2010-11-18  Dave Hyatt  <hyatt at apple.com>
+
+        Reviewed by Dan Bernstein.
+
+        https://bugs.webkit.org/show_bug.cgi?id=49717
+        
+        Implement better behavior for the logical height and block direction spacing of ruby text and ruby
+        base text.
+
+        Added six new tests: ruby-auto-line-expansion.html (one version for each of the four writing modes) to
+        test ruby text accommodation and quirks-mode-ruby-spacing.html / quirks-mode-ruby-spacing-bt.html to test
+        that ruby doesn't reset line-height.
+
+        * css/html.css:
+        Remove the line-height:normal rule for <ruby>  This behavior was incorrect, since a <ruby> on a line
+        by itself in quirks mode would cause the overall line-height of the enclosing block to not be honored.
+
+        * rendering/InlineBox.h:
+        (WebCore::InlineBox::adjustBlockDirectionPosition):
+        Add adjustBlockDirectionPosition as a shorthand for calling adjustPosition with the correct delta (x or y)
+        depending on orientation.
+        
+        * rendering/InlineFlowBox.cpp:
+        (WebCore::InlineFlowBox::placeBoxesInBlockDirection):
+        placeBoxesInBlockDirection now looks for Ruby runs, and when it encounters them it sets a flag, containsRuby,
+        to true.  This flag is stored as a bit on the RootInlineBox and lets us know whether we need to do a later
+        crawl of the line boxes after they are positioned to see if all the Ruby texts fit or not.
+        
+        Add the notion of a lineTop and lineBottom that include margins, since flipped lines writing modes (lr and bt)
+        mess up the flipping otherwise.  These new variables are lineTopIncludingMargins and lineBottomIncludingMargins.
+        This is only relevant for replaced elements, since the block direction margins of inline flows are always 0.
+        
+        Because RenderRubyRun is implemented as an inline-block (this is probably not a behavior we want to keep long-term),
+        the line-height is propagated into the inline-block, and it ends up being counted as part of the overall lineTop
+        and lineBottom since it is inside the inline-block's height.  To prevent this from happening, we have to fake it
+        as though RenderRubyRun was just a normal inline.  We look at the line boxes of the ruby base and we push lineTop/Bottom
+        in by the leading on either side so that it isn't counted as part of lineTop and lineBottom.  This enables the later
+        Ruby code that examines the spacing between lines to not be fooled into thinking it can't intrude into an inline-block's
+        interior on a previous line.
+
+        (WebCore::InlineFlowBox::computeBlockDirectionRubyAdjustment):
+        This function computes the amount that a line box has to be moved in order to accommodate all of the Ruby texts on the
+        line.  With tb and rl writing modes, the Ruby is trying to fit between the current line and a previous line, and so
+        we're checking some highest previous position and computing the amount we have to move.
+        
+        For lr and bt writing modes, the lines are flipped relative to the block direction, so we are computing how much we have
+        to move the *following* line based off a lowest position.
+        
+        In all writing modes we will allow Ruby text to intrude into the padding of a block.
+        
+        * rendering/InlineFlowBox.h:
+        * rendering/RenderBlock.cpp:
+        (WebCore::RenderBlock::layoutBlockChildren):
+        Ruby text is now considered a special child that should be excluded from normal layout, margin collapsing and height
+        computations.  Rename the layoutLegend function to be more generalized and make it apply to both Ruby text and to
+        legends.  This means that the RenderRubyRun computes its logical height without any regard for the ruby text.
+
+        * rendering/RenderBlock.h:
+        (WebCore::RenderBlock::layoutSpecialExcludedChild):
+        layoutSpecialExcludedChild is the new version of layoutLegend and it is implemented by RenderFieldset and RenderRubyRun.
+
+        * rendering/RenderBlockLineLayout.cpp:
+        (WebCore::RenderBlock::layoutInlineChildren):
+        When we hit the end of line layout, if we're in lr or bt writing modes, we have to potentially grow the height of the block
+        to accommodate ruby text along the bottom side of the line.  We call computeBlockDirectionRubyAdjustment here in flipped lines
+        writing mode only, and then we increase the logical height of the block if necessary.
+
+        * rendering/RenderFieldset.cpp:
+        (WebCore::RenderFieldset::layoutSpecialExcludedChild):
+        * rendering/RenderFieldset.h:
+        No changes here other than the function rename.
+
+        * rendering/RenderRubyRun.cpp:
+        (WebCore::RenderRubyRun::staticCreateRubyRun):
+        Remove the hack that locked RenderRubyRun's writing mode to tb or rl, since it didn't really work anyway, and it isn't necessary
+        now that RenderRubyRun has its own layout method.
+    
+        (WebCore::RenderRubyRun::layoutSpecialExcludedChild):
+        RenderRubyRun lays out the ruby text here but doesn't do anything with its placement yet.  We wait until the base is positioned
+        and then handled positioning the RenderRubyText at the end of RenderRubyRun's layout method. 
+
+        (WebCore::RenderRubyRun::layout):
+        * rendering/RenderRubyRun.h:
+        RenderRubyRun now has its own layout method that calls the base class to get the RenderRubyBase positioned and then moves the
+        RenderRubyText such that its bottommost line box's bottom and the RenderRubyBase's topmost line box's line top are flush with
+        one another.  The RenderRubyText will commonly be positioned at a negative coordinate now and spill out of the RenderRubyRun
+        as overflow.
+
+        * rendering/RootInlineBox.cpp:
+        (WebCore::RootInlineBox::RootInlineBox):
+        Added the m_containsRuby bit for performance to avoid the extra pass to try to accommodate ruby texts when none are present.
+
+        (WebCore::RootInlineBox::adjustPosition):
+        Fixed a bug in adjustPosition where the lineTop, lineBottom and blockLogicalHeight values were always being augmented by dy
+        even in vertical writing modes (where dx needed to be used instead).
+
+        (WebCore::RootInlineBox::alignBoxesInBlockDirection):
+        (WebCore::RootInlineBox::blockDirectionRubyAdjustment):
+        * rendering/RootInlineBox.h:
+        (WebCore::RootInlineBox::containsRuby):
+        RootInlineBox now calls blockDirectionRubyAdjustment to determine the amount of additional spacing that has to exist between
+        the lines in order to accommodate all Ruby texts, and then it does adjustPosition to move the new line by the amount required.
+
 2010-11-18  Alexey Proskuryakov  <ap at apple.com>
 
         Reviewed by Geoffrey Garen.
diff --git a/WebCore/css/html.css b/WebCore/css/html.css
index d091806..3032302 100644
--- a/WebCore/css/html.css
+++ b/WebCore/css/html.css
@@ -725,6 +725,9 @@ a:-webkit-any-link:active {
 
 ruby, rt {
     text-indent: 0; /* blocks used for ruby rendering should not trigger this */
+}
+
+rt {
     line-height: normal;
 }
 
diff --git a/WebCore/rendering/InlineBox.h b/WebCore/rendering/InlineBox.h
index c5f1997..991a3ff 100644
--- a/WebCore/rendering/InlineBox.h
+++ b/WebCore/rendering/InlineBox.h
@@ -120,6 +120,13 @@ public:
         else
             adjustPosition(0, delta);
     }
+    void adjustBlockDirectionPosition(int delta)
+    {
+        if (isHorizontal())
+            adjustPosition(0, delta);
+        else
+            adjustPosition(delta, 0);
+    }
 
     virtual void paint(PaintInfo&, int tx, int ty);
     virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, int x, int y, int tx, int ty);
diff --git a/WebCore/rendering/InlineFlowBox.cpp b/WebCore/rendering/InlineFlowBox.cpp
index e67c751..ee9fe9f 100644
--- a/WebCore/rendering/InlineFlowBox.cpp
+++ b/WebCore/rendering/InlineFlowBox.cpp
@@ -32,6 +32,9 @@
 #include "RenderInline.h"
 #include "RenderLayer.h"
 #include "RenderListMarker.h"
+#include "RenderRubyBase.h"
+#include "RenderRubyRun.h"
+#include "RenderRubyText.h"
 #include "RenderTableCell.h"
 #include "RootInlineBox.h"
 #include "Text.h"
@@ -620,7 +623,8 @@ void InlineFlowBox::computeLogicalBoxHeights(int& maxPositionTop, int& maxPositi
     }
 }
 
-void InlineFlowBox::placeBoxesInBlockDirection(int top, int maxHeight, int maxAscent, bool strictMode, int& lineTop, int& lineBottom, bool& setLineTop, FontBaseline baselineType)
+void InlineFlowBox::placeBoxesInBlockDirection(int top, int maxHeight, int maxAscent, bool strictMode, int& lineTop, int& lineBottom, bool& setLineTop,
+                                               int& lineTopIncludingMargins, int& lineBottomIncludingMargins, bool& containsRuby, FontBaseline baselineType)
 {
     if (isRootInlineBox())
         setLogicalTop(top + maxAscent - baselinePosition(baselineType)); // Place our root box.
@@ -633,7 +637,8 @@ void InlineFlowBox::placeBoxesInBlockDirection(int top, int maxHeight, int maxAs
         // line-height).
         bool isInlineFlow = curr->isInlineFlowBox();
         if (isInlineFlow)
-            static_cast<InlineFlowBox*>(curr)->placeBoxesInBlockDirection(top, maxHeight, maxAscent, strictMode, lineTop, lineBottom, setLineTop, baselineType);
+            static_cast<InlineFlowBox*>(curr)->placeBoxesInBlockDirection(top, maxHeight, maxAscent, strictMode, lineTop, lineBottom, setLineTop,
+                                                                          lineTopIncludingMargins, lineBottomIncludingMargins, containsRuby, baselineType);
 
         bool childAffectsTopBottomPos = true;
         if (curr->logicalTop() == PositionTop)
@@ -648,6 +653,10 @@ void InlineFlowBox::placeBoxesInBlockDirection(int top, int maxHeight, int maxAs
         }
         
         int newLogicalTop = curr->logicalTop();
+        int newLogicalTopIncludingMargins;
+        int boxHeight = curr->logicalHeight();
+        int boxHeightIncludingMargins = boxHeight;
+            
         if (curr->isText() || curr->isInlineFlowBox()) {
             const Font& font = curr->renderer()->style(m_firstLine)->font();
             newLogicalTop += curr->baselinePosition(baselineType) - font.ascent(baselineType);
@@ -656,21 +665,43 @@ void InlineFlowBox::placeBoxesInBlockDirection(int top, int maxHeight, int maxAs
                 newLogicalTop -= boxObject->style(m_firstLine)->isHorizontalWritingMode() ? boxObject->borderTop() + boxObject->paddingTop() : 
                                  boxObject->borderRight() + boxObject->paddingRight();
             }
+            newLogicalTopIncludingMargins = newLogicalTop;
         } else if (!curr->renderer()->isBR()) {
             RenderBox* box = toRenderBox(curr->renderer());
-            newLogicalTop += box->style(m_firstLine)->isHorizontalWritingMode() ? box->marginTop() : box->marginRight();
+            newLogicalTopIncludingMargins = newLogicalTop;
+            int overSideMargin = curr->isHorizontal() ? box->marginTop() : box->marginRight();
+            int underSideMargin = curr->isHorizontal() ? box->marginBottom() : box->marginLeft();
+            newLogicalTop += overSideMargin;
+            boxHeightIncludingMargins += overSideMargin + underSideMargin;
         }
 
         curr->setLogicalTop(newLogicalTop);
 
         if (childAffectsTopBottomPos) {
-            int boxHeight = curr->logicalHeight();
+            if (curr->renderer()->isRubyRun()) {
+                // Treat the leading on the first and last lines of ruby runs as not being part of the overall lineTop/lineBottom.
+                // Really this is a workaround hack for the fact that ruby should have been done as line layout and not done using
+                // inline-block.
+                containsRuby = true;
+                RenderRubyRun* rubyRun = static_cast<RenderRubyRun*>(curr->renderer());
+                if (RenderRubyBase* rubyBase = rubyRun->rubyBase()) {
+                    int bottomRubyBaseLeading = (curr->logicalHeight() - rubyBase->logicalBottom()) + rubyBase->logicalHeight() - (rubyBase->lastRootBox() ? rubyBase->lastRootBox()->lineBottom() : 0);
+                    int topRubyBaseLeading = rubyBase->logicalTop() + (rubyBase->firstRootBox() ? rubyBase->firstRootBox()->lineTop() : 0);
+                    newLogicalTop += !renderer()->style()->isFlippedLinesWritingMode() ? topRubyBaseLeading : bottomRubyBaseLeading;
+                    boxHeight -= (topRubyBaseLeading + bottomRubyBaseLeading);
+                }
+            }
+            
             if (!setLineTop) {
                 setLineTop = true;
                 lineTop = newLogicalTop;
-            } else
+                lineTopIncludingMargins = min(lineTop, newLogicalTopIncludingMargins);
+            } else {
                 lineTop = min(lineTop, newLogicalTop);
+                lineTopIncludingMargins = min(lineTop, min(lineTopIncludingMargins, newLogicalTopIncludingMargins));
+            }
             lineBottom = max(lineBottom, newLogicalTop + boxHeight);
+            lineBottomIncludingMargins = max(lineBottom, max(lineBottomIncludingMargins, newLogicalTopIncludingMargins + boxHeightIncludingMargins));
         }
     }
 
@@ -682,13 +713,17 @@ void InlineFlowBox::placeBoxesInBlockDirection(int top, int maxHeight, int maxAs
             if (!setLineTop) {
                 setLineTop = true;
                 lineTop = logicalTop();
-            } else
+                lineTopIncludingMargins = lineTop;
+            } else {
                 lineTop = min(lineTop, logicalTop());
+                lineTopIncludingMargins = min(lineTop, lineTopIncludingMargins);
+            }
             lineBottom = max(lineBottom, logicalTop() + logicalHeight());
+            lineBottomIncludingMargins = max(lineBottom, lineBottomIncludingMargins);
         }
         
         if (renderer()->style()->isFlippedLinesWritingMode())
-            flipLinesInBlockDirection(lineTop, lineBottom);
+            flipLinesInBlockDirection(lineTopIncludingMargins, lineBottomIncludingMargins);
     }
 }
 
@@ -1170,6 +1205,40 @@ void InlineFlowBox::clearTruncation()
         box->clearTruncation();
 }
 
+int InlineFlowBox::computeBlockDirectionRubyAdjustment(int allowedPosition) const
+{
+    int result = 0;
+    for (InlineBox* curr = firstChild(); curr; curr = curr->nextOnLine()) {
+        if (curr->renderer()->isPositioned())
+            continue; // Positioned placeholders don't affect calculations.
+        
+        if (curr->isInlineFlowBox())
+            result = max(result, static_cast<InlineFlowBox*>(curr)->computeBlockDirectionRubyAdjustment(allowedPosition));
+        
+        if (curr->renderer()->isReplaced() && curr->renderer()->isRubyRun()) {
+            RenderRubyRun* rubyRun = static_cast<RenderRubyRun*>(curr->renderer());
+            RenderRubyText* rubyText = rubyRun->rubyText();
+            if (!rubyText)
+                continue;
+            
+            if (!rubyRun->style()->isFlippedLinesWritingMode()) {
+                int topOfFirstRubyTextLine = rubyText->logicalTop() + (rubyText->firstRootBox() ? rubyText->firstRootBox()->lineTop() : 0);
+                if (topOfFirstRubyTextLine >= 0)
+                    continue;
+                topOfFirstRubyTextLine += curr->logicalTop();
+                result = max(result, allowedPosition - topOfFirstRubyTextLine);
+            } else {
+                int bottomOfLastRubyTextLine = rubyText->logicalTop() + (rubyText->lastRootBox() ? rubyText->lastRootBox()->lineBottom() : rubyText->logicalHeight());
+                if (bottomOfLastRubyTextLine <= curr->logicalHeight())
+                    continue;
+                bottomOfLastRubyTextLine += curr->logicalTop();
+                result = max(result, bottomOfLastRubyTextLine - allowedPosition);
+            }
+        }
+    }
+    return result;
+}
+
 #ifndef NDEBUG
 
 void InlineFlowBox::checkConsistency() const
diff --git a/WebCore/rendering/InlineFlowBox.h b/WebCore/rendering/InlineFlowBox.h
index e3127af..6e06a75 100644
--- a/WebCore/rendering/InlineFlowBox.h
+++ b/WebCore/rendering/InlineFlowBox.h
@@ -160,10 +160,12 @@ public:
                                   bool strictMode, GlyphOverflowAndFallbackFontsMap&, FontBaseline, VerticalPositionCache&);
     void adjustMaxAscentAndDescent(int& maxAscent, int& maxDescent,
                                    int maxPositionTop, int maxPositionBottom);
-    void placeBoxesInBlockDirection(int logicalTop, int maxHeight, int maxAscent, bool strictMode, int& lineTop, int& lineBottom, bool& setLineTop, FontBaseline);
+    void placeBoxesInBlockDirection(int logicalTop, int maxHeight, int maxAscent, bool strictMode, int& lineTop, int& lineBottom, bool& setLineTop,
+                                    int& lineTopIncludingMargins, int& lineBottomIncludingMargins, bool& containsRuby, FontBaseline);
     void flipLinesInBlockDirection(int lineTop, int lineBottom);
     void computeBlockDirectionOverflow(int lineTop, int lineBottom, bool strictMode, GlyphOverflowAndFallbackFontsMap&);
     bool requiresIdeographicBaseline(const GlyphOverflowAndFallbackFontsMap&) const;
+    int computeBlockDirectionRubyAdjustment(int allowedPosition) const;
     
     void removeChild(InlineBox* child);
 
diff --git a/WebCore/rendering/RenderBlock.cpp b/WebCore/rendering/RenderBlock.cpp
index 5f73dc4..cc40465 100644
--- a/WebCore/rendering/RenderBlock.cpp
+++ b/WebCore/rendering/RenderBlock.cpp
@@ -1772,10 +1772,9 @@ void RenderBlock::layoutBlockChildren(bool relayoutChildren, int& maxFloatLogica
     MarginInfo marginInfo(this, beforeEdge, afterEdge);
 
     // Fieldsets need to find their legend and position it inside the border of the object.
-    // The legend then gets skipped during normal layout.
-    // FIXME: Make fieldsets work with block-flow.
-    // https://bugs.webkit.org/show_bug.cgi?id=46785
-    RenderObject* legend = layoutLegend(relayoutChildren);
+    // The legend then gets skipped during normal layout.  The same is true for ruby text.
+    // It doesn't get included in the normal layout process but is instead skipped.
+    RenderObject* childToExclude = layoutSpecialExcludedChild(relayoutChildren);
 
     int previousFloatLogicalBottom = 0;
     maxFloatLogicalBottom = 0;
@@ -1786,8 +1785,8 @@ void RenderBlock::layoutBlockChildren(bool relayoutChildren, int& maxFloatLogica
         RenderBox* child = next;
         next = child->nextSiblingBox();
 
-        if (legend == child)
-            continue; // Skip the legend, since it has already been positioned up in the fieldset's border.
+        if (childToExclude == child)
+            continue; // Skip this child, since it will be positioned by the specialized subclass (fieldsets and ruby runs).
 
         // Make sure we layout children if they need it.
         // FIXME: Technically percentage height objects only need a relayout if their percentage isn't going to be turned into
diff --git a/WebCore/rendering/RenderBlock.h b/WebCore/rendering/RenderBlock.h
index 645c0ec..5153218 100644
--- a/WebCore/rendering/RenderBlock.h
+++ b/WebCore/rendering/RenderBlock.h
@@ -298,6 +298,8 @@ protected:
     }
 #endif
 
+    void addOverflowFromBlockChildren();
+
 private:
     virtual RenderObjectChildList* virtualChildren() { return children(); }
     virtual const RenderObjectChildList* virtualChildren() const { return children(); }
@@ -336,8 +338,8 @@ private:
 
     virtual RootInlineBox* createRootInlineBox(); // Subclassed by SVG and Ruby.
 
-    // Called to lay out the legend for a fieldset.
-    virtual RenderObject* layoutLegend(bool /*relayoutChildren*/) { return 0; }
+    // Called to lay out the legend for a fieldset or the ruby text of a ruby run.
+    virtual RenderObject* layoutSpecialExcludedChild(bool /*relayoutChildren*/) { return 0; }
 
     struct FloatWithRect {
         FloatWithRect(RenderBox* f)
@@ -468,7 +470,6 @@ private:
     int afterSideLayoutOverflowForLine(RootInlineBox*) const;
     // End of functions defined in RenderBlockLineLayout.cpp.
 
-    void addOverflowFromBlockChildren();
     void addOverflowFromFloats();
 
     void paintFloats(PaintInfo&, int tx, int ty, bool preservePhase = false);
diff --git a/WebCore/rendering/RenderBlockLineLayout.cpp b/WebCore/rendering/RenderBlockLineLayout.cpp
index 544a1f5..e969a2a 100644
--- a/WebCore/rendering/RenderBlockLineLayout.cpp
+++ b/WebCore/rendering/RenderBlockLineLayout.cpp
@@ -908,8 +908,16 @@ void RenderBlock::layoutInlineChildren(bool relayoutChildren, int& repaintLogica
         }
     }
 
+    // Expand the last line to accommodate Ruby in flipped lines writing modes (the Ruby is on
+    // the after side in this case).
+    int lastLineRubyAdjustment = 0;
+    if (lastRootBox() && style()->isFlippedLinesWritingMode()) {
+        int lowestAllowedPosition = max(lastRootBox()->lineBottom(), logicalHeight() + paddingAfter());
+        lastLineRubyAdjustment = lastRootBox()->computeBlockDirectionRubyAdjustment(lowestAllowedPosition);
+    }
+    
     // Now add in the bottom border/padding.
-    setLogicalHeight(logicalHeight() + borderAfter() + paddingAfter() + scrollbarLogicalHeight());
+    setLogicalHeight(logicalHeight() + lastLineRubyAdjustment + borderAfter() + paddingAfter() + scrollbarLogicalHeight());
 
     if (!firstLineBox() && hasLineIfEmpty())
         setLogicalHeight(logicalHeight() + lineHeight(true, style()->isHorizontalWritingMode() ? HorizontalLine : VerticalLine, PositionOfInteriorLineBoxes));
diff --git a/WebCore/rendering/RenderFieldset.cpp b/WebCore/rendering/RenderFieldset.cpp
index 12386e9..c83396c 100644
--- a/WebCore/rendering/RenderFieldset.cpp
+++ b/WebCore/rendering/RenderFieldset.cpp
@@ -63,7 +63,7 @@ void RenderFieldset::computePreferredLogicalWidths()
     }
 }
 
-RenderObject* RenderFieldset::layoutLegend(bool relayoutChildren)
+RenderObject* RenderFieldset::layoutSpecialExcludedChild(bool relayoutChildren)
 {
     RenderBox* legend = findLegend();
     if (legend) {
diff --git a/WebCore/rendering/RenderFieldset.h b/WebCore/rendering/RenderFieldset.h
index bada78c..b340794 100644
--- a/WebCore/rendering/RenderFieldset.h
+++ b/WebCore/rendering/RenderFieldset.h
@@ -38,7 +38,7 @@ private:
     virtual const char* renderName() const { return "RenderFieldSet"; }
     virtual bool isFieldset() const { return true; }
 
-    virtual RenderObject* layoutLegend(bool relayoutChildren);
+    virtual RenderObject* layoutSpecialExcludedChild(bool relayoutChildren);
 
     virtual void computePreferredLogicalWidths();
     virtual bool avoidsFloats() const { return true; }
diff --git a/WebCore/rendering/RenderRubyRun.cpp b/WebCore/rendering/RenderRubyRun.cpp
index a83a3e2..a6d6ba0 100644
--- a/WebCore/rendering/RenderRubyRun.cpp
+++ b/WebCore/rendering/RenderRubyRun.cpp
@@ -220,17 +220,65 @@ RenderRubyRun* RenderRubyRun::staticCreateRubyRun(const RenderObject* parentRuby
     RefPtr<RenderStyle> newStyle = RenderStyle::create();
     newStyle->inheritFrom(parentRuby->style());
     newStyle->setDisplay(INLINE_BLOCK);
-    if (parentRuby->style()->isFlippedLinesWritingMode()) {
-        // Ruby text is always in the line direction, so invert our block flow relative to the parent to
-        // ensure that the Ruby ends up on the correct side.
-        if (parentRuby->style()->isHorizontalWritingMode())
-            newStyle->setWritingMode(TopToBottomWritingMode);
-        else
-            newStyle->setWritingMode(RightToLeftWritingMode);
-    }
-
     rr->setStyle(newStyle.release());
     return rr;
 }
 
+RenderObject* RenderRubyRun::layoutSpecialExcludedChild(bool relayoutChildren)
+{
+    // Don't bother positioning the RenderRubyRun yet.
+    RenderRubyText* rt = rubyText();
+    if (!rt)
+        return 0;
+    if (relayoutChildren)
+        rt->setChildNeedsLayout(true, false);
+    rt->layoutIfNeeded();
+    return rt;
+}
+
+void RenderRubyRun::layout()
+{
+    RenderBlock::layout();
+    
+    // Place the RenderRubyText such that its bottom is flush with the lineTop of the first line of the RenderRubyBase.
+    RenderRubyText* rt = rubyText();
+    if (!rt)
+        return;
+    
+    int lastLineRubyTextBottom = rt->logicalHeight();
+    int firstLineRubyTextTop = 0;
+    RootInlineBox* rootBox = rt->lastRootBox();
+    if (rootBox) {
+        // In order to align, we have to ignore negative leading.
+        firstLineRubyTextTop = rt->firstRootBox()->lineTop();
+        lastLineRubyTextBottom = rootBox->lineBottom();
+    }
+
+    if (!style()->isFlippedLinesWritingMode()) {
+        int firstLineTop = 0;
+        if (RenderRubyBase* rb = rubyBase()) {
+            RootInlineBox* rootBox = rb->firstRootBox();
+            if (rootBox)
+                firstLineTop = rootBox->lineTop();
+            firstLineTop += rb->logicalTop();
+        }
+        
+        rt->setLogicalTop(-lastLineRubyTextBottom + firstLineTop);
+    } else {
+        int lastLineBottom = logicalHeight();
+        if (RenderRubyBase* rb = rubyBase()) {
+            RootInlineBox* rootBox = rb->lastRootBox();
+            if (rootBox)
+                lastLineBottom = rootBox->lineBottom();
+            lastLineBottom += rb->logicalTop();
+        }
+
+        rt->setLogicalTop(-firstLineRubyTextTop + lastLineBottom);
+    }
+
+    // Update our overflow to account for the new RenderRubyText position.
+    m_overflow.clear();
+    addOverflowFromBlockChildren();
+}
+
 } // namespace WebCore
diff --git a/WebCore/rendering/RenderRubyRun.h b/WebCore/rendering/RenderRubyRun.h
index 222ddb6..d844bff 100644
--- a/WebCore/rendering/RenderRubyRun.h
+++ b/WebCore/rendering/RenderRubyRun.h
@@ -55,6 +55,9 @@ public:
     RenderRubyBase* rubyBase() const;
     RenderRubyBase* rubyBaseSafe(); // creates the base if it doesn't already exist
 
+    virtual RenderObject* layoutSpecialExcludedChild(bool relayoutChildren);
+    virtual void layout();
+
     virtual bool isChildAllowed(RenderObject*, RenderStyle*) const;
     virtual void addChild(RenderObject* child, RenderObject* beforeChild = 0);
     virtual void removeChild(RenderObject* child);
diff --git a/WebCore/rendering/RootInlineBox.cpp b/WebCore/rendering/RootInlineBox.cpp
index cdc6525..da7d037 100644
--- a/WebCore/rendering/RootInlineBox.cpp
+++ b/WebCore/rendering/RootInlineBox.cpp
@@ -48,6 +48,7 @@ RootInlineBox::RootInlineBox(RenderBlock* block)
     , m_paginationStrut(0)
     , m_blockLogicalHeight(0)
     , m_baselineType(AlphabeticBaseline)
+    , m_containsRuby(false)
 {
     setIsHorizontal(block->style()->isHorizontalWritingMode());
 }
@@ -199,9 +200,10 @@ bool RootInlineBox::nodeAtPoint(const HitTestRequest& request, HitTestResult& re
 void RootInlineBox::adjustPosition(int dx, int dy)
 {
     InlineFlowBox::adjustPosition(dx, dy);
-    m_lineTop += dy;
-    m_lineBottom += dy;
-    m_blockLogicalHeight += dy;
+    int blockDirectionDelta = isHorizontal() ? dy : dx;
+    m_lineTop += blockDirectionDelta;
+    m_lineBottom += blockDirectionDelta;
+    m_blockLogicalHeight += blockDirectionDelta;
 }
 
 void RootInlineBox::childRemoved(InlineBox* box)
@@ -244,11 +246,25 @@ int RootInlineBox::alignBoxesInBlockDirection(int heightOfBlock, GlyphOverflowAn
     int maxHeight = maxAscent + maxDescent;
     int lineTop = heightOfBlock;
     int lineBottom = heightOfBlock;
+    int lineTopIncludingMargins = heightOfBlock;
+    int lineBottomIncludingMargins = heightOfBlock;
     bool setLineTop = false;
-    placeBoxesInBlockDirection(heightOfBlock, maxHeight, maxAscent, noQuirksMode, lineTop, lineBottom, setLineTop, m_baselineType);
+    bool containsRuby = false;
+    placeBoxesInBlockDirection(heightOfBlock, maxHeight, maxAscent, noQuirksMode, lineTop, lineBottom, setLineTop,
+                               lineTopIncludingMargins, lineBottomIncludingMargins, containsRuby, m_baselineType);
     computeBlockDirectionOverflow(lineTop, lineBottom, noQuirksMode, textBoxDataMap);
     setLineTopBottomPositions(lineTop, lineBottom);
 
+    m_containsRuby = containsRuby;
+    
+    int rubyAdjustment = blockDirectionRubyAdjustment();
+    if (rubyAdjustment) {
+        // FIXME: Need to handle pagination here. We might have to move to the next page/column as a result of the
+        // ruby expansion.
+        adjustBlockDirectionPosition(rubyAdjustment);
+        heightOfBlock += rubyAdjustment;
+    }
+
     // Detect integer overflow.
     if (heightOfBlock > numeric_limits<int>::max() - maxHeight)
         return numeric_limits<int>::max();
@@ -256,6 +272,21 @@ int RootInlineBox::alignBoxesInBlockDirection(int heightOfBlock, GlyphOverflowAn
     return heightOfBlock + maxHeight;
 }
 
+int RootInlineBox::blockDirectionRubyAdjustment() const
+{
+    if (!renderer()->style()->isFlippedLinesWritingMode()) {
+        if (!containsRuby())
+            return 0;
+        int highestAllowedPosition = prevRootBox() ? min(prevRootBox()->lineBottom(), lineTop()) : block()->borderBefore();
+        return computeBlockDirectionRubyAdjustment(highestAllowedPosition);
+    } else if (prevRootBox() && prevRootBox()->containsRuby()) {
+        // We have to compute the Ruby expansion for the previous line to see how much we should move.
+        int lowestAllowedPosition = max(prevRootBox()->lineBottom(), lineTop());
+        return prevRootBox()->computeBlockDirectionRubyAdjustment(lowestAllowedPosition);
+    }
+    return 0;
+}
+
 GapRects RootInlineBox::lineSelectionGap(RenderBlock* rootBlock, const IntPoint& rootBlockPhysicalPosition, const IntSize& offsetFromRootBlock, 
                                          int selTop, int selHeight, const PaintInfo* paintInfo)
 {
diff --git a/WebCore/rendering/RootInlineBox.h b/WebCore/rendering/RootInlineBox.h
index 851b4b1..42ad4da 100644
--- a/WebCore/rendering/RootInlineBox.h
+++ b/WebCore/rendering/RootInlineBox.h
@@ -128,10 +128,14 @@ public:
     
     FontBaseline baselineType() const { return m_baselineType; }
 
+    bool containsRuby() const { return m_containsRuby; }
+
 private:
     bool hasEllipsisBox() const { return m_hasEllipsisBoxOrHyphen; }
     void setHasEllipsisBox(bool hasEllipsisBox) { m_hasEllipsisBoxOrHyphen = hasEllipsisBox; }
 
+    int blockDirectionRubyAdjustment() const;
+
     // Where this line ended.  The exact object and the position within that object are stored so that
     // we can create an InlineIterator beginning just after the end of this line.
     RenderObject* m_lineBreakObj;
@@ -153,6 +157,9 @@ private:
     // Whether or not this line uses alphabetic or ideographic baselines by default.
     FontBaseline m_baselineType;
     
+    // If the line contains any ruby runs, then this will be true.
+    bool m_containsRuby : 1;
+
     WTF::Unicode::Direction m_lineBreakBidiStatusEor : 5;
     WTF::Unicode::Direction m_lineBreakBidiStatusLastStrong : 5;
     WTF::Unicode::Direction m_lineBreakBidiStatusLast : 5;

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list