Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(447)

Unified Diff: ui/android/view_android.cc

Issue 2896993002: Route OnDragEvent through ViewAndroid tree (Closed)
Patch Set: rebase Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ui/android/view_android.cc
diff --git a/ui/android/view_android.cc b/ui/android/view_android.cc
index 489a1b930c6ed2995f824e310d458b041b3a5302..fa065bc2c4f397f2045d41fc22b0fb17aaf0258b 100644
--- a/ui/android/view_android.cc
+++ b/ui/android/view_android.cc
@@ -15,6 +15,7 @@
#include "ui/android/view_client.h"
#include "ui/android/window_android.h"
#include "ui/base/layout.h"
+#include "ui/events/android/drag_event_android.h"
#include "ui/events/android/motion_event_android.h"
#include "url/gurl.h"
@@ -102,6 +103,10 @@ float ViewAndroid::GetDipScale() {
return ui::GetScaleFactorForNativeView(this);
}
+bool ViewAndroid::HitBy(const gfx::Point& point) {
boliu 2017/05/24 22:54:02 just inline this one line method with a single cal
Jinsuk Kim 2017/05/25 03:18:18 Done.
+ return layout_params_.HitBy(point);
+}
+
ScopedJavaLocalRef<jobject> ViewAndroid::GetEventForwarder() {
if (!event_forwarder_) {
DCHECK(!RootPathHasEventForwarder(parent_))
@@ -302,59 +307,76 @@ gfx::Size ViewAndroid::GetPhysicalBackingSize() {
return physical_size_;
}
+bool ViewAndroid::OnDragEvent(const DragEventAndroid& event) {
+ return HitTest(base::Bind(&ViewAndroid::SendDragEventToClient), event,
+ event.location());
+}
+
+// static
+bool ViewAndroid::SendDragEventToClient(ViewClient* client,
+ const DragEventAndroid& event,
+ const gfx::Point& point) {
+ std::unique_ptr<DragEventAndroid> e = event.CreateFor(point);
+ return client->OnDragEvent(*e);
+}
+
bool ViewAndroid::OnTouchEvent(const MotionEventAndroid& event,
bool for_touch_handle) {
return HitTest(
- base::Bind(&ViewAndroid::SendTouchEventToClient, for_touch_handle),
- event);
+ base::Bind(&ViewAndroid::SendTouchEventToClient, for_touch_handle), event,
+ event.GetPoint());
}
+// static
bool ViewAndroid::SendTouchEventToClient(bool for_touch_handle,
ViewClient* client,
- const MotionEventAndroid& event) {
- return client->OnTouchEvent(event, for_touch_handle);
+ const MotionEventAndroid& event,
+ const gfx::Point& point) {
+ std::unique_ptr<MotionEventAndroid> e(event.CreateFor(point));
+ return client->OnTouchEvent(*e, for_touch_handle);
}
bool ViewAndroid::OnMouseEvent(const MotionEventAndroid& event) {
- return HitTest(base::Bind(&ViewAndroid::SendMouseEventToClient), event);
+ return HitTest(base::Bind(&ViewAndroid::SendMouseEventToClient), event,
+ event.GetPoint());
}
// static
bool ViewAndroid::SendMouseEventToClient(ViewClient* client,
- const MotionEventAndroid& event) {
- return client->OnMouseEvent(event);
+ const MotionEventAndroid& event,
+ const gfx::Point& point) {
+ std::unique_ptr<MotionEventAndroid> e(event.CreateFor(point));
+ return client->OnMouseEvent(*e);
}
-// static
bool ViewAndroid::OnMouseWheelEvent(const MotionEventAndroid& event) {
- return HitTest(base::Bind(&ViewAndroid::SendMouseWheelEventToClient), event);
+ return HitTest(base::Bind(&ViewAndroid::SendMouseWheelEventToClient), event,
+ event.GetPoint());
}
// static
bool ViewAndroid::SendMouseWheelEventToClient(ViewClient* client,
- const MotionEventAndroid& event) {
- return client->OnMouseWheelEvent(event);
+ const MotionEventAndroid& event,
+ const gfx::Point& point) {
+ std::unique_ptr<MotionEventAndroid> e(event.CreateFor(point));
+ return client->OnMouseWheelEvent(*e);
}
-bool ViewAndroid::HitTest(ViewClientCallback send_to_client,
- const MotionEventAndroid& event) {
- if (client_ && send_to_client.Run(client_, event))
+template <typename E, typename T>
+bool ViewAndroid::HitTest(T send_to_client,
boliu 2017/05/24 22:54:02 I think T doesn't need to be a template, just decl
Jinsuk Kim 2017/05/25 03:18:18 Done.
+ const E& event,
+ const gfx::Point& point) {
+ if (client_ && send_to_client.Run(client_, event, point))
return true;
if (!children_.empty()) {
- std::unique_ptr<MotionEventAndroid> e(
- event.Offset(-layout_params_.x, -layout_params_.y));
+ gfx::Point offset_point(point);
+ offset_point.Offset(-layout_params_.x, -layout_params_.y);
// Match from back to front for hit testing.
for (auto* child : base::Reversed(children_)) {
- bool matched = child->layout_params_.match_parent;
- if (!matched) {
- gfx::Rect bound(child->layout_params_.x, child->layout_params_.y,
- child->layout_params_.width,
- child->layout_params_.height);
- matched = bound.Contains(e->GetX(0), e->GetY(0));
- }
- if (matched && child->HitTest(send_to_client, *e))
+ if (child->HitBy(offset_point) &&
+ child->HitTest(send_to_client, event, offset_point))
return true;
}
}

Powered by Google App Engine
This is Rietveld 408576698