Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(285)

Side by Side Diff: tools/dom/scripts/css_code_generator.py

Issue 1064783002: CssStyleDeclaration performance work (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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),
121 value, priority);
122 }
123
124 String _browserPropertyName(String propertyName) {
125 String name = _readCache(propertyName);
126 if (name is String) return name;
120 if (_supportsProperty(_camelCase(propertyName))) { 127 if (_supportsProperty(_camelCase(propertyName))) {
121 return _setPropertyHelper(propertyName, value, priority); 128 name = propertyName;
122 } else { 129 } else {
123 return _setPropertyHelper(Device.cssPrefix + propertyName, value, 130 name = Device.cssPrefix + propertyName;
124 priority);
125 } 131 }
132 _writeCache(propertyName, name);
133 return name;
126 } 134 }
127 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
128 static String _camelCase(String hyphenated) { 148 static String _camelCase(String hyphenated) {
129 $if DART2JS 149 $if DART2JS
130 var replacedMs = JS('String', r'#.replace(/^-ms-/, "ms-")', hyphenated); 150 var replacedMs = JS('String', r'#.replace(/^-ms-/, "ms-")', hyphenated);
131 151
132 var fToUpper = const JS_CONST( 152 var fToUpper = const JS_CONST(
133 r'function(_, letter) { return letter.toUpperCase(); }'); 153 r'function(_, letter) { return letter.toUpperCase(); }');
134 return JS('String', r'#.replace(/-([\da-z])/ig, #)', replacedMs, fToUpper); 154 return JS('String', r'#.replace(/-([\da-z])/ig, #)', replacedMs, fToUpper);
135 $else 155 $else
136 // The "ms" prefix is always lowercased. 156 // The "ms" prefix is always lowercased.
137 return hyphenated.replaceFirst(new RegExp('^-ms-'), 'ms-').replaceAllMapped( 157 return hyphenated.replaceFirst(new RegExp('^-ms-'), 'ms-').replaceAllMapped(
138 new RegExp('-([a-z]+)', caseSensitive: false), 158 new RegExp('-([a-z]+)', caseSensitive: false),
139 (match) => match[0][1].toUpperCase() + match[0].substring(2)); 159 (match) => match[0][1].toUpperCase() + match[0].substring(2));
140 $endif 160 $endif
141 } 161 }
142 162
143 $if DART2JS 163 $if DART2JS
144 void _setPropertyHelper(String propertyName, String value, [String priority]) { 164 void _setPropertyHelper(String propertyName, String value, [String priority]) {
145 // try/catch for IE9 which throws on unsupported values. 165 if (value == null) value = '';
146 try { 166 if (priority == null) priority = '';
147 if (value == null) value = ''; 167 JS('void', '#.setProperty(#, #, #)', this, propertyName, value, priority);
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) {}
157 } 168 }
158 169
159 /** 170 /**
160 * Checks to see if CSS Transitions are supported. 171 * Checks to see if CSS Transitions are supported.
161 */ 172 */
162 static bool get supportsTransitions { 173 static bool get supportsTransitions {
163 return document.body.style.supportsProperty('transition'); 174 return document.body.style.supportsProperty('transition');
164 } 175 }
165 $else 176 $else
166 void _setPropertyHelper(String propertyName, String value, [String priority]) { 177 void _setPropertyHelper(String propertyName, String value, [String priority]) {
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 class_lines.append(annotated[base_css_name]) 247 class_lines.append(annotated[base_css_name])
237 class_lines.append(""" 248 class_lines.append("""
238 void set %s(String value) { 249 void set %s(String value) {
239 setProperty('%s', value, ''); 250 setProperty('%s', value, '');
240 } 251 }
241 """ % (camel_case_name, css_name)) 252 """ % (camel_case_name, css_name))
242 253
243 class_file.write(''.join(class_lines)); 254 class_file.write(''.join(class_lines));
244 class_file.write('}\n') 255 class_file.write('}\n')
245 class_file.close() 256 class_file.close()
OLDNEW
« no previous file with comments | « tests/co19/co19-dart2js.status ('k') | tools/dom/templates/html/impl/impl_CSSStyleDeclaration.darttemplate » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698