clip-path-element-objectboundingbox-002.html (1248B)
1 <!DOCTYPE html> 2 <title>Hit-test of clip-path nested objectBoundingBox <clipPath></title> 3 <link rel="help" href="https://drafts.fxtf.org/css-masking/#the-clip-path"> 4 <script src="/resources/testharness.js"></script> 5 <script src="/resources/testharnessreport.js"></script> 6 <style> 7 body { 8 margin: 0; 9 } 10 .box { 11 width: 200px; 12 height: 200px; 13 background-color: blue; 14 margin: 100px; 15 clip-path: url(#clip); 16 } 17 </style> 18 <div class="box"></div> 19 <svg height="0"> 20 <clipPath id="nested" clipPathUnits="objectBoundingBox"> 21 <circle cx="0.25" cy="0.25" r="0.25"/> 22 </clipPath> 23 <clipPath id="clip" clipPathUnits="objectBoundingBox" clip-path="url(#nested)"> 24 <rect width="0.5" height="0.5"/> 25 </clipPath> 26 </svg> 27 <script> 28 function assert_element_at(element, pointlist) { 29 for (let point of pointlist) { 30 let result = document.elementFromPoint(point[0], point[1]); 31 assert_equals(result, element, point.join(',')); 32 } 33 } 34 35 test(function() { 36 let div = document.querySelector('.box'); 37 38 // Points inside clip-path. 39 assert_element_at(div, [[150, 150], [150, 125], [150, 175], [125, 150], [175, 150]]); 40 41 // Points outside clip-path. 42 assert_element_at(document.body, [[110, 110], [190, 110], [110, 190], [190, 190]]); 43 }); 44 </script>