Bug 842927 part.9 Implement D3E KeyboardEvent.key on Gonk r=smaug+mwu
authorMasayuki Nakano <masayuki@d-toybox.com>
Wed, 24 Apr 2013 12:49:48 +0900
changeset 129710 bfe45fd605f8
parent 129709 c85f2e0fad49
child 129711 96c0eae610a2
push id24586
push userryanvm@gmail.com
push date2013-04-24 12:15 +0000
treeherdermozilla-central@1c5977e8d52f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs842927
milestone23.0a1
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
Bug 842927 part.9 Implement D3E KeyboardEvent.key on Gonk r=smaug+mwu
widget/gonk/GonkKeyMapping.h
widget/gonk/nsAppShell.cpp
--- a/widget/gonk/GonkKeyMapping.h
+++ b/widget/gonk/GonkKeyMapping.h
@@ -11,16 +11,22 @@
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 
 #ifndef GONKKEYMAPPING_H
 #define GONKKEYMAPPING_H
 
+#include "nsEvent.h"
+#include "libui/android_keycodes.h"
+
+namespace mozilla {
+namespace widget {
+
 /* See libui/KeycodeLabels.h for the mapping */
 static const unsigned long kKeyMapping[] = {
     0,
     0, // SOFT_LEFT
     0, // SOFT_RIGHT
     NS_VK_HOME, // HOME
     0, // BACK
     0, // CALL
@@ -177,9 +183,81 @@ static const unsigned long kKeyMapping[]
     NS_VK_SUBTRACT,
     NS_VK_ADD,
     NS_VK_PERIOD,
     NS_VK_COMMA,
     NS_VK_ENTER,
     NS_VK_EQUALS,
     // There are more but we don't map them
 };
+
+static KeyNameIndex GetKeyNameIndex(int aKeyCode)
+{
+    switch (aKeyCode) {
+#define NS_NATIVE_KEY_TO_DOM_KEY_NAME_INDEX(aNativeKey, aKeyNameIndex) \
+    case aNativeKey: return aKeyNameIndex;
+
+#include "NativeKeyToDOMKeyName.h"
+
+#undef NS_NATIVE_KEY_TO_DOM_KEY_NAME_INDEX
+
+    case AKEYCODE_0:
+    case AKEYCODE_1:
+    case AKEYCODE_2:
+    case AKEYCODE_3:
+    case AKEYCODE_4:
+    case AKEYCODE_5:
+    case AKEYCODE_6:
+    case AKEYCODE_7:
+    case AKEYCODE_8:
+    case AKEYCODE_9:
+    case AKEYCODE_STAR:
+    case AKEYCODE_POUND:
+    case AKEYCODE_A:
+    case AKEYCODE_B:
+    case AKEYCODE_C:
+    case AKEYCODE_D:
+    case AKEYCODE_E:
+    case AKEYCODE_F:
+    case AKEYCODE_G:
+    case AKEYCODE_H:
+    case AKEYCODE_I:
+    case AKEYCODE_J:
+    case AKEYCODE_K:
+    case AKEYCODE_L:
+    case AKEYCODE_M:
+    case AKEYCODE_N:
+    case AKEYCODE_O:
+    case AKEYCODE_P:
+    case AKEYCODE_Q:
+    case AKEYCODE_R:
+    case AKEYCODE_S:
+    case AKEYCODE_T:
+    case AKEYCODE_U:
+    case AKEYCODE_V:
+    case AKEYCODE_W:
+    case AKEYCODE_X:
+    case AKEYCODE_Y:
+    case AKEYCODE_Z:
+    case AKEYCODE_COMMA:
+    case AKEYCODE_PERIOD:
+    case AKEYCODE_GRAVE:
+    case AKEYCODE_MINUS:
+    case AKEYCODE_EQUALS:
+    case AKEYCODE_LEFT_BRACKET:
+    case AKEYCODE_RIGHT_BRACKET:
+    case AKEYCODE_BACKSLASH:
+    case AKEYCODE_SEMICOLON:
+    case AKEYCODE_APOSTROPHE:
+    case AKEYCODE_SLASH:
+    case AKEYCODE_AT:
+    case AKEYCODE_PLUS:
+        return KEY_NAME_INDEX_PrintableKey;
+
+    default:
+        return KEY_NAME_INDEX_Unidentified;
+    }
+}
+
+} // namespace widget
+} // namespace mozilla
+
 #endif /* GONKKEYMAPPING_H */
--- a/widget/gonk/nsAppShell.cpp
+++ b/widget/gonk/nsAppShell.cpp
@@ -47,16 +47,19 @@
 
 #include "android/log.h"
 #include "libui/EventHub.h"
 #include "libui/InputReader.h"
 #include "libui/InputDispatcher.h"
 
 #include "GeckoProfiler.h"
 
+// Defines kKeyMapping and GetKeyNameIndex()
+#include "GonkKeyMapping.h"
+
 #define LOG(args...)                                            \
     __android_log_print(ANDROID_LOG_INFO, "Gonk" , ## args)
 #ifdef VERBOSE_LOG_ENABLED
 # define VERBOSE_LOG(args...)                           \
     __android_log_print(ANDROID_LOG_INFO, "Gonk" , ## args)
 #else
 # define VERBOSE_LOG(args...)                   \
     (void)0
@@ -195,53 +198,58 @@ sendTouchEvent(UserInputData& data, bool
             addDOMTouch(data, event, i);
     }
 
     return nsWindow::DispatchInputEvent(event, captured);
 }
 
 static nsEventStatus
 sendKeyEventWithMsg(uint32_t keyCode,
+                    KeyNameIndex keyNameIndex,
                     uint32_t msg,
                     uint64_t timeMs,
                     const EventFlags& flags)
 {
     nsKeyEvent event(true, msg, NULL);
     event.keyCode = keyCode;
+    event.mKeyNameIndex = keyNameIndex;
     event.location = nsIDOMKeyEvent::DOM_KEY_LOCATION_MOBILE;
     event.time = timeMs;
     event.mFlags.Union(flags);
     return nsWindow::DispatchInputEvent(event);
 }
 
 static void
-sendKeyEvent(uint32_t keyCode, bool down, uint64_t timeMs)
+sendKeyEvent(uint32_t keyCode, KeyNameIndex keyNameIndex, bool down,
+             uint64_t timeMs)
 {
     EventFlags extraFlags;
     nsEventStatus status =
-        sendKeyEventWithMsg(keyCode, down ? NS_KEY_DOWN : NS_KEY_UP, timeMs,
-                            extraFlags);
+        sendKeyEventWithMsg(keyCode, keyNameIndex,
+                            down ? NS_KEY_DOWN : NS_KEY_UP, timeMs, extraFlags);
     if (down) {
         extraFlags.mDefaultPrevented =
             (status == nsEventStatus_eConsumeNoDefault);
-        sendKeyEventWithMsg(keyCode, NS_KEY_PRESS, timeMs, extraFlags);
+        sendKeyEventWithMsg(keyCode, keyNameIndex, NS_KEY_PRESS, timeMs,
+                            extraFlags);
     }
 }
 
-// Defines kKeyMapping
-#include "GonkKeyMapping.h"
-
 static void
 maybeSendKeyEvent(int keyCode, bool pressed, uint64_t timeMs)
 {
-    if (keyCode < ArrayLength(kKeyMapping) && kKeyMapping[keyCode])
-        sendKeyEvent(kKeyMapping[keyCode], pressed, timeMs);
-    else
+    uint32_t DOMKeyCode =
+        (keyCode < ArrayLength(kKeyMapping)) ? kKeyMapping[keyCode] : 0;
+    KeyNameIndex DOMKeyNameIndex = GetKeyNameIndex(keyCode);
+    if (DOMKeyCode || DOMKeyNameIndex != KEY_NAME_INDEX_Unidentified) {
+        sendKeyEvent(DOMKeyCode, DOMKeyNameIndex, pressed, timeMs);
+    } else {
         VERBOSE_LOG("Got unknown key event code. type 0x%04x code 0x%04x value %d",
                     keyCode, pressed);
+    }
 }
 
 class GeckoPointerController : public PointerControllerInterface {
     float mX;
     float mY;
     int32_t mButtonState;
     InputReaderConfiguration* mConfig;
 public: