Index: Source/core/scripts/templates/StyleBuilderFunctions.cpp.tmpl |
diff --git a/Source/core/scripts/templates/StyleBuilderFunctions.cpp.tmpl b/Source/core/scripts/templates/StyleBuilderFunctions.cpp.tmpl |
index ca7dedcc4e93daa2ac92f634a327526200aa3ade..3cf0b450d61dc913de7b429600f27d3a55166128 100644 |
--- a/Source/core/scripts/templates/StyleBuilderFunctions.cpp.tmpl |
+++ b/Source/core/scripts/templates/StyleBuilderFunctions.cpp.tmpl |
@@ -1,3 +1,5 @@ |
+{% from "macros.tmpl" import wrap_with_condition -%} |
+ |
{# |
This file is for property handlers which use the templating engine to |
reduce (handwritten) code duplication. |
@@ -46,6 +48,153 @@ namespace WebCore { |
{{ apply_value_border_image("CSSPropertyWebkitBorderImage") }} |
{{ apply_value_border_image("CSSPropertyWebkitMaskBoxImage") }} |
+{%- macro apply_color(property_id, default_getter="color", initial_color=none, inherit_color=false) %} |
+{%- set property = properties[property_id] %} |
+{%- call wrap_with_condition(property.condition) %} |
+{%- set visited_link_setter = "setVisitedLink" + property.camel_case_name %} |
+{{ apply_initial(property_id) }} |
+{ |
+ Color color = {{ initial_color or "Color" -}}(); |
+ if (styleResolver->applyPropertyToRegularStyle()) |
+ {{ set_value(property) }}(color); |
+ if (styleResolver->applyPropertyToVisitedLinkStyle()) |
+ styleResolver->style()->{{visited_link_setter}}(color); |
+} |
+ |
+{{ apply_inherit(property_id) }} |
+{ |
+ // Visited link style can never explicitly inherit from parent visited link style so no separate getters are needed. |
+ Color color = styleResolver->parentStyle()->{{property.getter}}(); |
+ if (!color.isValid()) |
+ color = styleResolver->parentStyle()->{{default_getter}}(); |
+ if (styleResolver->applyPropertyToRegularStyle()) |
+ {{ set_value(property) }}(color); |
+ if (styleResolver->applyPropertyToVisitedLinkStyle()) |
+ styleResolver->style()->{{visited_link_setter}}(color); |
+} |
+ |
+{{ apply_value(property_id) }} |
+{ |
+ if (!value->isPrimitiveValue()) |
+ return; |
+ |
+ CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value); |
+ |
+{%- if inherit_color %} |
+ if (primitiveValue->getValueID() == CSSValueCurrentcolor) { |
+ applyInherit{{property_id}}(styleResolver); |
+ return; |
+ } |
+{%- endif %} |
+ |
+ if (styleResolver->applyPropertyToRegularStyle()) |
+ {{ set_value(property) }}(styleResolver->colorFromPrimitiveValue(primitiveValue)); |
+ if (styleResolver->applyPropertyToVisitedLinkStyle()) |
+ styleResolver->style()->{{visited_link_setter}}(styleResolver->colorFromPrimitiveValue(primitiveValue, /* forVisitedLink */ true)); |
+} |
+{%- endcall %} |
+{%- endmacro %} |
+ |
+{{ apply_color("CSSPropertyBackgroundColor", default_getter="invalidColor") }} |
+{{ apply_color("CSSPropertyBorderBottomColor") }} |
+{{ apply_color("CSSPropertyBorderLeftColor") }} |
+{{ apply_color("CSSPropertyBorderRightColor") }} |
+{{ apply_color("CSSPropertyBorderTopColor") }} |
+{{ apply_color("CSSPropertyColor", inherit_color=true, default_getter="invalidColor", initial_color="RenderStyle::initialColor") }} |
+{{ apply_color("CSSPropertyOutlineColor") }} |
+{{ apply_color("CSSPropertyTextDecorationColor") }} |
+{{ apply_color("CSSPropertyWebkitColumnRuleColor") }} |
+{{ apply_color("CSSPropertyWebkitTextEmphasisColor") }} |
+{{ apply_color("CSSPropertyWebkitTextFillColor") }} |
+{{ apply_color("CSSPropertyWebkitTextStrokeColor") }} |
+ |
+{%- macro apply_fill_layer(property_id, fill_type) %} |
+{%- set layer_type = "Background" if "Background" in property_id else "Mask" %} |
+{%- set fill_layer_type = layer_type + "FillLayer" %} |
+{%- set access_layers = "access" + layer_type + "Layers" %} |
+{%- set map_fill = "mapFill" + fill_type %} |
+{{ apply_initial(property_id) }} |
+{ |
+ FillLayer* currChild = styleResolver->style()->{{access_layers}}(); |
+ currChild->set{{fill_type}}(FillLayer::initialFill{{fill_type}}({{fill_layer_type}})); |
+ for (currChild = currChild->next(); currChild; currChild = currChild->next()) |
+ currChild->clear{{fill_type}}(); |
+} |
+ |
+{{ apply_inherit(property_id) }} |
+{ |
+ FillLayer* currChild = styleResolver->style()->{{access_layers}}(); |
+ FillLayer* prevChild = 0; |
+ const FillLayer* currParent = styleResolver->parentStyle()->{{layer_type|lower}}Layers(); |
+ while (currParent && currParent->is{{fill_type}}Set()) { |
+ if (!currChild) { |
+ /* Need to make a new layer.*/ |
+ currChild = new FillLayer({{fill_layer_type}}); |
+ prevChild->setNext(currChild); |
+ } |
+ currChild->set{{fill_type}}(currParent->{{(fill_type[0]|lower) + fill_type[1:]}}()); |
+ 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(); |
+ } |
+} |
+ |
+{{ apply_value(property_id) }} |
+{ |
+ FillLayer* currChild = styleResolver->style()->{{access_layers}}(); |
+ FillLayer* prevChild = 0; |
+ if (value->isValueList() && !value->isImageSetValue()) { |
+ /* Walk each value and put it into a layer, creating new layers as needed. */ |
+ CSSValueList* valueList = toCSSValueList(value); |
+ for (unsigned int i = 0; i < valueList->length(); i++) { |
+ if (!currChild) { |
+ /* Need to make a new layer to hold this value */ |
+ currChild = new FillLayer({{fill_layer_type}}); |
+ prevChild->setNext(currChild); |
+ } |
+ styleResolver->styleMap()->{{map_fill}}({{property_id}}, currChild, valueList->itemWithoutBoundsCheck(i)); |
+ prevChild = currChild; |
+ currChild = currChild->next(); |
+ } |
+ } else { |
+ styleResolver->styleMap()->{{map_fill}}({{property_id}}, currChild, value); |
+ currChild = currChild->next(); |
+ } |
+ while (currChild) { |
+ /* Reset all remaining layers to not have the property set. */ |
+ currChild->clear{{fill_type}}(); |
+ currChild = currChild->next(); |
+ } |
+} |
+{%- endmacro %} |
+ |
+{{ apply_fill_layer("CSSPropertyBackgroundAttachment", "Attachment") }} |
+{{ apply_fill_layer("CSSPropertyBackgroundBlendMode", "BlendMode") }} |
+{{ apply_fill_layer("CSSPropertyBackgroundClip", "Clip") }} |
+{{ apply_fill_layer("CSSPropertyBackgroundImage", "Image") }} |
+{{ apply_fill_layer("CSSPropertyBackgroundOrigin", "Origin") }} |
+{{ apply_fill_layer("CSSPropertyBackgroundPositionX", "XPosition") }} |
+{{ apply_fill_layer("CSSPropertyBackgroundPositionY", "YPosition") }} |
+{{ apply_fill_layer("CSSPropertyBackgroundRepeatX", "RepeatX") }} |
+{{ apply_fill_layer("CSSPropertyBackgroundRepeatY", "RepeatY") }} |
+{{ apply_fill_layer("CSSPropertyBackgroundSize", "Size") }} |
+{{ apply_fill_layer("CSSPropertyWebkitBackgroundComposite", "Composite") }} |
+{{ apply_fill_layer("CSSPropertyWebkitMaskClip", "Clip") }} |
+{{ apply_fill_layer("CSSPropertyWebkitMaskComposite", "Composite") }} |
+{{ apply_fill_layer("CSSPropertyWebkitMaskImage", "Image") }} |
+{{ apply_fill_layer("CSSPropertyWebkitMaskOrigin", "Origin") }} |
+{{ apply_fill_layer("CSSPropertyWebkitMaskPositionX", "XPosition") }} |
+{{ apply_fill_layer("CSSPropertyWebkitMaskPositionY", "YPosition") }} |
+{{ apply_fill_layer("CSSPropertyWebkitMaskRepeatX", "RepeatX") }} |
+{{ apply_fill_layer("CSSPropertyWebkitMaskRepeatY", "RepeatY") }} |
+{{ apply_fill_layer("CSSPropertyWebkitMaskSize", "Size") }} |
+ |
{%- macro apply_value_number(property_id, id_for_minus_one) %} |
{{ apply_value(property_id) }} |
{ |