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

Unified Diff: content/browser/android/content_view_core_impl.cc

Issue 2122403002: Android: Extend ViewAndroid (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comments Created 4 years, 5 months 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/android/content_view_core_impl.cc
diff --git a/content/browser/android/content_view_core_impl.cc b/content/browser/android/content_view_core_impl.cc
index 23708d9e4f9054cc2e2c0060204b85ad33921986..a094237d81a7755bcf415daefdc7cb90802705d1 100644
--- a/content/browser/android/content_view_core_impl.cc
+++ b/content/browser/android/content_view_core_impl.cc
@@ -212,29 +212,28 @@ ContentViewCoreImpl::ContentViewCoreImpl(
JNIEnv* env,
jobject obj,
WebContents* web_contents,
- jobject view_android_delegate,
+ const base::android::JavaRef<jobject>& view_android_delegate,
ui::WindowAndroid* window_android,
jobject java_bridge_retained_object_set)
: WebContentsObserver(web_contents),
java_ref_(env, obj),
+ view_android_(view_android_delegate, window_android),
web_contents_(static_cast<WebContentsImpl*>(web_contents)),
- root_layer_(cc::SolidColorLayer::Create()),
page_scale_(1),
- dpi_scale_(ui::GetScaleFactorForNativeView(this)),
- window_android_(window_android),
+ dpi_scale_(ui::GetScaleFactorForNativeView(&view_android_)),
device_orientation_(0),
accessibility_enabled_(false) {
CHECK(web_contents) <<
"A ContentViewCoreImpl should be created with a valid WebContents.";
- DCHECK(window_android_);
- DCHECK(view_android_delegate);
- view_android_delegate_.Reset(AttachCurrentThread(), view_android_delegate);
- root_layer_->SetBackgroundColor(GetBackgroundColor(env, obj));
+ DCHECK(window_android);
+ DCHECK(!view_android_delegate.is_null());
+ view_android_.SetLayer(cc::SolidColorLayer::Create());
+ view_android_.GetLayer()->SetBackgroundColor(GetBackgroundColor(env, obj));
gfx::Size physical_size(
Java_ContentViewCore_getPhysicalBackingWidthPix(env, obj),
Java_ContentViewCore_getPhysicalBackingHeightPix(env, obj));
- root_layer_->SetBounds(physical_size);
- root_layer_->SetIsDrawable(true);
+ view_android_.GetLayer()->SetBounds(physical_size);
+ view_android_.GetLayer()->SetIsDrawable(true);
// Currently, the only use case we have for overriding a user agent involves
// spoofing a desktop Linux user agent for "Request desktop site".
@@ -264,7 +263,7 @@ void ContentViewCoreImpl::RemoveObserver(
}
ContentViewCoreImpl::~ContentViewCoreImpl() {
- root_layer_->RemoveFromParent();
+ view_android_.GetLayer()->RemoveFromParent();
FOR_EACH_OBSERVER(ContentViewCoreImplObserver,
observer_list_,
OnContentViewCoreDestroyed());
@@ -284,8 +283,9 @@ void ContentViewCoreImpl::UpdateWindowAndroid(
const base::android::JavaParamRef<jobject>& obj,
jlong window_android) {
if (window_android) {
- DCHECK(!window_android_);
- window_android_ = reinterpret_cast<ui::WindowAndroid*>(window_android);
+ DCHECK(!view_android_.GetWindowAndroid());
+ view_android_.SetWindowAndroid(
+ reinterpret_cast<ui::WindowAndroid*>(window_android));
FOR_EACH_OBSERVER(ContentViewCoreImplObserver,
observer_list_,
OnAttachedToWindow());
@@ -293,7 +293,7 @@ void ContentViewCoreImpl::UpdateWindowAndroid(
FOR_EACH_OBSERVER(ContentViewCoreImplObserver,
observer_list_,
OnDetachedFromWindow());
- window_android_ = NULL;
+ view_android_.SetWindowAndroid(nullptr);
}
}
@@ -306,9 +306,9 @@ ContentViewCoreImpl::GetWebContentsAndroid(JNIEnv* env,
base::android::ScopedJavaLocalRef<jobject>
ContentViewCoreImpl::GetJavaWindowAndroid(JNIEnv* env,
const JavaParamRef<jobject>& obj) {
- if (!window_android_)
+ if (!view_android_.GetWindowAndroid())
return ScopedJavaLocalRef<jobject>();
- return window_android_->GetJavaObject();
+ return view_android_.GetWindowAndroid()->GetJavaObject();
}
void ContentViewCoreImpl::OnJavaContentViewCoreDestroyed(
@@ -429,10 +429,10 @@ void ContentViewCoreImpl::UpdateFrameInfo(
const gfx::SelectionBound& selection_start) {
JNIEnv* env = AttachCurrentThread();
ScopedJavaLocalRef<jobject> obj = java_ref_.get(env);
- if (obj.is_null() || !window_android_)
+ if (obj.is_null() || !view_android_.GetWindowAndroid())
return;
- window_android_->set_content_offset(
+ view_android_.GetWindowAndroid()->set_content_offset(
gfx::ScaleVector2d(content_offset, dpi_scale_));
page_scale_ = page_scale_factor;
@@ -481,7 +481,7 @@ void ContentViewCoreImpl::SetTitle(const base::string16& title) {
}
void ContentViewCoreImpl::OnBackgroundColorChanged(SkColor color) {
- root_layer_->SetBackgroundColor(color);
+ view_android_.GetLayer()->SetBackgroundColor(color);
JNIEnv* env = AttachCurrentThread();
ScopedJavaLocalRef<jobject> obj = java_ref_.get(env);
@@ -831,15 +831,15 @@ float ContentViewCoreImpl::GetTopControlsHeightDip() const {
}
void ContentViewCoreImpl::AttachLayer(scoped_refptr<cc::Layer> layer) {
- root_layer_->InsertChild(layer, 0);
- root_layer_->SetIsDrawable(false);
+ view_android_.GetLayer()->InsertChild(layer, 0);
+ view_android_.GetLayer()->SetIsDrawable(false);
}
void ContentViewCoreImpl::RemoveLayer(scoped_refptr<cc::Layer> layer) {
layer->RemoveFromParent();
- if (root_layer_->children().empty())
- root_layer_->SetIsDrawable(true);
+ if (!view_android_.GetLayer()->children().empty())
+ view_android_.GetLayer()->SetIsDrawable(true);
}
void ContentViewCoreImpl::MoveRangeSelectionExtent(const gfx::PointF& extent) {
@@ -862,19 +862,24 @@ void ContentViewCoreImpl::SelectBetweenCoordinates(const gfx::PointF& base,
web_contents_->SelectRange(base_point, extent_point);
}
-ScopedJavaLocalRef<jobject> ContentViewCoreImpl::GetViewAndroidDelegate()
- const {
- return base::android::ScopedJavaLocalRef<jobject>(view_android_delegate_);
+const base::android::JavaRef<jobject>&
+ContentViewCoreImpl::GetViewAndroidDelegate() const {
+ return view_android_.GetViewAndroidDelegate();
}
ui::WindowAndroid* ContentViewCoreImpl::GetWindowAndroid() const {
- return window_android_;
+ return view_android_.GetWindowAndroid();
}
-const scoped_refptr<cc::Layer>& ContentViewCoreImpl::GetLayer() const {
- return root_layer_;
+cc::Layer* ContentViewCoreImpl::GetLayer() const {
+ return view_android_.GetLayer();
Yusuf 2016/07/08 23:06:00 CVC and RWHVAndroid are both Android specific, we
no sievers 2016/07/08 23:24:22 True. I've made it CVC::view_ since 'android' is a
}
+ui::ViewAndroid* ContentViewCoreImpl::GetViewAndroid() {
+ return &view_android_;
+}
+
+
// ----------------------------------------------------------------------------
// Methods called from Java via JNI
// ----------------------------------------------------------------------------
@@ -1298,7 +1303,7 @@ void ContentViewCoreImpl::WasResized(JNIEnv* env,
gfx::Size physical_size(
Java_ContentViewCore_getPhysicalBackingWidthPix(env, obj),
Java_ContentViewCore_getPhysicalBackingHeightPix(env, obj));
- root_layer_->SetBounds(physical_size);
+ view_android_.GetLayer()->SetBounds(physical_size);
if (view) {
web_contents_->SendScreenRects();
@@ -1435,7 +1440,7 @@ void ContentViewCoreImpl::SetAccessibilityEnabledInternal(bool enabled) {
void ContentViewCoreImpl::SendOrientationChangeEventInternal() {
RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid();
if (rwhv)
- rwhv->UpdateScreenInfo(this);
+ rwhv->UpdateScreenInfo(&view_android_);
static_cast<WebContentsImpl*>(web_contents())->
screen_orientation_dispatcher_host()->OnOrientationChange();
« no previous file with comments | « content/browser/android/content_view_core_impl.h ('k') | content/browser/renderer_host/render_widget_host_view_android.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698