diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2019-07-31 15:50:41 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2019-08-30 12:35:23 +0000 |
commit | 7b2ffa587235a47d4094787d72f38102089f402a (patch) | |
tree | 30e82af9cbab08a7fa028bb18f4f2987a3f74dfa /chromium/ui/events/gesture_detection | |
parent | d94af01c90575348c4e81a418257f254b6f8d225 (diff) | |
download | qtwebengine-chromium-7b2ffa587235a47d4094787d72f38102089f402a.tar.gz |
BASELINE: Update Chromium to 76.0.3809.94
Change-Id: I321c3f5f929c105aec0f98c5091ef6108822e647
Reviewed-by: Michael BrĂ¼ning <michael.bruning@qt.io>
Diffstat (limited to 'chromium/ui/events/gesture_detection')
3 files changed, 71 insertions, 10 deletions
diff --git a/chromium/ui/events/gesture_detection/OWNERS b/chromium/ui/events/gesture_detection/OWNERS index 74e4b5f44ad..7d088914c89 100644 --- a/chromium/ui/events/gesture_detection/OWNERS +++ b/chromium/ui/events/gesture_detection/OWNERS @@ -1,4 +1,5 @@ tdresser@chromium.org +nzolghadr@chromium.org per-file gesture_configuration_cast.cc=alexst@chromium.org per-file gesture_configuration_cast.cc=kpschoedel@chromium.org diff --git a/chromium/ui/events/gesture_detection/gesture_provider.cc b/chromium/ui/events/gesture_detection/gesture_provider.cc index d724b5dc819..6ac3854e70a 100644 --- a/chromium/ui/events/gesture_detection/gesture_provider.cc +++ b/chromium/ui/events/gesture_detection/gesture_provider.cc @@ -10,6 +10,7 @@ #include "base/auto_reset.h" #include "base/macros.h" +#include "base/metrics/histogram_macros.h" #include "base/trace_event/trace_event.h" #include "ui/events/event_constants.h" #include "ui/events/gesture_detection/gesture_event_data.h" @@ -125,7 +126,7 @@ class GestureProvider::GestureListenerImpl : public ScaleGestureListener, const MotionEvent::Action action = event.GetAction(); if (action == MotionEvent::Action::DOWN) { - current_down_time_ = event.GetEventTime(); + current_down_action_event_time_ = event.GetEventTime(); current_longpress_time_ = base::TimeTicks(); ignore_single_tap_ = false; scroll_event_sent_ = false; @@ -145,7 +146,9 @@ class GestureProvider::GestureListenerImpl : public ScaleGestureListener, // |Fling()| will have already signalled an end to touch-scrolling. if (scroll_event_sent_) Send(CreateGesture(ET_GESTURE_SCROLL_END, event)); - current_down_time_ = base::TimeTicks(); + + // Reset this to indicate no sequence is going on. + current_down_action_event_time_ = base::TimeTicks(); } else if (action == MotionEvent::Action::MOVE) { if (!show_press_event_sent_ && !scroll_event_sent_) { max_diameter_before_show_press_ = @@ -159,7 +162,8 @@ class GestureProvider::GestureListenerImpl : public ScaleGestureListener, // The only valid events that should be sent without an active touch // sequence are SHOW_PRESS and TAP, potentially triggered by the double-tap // delay timing out. - DCHECK(!current_down_time_.is_null() || gesture.type() == ET_GESTURE_TAP || + DCHECK(!current_down_action_event_time_.is_null() || + gesture.type() == ET_GESTURE_TAP || gesture.type() == ET_GESTURE_SHOW_PRESS || gesture.type() == ET_GESTURE_BEGIN || gesture.type() == ET_GESTURE_END); @@ -316,14 +320,16 @@ class GestureProvider::GestureListenerImpl : public ScaleGestureListener, float raw_distance_y) override { float distance_x = raw_distance_x; float distance_y = raw_distance_y; + base::TimeTicks original_event_timestamp; if (!scroll_event_sent_ && e2.GetPointerCount() < 3) { // Remove the touch slop region from the first scroll event to avoid a // jump. Touch slop isn't used for scroll gestures with greater than 2 // pointers down, in those cases we don't subtract the slop. - gfx::Vector2dF delta = + std::pair<gfx::Vector2dF, base::TimeTicks> slop_delta_with_timestamp = ComputeFirstScrollDelta(e1, e2, secondary_pointer_down); - distance_x = delta.x(); - distance_y = delta.y(); + distance_x = slop_delta_with_timestamp.first.x(); + distance_y = slop_delta_with_timestamp.first.y(); + original_event_timestamp = slop_delta_with_timestamp.second; } snap_scroll_controller_.UpdateSnapScrollMode(distance_x, distance_y); @@ -338,6 +344,15 @@ class GestureProvider::GestureListenerImpl : public ScaleGestureListener, return true; if (!scroll_event_sent_) { + if (!original_event_timestamp.is_null()) { + // Calculate the latency (and log once per gesture-based scroll + // initiation) by determining the amount of time it took from when + // the pointer down event happened until now (when we've recognized + // that it should be a scroll). + UMA_HISTOGRAM_TIMES("Event.Scroll.TouchGestureLatency", + base::TimeTicks::Now() - original_event_timestamp); + } + // Note that scroll start hints are in distance traveled, where // scroll deltas are in the opposite direction. GestureEventDetails scroll_details(ET_GESTURE_SCROLL_BEGIN, -distance_x, @@ -453,7 +468,7 @@ class GestureProvider::GestureListenerImpl : public ScaleGestureListener, // OnSingleTapUp() in this case. This assumes singleTapUp // gets always called before singleTapConfirmed. if (!ignore_single_tap_) { - if (e.GetEventTime() - current_down_time_ > + if (e.GetEventTime() - current_down_action_event_time_ > config_.gesture_detector_config.double_tap_timeout) { return OnSingleTapImpl(e, tap_count); } else if (!IsDoubleTapEnabled()) { @@ -696,7 +711,7 @@ class GestureProvider::GestureListenerImpl : public ScaleGestureListener, // for the first time, scroll delta is adjusted. // The new deltas are calculated for each pointer individually, // and the final scroll delta is the average over all delta values. - gfx::Vector2dF ComputeFirstScrollDelta( + std::pair<gfx::Vector2dF, base::TimeTicks> ComputeFirstScrollDelta( const MotionEvent& ev1, const MotionEvent& ev2, const MotionEvent& secondary_pointer_down) { @@ -705,6 +720,7 @@ class GestureProvider::GestureListenerImpl : public ScaleGestureListener, DCHECK(ev2.GetPointerCount() < 3); gfx::Vector2dF delta(0, 0); + base::TimeTicks original_timestamp; for (size_t i = 0; i < ev2.GetPointerCount(); i++) { const int pointer_id = ev2.GetPointerId(i); const MotionEvent* source_pointer_down_event = @@ -721,9 +737,13 @@ class GestureProvider::GestureListenerImpl : public ScaleGestureListener, float dx = source_pointer_down_event->GetX(source_index) - ev2.GetX(i); float dy = source_pointer_down_event->GetY(source_index) - ev2.GetY(i); delta += SubtractSlopRegion(dx, dy); + + if (original_timestamp.is_null()) { + original_timestamp = source_pointer_down_event->GetEventTime(); + } } delta.Scale(1.0 / ev2.GetPointerCount()); - return delta; + return std::make_pair(delta, original_timestamp); } const GestureProvider::Config config_; @@ -733,7 +753,9 @@ class GestureProvider::GestureListenerImpl : public ScaleGestureListener, ScaleGestureDetector scale_gesture_detector_; SnapScrollController snap_scroll_controller_; - base::TimeTicks current_down_time_; + // Keeps track of the event time of the first down action in current touch + // sequence. + base::TimeTicks current_down_action_event_time_; // Keeps track of the current GESTURE_LONG_PRESS event. If a context menu is // opened after a GESTURE_LONG_PRESS, this is used to insert a diff --git a/chromium/ui/events/gesture_detection/gesture_provider_unittest.cc b/chromium/ui/events/gesture_detection/gesture_provider_unittest.cc index 4cf65bc0863..760ef0225dc 100644 --- a/chromium/ui/events/gesture_detection/gesture_provider_unittest.cc +++ b/chromium/ui/events/gesture_detection/gesture_provider_unittest.cc @@ -12,6 +12,7 @@ #include "base/logging.h" #include "base/run_loop.h" #include "base/single_thread_task_runner.h" +#include "base/test/metrics/histogram_tester.h" #include "base/test/scoped_task_environment.h" #include "base/threading/thread_task_runner_handle.h" #include "base/time/time.h" @@ -704,6 +705,38 @@ TEST_F(GestureProviderTest, NoTapAfterScrollBegins) { EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_LONG_TAP)); } +TEST_F(GestureProviderTest, ScrollBeginLatencyUMA) { + auto histogram_tester = std::make_unique<base::HistogramTester>(); + base::TimeTicks event_time = base::TimeTicks::Now(); + + // Send in a DOWN and MOVE that exceeds the slop threshold, and validate + // that the UMA fires. + MockMotionEvent event = + ObtainMotionEvent(event_time, MotionEvent::Action::DOWN); + EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); + EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); + EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); + + const float touch_slop = GetTouchSlop(); + event = + ObtainMotionEvent(event_time + kOneMicrosecond, MotionEvent::Action::MOVE, + kFakeCoordX + 2 * touch_slop, kFakeCoordY); + EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); + EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, GetMostRecentGestureEventType()); + + base::TimeTicks complete_time = base::TimeTicks::Now(); + std::vector<base::Bucket> buckets = + histogram_tester->GetAllSamples("Event.Scroll.TouchGestureLatency"); + + EXPECT_EQ(buckets.size(), 1ULL); + EXPECT_LE(buckets.front().min, (complete_time - event_time).InMilliseconds()); + + event = ObtainMotionEvent(event_time + kOneSecond, MotionEvent::Action::UP, + kFakeCoordX + 2 * touch_slop, kFakeCoordY); + EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); + EXPECT_EQ(ET_GESTURE_SCROLL_END, GetMostRecentGestureEventType()); +} + TEST_F(GestureProviderTest, DoubleTap) { base::TimeTicks event_time = base::TimeTicks::Now(); @@ -972,6 +1005,7 @@ TEST_F(GestureProviderTest, SlopRegionCheckOnTwoFingerScroll) { EnableTwoFingerTap(kMaxTwoFingerTapSeparation, base::TimeDelta()); const float scaled_touch_slop = GetTouchSlop(); + auto histogram_tester = std::make_unique<base::HistogramTester>(); base::TimeTicks event_time = base::TimeTicks::Now(); MockMotionEvent event = @@ -1019,6 +1053,10 @@ TEST_F(GestureProviderTest, SlopRegionCheckOnTwoFingerScroll) { EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, GetReceivedGesture(3).type()); EXPECT_EQ(ET_GESTURE_SCROLL_END, GetReceivedGesture(4).type()); EXPECT_EQ(5U, GetReceivedGestureCount()); + + // Even when there are two pointers, we should only log the gesture latency + // one time. + histogram_tester->ExpectTotalCount("Event.Scroll.TouchGestureLatency", 1); } // This test simulates cases like (crbug.com/704426) in which some of the events |