Bug 1463576 - 8. Hide selection actions on pagehide; r?snorp draft
authorJim Chen <nchen@mozilla.com>
Fri, 01 Jun 2018 13:39:21 -0400
changeset 802945 89ccfe50f136e337345a01f52e8af92475ddd9c2
parent 802944 51f0c9a68dd7e7cc2fd29a8ac8ccdef4604a747b
push id112001
push userbmo:nchen@mozilla.com
push dateFri, 01 Jun 2018 17:40:20 +0000
reviewerssnorp
bugs1463576
milestone62.0a1
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
mobile/android/chrome/geckoview/GeckoViewSelectionActionContent.js
--- 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";