| 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 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 | 211 |
| 212 void ImeAdapterAndroid::FocusedNodeChanged(bool is_editable_node) { | 212 void ImeAdapterAndroid::FocusedNodeChanged(bool is_editable_node) { |
| 213 base::android::ScopedJavaLocalRef<jobject> obj = | 213 base::android::ScopedJavaLocalRef<jobject> obj = |
| 214 java_ime_adapter_.get(AttachCurrentThread()); | 214 java_ime_adapter_.get(AttachCurrentThread()); |
| 215 if (!obj.is_null()) { | 215 if (!obj.is_null()) { |
| 216 Java_ImeAdapter_focusedNodeChanged(AttachCurrentThread(), obj, | 216 Java_ImeAdapter_focusedNodeChanged(AttachCurrentThread(), obj, |
| 217 is_editable_node); | 217 is_editable_node); |
| 218 } | 218 } |
| 219 } | 219 } |
| 220 | 220 |
| 221 void ImeAdapterAndroid::BeginBatchEdit(JNIEnv*, const JavaParamRef<jobject>&) { |
| 222 RenderWidgetHostImpl* rwhi = GetRenderWidgetHostImpl(); |
| 223 if (!rwhi) |
| 224 return; |
| 225 |
| 226 rwhi->BeginBatchEdit(); |
| 227 } |
| 228 |
| 229 void ImeAdapterAndroid::EndBatchEdit(JNIEnv*, const JavaParamRef<jobject>&) { |
| 230 RenderWidgetHostImpl* rwhi = GetRenderWidgetHostImpl(); |
| 231 if (!rwhi) |
| 232 return; |
| 233 |
| 234 rwhi->EndBatchEdit(); |
| 235 } |
| 236 |
| 221 void ImeAdapterAndroid::SetEditableSelectionOffsets( | 237 void ImeAdapterAndroid::SetEditableSelectionOffsets( |
| 222 JNIEnv*, | 238 JNIEnv*, |
| 223 const JavaParamRef<jobject>&, | 239 const JavaParamRef<jobject>&, |
| 224 int start, | 240 int start, |
| 225 int end) { | 241 int end) { |
| 226 RenderFrameHost* rfh = GetFocusedFrame(); | 242 RenderWidgetHostImpl* rwhi = GetRenderWidgetHostImpl(); |
| 227 if (!rfh) | 243 if (!rwhi) |
| 228 return; | 244 return; |
| 229 | 245 |
| 230 rfh->Send(new InputMsg_SetEditableSelectionOffsets(rfh->GetRoutingID(), start, | 246 rwhi->SendOrBatch(new InputMsg_ImeSetEditableSelectionOffsets( |
| 231 end)); | 247 rwhi->GetRoutingID(), start, end)); |
| 232 } | 248 } |
| 233 | 249 |
| 234 void ImeAdapterAndroid::SetCharacterBounds( | 250 void ImeAdapterAndroid::SetCharacterBounds( |
| 235 const std::vector<gfx::RectF>& character_bounds) { | 251 const std::vector<gfx::RectF>& character_bounds) { |
| 236 JNIEnv* env = AttachCurrentThread(); | 252 JNIEnv* env = AttachCurrentThread(); |
| 237 base::android::ScopedJavaLocalRef<jobject> obj = java_ime_adapter_.get(env); | 253 base::android::ScopedJavaLocalRef<jobject> obj = java_ime_adapter_.get(env); |
| 238 if (obj.is_null()) | 254 if (obj.is_null()) |
| 239 return; | 255 return; |
| 240 | 256 |
| 241 const size_t coordinates_array_size = character_bounds.size() * 4; | 257 const size_t coordinates_array_size = character_bounds.size() * 4; |
| 242 std::unique_ptr<float[]> coordinates_array(new float[coordinates_array_size]); | 258 std::unique_ptr<float[]> coordinates_array(new float[coordinates_array_size]); |
| 243 for (size_t i = 0; i < character_bounds.size(); ++i) { | 259 for (size_t i = 0; i < character_bounds.size(); ++i) { |
| 244 const gfx::RectF& rect = character_bounds[i]; | 260 const gfx::RectF& rect = character_bounds[i]; |
| 245 const size_t coordinates_array_index = i * 4; | 261 const size_t coordinates_array_index = i * 4; |
| 246 coordinates_array[coordinates_array_index + 0] = rect.x(); | 262 coordinates_array[coordinates_array_index + 0] = rect.x(); |
| 247 coordinates_array[coordinates_array_index + 1] = rect.y(); | 263 coordinates_array[coordinates_array_index + 1] = rect.y(); |
| 248 coordinates_array[coordinates_array_index + 2] = rect.right(); | 264 coordinates_array[coordinates_array_index + 2] = rect.right(); |
| 249 coordinates_array[coordinates_array_index + 3] = rect.bottom(); | 265 coordinates_array[coordinates_array_index + 3] = rect.bottom(); |
| 250 } | 266 } |
| 251 Java_ImeAdapter_setCharacterBounds( | 267 Java_ImeAdapter_setCharacterBounds( |
| 252 env, obj, base::android::ToJavaFloatArray(env, coordinates_array.get(), | 268 env, obj, base::android::ToJavaFloatArray(env, coordinates_array.get(), |
| 253 coordinates_array_size)); | 269 coordinates_array_size)); |
| 254 } | 270 } |
| 255 | 271 |
| 256 void ImeAdapterAndroid::SetComposingRegion(JNIEnv*, | 272 void ImeAdapterAndroid::SetComposingRegion(JNIEnv*, |
| 257 const JavaParamRef<jobject>&, | 273 const JavaParamRef<jobject>&, |
| 258 int start, | 274 int start, |
| 259 int end) { | 275 int end) { |
| 260 RenderFrameHost* rfh = GetFocusedFrame(); | 276 RenderWidgetHostImpl* rwhi = GetRenderWidgetHostImpl(); |
| 261 if (!rfh) | 277 if (!rwhi) |
| 262 return; | 278 return; |
| 263 | 279 |
| 264 std::vector<blink::WebCompositionUnderline> underlines; | 280 std::vector<blink::WebCompositionUnderline> underlines; |
| 265 underlines.push_back(blink::WebCompositionUnderline( | 281 underlines.push_back(blink::WebCompositionUnderline( |
| 266 0, end - start, SK_ColorBLACK, false, SK_ColorTRANSPARENT)); | 282 0, end - start, SK_ColorBLACK, false, SK_ColorTRANSPARENT)); |
| 267 | 283 |
| 268 rfh->Send(new InputMsg_SetCompositionFromExistingText( | 284 rwhi->SendOrBatch(new InputMsg_ImeSetCompositionFromExistingText( |
| 269 rfh->GetRoutingID(), start, end, underlines)); | 285 rwhi->GetRoutingID(), start, end, underlines)); |
| 270 } | 286 } |
| 271 | 287 |
| 272 void ImeAdapterAndroid::DeleteSurroundingText(JNIEnv*, | 288 void ImeAdapterAndroid::DeleteSurroundingText(JNIEnv*, |
| 273 const JavaParamRef<jobject>&, | 289 const JavaParamRef<jobject>&, |
| 274 int before, | 290 int before, |
| 275 int after) { | 291 int after) { |
| 276 RenderFrameHostImpl* rfh = | 292 RenderWidgetHostImpl* rwhi = GetRenderWidgetHostImpl(); |
| 277 static_cast<RenderFrameHostImpl*>(GetFocusedFrame()); | 293 if (!rwhi) |
| 278 if (rfh) | 294 return; |
| 279 rfh->ExtendSelectionAndDelete(before, after); | 295 rwhi->ExtendSelectionAndDelete(before, after); |
| 280 } | 296 } |
| 281 | 297 |
| 282 bool ImeAdapterAndroid::RequestTextInputStateUpdate( | 298 bool ImeAdapterAndroid::RequestTextInputStateUpdate( |
| 283 JNIEnv* env, | 299 JNIEnv* env, |
| 284 const JavaParamRef<jobject>&) { | 300 const JavaParamRef<jobject>&) { |
| 285 RenderWidgetHostImpl* rwhi = GetRenderWidgetHostImpl(); | 301 RenderWidgetHostImpl* rwhi = GetRenderWidgetHostImpl(); |
| 286 if (!rwhi) | 302 if (!rwhi) |
| 287 return false; | 303 return false; |
| 288 rwhi->Send(new InputMsg_RequestTextInputStateUpdate(rwhi->GetRoutingID())); | 304 rwhi->Send(new InputMsg_ImeRequestTextInputStateUpdate(rwhi->GetRoutingID())); |
| 289 return true; | 305 return true; |
| 290 } | 306 } |
| 291 | 307 |
| 292 void ImeAdapterAndroid::RequestCursorUpdate( | 308 void ImeAdapterAndroid::RequestCursorUpdate( |
| 293 JNIEnv* env, | 309 JNIEnv* env, |
| 294 const base::android::JavaParamRef<jobject>& obj, | 310 const base::android::JavaParamRef<jobject>& obj, |
| 295 bool immediate_request, | 311 bool immediate_request, |
| 296 bool monitor_request) { | 312 bool monitor_request) { |
| 297 RenderWidgetHostImpl* rwhi = GetRenderWidgetHostImpl(); | 313 RenderWidgetHostImpl* rwhi = GetRenderWidgetHostImpl(); |
| 298 if (!rwhi) | 314 if (!rwhi) |
| 299 return; | 315 return; |
| 300 rwhi->Send(new InputMsg_RequestCompositionUpdate( | 316 rwhi->Send(new InputMsg_ImeRequestCompositionUpdate( |
| 301 rwhi->GetRoutingID(), immediate_request, monitor_request)); | 317 rwhi->GetRoutingID(), immediate_request, monitor_request)); |
| 302 } | 318 } |
| 303 | 319 |
| 304 bool ImeAdapterAndroid::IsImeThreadEnabled( | 320 bool ImeAdapterAndroid::IsImeThreadEnabled( |
| 305 JNIEnv* env, | 321 JNIEnv* env, |
| 306 const base::android::JavaParamRef<jobject>&) { | 322 const base::android::JavaParamRef<jobject>&) { |
| 307 return base::FeatureList::IsEnabled(features::kImeThread); | 323 return base::FeatureList::IsEnabled(features::kImeThread); |
| 308 } | 324 } |
| 309 | 325 |
| 310 void ImeAdapterAndroid::ResetImeAdapter(JNIEnv* env, | 326 void ImeAdapterAndroid::ResetImeAdapter(JNIEnv* env, |
| (...skipping 27 matching lines...) Expand all Loading... |
| 338 } | 354 } |
| 339 | 355 |
| 340 WebContents* ImeAdapterAndroid::GetWebContents() { | 356 WebContents* ImeAdapterAndroid::GetWebContents() { |
| 341 RenderWidgetHostImpl* rwh = GetRenderWidgetHostImpl(); | 357 RenderWidgetHostImpl* rwh = GetRenderWidgetHostImpl(); |
| 342 if (!rwh) | 358 if (!rwh) |
| 343 return nullptr; | 359 return nullptr; |
| 344 return WebContents::FromRenderViewHost(RenderViewHost::From(rwh)); | 360 return WebContents::FromRenderViewHost(RenderViewHost::From(rwh)); |
| 345 } | 361 } |
| 346 | 362 |
| 347 } // namespace content | 363 } // namespace content |
| OLD | NEW |