Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / test / data / third_party / spaceport / js / sprites / renderers / css2dImg.js
blob0f3bb5780895c4119eaf8519d56ab9436d75051f
1 define([ 'util/ensureCallback', 'features', 'Modernizr', 'sprites/renderers/DomContext', 'util/create', 'sprites/container', 'util/quickPromise' ], function (ensureCallback, features, Modernizr, DomContext, create, container, quickPromise) {
2 function RenderContext(sourceData, frameData) {
3 if (!Modernizr.csstransforms) {
4 return;
7 this.loadPromise = quickPromise();
8 DomContext.call(this, sourceData, frameData, this.loadPromise.resolve);
10 this.elements.forEach(function (frameElements) {
11 frameElements.forEach(function (element) {
12 element.style[features.transformOriginStyleProperty] = '0 0';
13 });
14 });
16 this.transformData = frameData.map(function (objectTransforms) {
17 return objectTransforms.map(function (t) {
18 return t.cssTransform2d;
19 });
20 });
22 this.containerElement = container();
25 RenderContext.prototype = create(DomContext.prototype);
27 RenderContext.prototype.load = function load(callback) {
28 callback = ensureCallback(callback);
30 if (!Modernizr.csstransforms) {
31 callback(new Error('Not supported'));
32 return;
35 document.body.appendChild(this.containerElement);
37 this.loadPromise.then(function () {
38 callback(null);
39 });
42 RenderContext.prototype.unload = function unload() {
43 this.containerElement.parentNode.removeChild(this.containerElement);
44 DomContext.prototype.unload.call(this);
47 var transformStyleProperty = features.transformStyleProperty;
49 RenderContext.prototype.processElements = function processElements(elements, transforms) {
50 var count = elements.length;
51 var i;
52 for (i = 0; i < count; ++i) {
53 var element = elements[i];
54 element.style[transformStyleProperty] = transforms[i];
55 element.zIndex = i;
57 // Elements not in the DOM need to be added
58 if (!element.parentNode) {
59 this.containerElement.appendChild(element);
64 return function (element, frameData) {
65 return new RenderContext(element, frameData);
67 });