<!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>[200479] 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/200479">200479</a></dd>
<dt>Author</dt> <dd>n_wang@apple.com</dd>
<dt>Date</dt> <dd>2016-05-05 14:38:41 -0700 (Thu, 05 May 2016)</dd>
</dl>
<h3>Log Message</h3>
<pre>For keyboard users, activating a fragment URL should transfer focus and caret to the destination
https://bugs.webkit.org/show_bug.cgi?id=116046
Reviewed by Ryosuke Niwa.
Source/WebCore:
Added a sequential focus navigation starting node to document. When TAB or SHIFT-TAB is pressed
and there is no focused element, we start searching for next focus candidates at the sequential
focus navigation node.
Test: fast/events/sequential-focus-navigation-starting-point.html
* dom/Document.cpp:
(WebCore::Document::removedLastRef):
(WebCore::Document::destroyRenderTree):
(WebCore::Document::removeFocusedNodeOfSubtree):
(WebCore::Document::hoveredElementDidDetach):
(WebCore::Document::setFocusedElement):
(WebCore::isNodeFrameOrDocument):
(WebCore::Document::setFocusNavigationStartingNode):
(WebCore::Document::focusNavigationStartingNode):
(WebCore::Document::setCSSTarget):
(WebCore::Document::nodeChildrenWillBeRemoved):
(WebCore::Document::nodeWillBeRemoved):
(WebCore::fallbackFocusNavigationStartingNodeAfterRemoval):
(WebCore::Document::updateFocusNavigationStartingNodeWithNodeRemoval):
(WebCore::Document::textInserted):
* dom/Document.h:
(WebCore::Document::userActionElements):
* page/EventHandler.cpp:
(WebCore::EventHandler::handleMousePressEvent):
* page/FocusController.cpp:
(WebCore::FocusController::advanceFocusInDocumentOrder):
* page/FrameView.cpp:
(WebCore::FrameView::scrollToAnchor):
LayoutTests:
Updated fast/dom/fragment-activation-focuses-target.html, now that navigating to a unfocusable
fragment will unset the focused element.
* fast/dom/fragment-activation-focuses-target-expected.txt:
* fast/dom/fragment-activation-focuses-target.html:
* fast/events/sequential-focus-navigation-starting-point-expected.txt: Added.
* fast/events/sequential-focus-navigation-starting-point.html: Added.
* platform/ios-simulator/TestExpectations:</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkLayoutTestsfastdomfragmentactivationfocusestargetexpectedtxt">trunk/LayoutTests/fast/dom/fragment-activation-focuses-target-expected.txt</a></li>
<li><a href="#trunkLayoutTestsfastdomfragmentactivationfocusestargethtml">trunk/LayoutTests/fast/dom/fragment-activation-focuses-target.html</a></li>
<li><a href="#trunkLayoutTestsplatformiossimulatorTestExpectations">trunk/LayoutTests/platform/ios-simulator/TestExpectations</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoredomDocumentcpp">trunk/Source/WebCore/dom/Document.cpp</a></li>
<li><a href="#trunkSourceWebCoredomDocumenth">trunk/Source/WebCore/dom/Document.h</a></li>
<li><a href="#trunkSourceWebCorepageEventHandlercpp">trunk/Source/WebCore/page/EventHandler.cpp</a></li>
<li><a href="#trunkSourceWebCorepageFocusControllercpp">trunk/Source/WebCore/page/FocusController.cpp</a></li>
<li><a href="#trunkSourceWebCorepageFrameViewcpp">trunk/Source/WebCore/page/FrameView.cpp</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsfasteventssequentialfocusnavigationstartingpointexpectedtxt">trunk/LayoutTests/fast/events/sequential-focus-navigation-starting-point-expected.txt</a></li>
<li><a href="#trunkLayoutTestsfasteventssequentialfocusnavigationstartingpointhtml">trunk/LayoutTests/fast/events/sequential-focus-navigation-starting-point.html</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (200478 => 200479)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2016-05-05 21:31:59 UTC (rev 200478)
+++ trunk/LayoutTests/ChangeLog        2016-05-05 21:38:41 UTC (rev 200479)
</span><span class="lines">@@ -1,3 +1,19 @@
</span><ins>+2016-05-05 Nan Wang <n_wang@apple.com>
+
+ For keyboard users, activating a fragment URL should transfer focus and caret to the destination
+ https://bugs.webkit.org/show_bug.cgi?id=116046
+
+ Reviewed by Ryosuke Niwa.
+
+ Updated fast/dom/fragment-activation-focuses-target.html, now that navigating to a unfocusable
+ fragment will unset the focused element.
+
+ * fast/dom/fragment-activation-focuses-target-expected.txt:
+ * fast/dom/fragment-activation-focuses-target.html:
+ * fast/events/sequential-focus-navigation-starting-point-expected.txt: Added.
+ * fast/events/sequential-focus-navigation-starting-point.html: Added.
+ * platform/ios-simulator/TestExpectations:
+
</ins><span class="cx"> 2016-05-05 Carlos Alberto Lopez Perez <clopez@igalia.com>
</span><span class="cx">
</span><span class="cx"> [GTK] Unreviewed gardening.
</span></span></pre></div>
<a id="trunkLayoutTestsfastdomfragmentactivationfocusestargetexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/fast/dom/fragment-activation-focuses-target-expected.txt (200478 => 200479)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/dom/fragment-activation-focuses-target-expected.txt        2016-05-05 21:31:59 UTC (rev 200478)
+++ trunk/LayoutTests/fast/dom/fragment-activation-focuses-target-expected.txt        2016-05-05 21:38:41 UTC (rev 200479)
</span><span class="lines">@@ -14,9 +14,9 @@
</span><span class="cx"> Verify Tab behaves correctly after following the link.
</span><span class="cx"> PASS document.activeElement is document.getElementById('fragment3')
</span><span class="cx"> PASS document.activeElement is document.getElementById('fragment1')
</span><del>-Activate a link that does not have a focusable fragment and verify focus does not move.
</del><ins>+Activate a link that does not have a focusable fragment and verify that the currently focused element is unfocused.
</ins><span class="cx"> PASS document.activeElement is link2
</span><del>-PASS document.activeElement is link2
</del><ins>+PASS document.activeElement is document.body
</ins><span class="cx"> PASS successfullyParsed is true
</span><span class="cx">
</span><span class="cx"> TEST COMPLETE
</span></span></pre></div>
<a id="trunkLayoutTestsfastdomfragmentactivationfocusestargethtml"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/fast/dom/fragment-activation-focuses-target.html (200478 => 200479)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/dom/fragment-activation-focuses-target.html        2016-05-05 21:31:59 UTC (rev 200478)
+++ trunk/LayoutTests/fast/dom/fragment-activation-focuses-target.html        2016-05-05 21:38:41 UTC (rev 200479)
</span><span class="lines">@@ -43,12 +43,12 @@
</span><span class="cx"> shouldBe("document.activeElement", "document.getElementById('fragment1')");
</span><span class="cx"> }
</span><span class="cx">
</span><del>-debug("Activate a link that does not have a focusable fragment and verify focus does not move.");
</del><ins>+debug("Activate a link that does not have a focusable fragment and verify that the currently focused element is unfocused.");
</ins><span class="cx"> var link2 = document.getElementById("link2");
</span><span class="cx"> link2.focus();
</span><span class="cx"> shouldBe("document.activeElement", "link2");
</span><span class="cx"> link2.click();
</span><del>-shouldBe("document.activeElement", "link2");
</del><ins>+shouldBe("document.activeElement", "document.body");
</ins><span class="cx">
</span><span class="cx"> var successfullyParsed = true;
</span><span class="cx">
</span></span></pre></div>
<a id="trunkLayoutTestsfasteventssequentialfocusnavigationstartingpointexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/events/sequential-focus-navigation-starting-point-expected.txt (0 => 200479)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/events/sequential-focus-navigation-starting-point-expected.txt         (rev 0)
+++ trunk/LayoutTests/fast/events/sequential-focus-navigation-starting-point-expected.txt        2016-05-05 21:38:41 UTC (rev 200479)
</span><span class="lines">@@ -0,0 +1,19 @@
</span><ins>+Mouse press should update sequential focus navigation starting point.
+PASS container.innerHTML = '<input id=prev><div style="height:200px;"><span>text</span></div><input id=next>'; focusSpan(); moveFocus('forward'); document.activeElement.id is 'next'
+PASS container.innerHTML = '<input id=prev><div style="height:200px;"><span>text</span></div><input id=next>'; focusSpan(); moveFocus('backward'); document.activeElement.id is 'prev'
+PASS container.innerHTML = '<span style="font-size:60px;"><input id=prev>Text Text<input id=next></span>'; focusSpan(); moveFocus('forward'); document.activeElement.id is 'next'
+PASS container.innerHTML = '<span style="font-size:60px;"><input id=prev>Text Text<input id=next></span>'; focusSpan(); moveFocus('backward'); document.activeElement.id is 'prev'
+
+Fragment navigation should update sequential focus navigation starting point.
+PASS container.innerHTML = '<a href="#fragment"></a><input id=prev><a name="fragment"></a><input id=next>'; clickLink(); moveFocus('forward'); document.activeElement.id is 'next'
+
+Focusing an element should update sequential focus navigation starting point.
+PASS container.innerHTML = '<input id=prev><input id=start><input id=next>'; focusStart(); moveFocus('forward'); document.activeElement.id is 'next'
+
+After removing a focused element from the document tree, sequential focus navigation should start at a place where the focused element was.
+PASS container.innerHTML = '<input id=prev><input id=start><input id=next>'; focusStart(); removeStart(); moveFocus('forward'); document.activeElement.id is 'next'
+PASS container.innerHTML = '<input id=prev><input id=start><input id=next>'; focusStart(); removeStart(); moveFocus('backward'); document.activeElement.id is 'prev'
+PASS container.innerHTML = '<input id=prev><div><input id=start></div><input id=next>'; focusStart(); removeDiv(); moveFocus('forward'); document.activeElement.id is 'next'
+PASS container.innerHTML = '<div><input id=start><input id=prev></div><input id=next>'; focusStart(); removeStart(); moveFocus('forward'); document.activeElement.id is 'prev'
+
+
</ins></span></pre></div>
<a id="trunkLayoutTestsfasteventssequentialfocusnavigationstartingpointhtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/events/sequential-focus-navigation-starting-point.html (0 => 200479)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/events/sequential-focus-navigation-starting-point.html         (rev 0)
+++ trunk/LayoutTests/fast/events/sequential-focus-navigation-starting-point.html        2016-05-05 21:38:41 UTC (rev 200479)
</span><span class="lines">@@ -0,0 +1,69 @@
</span><ins>+<!DOCTYPE html>
+<body onload="runTest();">
+<script src="../../resources/js-test-pre.js"></script>
+<script src="../forms/resources/common.js"></script>
+<div id="log"></div>
+<div id="container"></div>
+<script>
+if (!window.eventSender)
+ document.body.textContent = 'This test requires window.eventSender.';
+
+function focusSpan() {
+ hoverOverElement(container.querySelector('span'));
+ eventSender.mouseDown();
+}
+
+function focusDiv() {
+ hoverOverElement(container.querySelector('div'));
+ eventSender.mouseDown();
+}
+
+function moveFocus(direction) {
+ eventSender.keyDown('\t', direction == 'forward' ? [] : ['shiftKey']);
+}
+
+function clickLink() {
+ container.querySelector('a').click();
+}
+
+function focusStart() {
+ container.querySelector('#start').focus();
+}
+
+function removeStart() {
+ container.querySelector('#start').remove();
+}
+
+function removeDiv() {
+ container.querySelector('div').remove();
+}
+
+function runTest() {
+
+ debug("Mouse press should update sequential focus navigation starting point.");
+ var container = document.querySelector('#container');
+
+ shouldBe("container.innerHTML = '<input id=prev><div style=\"height:200px;\"><span>text</span></div><input id=next>'; focusSpan(); moveFocus('forward'); document.activeElement.id", "'next'");
+ eventSender.mouseUp();
+ shouldBe("container.innerHTML = '<input id=prev><div style=\"height:200px;\"><span>text</span></div><input id=next>'; focusSpan(); moveFocus('backward'); document.activeElement.id", "'prev'");
+ eventSender.mouseUp();
+ shouldBe("container.innerHTML = '<span style=\"font-size:60px;\"><input id=prev>Text Text<input id=next></span>'; focusSpan(); moveFocus('forward'); document.activeElement.id", "'next'");
+ eventSender.mouseUp();
+ shouldBe("container.innerHTML = '<span style=\"font-size:60px;\"><input id=prev>Text Text<input id=next></span>'; focusSpan(); moveFocus('backward'); document.activeElement.id", "'prev'");
+ eventSender.mouseUp();
+
+ debug("\nFragment navigation should update sequential focus navigation starting point.");
+ shouldBe("container.innerHTML = '<a href=\"#fragment\"></a><input id=prev><a name=\"fragment\"></a><input id=next>'; clickLink(); moveFocus('forward'); document.activeElement.id", "'next'");
+
+ debug("\nFocusing an element should update sequential focus navigation starting point.");
+ shouldBe("container.innerHTML = '<input id=prev><input id=start><input id=next>'; focusStart(); moveFocus('forward'); document.activeElement.id", "'next'");
+
+ debug("\nAfter removing a focused element from the document tree, sequential focus navigation should start at a place where the focused element was.");
+ shouldBe("container.innerHTML = '<input id=prev><input id=start><input id=next>'; focusStart(); removeStart(); moveFocus('forward'); document.activeElement.id", "'next'");
+ shouldBe("container.innerHTML = '<input id=prev><input id=start><input id=next>'; focusStart(); removeStart(); moveFocus('backward'); document.activeElement.id", "'prev'");
+ shouldBe("container.innerHTML = '<input id=prev><div><input id=start></div><input id=next>'; focusStart(); removeDiv(); moveFocus('forward'); document.activeElement.id", "'next'");
+ shouldBe("container.innerHTML = '<div><input id=start><input id=prev></div><input id=next>'; focusStart(); removeStart(); moveFocus('forward'); document.activeElement.id", "'prev'");
+}
+
+</script>
+</body>
</ins><span class="cx">\ No newline at end of file
</span></span></pre></div>
<a id="trunkLayoutTestsplatformiossimulatorTestExpectations"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/platform/ios-simulator/TestExpectations (200478 => 200479)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/platform/ios-simulator/TestExpectations        2016-05-05 21:31:59 UTC (rev 200478)
+++ trunk/LayoutTests/platform/ios-simulator/TestExpectations        2016-05-05 21:38:41 UTC (rev 200479)
</span><span class="lines">@@ -261,6 +261,7 @@
</span><span class="cx">
</span><span class="cx"> # No tab navigation support on iOS
</span><span class="cx"> fast/shadow-dom/negative-tabindex-on-shadow-host.html [ Failure ]
</span><ins>+webkit.org/b/116046 fast/events/sequential-focus-navigation-starting-point.html [ Skip ]
</ins><span class="cx">
</span><span class="cx"> webkit.org/b/150225 fast/custom-elements [ Pass ]
</span><span class="cx">
</span></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (200478 => 200479)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2016-05-05 21:31:59 UTC (rev 200478)
+++ trunk/Source/WebCore/ChangeLog        2016-05-05 21:38:41 UTC (rev 200479)
</span><span class="lines">@@ -1,3 +1,40 @@
</span><ins>+2016-05-05 Nan Wang <n_wang@apple.com>
+
+ For keyboard users, activating a fragment URL should transfer focus and caret to the destination
+ https://bugs.webkit.org/show_bug.cgi?id=116046
+
+ Reviewed by Ryosuke Niwa.
+
+ Added a sequential focus navigation starting node to document. When TAB or SHIFT-TAB is pressed
+ and there is no focused element, we start searching for next focus candidates at the sequential
+ focus navigation node.
+
+ Test: fast/events/sequential-focus-navigation-starting-point.html
+
+ * dom/Document.cpp:
+ (WebCore::Document::removedLastRef):
+ (WebCore::Document::destroyRenderTree):
+ (WebCore::Document::removeFocusedNodeOfSubtree):
+ (WebCore::Document::hoveredElementDidDetach):
+ (WebCore::Document::setFocusedElement):
+ (WebCore::isNodeFrameOrDocument):
+ (WebCore::Document::setFocusNavigationStartingNode):
+ (WebCore::Document::focusNavigationStartingNode):
+ (WebCore::Document::setCSSTarget):
+ (WebCore::Document::nodeChildrenWillBeRemoved):
+ (WebCore::Document::nodeWillBeRemoved):
+ (WebCore::fallbackFocusNavigationStartingNodeAfterRemoval):
+ (WebCore::Document::updateFocusNavigationStartingNodeWithNodeRemoval):
+ (WebCore::Document::textInserted):
+ * dom/Document.h:
+ (WebCore::Document::userActionElements):
+ * page/EventHandler.cpp:
+ (WebCore::EventHandler::handleMousePressEvent):
+ * page/FocusController.cpp:
+ (WebCore::FocusController::advanceFocusInDocumentOrder):
+ * page/FrameView.cpp:
+ (WebCore::FrameView::scrollToAnchor):
+
</ins><span class="cx"> 2016-05-05 Ryosuke Niwa <rniwa@webkit.org>
</span><span class="cx">
</span><span class="cx"> Another iOS debug build fix after r200464.
</span></span></pre></div>
<a id="trunkSourceWebCoredomDocumentcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/Document.cpp (200478 => 200479)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/Document.cpp        2016-05-05 21:31:59 UTC (rev 200478)
+++ trunk/Source/WebCore/dom/Document.cpp        2016-05-05 21:38:41 UTC (rev 200479)
</span><span class="lines">@@ -691,6 +691,7 @@
</span><span class="cx"> m_activeElement = nullptr;
</span><span class="cx"> m_titleElement = nullptr;
</span><span class="cx"> m_documentElement = nullptr;
</span><ins>+ m_focusNavigationStartingNode = nullptr;
</ins><span class="cx"> m_userActionElements.documentDidRemoveLastRef();
</span><span class="cx"> #if ENABLE(FULLSCREEN_API)
</span><span class="cx"> m_fullScreenElement = nullptr;
</span><span class="lines">@@ -2311,6 +2312,7 @@
</span><span class="cx"> m_hoveredElement = nullptr;
</span><span class="cx"> m_focusedElement = nullptr;
</span><span class="cx"> m_activeElement = nullptr;
</span><ins>+ m_focusNavigationStartingNode = nullptr;
</ins><span class="cx">
</span><span class="cx"> if (m_documentElement)
</span><span class="cx"> RenderTreeUpdater::tearDownRenderers(*m_documentElement);
</span><span class="lines">@@ -3711,8 +3713,10 @@
</span><span class="cx"> else
</span><span class="cx"> nodeInSubtree = (focusedElement == node) || focusedElement->isDescendantOf(node);
</span><span class="cx">
</span><del>- if (nodeInSubtree)
</del><ins>+ if (nodeInSubtree) {
</ins><span class="cx"> setFocusedElement(nullptr);
</span><ins>+ setFocusNavigationStartingNode(focusedElement);
+ }
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> void Document::hoveredElementDidDetach(Element* element)
</span><span class="lines">@@ -3772,6 +3776,7 @@
</span><span class="cx"> oldFocusedElement->setActive(false);
</span><span class="cx">
</span><span class="cx"> oldFocusedElement->setFocus(false);
</span><ins>+ setFocusNavigationStartingNode(nullptr);
</ins><span class="cx">
</span><span class="cx"> // Dispatch a change event for form control elements that have been edited.
</span><span class="cx"> if (is<HTMLFormControlElement>(*oldFocusedElement)) {
</span><span class="lines">@@ -3819,6 +3824,7 @@
</span><span class="cx"> }
</span><span class="cx"> // Set focus on the new node
</span><span class="cx"> m_focusedElement = newFocusedElement;
</span><ins>+ setFocusNavigationStartingNode(m_focusedElement.get());
</ins><span class="cx">
</span><span class="cx"> // Dispatch the focus event and let the node do any other focus related activities (important for text fields)
</span><span class="cx"> m_focusedElement->dispatchFocusEvent(oldFocusedElement.copyRef(), direction);
</span><span class="lines">@@ -3885,6 +3891,59 @@
</span><span class="cx"> return !focusChangeBlocked;
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+static bool isNodeFrameOrDocument(Node& node)
+{
+ return is<HTMLIFrameElement>(node) || is<HTMLHtmlElement>(node) || is<HTMLDocument>(node);
+}
+
+void Document::setFocusNavigationStartingNode(Node* node)
+{
+ if (!m_frame)
+ return;
+
+ m_focusNavigationStartingNodeIsRemoved = false;
+ if (!node || isNodeFrameOrDocument(*node)) {
+ m_focusNavigationStartingNode = nullptr;
+ return;
+ }
+
+ m_focusNavigationStartingNode = node;
+}
+
+Element* Document::focusNavigationStartingNode(FocusDirection direction) const
+{
+ if (m_focusedElement) {
+ if (!m_focusNavigationStartingNode || !m_focusNavigationStartingNode->isDescendantOf(m_focusedElement.get()))
+ return m_focusedElement.get();
+ }
+
+ if (!m_focusNavigationStartingNode)
+ return nullptr;
+
+ Node* node = m_focusNavigationStartingNode.get();
+
+ // When the node was removed from the document tree. This case is not specified in the spec:
+ // https://html.spec.whatwg.org/multipage/interaction.html#sequential-focus-navigation-starting-point
+ // Current behaivor is to move the sequential navigation node to / after (based on the focus direction)
+ // the previous sibling of the removed node.
+ if (m_focusNavigationStartingNodeIsRemoved) {
+ Node* nextNode = NodeTraversal::next(*node);
+ if (direction == FocusDirectionForward)
+ return ElementTraversal::previous(*nextNode);
+ if (is<Element>(*nextNode))
+ return downcast<Element>(nextNode);
+ return ElementTraversal::next(*nextNode);
+ }
+
+ if (is<Element>(*node))
+ return downcast<Element>(node);
+ // When going forward, the sibling needs to be an element prior to the next focusable element.
+ // Similar logic goes to the backwards case.
+ if (Element* sibling = direction == FocusDirectionForward ? ElementTraversal::previous(*node) : ElementTraversal::next(*node))
+ return sibling;
+ return node->parentOrShadowHostElement();
+}
+
</ins><span class="cx"> void Document::setCSSTarget(Element* n)
</span><span class="cx"> {
</span><span class="cx"> if (m_cssTarget)
</span><span class="lines">@@ -3999,6 +4058,8 @@
</span><span class="cx"> for (Text* textNode = TextNodeTraversal::firstChild(container); textNode; textNode = TextNodeTraversal::nextSibling(*textNode))
</span><span class="cx"> m_markers->removeMarkers(textNode);
</span><span class="cx"> }
</span><ins>+
+ updateFocusNavigationStartingNodeWithNodeRemoval(container, true);
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> void Document::nodeWillBeRemoved(Node& n)
</span><span class="lines">@@ -4017,8 +4078,37 @@
</span><span class="cx">
</span><span class="cx"> if (is<Text>(n))
</span><span class="cx"> m_markers->removeMarkers(&n);
</span><ins>+
+ updateFocusNavigationStartingNodeWithNodeRemoval(n, false);
</ins><span class="cx"> }
</span><span class="cx">
</span><ins>+static Node* fallbackFocusNavigationStartingNodeAfterRemoval(Node& node)
+{
+ return node.previousSibling() ? node.previousSibling() : node.parentNode();
+}
+
+void Document::updateFocusNavigationStartingNodeWithNodeRemoval(Node& node, bool removeChildren)
+{
+ if (!m_focusNavigationStartingNode)
+ return;
+
+ if (m_focusNavigationStartingNode.get() == &node) {
+ if (removeChildren)
+ return;
+ m_focusNavigationStartingNode = fallbackFocusNavigationStartingNodeAfterRemoval(node);
+ m_focusNavigationStartingNodeIsRemoved = true;
+ return;
+ }
+
+ for (Node* parentNode = m_focusNavigationStartingNode->parentNode(); parentNode; parentNode = parentNode->parentNode()) {
+ if (parentNode == &node) {
+ m_focusNavigationStartingNode = removeChildren ? &node : fallbackFocusNavigationStartingNodeAfterRemoval(node);
+ m_focusNavigationStartingNodeIsRemoved = true;
+ return;
+ }
+ }
+}
+
</ins><span class="cx"> void Document::textInserted(Node* text, unsigned offset, unsigned length)
</span><span class="cx"> {
</span><span class="cx"> if (!m_ranges.isEmpty()) {
</span></span></pre></div>
<a id="trunkSourceWebCoredomDocumenth"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/Document.h (200478 => 200479)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/Document.h        2016-05-05 21:31:59 UTC (rev 200478)
+++ trunk/Source/WebCore/dom/Document.h        2016-05-05 21:38:41 UTC (rev 200479)
</span><span class="lines">@@ -729,6 +729,9 @@
</span><span class="cx"> UserActionElementSet& userActionElements() { return m_userActionElements; }
</span><span class="cx"> const UserActionElementSet& userActionElements() const { return m_userActionElements; }
</span><span class="cx">
</span><ins>+ void setFocusNavigationStartingNode(Node*);
+ Element* focusNavigationStartingNode(FocusDirection) const;
+
</ins><span class="cx"> void removeFocusedNodeOfSubtree(Node*, bool amongChildrenOnly = false);
</span><span class="cx"> void hoveredElementDidDetach(Element*);
</span><span class="cx"> void elementInActiveChainDidDetach(Element*);
</span><span class="lines">@@ -768,6 +771,7 @@
</span><span class="cx"> void nodeChildrenWillBeRemoved(ContainerNode&);
</span><span class="cx"> // nodeWillBeRemoved is only safe when removing one node at a time.
</span><span class="cx"> void nodeWillBeRemoved(Node&);
</span><ins>+ void updateFocusNavigationStartingNodeWithNodeRemoval(Node&, bool);
</ins><span class="cx"> enum class AcceptChildOperation { Replace, InsertOrAdd };
</span><span class="cx"> bool canAcceptChild(const Node& newChild, const Node* refChild, AcceptChildOperation) const;
</span><span class="cx">
</span><span class="lines">@@ -1464,6 +1468,8 @@
</span><span class="cx">
</span><span class="cx"> Color m_textColor;
</span><span class="cx">
</span><ins>+ bool m_focusNavigationStartingNodeIsRemoved;
+ RefPtr<Node> m_focusNavigationStartingNode;
</ins><span class="cx"> RefPtr<Element> m_focusedElement;
</span><span class="cx"> RefPtr<Element> m_hoveredElement;
</span><span class="cx"> RefPtr<Element> m_activeElement;
</span></span></pre></div>
<a id="trunkSourceWebCorepageEventHandlercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/EventHandler.cpp (200478 => 200479)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/EventHandler.cpp        2016-05-05 21:31:59 UTC (rev 200478)
+++ trunk/Source/WebCore/page/EventHandler.cpp        2016-05-05 21:38:41 UTC (rev 200479)
</span><span class="lines">@@ -793,6 +793,7 @@
</span><span class="cx"> focusDocumentView();
</span><span class="cx">
</span><span class="cx"> m_mousePressNode = event.targetNode();
</span><ins>+ m_frame.document()->setFocusNavigationStartingNode(event.targetNode());
</ins><span class="cx"> #if ENABLE(DRAG_SUPPORT)
</span><span class="cx"> m_dragStartPos = event.event().position();
</span><span class="cx"> #endif
</span><span class="lines">@@ -1648,6 +1649,7 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> m_mousePressNode = mouseEvent.targetNode();
</span><ins>+ m_frame.document()->setFocusNavigationStartingNode(mouseEvent.targetNode());
</ins><span class="cx">
</span><span class="cx"> RefPtr<Frame> subframe = subframeForHitTestResult(mouseEvent);
</span><span class="cx"> if (subframe && passMousePressEventToSubframe(mouseEvent, subframe.get())) {
</span></span></pre></div>
<a id="trunkSourceWebCorepageFocusControllercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/FocusController.cpp (200478 => 200479)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/FocusController.cpp        2016-05-05 21:31:59 UTC (rev 200478)
+++ trunk/Source/WebCore/page/FocusController.cpp        2016-05-05 21:38:41 UTC (rev 200479)
</span><span class="lines">@@ -345,7 +345,7 @@
</span><span class="cx"> Frame& frame = focusedOrMainFrame();
</span><span class="cx"> Document* document = frame.document();
</span><span class="cx">
</span><del>- Node* currentNode = document->focusedElement();
</del><ins>+ Node* currentNode = document->focusNavigationStartingNode(direction);
</ins><span class="cx"> // FIXME: Not quite correct when it comes to focus transitions leaving/entering the WebView itself
</span><span class="cx"> bool caretBrowsing = frame.settings().caretBrowsingEnabled();
</span><span class="cx">
</span></span></pre></div>
<a id="trunkSourceWebCorepageFrameViewcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/FrameView.cpp (200478 => 200479)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/FrameView.cpp        2016-05-05 21:31:59 UTC (rev 200478)
+++ trunk/Source/WebCore/page/FrameView.cpp        2016-05-05 21:38:41 UTC (rev 200479)
</span><span class="lines">@@ -2090,8 +2090,14 @@
</span><span class="cx"> maintainScrollPositionAtAnchor(scrollPositionAnchor);
</span><span class="cx">
</span><span class="cx"> // If the anchor accepts keyboard focus, move focus there to aid users relying on keyboard navigation.
</span><del>- if (anchorElement && anchorElement->isFocusable())
- document.setFocusedElement(anchorElement);
</del><ins>+ if (anchorElement) {
+ if (anchorElement->isFocusable())
+ document.setFocusedElement(anchorElement);
+ else {
+ document.setFocusedElement(nullptr);
+ document.setFocusNavigationStartingNode(anchorElement);
+ }
+ }
</ins><span class="cx">
</span><span class="cx"> return true;
</span><span class="cx"> }
</span></span></pre>
</div>
</div>
</body>
</html>