mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-10 11:55:49 +00:00
bug 867517 - Gecko-based WebView for Android, move touch handling to LayerView r=blassey
This commit is contained in:
parent
0ffcc25992
commit
245c63df69
@ -11,9 +11,7 @@ import org.mozilla.gecko.db.BrowserDB;
|
||||
import org.mozilla.gecko.gfx.BitmapUtils;
|
||||
import org.mozilla.gecko.gfx.Layer;
|
||||
import org.mozilla.gecko.gfx.LayerView;
|
||||
import org.mozilla.gecko.gfx.PanZoomController;
|
||||
import org.mozilla.gecko.gfx.PluginLayer;
|
||||
import org.mozilla.gecko.gfx.PointUtils;
|
||||
import org.mozilla.gecko.menu.GeckoMenu;
|
||||
import org.mozilla.gecko.menu.GeckoMenuInflater;
|
||||
import org.mozilla.gecko.menu.MenuPanel;
|
||||
@ -45,7 +43,6 @@ import android.content.res.Configuration;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Point;
|
||||
import android.graphics.PointF;
|
||||
import android.graphics.Rect;
|
||||
import android.hardware.Sensor;
|
||||
import android.hardware.SensorEvent;
|
||||
@ -108,7 +105,7 @@ abstract public class GeckoApp
|
||||
implements GeckoEventListener, SensorEventListener, LocationListener,
|
||||
Tabs.OnTabsChangedListener, GeckoEventResponder,
|
||||
GeckoMenu.Callback, GeckoMenu.MenuPresenter,
|
||||
TouchEventInterceptor, ContextGetter, GeckoAppShell.GeckoInterface
|
||||
ContextGetter, GeckoAppShell.GeckoInterface
|
||||
{
|
||||
private static final String LOGTAG = "GeckoApp";
|
||||
|
||||
@ -172,7 +169,6 @@ abstract public class GeckoApp
|
||||
|
||||
private String mPrivateBrowsingSession;
|
||||
|
||||
private PointF mInitialTouchPoint = null;
|
||||
private volatile BrowserHealthRecorder mHealthRecorder = null;
|
||||
|
||||
abstract public int getLayout();
|
||||
@ -500,7 +496,7 @@ abstract public class GeckoApp
|
||||
showReadingList();
|
||||
} else if (event.equals("Gecko:Ready")) {
|
||||
mGeckoReadyStartupTimer.stop();
|
||||
connectGeckoLayerClient();
|
||||
geckoConnected();
|
||||
} else if (event.equals("ToggleChrome:Hide")) {
|
||||
toggleChrome(false);
|
||||
} else if (event.equals("ToggleChrome:Show")) {
|
||||
@ -1458,7 +1454,7 @@ abstract public class GeckoApp
|
||||
Tab selectedTab = Tabs.getInstance().getSelectedTab();
|
||||
if (selectedTab != null)
|
||||
Tabs.getInstance().notifyListeners(selectedTab, Tabs.TabEvents.SELECTED);
|
||||
connectGeckoLayerClient();
|
||||
geckoConnected();
|
||||
GeckoAppShell.setLayerClient(mLayerView.getLayerClient());
|
||||
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("Viewport:Flush", null));
|
||||
}
|
||||
@ -2190,46 +2186,13 @@ abstract public class GeckoApp
|
||||
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("Update:CheckResult", result));
|
||||
}
|
||||
|
||||
protected void connectGeckoLayerClient() {
|
||||
mLayerView.getLayerClient().notifyGeckoReady();
|
||||
|
||||
mLayerView.addTouchInterceptor(this);
|
||||
protected void geckoConnected() {
|
||||
mLayerView.geckoConnected();
|
||||
}
|
||||
|
||||
public void setAccessibilityEnabled(boolean enabled) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onInterceptTouchEvent(View view, MotionEvent event) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTouch(View view, MotionEvent event) {
|
||||
if (event == null)
|
||||
return true;
|
||||
|
||||
int action = event.getActionMasked();
|
||||
PointF point = new PointF(event.getX(), event.getY());
|
||||
if (action == MotionEvent.ACTION_DOWN) {
|
||||
mInitialTouchPoint = point;
|
||||
}
|
||||
|
||||
if (mInitialTouchPoint != null && action == MotionEvent.ACTION_MOVE) {
|
||||
if (PointUtils.subtract(point, mInitialTouchPoint).length() <
|
||||
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.
|
||||
return true;
|
||||
} else {
|
||||
mInitialTouchPoint = null;
|
||||
}
|
||||
}
|
||||
|
||||
GeckoAppShell.sendEventToGecko(GeckoEvent.createMotionEvent(event, false));
|
||||
return true;
|
||||
}
|
||||
|
||||
public static class MainLayout extends RelativeLayout {
|
||||
private TouchEventInterceptor mTouchEventInterceptor;
|
||||
private MotionEventInterceptor mMotionEventInterceptor;
|
||||
|
@ -215,8 +215,8 @@ public class WebAppImpl extends GeckoApp {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void connectGeckoLayerClient() {
|
||||
super.connectGeckoLayerClient();
|
||||
protected void geckoConnected() {
|
||||
super.geckoConnected();
|
||||
getLayerView().setOverScrollMode(View.OVER_SCROLL_NEVER);
|
||||
}
|
||||
};
|
||||
|
@ -7,6 +7,7 @@ package org.mozilla.gecko.gfx;
|
||||
|
||||
import org.mozilla.gecko.GeckoAccessibility;
|
||||
import org.mozilla.gecko.GeckoAppShell;
|
||||
import org.mozilla.gecko.GeckoEvent;
|
||||
import org.mozilla.gecko.R;
|
||||
import org.mozilla.gecko.TouchEventInterceptor;
|
||||
import org.mozilla.gecko.ZoomConstraints;
|
||||
@ -117,6 +118,45 @@ public class LayerView extends FrameLayout {
|
||||
GeckoAccessibility.setDelegate(this);
|
||||
}
|
||||
|
||||
public void geckoConnected() {
|
||||
mLayerClient.notifyGeckoReady();
|
||||
addTouchInterceptor(new TouchEventInterceptor() {
|
||||
private PointF mInitialTouchPoint = null;
|
||||
|
||||
@Override
|
||||
public boolean onInterceptTouchEvent(View view, MotionEvent event) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTouch(View view, MotionEvent event) {
|
||||
if (event == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
int action = event.getActionMasked();
|
||||
PointF point = new PointF(event.getX(), event.getY());
|
||||
if (action == MotionEvent.ACTION_DOWN) {
|
||||
mInitialTouchPoint = point;
|
||||
}
|
||||
|
||||
if (mInitialTouchPoint != null && action == MotionEvent.ACTION_MOVE) {
|
||||
if (PointUtils.subtract(point, mInitialTouchPoint).length() <
|
||||
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.
|
||||
return true;
|
||||
} else {
|
||||
mInitialTouchPoint = null;
|
||||
}
|
||||
}
|
||||
|
||||
GeckoAppShell.sendEventToGecko(GeckoEvent.createMotionEvent(event, false));
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void show() {
|
||||
// Fix this if TextureView support is turned back on above
|
||||
mSurfaceView.setVisibility(View.VISIBLE);
|
||||
|
Loading…
Reference in New Issue
Block a user