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

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

Issue 2624783002: Fix movementX/Y attributes for touch pointer events (Closed)
Patch Set: Rebase Created 3 years, 11 months 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
« no previous file with comments | « third_party/WebKit/Source/core/events/PointerEventFactory.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 8271c17c3c1e74b2c7c68bce0f96489f14e1e84c..e917a4f07798211e4f3dc5b9b77a36dca0ae73b0 100644
--- a/third_party/WebKit/Source/core/events/PointerEventFactory.cpp
+++ b/third_party/WebKit/Source/core/events/PointerEventFactory.cpp
@@ -102,6 +102,8 @@ float getPointerEventPressure(float force, int buttons) {
void updateTouchPointerEventInit(const PlatformTouchPoint& touchPoint,
LocalFrame* targetFrame,
+ double lastClientX,
+ double lastClientY,
PointerEventInit* pointerEventInit) {
// This function should not update attributes like pointerId, isPrimary,
// and pointerType which is the same among the coalesced events and the
@@ -118,6 +120,14 @@ void updateTouchPointerEventInit(const PlatformTouchPoint& touchPoint,
pointerEventInit->setClientX(clientPoint.x());
pointerEventInit->setClientY(clientPoint.y());
+ // We leave movementX/Y to be zero for anything except pointerdown and
+ // pointermove.
+ if (touchPoint.state() == PlatformTouchPoint::TouchMoved ||
+ touchPoint.state() == PlatformTouchPoint::TouchPressed) {
mustaq 2017/01/11 19:55:16 Did you mean TouchReleased instead?
Navid Zolghadr 2017/01/16 18:57:23 I did mean release. But after the issue that I fil
+ pointerEventInit->setMovementX(clientPoint.x() - lastClientX);
+ pointerEventInit->setMovementY(clientPoint.y() - lastClientY);
+ }
+
FloatSize pointRadius = touchPoint.radius().scaledBy(scaleFactor);
pointerEventInit->setWidth(pointRadius.width());
pointerEventInit->setHeight(pointRadius.height());
@@ -155,6 +165,9 @@ void updateMousePointerEventInit(const PlatformMouseEvent& mouseEvent,
pointerEventInit->setClientX(locationInFrameZoomed.x());
pointerEventInit->setClientY(locationInFrameZoomed.y());
+ pointerEventInit->setMovementX(mouseEvent.movementDelta().x());
+ pointerEventInit->setMovementY(mouseEvent.movementDelta().y());
+
pointerEventInit->setPressure(getPointerEventPressure(
mouseEvent.pointerProperties().force, pointerEventInit->buttons()));
pointerEventInit->setTiltX(mouseEvent.pointerProperties().tiltX);
@@ -303,7 +316,15 @@ PointerEvent* PointerEventFactory::create(
: WebPointerProperties::Button::NoButton));
pointerEventInit.setView(view);
- updateTouchPointerEventInit(touchPoint, targetFrame, &pointerEventInit);
+ PointerAttributes lastPointerAttributes =
+ m_pointerIdMapping.get(pointerEventInit.pointerId());
+ double lastClientX = lastPointerAttributes.clientX;
+ double lastClientY = lastPointerAttributes.clientY;
+ updateTouchPointerEventInit(touchPoint, targetFrame, lastClientX, lastClientY,
+ &pointerEventInit);
+ lastPointerAttributes.clientX = pointerEventInit.clientX();
+ lastPointerAttributes.clientY = pointerEventInit.clientY();
+ m_pointerIdMapping.set(pointerEventInit.pointerId(), lastPointerAttributes);
UIEventWithKeyState::setFromPlatformModifiers(pointerEventInit, modifiers);
@@ -318,8 +339,10 @@ PointerEvent* PointerEventFactory::create(
DCHECK_EQ(touchPoint.pointerProperties().pointerType,
coalescedTouchPoint.pointerProperties().pointerType);
PointerEventInit coalescedEventInit = pointerEventInit;
- updateTouchPointerEventInit(coalescedTouchPoint, targetFrame,
- &coalescedEventInit);
+ updateTouchPointerEventInit(coalescedTouchPoint, targetFrame, lastClientX,
+ lastClientY, &coalescedEventInit);
+ lastClientX = pointerEventInit.clientX();
+ lastClientY = pointerEventInit.clientY();
coalescedPointerEvents.push_back(
PointerEvent::create(type, coalescedEventInit));
}
@@ -334,8 +357,8 @@ PointerEvent* PointerEventFactory::createPointerCancelEvent(
const WebPointerProperties::PointerType pointerType) {
DCHECK(m_pointerIdMapping.contains(pointerId));
m_pointerIdMapping.set(
- pointerId,
- PointerAttributes(m_pointerIdMapping.get(pointerId).incomingId, false));
+ pointerId, PointerAttributes(m_pointerIdMapping.get(pointerId).incomingId,
+ false, 0, 0));
PointerEventInit pointerEventInit;
@@ -420,12 +443,15 @@ void PointerEventFactory::clear() {
// Always add mouse pointer in initialization and never remove it.
// No need to add it to m_pointerIncomingIdMapping as it is not going to be
- // used with the existing APIs
+ // used with the existing APIs.
+ // We don't need to set clientX/Y for the mouse as that will only be used to
+ // set movementX/Y which for mouse it comes from the browser. See Pointer Lock
+ // spec: https://www.w3.org/TR/pointerlock/.
m_primaryId[toInt(WebPointerProperties::PointerType::Mouse)] = s_mouseId;
m_pointerIdMapping.add(
s_mouseId,
PointerAttributes(IncomingId(WebPointerProperties::PointerType::Mouse, 0),
- 0));
+ 0, 0, 0));
m_currentId = PointerEventFactory::s_mouseId + 1;
}
@@ -434,13 +460,18 @@ int PointerEventFactory::addIdAndActiveButtons(const IncomingId p,
bool isActiveButtons) {
// Do not add extra mouse pointer as it was added in initialization
if (p.pointerType() == WebPointerProperties::PointerType::Mouse) {
- m_pointerIdMapping.set(s_mouseId, PointerAttributes(p, isActiveButtons));
+ m_pointerIdMapping.set(s_mouseId,
+ PointerAttributes(p, isActiveButtons, 0, 0));
return s_mouseId;
}
if (m_pointerIncomingIdMapping.contains(p)) {
int mappedId = m_pointerIncomingIdMapping.get(p);
- m_pointerIdMapping.set(mappedId, PointerAttributes(p, isActiveButtons));
+ PointerAttributes lastPointerAttributes = m_pointerIdMapping.get(mappedId);
+ m_pointerIdMapping.set(
+ mappedId,
+ PointerAttributes(p, isActiveButtons, lastPointerAttributes.clientX,
+ lastPointerAttributes.clientY));
return mappedId;
}
int typeInt = p.pointerTypeInt();
@@ -450,7 +481,10 @@ int PointerEventFactory::addIdAndActiveButtons(const IncomingId p,
m_primaryId[typeInt] = mappedId;
m_idCount[typeInt]++;
m_pointerIncomingIdMapping.add(p, mappedId);
- m_pointerIdMapping.add(mappedId, PointerAttributes(p, isActiveButtons));
+
+ // Zero initialization should be fine as we only set the movementX/Y for
+ // pointermove and pointerup.
+ m_pointerIdMapping.add(mappedId, PointerAttributes(p, isActiveButtons, 0, 0));
return mappedId;
}
« no previous file with comments | « third_party/WebKit/Source/core/events/PointerEventFactory.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698