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

Unified Diff: client/base/scripts/css_code_generator.py

Issue 8360025: Move the individual property definitions from client/base/Css to CSSStyleDeclaration. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 9 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: client/base/scripts/css_code_generator.py
diff --git a/client/base/scripts/css_code_generator.py b/client/base/scripts/css_code_generator.py
index ff06954612556d8d37e114f33b61be73081b91e4..d5cbfda85f6d10456cbc0d101319b05f7ae4b8d1 100644
--- a/client/base/scripts/css_code_generator.py
+++ b/client/base/scripts/css_code_generator.py
@@ -4,14 +4,15 @@
# for details. All rights reserved. Use of this source code is governed by a
# BSD-style license that can be found in the LICENSE file.
Jacob 2011/10/21 17:12:23 Move this script to the client/html/scripts direct
nweiz 2011/10/24 19:48:28 Done.
-"""Generates Css.dart from css property definitions defined in WebKit."""
+"""Generates CSSStyleDeclaration from css property definitions defined in WebKit."""
import tempfile, os
COMMENT_LINE_PREFIX = ' * '
SOURCE_PATH = 'Source/WebCore/css/CSSPropertyNames.in'
INPUT_URL = 'http://trac.webkit.org/export/latest/trunk/%s' % SOURCE_PATH
-OUTPUT_FILE = '../Css.dart'
+INTERFACE_FILE = '../../html/src/CSSStyleDeclaration.dart'
+CLASS_FILE = '../../html/src/CSSStyleDeclarationWrappingImplementation.dart'
def main():
_, css_names_file = tempfile.mkstemp('.CSSPropertyNames.in')
@@ -19,7 +20,7 @@ def main():
if os.system('wget %s -O %s' % (INPUT_URL, css_names_file)):
return 1
generate_code(css_names_file)
- print 'Successfully generated ' + OUTPUT_FILE
+ print 'Successfully generated %s and %s' % (INTERFACE_FILE, CLASS_FILE)
finally:
os.remove(css_names_file)
@@ -44,9 +45,10 @@ def generate_code(input_path):
and not d.startswith('//')
and not '=' in d]
- output_file = open(OUTPUT_FILE, 'w')
+ interface_file = open(INTERFACE_FILE, 'w')
+ class_file = open(CLASS_FILE, 'w')
- output_file.write("""
+ interface_file.write("""
// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
@@ -59,15 +61,52 @@ def generate_code(input_path):
// TODO(jacobr): add versions that take numeric values in px, miliseconds, etc.
-/**
- * Browser neutral and typesafe class for setting CSS styles from Dart.
- * This class smoothes over browser differences.
- */
-class Css {
+interface CSSStyleDeclaration {
+
+ String get cssText();
+
+ void set cssText(String value);
+
+ int get length();
+
+ CSSRule get parentRule();
+
+ CSSValue getPropertyCSSValue(String propertyName);
+
+ String getPropertyPriority(String propertyName);
+
+ String getPropertyShorthand(String propertyName);
+
+ String getPropertyValue(String propertyName);
+
+ bool isPropertyImplicit(String propertyName);
+
+ String item(int index);
+
+ String removeProperty(String propertyName);
+
+ void setProperty(String propertyName, String value, [String priority]);
+
+""".lstrip() % SOURCE_PATH)
+
+
+ class_file.write("""
+// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+// WARNING: Do not edit.
+// This file was generated by base/scripts/css_code_generator.py
Jacob 2011/10/21 17:12:23 update this directory as part of the move
nweiz 2011/10/24 19:48:28 Done.
+
+// Source of CSS properties:
+// %s
+
+// TODO(jacobr): add versions that take numeric values in px, miliseconds, etc.
+
+class CSSStyleDeclarationWrappingImplementation extends DOMWrapperBase implements CSSStyleDeclaration {
static String _cachedBrowserPrefix;
- final CSSStyleDeclaration raw;
- Css(CSSStyleDeclaration this.raw) { }
+ CSSStyleDeclarationWrappingImplementation._wrap(ptr) : super._wrap(ptr) {}
static String get _browserPrefix() {
if (_cachedBrowserPrefix === null) {
@@ -80,16 +119,59 @@ class Css {
}
return _cachedBrowserPrefix;
}
-""".lstrip() % SOURCE_PATH);
- static_method_lines = [];
- property_lines = [];
+ String get cssText() { return _ptr.cssText; }
+
+ void set cssText(String value) { _ptr.cssText = value; }
+
+ int get length() { return _ptr.length; }
+
+ CSSRule get parentRule() { return LevelDom.wrapCSSRule(_ptr.parentRule); }
+
+ CSSValue getPropertyCSSValue(String propertyName) {
+ return LevelDom.wrapCSSValue(_ptr.getPropertyCSSValue(propertyName));
+ }
+
+ String getPropertyPriority(String propertyName) {
+ return _ptr.getPropertyPriority(propertyName);
+ }
+
+ String getPropertyShorthand(String propertyName) {
+ return _ptr.getPropertyShorthand(propertyName);
+ }
+
+ String getPropertyValue(String propertyName) {
+ return _ptr.getPropertyValue(propertyName);
+ }
+
+ bool isPropertyImplicit(String propertyName) {
+ return _ptr.isPropertyImplicit(propertyName);
+ }
+
+ String item(int index) {
+ return _ptr.item(index);
+ }
+
+ String removeProperty(String propertyName) {
+ return _ptr.removeProperty(propertyName);
+ }
+
+ void setProperty(String propertyName, String value, [String priority = '']) {
+ _ptr.setProperty(propertyName, value, priority);
+ }
+
+ String get typeName() { return "CSSStyleDeclaration"; }
+
+""".lstrip() % SOURCE_PATH)
+
+ interface_lines = [];
+ class_lines = [];
seen = set()
for prop in sorted(data, key=lambda p: camelCaseName(p)):
camel_case_name = camelCaseName(prop)
upper_camel_case_name = camel_case_name[0].upper() + camel_case_name[1:];
- css_name = prop.replace('-webkit-', '${_browserPrefix}')
+ css_name = prop.replace('-webkit-', '${CSSStyleDeclarationWrappingImplementation._browserPrefix}')
base_css_name = prop.replace('-webkit-', '')
if base_css_name in seen:
@@ -98,42 +180,40 @@ class Css {
comment = ' /** %s the value of "' + base_css_name + '" */'
- static_method_lines.append('\n');
- static_method_lines.append(comment % 'Gets')
- static_method_lines.append("""
- static String get%s(CSSStyleDeclaration style) {
- return style.getPropertyValue('%s');
- }
+ interface_lines.append(comment % 'Gets')
+ interface_lines.append("""
+ String get %s();
-""" % (upper_camel_case_name, css_name))
+""" % camel_case_name)
- static_method_lines.append(comment % 'Sets')
- static_method_lines.append("""
- static void set%s(CSSStyleDeclaration style, String value) {
- style.setProperty('%s', value, '');
- }
-""" % (upper_camel_case_name, css_name))
+ interface_lines.append(comment % 'Sets')
+ interface_lines.append("""
+ void set %s(String value);
- property_lines.append('\n')
- property_lines.append(comment % 'Gets')
- property_lines.append("""
- String get %s() {
- return get%s(raw);
- }
+""" % camel_case_name)
+
+ class_lines.append('\n');
+ class_lines.append(comment % 'Gets')
+ class_lines.append("""
+ String get %s() =>
+ getPropertyValue('%s');
-""" % (camel_case_name, upper_camel_case_name))
+""" % (camel_case_name, css_name))
- property_lines.append(comment % 'Sets')
- property_lines.append("""
+ class_lines.append(comment % 'Sets')
+ class_lines.append("""
void set %s(String value) {
- set%s(raw, value);
+ setProperty('%s', value, '');
}
-""" % (camel_case_name, upper_camel_case_name))
+""" % (camel_case_name, css_name))
+
+ interface_file.write(''.join(interface_lines));
+ interface_file.write('}\n')
+ interface_file.close()
- output_file.write(''.join(static_method_lines));
- output_file.write(''.join(property_lines));
- output_file.write('}\n')
- output_file.close()
+ class_file.write(''.join(class_lines));
+ class_file.write('}\n')
+ class_file.close()
if __name__ == '__main__':
main()

Powered by Google App Engine
This is Rietveld 408576698