| 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 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 void setProperty(String propertyName, String value, [String priority]) { | 119 void setProperty(String propertyName, String value, [String priority]) { |
| 120 if (_supportsProperty(_camelCase(propertyName))) { | 120 if (_supportsProperty(_camelCase(propertyName))) { |
| 121 return _setPropertyHelper(propertyName, value, priority); | 121 return _setPropertyHelper(propertyName, value, priority); |
| 122 } else { | 122 } else { |
| 123 return _setPropertyHelper(Device.cssPrefix + propertyName, value, | 123 return _setPropertyHelper(Device.cssPrefix + propertyName, value, |
| 124 priority); | 124 priority); |
| 125 } | 125 } |
| 126 } | 126 } |
| 127 | 127 |
| 128 String _camelCase(String hyphenated) { | 128 String _camelCase(String hyphenated) { |
| 129 bool firstWord = true; | 129 // The "ms" prefix is always lowercased. |
| 130 return hyphenated.splitMapJoin('-', onMatch : (_) => '', | 130 return hyphenated.replaceFirst(new RegExp('^-ms-'), 'ms-').replaceAllMapped( |
| 131 onNonMatch : (String word) { | 131 new RegExp('-([a-z]+)', caseSensitive: false), |
| 132 if (word.length > 0) { | 132 (match) => match[0][1].toUpperCase() + match[0].substring(2)); |
| 133 if (firstWord) { | |
| 134 firstWord = false; | |
| 135 return word; | |
| 136 } | |
| 137 return word[0].toUpperCase() + word.substring(1); | |
| 138 } | |
| 139 return ''; | |
| 140 }); | |
| 141 } | 133 } |
| 142 | 134 |
| 143 $if DART2JS | 135 $if DART2JS |
| 144 void _setPropertyHelper(String propertyName, String value, [String priority])
{ | 136 void _setPropertyHelper(String propertyName, String value, [String priority])
{ |
| 145 // try/catch for IE9 which throws on unsupported values. | 137 // try/catch for IE9 which throws on unsupported values. |
| 146 try { | 138 try { |
| 147 if (value == null) value = ''; | 139 if (value == null) value = ''; |
| 148 if (priority == null) { | 140 if (priority == null) { |
| 149 priority = ''; | 141 priority = ''; |
| 150 } | 142 } |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 class_lines.append(annotated[base_css_name]) | 228 class_lines.append(annotated[base_css_name]) |
| 237 class_lines.append(""" | 229 class_lines.append(""" |
| 238 void set %s(String value) { | 230 void set %s(String value) { |
| 239 setProperty('%s', value, ''); | 231 setProperty('%s', value, ''); |
| 240 } | 232 } |
| 241 """ % (camel_case_name, css_name)) | 233 """ % (camel_case_name, css_name)) |
| 242 | 234 |
| 243 class_file.write(''.join(class_lines)); | 235 class_file.write(''.join(class_lines)); |
| 244 class_file.write('}\n') | 236 class_file.write('}\n') |
| 245 class_file.close() | 237 class_file.close() |
| OLD | NEW |