diff --git a/widget/cocoa/TextInputHandler.h b/widget/cocoa/TextInputHandler.h index ce661d6e8f4..cf834b40a23 100644 --- a/widget/cocoa/TextInputHandler.h +++ b/widget/cocoa/TextInputHandler.h @@ -175,18 +175,14 @@ public: void InitByInputSourceID(const CFStringRef aID); /** * InitByLayoutID() initializes the keyboard layout by the layout ID. - * The KeyboardLayoutIdentifier (SInt32), used by Apple's now-deprecated - * Keyboard Layout Services, is no longer used by its replacement -- - * Apple's Text Input Services (TIS). All the layout IDs currently - * supported by InitByLayoutID() are backwards-compatible with the layout - * IDs used by Keyboard Layout Services. But there's no need to contine - * maintaining backwards compatibility as support for new IDs is added. * * @param aLayoutID An ID of keyboard layout. - * 0: US - * -18944: Greek - * 3: German - * 224: Swedish-Pro + * 0: US + * 1: Greek + * 2: German + * 3: Swedish-Pro + * 4: Dvorak-Qwerty Cmd + * 5: Thai * @param aOverrideKeyboard When testing set to TRUE, otherwise, set to * FALSE. When TRUE, we use an ANSI keyboard * instead of the actual keyboard. diff --git a/widget/cocoa/TextInputHandler.mm b/widget/cocoa/TextInputHandler.mm index 862f9e7cb6d..2479abc60b8 100644 --- a/widget/cocoa/TextInputHandler.mm +++ b/widget/cocoa/TextInputHandler.mm @@ -448,15 +448,21 @@ TISInputSourceWrapper::InitByLayoutID(SInt32 aLayoutID, case 0: InitByInputSourceID("com.apple.keylayout.US"); break; - case -18944: + case 1: InitByInputSourceID("com.apple.keylayout.Greek"); break; - case 3: + case 2: InitByInputSourceID("com.apple.keylayout.German"); break; - case 224: + case 3: InitByInputSourceID("com.apple.keylayout.Swedish-Pro"); break; + case 4: + InitByInputSourceID("com.apple.keylayout.DVORAK-QWERTYCMD"); + break; + case 5: + InitByInputSourceID("com.apple.keylayout.Thai"); + break; default: Clear(); break; @@ -876,8 +882,12 @@ TISInputSourceWrapper::InitKeyPressEvent(NSEvent *aNativeKeyEvent, // If the current keyboard layout is switched by the Cmd key, // we should append cmdedChar and shiftedCmdChar that are - // Latin char for the key. But don't append at Dvorak-QWERTY. - if ((cmdedChar || cmdedShiftChar) && isCmdSwitchLayout && !isDvorakQWERTY) { + // Latin char for the key. + // If the keyboard layout is Dvorak-QWERTY, we should append them only when + // command key is pressed because when command key isn't pressed, uncmded + // chars have been appended already. + if ((cmdedChar || cmdedShiftChar) && isCmdSwitchLayout && + (aKeyEvent.isMeta || !isDvorakQWERTY)) { nsAlternativeCharCode altCharCodes(cmdedChar, cmdedShiftChar); aKeyEvent.alternativeCharCodes.AppendElement(altCharCodes); } diff --git a/widget/tests/test_keycodes.xul b/widget/tests/test_keycodes.xul index aac21a41aa3..b727a3f44a8 100644 --- a/widget/tests/test_keycodes.xul +++ b/widget/tests/test_keycodes.xul @@ -73,15 +73,16 @@ function synthesizeNativeKey(aLayout, aKeyCode, aModifiers, aSystemChars, var keyboardLayouts; if (IS_MAC) { - // These constants can be found by inspecting files under - // /System/Library/Keyboard\ Layouts/Unicode.bundle/Contents/Resources/ - // XXX if you need a new keyboard layout and that uses KCHR resource, - // you need to modify GetScriptFromKeyboardLayout of nsChildView.mm + // Any unused number is okay for adding new keyboard layout. + // When you add new keyboard layout here, you need to modify + // TISInputSourceWrapper::InitByLayoutID(). keyboardLayouts = { - "US":0, - "Greek":-18944, - "German":3, - "Swedish":224 + "US": 0, + "Greek": 1, + "German": 2, + "Swedish": 3, + "Dvorak-Qwerty": 4, + "Thai": 5 }; } else if (IS_WIN) { // These constants can be found by inspecting registry keys under @@ -403,6 +404,11 @@ function runKeyEventTests() "", SHOULD_DELIVER_KEYDOWN); testKey({layout:"US", keyCode:54, commandRight:0, chars:"", unmodifiedChars:""}, "", SHOULD_DELIVER_KEYUP); + + testKey({layout:"Dvorak-Qwerty", keyCode:0x22, command:1, alt:1, chars:"^", unmodifiedChars:"c"}, + "^", SHOULD_DELIVER_KEYDOWN_KEYPRESS); + testKey({layout:"Dvorak-Qwerty", keyCode:0x22, command:1, alt:1, shift:1, chars:"\u02C6", unmodifiedChars:"C"}, + "\u02C6", SHOULD_DELIVER_KEYDOWN_KEYPRESS); } else if (IS_WIN) { // On Windows, you can use Spy++ or Winspector (free) to watch window messages.