Bug 1441279 - 5. Use BasicSelectionActionDelegate in GeckoView by default; r?snorp
Use BasicSelectionActionDelegate for GeckoView sessions by default, if
there is no existing delegate.
MozReview-Commit-ID: 1lrEav4esKh
--- a/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoView.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoView.java
@@ -7,17 +7,19 @@
package org.mozilla.geckoview;
import org.mozilla.gecko.AndroidGamepadManager;
import org.mozilla.gecko.EventDispatcher;
import org.mozilla.gecko.gfx.DynamicToolbarAnimator;
import org.mozilla.gecko.gfx.PanZoomController;
import org.mozilla.gecko.gfx.GeckoDisplay;
import org.mozilla.gecko.InputMethods;
+import org.mozilla.gecko.util.ActivityUtils;
+import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Rect;
import android.graphics.Region;
import android.os.Build;
import android.os.Handler;
import android.os.Parcel;
@@ -46,16 +48,18 @@ public class GeckoView extends FrameLayo
protected final Display mDisplay = new Display();
protected GeckoSession mSession;
private boolean mStateSaved;
protected SurfaceView mSurfaceView;
private boolean mIsResettingFocus;
+ private GeckoSession.SelectionActionDelegate mSelectionActionDelegate;
+
private static class SavedState extends BaseSavedState {
public final GeckoSession session;
public SavedState(final Parcelable superState, final GeckoSession session) {
super(superState);
this.session = session;
}
@@ -172,16 +176,21 @@ public class GeckoView extends FrameLayo
mSurfaceView = new SurfaceView(getContext());
mSurfaceView.setBackgroundColor(Color.WHITE);
addView(mSurfaceView,
new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT));
mSurfaceView.getHolder().addCallback(mDisplay);
+
+ final Activity activity = ActivityUtils.getActivityFromContext(getContext());
+ if (activity != null) {
+ mSelectionActionDelegate = new BasicSelectionActionDelegate(activity);
+ }
}
/**
* Set a color to cover the display surface while a document is being shown. The color
* is automatically cleared once the new document starts painting. Set to
* Color.TRANSPARENT to undo the cover.
*
* @param color Cover color.
@@ -196,32 +205,36 @@ public class GeckoView extends FrameLayo
if (mSession == null) {
return null;
}
GeckoSession session = mSession;
mSession.releaseDisplay(mDisplay.release());
mSession.getOverscrollEdgeEffect().setInvalidationCallback(null);
mSession.getCompositorController().setFirstPaintCallback(null);
+ if (session.getSelectionActionDelegate() == mSelectionActionDelegate) {
+ mSession.setSelectionActionDelegate(null);
+ }
mSession = null;
return session;
}
public void setSession(final GeckoSession session) {
if (mSession != null && mSession.isOpen()) {
throw new IllegalStateException("Current session is open");
}
releaseSession();
mSession = session;
if (mSession == null) {
return;
}
mDisplay.acquire(session.acquireDisplay());
+
final Context context = getContext();
session.getOverscrollEdgeEffect().setTheme(context);
session.getOverscrollEdgeEffect().setInvalidationCallback(new Runnable() {
@Override
public void run() {
if (Build.VERSION.SDK_INT >= 16) {
GeckoView.this.postInvalidateOnAnimation();
} else {
@@ -240,16 +253,20 @@ public class GeckoView extends FrameLayo
}
session.getCompositorController().setFirstPaintCallback(new Runnable() {
@Override
public void run() {
coverUntilFirstPaint(Color.TRANSPARENT);
}
});
+
+ if (session.getSelectionActionDelegate() == null && mSelectionActionDelegate != null) {
+ session.setSelectionActionDelegate(mSelectionActionDelegate);
+ }
}
public GeckoSession getSession() {
return mSession;
}
public EventDispatcher getEventDispatcher() {
return mSession.getEventDispatcher();