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

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

Issue 1164573002: CSSValue Immediates: Change CSSValue to an object instead of a pointer (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Some small fixes to (hopefully) fix some broken tests Created 5 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 license %} 1 {% from 'macros.tmpl' import license %}
2 {# 2 {#
3 This file is for property handlers which use the templating engine to 3 This file is for property handlers which use the templating engine to
4 reduce (handwritten) code duplication. 4 reduce (handwritten) code duplication.
5 5
6 The `properties' dict can be used to access a property's parameters in 6 The `properties' dict can be used to access a property's parameters in
7 jinja2 templates (i.e. setter, getter, initial, type_name) 7 jinja2 templates (i.e. setter, getter, initial, type_name)
8 #} 8 #}
9 #include "config.h" 9 #include "config.h"
10 #include "StyleBuilderFunctions.h" 10 #include "StyleBuilderFunctions.h"
11 11
12 #include "CSSValueKeywords.h" 12 #include "CSSValueKeywords.h"
13 #include "core/css/BasicShapeFunctions.h" 13 #include "core/css/BasicShapeFunctions.h"
14 #include "core/css/CSSContentDistributionValue.h" 14 #include "core/css/CSSContentDistributionValue.h"
15 #include "core/css/CSSPrimitiveValueMappings.h" 15 #include "core/css/CSSPrimitiveValueMappings.h"
16 #include "core/css/Pair.h" 16 #include "core/css/Pair.h"
17 #include "core/css/resolver/StyleResolverState.h" 17 #include "core/css/resolver/StyleResolverState.h"
18 18
19 {% macro declare_initial_function(property_id) %} 19 {% macro declare_initial_function(property_id) %}
20 void StyleBuilderFunctions::applyInitial{{property_id}}(StyleResolverState& stat e) 20 void StyleBuilderFunctions::applyInitial{{property_id}}(StyleResolverState& stat e)
21 {%- endmacro %} 21 {%- endmacro %}
22 {% macro declare_inherit_function(property_id) %} 22 {% macro declare_inherit_function(property_id) %}
23 void StyleBuilderFunctions::applyInherit{{property_id}}(StyleResolverState& stat e) 23 void StyleBuilderFunctions::applyInherit{{property_id}}(StyleResolverState& stat e)
24 {%- endmacro %} 24 {%- endmacro %}
25 {% macro declare_value_function(property_id) %} 25 {% macro declare_value_function(property_id) %}
26 void StyleBuilderFunctions::applyValue{{property_id}}(StyleResolverState& state, CSSValue* value) 26 void StyleBuilderFunctions::applyValue{{property_id}}(StyleResolverState& state, CSSValue value)
27 {%- endmacro %} 27 {%- endmacro %}
28 {% macro set_value(property) %} 28 {% macro set_value(property) %}
29 {% if property.svg %} 29 {% if property.svg %}
30 state.style()->accessSVGStyle().{{property.setter}} 30 state.style()->accessSVGStyle().{{property.setter}}
31 {%- elif property.font %} 31 {%- elif property.font %}
32 state.fontBuilder().{{property.setter}} 32 state.fontBuilder().{{property.setter}}
33 {%- else %} 33 {%- else %}
34 state.style()->{{property.setter}} 34 state.style()->{{property.setter}}
35 {%- endif %} 35 {%- endif %}
36 {% endmacro %} 36 {% endmacro %}
37 {% macro convert_and_set_value(property) %} 37 {% macro convert_and_set_value(property) %}
38 {% if property.converter %} 38 {% if property.converter %}
39 {{set_value(property)}}(StyleBuilderConverter::{{property.converter}}(state, val ue)); 39 {{set_value(property)}}(StyleBuilderConverter::{{property.converter}}(state, val ue));
40 {%- else %} 40 {%- else %}
41 {{set_value(property)}}(static_cast<{{property.type_name}}>(*toCSSPrimitiveValue (value))); 41 {{set_value(property)}}(static_cast<{{property.type_name}}>(toCSSPrimitiveValue( value)));
42 {%- endif %} 42 {%- endif %}
43 {% endmacro %} 43 {% endmacro %}
44 44
45 namespace blink { 45 namespace blink {
46 46
47 {% for property_id, property in properties.items() if property.should_declare_fu nctions %} 47 {% for property_id, property in properties.items() if property.should_declare_fu nctions %}
48 {% set apply_type = property.apply_type %} 48 {% set apply_type = property.apply_type %}
49 {% if not property.custom_initial %} 49 {% if not property.custom_initial %}
50 {{declare_initial_function(property_id)}} 50 {{declare_initial_function(property_id)}}
51 { 51 {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 if (!parentData) 96 if (!parentData)
97 applyInitial{{property_id}}(state); 97 applyInitial{{property_id}}(state);
98 else 98 else
99 state.style()->access{{animation}}s().{{vector}} = parentData->{{vector} }; 99 state.style()->access{{animation}}s().{{vector}} = parentData->{{vector} };
100 } 100 }
101 101
102 {{declare_value_function(property_id)}} 102 {{declare_value_function(property_id)}}
103 { 103 {
104 CSS{{animation}}Data& data = state.style()->access{{animation}}s(); 104 CSS{{animation}}Data& data = state.style()->access{{animation}}s();
105 data.{{vector}}.clear(); 105 data.{{vector}}.clear();
106 for (auto& listValue : toCSSValueList(*value)) 106 for (auto& listValue : toCSSValueList(value))
107 data.{{vector}}.append(CSSToStyleMap::mapAnimation{{attribute}}(listValu e.get())); 107 data.{{vector}}.append(CSSToStyleMap::mapAnimation{{attribute}}(listValu e));
108 } 108 }
109 {% endmacro %} 109 {% endmacro %}
110 {{apply_animation('CSSPropertyAnimationDelay', 'Delay', 'Animation')}} 110 {{apply_animation('CSSPropertyAnimationDelay', 'Delay', 'Animation')}}
111 {{apply_animation('CSSPropertyAnimationDirection', 'Direction', 'Animation')}} 111 {{apply_animation('CSSPropertyAnimationDirection', 'Direction', 'Animation')}}
112 {{apply_animation('CSSPropertyAnimationDuration', 'Duration', 'Animation')}} 112 {{apply_animation('CSSPropertyAnimationDuration', 'Duration', 'Animation')}}
113 {{apply_animation('CSSPropertyAnimationFillMode', 'FillMode', 'Animation')}} 113 {{apply_animation('CSSPropertyAnimationFillMode', 'FillMode', 'Animation')}}
114 {{apply_animation('CSSPropertyAnimationIterationCount', 'IterationCount', 'Anima tion')}} 114 {{apply_animation('CSSPropertyAnimationIterationCount', 'IterationCount', 'Anima tion')}}
115 {{apply_animation('CSSPropertyAnimationName', 'Name', 'Animation')}} 115 {{apply_animation('CSSPropertyAnimationName', 'Name', 'Animation')}}
116 {{apply_animation('CSSPropertyAnimationPlayState', 'PlayState', 'Animation')}} 116 {{apply_animation('CSSPropertyAnimationPlayState', 'PlayState', 'Animation')}}
117 {{apply_animation('CSSPropertyAnimationTimingFunction', 'TimingFunction', 'Anima tion')}} 117 {{apply_animation('CSSPropertyAnimationTimingFunction', 'TimingFunction', 'Anima tion')}}
(...skipping 14 matching lines...) Expand all
132 {{declare_inherit_function(property_id)}} 132 {{declare_inherit_function(property_id)}}
133 { 133 {
134 if (state.parentStyle()->{{auto_getter}}()) 134 if (state.parentStyle()->{{auto_getter}}())
135 state.style()->{{auto_setter}}(); 135 state.style()->{{auto_setter}}();
136 else 136 else
137 {{set_value(property)}}(state.parentStyle()->{{property.getter}}()); 137 {{set_value(property)}}(state.parentStyle()->{{property.getter}}());
138 } 138 }
139 139
140 {{declare_value_function(property_id)}} 140 {{declare_value_function(property_id)}}
141 { 141 {
142 if (!value->isPrimitiveValue()) 142 if (!value.isPrimitiveValue())
143 return; 143 return;
144 144
145 CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value); 145 CSSPrimitiveValue& primitiveValue = toCSSPrimitiveValue(value);
146 if (primitiveValue->getValueID() == {{auto_identity}}) 146 if (primitiveValue.getValueID() == {{auto_identity}})
147 state.style()->{{auto_setter}}(); 147 state.style()->{{auto_setter}}();
148 else 148 else
149 {{convert_and_set_value(property)}} 149 {{convert_and_set_value(property)}}
150 } 150 }
151 {% endmacro %} 151 {% endmacro %}
152 {{apply_auto('CSSPropertyClip')}} 152 {{apply_auto('CSSPropertyClip')}}
153 {{apply_auto('CSSPropertyOrphans')}} 153 {{apply_auto('CSSPropertyOrphans')}}
154 {{apply_auto('CSSPropertyWebkitColumnCount')}} 154 {{apply_auto('CSSPropertyWebkitColumnCount')}}
155 {{apply_auto('CSSPropertyWebkitColumnGap', auto_getter='hasNormalColumnGap', aut o_setter='setHasNormalColumnGap', auto_identity='CSSValueNormal')}} 155 {{apply_auto('CSSPropertyWebkitColumnGap', auto_getter='hasNormalColumnGap', aut o_setter='setHasNormalColumnGap', auto_identity='CSSValueNormal')}}
156 {{apply_auto('CSSPropertyWebkitColumnWidth')}} 156 {{apply_auto('CSSPropertyWebkitColumnWidth')}}
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 for (Iterator it = parentMap->begin(); it != end; ++it) { 342 for (Iterator it = parentMap->begin(); it != end; ++it) {
343 CounterDirectives& directives = map.add(it->key, CounterDirectives()).st oredValue->value; 343 CounterDirectives& directives = map.add(it->key, CounterDirectives()).st oredValue->value;
344 directives.inherit{{action}}(it->value); 344 directives.inherit{{action}}(it->value);
345 } 345 }
346 } 346 }
347 347
348 {{declare_value_function(property_id)}} 348 {{declare_value_function(property_id)}}
349 { 349 {
350 state.style()->clear{{action}}Directives(); 350 state.style()->clear{{action}}Directives();
351 351
352 if (!value->isValueList()) { 352 if (!value.isValueList()) {
353 ASSERT(value->isPrimitiveValue() && toCSSPrimitiveValue(value)->getValue ID() == CSSValueNone); 353 ASSERT(value.isPrimitiveValue() && toCSSPrimitiveValue(value).getValueID () == CSSValueNone);
354 return; 354 return;
355 } 355 }
356 356
357 CounterDirectiveMap& map = state.style()->accessCounterDirectives(); 357 CounterDirectiveMap& map = state.style()->accessCounterDirectives();
358 358
359 CSSValueList* list = toCSSValueList(value); 359 CSSValueList& list = toCSSValueList(value);
360 360
361 int length = list ? list->length() : 0; 361 int length = list.length();
362 for (int i = 0; i < length; ++i) { 362 for (int i = 0; i < length; ++i) {
363 CSSValue* currValue = list->item(i); 363 CSSValue currValue = list.item(i);
364 if (!currValue->isPrimitiveValue()) 364 if (!currValue.isPrimitiveValue())
365 continue; 365 continue;
366 366
367 Pair* pair = toCSSPrimitiveValue(currValue)->getPairValue(); 367 Pair* pair = toCSSPrimitiveValue(currValue).getPairValue();
368 if (!pair || !pair->first() || !pair->second()) 368 if (!pair || !pair->first() || !pair->second())
369 continue; 369 continue;
370 370
371 AtomicString identifier(pair->first()->getStringValue()); 371 AtomicString identifier(pair->first()->getStringValue());
372 int value = pair->second()->getIntValue(); 372 int value = pair->second()->getIntValue();
373 CounterDirectives& directives = map.add(identifier, CounterDirectives()) .storedValue->value; 373 CounterDirectives& directives = map.add(identifier, CounterDirectives()) .storedValue->value;
374 {% if action == 'Reset' %} 374 {% if action == 'Reset' %}
375 directives.setResetValue(value); 375 directives.setResetValue(value);
376 {% else %} 376 {% else %}
377 directives.addIncrementValue(value); 377 directives.addIncrementValue(value);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 /* Reset any remaining layers to not have the property set. */ 414 /* Reset any remaining layers to not have the property set. */
415 currChild->clear{{fill_type}}(); 415 currChild->clear{{fill_type}}();
416 currChild = currChild->next(); 416 currChild = currChild->next();
417 } 417 }
418 } 418 }
419 419
420 {{declare_value_function(property_id)}} 420 {{declare_value_function(property_id)}}
421 { 421 {
422 FillLayer* currChild = &state.style()->{{access_layers}}(); 422 FillLayer* currChild = &state.style()->{{access_layers}}();
423 FillLayer* prevChild = 0; 423 FillLayer* prevChild = 0;
424 if (value->isValueList() && !value->isImageSetValue()) { 424 if (value.isValueList() && !value.isImageSetValue()) {
425 /* Walk each value and put it into a layer, creating new layers as neede d. */ 425 /* Walk each value and put it into a layer, creating new layers as neede d. */
426 CSSValueList* valueList = toCSSValueList(value); 426 CSSValueList& valueList = toCSSValueList(value);
427 for (unsigned int i = 0; i < valueList->length(); i++) { 427 for (unsigned int i = 0; i < valueList.length(); i++) {
428 if (!currChild) 428 if (!currChild)
429 currChild = prevChild->ensureNext(); 429 currChild = prevChild->ensureNext();
430 CSSToStyleMap::{{map_fill}}(state, currChild, valueList->item(i)); 430 CSSToStyleMap::{{map_fill}}(state, currChild, valueList.item(i));
431 prevChild = currChild; 431 prevChild = currChild;
432 currChild = currChild->next(); 432 currChild = currChild->next();
433 } 433 }
434 } else { 434 } else {
435 CSSToStyleMap::{{map_fill}}(state, currChild, value); 435 CSSToStyleMap::{{map_fill}}(state, currChild, value);
436 currChild = currChild->next(); 436 currChild = currChild->next();
437 } 437 }
438 while (currChild) { 438 while (currChild) {
439 /* Reset all remaining layers to not have the property set. */ 439 /* Reset all remaining layers to not have the property set. */
440 currChild->clear{{fill_type}}(); 440 currChild->clear{{fill_type}}();
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
516 svgParentStyle.{{paint_type|lower_first}}Type(), 516 svgParentStyle.{{paint_type|lower_first}}Type(),
517 svgParentStyle.{{paint_type|lower_first}}Color(), 517 svgParentStyle.{{paint_type|lower_first}}Color(),
518 svgParentStyle.{{paint_type|lower_first}}Uri(), 518 svgParentStyle.{{paint_type|lower_first}}Uri(),
519 state.applyPropertyToRegularStyle(), 519 state.applyPropertyToRegularStyle(),
520 state.applyPropertyToVisitedLinkStyle()); 520 state.applyPropertyToVisitedLinkStyle());
521 } 521 }
522 522
523 {{declare_value_function(property_id)}} 523 {{declare_value_function(property_id)}}
524 { 524 {
525 String url; 525 String url;
526 if (value->isValueList()) { 526 if (value.isValueList()) {
527 CSSValueList* list = toCSSValueList(value); 527 CSSValueList& list = toCSSValueList(value);
528 ASSERT(list->length() > 1); 528 ASSERT(list.length() > 1);
529 529
530 if (!list->item(0)->isPrimitiveValue()) 530 if (!list.item(0).isPrimitiveValue())
531 return; 531 return;
532 532
533 CSSPrimitiveValue* pValue = toCSSPrimitiveValue(list->item(0)); 533 CSSPrimitiveValue& pValue = toCSSPrimitiveValue(list.item(0));
534 if (!pValue->isURI()) 534 if (!pValue.isURI())
535 return; 535 return;
536 536
537 url = pValue->getStringValue(); 537 url = pValue.getStringValue();
538 value = list->item(1); 538 value = list.item(1);
539 } 539 }
540 if (value->isPrimitiveValue()) { 540 if (value.isPrimitiveValue()) {
541 CSSPrimitiveValue* pValue = toCSSPrimitiveValue(value); 541 CSSPrimitiveValue& pValue = toCSSPrimitiveValue(value);
542 Color c; 542 Color c;
543 SVGPaintType ptype = SVG_PAINTTYPE_RGBCOLOR; 543 SVGPaintType ptype = SVG_PAINTTYPE_RGBCOLOR;
544 if (pValue->isRGBColor()) { 544 if (pValue.isRGBColor()) {
545 c = pValue->getRGBA32Value(); 545 c = pValue.getRGBA32Value();
546 ptype = url.isEmpty() ? SVG_PAINTTYPE_RGBCOLOR : SVG_PAINTTYPE_URI_R GBCOLOR; 546 ptype = url.isEmpty() ? SVG_PAINTTYPE_RGBCOLOR : SVG_PAINTTYPE_URI_R GBCOLOR;
547 } else if (pValue->getValueID() == CSSValueCurrentcolor) { 547 } else if (pValue.getValueID() == CSSValueCurrentcolor) {
548 c = state.style()->color(); 548 c = state.style()->color();
549 ptype = url.isEmpty() ? SVG_PAINTTYPE_CURRENTCOLOR : SVG_PAINTTYPE_U RI_CURRENTCOLOR; 549 ptype = url.isEmpty() ? SVG_PAINTTYPE_CURRENTCOLOR : SVG_PAINTTYPE_U RI_CURRENTCOLOR;
550 } else if (pValue->getValueID() == CSSValueNone) { 550 } else if (pValue.getValueID() == CSSValueNone) {
551 ptype = url.isEmpty() ? SVG_PAINTTYPE_NONE : SVG_PAINTTYPE_URI_NONE; 551 ptype = url.isEmpty() ? SVG_PAINTTYPE_NONE : SVG_PAINTTYPE_URI_NONE;
552 } else if (pValue->isURI()) { 552 } else if (pValue.isURI()) {
553 ptype = SVG_PAINTTYPE_URI; 553 ptype = SVG_PAINTTYPE_URI;
554 url = pValue->getStringValue(); 554 url = pValue.getStringValue();
555 } else { 555 } else {
556 return; 556 return;
557 } 557 }
558 {{set_value(property)}}(ptype, c, url, 558 {{set_value(property)}}(ptype, c, url,
559 state.applyPropertyToRegularStyle(), 559 state.applyPropertyToRegularStyle(),
560 state.applyPropertyToVisitedLinkStyle()); 560 state.applyPropertyToVisitedLinkStyle());
561 } 561 }
562 } 562 }
563 {% endmacro %} 563 {% endmacro %}
564 {{apply_svg_paint('CSSPropertyFill', 'FillPaint')}} 564 {{apply_svg_paint('CSSPropertyFill', 'FillPaint')}}
565 {{apply_svg_paint('CSSPropertyStroke', 'StrokePaint')}} 565 {{apply_svg_paint('CSSPropertyStroke', 'StrokePaint')}}
566 } // namespace blink 566 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698