OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 in_generator | 6 import in_generator |
7 from name_utilities import lower_first | 7 from name_utilities import lower_first |
8 | 8 |
9 | 9 |
10 class CSSProperties(in_generator.Writer): | 10 class CSSProperties(in_generator.Writer): |
11 defaults = { | 11 defaults = { |
12 'alias_for': None, | |
13 'longhands': '', | 12 'longhands': '', |
14 'animatable': False, | |
15 'inherited': False, | |
16 'font': False, | 13 'font': False, |
17 'svg': False, | 14 'svg': False, |
18 'name_for_methods': None, | 15 'name_for_methods': None, |
19 'use_handlers_for': None, | 16 'use_handlers_for': None, |
20 'getter': None, | 17 'getter': None, |
21 'setter': None, | 18 'setter': None, |
22 'initial': None, | 19 'initial': None, |
23 'type_name': None, | 20 'type_name': None, |
24 'converter': None, | 21 'converter': None, |
25 'custom_all': False, | 22 'custom_all': False, |
26 'custom_initial': False, | 23 'custom_initial': False, |
27 'custom_inherit': False, | 24 'custom_inherit': False, |
28 'custom_value': False, | 25 'custom_value': False, |
29 'builder_skip': False, | 26 'builder_skip': False, |
30 'direction_aware': False, | 27 'direction_aware': False, |
31 } | 28 } |
32 | 29 |
33 valid_values = { | 30 valid_values = { |
34 'animatable': (True, False), | |
35 'inherited': (True, False), | |
36 'font': (True, False), | 31 'font': (True, False), |
37 'svg': (True, False), | 32 'svg': (True, False), |
38 'custom_all': (True, False), | 33 'custom_all': (True, False), |
39 'custom_initial': (True, False), | 34 'custom_initial': (True, False), |
40 'custom_inherit': (True, False), | 35 'custom_inherit': (True, False), |
41 'custom_value': (True, False), | 36 'custom_value': (True, False), |
42 'builder_skip': (True, False), | 37 'builder_skip': (True, False), |
43 'direction_aware': (True, False), | 38 'direction_aware': (True, False), |
44 } | 39 } |
45 | 40 |
46 def __init__(self, file_paths): | 41 def __init__(self, file_paths): |
47 in_generator.Writer.__init__(self, file_paths) | 42 in_generator.Writer.__init__(self, file_paths) |
48 | 43 |
49 properties = self.in_file.name_dictionaries | 44 properties = self.in_file.name_dictionaries |
50 | 45 |
51 self._aliases = {property['name']: property['alias_for'] for property in
properties if property['alias_for']} | 46 for property in properties: |
52 properties = [property for property in properties if not property['alias
_for']] | |
53 | |
54 assert len(properties) <= 1024, 'There are more than 1024 CSS Properties
, you need to update CSSProperty.h/StylePropertyMetadata m_propertyID accordingl
y.' | |
55 # We currently assign 0 to CSSPropertyInvalid | |
56 self._first_enum_value = 1 | |
57 for offset, property in enumerate(properties): | |
58 property['property_id'] = css_name_to_enum(property['name']) | 47 property['property_id'] = css_name_to_enum(property['name']) |
59 property['upper_camel_name'] = camelcase_css_name(property['name']) | 48 property['upper_camel_name'] = camelcase_css_name(property['name']) |
60 property['lower_camel_name'] = lower_first(property['upper_camel_nam
e']) | 49 property['lower_camel_name'] = lower_first(property['upper_camel_nam
e']) |
61 property['enum_value'] = self._first_enum_value + offset | |
62 property['is_internal'] = property['name'].startswith('-internal-') | |
63 | 50 |
64 self._properties_list = properties | 51 self._properties_list = properties |
65 self._properties = {property['property_id']: property for property in pr
operties} | 52 self._properties = {property['property_id']: property for property in pr
operties} |
66 | 53 |
67 | 54 |
68 def camelcase_css_name(css_name): | 55 def camelcase_css_name(css_name): |
69 """Convert hyphen-separated-name to UpperCamelCase. | 56 """Convert hyphen-separated-name to UpperCamelCase. |
70 | 57 |
71 E.g., '-foo-bar' becomes 'FooBar'. | 58 E.g., '-foo-bar' becomes 'FooBar'. |
72 """ | 59 """ |
73 return ''.join(word.capitalize() for word in css_name.split('-')) | 60 return ''.join(word.capitalize() for word in css_name.split('-')) |
74 | 61 |
75 | 62 |
76 def css_name_to_enum(css_name): | 63 def css_name_to_enum(css_name): |
77 return 'CSSProperty' + camelcase_css_name(css_name) | 64 return 'CSSProperty' + camelcase_css_name(css_name) |
OLD | NEW |