| 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 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 } | 309 } |
| 310 | 310 |
| 311 void TouchEmulator::PinchEnd(const WebGestureEvent& event) { | 311 void TouchEmulator::PinchEnd(const WebGestureEvent& event) { |
| 312 DCHECK(pinch_gesture_active_); | 312 DCHECK(pinch_gesture_active_); |
| 313 pinch_gesture_active_ = false; | 313 pinch_gesture_active_ = false; |
| 314 FillPinchEvent(event); | 314 FillPinchEvent(event); |
| 315 pinch_event_.type = WebInputEvent::GesturePinchEnd; | 315 pinch_event_.type = WebInputEvent::GesturePinchEnd; |
| 316 client_->ForwardGestureEvent(pinch_event_); | 316 client_->ForwardGestureEvent(pinch_event_); |
| 317 } | 317 } |
| 318 | 318 |
| 319 void TouchEmulator::FillPinchEvent(const WebGestureEvent& event) { | 319 void TouchEmulator::FillPinchEvent(const WebInputEvent& event) { |
| 320 pinch_event_.timeStampSeconds = event.timeStampSeconds; | 320 pinch_event_.timeStampSeconds = event.timeStampSeconds; |
| 321 pinch_event_.modifiers = event.modifiers; | 321 pinch_event_.modifiers = event.modifiers; |
| 322 pinch_event_.sourceDevice = blink::WebGestureEvent::Touchscreen; | 322 pinch_event_.sourceDevice = blink::WebGestureEvent::Touchscreen; |
| 323 pinch_event_.x = pinch_anchor_.x(); | 323 pinch_event_.x = pinch_anchor_.x(); |
| 324 pinch_event_.y = pinch_anchor_.y(); | 324 pinch_event_.y = pinch_anchor_.y(); |
| 325 } | 325 } |
| 326 | 326 |
| 327 void TouchEmulator::ScrollEnd(const WebGestureEvent& event) { | 327 void TouchEmulator::ScrollEnd(const WebGestureEvent& event) { |
| 328 WebGestureEvent scroll_event; | 328 WebGestureEvent scroll_event; |
| 329 scroll_event.timeStampSeconds = event.timeStampSeconds; | 329 scroll_event.timeStampSeconds = event.timeStampSeconds; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 354 break; | 354 break; |
| 355 default: | 355 default: |
| 356 eventType = WebInputEvent::Undefined; | 356 eventType = WebInputEvent::Undefined; |
| 357 NOTREACHED(); | 357 NOTREACHED(); |
| 358 } | 358 } |
| 359 touch_event_.touchesLength = 1; | 359 touch_event_.touchesLength = 1; |
| 360 touch_event_.modifiers = mouse_event.modifiers; | 360 touch_event_.modifiers = mouse_event.modifiers; |
| 361 WebTouchEventTraits::ResetTypeAndTouchStates( | 361 WebTouchEventTraits::ResetTypeAndTouchStates( |
| 362 eventType, mouse_event.timeStampSeconds, &touch_event_); | 362 eventType, mouse_event.timeStampSeconds, &touch_event_); |
| 363 | 363 |
| 364 // On some platforms mouse event's timestamp does not necessarily relate to | |
| 365 // the system time at all, so use base::TimeTicks::HighResNow() if possible, | |
| 366 // or base::TimeTicks::Now() otherwise. | |
| 367 base::TimeTicks now; | |
| 368 if (base::TimeTicks::IsHighResNowFastAndReliable()) | |
| 369 now = base::TimeTicks::HighResNow(); | |
| 370 else | |
| 371 now = base::TimeTicks::Now(); | |
| 372 touch_event_.timeStampSeconds = (now - base::TimeTicks()).InSecondsF(); | |
| 373 | |
| 374 WebTouchPoint& point = touch_event_.touches[0]; | 364 WebTouchPoint& point = touch_event_.touches[0]; |
| 375 point.id = 0; | 365 point.id = 0; |
| 376 point.radiusX = point.radiusY = 1.f; | 366 point.radiusX = point.radiusY = 1.f; |
| 377 point.force = 1.f; | 367 point.force = 1.f; |
| 378 point.rotationAngle = 0.f; | 368 point.rotationAngle = 0.f; |
| 379 point.position.x = mouse_event.x; | 369 point.position.x = mouse_event.x; |
| 380 point.screenPosition.x = mouse_event.globalX; | 370 point.screenPosition.x = mouse_event.globalX; |
| 381 point.position.y = mouse_event.y; | 371 point.position.y = mouse_event.y; |
| 382 point.screenPosition.y = mouse_event.globalY; | 372 point.screenPosition.y = mouse_event.globalY; |
| 383 | 373 |
| 384 return true; | 374 return true; |
| 385 } | 375 } |
| 386 | 376 |
| 387 bool TouchEmulator::InPinchGestureMode() const { | 377 bool TouchEmulator::InPinchGestureMode() const { |
| 388 return shift_pressed_ && allow_pinch_; | 378 return shift_pressed_ && allow_pinch_; |
| 389 } | 379 } |
| 390 | 380 |
| 391 } // namespace content | 381 } // namespace content |
| OLD | NEW |