| 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..7719836db8652c60540e1c850ac2db9e1fb27725 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,
|
| + 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);
|
| + 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.
|
| + 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,9 +201,11 @@ 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>& coalescedEvents,
|
| + LocalDOMWindow* view) {
|
| DCHECK(mouseEventName == EventTypeNames::mousemove ||
|
| mouseEventName == EventTypeNames::mousedown ||
|
| mouseEventName == EventTypeNames::mouseup);
|
| @@ -144,24 +219,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 +233,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 +247,29 @@ PointerEvent* PointerEventFactory::create(const AtomicString& mouseEventName,
|
|
|
| pointerEventInit.setView(view);
|
|
|
| + updateMousePointerEventInit(mouseEvent, view, &pointerEventInit);
|
| +
|
| + // Created coalesced events init structure
|
| + HeapVector<PointerEventInit> coalescedEventInits;
|
| + for (const auto& coalescedMouseEvent : coalescedEvents) {
|
| + PointerEventInit coalescedEventInit = pointerEventInit;
|
| + updateMousePointerEventInit(coalescedMouseEvent, view, &coalescedEventInit);
|
| + coalescedEventInits.append(coalescedEventInit);
|
| + }
|
| + pointerEventInit.setCoalescedEventInits(coalescedEventInits);
|
| +
|
| 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());
|
|
|
| bool pointerReleasedOrCancelled =
|
| pointState == PlatformTouchPoint::TouchReleased ||
|
| @@ -216,26 +282,27 @@ 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<PointerEventInit> coalescedEventInits;
|
| + for (const auto& coalescedTouchPoint : coalescedPoints) {
|
| + PointerEventInit coalescedEventInit = pointerEventInit;
|
| + updateTouchPointPointerEventInit(coalescedTouchPoint, targetFrame,
|
| + &coalescedEventInit);
|
| + coalescedEventInits.append(coalescedEventInit);
|
| + }
|
| + pointerEventInit.setCoalescedEventInits(coalescedEventInits);
|
| +
|
| return PointerEvent::create(type, pointerEventInit);
|
| }
|
|
|
|
|