Index: ui/events/blink/compositor_thread_event_queue.cc |
diff --git a/ui/events/blink/compositor_thread_event_queue.cc b/ui/events/blink/compositor_thread_event_queue.cc |
index 58290fd98b2e01e27b0da3a6c4806be98293a0a5..9a934b27e8a41a14bf9905df8074e85d934ecea2 100644 |
--- a/ui/events/blink/compositor_thread_event_queue.cc |
+++ b/ui/events/blink/compositor_thread_event_queue.cc |
@@ -4,22 +4,89 @@ |
#include "ui/events/blink/compositor_thread_event_queue.h" |
+#include "base/memory/ptr_util.h" |
+#include "ui/events/blink/blink_event_util.h" |
+#include "ui/events/blink/web_input_event_traits.h" |
+ |
namespace ui { |
CompositorThreadEventQueue::CompositorThreadEventQueue() {} |
CompositorThreadEventQueue::~CompositorThreadEventQueue() {} |
-// TODO(chongz): Support coalescing events across interleaved boundaries. |
-// https://crbug.com/661601 |
-void CompositorThreadEventQueue::Queue(std::unique_ptr<EventWithCallback> event, |
- base::TimeTicks timestamp_now) { |
- if (!queue_.empty() && queue_.back()->CanCoalesceWith(*event)) { |
- queue_.back()->CoalesceWith(event.get(), timestamp_now); |
+void CompositorThreadEventQueue::Queue( |
+ std::unique_ptr<EventWithCallback> new_event, |
+ base::TimeTicks timestamp_now) { |
+ if (queue_.empty() || !IsContinuousGestureEvent(new_event->event().type) || |
+ !IsCompatibleScrollorPinch(new_event->ToWebGestureEvent(), |
+ queue_.back()->ToWebGestureEvent())) { |
+ queue_.emplace_back(std::move(new_event)); |
+ return; |
+ } |
+ |
+ if (queue_.back()->CanCoalesceWith(*new_event)) { |
+ queue_.back()->CoalesceWith(new_event.get(), timestamp_now); |
return; |
} |
- queue_.emplace_back(std::move(event)); |
+ // Coalesce |GestureScrollUpdate| and |GesturePinchUpdate| in one sequence. |
+ EventWithCallback* last_event = queue_.back().get(); |
+ EventWithCallback* second_last_event = nullptr; |
+ if (queue_.size() > 1 && |
+ IsCompatibleScrollorPinch( |
+ new_event->ToWebGestureEvent(), |
+ queue_[queue_.size() - 2]->ToWebGestureEvent())) { |
+ second_last_event = queue_[queue_.size() - 2].get(); |
+ } |
+ |
+ std::pair<blink::WebGestureEvent, blink::WebGestureEvent> coalesced_events = |
dtapuska
2016/12/08 15:18:37
Isn't this complicated logic if second_last_event
chongz
2016/12/09 20:52:25
As discussed we have to go through the matrix as 2
|
+ CoalesceScrollAndPinch( |
+ second_last_event ? &second_last_event->ToWebGestureEvent() : nullptr, |
+ last_event->ToWebGestureEvent(), new_event->ToWebGestureEvent()); |
+ |
+ DCHECK_LE(last_event->latency_info().trace_id(), |
+ new_event->latency_info().trace_id()); |
+ if (second_last_event) { |
+ DCHECK_LE(second_last_event->latency_info().trace_id(), |
+ last_event->latency_info().trace_id()); |
+ } |
+ LatencyInfo oldest_latency = second_last_event |
+ ? second_last_event->latency_info() |
+ : last_event->latency_info(); |
+ oldest_latency.set_coalesced(); |
+ const base::TimeTicks oldest_creation_timestamp = |
+ second_last_event ? second_last_event->creation_timestamp() |
+ : last_event->creation_timestamp(); |
+ |
+ // Creating 2 events, but store original events in the last one. |
+ auto combined_original_events = |
+ base::MakeUnique<EventWithCallback::OriginalEventList>(); |
+ if (second_last_event) { |
+ combined_original_events->splice(combined_original_events->end(), |
+ second_last_event->original_events()); |
+ } |
+ combined_original_events->splice(combined_original_events->end(), |
+ last_event->original_events()); |
+ combined_original_events->splice(combined_original_events->end(), |
+ new_event->original_events()); |
+ |
+ std::unique_ptr<EventWithCallback> scroll_event = |
+ base::MakeUnique<EventWithCallback>( |
+ WebInputEventTraits::Clone(coalesced_events.first), oldest_latency, |
+ oldest_creation_timestamp, timestamp_now, nullptr); |
+ |
+ std::unique_ptr<EventWithCallback> pinch_event = |
+ base::MakeUnique<EventWithCallback>( |
+ WebInputEventTraits::Clone(coalesced_events.second), oldest_latency, |
+ oldest_creation_timestamp, timestamp_now, |
+ std::move(combined_original_events)); |
+ |
+ // Pop |last_event| and |second_last_event| first. |
+ queue_.pop_back(); |
+ if (second_last_event) |
+ queue_.pop_back(); |
+ queue_.emplace_back(std::move(scroll_event)); |
+ queue_.emplace_back(std::move(pinch_event)); |
} |
std::unique_ptr<EventWithCallback> CompositorThreadEventQueue::Pop() { |