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

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

Issue 623293004: replace OVERRIDE and FINAL with override and final in ui/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase on master 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 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 virtual 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 virtual 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 virtual 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 virtual 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 virtual 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 double distance = 284 double distance =
285 std::sqrt(distance_x * distance_x + distance_y * distance_y); 285 std::sqrt(distance_x * distance_x + distance_y * distance_y);
286 double epsilon = 1e-3; 286 double epsilon = 1e-3;
287 if (distance > epsilon) { 287 if (distance > epsilon) {
288 double ratio = 288 double ratio =
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 virtual 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 virtual 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 virtual bool OnTwoFingerTap(const MotionEvent& e1,
388 const MotionEvent& e2) OVERRIDE { 388 const MotionEvent& e2) override {
389 // The location of the two finger tap event should be the location of the 389 // The location of the two finger tap event should be the location of the
390 // primary pointer. 390 // primary pointer.
391 GestureEventDetails two_finger_tap_details( 391 GestureEventDetails two_finger_tap_details(
392 ET_GESTURE_TWO_FINGER_TAP, e1.GetTouchMajor(), e1.GetTouchMajor()); 392 ET_GESTURE_TWO_FINGER_TAP, e1.GetTouchMajor(), e1.GetTouchMajor());
393 Send(CreateGesture(two_finger_tap_details, 393 Send(CreateGesture(two_finger_tap_details,
394 e2.GetId(), 394 e2.GetId(),
395 e2.GetToolType(), 395 e2.GetToolType(),
396 e2.GetEventTime(), 396 e2.GetEventTime(),
397 e1.GetX(), 397 e1.GetX(),
398 e1.GetY(), 398 e1.GetY(),
399 e1.GetRawX(), 399 e1.GetRawX(),
400 e1.GetRawY(), 400 e1.GetRawY(),
401 e2.GetPointerCount(), 401 e2.GetPointerCount(),
402 GetBoundingBox(e2, two_finger_tap_details.type()), 402 GetBoundingBox(e2, two_finger_tap_details.type()),
403 e2.GetFlags())); 403 e2.GetFlags()));
404 return true; 404 return true;
405 } 405 }
406 406
407 virtual void OnShowPress(const MotionEvent& e) OVERRIDE { 407 virtual void OnShowPress(const MotionEvent& e) override {
408 GestureEventDetails show_press_details(ET_GESTURE_SHOW_PRESS); 408 GestureEventDetails show_press_details(ET_GESTURE_SHOW_PRESS);
409 show_press_event_sent_ = true; 409 show_press_event_sent_ = true;
410 Send(CreateGesture(show_press_details, e)); 410 Send(CreateGesture(show_press_details, e));
411 } 411 }
412 412
413 virtual bool OnSingleTapUp(const MotionEvent& e) OVERRIDE { 413 virtual bool OnSingleTapUp(const MotionEvent& e) override {
414 // This is a hack to address the issue where user hovers 414 // This is a hack to address the issue where user hovers
415 // over a link for longer than double_tap_timeout_, then 415 // over a link for longer than double_tap_timeout_, then
416 // OnSingleTapConfirmed() is not triggered. But we still 416 // OnSingleTapConfirmed() is not triggered. But we still
417 // want to trigger the tap event at UP. So we override 417 // want to trigger the tap event at UP. So we override
418 // OnSingleTapUp() in this case. This assumes singleTapUp 418 // OnSingleTapUp() in this case. This assumes singleTapUp
419 // gets always called before singleTapConfirmed. 419 // gets always called before singleTapConfirmed.
420 if (!ignore_single_tap_) { 420 if (!ignore_single_tap_) {
421 if (e.GetEventTime() - current_down_time_ > 421 if (e.GetEventTime() - current_down_time_ >
422 config_.gesture_detector_config.double_tap_timeout) { 422 config_.gesture_detector_config.double_tap_timeout) {
423 return OnSingleTapConfirmed(e); 423 return OnSingleTapConfirmed(e);
(...skipping 13 matching lines...) Expand all
437 !IsScaleGestureDetectionInProgress()) { 437 !IsScaleGestureDetectionInProgress()) {
438 GestureEventDetails long_tap_details(ET_GESTURE_LONG_TAP); 438 GestureEventDetails long_tap_details(ET_GESTURE_LONG_TAP);
439 Send(CreateGesture(long_tap_details, e)); 439 Send(CreateGesture(long_tap_details, e));
440 return true; 440 return true;
441 } 441 }
442 442
443 return false; 443 return false;
444 } 444 }
445 445
446 // DoubleTapListener implementation. 446 // DoubleTapListener implementation.
447 virtual bool OnSingleTapConfirmed(const MotionEvent& e) OVERRIDE { 447 virtual bool OnSingleTapConfirmed(const MotionEvent& e) override {
448 // Long taps in the edges of the screen have their events delayed by 448 // 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 449 // ContentViewHolder for tab swipe operations. As a consequence of the delay
450 // this method might be called after receiving the up event. 450 // this method might be called after receiving the up event.
451 // These corner cases should be ignored. 451 // These corner cases should be ignored.
452 if (ignore_single_tap_) 452 if (ignore_single_tap_)
453 return true; 453 return true;
454 454
455 ignore_single_tap_ = true; 455 ignore_single_tap_ = true;
456 456
457 Send(CreateTapGesture(ET_GESTURE_TAP, e)); 457 Send(CreateTapGesture(ET_GESTURE_TAP, e));
458 return true; 458 return true;
459 } 459 }
460 460
461 virtual bool OnDoubleTap(const MotionEvent& e) OVERRIDE { 461 virtual bool OnDoubleTap(const MotionEvent& e) override {
462 return scale_gesture_detector_.OnDoubleTap(e); 462 return scale_gesture_detector_.OnDoubleTap(e);
463 } 463 }
464 464
465 virtual bool OnDoubleTapEvent(const MotionEvent& e) OVERRIDE { 465 virtual bool OnDoubleTapEvent(const MotionEvent& e) override {
466 switch (e.GetAction()) { 466 switch (e.GetAction()) {
467 case MotionEvent::ACTION_DOWN: 467 case MotionEvent::ACTION_DOWN:
468 gesture_detector_.set_longpress_enabled(false); 468 gesture_detector_.set_longpress_enabled(false);
469 break; 469 break;
470 470
471 case MotionEvent::ACTION_UP: 471 case MotionEvent::ACTION_UP:
472 if (!IsPinchInProgress() && !IsScrollInProgress()) { 472 if (!IsPinchInProgress() && !IsScrollInProgress()) {
473 Send(CreateTapGesture(ET_GESTURE_DOUBLE_TAP, e)); 473 Send(CreateTapGesture(ET_GESTURE_DOUBLE_TAP, e));
474 return true; 474 return true;
475 } 475 }
476 break; 476 break;
477 477
478 default: 478 default:
479 break; 479 break;
480 } 480 }
481 return false; 481 return false;
482 } 482 }
483 483
484 virtual void OnLongPress(const MotionEvent& e) OVERRIDE { 484 virtual void OnLongPress(const MotionEvent& e) override {
485 DCHECK(!IsDoubleTapInProgress()); 485 DCHECK(!IsDoubleTapInProgress());
486 SetIgnoreSingleTap(true); 486 SetIgnoreSingleTap(true);
487 GestureEventDetails long_press_details(ET_GESTURE_LONG_PRESS); 487 GestureEventDetails long_press_details(ET_GESTURE_LONG_PRESS);
488 Send(CreateGesture(long_press_details, e)); 488 Send(CreateGesture(long_press_details, e));
489 } 489 }
490 490
491 GestureEventData CreateGesture(const GestureEventDetails& details, 491 GestureEventData CreateGesture(const GestureEventDetails& details,
492 int motion_event_id, 492 int motion_event_id,
493 MotionEvent::ToolType primary_tool_type, 493 MotionEvent::ToolType primary_tool_type,
494 base::TimeTicks time, 494 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. 813 // null'ing of the listener until the sequence has ended.
814 if (current_down_event_) 814 if (current_down_event_)
815 return; 815 return;
816 816
817 const bool double_tap_enabled = 817 const bool double_tap_enabled =
818 double_tap_support_for_page_ && double_tap_support_for_platform_; 818 double_tap_support_for_page_ && double_tap_support_for_platform_;
819 gesture_listener_->SetDoubleTapEnabled(double_tap_enabled); 819 gesture_listener_->SetDoubleTapEnabled(double_tap_enabled);
820 } 820 }
821 821
822 } // namespace ui 822 } // namespace ui
OLDNEW
« no previous file with comments | « ui/events/gesture_detection/filtered_gesture_provider.h ('k') | ui/events/gesture_detection/gesture_provider_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698