Rubber-stamped by Brady Eidson.
[webbrowser.git] / LayoutTests / svg / css / composite-shadow-example.html
blobd6373b7e851eda8038a209ee3d5f33b6ba7ffde2
1 <html>
2 <head>
3 <script language="javascript">
4 <!--
6 SVG_NS = 'http://www.w3.org/2000/svg';
8 function pathFromStar (radius, innerRadius, sides) {
9 var path = [];
10 for (var i = 0; i < sides * 2; ++i) {
11 var theta = Math.PI * i / sides + (Math.PI / 2);
12 var r = (i % 2) ? radius : innerRadius;
13 var x = r * Math.cos(theta);
14 var y = r * Math.sin(theta);
15 path.push((i ? 'L' : 'M'), x, y);
17 path.push('Z');
18 return path.join(' ');
21 function newSvgElement (tagName, parentNode, attrs) {
22 var node = document.createElementNS(SVG_NS, tagName);
23 if (attrs) {
24 for (var k in attrs) {
25 node.setAttribute(k, attrs[k]);
28 if (parentNode) {
29 parentNode.appendChild(node);
31 return node;
34 function setCenterPosition (node, x, y) {
35 node.setAttribute('transform', 'translate($1, $2)'
36 .replace('$1', x)
37 .replace('$2', y));
40 var armed = null;
42 window.addEventListener('load', function () {
44 var svgContainer = newSvgElement('svg', document.body);
45 var shapes = [
46 { pos: [ 100, 100 ], size: 60, hasStroke: false },
47 { pos: [ 250, 100 ], size: 60, hasStroke: true },
48 { pos: [ 400, 100 ], size: 50, hasStroke: true }
50 svgContainer.style.WebkitShadow = '5px 5px 5px red';
51 for (var i = 0; i < shapes.length; ++i) {
52 var shape = shapes[i];
53 var group = newSvgElement('g', svgContainer);
54 var node = newSvgElement('path', group, {
55 d: pathFromStar(shape.size, shape.size / 2, 5),
56 fill: '#999',
57 stroke: 'black',
58 'stroke-width': 10,
59 });
60 setCenterPosition(node, shape.pos[0], shape.pos[1]);
61 if (shapes[i].hasStroke) {
62 node.setAttribute('stroke-dasharray', 20);
64 node.addEventListener('mousedown', function (ev) {
65 var e = ev || event;
66 armed = { node: e.target || e.srcElement };
67 });
68 node.addEventListener('mouseup', function () {
69 armed = null;
70 });
72 window.addEventListener('mousemove', function (ev) {
73 if (armed) {
74 var e = ev || event;
75 setCenterPosition(armed.node, e.clientX, e.clientY);
77 });
78 });
80 //-->
81 </script>
82 </head>
83 <body>
85 </body>
86 </html>