<!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>[167652] 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/167652">167652</a></dd>
<dt>Author</dt> <dd>rego@igalia.com</dd>
<dt>Date</dt> <dd>2014-04-22 03:22:47 -0700 (Tue, 22 Apr 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>[CSS Regions] Selection highlight doesn't match DOM selection
https://bugs.webkit.org/show_bug.cgi?id=131511

Reviewed by David Hyatt.

Source/WebCore:
This patch implements a subtrees approach to fix selection interaction in CSS Regions.

The idea is to divide the Render tree in subtrees. One subtree will be the RenderView (which is always present),
then for each RenderNamedFlowThread (which are children of RenderView) we will have an extra subtree.

For each subtree it determines the start and end positions according to the DOM tree. So, every subtree will
always have a start and end position, and the selection algorithm will be able to reach the end from the start
without problems (this allows us to remove the changes introduced in <a href="http://trac.webkit.org/projects/webkit/changeset/155058">r155058</a>).

Then selection related methods in RenderView are adapted to ensure that they are called for each subtree. Making
the selection highlight to match DOM selection as expected.

Test: fast/regions/selection/selecting-text-including-region.html

* CMakeLists.txt: Add new class SelectionSubtreeRoot to build file.
* WebCore.vcxproj/WebCore.vcxproj: Ditto.
* WebCore.vcxproj/WebCore.vcxproj.filters: Ditto.
* WebCore.xcodeproj/project.pbxproj: Ditto.
* rendering/RenderNamedFlowThread.h: Inherit from SelectionSubtreeRoot.
* rendering/RenderObject.cpp:
(WebCore::RenderObject::selectionRoot): New method to return the RenderNamedFlowThread if any or the RenderView
otherwise.
(WebCore::RenderObject::selectionStartEnd): If it's inside a RenderNamedFlowThread use specific method instead
of the RenderView's one.
* rendering/RenderObject.h: Add new method signature.
* rendering/RenderView.cpp:
(WebCore::RenderView::selectionBounds): Adapt method to subtrees approach.
(WebCore::RenderView::subtreeSelectionBounds): Modify previous method in order to use SelectionSubtreeRoot
objects.
(WebCore::RenderView::repaintSelection): Adapt method to subtrees approach.
(WebCore::RenderView::repaintSubtreeSelection): Modify previous method in order to use SelectionSubtreeRoot
objects.
(getNextOrPrevRenderObjectBasedOnDirection): Deleted method from <a href="http://trac.webkit.org/projects/webkit/changeset/155058">r155058</a> as it is not needed anymore. Each
subtree will have start and end positions, so the selection algorithm will always find the end.
(WebCore::RenderView::setSelection): Adapt method to subtrees approach.
(WebCore::RenderView::splitSelectionBetweenSubtrees): Determine start and end positions for each subtree and
call setSubtreeSelection().
(WebCore::RenderView::setSubtreeSelection): Modify previous method in order to use SelectionSubtreeRoot objects.
* rendering/RenderView.h: Inherit from SelectionSubtreeRoot. Add signature for new helper methods receiving
SelectionSubtreeRoot objects.
* rendering/SelectionSubtreeRoot.cpp: Added.
(WebCore::SelectionSubtreeRoot::SelectionSubtreeRoot):
(WebCore::SelectionSubtreeRoot::selectionStartEndPositions):
* rendering/SelectionSubtreeRoot.h: Added. New class to identify root elements for the subtrees. With some basic
attributes and methods to store the start and end positions and offsets.
(WebCore::SelectionSubtreeRoot::selectionStart):
(WebCore::SelectionSubtreeRoot::selectionStartPos):
(WebCore::SelectionSubtreeRoot::selectionEnd):
(WebCore::SelectionSubtreeRoot::selectionEndPos):
(WebCore::SelectionSubtreeRoot::setSelectionStart):
(WebCore::SelectionSubtreeRoot::setSelectionStartPos):
(WebCore::SelectionSubtreeRoot::setSelectionEnd):
(WebCore::SelectionSubtreeRoot::setSelectionEndPos):

LayoutTests:
Add new test to check highlight of render objects moved under RenderNamedFlowThread in the render tree.

Updated some tests to avoid issues with selection gap filling in the new implementation.

* fast/regions/selection/selecting-text-including-region-expected.html: Added.
* fast/regions/selection/selecting-text-including-region.html: Added.
* fast/regions/selection/selecting-text-through-different-region-flows-2-expected.html: Updated.
* fast/regions/selection/selecting-text-through-different-region-flows-2.html: Updated.
* fast/regions/selection/selection-direction-expected.html: Updated.
* fast/regions/selection/selection-direction.html: Updated.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkLayoutTestsfastregionsselectionselectingtextthroughdifferentregionflows2expectedhtml">trunk/LayoutTests/fast/regions/selection/selecting-text-through-different-region-flows-2-expected.html</a></li>
<li><a href="#trunkLayoutTestsfastregionsselectionselectingtextthroughdifferentregionflows2html">trunk/LayoutTests/fast/regions/selection/selecting-text-through-different-region-flows-2.html</a></li>
<li><a href="#trunkLayoutTestsfastregionsselectionselectiondirectionexpectedhtml">trunk/LayoutTests/fast/regions/selection/selection-direction-expected.html</a></li>
<li><a href="#trunkLayoutTestsfastregionsselectionselectiondirectionhtml">trunk/LayoutTests/fast/regions/selection/selection-direction.html</a></li>
<li><a href="#trunkSourceWebCoreCMakeListstxt">trunk/Source/WebCore/CMakeLists.txt</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreWebCorevcxprojWebCorevcxproj">trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj</a></li>
<li><a href="#trunkSourceWebCoreWebCorevcxprojWebCorevcxprojfilters">trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj.filters</a></li>
<li><a href="#trunkSourceWebCoreWebCorexcodeprojprojectpbxproj">trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj</a></li>
<li><a href="#trunkSourceWebCorerenderingRenderNamedFlowThreadh">trunk/Source/WebCore/rendering/RenderNamedFlowThread.h</a></li>
<li><a href="#trunkSourceWebCorerenderingRenderObjectcpp">trunk/Source/WebCore/rendering/RenderObject.cpp</a></li>
<li><a href="#trunkSourceWebCorerenderingRenderObjecth">trunk/Source/WebCore/rendering/RenderObject.h</a></li>
<li><a href="#trunkSourceWebCorerenderingRenderViewcpp">trunk/Source/WebCore/rendering/RenderView.cpp</a></li>
<li><a href="#trunkSourceWebCorerenderingRenderViewh">trunk/Source/WebCore/rendering/RenderView.h</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsfastregionsselectionselectingtextincludingregionexpectedhtml">trunk/LayoutTests/fast/regions/selection/selecting-text-including-region-expected.html</a></li>
<li><a href="#trunkLayoutTestsfastregionsselectionselectingtextincludingregionhtml">trunk/LayoutTests/fast/regions/selection/selecting-text-including-region.html</a></li>
<li><a href="#trunkSourceWebCorerenderingSelectionSubtreeRootcpp">trunk/Source/WebCore/rendering/SelectionSubtreeRoot.cpp</a></li>
<li><a href="#trunkSourceWebCorerenderingSelectionSubtreeRooth">trunk/Source/WebCore/rendering/SelectionSubtreeRoot.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (167651 => 167652)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2014-04-22 08:29:23 UTC (rev 167651)
+++ trunk/LayoutTests/ChangeLog        2014-04-22 10:22:47 UTC (rev 167652)
</span><span class="lines">@@ -1,3 +1,21 @@
</span><ins>+2014-04-22  Manuel Rego Casasnovas  &lt;rego@igalia.com&gt;
+
+        [CSS Regions] Selection highlight doesn't match DOM selection
+        https://bugs.webkit.org/show_bug.cgi?id=131511
+
+        Reviewed by David Hyatt.
+
+        Add new test to check highlight of render objects moved under RenderNamedFlowThread in the render tree.
+
+        Updated some tests to avoid issues with selection gap filling in the new implementation.
+
+        * fast/regions/selection/selecting-text-including-region-expected.html: Added.
+        * fast/regions/selection/selecting-text-including-region.html: Added.
+        * fast/regions/selection/selecting-text-through-different-region-flows-2-expected.html: Updated.
+        * fast/regions/selection/selecting-text-through-different-region-flows-2.html: Updated.
+        * fast/regions/selection/selection-direction-expected.html: Updated.
+        * fast/regions/selection/selection-direction.html: Updated.
+
</ins><span class="cx"> 2014-04-21  Brent Fulgham  &lt;bfulgham@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [Mac] After a horizontal overflow scroll with a mechanical wheel mouse, vertical scrolling no longer works
</span></span></pre></div>
<a id="trunkLayoutTestsfastregionsselectionselectingtextincludingregionexpectedhtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/regions/selection/selecting-text-including-region-expected.html (0 => 167652)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/regions/selection/selecting-text-including-region-expected.html                                (rev 0)
+++ trunk/LayoutTests/fast/regions/selection/selecting-text-including-region-expected.html        2014-04-22 10:22:47 UTC (rev 167652)
</span><span class="lines">@@ -0,0 +1,74 @@
</span><ins>+&lt;!DOCTYPE html&gt;
+&lt;html&gt;
+&lt;head&gt;
+    &lt;script src=&quot;../resources/helper.js&quot;&gt;&lt;/script&gt;
+    &lt;link rel=&quot;stylesheet&quot; href=&quot;../resources/region-style.css&quot;&gt;&lt;/link&gt;
+    &lt;style&gt;
+        * {
+            margin: 0px;
+            padding: 0px;
+        }
+
+        body {
+            line-height: 20px;
+            font-size: 20px;
+            font-family: Ahem;
+        }
+
+        #outside-1 {
+            position: absolute;
+            top: 0px;
+        }
+
+        #outside-2 {
+            position: absolute;
+            top: 100px;
+        }
+
+        #region {
+            position: absolute;
+            top: 200px;
+            background-color: cyan;
+        }
+
+        #description {
+            position: absolute;
+            top: 350px;
+        }
+    &lt;/style&gt;
+    &lt;script&gt;
+        onMouseUpLogSelection(&quot;selected-content&quot;);
+    &lt;/script&gt;
+&lt;/head&gt;
+&lt;body onload=&quot;selectContentByIds('word1', 'word2');&quot; style=&quot;margin-top: 0;&quot;&gt;
+    &lt;div id=&quot;outside-1&quot; class=&quot;bigBox&quot;&gt;
+        X X X X X X X X
+        X X X X X X X X
+        X X X &lt;span id=&quot;word1&quot; class=&quot;token&quot;&gt;X&lt;/span&gt; X X X X
+        X X X X X X X X
+        X X X X X X X X
+    &lt;/div&gt;
+    &lt;div id=&quot;region&quot; class=&quot;bigBox&quot;&gt;
+        X X X X X X X X
+        X X X X X X X X
+        X X X X X X X X
+        X X X X X X X X
+        X X X X X X X X
+    &lt;/div&gt;
+    &lt;div id=&quot;outside-2&quot; class=&quot;bigBox&quot;&gt;
+        X X X X X X X X
+        X X X X X X X X
+        X X X &lt;span id=&quot;word2&quot; class=&quot;token&quot;&gt;X&lt;/span&gt; X X X X
+        X X X X X X X X
+        X X X X X X X X
+    &lt;/div&gt;
+    &lt;div id=&quot;description&quot; class=&quot;description&quot;&gt;
+        &lt;h1&gt;&lt;a href=&quot;https://bugs.webkit.org/show_bug.cgi?id=131511&quot;&gt;Bug #131511 - [CSS Regions] Selection highlight doesn't match DOM selection&lt;/a&gt;&lt;/h1&gt;
+        &lt;p&gt;This test checks the selection in 2 text wrapping a content node. If you select from &lt;span class=&quot;token&quot;&gt;X&lt;/span&gt; to &lt;span class=&quot;token&quot;&gt;X&lt;/span&gt; you will see that region text is highlighted and included in the selected content (because of the content of the region is between bot texts in the DOM).&lt;/p&gt;
+        &lt;dl&gt;
+            &lt;dt&gt;Selected content:&lt;/dt&gt;
+            &lt;dd id=&quot;selected-content&quot;&gt;&lt;/dd&gt;
+        &lt;/dl&gt;
+    &lt;/div&gt;
+&lt;/body&gt;
+&lt;/html&gt;
</ins></span></pre></div>
<a id="trunkLayoutTestsfastregionsselectionselectingtextincludingregionhtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/regions/selection/selecting-text-including-region.html (0 => 167652)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/regions/selection/selecting-text-including-region.html                                (rev 0)
+++ trunk/LayoutTests/fast/regions/selection/selecting-text-including-region.html        2014-04-22 10:22:47 UTC (rev 167652)
</span><span class="lines">@@ -0,0 +1,65 @@
</span><ins>+&lt;!DOCTYPE html&gt;
+&lt;html&gt;
+&lt;head&gt;
+    &lt;script src=&quot;../resources/helper.js&quot;&gt;&lt;/script&gt;
+    &lt;link rel=&quot;stylesheet&quot; href=&quot;../resources/region-style.css&quot;&gt;&lt;/link&gt;
+    &lt;style&gt;
+        * {
+            margin: 0px;
+            padding: 0px;
+        }
+
+        body {
+            line-height: 20px;
+            font-size: 20px;
+            font-family: Ahem;
+        }
+
+        #region {
+            background-color: cyan;
+        }
+
+        #description {
+            position: absolute;
+            top: 350px;
+        }
+    &lt;/style&gt;
+    &lt;script&gt;
+        onMouseUpLogSelection(&quot;selected-content&quot;);
+    &lt;/script&gt;
+&lt;/head&gt;
+&lt;body onload=&quot;selectContentByIds('word1', 'word2');&quot; style=&quot;margin-top: 0;&quot;&gt;
+    &lt;div class=&quot;bigBox float&quot;&gt;
+        X X X X X X X X
+        X X X X X X X X
+        X X X &lt;span id=&quot;word1&quot; class=&quot;token&quot;&gt;X&lt;/span&gt; X X X X
+        X X X X X X X X
+        X X X X X X X X
+    &lt;/div&gt;
+    &lt;div class=&quot;clear&quot;&gt;&lt;/div&gt;
+    &lt;div class=&quot;flowArticle&quot;&gt;
+        X X X X X X X X
+        X X X X X X X X
+        X X X X X X X X
+        X X X X X X X X
+        X X X X X X X X
+    &lt;/div&gt;
+    &lt;div class=&quot;bigBox float&quot;&gt;
+        X X X X X X X X
+        X X X X X X X X
+        X X X &lt;span id=&quot;word2&quot; class=&quot;token&quot;&gt;X&lt;/span&gt; X X X X
+        X X X X X X X X
+        X X X X X X X X
+    &lt;/div&gt;
+    &lt;div class=&quot;clear&quot;&gt;&lt;/div&gt;
+    &lt;div id=&quot;region&quot; class=&quot;regionArticle bigBox&quot;&gt;&lt;/div&gt;
+    &lt;div id=&quot;description&quot; class=&quot;description&quot;&gt;
+        &lt;h1&gt;&lt;a href=&quot;https://bugs.webkit.org/show_bug.cgi?id=131511&quot;&gt;Bug #131511 - [CSS Regions] Selection highlight doesn't match DOM selection&lt;/a&gt;&lt;/h1&gt;
+        &lt;p&gt;This test checks the selection in 2 text wrapping a content node. If you select from &lt;span class=&quot;token&quot;&gt;X&lt;/span&gt; to &lt;span class=&quot;token&quot;&gt;X&lt;/span&gt; you will see that region text is highlighted and included in the selected content (because of the content of the region is between bot texts in the DOM).&lt;/p&gt;
+        &lt;dl&gt;
+            &lt;dt&gt;Selected content:&lt;/dt&gt;
+            &lt;dd id=&quot;selected-content&quot;&gt;&lt;/dd&gt;
+        &lt;/dl&gt;
+    &lt;/div&gt;
+&lt;/body&gt;
+&lt;/html&gt;
</ins></span></pre></div>
<a id="trunkLayoutTestsfastregionsselectionselectingtextthroughdifferentregionflows2expectedhtml"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/fast/regions/selection/selecting-text-through-different-region-flows-2-expected.html (167651 => 167652)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/regions/selection/selecting-text-through-different-region-flows-2-expected.html        2014-04-22 08:29:23 UTC (rev 167651)
+++ trunk/LayoutTests/fast/regions/selection/selecting-text-through-different-region-flows-2-expected.html        2014-04-22 10:22:47 UTC (rev 167652)
</span><span class="lines">@@ -3,19 +3,56 @@
</span><span class="cx"> &lt;head&gt;
</span><span class="cx"> &lt;script src=&quot;../resources/helper.js&quot;&gt;&lt;/script&gt;
</span><span class="cx"> &lt;style&gt;
</span><del>-body { width: 600px; }
-#footNote { font-size: 13px; }
</del><ins>+* {
+    margin: 0px;
+    padding: 0px;
+    font-size: 20px;
+    font-family: Ahem;
+    line-height: 20px;
+}
+#content1 {
+    height: 100px;
+    width: 200px;
+    position: absolute;
+    top: 50px;
+}
+#nestedRegion {
+    height: 100px;
+    width: 200px;
+    color: red;
+    position: absolute;
+    top: 250px;
+}
+#content2 {
+    height: 100px;
+    width: 200px;
+    position: absolute;
+    top: 150px;
+}
</ins><span class="cx"> &lt;/style&gt;
</span><span class="cx"> &lt;/head&gt;
</span><span class="cx"> &lt;body onload=&quot;selectBaseAndExtent('start', 0, 'end', 1)&quot;&gt;
</span><del>-&lt;div id=&quot;content&quot;&gt;
-    &lt;h1 style=&quot;margin-top: 0px&quot;&gt;Selecting text through different CSS-Region flows&lt;/h1&gt;
-    &lt;div&gt;
-    This text contains a footnote as a nested region what is diplayed &lt;span id=&quot;start&quot;&gt;below&lt;span&gt; the article. (1) If you start selecting
-        text from this article until somewhere in the footnote and then click somewhere, the selection should be cleared.
-    &lt;/div&gt;
-    &lt;div id=&quot;footNote&quot;&gt;(1) This is a footnote. Footnotes can be quite long and go over several lines. This footnote
-    is nested inside the text &lt;span id=&quot;end&quot;&gt;above&lt;span&gt; and displayed here with the help of css-regions.&lt;/span&gt;&lt;/div&gt;
</del><ins>+&lt;h1&gt;Selecting text through different CSS-Region flows&lt;/h1&gt;
+&lt;div id=&quot;content1&quot;&gt;
+    X X X X X
+    X X X X X
+    X X &lt;span id=&quot;start&quot;&gt;X&lt;/span&gt; X X
+    X X X X X
+    X X X X XX
</ins><span class="cx"> &lt;/div&gt;
</span><ins>+&lt;div id=&quot;nestedRegion&quot;&gt;
+    X X X X X
+    X X X X X
+    X X &lt;span id=&quot;end&quot;&gt;X&lt;/span&gt; X X
+    X X X X X
+    X X X X X
+&lt;/div&gt;
+&lt;div id=&quot;content2&quot;&gt;
+    X X X X X
+    X X X X X
+    X X X X X
+    X X X X X
+    X X X X X
+&lt;/div&gt;
</ins><span class="cx"> &lt;/body&gt;
</span><span class="cx"> &lt;/html&gt;
</span></span></pre></div>
<a id="trunkLayoutTestsfastregionsselectionselectingtextthroughdifferentregionflows2html"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/fast/regions/selection/selecting-text-through-different-region-flows-2.html (167651 => 167652)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/regions/selection/selecting-text-through-different-region-flows-2.html        2014-04-22 08:29:23 UTC (rev 167651)
+++ trunk/LayoutTests/fast/regions/selection/selecting-text-through-different-region-flows-2.html        2014-04-22 10:22:47 UTC (rev 167652)
</span><span class="lines">@@ -3,31 +3,74 @@
</span><span class="cx"> &lt;head&gt;
</span><span class="cx"> &lt;script src=&quot;../resources/helper.js&quot;&gt;&lt;/script&gt;
</span><span class="cx"> &lt;style&gt;
</span><del>-body { width: 600px; }
</del><ins>+* {
+    margin: 0px;
+    padding: 0px;
+    font-size: 20px;
+    font-family: Ahem;
+    line-height: 20px;
+}
</ins><span class="cx"> 
</span><del>-#footNote {
-    -webkit-flow-into: footNote;
-    display: block;
-    font-size: 13px;
</del><ins>+#nestedRegion {
+    -webkit-flow-into: nestedRegion;
+    color: red;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-#footNoteRegion { -webkit-flow-from: footNote; }
-#content { -webkit-flow-into: content; }
-#region { -webkit-flow-from: content; }
</del><ins>+#content {
+    -webkit-flow-into: content;
+}
+
+#nestedRegionRegion {
+    -webkit-flow-from: nestedRegion;
+    height: 100px;
+    width: 200px;
+}
+#region {
+    -webkit-flow-from: content;
+    height: 200px;
+    width: 200px;
+}
+
+#content1 {
+    height: 100px;
+}
+
+#content2 {
+    height: 100px;
+}
+
+h1 {
+    height: 50px;
+}
</ins><span class="cx"> &lt;/style&gt;
</span><span class="cx"> &lt;/head&gt;
</span><span class="cx"> &lt;body&gt;
</span><span class="cx"> 
</span><ins>+&lt;h1&gt;Selecting text through different CSS-Region flows&lt;/h1&gt;
</ins><span class="cx"> &lt;div id=&quot;region&quot;&gt;&lt;/div&gt;
</span><del>-&lt;div id=&quot;footNoteRegion&quot;&gt;&lt;/div&gt;
</del><ins>+&lt;div id=&quot;nestedRegionRegion&quot;&gt;&lt;/div&gt;
</ins><span class="cx"> &lt;div id=&quot;content&quot;&gt;
</span><del>-    &lt;h1 style=&quot;margin-top: 0px&quot;&gt;Selecting text through different CSS-Region flows&lt;/h1&gt;
-    &lt;div id=&quot;contentText&quot;&gt;
-        This text contains a footnote as a nested region what is diplayed &lt;span id=&quot;start&quot;&gt;below&lt;/span&gt; the article. (1) &lt;span id=&quot;footNote&quot;&gt;
-        &lt;span&gt;&lt;span&gt;&lt;/span&gt;(1) This is a footnote. Footnotes can be quite long and go over several lines. This footnote
-        is nested inside the text &lt;span id=&quot;end&quot;&gt;above&lt;/span&gt; and displayed here with the help of css-regions.&lt;/span&gt;&lt;/span&gt; If you start selecting
-        text from this article until somewhere in the footnote and then click somewhere, the selection should be cleared.
</del><ins>+    &lt;div id=&quot;content1&quot;&gt;
+        X X X X X
+        X X X X X
+        X X &lt;span id=&quot;start&quot;&gt;X&lt;/span&gt; X X
+        X X X X X
+        X X X X XX
</ins><span class="cx">     &lt;/div&gt;
</span><ins>+    &lt;div id=&quot;nestedRegion&quot;&gt;
+        X X X X X
+        X X X X X
+        X X &lt;span id=&quot;end&quot;&gt;X&lt;/span&gt; X X
+        X X X X X
+        X X X X X
+    &lt;/div&gt;
+    &lt;div id=&quot;content2&quot;&gt;
+        X X X X X
+        X X X X X
+        X X X X X
+        X X X X X
+        X X X X X
+    &lt;/div&gt;
</ins><span class="cx"> &lt;/div&gt;
</span><span class="cx"> 
</span><span class="cx"> &lt;script&gt;
</span></span></pre></div>
<a id="trunkLayoutTestsfastregionsselectionselectiondirectionexpectedhtml"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/fast/regions/selection/selection-direction-expected.html (167651 => 167652)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/regions/selection/selection-direction-expected.html        2014-04-22 08:29:23 UTC (rev 167651)
+++ trunk/LayoutTests/fast/regions/selection/selection-direction-expected.html        2014-04-22 10:22:47 UTC (rev 167652)
</span><span class="lines">@@ -7,6 +7,7 @@
</span><span class="cx">             width: 200px;
</span><span class="cx">             position: absolute;
</span><span class="cx">             top: 100px;
</span><ins>+            color: red;
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         #outside {
</span><span class="lines">@@ -14,10 +15,14 @@
</span><span class="cx">             width: 200px;
</span><span class="cx">             position: absolute;
</span><span class="cx">             top: 0px;
</span><ins>+            color: green;
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         body {
</span><span class="cx">             margin-top: 0;
</span><ins>+            font-size: 20px;
+            font-family: Ahem;
+            line-height: 20px;
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         #description {
</span><span class="lines">@@ -25,14 +30,30 @@
</span><span class="cx">             position: absolute;
</span><span class="cx">             top: 200px;
</span><span class="cx">         }
</span><ins>+
+        h1 {
+            line-height: 50px;
+        }
</ins><span class="cx">     &lt;/style&gt;
</span><span class="cx"> &lt;/head&gt;
</span><del>-&lt;body onload=&quot;selectContentByRange(100, 10, 100, 110);&quot;&gt;
-    &lt;div id=&quot;region&quot;&gt;inside region inside region inside region inside region&lt;/div&gt;
-    &lt;div id=&quot;outside&quot;&gt;outside region outside region outside region outside region&lt;/div&gt;
</del><ins>+&lt;body onload=&quot;selectContentByRange(100, 50, 100, 150);&quot;&gt;
+    &lt;div id=&quot;region&quot;&gt;
+        X X X X X
+        X X X X X
+        X X X X X
+        X X X X X
+        X X X X XX
+    &lt;/div&gt;
+    &lt;div id=&quot;outside&quot;&gt;
+        X X X X X
+        X X X X X
+        X X X X X
+        X X X X X
+        X X X X X
+    &lt;/div&gt;
</ins><span class="cx">     &lt;div id=&quot;description&quot;&gt;
</span><span class="cx">         &lt;h1&gt;&lt;a href=&quot;https://bugs.webkit.org/show_bug.cgi?id=121501&quot;&gt;Bug #121501 - [CSS Regions] Layout Test for selection direction&lt;/a&gt;&lt;/h1&gt;
</span><del>-        &lt;p&gt;Selection is based in DOM tree, so if you select text from &quot;outside region&quot; to &quot;inside region&quot; the highlighted area is exactly the opposite to what the user is actually selecting.&lt;/p&gt;
</del><ins>+        &lt;p&gt;Selection is based in DOM tree, so if you select text from &quot;green&quot; to &quot;red&quot; the highlighted area is exactly the opposite to what the user is actually selecting.&lt;/p&gt;
</ins><span class="cx">     &lt;/div&gt;
</span><span class="cx"> &lt;/body&gt;
</span><span class="cx"> &lt;/html&gt;
</span></span></pre></div>
<a id="trunkLayoutTestsfastregionsselectionselectiondirectionhtml"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/fast/regions/selection/selection-direction.html (167651 => 167652)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/regions/selection/selection-direction.html        2014-04-22 08:29:23 UTC (rev 167651)
+++ trunk/LayoutTests/fast/regions/selection/selection-direction.html        2014-04-22 10:22:47 UTC (rev 167652)
</span><span class="lines">@@ -4,6 +4,7 @@
</span><span class="cx">     &lt;style&gt;
</span><span class="cx">         #source {
</span><span class="cx">             -webkit-flow-into: content;
</span><ins>+            color: red;
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         #region {
</span><span class="lines">@@ -15,24 +16,50 @@
</span><span class="cx">         #outside {
</span><span class="cx">             height: 100px;
</span><span class="cx">             width: 200px;
</span><ins>+            color: green;
+            float: left;
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         body {
</span><span class="cx">             margin-top: 0;
</span><ins>+            font-size: 20px;
+            font-family: Ahem;
+            line-height: 20px;
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         #description {
</span><span class="cx">             width: 600px;
</span><span class="cx">         }
</span><ins>+
+        h1 {
+            line-height: 50px;
+        }
+
+        .clear {
+            clear: both;
+        }
</ins><span class="cx">     &lt;/style&gt;
</span><span class="cx"> &lt;/head&gt;
</span><del>-&lt;body onload=&quot;selectContentByRange(100, 10, 100, 110);&quot;&gt;
-    &lt;div id=&quot;source&quot;&gt;inside region inside region inside region inside region&lt;/div&gt;
-    &lt;div id=&quot;outside&quot;&gt;outside region outside region outside region outside region&lt;/div&gt;
</del><ins>+&lt;body onload=&quot;selectContentByRange(100, 50, 100, 150);&quot;&gt;
+    &lt;div id=&quot;source&quot;&gt;
+        X X X X X
+        X X X X X
+        X X X X X
+        X X X X X
+        X X X X XX
+    &lt;/div&gt;
+    &lt;div id=&quot;outside&quot;&gt;
+        X X X X X
+        X X X X X
+        X X X X X
+        X X X X X
+        X X X X X
+    &lt;/div&gt;
+    &lt;div class=&quot;clear&quot;&gt;&lt;/div&gt;
</ins><span class="cx">     &lt;div id=&quot;region&quot;&gt;&lt;/div&gt;
</span><span class="cx">     &lt;div id=&quot;description&quot;&gt;
</span><span class="cx">         &lt;h1&gt;&lt;a href=&quot;https://bugs.webkit.org/show_bug.cgi?id=121501&quot;&gt;Bug #121501 - [CSS Regions] Layout Test for selection direction&lt;/a&gt;&lt;/h1&gt;
</span><del>-        &lt;p&gt;Selection is based in DOM tree, so if you select text from &quot;outside region&quot; to &quot;inside region&quot; the highlighted area is exactly the opposite to what the user is actually selecting.&lt;/p&gt;
</del><ins>+        &lt;p&gt;Selection is based in DOM tree, so if you select text from &quot;green&quot; to &quot;red&quot; the highlighted area is exactly the opposite to what the user is actually selecting.&lt;/p&gt;
</ins><span class="cx">     &lt;/div&gt;
</span><span class="cx"> &lt;/body&gt;
</span><span class="cx"> &lt;/html&gt;
</span></span></pre></div>
<a id="trunkSourceWebCoreCMakeListstxt"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/CMakeLists.txt (167651 => 167652)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/CMakeLists.txt        2014-04-22 08:29:23 UTC (rev 167651)
+++ trunk/Source/WebCore/CMakeLists.txt        2014-04-22 10:22:47 UTC (rev 167652)
</span><span class="lines">@@ -2340,6 +2340,7 @@
</span><span class="cx">     rendering/RenderVTTCue.cpp
</span><span class="cx">     rendering/RenderWidget.cpp
</span><span class="cx">     rendering/RootInlineBox.cpp
</span><ins>+    rendering/SelectionSubtreeRoot.cpp
</ins><span class="cx">     rendering/ScrollBehavior.cpp
</span><span class="cx">     rendering/SimpleLineLayout.cpp
</span><span class="cx">     rendering/SimpleLineLayoutFunctions.cpp
</span></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (167651 => 167652)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2014-04-22 08:29:23 UTC (rev 167651)
+++ trunk/Source/WebCore/ChangeLog        2014-04-22 10:22:47 UTC (rev 167652)
</span><span class="lines">@@ -1,3 +1,64 @@
</span><ins>+2014-04-22  Manuel Rego Casasnovas  &lt;rego@igalia.com&gt;
+
+        [CSS Regions] Selection highlight doesn't match DOM selection
+        https://bugs.webkit.org/show_bug.cgi?id=131511
+
+        Reviewed by David Hyatt.
+
+        This patch implements a subtrees approach to fix selection interaction in CSS Regions.
+
+        The idea is to divide the Render tree in subtrees. One subtree will be the RenderView (which is always present),
+        then for each RenderNamedFlowThread (which are children of RenderView) we will have an extra subtree.
+
+        For each subtree it determines the start and end positions according to the DOM tree. So, every subtree will
+        always have a start and end position, and the selection algorithm will be able to reach the end from the start
+        without problems (this allows us to remove the changes introduced in r155058).
+
+        Then selection related methods in RenderView are adapted to ensure that they are called for each subtree. Making
+        the selection highlight to match DOM selection as expected.
+
+        Test: fast/regions/selection/selecting-text-including-region.html
+
+        * CMakeLists.txt: Add new class SelectionSubtreeRoot to build file.
+        * WebCore.vcxproj/WebCore.vcxproj: Ditto.
+        * WebCore.vcxproj/WebCore.vcxproj.filters: Ditto.
+        * WebCore.xcodeproj/project.pbxproj: Ditto.
+        * rendering/RenderNamedFlowThread.h: Inherit from SelectionSubtreeRoot.
+        * rendering/RenderObject.cpp:
+        (WebCore::RenderObject::selectionRoot): New method to return the RenderNamedFlowThread if any or the RenderView
+        otherwise.
+        (WebCore::RenderObject::selectionStartEnd): If it's inside a RenderNamedFlowThread use specific method instead
+        of the RenderView's one.
+        * rendering/RenderObject.h: Add new method signature.
+        * rendering/RenderView.cpp:
+        (WebCore::RenderView::selectionBounds): Adapt method to subtrees approach.
+        (WebCore::RenderView::subtreeSelectionBounds): Modify previous method in order to use SelectionSubtreeRoot
+        objects.
+        (WebCore::RenderView::repaintSelection): Adapt method to subtrees approach.
+        (WebCore::RenderView::repaintSubtreeSelection): Modify previous method in order to use SelectionSubtreeRoot
+        objects.
+        (getNextOrPrevRenderObjectBasedOnDirection): Deleted method from r155058 as it is not needed anymore. Each
+        subtree will have start and end positions, so the selection algorithm will always find the end.
+        (WebCore::RenderView::setSelection): Adapt method to subtrees approach.
+        (WebCore::RenderView::splitSelectionBetweenSubtrees): Determine start and end positions for each subtree and
+        call setSubtreeSelection().
+        (WebCore::RenderView::setSubtreeSelection): Modify previous method in order to use SelectionSubtreeRoot objects.
+        * rendering/RenderView.h: Inherit from SelectionSubtreeRoot. Add signature for new helper methods receiving
+        SelectionSubtreeRoot objects.
+        * rendering/SelectionSubtreeRoot.cpp: Added.
+        (WebCore::SelectionSubtreeRoot::SelectionSubtreeRoot):
+        (WebCore::SelectionSubtreeRoot::selectionStartEndPositions):
+        * rendering/SelectionSubtreeRoot.h: Added. New class to identify root elements for the subtrees. With some basic
+        attributes and methods to store the start and end positions and offsets.
+        (WebCore::SelectionSubtreeRoot::selectionStart):
+        (WebCore::SelectionSubtreeRoot::selectionStartPos):
+        (WebCore::SelectionSubtreeRoot::selectionEnd):
+        (WebCore::SelectionSubtreeRoot::selectionEndPos):
+        (WebCore::SelectionSubtreeRoot::setSelectionStart):
+        (WebCore::SelectionSubtreeRoot::setSelectionStartPos):
+        (WebCore::SelectionSubtreeRoot::setSelectionEnd):
+        (WebCore::SelectionSubtreeRoot::setSelectionEndPos):
+
</ins><span class="cx"> 2014-04-21  Brent Fulgham  &lt;bfulgham@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [Mac] Follow-up: After a horizontal overflow scroll with a mechanical wheel mouse, vertical scrolling no longer works
</span></span></pre></div>
<a id="trunkSourceWebCoreWebCorevcxprojWebCorevcxproj"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj (167651 => 167652)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj        2014-04-22 08:29:23 UTC (rev 167651)
+++ trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj        2014-04-22 10:22:47 UTC (rev 167652)
</span><span class="lines">@@ -11299,6 +11299,7 @@
</span><span class="cx">       &lt;ExcludedFromBuild Condition=&quot;'$(Configuration)|$(Platform)'=='Production|Win32'&quot;&gt;true&lt;/ExcludedFromBuild&gt;
</span><span class="cx">       &lt;ExcludedFromBuild Condition=&quot;'$(Configuration)|$(Platform)'=='Production|x64'&quot;&gt;true&lt;/ExcludedFromBuild&gt;
</span><span class="cx">     &lt;/ClCompile&gt;
</span><ins>+    &lt;ClCompile Include=&quot;..\rendering\SelectionSubtreeRoot.cpp&quot; /&gt;
</ins><span class="cx">     &lt;ClCompile Include=&quot;..\rendering\SimpleLineLayout.cpp&quot; /&gt;
</span><span class="cx">     &lt;ClCompile Include=&quot;..\rendering\SimpleLineLayoutFunctions.cpp&quot; /&gt;
</span><span class="cx">     &lt;ClCompile Include=&quot;..\rendering\TextPaintStyle.cpp&quot; /&gt;
</span><span class="lines">@@ -20097,6 +20098,7 @@
</span><span class="cx">     &lt;ClInclude Include=&quot;..\rendering\RenderWidget.h&quot; /&gt;
</span><span class="cx">     &lt;ClInclude Include=&quot;..\rendering\RootInlineBox.h&quot; /&gt;
</span><span class="cx">     &lt;ClInclude Include=&quot;..\rendering\ScrollBehavior.h&quot; /&gt;
</span><ins>+    &lt;ClInclude Include=&quot;..\rendering\SelectionSubtreeRoot.h&quot; /&gt;
</ins><span class="cx">     &lt;ClInclude Include=&quot;..\rendering\SimpleLineLayout.h&quot; /&gt;
</span><span class="cx">     &lt;ClInclude Include=&quot;..\rendering\SimpleLineLayoutFunctions.h&quot; /&gt;
</span><span class="cx">     &lt;ClInclude Include=&quot;..\rendering\SimpleLineLayoutResolver.h&quot; /&gt;
</span></span></pre></div>
<a id="trunkSourceWebCoreWebCorevcxprojWebCorevcxprojfilters"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj.filters (167651 => 167652)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj.filters        2014-04-22 08:29:23 UTC (rev 167651)
+++ trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj.filters        2014-04-22 10:22:47 UTC (rev 167652)
</span><span class="lines">@@ -6952,6 +6952,9 @@
</span><span class="cx">     &lt;ClCompile Include=&quot;..\platform\graphics\cairo\TiledBackingStoreBackendCairo.cpp&quot;&gt;
</span><span class="cx">       &lt;Filter&gt;platform\graphics\cairo&lt;/Filter&gt;
</span><span class="cx">     &lt;/ClCompile&gt;
</span><ins>+    &lt;ClCompile Include=&quot;..\rendering\SelectionSubtreeRoot.cpp&quot;&gt;
+      &lt;Filter&gt;rendering&lt;/Filter&gt;
+    &lt;/ClCompile&gt;
</ins><span class="cx">     &lt;ClCompile Include=&quot;..\rendering\SimpleLineLayout.cpp&quot;&gt;
</span><span class="cx">       &lt;Filter&gt;rendering&lt;/Filter&gt;
</span><span class="cx">     &lt;/ClCompile&gt;
</span><span class="lines">@@ -14808,6 +14811,9 @@
</span><span class="cx">     &lt;ClInclude Include=&quot;..\rendering\SimpleLineLayoutResolver.h&quot;&gt;
</span><span class="cx">       &lt;Filter&gt;rendering&lt;/Filter&gt;
</span><span class="cx">     &lt;/ClInclude&gt;
</span><ins>+    &lt;ClInclude Include=&quot;..\rendering\SelectionSubtreeRoot.h&quot;&gt;
+      &lt;Filter&gt;rendering&lt;/Filter&gt;
+    &lt;/ClInclude&gt;
</ins><span class="cx">     &lt;ClInclude Include=&quot;..\rendering\SimpleLineLayout.h&quot;&gt;
</span><span class="cx">       &lt;Filter&gt;rendering&lt;/Filter&gt;
</span><span class="cx">     &lt;/ClInclude&gt;
</span></span></pre></div>
<a id="trunkSourceWebCoreWebCorexcodeprojprojectpbxproj"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (167651 => 167652)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj        2014-04-22 08:29:23 UTC (rev 167651)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj        2014-04-22 10:22:47 UTC (rev 167652)
</span><span class="lines">@@ -5628,6 +5628,8 @@
</span><span class="cx">                 CDC8B5AD1804AE5D0016E685 /* SourceBufferPrivateClient.h in Headers */ = {isa = PBXBuildFile; fileRef = CDC8B5AC1804AE5D0016E685 /* SourceBufferPrivateClient.h */; };
</span><span class="cx">                 CDCA82961679100F00875714 /* TextTrackRepresentationIOS.mm in Sources */ = {isa = PBXBuildFile; fileRef = CDCA82941679100F00875714 /* TextTrackRepresentationIOS.mm */; };
</span><span class="cx">                 CDCA98EB18B2C8EB00C12FF9 /* CDMPrivateMediaPlayer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CDCA98EA18B2C8EB00C12FF9 /* CDMPrivateMediaPlayer.cpp */; };
</span><ins>+                CDCFABBD18C0AF78006F8450 /* SelectionSubtreeRoot.h in Headers */ = {isa = PBXBuildFile; fileRef = CDCFABBB18C0AE31006F8450 /* SelectionSubtreeRoot.h */; settings = {ATTRIBUTES = (Private, ); }; };
+                CDCFABBE18C0AF84006F8450 /* SelectionSubtreeRoot.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CDCFABBC18C0AF19006F8450 /* SelectionSubtreeRoot.cpp */; };
</ins><span class="cx">                 CDD525D7145B6DD0008D204D /* JSHTMLMediaElementCustom.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CDF65CCC145B6AFE00C4C7AA /* JSHTMLMediaElementCustom.cpp */; };
</span><span class="cx">                 CDD7089618359F6F002B3DC6 /* SampleMap.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CDD7089418359F6E002B3DC6 /* SampleMap.cpp */; };
</span><span class="cx">                 CDD7089718359F6F002B3DC6 /* SampleMap.h in Headers */ = {isa = PBXBuildFile; fileRef = CDD7089518359F6F002B3DC6 /* SampleMap.h */; };
</span><span class="lines">@@ -12992,6 +12994,8 @@
</span><span class="cx">                 CDCA98E918B2C8D000C12FF9 /* CDMPrivateMediaPlayer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CDMPrivateMediaPlayer.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 CDCA98EA18B2C8EB00C12FF9 /* CDMPrivateMediaPlayer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CDMPrivateMediaPlayer.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 CDCE5CD014633BC900D47CCA /* EventTargetFactory.in */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = EventTargetFactory.in; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><ins>+                CDCFABBB18C0AE31006F8450 /* SelectionSubtreeRoot.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SelectionSubtreeRoot.h; sourceTree = &quot;&lt;group&gt;&quot;; };
+                CDCFABBC18C0AF19006F8450 /* SelectionSubtreeRoot.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SelectionSubtreeRoot.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</ins><span class="cx">                 CDD1E525167BA56400CE820B /* TextTrackRepresentation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TextTrackRepresentation.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 CDD7089418359F6E002B3DC6 /* SampleMap.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SampleMap.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 CDD7089518359F6F002B3DC6 /* SampleMap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SampleMap.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="lines">@@ -22121,6 +22125,8 @@
</span><span class="cx">                                 A8CFF5DA0A155A05000A4234 /* RootInlineBox.h */,
</span><span class="cx">                                 5D925B650F64D4DD00B847F0 /* ScrollBehavior.cpp */,
</span><span class="cx">                                 5D925B660F64D4DD00B847F0 /* ScrollBehavior.h */,
</span><ins>+                                CDCFABBC18C0AF19006F8450 /* SelectionSubtreeRoot.cpp */,
+                                CDCFABBB18C0AE31006F8450 /* SelectionSubtreeRoot.h */,
</ins><span class="cx">                                 E48944A0180B57D800F165D8 /* SimpleLineLayout.cpp */,
</span><span class="cx">                                 E48944A1180B57D800F165D8 /* SimpleLineLayout.h */,
</span><span class="cx">                                 E4E9B11A18145692003ACCDF /* SimpleLineLayoutFunctions.cpp */,
</span><span class="lines">@@ -25837,6 +25843,7 @@
</span><span class="cx">                                 2D3A0E3613A7D76100E85AF0 /* SVGParsingError.h in Headers */,
</span><span class="cx">                                 A10DBF4718F92317000D70C6 /* QuickLookHandleClient.h in Headers */,
</span><span class="cx">                                 84C6784D1214814700A92902 /* SVGPathBlender.h in Headers */,
</span><ins>+                                CDCFABBD18C0AF78006F8450 /* SelectionSubtreeRoot.h in Headers */,
</ins><span class="cx">                                 8476C9EB11DF6A2900555B02 /* SVGPathBuilder.h in Headers */,
</span><span class="cx">                                 8419D2A7120D92D000141F8F /* SVGPathByteStream.h in Headers */,
</span><span class="cx">                                 8419D2A9120D92D000141F8F /* SVGPathByteStreamBuilder.h in Headers */,
</span><span class="lines">@@ -27965,6 +27972,7 @@
</span><span class="cx">                                 BCE1C43B0D9830D3003B02F2 /* JSLocation.cpp in Sources */,
</span><span class="cx">                                 BCE1C4400D9830F4003B02F2 /* JSLocationCustom.cpp in Sources */,
</span><span class="cx">                                 8FAC774D119872CB0015AE94 /* JSMainThreadExecState.cpp in Sources */,
</span><ins>+                                CDCFABBE18C0AF84006F8450 /* SelectionSubtreeRoot.cpp in Sources */,
</ins><span class="cx">                                 CD27F6E51457685A0078207D /* JSMediaController.cpp in Sources */,
</span><span class="cx">                                 CDAB6D2D17C814EE00C60B34 /* JSMediaControlsHost.cpp in Sources */,
</span><span class="cx">                                 FD23A12513F5FA5900F67001 /* JSMediaElementAudioSourceNode.cpp in Sources */,
</span></span></pre></div>
<a id="trunkSourceWebCorerenderingRenderNamedFlowThreadh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/RenderNamedFlowThread.h (167651 => 167652)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/RenderNamedFlowThread.h        2014-04-22 08:29:23 UTC (rev 167651)
+++ trunk/Source/WebCore/rendering/RenderNamedFlowThread.h        2014-04-22 10:22:47 UTC (rev 167652)
</span><span class="lines">@@ -28,6 +28,7 @@
</span><span class="cx"> #define RenderNamedFlowThread_h
</span><span class="cx"> 
</span><span class="cx"> #include &quot;RenderFlowThread.h&quot;
</span><ins>+#include &quot;SelectionSubtreeRoot.h&quot;
</ins><span class="cx"> #include &quot;Timer.h&quot;
</span><span class="cx"> #include &lt;wtf/HashCountedSet.h&gt;
</span><span class="cx"> #include &lt;wtf/ListHashSet.h&gt;
</span><span class="lines">@@ -43,7 +44,7 @@
</span><span class="cx"> typedef HashCountedSet&lt;RenderNamedFlowThread*&gt; RenderNamedFlowThreadCountedSet;
</span><span class="cx"> typedef ListHashSet&lt;Element*&gt; NamedFlowContentElements;
</span><span class="cx"> 
</span><del>-class RenderNamedFlowThread final : public RenderFlowThread {
</del><ins>+class RenderNamedFlowThread final : public RenderFlowThread, public SelectionSubtreeRoot {
</ins><span class="cx"> public:
</span><span class="cx">     RenderNamedFlowThread(Document&amp;, PassRef&lt;RenderStyle&gt;, PassRef&lt;WebKitNamedFlow&gt;);
</span><span class="cx">     virtual ~RenderNamedFlowThread();
</span></span></pre></div>
<a id="trunkSourceWebCorerenderingRenderObjectcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/RenderObject.cpp (167651 => 167652)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/RenderObject.cpp        2014-04-22 08:29:23 UTC (rev 167651)
+++ trunk/Source/WebCore/rendering/RenderObject.cpp        2014-04-22 10:22:47 UTC (rev 167652)
</span><span class="lines">@@ -1520,9 +1520,18 @@
</span><span class="cx">     return selectionColor(CSSPropertyWebkitTextEmphasisColor);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+SelectionSubtreeRoot&amp; RenderObject::selectionRoot() const
+{
+    RenderFlowThread* flowThread = flowThreadContainingBlock();
+    if (flowThread &amp;&amp; flowThread-&gt;isRenderNamedFlowThread())
+        return *toRenderNamedFlowThread(flowThread);
+
+    return view();
+}
+
</ins><span class="cx"> void RenderObject::selectionStartEnd(int&amp; spos, int&amp; epos) const
</span><span class="cx"> {
</span><del>-    view().selectionStartEnd(spos, epos);
</del><ins>+    selectionRoot().selectionStartEndPositions(spos, epos);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void RenderObject::handleDynamicFloatPositionChange()
</span></span></pre></div>
<a id="trunkSourceWebCorerenderingRenderObjecth"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/RenderObject.h (167651 => 167652)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/RenderObject.h        2014-04-22 08:29:23 UTC (rev 167651)
+++ trunk/Source/WebCore/rendering/RenderObject.h        2014-04-22 10:22:47 UTC (rev 167652)
</span><span class="lines">@@ -60,6 +60,7 @@
</span><span class="cx"> class RenderLayerModelObject;
</span><span class="cx"> class RenderNamedFlowThread;
</span><span class="cx"> class RenderTheme;
</span><ins>+class SelectionSubtreeRoot;
</ins><span class="cx"> class TransformState;
</span><span class="cx"> class VisiblePosition;
</span><span class="cx"> #if PLATFORM(IOS)
</span><span class="lines">@@ -850,6 +851,7 @@
</span><span class="cx">     virtual void imageChanged(CachedImage*, const IntRect* = 0) override;
</span><span class="cx">     virtual void imageChanged(WrappedImagePtr, const IntRect* = 0) { }
</span><span class="cx"> 
</span><ins>+    SelectionSubtreeRoot&amp; selectionRoot() const;
</ins><span class="cx">     void selectionStartEnd(int&amp; spos, int&amp; epos) const;
</span><span class="cx">     
</span><span class="cx">     void removeFromParent();
</span></span></pre></div>
<a id="trunkSourceWebCorerenderingRenderViewcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/RenderView.cpp (167651 => 167652)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/RenderView.cpp        2014-04-22 08:29:23 UTC (rev 167651)
+++ trunk/Source/WebCore/rendering/RenderView.cpp        2014-04-22 10:22:47 UTC (rev 167652)
</span><span class="lines">@@ -35,6 +35,7 @@
</span><span class="cx"> #include &quot;HTMLIFrameElement.h&quot;
</span><span class="cx"> #include &quot;HitTestResult.h&quot;
</span><span class="cx"> #include &quot;ImageQualityController.h&quot;
</span><ins>+#include &quot;NodeTraversal.h&quot;
</ins><span class="cx"> #include &quot;Page.h&quot;
</span><span class="cx"> #include &quot;RenderGeometryMap.h&quot;
</span><span class="cx"> #include &quot;RenderIterator.h&quot;
</span><span class="lines">@@ -660,13 +661,27 @@
</span><span class="cx"> 
</span><span class="cx"> IntRect RenderView::selectionBounds(bool clipToVisibleContent) const
</span><span class="cx"> {
</span><ins>+    LayoutRect selRect = subtreeSelectionBounds(*this, clipToVisibleContent);
+
+    if (m_flowThreadController) {
+        for (auto* namedFlowThread : *m_flowThreadController-&gt;renderNamedFlowThreadList()) {
+            LayoutRect currRect = subtreeSelectionBounds(*namedFlowThread, clipToVisibleContent);
+            selRect.unite(currRect);
+        }
+    }
+
+    return pixelSnappedIntRect(selRect);
+}
+
+LayoutRect RenderView::subtreeSelectionBounds(const SelectionSubtreeRoot&amp; root, bool clipToVisibleContent) const
+{
</ins><span class="cx">     typedef HashMap&lt;RenderObject*, std::unique_ptr&lt;RenderSelectionInfo&gt;&gt; SelectionMap;
</span><span class="cx">     SelectionMap selectedObjects;
</span><span class="cx"> 
</span><del>-    RenderObject* os = m_selectionStart;
-    RenderObject* stop = rendererAfterPosition(m_selectionEnd, m_selectionEndPos);
</del><ins>+    RenderObject* os = root.selectionStart();
+    RenderObject* stop = rendererAfterPosition(root.selectionEnd(), root.selectionEndPos());
</ins><span class="cx">     while (os &amp;&amp; os != stop) {
</span><del>-        if ((os-&gt;canBeSelectionLeaf() || os == m_selectionStart || os == m_selectionEnd) &amp;&amp; os-&gt;selectionState() != SelectionNone) {
</del><ins>+        if ((os-&gt;canBeSelectionLeaf() || os == root.selectionStart() || os == root.selectionEnd()) &amp;&amp; os-&gt;selectionState() != SelectionNone) {
</ins><span class="cx">             // Blocks are responsible for painting line gaps and margin gaps. They must be examined as well.
</span><span class="cx">             selectedObjects.set(os, std::make_unique&lt;RenderSelectionInfo&gt;(os, clipToVisibleContent));
</span><span class="cx">             RenderBlock* cb = os-&gt;containingBlock();
</span><span class="lines">@@ -695,16 +710,26 @@
</span><span class="cx">         }
</span><span class="cx">         selRect.unite(currRect);
</span><span class="cx">     }
</span><del>-    return pixelSnappedIntRect(selRect);
</del><ins>+    return selRect;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void RenderView::repaintSelection() const
</span><span class="cx"> {
</span><ins>+    repaintSubtreeSelection(*this);
+
+    if (m_flowThreadController) {
+        for (auto* namedFlowThread : *m_flowThreadController-&gt;renderNamedFlowThreadList())
+            repaintSubtreeSelection(*namedFlowThread);
+    }
+}
+
+void RenderView::repaintSubtreeSelection(const SelectionSubtreeRoot&amp; root) const
+{
</ins><span class="cx">     HashSet&lt;RenderBlock*&gt; processedBlocks;
</span><span class="cx"> 
</span><del>-    RenderObject* end = rendererAfterPosition(m_selectionEnd, m_selectionEndPos);
-    for (RenderObject* o = m_selectionStart; o &amp;&amp; o != end; o = o-&gt;nextInPreOrder()) {
-        if (!o-&gt;canBeSelectionLeaf() &amp;&amp; o != m_selectionStart &amp;&amp; o != m_selectionEnd)
</del><ins>+    RenderObject* end = rendererAfterPosition(root.selectionEnd(), root.selectionEndPos());
+    for (RenderObject* o = root.selectionStart(); o &amp;&amp; o != end; o = o-&gt;nextInPreOrder()) {
+        if (!o-&gt;canBeSelectionLeaf() &amp;&amp; o != root.selectionStart() &amp;&amp; o != root.selectionEnd())
</ins><span class="cx">             continue;
</span><span class="cx">         if (o-&gt;selectionState() == SelectionNone)
</span><span class="cx">             continue;
</span><span class="lines">@@ -733,27 +758,6 @@
</span><span class="cx">     }
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-// When exploring the RenderTree looking for the nodes involved in the Selection, sometimes it's
-// required to change the traversing direction because the &quot;start&quot; position is below the &quot;end&quot; one.
-static inline RenderObject* getNextOrPrevRenderObjectBasedOnDirection(const RenderObject* o, const RenderObject* stop, bool&amp; continueExploring, bool&amp; exploringBackwards)
-{
-    RenderObject* next;
-    if (exploringBackwards) {
-        next = o-&gt;previousInPreOrder();
-        continueExploring = next &amp;&amp; !(next)-&gt;isRenderView();
-    } else {
-        next = o-&gt;nextInPreOrder();
-        continueExploring = next &amp;&amp; next != stop;
-        exploringBackwards = !next &amp;&amp; (next != stop);
-        if (exploringBackwards) {
-            next = stop-&gt;previousInPreOrder();
-            continueExploring = next &amp;&amp; !next-&gt;isRenderView();
-        }
-    }
-
-    return next;
-}
-
</del><span class="cx"> void RenderView::setSelection(RenderObject* start, int startPos, RenderObject* end, int endPos, SelectionRepaintMode blockRepaintMode)
</span><span class="cx"> {
</span><span class="cx">     // Make sure both our start and end objects are defined.
</span><span class="lines">@@ -768,10 +772,94 @@
</span><span class="cx">         m_selectionEnd == end &amp;&amp; m_selectionEndPos == endPos &amp;&amp; !caretChanged)
</span><span class="cx">         return;
</span><span class="cx"> 
</span><ins>+    // Set global positions for new selection.
+    m_selectionStart = start;
+    m_selectionStartPos = startPos;
+    m_selectionEnd = end;
+    m_selectionEndPos = endPos;
+
+    // If there is no RenderNamedFlowThreads we follow the regular selection.
+    if (!hasRenderNamedFlowThreads()) {
+        setSubtreeSelection(*this, start, startPos, end, endPos, blockRepaintMode);
+        return;
+    }
+
+    splitSelectionBetweenSubtrees(start, startPos, end, endPos, blockRepaintMode);
+}
+
+void RenderView::splitSelectionBetweenSubtrees(RenderObject* start, int startPos, RenderObject* end, int endPos, SelectionRepaintMode blockRepaintMode)
+{
+    // Get ranges.
+    typedef HashMap&lt;SelectionSubtreeRoot*, RefPtr&lt;Range&gt; &gt; RenderSubtreesMap;
+    RenderSubtreesMap renderSubtreesMap;
+
+    // Initialize map for RenderView and all RenderNamedFlowThreads.
+    renderSubtreesMap.set(this, nullptr);
+    for (auto* namedFlowThread : *flowThreadController().renderNamedFlowThreadList())
+        renderSubtreesMap.set(namedFlowThread, nullptr);
+
+    if (start &amp;&amp; end) {
+        RefPtr&lt;Range&gt; initialRange = Range::create(document(), start-&gt;node(), startPos, end-&gt;node(), endPos);
+
+        Node* startNode = initialRange-&gt;startContainer();
+        Node* endNode = initialRange-&gt;endContainer();
+        Node* stopNode = initialRange-&gt;pastLastNode();
+
+        for (Node* node = startNode; node != stopNode; node = NodeTraversal::next(node)) {
+            RenderObject* renderer = node-&gt;renderer();
+            if (!renderer || !renderer-&gt;canBeSelectionLeaf())
+                continue;
+
+            SelectionSubtreeRoot&amp; root = renderer-&gt;selectionRoot();
+            RefPtr&lt;Range&gt; range = renderSubtreesMap.get(&amp;root);
+            if (!range) {
+                range = Range::create(document());
+
+                if (node == startNode)
+                    range-&gt;setStart(node, startPos);
+                else
+                    range-&gt;setStart(node, 0);
+
+                renderSubtreesMap.set(&amp;root, range);
+            }
+
+            if (node == endNode)
+                range-&gt;setEnd(node, endPos);
+            else
+                range-&gt;setEnd(node, node-&gt;offsetInCharacters() ? node-&gt;maxCharacterOffset() : node-&gt;childNodeCount());
+        }
+    }
+
+    for (RenderSubtreesMap::iterator i = renderSubtreesMap.begin(); i != renderSubtreesMap.end(); ++i) {
+        RefPtr&lt;Range&gt; range = i-&gt;value;
+
+        RenderObject* newStart;
+        int newStartPos;
+        RenderObject* newEnd;
+        int newEndPos;
+
+        if (range) {
+            newStart = range-&gt;startContainer()-&gt;renderer();
+            newStartPos = range-&gt;startOffset();
+            newEnd = range-&gt;endContainer()-&gt;renderer();
+            newEndPos = range-&gt;endOffset();
+        } else {
+            newStart = 0;
+            newStartPos = -1;
+            newEnd = 0;
+            newEndPos = -1;
+        }
+
+        setSubtreeSelection(*i-&gt;key, newStart, newStartPos, newEnd, newEndPos, blockRepaintMode);
+    }
+}
+
+void RenderView::setSubtreeSelection(SelectionSubtreeRoot&amp; root, RenderObject* start, int startPos, RenderObject* end, int endPos, SelectionRepaintMode blockRepaintMode)
+{
</ins><span class="cx">     // Record the old selected objects.  These will be used later
</span><span class="cx">     // when we compare against the new selected objects.
</span><del>-    int oldStartPos = m_selectionStartPos;
-    int oldEndPos = m_selectionEndPos;
</del><ins>+    int oldStartPos = root.selectionStartPos();
+    int oldEndPos = root.selectionEndPos();
</ins><span class="cx"> 
</span><span class="cx">     // Objects each have a single selection rect to examine.
</span><span class="cx">     typedef HashMap&lt;RenderObject*, std::unique_ptr&lt;RenderSelectionInfo&gt;&gt; SelectedObjectMap;
</span><span class="lines">@@ -785,12 +873,11 @@
</span><span class="cx">     SelectedBlockMap oldSelectedBlocks;
</span><span class="cx">     SelectedBlockMap newSelectedBlocks;
</span><span class="cx"> 
</span><del>-    RenderObject* os = m_selectionStart;
-    RenderObject* stop = rendererAfterPosition(m_selectionEnd, m_selectionEndPos);
-    bool exploringBackwards = false;
-    bool continueExploring = os &amp;&amp; (os != stop);
-    while (continueExploring) {
-        if ((os-&gt;canBeSelectionLeaf() || os == m_selectionStart || os == m_selectionEnd) &amp;&amp; os-&gt;selectionState() != SelectionNone) {
</del><ins>+    RenderObject* os = root.selectionStart();
+    RenderObject* stop = rendererAfterPosition(root.selectionEnd(), root.selectionEndPos());
+    while (os &amp;&amp; os != stop) {
+        if ((os-&gt;canBeSelectionLeaf() || os == root.selectionStart() || os == root.selectionEnd())
+            &amp;&amp; os-&gt;selectionState() != SelectionNone) {
</ins><span class="cx">             // Blocks are responsible for painting line gaps and margin gaps.  They must be examined as well.
</span><span class="cx">             oldSelectedObjects.set(os, std::make_unique&lt;RenderSelectionInfo&gt;(os, true));
</span><span class="cx">             if (blockRepaintMode == RepaintNewXOROld) {
</span><span class="lines">@@ -805,7 +892,7 @@
</span><span class="cx">             }
</span><span class="cx">         }
</span><span class="cx"> 
</span><del>-        os = getNextOrPrevRenderObjectBasedOnDirection(os, stop, continueExploring, exploringBackwards);
</del><ins>+        os = os-&gt;nextInPreOrder();
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     // Now clear the selection.
</span><span class="lines">@@ -814,12 +901,12 @@
</span><span class="cx">         i-&gt;key-&gt;setSelectionStateIfNeeded(SelectionNone);
</span><span class="cx"> 
</span><span class="cx">     // set selection start and end
</span><del>-    m_selectionStart = start;
-    m_selectionStartPos = startPos;
-    m_selectionEnd = end;
-    m_selectionEndPos = endPos;
</del><ins>+    root.setSelectionStart(start);
+    root.setSelectionStartPos(startPos);
+    root.setSelectionEnd(end);
+    root.setSelectionEndPos(endPos);
</ins><span class="cx"> 
</span><del>-    // Update the selection status of all objects between m_selectionStart and m_selectionEnd
</del><ins>+    // Update the selection status of all objects between selectionStart and selectionEnd
</ins><span class="cx">     if (start &amp;&amp; start == end)
</span><span class="cx">         start-&gt;setSelectionStateIfNeeded(SelectionBoth);
</span><span class="cx">     else {
</span><span class="lines">@@ -844,9 +931,7 @@
</span><span class="cx">     // Now that the selection state has been updated for the new objects, walk them again and
</span><span class="cx">     // put them in the new objects list.
</span><span class="cx">     o = start;
</span><del>-    exploringBackwards = false;
-    continueExploring = o &amp;&amp; (o != stop);
-    while (continueExploring) {
</del><ins>+    while (o &amp;&amp; o != stop) {
</ins><span class="cx">         if ((o-&gt;canBeSelectionLeaf() || o == start || o == end) &amp;&amp; o-&gt;selectionState() != SelectionNone) {
</span><span class="cx">             newSelectedObjects.set(o, std::make_unique&lt;RenderSelectionInfo&gt;(o, true));
</span><span class="cx">             RenderBlock* cb = o-&gt;containingBlock();
</span><span class="lines">@@ -859,7 +944,7 @@
</span><span class="cx">             }
</span><span class="cx">         }
</span><span class="cx"> 
</span><del>-        o = getNextOrPrevRenderObjectBasedOnDirection(o, stop, continueExploring, exploringBackwards);
</del><ins>+        o = o-&gt;nextInPreOrder();
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     if (blockRepaintMode == RepaintNothing)
</span><span class="lines">@@ -870,9 +955,9 @@
</span><span class="cx">         RenderObject* obj = i-&gt;key;
</span><span class="cx">         RenderSelectionInfo* newInfo = newSelectedObjects.get(obj);
</span><span class="cx">         RenderSelectionInfo* oldInfo = i-&gt;value.get();
</span><del>-        if (!newInfo || oldInfo-&gt;rect() != newInfo-&gt;rect() || oldInfo-&gt;state() != newInfo-&gt;state() ||
-            (m_selectionStart == obj &amp;&amp; oldStartPos != m_selectionStartPos) ||
-            (m_selectionEnd == obj &amp;&amp; oldEndPos != m_selectionEndPos)) {
</del><ins>+        if (!newInfo || oldInfo-&gt;rect() != newInfo-&gt;rect() || oldInfo-&gt;state() != newInfo-&gt;state()
+            || (root.selectionStart() == obj &amp;&amp; oldStartPos != root.selectionStartPos())
+            || (root.selectionEnd() == obj &amp;&amp; oldEndPos != root.selectionEndPos())) {
</ins><span class="cx">             oldInfo-&gt;repaint();
</span><span class="cx">             if (newInfo) {
</span><span class="cx">                 newInfo-&gt;repaint();
</span><span class="lines">@@ -921,12 +1006,6 @@
</span><span class="cx">     setSelection(0, -1, 0, -1, RepaintNewMinusOld);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void RenderView::selectionStartEnd(int&amp; startPos, int&amp; endPos) const
-{
-    startPos = m_selectionStartPos;
-    endPos = m_selectionEndPos;
-}
-
</del><span class="cx"> bool RenderView::printing() const
</span><span class="cx"> {
</span><span class="cx">     return document().printing();
</span></span></pre></div>
<a id="trunkSourceWebCorerenderingRenderViewh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/RenderView.h (167651 => 167652)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/RenderView.h        2014-04-22 08:29:23 UTC (rev 167651)
+++ trunk/Source/WebCore/rendering/RenderView.h        2014-04-22 10:22:47 UTC (rev 167652)
</span><span class="lines">@@ -27,8 +27,10 @@
</span><span class="cx"> #include &quot;PODFreeListArena.h&quot;
</span><span class="cx"> #include &quot;Region.h&quot;
</span><span class="cx"> #include &quot;RenderBlockFlow.h&quot;
</span><ins>+#include &quot;SelectionSubtreeRoot.h&quot;
</ins><span class="cx"> #include &lt;memory&gt;
</span><span class="cx"> #include &lt;wtf/HashSet.h&gt;
</span><ins>+#include &lt;wtf/OwnPtr.h&gt;
</ins><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><span class="cx"> 
</span><span class="lines">@@ -37,7 +39,7 @@
</span><span class="cx"> class RenderLayerCompositor;
</span><span class="cx"> class RenderQuote;
</span><span class="cx"> 
</span><del>-class RenderView final : public RenderBlockFlow {
</del><ins>+class RenderView final : public RenderBlockFlow, public SelectionSubtreeRoot {
</ins><span class="cx"> public:
</span><span class="cx">     RenderView(Document&amp;, PassRef&lt;RenderStyle&gt;);
</span><span class="cx">     virtual ~RenderView();
</span><span class="lines">@@ -86,7 +88,6 @@
</span><span class="cx">     RenderObject* selectionStart() const { return m_selectionStart; }
</span><span class="cx">     RenderObject* selectionEnd() const { return m_selectionEnd; }
</span><span class="cx">     IntRect selectionBounds(bool clipToVisibleContent = true) const;
</span><del>-    void selectionStartEnd(int&amp; startPos, int&amp; endPos) const;
</del><span class="cx">     void repaintSelection() const;
</span><span class="cx"> 
</span><span class="cx">     bool printing() const;
</span><span class="lines">@@ -296,6 +297,11 @@
</span><span class="cx">     friend class LayoutStateMaintainer;
</span><span class="cx">     friend class LayoutStateDisabler;
</span><span class="cx"> 
</span><ins>+    void splitSelectionBetweenSubtrees(RenderObject* start, int startPos, RenderObject* end, int endPos, SelectionRepaintMode blockRepaintMode);
+    void setSubtreeSelection(SelectionSubtreeRoot&amp;, RenderObject* start, int startPos, RenderObject* end, int endPos, SelectionRepaintMode);
+    LayoutRect subtreeSelectionBounds(const SelectionSubtreeRoot&amp;, bool clipToVisibleContent = true) const;
+    void repaintSubtreeSelection(const SelectionSubtreeRoot&amp;) const;
+
</ins><span class="cx"> private:
</span><span class="cx">     FrameView&amp; m_frameView;
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCorerenderingSelectionSubtreeRootcpp"></a>
<div class="addfile"><h4>Added: trunk/Source/WebCore/rendering/SelectionSubtreeRoot.cpp (0 => 167652)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/SelectionSubtreeRoot.cpp                                (rev 0)
+++ trunk/Source/WebCore/rendering/SelectionSubtreeRoot.cpp        2014-04-22 10:22:47 UTC (rev 167652)
</span><span class="lines">@@ -0,0 +1,49 @@
</span><ins>+/*
+ * Copyright (C) 2014 Igalia S.L.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above
+ *    copyright notice, this list of conditions and the following
+ *    disclaimer.
+ * 2. Redistributions in binary form must reproduce the above
+ *    copyright notice, this list of conditions and the following
+ *    disclaimer in the documentation and/or other materials
+ *    provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER “AS IS” AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
+ * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
+ * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include &quot;config.h&quot;
+#include &quot;SelectionSubtreeRoot.h&quot;
+
+namespace WebCore {
+
+SelectionSubtreeRoot::SelectionSubtreeRoot()
+    : m_selectionStart(nullptr)
+    , m_selectionStartPos(-1)
+    , m_selectionEnd(nullptr)
+    , m_selectionEndPos(-1)
+{
+}
+
+void SelectionSubtreeRoot::selectionStartEndPositions(int&amp; startPos, int&amp; endPos) const
+{
+    startPos = m_selectionStartPos;
+    endPos = m_selectionEndPos;
+}
+
+} // namespace WebCore
</ins></span></pre></div>
<a id="trunkSourceWebCorerenderingSelectionSubtreeRooth"></a>
<div class="addfile"><h4>Added: trunk/Source/WebCore/rendering/SelectionSubtreeRoot.h (0 => 167652)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/SelectionSubtreeRoot.h                                (rev 0)
+++ trunk/Source/WebCore/rendering/SelectionSubtreeRoot.h        2014-04-22 10:22:47 UTC (rev 167652)
</span><span class="lines">@@ -0,0 +1,65 @@
</span><ins>+/*
+ * Copyright (C) 2014 Igalia S.L.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above
+ *    copyright notice, this list of conditions and the following
+ *    disclaimer.
+ * 2. Redistributions in binary form must reproduce the above
+ *    copyright notice, this list of conditions and the following
+ *    disclaimer in the documentation and/or other materials
+ *    provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER “AS IS” AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
+ * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
+ * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef SelectionSubtreeRoot_h
+#define SelectionSubtreeRoot_h
+
+#include &quot;RenderObject.h&quot;
+
+namespace WebCore {
+
+class SelectionSubtreeRoot {
+public:
+
+    SelectionSubtreeRoot();
+
+    RenderObject* selectionStart() const { return m_selectionStart; }
+    int selectionStartPos() const { return m_selectionStartPos; }
+    RenderObject* selectionEnd() const { return m_selectionEnd; }
+    int selectionEndPos() const { return m_selectionEndPos; }
+
+    void setSelectionStart(RenderObject* selectionStart) { m_selectionStart = selectionStart; }
+    void setSelectionStartPos(int selectionStartPos) { m_selectionStartPos = selectionStartPos; }
+    void setSelectionEnd(RenderObject* selectionEnd) { m_selectionEnd = selectionEnd; }
+    void setSelectionEndPos(int selectionEndPos) { m_selectionEndPos = selectionEndPos; }
+
+    void selectionStartEndPositions(int&amp; startPos, int&amp; endPos) const;
+
+private:
+
+    RenderObject* m_selectionStart;
+    int m_selectionStartPos;
+    RenderObject* m_selectionEnd;
+    int m_selectionEndPos;
+
+};
+
+} // namespace WebCore
+
+#endif // SelectionSubtreeRoot_h
</ins></span></pre>
</div>
</div>

</body>
</html>