Bug 1752133 - Fix a couple more issues with the select dropdown on Android. r=agi

Two issues:

 * Set the openInParentProcess flag in GeckoViewPrompt.jsm for
   dropdowns. This avoids needing two taps to re-open the dropdown.

 * Make the "input" event composed, see bug 1734040.

Differential Revision: https://phabricator.services.mozilla.com/D137038
This commit is contained in:
Emilio Cobos Álvarez 2022-01-26 16:48:55 +00:00
Родитель b1f93026e6
Коммит 90a0deb6cb
2 изменённых файлов: 30 добавлений и 7 удалений

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

@ -29,7 +29,7 @@ class PromptFactory {
switch (aEvent.type) {
case "mozshowdropdown":
case "mozshowdropdown-sourcetouch":
this._handleSelect(aEvent.composedTarget);
this._handleSelect(aEvent.composedTarget, /* aIsDropDown = */ true);
break;
case "click":
this._handleClick(aEvent);
@ -65,7 +65,7 @@ class PromptFactory {
if (className === "HTMLSelectElement") {
if (target.multiple) {
this._handleSelect(target);
this._handleSelect(target, /* aIsDropDown = */ false);
return;
}
// non-multiple select is handled by mozshowdropdown.
@ -85,7 +85,7 @@ class PromptFactory {
}
}
_handleSelect(aElement) {
_handleSelect(aElement, aIsDropDown) {
const win = aElement.ownerGlobal;
let id = 0;
const map = {};
@ -117,6 +117,9 @@ class PromptFactory {
return items;
})(aElement);
if (aIsDropDown) {
aElement.openInParentProcess = true;
}
const prompt = new GeckoViewPrompter(win);
prompt.asyncShowPrompt(
{
@ -125,6 +128,9 @@ class PromptFactory {
choices: items,
},
result => {
if (aIsDropDown) {
aElement.openInParentProcess = false;
}
// OK: result
// Cancel: !result
if (!result || result.choices === undefined) {
@ -203,7 +209,7 @@ class PromptFactory {
// Fire both "input" and "change" events for <select> and <input> for
// date/time.
aElement.dispatchEvent(
new aElement.ownerGlobal.Event("input", { bubbles: true })
new aElement.ownerGlobal.Event("input", { bubbles: true, composed: true })
);
aElement.dispatchEvent(
new aElement.ownerGlobal.Event("change", { bubbles: true })

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

@ -300,7 +300,7 @@ class PromptDelegateTest : BaseSessionTest() {
mainSession.loadTestPath(SELECT_HTML_PATH)
sessionRule.waitForPageStop()
val result = GeckoResult<Void>()
val result = GeckoResult<PromptDelegate.PromptResponse>()
sessionRule.delegateUntilTestEnd(object : PromptDelegate {
@AssertCalled(count = 1)
override fun onChoicePrompt(session: GeckoSession, prompt: PromptDelegate.ChoicePrompt): GeckoResult<PromptDelegate.PromptResponse>? {
@ -308,12 +308,29 @@ class PromptDelegateTest : BaseSessionTest() {
assertThat("There should be two choices", prompt.choices.size, equalTo(2));
assertThat("First choice is correct", prompt.choices[0].label, equalTo("ABC"));
assertThat("Second choice is correct", prompt.choices[1].label, equalTo("DEF"));
result.complete(null);
return null
result.complete(prompt.confirm(prompt.choices[1]));
return result
}
})
val promise = mainSession.evaluatePromiseJS("""new Promise(function(resolve) {
let events = [];
// Record the events for testing purposes.
for (const t of ["change", "input"]) {
document.querySelector("select").addEventListener(t, function(e) {
events.push(e.type + "(composed=" + e.composed + ")");
if (events.length == 2) {
resolve(events.join(" "));
}
});
}
})""");
mainSession.synthesizeTap(10, 10)
sessionRule.waitForResult(result)
assertThat("Events should be as expected",
promise.value as String,
equalTo("input(composed=true) change(composed=false)"))
}
@Test