зеркало из https://github.com/mozilla/gecko-dev.git
Bug 842927 part.5 Implement D3E KeyboardEvent.key on Cocoa r=smaug+smichaud
This commit is contained in:
Родитель
c1222e22f1
Коммит
d1f3ea50ee
|
@ -231,6 +231,13 @@ public:
|
|||
uint32_t ComputeGeckoKeyCode(UInt32 aNativeKeyCode, UInt32 aKbType,
|
||||
bool aCmdIsPressed);
|
||||
|
||||
/**
|
||||
* ComputeGeckoKeyNameIndex() returns Gecko key name index for the key.
|
||||
*
|
||||
* @param aNativeKeyCode A native keycode.
|
||||
*/
|
||||
static KeyNameIndex ComputeGeckoKeyNameIndex(UInt32 aNativeKeyCode);
|
||||
|
||||
protected:
|
||||
/**
|
||||
* TranslateToString() computes the inputted text from the native keyCode,
|
||||
|
|
|
@ -930,15 +930,38 @@ TISInputSourceWrapper::InitKeyEvent(NSEvent *aNativeKeyEvent,
|
|||
InitKeyPressEvent(aNativeKeyEvent,
|
||||
insertString.IsEmpty() ? 0 : insertString[0],
|
||||
aKeyEvent, kbType);
|
||||
return;
|
||||
} else {
|
||||
aKeyEvent.charCode = 0;
|
||||
aKeyEvent.isChar = false; // XXX not used in XP level
|
||||
|
||||
PR_LOG(gLog, PR_LOG_ALWAYS,
|
||||
("%p TISInputSourceWrapper::InitKeyEvent, keyCode=0x%X charCode=0x0",
|
||||
this, aKeyEvent.keyCode));
|
||||
}
|
||||
|
||||
aKeyEvent.charCode = 0;
|
||||
aKeyEvent.isChar = false; // XXX not used in XP level
|
||||
|
||||
PR_LOG(gLog, PR_LOG_ALWAYS,
|
||||
("%p TISInputSourceWrapper::InitKeyEvent, keyCode=0x%X charCode=0x0",
|
||||
this, aKeyEvent.keyCode));
|
||||
// Compute the key for non-printable keys and some special printable keys.
|
||||
aKeyEvent.mKeyNameIndex = ComputeGeckoKeyNameIndex(nativeKeyCode);
|
||||
if (isPrintableKey &&
|
||||
aKeyEvent.mKeyNameIndex == KEY_NAME_INDEX_Unidentified) {
|
||||
// If the key name isn't in the list and the key is a printable key but
|
||||
// inserting no characters without control key nor command key, then,
|
||||
// check if the key is dead key.
|
||||
if (insertString.IsEmpty() &&
|
||||
!aKeyEvent.IsControl() && !aKeyEvent.IsMeta()) {
|
||||
UInt32 state =
|
||||
nsCocoaUtils::ConvertToCarbonModifier([aNativeKeyEvent modifierFlags]);
|
||||
uint32_t ch = TranslateToChar(nativeKeyCode, state, kbType);
|
||||
if (ch) {
|
||||
aKeyEvent.mKeyNameIndex =
|
||||
WidgetUtils::GetDeadKeyNameIndex(static_cast<PRUnichar>(ch));
|
||||
}
|
||||
}
|
||||
// If the printable key isn't a dead key, we should set printable key name
|
||||
// for now.
|
||||
if (aKeyEvent.mKeyNameIndex == KEY_NAME_INDEX_Unidentified) {
|
||||
aKeyEvent.mKeyNameIndex = KEY_NAME_INDEX_PrintableKey;
|
||||
}
|
||||
}
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK
|
||||
}
|
||||
|
@ -1281,6 +1304,24 @@ TISInputSourceWrapper::ComputeGeckoKeyCode(UInt32 aNativeKeyCode,
|
|||
(keyCode >= NS_VK_0 && keyCode <= NS_VK_9)) ? keyCode : 0;
|
||||
}
|
||||
|
||||
// static
|
||||
KeyNameIndex
|
||||
TISInputSourceWrapper::ComputeGeckoKeyNameIndex(UInt32 aNativeKeyCode)
|
||||
{
|
||||
switch (aNativeKeyCode) {
|
||||
|
||||
#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
|
||||
|
||||
default:
|
||||
return KEY_NAME_INDEX_Unidentified;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#pragma mark -
|
||||
|
||||
|
@ -1386,8 +1427,7 @@ TextInputHandler::HandleKeyDownEvent(NSEvent* aNativeEvent)
|
|||
KeyEventState* currentKeyEvent = PushKeyEvent(aNativeEvent);
|
||||
AutoKeyEventStateCleaner remover(this);
|
||||
|
||||
BOOL nonDeadKeyPress = [[aNativeEvent characters] length] > 0;
|
||||
if (nonDeadKeyPress && !IsIMEComposing()) {
|
||||
if (!IsIMEComposing()) {
|
||||
NSResponder* firstResponder = [[mView window] firstResponder];
|
||||
|
||||
nsKeyEvent keydownEvent(true, NS_KEY_DOWN, mWidget);
|
||||
|
@ -1459,7 +1499,7 @@ TextInputHandler::HandleKeyDownEvent(NSEvent* aNativeEvent)
|
|||
"IsIMEComposing()=%s",
|
||||
this, TrueOrFalse(wasComposing), TrueOrFalse(IsIMEComposing())));
|
||||
|
||||
if (!currentKeyEvent->mKeyPressDispatched && nonDeadKeyPress &&
|
||||
if (!currentKeyEvent->mKeyPressDispatched &&
|
||||
!wasComposing && !IsIMEComposing()) {
|
||||
nsKeyEvent keypressEvent(true, NS_KEY_PRESS, mWidget);
|
||||
InitKeyEvent(aNativeEvent, keypressEvent);
|
||||
|
@ -1529,7 +1569,7 @@ TextInputHandler::HandleKeyUpEvent(NSEvent* aNativeEvent)
|
|||
}
|
||||
|
||||
// if we don't have any characters we can't generate a keyUp event
|
||||
if ([[aNativeEvent characters] length] == 0 || IsIMEComposing()) {
|
||||
if (IsIMEComposing()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -595,7 +595,7 @@ function runKeyEventTests()
|
|||
testKey({layout:"US", keyCode:MAC_VK_ANSI_E, ctrl:1, chars:"\u0005", unmodifiedChars:"e"},
|
||||
nsIDOMKeyEvent.DOM_VK_E, "e", SHOULD_DELIVER_ALL, KeyboardEvent.DOM_KEY_LOCATION_STANDARD);
|
||||
testKey({layout:"US", keyCode:MAC_VK_ANSI_E, alt:1, chars:"", unmodifiedChars:"e"},
|
||||
nsIDOMKeyEvent.DOM_VK_E, "", SHOULD_DELIVER_NONE, KeyboardEvent.DOM_KEY_LOCATION_STANDARD); // dead key
|
||||
nsIDOMKeyEvent.DOM_VK_E, "", SHOULD_DELIVER_ALL, KeyboardEvent.DOM_KEY_LOCATION_STANDARD); // dead key
|
||||
testKey({layout:"US", keyCode:MAC_VK_ANSI_E, command:1, chars:"e", unmodifiedChars:"e"},
|
||||
nsIDOMKeyEvent.DOM_VK_E, "e", SHOULD_DELIVER_KEYDOWN_KEYPRESS, KeyboardEvent.DOM_KEY_LOCATION_STANDARD);
|
||||
testKey({layout:"US", keyCode:MAC_VK_ANSI_F, chars:"f", unmodifiedChars:"f"},
|
||||
|
@ -636,7 +636,7 @@ function runKeyEventTests()
|
|||
testKey({layout:"US", keyCode:MAC_VK_ANSI_I, ctrl:1, chars:"\u0009", unmodifiedChars:"i"},
|
||||
nsIDOMKeyEvent.DOM_VK_I, "i", SHOULD_DELIVER_ALL, KeyboardEvent.DOM_KEY_LOCATION_STANDARD);
|
||||
testKey({layout:"US", keyCode:MAC_VK_ANSI_I, alt:1, chars:"", unmodifiedChars:"i"},
|
||||
nsIDOMKeyEvent.DOM_VK_I, "", SHOULD_DELIVER_NONE, KeyboardEvent.DOM_KEY_LOCATION_STANDARD); // dead key
|
||||
nsIDOMKeyEvent.DOM_VK_I, "", SHOULD_DELIVER_ALL, KeyboardEvent.DOM_KEY_LOCATION_STANDARD); // dead key
|
||||
// XXX This test causes memory leak.
|
||||
// testKey({layout:"US", keyCode:MAC_VK_ANSI_I, command:1, chars:"i", unmodifiedChars:"i"},
|
||||
// nsIDOMKeyEvent.DOM_VK_I, "i", SHOULD_DELIVER_KEYDOWN_KEYPRESS, KeyboardEvent.DOM_KEY_LOCATION_STANDARD);
|
||||
|
@ -687,7 +687,7 @@ function runKeyEventTests()
|
|||
testKey({layout:"US", keyCode:MAC_VK_ANSI_N, ctrl:1, chars:"\u000E", unmodifiedChars:"n"},
|
||||
nsIDOMKeyEvent.DOM_VK_N, "n", SHOULD_DELIVER_ALL, KeyboardEvent.DOM_KEY_LOCATION_STANDARD);
|
||||
testKey({layout:"US", keyCode:MAC_VK_ANSI_N, alt:1, chars:"", unmodifiedChars:"n"},
|
||||
nsIDOMKeyEvent.DOM_VK_N, "", SHOULD_DELIVER_NONE, KeyboardEvent.DOM_KEY_LOCATION_STANDARD); // dead key
|
||||
nsIDOMKeyEvent.DOM_VK_N, "", SHOULD_DELIVER_ALL, KeyboardEvent.DOM_KEY_LOCATION_STANDARD); // dead key
|
||||
testKey({layout:"US", keyCode:MAC_VK_ANSI_N, command:1, chars:"n", unmodifiedChars:"n"},
|
||||
nsIDOMKeyEvent.DOM_VK_N, "n", SHOULD_DELIVER_KEYDOWN_KEYPRESS, KeyboardEvent.DOM_KEY_LOCATION_STANDARD);
|
||||
testKey({layout:"US", keyCode:MAC_VK_ANSI_O, chars:"o", unmodifiedChars:"o"},
|
||||
|
@ -759,7 +759,7 @@ function runKeyEventTests()
|
|||
testKey({layout:"US", keyCode:MAC_VK_ANSI_U, ctrl:1, chars:"\u0015", unmodifiedChars:"u"},
|
||||
nsIDOMKeyEvent.DOM_VK_U, "u", SHOULD_DELIVER_ALL, KeyboardEvent.DOM_KEY_LOCATION_STANDARD);
|
||||
testKey({layout:"US", keyCode:MAC_VK_ANSI_U, alt:1, chars:"", unmodifiedChars:"u"},
|
||||
nsIDOMKeyEvent.DOM_VK_U, "", SHOULD_DELIVER_NONE, KeyboardEvent.DOM_KEY_LOCATION_STANDARD); // dead key
|
||||
nsIDOMKeyEvent.DOM_VK_U, "", SHOULD_DELIVER_ALL, KeyboardEvent.DOM_KEY_LOCATION_STANDARD); // dead key
|
||||
testKey({layout:"US", keyCode:MAC_VK_ANSI_U, command:1, chars:"u", unmodifiedChars:"u"},
|
||||
nsIDOMKeyEvent.DOM_VK_U, "u", SHOULD_DELIVER_KEYDOWN_KEYPRESS, KeyboardEvent.DOM_KEY_LOCATION_STANDARD);
|
||||
testKey({layout:"US", keyCode:MAC_VK_ANSI_V, chars:"v", unmodifiedChars:"v"},
|
||||
|
@ -923,7 +923,7 @@ function runKeyEventTests()
|
|||
testKey({layout:"US", keyCode:MAC_VK_ANSI_Grave, ctrl:1, chars:"`", unmodifiedChars:"`"},
|
||||
nsIDOMKeyEvent.DOM_VK_BACK_QUOTE, "`", SHOULD_DELIVER_ALL, KeyboardEvent.DOM_KEY_LOCATION_STANDARD);
|
||||
testKey({layout:"US", keyCode:MAC_VK_ANSI_Grave, alt:1, chars:"", unmodifiedChars:"`"},
|
||||
nsIDOMKeyEvent.DOM_VK_BACK_QUOTE, "", SHOULD_DELIVER_NONE, KeyboardEvent.DOM_KEY_LOCATION_STANDARD); // dead key
|
||||
nsIDOMKeyEvent.DOM_VK_BACK_QUOTE, "", SHOULD_DELIVER_ALL, KeyboardEvent.DOM_KEY_LOCATION_STANDARD); // dead key
|
||||
testKey({layout:"US", keyCode:MAC_VK_ANSI_Grave, command:1, chars:"`", unmodifiedChars:"`"},
|
||||
nsIDOMKeyEvent.DOM_VK_BACK_QUOTE, "`", SHOULD_DELIVER_KEYDOWN_KEYPRESS, KeyboardEvent.DOM_KEY_LOCATION_STANDARD);
|
||||
testKey({layout:"US", keyCode:MAC_VK_ANSI_Minus, chars:"-", unmodifiedChars:"-"},
|
||||
|
@ -1328,7 +1328,7 @@ function runKeyEventTests()
|
|||
testKey({layout:"Dvorak-Qwerty", keyCode:MAC_VK_ANSI_D, ctrl:1, chars:"\u0005", unmodifiedChars:"e"},
|
||||
nsIDOMKeyEvent.DOM_VK_E, "e", SHOULD_DELIVER_ALL, KeyboardEvent.DOM_KEY_LOCATION_STANDARD);
|
||||
testKey({layout:"Dvorak-Qwerty", keyCode:MAC_VK_ANSI_D, alt:1, chars:"", unmodifiedChars:"e"},
|
||||
nsIDOMKeyEvent.DOM_VK_E, "", SHOULD_DELIVER_NONE, KeyboardEvent.DOM_KEY_LOCATION_STANDARD); // dead key
|
||||
nsIDOMKeyEvent.DOM_VK_E, "", SHOULD_DELIVER_ALL, KeyboardEvent.DOM_KEY_LOCATION_STANDARD); // dead key
|
||||
testKey({layout:"Dvorak-Qwerty", keyCode:MAC_VK_ANSI_D, command:1, chars:"d", unmodifiedChars:"e"},
|
||||
nsIDOMKeyEvent.DOM_VK_D, "d", SHOULD_DELIVER_KEYDOWN_KEYPRESS, KeyboardEvent.DOM_KEY_LOCATION_STANDARD);
|
||||
testKey({layout:"Dvorak-Qwerty", keyCode:MAC_VK_ANSI_I, command:1, alt:1, chars:"^", unmodifiedChars:"c"},
|
||||
|
|
Загрузка…
Ссылка в новой задаче