Skip to content

Commit a23a1b4

Browse files
committed
allow reuse of filtering functions
1 parent 9caf421 commit a23a1b4

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

org/w3c/css/values/RGB.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@ public class RGB {
1818

1919
CssValue vr, vg, vb;
2020

21-
public final CssValue filterValue(ApplContext ac, CssValue val)
21+
public static final CssValue filterValue(ApplContext ac, CssValue val)
2222
throws InvalidParamException {
23-
output = null;
2423
if (val.getRawType() == CssTypes.CSS_CALC) {
2524
// TODO add warning about uncheckability
2625
// might need to extend...
@@ -62,17 +61,20 @@ public final CssValue filterValue(ApplContext ac, CssValue val)
6261

6362
public final void setRed(ApplContext ac, CssValue val)
6463
throws InvalidParamException {
64+
output = null;
6565
vr = filterValue(ac, val);
6666
}
6767

6868
public final void setGreen(ApplContext ac, CssValue val)
6969
throws InvalidParamException {
70+
output = null;
7071
vg = filterValue(ac, val);
7172
}
7273

7374

7475
public final void setBlue(ApplContext ac, CssValue val)
7576
throws InvalidParamException {
77+
output = null;
7678
vb = filterValue(ac, val);
7779
}
7880

org/w3c/css/values/RGBA.java

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
import org.w3c.css.util.ApplContext;
1717
import org.w3c.css.util.InvalidParamException;
1818

19+
import java.math.BigDecimal;
20+
1921
public class RGBA extends RGB {
2022
static final String functionname = "rgba";
2123

@@ -24,10 +26,8 @@ public class RGBA extends RGB {
2426

2527
CssValue va;
2628

27-
public final void setAlpha(ApplContext ac, CssValue val)
29+
public static final CssValue filterAlpha(ApplContext ac, CssValue val)
2830
throws InvalidParamException {
29-
CssValue nv = val;
30-
output = null;
3131
if (val.getRawType() == CssTypes.CSS_CALC) {
3232
// TODO add warning about uncheckability
3333
// might need to extend...
@@ -38,15 +38,15 @@ public final void setAlpha(ApplContext ac, CssValue val)
3838
ac.getFrame().addWarning("out-of-range", val.toString());
3939
CssNumber nb = new CssNumber();
4040
nb.setIntValue(0);
41-
nv = nb;
41+
return nb;
4242
}
4343
if (val.getRawType() == CssTypes.CSS_NUMBER) {
44-
float p = ((CssNumber) val).getValue();
45-
if (p > 1.) {
44+
BigDecimal pp = ((CssNumber) val).value;
45+
if (pp.compareTo(BigDecimal.ONE) >= 0) {
4646
ac.getFrame().addWarning("out-of-range", val.toString());
4747
CssNumber nb = new CssNumber();
4848
nb.setIntValue(1);
49-
nv = nb;
49+
return nb;
5050
}
5151
}
5252
} else if (val.getType() == CssTypes.CSS_PERCENTAGE) {
@@ -56,20 +56,25 @@ public final void setAlpha(ApplContext ac, CssValue val)
5656
ac.getFrame().addWarning("out-of-range", val.toString());
5757
CssNumber nb = new CssNumber();
5858
nb.setIntValue(0);
59-
nv = nb;
59+
return nb;
6060
}
6161
if (val.getRawType() == CssTypes.CSS_PERCENTAGE) {
6262
float p = ((CssPercentage) val).floatValue();
6363
if (p > 100.) {
6464
ac.getFrame().addWarning("out-of-range", val.toString());
65-
nv = new CssPercentage(100);
65+
return new CssPercentage(100);
6666
}
6767
}
6868
}
6969
}
70-
va = nv;
70+
return val;
7171
}
7272

73+
public final void setAlpha(ApplContext ac, CssValue val)
74+
throws InvalidParamException {
75+
output = null;
76+
va = filterAlpha(ac, val);
77+
}
7378

7479
public boolean equals(RGBA other) {
7580
if (other != null) {

0 commit comments

Comments
 (0)