Bug 1139551 - Doorhanger anchor position. r=liuche, a=lmandel
authorAllison Naaktgeboren <ally@mozilla.com>
Thu, 16 Apr 2015 20:05:32 -0700
changeset 265690 fe48f12288a97e88170cb9c1d6e2b003f52d443d
parent 265689 a4373b504af74f356ad352e20fbfe95bfea46e34
child 265691 97cbb76b64ceff06b87d3b1a7d58a202518d422a
push id4718
push userraliiev@mozilla.com
push dateMon, 11 May 2015 18:39:53 +0000
treeherdermozilla-beta@c20c4ef55f08 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersliuche, lmandel
bugs1139551
milestone39.0a2
Bug 1139551 - Doorhanger anchor position. r=liuche, a=lmandel
mobile/android/base/resources/values-large-v11/dimens.xml
mobile/android/base/resources/values/dimens.xml
mobile/android/base/widget/AnchoredPopup.java
--- a/mobile/android/base/resources/values-large-v11/dimens.xml
+++ b/mobile/android/base/resources/values-large-v11/dimens.xml
@@ -1,17 +1,17 @@
 <?xml version="1.0" encoding="utf-8"?>
 <!-- This Source Code Form is subject to the terms of the Mozilla Public
    - License, v. 2.0. If a copy of the MPL was not distributed with this
    - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
 
 <resources>
 
     <dimen name="arrow_popup_container_width">400dp</dimen>
-    <dimen name="doorhanger_offsetY">2dp</dimen>
+    <dimen name="doorhanger_offsetY">126dp</dimen>
 
     <dimen name="browser_toolbar_height">56dp</dimen>
     <dimen name="browser_toolbar_button_padding">16dp</dimen>
     <dimen name="browser_toolbar_favicon_size">16dp</dimen>
 
     <dimen name="tabs_counter_size">26sp</dimen>
     <dimen name="panel_grid_view_column_width">200dp</dimen>
 
--- a/mobile/android/base/resources/values/dimens.xml
+++ b/mobile/android/base/resources/values/dimens.xml
@@ -94,17 +94,18 @@
     <!-- Padding at the top of the site identity popup, when no identity data is available. -->
     <dimen name="identity_padding_top">5dp</dimen>
 
     <dimen name="doorhanger_width">300dp</dimen>
     <dimen name="doorhanger_input_width">250dp</dimen>
     <dimen name="doorhanger_spinner_textsize">9sp</dimen>
     <dimen name="doorhanger_padding">15dp</dimen>
     <dimen name="doorhanger_offsetX">10dp</dimen>
-    <dimen name="doorhanger_offsetY">7dp</dimen>
+    <dimen name="doorhanger_offsetY">67dp</dimen>
+    <dimen name="doorhanger_GB_offsetY">7dp</dimen>
     <dimen name="doorhanger_drawable_padding">5dp</dimen>
     <dimen name="doorhanger_section_padding_small">20dp</dimen>
     <dimen name="doorhanger_section_padding_large">30dp</dimen>
     <dimen name="doorhanger_icon_size">60dp</dimen>
 
     <dimen name="context_menu_item_horizontal_padding">10dp</dimen>
 
     <dimen name="flow_layout_spacing">6dp</dimen>
--- a/mobile/android/base/widget/AnchoredPopup.java
+++ b/mobile/android/base/widget/AnchoredPopup.java
@@ -12,16 +12,17 @@ import android.app.Activity;
 import android.content.Context;
 import android.graphics.drawable.BitmapDrawable;
 import android.view.Gravity;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
 import android.widget.LinearLayout;
 import android.widget.PopupWindow;
+import org.mozilla.gecko.util.HardwareUtils;
 
 /**
  * AnchoredPopup is the base class for doorhanger notifications, and is anchored to the urlbar.
  */
 public abstract class AnchoredPopup extends PopupWindow {
     private View mAnchor;
 
     protected LinearLayout mContent;
@@ -77,34 +78,35 @@ public abstract class AnchoredPopup exte
             throw new IllegalStateException("ArrowPopup#init() must be called before ArrowPopup#show()");
         }
 
         final int[] anchorLocation = new int[2];
         if (mAnchor != null) {
             mAnchor.getLocationInWindow(anchorLocation);
         }
 
-        // If the anchor is null or out of the window bounds, just show the popup at the top of the
-        // root view, keeping the correct X coordinate.
-        if (mAnchor == null || anchorLocation[1] < 0) {
-            final View decorView = ((Activity) mContext).getWindow().getDecorView();
+        // The doorhanger should overlap the bottom of the urlbar.
+        int offsetY = mContext.getResources().getDimensionPixelOffset(R.dimen.doorhanger_offsetY);
+        final View decorView = ((Activity) mContext).getWindow().getDecorView();
 
-            // Bug in Android code causes the window layout parameters to be ignored
-            // when using showAtLocation() in Gingerbread phones.
-            if (Versions.preHC) {
-                setWidth(decorView.getWidth());
-                setHeight(decorView.getHeight());
+        // Hack for Gingerbread: showAtLocation ignores window layout parameters so we have to use
+        // showAsDropDown() instead.
+        // Height and width are always set to 0 dp.
+        if (Versions.preHC) {
+            setWidth(decorView.getWidth());
+            offsetY = mContext.getResources().getDimensionPixelOffset(R.dimen.doorhanger_GB_offsetY);
+            if (mAnchor == null) {
+              mAnchor = decorView;
             }
-
-            showAtLocation(decorView, Gravity.NO_GRAVITY, anchorLocation[0], 0);
+            showAsDropDown(mAnchor, 0, -offsetY);
             return;
         }
 
-        // We want the doorhanger to be offset from the base of the urlbar which is the anchor.
-        int offsetX = mContext.getResources().getDimensionPixelOffset(R.dimen.doorhanger_offsetX);
-        int offsetY = mContext.getResources().getDimensionPixelOffset(R.dimen.doorhanger_offsetY);
-        if (isShowing()) {
-            update(mAnchor, offsetX, -offsetY, -1, -1);
-        } else {
-            showAsDropDown(mAnchor, offsetX, -offsetY);
+        // If the anchor is null or out of the window bounds, just show the popup at the top of the
+        // root view.
+        if (mAnchor == null || anchorLocation[1] < 0) {
+            showAtLocation(decorView, Gravity.NO_GRAVITY, 0, offsetY);
+            return;
         }
+
+        showAtLocation(mAnchor, Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, offsetY);
     }
 }