LayoutTests:
authormjs <mjs@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 9 Mar 2007 02:12:43 +0000 (02:12 +0000)
committermjs <mjs@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 9 Mar 2007 02:12:43 +0000 (02:12 +0000)
        Reviewed by Adele.

        <rdar://problem/4646563> REGRESSION: Unable to send text message from Verizon text message website: vtext.com (12588)
        http://bugs.webkit.org/show_bug.cgi?id=12588

        Carefully revised which focus operations restore previous selection, which clear it, and which
        select the whole control contents, these test cases cover every focus call I could find.

        * fast/forms/focus-selection-input-expected.txt: Added.
        * fast/forms/focus-selection-input.html: Added.
        * fast/forms/focus-selection-textarea-expected.txt: Added.
        * fast/forms/focus-selection-textarea.html: Added.
        * fast/forms/onselect-textfield-expected.txt:

WebCore:

        Reviewed by Adele.

        <rdar://problem/4646563> REGRESSION: Unable to send text message from Verizon text message website: vtext.com (12588)
        http://bugs.webkit.org/show_bug.cgi?id=12588

        Carefully revised which focus operations restore previous selection, which clear it, and which
        select the whole control contents.

        Tests:
        fast/forms/focus-selection-input.html
        fast/forms/focus-selection-textarea.html

        * dom/Element.cpp:
        (WebCore::Element::focus):
        * dom/Element.h:
        * html/HTMLInputElement.cpp:
        (WebCore::HTMLInputElement::focus):
        (WebCore::HTMLInputElement::accessKeyAction):
        * html/HTMLInputElement.h:
        * html/HTMLLabelElement.cpp:
        (WebCore::HTMLLabelElement::focus):
        (WebCore::HTMLLabelElement::accessKeyAction):
        * html/HTMLLabelElement.h:
        * html/HTMLLegendElement.cpp:
        (WebCore::HTMLLegendElement::focus):
        * html/HTMLLegendElement.h:
        * html/HTMLTextAreaElement.cpp:
        (WebCore::HTMLTextAreaElement::focus):
        * html/HTMLTextAreaElement.h:
        * page/FocusController.cpp:
        (WebCore::FocusController::advanceFocus):

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

18 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/forms/focus-selection-input-expected.txt [new file with mode: 0644]
LayoutTests/fast/forms/focus-selection-input.html [new file with mode: 0644]
LayoutTests/fast/forms/focus-selection-textarea-expected.txt [new file with mode: 0644]
LayoutTests/fast/forms/focus-selection-textarea.html [new file with mode: 0644]
LayoutTests/fast/forms/onselect-textfield-expected.txt
WebCore/ChangeLog
WebCore/dom/Element.cpp
WebCore/dom/Element.h
WebCore/html/HTMLInputElement.cpp
WebCore/html/HTMLInputElement.h
WebCore/html/HTMLLabelElement.cpp
WebCore/html/HTMLLabelElement.h
WebCore/html/HTMLLegendElement.cpp
WebCore/html/HTMLLegendElement.h
WebCore/html/HTMLTextAreaElement.cpp
WebCore/html/HTMLTextAreaElement.h
WebCore/page/FocusController.cpp

index 7b58ee4e9143f668d18f68511117ffc5a78c40a9..fcd5bbaca132be9eafbac8f3a65ed0db1a4a87a8 100644 (file)
@@ -1,3 +1,19 @@
+2007-03-08  Maciej Stachowiak  <mjs@apple.com>
+
+        Reviewed by Adele.
+
+        <rdar://problem/4646563> REGRESSION: Unable to send text message from Verizon text message website: vtext.com (12588)
+        http://bugs.webkit.org/show_bug.cgi?id=12588
+
+        Carefully revised which focus operations restore previous selection, which clear it, and which
+        select the whole control contents, these test cases cover every focus call I could find.
+        
+        * fast/forms/focus-selection-input-expected.txt: Added.
+        * fast/forms/focus-selection-input.html: Added.
+        * fast/forms/focus-selection-textarea-expected.txt: Added.
+        * fast/forms/focus-selection-textarea.html: Added.
+        * fast/forms/onselect-textfield-expected.txt:
+
 2007-03-08  Justin Garcia  <justin.garcia@apple.com>
 
         Reviewed by harrison
diff --git a/LayoutTests/fast/forms/focus-selection-input-expected.txt b/LayoutTests/fast/forms/focus-selection-input-expected.txt
new file mode 100644 (file)
index 0000000..5cb831b
--- /dev/null
@@ -0,0 +1,80 @@
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidBeginEditing:WebViewDidBeginEditingNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidBeginEditing:WebViewDidBeginEditingNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidBeginEditing:WebViewDidBeginEditingNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: shouldChangeSelectedDOMRange:(null) toDOMRange:range from 0 of #text > DIV to 0 of #text > DIV affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: shouldChangeSelectedDOMRange:(null) toDOMRange:range from 0 of #text > LABEL > BODY > HTML > #document to 5 of #text > LABEL > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidBeginEditing:WebViewDidBeginEditingNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidBeginEditing:WebViewDidBeginEditingNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidBeginEditing:WebViewDidBeginEditingNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidBeginEditing:WebViewDidBeginEditingNotification
+<input type="text"> focus selection
+
+This test checks whether the selection is restored, cleared, or set to the full range when using different ways to focus a text field. These results all match Mozilla, except test 6, which selects the whole field contents to match all other cases of keyboard focus. When running manually, please follow the steps below. In the test harness, the test runs automatically.
+
+1) Hit tab, the whole phrase "SUCCESS and SUCCESS" should be selected:  
+2) Hit Ctrl-J, the whole phrase "SUCCESS and SUCCESS" should be selected:  
+3) , only the word "SUCCESS" should be selected:  
+4) Click in the input field, nothing should be selected:  
+5) Click this label, only the word "SUCCESS" should be selected:  
+6) Hit Ctrl-U, the whole phrase "SUCCESS and SUCCESS" should be selected:  
+7) , only the word "SUCCESS" should be selected:  
+8)  , the whole phrase "SUCCESS and SUCCESS" should be selected:
+
+
+9) Hit Ctrl-I, the whole phrase "SUCCESS and SUCCESS" should be selected:
+
+
+PASS first.selectionStart is 12
+PASS first.selectionEnd is 19
+PASS first.selectionStart is 0
+PASS first.selectionEnd is 19
+PASS second.selectionStart is 11
+PASS second.selectionEnd is 18
+PASS second.selectionStart is 11
+PASS second.selectionEnd is 18
+PASS third.selectionStart is 11
+PASS third.selectionEnd is 18
+PASS third.selectionStart is 11
+PASS third.selectionEnd is 18
+PASS fourth.selectionStart is 12
+PASS fourth.selectionEnd is 19
+PASS fourth.selectionStart is 0
+PASS fourth.selectionEnd is 0
+PASS fifth.selectionStart is 11
+PASS fifth.selectionEnd is 18
+PASS fifth.selectionStart is 11
+PASS fifth.selectionEnd is 18
+PASS sixth.selectionStart is 12
+PASS sixth.selectionEnd is 19
+PASS sixth.selectionStart is 0
+PASS sixth.selectionEnd is 19
+PASS seventh.selectionStart is 11
+PASS seventh.selectionEnd is 18
+PASS seventh.selectionStart is 11
+PASS seventh.selectionEnd is 18
+PASS eighth.selectionStart is 12
+PASS eighth.selectionEnd is 19
+PASS eighth.selectionStart is 0
+PASS eighth.selectionEnd is 19
+PASS ninth.selectionStart is 12
+PASS ninth.selectionEnd is 19
+PASS ninth.selectionStart is 0
+PASS ninth.selectionEnd is 19
+
diff --git a/LayoutTests/fast/forms/focus-selection-input.html b/LayoutTests/fast/forms/focus-selection-input.html
new file mode 100644 (file)
index 0000000..0272864
--- /dev/null
@@ -0,0 +1,193 @@
+<head>
+<link href="js-test-style.css">
+</head>
+<body onload="runTest()">
+<script src="../js/resources/js-test-pre.js"></script>
+
+<script>
+function runTest()
+{
+    if (!window.layoutTestController)
+        return;
+
+    layoutTestController.dumpEditingCallbacks();
+    layoutTestController.dumpAsText();
+
+    shouldBe("first.selectionStart", "12");
+    shouldBe("first.selectionEnd", "19");
+    eventSender.keyDown("\t");
+    shouldBe("first.selectionStart", "0");
+    shouldBe("first.selectionEnd", "19");
+
+    shouldBe("second.selectionStart", "11");
+    shouldBe("second.selectionEnd", "18");
+    eventSender.keyDown("J", ["ctrlKey"]);
+    shouldBe("second.selectionStart", "11");
+    shouldBe("second.selectionEnd", "18");
+
+    shouldBe("third.selectionStart", "11");
+    shouldBe("third.selectionEnd", "18");
+    third.focus();
+    shouldBe("third.selectionStart", "11");
+    shouldBe("third.selectionEnd", "18");
+
+    shouldBe("fourth.selectionStart", "12");
+    shouldBe("fourth.selectionEnd", "19");
+    eventSender.mouseMoveTo(fourth.offsetLeft + 4, fourth.offsetTop + 4);
+    eventSender.mouseClick();
+    shouldBe("fourth.selectionStart", "0");
+    shouldBe("fourth.selectionEnd", "0");
+
+    shouldBe("fifth.selectionStart", "11");
+    shouldBe("fifth.selectionEnd", "18");
+    var fifthLabel = document.getElementById("fifthLabel");
+    eventSender.mouseMoveTo(fifthLabel.offsetLeft + 4, fifthLabel.offsetTop + 4);
+    eventSender.mouseClick();
+    shouldBe("fifth.selectionStart", "11");
+    shouldBe("fifth.selectionEnd", "18");
+
+    shouldBe("sixth.selectionStart", "12");
+    shouldBe("sixth.selectionEnd", "19");
+    eventSender.keyDown("U", ["ctrlKey"]);
+    shouldBe("sixth.selectionStart", "0");
+    shouldBe("sixth.selectionEnd", "19");
+
+    shouldBe("seventh.selectionStart", "11");
+    shouldBe("seventh.selectionEnd", "18");
+    var seventLabel = document.getElementById("seventhLabel");
+    seventhLabel.focus();
+    shouldBe("seventh.selectionStart", "11");
+    shouldBe("seventh.selectionEnd", "18");
+
+    shouldBe("eighth.selectionStart", "12");
+    shouldBe("eighth.selectionEnd", "19");
+    var eighthLegend = document.getElementById("eighthLegend");
+    eighthLegend.focus();
+    shouldBe("eighth.selectionStart", "0");
+    shouldBe("eighth.selectionEnd", "19");
+
+    shouldBe("ninth.selectionStart", "12");
+    shouldBe("ninth.selectionEnd", "19");
+    eventSender.keyDown("I", ["ctrlKey"]);
+    shouldBe("ninth.selectionStart", "0");
+    shouldBe("ninth.selectionEnd", "19");
+
+}
+</script>
+
+<h2>&lt;input type="text"&gt; focus selection</h2>
+
+<p>This test checks whether the selection is restored, cleared, or set
+to the full range when using different ways to focus a text field. These
+results all match Mozilla, except test 6, which selects
+the whole field contents to match all other cases of keyboard
+focus. When running manually, please follow the steps below. In the
+test harness, the test runs automatically.</p>
+
+1) Hit tab, the whole phrase "SUCCESS and SUCCESS" should be selected:
+<input type="text" id="first" value="SUCCESS and SUCCESS">
+<script>
+    var first = document.getElementById("first");
+    first.focus();
+    first.setSelectionRange(12, 19);
+    first.blur();
+</script>
+
+<br>
+
+2) Hit Ctrl-J, the whole phrase "SUCCESS and SUCCESS" should be selected:
+<input type="text" id="second" accesskey="j" value="SUCCESS and SUCCESS">
+<script>
+    var second = document.getElementById("second");
+    second.focus();
+    second.setSelectionRange(12, 19);
+    second.blur();
+</script>
+
+<br>
+
+3) <input type="button" onclick="document.getElementById('third').focus()" value="Click this button">, only the word "SUCCESS" should be selected:
+<input type="text" id="third" value="FAILURE or SUCCESS">
+<script>
+    var third = document.getElementById("third");
+    third.focus();
+    third.setSelectionRange(11, 18);
+    third.blur();
+</script>
+
+<br>
+
+4) Click in the input field, nothing should be selected:
+<input type="text" id="fourth" value="FAILURE and FAILURE">
+<script>
+    var fourth = document.getElementById("fourth");
+    fourth.focus();
+    fourth.setSelectionRange(12, 19);
+    fourth.blur();
+</script>
+
+<br>
+
+5) <label id="fifthLabel" for="fifth" style="color: blue">Click this label, only the word "SUCCESS" should be selected:</label>
+<input type="text" id="fifth" value="FAILURE or SUCCESS">
+<script>
+    var second = document.getElementById("fifth");
+    fifth.focus();
+    fifth.setSelectionRange(11, 18);
+    fifth.blur();
+</script>
+
+<br>
+
+6) <label id="sixthLabel" for="sixth" accesskey="u">Hit Ctrl-U, the whole phrase "SUCCESS and SUCCESS" should be selected:</label>
+<input type="text" id="sixth" value="SUCCESS and SUCCESS">
+<script>
+    var sixth = document.getElementById("sixth");
+    sixth.focus();
+    sixth.setSelectionRange(12, 19);
+    sixth.blur();
+</script>
+
+<br>
+
+7) <input type="button" onclick="document.getElementById('seventhLabel').focus()" value="Click this button"><label id="seventhLabel" for="seventh">, only the word "SUCCESS" should be selected:</label>
+<input type="text" id="seventh" value="FAILURE or SUCCESS">
+<script>
+    var seventh = document.getElementById("seventh");
+    seventh.focus();
+    seventh.setSelectionRange(11, 18);
+    seventh.blur();
+</script>
+
+<br>
+
+8) <input type="button" onclick="document.getElementById('eighthLegend').focus()" value="Click this button">
+<fieldset>
+<legend id="eighthLegend">, the whole phrase "SUCCESS and SUCCESS" should be selected:</legend>
+<input type="text" id="eighth" value="SUCCESS and SUCCESS">
+<script>
+    var eighth = document.getElementById("eighth");
+    eighth.focus();
+    eighth.setSelectionRange(12, 19);
+    eighth.blur();
+</script>
+</fieldset>
+<br>
+
+
+9) <fieldset>
+<legend id="eighthLegend" accesskey="i">Hit Ctrl-I, the whole phrase "SUCCESS and SUCCESS" should be selected:</legend>
+<input type="text" id="ninth" value="SUCCESS and SUCCESS">
+<script>
+    var ninth = document.getElementById("ninth");
+    ninth.focus();
+    ninth.setSelectionRange(12, 19);
+    ninth.blur();
+</script>
+</fieldset>
+<br>
+
+<p id="description"></p>
+<div id="console"></div>
+
+</body>
diff --git a/LayoutTests/fast/forms/focus-selection-textarea-expected.txt b/LayoutTests/fast/forms/focus-selection-textarea-expected.txt
new file mode 100644 (file)
index 0000000..fa4d9eb
--- /dev/null
@@ -0,0 +1,73 @@
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: shouldChangeSelectedDOMRange:(null) toDOMRange:range from 0 of #text > DIV to 0 of #text > DIV affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: shouldChangeSelectedDOMRange:(null) toDOMRange:range from 0 of #text > LABEL > BODY > HTML > #document to 5 of #text > LABEL > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+<textarea> focus selection
+
+This test checks whether the selection is restored, cleared, or set to the full range when using different ways to focus a text area. These results all match Mozilla. When running manually, please follow the steps below. In the test harness, the test runs automatically.
+
+1) Hit tab, only the word "SUCCESS" should be selected:  
+2) Hit Ctrl-J, only the word "SUCCESS" should be selected:  
+3) , only the word "SUCCESS" should be selected:  
+4) Click in the input field, nothing should be selected:  
+5) Click this label, only the word "SUCCESS" should be selected:  
+6) Hit Ctrl-U, only the word "SUCCESS" should be selected:  
+7) , only the word "SUCCESS" should be selected:  
+8)  , only the word "SUCCESS" should be selected:
+
+
+9) Hit Ctrl-I, only the word "SUCCESS" should be selected:
+
+
+PASS first.selectionStart is 11
+PASS first.selectionEnd is 18
+PASS first.selectionStart is 11
+PASS first.selectionEnd is 18
+PASS second.selectionStart is 11
+PASS second.selectionEnd is 18
+PASS second.selectionStart is 11
+PASS second.selectionEnd is 18
+PASS third.selectionStart is 11
+PASS third.selectionEnd is 18
+PASS third.selectionStart is 11
+PASS third.selectionEnd is 18
+PASS fourth.selectionStart is 11
+PASS fourth.selectionEnd is 18
+PASS fourth.selectionStart is 0
+PASS fourth.selectionEnd is 0
+PASS fifth.selectionStart is 11
+PASS fifth.selectionEnd is 18
+PASS fifth.selectionStart is 11
+PASS fifth.selectionEnd is 18
+PASS sixth.selectionStart is 11
+PASS sixth.selectionEnd is 18
+PASS sixth.selectionStart is 11
+PASS sixth.selectionEnd is 18
+PASS seventh.selectionStart is 11
+PASS seventh.selectionEnd is 18
+PASS seventh.selectionStart is 11
+PASS seventh.selectionEnd is 18
+PASS eighth.selectionStart is 11
+PASS eighth.selectionEnd is 18
+PASS eighth.selectionStart is 11
+PASS eighth.selectionEnd is 18
+PASS ninth.selectionStart is 11
+PASS ninth.selectionEnd is 18
+PASS ninth.selectionStart is 11
+PASS ninth.selectionEnd is 18
+
diff --git a/LayoutTests/fast/forms/focus-selection-textarea.html b/LayoutTests/fast/forms/focus-selection-textarea.html
new file mode 100644 (file)
index 0000000..cf2beb0
--- /dev/null
@@ -0,0 +1,192 @@
+<head>
+<link href="js-test-style.css">
+</head>
+<body onload="runTest()">
+<script src="../js/resources/js-test-pre.js"></script>
+
+<script>
+function runTest()
+{
+    if (!window.layoutTestController)
+        return;
+
+    layoutTestController.dumpEditingCallbacks();
+    layoutTestController.dumpAsText();
+
+    shouldBe("first.selectionStart", "11");
+    shouldBe("first.selectionEnd", "18");
+    eventSender.keyDown("\t");
+    shouldBe("first.selectionStart", "11");
+    shouldBe("first.selectionEnd", "18");
+
+    shouldBe("second.selectionStart", "11");
+    shouldBe("second.selectionEnd", "18");
+    eventSender.keyDown("J", ["ctrlKey"]);
+    shouldBe("second.selectionStart", "11");
+    shouldBe("second.selectionEnd", "18");
+
+    shouldBe("third.selectionStart", "11");
+    shouldBe("third.selectionEnd", "18");
+    third.focus();
+    shouldBe("third.selectionStart", "11");
+    shouldBe("third.selectionEnd", "18");
+
+    shouldBe("fourth.selectionStart", "11");
+    shouldBe("fourth.selectionEnd", "18");
+    eventSender.mouseMoveTo(fourth.offsetLeft + 4, fourth.offsetTop + 4);
+    eventSender.mouseClick();
+    shouldBe("fourth.selectionStart", "0");
+    shouldBe("fourth.selectionEnd", "0");
+
+    shouldBe("fifth.selectionStart", "11");
+    shouldBe("fifth.selectionEnd", "18");
+    var fifthLabel = document.getElementById("fifthLabel");
+    eventSender.mouseMoveTo(fifthLabel.offsetLeft + 4, fifthLabel.offsetTop + 4);
+    eventSender.mouseClick();
+    shouldBe("fifth.selectionStart", "11");
+    shouldBe("fifth.selectionEnd", "18");
+
+    shouldBe("sixth.selectionStart", "11");
+    shouldBe("sixth.selectionEnd", "18");
+    eventSender.keyDown("U", ["ctrlKey"]);
+    shouldBe("sixth.selectionStart", "11");
+    shouldBe("sixth.selectionEnd", "18");
+
+    shouldBe("seventh.selectionStart", "11");
+    shouldBe("seventh.selectionEnd", "18");
+    var seventLabel = document.getElementById("seventhLabel");
+    seventhLabel.focus();
+    shouldBe("seventh.selectionStart", "11");
+    shouldBe("seventh.selectionEnd", "18");
+
+    shouldBe("eighth.selectionStart", "11");
+    shouldBe("eighth.selectionEnd", "18");
+    var eighthLegend = document.getElementById("eighthLegend");
+    eighthLegend.focus();
+    shouldBe("eighth.selectionStart", "11");
+    shouldBe("eighth.selectionEnd", "18");
+
+    shouldBe("ninth.selectionStart", "11");
+    shouldBe("ninth.selectionEnd", "18");
+    eventSender.keyDown("I", ["ctrlKey"]);
+    shouldBe("ninth.selectionStart", "11");
+    shouldBe("ninth.selectionEnd", "18");
+
+}
+</script>
+
+<h2>&lt;textarea&gt; focus selection</h2>
+
+<p>This test checks whether the selection is restored, cleared, or set
+to the full range when using different ways to focus a text
+area. These results all match Mozilla. When running manually, please
+follow the steps below. In the test harness, the test runs
+automatically.</p>
+
+1) Hit tab, only the word "SUCCESS" should be selected:
+<textarea id="first">FAILURE or SUCCESS</textarea>
+<script>
+    var first = document.getElementById("first");
+    first.focus();
+    first.setSelectionRange(11, 18);
+    first.blur();
+</script>
+
+<br>
+
+2) Hit Ctrl-J, only the word "SUCCESS" should be selected:
+<textarea id="second" accesskey="j">FAILURE or SUCCESS</textarea>
+<script>
+    var second = document.getElementById("second");
+    second.focus();
+    second.setSelectionRange(11, 18);
+    second.blur();
+</script>
+
+<br>
+
+3) <input type="button" onclick="document.getElementById('third').focus()" value="Click this button">, only the word "SUCCESS" should be selected:
+<textarea id="third">FAILURE or SUCCESS</textarea>
+<script>
+    var third = document.getElementById("third");
+    third.focus();
+    third.setSelectionRange(11, 18);
+    third.blur();
+</script>
+
+<br>
+
+4) Click in the input field, nothing should be selected:
+<textarea id="fourth">FAILURE and FAILURE</textarea>
+<script>
+    var fourth = document.getElementById("fourth");
+    fourth.focus();
+    fourth.setSelectionRange(11, 18);
+    fourth.blur();
+</script>
+
+<br>
+
+5) <label id="fifthLabel" for="fifth" style="color: blue">Click this label, only the word "SUCCESS" should be selected:</label>
+<textarea id="fifth">FAILURE or SUCCESS</textarea>
+<script>
+    var second = document.getElementById("fifth");
+    fifth.focus();
+    fifth.setSelectionRange(11, 18);
+    fifth.blur();
+</script>
+
+<br>
+
+6) <label id="sixthLabel" for="sixth" accesskey="u">Hit Ctrl-U, only the word "SUCCESS" should be selected:</label>
+<textarea id="sixth">FAILURE or SUCCESS</textarea>
+<script>
+    var sixth = document.getElementById("sixth");
+    sixth.focus();
+    sixth.setSelectionRange(11, 18);
+    sixth.blur();
+</script>
+
+<br>
+
+7) <input type="button" onclick="document.getElementById('seventhLabel').focus()" value="Click this button"><label id="seventhLabel" for="seventh">, only the word "SUCCESS" should be selected:</label>
+<textarea id="seventh">FAILURE or SUCCESS</textarea>
+<script>
+    var seventh = document.getElementById("seventh");
+    seventh.focus();
+    seventh.setSelectionRange(11, 18);
+    seventh.blur();
+</script>
+
+<br>
+
+8) <input type="button" onclick="document.getElementById('eighthLegend').focus()" value="Click this button">
+<fieldset>
+<legend id="eighthLegend">, only the word "SUCCESS" should be selected:</legend>
+<textarea id="eighth">FAILURE or SUCCESS</textarea>
+<script>
+    var eighth = document.getElementById("eighth");
+    eighth.focus();
+    eighth.setSelectionRange(11, 18);
+    eighth.blur();
+</script>
+</fieldset>
+<br>
+
+
+9) <fieldset>
+<legend id="eighthLegend" accesskey="i">Hit Ctrl-I, only the word "SUCCESS" should be selected:</legend>
+<textarea id="ninth">FAILURE or SUCCESS</textarea>
+<script>
+    var ninth = document.getElementById("ninth");
+    ninth.focus();
+    ninth.setSelectionRange(11, 18);
+    ninth.blur();
+</script>
+</fieldset>
+<br>
+
+<p id="description"></p>
+<div id="console"></div>
+
+</body>
\ No newline at end of file
index a3dfc91fa98586c13553f03b4fee5d70779536a0..13103db33bd307303a64f23b3efe5ed145005fcd 100644 (file)
@@ -16,5 +16,5 @@ Calling blur on text field
 After blur: text field selection start: 6 end: 10
 
 Calling focus on text field
-After focus: text field selection start: 0 end: 10
+After focus: text field selection start: 6 end: 10
 
index 5accaa2ab78984c5701cd91c6b3349995bd8b1d0..0934a1715a5a28536db52386f8a19350f23eb0a4 100644 (file)
@@ -1,3 +1,37 @@
+2007-03-08  Maciej Stachowiak  <mjs@apple.com>
+
+        Reviewed by Adele.
+        
+        <rdar://problem/4646563> REGRESSION: Unable to send text message from Verizon text message website: vtext.com (12588)
+        http://bugs.webkit.org/show_bug.cgi?id=12588
+
+        Carefully revised which focus operations restore previous selection, which clear it, and which
+        select the whole control contents.
+        
+        Tests:
+        fast/forms/focus-selection-input.html
+        fast/forms/focus-selection-textarea.html
+        
+        * dom/Element.cpp:
+        (WebCore::Element::focus):
+        * dom/Element.h:
+        * html/HTMLInputElement.cpp:
+        (WebCore::HTMLInputElement::focus):
+        (WebCore::HTMLInputElement::accessKeyAction):
+        * html/HTMLInputElement.h:
+        * html/HTMLLabelElement.cpp:
+        (WebCore::HTMLLabelElement::focus):
+        (WebCore::HTMLLabelElement::accessKeyAction):
+        * html/HTMLLabelElement.h:
+        * html/HTMLLegendElement.cpp:
+        (WebCore::HTMLLegendElement::focus):
+        * html/HTMLLegendElement.h:
+        * html/HTMLTextAreaElement.cpp:
+        (WebCore::HTMLTextAreaElement::focus):
+        * html/HTMLTextAreaElement.h:
+        * page/FocusController.cpp:
+        (WebCore::FocusController::advanceFocus):
+
 2007-03-08  Justin Garcia  <justin.garcia@apple.com>
 
         Reviewed by harrison
index b1b32a5228b7daa8735c91b75bd21f5fed4f5bb7..fa0ea819ae65703a49c2b9216690e9c6076f42e5 100644 (file)
@@ -889,7 +889,7 @@ CSSStyleDeclaration *Element::style()
     return 0;
 }
 
-void Element::focus()
+void Element::focus(bool restorePreviousSelection)
 {
     Document* doc = document();
     doc->updateLayout();
@@ -905,7 +905,7 @@ void Element::focus()
         return;
     }
         
-    updateFocusAppearance();
+    updateFocusAppearance(restorePreviousSelection);
 }
 
 void Element::updateFocusAppearance(bool restorePreviousSelection)
index 01a3edd337c40213108b9d666e305d109b2567dd..ea8092606ad244114ac16595da855cd584fe2400 100644 (file)
@@ -158,7 +158,7 @@ public:
     virtual bool isURLAttribute(Attribute *attr) const;
     virtual String target() const { return String(); }
         
-    virtual void focus();
+    virtual void focus(bool restorePreviousSelection = true);
     virtual void updateFocusAppearance(bool restorePreviousSelection = false);
     void blur();
     bool needsFocusAppearanceUpdate() const { return m_needsFocusAppearanceUpdate; }
index e2bcb9aacf84c988cf9db70303e792aeb59ee8c4..fb949fea39f6034db796d354887b801d472cc09c 100644 (file)
@@ -182,7 +182,7 @@ bool HTMLInputElement::isMouseFocusable() const
     return HTMLGenericFormElement::isMouseFocusable();
 }
 
-void HTMLInputElement::focus()
+void HTMLInputElement::focus(bool restorePreviousSelection)
 {
     if (isTextField()) {
         Document* doc = document();
@@ -198,10 +198,10 @@ void HTMLInputElement::focus()
             setNeedsFocusAppearanceUpdate(true);
             return;
         }
-        updateFocusAppearance();
+        updateFocusAppearance(restorePreviousSelection);
         return;
     }
-    HTMLGenericFormElement::focus();
+    HTMLGenericFormElement::focus(restorePreviousSelection);
 }
 
 void HTMLInputElement::updateFocusAppearance(bool restorePreviousSelection)
@@ -534,8 +534,7 @@ void HTMLInputElement::accessKeyAction(bool sendToAnyElement)
         case RANGE:
         case RESET:
         case SUBMIT:
-            // focus
-            focus();
+            focus(false);
             // send the mouse button events iff the caller specified sendToAnyElement
             dispatchSimulatedClick(0, sendToAnyElement);
             break;
@@ -546,7 +545,8 @@ void HTMLInputElement::accessKeyAction(bool sendToAnyElement)
         case PASSWORD:
         case SEARCH:
         case TEXT:
-            focus();
+            // should never restore previous selection here
+            focus(false);
             break;
     }
 }
index 9f4449cf5ac1333f5cf5dae887c4d072dca2ab75..9170fd1791bf1ee832e5d7072503a7cbaa3ac9b6 100644 (file)
@@ -61,7 +61,7 @@ public:
     virtual bool isKeyboardFocusable(KeyboardEvent*) const;
     virtual bool isMouseFocusable() const;
     virtual bool isEnumeratable() const { return inputType() != IMAGE; }
-    virtual void focus();
+    virtual void focus(bool restorePreviousSelection = true);
     virtual void dispatchFocusEvent();
     virtual void dispatchBlurEvent();
     virtual void updateFocusAppearance(bool restorePreviousSelection = false);
index aa1f4f14b7630f6aec85a1308ded6f2de2903dc1..34a220597800d2603f07819fc563de205e88e0d9 100644 (file)
 
 #include "config.h"
 #include "HTMLLabelElement.h"
-#include "HTMLFormElement.h"
 
-#include "HTMLNames.h"
-#include "EventNames.h"
-#include "Event.h"
 #include "Document.h"
+#include "Event.h"
+#include "EventNames.h"
+#include "HTMLFormElement.h"
+#include "HTMLNames.h"
 
 namespace WebCore {
 
@@ -130,16 +130,16 @@ void HTMLLabelElement::defaultEventHandler(Event* evt)
     HTMLElement::defaultEventHandler(evt);
 }
 
-void HTMLLabelElement::focus()
+void HTMLLabelElement::focus(bool)
 {
+    // to match other browsers, always restore previous selection
     if (Element* element = formElement())
         element->focus();
 }
 
 void HTMLLabelElement::accessKeyAction(bool sendToAnyElement)
 {
-    Element *element = formElement();
-    if (element)
+    if (Element* element = formElement())
         element->accessKeyAction(sendToAnyElement);
 }
 
index 05c62ba1bb9716832fe34c8f7249b2a640f470e3..35d7b3a8f5f9189fd7d46ef25d21df3f302952d1 100644 (file)
@@ -64,7 +64,7 @@ public:
     String htmlFor() const;
     void setHtmlFor(const String &);
 
-    void focus();
+    void focus(bool restorePreviousSelection = true);
 
  private:
     String m_formElementID;
index bffd3beb2172d4f4e482c6538bd312f3cda6a2d6..285b4af20748642909f71545253a897e070d8117 100644 (file)
@@ -105,10 +105,11 @@ Element *HTMLLegendElement::formElement()
     return 0;
 }
 
-void HTMLLegendElement::focus()
+void HTMLLegendElement::focus(bool)
 {
+    // to match other browsers, never restore previous selection
     if (Element *element = formElement())
-        element->focus();
+        element->focus(false);
 }
 
 void HTMLLegendElement::accessKeyAction(bool sendToAnyElement)
index b6b44891f3d69be702659b76d2e18e44541ec582..06b7a11d762fb74668cdf55fcf413a0f2f05a356 100644 (file)
@@ -51,7 +51,7 @@ public:
     String align() const;
     void setAlign(const String &);
     
-    void focus();
+    void focus(bool restorePreviousSelection = true);
 };
 
 } //namespace
index 49fa14b165ea9c3239b0ea9ae8d8517152f64147..b1a5741d9aaa8ac14f13238eed0f59adebd1de01 100644 (file)
@@ -200,7 +200,7 @@ bool HTMLTextAreaElement::isMouseFocusable() const
     return HTMLGenericFormElement::isFocusable();
 }
 
-void HTMLTextAreaElement::focus()
+void HTMLTextAreaElement::focus(bool)
 {
     Document* doc = document();
     if (doc->focusedNode() == this)
index 930df248867c748646f7dd7e194acc7098c082d7..30c71977696a407e13ca9143ab27eb3ebbcb398c 100644 (file)
@@ -72,7 +72,7 @@ public:
     virtual void defaultEventHandler(Event*);
     virtual bool isMouseFocusable() const;
     virtual bool isKeyboardFocusable(KeyboardEvent*) const;
-    virtual void focus();
+    virtual void focus(bool restorePreviousSelection = true);
     virtual void updateFocusAppearance(bool restorePreviousSelection = true);
 
     String value() const;
index bd1f8a270c0cbe06dccef5b3f3ac62e8b757a620..4924ae35dbe7f061d329f4286d5b12b7700f2624 100644 (file)
@@ -203,7 +203,7 @@ bool FocusController::advanceFocus(FocusDirection direction, KeyboardEvent* even
     if (newDocument)
         setFocusedFrame(newDocument->frame());
 
-    static_cast<Element*>(node)->focus();
+    static_cast<Element*>(node)->focus(false);
     return true;
 }