OLD | NEW |
1 <!DOCTYPE HTML> | 1 <!DOCTYPE HTML> |
2 <html> | 2 <html> |
3 <head> | 3 <head> |
4 <title>Canvas 2D Test: Red Box over Black Background</title> | 4 <title>Canvas 2D Test: Red Box over Black Background</title> |
5 <style type="text/css"> | 5 <style type="text/css"> |
6 .nomargin { | 6 .nomargin { |
7 margin: 0px auto; | 7 margin: 0px auto; |
8 } | 8 } |
9 </style> | 9 </style> |
10 <script> | 10 <script> |
11 var g_swapsBeforeAck = 6; | 11 var g_swapsBeforeAck = 15; |
12 var g_paintLoopStarted = false; | 12 var g_targetHeight, g_targetWidth; |
| 13 |
| 14 function onresized() |
| 15 { |
| 16 if (window.outerHeight != g_targetHeight || |
| 17 window.outerWidth != g_targetWidth) |
| 18 return; |
| 19 |
| 20 main(); |
| 21 } |
13 | 22 |
14 function main() | 23 function main() |
15 { | 24 { |
16 g_swapsBeforeAck = 6; | 25 draw(); |
17 | 26 waitForFinish(); |
18 if (!g_paintLoopStarted) { | |
19 g_paintLoopStarted = true; | |
20 draw(); | |
21 waitForFinish(); | |
22 } | |
23 } | 27 } |
24 | 28 |
25 function draw() | 29 function draw() |
26 { | 30 { |
27 var canvas = document.getElementById("c"); | 31 var canvas = document.getElementById("c"); |
28 var c2d = canvas.getContext("2d"); | 32 var c2d = canvas.getContext("2d"); |
29 c2d.clearRect(0, 0, canvas.width, canvas.height); | 33 c2d.clearRect(0, 0, canvas.width, canvas.height); |
30 c2d.fillStyle = "rgba(255, 0, 0, 0.5)"; | 34 c2d.fillStyle = "rgba(255, 0, 0, 0.5)"; |
31 c2d.fillRect(50, 50, 100, 100); | 35 c2d.fillRect(50, 50, 100, 100); |
32 } | 36 } |
33 | 37 |
34 function waitForFinish() | 38 function waitForFinish() |
35 { | 39 { |
36 if (g_swapsBeforeAck == 0) { | 40 if (g_swapsBeforeAck == 0) { |
37 domAutomationController.setAutomationId(1); | 41 domAutomationController.setAutomationId(1); |
38 domAutomationController.send("resized"); | 42 domAutomationController.send("resized"); |
39 } else { | 43 } else { |
40 g_swapsBeforeAck--; | 44 g_swapsBeforeAck--; |
41 draw(); | 45 draw(); |
42 window.webkitRequestAnimationFrame(waitForFinish); | 46 window.webkitRequestAnimationFrame(waitForFinish); |
43 } | 47 } |
44 } | 48 } |
45 | 49 |
46 function notifyLoadFinished() | 50 function notifyLoadFinished() |
47 { | 51 { |
48 domAutomationController.setAutomationId(1); | 52 domAutomationController.setAutomationId(1); |
49 domAutomationController.send("ok"); | 53 domAutomationController.send("ok"); |
50 } | 54 } |
51 | 55 |
52 function preCallResizeInChromium() | 56 function preCallResizeInChromium(targetWidth, targetHeight) |
53 { | 57 { |
54 window.onresize = main; | 58 g_targetWidth = targetWidth; |
| 59 g_targetHeight = targetHeight; |
| 60 window.onresize = onresized; |
55 // Call main() on a timeout in case the window did not resize for whatever | 61 // Call main() on a timeout in case the window did not resize for whatever |
56 // reason. | 62 // reason. |
57 setTimeout(main, 10000); | 63 setTimeout(main, 10000); |
58 } | 64 } |
59 </script> | 65 </script> |
60 </head> | 66 </head> |
61 <body onload="notifyLoadFinished()"> | 67 <body onload="notifyLoadFinished()"> |
62 <div style="position:relative; width:200px; height:200px; background-color:black
"> | 68 <div style="position:relative; width:200px; height:200px; background-color:black
"> |
63 </div> | 69 </div> |
64 <div style="position:absolute; top:0px; left:0px"> | 70 <div style="position:absolute; top:0px; left:0px"> |
65 <canvas id="c" width="200" height="200" class="nomargin"></canvas> | 71 <canvas id="c" width="200" height="200" class="nomargin"></canvas> |
66 </div> | 72 </div> |
67 </body> | 73 </body> |
68 </html> | 74 </html> |
OLD | NEW |