Chromium Code Reviews| Index: ui/android/view_android.cc |
| diff --git a/ui/android/view_android.cc b/ui/android/view_android.cc |
| index 1d5b146653458a83b93c58810f743f6df78e5c46..9b1e47a797a77b9e5fa8257a2b0bfb74ee17ff53 100644 |
| --- a/ui/android/view_android.cc |
| +++ b/ui/android/view_android.cc |
| @@ -10,9 +10,10 @@ |
| #include "base/android/jni_string.h" |
| #include "cc/layers/layer.h" |
| #include "jni/ViewAndroidDelegate_jni.h" |
| +#include "ui/android/event_handler.h" |
| +#include "ui/android/view_client.h" |
| #include "ui/android/window_android.h" |
| -#include "ui/display/display.h" |
| -#include "ui/display/screen.h" |
| +#include "ui/base/layout.h" |
| #include "url/gurl.h" |
| namespace ui { |
| @@ -71,11 +72,12 @@ ViewAndroid::ScopedAnchorView::view() const { |
| return view_.get(env); |
| } |
| -ViewAndroid::ViewAndroid(const JavaRef<jobject>& delegate) |
| +ViewAndroid::ViewAndroid(ViewClient* view_client) |
| : parent_(nullptr), |
| - delegate_(base::android::AttachCurrentThread(), delegate.obj()) {} |
| + client_(view_client), |
| + dip_scale_(ui::GetScaleFactorForNativeView(this)) {} |
|
boliu
2017/02/27 19:21:57
again, don't cache this
Jinsuk Kim
2017/02/28 06:56:04
Done.
|
| -ViewAndroid::ViewAndroid() : parent_(nullptr) {} |
| +ViewAndroid::ViewAndroid() : ViewAndroid(nullptr) {} |
| ViewAndroid::~ViewAndroid() { |
| RemoveFromParent(); |
| @@ -88,21 +90,48 @@ 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); |
| } |
| +float ViewAndroid::GetDipScale() { |
| + return dip_scale_; |
| +} |
| + |
| +EventHandler* ViewAndroid::CreateEventHandler() { |
| + DCHECK(!parent_ || parent_ == GetWindowAndroid()) |
|
boliu
2017/02/27 19:21:57
this is gonna break after WCVA is not immediate ch
Jinsuk Kim
2017/02/28 06:56:04
Done. Restored |GetViewRoot()| that returns the to
|
| + << "Only WebContentViewAndroid's ViewAndroid can have event handler."; |
| + DCHECK(!event_handler_) << "EventHandler is already created"; |
| + |
| + event_handler_.reset(EventHandler::Create(this)); |
| + return event_handler_.get(); |
| +} |
| + |
| void ViewAndroid::AddChild(ViewAndroid* child) { |
| DCHECK(child); |
| DCHECK(std::find(children_.begin(), children_.end(), child) == |
| children_.end()); |
| + DCHECK(!ViewTreeHasEventHandler(child)) << "Child cannot have event handler"; |
|
boliu
2017/02/27 19:21:57
why not..? that only holds if we don't already hav
Jinsuk Kim
2017/02/28 06:56:04
The restriction was to allow for the event handler
|
| + // The new child goes to the top, which is the end of the list. |
| children_.push_back(child); |
| if (child->parent_) |
| child->RemoveFromParent(); |
| child->parent_ = this; |
| } |
| +bool ViewAndroid::ViewTreeHasEventHandler(ViewAndroid* view) { |
| + if (view->has_event_handler()) |
| + return true; |
| + for (auto& child : view->children_) { |
| + if (child->has_event_handler()) |
| + return true; |
| + } |
| + return false; |
| +} |
| + |
| void ViewAndroid::RemoveFromParent() { |
| if (parent_) |
| parent_->RemoveChild(this); |
| @@ -124,15 +153,12 @@ void ViewAndroid::SetAnchorRect(const JavaRef<jobject>& anchor, |
| if (delegate.is_null()) |
| return; |
| - float scale = display::Screen::GetScreen() |
| - ->GetDisplayNearestWindow(this) |
| - .device_scale_factor(); |
| - int left_margin = std::round(bounds.x() * scale); |
| - int top_margin = std::round((content_offset().y() + bounds.y()) * scale); |
| + int left_margin = std::round(bounds.x() * dip_scale_); |
| + int top_margin = std::round((content_offset().y() + bounds.y()) * dip_scale_); |
| JNIEnv* env = base::android::AttachCurrentThread(); |
| Java_ViewAndroidDelegate_setViewPosition( |
| env, delegate, anchor, bounds.x(), bounds.y(), bounds.width(), |
| - bounds.height(), scale, left_margin, top_margin); |
| + bounds.height(), dip_scale_, left_margin, top_margin); |
| } |
| ScopedJavaLocalRef<jobject> ViewAndroid::GetContainerView() { |
| @@ -227,4 +253,30 @@ void ViewAndroid::StartContentIntent(const GURL& content_url, |
| is_main_frame); |
| } |
| +bool ViewAndroid::OnTouchEvent(const MotionEventAndroid& event, |
| + bool is_touch_handle_event) { |
| + if (client_ && client_->OnTouchEvent(event, is_touch_handle_event)) |
|
boliu
2017/02/27 19:21:57
what happened to hit testing?
Did that part get r
boliu
2017/02/28 03:18:15
actually, never mind, hit testing can be added lat
Jinsuk Kim
2017/02/28 06:56:04
Done.
Jinsuk Kim
2017/02/28 06:56:04
Restored and saw your comment too late :(
Set |mat
boliu
2017/02/28 22:44:54
Sure :p but bring back the unit tests too :)
Jinsuk Kim
2017/03/02 04:08:34
Done.
|
| + return true; |
| + |
| + for (auto it = children_.rbegin(); it != children_.rend(); ++it) { |
| + if ((*it)->OnTouchEvent(event, is_touch_handle_event)) |
| + return true; |
| + } |
| + |
| + return false; |
| +} |
| + |
| +bool ViewAndroid::OnMouseEvent(const MotionEventAndroid& event, |
| + int action_button) { |
| + if (client_ && client_->OnMouseEvent(event, action_button)) |
| + return true; |
| + |
| + for (auto it = children_.rbegin(); it != children_.rend(); ++it) { |
| + if ((*it)->OnMouseEvent(event, action_button)) |
| + return true; |
| + } |
| + |
| + return false; |
| +} |
| + |
| } // namespace ui |