Title: [148481] trunk
Revision
148481
Author
[email protected]
Date
2013-04-15 18:01:14 -0700 (Mon, 15 Apr 2013)

Log Message

activating a focused link to an in-page fragment ID should transfer focus to the target of the link when possible
https://bugs.webkit.org/show_bug.cgi?id=17450

Reviewed by Maciej Stachowiak.

Source/WebCore: 

When a fragment is scrolled to due to an activation event or on load, focus should attempt to 
move to the fragment if possible.

Test: fast/dom/fragment-activation-focuses-target.html

* page/FrameView.cpp:
(WebCore::FrameView::scrollToAnchor):

LayoutTests: 

* fast/dom/fragment-activation-focuses-target.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (148480 => 148481)


--- trunk/LayoutTests/ChangeLog	2013-04-16 00:30:26 UTC (rev 148480)
+++ trunk/LayoutTests/ChangeLog	2013-04-16 01:01:14 UTC (rev 148481)
@@ -1,3 +1,12 @@
+2013-04-15  Chris Fleizach  <[email protected]>
+
+        activating a focused link to an in-page fragment ID should transfer focus to the target of the link when possible
+        https://bugs.webkit.org/show_bug.cgi?id=17450
+
+        Reviewed by Maciej Stachowiak.
+
+        * fast/dom/fragment-activation-focuses-target.html: Added.
+
 2013-04-15  Robert Hogan  <[email protected]>
 
         An inline element with an absolutely positioned child does not correctly calculate/render padding and margin

Added: trunk/LayoutTests/fast/dom/fragment-activation-focuses-target-expected.txt (0 => 148481)


--- trunk/LayoutTests/fast/dom/fragment-activation-focuses-target-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/fragment-activation-focuses-target-expected.txt	2013-04-16 01:01:14 UTC (rev 148481)
@@ -0,0 +1,23 @@
+This tests that if an in-page link is activated, focus control is transferred to the fragment if possible.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Verify that the focus is on the link.
+PASS document.activeElement is link1
+Click the link and verify that focus has moved to the fragment.
+PASS document.activeElement is document.getElementById('fragment1')
+Move focus back to the link and verify.
+PASS document.activeElement is link1
+Send an enter key event which should also trigger focus to move to the fragment.
+PASS document.activeElement is document.getElementById('fragment1')
+Activate a link that does not have a focusable fragment and verify focus does not move.
+PASS document.activeElement is link2
+PASS document.activeElement is link2
+PASS successfullyParsed is true
+
+TEST COMPLETE
+link1 link2 
+
+fragment1
+fragment2

Added: trunk/LayoutTests/fast/dom/fragment-activation-focuses-target.html (0 => 148481)


--- trunk/LayoutTests/fast/dom/fragment-activation-focuses-target.html	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/fragment-activation-focuses-target.html	2013-04-16 01:01:14 UTC (rev 148481)
@@ -0,0 +1,51 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+</head>
+<body>
+
+<a href="" id="link1" tabindex="0">link1</a>
+<a href="" id="link2" tabindex="0">link2</a>
+
+<br><br>
+
+<div id="fragment1" name="fragment1" tabindex="0">fragment1</div>
+<div id="fragment2" name="fragment2">fragment2</div>
+
+<script>
+
+description("This tests that if an in-page link is activated, focus control is transferred to the fragment if possible.");
+
+var link1 = document.getElementById("link1");
+link1.focus();
+debug("Verify that the focus is on the link.");
+shouldBe("document.activeElement", "link1");
+
+link1.click();
+debug("Click the link and verify that focus has moved to the fragment.");
+shouldBe("document.activeElement", "document.getElementById('fragment1')");
+
+debug("Move focus back to the link and verify.");
+link1.focus();
+shouldBe("document.activeElement", "link1");
+
+if (window.testRunner) {
+  debug("Send an enter key event which should also trigger focus to move to the fragment.");
+  eventSender.keyDown("\r");
+  shouldBe("document.activeElement", "document.getElementById('fragment1')");
+}
+
+debug("Activate a link that does not have a focusable fragment and verify focus does not move.");
+var link2 = document.getElementById("link2");
+link2.focus();
+shouldBe("document.activeElement", "link2");
+link2.click();
+shouldBe("document.activeElement", "link2");
+
+var successfullyParsed = true;
+
+</script>
+<script src=""
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (148480 => 148481)


--- trunk/Source/WebCore/ChangeLog	2013-04-16 00:30:26 UTC (rev 148480)
+++ trunk/Source/WebCore/ChangeLog	2013-04-16 01:01:14 UTC (rev 148481)
@@ -1,3 +1,18 @@
+2013-04-15  Chris Fleizach  <[email protected]>
+
+        activating a focused link to an in-page fragment ID should transfer focus to the target of the link when possible
+        https://bugs.webkit.org/show_bug.cgi?id=17450
+
+        Reviewed by Maciej Stachowiak.
+
+        When a fragment is scrolled to due to an activation event or on load, focus should attempt to 
+        move to the fragment if possible.
+
+        Test: fast/dom/fragment-activation-focuses-target.html
+
+        * page/FrameView.cpp:
+        (WebCore::FrameView::scrollToAnchor):
+
 2013-04-12  Maciej Stachowiak  <[email protected]>
 
         Remove V8-specific extended attributes from IDL files

Modified: trunk/Source/WebCore/page/FrameView.cpp (148480 => 148481)


--- trunk/Source/WebCore/page/FrameView.cpp	2013-04-16 00:30:26 UTC (rev 148480)
+++ trunk/Source/WebCore/page/FrameView.cpp	2013-04-16 01:01:14 UTC (rev 148481)
@@ -1851,6 +1851,11 @@
         return false;
 
     maintainScrollPositionAtAnchor(anchorNode ? static_cast<Node*>(anchorNode) : m_frame->document());
+    
+    // If the anchor accepts keyboard focus, move focus there to aid users relying on keyboard navigation.
+    if (anchorNode && anchorNode->isFocusable())
+        m_frame->document()->setFocusedNode(anchorNode);
+    
     return true;
 }
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to