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

Side by Side Diff: content/browser/renderer_host/input/touch_emulator.cc

Issue 250923005: Touch emulator: overwrite timestamps from mouse event with current time. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 months 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | content/browser/renderer_host/input/touch_emulator_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 WebInputEvent& event) { 319 void TouchEmulator::FillPinchEvent(const WebInputEvent& event) {
jdduke (slow) 2014/04/25 16:56:05 Could you make this |const WebGestureEvent& event)
dgozman 2014/04/28 09:34:21 Done.
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
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
364 WebTouchPoint& point = touch_event_.touches[0]; 374 WebTouchPoint& point = touch_event_.touches[0];
365 point.id = 0; 375 point.id = 0;
366 point.radiusX = point.radiusY = 1.f; 376 point.radiusX = point.radiusY = 1.f;
367 point.force = 1.f; 377 point.force = 1.f;
368 point.rotationAngle = 0.f; 378 point.rotationAngle = 0.f;
369 point.position.x = mouse_event.x; 379 point.position.x = mouse_event.x;
370 point.screenPosition.x = mouse_event.globalX; 380 point.screenPosition.x = mouse_event.globalX;
371 point.position.y = mouse_event.y; 381 point.position.y = mouse_event.y;
372 point.screenPosition.y = mouse_event.globalY; 382 point.screenPosition.y = mouse_event.globalY;
373 383
374 return true; 384 return true;
375 } 385 }
376 386
377 bool TouchEmulator::InPinchGestureMode() const { 387 bool TouchEmulator::InPinchGestureMode() const {
378 return shift_pressed_ && allow_pinch_; 388 return shift_pressed_ && allow_pinch_;
379 } 389 }
380 390
381 } // namespace content 391 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/browser/renderer_host/input/touch_emulator_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698