Skip to content

Commit eef81b2

Browse files
committed
1 parent 71a2e00 commit eef81b2

File tree

2 files changed

+107
-32
lines changed

2 files changed

+107
-32
lines changed

org/w3c/css/properties/css3/CssWhiteSpace.java

Lines changed: 81 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,14 @@
1010
import org.w3c.css.values.CssIdent;
1111
import org.w3c.css.values.CssTypes;
1212
import org.w3c.css.values.CssValue;
13+
import org.w3c.css.values.CssValueList;
14+
15+
import java.util.ArrayList;
16+
17+
import static org.w3c.css.values.CssOperator.SPACE;
1318

1419
/**
15-
* @spec https://www.w3.org/TR/2021/CRD-css-text-3-20210422/#propdef-white-space
20+
* @spec https://www.w3.org/TR/2024/WD-css-text-4-20240219/#propdef-white-space
1621
*/
1722
public class CssWhiteSpace extends org.w3c.css.properties.css.CssWhiteSpace {
1823

@@ -21,7 +26,7 @@ public class CssWhiteSpace extends org.w3c.css.properties.css.CssWhiteSpace {
2126

2227
static {
2328
String[] WHITESPACE = {
24-
"normal", "pre", "nowrap", "pre-wrap", "break-spaces", "pre-line"
29+
"normal", "pre", "pre-wrap", "pre-line"
2530
};
2631
allowed_values = new CssIdent[WHITESPACE.length];
2732
int i = 0;
@@ -30,7 +35,7 @@ public class CssWhiteSpace extends org.w3c.css.properties.css.CssWhiteSpace {
3035
}
3136
}
3237

33-
public static final CssIdent getMatchingIdent(CssIdent ident) {
38+
public static final CssIdent getSingleValueIdent(CssIdent ident) {
3439
for (CssIdent id : allowed_values) {
3540
if (id.equals(ident)) {
3641
return id;
@@ -54,28 +59,87 @@ public CssWhiteSpace() {
5459
*/
5560
public CssWhiteSpace(ApplContext ac, CssExpression expression, boolean check)
5661
throws InvalidParamException {
57-
58-
if (check && expression.getCount() > 1) {
62+
ArrayList<CssValue> values = new ArrayList<CssValue>();
63+
CssValue val;
64+
CssExpression trimexp = null;
65+
CssIdent id;
66+
char op;
67+
boolean got_collapse = false;
68+
boolean got_wrap_mode = false;
69+
// we need 5 for <'white-space-collapse'> || <'text-wrap-mode'> || <'white-space-trim'>
70+
// as <'white-space-trim'> can contain as much as 3 values
71+
if (check && expression.getCount() > 5) {
5972
throw new InvalidParamException("unrecognize", ac);
6073
}
6174

62-
CssValue val = expression.getValue();
6375
setByUser();
6476

65-
if (val.getType() != CssTypes.CSS_IDENT) {
66-
throw new InvalidParamException("value", expression.getValue(),
67-
getPropertyName(), ac);
77+
while (!expression.end()) {
78+
val = expression.getValue();
79+
op = expression.getOperator();
80+
81+
if (val.getType() != CssTypes.CSS_IDENT) {
82+
throw new InvalidParamException("value",
83+
expression.getValue(),
84+
getPropertyName(), ac);
85+
}
86+
// ident, so inherit, or allowed value
87+
if (CssIdent.isCssWide(val.getIdent())) {
88+
if (expression.getCount() > 1) {
89+
throw new InvalidParamException("value",
90+
expression.getValue(),
91+
getPropertyName(), ac);
92+
}
93+
values.add(val);
94+
}
95+
if ((id = getSingleValueIdent(val.getIdent())) != null) {
96+
if (expression.getCount() > 1) {
97+
throw new InvalidParamException("value",
98+
expression.getValue(),
99+
getPropertyName(), ac);
100+
}
101+
values.add(val);
102+
} else if ((id = CssWhiteSpaceCollapse.getAllowedIdent(val.getIdent())) != null) {
103+
if (got_collapse) {
104+
throw new InvalidParamException("value",
105+
expression.getValue(),
106+
getPropertyName(), ac);
107+
}
108+
got_collapse = true;
109+
values.add(val);
110+
} else if ((id = CssTextWrapMode.getAllowedIdent(val.getIdent())) != null) {
111+
if (got_wrap_mode) {
112+
throw new InvalidParamException("value",
113+
expression.getValue(),
114+
getPropertyName(), ac);
115+
}
116+
got_wrap_mode = true;
117+
values.add(val);
118+
} else if ((id = CssTextWrapMode.getAllowedIdent(val.getIdent())) != null) {
119+
// TODO FIXME check if the values have to be contiguous or not
120+
if (trimexp == null) {
121+
trimexp = new CssExpression();
122+
}
123+
trimexp.setOperator(op);
124+
trimexp.addValue(val);
125+
} else {
126+
// nothing we know...
127+
throw new InvalidParamException("value",
128+
expression.getValue(),
129+
getPropertyName(), ac);
130+
}
131+
if (op != SPACE) {
132+
throw new InvalidParamException("operator", op,
133+
getPropertyName(), ac);
134+
}
135+
expression.next();
68136
}
69-
if (CssIdent.isCssWide(val.getIdent())) {
70-
value = val;
71-
} else if (getMatchingIdent(val.getIdent()) != null) {
72-
value = val;
73-
} else {
74-
throw new InvalidParamException("value", expression.getValue(),
75-
getPropertyName(), ac);
137+
// we got everything, check now that the wrap-mode related values are valid
138+
if (trimexp != null) {
139+
values.add(CssWhiteSpaceTrim.checkWhiteSpaceTrim(ac, trimexp, this));
76140
}
77-
expression.next();
78141

142+
value = (values.size() == 1) ? values.get(0) : new CssValueList(values);
79143
}
80144

81145
public CssWhiteSpace(ApplContext ac, CssExpression expression)

org/w3c/css/properties/css3/CssWhiteSpaceTrim.java

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
// Please first read the full copyright statement in file COPYRIGHT.html
66
package org.w3c.css.properties.css3;
77

8+
import org.w3c.css.properties.css.CssProperty;
89
import org.w3c.css.util.ApplContext;
910
import org.w3c.css.util.InvalidParamException;
1011
import org.w3c.css.values.CssExpression;
@@ -58,12 +59,27 @@ public CssWhiteSpaceTrim() {
5859
public CssWhiteSpaceTrim(ApplContext ac, CssExpression expression, boolean check)
5960
throws InvalidParamException {
6061
setByUser();
61-
CssValue val = expression.getValue();
62+
63+
if (check && expression.getCount() > 3) {
64+
throw new InvalidParamException("unrecognize", ac);
65+
}
66+
67+
value = checkWhiteSpaceTrim(ac, expression, this);
68+
}
69+
70+
public CssWhiteSpaceTrim(ApplContext ac, CssExpression expression)
71+
throws InvalidParamException {
72+
this(ac, expression, false);
73+
}
74+
75+
public static CssValue checkWhiteSpaceTrim(ApplContext ac, CssExpression expression, CssProperty caller)
76+
throws InvalidParamException {
77+
ArrayList<CssValue> values = new ArrayList<CssValue>();
78+
CssValue val;
6279
CssIdent id;
6380
char op;
64-
ArrayList<CssValue> values = new ArrayList<>();
6581

66-
if (check && expression.getCount() > 3) {
82+
if (expression.getCount() > 3) {
6783
throw new InvalidParamException("unrecognize", ac);
6884
}
6985

@@ -74,21 +90,21 @@ public CssWhiteSpaceTrim(ApplContext ac, CssExpression expression, boolean check
7490
if (val.getType() != CssTypes.CSS_IDENT) {
7591
throw new InvalidParamException("value",
7692
expression.getValue(),
77-
getPropertyName(), ac);
93+
caller.getPropertyName(), ac);
7894
}
7995
// ident, so inherit, or allowed value
8096
if (CssIdent.isCssWide(val.getIdent())) {
8197
if (expression.getCount() > 1) {
8298
throw new InvalidParamException("value",
8399
expression.getValue(),
84-
getPropertyName(), ac);
100+
caller.getPropertyName(), ac);
85101
}
86102
values.add(val);
87103
} else if (none.equals(val.getIdent())) {
88104
if (expression.getCount() > 1) {
89105
throw new InvalidParamException("value",
90106
expression.getValue(),
91-
getPropertyName(), ac);
107+
caller.getPropertyName(), ac);
92108
}
93109
values.add(val);
94110
} else if ((id = getAllowedIdent(val.getIdent())) != null) {
@@ -97,27 +113,22 @@ public CssWhiteSpaceTrim(ApplContext ac, CssExpression expression, boolean check
97113
if (values.contains(id)) {
98114
throw new InvalidParamException("value",
99115
expression.getValue(),
100-
getPropertyName(), ac);
116+
caller.getPropertyName(), ac);
101117
}
102118
values.add(val);
103119
} else {
104120
throw new InvalidParamException("value",
105121
expression.getValue(),
106-
getPropertyName(), ac);
122+
caller.getPropertyName(), ac);
107123
}
108124
if (op != SPACE) {
109125
throw new InvalidParamException("operator", op,
110-
getPropertyName(), ac);
126+
caller.getPropertyName(), ac);
111127
}
112128
expression.next();
113129
}
114-
value = (values.size() == 1) ? values.get(0) : new CssValueList(values);
115-
130+
return (values.size() == 1) ? values.get(0) : new CssValueList(values);
116131
}
117132

118-
public CssWhiteSpaceTrim(ApplContext ac, CssExpression expression)
119-
throws InvalidParamException {
120-
this(ac, expression, false);
121-
}
122133
}
123134

0 commit comments

Comments
 (0)