Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #!/usr/bin/env python | |
| 2 # Copyright 2014 The Chromium Authors. All rights reserved. | |
| 3 # Use of this source code is governed by a BSD-style license that can be | |
| 4 # found in the LICENSE file. | |
| 5 | |
| 6 import in_generator | |
| 7 from name_utilities import lower_first | |
| 8 | |
| 9 | |
| 10 class CSSProperties(in_generator.Writer): | |
| 11 defaults = { | |
| 12 'alias_for': None, | |
| 13 'longhands': '', | |
| 14 'runtime_enabled_shorthand': None, | |
| 15 'font': False, | |
|
Nils Barth (inactive)
2014/07/07 16:43:27
alpha?
| |
| 16 'svg': False, | |
| 17 'name_for_methods': None, | |
| 18 'getter': None, | |
| 19 'setter': None, | |
| 20 'initial': None, | |
| 21 'type_name': None, | |
| 22 'sb_converter': None, | |
| 23 'sb_custom_all': False, | |
| 24 'sb_custom_initial': False, | |
| 25 'sb_custom_inherit': False, | |
| 26 'sb_custom_value': False, | |
| 27 'sb_skip': False, | |
| 28 'sb_unreachable': False, | |
| 29 } | |
| 30 | |
| 31 valid_values = { | |
| 32 'svg': [True, False], | |
|
Nils Barth (inactive)
2014/07/07 16:43:27
list -> tuple?
| |
| 33 'font': [True, False], | |
| 34 'sb_custom_all': [True, False], | |
| 35 'sb_custom_initial': [True, False], | |
| 36 'sb_custom_inherit': [True, False], | |
| 37 'sb_custom_value': [True, False], | |
| 38 'sb_skip': [True, False], | |
| 39 'sb_unreachable': [True, False], | |
| 40 } | |
| 41 | |
| 42 def __init__(self, file_paths): | |
| 43 in_generator.Writer.__init__(self, file_paths) | |
| 44 | |
| 45 properties = self.in_file.name_dictionaries | |
| 46 | |
| 47 self._aliases = {property['name']: property['alias_for'] for property in properties if property['alias_for']} | |
|
Nils Barth (inactive)
2014/07/07 16:43:27
line break?
This needs to be dict((property['name
| |
| 48 properties = [property for property in properties if not property['alias _for']] | |
|
Nils Barth (inactive)
2014/07/07 16:43:27
line break?
| |
| 49 | |
| 50 assert len(properties) <= 1024, "There are more than 1024 CSS Properties , you need to update CSSProperty.h/StylePropertyMetadata m_propertyID accordingl y." | |
| 51 # We currently assign 0 to CSSPropertyInvalid | |
| 52 self._first_enum_value = 1 | |
| 53 for offset, property in enumerate(properties): | |
| 54 property['property_id'] = self._css_name_to_enum(property['name']) | |
|
Nils Barth (inactive)
2014/07/07 16:43:27
Would this list be clearer alphabetically?
(other
| |
| 55 property['upper_camel_name'] = self._camelcase_css_name(property['na me']) | |
| 56 property['lower_camel_name'] = lower_first(property['upper_camel_nam e']) | |
| 57 property['enum_value'] = self._first_enum_value + offset | |
| 58 property['is_internal'] = property['name'].startswith('-internal-') | |
| 59 if property['sb_custom_all']: | |
| 60 property['sb_custom_initial'] = True | |
| 61 property['sb_custom_inherit'] = True | |
| 62 property['sb_custom_value'] = True | |
| 63 | |
| 64 self._properties_list = properties | |
| 65 self._properties = {property['property_id']: property for property in pr operties} | |
| 66 | |
| 67 @staticmethod | |
|
Nils Barth (inactive)
2014/07/07 16:43:27
Any reason to use static methods instead of just f
| |
| 68 def _camelcase_css_name(css_name): | |
| 69 """Convert hyphen-separated-name to UpperCamelCase. | |
| 70 | |
| 71 E.g., '-foo-bar' becomes 'FooBar'. | |
| 72 """ | |
| 73 return ''.join(word.capitalize() for word in css_name.split('-')) | |
| 74 | |
| 75 @staticmethod | |
| 76 def _css_name_to_enum(css_name): | |
| 77 return "CSSProperty" + CSSProperties._camelcase_css_name(css_name) | |
|
Nils Barth (inactive)
2014/07/07 16:43:27
Single quotes.
| |
| OLD | NEW |