5
5
// Please first read the full copyright statement in file COPYRIGHT.html
6
6
package org .w3c .css .properties .css3 ;
7
7
8
+ import org .w3c .css .properties .css .CssProperty ;
8
9
import org .w3c .css .util .ApplContext ;
9
10
import org .w3c .css .util .InvalidParamException ;
10
11
import org .w3c .css .values .CssExpression ;
11
12
import org .w3c .css .values .CssIdent ;
12
13
import org .w3c .css .values .CssTypes ;
13
14
import org .w3c .css .values .CssValue ;
15
+ import org .w3c .css .values .CssValueList ;
16
+
17
+ import java .util .ArrayList ;
18
+
19
+ import static org .w3c .css .values .CssOperator .SPACE ;
14
20
15
21
/**
16
22
* @spec https://www.w3.org/TR/2016/CR-css-flexbox-1-20160526/#propdef-align-items
23
+ * replaced by
24
+ * https://www.w3.org/TR/2018/WD-css-align-3-20180423/#propdef-align-items
17
25
*/
18
26
public class CssAlignItems extends org .w3c .css .properties .css .CssAlignItems {
19
27
20
- public static final CssIdent [] allowed_values ;
28
+ public static final CssIdent [] single_align_items_values ;
21
29
22
30
static {
23
- String [] _allowed_values = {"flex-start" , "flex-end" , "center" , "baseline " , "stretch" };
24
- allowed_values = new CssIdent [_allowed_values .length ];
31
+ String [] _single_values = {"normal " , "stretch" };
32
+ single_align_items_values = new CssIdent [_single_values .length ];
25
33
int i = 0 ;
26
- for (String s : _allowed_values ) {
27
- allowed_values [i ++] = CssIdent .getIdent (s );
34
+ for (String s : _single_values ) {
35
+ single_align_items_values [i ++] = CssIdent .getIdent (s );
28
36
}
29
37
}
30
38
31
- public static CssIdent getAllowedIdent (CssIdent ident ) {
32
- for (CssIdent id : allowed_values ) {
39
+ public static CssIdent getSingleAlignItemsValue (CssIdent ident ) {
40
+ for (CssIdent id : single_align_items_values ) {
33
41
if (id .equals (ident )) {
34
42
return id ;
35
43
}
@@ -53,12 +61,23 @@ public CssAlignItems() {
53
61
*/
54
62
public CssAlignItems (ApplContext ac , CssExpression expression , boolean check )
55
63
throws InvalidParamException {
56
- if (check && expression .getCount () > 1 ) {
64
+ if (check && expression .getCount () > 2 ) {
57
65
throw new InvalidParamException ("unrecognize" , ac );
58
66
}
59
67
setByUser ();
60
68
61
- CssValue val ;
69
+ value = parseAlignItems (ac , expression , this );
70
+ if (!expression .end ()) {
71
+ throw new InvalidParamException ("unrecognize" , ac );
72
+ }
73
+
74
+ }
75
+
76
+ public static CssValue parseAlignItems (ApplContext ac , CssExpression expression ,
77
+ CssProperty caller )
78
+ throws InvalidParamException {
79
+ CssValue val , value ;
80
+ ArrayList <CssValue > values = new ArrayList <>();
62
81
char op ;
63
82
64
83
val = expression .getValue ();
@@ -67,22 +86,79 @@ public CssAlignItems(ApplContext ac, CssExpression expression, boolean check)
67
86
if (val .getType () == CssTypes .CSS_IDENT ) {
68
87
CssIdent ident = (CssIdent ) val ;
69
88
if (inherit .equals (ident )) {
70
- value = inherit ;
71
- } else {
72
- value = getAllowedIdent (ident );
89
+ if (expression .getCount () > 1 ) {
90
+ throw new InvalidParamException ("value" , val .toString (),
91
+ caller .getPropertyName (), ac );
92
+ }
93
+ expression .next ();
94
+ return inherit ;
95
+ }
96
+ value = getSingleAlignItemsValue (ident );
97
+ if (value != null ) {
98
+ expression .next ();
99
+ return value ;
100
+ }
101
+ // now try the two-values position, starting first with only one.
102
+ if (CssAlignContent .baseline .equals (ident )) {
103
+ expression .next ();
104
+ return CssAlignContent .baseline ;
105
+ }
106
+ value = CssAlignSelf .getSelfPosition (ident );
107
+ if (value != null ) {
108
+ expression .next ();
109
+ return value ;
110
+ }
111
+ // ok, at that point we need two values.
112
+ value = CssAlignContent .getBaselineQualifier (ident );
113
+ if (value != null ) {
114
+ values .add (value );
115
+ if (op != SPACE ) {
116
+ throw new InvalidParamException ("operator" ,
117
+ ((new Character (op )).toString ()), ac );
118
+ }
119
+ expression .next ();
120
+ if (expression .end ()) {
121
+ throw new InvalidParamException ("unrecognize" , ac );
122
+ }
123
+ val = expression .getValue ();
124
+ if (val .getType () != CssTypes .CSS_IDENT || !CssAlignContent .baseline .equals (val )) {
125
+ throw new InvalidParamException ("value" , val .toString (),
126
+ caller .getPropertyName (), ac );
127
+ }
128
+ values .add (CssAlignContent .baseline );
129
+ expression .next ();
130
+ return new CssValueList (values );
131
+ }
132
+ value = CssAlignContent .getOverflowPosition (ident );
133
+ if (value != null ) {
134
+ values .add (value );
135
+ if (op != SPACE ) {
136
+ throw new InvalidParamException ("operator" ,
137
+ ((new Character (op )).toString ()), ac );
138
+ }
139
+ expression .next ();
140
+ if (expression .end ()) {
141
+ throw new InvalidParamException ("unrecognize" , ac );
142
+ }
143
+ val = expression .getValue ();
144
+ if (val .getType () != CssTypes .CSS_IDENT ) {
145
+ throw new InvalidParamException ("value" , val .toString (),
146
+ caller .getPropertyName (), ac );
147
+ }
148
+ value = CssAlignSelf .getSelfPosition ((CssIdent ) val );
73
149
if (value == null ) {
74
- throw new InvalidParamException ("value" ,
75
- val .toString (),
76
- getPropertyName (), ac );
150
+ throw new InvalidParamException ("value" , val .toString (),
151
+ caller .getPropertyName (), ac );
77
152
}
153
+ values .add (value );
154
+ expression .next ();
155
+ return new CssValueList (values );
78
156
}
79
- } else {
80
- throw new InvalidParamException ("value" ,
81
- val .toString (),
82
- getPropertyName (), ac );
83
- }
84
- expression .next ();
85
157
158
+ }
159
+ throw new InvalidParamException ("value" ,
160
+ val .toString (),
161
+ caller .getPropertyName (), ac );
86
162
}
87
163
88
164
public CssAlignItems (ApplContext ac , CssExpression expression )
0 commit comments