| 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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 } | 117 } |
| 118 | 118 |
| 119 ImeAdapterAndroid::ImeAdapterAndroid(RenderWidgetHostViewAndroid* rwhva) | 119 ImeAdapterAndroid::ImeAdapterAndroid(RenderWidgetHostViewAndroid* rwhva) |
| 120 : rwhva_(rwhva) { | 120 : rwhva_(rwhva) { |
| 121 } | 121 } |
| 122 | 122 |
| 123 ImeAdapterAndroid::~ImeAdapterAndroid() { | 123 ImeAdapterAndroid::~ImeAdapterAndroid() { |
| 124 JNIEnv* env = AttachCurrentThread(); | 124 JNIEnv* env = AttachCurrentThread(); |
| 125 base::android::ScopedJavaLocalRef<jobject> obj = java_ime_adapter_.get(env); | 125 base::android::ScopedJavaLocalRef<jobject> obj = java_ime_adapter_.get(env); |
| 126 if (!obj.is_null()) | 126 if (!obj.is_null()) |
| 127 Java_ImeAdapter_detach(env, obj.obj()); | 127 Java_ImeAdapter_detach(env, obj); |
| 128 } | 128 } |
| 129 | 129 |
| 130 bool ImeAdapterAndroid::SendSyntheticKeyEvent(JNIEnv*, | 130 bool ImeAdapterAndroid::SendSyntheticKeyEvent(JNIEnv*, |
| 131 const JavaParamRef<jobject>&, | 131 const JavaParamRef<jobject>&, |
| 132 int type, | 132 int type, |
| 133 long time_ms, | 133 long time_ms, |
| 134 int key_code, | 134 int key_code, |
| 135 int modifiers, | 135 int modifiers, |
| 136 int text) { | 136 int text) { |
| 137 NativeWebKeyboardEvent event(static_cast<blink::WebInputEvent::Type>(type), | 137 NativeWebKeyboardEvent event(static_cast<blink::WebInputEvent::Type>(type), |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 void ImeAdapterAndroid::AttachImeAdapter( | 235 void ImeAdapterAndroid::AttachImeAdapter( |
| 236 JNIEnv* env, | 236 JNIEnv* env, |
| 237 const JavaParamRef<jobject>& java_object) { | 237 const JavaParamRef<jobject>& java_object) { |
| 238 java_ime_adapter_ = JavaObjectWeakGlobalRef(env, java_object); | 238 java_ime_adapter_ = JavaObjectWeakGlobalRef(env, java_object); |
| 239 } | 239 } |
| 240 | 240 |
| 241 void ImeAdapterAndroid::CancelComposition() { | 241 void ImeAdapterAndroid::CancelComposition() { |
| 242 base::android::ScopedJavaLocalRef<jobject> obj = | 242 base::android::ScopedJavaLocalRef<jobject> obj = |
| 243 java_ime_adapter_.get(AttachCurrentThread()); | 243 java_ime_adapter_.get(AttachCurrentThread()); |
| 244 if (!obj.is_null()) | 244 if (!obj.is_null()) |
| 245 Java_ImeAdapter_cancelComposition(AttachCurrentThread(), obj.obj()); | 245 Java_ImeAdapter_cancelComposition(AttachCurrentThread(), obj); |
| 246 } | 246 } |
| 247 | 247 |
| 248 void ImeAdapterAndroid::FocusedNodeChanged(bool is_editable_node) { | 248 void ImeAdapterAndroid::FocusedNodeChanged(bool is_editable_node) { |
| 249 base::android::ScopedJavaLocalRef<jobject> obj = | 249 base::android::ScopedJavaLocalRef<jobject> obj = |
| 250 java_ime_adapter_.get(AttachCurrentThread()); | 250 java_ime_adapter_.get(AttachCurrentThread()); |
| 251 if (!obj.is_null()) { | 251 if (!obj.is_null()) { |
| 252 Java_ImeAdapter_focusedNodeChanged(AttachCurrentThread(), | 252 Java_ImeAdapter_focusedNodeChanged(AttachCurrentThread(), obj, |
| 253 obj.obj(), | |
| 254 is_editable_node); | 253 is_editable_node); |
| 255 } | 254 } |
| 256 } | 255 } |
| 257 | 256 |
| 258 void ImeAdapterAndroid::SetEditableSelectionOffsets( | 257 void ImeAdapterAndroid::SetEditableSelectionOffsets( |
| 259 JNIEnv*, | 258 JNIEnv*, |
| 260 const JavaParamRef<jobject>&, | 259 const JavaParamRef<jobject>&, |
| 261 int start, | 260 int start, |
| 262 int end) { | 261 int end) { |
| 263 RenderFrameHost* rfh = GetFocusedFrame(); | 262 RenderFrameHost* rfh = GetFocusedFrame(); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 279 std::unique_ptr<float[]> coordinates_array(new float[coordinates_array_size]); | 278 std::unique_ptr<float[]> coordinates_array(new float[coordinates_array_size]); |
| 280 for (size_t i = 0; i < character_bounds.size(); ++i) { | 279 for (size_t i = 0; i < character_bounds.size(); ++i) { |
| 281 const gfx::RectF& rect = character_bounds[i]; | 280 const gfx::RectF& rect = character_bounds[i]; |
| 282 const size_t coordinates_array_index = i * 4; | 281 const size_t coordinates_array_index = i * 4; |
| 283 coordinates_array[coordinates_array_index + 0] = rect.x(); | 282 coordinates_array[coordinates_array_index + 0] = rect.x(); |
| 284 coordinates_array[coordinates_array_index + 1] = rect.y(); | 283 coordinates_array[coordinates_array_index + 1] = rect.y(); |
| 285 coordinates_array[coordinates_array_index + 2] = rect.right(); | 284 coordinates_array[coordinates_array_index + 2] = rect.right(); |
| 286 coordinates_array[coordinates_array_index + 3] = rect.bottom(); | 285 coordinates_array[coordinates_array_index + 3] = rect.bottom(); |
| 287 } | 286 } |
| 288 Java_ImeAdapter_setCharacterBounds( | 287 Java_ImeAdapter_setCharacterBounds( |
| 289 env, | 288 env, obj, base::android::ToJavaFloatArray(env, coordinates_array.get(), |
| 290 obj.obj(), | 289 coordinates_array_size)); |
| 291 base::android::ToJavaFloatArray(env, | |
| 292 coordinates_array.get(), | |
| 293 coordinates_array_size).obj()); | |
| 294 } | 290 } |
| 295 | 291 |
| 296 void ImeAdapterAndroid::SetComposingRegion(JNIEnv*, | 292 void ImeAdapterAndroid::SetComposingRegion(JNIEnv*, |
| 297 const JavaParamRef<jobject>&, | 293 const JavaParamRef<jobject>&, |
| 298 int start, | 294 int start, |
| 299 int end) { | 295 int end) { |
| 300 RenderFrameHost* rfh = GetFocusedFrame(); | 296 RenderFrameHost* rfh = GetFocusedFrame(); |
| 301 if (!rfh) | 297 if (!rfh) |
| 302 return; | 298 return; |
| 303 | 299 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 378 } | 374 } |
| 379 | 375 |
| 380 WebContents* ImeAdapterAndroid::GetWebContents() { | 376 WebContents* ImeAdapterAndroid::GetWebContents() { |
| 381 RenderWidgetHostImpl* rwh = GetRenderWidgetHostImpl(); | 377 RenderWidgetHostImpl* rwh = GetRenderWidgetHostImpl(); |
| 382 if (!rwh) | 378 if (!rwh) |
| 383 return nullptr; | 379 return nullptr; |
| 384 return WebContents::FromRenderViewHost(RenderViewHost::From(rwh)); | 380 return WebContents::FromRenderViewHost(RenderViewHost::From(rwh)); |
| 385 } | 381 } |
| 386 | 382 |
| 387 } // namespace content | 383 } // namespace content |
| OLD | NEW |