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 | |
nainar
2017/06/12 23:20:55
YEAH! \o/
| |
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 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
468 | 476 |
469 @template_expander.use_jinja('ComputedStyleBaseConstants.h.tmpl') | 477 @template_expander.use_jinja('ComputedStyleBaseConstants.h.tmpl') |
470 def generate_base_computed_style_constants(self): | 478 def generate_base_computed_style_constants(self): |
471 return { | 479 return { |
472 'properties': self._properties, | 480 'properties': self._properties, |
473 'enums': self._generated_enums, | 481 'enums': self._generated_enums, |
474 } | 482 } |
475 | 483 |
476 if __name__ == '__main__': | 484 if __name__ == '__main__': |
477 json5_generator.Maker(ComputedStyleBaseWriter).main() | 485 json5_generator.Maker(ComputedStyleBaseWriter).main() |
OLD | NEW |