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

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

Issue 667923002: Standardize usage of virtual/override/final in ui/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 return; 187 return;
188 default: 188 default:
189 break; 189 break;
190 }; 190 };
191 191
192 client_->OnGestureEvent(gesture); 192 client_->OnGestureEvent(gesture);
193 GestureTouchUMAHistogram::RecordGestureEvent(gesture); 193 GestureTouchUMAHistogram::RecordGestureEvent(gesture);
194 } 194 }
195 195
196 // ScaleGestureListener implementation. 196 // ScaleGestureListener implementation.
197 virtual bool OnScaleBegin(const ScaleGestureDetector& detector, 197 bool OnScaleBegin(const ScaleGestureDetector& detector,
198 const MotionEvent& e) override { 198 const MotionEvent& e) override {
199 if (ignore_multitouch_zoom_events_ && !detector.InDoubleTapMode()) 199 if (ignore_multitouch_zoom_events_ && !detector.InDoubleTapMode())
200 return false; 200 return false;
201 return true; 201 return true;
202 } 202 }
203 203
204 virtual void OnScaleEnd(const ScaleGestureDetector& detector, 204 void OnScaleEnd(const ScaleGestureDetector& detector,
205 const MotionEvent& e) override { 205 const MotionEvent& e) override {
206 if (!pinch_event_sent_) 206 if (!pinch_event_sent_)
207 return; 207 return;
208 Send(CreateGesture(ET_GESTURE_PINCH_END, e)); 208 Send(CreateGesture(ET_GESTURE_PINCH_END, e));
209 } 209 }
210 210
211 virtual bool OnScale(const ScaleGestureDetector& detector, 211 bool OnScale(const ScaleGestureDetector& detector,
212 const MotionEvent& e) override { 212 const MotionEvent& e) override {
213 if (ignore_multitouch_zoom_events_ && !detector.InDoubleTapMode()) 213 if (ignore_multitouch_zoom_events_ && !detector.InDoubleTapMode())
214 return false; 214 return false;
215 if (!pinch_event_sent_) { 215 if (!pinch_event_sent_) {
216 Send(CreateGesture(ET_GESTURE_PINCH_BEGIN, 216 Send(CreateGesture(ET_GESTURE_PINCH_BEGIN,
217 e.GetId(), 217 e.GetId(),
218 e.GetToolType(), 218 e.GetToolType(),
219 detector.GetEventTime(), 219 detector.GetEventTime(),
220 detector.GetFocusX(), 220 detector.GetFocusX(),
221 detector.GetFocusY(), 221 detector.GetFocusY(),
222 detector.GetFocusX() + e.GetRawOffsetX(), 222 detector.GetFocusX() + e.GetRawOffsetX(),
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 detector.GetFocusY(), 257 detector.GetFocusY(),
258 detector.GetFocusX() + e.GetRawOffsetX(), 258 detector.GetFocusX() + e.GetRawOffsetX(),
259 detector.GetFocusY() + e.GetRawOffsetY(), 259 detector.GetFocusY() + e.GetRawOffsetY(),
260 e.GetPointerCount(), 260 e.GetPointerCount(),
261 GetBoundingBox(e, pinch_details.type()), 261 GetBoundingBox(e, pinch_details.type()),
262 e.GetFlags())); 262 e.GetFlags()));
263 return true; 263 return true;
264 } 264 }
265 265
266 // GestureListener implementation. 266 // GestureListener implementation.
267 virtual bool OnDown(const MotionEvent& e) override { 267 bool OnDown(const MotionEvent& e) override {
268 GestureEventDetails tap_details(ET_GESTURE_TAP_DOWN); 268 GestureEventDetails tap_details(ET_GESTURE_TAP_DOWN);
269 Send(CreateGesture(tap_details, e)); 269 Send(CreateGesture(tap_details, e));
270 270
271 // Return true to indicate that we want to handle touch. 271 // Return true to indicate that we want to handle touch.
272 return true; 272 return true;
273 } 273 }
274 274
275 virtual bool OnScroll(const MotionEvent& e1, 275 bool OnScroll(const MotionEvent& e1,
276 const MotionEvent& e2, 276 const MotionEvent& e2,
277 float raw_distance_x, 277 float raw_distance_x,
278 float raw_distance_y) override { 278 float raw_distance_y) override {
279 float distance_x = raw_distance_x; 279 float distance_x = raw_distance_x;
280 float distance_y = raw_distance_y; 280 float distance_y = raw_distance_y;
281 if (!scroll_event_sent_) { 281 if (!scroll_event_sent_) {
282 // Remove the touch slop region from the first scroll event to avoid a 282 // Remove the touch slop region from the first scroll event to avoid a
283 // jump. 283 // jump.
284 float distance = 284 float distance =
285 std::sqrt(distance_x * distance_x + distance_y * distance_y); 285 std::sqrt(distance_x * distance_x + distance_y * distance_y);
286 float epsilon = 1e-3f; 286 float epsilon = 1e-3f;
287 if (distance > epsilon) { 287 if (distance > epsilon) {
288 float ratio = 288 float ratio =
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 raw_center.x(), 338 raw_center.x(),
339 raw_center.y(), 339 raw_center.y(),
340 e2.GetPointerCount(), 340 e2.GetPointerCount(),
341 bounding_box, 341 bounding_box,
342 e2.GetFlags())); 342 e2.GetFlags()));
343 } 343 }
344 344
345 return true; 345 return true;
346 } 346 }
347 347
348 virtual bool OnFling(const MotionEvent& e1, 348 bool OnFling(const MotionEvent& e1,
349 const MotionEvent& e2, 349 const MotionEvent& e2,
350 float velocity_x, 350 float velocity_x,
351 float velocity_y) override { 351 float velocity_y) override {
352 if (snap_scroll_controller_.IsSnappingScrolls()) { 352 if (snap_scroll_controller_.IsSnappingScrolls()) {
353 if (snap_scroll_controller_.IsSnapHorizontal()) { 353 if (snap_scroll_controller_.IsSnapHorizontal()) {
354 velocity_y = 0; 354 velocity_y = 0;
355 } else { 355 } else {
356 velocity_x = 0; 356 velocity_x = 0;
357 } 357 }
358 } 358 }
359 359
360 if (!velocity_x && !velocity_y) 360 if (!velocity_x && !velocity_y)
361 return true; 361 return true;
362 362
363 if (!scroll_event_sent_) { 363 if (!scroll_event_sent_) {
364 // The native side needs a ET_GESTURE_SCROLL_BEGIN before 364 // The native side needs a ET_GESTURE_SCROLL_BEGIN before
365 // ET_SCROLL_FLING_START to send the fling to the correct target. 365 // ET_SCROLL_FLING_START to send the fling to the correct target.
366 // The distance traveled in one second is a reasonable scroll start hint. 366 // The distance traveled in one second is a reasonable scroll start hint.
367 GestureEventDetails scroll_details( 367 GestureEventDetails scroll_details(
368 ET_GESTURE_SCROLL_BEGIN, velocity_x, velocity_y); 368 ET_GESTURE_SCROLL_BEGIN, velocity_x, velocity_y);
369 Send(CreateGesture(scroll_details, e2)); 369 Send(CreateGesture(scroll_details, e2));
370 } 370 }
371 371
372 GestureEventDetails fling_details( 372 GestureEventDetails fling_details(
373 ET_SCROLL_FLING_START, velocity_x, velocity_y); 373 ET_SCROLL_FLING_START, velocity_x, velocity_y);
374 Send(CreateGesture(fling_details, e2)); 374 Send(CreateGesture(fling_details, e2));
375 return true; 375 return true;
376 } 376 }
377 377
378 virtual bool OnSwipe(const MotionEvent& e1, 378 bool OnSwipe(const MotionEvent& e1,
379 const MotionEvent& e2, 379 const MotionEvent& e2,
380 float velocity_x, 380 float velocity_x,
381 float velocity_y) override { 381 float velocity_y) override {
382 GestureEventDetails swipe_details(ET_GESTURE_SWIPE, velocity_x, velocity_y); 382 GestureEventDetails swipe_details(ET_GESTURE_SWIPE, velocity_x, velocity_y);
383 Send(CreateGesture(swipe_details, e2)); 383 Send(CreateGesture(swipe_details, e2));
384 return true; 384 return true;
385 } 385 }
386 386
387 virtual bool OnTwoFingerTap(const MotionEvent& e1, 387 bool OnTwoFingerTap(const MotionEvent& e1, const MotionEvent& e2) override {
388 const MotionEvent& e2) override {
389 // The location of the two finger tap event should be the location of the 388 // The location of the two finger tap event should be the location of the
390 // primary pointer. 389 // primary pointer.
391 GestureEventDetails two_finger_tap_details( 390 GestureEventDetails two_finger_tap_details(
392 ET_GESTURE_TWO_FINGER_TAP, e1.GetTouchMajor(), e1.GetTouchMajor()); 391 ET_GESTURE_TWO_FINGER_TAP, e1.GetTouchMajor(), e1.GetTouchMajor());
393 Send(CreateGesture(two_finger_tap_details, 392 Send(CreateGesture(two_finger_tap_details,
394 e2.GetId(), 393 e2.GetId(),
395 e2.GetToolType(), 394 e2.GetToolType(),
396 e2.GetEventTime(), 395 e2.GetEventTime(),
397 e1.GetX(), 396 e1.GetX(),
398 e1.GetY(), 397 e1.GetY(),
399 e1.GetRawX(), 398 e1.GetRawX(),
400 e1.GetRawY(), 399 e1.GetRawY(),
401 e2.GetPointerCount(), 400 e2.GetPointerCount(),
402 GetBoundingBox(e2, two_finger_tap_details.type()), 401 GetBoundingBox(e2, two_finger_tap_details.type()),
403 e2.GetFlags())); 402 e2.GetFlags()));
404 return true; 403 return true;
405 } 404 }
406 405
407 virtual void OnShowPress(const MotionEvent& e) override { 406 void OnShowPress(const MotionEvent& e) override {
408 GestureEventDetails show_press_details(ET_GESTURE_SHOW_PRESS); 407 GestureEventDetails show_press_details(ET_GESTURE_SHOW_PRESS);
409 show_press_event_sent_ = true; 408 show_press_event_sent_ = true;
410 Send(CreateGesture(show_press_details, e)); 409 Send(CreateGesture(show_press_details, e));
411 } 410 }
412 411
413 virtual bool OnSingleTapUp(const MotionEvent& e) override { 412 bool OnSingleTapUp(const MotionEvent& e) override {
414 // This is a hack to address the issue where user hovers 413 // This is a hack to address the issue where user hovers
415 // over a link for longer than double_tap_timeout_, then 414 // over a link for longer than double_tap_timeout_, then
416 // OnSingleTapConfirmed() is not triggered. But we still 415 // OnSingleTapConfirmed() is not triggered. But we still
417 // want to trigger the tap event at UP. So we override 416 // want to trigger the tap event at UP. So we override
418 // OnSingleTapUp() in this case. This assumes singleTapUp 417 // OnSingleTapUp() in this case. This assumes singleTapUp
419 // gets always called before singleTapConfirmed. 418 // gets always called before singleTapConfirmed.
420 if (!ignore_single_tap_) { 419 if (!ignore_single_tap_) {
421 if (e.GetEventTime() - current_down_time_ > 420 if (e.GetEventTime() - current_down_time_ >
422 config_.gesture_detector_config.double_tap_timeout) { 421 config_.gesture_detector_config.double_tap_timeout) {
423 return OnSingleTapConfirmed(e); 422 return OnSingleTapConfirmed(e);
(...skipping 13 matching lines...) Expand all
437 !IsScaleGestureDetectionInProgress()) { 436 !IsScaleGestureDetectionInProgress()) {
438 GestureEventDetails long_tap_details(ET_GESTURE_LONG_TAP); 437 GestureEventDetails long_tap_details(ET_GESTURE_LONG_TAP);
439 Send(CreateGesture(long_tap_details, e)); 438 Send(CreateGesture(long_tap_details, e));
440 return true; 439 return true;
441 } 440 }
442 441
443 return false; 442 return false;
444 } 443 }
445 444
446 // DoubleTapListener implementation. 445 // DoubleTapListener implementation.
447 virtual bool OnSingleTapConfirmed(const MotionEvent& e) override { 446 bool OnSingleTapConfirmed(const MotionEvent& e) override {
448 // 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
449 // ContentViewHolder for tab swipe operations. As a consequence of the delay 448 // ContentViewHolder for tab swipe operations. As a consequence of the delay
450 // this method might be called after receiving the up event. 449 // this method might be called after receiving the up event.
451 // These corner cases should be ignored. 450 // These corner cases should be ignored.
452 if (ignore_single_tap_) 451 if (ignore_single_tap_)
453 return true; 452 return true;
454 453
455 ignore_single_tap_ = true; 454 ignore_single_tap_ = true;
456 455
457 Send(CreateTapGesture(ET_GESTURE_TAP, e)); 456 Send(CreateTapGesture(ET_GESTURE_TAP, e));
458 return true; 457 return true;
459 } 458 }
460 459
461 virtual bool OnDoubleTap(const MotionEvent& e) override { 460 bool OnDoubleTap(const MotionEvent& e) override {
462 return scale_gesture_detector_.OnDoubleTap(e); 461 return scale_gesture_detector_.OnDoubleTap(e);
463 } 462 }
464 463
465 virtual bool OnDoubleTapEvent(const MotionEvent& e) override { 464 bool OnDoubleTapEvent(const MotionEvent& e) override {
466 switch (e.GetAction()) { 465 switch (e.GetAction()) {
467 case MotionEvent::ACTION_DOWN: 466 case MotionEvent::ACTION_DOWN:
468 gesture_detector_.set_longpress_enabled(false); 467 gesture_detector_.set_longpress_enabled(false);
469 break; 468 break;
470 469
471 case MotionEvent::ACTION_UP: 470 case MotionEvent::ACTION_UP:
472 if (!IsPinchInProgress() && !IsScrollInProgress()) { 471 if (!IsPinchInProgress() && !IsScrollInProgress()) {
473 Send(CreateTapGesture(ET_GESTURE_DOUBLE_TAP, e)); 472 Send(CreateTapGesture(ET_GESTURE_DOUBLE_TAP, e));
474 return true; 473 return true;
475 } 474 }
476 break; 475 break;
477 476
478 default: 477 default:
479 break; 478 break;
480 } 479 }
481 return false; 480 return false;
482 } 481 }
483 482
484 virtual void OnLongPress(const MotionEvent& e) override { 483 void OnLongPress(const MotionEvent& e) override {
485 DCHECK(!IsDoubleTapInProgress()); 484 DCHECK(!IsDoubleTapInProgress());
486 SetIgnoreSingleTap(true); 485 SetIgnoreSingleTap(true);
487 GestureEventDetails long_press_details(ET_GESTURE_LONG_PRESS); 486 GestureEventDetails long_press_details(ET_GESTURE_LONG_PRESS);
488 Send(CreateGesture(long_press_details, e)); 487 Send(CreateGesture(long_press_details, e));
489 } 488 }
490 489
491 GestureEventData CreateGesture(const GestureEventDetails& details, 490 GestureEventData CreateGesture(const GestureEventDetails& details,
492 int motion_event_id, 491 int motion_event_id,
493 MotionEvent::ToolType primary_tool_type, 492 MotionEvent::ToolType primary_tool_type,
494 base::TimeTicks time, 493 base::TimeTicks time,
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
813 // null'ing of the listener until the sequence has ended. 812 // null'ing of the listener until the sequence has ended.
814 if (current_down_event_) 813 if (current_down_event_)
815 return; 814 return;
816 815
817 const bool double_tap_enabled = 816 const bool double_tap_enabled =
818 double_tap_support_for_page_ && double_tap_support_for_platform_; 817 double_tap_support_for_page_ && double_tap_support_for_platform_;
819 gesture_listener_->SetDoubleTapEnabled(double_tap_enabled); 818 gesture_listener_->SetDoubleTapEnabled(double_tap_enabled);
820 } 819 }
821 820
822 } // namespace ui 821 } // namespace ui
OLDNEW
« no previous file with comments | « ui/events/gesture_detection/gesture_listeners.h ('k') | ui/events/gesture_detection/motion_event_buffer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698