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

Side by Side Diff: content/renderer/input/main_thread_event_queue.cc

Issue 2788203002: Adjust cancelabilty of touchmoves that are queued when scroll start occurs (Closed)
Patch Set: Created 3 years, 8 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "content/renderer/input/main_thread_event_queue.h" 5 #include "content/renderer/input/main_thread_event_queue.h"
6 6
7 #include "base/metrics/field_trial.h" 7 #include "base/metrics/field_trial.h"
8 #include "base/metrics/histogram_macros.h" 8 #include "base/metrics/histogram_macros.h"
9 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "content/common/input/event_with_latency_info.h" 10 #include "content/common/input/event_with_latency_info.h"
11 #include "content/common/input_messages.h" 11 #include "content/common/input_messages.h"
12 12
13 namespace content { 13 namespace content {
14 14
15 namespace { 15 namespace {
16 16
17 const size_t kTenSeconds = 10 * 1000 * 1000; 17 const size_t kTenSeconds = 10 * 1000 * 1000;
18 18
19 class QueuedClosure : public MainThreadEventQueueTask { 19 class QueuedClosure : public MainThreadEventQueueTask {
20 public: 20 public:
21 QueuedClosure(const base::Closure& closure) : closure_(closure) {} 21 QueuedClosure(const base::Closure& closure) : closure_(closure) {}
22 22
23 ~QueuedClosure() override {} 23 ~QueuedClosure() override {}
24 24
25 CoalesceResult CoalesceWith( 25 NotifyResult NotifyEventWillBeQueued(
26 const MainThreadEventQueueTask& other_task) override { 26 const MainThreadEventQueueTask& other_task) override {
27 return other_task.IsWebInputEvent() ? CoalesceResult::KeepSearching 27 return other_task.IsWebInputEvent() ? NotifyResult::KeepIterating
28 : CoalesceResult::CannotCoalesce; 28 : NotifyResult::Stop;
29 } 29 }
30 30
31 bool IsWebInputEvent() const override { return false; } 31 bool IsWebInputEvent() const override { return false; }
32 32
33 void Dispatch(int routing_id, MainThreadEventQueueClient*) override { 33 void Dispatch(int routing_id, MainThreadEventQueueClient*) override {
34 closure_.Run(); 34 closure_.Run();
35 } 35 }
36 36
37 void EventHandled(int routing_id, 37 void EventHandled(int routing_id,
38 blink::scheduler::RendererScheduler* renderer_scheduler, 38 blink::scheduler::RendererScheduler* renderer_scheduler,
(...skipping 15 matching lines...) Expand all
54 bool originally_cancelable) 54 bool originally_cancelable)
55 : ScopedWebInputEventWithLatencyInfo(std::move(event), latency), 55 : ScopedWebInputEventWithLatencyInfo(std::move(event), latency),
56 dispatch_type_(dispatch_type), 56 dispatch_type_(dispatch_type),
57 non_blocking_coalesced_count_(0), 57 non_blocking_coalesced_count_(0),
58 creation_timestamp_(base::TimeTicks::Now()), 58 creation_timestamp_(base::TimeTicks::Now()),
59 last_coalesced_timestamp_(creation_timestamp_), 59 last_coalesced_timestamp_(creation_timestamp_),
60 originally_cancelable_(originally_cancelable) {} 60 originally_cancelable_(originally_cancelable) {}
61 61
62 ~QueuedWebInputEvent() override {} 62 ~QueuedWebInputEvent() override {}
63 63
64 CoalesceResult CoalesceWith( 64 NotifyResult NotifyEventWillBeQueued(
65 const MainThreadEventQueueTask& other_item) override { 65 const MainThreadEventQueueTask& other_task) override {
66 if (!other_item.IsWebInputEvent()) 66 if (!other_task.IsWebInputEvent())
67 return CoalesceResult::CannotCoalesce; 67 return NotifyResult::Stop;
68 68
69 const QueuedWebInputEvent& other_event = 69 const QueuedWebInputEvent& other_event =
70 static_cast<const QueuedWebInputEvent&>(other_item); 70 static_cast<const QueuedWebInputEvent&>(other_task);
71 if (other_event.event().type() ==
72 blink::WebInputEvent::TouchScrollStarted) {
73 HandleTouchScrollStartQueued();
74 return NotifyResult::KeepIterating;
75 }
76
71 if (!event().isSameEventClass(other_event.event())) 77 if (!event().isSameEventClass(other_event.event()))
72 return CoalesceResult::KeepSearching; 78 return NotifyResult::KeepIterating;
73 79
74 if (!ScopedWebInputEventWithLatencyInfo::CanCoalesceWith(other_event)) 80 if (!ScopedWebInputEventWithLatencyInfo::CanCoalesceWith(other_event))
75 return CoalesceResult::CannotCoalesce; 81 return NotifyResult::Stop;
76 82
77 // If this event was blocking push the event id to the blocking 83 // If this event was blocking push the event id to the blocking
78 // list before updating the dispatch_type of this event. 84 // list before updating the dispatch_type of this event.
79 if (dispatch_type_ == DISPATCH_TYPE_BLOCKING) { 85 if (dispatch_type_ == DISPATCH_TYPE_BLOCKING) {
80 blocking_coalesced_event_ids_.push_back( 86 blocking_coalesced_event_ids_.push_back(
81 ui::WebInputEventTraits::GetUniqueTouchEventId(event())); 87 ui::WebInputEventTraits::GetUniqueTouchEventId(event()));
82 } else { 88 } else {
83 non_blocking_coalesced_count_++; 89 non_blocking_coalesced_count_++;
84 } 90 }
85 ScopedWebInputEventWithLatencyInfo::CoalesceWith(other_event); 91 ScopedWebInputEventWithLatencyInfo::CoalesceWith(other_event);
86 last_coalesced_timestamp_ = base::TimeTicks::Now(); 92 last_coalesced_timestamp_ = base::TimeTicks::Now();
87 93
88 // The newest event (|other_item|) always wins when updating fields. 94 // The newest event (|other_item|) always wins when updating fields.
89 dispatch_type_ = other_event.dispatch_type_; 95 dispatch_type_ = other_event.dispatch_type_;
90 originally_cancelable_ = other_event.originally_cancelable_; 96 originally_cancelable_ = other_event.originally_cancelable_;
91 97
92 return CoalesceResult::Coalesced; 98 return NotifyResult::CoalescedEvent;
93 } 99 }
94 100
95 bool IsWebInputEvent() const override { return true; } 101 bool IsWebInputEvent() const override { return true; }
96 102
97 void Dispatch(int routing_id, MainThreadEventQueueClient* client) override { 103 void Dispatch(int routing_id, MainThreadEventQueueClient* client) override {
98 // Report the coalesced count only for continuous events; otherwise 104 // Report the coalesced count only for continuous events; otherwise
99 // the zero value would be dominated by non-continuous events. 105 // the zero value would be dominated by non-continuous events.
100 base::TimeTicks now = base::TimeTicks::Now(); 106 base::TimeTicks now = base::TimeTicks::Now();
101 if (IsContinuousEvent()) { 107 if (IsContinuousEvent()) {
102 UMA_HISTOGRAM_CUSTOM_COUNTS( 108 UMA_HISTOGRAM_CUSTOM_COUNTS(
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 client->SendInputEventAck(routing_id, type, ack_result, id); 149 client->SendInputEventAck(routing_id, type, ack_result, id);
144 if (renderer_scheduler) { 150 if (renderer_scheduler) {
145 renderer_scheduler->DidHandleInputEventOnMainThread(event(), result); 151 renderer_scheduler->DidHandleInputEventOnMainThread(event(), result);
146 } 152 }
147 } 153 }
148 } 154 }
149 155
150 bool originallyCancelable() const { return originally_cancelable_; } 156 bool originallyCancelable() const { return originally_cancelable_; }
151 157
152 private: 158 private:
159 void HandleTouchScrollStartQueued() {
160 // A TouchScrollStart will queued after this touch move which will make all
161 // previous touch moves that are queued uncancelable.
162 if (event().type() == blink::WebInputEvent::TouchMove) {
163 blink::WebTouchEvent& touch_event =
164 static_cast<blink::WebTouchEvent&>(event());
165 if (touch_event.dispatchType ==
166 blink::WebInputEvent::DispatchType::Blocking) {
167 touch_event.dispatchType =
168 blink::WebInputEvent::DispatchType::EventNonBlocking;
169 }
170 }
171 }
172
153 const std::deque<uint32_t>& blockingCoalescedEventIds() const { 173 const std::deque<uint32_t>& blockingCoalescedEventIds() const {
154 return blocking_coalesced_event_ids_; 174 return blocking_coalesced_event_ids_;
155 } 175 }
156 InputEventDispatchType dispatchType() const { return dispatch_type_; } 176 InputEventDispatchType dispatchType() const { return dispatch_type_; }
157 base::TimeTicks creationTimestamp() const { return creation_timestamp_; } 177 base::TimeTicks creationTimestamp() const { return creation_timestamp_; }
158 base::TimeTicks lastCoalescedTimestamp() const { 178 base::TimeTicks lastCoalescedTimestamp() const {
159 return last_coalesced_timestamp_; 179 return last_coalesced_timestamp_;
160 } 180 }
161 181
162 size_t coalescedCount() const { 182 size_t coalescedCount() const {
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 case blink::WebInputEvent::MouseWheel: 522 case blink::WebInputEvent::MouseWheel:
503 return handle_raf_aligned_mouse_input_; 523 return handle_raf_aligned_mouse_input_;
504 case blink::WebInputEvent::TouchMove: 524 case blink::WebInputEvent::TouchMove:
505 return handle_raf_aligned_touch_input_; 525 return handle_raf_aligned_touch_input_;
506 default: 526 default:
507 return false; 527 return false;
508 } 528 }
509 } 529 }
510 530
511 } // namespace content 531 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698