OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <title>MouseEvent.offsetX/offsetY for an SVG element is always relative to the o
utermost <svg> CSS layout box</title> |
| 3 <script src="../../resources/testharness.js"></script> |
| 4 <script src="../../resources/testharnessreport.js"></script> |
| 5 <style> |
| 6 svg { |
| 7 border: 10px solid blue; |
| 8 border-width: 20px 40px 30px 10px; |
| 9 } |
| 10 </style> |
| 11 <svg width="400" height="400" viewBox="0 0 400000 400000"> |
| 12 <rect x="40000" y="60000" width="80000" height="80000" fill="blue"/> |
| 13 <rect x="160000" y="180000" width="80000" height="80000" fill="blue" stroke="l
ightblue" stroke-width="10000"/> |
| 14 </svg> |
| 15 <script> |
| 16 function check_offset(test, element, clientX, clientY, expectedOffsetX, expected
OffsetY) { |
| 17 element.onclick = test.step_func(function(event) { |
| 18 assert_equals(event.offsetX, expectedOffsetX, 'offsetX'); |
| 19 assert_equals(event.offsetY, expectedOffsetY, 'offsetY'); |
| 20 }); |
| 21 var mouseEvent = new MouseEvent('click', { clientX: clientX, clientY: client
Y }); |
| 22 element.dispatchEvent(mouseEvent); |
| 23 } |
| 24 |
| 25 test(function(t) { |
| 26 var rects = document.querySelectorAll('rect'); |
| 27 var svgBoundingRect = document.querySelector('svg').getBoundingClientRect(); |
| 28 var offsetBase = { x: svgBoundingRect.left + 10, y: svgBoundingRect.top + 20
}; |
| 29 check_offset(t, rects[0], offsetBase.x + 80, offsetBase.y + 100, 80, 100); |
| 30 check_offset(t, rects[1], offsetBase.x + 200, offsetBase.y + 220, 200, 220); |
| 31 }); |
| 32 </script> |
OLD | NEW |