Skip to content

Commit

Permalink
Bug 1795116 - Support specifying tiltX/tiltY/twist on synthesized tou…
Browse files Browse the repository at this point in the history
…ch event; r=webdriver-reviewers,smaug,whimboo

Differential Revision: https://phabricator.services.mozilla.com/D160970
  • Loading branch information
EdgarChen committed Nov 8, 2022
1 parent e98fad0 commit 04cf2a5
Show file tree
Hide file tree
Showing 29 changed files with 269 additions and 103 deletions.
27 changes: 17 additions & 10 deletions dom/base/nsDOMWindowUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -840,10 +840,13 @@ nsDOMWindowUtils::SendTouchEvent(
const nsTArray<int32_t>& aXs, const nsTArray<int32_t>& aYs,
const nsTArray<uint32_t>& aRxs, const nsTArray<uint32_t>& aRys,
const nsTArray<float>& aRotationAngles, const nsTArray<float>& aForces,
int32_t aModifiers, bool aIgnoreRootScrollFrame, bool* aPreventDefault) {
const nsTArray<int32_t>& aTiltXs, const nsTArray<int32_t>& aTiltYs,
const nsTArray<int32_t>& aTwists, int32_t aModifiers,
bool aIgnoreRootScrollFrame, bool* aPreventDefault) {
return SendTouchEventCommon(aType, aIdentifiers, aXs, aYs, aRxs, aRys,
aRotationAngles, aForces, aModifiers,
aIgnoreRootScrollFrame, false, aPreventDefault);
aRotationAngles, aForces, aTiltXs, aTiltYs,
aTwists, aModifiers, aIgnoreRootScrollFrame,
false, aPreventDefault);
}

NS_IMETHODIMP
Expand All @@ -852,19 +855,23 @@ nsDOMWindowUtils::SendTouchEventToWindow(
const nsTArray<int32_t>& aXs, const nsTArray<int32_t>& aYs,
const nsTArray<uint32_t>& aRxs, const nsTArray<uint32_t>& aRys,
const nsTArray<float>& aRotationAngles, const nsTArray<float>& aForces,
int32_t aModifiers, bool aIgnoreRootScrollFrame, bool* aPreventDefault) {
const nsTArray<int32_t>& aTiltXs, const nsTArray<int32_t>& aTiltYs,
const nsTArray<int32_t>& aTwists, int32_t aModifiers,
bool aIgnoreRootScrollFrame, bool* aPreventDefault) {
return SendTouchEventCommon(aType, aIdentifiers, aXs, aYs, aRxs, aRys,
aRotationAngles, aForces, aModifiers,
aIgnoreRootScrollFrame, true, aPreventDefault);
aRotationAngles, aForces, aTiltXs, aTiltYs,
aTwists, aModifiers, aIgnoreRootScrollFrame, true,
aPreventDefault);
}

nsresult nsDOMWindowUtils::SendTouchEventCommon(
const nsAString& aType, const nsTArray<uint32_t>& aIdentifiers,
const nsTArray<int32_t>& aXs, const nsTArray<int32_t>& aYs,
const nsTArray<uint32_t>& aRxs, const nsTArray<uint32_t>& aRys,
const nsTArray<float>& aRotationAngles, const nsTArray<float>& aForces,
int32_t aModifiers, bool aIgnoreRootScrollFrame, bool aToWindow,
bool* aPreventDefault) {
const nsTArray<int32_t>& aTiltXs, const nsTArray<int32_t>& aTiltYs,
const nsTArray<int32_t>& aTwists, int32_t aModifiers,
bool aIgnoreRootScrollFrame, bool aToWindow, bool* aPreventDefault) {
// get the widget to send the event to
nsPoint offset;
nsCOMPtr<nsIWidget> widget = GetWidget(&offset);
Expand Down Expand Up @@ -905,8 +912,8 @@ nsresult nsDOMWindowUtils::SendTouchEventCommon(
CSSPoint::ToAppUnits(CSSPoint(aRxs[i], aRys[i])),
presContext->AppUnitsPerDevPixel());

RefPtr<Touch> t =
new Touch(aIdentifiers[i], pt, radius, aRotationAngles[i], aForces[i]);
RefPtr<Touch> t = new Touch(aIdentifiers[i], pt, radius, aRotationAngles[i],
aForces[i], aTiltXs[i], aTiltYs[i], aTwists[i]);

event.mTouches.AppendElement(t);
}
Expand Down
5 changes: 3 additions & 2 deletions dom/base/nsDOMWindowUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,9 @@ class nsDOMWindowUtils final : public nsIDOMWindowUtils,
const nsTArray<int32_t>& aXs, const nsTArray<int32_t>& aYs,
const nsTArray<uint32_t>& aRxs, const nsTArray<uint32_t>& aRys,
const nsTArray<float>& aRotationAngles, const nsTArray<float>& aForces,
int32_t aModifiers, bool aIgnoreRootScrollFrame, bool aToWindow,
bool* aPreventDefault);
const nsTArray<int32_t>& aTiltXs, const nsTArray<int32_t>& aTiltYs,
const nsTArray<int32_t>& aTwists, int32_t aModifiers,
bool aIgnoreRootScrollFrame, bool aToWindow, bool* aPreventDefault);

void ReportErrorMessageForWindow(const nsAString& aErrorMessage,
const char* aClassification,
Expand Down
9 changes: 9 additions & 0 deletions dom/events/Touch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,15 @@ Touch::Touch(int32_t aIdentifier, LayoutDeviceIntPoint aPoint,
nsJSContext::LikelyShortLivingObjectCreated();
}

Touch::Touch(int32_t aIdentifier, LayoutDeviceIntPoint aPoint,
LayoutDeviceIntPoint aRadius, float aRotationAngle, float aForce,
int32_t aTiltX, int32_t aTiltY, int32_t aTwist)
: Touch(aIdentifier, aPoint, aRadius, aRotationAngle, aForce) {
tiltX = aTiltX;
tiltY = aTiltY;
twist = aTwist;
}

Touch::Touch(const Touch& aOther)
: mOriginalTarget(aOther.mOriginalTarget),
mTarget(aOther.mTarget),
Expand Down
3 changes: 3 additions & 0 deletions dom/events/Touch.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ class Touch final : public nsISupports,
float aRotationAngle, float aForce);
Touch(int32_t aIdentifier, LayoutDeviceIntPoint aPoint,
LayoutDeviceIntPoint aRadius, float aRotationAngle, float aForce);
Touch(int32_t aIdentifier, LayoutDeviceIntPoint aPoint,
LayoutDeviceIntPoint aRadius, float aRotationAngle, float aForce,
int32_t aTiltX, int32_t aTiltY, int32_t aTwist);
Touch(const Touch& aOther);

NS_DECL_CYCLE_COLLECTING_ISUPPORTS
Expand Down
10 changes: 5 additions & 5 deletions dom/events/test/file_coalesce_touchmove_browserchild.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,24 @@
var endYForFirstTouch = Math.floor(rect.y + ((rect.height / 4) * 2));
var endYForSecondTouch = Math.floor(rect.y + ((rect.height / 4) * 4));
utils.sendTouchEvent("touchstart", [0], [x], [y], [1], [1], [0], [1],
0, false);
[0], [0], [0], 0, false);
while (y != endYForFirstTouch) {
utils.sendTouchEvent("touchmove", [0], [x], [y], [1], [1], [0], [1],
0, false);
[0], [0], [0], 0, false);
++y;
}

// Add a new touch and move this touch
utils.sendTouchEvent("touchstart", [0, 1], [x, x], [endYForFirstTouch, endYForFirstTouch], [1, 1], [1, 1], [0, 0], [1, 1],
0, false);
[0, 0], [0, 0], [0, 0], 0, false);
while (y != endYForSecondTouch) {
utils.sendTouchEvent("touchmove", [0, 1], [x, x], [endYForFirstTouch, y], [1, 1], [1, 1], [0, 0], [1, 1],
0, false);
[0, 0], [0, 0], [0, 0], 0, false);
++y;
}

utils.sendTouchEvent("touchend", [0, 1], [x, x], [endYForFirstTouch, endYForSecondTouch], [1, 1], [1, 1], [0, 0], [1, 1],
0, false);
[0, 0], [0, 0], [0, 0], 0, false);
});

let touchStartCount = 0;
Expand Down
21 changes: 11 additions & 10 deletions dom/events/test/file_coalesce_touchmove_browserchild2.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@
var y = Math.floor(rect.y + (rect.height / 4));
var endY = Math.floor(rect.y + ((rect.height / 4) * 2));
utils.sendTouchEvent("touchstart", [0], [x], [y], [1], [1], [0], [1],
0, false);
[0], [0], [0], 0, false);
while (y != endY) {
utils.sendTouchEvent("touchmove", [0], [x], [y], [1], [1], [0], [1],
0, false);
[0], [0], [0], 0, false);
++y;
}
utils.sendTouchEvent("touchend", [0], [x], [y], [1], [1], [0], [1],
0, false);
[0], [0], [0], 0, false);

});

Expand All @@ -68,13 +68,13 @@
var startY = Math.floor(rect.y + (rect.height / 4));
var endY = Math.floor(rect.y + ((rect.height / 4) * 2));
utils.sendTouchEvent("touchstart", [0], [x], [startY], [1], [1], [0],
[1], 0, false);
[1], [0], [0], [0], 0, false);
utils.sendTouchEvent("touchmove", [0], [x], [startY], [1], [1], [0],
[1], 0, false);
[1], [0], [0], [0], 0, false);
utils.sendTouchEvent("touchmove", [0], [x], [startY + 1], [1], [1], [0],
[1], 0, false);
[1], [0], [0], [0], 0, false);
utils.sendTouchEvent("touchend", [0], [x], [endY], [1], [1], [0],
[1], 0, false);
[1], [0], [0], [0], 0, false);
});

touchmoveEvents = [];
Expand All @@ -101,15 +101,16 @@
var endY = Math.floor(rect.y + ((rect.height / 4) * 2));
utils.sendTouchEvent("touchstart", [0, 1], [x, x + 1],
[startY, startY + 1], [1, 1], [1, 1], [0, 0],
[1, 1], 0, false);
[1, 1], [0, 0], [0, 0], [0, 0], 0, false);
while (startY != endY) {
utils.sendTouchEvent("touchmove", [0, 1], [x, x + 1],
[startY, startY + 1], [1, 1], [1, 1], [0, 0],
[1, 1], 0, false);
[1, 1], [0, 0], [0, 0], [0, 0], 0, false);
++startY;
}
utils.sendTouchEvent("touchend", [0, 1], [x, x + 1], [endY, endY + 1],
[1, 1], [1, 1], [0, 0], [1, 1], 0, false);
[1, 1], [1, 1], [0, 0], [1, 1], [0, 0], [0, 0],
[0, 0], 0, false);

});

Expand Down
21 changes: 11 additions & 10 deletions dom/events/test/file_coalesce_touchmove_ipc.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@
var y = Math.floor(rect.y + (rect.height / 4));
var endY = Math.floor(rect.y + ((rect.height / 4) * 2));
utils.sendTouchEvent("touchstart", [0], [x], [y], [1], [1], [0], [1],
0, false);
[0], [0], [0], 0, false);
while (y != endY) {
utils.sendTouchEvent("touchmove", [0], [x], [y], [1], [1], [0], [1],
0, false);
[0], [0], [0], 0, false);
++y;
}
utils.sendTouchEvent("touchend", [0], [x], [y], [1], [1], [0], [1],
0, false);
[0], [0], [0], 0, false);

});

Expand All @@ -68,13 +68,13 @@
var startY = Math.floor(rect.y + (rect.height / 4));
var endY = Math.floor(rect.y + ((rect.height / 4) * 2));
utils.sendTouchEvent("touchstart", [0], [x], [startY], [1], [1], [0],
[1], 0, false);
[1], [0], [0], [0], 0, false);
utils.sendTouchEvent("touchmove", [0], [x], [startY], [1], [1], [0],
[1], 0, false);
[1], [0], [0], [0], 0, false);
utils.sendTouchEvent("touchmove", [0], [x], [startY + 1], [1], [1], [0],
[1], 0, false);
[1], [0], [0], [0], 0, false);
utils.sendTouchEvent("touchend", [0], [x], [endY], [1], [1], [0],
[1], 0, false);
[1], [0], [0], [0], 0, false);
});

touchmoveEvents = [];
Expand All @@ -101,15 +101,16 @@
var endY = Math.floor(rect.y + ((rect.height / 4) * 2));
utils.sendTouchEvent("touchstart", [0, 1], [x, x + 1],
[startY, startY + 1], [1, 1], [1, 1], [0, 0],
[1, 1], 0, false);
[1, 1], [0, 0], [0, 0], [0, 0], 0, false);
while (startY != endY) {
utils.sendTouchEvent("touchmove", [0, 1], [x, x + 1],
[startY, startY + 1], [1, 1], [1, 1], [0, 0],
[1, 1], 0, false);
[1, 1], [0, 0], [0, 0], [0, 0], 0, false);
++startY;
}
utils.sendTouchEvent("touchend", [0, 1], [x, x + 1], [endY, endY + 1],
[1, 1], [1, 1], [0, 0], [1, 1], 0, false);
[1, 1], [1, 1], [0, 0], [1, 1], [0, 0], [0, 0],
[0, 0], 0, false);

});

Expand Down
30 changes: 20 additions & 10 deletions dom/events/test/pointerevents/bug968148_inner.html
Original file line number Diff line number Diff line change
Expand Up @@ -194,15 +194,18 @@
// event listener.
utils.sendTouchEvent('touchstart', [test1PointerId, test2PointerId],
[left1d1, left2d1], [top1d1, top2d1], [rx, rx], [ry, ry],
[angle, angle], [force, force], modifiers);
[angle, angle], [force, force], [0, 0], [0, 0],
[0, 0], modifiers);

utils.sendTouchEvent('touchmove', [test1PointerId, test2PointerId],
[left1d2, left2d2], [top1d2, top2d2], [rx, rx], [ry, ry],
[angle, angle], [force, force], modifiers);
[angle, angle], [force, force], [0, 0], [0, 0],
[0, 0], modifiers);

utils.sendTouchEvent('touchend', [test1PointerId, test2PointerId],
[left1d1, left2d1], [top1d1, top2d1], [rx, rx], [ry, ry],
[angle, angle], [force, force], modifiers);
[angle, angle], [force, force], [0, 0], [0, 0],
[0, 0], modifiers);

// No implicitly / explicitly pointer capture. pointermove should be
// dispatched to 1d2, 2d2
Expand All @@ -217,11 +220,13 @@

utils.sendTouchEvent('touchstart', [test1PointerId, test2PointerId],
[left1d1, left2d1], [top1d1, top2d1], [rx, rx], [ry, ry],
[angle, angle], [force, force], modifiers);
[angle, angle], [force, force], [0, 0], [0, 0],
[0, 0], modifiers);

utils.sendTouchEvent('touchmove', [test1PointerId, test2PointerId],
[left1d2, left2d2], [top1d2, top2d2], [rx, rx], [ry, ry],
[angle, angle], [force, force], modifiers);
[angle, angle], [force, force], [0, 0], [0, 0],
[0, 0], modifiers);

// Explicitly capture pointer to 1d1, 2d1. pointermove, gotpointercapture
// should be dispatched to 1d1, 2d1
Expand All @@ -237,7 +242,8 @@

utils.sendTouchEvent('touchend', [test1PointerId, test2PointerId],
[left1d1, left2d1], [top1d1, top2d1], [rx, rx], [ry, ry],
[angle, angle], [force, force], modifiers);
[angle, angle], [force, force], [0, 0], [0, 0],
[0, 0], modifiers);

// Explicitly capture pointer to 1d1, 2d1 when pointerdown
test1d1.addEventListener("pointerdown", test1d1CapturePointer, {capture: true, once: true});
Expand All @@ -249,17 +255,20 @@

utils.sendTouchEvent('touchstart', [test1PointerId, test2PointerId],
[left1d1, left2d1], [top1d1, top2d1], [rx, rx], [ry, ry],
[angle, angle], [force, force], modifiers);
[angle, angle], [force, force], [0, 0], [0, 0],
[0, 0], modifiers);

// This should send pointer event to test1d1, test2d1.
utils.sendTouchEvent('touchmove', [test1PointerId, test2PointerId],
[left1d1 + 5, left2d1 + 5], [top1d1, top2d1], [rx, rx], [ry, ry],
[angle, angle], [force, force], modifiers);
[angle, angle], [force, force], [0, 0], [0, 0],
[0, 0], modifiers);

// This should send pointer event to test1d2, test2d2.
utils.sendTouchEvent('touchmove', [test1PointerId, test2PointerId],
[left1d1 + 5, left2d1 + 5], [top1d1 + 5, top2d1 + 5], [rx, rx], [ry, ry],
[angle, angle], [force, force], modifiers);
[angle, angle], [force, force], [0, 0], [0, 0],
[0, 0], modifiers);

is(test1d1pointermovecount, 2, "1d1 should have got pointermove");
is(test1d1pointergotcapture, 2, "1d1 should have got pointergotcapture");
Expand All @@ -273,7 +282,8 @@

utils.sendTouchEvent('touchend', [test1PointerId, test2PointerId],
[left1d1, left2d1], [top1d1, top2d1], [rx, rx], [ry, ry],
[angle, angle], [force, force], modifiers);
[angle, angle], [force, force], [0, 0], [0, 0],
[0, 0], modifiers);

finishTest();
}
Expand Down
Loading

0 comments on commit 04cf2a5

Please sign in to comment.