Skip to content

Commit 656eacd

Browse files
committed
fix syntax per latest css-color-4 draft
1 parent e71dcc7 commit 656eacd

4 files changed

Lines changed: 74 additions & 23 deletions

File tree

org/w3c/css/values/CssColor.java

Lines changed: 66 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -809,23 +809,41 @@ public void setHWBColor(CssExpression exp, ApplContext ac)
809809

810810
// A
811811
exp.next();
812-
val = exp.getValue();
813-
if (val != null) {
812+
if (!exp.end()) {
813+
if (op != SPACE) {
814+
throw new InvalidParamException("invalid-color", ac);
815+
}
816+
// now we need an alpha.
817+
val = exp.getValue();
818+
op = exp.getOperator();
819+
820+
if (val.getType() != CssTypes.CSS_SWITCH) {
821+
throw new InvalidParamException("rgb", val, ac);
822+
}
823+
if (op != SPACE) {
824+
throw new InvalidParamException("invalid-color", ac);
825+
}
826+
exp.next();
827+
// now we get the alpha value
828+
val = exp.getValue();
829+
if (val == null) {
830+
throw new InvalidParamException("invalid-color", exp.toStringFromStart(), ac);
831+
}
814832
switch (val.getType()) {
815833
case CssTypes.CSS_NUMBER:
816834
case CssTypes.CSS_PERCENTAGE:
817835
hwb.setAlpha(ac, val);
818836
break;
819837
default:
820838
exp.starts();
821-
throw new InvalidParamException("rgb", val, ac); // FIXME hsl
839+
throw new InvalidParamException("rgb", val, ac); // FIXME hwb
822840
}
841+
exp.next();
823842
}
824843
// extra values?
825-
exp.next();
826-
if (exp.getValue() != null) {
844+
if (!exp.end()) {
827845
exp.starts();
828-
throw new InvalidParamException("rgb", exp.getValue(), ac);
846+
throw new InvalidParamException("rgb", exp.toStringFromStart(), ac);
829847
}
830848
}
831849

@@ -888,10 +906,21 @@ public void setLABColor(CssExpression exp, ApplContext ac)
888906

889907
exp.next();
890908
if (!exp.end()) {
891-
if (op != COMMA) {
892-
throw new InvalidParamException("operator", exp.toStringFromStart(), ac);
909+
if (op != SPACE) {
910+
throw new InvalidParamException("invalid-color", ac);
893911
}
894-
// Alpha
912+
// now we need an alpha.
913+
val = exp.getValue();
914+
op = exp.getOperator();
915+
916+
if (val.getType() != CssTypes.CSS_SWITCH) {
917+
throw new InvalidParamException("rgb", val, ac);
918+
}
919+
if (op != SPACE) {
920+
throw new InvalidParamException("invalid-color", ac);
921+
}
922+
exp.next();
923+
// now we get the alpha value
895924
val = exp.getValue();
896925
if (val == null) {
897926
throw new InvalidParamException("invalid-color", exp.toStringFromStart(), ac);
@@ -950,10 +979,21 @@ public void setGrayColor(CssExpression exp, ApplContext ac)
950979

951980
exp.next();
952981
if (!exp.end()) {
953-
if (op != COMMA) {
954-
throw new InvalidParamException("operator", exp.toStringFromStart(), ac);
982+
if (op != SPACE) {
983+
throw new InvalidParamException("invalid-color", ac);
984+
}
985+
// now we need an alpha.
986+
val = exp.getValue();
987+
op = exp.getOperator();
988+
989+
if (val.getType() != CssTypes.CSS_SWITCH) {
990+
throw new InvalidParamException("rgb", val, ac);
991+
}
992+
if (op != SPACE) {
993+
throw new InvalidParamException("invalid-color", ac);
955994
}
956-
// Alpha
995+
exp.next();
996+
// now we get the alpha value
957997
val = exp.getValue();
958998
if (val == null) {
959999
throw new InvalidParamException("invalid-color", exp.toStringFromStart(), ac);
@@ -1034,10 +1074,21 @@ public void setLCHColor(CssExpression exp, ApplContext ac)
10341074

10351075
exp.next();
10361076
if (!exp.end()) {
1037-
if (op != COMMA) {
1038-
throw new InvalidParamException("operator", exp.toStringFromStart(), ac);
1077+
if (op != SPACE) {
1078+
throw new InvalidParamException("invalid-color", ac);
10391079
}
1040-
// Alpha
1080+
// now we need an alpha.
1081+
val = exp.getValue();
1082+
op = exp.getOperator();
1083+
1084+
if (val.getType() != CssTypes.CSS_SWITCH) {
1085+
throw new InvalidParamException("rgb", val, ac);
1086+
}
1087+
if (op != SPACE) {
1088+
throw new InvalidParamException("invalid-color", ac);
1089+
}
1090+
exp.next();
1091+
// now we get the alpha value
10411092
val = exp.getValue();
10421093
if (val == null) {
10431094
throw new InvalidParamException("invalid-color", exp.toStringFromStart(), ac);

org/w3c/css/values/HWB.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,9 @@ public String toString() {
111111
sb.append(vw).append(", ");
112112
sb.append(vb);
113113
if (!faSet) {
114-
sb.append(")");
114+
sb.append(')');
115115
} else {
116-
sb.append(", ").append(va).append(')');
116+
sb.append(" / ").append(va).append(')');
117117
}
118118
output = sb.toString();
119119
}

org/w3c/css/values/LAB.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public String toString() {
9494
sb = new StringBuilder("gray(");
9595
sb.append(vl);
9696
if (faSet) {
97-
sb.append(", ").append(alpha);
97+
sb.append(" / ").append(alpha);
9898
}
9999
sb.append(')');
100100
} else {
@@ -103,7 +103,7 @@ public String toString() {
103103
sb.append(va).append(' ');
104104
sb.append(vb);
105105
if (faSet) {
106-
sb.append(", ").append(alpha);
106+
sb.append(" / ").append(alpha);
107107
}
108108
sb.append(')');
109109
}

org/w3c/css/values/LCH.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,13 @@ public final void setAlpha(ApplContext ac, CssValue val)
102102
public String toString() {
103103
if (output == null) {
104104
StringBuilder sb = new StringBuilder("lch(");
105-
sb.append(vl).append(" ");
106-
sb.append(vc).append(" ");
105+
sb.append(vl).append(' ');
106+
sb.append(vc).append(' ');
107107
sb.append(vh);
108108
if (faSet) {
109-
sb.append(", ").append(alpha);
109+
sb.append(" / ").append(alpha);
110110
}
111-
sb.append(")");
111+
sb.append(')');
112112
output = sb.toString();
113113
}
114114
return output;

0 commit comments

Comments
 (0)