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