| Index: ui/android/view_android.cc
|
| diff --git a/ui/android/view_android.cc b/ui/android/view_android.cc
|
| index 6c55a7bf9df724ce0eea47170c138cd146ba2d85..da8b8102d7856e2074f7963c5b1eb997ae318866 100644
|
| --- a/ui/android/view_android.cc
|
| +++ b/ui/android/view_android.cc
|
| @@ -9,6 +9,7 @@
|
| #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"
|
| @@ -18,6 +19,7 @@ namespace ui {
|
| using base::android::JavaRef;
|
| using base::android::ScopedJavaLocalRef;
|
|
|
| +// ViewAndroid::ScopedAndroidView
|
| ViewAndroid::ScopedAnchorView::ScopedAnchorView(
|
| JNIEnv* env,
|
| const JavaRef<jobject>& jview,
|
| @@ -68,34 +70,49 @@ ViewAndroid::ScopedAnchorView::view() const {
|
| return view_.get(env);
|
| }
|
|
|
| -ViewAndroid::ViewAndroid(const JavaRef<jobject>& delegate)
|
| - : parent_(nullptr)
|
| - , delegate_(base::android::AttachCurrentThread(),
|
| - delegate.obj()) {}
|
| +// ViewAndroid::Bounds
|
| +void ViewAndroid::Bounds::SetBounds(const gfx::Point& origin,
|
| + int width,
|
| + int height) {
|
| + rect_.SetRect(origin.x(), origin.y(), width, height);
|
| +}
|
| +
|
| +bool ViewAndroid::Bounds::IsInBounds(const MotionEventAndroid& event) {
|
| + bool width_matched = (rect_.width() == Bounds::kMatchParent) ? true :
|
| + rect_.x() <= event.GetX(0) && event.GetX(0) < rect_.right();
|
| + bool height_matched = (rect_.height() == Bounds::kMatchParent) ? true:
|
| + rect_.y() <= event.GetY(0) && event.GetY(0) < rect_.bottom();
|
| + return width_matched && height_matched;
|
| +}
|
|
|
| -ViewAndroid::ViewAndroid() : parent_(nullptr) {}
|
| +// ViewAndroid
|
| +ViewAndroid::ViewAndroid(ViewClient* client) : parent_(nullptr),
|
| + client_(client) {}
|
| +ViewAndroid::ViewAndroid() : ViewAndroid(nullptr) {}
|
|
|
| ViewAndroid::~ViewAndroid() {
|
| RemoveFromParent();
|
|
|
| - for (std::list<ViewAndroid*>::iterator it = children_.begin();
|
| - it != children_.end(); it++) {
|
| - DCHECK_EQ((*it)->parent_, this);
|
| - (*it)->parent_ = nullptr;
|
| + for (auto& child : children_) {
|
| + DCHECK_EQ(child->parent_, this);
|
| + child->parent_ = nullptr;
|
| }
|
| }
|
|
|
| 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);
|
| }
|
|
|
| void ViewAndroid::AddChild(ViewAndroid* child) {
|
| DCHECK(child);
|
| + DCHECK(!child->IsViewRoot()); // ViewRoot cannot be a child.
|
| DCHECK(std::find(children_.begin(), children_.end(), child) ==
|
| children_.end());
|
|
|
| - children_.push_back(child);
|
| + children_.push_front(child);
|
| if (child->parent_)
|
| child->RemoveFromParent();
|
| child->parent_ = this;
|
| @@ -106,6 +123,14 @@ void ViewAndroid::RemoveFromParent() {
|
| parent_->RemoveChild(this);
|
| }
|
|
|
| +void ViewAndroid::SetBounds(const gfx::Point& origin, int width, int height) {
|
| + bounds_.SetBounds(origin, width, height);
|
| +}
|
| +
|
| +bool ViewAndroid::IsInBounds(const MotionEventAndroid& event) {
|
| + return bounds_.IsInBounds(event);
|
| +}
|
| +
|
| ViewAndroid::ScopedAnchorView ViewAndroid::AcquireAnchorView() {
|
| ScopedJavaLocalRef<jobject> delegate(GetViewAndroidDelegate());
|
| if (delegate.is_null())
|
| @@ -153,6 +178,7 @@ void ViewAndroid::RemoveChild(ViewAndroid* child) {
|
| child->parent_ = nullptr;
|
| }
|
|
|
| +
|
| WindowAndroid* ViewAndroid::GetWindowAndroid() const {
|
| return parent_ ? parent_->GetWindowAndroid() : nullptr;
|
| }
|
| @@ -175,6 +201,14 @@ void ViewAndroid::SetLayer(scoped_refptr<cc::Layer> layer) {
|
| layer_ = layer;
|
| }
|
|
|
| +ViewAndroid* ViewAndroid::GetViewRoot() {
|
| + return parent_ ? parent_->GetViewRoot() : nullptr;
|
| +}
|
| +
|
| +bool ViewAndroid::IsViewRoot() {
|
| + return GetViewRoot() == this;
|
| +}
|
| +
|
| bool ViewAndroid::StartDragAndDrop(const JavaRef<jstring>& jtext,
|
| const JavaRef<jobject>& jimage) {
|
| ScopedJavaLocalRef<jobject> delegate(GetViewAndroidDelegate());
|
| @@ -185,4 +219,21 @@ bool ViewAndroid::StartDragAndDrop(const JavaRef<jstring>& jtext,
|
| jimage);
|
| }
|
|
|
| +bool ViewAndroid::OnTouchEventInternal(const MotionEventAndroid& event,
|
| + bool is_touch_handle_event) {
|
| + if (!IsInBounds(event))
|
| + return false;
|
| +
|
| + if (client_) {
|
| + if (client_->OnTouchEvent(event, is_touch_handle_event))
|
| + return true;
|
| + }
|
| +
|
| + for (auto& child: children_) {
|
| + if (child->OnTouchEventInternal(event, is_touch_handle_event))
|
| + return true;
|
| + }
|
| + return false;
|
| +}
|
| +
|
| } // namespace ui
|
|
|