6"""Generates CSSStyleDeclaration template file from css property definitions
11COMMENT_LINE_PREFIX =
' * '
14SOURCE_PATH =
'CSSPropertyNames.in'
16TEMPLATE_FILE =
'../templates/html/impl/impl_CSSStyleDeclaration.darttemplate'
22 'cssProperties.CSS21.txt',
23 'cssProperties.ie9.txt',
24 'cssProperties.ie10.txt',
25 'cssProperties.ie11.txt',
26 'cssProperties.ff36.txt',
27 'cssProperties.chrome40.txt',
28 'cssProperties.safari-7.1.3.txt',
29 'cssProperties.mobileSafari-8.2.txt',
30 'cssProperties.iPad4Air.onGoogleSites.txt',
36 '''@SupportedBrowser(SupportedBrowser.CHROME)
37 @SupportedBrowser(SupportedBrowser.FIREFOX)
38 @SupportedBrowser(SupportedBrowser.IE, '10')
39 @SupportedBrowser(SupportedBrowser.SAFARI)'''
53 """Convert a CSS property name to a lowerCamelCase name."""
54 name = name.replace(
'-webkit-',
'')
56 for word
in name.split(
'-'):
58 words.append(word.title())
67 return '-' + match.group(0).
lower()
69 return re.sub(
r'[A-Z]', fix, camelName)
73 return line.strip() ==
'' or line.startswith(
'#')
or line.startswith(
'//')
87 data = [d.strip()
for d
in data
if not isCommentLine(d)
and not '=' in d]
90 universal_properties = set.intersection(*browser_props)
91 universal_properties = universal_properties.difference([
'cssText'])
92 universal_properties = universal_properties.intersection(
93 list(
map(camelCaseName, data)))
95 class_file = open(TEMPLATE_FILE,
'w')
98// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
99// for details. All rights reserved. Use of this source code
is governed by a
100// BSD-style license that can be found
in the LICENSE file.
102// WARNING: DO NOT EDIT THIS TEMPLATE FILE.
103// The template file was generated by scripts/css_code_generator.py
105// Source of CSS properties:
112$(ANNOTATIONS)$(NATIVESPEC)$(CLASS_MODIFIERS)class $CLASSNAME $EXTENDS with
113 $(CLASSNAME)Base $IMPLEMENTS {
114 factory $CLASSNAME() => new CssStyleDeclaration.css('');
116 factory $CLASSNAME.css(String css) {
117 final style = new DivElement().style;
122 /// Returns the value of the property
if the provided *CSS* property
123 /// name
is supported on this element
and if the value
is set. Otherwise
124 /// returns an empty string.
126 /// Please note the property name uses camelCase,
not-hyphens.
127 String getPropertyValue(String propertyName) {
128 return _getPropertyValueHelper(propertyName);
131 String _getPropertyValueHelper(String propertyName) {
132 return _getPropertyValue(_browserPropertyName(propertyName));
136 * Returns true
if the provided *CSS* property name
is supported on this
139 * Please note the property name camelCase,
not-hyphens. This
140 * method returns true
if the property
is accessible via an unprefixed _or_
143 bool supportsProperty(String propertyName) {
144 return _supportsProperty(propertyName) ||
145 _supportsProperty(_camelCase(
"${Device.cssPrefix}$propertyName"));
148 bool _supportsProperty(String propertyName) {
149 return JS(
'bool',
'# in #', propertyName, this);
153 void setProperty(String propertyName, String$NULLABLE value,
154 [String$NULLABLE priority]) {
155 return _setPropertyHelper(_browserPropertyName(propertyName),
159 String _browserPropertyName(String propertyName) {
160 String$NULLABLE name = _readCache(propertyName);
161 if (name
is String)
return name;
162 name = _supportedBrowserPropertyName(propertyName);
163 _writeCache(propertyName, name);
167 String _supportedBrowserPropertyName(String propertyName) {
168 if (_supportsProperty(_camelCase(propertyName))) {
171 var prefixed =
"${Device.cssPrefix}$propertyName";
172 if (_supportsProperty(prefixed)) {
175 // May be a CSS variable, just use it
as provided.
179 static final _propertyCache = JS(
'',
'{}');
180 static String$NULLABLE _readCache(String key) =>
181 JS(
'String|Null',
'#[#]', _propertyCache, key);
182 static void _writeCache(String key, String value) {
183 JS(
'void',
'#[#] = #', _propertyCache, key, value);
186 static String _camelCase(String hyphenated) {
187 var replacedMs = JS(
'String',
r'#.replace(/^-ms-/, "ms-")', hyphenated);
190 r'#.replace(/-([\da-z])/ig,'
191 r'function(_, letter) { return letter.toUpperCase();})',
195 void _setPropertyHelper(String propertyName, String$NULLABLE value,
196 [String$NULLABLE priority]) {
197 if (value == null) value =
'';
198 if (priority == null) priority =
'';
199 JS(
'void',
'#.setProperty(#, #, #)', this, propertyName, value, priority);
203 * Checks to see
if CSS Transitions are supported.
205 static bool get supportsTransitions {
206 return document.body$NULLASSERT.style.supportsProperty(
'transition');
211 for camelName
in sorted(universal_properties):
214 /** Gets the value of "%s" */
215 String get %s => this._%s;
217 /** Sets the value of
"%s" */
218 set %
s(String$NULLABLE value) {
219 _%s = value == null ?
'' : value;
223 String get _%s native;
226 set _%
s(String value) native;
227 """ % (property, camelName, camelName, property, camelName, camelName,
228 camelName, camelName, camelName, camelName))
233class _CssStyleDeclarationSet extends Object with CssStyleDeclarationBase {
234 final Iterable<Element> _elementIterable;
235 Iterable<CssStyleDeclaration> _elementCssStyleDeclarationSetIterable;
237 _CssStyleDeclarationSet(this._elementIterable)
238 : _elementCssStyleDeclarationSetIterable =
239 new List.of(_elementIterable).map((e) => e.style);
241 String getPropertyValue(String propertyName) =>
242 _elementCssStyleDeclarationSetIterable.first.getPropertyValue(
245 void setProperty(String propertyName, String$NULLABLE value,
246 [String$NULLABLE priority]) {
247 _elementCssStyleDeclarationSetIterable.forEach((e) =>
248 e.setProperty(propertyName, value, priority));
254 void _setAll(String propertyName, String$NULLABLE value) {
255 value = value == null ? '' : value;
256 for (Element element
in _elementIterable) {
257 JS(
'void',
'#.style[#] = #', element, propertyName, value);
262 for camelName
in sorted(universal_properties):
265 /** Sets the value of "%s" */
266 set %
s(String value) {
267 _setAll(
'%s', value);
269 """ % (property, camelName, camelName))
273 // Important note: CssStyleDeclarationSet does NOT implement every method
274 // available in CssStyleDeclaration. Some of the methods don
't make so much
275 // sense in terms of having a reasonable value to
return when you
're
276 // considering a list of Elements. You will need to manually add any of the
277 // items in the MEMBERS set
if you want that functionality.
280abstract mixin
class CssStyleDeclarationBase {
281 String getPropertyValue(String propertyName);
282 void setProperty(String propertyName, String$NULLABLE value,
283 [String$NULLABLE priority]);
289 for prop
in sorted(data, key=camelCaseName):
291 upper_camel_case_name = camel_case_name[0].upper() + camel_case_name[1:]
292 css_name = prop.replace(
'-webkit-',
'')
293 base_css_name = prop.replace(
'-webkit-',
'')
295 if base_css_name
in seen
or base_css_name.startswith(
'-internal'):
297 seen.add(base_css_name)
299 comment =
' /** %s the value of "' + base_css_name +
'" */'
300 class_lines.append(
'\n')
301 class_lines.append(comment %
'Gets')
302 if base_css_name
in annotated:
303 class_lines.append(annotated[base_css_name])
304 class_lines.append(
"""
306 getPropertyValue('%s');
308""" % (camel_case_name, css_name))
310 class_lines.append(comment % 'Sets')
311 if base_css_name
in annotated:
312 class_lines.append(annotated[base_css_name])
313 class_lines.append(
"""
314 set %s(String value) {
315 setProperty('%s', value,
'');
317""" % (camel_case_name, css_name))
319 class_file.write(''.
join(class_lines))
320 class_file.write(
'}\n')
def __init__(self, message)
static void readlines(const void *data, size_t size, F f)
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not set
def dashifyName(camelName)
def GenerateCssTemplateFile()
def readCssProperties(filename)
SI auto map(std::index_sequence< I... >, Fn &&fn, const Args &... args) -> skvx::Vec< sizeof...(I), decltype(fn(args[0]...))>
static SkString join(const CommandLineFlags::StringArray &)