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 json5_generator | 9 import json5_generator |
10 import template_expander | 10 import template_expander |
11 import make_style_builder | 11 import make_style_builder |
12 | 12 |
13 from name_utilities import ( | 13 from name_utilities import ( |
14 enum_for_css_keyword, enum_type_name, enum_value_name, class_member_name, me
thod_name, | 14 enum_for_css_keyword, enum_type_name, enum_value_name, class_member_name, me
thod_name, |
15 class_name, join_name | 15 class_name, join_name |
16 ) | 16 ) |
17 from collections import defaultdict, OrderedDict | 17 from collections import defaultdict, OrderedDict |
18 from itertools import chain | 18 from itertools import chain |
19 | 19 |
20 # Heuristic ordering of types from largest to smallest, used to sort fields by t
heir alignment sizes. | 20 # Heuristic ordering of types from largest to smallest, used to sort fields by t
heir alignment sizes. |
21 # Specifying the exact alignment sizes for each type is impossible because it's
platform specific, | 21 # Specifying the exact alignment sizes for each type is impossible because it's
platform specific, |
22 # so we define an ordering instead. | 22 # so we define an ordering instead. |
23 # The ordering comes from the data obtained in: | 23 # The ordering comes from the data obtained in: |
24 # https://codereview.chromium.org/2841413002 | 24 # https://codereview.chromium.org/2841413002 |
25 # TODO(shend): Put alignment sizes into code form, rather than linking to a CL w
hich may disappear. | 25 # TODO(shend): Put alignment sizes into code form, rather than linking to a CL w
hich may disappear. |
26 ALIGNMENT_ORDER = [ | 26 ALIGNMENT_ORDER = [ |
| 27 # Aligns like double |
27 'double', | 28 'double', |
28 'AtomicString', 'RefPtr', 'Persistent', 'Font', 'FillLayer', 'NinePieceImage
', # Aligns like a pointer (can be 32 or 64 bits) | 29 # Aligns like a pointer (can be 32 or 64 bits) |
29 'LengthBox', 'LengthSize', 'Length', 'TextSizeAdjust', 'TabSize', 'float', | 30 'AtomicString', 'DataRef', 'RefPtr', 'DataPersistent', 'Persistent', 'std::u
nique_ptr', |
30 'StyleColor', 'Color', 'LayoutUnit', 'unsigned', 'int', | 31 'Vector<String>', 'Font', 'FillLayer', 'NinePieceImage', |
| 32 # Aligns like float |
| 33 'LengthBox', 'LengthSize', 'FloatSize', 'LengthPoint', 'Length', 'TextSizeAd
just', 'TabSize', 'float', |
| 34 # Aligns like int |
| 35 'StyleColor', 'Color', 'LayoutUnit', 'LineClampValue', 'OutlineValue', 'unsi
gned', 'int', |
| 36 # Aligns like short |
31 'short', | 37 'short', |
32 'uint8_t', 'char', | 38 # Aligns like char |
| 39 'StyleSelfAlignmentData', 'StyleContentAlignmentData', 'uint8_t', 'char', |
| 40 # Aligns like bool |
33 'bool' | 41 'bool' |
34 ] | 42 ] |
35 | 43 |
36 # TODO(shend): Improve documentation and add docstrings. | 44 # TODO(shend): Improve documentation and add docstrings. |
37 | 45 |
38 | 46 |
39 def _flatten_list(x): | 47 def _flatten_list(x): |
40 """Flattens a list of lists into a single list.""" | 48 """Flattens a list of lists into a single list.""" |
41 return list(chain.from_iterable(x)) | 49 return list(chain.from_iterable(x)) |
42 | 50 |
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
462 | 470 |
463 @template_expander.use_jinja('ComputedStyleBaseConstants.h.tmpl') | 471 @template_expander.use_jinja('ComputedStyleBaseConstants.h.tmpl') |
464 def generate_base_computed_style_constants(self): | 472 def generate_base_computed_style_constants(self): |
465 return { | 473 return { |
466 'properties': self._properties, | 474 'properties': self._properties, |
467 'enums': self._generated_enums, | 475 'enums': self._generated_enums, |
468 } | 476 } |
469 | 477 |
470 if __name__ == '__main__': | 478 if __name__ == '__main__': |
471 json5_generator.Maker(ComputedStyleBaseWriter).main() | 479 json5_generator.Maker(ComputedStyleBaseWriter).main() |
OLD | NEW |