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 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 const JavaRef<jobject>& java_bridge_retained_object_set) | 212 const JavaRef<jobject>& java_bridge_retained_object_set) |
| 213 : WebContentsObserver(web_contents), | 213 : WebContentsObserver(web_contents), |
| 214 java_ref_(env, obj), | 214 java_ref_(env, obj), |
| 215 view_(view_android_delegate), | 215 view_(view_android_delegate), |
| 216 web_contents_(static_cast<WebContentsImpl*>(web_contents)), | 216 web_contents_(static_cast<WebContentsImpl*>(web_contents)), |
| 217 page_scale_(1), | 217 page_scale_(1), |
| 218 dpi_scale_(ui::GetScaleFactorForNativeView(&view_)), | 218 dpi_scale_(1), |
|
boliu
2016/10/18 00:26:25
why is this change needed?
Tima Vaisburd
2016/10/19 01:15:54
It is actually not needed, but I wanted to make it
| |
| 219 device_orientation_(0), | 219 device_orientation_(0), |
| 220 accessibility_enabled_(false) { | 220 accessibility_enabled_(false) { |
| 221 CHECK(web_contents) << | 221 CHECK(web_contents) << |
| 222 "A ContentViewCoreImpl should be created with a valid WebContents."; | 222 "A ContentViewCoreImpl should be created with a valid WebContents."; |
| 223 DCHECK(window_android); | 223 DCHECK(window_android); |
| 224 DCHECK(!view_android_delegate.is_null()); | 224 DCHECK(!view_android_delegate.is_null()); |
| 225 window_android->AddChild(&view_); | 225 window_android->AddChild(&view_); |
| 226 view_.SetLayer(cc::Layer::Create()); | 226 view_.SetLayer(cc::Layer::Create()); |
| 227 gfx::Size physical_size( | 227 gfx::Size physical_size( |
| 228 Java_ContentViewCore_getPhysicalBackingWidthPix(env, obj), | 228 Java_ContentViewCore_getPhysicalBackingWidthPix(env, obj), |
| (...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 796 } | 796 } |
| 797 | 797 |
| 798 float ContentViewCoreImpl::GetTopControlsHeightDip() const { | 798 float ContentViewCoreImpl::GetTopControlsHeightDip() const { |
| 799 return GetTopControlsHeightPix() / dpi_scale(); | 799 return GetTopControlsHeightPix() / dpi_scale(); |
| 800 } | 800 } |
| 801 | 801 |
| 802 float ContentViewCoreImpl::GetBottomControlsHeightDip() const { | 802 float ContentViewCoreImpl::GetBottomControlsHeightDip() const { |
| 803 return GetBottomControlsHeightPix() / dpi_scale(); | 803 return GetBottomControlsHeightPix() / dpi_scale(); |
| 804 } | 804 } |
| 805 | 805 |
| 806 void ContentViewCoreImpl::ForceLayout() { | |
|
boliu
2016/10/18 00:26:25
just call this "WasResized"?
Tima Vaisburd
2016/10/19 01:15:54
WasResized() already existed, now it sets the phys
| |
| 807 RenderWidgetHostViewAndroid* view = GetRenderWidgetHostViewAndroid(); | |
| 808 if (view) { | |
| 809 // |SendScreenRects()| indirectly calls GetViewSize() that asks Java layer. | |
| 810 web_contents_->SendScreenRects(); | |
| 811 view->WasResized(); | |
| 812 } | |
| 813 } | |
| 814 | |
| 806 void ContentViewCoreImpl::MoveRangeSelectionExtent(const gfx::PointF& extent) { | 815 void ContentViewCoreImpl::MoveRangeSelectionExtent(const gfx::PointF& extent) { |
| 807 if (!web_contents_) | 816 if (!web_contents_) |
| 808 return; | 817 return; |
| 809 | 818 |
| 810 web_contents_->MoveRangeSelectionExtent(gfx::ToRoundedPoint(extent)); | 819 web_contents_->MoveRangeSelectionExtent(gfx::ToRoundedPoint(extent)); |
| 811 } | 820 } |
| 812 | 821 |
| 813 void ContentViewCoreImpl::SelectBetweenCoordinates(const gfx::PointF& base, | 822 void ContentViewCoreImpl::SelectBetweenCoordinates(const gfx::PointF& base, |
| 814 const gfx::PointF& extent) { | 823 const gfx::PointF& extent) { |
| 815 if (!web_contents_) | 824 if (!web_contents_) |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 861 WebContents* ContentViewCoreImpl::GetWebContents() const { | 870 WebContents* ContentViewCoreImpl::GetWebContents() const { |
| 862 return web_contents_; | 871 return web_contents_; |
| 863 } | 872 } |
| 864 | 873 |
| 865 void ContentViewCoreImpl::SetFocus(JNIEnv* env, | 874 void ContentViewCoreImpl::SetFocus(JNIEnv* env, |
| 866 const JavaParamRef<jobject>& obj, | 875 const JavaParamRef<jobject>& obj, |
| 867 jboolean focused) { | 876 jboolean focused) { |
| 868 SetFocusInternal(focused); | 877 SetFocusInternal(focused); |
| 869 } | 878 } |
| 870 | 879 |
| 880 void ContentViewCoreImpl::SetDIPScale(JNIEnv* env, | |
| 881 const JavaParamRef<jobject>& obj, | |
| 882 jfloat dipScale, | |
| 883 jboolean forceLayout) { | |
| 884 dpi_scale_ = dipScale; | |
| 885 if (forceLayout) | |
| 886 ForceLayout(); | |
| 887 } | |
| 888 | |
| 871 void ContentViewCoreImpl::SetFocusInternal(bool focused) { | 889 void ContentViewCoreImpl::SetFocusInternal(bool focused) { |
| 872 if (!GetRenderWidgetHostViewAndroid()) | 890 if (!GetRenderWidgetHostViewAndroid()) |
| 873 return; | 891 return; |
| 874 | 892 |
| 875 if (focused) | 893 if (focused) |
| 876 GetRenderWidgetHostViewAndroid()->Focus(); | 894 GetRenderWidgetHostViewAndroid()->Focus(); |
| 877 else | 895 else |
| 878 GetRenderWidgetHostViewAndroid()->Blur(); | 896 GetRenderWidgetHostViewAndroid()->Blur(); |
| 879 } | 897 } |
| 880 | 898 |
| (...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1229 void ContentViewCoreImpl::RemoveJavascriptInterface( | 1247 void ContentViewCoreImpl::RemoveJavascriptInterface( |
| 1230 JNIEnv* env, | 1248 JNIEnv* env, |
| 1231 const JavaParamRef<jobject>& /* obj */, | 1249 const JavaParamRef<jobject>& /* obj */, |
| 1232 const JavaParamRef<jstring>& name) { | 1250 const JavaParamRef<jstring>& name) { |
| 1233 java_bridge_dispatcher_host_->RemoveNamedObject( | 1251 java_bridge_dispatcher_host_->RemoveNamedObject( |
| 1234 ConvertJavaStringToUTF8(env, name)); | 1252 ConvertJavaStringToUTF8(env, name)); |
| 1235 } | 1253 } |
| 1236 | 1254 |
| 1237 void ContentViewCoreImpl::WasResized(JNIEnv* env, | 1255 void ContentViewCoreImpl::WasResized(JNIEnv* env, |
| 1238 const JavaParamRef<jobject>& obj) { | 1256 const JavaParamRef<jobject>& obj) { |
| 1239 RenderWidgetHostViewAndroid* view = GetRenderWidgetHostViewAndroid(); | |
| 1240 gfx::Size physical_size( | 1257 gfx::Size physical_size( |
| 1241 Java_ContentViewCore_getPhysicalBackingWidthPix(env, obj), | 1258 Java_ContentViewCore_getPhysicalBackingWidthPix(env, obj), |
| 1242 Java_ContentViewCore_getPhysicalBackingHeightPix(env, obj)); | 1259 Java_ContentViewCore_getPhysicalBackingHeightPix(env, obj)); |
| 1243 view_.GetLayer()->SetBounds(physical_size); | 1260 view_.GetLayer()->SetBounds(physical_size); |
| 1244 | 1261 |
| 1245 if (view) { | 1262 ForceLayout(); |
| 1246 web_contents_->SendScreenRects(); | |
| 1247 view->WasResized(); | |
| 1248 } | |
| 1249 } | 1263 } |
| 1250 | 1264 |
| 1251 long ContentViewCoreImpl::GetNativeImeAdapter( | 1265 long ContentViewCoreImpl::GetNativeImeAdapter( |
| 1252 JNIEnv* env, | 1266 JNIEnv* env, |
| 1253 const JavaParamRef<jobject>& obj) { | 1267 const JavaParamRef<jobject>& obj) { |
| 1254 RenderWidgetHostViewAndroid* rwhva = GetRenderWidgetHostViewAndroid(); | 1268 RenderWidgetHostViewAndroid* rwhva = GetRenderWidgetHostViewAndroid(); |
| 1255 if (!rwhva) | 1269 if (!rwhva) |
| 1256 return 0; | 1270 return 0; |
| 1257 return rwhva->GetNativeImeAdapter(); | 1271 return rwhva->GetNativeImeAdapter(); |
| 1258 } | 1272 } |
| (...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1577 return ScopedJavaLocalRef<jobject>(); | 1591 return ScopedJavaLocalRef<jobject>(); |
| 1578 | 1592 |
| 1579 return view->GetJavaObject(); | 1593 return view->GetJavaObject(); |
| 1580 } | 1594 } |
| 1581 | 1595 |
| 1582 bool RegisterContentViewCore(JNIEnv* env) { | 1596 bool RegisterContentViewCore(JNIEnv* env) { |
| 1583 return RegisterNativesImpl(env); | 1597 return RegisterNativesImpl(env); |
| 1584 } | 1598 } |
| 1585 | 1599 |
| 1586 } // namespace content | 1600 } // namespace content |
| OLD | NEW |