10
10
import org .w3c .css .values .CssIdent ;
11
11
import org .w3c .css .values .CssTypes ;
12
12
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 ;
13
18
14
19
/**
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
16
21
*/
17
22
public class CssWhiteSpace extends org .w3c .css .properties .css .CssWhiteSpace {
18
23
@@ -21,7 +26,7 @@ public class CssWhiteSpace extends org.w3c.css.properties.css.CssWhiteSpace {
21
26
22
27
static {
23
28
String [] WHITESPACE = {
24
- "normal" , "pre" , "nowrap" , " pre-wrap" , "break-spaces " , "pre-line"
29
+ "normal" , "pre" , "pre-wrap" , "pre-line"
25
30
};
26
31
allowed_values = new CssIdent [WHITESPACE .length ];
27
32
int i = 0 ;
@@ -30,7 +35,7 @@ public class CssWhiteSpace extends org.w3c.css.properties.css.CssWhiteSpace {
30
35
}
31
36
}
32
37
33
- public static final CssIdent getMatchingIdent (CssIdent ident ) {
38
+ public static final CssIdent getSingleValueIdent (CssIdent ident ) {
34
39
for (CssIdent id : allowed_values ) {
35
40
if (id .equals (ident )) {
36
41
return id ;
@@ -54,28 +59,87 @@ public CssWhiteSpace() {
54
59
*/
55
60
public CssWhiteSpace (ApplContext ac , CssExpression expression , boolean check )
56
61
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 ) {
59
72
throw new InvalidParamException ("unrecognize" , ac );
60
73
}
61
74
62
- CssValue val = expression .getValue ();
63
75
setByUser ();
64
76
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 ();
68
136
}
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 ));
76
140
}
77
- expression .next ();
78
141
142
+ value = (values .size () == 1 ) ? values .get (0 ) : new CssValueList (values );
79
143
}
80
144
81
145
public CssWhiteSpace (ApplContext ac , CssExpression expression )
0 commit comments