diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-10-12 14:27:29 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-10-13 09:35:20 +0000 |
commit | c30a6232df03e1efbd9f3b226777b07e087a1122 (patch) | |
tree | e992f45784689f373bcc38d1b79a239ebe17ee23 /chromium/third_party/blink/renderer/build/scripts/core/css/make_style_shorthands.py | |
parent | 7b5b123ac58f58ffde0f4f6e488bcd09aa4decd3 (diff) | |
download | qtwebengine-chromium-c30a6232df03e1efbd9f3b226777b07e087a1122.tar.gz |
BASELINE: Update Chromium to 85.0.4183.14085-based
Change-Id: Iaa42f4680837c57725b1344f108c0196741f6057
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'chromium/third_party/blink/renderer/build/scripts/core/css/make_style_shorthands.py')
-rwxr-xr-x | chromium/third_party/blink/renderer/build/scripts/core/css/make_style_shorthands.py | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/chromium/third_party/blink/renderer/build/scripts/core/css/make_style_shorthands.py b/chromium/third_party/blink/renderer/build/scripts/core/css/make_style_shorthands.py index a3cab6f8bb4..1799cd5a153 100755 --- a/chromium/third_party/blink/renderer/build/scripts/core/css/make_style_shorthands.py +++ b/chromium/third_party/blink/renderer/build/scripts/core/css/make_style_shorthands.py @@ -34,6 +34,67 @@ from name_utilities import enum_key_for_css_property, id_for_css_property import template_expander +def collect_runtime_flags(properties): + """Returns a list of unique runtime flags used by the properties""" + flags = {p['runtime_flag'] for p in properties if p['runtime_flag']} + return sorted(flags) + + +class Expansion(object): + """A specific (longhand) expansion of a shorthand. + + A shorthand may have multiple expansions, because some of the longhands + might be behind runtime flags. + + The enabled_mask represents which flags are enabled/disabled for this + specific expansion. For example, if flags contains three elements, + and enabled_mask is 0b100, then flags[0] is disabled, flags[1] is disabled, + and flags[2] is enabled. This information is used to produce the correct + list of longhands corresponding to the runtime flags that are enabled/ + disabled. + """ + + def __init__(self, longhands, flags, enabled_mask): + super(Expansion, self).__init__() + self._longhands = longhands + self._flags = flags + self._enabled_mask = enabled_mask + + def is_enabled(self, flag): + return (1 << self._flags.index(flag)) & self._enabled_mask + + @property + def is_empty(self): + return len(self.enabled_longhands) == 0 + + @property + def enabled_longhands(self): + include = lambda longhand: not longhand[ + 'runtime_flag'] or self.is_enabled(longhand['runtime_flag']) + return filter(include, self._longhands) + + @property + def index(self): + return self._enabled_mask + + @property + def flags(self): + return [ + dict(name=flag, enabled=self.is_enabled(flag)) + for flag in self._flags + ] + + +def create_expansions(longhands): + flags = collect_runtime_flags(longhands) + expansions = map(lambda mask: Expansion(longhands, flags, mask), + range(1 << len(flags))) + assert len(expansions) > 0 + # We generate 2^N expansions for N flags, so enforce some limit. + assert len(flags) <= 4, 'Too many runtime flags for a single shorthand' + return expansions + + class StylePropertyShorthandWriter(json5_generator.Writer): class_name = 'StylePropertyShorthand' _FILE_BASENAME = 'style_property_shorthand' @@ -57,6 +118,11 @@ class StylePropertyShorthandWriter(json5_generator.Writer): property_['longhands']) property_['longhand_property_ids'] = map(id_for_css_property, property_['longhands']) + + longhands = map( + lambda name: json5_properties.properties_by_name[name], + property_['longhands']) + property_['expansions'] = create_expansions(longhands) for longhand_enum_key in property_['longhand_enum_keys']: self._longhand_dictionary[longhand_enum_key].append(property_) |