Skip to content

Commit 3975ea8

Browse files
committed
1 parent ba81909 commit 3975ea8

File tree

1 file changed

+97
-21
lines changed

1 file changed

+97
-21
lines changed

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

Lines changed: 97 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,39 @@
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;
1112
import org.w3c.css.values.CssIdent;
1213
import org.w3c.css.values.CssTypes;
1314
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;
1420

1521
/**
1622
* @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
1725
*/
1826
public class CssAlignItems extends org.w3c.css.properties.css.CssAlignItems {
1927

20-
public static final CssIdent[] allowed_values;
28+
public static final CssIdent[] single_align_items_values;
2129

2230
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];
2533
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);
2836
}
2937
}
3038

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) {
3341
if (id.equals(ident)) {
3442
return id;
3543
}
@@ -53,12 +61,23 @@ public CssAlignItems() {
5361
*/
5462
public CssAlignItems(ApplContext ac, CssExpression expression, boolean check)
5563
throws InvalidParamException {
56-
if (check && expression.getCount() > 1) {
64+
if (check && expression.getCount() > 2) {
5765
throw new InvalidParamException("unrecognize", ac);
5866
}
5967
setByUser();
6068

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<>();
6281
char op;
6382

6483
val = expression.getValue();
@@ -67,22 +86,79 @@ public CssAlignItems(ApplContext ac, CssExpression expression, boolean check)
6786
if (val.getType() == CssTypes.CSS_IDENT) {
6887
CssIdent ident = (CssIdent) val;
6988
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);
73149
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);
77152
}
153+
values.add(value);
154+
expression.next();
155+
return new CssValueList(values);
78156
}
79-
} else {
80-
throw new InvalidParamException("value",
81-
val.toString(),
82-
getPropertyName(), ac);
83-
}
84-
expression.next();
85157

158+
}
159+
throw new InvalidParamException("value",
160+
val.toString(),
161+
caller.getPropertyName(), ac);
86162
}
87163

88164
public CssAlignItems(ApplContext ac, CssExpression expression)

0 commit comments

Comments
 (0)