Bug 936313 part.2 Compute DOM key location from code value on Android and Gonk r=smaug+mwu+cpeterson
authorMasayuki Nakano <masayuki@d-toybox.com>
Wed, 28 Jan 2015 22:36:53 +0900
changeset 226287 53cf3295596e0e3d5da1fe8e02e664c9692da149
parent 226286 3f291f100e26507fef3bc08b4d8d66733eacfbd1
child 226288 74f29dfebd9c8987f4c2912dd7d3158108b3f669
push id11039
push userryanvm@gmail.com
push dateWed, 28 Jan 2015 20:05:03 +0000
treeherderfx-team@56b736e32ae6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs936313
milestone38.0a1
Bug 936313 part.2 Compute DOM key location from code value on Android and Gonk r=smaug+mwu+cpeterson
widget/TextEvents.h
widget/WidgetEventImpl.cpp
widget/android/nsWindow.cpp
widget/gonk/nsAppShell.cpp
--- a/widget/TextEvents.h
+++ b/widget/TextEvents.h
@@ -175,16 +175,18 @@ public:
   {
     if (mCodeNameIndex == CODE_NAME_INDEX_USE_STRING) {
       aCodeName = mCodeValue;
       return;
     }
     GetDOMCodeName(mCodeNameIndex, aCodeName);
   }
 
+  static uint32_t ComputeLocationFromCodeValue(CodeNameIndex aCodeNameIndex);
+
   static void GetDOMKeyName(KeyNameIndex aKeyNameIndex,
                             nsAString& aKeyName);
   static void GetDOMCodeName(CodeNameIndex aCodeNameIndex,
                              nsAString& aCodeName);
 
   static const char* GetCommandStr(Command aCommand);
 
   void AssignKeyEventData(const WidgetKeyboardEvent& aEvent, bool aCopyTargets)
--- a/widget/WidgetEventImpl.cpp
+++ b/widget/WidgetEventImpl.cpp
@@ -388,9 +388,60 @@ WidgetKeyboardEvent::GetCommandStr(Comma
   };
 #undef NS_DEFINE_COMMAND
 
   MOZ_RELEASE_ASSERT(static_cast<size_t>(aCommand) < ArrayLength(kCommands),
                      "Illegal command enumeration value");
   return kCommands[aCommand];
 }
 
+/* static */ uint32_t
+WidgetKeyboardEvent::ComputeLocationFromCodeValue(CodeNameIndex aCodeNameIndex)
+{
+  // Following commented out cases are not defined in PhysicalKeyCodeNameList.h
+  // but are defined by D3E spec.  So, they should be uncommented when the
+  // code values are defined in the header.
+  switch (aCodeNameIndex) {
+    case CODE_NAME_INDEX_AltLeft:
+    case CODE_NAME_INDEX_ControlLeft:
+    case CODE_NAME_INDEX_OSLeft:
+    case CODE_NAME_INDEX_ShiftLeft:
+      return nsIDOMKeyEvent::DOM_KEY_LOCATION_LEFT;
+    case CODE_NAME_INDEX_AltRight:
+    case CODE_NAME_INDEX_ControlRight:
+    case CODE_NAME_INDEX_OSRight:
+    case CODE_NAME_INDEX_ShiftRight:
+      return nsIDOMKeyEvent::DOM_KEY_LOCATION_RIGHT;
+    case CODE_NAME_INDEX_Numpad0:
+    case CODE_NAME_INDEX_Numpad1:
+    case CODE_NAME_INDEX_Numpad2:
+    case CODE_NAME_INDEX_Numpad3:
+    case CODE_NAME_INDEX_Numpad4:
+    case CODE_NAME_INDEX_Numpad5:
+    case CODE_NAME_INDEX_Numpad6:
+    case CODE_NAME_INDEX_Numpad7:
+    case CODE_NAME_INDEX_Numpad8:
+    case CODE_NAME_INDEX_Numpad9:
+    case CODE_NAME_INDEX_NumpadAdd:
+    case CODE_NAME_INDEX_NumpadBackspace:
+    // case CODE_NAME_INDEX_NumpadClear:
+    // case CODE_NAME_INDEX_NumpadClearEntry:
+    case CODE_NAME_INDEX_NumpadComma:
+    case CODE_NAME_INDEX_NumpadDecimal:
+    case CODE_NAME_INDEX_NumpadDivide:
+    case CODE_NAME_INDEX_NumpadEnter:
+    case CODE_NAME_INDEX_NumpadEqual:
+    // case CODE_NAME_INDEX_NumpadMemoryAdd:
+    // case CODE_NAME_INDEX_NumpadMemoryClear:
+    // case CODE_NAME_INDEX_NumpadMemoryRecall:
+    // case CODE_NAME_INDEX_NumpadMemoryStore:
+    case CODE_NAME_INDEX_NumpadMemorySubtract:
+    case CODE_NAME_INDEX_NumpadMultiply:
+    // case CODE_NAME_INDEX_NumpadParenLeft:
+    // case CODE_NAME_INDEX_NumpadParenRight:
+    case CODE_NAME_INDEX_NumpadSubtract:
+      return nsIDOMKeyEvent::DOM_KEY_LOCATION_NUMPAD;
+    default:
+      return nsIDOMKeyEvent::DOM_KEY_LOCATION_STANDARD;
+  }
+}
+
 } // namespace mozilla
--- a/widget/android/nsWindow.cpp
+++ b/widget/android/nsWindow.cpp
@@ -1535,18 +1535,18 @@ nsWindow::InitKeyEvent(WidgetKeyboardEve
     if (event.message == NS_KEY_PRESS &&
         key.UnicodeChar() && key.UnicodeChar() != key.BaseUnicodeChar()) {
         event.modifiers &= ~(MODIFIER_ALT | MODIFIER_CONTROL | MODIFIER_META);
     }
 
     event.mIsRepeat =
         (event.message == NS_KEY_DOWN || event.message == NS_KEY_PRESS) &&
         (!!(key.Flags() & AKEY_EVENT_FLAG_LONG_PRESS) || !!key.RepeatCount());
-    // XXX Compute the location from code value, later.
-    event.location = nsIDOMKeyboardEvent::DOM_KEY_LOCATION_STANDARD;
+    event.location =
+        WidgetKeyboardEvent::ComputeLocationFromCodeValue(event.mCodeNameIndex);
     event.time = key.Time();
 
     if (gMenu)
         gMenuConsumed = true;
 }
 
 void
 nsWindow::HandleSpecialKey(AndroidGeckoEvent *ae)
--- a/widget/gonk/nsAppShell.cpp
+++ b/widget/gonk/nsAppShell.cpp
@@ -207,16 +207,17 @@ public:
 private:
     const UserInputData& mData;
     sp<KeyCharacterMap> mKeyCharMap;
 
     char16_t mChar;
     char16_t mUnmodifiedChar;
 
     uint32_t mDOMKeyCode;
+    uint32_t mDOMKeyLocation;
     KeyNameIndex mDOMKeyNameIndex;
     CodeNameIndex mDOMCodeNameIndex;
     char16_t mDOMPrintableKeyValue;
 
     bool IsKeyPress() const
     {
         return mData.action == AKEY_EVENT_ACTION_DOWN;
     }
@@ -241,26 +242,31 @@ private:
     }
 
     void DispatchKeyDownEvent();
     void DispatchKeyUpEvent();
     nsEventStatus DispatchKeyEventInternal(uint32_t aEventMessage);
 };
 
 KeyEventDispatcher::KeyEventDispatcher(const UserInputData& aData,
-                                       KeyCharacterMap* aKeyCharMap) :
-    mData(aData), mKeyCharMap(aKeyCharMap), mChar(0), mUnmodifiedChar(0),
-    mDOMPrintableKeyValue(0)
+                                       KeyCharacterMap* aKeyCharMap)
+    : mData(aData)
+    , mKeyCharMap(aKeyCharMap)
+    , mChar(0)
+    , mUnmodifiedChar(0)
+    , mDOMPrintableKeyValue(0)
 {
     // XXX Printable key's keyCode value should be computed with actual
     //     input character.
     mDOMKeyCode = (mData.key.keyCode < (ssize_t)ArrayLength(kKeyMapping)) ?
         kKeyMapping[mData.key.keyCode] : 0;
     mDOMKeyNameIndex = GetKeyNameIndex(mData.key.keyCode);
     mDOMCodeNameIndex = GetCodeNameIndex(mData.key.scanCode);
+    mDOMKeyLocation =
+        WidgetKeyboardEvent::ComputeLocationFromCodeValue(mDOMCodeNameIndex);
 
     if (!mKeyCharMap.get()) {
         return;
     }
 
     mChar = mKeyCharMap->getCharacter(mData.key.keyCode, mData.metaState);
     if (IsControlChar(mChar)) {
         mChar = 0;
@@ -303,18 +309,17 @@ KeyEventDispatcher::DispatchKeyEventInte
     event.isChar = !!event.charCode;
     event.mIsRepeat = IsRepeat();
     event.mKeyNameIndex = mDOMKeyNameIndex;
     if (mDOMPrintableKeyValue) {
         event.mKeyValue = mDOMPrintableKeyValue;
     }
     event.mCodeNameIndex = mDOMCodeNameIndex;
     event.modifiers = getDOMModifiers(mData.metaState);
-    // XXX Compute the location from code value, later.
-    event.location = nsIDOMKeyEvent::DOM_KEY_LOCATION_STANDARD;
+    event.location = mDOMKeyLocation;
     event.time = mData.timeMs;
     return nsWindow::DispatchInputEvent(event);
 }
 
 void
 KeyEventDispatcher::Dispatch()
 {
     // XXX Even if unknown key is pressed, DOM key event should be