| 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 #include "content/common/input/web_input_event_traits.h" |
| 9 | 10 |
| 10 using blink::WebGestureEvent; | 11 using blink::WebGestureEvent; |
| 11 using blink::WebInputEvent; | 12 using blink::WebInputEvent; |
| 12 using blink::WebKeyboardEvent; | 13 using blink::WebKeyboardEvent; |
| 13 using blink::WebMouseEvent; | 14 using blink::WebMouseEvent; |
| 14 using blink::WebMouseWheelEvent; | 15 using blink::WebMouseWheelEvent; |
| 15 using blink::WebTouchEvent; | 16 using blink::WebTouchEvent; |
| 16 using std::numeric_limits; | 17 using std::numeric_limits; |
| 17 | 18 |
| 18 namespace content { | 19 namespace content { |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 event->data.pinchUpdate.scale *= event_to_coalesce.data.pinchUpdate.scale; | 188 event->data.pinchUpdate.scale *= event_to_coalesce.data.pinchUpdate.scale; |
| 188 // Ensure the scale remains bounded above 0 and below Infinity so that | 189 // Ensure the scale remains bounded above 0 and below Infinity so that |
| 189 // we can reliably perform operations like log on the values. | 190 // we can reliably perform operations like log on the values. |
| 190 if (event->data.pinchUpdate.scale < numeric_limits<float>::min()) | 191 if (event->data.pinchUpdate.scale < numeric_limits<float>::min()) |
| 191 event->data.pinchUpdate.scale = numeric_limits<float>::min(); | 192 event->data.pinchUpdate.scale = numeric_limits<float>::min(); |
| 192 else if (event->data.pinchUpdate.scale > numeric_limits<float>::max()) | 193 else if (event->data.pinchUpdate.scale > numeric_limits<float>::max()) |
| 193 event->data.pinchUpdate.scale = numeric_limits<float>::max(); | 194 event->data.pinchUpdate.scale = numeric_limits<float>::max(); |
| 194 } | 195 } |
| 195 } | 196 } |
| 196 | 197 |
| 198 bool CanCoalesce(const blink::WebInputEvent& event_to_coalesce, |
| 199 const blink::WebInputEvent& event) { |
| 200 if (blink::WebInputEvent::isGestureEventType(event_to_coalesce.type) && |
| 201 blink::WebInputEvent::isGestureEventType(event.type)) { |
| 202 return CanCoalesce( |
| 203 static_cast<const blink::WebGestureEvent&>(event_to_coalesce), |
| 204 static_cast<const blink::WebGestureEvent&>(event)); |
| 205 } |
| 206 if (blink::WebInputEvent::isMouseEventType(event_to_coalesce.type) && |
| 207 blink::WebInputEvent::isMouseEventType(event.type)) { |
| 208 return CanCoalesce( |
| 209 static_cast<const blink::WebMouseEvent&>(event_to_coalesce), |
| 210 static_cast<const blink::WebMouseEvent&>(event)); |
| 211 } |
| 212 if (blink::WebInputEvent::isTouchEventType(event_to_coalesce.type) && |
| 213 blink::WebInputEvent::isTouchEventType(event.type)) { |
| 214 return CanCoalesce( |
| 215 static_cast<const blink::WebTouchEvent&>(event_to_coalesce), |
| 216 static_cast<const blink::WebTouchEvent&>(event)); |
| 217 } |
| 218 if (event_to_coalesce.type == blink::WebInputEvent::MouseWheel && |
| 219 event.type == blink::WebInputEvent::MouseWheel) { |
| 220 return CanCoalesce( |
| 221 static_cast<const blink::WebMouseWheelEvent&>(event_to_coalesce), |
| 222 static_cast<const blink::WebMouseWheelEvent&>(event)); |
| 223 } |
| 224 return false; |
| 225 } |
| 226 |
| 227 void Coalesce(const blink::WebInputEvent& event_to_coalesce, |
| 228 blink::WebInputEvent* event) { |
| 229 if (blink::WebInputEvent::isGestureEventType(event_to_coalesce.type) && |
| 230 blink::WebInputEvent::isGestureEventType(event->type)) { |
| 231 Coalesce(static_cast<const blink::WebGestureEvent&>(event_to_coalesce), |
| 232 static_cast<blink::WebGestureEvent*>(event)); |
| 233 return; |
| 234 } |
| 235 if (blink::WebInputEvent::isMouseEventType(event_to_coalesce.type) && |
| 236 blink::WebInputEvent::isMouseEventType(event->type)) { |
| 237 Coalesce(static_cast<const blink::WebMouseEvent&>(event_to_coalesce), |
| 238 static_cast<blink::WebMouseEvent*>(event)); |
| 239 return; |
| 240 } |
| 241 if (blink::WebInputEvent::isTouchEventType(event_to_coalesce.type) && |
| 242 blink::WebInputEvent::isTouchEventType(event->type)) { |
| 243 Coalesce(static_cast<const blink::WebTouchEvent&>(event_to_coalesce), |
| 244 static_cast<blink::WebTouchEvent*>(event)); |
| 245 return; |
| 246 } |
| 247 if (event_to_coalesce.type == blink::WebInputEvent::MouseWheel && |
| 248 event->type == blink::WebInputEvent::MouseWheel) { |
| 249 Coalesce(static_cast<const blink::WebMouseWheelEvent&>(event_to_coalesce), |
| 250 static_cast<blink::WebMouseWheelEvent*>(event)); |
| 251 } |
| 252 } |
| 253 |
| 197 } // namespace internal | 254 } // namespace internal |
| 255 |
| 256 ScopedWebInputEventWithLatencyInfo::ScopedWebInputEventWithLatencyInfo( |
| 257 const WebInputEvent& event, |
| 258 const ui::LatencyInfo& latency_info) |
| 259 : event_(WebInputEventTraits::Clone(event)), latency_(latency_info) {} |
| 260 |
| 261 ScopedWebInputEventWithLatencyInfo::~ScopedWebInputEventWithLatencyInfo() {} |
| 262 |
| 263 bool ScopedWebInputEventWithLatencyInfo::CanCoalesceWith( |
| 264 const ScopedWebInputEventWithLatencyInfo& other) const { |
| 265 return internal::CanCoalesce(other.event(), event()); |
| 266 } |
| 267 |
| 268 void ScopedWebInputEventWithLatencyInfo::CoalesceWith( |
| 269 const ScopedWebInputEventWithLatencyInfo& other) { |
| 270 // |other| should be a newer event than |this|. |
| 271 if (other.latency_.trace_id() >= 0 && latency_.trace_id() >= 0) |
| 272 DCHECK_GT(other.latency_.trace_id(), latency_.trace_id()); |
| 273 |
| 274 // New events get coalesced into older events, and the newer timestamp |
| 275 // should always be preserved. |
| 276 const double time_stamp_seconds = other.event().timeStampSeconds; |
| 277 internal::Coalesce(other.event(), event_.get()); |
| 278 event_->timeStampSeconds = time_stamp_seconds; |
| 279 |
| 280 // When coalescing two input events, we keep the oldest LatencyInfo |
| 281 // since it will represent the longest latency. |
| 282 other.latency_ = latency_; |
| 283 other.latency_.set_coalesced(); |
| 284 } |
| 285 |
| 286 const blink::WebInputEvent& ScopedWebInputEventWithLatencyInfo::event() const { |
| 287 return *event_; |
| 288 } |
| 289 |
| 290 blink::WebInputEvent& ScopedWebInputEventWithLatencyInfo::event() { |
| 291 return *event_; |
| 292 } |
| 293 |
| 198 } // namespace content | 294 } // namespace content |
| OLD | NEW |