Bug 1240208 - use inputmode in XUL to get better hinting for IME and on-screen keyboards, r=masayuki,smaug

--HG--
extra : commitid : KANhgN15KJK
extra : rebase_source : 0b640769e92d9d8c01e972c2b526ea56cc56d1df
This commit is contained in:
Gijs Kruitbosch 2016-02-01 17:57:29 +00:00
Родитель 6bc8a32265
Коммит 957a33f4d4
6 изменённых файлов: 51 добавлений и 13 удалений

Просмотреть файл

@ -37,7 +37,8 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/.
<html:input anonid="input" <html:input anonid="input"
class="autocomplete-textbox urlbar-input textbox-input uri-element-right-align" class="autocomplete-textbox urlbar-input textbox-input uri-element-right-align"
allowevents="true" allowevents="true"
xbl:inherits="tooltiptext=inputtooltiptext,value,type=inputtype,maxlength,disabled,size,readonly,placeholder,tabindex,accesskey"/> inputmode="url"
xbl:inherits="tooltiptext=inputtooltiptext,value,maxlength,disabled,size,readonly,placeholder,tabindex,accesskey"/>
</xul:hbox> </xul:hbox>
<xul:dropmarker anonid="historydropmarker" <xul:dropmarker anonid="historydropmarker"
class="autocomplete-history-dropmarker urlbar-history-dropmarker" class="autocomplete-history-dropmarker urlbar-history-dropmarker"

Просмотреть файл

@ -1034,7 +1034,8 @@ IMEStateManager::SetIMEState(const IMEState& aState,
context.mHTMLInputType.Assign(nsGkAtoms::textarea->GetUTF16String()); context.mHTMLInputType.Assign(nsGkAtoms::textarea->GetUTF16String());
} }
if (Preferences::GetBool("dom.forms.inputmode", false)) { if (Preferences::GetBool("dom.forms.inputmode", false) ||
nsContentUtils::IsChromeDoc(aContent->OwnerDoc())) {
aContent->GetAttr(kNameSpaceID_None, nsGkAtoms::inputmode, aContent->GetAttr(kNameSpaceID_None, nsGkAtoms::inputmode,
context.mHTMLInputInputmode); context.mHTMLInputInputmode);
} }

Просмотреть файл

@ -3028,10 +3028,21 @@ TSFTextStore::InsertEmbedded(DWORD dwFlags,
} }
void void
TSFTextStore::SetInputScope(const nsString& aHTMLInputType) TSFTextStore::SetInputScope(const nsString& aHTMLInputType,
const nsString& aHTMLInputInputMode)
{ {
mInputScopes.Clear(); mInputScopes.Clear();
if (aHTMLInputType.IsEmpty() || aHTMLInputType.EqualsLiteral("text")) { if (aHTMLInputType.IsEmpty() || aHTMLInputType.EqualsLiteral("text")) {
if (aHTMLInputInputMode.EqualsLiteral("url")) {
mInputScopes.AppendElement(IS_URL);
} else if (aHTMLInputInputMode.EqualsLiteral("email")) {
mInputScopes.AppendElement(IS_EMAIL_SMTPEMAILADDRESS);
} else if (aHTMLInputType.EqualsLiteral("tel")) {
mInputScopes.AppendElement(IS_TELEPHONE_FULLTELEPHONENUMBER);
mInputScopes.AppendElement(IS_TELEPHONE_LOCALNUMBER);
} else if (aHTMLInputType.EqualsLiteral("numeric")) {
mInputScopes.AppendElement(IS_NUMBER);
}
return; return;
} }
@ -4559,7 +4570,8 @@ TSFTextStore::CreateAndSetFocus(nsWindowBase* aFocusedWidget,
"ITfTheadMgr::AssociateFocus() failure")); "ITfTheadMgr::AssociateFocus() failure"));
return false; return false;
} }
sEnabledTextStore->SetInputScope(aContext.mHTMLInputType); sEnabledTextStore->SetInputScope(aContext.mHTMLInputType,
aContext.mHTMLInputInputmode);
if (sEnabledTextStore->mSink) { if (sEnabledTextStore->mSink) {
MOZ_LOG(sTextStoreLog, LogLevel::Info, MOZ_LOG(sTextStoreLog, LogLevel::Info,
@ -5296,7 +5308,8 @@ TSFTextStore::SetInputContext(nsWindowBase* aWidget,
if (aAction.mFocusChange != InputContextAction::FOCUS_NOT_CHANGED) { if (aAction.mFocusChange != InputContextAction::FOCUS_NOT_CHANGED) {
if (sEnabledTextStore) { if (sEnabledTextStore) {
sEnabledTextStore->SetInputScope(aContext.mHTMLInputType); sEnabledTextStore->SetInputScope(aContext.mHTMLInputType,
aContext.mHTMLInputInputmode);
} }
return; return;
} }

Просмотреть файл

@ -302,7 +302,8 @@ protected:
HRESULT HandleRequestAttrs(DWORD aFlags, HRESULT HandleRequestAttrs(DWORD aFlags,
ULONG aFilterCount, ULONG aFilterCount,
const TS_ATTRID* aFilterAttrs); const TS_ATTRID* aFilterAttrs);
void SetInputScope(const nsString& aHTMLInputType); void SetInputScope(const nsString& aHTMLInputType,
const nsString& aHTMLInputInputmode);
// Creates native caret over our caret. This method only works on desktop // Creates native caret over our caret. This method only works on desktop
// application. Otherwise, this does nothing. // application. Otherwise, this does nothing.

Просмотреть файл

@ -393,7 +393,7 @@ IMEHandler::OnDestroyWindow(nsWindow* aWindow)
if (!sIsInTSFMode) { if (!sIsInTSFMode) {
// MSDN says we need to set IS_DEFAULT to avoid memory leak when we use // MSDN says we need to set IS_DEFAULT to avoid memory leak when we use
// SetInputScopes API. Use an empty string to do this. // SetInputScopes API. Use an empty string to do this.
SetInputScopeForIMM32(aWindow, EmptyString()); SetInputScopeForIMM32(aWindow, EmptyString(), EmptyString());
} }
#endif // #ifdef NS_ENABLE_TSF #endif // #ifdef NS_ENABLE_TSF
AssociateIMEContext(aWindow, true); AssociateIMEContext(aWindow, true);
@ -444,7 +444,8 @@ IMEHandler::SetInputContext(nsWindow* aWindow,
} }
} else { } else {
// Set at least InputScope even when TextStore is not available. // Set at least InputScope even when TextStore is not available.
SetInputScopeForIMM32(aWindow, aInputContext.mHTMLInputType); SetInputScopeForIMM32(aWindow, aInputContext.mHTMLInputType,
aInputContext.mHTMLInputInputmode);
} }
#endif // #ifdef NS_ENABLE_TSF #endif // #ifdef NS_ENABLE_TSF
@ -517,7 +518,8 @@ IMEHandler::CurrentKeyboardLayoutHasIME()
// static // static
void void
IMEHandler::SetInputScopeForIMM32(nsWindow* aWindow, IMEHandler::SetInputScopeForIMM32(nsWindow* aWindow,
const nsAString& aHTMLInputType) const nsAString& aHTMLInputType,
const nsAString& aHTMLInputInputmode)
{ {
if (sIsInTSFMode || !sSetInputScopes || aWindow->Destroyed()) { if (sIsInTSFMode || !sSetInputScopes || aWindow->Destroyed()) {
return; return;
@ -526,9 +528,28 @@ IMEHandler::SetInputScopeForIMM32(nsWindow* aWindow,
const InputScope* scopes = nullptr; 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")) {
static const InputScope inputScopes[] = { IS_DEFAULT }; if (aHTMLInputInputmode.EqualsLiteral("url")) {
scopes = &inputScopes[0]; static const InputScope inputScopes[] = { IS_URL };
arraySize = ArrayLength(inputScopes); scopes = &inputScopes[0];
arraySize = ArrayLength(inputScopes);
} else if (aHTMLInputInputmode.EqualsLiteral("email")) {
static const InputScope inputScopes[] = { IS_EMAIL_SMTPEMAILADDRESS };
scopes = &inputScopes[0];
arraySize = ArrayLength(inputScopes);
} else if (aHTMLInputInputmode.EqualsLiteral("tel")) {
static const InputScope inputScopes[] =
{IS_TELEPHONE_LOCALNUMBER, IS_TELEPHONE_FULLTELEPHONENUMBER};
scopes = &inputScopes[0];
arraySize = ArrayLength(inputScopes);
} else if (aHTMLInputInputmode.EqualsLiteral("numeric")) {
static const InputScope inputScopes[] = { IS_NUMBER };
scopes = &inputScopes[0];
arraySize = ArrayLength(inputScopes);
} else {
static const InputScope inputScopes[] = { IS_DEFAULT };
scopes = &inputScopes[0];
arraySize = ArrayLength(inputScopes);
}
} else if (aHTMLInputType.EqualsLiteral("url")) { } else if (aHTMLInputType.EqualsLiteral("url")) {
static const InputScope inputScopes[] = { IS_URL }; static const InputScope inputScopes[] = { IS_URL };
scopes = &inputScopes[0]; scopes = &inputScopes[0];

Просмотреть файл

@ -131,7 +131,8 @@ private:
#ifdef NS_ENABLE_TSF #ifdef NS_ENABLE_TSF
static decltype(SetInputScopes)* sSetInputScopes; static decltype(SetInputScopes)* sSetInputScopes;
static void SetInputScopeForIMM32(nsWindow* aWindow, static void SetInputScopeForIMM32(nsWindow* aWindow,
const nsAString& aHTMLInputType); const nsAString& aHTMLInputType,
const nsAString& aHTMLInputInputmode);
static bool sIsInTSFMode; static bool sIsInTSFMode;
// If sIMMEnabled is false, any IME messages are not handled in TSF mode. // If sIMMEnabled is false, any IME messages are not handled in TSF mode.
// Additionally, IME context is always disassociated from focused window. // Additionally, IME context is always disassociated from focused window.