Skip to content

Commit 71a2e00

Browse files
committed
1 parent bc0b013 commit 71a2e00

File tree

4 files changed

+211
-0
lines changed

4 files changed

+211
-0
lines changed

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-collapse: org.w3c.css.properties.css3.CssWhiteSpaceCollapse
231232
white-space-trim: org.w3c.css.properties.css3.CssWhiteSpaceTrim
232233

233234
text-combine-upright: org.w3c.css.properties.css3.CssTextCombineUpright
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 World Wide Web Consortium, 2024.
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 CssWhiteSpaceCollapse extends CssProperty {
18+
19+
/**
20+
* Create a new CssWhiteSpaceCollapse
21+
*/
22+
public CssWhiteSpaceCollapse() {
23+
}
24+
25+
/**
26+
* Creates a new CssWhiteSpaceCollapse
27+
*
28+
* @param expression The expression for this property
29+
* @throws InvalidParamException Expressions are incorrect
30+
*/
31+
public CssWhiteSpaceCollapse(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 CssWhiteSpaceCollapse(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-collapse";
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.cssWhiteSpaceCollapse != null) {
81+
style.addRedefinitionWarning(ac, this);
82+
}
83+
s.cssWhiteSpaceCollapse = 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 CssWhiteSpaceCollapse &&
94+
value.equals(((CssWhiteSpaceCollapse) 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).getWhiteSpaceCollapse();
107+
} else {
108+
return ((Css3Style) style).cssWhiteSpaceCollapse;
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.CssWhiteSpaceCollapse;
301302
import org.w3c.css.properties.css.CssWhiteSpaceTrim;
302303
import org.w3c.css.properties.css.CssWillChange;
303304
import org.w3c.css.properties.css.CssWordBreak;
@@ -700,6 +701,7 @@ public class Css3Style extends ATSCStyle {
700701
public CssWrapAfter cssWrapAfter;
701702
public CssWrapBefore cssWrapBefore;
702703
public CssTextWrap cssTextWrap;
704+
public CssWhiteSpaceCollapse cssWhiteSpaceCollapse;
703705
public CssWhiteSpaceTrim cssWhiteSpaceTrim;
704706

705707
public CssWhiteSpaceTrim getWhiteSpaceTrim() {
@@ -710,6 +712,15 @@ public CssWhiteSpaceTrim getWhiteSpaceTrim() {
710712
}
711713
return cssWhiteSpaceTrim;
712714
}
715+
716+
public CssWhiteSpaceCollapse getWhiteSpaceCollapse() {
717+
if (cssWhiteSpaceCollapse == null) {
718+
cssWhiteSpaceCollapse =
719+
(CssWhiteSpaceCollapse) style.CascadingOrder(new CssWhiteSpaceCollapse(),
720+
style, selector);
721+
}
722+
return cssWhiteSpaceCollapse;
723+
}
713724

714725
public CssWrapBefore getWrapBefore() {
715726
if (cssWrapBefore == null) {
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
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+
15+
/**
16+
* @spec https://www.w3.org/TR/2024/WD-css-text-4-20240219/#propdef-white-space-collapse
17+
*/
18+
public class CssWhiteSpaceCollapse extends org.w3c.css.properties.css.CssWhiteSpaceCollapse {
19+
20+
private static final CssIdent[] allowed_idents;
21+
22+
23+
static {
24+
String[] id_values = {"collapse", "discard", "preserve", "preserve-breaks", "preserve-spaces", "break-spaces"};
25+
allowed_idents = new CssIdent[id_values.length];
26+
int i = 0;
27+
for (String s : id_values) {
28+
allowed_idents[i++] = CssIdent.getIdent(s);
29+
}
30+
}
31+
32+
public static CssIdent getAllowedIdent(CssIdent ident) {
33+
for (CssIdent id : allowed_idents) {
34+
if (id.equals(ident)) {
35+
return id;
36+
}
37+
}
38+
return null;
39+
}
40+
41+
/**
42+
* Create a new CssWhiteSpaceCollapse
43+
*/
44+
public CssWhiteSpaceCollapse() {
45+
value = initial;
46+
}
47+
48+
/**
49+
* Creates a new CssWhiteSpaceCollapse
50+
*
51+
* @param expression The expression for this property
52+
* @throws InvalidParamException Expressions are incorrect
53+
*/
54+
public CssWhiteSpaceCollapse(ApplContext ac, CssExpression expression, boolean check)
55+
throws InvalidParamException {
56+
57+
if (check && expression.getCount() > 1) {
58+
throw new InvalidParamException("unrecognize", ac);
59+
}
60+
setByUser();
61+
62+
CssValue val;
63+
char op;
64+
65+
val = expression.getValue();
66+
op = expression.getOperator();
67+
68+
if (val.getType() != CssTypes.CSS_IDENT) {
69+
throw new InvalidParamException("value", val,
70+
getPropertyName(), ac);
71+
}
72+
CssIdent id = val.getIdent();
73+
if (!CssIdent.isCssWide(id) && (getAllowedIdent(id) == null)) {
74+
throw new InvalidParamException("value",
75+
val.toString(),
76+
getPropertyName(), ac);
77+
}
78+
value = val;
79+
expression.next();
80+
}
81+
82+
public CssWhiteSpaceCollapse(ApplContext ac, CssExpression expression)
83+
throws InvalidParamException {
84+
this(ac, expression, false);
85+
}
86+
}
87+

0 commit comments

Comments
 (0)