Bug 634555: sync with the Gecko event queue at the end of onTextChanged, r=mwu,blassey, a=blocking-fennec:2.0,blassey

This commit is contained in:
Brian Crowder
2011-03-02 12:23:02 -05:00
parent 22c424dd43
commit f537a16a77
7 changed files with 64 additions and 8 deletions

View File

@@ -44,6 +44,7 @@ import java.nio.channels.*;
import java.text.*;
import java.util.*;
import java.util.zip.*;
import java.util.concurrent.locks.*;
import android.os.*;
import android.app.*;
@@ -343,6 +344,11 @@ public class GeckoAppShell
}
}
public static void sendEventToGeckoSync(GeckoEvent e) {
sendEventToGecko(e);
geckoEventSync();
}
// Tell the Gecko event loop that an event is available.
public static native void notifyGeckoOfEvent(GeckoEvent event);
@@ -471,6 +477,37 @@ public class GeckoAppShell
imm, text, start, end, newEnd);
}
private static final ReentrantLock mGeckoSyncLock = new ReentrantLock();
private static final Condition mGeckoSyncCond = mGeckoSyncLock.newCondition();
private static boolean mGeckoSyncAcked;
// Block the current thread until the Gecko event loop is caught up
public static void geckoEventSync() {
GeckoAppShell.sendEventToGecko(
new GeckoEvent(GeckoEvent.GECKO_EVENT_SYNC));
mGeckoSyncLock.lock();
mGeckoSyncAcked = false;
while (!mGeckoSyncAcked) {
try {
mGeckoSyncCond.await();
} catch (InterruptedException e) {
break;
}
}
mGeckoSyncLock.unlock();
}
// Signal the Java thread that it's time to wake up
public static void acknowledgeEventSync() {
mGeckoSyncLock.lock();
mGeckoSyncAcked = true;
try {
mGeckoSyncCond.signal();
} finally {
mGeckoSyncLock.unlock();
}
}
public static void enableAccelerometer(boolean enable) {
SensorManager sm = (SensorManager)
GeckoApp.surfaceView.getContext().getSystemService(Context.SENSOR_SERVICE);