Bug 1173580 - Make synthesizeNativeWheelAnd*() functions iframe-friendly. r=kats
authorBotond Ballo <botond@mozilla.com>
Mon, 15 Jun 2015 16:43:46 -0400
changeset 249280 2fddc8dcca7823b7cb4ff1191262e7022ab71613
parent 249279 e7df200578ce326f1f53d5bdc364ce9f176c5303
child 249281 1f163b3a20a81a226c9d2fb0cd5366b28748d3d2
push id28923
push userryanvm@gmail.com
push dateWed, 17 Jun 2015 18:57:11 +0000
treeherdermozilla-central@099d6cd6725e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskats
bugs1173580
milestone41.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1173580 - Make synthesizeNativeWheelAnd*() functions iframe-friendly. r=kats
gfx/layers/apz/test/apz_test_native_event_utils.js
--- a/gfx/layers/apz/test/apz_test_native_event_utils.js
+++ b/gfx/layers/apz/test/apz_test_native_event_utils.js
@@ -29,21 +29,23 @@ function nativeHorizontalWheelEventMsg()
     case "linux": return 4; // value is unused, pass GDK_SCROLL_SMOOTH anyway
   }
   throw "Native wheel events not supported on platform " + getPlatform();
 }
 
 // Synthesizes a native mousewheel event and returns immediately. This does not
 // guarantee anything; you probably want to use one of the other functions below
 // which actually wait for results.
-// aX and aY are relative to |window|'s top-left. aDeltaX and aDeltaY
-// are pixel deltas, and aObserver can be left undefined if not needed.
+// aX and aY are relative to the top-left of |aElement|'s containing window.
+// aDeltaX and aDeltaY are pixel deltas, and aObserver can be left undefined
+// if not needed.
 function synthesizeNativeWheel(aElement, aX, aY, aDeltaX, aDeltaY, aObserver) {
-  aX += window.mozInnerScreenX;
-  aY += window.mozInnerScreenY;
+  var targetWindow = aElement.ownerDocument.defaultView;
+  aX += targetWindow.mozInnerScreenX;
+  aY += targetWindow.mozInnerScreenY;
   if (aDeltaX && aDeltaY) {
     throw "Simultaneous wheeling of horizontal and vertical is not supported on all platforms.";
   }
   var msg = aDeltaX ? nativeHorizontalWheelEventMsg() : nativeVerticalWheelEventMsg();
   _getDOMWindowUtils().sendNativeMouseScrollEvent(aX, aY, msg, aDeltaX, aDeltaY, 0, 0, 0, aElement, aObserver);
   return true;
 }
 
@@ -58,29 +60,34 @@ function synthesizeNativeWheelAndWaitFor
         setTimeout(aCallback, 0);
       }
     }
   };
   return synthesizeNativeWheel(aElement, aX, aY, aDeltaX, aDeltaY, observer);
 }
 
 // Synthesizes a native mousewheel event and invokes the callback once the
-// wheel event is dispatched to the window. See synthesizeNativeWheel for
-// details on the parameters.
+// wheel event is dispatched to |aElement|'s containing window. If the event
+// targets content in a subdocument, |aElement| should be inside the
+// subdocument. See synthesizeNativeWheel for details on the other parameters.
 function synthesizeNativeWheelAndWaitForWheelEvent(aElement, aX, aY, aDeltaX, aDeltaY, aCallback) {
-  window.addEventListener("wheel", function wheelWaiter(e) {
-    window.removeEventListener("wheel", wheelWaiter);
+  var targetWindow = aElement.ownerDocument.defaultView;
+  targetWindow.addEventListener("wheel", function wheelWaiter(e) {
+    targetWindow.removeEventListener("wheel", wheelWaiter);
     setTimeout(aCallback, 0);
   });
   return synthesizeNativeWheel(aElement, aX, aY, aDeltaX, aDeltaY);
 }
 
 // Synthesizes a native mousewheel event and invokes the callback once the
-// first resulting scroll event is dispatched to the window.
-// See synthesizeNativeWheel for details on the parameters.
+// first resulting scroll event is dispatched to |aElement|'s containing window.
+// If the event targets content in a subdocument, |aElement| should be inside
+// the subdocument.  See synthesizeNativeWheel for details on the other
+// parameters.
 function synthesizeNativeWheelAndWaitForScrollEvent(aElement, aX, aY, aDeltaX, aDeltaY, aCallback) {
+  var targetWindow = aElement.ownerDocument.defaultView;
   var useCapture = true;  // scroll events don't always bubble
-  window.addEventListener("scroll", function scrollWaiter(e) {
-    window.removeEventListener("scroll", scrollWaiter, useCapture);
+  targetWindow.addEventListener("scroll", function scrollWaiter(e) {
+    targetWindow.removeEventListener("scroll", scrollWaiter, useCapture);
     setTimeout(aCallback, 0);
   }, useCapture);
   return synthesizeNativeWheel(aElement, aX, aY, aDeltaX, aDeltaY);
 }