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..e88b9b008d8e71aa844972999ac575daa78c199b 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,12 @@ 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), |
| + physical_width_pix_(0), |
| + physical_height_pix_(0), |
| + has_event_handler_(false) {} |
| +ViewAndroid::ViewAndroid() : ViewAndroid(nullptr) {} |
| ViewAndroid::~ViewAndroid() { |
| RemoveFromParent(); |
| @@ -86,6 +88,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); |
| } |
| @@ -94,6 +98,8 @@ void ViewAndroid::AddChild(ViewAndroid* child) { |
| DCHECK(child); |
| DCHECK(std::find(children_.begin(), children_.end(), child) == |
| children_.end()); |
| + DCHECK(!HasEventHandlerInTreeHierarchy() || |
| + !child->HasEventHandlerInSubtree()); |
| children_.push_back(child); |
| if (child->parent_) |
| @@ -169,6 +175,31 @@ void ViewAndroid::SetLayer(scoped_refptr<cc::Layer> layer) { |
| layer_ = layer; |
| } |
| +void ViewAndroid::OnSetEventHandler() { |
| + DCHECK(!HasEventHandlerInTreeHierarchy()); |
| + has_event_handler_ = true; |
| +} |
| + |
| +bool ViewAndroid::HasEventHandlerInTreeHierarchy() { |
| + ViewAndroid* view = parent_; |
| + while (view) { |
| + if (view->has_event_handler()) |
| + return true; |
| + view = view->parent_; |
| + } |
| + return HasEventHandlerInSubtree(); |
| +} |
| + |
| +bool ViewAndroid::HasEventHandlerInSubtree() { |
| + if (has_event_handler_) |
| + return true; |
| + for (auto it = children_.begin(); it != children_.end(); ++it) { |
|
boliu
2016/12/06 23:15:46
style: you can use for-each style "for (auto& chil
Jinsuk Kim
2016/12/07 12:36:28
Done.
|
| + if ((*it)->HasEventHandlerInSubtree()) |
| + return true; |
| + } |
| + return false; |
| +} |
| + |
| bool ViewAndroid::StartDragAndDrop(const JavaRef<jstring>& jtext, |
| const JavaRef<jobject>& jimage) { |
| ScopedJavaLocalRef<jobject> delegate(GetViewAndroidDelegate()); |
| @@ -179,4 +210,30 @@ bool ViewAndroid::StartDragAndDrop(const JavaRef<jstring>& jtext, |
| jimage); |
| } |
| +gfx::Size ViewAndroid::GetPhysicalBackingSize() { |
| + return gfx::Size(physical_width_pix_, physical_height_pix_); |
| +} |
| + |
| +void ViewAndroid::SetPhysicalBackingSize(int width, int height) { |
|
boliu
2016/12/06 23:15:46
nit: maybe this can just be inlined, a bit confusi
Jinsuk Kim
2016/12/07 12:36:28
Done.
|
| + physical_width_pix_ = width; |
| + physical_height_pix_ = height; |
| + UpdateLayerBounds(); |
| +} |
| + |
| +void ViewAndroid::UpdateLayerBounds() { |
| + layer_->SetBounds(GetPhysicalBackingSize()); |
| +} |
| + |
| +void ViewAndroid::OnPhysicalBackingSizeChanged(int width, int height) { |
| + if (width == physical_width_pix_ && height == physical_height_pix_) |
| + return; |
| + |
| + SetPhysicalBackingSize(width, height); |
| + if (client_) |
| + client_->OnPhysicalBackingSizeChanged(width, height); |
| + |
| + for (auto it = children_.begin(); it != children_.end(); ++it) |
|
boliu
2016/12/06 23:15:46
ditto for-each loop
Jinsuk Kim
2016/12/07 12:36:28
Done.
|
| + (*it)->OnPhysicalBackingSizeChanged(width, height); |
| +} |
| + |
| } // namespace ui |