| 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/android/content_view_core_impl.h" | 5 #include "content/browser/android/content_view_core_impl.h" |
| 6 | 6 |
| 7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
| 8 #include "base/android/jni_array.h" | 8 #include "base/android/jni_array.h" |
| 9 #include "base/android/jni_string.h" | 9 #include "base/android/jni_string.h" |
| 10 #include "base/android/scoped_java_ref.h" | 10 #include "base/android/scoped_java_ref.h" |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 POPUP_ITEM_TYPE_ENABLED | 65 POPUP_ITEM_TYPE_ENABLED |
| 66 }; | 66 }; |
| 67 | 67 |
| 68 namespace { | 68 namespace { |
| 69 jfieldID g_native_content_view; | 69 jfieldID g_native_content_view; |
| 70 } // namespace | 70 } // namespace |
| 71 | 71 |
| 72 namespace content { | 72 namespace content { |
| 73 | 73 |
| 74 struct ContentViewCoreImpl::JavaObject { | 74 struct ContentViewCoreImpl::JavaObject { |
| 75 | 75 ScopedJavaGlobalRef<jclass> rect_clazz; |
| 76 jmethodID rect_constructor; |
| 76 }; | 77 }; |
| 77 | 78 |
| 78 ContentViewCore* ContentViewCore::GetNativeContentViewCore(JNIEnv* env, | 79 ContentViewCore* ContentViewCore::GetNativeContentViewCore(JNIEnv* env, |
| 79 jobject obj) { | 80 jobject obj) { |
| 80 return reinterpret_cast<ContentViewCore*>( | 81 return reinterpret_cast<ContentViewCore*>( |
| 81 env->GetIntField(obj, g_native_content_view)); | 82 env->GetIntField(obj, g_native_content_view)); |
| 82 } | 83 } |
| 83 | 84 |
| 84 | 85 |
| 85 ContentViewCoreImpl::ContentViewCoreImpl(JNIEnv* env, jobject obj, | 86 ContentViewCoreImpl::ContentViewCoreImpl(JNIEnv* env, jobject obj, |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 Java_ContentViewCore_onEvaluateJavaScriptResult(env, j_obj.obj(), | 167 Java_ContentViewCore_onEvaluateJavaScriptResult(env, j_obj.obj(), |
| 167 static_cast<jint>(result_pair->first), j_json.obj()); | 168 static_cast<jint>(result_pair->first), j_json.obj()); |
| 168 } | 169 } |
| 169 break; | 170 break; |
| 170 } | 171 } |
| 171 } | 172 } |
| 172 } | 173 } |
| 173 | 174 |
| 174 void ContentViewCoreImpl::InitJNI(JNIEnv* env, jobject obj) { | 175 void ContentViewCoreImpl::InitJNI(JNIEnv* env, jobject obj) { |
| 175 java_object_ = new JavaObject; | 176 java_object_ = new JavaObject; |
| 177 java_object_->rect_clazz.Reset(GetClass(env, "android/graphics/Rect")); |
| 178 java_object_->rect_constructor = |
| 179 GetMethodID(env, java_object_->rect_clazz, "<init>", "(IIII)V"); |
| 176 } | 180 } |
| 177 | 181 |
| 178 RenderWidgetHostViewAndroid* | 182 RenderWidgetHostViewAndroid* |
| 179 ContentViewCoreImpl::GetRenderWidgetHostViewAndroid() { | 183 ContentViewCoreImpl::GetRenderWidgetHostViewAndroid() { |
| 180 RenderWidgetHostView* rwhv = NULL; | 184 RenderWidgetHostView* rwhv = NULL; |
| 181 if (web_contents_) | 185 if (web_contents_) |
| 182 rwhv = web_contents_->GetRenderWidgetHostView(); | 186 rwhv = web_contents_->GetRenderWidgetHostView(); |
| 183 return static_cast<RenderWidgetHostViewAndroid*>(rwhv); | 187 return static_cast<RenderWidgetHostViewAndroid*>(rwhv); |
| 184 } | 188 } |
| 185 | 189 |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 | 336 |
| 333 bool ContentViewCoreImpl::HasFocus() { | 337 bool ContentViewCoreImpl::HasFocus() { |
| 334 JNIEnv* env = AttachCurrentThread(); | 338 JNIEnv* env = AttachCurrentThread(); |
| 335 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | 339 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); |
| 336 if (obj.is_null()) | 340 if (obj.is_null()) |
| 337 return false; | 341 return false; |
| 338 return Java_ContentViewCore_hasFocus(env, obj.obj()); | 342 return Java_ContentViewCore_hasFocus(env, obj.obj()); |
| 339 } | 343 } |
| 340 | 344 |
| 341 void ContentViewCoreImpl::OnSelectionChanged(const std::string& text) { | 345 void ContentViewCoreImpl::OnSelectionChanged(const std::string& text) { |
| 342 NOTIMPLEMENTED() << "not upstreamed yet"; | 346 JNIEnv* env = AttachCurrentThread(); |
| 347 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); |
| 348 if (obj.is_null()) |
| 349 return; |
| 350 ScopedJavaLocalRef<jstring> jtext = ConvertUTF8ToJavaString(env, text); |
| 351 Java_ContentViewCore_onSelectionChanged(env, obj.obj(), jtext.obj()); |
| 352 } |
| 353 |
| 354 void ContentViewCoreImpl::OnSelectionBoundsChanged( |
| 355 const gfx::Rect& start_rect, base::i18n::TextDirection start_dir, |
| 356 const gfx::Rect& end_rect, base::i18n::TextDirection end_dir) { |
| 357 JNIEnv* env = AttachCurrentThread(); |
| 358 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); |
| 359 if (obj.is_null()) |
| 360 return; |
| 361 ScopedJavaLocalRef<jobject> start_rect_object(env, |
| 362 env->NewObject(java_object_->rect_clazz.obj(), |
| 363 java_object_->rect_constructor, |
| 364 start_rect.x(), |
| 365 start_rect.y(), |
| 366 start_rect.right(), |
| 367 start_rect.bottom())); |
| 368 ScopedJavaLocalRef<jobject> end_rect_object(env, |
| 369 env->NewObject(java_object_->rect_clazz.obj(), |
| 370 java_object_->rect_constructor, |
| 371 end_rect.x(), |
| 372 end_rect.y(), |
| 373 end_rect.right(), |
| 374 end_rect.bottom())); |
| 375 Java_ContentViewCore_onSelectionBoundsChanged(env, obj.obj(), |
| 376 start_rect_object.obj(), |
| 377 start_dir, |
| 378 end_rect_object.obj(), |
| 379 end_dir); |
| 343 } | 380 } |
| 344 | 381 |
| 345 void ContentViewCoreImpl::StartContentIntent(const GURL& content_url) { | 382 void ContentViewCoreImpl::StartContentIntent(const GURL& content_url) { |
| 346 JNIEnv* env = AttachCurrentThread(); | 383 JNIEnv* env = AttachCurrentThread(); |
| 347 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); | 384 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); |
| 348 if (j_obj.is_null()) | 385 if (j_obj.is_null()) |
| 349 return; | 386 return; |
| 350 ScopedJavaLocalRef<jstring> jcontent_url = | 387 ScopedJavaLocalRef<jstring> jcontent_url = |
| 351 ConvertUTF8ToJavaString(env, content_url.spec()); | 388 ConvertUTF8ToJavaString(env, content_url.spec()); |
| 352 Java_ContentViewCore_startContentIntent(env, | 389 Java_ContentViewCore_startContentIntent(env, |
| (...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 926 if (!HasField(env, clazz, "mNativeContentViewCore", "I")) { | 963 if (!HasField(env, clazz, "mNativeContentViewCore", "I")) { |
| 927 DLOG(ERROR) << "Unable to find ContentView.mNativeContentViewCore!"; | 964 DLOG(ERROR) << "Unable to find ContentView.mNativeContentViewCore!"; |
| 928 return false; | 965 return false; |
| 929 } | 966 } |
| 930 g_native_content_view = GetFieldID(env, clazz, "mNativeContentViewCore", "I"); | 967 g_native_content_view = GetFieldID(env, clazz, "mNativeContentViewCore", "I"); |
| 931 | 968 |
| 932 return RegisterNativesImpl(env) >= 0; | 969 return RegisterNativesImpl(env) >= 0; |
| 933 } | 970 } |
| 934 | 971 |
| 935 } // namespace content | 972 } // namespace content |
| OLD | NEW |