Don't drop keypress messages with character codes > U+FFFF. Bug 297943, r=karlt
authorSimon Montagu <smontagu@smontagu.org>
Sun, 04 Jul 2010 15:42:04 +0300
changeset 47210 d2d570a50ddfb311b97cd457705df69e9378d87b
parent 47209 55f39d8d866ce6ce6e7c0b62189798f18b1c8de4
child 47211 4a6b283ec78cdeb50368c7ebf957079a82cc9f66
push id14274
push usersmontagu@mozilla.com
push dateSun, 04 Jul 2010 12:43:19 +0000
treeherdermozilla-central@4a6b283ec78c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskarlt
bugs297943
milestone2.0b2pre
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Don't drop keypress messages with character codes > U+FFFF. Bug 297943, r=karlt
widget/src/gtk2/nsGtkKeyUtils.cpp
widget/src/gtk2/nsWindow.cpp
--- a/widget/src/gtk2/nsGtkKeyUtils.cpp
+++ b/widget/src/gtk2/nsGtkKeyUtils.cpp
@@ -44,16 +44,18 @@
 
 #include <gdk/gdk.h>
 #ifdef MOZ_X11
 #include <gdk/gdkx.h>
 #endif /* MOZ_X11 */
 #include "nsGUIEvent.h"
 #include "keysym2ucs.h"
 
+#define MAX_UNICODE 0x10FFFF
+
 struct nsKeyConverter {
     int vkCode; // Platform independent key code
     int keysym; // GDK keysym key code
 };
 
 //
 // Netscape keycodes are defined in widget/public/nsGUIEvent.h
 // GTK keycodes are defined in <gdk/gdkkeysyms.h>
@@ -329,14 +331,14 @@ PRUint32 nsConvertCharCodeToUnicode(GdkE
             }
 
         // non-printables
         return 0;
     }
 
     // we're supposedly printable, let's try to convert
     long ucs = keysym2ucs(aEvent->keyval);
-    if ((ucs != -1) && (ucs < 0x10000))
+    if ((ucs != -1) && (ucs < MAX_UNICODE))
         return ucs;
 
     // I guess we couldn't convert
     return 0;
 }
--- a/widget/src/gtk2/nsWindow.cpp
+++ b/widget/src/gtk2/nsWindow.cpp
@@ -3438,18 +3438,31 @@ nsWindow::OnKeyPressEvent(GtkWidget *aWi
     if (is_context_menu_key(event)) {
         nsMouseEvent contextMenuEvent(PR_TRUE, NS_CONTEXTMENU, this,
                                       nsMouseEvent::eReal,
                                       nsMouseEvent::eContextMenuKey);
         key_event_to_context_menu_event(contextMenuEvent, aEvent);
         DispatchEvent(&contextMenuEvent, status);
     }
     else {
-        // send the key press event
-        DispatchEvent(&event, status);
+        // If the character code is in the BMP, send the key press event.
+        // Otherwise, send a text event with the equivalent UTF-16 string.
+        if (IS_IN_BMP(event.charCode)) {
+            DispatchEvent(&event, status);
+        }
+        else {
+            nsTextEvent textEvent(PR_TRUE, NS_TEXT_TEXT, this);
+            PRUnichar textString[3];
+            textString[0] = H_SURROGATE(event.charCode);
+            textString[1] = L_SURROGATE(event.charCode);
+            textString[2] = 0;
+            textEvent.theText = textString;
+            textEvent.time = event.time;
+            DispatchEvent(&textEvent, status);
+        }
     }
 
     // If the event was consumed, return.
     if (status == nsEventStatus_eConsumeNoDefault) {
         return TRUE;
     }
 
     return FALSE;