зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1297985 part.1 Log KeybordLayout::LoadLayout() to help developers to understand what data is created r=m_kato
It's difficult to understand what data is created by KeyboardLayout::LoadLayout(). So, for understanding what data is created, let's add logging code into it. MozReview-Commit-ID: CelxyVpGn5f --HG-- extra : rebase_source : fd8f15a42c4c2b4c1f1079184060c6e5f796ac5a
This commit is contained in:
Родитель
36b32a22e9
Коммит
af458c6eea
|
@ -138,6 +138,171 @@ static const char* kVirtualKeyName[] = {
|
|||
static_assert(sizeof(kVirtualKeyName) / sizeof(const char*) == 0x100,
|
||||
"The virtual key name must be defined just 256 keys");
|
||||
|
||||
static const nsCString
|
||||
GetCharacterCodeName(WPARAM aCharCode)
|
||||
{
|
||||
switch (aCharCode) {
|
||||
case 0x0000:
|
||||
return NS_LITERAL_CSTRING("NULL (0x0000)");
|
||||
case 0x0008:
|
||||
return NS_LITERAL_CSTRING("BACKSPACE (0x0008)");
|
||||
case 0x0009:
|
||||
return NS_LITERAL_CSTRING("CHARACTER TABULATION (0x0009)");
|
||||
case 0x000A:
|
||||
return NS_LITERAL_CSTRING("LINE FEED (0x000A)");
|
||||
case 0x000B:
|
||||
return NS_LITERAL_CSTRING("LINE TABULATION (0x000B)");
|
||||
case 0x000C:
|
||||
return NS_LITERAL_CSTRING("FORM FEED (0x000C)");
|
||||
case 0x000D:
|
||||
return NS_LITERAL_CSTRING("CARRIAGE RETURN (0x000D)");
|
||||
case 0x0018:
|
||||
return NS_LITERAL_CSTRING("CANCEL (0x0018)");
|
||||
case 0x001B:
|
||||
return NS_LITERAL_CSTRING("ESCAPE (0x001B)");
|
||||
case 0x0020:
|
||||
return NS_LITERAL_CSTRING("SPACE (0x0020)");
|
||||
case 0x007F:
|
||||
return NS_LITERAL_CSTRING("DELETE (0x007F)");
|
||||
case 0x00A0:
|
||||
return NS_LITERAL_CSTRING("NO-BREAK SPACE (0x00A0)");
|
||||
case 0x00AD:
|
||||
return NS_LITERAL_CSTRING("SOFT HYPHEN (0x00AD)");
|
||||
case 0x2000:
|
||||
return NS_LITERAL_CSTRING("EN QUAD (0x2000)");
|
||||
case 0x2001:
|
||||
return NS_LITERAL_CSTRING("EM QUAD (0x2001)");
|
||||
case 0x2002:
|
||||
return NS_LITERAL_CSTRING("EN SPACE (0x2002)");
|
||||
case 0x2003:
|
||||
return NS_LITERAL_CSTRING("EM SPACE (0x2003)");
|
||||
case 0x2004:
|
||||
return NS_LITERAL_CSTRING("THREE-PER-EM SPACE (0x2004)");
|
||||
case 0x2005:
|
||||
return NS_LITERAL_CSTRING("FOUR-PER-EM SPACE (0x2005)");
|
||||
case 0x2006:
|
||||
return NS_LITERAL_CSTRING("SIX-PER-EM SPACE (0x2006)");
|
||||
case 0x2007:
|
||||
return NS_LITERAL_CSTRING("FIGURE SPACE (0x2007)");
|
||||
case 0x2008:
|
||||
return NS_LITERAL_CSTRING("PUNCTUATION SPACE (0x2008)");
|
||||
case 0x2009:
|
||||
return NS_LITERAL_CSTRING("THIN SPACE (0x2009)");
|
||||
case 0x200A:
|
||||
return NS_LITERAL_CSTRING("HAIR SPACE (0x200A)");
|
||||
case 0x200B:
|
||||
return NS_LITERAL_CSTRING("ZERO WIDTH SPACE (0x200B)");
|
||||
case 0x200C:
|
||||
return NS_LITERAL_CSTRING("ZERO WIDTH NON-JOINER (0x200C)");
|
||||
case 0x200D:
|
||||
return NS_LITERAL_CSTRING("ZERO WIDTH JOINER (0x200D)");
|
||||
case 0x200E:
|
||||
return NS_LITERAL_CSTRING("LEFT-TO-RIGHT MARK (0x200E)");
|
||||
case 0x200F:
|
||||
return NS_LITERAL_CSTRING("RIGHT-TO-LEFT MARK (0x200F)");
|
||||
case 0x2029:
|
||||
return NS_LITERAL_CSTRING("PARAGRAPH SEPARATOR (0x2029)");
|
||||
case 0x202A:
|
||||
return NS_LITERAL_CSTRING("LEFT-TO-RIGHT EMBEDDING (0x202A)");
|
||||
case 0x202B:
|
||||
return NS_LITERAL_CSTRING("RIGHT-TO-LEFT EMBEDDING (0x202B)");
|
||||
case 0x202D:
|
||||
return NS_LITERAL_CSTRING("LEFT-TO-RIGHT OVERRIDE (0x202D)");
|
||||
case 0x202E:
|
||||
return NS_LITERAL_CSTRING("RIGHT-TO-LEFT OVERRIDE (0x202E)");
|
||||
case 0x202F:
|
||||
return NS_LITERAL_CSTRING("NARROW NO-BREAK SPACE (0x202F)");
|
||||
case 0x205F:
|
||||
return NS_LITERAL_CSTRING("MEDIUM MATHEMATICAL SPACE (0x205F)");
|
||||
case 0x2060:
|
||||
return NS_LITERAL_CSTRING("WORD JOINER (0x2060)");
|
||||
case 0x2066:
|
||||
return NS_LITERAL_CSTRING("LEFT-TO-RIGHT ISOLATE (0x2066)");
|
||||
case 0x2067:
|
||||
return NS_LITERAL_CSTRING("RIGHT-TO-LEFT ISOLATE (0x2067)");
|
||||
case 0x3000:
|
||||
return NS_LITERAL_CSTRING("IDEOGRAPHIC SPACE (0x3000)");
|
||||
case 0xFEFF:
|
||||
return NS_LITERAL_CSTRING("ZERO WIDTH NO-BREAK SPACE (0xFEFF)");
|
||||
default: {
|
||||
if (aCharCode < ' ' ||
|
||||
(aCharCode >= 0x80 && aCharCode < 0xA0)) {
|
||||
return nsPrintfCString("control (0x%04X)", aCharCode);
|
||||
}
|
||||
if (NS_IS_HIGH_SURROGATE(aCharCode)) {
|
||||
return nsPrintfCString("high surrogate (0x%04X)", aCharCode);
|
||||
}
|
||||
if (NS_IS_LOW_SURROGATE(aCharCode)) {
|
||||
return nsPrintfCString("low surrogate (0x%04X)", aCharCode);
|
||||
}
|
||||
return IS_IN_BMP(aCharCode) ?
|
||||
nsPrintfCString("'%s' (0x%04X)",
|
||||
NS_ConvertUTF16toUTF8(nsAutoString(aCharCode)).get(), aCharCode) :
|
||||
nsPrintfCString("'%s' (0x%08X)",
|
||||
NS_ConvertUTF16toUTF8(nsAutoString(aCharCode)).get(), aCharCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static const nsCString
|
||||
GetCharacterCodeName(char16_t* aChars, uint32_t aLength)
|
||||
{
|
||||
if (!aLength) {
|
||||
return NS_LITERAL_CSTRING("");
|
||||
}
|
||||
nsAutoCString result;
|
||||
for (uint32_t i = 0; i < aLength; ++i) {
|
||||
if (!result.IsEmpty()) {
|
||||
result.AppendLiteral(", ");
|
||||
} else {
|
||||
result.AssignLiteral("\"");
|
||||
}
|
||||
result.Append(GetCharacterCodeName(aChars[i]));
|
||||
}
|
||||
result.AppendLiteral("\"");
|
||||
return result;
|
||||
}
|
||||
|
||||
class MOZ_STACK_CLASS GetShiftStateName final : public nsAutoCString
|
||||
{
|
||||
public:
|
||||
explicit GetShiftStateName(VirtualKey::ShiftState aShiftState)
|
||||
{
|
||||
if (!aShiftState) {
|
||||
AssignLiteral("none");
|
||||
return;
|
||||
}
|
||||
if (aShiftState & VirtualKey::STATE_SHIFT) {
|
||||
AssignLiteral("Shift");
|
||||
aShiftState &= ~VirtualKey::STATE_SHIFT;
|
||||
}
|
||||
if (aShiftState & VirtualKey::STATE_CONTROL) {
|
||||
MaybeAppendSeparator();
|
||||
AssignLiteral("Ctrl");
|
||||
aShiftState &= ~VirtualKey::STATE_CONTROL;
|
||||
}
|
||||
if (aShiftState & VirtualKey::STATE_ALT) {
|
||||
MaybeAppendSeparator();
|
||||
AssignLiteral("Alt");
|
||||
aShiftState &= ~VirtualKey::STATE_ALT;
|
||||
}
|
||||
if (aShiftState & VirtualKey::STATE_CAPSLOCK) {
|
||||
MaybeAppendSeparator();
|
||||
AssignLiteral("CapsLock");
|
||||
aShiftState &= ~VirtualKey::STATE_CAPSLOCK;
|
||||
}
|
||||
MOZ_ASSERT(!aShiftState);
|
||||
}
|
||||
|
||||
private:
|
||||
void MaybeAppendSeparator()
|
||||
{
|
||||
if (!IsEmpty()) {
|
||||
AppendLiteral(" | ");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Unique id counter associated with a keydown / keypress events. Used in
|
||||
// identifing keypress events for removal from async event dispatch queue
|
||||
// in metrofx after preventDefault is called on keydown events.
|
||||
|
@ -2520,6 +2685,10 @@ NativeKey::DispatchKeyPressEventForFollowingCharMessage(
|
|||
KeyboardLayout* KeyboardLayout::sInstance = nullptr;
|
||||
nsIIdleServiceInternal* KeyboardLayout::sIdleService = nullptr;
|
||||
|
||||
// This log is very noisy if you don't want to retrieve the mapping table
|
||||
// of specific keyboard layout. LogLevel::Debug and LogLevel::Verbose are
|
||||
// used to log the layout mapping. If you need to log some behavior of
|
||||
// KeyboardLayout class, you should use LogLevel::Info or lower level.
|
||||
LazyLogModule sKeyboardLayoutLogger("KeyboardLayoutWidgets");
|
||||
|
||||
// static
|
||||
|
@ -2779,6 +2948,9 @@ KeyboardLayout::LoadLayout(HKL aLayout)
|
|||
|
||||
mKeyboardLayout = aLayout;
|
||||
|
||||
MOZ_LOG(sKeyboardLayoutLogger, LogLevel::Debug,
|
||||
("KeyboardLayout::LoadLayout(aLayout=0x%08X)", aLayout));
|
||||
|
||||
BYTE kbdState[256];
|
||||
memset(kbdState, 0, sizeof(kbdState));
|
||||
|
||||
|
@ -2820,12 +2992,23 @@ KeyboardLayout::LoadLayout(HKL aLayout)
|
|||
ArrayLength(deadChar), 0, mKeyboardLayout);
|
||||
NS_ASSERTION(ret == 2, "Expecting twice repeated dead-key character");
|
||||
mVirtualKeys[vki].SetDeadChar(shiftState, deadChar[0]);
|
||||
|
||||
MOZ_LOG(sKeyboardLayoutLogger, LogLevel::Debug,
|
||||
(" %s (%d): DeadChar(%s, %s) (ret=%d)",
|
||||
kVirtualKeyName[virtualKey], vki,
|
||||
GetShiftStateName(shiftState).get(),
|
||||
GetCharacterCodeName(deadChar, 1).get(), ret));
|
||||
} else {
|
||||
if (ret == 1) {
|
||||
// dead-key can pair only with exactly one base character.
|
||||
shiftStatesWithBaseChars |= (1 << shiftState);
|
||||
}
|
||||
mVirtualKeys[vki].SetNormalChars(shiftState, uniChars, ret);
|
||||
MOZ_LOG(sKeyboardLayoutLogger, LogLevel::Verbose,
|
||||
(" %s (%d): NormalChar(%s, %s) (ret=%d)",
|
||||
kVirtualKeyName[virtualKey], vki,
|
||||
GetShiftStateName(shiftState).get(),
|
||||
GetCharacterCodeName(uniChars, ret).get(), ret));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2859,20 +3042,20 @@ KeyboardLayout::LoadLayout(HKL aLayout)
|
|||
|
||||
::SetKeyboardState(originalKbdState);
|
||||
|
||||
if (MOZ_LOG_TEST(sKeyboardLayoutLogger, LogLevel::Debug)) {
|
||||
if (MOZ_LOG_TEST(sKeyboardLayoutLogger, LogLevel::Verbose)) {
|
||||
static const UINT kExtendedScanCode[] = { 0x0000, 0xE000 };
|
||||
static const UINT kMapType =
|
||||
IsVistaOrLater() ? MAPVK_VSC_TO_VK_EX : MAPVK_VSC_TO_VK;
|
||||
MOZ_LOG(sKeyboardLayoutLogger, LogLevel::Debug,
|
||||
("Logging virtual keycode values for scancode (0x%p)...",
|
||||
mKeyboardLayout));
|
||||
MOZ_LOG(sKeyboardLayoutLogger, LogLevel::Verbose,
|
||||
("Logging virtual keycode values for scancode (0x%p)...",
|
||||
mKeyboardLayout));
|
||||
for (uint32_t i = 0; i < ArrayLength(kExtendedScanCode); i++) {
|
||||
for (uint32_t j = 1; j <= 0xFF; j++) {
|
||||
UINT scanCode = kExtendedScanCode[i] + j;
|
||||
UINT virtualKeyCode =
|
||||
::MapVirtualKeyEx(scanCode, kMapType, mKeyboardLayout);
|
||||
MOZ_LOG(sKeyboardLayoutLogger, LogLevel::Debug,
|
||||
("0x%04X, %s", scanCode, kVirtualKeyName[virtualKeyCode]));
|
||||
MOZ_LOG(sKeyboardLayoutLogger, LogLevel::Verbose,
|
||||
("0x%04X, %s", scanCode, kVirtualKeyName[virtualKeyCode]));
|
||||
}
|
||||
// XP and Server 2003 don't support 0xE0 prefix of the scancode.
|
||||
// Therefore, we don't need to continue on them.
|
||||
|
@ -3100,6 +3283,12 @@ KeyboardLayout::GetDeadKeyCombinations(uint8_t aDeadKey,
|
|||
entries++;
|
||||
}
|
||||
deadKeyActive = false;
|
||||
MOZ_LOG(sKeyboardLayoutLogger, LogLevel::Debug,
|
||||
(" %s -> %s (%d): DeadKeyEntry(%s, %s) (ret=%d)",
|
||||
kVirtualKeyName[aDeadKey], kVirtualKeyName[virtualKey], vki,
|
||||
GetCharacterCodeName(compositeChars, 1).get(),
|
||||
ret <= 0 ? "''" :
|
||||
GetCharacterCodeName(baseChars, std::min(ret, 5)).get(), ret));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
@ -3107,6 +3296,12 @@ KeyboardLayout::GetDeadKeyCombinations(uint8_t aDeadKey,
|
|||
// 2. More than one character generated. This is not a valid
|
||||
// dead-key and base character combination.
|
||||
deadKeyActive = false;
|
||||
MOZ_LOG(sKeyboardLayoutLogger, LogLevel::Verbose,
|
||||
(" %s -> %s (%d): Unsupport dead key type(%s) (ret=%d)",
|
||||
kVirtualKeyName[aDeadKey], kVirtualKeyName[virtualKey], vki,
|
||||
ret <= 0 ? "''" :
|
||||
GetCharacterCodeName(compositeChars,
|
||||
std::min(ret, 5)).get(), ret));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче