Bug 1475325 - Hide selection action in some scenarios; r=droeh a=ritu
authorJim Chen <nchen@mozilla.com>
Mon, 17 Sep 2018 23:15:17 +0000
changeset 492601 297509ef3d02a63316ca5f3b6e20029b542ba996
parent 492600 620018ee95d1c553698b335aa7e31bad14da046d
child 492602 d21a43596d555ea618da75910aa3c1cb06158725
push id1815
push userffxbld-merge
push dateMon, 15 Oct 2018 10:40:45 +0000
treeherdermozilla-release@18d4c09e9378 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdroeh, ritu
bugs1475325
milestone63.0
Bug 1475325 - Hide selection action in some scenarios; r=droeh a=ritu Hide the selection action toolbar when the session is unfocused, or when changing the selection action delegate. Differential Revision: https://phabricator.services.mozilla.com/D5807
mobile/android/chrome/geckoview/GeckoViewSelectionActionContent.js
mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoSession.java
--- a/mobile/android/chrome/geckoview/GeckoViewSelectionActionContent.js
+++ b/mobile/android/chrome/geckoview/GeckoViewSelectionActionContent.js
@@ -96,31 +96,33 @@ class GeckoViewSelectionActionContent ex
 
     return offset;
   }
 
   onEnable() {
     debug `onEnable`;
     addEventListener("mozcaretstatechanged", this, { mozSystemGroup: true });
     addEventListener("pagehide", this, { capture: true, mozSystemGroup: true });
+    addEventListener("deactivate", this, { mozSystemGroup: true });
   }
 
   onDisable() {
     debug `onDisable`;
     removeEventListener("mozcaretstatechanged", this, { mozSystemGroup: true });
     removeEventListener("pagehide", this, { capture: true, mozSystemGroup: true });
+    removeEventListener("deactivate", this, { mozSystemGroup: true });
   }
 
   /**
    * Receive and act on AccessibleCarets caret state-change
    * (mozcaretstatechanged and pagehide) events.
    */
   handleEvent(aEvent) {
-    if (aEvent.type === "pagehide") {
-      // Hide any selection actions on page hide.
+    if (aEvent.type === "pagehide" || aEvent.type === "deactivate") {
+      // Hide any selection actions on page hide or deactivate.
       aEvent = {
         reason: "visibilitychange",
         caretVisibile: false,
         selectionVisible: false,
         collapsed: true,
         selectionEditable: false,
       };
     }
--- a/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoSession.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoSession.java
@@ -1569,16 +1569,23 @@ public class GeckoSession extends LayerS
     }
 
     /**
      * Set the current selection action delegate for this GeckoSession.
      *
      * @param delegate SelectionActionDelegate instance or null to unset.
      */
     public void setSelectionActionDelegate(@Nullable SelectionActionDelegate delegate) {
+        if (getSelectionActionDelegate() != null) {
+            // When the delegate is changed or cleared, make sure onHideAction is called
+            // one last time to hide any existing selection action UI. Gecko doesn't keep
+            // track of the old delegate, so we can't rely on Gecko to do that for us.
+            getSelectionActionDelegate().onHideAction(
+                    this, GeckoSession.SelectionActionDelegate.HIDE_REASON_NO_SELECTION);
+        }
         mSelectionActionDelegate.setDelegate(delegate, this);
     }
 
     /**
      * Get the current selection action delegate for this GeckoSession.
      *
      * @return SelectionActionDelegate instance or null if not set.
      */