Bug 1489569 - 2. Don't blur window on temporary focus loss; r=droeh a=cpeterson GECKOVIEW_62_RELBRANCH
authorJim Chen <nchen@mozilla.com>
Mon, 10 Sep 2018 12:42:35 -0400
branchGECKOVIEW_62_RELBRANCH
changeset 481129 ae008cd087d2
parent 481128 c019d0af0d64
child 481152 0ac3e96a9fa5
push id1783
push usernchen@mozilla.com
push date2018-09-14 20:24 +0000
treeherdermozilla-release@ae008cd087d2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdroeh, cpeterson
bugs1489569
milestone62.0.2
Bug 1489569 - 2. Don't blur window on temporary focus loss; r=droeh a=cpeterson 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
@@ -419,23 +419,36 @@ public class GeckoView extends FrameLayo
             mRuntime = ss.session.getRuntime();
         }
     }
 
     @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);