| 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 1114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1125 void ContentViewCoreImpl::WasResized(JNIEnv* env, | 1125 void ContentViewCoreImpl::WasResized(JNIEnv* env, |
| 1126 const JavaParamRef<jobject>& obj) { | 1126 const JavaParamRef<jobject>& obj) { |
| 1127 gfx::Size physical_size( | 1127 gfx::Size physical_size( |
| 1128 Java_ContentViewCore_getPhysicalBackingWidthPix(env, obj), | 1128 Java_ContentViewCore_getPhysicalBackingWidthPix(env, obj), |
| 1129 Java_ContentViewCore_getPhysicalBackingHeightPix(env, obj)); | 1129 Java_ContentViewCore_getPhysicalBackingHeightPix(env, obj)); |
| 1130 GetViewAndroid()->GetLayer()->SetBounds(physical_size); | 1130 GetViewAndroid()->GetLayer()->SetBounds(physical_size); |
| 1131 | 1131 |
| 1132 SendScreenRectsAndResizeWidget(); | 1132 SendScreenRectsAndResizeWidget(); |
| 1133 } | 1133 } |
| 1134 | 1134 |
| 1135 long ContentViewCoreImpl::GetNativeImeAdapter( | 1135 void ContentViewCoreImpl::UpdateImeAdapter(int text_input_type, |
| 1136 JNIEnv* env, | |
| 1137 const JavaParamRef<jobject>& obj) { | |
| 1138 RenderWidgetHostViewAndroid* rwhva = GetRenderWidgetHostViewAndroid(); | |
| 1139 if (!rwhva) | |
| 1140 return 0; | |
| 1141 return rwhva->GetNativeImeAdapter(); | |
| 1142 } | |
| 1143 | |
| 1144 void ContentViewCoreImpl::ForceUpdateImeAdapter(long native_ime_adapter) { | |
| 1145 JNIEnv* env = AttachCurrentThread(); | |
| 1146 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | |
| 1147 if (obj.is_null()) | |
| 1148 return; | |
| 1149 Java_ContentViewCore_forceUpdateImeAdapter(env, obj, native_ime_adapter); | |
| 1150 } | |
| 1151 | |
| 1152 void ContentViewCoreImpl::UpdateImeAdapter(long native_ime_adapter, | |
| 1153 int text_input_type, | |
| 1154 int text_input_flags, | 1136 int text_input_flags, |
| 1155 int text_input_mode, | 1137 int text_input_mode, |
| 1156 const std::string& text, | 1138 const std::string& text, |
| 1157 int selection_start, | 1139 int selection_start, |
| 1158 int selection_end, | 1140 int selection_end, |
| 1159 int composition_start, | 1141 int composition_start, |
| 1160 int composition_end, | 1142 int composition_end, |
| 1161 bool show_ime_if_needed, | 1143 bool show_ime_if_needed, |
| 1162 bool reply_to_request) { | 1144 bool reply_to_request) { |
| 1163 JNIEnv* env = AttachCurrentThread(); | 1145 JNIEnv* env = AttachCurrentThread(); |
| 1164 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | 1146 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); |
| 1165 if (obj.is_null()) | 1147 if (obj.is_null()) |
| 1166 return; | 1148 return; |
| 1167 | 1149 |
| 1168 ScopedJavaLocalRef<jstring> jstring_text = ConvertUTF8ToJavaString(env, text); | 1150 ScopedJavaLocalRef<jstring> jstring_text = ConvertUTF8ToJavaString(env, text); |
| 1169 Java_ContentViewCore_updateImeAdapter( | 1151 Java_ContentViewCore_updateImeAdapter( |
| 1170 env, obj, native_ime_adapter, text_input_type, text_input_flags, | 1152 env, obj, text_input_type, text_input_flags, text_input_mode, |
| 1171 text_input_mode, jstring_text, selection_start, selection_end, | 1153 jstring_text, selection_start, selection_end, composition_start, |
| 1172 composition_start, composition_end, show_ime_if_needed, reply_to_request); | 1154 composition_end, show_ime_if_needed, reply_to_request); |
| 1173 } | 1155 } |
| 1174 | 1156 |
| 1175 void ContentViewCoreImpl::SetAccessibilityEnabled( | 1157 void ContentViewCoreImpl::SetAccessibilityEnabled( |
| 1176 JNIEnv* env, | 1158 JNIEnv* env, |
| 1177 const JavaParamRef<jobject>& obj, | 1159 const JavaParamRef<jobject>& obj, |
| 1178 bool enabled) { | 1160 bool enabled) { |
| 1179 SetAccessibilityEnabledInternal(enabled); | 1161 SetAccessibilityEnabledInternal(enabled); |
| 1180 } | 1162 } |
| 1181 | 1163 |
| 1182 void ContentViewCoreImpl::SetTextTrackSettings( | 1164 void ContentViewCoreImpl::SetTextTrackSettings( |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1369 DCHECK(wcva); | 1351 DCHECK(wcva); |
| 1370 wcva->SetContentViewCore(NULL); | 1352 wcva->SetContentViewCore(NULL); |
| 1371 } | 1353 } |
| 1372 | 1354 |
| 1373 // This is called for each ContentView. | 1355 // This is called for each ContentView. |
| 1374 jlong Init(JNIEnv* env, | 1356 jlong Init(JNIEnv* env, |
| 1375 const JavaParamRef<jobject>& obj, | 1357 const JavaParamRef<jobject>& obj, |
| 1376 const JavaParamRef<jobject>& jweb_contents, | 1358 const JavaParamRef<jobject>& jweb_contents, |
| 1377 const JavaParamRef<jobject>& jview_android_delegate, | 1359 const JavaParamRef<jobject>& jview_android_delegate, |
| 1378 jlong jwindow_android, | 1360 jlong jwindow_android, |
| 1379 jfloat dipScale, | 1361 jfloat dip_scale, |
| 1380 const JavaParamRef<jobject>& retained_objects_set) { | 1362 const JavaParamRef<jobject>& retained_objects_set) { |
| 1381 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>( | 1363 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>( |
| 1382 WebContents::FromJavaWebContents(jweb_contents)); | 1364 WebContents::FromJavaWebContents(jweb_contents)); |
| 1383 CHECK(web_contents) << | 1365 CHECK(web_contents) << |
| 1384 "A ContentViewCoreImpl should be created with a valid WebContents."; | 1366 "A ContentViewCoreImpl should be created with a valid WebContents."; |
| 1385 ui::ViewAndroid* view_android = web_contents->GetView()->GetNativeView(); | 1367 ui::ViewAndroid* view_android = web_contents->GetView()->GetNativeView(); |
| 1386 view_android->SetDelegate(jview_android_delegate); | 1368 view_android->SetDelegate(jview_android_delegate); |
| 1387 view_android->SetLayout(ui::ViewAndroid::LayoutParams::MatchParent()); | 1369 view_android->SetLayout(ui::ViewAndroid::LayoutParams::MatchParent()); |
| 1388 | 1370 |
| 1389 ui::WindowAndroid* window_android = | 1371 ui::WindowAndroid* window_android = |
| 1390 reinterpret_cast<ui::WindowAndroid*>(jwindow_android); | 1372 reinterpret_cast<ui::WindowAndroid*>(jwindow_android); |
| 1391 DCHECK(window_android); | 1373 DCHECK(window_android); |
| 1392 window_android->AddChild(view_android); | 1374 window_android->AddChild(view_android); |
| 1393 | 1375 |
| 1394 // TODO: pass dipScale. | |
| 1395 ContentViewCoreImpl* view = new ContentViewCoreImpl( | 1376 ContentViewCoreImpl* view = new ContentViewCoreImpl( |
| 1396 env, obj, web_contents, dipScale, retained_objects_set); | 1377 env, obj, web_contents, dip_scale, retained_objects_set); |
| 1397 return reinterpret_cast<intptr_t>(view); | 1378 return reinterpret_cast<intptr_t>(view); |
| 1398 } | 1379 } |
| 1399 | 1380 |
| 1400 static ScopedJavaLocalRef<jobject> FromWebContentsAndroid( | 1381 static ScopedJavaLocalRef<jobject> FromWebContentsAndroid( |
| 1401 JNIEnv* env, | 1382 JNIEnv* env, |
| 1402 const JavaParamRef<jclass>& clazz, | 1383 const JavaParamRef<jclass>& clazz, |
| 1403 const JavaParamRef<jobject>& jweb_contents) { | 1384 const JavaParamRef<jobject>& jweb_contents) { |
| 1404 WebContents* web_contents = WebContents::FromJavaWebContents(jweb_contents); | 1385 WebContents* web_contents = WebContents::FromJavaWebContents(jweb_contents); |
| 1405 if (!web_contents) | 1386 if (!web_contents) |
| 1406 return ScopedJavaLocalRef<jobject>(); | 1387 return ScopedJavaLocalRef<jobject>(); |
| 1407 | 1388 |
| 1408 ContentViewCore* view = ContentViewCore::FromWebContents(web_contents); | 1389 ContentViewCore* view = ContentViewCore::FromWebContents(web_contents); |
| 1409 if (!view) | 1390 if (!view) |
| 1410 return ScopedJavaLocalRef<jobject>(); | 1391 return ScopedJavaLocalRef<jobject>(); |
| 1411 | 1392 |
| 1412 return view->GetJavaObject(); | 1393 return view->GetJavaObject(); |
| 1413 } | 1394 } |
| 1414 | 1395 |
| 1415 bool RegisterContentViewCore(JNIEnv* env) { | 1396 bool RegisterContentViewCore(JNIEnv* env) { |
| 1416 return RegisterNativesImpl(env); | 1397 return RegisterNativesImpl(env); |
| 1417 } | 1398 } |
| 1418 | 1399 |
| 1419 } // namespace content | 1400 } // namespace content |
| OLD | NEW |