Skip to content

Commit c588815

Browse files
committed
Following w3c#257 output of color parsing no longer depends on the css level, but on the original syntax, at least for rgb/rgba
1 parent 55d9fc9 commit c588815

File tree

3 files changed

+29
-22
lines changed

3 files changed

+29
-22
lines changed

org/w3c/css/values/CssColor.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ public void setModernRGBColor(ApplContext ac, CssExpression exp)
211211
color = null;
212212
rgba = new RGBA("rgb");
213213
boolean separator_space = (op == SPACE);
214+
rgba.setModernStyle(separator_space);
214215

215216
if (val == null || (!separator_space && (op != COMMA))) {
216217
throw new InvalidParamException("invalid-color", ac);

org/w3c/css/values/RGB.java

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public class RGB {
1616

1717
private String output = null;
1818
private boolean percent = false;
19-
boolean isCss3 = false;
19+
boolean isModernCss = false;
2020

2121
CssValue vr, vg, vb;
2222

@@ -27,10 +27,10 @@ public static final CssValue filterValue(ApplContext ac, CssValue val)
2727
// might need to extend...
2828
} else {
2929
if (val.getType() == CssTypes.CSS_NUMBER) {
30-
boolean isCss3 = (ac.getCssVersion().compareTo(CssVersion.CSS3) >= 0);
30+
boolean IsModernCss = (ac.getCssVersion().compareTo(CssVersion.CSS3) >= 0);
3131
CssCheckableValue v = val.getCheckableValue();
3232
// in CSS2, numbers can only be integers
33-
if (!isCss3) {
33+
if (!IsModernCss) {
3434
if (!v.isInteger()) {
3535
throw new InvalidParamException("rgb", val, ac);
3636
}
@@ -71,7 +71,6 @@ public static final CssValue filterValue(ApplContext ac, CssValue val)
7171
public final void setRed(ApplContext ac, CssValue val)
7272
throws InvalidParamException {
7373
output = null;
74-
isCss3 = (ac.getCssVersion().compareTo(CssVersion.CSS3) >= 0);
7574
vr = filterValue(ac, val);
7675
}
7776

@@ -130,14 +129,14 @@ public RGB(int r, int g, int b) {
130129
/**
131130
* Create a new RGB with default values
132131
*
133-
* @param isCss3 a boolean toggling the output of RGB
134-
* @param r the red channel, an <EM>int</EM>
135-
* @param g the green channel, an <EM>int</EM>
136-
* @param b the blue channel, an <EM>int</EM>
132+
* @param isModernCss a boolean toggling the output of RGB
133+
* @param r the red channel, an <EM>int</EM>
134+
* @param g the green channel, an <EM>int</EM>
135+
* @param b the blue channel, an <EM>int</EM>
137136
*/
138-
public RGB(boolean isCss3, int r, int g, int b) {
137+
public RGB(boolean isModernCss, int r, int g, int b) {
139138
this(r, g, b);
140-
this.isCss3 = isCss3;
139+
this.isModernCss = isModernCss;
141140
}
142141

143142
public boolean equals(RGB other) {
@@ -151,13 +150,18 @@ protected void setRepresentationString(String s) {
151150
output = s;
152151
}
153152

153+
protected void setModernStyle(boolean isModernCss) {
154+
this.isModernCss = isModernCss;
155+
output = null;
156+
}
157+
154158
/**
155159
* Returns a string representation of the object.
156160
*/
157161
public String toString() {
158162
if (output == null) {
159163
StringBuilder sb = new StringBuilder(functionname).append('(');
160-
if (isCss3) {
164+
if (isModernCss) {
161165
sb.append(vr).append(' ').append(vg).append(' ').append(vb).append(')');
162166
} else {
163167
sb.append(vr).append(", ");

org/w3c/css/values/RGBA.java

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -117,15 +117,15 @@ public RGBA(int r, int g, int b, float a) {
117117
/**
118118
* Create a new RGBA with default values
119119
*
120-
* @param isCss3 a boolean toggling the output of RGB
121-
* @param r the red channel, an <EM>int</EM>
122-
* @param g the green channel, an <EM>int</EM>
123-
* @param b the blue channel, an <EM>int</EM>
124-
* @param a the alpha channel, an <EM>float</EM>
120+
* @param isModernCss a boolean toggling the output of RGB
121+
* @param r the red channel, an <EM>int</EM>
122+
* @param g the green channel, an <EM>int</EM>
123+
* @param b the blue channel, an <EM>int</EM>
124+
* @param a the alpha channel, an <EM>float</EM>
125125
*/
126-
public RGBA(boolean isCss3, int r, int g, int b, float a) {
126+
public RGBA(boolean isModernCss, int r, int g, int b, float a) {
127127
this(r, g, b, a);
128-
this.isCss3 = isCss3;
128+
this.isModernCss = isModernCss;
129129
}
130130

131131
protected void setRepresentationString(String s) {
@@ -138,7 +138,7 @@ protected void setRepresentationString(String s) {
138138
public String toString() {
139139
if (output == null) {
140140
StringBuilder sb = new StringBuilder();
141-
if (isCss3) {
141+
if (isModernCss) {
142142
sb.append(RGB.functionname).append('(');
143143
sb.append(vr).append(' ');
144144
sb.append(vg).append(' ').append(vb);
@@ -149,9 +149,11 @@ public String toString() {
149149
} else {
150150
sb.append(fname).append('(');
151151
sb.append(vr).append(", ");
152-
sb.append(vg).append(", ");
153-
sb.append(vb).append(", ");
154-
sb.append(va).append(')');
152+
sb.append(vg).append(", ").append(vb);
153+
if (va != null) {
154+
sb.append(", ").append(va);
155+
}
156+
sb.append(')');
155157
}
156158
output = sb.toString();
157159
}

0 commit comments

Comments
 (0)