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..6eac493b4fd76a1d6ddaed6df8bf09b9fd184522 |
| --- /dev/null |
| +++ b/third_party/WebKit/Source/build/scripts/make_css_property_descriptor.py |
| @@ -0,0 +1,47 @@ |
| +#!/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 |
| + classnames = defaultdict(list) |
| + for property in self._properties.values(): |
| + if property['api_class'] is not None: |
|
alancutter (OOO until 2018)
2016/12/13 03:29:54
The indent level is getting a bit much here. Inver
aazzam
2016/12/13 05:01:09
done :)
|
| + if property['api_class'] is True: |
| + # This property had the generated_api_class flag set in CSSProperties.in, |
| + # but did not specify a class name. |
| + classnames["CSSPropertyAPI" + property['upper_camel_name']].append("CSSProperty" + property['upper_camel_name']) |
| + elif isinstance(property['api_class'], str): |
|
alancutter (OOO until 2018)
2016/12/13 03:29:54
Assert this condition, the else: case should never
aazzam
2016/12/13 05:01:09
done :)
|
| + # This property has a specified class name. |
| + classnames[property['api_class']].append("CSSProperty" + property['upper_camel_name']) |
|
alancutter (OOO until 2018)
2016/12/13 03:29:54
I think something like
classname = get_classname(a
|
| + |
| + # Stores a list of classes with elements (index, classname, [propertyIDs, ..]) |
| + self._api_classes = [] |
| + |
| + api_class = namedtuple('api_class', ('index', 'classname', 'propertyIDs')) |
|
alancutter (OOO until 2018)
2016/12/13 03:29:54
Use CamelCase for types.
I don't think a namedtup
aazzam
2016/12/13 05:01:09
The reason we thought of using a namedtuple instea
|
| + for i, classname in enumerate(classnames.keys()): |
| + self._api_classes.append(api_class(index=i + 1, classname=classname, propertyIDs=classnames[classname])) |
|
alancutter (OOO until 2018)
2016/12/13 03:29:54
Use snake_case for propertyIDs.
aazzam
2016/12/13 05:01:09
done! :)
|
| + |
| + @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) |