Simplify the test harness
[WebKit-https.git] / PerformanceTests / Animometer / tests / bouncing-particles / resources / bouncing-svg-particles.js
1 BouncingSvgParticle = Utilities.createSubclass(BouncingParticle,
2     function(stage, shape)
3     {
4         BouncingParticle.call(this, stage);
5         this._shape = shape;
6     }, {
7
8     _applyClipping: function(stage)
9     {
10         if (stage.clip != "star")
11             return;
12
13         stage.ensureClipStarIsCreated();
14         this.element.setAttribute("clip-path", "url(#star-clip)");
15     },
16
17     _move: function()
18     {
19         var transform = "translate(" + this.position.x + ", " + this.position.y + ")";
20         if (this._shape != "circle")
21             transform += this.rotater.rotate(this.size.center);
22         this.element.setAttribute("transform", transform);
23     },
24
25     animate: function(timeDelta)
26     {
27         BouncingParticle.prototype.animate.call(this, timeDelta);
28         this._move();
29     }
30 });
31
32 BouncingSvgParticlesStage = Utilities.createSubclass(BouncingParticlesStage,
33     function()
34     {
35         BouncingParticlesStage.call(this);
36     }, {
37
38     _createDefs: function()
39     {
40         return DocumentExtension.createSvgElement("defs", {}, {}, this.element);
41     },
42
43     _ensureDefsIsCreated: function()
44     {
45         return this.element.querySelector("defs") || this._createDefs();
46     },
47
48     _createClipStar: function()
49     {
50         var attrs = { id: "star-clip", clipPathUnits: "objectBoundingBox" };
51         var clipPath  = DocumentExtension.createSvgElement("clipPath", attrs, {}, this._ensureDefsIsCreated());
52
53         attrs = { d: "M.50,0L.38,.38L0,.38L.30,.60L.18,1L.50,.75L.82,1L.70,.60L1,.38L.62,.38z" };
54         DocumentExtension.createSvgElement("path", attrs, {}, clipPath);
55         return clipPath;
56     },
57
58     ensureClipStarIsCreated: function()
59     {
60         return this.element.querySelector("#star-clip") || this._createClipStar();
61     },
62
63     particleWillBeRemoved: function(particle)
64     {
65         particle.element.remove();
66     }
67 });