2011-11-18 18:28:17 +00:00
|
|
|
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
|
2012-05-21 11:12:37 +00:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2011-11-18 18:28:17 +00:00
|
|
|
|
|
|
|
package org.mozilla.gecko.gfx;
|
|
|
|
|
2014-07-18 23:47:08 +00:00
|
|
|
import java.nio.IntBuffer;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
2014-04-22 14:53:48 +00:00
|
|
|
import org.mozilla.gecko.AndroidGamepadManager;
|
2014-07-30 15:19:35 +00:00
|
|
|
import org.mozilla.gecko.AppConstants.Versions;
|
2014-07-18 23:47:08 +00:00
|
|
|
import org.mozilla.gecko.EventDispatcher;
|
2013-03-28 16:40:06 +00:00
|
|
|
import org.mozilla.gecko.GeckoAccessibility;
|
2013-05-24 16:21:01 +00:00
|
|
|
import org.mozilla.gecko.GeckoAppShell;
|
2013-05-30 04:34:02 +00:00
|
|
|
import org.mozilla.gecko.GeckoEvent;
|
2013-07-04 13:53:27 +00:00
|
|
|
import org.mozilla.gecko.PrefsHelper;
|
2013-11-04 16:56:29 +00:00
|
|
|
import org.mozilla.gecko.Tab;
|
|
|
|
import org.mozilla.gecko.Tabs;
|
2012-08-20 19:43:53 +00:00
|
|
|
import org.mozilla.gecko.ZoomConstraints;
|
2013-12-06 19:43:10 +00:00
|
|
|
import org.mozilla.gecko.mozglue.RobocopTarget;
|
2014-07-18 23:47:08 +00:00
|
|
|
import org.mozilla.gecko.mozglue.generatorannotations.WrapElementForJNI;
|
2012-07-15 20:20:43 +00:00
|
|
|
|
2011-11-18 18:28:17 +00:00
|
|
|
import android.content.Context;
|
2012-08-07 14:39:04 +00:00
|
|
|
import android.graphics.Bitmap;
|
|
|
|
import android.graphics.BitmapFactory;
|
2013-09-27 05:57:57 +00:00
|
|
|
import android.graphics.Canvas;
|
2012-08-20 19:43:53 +00:00
|
|
|
import android.graphics.Color;
|
2013-10-15 15:06:01 +00:00
|
|
|
import android.graphics.Point;
|
2012-08-20 19:43:53 +00:00
|
|
|
import android.graphics.PointF;
|
2012-10-19 17:06:08 +00:00
|
|
|
import android.graphics.Rect;
|
2012-07-28 00:53:54 +00:00
|
|
|
import android.graphics.SurfaceTexture;
|
2013-02-08 21:07:12 +00:00
|
|
|
import android.os.Handler;
|
2012-07-28 00:53:54 +00:00
|
|
|
import android.util.AttributeSet;
|
|
|
|
import android.util.Log;
|
2011-11-18 18:28:17 +00:00
|
|
|
import android.view.KeyEvent;
|
|
|
|
import android.view.MotionEvent;
|
2012-07-28 00:53:54 +00:00
|
|
|
import android.view.SurfaceHolder;
|
|
|
|
import android.view.SurfaceView;
|
|
|
|
import android.view.TextureView;
|
2012-08-03 17:40:33 +00:00
|
|
|
import android.view.View;
|
2012-07-28 00:53:54 +00:00
|
|
|
import android.view.ViewGroup;
|
2011-11-18 18:28:17 +00:00
|
|
|
import android.view.inputmethod.EditorInfo;
|
|
|
|
import android.view.inputmethod.InputConnection;
|
2012-07-31 17:30:46 +00:00
|
|
|
import android.widget.FrameLayout;
|
2012-04-05 15:28:50 +00:00
|
|
|
|
2011-11-18 18:28:17 +00:00
|
|
|
/**
|
|
|
|
* A view rendered by the layer compositor.
|
|
|
|
*
|
2012-03-22 17:35:19 +00:00
|
|
|
* Note that LayerView is accessed by Robocop via reflection.
|
2011-11-18 18:28:17 +00:00
|
|
|
*/
|
2013-11-04 16:56:29 +00:00
|
|
|
public class LayerView extends FrameLayout implements Tabs.OnTabsChangedListener {
|
2014-10-10 23:17:01 +00:00
|
|
|
private static final String LOGTAG = "GeckoLayerView";
|
2012-04-07 07:09:26 +00:00
|
|
|
|
2012-08-07 14:39:04 +00:00
|
|
|
private GeckoLayerClient mLayerClient;
|
2013-02-08 14:13:09 +00:00
|
|
|
private PanZoomController mPanZoomController;
|
2013-04-25 17:47:08 +00:00
|
|
|
private LayerMarginsAnimator mMarginsAnimator;
|
2014-10-10 23:17:01 +00:00
|
|
|
private final GLController mGLController;
|
2011-11-18 18:28:17 +00:00
|
|
|
private InputConnectionHandler mInputConnectionHandler;
|
|
|
|
private LayerRenderer mRenderer;
|
2012-03-22 22:07:00 +00:00
|
|
|
/* Must be a PAINT_xxx constant */
|
2012-08-20 19:43:53 +00:00
|
|
|
private int mPaintState;
|
2012-12-15 15:43:57 +00:00
|
|
|
private int mBackgroundColor;
|
2014-05-07 19:22:14 +00:00
|
|
|
private FullScreenState mFullScreenState;
|
2012-03-22 22:07:00 +00:00
|
|
|
|
2012-07-31 17:30:46 +00:00
|
|
|
private SurfaceView mSurfaceView;
|
|
|
|
private TextureView mTextureView;
|
|
|
|
|
2012-04-05 15:28:50 +00:00
|
|
|
private Listener mListener;
|
2013-04-29 14:18:23 +00:00
|
|
|
|
2014-08-08 22:15:36 +00:00
|
|
|
private PointF mInitialTouchPoint;
|
|
|
|
private boolean mGeckoIsReady;
|
|
|
|
|
2013-04-29 14:18:23 +00:00
|
|
|
/* This should only be modified on the Java UI thread. */
|
2013-09-27 05:57:57 +00:00
|
|
|
private final Overscroll mOverscroll;
|
2012-04-05 15:28:50 +00:00
|
|
|
|
2012-10-10 20:51:31 +00:00
|
|
|
/* Flags used to determine when to show the painted surface. */
|
2012-10-18 07:01:20 +00:00
|
|
|
public static final int PAINT_START = 0;
|
|
|
|
public static final int PAINT_BEFORE_FIRST = 1;
|
|
|
|
public static final int PAINT_AFTER_FIRST = 2;
|
2012-02-02 01:08:04 +00:00
|
|
|
|
2012-10-12 11:57:07 +00:00
|
|
|
public boolean shouldUseTextureView() {
|
2012-10-12 11:57:07 +00:00
|
|
|
// Disable TextureView support for now as it causes panning/zooming
|
|
|
|
// performance regressions (see bug 792259). Uncomment the code below
|
|
|
|
// once this bug is fixed.
|
|
|
|
return false;
|
|
|
|
|
|
|
|
/*
|
2012-08-03 17:40:33 +00:00
|
|
|
// we can only use TextureView on ICS or higher
|
|
|
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
|
|
|
|
Log.i(LOGTAG, "Not using TextureView: not on ICS+");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
// and then we can only use it if we have a hardware accelerated window
|
2012-08-07 17:57:19 +00:00
|
|
|
Method m = View.class.getMethod("isHardwareAccelerated", (Class[]) null);
|
2012-08-03 17:40:33 +00:00
|
|
|
return (Boolean) m.invoke(this);
|
|
|
|
} catch (Exception e) {
|
|
|
|
Log.i(LOGTAG, "Not using TextureView: caught exception checking for hw accel: " + e.toString());
|
|
|
|
return false;
|
2012-10-12 11:57:07 +00:00
|
|
|
} */
|
2012-08-03 17:40:33 +00:00
|
|
|
}
|
|
|
|
|
2012-07-28 14:33:51 +00:00
|
|
|
public LayerView(Context context, AttributeSet attrs) {
|
|
|
|
super(context, attrs);
|
2011-11-18 18:28:17 +00:00
|
|
|
|
2013-02-28 18:28:23 +00:00
|
|
|
mGLController = GLController.getInstance(this);
|
2012-10-18 07:01:20 +00:00
|
|
|
mPaintState = PAINT_START;
|
2012-12-15 15:43:57 +00:00
|
|
|
mBackgroundColor = Color.WHITE;
|
2014-05-07 19:22:14 +00:00
|
|
|
mFullScreenState = FullScreenState.NONE;
|
2013-04-29 14:18:23 +00:00
|
|
|
|
2014-07-30 15:19:35 +00:00
|
|
|
if (Versions.feature14Plus) {
|
2013-10-23 16:12:28 +00:00
|
|
|
mOverscroll = new OverscrollEdgeEffect(this);
|
|
|
|
} else {
|
|
|
|
mOverscroll = null;
|
|
|
|
}
|
2013-11-04 16:56:29 +00:00
|
|
|
Tabs.registerOnTabsChangedListener(this);
|
2012-10-12 11:57:07 +00:00
|
|
|
}
|
|
|
|
|
2013-11-27 22:58:41 +00:00
|
|
|
public LayerView(Context context) {
|
2013-12-12 02:03:56 +00:00
|
|
|
this(context, null);
|
2013-11-27 22:58:41 +00:00
|
|
|
}
|
|
|
|
|
2012-10-12 11:57:07 +00:00
|
|
|
public void initializeView(EventDispatcher eventDispatcher) {
|
2012-08-20 19:43:53 +00:00
|
|
|
mLayerClient = new GeckoLayerClient(getContext(), this, eventDispatcher);
|
2013-10-23 16:12:28 +00:00
|
|
|
if (mOverscroll != null) {
|
|
|
|
mLayerClient.setOverscrollHandler(mOverscroll);
|
|
|
|
}
|
2013-09-27 05:57:57 +00:00
|
|
|
|
2013-02-08 14:13:09 +00:00
|
|
|
mPanZoomController = mLayerClient.getPanZoomController();
|
2013-04-25 17:47:08 +00:00
|
|
|
mMarginsAnimator = mLayerClient.getLayerMarginsAnimator();
|
2012-08-20 19:43:53 +00:00
|
|
|
|
2011-11-18 18:28:17 +00:00
|
|
|
mRenderer = new LayerRenderer(this);
|
|
|
|
mInputConnectionHandler = null;
|
|
|
|
|
|
|
|
setFocusable(true);
|
|
|
|
setFocusableInTouchMode(true);
|
2012-08-20 22:29:22 +00:00
|
|
|
|
|
|
|
GeckoAccessibility.setDelegate(this);
|
2014-08-21 00:37:32 +00:00
|
|
|
GeckoAccessibility.setAccessibilityStateChangeListener(getContext());
|
2012-08-20 19:43:53 +00:00
|
|
|
}
|
2012-08-20 19:43:53 +00:00
|
|
|
|
2014-07-18 23:47:08 +00:00
|
|
|
private static Point getEventRadius(MotionEvent event) {
|
|
|
|
return new Point((int)event.getToolMajor() / 2,
|
|
|
|
(int)event.getToolMinor() / 2);
|
2013-10-15 15:06:01 +00:00
|
|
|
}
|
|
|
|
|
2013-05-30 04:34:02 +00:00
|
|
|
public void geckoConnected() {
|
2013-07-04 13:53:27 +00:00
|
|
|
// See if we want to force 16-bit colour before doing anything
|
|
|
|
PrefsHelper.getPref("gfx.android.rgb16.force", new PrefsHelper.PrefHandlerBase() {
|
|
|
|
@Override public void prefValue(String pref, boolean force16bit) {
|
|
|
|
if (force16bit) {
|
|
|
|
GeckoAppShell.setScreenDepthOverride(16);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2013-05-30 04:34:02 +00:00
|
|
|
mLayerClient.notifyGeckoReady();
|
2014-08-08 22:15:36 +00:00
|
|
|
mInitialTouchPoint = null;
|
|
|
|
mGeckoIsReady = true;
|
|
|
|
}
|
2013-05-30 04:34:02 +00:00
|
|
|
|
2014-08-08 22:15:36 +00:00
|
|
|
private boolean sendEventToGecko(MotionEvent event) {
|
|
|
|
if (!mGeckoIsReady) {
|
|
|
|
return false;
|
|
|
|
}
|
2013-05-30 04:34:02 +00:00
|
|
|
|
2014-08-08 22:15:36 +00:00
|
|
|
int action = event.getActionMasked();
|
|
|
|
PointF point = new PointF(event.getX(), event.getY());
|
|
|
|
if (action == MotionEvent.ACTION_DOWN) {
|
|
|
|
mInitialTouchPoint = point;
|
|
|
|
}
|
2013-05-30 04:34:02 +00:00
|
|
|
|
2014-08-08 22:15:36 +00:00
|
|
|
if (mInitialTouchPoint != null && action == MotionEvent.ACTION_MOVE) {
|
|
|
|
Point p = getEventRadius(event);
|
2013-05-30 04:34:02 +00:00
|
|
|
|
2014-08-08 22:15:36 +00:00
|
|
|
if (PointUtils.subtract(point, mInitialTouchPoint).length() <
|
|
|
|
Math.max(PanZoomController.CLICK_THRESHOLD, Math.min(Math.min(p.x, p.y), PanZoomController.PAN_THRESHOLD))) {
|
|
|
|
// Don't send the touchmove event if if the users finger hasn't moved far.
|
|
|
|
// Necessary for Google Maps to work correctly. See bug 771099.
|
2013-05-30 04:34:02 +00:00
|
|
|
return true;
|
2014-08-08 22:15:36 +00:00
|
|
|
} else {
|
|
|
|
mInitialTouchPoint = null;
|
2013-05-30 04:34:02 +00:00
|
|
|
}
|
2014-08-08 22:15:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GeckoAppShell.sendEventToGecko(GeckoEvent.createMotionEvent(event, false));
|
|
|
|
return true;
|
2013-05-30 04:34:02 +00:00
|
|
|
}
|
|
|
|
|
2013-11-21 19:18:40 +00:00
|
|
|
public void showSurface() {
|
2012-10-22 14:51:29 +00:00
|
|
|
// Fix this if TextureView support is turned back on above
|
|
|
|
mSurfaceView.setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
|
2013-11-21 19:18:40 +00:00
|
|
|
public void hideSurface() {
|
2012-10-22 14:51:29 +00:00
|
|
|
// Fix this if TextureView support is turned back on above
|
|
|
|
mSurfaceView.setVisibility(View.INVISIBLE);
|
|
|
|
}
|
|
|
|
|
2012-08-20 19:43:53 +00:00
|
|
|
public void destroy() {
|
|
|
|
if (mLayerClient != null) {
|
|
|
|
mLayerClient.destroy();
|
|
|
|
}
|
2012-10-18 03:53:40 +00:00
|
|
|
if (mRenderer != null) {
|
|
|
|
mRenderer.destroy();
|
|
|
|
}
|
2013-11-11 21:56:47 +00:00
|
|
|
Tabs.unregisterOnTabsChangedListener(this);
|
2013-02-08 14:13:09 +00:00
|
|
|
}
|
|
|
|
|
2013-09-27 05:57:57 +00:00
|
|
|
@Override
|
|
|
|
public void dispatchDraw(final Canvas canvas) {
|
|
|
|
super.dispatchDraw(canvas);
|
|
|
|
|
|
|
|
// We must have a layer client to get valid viewport metrics
|
2013-10-23 16:12:28 +00:00
|
|
|
if (mLayerClient != null && mOverscroll != null) {
|
2013-09-27 05:57:57 +00:00
|
|
|
mOverscroll.draw(canvas, getViewportMetrics());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-18 18:28:17 +00:00
|
|
|
@Override
|
|
|
|
public boolean onTouchEvent(MotionEvent event) {
|
2013-02-08 14:13:09 +00:00
|
|
|
if (event.getActionMasked() == MotionEvent.ACTION_DOWN) {
|
2012-06-08 18:43:17 +00:00
|
|
|
requestFocus();
|
2013-02-08 14:13:09 +00:00
|
|
|
}
|
2012-06-08 18:43:17 +00:00
|
|
|
|
2014-08-08 22:15:36 +00:00
|
|
|
if (mMarginsAnimator != null && mMarginsAnimator.onInterceptTouchEvent(event)) {
|
2013-02-08 14:13:09 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (mPanZoomController != null && mPanZoomController.onTouchEvent(event)) {
|
|
|
|
return true;
|
|
|
|
}
|
2014-08-08 22:15:36 +00:00
|
|
|
return sendEventToGecko(event);
|
2011-11-18 18:28:17 +00:00
|
|
|
}
|
|
|
|
|
2012-06-15 22:34:22 +00:00
|
|
|
@Override
|
|
|
|
public boolean onHoverEvent(MotionEvent event) {
|
2014-08-08 22:15:36 +00:00
|
|
|
return sendEventToGecko(event);
|
2013-02-08 14:13:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onGenericMotionEvent(MotionEvent event) {
|
2014-04-22 14:53:48 +00:00
|
|
|
if (AndroidGamepadManager.handleMotionEvent(event)) {
|
|
|
|
return true;
|
|
|
|
}
|
2013-02-08 14:13:09 +00:00
|
|
|
if (mPanZoomController != null && mPanZoomController.onMotionEvent(event)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2012-06-15 22:34:22 +00:00
|
|
|
}
|
|
|
|
|
2012-10-17 16:59:18 +00:00
|
|
|
@Override
|
|
|
|
protected void onAttachedToWindow() {
|
|
|
|
// This check should not be done before the view is attached to a window
|
|
|
|
// as hardware acceleration will not be enabled at that point.
|
|
|
|
// We must create and add the SurfaceView instance before the view tree
|
|
|
|
// is fully created to avoid flickering (see bug 801477).
|
|
|
|
if (shouldUseTextureView()) {
|
|
|
|
mTextureView = new TextureView(getContext());
|
|
|
|
mTextureView.setSurfaceTextureListener(new SurfaceTextureListener());
|
2013-04-16 21:34:46 +00:00
|
|
|
|
|
|
|
// The background is set to this color when the LayerView is
|
|
|
|
// created, and it will be shown immediately at startup. Shortly
|
|
|
|
// after, the tab's background color will be used before any content
|
|
|
|
// is shown.
|
2013-05-29 18:31:52 +00:00
|
|
|
mTextureView.setBackgroundColor(Color.WHITE);
|
2012-10-17 16:59:18 +00:00
|
|
|
addView(mTextureView, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
|
|
|
|
} else {
|
|
|
|
// This will stop PropertyAnimator from creating a drawing cache (i.e. a bitmap)
|
|
|
|
// from a SurfaceView, which is just not possible (the bitmap will be transparent).
|
|
|
|
setWillNotCacheDrawing(false);
|
|
|
|
|
2013-01-10 17:32:43 +00:00
|
|
|
mSurfaceView = new LayerSurfaceView(getContext(), this);
|
2013-05-29 18:31:52 +00:00
|
|
|
mSurfaceView.setBackgroundColor(Color.WHITE);
|
2012-10-17 16:59:18 +00:00
|
|
|
addView(mSurfaceView, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
|
|
|
|
|
|
|
|
SurfaceHolder holder = mSurfaceView.getHolder();
|
|
|
|
holder.addCallback(new SurfaceListener());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-12 00:49:46 +00:00
|
|
|
// Don't expose GeckoLayerClient to things outside this package; only expose it as an Object
|
|
|
|
GeckoLayerClient getLayerClient() { return mLayerClient; }
|
|
|
|
public Object getLayerClientObject() { return mLayerClient; }
|
|
|
|
|
2013-02-08 14:13:09 +00:00
|
|
|
public PanZoomController getPanZoomController() { return mPanZoomController; }
|
2013-04-25 17:47:08 +00:00
|
|
|
public LayerMarginsAnimator getLayerMarginsAnimator() { return mMarginsAnimator; }
|
2011-11-18 18:28:17 +00:00
|
|
|
|
2012-08-20 19:43:53 +00:00
|
|
|
public ImmutableViewportMetrics getViewportMetrics() {
|
|
|
|
return mLayerClient.getViewportMetrics();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void abortPanning() {
|
2013-03-02 03:50:49 +00:00
|
|
|
if (mPanZoomController != null) {
|
|
|
|
mPanZoomController.abortPanning();
|
|
|
|
}
|
2012-08-20 19:43:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public PointF convertViewPointToLayerPoint(PointF viewPoint) {
|
|
|
|
return mLayerClient.convertViewPointToLayerPoint(viewPoint);
|
|
|
|
}
|
|
|
|
|
2012-12-15 15:43:57 +00:00
|
|
|
int getBackgroundColor() {
|
|
|
|
return mBackgroundColor;
|
2012-08-20 19:43:53 +00:00
|
|
|
}
|
|
|
|
|
2013-02-27 05:48:00 +00:00
|
|
|
@Override
|
2012-12-15 15:43:57 +00:00
|
|
|
public void setBackgroundColor(int newColor) {
|
|
|
|
mBackgroundColor = newColor;
|
2012-08-20 19:43:53 +00:00
|
|
|
requestRender();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setZoomConstraints(ZoomConstraints constraints) {
|
|
|
|
mLayerClient.setZoomConstraints(constraints);
|
|
|
|
}
|
|
|
|
|
2013-04-25 17:47:08 +00:00
|
|
|
public void setIsRTL(boolean aIsRTL) {
|
|
|
|
mLayerClient.setIsRTL(aIsRTL);
|
|
|
|
}
|
|
|
|
|
2012-08-02 18:56:52 +00:00
|
|
|
public void setInputConnectionHandler(InputConnectionHandler inputConnectionHandler) {
|
|
|
|
mInputConnectionHandler = inputConnectionHandler;
|
2013-04-26 17:26:46 +00:00
|
|
|
mLayerClient.forceRedraw(null);
|
2011-11-18 18:28:17 +00:00
|
|
|
}
|
|
|
|
|
2013-02-08 21:07:12 +00:00
|
|
|
@Override
|
|
|
|
public Handler getHandler() {
|
|
|
|
if (mInputConnectionHandler != null)
|
|
|
|
return mInputConnectionHandler.getHandler(super.getHandler());
|
|
|
|
return super.getHandler();
|
|
|
|
}
|
|
|
|
|
2011-11-18 18:28:17 +00:00
|
|
|
@Override
|
|
|
|
public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
|
|
|
|
if (mInputConnectionHandler != null)
|
|
|
|
return mInputConnectionHandler.onCreateInputConnection(outAttrs);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onKeyPreIme(int keyCode, KeyEvent event) {
|
2013-03-02 03:50:49 +00:00
|
|
|
if (mInputConnectionHandler != null && mInputConnectionHandler.onKeyPreIme(keyCode, event)) {
|
|
|
|
return true;
|
|
|
|
}
|
2011-11-18 18:28:17 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
2013-03-02 03:50:49 +00:00
|
|
|
if (mPanZoomController != null && mPanZoomController.onKeyEvent(event)) {
|
2013-03-02 03:50:48 +00:00
|
|
|
return true;
|
2013-03-02 03:50:49 +00:00
|
|
|
}
|
|
|
|
if (mInputConnectionHandler != null && mInputConnectionHandler.onKeyDown(keyCode, event)) {
|
|
|
|
return true;
|
|
|
|
}
|
2011-11-18 18:28:17 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onKeyLongPress(int keyCode, KeyEvent event) {
|
2013-03-02 03:50:49 +00:00
|
|
|
if (mInputConnectionHandler != null && mInputConnectionHandler.onKeyLongPress(keyCode, event)) {
|
|
|
|
return true;
|
|
|
|
}
|
2011-11-18 18:28:17 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onKeyMultiple(int keyCode, int repeatCount, KeyEvent event) {
|
2013-03-02 03:50:49 +00:00
|
|
|
if (mInputConnectionHandler != null && mInputConnectionHandler.onKeyMultiple(keyCode, repeatCount, event)) {
|
|
|
|
return true;
|
|
|
|
}
|
2011-11-18 18:28:17 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onKeyUp(int keyCode, KeyEvent event) {
|
2013-03-02 03:50:49 +00:00
|
|
|
if (mInputConnectionHandler != null && mInputConnectionHandler.onKeyUp(keyCode, event)) {
|
|
|
|
return true;
|
|
|
|
}
|
2011-11-18 18:28:17 +00:00
|
|
|
return false;
|
|
|
|
}
|
2011-11-30 17:27:13 +00:00
|
|
|
|
2012-11-01 20:11:02 +00:00
|
|
|
public boolean isIMEEnabled() {
|
|
|
|
if (mInputConnectionHandler != null) {
|
|
|
|
return mInputConnectionHandler.isIMEEnabled();
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-05-10 02:32:54 +00:00
|
|
|
public void requestRender() {
|
2012-04-05 15:28:50 +00:00
|
|
|
if (mListener != null) {
|
|
|
|
mListener.renderRequested();
|
2011-11-30 17:27:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-31 14:40:58 +00:00
|
|
|
public void addLayer(Layer layer) {
|
|
|
|
mRenderer.addLayer(layer);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void removeLayer(Layer layer) {
|
|
|
|
mRenderer.removeLayer(layer);
|
|
|
|
}
|
|
|
|
|
2013-09-04 18:07:11 +00:00
|
|
|
public void postRenderTask(RenderTask task) {
|
|
|
|
mRenderer.postRenderTask(task);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void removeRenderTask(RenderTask task) {
|
|
|
|
mRenderer.removeRenderTask(task);
|
|
|
|
}
|
|
|
|
|
2011-12-15 23:45:52 +00:00
|
|
|
public int getMaxTextureSize() {
|
|
|
|
return mRenderer.getMaxTextureSize();
|
|
|
|
}
|
2012-01-26 19:23:13 +00:00
|
|
|
|
2012-08-14 12:55:58 +00:00
|
|
|
/** Used by robocop for testing purposes. Not for production use! */
|
2013-12-06 19:43:10 +00:00
|
|
|
@RobocopTarget
|
2012-01-31 03:45:38 +00:00
|
|
|
public IntBuffer getPixels() {
|
|
|
|
return mRenderer.getPixels();
|
|
|
|
}
|
2012-03-12 17:03:54 +00:00
|
|
|
|
2012-10-10 20:51:31 +00:00
|
|
|
/* paintState must be a PAINT_xxx constant. */
|
2012-03-22 22:07:00 +00:00
|
|
|
public void setPaintState(int paintState) {
|
2012-10-10 20:51:31 +00:00
|
|
|
mPaintState = paintState;
|
2012-03-22 22:07:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public int getPaintState() {
|
|
|
|
return mPaintState;
|
|
|
|
}
|
2012-04-05 15:27:02 +00:00
|
|
|
|
2012-04-24 19:13:36 +00:00
|
|
|
public LayerRenderer getRenderer() {
|
2012-04-05 15:28:50 +00:00
|
|
|
return mRenderer;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setListener(Listener listener) {
|
|
|
|
mListener = listener;
|
|
|
|
}
|
|
|
|
|
2012-07-13 14:19:46 +00:00
|
|
|
Listener getListener() {
|
|
|
|
return mListener;
|
|
|
|
}
|
|
|
|
|
2012-05-10 02:32:54 +00:00
|
|
|
public GLController getGLController() {
|
2012-04-05 15:28:50 +00:00
|
|
|
return mGLController;
|
|
|
|
}
|
|
|
|
|
2013-09-05 04:29:29 +00:00
|
|
|
private Bitmap getDrawable(String name) {
|
2012-08-07 14:39:04 +00:00
|
|
|
BitmapFactory.Options options = new BitmapFactory.Options();
|
|
|
|
options.inScaled = false;
|
2013-09-05 04:29:29 +00:00
|
|
|
Context context = getContext();
|
|
|
|
int resId = context.getResources().getIdentifier(name, "drawable", context.getPackageName());
|
|
|
|
return BitmapUtils.decodeResource(context, resId, options);
|
2012-08-07 14:39:04 +00:00
|
|
|
}
|
|
|
|
|
2012-12-29 20:24:01 +00:00
|
|
|
Bitmap getScrollbarImage() {
|
2013-09-05 04:29:29 +00:00
|
|
|
return getDrawable("scrollbar");
|
2012-12-29 20:24:01 +00:00
|
|
|
}
|
|
|
|
|
2013-01-10 17:32:43 +00:00
|
|
|
/* When using a SurfaceView (mSurfaceView != null), resizing happens in two
|
|
|
|
* phases. First, the LayerView changes size, then, often some frames later,
|
|
|
|
* the SurfaceView changes size. Because of this, we need to split the
|
|
|
|
* resize into two phases to avoid jittering.
|
|
|
|
*
|
|
|
|
* The first phase is the LayerView size change. mListener is notified so
|
|
|
|
* that a synchronous draw can be performed (otherwise a blank frame will
|
|
|
|
* appear).
|
|
|
|
*
|
|
|
|
* The second phase is the SurfaceView size change. At this point, the
|
|
|
|
* backing GL surface is resized and another synchronous draw is performed.
|
|
|
|
* Gecko is also sent the new window size, and this will likely cause an
|
|
|
|
* extra draw a few frames later, after it's re-rendered and caught up.
|
|
|
|
*
|
|
|
|
* In the case that there is no valid GL surface (for example, when
|
|
|
|
* resuming, or when coming back from the awesomescreen), or we're using a
|
|
|
|
* TextureView instead of a SurfaceView, the first phase is skipped.
|
|
|
|
*/
|
2012-07-31 17:30:46 +00:00
|
|
|
private void onSizeChanged(int width, int height) {
|
2014-10-14 18:52:05 +00:00
|
|
|
if (!mGLController.isServerSurfaceValid() || mSurfaceView == null) {
|
|
|
|
surfaceChanged(width, height);
|
2013-01-10 17:32:43 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mListener != null) {
|
|
|
|
mListener.sizeChanged(width, height);
|
|
|
|
}
|
2013-09-27 05:57:57 +00:00
|
|
|
|
2013-10-23 16:12:28 +00:00
|
|
|
if (mOverscroll != null) {
|
|
|
|
mOverscroll.setSize(width, height);
|
|
|
|
}
|
2013-01-10 17:32:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void surfaceChanged(int width, int height) {
|
2013-11-15 16:28:52 +00:00
|
|
|
mGLController.serverSurfaceChanged(width, height);
|
2012-04-05 15:28:50 +00:00
|
|
|
|
|
|
|
if (mListener != null) {
|
|
|
|
mListener.surfaceChanged(width, height);
|
|
|
|
}
|
2013-09-27 05:57:57 +00:00
|
|
|
|
2013-10-23 16:12:28 +00:00
|
|
|
if (mOverscroll != null) {
|
|
|
|
mOverscroll.setSize(width, height);
|
|
|
|
}
|
2012-04-05 15:28:50 +00:00
|
|
|
}
|
|
|
|
|
2012-07-31 17:30:46 +00:00
|
|
|
private void onDestroyed() {
|
2013-11-15 16:28:52 +00:00
|
|
|
mGLController.serverSurfaceDestroyed();
|
2012-04-05 15:28:50 +00:00
|
|
|
}
|
|
|
|
|
2012-07-31 17:30:46 +00:00
|
|
|
public Object getNativeWindow() {
|
2012-08-03 17:40:33 +00:00
|
|
|
if (mSurfaceView != null)
|
2012-07-31 17:30:46 +00:00
|
|
|
return mSurfaceView.getHolder();
|
|
|
|
|
|
|
|
return mTextureView.getSurfaceTexture();
|
|
|
|
}
|
|
|
|
|
2013-11-12 18:40:59 +00:00
|
|
|
@WrapElementForJNI(allowMultithread = true, stubName = "RegisterCompositorWrapper")
|
2012-04-05 15:28:50 +00:00
|
|
|
public static GLController registerCxxCompositor() {
|
|
|
|
try {
|
2013-05-24 16:21:01 +00:00
|
|
|
LayerView layerView = GeckoAppShell.getLayerView();
|
2013-02-28 18:28:23 +00:00
|
|
|
GLController controller = layerView.getGLController();
|
|
|
|
controller.compositorCreated();
|
|
|
|
return controller;
|
2012-04-05 15:28:50 +00:00
|
|
|
} catch (Exception e) {
|
2012-07-23 19:04:28 +00:00
|
|
|
Log.e(LOGTAG, "Error registering compositor!", e);
|
2012-04-05 15:28:50 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public interface Listener {
|
|
|
|
void renderRequested();
|
2013-01-10 17:32:43 +00:00
|
|
|
void sizeChanged(int width, int height);
|
2012-04-05 15:28:50 +00:00
|
|
|
void surfaceChanged(int width, int height);
|
|
|
|
}
|
2012-07-18 00:54:54 +00:00
|
|
|
|
2012-07-31 17:30:46 +00:00
|
|
|
private class SurfaceListener implements SurfaceHolder.Callback {
|
2013-02-27 05:48:00 +00:00
|
|
|
@Override
|
2012-07-31 17:30:46 +00:00
|
|
|
public void surfaceChanged(SurfaceHolder holder, int format, int width,
|
|
|
|
int height) {
|
|
|
|
onSizeChanged(width, height);
|
|
|
|
}
|
|
|
|
|
2013-02-27 05:48:00 +00:00
|
|
|
@Override
|
2012-07-31 17:30:46 +00:00
|
|
|
public void surfaceCreated(SurfaceHolder holder) {
|
|
|
|
}
|
2012-07-18 00:54:54 +00:00
|
|
|
|
2013-02-27 05:48:00 +00:00
|
|
|
@Override
|
2012-07-31 17:30:46 +00:00
|
|
|
public void surfaceDestroyed(SurfaceHolder holder) {
|
|
|
|
onDestroyed();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-10 17:32:43 +00:00
|
|
|
/* A subclass of SurfaceView to listen to layout changes, as
|
|
|
|
* View.OnLayoutChangeListener requires API level 11.
|
|
|
|
*/
|
|
|
|
private class LayerSurfaceView extends SurfaceView {
|
|
|
|
LayerView mParent;
|
|
|
|
|
|
|
|
public LayerSurfaceView(Context aContext, LayerView aParent) {
|
|
|
|
super(aContext);
|
|
|
|
mParent = aParent;
|
|
|
|
}
|
|
|
|
|
2013-02-27 05:48:00 +00:00
|
|
|
@Override
|
2013-01-10 17:32:43 +00:00
|
|
|
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
|
|
|
|
if (changed) {
|
|
|
|
mParent.surfaceChanged(right - left, bottom - top);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-31 17:30:46 +00:00
|
|
|
private class SurfaceTextureListener implements TextureView.SurfaceTextureListener {
|
2013-03-13 20:20:57 +00:00
|
|
|
@Override
|
2012-07-31 17:30:46 +00:00
|
|
|
public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
|
|
|
|
// We don't do this for surfaceCreated above because it is always followed by a surfaceChanged,
|
|
|
|
// but that is not the case here.
|
|
|
|
onSizeChanged(width, height);
|
|
|
|
}
|
|
|
|
|
2013-03-13 20:20:57 +00:00
|
|
|
@Override
|
2012-07-31 17:30:46 +00:00
|
|
|
public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
|
|
|
|
onDestroyed();
|
|
|
|
return true; // allow Android to call release() on the SurfaceTexture, we are done drawing to it
|
|
|
|
}
|
|
|
|
|
2013-03-13 20:20:57 +00:00
|
|
|
@Override
|
2012-07-31 17:30:46 +00:00
|
|
|
public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) {
|
|
|
|
onSizeChanged(width, height);
|
|
|
|
}
|
|
|
|
|
2013-03-13 20:20:57 +00:00
|
|
|
@Override
|
2012-07-31 17:30:46 +00:00
|
|
|
public void onSurfaceTextureUpdated(SurfaceTexture surface) {
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2012-09-12 20:36:36 +00:00
|
|
|
|
2014-04-11 14:38:14 +00:00
|
|
|
@RobocopTarget
|
|
|
|
public void addDrawListener(DrawListener listener) {
|
|
|
|
mLayerClient.addDrawListener(listener);
|
|
|
|
}
|
|
|
|
|
|
|
|
@RobocopTarget
|
|
|
|
public void removeDrawListener(DrawListener listener) {
|
|
|
|
mLayerClient.removeDrawListener(listener);
|
|
|
|
}
|
|
|
|
|
|
|
|
@RobocopTarget
|
|
|
|
public static interface DrawListener {
|
|
|
|
public void drawFinished();
|
|
|
|
}
|
|
|
|
|
2012-09-12 20:36:36 +00:00
|
|
|
@Override
|
|
|
|
public void setOverScrollMode(int overscrollMode) {
|
2014-07-18 23:47:08 +00:00
|
|
|
super.setOverScrollMode(overscrollMode);
|
2013-03-02 03:50:49 +00:00
|
|
|
if (mPanZoomController != null) {
|
|
|
|
mPanZoomController.setOverScrollMode(overscrollMode);
|
|
|
|
}
|
2012-09-12 20:36:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getOverScrollMode() {
|
2013-03-02 03:50:49 +00:00
|
|
|
if (mPanZoomController != null) {
|
|
|
|
return mPanZoomController.getOverScrollMode();
|
|
|
|
}
|
2013-03-22 20:37:24 +00:00
|
|
|
|
2014-07-18 23:47:08 +00:00
|
|
|
return super.getOverScrollMode();
|
2012-09-12 20:36:36 +00:00
|
|
|
}
|
2012-10-19 17:06:08 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFocusChanged (boolean gainFocus, int direction, Rect previouslyFocusedRect) {
|
|
|
|
super.onFocusChanged(gainFocus, direction, previouslyFocusedRect);
|
|
|
|
GeckoAccessibility.onLayerViewFocusChanged(this, gainFocus);
|
|
|
|
}
|
2012-11-24 22:32:08 +00:00
|
|
|
|
2014-05-07 19:22:14 +00:00
|
|
|
public void setFullScreenState(FullScreenState state) {
|
|
|
|
mFullScreenState = state;
|
2012-11-24 22:32:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isFullScreen() {
|
2014-05-07 19:22:14 +00:00
|
|
|
return mFullScreenState != FullScreenState.NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
public FullScreenState getFullScreenState() {
|
|
|
|
return mFullScreenState;
|
2012-11-24 22:32:08 +00:00
|
|
|
}
|
2013-11-04 16:56:29 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onTabChanged(Tab tab, Tabs.TabEvents msg, Object data) {
|
2014-01-16 21:14:08 +00:00
|
|
|
if (msg == Tabs.TabEvents.VIEWPORT_CHANGE && Tabs.getInstance().isSelectedTab(tab) && mLayerClient != null) {
|
2013-11-04 16:56:29 +00:00
|
|
|
setZoomConstraints(tab.getZoomConstraints());
|
|
|
|
setIsRTL(tab.getIsRTL());
|
|
|
|
}
|
|
|
|
}
|
2014-04-12 00:49:44 +00:00
|
|
|
|
|
|
|
// Public hooks for listening to metrics changing
|
|
|
|
|
|
|
|
public interface OnMetricsChangedListener {
|
|
|
|
public void onMetricsChanged(ImmutableViewportMetrics viewport);
|
|
|
|
public void onPanZoomStopped();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setOnMetricsChangedListener(OnMetricsChangedListener listener) {
|
|
|
|
mLayerClient.setOnMetricsChangedListener(listener);
|
|
|
|
}
|
2012-04-05 15:28:50 +00:00
|
|
|
}
|