зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1490661 - Part 3. InputContext should reference enterkeyhint attribute for action hint. r=masayuki
Set enterkeyhint to `InputContext.mActionHint`. Although it is used by `moz_action` attribute, enterkeyhint is standardized version of this. New logic is the following. 1. Read `enterkeyhint` that is from editing host 2. Read `moz_action` on `<input>` element if no `enterkeyhint` 3. If both is nothing, we infer this value from the `<form>`. Differential Revision: https://phabricator.services.mozilla.com/D79644
This commit is contained in:
Родитель
41fc689975
Коммит
6f7d15e2e1
|
@ -1165,10 +1165,17 @@ static bool IsNextFocusableElementTextControl(Element* aInputContent) {
|
|||
}
|
||||
|
||||
static void GetActionHint(nsIContent& aContent, nsAString& aActionHint) {
|
||||
// If enterkeyhint is set, we don't infer action hint.
|
||||
if (!aActionHint.IsEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// XXX This is old compatibility, but we might be able to remove this.
|
||||
aContent.AsElement()->GetAttr(kNameSpaceID_None, nsGkAtoms::moz_action_hint,
|
||||
aActionHint);
|
||||
|
||||
if (!aActionHint.IsEmpty()) {
|
||||
ToLowerCase(aActionHint);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1269,7 +1276,12 @@ void IMEStateManager::SetIMEState(const IMEState& aState,
|
|||
aPresContext &&
|
||||
nsContentUtils::IsInPrivateBrowsing(aPresContext->Document());
|
||||
|
||||
if (aContent) {
|
||||
if (aContent && aContent->IsHTMLElement()) {
|
||||
if (aState.IsEditable() && StaticPrefs::dom_forms_enterkeyhint()) {
|
||||
nsGenericHTMLElement::FromNode(aContent)->GetEnterKeyHint(
|
||||
context.mActionHint);
|
||||
}
|
||||
|
||||
if (aContent->IsHTMLElement(nsGkAtoms::input)) {
|
||||
HTMLInputElement::FromNode(aContent)->GetType(context.mHTMLInputType);
|
||||
GetActionHint(*aContent, context.mActionHint);
|
||||
|
@ -1278,7 +1290,7 @@ void IMEStateManager::SetIMEState(const IMEState& aState,
|
|||
GetActionHint(*aContent, context.mActionHint);
|
||||
}
|
||||
|
||||
if (aContent->IsHTMLElement() && aState.IsEditable() &&
|
||||
if (aState.IsEditable() &&
|
||||
(StaticPrefs::dom_forms_inputmode() ||
|
||||
nsContentUtils::IsChromeDoc(aContent->OwnerDoc()))) {
|
||||
aContent->AsElement()->GetAttr(kNameSpaceID_None, nsGkAtoms::inputmode,
|
||||
|
|
|
@ -21,12 +21,22 @@
|
|||
<form><input type="text" id="i1"><input type="text" disabled><input type="submit"></form>
|
||||
<input type="text" id="j1"><input type="text"><input type="button">
|
||||
<form><input type="text" id="k1"><a href="#foo">foo</a><input type="text"><input type="submit"></form>
|
||||
<form>
|
||||
<input id="l1" enterkeyhint="enter">
|
||||
<input id="l2" enterkeyhint="DONE">
|
||||
<input id="l3" enterkeyhint="go">
|
||||
<input id="l4" enterkeyhint="Next">
|
||||
<input id="l5" enterkeyhint="Previous">
|
||||
<input id="l6" enterkeyhint="search">
|
||||
<textarea id="l7" enterkeyhint="send"></textarea>
|
||||
<input id="l8" enterkeyhint="NONE">
|
||||
</form>
|
||||
</div>
|
||||
<pre id="test">
|
||||
<script class=testbody" type="application/javascript">
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
SimpleTest.waitForFocus(() => {
|
||||
SimpleTest.waitForFocus(async () => {
|
||||
const tests = [
|
||||
{ id: "a1", hint: "next", desc: "next element is type=text" },
|
||||
{ id: "a2", hint: "go", desc: "next element is type=submit" },
|
||||
|
@ -38,6 +48,15 @@ SimpleTest.waitForFocus(() => {
|
|||
// XXX Feel free to change this result if you get some bugs reports
|
||||
{ id: "i1", hint: "go", desc: "next element is disabled" },
|
||||
{ id: "j1", hint: "", desc: "no form element" },
|
||||
{ id: "l1", hint: "enter", desc: "enterkeyhint=enter" },
|
||||
{ id: "l2", hint: "done", desc: "enterkeyhint=DONE" },
|
||||
{ id: "l3", hint: "go", desc: "enterkeyhint=go" },
|
||||
{ id: "l4", hint: "next", desc: "enterkeyhint=Next" },
|
||||
{ id: "l5", hint: "previous", desc: "enterkeyhint=Previous" },
|
||||
{ id: "l6", hint: "search", desc: "enterkeyhint=search" },
|
||||
{ id: "l7", hint: "send", desc: "enterkeyhint=send" },
|
||||
// Since enterkeyhint is invalid, we infer action hint. So feel free to change this.
|
||||
{ id: "l8", hint: "go", desc: "enterkeyhint is invalid" },
|
||||
];
|
||||
|
||||
const todo_tests = [
|
||||
|
@ -45,6 +64,8 @@ SimpleTest.waitForFocus(() => {
|
|||
{ id: "k1", hint: "", desc: "next is anchor link" },
|
||||
];
|
||||
|
||||
await SpecialPowers.setBoolPref("dom.forms.enterkeyhint", true);
|
||||
|
||||
for (let test of tests) {
|
||||
document.getElementById(test.id).focus();
|
||||
is(SpecialPowers.DOMWindowUtils.focusedActionHint, test.hint, test.desc);
|
||||
|
@ -55,6 +76,7 @@ SimpleTest.waitForFocus(() => {
|
|||
todo_is(SpecialPowers.DOMWindowUtils.focusedActionHint, test.hint, test.desc);
|
||||
}
|
||||
|
||||
SpecialPowers.clearUserPref("dom.forms.enterkeyhint");
|
||||
SimpleTest.finish();
|
||||
});
|
||||
</script>
|
||||
|
|
Загрузка…
Ссылка в новой задаче