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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
61 POPUP_ITEM_TYPE_ENABLED | 61 POPUP_ITEM_TYPE_ENABLED |
62 }; | 62 }; |
63 | 63 |
64 namespace { | 64 namespace { |
65 jfieldID g_native_content_view; | 65 jfieldID g_native_content_view; |
66 } // namespace | 66 } // namespace |
67 | 67 |
68 namespace content { | 68 namespace content { |
69 | 69 |
70 struct ContentViewCoreImpl::JavaObject { | 70 struct ContentViewCoreImpl::JavaObject { |
71 | 71 ScopedJavaGlobalRef<jclass> rect_clazz; |
72 jmethodID rect_constructor; | |
72 }; | 73 }; |
73 | 74 |
74 ContentViewCore* ContentViewCore::GetNativeContentViewCore(JNIEnv* env, | 75 ContentViewCore* ContentViewCore::GetNativeContentViewCore(JNIEnv* env, |
75 jobject obj) { | 76 jobject obj) { |
76 return reinterpret_cast<ContentViewCore*>( | 77 return reinterpret_cast<ContentViewCore*>( |
77 env->GetIntField(obj, g_native_content_view)); | 78 env->GetIntField(obj, g_native_content_view)); |
78 } | 79 } |
79 | 80 |
80 | 81 |
81 ContentViewCoreImpl::ContentViewCoreImpl(JNIEnv* env, jobject obj, | 82 ContentViewCoreImpl::ContentViewCoreImpl(JNIEnv* env, jobject obj, |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
155 Java_ContentViewCore_onEvaluateJavaScriptResult(env, j_obj.obj(), | 156 Java_ContentViewCore_onEvaluateJavaScriptResult(env, j_obj.obj(), |
156 static_cast<jint>(result_pair->first), j_json.obj()); | 157 static_cast<jint>(result_pair->first), j_json.obj()); |
157 } | 158 } |
158 break; | 159 break; |
159 } | 160 } |
160 } | 161 } |
161 } | 162 } |
162 | 163 |
163 void ContentViewCoreImpl::InitJNI(JNIEnv* env, jobject obj) { | 164 void ContentViewCoreImpl::InitJNI(JNIEnv* env, jobject obj) { |
164 java_object_ = new JavaObject; | 165 java_object_ = new JavaObject; |
166 java_object_->rect_clazz.Reset(GetClass(env, "android/graphics/Rect")); | |
167 java_object_->rect_constructor = | |
168 GetMethodID(env, java_object_->rect_clazz, "<init>", "(IIII)V"); | |
bulach
2012/10/05 12:50:59
FYI: one of us :) will need to change this dependi
Iain Merrick
2012/10/05 19:01:52
Thanks for the heads-up -- I'll rely on the trybot
| |
165 } | 169 } |
166 | 170 |
167 RenderWidgetHostViewAndroid* | 171 RenderWidgetHostViewAndroid* |
168 ContentViewCoreImpl::GetRenderWidgetHostViewAndroid() { | 172 ContentViewCoreImpl::GetRenderWidgetHostViewAndroid() { |
169 RenderWidgetHostView* rwhv = NULL; | 173 RenderWidgetHostView* rwhv = NULL; |
170 if (web_contents_) | 174 if (web_contents_) |
171 rwhv = web_contents_->GetRenderWidgetHostView(); | 175 rwhv = web_contents_->GetRenderWidgetHostView(); |
172 return static_cast<RenderWidgetHostViewAndroid*>(rwhv); | 176 return static_cast<RenderWidgetHostViewAndroid*>(rwhv); |
173 } | 177 } |
174 | 178 |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
321 | 325 |
322 bool ContentViewCoreImpl::HasFocus() { | 326 bool ContentViewCoreImpl::HasFocus() { |
323 JNIEnv* env = AttachCurrentThread(); | 327 JNIEnv* env = AttachCurrentThread(); |
324 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | 328 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); |
325 if (obj.is_null()) | 329 if (obj.is_null()) |
326 return false; | 330 return false; |
327 return Java_ContentViewCore_hasFocus(env, obj.obj()); | 331 return Java_ContentViewCore_hasFocus(env, obj.obj()); |
328 } | 332 } |
329 | 333 |
330 void ContentViewCoreImpl::OnSelectionChanged(const std::string& text) { | 334 void ContentViewCoreImpl::OnSelectionChanged(const std::string& text) { |
331 NOTIMPLEMENTED() << "not upstreamed yet"; | 335 JNIEnv* env = AttachCurrentThread(); |
336 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | |
337 if (obj.is_null()) | |
338 return; | |
339 ScopedJavaLocalRef<jstring> jtext = ConvertUTF8ToJavaString(env, text); | |
340 Java_ContentViewCore_onSelectionChanged(env, obj.obj(), jtext.obj()); | |
341 } | |
342 | |
343 void ContentViewCoreImpl::OnSelectionBoundsChanged( | |
344 const gfx::Rect& start_rect, base::i18n::TextDirection start_dir, | |
345 const gfx::Rect& end_rect, base::i18n::TextDirection end_dir) { | |
346 JNIEnv* env = AttachCurrentThread(); | |
347 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | |
348 if (obj.is_null()) | |
349 return; | |
350 ScopedJavaLocalRef<jobject> start_rect_object(env, | |
351 env->NewObject(java_object_->rect_clazz.obj(), | |
352 java_object_->rect_constructor, | |
353 start_rect.x(), | |
354 start_rect.y(), | |
355 start_rect.right(), | |
356 start_rect.bottom())); | |
357 ScopedJavaLocalRef<jobject> end_rect_object(env, | |
358 env->NewObject(java_object_->rect_clazz.obj(), | |
359 java_object_->rect_constructor, | |
360 end_rect.x(), | |
361 end_rect.y(), | |
362 end_rect.right(), | |
363 end_rect.bottom())); | |
364 Java_ContentViewCore_onSelectionBoundsChanged(env, obj.obj(), | |
365 start_rect_object.obj(), | |
366 start_dir, | |
367 end_rect_object.obj(), | |
368 end_dir); | |
332 } | 369 } |
333 | 370 |
334 void ContentViewCoreImpl::StartContentIntent(const GURL& content_url) { | 371 void ContentViewCoreImpl::StartContentIntent(const GURL& content_url) { |
335 JNIEnv* env = AttachCurrentThread(); | 372 JNIEnv* env = AttachCurrentThread(); |
336 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); | 373 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); |
337 if (j_obj.is_null()) | 374 if (j_obj.is_null()) |
338 return; | 375 return; |
339 ScopedJavaLocalRef<jstring> jcontent_url = | 376 ScopedJavaLocalRef<jstring> jcontent_url = |
340 ConvertUTF8ToJavaString(env, content_url.spec()); | 377 ConvertUTF8ToJavaString(env, content_url.spec()); |
341 Java_ContentViewCore_startContentIntent(env, | 378 Java_ContentViewCore_startContentIntent(env, |
(...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
851 if (!HasField(env, clazz, "mNativeContentViewCore", "I")) { | 888 if (!HasField(env, clazz, "mNativeContentViewCore", "I")) { |
852 DLOG(ERROR) << "Unable to find ContentView.mNativeContentViewCore!"; | 889 DLOG(ERROR) << "Unable to find ContentView.mNativeContentViewCore!"; |
853 return false; | 890 return false; |
854 } | 891 } |
855 g_native_content_view = GetFieldID(env, clazz, "mNativeContentViewCore", "I"); | 892 g_native_content_view = GetFieldID(env, clazz, "mNativeContentViewCore", "I"); |
856 | 893 |
857 return RegisterNativesImpl(env) >= 0; | 894 return RegisterNativesImpl(env) >= 0; |
858 } | 895 } |
859 | 896 |
860 } // namespace content | 897 } // namespace content |
OLD | NEW |