| {% from "macros.tmpl" import wrap_with_condition, license -%} |
| {{ license() }} |
| |
| #include "config.h" |
| #include "core/css/resolver/StyleBuilder.h" |
| |
| #include "core/css/CSSPrimitiveValueMappings.h" |
| #include "core/css/resolver/StyleResolver.h" |
| |
| // FIXME: currently we're just generating a switch statement, but we should |
| // test other variations for performance once we have more properties here. |
| |
| namespace WebCore { |
| |
| class StyleBuilderImpl { |
| public: |
| |
| {%- macro set_value(property) -%} |
| styleResolver->style()->{{property.setter}} |
| {%- endmacro %} |
| |
| {%- macro apply_value_length(property) -%} |
| if (!value->isPrimitiveValue()) |
| return; |
| |
| CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value); |
| {% if property.use_none %} |
| if (primitiveValue->getIdent() == CSSValueNone) |
| {{ set_value(property) }}(Length(Undefined)); |
| {% endif %} |
| |
| {%- if property.use_intrinsic %} |
| if (primitiveValue->getIdent() == CSSValueIntrinsic) |
| {{ set_value(property) }}(Length(Intrinsic)); |
| else if (primitiveValue->getIdent() == CSSValueMinIntrinsic) |
| {{ set_value(property) }}(Length(MinIntrinsic)); |
| else if (primitiveValue->getIdent() == CSSValueWebkitMinContent) |
| {{ set_value(property) }}(Length(MinContent)); |
| else if (primitiveValue->getIdent() == CSSValueWebkitMaxContent) |
| {{ set_value(property) }}(Length(MaxContent)); |
| else if (primitiveValue->getIdent() == CSSValueWebkitFillAvailable) |
| {{ set_value(property) }}(Length(FillAvailable)); |
| else if (primitiveValue->getIdent() == CSSValueWebkitFitContent) |
| {{ set_value(property) }}(Length(FitContent)); |
| {% endif %} |
| |
| {%- if property.use_auto %} |
| if (primitiveValue->getIdent() == CSSValueAuto) |
| {{ set_value(property) }}(Length()); |
| {%- endif %} |
| |
| if (primitiveValue->isLength()) { |
| Length length = primitiveValue->computeLength<Length>(styleResolver->style(), styleResolver->rootElementStyle(), styleResolver->style()->effectiveZoom()); |
| length.setQuirk(primitiveValue->isQuirkValue()); |
| {{ set_value(property) }}(length); |
| } else if (primitiveValue->isPercentage()) |
| {{ set_value(property) }}(Length(primitiveValue->getDoubleValue(), Percent)); |
| else if (primitiveValue->isCalculatedPercentageWithLength()) |
| {{ set_value(property) }}(Length(primitiveValue->cssCalcValue()->toCalcValue(styleResolver->style(), styleResolver->rootElementStyle(), styleResolver->style()->effectiveZoom()))); |
| else if (primitiveValue->isViewportPercentageLength()) |
| {{ set_value(property) }}(primitiveValue->viewportPercentageLength()); |
| {%- endmacro %} |
| |
| {%- for property in properties %} |
| {%- call wrap_with_condition(property.condition) %} |
| {%- set property_id = property.property_id %} |
| {%- set apply_type = property.apply_type %} |
| |
| static void applyInitial{{property_id}}(StyleResolver* styleResolver) |
| { |
| {{ set_value(property) }}(RenderStyle::{{property.initial}}()); |
| } |
| |
| static void applyInherit{{property_id}}(StyleResolver* styleResolver) |
| { |
| {{ set_value(property) }}(styleResolver->parentStyle()->{{property.getter}}()); |
| } |
| |
| static void applyValue{{property_id}}(StyleResolver* styleResolver, CSSValue* value) |
| { |
| {%- if apply_type == "length" %} |
| {{ apply_value_length(property) }} |
| {%- else %} |
| {{ set_value(property) }}(static_cast<{{property.type_name}}>(*toCSSPrimitiveValue(value))); |
| {%- endif %} |
| } |
| |
| {%- endcall %} |
| {%- endfor %} |
| |
| }; |
| |
| bool StyleBuilder::applyProperty(CSSPropertyID property, StyleResolver* styleResolver, CSSValue* value, bool isInitial, bool isInherit) { |
| switch(property) { |
| {%- for property in properties %} |
| {%- call wrap_with_condition(property.condition) %} |
| {%- set property_id = property.property_id %} |
| case {{property_id}}: |
| if (isInitial) |
| StyleBuilderImpl::applyInitial{{property_id}}(styleResolver); |
| else if (isInherit) |
| StyleBuilderImpl::applyInherit{{property_id}}(styleResolver); |
| else |
| StyleBuilderImpl::applyValue{{property_id}}(styleResolver, value); |
| return true; |
| {%- endcall %} |
| {% endfor %} |
| default: |
| return false; |
| } |
| } |
| } |
| |