From 6e75a14df0f1a480ccf8183083e620b5fbfb3cfc Mon Sep 17 00:00:00 2001 From: Masayuki Nakano Date: Wed, 28 Jan 2015 22:36:53 +0900 Subject: [PATCH] Bug 936313 part.2 Compute DOM key location from code value on Android and Gonk r=smaug+mwu+cpeterson --- widget/TextEvents.h | 2 ++ widget/WidgetEventImpl.cpp | 51 +++++++++++++++++++++++++++++++++++++ widget/android/nsWindow.cpp | 4 +-- widget/gonk/nsAppShell.cpp | 15 +++++++---- 4 files changed, 65 insertions(+), 7 deletions(-) diff --git a/widget/TextEvents.h b/widget/TextEvents.h index e9ec1d22349..957a7b15ac5 100644 --- a/widget/TextEvents.h +++ b/widget/TextEvents.h @@ -180,6 +180,8 @@ public: GetDOMCodeName(mCodeNameIndex, aCodeName); } + static uint32_t ComputeLocationFromCodeValue(CodeNameIndex aCodeNameIndex); + static void GetDOMKeyName(KeyNameIndex aKeyNameIndex, nsAString& aKeyName); static void GetDOMCodeName(CodeNameIndex aCodeNameIndex, diff --git a/widget/WidgetEventImpl.cpp b/widget/WidgetEventImpl.cpp index d8b8f27a665..9386128a6ae 100644 --- a/widget/WidgetEventImpl.cpp +++ b/widget/WidgetEventImpl.cpp @@ -393,4 +393,55 @@ WidgetKeyboardEvent::GetCommandStr(Command aCommand) 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 diff --git a/widget/android/nsWindow.cpp b/widget/android/nsWindow.cpp index ad34d8a7734..7d17657f408 100644 --- a/widget/android/nsWindow.cpp +++ b/widget/android/nsWindow.cpp @@ -1540,8 +1540,8 @@ nsWindow::InitKeyEvent(WidgetKeyboardEvent& event, AndroidGeckoEvent& key, 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) diff --git a/widget/gonk/nsAppShell.cpp b/widget/gonk/nsAppShell.cpp index ebdcd7ea28d..951c59c9b97 100644 --- a/widget/gonk/nsAppShell.cpp +++ b/widget/gonk/nsAppShell.cpp @@ -212,6 +212,7 @@ private: char16_t mUnmodifiedChar; uint32_t mDOMKeyCode; + uint32_t mDOMKeyLocation; KeyNameIndex mDOMKeyNameIndex; CodeNameIndex mDOMCodeNameIndex; char16_t mDOMPrintableKeyValue; @@ -246,9 +247,12 @@ private: }; 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. @@ -256,6 +260,8 @@ KeyEventDispatcher::KeyEventDispatcher(const UserInputData& aData, kKeyMapping[mData.key.keyCode] : 0; mDOMKeyNameIndex = GetKeyNameIndex(mData.key.keyCode); mDOMCodeNameIndex = GetCodeNameIndex(mData.key.scanCode); + mDOMKeyLocation = + WidgetKeyboardEvent::ComputeLocationFromCodeValue(mDOMCodeNameIndex); if (!mKeyCharMap.get()) { return; @@ -308,8 +314,7 @@ KeyEventDispatcher::DispatchKeyEventInternal(uint32_t aEventMessage) } 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); }