Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1226)

Side by Side Diff: Source/core/scripts/templates/StyleBuilderFunctions.cpp.tmpl

Issue 16530002: Move Color and FillLayer properties to new StyleBuilder (Closed) Base URL: https://chromium.googlesource.com/chromium/blink@master
Patch Set: rebased Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 {% from "macros.tmpl" import wrap_with_condition -%}
2
1 {# 3 {#
2 This file is for property handlers which use the templating engine to 4 This file is for property handlers which use the templating engine to
3 reduce (handwritten) code duplication. 5 reduce (handwritten) code duplication.
4 6
5 The `properties' dict can be used to access a property's parameters in 7 The `properties' dict can be used to access a property's parameters in
6 jinja2 templates (i.e. setter, getter, initial, type_name, condition) 8 jinja2 templates (i.e. setter, getter, initial, type_name, condition)
7 -#} 9 -#}
8 10
9 #include "config.h" 11 #include "config.h"
10 #include "StyleBuilderFunctions.h" 12 #include "StyleBuilderFunctions.h"
(...skipping 28 matching lines...) Expand all
39 image.setMaskDefaults(); 41 image.setMaskDefaults();
40 {%- endif %} 42 {%- endif %}
41 styleResolver->styleMap()->mapNinePieceImage({{property_id}}, value, image); 43 styleResolver->styleMap()->mapNinePieceImage({{property_id}}, value, image);
42 {{ set_value(property) }}(image); 44 {{ set_value(property) }}(image);
43 } 45 }
44 {%- endmacro %} 46 {%- endmacro %}
45 47
46 {{ apply_value_border_image("CSSPropertyWebkitBorderImage") }} 48 {{ apply_value_border_image("CSSPropertyWebkitBorderImage") }}
47 {{ apply_value_border_image("CSSPropertyWebkitMaskBoxImage") }} 49 {{ apply_value_border_image("CSSPropertyWebkitMaskBoxImage") }}
48 50
51 {%- macro apply_color(property_id, default_getter="color", initial_color=none, i nherit_color=false) %}
52 {%- set property = properties[property_id] %}
53 {%- call wrap_with_condition(property.condition) %}
54 {%- set visited_link_setter = "setVisitedLink" + property.camel_case_name %}
55 {{ apply_initial(property_id) }}
56 {
57 Color color = {{ initial_color or "Color" -}}();
58 if (styleResolver->applyPropertyToRegularStyle())
59 {{ set_value(property) }}(color);
60 if (styleResolver->applyPropertyToVisitedLinkStyle())
61 styleResolver->style()->{{visited_link_setter}}(color);
62 }
63
64 {{ apply_inherit(property_id) }}
65 {
66 // Visited link style can never explicitly inherit from parent visited link style so no separate getters are needed.
67 Color color = styleResolver->parentStyle()->{{property.getter}}();
68 if (!color.isValid())
69 color = styleResolver->parentStyle()->{{default_getter}}();
70 if (styleResolver->applyPropertyToRegularStyle())
71 {{ set_value(property) }}(color);
72 if (styleResolver->applyPropertyToVisitedLinkStyle())
73 styleResolver->style()->{{visited_link_setter}}(color);
74 }
75
76 {{ apply_value(property_id) }}
77 {
78 if (!value->isPrimitiveValue())
79 return;
80
81 CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value);
82
83 {%- if inherit_color %}
84 if (primitiveValue->getValueID() == CSSValueCurrentcolor) {
85 applyInherit{{property_id}}(styleResolver);
86 return;
87 }
88 {%- endif %}
89
90 if (styleResolver->applyPropertyToRegularStyle())
91 {{ set_value(property) }}(styleResolver->colorFromPrimitiveValue(primiti veValue));
92 if (styleResolver->applyPropertyToVisitedLinkStyle())
93 styleResolver->style()->{{visited_link_setter}}(styleResolver->colorFrom PrimitiveValue(primitiveValue, /* forVisitedLink */ true));
94 }
95 {%- endcall %}
96 {%- endmacro %}
97
98 {{ apply_color("CSSPropertyBackgroundColor", default_getter="invalidColor") }}
99 {{ apply_color("CSSPropertyBorderBottomColor") }}
100 {{ apply_color("CSSPropertyBorderLeftColor") }}
101 {{ apply_color("CSSPropertyBorderRightColor") }}
102 {{ apply_color("CSSPropertyBorderTopColor") }}
103 {{ apply_color("CSSPropertyColor", inherit_color=true, default_getter="invalidCo lor", initial_color="RenderStyle::initialColor") }}
104 {{ apply_color("CSSPropertyOutlineColor") }}
105 {{ apply_color("CSSPropertyTextDecorationColor") }}
106 {{ apply_color("CSSPropertyWebkitColumnRuleColor") }}
107 {{ apply_color("CSSPropertyWebkitTextEmphasisColor") }}
108 {{ apply_color("CSSPropertyWebkitTextFillColor") }}
109 {{ apply_color("CSSPropertyWebkitTextStrokeColor") }}
110
111 {%- macro apply_fill_layer(property_id, fill_type) %}
112 {%- set layer_type = "Background" if "Background" in property_id else "Mask" %}
113 {%- set fill_layer_type = layer_type + "FillLayer" %}
114 {%- set access_layers = "access" + layer_type + "Layers" %}
115 {%- set map_fill = "mapFill" + fill_type %}
116 {{ apply_initial(property_id) }}
117 {
118 FillLayer* currChild = styleResolver->style()->{{access_layers}}();
119 currChild->set{{fill_type}}(FillLayer::initialFill{{fill_type}}({{fill_layer _type}}));
120 for (currChild = currChild->next(); currChild; currChild = currChild->next() )
121 currChild->clear{{fill_type}}();
122 }
123
124 {{ apply_inherit(property_id) }}
125 {
126 FillLayer* currChild = styleResolver->style()->{{access_layers}}();
127 FillLayer* prevChild = 0;
128 const FillLayer* currParent = styleResolver->parentStyle()->{{layer_type|low er}}Layers();
129 while (currParent && currParent->is{{fill_type}}Set()) {
130 if (!currChild) {
131 /* Need to make a new layer.*/
132 currChild = new FillLayer({{fill_layer_type}});
133 prevChild->setNext(currChild);
134 }
135 currChild->set{{fill_type}}(currParent->{{(fill_type[0]|lower) + fill_ty pe[1:]}}());
136 prevChild = currChild;
137 currChild = prevChild->next();
138 currParent = currParent->next();
139 }
140
141 while (currChild) {
142 /* Reset any remaining layers to not have the property set. */
143 currChild->clear{{fill_type}}();
144 currChild = currChild->next();
145 }
146 }
147
148 {{ apply_value(property_id) }}
149 {
150 FillLayer* currChild = styleResolver->style()->{{access_layers}}();
151 FillLayer* prevChild = 0;
152 if (value->isValueList() && !value->isImageSetValue()) {
153 /* Walk each value and put it into a layer, creating new layers as neede d. */
154 CSSValueList* valueList = toCSSValueList(value);
155 for (unsigned int i = 0; i < valueList->length(); i++) {
156 if (!currChild) {
157 /* Need to make a new layer to hold this value */
158 currChild = new FillLayer({{fill_layer_type}});
159 prevChild->setNext(currChild);
160 }
161 styleResolver->styleMap()->{{map_fill}}({{property_id}}, currChild, valueList->itemWithoutBoundsCheck(i));
162 prevChild = currChild;
163 currChild = currChild->next();
164 }
165 } else {
166 styleResolver->styleMap()->{{map_fill}}({{property_id}}, currChild, valu e);
167 currChild = currChild->next();
168 }
169 while (currChild) {
170 /* Reset all remaining layers to not have the property set. */
171 currChild->clear{{fill_type}}();
172 currChild = currChild->next();
173 }
174 }
175 {%- endmacro %}
176
177 {{ apply_fill_layer("CSSPropertyBackgroundAttachment", "Attachment") }}
178 {{ apply_fill_layer("CSSPropertyBackgroundBlendMode", "BlendMode") }}
179 {{ apply_fill_layer("CSSPropertyBackgroundClip", "Clip") }}
180 {{ apply_fill_layer("CSSPropertyBackgroundImage", "Image") }}
181 {{ apply_fill_layer("CSSPropertyBackgroundOrigin", "Origin") }}
182 {{ apply_fill_layer("CSSPropertyBackgroundPositionX", "XPosition") }}
183 {{ apply_fill_layer("CSSPropertyBackgroundPositionY", "YPosition") }}
184 {{ apply_fill_layer("CSSPropertyBackgroundRepeatX", "RepeatX") }}
185 {{ apply_fill_layer("CSSPropertyBackgroundRepeatY", "RepeatY") }}
186 {{ apply_fill_layer("CSSPropertyBackgroundSize", "Size") }}
187 {{ apply_fill_layer("CSSPropertyWebkitBackgroundComposite", "Composite") }}
188 {{ apply_fill_layer("CSSPropertyWebkitMaskClip", "Clip") }}
189 {{ apply_fill_layer("CSSPropertyWebkitMaskComposite", "Composite") }}
190 {{ apply_fill_layer("CSSPropertyWebkitMaskImage", "Image") }}
191 {{ apply_fill_layer("CSSPropertyWebkitMaskOrigin", "Origin") }}
192 {{ apply_fill_layer("CSSPropertyWebkitMaskPositionX", "XPosition") }}
193 {{ apply_fill_layer("CSSPropertyWebkitMaskPositionY", "YPosition") }}
194 {{ apply_fill_layer("CSSPropertyWebkitMaskRepeatX", "RepeatX") }}
195 {{ apply_fill_layer("CSSPropertyWebkitMaskRepeatY", "RepeatY") }}
196 {{ apply_fill_layer("CSSPropertyWebkitMaskSize", "Size") }}
197
49 {%- macro apply_value_number(property_id, id_for_minus_one) %} 198 {%- macro apply_value_number(property_id, id_for_minus_one) %}
50 {{ apply_value(property_id) }} 199 {{ apply_value(property_id) }}
51 { 200 {
52 {%- set property = properties[property_id] %} 201 {%- set property = properties[property_id] %}
53 if (!value->isPrimitiveValue()) 202 if (!value->isPrimitiveValue())
54 return; 203 return;
55 204
56 CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value); 205 CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value);
57 if (primitiveValue->getValueID() == {{id_for_minus_one}}) 206 if (primitiveValue->getValueID() == {{id_for_minus_one}})
58 {{ set_value(property) }}(-1); 207 {{ set_value(property) }}(-1);
(...skipping 28 matching lines...) Expand all
87 break; 236 break;
88 } 237 }
89 } else { 238 } else {
90 Length marqueeLength = styleResolver->convertToIntLength(primitiveValue, styleResolver->style(), styleResolver->rootElementStyle()); 239 Length marqueeLength = styleResolver->convertToIntLength(primitiveValue, styleResolver->style(), styleResolver->rootElementStyle());
91 if (!marqueeLength.isUndefined()) 240 if (!marqueeLength.isUndefined())
92 styleResolver->style()->setMarqueeIncrement(marqueeLength); 241 styleResolver->style()->setMarqueeIncrement(marqueeLength);
93 } 242 }
94 } 243 }
95 244
96 } // namespace WebCore 245 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/scripts/templates/StyleBuilder.cpp.tmpl ('k') | Source/core/scripts/templates/StyleBuilderFunctions.h.tmpl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698