2006-01-07 21:46:46 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Dainis Jonitis, <Dainis_Jonitis@exigengroup.lv>.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2006
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
2010-07-27 16:47:42 +04:00
|
|
|
#ifndef KeyboardLayout_h__
|
|
|
|
#define KeyboardLayout_h__
|
2006-01-07 21:46:46 +03:00
|
|
|
|
|
|
|
#include "nscore.h"
|
|
|
|
#include <windows.h>
|
|
|
|
|
2012-05-17 11:04:16 +04:00
|
|
|
#define NS_NUM_OF_KEYS 54
|
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
|
|
|
|
#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
|
|
|
|
2012-05-05 02:47:46 +04:00
|
|
|
class nsWindow;
|
|
|
|
|
2010-07-27 16:47:42 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace widget {
|
2006-01-07 21:46:46 +03:00
|
|
|
|
2012-05-17 11:04:16 +04:00
|
|
|
class KeyboardLayout;
|
|
|
|
|
2006-01-07 21:46:46 +03:00
|
|
|
// 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 eKeyShiftFlags
|
|
|
|
{
|
|
|
|
eShift = 0x01,
|
|
|
|
eCtrl = 0x02,
|
|
|
|
eAlt = 0x04,
|
|
|
|
eCapsLock = 0x08
|
|
|
|
};
|
|
|
|
|
|
|
|
struct DeadKeyEntry;
|
|
|
|
class DeadKeyTable;
|
|
|
|
|
|
|
|
|
2010-07-22 06:11:34 +04:00
|
|
|
class VirtualKey
|
2006-01-07 21:46:46 +03:00
|
|
|
{
|
|
|
|
union KeyShiftState
|
|
|
|
{
|
|
|
|
struct
|
|
|
|
{
|
2010-07-27 16:48:59 +04:00
|
|
|
PRUnichar Chars[4];
|
2006-01-07 21:46:46 +03:00
|
|
|
} Normal;
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
const DeadKeyTable* Table;
|
2008-12-03 15:22:14 +03:00
|
|
|
PRUnichar DeadChar;
|
2006-01-07 21:46:46 +03:00
|
|
|
} DeadKey;
|
|
|
|
};
|
|
|
|
|
2010-07-27 16:48:59 +04:00
|
|
|
KeyShiftState mShiftStates[16];
|
2006-01-07 21:46:46 +03:00
|
|
|
PRUint16 mIsDeadKey;
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
void SetDeadKey(PRUint8 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:
|
2011-09-29 10:19:26 +04:00
|
|
|
bool IsDeadKey(PRUint8 aShiftState) const
|
2006-01-07 21:46:46 +03:00
|
|
|
{
|
|
|
|
return (mIsDeadKey & (1 << aShiftState)) != 0;
|
|
|
|
}
|
|
|
|
|
2010-07-27 16:48:59 +04:00
|
|
|
void AttachDeadKeyTable(PRUint8 aShiftState,
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2010-07-27 16:48:59 +04:00
|
|
|
void SetNormalChars(PRUint8 aShiftState, const PRUnichar* aChars,
|
|
|
|
PRUint32 aNumOfChars);
|
|
|
|
void SetDeadChar(PRUint8 aShiftState, PRUnichar aDeadChar);
|
|
|
|
const DeadKeyTable* MatchingDeadKeyTable(const DeadKeyEntry* aDeadKeyArray,
|
|
|
|
PRUint32 aEntries) const;
|
|
|
|
inline PRUnichar GetCompositeChar(PRUint8 aShiftState,
|
|
|
|
PRUnichar aBaseChar) const;
|
|
|
|
PRUint32 GetNativeUniChars(PRUint8 aShiftState,
|
|
|
|
PRUnichar* aUniChars = nsnull) const;
|
|
|
|
PRUint32 GetUniChars(PRUint8 aShiftState, PRUnichar* aUniChars,
|
|
|
|
PRUint8* aFinalShiftState) const;
|
2006-01-07 21:46:46 +03:00
|
|
|
};
|
|
|
|
|
2012-05-03 12:35:02 +04:00
|
|
|
class NativeKey {
|
|
|
|
public:
|
|
|
|
NativeKey() :
|
2012-05-05 02:47:46 +04:00
|
|
|
mDOMKeyCode(0), mVirtualKeyCode(0), mOriginalVirtualKeyCode(0),
|
2012-05-03 12:35:02 +04:00
|
|
|
mScanCode(0), mIsExtended(false)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-05-17 11:04:16 +04:00
|
|
|
NativeKey(const KeyboardLayout& aKeyboardLayout,
|
2012-05-05 02:47:46 +04:00
|
|
|
nsWindow* aWindow,
|
2012-05-03 12:35:02 +04:00
|
|
|
const MSG& aKeyOrCharMessage);
|
|
|
|
|
2012-05-05 02:47:46 +04:00
|
|
|
PRUint32 GetDOMKeyCode() const { return mDOMKeyCode; }
|
|
|
|
|
2012-05-03 12:35:02 +04:00
|
|
|
// The result is one of nsIDOMKeyEvent::DOM_KEY_LOCATION_*.
|
|
|
|
PRUint32 GetKeyLocation() const;
|
2012-05-05 02:47:46 +04:00
|
|
|
WORD GetScanCode() const { return mScanCode; }
|
2012-05-03 12:35:02 +04:00
|
|
|
PRUint8 GetVirtualKeyCode() const { return mVirtualKeyCode; }
|
|
|
|
PRUint8 GetOriginalVirtualKeyCode() const { return mOriginalVirtualKeyCode; }
|
|
|
|
|
|
|
|
private:
|
2012-05-05 02:47:46 +04:00
|
|
|
PRUint32 mDOMKeyCode;
|
2012-05-03 12:35:02 +04:00
|
|
|
// mVirtualKeyCode distinguishes left key or right key of modifier key.
|
|
|
|
PRUint8 mVirtualKeyCode;
|
|
|
|
// 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.
|
|
|
|
PRUint8 mOriginalVirtualKeyCode;
|
|
|
|
WORD mScanCode;
|
|
|
|
bool mIsExtended;
|
|
|
|
|
|
|
|
UINT GetScanCodeWithExtendedFlag() const;
|
|
|
|
};
|
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
|
|
|
{
|
|
|
|
struct DeadKeyTableListEntry
|
|
|
|
{
|
|
|
|
DeadKeyTableListEntry* next;
|
2010-07-27 16:48:59 +04:00
|
|
|
PRUint8 data[1];
|
2006-01-07 21:46:46 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
HKL mKeyboardLayout;
|
|
|
|
|
2010-07-27 16:50:21 +04:00
|
|
|
VirtualKey mVirtualKeys[NS_NUM_OF_KEYS];
|
2006-01-07 21:46:46 +03:00
|
|
|
DeadKeyTableListEntry* mDeadKeyTableListHead;
|
|
|
|
PRInt32 mActiveDeadKey; // -1 = no active dead-key
|
|
|
|
PRUint8 mDeadKeyShiftState;
|
|
|
|
PRInt32 mLastVirtualKeyIndex;
|
|
|
|
PRUint8 mLastShiftState;
|
2010-07-27 16:48:59 +04:00
|
|
|
PRUnichar mChars[5]; // Dead-key + up to 4 characters
|
|
|
|
PRUint8 mShiftStates[5];
|
2006-01-07 21:46:46 +03:00
|
|
|
PRUint8 mNumOfChars;
|
|
|
|
|
2010-07-27 16:48:59 +04:00
|
|
|
static PRUint8 GetShiftState(const PBYTE aKbdState);
|
|
|
|
static void SetShiftState(PBYTE aKbdState, PRUint8 aShiftState);
|
|
|
|
static inline PRInt32 GetKeyIndex(PRUint8 aVirtualKey);
|
|
|
|
static int CompareDeadKeyEntries(const void* aArg1, const void* aArg2,
|
|
|
|
void* aData);
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool AddDeadKeyEntry(PRUnichar aBaseChar, PRUnichar aCompositeChar,
|
2010-07-27 16:48:59 +04:00
|
|
|
DeadKeyEntry* aDeadKeyArray, PRUint32 aEntries);
|
2011-09-29 10:19:26 +04:00
|
|
|
bool EnsureDeadKeyActive(bool aIsActive, PRUint8 aDeadKey,
|
2010-07-27 16:48:59 +04:00
|
|
|
const PBYTE aDeadKeyKbdState);
|
|
|
|
PRUint32 GetDeadKeyCombinations(PRUint8 aDeadKey,
|
|
|
|
const PBYTE aDeadKeyKbdState,
|
|
|
|
PRUint16 aShiftStatesWithBaseChars,
|
|
|
|
DeadKeyEntry* aDeadKeyArray,
|
|
|
|
PRUint32 aMaxEntries);
|
|
|
|
void DeactivateDeadKeyState();
|
|
|
|
const DeadKeyTable* AddDeadKeyTable(const DeadKeyEntry* aDeadKeyArray,
|
|
|
|
PRUint32 aEntries);
|
|
|
|
void ReleaseDeadKeyTables();
|
2006-01-07 21:46:46 +03:00
|
|
|
|
|
|
|
public:
|
2010-07-27 16:48:59 +04:00
|
|
|
KeyboardLayout();
|
|
|
|
~KeyboardLayout();
|
2006-01-07 21:46:46 +03:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool IsPrintableCharKey(PRUint8 aVirtualKey);
|
|
|
|
static bool IsNumpadKey(PRUint8 aVirtualKey);
|
2006-01-07 21:46:46 +03:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool IsDeadKey() const
|
2006-01-07 21:46:46 +03:00
|
|
|
{
|
2010-07-27 16:48:59 +04:00
|
|
|
return (mLastVirtualKeyIndex >= 0) ?
|
2011-10-02 06:16:19 +04:00
|
|
|
mVirtualKeys[mLastVirtualKeyIndex].IsDeadKey(mLastShiftState) : false;
|
2006-01-07 21:46:46 +03:00
|
|
|
}
|
|
|
|
|
2010-07-27 16:48:59 +04:00
|
|
|
void LoadLayout(HKL aLayout);
|
|
|
|
void OnKeyDown(PRUint8 aVirtualKey);
|
|
|
|
PRUint32 GetUniChars(PRUnichar* aUniChars, PRUint8* aShiftStates,
|
|
|
|
PRUint32 aMaxChars) const;
|
2008-04-15 08:16:24 +04:00
|
|
|
PRUint32 GetUniCharsWithShiftState(PRUint8 aVirtualKey, PRUint8 aShiftStates,
|
2008-12-03 15:22:14 +03:00
|
|
|
PRUnichar* aUniChars,
|
2008-04-15 08:16:24 +04:00
|
|
|
PRUint32 aMaxChars) const;
|
2012-05-17 11:04:16 +04:00
|
|
|
PRUint32 ConvertNativeKeyCodeToDOMKeyCode(UINT aNativeKeyCode) const;
|
2008-12-06 12:27:30 +03:00
|
|
|
|
2012-05-17 11:04:16 +04:00
|
|
|
HKL GetLayout() const { return mKeyboardLayout; }
|
2006-01-07 21:46:46 +03:00
|
|
|
};
|
|
|
|
|
2010-07-27 16:47:42 +04:00
|
|
|
} // namespace widget
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2006-01-07 21:46:46 +03:00
|
|
|
#endif
|