From 245c63df6942e9dfeb14bb916961fd932c1ecdca Mon Sep 17 00:00:00 2001 From: Kartikaya Gupta Date: Thu, 30 May 2013 00:34:02 -0400 Subject: [PATCH] bug 867517 - Gecko-based WebView for Android, move touch handling to LayerView r=blassey --- mobile/android/base/GeckoApp.java | 47 +++----------------------- mobile/android/base/WebAppImpl.java | 4 +-- mobile/android/base/gfx/LayerView.java | 40 ++++++++++++++++++++++ 3 files changed, 47 insertions(+), 44 deletions(-) diff --git a/mobile/android/base/GeckoApp.java b/mobile/android/base/GeckoApp.java index ab64888095f1..37994e25f434 100644 --- a/mobile/android/base/GeckoApp.java +++ b/mobile/android/base/GeckoApp.java @@ -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; diff --git a/mobile/android/base/WebAppImpl.java b/mobile/android/base/WebAppImpl.java index bb9d9e68f8d2..25bcc348e299 100644 --- a/mobile/android/base/WebAppImpl.java +++ b/mobile/android/base/WebAppImpl.java @@ -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); } }; diff --git a/mobile/android/base/gfx/LayerView.java b/mobile/android/base/gfx/LayerView.java index a880b1677acf..bd8622741ea4 100644 --- a/mobile/android/base/gfx/LayerView.java +++ b/mobile/android/base/gfx/LayerView.java @@ -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);