Skip to content

Commit

Permalink
Handle initial values in background-repeat introduced by the backgrou…
Browse files Browse the repository at this point in the history
…nd 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
  • Loading branch information
alancutter@chromium.org committed Jun 2, 2014
1 parent 35a0fdf commit 05eca13
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
9 changes: 8 additions & 1 deletion LayoutTests/fast/css/background-repeat-serialize.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@
// 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'),
// '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');

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>
18 changes: 11 additions & 7 deletions Source/core/css/StylePropertySerializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -702,20 +702,24 @@ String StylePropertySerializer::borderPropertyValue(CommonValueMode valueMode) c
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();
CSSValueID repeatYValueId = toCSSPrimitiveValue(repeatYValue).getValueID();
// FIXME: Ensure initial values do not appear in CSS_VALUE_LISTS.
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) {
builder.append(repeatXValue.cssText());
builder.append(repeatX.cssText());
} else if (repeatXValueId == CSSValueNoRepeat && repeatYValueId == CSSValueRepeat) {
builder.append("repeat-y");
} else if (repeatXValueId == CSSValueRepeat && repeatYValueId == CSSValueNoRepeat) {
builder.append("repeat-x");
} else {
builder.append(repeatXValue.cssText());
builder.append(repeatX.cssText());
builder.append(" ");
builder.append(repeatYValue.cssText());
builder.append(repeatY.cssText());
}
}

Expand Down Expand Up @@ -757,7 +761,7 @@ String StylePropertySerializer::backgroundRepeatPropertyValue() const
for (size_t i = 0; i < shorthandLength; ++i) {
if (i)
builder.append(", ");
buildSingleBackgroundRepeatValue(builder,
appendBackgroundRepeatValue(builder,
*repeatXList->item(i % repeatXList->length()),
*repeatYList->item(i % repeatYList->length()));
}
Expand Down

0 comments on commit 05eca13

Please sign in to comment.