Bug 886589 - Change - Add infrastructure for tapping center of elements rather than relying on hard-coded offsets. r=jimm

This commit is contained in:
Jonathan Wilde 2013-06-25 15:35:50 -07:00
parent 4efe1b36ab
commit ada4e56eb9
2 changed files with 33 additions and 14 deletions

View File

@ -54,7 +54,7 @@ gTests.push({
// invoke selection context menu
let promise = waitForEvent(document, "popupshown");
sendContextMenuClickToElement(win, span, 85, 10);
sendContextMenuClickToElement(win, span);
yield promise;
// should be visible
@ -87,7 +87,7 @@ gTests.push({
let link = win.document.getElementById("text2-link");
win.getSelection().selectAllChildren(link);
promise = waitForEvent(document, "popupshown");
sendContextMenuClickToElement(win, link, 40, 10);
sendContextMenuClickToElement(win, link);
yield promise;
// should be visible
@ -109,7 +109,7 @@ gTests.push({
link = win.document.getElementById("text2-link");
promise = waitForEvent(document, "popupshown");
sendContextMenuClickToElement(win, link, 40, 10);
sendContextMenuClickToElement(win, link);
yield promise;
// should be visible
@ -131,7 +131,7 @@ gTests.push({
let input = win.document.getElementById("text3-input");
promise = waitForEvent(document, "popupshown");
sendContextMenuClickToElement(win, input, 20, 10);
sendContextMenuClickToElement(win, input);
yield promise;
// should be visible
@ -155,7 +155,7 @@ gTests.push({
input.value = "hello, I'm sorry but I must be going.";
input.setSelectionRange(0, 5);
promise = waitForEvent(document, "popupshown");
sendContextMenuClickToElement(win, input, 20, 10);
sendContextMenuClickToElement(win, input, 20);
yield promise;
// should be visible
@ -187,7 +187,7 @@ gTests.push({
input = win.document.getElementById("text3-input");
input.select();
promise = waitForEvent(document, "popupshown");
sendContextMenuClickToElement(win, input, 20, 10);
sendContextMenuClickToElement(win, input, 20);
yield promise;
// should be visible
@ -208,7 +208,7 @@ gTests.push({
input = win.document.getElementById("text3-input");
input.select();
promise = waitForEvent(document, "popupshown");
sendContextMenuClickToElement(win, input, 20, 10);
sendContextMenuClickToElement(win, input, 20);
yield promise;
// should be visible
@ -232,7 +232,7 @@ gTests.push({
input.value = "hello, I'm sorry but I must be going.";
input.setSelectionRange(0, 5);
promise = waitForEvent(document, "popupshown");
sendContextMenuClickToElement(win, input, 20, 10);
sendContextMenuClickToElement(win, input, 20);
yield promise;
// should be visible
@ -268,7 +268,7 @@ gTests.push({
input.value = "";
promise = waitForEvent(document, "popupshown");
sendContextMenuClickToElement(win, input, 20, 10);
sendContextMenuClickToElement(win, input, 20);
yield promise;
// should be visible
@ -291,7 +291,7 @@ gTests.push({
input.value = "";
promise = waitForEvent(Elements.tray, "transitionend");
sendContextMenuClickToElement(win, input, 20, 10);
sendContextMenuClickToElement(win, input, 20);
yield promise;
// should *not* be visible

View File

@ -533,6 +533,25 @@ function synthesizeNativeMouseMUp(aElement, aOffsetX, aOffsetY) {
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
* 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) {
let utils = aWindow.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIDOMWindowUtils);
let rect = aElement.getBoundingClientRect();
utils.sendMouseEventToWindow("contextmenu", rect.left + aX, rect.top + aY, 2, 1, 0, true,
let coords = logicalCoordsForElement(aElement, aX, aY);
utils.sendMouseEventToWindow("contextmenu", coords.x, coords.y, 2, 1, 0, true,
1, Ci.nsIDOMMouseEvent.MOZ_SOURCE_TOUCH);
}
@ -596,8 +615,8 @@ function sendTap(aWindow, aX, aY) {
}
function sendElementTap(aWindow, aElement, aX, aY) {
let rect = aElement.getBoundingClientRect();
EventUtils.synthesizeMouseAtPoint(rect.left + aX, rect.top + aY, {
let coords = logicalCoordsForElement(aElement, aX, aY);
EventUtils.synthesizeMouseAtPoint(coords.x, coords.y, {
clickCount: 1,
inputSource: Ci.nsIDOMMouseEvent.MOZ_SOURCE_TOUCH
}, aWindow);