Commit ca700124 authored by Ryan Landay's avatar Ryan Landay Committed by Commit Bot

Add support for Android SuggestionSpans with FLAG_MISSPELLED set

Now that we have support in Blink for suggestion markers that remove themselves
after applying a replacement, we can enable support for Android SuggestionSpans
with FLAG_MISSPELLED set.

Bug: 672259
Change-Id: I01b9542bace2a6f9196bb1501b71062dfc35bd27
Reviewed-on: https://chromium-review.googlesource.com/679475Reviewed-by: default avatarTed Choc <tedchoc@chromium.org>
Commit-Queue: Ryan Landay <rlanday@chromium.org>
Cr-Commit-Position: refs/heads/master@{#504477}
parent 75b3aaf6
...@@ -99,21 +99,25 @@ void AppendSuggestionSpan(JNIEnv* env, ...@@ -99,21 +99,25 @@ void AppendSuggestionSpan(JNIEnv* env,
jlong ime_text_spans_ptr, jlong ime_text_spans_ptr,
jint start, jint start,
jint end, jint end,
jboolean is_misspelling,
jint underline_color, jint underline_color,
jint suggestion_highlight_color, jint suggestion_highlight_color,
const JavaParamRef<jobjectArray>& suggestions) { const JavaParamRef<jobjectArray>& suggestions) {
DCHECK_GE(start, 0); DCHECK_GE(start, 0);
DCHECK_GE(end, 0); DCHECK_GE(end, 0);
blink::WebImeTextSpan::Type type =
is_misspelling ? blink::WebImeTextSpan::Type::kMisspellingSuggestion
: blink::WebImeTextSpan::Type::kSuggestion;
std::vector<blink::WebImeTextSpan>* ime_text_spans = std::vector<blink::WebImeTextSpan>* ime_text_spans =
reinterpret_cast<std::vector<blink::WebImeTextSpan>*>(ime_text_spans_ptr); reinterpret_cast<std::vector<blink::WebImeTextSpan>*>(ime_text_spans_ptr);
std::vector<std::string> suggestions_vec; std::vector<std::string> suggestions_vec;
AppendJavaStringArrayToStringVector(env, suggestions, &suggestions_vec); AppendJavaStringArrayToStringVector(env, suggestions, &suggestions_vec);
ime_text_spans->push_back(blink::WebImeTextSpan( ime_text_spans->push_back(blink::WebImeTextSpan(
blink::WebImeTextSpan::Type::kSuggestion, static_cast<unsigned>(start), type, static_cast<unsigned>(start), static_cast<unsigned>(end),
static_cast<unsigned>(end), static_cast<unsigned>(underline_color), true, static_cast<unsigned>(underline_color), true, SK_ColorTRANSPARENT,
SK_ColorTRANSPARENT, static_cast<unsigned>(suggestion_highlight_color), static_cast<unsigned>(suggestion_highlight_color), suggestions_vec));
suggestions_vec));
} }
// Callback from Java to convert UnderlineSpan data to a // Callback from Java to convert UnderlineSpan data to a
......
...@@ -911,8 +911,7 @@ public class ImeAdapter { ...@@ -911,8 +911,7 @@ public class ImeAdapter {
} else if (span instanceof SuggestionSpan) { } else if (span instanceof SuggestionSpan) {
final SuggestionSpan suggestionSpan = (SuggestionSpan) span; final SuggestionSpan suggestionSpan = (SuggestionSpan) span;
// We currently only support FLAG_EASY_CORRECT SuggestionSpans. // We currently only support FLAG_EASY_CORRECT and FLAG_MISSPELLED SuggestionSpans.
// TODO(rlanday): support FLAG_MISSPELLED SuggestionSpans.
// Other types: // Other types:
// - FLAG_AUTO_CORRECTION is used e.g. by Samsung's IME to flash a blue background // - FLAG_AUTO_CORRECTION is used e.g. by Samsung's IME to flash a blue background
...@@ -923,7 +922,10 @@ public class ImeAdapter { ...@@ -923,7 +922,10 @@ public class ImeAdapter {
// flags set and no underline color to add suggestions to words marked as // flags set and no underline color to add suggestions to words marked as
// misspelled (instead of having the spell checker return the suggestions when // misspelled (instead of having the spell checker return the suggestions when
// called). We don't support these either. // called). We don't support these either.
if (suggestionSpan.getFlags() != SuggestionSpan.FLAG_EASY_CORRECT) { final boolean isMisspellingSpan =
(suggestionSpan.getFlags() & SuggestionSpan.FLAG_MISSPELLED) != 0;
if (suggestionSpan.getFlags() != SuggestionSpan.FLAG_EASY_CORRECT
&& !isMisspellingSpan) {
continue; continue;
} }
...@@ -937,8 +939,8 @@ public class ImeAdapter { ...@@ -937,8 +939,8 @@ public class ImeAdapter {
nativeAppendSuggestionSpan(imeTextSpans, nativeAppendSuggestionSpan(imeTextSpans,
spannableString.getSpanStart(suggestionSpan), spannableString.getSpanStart(suggestionSpan),
spannableString.getSpanEnd(suggestionSpan), underlineColor, spannableString.getSpanEnd(suggestionSpan), isMisspellingSpan,
suggestionHighlightColor, suggestionSpan.getSuggestions()); underlineColor, suggestionHighlightColor, suggestionSpan.getSuggestions());
} }
} }
} }
...@@ -971,7 +973,8 @@ public class ImeAdapter { ...@@ -971,7 +973,8 @@ public class ImeAdapter {
private static native void nativeAppendBackgroundColorSpan( private static native void nativeAppendBackgroundColorSpan(
long spanPtr, int start, int end, int backgroundColor); long spanPtr, int start, int end, int backgroundColor);
private static native void nativeAppendSuggestionSpan(long spanPtr, int start, int end, private static native void nativeAppendSuggestionSpan(long spanPtr, int start, int end,
int underlineColor, int suggestionHighlightColor, String[] suggestions); boolean isMisspelling, int underlineColor, int suggestionHighlightColor,
String[] suggestions);
private native void nativeSetComposingText(long nativeImeAdapterAndroid, CharSequence text, private native void nativeSetComposingText(long nativeImeAdapterAndroid, CharSequence text,
String textStr, int newCursorPosition); String textStr, int newCursorPosition);
private native void nativeCommitText( private native void nativeCommitText(
......
...@@ -147,6 +147,53 @@ public class TextSuggestionMenuTest { ...@@ -147,6 +147,53 @@ public class TextSuggestionMenuTest {
waitForMenuToHide(cvc); waitForMenuToHide(cvc);
} }
@Test
@LargeTest
public void testApplyMisspellingSuggestion()
throws InterruptedException, Throwable, TimeoutException {
final ContentViewCore cvc = mRule.getContentViewCore();
WebContents webContents = cvc.getWebContents();
DOMUtils.focusNode(webContents, "div");
SpannableString textToCommit = new SpannableString("word");
SuggestionSpan suggestionSpan = new SuggestionSpan(mRule.getContentViewCore().getContext(),
new String[] {"replacement"},
SuggestionSpan.FLAG_EASY_CORRECT | SuggestionSpan.FLAG_MISSPELLED);
textToCommit.setSpan(suggestionSpan, 0, 4, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
mRule.commitText(textToCommit, 1);
DOMUtils.clickNode(cvc, "span");
waitForMenuToShow(cvc);
// There should be 2 child views: 1 suggestion plus the list footer.
Assert.assertEquals(2, getSuggestionList(cvc).getChildCount());
Assert.assertEquals(
"replacement", ((TextView) getSuggestionButton(cvc, 0)).getText().toString());
TouchCommon.singleClickView(getSuggestionButton(cvc, 0));
CriteriaHelper.pollInstrumentationThread(new Criteria() {
@Override
public boolean isSatisfied() {
try {
return DOMUtils.getNodeContents(cvc.getWebContents(), "div")
.equals("replacement");
} catch (InterruptedException | TimeoutException e) {
return false;
}
}
});
waitForMenuToHide(cvc);
// TODO(rlanday): Verify that the suggestion marker was removed once we have a way to do
// this in a content test (crbug.com/767507).
}
@Test @Test
@LargeTest @LargeTest
public void menuDismissal() throws InterruptedException, Throwable, TimeoutException { public void menuDismissal() throws InterruptedException, Throwable, TimeoutException {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment