Bug 574340 Cleaning up nsKeyboardLayout which doesn't use our coding style. Part.3 Use our control structure coding style r=jmatheis, a2=joe

This commit is contained in:
Masayuki Nakano 2010-07-27 21:49:37 +09:00
parent 4e4998c0f7
commit 8ad57f5b44
2 changed files with 103 additions and 125 deletions

View File

@ -105,17 +105,17 @@ const DeadKeyTable*
VirtualKey::MatchingDeadKeyTable(const DeadKeyEntry* aDeadKeyArray, VirtualKey::MatchingDeadKeyTable(const DeadKeyEntry* aDeadKeyArray,
PRUint32 aEntries) const PRUint32 aEntries) const
{ {
if (!mIsDeadKey) if (!mIsDeadKey) {
return nsnull; return nsnull;
}
for (PRUint32 shiftState = 0; shiftState < 16; shiftState++) for (PRUint32 shiftState = 0; shiftState < 16; shiftState++) {
{ if (IsDeadKey(shiftState)) {
if (IsDeadKey(shiftState))
{
const DeadKeyTable* dkt = mShiftStates[shiftState].DeadKey.Table; const DeadKeyTable* dkt = mShiftStates[shiftState].DeadKey.Table;
if (dkt && dkt->IsEqual(aDeadKeyArray, aEntries)) if (dkt && dkt->IsEqual(aDeadKeyArray, aEntries)) {
return dkt; return dkt;
}
} }
} }
@ -130,17 +130,17 @@ VirtualKey::SetNormalChars(PRUint8 aShiftState,
NS_ASSERTION(aShiftState < NS_ARRAY_LENGTH(mShiftStates), "invalid index"); NS_ASSERTION(aShiftState < NS_ARRAY_LENGTH(mShiftStates), "invalid index");
SetDeadKey(aShiftState, PR_FALSE); SetDeadKey(aShiftState, PR_FALSE);
for (PRUint32 c1 = 0; c1 < aNumOfChars; c1++) for (PRUint32 c1 = 0; c1 < aNumOfChars; c1++) {
{
// Ignore legacy non-printable control characters // Ignore legacy non-printable control characters
mShiftStates[aShiftState].Normal.Chars[c1] = mShiftStates[aShiftState].Normal.Chars[c1] =
(aChars[c1] >= 0x20) ? aChars[c1] : 0; (aChars[c1] >= 0x20) ? aChars[c1] : 0;
} }
for (PRUint32 c2 = aNumOfChars; for (PRUint32 c2 = aNumOfChars;
c2 < NS_ARRAY_LENGTH(mShiftStates[aShiftState].Normal.Chars); c2++) c2 < NS_ARRAY_LENGTH(mShiftStates[aShiftState].Normal.Chars); c2++) {
mShiftStates[aShiftState].Normal.Chars[c2] = 0; mShiftStates[aShiftState].Normal.Chars[c2] = 0;
}
} }
void void
@ -162,14 +162,12 @@ VirtualKey::GetUniChars(PRUint8 aShiftState,
*aFinalShiftState = aShiftState; *aFinalShiftState = aShiftState;
PRUint32 numOfChars = GetNativeUniChars(aShiftState, aUniChars); PRUint32 numOfChars = GetNativeUniChars(aShiftState, aUniChars);
if (aShiftState & (eAlt | eCtrl)) if (aShiftState & (eAlt | eCtrl)) {
{
PRUnichar unshiftedChars[5]; PRUnichar unshiftedChars[5];
PRUint32 numOfUnshiftedChars = PRUint32 numOfUnshiftedChars =
GetNativeUniChars(aShiftState & ~(eAlt | eCtrl), unshiftedChars); GetNativeUniChars(aShiftState & ~(eAlt | eCtrl), unshiftedChars);
if (numOfChars) if (numOfChars) {
{
if ((aShiftState & (eAlt | eCtrl)) == (eAlt | eCtrl)) { if ((aShiftState & (eAlt | eCtrl)) == (eAlt | eCtrl)) {
// Even if the shifted chars and the unshifted chars are same, we // Even if the shifted chars and the unshifted chars are same, we
// should consume the Alt key state and the Ctrl key state when // should consume the Alt key state and the Ctrl key state when
@ -184,10 +182,8 @@ VirtualKey::GetUniChars(PRUint8 aShiftState,
// only when the shifted chars and unshifted chars are different. // only when the shifted chars and unshifted chars are different.
*aFinalShiftState &= ~(eAlt | eCtrl); *aFinalShiftState &= ~(eAlt | eCtrl);
} }
} else } else {
{ if (numOfUnshiftedChars) {
if (numOfUnshiftedChars)
{
memcpy(aUniChars, unshiftedChars, memcpy(aUniChars, unshiftedChars,
numOfUnshiftedChars * sizeof(PRUnichar)); numOfUnshiftedChars * sizeof(PRUnichar));
numOfChars = numOfUnshiftedChars; numOfChars = numOfUnshiftedChars;
@ -203,27 +199,22 @@ PRUint32
VirtualKey::GetNativeUniChars(PRUint8 aShiftState, VirtualKey::GetNativeUniChars(PRUint8 aShiftState,
PRUnichar* aUniChars) const PRUnichar* aUniChars) const
{ {
if (IsDeadKey(aShiftState)) if (IsDeadKey(aShiftState)) {
{ if (aUniChars) {
if (aUniChars)
aUniChars[0] = mShiftStates[aShiftState].DeadKey.DeadChar; aUniChars[0] = mShiftStates[aShiftState].DeadKey.DeadChar;
return 1;
} else
{
PRUint32 cnt = 0;
while (cnt < NS_ARRAY_LENGTH(mShiftStates[aShiftState].Normal.Chars) &&
mShiftStates[aShiftState].Normal.Chars[cnt])
{
if (aUniChars)
aUniChars[cnt] = mShiftStates[aShiftState].Normal.Chars[cnt];
cnt++;
} }
return 1;
return cnt;
} }
PRUint32 cnt = 0;
while (cnt < NS_ARRAY_LENGTH(mShiftStates[aShiftState].Normal.Chars) &&
mShiftStates[aShiftState].Normal.Chars[cnt]) {
if (aUniChars) {
aUniChars[cnt] = mShiftStates[aShiftState].Normal.Chars[cnt];
}
cnt++;
}
return cnt;
} }
KeyboardLayout::KeyboardLayout() : KeyboardLayout::KeyboardLayout() :
@ -258,23 +249,18 @@ KeyboardLayout::OnKeyDown(PRUint8 aVirtualKey)
{ {
mLastVirtualKeyIndex = GetKeyIndex(aVirtualKey); mLastVirtualKeyIndex = GetKeyIndex(aVirtualKey);
if (mLastVirtualKeyIndex < 0) if (mLastVirtualKeyIndex < 0) {
{
// Does not produce any printable characters, but still preserves the // Does not produce any printable characters, but still preserves the
// dead-key state. // dead-key state.
mNumOfChars = 0; mNumOfChars = 0;
} else } else {
{
BYTE kbdState[256]; BYTE kbdState[256];
if (::GetKeyboardState(kbdState)) if (::GetKeyboardState(kbdState)) {
{
mLastShiftState = GetShiftState(kbdState); mLastShiftState = GetShiftState(kbdState);
if (mVirtualKeys[mLastVirtualKeyIndex].IsDeadKey(mLastShiftState)) if (mVirtualKeys[mLastVirtualKeyIndex].IsDeadKey(mLastShiftState)) {
{ if (mActiveDeadKey >= 0) {
if (mActiveDeadKey >= 0)
{
// Dead-key followed by another dead-key. Reset dead-key state and // Dead-key followed by another dead-key. Reset dead-key state and
// return both dead-key characters. // return both dead-key characters.
PRInt32 activeDeadKeyIndex = GetKeyIndex(mActiveDeadKey); PRInt32 activeDeadKeyIndex = GetKeyIndex(mActiveDeadKey);
@ -286,15 +272,13 @@ KeyboardLayout::OnKeyDown(PRUint8 aVirtualKey)
mNumOfChars = 2; mNumOfChars = 2;
DeactivateDeadKeyState(); DeactivateDeadKeyState();
} else } else {
{
// Dead-key state activated. No characters generated. // Dead-key state activated. No characters generated.
mActiveDeadKey = aVirtualKey; mActiveDeadKey = aVirtualKey;
mDeadKeyShiftState = mLastShiftState; mDeadKeyShiftState = mLastShiftState;
mNumOfChars = 0; mNumOfChars = 0;
} }
} else } else {
{
PRUint8 finalShiftState; PRUint8 finalShiftState;
PRUnichar uniChars[5]; PRUnichar uniChars[5];
PRUint32 numOfBaseChars = PRUint32 numOfBaseChars =
@ -302,25 +286,22 @@ KeyboardLayout::OnKeyDown(PRUint8 aVirtualKey)
uniChars, uniChars,
&finalShiftState); &finalShiftState);
if (mActiveDeadKey >= 0) if (mActiveDeadKey >= 0) {
{
PRInt32 activeDeadKeyIndex = GetKeyIndex(mActiveDeadKey); PRInt32 activeDeadKeyIndex = GetKeyIndex(mActiveDeadKey);
// Dead-key was active. See if pressed base character does produce // Dead-key was active. See if pressed base character does produce
// valid composite character. // valid composite character.
PRUnichar compositeChar = (numOfBaseChars == 1 && uniChars[0]) ? PRUnichar compositeChar = (numOfBaseChars == 1 && uniChars[0]) ?
mVirtualKeys[activeDeadKeyIndex]. mVirtualKeys[activeDeadKeyIndex].
GetCompositeChar(mDeadKeyShiftState, uniChars[0]) : 0; GetCompositeChar(mDeadKeyShiftState, uniChars[0]) : 0;
if (compositeChar) if (compositeChar) {
{
// Active dead-key and base character does produce exactly one // Active dead-key and base character does produce exactly one
// composite character. // composite character.
mChars[0] = compositeChar; mChars[0] = compositeChar;
mShiftStates[0] = finalShiftState; mShiftStates[0] = finalShiftState;
mNumOfChars = 1; mNumOfChars = 1;
} else } else {
{
// There is no valid dead-key and base character combination. // There is no valid dead-key and base character combination.
// Return dead-key character followed by base character. // Return dead-key character followed by base character.
mVirtualKeys[activeDeadKeyIndex].GetUniChars(mDeadKeyShiftState, mVirtualKeys[activeDeadKeyIndex].GetUniChars(mDeadKeyShiftState,
@ -331,8 +312,7 @@ KeyboardLayout::OnKeyDown(PRUint8 aVirtualKey)
} }
DeactivateDeadKeyState(); DeactivateDeadKeyState();
} else } else {
{
// No dead-keys are active. Just return the produced characters. // No dead-keys are active. Just return the produced characters.
memcpy(mChars, uniChars, numOfBaseChars * sizeof(PRUnichar)); memcpy(mChars, uniChars, numOfBaseChars * sizeof(PRUnichar));
memset(mShiftStates, finalShiftState, numOfBaseChars); memset(mShiftStates, finalShiftState, numOfBaseChars);
@ -363,8 +343,9 @@ KeyboardLayout::GetUniCharsWithShiftState(PRUint8 aVirtualKey,
PRUint32 aMaxChars) const PRUint32 aMaxChars) const
{ {
PRInt32 key = GetKeyIndex(aVirtualKey); PRInt32 key = GetKeyIndex(aVirtualKey);
if (key < 0) if (key < 0) {
return 0; return 0;
}
PRUint8 finalShiftState; PRUint8 finalShiftState;
PRUnichar uniChars[5]; PRUnichar uniChars[5];
PRUint32 numOfBaseChars = PRUint32 numOfBaseChars =
@ -379,8 +360,9 @@ KeyboardLayout::GetUniCharsWithShiftState(PRUint8 aVirtualKey,
void void
KeyboardLayout::LoadLayout(HKL aLayout) KeyboardLayout::LoadLayout(HKL aLayout)
{ {
if (mKeyboardLayout == aLayout) if (mKeyboardLayout == aLayout) {
return; return;
}
mKeyboardLayout = aLayout; mKeyboardLayout = aLayout;
@ -405,15 +387,14 @@ KeyboardLayout::LoadLayout(HKL aLayout)
// For each shift state gather all printable characters that are produced // For each shift state gather all printable characters that are produced
// for normal case when no any dead-key is active. // for normal case when no any dead-key is active.
for (shiftState = 0; shiftState < 16; shiftState++) for (shiftState = 0; shiftState < 16; shiftState++) {
{
SetShiftState(kbdState, shiftState); SetShiftState(kbdState, shiftState);
for (PRUint32 virtualKey = 0; virtualKey < 256; virtualKey++) for (PRUint32 virtualKey = 0; virtualKey < 256; virtualKey++) {
{
PRInt32 vki = GetKeyIndex(virtualKey); PRInt32 vki = GetKeyIndex(virtualKey);
if (vki < 0) if (vki < 0) {
continue; continue;
}
NS_ASSERTION(vki < NS_ARRAY_LENGTH(mVirtualKeys), "invalid index"); NS_ASSERTION(vki < NS_ARRAY_LENGTH(mVirtualKeys), "invalid index");
@ -423,10 +404,10 @@ KeyboardLayout::LoadLayout(HKL aLayout)
rv = ::ToUnicodeEx(virtualKey, 0, kbdState, (LPWSTR)uniChars, rv = ::ToUnicodeEx(virtualKey, 0, kbdState, (LPWSTR)uniChars,
NS_ARRAY_LENGTH(uniChars), 0, mKeyboardLayout); NS_ARRAY_LENGTH(uniChars), 0, mKeyboardLayout);
if (rv < 0) // dead-key // dead-key
{ if (rv < 0) {
shiftStatesWithDeadKeys |= 1 << shiftState; shiftStatesWithDeadKeys |= 1 << shiftState;
// Repeat dead-key to deactivate it and get its character // Repeat dead-key to deactivate it and get its character
// representation. // representation.
PRUnichar deadChar[2]; PRUnichar deadChar[2];
@ -437,8 +418,7 @@ KeyboardLayout::LoadLayout(HKL aLayout)
NS_ASSERTION(rv == 2, "Expecting twice repeated dead-key character"); NS_ASSERTION(rv == 2, "Expecting twice repeated dead-key character");
mVirtualKeys[vki].SetDeadChar(shiftState, deadChar[0]); mVirtualKeys[vki].SetDeadChar(shiftState, deadChar[0]);
} else } else {
{
if (rv == 1) { if (rv == 1) {
// dead-key can pair only with exactly one base character. // dead-key can pair only with exactly one base character.
shiftStatesWithBaseChars |= 1 << shiftState; shiftStatesWithBaseChars |= 1 << shiftState;
@ -453,19 +433,17 @@ KeyboardLayout::LoadLayout(HKL aLayout)
// Now process each dead-key to find all its base characters and resulting // Now process each dead-key to find all its base characters and resulting
// composite characters. // composite characters.
for (shiftState = 0; shiftState < 16; shiftState++) for (shiftState = 0; shiftState < 16; shiftState++) {
{ if (!(shiftStatesWithDeadKeys & (1 << shiftState))) {
if (!(shiftStatesWithDeadKeys & (1 << shiftState)))
continue; continue;
}
SetShiftState(kbdState, shiftState); SetShiftState(kbdState, shiftState);
for (PRUint32 virtualKey = 0; virtualKey < 256; virtualKey++) for (PRUint32 virtualKey = 0; virtualKey < 256; virtualKey++) {
{
PRInt32 vki = GetKeyIndex(virtualKey); PRInt32 vki = GetKeyIndex(virtualKey);
if (vki >= 0 && mVirtualKeys[vki].IsDeadKey(shiftState)) if (vki >= 0 && mVirtualKeys[vki].IsDeadKey(shiftState)) {
{
DeadKeyEntry deadKeyArray[256]; DeadKeyEntry deadKeyArray[256];
PRInt32 n = GetDeadKeyCombinations(virtualKey, kbdState, PRInt32 n = GetDeadKeyCombinations(virtualKey, kbdState,
@ -476,9 +454,10 @@ KeyboardLayout::LoadLayout(HKL aLayout)
const DeadKeyTable* dkt = const DeadKeyTable* dkt =
mVirtualKeys[vki].MatchingDeadKeyTable(deadKeyArray, n); mVirtualKeys[vki].MatchingDeadKeyTable(deadKeyArray, n);
if (!dkt) if (!dkt) {
dkt = AddDeadKeyTable(deadKeyArray, n); dkt = AddDeadKeyTable(deadKeyArray, n);
}
mVirtualKeys[vki].AttachDeadKeyTable(shiftState, dkt); mVirtualKeys[vki].AttachDeadKeyTable(shiftState, dkt);
} }
} }
@ -504,37 +483,35 @@ KeyboardLayout::SetShiftState(PBYTE aKbdState, PRUint8 aShiftState)
{ {
NS_ASSERTION(aShiftState < 16, "aShiftState out of range"); NS_ASSERTION(aShiftState < 16, "aShiftState out of range");
if (aShiftState & eShift) if (aShiftState & eShift) {
aKbdState[VK_SHIFT] |= 0x80; aKbdState[VK_SHIFT] |= 0x80;
else } else {
{
aKbdState[VK_SHIFT] &= ~0x80; aKbdState[VK_SHIFT] &= ~0x80;
aKbdState[VK_LSHIFT] &= ~0x80; aKbdState[VK_LSHIFT] &= ~0x80;
aKbdState[VK_RSHIFT] &= ~0x80; aKbdState[VK_RSHIFT] &= ~0x80;
} }
if (aShiftState & eCtrl) if (aShiftState & eCtrl) {
aKbdState[VK_CONTROL] |= 0x80; aKbdState[VK_CONTROL] |= 0x80;
else } else {
{
aKbdState[VK_CONTROL] &= ~0x80; aKbdState[VK_CONTROL] &= ~0x80;
aKbdState[VK_LCONTROL] &= ~0x80; aKbdState[VK_LCONTROL] &= ~0x80;
aKbdState[VK_RCONTROL] &= ~0x80; aKbdState[VK_RCONTROL] &= ~0x80;
} }
if (aShiftState & eAlt) if (aShiftState & eAlt) {
aKbdState[VK_MENU] |= 0x80; aKbdState[VK_MENU] |= 0x80;
else } else {
{
aKbdState[VK_MENU] &= ~0x80; aKbdState[VK_MENU] &= ~0x80;
aKbdState[VK_LMENU] &= ~0x80; aKbdState[VK_LMENU] &= ~0x80;
aKbdState[VK_RMENU] &= ~0x80; aKbdState[VK_RMENU] &= ~0x80;
} }
if (aShiftState & eCapsLock) if (aShiftState & eCapsLock) {
aKbdState[VK_CAPITAL] |= 0x01; aKbdState[VK_CAPITAL] |= 0x01;
else } else {
aKbdState[VK_CAPITAL] &= ~0x01; aKbdState[VK_CAPITAL] &= ~0x01;
}
} }
inline PRInt32 inline PRInt32
@ -600,7 +577,7 @@ KeyboardLayout::AddDeadKeyTable(const DeadKeyEntry* aDeadKeyArray,
PRUint32 aEntries) PRUint32 aEntries)
{ {
DeadKeyTableListEntry* next = mDeadKeyTableListHead; DeadKeyTableListEntry* next = mDeadKeyTableListHead;
const size_t bytes = offsetof(DeadKeyTableListEntry, data) + const size_t bytes = offsetof(DeadKeyTableListEntry, data) +
DeadKeyTable::SizeInBytes(aEntries); DeadKeyTable::SizeInBytes(aEntries);
PRUint8* p = new PRUint8[bytes]; PRUint8* p = new PRUint8[bytes];
@ -619,8 +596,7 @@ KeyboardLayout::AddDeadKeyTable(const DeadKeyEntry* aDeadKeyArray,
void void
KeyboardLayout::ReleaseDeadKeyTables() KeyboardLayout::ReleaseDeadKeyTables()
{ {
while (mDeadKeyTableListHead) while (mDeadKeyTableListHead) {
{
PRUint8* p = reinterpret_cast<PRUint8*>(mDeadKeyTableListHead); PRUint8* p = reinterpret_cast<PRUint8*>(mDeadKeyTableListHead);
mDeadKeyTableListHead = mDeadKeyTableListHead->next; mDeadKeyTableListHead = mDeadKeyTableListHead->next;
@ -635,8 +611,7 @@ KeyboardLayout::EnsureDeadKeyActive(PRBool aIsActive,
{ {
PRInt32 rv; PRInt32 rv;
do do {
{
PRUnichar dummyChars[5]; PRUnichar dummyChars[5];
rv = ::ToUnicodeEx(aDeadKey, 0, (PBYTE)aDeadKeyKbdState, (LPWSTR)dummyChars, rv = ::ToUnicodeEx(aDeadKey, 0, (PBYTE)aDeadKeyKbdState, (LPWSTR)dummyChars,
@ -656,9 +631,10 @@ KeyboardLayout::EnsureDeadKeyActive(PRBool aIsActive,
void void
KeyboardLayout::DeactivateDeadKeyState() KeyboardLayout::DeactivateDeadKeyState()
{ {
if (mActiveDeadKey < 0) if (mActiveDeadKey < 0) {
return; return;
}
BYTE kbdState[256]; BYTE kbdState[256];
memset(kbdState, 0, sizeof(kbdState)); memset(kbdState, 0, sizeof(kbdState));
@ -674,9 +650,11 @@ KeyboardLayout::AddDeadKeyEntry(PRUnichar aBaseChar,
DeadKeyEntry* aDeadKeyArray, DeadKeyEntry* aDeadKeyArray,
PRUint32 aEntries) PRUint32 aEntries)
{ {
for (PRUint32 cnt = 0; cnt < aEntries; cnt++) for (PRUint32 cnt = 0; cnt < aEntries; cnt++) {
if (aDeadKeyArray[cnt].BaseChar == aBaseChar) if (aDeadKeyArray[cnt].BaseChar == aBaseChar) {
return PR_FALSE; return PR_FALSE;
}
}
aDeadKeyArray[aEntries].BaseChar = aBaseChar; aDeadKeyArray[aEntries].BaseChar = aBaseChar;
aDeadKeyArray[aEntries].CompositeChar = aCompositeChar; aDeadKeyArray[aEntries].CompositeChar = aCompositeChar;
@ -694,24 +672,22 @@ KeyboardLayout::GetDeadKeyCombinations(PRUint8 aDeadKey,
PRBool deadKeyActive = PR_FALSE; PRBool deadKeyActive = PR_FALSE;
PRUint32 entries = 0; PRUint32 entries = 0;
BYTE kbdState[256]; BYTE kbdState[256];
memset(kbdState, 0, sizeof(kbdState)); memset(kbdState, 0, sizeof(kbdState));
for (PRUint32 shiftState = 0; shiftState < 16; shiftState++) for (PRUint32 shiftState = 0; shiftState < 16; shiftState++) {
{ if (!(aShiftStatesWithBaseChars & (1 << shiftState))) {
if (!(aShiftStatesWithBaseChars & (1 << shiftState)))
continue; continue;
}
SetShiftState(kbdState, shiftState); SetShiftState(kbdState, shiftState);
for (PRUint32 virtualKey = 0; virtualKey < 256; virtualKey++) for (PRUint32 virtualKey = 0; virtualKey < 256; virtualKey++) {
{
PRInt32 vki = GetKeyIndex(virtualKey); PRInt32 vki = GetKeyIndex(virtualKey);
// Dead-key can pair only with such key that produces exactly one base // Dead-key can pair only with such key that produces exactly one base
// character. // character.
if (vki >= 0 && mVirtualKeys[vki].GetNativeUniChars(shiftState) == 1) if (vki >= 0 && mVirtualKeys[vki].GetNativeUniChars(shiftState) == 1) {
{
// Ensure dead-key is in active state, when it swallows entered // Ensure dead-key is in active state, when it swallows entered
// character and waits for the next pressed key. // character and waits for the next pressed key.
if (!deadKeyActive) { if (!deadKeyActive) {
@ -728,15 +704,13 @@ KeyboardLayout::GetDeadKeyCombinations(PRUint8 aDeadKey,
rv = ::ToUnicodeEx(virtualKey, 0, kbdState, (LPWSTR)compositeChars, rv = ::ToUnicodeEx(virtualKey, 0, kbdState, (LPWSTR)compositeChars,
NS_ARRAY_LENGTH(compositeChars), 0, mKeyboardLayout); NS_ARRAY_LENGTH(compositeChars), 0, mKeyboardLayout);
switch (rv) switch (rv) {
{
case 0: case 0:
// This key combination does not produce any characters. The // This key combination does not produce any characters. The
// dead-key is still in active state. // dead-key is still in active state.
break; break;
case 1: case 1: {
{
// Exactly one composite character produced. Now, when dead-key // Exactly one composite character produced. Now, when dead-key
// is not active, repeat the last character one more time to // is not active, repeat the last character one more time to
// determine the base character. // determine the base character.
@ -747,11 +721,12 @@ KeyboardLayout::GetDeadKeyCombinations(PRUint8 aDeadKey,
NS_ASSERTION(rv == 1, "One base character expected"); NS_ASSERTION(rv == 1, "One base character expected");
if (rv == 1 && entries < aMaxEntries) if (rv == 1 && entries < aMaxEntries) {
if (AddDeadKeyEntry(baseChars[0], compositeChars[0], if (AddDeadKeyEntry(baseChars[0], compositeChars[0],
aDeadKeyArray, entries)) aDeadKeyArray, entries)) {
entries++; entries++;
}
}
deadKeyActive = PR_FALSE; deadKeyActive = PR_FALSE;
break; break;
} }
@ -767,8 +742,9 @@ KeyboardLayout::GetDeadKeyCombinations(PRUint8 aDeadKey,
} }
} }
if (deadKeyActive) if (deadKeyActive) {
deadKeyActive = EnsureDeadKeyActive(PR_FALSE, aDeadKey, aDeadKeyKbdState); deadKeyActive = EnsureDeadKeyActive(PR_FALSE, aDeadKey, aDeadKeyKbdState);
}
NS_QuickSort(aDeadKeyArray, entries, sizeof(DeadKeyEntry), NS_QuickSort(aDeadKeyArray, entries, sizeof(DeadKeyEntry),
CompareDeadKeyEntries, nsnull); CompareDeadKeyEntries, nsnull);
@ -783,12 +759,13 @@ DeadKeyTable::GetCompositeChar(PRUnichar aBaseChar) const
// Dead-key table is sorted by BaseChar in ascending order. // Dead-key table is sorted by BaseChar in ascending order.
// Usually they are too small to use binary search. // Usually they are too small to use binary search.
for (PRUint32 cnt = 0; cnt < mEntries; cnt++) for (PRUint32 cnt = 0; cnt < mEntries; cnt++) {
{ if (mTable[cnt].BaseChar == aBaseChar) {
if (mTable[cnt].BaseChar == aBaseChar)
return mTable[cnt].CompositeChar; return mTable[cnt].CompositeChar;
else if (mTable[cnt].BaseChar > aBaseChar) }
if (mTable[cnt].BaseChar > aBaseChar) {
break; break;
}
} }
return 0; return 0;

View File

@ -97,10 +97,11 @@ class VirtualKey
void SetDeadKey(PRUint8 aShiftState, PRBool aIsDeadKey) void SetDeadKey(PRUint8 aShiftState, PRBool aIsDeadKey)
{ {
if (aIsDeadKey) if (aIsDeadKey) {
mIsDeadKey |= 1 << aShiftState; mIsDeadKey |= 1 << aShiftState;
else } else {
mIsDeadKey &= ~(1 << aShiftState); mIsDeadKey &= ~(1 << aShiftState);
}
} }
public: public: