Chromium Code Reviews| 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 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 202 content::WebContents* web_contents) { | 202 content::WebContents* web_contents) { |
| 203 return ContentViewCoreImpl::FromWebContents(web_contents); | 203 return ContentViewCoreImpl::FromWebContents(web_contents); |
| 204 } | 204 } |
| 205 | 205 |
| 206 ContentViewCoreImpl::ContentViewCoreImpl( | 206 ContentViewCoreImpl::ContentViewCoreImpl( |
| 207 JNIEnv* env, | 207 JNIEnv* env, |
| 208 const JavaRef<jobject>& obj, | 208 const JavaRef<jobject>& obj, |
| 209 WebContents* web_contents, | 209 WebContents* web_contents, |
| 210 const JavaRef<jobject>& view_android_delegate, | 210 const JavaRef<jobject>& view_android_delegate, |
| 211 ui::WindowAndroid* window_android, | 211 ui::WindowAndroid* window_android, |
| 212 float dpi_scale, | |
|
Ted C
2016/10/31 20:02:40
since we're here, is this supposed to be dpi or di
Tima Vaisburd
2016/10/31 20:37:59
I wanted it to be dip (for Device Independent Pixe
Ted C
2016/11/01 17:07:16
Hmm...it does seem to be used all over this class
Tima Vaisburd
2016/11/01 18:23:26
Let's have a followup!
| |
| 212 const JavaRef<jobject>& java_bridge_retained_object_set) | 213 const JavaRef<jobject>& java_bridge_retained_object_set) |
| 213 : WebContentsObserver(web_contents), | 214 : WebContentsObserver(web_contents), |
| 214 java_ref_(env, obj), | 215 java_ref_(env, obj), |
| 215 view_(view_android_delegate), | 216 view_(view_android_delegate), |
| 216 web_contents_(static_cast<WebContentsImpl*>(web_contents)), | 217 web_contents_(static_cast<WebContentsImpl*>(web_contents)), |
| 217 page_scale_(1), | 218 page_scale_(1), |
| 218 dpi_scale_(ui::GetScaleFactorForNativeView(&view_)), | 219 dpi_scale_(dpi_scale), |
| 219 device_orientation_(0), | 220 device_orientation_(0), |
| 220 accessibility_enabled_(false) { | 221 accessibility_enabled_(false) { |
| 221 CHECK(web_contents) << | 222 CHECK(web_contents) << |
| 222 "A ContentViewCoreImpl should be created with a valid WebContents."; | 223 "A ContentViewCoreImpl should be created with a valid WebContents."; |
| 223 DCHECK(window_android); | 224 DCHECK(window_android); |
| 224 DCHECK(!view_android_delegate.is_null()); | 225 DCHECK(!view_android_delegate.is_null()); |
| 225 window_android->AddChild(&view_); | 226 window_android->AddChild(&view_); |
| 226 view_.SetLayer(cc::Layer::Create()); | 227 view_.SetLayer(cc::Layer::Create()); |
| 227 gfx::Size physical_size( | 228 gfx::Size physical_size( |
| 228 Java_ContentViewCore_getPhysicalBackingWidthPix(env, obj), | 229 Java_ContentViewCore_getPhysicalBackingWidthPix(env, obj), |
| (...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 796 } | 797 } |
| 797 | 798 |
| 798 float ContentViewCoreImpl::GetTopControlsHeightDip() const { | 799 float ContentViewCoreImpl::GetTopControlsHeightDip() const { |
| 799 return GetTopControlsHeightPix() / dpi_scale(); | 800 return GetTopControlsHeightPix() / dpi_scale(); |
| 800 } | 801 } |
| 801 | 802 |
| 802 float ContentViewCoreImpl::GetBottomControlsHeightDip() const { | 803 float ContentViewCoreImpl::GetBottomControlsHeightDip() const { |
| 803 return GetBottomControlsHeightPix() / dpi_scale(); | 804 return GetBottomControlsHeightPix() / dpi_scale(); |
| 804 } | 805 } |
| 805 | 806 |
| 807 void ContentViewCoreImpl::SendScreenRectsAndResizeWidget() { | |
| 808 RenderWidgetHostViewAndroid* view = GetRenderWidgetHostViewAndroid(); | |
| 809 if (view) { | |
| 810 // |SendScreenRects()| indirectly calls GetViewSize() that asks Java layer. | |
| 811 web_contents_->SendScreenRects(); | |
| 812 view->WasResized(); | |
| 813 } | |
| 814 } | |
| 815 | |
| 806 void ContentViewCoreImpl::MoveRangeSelectionExtent(const gfx::PointF& extent) { | 816 void ContentViewCoreImpl::MoveRangeSelectionExtent(const gfx::PointF& extent) { |
| 807 if (!web_contents_) | 817 if (!web_contents_) |
| 808 return; | 818 return; |
| 809 | 819 |
| 810 web_contents_->MoveRangeSelectionExtent(gfx::ToRoundedPoint(extent)); | 820 web_contents_->MoveRangeSelectionExtent(gfx::ToRoundedPoint(extent)); |
| 811 } | 821 } |
| 812 | 822 |
| 813 void ContentViewCoreImpl::SelectBetweenCoordinates(const gfx::PointF& base, | 823 void ContentViewCoreImpl::SelectBetweenCoordinates(const gfx::PointF& base, |
| 814 const gfx::PointF& extent) { | 824 const gfx::PointF& extent) { |
| 815 if (!web_contents_) | 825 if (!web_contents_) |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 861 WebContents* ContentViewCoreImpl::GetWebContents() const { | 871 WebContents* ContentViewCoreImpl::GetWebContents() const { |
| 862 return web_contents_; | 872 return web_contents_; |
| 863 } | 873 } |
| 864 | 874 |
| 865 void ContentViewCoreImpl::SetFocus(JNIEnv* env, | 875 void ContentViewCoreImpl::SetFocus(JNIEnv* env, |
| 866 const JavaParamRef<jobject>& obj, | 876 const JavaParamRef<jobject>& obj, |
| 867 jboolean focused) { | 877 jboolean focused) { |
| 868 SetFocusInternal(focused); | 878 SetFocusInternal(focused); |
| 869 } | 879 } |
| 870 | 880 |
| 881 void ContentViewCoreImpl::SetDIPScale(JNIEnv* env, | |
| 882 const JavaParamRef<jobject>& obj, | |
| 883 jfloat dpi_scale) { | |
| 884 if (dpi_scale_ == dpi_scale) | |
| 885 return; | |
| 886 | |
| 887 dpi_scale_ = dpi_scale; | |
| 888 SendScreenRectsAndResizeWidget(); | |
| 889 } | |
| 890 | |
| 871 void ContentViewCoreImpl::SetFocusInternal(bool focused) { | 891 void ContentViewCoreImpl::SetFocusInternal(bool focused) { |
| 872 if (!GetRenderWidgetHostViewAndroid()) | 892 if (!GetRenderWidgetHostViewAndroid()) |
| 873 return; | 893 return; |
| 874 | 894 |
| 875 if (focused) | 895 if (focused) |
| 876 GetRenderWidgetHostViewAndroid()->Focus(); | 896 GetRenderWidgetHostViewAndroid()->Focus(); |
| 877 else | 897 else |
| 878 GetRenderWidgetHostViewAndroid()->Blur(); | 898 GetRenderWidgetHostViewAndroid()->Blur(); |
| 879 } | 899 } |
| 880 | 900 |
| (...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1229 void ContentViewCoreImpl::RemoveJavascriptInterface( | 1249 void ContentViewCoreImpl::RemoveJavascriptInterface( |
| 1230 JNIEnv* env, | 1250 JNIEnv* env, |
| 1231 const JavaParamRef<jobject>& /* obj */, | 1251 const JavaParamRef<jobject>& /* obj */, |
| 1232 const JavaParamRef<jstring>& name) { | 1252 const JavaParamRef<jstring>& name) { |
| 1233 java_bridge_dispatcher_host_->RemoveNamedObject( | 1253 java_bridge_dispatcher_host_->RemoveNamedObject( |
| 1234 ConvertJavaStringToUTF8(env, name)); | 1254 ConvertJavaStringToUTF8(env, name)); |
| 1235 } | 1255 } |
| 1236 | 1256 |
| 1237 void ContentViewCoreImpl::WasResized(JNIEnv* env, | 1257 void ContentViewCoreImpl::WasResized(JNIEnv* env, |
| 1238 const JavaParamRef<jobject>& obj) { | 1258 const JavaParamRef<jobject>& obj) { |
| 1239 RenderWidgetHostViewAndroid* view = GetRenderWidgetHostViewAndroid(); | |
| 1240 gfx::Size physical_size( | 1259 gfx::Size physical_size( |
| 1241 Java_ContentViewCore_getPhysicalBackingWidthPix(env, obj), | 1260 Java_ContentViewCore_getPhysicalBackingWidthPix(env, obj), |
| 1242 Java_ContentViewCore_getPhysicalBackingHeightPix(env, obj)); | 1261 Java_ContentViewCore_getPhysicalBackingHeightPix(env, obj)); |
| 1243 view_.GetLayer()->SetBounds(physical_size); | 1262 view_.GetLayer()->SetBounds(physical_size); |
| 1244 | 1263 |
| 1245 if (view) { | 1264 SendScreenRectsAndResizeWidget(); |
| 1246 web_contents_->SendScreenRects(); | |
| 1247 view->WasResized(); | |
| 1248 } | |
| 1249 } | 1265 } |
| 1250 | 1266 |
| 1251 long ContentViewCoreImpl::GetNativeImeAdapter( | 1267 long ContentViewCoreImpl::GetNativeImeAdapter( |
| 1252 JNIEnv* env, | 1268 JNIEnv* env, |
| 1253 const JavaParamRef<jobject>& obj) { | 1269 const JavaParamRef<jobject>& obj) { |
| 1254 RenderWidgetHostViewAndroid* rwhva = GetRenderWidgetHostViewAndroid(); | 1270 RenderWidgetHostViewAndroid* rwhva = GetRenderWidgetHostViewAndroid(); |
| 1255 if (!rwhva) | 1271 if (!rwhva) |
| 1256 return 0; | 1272 return 0; |
| 1257 return rwhva->GetNativeImeAdapter(); | 1273 return rwhva->GetNativeImeAdapter(); |
| 1258 } | 1274 } |
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1548 if (!obj.is_null()) | 1564 if (!obj.is_null()) |
| 1549 Java_ContentViewCore_onOverscrollRefreshReset(env, obj); | 1565 Java_ContentViewCore_onOverscrollRefreshReset(env, obj); |
| 1550 } | 1566 } |
| 1551 | 1567 |
| 1552 // This is called for each ContentView. | 1568 // This is called for each ContentView. |
| 1553 jlong Init(JNIEnv* env, | 1569 jlong Init(JNIEnv* env, |
| 1554 const JavaParamRef<jobject>& obj, | 1570 const JavaParamRef<jobject>& obj, |
| 1555 const JavaParamRef<jobject>& web_contents, | 1571 const JavaParamRef<jobject>& web_contents, |
| 1556 const JavaParamRef<jobject>& view_android_delegate, | 1572 const JavaParamRef<jobject>& view_android_delegate, |
| 1557 jlong window_android, | 1573 jlong window_android, |
| 1574 jfloat dipScale, | |
| 1558 const JavaParamRef<jobject>& retained_objects_set) { | 1575 const JavaParamRef<jobject>& retained_objects_set) { |
| 1559 ContentViewCoreImpl* view = new ContentViewCoreImpl( | 1576 ContentViewCoreImpl* view = new ContentViewCoreImpl( |
| 1560 env, obj, WebContents::FromJavaWebContents(web_contents), | 1577 env, obj, WebContents::FromJavaWebContents(web_contents), |
| 1561 view_android_delegate, | 1578 view_android_delegate, |
| 1562 reinterpret_cast<ui::WindowAndroid*>(window_android), | 1579 reinterpret_cast<ui::WindowAndroid*>(window_android), dipScale, |
| 1563 retained_objects_set); | 1580 retained_objects_set); |
| 1564 return reinterpret_cast<intptr_t>(view); | 1581 return reinterpret_cast<intptr_t>(view); |
| 1565 } | 1582 } |
| 1566 | 1583 |
| 1567 static ScopedJavaLocalRef<jobject> FromWebContentsAndroid( | 1584 static ScopedJavaLocalRef<jobject> FromWebContentsAndroid( |
| 1568 JNIEnv* env, | 1585 JNIEnv* env, |
| 1569 const JavaParamRef<jclass>& clazz, | 1586 const JavaParamRef<jclass>& clazz, |
| 1570 const JavaParamRef<jobject>& jweb_contents) { | 1587 const JavaParamRef<jobject>& jweb_contents) { |
| 1571 WebContents* web_contents = WebContents::FromJavaWebContents(jweb_contents); | 1588 WebContents* web_contents = WebContents::FromJavaWebContents(jweb_contents); |
| 1572 if (!web_contents) | 1589 if (!web_contents) |
| 1573 return ScopedJavaLocalRef<jobject>(); | 1590 return ScopedJavaLocalRef<jobject>(); |
| 1574 | 1591 |
| 1575 ContentViewCore* view = ContentViewCore::FromWebContents(web_contents); | 1592 ContentViewCore* view = ContentViewCore::FromWebContents(web_contents); |
| 1576 if (!view) | 1593 if (!view) |
| 1577 return ScopedJavaLocalRef<jobject>(); | 1594 return ScopedJavaLocalRef<jobject>(); |
| 1578 | 1595 |
| 1579 return view->GetJavaObject(); | 1596 return view->GetJavaObject(); |
| 1580 } | 1597 } |
| 1581 | 1598 |
| 1582 bool RegisterContentViewCore(JNIEnv* env) { | 1599 bool RegisterContentViewCore(JNIEnv* env) { |
| 1583 return RegisterNativesImpl(env); | 1600 return RegisterNativesImpl(env); |
| 1584 } | 1601 } |
| 1585 | 1602 |
| 1586 } // namespace content | 1603 } // namespace content |
| OLD | NEW |