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

Side by Side Diff: content/common/input/event_with_latency_info.cc

Issue 2479123003: WIP Add getCoalescedEvents API using vector of WebInputEvents (Closed)
Patch Set: Created 4 years, 1 month 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/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 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 static_cast<blink::WebTouchEvent*>(event)); 252 static_cast<blink::WebTouchEvent*>(event));
253 return; 253 return;
254 } 254 }
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 ui::ScopedWebInputEvent makeDeepCopyUniquePtr(
263 const blink::WebInputEvent& event) {
264 if (blink::WebInputEvent::isGestureEventType(event.type)) {
265 return ui::ScopedWebInputEvent(new blink::WebGestureEvent(
266 static_cast<const blink::WebGestureEvent&>(event)));
267 }
268 if (blink::WebInputEvent::isMouseEventType(event.type)) {
269 return ui::ScopedWebInputEvent(new blink::WebMouseEvent(
270 static_cast<const blink::WebMouseEvent&>(event)));
271 }
272 if (blink::WebInputEvent::isTouchEventType(event.type)) {
273 return ui::ScopedWebInputEvent(new blink::WebTouchEvent(
274 static_cast<const blink::WebTouchEvent&>(event)));
275 }
276 if (event.type == blink::WebInputEvent::MouseWheel) {
277 return ui::ScopedWebInputEvent(new blink::WebMouseWheelEvent(
278 static_cast<const blink::WebMouseWheelEvent&>(event)));
279 }
280 NOTREACHED();
281 return ui::ScopedWebInputEvent();
282 }
283
262 } // namespace internal 284 } // namespace internal
263 285
264 ScopedWebInputEventWithLatencyInfo::ScopedWebInputEventWithLatencyInfo( 286 ScopedWebInputEventWithLatencyInfo::ScopedWebInputEventWithLatencyInfo(
265 ui::ScopedWebInputEvent event, 287 ui::ScopedWebInputEvent event,
266 const ui::LatencyInfo& latency_info) 288 const ui::LatencyInfo& latency_info)
267 : event_(std::move(event)), latency_(latency_info) { 289 : event_(internal::makeDeepCopyUniquePtr(*event.get())),
290 latency_(latency_info) {
291 scopedCoalescedEvents_.push_back(std::move(event));
292 coalescedEvents_.push_back(scopedCoalescedEvents_.back().get());
268 } 293 }
269 294
270 ScopedWebInputEventWithLatencyInfo::~ScopedWebInputEventWithLatencyInfo() {} 295 ScopedWebInputEventWithLatencyInfo::~ScopedWebInputEventWithLatencyInfo() {}
271 296
272 bool ScopedWebInputEventWithLatencyInfo::CanCoalesceWith( 297 bool ScopedWebInputEventWithLatencyInfo::CanCoalesceWith(
273 const ScopedWebInputEventWithLatencyInfo& other) const { 298 const ScopedWebInputEventWithLatencyInfo& other) const {
274 return internal::CanCoalesce(other.event(), event()); 299 return internal::CanCoalesce(other.event(), event());
275 } 300 }
276 301
277 void ScopedWebInputEventWithLatencyInfo::CoalesceWith( 302 void ScopedWebInputEventWithLatencyInfo::CoalesceWith(
278 const ScopedWebInputEventWithLatencyInfo& other) { 303 const ScopedWebInputEventWithLatencyInfo& other) {
279 // |other| should be a newer event than |this|. 304 // |other| should be a newer event than |this|.
280 if (other.latency_.trace_id() >= 0 && latency_.trace_id() >= 0) 305 if (other.latency_.trace_id() >= 0 && latency_.trace_id() >= 0)
281 DCHECK_GT(other.latency_.trace_id(), latency_.trace_id()); 306 DCHECK_GT(other.latency_.trace_id(), latency_.trace_id());
282 307
283 // New events get coalesced into older events, and the newer timestamp 308 // New events get coalesced into older events, and the newer timestamp
284 // should always be preserved. 309 // should always be preserved.
285 const double time_stamp_seconds = other.event().timeStampSeconds; 310 const double time_stamp_seconds = other.event().timeStampSeconds;
311 scopedCoalescedEvents_.push_back(
312 internal::makeDeepCopyUniquePtr(other.event()));
313 coalescedEvents_.push_back(scopedCoalescedEvents_.back().get());
286 internal::Coalesce(other.event(), event_.get()); 314 internal::Coalesce(other.event(), event_.get());
287 event_->timeStampSeconds = time_stamp_seconds; 315 event_->timeStampSeconds = time_stamp_seconds;
288 316
289 // When coalescing two input events, we keep the oldest LatencyInfo 317 // When coalescing two input events, we keep the oldest LatencyInfo
290 // since it will represent the longest latency. 318 // since it will represent the longest latency.
291 other.latency_ = latency_; 319 other.latency_ = latency_;
292 other.latency_.set_coalesced(); 320 other.latency_.set_coalesced();
293 } 321 }
294 322
295 const blink::WebInputEvent& ScopedWebInputEventWithLatencyInfo::event() const { 323 const blink::WebInputEvent& ScopedWebInputEventWithLatencyInfo::event() const {
296 return *event_; 324 return *event_;
297 } 325 }
298 326
299 blink::WebInputEvent& ScopedWebInputEventWithLatencyInfo::event() { 327 blink::WebInputEvent& ScopedWebInputEventWithLatencyInfo::event() {
300 return *event_; 328 return *event_;
301 } 329 }
302 330
331 const std::vector<const blink::WebInputEvent*>&
332 ScopedWebInputEventWithLatencyInfo::coalescedEvents() {
333 return coalescedEvents_;
334 }
335
303 } // namespace content 336 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698