Commit 2df8c301 authored by denniskempin's avatar denniskempin Committed by Commit bot

exo: Replace fling cancel with generic zero distance scroll

This change will suppress all fling cancel events unless the last event
was a fling event. Also it generates a proper sequence of a scroll
event with zero distance.

BUG=590754
TEST=Fling and touch the touchpad after fling. Should stop scrolling
motion in android apps.

Review-Url: https://codereview.chromium.org/2840113002
Cr-Commit-Position: refs/heads/master@{#469403}
parent 5a762e45
......@@ -207,13 +207,26 @@ void Pointer::OnMouseEvent(ui::MouseEvent* event) {
break;
}
case ui::ET_SCROLL_FLING_START: {
// Fling start in chrome signals the lifting of fingers after scrolling.
// In wayland terms this signals the end of a scroll sequence.
delegate_->OnPointerScrollStop(event->time_stamp());
delegate_->OnPointerFrame();
break;
}
case ui::ET_SCROLL_FLING_CANCEL: {
delegate_->OnPointerScrollCancel(event->time_stamp());
delegate_->OnPointerFrame();
// Fling cancel is generated very generously at every touch of the
// touchpad. Since it's not directly supported by the delegate, we do not
// want limit this event to only right after a fling start has been
// generated to prevent erronous behavior.
if (last_event_type_ == ui::ET_SCROLL_FLING_START) {
// We emulate fling cancel by starting a new scroll sequence that
// scrolls by 0 pixels, effectively stopping any kinetic scroll motion.
delegate_->OnPointerScroll(event->time_stamp(), gfx::Vector2dF(),
false);
delegate_->OnPointerFrame();
delegate_->OnPointerScrollStop(event->time_stamp());
delegate_->OnPointerFrame();
}
break;
}
case ui::ET_MOUSE_MOVED:
......@@ -227,6 +240,7 @@ void Pointer::OnMouseEvent(ui::MouseEvent* event) {
break;
}
last_event_type_ = event->type();
UpdateCursorScale();
}
......
......@@ -14,6 +14,7 @@
#include "components/exo/surface_observer.h"
#include "components/exo/wm_helper.h"
#include "ui/base/cursor/cursor.h"
#include "ui/events/event_constants.h"
#include "ui/events/event_handler.h"
#include "ui/gfx/geometry/point.h"
#include "ui/gfx/geometry/point_f.h"
......@@ -107,6 +108,9 @@ class Pointer : public ui::EventHandler,
// Source used for cursor capture copy output requests.
const base::UnguessableToken cursor_capture_source_id_;
// Last received event type.
ui::EventType last_event_type_ = ui::ET_UNKNOWN;
// Weak pointer factory used for cursor capture callbacks.
base::WeakPtrFactory<Pointer> cursor_capture_weak_ptr_factory_;
......
......@@ -56,9 +56,6 @@ class PointerDelegate {
const gfx::Vector2dF& offset,
bool discrete) = 0;
// Called when a current kinetic scroll should be canceled.
virtual void OnPointerScrollCancel(base::TimeTicks time_stamp) = 0;
// Called when pointer scroll has stopped and a fling is happening (e.g.
// lifting the fingers from the touchpad after scrolling quickly)
virtual void OnPointerScrollStop(base::TimeTicks time_stamp) = 0;
......
......@@ -37,7 +37,6 @@ class MockPointerDelegate : public PointerDelegate {
MOCK_METHOD3(OnPointerButton, void(base::TimeTicks, int, bool));
MOCK_METHOD3(OnPointerScroll,
void(base::TimeTicks, const gfx::Vector2dF&, bool));
MOCK_METHOD1(OnPointerScrollCancel, void(base::TimeTicks));
MOCK_METHOD1(OnPointerScrollStop, void(base::TimeTicks));
MOCK_METHOD0(OnPointerFrame, void());
};
......@@ -245,7 +244,7 @@ TEST_F(PointerTest, OnPointerScroll) {
EXPECT_CALL(delegate, CanAcceptPointerEventsForSurface(surface.get()))
.WillRepeatedly(testing::Return(true));
EXPECT_CALL(delegate, OnPointerFrame()).Times(4);
EXPECT_CALL(delegate, OnPointerFrame()).Times(3);
EXPECT_CALL(delegate, OnPointerEnter(surface.get(), gfx::PointF(), 0));
generator.MoveMouseTo(location);
......@@ -254,7 +253,6 @@ TEST_F(PointerTest, OnPointerScroll) {
// Expect fling stop followed by scroll and scroll stop.
testing::InSequence sequence;
EXPECT_CALL(delegate, OnPointerScrollCancel(testing::_));
EXPECT_CALL(delegate,
OnPointerScroll(testing::_, gfx::Vector2dF(1.2, 1.2), false));
EXPECT_CALL(delegate, OnPointerScrollStop(testing::_));
......@@ -352,7 +350,6 @@ TEST_F(PointerTest, IgnorePointerEventDuringModal) {
{
testing::InSequence sequence;
EXPECT_CALL(delegate, OnPointerScrollCancel(testing::_));
EXPECT_CALL(delegate,
OnPointerScroll(testing::_, gfx::Vector2dF(1.2, 1.2), false));
EXPECT_CALL(delegate, OnPointerScrollStop(testing::_));
......@@ -393,7 +390,6 @@ TEST_F(PointerTest, IgnorePointerEventDuringModal) {
{
testing::InSequence sequence;
EXPECT_CALL(delegate, OnPointerScrollCancel(testing::_)).Times(0);
EXPECT_CALL(delegate,
OnPointerScroll(testing::_, gfx::Vector2dF(1.2, 1.2), false))
.Times(0);
......@@ -435,7 +431,6 @@ TEST_F(PointerTest, IgnorePointerEventDuringModal) {
{
testing::InSequence sequence;
EXPECT_CALL(delegate, OnPointerScrollCancel(testing::_));
EXPECT_CALL(delegate,
OnPointerScroll(testing::_, gfx::Vector2dF(1.2, 1.2), false));
EXPECT_CALL(delegate, OnPointerScrollStop(testing::_));
......
......@@ -2661,12 +2661,6 @@ class WaylandPointerDelegate : public PointerDelegate {
WL_POINTER_AXIS_VERTICAL_SCROLL,
wl_fixed_from_double(-y_value));
}
void OnPointerScrollCancel(base::TimeTicks time_stamp) override {
// Wayland doesn't know the concept of a canceling kinetic scrolling.
// But we can send a 0 distance scroll to emulate this behavior.
OnPointerScroll(time_stamp, gfx::Vector2dF(0, 0), false);
OnPointerScrollStop(time_stamp);
}
void OnPointerScrollStop(base::TimeTicks time_stamp) override {
if (wl_resource_get_version(pointer_resource_) >=
WL_POINTER_AXIS_STOP_SINCE_VERSION) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment