Bug 1363457 - 2. Remove GeckoApp.getEventDispatcher(); r=droeh

Use the current Activity to derive GeckoApp instances in tests, so we
no longer need GeckoApp.getEventDispatcher() at all.

Also refactor some code for getting an Activity from Context in
FindInPageBar and FormAssistPopup.

MozReview-Commit-ID: H1QNbtt9dB1
This commit is contained in:
Jim Chen 2017-05-18 17:40:32 -04:00
Родитель ce3a0eabe2
Коммит c083d97f53
6 изменённых файлов: 28 добавлений и 40 удалений

Просмотреть файл

@ -4,13 +4,13 @@
package org.mozilla.gecko;
import org.mozilla.gecko.util.ActivityUtils;
import org.mozilla.gecko.util.BundleEventListener;
import org.mozilla.gecko.util.EventCallback;
import org.mozilla.gecko.util.GeckoBundle;
import org.mozilla.gecko.util.ThreadUtils;
import android.content.Context;
import android.content.ContextWrapper;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
@ -28,27 +28,20 @@ public class FindInPageBar extends LinearLayout
private static final String LOGTAG = "GeckoFindInPageBar";
private static final String REQUEST_ID = "FindInPageBar";
private final Context mContext;
/* package */ CustomEditText mFindText;
private TextView mStatusText;
private boolean mInflated;
private GeckoApp geckoApp;
private final GeckoApp geckoApp;
public FindInPageBar(Context context, AttributeSet attrs) {
super(context, attrs);
mContext = context;
setFocusable(true);
while (context instanceof ContextWrapper) {
if (context instanceof GeckoApp) {
geckoApp = (GeckoApp) context;
}
context = ((ContextWrapper) context).getBaseContext();
}
geckoApp = (GeckoApp) ActivityUtils.getActivityFromContext(context);
}
public void inflateContent() {
LayoutInflater inflater = LayoutInflater.from(mContext);
LayoutInflater inflater = LayoutInflater.from(getContext());
View content = inflater.inflate(R.layout.find_in_page_content, this);
content.findViewById(R.id.find_prev).setOnClickListener(this);

Просмотреть файл

@ -8,6 +8,7 @@ package org.mozilla.gecko;
import org.mozilla.gecko.animation.ViewHelper;
import org.mozilla.gecko.gfx.FloatSize;
import org.mozilla.gecko.gfx.ImmutableViewportMetrics;
import org.mozilla.gecko.util.ActivityUtils;
import org.mozilla.gecko.util.BundleEventListener;
import org.mozilla.gecko.util.EventCallback;
import org.mozilla.gecko.util.GeckoBundle;
@ -16,7 +17,6 @@ import org.mozilla.gecko.widget.SwipeDismissListViewTouchListener;
import org.mozilla.gecko.widget.SwipeDismissListViewTouchListener.OnDismissCallback;
import android.content.Context;
import android.content.ContextWrapper;
import android.content.res.Resources;
import android.graphics.PointF;
import android.util.AttributeSet;
@ -41,7 +41,6 @@ import java.util.Arrays;
import java.util.Collection;
public class FormAssistPopup extends RelativeLayout implements BundleEventListener {
private final Context mContext;
private final Animation mAnimation;
private ListView mAutoCompleteList;
@ -49,7 +48,7 @@ public class FormAssistPopup extends RelativeLayout implements BundleEventListen
private TextView mValidationMessageText;
private ImageView mValidationMessageArrow;
private ImageView mValidationMessageArrowInverted;
private GeckoApp geckoApp;
private final GeckoApp geckoApp;
private double mX;
private double mY;
@ -84,19 +83,13 @@ public class FormAssistPopup extends RelativeLayout implements BundleEventListen
public FormAssistPopup(Context context, AttributeSet attrs) {
super(context, attrs);
mContext = context;
mAnimation = AnimationUtils.loadAnimation(context, R.anim.grow_fade_in);
mAnimation.setDuration(75);
setFocusable(false);
while (context instanceof ContextWrapper) {
if (context instanceof GeckoApp) {
geckoApp = (GeckoApp) context;
}
context = ((ContextWrapper) context).getBaseContext();
}
geckoApp = (GeckoApp) ActivityUtils.getActivityFromContext(context);
}
@Override
@ -142,7 +135,7 @@ public class FormAssistPopup extends RelativeLayout implements BundleEventListen
private void showAutoCompleteSuggestions(final GeckoBundle[] suggestions,
final GeckoBundle rect,
final boolean isEmpty) {
final String inputMethod = InputMethods.getCurrentInputMethod(mContext);
final String inputMethod = InputMethods.getCurrentInputMethod(getContext());
if (!isEmpty && sInputMethodBlocklist.contains(inputMethod)) {
// Don't display the form auto-complete popup after the user starts typing
// to avoid confusing somes IME. See bug 758820 and bug 632744.
@ -151,7 +144,7 @@ public class FormAssistPopup extends RelativeLayout implements BundleEventListen
}
if (mAutoCompleteList == null) {
LayoutInflater inflater = LayoutInflater.from(mContext);
LayoutInflater inflater = LayoutInflater.from(getContext());
mAutoCompleteList = (ListView) inflater.inflate(R.layout.autocomplete_list, null);
mAutoCompleteList.setOnItemClickListener(new OnItemClickListener() {
@ -201,7 +194,8 @@ public class FormAssistPopup extends RelativeLayout implements BundleEventListen
addView(mAutoCompleteList);
}
AutoCompleteListAdapter adapter = new AutoCompleteListAdapter(mContext, R.layout.autocomplete_list_item);
AutoCompleteListAdapter adapter = new AutoCompleteListAdapter(
getContext(), R.layout.autocomplete_list_item);
adapter.populateSuggestionsList(suggestions);
mAutoCompleteList.setAdapter(adapter);
@ -213,13 +207,14 @@ public class FormAssistPopup extends RelativeLayout implements BundleEventListen
private void showValidationMessage(final String validationMessage,
final GeckoBundle rect) {
if (mValidationMessage == null) {
LayoutInflater inflater = LayoutInflater.from(mContext);
LayoutInflater inflater = LayoutInflater.from(getContext());
mValidationMessage = (RelativeLayout) inflater.inflate(R.layout.validation_message, null);
addView(mValidationMessage);
mValidationMessageText = (TextView) mValidationMessage.findViewById(R.id.validation_message_text);
sValidationTextMarginTop = (int) (mContext.getResources().getDimension(R.dimen.validation_message_margin_top));
sValidationTextMarginTop = (int) (getContext().getResources().getDimension(
R.dimen.validation_message_margin_top));
sValidationTextLayoutNormal = new LayoutParams(mValidationMessageText.getLayoutParams());
sValidationTextLayoutNormal.setMargins(0, sValidationTextMarginTop, 0, 0);
@ -260,8 +255,8 @@ public class FormAssistPopup extends RelativeLayout implements BundleEventListen
ThreadUtils.assertOnUiThread();
// Don't show the form assist popup when using fullscreen VKB
InputMethodManager imm =
(InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
InputMethodManager imm = (InputMethodManager)
getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
if (imm.isFullscreenMode()) {
return;
}
@ -275,7 +270,7 @@ public class FormAssistPopup extends RelativeLayout implements BundleEventListen
}
if (sAutoCompleteMinWidth == 0) {
Resources res = mContext.getResources();
Resources res = getContext().getResources();
sAutoCompleteMinWidth = (int) (res.getDimension(R.dimen.autocomplete_min_width));
sAutoCompleteRowHeight = (int) (res.getDimension(R.dimen.autocomplete_row_height));
sValidationMessageHeight = (int) (res.getDimension(R.dimen.validation_message_height));

Просмотреть файл

@ -2010,11 +2010,6 @@ public abstract class GeckoApp extends GeckoActivity
}
@RobocopTarget
public static @NonNull EventDispatcher getEventDispatcher() {
final GeckoApp geckoApp = (GeckoApp) GeckoAppShell.getGeckoInterface();
return geckoApp.getAppEventDispatcher();
}
public @NonNull EventDispatcher getAppEventDispatcher() {
if (mLayerView == null) {
throw new IllegalStateException("Must not call getAppEventDispatcher() until after onCreate()");

Просмотреть файл

@ -224,7 +224,9 @@ public class FennecNativeActions implements Actions {
public RepeatedEventExpecter expectWindowEvent(final EventType type, final String geckoEvent) {
FennecNativeDriver.log(FennecNativeDriver.LogLevel.DEBUG, "waiting for " + geckoEvent);
return new GeckoEventExpecter(GeckoApp.getEventDispatcher(), type, geckoEvent);
return new GeckoEventExpecter(
((GeckoApp) mSolo.getCurrentActivity()).getAppEventDispatcher(),
type, geckoEvent);
}
public void sendGlobalEvent(final String event, final GeckoBundle data) {
@ -232,7 +234,7 @@ public class FennecNativeActions implements Actions {
}
public void sendWindowEvent(final String event, final GeckoBundle data) {
GeckoApp.getEventDispatcher().dispatch(event, data);
((GeckoApp) mSolo.getCurrentActivity()).getAppEventDispatcher().dispatch(event, data);
}
public static final class PrefProxy implements PrefsHelper.PrefHandler, PrefWaiter {

Просмотреть файл

@ -65,12 +65,12 @@ public class testEventDispatcher extends JavascriptBridgeTest implements BundleE
getJS().syncCall("finish_test");
}
private static EventDispatcher getDispatcher(final String scope) {
private EventDispatcher getDispatcher(final String scope) {
if ("global".equals(scope)) {
return EventDispatcher.getInstance();
}
if ("window".equals(scope)) {
return GeckoApp.getEventDispatcher();
return ((GeckoApp) getActivity()).getAppEventDispatcher();
}
fFail("scope argument should be valid string");
return null;

Просмотреть файл

@ -21,14 +21,17 @@ public class testRuntimePermissionsAPI extends JavascriptTest implements BundleE
public void setUp() throws Exception {
super.setUp();
GeckoApp.getEventDispatcher().registerUiThreadListener(this, "RuntimePermissions:Prompt");
((GeckoApp) getActivity()).getAppEventDispatcher()
.registerUiThreadListener(this, "RuntimePermissions:Prompt");
}
@Override
public void tearDown() throws Exception {
super.tearDown();
GeckoApp.getEventDispatcher().unregisterUiThreadListener(this, "RuntimePermissions:Prompt");
((GeckoApp) getActivity()).getAppEventDispatcher()
.unregisterUiThreadListener(this,
"RuntimePermissions:Prompt");
}
@Override