| 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" | |
| 15 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 16 #include "base/time/time.h" | 15 #include "base/time/time.h" |
| 17 #include "content/browser/frame_host/frame_tree.h" | 16 #include "content/browser/frame_host/frame_tree.h" |
| 18 #include "content/browser/frame_host/frame_tree_node.h" | 17 #include "content/browser/frame_host/frame_tree_node.h" |
| 19 #include "content/browser/frame_host/render_frame_host_impl.h" | 18 #include "content/browser/frame_host/render_frame_host_impl.h" |
| 20 #include "content/browser/renderer_host/render_view_host_delegate.h" | 19 #include "content/browser/renderer_host/render_view_host_delegate.h" |
| 21 #include "content/browser/renderer_host/render_view_host_impl.h" | 20 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 22 #include "content/browser/renderer_host/render_widget_host_impl.h" | 21 #include "content/browser/renderer_host/render_widget_host_impl.h" |
| 23 #include "content/browser/renderer_host/render_widget_host_view_android.h" | 22 #include "content/browser/renderer_host/render_widget_host_view_android.h" |
| 24 #include "content/common/frame_messages.h" | 23 #include "content/common/frame_messages.h" |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 void ImeAdapterAndroid::FocusedNodeChanged(bool is_editable_node) { | 260 void ImeAdapterAndroid::FocusedNodeChanged(bool is_editable_node) { |
| 262 base::android::ScopedJavaLocalRef<jobject> obj = | 261 base::android::ScopedJavaLocalRef<jobject> obj = |
| 263 java_ime_adapter_.get(AttachCurrentThread()); | 262 java_ime_adapter_.get(AttachCurrentThread()); |
| 264 if (!obj.is_null()) { | 263 if (!obj.is_null()) { |
| 265 Java_ImeAdapter_focusedNodeChanged(AttachCurrentThread(), | 264 Java_ImeAdapter_focusedNodeChanged(AttachCurrentThread(), |
| 266 obj.obj(), | 265 obj.obj(), |
| 267 is_editable_node); | 266 is_editable_node); |
| 268 } | 267 } |
| 269 } | 268 } |
| 270 | 269 |
| 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(); | |
| 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 | |
| 301 void ImeAdapterAndroid::SetEditableSelectionOffsets(JNIEnv*, jobject, | 270 void ImeAdapterAndroid::SetEditableSelectionOffsets(JNIEnv*, jobject, |
| 302 int start, int end) { | 271 int start, int end) { |
| 303 RenderFrameHost* rfh = GetFocusedFrame(); | 272 RenderFrameHost* rfh = GetFocusedFrame(); |
| 304 if (!rfh) | 273 if (!rfh) |
| 305 return; | 274 return; |
| 306 | 275 |
| 307 rfh->Send(new FrameMsg_SetEditableSelectionOffsets(rfh->GetRoutingID(), | 276 rfh->Send(new FrameMsg_SetEditableSelectionOffsets(rfh->GetRoutingID(), |
| 308 start, end)); | 277 start, end)); |
| 309 } | 278 } |
| 310 | 279 |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 392 WebContents* ImeAdapterAndroid::GetWebContents() { | 361 WebContents* ImeAdapterAndroid::GetWebContents() { |
| 393 RenderWidgetHostImpl* rwh = GetRenderWidgetHostImpl(); | 362 RenderWidgetHostImpl* rwh = GetRenderWidgetHostImpl(); |
| 394 if (!rwh) | 363 if (!rwh) |
| 395 return NULL; | 364 return NULL; |
| 396 if (!rwh->IsRenderView()) | 365 if (!rwh->IsRenderView()) |
| 397 return NULL; | 366 return NULL; |
| 398 return WebContents::FromRenderViewHost(RenderViewHost::From(rwh)); | 367 return WebContents::FromRenderViewHost(RenderViewHost::From(rwh)); |
| 399 } | 368 } |
| 400 | 369 |
| 401 } // namespace content | 370 } // namespace content |
| OLD | NEW |