Bug 1253244 - Use element.coordinates in listener; r=automatedtester a=test-only
authorAndreas Tolfsen <ato@mozilla.com>
Thu, 03 Mar 2016 14:28:40 +0000
changeset 325281 32d5e78157293e5709a6324121e09988bcf94a44
parent 325280 92b98e56360e81c833442b1927d7fdcbff18d6b1
child 325282 f565c27537b56e155d373bfa3eeb7b99e3967770
push id1128
push userjlund@mozilla.com
push dateWed, 01 Jun 2016 01:31:59 +0000
treeherdermozilla-release@fe0d30de989d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersautomatedtester, test-only
bugs1253244
milestone47.0a2
Bug 1253244 - Use element.coordinates in listener; r=automatedtester a=test-only MozReview-Commit-ID: 4sWZNXrenqZ
testing/marionette/element.js
testing/marionette/listener.js
--- a/testing/marionette/element.js
+++ b/testing/marionette/element.js
@@ -737,17 +737,16 @@ element.generateUUID = function() {
  *     Target node.
  * @param {number=} x
  *     Horizontal offset relative to target.  Defaults to the centre of
  *     the target's bounding box.
  * @param {number=} y
  *     Vertical offset relative to target.  Defaults to the centre of
  *     the target's bounding box.
  */
-// TODO(ato): Replicated from listener.js for the time being
 element.coordinates = function(node, x = undefined, y = undefined) {
   let box = node.getBoundingClientRect();
   if (!x) {
     x = box.width / 2.0;
   }
   if (!y) {
     y = box.height / 2.0;
   }
--- a/testing/marionette/listener.js
+++ b/testing/marionette/listener.js
@@ -844,52 +844,32 @@ function emitTouchEvent(type, touch) {
     marionetteLogObj.clearLogs();
     */
     let domWindowUtils = curContainer.frame.QueryInterface(Components.interfaces.nsIInterfaceRequestor).getInterface(Components.interfaces.nsIDOMWindowUtils);
     domWindowUtils.sendTouchEvent(type, [touch.identifier], [touch.clientX], [touch.clientY], [touch.radiusX], [touch.radiusY], [touch.rotationAngle], [touch.force], 1, 0);
   }
 }
 
 /**
- * This function generates a pair of coordinates relative to the viewport given a
- * target element and coordinates relative to that element's top-left corner.
- * @param 'x', and 'y' are the relative to the target.
- *        If they are not specified, then the center of the target is used.
- */
-function coordinates(target, x, y) {
-  let box = target.getBoundingClientRect();
-  if (x == null) {
-    x = box.width / 2;
-  }
-  if (y == null) {
-    y = box.height / 2;
-  }
-  let coords = {};
-  coords.x = box.left + x;
-  coords.y = box.top + y;
-  return coords;
-}
-
-/**
  * Function that perform a single tap
  */
 function singleTap(id, corx, cory) {
   let el = elementManager.getKnownElement(id, curContainer);
   // after this block, the element will be scrolled into view
   let visible = element.isVisible(el, corx, cory);
   if (!visible) {
     throw new ElementNotVisibleError("Element is not currently visible and may not be manipulated");
   }
   return interactions.accessibility.getAccessibleObject(el, true).then(acc => {
     interactions.accessibility.checkVisible(acc, el, visible);
     interactions.accessibility.checkActionable(acc, el);
     if (!curContainer.frame.document.createTouch) {
       actions.mouseEventsOnly = true;
     }
-    let c = coordinates(el, corx, cory);
+    let c = element.coordinates(el, corx, cory);
     if (!actions.mouseEventsOnly) {
       let touchId = actions.nextTouchId++;
       let touch = createATouch(el, c.x, c.y, touchId);
       emitTouchEvent('touchstart', touch);
       emitTouchEvent('touchend', touch);
     }
     actions.mouseTap(el.ownerDocument, c.x, c.y);
   });
@@ -991,34 +971,34 @@ function setDispatch(batches, touches, b
   for (let i = 0; i < batch.length; i++) {
     pack = batch[i];
     touchId = pack[0];
     command = pack[1];
 
     switch (command) {
       case "press":
         el = elementManager.getKnownElement(pack[2], curContainer);
-        c = coordinates(el, pack[3], pack[4]);
+        c = element.coordinates(el, pack[3], pack[4]);
         touch = createATouch(el, c.x, c.y, touchId);
         multiLast[touchId] = touch;
         touches.push(touch);
         emitMultiEvents("touchstart", touch, touches);
         break;
 
       case "release":
         touch = multiLast[touchId];
         // the index of the previous touch for the finger may change in the touches array
         touchIndex = touches.indexOf(touch);
         touches.splice(touchIndex, 1);
         emitMultiEvents("touchend", touch, touches);
         break;
 
       case "move":
         el = elementManager.getKnownElement(pack[2], curContainer);
-        c = coordinates(el);
+        c = element.coordinates(el);
         touch = createATouch(multiLast[touchId].target, c.x, c.y, touchId);
         touchIndex = touches.indexOf(lastTouch);
         touches[touchIndex] = touch;
         multiLast[touchId] = touch;
         emitMultiEvents("touchmove", touch, touches);
         break;
 
       case "moveByOffset":