Bug 1203404. offsetX/Y on mouse events should remain target-relative, instead of becoming page-relative, after event dispatch is done. r=roc
authorBoris Zbarsky <bzbarsky@mit.edu>
Fri, 18 Sep 2015 13:36:13 -0400
changeset 295905 82767b12c2334eff297653cf9eb6c7241541cc7f
parent 295904 03233057f1e699551915436d9fa98818b28f9b4d
child 295906 12981e43cd80998c97c72ac18abc8558ed7c0bd0
push id5245
push userraliiev@mozilla.com
push dateThu, 29 Oct 2015 11:30:51 +0000
treeherdermozilla-beta@dac831dc1bd0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc
bugs1203404
milestone43.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 1203404. offsetX/Y on mouse events should remain target-relative, instead of becoming page-relative, after event dispatch is done. r=roc
dom/events/Event.cpp
dom/events/test/test_offsetxy.html
--- a/dom/events/Event.cpp
+++ b/dom/events/Event.cpp
@@ -1000,17 +1000,17 @@ Event::GetClientCoords(nsPresContext* aP
 
 // static
 CSSIntPoint
 Event::GetOffsetCoords(nsPresContext* aPresContext,
                        WidgetEvent* aEvent,
                        LayoutDeviceIntPoint aPoint,
                        CSSIntPoint aDefaultPoint)
 {
-  if (!aEvent->mFlags.mIsBeingDispatched) {
+  if (!aEvent->target) {
     return GetPageCoords(aPresContext, aEvent, aPoint, aDefaultPoint);
   }
   nsCOMPtr<nsIContent> content = do_QueryInterface(aEvent->target);
   if (!content || !aPresContext) {
     return CSSIntPoint(0, 0);
   }
   nsCOMPtr<nsIPresShell> shell = aPresContext->GetPresShell();
   if (!shell) {
--- a/dom/events/test/test_offsetxy.html
+++ b/dom/events/test/test_offsetxy.html
@@ -15,59 +15,84 @@
 <div id="d3" style="display:none; position:absolute; top:100px; left:100px; width:100px; border:5px dotted black; height:100px"></div>
 <div id="d4" style="transform:scale(0); position:absolute; top:100px; left:100px; width:100px; border:5px dotted black; height:100px"></div>
 
 <pre id="test">
 <script type="application/javascript">
 
 var offsetX = -1, offsetY = -1;
 var ev = new MouseEvent("click", {clientX:110, clientY:110});
+is(ev.offsetX, 110);
+is(ev.offsetY, 110);
+is(ev.offsetX, ev.pageX);
+is(ev.offsetY, ev.pageY);
 d.addEventListener("click", function (event) {
   is(ev, event, "Event objects must match");
   offsetX = event.offsetX;
   offsetY = event.offsetY;
 });
 d.dispatchEvent(ev);
 is(offsetX, 5);
 is(offsetY, 5);
-is(ev.offsetX, ev.pageX);
-is(ev.offsetY, ev.pageY);
+is(ev.offsetX, 5);
+is(ev.offsetY, 5);
 
 var ev2 = new MouseEvent("click", {clientX:220, clientY:130});
+is(ev2.offsetX, 220);
+is(ev2.offsetY, 130);
+is(ev2.offsetX, ev2.pageX);
+is(ev2.offsetY, ev2.pageY);
 d2.addEventListener("click", function (event) {
   is(ev2, event, "Event objects must match");
   offsetX = event.offsetX;
   offsetY = event.offsetY;
 });
 d2.dispatchEvent(ev2);
 is(offsetX, 15);
 is(offsetY, 25);
-is(ev2.offsetX, ev2.pageX);
-is(ev2.offsetY, ev2.pageY);
+is(ev2.offsetX, 15);
+is(ev2.offsetY, 25);
 
 var ev3 = new MouseEvent("click", {clientX:110, clientY:110});
+is(ev3.offsetX, 110);
+is(ev3.offsetY, 110);
+is(ev3.offsetX, ev3.pageX);
+is(ev3.offsetY, ev3.pageY);
 d3.addEventListener("click", function (event) {
   is(ev3, event, "Event objects must match");
   offsetX = event.offsetX;
   offsetY = event.offsetY;
 });
 d3.dispatchEvent(ev3);
 is(offsetX, 0);
 is(offsetY, 0);
-is(ev3.offsetX, ev3.pageX);
-is(ev3.offsetY, ev3.pageY);
+is(ev3.offsetX, 0);
+is(ev3.offsetY, 0);
 
 var ev4 = new MouseEvent("click", {clientX:110, clientY:110});
+is(ev4.offsetX, 110);
+is(ev4.offsetY, 110);
+is(ev4.offsetX, ev4.pageX);
+is(ev4.offsetY, ev4.pageY);
 d4.addEventListener("click", function (event) {
   is(ev4, event, "Event objects must match");
   offsetX = event.offsetX;
   offsetY = event.offsetY;
 });
 d4.dispatchEvent(ev4);
 is(offsetX, 0);
 is(offsetY, 0);
-is(ev4.offsetX, ev4.pageX);
-is(ev4.offsetY, ev4.pageY);
+is(ev4.offsetX, 0);
+is(ev4.offsetY, 0);
 
+// Now redispatch ev4 to "d" to make sure that its offsetX gets updated
+// relative to the new target.  Have to set "ev" to "ev4", because the listener
+// on "d" expects to see "ev" as the event.
+ev = ev4;
+d.dispatchEvent(ev4);
+is(offsetX, 5);
+is(offsetY, 5);
+is(ev.offsetX, 5);
+is(ev.offsetY, 5);
 </script>
 </pre>
 </body>
 </html>