Diff
Modified: trunk/LayoutTests/ChangeLog (200478 => 200479)
--- trunk/LayoutTests/ChangeLog 2016-05-05 21:31:59 UTC (rev 200478)
+++ trunk/LayoutTests/ChangeLog 2016-05-05 21:38:41 UTC (rev 200479)
@@ -1,3 +1,19 @@
+2016-05-05 Nan Wang <n_w...@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:
+
2016-05-05 Carlos Alberto Lopez Perez <clo...@igalia.com>
[GTK] Unreviewed gardening.
Modified: trunk/LayoutTests/fast/dom/fragment-activation-focuses-target-expected.txt (200478 => 200479)
--- 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)
@@ -14,9 +14,9 @@
Verify Tab behaves correctly after following the link.
PASS document.activeElement is document.getElementById('fragment3')
PASS document.activeElement is document.getElementById('fragment1')
-Activate a link that does not have a focusable fragment and verify focus does not move.
+Activate a link that does not have a focusable fragment and verify that the currently focused element is unfocused.
PASS document.activeElement is link2
-PASS document.activeElement is link2
+PASS document.activeElement is document.body
PASS successfullyParsed is true
TEST COMPLETE
Modified: trunk/LayoutTests/fast/dom/fragment-activation-focuses-target.html (200478 => 200479)
--- 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)
@@ -43,12 +43,12 @@
shouldBe("document.activeElement", "document.getElementById('fragment1')");
}
-debug("Activate a link that does not have a focusable fragment and verify focus does not move.");
+debug("Activate a link that does not have a focusable fragment and verify that the currently focused element is unfocused.");
var link2 = document.getElementById("link2");
link2.focus();
shouldBe("document.activeElement", "link2");
link2.click();
-shouldBe("document.activeElement", "link2");
+shouldBe("document.activeElement", "document.body");
var successfullyParsed = true;
Added: trunk/LayoutTests/fast/events/sequential-focus-navigation-starting-point-expected.txt (0 => 200479)
--- 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)
@@ -0,0 +1,19 @@
+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="" 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'
+
+
Added: trunk/LayoutTests/fast/events/sequential-focus-navigation-starting-point.html (0 => 200479)
--- 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)
@@ -0,0 +1,69 @@
+<!DOCTYPE html>
+<body _onload_="runTest();">
+<script src=""
+<script src=""
+<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="" 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>
\ No newline at end of file
Modified: trunk/LayoutTests/platform/ios-simulator/TestExpectations (200478 => 200479)
--- 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)
@@ -261,6 +261,7 @@
# No tab navigation support on iOS
fast/shadow-dom/negative-tabindex-on-shadow-host.html [ Failure ]
+webkit.org/b/116046 fast/events/sequential-focus-navigation-starting-point.html [ Skip ]
webkit.org/b/150225 fast/custom-elements [ Pass ]
Modified: trunk/Source/WebCore/ChangeLog (200478 => 200479)
--- 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)
@@ -1,3 +1,40 @@
+2016-05-05 Nan Wang <n_w...@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):
+
2016-05-05 Ryosuke Niwa <rn...@webkit.org>
Another iOS debug build fix after r200464.
Modified: trunk/Source/WebCore/dom/Document.cpp (200478 => 200479)
--- 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)
@@ -691,6 +691,7 @@
m_activeElement = nullptr;
m_titleElement = nullptr;
m_documentElement = nullptr;
+ m_focusNavigationStartingNode = nullptr;
m_userActionElements.documentDidRemoveLastRef();
#if ENABLE(FULLSCREEN_API)
m_fullScreenElement = nullptr;
@@ -2311,6 +2312,7 @@
m_hoveredElement = nullptr;
m_focusedElement = nullptr;
m_activeElement = nullptr;
+ m_focusNavigationStartingNode = nullptr;
if (m_documentElement)
RenderTreeUpdater::tearDownRenderers(*m_documentElement);
@@ -3711,8 +3713,10 @@
else
nodeInSubtree = (focusedElement == node) || focusedElement->isDescendantOf(node);
- if (nodeInSubtree)
+ if (nodeInSubtree) {
setFocusedElement(nullptr);
+ setFocusNavigationStartingNode(focusedElement);
+ }
}
void Document::hoveredElementDidDetach(Element* element)
@@ -3772,6 +3776,7 @@
oldFocusedElement->setActive(false);
oldFocusedElement->setFocus(false);
+ setFocusNavigationStartingNode(nullptr);
// Dispatch a change event for form control elements that have been edited.
if (is<HTMLFormControlElement>(*oldFocusedElement)) {
@@ -3819,6 +3824,7 @@
}
// Set focus on the new node
m_focusedElement = newFocusedElement;
+ setFocusNavigationStartingNode(m_focusedElement.get());
// Dispatch the focus event and let the node do any other focus related activities (important for text fields)
m_focusedElement->dispatchFocusEvent(oldFocusedElement.copyRef(), direction);
@@ -3885,6 +3891,59 @@
return !focusChangeBlocked;
}
+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();
+}
+
void Document::setCSSTarget(Element* n)
{
if (m_cssTarget)
@@ -3999,6 +4058,8 @@
for (Text* textNode = TextNodeTraversal::firstChild(container); textNode; textNode = TextNodeTraversal::nextSibling(*textNode))
m_markers->removeMarkers(textNode);
}
+
+ updateFocusNavigationStartingNodeWithNodeRemoval(container, true);
}
void Document::nodeWillBeRemoved(Node& n)
@@ -4017,8 +4078,37 @@
if (is<Text>(n))
m_markers->removeMarkers(&n);
+
+ updateFocusNavigationStartingNodeWithNodeRemoval(n, false);
}
+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;
+ }
+ }
+}
+
void Document::textInserted(Node* text, unsigned offset, unsigned length)
{
if (!m_ranges.isEmpty()) {
Modified: trunk/Source/WebCore/dom/Document.h (200478 => 200479)
--- 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)
@@ -729,6 +729,9 @@
UserActionElementSet& userActionElements() { return m_userActionElements; }
const UserActionElementSet& userActionElements() const { return m_userActionElements; }
+ void setFocusNavigationStartingNode(Node*);
+ Element* focusNavigationStartingNode(FocusDirection) const;
+
void removeFocusedNodeOfSubtree(Node*, bool amongChildrenOnly = false);
void hoveredElementDidDetach(Element*);
void elementInActiveChainDidDetach(Element*);
@@ -768,6 +771,7 @@
void nodeChildrenWillBeRemoved(ContainerNode&);
// nodeWillBeRemoved is only safe when removing one node at a time.
void nodeWillBeRemoved(Node&);
+ void updateFocusNavigationStartingNodeWithNodeRemoval(Node&, bool);
enum class AcceptChildOperation { Replace, InsertOrAdd };
bool canAcceptChild(const Node& newChild, const Node* refChild, AcceptChildOperation) const;
@@ -1464,6 +1468,8 @@
Color m_textColor;
+ bool m_focusNavigationStartingNodeIsRemoved;
+ RefPtr<Node> m_focusNavigationStartingNode;
RefPtr<Element> m_focusedElement;
RefPtr<Element> m_hoveredElement;
RefPtr<Element> m_activeElement;
Modified: trunk/Source/WebCore/page/EventHandler.cpp (200478 => 200479)
--- 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)
@@ -793,6 +793,7 @@
focusDocumentView();
m_mousePressNode = event.targetNode();
+ m_frame.document()->setFocusNavigationStartingNode(event.targetNode());
#if ENABLE(DRAG_SUPPORT)
m_dragStartPos = event.event().position();
#endif
@@ -1648,6 +1649,7 @@
}
m_mousePressNode = mouseEvent.targetNode();
+ m_frame.document()->setFocusNavigationStartingNode(mouseEvent.targetNode());
RefPtr<Frame> subframe = subframeForHitTestResult(mouseEvent);
if (subframe && passMousePressEventToSubframe(mouseEvent, subframe.get())) {
Modified: trunk/Source/WebCore/page/FocusController.cpp (200478 => 200479)
--- 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)
@@ -345,7 +345,7 @@
Frame& frame = focusedOrMainFrame();
Document* document = frame.document();
- Node* currentNode = document->focusedElement();
+ Node* currentNode = document->focusNavigationStartingNode(direction);
// FIXME: Not quite correct when it comes to focus transitions leaving/entering the WebView itself
bool caretBrowsing = frame.settings().caretBrowsingEnabled();
Modified: trunk/Source/WebCore/page/FrameView.cpp (200478 => 200479)
--- 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)
@@ -2090,8 +2090,14 @@
maintainScrollPositionAtAnchor(scrollPositionAnchor);
// If the anchor accepts keyboard focus, move focus there to aid users relying on keyboard navigation.
- if (anchorElement && anchorElement->isFocusable())
- document.setFocusedElement(anchorElement);
+ if (anchorElement) {
+ if (anchorElement->isFocusable())
+ document.setFocusedElement(anchorElement);
+ else {
+ document.setFocusedElement(nullptr);
+ document.setFocusNavigationStartingNode(anchorElement);
+ }
+ }
return true;
}