Skip to content

Commit

Permalink
#649 Multiple values for background-repeat property
Browse files Browse the repository at this point in the history
  • Loading branch information
danfickle committed Feb 14, 2021
1 parent b94d62f commit 0ad58c5
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public List<PropertyDeclaration> buildDeclarations(
}

backgroundRepeat = new PropertyDeclaration(
CSSName.BACKGROUND_REPEAT, value, important, origin);
CSSName.BACKGROUND_REPEAT, new PropertyValue(Collections.singletonList(value)), important, origin);
}

if (PrimitivePropertyBuilders.BACKGROUND_ATTACHMENTS.get(ident.FS_ID)) {
Expand Down Expand Up @@ -182,7 +182,7 @@ public List<PropertyDeclaration> buildDeclarations(

if (backgroundRepeat == null) {
backgroundRepeat = new PropertyDeclaration(
CSSName.BACKGROUND_REPEAT, new PropertyValue(IdentValue.REPEAT), important, origin);
CSSName.BACKGROUND_REPEAT, new PropertyValue(Collections.singletonList(new PropertyValue(IdentValue.REPEAT))), important, origin);
}

if (backgroundAttachment == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,17 @@ private BitSet getAllowed() {
}
}

public static class BackgroundRepeat extends SingleIdent {
public static class BackgroundRepeat extends MultipleBackgroundValueBuilder {
@Override
protected List<PropertyValue> processValue(CSSName cssName, PropertyValue value) {
checkIdentType(cssName, value);
IdentValue ident = checkIdent(cssName, value);

checkValidity(cssName, getAllowed(), ident);

return Collections.singletonList(value);
}

protected BitSet getAllowed() {
return PrimitivePropertyBuilders.BACKGROUND_REPEATS;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -791,8 +791,8 @@ public boolean isCleared() {
return ! isIdent(CSSName.CLEAR, IdentValue.NONE);
}

public IdentValue getBackgroundRepeat() {
return getIdent(CSSName.BACKGROUND_REPEAT);
public IdentValue getBackgroundRepeat(PropertyValue value) {
return value.getIdentValue();
}

public IdentValue getBackgroundAttachment() {
Expand Down Expand Up @@ -1011,14 +1011,12 @@ public boolean isOverflowVisible() {
return valueByName(CSSName.OVERFLOW) == IdentValue.VISIBLE;
}

public boolean isHorizontalBackgroundRepeat() {
IdentValue value = getIdent(CSSName.BACKGROUND_REPEAT);
return value == IdentValue.REPEAT_X || value == IdentValue.REPEAT;
public boolean isHorizontalBackgroundRepeat(PropertyValue value) {
return value.getIdentValue() == IdentValue.REPEAT_X || value.getIdentValue() == IdentValue.REPEAT;
}

public boolean isVerticalBackgroundRepeat() {
IdentValue value = getIdent(CSSName.BACKGROUND_REPEAT);
return value == IdentValue.REPEAT_Y || value == IdentValue.REPEAT;
public boolean isVerticalBackgroundRepeat(PropertyValue value) {
return value.getIdentValue() == IdentValue.REPEAT_Y || value.getIdentValue() == IdentValue.REPEAT;
}

public boolean isTopAuto() {
Expand Down Expand Up @@ -1412,6 +1410,7 @@ public static class BackgroundContainer {
public PropertyValue imageGradientOrNone;

public BackgroundPosition backgroundPosition;
public PropertyValue backgroundRepeat;
}

public boolean isLinearGradient(PropertyValue value) {
Expand All @@ -1432,6 +1431,7 @@ public FSLinearGradient getLinearGradient(
public List<BackgroundContainer> getBackgroundImages() {
List<PropertyValue> images = ((ListValue) valueByName(CSSName.BACKGROUND_IMAGE)).getValues();
List<PropertyValue> positions = ((ListValue) valueByName(CSSName.BACKGROUND_POSITION)).getValues();
List<PropertyValue> repeats = ((ListValue) valueByName(CSSName.BACKGROUND_REPEAT)).getValues();

assert positions.size() % 2 == 0;

Expand Down Expand Up @@ -1459,6 +1459,7 @@ public List<BackgroundContainer> getBackgroundImages() {
// If less background-position values are provided than images,
// they must repeat.
bg.backgroundPosition = posPairs.get(i % posPairs.size());
bg.backgroundRepeat = repeats.get(i % repeats.size());

backgrounds.add(bg);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -359,8 +359,8 @@ private void drawBgImage(
xoff += calcOffset(c, style, position.getHorizontal(), localBGImageContainer.width, imageWidth);
yoff += calcOffset(c, style, position.getVertical(), localBGImageContainer.height, imageHeight);

boolean hrepeat = style.isHorizontalBackgroundRepeat();
boolean vrepeat = style.isVerticalBackgroundRepeat();
boolean hrepeat = style.isHorizontalBackgroundRepeat(bgImage.backgroundRepeat);
boolean vrepeat = style.isVerticalBackgroundRepeat(bgImage.backgroundRepeat);

if (!hrepeat && !vrepeat) {
Rectangle imageBounds = new Rectangle(xoff, yoff, (int) imageWidth, (int) imageHeight);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@
background-image: url(../../demos/images/cc0-cat.png), linear-gradient(to top, red, blue);
background-position: 20% top;
}
#five {
height: 200px;
background-image: url(../../demos/images/cc0-cat.png), url(../../demos/images/flyingsaucer.png), none;
background-repeat: no-repeat, repeat-y;
background-position: right;
}
</style>
</head>
<body>
Expand All @@ -45,5 +51,7 @@

<div id="four"></div>

<div id="five"></div>

</body>
</html>

0 comments on commit 0ad58c5

Please sign in to comment.