Chromium Code Reviews| Index: content/public/android/java/src/org/chromium/content/browser/input/TextSuggestionHost.java |
| diff --git a/content/public/android/java/src/org/chromium/content/browser/input/TextSuggestionHost.java b/content/public/android/java/src/org/chromium/content/browser/input/TextSuggestionHost.java |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..d78bfefce04e11f177fd2fa37025d50b8a9f213a |
| --- /dev/null |
| +++ b/content/public/android/java/src/org/chromium/content/browser/input/TextSuggestionHost.java |
| @@ -0,0 +1,92 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +package org.chromium.content.browser.input; |
| + |
| +import android.content.Context; |
| +import android.view.View; |
| + |
| +import org.chromium.base.annotations.CalledByNative; |
| +import org.chromium.base.annotations.JNINamespace; |
| +import org.chromium.content.browser.RenderCoordinates; |
| +import org.chromium.content_public.browser.WebContents; |
| + |
| +/** |
| + * Handles displaying the Android spellcheck/text suggestion menu (provided by |
| + * SuggestionsPopupWindow) when requested by the C++ class TextSuggestionHostAndroid and applying |
| + * the commands in that menu (by calling back to the C++ class). |
| + */ |
| +@JNINamespace("content") |
| +public class TextSuggestionHost { |
| + private long mNativeTextSuggestionHost; |
| + private final Context mContext; |
| + private final WebContents mWebContents; |
| + private final View mContainerView; |
| + private final RenderCoordinates mRenderCoordinates; |
| + |
| + private SuggestionsPopupWindow mSuggestionsPopupWindow; |
| + |
| + public TextSuggestionHost(Context context, WebContents webContents, View containerView, |
| + RenderCoordinates renderCoordinates) { |
| + mContext = context; |
| + mWebContents = webContents; |
| + mContainerView = containerView; |
| + mRenderCoordinates = renderCoordinates; |
| + |
| + mNativeTextSuggestionHost = nativeInit(webContents); |
| + } |
| + |
| + @CalledByNative |
| + private void showSpellCheckSuggestionMenu( |
| + double caretX, double caretY, String markedText, String[] suggestions) { |
| + if (mSuggestionsPopupWindow == null) { |
| + mSuggestionsPopupWindow = new SuggestionsPopupWindow(mContext, this, mContainerView); |
| + } |
| + |
| + mSuggestionsPopupWindow.setHighlightedText(markedText); |
| + mSuggestionsPopupWindow.setSpellCheckSuggestions(suggestions); |
| + |
| + float density = mRenderCoordinates.getDeviceScaleFactor(); |
| + mSuggestionsPopupWindow.show( |
| + density * caretX, density * caretY + mRenderCoordinates.getContentOffsetYPix()); |
| + } |
| + |
| + public void hidePopups() { |
|
Ted C
2017/06/21 17:59:22
same thing about javadoc
rlanday
2017/06/28 01:35:34
Ok
|
| + if (mSuggestionsPopupWindow != null && mSuggestionsPopupWindow.isShowing()) { |
| + mSuggestionsPopupWindow.dismiss(); |
| + } |
| + } |
| + |
| + public void applySpellCheckSuggestion(String suggestion) { |
| + nativeApplySpellCheckSuggestion(mNativeTextSuggestionHost, suggestion); |
| + } |
| + |
| + public void deleteActiveSuggestionRange() { |
| + nativeDeleteActiveSuggestionRange(mNativeTextSuggestionHost); |
| + } |
| + |
| + public void newWordAddedToDictionary(String word) { |
| + nativeNewWordAddedToDictionary(mNativeTextSuggestionHost, word); |
| + } |
| + |
| + public void suggestionMenuClosed(boolean dismissedByItemTap) { |
| + if (!dismissedByItemTap) { |
| + nativeSuggestionMenuClosed(mNativeTextSuggestionHost); |
| + } |
| + mSuggestionsPopupWindow = null; |
| + } |
| + |
| + @CalledByNative |
| + private void destroy() { |
| + mNativeTextSuggestionHost = 0; |
| + } |
| + |
| + private native long nativeInit(WebContents webContents); |
| + private native void nativeApplySpellCheckSuggestion( |
| + long nativeTextSuggestionHostAndroid, String suggestion); |
| + private native void nativeDeleteActiveSuggestionRange(long nativeTextSuggestionHostAndroid); |
| + private native void nativeNewWordAddedToDictionary( |
| + long nativeTextSuggestionHostAndroid, String word); |
| + private native void nativeSuggestionMenuClosed(long nativeTextSuggestionHostAndroid); |
| +} |