Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Side by Side Diff: LayoutTests/fast/canvas/canvas-hit-regions-basic-test.html

Issue 300223009: Implement basic parts of hit regions on canvas2d. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: rebase Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <title>Canvas Hit Regions: basic test</title>
5 <script src="../../resources/js-test.js"></script>
6 </head>
7 <body>
8 <canvas id="canvas" width="400" height="400">
9 <button id="face"></button>
10 <button id="eyes"></button>
11 </canvas>
12 <script>
13
14 canvas = document.getElementById("canvas");
15 context = canvas.getContext("2d");
16
17 context.fillStyle = "pink";
18 context.arc(200, 175, 150, 0, Math.PI * 2, true);
19 context.fill();
20 context.addHitRegion({ id : "face", control : document.getElementById("face") });
21
22 context.beginPath();
23 context.fillStyle = "black";
24 context.globalAlpha = .5;
25 context.moveTo(200, 165);
26 context.lineTo(240, 205);
27 context.lineTo(160, 205);
28 context.closePath();
29 context.fill();
30 context.addHitRegion({ id : "nose" });
31
32 context.beginPath();
33 context.fillStyle = "red";
34 context.rect(125, 240, 150, 20);
35 context.fill();
36 context.addHitRegion({ id : "mouth" });
37
38 context.beginPath();
39 context.globalAlpha = 1;
40 context.fillStyle = "blue";
41 context.arc(150, 125, 25, 0, Math.PI * 2, true);
42 context.arc(250, 125, 25, 0, Math.PI * 2, true);
43 context.fill();
44 context.addHitRegion({ id: "eye", control : document.getElementById("eyes") }) ;
45
46 function clickCanvas(x, y)
47 {
48 if (!window.eventSender)
49 return "This test requires eventSender";
50
51 var result = null;
52 function listener(event)
53 {
54 result = event.region;
55 }
56
57 var rect = canvas.getBoundingClientRect();
58 canvas.addEventListener("click", listener, false);
59 eventSender.mouseMoveTo(rect.left + x, rect.top + y);
60 eventSender.mouseDown();
61 eventSender.mouseUp();
62 canvas.removeEventListener("click", listener, false);
63
64 return result;
65 }
66
67 debug("Hit detection and mouse event tests");
68 shouldBe("clickCanvas(100, 100)", "'face'");
69 shouldBe("clickCanvas(200, 200)", "'nose'");
70 shouldBe("clickCanvas(127, 242)", "'mouth'");
71 shouldBe("clickCanvas(150, 125)", "'eye'");
72 shouldBe("clickCanvas(250, 125)", "'eye'");
73 shouldBe("clickCanvas(200, 125)", "'face'");
74 shouldBe("clickCanvas(20, 10)", "null");
75 debug("");
76
77 debug("NotSupportedError exception tests");
78 shouldThrow("context.addHitRegion()");
79 shouldThrow("context.addHitRegion({ id : '' })");
80 shouldThrow("context.addHitRegion({ id : null })");
81 shouldThrow("context.addHitRegion({ id : undefined })");
82 shouldThrow("context.addHitRegion({ control : {} })");
83 shouldThrow("context.addHitRegion({ control : null })");
84 shouldThrow("context.addHitRegion({ control : undefined })");
85 shouldThrow("context.addHitRegion({ id : '', control : {} })");
86 shouldThrow("context.addHitRegion({ id : null, control : {} })");
87 shouldThrow("context.addHitRegion({ id : undefined, control : {} })");
88 shouldThrow("context.addHitRegion({ id : '', control : null })");
89 shouldThrow("context.addHitRegion({ id : null, control : null })");
90 shouldThrow("context.addHitRegion({ id : undefined, control : null })");
91 shouldThrow("context.addHitRegion({ id : '', control : undefined })");
92 shouldThrow("context.addHitRegion({ id : null, control : undefined })");
93 shouldThrow("context.addHitRegion({ id : undefined, control : undefined })");
94
95 </script>
96 </body>
97 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698