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_array.h" |
12 #include "base/android/jni_string.h" | 13 #include "base/android/jni_string.h" |
13 #include "base/android/scoped_java_ref.h" | 14 #include "base/android/scoped_java_ref.h" |
14 #include "base/feature_list.h" | 15 #include "base/feature_list.h" |
15 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
16 #include "base/time/time.h" | 17 #include "base/time/time.h" |
17 #include "content/browser/frame_host/frame_tree.h" | 18 #include "content/browser/frame_host/frame_tree.h" |
18 #include "content/browser/frame_host/frame_tree_node.h" | 19 #include "content/browser/frame_host/frame_tree_node.h" |
19 #include "content/browser/frame_host/render_frame_host_impl.h" | 20 #include "content/browser/frame_host/render_frame_host_impl.h" |
20 #include "content/browser/renderer_host/render_view_host_delegate.h" | 21 #include "content/browser/renderer_host/render_view_host_delegate.h" |
21 #include "content/browser/renderer_host/render_view_host_impl.h" | 22 #include "content/browser/renderer_host/render_view_host_impl.h" |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 int start, | 260 int start, |
260 int end) { | 261 int end) { |
261 RenderFrameHost* rfh = GetFocusedFrame(); | 262 RenderFrameHost* rfh = GetFocusedFrame(); |
262 if (!rfh) | 263 if (!rfh) |
263 return; | 264 return; |
264 | 265 |
265 rfh->Send(new FrameMsg_SetEditableSelectionOffsets(rfh->GetRoutingID(), | 266 rfh->Send(new FrameMsg_SetEditableSelectionOffsets(rfh->GetRoutingID(), |
266 start, end)); | 267 start, end)); |
267 } | 268 } |
268 | 269 |
| 270 void ImeAdapterAndroid::SetCharacterBounds( |
| 271 const std::vector<gfx::RectF>& character_bounds) { |
| 272 JNIEnv* env = AttachCurrentThread(); |
| 273 base::android::ScopedJavaLocalRef<jobject> obj = java_ime_adapter_.get(env); |
| 274 if (obj.is_null()) |
| 275 return; |
| 276 |
| 277 const size_t coordinates_array_size = character_bounds.size() * 4; |
| 278 scoped_ptr<float[]> coordinates_array(new float[coordinates_array_size]); |
| 279 for (size_t i = 0; i < character_bounds.size(); ++i) { |
| 280 const gfx::RectF& rect = character_bounds[i]; |
| 281 const size_t coordinates_array_index = i * 4; |
| 282 coordinates_array[coordinates_array_index + 0] = rect.x(); |
| 283 coordinates_array[coordinates_array_index + 1] = rect.y(); |
| 284 coordinates_array[coordinates_array_index + 2] = rect.right(); |
| 285 coordinates_array[coordinates_array_index + 3] = rect.bottom(); |
| 286 } |
| 287 Java_ImeAdapter_setCharacterBounds( |
| 288 env, |
| 289 obj.obj(), |
| 290 base::android::ToJavaFloatArray(env, |
| 291 coordinates_array.get(), |
| 292 coordinates_array_size).obj()); |
| 293 } |
| 294 |
269 void ImeAdapterAndroid::SetComposingRegion(JNIEnv*, | 295 void ImeAdapterAndroid::SetComposingRegion(JNIEnv*, |
270 const JavaParamRef<jobject>&, | 296 const JavaParamRef<jobject>&, |
271 int start, | 297 int start, |
272 int end) { | 298 int end) { |
273 RenderFrameHost* rfh = GetFocusedFrame(); | 299 RenderFrameHost* rfh = GetFocusedFrame(); |
274 if (!rfh) | 300 if (!rfh) |
275 return; | 301 return; |
276 | 302 |
277 std::vector<blink::WebCompositionUnderline> underlines; | 303 std::vector<blink::WebCompositionUnderline> underlines; |
278 underlines.push_back(blink::WebCompositionUnderline( | 304 underlines.push_back(blink::WebCompositionUnderline( |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
339 } | 365 } |
340 | 366 |
341 WebContents* ImeAdapterAndroid::GetWebContents() { | 367 WebContents* ImeAdapterAndroid::GetWebContents() { |
342 RenderWidgetHostImpl* rwh = GetRenderWidgetHostImpl(); | 368 RenderWidgetHostImpl* rwh = GetRenderWidgetHostImpl(); |
343 if (!rwh) | 369 if (!rwh) |
344 return nullptr; | 370 return nullptr; |
345 return WebContents::FromRenderViewHost(RenderViewHost::From(rwh)); | 371 return WebContents::FromRenderViewHost(RenderViewHost::From(rwh)); |
346 } | 372 } |
347 | 373 |
348 } // namespace content | 374 } // namespace content |
OLD | NEW |