Bug 1463576 - 8. Hide selection actions on pagehide; r?snorp
When the page navigates away, we should hide any active selection
actions.
MozReview-Commit-ID: 2LojAuPxyyl
--- a/mobile/android/chrome/geckoview/GeckoViewSelectionActionContent.js
+++ b/mobile/android/chrome/geckoview/GeckoViewSelectionActionContent.js
@@ -13,17 +13,17 @@ XPCOMUtils.defineLazyModuleGetters(this,
// Dispatches GeckoView:ShowSelectionAction and GeckoView:HideSelectionAction to
// the GeckoSession on accessible caret changes.
class GeckoViewSelectionActionContent extends GeckoViewContentModule {
constructor(aModuleName, aMessageManager) {
super(aModuleName, aMessageManager);
this._seqNo = 0;
this._isActive = false;
- this._previousMessage = {};
+ this._previousMessage = "";
this._actions = [{
id: "org.mozilla.geckoview.CUT",
predicate: e => !e.collapsed && e.selectionEditable && !this._isPasswordField(e),
perform: _ => docShell.doCommand("cmd_cut"),
}, {
id: "org.mozilla.geckoview.COPY",
predicate: e => !e.collapsed && !this._isPasswordField(e),
@@ -92,28 +92,41 @@ class GeckoViewSelectionActionContent ex
}
return offset;
}
onEnable() {
debug `onEnable`;
addEventListener("mozcaretstatechanged", this, { mozSystemGroup: true });
+ addEventListener("pagehide", this, { capture: true, mozSystemGroup: true });
}
onDisable() {
debug `onDisable`;
removeEventListener("mozcaretstatechanged", this, { mozSystemGroup: true });
+ removeEventListener("pagehide", this, { capture: true, mozSystemGroup: true });
}
/**
* Receive and act on AccessibleCarets caret state-change
- * (mozcaretstatechanged) events.
+ * (mozcaretstatechanged and pagehide) events.
*/
handleEvent(aEvent) {
+ if (aEvent.type === "pagehide") {
+ // Hide any selection actions on page hide.
+ aEvent = {
+ reason: "visibilitychange",
+ caretVisibile: false,
+ selectionVisible: false,
+ collapsed: true,
+ selectionEditable: false,
+ };
+ }
+
let reason = aEvent.reason;
if (this._isActive && !aEvent.caretVisible) {
// For mozcaretstatechanged, "visibilitychange" means the caret is hidden.
reason = "visibilitychange";
} else if (!aEvent.collapsed &&
!aEvent.selectionVisible) {
reason = "invisibleselection";