OLD | NEW |
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/common/input/event_with_latency_info.h" | 5 #include "content/common/input/event_with_latency_info.h" |
6 | 6 |
7 #include <bitset> | 7 #include <bitset> |
8 #include <limits> | 8 #include <limits> |
9 | 9 |
10 using blink::WebGestureEvent; | 10 using blink::WebGestureEvent; |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 if (event_to_coalesce.type == blink::WebInputEvent::MouseWheel && | 255 if (event_to_coalesce.type == blink::WebInputEvent::MouseWheel && |
256 event->type == blink::WebInputEvent::MouseWheel) { | 256 event->type == blink::WebInputEvent::MouseWheel) { |
257 Coalesce(static_cast<const blink::WebMouseWheelEvent&>(event_to_coalesce), | 257 Coalesce(static_cast<const blink::WebMouseWheelEvent&>(event_to_coalesce), |
258 static_cast<blink::WebMouseWheelEvent*>(event)); | 258 static_cast<blink::WebMouseWheelEvent*>(event)); |
259 } | 259 } |
260 } | 260 } |
261 | 261 |
262 } // namespace internal | 262 } // namespace internal |
263 | 263 |
264 ScopedWebInputEventWithLatencyInfo::ScopedWebInputEventWithLatencyInfo( | 264 ScopedWebInputEventWithLatencyInfo::ScopedWebInputEventWithLatencyInfo( |
265 ui::ScopedWebInputEvent event, | 265 blink::CoalescedWebInputEvent::ScopedWebInputEvent event, |
266 const ui::LatencyInfo& latency_info) | 266 const ui::LatencyInfo& latency_info) |
267 : event_(std::move(event)), latency_(latency_info) { | 267 : event_(new blink::CoalescedWebInputEvent(std::move(event))), |
268 } | 268 latency_(latency_info) {} |
269 | 269 |
270 ScopedWebInputEventWithLatencyInfo::~ScopedWebInputEventWithLatencyInfo() {} | 270 ScopedWebInputEventWithLatencyInfo::~ScopedWebInputEventWithLatencyInfo() {} |
271 | 271 |
272 bool ScopedWebInputEventWithLatencyInfo::CanCoalesceWith( | 272 bool ScopedWebInputEventWithLatencyInfo::CanCoalesceWith( |
273 const ScopedWebInputEventWithLatencyInfo& other) const { | 273 const ScopedWebInputEventWithLatencyInfo& other) const { |
274 return internal::CanCoalesce(other.event(), event()); | 274 return internal::CanCoalesce(other.coalescedEvent().event(), |
| 275 coalescedEvent().event()); |
275 } | 276 } |
276 | 277 |
277 void ScopedWebInputEventWithLatencyInfo::CoalesceWith( | 278 void ScopedWebInputEventWithLatencyInfo::CoalesceWith( |
278 const ScopedWebInputEventWithLatencyInfo& other) { | 279 const ScopedWebInputEventWithLatencyInfo& other) { |
279 // |other| should be a newer event than |this|. | 280 // |other| should be a newer event than |this|. |
280 if (other.latency_.trace_id() >= 0 && latency_.trace_id() >= 0) | 281 if (other.latency_.trace_id() >= 0 && latency_.trace_id() >= 0) |
281 DCHECK_GT(other.latency_.trace_id(), latency_.trace_id()); | 282 DCHECK_GT(other.latency_.trace_id(), latency_.trace_id()); |
282 | 283 |
283 // New events get coalesced into older events, and the newer timestamp | 284 // New events get coalesced into older events, and the newer timestamp |
284 // should always be preserved. | 285 // should always be preserved. |
285 const double time_stamp_seconds = other.event().timeStampSeconds; | 286 const double time_stamp_seconds = |
286 internal::Coalesce(other.event(), event_.get()); | 287 other.coalescedEvent().event().timeStampSeconds; |
287 event_->timeStampSeconds = time_stamp_seconds; | 288 |
| 289 // The new event will have no coalesced events itself. So we do not copy all |
| 290 // the coalesced event over here. |
| 291 event_->addCoalescedEvent(other.coalescedEvent().event()); |
| 292 internal::Coalesce(other.coalescedEvent().event(), event_->eventPointer()); |
| 293 event_->eventPointer()->timeStampSeconds = time_stamp_seconds; |
288 | 294 |
289 // When coalescing two input events, we keep the oldest LatencyInfo | 295 // When coalescing two input events, we keep the oldest LatencyInfo |
290 // since it will represent the longest latency. | 296 // since it will represent the longest latency. |
291 other.latency_ = latency_; | 297 other.latency_ = latency_; |
292 other.latency_.set_coalesced(); | 298 other.latency_.set_coalesced(); |
293 } | 299 } |
294 | 300 |
295 const blink::WebInputEvent& ScopedWebInputEventWithLatencyInfo::event() const { | 301 const blink::CoalescedWebInputEvent& |
| 302 ScopedWebInputEventWithLatencyInfo::coalescedEvent() const { |
296 return *event_; | 303 return *event_; |
297 } | 304 } |
298 | 305 |
299 blink::WebInputEvent& ScopedWebInputEventWithLatencyInfo::event() { | 306 blink::CoalescedWebInputEvent& |
| 307 ScopedWebInputEventWithLatencyInfo::coalescedEvent() { |
300 return *event_; | 308 return *event_; |
301 } | 309 } |
302 | 310 |
303 } // namespace content | 311 } // namespace content |
OLD | NEW |