OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # | 2 # |
3 # Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 3 # Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
4 # for details. All rights reserved. Use of this source code is governed by a | 4 # for details. All rights reserved. Use of this source code is governed by a |
5 # BSD-style license that can be found in the LICENSE file. | 5 # BSD-style license that can be found in the LICENSE file. |
6 | 6 |
7 """Generates CSSStyleDeclaration template file from css property definitions | 7 """Generates CSSStyleDeclaration template file from css property definitions |
8 defined in WebKit.""" | 8 defined in WebKit.""" |
9 | 9 |
10 import tempfile, os | 10 import tempfile, os |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 $endif | 110 $endif |
111 } | 111 } |
112 $if DARTIUM | 112 $if DARTIUM |
113 | 113 |
114 bool _hasProperty(String propertyName) => | 114 bool _hasProperty(String propertyName) => |
115 _blink.BlinkCSSStyleDeclaration.$__propertyQuery___Callback_1(this, proper
tyName); | 115 _blink.BlinkCSSStyleDeclaration.$__propertyQuery___Callback_1(this, proper
tyName); |
116 $endif | 116 $endif |
117 | 117 |
118 @DomName('CSSStyleDeclaration.setProperty') | 118 @DomName('CSSStyleDeclaration.setProperty') |
119 void setProperty(String propertyName, String value, [String priority]) { | 119 void setProperty(String propertyName, String value, [String priority]) { |
120 return _setPropertyHelper(_browserPropertyName(propertyName), | 120 if (_supportsProperty(_camelCase(propertyName))) { |
121 value, priority); | 121 return _setPropertyHelper(propertyName, value, priority); |
| 122 } else { |
| 123 return _setPropertyHelper(Device.cssPrefix + propertyName, value, |
| 124 priority); |
| 125 } |
122 } | 126 } |
123 | 127 |
124 String _browserPropertyName(String propertyName) { | |
125 String name = _readCache(propertyName); | |
126 if (name is String) return name; | |
127 if (_supportsProperty(_camelCase(propertyName))) { | |
128 name = propertyName; | |
129 } else { | |
130 name = Device.cssPrefix + propertyName; | |
131 } | |
132 _writeCache(propertyName, name); | |
133 return name; | |
134 } | |
135 | |
136 $if DART2JS | |
137 static final _propertyCache = JS('', '{}'); | |
138 static String _readCache(String key) => | |
139 JS('String|Null', '#[#]', _propertyCache, key); | |
140 static void _writeCache(String key, String value) { | |
141 JS('void', '#[#] = #', _propertyCache, key, value); | |
142 } | |
143 $else | |
144 static String _readCache(String key) => null; | |
145 static void _writeCache(String key, value) {} | |
146 $endif | |
147 | |
148 static String _camelCase(String hyphenated) { | 128 static String _camelCase(String hyphenated) { |
149 $if DART2JS | 129 $if DART2JS |
150 var replacedMs = JS('String', r'#.replace(/^-ms-/, "ms-")', hyphenated); | 130 var replacedMs = JS('String', r'#.replace(/^-ms-/, "ms-")', hyphenated); |
151 | 131 |
152 var fToUpper = const JS_CONST( | 132 var fToUpper = const JS_CONST( |
153 r'function(_, letter) { return letter.toUpperCase(); }'); | 133 r'function(_, letter) { return letter.toUpperCase(); }'); |
154 return JS('String', r'#.replace(/-([\da-z])/ig, #)', replacedMs, fToUpper); | 134 return JS('String', r'#.replace(/-([\da-z])/ig, #)', replacedMs, fToUpper); |
155 $else | 135 $else |
156 // The "ms" prefix is always lowercased. | 136 // The "ms" prefix is always lowercased. |
157 return hyphenated.replaceFirst(new RegExp('^-ms-'), 'ms-').replaceAllMapped( | 137 return hyphenated.replaceFirst(new RegExp('^-ms-'), 'ms-').replaceAllMapped( |
158 new RegExp('-([a-z]+)', caseSensitive: false), | 138 new RegExp('-([a-z]+)', caseSensitive: false), |
159 (match) => match[0][1].toUpperCase() + match[0].substring(2)); | 139 (match) => match[0][1].toUpperCase() + match[0].substring(2)); |
160 $endif | 140 $endif |
161 } | 141 } |
162 | 142 |
163 $if DART2JS | 143 $if DART2JS |
164 void _setPropertyHelper(String propertyName, String value, [String priority])
{ | 144 void _setPropertyHelper(String propertyName, String value, [String priority])
{ |
165 if (value == null) value = ''; | 145 // try/catch for IE9 which throws on unsupported values. |
166 if (priority == null) priority = ''; | 146 try { |
167 JS('void', '#.setProperty(#, #, #)', this, propertyName, value, priority); | 147 if (value == null) value = ''; |
| 148 if (priority == null) { |
| 149 priority = ''; |
| 150 } |
| 151 JS('void', '#.setProperty(#, #, #)', this, propertyName, value, priority); |
| 152 // Bug #2772, IE9 requires a poke to actually apply the value. |
| 153 if (JS('bool', '!!#.setAttribute', this)) { |
| 154 JS('void', '#.setAttribute(#, #)', this, propertyName, value); |
| 155 } |
| 156 } catch (e) {} |
168 } | 157 } |
169 | 158 |
170 /** | 159 /** |
171 * Checks to see if CSS Transitions are supported. | 160 * Checks to see if CSS Transitions are supported. |
172 */ | 161 */ |
173 static bool get supportsTransitions { | 162 static bool get supportsTransitions { |
174 return document.body.style.supportsProperty('transition'); | 163 return document.body.style.supportsProperty('transition'); |
175 } | 164 } |
176 $else | 165 $else |
177 void _setPropertyHelper(String propertyName, String value, [String priority])
{ | 166 void _setPropertyHelper(String propertyName, String value, [String priority])
{ |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 class_lines.append(annotated[base_css_name]) | 236 class_lines.append(annotated[base_css_name]) |
248 class_lines.append(""" | 237 class_lines.append(""" |
249 void set %s(String value) { | 238 void set %s(String value) { |
250 setProperty('%s', value, ''); | 239 setProperty('%s', value, ''); |
251 } | 240 } |
252 """ % (camel_case_name, css_name)) | 241 """ % (camel_case_name, css_name)) |
253 | 242 |
254 class_file.write(''.join(class_lines)); | 243 class_file.write(''.join(class_lines)); |
255 class_file.write('}\n') | 244 class_file.write('}\n') |
256 class_file.close() | 245 class_file.close() |
OLD | NEW |