<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[176262] trunk</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/176262">176262</a></dd>
<dt>Author</dt> <dd>hyatt@apple.com</dd>
<dt>Date</dt> <dd>2014-11-18 09:54:52 -0800 (Tue, 18 Nov 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Improve Ruby selection (getting rid of overlap and improving gap filling)
https://bugs.webkit.org/show_bug.cgi?id=138250

Reviewed by Dean Jackson.

Source/WebCore:

* rendering/RenderBlock.cpp:
(WebCore::RenderBlock::selectionGaps):
(WebCore::RenderBlock::blockSelectionGaps):
Add Ruby text in along with the Ruby base.

* rendering/RenderBlockFlow.cpp:
(WebCore::RenderBlockFlow::inlineSelectionGaps):
Don't let block gaps get filled in here.

* rendering/RenderRubyBase.h:
Expose accessor to the ruby run.

* rendering/RenderRubyText.cpp:
(WebCore::RenderRubyText::rubyRun):
* rendering/RenderRubyText.h:
Add accessor to the ruby run.

* rendering/RootInlineBox.cpp:
(WebCore::RootInlineBox::selectionTop):
(WebCore::RootInlineBox::selectionBottom):
Improve selectionTop and selectionBottom of ruby bases to avoid the
ruby text. Improve the selectionTop and selectionBottom of ruby texts
to fill the gap up to the previous/next line as appropriate.

LayoutTests:

Added fast/repaint/selection-ruby-rl.html

* fast/repaint/selection-ruby-rl-expected.txt: Added.
* fast/repaint/selection-ruby-rl.html: Added.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCorerenderingRenderBlockcpp">trunk/Source/WebCore/rendering/RenderBlock.cpp</a></li>
<li><a href="#trunkSourceWebCorerenderingRenderBlockFlowcpp">trunk/Source/WebCore/rendering/RenderBlockFlow.cpp</a></li>
<li><a href="#trunkSourceWebCorerenderingRenderRubyBaseh">trunk/Source/WebCore/rendering/RenderRubyBase.h</a></li>
<li><a href="#trunkSourceWebCorerenderingRenderRubyTextcpp">trunk/Source/WebCore/rendering/RenderRubyText.cpp</a></li>
<li><a href="#trunkSourceWebCorerenderingRenderRubyTexth">trunk/Source/WebCore/rendering/RenderRubyText.h</a></li>
<li><a href="#trunkSourceWebCorerenderingRootInlineBoxcpp">trunk/Source/WebCore/rendering/RootInlineBox.cpp</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsfastrepaintselectionrubyrlexpectedtxt">trunk/LayoutTests/fast/repaint/selection-ruby-rl-expected.txt</a></li>
<li><a href="#trunkLayoutTestsfastrepaintselectionrubyrlhtml">trunk/LayoutTests/fast/repaint/selection-ruby-rl.html</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (176261 => 176262)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2014-11-18 17:45:00 UTC (rev 176261)
+++ trunk/LayoutTests/ChangeLog        2014-11-18 17:54:52 UTC (rev 176262)
</span><span class="lines">@@ -1,3 +1,15 @@
</span><ins>+2014-11-17  David Hyatt  &lt;hyatt@apple.com&gt;
+
+        Improve Ruby selection (getting rid of overlap and improving gap filling)
+        https://bugs.webkit.org/show_bug.cgi?id=138250
+
+        Reviewed by Dean Jackson.
+
+        Added fast/repaint/selection-ruby-rl.html
+
+        * fast/repaint/selection-ruby-rl-expected.txt: Added.
+        * fast/repaint/selection-ruby-rl.html: Added.
+
</ins><span class="cx"> 2014-11-18  Commit Queue  &lt;commit-queue@webkit.org&gt;
</span><span class="cx"> 
</span><span class="cx">         Unreviewed, rolling out r176218.
</span></span></pre></div>
<a id="trunkLayoutTestsfastrepaintselectionrubyrlexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/repaint/selection-ruby-rl-expected.txt (0 => 176262)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/repaint/selection-ruby-rl-expected.txt                                (rev 0)
+++ trunk/LayoutTests/fast/repaint/selection-ruby-rl-expected.txt        2014-11-18 17:54:52 UTC (rev 176262)
</span><span class="lines">@@ -0,0 +1,14 @@
</span><ins>+Testing both hit testing and painting of selection.
+Testing both hit testing and painting of selection.
+Testing both hit testing and painting of selection.Some ruby
+Testing both hit testing and painting of selection.
+Testing both hit testing and painting of selection.
+Testing both hit testing and painting of selection.
+Testing both hit testing and painting of selection.
+Testing both hit testing and painting of selection.
+Testing both hit testing and painting of selection.
+Testing both hit testing and painting of selection.
+(repaint rects
+  (rect 774 39 18 83)
+)
+
</ins></span></pre></div>
<a id="trunkLayoutTestsfastrepaintselectionrubyrlhtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/repaint/selection-ruby-rl.html (0 => 176262)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/repaint/selection-ruby-rl.html                                (rev 0)
+++ trunk/LayoutTests/fast/repaint/selection-ruby-rl.html        2014-11-18 17:54:52 UTC (rev 176262)
</span><span class="lines">@@ -0,0 +1,29 @@
</span><ins>+&lt;!doctype html&gt;
+&lt;html&gt;
+&lt;head&gt;
+&lt;script src=&quot;resources/text-based-repaint.js&quot;&gt;&lt;/script&gt;
+&lt;script&gt;
+function repaintTest() {
+    if (eventSender) {
+        eventSender.mouseMoveTo(790, 40);
+        eventSender.mouseDown();
+        eventSender.mouseMoveTo(790, 40);
+        eventSender.mouseMoveTo(790, 120);
+        eventSender.mouseUp();
+    }
+}
+&lt;/script&gt;
+
+&lt;/head&gt;
+&lt;body style=&quot;-webkit-writing-mode:vertical-rl&quot; onload=&quot;runRepaintTest()&quot;&gt;
+&lt;span&gt;Testing both hit testing&lt;/span&gt; and painting of selection.&lt;br&gt;
+Testing both hit testing and painting of selection.&lt;br&gt;
+&lt;ruby&gt;Testing both hit testing and painting of selection.&lt;rt&gt;Some ruby&lt;/rt&gt;&lt;/ruby&gt;&lt;br&gt;
+Testing both hit testing and painting of selection.&lt;br&gt;
+Testing both hit testing and painting of selection.&lt;br&gt;
+Testing both hit testing and painting of selection.&lt;br&gt;
+Testing both hit testing and painting of selection.&lt;br&gt;
+Testing both hit testing and painting of selection.&lt;br&gt;
+Testing both hit testing and painting of selection.&lt;br&gt;
+Testing both hit testing and painting of selection.&lt;br&gt;
+&lt;/body&gt;
</ins></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (176261 => 176262)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2014-11-18 17:45:00 UTC (rev 176261)
+++ trunk/Source/WebCore/ChangeLog        2014-11-18 17:54:52 UTC (rev 176262)
</span><span class="lines">@@ -1,3 +1,34 @@
</span><ins>+2014-11-17  David Hyatt  &lt;hyatt@apple.com&gt;
+
+        Improve Ruby selection (getting rid of overlap and improving gap filling)
+        https://bugs.webkit.org/show_bug.cgi?id=138250
+
+        Reviewed by Dean Jackson.
+
+        * rendering/RenderBlock.cpp:
+        (WebCore::RenderBlock::selectionGaps):
+        (WebCore::RenderBlock::blockSelectionGaps):
+        Add Ruby text in along with the Ruby base.
+
+        * rendering/RenderBlockFlow.cpp:
+        (WebCore::RenderBlockFlow::inlineSelectionGaps):
+        Don't let block gaps get filled in here.
+
+        * rendering/RenderRubyBase.h:
+        Expose accessor to the ruby run.
+
+        * rendering/RenderRubyText.cpp:
+        (WebCore::RenderRubyText::rubyRun):
+        * rendering/RenderRubyText.h:
+        Add accessor to the ruby run.
+
+        * rendering/RootInlineBox.cpp:
+        (WebCore::RootInlineBox::selectionTop):
+        (WebCore::RootInlineBox::selectionBottom):
+        Improve selectionTop and selectionBottom of ruby bases to avoid the
+        ruby text. Improve the selectionTop and selectionBottom of ruby texts
+        to fill the gap up to the previous/next line as appropriate.
+
</ins><span class="cx"> 2014-11-18  Shivakumar JM  &lt;shiva.jm@samsung.com&gt;
</span><span class="cx"> 
</span><span class="cx">         crypto: Use sequence&lt;&gt; instead of KeyUsage[] in IDL.
</span></span></pre></div>
<a id="trunkSourceWebCorerenderingRenderBlockcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/RenderBlock.cpp (176261 => 176262)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/RenderBlock.cpp        2014-11-18 17:45:00 UTC (rev 176261)
+++ trunk/Source/WebCore/rendering/RenderBlock.cpp        2014-11-18 17:54:52 UTC (rev 176262)
</span><span class="lines">@@ -1882,7 +1882,7 @@
</span><span class="cx">         result = blockSelectionGaps(rootBlock, rootBlockPhysicalPosition, offsetFromRootBlock, lastLogicalTop, lastLogicalLeft, lastLogicalRight, cache, paintInfo);
</span><span class="cx"> 
</span><span class="cx">     // Go ahead and fill the vertical gap all the way to the bottom of our block if the selection extends past our block.
</span><del>-    if (&amp;rootBlock == this &amp;&amp; (selectionState() != SelectionBoth &amp;&amp; selectionState() != SelectionEnd) &amp;&amp; !isRubyBase()) {
</del><ins>+    if (&amp;rootBlock == this &amp;&amp; (selectionState() != SelectionBoth &amp;&amp; selectionState() != SelectionEnd) &amp;&amp; !isRubyBase() &amp;&amp; !isRubyText()) {
</ins><span class="cx">         result.uniteCenter(blockSelectionGap(rootBlock, rootBlockPhysicalPosition, offsetFromRootBlock,
</span><span class="cx">             lastLogicalTop, lastLogicalLeft, lastLogicalRight, logicalHeight(), cache, paintInfo));
</span><span class="cx">     }
</span><span class="lines">@@ -1927,7 +1927,7 @@
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         bool paintsOwnSelection = curr-&gt;shouldPaintSelectionGaps() || curr-&gt;isTable(); // FIXME: Eventually we won't special-case table like this.
</span><del>-        bool fillBlockGaps = !isRubyBase() &amp;&amp; (paintsOwnSelection || (curr-&gt;canBeSelectionLeaf() &amp;&amp; childState != SelectionNone));
</del><ins>+        bool fillBlockGaps = (paintsOwnSelection || (curr-&gt;canBeSelectionLeaf() &amp;&amp; childState != SelectionNone)) &amp;&amp; !isRubyBase() &amp;&amp; !isRubyText();
</ins><span class="cx">         if (fillBlockGaps) {
</span><span class="cx">             // We need to fill the vertical gap above this object.
</span><span class="cx">             if (childState == SelectionEnd || childState == SelectionInside) {
</span></span></pre></div>
<a id="trunkSourceWebCorerenderingRenderBlockFlowcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/RenderBlockFlow.cpp (176261 => 176262)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/RenderBlockFlow.cpp        2014-11-18 17:45:00 UTC (rev 176261)
+++ trunk/Source/WebCore/rendering/RenderBlockFlow.cpp        2014-11-18 17:54:52 UTC (rev 176262)
</span><span class="lines">@@ -3012,7 +3012,7 @@
</span><span class="cx">         LayoutUnit selHeight = curr-&gt;selectionHeightAdjustedForPrecedingBlock();
</span><span class="cx"> 
</span><span class="cx">         if (!containsStart &amp;&amp; !lastSelectedLine &amp;&amp;
</span><del>-            selectionState() != SelectionStart &amp;&amp; selectionState() != SelectionBoth)
</del><ins>+            selectionState() != SelectionStart &amp;&amp; selectionState() != SelectionBoth &amp;&amp; !isRubyBase())
</ins><span class="cx">             result.uniteCenter(blockSelectionGap(rootBlock, rootBlockPhysicalPosition, offsetFromRootBlock, lastLogicalTop, lastLogicalLeft, lastLogicalRight, selTop, cache, paintInfo));
</span><span class="cx">         
</span><span class="cx">         LayoutRect logicalRect(curr-&gt;logicalLeft(), selTop, curr-&gt;logicalWidth(), selTop + selHeight);
</span></span></pre></div>
<a id="trunkSourceWebCorerenderingRenderRubyBaseh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/RenderRubyBase.h (176261 => 176262)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/RenderRubyBase.h        2014-11-18 17:45:00 UTC (rev 176261)
+++ trunk/Source/WebCore/rendering/RenderRubyBase.h        2014-11-18 17:54:52 UTC (rev 176262)
</span><span class="lines">@@ -43,6 +43,8 @@
</span><span class="cx">     virtual ~RenderRubyBase();
</span><span class="cx">     
</span><span class="cx">     virtual const char* renderName() const override { return &quot;RenderRubyBase (anonymous)&quot;; }
</span><ins>+    
+    RenderRubyRun* rubyRun() const;
</ins><span class="cx"> 
</span><span class="cx"> private:
</span><span class="cx">     virtual bool isRubyBase() const override { return true; }
</span><span class="lines">@@ -55,12 +57,12 @@
</span><span class="cx">     void moveInlineChildren(RenderRubyBase* toBase, RenderObject* beforeChild = 0);
</span><span class="cx">     void moveBlockChildren(RenderRubyBase* toBase, RenderObject* beforeChild = 0);
</span><span class="cx"> 
</span><del>-    RenderRubyRun* rubyRun() const;
-
</del><span class="cx">     // Allow RenderRubyRun to manipulate the children within ruby bases.
</span><span class="cx">     friend class RenderRubyRun;
</span><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> } // namespace WebCore
</span><span class="cx"> 
</span><ins>+SPECIALIZE_TYPE_TRAITS_RENDER_OBJECT(RenderRubyBase, isRubyBase())
+
</ins><span class="cx"> #endif // RenderRubyBase_h
</span></span></pre></div>
<a id="trunkSourceWebCorerenderingRenderRubyTextcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/RenderRubyText.cpp (176261 => 176262)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/RenderRubyText.cpp        2014-11-18 17:45:00 UTC (rev 176261)
+++ trunk/Source/WebCore/rendering/RenderRubyText.cpp        2014-11-18 17:54:52 UTC (rev 176262)
</span><span class="lines">@@ -32,6 +32,7 @@
</span><span class="cx"> #include &quot;config.h&quot;
</span><span class="cx"> 
</span><span class="cx"> #include &quot;RenderRubyText.h&quot;
</span><ins>+#include &quot;RenderRubyRun.h&quot;
</ins><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><span class="cx"> 
</span><span class="lines">@@ -44,6 +45,12 @@
</span><span class="cx"> {
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+RenderRubyRun* RenderRubyText::rubyRun() const
+{
+    ASSERT(parent());
+    return downcast&lt;RenderRubyRun&gt;(parent());
+}
+
</ins><span class="cx"> bool RenderRubyText::isChildAllowed(const RenderObject&amp; child, const RenderStyle&amp;) const
</span><span class="cx"> {
</span><span class="cx">     return child.isInline();
</span></span></pre></div>
<a id="trunkSourceWebCorerenderingRenderRubyTexth"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/RenderRubyText.h (176261 => 176262)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/RenderRubyText.h        2014-11-18 17:45:00 UTC (rev 176261)
+++ trunk/Source/WebCore/rendering/RenderRubyText.h        2014-11-18 17:54:52 UTC (rev 176262)
</span><span class="lines">@@ -43,6 +43,8 @@
</span><span class="cx">     Element&amp; element() const { return downcast&lt;Element&gt;(nodeForNonAnonymous()); }
</span><span class="cx"> 
</span><span class="cx">     virtual bool isChildAllowed(const RenderObject&amp;, const RenderStyle&amp;) const override;
</span><ins>+    
+    RenderRubyRun* rubyRun() const;
</ins><span class="cx"> 
</span><span class="cx"> private:
</span><span class="cx">     virtual const char* renderName() const override { return &quot;RenderRubyText&quot;; }
</span><span class="lines">@@ -56,4 +58,6 @@
</span><span class="cx"> 
</span><span class="cx"> } // namespace WebCore
</span><span class="cx"> 
</span><ins>+SPECIALIZE_TYPE_TRAITS_RENDER_OBJECT(RenderRubyText, isRubyText())
+
</ins><span class="cx"> #endif // RenderRubyText_h
</span></span></pre></div>
<a id="trunkSourceWebCorerenderingRootInlineBoxcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/RootInlineBox.cpp (176261 => 176262)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/RootInlineBox.cpp        2014-11-18 17:45:00 UTC (rev 176261)
+++ trunk/Source/WebCore/rendering/RootInlineBox.cpp        2014-11-18 17:54:52 UTC (rev 176262)
</span><span class="lines">@@ -34,6 +34,9 @@
</span><span class="cx"> #include &quot;PaintInfo.h&quot;
</span><span class="cx"> #include &quot;RenderFlowThread.h&quot;
</span><span class="cx"> #include &quot;RenderInline.h&quot;
</span><ins>+#include &quot;RenderRubyBase.h&quot;
+#include &quot;RenderRubyRun.h&quot;
+#include &quot;RenderRubyText.h&quot;
</ins><span class="cx"> #include &quot;RenderView.h&quot;
</span><span class="cx"> #include &quot;VerticalPositionCache.h&quot;
</span><span class="cx"> #include &lt;wtf/NeverDestroyed.h&gt;
</span><span class="lines">@@ -594,13 +597,41 @@
</span><span class="cx"> LayoutUnit RootInlineBox::selectionTop() const
</span><span class="cx"> {
</span><span class="cx">     LayoutUnit selectionTop = m_lineTop;
</span><del>-
</del><ins>+    
</ins><span class="cx">     if (m_hasAnnotationsBefore)
</span><span class="cx">         selectionTop -= !renderer().style().isFlippedLinesWritingMode() ? computeOverAnnotationAdjustment(m_lineTop) : computeUnderAnnotationAdjustment(m_lineTop);
</span><span class="cx"> 
</span><span class="cx">     if (renderer().style().isFlippedLinesWritingMode())
</span><span class="cx">         return selectionTop;
</span><span class="cx"> 
</span><ins>+    if (renderer().isRubyBase()) {
+        // The ruby base selection should avoid intruding into the ruby text. This is only the case if there is an actual ruby text above us.
+        RenderRubyBase* base = &amp;downcast&lt;RenderRubyBase&gt;(renderer());
+        RenderRubyRun* run = base-&gt;rubyRun();
+        if (run) {
+            RenderRubyText* text = run-&gt;rubyText();
+            if (text &amp;&amp; text-&gt;logicalTop() &lt; base-&gt;logicalTop()) {
+                // The ruby text is above the ruby base. Just return now in order to avoid painting on top of the ruby text.
+                return selectionTop;
+            }
+        }
+    } else if (renderer().isRubyText()) {
+        // The ruby text selection should go all the way to the selection top of the containing line.
+        RenderRubyText* text = &amp;downcast&lt;RenderRubyText&gt;(renderer());
+        RenderRubyRun* run = text-&gt;rubyRun();
+        if (run &amp;&amp; run-&gt;inlineBoxWrapper()) {
+            RenderRubyBase* base = run-&gt;rubyBase();
+            if (base &amp;&amp; text-&gt;logicalTop() &lt; base-&gt;logicalTop()) {
+                // The ruby text is above the ruby base.
+                const RootInlineBox&amp; containingLine = run-&gt;inlineBoxWrapper()-&gt;root();
+                LayoutUnit enclosingSelectionTop = containingLine.selectionTop();
+                LayoutUnit deltaBetweenObjects = text-&gt;logicalTop() + run-&gt;logicalTop();
+                LayoutUnit selectionTopInRubyTextCoords = enclosingSelectionTop - deltaBetweenObjects;
+                return std::min(selectionTop, selectionTopInRubyTextCoords);
+            }
+        }
+    }
+
</ins><span class="cx">     LayoutUnit prevBottom = prevRootBox() ? prevRootBox()-&gt;selectionBottom() : blockFlow().borderAndPaddingBefore();
</span><span class="cx">     if (prevBottom &lt; selectionTop &amp;&amp; blockFlow().containsFloats()) {
</span><span class="cx">         // This line has actually been moved further down, probably from a large line-height, but possibly because the
</span><span class="lines">@@ -649,9 +680,37 @@
</span><span class="cx"> 
</span><span class="cx">     if (m_hasAnnotationsAfter)
</span><span class="cx">         selectionBottom += !renderer().style().isFlippedLinesWritingMode() ? computeUnderAnnotationAdjustment(m_lineBottom) : computeOverAnnotationAdjustment(m_lineBottom);
</span><del>-
</del><ins>+    
</ins><span class="cx">     if (!renderer().style().isFlippedLinesWritingMode() || !nextRootBox())
</span><span class="cx">         return selectionBottom;
</span><ins>+    
+    if (renderer().isRubyBase()) {
+        // The ruby base selection should avoid intruding into the ruby text. This is only the case if there is an actual ruby text below us.
+        RenderRubyBase* base = &amp;downcast&lt;RenderRubyBase&gt;(renderer());
+        RenderRubyRun* run = base-&gt;rubyRun();
+        if (run) {
+            RenderRubyText* text = run-&gt;rubyText();
+            if (text &amp;&amp; text-&gt;logicalTop() &gt; base-&gt;logicalTop()) {
+                // The ruby text is below the ruby base. Just return now in order to avoid painting on top of the ruby text.
+                return selectionBottom;
+            }
+        }
+    } else if (renderer().isRubyText()) {
+        // The ruby text selection should go all the way to the selection bottom of the containing line.
+        RenderRubyText* text = &amp;downcast&lt;RenderRubyText&gt;(renderer());
+        RenderRubyRun* run = text-&gt;rubyRun();
+        if (run &amp;&amp; run-&gt;inlineBoxWrapper()) {
+            RenderRubyBase* base = run-&gt;rubyBase();
+            if (base &amp;&amp; text-&gt;logicalTop() &gt; base-&gt;logicalTop()) {
+                // The ruby text is above the ruby base.
+                const RootInlineBox&amp; containingLine = run-&gt;inlineBoxWrapper()-&gt;root();
+                LayoutUnit enclosingSelectionBottom = containingLine.selectionBottom();
+                LayoutUnit deltaBetweenObjects = text-&gt;logicalTop() + run-&gt;logicalTop();
+                LayoutUnit selectionBottomInRubyTextCoords = enclosingSelectionBottom - deltaBetweenObjects;
+                return std::min(selectionBottom, selectionBottomInRubyTextCoords);
+            }
+        }
+    }
</ins><span class="cx"> 
</span><span class="cx">     LayoutUnit nextTop = nextRootBox()-&gt;selectionTop();
</span><span class="cx">     if (nextTop &gt; selectionBottom &amp;&amp; blockFlow().containsFloats()) {
</span></span></pre>
</div>
</div>

</body>
</html>