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

Side by Side Diff: ui/android/view_android.cc

Issue 2896993002: Route OnDragEvent through ViewAndroid tree (Closed)
Patch Set: +ui/base Created 3 years, 6 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 unified diff | Download patch
« no previous file with comments | « ui/android/view_android.h ('k') | ui/android/view_client.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/android/view_android.h" 5 #include "ui/android/view_android.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/android/jni_android.h" 9 #include "base/android/jni_android.h"
10 #include "base/android/jni_string.h" 10 #include "base/android/jni_string.h"
11 #include "base/containers/adapters.h" 11 #include "base/containers/adapters.h"
12 #include "cc/layers/layer.h" 12 #include "cc/layers/layer.h"
13 #include "jni/ViewAndroidDelegate_jni.h" 13 #include "jni/ViewAndroidDelegate_jni.h"
14 #include "ui/android/event_forwarder.h" 14 #include "ui/android/event_forwarder.h"
15 #include "ui/android/view_client.h" 15 #include "ui/android/view_client.h"
16 #include "ui/android/window_android.h" 16 #include "ui/android/window_android.h"
17 #include "ui/base/layout.h" 17 #include "ui/base/layout.h"
18 #include "ui/events/android/drag_event_android.h"
18 #include "ui/events/android/motion_event_android.h" 19 #include "ui/events/android/motion_event_android.h"
19 #include "url/gurl.h" 20 #include "url/gurl.h"
20 21
21 namespace ui { 22 namespace ui {
22 23
23 using base::android::ConvertUTF8ToJavaString; 24 using base::android::ConvertUTF8ToJavaString;
24 using base::android::JavaRef; 25 using base::android::JavaRef;
25 using base::android::ScopedJavaLocalRef; 26 using base::android::ScopedJavaLocalRef;
26 27
27 ViewAndroid::ScopedAnchorView::ScopedAnchorView( 28 ViewAndroid::ScopedAnchorView::ScopedAnchorView(
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 client_->OnPhysicalBackingSizeChanged(); 296 client_->OnPhysicalBackingSizeChanged();
296 297
297 for (auto* child : children_) 298 for (auto* child : children_)
298 child->OnPhysicalBackingSizeChanged(size); 299 child->OnPhysicalBackingSizeChanged(size);
299 } 300 }
300 301
301 gfx::Size ViewAndroid::GetPhysicalBackingSize() { 302 gfx::Size ViewAndroid::GetPhysicalBackingSize() {
302 return physical_size_; 303 return physical_size_;
303 } 304 }
304 305
306 bool ViewAndroid::OnDragEvent(const DragEventAndroid& event) {
307 return HitTest(base::Bind(&ViewAndroid::SendDragEventToClient), event,
308 event.location_f());
309 }
310
311 // static
312 bool ViewAndroid::SendDragEventToClient(ViewClient* client,
313 const DragEventAndroid& event,
314 const gfx::PointF& point) {
315 std::unique_ptr<DragEventAndroid> e = event.CreateFor(point);
316 return client->OnDragEvent(*e);
317 }
318
305 bool ViewAndroid::OnTouchEvent(const MotionEventAndroid& event, 319 bool ViewAndroid::OnTouchEvent(const MotionEventAndroid& event,
306 bool for_touch_handle) { 320 bool for_touch_handle) {
307 return HitTest( 321 return HitTest(
308 base::Bind(&ViewAndroid::SendTouchEventToClient, for_touch_handle), 322 base::Bind(&ViewAndroid::SendTouchEventToClient, for_touch_handle), event,
309 event); 323 event.GetPoint());
310 } 324 }
311 325
326 // static
312 bool ViewAndroid::SendTouchEventToClient(bool for_touch_handle, 327 bool ViewAndroid::SendTouchEventToClient(bool for_touch_handle,
313 ViewClient* client, 328 ViewClient* client,
314 const MotionEventAndroid& event) { 329 const MotionEventAndroid& event,
315 return client->OnTouchEvent(event, for_touch_handle); 330 const gfx::PointF& point) {
331 std::unique_ptr<MotionEventAndroid> e(event.CreateFor(point));
332 return client->OnTouchEvent(*e, for_touch_handle);
316 } 333 }
317 334
318 bool ViewAndroid::OnMouseEvent(const MotionEventAndroid& event) { 335 bool ViewAndroid::OnMouseEvent(const MotionEventAndroid& event) {
319 return HitTest(base::Bind(&ViewAndroid::SendMouseEventToClient), event); 336 return HitTest(base::Bind(&ViewAndroid::SendMouseEventToClient), event,
337 event.GetPoint());
320 } 338 }
321 339
322 // static 340 // static
323 bool ViewAndroid::SendMouseEventToClient(ViewClient* client, 341 bool ViewAndroid::SendMouseEventToClient(ViewClient* client,
324 const MotionEventAndroid& event) { 342 const MotionEventAndroid& event,
325 return client->OnMouseEvent(event); 343 const gfx::PointF& point) {
344 std::unique_ptr<MotionEventAndroid> e(event.CreateFor(point));
345 return client->OnMouseEvent(*e);
326 } 346 }
327 347
328 // static
329 bool ViewAndroid::OnMouseWheelEvent(const MotionEventAndroid& event) { 348 bool ViewAndroid::OnMouseWheelEvent(const MotionEventAndroid& event) {
330 return HitTest(base::Bind(&ViewAndroid::SendMouseWheelEventToClient), event); 349 return HitTest(base::Bind(&ViewAndroid::SendMouseWheelEventToClient), event,
350 event.GetPoint());
331 } 351 }
332 352
333 // static 353 // static
334 bool ViewAndroid::SendMouseWheelEventToClient(ViewClient* client, 354 bool ViewAndroid::SendMouseWheelEventToClient(ViewClient* client,
335 const MotionEventAndroid& event) { 355 const MotionEventAndroid& event,
336 return client->OnMouseWheelEvent(event); 356 const gfx::PointF& point) {
357 std::unique_ptr<MotionEventAndroid> e(event.CreateFor(point));
358 return client->OnMouseWheelEvent(*e);
337 } 359 }
338 360
339 bool ViewAndroid::HitTest(ViewClientCallback send_to_client, 361 template <typename E>
340 const MotionEventAndroid& event) { 362 bool ViewAndroid::HitTest(ViewClientCallback<E> send_to_client,
341 if (client_ && send_to_client.Run(client_, event)) 363 const E& event,
364 const gfx::PointF& point) {
365 if (client_ && send_to_client.Run(client_, event, point))
342 return true; 366 return true;
343 367
344 if (!children_.empty()) { 368 if (!children_.empty()) {
345 std::unique_ptr<MotionEventAndroid> e( 369 gfx::PointF offset_point(point);
346 event.Offset(-layout_params_.x, -layout_params_.y)); 370 offset_point.Offset(-layout_params_.x, -layout_params_.y);
371 gfx::Point int_point = gfx::ToFlooredPoint(offset_point);
347 372
348 // Match from back to front for hit testing. 373 // Match from back to front for hit testing.
349 for (auto* child : base::Reversed(children_)) { 374 for (auto* child : base::Reversed(children_)) {
350 bool matched = child->layout_params_.match_parent; 375 bool matched = child->layout_params_.match_parent;
351 if (!matched) { 376 if (!matched) {
352 gfx::Rect bound(child->layout_params_.x, child->layout_params_.y, 377 gfx::Rect bound(child->layout_params_.x, child->layout_params_.y,
353 child->layout_params_.width, 378 child->layout_params_.width,
354 child->layout_params_.height); 379 child->layout_params_.height);
355 matched = bound.Contains(e->GetX(0), e->GetY(0)); 380 matched = bound.Contains(int_point);
356 } 381 }
357 if (matched && child->HitTest(send_to_client, *e)) 382 if (matched && child->HitTest(send_to_client, event, offset_point))
358 return true; 383 return true;
359 } 384 }
360 } 385 }
361 return false; 386 return false;
362 } 387 }
363 388
364 } // namespace ui 389 } // namespace ui
OLDNEW
« 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