Chromium Code Reviews| Index: ui/android/view_android.cc |
| diff --git a/ui/android/view_android.cc b/ui/android/view_android.cc |
| index 664758cd5304088709f1cd99bdb655bae764aadf..254302320d61ce38b8a8c1f2de9f589e458b9579 100644 |
| --- a/ui/android/view_android.cc |
| +++ b/ui/android/view_android.cc |
| @@ -9,12 +9,14 @@ |
| #include "base/android/jni_android.h" |
| #include "cc/layers/layer.h" |
| #include "jni/ViewAndroidDelegate_jni.h" |
| +#include "ui/android/view_client.h" |
| #include "ui/android/window_android.h" |
| #include "ui/display/display.h" |
| #include "ui/display/screen.h" |
| namespace ui { |
| +using base::android::JavaParamRef; |
| using base::android::JavaRef; |
| using base::android::ScopedJavaLocalRef; |
| @@ -68,12 +70,9 @@ ViewAndroid::ScopedAnchorView::view() const { |
| return view_.get(env); |
| } |
| -ViewAndroid::ViewAndroid(const JavaRef<jobject>& delegate) |
| - : parent_(nullptr) |
| - , delegate_(base::android::AttachCurrentThread(), |
| - delegate.obj()) {} |
| - |
| -ViewAndroid::ViewAndroid() : parent_(nullptr) {} |
| +ViewAndroid::ViewAndroid(ViewClient* client) : parent_(nullptr), |
| + client_(client) {} |
| +ViewAndroid::ViewAndroid() : ViewAndroid(nullptr) {} |
| ViewAndroid::~ViewAndroid() { |
| RemoveFromParent(); |
| @@ -86,6 +85,8 @@ ViewAndroid::~ViewAndroid() { |
| } |
| void ViewAndroid::SetDelegate(const JavaRef<jobject>& delegate) { |
| + // A ViewAndroid may have its own delegate or otherwise will |
| + // use the next available parent's delegate. |
| JNIEnv* env = base::android::AttachCurrentThread(); |
| delegate_ = JavaObjectWeakGlobalRef(env, delegate); |
| } |
| @@ -179,4 +180,53 @@ bool ViewAndroid::StartDragAndDrop(const JavaRef<jstring>& jtext, |
| jimage); |
| } |
| +int ViewAndroid::GetPhysicalBackingSizeWidthPix() { |
| + if (!parent_ || parent_ == GetWindowAndroid()) |
|
boliu
2016/12/06 00:34:14
should just return own size, not recurse
ie we sh
Jinsuk Kim
2016/12/06 07:35:07
Done.
|
| + return physical_width_pix_; |
| + else |
| + return parent_->GetPhysicalBackingSizeWidthPix(); |
| +} |
| + |
| +int ViewAndroid::GetPhysicalBackingSizeHeightPix() { |
| + if (!parent_ || parent_ == GetWindowAndroid()) |
| + return physical_height_pix_; |
| + else |
| + return parent_->GetPhysicalBackingSizeHeightPix(); |
| +} |
| + |
| +gfx::Size ViewAndroid::GetPhysicalBackingSize() { |
| + return gfx::Size(GetPhysicalBackingSizeWidthPix(), |
| + GetPhysicalBackingSizeHeightPix()); |
| +} |
| + |
| +void ViewAndroid::SetPhysicalBackingSize(int width, int height) { |
| + if (!parent_ || parent_ == GetWindowAndroid()) { |
| + physical_width_pix_ = width; |
| + physical_height_pix_ = height; |
| + } else { |
| + return parent_->SetPhysicalBackingSize(width, height); |
|
boliu
2016/12/06 00:34:14
recursion in the wrong direction.. this value shou
Jinsuk Kim
2016/12/06 07:35:07
Done.
|
| + } |
| +} |
| + |
| +void ViewAndroid::UpdateLayerBounds() { |
| + layer_->SetBounds(GetPhysicalBackingSize()); |
|
boliu
2016/12/06 00:34:14
just do this inside SetPhyiscalBackingSize, then c
Jinsuk Kim
2016/12/06 07:35:07
Done.
|
| +} |
| + |
| +bool ViewAndroid::OnPhysicalBackingSizeChanged(int width, int height) { |
| + if (width == GetPhysicalBackingSizeWidthPix() |
| + && height == GetPhysicalBackingSizeHeightPix()) |
| + return true; |
| + |
| + if (client_ && client_->OnPhysicalBackingSizeChanged(width, height)) { |
| + SetPhysicalBackingSize(width, height); |
| + UpdateLayerBounds(); |
| + return true; |
| + } |
| + for (auto it = children_.begin(); it != children_.end(); ++it) { |
| + if ((*it)->OnPhysicalBackingSizeChanged(width, height)) |
| + return true; |
| + } |
| + return false; |
| +} |
| + |
| } // namespace ui |