LayoutTests:
authordarin <darin@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 15 Jul 2006 15:21:28 +0000 (15:21 +0000)
committerdarin <darin@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 15 Jul 2006 15:21:28 +0000 (15:21 +0000)
        Reviewed by Adele.

        - test for http://bugzilla.opendarwin.org/show_bug.cgi?id=8871
          <rdar://problem/4575417>
          REGRESSION: Pressing Enter/Return in a text input removes the selected text
          and http://bugzilla.opendarwin.org/show_bug.cgi?id=9743
          <rdar://problem/4614228>
          REGRESSION: crash dispatching JavaScript-created keyboard event to input element

        * fast/forms/input-text-enter-expected.txt: Added.
        * fast/forms/input-text-enter.html: Added.

WebCore:

        Reviewed by Adele.

        - fix http://bugzilla.opendarwin.org/show_bug.cgi?id=8871
          <rdar://problem/4575417>
          REGRESSION: Pressing Enter/Return in a text input removes the selected text

        - fix http://bugzilla.opendarwin.org/show_bug.cgi?id=9743
          <rdar://problem/4614228>
          REGRESSION: crash dispatching JavaScript-created keyboard event to input element

        * bridge/mac/FrameMac.mm: (WebCore::FrameMac::doTextFieldCommandFromEvent):
        Add a null check to fix the crash, and a FIXME explaining why this is not necessarily
        enough for the future.

        * html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::defaultEventHandler):
        Consume Enter key keypress events even if the element is not in a form.

        * platform/mac/KeyEventMac.mm: (WebCore::keyIdentifierForKeyEvent): Added \n to the
        characters that turn into "Enter". Actual keyboard events always are \r or \003 on
        the Macintosh, but in layout tests we can use \n, and everything other than the
        code path here works, so worth fixing.

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

LayoutTests/ChangeLog
LayoutTests/fast/forms/input-text-enter-expected.txt [new file with mode: 0644]
LayoutTests/fast/forms/input-text-enter.html [new file with mode: 0644]
WebCore/ChangeLog
WebCore/bridge/mac/FrameMac.mm
WebCore/html/HTMLInputElement.cpp
WebCore/platform/mac/KeyEventMac.mm

index f9f0700e6b0f5e4fc4bc591ffdc51c02df038c7f..022832e38ccc082f5256300e5011c89b830c852f 100644 (file)
@@ -1,3 +1,17 @@
+2006-07-15  Darin Adler  <darin@apple.com>
+
+        Reviewed by Adele.
+
+        - test for http://bugzilla.opendarwin.org/show_bug.cgi?id=8871
+          <rdar://problem/4575417>
+          REGRESSION: Pressing Enter/Return in a text input removes the selected text
+          and http://bugzilla.opendarwin.org/show_bug.cgi?id=9743
+          <rdar://problem/4614228>
+          REGRESSION: crash dispatching JavaScript-created keyboard event to input element
+
+        * fast/forms/input-text-enter-expected.txt: Added.
+        * fast/forms/input-text-enter.html: Added.
+
 2006-07-15  Darin Adler  <darin@apple.com>
 
         Reviewed by John Sullivan.
diff --git a/LayoutTests/fast/forms/input-text-enter-expected.txt b/LayoutTests/fast/forms/input-text-enter-expected.txt
new file mode 100644 (file)
index 0000000..01a38d0
--- /dev/null
@@ -0,0 +1,7 @@
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+This test selects some characters, then simulates a press of the Enter key (marked Return on Macintosh keyboards).
+
+
+Content of input after pressing return is "12345678". It should be "12345678".
+
+
diff --git a/LayoutTests/fast/forms/input-text-enter.html b/LayoutTests/fast/forms/input-text-enter.html
new file mode 100644 (file)
index 0000000..10a1c00
--- /dev/null
@@ -0,0 +1,15 @@
+<p>This test selects some characters, then simulates a press of the Enter key (marked Return on Macintosh keyboards).</p>
+<p><input id="input" value="12345678"></input></p>
+<p>Content of input after pressing return is "<span id="result"></span>". It should be "12345678".</p>
+<script>
+if (window.layoutTestController)
+    layoutTestController.dumpAsText();
+var input = document.getElementById("input");
+input.setSelectionRange(2, 6);
+var event = document.createEvent("KeyboardEvents");
+event.initKeyboardEvent("keypress", true, true, document.defaultView, "Enter", 0, false, false, false, false, false);
+input.dispatchEvent(event);
+if (window.eventSender)
+    eventSender.keyDown('\n', []);
+document.getElementById("result").innerText = input.value;
+</script>
index d3cf652fb3a4f0757cfd53d0b9196f2157a20dcd..ec786b72b626520219ed17f582e508b88315b16f 100644 (file)
@@ -1,3 +1,27 @@
+2006-07-15  Darin Adler  <darin@apple.com>
+
+        Reviewed by Adele.
+
+        - fix http://bugzilla.opendarwin.org/show_bug.cgi?id=8871
+          <rdar://problem/4575417>
+          REGRESSION: Pressing Enter/Return in a text input removes the selected text
+
+        - fix http://bugzilla.opendarwin.org/show_bug.cgi?id=9743
+          <rdar://problem/4614228>
+          REGRESSION: crash dispatching JavaScript-created keyboard event to input element
+
+        * bridge/mac/FrameMac.mm: (WebCore::FrameMac::doTextFieldCommandFromEvent):
+        Add a null check to fix the crash, and a FIXME explaining why this is not necessarily
+        enough for the future.
+
+        * html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::defaultEventHandler):
+        Consume Enter key keypress events even if the element is not in a form.
+
+        * platform/mac/KeyEventMac.mm: (WebCore::keyIdentifierForKeyEvent): Added \n to the
+        characters that turn into "Enter". Actual keyboard events always are \r or \003 on
+        the Macintosh, but in layout tests we can use \n, and everything other than the
+        code path here works, so worth fixing.
+
 2006-07-15  Darin Adler  <darin@apple.com>
 
         Reviewed by John Sullivan.
index 983ef135ffe81729ddb4609116157c7173483329..1527b232da59e00afafcce48fcfb5ad59a4cda5a 100644 (file)
@@ -3264,6 +3264,11 @@ void FrameMac::textDidChangeInTextArea(Element* textarea)
 
 bool FrameMac::doTextFieldCommandFromEvent(Element* input, const PlatformKeyboardEvent* event)
 {
+    // FIXME: We might eventually need to make sure key bindings for editing work even with
+    // events created with the DOM API. Those don't have a PlatformKeyboardEvent.
+    if (!event)
+        return false;
+
     BEGIN_BLOCK_OBJC_EXCEPTIONS;
     return [_bridge textField:(DOMHTMLInputElement *)[DOMElement _elementWith:input] doCommandBySelector:selectorForKeyEvent(event)];
     END_BLOCK_OBJC_EXCEPTIONS;
index dae0dc2e40a37eda53a5d0a8594a611551013579..22b7908ba0ad89545f15da6f27c34c38c11ddaed 100644 (file)
@@ -1343,8 +1343,9 @@ void HTMLInputElement::defaultEventHandler(Event *evt)
         if (clickElement) {
             click(false);
             evt->setDefaultHandled();
-        } else if (clickDefaultFormButton && form()) {
-            form()->submitClick();
+        } else if (clickDefaultFormButton) {
+            if (form())
+                form()->submitClick();
             evt->setDefaultHandled();
         }
     }
index df1b1c317567685d9a3e6ef3d5136eec3e8dadad..855487f37883c39d3aa3f2f061392a2fdbc4a892 100644 (file)
@@ -78,7 +78,7 @@ static String keyIdentifierForKeyEvent(NSEvent* event)
         case NSEndFunctionKey:
             return "End";
         // "Enter"
-        case 0x3: case 0xD: // Macintosh calls the one on the main keyboard Return, but Windows calls it Enter, so we'll do the same for the DOM
+        case 0x3: case 0xA: case 0xD: // Macintosh calls the one on the main keyboard Return, but Windows calls it Enter, so we'll do the same for the DOM
             return "Enter";
 
         // "EraseEof"
@@ -270,27 +270,27 @@ static String keyIdentifierForKeyEvent(NSEvent* event)
         // "Zoom"
 
         // More function keys, not in the key identifier specification.
-       case NSF25FunctionKey:
+        case NSF25FunctionKey:
             return "F25";
-       case NSF26FunctionKey:
+        case NSF26FunctionKey:
             return "F26";
-       case NSF27FunctionKey:
+        case NSF27FunctionKey:
             return "F27";
-       case NSF28FunctionKey:
+        case NSF28FunctionKey:
             return "F28";
-       case NSF29FunctionKey:
+        case NSF29FunctionKey:
             return "F29";
-       case NSF30FunctionKey:
+        case NSF30FunctionKey:
             return "F30";
-       case NSF31FunctionKey:
+        case NSF31FunctionKey:
             return "F31";
-       case NSF32FunctionKey:
+        case NSF32FunctionKey:
             return "F32";
-       case NSF33FunctionKey:
+        case NSF33FunctionKey:
             return "F33";
-       case NSF34FunctionKey:
+        case NSF34FunctionKey:
             return "F34";
-       case NSF35FunctionKey:
+        case NSF35FunctionKey:
             return "F35";
 
         // Turn 0x7F into 0x08, because backspace needs to always be 0x08.
@@ -300,21 +300,21 @@ static String keyIdentifierForKeyEvent(NSEvent* event)
         case NSDeleteFunctionKey:
             return "U+00007F";
 
-       case NSBeginFunctionKey:
-       case NSBreakFunctionKey:
-       case NSClearDisplayFunctionKey:
-       case NSDeleteCharFunctionKey:
-       case NSDeleteLineFunctionKey:
-       case NSInsertCharFunctionKey:
-       case NSInsertLineFunctionKey:
-       case NSNextFunctionKey:
-       case NSPrevFunctionKey:
-       case NSPrintFunctionKey:
-       case NSRedoFunctionKey:
-       case NSResetFunctionKey:
-       case NSSysReqFunctionKey:
-       case NSSystemFunctionKey:
-       case NSUserFunctionKey:
+        case NSBeginFunctionKey:
+        case NSBreakFunctionKey:
+        case NSClearDisplayFunctionKey:
+        case NSDeleteCharFunctionKey:
+        case NSDeleteLineFunctionKey:
+        case NSInsertCharFunctionKey:
+        case NSInsertLineFunctionKey:
+        case NSNextFunctionKey:
+        case NSPrevFunctionKey:
+        case NSPrintFunctionKey:
+        case NSRedoFunctionKey:
+        case NSResetFunctionKey:
+        case NSSysReqFunctionKey:
+        case NSSystemFunctionKey:
+        case NSUserFunctionKey:
             // FIXME: We should use something other than the vendor-area Unicode values for the above keys.
             // For now, just fall through to the default.
         default:
@@ -326,9 +326,9 @@ static bool isKeypadEvent(NSEvent* event)
 {
     // Check that this is the type of event that has a keyCode.
     switch ([event type]) {
-       case NSKeyDown:
-       case NSKeyUp:
-       case NSFlagsChanged:
+        case NSKeyDown:
+        case NSKeyUp:
+        case NSFlagsChanged:
             break;
         default:
             return false;