Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Functions | Variables
scripts.prototype_css_generator Namespace Reference

Classes

class  Error
 

Functions

 camelCaseName (name)
 
 dashifyName (camelName)
 
 isCommentLine (line)
 
 readCssProperties (filename)
 
 main ()
 

Variables

str COMMENT_LINE_PREFIX = ' * '
 
str SOURCE_PATH = 'CSSPropertyNames.in'
 
str OUTPUT_FILE = 'prototype_css_properties.dart'
 
list BROWSER_PATHS
 
dict annotated
 

Detailed Description

Generates CssStyleDeclaration extension with all property getters and setters
from css property definitions defined in WebKit.

Function Documentation

◆ camelCaseName()

scripts.prototype_css_generator.camelCaseName (   name)
Convert a CSS property name to a lowerCamelCase name.

Definition at line 50 of file prototype_css_generator.py.

50def camelCaseName(name):
51 """Convert a CSS property name to a lowerCamelCase name."""
52 name = name.replace('-webkit-', '')
53 words = []
54 for word in name.split('-'):
55 if words:
56 words.append(word.title())
57 else:
58 words.append(word)
59 return ''.join(words)
60
61

◆ dashifyName()

scripts.prototype_css_generator.dashifyName (   camelName)

Definition at line 62 of file prototype_css_generator.py.

62def dashifyName(camelName):
63
64 def fix(match):
65 return '-' + match.group(0).lower()
66
67 return re.sub(r'[A-Z]', fix, camelName)
68
69

◆ isCommentLine()

scripts.prototype_css_generator.isCommentLine (   line)

Definition at line 70 of file prototype_css_generator.py.

70def isCommentLine(line):
71 return line.strip() == '' or line.startswith('#') or line.startswith('//')
72
73

◆ main()

scripts.prototype_css_generator.main ( )

Definition at line 80 of file prototype_css_generator.py.

80def main():
81 data = open(SOURCE_PATH).readlines()
82 data = [d.strip() for d in data if not isCommentLine(d) and not '=' in d]
83
84 browser_props = [set(readCssProperties(file)) for file in BROWSER_PATHS]
85 universal_properties = set.intersection(*browser_props)
86 universal_properties = universal_properties.difference(['cssText'])
87 universal_properties = universal_properties.intersection(
88 list(map(camelCaseName, data)))
89
90 output_file = open(OUTPUT_FILE, 'w')
91 output_file.write("""
92/// Exposing all the extra CSS property getters and setters.
93@JS()
94library dart.css_properties;
95
96import 'dart:_js_annotations';
97import 'dart:_js_bindings' as js_bindings;
98import 'dart:html_common';
99
100@JS()
101@staticInterop
102class CssStyleDeclaration implements js_bindings.CSSStyleDeclaration {}
103
104extension CssStyleDeclarationView on CssStyleDeclaration {
105 // dart:html requires a `String?` type for `value`.
106 external Object setProperty(String property, String? value,
107 [String? priority = '']);
108
109 // ##### Universal property getters and setters #####
110 """)
111
112 for camelName in sorted(universal_properties):
113 property = dashifyName(camelName)
114 output_file.write("""
115 /** Gets the value of "%s" */
116 String get %s => this._%s;
117
118 /** Sets the value of "%s" */
119 set %s(String? value) {
120 _%s = value == null ? '' : value;
121 }
122
123 @JS('%s')
124 external String get _%s;
125
126 @JS('%s')
127 external set _%s(String value);
128 """ % (property, camelName, camelName, property, camelName, camelName,
129 camelName, camelName, camelName, camelName))
130
131 output_file.write("""
132
133 // ##### Non-universal property getters and setters #####
134
135""")
136
137 property_lines = []
138
139 seen = set()
140 for prop in sorted(data, key=camelCaseName):
141 camel_case_name = camelCaseName(prop)
142 upper_camel_case_name = camel_case_name[0].upper() + camel_case_name[1:]
143 css_name = prop.replace('-webkit-', '')
144 base_css_name = prop.replace('-webkit-', '')
145
146 if base_css_name in seen or base_css_name.startswith(
147 '-internal') or camel_case_name in universal_properties:
148 continue
149 seen.add(base_css_name)
150
151 comment = ' /** %s the value of "' + base_css_name + '" */'
152 property_lines.append('\n')
153 property_lines.append(comment % 'Gets')
154 if base_css_name in annotated:
155 property_lines.append(annotated[base_css_name])
156 property_lines.append("""
157 String get %s =>
158 getPropertyValue('%s');
159
160""" % (camel_case_name, css_name))
161
162 property_lines.append(comment % 'Sets')
163 if base_css_name in annotated:
164 property_lines.append(annotated[base_css_name])
165 property_lines.append("""
166 set %s(String value) {
167 setProperty('%s', value, '');
168 }
169""" % (camel_case_name, css_name))
170
171 output_file.write(''.join(property_lines))
172 output_file.write('}\n')
173 output_file.close()
174
175
static void readlines(const void *data, size_t size, F f)
Definition editor.cpp:30
Definition main.py:1

◆ readCssProperties()

scripts.prototype_css_generator.readCssProperties (   filename)

Definition at line 74 of file prototype_css_generator.py.

74def readCssProperties(filename):
75 data = open(filename).readlines()
76 data = sorted([d.strip() for d in set(data) if not isCommentLine(d)])
77 return data
78
79

Variable Documentation

◆ annotated

dict scripts.prototype_css_generator.annotated
Initial value:
1= {
2 'transition':
3
4}

Definition at line 31 of file prototype_css_generator.py.

◆ BROWSER_PATHS

list scripts.prototype_css_generator.BROWSER_PATHS
Initial value:
1= [
2 'cssProperties.CSS21.txt', # Remove when we have samples from all browsers.
3 'cssProperties.ie9.txt',
4 'cssProperties.ie10.txt',
5 'cssProperties.ie11.txt',
6 'cssProperties.ff36.txt',
7 'cssProperties.chrome40.txt',
8 'cssProperties.safari-7.1.3.txt',
9 'cssProperties.mobileSafari-8.2.txt',
10 'cssProperties.iPad4Air.onGoogleSites.txt',
11]

Definition at line 18 of file prototype_css_generator.py.

◆ COMMENT_LINE_PREFIX

str scripts.prototype_css_generator.COMMENT_LINE_PREFIX = ' * '

Definition at line 11 of file prototype_css_generator.py.

◆ OUTPUT_FILE

str scripts.prototype_css_generator.OUTPUT_FILE = 'prototype_css_properties.dart'

Definition at line 13 of file prototype_css_generator.py.

◆ SOURCE_PATH

str scripts.prototype_css_generator.SOURCE_PATH = 'CSSPropertyNames.in'

Definition at line 12 of file prototype_css_generator.py.