зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1625925 Part 1: Change touch-simulator.js synthesizeNative methods to use screen coordinates directly. r=botond
This removes the calculation method coordinatesRelativeToScreen in favor of using the event-supplied screen coordinates. Those coordinates are scaled to device coordinates to meet expectations of the sendNative methods. Differential Revision: https://phabricator.services.mozilla.com/D74161
This commit is contained in:
Родитель
e2a46cc211
Коммит
9d266c9a3f
|
@ -276,6 +276,8 @@ TouchSimulator.prototype = {
|
||||||
this.getContent(evt.target),
|
this.getContent(evt.target),
|
||||||
evt.clientX,
|
evt.clientX,
|
||||||
evt.clientY,
|
evt.clientY,
|
||||||
|
evt.screenX,
|
||||||
|
evt.screenY,
|
||||||
type
|
type
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -307,7 +309,7 @@ TouchSimulator.prototype = {
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Synthesizes a native tap gesture on a given target element. The `x` and `y` values
|
* Synthesizes a native touch action on a given target element. The `x` and `y` values
|
||||||
* passed to this function should be relative to the layout viewport (what is returned
|
* passed to this function should be relative to the layout viewport (what is returned
|
||||||
* by `MouseEvent.clientX/clientY`) and are reported in CSS pixels.
|
* by `MouseEvent.clientX/clientY`) and are reported in CSS pixels.
|
||||||
*
|
*
|
||||||
|
@ -317,59 +319,24 @@ TouchSimulator.prototype = {
|
||||||
* The `x` CSS coordinate relative to the layout viewport.
|
* The `x` CSS coordinate relative to the layout viewport.
|
||||||
* @param {Number} y
|
* @param {Number} y
|
||||||
* The `y` CSS coordinate relative to the layout viewport.
|
* The `y` CSS coordinate relative to the layout viewport.
|
||||||
|
* @param {Number} screenX
|
||||||
|
* The `x` screen coordinate relative to the screen origin.
|
||||||
|
* @param {Number} screenY
|
||||||
|
* The `y` screen coordinate relative to the screen origin.
|
||||||
|
* @param {String} type
|
||||||
|
* A key appearing in the TOUCH_STATES associative array.
|
||||||
*/
|
*/
|
||||||
synthesizeNativeTap(win, x, y) {
|
synthesizeNativeTouch(win, x, y, screenX, screenY, type) {
|
||||||
const pt = this.coordinatesRelativeToScreen(win, x, y);
|
// Native events work in device pixels, so calculate device coordinates from
|
||||||
|
// the screen coordinates.
|
||||||
const utils = win.windowUtils;
|
const utils = win.windowUtils;
|
||||||
|
const deviceScale = utils.screenPixelsPerCSSPixelNoOverride;
|
||||||
|
const pt = { x: screenX * deviceScale, y: screenY * deviceScale };
|
||||||
|
|
||||||
// Bug 1619402: RDM has issues with full-zoom + resolution handling. Knowing this,
|
|
||||||
// it's possible the pt.x and pt.y values passed here will result in incorrect
|
|
||||||
// behavior when attempting to perform a native touch gesture. However, we know
|
|
||||||
// that setting the full-zoom to 100% will produce expected behavior. So let's
|
|
||||||
// leave this note here and revisit when this issue gets resolved.
|
|
||||||
utils.sendNativeTouchTap(pt.x, pt.y, false, null);
|
|
||||||
return true;
|
|
||||||
},
|
|
||||||
|
|
||||||
synthesizeNativeTouch(win, x, y, type) {
|
|
||||||
const pt = this.coordinatesRelativeToScreen(win, x, y);
|
|
||||||
const utils = win.windowUtils;
|
|
||||||
utils.sendNativeTouchPoint(0, TOUCH_STATES[type], pt.x, pt.y, 1, 90, null);
|
utils.sendNativeTouchPoint(0, TOUCH_STATES[type], pt.x, pt.y, 1, 90, null);
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
|
||||||
* Calculates the given CSS coordinates into global screen coordinates, which are
|
|
||||||
* reported in device pixels.
|
|
||||||
*
|
|
||||||
* @param {Window} win
|
|
||||||
* The target window.
|
|
||||||
* @param {Number} x
|
|
||||||
* The `x` CSS coordinate relative to the layout viewport.
|
|
||||||
* @param {Number} y
|
|
||||||
* The `y` CSS coordinate relative to the layout viewport.
|
|
||||||
*
|
|
||||||
* @returns {Object} the `x` and `y` global screen coordinattes.
|
|
||||||
*/
|
|
||||||
coordinatesRelativeToScreen(win, x, y) {
|
|
||||||
const utils = win.windowUtils;
|
|
||||||
// Bug 1617741: Ignore RDM's override DPR. The physical size of content displayed
|
|
||||||
// in RDM is not scaled to the override DPR, so a workaround is to use the device
|
|
||||||
// scale of the physical device when calculating the cordinates.
|
|
||||||
const deviceScale = utils.screenPixelsPerCSSPixelNoOverride;
|
|
||||||
|
|
||||||
const resolution = utils.getResolution();
|
|
||||||
const offsetX = {};
|
|
||||||
const offsetY = {};
|
|
||||||
|
|
||||||
utils.getVisualViewportOffsetRelativeToLayoutViewport(offsetX, offsetY);
|
|
||||||
|
|
||||||
return {
|
|
||||||
x: (win.mozInnerScreenX + (x - offsetX.value) * resolution) * deviceScale,
|
|
||||||
y: (win.mozInnerScreenY + (y - offsetY.value) * resolution) * deviceScale,
|
|
||||||
};
|
|
||||||
},
|
|
||||||
|
|
||||||
sendTouchEvent(evt, target, name) {
|
sendTouchEvent(evt, target, name) {
|
||||||
const win = target.ownerGlobal;
|
const win = target.ownerGlobal;
|
||||||
const content = this.getContent(target);
|
const content = this.getContent(target);
|
||||||
|
|
Загрузка…
Ссылка в новой задаче