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

Unified Diff: content/browser/renderer_host/input/touch_event_queue.cc

Issue 23856016: Send touch cancel to renderer when scrolling starts (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 7 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/renderer_host/input/touch_event_queue.cc
diff --git a/content/browser/renderer_host/input/touch_event_queue.cc b/content/browser/renderer_host/input/touch_event_queue.cc
index e22c05d0f80ff504cdbcdd8408c55dd3b030bb06..fefb4691da08cc0512848533adfbbfdb17539a53 100644
--- a/content/browser/renderer_host/input/touch_event_queue.cc
+++ b/content/browser/renderer_host/input/touch_event_queue.cc
@@ -92,7 +92,8 @@ class CoalescedWebTouchEvent {
TouchEventQueue::TouchEventQueue(TouchEventQueueClient* client)
: client_(client),
dispatching_touch_ack_(false),
- no_touch_move_to_renderer_(false) {
+ no_touch_to_renderer_(false),
+ synthesized_cancel_event_(NULL) {
DCHECK(client);
}
@@ -102,6 +103,7 @@ TouchEventQueue::~TouchEventQueue() {
}
void TouchEventQueue::QueueEvent(const TouchEventWithLatencyInfo& event) {
+ latest_event_ = event;
// If the queueing of |event| was triggered by an ack dispatch, defer
// processing the event until the dispatch has finished.
if (touch_queue_.empty() && !dispatching_touch_ack_) {
@@ -120,8 +122,10 @@ void TouchEventQueue::QueueEvent(const TouchEventWithLatencyInfo& event) {
// also a touch-move, then the events can be coalesced into a single event.
if (touch_queue_.size() > 1) {
CoalescedWebTouchEvent* last_event = touch_queue_.back();
- if (last_event->CoalesceEventIfPossible(event))
+ if (last_event->CoalesceEventIfPossible(event)) {
+ latest_event_ = last_event->coalesced_event();
return;
+ }
}
touch_queue_.push_back(new CoalescedWebTouchEvent(event));
}
@@ -168,6 +172,28 @@ void TouchEventQueue::ProcessTouchAck(InputEventAckState ack_result,
}
}
+void TouchEventQueue::OnGestureScrollEvent(
+ const GestureEventWithLatencyInfo& gesture_event) {
+ if (gesture_event.event.type == WebKit::WebInputEvent::GestureScrollBegin) {
+ if (no_touch_to_renderer_)
+ return;
+ no_touch_to_renderer_ = true;
+ TouchEventWithLatencyInfo cancel_event = GetLatestEvent();
+ cancel_event.event.type = WebKit::WebInputEvent::TouchCancel;
+ for (size_t i = 0; i < cancel_event.event.touchesLength; i++)
+ cancel_event.event.touches[i].state =
+ WebKit::WebTouchPoint::StateCancelled;
+ DCHECK(!synthesized_cancel_event_);
+ synthesized_cancel_event_ = new CoalescedWebTouchEvent(cancel_event);
+ touch_queue_.push_front(synthesized_cancel_event_);
sadrul 2013/09/23 16:17:33 When is this cancel event actually dispatched to t
jdduke (slow) 2013/09/23 16:34:34 Inserting the cancel at the front... The only way
Yufeng Shen (Slow to review) 2013/09/23 20:49:34 How about : 1) if the touch_queue_ is empty, we en
+ }
+
+ if (gesture_event.event.type == WebKit::WebInputEvent::GestureScrollEnd ||
sadrul 2013/09/23 16:17:33 else if
+ gesture_event.event.type == WebKit::WebInputEvent::GestureFlingStart) {
+ no_touch_to_renderer_ = false;
+ }
+}
+
void TouchEventQueue::FlushQueue() {
DCHECK(!dispatching_touch_ack_);
while (!touch_queue_.empty())
@@ -180,7 +206,7 @@ size_t TouchEventQueue::GetQueueSize() const {
}
const TouchEventWithLatencyInfo& TouchEventQueue::GetLatestEvent() const {
- return touch_queue_.back()->coalesced_event();
+ return latest_event_;
}
void TouchEventQueue::PopTouchEventToClient(
@@ -191,6 +217,12 @@ void TouchEventQueue::PopTouchEventToClient(
scoped_ptr<CoalescedWebTouchEvent> acked_event(touch_queue_.front());
touch_queue_.pop_front();
+ // Don't send the synthesized touch cancel to view.
+ if (acked_event.get() == synthesized_cancel_event_) {
+ synthesized_cancel_event_ = NULL;
+ return;
+ }
+
// Note that acking the touch-event may result in multiple gestures being sent
// to the renderer, or touch-events being queued.
base::AutoReset<bool> dispatching_touch_ack(&dispatching_touch_ack_, true);
@@ -209,14 +241,14 @@ void TouchEventQueue::PopTouchEventToClient(
bool TouchEventQueue::ShouldForwardToRenderer(
const WebKit::WebTouchEvent& event) const {
+ if (no_touch_to_renderer_ &&
+ event.type != WebKit::WebInputEvent::TouchCancel)
+ return false;
+
// Touch press events should always be forwarded to the renderer.
if (event.type == WebKit::WebInputEvent::TouchStart)
return true;
- if (event.type == WebKit::WebInputEvent::TouchMove &&
- no_touch_move_to_renderer_)
- return false;
-
for (unsigned int i = 0; i < event.touchesLength; ++i) {
const WebKit::WebTouchPoint& point = event.touches[i];
// If a point has been stationary, then don't take it into account.

Powered by Google App Engine
This is Rietveld 408576698