OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2016 The Chromium Authors. All rights reserved. | 2 # Copyright 2016 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 import sys | 6 import sys |
7 | 7 |
8 import css_properties | 8 import css_properties |
9 import json5_generator | 9 import json5_generator |
10 from name_utilities import enum_for_css_keyword | 10 from name_utilities import enum_for_css_keyword |
11 import template_expander | 11 import template_expander |
12 | 12 |
13 | 13 |
14 class CSSOMTypesWriter(css_properties.CSSProperties): | 14 class CSSOMTypesWriter(css_properties.CSSProperties): |
15 """ | 15 """ |
16 Generates CSSOMTypes.cpp and CSSOMKeywords.cpp. These classes provide | 16 Generates CSSOMTypes.cpp and CSSOMKeywords.cpp. These classes provide |
17 utility methods for determining whether a given CSSStyleValue or | 17 utility methods for determining whether a given CSSStyleValue or |
18 CSSKeywordValue is valid for a given CSS property. The header files live in | 18 CSSKeywordValue is valid for a given CSS property. The header files live in |
19 core/css/cssom. | 19 core/css/cssom. |
20 """ | 20 """ |
21 def __init__(self, json5_file_path): | 21 def __init__(self, json5_file_path): |
22 super(CSSOMTypesWriter, self).__init__(json5_file_path) | 22 super(CSSOMTypesWriter, self).__init__(json5_file_path) |
23 | 23 |
24 for property in self._properties.values(): | 24 for property in self._properties.values(): |
25 types = [] | 25 types = [] |
26 # Expand types | 26 # Expand types |
27 for singleType in property['typedom_types']: | 27 for singleType in property['typedom_types']: |
28 if singleType == 'Length': | 28 if singleType == 'Image': |
29 types.append('SimpleLength') | |
30 types.append('CalcLength') | |
31 elif singleType == 'Image': | |
32 types.append('URLImage') | 29 types.append('URLImage') |
33 else: | 30 else: |
34 types.append(singleType) | 31 types.append(singleType) |
35 property['typedom_types'] = types | 32 property['typedom_types'] = types |
36 | 33 |
37 # Generate Keyword ID values from keywords. | 34 # Generate Keyword ID values from keywords. |
38 property['keywordIDs'] = map( | 35 property['keywordIDs'] = map( |
39 enum_for_css_keyword, property['keywords']) | 36 enum_for_css_keyword, property['keywords']) |
40 | 37 |
41 self._outputs = { | 38 self._outputs = { |
42 'CSSOMTypes.cpp': self.generate_types, | 39 'CSSOMTypes.cpp': self.generate_types, |
43 'CSSOMKeywords.cpp': self.generate_keywords, | 40 'CSSOMKeywords.cpp': self.generate_keywords, |
44 } | 41 } |
45 | 42 |
46 @template_expander.use_jinja('CSSOMTypes.cpp.tmpl') | 43 @template_expander.use_jinja('CSSOMTypes.cpp.tmpl') |
47 def generate_types(self): | 44 def generate_types(self): |
48 return { | 45 return { |
49 'properties': self._properties, | 46 'properties': self._properties, |
50 } | 47 } |
51 | 48 |
52 @template_expander.use_jinja('CSSOMKeywords.cpp.tmpl') | 49 @template_expander.use_jinja('CSSOMKeywords.cpp.tmpl') |
53 def generate_keywords(self): | 50 def generate_keywords(self): |
54 return { | 51 return { |
55 'properties': self._properties, | 52 'properties': self._properties, |
56 } | 53 } |
57 | 54 |
58 if __name__ == '__main__': | 55 if __name__ == '__main__': |
59 json5_generator.Maker(CSSOMTypesWriter).main() | 56 json5_generator.Maker(CSSOMTypesWriter).main() |
OLD | NEW |