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

Unified Diff: ui/android/view_android.cc

Issue 2896993002: Route OnDragEvent through ViewAndroid tree (Closed)
Patch Set: +ui/base 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
« no previous file with comments | « ui/android/view_android.h ('k') | ui/android/view_client.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/android/view_android.cc
diff --git a/ui/android/view_android.cc b/ui/android/view_android.cc
index 489a1b930c6ed2995f824e310d458b041b3a5302..abec6aba03397c9236c6797d82e460e71c0cb5be 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"
@@ -302,48 +303,72 @@ gfx::Size ViewAndroid::GetPhysicalBackingSize() {
return physical_size_;
}
+bool ViewAndroid::OnDragEvent(const DragEventAndroid& event) {
+ return HitTest(base::Bind(&ViewAndroid::SendDragEventToClient), event,
+ event.location_f());
+}
+
+// static
+bool ViewAndroid::SendDragEventToClient(ViewClient* client,
+ const DragEventAndroid& event,
+ const gfx::PointF& 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::PointF& 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::PointF& 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::PointF& 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>
+bool ViewAndroid::HitTest(ViewClientCallback<E> send_to_client,
+ const E& event,
+ const gfx::PointF& 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::PointF offset_point(point);
+ offset_point.Offset(-layout_params_.x, -layout_params_.y);
+ gfx::Point int_point = gfx::ToFlooredPoint(offset_point);
// Match from back to front for hit testing.
for (auto* child : base::Reversed(children_)) {
@@ -352,9 +377,9 @@ bool ViewAndroid::HitTest(ViewClientCallback send_to_client,
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));
+ matched = bound.Contains(int_point);
}
- if (matched && child->HitTest(send_to_client, *e))
+ if (matched && child->HitTest(send_to_client, event, offset_point))
return true;
}
}
« no previous file with comments | « ui/android/view_android.h ('k') | ui/android/view_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698