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

Side by Side Diff: ui/events/gesture_detection/gesture_provider.cc

Issue 565583005: Clean up GestureEventDetails constructors (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Upload to the most recent patch Created 6 years, 3 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
OLDNEW
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 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 // diminish as the touch moves away from the original double-tap focus. 239 // diminish as the touch moves away from the original double-tap focus.
240 // For historical reasons, Chrome has instead adopted a scale factor 240 // For historical reasons, Chrome has instead adopted a scale factor
241 // computation that is invariant to the focal distance, where 241 // computation that is invariant to the focal distance, where
242 // the scale delta remains constant if the touch velocity is constant. 242 // the scale delta remains constant if the touch velocity is constant.
243 float dy = 243 float dy =
244 (detector.GetCurrentSpanY() - detector.GetPreviousSpanY()) * 0.5f; 244 (detector.GetCurrentSpanY() - detector.GetPreviousSpanY()) * 0.5f;
245 scale = std::pow(scale > 1 ? 1.0f + kDoubleTapDragZoomSpeed 245 scale = std::pow(scale > 1 ? 1.0f + kDoubleTapDragZoomSpeed
246 : 1.0f - kDoubleTapDragZoomSpeed, 246 : 1.0f - kDoubleTapDragZoomSpeed,
247 std::abs(dy)); 247 std::abs(dy));
248 } 248 }
249 GestureEventDetails pinch_details(ET_GESTURE_PINCH_UPDATE, scale, 0); 249 GestureEventDetails pinch_details(ET_GESTURE_PINCH_UPDATE);
250 pinch_details.set_scale(scale);
250 Send(CreateGesture(pinch_details, 251 Send(CreateGesture(pinch_details,
251 e.GetId(), 252 e.GetId(),
252 e.GetToolType(), 253 e.GetToolType(),
253 detector.GetEventTime(), 254 detector.GetEventTime(),
254 detector.GetFocusX(), 255 detector.GetFocusX(),
255 detector.GetFocusY(), 256 detector.GetFocusY(),
256 detector.GetFocusX() + e.GetRawOffsetX(), 257 detector.GetFocusX() + e.GetRawOffsetX(),
257 detector.GetFocusY() + e.GetRawOffsetY(), 258 detector.GetFocusY() + e.GetRawOffsetY(),
258 e.GetPointerCount(), 259 e.GetPointerCount(),
259 GetBoundingBox(e, pinch_details.type()), 260 GetBoundingBox(e, pinch_details.type()),
260 e.GetFlags())); 261 e.GetFlags()));
261 return true; 262 return true;
262 } 263 }
263 264
264 // GestureDetector::GestureListener implementation. 265 // GestureDetector::GestureListener implementation.
265 virtual bool OnDown(const MotionEvent& e) OVERRIDE { 266 virtual bool OnDown(const MotionEvent& e) OVERRIDE {
266 GestureEventDetails tap_details(ET_GESTURE_TAP_DOWN, 0, 0); 267 GestureEventDetails tap_details(ET_GESTURE_TAP_DOWN);
267 Send(CreateGesture(tap_details, e)); 268 Send(CreateGesture(tap_details, e));
268 269
269 // Return true to indicate that we want to handle touch. 270 // Return true to indicate that we want to handle touch.
270 return true; 271 return true;
271 } 272 }
272 273
273 virtual bool OnScroll(const MotionEvent& e1, 274 virtual bool OnScroll(const MotionEvent& e1,
274 const MotionEvent& e2, 275 const MotionEvent& e2,
275 float raw_distance_x, 276 float raw_distance_x,
276 float raw_distance_y) OVERRIDE { 277 float raw_distance_y) OVERRIDE {
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 e1.GetY(), 397 e1.GetY(),
397 e1.GetRawX(), 398 e1.GetRawX(),
398 e1.GetRawY(), 399 e1.GetRawY(),
399 e2.GetPointerCount(), 400 e2.GetPointerCount(),
400 GetBoundingBox(e2, two_finger_tap_details.type()), 401 GetBoundingBox(e2, two_finger_tap_details.type()),
401 e2.GetFlags())); 402 e2.GetFlags()));
402 return true; 403 return true;
403 } 404 }
404 405
405 virtual void OnShowPress(const MotionEvent& e) OVERRIDE { 406 virtual void OnShowPress(const MotionEvent& e) OVERRIDE {
406 GestureEventDetails show_press_details(ET_GESTURE_SHOW_PRESS, 0, 0); 407 GestureEventDetails show_press_details(ET_GESTURE_SHOW_PRESS);
407 show_press_event_sent_ = true; 408 show_press_event_sent_ = true;
408 Send(CreateGesture(show_press_details, e)); 409 Send(CreateGesture(show_press_details, e));
409 } 410 }
410 411
411 virtual bool OnSingleTapUp(const MotionEvent& e) OVERRIDE { 412 virtual bool OnSingleTapUp(const MotionEvent& e) OVERRIDE {
412 // This is a hack to address the issue where user hovers 413 // This is a hack to address the issue where user hovers
413 // over a link for longer than double_tap_timeout_, then 414 // over a link for longer than double_tap_timeout_, then
414 // OnSingleTapConfirmed() is not triggered. But we still 415 // OnSingleTapConfirmed() is not triggered. But we still
415 // want to trigger the tap event at UP. So we override 416 // want to trigger the tap event at UP. So we override
416 // OnSingleTapUp() in this case. This assumes singleTapUp 417 // OnSingleTapUp() in this case. This assumes singleTapUp
417 // gets always called before singleTapConfirmed. 418 // gets always called before singleTapConfirmed.
418 if (!ignore_single_tap_) { 419 if (!ignore_single_tap_) {
419 if (e.GetEventTime() - current_down_time_ > 420 if (e.GetEventTime() - current_down_time_ >
420 config_.gesture_detector_config.double_tap_timeout) { 421 config_.gesture_detector_config.double_tap_timeout) {
421 return OnSingleTapConfirmed(e); 422 return OnSingleTapConfirmed(e);
422 } else if (!IsDoubleTapEnabled() || config_.disable_click_delay) { 423 } else if (!IsDoubleTapEnabled() || config_.disable_click_delay) {
423 // If double-tap has been disabled, there is no need to wait 424 // If double-tap has been disabled, there is no need to wait
424 // for the double-tap timeout. 425 // for the double-tap timeout.
425 return OnSingleTapConfirmed(e); 426 return OnSingleTapConfirmed(e);
426 } else { 427 } else {
427 // Notify Blink about this tapUp event anyway, when none of the above 428 // Notify Blink about this tapUp event anyway, when none of the above
428 // conditions applied. 429 // conditions applied.
429 Send(CreateTapGesture(ET_GESTURE_TAP_UNCONFIRMED, e)); 430 Send(CreateTapGesture(ET_GESTURE_TAP_UNCONFIRMED, e));
430 } 431 }
431 } 432 }
432 433
433 if (e.GetAction() == MotionEvent::ACTION_UP && 434 if (e.GetAction() == MotionEvent::ACTION_UP &&
434 !current_longpress_time_.is_null() && 435 !current_longpress_time_.is_null() &&
435 !IsScaleGestureDetectionInProgress()) { 436 !IsScaleGestureDetectionInProgress()) {
436 GestureEventDetails long_tap_details(ET_GESTURE_LONG_TAP, 0, 0); 437 GestureEventDetails long_tap_details(ET_GESTURE_LONG_TAP);
437 Send(CreateGesture(long_tap_details, e)); 438 Send(CreateGesture(long_tap_details, e));
438 return true; 439 return true;
439 } 440 }
440 441
441 return false; 442 return false;
442 } 443 }
443 444
444 // GestureDetector::DoubleTapListener implementation. 445 // GestureDetector::DoubleTapListener implementation.
445 virtual bool OnSingleTapConfirmed(const MotionEvent& e) OVERRIDE { 446 virtual bool OnSingleTapConfirmed(const MotionEvent& e) OVERRIDE {
446 // Long taps in the edges of the screen have their events delayed by 447 // Long taps in the edges of the screen have their events delayed by
(...skipping 28 matching lines...) Expand all
475 476
476 default: 477 default:
477 break; 478 break;
478 } 479 }
479 return false; 480 return false;
480 } 481 }
481 482
482 virtual void OnLongPress(const MotionEvent& e) OVERRIDE { 483 virtual void OnLongPress(const MotionEvent& e) OVERRIDE {
483 DCHECK(!IsDoubleTapInProgress()); 484 DCHECK(!IsDoubleTapInProgress());
484 SetIgnoreSingleTap(true); 485 SetIgnoreSingleTap(true);
485 GestureEventDetails long_press_details(ET_GESTURE_LONG_PRESS, 0, 0); 486 GestureEventDetails long_press_details(ET_GESTURE_LONG_PRESS);
486 Send(CreateGesture(long_press_details, e)); 487 Send(CreateGesture(long_press_details, e));
487 } 488 }
488 489
489 GestureEventData CreateGesture(const GestureEventDetails& details, 490 GestureEventData CreateGesture(const GestureEventDetails& details,
490 int motion_event_id, 491 int motion_event_id,
491 MotionEvent::ToolType primary_tool_type, 492 MotionEvent::ToolType primary_tool_type,
492 base::TimeTicks time, 493 base::TimeTicks time,
493 float x, 494 float x,
494 float y, 495 float y,
495 float raw_x, 496 float raw_x,
(...skipping 18 matching lines...) Expand all
514 int motion_event_id, 515 int motion_event_id,
515 MotionEvent::ToolType primary_tool_type, 516 MotionEvent::ToolType primary_tool_type,
516 base::TimeTicks time, 517 base::TimeTicks time,
517 float x, 518 float x,
518 float y, 519 float y,
519 float raw_x, 520 float raw_x,
520 float raw_y, 521 float raw_y,
521 size_t touch_point_count, 522 size_t touch_point_count,
522 const gfx::RectF& bounding_box, 523 const gfx::RectF& bounding_box,
523 int flags) { 524 int flags) {
524 return GestureEventData(GestureEventDetails(type, 0, 0), 525 return GestureEventData(GestureEventDetails(type),
525 motion_event_id, 526 motion_event_id,
526 primary_tool_type, 527 primary_tool_type,
527 time, 528 time,
528 x, 529 x,
529 y, 530 y,
530 raw_x, 531 raw_x,
531 raw_y, 532 raw_y,
532 touch_point_count, 533 touch_point_count,
533 bounding_box, 534 bounding_box,
534 flags); 535 flags);
535 } 536 }
536 537
537 GestureEventData CreateGesture(const GestureEventDetails& details, 538 GestureEventData CreateGesture(const GestureEventDetails& details,
538 const MotionEvent& event) { 539 const MotionEvent& event) {
539 return GestureEventData(details, 540 return GestureEventData(details,
540 event.GetId(), 541 event.GetId(),
541 event.GetToolType(), 542 event.GetToolType(),
542 event.GetEventTime(), 543 event.GetEventTime(),
543 event.GetX(), 544 event.GetX(),
544 event.GetY(), 545 event.GetY(),
545 event.GetRawX(), 546 event.GetRawX(),
546 event.GetRawY(), 547 event.GetRawY(),
547 event.GetPointerCount(), 548 event.GetPointerCount(),
548 GetBoundingBox(event, details.type()), 549 GetBoundingBox(event, details.type()),
549 event.GetFlags()); 550 event.GetFlags());
550 } 551 }
551 552
552 GestureEventData CreateGesture(EventType type, const MotionEvent& event) { 553 GestureEventData CreateGesture(EventType type, const MotionEvent& event) {
553 return CreateGesture(GestureEventDetails(type, 0, 0), event); 554 return CreateGesture(GestureEventDetails(type), event);
554 } 555 }
555 556
556 GestureEventData CreateTapGesture(EventType type, const MotionEvent& event) { 557 GestureEventData CreateTapGesture(EventType type, const MotionEvent& event) {
557 // Set the tap count to 1 even for ET_GESTURE_DOUBLE_TAP, in order to be 558 // Set the tap count to 1 even for ET_GESTURE_DOUBLE_TAP, in order to be
558 // consistent with double tap behavior on a mobile viewport. See 559 // consistent with double tap behavior on a mobile viewport. See
559 // crbug.com/234986 for context. 560 // crbug.com/234986 for context.
560 return CreateGesture(GestureEventDetails(type, 1, 0), event); 561 GestureEventDetails details(type);
562 details.set_tap_count(1);
563 return CreateGesture(details, event);
561 } 564 }
562 565
563 gfx::RectF GetBoundingBox(const MotionEvent& event, EventType type) { 566 gfx::RectF GetBoundingBox(const MotionEvent& event, EventType type) {
564 // Can't use gfx::RectF::Union, as it ignores touches with a radius of 0. 567 // Can't use gfx::RectF::Union, as it ignores touches with a radius of 0.
565 float left = std::numeric_limits<float>::max(); 568 float left = std::numeric_limits<float>::max();
566 float top = std::numeric_limits<float>::max(); 569 float top = std::numeric_limits<float>::max();
567 float right = -std::numeric_limits<float>::max(); 570 float right = -std::numeric_limits<float>::max();
568 float bottom = -std::numeric_limits<float>::max(); 571 float bottom = -std::numeric_limits<float>::max();
569 for (size_t i = 0; i < event.GetPointerCount(); ++i) { 572 for (size_t i = 0; i < event.GetPointerCount(); ++i) {
570 float x, y, diameter; 573 float x, y, diameter;
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
809 // null'ing of the listener until the sequence has ended. 812 // null'ing of the listener until the sequence has ended.
810 if (current_down_event_) 813 if (current_down_event_)
811 return; 814 return;
812 815
813 const bool double_tap_enabled = 816 const bool double_tap_enabled =
814 double_tap_support_for_page_ && double_tap_support_for_platform_; 817 double_tap_support_for_page_ && double_tap_support_for_platform_;
815 gesture_listener_->SetDoubleTapEnabled(double_tap_enabled); 818 gesture_listener_->SetDoubleTapEnabled(double_tap_enabled);
816 } 819 }
817 820
818 } // namespace ui 821 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698