Bug 432466. Allow sendNativeKeyEvent to return NS_ERROR_NOT_AVAILABLE to indicate that a keyboard layout is not available. Load keyboard layouts programmatically on Windows so we can detect whether a keyboard is available. This also makes keyboard layouts usable when they're installed but not enabled, which is true for most layouts, so we can reenable the Greek keyboard tests on tinderbox. r=karlt,a=beltzner

This commit is contained in:
roc+%cs.cmu.edu 2008-05-07 04:46:38 +00:00
Родитель 75aac49298
Коммит 1604bf1e9b
6 изменённых файлов: 42 добавлений и 33 удалений

Просмотреть файл

@ -293,9 +293,8 @@ nsDOMWindowUtils::SendNativeKeyEvent(PRInt32 aNativeKeyboardLayout,
if (!widget)
return NS_ERROR_FAILURE;
widget->SynthesizeNativeKeyEvent(aNativeKeyboardLayout, aNativeKeyCode,
return widget->SynthesizeNativeKeyEvent(aNativeKeyboardLayout, aNativeKeyCode,
aModifiers, aCharacters, aUnmodifiedCharacters);
return NS_OK;
}
nsIWidget*

Просмотреть файл

@ -95,10 +95,10 @@ typedef nsEventStatus (*PR_CALLBACK EVENT_CALLBACK)(nsGUIEvent *event);
#define NS_NATIVE_PLUGIN_PORT_CG 101
#endif
// e197eeba-a82b-46d9-8aa9-52e1133fc593
// 517a0eef-cd1c-48b3-96f0-e341a50f120d
#define NS_IWIDGET_IID \
{ 0xe197eeba, 0xa82b, 0x46d9, \
{ 0x8a, 0xa9, 0x52, 0xe1, 0x13, 0x3f, 0xc5, 0x93 } }
{ 0x517a0eef, 0xcd1c, 0x48b3, \
{ 0x96, 0xf0, 0xe3, 0x41, 0xa5, 0x0f, 0x12, 0x0d } }
// Hide the native window systems real window type so as to avoid
// including native window system types and APIs. This is necessary
@ -1096,8 +1096,10 @@ class nsIWidget : public nsISupports {
* @param aUnmodifiedCharacters characters that the OS would decide
* to generate from the event if modifier keys (other than shift)
* were assumed inactive. Needed on Mac, ignored on Windows.
* @return NS_ERROR_NOT_AVAILABLE to indicate that the keyboard
* layout is not supported and the event was not fired
*/
virtual void SynthesizeNativeKeyEvent(PRInt32 aNativeKeyboardLayout,
virtual nsresult SynthesizeNativeKeyEvent(PRInt32 aNativeKeyboardLayout,
PRInt32 aNativeKeyCode,
PRUint32 aModifierFlags,
const nsAString& aCharacters,

Просмотреть файл

@ -3556,13 +3556,18 @@ SetupKeyModifiersSequence(nsTArray<KeyPair>* aArray, PRUint32 aModifiers)
}
}
void
nsresult
nsWindow::SynthesizeNativeKeyEvent(PRInt32 aNativeKeyboardLayout,
PRInt32 aNativeKeyCode,
PRUint32 aModifierFlags,
const nsAString& aCharacters,
const nsAString& aUnmodifiedCharacters)
{
nsPrintfCString layoutName("%08x", aNativeKeyboardLayout);
HKL loadedLayout = LoadKeyboardLayoutA(layoutName.get(), KLF_NOTELLSHELL);
if (loadedLayout == NULL)
return NS_ERROR_NOT_AVAILABLE;
// Setup clean key state and load desired layout
BYTE originalKbdState[256];
::GetKeyboardState(originalKbdState);
@ -3572,7 +3577,7 @@ nsWindow::SynthesizeNativeKeyEvent(PRInt32 aNativeKeyboardLayout,
// and we'll restore it soon, so this should be OK.
::SetKeyboardState(kbdState);
HKL oldLayout = gKeyboardLayout;
gKeyboardLayout = (HKL)aNativeKeyboardLayout;
gKeyboardLayout = loadedLayout;
gKbdLayout.LoadLayout(gKeyboardLayout);
nsAutoTArray<KeyPair,10> keySequence;
@ -3616,6 +3621,9 @@ nsWindow::SynthesizeNativeKeyEvent(PRInt32 aNativeKeyboardLayout,
gKeyboardLayout = oldLayout;
gKbdLayout.LoadLayout(gKeyboardLayout);
SetupModKeyState();
UnloadKeyboardLayout(loadedLayout);
return NS_OK;
}
void nsWindow::ConstrainZLevel(HWND *aAfter)

Просмотреть файл

@ -369,7 +369,7 @@ protected:
PRBool CanTakeFocus();
virtual void SynthesizeNativeKeyEvent(PRInt32 aNativeKeyboardLayout,
virtual nsresult SynthesizeNativeKeyEvent(PRInt32 aNativeKeyboardLayout,
PRInt32 aNativeKeyCode,
PRUint32 aModifierFlags,
const nsAString& aCharacters,

Просмотреть файл

@ -156,11 +156,12 @@ protected:
return mLastRollup;
}
virtual void SynthesizeNativeKeyEvent(PRInt32 aNativeKeyboardLayout,
virtual nsresult SynthesizeNativeKeyEvent(PRInt32 aNativeKeyboardLayout,
PRInt32 aNativeKeyCode,
PRUint32 aModifierFlags,
const nsAString& aCharacters,
const nsAString& aUnmodifiedCharacters) {}
const nsAString& aUnmodifiedCharacters)
{ return NS_ERROR_UNEXPECTED; }
protected:
void* mClientData;

Просмотреть файл

@ -322,16 +322,15 @@ function runAccessKeyTests()
"A", false);
// Greek layout can activate a Latin accesskey
// tests disabled because they currently fail on tinderbox
// testKey({layout:"Greek", keyCode:65, shift:1, alt:1, chars:"A"},
// "a", true);
// testKey({layout:"Greek", keyCode:65, shift:1, alt:1, chars:"A"},
// "A", true);
testKey({layout:"Greek", keyCode:65, shift:1, alt:1, chars:"A"},
"a", true);
testKey({layout:"Greek", keyCode:65, shift:1, alt:1, chars:"A"},
"A", true);
// ... and a Greek accesskey!
// testKey({layout:"Greek", keyCode:65, shift:1, alt:1, chars:"A"},
// "\u03b1", true);
// testKey({layout:"Greek", keyCode:65, shift:1, alt:1, chars:"A"},
// "\u0391", true);
testKey({layout:"Greek", keyCode:65, shift:1, alt:1, chars:"A"},
"\u03b1", true);
testKey({layout:"Greek", keyCode:65, shift:1, alt:1, chars:"A"},
"\u0391", true);
}
button.removeEventListener("click", onClick, false);