Bug 1489569 - 2. Don't blur window on temporary focus loss; r=droeh a=pascalc
authorJim Chen <nchen@mozilla.com>
Mon, 10 Sep 2018 12:42:35 -0400
changeset 492441 c38cf879410f5d90b7d87f2e13f108f5c9b3d133
parent 492440 3c3062f20a3d9c69655dd8c85a7a28ffd97bc7ff
child 492442 950b4168885978e03fba79c983a007ade5e50ae9
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, pascalc
bugs1489569
milestone63.0
Bug 1489569 - 2. Don't blur window on temporary focus loss; r=droeh a=pascalc When the window temporarily loses focus (e.g. due to auto-fill popups), don't call setFocus(false). Otherwise, we can end up disrupting user interaction (e.g. causing the auto-fill popup to flicker). Only call setFocus(false) when we are reasonably sure the focus loss is not temporary. Differential Revision: https://phabricator.services.mozilla.com/D5329
mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoView.java
--- a/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoView.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoView.java
@@ -457,23 +457,36 @@ public class GeckoView extends FrameLayo
             }
         }
     }
 
     @Override
     public void onWindowFocusChanged(boolean hasWindowFocus) {
         super.onWindowFocusChanged(hasWindowFocus);
 
-        if (mSession != null) {
-            mSession.setFocused(hasWindowFocus && isFocused());
+        // Only call setFocus(true) when the window gains focus. Any focus loss could be temporary
+        // (e.g. due to auto-fill popups) and we don't want to call setFocus(false) in those cases.
+        // Instead, we call setFocus(false) in onWindowVisibilityChanged.
+        if (mSession != null && hasWindowFocus && isFocused()) {
+            mSession.setFocused(true);
         }
     }
 
     @Override
-    public void onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect) {
+    protected void onWindowVisibilityChanged(int visibility) {
+        super.onWindowVisibilityChanged(visibility);
+
+        // We can be reasonably sure that the focus loss is not temporary, so call setFocus(false).
+        if (mSession != null && visibility != View.VISIBLE && !hasWindowFocus()) {
+            mSession.setFocused(false);
+        }
+    }
+
+    @Override
+    protected void onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect) {
         super.onFocusChanged(gainFocus, direction, previouslyFocusedRect);
 
         if (mIsResettingFocus) {
             return;
         }
 
         if (mSession != null) {
             mSession.setFocused(gainFocus);