mirror of
https://github.com/RGBCube/serenity
synced 2025-10-13 16:32:06 +00:00

This patch adds HTMLCanvasElement along with a LayoutCanvas object. The DOM and layout parts are very similar to <img> elements. The <canvas> element holds a Gfx::Bitmap which is sized according to the "width" and "height" attributes on the element. Calling .getContext("2d") on a <canvas> element gives you a context object that draws into the underlying Gfx::Bitmap of the <canvas>. The context weakly points to the <canvas> which allows it to outlive the canvas element if needed. This is really quite cool. :^)
27 lines
617 B
HTML
27 lines
617 B
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<title>Canvas 2D test!</title>
|
|
<style type="text/css">
|
|
body {
|
|
background-color: #000;
|
|
color: #fff; /* another css comment */
|
|
}
|
|
canvas {
|
|
border-width: 1px;
|
|
border-style: solid;
|
|
border-color: #fff;
|
|
}
|
|
</style>
|
|
<script>
|
|
document.addEventListener("DOMContentLoaded", function() {
|
|
ctx = document.getElementById("foo").getContext("2d");
|
|
ctx.fillStyle = 'red';
|
|
ctx.fillRect(10, 10, 200, 100);
|
|
});
|
|
</script>
|
|
</head>
|
|
<body link="#44f" vlink="#c4c" background="90s-bg.png">
|
|
<canvas id="foo" width="300" height="200"></canvas>
|
|
</body>
|
|
</html>
|