Issue #1348 - Part 1: Clean up input scope support for IMM32.

Use AutoTArray to set input scope.
This commit is contained in:
Makoto Kato 2020-01-09 09:53:16 +01:00 • committed by Roy Tam
commit 8972304bba

View file

@ -588,77 +588,53 @@ IMEHandler::SetInputScopeForIMM32(nsWindow* aWindow,
if (sIsInTSFMode || !sSetInputScopes || aWindow->Destroyed()) { if (sIsInTSFMode || !sSetInputScopes || aWindow->Destroyed()) {
return; return;
} }
UINT arraySize = 0; AutoTArray<InputScope, 3> scopes;
const InputScope* scopes = nullptr;
// http://www.whatwg.org/specs/web-apps/current-work/multipage/the-input-element.html // http://www.whatwg.org/specs/web-apps/current-work/multipage/the-input-element.html
if (aHTMLInputType.IsEmpty() || aHTMLInputType.EqualsLiteral("text")) { if (aHTMLInputType.IsEmpty() || aHTMLInputType.EqualsLiteral("text")) {
if (aHTMLInputInputmode.EqualsLiteral("url")) { if (aHTMLInputInputmode.EqualsLiteral("url")) {
static const InputScope inputScopes[] = { IS_URL }; scopes.AppendElement(IS_URL);
scopes = &inputScopes[0];
arraySize = ArrayLength(inputScopes);
} else if (aHTMLInputInputmode.EqualsLiteral("email")) { } else if (aHTMLInputInputmode.EqualsLiteral("email")) {
static const InputScope inputScopes[] = { IS_EMAIL_SMTPEMAILADDRESS }; scopes.AppendElement(IS_EMAIL_SMTPEMAILADDRESS);
scopes = &inputScopes[0];
arraySize = ArrayLength(inputScopes);
} else if (aHTMLInputInputmode.EqualsLiteral("tel")) { } else if (aHTMLInputInputmode.EqualsLiteral("tel")) {
static const InputScope inputScopes[] = scopes.AppendElement(IS_TELEPHONE_LOCALNUMBER);
{IS_TELEPHONE_LOCALNUMBER, IS_TELEPHONE_FULLTELEPHONENUMBER}; scopes.AppendElement(IS_TELEPHONE_FULLTELEPHONENUMBER);
scopes = &inputScopes[0];
arraySize = ArrayLength(inputScopes);
} else if (aHTMLInputInputmode.EqualsLiteral("numeric")) { } else if (aHTMLInputInputmode.EqualsLiteral("numeric")) {
static const InputScope inputScopes[] = { IS_NUMBER }; scopes.AppendElement(IS_NUMBER);
scopes = &inputScopes[0];
arraySize = ArrayLength(inputScopes);
} else { } else {
static const InputScope inputScopes[] = { IS_DEFAULT }; scopes.AppendElement(IS_DEFAULT);
scopes = &inputScopes[0];
arraySize = ArrayLength(inputScopes);
} }
} else if (aHTMLInputType.EqualsLiteral("url")) { } else if (aHTMLInputType.EqualsLiteral("url")) {
static const InputScope inputScopes[] = { IS_URL }; scopes.AppendElement(IS_URL);
scopes = &inputScopes[0];
arraySize = ArrayLength(inputScopes);
} else if (aHTMLInputType.EqualsLiteral("search")) { } else if (aHTMLInputType.EqualsLiteral("search")) {
static const InputScope inputScopes[] = { IS_SEARCH }; scopes.AppendElement(IS_SEARCH);
scopes = &inputScopes[0];
arraySize = ArrayLength(inputScopes);
} else if (aHTMLInputType.EqualsLiteral("email")) { } else if (aHTMLInputType.EqualsLiteral("email")) {
static const InputScope inputScopes[] = { IS_EMAIL_SMTPEMAILADDRESS }; scopes.AppendElement(IS_EMAIL_SMTPEMAILADDRESS);
scopes = &inputScopes[0];
arraySize = ArrayLength(inputScopes);
} else if (aHTMLInputType.EqualsLiteral("password")) { } else if (aHTMLInputType.EqualsLiteral("password")) {
static const InputScope inputScopes[] = { IS_PASSWORD }; scopes.AppendElement(IS_PASSWORD);
scopes = &inputScopes[0];
arraySize = ArrayLength(inputScopes);
} else if (aHTMLInputType.EqualsLiteral("datetime") || } else if (aHTMLInputType.EqualsLiteral("datetime") ||
aHTMLInputType.EqualsLiteral("datetime-local")) { aHTMLInputType.EqualsLiteral("datetime-local")) {
static const InputScope inputScopes[] = { scopes.AppendElement(IS_DATE_FULLDATE);
IS_DATE_FULLDATE, IS_TIME_FULLTIME }; scopes.AppendElement(IS_TIME_FULLTIME);
scopes = &inputScopes[0];
arraySize = ArrayLength(inputScopes);
} else if (aHTMLInputType.EqualsLiteral("date") || } else if (aHTMLInputType.EqualsLiteral("date") ||
aHTMLInputType.EqualsLiteral("month") || aHTMLInputType.EqualsLiteral("month") ||
aHTMLInputType.EqualsLiteral("week")) { aHTMLInputType.EqualsLiteral("week")) {
static const InputScope inputScopes[] = { IS_DATE_FULLDATE }; scopes.AppendElement(IS_DATE_FULLDATE);
scopes = &inputScopes[0];
arraySize = ArrayLength(inputScopes);
} else if (aHTMLInputType.EqualsLiteral("time")) { } else if (aHTMLInputType.EqualsLiteral("time")) {
static const InputScope inputScopes[] = { IS_TIME_FULLTIME }; scopes.AppendElement(IS_TIME_FULLTIME);
scopes = &inputScopes[0];
arraySize = ArrayLength(inputScopes);
} else if (aHTMLInputType.EqualsLiteral("tel")) { } else if (aHTMLInputType.EqualsLiteral("tel")) {
static const InputScope inputScopes[] = { scopes.AppendElement(IS_TELEPHONE_FULLTELEPHONENUMBER);
IS_TELEPHONE_FULLTELEPHONENUMBER, IS_TELEPHONE_LOCALNUMBER }; scopes.AppendElement(IS_TELEPHONE_LOCALNUMBER);
scopes = &inputScopes[0];
arraySize = ArrayLength(inputScopes);
} else if (aHTMLInputType.EqualsLiteral("number")) { } else if (aHTMLInputType.EqualsLiteral("number")) {
static const InputScope inputScopes[] = { IS_NUMBER }; scopes.AppendElement(IS_NUMBER);
scopes = &inputScopes[0];
arraySize = ArrayLength(inputScopes);
} }
if (scopes && arraySize > 0) { if (!scopes.IsEmpty()) {
sSetInputScopes(aWindow->GetWindowHandle(), scopes, arraySize, nullptr, 0, sSetInputScopes(aWindow->GetWindowHandle(),
nullptr, nullptr); scopes.Elements(),
scopes.Length(),
nullptr,
0,
nullptr,
nullptr);
} }
} }