OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/browser/renderer_host/input/touch_emulator.h" | 5 #include "content/browser/renderer_host/input/touch_emulator.h" |
6 | 6 |
7 #include "content/browser/renderer_host/input/motion_event_web.h" | 7 #include "content/browser/renderer_host/input/motion_event_web.h" |
8 #include "content/browser/renderer_host/input/web_input_event_util.h" | 8 #include "content/browser/renderer_host/input/web_input_event_util.h" |
9 #include "content/common/input/web_touch_event_traits.h" | 9 #include "content/common/input/web_touch_event_traits.h" |
10 #include "content/public/common/content_client.h" | 10 #include "content/public/common/content_client.h" |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 cursor->InitFromCursorInfo(cursor_info); | 124 cursor->InitFromCursorInfo(cursor_info); |
125 } | 125 } |
126 | 126 |
127 bool TouchEmulator::HandleMouseEvent(const WebMouseEvent& mouse_event) { | 127 bool TouchEmulator::HandleMouseEvent(const WebMouseEvent& mouse_event) { |
128 if (!enabled_) | 128 if (!enabled_) |
129 return false; | 129 return false; |
130 | 130 |
131 if (mouse_event.button != WebMouseEvent::ButtonLeft) | 131 if (mouse_event.button != WebMouseEvent::ButtonLeft) |
132 return true; | 132 return true; |
133 | 133 |
134 if (mouse_event.type == WebInputEvent::MouseMove) { | 134 if (mouse_event.type == WebInputEvent::MouseMove && |
| 135 mouse_event.timeStampSeconds) { |
135 if (last_mouse_event_was_move_ && | 136 if (last_mouse_event_was_move_ && |
136 mouse_event.timeStampSeconds < last_mouse_move_timestamp_ + | 137 mouse_event.timeStampSeconds < last_mouse_move_timestamp_ + |
137 kMouseMoveDropIntervalSeconds) | 138 kMouseMoveDropIntervalSeconds) |
138 return true; | 139 return true; |
139 | 140 |
140 last_mouse_event_was_move_ = true; | 141 last_mouse_event_was_move_ = true; |
141 last_mouse_move_timestamp_ = mouse_event.timeStampSeconds; | 142 last_mouse_move_timestamp_ = mouse_event.timeStampSeconds; |
142 } else { | 143 } else { |
143 last_mouse_event_was_move_ = false; | 144 last_mouse_event_was_move_ = false; |
144 } | 145 } |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 } | 310 } |
310 | 311 |
311 void TouchEmulator::PinchEnd(const WebGestureEvent& event) { | 312 void TouchEmulator::PinchEnd(const WebGestureEvent& event) { |
312 DCHECK(pinch_gesture_active_); | 313 DCHECK(pinch_gesture_active_); |
313 pinch_gesture_active_ = false; | 314 pinch_gesture_active_ = false; |
314 FillPinchEvent(event); | 315 FillPinchEvent(event); |
315 pinch_event_.type = WebInputEvent::GesturePinchEnd; | 316 pinch_event_.type = WebInputEvent::GesturePinchEnd; |
316 client_->ForwardGestureEvent(pinch_event_); | 317 client_->ForwardGestureEvent(pinch_event_); |
317 } | 318 } |
318 | 319 |
319 void TouchEmulator::FillPinchEvent(const WebInputEvent& event) { | 320 void TouchEmulator::FillPinchEvent(const WebGestureEvent& event) { |
320 pinch_event_.timeStampSeconds = event.timeStampSeconds; | 321 pinch_event_.timeStampSeconds = event.timeStampSeconds; |
321 pinch_event_.modifiers = event.modifiers; | 322 pinch_event_.modifiers = event.modifiers; |
322 pinch_event_.sourceDevice = blink::WebGestureEvent::Touchscreen; | 323 pinch_event_.sourceDevice = blink::WebGestureEvent::Touchscreen; |
323 pinch_event_.x = pinch_anchor_.x(); | 324 pinch_event_.x = pinch_anchor_.x(); |
324 pinch_event_.y = pinch_anchor_.y(); | 325 pinch_event_.y = pinch_anchor_.y(); |
325 } | 326 } |
326 | 327 |
327 void TouchEmulator::ScrollEnd(const WebGestureEvent& event) { | 328 void TouchEmulator::ScrollEnd(const WebGestureEvent& event) { |
328 WebGestureEvent scroll_event; | 329 WebGestureEvent scroll_event; |
329 scroll_event.timeStampSeconds = event.timeStampSeconds; | 330 scroll_event.timeStampSeconds = event.timeStampSeconds; |
(...skipping 25 matching lines...) Expand all Loading... |
355 break; | 356 break; |
356 default: | 357 default: |
357 eventType = WebInputEvent::Undefined; | 358 eventType = WebInputEvent::Undefined; |
358 NOTREACHED(); | 359 NOTREACHED(); |
359 } | 360 } |
360 touch_event_.touchesLength = 1; | 361 touch_event_.touchesLength = 1; |
361 touch_event_.modifiers = mouse_event.modifiers; | 362 touch_event_.modifiers = mouse_event.modifiers; |
362 WebTouchEventTraits::ResetTypeAndTouchStates( | 363 WebTouchEventTraits::ResetTypeAndTouchStates( |
363 eventType, mouse_event.timeStampSeconds, &touch_event_); | 364 eventType, mouse_event.timeStampSeconds, &touch_event_); |
364 | 365 |
| 366 if (!touch_event_.timeStampSeconds) { |
| 367 // Gesture detector does not tolerate null timestamps generated in tests. |
| 368 touch_event_.timeStampSeconds = |
| 369 (base::TimeTicks::Now() - base::TimeTicks()).InSecondsF(); |
| 370 } |
| 371 |
365 WebTouchPoint& point = touch_event_.touches[0]; | 372 WebTouchPoint& point = touch_event_.touches[0]; |
366 point.id = 0; | 373 point.id = 0; |
367 point.radiusX = point.radiusY = 1.f; | 374 point.radiusX = point.radiusY = 1.f; |
368 point.force = 1.f; | 375 point.force = 1.f; |
369 point.rotationAngle = 0.f; | 376 point.rotationAngle = 0.f; |
370 point.position.x = mouse_event.x; | 377 point.position.x = mouse_event.x; |
371 point.screenPosition.x = mouse_event.globalX; | 378 point.screenPosition.x = mouse_event.globalX; |
372 point.position.y = mouse_event.y; | 379 point.position.y = mouse_event.y; |
373 point.screenPosition.y = mouse_event.globalY; | 380 point.screenPosition.y = mouse_event.globalY; |
374 | 381 |
375 return true; | 382 return true; |
376 } | 383 } |
377 | 384 |
378 bool TouchEmulator::InPinchGestureMode() const { | 385 bool TouchEmulator::InPinchGestureMode() const { |
379 return shift_pressed_ && allow_pinch_; | 386 return shift_pressed_ && allow_pinch_; |
380 } | 387 } |
381 | 388 |
382 } // namespace content | 389 } // namespace content |
OLD | NEW |