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) { | |
136 if (last_mouse_event_was_move_ && | 135 if (last_mouse_event_was_move_ && |
137 mouse_event.timeStampSeconds < last_mouse_move_timestamp_ + | 136 mouse_event.timeStampSeconds < last_mouse_move_timestamp_ + |
138 kMouseMoveDropIntervalSeconds) | 137 kMouseMoveDropIntervalSeconds) |
139 return true; | 138 return true; |
140 | 139 |
141 last_mouse_event_was_move_ = true; | 140 last_mouse_event_was_move_ = true; |
142 last_mouse_move_timestamp_ = mouse_event.timeStampSeconds; | 141 last_mouse_move_timestamp_ = mouse_event.timeStampSeconds; |
143 } else { | 142 } else { |
144 last_mouse_event_was_move_ = false; | 143 last_mouse_event_was_move_ = false; |
145 } | 144 } |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 } | 309 } |
311 | 310 |
312 void TouchEmulator::PinchEnd(const WebGestureEvent& event) { | 311 void TouchEmulator::PinchEnd(const WebGestureEvent& event) { |
313 DCHECK(pinch_gesture_active_); | 312 DCHECK(pinch_gesture_active_); |
314 pinch_gesture_active_ = false; | 313 pinch_gesture_active_ = false; |
315 FillPinchEvent(event); | 314 FillPinchEvent(event); |
316 pinch_event_.type = WebInputEvent::GesturePinchEnd; | 315 pinch_event_.type = WebInputEvent::GesturePinchEnd; |
317 client_->ForwardGestureEvent(pinch_event_); | 316 client_->ForwardGestureEvent(pinch_event_); |
318 } | 317 } |
319 | 318 |
320 void TouchEmulator::FillPinchEvent(const WebGestureEvent& event) { | 319 void TouchEmulator::FillPinchEvent(const WebInputEvent& event) { |
321 pinch_event_.timeStampSeconds = event.timeStampSeconds; | 320 pinch_event_.timeStampSeconds = event.timeStampSeconds; |
322 pinch_event_.modifiers = event.modifiers; | 321 pinch_event_.modifiers = event.modifiers; |
323 pinch_event_.sourceDevice = blink::WebGestureEvent::Touchscreen; | 322 pinch_event_.sourceDevice = blink::WebGestureEvent::Touchscreen; |
324 pinch_event_.x = pinch_anchor_.x(); | 323 pinch_event_.x = pinch_anchor_.x(); |
325 pinch_event_.y = pinch_anchor_.y(); | 324 pinch_event_.y = pinch_anchor_.y(); |
326 } | 325 } |
327 | 326 |
328 void TouchEmulator::ScrollEnd(const WebGestureEvent& event) { | 327 void TouchEmulator::ScrollEnd(const WebGestureEvent& event) { |
329 WebGestureEvent scroll_event; | 328 WebGestureEvent scroll_event; |
330 scroll_event.timeStampSeconds = event.timeStampSeconds; | 329 scroll_event.timeStampSeconds = event.timeStampSeconds; |
(...skipping 25 matching lines...) Expand all Loading... |
356 break; | 355 break; |
357 default: | 356 default: |
358 eventType = WebInputEvent::Undefined; | 357 eventType = WebInputEvent::Undefined; |
359 NOTREACHED(); | 358 NOTREACHED(); |
360 } | 359 } |
361 touch_event_.touchesLength = 1; | 360 touch_event_.touchesLength = 1; |
362 touch_event_.modifiers = mouse_event.modifiers; | 361 touch_event_.modifiers = mouse_event.modifiers; |
363 WebTouchEventTraits::ResetTypeAndTouchStates( | 362 WebTouchEventTraits::ResetTypeAndTouchStates( |
364 eventType, mouse_event.timeStampSeconds, &touch_event_); | 363 eventType, mouse_event.timeStampSeconds, &touch_event_); |
365 | 364 |
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 | |
372 WebTouchPoint& point = touch_event_.touches[0]; | 365 WebTouchPoint& point = touch_event_.touches[0]; |
373 point.id = 0; | 366 point.id = 0; |
374 point.radiusX = point.radiusY = 1.f; | 367 point.radiusX = point.radiusY = 1.f; |
375 point.force = 1.f; | 368 point.force = 1.f; |
376 point.rotationAngle = 0.f; | 369 point.rotationAngle = 0.f; |
377 point.position.x = mouse_event.x; | 370 point.position.x = mouse_event.x; |
378 point.screenPosition.x = mouse_event.globalX; | 371 point.screenPosition.x = mouse_event.globalX; |
379 point.position.y = mouse_event.y; | 372 point.position.y = mouse_event.y; |
380 point.screenPosition.y = mouse_event.globalY; | 373 point.screenPosition.y = mouse_event.globalY; |
381 | 374 |
382 return true; | 375 return true; |
383 } | 376 } |
384 | 377 |
385 bool TouchEmulator::InPinchGestureMode() const { | 378 bool TouchEmulator::InPinchGestureMode() const { |
386 return shift_pressed_ && allow_pinch_; | 379 return shift_pressed_ && allow_pinch_; |
387 } | 380 } |
388 | 381 |
389 } // namespace content | 382 } // namespace content |
OLD | NEW |