Chromium Code Reviews| Index: third_party/WebKit/Source/core/events/PointerEventFactory.cpp |
| diff --git a/third_party/WebKit/Source/core/events/PointerEventFactory.cpp b/third_party/WebKit/Source/core/events/PointerEventFactory.cpp |
| index 5c476a6c612687bb9a28480fa707b594d9a169ac..f61342f9166141bcc281d66a777cae980c843e6d 100644 |
| --- a/third_party/WebKit/Source/core/events/PointerEventFactory.cpp |
| +++ b/third_party/WebKit/Source/core/events/PointerEventFactory.cpp |
| @@ -75,12 +75,24 @@ unsigned short buttonToButtonsBitfield(WebPointerProperties::Button button) { |
| return 0; |
| } |
| -} // namespace |
| - |
| -const int PointerEventFactory::s_invalidId = 0; |
| - |
| -// Mouse id is 1 to behave the same as MS Edge for compatibility reasons. |
| -const int PointerEventFactory::s_mouseId = 1; |
| +const AtomicString& pointerEventNameForTouchPointState( |
| + PlatformTouchPoint::TouchState state) { |
| + switch (state) { |
| + case PlatformTouchPoint::TouchReleased: |
| + return EventTypeNames::pointerup; |
| + case PlatformTouchPoint::TouchCancelled: |
| + return EventTypeNames::pointercancel; |
| + case PlatformTouchPoint::TouchPressed: |
| + return EventTypeNames::pointerdown; |
| + case PlatformTouchPoint::TouchMoved: |
| + return EventTypeNames::pointermove; |
| + case PlatformTouchPoint::TouchStationary: |
| + // Fall through to default |
| + default: |
| + NOTREACHED(); |
| + return emptyAtom; |
| + } |
| +} |
| float getPointerEventPressure(float force, int buttons) { |
| if (std::isnan(force)) |
| @@ -88,6 +100,67 @@ float getPointerEventPressure(float force, int buttons) { |
| return force; |
| } |
| +void updateTouchPointPointerEventInit(const PlatformTouchPoint& touchPoint, |
|
mustaq
2016/11/21 20:53:53
You meant "updateTouchPointerEventInit" instead?
Navid Zolghadr
2016/11/21 21:31:21
Done.
|
| + LocalFrame* targetFrame, |
| + PointerEventInit* pointerEventInit) { |
| + if (targetFrame) { |
| + FloatPoint pagePoint = |
| + targetFrame->view()->rootFrameToContents(touchPoint.pos()); |
| + float scaleFactor = 1.0f / targetFrame->pageZoomFactor(); |
| + FloatPoint scrollPosition(targetFrame->view()->scrollOffset()); |
| + FloatPoint clientPoint = pagePoint.scaledBy(scaleFactor); |
| + clientPoint.moveBy(scrollPosition.scaledBy(-scaleFactor)); |
| + |
| + pointerEventInit->setClientX(clientPoint.x()); |
| + pointerEventInit->setClientY(clientPoint.y()); |
| + |
| + FloatSize pointRadius = touchPoint.radius().scaledBy(scaleFactor); |
|
mustaq
2016/11/21 20:53:53
Radius, width & height should be outside the |if|
Navid Zolghadr
2016/11/21 21:31:21
But scaleFactor comes from the targetFrame. What s
mustaq
2016/11/22 15:31:10
I thought it's a bug because when target frame is
|
| + pointerEventInit->setWidth(pointRadius.width()); |
| + pointerEventInit->setHeight(pointRadius.height()); |
| + } |
| + |
| + pointerEventInit->setScreenX(touchPoint.screenPos().x()); |
| + pointerEventInit->setScreenY(touchPoint.screenPos().y()); |
| + pointerEventInit->setPressure( |
| + getPointerEventPressure(touchPoint.force(), pointerEventInit->buttons())); |
| + pointerEventInit->setTiltX(touchPoint.pointerProperties().tiltX); |
| + pointerEventInit->setTiltY(touchPoint.pointerProperties().tiltY); |
| +} |
| + |
| +void updateMousePointerEventInit(const PlatformMouseEvent& mouseEvent, |
| + LocalDOMWindow* view, |
| + PointerEventInit* pointerEventInit) { |
| + pointerEventInit->setScreenX(mouseEvent.globalPosition().x()); |
| + pointerEventInit->setScreenY(mouseEvent.globalPosition().y()); |
| + |
| + IntPoint locationInFrameZoomed; |
| + if (view && view->frame() && view->frame()->view()) { |
| + LocalFrame* frame = view->frame(); |
| + FrameView* frameView = frame->view(); |
| + IntPoint locationInContents = |
| + frameView->rootFrameToContents(mouseEvent.position()); |
| + locationInFrameZoomed = frameView->contentsToFrame(locationInContents); |
| + float scaleFactor = 1 / frame->pageZoomFactor(); |
| + locationInFrameZoomed.scale(scaleFactor, scaleFactor); |
| + } |
| + |
| + // Set up initial values for coordinates. |
|
mustaq
2016/11/21 20:53:53
Please get rid of this old comment line, the value
Navid Zolghadr
2016/11/21 21:31:21
Done.
|
| + pointerEventInit->setClientX(locationInFrameZoomed.x()); |
| + pointerEventInit->setClientY(locationInFrameZoomed.y()); |
| + |
| + pointerEventInit->setPressure(getPointerEventPressure( |
| + mouseEvent.pointerProperties().force, pointerEventInit->buttons())); |
| + pointerEventInit->setTiltX(mouseEvent.pointerProperties().tiltX); |
| + pointerEventInit->setTiltY(mouseEvent.pointerProperties().tiltY); |
| +} |
| + |
| +} // namespace |
| + |
| +const int PointerEventFactory::s_invalidId = 0; |
| + |
| +// Mouse id is 1 to behave the same as MS Edge for compatibility reasons. |
| +const int PointerEventFactory::s_mouseId = 1; |
| + |
| void PointerEventFactory::setIdTypeButtons( |
| PointerEventInit& pointerEventInit, |
| const WebPointerProperties& pointerProperties, |
| @@ -128,15 +201,20 @@ void PointerEventFactory::setEventSpecificFields( |
| pointerEventInit.setDetail(0); |
| } |
| -PointerEvent* PointerEventFactory::create(const AtomicString& mouseEventName, |
| - const PlatformMouseEvent& mouseEvent, |
| - LocalDOMWindow* view) { |
| +PointerEvent* PointerEventFactory::create( |
| + const AtomicString& mouseEventName, |
| + const PlatformMouseEvent& mouseEvent, |
| + const Vector<PlatformMouseEvent>& coalescedMouseEvents, |
| + LocalDOMWindow* view) { |
| DCHECK(mouseEventName == EventTypeNames::mousemove || |
| mouseEventName == EventTypeNames::mousedown || |
| mouseEventName == EventTypeNames::mouseup); |
| AtomicString pointerEventName = |
| pointerEventNameForMouseEventName(mouseEventName); |
| + DCHECK(pointerEventName == EventTypeNames::pointermove || |
| + coalescedMouseEvents.isEmpty()); |
| + |
| unsigned buttons = |
| MouseEvent::platformModifiersToButtons(mouseEvent.getModifiers()); |
| PointerEventInit pointerEventInit; |
| @@ -144,24 +222,6 @@ PointerEvent* PointerEventFactory::create(const AtomicString& mouseEventName, |
| setIdTypeButtons(pointerEventInit, mouseEvent.pointerProperties(), buttons); |
| setEventSpecificFields(pointerEventInit, pointerEventName); |
| - pointerEventInit.setScreenX(mouseEvent.globalPosition().x()); |
| - pointerEventInit.setScreenY(mouseEvent.globalPosition().y()); |
| - |
| - IntPoint locationInFrameZoomed; |
| - if (view && view->frame() && view->frame()->view()) { |
| - LocalFrame* frame = view->frame(); |
| - FrameView* frameView = frame->view(); |
| - IntPoint locationInContents = |
| - frameView->rootFrameToContents(mouseEvent.position()); |
| - locationInFrameZoomed = frameView->contentsToFrame(locationInContents); |
| - float scaleFactor = 1 / frame->pageZoomFactor(); |
| - locationInFrameZoomed.scale(scaleFactor, scaleFactor); |
| - } |
| - |
| - // Set up initial values for coordinates. |
| - pointerEventInit.setClientX(locationInFrameZoomed.x()); |
| - pointerEventInit.setClientY(locationInFrameZoomed.y()); |
| - |
| if (pointerEventName == EventTypeNames::pointerdown || |
| pointerEventName == EventTypeNames::pointerup) { |
| WebPointerProperties::Button button = mouseEvent.pointerProperties().button; |
| @@ -176,10 +236,6 @@ PointerEvent* PointerEventFactory::create(const AtomicString& mouseEventName, |
| pointerEventInit.setButton( |
| static_cast<int>(WebPointerProperties::Button::NoButton)); |
| } |
| - pointerEventInit.setPressure(getPointerEventPressure( |
| - mouseEvent.pointerProperties().force, pointerEventInit.buttons())); |
| - pointerEventInit.setTiltX(mouseEvent.pointerProperties().tiltX); |
| - pointerEventInit.setTiltY(mouseEvent.pointerProperties().tiltY); |
| UIEventWithKeyState::setFromPlatformModifiers(pointerEventInit, |
| mouseEvent.getModifiers()); |
| @@ -194,16 +250,31 @@ PointerEvent* PointerEventFactory::create(const AtomicString& mouseEventName, |
| pointerEventInit.setView(view); |
| + updateMousePointerEventInit(mouseEvent, view, &pointerEventInit); |
| + |
| + // Created coalesced events init structure |
| + HeapVector<Member<PointerEvent>> coalescedPointerEvents; |
| + for (const auto& coalescedMouseEvent : coalescedMouseEvents) { |
| + PointerEventInit coalescedEventInit = pointerEventInit; |
| + updateMousePointerEventInit(coalescedMouseEvent, view, &coalescedEventInit); |
| + coalescedPointerEvents.append( |
|
mustaq
2016/11/21 20:53:53
Add a DCHECK here for matching (with the container
Navid Zolghadr
2016/11/21 21:31:21
I'm not sure what the DCHECK would achieve here. W
mustaq
2016/11/22 15:31:10
Right but we still need to enforce the equality of
Navid Zolghadr
2016/11/22 15:59:28
I don't think that is the case either as that path
mustaq
2016/11/22 21:07:51
Instead of the raw data checks you have added, let
|
| + PointerEvent::create(pointerEventName, coalescedEventInit)); |
| + } |
| + pointerEventInit.setCoalescedEvents(coalescedPointerEvents); |
| + |
| return PointerEvent::create(pointerEventName, pointerEventInit); |
| } |
| -PointerEvent* PointerEventFactory::create(const AtomicString& type, |
| - const PlatformTouchPoint& touchPoint, |
| - PlatformEvent::Modifiers modifiers, |
| - const FloatSize& pointRadius, |
| - const FloatPoint& clientPoint, |
| - DOMWindow* view) { |
| +PointerEvent* PointerEventFactory::create( |
| + const PlatformTouchPoint& touchPoint, |
| + const Vector<PlatformTouchPoint>& coalescedPoints, |
| + PlatformEvent::Modifiers modifiers, |
| + LocalFrame* targetFrame, |
| + DOMWindow* view) { |
| const PlatformTouchPoint::TouchState pointState = touchPoint.state(); |
| + const AtomicString& type = |
| + pointerEventNameForTouchPointState(touchPoint.state()); |
| + DCHECK(type == EventTypeNames::pointermove || coalescedPoints.isEmpty()); |
| bool pointerReleasedOrCancelled = |
| pointState == PlatformTouchPoint::TouchReleased || |
| @@ -216,26 +287,28 @@ PointerEvent* PointerEventFactory::create(const AtomicString& type, |
| setIdTypeButtons(pointerEventInit, touchPoint.pointerProperties(), |
| pointerReleasedOrCancelled ? 0 : 1); |
| - |
| - pointerEventInit.setWidth(pointRadius.width()); |
| - pointerEventInit.setHeight(pointRadius.height()); |
| - pointerEventInit.setScreenX(touchPoint.screenPos().x()); |
| - pointerEventInit.setScreenY(touchPoint.screenPos().y()); |
| - pointerEventInit.setClientX(clientPoint.x()); |
| - pointerEventInit.setClientY(clientPoint.y()); |
| pointerEventInit.setButton(static_cast<int>( |
| pointerPressedOrReleased ? WebPointerProperties::Button::Left |
| : WebPointerProperties::Button::NoButton)); |
| - pointerEventInit.setPressure( |
| - getPointerEventPressure(touchPoint.force(), pointerEventInit.buttons())); |
| - pointerEventInit.setTiltX(touchPoint.pointerProperties().tiltX); |
| - pointerEventInit.setTiltY(touchPoint.pointerProperties().tiltY); |
| + |
| pointerEventInit.setView(view); |
| + updateTouchPointPointerEventInit(touchPoint, targetFrame, &pointerEventInit); |
| UIEventWithKeyState::setFromPlatformModifiers(pointerEventInit, modifiers); |
| setEventSpecificFields(pointerEventInit, type); |
| + // Created coalesced events init structure |
| + HeapVector<Member<PointerEvent>> coalescedPointerEvents; |
| + for (const auto& coalescedTouchPoint : coalescedPoints) { |
| + PointerEventInit coalescedEventInit = pointerEventInit; |
| + updateTouchPointPointerEventInit(coalescedTouchPoint, targetFrame, |
| + &coalescedEventInit); |
| + coalescedPointerEvents.append( |
|
mustaq
2016/11/21 20:53:53
Ditto.
|
| + PointerEvent::create(type, coalescedEventInit)); |
| + } |
| + pointerEventInit.setCoalescedEvents(coalescedPointerEvents); |
| + |
| return PointerEvent::create(type, pointerEventInit); |
| } |