Chromium Code Reviews| Index: third_party/WebKit/Source/build/scripts/make_css_property_descriptor.py |
| diff --git a/third_party/WebKit/Source/build/scripts/make_css_property_descriptor.py b/third_party/WebKit/Source/build/scripts/make_css_property_descriptor.py |
| new file mode 100755 |
| index 0000000000000000000000000000000000000000..27355d3b9027f0fe35462a7d6ee79d63744a451a |
| --- /dev/null |
| +++ b/third_party/WebKit/Source/build/scripts/make_css_property_descriptor.py |
| @@ -0,0 +1,53 @@ |
| +#!/usr/bin/env python |
| +# Copyright 2016 The Chromium Authors. All rights reserved. |
| +# Use of this source code is governed by a BSD-style license that can be |
| +# found in the LICENSE file. |
| + |
| +import sys |
| + |
| +import in_generator |
| +import template_expander |
| +import make_style_builder |
| +from collections import namedtuple, defaultdict |
| + |
| + |
| +class CSSPropertyAPIWriter(make_style_builder.StyleBuilderWriter): |
| + def __init__(self, in_file_path): |
| + super(CSSPropertyAPIWriter, self).__init__(in_file_path) |
| + self._outputs = { |
| + 'CSSPropertyDescriptor.cpp': self.generate_property_descriptor_h, |
| + } |
| + |
| + # Temporary map of classname to list of propertyIDs. |
| + properties_for_class = defaultdict(list) |
| + for property in self._properties.values(): |
| + if property['api_class'] is None: |
| + continue |
| + classname = self.get_classname(property) |
| + properties_for_class[classname].append('CSSProperty' + property['upper_camel_name']) |
|
alancutter (OOO until 2018)
2016/12/13 05:55:34
Use property['property_id'] instead of constructin
aazzam
2016/12/13 21:47:52
done :)
|
| + |
| + # Stores a list of classes with elements (index, classname, [propertyIDs, ..]). |
| + self._api_classes = [] |
| + |
| + ApiClass = namedtuple('ApiClass', ('index', 'classname', 'property_ids')) |
| + for i, classname in enumerate(properties_for_class.keys()): |
| + self._api_classes.append(ApiClass(index=i + 1, classname=classname, property_ids=properties_for_class[classname])) |
| + |
| + # Gets the classname for a given property. |
| + def get_classname(self, property): |
| + if property['api_class'] is True: |
| + # This property had the generated_api_class flag set in CSSProperties.in. |
| + return 'CSSPropertyAPI' + property['upper_camel_name'] |
| + else: |
|
alancutter (OOO until 2018)
2016/12/13 05:55:34
No need for else after return.
aazzam
2016/12/13 21:47:52
done :)
|
| + # This property has a specified class name. |
| + assert isinstance(property['api_class'], str) |
| + return property['api_class'] |
| + |
| + @template_expander.use_jinja('CSSPropertyDescriptor.cpp.tmpl') |
| + def generate_property_descriptor_h(self): |
| + return { |
| + 'api_classes': self._api_classes, |
| + } |
| + |
| +if __name__ == '__main__': |
| + in_generator.Maker(CSSPropertyAPIWriter).main(sys.argv) |