mirror of
https://github.com/roytam1/palemoon27.git
synced 2026-05-26 14:18:48 +00:00
8a0a002cf2
- Bug 1148708: Add missing 'override' annotations in DocAccessibleChild.h. rs=ehsan (d606358545)
- Bug 1210408 - make nsMaiInterfaceAction work with proxies, r=tbsaunde (f7c819c6ae)
- Bug 1210407 - teach nsMaiInterfaceTable to use proxies, r=tbsaunde (4ca4f10b5f)
- bug 1185157 make sure we don't send an event to a destroyed ipc document r=billm (23acf53f75)
- bug 1214864 - make SetCarretOffset() async r=davidb (e3079e9b2d)
- missing of Bug 1139972 - IPC Proxy for charAt, r=tbsaunde (e9593ed752)
- bug 1191598 - Pass MOZ_CURRENT_PROJECT in environment when running post-build automation steps for universal mac builds. r=gps (fc342c6ced)
- Bug 1164596 - Add mach android-emulator command; r=ahal (afeb9b27d1)
- Bug 1223149 - Add basic usage documentation for mach build; r=glandium (bfb802d175)
- Bug 1182301 - Improve 'mach build' notifications. r=gps (2c65a122d1)
- Bug 1184696 - Add clobber targets to |mach clobber|; Ability to clobber compiled python files, r=gps (35d8be292e)
- Bug 1117958 - Allow any debugging options to the run or gtest mach subcommands to automatically enable debugging. r=gps (32f986af4b)
- Bug 1180081 - Properly rebuild gtest/libxul before running gtests. r=gps (80db9a3d49)
- Bug 1171647, part 1 - Define a new function to convert the mode to a string. r=njn (61ad16f5ba)
- Bug 1171647, part 2 - Remove redundant assertion for dark matter mode. r=njn (b5ac9519f3)
- Bug 1058178, part 1 - Implement DMD heap scanning mode. r=njn (60e1079536)
- Bug 1058178, part 2 - Implement address clamping analysis for DMD scan logs. r=njn (45c0326b93)
- Bug 1102388 - Fix DMD static constructor ordering dependency. r=mccr8 (59b87897a1)
- Bug 1128705 - Don't redefine PAGE_SIZE in DMD if it's already defined. r=erahm (49216348ee)
- Bug 1179042 - Add a script for analyzing memory blocks using a heap scan DMD log. r=njn DONTBUILD (1c08d2d66e)
- Bug 1207245 - part 6 - rename nsRefPtr<T> to RefPtr<T>; r=ehsan; a=Tomcat (1c999d139b)
- Bug 1158772 - fix non-idiomatic memset call in nsDeque.cpp; r=erahm (de6b555245)
- Bug 1199400 - Part 1: Use CheckedInt when growing nsDeque capacity. r=froydnj (dfdf6814a3)
- Bug 1199400 - Part 0: Remove unused nsDequeIterator. r=froydnj (38d69d7f47)
- Bug 1199400 - Part 2: Add tests for possible nsDeque corner cases. r=froydnj (931baff195)
- Bug 1201997 - Part 1 - Converted compiled test to gtest for nsDeque class. Added tests to test untested methods. r=froydn (e893916651)
- Bug 1201997 - Part 2 - Removing unused methods from the nsDeque class. r=froydn (41595a90ac)
- Bug 1201997 - Part 3 - Make internally used methods private. r=froydn (8cd3afd96f)
- Bug 1201997 - Part 4 - Change size and offset variables to size_t.r=froydn (73eabc8d60)
- Bug 1215140 P1 Add an nsIConsoleReportCollector interface to support navigation channel logging. r=bz (8a41535e2b)
- Bug 1215140 P2 Make HttpBaseChannel implement nsIConsoleReportCollector. r=bz (75fca301f2)
- Bug 1197679 - If nsUnknownDecoder is involved in e10s DivertToParent can break. r=jduell (5d94a12504)
- Bug 1178991 - smartptr for http converter r=hurley (8e7fbc8443)
- bug 366559 - patch 2, fix nsHTTPCompressConv indentation r=bagder (ba762da587)
- bug 366559 - patch 3, fix nsHTTPCompressConv bracing style r=bagder (54195ab451)
- bits of bug 366559 - patch 7, content-encoding brotli for http (f0b4051022)
- Bug 1205112 - Make PushEvent.data nullable. r=mt,smaug (775db32856)
- Bug 1193414 - SharedWorkers thread should be kept alive also when the SharedWorker object is CCed, r=khuey (b77ea8125c)
- Bug 1206520: Add about:config prefs to enable throwing on asm.js validation failures; r=bz (c42126665d)
- Bug 1193414 - Telemetry for SharedWorker spawning. r=bkelly (77984b7bcc)
- Bug 1205676 - Enable WPT service-worker/unregister-then-register-new-script.https.html in e10s, r=nsm (ec24939cf6)
- Bug 1193133 - Throw when calling postMessage from a Service Worker dom object with no global. r=bkelly (526dcacfab)
- Bug 1181871 P1 Only enforce Cache Context shared data destruction on target thread after init. r=ehsan (cdbf3ed3a8)
- Bug 1181871 P2 Fix ServiceWorkerManager usage of stack-based ErrorResult. r=ehsan (c449195d90)
- minor cleanup and missing bit of 1198230 (02f459db05)
- Bug 1143717 - Implement the ServiceWorkerMessageEvent interface. r=baku (027b3465f2)
- fix misspatch (708eee4e84)
- Bug 1188545 - Disentangle service workers from shared workers and refactor event dispatching code into a separate class. r=nsm,mrbkap (fb5b5341c9)
- Bug 1205228 - Change PackagedAppVerifier to notify the verification result asynchronously. r=valentin. (9edda0fa00)
- Bug 1178518 - Packaged App Utils. r=valentin (f60f3b7a93)
- Bug 1213150 - Part 1: Add a nsContentUtils::IsNonSubresourceRequest helper; r=jdm (b509cc3cc9)
- Bug 1213150 - Part 2: Rework ShouldPrepareForIntercept() in terms of subresource requests; r=jdm (2e92fe8780)
- Bug 1213150 - Part 3: Remove nsIInterceptedChannel.isNavigation; r=jdm (becf1cc12f)
- Bug 1213150 follow-up: fix build bustage (8d73d6ca73)
- Bug 1198394 - Part 1: Allow interception of HSTS upgraded connections in non-e10s mode; r=mcmanus (f504c5be08)
- Bug 1198394 - Part 2: Add a test for interception of HSTS upgraded connections; r=jdm (054e984eef)
- Bug 1187011 - Don't allow response body with null body status. r=bkelly (b1860741d1)
- missing bit of 1140788 (29d319712e)
- Bug 1213436 - Reject core dumps with node IDs that don't fit in an IEEE 754 double; r=sfink (3c1f6fdda0)
- Bug 1211006 - Add Debugger.Source.prototype.canonicalId; r=ejpbruel (eef7b79fce)
- Bug 1199218 - Implement JS::ubi::Node::size for js::LazyScript referents; r=sfink (098a48d240)
- Bug 1220031 - Add JS::ubi::Node::scriptFilename; r=sfink (6b824ae680)
- Bug 1143575. Remove unused MediaQueue::Empty. r=cpearce (de737f3433)
- Bug 1209933 - Make sure all parent runtime pointers are the topmost parent, r=billm. (fe824d967d)
- Bug 1197012 - Fix ThrowTypeError in Notification. r=mccr8 (0b1a097526)
- Bug 1197893 - Check the number of arguments for ThrowTypeError() and ThrowRangeError() at compile time. r=peterv (d98c7d78a0)
- Bug 1142083 - Add test for IDN Unicode domain redirect. r=mcmanus (0c8961fe17)
- Bug 1187159 - Add mochitest for loading packaged apps (iframe+fetch+mozapp) r=jduell (ce90ea561b)
- Bug 1186290 - Notify TabParent to switch process when loading a signed package. r=honzab, r=kanru. (c58a14554a)
- fix (15e2df75eb)
- Bug 1206124 P1 Fix "same-origin" CORS credentials in FetchDriver. r=ehsan (fae1bb6ab3)
- Bug 1206124 P2 Test fetch() with credentials and redirects. r=ehsan (ffc6254112)
- Bug 1211751: Remove nsIChannelEventSink-forwarding from EventSource and FetchDriver. It's never needed. r=smaug (adafe5737a)
- Bug 1212433 Fail fetch() calls that require preflight and also redirect. r=sicking a=abillings (c0d6742b9e)
- Bug 1193128 - Fix base64 decoding when fetching data URIs. r=baku (80bafa291a)
- Bug 1195167 part 1: Let necko handle all protocols. r=bkelly (bb932b0ada)
- Bug 1195167 part 2: Remove redundant aCORSFlag argument and instead use mCORSFlagEverSet. r=bkelly (beadafcad0)
- Bug 1195167 part 3: Remove more scheme-specific handling from FetchDriver. r=bkelly (d00b38db9e)
- Bug 1195167 part 4: Remove FetchDriver::BasicFetch since it is empty. r=bkelly (c5ed097267)
- Bug 1210413 P2 Test CORS credentials on cross-origin redirects. r=sicking a=dveditz (b4eeb8aac0)
- Bug 1210413 P1 Propagate new channel load flags from child to parent on redirect. r=jduell a=dveditz (8b329af4fa)
- Bug 1195167 part 5: Make FetchDriver use AsyncOpen2. r=bkelly (cc217c4cc1)
- Bug 1195167 part 6: Some code simplification since necko handles fetch recursion. r=bkelly (f3b6da2262)
- Bug 1195167: Followup to fix test which I forgot to change (81e7439a2e)
- Bug 1215746: Remove RequestMode::Cors_with_forced_preflight. r=bkelly (0336e812b6)
- Bug 1211000: Move CORS preflight logic from nsCORSListenerProxy to nsCORSPreflightListener. r=ehsan (bf2f71cf22)
- missing bit of Bug 1211443 - Drop scheduled update if decoder initialization isn't done yet. r=jya (f6bc074e33)
- Bug 1182571: Fix nsILoadInfo->GetContentPolicyType API to be less ambigious. Audit and fix all users of it. r=ckerschb (5af6fa7442)
- fix (e40c8e7625)
- Bug 1173811 - Part 1: Propagate the response URL to intercepted channels when necessary (non-e10s). r=mayhemer,bkelly (26f4f13c28)
- Bug 1173811 - Part 2: Propagate the response URL to intercepted channels when necessary (e10s). r=mayhemer,bkelly (a603fe1df2)
- Bug 1154309 - Add New Resource Timing Fields r=bz,hurley (1d14eb6bef)
- Bug 1175685 - add OriginAttribute to LoadInfo. r=jonas, r=ckerschb, r=michal (a5d18bb637)
- Bug 1175685 - add OriginAttribute to LoadInfo. r=jonas, r=ckerschb, r=michal (fb07d2c8aa)
- Bug 1212904 P1 Add a LoadTainting enumeration. r=jduell (a1db8a3e99)
- Bug 1212904 P2 Add LoadTainting information to nsILoadInfo. r=jduell (2482e5e334)
- Bug 1221151 - use [infallible] in nsILoadInfo.idl instead of manual %{C++ blocks; r=jduell (aae73129b6)
- Bug 1045891 - CSP 2 child-src implementation r=ckerschb (792920aeb9)
- Bug 1219931 - CSP: Don't allow removing a policy (r=sicking) (9daaab4186)
- Bug 1208661 - Dump client-side layer textures. r=BenWa (1f2d17d515)
719 lines
22 KiB
C++
719 lines
22 KiB
C++
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
/* 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/. */
|
|
|
|
#ifndef KeyboardLayout_h__
|
|
#define KeyboardLayout_h__
|
|
|
|
#include "nscore.h"
|
|
#include "nsAutoPtr.h"
|
|
#include "nsString.h"
|
|
#include "nsWindowBase.h"
|
|
#include "nsWindowDefs.h"
|
|
#include "mozilla/Attributes.h"
|
|
#include "mozilla/EventForwards.h"
|
|
#include <windows.h>
|
|
|
|
#define NS_NUM_OF_KEYS 70
|
|
|
|
#define VK_OEM_1 0xBA // ';:' for US
|
|
#define VK_OEM_PLUS 0xBB // '+' any country
|
|
#define VK_OEM_COMMA 0xBC
|
|
#define VK_OEM_MINUS 0xBD // '-' any country
|
|
#define VK_OEM_PERIOD 0xBE
|
|
#define VK_OEM_2 0xBF
|
|
#define VK_OEM_3 0xC0
|
|
// '/?' for Brazilian (ABNT)
|
|
#define VK_ABNT_C1 0xC1
|
|
// Separator in Numpad for Brazilian (ABNT) or JIS keyboard for Mac.
|
|
#define VK_ABNT_C2 0xC2
|
|
#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
|
|
|
|
class nsIIdleServiceInternal;
|
|
|
|
namespace mozilla {
|
|
namespace widget {
|
|
|
|
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 }
|
|
};
|
|
|
|
class KeyboardLayout;
|
|
|
|
class ModifierKeyState
|
|
{
|
|
public:
|
|
ModifierKeyState();
|
|
ModifierKeyState(bool aIsShiftDown, bool aIsControlDown, bool aIsAltDown);
|
|
ModifierKeyState(Modifiers aModifiers);
|
|
|
|
MOZ_ALWAYS_INLINE void Update();
|
|
|
|
MOZ_ALWAYS_INLINE void Unset(Modifiers aRemovingModifiers);
|
|
void Set(Modifiers aAddingModifiers);
|
|
|
|
void InitInputEvent(WidgetInputEvent& aInputEvent) const;
|
|
|
|
bool IsShift() const;
|
|
bool IsControl() const;
|
|
MOZ_ALWAYS_INLINE bool IsAlt() const;
|
|
MOZ_ALWAYS_INLINE bool IsAltGr() const;
|
|
MOZ_ALWAYS_INLINE bool IsWin() const;
|
|
|
|
MOZ_ALWAYS_INLINE bool IsCapsLocked() const;
|
|
MOZ_ALWAYS_INLINE bool IsNumLocked() const;
|
|
MOZ_ALWAYS_INLINE bool IsScrollLocked() const;
|
|
|
|
MOZ_ALWAYS_INLINE Modifiers GetModifiers() const;
|
|
|
|
private:
|
|
Modifiers mModifiers;
|
|
|
|
MOZ_ALWAYS_INLINE void EnsureAltGr();
|
|
|
|
void InitMouseEvent(WidgetInputEvent& aMouseEvent) const;
|
|
};
|
|
|
|
struct UniCharsAndModifiers
|
|
{
|
|
// Dead-key + up to 4 characters
|
|
char16_t mChars[5];
|
|
Modifiers mModifiers[5];
|
|
uint32_t mLength;
|
|
|
|
UniCharsAndModifiers() : mLength(0) {}
|
|
UniCharsAndModifiers operator+(const UniCharsAndModifiers& aOther) const;
|
|
UniCharsAndModifiers& operator+=(const UniCharsAndModifiers& aOther);
|
|
|
|
/**
|
|
* Append a pair of unicode character and the final modifier.
|
|
*/
|
|
void Append(char16_t aUniChar, Modifiers aModifiers);
|
|
void Clear() { mLength = 0; }
|
|
bool IsEmpty() const { return !mLength; }
|
|
|
|
void FillModifiers(Modifiers aModifiers);
|
|
|
|
bool UniCharsEqual(const UniCharsAndModifiers& aOther) const;
|
|
bool UniCharsCaseInsensitiveEqual(const UniCharsAndModifiers& aOther) const;
|
|
|
|
nsString ToString() const { return nsString(mChars, mLength); }
|
|
};
|
|
|
|
struct DeadKeyEntry;
|
|
class DeadKeyTable;
|
|
|
|
|
|
class VirtualKey
|
|
{
|
|
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
|
|
};
|
|
|
|
typedef uint8_t ShiftState;
|
|
|
|
static ShiftState ModifiersToShiftState(Modifiers aModifiers);
|
|
static Modifiers ShiftStateToModifiers(ShiftState aShiftState);
|
|
|
|
private:
|
|
union KeyShiftState
|
|
{
|
|
struct
|
|
{
|
|
char16_t Chars[4];
|
|
} Normal;
|
|
struct
|
|
{
|
|
const DeadKeyTable* Table;
|
|
char16_t DeadChar;
|
|
} DeadKey;
|
|
};
|
|
|
|
KeyShiftState mShiftStates[16];
|
|
uint16_t mIsDeadKey;
|
|
|
|
void SetDeadKey(ShiftState aShiftState, bool aIsDeadKey)
|
|
{
|
|
if (aIsDeadKey) {
|
|
mIsDeadKey |= 1 << aShiftState;
|
|
} else {
|
|
mIsDeadKey &= ~(1 << aShiftState);
|
|
}
|
|
}
|
|
|
|
public:
|
|
static void FillKbdState(PBYTE aKbdState, const ShiftState aShiftState);
|
|
|
|
bool IsDeadKey(ShiftState aShiftState) const
|
|
{
|
|
return (mIsDeadKey & (1 << aShiftState)) != 0;
|
|
}
|
|
|
|
void AttachDeadKeyTable(ShiftState aShiftState,
|
|
const DeadKeyTable* aDeadKeyTable)
|
|
{
|
|
mShiftStates[aShiftState].DeadKey.Table = aDeadKeyTable;
|
|
}
|
|
|
|
void SetNormalChars(ShiftState aShiftState, const char16_t* aChars,
|
|
uint32_t aNumOfChars);
|
|
void SetDeadChar(ShiftState aShiftState, char16_t aDeadChar);
|
|
const DeadKeyTable* MatchingDeadKeyTable(const DeadKeyEntry* aDeadKeyArray,
|
|
uint32_t aEntries) const;
|
|
inline char16_t GetCompositeChar(ShiftState aShiftState,
|
|
char16_t aBaseChar) const;
|
|
UniCharsAndModifiers GetNativeUniChars(ShiftState aShiftState) const;
|
|
UniCharsAndModifiers GetUniChars(ShiftState aShiftState) const;
|
|
};
|
|
|
|
class MOZ_STACK_CLASS NativeKey
|
|
{
|
|
friend class KeyboardLayout;
|
|
|
|
public:
|
|
struct FakeCharMsg
|
|
{
|
|
UINT mCharCode;
|
|
UINT mScanCode;
|
|
bool mIsDeadKey;
|
|
bool mConsumed;
|
|
|
|
FakeCharMsg() :
|
|
mCharCode(0), mScanCode(0), mIsDeadKey(false), mConsumed(false)
|
|
{
|
|
}
|
|
|
|
MSG GetCharMsg(HWND aWnd) const
|
|
{
|
|
MSG msg;
|
|
msg.hwnd = aWnd;
|
|
msg.message = mIsDeadKey ? WM_DEADCHAR : WM_CHAR;
|
|
msg.wParam = static_cast<WPARAM>(mCharCode);
|
|
msg.lParam = static_cast<LPARAM>(mScanCode << 16);
|
|
msg.time = 0;
|
|
msg.pt.x = msg.pt.y = 0;
|
|
return msg;
|
|
}
|
|
};
|
|
|
|
NativeKey(nsWindowBase* aWidget,
|
|
const MSG& aMessage,
|
|
const ModifierKeyState& aModKeyState,
|
|
nsTArray<FakeCharMsg>* aFakeCharMsgs = nullptr);
|
|
|
|
/**
|
|
* 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.
|
|
*/
|
|
bool HandleKeyDownMessage(bool* aEventDispatched = nullptr) const;
|
|
|
|
/**
|
|
* 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;
|
|
|
|
/**
|
|
* Handles keyup message. Returns true if the event is consumed.
|
|
* Otherwise, false.
|
|
*/
|
|
bool HandleKeyUpMessage(bool* aEventDispatched = nullptr) const;
|
|
|
|
/**
|
|
* Handles WM_APPCOMMAND message. Returns true if the event is consumed.
|
|
* Otherwise, false.
|
|
*/
|
|
bool HandleAppCommandMessage() const;
|
|
|
|
private:
|
|
RefPtr<nsWindowBase> mWidget;
|
|
HKL mKeyboardLayout;
|
|
MSG mMsg;
|
|
|
|
uint32_t mDOMKeyCode;
|
|
KeyNameIndex mKeyNameIndex;
|
|
CodeNameIndex mCodeNameIndex;
|
|
|
|
ModifierKeyState mModKeyState;
|
|
|
|
// mVirtualKeyCode distinguishes left key or right key of modifier key.
|
|
uint8_t 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.
|
|
uint8_t mOriginalVirtualKeyCode;
|
|
|
|
// 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;
|
|
|
|
WORD mScanCode;
|
|
bool mIsExtended;
|
|
bool mIsDeadKey;
|
|
// 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.
|
|
bool mIsPrintableKey;
|
|
|
|
nsTArray<FakeCharMsg>* mFakeCharMsgs;
|
|
|
|
// 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;
|
|
|
|
NativeKey()
|
|
{
|
|
MOZ_CRASH("The default constructor of NativeKey isn't available");
|
|
}
|
|
|
|
void InitWithAppCommand();
|
|
|
|
/**
|
|
* 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:
|
|
return ((mMsg.lParam & (1 << 30)) != 0);
|
|
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;
|
|
default:
|
|
return false;
|
|
}
|
|
}
|
|
|
|
UINT GetScanCodeWithExtendedFlag() const;
|
|
|
|
// The result is one of nsIDOMKeyEvent::DOM_KEY_LOCATION_*.
|
|
uint32_t GetKeyLocation() const;
|
|
|
|
/**
|
|
* "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;
|
|
|
|
bool IsKeyDownMessage() const
|
|
{
|
|
return (mMsg.message == WM_KEYDOWN || mMsg.message == WM_SYSKEYDOWN);
|
|
}
|
|
bool IsKeyUpMessage() const
|
|
{
|
|
return (mMsg.message == WM_KEYUP || mMsg.message == WM_SYSKEYUP);
|
|
}
|
|
bool IsPrintableCharMessage(const MSG& aMSG) const
|
|
{
|
|
return IsPrintableCharMessage(aMSG.message);
|
|
}
|
|
bool IsPrintableCharMessage(UINT aMessage) const
|
|
{
|
|
return (aMessage == WM_CHAR || aMessage == WM_SYSCHAR);
|
|
}
|
|
bool IsCharMessage(const MSG& aMSG) const
|
|
{
|
|
return IsCharMessage(aMSG.message);
|
|
}
|
|
bool IsCharMessage(UINT aMessage) const
|
|
{
|
|
return (IsPrintableCharMessage(aMessage) || IsDeadCharMessage(aMessage));
|
|
}
|
|
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);
|
|
}
|
|
bool MayBeSameCharMessage(const MSG& aCharMsg1, const MSG& aCharMsg2) const;
|
|
bool IsFollowedByDeadCharMessage() const;
|
|
|
|
/**
|
|
* 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.
|
|
*/
|
|
bool GetFollowingCharMessage(MSG& aCharMsg) const;
|
|
|
|
/**
|
|
* Whether the key event can compute virtual keycode from the scancode value.
|
|
*/
|
|
bool CanComputeVirtualKeyCodeFromScanCode() const;
|
|
|
|
/**
|
|
* Wraps MapVirtualKeyEx() with MAPVK_VSC_TO_VK.
|
|
*/
|
|
uint8_t ComputeVirtualKeyCodeFromScanCode() const;
|
|
|
|
/**
|
|
* Wraps MapVirtualKeyEx() with MAPVK_VSC_TO_VK_EX.
|
|
*/
|
|
uint8_t ComputeVirtualKeyCodeFromScanCodeEx() const;
|
|
|
|
/**
|
|
* Wraps MapVirtualKeyEx() with MAPVK_VK_TO_VSC_EX or MAPVK_VK_TO_VSC.
|
|
*/
|
|
uint16_t ComputeScanCodeExFromVirtualKeyCode(UINT aVirtualKeyCode) const;
|
|
|
|
/**
|
|
* Wraps MapVirtualKeyEx() with MAPVK_VSC_TO_VK and MAPVK_VK_TO_CHAR.
|
|
*/
|
|
char16_t ComputeUnicharFromScanCode() const;
|
|
|
|
/**
|
|
* Initializes the aKeyEvent with the information stored in the instance.
|
|
*/
|
|
void InitKeyEvent(WidgetKeyboardEvent& aKeyEvent,
|
|
const ModifierKeyState& aModKeyState) const;
|
|
void InitKeyEvent(WidgetKeyboardEvent& aKeyEvent) const;
|
|
|
|
/**
|
|
* Dispatches a command event for aEventCommand.
|
|
* Returns true if the event is consumed. Otherwise, false.
|
|
*/
|
|
bool DispatchCommandEvent(uint32_t aEventCommand) const;
|
|
|
|
/**
|
|
* Dispatches the key event. Returns true if the event is consumed.
|
|
* Otherwise, false.
|
|
*/
|
|
bool DispatchKeyEvent(WidgetKeyboardEvent& aKeyEvent,
|
|
const MSG* aMsgSentToPlugin = nullptr) const;
|
|
|
|
/**
|
|
* DispatchKeyPressEventsWithKeyboardLayout() dispatches keypress event(s)
|
|
* with the information provided by KeyboardLayout class.
|
|
*/
|
|
bool DispatchKeyPressEventsWithKeyboardLayout() const;
|
|
|
|
/**
|
|
* Remove all following WM_CHAR, WM_SYSCHAR and WM_DEADCHAR messages for the
|
|
* WM_KEYDOWN or WM_SYSKEYDOWN message. Additionally, dispatches plugin
|
|
* events if it's necessary.
|
|
* Returns true if the widget is destroyed. Otherwise, false.
|
|
*/
|
|
bool DispatchPluginEventsAndDiscardsCharMessages() const;
|
|
|
|
/**
|
|
* DispatchKeyPressEventForFollowingCharMessage() dispatches keypress event
|
|
* for following WM_*CHAR message which is removed and set to aCharMsg.
|
|
* Returns true if the event is consumed. Otherwise, false.
|
|
*/
|
|
bool DispatchKeyPressEventForFollowingCharMessage(const MSG& aCharMsg) const;
|
|
|
|
/**
|
|
* 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;
|
|
};
|
|
|
|
class KeyboardLayout
|
|
{
|
|
friend class NativeKey;
|
|
|
|
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 : 1;
|
|
bool mIsPendingToRestoreKeyboardLayout : 1;
|
|
|
|
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);
|
|
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);
|
|
|
|
public:
|
|
static KeyboardLayout* GetInstance();
|
|
static void Shutdown();
|
|
static void NotifyIdleServiceOfUserActivity();
|
|
|
|
static bool IsPrintableCharKey(uint8_t aVirtualKey);
|
|
|
|
/**
|
|
* IsDeadKey() returns true if aVirtualKey is a dead key with aModKeyState.
|
|
* This method isn't stateful.
|
|
*/
|
|
bool IsDeadKey(uint8_t aVirtualKey,
|
|
const ModifierKeyState& aModKeyState) const;
|
|
|
|
/**
|
|
* GetUniCharsAndModifiers() returns characters which is inputted by the
|
|
* aVirtualKey with aModKeyState. This method isn't stateful.
|
|
*/
|
|
UniCharsAndModifiers GetUniCharsAndModifiers(
|
|
uint8_t aVirtualKey,
|
|
const ModifierKeyState& aModKeyState) const;
|
|
|
|
/**
|
|
* 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.
|
|
*/
|
|
void OnLayoutChange(HKL aKeyboardLayout)
|
|
{
|
|
MOZ_ASSERT(!mIsOverridden);
|
|
LoadLayout(aKeyboardLayout);
|
|
}
|
|
|
|
/**
|
|
* OverrideLayout() loads the specified keyboard layout.
|
|
*/
|
|
void OverrideLayout(HKL aLayout)
|
|
{
|
|
mIsOverridden = true;
|
|
LoadLayout(aLayout);
|
|
}
|
|
|
|
/**
|
|
* RestoreLayout() loads the current keyboard layout of the thread.
|
|
*/
|
|
void RestoreLayout()
|
|
{
|
|
mIsOverridden = false;
|
|
mIsPendingToRestoreKeyboardLayout = true;
|
|
}
|
|
|
|
uint32_t ConvertNativeKeyCodeToDOMKeyCode(UINT aNativeKeyCode) const;
|
|
|
|
/**
|
|
* ConvertNativeKeyCodeToKeyNameIndex() returns KeyNameIndex value for
|
|
* non-printable keys (except some special keys like space key).
|
|
*/
|
|
KeyNameIndex ConvertNativeKeyCodeToKeyNameIndex(uint8_t aVirtualKey) const;
|
|
|
|
/**
|
|
* ConvertScanCodeToCodeNameIndex() returns CodeNameIndex value for
|
|
* the given scan code. aScanCode can be over 0xE000 since this method
|
|
* doesn't use Windows API.
|
|
*/
|
|
static CodeNameIndex ConvertScanCodeToCodeNameIndex(UINT aScanCode);
|
|
|
|
HKL GetLayout() const
|
|
{
|
|
return mIsPendingToRestoreKeyboardLayout ? ::GetKeyboardLayout(0) :
|
|
mKeyboardLayout;
|
|
}
|
|
|
|
/**
|
|
* This wraps MapVirtualKeyEx() API with MAPVK_VK_TO_VSC.
|
|
*/
|
|
WORD ComputeScanCodeForVirtualKeyCode(uint8_t aVirtualKeyCode) const;
|
|
|
|
/**
|
|
* Implementation of nsIWidget::SynthesizeNativeKeyEvent().
|
|
*/
|
|
nsresult SynthesizeNativeKeyEvent(nsWindowBase* aWidget,
|
|
int32_t aNativeKeyboardLayout,
|
|
int32_t aNativeKeyCode,
|
|
uint32_t aModifierFlags,
|
|
const nsAString& aCharacters,
|
|
const nsAString& aUnmodifiedCharacters);
|
|
};
|
|
|
|
class RedirectedKeyDownMessageManager
|
|
{
|
|
public:
|
|
/*
|
|
* If a window receives WM_KEYDOWN message or WM_SYSKEYDOWM message which is
|
|
* a redirected message, NativeKey::DispatchKeyDownAndKeyPressEvent()
|
|
* prevents to dispatch eKeyDown event because it has been dispatched
|
|
* 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.
|
|
*/
|
|
class MOZ_STACK_CLASS AutoFlusher final
|
|
{
|
|
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;
|
|
RefPtr<nsWindowBase> mWidget;
|
|
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;
|
|
};
|
|
|
|
} // namespace widget
|
|
} // namespace mozilla
|
|
|
|
#endif
|