OLD | NEW |
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 Loading... |
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 rwhi->ImeConfirmComposition(text16, gfx::Range::InvalidRange(), false, |
| 188 relative_cursor_pos); |
187 } | 189 } |
188 | 190 |
189 void ImeAdapterAndroid::FinishComposingText(JNIEnv* env, | 191 void ImeAdapterAndroid::FinishComposingText(JNIEnv* env, |
190 const JavaParamRef<jobject>&) { | 192 const JavaParamRef<jobject>&) { |
191 RenderWidgetHostImpl* rwhi = GetRenderWidgetHostImpl(); | 193 RenderWidgetHostImpl* rwhi = GetRenderWidgetHostImpl(); |
192 if (!rwhi) | 194 if (!rwhi) |
193 return; | 195 return; |
194 | 196 |
195 rwhi->ImeConfirmComposition(base::string16(), gfx::Range::InvalidRange(), | 197 rwhi->ImeConfirmComposition(base::string16(), gfx::Range::InvalidRange(), |
196 true); | 198 true); |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
338 } | 340 } |
339 | 341 |
340 WebContents* ImeAdapterAndroid::GetWebContents() { | 342 WebContents* ImeAdapterAndroid::GetWebContents() { |
341 RenderWidgetHostImpl* rwh = GetRenderWidgetHostImpl(); | 343 RenderWidgetHostImpl* rwh = GetRenderWidgetHostImpl(); |
342 if (!rwh) | 344 if (!rwh) |
343 return nullptr; | 345 return nullptr; |
344 return WebContents::FromRenderViewHost(RenderViewHost::From(rwh)); | 346 return WebContents::FromRenderViewHost(RenderViewHost::From(rwh)); |
345 } | 347 } |
346 | 348 |
347 } // namespace content | 349 } // namespace content |
OLD | NEW |