Skip to content

Commit df80902

Browse files
committed
1 parent e9d2b9b commit df80902

File tree

5 files changed

+297
-0
lines changed

5 files changed

+297
-0
lines changed

org/w3c/css/properties/CSS3Properties.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ grid-template-rows: org.w3c.css.properties.css3.CssGridTempl
108108
# align
109109
row-gap: org.w3c.css.properties.css3.CssRowGap
110110
gap: org.w3c.css.properties.css3.CssGap
111+
justify-self: org.w3c.css.properties.css3.CssJustifySelf
111112

112113
# text properties
113114

org/w3c/css/properties/CSS3SVGProperties.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ grid-template-rows: org.w3c.css.properties.css3.CssGridTempl
165165
# align
166166
row-gap: org.w3c.css.properties.css3.CssRowGap
167167
gap: org.w3c.css.properties.css3.CssGap
168+
justify-self: org.w3c.css.properties.css3.CssJustifySelf
168169

169170
# text properties
170171

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
//
2+
// Author: Yves Lafon <ylafon@w3.org>
3+
//
4+
// (c) COPYRIGHT MIT, ERCIM, Keio, Beihang, 2018.
5+
// Please first read the full copyright statement in file COPYRIGHT.html
6+
package org.w3c.css.properties.css;
7+
8+
import org.w3c.css.parser.CssStyle;
9+
import org.w3c.css.properties.css3.Css3Style;
10+
import org.w3c.css.util.ApplContext;
11+
import org.w3c.css.util.InvalidParamException;
12+
import org.w3c.css.values.CssExpression;
13+
import org.w3c.css.values.CssValue;
14+
15+
/**
16+
* @since CSS3
17+
*/
18+
public class CssJustifySelf extends CssProperty {
19+
20+
public CssValue value;
21+
22+
/**
23+
* Create a new CssJustifySelf
24+
*/
25+
public CssJustifySelf() {
26+
}
27+
28+
/**
29+
* Creates a new CssJustifySelf
30+
*
31+
* @param expression The expression for this property
32+
* @throws org.w3c.css.util.InvalidParamException
33+
* Expressions are incorrect
34+
*/
35+
public CssJustifySelf(ApplContext ac, CssExpression expression, boolean check)
36+
throws InvalidParamException {
37+
throw new InvalidParamException("value",
38+
expression.getValue().toString(),
39+
getPropertyName(), ac);
40+
}
41+
42+
public CssJustifySelf(ApplContext ac, CssExpression expression)
43+
throws InvalidParamException {
44+
this(ac, expression, false);
45+
}
46+
47+
/**
48+
* Returns the value of this property
49+
*/
50+
public Object get() {
51+
return value;
52+
}
53+
54+
55+
/**
56+
* Returns the name of this property
57+
*/
58+
public final String getPropertyName() {
59+
return "justify-self";
60+
}
61+
62+
/**
63+
* Returns true if this property is "softly" inherited
64+
* e.g. his value is equals to inherit
65+
*/
66+
public boolean isSoftlyInherited() {
67+
return value.equals(inherit);
68+
}
69+
70+
/**
71+
* Returns a string representation of the object.
72+
*/
73+
public String toString() {
74+
return value.toString();
75+
}
76+
77+
/**
78+
* Add this property to the CssStyle.
79+
*
80+
* @param style The CssStyle
81+
*/
82+
public void addToStyle(ApplContext ac, CssStyle style) {
83+
Css3Style s = (Css3Style) style;
84+
if (s.cssJustifySelf != null) {
85+
style.addRedefinitionWarning(ac, this);
86+
}
87+
s.cssJustifySelf = this;
88+
}
89+
90+
91+
/**
92+
* Compares two properties for equality.
93+
*
94+
* @param property The other property.
95+
*/
96+
public boolean equals(CssProperty property) {
97+
return (property instanceof CssJustifySelf &&
98+
value.equals(((CssJustifySelf) property).value));
99+
}
100+
101+
102+
/**
103+
* Get this property in the style.
104+
*
105+
* @param style The style where the property is
106+
* @param resolve if true, resolve the style to find this property
107+
*/
108+
public CssProperty getPropertyInStyle(CssStyle style, boolean resolve) {
109+
if (resolve) {
110+
return ((Css3Style) style).getJustifySelf();
111+
} else {
112+
return ((Css3Style) style).cssJustifySelf;
113+
}
114+
}
115+
}
116+

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@
109109
import org.w3c.css.properties.css.CssInitialLetterWrap;
110110
import org.w3c.css.properties.css.CssIsolation;
111111
import org.w3c.css.properties.css.CssJustifyContent;
112+
import org.w3c.css.properties.css.CssJustifySelf;
112113
import org.w3c.css.properties.css.CssLightingColor;
113114
import org.w3c.css.properties.css.CssLineBreak;
114115
import org.w3c.css.properties.css.CssMarkerSide;
@@ -468,8 +469,18 @@ public class Css3Style extends ATSCStyle {
468469

469470
public CssRowGap cssRowGap;
470471
public CssGap cssGap;
472+
public CssJustifySelf cssJustifySelf;
471473

472474

475+
public CssJustifySelf getJustifySelf() {
476+
if (cssJustifySelf == null) {
477+
cssJustifySelf =
478+
(CssJustifySelf) style.CascadingOrder(new CssJustifySelf(),
479+
style, selector);
480+
}
481+
return cssJustifySelf;
482+
}
483+
473484
public CssGap getGap() {
474485
if (cssGap == null) {
475486
cssGap =
Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
//
2+
// Author: Yves Lafon <ylafon@w3.org>
3+
//
4+
// (c) COPYRIGHT MIT, ERCIM, Keio, Beihang, 2016.
5+
// Please first read the full copyright statement in file COPYRIGHT.html
6+
package org.w3c.css.properties.css3;
7+
8+
import org.w3c.css.properties.css.CssProperty;
9+
import org.w3c.css.util.ApplContext;
10+
import org.w3c.css.util.InvalidParamException;
11+
import org.w3c.css.values.CssExpression;
12+
import org.w3c.css.values.CssIdent;
13+
import org.w3c.css.values.CssTypes;
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;
20+
21+
/**
22+
* @spec https://www.w3.org/TR/2018/WD-css-align-3-20180423/#justify-self-property
23+
*/
24+
public class CssJustifySelf extends org.w3c.css.properties.css.CssJustifySelf {
25+
26+
public static final CssIdent[] self_position_extras;
27+
28+
static {
29+
String[] _self_position_extra_values = {"left", "right"};
30+
self_position_extras = new CssIdent[_self_position_extra_values.length];
31+
int i = 0;
32+
for (String s : _self_position_extra_values) {
33+
self_position_extras[i++] = CssIdent.getIdent(s);
34+
}
35+
}
36+
37+
public static CssIdent getSelfPositionAddExtras(CssIdent ident) {
38+
for (CssIdent id : self_position_extras) {
39+
if (id.equals(ident)) {
40+
return id;
41+
}
42+
}
43+
return CssAlignSelf.getSelfPosition(ident);
44+
}
45+
46+
/**
47+
* Create a new CssAlignSelf
48+
*/
49+
public CssJustifySelf() {
50+
value = initial;
51+
}
52+
53+
/**
54+
* Creates a new CssAlignSelf
55+
*
56+
* @param expression The expression for this property
57+
* @throws org.w3c.css.util.InvalidParamException
58+
* Expressions are incorrect
59+
*/
60+
public CssJustifySelf(ApplContext ac, CssExpression expression, boolean check)
61+
throws InvalidParamException {
62+
if (check && expression.getCount() > 2) {
63+
throw new InvalidParamException("unrecognize", ac);
64+
}
65+
setByUser();
66+
67+
value = parseJustifyContent(ac, expression, this);
68+
if (!expression.end()) {
69+
throw new InvalidParamException("unrecognize", ac);
70+
}
71+
}
72+
73+
public static CssValue parseJustifyContent(ApplContext ac, CssExpression expression,
74+
CssProperty caller)
75+
throws InvalidParamException {
76+
CssValue val, value;
77+
ArrayList<CssValue> values = new ArrayList<>();
78+
char op;
79+
80+
val = expression.getValue();
81+
op = expression.getOperator();
82+
83+
if (val.getType() == CssTypes.CSS_IDENT) {
84+
CssIdent ident = (CssIdent) val;
85+
if (inherit.equals(ident)) {
86+
if (expression.getCount() > 1) {
87+
throw new InvalidParamException("value", val.toString(),
88+
caller.getPropertyName(), ac);
89+
}
90+
expression.next();
91+
return inherit;
92+
}
93+
value = CssAlignSelf.getSingleAlignSelfValue(ident);
94+
if (value != null) {
95+
expression.next();
96+
return value;
97+
}
98+
// now try the two-values position, starting first with only one.
99+
if (CssAlignContent.baseline.equals(ident)) {
100+
expression.next();
101+
return CssAlignContent.baseline;
102+
}
103+
value = getSelfPositionAddExtras(ident);
104+
if (value != null) {
105+
expression.next();
106+
return value;
107+
}
108+
// ok, at that point we need two values.
109+
value = CssAlignContent.getBaselineQualifier(ident);
110+
if (value != null) {
111+
values.add(value);
112+
if (op != SPACE) {
113+
throw new InvalidParamException("operator",
114+
((new Character(op)).toString()), ac);
115+
}
116+
expression.next();
117+
if (expression.end()) {
118+
throw new InvalidParamException("unrecognize", ac);
119+
}
120+
val = expression.getValue();
121+
if (val.getType() != CssTypes.CSS_IDENT || !CssAlignContent.baseline.equals(val)) {
122+
throw new InvalidParamException("value", val.toString(),
123+
caller.getPropertyName(), ac);
124+
}
125+
values.add(CssAlignContent.baseline);
126+
expression.next();
127+
return new CssValueList(values);
128+
}
129+
value = CssAlignContent.getOverflowPosition(ident);
130+
if (value != null) {
131+
values.add(value);
132+
if (op != SPACE) {
133+
throw new InvalidParamException("operator",
134+
((new Character(op)).toString()), ac);
135+
}
136+
expression.next();
137+
if (expression.end()) {
138+
throw new InvalidParamException("unrecognize", ac);
139+
}
140+
val = expression.getValue();
141+
if (val.getType() != CssTypes.CSS_IDENT) {
142+
throw new InvalidParamException("value", val.toString(),
143+
caller.getPropertyName(), ac);
144+
}
145+
value = getSelfPositionAddExtras((CssIdent) val);
146+
if (value == null) {
147+
throw new InvalidParamException("value", val.toString(),
148+
caller.getPropertyName(), ac);
149+
}
150+
values.add(value);
151+
expression.next();
152+
return new CssValueList(values);
153+
}
154+
155+
}
156+
throw new InvalidParamException("value",
157+
val.toString(),
158+
caller.getPropertyName(), ac);
159+
}
160+
161+
162+
public CssJustifySelf(ApplContext ac, CssExpression expression)
163+
throws InvalidParamException {
164+
this(ac, expression, false);
165+
}
166+
167+
}
168+

0 commit comments

Comments
 (0)