OLD | NEW |
1 // Copyright 2014 Google Inc. All rights reserved. | 1 // Copyright 2014 Google Inc. All rights reserved. |
2 // | 2 // |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
6 // | 6 // |
7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
8 // | 8 // |
9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
(...skipping 29 matching lines...) Loading... |
40 Object.defineProperty(object, property, descriptor); | 40 Object.defineProperty(object, property, descriptor); |
41 } | 41 } |
42 | 42 |
43 function AnimatedCSSStyleDeclaration(element) { | 43 function AnimatedCSSStyleDeclaration(element) { |
44 WEB_ANIMATIONS_TESTING && console.assert(!(element.style instanceof Animated
CSSStyleDeclaration), | 44 WEB_ANIMATIONS_TESTING && console.assert(!(element.style instanceof Animated
CSSStyleDeclaration), |
45 'Element must not already have an animated style attached.'); | 45 'Element must not already have an animated style attached.'); |
46 | 46 |
47 // Stores the inline style of the element on its behalf while the | 47 // Stores the inline style of the element on its behalf while the |
48 // polyfill uses the element's inline style to simulate web animations. | 48 // polyfill uses the element's inline style to simulate web animations. |
49 // This is needed to fake regular inline style CSSOM access on the element. | 49 // This is needed to fake regular inline style CSSOM access on the element. |
50 this._surrogateElement = document.createElement('div'); | 50 this._surrogateStyle = document.createElementNS('http://www.w3.org/1999/xhtm
l', 'div').style; |
51 this._surrogateStyle = this._surrogateElement.style; | |
52 this._style = element.style; | 51 this._style = element.style; |
53 this._length = 0; | 52 this._length = 0; |
54 this._isAnimatedProperty = {}; | 53 this._isAnimatedProperty = {}; |
55 | 54 |
56 // Copy the inline style contents over to the surrogate. | 55 // Copy the inline style contents over to the surrogate. |
57 for (var i = 0; i < this._style.length; i++) { | 56 for (var i = 0; i < this._style.length; i++) { |
58 var property = this._style[i]; | 57 var property = this._style[i]; |
59 this._surrogateStyle[property] = this._style[property]; | 58 this._surrogateStyle[property] = this._style[property]; |
60 } | 59 } |
61 this._updateIndices(); | 60 this._updateIndices(); |
(...skipping 88 matching lines...) Loading... |
150 this._style[property] = value; | 149 this._style[property] = value; |
151 } | 150 } |
152 }); | 151 }); |
153 })(property); | 152 })(property); |
154 } | 153 } |
155 | 154 |
156 function ensureStyleIsPatched(element) { | 155 function ensureStyleIsPatched(element) { |
157 if (element._webAnimationsPatchedStyle) | 156 if (element._webAnimationsPatchedStyle) |
158 return; | 157 return; |
159 | 158 |
160 // If this style patch fails (on Safari and iOS) use the apply-preserving-in
line-style-methods.js | |
161 // module instead and restrict inline style interactions to the methods list
ed in styleMethods. | |
162 var animatedStyle = new AnimatedCSSStyleDeclaration(element); | 159 var animatedStyle = new AnimatedCSSStyleDeclaration(element); |
163 configureProperty(element, 'style', { get: function() { return animatedStyle
; } }); | 160 try { |
| 161 configureProperty(element, 'style', { get: function() { return animatedSty
le; } }); |
| 162 } catch (_) { |
| 163 // iOS and older versions of Safari (pre v7) do not support overriding an
element's |
| 164 // style object. Animations will clobber any inline styles as a result. |
| 165 element.style._set = function(property, value) { |
| 166 element.style[property] = value; |
| 167 }; |
| 168 element.style._clear = function(property) { |
| 169 element.style[property] = ''; |
| 170 }; |
| 171 } |
164 | 172 |
165 // We must keep a handle on the patched style to prevent it from getting GC'
d. | 173 // We must keep a handle on the patched style to prevent it from getting GC'
d. |
166 element._webAnimationsPatchedStyle = element.style; | 174 element._webAnimationsPatchedStyle = element.style; |
167 } | 175 } |
168 | 176 |
169 scope.apply = function(element, property, value) { | 177 scope.apply = function(element, property, value) { |
170 ensureStyleIsPatched(element); | 178 ensureStyleIsPatched(element); |
171 element.style._set(scope.propertyName(property), value); | 179 element.style._set(scope.propertyName(property), value); |
172 }; | 180 }; |
173 | 181 |
174 scope.clear = function(element, property) { | 182 scope.clear = function(element, property) { |
175 if (element._webAnimationsPatchedStyle) { | 183 if (element._webAnimationsPatchedStyle) { |
176 element.style._clear(scope.propertyName(property)); | 184 element.style._clear(scope.propertyName(property)); |
177 } | 185 } |
178 }; | 186 }; |
179 | 187 |
180 if (WEB_ANIMATIONS_TESTING) | 188 if (WEB_ANIMATIONS_TESTING) |
181 testing.ensureStyleIsPatched = ensureStyleIsPatched; | 189 testing.ensureStyleIsPatched = ensureStyleIsPatched; |
182 | 190 |
183 })(webAnimationsMinifill, webAnimationsTesting); | 191 })(webAnimations1, webAnimationsTesting); |
OLD | NEW |