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 math | 6 import math |
7 import sys | 7 import sys |
8 | 8 |
9 import json5_generator | 9 import json5_generator |
10 import template_expander | 10 import template_expander |
11 import make_style_builder | 11 import make_style_builder |
12 | 12 |
13 from name_utilities import ( | 13 from name_utilities import ( |
14 enum_for_css_keyword, enum_type_name, enum_value_name, class_member_name, me thod_name, | 14 enum_for_css_keyword, enum_type_name, enum_value_name, class_member_name, me thod_name, |
Bugs Nash
2017/04/03 23:58:55
enum_for_css_keyword is no longer needed here
| |
15 join_name | 15 join_name |
16 ) | 16 ) |
17 | 17 |
18 | 18 |
19 # Temporary hard-coded list of fields that are not CSS properties. | 19 # Temporary hard-coded list of fields that are not CSS properties. |
20 # TODO(shend): Put this into its own JSON5 file. | 20 # TODO(shend): Put this into its own JSON5 file. |
21 NONPROPERTIES = [ | 21 NONPROPERTIES = [ |
22 {'name': 'IsLink', 'field_template': 'monotonic_flag', | 22 {'name': 'IsLink', 'field_template': 'monotonic_flag', |
23 'inherited': False, 'independent': False, 'default_value': False}, | 23 'inherited': False, 'independent': False, 'default_value': False}, |
24 {'name': 'OriginalDisplay', 'field_template': 'keyword', 'default_value': 'i nline', | 24 {'name': 'OriginalDisplay', 'field_template': 'keyword', 'default_value': 'i nline', |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
279 return field_buckets | 279 return field_buckets |
280 | 280 |
281 | 281 |
282 class ComputedStyleBaseWriter(make_style_builder.StyleBuilderWriter): | 282 class ComputedStyleBaseWriter(make_style_builder.StyleBuilderWriter): |
283 def __init__(self, json5_file_path): | 283 def __init__(self, json5_file_path): |
284 super(ComputedStyleBaseWriter, self).__init__(json5_file_path) | 284 super(ComputedStyleBaseWriter, self).__init__(json5_file_path) |
285 self._outputs = { | 285 self._outputs = { |
286 'ComputedStyleBase.h': self.generate_base_computed_style_h, | 286 'ComputedStyleBase.h': self.generate_base_computed_style_h, |
287 'ComputedStyleBase.cpp': self.generate_base_computed_style_cpp, | 287 'ComputedStyleBase.cpp': self.generate_base_computed_style_cpp, |
288 'ComputedStyleBaseConstants.h': self.generate_base_computed_style_co nstants, | 288 'ComputedStyleBaseConstants.h': self.generate_base_computed_style_co nstants, |
289 'CSSValueIDMappingsGenerated.h': self.generate_css_value_mappings, | |
290 } | 289 } |
291 | 290 |
292 # TODO(shend): Remove this once we move NONPROPERTIES to its own JSON fi le, | 291 # TODO(shend): Remove this once we move NONPROPERTIES to its own JSON fi le, |
293 # since the JSON5 reader will handle missing fields and defaults. | 292 # since the JSON5 reader will handle missing fields and defaults. |
294 for property_ in NONPROPERTIES: | 293 for property_ in NONPROPERTIES: |
295 property_['name_for_methods'] = property_['name'] | 294 property_['name_for_methods'] = property_['name'] |
296 if 'field_type_path' not in property_: | 295 if 'field_type_path' not in property_: |
297 property_['field_type_path'] = None | 296 property_['field_type_path'] = None |
298 if 'type_name' not in property_: | 297 if 'type_name' not in property_: |
299 property_['type_name'] = 'E' + enum_type_name(property_['name_fo r_methods']) | 298 property_['type_name'] = 'E' + enum_type_name(property_['name_fo r_methods']) |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
367 } | 366 } |
368 | 367 |
369 @template_expander.use_jinja('ComputedStyleBaseConstants.h.tmpl') | 368 @template_expander.use_jinja('ComputedStyleBaseConstants.h.tmpl') |
370 def generate_base_computed_style_constants(self): | 369 def generate_base_computed_style_constants(self): |
371 return { | 370 return { |
372 'properties': self._properties, | 371 'properties': self._properties, |
373 'enums': self._generated_enums, | 372 'enums': self._generated_enums, |
374 'fields': self._fields, | 373 'fields': self._fields, |
375 } | 374 } |
376 | 375 |
377 @template_expander.use_jinja('CSSValueIDMappingsGenerated.h.tmpl') | |
378 def generate_css_value_mappings(self): | |
379 mappings = {} | |
380 | |
381 for property_ in self._properties.values(): | |
382 if property_['field_template'] == 'keyword': | |
383 mappings[property_['type_name']] = { | |
384 'default_value': enum_value_name(property_['default_value']) , | |
385 'mapping': [(enum_value_name(k), enum_for_css_keyword(k)) fo r k in property_['keywords']], | |
386 } | |
387 | |
388 return { | |
389 'include_paths': self._include_paths, | |
390 'mappings': mappings, | |
391 } | |
392 | |
393 if __name__ == '__main__': | 376 if __name__ == '__main__': |
394 json5_generator.Maker(ComputedStyleBaseWriter).main() | 377 json5_generator.Maker(ComputedStyleBaseWriter).main() |
OLD | NEW |