Bug 808287 - Fix out-of-order IME events during focus change; r=cpeterson

This commit is contained in:
Jim Chen 2012-11-13 17:27:19 -05:00
parent 27e7522ed0
commit 69a369d479
5 changed files with 30 additions and 2 deletions

View File

@ -53,6 +53,7 @@ final class GeckoEditable
private static final boolean DEBUG = false;
private static final String LOGTAG = "GeckoEditable";
private static final int NOTIFY_IME_REPLY_EVENT = 1;
private static final int NOTIFY_IME_FOCUSCHANGE = 3;
// Filters to implement Editable's filtering functionality
private InputFilter[] mFilters;
@ -464,6 +465,11 @@ final class GeckoEditable
public void run() {
// Make sure there are no other things going on
mActionQueue.syncWithGecko();
if (type == NOTIFY_IME_FOCUSCHANGE && state != 0) {
// Unmask events on the Gecko side
GeckoAppShell.sendEventToGecko(GeckoEvent.createIMEEvent(
GeckoEvent.IME_ACKNOWLEDGE_FOCUS));
}
if (mListener != null) {
mListener.notifyIME(type, state);
}

View File

@ -86,6 +86,7 @@ public class GeckoEvent {
public static final int IME_ADD_COMPOSITION_RANGE = 3;
public static final int IME_UPDATE_COMPOSITION = 4;
public static final int IME_REMOVE_COMPOSITION = 5;
public static final int IME_ACKNOWLEDGE_FOCUS = 6;
public static final int IME_RANGE_CARETPOSITION = 1;
public static final int IME_RANGE_RAWINPUT = 2;

View File

@ -815,7 +815,8 @@ public:
IME_SET_SELECTION = 2,
IME_ADD_COMPOSITION_RANGE = 3,
IME_UPDATE_COMPOSITION = 4,
IME_REMOVE_COMPOSITION = 5
IME_REMOVE_COMPOSITION = 5,
IME_ACKNOWLEDGE_FOCUS = 6
};
};

View File

@ -163,7 +163,9 @@ nsWindow::nsWindow() :
mFocus(nullptr),
mIMEComposing(false),
mIMEMaskSelectionUpdate(false),
mIMEMaskTextUpdate(false)
mIMEMaskTextUpdate(false),
// Mask IME events initially because there is no focused editors yet
mIMEMaskEvents(true)
{
}
@ -1880,6 +1882,18 @@ nsWindow::OnIMEEvent(AndroidGeckoEvent *ae)
composition through update composition events
*/
nsRefPtr<nsWindow> kungFuDeathGrip(this);
if (ae->Action() == AndroidGeckoEvent::IME_ACKNOWLEDGE_FOCUS) {
mIMEMaskEvents = false;
return;
} else if (mIMEMaskEvents) {
// Still reply to events, but don't do anything else
if (ae->Action() == AndroidGeckoEvent::IME_SYNCHRONIZE ||
ae->Action() == AndroidGeckoEvent::IME_REPLACE_TEXT) {
AndroidBridge::NotifyIME(AndroidBridge::NOTIFY_IME_REPLY_EVENT, 0);
}
return;
}
switch (ae->Action()) {
case AndroidGeckoEvent::IME_SYNCHRONIZE:
{
@ -2166,6 +2180,11 @@ nsWindow::OnIMEFocusChange(bool aFocus)
if (aFocus) {
OnIMETextChange(0, INT32_MAX, INT32_MAX);
OnIMESelectionChange();
} else {
// Mask events because we lost focus. On the next focus event, Gecko will notify
// Java, and Java will send an acknowledge focus event back to Gecko. That is
// where we unmask event handling
mIMEMaskEvents = true;
}
AndroidBridge::NotifyIME(AndroidBridge::NOTIFY_IME_FOCUSCHANGE,

View File

@ -184,6 +184,7 @@ protected:
bool mIMEComposing;
bool mIMEMaskSelectionUpdate, mIMEMaskTextUpdate;
bool mIMEMaskEvents;
nsString mIMEComposingText;
nsAutoTArray<nsTextRange, 4> mIMERanges;