Bug 1139551 - Doorhanger anchor position.r=liuche

This commit is contained in:
Allison Naaktgeboren 2015-04-16 20:05:32 -07:00
parent 54263476c1
commit 45281506ee
3 changed files with 23 additions and 20 deletions

View File

@ -6,7 +6,7 @@
<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_height_flipper">60dp</dimen>

View File

@ -104,7 +104,8 @@
<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>

View File

@ -17,6 +17,7 @@ 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.
@ -82,29 +83,30 @@ public abstract class AnchoredPopup extends PopupWindow {
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);
}
}