Bug 1416319 - 2. Remove usage of MetricsListener by FormAssistPopup; r?rbarker
This code is supposed to reposition the form assist popup if the toolbar
appears or disappears while the popup is visible, but we can move that
to a resize event listener in JS, so we don't have to maintain
the MetricsListener API for DynamicToolbarAnimator.
MozReview-Commit-ID: HR6wcJrGloR
--- a/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
+++ b/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
@@ -190,17 +190,16 @@ import java.util.regex.Pattern;
import static org.mozilla.gecko.mma.MmaDelegate.NEW_TAB;
public class BrowserApp extends GeckoApp
implements ActionModePresenter,
AnchoredPopup.OnVisibilityChangeListener,
BookmarkEditFragment.Callbacks,
BrowserSearch.OnEditSuggestionListener,
BrowserSearch.OnSearchListener,
- DynamicToolbarAnimator.MetricsListener,
DynamicToolbarAnimator.ToolbarChromeProxy,
LayoutInflater.Factory,
LightweightTheme.OnChangeListener,
OnUrlOpenListener,
OnUrlOpenInBackgroundListener,
PropertyAnimator.PropertyAnimationListener,
TabsPanel.TabsLayoutChangeListener,
View.OnKeyListener {
@@ -1664,17 +1663,16 @@ public class BrowserApp extends GeckoApp
@Override
protected void initializeChrome() {
super.initializeChrome();
mDoorHangerPopup.setAnchor(mBrowserToolbar.getDoorHangerAnchor());
mDoorHangerPopup.setOnVisibilityChangeListener(this);
if (mLayerView != null) {
- mLayerView.getDynamicToolbarAnimator().addMetricsListener(this);
mLayerView.getDynamicToolbarAnimator().setToolbarChromeProxy(this);
}
setDynamicToolbarEnabled(mDynamicToolbar.isEnabled());
// Intercept key events for gamepad shortcuts
mLayerView.setOnKeyListener(this);
// Initialize the actionbar menu items on startup for both large and small tablets
@@ -1685,27 +1683,16 @@ public class BrowserApp extends GeckoApp
}
@Override
public void onDoorHangerShow() {
mDynamicToolbar.setVisible(true, VisibilityTransition.ANIMATE);
super.onDoorHangerShow();
}
- @Override
- public void onMetricsChanged(ImmutableViewportMetrics aMetrics) {
- if (isHomePagerVisible() || mBrowserChrome == null) {
- return;
- }
-
- if (mFormAssistPopup != null) {
- mFormAssistPopup.onMetricsChanged(aMetrics);
- }
- }
-
// ToolbarChromeProxy inteface
@Override
public Bitmap getBitmapOfToolbarChrome() {
if (mBrowserChrome == null) {
return null;
}
Bitmap bm = Bitmap.createBitmap(mBrowserChrome.getWidth(), mBrowserChrome.getHeight(), Bitmap.Config.ARGB_8888);
--- a/mobile/android/base/java/org/mozilla/gecko/FormAssistPopup.java
+++ b/mobile/android/base/java/org/mozilla/gecko/FormAssistPopup.java
@@ -380,29 +380,16 @@ public class FormAssistPopup extends Rel
void onTranslationChanged() {
ThreadUtils.assertOnUiThread();
if (!isShown()) {
return;
}
positionAndShowPopup();
}
- void onMetricsChanged(final ImmutableViewportMetrics aMetrics) {
- if (!isShown()) {
- return;
- }
-
- ThreadUtils.postToUiThread(new Runnable() {
- @Override
- public void run() {
- positionAndShowPopup(aMetrics);
- }
- });
- }
-
private static final class AutoCompleteListAdapter extends ArrayAdapter<Pair<String, String>> {
private final LayoutInflater mInflater;
private final int mTextViewResourceId;
public AutoCompleteListAdapter(Context context, int textViewResourceId) {
super(context, textViewResourceId);
mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
--- a/mobile/android/modules/FormAssistant.jsm
+++ b/mobile/android/modules/FormAssistant.jsm
@@ -110,16 +110,19 @@ var FormAssistant = {
handleEvent: function(aEvent) {
switch (aEvent.type) {
case "focus": {
let currentElement = aEvent.target;
// Only show a validation message on focus.
if (this._showValidationMessage(currentElement) ||
this._isAutoComplete(currentElement)) {
this._currentFocusedElement = Cu.getWeakReference(currentElement);
+ // Start listening to resizes.
+ currentElement.ownerGlobal.addEventListener(
+ "resize", this, {capture: true, mozSystemGroup: true, once: true});
}
break;
}
case "blur": {
let focused = this.focusedElement;
if (focused) {
this._hideFormAssistPopup(focused);
@@ -171,16 +174,28 @@ var FormAssistant = {
}
// If we're not showing autocomplete suggestions, hide the form assist popup
this._hideFormAssistPopup(currentElement);
};
this._showAutoCompleteSuggestions(currentElement, checkResultsInput);
break;
}
+
+ case "resize": {
+ let focused = this.focusedElement;
+ if (focused && focused.ownerGlobal == aEvent.target) {
+ // Reposition the popup as if we just stopped pannning.
+ this.observe(null, "PanZoom:StateChange", "NOTHING");
+ // Continue to listen to resizes.
+ focused.ownerGlobal.addEventListener(
+ "resize", this, {capture: true, mozSystemGroup: true, once: true});
+ }
+ break;
+ }
}
},
// We only want to show autocomplete suggestions for certain elements
_isAutoComplete: function(aElement) {
return (aElement instanceof Ci.nsIDOMHTMLInputElement) &&
!aElement.readOnly &&
!this._isDisabledElement(aElement) &&