2006-01-07 21:46:46 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2006-01-07 21:46:46 +03:00
|
|
|
|
2010-07-27 16:47:42 +04:00
|
|
|
#ifndef KeyboardLayout_h__
|
|
|
|
#define KeyboardLayout_h__
|
2006-01-07 21:46:46 +03:00
|
|
|
|
2016-04-19 23:51:25 +03:00
|
|
|
#include "mozilla/RefPtr.h"
|
2006-01-07 21:46:46 +03:00
|
|
|
#include "nscore.h"
|
2012-06-15 13:52:51 +04:00
|
|
|
#include "nsString.h"
|
2013-05-29 10:34:47 +04:00
|
|
|
#include "nsWindowBase.h"
|
2013-05-30 13:52:14 +04:00
|
|
|
#include "nsWindowDefs.h"
|
2013-10-22 17:27:36 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
|
|
|
#include "mozilla/EventForwards.h"
|
2016-03-16 07:47:49 +03:00
|
|
|
#include "mozilla/TextEventDispatcher.h"
|
2016-04-15 11:02:36 +03:00
|
|
|
#include "mozilla/widget/WinMessages.h"
|
2016-04-09 09:45:06 +03:00
|
|
|
#include "mozilla/widget/WinModifierKeyState.h"
|
2006-01-07 21:46:46 +03:00
|
|
|
#include <windows.h>
|
|
|
|
|
2013-07-25 10:04:17 +04:00
|
|
|
#define NS_NUM_OF_KEYS 70
|
2010-07-27 16:50:21 +04:00
|
|
|
|
2006-01-07 21:46:46 +03:00
|
|
|
#define VK_OEM_1 0xBA // ';:' for US
|
|
|
|
#define VK_OEM_PLUS 0xBB // '+' any country
|
2012-05-17 11:04:16 +04:00
|
|
|
#define VK_OEM_COMMA 0xBC
|
2006-01-07 21:46:46 +03:00
|
|
|
#define VK_OEM_MINUS 0xBD // '-' any country
|
2012-05-17 11:04:16 +04:00
|
|
|
#define VK_OEM_PERIOD 0xBE
|
|
|
|
#define VK_OEM_2 0xBF
|
|
|
|
#define VK_OEM_3 0xC0
|
2013-05-01 03:19:04 +04:00
|
|
|
// '/?' for Brazilian (ABNT)
|
|
|
|
#define VK_ABNT_C1 0xC1
|
|
|
|
// Separator in Numpad for Brazilian (ABNT) or JIS keyboard for Mac.
|
|
|
|
#define VK_ABNT_C2 0xC2
|
2012-05-17 11:04:16 +04:00
|
|
|
#define VK_OEM_4 0xDB
|
|
|
|
#define VK_OEM_5 0xDC
|
|
|
|
#define VK_OEM_6 0xDD
|
|
|
|
#define VK_OEM_7 0xDE
|
|
|
|
#define VK_OEM_8 0xDF
|
|
|
|
#define VK_OEM_102 0xE2
|
|
|
|
#define VK_OEM_CLEAR 0xFE
|
2006-01-07 21:46:46 +03:00
|
|
|
|
2013-05-29 10:34:47 +04:00
|
|
|
class nsIIdleServiceInternal;
|
2012-05-05 02:47:46 +04:00
|
|
|
|
2010-07-27 16:47:42 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace widget {
|
2006-01-07 21:46:46 +03:00
|
|
|
|
2013-05-29 10:34:49 +04:00
|
|
|
static const uint32_t sModifierKeyMap[][3] = {
|
|
|
|
{ nsIWidget::CAPS_LOCK, VK_CAPITAL, 0 },
|
|
|
|
{ nsIWidget::NUM_LOCK, VK_NUMLOCK, 0 },
|
|
|
|
{ nsIWidget::SHIFT_L, VK_SHIFT, VK_LSHIFT },
|
|
|
|
{ nsIWidget::SHIFT_R, VK_SHIFT, VK_RSHIFT },
|
|
|
|
{ nsIWidget::CTRL_L, VK_CONTROL, VK_LCONTROL },
|
|
|
|
{ nsIWidget::CTRL_R, VK_CONTROL, VK_RCONTROL },
|
|
|
|
{ nsIWidget::ALT_L, VK_MENU, VK_LMENU },
|
|
|
|
{ nsIWidget::ALT_R, VK_MENU, VK_RMENU }
|
|
|
|
};
|
|
|
|
|
2012-05-17 11:04:16 +04:00
|
|
|
class KeyboardLayout;
|
|
|
|
|
2016-10-07 06:04:49 +03:00
|
|
|
class UniCharsAndModifiers final
|
2012-06-15 13:52:50 +04:00
|
|
|
{
|
2016-10-07 06:04:49 +03:00
|
|
|
public:
|
2012-06-15 13:52:50 +04:00
|
|
|
// Dead-key + up to 4 characters
|
|
|
|
Modifiers mModifiers[5];
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t mLength;
|
2012-06-15 13:52:50 +04:00
|
|
|
|
|
|
|
UniCharsAndModifiers() : mLength(0) {}
|
|
|
|
UniCharsAndModifiers operator+(const UniCharsAndModifiers& aOther) const;
|
|
|
|
UniCharsAndModifiers& operator+=(const UniCharsAndModifiers& aOther);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Append a pair of unicode character and the final modifier.
|
|
|
|
*/
|
2014-01-04 19:02:17 +04:00
|
|
|
void Append(char16_t aUniChar, Modifiers aModifiers);
|
2012-06-15 13:52:50 +04:00
|
|
|
void Clear() { mLength = 0; }
|
2013-05-29 10:34:48 +04:00
|
|
|
bool IsEmpty() const { return !mLength; }
|
2012-06-15 13:52:50 +04:00
|
|
|
|
2016-10-07 06:04:49 +03:00
|
|
|
char16_t CharAt(size_t aIndex) const
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aIndex < mLength);
|
|
|
|
return mChars[aIndex];
|
|
|
|
}
|
2012-06-15 13:52:50 +04:00
|
|
|
void FillModifiers(Modifiers aModifiers);
|
|
|
|
|
|
|
|
bool UniCharsEqual(const UniCharsAndModifiers& aOther) const;
|
|
|
|
bool UniCharsCaseInsensitiveEqual(const UniCharsAndModifiers& aOther) const;
|
2016-10-07 05:36:34 +03:00
|
|
|
bool BeginsWith(const UniCharsAndModifiers& aOther) const;
|
2012-06-15 13:52:51 +04:00
|
|
|
|
|
|
|
nsString ToString() const { return nsString(mChars, mLength); }
|
2016-10-07 06:04:49 +03:00
|
|
|
|
|
|
|
private:
|
|
|
|
char16_t mChars[5];
|
2012-06-15 13:52:50 +04:00
|
|
|
};
|
|
|
|
|
2006-01-07 21:46:46 +03:00
|
|
|
struct DeadKeyEntry;
|
|
|
|
class DeadKeyTable;
|
|
|
|
|
|
|
|
|
2010-07-22 06:11:34 +04:00
|
|
|
class VirtualKey
|
2006-01-07 21:46:46 +03:00
|
|
|
{
|
2012-06-15 13:52:50 +04:00
|
|
|
public:
|
|
|
|
// 0 - Normal
|
|
|
|
// 1 - Shift
|
|
|
|
// 2 - Control
|
|
|
|
// 3 - Control + Shift
|
|
|
|
// 4 - Alt
|
|
|
|
// 5 - Alt + Shift
|
|
|
|
// 6 - Alt + Control (AltGr)
|
|
|
|
// 7 - Alt + Control + Shift (AltGr + Shift)
|
|
|
|
// 8 - CapsLock
|
|
|
|
// 9 - CapsLock + Shift
|
|
|
|
// 10 - CapsLock + Control
|
|
|
|
// 11 - CapsLock + Control + Shift
|
|
|
|
// 12 - CapsLock + Alt
|
|
|
|
// 13 - CapsLock + Alt + Shift
|
|
|
|
// 14 - CapsLock + Alt + Control (CapsLock + AltGr)
|
|
|
|
// 15 - CapsLock + Alt + Control + Shift (CapsLock + AltGr + Shift)
|
|
|
|
|
|
|
|
enum ShiftStateFlag
|
|
|
|
{
|
|
|
|
STATE_SHIFT = 0x01,
|
|
|
|
STATE_CONTROL = 0x02,
|
|
|
|
STATE_ALT = 0x04,
|
|
|
|
STATE_CAPSLOCK = 0x08
|
|
|
|
};
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
typedef uint8_t ShiftState;
|
2012-06-15 13:52:50 +04:00
|
|
|
|
2013-10-22 17:27:36 +04:00
|
|
|
static ShiftState ModifiersToShiftState(Modifiers aModifiers);
|
2016-09-30 09:32:10 +03:00
|
|
|
static ShiftState ModifierKeyStateToShiftState(
|
|
|
|
const ModifierKeyState& aModKeyState)
|
|
|
|
{
|
|
|
|
return ModifiersToShiftState(aModKeyState.GetModifiers());
|
|
|
|
}
|
2013-10-22 17:27:36 +04:00
|
|
|
static Modifiers ShiftStateToModifiers(ShiftState aShiftState);
|
2012-06-15 13:52:50 +04:00
|
|
|
|
|
|
|
private:
|
2006-01-07 21:46:46 +03:00
|
|
|
union KeyShiftState
|
|
|
|
{
|
|
|
|
struct
|
|
|
|
{
|
2014-01-04 19:02:17 +04:00
|
|
|
char16_t Chars[4];
|
2006-01-07 21:46:46 +03:00
|
|
|
} Normal;
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
const DeadKeyTable* Table;
|
2014-01-04 19:02:17 +04:00
|
|
|
char16_t DeadChar;
|
2006-01-07 21:46:46 +03:00
|
|
|
} DeadKey;
|
|
|
|
};
|
|
|
|
|
2010-07-27 16:48:59 +04:00
|
|
|
KeyShiftState mShiftStates[16];
|
2012-08-22 19:56:38 +04:00
|
|
|
uint16_t mIsDeadKey;
|
2006-01-07 21:46:46 +03:00
|
|
|
|
2012-06-15 13:52:50 +04:00
|
|
|
void SetDeadKey(ShiftState aShiftState, bool aIsDeadKey)
|
2006-01-07 21:46:46 +03:00
|
|
|
{
|
2010-07-27 16:49:37 +04:00
|
|
|
if (aIsDeadKey) {
|
2006-01-07 21:46:46 +03:00
|
|
|
mIsDeadKey |= 1 << aShiftState;
|
2010-07-27 16:49:37 +04:00
|
|
|
} else {
|
2006-01-07 21:46:46 +03:00
|
|
|
mIsDeadKey &= ~(1 << aShiftState);
|
2010-07-27 16:49:37 +04:00
|
|
|
}
|
2006-01-07 21:46:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
2012-06-15 13:52:50 +04:00
|
|
|
static void FillKbdState(PBYTE aKbdState, const ShiftState aShiftState);
|
|
|
|
|
2012-06-15 13:52:50 +04:00
|
|
|
bool IsDeadKey(ShiftState aShiftState) const
|
2006-01-07 21:46:46 +03:00
|
|
|
{
|
|
|
|
return (mIsDeadKey & (1 << aShiftState)) != 0;
|
|
|
|
}
|
|
|
|
|
2012-06-15 13:52:50 +04:00
|
|
|
void AttachDeadKeyTable(ShiftState aShiftState,
|
2010-07-27 16:48:59 +04:00
|
|
|
const DeadKeyTable* aDeadKeyTable)
|
2006-01-07 21:46:46 +03:00
|
|
|
{
|
2010-07-27 16:48:59 +04:00
|
|
|
mShiftStates[aShiftState].DeadKey.Table = aDeadKeyTable;
|
2006-01-07 21:46:46 +03:00
|
|
|
}
|
|
|
|
|
2014-01-04 19:02:17 +04:00
|
|
|
void SetNormalChars(ShiftState aShiftState, const char16_t* aChars,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aNumOfChars);
|
2014-01-04 19:02:17 +04:00
|
|
|
void SetDeadChar(ShiftState aShiftState, char16_t aDeadChar);
|
2010-07-27 16:48:59 +04:00
|
|
|
const DeadKeyTable* MatchingDeadKeyTable(const DeadKeyEntry* aDeadKeyArray,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aEntries) const;
|
2014-01-04 19:02:17 +04:00
|
|
|
inline char16_t GetCompositeChar(ShiftState aShiftState,
|
|
|
|
char16_t aBaseChar) const;
|
2016-09-30 09:32:10 +03:00
|
|
|
char16_t GetCompositeChar(const ModifierKeyState& aModKeyState,
|
|
|
|
char16_t aBaseChar) const
|
|
|
|
{
|
|
|
|
return GetCompositeChar(ModifierKeyStateToShiftState(aModKeyState),
|
|
|
|
aBaseChar);
|
|
|
|
}
|
2012-06-15 13:52:50 +04:00
|
|
|
UniCharsAndModifiers GetNativeUniChars(ShiftState aShiftState) const;
|
2016-09-30 09:32:10 +03:00
|
|
|
UniCharsAndModifiers GetNativeUniChars(
|
|
|
|
const ModifierKeyState& aModKeyState) const
|
|
|
|
{
|
|
|
|
return GetNativeUniChars(ModifierKeyStateToShiftState(aModKeyState));
|
|
|
|
}
|
2012-06-15 13:52:50 +04:00
|
|
|
UniCharsAndModifiers GetUniChars(ShiftState aShiftState) const;
|
2016-09-30 09:32:10 +03:00
|
|
|
UniCharsAndModifiers GetUniChars(const ModifierKeyState& aModKeyState) const
|
|
|
|
{
|
|
|
|
return GetUniChars(ModifierKeyStateToShiftState(aModKeyState));
|
|
|
|
}
|
2006-01-07 21:46:46 +03:00
|
|
|
};
|
|
|
|
|
2016-04-15 11:02:36 +03:00
|
|
|
class MOZ_STACK_CLASS NativeKey final
|
2013-05-29 10:34:47 +04:00
|
|
|
{
|
|
|
|
friend class KeyboardLayout;
|
2012-05-03 12:35:02 +04:00
|
|
|
|
2013-05-29 10:34:47 +04:00
|
|
|
public:
|
2013-05-29 10:34:49 +04:00
|
|
|
struct FakeCharMsg
|
|
|
|
{
|
|
|
|
UINT mCharCode;
|
|
|
|
UINT mScanCode;
|
2016-08-31 10:42:27 +03:00
|
|
|
bool mIsSysKey;
|
2013-05-29 10:34:49 +04:00
|
|
|
bool mIsDeadKey;
|
2013-08-14 06:09:38 +04:00
|
|
|
bool mConsumed;
|
|
|
|
|
2016-08-31 10:42:27 +03:00
|
|
|
FakeCharMsg()
|
|
|
|
: mCharCode(0)
|
|
|
|
, mScanCode(0)
|
|
|
|
, mIsSysKey(false)
|
|
|
|
, mIsDeadKey(false)
|
|
|
|
, mConsumed(false)
|
2013-08-14 06:09:38 +04:00
|
|
|
{
|
|
|
|
}
|
2013-05-29 10:34:49 +04:00
|
|
|
|
|
|
|
MSG GetCharMsg(HWND aWnd) const
|
|
|
|
{
|
|
|
|
MSG msg;
|
|
|
|
msg.hwnd = aWnd;
|
2016-08-31 10:42:27 +03:00
|
|
|
msg.message = mIsDeadKey && mIsSysKey ? WM_SYSDEADCHAR :
|
|
|
|
mIsDeadKey ? WM_DEADCHAR :
|
|
|
|
mIsSysKey ? WM_SYSCHAR :
|
|
|
|
WM_CHAR;
|
2013-05-29 10:34:49 +04:00
|
|
|
msg.wParam = static_cast<WPARAM>(mCharCode);
|
2013-08-14 06:09:38 +04:00
|
|
|
msg.lParam = static_cast<LPARAM>(mScanCode << 16);
|
2013-05-29 10:34:49 +04:00
|
|
|
msg.time = 0;
|
|
|
|
msg.pt.x = msg.pt.y = 0;
|
|
|
|
return msg;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-05-29 10:34:47 +04:00
|
|
|
NativeKey(nsWindowBase* aWidget,
|
2014-12-30 04:47:56 +03:00
|
|
|
const MSG& aMessage,
|
2013-05-29 10:34:48 +04:00
|
|
|
const ModifierKeyState& aModKeyState,
|
2016-04-15 11:02:36 +03:00
|
|
|
HKL aOverrideKeyboardLayout = 0,
|
2013-08-14 06:09:38 +04:00
|
|
|
nsTArray<FakeCharMsg>* aFakeCharMsgs = nullptr);
|
2012-05-03 12:35:02 +04:00
|
|
|
|
2016-04-15 11:02:36 +03:00
|
|
|
~NativeKey();
|
|
|
|
|
2013-05-29 10:34:49 +04:00
|
|
|
/**
|
|
|
|
* Handle WM_KEYDOWN message or WM_SYSKEYDOWN message. The instance must be
|
|
|
|
* initialized with WM_KEYDOWN or WM_SYSKEYDOWN.
|
|
|
|
* Returns true if dispatched keydown event or keypress event is consumed.
|
|
|
|
* Otherwise, false.
|
|
|
|
*/
|
2013-08-14 06:09:38 +04:00
|
|
|
bool HandleKeyDownMessage(bool* aEventDispatched = nullptr) const;
|
2013-05-29 10:34:49 +04:00
|
|
|
|
2013-05-29 10:34:48 +04:00
|
|
|
/**
|
|
|
|
* Handles WM_CHAR message or WM_SYSCHAR message. The instance must be
|
2016-10-03 17:55:14 +03:00
|
|
|
* initialized with them.
|
2013-05-29 10:34:48 +04:00
|
|
|
* Returns true if dispatched keypress event is consumed. Otherwise, false.
|
|
|
|
*/
|
2016-10-03 17:55:14 +03:00
|
|
|
bool HandleCharMessage(bool* aEventDispatched = nullptr) const;
|
2013-05-29 10:34:48 +04:00
|
|
|
|
2013-05-29 10:34:47 +04:00
|
|
|
/**
|
|
|
|
* Handles keyup message. Returns true if the event is consumed.
|
|
|
|
* Otherwise, false.
|
|
|
|
*/
|
|
|
|
bool HandleKeyUpMessage(bool* aEventDispatched = nullptr) const;
|
|
|
|
|
2014-12-30 04:47:56 +03:00
|
|
|
/**
|
|
|
|
* Handles WM_APPCOMMAND message. Returns true if the event is consumed.
|
|
|
|
* Otherwise, false.
|
|
|
|
*/
|
|
|
|
bool HandleAppCommandMessage() const;
|
|
|
|
|
2016-03-16 07:47:49 +03:00
|
|
|
/**
|
|
|
|
* Callback of TextEventDispatcherListener::WillDispatchKeyboardEvent().
|
|
|
|
* This method sets alternative char codes of aKeyboardEvent.
|
|
|
|
*/
|
|
|
|
void WillDispatchKeyboardEvent(WidgetKeyboardEvent& aKeyboardEvent,
|
|
|
|
uint32_t aIndex);
|
|
|
|
|
2016-08-22 08:23:59 +03:00
|
|
|
/**
|
|
|
|
* Returns true if aChar is a control character which shouldn't be inputted
|
|
|
|
* into focused text editor.
|
|
|
|
*/
|
|
|
|
static bool IsControlChar(char16_t aChar);
|
|
|
|
|
2012-05-03 12:35:02 +04:00
|
|
|
private:
|
2016-09-15 11:02:30 +03:00
|
|
|
NativeKey* mLastInstance;
|
2016-09-23 10:40:01 +03:00
|
|
|
// mRemovingMsg is set at removing a char message from
|
|
|
|
// GetFollowingCharMessage().
|
|
|
|
MSG mRemovingMsg;
|
|
|
|
// mReceivedMsg is set when another instance starts to handle the message
|
|
|
|
// unexpectedly.
|
|
|
|
MSG mReceivedMsg;
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsWindowBase> mWidget;
|
2016-03-16 07:47:49 +03:00
|
|
|
RefPtr<TextEventDispatcher> mDispatcher;
|
2013-05-29 10:34:47 +04:00
|
|
|
HKL mKeyboardLayout;
|
2013-05-29 10:34:47 +04:00
|
|
|
MSG mMsg;
|
2016-09-14 18:02:15 +03:00
|
|
|
// mFollowingCharMsgs stores WM_CHAR, WM_SYSCHAR, WM_DEADCHAR or
|
|
|
|
// WM_SYSDEADCHAR message which follows WM_KEYDOWN.
|
|
|
|
// Note that the stored messaged are already removed from the queue.
|
|
|
|
nsTArray<MSG> mFollowingCharMsgs;
|
2016-09-14 10:20:53 +03:00
|
|
|
// mRemovedOddCharMsgs stores WM_CHAR messages which are caused by ATOK or
|
|
|
|
// WXG (they are Japanese IME) when the user tries to do "Kakutei-undo"
|
|
|
|
// (it means "undo the last commit").
|
|
|
|
nsTArray<MSG> mRemovedOddCharMsgs;
|
2016-09-05 12:56:34 +03:00
|
|
|
// If dispatching eKeyDown or eKeyPress event causes focus change,
|
|
|
|
// the instance shouldn't handle remaning char messages. For checking it,
|
|
|
|
// this should store first focused window.
|
|
|
|
HWND mFocusedWndBeforeDispatch;
|
2013-05-29 10:34:47 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t mDOMKeyCode;
|
2013-04-24 07:49:47 +04:00
|
|
|
KeyNameIndex mKeyNameIndex;
|
2014-05-25 06:08:59 +04:00
|
|
|
CodeNameIndex mCodeNameIndex;
|
2013-04-24 07:49:47 +04:00
|
|
|
|
2013-05-29 10:34:47 +04:00
|
|
|
ModifierKeyState mModKeyState;
|
|
|
|
|
2012-05-03 12:35:02 +04:00
|
|
|
// mVirtualKeyCode distinguishes left key or right key of modifier key.
|
2012-08-22 19:56:38 +04:00
|
|
|
uint8_t mVirtualKeyCode;
|
2012-05-03 12:35:02 +04:00
|
|
|
// mOriginalVirtualKeyCode doesn't distinguish left key or right key of
|
|
|
|
// modifier key. However, if the given keycode is VK_PROCESS, it's resolved
|
|
|
|
// to a keycode before it's handled by IME.
|
2012-08-22 19:56:38 +04:00
|
|
|
uint8_t mOriginalVirtualKeyCode;
|
2013-04-24 07:49:47 +04:00
|
|
|
|
|
|
|
// mCommittedChars indicates the inputted characters which is committed by
|
|
|
|
// the key. If dead key fail to composite a character, mCommittedChars
|
|
|
|
// indicates both the dead characters and the base characters.
|
|
|
|
UniCharsAndModifiers mCommittedCharsAndModifiers;
|
|
|
|
|
2016-03-16 07:47:49 +03:00
|
|
|
// Following strings are computed by
|
|
|
|
// ComputeInputtingStringWithKeyboardLayout() which is typically called
|
|
|
|
// before dispatching keydown event.
|
|
|
|
// mInputtingStringAndModifiers's string is the string to be
|
|
|
|
// inputted into the focused editor and its modifier state is proper
|
|
|
|
// modifier state for inputting the string into the editor.
|
2016-03-16 07:47:49 +03:00
|
|
|
UniCharsAndModifiers mInputtingStringAndModifiers;
|
2016-03-16 07:47:49 +03:00
|
|
|
// mShiftedString is the string to be inputted into the editor with
|
|
|
|
// current modifier state with active shift state.
|
2016-03-16 07:47:49 +03:00
|
|
|
UniCharsAndModifiers mShiftedString;
|
2016-03-16 07:47:49 +03:00
|
|
|
// mUnshiftedString is the string to be inputted into the editor with
|
|
|
|
// current modifier state without shift state.
|
2016-03-16 07:47:49 +03:00
|
|
|
UniCharsAndModifiers mUnshiftedString;
|
2016-03-16 07:47:49 +03:00
|
|
|
// Following integers are computed by
|
|
|
|
// ComputeInputtingStringWithKeyboardLayout() which is typically called
|
|
|
|
// before dispatching keydown event. The meaning of these values is same
|
|
|
|
// as charCode.
|
2016-03-16 07:47:49 +03:00
|
|
|
uint32_t mShiftedLatinChar;
|
|
|
|
uint32_t mUnshiftedLatinChar;
|
2016-03-16 07:47:49 +03:00
|
|
|
|
2012-05-03 12:35:02 +04:00
|
|
|
WORD mScanCode;
|
|
|
|
bool mIsExtended;
|
2013-05-29 10:34:48 +04:00
|
|
|
bool mIsDeadKey;
|
2013-05-29 10:34:49 +04:00
|
|
|
// mIsPrintableKey is true if the key may be a printable key without
|
|
|
|
// any modifier keys. Otherwise, false.
|
|
|
|
// Please note that the event may not cause any text input even if this
|
|
|
|
// is true. E.g., it might be dead key state or Ctrl key may be pressed.
|
2013-05-29 10:34:48 +04:00
|
|
|
bool mIsPrintableKey;
|
2016-04-15 11:02:36 +03:00
|
|
|
// mIsOverridingKeyboardLayout is true if the instance temporarily overriding
|
|
|
|
// keyboard layout with specified by the constructor.
|
|
|
|
bool mIsOverridingKeyboardLayout;
|
2013-08-14 06:09:38 +04:00
|
|
|
|
|
|
|
nsTArray<FakeCharMsg>* mFakeCharMsgs;
|
2012-05-03 12:35:02 +04:00
|
|
|
|
2014-12-30 04:47:56 +03:00
|
|
|
// When a keydown event is dispatched at handling WM_APPCOMMAND, the computed
|
|
|
|
// virtual keycode is set to this. Even if we consume WM_APPCOMMAND message,
|
|
|
|
// Windows may send WM_KEYDOWN and WM_KEYUP message for them.
|
|
|
|
// At that time, we should not dispatch key events for them.
|
|
|
|
static uint8_t sDispatchedKeyOfAppCommand;
|
|
|
|
|
2013-05-29 10:34:47 +04:00
|
|
|
NativeKey()
|
|
|
|
{
|
2013-06-29 05:38:30 +04:00
|
|
|
MOZ_CRASH("The default constructor of NativeKey isn't available");
|
2013-05-29 10:34:47 +04:00
|
|
|
}
|
2013-04-24 07:49:47 +04:00
|
|
|
|
2014-12-30 04:47:56 +03:00
|
|
|
void InitWithAppCommand();
|
2016-09-21 07:29:34 +03:00
|
|
|
void InitWithKeyChar();
|
2014-12-30 04:47:56 +03:00
|
|
|
|
2016-10-07 05:36:34 +03:00
|
|
|
/**
|
|
|
|
* InitCommittedCharsAndModifiersWithFollowingCharMessages() initializes
|
|
|
|
* mCommittedCharsAndModifiers with mFollowingCharMsgs and aModKeyState.
|
|
|
|
* If mFollowingCharMsgs includes non-printable char messages, they are
|
|
|
|
* ignored (skipped).
|
|
|
|
*/
|
|
|
|
void InitCommittedCharsAndModifiersWithFollowingCharMessages(
|
|
|
|
const ModifierKeyState& aModKeyState);
|
|
|
|
|
2013-11-07 15:17:32 +04:00
|
|
|
/**
|
|
|
|
* Returns true if the key event is caused by auto repeat.
|
|
|
|
*/
|
|
|
|
bool IsRepeat() const
|
|
|
|
{
|
|
|
|
switch (mMsg.message) {
|
|
|
|
case WM_KEYDOWN:
|
|
|
|
case WM_SYSKEYDOWN:
|
|
|
|
case WM_CHAR:
|
|
|
|
case WM_SYSCHAR:
|
|
|
|
case WM_DEADCHAR:
|
|
|
|
case WM_SYSDEADCHAR:
|
2016-04-15 11:02:36 +03:00
|
|
|
case MOZ_WM_KEYDOWN:
|
2013-11-07 15:17:32 +04:00
|
|
|
return ((mMsg.lParam & (1 << 30)) != 0);
|
2014-12-30 04:47:56 +03:00
|
|
|
case WM_APPCOMMAND:
|
|
|
|
if (mVirtualKeyCode) {
|
|
|
|
// If we can map the WM_APPCOMMAND to a virtual keycode, we can trust
|
|
|
|
// the result of GetKeyboardState().
|
|
|
|
BYTE kbdState[256];
|
|
|
|
memset(kbdState, 0, sizeof(kbdState));
|
|
|
|
::GetKeyboardState(kbdState);
|
|
|
|
return !!kbdState[mVirtualKeyCode];
|
|
|
|
}
|
|
|
|
// If there is no virtual keycode for the command, we dispatch both
|
|
|
|
// keydown and keyup events from WM_APPCOMMAND handler. Therefore,
|
|
|
|
// even if WM_APPCOMMAND is caused by auto key repeat, web apps receive
|
|
|
|
// a pair of DOM keydown and keyup events. I.e., KeyboardEvent.repeat
|
|
|
|
// should be never true of such keys.
|
|
|
|
return false;
|
2013-11-07 15:17:32 +04:00
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-29 10:34:47 +04:00
|
|
|
UINT GetScanCodeWithExtendedFlag() const;
|
2013-05-29 10:34:47 +04:00
|
|
|
|
|
|
|
// The result is one of nsIDOMKeyEvent::DOM_KEY_LOCATION_*.
|
|
|
|
uint32_t GetKeyLocation() const;
|
2013-05-29 10:34:48 +04:00
|
|
|
|
2016-09-14 10:20:53 +03:00
|
|
|
/**
|
|
|
|
* RemoveFollowingOddCharMessages() removes odd WM_CHAR messages from the
|
|
|
|
* queue when IsIMEDoingKakuteiUndo() returns true.
|
|
|
|
*/
|
|
|
|
void RemoveFollowingOddCharMessages();
|
|
|
|
|
2013-05-29 10:34:48 +04:00
|
|
|
/**
|
|
|
|
* "Kakutei-Undo" of ATOK or WXG (both of them are Japanese IME) causes
|
|
|
|
* strange WM_KEYDOWN/WM_KEYUP/WM_CHAR message pattern. So, when this
|
|
|
|
* returns true, the caller needs to be careful for processing the messages.
|
|
|
|
*/
|
|
|
|
bool IsIMEDoingKakuteiUndo() const;
|
|
|
|
|
2013-05-29 10:34:49 +04:00
|
|
|
bool IsKeyDownMessage() const
|
|
|
|
{
|
2016-04-15 11:02:36 +03:00
|
|
|
return (mMsg.message == WM_KEYDOWN ||
|
|
|
|
mMsg.message == WM_SYSKEYDOWN ||
|
|
|
|
mMsg.message == MOZ_WM_KEYDOWN);
|
2013-05-29 10:34:49 +04:00
|
|
|
}
|
2014-01-31 20:31:01 +04:00
|
|
|
bool IsKeyUpMessage() const
|
|
|
|
{
|
2016-04-15 11:02:36 +03:00
|
|
|
return (mMsg.message == WM_KEYUP ||
|
|
|
|
mMsg.message == WM_SYSKEYUP ||
|
|
|
|
mMsg.message == MOZ_WM_KEYUP);
|
2014-01-31 20:31:01 +04:00
|
|
|
}
|
2016-10-03 11:45:03 +03:00
|
|
|
bool IsCharOrSysCharMessage(const MSG& aMSG) const
|
2014-01-31 20:31:01 +04:00
|
|
|
{
|
2016-10-03 11:45:03 +03:00
|
|
|
return IsCharOrSysCharMessage(aMSG.message);
|
2014-01-31 20:31:01 +04:00
|
|
|
}
|
2016-10-03 11:45:03 +03:00
|
|
|
bool IsCharOrSysCharMessage(UINT aMessage) const
|
2014-01-31 20:31:01 +04:00
|
|
|
{
|
|
|
|
return (aMessage == WM_CHAR || aMessage == WM_SYSCHAR);
|
|
|
|
}
|
|
|
|
bool IsCharMessage(const MSG& aMSG) const
|
|
|
|
{
|
|
|
|
return IsCharMessage(aMSG.message);
|
|
|
|
}
|
|
|
|
bool IsCharMessage(UINT aMessage) const
|
|
|
|
{
|
2016-10-03 11:45:03 +03:00
|
|
|
return (IsCharOrSysCharMessage(aMessage) || IsDeadCharMessage(aMessage));
|
2014-01-31 20:31:01 +04:00
|
|
|
}
|
|
|
|
bool IsDeadCharMessage(const MSG& aMSG) const
|
|
|
|
{
|
|
|
|
return IsDeadCharMessage(aMSG.message);
|
|
|
|
}
|
|
|
|
bool IsDeadCharMessage(UINT aMessage) const
|
|
|
|
{
|
|
|
|
return (aMessage == WM_DEADCHAR || aMessage == WM_SYSDEADCHAR);
|
|
|
|
}
|
|
|
|
bool IsSysCharMessage(const MSG& aMSG) const
|
|
|
|
{
|
|
|
|
return IsSysCharMessage(aMSG.message);
|
|
|
|
}
|
|
|
|
bool IsSysCharMessage(UINT aMessage) const
|
|
|
|
{
|
|
|
|
return (aMessage == WM_SYSCHAR || aMessage == WM_SYSDEADCHAR);
|
|
|
|
}
|
2014-03-12 15:04:17 +04:00
|
|
|
bool MayBeSameCharMessage(const MSG& aCharMsg1, const MSG& aCharMsg2) const;
|
2016-10-03 12:07:33 +03:00
|
|
|
bool IsFollowedByPrintableCharMessage() const;
|
2016-10-07 05:36:34 +03:00
|
|
|
bool IsFollowedByPrintableCharOrSysCharMessage() const;
|
2013-08-27 16:34:57 +04:00
|
|
|
bool IsFollowedByDeadCharMessage() const;
|
2016-04-15 11:02:36 +03:00
|
|
|
bool IsKeyMessageOnPlugin() const
|
|
|
|
{
|
|
|
|
return (mMsg.message == MOZ_WM_KEYDOWN ||
|
|
|
|
mMsg.message == MOZ_WM_KEYUP);
|
|
|
|
}
|
2016-10-03 11:52:41 +03:00
|
|
|
bool IsPrintableCharMessage(const MSG& aMSG) const
|
|
|
|
{
|
|
|
|
return aMSG.message == WM_CHAR &&
|
|
|
|
!IsControlChar(static_cast<char16_t>(aMSG.wParam));
|
|
|
|
}
|
2016-10-07 05:36:34 +03:00
|
|
|
bool IsPrintableCharOrSysCharMessage(const MSG& aMSG) const
|
|
|
|
{
|
|
|
|
return IsCharOrSysCharMessage(aMSG) &&
|
|
|
|
!IsControlChar(static_cast<char16_t>(aMSG.wParam));
|
|
|
|
}
|
2016-10-03 18:21:40 +03:00
|
|
|
bool IsControlCharMessage(const MSG& aMSG) const
|
|
|
|
{
|
|
|
|
return IsCharMessage(aMSG.message) &&
|
|
|
|
IsControlChar(static_cast<char16_t>(aMSG.wParam));
|
|
|
|
}
|
2014-03-04 05:34:27 +04:00
|
|
|
|
Bug 1305943 Don't consume following WM_SYSCHAR message for some key combinations which are reserved by the system r=m_kato
When key combination is reserved by the system, web apps shouldn't be able to consume the key events. In such case, we've decided that we never expose the key events in web contents (including chrome contents). Therefore, NativeKey stops dispatching keyboard events only for Alt+Space.
However, new code of the fix of bug 1300003 always consumes WM_SYSCHAR which follows WM_SYSKEYDOWN of Alt+Space. This is the cause of bug 1305943.
For fixing this bug, NativeKey should have a helper method, IsReservedBySystem(), and when it returns true, it should do nothing when Handle*Message() is called and should not consume following WM_SYSCHAR messages at handling WM_*KEYDOWN.
Unfortunately, it's impossible to test this regression because nsDOMWindowUtils::SendNativeKeyEvent() may call nsIWidget::SynthesizeNativeKeyEvent() asynchronously. See <https://dxr.mozilla.org/mozilla-central/source/dom/base/nsDOMWindowUtils.cpp#1105-1108>. Therefore, it cannot return if it's consumed.
MozReview-Commit-ID: 9ABh2rYNkFs
--HG--
extra : rebase_source : 7416e45babccce3af795dc523f46dc00fdddc6c7
2016-09-30 11:32:34 +03:00
|
|
|
/**
|
|
|
|
* IsReservedBySystem() returns true if the key combination is reserved by
|
|
|
|
* the system. Even if it's consumed by web apps, the message should be
|
|
|
|
* sent to next wndproc.
|
|
|
|
*/
|
|
|
|
bool IsReservedBySystem() const;
|
|
|
|
|
2014-03-04 05:34:27 +04:00
|
|
|
/**
|
|
|
|
* GetFollowingCharMessage() returns following char message of handling
|
|
|
|
* keydown event. If the message is found, this method returns true.
|
|
|
|
* Otherwise, returns false.
|
|
|
|
*
|
|
|
|
* WARNING: Even if this returns true, aCharMsg may be WM_NULL or its
|
|
|
|
* hwnd may be different window.
|
|
|
|
*/
|
2016-09-23 10:40:01 +03:00
|
|
|
bool GetFollowingCharMessage(MSG& aCharMsg);
|
2013-05-29 10:34:49 +04:00
|
|
|
|
2014-06-01 06:32:08 +04:00
|
|
|
/**
|
|
|
|
* Whether the key event can compute virtual keycode from the scancode value.
|
|
|
|
*/
|
|
|
|
bool CanComputeVirtualKeyCodeFromScanCode() const;
|
|
|
|
|
2013-05-29 10:34:49 +04:00
|
|
|
/**
|
|
|
|
* Wraps MapVirtualKeyEx() with MAPVK_VSC_TO_VK.
|
|
|
|
*/
|
|
|
|
uint8_t ComputeVirtualKeyCodeFromScanCode() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Wraps MapVirtualKeyEx() with MAPVK_VSC_TO_VK_EX.
|
|
|
|
*/
|
|
|
|
uint8_t ComputeVirtualKeyCodeFromScanCodeEx() const;
|
|
|
|
|
2014-06-01 06:32:08 +04:00
|
|
|
/**
|
|
|
|
* Wraps MapVirtualKeyEx() with MAPVK_VK_TO_VSC_EX or MAPVK_VK_TO_VSC.
|
|
|
|
*/
|
|
|
|
uint16_t ComputeScanCodeExFromVirtualKeyCode(UINT aVirtualKeyCode) const;
|
|
|
|
|
2013-05-29 10:34:49 +04:00
|
|
|
/**
|
|
|
|
* Wraps MapVirtualKeyEx() with MAPVK_VSC_TO_VK and MAPVK_VK_TO_CHAR.
|
|
|
|
*/
|
2014-01-04 19:02:17 +04:00
|
|
|
char16_t ComputeUnicharFromScanCode() const;
|
2013-05-29 10:34:49 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Initializes the aKeyEvent with the information stored in the instance.
|
|
|
|
*/
|
2016-03-16 07:47:49 +03:00
|
|
|
nsEventStatus InitKeyEvent(WidgetKeyboardEvent& aKeyEvent,
|
|
|
|
const ModifierKeyState& aModKeyState,
|
|
|
|
const MSG* aMsgSentToPlugin = nullptr) const;
|
|
|
|
nsEventStatus InitKeyEvent(WidgetKeyboardEvent& aKeyEvent,
|
|
|
|
const MSG* aMsgSentToPlugin = nullptr) const;
|
2013-05-29 10:34:49 +04:00
|
|
|
|
Bug 1303273 part.3 Dispatch eKeyPress events without NativeKey::HandleCharMessage() when it handles WM_(SYS)KEYDOWN message and there are following WM_(SYS)CHAR messages which includes non-control character r=m_kato
This patch creates NativeKey::DispatchKeyPressEventsWithRetrievedCharMessages() for dispatching eKeyPress event with mCommittedCharsAndModifiers when it stores following printable WM_(SYS)CHAR messages.
Using loop for dispatching eKeyPress event for every WM_(SYS)CHAR message is wrong because WidgetKeyboardEvent::mKeyValue is initialized with mCommittedCharsAndModifiers and it causes TextEventDispatcher dispatching multiple eKeyPress events at every call of MaybeDispatchKeypressEvents(). Therefore, if mKeyValue is "^^", eKeyPress event is dispatched 4 times --for the first message, eKeyPress events are fired for each "^" and for the second message, eKeyPress events are fired again for each "^"--. Therefore, when it handles WM_(SYS)KEYDOWN and it causes inputting one or more printable characters, it's the easiest way not to use HandleCharMessage().
The new method calls TextEventDispatcher::MaybeDispatchKeypressEvents() only once and it requests to call the callback method with new argument of MaybeDispatchKeypressEvents() when it needs to dispatch 2 or more eKeyPress events. Then, NativeKey::WillDispatchKeyboardEvent() can set each eKeyPress event to raw information of the message and proper modifier state.
With this change, we can dispatch multiple eKeyPress events with retrieved WM_(SYS)CHAR message information rather than retrieved information from active keyboard layout. Therefore, NeedsToHandleWithoutFollowingCharMessages() doesn't return true even when mCommittedCharsAndModifiers stores two or more characters.
FYI: there is a bug in test_keycodes.xul. That is, Alt+'A' of Greek keyboard layout should cause WM_SYSCHAR with a corresponding Greek character but ASCII characters are specified. Therefore, this patch includes the fix of these bugs
MozReview-Commit-ID: JVm7ZJVug0O
--HG--
extra : rebase_source : 414ecbe2c01c53f294d1346414b1a289aa0abfe8
2016-10-06 14:52:03 +03:00
|
|
|
/**
|
|
|
|
* MaybeInitPluginEventOfKeyEvent() may initialize aKeyEvent::mPluginEvent
|
|
|
|
* with aMsgSentToPlugin if it's necessary.
|
|
|
|
*/
|
|
|
|
void MaybeInitPluginEventOfKeyEvent(WidgetKeyboardEvent& aKeyEvent,
|
|
|
|
const MSG& aMsgSentToPlugin) const;
|
|
|
|
|
2014-12-30 04:47:56 +03:00
|
|
|
/**
|
|
|
|
* Dispatches a command event for aEventCommand.
|
|
|
|
* Returns true if the event is consumed. Otherwise, false.
|
|
|
|
*/
|
|
|
|
bool DispatchCommandEvent(uint32_t aEventCommand) const;
|
|
|
|
|
Bug 1303273 part.3 Dispatch eKeyPress events without NativeKey::HandleCharMessage() when it handles WM_(SYS)KEYDOWN message and there are following WM_(SYS)CHAR messages which includes non-control character r=m_kato
This patch creates NativeKey::DispatchKeyPressEventsWithRetrievedCharMessages() for dispatching eKeyPress event with mCommittedCharsAndModifiers when it stores following printable WM_(SYS)CHAR messages.
Using loop for dispatching eKeyPress event for every WM_(SYS)CHAR message is wrong because WidgetKeyboardEvent::mKeyValue is initialized with mCommittedCharsAndModifiers and it causes TextEventDispatcher dispatching multiple eKeyPress events at every call of MaybeDispatchKeypressEvents(). Therefore, if mKeyValue is "^^", eKeyPress event is dispatched 4 times --for the first message, eKeyPress events are fired for each "^" and for the second message, eKeyPress events are fired again for each "^"--. Therefore, when it handles WM_(SYS)KEYDOWN and it causes inputting one or more printable characters, it's the easiest way not to use HandleCharMessage().
The new method calls TextEventDispatcher::MaybeDispatchKeypressEvents() only once and it requests to call the callback method with new argument of MaybeDispatchKeypressEvents() when it needs to dispatch 2 or more eKeyPress events. Then, NativeKey::WillDispatchKeyboardEvent() can set each eKeyPress event to raw information of the message and proper modifier state.
With this change, we can dispatch multiple eKeyPress events with retrieved WM_(SYS)CHAR message information rather than retrieved information from active keyboard layout. Therefore, NeedsToHandleWithoutFollowingCharMessages() doesn't return true even when mCommittedCharsAndModifiers stores two or more characters.
FYI: there is a bug in test_keycodes.xul. That is, Alt+'A' of Greek keyboard layout should cause WM_SYSCHAR with a corresponding Greek character but ASCII characters are specified. Therefore, this patch includes the fix of these bugs
MozReview-Commit-ID: JVm7ZJVug0O
--HG--
extra : rebase_source : 414ecbe2c01c53f294d1346414b1a289aa0abfe8
2016-10-06 14:52:03 +03:00
|
|
|
/**
|
|
|
|
* DispatchKeyPressEventsWithRetrievedCharMessages() dispatches keypress
|
|
|
|
* event(s) with retrieved char messages.
|
|
|
|
*/
|
|
|
|
bool DispatchKeyPressEventsWithRetrievedCharMessages() const;
|
|
|
|
|
2013-05-29 10:34:49 +04:00
|
|
|
/**
|
2016-03-16 07:47:49 +03:00
|
|
|
* DispatchKeyPressEventsWithoutCharMessage() dispatches keypress event(s)
|
|
|
|
* without char messages. So, this should be used only when there are no
|
|
|
|
* following char messages.
|
2013-05-29 10:34:49 +04:00
|
|
|
*/
|
2016-03-16 07:47:49 +03:00
|
|
|
bool DispatchKeyPressEventsWithoutCharMessage() const;
|
2013-05-29 10:34:49 +04:00
|
|
|
|
|
|
|
/**
|
2016-09-14 18:16:18 +03:00
|
|
|
* MaybeDispatchPluginEventsForRemovedCharMessages() dispatches plugin events
|
|
|
|
* for removed char messages when a windowless plugin has focus.
|
|
|
|
* Returns true if the widget is destroyed or blurred during dispatching a
|
|
|
|
* plugin event.
|
2013-05-29 10:34:49 +04:00
|
|
|
*/
|
2016-09-14 18:16:18 +03:00
|
|
|
bool MaybeDispatchPluginEventsForRemovedCharMessages() const;
|
2013-05-29 10:34:49 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Checkes whether the key event down message is handled without following
|
|
|
|
* WM_CHAR messages. For example, if following WM_CHAR message indicates
|
|
|
|
* control character input, the WM_CHAR message is unclear whether it's
|
|
|
|
* caused by a printable key with Ctrl or just a function key such as Enter
|
|
|
|
* or Backspace.
|
|
|
|
*/
|
|
|
|
bool NeedsToHandleWithoutFollowingCharMessages() const;
|
2016-03-16 07:47:49 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* ComputeInputtingStringWithKeyboardLayout() computes string to be inputted
|
|
|
|
* with the key and the modifier state, without shift state and with shift
|
|
|
|
* state.
|
|
|
|
*/
|
|
|
|
void ComputeInputtingStringWithKeyboardLayout();
|
2016-09-05 12:56:34 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* IsFocusedWindowChanged() returns true if focused window is changed
|
|
|
|
* after the instance is created.
|
|
|
|
*/
|
|
|
|
bool IsFocusedWindowChanged() const
|
|
|
|
{
|
|
|
|
return mFocusedWndBeforeDispatch != ::GetFocus();
|
|
|
|
}
|
2016-09-15 11:02:30 +03:00
|
|
|
|
2016-10-03 17:55:14 +03:00
|
|
|
/**
|
|
|
|
* Handles WM_CHAR message or WM_SYSCHAR message. The instance must be
|
|
|
|
* initialized with WM_KEYDOWN, WM_SYSKEYDOWN or them.
|
|
|
|
* Returns true if dispatched keypress event is consumed. Otherwise, false.
|
|
|
|
*/
|
|
|
|
bool HandleCharMessage(const MSG& aCharMsg,
|
|
|
|
bool* aEventDispatched = nullptr) const;
|
|
|
|
|
2016-09-15 11:02:30 +03:00
|
|
|
// Calls of PeekMessage() from NativeKey might cause nested message handling
|
|
|
|
// due to (perhaps) odd API hook. NativeKey should do nothing if given
|
|
|
|
// message is tried to be retrieved by another instance.
|
|
|
|
|
|
|
|
/**
|
|
|
|
* sLatestInstacne is a pointer to the newest instance of NativeKey which is
|
|
|
|
* handling a key or char message(s).
|
|
|
|
*/
|
|
|
|
static NativeKey* sLatestInstance;
|
2016-09-23 10:40:01 +03:00
|
|
|
|
2016-10-06 17:22:18 +03:00
|
|
|
static const MSG sEmptyMSG;
|
|
|
|
|
2016-09-23 10:40:01 +03:00
|
|
|
static bool IsEmptyMSG(const MSG& aMSG)
|
|
|
|
{
|
2016-10-06 17:22:18 +03:00
|
|
|
return !memcmp(&aMSG, &sEmptyMSG, sizeof(MSG));
|
2016-09-23 10:40:01 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool IsAnotherInstanceRemovingCharMessage() const
|
|
|
|
{
|
|
|
|
return mLastInstance && !IsEmptyMSG(mLastInstance->mRemovingMsg);
|
|
|
|
}
|
2012-05-03 12:35:02 +04:00
|
|
|
};
|
2006-01-07 21:46:46 +03:00
|
|
|
|
2010-07-22 06:11:34 +04:00
|
|
|
class KeyboardLayout
|
2006-01-07 21:46:46 +03:00
|
|
|
{
|
|
|
|
public:
|
2013-05-29 10:34:47 +04:00
|
|
|
static KeyboardLayout* GetInstance();
|
|
|
|
static void Shutdown();
|
2013-05-29 10:34:47 +04:00
|
|
|
static void NotifyIdleServiceOfUserActivity();
|
2006-01-07 21:46:46 +03:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
static bool IsPrintableCharKey(uint8_t aVirtualKey);
|
2006-01-07 21:46:46 +03:00
|
|
|
|
2012-06-15 13:52:50 +04:00
|
|
|
/**
|
2012-06-15 13:52:50 +04:00
|
|
|
* IsDeadKey() returns true if aVirtualKey is a dead key with aModKeyState.
|
2012-06-15 13:52:50 +04:00
|
|
|
* This method isn't stateful.
|
2012-06-15 13:52:50 +04:00
|
|
|
*/
|
2012-08-22 19:56:38 +04:00
|
|
|
bool IsDeadKey(uint8_t aVirtualKey,
|
2012-06-15 13:52:50 +04:00
|
|
|
const ModifierKeyState& aModKeyState) const;
|
2006-01-07 21:46:46 +03:00
|
|
|
|
2016-09-30 09:55:51 +03:00
|
|
|
/**
|
|
|
|
* IsInDeadKeySequence() returns true when it's in a dead key sequence.
|
|
|
|
* It starts when a dead key is down and ends when another key down causes
|
|
|
|
* inactivating the dead key state.
|
|
|
|
*/
|
|
|
|
bool IsInDeadKeySequence() const { return mActiveDeadKey >= 0; }
|
|
|
|
|
2016-08-31 10:42:27 +03:00
|
|
|
/**
|
|
|
|
* IsSysKey() returns true if aVirtualKey with aModKeyState causes WM_SYSKEY*
|
|
|
|
* or WM_SYS*CHAR messages.
|
|
|
|
*/
|
|
|
|
bool IsSysKey(uint8_t aVirtualKey,
|
|
|
|
const ModifierKeyState& aModKeyState) const;
|
|
|
|
|
2012-06-15 13:52:50 +04:00
|
|
|
/**
|
2016-09-16 12:38:53 +03:00
|
|
|
* GetUniCharsAndModifiers() returns characters which are inputted by
|
2012-06-15 13:52:50 +04:00
|
|
|
* aVirtualKey with aModKeyState. This method isn't stateful.
|
2016-09-16 12:22:12 +03:00
|
|
|
* Note that if the combination causes text input, the result's Ctrl and
|
|
|
|
* Alt key state are never active.
|
2012-06-15 13:52:50 +04:00
|
|
|
*/
|
|
|
|
UniCharsAndModifiers GetUniCharsAndModifiers(
|
2012-08-22 19:56:38 +04:00
|
|
|
uint8_t aVirtualKey,
|
2016-09-16 12:22:12 +03:00
|
|
|
const ModifierKeyState& aModKeyState) const
|
|
|
|
{
|
|
|
|
VirtualKey::ShiftState shiftState =
|
|
|
|
VirtualKey::ModifierKeyStateToShiftState(aModKeyState);
|
|
|
|
return GetUniCharsAndModifiers(aVirtualKey, shiftState);
|
|
|
|
}
|
2012-06-15 13:52:50 +04:00
|
|
|
|
2016-09-16 12:38:53 +03:00
|
|
|
/**
|
|
|
|
* GetNativeUniCharsAndModifiers() returns characters which are inputted by
|
|
|
|
* aVirtualKey with aModKeyState. The method isn't stateful.
|
|
|
|
* Note that different from GetUniCharsAndModifiers(), this returns
|
|
|
|
* actual modifier state of Ctrl and Alt.
|
|
|
|
*/
|
|
|
|
UniCharsAndModifiers GetNativeUniCharsAndModifiers(
|
|
|
|
uint8_t aVirtualKey,
|
|
|
|
const ModifierKeyState& aModKeyState) const;
|
|
|
|
|
2012-06-15 13:52:50 +04:00
|
|
|
/**
|
2013-05-29 10:34:47 +04:00
|
|
|
* OnLayoutChange() must be called before the first keydown message is
|
|
|
|
* received. LoadLayout() changes the keyboard state, that causes breaking
|
|
|
|
* dead key state. Therefore, we need to load the layout before the first
|
|
|
|
* keydown message.
|
2012-06-15 13:52:50 +04:00
|
|
|
*/
|
2013-05-29 10:34:47 +04:00
|
|
|
void OnLayoutChange(HKL aKeyboardLayout)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(!mIsOverridden);
|
|
|
|
LoadLayout(aKeyboardLayout);
|
|
|
|
}
|
2012-06-15 13:52:50 +04:00
|
|
|
|
2012-06-15 13:52:51 +04:00
|
|
|
/**
|
2013-05-29 10:34:47 +04:00
|
|
|
* OverrideLayout() loads the specified keyboard layout.
|
2012-06-15 13:52:51 +04:00
|
|
|
*/
|
2013-05-29 10:34:47 +04:00
|
|
|
void OverrideLayout(HKL aLayout)
|
|
|
|
{
|
|
|
|
mIsOverridden = true;
|
|
|
|
LoadLayout(aLayout);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* RestoreLayout() loads the current keyboard layout of the thread.
|
|
|
|
*/
|
|
|
|
void RestoreLayout()
|
|
|
|
{
|
|
|
|
mIsOverridden = false;
|
|
|
|
mIsPendingToRestoreKeyboardLayout = true;
|
|
|
|
}
|
2012-06-15 13:52:50 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t ConvertNativeKeyCodeToDOMKeyCode(UINT aNativeKeyCode) const;
|
2008-12-06 12:27:30 +03:00
|
|
|
|
2013-04-24 07:49:47 +04:00
|
|
|
/**
|
|
|
|
* ConvertNativeKeyCodeToKeyNameIndex() returns KeyNameIndex value for
|
|
|
|
* non-printable keys (except some special keys like space key).
|
|
|
|
*/
|
|
|
|
KeyNameIndex ConvertNativeKeyCodeToKeyNameIndex(uint8_t aVirtualKey) const;
|
|
|
|
|
2014-05-25 06:08:59 +04:00
|
|
|
/**
|
|
|
|
* ConvertScanCodeToCodeNameIndex() returns CodeNameIndex value for
|
|
|
|
* the given scan code. aScanCode can be over 0xE000 since this method
|
|
|
|
* doesn't use Windows API.
|
|
|
|
*/
|
2014-06-01 06:32:08 +04:00
|
|
|
static CodeNameIndex ConvertScanCodeToCodeNameIndex(UINT aScanCode);
|
2014-05-25 06:08:59 +04:00
|
|
|
|
2012-06-15 13:52:51 +04:00
|
|
|
HKL GetLayout() const
|
|
|
|
{
|
2013-05-29 10:34:47 +04:00
|
|
|
return mIsPendingToRestoreKeyboardLayout ? ::GetKeyboardLayout(0) :
|
|
|
|
mKeyboardLayout;
|
2012-06-15 13:52:51 +04:00
|
|
|
}
|
2013-05-29 10:34:47 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This wraps MapVirtualKeyEx() API with MAPVK_VK_TO_VSC.
|
|
|
|
*/
|
|
|
|
WORD ComputeScanCodeForVirtualKeyCode(uint8_t aVirtualKeyCode) const;
|
2013-05-29 10:34:49 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Implementation of nsIWidget::SynthesizeNativeKeyEvent().
|
|
|
|
*/
|
|
|
|
nsresult SynthesizeNativeKeyEvent(nsWindowBase* aWidget,
|
|
|
|
int32_t aNativeKeyboardLayout,
|
|
|
|
int32_t aNativeKeyCode,
|
|
|
|
uint32_t aModifierFlags,
|
|
|
|
const nsAString& aCharacters,
|
|
|
|
const nsAString& aUnmodifiedCharacters);
|
2016-10-04 10:37:07 +03:00
|
|
|
|
|
|
|
private:
|
|
|
|
KeyboardLayout();
|
|
|
|
~KeyboardLayout();
|
|
|
|
|
|
|
|
static KeyboardLayout* sInstance;
|
|
|
|
static nsIIdleServiceInternal* sIdleService;
|
|
|
|
|
|
|
|
struct DeadKeyTableListEntry
|
|
|
|
{
|
|
|
|
DeadKeyTableListEntry* next;
|
|
|
|
uint8_t data[1];
|
|
|
|
};
|
|
|
|
|
|
|
|
HKL mKeyboardLayout;
|
|
|
|
|
|
|
|
VirtualKey mVirtualKeys[NS_NUM_OF_KEYS];
|
|
|
|
DeadKeyTableListEntry* mDeadKeyTableListHead;
|
|
|
|
int32_t mActiveDeadKey; // -1 = no active dead-key
|
|
|
|
VirtualKey::ShiftState mDeadKeyShiftState;
|
|
|
|
|
|
|
|
bool mIsOverridden;
|
|
|
|
bool mIsPendingToRestoreKeyboardLayout;
|
|
|
|
|
|
|
|
static inline int32_t GetKeyIndex(uint8_t aVirtualKey);
|
|
|
|
static int CompareDeadKeyEntries(const void* aArg1, const void* aArg2,
|
|
|
|
void* aData);
|
|
|
|
static bool AddDeadKeyEntry(char16_t aBaseChar, char16_t aCompositeChar,
|
|
|
|
DeadKeyEntry* aDeadKeyArray, uint32_t aEntries);
|
|
|
|
bool EnsureDeadKeyActive(bool aIsActive, uint8_t aDeadKey,
|
|
|
|
const PBYTE aDeadKeyKbdState);
|
|
|
|
uint32_t GetDeadKeyCombinations(uint8_t aDeadKey,
|
|
|
|
const PBYTE aDeadKeyKbdState,
|
|
|
|
uint16_t aShiftStatesWithBaseChars,
|
|
|
|
DeadKeyEntry* aDeadKeyArray,
|
|
|
|
uint32_t aMaxEntries);
|
|
|
|
/**
|
|
|
|
* Activates or deactivates dead key state.
|
|
|
|
*/
|
|
|
|
void ActivateDeadKeyState(const NativeKey& aNativeKey,
|
|
|
|
const ModifierKeyState& aModKeyState);
|
|
|
|
void DeactivateDeadKeyState();
|
|
|
|
|
|
|
|
const DeadKeyTable* AddDeadKeyTable(const DeadKeyEntry* aDeadKeyArray,
|
|
|
|
uint32_t aEntries);
|
|
|
|
void ReleaseDeadKeyTables();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Loads the specified keyboard layout. This method always clear the dead key
|
|
|
|
* state.
|
|
|
|
*/
|
|
|
|
void LoadLayout(HKL aLayout);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* InitNativeKey() must be called when actually widget receives WM_KEYDOWN or
|
|
|
|
* WM_KEYUP. This method is stateful. This saves current dead key state at
|
|
|
|
* WM_KEYDOWN. Additionally, computes current inputted character(s) and set
|
|
|
|
* them to the aNativeKey.
|
|
|
|
*/
|
|
|
|
void InitNativeKey(NativeKey& aNativeKey,
|
|
|
|
const ModifierKeyState& aModKeyState);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* MaybeInitNativeKeyAsDeadKey() initializes aNativeKey only when aNativeKey
|
|
|
|
* is a dead key's event.
|
|
|
|
* When it's not in a dead key sequence, this activates the dead key state.
|
|
|
|
* When it's in a dead key sequence, this initializes aNativeKey with a
|
|
|
|
* composite character or a preceding dead char and a dead char which should
|
|
|
|
* be caused by aNativeKey.
|
|
|
|
* Returns true when this initializes aNativeKey. Otherwise, false.
|
|
|
|
*/
|
|
|
|
bool MaybeInitNativeKeyAsDeadKey(NativeKey& aNativeKey,
|
|
|
|
const ModifierKeyState& aModKeyState);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* MaybeInitNativeKeyWithCompositeChar() may initialize aNativeKey with
|
|
|
|
* proper composite character when dead key produces a composite character.
|
|
|
|
* Otherwise, just returns false.
|
|
|
|
*/
|
|
|
|
bool MaybeInitNativeKeyWithCompositeChar(
|
|
|
|
NativeKey& aNativeKey,
|
|
|
|
const ModifierKeyState& aModKeyState);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* See the comment of GetUniCharsAndModifiers() below.
|
|
|
|
*/
|
|
|
|
UniCharsAndModifiers GetUniCharsAndModifiers(
|
|
|
|
uint8_t aVirtualKey,
|
|
|
|
VirtualKey::ShiftState aShiftState) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* GetCompositeChar() returns a composite character with dead character
|
|
|
|
* caused by aVirtualKeyOfDeadKey and aShiftStateOfDeadKey and a base
|
|
|
|
* character (aBaseChar).
|
|
|
|
* If the combination of the dead character and the base character doesn't
|
|
|
|
* cause a composite character, this returns 0.
|
|
|
|
*/
|
|
|
|
char16_t GetCompositeChar(uint8_t aVirtualKeyOfDeadKey,
|
|
|
|
VirtualKey::ShiftState aShiftStateOfDeadKey,
|
|
|
|
char16_t aBaseChar) const;
|
|
|
|
|
|
|
|
// NativeKey class should access InitNativeKey() directly, but it shouldn't
|
|
|
|
// be available outside of NativeKey. So, let's make NativeKey a friend
|
|
|
|
// class of this.
|
|
|
|
friend class NativeKey;
|
2006-01-07 21:46:46 +03:00
|
|
|
};
|
|
|
|
|
2013-05-29 10:34:49 +04:00
|
|
|
class RedirectedKeyDownMessageManager
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/*
|
|
|
|
* If a window receives WM_KEYDOWN message or WM_SYSKEYDOWM message which is
|
|
|
|
* a redirected message, NativeKey::DispatchKeyDownAndKeyPressEvent()
|
2015-08-29 02:58:27 +03:00
|
|
|
* prevents to dispatch eKeyDown event because it has been dispatched
|
2013-05-29 10:34:49 +04:00
|
|
|
* before the message was redirected. However, in some cases, WM_*KEYDOWN
|
|
|
|
* message handler may not handle actually. Then, the message handler needs
|
|
|
|
* to forget the redirected message and remove WM_CHAR message or WM_SYSCHAR
|
|
|
|
* message for the redirected keydown message. AutoFlusher class is a helper
|
|
|
|
* class for doing it. This must be created in the stack.
|
|
|
|
*/
|
2015-03-21 19:28:04 +03:00
|
|
|
class MOZ_STACK_CLASS AutoFlusher final
|
2013-05-29 10:34:49 +04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
AutoFlusher(nsWindowBase* aWidget, const MSG &aMsg) :
|
|
|
|
mCancel(!RedirectedKeyDownMessageManager::IsRedirectedMessage(aMsg)),
|
|
|
|
mWidget(aWidget), mMsg(aMsg)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
~AutoFlusher()
|
|
|
|
{
|
|
|
|
if (mCancel) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Prevent unnecessary keypress event
|
|
|
|
if (!mWidget->Destroyed()) {
|
|
|
|
RedirectedKeyDownMessageManager::RemoveNextCharMessage(mMsg.hwnd);
|
|
|
|
}
|
|
|
|
// Foreget the redirected message
|
|
|
|
RedirectedKeyDownMessageManager::Forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Cancel() { mCancel = true; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool mCancel;
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsWindowBase> mWidget;
|
2013-05-29 10:34:49 +04:00
|
|
|
const MSG &mMsg;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void WillRedirect(const MSG& aMsg, bool aDefualtPrevented)
|
|
|
|
{
|
|
|
|
sRedirectedKeyDownMsg = aMsg;
|
|
|
|
sDefaultPreventedOfRedirectedMsg = aDefualtPrevented;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void Forget()
|
|
|
|
{
|
|
|
|
sRedirectedKeyDownMsg.message = WM_NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void PreventDefault() { sDefaultPreventedOfRedirectedMsg = true; }
|
|
|
|
static bool DefaultPrevented() { return sDefaultPreventedOfRedirectedMsg; }
|
|
|
|
|
|
|
|
static bool IsRedirectedMessage(const MSG& aMsg);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* RemoveNextCharMessage() should be called by WM_KEYDOWN or WM_SYSKEYDOWM
|
|
|
|
* message handler. If there is no WM_(SYS)CHAR message for it, this
|
|
|
|
* method does nothing.
|
|
|
|
* NOTE: WM_(SYS)CHAR message is posted by TranslateMessage() API which is
|
|
|
|
* called in message loop. So, WM_(SYS)KEYDOWN message should have
|
|
|
|
* WM_(SYS)CHAR message in the queue if the keydown event causes character
|
|
|
|
* input.
|
|
|
|
*/
|
|
|
|
static void RemoveNextCharMessage(HWND aWnd);
|
|
|
|
|
|
|
|
private:
|
|
|
|
// sRedirectedKeyDownMsg is WM_KEYDOWN message or WM_SYSKEYDOWN message which
|
|
|
|
// is reirected with SendInput() API by
|
|
|
|
// widget::NativeKey::DispatchKeyDownAndKeyPressEvent()
|
|
|
|
static MSG sRedirectedKeyDownMsg;
|
|
|
|
static bool sDefaultPreventedOfRedirectedMsg;
|
|
|
|
};
|
|
|
|
|
2010-07-27 16:47:42 +04:00
|
|
|
} // namespace widget
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2006-01-07 21:46:46 +03:00
|
|
|
#endif
|