Skip to content

Commit

Permalink
#649 Removed broken support for background-attachment: fixed
Browse files Browse the repository at this point in the history
Currently the property is a no-op as the only valid value is scroll.
  • Loading branch information
danfickle committed Feb 15, 2021
1 parent 0ad58c5 commit 2dbce9b
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package com.openhtmltopdf.css.parser.property;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

Expand Down Expand Up @@ -101,11 +102,11 @@ public List<PropertyDeclaration> buildDeclarations(
if (backgroundAttachment != null) {
throw new CSSParseException("A background-attachment value cannot be set twice", -1);
}

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

if (ident == IdentValue.TRANSPARENT) {
if (backgroundColor != null) {
throw new CSSParseException("A background-color value cannot be set twice", -1);
Expand Down Expand Up @@ -172,40 +173,34 @@ public List<PropertyDeclaration> buildDeclarations(
backgroundColor = new PropertyDeclaration(
CSSName.BACKGROUND_COLOR, new PropertyValue(IdentValue.TRANSPARENT), important, origin);
}

if (backgroundImage == null) {
List<PropertyValue> bgImages = Collections.singletonList(new PropertyValue(IdentValue.NONE));

backgroundImage = new PropertyDeclaration(
CSSName.BACKGROUND_IMAGE, new PropertyValue(bgImages), important, origin);
}

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

if (backgroundAttachment == null) {
backgroundAttachment = new PropertyDeclaration(
CSSName.BACKGROUND_ATTACHMENT, new PropertyValue(IdentValue.SCROLL), important, origin);

CSSName.BACKGROUND_ATTACHMENT, new PropertyValue(Collections.singletonList(new PropertyValue(IdentValue.SCROLL))), important, origin);
}

if (backgroundPosition == null) {
List<PropertyValue> v = new ArrayList<>(2);
v.add(new PropertyValue(CSSPrimitiveValue.CSS_PERCENTAGE, 0.0f, "0%"));
v.add(new PropertyValue(CSSPrimitiveValue.CSS_PERCENTAGE, 0.0f, "0%"));
backgroundPosition = new PropertyDeclaration(
CSSName.BACKGROUND_POSITION, new PropertyValue(v), important, origin);
}

result = new ArrayList<>(5);
result.add(backgroundColor);
result.add(backgroundImage);
result.add(backgroundRepeat);
result.add(backgroundAttachment);
result.add(backgroundPosition);

return result;

return Arrays.asList(
backgroundColor, backgroundImage, backgroundRepeat,
backgroundAttachment, backgroundPosition);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import com.openhtmltopdf.css.parser.PropertyValue;
import com.openhtmltopdf.css.parser.Token;
import com.openhtmltopdf.css.parser.property.PrimitivePropertyBuilders.GenericColor;
import com.openhtmltopdf.css.parser.property.PrimitivePropertyBuilders.SingleIdent;
import com.openhtmltopdf.css.sheet.PropertyDeclaration;

public class PrimitiveBackgroundPropertyBuilders {
Expand Down Expand Up @@ -304,7 +303,7 @@ private BitSet getAllowed() {
}
}

public static class BackgroundRepeat extends MultipleBackgroundValueBuilder {
private abstract static class MultipleIdentValue extends MultipleBackgroundValueBuilder {
@Override
protected List<PropertyValue> processValue(CSSName cssName, PropertyValue value) {
checkIdentType(cssName, value);
Expand All @@ -315,12 +314,17 @@ protected List<PropertyValue> processValue(CSSName cssName, PropertyValue value)
return Collections.singletonList(value);
}

protected abstract BitSet getAllowed();
}

public static class BackgroundRepeat extends MultipleIdentValue {
@Override
protected BitSet getAllowed() {
return PrimitivePropertyBuilders.BACKGROUND_REPEATS;
}
}

public static class BackgroundAttachment extends SingleIdent {
public static class BackgroundAttachment extends MultipleIdentValue {
@Override
protected BitSet getAllowed() {
return PrimitivePropertyBuilders.BACKGROUND_ATTACHMENTS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ public class PrimitivePropertyBuilders {

// scroll | fixed | inherit
public static final BitSet BACKGROUND_ATTACHMENTS = setFor(
new IdentValue[] { IdentValue.SCROLL, IdentValue.FIXED });
new IdentValue[] { IdentValue.SCROLL
/*, IdentValue.FIXED - removed broken support for fixed in PR#650 by @danfickle */ });

// left | right | top | bottom | center
public static final BitSet BACKGROUND_POSITIONS = setFor(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -795,14 +795,6 @@ public IdentValue getBackgroundRepeat(PropertyValue value) {
return value.getIdentValue();
}

public IdentValue getBackgroundAttachment() {
return getIdent(CSSName.BACKGROUND_ATTACHMENT);
}

public boolean isFixedBackground() {
return getIdent(CSSName.BACKGROUND_ATTACHMENT) == IdentValue.FIXED;
}

public boolean isInline() {
return isIdent(CSSName.DISPLAY, IdentValue.INLINE) &&
! (isFloated() || isAbsolute() || isFixed() || isRunning());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -869,26 +869,6 @@ private PaintingInfo calcPaintingDimension(LayoutContext c) {
return result;
}

@Deprecated // Not used.
private boolean containsFixedLayer() {
for (Layer child : getChildren()) {
if (child.getMaster().getStyle().isFixed() || child.containsFixedLayer()) {
return true;
}
}
return false;
}

@Deprecated
public boolean containsFixedContent() {
return _fixedBackground || containsFixedLayer();
}

@Deprecated // We not longer support fixed background.
public void setFixedBackground(boolean b) {
_fixedBackground = b;
}

/**
* The resulting list should not be modified.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ private void paintBackground0(
style.getLinearGradient(bgImage.imageGradientOrNone, c, (int) (bgImageContainer.width - border.width()), (int) (bgImageContainer.height - border.height()));

if (backgroundLinearGradient != null) {
Dimension xyoff = calcInitialXYOff(bgImageContainer, border, style, c);
Dimension xyoff = calcInitialXYOff(bgImage, bgImageContainer, border, style, c);

int xoff = xyoff.width;
int yoff = xyoff.height;
Expand Down Expand Up @@ -310,17 +310,14 @@ private void paintBackground0(
}

private Dimension calcInitialXYOff(
BackgroundContainer bgImage,
Rectangle bgImageContainer,
BorderPropertySet border,
CalculatedStyle style,
RenderingContext c) {

Rectangle localBGImageContainer = bgImageContainer;

if (style.isFixedBackground()) {
localBGImageContainer = c.getViewportRectangle();
}

int xoff = localBGImageContainer.x;
int yoff = localBGImageContainer.y;

Expand All @@ -341,13 +338,12 @@ private void drawBgImage(
FSImage backgroundImage,
BackgroundContainer bgImage) {

Dimension xyoff = calcInitialXYOff(bgImageContainer, border, style, c);
Dimension xyoff = calcInitialXYOff(bgImage, bgImageContainer, border, style, c);

int xoff = xyoff.width;
int yoff = xyoff.height;

Rectangle localBGImageContainer = style.isFixedBackground() ?
c.getViewportRectangle() : bgImageContainer;
Rectangle localBGImageContainer = bgImageContainer;

scaleBackgroundImage(c, style, localBGImageContainer, backgroundImage);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -999,10 +999,6 @@ public void layout(LayoutContext c, int contentStart) {
c.pushLayer(this);
}

if (style.isFixedBackground()) {
c.getRootLayer().setFixedBackground(true);
}

calcClearance(c);

if (isRoot() || getStyle().establishesBFC() || isMarginAreaRoot()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
background-image: url(../../demos/images/cc0-cat.png), url(../../demos/images/flyingsaucer.png), none;
background-repeat: no-repeat, repeat-y;
background-position: right;
background-attachment: scroll;
}
</style>
</head>
Expand Down

0 comments on commit 2dbce9b

Please sign in to comment.