LayoutTests:
authordarin <darin@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 11 May 2006 17:47:02 +0000 (17:47 +0000)
committerdarin <darin@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 11 May 2006 17:47:02 +0000 (17:47 +0000)
        - test for http://bugzilla.opendarwin.org/show_bug.cgi?id=8743
          REGRESSION: focus() on input field selects all text within it (was: cannot select cities on British Rail reservation site)

        * fast/forms/double-focus-expected.txt: Added.
        * fast/forms/double-focus.html: Added.

WebCore:

        Reviewed by Adele.

        - test for http://bugzilla.opendarwin.org/show_bug.cgi?id=8743
          REGRESSION: focus() on input field selects all text within it
          (was: cannot select cities on British Rail reservation site)

        Test: fast/forms/double-focus.html

        * html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::focus):
        Changed to only call setFocusNode, select, and revealSelection
        if the element is not already focused. Also changed to use return
        a bit more rather than else.

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

LayoutTests/ChangeLog
LayoutTests/fast/forms/double-focus-expected.txt [new file with mode: 0644]
LayoutTests/fast/forms/double-focus.html [new file with mode: 0644]
WebCore/ChangeLog
WebCore/html/HTMLInputElement.cpp

index d7ac846a9227ff9883b80002380a9ba851e63c2a..2d85365db6d40b7b9cc95e832bad4b8b1a7319fa 100644 (file)
@@ -1,3 +1,11 @@
+2006-05-11  Darin Adler  <darin@apple.com>
+
+        - test for http://bugzilla.opendarwin.org/show_bug.cgi?id=8743
+          REGRESSION: focus() on input field selects all text within it (was: cannot select cities on British Rail reservation site)
+
+        * fast/forms/double-focus-expected.txt: Added.
+        * fast/forms/double-focus.html: Added.
+
 2006-05-11  Anders Carlsson  <acarlsson@apple.com>
 
         Reviewed by Darin.
diff --git a/LayoutTests/fast/forms/double-focus-expected.txt b/LayoutTests/fast/forms/double-focus-expected.txt
new file mode 100644 (file)
index 0000000..2ab22dc
--- /dev/null
@@ -0,0 +1,14 @@
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+This test checks if a call to focus on an already-focused element causes a change in selection.
+
+If the test passes for both textarea and text input elements you'll see two messages saying "passed" below.
+
+Passed.
+Passed.
+
+
+
+
+
diff --git a/LayoutTests/fast/forms/double-focus.html b/LayoutTests/fast/forms/double-focus.html
new file mode 100644 (file)
index 0000000..a882cbd
--- /dev/null
@@ -0,0 +1,49 @@
+<html>
+        <script type="text/javascript">
+
+            function print(message)
+            {
+                var paragraph = document.createElement("div");
+                if (message == "")
+                    paragraph.appendChild(document.createElement("br"));
+                else
+                    paragraph.appendChild(document.createTextNode(message));
+                document.getElementById("console").appendChild(paragraph);
+            }
+
+            function test()
+            {
+                if (window.layoutTestController)
+                    layoutTestController.dumpAsText();
+
+                testElement(document.getElementById("textarea"));
+                testElement(document.getElementById("input"));
+            }
+
+            function testElement(element)
+            {
+                element.focus();
+                element.value = "This is a test value.";
+                element.setSelectionRange(3,7);
+                element.focus();
+                if (element.selectionStart == 3)
+                    print("Passed.");
+                else
+                    print("Failed, selection of " + element + " is " + element.selectionStart + "-" + element.selectionEnd + ".");
+                element.blur();
+            }
+
+        </script>
+    </head>
+    <body onload="test();">
+        <p>This test checks if a call to focus on an already-focused element causes a change in selection.</p>
+        <p>If the test passes for both textarea and text input elements you'll see two messages saying "passed" below.</p>
+        <hr>
+        <p id="console"></p>
+        <hr>
+        <form>
+            <p><textarea id="textarea" cols="20"></textarea></p>
+            <p><input type="text" id="input" size="20"></p>
+        </form>
+    </body>
+</html>
\ No newline at end of file
index f974085f6803b36c9606885fda1afa61b9c6463b..79e8a42e4286b30f243928b58a84b6b60f6caf4b 100644 (file)
@@ -1,3 +1,18 @@
+2006-05-11  Darin Adler  <darin@apple.com>
+
+        Reviewed by Adele.
+
+        - test for http://bugzilla.opendarwin.org/show_bug.cgi?id=8743
+          REGRESSION: focus() on input field selects all text within it
+          (was: cannot select cities on British Rail reservation site)
+
+        Test: fast/forms/double-focus.html
+
+        * html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::focus):
+        Changed to only call setFocusNode, select, and revealSelection
+        if the element is not already focused. Also changed to use return
+        a bit more rather than else.
+
 2006-05-11  Darin Adler  <darin@apple.com>
 
         Reviewed by Tim Hatcher (earlier version).
index f2603545d017a581238828dfe9969c0cc0759c5a..0ae202d0b0b790ac17bafeeb3b9453e3d3f395dc 100644 (file)
@@ -169,15 +169,19 @@ void HTMLInputElement::focus()
 {
     if (isNonWidgetTextField()) {
         Document* doc = document();
+        if (doc->focusNode() == this)
+            return;
         doc->updateLayout();
-        if (isFocusable()) {
-            doc->setFocusNode(this);
-            select();
-            if (doc->frame())
-                doc->frame()->revealSelection();
-        }
-    } else
-        HTMLGenericFormElement::focus();
+        // FIXME: Should isFocusable do the updateLayout?
+        if (!isFocusable())
+            return;
+        doc->setFocusNode(this);
+        select();
+        if (doc->frame())
+            doc->frame()->revealSelection();
+        return;
+    }
+    HTMLGenericFormElement::focus();
 }
 
 void HTMLInputElement::dispatchFocusEvent()