Bug 1200181 - Zoomed view and Form Assistant should not be displayed at the same time. r=mcomella
authordominique vincent <domivinc@toitl.com>
Mon, 14 Sep 2015 14:10:16 +0200
changeset 296063 9a789bc21fb6ca50eeca7a211199cb7f810600e3
parent 296062 90ad1f7de0b024a238b798cd0ab465a8cd4a6080
child 296064 a680fbd6535e07ddbeb00c138edcbe72f4810dbb
push id5245
push userraliiev@mozilla.com
push dateThu, 29 Oct 2015 11:30:51 +0000
treeherdermozilla-beta@dac831dc1bd0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmcomella
bugs1200181
milestone43.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1200181 - Zoomed view and Form Assistant should not be displayed at the same time. r=mcomella
mobile/android/base/ZoomedView.java
mobile/android/chrome/content/browser.js
--- a/mobile/android/base/ZoomedView.java
+++ b/mobile/android/base/ZoomedView.java
@@ -73,16 +73,17 @@ public class ZoomedView extends FrameLay
     private LayerView layerView;
     private int viewWidth;
     private int viewHeight; // Only the zoomed view height, no toolbar, no shadow ...
     private int viewContainerWidth;
     private int viewContainerHeight; // Zoomed view height with toolbar and other elements like shadow, ...
     private int containterSize; // shadow, margin, ...
     private Point lastPosition;
     private boolean shouldSetVisibleOnUpdate;
+    private boolean isBlockedFromAppearing; // Prevent the display of the zoomedview while FormAssistantPopup is visible
     private PointF returnValue;
     private final PointF animationStart;
     private ImageView closeButton;
     private TextView changeZoomFactorButton;
     private boolean toolbarOnTop;
     private float offsetDueToToolBarPosition;
     private int toolbarHeight;
     private int cornerRadius;
@@ -223,39 +224,42 @@ public class ZoomedView extends FrameLay
 
     public ZoomedView(Context context, AttributeSet attrs) {
         this(context, attrs, 0);
     }
 
     public ZoomedView(Context context, AttributeSet attrs, int defStyle) {
         super(context, attrs, defStyle);
         isSimplifiedUI = true;
+        isBlockedFromAppearing = false;
         getPrefs();
         currentZoomFactorIndex = 0;
         returnValue = new PointF();
         animationStart = new PointF();
         requestRenderRunnable = new Runnable() {
             @Override
             public void run() {
                 requestZoomedViewRender();
             }
         };
         touchListener = new ZoomedViewTouchListener();
         EventDispatcher.getInstance().registerGeckoThreadListener(this,
                 "Gesture:clusteredLinksClicked", "Window:Resize", "Content:LocationChange",
-                "Gesture:CloseZoomedView", "Browser:ZoomToPageWidth", "Browser:ZoomToRect");
+                "Gesture:CloseZoomedView", "Browser:ZoomToPageWidth", "Browser:ZoomToRect",
+                "FormAssist:AutoComplete", "FormAssist:Hide");
     }
 
     void destroy() {
         PrefsHelper.removeObserver(prefDefaultZoomFactorObserverId);
         PrefsHelper.removeObserver(prefSimplifiedUIObserverId);
         ThreadUtils.removeCallbacksFromUiThread(requestRenderRunnable);
         EventDispatcher.getInstance().unregisterGeckoThreadListener(this,
                 "Gesture:clusteredLinksClicked", "Window:Resize", "Content:LocationChange",
-                "Gesture:CloseZoomedView", "Browser:ZoomToPageWidth", "Browser:ZoomToRect");
+                "Gesture:CloseZoomedView", "Browser:ZoomToPageWidth", "Browser:ZoomToRect",
+                "FormAssist:AutoComplete", "FormAssist:Hide");
     }
 
     // This method (onFinishInflate) is called only when the zoomed view class is used inside
     // an xml structure <org.mozilla.gecko.ZoomedView ...
     // It won't be called if the class is used from java code like "new  ZoomedView(context);"
     @Override
     protected void onFinishInflate() {
         super.onFinishInflate();
@@ -536,16 +540,19 @@ public class ZoomedView extends FrameLay
             @Override
             public boolean isObserver() {
                 return true;
             }
         });
     }
 
     private void startZoomDisplay(LayerView aLayerView, final int leftFromGecko, final int topFromGecko) {
+        if (isBlockedFromAppearing) {
+            return;
+        }
         if (layerView == null) {
             layerView = aLayerView;
             layerView.addZoomedViewListener(this);
             layerView.getDynamicToolbarAnimator().addTranslationListener(this);
             ImmutableViewportMetrics metrics = layerView.getViewportMetrics();
             setCapturedSize(metrics);
         }
         startTimeReRender = 0;
@@ -620,16 +627,21 @@ public class ZoomedView extends FrameLay
                         ImmutableViewportMetrics metrics = layerView.getViewportMetrics();
                         refreshZoomedViewSize(metrics);
                     } else if (event.equals("Content:LocationChange")) {
                         stopZoomDisplay(false);
                     } else if (event.equals("Gesture:CloseZoomedView") ||
                             event.equals("Browser:ZoomToPageWidth") ||
                             event.equals("Browser:ZoomToRect")) {
                         stopZoomDisplay(true);
+                    } else if (event.equals("FormAssist:AutoComplete")) {
+                        isBlockedFromAppearing = true;
+                        stopZoomDisplay(true);
+                    } else if (event.equals("FormAssist:Hide")) {
+                        isBlockedFromAppearing = false;
                     }
                 } catch (JSONException e) {
                     Log.e(LOGTAG, "JSON exception", e);
                 }
             }
         });
     }
 
--- a/mobile/android/chrome/content/browser.js
+++ b/mobile/android/chrome/content/browser.js
@@ -4803,33 +4803,46 @@ var BrowserEventHandler = {
         this._cancelTapHighlight();
         break;
 
       case "Gesture:ClickInZoomedView":
         this._clickInZoomedView = true;
         break;
 
       case "Gesture:SingleTap": {
+        let focusedElement = null;
         try {
           // If the element was previously focused, show the caret attached to it.
           let element = this._highlightElement;
-          if (element && element == BrowserApp.getFocusedInput(BrowserApp.selectedBrowser)) {
+          focusedElement = BrowserApp.getFocusedInput(BrowserApp.selectedBrowser);
+          if (element && element == focusedElement) {
             let result = SelectionHandler.attachCaret(element);
             if (result !== SelectionHandler.ERROR_NONE) {
               dump("Unexpected failure during caret attach: " + result);
             }
           }
         } catch(e) {
           Cu.reportError(e);
         }
 
         let data = JSON.parse(aData);
         let {x, y} = data;
 
         if (this._inCluster && this._clickInZoomedView != true) {
+          // If there is a focused element, the display of the zoomed view won't remove the focus.
+          // In this case, the form assistant linked to the focused element will never be closed.
+          // To avoid this situation, the focus is moved and the form assistant is closed.
+          if (focusedElement) {
+            try {
+              Services.focus.moveFocus(BrowserApp.selectedBrowser.contentWindow, null, Services.focus.MOVEFOCUS_ROOT, 0);
+            } catch(e) {
+              Cu.reportError(e);
+            }
+            Messaging.sendRequest({ type: "FormAssist:Hide" });
+          }
           this._clusterClicked(x, y);
         } else {
           if (this._clickInZoomedView != true) {
             this._closeZoomedView();
           }
           // The _highlightElement was chosen after fluffing the touch events
           // that led to this SingleTap, so by fluffing the mouse events, they
           // should find the same target since we fluff them again below.