diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2018-05-15 10:20:33 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2018-05-15 10:28:57 +0000 |
commit | d17ea114e5ef69ad5d5d7413280a13e6428098aa (patch) | |
tree | 2c01a75df69f30d27b1432467cfe7c1467a498da /chromium/third_party/blink/renderer/build/scripts/core | |
parent | 8c5c43c7b138c9b4b0bf56d946e61d3bbc111bec (diff) | |
download | qtwebengine-chromium-d17ea114e5ef69ad5d5d7413280a13e6428098aa.tar.gz |
BASELINE: Update Chromium to 67.0.3396.47
Change-Id: Idcb1341782e417561a2473eeecc82642dafda5b7
Reviewed-by: Michal Klocek <michal.klocek@qt.io>
Diffstat (limited to 'chromium/third_party/blink/renderer/build/scripts/core')
34 files changed, 2686 insertions, 0 deletions
diff --git a/chromium/third_party/blink/renderer/build/scripts/core/OWNERS b/chromium/third_party/blink/renderer/build/scripts/core/OWNERS new file mode 100644 index 00000000000..fd832b84057 --- /dev/null +++ b/chromium/third_party/blink/renderer/build/scripts/core/OWNERS @@ -0,0 +1,5 @@ +set noparent +file://third_party/blink/renderer/core/OWNERS + +# TEAM: blink-dev@chromium.org +# COMPONENT: Blink diff --git a/chromium/third_party/blink/renderer/build/scripts/core/__init__.py b/chromium/third_party/blink/renderer/build/scripts/core/__init__.py new file mode 100644 index 00000000000..e69de29bb2d --- /dev/null +++ b/chromium/third_party/blink/renderer/build/scripts/core/__init__.py diff --git a/chromium/third_party/blink/renderer/build/scripts/core/css/OWNERS b/chromium/third_party/blink/renderer/build/scripts/core/css/OWNERS new file mode 100644 index 00000000000..863b76fdb1c --- /dev/null +++ b/chromium/third_party/blink/renderer/build/scripts/core/css/OWNERS @@ -0,0 +1,7 @@ +file://third_party/blink/renderer/core/css/OWNERS + +nainar@chromium.org +shend@chromium.org +meade@chromium.org + +# COMPONENT: Blink>CSS diff --git a/chromium/third_party/blink/renderer/build/scripts/core/css/__init__.py b/chromium/third_party/blink/renderer/build/scripts/core/css/__init__.py new file mode 100644 index 00000000000..e69de29bb2d --- /dev/null +++ b/chromium/third_party/blink/renderer/build/scripts/core/css/__init__.py diff --git a/chromium/third_party/blink/renderer/build/scripts/core/css/css_properties.py b/chromium/third_party/blink/renderer/build/scripts/core/css/css_properties.py new file mode 100755 index 00000000000..7e646855f6b --- /dev/null +++ b/chromium/third_party/blink/renderer/build/scripts/core/css/css_properties.py @@ -0,0 +1,291 @@ +#!/usr/bin/env python +# Copyright 2014 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +import json5_generator +from name_utilities import ( + upper_camel_case, + lower_camel_case, + enum_value_name, + enum_for_css_property, + enum_for_css_property_alias +) +from core.css.field_alias_expander import FieldAliasExpander + + +# These values are converted using CSSPrimitiveValue in the setter function, +# if applicable. +PRIMITIVE_TYPES = [ + 'short', + 'unsigned short', + 'int', + 'unsigned int', + 'unsigned', + 'float', + 'LineClampValue' +] + + +# Check properties parameters are valid. +# TODO(jiameng): add more flag checks later. +def check_property_parameters(property_to_check): + # Only longhand properties can be interpolable. + if property_to_check['longhands']: + assert not(property_to_check['interpolable']), \ + 'Shorthand property (' + property_to_check['name'] + ') ' \ + 'cannot be interpolable' + if property_to_check['longhands']: + assert 'parseSingleValue' not in property_to_check['property_methods'], \ + 'Shorthand property (' + property_to_check['name'] + ') ' \ + 'should not implement parseSingleValue' + else: + assert 'parseShorthand' not in property_to_check['property_methods'], \ + 'Longhand property (' + property_to_check['name'] + ') ' \ + 'should not implement parseShorthand' + assert property_to_check['is_descriptor'] or \ + property_to_check['is_property'], \ + '{} must be a property, descriptor, or both'.format( + property_to_check['name']) + if property_to_check['field_template'] is not None: + assert not property_to_check['longhands'], \ + "Shorthand '{}' cannot have a field_template.".format( + property_to_check['name']) + if property_to_check['mutable']: + assert property_to_check['field_template'] == 'monotonic_flag', \ + 'mutable keyword only implemented for monotonic_flag' + + +class CSSProperties(object): + def __init__(self, file_paths): + assert len(file_paths) >= 2, \ + "CSSProperties at least needs both CSSProperties.json5 and \ + ComputedStyleFieldAliases.json5 to function" + + # ComputedStyleFieldAliases.json5. Used to expand out parameters used + # in the various generators for ComputedStyle. + self._field_alias_expander = FieldAliasExpander(file_paths[1]) + + # CSSPropertyValueMetadata assumes that there are at most 1024 + # properties + aliases. + self._alias_offset = 512 + # 0: CSSPropertyInvalid + # 1: CSSPropertyVariable + self._first_enum_value = 2 + self._last_used_enum_value = self._first_enum_value + + self._properties_by_id = {} + self._aliases = [] + self._longhands = [] + self._shorthands = [] + self._properties_including_aliases = [] + + # Add default data in CSSProperties.json5. This must be consistent + # across instantiations of this class. + css_properties_file = json5_generator.Json5File.load_from_files( + [file_paths[0]]) + self._default_parameters = css_properties_file.parameters + self.add_properties(css_properties_file.name_dictionaries) + + assert self._first_enum_value + len(self._properties_by_id) < \ + self._alias_offset, \ + 'Property aliasing expects fewer than %d properties.' % \ + self._alias_offset + self._last_unresolved_property_id = max( + property_["enum_value"] for property_ in self._aliases) + + # Process extra files passed in. + self._extra_fields = [] + for i in range(2, len(file_paths)): + fields = json5_generator.Json5File.load_from_files( + [file_paths[i]], + default_parameters=self._default_parameters) + self._extra_fields.extend(fields.name_dictionaries) + for field in self._extra_fields: + self.expand_parameters(field) + + def add_properties(self, properties): + self._aliases = [ + property_ for property_ in properties if property_['alias_for']] + self._shorthands = [ + property_ for property_ in properties if property_['longhands']] + self._longhands = [ + property_ for property_ in properties if ( + not property_['alias_for'] and not property_['longhands'])] + + # Sort the properties by priority, then alphabetically. Ensure that + # the resulting order is deterministic. + # Sort properties by priority, then alphabetically. + for property_ in self._longhands + self._shorthands: + self.expand_parameters(property_) + check_property_parameters(property_) + # This order must match the order in CSSPropertyPriority.h. + priority_numbers = {'Animation': 0, 'High': 1, 'Low': 2} + priority = priority_numbers[property_['priority']] + name_without_leading_dash = property_['name'] + if property_['name'].startswith('-'): + name_without_leading_dash = property_['name'][1:] + property_['sorting_key'] = (priority, name_without_leading_dash) + + sorting_keys = {} + for property_ in self._longhands + self._shorthands: + key = property_['sorting_key'] + assert key not in sorting_keys, \ + ('Collision detected - two properties have the same name and ' + 'priority, a potentially non-deterministic ordering can ' + 'occur: {}, {} and {}'.format( + key, property_['name'], sorting_keys[key])) + sorting_keys[key] = property_['name'] + self._longhands.sort(key=lambda p: p['sorting_key']) + self._shorthands.sort(key=lambda p: p['sorting_key']) + + # The sorted index becomes the CSSPropertyID enum value. + for property_ in self._longhands + self._shorthands: + property_['enum_value'] = self._last_used_enum_value + self._last_used_enum_value += 1 + # Add the new property into the map of properties. + assert property_['property_id'] not in self._properties_by_id, \ + ('property with ID {} appears more than once in the ' + 'properties list'.format(property_['property_id'])) + self._properties_by_id[property_['property_id']] = property_ + + self.expand_aliases() + self._properties_including_aliases = self._longhands + \ + self._shorthands + self._aliases + + def expand_aliases(self): + for i, alias in enumerate(self._aliases): + assert not alias['runtime_flag'], \ + "Property '{}' is an alias with a runtime_flag, "\ + "but runtime flags do not currently work for aliases.".format( + alias['name']) + aliased_property = self._properties_by_id[ + enum_for_css_property(alias['alias_for'])] + updated_alias = aliased_property.copy() + updated_alias['name'] = alias['name'] + updated_alias['alias_for'] = alias['alias_for'] + updated_alias['aliased_property'] = aliased_property['upper_camel_name'] + updated_alias['property_id'] = enum_for_css_property_alias( + alias['name']) + updated_alias['enum_value'] = aliased_property['enum_value'] + \ + self._alias_offset + updated_alias['upper_camel_name'] = upper_camel_case(alias['name']) + updated_alias['lower_camel_name'] = lower_camel_case(alias['name']) + self._aliases[i] = updated_alias + + def expand_parameters(self, property_): + def set_if_none(property_, key, value): + if key not in property_ or property_[key] is None: + property_[key] = value + + # Basic info. + property_['property_id'] = enum_for_css_property(property_['name']) + property_['upper_camel_name'] = upper_camel_case(property_['name']) + property_['lower_camel_name'] = lower_camel_case(property_['name']) + property_['is_internal'] = property_['name'].startswith('-internal-') + name = property_['name_for_methods'] + if not name: + name = upper_camel_case(property_['name']).replace('Webkit', '') + set_if_none(property_, 'inherited', False) + + # Initial function, Getters and Setters for ComputedStyle. + property_['initial'] = 'Initial' + name + simple_type_name = str(property_['type_name']).split('::')[-1] + set_if_none(property_, 'name_for_methods', name) + set_if_none(property_, 'type_name', 'E' + name) + set_if_none( + property_, + 'getter', + name if simple_type_name != name else 'Get' + name) + set_if_none(property_, 'setter', 'Set' + name) + if property_['inherited']: + property_['is_inherited_setter'] = 'Set' + name + 'IsInherited' + + # Expand whether there are custom StyleBuilder methods. + if property_['custom_apply_functions_all']: + property_['custom_apply_functions_inherit'] = True + property_['custom_apply_functions_initial'] = True + property_['custom_apply_functions_value'] = True + + # Expand StyleBuilderConverter params where ncessary. + if property_['type_name'] in PRIMITIVE_TYPES: + set_if_none(property_, 'converter', 'CSSPrimitiveValue') + else: + set_if_none(property_, 'converter', 'CSSIdentifierValue') + + # Expand out field templates. + if property_['field_template']: + self._field_alias_expander.expand_field_alias(property_) + + type_name = property_['type_name'] + if (property_['field_template'] == 'keyword' or + property_['field_template'] == 'multi_keyword'): + default_value = type_name + '::' + \ + enum_value_name(property_['default_value']) + elif (property_['field_template'] == 'external' or + property_['field_template'] == 'primitive' or + property_['field_template'] == 'pointer'): + default_value = property_['default_value'] + else: + assert property_['field_template'] == 'monotonic_flag', \ + "Please put a valid value for field_template; got " + \ + str(property_['field_template']) + property_['type_name'] = 'bool' + default_value = 'false' + property_['default_value'] = default_value + + property_['unwrapped_type_name'] = property_['type_name'] + if property_['wrapper_pointer_name']: + assert property_['field_template'] in ['pointer', 'external'] + if property_['field_template'] == 'external': + property_['type_name'] = '{}<{}>'.format( + property_['wrapper_pointer_name'], type_name) + + # Default values for extra parameters in ComputedStyleExtraFields.json5. + set_if_none(property_, 'custom_copy', False) + set_if_none(property_, 'custom_compare', False) + set_if_none(property_, 'mutable', False) + + @property + def default_parameters(self): + return self._default_parameters + + @property + def aliases(self): + return self._aliases + + @property + def shorthands(self): + return self._shorthands + + @property + def longhands(self): + return self._longhands + + @property + def properties_by_id(self): + return self._properties_by_id + + @property + def properties_including_aliases(self): + return self._properties_including_aliases + + @property + def first_property_id(self): + return self._first_enum_value + + @property + def last_property_id(self): + return self._first_enum_value + len(self._properties_by_id) - 1 + + @property + def last_unresolved_property_id(self): + return self._last_unresolved_property_id + + @property + def alias_offset(self): + return self._alias_offset + + @property + def extra_fields(self): + return self._extra_fields diff --git a/chromium/third_party/blink/renderer/build/scripts/core/css/field_alias_expander.py b/chromium/third_party/blink/renderer/build/scripts/core/css/field_alias_expander.py new file mode 100644 index 00000000000..5bbca46e893 --- /dev/null +++ b/chromium/third_party/blink/renderer/build/scripts/core/css/field_alias_expander.py @@ -0,0 +1,30 @@ +# Copyright 2017 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +import json5_generator + + +class FieldAliasExpander(object): + """ + A helper for expanding the "field_template" parameter in CSSProperties.json5 + + It takes the list of aliases and expansions from the given file_path, (it + should point to core/css/ComputedStyleFieldAliases.json5) and uses that to + inform which fields in a given property should be set. + """ + def __init__(self, file_path): + loaded_file = json5_generator.Json5File.load_from_files([file_path]) + self._field_aliases = dict([(alias["name"], alias) + for alias in loaded_file.name_dictionaries]) + + def expand_field_alias(self, property_): + """ + Does expansion based on the value of field_template of a given property. + """ + if property_['field_template'] in self._field_aliases: + alias_template = property_['field_template'] + for field in self._field_aliases[alias_template]: + if field == 'name': + continue + property_[field] = self._field_aliases[alias_template][field] diff --git a/chromium/third_party/blink/renderer/build/scripts/core/css/make_css_value_keywords.py b/chromium/third_party/blink/renderer/build/scripts/core/css/make_css_value_keywords.py new file mode 100755 index 00000000000..e2435d12350 --- /dev/null +++ b/chromium/third_party/blink/renderer/build/scripts/core/css/make_css_value_keywords.py @@ -0,0 +1,75 @@ +#!/usr/bin/env python + +import os +import sys +sys.path.append(os.path.join(os.path.dirname(__file__), '../..')) + +import os.path +import subprocess +from name_utilities import enum_for_css_keyword +import json5_generator + +import template_expander +import gperf + + +class CSSValueKeywordsWriter(json5_generator.Writer): + def __init__(self, file_paths): + json5_generator.Writer.__init__(self, file_paths) + self._outputs = { + "css_value_keywords.h": self.generate_header, + "css_value_keywords.cc": self.generate_implementation + } + + self._value_keywords = self.json5_file.name_dictionaries + first_keyword_id = 1 + for offset, keyword in enumerate(self._value_keywords): + keyword['lower_name'] = keyword['name'].lower() + keyword['enum_name'] = enum_for_css_keyword(keyword['name']) + keyword['enum_value'] = first_keyword_id + offset + if keyword['name'].startswith('-internal-'): + assert keyword['mode'] is None, 'Can\'t specify mode for ' \ + 'value keywords with the prefix "-internal-".' + keyword['mode'] = 'UASheet' + else: + assert keyword['mode'] != 'UASheet', 'UASheet mode only ' \ + 'value keywords should have the prefix "-internal-".' + self._keyword_count = len(self._value_keywords) + first_keyword_id + + @template_expander.use_jinja('core/css/templates/css_value_keywords.h.tmpl') + def generate_header(self): + return { + 'value_keywords': self._value_keywords, + 'value_keywords_count': self._keyword_count, + 'max_value_keyword_length': + max(len(keyword['name']) for keyword in self._value_keywords), + } + + def _value_keywords_with_mode(self, mode): + return [ + keyword for keyword in self._value_keywords + if keyword['mode'] == mode + ] + + @gperf.use_jinja_gperf_template( + 'core/css/templates/css_value_keywords.cc.tmpl', + ['-Q', 'CSSValueStringPool']) + def generate_implementation(self): + keyword_offsets = [] + current_offset = 0 + for keyword in self._value_keywords: + keyword_offsets.append(current_offset) + current_offset += len(keyword["name"]) + 1 + + return { + 'value_keywords': self._value_keywords, + 'value_keyword_offsets': keyword_offsets, + 'ua_sheet_mode_values_keywords': + self._value_keywords_with_mode('UASheet'), + 'quirks_mode_or_ua_sheet_mode_values_keywords': + self._value_keywords_with_mode('QuirksOrUASheet'), + 'gperf_path': self.gperf_path, + } + +if __name__ == "__main__": + json5_generator.Maker(CSSValueKeywordsWriter).main() diff --git a/chromium/third_party/blink/renderer/build/scripts/core/css/make_cssom_types.py b/chromium/third_party/blink/renderer/build/scripts/core/css/make_cssom_types.py new file mode 100755 index 00000000000..14ea88d4ac6 --- /dev/null +++ b/chromium/third_party/blink/renderer/build/scripts/core/css/make_cssom_types.py @@ -0,0 +1,60 @@ +#!/usr/bin/env python +# Copyright 2016 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +import os +import sys +sys.path.append(os.path.join(os.path.dirname(__file__), '../..')) + +from core.css import css_properties +import json5_generator +from name_utilities import enum_for_css_keyword +import template_expander + + +class CSSOMTypesWriter(json5_generator.Writer): + """ + Generates cssom_types.cc and cssom_keywords.cc. These classes provide + utility methods for determining whether a given CSSStyleValue is valid + for a given CSS property. The header files live in core/css/cssom. + """ + def __init__(self, json5_file_paths): + super(CSSOMTypesWriter, self).__init__([]) + + self._input_files = json5_file_paths + self._properties = ( + css_properties.CSSProperties(json5_file_paths)).longhands + + for property_ in self._properties: + types = [] + # Expand types + for single_type in property_['typedom_types']: + types.append(single_type) + property_['typedom_types'] = types + + # Generate Keyword ID values from keywords. + property_['keywordIDs'] = map( + enum_for_css_keyword, property_['keywords']) + + self._outputs = { + 'cssom_types.cc': self.generate_types, + 'cssom_keywords.cc': self.generate_keywords, + } + + @template_expander.use_jinja('core/css/templates/cssom_types.cc.tmpl') + def generate_types(self): + return { + 'input_files': self._input_files, + 'properties': self._properties, + } + + @template_expander.use_jinja('core/css/templates/cssom_keywords.cc.tmpl') + def generate_keywords(self): + return { + 'input_files': self._input_files, + 'properties': self._properties, + } + +if __name__ == '__main__': + json5_generator.Maker(CSSOMTypesWriter).main() diff --git a/chromium/third_party/blink/renderer/build/scripts/core/css/make_media_feature_names.py b/chromium/third_party/blink/renderer/build/scripts/core/css/make_media_feature_names.py new file mode 100755 index 00000000000..273aaba6a3c --- /dev/null +++ b/chromium/third_party/blink/renderer/build/scripts/core/css/make_media_feature_names.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python + +# Copyright 2014 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +import os +import sys +sys.path.append(os.path.join(os.path.dirname(__file__), '../..')) + +import json5_generator +import make_names +import media_feature_symbol + + +class MakeMediaFeatureNamesWriter(make_names.MakeNamesWriter): + pass + +MakeMediaFeatureNamesWriter.filters['symbol'] = media_feature_symbol.getMediaFeatureSymbolWithSuffix('MediaFeature') + +if __name__ == "__main__": + json5_generator.Maker(MakeMediaFeatureNamesWriter).main() diff --git a/chromium/third_party/blink/renderer/build/scripts/core/css/make_media_features.py b/chromium/third_party/blink/renderer/build/scripts/core/css/make_media_features.py new file mode 100755 index 00000000000..a01713ae939 --- /dev/null +++ b/chromium/third_party/blink/renderer/build/scripts/core/css/make_media_features.py @@ -0,0 +1,44 @@ +#!/usr/bin/env python + +# Copyright 2014 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +import os +import sys +sys.path.append(os.path.join(os.path.dirname(__file__), '../..')) + +import media_feature_symbol +import json5_generator +import template_expander +import name_utilities + + +class MakeMediaFeaturesWriter(json5_generator.Writer): + default_metadata = { + 'namespace': '', + 'export': '', + } + filters = { + 'symbol': media_feature_symbol.getMediaFeatureSymbolWithSuffix(''), + 'to_macro_style': name_utilities.to_macro_style, + 'upper_first_letter': name_utilities.upper_first_letter, + } + + def __init__(self, json5_file_path): + super(MakeMediaFeaturesWriter, self).__init__(json5_file_path) + + self._outputs = { + ('media_features.h'): self.generate_header, + } + self._template_context = { + 'entries': self.json5_file.name_dictionaries, + 'input_files': self._input_files, + } + + @template_expander.use_jinja('core/css/templates/media_features.h.tmpl', filters=filters) + def generate_header(self): + return self._template_context + +if __name__ == '__main__': + json5_generator.Maker(MakeMediaFeaturesWriter).main() 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 new file mode 100755 index 00000000000..edd4e2df805 --- /dev/null +++ b/chromium/third_party/blink/renderer/build/scripts/core/css/make_style_shorthands.py @@ -0,0 +1,89 @@ +#!/usr/bin/env python +# Copyright (C) 2013 Intel Corporation. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following disclaimer +# in the documentation and/or other materials provided with the +# distribution. +# * Neither the name of Google Inc. nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +import os +import sys +sys.path.append(os.path.join(os.path.dirname(__file__), '../..')) + +from core.css import css_properties +from collections import defaultdict +import json5_generator +from name_utilities import enum_for_css_property +import template_expander + + +class StylePropertyShorthandWriter(json5_generator.Writer): + class_name = 'StylePropertyShorthand' + + def __init__(self, json5_file_paths): + super(StylePropertyShorthandWriter, self).__init__([]) + self._input_files = json5_file_paths + self._outputs = { + 'style_property_shorthand.cc': + self.generate_style_property_shorthand_cpp, + 'style_property_shorthand.h': + self.generate_style_property_shorthand_h} + + json5_properties = css_properties.CSSProperties(json5_file_paths) + self._shorthands = json5_properties.shorthands + + self._longhand_dictionary = defaultdict(list) + for property_ in json5_properties.shorthands: + property_['longhand_property_ids'] = map( + enum_for_css_property, property_['longhands']) + for longhand in property_['longhand_property_ids']: + self._longhand_dictionary[longhand].append(property_) + + for longhands in self._longhand_dictionary.values(): + # Sort first by number of longhands in decreasing order, then + # alphabetically + longhands.sort( + key=lambda property_: ( + -len(property_['longhand_property_ids']), property_['name']) + ) + + @template_expander.use_jinja( + 'core/css/templates/style_property_shorthand.cc.tmpl') + def generate_style_property_shorthand_cpp(self): + return { + 'input_files': self._input_files, + 'properties': self._shorthands, + 'longhands_dictionary': self._longhand_dictionary, + } + + @template_expander.use_jinja( + 'core/css/templates/style_property_shorthand.h.tmpl') + def generate_style_property_shorthand_h(self): + return { + 'input_files': self._input_files, + 'properties': self._shorthands, + } + +if __name__ == '__main__': + json5_generator.Maker(StylePropertyShorthandWriter).main() diff --git a/chromium/third_party/blink/renderer/build/scripts/core/css/parser/make_atrule_names.py b/chromium/third_party/blink/renderer/build/scripts/core/css/parser/make_atrule_names.py new file mode 100755 index 00000000000..0c964b902f5 --- /dev/null +++ b/chromium/third_party/blink/renderer/build/scripts/core/css/parser/make_atrule_names.py @@ -0,0 +1,71 @@ +#!/usr/bin/env python +# Copyright 2017 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +import os +import sys +sys.path.append(os.path.join(os.path.dirname(__file__), '../../..')) + +import gperf +import json5_generator +import template_expander + +from name_utilities import upper_camel_case + + +class AtRuleNamesWriter(json5_generator.Writer): + """ + Generates AtRuleNames. This class provides utility methods for parsing + @rules (e.g. @font-face, @viewport, etc) + """ + def __init__(self, json5_file_paths): + super(AtRuleNamesWriter, self).__init__(json5_file_paths) + + self._outputs = { + 'at_rule_descriptors.h': self.generate_header, + 'at_rule_descriptors.cc': self.generate_implementation + } + + self._descriptors = self.json5_file.name_dictionaries + self._character_offsets = [] + + # AtRuleDescriptorID::Invalid is 0. + first_descriptor_id = 1 + # Aliases are resolved immediately at parse time, and thus don't appear + # in the enum. + self._descriptors_count = len(self._descriptors) + first_descriptor_id + chars_used = 0 + self._longest_name_length = 0 + for offset, descriptor in enumerate(self._descriptors): + descriptor['upper_camel_name'] = upper_camel_case( + descriptor['name']) + descriptor['enum_value'] = first_descriptor_id + offset + self._character_offsets.append(chars_used) + chars_used += len(descriptor['name']) + self._longest_name_length = max( + len(descriptor['name']), + len(descriptor['alias']), + self._longest_name_length) + + @template_expander.use_jinja( + 'core/css/parser/templates/at_rule_descriptors.h.tmpl') + def generate_header(self): + return { + 'descriptors': self._descriptors, + 'descriptors_count': self._descriptors_count + } + + @gperf.use_jinja_gperf_template( + 'core/css/parser/templates/at_rule_descriptors.cc.tmpl') + def generate_implementation(self): + return { + 'descriptors': self._descriptors, + 'descriptor_offsets': self._character_offsets, + 'descriptors_count': len(self._descriptors), + 'longest_name_length': self._longest_name_length, + 'gperf_path': self.gperf_path + } + +if __name__ == '__main__': + json5_generator.Maker(AtRuleNamesWriter).main() diff --git a/chromium/third_party/blink/renderer/build/scripts/core/css/parser/templates/at_rule_descriptors.cc.tmpl b/chromium/third_party/blink/renderer/build/scripts/core/css/parser/templates/at_rule_descriptors.cc.tmpl new file mode 100644 index 00000000000..14db20859de --- /dev/null +++ b/chromium/third_party/blink/renderer/build/scripts/core/css/parser/templates/at_rule_descriptors.cc.tmpl @@ -0,0 +1,108 @@ +%{ +// Copyright 2017 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "third_party/blink/renderer/core/css/parser/at_rule_descriptors.h" + +#include "third_party/blink/renderer/core/css/hash_tools.h" + +#ifdef _MSC_VER +// Disable the warnings from casting a 64-bit pointer to 32-bit long +// warning C4302: 'type cast': truncation from 'char (*)[28]' to 'long' +// warning C4311: 'type cast': pointer truncation from 'char (*)[18]' to 'long' +#pragma warning(disable : 4302 4311) +#endif + +namespace blink { + +namespace { + +%} + +%struct-type +struct Property; +%omit-struct-type +%language=C++ +%readonly-tables +%compare-strncmp +%define class-name AtRuleDescriptorHash +%define lookup-function-name findDescriptorImpl +%define hash-function-name descriptor_hash_function +%define slot-name name_offset +%define word-array-name descriptor_word_list +%pic +%enum +%% +{% for descriptor in descriptors %} +{{descriptor.name}}, static_cast<int>(AtRuleDescriptorID::{{descriptor.upper_camel_name}}) +{% if descriptor.alias %} +{{descriptor.alias}}, static_cast<int>(AtRuleDescriptorID::{{descriptor.upper_camel_name}}) +{% endif %} +{% endfor %} +%% + +const Property* FindDescriptor(const char* str, unsigned int len) { + return AtRuleDescriptorHash::findDescriptorImpl(str, len); +} + +template <typename CharacterType> +static AtRuleDescriptorID AsAtRuleDescriptorID( + const CharacterType* descriptor_name, + unsigned length) { + if (length == 0) + return AtRuleDescriptorID::Invalid; + if (length > {{longest_name_length}}) + return AtRuleDescriptorID::Invalid; + + char buffer[{{longest_name_length}} + 1]; // 1 for null character + + for (unsigned i = 0; i != length; ++i) { + CharacterType c = descriptor_name[i]; + if (c == 0 || c >= 0x7F) + return AtRuleDescriptorID::Invalid; // illegal character + buffer[i] = ToASCIILower(c); + } + buffer[length] = '\0'; + + const char* name = buffer; + const Property* hash_table_entry = FindDescriptor(name, length); + if (!hash_table_entry) + return AtRuleDescriptorID::Invalid; + return static_cast<AtRuleDescriptorID>(hash_table_entry->id); +} + +} // namespace + +AtRuleDescriptorID AsAtRuleDescriptorID(StringView string) { + unsigned length = string.length(); + return string.Is8Bit() + ? AsAtRuleDescriptorID(string.Characters8(), length) + : AsAtRuleDescriptorID(string.Characters16(), length); +} + +CSSPropertyID AtRuleDescriptorIDAsCSSPropertyID(AtRuleDescriptorID id) { + switch (id) { +{% for descriptor in descriptors %} + case AtRuleDescriptorID::{{descriptor.upper_camel_name}}: + return CSSProperty{{descriptor.upper_camel_name}}; +{% endfor %} + default: + NOTREACHED(); + return CSSPropertyInvalid; + } +} + +AtRuleDescriptorID CSSPropertyIDAsAtRuleDescriptor(CSSPropertyID id) { + switch (id) { +{% for descriptor in descriptors %} + case CSSProperty{{descriptor.upper_camel_name}}: + return AtRuleDescriptorID::{{descriptor.upper_camel_name}}; +{% endfor %} + default: + NOTREACHED(); + return AtRuleDescriptorID::Invalid; + } +} + +} // namespace blink diff --git a/chromium/third_party/blink/renderer/build/scripts/core/css/parser/templates/at_rule_descriptors.h.tmpl b/chromium/third_party/blink/renderer/build/scripts/core/css/parser/templates/at_rule_descriptors.h.tmpl new file mode 100644 index 00000000000..59694741efc --- /dev/null +++ b/chromium/third_party/blink/renderer/build/scripts/core/css/parser/templates/at_rule_descriptors.h.tmpl @@ -0,0 +1,32 @@ +// Copyright 2017 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef BLINK_CORE_CSS_PARSER_AT_RULE_DESCRIPTORS_H_ +#define BLINK_CORE_CSS_PARSER_AT_RULE_DESCRIPTORS_H_ + +#include "third_party/blink/renderer/core/css_property_names.h" +#include "third_party/blink/renderer/platform/wtf/text/string_view.h" +#include <string.h> + +namespace blink { + +enum class AtRuleDescriptorID { + Invalid = 0, +{% for descriptor in descriptors %} + {{descriptor.upper_camel_name}} = {{descriptor.enum_value}}, +{% endfor %} +}; + +const int numAtRuleDescriptors = {{descriptors_count}}; + +const char* getValueName(AtRuleDescriptorID); + +AtRuleDescriptorID AsAtRuleDescriptorID(StringView string); + +CSSPropertyID AtRuleDescriptorIDAsCSSPropertyID(AtRuleDescriptorID); +AtRuleDescriptorID CSSPropertyIDAsAtRuleDescriptor(CSSPropertyID id); + +} // namespace blink + +#endif // BLINK_CORE_CSS_PARSER_AT_RULE_DESCRIPTORS_H_ diff --git a/chromium/third_party/blink/renderer/build/scripts/core/css/properties/make_css_property_base.py b/chromium/third_party/blink/renderer/build/scripts/core/css/properties/make_css_property_base.py new file mode 100755 index 00000000000..5eb812eaf43 --- /dev/null +++ b/chromium/third_party/blink/renderer/build/scripts/core/css/properties/make_css_property_base.py @@ -0,0 +1,125 @@ +#!/usr/bin/env python +# Copyright 2016 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +import os +import sys +sys.path.append(os.path.join(os.path.dirname(__file__), '../../..')) + +import json5_generator +import template_expander + +from collections import namedtuple +from core.css import css_properties +from name_utilities import snake_case + + +class PropertyClassData( + namedtuple('PropertyClassData', 'enum_value,property_id,classname,namespace_group,filename')): + pass + + +class CSSPropertyBaseWriter(json5_generator.Writer): + def __init__(self, json5_file_paths): + super(CSSPropertyBaseWriter, self).__init__([]) + self._input_files = json5_file_paths + self._outputs = { + 'css_unresolved_property.h': self.generate_unresolved_property_header, + 'css_unresolved_property.cc': + self.generate_unresolved_property_implementation, + 'css_property.h': self.generate_resolved_property_header, + 'css_property.cc': self.generate_resolved_property_implementation, + } + + self._css_properties = css_properties.CSSProperties(json5_file_paths) + + # A list of (enum_value, property_id, property_classname) tuples. + self._property_classes_by_id = [] + self._alias_classes_by_id = [] + # Just a set of class names. + self._shorthand_property_filenames = set() + self._longhand_property_filenames = set() + for property_ in self._css_properties.longhands: + property_class = self.get_class(property_) + self._property_classes_by_id.append(property_class) + if property_class.classname != 'Longhand': + self._longhand_property_filenames.add(property_class.filename) + for property_ in self._css_properties.shorthands: + property_class = self.get_class(property_) + self._property_classes_by_id.append(property_class) + self._shorthand_property_filenames.add(property_class.filename) + for property_ in self._css_properties.aliases: + property_class = self.get_class(property_) + self._alias_classes_by_id.append(property_class) + if property_['longhands']: + self._shorthand_property_filenames.add(property_class.filename) + elif property_class.classname != 'Longhand': + self._longhand_property_filenames.add(property_class.filename) + + # Sort by enum value. + self._property_classes_by_id.sort(key=lambda t: t.enum_value) + self._alias_classes_by_id.sort(key=lambda t: t.enum_value) + + def get_class(self, property_): + """Gets the automatically + generated class name for a property. + Args: + property_: A single property from CSSProperties.properties() + Returns: + The name to use for the property class. + """ + namespace_group = 'Shorthand' if property_['longhands'] else 'Longhand' + return PropertyClassData( + enum_value=property_['enum_value'], + property_id=property_['property_id'], + classname=property_['upper_camel_name'], + namespace_group=namespace_group, + filename=snake_case(property_['upper_camel_name'])) + + @property + def css_properties(self): + return self._css_properties + + @template_expander.use_jinja( + 'core/css/properties/templates/css_unresolved_property.h.tmpl') + def generate_unresolved_property_header(self): + return { + 'input_files': self._input_files, + 'property_classes_by_property_id': self._property_classes_by_id, + 'alias_classes_by_property_id': self._alias_classes_by_id, + } + + @template_expander.use_jinja( + 'core/css/properties/templates/css_unresolved_property.cc.tmpl') + def generate_unresolved_property_implementation(self): + return { + 'input_files': self._input_files, + 'longhand_property_filenames': self._longhand_property_filenames, + 'shorthand_property_filenames': self._shorthand_property_filenames, + 'property_classes_by_property_id': self._property_classes_by_id, + 'alias_classes_by_property_id': self._alias_classes_by_id, + 'last_unresolved_property_id': + self._css_properties.last_unresolved_property_id, + 'last_property_id': self._css_properties.last_property_id + } + + @template_expander.use_jinja( + 'core/css/properties/templates/css_property.cc.tmpl') + def generate_resolved_property_implementation(self): + return { + 'input_files': self._input_files, + 'property_classes_by_property_id': self._property_classes_by_id, + 'last_property_id': self._css_properties.last_property_id + } + + @template_expander.use_jinja( + 'core/css/properties/templates/css_property.h.tmpl') + def generate_resolved_property_header(self): + return { + 'input_files': self._input_files, + 'property_classes_by_property_id': self._property_classes_by_id, + } + +if __name__ == '__main__': + json5_generator.Maker(CSSPropertyBaseWriter).main() diff --git a/chromium/third_party/blink/renderer/build/scripts/core/css/properties/make_css_property_subclasses.py b/chromium/third_party/blink/renderer/build/scripts/core/css/properties/make_css_property_subclasses.py new file mode 100755 index 00000000000..972829eeb48 --- /dev/null +++ b/chromium/third_party/blink/renderer/build/scripts/core/css/properties/make_css_property_subclasses.py @@ -0,0 +1,187 @@ +#!/usr/bin/env python +# Copyright 2017 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +import os +import sys +sys.path.append(os.path.join(os.path.dirname(__file__), '../../..')) + +import json5_generator +import template_expander + +from collections import namedtuple +from make_css_property_base import CSSPropertyBaseWriter + + +class PropertyMethod(namedtuple('PropertyMethod', 'name,return_type,parameters')): + pass + + +class CSSPropertiesWriter(CSSPropertyBaseWriter): + def __init__(self, json5_file_paths): + super(CSSPropertiesWriter, self).__init__(json5_file_paths) + assert len(json5_file_paths) == 3,\ + ('CSSPropertiesWriter requires 3 input json5 files, ' + + 'got {}.'.format(len(json5_file_paths))) + + self.template_cache = {} + + # Map of property method name -> (return_type, parameters) + self._property_methods = {} + property_methods = json5_generator.Json5File.load_from_files( + [json5_file_paths[2]]) + for property_method in property_methods.name_dictionaries: + self._property_methods[property_method['name']] = PropertyMethod( + name=property_method['name'], + return_type=property_method['return_type'], + parameters=property_method['parameters'], + ) + + self._outputs = {} + output_dir = sys.argv[sys.argv.index('--output_dir') + 1] + properties = self.css_properties.longhands + namespace_group = 'Longhand' + if 'shorthands' in output_dir: + properties = self.css_properties.shorthands + namespace_group = 'Shorthand' + for property_ in properties: + property_['property_methods'] = [ + self._property_methods[method_name] + for method_name in property_['property_methods'] + ] + property_['namespace_group'] = namespace_group + class_data = self.get_class(property_) + self.calculate_apply_functions_to_declare(property_) + self._outputs[class_data.filename + '.h'] = ( + self.generate_property_h_builder( + class_data.classname, class_data.filename, property_)) + if 'should_implement_apply_functions_in_cpp' in property_: + self._outputs[class_data.filename + '.cc'] = ( + self.generate_property_cpp_builder( + class_data.filename, property_)) + for property_ in self.css_properties.aliases: + if ('shorthands' in output_dir and property_['longhands']) or \ + ('longhands' in output_dir and not property_['longhands']): + class_data = self.get_class(property_) + property_['namespace_group'] = namespace_group + self._outputs[class_data.filename + '.h'] = ( + self.generate_property_h_builder( + class_data.classname, class_data.filename, property_)) + + def generate_property_h_builder(self, property_classname, property_filename, property_): + @template_expander.use_jinja( + 'core/css/properties/templates/css_property_subclass.h.tmpl', + template_cache=self.template_cache) + def generate_property_h(): + return { + 'input_files': self._input_files, + 'property_classname': property_classname, + 'property_filename': property_filename, + 'property': property_, + 'includes': sorted(list(self.h_includes(property_))) + } + return generate_property_h + + def generate_property_cpp_builder(self, property_filename, property_): + @template_expander.use_jinja( + 'core/css/properties/templates/css_property_subclass.cc.tmpl', + template_cache=self.template_cache) + def generate_property_cpp(): + return { + 'input_files': self._input_files, + 'property_filename': property_filename, + 'property': property_, + 'includes': sorted(list(self.cpp_includes(property_))) + } + return generate_property_cpp + + def calculate_apply_functions_to_declare(self, property_): + if property_['custom_apply_functions_all']: + property_name = property_['upper_camel_name'] + if (property_name in ['Clip', 'ColumnCount', 'ColumnWidth', 'ZIndex']): + property_['custom_apply'] = "auto" + property_['custom_apply_args'] = {'auto_identity': 'CSSValueAuto'} + elif (property_name in [ + 'BorderImageOutset', 'BorderImageRepeat', 'BorderImageSlice', 'BorderImageWidth', 'WebkitMaskBoxImageOutset', + 'WebkitMaskBoxImageRepeat', 'WebkitMaskBoxImageSlice', 'WebkitMaskBoxImageWidth']): + property_['custom_apply'] = 'border_image' + is_mask_box = 'WebkitMaskBox' in property_name + getter = 'MaskBoxImage' if is_mask_box else 'BorderImage' + modifier_type = property_name[len('WebkitMaskBoxImage'):] if is_mask_box else property_name[len('BorderImage'):] + property_['custom_apply_args'] = { + 'is_mask_box': is_mask_box, + 'modifier_type': modifier_type, + 'getter': getter, + 'setter': 'Set' + getter + } + elif (property_name in [ + 'BackgroundAttachment', 'BackgroundBlendMode', 'BackgroundClip', 'BackgroundImage', 'BackgroundOrigin', + 'BackgroundPositionX', 'BackgroundPositionY', 'BackgroundRepeatX', 'BackgroundRepeatY', 'BackgroundSize', + 'MaskSourceType', 'WebkitMaskClip', 'WebkitMaskComposite', 'WebkitMaskImage', 'WebkitMaskOrigin', + 'WebkitMaskPositionX', 'WebkitMaskPositionY', 'WebkitMaskRepeatX', 'WebkitMaskRepeatY', 'WebkitMaskSize']): + fill_type = property_name if property_name == 'MaskSourceType' else property_name[len('Background'):] + property_['custom_apply'] = 'fill_layer' + property_['should_implement_apply_functions_in_cpp'] = True + property_['custom_apply_args'] = { + 'layer_type': 'Background' if 'Background' in property_name else 'Mask', + 'fill_type': fill_type, + 'fill_type_getter': 'Get' + fill_type if fill_type == "Image" else fill_type + } + property_['should_implement_apply_functions'] = ( + property_['is_property'] and + not property_['longhands'] and + not property_['direction_aware_options'] and + not property_['builder_skip'] and + (not (property_['custom_apply_functions_initial'] and + property_['custom_apply_functions_inherit'] and + property_['custom_apply_functions_value']) or + 'custom_apply' in property_)) + + def h_includes(self, property_): + if property_['alias_for']: + yield "core/css/properties/css_unresolved_property.h" + else: + yield "core/css/properties/" + property_['namespace_group'].lower() + ".h" + if property_['direction_aware_options']: + yield "core/style_property_shorthand.h" + if property_['runtime_flag']: + yield "platform/runtime_enabled_features.h" + if property_['should_implement_apply_functions']: + for include in self.apply_includes(property_): + yield include + + def cpp_includes(self, property_): + if 'should_implement_apply_functions_in_cpp' in property_: + for include in self.apply_includes(property_): + yield include + + def apply_includes(self, property_): + yield "core/css/resolver/style_resolver_state.h" + yield "core/css/css_primitive_value_mappings.h" + if property_['converter'] == "CSSPrimitiveValue": + yield "core/css/css_primitive_value.h" + yield "core/css/css_primitive_value_mappings.h" + elif property_['converter'] == "CSSIdentifierValue": + yield "core/css/css_identifier_value.h" + else: + yield "core/css/css_primitive_value_mappings.h" + yield "core/css/resolver/style_builder_converter.h" + if property_['font']: + yield "core/css/resolver/font_builder.h" + elif property_['svg']: + yield "core/css/css_primitive_value_mappings.h" + yield "core/style/computed_style.h" + yield "core/style/svg_computed_style.h" + else: + yield "core/style/computed_style.h" + if ('custom_apply_args' in property_ and + property_['custom_apply_args'].get('modifier_type') + in ['Width', 'Slice', 'Outset']): + yield "core/css/properties/style_building_utils.h" + if property_.get('custom_apply') == "fill_layer": + yield "core/css/css_value_list.h" + + +if __name__ == '__main__': + json5_generator.Maker(CSSPropertiesWriter).main() diff --git a/chromium/third_party/blink/renderer/build/scripts/core/css/properties/templates/css_property.cc.tmpl b/chromium/third_party/blink/renderer/build/scripts/core/css/properties/templates/css_property.cc.tmpl new file mode 100644 index 00000000000..ffce5b5574f --- /dev/null +++ b/chromium/third_party/blink/renderer/build/scripts/core/css/properties/templates/css_property.cc.tmpl @@ -0,0 +1,29 @@ +// Copyright 2017 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +{% from 'templates/macros.tmpl' import source_files_for_generated_file %} +{{source_files_for_generated_file(template_file, input_files)}} +// clang-format off + +#include "third_party/blink/renderer/core/css/properties/css_property.h" + +namespace blink { + +const CSSProperty& GetCSSPropertyVariable() { + return ToCSSProperty(CSSUnresolvedProperty::GetCSSPropertyVariableInternal()); +} +{% for property_class_data in property_classes_by_property_id %} +const CSSProperty& Get{{property_class_data.property_id}}() { + return ToCSSProperty(CSSUnresolvedProperty::Get{{property_class_data.property_id}}Internal()); +} +{% endfor %} + +const CSSProperty& CSSProperty::Get(CSSPropertyID id) { + DCHECK_NE(id, CSSPropertyInvalid); + DCHECK_LE(id, {{last_property_id}}); // last property id + return ToCSSProperty(CSSUnresolvedProperty::GetNonAliasProperty(id)); +} + +} // namespace blink + diff --git a/chromium/third_party/blink/renderer/build/scripts/core/css/properties/templates/css_property.h.tmpl b/chromium/third_party/blink/renderer/build/scripts/core/css/properties/templates/css_property.h.tmpl new file mode 100644 index 00000000000..6e5f8ea72ae --- /dev/null +++ b/chromium/third_party/blink/renderer/build/scripts/core/css/properties/templates/css_property.h.tmpl @@ -0,0 +1,149 @@ +// Copyright 2017 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +{% from 'templates/macros.tmpl' import source_files_for_generated_file %} +{{source_files_for_generated_file(template_file, input_files)}} +// clang-format off + +#ifndef BLINK_CORE_CSS_PROPERTY_H_ +#define BLINK_CORE_CSS_PROPERTY_H_ + +#include "third_party/blink/renderer/core/css_property_names.h" +#include "third_party/blink/renderer/core/css/css_value.h" +#include "third_party/blink/renderer/core/css/properties/css_unresolved_property.h" +#include "third_party/blink/renderer/platform/heap/heap_allocator.h" +#include "third_party/blink/renderer/platform/text/text_direction.h" +#include "third_party/blink/renderer/platform/text/writing_mode.h" +#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h" + +namespace blink { + +class ComputedStyle; +class CSSParserContext; +class CSSParserLocalContext; +class CSSParserTokenRange; +class LayoutObject; +class Longhand; +class Shorthand; +class SVGComputedStyle; +class StylePropertyShorthand; + +enum PhysicalBoxSide { kTopSide, kRightSide, kBottomSide, kLeftSide }; + +class CSSProperty : public CSSUnresolvedProperty { + public: + CORE_EXPORT static const CSSProperty& Get(CSSPropertyID); + + // For backwards compatibility when passing around CSSUnresolvedProperty + // references. In case we need to call a function that hasn't been converted + // to using property classes yet. + virtual CSSPropertyID PropertyID() const { + NOTREACHED(); + return CSSPropertyInvalid; + } + bool IDEquals(CSSPropertyID id) const { return PropertyID() == id; } + bool IsResolvedProperty() const override { return true; } + virtual const WTF::String GetJSPropertyName() const { + NOTREACHED(); + return g_empty_string; + } + virtual bool IsInterpolable() const { return false; } + virtual bool IsInherited() const { return false; } + virtual bool IsCompositableProperty() const { return false; } + virtual bool IsRepeated() const { return false; } + virtual char RepetitionSeparator() const { + NOTREACHED(); + return 0; + } + virtual bool IsDescriptor() const { return false; } + virtual bool SupportsPercentage() const { return false; } + virtual bool IsProperty() const { return true; } + virtual bool IsEnabled() const { return true; } + virtual bool IsAffectedByAll() const { return IsEnabled() && IsProperty(); } + virtual bool IsLayoutDependentProperty() const { return false; } + virtual bool IsLayoutDependent(const ComputedStyle* style, LayoutObject* layout_object) const { return false; } + + // Properties that do not override this method: + // CSSPropertyWebkitFontSizeDelta + // CSSPropertyWebkitTextEmphasis + // CSSPropertyFontDisplay + // CSSPropertySrc + // CSSPropertyUnicodeRange + // CSSPropertyPage + // CSSPropertySize + // CSSPropertyWebkitMarginCollapse + // CSSPropertyWebkitMask + // CSSPropertyWebkitMaskRepeatX + // CSSPropertyWebkitMaskRepeatY + // CSSPropertyWebkitPerspectiveOriginX + // CSSPropertyWebkitPerspectiveOriginY + // CSSPropertyWebkitTextStroke + // CSSPropertyWebkitTransformOriginX + // CSSPropertyWebkitTransformOriginY + // CSSPropertyWebkitTransformOriginZ + // CSSPropertyMaxZoom + // CSSPropertyMinZoom + // CSSPropertyOrientation + // CSSPropertyUserZoom + // CSSPropertyMarker + // CSSPropertyAll + // CSSPropertyVariable (Variables are retrieved via Get(AtomicString)) + virtual const CSSValue* CSSValueFromComputedStyleInternal(const ComputedStyle&, + const SVGComputedStyle&, + const LayoutObject*, + Node*, + bool allow_visited_style) const { return nullptr; } + // FIXME: Resolve computed auto alignment in applyProperty/ComputedStyle and + // remove this non-const Node parameter. + CORE_EXPORT const CSSValue* CSSValueFromComputedStyle(const ComputedStyle&, + const LayoutObject*, + Node*, + bool allow_visited_style) const; + virtual const CSSProperty& ResolveDirectionAwareProperty( + TextDirection, + WritingMode) const { + return *this; + } + virtual bool IsShorthand() const { return false; } + virtual bool IsLonghand() const { return false; } + static void FilterEnabledCSSPropertiesIntoVector(const CSSPropertyID*, + size_t length, + Vector<const CSSProperty*>&); + + protected: + constexpr CSSProperty() : CSSUnresolvedProperty() {} + + static const StylePropertyShorthand& BorderDirections(); + static const CSSProperty& ResolveAfterToPhysicalProperty( + TextDirection, + WritingMode, + const StylePropertyShorthand&); + static const CSSProperty& ResolveBeforeToPhysicalProperty( + TextDirection, + WritingMode, + const StylePropertyShorthand&); + static const CSSProperty& ResolveEndToPhysicalProperty( + TextDirection, + WritingMode, + const StylePropertyShorthand&); + static const CSSProperty& ResolveStartToPhysicalProperty( + TextDirection, + WritingMode, + const StylePropertyShorthand&); +}; + +DEFINE_TYPE_CASTS(CSSProperty, + CSSUnresolvedProperty, + unresolved, + unresolved->IsResolvedProperty(), + unresolved.IsResolvedProperty()); + +CORE_EXPORT const CSSProperty& GetCSSPropertyVariable(); +{% for property_class_data in property_classes_by_property_id %} +CORE_EXPORT const CSSProperty& Get{{property_class_data.property_id}}(); +{% endfor %} + +} // namespace blink + +#endif // BLINK_CORE_CSS_PROPERTY_H_ diff --git a/chromium/third_party/blink/renderer/build/scripts/core/css/properties/templates/css_property_subclass.cc.tmpl b/chromium/third_party/blink/renderer/build/scripts/core/css/properties/templates/css_property_subclass.cc.tmpl new file mode 100644 index 00000000000..481236ffc6e --- /dev/null +++ b/chromium/third_party/blink/renderer/build/scripts/core/css/properties/templates/css_property_subclass.cc.tmpl @@ -0,0 +1,82 @@ +// Copyright 2017 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +{% from 'core/css/properties/templates/style_builder_functions.tmpl' import declare_initial, declare_inherit, declare_value %} +{% from 'templates/macros.tmpl' import source_files_for_generated_file %} +{{source_files_for_generated_file(template_file, input_files)}} + +#include "core/css/properties/{{property.namespace_group.lower()}}s/{{property_filename}}.h" + +{% for include in includes %} +#include "{{include}}" +{% endfor %} + +namespace blink { +namespace CSSLonghand { + +{% if property.custom_apply == "fill_layer" %} +{% set layer_type = property.custom_apply_args['layer_type'] %} +{% set fill_type = property.custom_apply_args['fill_type'] %} +{{declare_initial(property.upper_camel_name)}} { + FillLayer* currChild = &state.Style()->Access{{layer_type}}Layers(); + currChild->Set{{fill_type}}(FillLayer::InitialFill{{fill_type}}(EFillLayerType::k{{layer_type}})); + for (currChild = currChild->Next(); currChild; currChild = currChild->Next()) + currChild->Clear{{fill_type}}(); +} + +{{declare_inherit(property.upper_camel_name)}} { + FillLayer* currChild = &state.Style()->Access{{layer_type}}Layers(); + FillLayer* prevChild = 0; + const FillLayer* currParent = &state.ParentStyle()->{{layer_type}}Layers(); + while (currParent && currParent->Is{{fill_type}}Set()) { + if (!currChild) + currChild = prevChild->EnsureNext(); + currChild->Set{{fill_type}}(currParent->{{property.custom_apply_args['fill_type_getter']}}()); + {% if fill_type == "PositionX" %} + if (currParent->IsBackgroundXOriginSet()) + currChild->SetBackgroundXOrigin(currParent->BackgroundXOrigin()); + {% endif %} + {% if fill_type == "PositionY" %} + if (currParent->IsBackgroundYOriginSet()) + currChild->SetBackgroundYOrigin(currParent->BackgroundYOrigin()); + {% endif %} + prevChild = currChild; + currChild = prevChild->Next(); + currParent = currParent->Next(); + } + + while (currChild) { + // Reset any remaining layers to not have the property set. + currChild->Clear{{fill_type}}(); + currChild = currChild->Next(); + } +} + +{{declare_value(property.upper_camel_name)}} { + FillLayer* currChild = &state.Style()->Access{{layer_type}}Layers(); + FillLayer* prevChild = 0; + if (value.IsValueList() && !value.IsImageSetValue()) { + // Walk each value and put it into a layer, creating new layers as needed. + const CSSValueList& valueList = ToCSSValueList(value); + for (unsigned int i = 0; i < valueList.length(); i++) { + if (!currChild) + currChild = prevChild->EnsureNext(); + CSSToStyleMap::MapFill{{fill_type}}(state, currChild, valueList.Item(i)); + prevChild = currChild; + currChild = currChild->Next(); + } + } else { + CSSToStyleMap::MapFill{{fill_type}}(state, currChild, value); + currChild = currChild->Next(); + } + while (currChild) { + // Reset all remaining layers to not have the property set. + currChild->Clear{{fill_type}}(); + currChild = currChild->Next(); + } +} +{% endif %} + +} // namespace CSSLonghand +} // namespace blink diff --git a/chromium/third_party/blink/renderer/build/scripts/core/css/properties/templates/css_property_subclass.h.tmpl b/chromium/third_party/blink/renderer/build/scripts/core/css/properties/templates/css_property_subclass.h.tmpl new file mode 100644 index 00000000000..0063da3f592 --- /dev/null +++ b/chromium/third_party/blink/renderer/build/scripts/core/css/properties/templates/css_property_subclass.h.tmpl @@ -0,0 +1,133 @@ +// Copyright 2016 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +{% from 'templates/macros.tmpl' import source_files_for_generated_file %} +{% from 'core/css/properties/templates/style_builder_functions.tmpl' import style_builder_functions %} +{{source_files_for_generated_file(template_file, input_files)}} + +#ifndef GEN_BLINK_CORE_CSS_PROPERTIES_{{property.namespace_group.upper()}}_{{property_filename|upper}}_H_ +#define GEN_BLINK_CORE_CSS_PROPERTIES_{{property.namespace_group.upper()}}_{{property_filename|upper}}_H_ + +{% for include in includes %} +#include "{{include}}" +{% endfor %} + +namespace blink { +namespace CSS{{property.namespace_group}} { + +{% if property.is_property %} +// Implements the '{{property.name}}' CSS property +{% else %} +// Implements the '{{property.name}}' CSS descriptor +{% endif %} +// See src/third_party/WebKit/Source/core/css/properties/README.md + {% if property.alias_for != None%} +class {{property_classname}} final : public CSSUnresolvedProperty { + public: + constexpr {{property_classname}}() : CSSUnresolvedProperty() {} + {% else %} +class {{property_classname}} final : public {{property.namespace_group}} { + public: + constexpr {{property_classname}}() : {{property.namespace_group}}() {} + {% endif %} + const char* GetPropertyName() const override { return "{{property.name}}\0"; } + const WTF::AtomicString& GetPropertyNameAtomicString() const override { + static const WTF::AtomicString& name = WTF::AtomicString("{{property.name}}\0"); + return name; + } + {% if property.alias_for == None %} + const WTF::String GetJSPropertyName() const override { + return WTF::String("{{property_classname[0].lower() + property_classname[1:]}}\0"); + } + CSSPropertyID PropertyID() const override { return {{property.property_id}}; } + {%if property.layout_dependent %} + bool IsLayoutDependentProperty() const override { return true; } + bool IsLayoutDependent(const ComputedStyle*, LayoutObject*) const override; + {% endif %} + {% for property_method in property.property_methods %} + {{property_method.return_type}} {{property_method.name}}{{property_method.parameters}} const override; + {% endfor %} + {% if property.interpolable %} + bool IsInterpolable() const override { return true; } + {% endif %} + {% if property.inherited %} + bool IsInherited() const override { return true; } + {% endif %} + {% if property.compositable %} + bool IsCompositableProperty() const override { return true; } + {% endif %} + {% if property.separator != None %} + bool IsRepeated() const override { return true; } + char RepetitionSeparator() const override { return '{{property.separator}}'; } + {% endif %} + {% if property.is_descriptor %} + bool IsDescriptor() const override { return true; } + {% endif %} + {% if 'Percent' in property.typedom_types %} + bool SupportsPercentage() const override { return true; } + {% endif %} + {% if not property.is_property %} + bool IsProperty() const override { return false; } + {% endif %} + {% if property.is_internal %} + bool IsEnabled() const override { return false; } + {% elif property.runtime_flag %} + bool IsEnabled() const override { + return RuntimeEnabledFeatures::{{property.runtime_flag}}Enabled(); + } + {% endif %} + {% if not property.affected_by_all %} + bool IsAffectedByAll() const override { return false; } + {% endif %} + {% if property.direction_aware_options %} + const CSSValue* CSSValueFromComputedStyleInternal( + const ComputedStyle& , + const SVGComputedStyle&, + const LayoutObject*, + Node*, + bool allow_visited_style) const override { + // Directional properties are resolved by resolveDirectionAwareProperty() + // before calling CSSValueFromComputedStyleInternal. + NOTREACHED(); + return nullptr; + } + {% if property.direction_aware_options.logical_side == "width" %} + const CSSProperty& ResolveDirectionAwareProperty( + TextDirection direction, + blink::WritingMode writing_mode) const override { + if (IsHorizontalWritingMode(writing_mode)) + return Get{{property.direction_aware_options.shorthand_for_physical_side}}Width(); + return Get{{property.direction_aware_options.shorthand_for_physical_side}}Height(); + } + {% elif property.direction_aware_options.logical_side == "height" %} + const CSSProperty& ResolveDirectionAwareProperty( + TextDirection direction, + blink::WritingMode writing_mode) const override { + if (IsHorizontalWritingMode(writing_mode)) + return Get{{property.direction_aware_options.shorthand_for_physical_side}}Height(); + return Get{{property.direction_aware_options.shorthand_for_physical_side}}Width(); + } + {% else %} + const CSSProperty& ResolveDirectionAwareProperty( + TextDirection direction, + blink::WritingMode writing_mode) const override { + return Resolve{{property.direction_aware_options.logical_side[0].upper() + property.direction_aware_options.logical_side[1:]}}ToPhysicalProperty( + direction, + writing_mode, + {{property.direction_aware_options.shorthand_for_physical_side}}()); + } + {% endif %} + {% endif %} + {% if property.should_implement_apply_functions %} + + // Style builder functions +{{style_builder_functions(property)}} + {%- endif %} + {% endif %} +}; + +} // namespace CSS{{property.namespace_group}} +} // namespace blink + +#endif // GEN_BLINK_CORE_CSS_PROPERTIES_{{property.namespace_group.upper()}}_{{property_filename|upper}}_H_ diff --git a/chromium/third_party/blink/renderer/build/scripts/core/css/properties/templates/css_unresolved_property.cc.tmpl b/chromium/third_party/blink/renderer/build/scripts/core/css/properties/templates/css_unresolved_property.cc.tmpl new file mode 100644 index 00000000000..d1e21d0d9c0 --- /dev/null +++ b/chromium/third_party/blink/renderer/build/scripts/core/css/properties/templates/css_unresolved_property.cc.tmpl @@ -0,0 +1,78 @@ +// Copyright 2017 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +{% from 'templates/macros.tmpl' import source_files_for_generated_file %} +{{source_files_for_generated_file(template_file, input_files)}} +// clang-format off + +#include "third_party/blink/renderer/core/css/properties/css_unresolved_property.h" + +#include "third_party/blink/renderer/core/css/properties/longhands/variable.h" +{% for property_filename in longhand_property_filenames %} + {% if property_filename != "longhand" %} +#include "core/css/properties/longhands/{{property_filename}}.h" + {% endif %} +{% endfor %} +{% for property_filename in shorthand_property_filenames %} +#include "core/css/properties/shorthands/{{property_filename}}.h" +{% endfor %} + +namespace blink { +namespace { + +static constexpr Variable property_csspropertyvariable; +{% for _, property_id, classname, namespace_group, _ in property_classes_by_property_id %} +static constexpr CSS{{namespace_group}}::{{classname}} property_{{property_id.lower()}}; +{% endfor %} +{% for _, property_id, classname, namespace_group, _ in alias_classes_by_property_id %} +static constexpr CSS{{namespace_group}}::{{classname}} property_{{property_id.lower()}}; +{% endfor %} + +} // namespace + +const CSSUnresolvedProperty& CSSUnresolvedProperty::GetCSSPropertyVariableInternal() { + return property_csspropertyvariable; +} +{% for property_class_data in property_classes_by_property_id %} +const CSSUnresolvedProperty& CSSUnresolvedProperty::Get{{property_class_data.property_id}}Internal() { + return property_{{property_class_data.property_id.lower()}}; +} +{% endfor %} + +const CSSUnresolvedProperty* CSSUnresolvedProperty::GetAliasProperty(CSSPropertyID id) { + DCHECK_GT(id, {{last_property_id}}); // last property id + DCHECK_LE(id, {{last_unresolved_property_id}}); // last unresolved property id + switch (id) { + {% for property_class_data in alias_classes_by_property_id %} + case {{property_class_data.property_id}}: + return &property_{{property_class_data.property_id.lower()}}; + {% endfor %} + default: + NOTREACHED(); + return nullptr; + } +} + +const CSSUnresolvedProperty& CSSUnresolvedProperty::GetNonAliasProperty(CSSPropertyID id) { + DCHECK_NE(id, CSSPropertyInvalid); + DCHECK_LE(id, {{last_property_id}}); // last property id + static constexpr const CSSUnresolvedProperty* const property_classes[] = { + &property_csspropertyvariable, // CSSPropertyVariable + {% for property_class_data in property_classes_by_property_id %} + &property_{{property_class_data.property_id.lower()}}, // {{property_class_data.property_id}} + {% endfor %} + }; + // Subtract 1 because CSSPropertyInvalid does not appear in the array. + return *property_classes[id - 1]; +} + +const CSSUnresolvedProperty& CSSUnresolvedProperty::Get(CSSPropertyID id) { + DCHECK_NE(id, CSSPropertyInvalid); + DCHECK_LE(id, {{last_unresolved_property_id}}); // last_unresolved_property_id + if (id <= {{last_property_id}}) // last property id + return GetNonAliasProperty(id); + return *GetAliasProperty(id); +} + +} // namespace blink diff --git a/chromium/third_party/blink/renderer/build/scripts/core/css/properties/templates/css_unresolved_property.h.tmpl b/chromium/third_party/blink/renderer/build/scripts/core/css/properties/templates/css_unresolved_property.h.tmpl new file mode 100644 index 00000000000..a4841bed503 --- /dev/null +++ b/chromium/third_party/blink/renderer/build/scripts/core/css/properties/templates/css_unresolved_property.h.tmpl @@ -0,0 +1,52 @@ +// Copyright 2017 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +{% from 'templates/macros.tmpl' import source_files_for_generated_file %} +{{source_files_for_generated_file(template_file, input_files)}} +// clang-format off + +#ifndef BLINK_CORE_CSS_UNRESOLVED_PROPERTY_H_ +#define BLINK_CORE_CSS_UNRESOLVED_PROPERTY_H_ + +#include "third_party/blink/renderer/core/css_property_names.h" +#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h" + +namespace blink { + +// TODO(crbug.com/793288): audit and consider redesigning how aliases are +// handled once more of project Ribbon is done and all use of aliases can be +// found and (hopefully) constrained. +class CSSUnresolvedProperty { + public: + CORE_EXPORT static const CSSUnresolvedProperty& Get(CSSPropertyID); + + virtual bool IsResolvedProperty() const { return false; } + virtual const char* GetPropertyName() const { + NOTREACHED(); + return nullptr; + } + virtual const WTF::AtomicString& GetPropertyNameAtomicString() const { + NOTREACHED(); + return g_empty_atom; + } + WTF::String GetPropertyNameString() const { + // We share the StringImpl with the AtomicStrings. + return GetPropertyNameAtomicString().GetString(); + } + + static const CSSUnresolvedProperty& GetCSSPropertyVariableInternal(); + {% for property_class_data in property_classes_by_property_id %} + static const CSSUnresolvedProperty& Get{{property_class_data.property_id}}Internal(); + {% endfor %} + + CORE_EXPORT static const CSSUnresolvedProperty* GetAliasProperty(CSSPropertyID); + + protected: + constexpr CSSUnresolvedProperty() {} + static const CSSUnresolvedProperty& GetNonAliasProperty(CSSPropertyID); +}; + +} // namespace blink + +#endif // BLINK_CORE_CSS_UNRESOLVED_PROPERTY_H_ diff --git a/chromium/third_party/blink/renderer/build/scripts/core/css/properties/templates/style_builder_functions.tmpl b/chromium/third_party/blink/renderer/build/scripts/core/css/properties/templates/style_builder_functions.tmpl new file mode 100644 index 00000000000..36b37a9be76 --- /dev/null +++ b/chromium/third_party/blink/renderer/build/scripts/core/css/properties/templates/style_builder_functions.tmpl @@ -0,0 +1,184 @@ +// Copyright 2017 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +{% macro declare_initial(prefix = None) %} +void {{prefix ~ '::' if prefix}}ApplyInitial(StyleResolverState& state) const{{' override' if not prefix}} +{%- endmacro %} +{% macro declare_inherit(prefix = None) %} +void {{prefix ~ '::' if prefix}}ApplyInherit(StyleResolverState& state) const{{' override' if not prefix}} +{%- endmacro %} +{% macro declare_value(prefix = None) %} +void {{prefix ~ '::' if prefix}}ApplyValue(StyleResolverState& state, const CSSValue& value) const{{' override' if not prefix}} +{%- endmacro %} + +{% macro set_value(property) %} + {% if property.svg %} +state.Style()->AccessSVGStyle().{{property.setter}} + {%- elif property.font %} +state.GetFontBuilder().{{property.setter}} + {%- else %} +state.Style()->{{property.setter}} + {%- endif %} +{% endmacro %} + +{% macro convert_and_set_value(property) %} + {% if property.converter == 'CSSPrimitiveValue' %} +{{set_value(property)}}(ToCSSPrimitiveValue(value).ConvertTo<{{property.type_name}}>()); + {%- elif property.converter == 'CSSIdentifierValue' %} +{{set_value(property)}}(ToCSSIdentifierValue(value).ConvertTo<blink::{{property.type_name}}>()); + {%- elif property.converter %} +{{set_value(property)}}(StyleBuilderConverter::{{property.converter}}(state, value)); + {%- endif %} +{% endmacro %} + +{% macro style_builder_functions(property) %} + {% if property.should_implement_apply_functions_in_cpp %} + {# declaration only #} + {{declare_initial()}}; + {{declare_inherit()}}; + {{declare_value()}}; + {% else %} + {# full implementation #} + {% if not property.custom_apply_functions_initial %} + {{declare_initial()}} { + {% if property.svg %} + {{set_value(property)}}(SVGComputedStyle::{{property.initial}}()); + {% elif property.font %} + {{set_value(property)}}(FontBuilder::{{property.initial}}()); + {% else %} + {{set_value(property)}}(ComputedStyleInitialValues::{{property.initial}}()); + {% endif %} + {% if property.independent %} + state.Style()->{{property.is_inherited_setter}}(false); + {% endif %} + } + {% endif %} + {% if not property.custom_apply_functions_inherit %} + {{declare_inherit()}} { + {% if property.svg %} + {{set_value(property)}}(state.ParentStyle()->SvgStyle().{{property.getter}}()); + {% elif property.font %} + {{set_value(property)}}(state.ParentFontDescription().{{property.getter}}()); + {% else %} + {{set_value(property)}}(state.ParentStyle()->{{property.getter}}()); + {% endif %} + {% if property.independent %} + state.Style()->{{property.is_inherited_setter}}(true); + {% endif %} + } + {% endif %} + {% if not property.custom_apply_functions_value %} + {{declare_value()}} { + {{convert_and_set_value(property)}} + {% if property.independent %} + state.Style()->{{property.is_inherited_setter}}(false); + {% endif %} + } + {% endif %} + {% if property.custom_apply == "auto" %} + {% set auto_getter = property.custom_apply_args['auto_getter'] or + 'HasAuto' + property.name_for_methods %} + {% set auto_setter = property.custom_apply_args['auto_setter'] or + 'SetHasAuto' + property.name_for_methods %} + {% set auto_identity = property.custom_apply_args['auto_identity'] or + 'CSSValueAuto' %} + {{declare_initial()}} { + state.Style()->{{auto_setter}}(); + } + {{declare_inherit()}} { + if (state.ParentStyle()->{{auto_getter}}()) + state.Style()->{{auto_setter}}(); + else + {{set_value(property)}}(state.ParentStyle()->{{property.getter}}()); + } + {{declare_value()}} { + if (value.IsIdentifierValue() && + ToCSSIdentifierValue(value).GetValueID() == {{auto_identity}}) + state.Style()->{{auto_setter}}(); + else + {{convert_and_set_value(property)}} + } + {% elif property.custom_apply == "border_image" %} + {% set is_mask_box = property.custom_apply_args['is_mask_box'] %} + {% set modifier_type = property.custom_apply_args['modifier_type'] %} + {% set getter = property.custom_apply_args['getter'] %} + {% set setter = property.custom_apply_args['setter'] %} + {{declare_initial()}} { + const NinePieceImage& currentImage = state.Style()->{{getter}}(); + {# Check for equality in case we can bail out before creating a new NinePieceImage. #} + {% if modifier_type == 'Outset' %} + if (StyleBuildingUtils::borderImageLengthMatchesAllSides(currentImage.Outset(), + BorderImageLength(Length(0, kFixed)))) + return; + {% elif modifier_type == 'Repeat' %} + if (currentImage.HorizontalRule() == kStretchImageRule && + currentImage.VerticalRule() == kStretchImageRule) + return; + {% elif modifier_type == 'Slice' and is_mask_box %} + // Masks have a different initial value for slices. Preserve the value of 0 + // for backwards compatibility. + if (currentImage.Fill() == true && + StyleBuildingUtils::lengthMatchesAllSides(currentImage.ImageSlices(), Length(0, kFixed))) + return; + {% elif modifier_type == 'Slice' and not is_mask_box %} + if (currentImage.Fill() == false && + StyleBuildingUtils::lengthMatchesAllSides(currentImage.ImageSlices(), Length(100, kPercent))) + return; + {% elif modifier_type == 'Width' and is_mask_box %} + // Masks have a different initial value for widths. Preserve the value of + // 'auto' for backwards compatibility. + if (StyleBuildingUtils::borderImageLengthMatchesAllSides(currentImage.BorderSlices(), + BorderImageLength(Length(kAuto)))) + return; + {% elif modifier_type == 'Width' and not is_mask_box %} + if (StyleBuildingUtils::borderImageLengthMatchesAllSides(currentImage.BorderSlices(), + BorderImageLength(1.0))) + return; + {% endif %} + NinePieceImage image(currentImage); + {% if modifier_type == 'Outset' %} + image.SetOutset(Length(0, kFixed)); + {% elif modifier_type == 'Repeat' %} + image.SetHorizontalRule(kStretchImageRule); + image.SetVerticalRule(kStretchImageRule); + {% elif modifier_type == 'Slice' and is_mask_box %} + image.SetImageSlices(LengthBox({{ (['Length(0, kFixed)']*4) | join(', ') }})); + image.SetFill(true); + {% elif modifier_type == 'Slice' and not is_mask_box %} + image.SetImageSlices(LengthBox({{ (['Length(100, kPercent)']*4) | join(', ') }})); + image.SetFill(false); + {% elif modifier_type == 'Width' %} + image.SetBorderSlices({{ 'Length(kAuto)' if is_mask_box else '1.0' }}); + {% endif %} + state.Style()->{{setter}}(image); + } + {{declare_inherit()}} { + NinePieceImage image(state.Style()->{{getter}}()); + {% if modifier_type == 'Outset' %} + image.CopyOutsetFrom(state.ParentStyle()->{{getter}}()); + {% elif modifier_type == 'Repeat' %} + image.CopyRepeatFrom(state.ParentStyle()->{{getter}}()); + {% elif modifier_type == 'Slice' %} + image.CopyImageSlicesFrom(state.ParentStyle()->{{getter}}()); + {% elif modifier_type == 'Width' %} + image.CopyBorderSlicesFrom(state.ParentStyle()->{{getter}}()); + {% endif %} + state.Style()->{{setter}}(image); + } + {{declare_value()}} { + NinePieceImage image(state.Style()->{{getter}}()); + {% if modifier_type == 'Outset' %} + image.SetOutset(CSSToStyleMap::MapNinePieceImageQuad(state, value)); + {% elif modifier_type == 'Repeat' %} + CSSToStyleMap::MapNinePieceImageRepeat(state, value, image); + {% elif modifier_type == 'Slice' %} + CSSToStyleMap::MapNinePieceImageSlice(state, value, image); + {% elif modifier_type == 'Width' %} + image.SetBorderSlices(CSSToStyleMap::MapNinePieceImageQuad(state, value)); + {% endif %} + state.Style()->{{setter}}(image); + } + {% endif %} + {%- endif %} +{%- endmacro %} diff --git a/chromium/third_party/blink/renderer/build/scripts/core/css/templates/css_value_keywords.cc.tmpl b/chromium/third_party/blink/renderer/build/scripts/core/css/templates/css_value_keywords.cc.tmpl new file mode 100644 index 00000000000..c6e8c5c3f89 --- /dev/null +++ b/chromium/third_party/blink/renderer/build/scripts/core/css/templates/css_value_keywords.cc.tmpl @@ -0,0 +1,76 @@ +%{ +// Copyright (c) 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "third_party/blink/renderer/core/css_value_keywords.h" + +#include <string.h> +#include "third_party/blink/renderer/core/css/hash_tools.h" + +#ifdef _MSC_VER +// Disable the warnings from casting a 64-bit pointer to 32-bit long +// warning C4302: 'type cast': truncation from 'char (*)[28]' to 'long' +// warning C4311: 'type cast': pointer truncation from 'char (*)[18]' to 'long' +#pragma warning(disable : 4302 4311) +#endif + +namespace blink { +static const char valueListStringPool[] = { +{% for keyword in value_keywords %} + "{{keyword.name}}\0" +{% endfor %} +}; + +static const unsigned short valueListStringOffsets[] = { +{% for offset in value_keyword_offsets %} + {{offset}}, +{% endfor %} +}; + +%} +%struct-type +struct Value; +%omit-struct-type +%language=C++ +%readonly-tables +%compare-strncmp +%define class-name CSSValueKeywordsHash +%define lookup-function-name findValueImpl +%define hash-function-name value_hash_function +%define slot-name name_offset +%define word-array-name value_word_list +%pic +%enum +%% +{% for keyword in value_keywords %} +{{keyword.lower_name}}, {{keyword.enum_name}} +{% endfor %} +%% + +const Value* FindValue(const char* str, unsigned int len) { + return CSSValueKeywordsHash::findValueImpl(str, len); +} + +const char* getValueName(CSSValueID id) { + DCHECK_GT(id, 0); + DCHECK_LT(id, numCSSValueKeywords); + return valueListStringPool + valueListStringOffsets[id - 1]; +} + +bool isValueAllowedInMode(unsigned short id, CSSParserMode mode) { + switch (id) { +{% for ua_keyword in ua_sheet_mode_values_keywords %} + case {{ua_keyword.enum_name}}: +{% endfor %} + return IsUASheetBehavior(mode); +{% for quirks_or_ua_keyword in quirks_mode_or_ua_sheet_mode_values_keywords %} + case {{quirks_or_ua_keyword.enum_name}}: +{% endfor %} + return IsUASheetBehavior(mode) || IsQuirksModeBehavior(mode); + default: + return true; + } +} + +} // namespace blink diff --git a/chromium/third_party/blink/renderer/build/scripts/core/css/templates/css_value_keywords.h.tmpl b/chromium/third_party/blink/renderer/build/scripts/core/css/templates/css_value_keywords.h.tmpl new file mode 100644 index 00000000000..ae17728ee96 --- /dev/null +++ b/chromium/third_party/blink/renderer/build/scripts/core/css/templates/css_value_keywords.h.tmpl @@ -0,0 +1,28 @@ +// Copyright (c) 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef BLINK_CORE_CSS_VALUE_KEYWORDS_H_ +#define BLINK_CORE_CSS_VALUE_KEYWORDS_H_ + +#include "third_party/blink/renderer/core/css/parser/css_parser_mode.h" +#include <string.h> + +namespace blink { + +enum CSSValueID { + CSSValueInvalid = 0, +{% for keyword in value_keywords %} + {{keyword.enum_name}} = {{keyword.enum_value}}, +{% endfor %} +}; + +const int numCSSValueKeywords = {{value_keywords_count}}; +const size_t maxCSSValueKeywordLength = {{max_value_keyword_length}}; + +const char* getValueName(CSSValueID); +bool isValueAllowedInMode(unsigned short id, CSSParserMode mode); + +} // namespace blink + +#endif // BLINK_CORE_CSS_VALUE_KEYWORDS_H_ diff --git a/chromium/third_party/blink/renderer/build/scripts/core/css/templates/cssom_keywords.cc.tmpl b/chromium/third_party/blink/renderer/build/scripts/core/css/templates/cssom_keywords.cc.tmpl new file mode 100644 index 00000000000..56fe6df7896 --- /dev/null +++ b/chromium/third_party/blink/renderer/build/scripts/core/css/templates/cssom_keywords.cc.tmpl @@ -0,0 +1,47 @@ +// Copyright 2016 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +{% from 'templates/macros.tmpl' import source_files_for_generated_file %} +{{source_files_for_generated_file(template_file, input_files)}} + +#include "third_party/blink/renderer/core/css/cssom/cssom_keywords.h" + +#include "third_party/blink/renderer/core/css/css_property_id_templates.h" +#include "third_party/blink/renderer/core/css/cssom/css_keyword_value.h" +#include "third_party/blink/renderer/platform/wtf/hash_map.h" + +namespace blink { + +bool CSSOMKeywords::ValidKeywordForProperty(CSSPropertyID id, + const CSSKeywordValue& keyword) { + CSSValueID valueID = keyword.KeywordValueID(); + if (valueID == CSSValueInvalid) { + return false; + } + + if (valueID == CSSValueInherit || valueID == CSSValueInitial || + valueID == CSSValueUnset) { + // These are css-wide keywords that are valid for all properties. + return true; + } + + switch (id) { + {% for property in properties if property.keywordIDs and 'Keyword' in property.typedom_types %} + case {{property.property_id}}: { + switch (valueID) { + {% for keywordValueID in property.keywordIDs %} + case {{keywordValueID}}: + {% endfor %} + return true; + default: + return false; + } + } + {% endfor %} + default: + return false; + } +} + +} // namespace blink diff --git a/chromium/third_party/blink/renderer/build/scripts/core/css/templates/cssom_types.cc.tmpl b/chromium/third_party/blink/renderer/build/scripts/core/css/templates/cssom_types.cc.tmpl new file mode 100644 index 00000000000..425b9d20148 --- /dev/null +++ b/chromium/third_party/blink/renderer/build/scripts/core/css/templates/cssom_types.cc.tmpl @@ -0,0 +1,120 @@ +// Copyright 2016 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +{% from 'templates/macros.tmpl' import source_files_for_generated_file %} +{{source_files_for_generated_file(template_file, input_files)}} + +#include "third_party/blink/renderer/core/css/cssom/cssom_types.h" + +#include "third_party/blink/renderer/core/css/cssom/cssom_keywords.h" +#include "third_party/blink/renderer/core/css/cssom/css_keyword_value.h" +#include "third_party/blink/renderer/core/css/cssom/css_numeric_value.h" +#include "third_party/blink/renderer/core/css/cssom/css_style_value.h" +#include "third_party/blink/renderer/core/css/cssom/css_unsupported_style_value.h" +#include "third_party/blink/renderer/core/css/properties/css_property.h" + +namespace blink { + +namespace { + +bool IsCSSStyleValueLength(const CSSStyleValue& value) { + if (!value.IsNumericValue()) + return false; + return static_cast<const CSSNumericValue&>(value).Type(). + MatchesBaseType(CSSNumericValueType::BaseType::kLength); +} + +bool IsCSSStyleValueNumber(const CSSStyleValue& value) { + if (!value.IsNumericValue()) + return false; + return static_cast<const CSSNumericValue&>(value).Type(). + MatchesNumber(); +} + +bool IsCSSStyleValueTime(const CSSStyleValue& value) { + if (!value.IsNumericValue()) + return false; + return static_cast<const CSSNumericValue&>(value).Type(). + MatchesBaseType(CSSNumericValueType::BaseType::kTime); +} + +bool IsCSSStyleValueAngle(const CSSStyleValue& value) { + if (!value.IsNumericValue()) + return false; + return static_cast<const CSSNumericValue&>(value).Type(). + MatchesBaseType(CSSNumericValueType::BaseType::kAngle); +} + +bool IsCSSStyleValuePercentage(const CSSStyleValue& value) { + if (!value.IsNumericValue()) + return false; + return static_cast<const CSSNumericValue&>(value).Type(). + MatchesPercentage(); +} + +bool IsCSSStyleValueFlex(const CSSStyleValue& value) { + if (!value.IsNumericValue()) + return false; + return static_cast<const CSSNumericValue&>(value).Type(). + MatchesBaseType(CSSNumericValueType::BaseType::kFlex); +} + +bool IsCSSStyleValueImage(const CSSStyleValue& value) { + return value.GetType() == CSSStyleValue::kURLImageType; +} + +bool IsCSSStyleValueTransform(const CSSStyleValue& value) { + return value.GetType() == CSSStyleValue::kTransformType; +} + +bool IsCSSStyleValuePosition(const CSSStyleValue& value) { + return value.GetType() == CSSStyleValue::kPositionType; +} + +} + +bool CSSOMTypes::IsPropertySupported(CSSPropertyID id) { + switch (id) { + case CSSPropertyVariable: + {% for property in properties if property.typedom_types %} + case {{property.property_id}}: + {% endfor %} + return true; + default: + return false; + } +} + +bool CSSOMTypes::PropertyCanTake(CSSPropertyID id, + const CSSStyleValue& value) { + if (value.GetType() == CSSStyleValue::kKeywordType) { + return CSSOMKeywords::ValidKeywordForProperty( + id, ToCSSKeywordValue(value)); + } + if (value.GetType() == CSSStyleValue::kUnknownType) { + return ToCSSUnsupportedStyleValue(value).GetProperty() == id; + } + if (value.GetType() == CSSStyleValue::kUnparsedType) { + return true; + } + + switch (id) { + case CSSPropertyVariable: + return value.GetType() == CSSStyleValue::kUnparsedType; + {% for property in properties if property.typedom_types %} + {% if property.typedom_types != ['Keyword'] %} + case {{property.property_id}}: + return ( + {% for type in property.typedom_types if type != 'Keyword' %} + {{ "|| " if not loop.first }}IsCSSStyleValue{{type}}(value) + {% endfor %} + ); + {% endif %} + {% endfor %} + default: + return false; + } +} + +} // namespace blink diff --git a/chromium/third_party/blink/renderer/build/scripts/core/css/templates/media_features.h.tmpl b/chromium/third_party/blink/renderer/build/scripts/core/css/templates/media_features.h.tmpl new file mode 100644 index 00000000000..ad7696f2b9b --- /dev/null +++ b/chromium/third_party/blink/renderer/build/scripts/core/css/templates/media_features.h.tmpl @@ -0,0 +1,17 @@ +{% from "templates/macros.tmpl" import license, source_files_for_generated_file %} +{{ license() }} + +{{source_files_for_generated_file(template_file, input_files)}} + +#ifndef BLINK_CORE_CSS_MEDIA_FEATURES_H_ +#define BLINK_CORE_CSS_MEDIA_FEATURES_H_ + +#define CSS_MEDIAQUERY_NAMES_FOR_EACH_MEDIAFEATURE(macro) \ + {% for entry in entries %} + {% set constant_prefix = entry | symbol %} + {% set method_prefix = constant_prefix | upper_first_letter %} + macro({{constant_prefix}}, {{method_prefix}}){% if not loop.last %} \ + {% endif %} + {% endfor %} + +#endif // BLINK_CORE_CSS_MEDIA_FEATURES_H_ diff --git a/chromium/third_party/blink/renderer/build/scripts/core/css/templates/style_property_shorthand.cc.tmpl b/chromium/third_party/blink/renderer/build/scripts/core/css/templates/style_property_shorthand.cc.tmpl new file mode 100644 index 00000000000..a03a22612ac --- /dev/null +++ b/chromium/third_party/blink/renderer/build/scripts/core/css/templates/style_property_shorthand.cc.tmpl @@ -0,0 +1,96 @@ +/* + * (C) 1999-2003 Lars Knoll (knoll@kde.org) + * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. + * Copyright (C) 2013 Intel Corporation. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +{% from 'templates/macros.tmpl' import source_files_for_generated_file %} +{{source_files_for_generated_file(template_file, input_files)}} + +#include "third_party/blink/renderer/core/style_property_shorthand.h" + +#include "third_party/blink/renderer/platform/runtime_enabled_features.h" +#include "third_party/blink/renderer/platform/wtf/hash_map.h" +#include "third_party/blink/renderer/platform/wtf/std_lib_extras.h" + +namespace blink { +{% for property in properties %} + +const StylePropertyShorthand& {{property.lower_camel_name}}Shorthand() { + static const CSSProperty* {{property.lower_camel_name}}Properties[] = { + {% for longhand_id in property.longhand_property_ids %} + &Get{{longhand_id}}(), + {% endfor %} + }; + + static StylePropertyShorthand {{property.lower_camel_name}}Longhands( + {{property.property_id}}, + {{property.lower_camel_name}}Properties, + WTF_ARRAY_LENGTH({{property.lower_camel_name}}Properties)); + return {{property.lower_camel_name}}Longhands; +} +{% endfor %} + +// TODO(ericwilligers): Retire this when offset-position and offset-anchor ship +const StylePropertyShorthand& offsetShorthandWithoutPositionAnchor() { + static const CSSProperty* offsetProperties[] = { + &GetCSSPropertyOffsetPath(), + &GetCSSPropertyOffsetDistance(), + &GetCSSPropertyOffsetRotate(), + }; + DEFINE_STATIC_LOCAL(StylePropertyShorthand, offsetLonghands, (CSSPropertyOffset, offsetProperties, WTF_ARRAY_LENGTH(offsetProperties))); + return offsetLonghands; +} + +// Returns an empty list if the property is not a shorthand +const StylePropertyShorthand& shorthandForProperty(CSSPropertyID propertyID) { + // FIXME: We shouldn't switch between shorthand/not shorthand based on a runtime flag + static StylePropertyShorthand emptyShorthand; + + if (propertyID == CSSPropertyOffset && + !RuntimeEnabledFeatures::CSSOffsetPositionAnchorEnabled()) + return offsetShorthandWithoutPositionAnchor(); + switch (propertyID) { + {% for property in properties %} + case {{property.property_id}}: + return {{property.lower_camel_name}}Shorthand(); + {% endfor %} + default: { + return emptyShorthand; + } + } +} + +void getMatchingShorthandsForLonghand( + CSSPropertyID propertyID, Vector<StylePropertyShorthand, 4>* result) { + DCHECK(!result->size()); + switch (propertyID) { + {% for longhand_id, shorthands in longhands_dictionary.items() %} + case {{longhand_id}}: { + {% for shorthand in shorthands %} + result->UncheckedAppend({{shorthand.lower_camel_name}}Shorthand()); + {% endfor %} + break; + } + {% endfor %} + default: + break; + } +} + +} // namespace blink diff --git a/chromium/third_party/blink/renderer/build/scripts/core/css/templates/style_property_shorthand.h.tmpl b/chromium/third_party/blink/renderer/build/scripts/core/css/templates/style_property_shorthand.h.tmpl new file mode 100644 index 00000000000..715ce15bbc8 --- /dev/null +++ b/chromium/third_party/blink/renderer/build/scripts/core/css/templates/style_property_shorthand.h.tmpl @@ -0,0 +1,79 @@ +/* + * (C) 1999-2003 Lars Knoll (knoll@kde.org) + * Copyright (C) 2004, 2005, 2006, 2008 Apple Inc. All rights reserved. + * Copyright (C) 2013 Intel Corporation. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +{% from 'templates/macros.tmpl' import source_files_for_generated_file %} +{{source_files_for_generated_file(template_file, input_files)}} + +#ifndef BLINK_CORE_STYLE_PROPERTY_SHORTHAND_H_ +#define BLINK_CORE_STYLE_PROPERTY_SHORTHAND_H_ + +#include "css_property_names.h" +#include "third_party/blink/renderer/core/css/properties/css_property.h" +#include "third_party/blink/renderer/platform/wtf/vector.h" + +namespace blink { + +class StylePropertyShorthand { + USING_FAST_MALLOC(StylePropertyShorthand); + public: + constexpr StylePropertyShorthand() + : m_properties(0), + m_length(0), + m_shorthandID(CSSPropertyInvalid) {} + + constexpr StylePropertyShorthand(CSSPropertyID id, + const CSSProperty** properties, + unsigned numProperties) + : m_properties(properties), + m_length(numProperties), + m_shorthandID(id) {} + + const CSSProperty** properties() const { return m_properties; } + unsigned length() const { return m_length; } + CSSPropertyID id() const { return m_shorthandID; } + + private: + const CSSProperty** m_properties; + unsigned m_length; + CSSPropertyID m_shorthandID; +}; + +{% for property in properties %} +const StylePropertyShorthand& {{property.lower_camel_name}}Shorthand(); +{% endfor %} + +const StylePropertyShorthand& animationShorthandForParsing(); +const StylePropertyShorthand& transitionShorthandForParsing(); + +// Returns an empty list if the property is not a shorthand. +const StylePropertyShorthand& shorthandForProperty(CSSPropertyID); + +// Return the list of shorthands for a given longhand. +// The client must pass in an empty result vector. +void getMatchingShorthandsForLonghand( + CSSPropertyID, Vector<StylePropertyShorthand, 4>* result); + +unsigned indexOfShorthandForLonghand(CSSPropertyID, + const Vector<StylePropertyShorthand, 4>&); + +} // namespace blink + +#endif // BLINK_CORE_STYLE_PROPERTY_SHORTHAND_H_ diff --git a/chromium/third_party/blink/renderer/build/scripts/core/style/__init__.py b/chromium/third_party/blink/renderer/build/scripts/core/style/__init__.py new file mode 100644 index 00000000000..e69de29bb2d --- /dev/null +++ b/chromium/third_party/blink/renderer/build/scripts/core/style/__init__.py diff --git a/chromium/third_party/blink/renderer/build/scripts/core/style/computed_style_fields.py b/chromium/third_party/blink/renderer/build/scripts/core/style/computed_style_fields.py new file mode 100644 index 00000000000..9e4795169ba --- /dev/null +++ b/chromium/third_party/blink/renderer/build/scripts/core/style/computed_style_fields.py @@ -0,0 +1,183 @@ +# Copyright 2017 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +from name_utilities import ( + enum_value_name, class_member_name, method_name, class_name +) + +from itertools import chain + + +def _flatten_list(x): + """Flattens a list of lists into a single list.""" + return list(chain.from_iterable(x)) + + +def _num_32_bit_words_for_bit_fields(bit_fields): + """ + Gets the number of 32 bit unsigned ints needed store a list of bit fields. + """ + num_buckets, cur_bucket = 0, 0 + for field in bit_fields: + if field.size + cur_bucket > 32: + num_buckets += 1 + cur_bucket = 0 + cur_bucket += field.size + return num_buckets + (cur_bucket > 0) + + +class Group(object): + """Represents a group of fields stored together in a class. + + Attributes: + name: The name of the group as a string. + subgroups: List of Group instances that are stored as subgroups under + this group. + fields: List of Field instances stored directly under this group. + parent: The parent group, or None if this is the root group. + """ + def __init__(self, name, subgroups, fields): + self.name = name + self.subgroups = subgroups + self.fields = fields + self.parent = None + + self.type_name = class_name(['style', name, 'data']) + self.member_name = class_member_name([name, 'data']) + self.num_32_bit_words_for_bit_fields = _num_32_bit_words_for_bit_fields( + field for field in fields if field.is_bit_field + ) + + # Recursively get all the fields in the subgroups as well + self.all_fields = _flatten_list( + subgroup.all_fields for subgroup in subgroups) + fields + + # Ensure that all fields/subgroups on this group link to it + for field in fields: + field.group = self + + for subgroup in subgroups: + subgroup.parent = self + + def path_without_root(self): + """Return list of ancestor groups, excluding the root group. + + The first item is the current group, second item is the parent, third + is the grandparent and so on. + """ + group_path = [] + current_group = self + while current_group.name: + group_path.insert(0, current_group) + current_group = current_group.parent + return group_path + + +class Enum(object): + """Represents a generated enum in ComputedStyleBaseConstants.""" + def __init__(self, type_name, keywords, is_set): + self.type_name = type_name + self.values = [enum_value_name(keyword) for keyword in keywords] + self.is_set = is_set + + +class DiffGroup(object): + """Represents a group of expressions and subgroups that need to be diffed + for a function in ComputedStyle. + + Attributes: + subgroups: List of DiffGroup instances that are stored as subgroups + under this group. + expressions: List of expression that are on this group that need to + be diffed. + """ + def __init__(self, group): + self.group = group + self.subgroups = [] + self.fields = [] + self.expressions = [] + self.predicates = [] + + +class Field(object): + """ + The generated ComputedStyle object is made up of a series of Fields. + Each Field has a name, size, type, etc, and a bunch of attributes to + determine which methods it will be used in. + + A Field also has enough information to use any storage type in C++, such as + regular member variables, or more complex storage like vectors or hashmaps. + Almost all properties will have at least one Field, often more than one. + + Most attributes in this class correspond to parameters in + CSSProperties.json5. See that file for a more detailed explanation of + each attribute. + + Attributes: + field_role: The semantic role of the field. Can be: + - 'property': for fields that store CSS properties + - 'inherited_flag': for single-bit flags that store whether a + property is inherited by this style or + set explicitly + name_for_methods: String used to form the names of getters and setters. + Should be in upper camel case. + property_name: Name of the property that the field is part of. + type_name: Name of the C++ type exposed by the generated interface + (e.g. EClear, int). + wrapper_pointer_name: Name of the pointer type that wraps this field + (e.g. RefPtr). + field_template: Determines the interface generated for the field. Can + be one of: keyword, flag, or monotonic_flag. + size: Number of bits needed for storage. + default_value: Default value for this field when it is first initialized + """ + + def __init__(self, field_role, name_for_methods, property_name, type_name, + wrapper_pointer_name, field_template, size, default_value, + custom_copy, custom_compare, mutable, getter_method_name, + setter_method_name, initial_method_name, + computed_style_custom_functions, **kwargs): + self.name = class_member_name(name_for_methods) + self.property_name = property_name + self.type_name = type_name + self.wrapper_pointer_name = wrapper_pointer_name + self.alignment_type = self.wrapper_pointer_name or self.type_name + self.field_template = field_template + self.size = size + self.default_value = default_value + self.custom_copy = custom_copy + self.custom_compare = custom_compare + self.mutable = mutable + self.group = None + + # Method names + self.getter_method_name = getter_method_name + self.setter_method_name = setter_method_name + self.internal_getter_method_name = method_name([self.name, 'internal']) + self.internal_mutable_method_name = method_name( + ['mutable', name_for_methods, 'internal']) + self.internal_setter_method_name = method_name( + [setter_method_name, 'internal']) + self.initial_method_name = initial_method_name + self.resetter_method_name = method_name(['reset', name_for_methods]) + self.computed_style_custom_functions = computed_style_custom_functions + # Only bitfields have sizes. + self.is_bit_field = self.size is not None + + # Field role: one of these must be true + self.is_property = field_role == 'property' + self.is_inherited_flag = field_role == 'inherited_flag' + assert (self.is_property, self.is_inherited_flag).count(True) == 1, \ + 'Field role has to be exactly one of: property, inherited_flag' + + if not self.is_inherited_flag: + self.is_inherited = kwargs.pop('inherited') + self.is_independent = kwargs.pop('independent') + assert self.is_inherited or not self.is_independent, \ + 'Only inherited fields can be independent' + + self.is_inherited_method_name = method_name( + [name_for_methods, 'is inherited']) + assert len(kwargs) == 0, \ + 'Unexpected arguments provided to Field: ' + str(kwargs) diff --git a/chromium/third_party/blink/renderer/build/scripts/core/style/make_computed_style_initial_values.py b/chromium/third_party/blink/renderer/build/scripts/core/style/make_computed_style_initial_values.py new file mode 100755 index 00000000000..16d11732b93 --- /dev/null +++ b/chromium/third_party/blink/renderer/build/scripts/core/style/make_computed_style_initial_values.py @@ -0,0 +1,55 @@ +#!/usr/bin/env python +# Copyright 2017 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +import os +import sys +sys.path.append(os.path.join(os.path.dirname(__file__), '../..')) + +import json5_generator +import template_expander + +from core.css import css_properties + + +class ComputedStyleInitialValuesWriter(json5_generator.Writer): + def __init__(self, json5_file_paths): + super(ComputedStyleInitialValuesWriter, self).__init__([]) + + json_properties = css_properties.CSSProperties(json5_file_paths) + + self._properties = json_properties.longhands + \ + json_properties.extra_fields + self._includes = set() + self._forward_declarations = set() + + for property_ in self._properties: + # TODO(meade): CursorList and AppliedTextDecorationList are + # typedefs, not classes, so they can't be forward declared. Find a + # better way to specify this. + if property_['default_value'] == 'nullptr' \ + and not property_['unwrapped_type_name'] == 'CursorList' \ + and not property_['unwrapped_type_name'] == \ + 'AppliedTextDecorationList': + self._forward_declarations.add( + property_['unwrapped_type_name']) + else: + self._includes.update(property_['include_paths']) + + self._outputs = { + 'computed_style_initial_values.h': self.generate_header, + } + + @template_expander.use_jinja( + 'core/style/templates/computed_style_initial_values.h.tmpl') + def generate_header(self): + return { + 'properties': self._properties, + 'forward_declarations': sorted(list(self._forward_declarations)), + 'includes': sorted(list(self._includes)) + } + + +if __name__ == '__main__': + json5_generator.Maker(ComputedStyleInitialValuesWriter).main() diff --git a/chromium/third_party/blink/renderer/build/scripts/core/style/templates/computed_style_initial_values.h.tmpl b/chromium/third_party/blink/renderer/build/scripts/core/style/templates/computed_style_initial_values.h.tmpl new file mode 100644 index 00000000000..943a7d51d7a --- /dev/null +++ b/chromium/third_party/blink/renderer/build/scripts/core/style/templates/computed_style_initial_values.h.tmpl @@ -0,0 +1,132 @@ +// Copyright 2017 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef BLINK_CORE_STYLE_COMPUTED_STYLE_INITIAL_VALUES_H_ +#define BLINK_CORE_STYLE_COMPUTED_STYLE_INITIAL_VALUES_H_ + +#include "third_party/blink/renderer/core/layout/layout_theme.h" +#include "third_party/blink/renderer/core/style/computed_style_constants.h" +#include "third_party/blink/renderer/core/style/filter_operations.h" +#include "third_party/blink/renderer/platform/theme_types.h" +#include "third_party/blink/renderer/platform/scroll/scroll_types.h" +{% for include in includes %} +#include "{{include}}" +{% endfor %} + +namespace blink { + +class ShapeValue; +class StyleImage; +class StyleInheritedVariables; +class StyleNonInheritedVariables; +{% for forward_declaration in forward_declarations %} +class {{forward_declaration}}; +{% endfor %} + +/** + * A set of functions that return the initial value for each field on ComputedStyle. + * This includes both properties defined in CSSProperties.json5 and the extra + * fields defined in ComputedStyleExtraFields.json5. + */ +class ComputedStyleInitialValues{ + STATIC_ONLY(ComputedStyleInitialValues); + public: + // Hand-written methods. + + static StyleContentAlignmentData InitialContentAlignment() { + return StyleContentAlignmentData(ContentPosition::kNormal, + ContentDistributionType::kDefault, + OverflowAlignment::kDefault); + } + static StyleSelfAlignmentData InitialDefaultAlignment() { + return StyleSelfAlignmentData(ItemPosition::kNormal, + OverflowAlignment::kDefault); + } + static StyleImage* InitialBorderImageSource() { return nullptr; } + static float InitialBorderWidth() { return 3; } + static unsigned short InitialColumnRuleWidth() { + return 3; + } + + // Grid properties. + static size_t InitialGridAutoRepeatInsertionPoint() { return 0; } + static AutoRepeatType InitialGridAutoRepeatType() { + return AutoRepeatType::kNoAutoRepeat; + } + + // FIXME: Remove letter-spacing/word-spacing and replace them with respective + // FontBuilder calls. + static float InitialWordSpacing() { return 0.0f; } + static float InitialLetterSpacing() { return 0.0f; } + + static unsigned short InitialOutlineWidth() { + return 3; + } + static EVerticalAlign InitialVerticalAlign() { + return EVerticalAlign::kBaseline; + } + + // -webkit-perspective-origin-x + static Length InitialPerspectiveOriginX() { return Length(50.0, kPercent); } + + // -webkit-perspective-origin-y + static Length InitialPerspectiveOriginY() { return Length(50.0, kPercent); } + + // -webkit-transform-origin-x + static Length InitialTransformOriginX() { return Length(50.0, kPercent); } + // -webkit-transform-origin-y + static Length InitialTransformOriginY() { return Length(50.0, kPercent); } + // -webkit-transform-origin-z + static float InitialTransformOriginZ() { return 0; } + + // -webkit-mask-box-image-source + static StyleImage* InitialMaskBoxImageSource() { return nullptr; } + + static const FilterOperations& InitialFilter() { + return InitialFilterInternal(); + } + static const FilterOperations& InitialBackdropFilter() { + return InitialFilterInternal(); + } + + // Generated methods below. +{% for property in properties if + 'initial' not in property.computed_style_custom_functions %} + {% if property.field_template == "pointer" %} + + static {{property.type_name}}* {{property.initial}}() { + return {{property.default_value}}; + } + {% elif property.field_template == "external" %} + + {% if property.wrapper_pointer_name %} + static {{property.unwrapped_type_name}}* {{property.initial}}() { + return {{property.default_value}}; + } + {% else %} + static {{property.type_name}} {{property.initial}}() { + return {{property.default_value}}; + } + {% endif %} + {% elif property.field_template == "keyword" or + property.field_template == "multi_keyword" or + property.field_template == "primitive" %} + + static {{property.type_name}} {{property.initial}}() { + return {{property.default_value}}; + } + {% endif %} +{% endfor %} + + private: + static const FilterOperations& InitialFilterInternal() { + DEFINE_STATIC_LOCAL(FilterOperationsWrapper, ops, + (FilterOperationsWrapper::Create())); + return ops.Operations(); + } +}; + +} // namespace blink + +#endif // BLINK_CORE_STYLE_COMPUTED_STYLE_INITIAL_VALUES_H_ |