Bug 1546851 - Ensure that the context menu is closed when performing a paste. r=geckoview-reviewers,droeh

This issue was caused by the updating of the caret position after the paste occurs firing an `updateposition` event resulting in an `GeckoView:ShowSelectionAction` message to reposition context menu without any attempt to close the context menu. The solution is to hide the context menu before the repositioning of the caret occurs such that the `updateposition` event doesn't trigger a redisplay.

I tried several versions of this trying to trigger the menu close from inside `GeckoViewSelectionActionDelegate`, including making the call to `docShell.doCommand("cmd_paste");` asynchronous and firing `ACTION_HIDE` before firing `ACTION_PASTE`, but the result is always the same - one of the events is processed before the other and so the second event is rejected as a stale response.

Therefore we are firing the `pagehide` from inside the code that performs the paste. This has to be done before the paste occurs otherwise the `updateposition` event is fired before the page hide event and the context menu redisplays before being hidden.

Differential Revision: https://phabricator.services.mozilla.com/D29665

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Emily Toop 2019-05-02 15:06:58 +00:00
Родитель 3c771d5a8b
Коммит 3fd2272331
1 изменённых файлов: 6 добавлений и 3 удалений

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

@ -34,7 +34,7 @@ class GeckoViewSelectionActionChild extends GeckoViewChildModule {
predicate: e => e.selectionEditable &&
Services.clipboard.hasDataMatchingFlavors(
["text/unicode"], 1, Ci.nsIClipboard.kGlobalClipboard),
perform: _ => docShell.doCommand("cmd_paste"),
perform: _ => this._performPaste(),
}, {
id: "org.mozilla.geckoview.DELETE",
predicate: e => !e.collapsed && e.selectionEditable,
@ -58,6 +58,11 @@ class GeckoViewSelectionActionChild extends GeckoViewChildModule {
}];
}
_performPaste() {
this.handleEvent({type: "pagehide"});
docShell.doCommand("cmd_paste");
}
_isPasswordField(aEvent) {
if (!aEvent.selectionEditable) {
return false;
@ -190,8 +195,6 @@ class GeckoViewSelectionActionChild extends GeckoViewChildModule {
this._isActive = true;
this._previousMessage = JSON.stringify(msg);
// This event goes to GeckoViewSelectionAction.jsm, where the data is
// further transformed and then sent to GeckoSession.
this.eventDispatcher.sendRequest(msg, {
onSuccess: response => {
if (response.seqNo !== this._seqNo) {