WebCore:
authoradele@apple.com <adele@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 4 Mar 2008 21:09:07 +0000 (21:09 +0000)
committeradele@apple.com <adele@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 4 Mar 2008 21:09:07 +0000 (21:09 +0000)
        Reviewed by Beth.

        Fix for <rdar://problem/5779718> focus() does not work for anchor elements with no content

        If an anchor has zero size, don't exclude it from being focusable from JS, just exclude it
        from being keyboard focusable (using the tab key).

        * html/HTMLAnchorElement.cpp:
        (WebCore::HTMLAnchorElement::isFocusable):
        (WebCore::HTMLAnchorElement::isKeyboardFocusable):

LayoutTests:

        Reviewed by Beth.

        Test for <rdar://problem/5779718> focus() does not work for anchor elements with no content

        * fast/events/anchor-empty-focus-expected.txt: Added.
        * fast/events/anchor-empty-focus.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@30761 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/fast/events/anchor-empty-focus-expected.txt [new file with mode: 0644]
LayoutTests/fast/events/anchor-empty-focus.html [new file with mode: 0644]
WebCore/ChangeLog
WebCore/html/HTMLAnchorElement.cpp

index ad8a2c1..5ef2227 100644 (file)
@@ -1,3 +1,12 @@
+2008-03-04  Adele Peterson  <adele@apple.com>
+
+        Reviewed by Beth.
+
+        Test for <rdar://problem/5779718> focus() does not work for anchor elements with no content
+
+        * fast/events/anchor-empty-focus-expected.txt: Added.
+        * fast/events/anchor-empty-focus.html: Added.
+
 2008-03-04  Dan Bernstein  <mitz@apple.com>
 
         - test for <rdar://problem/5622336> Burmese text does not render on http://www.myanmarbible.com/bible/Judson/html/index.html
diff --git a/LayoutTests/fast/events/anchor-empty-focus-expected.txt b/LayoutTests/fast/events/anchor-empty-focus-expected.txt
new file mode 100644 (file)
index 0000000..a547e82
--- /dev/null
@@ -0,0 +1,3 @@
+This tests that focus() works on an empty anchor.
+
+TEST PASSED
diff --git a/LayoutTests/fast/events/anchor-empty-focus.html b/LayoutTests/fast/events/anchor-empty-focus.html
new file mode 100644 (file)
index 0000000..cf209d7
--- /dev/null
@@ -0,0 +1,20 @@
+<html>
+   <head>
+      <script>
+         function test()
+         {
+            document.getElementById("anch").focus();
+            if (window.layoutTestController) {
+                layoutTestController.dumpAsText();
+                eventSender.keyDown('s');
+            }
+         }
+      </script>
+   </head>
+   <body onload="test()">
+    This tests that focus() works on an empty anchor.<br>
+    <a id="anch" href="#" onkeydown="document.getElementById('console').innerText = 'TEST PASSED'"></a>
+    <br>
+    <pre id="console">TEST FAILED</pre>
+    </body>
+</html>
index b97e43f..1e1886a 100644 (file)
@@ -1,3 +1,16 @@
+2008-03-04  Adele Peterson  <adele@apple.com>
+
+        Reviewed by Beth.
+
+        Fix for <rdar://problem/5779718> focus() does not work for anchor elements with no content
+
+        If an anchor has zero size, don't exclude it from being focusable from JS, just exclude it
+        from being keyboard focusable (using the tab key).
+
+        * html/HTMLAnchorElement.cpp:
+        (WebCore::HTMLAnchorElement::isFocusable):
+        (WebCore::HTMLAnchorElement::isKeyboardFocusable):
+
 2008-03-04  Chris Fleizach  <cfleizach@apple.com>
 
         Reviewed by Darin Adler.
index bd1e2fc..2b5ea79 100644 (file)
@@ -83,6 +83,25 @@ bool HTMLAnchorElement::isFocusable() const
     if (!(m_isLink && renderer() && renderer()->style()->visibility() == VISIBLE))
         return false;
 
+    return true;
+}
+
+bool HTMLAnchorElement::isMouseFocusable() const
+{
+    return false;
+}
+
+bool HTMLAnchorElement::isKeyboardFocusable(KeyboardEvent* event) const
+{
+    if (!isFocusable())
+        return false;
+    
+    if (!document()->frame())
+        return false;
+
+    if (!document()->frame()->eventHandler()->tabsToLinks(event))
+        return false;
+
     // Before calling absoluteRects, check for the common case where the renderer
     // or one of the continuations is non-empty, since this is a faster check and
     // almost always returns true.
@@ -102,22 +121,6 @@ bool HTMLAnchorElement::isFocusable() const
     return false;
 }
 
-bool HTMLAnchorElement::isMouseFocusable() const
-{
-    return false;
-}
-
-bool HTMLAnchorElement::isKeyboardFocusable(KeyboardEvent* event) const
-{
-    if (!isFocusable())
-        return false;
-    
-    if (!document()->frame())
-        return false;
-
-    return document()->frame()->eventHandler()->tabsToLinks(event);
-}
-
 void HTMLAnchorElement::defaultEventHandler(Event* evt)
 {
     // React on clicks and on keypresses.