mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-28 21:28:55 +00:00
Bug 886589 - Change - Add infrastructure for tapping center of elements rather than relying on hard-coded offsets. r=jimm
This commit is contained in:
parent
ad5df63273
commit
b18c81a34e
@ -54,7 +54,7 @@ gTests.push({
|
|||||||
|
|
||||||
// invoke selection context menu
|
// invoke selection context menu
|
||||||
let promise = waitForEvent(document, "popupshown");
|
let promise = waitForEvent(document, "popupshown");
|
||||||
sendContextMenuClickToElement(win, span, 85, 10);
|
sendContextMenuClickToElement(win, span);
|
||||||
yield promise;
|
yield promise;
|
||||||
|
|
||||||
// should be visible
|
// should be visible
|
||||||
@ -87,7 +87,7 @@ gTests.push({
|
|||||||
let link = win.document.getElementById("text2-link");
|
let link = win.document.getElementById("text2-link");
|
||||||
win.getSelection().selectAllChildren(link);
|
win.getSelection().selectAllChildren(link);
|
||||||
promise = waitForEvent(document, "popupshown");
|
promise = waitForEvent(document, "popupshown");
|
||||||
sendContextMenuClickToElement(win, link, 40, 10);
|
sendContextMenuClickToElement(win, link);
|
||||||
yield promise;
|
yield promise;
|
||||||
|
|
||||||
// should be visible
|
// should be visible
|
||||||
@ -109,7 +109,7 @@ gTests.push({
|
|||||||
|
|
||||||
link = win.document.getElementById("text2-link");
|
link = win.document.getElementById("text2-link");
|
||||||
promise = waitForEvent(document, "popupshown");
|
promise = waitForEvent(document, "popupshown");
|
||||||
sendContextMenuClickToElement(win, link, 40, 10);
|
sendContextMenuClickToElement(win, link);
|
||||||
yield promise;
|
yield promise;
|
||||||
|
|
||||||
// should be visible
|
// should be visible
|
||||||
@ -131,7 +131,7 @@ gTests.push({
|
|||||||
|
|
||||||
let input = win.document.getElementById("text3-input");
|
let input = win.document.getElementById("text3-input");
|
||||||
promise = waitForEvent(document, "popupshown");
|
promise = waitForEvent(document, "popupshown");
|
||||||
sendContextMenuClickToElement(win, input, 20, 10);
|
sendContextMenuClickToElement(win, input);
|
||||||
yield promise;
|
yield promise;
|
||||||
|
|
||||||
// should be visible
|
// should be visible
|
||||||
@ -155,7 +155,7 @@ gTests.push({
|
|||||||
input.value = "hello, I'm sorry but I must be going.";
|
input.value = "hello, I'm sorry but I must be going.";
|
||||||
input.setSelectionRange(0, 5);
|
input.setSelectionRange(0, 5);
|
||||||
promise = waitForEvent(document, "popupshown");
|
promise = waitForEvent(document, "popupshown");
|
||||||
sendContextMenuClickToElement(win, input, 20, 10);
|
sendContextMenuClickToElement(win, input, 20);
|
||||||
yield promise;
|
yield promise;
|
||||||
|
|
||||||
// should be visible
|
// should be visible
|
||||||
@ -187,7 +187,7 @@ gTests.push({
|
|||||||
input = win.document.getElementById("text3-input");
|
input = win.document.getElementById("text3-input");
|
||||||
input.select();
|
input.select();
|
||||||
promise = waitForEvent(document, "popupshown");
|
promise = waitForEvent(document, "popupshown");
|
||||||
sendContextMenuClickToElement(win, input, 20, 10);
|
sendContextMenuClickToElement(win, input, 20);
|
||||||
yield promise;
|
yield promise;
|
||||||
|
|
||||||
// should be visible
|
// should be visible
|
||||||
@ -208,7 +208,7 @@ gTests.push({
|
|||||||
input = win.document.getElementById("text3-input");
|
input = win.document.getElementById("text3-input");
|
||||||
input.select();
|
input.select();
|
||||||
promise = waitForEvent(document, "popupshown");
|
promise = waitForEvent(document, "popupshown");
|
||||||
sendContextMenuClickToElement(win, input, 20, 10);
|
sendContextMenuClickToElement(win, input, 20);
|
||||||
yield promise;
|
yield promise;
|
||||||
|
|
||||||
// should be visible
|
// should be visible
|
||||||
@ -232,7 +232,7 @@ gTests.push({
|
|||||||
input.value = "hello, I'm sorry but I must be going.";
|
input.value = "hello, I'm sorry but I must be going.";
|
||||||
input.setSelectionRange(0, 5);
|
input.setSelectionRange(0, 5);
|
||||||
promise = waitForEvent(document, "popupshown");
|
promise = waitForEvent(document, "popupshown");
|
||||||
sendContextMenuClickToElement(win, input, 20, 10);
|
sendContextMenuClickToElement(win, input, 20);
|
||||||
yield promise;
|
yield promise;
|
||||||
|
|
||||||
// should be visible
|
// should be visible
|
||||||
@ -268,7 +268,7 @@ gTests.push({
|
|||||||
input.value = "";
|
input.value = "";
|
||||||
|
|
||||||
promise = waitForEvent(document, "popupshown");
|
promise = waitForEvent(document, "popupshown");
|
||||||
sendContextMenuClickToElement(win, input, 20, 10);
|
sendContextMenuClickToElement(win, input, 20);
|
||||||
yield promise;
|
yield promise;
|
||||||
|
|
||||||
// should be visible
|
// should be visible
|
||||||
@ -291,7 +291,7 @@ gTests.push({
|
|||||||
input.value = "";
|
input.value = "";
|
||||||
|
|
||||||
promise = waitForEvent(Elements.tray, "transitionend");
|
promise = waitForEvent(Elements.tray, "transitionend");
|
||||||
sendContextMenuClickToElement(win, input, 20, 10);
|
sendContextMenuClickToElement(win, input, 20);
|
||||||
yield promise;
|
yield promise;
|
||||||
|
|
||||||
// should *not* be visible
|
// should *not* be visible
|
||||||
|
@ -533,6 +533,25 @@ function synthesizeNativeMouseMUp(aElement, aOffsetX, aOffsetY) {
|
|||||||
0x0040); // MOUSEEVENTF_MIDDLEUP
|
0x0040); // MOUSEEVENTF_MIDDLEUP
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* logicalCoordsForElement - given coordinates relative to top-left of
|
||||||
|
* given element, returns logical coordinates for window. If a non-numeric
|
||||||
|
* X or Y value is given, a value for the center of the element in that
|
||||||
|
* dimension is used.
|
||||||
|
*
|
||||||
|
* @param aElement element coordinates are relative to.
|
||||||
|
* @param aX, aY relative coordinates.
|
||||||
|
*/
|
||||||
|
function logicalCoordsForElement (aElement, aX, aY) {
|
||||||
|
let coords = { x: null, y: null };
|
||||||
|
let rect = aElement.getBoundingClientRect();
|
||||||
|
|
||||||
|
coords.x = isNaN(aX) ? rect.left + (rect.width / 2) : rect.left + aX;
|
||||||
|
coords.y = isNaN(aY) ? rect.top + (rect.height / 2) : rect.top + aY;
|
||||||
|
|
||||||
|
return coords;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* sendContextMenuClick - simulates a press-hold touch input event. Event
|
* sendContextMenuClick - simulates a press-hold touch input event. Event
|
||||||
* is delivered to the main window of the application through the top-level
|
* is delivered to the main window of the application through the top-level
|
||||||
@ -568,8 +587,8 @@ function sendContextMenuClickToWindow(aWindow, aX, aY) {
|
|||||||
function sendContextMenuClickToElement(aWindow, aElement, aX, aY) {
|
function sendContextMenuClickToElement(aWindow, aElement, aX, aY) {
|
||||||
let utils = aWindow.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
|
let utils = aWindow.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
|
||||||
.getInterface(Components.interfaces.nsIDOMWindowUtils);
|
.getInterface(Components.interfaces.nsIDOMWindowUtils);
|
||||||
let rect = aElement.getBoundingClientRect();
|
let coords = logicalCoordsForElement(aElement, aX, aY);
|
||||||
utils.sendMouseEventToWindow("contextmenu", rect.left + aX, rect.top + aY, 2, 1, 0, true,
|
utils.sendMouseEventToWindow("contextmenu", coords.x, coords.y, 2, 1, 0, true,
|
||||||
1, Ci.nsIDOMMouseEvent.MOZ_SOURCE_TOUCH);
|
1, Ci.nsIDOMMouseEvent.MOZ_SOURCE_TOUCH);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -596,8 +615,8 @@ function sendTap(aWindow, aX, aY) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function sendElementTap(aWindow, aElement, aX, aY) {
|
function sendElementTap(aWindow, aElement, aX, aY) {
|
||||||
let rect = aElement.getBoundingClientRect();
|
let coords = logicalCoordsForElement(aElement, aX, aY);
|
||||||
EventUtils.synthesizeMouseAtPoint(rect.left + aX, rect.top + aY, {
|
EventUtils.synthesizeMouseAtPoint(coords.x, coords.y, {
|
||||||
clickCount: 1,
|
clickCount: 1,
|
||||||
inputSource: Ci.nsIDOMMouseEvent.MOZ_SOURCE_TOUCH
|
inputSource: Ci.nsIDOMMouseEvent.MOZ_SOURCE_TOUCH
|
||||||
}, aWindow);
|
}, aWindow);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user