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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/spellchecker/SpellCheckerSessionBridge.java

Issue 1275813002: Implemented typo recognition in Chrome for Android. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@4_remove_mac_redundancies
Patch Set: #ifdef declaration in message filter to have mac compile Created 5 years, 4 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: chrome/android/java/src/org/chromium/chrome/browser/spellchecker/SpellCheckerSessionBridge.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/spellchecker/SpellCheckerSessionBridge.java b/chrome/android/java/src/org/chromium/chrome/browser/spellchecker/SpellCheckerSessionBridge.java
new file mode 100644
index 0000000000000000000000000000000000000000..68a5755f2a1c2dee28a788ad9860be55ff381af4
--- /dev/null
+++ b/chrome/android/java/src/org/chromium/chrome/browser/spellchecker/SpellCheckerSessionBridge.java
@@ -0,0 +1,94 @@
+// Copyright 2015 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.chrome.browser.spellchecker;
+
+import android.content.Context;
+import android.view.textservice.SentenceSuggestionsInfo;
+import android.view.textservice.SpellCheckerSession;
+import android.view.textservice.SpellCheckerSession.SpellCheckerSessionListener;
+import android.view.textservice.SuggestionsInfo;
+import android.view.textservice.TextInfo;
+import android.view.textservice.TextServicesManager;
+
+import org.chromium.base.ApplicationStatus;
+import org.chromium.base.annotations.CalledByNative;
+
+import java.util.ArrayList;
+
+/**
+* JNI interface for native SpellCheckerSessionBridge to use Android's spellchecker.
please use gerrit instead 2015/08/17 21:29:46 +1 space before *.
dylanking 2015/08/18 01:21:30 Done.
+*/
+public class SpellCheckerSessionBridge implements SpellCheckerSessionListener {
+ private final long mNativeSpellCheckerSessionBridge;
+ private SpellCheckerSession mSpellCheckerSession;
please use gerrit instead 2015/08/17 21:29:46 final
dylanking 2015/08/18 01:21:30 Done.
+
+ private SpellCheckerSessionBridge(long nativeSpellCheckerSessionBridge) {
please use gerrit instead 2015/08/17 21:29:46 Javadocs for all of the methods please?
+ mNativeSpellCheckerSessionBridge = nativeSpellCheckerSessionBridge;
+
+ Context context = ApplicationStatus.getApplicationContext();
+ final TextServicesManager textServicesManager =
+ (TextServicesManager) context.getSystemService(
+ Context.TEXT_SERVICES_MANAGER_SERVICE);
+
+ // This combination of parameters will cause the spellchecker to be based off of
+ // the language specified at "Settings > Language & input > Spell checker > Language".
+ // If that setting is set to "Use system language" and the system language is not on the
+ // list of supported spellcheck languages, this call will return null. This call will also
+ // return null if the user has turned spellchecking off at "Settings > Language & input >
+ // Spell checker".
+ mSpellCheckerSession = textServicesManager.newSpellCheckerSession(null, null, this, true);
+ }
+
+ @CalledByNative
+ private static SpellCheckerSessionBridge create(long nativeSpellCheckerSessionBridge) {
+ SpellCheckerSessionBridge bridge =
+ new SpellCheckerSessionBridge(nativeSpellCheckerSessionBridge);
+ if (bridge.mSpellCheckerSession == null) {
+ return null;
+ }
+ return bridge;
+ }
+
+ @CalledByNative
+ private void requestTextCheck(String text) {
+ mSpellCheckerSession.getSentenceSuggestions(new TextInfo[] {new TextInfo(text)}, 0);
+ }
+
+ @Override
+ public void onGetSentenceSuggestions(SentenceSuggestionsInfo[] results) {
+ ArrayList<Integer> offsets = new ArrayList<Integer>();
+ ArrayList<Integer> lengths = new ArrayList<Integer>();
+
+ for (SentenceSuggestionsInfo result : results) {
+ for (int i = 0; i < result.getSuggestionsCount(); i++) {
+ SuggestionsInfo currentSuggestion = result.getSuggestionsInfoAt(i);
please use gerrit instead 2015/08/17 21:29:46 Inline "currentSuggestion", unless that contradict
dylanking 2015/08/18 01:21:30 Done.
+ boolean isWordCorrect = (currentSuggestion.getSuggestionsAttributes()
please use gerrit instead 2015/08/17 21:29:46 Inline "isWordCorrect", unless that contradicts so
dylanking 2015/08/18 01:21:30 Inlined. == has higher precedence than bitwise AN
+ & SuggestionsInfo.RESULT_ATTR_LOOKS_LIKE_TYPO)
+ == 0;
+ if (!isWordCorrect) {
+ offsets.add(result.getOffsetAt(i));
+ lengths.add(result.getLengthAt(i));
+ }
+ }
+ }
+
+ nativeProcessSpellCheckResults(mNativeSpellCheckerSessionBridge,
+ convertListToArray(offsets), convertListToArray(lengths));
+ }
+
+ private int[] convertListToArray(ArrayList<Integer> list) {
+ int[] array = new int[list.size()];
+ for (int index = 0; index < array.length; index++) {
+ array[index] = list.get(index).intValue();
+ }
+ return array;
+ }
+
+ @Override
+ public void onGetSuggestions(SuggestionsInfo[] results) {}
+
+ private native void nativeProcessSpellCheckResults(
+ long nativeSpellCheckerSessionBridge, int[] offsets, int[] lengths);
+}

Powered by Google App Engine
This is Rietveld 408576698