LayoutTests:
authorggaren <ggaren@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 8 Dec 2006 07:05:53 +0000 (07:05 +0000)
committerggaren <ggaren@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 8 Dec 2006 07:05:53 +0000 (07:05 +0000)
        Reviewed by Beth Dakin.

        Tests for the change and blur events in input elements.

        * fast/events/onchange-passwordfield-expected.txt: Added.
        * fast/events/onchange-passwordfield.html: Added.
        * fast/events/onchange-searchfield-expected.txt: Added.
        * fast/events/onchange-searchfield.html: Added.
        * fast/events/onchange-textfield-expected.txt: Added.
        * fast/events/onchange-textfield.html: Added.

WebCore:

        Reviewed by Beth Dakin.

        Fixed <rdar://problem/4870551> 9A320: <input type="text"> no longer
        dispatches onchange event in response to enter key

        To match our old behavior and FF, we need to dispatch onchange in response to the
        ENTER key. The strategy here is just to dispatch a blur event, since that's how
        the search field always worked, and the DOM spec says onchange only fires
        as a precursor to blur.

        * ChangeLog:
        * html/HTMLInputElement.cpp:
        (WebCore::HTMLInputElement::defaultEventHandler):

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

LayoutTests/ChangeLog
LayoutTests/fast/events/onchange-passwordfield-expected.txt [new file with mode: 0644]
LayoutTests/fast/events/onchange-passwordfield.html [new file with mode: 0644]
LayoutTests/fast/events/onchange-searchfield-expected.txt [new file with mode: 0644]
LayoutTests/fast/events/onchange-searchfield.html [new file with mode: 0644]
LayoutTests/fast/events/onchange-textfield-expected.txt [new file with mode: 0644]
LayoutTests/fast/events/onchange-textfield.html [new file with mode: 0644]
WebCore/ChangeLog
WebCore/html/HTMLInputElement.cpp

index 8bd9730d5e3c202d7e8989969e6bf1e097098ee8..3e965145e7e43fac80a241b1b2778787bac54d76 100644 (file)
@@ -1,3 +1,16 @@
+2006-12-07  Geoffrey Garen  <ggaren@apple.com>
+
+        Reviewed by Beth Dakin.
+        
+        Tests for the change and blur events in input elements.
+
+        * fast/events/onchange-passwordfield-expected.txt: Added.
+        * fast/events/onchange-passwordfield.html: Added.
+        * fast/events/onchange-searchfield-expected.txt: Added.
+        * fast/events/onchange-searchfield.html: Added.
+        * fast/events/onchange-textfield-expected.txt: Added.
+        * fast/events/onchange-textfield.html: Added.
+
 2006-12-07  Anders Carlsson  <acarlsson@apple.com>
 
         Reviewed by Darin.
 2006-12-07  Anders Carlsson  <acarlsson@apple.com>
 
         Reviewed by Darin.
diff --git a/LayoutTests/fast/events/onchange-passwordfield-expected.txt b/LayoutTests/fast/events/onchange-passwordfield-expected.txt
new file mode 100644 (file)
index 0000000..2ecee15
--- /dev/null
@@ -0,0 +1,10 @@
+This test verifies that the ENTER key fires the change and then the blur event.
+
+
+PASS: change event fired.
+
+PASS: blur event fired.
+
+PASS: blur event fired last.
+
+
diff --git a/LayoutTests/fast/events/onchange-passwordfield.html b/LayoutTests/fast/events/onchange-passwordfield.html
new file mode 100644 (file)
index 0000000..aa2de1c
--- /dev/null
@@ -0,0 +1,39 @@
+<p>This test verifies that the ENTER key fires the change and then the blur event.</p>
+<hr>
+<input id="input" type="password" onchange="changeHandler()" onblur="blurHandler()"></input>
+<pre id="console"></pre>
+
+<script>
+function log(s)
+{
+    document.getElementById('console').appendChild(document.createTextNode(s + "\n"));
+}
+
+function changeHandler()
+{
+    lastEvent = "change";
+    log ('PASS: change event fired.\n');
+}
+
+function blurHandler()
+{
+    lastEvent = "blur";
+    log ('PASS: blur event fired.\n');
+}
+
+if (window.layoutTestController)
+    layoutTestController.dumpAsText();
+
+// change the field
+document.getElementById('input').focus();
+document.execCommand("InsertText", false, "foo bar baz");
+
+// hit enter
+var enterEvent = document.createEvent("KeyboardEvents");
+enterEvent.initKeyboardEvent("keypress", true, false, window, "Enter", 0, false, false, false, false, false); // This is not at all like pulling teeth
+input.dispatchEvent(enterEvent);
+
+// test that blur happened last
+if (lastEvent == "blur")
+    log('PASS: blur event fired last.\n');
+</script>
diff --git a/LayoutTests/fast/events/onchange-searchfield-expected.txt b/LayoutTests/fast/events/onchange-searchfield-expected.txt
new file mode 100644 (file)
index 0000000..6a94c79
--- /dev/null
@@ -0,0 +1,8 @@
+This test verifies that the ENTER key fires the change and then the blur event.
+
+
+PASS: blur event fired.
+
+PASS: blur event fired last.
+
+
diff --git a/LayoutTests/fast/events/onchange-searchfield.html b/LayoutTests/fast/events/onchange-searchfield.html
new file mode 100644 (file)
index 0000000..07d4bdf
--- /dev/null
@@ -0,0 +1,39 @@
+<p>This test verifies that the ENTER key fires the change and then the blur event.</p>
+<hr>
+<input id="input" type="search" onchange="changeHandler()" onblur="blurHandler()"></input>
+<pre id="console"></pre>
+
+<script>
+function log(s)
+{
+    document.getElementById('console').appendChild(document.createTextNode(s + "\n"));
+}
+
+function changeHandler()
+{
+    window.lastEvent = "change";
+    log ('PASS: change event fired.\n');
+}
+
+function blurHandler()
+{
+    window.lastEvent = "blur";
+    log ('PASS: blur event fired.\n');
+}
+
+if (window.layoutTestController)
+    layoutTestController.dumpAsText();
+
+// change the field
+document.getElementById('input').focus();
+document.execCommand("InsertText", false, "foo bar baz"); // Won't work until searchfield becomes a non-AppKit control
+
+// hit enter
+var enterEvent = document.createEvent("KeyboardEvents");
+enterEvent.initKeyboardEvent("keypress", true, false, window, "Enter", 0, false, false, false, false, false); // This is not at all like pulling teeth
+input.dispatchEvent(enterEvent);
+
+// test that blur happened last
+if (window.lastEvent == "blur")
+    log('PASS: blur event fired last.\n');
+</script>
diff --git a/LayoutTests/fast/events/onchange-textfield-expected.txt b/LayoutTests/fast/events/onchange-textfield-expected.txt
new file mode 100644 (file)
index 0000000..2ecee15
--- /dev/null
@@ -0,0 +1,10 @@
+This test verifies that the ENTER key fires the change and then the blur event.
+
+
+PASS: change event fired.
+
+PASS: blur event fired.
+
+PASS: blur event fired last.
+
+
diff --git a/LayoutTests/fast/events/onchange-textfield.html b/LayoutTests/fast/events/onchange-textfield.html
new file mode 100644 (file)
index 0000000..103433c
--- /dev/null
@@ -0,0 +1,39 @@
+<p>This test verifies that the ENTER key fires the change and then the blur event.</p>
+<hr>
+<input id="input" type="text" onchange="changeHandler()" onblur="blurHandler()"></input>
+<pre id="console"></pre>
+
+<script>
+function log(s)
+{
+    document.getElementById('console').appendChild(document.createTextNode(s + "\n"));
+}
+
+function changeHandler()
+{
+    window.lastEvent = "change";
+    log ('PASS: change event fired.\n');
+}
+
+function blurHandler()
+{
+    window.lastEvent = "blur";
+    log ('PASS: blur event fired.\n');
+}
+
+if (window.layoutTestController)
+    layoutTestController.dumpAsText();
+    
+// change the field
+document.getElementById('input').focus();
+document.execCommand("InsertText", false, "foo bar baz");
+
+// hit enter
+var enterEvent = document.createEvent("KeyboardEvents");
+enterEvent.initKeyboardEvent("keypress", true, false, window, "Enter", 0, false, false, false, false, false); // This is not at all like pulling teeth
+input.dispatchEvent(enterEvent);
+
+// test that blur happened last
+if (window.lastEvent == "blur")
+    log('PASS: blur event fired last.\n');
+</script>
index 3840f555df8ec12a23583e2a03d3e232165a8767..46099a3ce4661f6d043855e4b08ac100c34dfa3a 100644 (file)
@@ -1,3 +1,19 @@
+2006-12-07  Geoffrey Garen  <ggaren@apple.com>
+
+        Reviewed by Beth Dakin.
+
+        Fixed <rdar://problem/4870551> 9A320: <input type="text"> no longer 
+        dispatches onchange event in response to enter key
+        
+        To match our old behavior and FF, we need to dispatch onchange in response to the
+        ENTER key. The strategy here is just to dispatch a blur event, since that's how
+        the search field always worked, and the DOM spec says onchange only fires
+        as a precursor to blur.
+
+        * ChangeLog:
+        * html/HTMLInputElement.cpp:
+        (WebCore::HTMLInputElement::defaultEventHandler):
+
 2006-12-07  Adam Roben  <aroben@apple.com>
 
         Reviewed by Oliver.
 2006-12-07  Adam Roben  <aroben@apple.com>
 
         Reviewed by Oliver.
index a1e89cb3ae49ddbc45b60a562eb478dc7e83593f..8cf3bb81a536f356da74766587fb27b6ac3beb81 100644 (file)
@@ -1340,14 +1340,15 @@ void HTMLInputElement::defaultEventHandler(Event* evt)
         if (clickElement) {
             dispatchSimulatedClick(evt);
             evt->setDefaultHandled();
         if (clickElement) {
             dispatchSimulatedClick(evt);
             evt->setDefaultHandled();
-        } else if (clickDefaultFormButton && (inputType() != SEARCH || form())) {
+        } else if (clickDefaultFormButton) {
+            blur();
+            // Form may never have been present, or may have been destroyed by the blur event.
             if (form()) {
             if (form()) {
-                blur();
-                // Make sure the form hasn't been destroyed during the blur.
-                if (form())
-                    form()->submitClick(evt);
+                form()->submitClick(evt);
+                evt->setDefaultHandled();
+            } else if (inputType() != SEARCH) {
+                evt->setDefaultHandled();
             }
             }
-            evt->setDefaultHandled();
         }
     }
 
         }
     }