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 |
11 #include "base/android/jni_android.h" | 11 #include "base/android/jni_android.h" |
12 #include "base/android/jni_string.h" | 12 #include "base/android/jni_string.h" |
13 #include "base/android/scoped_java_ref.h" | 13 #include "base/android/scoped_java_ref.h" |
14 #include "base/memory/scoped_ptr.h" | |
14 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
15 #include "base/time/time.h" | 16 #include "base/time/time.h" |
16 #include "content/browser/frame_host/frame_tree.h" | 17 #include "content/browser/frame_host/frame_tree.h" |
17 #include "content/browser/frame_host/frame_tree_node.h" | 18 #include "content/browser/frame_host/frame_tree_node.h" |
18 #include "content/browser/frame_host/render_frame_host_impl.h" | 19 #include "content/browser/frame_host/render_frame_host_impl.h" |
19 #include "content/browser/renderer_host/render_view_host_delegate.h" | 20 #include "content/browser/renderer_host/render_view_host_delegate.h" |
20 #include "content/browser/renderer_host/render_view_host_impl.h" | 21 #include "content/browser/renderer_host/render_view_host_impl.h" |
21 #include "content/browser/renderer_host/render_widget_host_impl.h" | 22 #include "content/browser/renderer_host/render_widget_host_impl.h" |
22 #include "content/browser/renderer_host/render_widget_host_view_android.h" | 23 #include "content/browser/renderer_host/render_widget_host_view_android.h" |
23 #include "content/common/frame_messages.h" | 24 #include "content/common/frame_messages.h" |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
260 void ImeAdapterAndroid::FocusedNodeChanged(bool is_editable_node) { | 261 void ImeAdapterAndroid::FocusedNodeChanged(bool is_editable_node) { |
261 base::android::ScopedJavaLocalRef<jobject> obj = | 262 base::android::ScopedJavaLocalRef<jobject> obj = |
262 java_ime_adapter_.get(AttachCurrentThread()); | 263 java_ime_adapter_.get(AttachCurrentThread()); |
263 if (!obj.is_null()) { | 264 if (!obj.is_null()) { |
264 Java_ImeAdapter_focusedNodeChanged(AttachCurrentThread(), | 265 Java_ImeAdapter_focusedNodeChanged(AttachCurrentThread(), |
265 obj.obj(), | 266 obj.obj(), |
266 is_editable_node); | 267 is_editable_node); |
267 } | 268 } |
268 } | 269 } |
269 | 270 |
271 void ImeAdapterAndroid::SetCharacterBounds( | |
272 const std::vector<gfx::Rect>& character_bounds) { | |
273 JNIEnv* env = AttachCurrentThread(); | |
274 base::android::ScopedJavaLocalRef<jobject> obj = java_ime_adapter_.get(env); | |
275 if (obj.is_null()) | |
276 return; | |
277 | |
278 const size_t coordinates_array_size = character_bounds.size() * 4; | |
279 base::android::ScopedJavaLocalRef<jfloatArray> coordinates_dest_array( | |
280 env, env->NewFloatArray(coordinates_array_size)); | |
281 if (coordinates_dest_array.is_null()) | |
aurimas (slooooooooow)
2014/10/28 05:49:08
Why would this be null? Is this for cases where yo
yukawa
2014/10/28 06:15:15
I'm not an expert, but I presume that this could b
| |
282 return; | |
283 | |
284 scoped_ptr<jfloat[]> coordinates_array(new jfloat[coordinates_array_size]); | |
285 for (size_t i = 0; i < character_bounds.size(); ++i) { | |
286 const gfx::Rect& rect = character_bounds[i]; | |
287 const size_t coordinates_array_index = i * 4; | |
288 coordinates_array[coordinates_array_index + 0] = rect.x(); | |
289 coordinates_array[coordinates_array_index + 1] = rect.y(); | |
290 coordinates_array[coordinates_array_index + 2] = rect.right(); | |
291 coordinates_array[coordinates_array_index + 3] = rect.bottom(); | |
292 } | |
293 env->SetFloatArrayRegion(coordinates_dest_array.obj(), 0, | |
aurimas (slooooooooow)
2014/10/28 05:49:08
You are calling to JNIEnv directly, should we be d
yukawa
2014/10/28 06:15:15
Added base::android::CheckException by following s
| |
294 coordinates_array_size, coordinates_array.get()); | |
295 Java_ImeAdapter_setCharacterBounds(env, obj.obj(), | |
296 coordinates_dest_array.obj()); | |
297 } | |
298 | |
270 void ImeAdapterAndroid::SetEditableSelectionOffsets(JNIEnv*, jobject, | 299 void ImeAdapterAndroid::SetEditableSelectionOffsets(JNIEnv*, jobject, |
271 int start, int end) { | 300 int start, int end) { |
272 RenderFrameHost* rfh = GetFocusedFrame(); | 301 RenderFrameHost* rfh = GetFocusedFrame(); |
273 if (!rfh) | 302 if (!rfh) |
274 return; | 303 return; |
275 | 304 |
276 rfh->Send(new FrameMsg_SetEditableSelectionOffsets(rfh->GetRoutingID(), | 305 rfh->Send(new FrameMsg_SetEditableSelectionOffsets(rfh->GetRoutingID(), |
277 start, end)); | 306 start, end)); |
278 } | 307 } |
279 | 308 |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
361 WebContents* ImeAdapterAndroid::GetWebContents() { | 390 WebContents* ImeAdapterAndroid::GetWebContents() { |
362 RenderWidgetHostImpl* rwh = GetRenderWidgetHostImpl(); | 391 RenderWidgetHostImpl* rwh = GetRenderWidgetHostImpl(); |
363 if (!rwh) | 392 if (!rwh) |
364 return NULL; | 393 return NULL; |
365 if (!rwh->IsRenderView()) | 394 if (!rwh->IsRenderView()) |
366 return NULL; | 395 return NULL; |
367 return WebContents::FromRenderViewHost(RenderViewHost::From(rwh)); | 396 return WebContents::FromRenderViewHost(RenderViewHost::From(rwh)); |
368 } | 397 } |
369 | 398 |
370 } // namespace content | 399 } // namespace content |
OLD | NEW |