Bug 1396951 - 3. Move GeckoAppShell.viewSizeChanged() to GeckoLayerClient; r?rbarker
Let `GeckoLayerClient` directly deal with scroll-to-input on resize,
instead of going through `GeckoAppShell` and relying on
`getLayerView()`. This is a necessary fix to let us remove
`getLayerView()`, and in a follow-up bug we should actually fix
scroll-to-input to work on any GeckoView.
MozReview-Commit-ID: 1xsHh2vg08M
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoAppShell.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoAppShell.java
@@ -1579,31 +1579,16 @@ public class GeckoAppShell
/* Called by JNI from AndroidBridge, and by reflection from tests/BaseTest.java.in */
@WrapForJNI(calledFrom = "gecko")
@RobocopTarget
public static boolean isTablet() {
return HardwareUtils.isTablet();
}
- private static boolean sImeWasEnabledOnLastResize = false;
- public static void viewSizeChanged() {
- GeckoView v = (GeckoView) getLayerView();
- if (v == null) {
- return;
- }
- boolean imeIsEnabled = v.isIMEEnabled();
- if (imeIsEnabled && !sImeWasEnabledOnLastResize) {
- // The IME just came up after not being up, so let's scroll
- // to the focused input.
- EventDispatcher.getInstance().dispatch("ScrollTo:FocusedInput", null);
- }
- sImeWasEnabledOnLastResize = imeIsEnabled;
- }
-
@WrapForJNI(calledFrom = "gecko")
private static double[] getCurrentNetworkInformation() {
return GeckoNetworkManager.getInstance().getCurrentInformation();
}
@WrapForJNI(calledFrom = "gecko")
private static void enableNetworkNotifications() {
ThreadUtils.postToUiThread(new Runnable() {
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoView.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoView.java
@@ -746,17 +746,18 @@ public class GeckoView extends LayerView
public boolean onKeyMultiple(int keyCode, int repeatCount, KeyEvent event) {
if (super.onKeyMultiple(keyCode, repeatCount, event)) {
return true;
}
return mInputConnectionListener != null &&
mInputConnectionListener.onKeyMultiple(keyCode, repeatCount, event);
}
- /* package */ boolean isIMEEnabled() {
+ @Override
+ public boolean isIMEEnabled() {
return mInputConnectionListener != null &&
mInputConnectionListener.isIMEEnabled();
}
public void importScript(final String url) {
if (url.startsWith("resource://android/assets/")) {
final GeckoBundle data = new GeckoBundle(1);
data.putString("scriptURL", url);
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/gfx/GeckoLayerClient.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/gfx/GeckoLayerClient.java
@@ -28,16 +28,17 @@ class GeckoLayerClient implements LayerV
{
private static final String LOGTAG = "GeckoLayerClient";
private final Context mContext;
private IntSize mScreenSize;
private IntSize mWindowSize;
private boolean mForceRedraw;
+ private boolean mImeWasEnabledOnLastResize;
/* The current viewport metrics.
* This is volatile so that we can read and write to it from different threads.
* We avoid synchronization to make getting the viewport metrics from
* the compositor as cheap as possible. The viewport is immutable so
* we don't need to worry about anyone mutating it while we're reading from it.
* Specifically:
* 1) reading mViewportMetrics from any thread is fine without synchronization
@@ -148,17 +149,23 @@ class GeckoLayerClient implements LayerV
// here we send gecko a resize message. The code in browser.js is responsible for
// picking up on that resize event, modifying the viewport as necessary, and informing
// us of the new viewport.
sendResizeEventIfNecessary(true);
// the following call also sends gecko a message, which will be processed after the resize
// message above has updated the viewport. this message ensures that if we have just put
// focus in a text field, we scroll the content so that the text field is in view.
- GeckoAppShell.viewSizeChanged();
+ final boolean imeIsEnabled = mView.isIMEEnabled();
+ if (imeIsEnabled && !mImeWasEnabledOnLastResize) {
+ // The IME just came up after not being up, so let's scroll
+ // to the focused input.
+ EventDispatcher.getInstance().dispatch("ScrollTo:FocusedInput", null);
+ }
+ mImeWasEnabledOnLastResize = imeIsEnabled;
}
return true;
}
PanZoomController getPanZoomController() {
return mPanZoomController;
}
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/gfx/LayerView.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/gfx/LayerView.java
@@ -819,10 +819,14 @@ public class LayerView extends FrameLayo
});
return;
}
mDefaultClearColor = color;
if (isCompositorReady()) {
mCompositor.setDefaultClearColor(mDefaultClearColor);
}
- }
+ }
+
+ public boolean isIMEEnabled() {
+ return false;
+ }
}