1010import org .w3c .css .values .CssIdent ;
1111import org .w3c .css .values .CssTypes ;
1212import 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 */
1722public 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 )
0 commit comments