# HG changeset patch # User Brad Lassey # Date 1299086582 18000 # Node ID f0b9d55a71741ff241e392e650b9ab9e2517cc62 # Parent 72fa9452e56a7b0dd1702fb263702765a4cc43a6 [mq]: sync_selection diff --git a/embedding/android/GeckoInputConnection.java b/embedding/android/GeckoInputConnection.java --- a/embedding/android/GeckoInputConnection.java +++ b/embedding/android/GeckoInputConnection.java @@ -115,8 +115,7 @@ public class GeckoInputConnection delStart = mSelectionStart > leftLength ? mSelectionStart - leftLength : 0; delLen = mSelectionStart + rightLength - delStart; - GeckoAppShell.sendEventToGecko( - new GeckoEvent(GeckoEvent.IME_SET_SELECTION, delStart, delLen)); + sendSetSelection(delStart, delLen); // Restore composition / delete text if (mComposing) { @@ -160,9 +159,7 @@ public class GeckoInputConnection mComposingText = null; // Make sure caret stays at the same position - GeckoAppShell.sendEventToGecko( - new GeckoEvent(GeckoEvent.IME_SET_SELECTION, - mCompositionStart + mCompositionSelStart, 0)); + sendSetSelection(mCompositionStart + mCompositionSelStart, 0); } return true; } @@ -207,8 +204,7 @@ public class GeckoInputConnection GeckoAppShell.setClipboardText(text); // If GET_TEXT returned an empty selection, we'll select everything if (mSelectionLength <= 0) - GeckoAppShell.sendEventToGecko( - new GeckoEvent(GeckoEvent.IME_SET_SELECTION, 0, text.length())); + sendSetSelection(0, text.length()); GeckoAppShell.sendEventToGecko( new GeckoEvent(GeckoEvent.IME_DELETE_TEXT, 0, 0)); break; @@ -435,6 +431,28 @@ public class GeckoInputConnection return true; } + class SelectionRange { + SelectionRange(int start, int end) { + mStart = start; + mEnd = end; + } + public int mStart; + public int mEnd; + } + SynchronousQueue mSelectionQueue = + new SynchronousQueue(); + + void sendSetSelection(int start, int end) { + GeckoAppShell.sendEventToGecko( + new GeckoEvent(GeckoEvent.IME_SET_SELECTION, + start, end)); + try { + SelectionRange sr = mSelectionQueue.take(); + if (sr.mStart != start || sr.mEnd != end) + Log.w("GeckoInput", "seleciton notify does not match selection set (" + sr.mStart + ", " + sr.mEnd + ") != (" + start + ", " + end + ")"); + } catch(InterruptedException ie) {} + } + @Override public boolean setSelection(int start, int end) { //Log.d("GeckoAppJava", "IME: setSelection"); @@ -457,9 +475,7 @@ public class GeckoInputConnection mCompositionSelStart = start; mCompositionSelLen = end - start; } else { - GeckoAppShell.sendEventToGecko( - new GeckoEvent(GeckoEvent.IME_SET_SELECTION, - start, end - start)); + sendSetSelection(start, end - start); } return true; } @@ -528,6 +544,8 @@ public class GeckoInputConnection Selection.setSelection(GeckoApp.surfaceView.mEditable, Math.min(start, maxLen), Math.min(end, maxLen)); + mSelectionQueue.offer(new SelectionRange(Math.min(start, maxLen), + Math.min(end, maxLen))); } public void reset() { @@ -539,8 +557,7 @@ public class GeckoInputConnection // TextWatcher public void onTextChanged(CharSequence s, int start, int before, int count) { - GeckoAppShell.sendEventToGecko( - new GeckoEvent(GeckoEvent.IME_SET_SELECTION, start, before)); + sendSetSelection(start, before); if (count == 0) { GeckoAppShell.sendEventToGecko( @@ -559,10 +576,7 @@ public class GeckoInputConnection GeckoAppShell.sendEventToGecko( new GeckoEvent(GeckoEvent.IME_COMPOSITION_END, 0, 0)); - GeckoAppShell.sendEventToGecko( - new GeckoEvent(GeckoEvent.IME_SET_SELECTION, start + count, 0)); - - + sendSetSelection(start + count, 0); } }