Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(411)

Unified Diff: content/public/android/java/src/org/chromium/content/browser/input/ImeAdapter.java

Issue 2931443003: Add support for Android spellcheck menu in Chrome/WebViews (Closed)
Patch Set: Re-upload with no changes because I screwed something up trying to cancel the last upload when I sa… Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/public/android/java/src/org/chromium/content/browser/input/ImeAdapter.java
diff --git a/content/public/android/java/src/org/chromium/content/browser/input/ImeAdapter.java b/content/public/android/java/src/org/chromium/content/browser/input/ImeAdapter.java
index 0dc13ed95d8e0d83b6b02969c7c76234bcb62276..1dd32e30fbee8c11348f8ce1ce23692ddc739625 100644
--- a/content/public/android/java/src/org/chromium/content/browser/input/ImeAdapter.java
+++ b/content/public/android/java/src/org/chromium/content/browser/input/ImeAdapter.java
@@ -34,6 +34,7 @@ import org.chromium.base.annotations.JNINamespace;
import org.chromium.blink_public.web.WebInputEventModifier;
import org.chromium.blink_public.web.WebInputEventType;
import org.chromium.blink_public.web.WebTextInputMode;
+import org.chromium.content.browser.RenderCoordinates;
import org.chromium.content.browser.ViewUtils;
import org.chromium.content.browser.picker.InputDialogContainer;
import org.chromium.content_public.browser.ImeEventObserver;
@@ -84,6 +85,7 @@ public class ImeAdapter {
private final WebContents mWebContents;
private View mContainerView;
+ private final RenderCoordinates mRenderCoordinates;
// This holds the information necessary for constructing CursorAnchorInfo, and notifies to
// InputMethodManager on appropriate timing, depending on how IME requested the information
@@ -91,6 +93,8 @@ public class ImeAdapter {
// re-created, the monitoring status will be reset.
private final CursorAnchorInfoController mCursorAnchorInfoController;
+ private SuggestionsPopupWindow mSuggestionsPopupWindow;
+
private final List<ImeEventObserver> mEventObservers = new ArrayList<>();
private int mTextInputType = TextInputType.NONE;
@@ -147,12 +151,14 @@ public class ImeAdapter {
* @param containerView {@link View} instance which input events are posted on.
* @param wrapper InputMethodManagerWrapper that should receive all the call directed to
* InputMethodManager.
+ * @param renderCoordinates Coordinates info used to position elements.
*/
- public ImeAdapter(
- WebContents webContents, View containerView, InputMethodManagerWrapper wrapper) {
+ public ImeAdapter(WebContents webContents, View containerView,
+ InputMethodManagerWrapper wrapper, RenderCoordinates renderCoordinates) {
mWebContents = webContents;
mContainerView = containerView;
mInputMethodManagerWrapper = wrapper;
+ mRenderCoordinates = renderCoordinates;
// Deep copy newConfig so that we can notice the difference.
mCurrentConfig = new Configuration(mContainerView.getResources().getConfiguration());
@@ -898,6 +904,47 @@ public class ImeAdapter {
resetAndHideKeyboard();
}
+ public void hidePopups() {
+ if (mSuggestionsPopupWindow != null && mSuggestionsPopupWindow.isShowing()) {
+ mSuggestionsPopupWindow.dismiss();
+ suggestionMenuClosed();
+ }
+ }
+
+ @CalledByNative
+ private void showSpellCheckSuggestionMenu(
+ double caretX, double caretY, String markedText, String[] suggestions) {
+ if (mSuggestionsPopupWindow == null) {
+ mSuggestionsPopupWindow =
+ new SuggestionsPopupWindow(mInputMethodManagerWrapper.getContext(), this,
+ mContainerView, mCursorAnchorInfoController);
+ }
+
+ mSuggestionsPopupWindow.setHighlightedText(markedText);
+ mSuggestionsPopupWindow.setSpellCheckSuggestions(suggestions);
+ mSuggestionsPopupWindow.show(caretX, caretY);
+ }
+
+ public float getContentOffsetYPix() {
+ return mRenderCoordinates.getContentOffsetYPix();
+ }
+
+ public void applySpellCheckSuggestion(String suggestion) {
+ nativeApplySpellCheckSuggestion(mNativeImeAdapterAndroid, suggestion);
+ }
+
+ public void deleteActiveSuggestionRange() {
+ nativeDeleteActiveSuggestionRange(mNativeImeAdapterAndroid);
+ }
+
+ public void newWordAddedToDictionary(String word) {
+ nativeNewWordAddedToDictionary(mNativeImeAdapterAndroid, word);
+ }
+
+ public void suggestionMenuClosed() {
+ nativeSuggestionMenuClosed(mNativeImeAdapterAndroid);
+ }
+
private native long nativeInit(WebContents webContents);
private native boolean nativeSendKeyEvent(long nativeImeAdapterAndroid, KeyEvent event,
int type, int modifiers, long timestampMs, int keyCode, int scanCode,
@@ -920,4 +967,9 @@ public class ImeAdapter {
private native boolean nativeRequestTextInputStateUpdate(long nativeImeAdapterAndroid);
private native void nativeRequestCursorUpdate(long nativeImeAdapterAndroid,
boolean immediateRequest, boolean monitorRequest);
+ private native void nativeApplySpellCheckSuggestion(
+ long nativeImeAdapterAndroid, String suggestion);
+ private native void nativeDeleteActiveSuggestionRange(long nativeImeAdapterAndroid);
+ private native void nativeNewWordAddedToDictionary(long nativeImeAdapterAndroid, String word);
+ private native void nativeSuggestionMenuClosed(long nativeImeAdapterAndroid);
}

Powered by Google App Engine
This is Rietveld 408576698