Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(746)

Side by Side Diff: content/browser/android/content_view_core_impl.cc

Issue 2300463002: Add observers for DIP scale change. (Closed)
Patch Set: Rebased to master Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 // static 200 // static
201 ContentViewCore* ContentViewCore::FromWebContents( 201 ContentViewCore* ContentViewCore::FromWebContents(
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 float dpi_scale,
210 const JavaRef<jobject>& java_bridge_retained_object_set) 211 const JavaRef<jobject>& java_bridge_retained_object_set)
211 : WebContentsObserver(web_contents), 212 : WebContentsObserver(web_contents),
212 java_ref_(env, obj), 213 java_ref_(env, obj),
213 web_contents_(static_cast<WebContentsImpl*>(web_contents)), 214 web_contents_(static_cast<WebContentsImpl*>(web_contents)),
214 page_scale_(1), 215 page_scale_(1),
215 dpi_scale_(ui::GetScaleFactorForNativeView(GetViewAndroid())), 216 dpi_scale_(dpi_scale),
216 device_orientation_(0), 217 device_orientation_(0),
217 accessibility_enabled_(false) { 218 accessibility_enabled_(false) {
218 GetViewAndroid()->SetLayer(cc::Layer::Create()); 219 GetViewAndroid()->SetLayer(cc::Layer::Create());
219 gfx::Size physical_size( 220 gfx::Size physical_size(
220 Java_ContentViewCore_getPhysicalBackingWidthPix(env, obj), 221 Java_ContentViewCore_getPhysicalBackingWidthPix(env, obj),
221 Java_ContentViewCore_getPhysicalBackingHeightPix(env, obj)); 222 Java_ContentViewCore_getPhysicalBackingHeightPix(env, obj));
222 GetViewAndroid()->GetLayer()->SetBounds(physical_size); 223 GetViewAndroid()->GetLayer()->SetBounds(physical_size);
223 224
224 // Currently, the only use case we have for overriding a user agent involves 225 // Currently, the only use case we have for overriding a user agent involves
225 // spoofing a desktop Linux user agent for "Request desktop site". 226 // spoofing a desktop Linux user agent for "Request desktop site".
(...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after
779 } 780 }
780 781
781 float ContentViewCoreImpl::GetTopControlsHeightDip() const { 782 float ContentViewCoreImpl::GetTopControlsHeightDip() const {
782 return GetTopControlsHeightPix() / dpi_scale(); 783 return GetTopControlsHeightPix() / dpi_scale();
783 } 784 }
784 785
785 float ContentViewCoreImpl::GetBottomControlsHeightDip() const { 786 float ContentViewCoreImpl::GetBottomControlsHeightDip() const {
786 return GetBottomControlsHeightPix() / dpi_scale(); 787 return GetBottomControlsHeightPix() / dpi_scale();
787 } 788 }
788 789
790 void ContentViewCoreImpl::SendScreenRectsAndResizeWidget() {
791 RenderWidgetHostViewAndroid* view = GetRenderWidgetHostViewAndroid();
792 if (view) {
793 // |SendScreenRects()| indirectly calls GetViewSize() that asks Java layer.
794 web_contents_->SendScreenRects();
795 view->WasResized();
796 }
797 }
798
789 void ContentViewCoreImpl::MoveRangeSelectionExtent(const gfx::PointF& extent) { 799 void ContentViewCoreImpl::MoveRangeSelectionExtent(const gfx::PointF& extent) {
790 if (!web_contents_) 800 if (!web_contents_)
791 return; 801 return;
792 802
793 web_contents_->MoveRangeSelectionExtent(gfx::ToRoundedPoint(extent)); 803 web_contents_->MoveRangeSelectionExtent(gfx::ToRoundedPoint(extent));
794 } 804 }
795 805
796 void ContentViewCoreImpl::SelectBetweenCoordinates(const gfx::PointF& base, 806 void ContentViewCoreImpl::SelectBetweenCoordinates(const gfx::PointF& base,
797 const gfx::PointF& extent) { 807 const gfx::PointF& extent) {
798 if (!web_contents_) 808 if (!web_contents_)
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
844 WebContents* ContentViewCoreImpl::GetWebContents() const { 854 WebContents* ContentViewCoreImpl::GetWebContents() const {
845 return web_contents_; 855 return web_contents_;
846 } 856 }
847 857
848 void ContentViewCoreImpl::SetFocus(JNIEnv* env, 858 void ContentViewCoreImpl::SetFocus(JNIEnv* env,
849 const JavaParamRef<jobject>& obj, 859 const JavaParamRef<jobject>& obj,
850 jboolean focused) { 860 jboolean focused) {
851 SetFocusInternal(focused); 861 SetFocusInternal(focused);
852 } 862 }
853 863
864 void ContentViewCoreImpl::SetDIPScale(JNIEnv* env,
865 const JavaParamRef<jobject>& obj,
866 jfloat dpi_scale) {
867 if (dpi_scale_ == dpi_scale)
868 return;
869
870 dpi_scale_ = dpi_scale;
871 SendScreenRectsAndResizeWidget();
872 }
873
854 void ContentViewCoreImpl::SetFocusInternal(bool focused) { 874 void ContentViewCoreImpl::SetFocusInternal(bool focused) {
855 if (!GetRenderWidgetHostViewAndroid()) 875 if (!GetRenderWidgetHostViewAndroid())
856 return; 876 return;
857 877
858 if (focused) 878 if (focused)
859 GetRenderWidgetHostViewAndroid()->Focus(); 879 GetRenderWidgetHostViewAndroid()->Focus();
860 else 880 else
861 GetRenderWidgetHostViewAndroid()->Blur(); 881 GetRenderWidgetHostViewAndroid()->Blur();
862 } 882 }
863 883
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after
1212 void ContentViewCoreImpl::RemoveJavascriptInterface( 1232 void ContentViewCoreImpl::RemoveJavascriptInterface(
1213 JNIEnv* env, 1233 JNIEnv* env,
1214 const JavaParamRef<jobject>& /* obj */, 1234 const JavaParamRef<jobject>& /* obj */,
1215 const JavaParamRef<jstring>& name) { 1235 const JavaParamRef<jstring>& name) {
1216 java_bridge_dispatcher_host_->RemoveNamedObject( 1236 java_bridge_dispatcher_host_->RemoveNamedObject(
1217 ConvertJavaStringToUTF8(env, name)); 1237 ConvertJavaStringToUTF8(env, name));
1218 } 1238 }
1219 1239
1220 void ContentViewCoreImpl::WasResized(JNIEnv* env, 1240 void ContentViewCoreImpl::WasResized(JNIEnv* env,
1221 const JavaParamRef<jobject>& obj) { 1241 const JavaParamRef<jobject>& obj) {
1222 RenderWidgetHostViewAndroid* view = GetRenderWidgetHostViewAndroid();
1223 gfx::Size physical_size( 1242 gfx::Size physical_size(
1224 Java_ContentViewCore_getPhysicalBackingWidthPix(env, obj), 1243 Java_ContentViewCore_getPhysicalBackingWidthPix(env, obj),
1225 Java_ContentViewCore_getPhysicalBackingHeightPix(env, obj)); 1244 Java_ContentViewCore_getPhysicalBackingHeightPix(env, obj));
1226 GetViewAndroid()->GetLayer()->SetBounds(physical_size); 1245 GetViewAndroid()->GetLayer()->SetBounds(physical_size);
1227 1246
1228 if (view) { 1247 SendScreenRectsAndResizeWidget();
1229 web_contents_->SendScreenRects();
1230 view->WasResized();
1231 }
1232 } 1248 }
1233 1249
1234 long ContentViewCoreImpl::GetNativeImeAdapter( 1250 long ContentViewCoreImpl::GetNativeImeAdapter(
1235 JNIEnv* env, 1251 JNIEnv* env,
1236 const JavaParamRef<jobject>& obj) { 1252 const JavaParamRef<jobject>& obj) {
1237 RenderWidgetHostViewAndroid* rwhva = GetRenderWidgetHostViewAndroid(); 1253 RenderWidgetHostViewAndroid* rwhva = GetRenderWidgetHostViewAndroid();
1238 if (!rwhva) 1254 if (!rwhva)
1239 return 0; 1255 return 0;
1240 return rwhva->GetNativeImeAdapter(); 1256 return rwhva->GetNativeImeAdapter();
1241 } 1257 }
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
1529 if (!obj.is_null()) 1545 if (!obj.is_null())
1530 Java_ContentViewCore_onOverscrollRefreshReset(env, obj); 1546 Java_ContentViewCore_onOverscrollRefreshReset(env, obj);
1531 } 1547 }
1532 1548
1533 // This is called for each ContentView. 1549 // This is called for each ContentView.
1534 jlong Init(JNIEnv* env, 1550 jlong Init(JNIEnv* env,
1535 const JavaParamRef<jobject>& obj, 1551 const JavaParamRef<jobject>& obj,
1536 const JavaParamRef<jobject>& jweb_contents, 1552 const JavaParamRef<jobject>& jweb_contents,
1537 const JavaParamRef<jobject>& jview_android_delegate, 1553 const JavaParamRef<jobject>& jview_android_delegate,
1538 jlong jwindow_android, 1554 jlong jwindow_android,
1555 jfloat dipScale,
1539 const JavaParamRef<jobject>& retained_objects_set) { 1556 const JavaParamRef<jobject>& retained_objects_set) {
1540 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>( 1557 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>(
1541 WebContents::FromJavaWebContents(jweb_contents)); 1558 WebContents::FromJavaWebContents(jweb_contents));
1542 CHECK(web_contents) << 1559 CHECK(web_contents) <<
1543 "A ContentViewCoreImpl should be created with a valid WebContents."; 1560 "A ContentViewCoreImpl should be created with a valid WebContents.";
1544 ui::ViewAndroid* view_android = web_contents->GetView()->GetNativeView(); 1561 ui::ViewAndroid* view_android = web_contents->GetView()->GetNativeView();
1545 view_android->SetDelegate(jview_android_delegate); 1562 view_android->SetDelegate(jview_android_delegate);
1546 1563
1547 ui::WindowAndroid* window_android = 1564 ui::WindowAndroid* window_android =
1548 reinterpret_cast<ui::WindowAndroid*>(jwindow_android); 1565 reinterpret_cast<ui::WindowAndroid*>(jwindow_android);
1549 DCHECK(window_android); 1566 DCHECK(window_android);
1550 window_android->AddChild(view_android); 1567 window_android->AddChild(view_android);
1551 1568
1569 // TODO: pass dipScale.
1552 ContentViewCoreImpl* view = new ContentViewCoreImpl( 1570 ContentViewCoreImpl* view = new ContentViewCoreImpl(
1553 env, obj, web_contents, retained_objects_set); 1571 env, obj, web_contents, dipScale, retained_objects_set);
1554 return reinterpret_cast<intptr_t>(view); 1572 return reinterpret_cast<intptr_t>(view);
1555 } 1573 }
1556 1574
1557 static ScopedJavaLocalRef<jobject> FromWebContentsAndroid( 1575 static ScopedJavaLocalRef<jobject> FromWebContentsAndroid(
1558 JNIEnv* env, 1576 JNIEnv* env,
1559 const JavaParamRef<jclass>& clazz, 1577 const JavaParamRef<jclass>& clazz,
1560 const JavaParamRef<jobject>& jweb_contents) { 1578 const JavaParamRef<jobject>& jweb_contents) {
1561 WebContents* web_contents = WebContents::FromJavaWebContents(jweb_contents); 1579 WebContents* web_contents = WebContents::FromJavaWebContents(jweb_contents);
1562 if (!web_contents) 1580 if (!web_contents)
1563 return ScopedJavaLocalRef<jobject>(); 1581 return ScopedJavaLocalRef<jobject>();
1564 1582
1565 ContentViewCore* view = ContentViewCore::FromWebContents(web_contents); 1583 ContentViewCore* view = ContentViewCore::FromWebContents(web_contents);
1566 if (!view) 1584 if (!view)
1567 return ScopedJavaLocalRef<jobject>(); 1585 return ScopedJavaLocalRef<jobject>();
1568 1586
1569 return view->GetJavaObject(); 1587 return view->GetJavaObject();
1570 } 1588 }
1571 1589
1572 bool RegisterContentViewCore(JNIEnv* env) { 1590 bool RegisterContentViewCore(JNIEnv* env) {
1573 return RegisterNativesImpl(env); 1591 return RegisterNativesImpl(env);
1574 } 1592 }
1575 1593
1576 } // namespace content 1594 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/android/content_view_core_impl.h ('k') | content/browser/site_per_process_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698