This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 16673 - Specify how MouseEventExtension coordinates are set using initMouseEvent()
Summary: Specify how MouseEventExtension coordinates are set using initMouseEvent()
Status: NEW
Alias: None
Product: CSS
Classification: Unclassified
Component: CSSOM View (show other bugs)
Version: unspecified
Hardware: PC Windows NT
: P2 normal
Target Milestone: ---
Assignee: Simon Pieters
QA Contact: public-css-bugzilla
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-04-09 21:18 UTC by Jacob Rossi [MSFT]
Modified: 2015-10-05 00:56 UTC (History)
3 users (show)

See Also:


Attachments
Test case for synthetic event pageX/pageY calculation... (1.62 KB, text/html)
2013-06-17 19:15 UTC, Travis Leithead [MSFT]
Details

Description Jacob Rossi [MSFT] 2012-04-09 21:18:39 UTC
The initMouseEvent() method from DOM L3 Events allows for the creation of synthetic mouse events [1]. However, it seems it was defined prior to the existence/standardization of the extensions to MouseEvent [2]. For compatibility reasons, we don't believe we can change the signature of initMouseEvent() to include properties like pageX/pageY.  Instead, we suggest calculating these values based on the inputs provided for clientX/clientY. This seems to be what Webkit (and to some extent, Firefox) do.

pageX =  clientX + scrollLeft  (using the values at the time of calling initMouseEvent)
pageY = clientY + scrollTop
x = clientX
y = clientY

Prior to calling dispatchEvent() (which indicates a target element for the event)"
offsetX = pageX
offsetY = pageY

After calling dispatchEvent()  (e.g. during and after the dispatch of the event):
offsetX = the x offset relative to the padding edge of the target element (as reported in the element's coordinate space)
offsetY = the y offset relative to the padding edge of the target element (as reported in the element's coordinate space)

[1]http://dev.w3.org/2006/webapi/DOM-Level-3-Events/html/DOM3-Events.html#events-event-type-initMouseEvent
[2]http://dev.w3.org/csswg/cssom-view/#extensions-to-the-mouseevent-interface
Comment 1 Glenn Adams 2012-08-03 05:55:15 UTC
reassign to myself; apparently i am not the default assignee for this component
Comment 2 Simon Pieters 2013-05-15 09:57:26 UTC
(In reply to comment #0)
> pageX =  clientX + scrollLeft  (using the values at the time of calling
> initMouseEvent)
> pageY = clientY + scrollTop

scrollLeft and scrollTop of what?

Do you have test cases in this area I can look at?
Comment 3 Travis Leithead [MSFT] 2013-06-17 19:15:15 UTC
Created attachment 1373 [details]
Test case for synthetic event pageX/pageY calculation...
Comment 4 Travis Leithead [MSFT] 2013-06-17 19:17:07 UTC
In IE/Firefox, this appears to be the scrollLeft/Top of the documentElement (HTML).

Chrome's scrollLeft/top for the viewport are on body, but regardless, Chrome does not seem to do this pageX/pageY calculation on dispatch.

Attachment included.
Comment 5 Simon Pieters 2013-06-18 08:42:35 UTC
Thanks!

https://dvcs.w3.org/hg/csswg/rev/39af9667776a
Comment 6 Simon Pieters 2015-09-16 07:17:41 UTC
The fix here seems to have caused some other problems, see
https://bugzilla.mozilla.org/show_bug.cgi?id=1203404
Comment 7 Boris Zbarsky 2015-09-16 14:58:59 UTC
That's because the fix here didn't match the behavior description in comment 0.  From comment 0 again:

  Prior to calling dispatchEvent() (which indicates a target element for the
  event)"
    offsetX = pageX

  After calling dispatchEvent()  (e.g. during and after the dispatch of the
  event):
    offsetX = the x offset relative to the padding edge of the target element (as
    reported in the element's coordinate space)

The behavior in the spec doesn't do "during and after the dispatch".  It just does "during the dispatch", and goes back to "pageX" after the dispatch.