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

Side by Side Diff: third_party/WebKit/Source/web/WebInputEventConversion.cpp

Issue 2542693002: Use WTF::TimeTicks to represent timestamp in Platform/Core event types (Closed)
Patch Set: Don't fix bug in this patch Created 4 years 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2009 Google Inc. All rights reserved. 2 * Copyright (C) 2009 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 scale = rootView->inputEventsScaleFactor(); 58 scale = rootView->inputEventsScaleFactor();
59 } 59 }
60 return delta / scale; 60 return delta / scale;
61 } 61 }
62 62
63 FloatSize scaleSizeToWindow(const Widget* widget, FloatSize size) { 63 FloatSize scaleSizeToWindow(const Widget* widget, FloatSize size) {
64 return FloatSize(scaleDeltaToWindow(widget, size.width()), 64 return FloatSize(scaleDeltaToWindow(widget, size.width()),
65 scaleDeltaToWindow(widget, size.height())); 65 scaleDeltaToWindow(widget, size.height()));
66 } 66 }
67 67
68 TimeTicks toTimeTicks(double eventTimeStampSeconds) {
69 return TimeTicks() + TimeDelta::FromSecondsD(eventTimeStampSeconds);
esprehn 2016/12/06 22:14:19 Can you add a method to TimeTicks for FromSeconds(
70 }
71
72 double toSeconds(TimeTicks ticks) {
73 return (ticks - TimeTicks()).InSecondsF();
esprehn 2016/12/06 22:14:19 Why does TimeTicks not have a ToSecondsF() method
74 }
75
68 // This method converts from the renderer's coordinate space into Blink's root 76 // This method converts from the renderer's coordinate space into Blink's root
69 // frame coordinate space. It's somewhat unique in that it takes into account 77 // frame coordinate space. It's somewhat unique in that it takes into account
70 // DevTools emulation, which applies a scale and offset in the root layer (see 78 // DevTools emulation, which applies a scale and offset in the root layer (see
71 // updateRootLayerTransform in WebViewImpl) as well as the overscroll effect on 79 // updateRootLayerTransform in WebViewImpl) as well as the overscroll effect on
72 // OSX. This is in addition to the visual viewport "pinch-zoom" transformation 80 // OSX. This is in addition to the visual viewport "pinch-zoom" transformation
73 // and is one of the few cases where the visual viewport is not equal to the 81 // and is one of the few cases where the visual viewport is not equal to the
74 // renderer's coordinate-space. 82 // renderer's coordinate-space.
75 FloatPoint convertHitPointToRootFrame(const Widget* widget, 83 FloatPoint convertHitPointToRootFrame(const Widget* widget,
76 FloatPoint pointInRendererViewport) { 84 FloatPoint pointInRendererViewport) {
77 float scale = 1; 85 float scale = 1;
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 const WebMouseEvent& e) { 204 const WebMouseEvent& e) {
197 // FIXME: Widget is always toplevel, unless it's a popup. We may be able 205 // FIXME: Widget is always toplevel, unless it's a popup. We may be able
198 // to get rid of this once we abstract popups into a WebKit API. 206 // to get rid of this once we abstract popups into a WebKit API.
199 m_position = widget->convertFromRootFrame( 207 m_position = widget->convertFromRootFrame(
200 flooredIntPoint(convertHitPointToRootFrame(widget, IntPoint(e.x, e.y)))); 208 flooredIntPoint(convertHitPointToRootFrame(widget, IntPoint(e.x, e.y))));
201 m_globalPosition = IntPoint(e.globalX, e.globalY); 209 m_globalPosition = IntPoint(e.globalX, e.globalY);
202 m_movementDelta = IntPoint(scaleDeltaToWindow(widget, e.movementX), 210 m_movementDelta = IntPoint(scaleDeltaToWindow(widget, e.movementX),
203 scaleDeltaToWindow(widget, e.movementY)); 211 scaleDeltaToWindow(widget, e.movementY));
204 m_modifiers = e.modifiers; 212 m_modifiers = e.modifiers;
205 213
206 m_timestamp = e.timeStampSeconds; 214 m_timestamp = toTimeTicks(e.timeStampSeconds);
207 m_clickCount = e.clickCount; 215 m_clickCount = e.clickCount;
208 216
209 m_pointerProperties = static_cast<WebPointerProperties>(e); 217 m_pointerProperties = static_cast<WebPointerProperties>(e);
210 218
211 switch (e.type) { 219 switch (e.type) {
212 case WebInputEvent::MouseMove: 220 case WebInputEvent::MouseMove:
213 case WebInputEvent::MouseEnter: // synthesize a move event 221 case WebInputEvent::MouseEnter: // synthesize a move event
214 case WebInputEvent::MouseLeave: // synthesize a move event 222 case WebInputEvent::MouseLeave: // synthesize a move event
215 m_type = PlatformEvent::MouseMoved; 223 m_type = PlatformEvent::MouseMoved;
216 break; 224 break;
(...skipping 27 matching lines...) Expand all
244 m_globalPosition = IntPoint(e.globalX, e.globalY); 252 m_globalPosition = IntPoint(e.globalX, e.globalY);
245 m_deltaX = scaleDeltaToWindow(widget, e.deltaX); 253 m_deltaX = scaleDeltaToWindow(widget, e.deltaX);
246 m_deltaY = scaleDeltaToWindow(widget, e.deltaY); 254 m_deltaY = scaleDeltaToWindow(widget, e.deltaY);
247 m_wheelTicksX = e.wheelTicksX; 255 m_wheelTicksX = e.wheelTicksX;
248 m_wheelTicksY = e.wheelTicksY; 256 m_wheelTicksY = e.wheelTicksY;
249 m_granularity = 257 m_granularity =
250 e.scrollByPage ? ScrollByPageWheelEvent : ScrollByPixelWheelEvent; 258 e.scrollByPage ? ScrollByPageWheelEvent : ScrollByPixelWheelEvent;
251 259
252 m_type = PlatformEvent::Wheel; 260 m_type = PlatformEvent::Wheel;
253 261
254 m_timestamp = e.timeStampSeconds; 262 m_timestamp = toTimeTicks(e.timeStampSeconds);
255 m_modifiers = e.modifiers; 263 m_modifiers = e.modifiers;
256 m_dispatchType = toPlatformDispatchType(e.dispatchType); 264 m_dispatchType = toPlatformDispatchType(e.dispatchType);
257 265
258 m_hasPreciseScrollingDeltas = e.hasPreciseScrollingDeltas; 266 m_hasPreciseScrollingDeltas = e.hasPreciseScrollingDeltas;
259 m_resendingPluginId = e.resendingPluginId; 267 m_resendingPluginId = e.resendingPluginId;
260 m_railsMode = static_cast<PlatformEvent::RailsMode>(e.railsMode); 268 m_railsMode = static_cast<PlatformEvent::RailsMode>(e.railsMode);
261 #if OS(MACOSX) 269 #if OS(MACOSX)
262 m_phase = static_cast<PlatformWheelEventPhase>(e.phase); 270 m_phase = static_cast<PlatformWheelEventPhase>(e.phase);
263 m_momentumPhase = static_cast<PlatformWheelEventPhase>(e.momentumPhase); 271 m_momentumPhase = static_cast<PlatformWheelEventPhase>(e.momentumPhase);
264 #endif 272 #endif
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 case WebInputEvent::GesturePinchUpdate: 376 case WebInputEvent::GesturePinchUpdate:
369 m_type = PlatformEvent::GesturePinchUpdate; 377 m_type = PlatformEvent::GesturePinchUpdate;
370 m_data.m_pinchUpdate.m_scale = e.data.pinchUpdate.scale; 378 m_data.m_pinchUpdate.m_scale = e.data.pinchUpdate.scale;
371 break; 379 break;
372 default: 380 default:
373 NOTREACHED(); 381 NOTREACHED();
374 } 382 }
375 m_position = widget->convertFromRootFrame(flooredIntPoint( 383 m_position = widget->convertFromRootFrame(flooredIntPoint(
376 convertHitPointToRootFrame(widget, FloatPoint(e.x, e.y)))); 384 convertHitPointToRootFrame(widget, FloatPoint(e.x, e.y))));
377 m_globalPosition = IntPoint(e.globalX, e.globalY); 385 m_globalPosition = IntPoint(e.globalX, e.globalY);
378 m_timestamp = e.timeStampSeconds; 386 m_timestamp = toTimeTicks(e.timeStampSeconds);
379 m_modifiers = e.modifiers; 387 m_modifiers = e.modifiers;
380 switch (e.sourceDevice) { 388 switch (e.sourceDevice) {
381 case WebGestureDeviceTouchpad: 389 case WebGestureDeviceTouchpad:
382 m_source = PlatformGestureSourceTouchpad; 390 m_source = PlatformGestureSourceTouchpad;
383 break; 391 break;
384 case WebGestureDeviceTouchscreen: 392 case WebGestureDeviceTouchscreen:
385 m_source = PlatformGestureSourceTouchscreen; 393 m_source = PlatformGestureSourceTouchscreen;
386 break; 394 break;
387 case WebGestureDeviceUninitialized: 395 case WebGestureDeviceUninitialized:
388 NOTREACHED(); 396 NOTREACHED();
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
456 m_screenPos = FloatPoint(point.screenPosition.x, point.screenPosition.y); 464 m_screenPos = FloatPoint(point.screenPosition.x, point.screenPosition.y);
457 m_radius = scaleSizeToWindow(widget, FloatSize(point.radiusX, point.radiusY)); 465 m_radius = scaleSizeToWindow(widget, FloatSize(point.radiusX, point.radiusY));
458 m_rotationAngle = point.rotationAngle; 466 m_rotationAngle = point.rotationAngle;
459 } 467 }
460 468
461 PlatformTouchEventBuilder::PlatformTouchEventBuilder( 469 PlatformTouchEventBuilder::PlatformTouchEventBuilder(
462 Widget* widget, 470 Widget* widget,
463 const WebTouchEvent& event) { 471 const WebTouchEvent& event) {
464 m_type = toPlatformTouchEventType(event.type); 472 m_type = toPlatformTouchEventType(event.type);
465 m_modifiers = event.modifiers; 473 m_modifiers = event.modifiers;
466 m_timestamp = event.timeStampSeconds; 474 m_timestamp = toTimeTicks(event.timeStampSeconds);
467 m_causesScrollingIfUncanceled = event.movedBeyondSlopRegion; 475 m_causesScrollingIfUncanceled = event.movedBeyondSlopRegion;
468 m_touchStartOrFirstTouchMove = event.touchStartOrFirstTouchMove; 476 m_touchStartOrFirstTouchMove = event.touchStartOrFirstTouchMove;
469 477
470 for (unsigned i = 0; i < event.touchesLength; ++i) 478 for (unsigned i = 0; i < event.touchesLength; ++i)
471 m_touchPoints.append(PlatformTouchPointBuilder(widget, event.touches[i])); 479 m_touchPoints.append(PlatformTouchPointBuilder(widget, event.touches[i]));
472 480
473 m_dispatchType = toPlatformDispatchType(event.dispatchType); 481 m_dispatchType = toPlatformDispatchType(event.dispatchType);
474 m_uniqueTouchEventId = event.uniqueTouchEventId; 482 m_uniqueTouchEventId = event.uniqueTouchEventId;
475 } 483 }
476 484
(...skipping 10 matching lines...) Expand all
487 convertAbsoluteLocationForLayoutObjectFloat(location, layoutItem)); 495 convertAbsoluteLocationForLayoutObjectFloat(location, layoutItem));
488 } 496 }
489 497
490 // FIXME: Change |widget| to const Widget& after RemoteFrames get 498 // FIXME: Change |widget| to const Widget& after RemoteFrames get
491 // RemoteFrameViews. 499 // RemoteFrameViews.
492 static void updateWebMouseEventFromCoreMouseEvent( 500 static void updateWebMouseEventFromCoreMouseEvent(
493 const MouseRelatedEvent& event, 501 const MouseRelatedEvent& event,
494 const Widget* widget, 502 const Widget* widget,
495 const LayoutItem layoutItem, 503 const LayoutItem layoutItem,
496 WebMouseEvent& webEvent) { 504 WebMouseEvent& webEvent) {
497 webEvent.timeStampSeconds = event.platformTimeStamp(); 505 webEvent.timeStampSeconds = toSeconds(event.platformTimeStamp());
498 webEvent.modifiers = event.modifiers(); 506 webEvent.modifiers = event.modifiers();
499 507
500 FrameView* view = widget ? toFrameView(widget->parent()) : 0; 508 FrameView* view = widget ? toFrameView(widget->parent()) : 0;
501 // TODO(bokan): If view == nullptr, pointInRootFrame will really be 509 // TODO(bokan): If view == nullptr, pointInRootFrame will really be
502 // pointInRootContent. 510 // pointInRootContent.
503 IntPoint pointInRootFrame(event.absoluteLocation().x(), 511 IntPoint pointInRootFrame(event.absoluteLocation().x(),
504 event.absoluteLocation().y()); 512 event.absoluteLocation().y());
505 if (view) 513 if (view)
506 pointInRootFrame = view->contentsToRootFrame(pointInRootFrame); 514 pointInRootFrame = view->contentsToRootFrame(pointInRootFrame);
507 webEvent.globalX = event.screenX(); 515 webEvent.globalX = event.screenX();
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
590 598
591 if (event.type() == EventTypeNames::touchstart) 599 if (event.type() == EventTypeNames::touchstart)
592 type = MouseDown; 600 type = MouseDown;
593 else if (event.type() == EventTypeNames::touchmove) 601 else if (event.type() == EventTypeNames::touchmove)
594 type = MouseMove; 602 type = MouseMove;
595 else if (event.type() == EventTypeNames::touchend) 603 else if (event.type() == EventTypeNames::touchend)
596 type = MouseUp; 604 type = MouseUp;
597 else 605 else
598 return; 606 return;
599 607
600 timeStampSeconds = event.platformTimeStamp(); 608 timeStampSeconds = toSeconds(event.platformTimeStamp());
601 modifiers = event.modifiers(); 609 modifiers = event.modifiers();
602 610
603 // The mouse event co-ordinates should be generated from the co-ordinates of 611 // The mouse event co-ordinates should be generated from the co-ordinates of
604 // the touch point. 612 // the touch point.
605 FrameView* view = toFrameView(widget->parent()); 613 FrameView* view = toFrameView(widget->parent());
606 // FIXME: if view == nullptr, pointInRootFrame will really be 614 // FIXME: if view == nullptr, pointInRootFrame will really be
607 // pointInRootContent. 615 // pointInRootContent.
608 IntPoint pointInRootFrame = roundedIntPoint(touch->absoluteLocation()); 616 IntPoint pointInRootFrame = roundedIntPoint(touch->absoluteLocation());
609 if (view) 617 if (view)
610 pointInRootFrame = view->contentsToRootFrame(pointInRootFrame); 618 pointInRootFrame = view->contentsToRootFrame(pointInRootFrame);
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
665 if (event.type() == EventTypeNames::keydown) 673 if (event.type() == EventTypeNames::keydown)
666 type = KeyDown; 674 type = KeyDown;
667 else if (event.type() == EventTypeNames::keyup) 675 else if (event.type() == EventTypeNames::keyup)
668 type = WebInputEvent::KeyUp; 676 type = WebInputEvent::KeyUp;
669 else if (event.type() == EventTypeNames::keypress) 677 else if (event.type() == EventTypeNames::keypress)
670 type = WebInputEvent::Char; 678 type = WebInputEvent::Char;
671 else 679 else
672 return; // Skip all other keyboard events. 680 return; // Skip all other keyboard events.
673 681
674 modifiers = event.modifiers(); 682 modifiers = event.modifiers();
675 timeStampSeconds = event.platformTimeStamp(); 683 timeStampSeconds = toSeconds(event.platformTimeStamp());
676 windowsKeyCode = event.keyCode(); 684 windowsKeyCode = event.keyCode();
677 } 685 }
678 686
679 static WebTouchPoint toWebTouchPoint(const Touch* touch, 687 static WebTouchPoint toWebTouchPoint(const Touch* touch,
680 const LayoutItem layoutItem, 688 const LayoutItem layoutItem,
681 WebTouchPoint::State state, 689 WebTouchPoint::State state,
682 WebPointerProperties::PointerType type) { 690 WebPointerProperties::PointerType type) {
683 WebTouchPoint point; 691 WebTouchPoint point;
684 point.pointerType = type; 692 point.pointerType = type;
685 point.id = touch->identifier(); 693 point.id = touch->identifier();
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
739 else if (event.type() == EventTypeNames::touchend) 747 else if (event.type() == EventTypeNames::touchend)
740 type = TouchEnd; 748 type = TouchEnd;
741 else if (event.type() == EventTypeNames::touchcancel) 749 else if (event.type() == EventTypeNames::touchcancel)
742 type = TouchCancel; 750 type = TouchCancel;
743 else { 751 else {
744 NOTREACHED(); 752 NOTREACHED();
745 type = Undefined; 753 type = Undefined;
746 return; 754 return;
747 } 755 }
748 756
749 timeStampSeconds = event.platformTimeStamp(); 757 timeStampSeconds = toSeconds(event.platformTimeStamp());
750 modifiers = event.modifiers(); 758 modifiers = event.modifiers();
751 dispatchType = event.cancelable() ? WebInputEvent::Blocking 759 dispatchType = event.cancelable() ? WebInputEvent::Blocking
752 : WebInputEvent::EventNonBlocking; 760 : WebInputEvent::EventNonBlocking;
753 movedBeyondSlopRegion = event.causesScrollingIfUncanceled(); 761 movedBeyondSlopRegion = event.causesScrollingIfUncanceled();
754 762
755 // Currently touches[] is empty, add stationary points as-is. 763 // Currently touches[] is empty, add stationary points as-is.
756 for (unsigned i = 0; 764 for (unsigned i = 0;
757 i < event.touches()->length() && 765 i < event.touches()->length() &&
758 i < static_cast<unsigned>(WebTouchEvent::kTouchesLengthCap); 766 i < static_cast<unsigned>(WebTouchEvent::kTouchesLengthCap);
759 ++i) { 767 ++i) {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
804 resendingPluginId = event.resendingPluginId(); 812 resendingPluginId = event.resendingPluginId();
805 } else if (event.type() == EventTypeNames::gestureflingstart) { 813 } else if (event.type() == EventTypeNames::gestureflingstart) {
806 type = GestureFlingStart; 814 type = GestureFlingStart;
807 data.flingStart.velocityX = event.velocityX(); 815 data.flingStart.velocityX = event.velocityX();
808 data.flingStart.velocityY = event.velocityY(); 816 data.flingStart.velocityY = event.velocityY();
809 } else if (event.type() == EventTypeNames::gesturetap) { 817 } else if (event.type() == EventTypeNames::gesturetap) {
810 type = GestureTap; 818 type = GestureTap;
811 data.tap.tapCount = 1; 819 data.tap.tapCount = 1;
812 } 820 }
813 821
814 timeStampSeconds = event.platformTimeStamp(); 822 timeStampSeconds = toSeconds(event.platformTimeStamp());
815 modifiers = event.modifiers(); 823 modifiers = event.modifiers();
816 824
817 globalX = event.screenX(); 825 globalX = event.screenX();
818 globalY = event.screenY(); 826 globalY = event.screenY();
819 IntPoint localPoint = convertAbsoluteLocationForLayoutObjectInt( 827 IntPoint localPoint = convertAbsoluteLocationForLayoutObjectInt(
820 event.absoluteLocation(), layoutItem); 828 event.absoluteLocation(), layoutItem);
821 x = localPoint.x(); 829 x = localPoint.x();
822 y = localPoint.y(); 830 y = localPoint.y();
823 831
824 switch (event.source()) { 832 switch (event.source()) {
(...skipping 26 matching lines...) Expand all
851 Vector<PlatformTouchEvent> result; 859 Vector<PlatformTouchEvent> result;
852 for (const auto& event : coalescedEvents) { 860 for (const auto& event : coalescedEvents) {
853 DCHECK(WebInputEvent::isTouchEventType(event->type)); 861 DCHECK(WebInputEvent::isTouchEventType(event->type));
854 result.append(PlatformTouchEventBuilder( 862 result.append(PlatformTouchEventBuilder(
855 widget, static_cast<const WebTouchEvent&>(*event))); 863 widget, static_cast<const WebTouchEvent&>(*event)));
856 } 864 }
857 return result; 865 return result;
858 } 866 }
859 867
860 } // namespace blink 868 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698