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) { ...@@ -207,13 +207,26 @@ void Pointer::OnMouseEvent(ui::MouseEvent* event) {
break; break;
} }
case ui::ET_SCROLL_FLING_START: { 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_->OnPointerScrollStop(event->time_stamp());
delegate_->OnPointerFrame(); delegate_->OnPointerFrame();
break; break;
} }
case ui::ET_SCROLL_FLING_CANCEL: { case ui::ET_SCROLL_FLING_CANCEL: {
delegate_->OnPointerScrollCancel(event->time_stamp()); // Fling cancel is generated very generously at every touch of the
delegate_->OnPointerFrame(); // 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; break;
} }
case ui::ET_MOUSE_MOVED: case ui::ET_MOUSE_MOVED:
...@@ -227,6 +240,7 @@ void Pointer::OnMouseEvent(ui::MouseEvent* event) { ...@@ -227,6 +240,7 @@ void Pointer::OnMouseEvent(ui::MouseEvent* event) {
break; break;
} }
last_event_type_ = event->type();
UpdateCursorScale(); UpdateCursorScale();
} }
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "components/exo/surface_observer.h" #include "components/exo/surface_observer.h"
#include "components/exo/wm_helper.h" #include "components/exo/wm_helper.h"
#include "ui/base/cursor/cursor.h" #include "ui/base/cursor/cursor.h"
#include "ui/events/event_constants.h"
#include "ui/events/event_handler.h" #include "ui/events/event_handler.h"
#include "ui/gfx/geometry/point.h" #include "ui/gfx/geometry/point.h"
#include "ui/gfx/geometry/point_f.h" #include "ui/gfx/geometry/point_f.h"
...@@ -107,6 +108,9 @@ class Pointer : public ui::EventHandler, ...@@ -107,6 +108,9 @@ class Pointer : public ui::EventHandler,
// Source used for cursor capture copy output requests. // Source used for cursor capture copy output requests.
const base::UnguessableToken cursor_capture_source_id_; 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. // Weak pointer factory used for cursor capture callbacks.
base::WeakPtrFactory<Pointer> cursor_capture_weak_ptr_factory_; base::WeakPtrFactory<Pointer> cursor_capture_weak_ptr_factory_;
......
...@@ -56,9 +56,6 @@ class PointerDelegate { ...@@ -56,9 +56,6 @@ class PointerDelegate {
const gfx::Vector2dF& offset, const gfx::Vector2dF& offset,
bool discrete) = 0; 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. // Called when pointer scroll has stopped and a fling is happening (e.g.
// lifting the fingers from the touchpad after scrolling quickly) // lifting the fingers from the touchpad after scrolling quickly)
virtual void OnPointerScrollStop(base::TimeTicks time_stamp) = 0; virtual void OnPointerScrollStop(base::TimeTicks time_stamp) = 0;
......
...@@ -37,7 +37,6 @@ class MockPointerDelegate : public PointerDelegate { ...@@ -37,7 +37,6 @@ class MockPointerDelegate : public PointerDelegate {
MOCK_METHOD3(OnPointerButton, void(base::TimeTicks, int, bool)); MOCK_METHOD3(OnPointerButton, void(base::TimeTicks, int, bool));
MOCK_METHOD3(OnPointerScroll, MOCK_METHOD3(OnPointerScroll,
void(base::TimeTicks, const gfx::Vector2dF&, bool)); void(base::TimeTicks, const gfx::Vector2dF&, bool));
MOCK_METHOD1(OnPointerScrollCancel, void(base::TimeTicks));
MOCK_METHOD1(OnPointerScrollStop, void(base::TimeTicks)); MOCK_METHOD1(OnPointerScrollStop, void(base::TimeTicks));
MOCK_METHOD0(OnPointerFrame, void()); MOCK_METHOD0(OnPointerFrame, void());
}; };
...@@ -245,7 +244,7 @@ TEST_F(PointerTest, OnPointerScroll) { ...@@ -245,7 +244,7 @@ TEST_F(PointerTest, OnPointerScroll) {
EXPECT_CALL(delegate, CanAcceptPointerEventsForSurface(surface.get())) EXPECT_CALL(delegate, CanAcceptPointerEventsForSurface(surface.get()))
.WillRepeatedly(testing::Return(true)); .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)); EXPECT_CALL(delegate, OnPointerEnter(surface.get(), gfx::PointF(), 0));
generator.MoveMouseTo(location); generator.MoveMouseTo(location);
...@@ -254,7 +253,6 @@ TEST_F(PointerTest, OnPointerScroll) { ...@@ -254,7 +253,6 @@ TEST_F(PointerTest, OnPointerScroll) {
// Expect fling stop followed by scroll and scroll stop. // Expect fling stop followed by scroll and scroll stop.
testing::InSequence sequence; testing::InSequence sequence;
EXPECT_CALL(delegate, OnPointerScrollCancel(testing::_));
EXPECT_CALL(delegate, EXPECT_CALL(delegate,
OnPointerScroll(testing::_, gfx::Vector2dF(1.2, 1.2), false)); OnPointerScroll(testing::_, gfx::Vector2dF(1.2, 1.2), false));
EXPECT_CALL(delegate, OnPointerScrollStop(testing::_)); EXPECT_CALL(delegate, OnPointerScrollStop(testing::_));
...@@ -352,7 +350,6 @@ TEST_F(PointerTest, IgnorePointerEventDuringModal) { ...@@ -352,7 +350,6 @@ TEST_F(PointerTest, IgnorePointerEventDuringModal) {
{ {
testing::InSequence sequence; testing::InSequence sequence;
EXPECT_CALL(delegate, OnPointerScrollCancel(testing::_));
EXPECT_CALL(delegate, EXPECT_CALL(delegate,
OnPointerScroll(testing::_, gfx::Vector2dF(1.2, 1.2), false)); OnPointerScroll(testing::_, gfx::Vector2dF(1.2, 1.2), false));
EXPECT_CALL(delegate, OnPointerScrollStop(testing::_)); EXPECT_CALL(delegate, OnPointerScrollStop(testing::_));
...@@ -393,7 +390,6 @@ TEST_F(PointerTest, IgnorePointerEventDuringModal) { ...@@ -393,7 +390,6 @@ TEST_F(PointerTest, IgnorePointerEventDuringModal) {
{ {
testing::InSequence sequence; testing::InSequence sequence;
EXPECT_CALL(delegate, OnPointerScrollCancel(testing::_)).Times(0);
EXPECT_CALL(delegate, EXPECT_CALL(delegate,
OnPointerScroll(testing::_, gfx::Vector2dF(1.2, 1.2), false)) OnPointerScroll(testing::_, gfx::Vector2dF(1.2, 1.2), false))
.Times(0); .Times(0);
...@@ -435,7 +431,6 @@ TEST_F(PointerTest, IgnorePointerEventDuringModal) { ...@@ -435,7 +431,6 @@ TEST_F(PointerTest, IgnorePointerEventDuringModal) {
{ {
testing::InSequence sequence; testing::InSequence sequence;
EXPECT_CALL(delegate, OnPointerScrollCancel(testing::_));
EXPECT_CALL(delegate, EXPECT_CALL(delegate,
OnPointerScroll(testing::_, gfx::Vector2dF(1.2, 1.2), false)); OnPointerScroll(testing::_, gfx::Vector2dF(1.2, 1.2), false));
EXPECT_CALL(delegate, OnPointerScrollStop(testing::_)); EXPECT_CALL(delegate, OnPointerScrollStop(testing::_));
......
...@@ -2661,12 +2661,6 @@ class WaylandPointerDelegate : public PointerDelegate { ...@@ -2661,12 +2661,6 @@ class WaylandPointerDelegate : public PointerDelegate {
WL_POINTER_AXIS_VERTICAL_SCROLL, WL_POINTER_AXIS_VERTICAL_SCROLL,
wl_fixed_from_double(-y_value)); 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 { void OnPointerScrollStop(base::TimeTicks time_stamp) override {
if (wl_resource_get_version(pointer_resource_) >= if (wl_resource_get_version(pointer_resource_) >=
WL_POINTER_AXIS_STOP_SINCE_VERSION) { 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