Skip to content

Commit ef6daa7

Browse files
committed
1 parent 4363bdc commit ef6daa7

4 files changed

Lines changed: 259 additions & 0 deletions

File tree

org/w3c/css/properties/CSS3Properties.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ hanging-punctuation: org.w3c.css.properties.css3.CssHangingPu
228228
wrap-after: org.w3c.css.properties.css3.CssWrapAfter
229229
wrap-before: org.w3c.css.properties.css3.CssWrapBefore
230230
wrap-inside: org.w3c.css.properties.css3.CssWrapInside
231+
white-space-trim: org.w3c.css.properties.css3.CssWhiteSpaceTrim
231232

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

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@
298298
import org.w3c.css.properties.css.CssVoiceRate;
299299
import org.w3c.css.properties.css.CssVoiceStress;
300300
import org.w3c.css.properties.css.CssVoiceVolume;
301+
import org.w3c.css.properties.css.CssWhiteSpaceTrim;
301302
import org.w3c.css.properties.css.CssWillChange;
302303
import org.w3c.css.properties.css.CssWordBreak;
303304
import org.w3c.css.properties.css.CssWordSpaceTransform;
@@ -699,7 +700,17 @@ public class Css3Style extends ATSCStyle {
699700
public CssWrapAfter cssWrapAfter;
700701
public CssWrapBefore cssWrapBefore;
701702
public CssTextWrap cssTextWrap;
703+
public CssWhiteSpaceTrim cssWhiteSpaceTrim;
702704

705+
public CssWhiteSpaceTrim getWhiteSpaceTrim() {
706+
if (cssWhiteSpaceTrim == null) {
707+
cssWhiteSpaceTrim =
708+
(CssWhiteSpaceTrim) style.CascadingOrder(new CssWhiteSpaceTrim(),
709+
style, selector);
710+
}
711+
return cssWhiteSpaceTrim;
712+
}
713+
703714
public CssWrapBefore getWrapBefore() {
704715
if (cssWrapBefore == null) {
705716
cssWrapBefore =
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
//
2+
// Author: Yves Lafon <ylafon@w3.org>
3+
//
4+
// (c) COPYRIGHT World Wide Web Consortium, 2024.
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.util.ApplContext;
9+
import org.w3c.css.util.InvalidParamException;
10+
import org.w3c.css.values.CssExpression;
11+
import org.w3c.css.values.CssIdent;
12+
import org.w3c.css.values.CssTypes;
13+
import org.w3c.css.values.CssValue;
14+
import org.w3c.css.values.CssValueList;
15+
16+
import java.util.ArrayList;
17+
18+
import static org.w3c.css.values.CssOperator.SPACE;
19+
20+
/**
21+
* @spec https://www.w3.org/TR/2024/WD-css-text-4-20240219/#propdef-text-transform
22+
*/
23+
public class CssWhiteSpaceTrim extends org.w3c.css.properties.css.CssTextTransform {
24+
25+
private static CssIdent[] allowed_action_values;
26+
private static CssIdent fullWidth, fullSizeKana;
27+
28+
29+
static {
30+
fullWidth = CssIdent.getIdent("full-width");
31+
fullSizeKana = CssIdent.getIdent("full-size-kana");
32+
33+
String id_values[] = {"capitalize", "uppercase", "lowercase"};
34+
allowed_action_values = new CssIdent[id_values.length];
35+
int i = 0;
36+
for (String s : id_values) {
37+
allowed_action_values[i++] = CssIdent.getIdent(s);
38+
}
39+
}
40+
41+
public static CssIdent getMatchingActionIdent(CssIdent ident) {
42+
for (CssIdent id : allowed_action_values) {
43+
if (id.equals(ident)) {
44+
return id;
45+
}
46+
}
47+
return null;
48+
}
49+
50+
/**
51+
* Create a new CssTextTransform
52+
*/
53+
public CssWhiteSpaceTrim() {
54+
value = initial;
55+
}
56+
57+
/**
58+
* Creates a new CssTextTransform
59+
*
60+
* @param expression The expression for this property
61+
* @throws InvalidParamException
62+
* Expressions are incorrect
63+
*/
64+
public CssWhiteSpaceTrim(ApplContext ac, CssExpression expression, boolean check)
65+
throws InvalidParamException {
66+
setByUser();
67+
CssValue val = expression.getValue();
68+
char op;
69+
ArrayList<CssValue> values = new ArrayList<>();
70+
boolean got_action = false;
71+
boolean got_full_width = false;
72+
boolean got_full_size_kana = false;
73+
74+
if (check && expression.getCount() > 3) {
75+
throw new InvalidParamException("unrecognize", ac);
76+
}
77+
78+
while (!expression.end()) {
79+
val = expression.getValue();
80+
op = expression.getOperator();
81+
82+
if (val.getType() != CssTypes.CSS_IDENT) {
83+
throw new InvalidParamException("value",
84+
expression.getValue(),
85+
getPropertyName(), ac);
86+
}
87+
// ident, so inherit, or allowed value
88+
if (CssIdent.isCssWide(val.getIdent())) {
89+
if (expression.getCount() > 1) {
90+
throw new InvalidParamException("value",
91+
expression.getValue(),
92+
getPropertyName(), ac);
93+
}
94+
values.add(val);
95+
} else if (none.equals(val.getIdent())) {
96+
if (expression.getCount() > 1) {
97+
throw new InvalidParamException("value",
98+
expression.getValue(),
99+
getPropertyName(), ac);
100+
}
101+
values.add(val);
102+
} else if (fullWidth.equals(val.getIdent()) && !got_full_width) {
103+
got_full_width = true;
104+
values.add(val);
105+
} else if (fullSizeKana.equals(val.getIdent()) && !got_full_size_kana) {
106+
got_full_size_kana = true;
107+
values.add(val);
108+
} else if (!got_action) {
109+
if (getMatchingActionIdent(val.getIdent()) == null) {
110+
throw new InvalidParamException("value",
111+
expression.getValue(),
112+
getPropertyName(), ac);
113+
}
114+
got_action = true;
115+
values.add(val);
116+
} else {
117+
throw new InvalidParamException("value",
118+
expression.getValue(),
119+
getPropertyName(), ac);
120+
}
121+
if (op != SPACE) {
122+
throw new InvalidParamException("operator", op,
123+
getPropertyName(), ac);
124+
}
125+
expression.next();
126+
}
127+
value = (values.size() == 1) ? values.get(0) : new CssValueList(values);
128+
}
129+
130+
public CssWhiteSpaceTrim(ApplContext ac, CssExpression expression)
131+
throws InvalidParamException {
132+
this(ac, expression, false);
133+
}
134+
}
135+

0 commit comments

Comments
 (0)