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

Unified Diff: third_party/WebKit/Source/core/events/PointerEventFactory.cpp

Issue 2479123003: WIP Add getCoalescedEvents API using vector of WebInputEvents (Closed)
Patch Set: Created 4 years, 1 month 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 side-by-side diff with in-line comments
Download patch
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 d13b63c28786cd1366bbfafd7d85402c3fef0469..88a01134e4c6d2bc087efa267d600694703e2f21 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,
@@ -125,9 +198,11 @@ void PointerEventFactory::setBubblesAndCancelable(
type != EventTypeNames::lostpointercapture);
}
-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);
@@ -141,24 +216,6 @@ PointerEvent* PointerEventFactory::create(const AtomicString& mouseEventName,
setIdTypeButtons(pointerEventInit, mouseEvent.pointerProperties(), buttons);
setBubblesAndCancelable(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;
@@ -173,10 +230,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());
@@ -191,15 +244,28 @@ 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,
+ // const float scaleFactor,
+ // const FloatPoint& clientPoint,
+ DOMWindow* view) {
const PlatformTouchPoint::TouchState pointState = touchPoint.state();
bool pointerReleasedOrCancelled =
@@ -215,21 +281,12 @@ 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);
@@ -237,7 +294,18 @@ PointerEvent* PointerEventFactory::create(const AtomicString& type,
pointerEventInit.setCancelable(
!isEnterOrLeave && pointState != PlatformTouchPoint::TouchCancelled);
- return PointerEvent::create(type, pointerEventInit);
+ // 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(
+ pointerEventNameForTouchPointState(touchPoint.state()), pointerEventInit);
}
PointerEvent* PointerEventFactory::createPointerCancelEvent(

Powered by Google App Engine
This is Rietveld 408576698