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

Side by Side Diff: components/spellcheck/browser/android/java/src/org/chromium/components/spellcheck/SpellCheckerSessionBridge.java

Issue 2849933002: Store suggestions from Android spellchecker in spelling markers (Closed)
Patch Set: Created 3 years, 7 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 unified diff | Download patch
« no previous file with comments | « no previous file | components/spellcheck/browser/spellchecker_session_bridge_android.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.components.spellcheck; 5 package org.chromium.components.spellcheck;
6 6
7 import android.content.Context; 7 import android.content.Context;
8 import android.os.SystemClock; 8 import android.os.SystemClock;
9 import android.view.textservice.SentenceSuggestionsInfo; 9 import android.view.textservice.SentenceSuggestionsInfo;
10 import android.view.textservice.SpellCheckerSession; 10 import android.view.textservice.SpellCheckerSession;
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 @Override 99 @Override
100 public void onGetSentenceSuggestions(SentenceSuggestionsInfo[] results) { 100 public void onGetSentenceSuggestions(SentenceSuggestionsInfo[] results) {
101 mStopMs = SystemClock.elapsedRealtime(); 101 mStopMs = SystemClock.elapsedRealtime();
102 102
103 if (mNativeSpellCheckerSessionBridge == 0) { 103 if (mNativeSpellCheckerSessionBridge == 0) {
104 return; 104 return;
105 } 105 }
106 106
107 ArrayList<Integer> offsets = new ArrayList<Integer>(); 107 ArrayList<Integer> offsets = new ArrayList<Integer>();
108 ArrayList<Integer> lengths = new ArrayList<Integer>(); 108 ArrayList<Integer> lengths = new ArrayList<Integer>();
109 ArrayList<String[]> suggestions = new ArrayList<String[]>();
109 110
110 for (SentenceSuggestionsInfo result : results) { 111 for (SentenceSuggestionsInfo result : results) {
111 if (result == null) { 112 if (result == null) {
112 // In some cases null can be returned by the selected spellcheck ing service, 113 // In some cases null can be returned by the selected spellcheck ing service,
113 // see crbug.com/651458. In this case skip to next result to avo id a 114 // see crbug.com/651458. In this case skip to next result to avo id a
114 // NullPointerException later on. 115 // NullPointerException later on.
115 continue; 116 continue;
116 } 117 }
117 for (int i = 0; i < result.getSuggestionsCount(); i++) { 118 for (int i = 0; i < result.getSuggestionsCount(); i++) {
118 // If a word looks like a typo, record its offset and length. 119 // If a word looks like a typo, record its offset and length.
119 if ((result.getSuggestionsInfoAt(i).getSuggestionsAttributes() 120 if ((result.getSuggestionsInfoAt(i).getSuggestionsAttributes()
120 & SuggestionsInfo.RESULT_ATTR_LOOKS_LIKE_TYPO) 121 & SuggestionsInfo.RESULT_ATTR_LOOKS_LIKE_TYPO)
121 == SuggestionsInfo.RESULT_ATTR_LOOKS_LIKE_TYPO) { 122 == SuggestionsInfo.RESULT_ATTR_LOOKS_LIKE_TYPO) {
122 offsets.add(result.getOffsetAt(i)); 123 offsets.add(result.getOffsetAt(i));
123 lengths.add(result.getLengthAt(i)); 124 lengths.add(result.getLengthAt(i));
125 SuggestionsInfo info = result.getSuggestionsInfoAt(i);
126 ArrayList<String> suggestions_for_word = new ArrayList<Strin g>();
127 for (int j = 0; j < info.getSuggestionsCount(); ++j) {
128 suggestions_for_word.add(info.getSuggestionAt(j));
129 }
130 suggestions.add(
131 suggestions_for_word.toArray(new String[suggestions_ for_word.size()]));
124 } 132 }
125 } 133 }
126 } 134 }
127 nativeProcessSpellCheckResults(mNativeSpellCheckerSessionBridge, 135 nativeProcessSpellCheckResults(mNativeSpellCheckerSessionBridge,
128 convertListToArray(offsets), convertListToArray(lengths)); 136 convertListToArray(offsets), convertListToArray(lengths),
137 suggestions.toArray(new String[suggestions.size()][]));
129 138
130 RecordHistogram.recordTimesHistogram("SpellCheck.Android.Latency", 139 RecordHistogram.recordTimesHistogram("SpellCheck.Android.Latency",
131 mStopMs - mStartMs, TimeUnit.MILLISECONDS); 140 mStopMs - mStartMs, TimeUnit.MILLISECONDS);
132 } 141 }
133 142
134 /** 143 /**
135 * Helper method to convert an ArrayList of Integer objects into an array of primitive ints 144 * Helper method to convert an ArrayList of Integer objects into an array of primitive ints
136 * for easier JNI handling of these objects on the native side. 145 * for easier JNI handling of these objects on the native side.
137 * @param list List to be converted to an array. 146 * @param list List to be converted to an array.
138 */ 147 */
139 private int[] convertListToArray(ArrayList<Integer> list) { 148 private int[] convertListToArray(ArrayList<Integer> list) {
140 int[] array = new int[list.size()]; 149 int[] array = new int[list.size()];
141 for (int index = 0; index < array.length; index++) { 150 for (int index = 0; index < array.length; index++) {
142 array[index] = list.get(index).intValue(); 151 array[index] = list.get(index).intValue();
143 } 152 }
144 return array; 153 return array;
145 } 154 }
146 155
147 @Override 156 @Override
148 public void onGetSuggestions(SuggestionsInfo[] results) {} 157 public void onGetSuggestions(SuggestionsInfo[] results) {}
149 158
150 private native void nativeProcessSpellCheckResults( 159 private native void nativeProcessSpellCheckResults(long nativeSpellCheckerSe ssionBridge,
151 long nativeSpellCheckerSessionBridge, int[] offsets, int[] lengths); 160 int[] offsets, int[] lengths, String[][] suggestions);
152 } 161 }
OLDNEW
« no previous file with comments | « no previous file | components/spellcheck/browser/spellchecker_session_bridge_android.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698