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()) | |
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(); | |
aurimas (slooooooooow)
2014/10/28 20:45:09
Do we have to do something special here for RTL?
yukawa
2014/10/29 00:50:18
Good point. Basically we don't need to do anythin
| |
291 coordinates_array[coordinates_array_index + 3] = rect.bottom(); | |
292 } | |
293 // TODO(yukawa): Consider to move this to base/android/jni_array.h | |
294 env->SetFloatArrayRegion(coordinates_dest_array.obj(), 0, | |
295 coordinates_array_size, coordinates_array.get()); | |
296 base::android::CheckException(env); | |
297 Java_ImeAdapter_setCharacterBounds(env, obj.obj(), | |
298 coordinates_dest_array.obj()); | |
299 } | |
300 | |
270 void ImeAdapterAndroid::SetEditableSelectionOffsets(JNIEnv*, jobject, | 301 void ImeAdapterAndroid::SetEditableSelectionOffsets(JNIEnv*, jobject, |
271 int start, int end) { | 302 int start, int end) { |
272 RenderFrameHost* rfh = GetFocusedFrame(); | 303 RenderFrameHost* rfh = GetFocusedFrame(); |
273 if (!rfh) | 304 if (!rfh) |
274 return; | 305 return; |
275 | 306 |
276 rfh->Send(new FrameMsg_SetEditableSelectionOffsets(rfh->GetRoutingID(), | 307 rfh->Send(new FrameMsg_SetEditableSelectionOffsets(rfh->GetRoutingID(), |
277 start, end)); | 308 start, end)); |
278 } | 309 } |
279 | 310 |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
361 WebContents* ImeAdapterAndroid::GetWebContents() { | 392 WebContents* ImeAdapterAndroid::GetWebContents() { |
362 RenderWidgetHostImpl* rwh = GetRenderWidgetHostImpl(); | 393 RenderWidgetHostImpl* rwh = GetRenderWidgetHostImpl(); |
363 if (!rwh) | 394 if (!rwh) |
364 return NULL; | 395 return NULL; |
365 if (!rwh->IsRenderView()) | 396 if (!rwh->IsRenderView()) |
366 return NULL; | 397 return NULL; |
367 return WebContents::FromRenderViewHost(RenderViewHost::From(rwh)); | 398 return WebContents::FromRenderViewHost(RenderViewHost::From(rwh)); |
368 } | 399 } |
369 | 400 |
370 } // namespace content | 401 } // namespace content |
OLD | NEW |