Bug 936313 part.2 Compute DOM key location from code value on Android and Gonk r=smaug+mwu+cpeterson

This commit is contained in:
Masayuki Nakano 2015-01-28 22:36:53 +09:00
parent f1abe83b3f
commit 6e75a14df0
4 changed files with 65 additions and 7 deletions

View File

@ -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,

View File

@ -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

View File

@ -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)

View File

@ -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);
}