Bug 805162 - a. Expose GeckoAppShell only to Gecko-side IME interface; r=blassey

This commit is contained in:
Jim Chen 2012-10-31 17:35:31 -04:00
parent 50f2bdbf14
commit 9cab292b99
3 changed files with 38 additions and 15 deletions

View File

@ -9,6 +9,7 @@ import org.mozilla.gecko.gfx.BitmapUtils;
import org.mozilla.gecko.gfx.GeckoLayerClient;
import org.mozilla.gecko.gfx.GfxInfoThread;
import org.mozilla.gecko.gfx.ImmutableViewportMetrics;
import org.mozilla.gecko.gfx.InputConnectionHandler;
import org.mozilla.gecko.gfx.LayerView;
import org.mozilla.gecko.gfx.TouchEventHandler;
import org.mozilla.gecko.util.EventDispatcher;
@ -109,7 +110,7 @@ public class GeckoAppShell
static private boolean gRestartScheduled = false;
static private GeckoInputConnection mInputConnection = null;
static private GeckoEditableListener mEditableListener = null;
static private final HashMap<Integer, AlertNotification>
mAlertNotifications = new HashMap<Integer, AlertNotification>();
@ -534,8 +535,11 @@ public class GeckoAppShell
// Called on the UI thread after Gecko loads.
private static void geckoLoaded() {
LayerView v = GeckoApp.mAppContext.getLayerView();
mInputConnection = GeckoInputConnection.create(v);
v.setInputConnectionHandler(mInputConnection);
GeckoEditable editable = new GeckoEditable();
InputConnectionHandler ich = GeckoInputConnection.create(v, editable);
v.setInputConnectionHandler(ich);
// install the gecko => editable listener
mEditableListener = editable;
}
static void sendPendingEventsToGecko() {
@ -568,21 +572,30 @@ public class GeckoAppShell
* The Gecko-side API: API methods that Gecko calls
*/
public static void notifyIME(int type, int state) {
if (mInputConnection != null)
mInputConnection.notifyIME(type, state);
if (mEditableListener != null) {
mEditableListener.notifyIME(type, state);
}
}
public static void notifyIMEEnabled(int state, String typeHint, String modeHint,
String actionHint, boolean landscapeFS) {
// notifyIMEEnabled() still needs the landscapeFS parameter because it is called from JNI
// code that assumes it has the same signature as XUL Fennec's (which does use landscapeFS).
if (mInputConnection != null)
mInputConnection.notifyIMEEnabled(state, typeHint, modeHint, actionHint);
public static void notifyIMEEnabled(int state, String typeHint,
String modeHint, String actionHint,
boolean landscapeFS) {
// notifyIMEEnabled() still needs the landscapeFS parameter
// because it is called from JNI code that assumes it has the
// same signature as XUL Fennec's (which does use landscapeFS).
// Bug 807124 will eliminate the need for landscapeFS
if (mEditableListener != null) {
mEditableListener.notifyIMEEnabled(state, typeHint,
modeHint, actionHint);
}
}
public static void notifyIMEChange(String text, int start, int end, int newEnd) {
if (mInputConnection != null)
mInputConnection.notifyIMEChange(text, start, end, newEnd);
if (newEnd < 0) { // Selection change
mEditableListener.onSelectionChange(start, end);
} else { // Text change
mEditableListener.onTextChange(text, start, end, newEnd);
}
}
private static CountDownLatch sGeckoPendingAcks = null;
@ -1997,8 +2010,10 @@ public class GeckoAppShell
}
public static void viewSizeChanged() {
if (mInputConnection != null && mInputConnection.isIMEEnabled()) {
sendEventToGecko(GeckoEvent.createBroadcastEvent("ScrollTo:FocusedInput", ""));
LayerView v = GeckoApp.mAppContext.getLayerView();
if (v != null && v.isIMEEnabled()) {
sendEventToGecko(GeckoEvent.createBroadcastEvent(
"ScrollTo:FocusedInput", ""));
}
}

View File

@ -16,4 +16,5 @@ public interface InputConnectionHandler
boolean onKeyLongPress(int keyCode, KeyEvent event);
boolean onKeyMultiple(int keyCode, int repeatCount, KeyEvent event);
boolean onKeyUp(int keyCode, KeyEvent event);
boolean isIMEEnabled();
}

View File

@ -261,6 +261,13 @@ public class LayerView extends FrameLayout {
return false;
}
public boolean isIMEEnabled() {
if (mInputConnectionHandler != null) {
return mInputConnectionHandler.isIMEEnabled();
}
return false;
}
public void requestRender() {
if (mListener != null) {
mListener.renderRequested();