Reviewed by Darin.
authorap@webkit.org <ap@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 17 Dec 2007 18:34:17 +0000 (18:34 +0000)
committerap@webkit.org <ap@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 17 Dec 2007 18:34:17 +0000 (18:34 +0000)
        Live to the promise of never making AppKit special character codes visible via DOM.

        Test: fast/events/arrow-keys-on-body.html

        * page/EventHandler.cpp:
        (WebCore::EventHandler::keyEvent): Check for empty keypress characters after disambiguation,
        to let quirks-aware code strip special charactrers.
        * platform/mac/KeyEventMac.mm:
        (WebCore::PlatformKeyboardEvent::disambiguateKeyDownEvent): If not in keyboard event quirks
        mode, remove the text if it's a special character.

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

LayoutTests/ChangeLog
LayoutTests/fast/events/arrow-keys-on-body-expected.txt [new file with mode: 0644]
LayoutTests/fast/events/arrow-keys-on-body.html [new file with mode: 0644]
WebCore/ChangeLog
WebCore/page/EventHandler.cpp
WebCore/platform/mac/KeyEventMac.mm

index 16aa7fe..2d2bbf6 100644 (file)
@@ -1,3 +1,12 @@
+2007-12-17  Alexey Proskuryakov  <ap@webkit.org>
+
+        Reviewed by Darin.
+
+        Live to the promise of never making AppKit special character codes visible via DOM.
+
+        * fast/events/arrow-keys-on-body-expected.txt: Added.
+        * fast/events/arrow-keys-on-body.html: Added.
+
 2007-12-16  Darin Adler  <darin@apple.com>
 
         * fast/js/regexp-overflow-expected.txt: Updated. I accidentally checked in an
diff --git a/LayoutTests/fast/events/arrow-keys-on-body-expected.txt b/LayoutTests/fast/events/arrow-keys-on-body-expected.txt
new file mode 100644 (file)
index 0000000..b5b70b1
--- /dev/null
@@ -0,0 +1,8 @@
+Test that arrow keys do not dispatch keypress events even if there is no default handler.
+
+To test manually, press arrow keys and verify that no keypress events are logged.
+
+target - type - ctrlKey,altKey,shiftKey,metaKey - keyIdentifier - keyLocation - keyCode - charCode
+BODY - keydown - false,false,false,false - Left - DOM_KEY_LOCATION_STANDARD - 37 - 0
+BODY - keyup - false,false,false,false - Left - DOM_KEY_LOCATION_STANDARD - 37 - 0
+
diff --git a/LayoutTests/fast/events/arrow-keys-on-body.html b/LayoutTests/fast/events/arrow-keys-on-body.html
new file mode 100644 (file)
index 0000000..84777d4
--- /dev/null
@@ -0,0 +1,65 @@
+<body
+   onkeypress="log(eventInfo(event))"
+   onkeydown="log(eventInfo(event))"
+   onkeyup="log(eventInfo(event))">
+<p>Test that arrow keys do not dispatch keypress events even if there is no default handler.</p>
+<p>To test manually, press arrow keys and verify that no keypress events are logged.</p>
+<div id="log"></div>
+
+<script>
+function log(msg) {
+   document.getElementById("log").innerHTML+= msg + "<br />";
+}
+
+
+function locationName(code) {
+  switch (code) {
+    case 0:
+        return "DOM_KEY_LOCATION_STANDARD";
+    case 1:
+        return "DOM_KEY_LOCATION_LEFT";
+    case 2:
+        return "DOM_KEY_LOCATION_RIGHT";
+    case 3:
+        return "DOM_KEY_LOCATION_NUMPAD";
+    default:
+        return code.toString();
+  }
+}
+
+function eventInfo(event, where) {
+  try {
+    if (!event)
+      event = window.event;
+    target = event.srcElement ? event.srcElement : event.target;
+    if (event.type == "textInput")
+        return (where ? "(" + where + ") " : "") + target.tagName + " - " + event.type + " - " + event.data
+            + '. Value: "' + target.value + '".';
+    else if (event.type == "keydown" || event.type == "keypress" || event.type == "keyup") 
+        return (where ? "(" + where + ") " : "") + target.tagName
+            + (target.tagName == "INPUT" ? " " + target.type : "")
+            + " - " + event.type
+            + ' - ' + [event.ctrlKey, event.altKey, event.shiftKey, event.metaKey]
+            + ' - ' + event.keyIdentifier
+            + ' - ' + (event.keyLocation === undefined ? "undefined" : locationName(event.keyLocation))
+            + ' - ' + event.keyCode
+            + ' - ' + event.charCode;
+
+    } catch (ex) {
+        alert(ex);
+    }
+}
+log("target - type - " + ["ctrlKey", "altKey", "shiftKey", "metaKey"]
+        + ' - ' + "keyIdentifier"
+        + ' - ' + "keyLocation"
+        + ' - ' + "keyCode"
+        + ' - ' + "charCode");
+
+if (window.layoutTestController) {
+    layoutTestController.dumpAsText();
+    eventSender.keyDown("leftArrow", []);
+}
+
+</script>
+
+</body>
index 4b06fff..02d5a4e 100644 (file)
@@ -1,3 +1,18 @@
+2007-12-17  Alexey Proskuryakov  <ap@webkit.org>
+
+        Reviewed by Darin.
+
+        Live to the promise of never making AppKit special character codes visible via DOM.
+
+        Test: fast/events/arrow-keys-on-body.html
+
+        * page/EventHandler.cpp:
+        (WebCore::EventHandler::keyEvent): Check for empty keypress characters after disambiguation,
+        to let quirks-aware code strip special charactrers.
+        * platform/mac/KeyEventMac.mm:
+        (WebCore::PlatformKeyboardEvent::disambiguateKeyDownEvent): If not in keyboard event quirks
+        mode, remove the text if it's a special character.
+
 2007-12-17  Mark Rowe  <mrowe@apple.com>
 
         Reviewed by Darin Adler.
index 56ede27..066116a 100644 (file)
@@ -1548,7 +1548,7 @@ bool EventHandler::keyEvent(const PlatformKeyboardEvent& initialKeyEvent)
 
     node->dispatchEvent(keydown, ec, true);
     bool keydownResult = keydown->defaultHandled() || keydown->defaultPrevented();
-    if (handledByInputMethod || (keydownResult && !backwardCompatibilityMode) || initialKeyEvent.text().isEmpty())
+    if (handledByInputMethod || (keydownResult && !backwardCompatibilityMode))
         return keydownResult;
     
     // Focus may have changed during keydown handling, so refetch node.
@@ -1561,6 +1561,8 @@ bool EventHandler::keyEvent(const PlatformKeyboardEvent& initialKeyEvent)
 
     PlatformKeyboardEvent keyPressEvent = initialKeyEvent;
     keyPressEvent.disambiguateKeyDownEvent(PlatformKeyboardEvent::Char, backwardCompatibilityMode);
+    if (keyPressEvent.text().isEmpty())
+        return keydownResult;
     RefPtr<KeyboardEvent> keypress = new KeyboardEvent(keyPressEvent, m_frame->document()->defaultView());
     keypress->setTarget(node);
     if (keydownResult)
index 50d0546..9aa6d8b 100644 (file)
@@ -857,6 +857,13 @@ void PlatformKeyboardEvent::disambiguateKeyDownEvent(Type type, bool backwardCom
     } else {
         m_keyIdentifier = String();
         m_windowsVirtualKeyCode = 0;
+        if (m_text.length() == 1 && (m_text[0U] >= 0xF700 && m_text[0U] <= 0xF7FF)) {
+            // According to NSEvents.h, OpenStep reserves the range 0xF700-0xF8FF for function keys. However, some actual private use characters
+            // happen to be in this range, e.g. the Apple logo (Option+Shift+K).
+            // 0xF7FF is an arbitrary cut-off.
+            m_text = String();
+            m_unmodifiedText = String();
+        }
     }
 }