OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/events/gesture_detection/gesture_provider.h" | 5 #include "ui/events/gesture_detection/gesture_provider.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 | 8 |
9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 if (!pinch_event_sent_) { | 214 if (!pinch_event_sent_) { |
215 Send(CreateGesture(ET_GESTURE_PINCH_BEGIN, | 215 Send(CreateGesture(ET_GESTURE_PINCH_BEGIN, |
216 e.GetId(), | 216 e.GetId(), |
217 e.GetToolType(), | 217 e.GetToolType(), |
218 detector.GetEventTime(), | 218 detector.GetEventTime(), |
219 detector.GetFocusX(), | 219 detector.GetFocusX(), |
220 detector.GetFocusY(), | 220 detector.GetFocusY(), |
221 detector.GetFocusX() + e.GetRawOffsetX(), | 221 detector.GetFocusX() + e.GetRawOffsetX(), |
222 detector.GetFocusY() + e.GetRawOffsetY(), | 222 detector.GetFocusY() + e.GetRawOffsetY(), |
223 e.GetPointerCount(), | 223 e.GetPointerCount(), |
224 GetBoundingBox(e, ET_GESTURE_PINCH_BEGIN))); | 224 GetBoundingBox(e, ET_GESTURE_PINCH_BEGIN), |
| 225 e.GetFlags())); |
225 } | 226 } |
226 | 227 |
227 if (std::abs(detector.GetCurrentSpan() - detector.GetPreviousSpan()) < | 228 if (std::abs(detector.GetCurrentSpan() - detector.GetPreviousSpan()) < |
228 config_.scale_gesture_detector_config.min_pinch_update_span_delta) { | 229 config_.scale_gesture_detector_config.min_pinch_update_span_delta) { |
229 return false; | 230 return false; |
230 } | 231 } |
231 | 232 |
232 float scale = detector.GetScaleFactor(); | 233 float scale = detector.GetScaleFactor(); |
233 if (scale == 1) | 234 if (scale == 1) |
234 return true; | 235 return true; |
(...skipping 13 matching lines...) Expand all Loading... |
248 GestureEventDetails pinch_details(ET_GESTURE_PINCH_UPDATE, scale, 0); | 249 GestureEventDetails pinch_details(ET_GESTURE_PINCH_UPDATE, scale, 0); |
249 Send(CreateGesture(pinch_details, | 250 Send(CreateGesture(pinch_details, |
250 e.GetId(), | 251 e.GetId(), |
251 e.GetToolType(), | 252 e.GetToolType(), |
252 detector.GetEventTime(), | 253 detector.GetEventTime(), |
253 detector.GetFocusX(), | 254 detector.GetFocusX(), |
254 detector.GetFocusY(), | 255 detector.GetFocusY(), |
255 detector.GetFocusX() + e.GetRawOffsetX(), | 256 detector.GetFocusX() + e.GetRawOffsetX(), |
256 detector.GetFocusY() + e.GetRawOffsetY(), | 257 detector.GetFocusY() + e.GetRawOffsetY(), |
257 e.GetPointerCount(), | 258 e.GetPointerCount(), |
258 GetBoundingBox(e, pinch_details.type()))); | 259 GetBoundingBox(e, pinch_details.type()), |
| 260 e.GetFlags())); |
259 return true; | 261 return true; |
260 } | 262 } |
261 | 263 |
262 // GestureDetector::GestureListener implementation. | 264 // GestureDetector::GestureListener implementation. |
263 virtual bool OnDown(const MotionEvent& e) OVERRIDE { | 265 virtual bool OnDown(const MotionEvent& e) OVERRIDE { |
264 GestureEventDetails tap_details(ET_GESTURE_TAP_DOWN, 0, 0); | 266 GestureEventDetails tap_details(ET_GESTURE_TAP_DOWN, 0, 0); |
265 Send(CreateGesture(tap_details, e)); | 267 Send(CreateGesture(tap_details, e)); |
266 | 268 |
267 // Return true to indicate that we want to handle touch. | 269 // Return true to indicate that we want to handle touch. |
268 return true; | 270 return true; |
(...skipping 29 matching lines...) Expand all Loading... |
298 // used to determine which layer the scroll should affect. | 300 // used to determine which layer the scroll should affect. |
299 Send(CreateGesture(scroll_details, | 301 Send(CreateGesture(scroll_details, |
300 e2.GetId(), | 302 e2.GetId(), |
301 e2.GetToolType(), | 303 e2.GetToolType(), |
302 e2.GetEventTime(), | 304 e2.GetEventTime(), |
303 e1.GetX(), | 305 e1.GetX(), |
304 e1.GetY(), | 306 e1.GetY(), |
305 e1.GetRawX(), | 307 e1.GetRawX(), |
306 e1.GetRawY(), | 308 e1.GetRawY(), |
307 e2.GetPointerCount(), | 309 e2.GetPointerCount(), |
308 GetBoundingBox(e2, scroll_details.type()))); | 310 GetBoundingBox(e2, scroll_details.type()), |
| 311 e2.GetFlags())); |
309 DCHECK(scroll_event_sent_); | 312 DCHECK(scroll_event_sent_); |
310 } | 313 } |
311 | 314 |
312 snap_scroll_controller_.UpdateSnapScrollMode(distance_x, distance_y); | 315 snap_scroll_controller_.UpdateSnapScrollMode(distance_x, distance_y); |
313 if (snap_scroll_controller_.IsSnappingScrolls()) { | 316 if (snap_scroll_controller_.IsSnappingScrolls()) { |
314 if (snap_scroll_controller_.IsSnapHorizontal()) | 317 if (snap_scroll_controller_.IsSnapHorizontal()) |
315 distance_y = 0; | 318 distance_y = 0; |
316 else | 319 else |
317 distance_x = 0; | 320 distance_x = 0; |
318 } | 321 } |
319 | 322 |
320 if (distance_x || distance_y) { | 323 if (distance_x || distance_y) { |
321 GestureEventDetails scroll_details( | 324 GestureEventDetails scroll_details( |
322 ET_GESTURE_SCROLL_UPDATE, -distance_x, -distance_y); | 325 ET_GESTURE_SCROLL_UPDATE, -distance_x, -distance_y); |
323 const gfx::RectF bounding_box = GetBoundingBox(e2, scroll_details.type()); | 326 const gfx::RectF bounding_box = GetBoundingBox(e2, scroll_details.type()); |
324 const gfx::PointF center = bounding_box.CenterPoint(); | 327 const gfx::PointF center = bounding_box.CenterPoint(); |
325 const gfx::PointF raw_center = | 328 const gfx::PointF raw_center = |
326 center + gfx::Vector2dF(e2.GetRawOffsetX(), e2.GetRawOffsetY()); | 329 center + gfx::Vector2dF(e2.GetRawOffsetX(), e2.GetRawOffsetY()); |
327 Send(CreateGesture(scroll_details, | 330 Send(CreateGesture(scroll_details, |
328 e2.GetId(), | 331 e2.GetId(), |
329 e2.GetToolType(), | 332 e2.GetToolType(), |
330 e2.GetEventTime(), | 333 e2.GetEventTime(), |
331 center.x(), | 334 center.x(), |
332 center.y(), | 335 center.y(), |
333 raw_center.x(), | 336 raw_center.x(), |
334 raw_center.y(), | 337 raw_center.y(), |
335 e2.GetPointerCount(), | 338 e2.GetPointerCount(), |
336 bounding_box)); | 339 bounding_box, |
| 340 e2.GetFlags())); |
337 } | 341 } |
338 | 342 |
339 return true; | 343 return true; |
340 } | 344 } |
341 | 345 |
342 virtual bool OnFling(const MotionEvent& e1, | 346 virtual bool OnFling(const MotionEvent& e1, |
343 const MotionEvent& e2, | 347 const MotionEvent& e2, |
344 float velocity_x, | 348 float velocity_x, |
345 float velocity_y) OVERRIDE { | 349 float velocity_y) OVERRIDE { |
346 if (snap_scroll_controller_.IsSnappingScrolls()) { | 350 if (snap_scroll_controller_.IsSnappingScrolls()) { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
386 ET_GESTURE_TWO_FINGER_TAP, e1.GetTouchMajor(), e1.GetTouchMajor()); | 390 ET_GESTURE_TWO_FINGER_TAP, e1.GetTouchMajor(), e1.GetTouchMajor()); |
387 Send(CreateGesture(two_finger_tap_details, | 391 Send(CreateGesture(two_finger_tap_details, |
388 e2.GetId(), | 392 e2.GetId(), |
389 e2.GetToolType(), | 393 e2.GetToolType(), |
390 e2.GetEventTime(), | 394 e2.GetEventTime(), |
391 e1.GetX(), | 395 e1.GetX(), |
392 e1.GetY(), | 396 e1.GetY(), |
393 e1.GetRawX(), | 397 e1.GetRawX(), |
394 e1.GetRawY(), | 398 e1.GetRawY(), |
395 e2.GetPointerCount(), | 399 e2.GetPointerCount(), |
396 GetBoundingBox(e2, two_finger_tap_details.type()))); | 400 GetBoundingBox(e2, two_finger_tap_details.type()), |
| 401 e2.GetFlags())); |
397 return true; | 402 return true; |
398 } | 403 } |
399 | 404 |
400 virtual void OnShowPress(const MotionEvent& e) OVERRIDE { | 405 virtual void OnShowPress(const MotionEvent& e) OVERRIDE { |
401 GestureEventDetails show_press_details(ET_GESTURE_SHOW_PRESS, 0, 0); | 406 GestureEventDetails show_press_details(ET_GESTURE_SHOW_PRESS, 0, 0); |
402 show_press_event_sent_ = true; | 407 show_press_event_sent_ = true; |
403 Send(CreateGesture(show_press_details, e)); | 408 Send(CreateGesture(show_press_details, e)); |
404 } | 409 } |
405 | 410 |
406 virtual bool OnSingleTapUp(const MotionEvent& e) OVERRIDE { | 411 virtual bool OnSingleTapUp(const MotionEvent& e) OVERRIDE { |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
483 | 488 |
484 GestureEventData CreateGesture(const GestureEventDetails& details, | 489 GestureEventData CreateGesture(const GestureEventDetails& details, |
485 int motion_event_id, | 490 int motion_event_id, |
486 MotionEvent::ToolType primary_tool_type, | 491 MotionEvent::ToolType primary_tool_type, |
487 base::TimeTicks time, | 492 base::TimeTicks time, |
488 float x, | 493 float x, |
489 float y, | 494 float y, |
490 float raw_x, | 495 float raw_x, |
491 float raw_y, | 496 float raw_y, |
492 size_t touch_point_count, | 497 size_t touch_point_count, |
493 const gfx::RectF& bounding_box) { | 498 const gfx::RectF& bounding_box, |
| 499 int flags) { |
494 return GestureEventData(details, | 500 return GestureEventData(details, |
495 motion_event_id, | 501 motion_event_id, |
496 primary_tool_type, | 502 primary_tool_type, |
497 time, | 503 time, |
498 x, | 504 x, |
499 y, | 505 y, |
500 raw_x, | 506 raw_x, |
501 raw_y, | 507 raw_y, |
502 touch_point_count, | 508 touch_point_count, |
503 bounding_box); | 509 bounding_box, |
| 510 flags); |
504 } | 511 } |
505 | 512 |
506 GestureEventData CreateGesture(EventType type, | 513 GestureEventData CreateGesture(EventType type, |
507 int motion_event_id, | 514 int motion_event_id, |
508 MotionEvent::ToolType primary_tool_type, | 515 MotionEvent::ToolType primary_tool_type, |
509 base::TimeTicks time, | 516 base::TimeTicks time, |
510 float x, | 517 float x, |
511 float y, | 518 float y, |
512 float raw_x, | 519 float raw_x, |
513 float raw_y, | 520 float raw_y, |
514 size_t touch_point_count, | 521 size_t touch_point_count, |
515 const gfx::RectF& bounding_box) { | 522 const gfx::RectF& bounding_box, |
| 523 int flags) { |
516 return GestureEventData(GestureEventDetails(type, 0, 0), | 524 return GestureEventData(GestureEventDetails(type, 0, 0), |
517 motion_event_id, | 525 motion_event_id, |
518 primary_tool_type, | 526 primary_tool_type, |
519 time, | 527 time, |
520 x, | 528 x, |
521 y, | 529 y, |
522 raw_x, | 530 raw_x, |
523 raw_y, | 531 raw_y, |
524 touch_point_count, | 532 touch_point_count, |
525 bounding_box); | 533 bounding_box, |
| 534 flags); |
526 } | 535 } |
527 | 536 |
528 GestureEventData CreateGesture(const GestureEventDetails& details, | 537 GestureEventData CreateGesture(const GestureEventDetails& details, |
529 const MotionEvent& event) { | 538 const MotionEvent& event) { |
530 return GestureEventData(details, | 539 return GestureEventData(details, |
531 event.GetId(), | 540 event.GetId(), |
532 event.GetToolType(), | 541 event.GetToolType(), |
533 event.GetEventTime(), | 542 event.GetEventTime(), |
534 event.GetX(), | 543 event.GetX(), |
535 event.GetY(), | 544 event.GetY(), |
536 event.GetRawX(), | 545 event.GetRawX(), |
537 event.GetRawY(), | 546 event.GetRawY(), |
538 event.GetPointerCount(), | 547 event.GetPointerCount(), |
539 GetBoundingBox(event, details.type())); | 548 GetBoundingBox(event, details.type()), |
| 549 event.GetFlags()); |
540 } | 550 } |
541 | 551 |
542 GestureEventData CreateGesture(EventType type, const MotionEvent& event) { | 552 GestureEventData CreateGesture(EventType type, const MotionEvent& event) { |
543 return CreateGesture(GestureEventDetails(type, 0, 0), event); | 553 return CreateGesture(GestureEventDetails(type, 0, 0), event); |
544 } | 554 } |
545 | 555 |
546 GestureEventData CreateTapGesture(EventType type, const MotionEvent& event) { | 556 GestureEventData CreateTapGesture(EventType type, const MotionEvent& event) { |
547 // Set the tap count to 1 even for ET_GESTURE_DOUBLE_TAP, in order to be | 557 // Set the tap count to 1 even for ET_GESTURE_DOUBLE_TAP, in order to be |
548 // consistent with double tap behavior on a mobile viewport. See | 558 // consistent with double tap behavior on a mobile viewport. See |
549 // crbug.com/234986 for context. | 559 // crbug.com/234986 for context. |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
749 gesture_listener_->Send(gesture_listener_->CreateGesture( | 759 gesture_listener_->Send(gesture_listener_->CreateGesture( |
750 ET_GESTURE_BEGIN, | 760 ET_GESTURE_BEGIN, |
751 event.GetId(), | 761 event.GetId(), |
752 event.GetToolType(), | 762 event.GetToolType(), |
753 event.GetEventTime(), | 763 event.GetEventTime(), |
754 event.GetX(action_index), | 764 event.GetX(action_index), |
755 event.GetY(action_index), | 765 event.GetY(action_index), |
756 event.GetRawX(action_index), | 766 event.GetRawX(action_index), |
757 event.GetRawY(action_index), | 767 event.GetRawY(action_index), |
758 event.GetPointerCount(), | 768 event.GetPointerCount(), |
759 gesture_listener_->GetBoundingBox(event, ET_GESTURE_BEGIN))); | 769 gesture_listener_->GetBoundingBox(event, ET_GESTURE_BEGIN), |
| 770 event.GetFlags())); |
760 } | 771 } |
761 break; | 772 break; |
762 case MotionEvent::ACTION_POINTER_UP: | 773 case MotionEvent::ACTION_POINTER_UP: |
763 case MotionEvent::ACTION_UP: | 774 case MotionEvent::ACTION_UP: |
764 case MotionEvent::ACTION_CANCEL: | 775 case MotionEvent::ACTION_CANCEL: |
765 case MotionEvent::ACTION_MOVE: | 776 case MotionEvent::ACTION_MOVE: |
766 break; | 777 break; |
767 } | 778 } |
768 } | 779 } |
769 | 780 |
(...skipping 28 matching lines...) Expand all Loading... |
798 // null'ing of the listener until the sequence has ended. | 809 // null'ing of the listener until the sequence has ended. |
799 if (current_down_event_) | 810 if (current_down_event_) |
800 return; | 811 return; |
801 | 812 |
802 const bool double_tap_enabled = | 813 const bool double_tap_enabled = |
803 double_tap_support_for_page_ && double_tap_support_for_platform_; | 814 double_tap_support_for_page_ && double_tap_support_for_platform_; |
804 gesture_listener_->SetDoubleTapEnabled(double_tap_enabled); | 815 gesture_listener_->SetDoubleTapEnabled(double_tap_enabled); |
805 } | 816 } |
806 | 817 |
807 } // namespace ui | 818 } // namespace ui |
OLD | NEW |