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 669 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
680 ScopedJavaLocalRef<jobject> ContentViewCoreImpl::GetContext() const { | 680 ScopedJavaLocalRef<jobject> ContentViewCoreImpl::GetContext() const { |
681 JNIEnv* env = AttachCurrentThread(); | 681 JNIEnv* env = AttachCurrentThread(); |
682 | 682 |
683 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | 683 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); |
684 if (obj.is_null()) | 684 if (obj.is_null()) |
685 return ScopedJavaLocalRef<jobject>(); | 685 return ScopedJavaLocalRef<jobject>(); |
686 | 686 |
687 return Java_ContentViewCore_getContext(env, obj); | 687 return Java_ContentViewCore_getContext(env, obj); |
688 } | 688 } |
689 | 689 |
| 690 gfx::Size ContentViewCoreImpl::GetViewSizeWithOSKHidden() const { |
| 691 gfx::Size size_pix; |
| 692 JNIEnv* env = AttachCurrentThread(); |
| 693 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); |
| 694 if (j_obj.is_null()) |
| 695 return size_pix = gfx::Size(); |
| 696 size_pix = gfx::Size( |
| 697 Java_ContentViewCore_getViewportWidthPix(env, j_obj), |
| 698 Java_ContentViewCore_getViewportHeightWithOSKHiddenPix(env, j_obj)); |
| 699 |
| 700 gfx::Size size_dip = gfx::ScaleToCeiledSize(size_pix, 1.0f / dpi_scale()); |
| 701 if (DoBrowserControlsShrinkBlinkSize()) |
| 702 size_dip.Enlarge(0, -GetTopControlsHeightDip()); |
| 703 return size_dip; |
| 704 } |
| 705 |
690 gfx::Size ContentViewCoreImpl::GetViewSize() const { | 706 gfx::Size ContentViewCoreImpl::GetViewSize() const { |
691 gfx::Size size = GetViewportSizeDip(); | 707 gfx::Size size = GetViewportSizeDip(); |
692 if (DoBrowserControlsShrinkBlinkSize()) | 708 if (DoBrowserControlsShrinkBlinkSize()) |
693 size.Enlarge(0, -GetTopControlsHeightDip() - GetBottomControlsHeightDip()); | 709 size.Enlarge(0, -GetTopControlsHeightDip() - GetBottomControlsHeightDip()); |
694 return size; | 710 return size; |
695 } | 711 } |
696 | 712 |
697 gfx::Size ContentViewCoreImpl::GetPhysicalBackingSize() const { | 713 gfx::Size ContentViewCoreImpl::GetPhysicalBackingSize() const { |
698 JNIEnv* env = AttachCurrentThread(); | 714 JNIEnv* env = AttachCurrentThread(); |
699 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); | 715 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); |
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1069 void ContentViewCoreImpl::WasResized(JNIEnv* env, | 1085 void ContentViewCoreImpl::WasResized(JNIEnv* env, |
1070 const JavaParamRef<jobject>& obj) { | 1086 const JavaParamRef<jobject>& obj) { |
1071 gfx::Size physical_size( | 1087 gfx::Size physical_size( |
1072 Java_ContentViewCore_getPhysicalBackingWidthPix(env, obj), | 1088 Java_ContentViewCore_getPhysicalBackingWidthPix(env, obj), |
1073 Java_ContentViewCore_getPhysicalBackingHeightPix(env, obj)); | 1089 Java_ContentViewCore_getPhysicalBackingHeightPix(env, obj)); |
1074 GetViewAndroid()->GetLayer()->SetBounds(physical_size); | 1090 GetViewAndroid()->GetLayer()->SetBounds(physical_size); |
1075 | 1091 |
1076 SendScreenRectsAndResizeWidget(); | 1092 SendScreenRectsAndResizeWidget(); |
1077 } | 1093 } |
1078 | 1094 |
| 1095 long ContentViewCoreImpl::GetNativeImeAdapter( |
| 1096 JNIEnv* env, |
| 1097 const JavaParamRef<jobject>& obj) { |
| 1098 RenderWidgetHostViewAndroid* rwhva = GetRenderWidgetHostViewAndroid(); |
| 1099 if (!rwhva) |
| 1100 return 0; |
| 1101 return rwhva->GetNativeImeAdapter(); |
| 1102 } |
| 1103 |
| 1104 void ContentViewCoreImpl::ForceUpdateImeAdapter(long native_ime_adapter) { |
| 1105 JNIEnv* env = AttachCurrentThread(); |
| 1106 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); |
| 1107 if (obj.is_null()) |
| 1108 return; |
| 1109 Java_ContentViewCore_forceUpdateImeAdapter(env, obj, native_ime_adapter); |
| 1110 } |
| 1111 |
| 1112 void ContentViewCoreImpl::UpdateImeAdapter(long native_ime_adapter, |
| 1113 int text_input_type, |
| 1114 int text_input_flags, |
| 1115 int text_input_mode, |
| 1116 const std::string& text, |
| 1117 int selection_start, |
| 1118 int selection_end, |
| 1119 int composition_start, |
| 1120 int composition_end, |
| 1121 bool show_ime_if_needed, |
| 1122 bool reply_to_request) { |
| 1123 JNIEnv* env = AttachCurrentThread(); |
| 1124 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); |
| 1125 if (obj.is_null()) |
| 1126 return; |
| 1127 |
| 1128 ScopedJavaLocalRef<jstring> jstring_text = ConvertUTF8ToJavaString(env, text); |
| 1129 Java_ContentViewCore_updateImeAdapter( |
| 1130 env, obj, native_ime_adapter, text_input_type, text_input_flags, |
| 1131 text_input_mode, jstring_text, selection_start, selection_end, |
| 1132 composition_start, composition_end, show_ime_if_needed, reply_to_request); |
| 1133 } |
| 1134 |
1079 void ContentViewCoreImpl::SetAccessibilityEnabled( | 1135 void ContentViewCoreImpl::SetAccessibilityEnabled( |
1080 JNIEnv* env, | 1136 JNIEnv* env, |
1081 const JavaParamRef<jobject>& obj, | 1137 const JavaParamRef<jobject>& obj, |
1082 bool enabled) { | 1138 bool enabled) { |
1083 SetAccessibilityEnabledInternal(enabled); | 1139 SetAccessibilityEnabledInternal(enabled); |
1084 } | 1140 } |
1085 | 1141 |
1086 void ContentViewCoreImpl::SetTextTrackSettings( | 1142 void ContentViewCoreImpl::SetTextTrackSettings( |
1087 JNIEnv* env, | 1143 JNIEnv* env, |
1088 const JavaParamRef<jobject>& obj, | 1144 const JavaParamRef<jobject>& obj, |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1273 DCHECK(wcva); | 1329 DCHECK(wcva); |
1274 wcva->SetContentViewCore(NULL); | 1330 wcva->SetContentViewCore(NULL); |
1275 } | 1331 } |
1276 | 1332 |
1277 // This is called for each ContentView. | 1333 // This is called for each ContentView. |
1278 jlong Init(JNIEnv* env, | 1334 jlong Init(JNIEnv* env, |
1279 const JavaParamRef<jobject>& obj, | 1335 const JavaParamRef<jobject>& obj, |
1280 const JavaParamRef<jobject>& jweb_contents, | 1336 const JavaParamRef<jobject>& jweb_contents, |
1281 const JavaParamRef<jobject>& jview_android_delegate, | 1337 const JavaParamRef<jobject>& jview_android_delegate, |
1282 jlong jwindow_android, | 1338 jlong jwindow_android, |
1283 jfloat dip_scale, | 1339 jfloat dipScale, |
1284 const JavaParamRef<jobject>& retained_objects_set) { | 1340 const JavaParamRef<jobject>& retained_objects_set) { |
1285 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>( | 1341 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>( |
1286 WebContents::FromJavaWebContents(jweb_contents)); | 1342 WebContents::FromJavaWebContents(jweb_contents)); |
1287 CHECK(web_contents) << | 1343 CHECK(web_contents) << |
1288 "A ContentViewCoreImpl should be created with a valid WebContents."; | 1344 "A ContentViewCoreImpl should be created with a valid WebContents."; |
1289 ui::ViewAndroid* view_android = web_contents->GetView()->GetNativeView(); | 1345 ui::ViewAndroid* view_android = web_contents->GetView()->GetNativeView(); |
1290 view_android->SetDelegate(jview_android_delegate); | 1346 view_android->SetDelegate(jview_android_delegate); |
1291 view_android->SetLayout(ui::ViewAndroid::LayoutParams::MatchParent()); | 1347 view_android->SetLayout(ui::ViewAndroid::LayoutParams::MatchParent()); |
1292 | 1348 |
1293 ui::WindowAndroid* window_android = | 1349 ui::WindowAndroid* window_android = |
1294 reinterpret_cast<ui::WindowAndroid*>(jwindow_android); | 1350 reinterpret_cast<ui::WindowAndroid*>(jwindow_android); |
1295 DCHECK(window_android); | 1351 DCHECK(window_android); |
1296 window_android->AddChild(view_android); | 1352 window_android->AddChild(view_android); |
1297 | 1353 |
| 1354 // TODO: pass dipScale. |
1298 ContentViewCoreImpl* view = new ContentViewCoreImpl( | 1355 ContentViewCoreImpl* view = new ContentViewCoreImpl( |
1299 env, obj, web_contents, dip_scale, retained_objects_set); | 1356 env, obj, web_contents, dipScale, retained_objects_set); |
1300 return reinterpret_cast<intptr_t>(view); | 1357 return reinterpret_cast<intptr_t>(view); |
1301 } | 1358 } |
1302 | 1359 |
1303 static ScopedJavaLocalRef<jobject> FromWebContentsAndroid( | 1360 static ScopedJavaLocalRef<jobject> FromWebContentsAndroid( |
1304 JNIEnv* env, | 1361 JNIEnv* env, |
1305 const JavaParamRef<jclass>& clazz, | 1362 const JavaParamRef<jclass>& clazz, |
1306 const JavaParamRef<jobject>& jweb_contents) { | 1363 const JavaParamRef<jobject>& jweb_contents) { |
1307 WebContents* web_contents = WebContents::FromJavaWebContents(jweb_contents); | 1364 WebContents* web_contents = WebContents::FromJavaWebContents(jweb_contents); |
1308 if (!web_contents) | 1365 if (!web_contents) |
1309 return ScopedJavaLocalRef<jobject>(); | 1366 return ScopedJavaLocalRef<jobject>(); |
1310 | 1367 |
1311 ContentViewCore* view = ContentViewCore::FromWebContents(web_contents); | 1368 ContentViewCore* view = ContentViewCore::FromWebContents(web_contents); |
1312 if (!view) | 1369 if (!view) |
1313 return ScopedJavaLocalRef<jobject>(); | 1370 return ScopedJavaLocalRef<jobject>(); |
1314 | 1371 |
1315 return view->GetJavaObject(); | 1372 return view->GetJavaObject(); |
1316 } | 1373 } |
1317 | 1374 |
1318 bool RegisterContentViewCore(JNIEnv* env) { | 1375 bool RegisterContentViewCore(JNIEnv* env) { |
1319 return RegisterNativesImpl(env); | 1376 return RegisterNativesImpl(env); |
1320 } | 1377 } |
1321 | 1378 |
1322 } // namespace content | 1379 } // namespace content |
OLD | NEW |