Bug 774205 - Guard against a null layer controller object in GeckoInputConnection. r=cpeterson

This commit is contained in:
Kartikaya Gupta 2012-07-23 14:52:55 -04:00
Родитель bdf274f8f7
Коммит b528368405
1 изменённых файлов: 17 добавлений и 9 удалений

Просмотреть файл

@ -39,6 +39,7 @@ import android.view.inputmethod.InputConnection;
import android.view.inputmethod.InputMethodManager;
import org.mozilla.gecko.gfx.InputConnectionHandler;
import org.mozilla.gecko.gfx.LayerController;
import java.util.Arrays;
import java.util.Collection;
@ -304,6 +305,11 @@ public class GeckoInputConnection
return super.setComposingText(text, newCursorPosition);
}
private static View getView() {
LayerController controller = GeckoApp.mAppContext.getLayerController();
return (controller == null ? null : controller.getView());
}
private Span getSelection() {
Editable content = getEditable();
int start = Selection.getSelectionStart(content);
@ -441,7 +447,7 @@ public class GeckoInputConnection
}
private static InputMethodManager getInputMethodManager() {
Context context = GeckoApp.mAppContext.getLayerController().getView().getContext();
Context context = getView().getContext();
return (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
}
@ -461,7 +467,7 @@ public class GeckoInputConnection
if (mUpdateRequest == null)
return;
View v = GeckoApp.mAppContext.getLayerController().getView();
View v = getView();
if (imm == null) {
imm = getInputMethodManager();
@ -524,7 +530,7 @@ public class GeckoInputConnection
}
if (imm != null && imm.isFullscreenMode()) {
View v = GeckoApp.mAppContext.getLayerController().getView();
View v = getView();
imm.updateSelection(v, start, end, -1, -1);
}
}
@ -929,7 +935,7 @@ public class GeckoInputConnection
// Let active IME process pre-IME key events
return false;
View view = GeckoApp.mAppContext.getLayerController().getView();
View view = getView();
KeyListener keyListener = TextKeyListener.getInstance();
// KeyListener returns true if it handled the event for us.
@ -977,7 +983,7 @@ public class GeckoInputConnection
// Let active IME process pre-IME key events
return false;
View view = GeckoApp.mAppContext.getLayerController().getView();
View view = getView();
KeyListener keyListener = TextKeyListener.getInstance();
if (mIMEState == IME_STATE_DISABLED ||
@ -997,7 +1003,7 @@ public class GeckoInputConnection
}
public boolean onKeyLongPress(int keyCode, KeyEvent event) {
View v = GeckoApp.mAppContext.getLayerController().getView();
View v = getView();
switch (keyCode) {
case KeyEvent.KEYCODE_MENU:
InputMethodManager imm = getInputMethodManager();
@ -1018,7 +1024,7 @@ public class GeckoInputConnection
public void notifyIME(final int type, final int state) {
postToUiThread(new Runnable() {
public void run() {
View v = GeckoApp.mAppContext.getLayerController().getView();
View v = getView();
if (v == null)
return;
@ -1063,7 +1069,7 @@ public class GeckoInputConnection
public void notifyIMEEnabled(final int state, final String typeHint, final String actionHint) {
postToUiThread(new Runnable() {
public void run() {
View v = GeckoApp.mAppContext.getLayerController().getView();
View v = getView();
if (v == null)
return;
@ -1124,7 +1130,9 @@ public class GeckoInputConnection
// TimerTask.run() is running on a random background thread, so post to UI thread.
postToUiThread(new Runnable() {
public void run() {
final View v = GeckoApp.mAppContext.getLayerController().getView();
final View v = getView();
if (v == null)
return;
final InputMethodManager imm = getInputMethodManager();
if (imm == null)