|
14 | 14 |
|
15 | 15 | (function(scope, testing) { |
16 | 16 |
|
| 17 | + var SVG_TRANSFORM_PROP = '_webAnimationsUpdateSvgTransformAttr'; |
| 18 | + |
| 19 | + /** |
| 20 | + * IE/Edge do not support `transform` styles for SVG elements. Instead, |
| 21 | + * `transform` attribute can be animated with some restrictions. |
| 22 | + * See https://connect.microsoft.com/IE/feedback/details/811744/ie11-bug-with-implementation-of-css-transforms-in-svg, |
| 23 | + * https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/1173754/, |
| 24 | + * https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/101242/, etc. |
| 25 | + * The same problem is exhibited by pre-Chrome Android browsers (ICS). |
| 26 | + * Unfortunately, there's no easy way to feature-detect it. |
| 27 | + */ |
| 28 | + function updateSvgTransformAttr(window, element) { |
| 29 | + if (!element.namespaceURI || element.namespaceURI.indexOf('/svg') == -1) { |
| 30 | + return false; |
| 31 | + } |
| 32 | + if (!(SVG_TRANSFORM_PROP in window)) { |
| 33 | + window[SVG_TRANSFORM_PROP] = |
| 34 | + /Trident|MSIE|IEMobile|Edge|Android 4/i.test(window.navigator.userAgent); |
| 35 | + } |
| 36 | + return window[SVG_TRANSFORM_PROP]; |
| 37 | + } |
| 38 | + |
17 | 39 | var styleAttributes = { |
18 | 40 | cssText: 1, |
19 | 41 | length: 1, |
|
44 | 66 | WEB_ANIMATIONS_TESTING && console.assert(!(element.style instanceof AnimatedCSSStyleDeclaration), |
45 | 67 | 'Element must not already have an animated style attached.'); |
46 | 68 |
|
| 69 | + this._element = element; |
47 | 70 | // Stores the inline style of the element on its behalf while the |
48 | 71 | // polyfill uses the element's inline style to simulate web animations. |
49 | 72 | // This is needed to fake regular inline style CSSOM access on the element. |
50 | 73 | this._surrogateStyle = document.createElementNS('http://www.w3.org/1999/xhtml', 'div').style; |
51 | 74 | this._style = element.style; |
52 | 75 | this._length = 0; |
53 | 76 | this._isAnimatedProperty = {}; |
| 77 | + this._updateSvgTransformAttr = updateSvgTransformAttr(window, element); |
| 78 | + this._savedTransformAttr = null; |
54 | 79 |
|
55 | 80 | // Copy the inline style contents over to the surrogate. |
56 | 81 | for (var i = 0; i < this._style.length; i++) { |
|
110 | 135 | _set: function(property, value) { |
111 | 136 | this._style[property] = value; |
112 | 137 | this._isAnimatedProperty[property] = true; |
| 138 | + if (this._updateSvgTransformAttr && |
| 139 | + scope.unprefixedPropertyName(property) == 'transform') { |
| 140 | + // On IE/Edge, also set SVG element's `transform` attribute to 2d |
| 141 | + // matrix of the transform. The `transform` style does not work, but |
| 142 | + // `transform` attribute can be used instead. |
| 143 | + // Notice, if the platform indeed supports SVG/CSS transforms the CSS |
| 144 | + // declaration is supposed to override the attribute. |
| 145 | + if (this._savedTransformAttr == null) { |
| 146 | + this._savedTransformAttr = this._element.getAttribute('transform'); |
| 147 | + } |
| 148 | + this._element.setAttribute('transform', scope.transformToSvgMatrix(value)); |
| 149 | + } |
113 | 150 | }, |
114 | 151 | _clear: function(property) { |
115 | 152 | this._style[property] = this._surrogateStyle[property]; |
| 153 | + if (this._updateSvgTransformAttr && |
| 154 | + scope.unprefixedPropertyName(property) == 'transform') { |
| 155 | + if (this._savedTransformAttr) { |
| 156 | + this._element.setAttribute('transform', this._savedTransformAttr); |
| 157 | + } else { |
| 158 | + this._element.removeAttribute('transform'); |
| 159 | + } |
| 160 | + this._savedTransformAttr = null; |
| 161 | + } |
116 | 162 | delete this._isAnimatedProperty[property]; |
117 | 163 | }, |
118 | 164 | }; |
|
185 | 231 | } |
186 | 232 | }; |
187 | 233 |
|
188 | | - if (WEB_ANIMATIONS_TESTING) |
| 234 | + if (WEB_ANIMATIONS_TESTING) { |
189 | 235 | testing.ensureStyleIsPatched = ensureStyleIsPatched; |
| 236 | + testing.updateSvgTransformAttr = updateSvgTransformAttr; |
| 237 | + } |
190 | 238 |
|
191 | 239 | })(webAnimations1, webAnimationsTesting); |
0 commit comments