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, | |
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) { | |
boliu
2016/10/19 20:49:07
nit: general pattern is write it as an early out
i
Tima Vaisburd
2016/10/25 01:51:43
Done.
| |
885 dpi_scale_ = dpi_scale; | |
886 SendScreenRectsAndResizeWidget(); | |
887 } | |
888 } | |
889 | |
871 void ContentViewCoreImpl::SetFocusInternal(bool focused) { | 890 void ContentViewCoreImpl::SetFocusInternal(bool focused) { |
872 if (!GetRenderWidgetHostViewAndroid()) | 891 if (!GetRenderWidgetHostViewAndroid()) |
873 return; | 892 return; |
874 | 893 |
875 if (focused) | 894 if (focused) |
876 GetRenderWidgetHostViewAndroid()->Focus(); | 895 GetRenderWidgetHostViewAndroid()->Focus(); |
877 else | 896 else |
878 GetRenderWidgetHostViewAndroid()->Blur(); | 897 GetRenderWidgetHostViewAndroid()->Blur(); |
879 } | 898 } |
880 | 899 |
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1229 void ContentViewCoreImpl::RemoveJavascriptInterface( | 1248 void ContentViewCoreImpl::RemoveJavascriptInterface( |
1230 JNIEnv* env, | 1249 JNIEnv* env, |
1231 const JavaParamRef<jobject>& /* obj */, | 1250 const JavaParamRef<jobject>& /* obj */, |
1232 const JavaParamRef<jstring>& name) { | 1251 const JavaParamRef<jstring>& name) { |
1233 java_bridge_dispatcher_host_->RemoveNamedObject( | 1252 java_bridge_dispatcher_host_->RemoveNamedObject( |
1234 ConvertJavaStringToUTF8(env, name)); | 1253 ConvertJavaStringToUTF8(env, name)); |
1235 } | 1254 } |
1236 | 1255 |
1237 void ContentViewCoreImpl::WasResized(JNIEnv* env, | 1256 void ContentViewCoreImpl::WasResized(JNIEnv* env, |
1238 const JavaParamRef<jobject>& obj) { | 1257 const JavaParamRef<jobject>& obj) { |
1239 RenderWidgetHostViewAndroid* view = GetRenderWidgetHostViewAndroid(); | |
1240 gfx::Size physical_size( | 1258 gfx::Size physical_size( |
1241 Java_ContentViewCore_getPhysicalBackingWidthPix(env, obj), | 1259 Java_ContentViewCore_getPhysicalBackingWidthPix(env, obj), |
1242 Java_ContentViewCore_getPhysicalBackingHeightPix(env, obj)); | 1260 Java_ContentViewCore_getPhysicalBackingHeightPix(env, obj)); |
1243 view_.GetLayer()->SetBounds(physical_size); | 1261 view_.GetLayer()->SetBounds(physical_size); |
1244 | 1262 |
1245 if (view) { | 1263 SendScreenRectsAndResizeWidget(); |
1246 web_contents_->SendScreenRects(); | |
1247 view->WasResized(); | |
1248 } | |
1249 } | 1264 } |
1250 | 1265 |
1251 long ContentViewCoreImpl::GetNativeImeAdapter( | 1266 long ContentViewCoreImpl::GetNativeImeAdapter( |
1252 JNIEnv* env, | 1267 JNIEnv* env, |
1253 const JavaParamRef<jobject>& obj) { | 1268 const JavaParamRef<jobject>& obj) { |
1254 RenderWidgetHostViewAndroid* rwhva = GetRenderWidgetHostViewAndroid(); | 1269 RenderWidgetHostViewAndroid* rwhva = GetRenderWidgetHostViewAndroid(); |
1255 if (!rwhva) | 1270 if (!rwhva) |
1256 return 0; | 1271 return 0; |
1257 return rwhva->GetNativeImeAdapter(); | 1272 return rwhva->GetNativeImeAdapter(); |
1258 } | 1273 } |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1548 if (!obj.is_null()) | 1563 if (!obj.is_null()) |
1549 Java_ContentViewCore_onOverscrollRefreshReset(env, obj); | 1564 Java_ContentViewCore_onOverscrollRefreshReset(env, obj); |
1550 } | 1565 } |
1551 | 1566 |
1552 // This is called for each ContentView. | 1567 // This is called for each ContentView. |
1553 jlong Init(JNIEnv* env, | 1568 jlong Init(JNIEnv* env, |
1554 const JavaParamRef<jobject>& obj, | 1569 const JavaParamRef<jobject>& obj, |
1555 const JavaParamRef<jobject>& web_contents, | 1570 const JavaParamRef<jobject>& web_contents, |
1556 const JavaParamRef<jobject>& view_android_delegate, | 1571 const JavaParamRef<jobject>& view_android_delegate, |
1557 jlong window_android, | 1572 jlong window_android, |
1573 jfloat dipScale, | |
1558 const JavaParamRef<jobject>& retained_objects_set) { | 1574 const JavaParamRef<jobject>& retained_objects_set) { |
1559 ContentViewCoreImpl* view = new ContentViewCoreImpl( | 1575 ContentViewCoreImpl* view = new ContentViewCoreImpl( |
1560 env, obj, WebContents::FromJavaWebContents(web_contents), | 1576 env, obj, WebContents::FromJavaWebContents(web_contents), |
1561 view_android_delegate, | 1577 view_android_delegate, |
1562 reinterpret_cast<ui::WindowAndroid*>(window_android), | 1578 reinterpret_cast<ui::WindowAndroid*>(window_android), dipScale, |
1563 retained_objects_set); | 1579 retained_objects_set); |
1564 return reinterpret_cast<intptr_t>(view); | 1580 return reinterpret_cast<intptr_t>(view); |
1565 } | 1581 } |
1566 | 1582 |
1567 static ScopedJavaLocalRef<jobject> FromWebContentsAndroid( | 1583 static ScopedJavaLocalRef<jobject> FromWebContentsAndroid( |
1568 JNIEnv* env, | 1584 JNIEnv* env, |
1569 const JavaParamRef<jclass>& clazz, | 1585 const JavaParamRef<jclass>& clazz, |
1570 const JavaParamRef<jobject>& jweb_contents) { | 1586 const JavaParamRef<jobject>& jweb_contents) { |
1571 WebContents* web_contents = WebContents::FromJavaWebContents(jweb_contents); | 1587 WebContents* web_contents = WebContents::FromJavaWebContents(jweb_contents); |
1572 if (!web_contents) | 1588 if (!web_contents) |
1573 return ScopedJavaLocalRef<jobject>(); | 1589 return ScopedJavaLocalRef<jobject>(); |
1574 | 1590 |
1575 ContentViewCore* view = ContentViewCore::FromWebContents(web_contents); | 1591 ContentViewCore* view = ContentViewCore::FromWebContents(web_contents); |
1576 if (!view) | 1592 if (!view) |
1577 return ScopedJavaLocalRef<jobject>(); | 1593 return ScopedJavaLocalRef<jobject>(); |
1578 | 1594 |
1579 return view->GetJavaObject(); | 1595 return view->GetJavaObject(); |
1580 } | 1596 } |
1581 | 1597 |
1582 bool RegisterContentViewCore(JNIEnv* env) { | 1598 bool RegisterContentViewCore(JNIEnv* env) { |
1583 return RegisterNativesImpl(env); | 1599 return RegisterNativesImpl(env); |
1584 } | 1600 } |
1585 | 1601 |
1586 } // namespace content | 1602 } // namespace content |
OLD | NEW |