| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/android/jni_android.h" | 9 #include "base/android/jni_android.h" |
| 10 #include "base/android/jni_array.h" | 10 #include "base/android/jni_array.h" |
| (...skipping 1069 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1080 void ContentViewCoreImpl::WasResized(JNIEnv* env, | 1080 void ContentViewCoreImpl::WasResized(JNIEnv* env, |
| 1081 const JavaParamRef<jobject>& obj) { | 1081 const JavaParamRef<jobject>& obj) { |
| 1082 gfx::Size physical_size( | 1082 gfx::Size physical_size( |
| 1083 Java_ContentViewCore_getPhysicalBackingWidthPix(env, obj), | 1083 Java_ContentViewCore_getPhysicalBackingWidthPix(env, obj), |
| 1084 Java_ContentViewCore_getPhysicalBackingHeightPix(env, obj)); | 1084 Java_ContentViewCore_getPhysicalBackingHeightPix(env, obj)); |
| 1085 GetViewAndroid()->GetLayer()->SetBounds(physical_size); | 1085 GetViewAndroid()->GetLayer()->SetBounds(physical_size); |
| 1086 | 1086 |
| 1087 SendScreenRectsAndResizeWidget(); | 1087 SendScreenRectsAndResizeWidget(); |
| 1088 } | 1088 } |
| 1089 | 1089 |
| 1090 long ContentViewCoreImpl::GetNativeImeAdapter( | 1090 void ContentViewCoreImpl::UpdateImeAdapter(int text_input_type, |
| 1091 JNIEnv* env, | |
| 1092 const JavaParamRef<jobject>& obj) { | |
| 1093 RenderWidgetHostViewAndroid* rwhva = GetRenderWidgetHostViewAndroid(); | |
| 1094 if (!rwhva) | |
| 1095 return 0; | |
| 1096 return rwhva->GetNativeImeAdapter(); | |
| 1097 } | |
| 1098 | |
| 1099 void ContentViewCoreImpl::ForceUpdateImeAdapter(long native_ime_adapter) { | |
| 1100 JNIEnv* env = AttachCurrentThread(); | |
| 1101 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | |
| 1102 if (obj.is_null()) | |
| 1103 return; | |
| 1104 Java_ContentViewCore_forceUpdateImeAdapter(env, obj, native_ime_adapter); | |
| 1105 } | |
| 1106 | |
| 1107 void ContentViewCoreImpl::UpdateImeAdapter(long native_ime_adapter, | |
| 1108 int text_input_type, | |
| 1109 int text_input_flags, | 1091 int text_input_flags, |
| 1110 int text_input_mode, | 1092 int text_input_mode, |
| 1111 const std::string& text, | 1093 const std::string& text, |
| 1112 int selection_start, | 1094 int selection_start, |
| 1113 int selection_end, | 1095 int selection_end, |
| 1114 int composition_start, | 1096 int composition_start, |
| 1115 int composition_end, | 1097 int composition_end, |
| 1116 bool show_ime_if_needed, | 1098 bool show_ime_if_needed, |
| 1117 bool reply_to_request) { | 1099 bool reply_to_request) { |
| 1118 JNIEnv* env = AttachCurrentThread(); | 1100 JNIEnv* env = AttachCurrentThread(); |
| 1119 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | 1101 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); |
| 1120 if (obj.is_null()) | 1102 if (obj.is_null()) |
| 1121 return; | 1103 return; |
| 1122 | 1104 |
| 1123 ScopedJavaLocalRef<jstring> jstring_text = ConvertUTF8ToJavaString(env, text); | 1105 ScopedJavaLocalRef<jstring> jstring_text = ConvertUTF8ToJavaString(env, text); |
| 1124 Java_ContentViewCore_updateImeAdapter( | 1106 Java_ContentViewCore_updateImeAdapter( |
| 1125 env, obj, native_ime_adapter, text_input_type, text_input_flags, | 1107 env, obj, text_input_type, text_input_flags, text_input_mode, |
| 1126 text_input_mode, jstring_text, selection_start, selection_end, | 1108 jstring_text, selection_start, selection_end, composition_start, |
| 1127 composition_start, composition_end, show_ime_if_needed, reply_to_request); | 1109 composition_end, show_ime_if_needed, reply_to_request); |
| 1128 } | 1110 } |
| 1129 | 1111 |
| 1130 void ContentViewCoreImpl::SetAccessibilityEnabled( | 1112 void ContentViewCoreImpl::SetAccessibilityEnabled( |
| 1131 JNIEnv* env, | 1113 JNIEnv* env, |
| 1132 const JavaParamRef<jobject>& obj, | 1114 const JavaParamRef<jobject>& obj, |
| 1133 bool enabled) { | 1115 bool enabled) { |
| 1134 SetAccessibilityEnabledInternal(enabled); | 1116 SetAccessibilityEnabledInternal(enabled); |
| 1135 } | 1117 } |
| 1136 | 1118 |
| 1137 void ContentViewCoreImpl::SetTextTrackSettings( | 1119 void ContentViewCoreImpl::SetTextTrackSettings( |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1324 DCHECK(wcva); | 1306 DCHECK(wcva); |
| 1325 wcva->SetContentViewCore(NULL); | 1307 wcva->SetContentViewCore(NULL); |
| 1326 } | 1308 } |
| 1327 | 1309 |
| 1328 // This is called for each ContentView. | 1310 // This is called for each ContentView. |
| 1329 jlong Init(JNIEnv* env, | 1311 jlong Init(JNIEnv* env, |
| 1330 const JavaParamRef<jobject>& obj, | 1312 const JavaParamRef<jobject>& obj, |
| 1331 const JavaParamRef<jobject>& jweb_contents, | 1313 const JavaParamRef<jobject>& jweb_contents, |
| 1332 const JavaParamRef<jobject>& jview_android_delegate, | 1314 const JavaParamRef<jobject>& jview_android_delegate, |
| 1333 jlong jwindow_android, | 1315 jlong jwindow_android, |
| 1334 jfloat dipScale, | 1316 jfloat dip_scale, |
| 1335 const JavaParamRef<jobject>& retained_objects_set) { | 1317 const JavaParamRef<jobject>& retained_objects_set) { |
| 1336 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>( | 1318 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>( |
| 1337 WebContents::FromJavaWebContents(jweb_contents)); | 1319 WebContents::FromJavaWebContents(jweb_contents)); |
| 1338 CHECK(web_contents) << | 1320 CHECK(web_contents) << |
| 1339 "A ContentViewCoreImpl should be created with a valid WebContents."; | 1321 "A ContentViewCoreImpl should be created with a valid WebContents."; |
| 1340 ui::ViewAndroid* view_android = web_contents->GetView()->GetNativeView(); | 1322 ui::ViewAndroid* view_android = web_contents->GetView()->GetNativeView(); |
| 1341 view_android->SetDelegate(jview_android_delegate); | 1323 view_android->SetDelegate(jview_android_delegate); |
| 1342 view_android->SetLayout(ui::ViewAndroid::LayoutParams::MatchParent()); | 1324 view_android->SetLayout(ui::ViewAndroid::LayoutParams::MatchParent()); |
| 1343 | 1325 |
| 1344 ui::WindowAndroid* window_android = | 1326 ui::WindowAndroid* window_android = |
| 1345 reinterpret_cast<ui::WindowAndroid*>(jwindow_android); | 1327 reinterpret_cast<ui::WindowAndroid*>(jwindow_android); |
| 1346 DCHECK(window_android); | 1328 DCHECK(window_android); |
| 1347 window_android->AddChild(view_android); | 1329 window_android->AddChild(view_android); |
| 1348 | 1330 |
| 1349 // TODO: pass dipScale. | |
| 1350 ContentViewCoreImpl* view = new ContentViewCoreImpl( | 1331 ContentViewCoreImpl* view = new ContentViewCoreImpl( |
| 1351 env, obj, web_contents, dipScale, retained_objects_set); | 1332 env, obj, web_contents, dip_scale, retained_objects_set); |
| 1352 return reinterpret_cast<intptr_t>(view); | 1333 return reinterpret_cast<intptr_t>(view); |
| 1353 } | 1334 } |
| 1354 | 1335 |
| 1355 static ScopedJavaLocalRef<jobject> FromWebContentsAndroid( | 1336 static ScopedJavaLocalRef<jobject> FromWebContentsAndroid( |
| 1356 JNIEnv* env, | 1337 JNIEnv* env, |
| 1357 const JavaParamRef<jclass>& clazz, | 1338 const JavaParamRef<jclass>& clazz, |
| 1358 const JavaParamRef<jobject>& jweb_contents) { | 1339 const JavaParamRef<jobject>& jweb_contents) { |
| 1359 WebContents* web_contents = WebContents::FromJavaWebContents(jweb_contents); | 1340 WebContents* web_contents = WebContents::FromJavaWebContents(jweb_contents); |
| 1360 if (!web_contents) | 1341 if (!web_contents) |
| 1361 return ScopedJavaLocalRef<jobject>(); | 1342 return ScopedJavaLocalRef<jobject>(); |
| 1362 | 1343 |
| 1363 ContentViewCore* view = ContentViewCore::FromWebContents(web_contents); | 1344 ContentViewCore* view = ContentViewCore::FromWebContents(web_contents); |
| 1364 if (!view) | 1345 if (!view) |
| 1365 return ScopedJavaLocalRef<jobject>(); | 1346 return ScopedJavaLocalRef<jobject>(); |
| 1366 | 1347 |
| 1367 return view->GetJavaObject(); | 1348 return view->GetJavaObject(); |
| 1368 } | 1349 } |
| 1369 | 1350 |
| 1370 bool RegisterContentViewCore(JNIEnv* env) { | 1351 bool RegisterContentViewCore(JNIEnv* env) { |
| 1371 return RegisterNativesImpl(env); | 1352 return RegisterNativesImpl(env); |
| 1372 } | 1353 } |
| 1373 | 1354 |
| 1374 } // namespace content | 1355 } // namespace content |
| OLD | NEW |