Index: tools/dom/scripts/css_code_generator.py |
diff --git a/tools/dom/scripts/css_code_generator.py b/tools/dom/scripts/css_code_generator.py |
index a290c5fc83d1a253765fe5df0c465876cc127fd1..0b79aae415a617e6d7988ab789bf8b2ec3558a26 100644 |
--- a/tools/dom/scripts/css_code_generator.py |
+++ b/tools/dom/scripts/css_code_generator.py |
@@ -7,7 +7,7 @@ |
"""Generates CSSStyleDeclaration template file from css property definitions |
defined in WebKit.""" |
-import tempfile, os |
+import tempfile, os, re |
COMMENT_LINE_PREFIX = ' * ' |
# TODO(efortuna): Pull from DEPS so that we have latest css *in sync* with our |
@@ -16,6 +16,16 @@ SOURCE_PATH = 'CSSPropertyNames.in' |
#SOURCE_PATH = 'Source/WebCore/css/CSSPropertyNames.in' |
TEMPLATE_FILE = '../templates/html/impl/impl_CSSStyleDeclaration.darttemplate' |
+# These are the properties that are supported on all Dart project supported |
+# browsers as camelCased names on the CssStyleDeclaration. |
+BROWSER_PATHS = [ |
+ 'cssProperties.ie9.txt', |
Alan Knight
2015/03/04 17:49:32
Shouldn't we be doing ie10 and 11 rather than 9 an
sra1
2015/03/25 05:23:35
Yes, but to not include ie9 would break ie9 which
Alan Knight
2015/03/25 17:51:05
OK. But shouldn't there be IE11?
|
+ 'cssProperties.ie10.txt', |
+ 'cssProperties.ff36.txt', |
+ 'cssProperties.chrome40.txt', |
+ 'cssProperties.safari-7.1.3.txt', |
+ ] |
+ |
# Supported annotations for any specific CSS properties. |
annotated = { |
'transition': '''@SupportedBrowser(SupportedBrowser.CHROME) |
@@ -24,6 +34,12 @@ annotated = { |
@SupportedBrowser(SupportedBrowser.SAFARI)''' |
} |
+class Error: |
+ def __init__(self, message): |
+ self.message = message |
+ def __repr__(self): |
+ return self.message |
+ |
def camelCaseName(name): |
"""Convert a CSS property name to a lowerCamelCase name.""" |
name = name.replace('-webkit-', '') |
@@ -35,17 +51,35 @@ def camelCaseName(name): |
words.append(word) |
return ''.join(words) |
+def dashifyName(camelName): |
+ def fix(match): |
+ return '-' + match.group(0).lower() |
+ return re.sub(r'[A-Z]', fix, camelName) |
+ |
+def isCommentLine(line): |
+ return line.strip() == '' or line.startswith('#') or line.startswith('//') |
+ |
+def readCssProperties(filename): |
+ data = open(filename).readlines() |
+ data = sorted([d.strip() for d in set(data) if not isCommentLine(d)]) |
+ return data |
+ |
def GenerateCssTemplateFile(): |
data = open(SOURCE_PATH).readlines() |
# filter CSSPropertyNames.in to only the properties |
# TODO(efortuna): do we also want CSSPropertyNames.in? |
- data = [d[:-1] for d in data |
- if len(d) > 1 |
- and not d.startswith('#') |
- and not d.startswith('//') |
+ data = [d.strip() for d in data |
+ if not isCommentLine(d) |
and not '=' in d] |
+ browser_props = [readCssProperties(file) for file in BROWSER_PATHS] |
+ universal_properties = reduce( |
+ lambda a, b: set(a).intersection(b), browser_props) |
+ universal_properties = universal_properties.difference(['cssText']) |
+ universal_properties = universal_properties.intersection( |
+ map(camelCaseName, data)) |
+ |
class_file = open(TEMPLATE_FILE, 'w') |
class_file.write(""" |
@@ -60,8 +94,11 @@ def GenerateCssTemplateFile(): |
// %s |
part of $LIBRARYNAME; |
+""" % SOURCE_PATH) |
-$(ANNOTATIONS)$(NATIVESPEC)$(CLASS_MODIFIERS) class $CLASSNAME $EXTENDS with |
+ |
+ class_file.write(""" |
+$(ANNOTATIONS)$(NATIVESPEC)$(CLASS_MODIFIERS)class $CLASSNAME $EXTENDS with |
$(CLASSNAME)Base $IMPLEMENTS { |
factory $CLASSNAME() => new CssStyleDeclaration.css(''); |
@@ -176,6 +213,23 @@ $else |
static bool get supportsTransitions => true; |
$endif |
$!MEMBERS |
+$if DART2JS |
+""") |
+ |
+ for camelName in sorted(universal_properties): |
+ property = dashifyName(camelName) |
+ class_file.write(""" |
+ /** Gets the value of "%s" */ |
+ String get %s => JS('String', '#.%s', this); |
+ |
+ /** Sets the value of "%s" */ |
+ void set %s(String value) { |
+ JS('', '#.%s = #', this, value == null ? '' : value); |
+ } |
+ """ % (property, camelName, camelName, property, camelName, camelName)) |
+ |
+ class_file.write(""" |
+$endif |
} |
class _CssStyleDeclarationSet extends Object with CssStyleDeclarationBase { |
@@ -205,12 +259,12 @@ class _CssStyleDeclarationSet extends Object with CssStyleDeclarationBase { |
abstract class CssStyleDeclarationBase { |
String getPropertyValue(String propertyName); |
void setProperty(String propertyName, String value, [String priority]); |
-""" % SOURCE_PATH) |
+""") |
class_lines = []; |
seen = set() |
- for prop in sorted(data, key=lambda p: camelCaseName(p)): |
+ for prop in sorted(data, key=camelCaseName): |
camel_case_name = camelCaseName(prop) |
upper_camel_case_name = camel_case_name[0].upper() + camel_case_name[1:]; |
css_name = prop.replace('-webkit-', '') |