<!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>[167033] 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/167033">167033</a></dd>
<dt>Author</dt> <dd>samuel_white@apple.com</dd>
<dt>Date</dt> <dd>2014-04-09 14:13:24 -0700 (Wed, 09 Apr 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>AX: Initial text selection point should respect element focus.
https://bugs.webkit.org/show_bug.cgi?id=131402

Reviewed by Chris Fleizach.

Source/WebCore:

No new tests, updated existing selection-initial to test this functionality.

Support the case where we want to set the initial selection and there's already a focused element.

* page/EventHandler.cpp:
(WebCore::setKeyboardSelection):
(WebCore::handleKeyboardSelectionMovement):

LayoutTests:

Updating test to make sure initial selection respects the focused element when necessary. Now, if a VoiceOver user attempts to use
arrow keys to read text and selection isn't set, we will set initial selection before/after the focused element if one is present.

* platform/mac/accessibility/selection-initial-expected.txt:
* platform/mac/accessibility/selection-initial.html:</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkLayoutTestsplatformmacaccessibilityselectioninitialexpectedtxt">trunk/LayoutTests/platform/mac/accessibility/selection-initial-expected.txt</a></li>
<li><a href="#trunkLayoutTestsplatformmacaccessibilityselectioninitialhtml">trunk/LayoutTests/platform/mac/accessibility/selection-initial.html</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCorepageEventHandlercpp">trunk/Source/WebCore/page/EventHandler.cpp</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (167032 => 167033)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2014-04-09 21:07:14 UTC (rev 167032)
+++ trunk/LayoutTests/ChangeLog        2014-04-09 21:13:24 UTC (rev 167033)
</span><span class="lines">@@ -1,3 +1,16 @@
</span><ins>+2014-04-08  Samuel White  &lt;samuel_white@apple.com&gt;
+
+        AX: Initial text selection point should respect element focus.
+        https://bugs.webkit.org/show_bug.cgi?id=131402
+
+        Reviewed by Chris Fleizach.
+
+        Updating test to make sure initial selection respects the focused element when necessary. Now, if a VoiceOver user attempts to use
+        arrow keys to read text and selection isn't set, we will set initial selection before/after the focused element if one is present.
+
+        * platform/mac/accessibility/selection-initial-expected.txt:
+        * platform/mac/accessibility/selection-initial.html:
+
</ins><span class="cx"> 2014-04-09  Brendan Long  &lt;b.long@cablelabs.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [GStreamer] Expose MPEG-TS metadata
</span></span></pre></div>
<a id="trunkLayoutTestsplatformmacaccessibilityselectioninitialexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/platform/mac/accessibility/selection-initial-expected.txt (167032 => 167033)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/platform/mac/accessibility/selection-initial-expected.txt        2014-04-09 21:07:14 UTC (rev 167032)
+++ trunk/LayoutTests/platform/mac/accessibility/selection-initial-expected.txt        2014-04-09 21:13:24 UTC (rev 167033)
</span><span class="lines">@@ -3,19 +3,27 @@
</span><span class="cx"> On success, you will see a series of &quot;PASS&quot; messages, followed by &quot;TEST COMPLETE&quot;.
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-PASS isSelectionAtStartOfDocument() is false
-PASS isSelectionAtStartOfDocument() is false
</del><ins>+PASS isSelection() is false
+PASS isSelection() is false
</ins><span class="cx"> PASS accessibilityController.enhancedAccessibilityEnabled is true
</span><del>-PASS isSelectionAtStartOfDocument() is false
</del><ins>+PASS isSelection() is false
</ins><span class="cx"> PASS isSelectionAtStartOfDocument() is true
</span><del>-PASS isSelectionAtStartOfDocument() is false
</del><ins>+PASS isSelection() is false
+PASS isSelectionAtEndOfDocument() is true
+PASS isSelection() is false
</ins><span class="cx"> PASS isSelectionAtStartOfDocument() is true
</span><del>-PASS isSelectionAtStartOfDocument() is false
-PASS isSelectionAtStartOfDocument() is true
-PASS isSelectionAtStartOfDocument() is false
-PASS isSelectionAtStartOfDocument() is true
-PASS isSelectionAtStartOfDocument() is false
-PASS isSelectionAtStartOfDocument() is false
</del><ins>+PASS isSelection() is false
+PASS isSelectionAtEndOfDocument() is true
+PASS isSelection() is false
+PASS isSelection() is false
+PASS isSelection() is false
+PASS isSelectionAfterButton() is true
+PASS isSelection() is false
+PASS isSelectionBeforeButton() is true
+PASS isSelection() is false
+PASS isSelectionAfterButton() is true
+PASS isSelection() is false
+PASS isSelectionBeforeButton() is true
</ins><span class="cx"> PASS successfullyParsed is true
</span><span class="cx"> 
</span><span class="cx"> TEST COMPLETE
</span></span></pre></div>
<a id="trunkLayoutTestsplatformmacaccessibilityselectioninitialhtml"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/platform/mac/accessibility/selection-initial.html (167032 => 167033)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/platform/mac/accessibility/selection-initial.html        2014-04-09 21:07:14 UTC (rev 167032)
+++ trunk/LayoutTests/platform/mac/accessibility/selection-initial.html        2014-04-09 21:13:24 UTC (rev 167033)
</span><span class="lines">@@ -6,28 +6,89 @@
</span><span class="cx"> &lt;/head&gt;
</span><span class="cx"> &lt;body&gt;
</span><span class="cx"> 
</span><del>-&lt;p id=&quot;text&quot;&gt;Text.&lt;/p&gt;
</del><ins>+&lt;p id=&quot;startText&quot;&gt;Start text. Before. &lt;input id=&quot;button&quot; type=&quot;button&quot; value=&quot;Submit&quot;&gt; After.&lt;/p&gt;
</ins><span class="cx"> 
</span><span class="cx"> &lt;p id=&quot;description&quot;&gt;&lt;/p&gt;
</span><span class="cx"> &lt;div id=&quot;console&quot;&gt;&lt;/div&gt;
</span><span class="cx"> 
</span><ins>+&lt;p id=&quot;endText&quot;&gt;End text.&lt;/p&gt;
+
</ins><span class="cx"> &lt;script&gt;
</span><span class="cx">     description(&quot;This tests that initial selection is set when arrow keys are pressed and no selection exists.&quot;);
</span><span class="cx">     
</span><ins>+    var afterButtonTextRange = null;
+    var beforeButtonTextRange = null;
+    
+    var documentEndTextRange = null;
+    var documentStartTextRange = null;
+    
</ins><span class="cx">     function clearSelection() {
</span><span class="cx">         window.getSelection().removeAllRanges();
</span><span class="cx">     }
</span><span class="cx">     
</span><ins>+    function isSelection() {
+        return window.getSelection().rangeCount &gt; 0;
+    }
+    
+    function isSelectionAfterButton() {
+        if (isSelection() === false)
+            return false;
+        var selectionRange = window.getSelection().getRangeAt(0);
+        if (afterButtonTextRange === null) {
+            var buttonNode = document.getElementById(&quot;button&quot;);
+            afterButtonTextRange = new Range();
+            afterButtonTextRange.setEndAfter(buttonNode);
+            afterButtonTextRange.setStartBefore(buttonNode.nextSibling);
+        }
+        return selectionRange.endOffset === afterButtonTextRange.endOffset &amp;&amp; selectionRange.startOffset === afterButtonTextRange.startOffset;
+    }
+    
+    function isSelectionBeforeButton() {
+        if (isSelection() === false)
+            return false;
+        var selectionRange = window.getSelection().getRangeAt(0);
+        if (beforeButtonTextRange === null) {
+            var buttonNode = document.getElementById(&quot;button&quot;);
+            beforeButtonTextRange = new Range();
+            beforeButtonTextRange.setEnd(buttonNode.previousSibling, buttonNode.previousSibling.length);
+            beforeButtonTextRange.setStart(buttonNode.previousSibling, buttonNode.previousSibling.length);
+        }
+        return selectionRange.endOffset === beforeButtonTextRange.endOffset &amp;&amp; selectionRange.startOffset === beforeButtonTextRange.startOffset;
+    }
+    
+    function isSelectionAtEndOfDocument() {
+        if (isSelection() === false)
+            return false;
+        var selectionRange = window.getSelection().getRangeAt(0);
+        if (documentEndTextRange === null) {
+            var endTextNode = document.getElementById(&quot;endText&quot;).firstChild;
+            documentEndTextRange = new Range();
+            documentEndTextRange.setEnd(endTextNode, endTextNode.length);
+            documentEndTextRange.setStart(endTextNode, endTextNode.length);
+        }
+        return selectionRange.endOffset === documentEndTextRange.endOffset &amp;&amp; selectionRange.startOffset === documentEndTextRange.startOffset;
+    }
+    
</ins><span class="cx">     function isSelectionAtStartOfDocument() {
</span><del>-        var selection = window.getSelection();
-        return selection.rangeCount &gt;= 1 &amp;&amp; selection.getRangeAt(0).endOffset === 0 &amp;&amp; selection.getRangeAt(0).startOffset === 0;
</del><ins>+        if (isSelection() === false)
+            return false;
+        var selectionRange = window.getSelection().getRangeAt(0);
+        if (documentStartTextRange === null) {
+            var startTextNode = document.getElementById(&quot;startText&quot;).firstChild;
+            documentStartTextRange = new Range();
+            documentStartTextRange.setEnd(startTextNode, 0);
+            documentStartTextRange.setStart(startTextNode, 0);
+        }
+        return selectionRange.endOffset === documentStartTextRange.endOffset &amp;&amp; selectionRange.startOffset === documentStartTextRange.startOffset;
</ins><span class="cx">     }
</span><span class="cx">     
</span><span class="cx">     if (window.accessibilityController &amp;&amp; window.eventSender) {
</span><ins>+        // Tests WITHOUT focus set.
+        
</ins><span class="cx">         // Down arrow key (should NOT set initial selection before enhanced accessibility is enabled).
</span><del>-        shouldBe(&quot;isSelectionAtStartOfDocument()&quot;, &quot;false&quot;);
</del><ins>+        shouldBe(&quot;isSelection()&quot;, &quot;false&quot;);
</ins><span class="cx">         eventSender.keyDown(&quot;downArrow&quot;);
</span><del>-        shouldBe(&quot;isSelectionAtStartOfDocument()&quot;, &quot;false&quot;);
</del><ins>+        shouldBe(&quot;isSelection()&quot;, &quot;false&quot;);
</ins><span class="cx">         clearSelection();
</span><span class="cx">         
</span><span class="cx">         // Enable enhanced accessibility (necessary for accessibility specific selection handling).
</span><span class="lines">@@ -35,36 +96,66 @@
</span><span class="cx">         shouldBe(&quot;accessibilityController.enhancedAccessibilityEnabled&quot;, &quot;true&quot;);
</span><span class="cx">         
</span><span class="cx">         // Down arrow key.
</span><del>-        shouldBe(&quot;isSelectionAtStartOfDocument()&quot;, &quot;false&quot;);
</del><ins>+        shouldBe(&quot;isSelection()&quot;, &quot;false&quot;);
</ins><span class="cx">         eventSender.keyDown(&quot;downArrow&quot;);
</span><span class="cx">         shouldBe(&quot;isSelectionAtStartOfDocument()&quot;, &quot;true&quot;);
</span><span class="cx">         clearSelection();
</span><span class="cx">         
</span><span class="cx">         // Left arrow key.
</span><del>-        shouldBe(&quot;isSelectionAtStartOfDocument()&quot;, &quot;false&quot;);
</del><ins>+        shouldBe(&quot;isSelection()&quot;, &quot;false&quot;);
</ins><span class="cx">         eventSender.keyDown(&quot;leftArrow&quot;);
</span><del>-        shouldBe(&quot;isSelectionAtStartOfDocument()&quot;, &quot;true&quot;);
</del><ins>+        shouldBe(&quot;isSelectionAtEndOfDocument()&quot;, &quot;true&quot;);
</ins><span class="cx">         clearSelection();
</span><span class="cx">         
</span><span class="cx">         // Right arrow key.
</span><del>-        shouldBe(&quot;isSelectionAtStartOfDocument()&quot;, &quot;false&quot;);
</del><ins>+        shouldBe(&quot;isSelection()&quot;, &quot;false&quot;);
</ins><span class="cx">         eventSender.keyDown(&quot;rightArrow&quot;);
</span><span class="cx">         shouldBe(&quot;isSelectionAtStartOfDocument()&quot;, &quot;true&quot;);
</span><span class="cx">         clearSelection();
</span><span class="cx">         
</span><span class="cx">         // Up arrow key.
</span><del>-        shouldBe(&quot;isSelectionAtStartOfDocument()&quot;, &quot;false&quot;);
</del><ins>+        shouldBe(&quot;isSelection()&quot;, &quot;false&quot;);
</ins><span class="cx">         eventSender.keyDown(&quot;upArrow&quot;);
</span><del>-        shouldBe(&quot;isSelectionAtStartOfDocument()&quot;, &quot;true&quot;);
</del><ins>+        shouldBe(&quot;isSelectionAtEndOfDocument()&quot;, &quot;true&quot;);
</ins><span class="cx">         clearSelection();
</span><span class="cx">         
</span><span class="cx">         // Z key (only arrow keys should set initial selection if no selection exists).
</span><del>-        shouldBe(&quot;isSelectionAtStartOfDocument()&quot;, &quot;false&quot;);
</del><ins>+        shouldBe(&quot;isSelection()&quot;, &quot;false&quot;);
</ins><span class="cx">         eventSender.keyDown(&quot;Z&quot;);
</span><del>-        shouldBe(&quot;isSelectionAtStartOfDocument()&quot;, &quot;false&quot;);
</del><ins>+        shouldBe(&quot;isSelection()&quot;, &quot;false&quot;);
</ins><span class="cx">         
</span><ins>+        // Tests WITH focus set.
+        
+        // Set focus.
+        document.getElementById(&quot;button&quot;).focus();
+        
+        // Down arrow key.
+        shouldBe(&quot;isSelection()&quot;, &quot;false&quot;);
+        eventSender.keyDown(&quot;downArrow&quot;);
+        shouldBe(&quot;isSelectionAfterButton()&quot;, &quot;true&quot;);
+        clearSelection();
+        
+        // Left arrow key.
+        shouldBe(&quot;isSelection()&quot;, &quot;false&quot;);
+        eventSender.keyDown(&quot;leftArrow&quot;);
+        shouldBe(&quot;isSelectionBeforeButton()&quot;, &quot;true&quot;);
+        clearSelection();
+        
+        // Right arrow key.
+        shouldBe(&quot;isSelection()&quot;, &quot;false&quot;);
+        eventSender.keyDown(&quot;rightArrow&quot;);
+        shouldBe(&quot;isSelectionAfterButton()&quot;, &quot;true&quot;);
+        clearSelection();
+        
+        // Up arrow key.
+        shouldBe(&quot;isSelection()&quot;, &quot;false&quot;);
+        eventSender.keyDown(&quot;upArrow&quot;);
+        shouldBe(&quot;isSelectionBeforeButton()&quot;, &quot;true&quot;);
+        clearSelection();
+        
</ins><span class="cx">         // Hide superfluous text.
</span><del>-        document.getElementById(&quot;text&quot;).style.display = &quot;none&quot;;
</del><ins>+        document.getElementById(&quot;endText&quot;).style.display = &quot;none&quot;;
+        document.getElementById(&quot;startText&quot;).style.display = &quot;none&quot;;
</ins><span class="cx">     }
</span><span class="cx"> &lt;/script&gt;
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (167032 => 167033)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2014-04-09 21:07:14 UTC (rev 167032)
+++ trunk/Source/WebCore/ChangeLog        2014-04-09 21:13:24 UTC (rev 167033)
</span><span class="lines">@@ -1,3 +1,18 @@
</span><ins>+2014-04-08  Samuel White  &lt;samuel_white@apple.com&gt;
+
+        AX: Initial text selection point should respect element focus.
+        https://bugs.webkit.org/show_bug.cgi?id=131402
+
+        Reviewed by Chris Fleizach.
+
+        Support the case where we want to set the initial selection and there's already a focused element.
+
+        No new tests, updated existing selection-initial to test this functionality.
+
+        * page/EventHandler.cpp:
+        (WebCore::setKeyboardSelection):
+        (WebCore::handleKeyboardSelectionMovement):
+
</ins><span class="cx"> 2014-04-09  Ryosuke Niwa  &lt;rniwa@webkit.org&gt;
</span><span class="cx"> 
</span><span class="cx">         HTMLCollection::updateNamedElementCach iterates over items twice
</span></span></pre></div>
<a id="trunkSourceWebCorepageEventHandlercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/EventHandler.cpp (167032 => 167033)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/EventHandler.cpp        2014-04-09 21:07:14 UTC (rev 167032)
+++ trunk/Source/WebCore/page/EventHandler.cpp        2014-04-09 21:13:24 UTC (rev 167033)
</span><span class="lines">@@ -3046,6 +3046,40 @@
</span><span class="cx">     return retVal;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+static void setInitialKeyboardSelection(Frame&amp; frame, SelectionDirection direction)
+{
+    Document* document = frame.document();
+    if (!document)
+        return;
+
+    FrameSelection&amp; selection = frame.selection();
+
+    if (!selection.isNone())
+        return;
+
+    Element* focusedElement = document-&gt;focusedElement();
+    VisiblePosition visiblePosition;
+
+    switch (direction) {
+    case DirectionBackward:
+    case DirectionLeft:
+        if (focusedElement)
+            visiblePosition = VisiblePosition(positionBeforeNode(focusedElement));
+        else
+            visiblePosition = endOfDocument(document);
+        break;
+    case DirectionForward:
+    case DirectionRight:
+        if (focusedElement)
+            visiblePosition = VisiblePosition(positionAfterNode(focusedElement));
+        else
+            visiblePosition = startOfDocument(document);
+        break;
+    }
+
+    selection.setSelection(visiblePosition, FrameSelection::defaultSetSelectionOptions(UserTriggered));
+}
+
</ins><span class="cx"> static void handleKeyboardSelectionMovement(Frame&amp; frame, KeyboardEvent* event)
</span><span class="cx"> {
</span><span class="cx">     if (!event)
</span><span class="lines">@@ -3089,7 +3123,7 @@
</span><span class="cx">     if (isSelection)
</span><span class="cx">         selection.modify(alternation, direction, granularity, UserTriggered);
</span><span class="cx">     else
</span><del>-        selection.setSelection(startOfDocument(frame.document()), FrameSelection::defaultSetSelectionOptions(UserTriggered));
</del><ins>+        setInitialKeyboardSelection(frame, direction);
</ins><span class="cx"> 
</span><span class="cx">     event-&gt;setDefaultHandled();
</span><span class="cx"> }
</span></span></pre>
</div>
</div>

</body>
</html>