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.
7 from name_utilities import lower_first
10 class CSSProperties(in_generator.Writer):
19 'name_for_methods': None,
20 'use_handlers_for': None,
27 'custom_initial': False,
28 'custom_inherit': False,
29 'custom_value': False,
30 'builder_skip': False,
31 'direction_aware': False,
35 'animatable': (True, False),
36 'inherited': (True, False),
37 'font': (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['name']: property['alias_for'] for property in properties if property['alias_for']}
53 properties = [property for property in properties if not property['alias_for']]
55 assert len(properties) <= 1024, 'There are more than 1024 CSS Properties, you need to update CSSProperty.h/StylePropertyMetadata m_propertyID accordingly.'
56 # We currently assign 0 to CSSPropertyInvalid
57 self._first_enum_value = 1
58 for offset, property in enumerate(properties):
59 property['property_id'] = css_name_to_enum(property['name'])
60 property['upper_camel_name'] = camelcase_css_name(property['name'])
61 property['lower_camel_name'] = lower_first(property['upper_camel_name'])
62 property['enum_value'] = self._first_enum_value + offset
63 property['is_internal'] = property['name'].startswith('-internal-')
65 self._properties_list = properties
66 self._properties = {property['property_id']: property for property in properties}
69 def camelcase_css_name(css_name):
70 """Convert hyphen-separated-name to UpperCamelCase.
72 E.g., '-foo-bar' becomes 'FooBar'.
74 return ''.join(word.capitalize() for word in css_name.split('-'))
77 def css_name_to_enum(css_name):
78 return 'CSSProperty' + camelcase_css_name(css_name)