Skip to content

Commit 3a24bcf

Browse files
committed
marked as deprecated changed the parsing to allow some keywords + optional 'flip' on angle.
1 parent 5c113e5 commit 3a24bcf

File tree

1 file changed

+70
-4
lines changed

1 file changed

+70
-4
lines changed

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

Lines changed: 70 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,50 @@
1-
// $Id$
1+
//
22
// Author: Yves Lafon <ylafon@w3.org>
33
//
4-
// (c) COPYRIGHT MIT, ERCIM and Keio University, 2012.
4+
// (c) COPYRIGHT MIT, ERCIM, Keio University, Beihang, 2012-2019
55
// Please first read the full copyright statement in file COPYRIGHT.html
66
package org.w3c.css.properties.css3;
77

88
import org.w3c.css.util.ApplContext;
99
import org.w3c.css.util.InvalidParamException;
10+
import org.w3c.css.values.CssAngle;
1011
import org.w3c.css.values.CssExpression;
12+
import org.w3c.css.values.CssIdent;
13+
import org.w3c.css.values.CssOperator;
1114
import org.w3c.css.values.CssTypes;
1215
import org.w3c.css.values.CssValue;
16+
import org.w3c.css.values.CssValueList;
17+
18+
import java.util.ArrayList;
1319

1420
/**
15-
* @spec http://www.w3.org/TR/2012/CR-css3-images-20120417/#image-orientation
21+
* @spec https://www.w3.org/TR/2019/CR-css-images-3-20191010/#propdef-image-orientation
22+
* @deprecated
1623
*/
1724
public class CssImageOrientation extends org.w3c.css.properties.css.CssImageOrientation {
1825

26+
public static final CssIdent[] allowed_values;
27+
public static final CssIdent flip;
28+
29+
static {
30+
String[] _allowed_values = {"from-image", "none", "flip"};
31+
allowed_values = new CssIdent[_allowed_values.length];
32+
int i = 0;
33+
for (String s : _allowed_values) {
34+
allowed_values[i++] = CssIdent.getIdent(s);
35+
}
36+
flip = CssIdent.getIdent("flip");
37+
}
38+
39+
public static CssIdent getAllowedIdent(CssIdent ident) {
40+
for (CssIdent id : allowed_values) {
41+
if (id.equals(ident)) {
42+
return id;
43+
}
44+
}
45+
return null;
46+
}
47+
1948
/**
2049
* Create a new CssImageOrientation
2150
*/
@@ -32,7 +61,7 @@ public CssImageOrientation() {
3261
*/
3362
public CssImageOrientation(ApplContext ac, CssExpression expression, boolean check)
3463
throws InvalidParamException {
35-
if (check && expression.getCount() > 1) {
64+
if (check && expression.getCount() > 2) {
3665
throw new InvalidParamException("unrecognize", ac);
3766
}
3867
setByUser();
@@ -43,17 +72,54 @@ public CssImageOrientation(ApplContext ac, CssExpression expression, boolean che
4372
val = expression.getValue();
4473
op = expression.getOperator();
4574

75+
ac.getFrame().addWarning("deprecatedproperty", getPropertyName());
76+
4677
switch (val.getType()) {
4778
case CssTypes.CSS_NUMBER:
4879
val.getCheckableValue().checkEqualsZero(ac, this);
4980
case CssTypes.CSS_ANGLE:
5081
value = val;
82+
// check for optional 'flip'
83+
if (op == CssOperator.SPACE && expression.getRemainingCount() > 1) {
84+
expression.next();
85+
val = expression.getValue();
86+
op = expression.getOperator();
87+
if (val.getType() != CssTypes.CSS_IDENT) {
88+
throw new InvalidParamException("value",
89+
val.toString(),
90+
getPropertyName(), ac);
91+
}
92+
if (!flip.equals((CssIdent) val)) {
93+
throw new InvalidParamException("value",
94+
val.toString(),
95+
getPropertyName(), ac);
96+
}
97+
ArrayList<CssValue> v = new ArrayList<>(2);
98+
v.add(value);
99+
v.add(flip);
100+
value = new CssValueList(v);
101+
}
51102
break;
52103
case CssTypes.CSS_IDENT:
104+
if (check && expression.getCount() > 1) {
105+
throw new InvalidParamException("unrecognize", ac);
106+
}
53107
if (inherit.equals(val)) {
54108
value = inherit;
55109
break;
56110
}
111+
value = getAllowedIdent((CssIdent) val);
112+
if (value != null) {
113+
// single 'flip' will be pretty-printed as 0deg flip
114+
if (flip == value) {
115+
ArrayList<CssValue> v = new ArrayList<>(2);
116+
v.add(new CssAngle());
117+
v.add(flip);
118+
value = new CssValueList(v);
119+
}
120+
break;
121+
}
122+
// null value, bail out
57123
default:
58124
throw new InvalidParamException("value",
59125
val.toString(),

0 commit comments

Comments
 (0)