Bug 1303273 part.7 Hide UniCharsAndModifiers::mLength and make its type size_t r?m_kato
MozReview-Commit-ID: 7QLdmgopOwG
--- a/widget/windows/KeyboardLayout.cpp
+++ b/widget/windows/KeyboardLayout.cpp
@@ -621,28 +621,28 @@ static const nsCString
ToString(const UniCharsAndModifiers& aUniCharsAndModifiers)
{
if (aUniCharsAndModifiers.IsEmpty()) {
return NS_LITERAL_CSTRING("{}");
}
nsAutoCString result;
result.AssignLiteral("{ ");
result.Append(GetCharacterCodeName(aUniCharsAndModifiers.CharAt(0)));
- for (uint32_t i = 1; i < aUniCharsAndModifiers.mLength; ++i) {
+ for (size_t i = 1; i < aUniCharsAndModifiers.Length(); ++i) {
if (aUniCharsAndModifiers.ModifiersAt(i - 1) !=
aUniCharsAndModifiers.ModifiersAt(i)) {
result.AppendLiteral(" [");
result.Append(GetModifiersName(aUniCharsAndModifiers.ModifiersAt(0)));
result.AppendLiteral("]");
}
result.AppendLiteral(", ");
result.Append(GetCharacterCodeName(aUniCharsAndModifiers.CharAt(i)));
}
result.AppendLiteral(" [");
- uint32_t lastIndex = aUniCharsAndModifiers.mLength - 1;
+ uint32_t lastIndex = aUniCharsAndModifiers.Length() - 1;
result.Append(GetModifiersName(aUniCharsAndModifiers.ModifiersAt(lastIndex)));
result.AppendLiteral("] }");
return result;
}
const nsCString
ToString(const ModifierKeyState& aModifierKeyState)
{
@@ -920,29 +920,29 @@ UniCharsAndModifiers::Append(char16_t aU
mChars[mLength] = aUniChar;
mModifiers[mLength] = aModifiers;
mLength++;
}
void
UniCharsAndModifiers::FillModifiers(Modifiers aModifiers)
{
- for (uint32_t i = 0; i < mLength; i++) {
+ for (size_t i = 0; i < mLength; i++) {
mModifiers[i] = aModifiers;
}
}
void
UniCharsAndModifiers::OverwriteModifiersIfBeginsWith(
const UniCharsAndModifiers& aOther)
{
if (!BeginsWith(aOther)) {
return;
}
- for (uint32_t i = 0; i < aOther.mLength; ++i) {
+ for (size_t i = 0; i < aOther.mLength; ++i) {
mModifiers[i] = aOther.mModifiers[i];
}
}
bool
UniCharsAndModifiers::UniCharsEqual(const UniCharsAndModifiers& aOther) const
{
if (mLength != aOther.mLength) {
@@ -1104,17 +1104,17 @@ VirtualKey::GetUniChars(ShiftState aShif
{
UniCharsAndModifiers result = GetNativeUniChars(aShiftState);
const ShiftState STATE_ALT_CONTROL = (STATE_ALT | STATE_CONTROL);
if (!(aShiftState & STATE_ALT_CONTROL)) {
return result;
}
- if (!result.mLength) {
+ if (result.IsEmpty()) {
result = GetNativeUniChars(aShiftState & ~STATE_ALT_CONTROL);
result.FillModifiers(ShiftStateToModifiers(aShiftState));
return result;
}
if ((aShiftState & STATE_ALT_CONTROL) == STATE_ALT_CONTROL) {
// Even if the shifted chars and the unshifted chars are same, we
// should consume the Alt key state and the Ctrl key state when
@@ -3295,17 +3295,17 @@ NativeKey::DispatchKeyPressEventsWithout
void
NativeKey::WillDispatchKeyboardEvent(WidgetKeyboardEvent& aKeyboardEvent,
uint32_t aIndex)
{
// If it's an eKeyPress event and it's generated from retrieved char message,
// we need to set raw message information for plugins.
if (aKeyboardEvent.mMessage == eKeyPress &&
IsFollowedByPrintableCharOrSysCharMessage()) {
- MOZ_RELEASE_ASSERT(aIndex < mCommittedCharsAndModifiers.mLength);
+ MOZ_RELEASE_ASSERT(aIndex < mCommittedCharsAndModifiers.Length());
uint32_t foundPrintableCharMessages = 0;
for (size_t i = 0; i < mFollowingCharMsgs.Length(); ++i) {
if (!IsPrintableCharOrSysCharMessage(mFollowingCharMsgs[i])) {
// XXX Should we dispatch a plugin event for WM_*DEADCHAR messages and
// WM_CHAR with a control character here? But we're not sure
// how can we create such message queue (i.e., WM_CHAR or
// WM_SYSCHAR with a printable character and such message are
// generated by a keydown). So, let's ignore such case until
@@ -3331,52 +3331,52 @@ NativeKey::WillDispatchKeyboardEvent(Wid
MODIFIER_ALTGRAPH | MODIFIER_CAPSLOCK);
modKeyState.Set(mCommittedCharsAndModifiers.ModifiersAt(aIndex));
modKeyState.InitInputEvent(aKeyboardEvent);
MOZ_LOG(sNativeKeyLogger, LogLevel::Info,
("%p NativeKey::WillDispatchKeyboardEvent(), "
"setting %uth modifier state to %s",
this, aIndex + 1, ToString(modKeyState).get()));
}
- uint32_t longestLength =
- std::max(mInputtingStringAndModifiers.mLength,
- std::max(mShiftedString.mLength, mUnshiftedString.mLength));
- uint32_t skipUniChars = longestLength - mInputtingStringAndModifiers.mLength;
- uint32_t skipShiftedChars = longestLength - mShiftedString.mLength;
- uint32_t skipUnshiftedChars = longestLength - mUnshiftedString.mLength;
+ size_t longestLength =
+ std::max(mInputtingStringAndModifiers.Length(),
+ std::max(mShiftedString.Length(), mUnshiftedString.Length()));
+ size_t skipUniChars = longestLength - mInputtingStringAndModifiers.Length();
+ size_t skipShiftedChars = longestLength - mShiftedString.Length();
+ size_t skipUnshiftedChars = longestLength - mUnshiftedString.Length();
if (aIndex >= longestLength) {
MOZ_LOG(sNativeKeyLogger, LogLevel::Info,
("%p NativeKey::WillDispatchKeyboardEvent(), does nothing for %uth "
"%s event",
this, aIndex + 1, ToChar(aKeyboardEvent.mMessage)));
return;
}
// Check if aKeyboardEvent is the last event for a key press.
// So, if it's not an eKeyPress event, it's always the last event.
// Otherwise, check if the index is the last character of
// mCommittedCharsAndModifiers.
bool isLastIndex =
aKeyboardEvent.mMessage != eKeyPress ||
mCommittedCharsAndModifiers.IsEmpty() ||
- mCommittedCharsAndModifiers.mLength - 1 == aIndex;
+ mCommittedCharsAndModifiers.Length() - 1 == aIndex;
nsTArray<AlternativeCharCode>& altArray =
aKeyboardEvent.mAlternativeCharCodes;
// Set charCode and adjust modifier state for every eKeyPress event.
// This is not necessary for the other keyboard events because the other
// keyboard events shouldn't have non-zero charCode value and should have
// current modifier state.
if (aKeyboardEvent.mMessage == eKeyPress && skipUniChars <= aIndex) {
// XXX Modifying modifier state of aKeyboardEvent is illegal, but no way
// to set different modifier state per keypress event except this
// hack. Note that ideally, dead key should cause composition events
// instead of keypress events, though.
- if (aIndex - skipUniChars < mInputtingStringAndModifiers.mLength) {
+ if (aIndex - skipUniChars < mInputtingStringAndModifiers.Length()) {
ModifierKeyState modKeyState(mModKeyState);
// If key in combination with Alt and/or Ctrl produces a different
// character than without them then do not report these flags
// because it is separate keyboard layout shift state. If dead-key
// and base character does not produce a valid composite character
// then both produced dead-key character and following base
// character may have different modifier flags, too.
modKeyState.Unset(MODIFIER_SHIFT | MODIFIER_CONTROL | MODIFIER_ALT |
@@ -3709,17 +3709,17 @@ KeyboardLayout::MaybeInitNativeKeyAsDead
if ((aNativeKey.IsKeyDownMessage() && !IsInDeadKeySequence()) ||
(!aNativeKey.IsKeyDownMessage() &&
mActiveDeadKey == aNativeKey.mOriginalVirtualKeyCode)) {
ActivateDeadKeyState(aNativeKey, aModKeyState);
#ifdef DEBUG
UniCharsAndModifiers deadChars =
GetNativeUniCharsAndModifiers(aNativeKey.mOriginalVirtualKeyCode,
aModKeyState);
- MOZ_ASSERT(deadChars.mLength == 1,
+ MOZ_ASSERT(deadChars.Length() == 1,
"dead key must generate only one character");
#endif
// First dead key event doesn't generate characters. Dead key should
// cause only keydown event and keyup event whose KeyboardEvent.key
// values are "Dead".
aNativeKey.mCommittedCharsAndModifiers.Clear();
aNativeKey.mKeyNameIndex = KEY_NAME_INDEX_Dead;
return true;
@@ -4174,17 +4174,17 @@ KeyboardLayout::GetDeadKeyCombinations(u
VirtualKey::FillKbdState(kbdState, shiftState);
for (uint32_t virtualKey = 0; virtualKey < 256; virtualKey++) {
int32_t vki = GetKeyIndex(virtualKey);
// Dead-key can pair only with such key that produces exactly one base
// character.
if (vki >= 0 &&
- mVirtualKeys[vki].GetNativeUniChars(shiftState).mLength == 1) {
+ mVirtualKeys[vki].GetNativeUniChars(shiftState).Length() == 1) {
// Ensure dead-key is in active state, when it swallows entered
// character and waits for the next pressed key.
if (!deadKeyActive) {
deadKeyActive = EnsureDeadKeyActive(true, aDeadKey,
aDeadKeyKbdState);
}
// Depending on the character the followed the dead-key, the keyboard
@@ -4436,21 +4436,21 @@ KeyboardLayout::ConvertNativeKeyCodeToDO
case VK_OEM_102:
case VK_ABNT_C1:
{
NS_ASSERTION(IsPrintableCharKey(aNativeKeyCode),
"The key must be printable");
ModifierKeyState modKeyState(0);
UniCharsAndModifiers uniChars =
GetUniCharsAndModifiers(aNativeKeyCode, modKeyState);
- if (uniChars.mLength != 1 ||
+ if (uniChars.Length() != 1 ||
uniChars.CharAt(0) < ' ' || uniChars.CharAt(0) > 0x7F) {
modKeyState.Set(MODIFIER_SHIFT);
uniChars = GetUniCharsAndModifiers(aNativeKeyCode, modKeyState);
- if (uniChars.mLength != 1 ||
+ if (uniChars.Length() != 1 ||
uniChars.CharAt(0) < ' ' || uniChars.CharAt(0) > 0x7F) {
return 0;
}
}
return WidgetUtils::ComputeKeyCodeFromChar(uniChars.CharAt(0));
}
// IE sets 0xC2 to the DOM keyCode for VK_ABNT_C2. However, we're already
--- a/widget/windows/KeyboardLayout.h
+++ b/widget/windows/KeyboardLayout.h
@@ -55,18 +55,16 @@ static const uint32_t sModifierKeyMap[][
{ nsIWidget::ALT_R, VK_MENU, VK_RMENU }
};
class KeyboardLayout;
class UniCharsAndModifiers final
{
public:
- 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);
@@ -78,16 +76,18 @@ public:
MOZ_ASSERT(aIndex < mLength);
return mChars[aIndex];
}
Modifiers ModifiersAt(size_t aIndex) const
{
MOZ_ASSERT(aIndex < mLength);
return mModifiers[aIndex];
}
+ size_t Length() const { return mLength; }
+
void FillModifiers(Modifiers aModifiers);
/**
* OverwriteModifiersIfBeginsWith() assigns mModifiers with aOther between
* [0] and [aOther.mLength - 1] only when mChars begins with aOther.mChars.
*/
void OverwriteModifiersIfBeginsWith(const UniCharsAndModifiers& aOther);
bool UniCharsEqual(const UniCharsAndModifiers& aOther) const;
@@ -95,16 +95,17 @@ public:
bool BeginsWith(const UniCharsAndModifiers& aOther) const;
nsString ToString() const { return nsString(mChars, mLength); }
private:
// Dead-key + up to 4 characters
char16_t mChars[5];
Modifiers mModifiers[5];
+ size_t mLength;
};
struct DeadKeyEntry;
class DeadKeyTable;
class VirtualKey
{