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

Side by Side Diff: content/browser/renderer_host/ime_adapter_android.cc

Issue 1999423002: tyrbot test for commitText (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: SetHasCompositionTextToTrue Created 4 years, 3 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #include "content/browser/renderer_host/ime_adapter_android.h" 5 #include "content/browser/renderer_host/ime_adapter_android.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <android/input.h> 8 #include <android/input.h>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 env, original_key_event, type, modifiers, 136 env, original_key_event, type, modifiers,
137 time_ms / 1000.0, key_code, scan_code, is_system_key, unicode_char); 137 time_ms / 1000.0, key_code, scan_code, is_system_key, unicode_char);
138 rwhva_->SendKeyEvent(event); 138 rwhva_->SendKeyEvent(event);
139 return true; 139 return true;
140 } 140 }
141 141
142 void ImeAdapterAndroid::SetComposingText(JNIEnv* env, 142 void ImeAdapterAndroid::SetComposingText(JNIEnv* env,
143 const JavaParamRef<jobject>& obj, 143 const JavaParamRef<jobject>& obj,
144 const JavaParamRef<jobject>& text, 144 const JavaParamRef<jobject>& text,
145 const JavaParamRef<jstring>& text_str, 145 const JavaParamRef<jstring>& text_str,
146 int new_cursor_pos) { 146 int relative_cursor_pos) {
147 RenderWidgetHostImpl* rwhi = GetRenderWidgetHostImpl(); 147 RenderWidgetHostImpl* rwhi = GetRenderWidgetHostImpl();
148 if (!rwhi) 148 if (!rwhi)
149 return; 149 return;
150 150
151 base::string16 text16 = ConvertJavaStringToUTF16(env, text_str); 151 base::string16 text16 = ConvertJavaStringToUTF16(env, text_str);
152 152
153 std::vector<blink::WebCompositionUnderline> underlines; 153 std::vector<blink::WebCompositionUnderline> underlines;
154 // Iterate over spans in |text|, dispatch those that we care about (e.g., 154 // Iterate over spans in |text|, dispatch those that we care about (e.g.,
155 // BackgroundColorSpan) to a matching callback (e.g., 155 // BackgroundColorSpan) to a matching callback (e.g.,
156 // AppendBackgroundColorSpan()), and populate |underlines|. 156 // AppendBackgroundColorSpan()), and populate |underlines|.
157 Java_ImeAdapter_populateUnderlinesFromSpans( 157 Java_ImeAdapter_populateUnderlinesFromSpans(
158 env, obj, text, reinterpret_cast<jlong>(&underlines)); 158 env, obj, text, reinterpret_cast<jlong>(&underlines));
159 159
160 // Default to plain underline if we didn't find any span that we care about. 160 // Default to plain underline if we didn't find any span that we care about.
161 if (underlines.empty()) { 161 if (underlines.empty()) {
162 underlines.push_back(blink::WebCompositionUnderline( 162 underlines.push_back(blink::WebCompositionUnderline(
163 0, text16.length(), SK_ColorBLACK, false, SK_ColorTRANSPARENT)); 163 0, text16.length(), SK_ColorBLACK, false, SK_ColorTRANSPARENT));
164 } 164 }
165 // Sort spans by |.startOffset|. 165 // Sort spans by |.startOffset|.
166 std::sort(underlines.begin(), underlines.end()); 166 std::sort(underlines.begin(), underlines.end());
167 167
168 // new_cursor_position is as described in the Android API for 168 // relative_cursor_pos is as described in the Android API for
169 // InputConnection#setComposingText, whereas the parameters for 169 // InputConnection#setComposingText, whereas the parameters for
170 // ImeSetComposition are relative to the start of the composition. 170 // ImeSetComposition are relative to the start of the composition.
171 if (new_cursor_pos > 0) 171 if (relative_cursor_pos > 0)
172 new_cursor_pos = text16.length() + new_cursor_pos - 1; 172 relative_cursor_pos = text16.length() + relative_cursor_pos - 1;
173 173
174 rwhi->ImeSetComposition(text16, underlines, gfx::Range::InvalidRange(), 174 rwhi->ImeSetComposition(text16, underlines, gfx::Range::InvalidRange(),
175 new_cursor_pos, new_cursor_pos); 175 relative_cursor_pos, relative_cursor_pos);
176 } 176 }
177 177
178 void ImeAdapterAndroid::CommitText(JNIEnv* env, 178 void ImeAdapterAndroid::CommitText(JNIEnv* env,
179 const JavaParamRef<jobject>&, 179 const JavaParamRef<jobject>&,
180 const JavaParamRef<jstring>& text_str) { 180 const JavaParamRef<jstring>& text_str,
181 int relative_cursor_pos) {
181 RenderWidgetHostImpl* rwhi = GetRenderWidgetHostImpl(); 182 RenderWidgetHostImpl* rwhi = GetRenderWidgetHostImpl();
182 if (!rwhi) 183 if (!rwhi)
183 return; 184 return;
184 185
185 base::string16 text16 = ConvertJavaStringToUTF16(env, text_str); 186 base::string16 text16 = ConvertJavaStringToUTF16(env, text_str);
186 rwhi->ImeConfirmComposition(text16, gfx::Range::InvalidRange(), false); 187
188 // relative_cursor_pos is as described in the Android API for
189 // InputConnection#commitText, whereas the parameters for
190 // ImeConfirmComposition are relative to the end of the composition.
191 if (relative_cursor_pos > 0)
192 relative_cursor_pos--;
193 else
194 relative_cursor_pos -= text16.length();
195
196 rwhi->ImeCommitText(text16, gfx::Range::InvalidRange(), relative_cursor_pos);
187 } 197 }
188 198
189 void ImeAdapterAndroid::FinishComposingText(JNIEnv* env, 199 void ImeAdapterAndroid::FinishComposingText(JNIEnv* env,
190 const JavaParamRef<jobject>&) { 200 const JavaParamRef<jobject>&) {
191 RenderWidgetHostImpl* rwhi = GetRenderWidgetHostImpl(); 201 RenderWidgetHostImpl* rwhi = GetRenderWidgetHostImpl();
192 if (!rwhi) 202 if (!rwhi)
193 return; 203 return;
194 204
195 rwhi->ImeConfirmComposition(base::string16(), gfx::Range::InvalidRange(), 205 rwhi->ImeFinishComposingText(true);
196 true);
197 } 206 }
198 207
199 void ImeAdapterAndroid::AttachImeAdapter( 208 void ImeAdapterAndroid::AttachImeAdapter(
200 JNIEnv* env, 209 JNIEnv* env,
201 const JavaParamRef<jobject>& java_object) { 210 const JavaParamRef<jobject>& java_object) {
202 java_ime_adapter_ = JavaObjectWeakGlobalRef(env, java_object); 211 java_ime_adapter_ = JavaObjectWeakGlobalRef(env, java_object);
203 } 212 }
204 213
205 void ImeAdapterAndroid::CancelComposition() { 214 void ImeAdapterAndroid::CancelComposition() {
206 base::android::ScopedJavaLocalRef<jobject> obj = 215 base::android::ScopedJavaLocalRef<jobject> obj =
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 } 347 }
339 348
340 WebContents* ImeAdapterAndroid::GetWebContents() { 349 WebContents* ImeAdapterAndroid::GetWebContents() {
341 RenderWidgetHostImpl* rwh = GetRenderWidgetHostImpl(); 350 RenderWidgetHostImpl* rwh = GetRenderWidgetHostImpl();
342 if (!rwh) 351 if (!rwh)
343 return nullptr; 352 return nullptr;
344 return WebContents::FromRenderViewHost(RenderViewHost::From(rwh)); 353 return WebContents::FromRenderViewHost(RenderViewHost::From(rwh));
345 } 354 }
346 355
347 } // namespace content 356 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/ime_adapter_android.h ('k') | content/browser/renderer_host/render_widget_host_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698