| 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 in_generator | 9 import in_generator |
| 10 import template_expander | 10 import template_expander |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 field_name = 'm_' + property_name_lower | 97 field_name = 'm_' + property_name_lower |
| 98 bits_needed = math.log(len(property['keywords']), 2) | 98 bits_needed = math.log(len(property['keywords']), 2) |
| 99 | 99 |
| 100 # Separate the type path from the type name, if specified. | 100 # Separate the type path from the type name, if specified. |
| 101 type_name = property['type_name'] | 101 type_name = property['type_name'] |
| 102 type_path = None | 102 type_path = None |
| 103 if property['field_storage_type']: | 103 if property['field_storage_type']: |
| 104 type_path = property['field_storage_type'] | 104 type_path = property['field_storage_type'] |
| 105 type_name = type_path.split('/')[-1] | 105 type_name = type_path.split('/')[-1] |
| 106 | 106 |
| 107 # For now, the getter name should match the field name. Later, g
etter names |
| 108 # will start with an uppercase letter, so if they conflict with
the type name, |
| 109 # add 'get' to the front. |
| 110 getter_method_name = property_name_lower |
| 111 if type_name == property_name: |
| 112 getter_method_name = 'get' + property_name |
| 113 |
| 107 assert property['initial_keyword'] is not None, \ | 114 assert property['initial_keyword'] is not None, \ |
| 108 ('MakeComputedStyleBase requires an initial keyword for keyw
ord_only values, none specified ' | 115 ('MakeComputedStyleBase requires an initial keyword for keyw
ord_only values, none specified ' |
| 109 'for property ' + property['name']) | 116 'for property ' + property['name']) |
| 110 default_value = type_name + '::' + camel_case(property['initial_
keyword']) | 117 default_value = type_name + '::' + camel_case(property['initial_
keyword']) |
| 111 | 118 |
| 112 # If the property is independent, add the single-bit sized isInh
erited flag | 119 # If the property is independent, add the single-bit sized isInh
erited flag |
| 113 # to the list of Fields as well. | 120 # to the list of Fields as well. |
| 114 if property['independent']: | 121 if property['independent']: |
| 115 field_name_suffix_upper = property_name + 'IsInherited' | 122 field_name_suffix_upper = property_name + 'IsInherited' |
| 116 field_name_suffix_lower = property_name_lower + 'IsInherited
' | 123 field_name_suffix_lower = property_name_lower + 'IsInherited
' |
| (...skipping 15 matching lines...) Expand all Loading... |
| 132 self._fields.append(Field( | 139 self._fields.append(Field( |
| 133 'enum', | 140 'enum', |
| 134 name=field_name, | 141 name=field_name, |
| 135 property_name=property['name'], | 142 property_name=property['name'], |
| 136 inherited=property['inherited'], | 143 inherited=property['inherited'], |
| 137 independent=property['independent'], | 144 independent=property['independent'], |
| 138 storage_type=type_name, | 145 storage_type=type_name, |
| 139 storage_type_path=type_path, | 146 storage_type_path=type_path, |
| 140 size=int(math.ceil(bits_needed)), | 147 size=int(math.ceil(bits_needed)), |
| 141 default_value=default_value, | 148 default_value=default_value, |
| 142 getter_method_name=property_name_lower, | 149 getter_method_name=getter_method_name, |
| 143 setter_method_name='set' + property_name, | 150 setter_method_name='set' + property_name, |
| 144 initial_method_name='initial' + property_name, | 151 initial_method_name='initial' + property_name, |
| 145 resetter_method_name='reset' + property_name, | 152 resetter_method_name='reset' + property_name, |
| 146 is_inherited_method_name=property_name_lower + 'IsInherited'
, | 153 is_inherited_method_name=property_name_lower + 'IsInherited'
, |
| 147 )) | 154 )) |
| 148 | 155 |
| 149 # Small optimization: order fields by size, from largest to smallest, | 156 # Small optimization: order fields by size, from largest to smallest, |
| 150 # to reduce wasted space from alignment. | 157 # to reduce wasted space from alignment. |
| 151 self._fields.sort(key=lambda f: f.size, reverse=True) | 158 self._fields.sort(key=lambda f: f.size, reverse=True) |
| 152 | 159 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 169 @template_expander.use_jinja('ComputedStyleBaseConstants.h.tmpl') | 176 @template_expander.use_jinja('ComputedStyleBaseConstants.h.tmpl') |
| 170 def generate_base_computed_style_constants(self): | 177 def generate_base_computed_style_constants(self): |
| 171 return { | 178 return { |
| 172 'properties': self._properties, | 179 'properties': self._properties, |
| 173 'enums': self._computed_enums, | 180 'enums': self._computed_enums, |
| 174 'fields': self._fields, | 181 'fields': self._fields, |
| 175 } | 182 } |
| 176 | 183 |
| 177 if __name__ == '__main__': | 184 if __name__ == '__main__': |
| 178 in_generator.Maker(ComputedStyleBaseWriter).main(sys.argv) | 185 in_generator.Maker(ComputedStyleBaseWriter).main(sys.argv) |
| OLD | NEW |