Commit 353bb5ee authored by Bugs Nash's avatar Bugs Nash Committed by Commit Bot

Moved generated apply methods to property class for 'auto' properties

Moved the generated apply* methods from StyleBuilderFunctions.cpp
to the property classes for 'auto' properties which share a non
custom template:
- clip
- column-count
- column-gap
- column-width
- z-index

Also fixed includes so that headers required for apply* functions
are only included when those functions are implemented, not
when they are to be declared only.

Note that this patch creates duplicated logic in
make_css_property_headers.py and make_style_builder.py.
Since it is planned to remove style builder as part of this project
I have not bothered factoring this logic out.

Diff of generated files:
https://gist.github.com/1bad2de3801d6d75d77e9b08c7b128f8/revisions

Bug: 751354
Change-Id: I75d9a85a50771541f8c8be64c62c4dfa0796cd8a
Reviewed-on: https://chromium-review.googlesource.com/760079Reviewed-by: default avatarRenée Wright <rjwright@chromium.org>
Commit-Queue: Bugs Nash <bugsnash@chromium.org>
Cr-Commit-Position: refs/heads/master@{#515888}
parent 65155917
......@@ -56,15 +56,7 @@ class CSSPropertyHeadersWriter(CSSPropertyWriter):
]
property_['superclass'] = superclass
class_data = self.get_class(property_)
# Functions should only be declared on the property classes if they are
# implemented and not shared (denoted by property_class = true. Shared
# classes are denoted by property_class = "some string").
property_['should_declare_application_functions'] = \
property_['unique'] \
and property_['is_property'] \
and not property_['longhands'] \
and not property_['direction_aware_options'] \
and not property_['builder_skip']
self.calculate_apply_functions_to_declare(property_)
self._outputs[class_data.classname + '.h'] = (
self.generate_property_h_builder(
class_data.classname, property_))
......@@ -80,6 +72,35 @@ class CSSPropertyHeadersWriter(CSSPropertyWriter):
}
return generate_property_h
def calculate_apply_functions_to_declare(self, property_):
# Functions should only be declared on the property classes if they are
# implemented and not shared (denoted by property_class = true. Shared
# classes are denoted by property_class = "some string").
property_['should_declare_apply_functions'] = \
property_['unique'] \
and property_['is_property'] \
and not property_['longhands'] \
and not property_['direction_aware_options'] \
and not property_['builder_skip']
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'}
if property_name == 'ColumnGap':
property_['custom_apply'] = "auto"
property_['custom_apply_args'] = {
'auto_getter': 'HasNormalColumnGap',
'auto_setter': 'SetHasNormalColumnGap',
'auto_identity': 'CSSValueNormal'}
property_['should_implement_apply_functions'] = (
property_['should_declare_apply_functions'] and
(not (property_['custom_apply_functions_initial'] and
property_['custom_apply_functions_inherit'] and
property_['custom_apply_functions_value']) or
'custom_apply' in property_.keys()))
def validate_input(self):
# First collect which classes correspond to which properties.
class_names_to_properties = defaultdict(list)
......
......@@ -14,7 +14,7 @@
{% if property.direction_aware_options %}
#include "core/StylePropertyShorthand.h"
{% endif %}
{% if property.should_declare_application_functions %}
{% if property.should_implement_apply_functions %}
#include "core/css/resolver/StyleResolverState.h"
{% if property.converter == "CSSPrimitiveValue" %}
#include "core/css/CSSPrimitiveValue.h"
......@@ -77,9 +77,19 @@ class {{property_classname}} : public {{property.superclass}} {
{% if property.is_descriptor %}
bool IsDescriptor() const override { return true; }
{% endif %}
{% if property.should_declare_application_functions %}
{# Style builder functions #}
{% macro declare_initial() %}
void ApplyInitial(StyleResolverState& state) const override {
{%- endmacro %}
{% macro declare_inherit() %}
void ApplyInherit(StyleResolverState& state) const override {
{%- endmacro %}
{% macro declare_value() %}
void ApplyValue(StyleResolverState& state, const CSSValue& value) const override {
{%- endmacro %}
{% if property.should_declare_apply_functions %}
{% if not property.custom_apply_functions_initial %}
void ApplyInitial(StyleResolverState& state) const override {
{{declare_initial()}}
{% if property.svg %}
{{set_value(property)}}(SVGComputedStyle::{{property.initial}}());
{% elif property.font %}
......@@ -94,7 +104,7 @@ class {{property_classname}} : public {{property.superclass}} {
{% endif %}
{# TODO(meade): else emit function declaration only #}
{% if not property.custom_apply_functions_inherit %}
void ApplyInherit(StyleResolverState& state) const override {
{{declare_inherit()}}
{% if property.svg %}
{{set_value(property)}}(state.ParentStyle()->SvgStyle().{{property.getter}}());
{% elif property.font %}
......@@ -109,7 +119,7 @@ class {{property_classname}} : public {{property.superclass}} {
{% endif %}
{# TODO(meade): else emit function declaration only #}
{% if not property.custom_apply_functions_value %}
void ApplyValue(StyleResolverState& state, const CSSValue& value) const override {
{{declare_value()}}
{{convert_and_set_value(property)}}
{% if property.independent %}
state.Style()->{{property.is_inherited_setter}}(false);
......@@ -117,6 +127,30 @@ class {{property_classname}} : public {{property.superclass}} {
}
{% endif %}
{# TODO(meade): else emit function declaration only #}
{% 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)}}
}
{% endif %}
{% endif %}
{% if 'Percent' in property.typedom_types %}
bool SupportsPercentage() const override { return true; }
......
......@@ -36,7 +36,7 @@ from name_utilities import lower_first
import template_expander
def calculate_functions_to_declare(property_):
def calculate_apply_functions_to_declare(property_):
property_['should_declare_functions'] = \
not property_['longhands'] \
and not property_['direction_aware_options'] \
......@@ -52,6 +52,10 @@ def calculate_functions_to_declare(property_):
property_['custom_apply_functions_value']) \
and property_['property_class'] \
and isinstance(property_['property_class'], types.BooleanType)
if property_['custom_apply_functions_all']:
if (property_['upper_camel_name'] in
['Clip', 'ColumnCount', 'ColumnGap', 'ColumnWidth', 'ZIndex']):
property_['use_property_class_in_stylebuilder'] = True
class StyleBuilderWriter(json5_generator.Writer):
......@@ -73,7 +77,7 @@ class StyleBuilderWriter(json5_generator.Writer):
self._properties = self._json5_properties.longhands + \
self._json5_properties.shorthands
for property_ in self._properties:
calculate_functions_to_declare(property_)
calculate_apply_functions_to_declare(property_)
@property
def css_properties(self):
......
......@@ -121,34 +121,6 @@ namespace blink {
{{apply_animation('CSSPropertyTransitionProperty', 'Property', 'Transition')}}
{{apply_animation('CSSPropertyTransitionTimingFunction', 'TimingFunction', 'Transition')}}
{% macro apply_auto(property_id, auto_getter=none, auto_setter=none, auto_identity='CSSValueAuto') %}
{% set property = properties_by_id[property_id] %}
{% set auto_getter = auto_getter or 'HasAuto' + property.name_for_methods %}
{% set auto_setter = auto_setter or 'SetHasAuto' + property.name_for_methods %}
{{declare_initial_function(property_id)}} {
state.Style()->{{auto_setter}}();
}
{{declare_inherit_function(property_id)}} {
if (state.ParentStyle()->{{auto_getter}}())
state.Style()->{{auto_setter}}();
else
{{set_value(property)}}(state.ParentStyle()->{{property.getter}}());
}
{{declare_value_function(property_id)}} {
if (value.IsIdentifierValue() && ToCSSIdentifierValue(value).GetValueID() == {{auto_identity}})
state.Style()->{{auto_setter}}();
else
{{convert_and_set_value(property)}}
}
{% endmacro %}
{{apply_auto('CSSPropertyClip')}}
{{apply_auto('CSSPropertyColumnCount')}}
{{apply_auto('CSSPropertyColumnGap', auto_getter='HasNormalColumnGap', auto_setter='SetHasNormalColumnGap', auto_identity='CSSValueNormal')}}
{{apply_auto('CSSPropertyColumnWidth')}}
{{apply_auto('CSSPropertyZIndex')}}
static bool lengthMatchesAllSides(const LengthBox& lengthBox,
const Length& length) {
return (lengthBox.Left() == length &&
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment