Skip to content

Commit 3591111

Browse files
committed
1 parent 5cf1dbd commit 3591111

4 files changed

Lines changed: 206 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
@@ -109,6 +109,7 @@ will-change: org.w3c.css.properties.css3.CssWillChang
109109

110110
# contain
111111
contain: org.w3c.css.properties.css3.CssContain
112+
content-visibility: org.w3c.css.properties.css3.CssContentVisibility
112113

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

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@
9191
import org.w3c.css.properties.css.CssColumnWidth;
9292
import org.w3c.css.properties.css.CssColumns;
9393
import org.w3c.css.properties.css.CssContain;
94+
import org.w3c.css.properties.css.CssContentVisibility;
9495
import org.w3c.css.properties.css.CssCounterSet;
9596
import org.w3c.css.properties.css.CssDominantBaseline;
9697
import org.w3c.css.properties.css.CssFilter;
@@ -680,7 +681,17 @@ public class Css3Style extends ATSCStyle {
680681
public CssOverscrollBehavior cssOverscrollBehavior;
681682
public CssOverscrollBehaviorBlock cssOverscrollBehaviorBlock;
682683
public CssOverscrollBehaviorInline cssOverscrollBehaviorInline;
684+
public CssContentVisibility cssContentVisibility;
683685

686+
public CssContentVisibility getContentVisibility() {
687+
if (cssContentVisibility == null) {
688+
cssContentVisibility =
689+
(CssContentVisibility) style.CascadingOrder(new CssContentVisibility(),
690+
style, selector);
691+
}
692+
return cssContentVisibility;
693+
}
694+
684695
public CssOverscrollBehavior getOverscrollBehavior() {
685696
if (cssOverscrollBehavior == null) {
686697
cssOverscrollBehavior =
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
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.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/2020/WD-css-contain-2-20201216/#propdef-content-visibility
17+
*/
18+
public class CssContentVisibility extends org.w3c.css.properties.css.CssContentVisibility {
19+
20+
public static final CssIdent[] allowed_values;
21+
22+
static {
23+
String[] _allowed_values = {"visible", "auto", "hidden"};
24+
allowed_values = new CssIdent[_allowed_values.length];
25+
int i = 0;
26+
for (String s : _allowed_values) {
27+
allowed_values[i++] = CssIdent.getIdent(s);
28+
}
29+
}
30+
31+
public static CssIdent getAllowedIdent(CssIdent ident) {
32+
for (CssIdent id : allowed_values) {
33+
if (id.equals(ident)) {
34+
return id;
35+
}
36+
}
37+
return null;
38+
}
39+
40+
/**
41+
* Create a new CssContentVisibility
42+
*/
43+
public CssContentVisibility() {
44+
value = initial;
45+
}
46+
47+
/**
48+
* Creates a new CssContentVisibility
49+
*
50+
* @param expression The expression for this property
51+
* @throws InvalidParamException Expressions are incorrect
52+
*/
53+
public CssContentVisibility(ApplContext ac, CssExpression expression, boolean check)
54+
throws InvalidParamException {
55+
56+
if (check && expression.getCount() > 1) {
57+
throw new InvalidParamException("unrecognize", ac);
58+
}
59+
60+
CssValue val = expression.getValue();
61+
62+
setByUser();
63+
if (val.getType() != CssTypes.CSS_IDENT) {
64+
throw new InvalidParamException("value", expression.getValue(),
65+
getPropertyName(), ac);
66+
}
67+
CssIdent id = val.getIdent();
68+
if (!CssIdent.isCssWide(id) && (getAllowedIdent(id) == null)) {
69+
throw new InvalidParamException("value", expression.getValue(),
70+
getPropertyName(), ac);
71+
}
72+
value = val;
73+
expression.next();
74+
}
75+
76+
public CssContentVisibility(ApplContext ac, CssExpression expression)
77+
throws InvalidParamException {
78+
this(ac, expression, false);
79+
}
80+
}
81+

0 commit comments

Comments
 (0)