Move createElement and createSVGElement to Utilities.
authorjonlee@apple.com <jonlee@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 7 Feb 2016 00:34:31 +0000 (00:34 +0000)
committerjonlee@apple.com <jonlee@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 7 Feb 2016 00:34:31 +0000 (00:34 +0000)
* Animometer/resources/extensions.js:
(Utilities.createElement): Added.
(Utilities.createSVGElement): Added.
(DocumentExtension.createElement): Deleted.
(DocumentExtension.createSvgElement): Deleted.

* Animometer/resources/debug-runner/animometer.js:
* Animometer/resources/runner/animometer.js:
* Animometer/tests/bouncing-particles/resources/bouncing-svg-images.js:
* Animometer/tests/bouncing-particles/resources/bouncing-svg-particles.js:
* Animometer/tests/bouncing-particles/resources/bouncing-svg-shapes.js:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@196229 268f45cc-cd09-0410-ab3c-d52691b4dbfc

PerformanceTests/Animometer/resources/debug-runner/animometer.js
PerformanceTests/Animometer/resources/extensions.js
PerformanceTests/Animometer/resources/runner/animometer.js
PerformanceTests/Animometer/tests/bouncing-particles/resources/bouncing-svg-images.js
PerformanceTests/Animometer/tests/bouncing-particles/resources/bouncing-svg-particles.js
PerformanceTests/Animometer/tests/bouncing-particles/resources/bouncing-svg-shapes.js
PerformanceTests/ChangeLog

index 564f993..7625908 100644 (file)
@@ -186,11 +186,11 @@ window.suitesManager =
 
     _createSuiteElement: function(treeElement, suite, id)
     {
-        var suiteElement = DocumentExtension.createElement("li", {}, treeElement);
-        var expand = DocumentExtension.createElement("input", { type: "checkbox",  class: "expand-button", id: id }, suiteElement);
-        var label = DocumentExtension.createElement("label", { class: "tree-label", for: id }, suiteElement);
+        var suiteElement = Utilities.createElement("li", {}, treeElement);
+        var expand = Utilities.createElement("input", { type: "checkbox",  class: "expand-button", id: id }, suiteElement);
+        var label = Utilities.createElement("label", { class: "tree-label", for: id }, suiteElement);
 
-        var suiteCheckbox = DocumentExtension.createElement("input", { type: "checkbox" }, label);
+        var suiteCheckbox = Utilities.createElement("input", { type: "checkbox" }, label);
         suiteCheckbox.suite = suite;
         suiteCheckbox.onchange = this._onChangeSuiteCheckbox.bind(this);
         suiteCheckbox.testsElements = [];
@@ -201,10 +201,10 @@ window.suitesManager =
 
     _createTestElement: function(listElement, test, suiteCheckbox)
     {
-        var testElement = DocumentExtension.createElement("li", {}, listElement);
-        var span = DocumentExtension.createElement("label", { class: "tree-label" }, testElement);
+        var testElement = Utilities.createElement("li", {}, listElement);
+        var span = Utilities.createElement("label", { class: "tree-label" }, testElement);
 
-        var testCheckbox = DocumentExtension.createElement("input", { type: "checkbox" }, span);
+        var testCheckbox = Utilities.createElement("input", { type: "checkbox" }, span);
         testCheckbox.test = test;
         testCheckbox.onchange = function(event) {
             this._onChangeTestCheckbox(event.target.suiteCheckbox);
@@ -213,7 +213,7 @@ window.suitesManager =
 
         suiteCheckbox.testsElements.push(testElement);
         span.appendChild(document.createTextNode(" " + test.name));
-        var complexity = DocumentExtension.createElement("input", { type: "number" }, testElement);
+        var complexity = Utilities.createElement("input", { type: "number" }, testElement);
         complexity.relatedCheckbox = testCheckbox;
         complexity.oninput = function(event) {
             var relatedCheckbox = event.target.relatedCheckbox;
@@ -229,7 +229,7 @@ window.suitesManager =
 
         Suites.forEach(function(suite, index) {
             var suiteElement = this._createSuiteElement(treeElement, suite, "suite-" + index);
-            var listElement = DocumentExtension.createElement("ul", {}, suiteElement);
+            var listElement = Utilities.createElement("ul", {}, suiteElement);
             var suiteCheckbox = this._checkboxElement(suiteElement);
 
             suite.tests.forEach(function(test) {
index cc3ec9d..54865ee 100644 (file)
@@ -54,6 +54,34 @@ Utilities =
         if (classMethods)
             Utilities.extendObject(classConstructor.prototype, classMethods);
         return classConstructor;
+    },
+
+    createElement: function(name, attrs, parentElement)
+    {
+        var element = document.createElement(name);
+
+        for (var key in attrs)
+            element.setAttribute(key, attrs[key]);
+
+        parentElement.appendChild(element);
+        return element;
+    },
+
+    createSVGElement: function(name, attrs, xlinkAttrs, parentElement)
+    {
+        const svgNamespace = "http://www.w3.org/2000/svg";
+        const xlinkNamespace = "http://www.w3.org/1999/xlink";
+
+        var element = document.createElementNS(svgNamespace, name);
+
+        for (var key in attrs)
+            element.setAttribute(key, attrs[key]);
+
+        for (var key in xlinkAttrs)
+            element.setAttributeNS(xlinkNamespace, key, xlinkAttrs[key]);
+
+        parentElement.appendChild(element);
+        return element;
     }
 };
 
@@ -306,34 +334,3 @@ Statistics =
         return roots.reduce(function(a, b) { return a * b; });
     }
 };
-
-DocumentExtension =
-{
-    createElement: function(name, attrs, parentElement)
-    {
-        var element = document.createElement(name);
-
-        for (var key in attrs)
-            element.setAttribute(key, attrs[key]);
-
-        parentElement.appendChild(element);
-        return element;
-    },
-
-    createSvgElement: function(name, attrs, xlinkAttrs, parentElement)
-    {
-        const svgNamespace = "http://www.w3.org/2000/svg";
-        const xlinkNamespace = "http://www.w3.org/1999/xlink";
-
-        var element = document.createElementNS(svgNamespace, name);
-
-        for (var key in attrs)
-            element.setAttribute(key, attrs[key]);
-
-        for (var key in xlinkAttrs)
-            element.setAttributeNS(xlinkNamespace, key, xlinkAttrs[key]);
-
-        parentElement.appendChild(element);
-        return element;
-    }
-};
index 2c2555f..41fa976 100644 (file)
@@ -86,11 +86,11 @@ ResultsTable = Utilities.createClass(
 
     _addHeader: function()
     {
-        var thead = DocumentExtension.createElement("thead", {}, this.element);
-        var row = DocumentExtension.createElement("tr", {}, thead);
+        var thead = Utilities.createElement("thead", {}, this.element);
+        var row = Utilities.createElement("tr", {}, thead);
 
         this._headers.forEach(function (header) {
-            var th = DocumentExtension.createElement("th", {}, row);
+            var th = Utilities.createElement("th", {}, row);
             if (header.title != Strings.text.results.graph)
                 th.textContent = header.title;
             if (header.children)
@@ -104,7 +104,7 @@ ResultsTable = Utilities.createClass(
         if (!data)
             return;
 
-        var button = DocumentExtension.createElement("button", { class: "small-button" }, td);
+        var button = Utilities.createElement("button", { class: "small-button" }, td);
 
         button.addEventListener("click", function() {
             var score = testResults[Strings.json.score].toFixed(2);
@@ -152,15 +152,15 @@ ResultsTable = Utilities.createClass(
 
     _addEmptyRow: function()
     {
-        var row = DocumentExtension.createElement("tr", {}, this.element);
+        var row = Utilities.createElement("tr", {}, this.element);
         this._flattenedHeaders.forEach(function (header) {
-            return DocumentExtension.createElement("td", { class: "suites-separator" }, row);
+            return Utilities.createElement("td", { class: "suites-separator" }, row);
         });
     },
 
     _addTest: function(testName, testResults, options)
     {
-        var row = DocumentExtension.createElement("tr", {}, this.element);
+        var row = Utilities.createElement("tr", {}, this.element);
 
         var isNoisy = false;
         [Strings.json.experiments.complexity, Strings.json.experiments.frameRate].forEach(function (experiment) {
@@ -184,12 +184,12 @@ ResultsTable = Utilities.createClass(
                 var titleClassName = className;
                 if (isNoisy)
                     titleClassName += " noisy-results";
-                var td = DocumentExtension.createElement("td", { class: titleClassName }, row);
+                var td = Utilities.createElement("td", { class: titleClassName }, row);
                 td.textContent = testName;
                 return;
             }
 
-            var td = DocumentExtension.createElement("td", { class: className }, row);
+            var td = Utilities.createElement("td", { class: className }, row);
             if (header.title == Strings.text.results.graph) {
                 this._addGraphButton(td, testName, testResults);
             } else if (!("text" in header)) {
index e331cc4..dd244af 100644 (file)
@@ -7,7 +7,7 @@ BouncingSvgImage = Utilities.createSubclass(BouncingSvgParticle,
 
         var attrs = { x: 0, y: 0, width: this.size.x, height: this.size.y };
         var xlinkAttrs = { href: stage.imageSrc };
-        this.element = DocumentExtension.createSvgElement("image", attrs, xlinkAttrs, stage.element);
+        this.element = Utilities.createSVGElement("image", attrs, xlinkAttrs, stage.element);
         this._move();
     }
 );
index e39f2f0..0988c42 100644 (file)
@@ -37,7 +37,7 @@ BouncingSvgParticlesStage = Utilities.createSubclass(BouncingParticlesStage,
 
     _createDefs: function()
     {
-        return DocumentExtension.createSvgElement("defs", {}, {}, this.element);
+        return Utilities.createSVGElement("defs", {}, {}, this.element);
     },
 
     _ensureDefsIsCreated: function()
@@ -48,10 +48,10 @@ BouncingSvgParticlesStage = Utilities.createSubclass(BouncingParticlesStage,
     _createClipStar: function()
     {
         var attrs = { id: "star-clip", clipPathUnits: "objectBoundingBox" };
-        var clipPath  = DocumentExtension.createSvgElement("clipPath", attrs, {}, this._ensureDefsIsCreated());
+        var clipPath  = Utilities.createSVGElement("clipPath", attrs, {}, this._ensureDefsIsCreated());
 
         attrs = { d: "M.50,0L.38,.38L0,.38L.30,.60L.18,1L.50,.75L.82,1L.70,.60L1,.38L.62,.38z" };
-        DocumentExtension.createSvgElement("path", attrs, {}, clipPath);
+        Utilities.createSVGElement("path", attrs, {}, clipPath);
         return clipPath;
     },
 
index 48825ef..d05ab11 100644 (file)
@@ -18,13 +18,13 @@ BouncingSvgShape = Utilities.createSubclass(BouncingSvgParticle,
         switch (this._shape) {
         case "rect":
             var attrs = { x: 0, y: 0, width: this.size.x, height: this.size.y };
-            this.element = DocumentExtension.createSvgElement("rect", attrs, {}, stage.element);
+            this.element = Utilities.createSVGElement("rect", attrs, {}, stage.element);
             break;
 
         case "circle":
         default:
             var attrs = { cx: this.size.x / 2, cy: this.size.y / 2, r: Math.min(this.size.x, this.size.y) / 2 };
-            this.element = DocumentExtension.createSvgElement("circle", attrs, {}, stage.element);
+            this.element = Utilities.createSVGElement("circle", attrs, {}, stage.element);
             break;
         }
     },
@@ -61,11 +61,11 @@ BouncingSvgShapesStage = Utilities.createSubclass(BouncingSvgParticlesStage,
     createGradient: function(stops)
     {
         var attrs = { id: "gradient-" + ++this._gradientsCount };
-        var gradient = DocumentExtension.createSvgElement("linearGradient", attrs, {}, this._ensureDefsIsCreated());
+        var gradient = Utilities.createSVGElement("linearGradient", attrs, {}, this._ensureDefsIsCreated());
 
         for (var i = 0; i < stops; ++i) {
             attrs = { offset: i * 100 / stops + "%", 'stop-color': Stage.randomColor() };
-            DocumentExtension.createSvgElement("stop", attrs, {}, gradient);
+            Utilities.createSVGElement("stop", attrs, {}, gradient);
         }
 
         return gradient;
index 84d5af3..00033b4 100644 (file)
@@ -1,5 +1,21 @@
 2016-02-06  Jon Lee  <jonlee@apple.com>
 
+        Move createElement and createSVGElement to Utilities.
+
+        * Animometer/resources/extensions.js:
+        (Utilities.createElement): Added.
+        (Utilities.createSVGElement): Added.
+        (DocumentExtension.createElement): Deleted.
+        (DocumentExtension.createSvgElement): Deleted.
+
+        * Animometer/resources/debug-runner/animometer.js:
+        * Animometer/resources/runner/animometer.js:
+        * Animometer/tests/bouncing-particles/resources/bouncing-svg-images.js:
+        * Animometer/tests/bouncing-particles/resources/bouncing-svg-particles.js:
+        * Animometer/tests/bouncing-particles/resources/bouncing-svg-shapes.js:
+
+2016-02-06  Jon Lee  <jonlee@apple.com>
+
         Add a convenience function for creating a class.
 
         The pattern for creating a class is common enough to add as a Utilities