Chromium Code Reviews| Index: ui/android/view_android.cc |
| diff --git a/ui/android/view_android.cc b/ui/android/view_android.cc |
| index 6334526014b0a0450834a4ab4b2ce0189d5342f3..9cf7bf557c91c5f890c226d025b0125e0c3c7b73 100644 |
| --- a/ui/android/view_android.cc |
| +++ b/ui/android/view_android.cc |
| @@ -8,6 +8,9 @@ |
| #include "base/android/jni_android.h" |
| #include "cc/layers/layer.h" |
| +#include "jni/ViewAndroidDelegate_jni.h" |
| +#include "ui/android/window_android.h" |
| +#include "ui/gfx/android/device_display_info.h" |
| namespace ui { |
| @@ -15,12 +18,24 @@ using base::android::AttachCurrentThread; |
| using base::android::JavaRef; |
| using base::android::ScopedJavaLocalRef; |
| +ViewAndroid::ScopedAnchorView::~ScopedAnchorView() { |
| + JNIEnv* env = base::android::AttachCurrentThread(); |
| + Java_ViewAndroidDelegate_removeView(env, delegate_.obj(), view_.obj()); |
| + view_.Reset(); |
| +} |
| + |
| ViewAndroid::ViewAndroid(const JavaRef<jobject>& delegate, |
| WindowAndroid* root_window) |
| - : parent_(nullptr), window_(root_window), delegate_(delegate) {} |
| + : parent_(nullptr) |
| + , window_(root_window) |
| + , delegate_(delegate) {} |
| ViewAndroid::ViewAndroid() : parent_(nullptr), window_(nullptr) {} |
| +bool ViewAndroid::RegisterWindowAndroid(JNIEnv* env) { |
| + return RegisterNativesImpl(env); |
| +} |
| + |
| ViewAndroid::~ViewAndroid() { |
| if (parent_) |
| parent_->RemoveChild(this); |
| @@ -55,6 +70,53 @@ void ViewAndroid::RemoveChild(ViewAndroid* child) { |
| child->parent_ = nullptr; |
| } |
| + |
| +ViewAndroid::ScopedAnchorView* ViewAndroid::AcquireAnchorView() { |
| + if (delegate_.is_null()) |
| + return parent_ ? parent_->AcquireAnchorView() : |
| + new ViewAndroid::ScopedAnchorView(); |
| + |
| + JNIEnv* env = base::android::AttachCurrentThread(); |
| + return new ViewAndroid::ScopedAnchorView( |
| + Java_ViewAndroidDelegate_acquireView(env, delegate_.obj()), delegate_); |
| +} |
| + |
| +void ViewAndroid::SetAnchorRect(const JavaRef<jobject>& anchor, |
| + const gfx::RectF& bounds) { |
| + if (bounds.IsEmpty()) return; |
| + |
| + if (delegate_.is_null()) { |
| + if (parent_) parent_->SetAnchorRect(anchor, bounds); |
| + return; |
| + } |
| + |
| + JNIEnv* env = base::android::AttachCurrentThread(); |
| + gfx::DeviceDisplayInfo device_info; |
| + float scale = device_info.GetDIPScale(); |
|
no sievers
2016/07/18 22:14:16
Can you call GetScaleFactorForNativeView(this) ins
Jinsuk Kim
2016/07/19 07:08:40
Done.
|
| + int left_margin = std::round(bounds.x() * scale); |
| + // TODO(jinsukkim): Move content_offset() to ViewAndroid, since it's |
| + // specific to a given web contents/render widget. |
| + float content_offset_y_pix = GetWindowAndroid()->content_offset().y(); |
| + int top_margin = std::round(content_offset_y_pix + bounds.y() * scale); |
| + Java_ViewAndroidDelegate_setViewPosition(env, |
| + delegate_.obj(), |
| + anchor.obj(), |
| + bounds.x(), |
| + bounds.y(), |
| + bounds.width(), |
| + bounds.height(), |
| + scale, |
| + left_margin, |
| + top_margin); |
| +} |
| + |
| +const JavaRef<jobject>& ViewAndroid::GetViewAndroidDelegate() const { |
|
no sievers
2016/07/18 22:14:16
nit: This is unused now. But I wonder if it makes
Jinsuk Kim
2016/07/19 07:08:40
That's neat. Done.
|
| + if (!delegate_.is_null()) |
| + return delegate_; |
| + |
| + return parent_ ? parent_->GetViewAndroidDelegate() : delegate_; |
| +} |
| + |
| WindowAndroid* ViewAndroid::GetWindowAndroid() const { |
| if (window_) |
| return window_; |
| @@ -67,14 +129,6 @@ void ViewAndroid::SetWindowAndroid(WindowAndroid* root_window) { |
| DCHECK(parent_ == nullptr) << "Children shouldn't have a root window"; |
| } |
| -const JavaRef<jobject>& ViewAndroid::GetViewAndroidDelegate() |
| - const { |
| - if (!delegate_.is_null()) |
| - return delegate_; |
| - |
| - return parent_ ? parent_->GetViewAndroidDelegate() : delegate_; |
| -} |
| - |
| cc::Layer* ViewAndroid::GetLayer() const { |
| return layer_.get(); |
| } |