зеркало из https://github.com/mozilla/gecko-dev.git
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:
Родитель
ce3a0eabe2
Коммит
c083d97f53
|
@ -4,13 +4,13 @@
|
||||||
|
|
||||||
package org.mozilla.gecko;
|
package org.mozilla.gecko;
|
||||||
|
|
||||||
|
import org.mozilla.gecko.util.ActivityUtils;
|
||||||
import org.mozilla.gecko.util.BundleEventListener;
|
import org.mozilla.gecko.util.BundleEventListener;
|
||||||
import org.mozilla.gecko.util.EventCallback;
|
import org.mozilla.gecko.util.EventCallback;
|
||||||
import org.mozilla.gecko.util.GeckoBundle;
|
import org.mozilla.gecko.util.GeckoBundle;
|
||||||
import org.mozilla.gecko.util.ThreadUtils;
|
import org.mozilla.gecko.util.ThreadUtils;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.ContextWrapper;
|
|
||||||
import android.text.Editable;
|
import android.text.Editable;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.text.TextWatcher;
|
import android.text.TextWatcher;
|
||||||
|
@ -28,27 +28,20 @@ public class FindInPageBar extends LinearLayout
|
||||||
private static final String LOGTAG = "GeckoFindInPageBar";
|
private static final String LOGTAG = "GeckoFindInPageBar";
|
||||||
private static final String REQUEST_ID = "FindInPageBar";
|
private static final String REQUEST_ID = "FindInPageBar";
|
||||||
|
|
||||||
private final Context mContext;
|
|
||||||
/* package */ CustomEditText mFindText;
|
/* package */ CustomEditText mFindText;
|
||||||
private TextView mStatusText;
|
private TextView mStatusText;
|
||||||
private boolean mInflated;
|
private boolean mInflated;
|
||||||
private GeckoApp geckoApp;
|
private final GeckoApp geckoApp;
|
||||||
|
|
||||||
public FindInPageBar(Context context, AttributeSet attrs) {
|
public FindInPageBar(Context context, AttributeSet attrs) {
|
||||||
super(context, attrs);
|
super(context, attrs);
|
||||||
mContext = context;
|
|
||||||
setFocusable(true);
|
setFocusable(true);
|
||||||
|
|
||||||
while (context instanceof ContextWrapper) {
|
geckoApp = (GeckoApp) ActivityUtils.getActivityFromContext(context);
|
||||||
if (context instanceof GeckoApp) {
|
|
||||||
geckoApp = (GeckoApp) context;
|
|
||||||
}
|
|
||||||
context = ((ContextWrapper) context).getBaseContext();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void inflateContent() {
|
public void inflateContent() {
|
||||||
LayoutInflater inflater = LayoutInflater.from(mContext);
|
LayoutInflater inflater = LayoutInflater.from(getContext());
|
||||||
View content = inflater.inflate(R.layout.find_in_page_content, this);
|
View content = inflater.inflate(R.layout.find_in_page_content, this);
|
||||||
|
|
||||||
content.findViewById(R.id.find_prev).setOnClickListener(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.animation.ViewHelper;
|
||||||
import org.mozilla.gecko.gfx.FloatSize;
|
import org.mozilla.gecko.gfx.FloatSize;
|
||||||
import org.mozilla.gecko.gfx.ImmutableViewportMetrics;
|
import org.mozilla.gecko.gfx.ImmutableViewportMetrics;
|
||||||
|
import org.mozilla.gecko.util.ActivityUtils;
|
||||||
import org.mozilla.gecko.util.BundleEventListener;
|
import org.mozilla.gecko.util.BundleEventListener;
|
||||||
import org.mozilla.gecko.util.EventCallback;
|
import org.mozilla.gecko.util.EventCallback;
|
||||||
import org.mozilla.gecko.util.GeckoBundle;
|
import org.mozilla.gecko.util.GeckoBundle;
|
||||||
|
@ -16,7 +17,6 @@ import org.mozilla.gecko.widget.SwipeDismissListViewTouchListener;
|
||||||
import org.mozilla.gecko.widget.SwipeDismissListViewTouchListener.OnDismissCallback;
|
import org.mozilla.gecko.widget.SwipeDismissListViewTouchListener.OnDismissCallback;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.ContextWrapper;
|
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.graphics.PointF;
|
import android.graphics.PointF;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
|
@ -41,7 +41,6 @@ import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
public class FormAssistPopup extends RelativeLayout implements BundleEventListener {
|
public class FormAssistPopup extends RelativeLayout implements BundleEventListener {
|
||||||
private final Context mContext;
|
|
||||||
private final Animation mAnimation;
|
private final Animation mAnimation;
|
||||||
|
|
||||||
private ListView mAutoCompleteList;
|
private ListView mAutoCompleteList;
|
||||||
|
@ -49,7 +48,7 @@ public class FormAssistPopup extends RelativeLayout implements BundleEventListen
|
||||||
private TextView mValidationMessageText;
|
private TextView mValidationMessageText;
|
||||||
private ImageView mValidationMessageArrow;
|
private ImageView mValidationMessageArrow;
|
||||||
private ImageView mValidationMessageArrowInverted;
|
private ImageView mValidationMessageArrowInverted;
|
||||||
private GeckoApp geckoApp;
|
private final GeckoApp geckoApp;
|
||||||
|
|
||||||
private double mX;
|
private double mX;
|
||||||
private double mY;
|
private double mY;
|
||||||
|
@ -84,19 +83,13 @@ public class FormAssistPopup extends RelativeLayout implements BundleEventListen
|
||||||
|
|
||||||
public FormAssistPopup(Context context, AttributeSet attrs) {
|
public FormAssistPopup(Context context, AttributeSet attrs) {
|
||||||
super(context, attrs);
|
super(context, attrs);
|
||||||
mContext = context;
|
|
||||||
|
|
||||||
mAnimation = AnimationUtils.loadAnimation(context, R.anim.grow_fade_in);
|
mAnimation = AnimationUtils.loadAnimation(context, R.anim.grow_fade_in);
|
||||||
mAnimation.setDuration(75);
|
mAnimation.setDuration(75);
|
||||||
|
|
||||||
setFocusable(false);
|
setFocusable(false);
|
||||||
|
|
||||||
while (context instanceof ContextWrapper) {
|
geckoApp = (GeckoApp) ActivityUtils.getActivityFromContext(context);
|
||||||
if (context instanceof GeckoApp) {
|
|
||||||
geckoApp = (GeckoApp) context;
|
|
||||||
}
|
|
||||||
context = ((ContextWrapper) context).getBaseContext();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -142,7 +135,7 @@ public class FormAssistPopup extends RelativeLayout implements BundleEventListen
|
||||||
private void showAutoCompleteSuggestions(final GeckoBundle[] suggestions,
|
private void showAutoCompleteSuggestions(final GeckoBundle[] suggestions,
|
||||||
final GeckoBundle rect,
|
final GeckoBundle rect,
|
||||||
final boolean isEmpty) {
|
final boolean isEmpty) {
|
||||||
final String inputMethod = InputMethods.getCurrentInputMethod(mContext);
|
final String inputMethod = InputMethods.getCurrentInputMethod(getContext());
|
||||||
if (!isEmpty && sInputMethodBlocklist.contains(inputMethod)) {
|
if (!isEmpty && sInputMethodBlocklist.contains(inputMethod)) {
|
||||||
// Don't display the form auto-complete popup after the user starts typing
|
// Don't display the form auto-complete popup after the user starts typing
|
||||||
// to avoid confusing somes IME. See bug 758820 and bug 632744.
|
// 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) {
|
if (mAutoCompleteList == null) {
|
||||||
LayoutInflater inflater = LayoutInflater.from(mContext);
|
LayoutInflater inflater = LayoutInflater.from(getContext());
|
||||||
mAutoCompleteList = (ListView) inflater.inflate(R.layout.autocomplete_list, null);
|
mAutoCompleteList = (ListView) inflater.inflate(R.layout.autocomplete_list, null);
|
||||||
|
|
||||||
mAutoCompleteList.setOnItemClickListener(new OnItemClickListener() {
|
mAutoCompleteList.setOnItemClickListener(new OnItemClickListener() {
|
||||||
|
@ -201,7 +194,8 @@ public class FormAssistPopup extends RelativeLayout implements BundleEventListen
|
||||||
addView(mAutoCompleteList);
|
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);
|
adapter.populateSuggestionsList(suggestions);
|
||||||
mAutoCompleteList.setAdapter(adapter);
|
mAutoCompleteList.setAdapter(adapter);
|
||||||
|
|
||||||
|
@ -213,13 +207,14 @@ public class FormAssistPopup extends RelativeLayout implements BundleEventListen
|
||||||
private void showValidationMessage(final String validationMessage,
|
private void showValidationMessage(final String validationMessage,
|
||||||
final GeckoBundle rect) {
|
final GeckoBundle rect) {
|
||||||
if (mValidationMessage == null) {
|
if (mValidationMessage == null) {
|
||||||
LayoutInflater inflater = LayoutInflater.from(mContext);
|
LayoutInflater inflater = LayoutInflater.from(getContext());
|
||||||
mValidationMessage = (RelativeLayout) inflater.inflate(R.layout.validation_message, null);
|
mValidationMessage = (RelativeLayout) inflater.inflate(R.layout.validation_message, null);
|
||||||
|
|
||||||
addView(mValidationMessage);
|
addView(mValidationMessage);
|
||||||
mValidationMessageText = (TextView) mValidationMessage.findViewById(R.id.validation_message_text);
|
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 = new LayoutParams(mValidationMessageText.getLayoutParams());
|
||||||
sValidationTextLayoutNormal.setMargins(0, sValidationTextMarginTop, 0, 0);
|
sValidationTextLayoutNormal.setMargins(0, sValidationTextMarginTop, 0, 0);
|
||||||
|
@ -260,8 +255,8 @@ public class FormAssistPopup extends RelativeLayout implements BundleEventListen
|
||||||
ThreadUtils.assertOnUiThread();
|
ThreadUtils.assertOnUiThread();
|
||||||
|
|
||||||
// Don't show the form assist popup when using fullscreen VKB
|
// Don't show the form assist popup when using fullscreen VKB
|
||||||
InputMethodManager imm =
|
InputMethodManager imm = (InputMethodManager)
|
||||||
(InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
|
getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||||
if (imm.isFullscreenMode()) {
|
if (imm.isFullscreenMode()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -275,7 +270,7 @@ public class FormAssistPopup extends RelativeLayout implements BundleEventListen
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sAutoCompleteMinWidth == 0) {
|
if (sAutoCompleteMinWidth == 0) {
|
||||||
Resources res = mContext.getResources();
|
Resources res = getContext().getResources();
|
||||||
sAutoCompleteMinWidth = (int) (res.getDimension(R.dimen.autocomplete_min_width));
|
sAutoCompleteMinWidth = (int) (res.getDimension(R.dimen.autocomplete_min_width));
|
||||||
sAutoCompleteRowHeight = (int) (res.getDimension(R.dimen.autocomplete_row_height));
|
sAutoCompleteRowHeight = (int) (res.getDimension(R.dimen.autocomplete_row_height));
|
||||||
sValidationMessageHeight = (int) (res.getDimension(R.dimen.validation_message_height));
|
sValidationMessageHeight = (int) (res.getDimension(R.dimen.validation_message_height));
|
||||||
|
|
|
@ -2010,11 +2010,6 @@ public abstract class GeckoApp extends GeckoActivity
|
||||||
}
|
}
|
||||||
|
|
||||||
@RobocopTarget
|
@RobocopTarget
|
||||||
public static @NonNull EventDispatcher getEventDispatcher() {
|
|
||||||
final GeckoApp geckoApp = (GeckoApp) GeckoAppShell.getGeckoInterface();
|
|
||||||
return geckoApp.getAppEventDispatcher();
|
|
||||||
}
|
|
||||||
|
|
||||||
public @NonNull EventDispatcher getAppEventDispatcher() {
|
public @NonNull EventDispatcher getAppEventDispatcher() {
|
||||||
if (mLayerView == null) {
|
if (mLayerView == null) {
|
||||||
throw new IllegalStateException("Must not call getAppEventDispatcher() until after onCreate()");
|
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) {
|
public RepeatedEventExpecter expectWindowEvent(final EventType type, final String geckoEvent) {
|
||||||
FennecNativeDriver.log(FennecNativeDriver.LogLevel.DEBUG, "waiting for " + 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) {
|
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) {
|
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 {
|
public static final class PrefProxy implements PrefsHelper.PrefHandler, PrefWaiter {
|
||||||
|
|
|
@ -65,12 +65,12 @@ public class testEventDispatcher extends JavascriptBridgeTest implements BundleE
|
||||||
getJS().syncCall("finish_test");
|
getJS().syncCall("finish_test");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static EventDispatcher getDispatcher(final String scope) {
|
private EventDispatcher getDispatcher(final String scope) {
|
||||||
if ("global".equals(scope)) {
|
if ("global".equals(scope)) {
|
||||||
return EventDispatcher.getInstance();
|
return EventDispatcher.getInstance();
|
||||||
}
|
}
|
||||||
if ("window".equals(scope)) {
|
if ("window".equals(scope)) {
|
||||||
return GeckoApp.getEventDispatcher();
|
return ((GeckoApp) getActivity()).getAppEventDispatcher();
|
||||||
}
|
}
|
||||||
fFail("scope argument should be valid string");
|
fFail("scope argument should be valid string");
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -21,14 +21,17 @@ public class testRuntimePermissionsAPI extends JavascriptTest implements BundleE
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
super.setUp();
|
super.setUp();
|
||||||
|
|
||||||
GeckoApp.getEventDispatcher().registerUiThreadListener(this, "RuntimePermissions:Prompt");
|
((GeckoApp) getActivity()).getAppEventDispatcher()
|
||||||
|
.registerUiThreadListener(this, "RuntimePermissions:Prompt");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void tearDown() throws Exception {
|
public void tearDown() throws Exception {
|
||||||
super.tearDown();
|
super.tearDown();
|
||||||
|
|
||||||
GeckoApp.getEventDispatcher().unregisterUiThreadListener(this, "RuntimePermissions:Prompt");
|
((GeckoApp) getActivity()).getAppEventDispatcher()
|
||||||
|
.unregisterUiThreadListener(this,
|
||||||
|
"RuntimePermissions:Prompt");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Загрузка…
Ссылка в новой задаче