<!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>[203412] 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/203412">203412</a></dd>
<dt>Author</dt> <dd>n_wang@apple.com</dd>
<dt>Date</dt> <dd>2016-07-19 11:14:02 -0700 (Tue, 19 Jul 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>AX: Incorrect behavior for word related text marker functions when there's collapsed whitespace
https://bugs.webkit.org/show_bug.cgi?id=159910

Reviewed by Chris Fleizach.

Source/WebCore:

We are getting a bad CharacterOffset when there's collapsed whitespace. Added a TraverseOptionValidateOffset
option to make sure we are getting the correct CharacterOffset based on the corresponding Range offset. And
fixed a word navigation issue based on that.

Test: accessibility/mac/text-marker-word-nav-collapsed-whitespace.html

* accessibility/AXObjectCache.cpp:
(WebCore::AXObjectCache::traverseToOffsetInRange):
(WebCore::AXObjectCache::rangeForNodeContents):
(WebCore::AXObjectCache::startOrEndCharacterOffsetForRange):
(WebCore::AXObjectCache::characterOffsetFromVisiblePosition):
(WebCore::AXObjectCache::rightWordRange):
(WebCore::AXObjectCache::previousBoundary):
* accessibility/AXObjectCache.h:
(WebCore::AXObjectCache::isNodeInUse):

LayoutTests:

* accessibility/mac/text-marker-word-nav-collapsed-whitespace-expected.txt: Added.
* accessibility/mac/text-marker-word-nav-collapsed-whitespace.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="#trunkSourceWebCoreaccessibilityAXObjectCachecpp">trunk/Source/WebCore/accessibility/AXObjectCache.cpp</a></li>
<li><a href="#trunkSourceWebCoreaccessibilityAXObjectCacheh">trunk/Source/WebCore/accessibility/AXObjectCache.h</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsaccessibilitymactextmarkerwordnavcollapsedwhitespaceexpectedtxt">trunk/LayoutTests/accessibility/mac/text-marker-word-nav-collapsed-whitespace-expected.txt</a></li>
<li><a href="#trunkLayoutTestsaccessibilitymactextmarkerwordnavcollapsedwhitespacehtml">trunk/LayoutTests/accessibility/mac/text-marker-word-nav-collapsed-whitespace.html</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (203411 => 203412)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2016-07-19 17:27:32 UTC (rev 203411)
+++ trunk/LayoutTests/ChangeLog        2016-07-19 18:14:02 UTC (rev 203412)
</span><span class="lines">@@ -1,3 +1,13 @@
</span><ins>+2016-07-19  Nan Wang  &lt;n_wang@apple.com&gt;
+
+        AX: Incorrect behavior for word related text marker functions when there's collapsed whitespace
+        https://bugs.webkit.org/show_bug.cgi?id=159910
+
+        Reviewed by Chris Fleizach.
+
+        * accessibility/mac/text-marker-word-nav-collapsed-whitespace-expected.txt: Added.
+        * accessibility/mac/text-marker-word-nav-collapsed-whitespace.html: Added.
+
</ins><span class="cx"> 2016-07-19  Youenn Fablet  &lt;youenn@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [Streams API] ReadableStreamController methods should throw if its stream is not readable
</span></span></pre></div>
<a id="trunkLayoutTestsaccessibilitymactextmarkerwordnavcollapsedwhitespaceexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/accessibility/mac/text-marker-word-nav-collapsed-whitespace-expected.txt (0 => 203412)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/accessibility/mac/text-marker-word-nav-collapsed-whitespace-expected.txt                                (rev 0)
+++ trunk/LayoutTests/accessibility/mac/text-marker-word-nav-collapsed-whitespace-expected.txt        2016-07-19 18:14:02 UTC (rev 203412)
</span><span class="lines">@@ -0,0 +1,30 @@
</span><ins>+Test1 Test2 Test3
+This tests that word navigation is working correctly with collapsed whitespaces.
+
+On success, you will see a series of &quot;PASS&quot; messages, followed by &quot;TEST COMPLETE&quot;.
+
+
+Current character is: 1
+Left word is: Test1
+Right word is:  
+Pre word start to next word end: Test1 
+
+Current character is:  
+Left word is:  
+Right word is: Test2
+Pre word start to next word end:  Test2
+
+Current character is: 2
+Left word is: Test2
+Right word is:  
+Pre word start to next word end: Test2 
+
+Current character is:  
+Left word is:  
+Right word is: Test3
+Pre word start to next word end:  Test3
+
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
</ins></span></pre></div>
<a id="trunkLayoutTestsaccessibilitymactextmarkerwordnavcollapsedwhitespacehtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/accessibility/mac/text-marker-word-nav-collapsed-whitespace.html (0 => 203412)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/accessibility/mac/text-marker-word-nav-collapsed-whitespace.html                                (rev 0)
+++ trunk/LayoutTests/accessibility/mac/text-marker-word-nav-collapsed-whitespace.html        2016-07-19 18:14:02 UTC (rev 203412)
</span><span class="lines">@@ -0,0 +1,81 @@
</span><ins>+&lt;!DOCTYPE HTML PUBLIC &quot;-//IETF//DTD HTML//EN&quot;&gt;
+&lt;html&gt;
+&lt;head&gt;
+&lt;meta charset=&quot;utf-8&quot;&gt; 
+&lt;script src=&quot;../../resources/js-test-pre.js&quot;&gt;&lt;/script&gt;
+&lt;/head&gt;
+&lt;body id=&quot;body&quot;&gt;
+
+&lt;div id=&quot;text&quot;&gt;
+Test1
+
+
+
+Test2   Test3
+&lt;/div&gt;
+
+&lt;p id=&quot;description&quot;&gt;&lt;/p&gt;
+&lt;div id=&quot;console&quot;&gt;&lt;/div&gt;
+
+&lt;script&gt;
+
+    description(&quot;This tests that word navigation is working correctly with collapsed whitespaces.&quot;);
+    
+    if (window.accessibilityController) {
+        
+        var text = accessibilityController.accessibleElementById(&quot;text&quot;);
+        // Get the actual text node.
+        text = text.childAtIndex(0);
+        
+        // Check that we can get the second word &quot;Test2&quot;
+        var textMarkerRange = text.textMarkerRangeForElement(text);
+        var startMarker = text.startTextMarkerForTextMarkerRange(textMarkerRange);
+        var currentMarker = advanceAndVerify(startMarker, 5, text);
+        currentMarker = advanceAndVerify(currentMarker, 1, text);
+        
+        // Check that we can get the third word &quot;Test3&quot;
+        currentMarker = advanceAndVerify(currentMarker, 5, text);
+        currentMarker = advanceAndVerify(currentMarker, 1, text);
+        
+        function advanceAndVerify(currentMarker, offset, obj) {
+            var previousMarker = currentMarker;
+            for (var i = 0; i &lt; offset; i++) {
+                previousMarker = currentMarker;
+                currentMarker = obj.nextTextMarker(previousMarker);
+            }
+            verifyWordRangeForTextMarker(previousMarker, currentMarker, obj);
+            return currentMarker;
+        }
+        
+        function replaceAttachmentInString(str) {
+            var newline = '\n';
+            str =  str.replace(String.fromCharCode(65532), &quot;[ATTACHMENT]&quot;);
+            str = str.replace(newline, &quot;'line break'&quot;);
+            return str;
+        }
+        
+        function verifyWordRangeForTextMarker(preMarker, textMarker, obj) {
+            var markerRange = obj.textMarkerRangeForMarkers(preMarker, textMarker);
+            var currentCharacter = obj.stringForTextMarkerRange(markerRange);
+            debug(&quot;Current character is: &quot; + currentCharacter);
+            
+            var previousWordRange = obj.leftWordTextMarkerRangeForTextMarker(textMarker);
+            var nextWordRange = obj.rightWordTextMarkerRangeForTextMarker(textMarker);
+            var preWord = obj.stringForTextMarkerRange(previousWordRange);
+            var nextWord = obj.stringForTextMarkerRange(nextWordRange);
+            debug(&quot;Left word is: &quot; + preWord);
+            debug(&quot;Right word is: &quot; + nextWord);
+            
+            var preWordStart = obj.previousWordStartTextMarkerForTextMarker(textMarker);
+            var nextWordEnd = obj.nextWordEndTextMarkerForTextMarker(textMarker);
+            var preAndNextWordRange = obj.textMarkerRangeForMarkers(preWordStart, nextWordEnd);
+            var preAndNextWord = obj.stringForTextMarkerRange(preAndNextWordRange);
+            debug(&quot;Pre word start to next word end: &quot; + preAndNextWord + &quot;\n&quot;);
+        }
+    }
+
+&lt;/script&gt;
+
+&lt;script src=&quot;../../resources/js-test-post.js&quot;&gt;&lt;/script&gt;
+&lt;/body&gt;
+&lt;/html&gt;
</ins><span class="cx">\ No newline at end of file
</span></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (203411 => 203412)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2016-07-19 17:27:32 UTC (rev 203411)
+++ trunk/Source/WebCore/ChangeLog        2016-07-19 18:14:02 UTC (rev 203412)
</span><span class="lines">@@ -1,3 +1,26 @@
</span><ins>+2016-07-19  Nan Wang  &lt;n_wang@apple.com&gt;
+
+        AX: Incorrect behavior for word related text marker functions when there's collapsed whitespace
+        https://bugs.webkit.org/show_bug.cgi?id=159910
+
+        Reviewed by Chris Fleizach.
+
+        We are getting a bad CharacterOffset when there's collapsed whitespace. Added a TraverseOptionValidateOffset
+        option to make sure we are getting the correct CharacterOffset based on the corresponding Range offset. And
+        fixed a word navigation issue based on that.
+
+        Test: accessibility/mac/text-marker-word-nav-collapsed-whitespace.html
+
+        * accessibility/AXObjectCache.cpp:
+        (WebCore::AXObjectCache::traverseToOffsetInRange):
+        (WebCore::AXObjectCache::rangeForNodeContents):
+        (WebCore::AXObjectCache::startOrEndCharacterOffsetForRange):
+        (WebCore::AXObjectCache::characterOffsetFromVisiblePosition):
+        (WebCore::AXObjectCache::rightWordRange):
+        (WebCore::AXObjectCache::previousBoundary):
+        * accessibility/AXObjectCache.h:
+        (WebCore::AXObjectCache::isNodeInUse):
+
</ins><span class="cx"> 2016-07-19  Youenn Fablet  &lt;youenn@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [Streams API] ReadableStreamController methods should throw if its stream is not readable
</span></span></pre></div>
<a id="trunkSourceWebCoreaccessibilityAXObjectCachecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/accessibility/AXObjectCache.cpp (203411 => 203412)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/accessibility/AXObjectCache.cpp        2016-07-19 17:27:32 UTC (rev 203411)
+++ trunk/Source/WebCore/accessibility/AXObjectCache.cpp        2016-07-19 18:14:02 UTC (rev 203412)
</span><span class="lines">@@ -1503,6 +1503,7 @@
</span><span class="cx">         return CharacterOffset();
</span><span class="cx">     
</span><span class="cx">     bool toNodeEnd = option &amp; TraverseOptionToNodeEnd;
</span><ins>+    bool validateOffset = option &amp; TraverseOptionValidateOffset;
</ins><span class="cx">     
</span><span class="cx">     int offsetInCharacter = 0;
</span><span class="cx">     int cumulativeOffset = 0;
</span><span class="lines">@@ -1536,9 +1537,6 @@
</span><span class="cx">     // Sometimes text contents in a node are splitted into several iterations, so that iterator.range()-&gt;startOffset()
</span><span class="cx">     // might not be the correct character count. Here we use a previousNode object to keep track of that.
</span><span class="cx">     Node* previousNode = nullptr;
</span><del>-    // When text node has collapsed whitespaces, we need to treat it differently since text iterator
-    // will omit the collapsed spaces and make the offset inaccurate.
-    Node* collapsedWhitespaceNode = nullptr;
</del><span class="cx">     for (; !iterator.atEnd(); iterator.advance()) {
</span><span class="cx">         int currentLength = iterator.text().length();
</span><span class="cx">         bool hasReplacedNodeOrBR = false;
</span><span class="lines">@@ -1546,10 +1544,6 @@
</span><span class="cx">         Node&amp; node = iterator.range()-&gt;startContainer();
</span><span class="cx">         currentNode = &amp;node;
</span><span class="cx">         
</span><del>-        // The offset of node with collapsed whitespaces has been calcualted in the first iteration.
-        if (currentNode == collapsedWhitespaceNode)
-            continue;
-        
</del><span class="cx">         // When currentLength == 0, we check if there's any replaced node.
</span><span class="cx">         // If not, we skip the node with no length.
</span><span class="cx">         if (!currentLength) {
</span><span class="lines">@@ -1579,34 +1573,14 @@
</span><span class="cx">                         continue;
</span><span class="cx">                     }
</span><span class="cx">                 }
</span><del>-            } else if (currentNode-&gt;isTextNode() &amp;&amp; currentNode-&gt;renderer()) {
-                // When there's collapsed whitespace, the text iterator will only count those spaces as one single space.
-                // Here we use the RenderText to get the actual length.
-                RenderText* renderedText = downcast&lt;RenderText&gt;(currentNode-&gt;renderer());
-                int currentStartOffset = iterator.range()-&gt;startOffset();
-                if (renderedText-&gt;style().isCollapsibleWhiteSpace(iterator.text()[currentLength - 1])  &amp;&amp; currentLength + currentStartOffset != renderedText-&gt;caretMaxOffset()) {
-                    int appendLength = (&amp;range-&gt;endContainer() == currentNode ? range-&gt;endOffset() : (int)renderedText-&gt;text()-&gt;length()) - currentStartOffset;
-                    lastStartOffset = currentStartOffset;
-                    cumulativeOffset += appendLength;
-                    lastLength = appendLength;
-                    
-                    // Break early if we have advanced enough characters.
-                    if (!toNodeEnd &amp;&amp; cumulativeOffset &gt;= offset) {
-                        offsetInCharacter = offset - (cumulativeOffset - lastLength);
-                        finished = true;
-                        break;
-                    }
-                    
-                    collapsedWhitespaceNode = currentNode;
-                    continue;
-                }
-                
</del><span class="cx">             }
</span><span class="cx">             cumulativeOffset += currentLength;
</span><span class="cx">         }
</span><span class="cx"> 
</span><del>-        if (currentNode == previousNode)
</del><ins>+        if (currentNode == previousNode) {
</ins><span class="cx">             lastLength += currentLength;
</span><ins>+            lastStartOffset = iterator.range()-&gt;endOffset() - lastLength;
+        }
</ins><span class="cx">         else {
</span><span class="cx">             lastLength = currentLength;
</span><span class="cx">             lastStartOffset = hasReplacedNodeOrBR ? 0 : iterator.range()-&gt;startOffset();
</span><span class="lines">@@ -1613,8 +1587,9 @@
</span><span class="cx">         }
</span><span class="cx">         
</span><span class="cx">         // Break early if we have advanced enough characters.
</span><del>-        if (!toNodeEnd &amp;&amp; cumulativeOffset &gt;= offset) {
-            offsetInCharacter = offset - (cumulativeOffset - lastLength);
</del><ins>+        bool offsetLimitReached = validateOffset ? cumulativeOffset + lastStartOffset &gt;= offset : cumulativeOffset &gt;= offset;
+        if (!toNodeEnd &amp;&amp; offsetLimitReached) {
+            offsetInCharacter = validateOffset ? std::max(offset - lastStartOffset, 0) : offset - (cumulativeOffset - lastLength);
</ins><span class="cx">             finished = true;
</span><span class="cx">             break;
</span><span class="cx">         }
</span><span class="lines">@@ -1667,7 +1642,11 @@
</span><span class="cx">         return nullptr;
</span><span class="cx">     RefPtr&lt;Range&gt; range = Range::create(*document);
</span><span class="cx">     ExceptionCode ec = 0;
</span><del>-    range-&gt;selectNodeContents(*node, ec);
</del><ins>+    // For replaced node without children, we should incluce itself in the range.
+    if (AccessibilityObject::replacedNodeNeedsCharacter(node))
+        range-&gt;selectNode(*node, ec);
+    else
+        range-&gt;selectNodeContents(*node, ec);
</ins><span class="cx">     return ec ? nullptr : range;
</span><span class="cx"> }
</span><span class="cx">     
</span><span class="lines">@@ -1811,15 +1790,20 @@
</span><span class="cx">     // If it's end text marker, we want to go to the end of the range, and stay within the range.
</span><span class="cx">     bool stayWithinRange = !isStart;
</span><span class="cx">     
</span><ins>+    Node&amp; endNode = range-&gt;endContainer();
+    if (endNode.offsetInCharacters() &amp;&amp; !isStart)
+        return traverseToOffsetInRange(rangeForNodeContents(&amp;endNode), range-&gt;endOffset(), TraverseOptionValidateOffset);
+    
</ins><span class="cx">     Ref&lt;Range&gt; copyRange = *range;
</span><span class="cx">     // Change the start of the range, so the character offset starts from node beginning.
</span><span class="cx">     int offset = 0;
</span><span class="cx">     Node&amp; node = copyRange-&gt;startContainer();
</span><span class="cx">     if (node.offsetInCharacters()) {
</span><del>-        copyRange = Range::create(range-&gt;ownerDocument(), &amp;range-&gt;startContainer(), range-&gt;startOffset(), &amp;range-&gt;endContainer(), range-&gt;endOffset());
-        CharacterOffset nodeStartOffset = traverseToOffsetInRange(rangeForNodeContents(&amp;node), 0);
-        offset = std::max(copyRange-&gt;startOffset() - nodeStartOffset.startIndex, 0);
-        copyRange-&gt;setStart(node, nodeStartOffset.startIndex);
</del><ins>+        CharacterOffset nodeStartOffset = traverseToOffsetInRange(rangeForNodeContents(&amp;node), range-&gt;startOffset(), TraverseOptionValidateOffset);
+        if (isStart)
+            return nodeStartOffset;
+        copyRange = Range::create(range-&gt;ownerDocument(), &amp;range-&gt;startContainer(), 0, &amp;range-&gt;endContainer(), range-&gt;endOffset());
+        offset += nodeStartOffset.offset;
</ins><span class="cx">     }
</span><span class="cx">     
</span><span class="cx">     return traverseToOffsetInRange(WTFMove(copyRange), offset, isStart ? TraverseOptionDefault : TraverseOptionToNodeEnd, stayWithinRange);
</span><span class="lines">@@ -1984,7 +1968,7 @@
</span><span class="cx">     ASSERT(domNode);
</span><span class="cx">     
</span><span class="cx">     if (domNode-&gt;offsetInCharacters())
</span><del>-        return CharacterOffset(domNode, 0, deepPos.deprecatedEditingOffset(), 0);
</del><ins>+        return traverseToOffsetInRange(rangeForNodeContents(domNode), deepPos.deprecatedEditingOffset(), TraverseOptionValidateOffset);
</ins><span class="cx">     
</span><span class="cx">     RefPtr&lt;AccessibilityObject&gt; obj = this-&gt;getOrCreate(domNode);
</span><span class="cx">     if (!obj)
</span><span class="lines">@@ -2186,7 +2170,7 @@
</span><span class="cx"> 
</span><span class="cx"> RefPtr&lt;Range&gt; AXObjectCache::rightWordRange(const CharacterOffset&amp; characterOffset)
</span><span class="cx"> {
</span><del>-    CharacterOffset start = startCharacterOffsetOfWord(characterOffset);
</del><ins>+    CharacterOffset start = startCharacterOffsetOfWord(characterOffset, RightWordIfOnBoundary);
</ins><span class="cx">     CharacterOffset end = endCharacterOffsetOfWord(start);
</span><span class="cx">     return rangeForUnorderedCharacterOffsets(start, end);
</span><span class="cx"> }
</span><span class="lines">@@ -2319,10 +2303,18 @@
</span><span class="cx">         return it.atEnd() ? start : characterOffset;
</span><span class="cx">     
</span><span class="cx">     Node&amp; node = it.atEnd() ? searchRange-&gt;startContainer() : it.range()-&gt;startContainer();
</span><ins>+    
+    // SimplifiedBackwardsTextIterator ignores replaced elements.
+    if (AccessibilityObject::replacedNodeNeedsCharacter(characterOffset.node))
+        return characterOffsetForNodeAndOffset(*characterOffset.node, 0);
+    Node* nextSibling = node.nextSibling();
+    if (&amp;node != characterOffset.node &amp;&amp; AccessibilityObject::replacedNodeNeedsCharacter(nextSibling))
+        return startOrEndCharacterOffsetForRange(rangeForNodeContents(nextSibling), false);
+    
</ins><span class="cx">     if ((node.isTextNode() &amp;&amp; static_cast&lt;int&gt;(next) &lt;= node.maxCharacterOffset()) || (node.renderer() &amp;&amp; node.renderer()-&gt;isBR() &amp;&amp; !next)) {
</span><span class="cx">         // The next variable contains a usable index into a text node
</span><del>-        if (&amp;node == characterOffset.node)
-            next -= characterOffset.startIndex;
</del><ins>+        if (node.isTextNode())
+            return traverseToOffsetInRange(rangeForNodeContents(&amp;node), next, TraverseOptionValidateOffset);
</ins><span class="cx">         return characterOffsetForNodeAndOffset(node, next, TraverseOptionIncludeStart);
</span><span class="cx">     }
</span><span class="cx">     
</span></span></pre></div>
<a id="trunkSourceWebCoreaccessibilityAXObjectCacheh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/accessibility/AXObjectCache.h (203411 => 203412)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/accessibility/AXObjectCache.h        2016-07-19 17:27:32 UTC (rev 203411)
+++ trunk/Source/WebCore/accessibility/AXObjectCache.h        2016-07-19 18:14:02 UTC (rev 203412)
</span><span class="lines">@@ -348,7 +348,7 @@
</span><span class="cx">     bool isNodeInUse(Node* n) { return m_textMarkerNodes.contains(n); }
</span><span class="cx">     
</span><span class="cx">     // CharacterOffset functions.
</span><del>-    enum TraverseOption { TraverseOptionDefault = 1 &lt;&lt; 0, TraverseOptionToNodeEnd = 1 &lt;&lt; 1, TraverseOptionIncludeStart = 1 &lt;&lt; 2 };
</del><ins>+    enum TraverseOption { TraverseOptionDefault = 1 &lt;&lt; 0, TraverseOptionToNodeEnd = 1 &lt;&lt; 1, TraverseOptionIncludeStart = 1 &lt;&lt; 2, TraverseOptionValidateOffset = 1 &lt;&lt; 3 };
</ins><span class="cx">     Node* nextNode(Node*) const;
</span><span class="cx">     Node* previousNode(Node*) const;
</span><span class="cx">     CharacterOffset traverseToOffsetInRange(RefPtr&lt;Range&gt;, int, TraverseOption = TraverseOptionDefault, bool stayWithinRange = false);
</span></span></pre>
</div>
</div>

</body>
</html>