Bug 1416918 - 3. Use TextInputController in GeckoView; r=esawin
authorJim Chen <nchen@mozilla.com>
Wed, 13 Dec 2017 22:57:21 -0500
changeset 396429 39f1117294d19db393e644f30fc6c1c0f98ef3e0
parent 396428 29a3c1e94980304151b3b9b58f03d83b4a70ad5b
child 396430 40e3669c4a30bd4c8ad4380b0f694824aa112e5d
push id98313
push usernbeleuzu@mozilla.com
push dateFri, 15 Dec 2017 01:48:15 +0000
treeherdermozilla-inbound@cebcea19cfb0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersesawin
bugs1416918
milestone59.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1416918 - 3. Use TextInputController in GeckoView; r=esawin Use the new TextInputController API in GeckoView to process key events and input method interactions. MozReview-Commit-ID: H0oyCDkGHul
mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoSession.java
mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoView.java
widget/android/nsWindow.cpp
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoSession.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoSession.java
@@ -325,19 +325,16 @@ public class GeckoSession extends LayerS
             final NativeQueue nativeQueue = dispatcher.getNativeQueue();
             if (mNativeQueue != nativeQueue) {
                 nativeQueue.setState(mNativeQueue.getState());
                 mNativeQueue = nativeQueue;
             }
         }
 
         @WrapForJNI(dispatchTo = "proxy")
-        public native void attach(GeckoView view);
-
-        @WrapForJNI(dispatchTo = "proxy")
         public native void attachEditable(IGeckoEditableParent parent,
                                           GeckoEditableChild child);
 
         @WrapForJNI(calledFrom = "gecko")
         private synchronized void onReady() {
             if (mNativeQueue.checkAndSetState(State.INITIAL, State.READY)) {
                 Log.i(LOGTAG, "zerdatime " + SystemClock.elapsedRealtime() +
                       " - chrome startup finished");
@@ -512,30 +509,16 @@ public class GeckoSession extends LayerS
                 screenId, isPrivate);
         }
 
         if (mTextInput != null) {
             mTextInput.onWindowReady(mNativeQueue, mWindow);
         }
     }
 
-    public void attachView(final GeckoView view) {
-        if (view == null) {
-            return;
-        }
-
-        if (GeckoThread.isStateAtLeast(GeckoThread.State.PROFILE_READY)) {
-            mWindow.attach(view);
-        } else {
-            GeckoThread.queueNativeCallUntil(GeckoThread.State.PROFILE_READY,
-                    mWindow, "attach",
-                    GeckoView.class, view);
-        }
-    }
-
     public void closeWindow() {
         if (GeckoThread.isStateAtLeast(GeckoThread.State.PROFILE_READY)) {
             mWindow.close();
             mWindow.disposeNative();
         } else {
             GeckoThread.queueNativeCallUntil(GeckoThread.State.PROFILE_READY,
                     mWindow, "close");
             GeckoThread.queueNativeCallUntil(GeckoThread.State.PROFILE_READY,
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoView.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoView.java
@@ -41,17 +41,16 @@ public class GeckoView extends FrameLayo
     private static AccessibilityManager sAccessibilityManager;
 
     protected final Display mDisplay = new Display();
     protected GeckoSession mSession;
     private boolean mStateSaved;
 
     protected SurfaceView mSurfaceView;
 
-    private InputConnectionListener mInputConnectionListener;
     private boolean mIsResettingFocus;
 
     private static class SavedState extends BaseSavedState {
         public final GeckoSession session;
 
         public SavedState(final Parcelable superState, final GeckoSession session) {
             super(superState);
             this.session = session;
@@ -260,25 +259,28 @@ public class GeckoView extends FrameLayo
     public void onAttachedToWindow() {
         if (mSession == null) {
             setSession(new GeckoSession());
         }
 
         if (!mSession.isOpen()) {
             mSession.openWindow(getContext().getApplicationContext());
         }
-        mSession.attachView(this);
+
+        mSession.getTextInputController().setView(this);
 
         super.onAttachedToWindow();
     }
 
     @Override
     public void onDetachedFromWindow() {
         super.onDetachedFromWindow();
 
+        mSession.getTextInputController().setView(this);
+
         if (mStateSaved) {
             // If we saved state earlier, we don't want to close the window.
             return;
         }
 
         if (mSession != null && mSession.isOpen()) {
             mSession.closeWindow();
         }
@@ -315,20 +317,16 @@ public class GeckoView extends FrameLayo
 
         if (mSession == null) {
             setSession(ss.session);
         } else if (ss.session != null) {
             mSession.transferFrom(ss.session);
         }
     }
 
-    /* package */ void setInputConnectionListener(final InputConnectionListener icl) {
-        mInputConnectionListener = icl;
-    }
-
     @Override
     public void onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect) {
         super.onFocusChanged(gainFocus, direction, previouslyFocusedRect);
 
         if (!gainFocus || mIsResettingFocus) {
             return;
         }
 
@@ -363,73 +361,73 @@ public class GeckoView extends FrameLayo
                     mIsResettingFocus = false;
                 }
             }
         });
     }
 
     @Override
     public Handler getHandler() {
-        if (mInputConnectionListener != null) {
-            return mInputConnectionListener.getHandler(super.getHandler());
+        if (Build.VERSION.SDK_INT >= 24 || mSession == null) {
+            return super.getHandler();
         }
-        return super.getHandler();
+        return mSession.getTextInputController().getHandler(super.getHandler());
     }
 
     @Override
-    public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
-        if (mInputConnectionListener != null) {
-            return mInputConnectionListener.onCreateInputConnection(outAttrs);
+    public InputConnection onCreateInputConnection(final EditorInfo outAttrs) {
+        if (mSession == null) {
+            return null;
         }
-        return null;
+        return mSession.getTextInputController().onCreateInputConnection(outAttrs);
     }
 
     @Override
     public boolean onKeyPreIme(int keyCode, KeyEvent event) {
         if (super.onKeyPreIme(keyCode, event)) {
             return true;
         }
-        return mInputConnectionListener != null &&
-                mInputConnectionListener.onKeyPreIme(keyCode, event);
+        return mSession != null &&
+               mSession.getTextInputController().onKeyPreIme(keyCode, event);
     }
 
     @Override
     public boolean onKeyUp(int keyCode, KeyEvent event) {
         if (super.onKeyUp(keyCode, event)) {
             return true;
         }
-        return mInputConnectionListener != null &&
-                mInputConnectionListener.onKeyUp(keyCode, event);
+        return mSession != null &&
+               mSession.getTextInputController().onKeyUp(keyCode, event);
     }
 
     @Override
     public boolean onKeyDown(int keyCode, KeyEvent event) {
         if (super.onKeyDown(keyCode, event)) {
             return true;
         }
-        return mInputConnectionListener != null &&
-                mInputConnectionListener.onKeyDown(keyCode, event);
+        return mSession != null &&
+               mSession.getTextInputController().onKeyDown(keyCode, event);
     }
 
     @Override
     public boolean onKeyLongPress(int keyCode, KeyEvent event) {
         if (super.onKeyLongPress(keyCode, event)) {
             return true;
         }
-        return mInputConnectionListener != null &&
-                mInputConnectionListener.onKeyLongPress(keyCode, event);
+        return mSession != null &&
+               mSession.getTextInputController().onKeyLongPress(keyCode, event);
     }
 
     @Override
     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);
+        return mSession != null &&
+               mSession.getTextInputController().onKeyMultiple(keyCode, repeatCount, event);
     }
 
     @Override
     public void dispatchDraw(final Canvas canvas) {
         super.dispatchDraw(canvas);
 
         if (mSession != null) {
             mSession.getOverscrollEdgeEffect().draw(canvas);
--- a/widget/android/nsWindow.cpp
+++ b/widget/android/nsWindow.cpp
@@ -292,20 +292,16 @@ public:
     void Close();
 
     // Transfer this nsWindow to new GeckoSession objects.
     void Transfer(const GeckoSession::Window::LocalRef& inst,
                   jni::Object::Param aCompositor,
                   jni::Object::Param aDispatcher,
                   jni::Object::Param aSettings);
 
-    // Reattach this nsWindow to a new GeckoView.
-    void Attach(const GeckoSession::Window::LocalRef& inst,
-                jni::Object::Param aView);
-
     void AttachEditable(const GeckoSession::Window::LocalRef& inst,
                         jni::Object::Param aEditableParent,
                         jni::Object::Param aEditableChild);
 
     void EnableEventDispatcher();
 };
 
 /**
@@ -1367,22 +1363,16 @@ nsWindow::GeckoViewSupport::Transfer(con
 
     // Set the first-paint flag so that we refresh viewports, etc.
     if (RefPtr<CompositorBridgeChild> bridge = window.GetCompositorBridgeChild()) {
         bridge->SendForceIsFirstPaint();
     }
 }
 
 void
-nsWindow::GeckoViewSupport::Attach(const GeckoSession::Window::LocalRef& inst,
-                                   jni::Object::Param aView)
-{
-}
-
-void
 nsWindow::GeckoViewSupport::AttachEditable(const GeckoSession::Window::LocalRef& inst,
                                            jni::Object::Param aEditableParent,
                                            jni::Object::Param aEditableChild)
 {
     java::GeckoEditableChild::LocalRef editableChild(inst.Env());
     editableChild = java::GeckoEditableChild::Ref::From(aEditableChild);
 
     MOZ_ASSERT(!window.mEditableSupport);