Handle initial values in background-repeat introduced by the background shorthand

background-repeat serialization did not handle initial keyword values in
background-repeat value lists.
Initial values in value lists are introduced by setting the background
shorthand to multiple background values while omitting background-repeat
properties.
Example: background: url(#1), url(#2), url(#3);
The background-repeat gets stored internally as "initial, initial, initial".

This patch updates StylePropertySerializer::backgroundRepeatPropertyValue()
to handle this case correctly.

BUG=378167

Review URL: https://codereview.chromium.org/303993003

git-svn-id: svn://svn.chromium.org/blink/trunk@175261 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent faeadbc7
...@@ -34,6 +34,13 @@ test(function() { ...@@ -34,6 +34,13 @@ test(function() {
// FIXME (crbug.com/376179): Make setting background-repeat-x/y to multiple values work on CSSStyleDeclarations. // FIXME (crbug.com/376179): Make setting background-repeat-x/y to multiple values work on CSSStyleDeclarations.
// assert_equals(serialize('background-repeat-x: repeat, no-repeat; background-repeat-y: no-repeat, repeat, no-repeat'), // assert_equals(serialize('background-repeat-x: repeat, no-repeat; background-repeat-y: no-repeat, repeat, no-repeat'),
// 'repeat-x, repeat-y, repeat-x, no-repeat, repeat, no-repeat'); // 'repeat-x, repeat-y, repeat-x, no-repeat, repeat, no-repeat');
assert_equals(serialize('background-repeat: repeat, no-repeat, repeat; background-repeat-y: no-repeat'), 'repeat-x, no-repeat, repeat-x'); assert_equals(serialize('background-repeat: repeat, no-repeat, repeat; background-repeat-y: no-repeat;'), 'repeat-x, no-repeat, repeat-x');
}, 'Mismatched value lengths should repeat to their lowest common multiple'); }, 'Mismatched value lengths should repeat to their lowest common multiple');
test(function() {
assert_equals(serialize('background: url(#1), url(#2), url(#3);'), 'repeat, repeat, repeat');
assert_equals(serialize('background: repeat-x, repeat-y, url(#);'), 'repeat-x, repeat-y, repeat');
assert_equals(serialize('background: url(#), no-repeat; background-repeat-x: no-repeat'), 'repeat-y, no-repeat');
assert_equals(serialize('background: url(#), no-repeat; background-repeat-y: no-repeat'), 'repeat-x, no-repeat');
}, 'Initial values introduced by the background shorthand should be handled as repeat.');
</script> </script>
...@@ -702,20 +702,24 @@ String StylePropertySerializer::borderPropertyValue(CommonValueMode valueMode) c ...@@ -702,20 +702,24 @@ String StylePropertySerializer::borderPropertyValue(CommonValueMode valueMode) c
return result.isEmpty() ? String() : result.toString(); return result.isEmpty() ? String() : result.toString();
} }
static void buildSingleBackgroundRepeatValue(StringBuilder& builder, const CSSValue& repeatXValue, const CSSValue& repeatYValue) static void appendBackgroundRepeatValue(StringBuilder& builder, const CSSValue& repeatXCSSValue, const CSSValue& repeatYCSSValue)
{ {
CSSValueID repeatXValueId = toCSSPrimitiveValue(repeatXValue).getValueID(); // FIXME: Ensure initial values do not appear in CSS_VALUE_LISTS.
CSSValueID repeatYValueId = toCSSPrimitiveValue(repeatYValue).getValueID(); DEFINE_STATIC_REF_WILL_BE_PERSISTENT(CSSPrimitiveValue, initialRepeatValue, CSSPrimitiveValue::create(CSSValueRepeat));
const CSSPrimitiveValue& repeatX = repeatXCSSValue.isInitialValue() ? *initialRepeatValue : toCSSPrimitiveValue(repeatXCSSValue);
const CSSPrimitiveValue& repeatY = repeatYCSSValue.isInitialValue() ? *initialRepeatValue : toCSSPrimitiveValue(repeatYCSSValue);
CSSValueID repeatXValueId = repeatX.getValueID();
CSSValueID repeatYValueId = repeatY.getValueID();
if (repeatXValueId == repeatYValueId) { if (repeatXValueId == repeatYValueId) {
builder.append(repeatXValue.cssText()); builder.append(repeatX.cssText());
} else if (repeatXValueId == CSSValueNoRepeat && repeatYValueId == CSSValueRepeat) { } else if (repeatXValueId == CSSValueNoRepeat && repeatYValueId == CSSValueRepeat) {
builder.append("repeat-y"); builder.append("repeat-y");
} else if (repeatXValueId == CSSValueRepeat && repeatYValueId == CSSValueNoRepeat) { } else if (repeatXValueId == CSSValueRepeat && repeatYValueId == CSSValueNoRepeat) {
builder.append("repeat-x"); builder.append("repeat-x");
} else { } else {
builder.append(repeatXValue.cssText()); builder.append(repeatX.cssText());
builder.append(" "); builder.append(" ");
builder.append(repeatYValue.cssText()); builder.append(repeatY.cssText());
} }
} }
...@@ -757,7 +761,7 @@ String StylePropertySerializer::backgroundRepeatPropertyValue() const ...@@ -757,7 +761,7 @@ String StylePropertySerializer::backgroundRepeatPropertyValue() const
for (size_t i = 0; i < shorthandLength; ++i) { for (size_t i = 0; i < shorthandLength; ++i) {
if (i) if (i)
builder.append(", "); builder.append(", ");
buildSingleBackgroundRepeatValue(builder, appendBackgroundRepeatValue(builder,
*repeatXList->item(i % repeatXList->length()), *repeatXList->item(i % repeatXList->length()),
*repeatYList->item(i % repeatYList->length())); *repeatYList->item(i % repeatYList->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