Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / Source / build / scripts / css_properties.py
blob2f4ae99705ad51a300da03c7a86a76718caf0161
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.
6 import in_generator
7 from name_utilities import lower_first
10 class CSSProperties(in_generator.Writer):
11 defaults = {
12 'alias_for': None,
13 'runtime_flag': None,
14 'longhands': '',
15 'interpolable': False,
16 'inherited': False,
17 'font': False,
18 'svg': False,
19 'name_for_methods': None,
20 'use_handlers_for': None,
21 'getter': None,
22 'setter': None,
23 'initial': None,
24 'type_name': None,
25 'converter': None,
26 'custom_all': False,
27 'custom_initial': False,
28 'custom_inherit': False,
29 'custom_value': False,
30 'builder_skip': False,
31 'direction_aware': False,
34 valid_values = {
35 'interpolable': (True, False),
36 'inherited': (True, False),
37 'font': (True, False),
38 'svg': (True, False),
39 'custom_all': (True, False),
40 'custom_initial': (True, False),
41 'custom_inherit': (True, False),
42 'custom_value': (True, False),
43 'builder_skip': (True, False),
44 'direction_aware': (True, False),
47 def __init__(self, file_paths):
48 in_generator.Writer.__init__(self, file_paths)
50 properties = self.in_file.name_dictionaries
52 self._aliases = [property for property in properties if property['alias_for']]
53 properties = [property for property in properties if not property['alias_for']]
55 # We currently assign 0 to CSSPropertyInvalid
56 self._first_enum_value = 1
58 # StylePropertyMetadata additionally assumes there are under 1024 properties.
59 assert self._first_enum_value + len(properties) < 512, 'Property aliasing expects there are under 512 properties.'
61 for offset, property in enumerate(properties):
62 property['property_id'] = css_name_to_enum(property['name'])
63 property['upper_camel_name'] = camelcase_css_name(property['name'])
64 property['lower_camel_name'] = lower_first(property['upper_camel_name'])
65 property['enum_value'] = self._first_enum_value + offset
66 property['is_internal'] = property['name'].startswith('-internal-')
68 self._properties_including_aliases = properties
69 self._properties = {property['property_id']: property for property in properties}
71 # The generated code will only work with at most one alias per property
72 assert len({property['alias_for'] for property in self._aliases}) == len(self._aliases)
74 for property in self._aliases:
75 property['property_id'] = css_alias_name_to_enum(property['name'])
76 aliased_property = self._properties[css_name_to_enum(property['alias_for'])]
77 property['enum_value'] = aliased_property['enum_value'] + 512
78 self._properties_including_aliases += self._aliases
81 def camelcase_css_name(css_name):
82 """Convert hyphen-separated-name to UpperCamelCase.
84 E.g., '-foo-bar' becomes 'FooBar'.
85 """
86 return ''.join(word.capitalize() for word in css_name.split('-'))
89 def css_name_to_enum(css_name):
90 return 'CSSProperty' + camelcase_css_name(css_name)
93 def css_alias_name_to_enum(css_name):
94 return 'CSSPropertyAlias' + camelcase_css_name(css_name)