OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <html> |
| 3 <head> |
| 4 <title>Canvas Hit Regions: fillRule test</title> |
| 5 <script src="../../resources/js-test.js"></script> |
| 6 </head> |
| 7 <body> |
| 8 <canvas id="canvas" width="400" height="400"> |
| 9 </canvas> |
| 10 <script> |
| 11 |
| 12 var canvas = document.getElementById("canvas"); |
| 13 var context = canvas.getContext("2d"); |
| 14 |
| 15 function clickCanvas(x, y) |
| 16 { |
| 17 if (!window.eventSender) |
| 18 return "This test requires eventSender"; |
| 19 |
| 20 var result = null; |
| 21 function listener(event) |
| 22 { |
| 23 result = event.region; |
| 24 } |
| 25 |
| 26 var rect = canvas.getBoundingClientRect(); |
| 27 canvas.addEventListener("click", listener, false); |
| 28 eventSender.mouseMoveTo(rect.left + x, rect.top + y); |
| 29 eventSender.mouseDown(); |
| 30 eventSender.mouseUp(); |
| 31 canvas.removeEventListener("click", listener, false); |
| 32 |
| 33 return result; |
| 34 } |
| 35 |
| 36 context.rect(20, 20, 60, 60); |
| 37 context.rect(0, 0, 100, 100); |
| 38 context.addHitRegion({ |
| 39 id : "nonzero" |
| 40 // default fillRule |
| 41 }); |
| 42 |
| 43 debug("default fillRule(nonzero):"); |
| 44 shouldBe("clickCanvas(1, 1)", "'nonzero'"); |
| 45 shouldBe("clickCanvas(99, 98)", "'nonzero'"); |
| 46 shouldBe("clickCanvas(21, 21)", "'nonzero'"); |
| 47 shouldBe("clickCanvas(50, 50)", "'nonzero'"); |
| 48 debug(""); |
| 49 |
| 50 context.removeHitRegion("nonzero"); |
| 51 |
| 52 context.addHitRegion({ |
| 53 id : "evenodd", |
| 54 fillRule : "evenodd" |
| 55 }); |
| 56 |
| 57 debug("fillRule = evenodd:"); |
| 58 shouldBe("clickCanvas(1, 1)", "'evenodd'"); |
| 59 shouldBe("clickCanvas(99, 98)", "'evenodd'"); |
| 60 shouldBe("clickCanvas(21, 21)", "null"); |
| 61 shouldBe("clickCanvas(50, 50)", "null"); |
| 62 debug(""); |
| 63 |
| 64 context.removeHitRegion("evenodd"); |
| 65 |
| 66 context.addHitRegion({ |
| 67 id : "nonzero", |
| 68 fillRule : "nonzero" |
| 69 }); |
| 70 |
| 71 debug("fillRule = nonzero:"); |
| 72 shouldBe("clickCanvas(1, 1)", "'nonzero'"); |
| 73 shouldBe("clickCanvas(99, 98)", "'nonzero'"); |
| 74 shouldBe("clickCanvas(21, 21)", "'nonzero'"); |
| 75 shouldBe("clickCanvas(50, 50)", "'nonzero'"); |
| 76 debug(""); |
| 77 |
| 78 context.removeHitRegion("nonzero"); |
| 79 |
| 80 context.addHitRegion({ |
| 81 id : "nonzero", |
| 82 fillRule : null |
| 83 }); |
| 84 |
| 85 debug("fillRule = null, falls back to default (nonzero):"); |
| 86 shouldBe("clickCanvas(1, 1)", "'nonzero'"); |
| 87 shouldBe("clickCanvas(99, 98)", "'nonzero'"); |
| 88 shouldBe("clickCanvas(21, 21)", "'nonzero'"); |
| 89 shouldBe("clickCanvas(50, 50)", "'nonzero'"); |
| 90 debug(""); |
| 91 |
| 92 context.removeHitRegion("nonzero"); |
| 93 |
| 94 context.addHitRegion({ |
| 95 id : "nonzero", |
| 96 fillRule : undefined |
| 97 }); |
| 98 |
| 99 debug("fillRule = undefined, falls back to default (nonzero):"); |
| 100 shouldBe("clickCanvas(1, 1)", "'nonzero'"); |
| 101 shouldBe("clickCanvas(99, 98)", "'nonzero'"); |
| 102 shouldBe("clickCanvas(21, 21)", "'nonzero'"); |
| 103 shouldBe("clickCanvas(50, 50)", "'nonzero'"); |
| 104 debug(""); |
| 105 |
| 106 </script> |
| 107 </body> |
| 108 </html> |
OLD | NEW |