Index: third_party/WebKit/Source/web/WebInputEventConversion.cpp |
diff --git a/third_party/WebKit/Source/web/WebInputEventConversion.cpp b/third_party/WebKit/Source/web/WebInputEventConversion.cpp |
index f720a9fa7f693772cc4be9dddbcf18de1e635cf2..aed825ce918ec8e496f48ca293ac7ab271801bc2 100644 |
--- a/third_party/WebKit/Source/web/WebInputEventConversion.cpp |
+++ b/third_party/WebKit/Source/web/WebInputEventConversion.cpp |
@@ -89,11 +89,6 @@ float scaleDeltaToWindow(const Widget* widget, float delta) { |
return delta / frameScale(widget); |
} |
-FloatSize scaleSizeToWindow(const Widget* widget, FloatSize size) { |
- return FloatSize(scaleDeltaToWindow(widget, size.width()), |
- scaleDeltaToWindow(widget, size.height())); |
-} |
- |
// This method converts from the renderer's coordinate space into Blink's root |
// frame coordinate space. It's somewhat unique in that it takes into account |
// DevTools emulation, which applies a scale and offset in the root layer (see |
@@ -127,31 +122,6 @@ FloatPoint convertHitPointToRootFrame(const Widget* widget, |
visualViewport.y() + overscrollOffset.height()); |
} |
-PlatformEvent::DispatchType toPlatformDispatchType( |
- WebInputEvent::DispatchType type) { |
- static_assert(PlatformEvent::DispatchType::Blocking == |
- static_cast<PlatformEvent::DispatchType>( |
- WebInputEvent::DispatchType::Blocking), |
- "Dispatch Types not equal"); |
- static_assert(PlatformEvent::DispatchType::EventNonBlocking == |
- static_cast<PlatformEvent::DispatchType>( |
- WebInputEvent::DispatchType::EventNonBlocking), |
- "Dispatch Types not equal"); |
- static_assert( |
- PlatformEvent::DispatchType::ListenersNonBlockingPassive == |
- static_cast<PlatformEvent::DispatchType>( |
- WebInputEvent::DispatchType::ListenersNonBlockingPassive), |
- "Dispatch Types not equal"); |
- static_assert( |
- PlatformEvent::DispatchType::ListenersForcedNonBlockingDueToFling == |
- static_cast<PlatformEvent::DispatchType>( |
- WebInputEvent::DispatchType:: |
- ListenersForcedNonBlockingDueToFling), |
- "Dispatch Types not equal"); |
- |
- return static_cast<PlatformEvent::DispatchType>(type); |
-} |
- |
unsigned toPlatformModifierFrom(WebMouseEvent::Button button) { |
if (button == WebMouseEvent::Button::NoButton) |
return 0; |
@@ -163,6 +133,45 @@ unsigned toPlatformModifierFrom(WebMouseEvent::Button button) { |
return webMouseButtonToPlatformModifier[static_cast<int>(button)]; |
} |
+FloatPoint convertAbsoluteLocationForLayoutObjectFloat( |
+ const DoublePoint& location, |
+ const LayoutItem layoutItem) { |
+ return layoutItem.absoluteToLocal(FloatPoint(location), UseTransforms); |
+} |
+ |
+IntPoint convertAbsoluteLocationForLayoutObjectInt( |
+ const DoublePoint& location, |
+ const LayoutItem layoutItem) { |
+ return roundedIntPoint( |
+ convertAbsoluteLocationForLayoutObjectFloat(location, layoutItem)); |
+} |
+ |
+// FIXME: Change |widget| to const Widget& after RemoteFrames get |
+// RemoteFrameViews. |
+void updateWebMouseEventFromCoreMouseEvent(const MouseEvent& event, |
+ const Widget* widget, |
+ const LayoutItem layoutItem, |
+ WebMouseEvent& webEvent) { |
+ webEvent.setTimeStampSeconds(event.platformTimeStamp().InSeconds()); |
+ webEvent.setModifiers(event.modifiers()); |
+ |
+ FrameView* view = widget ? toFrameView(widget->parent()) : 0; |
+ // TODO(bokan): If view == nullptr, pointInRootFrame will really be |
+ // pointInRootContent. |
+ IntPoint pointInRootFrame(event.absoluteLocation().x(), |
+ event.absoluteLocation().y()); |
+ if (view) |
+ pointInRootFrame = view->contentsToRootFrame(pointInRootFrame); |
+ webEvent.globalX = event.screenX(); |
+ webEvent.globalY = event.screenY(); |
+ webEvent.windowX = pointInRootFrame.x(); |
+ webEvent.windowY = pointInRootFrame.y(); |
+ IntPoint localPoint = convertAbsoluteLocationForLayoutObjectInt( |
+ event.absoluteLocation(), layoutItem); |
+ webEvent.x = localPoint.x(); |
+ webEvent.y = localPoint.y(); |
+} |
+ |
} // namespace |
// MakePlatformMouseEvent ----------------------------------------------------- |
@@ -227,127 +236,23 @@ WebGestureEvent TransformWebGestureEvent(Widget* widget, |
return result; |
} |
-inline PlatformEvent::EventType toPlatformTouchEventType( |
- const WebInputEvent::Type type) { |
- switch (type) { |
- case WebInputEvent::TouchStart: |
- return PlatformEvent::TouchStart; |
- case WebInputEvent::TouchMove: |
- return PlatformEvent::TouchMove; |
- case WebInputEvent::TouchEnd: |
- return PlatformEvent::TouchEnd; |
- case WebInputEvent::TouchCancel: |
- return PlatformEvent::TouchCancel; |
- case WebInputEvent::TouchScrollStarted: |
- return PlatformEvent::TouchScrollStarted; |
- default: |
- NOTREACHED(); |
- } |
- return PlatformEvent::TouchStart; |
-} |
- |
-inline PlatformTouchPoint::TouchState toPlatformTouchPointState( |
- const WebTouchPoint::State state) { |
- switch (state) { |
- case WebTouchPoint::StateReleased: |
- return PlatformTouchPoint::TouchReleased; |
- case WebTouchPoint::StatePressed: |
- return PlatformTouchPoint::TouchPressed; |
- case WebTouchPoint::StateMoved: |
- return PlatformTouchPoint::TouchMoved; |
- case WebTouchPoint::StateStationary: |
- return PlatformTouchPoint::TouchStationary; |
- case WebTouchPoint::StateCancelled: |
- return PlatformTouchPoint::TouchCancelled; |
- case WebTouchPoint::StateUndefined: |
- NOTREACHED(); |
- } |
- return PlatformTouchPoint::TouchReleased; |
-} |
- |
-inline WebTouchPoint::State toWebTouchPointState(const AtomicString& type) { |
- if (type == EventTypeNames::touchend) |
- return WebTouchPoint::StateReleased; |
- if (type == EventTypeNames::touchcancel) |
- return WebTouchPoint::StateCancelled; |
- if (type == EventTypeNames::touchstart) |
- return WebTouchPoint::StatePressed; |
- if (type == EventTypeNames::touchmove) |
- return WebTouchPoint::StateMoved; |
- return WebTouchPoint::StateUndefined; |
-} |
- |
-// TODO(mustaq): Add tests for this. |
-PlatformTouchPointBuilder::PlatformTouchPointBuilder( |
- Widget* widget, |
- const WebTouchPoint& point) { |
- m_pointerProperties = point; |
- m_state = toPlatformTouchPointState(point.state); |
- |
- FloatPoint floatPos = convertHitPointToRootFrame(widget, point.position); |
- IntPoint flooredPoint = flooredIntPoint(floatPos); |
- m_pos = |
- widget->convertFromRootFrame(flooredPoint) + (floatPos - flooredPoint); |
- |
- m_screenPos = FloatPoint(point.screenPosition.x, point.screenPosition.y); |
- m_radius = scaleSizeToWindow(widget, FloatSize(point.radiusX, point.radiusY)); |
- m_rotationAngle = point.rotationAngle; |
-} |
- |
-PlatformTouchEventBuilder::PlatformTouchEventBuilder( |
- Widget* widget, |
- const WebTouchEvent& event) { |
- m_type = toPlatformTouchEventType(event.type()); |
- m_modifiers = event.modifiers(); |
- m_timestamp = TimeTicks::FromSeconds(event.timeStampSeconds()); |
- m_causesScrollingIfUncanceled = event.movedBeyondSlopRegion; |
- m_touchStartOrFirstTouchMove = event.touchStartOrFirstTouchMove; |
- |
- for (unsigned i = 0; i < event.touchesLength; ++i) |
- m_touchPoints.push_back( |
- PlatformTouchPointBuilder(widget, event.touches[i])); |
- |
- m_dispatchType = toPlatformDispatchType(event.dispatchType); |
- m_uniqueTouchEventId = event.uniqueTouchEventId; |
-} |
- |
-static FloatPoint convertAbsoluteLocationForLayoutObjectFloat( |
- const DoublePoint& location, |
- const LayoutItem layoutItem) { |
- return layoutItem.absoluteToLocal(FloatPoint(location), UseTransforms); |
-} |
- |
-static IntPoint convertAbsoluteLocationForLayoutObjectInt( |
- const DoublePoint& location, |
- const LayoutItem layoutItem) { |
- return roundedIntPoint( |
- convertAbsoluteLocationForLayoutObjectFloat(location, layoutItem)); |
+WebTouchEvent TransformWebTouchEvent(float frameScale, |
+ FloatPoint frameTranslate, |
+ const WebTouchEvent& event) { |
+ // frameScale is default initialized in debug builds to be 0. |
+ DCHECK_EQ(0, event.frameScale()); |
+ DCHECK_EQ(0, event.frameTranslate().x); |
+ DCHECK_EQ(0, event.frameTranslate().y); |
+ WebTouchEvent result = event; |
+ result.setFrameScale(frameScale); |
+ result.setFrameTranslate(frameTranslate); |
+ return result; |
} |
-// FIXME: Change |widget| to const Widget& after RemoteFrames get |
-// RemoteFrameViews. |
-static void updateWebMouseEventFromCoreMouseEvent(const MouseEvent& event, |
- const Widget* widget, |
- const LayoutItem layoutItem, |
- WebMouseEvent& webEvent) { |
- webEvent.setTimeStampSeconds(event.platformTimeStamp().InSeconds()); |
- webEvent.setModifiers(event.modifiers()); |
- |
- FrameView* view = widget ? toFrameView(widget->parent()) : 0; |
- // TODO(bokan): If view == nullptr, pointInRootFrame will really be |
- // pointInRootContent. |
- IntPoint pointInRootFrame(event.absoluteLocation().x(), |
- event.absoluteLocation().y()); |
- if (view) |
- pointInRootFrame = view->contentsToRootFrame(pointInRootFrame); |
- webEvent.globalX = event.screenX(); |
- webEvent.globalY = event.screenY(); |
- webEvent.windowX = pointInRootFrame.x(); |
- webEvent.windowY = pointInRootFrame.y(); |
- IntPoint localPoint = convertAbsoluteLocationForLayoutObjectInt( |
- event.absoluteLocation(), layoutItem); |
- webEvent.x = localPoint.x(); |
- webEvent.y = localPoint.y(); |
+WebTouchEvent TransformWebTouchEvent(Widget* widget, |
+ const WebTouchEvent& event) { |
+ return TransformWebTouchEvent(frameScale(widget), frameTranslation(widget), |
+ event); |
} |
WebMouseEventBuilder::WebMouseEventBuilder(const Widget* widget, |
@@ -437,6 +342,8 @@ WebMouseEventBuilder::WebMouseEventBuilder(const Widget* widget, |
m_timeStampSeconds = event.platformTimeStamp().InSeconds(); |
m_modifiers = event.modifiers(); |
+ m_frameScale = 1; |
+ m_frameTranslate = WebFloatPoint(); |
// The mouse event co-ordinates should be generated from the co-ordinates of |
// the touch point. |
@@ -489,99 +396,6 @@ WebKeyboardEventBuilder::WebKeyboardEventBuilder(const KeyboardEvent& event) { |
windowsKeyCode = event.keyCode(); |
} |
-static WebTouchPoint toWebTouchPoint(const Touch* touch, |
- const LayoutItem layoutItem, |
- WebTouchPoint::State state, |
- WebPointerProperties::PointerType type) { |
- WebTouchPoint point; |
- point.pointerType = type; |
- point.id = touch->identifier(); |
- point.screenPosition = touch->screenLocation(); |
- point.position = convertAbsoluteLocationForLayoutObjectFloat( |
- DoublePoint(touch->absoluteLocation()), layoutItem); |
- point.radiusX = touch->radiusX(); |
- point.radiusY = touch->radiusY(); |
- point.rotationAngle = touch->rotationAngle(); |
- point.force = touch->force(); |
- point.state = state; |
- return point; |
-} |
- |
-static unsigned indexOfTouchPointWithId(const WebTouchPoint* touchPoints, |
- unsigned touchPointsLength, |
- unsigned id) { |
- for (unsigned i = 0; i < touchPointsLength; ++i) { |
- if (touchPoints[i].id == static_cast<int>(id)) |
- return i; |
- } |
- return std::numeric_limits<unsigned>::max(); |
-} |
- |
-static void addTouchPointsUpdateStateIfNecessary( |
- WebTouchPoint::State state, |
- TouchList* touches, |
- WebTouchPoint* touchPoints, |
- unsigned* touchPointsLength, |
- const LayoutItem layoutItem, |
- WebPointerProperties::PointerType pointerType) { |
- unsigned initialTouchPointsLength = *touchPointsLength; |
- for (unsigned i = 0; i < touches->length(); ++i) { |
- const unsigned pointIndex = *touchPointsLength; |
- if (pointIndex >= static_cast<unsigned>(WebTouchEvent::kTouchesLengthCap)) |
- return; |
- |
- const Touch* touch = touches->item(i); |
- unsigned existingPointIndex = indexOfTouchPointWithId( |
- touchPoints, initialTouchPointsLength, touch->identifier()); |
- if (existingPointIndex != std::numeric_limits<unsigned>::max()) { |
- touchPoints[existingPointIndex].state = state; |
- } else { |
- touchPoints[pointIndex] = |
- toWebTouchPoint(touch, layoutItem, state, pointerType); |
- ++(*touchPointsLength); |
- } |
- } |
-} |
- |
-WebTouchEventBuilder::WebTouchEventBuilder(const LayoutItem layoutItem, |
- const TouchEvent& event) { |
- if (event.type() == EventTypeNames::touchstart) |
- m_type = TouchStart; |
- else if (event.type() == EventTypeNames::touchmove) |
- m_type = TouchMove; |
- else if (event.type() == EventTypeNames::touchend) |
- m_type = TouchEnd; |
- else if (event.type() == EventTypeNames::touchcancel) |
- m_type = TouchCancel; |
- else { |
- NOTREACHED(); |
- m_type = Undefined; |
- return; |
- } |
- |
- m_timeStampSeconds = event.platformTimeStamp().InSeconds(); |
- m_modifiers = event.modifiers(); |
- dispatchType = event.cancelable() ? WebInputEvent::Blocking |
- : WebInputEvent::EventNonBlocking; |
- movedBeyondSlopRegion = event.causesScrollingIfUncanceled(); |
- |
- // Currently touches[] is empty, add stationary points as-is. |
- for (unsigned i = 0; |
- i < event.touches()->length() && |
- i < static_cast<unsigned>(WebTouchEvent::kTouchesLengthCap); |
- ++i) { |
- touches[i] = |
- toWebTouchPoint(event.touches()->item(i), layoutItem, |
- WebTouchPoint::StateStationary, event.pointerType()); |
- ++touchesLength; |
- } |
- // If any existing points are also in the change list, we should update |
- // their state, otherwise just add the new points. |
- addTouchPointsUpdateStateIfNecessary( |
- toWebTouchPointState(event.type()), event.changedTouches(), touches, |
- &touchesLength, layoutItem, event.pointerType()); |
-} |
- |
Vector<PlatformMouseEvent> createPlatformMouseEventVector( |
Widget* widget, |
const std::vector<const WebInputEvent*>& coalescedEvents) { |
@@ -594,14 +408,16 @@ Vector<PlatformMouseEvent> createPlatformMouseEventVector( |
return result; |
} |
-Vector<PlatformTouchEvent> createPlatformTouchEventVector( |
+Vector<WebTouchEvent> TransformWebTouchEventVector( |
Widget* widget, |
const std::vector<const WebInputEvent*>& coalescedEvents) { |
- Vector<PlatformTouchEvent> result; |
+ float scale = frameScale(widget); |
+ FloatPoint translation = frameTranslation(widget); |
+ Vector<WebTouchEvent> result; |
for (const auto& event : coalescedEvents) { |
DCHECK(WebInputEvent::isTouchEventType(event->type())); |
- result.push_back(PlatformTouchEventBuilder( |
- widget, static_cast<const WebTouchEvent&>(*event))); |
+ result.push_back(TransformWebTouchEvent( |
+ scale, translation, static_cast<const WebTouchEvent&>(*event))); |
} |
return result; |
} |