Issue metadata
Sign in to add a comment
|
offsetX and offsetY in MouseEvent are not correct on SVG element with viewBox attribute
Reported by
zhengjia...@gmail.com,
Mar 7 2016
|
||||||||||||||||||||
Issue description
UserAgent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2667.0 Safari/537.36
Steps to reproduce the problem:
1. Prepare an svg element and a path inside it.
<svg version="1.1" type="system" x="800px" y="600px" viewBox="0 0 800 600" style="position: absolute; top: 0px; left: 0px; width: 800px; height: 600px;">
<path fill-rule="evenodd" stroke="#3a6bdb" stroke-width="5" stroke-dasharray="0" fill="#fff" stroke-opacity="0.65" fill-opacity="0.65" d="M 177 270 L 553 254 310 393 407 115 497 391 177 270" style="-webkit-user-select: none;"></path>
</svg>
2. Add mouse click event listener on document like this and print the offsetX and offsetY in the console.
document.addEventListener('click', function (e) {
console.log('offset', e.offsetX, e.offsetY);
console.log('layer', e.layerX, e.layerY);
}, false);
3. click somewhere on the path and you get the arguments printed in console:
offset 402 207
layer 402 207
The offset and layer value are the same. Both of them are the value relative to the top left corner of the svg element.
4. Now change the viewBox attribute in svg element to this: 100 100 800 600 and then click somewhere on the path. You get the following values:
offset 302 274
layer 202 174
You will find that layerX/layerY is still relative to the upper left of the svg element. But the offsetX/offsetY are added the viewBox's minX and minY value which i think is not correct.
What is the expected behavior?
OffsetX/OffsetY are always relative to the upper left corner of the svg element no matter what value of the viewBox attribute is.
What went wrong?
OffsetX/OffsetY in mouse event is not correct.
Did this work before? Yes on 49.0.2623.75 (Official Build) beta (64-bit) the values are correct.
Chrome version: 51.0.2667.0 Channel: canary
OS Version: OS X 10.11.3
Flash Version: Shockwave Flash 21.0 r0
Here is the test page:
http://jiazhengblog.com/test/mouse/svg-mouse-event.html
,
Mar 7 2016
,
Mar 7 2016
,
Mar 7 2016
This changed with https://codereview.chromium.org/1747223002, so the old behavior can't really be argued to be correct in any way I'm afraid. The new behavior seems more useful to me and seems to match what Edge is doing. Gecko does things in yet another way (looks like they compute the position relative to the bounding client rect.) So I 'm leaning towards WontFix here.
,
Mar 7 2016
,
Mar 7 2016
The following revision refers to this bug: https://chromium.googlesource.com/chromium/src.git/+/2a2aac110bd8ea0d15d7b2979e87052a501218f1 commit 2a2aac110bd8ea0d15d7b2979e87052a501218f1 Author: fs <fs@opera.com> Date: Mon Mar 07 19:08:01 2016 Add more SVG-related mapLocalToAncestor/mapAncestorToLocal tests Written while looking at crbug.com/592316 . Tests viewBoxes with a non-zero x/y component. BUG= 592316 , 568614 Review URL: https://codereview.chromium.org/1771833002 Cr-Commit-Position: refs/heads/master@{#379600} [modify] https://crrev.com/2a2aac110bd8ea0d15d7b2979e87052a501218f1/third_party/WebKit/Source/core/layout/MapCoordinatesTest.cpp |
|||||||||||||||||||||
►
Sign in to add a comment |
|||||||||||||||||||||
Comment 1 by f...@opera.com
, Mar 7 2016Status: Available (was: Unconfirmed)