mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-26 14:22:01 +00:00
Bug 855975 part.6 Move nsWindow::OnKeyUp() to widget::NativeKey::HandleKeyUpMessage() r=jimm
This commit is contained in:
parent
4428a65a82
commit
fc5549ae89
@ -388,31 +388,30 @@ VirtualKey::FillKbdState(PBYTE aKbdState,
|
||||
NativeKey::NativeKey(nsWindowBase* aWidget,
|
||||
const MSG& aKeyOrCharMessage,
|
||||
const ModifierKeyState& aModKeyState) :
|
||||
mWidget(aWidget), mDOMKeyCode(0), mMessage(aKeyOrCharMessage.message),
|
||||
mWidget(aWidget), mMsg(aKeyOrCharMessage), mDOMKeyCode(0),
|
||||
mModKeyState(aModKeyState), mVirtualKeyCode(0), mOriginalVirtualKeyCode(0)
|
||||
{
|
||||
MOZ_ASSERT(aWidget);
|
||||
KeyboardLayout* keyboardLayout = KeyboardLayout::GetInstance();
|
||||
mKeyboardLayout = keyboardLayout->GetLayout();
|
||||
mScanCode = WinUtils::GetScanCode(aKeyOrCharMessage.lParam);
|
||||
mIsExtended = WinUtils::IsExtendedScanCode(aKeyOrCharMessage.lParam);
|
||||
mScanCode = WinUtils::GetScanCode(mMsg.lParam);
|
||||
mIsExtended = WinUtils::IsExtendedScanCode(mMsg.lParam);
|
||||
// On WinXP and WinServer2003, we cannot compute the virtual keycode for
|
||||
// extended keys due to the API limitation.
|
||||
bool canComputeVirtualKeyCodeFromScanCode =
|
||||
(!mIsExtended || WinUtils::GetWindowsVersion() >= WinUtils::VISTA_VERSION);
|
||||
switch (mMessage) {
|
||||
switch (mMsg.message) {
|
||||
case WM_KEYDOWN:
|
||||
case WM_KEYUP:
|
||||
case WM_SYSKEYDOWN:
|
||||
case WM_SYSKEYUP: {
|
||||
// First, resolve the IME converted virtual keycode to its original
|
||||
// keycode.
|
||||
if (aKeyOrCharMessage.wParam == VK_PROCESSKEY) {
|
||||
mOriginalVirtualKeyCode = static_cast<uint8_t>(
|
||||
::ImmGetVirtualKey(mWidget->GetWindowHandle()));
|
||||
} else {
|
||||
if (mMsg.wParam == VK_PROCESSKEY) {
|
||||
mOriginalVirtualKeyCode =
|
||||
static_cast<uint8_t>(aKeyOrCharMessage.wParam);
|
||||
static_cast<uint8_t>(::ImmGetVirtualKey(mMsg.hwnd));
|
||||
} else {
|
||||
mOriginalVirtualKeyCode = static_cast<uint8_t>(mMsg.wParam);
|
||||
}
|
||||
|
||||
// Most keys are not distinguished as left or right keys.
|
||||
@ -664,6 +663,27 @@ NativeKey::InitKeyEvent(nsKeyEvent& aKeyEvent,
|
||||
{
|
||||
nsIntPoint point(0, 0);
|
||||
mWidget->InitEvent(aKeyEvent, &point);
|
||||
|
||||
switch (aKeyEvent.message) {
|
||||
case NS_KEY_DOWN:
|
||||
break;
|
||||
case NS_KEY_UP:
|
||||
aKeyEvent.keyCode = mDOMKeyCode;
|
||||
// Set defaultPrevented of the key event if the VK_MENU is not a system
|
||||
// key release, so that the menu bar does not trigger. This helps avoid
|
||||
// triggering the menu bar for ALT key accelerators used in assistive
|
||||
// technologies such as Window-Eyes and ZoomText or for switching open
|
||||
// state of IME.
|
||||
aKeyEvent.mFlags.mDefaultPrevented =
|
||||
(mOriginalVirtualKeyCode == VK_MENU && mMsg.message != WM_SYSKEYUP);
|
||||
break;
|
||||
case NS_KEY_PRESS:
|
||||
break;
|
||||
default:
|
||||
MOZ_NOT_REACHED("Invalid event message");
|
||||
break;
|
||||
}
|
||||
|
||||
aKeyEvent.mKeyNameIndex = mKeyNameIndex;
|
||||
aKeyEvent.location = GetKeyLocation();
|
||||
aModKeyState.InitInputEvent(aKeyEvent);
|
||||
@ -687,6 +707,29 @@ NativeKey::DispatchKeyEvent(nsKeyEvent& aKeyEvent,
|
||||
return mWidget->DispatchWindowEvent(&aKeyEvent);
|
||||
}
|
||||
|
||||
bool
|
||||
NativeKey::HandleKeyUpMessage(bool* aEventDispatched) const
|
||||
{
|
||||
MOZ_ASSERT(mMsg.message == WM_KEYUP || mMsg.message == WM_SYSKEYUP);
|
||||
|
||||
if (aEventDispatched) {
|
||||
*aEventDispatched = false;
|
||||
}
|
||||
|
||||
// Ignore [shift+]alt+space so the OS can handle it.
|
||||
if (mModKeyState.IsAlt() && !mModKeyState.IsControl() &&
|
||||
mVirtualKeyCode == VK_SPACE) {
|
||||
return false;
|
||||
}
|
||||
|
||||
nsKeyEvent keyupEvent(true, NS_KEY_UP, mWidget);
|
||||
InitKeyEvent(keyupEvent, mModKeyState);
|
||||
if (aEventDispatched) {
|
||||
*aEventDispatched = true;
|
||||
}
|
||||
return DispatchKeyEvent(keyupEvent, &mMsg);
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
* mozilla::widget::KeyboardLayout
|
||||
*****************************************************************************/
|
||||
|
@ -290,10 +290,10 @@ public:
|
||||
return mCommittedCharsAndModifiers;
|
||||
}
|
||||
|
||||
UINT GetMessage() const { return mMessage; }
|
||||
UINT GetMessage() const { return mMsg.message; }
|
||||
bool IsKeyDownMessage() const
|
||||
{
|
||||
return (mMessage == WM_KEYDOWN || mMessage == WM_SYSKEYDOWN);
|
||||
return (mMsg.message == WM_KEYDOWN || mMsg.message == WM_SYSKEYDOWN);
|
||||
}
|
||||
WORD GetScanCode() const { return mScanCode; }
|
||||
uint8_t GetVirtualKeyCode() const { return mVirtualKeyCode; }
|
||||
@ -331,15 +331,20 @@ public:
|
||||
bool DispatchKeyEvent(nsKeyEvent& aKeyEvent,
|
||||
const MSG* aMsgSentToPlugin = nullptr) const;
|
||||
|
||||
/**
|
||||
* Handles keyup message. Returns true if the event is consumed.
|
||||
* Otherwise, false.
|
||||
*/
|
||||
bool HandleKeyUpMessage(bool* aEventDispatched = nullptr) const;
|
||||
|
||||
private:
|
||||
nsRefPtr<nsWindowBase> mWidget;
|
||||
HKL mKeyboardLayout;
|
||||
MSG mMsg;
|
||||
|
||||
uint32_t mDOMKeyCode;
|
||||
KeyNameIndex mKeyNameIndex;
|
||||
|
||||
// The message which the instance was initialized with.
|
||||
UINT mMessage;
|
||||
|
||||
ModifierKeyState mModKeyState;
|
||||
|
||||
// mVirtualKeyCode distinguishes left key or right key of modifier key.
|
||||
|
@ -5634,34 +5634,13 @@ LRESULT nsWindow::ProcessCharMessage(const MSG &aMsg, bool *aEventDispatched)
|
||||
|
||||
LRESULT nsWindow::ProcessKeyUpMessage(const MSG &aMsg, bool *aEventDispatched)
|
||||
{
|
||||
NS_PRECONDITION(aMsg.message == WM_KEYUP || aMsg.message == WM_SYSKEYUP,
|
||||
"message is not keydown event");
|
||||
PR_LOG(gWindowsLog, PR_LOG_ALWAYS,
|
||||
("%s VK=%d\n", aMsg.message == WM_SYSKEYDOWN ?
|
||||
"WM_SYSKEYUP" : "WM_KEYUP", aMsg.wParam));
|
||||
if (IMEHandler::IsComposingOn(this)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
ModifierKeyState modKeyState;
|
||||
|
||||
// Note: the original code passed (HIWORD(lParam)) to OnKeyUp as
|
||||
// scan code. However, this breaks Alt+Num pad input.
|
||||
// MSDN states the following:
|
||||
// Typically, ToAscii performs the translation based on the
|
||||
// virtual-key code. In some cases, however, bit 15 of the
|
||||
// uScanCode parameter may be used to distinguish between a key
|
||||
// press and a key release. The scan code is used for
|
||||
// translating ALT+number key combinations.
|
||||
|
||||
// ignore [shift+]alt+space so the OS can handle it
|
||||
if (modKeyState.IsAlt() && !modKeyState.IsControl() &&
|
||||
IS_VK_DOWN(NS_VK_SPACE)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!IMEHandler::IsComposingOn(this)) {
|
||||
return OnKeyUp(aMsg, modKeyState, aEventDispatched);
|
||||
}
|
||||
|
||||
return 0;
|
||||
NativeKey nativeKey(this, aMsg, modKeyState);
|
||||
return static_cast<LRESULT>(nativeKey.HandleKeyUpMessage(aEventDispatched));
|
||||
}
|
||||
|
||||
LRESULT nsWindow::ProcessKeyDownMessage(const MSG &aMsg,
|
||||
@ -5890,7 +5869,8 @@ nsWindow::SynthesizeNativeKeyEvent(int32_t aNativeKeyboardLayout,
|
||||
lParam |= 0x1000000;
|
||||
}
|
||||
MSG msg = WinUtils::InitMSG(WM_KEYUP, key, lParam);
|
||||
OnKeyUp(msg, modKeyState, nullptr);
|
||||
NativeKey nativeKey(this, msg, modKeyState);
|
||||
nativeKey.HandleKeyUpMessage();
|
||||
}
|
||||
|
||||
// Restore old key state and layout
|
||||
@ -6780,31 +6760,6 @@ LRESULT nsWindow::OnKeyDown(const MSG &aMsg,
|
||||
return noDefault;
|
||||
}
|
||||
|
||||
// OnKeyUp
|
||||
LRESULT nsWindow::OnKeyUp(const MSG &aMsg,
|
||||
const ModifierKeyState &aModKeyState,
|
||||
bool *aEventDispatched)
|
||||
{
|
||||
// NOTE: VK_PROCESSKEY never comes with WM_KEYUP
|
||||
PR_LOG(gWindowsLog, PR_LOG_ALWAYS,
|
||||
("nsWindow::OnKeyUp wParam(VK)=%d\n", aMsg.wParam));
|
||||
|
||||
if (aEventDispatched)
|
||||
*aEventDispatched = true;
|
||||
nsKeyEvent keyupEvent(true, NS_KEY_UP, this);
|
||||
NativeKey nativeKey(this, aMsg, aModKeyState);
|
||||
keyupEvent.keyCode = nativeKey.GetDOMKeyCode();
|
||||
nativeKey.InitKeyEvent(keyupEvent);
|
||||
// Set defaultPrevented of the key event if the VK_MENU is not a system key
|
||||
// release, so that the menu bar does not trigger. This helps avoid
|
||||
// triggering the menu bar for ALT key accelerators used in assistive
|
||||
// technologies such as Window-Eyes and ZoomText or for switching open state
|
||||
// of IME.
|
||||
keyupEvent.mFlags.mDefaultPrevented =
|
||||
(aMsg.wParam == VK_MENU && aMsg.message != WM_SYSKEYUP);
|
||||
return nativeKey.DispatchKeyEvent(keyupEvent, &aMsg);
|
||||
}
|
||||
|
||||
// OnChar
|
||||
LRESULT nsWindow::OnChar(const MSG &aMsg,
|
||||
const NativeKey& aNativeKey,
|
||||
|
@ -377,9 +377,6 @@ protected:
|
||||
const mozilla::widget::ModifierKeyState &aModKeyState,
|
||||
bool *aEventDispatched,
|
||||
nsFakeCharMessage* aFakeCharMessage);
|
||||
LRESULT OnKeyUp(const MSG &aMsg,
|
||||
const mozilla::widget::ModifierKeyState &aModKeyState,
|
||||
bool *aEventDispatched);
|
||||
bool OnGesture(WPARAM wParam, LPARAM lParam);
|
||||
bool OnTouch(WPARAM wParam, LPARAM lParam);
|
||||
bool OnHotKey(WPARAM wParam, LPARAM lParam);
|
||||
|
Loading…
Reference in New Issue
Block a user