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

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

Issue 2502763003: Introduce ViewRoot to forward input/view events to native (Closed)
Patch Set: addressed comments Created 4 years 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 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 WebContents* web_contents, 222 WebContents* web_contents,
223 float dpi_scale, 223 float dpi_scale,
224 const JavaRef<jobject>& java_bridge_retained_object_set) 224 const JavaRef<jobject>& java_bridge_retained_object_set)
225 : WebContentsObserver(web_contents), 225 : WebContentsObserver(web_contents),
226 java_ref_(env, obj), 226 java_ref_(env, obj),
227 web_contents_(static_cast<WebContentsImpl*>(web_contents)), 227 web_contents_(static_cast<WebContentsImpl*>(web_contents)),
228 page_scale_(1), 228 page_scale_(1),
229 dpi_scale_(dpi_scale), 229 dpi_scale_(dpi_scale),
230 device_orientation_(0), 230 device_orientation_(0),
231 accessibility_enabled_(false) { 231 accessibility_enabled_(false) {
232 GetViewAndroid()->SetLayer(cc::Layer::Create());
233 gfx::Size physical_size(
234 Java_ContentViewCore_getPhysicalBackingWidthPix(env, obj),
235 Java_ContentViewCore_getPhysicalBackingHeightPix(env, obj));
236 GetViewAndroid()->GetLayer()->SetBounds(physical_size);
237
238 // Currently, the only use case we have for overriding a user agent involves 232 // Currently, the only use case we have for overriding a user agent involves
239 // spoofing a desktop Linux user agent for "Request desktop site". 233 // spoofing a desktop Linux user agent for "Request desktop site".
240 // Automatically set it for all WebContents so that it is available when a 234 // Automatically set it for all WebContents so that it is available when a
241 // NavigationEntry requires the user agent to be overridden. 235 // NavigationEntry requires the user agent to be overridden.
242 const char kLinuxInfoStr[] = "X11; Linux x86_64"; 236 const char kLinuxInfoStr[] = "X11; Linux x86_64";
243 std::string product = content::GetContentClient()->GetProduct(); 237 std::string product = content::GetContentClient()->GetProduct();
244 std::string spoofed_ua = 238 std::string spoofed_ua =
245 BuildUserAgentFromOSAndProduct(kLinuxInfoStr, product); 239 BuildUserAgentFromOSAndProduct(kLinuxInfoStr, product);
246 web_contents->SetUserAgentOverride(spoofed_ua); 240 web_contents->SetUserAgentOverride(spoofed_ua);
247 241
(...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after
727 return size_dip; 721 return size_dip;
728 } 722 }
729 723
730 gfx::Size ContentViewCoreImpl::GetViewSize() const { 724 gfx::Size ContentViewCoreImpl::GetViewSize() const {
731 gfx::Size size = GetViewportSizeDip(); 725 gfx::Size size = GetViewportSizeDip();
732 if (DoBrowserControlsShrinkBlinkSize()) 726 if (DoBrowserControlsShrinkBlinkSize())
733 size.Enlarge(0, -GetTopControlsHeightDip() - GetBottomControlsHeightDip()); 727 size.Enlarge(0, -GetTopControlsHeightDip() - GetBottomControlsHeightDip());
734 return size; 728 return size;
735 } 729 }
736 730
737 gfx::Size ContentViewCoreImpl::GetPhysicalBackingSize() const {
738 JNIEnv* env = AttachCurrentThread();
739 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env);
740 if (j_obj.is_null())
741 return gfx::Size();
742 return gfx::Size(
743 Java_ContentViewCore_getPhysicalBackingWidthPix(env, j_obj),
744 Java_ContentViewCore_getPhysicalBackingHeightPix(env, j_obj));
745 }
746
747 gfx::Size ContentViewCoreImpl::GetViewportSizePix() const { 731 gfx::Size ContentViewCoreImpl::GetViewportSizePix() const {
748 JNIEnv* env = AttachCurrentThread(); 732 JNIEnv* env = AttachCurrentThread();
749 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); 733 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env);
750 if (j_obj.is_null()) 734 if (j_obj.is_null())
751 return gfx::Size(); 735 return gfx::Size();
752 return gfx::Size(Java_ContentViewCore_getViewportWidthPix(env, j_obj), 736 return gfx::Size(Java_ContentViewCore_getViewportWidthPix(env, j_obj),
753 Java_ContentViewCore_getViewportHeightPix(env, j_obj)); 737 Java_ContentViewCore_getViewportHeightPix(env, j_obj));
754 } 738 }
755 739
756 int ContentViewCoreImpl::GetTopControlsHeightPix() const { 740 int ContentViewCoreImpl::GetTopControlsHeightPix() const {
(...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after
1259 void ContentViewCoreImpl::RemoveJavascriptInterface( 1243 void ContentViewCoreImpl::RemoveJavascriptInterface(
1260 JNIEnv* env, 1244 JNIEnv* env,
1261 const JavaParamRef<jobject>& /* obj */, 1245 const JavaParamRef<jobject>& /* obj */,
1262 const JavaParamRef<jstring>& name) { 1246 const JavaParamRef<jstring>& name) {
1263 java_bridge_dispatcher_host_->RemoveNamedObject( 1247 java_bridge_dispatcher_host_->RemoveNamedObject(
1264 ConvertJavaStringToUTF8(env, name)); 1248 ConvertJavaStringToUTF8(env, name));
1265 } 1249 }
1266 1250
1267 void ContentViewCoreImpl::WasResized(JNIEnv* env, 1251 void ContentViewCoreImpl::WasResized(JNIEnv* env,
1268 const JavaParamRef<jobject>& obj) { 1252 const JavaParamRef<jobject>& obj) {
1269 gfx::Size physical_size(
1270 Java_ContentViewCore_getPhysicalBackingWidthPix(env, obj),
1271 Java_ContentViewCore_getPhysicalBackingHeightPix(env, obj));
1272 GetViewAndroid()->GetLayer()->SetBounds(physical_size);
1273
1274 SendScreenRectsAndResizeWidget(); 1253 SendScreenRectsAndResizeWidget();
1275 } 1254 }
1276 1255
1277 long ContentViewCoreImpl::GetNativeImeAdapter( 1256 long ContentViewCoreImpl::GetNativeImeAdapter(
1278 JNIEnv* env, 1257 JNIEnv* env,
1279 const JavaParamRef<jobject>& obj) { 1258 const JavaParamRef<jobject>& obj) {
1280 RenderWidgetHostViewAndroid* rwhva = GetRenderWidgetHostViewAndroid(); 1259 RenderWidgetHostViewAndroid* rwhva = GetRenderWidgetHostViewAndroid();
1281 if (!rwhva) 1260 if (!rwhva)
1282 return 0; 1261 return 0;
1283 return rwhva->GetNativeImeAdapter(); 1262 return rwhva->GetNativeImeAdapter();
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
1583 const JavaParamRef<jobject>& jview_android_delegate, 1562 const JavaParamRef<jobject>& jview_android_delegate,
1584 jlong jwindow_android, 1563 jlong jwindow_android,
1585 jfloat dipScale, 1564 jfloat dipScale,
1586 const JavaParamRef<jobject>& retained_objects_set) { 1565 const JavaParamRef<jobject>& retained_objects_set) {
1587 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>( 1566 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>(
1588 WebContents::FromJavaWebContents(jweb_contents)); 1567 WebContents::FromJavaWebContents(jweb_contents));
1589 CHECK(web_contents) << 1568 CHECK(web_contents) <<
1590 "A ContentViewCoreImpl should be created with a valid WebContents."; 1569 "A ContentViewCoreImpl should be created with a valid WebContents.";
1591 ui::ViewAndroid* view_android = web_contents->GetView()->GetNativeView(); 1570 ui::ViewAndroid* view_android = web_contents->GetView()->GetNativeView();
1592 view_android->SetDelegate(jview_android_delegate); 1571 view_android->SetDelegate(jview_android_delegate);
1572 view_android->SetLayer(cc::Layer::Create());
boliu 2016/12/08 05:01:06 if this ViewAndroid didn't have a layer, then don'
Jinsuk Kim 2016/12/13 23:20:38 Yes you did, and this was my reply : "Yes, also th
boliu 2016/12/13 23:50:41 Ohh, didn't notice it's moved. That's fine then
1593 1573
1594 ui::WindowAndroid* window_android = 1574 ui::WindowAndroid* window_android =
1595 reinterpret_cast<ui::WindowAndroid*>(jwindow_android); 1575 reinterpret_cast<ui::WindowAndroid*>(jwindow_android);
1596 DCHECK(window_android); 1576 DCHECK(window_android);
1597 window_android->AddChild(view_android); 1577 window_android->AddChild(view_android);
1598 1578
1599 // TODO: pass dipScale. 1579 // TODO: pass dipScale.
1600 ContentViewCoreImpl* view = new ContentViewCoreImpl( 1580 ContentViewCoreImpl* view = new ContentViewCoreImpl(
1601 env, obj, web_contents, dipScale, retained_objects_set); 1581 env, obj, web_contents, dipScale, retained_objects_set);
1602 return reinterpret_cast<intptr_t>(view); 1582 return reinterpret_cast<intptr_t>(view);
(...skipping 12 matching lines...) Expand all
1615 return ScopedJavaLocalRef<jobject>(); 1595 return ScopedJavaLocalRef<jobject>();
1616 1596
1617 return view->GetJavaObject(); 1597 return view->GetJavaObject();
1618 } 1598 }
1619 1599
1620 bool RegisterContentViewCore(JNIEnv* env) { 1600 bool RegisterContentViewCore(JNIEnv* env) {
1621 return RegisterNativesImpl(env); 1601 return RegisterNativesImpl(env);
1622 } 1602 }
1623 1603
1624 } // namespace content 1604 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698