Skip to content

Commit 38b6627

Browse files
authored
Merge pull request #312 from w3c/scroll-anchoring-1
scroll-anchoring-1
2 parents b724614 + 8f4db85 commit 38b6627

File tree

4 files changed

+212
-0
lines changed

4 files changed

+212
-0
lines changed

org/w3c/css/properties/CSS3Properties.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,8 @@ caret-shape: org.w3c.css.properties.css3.CssCaretShap
333333
aspect-ratio: org.w3c.css.properties.css3.CssAspectRatio
334334
accent-color: org.w3c.css.properties.css3.CssAccentColor
335335

336+
overflow-anchor: org.w3c.css.properties.css3.CssOverflowAnchor
337+
336338
word-spacing: org.w3c.css.properties.css3.CssWordSpacing
337339
letter-spacing: org.w3c.css.properties.css3.CssLetterSpacing
338340
vertical-align: org.w3c.css.properties.css3.CssVerticalAlign
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, 2021.
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 CssOverflowAnchor extends CssProperty {
19+
20+
public CssValue value;
21+
22+
/**
23+
* Create a new CssOverflowAnchor
24+
*/
25+
public CssOverflowAnchor() {
26+
}
27+
28+
/**
29+
* Creates a new CssOverflowAnchor
30+
*
31+
* @param expression The expression for this property
32+
* @throws InvalidParamException Expressions are incorrect
33+
*/
34+
public CssOverflowAnchor(ApplContext ac, CssExpression expression, boolean check)
35+
throws InvalidParamException {
36+
throw new InvalidParamException("value",
37+
expression.getValue().toString(),
38+
getPropertyName(), ac);
39+
}
40+
41+
public CssOverflowAnchor(ApplContext ac, CssExpression expression)
42+
throws InvalidParamException {
43+
this(ac, expression, false);
44+
}
45+
46+
/**
47+
* Returns the value of this property
48+
*/
49+
public Object get() {
50+
return value;
51+
}
52+
53+
54+
/**
55+
* Returns the name of this property
56+
*/
57+
public final String getPropertyName() {
58+
return "overflow-anchor";
59+
}
60+
61+
/**
62+
* Returns true if this property is "softly" inherited
63+
* e.g. his value is equals to inherit
64+
*/
65+
public boolean isSoftlyInherited() {
66+
return inherit.equals(value);
67+
}
68+
69+
/**
70+
* Returns a string representation of the object.
71+
*/
72+
public String toString() {
73+
return value.toString();
74+
}
75+
76+
/**
77+
* Add this property to the CssStyle.
78+
*
79+
* @param style The CssStyle
80+
*/
81+
public void addToStyle(ApplContext ac, CssStyle style) {
82+
if (((Css3Style) style).cssOverflowAnchor != null)
83+
style.addRedefinitionWarning(ac, this);
84+
((Css3Style) style).cssOverflowAnchor = this;
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 CssOverflowAnchor &&
94+
value.equals(((CssOverflowAnchor) 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).getOverflowAnchor();
107+
} else {
108+
return ((Css3Style) style).cssOverflowAnchor;
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
@@ -182,6 +182,7 @@
182182
import org.w3c.css.properties.css.CssOpacity;
183183
import org.w3c.css.properties.css.CssOrder;
184184
import org.w3c.css.properties.css.CssOutlineOffset;
185+
import org.w3c.css.properties.css.CssOverflowAnchor;
185186
import org.w3c.css.properties.css.CssOverflowStyle;
186187
import org.w3c.css.properties.css.CssOverflowWrap;
187188
import org.w3c.css.properties.css.CssOverflowX;
@@ -607,7 +608,17 @@ public class Css3Style extends ATSCStyle {
607608
public CssBorderEndEndRadius cssBorderEndEndRadius;
608609
public CssAspectRatio cssAspectRatio;
609610
public CssAccentColor cssAccentColor;
611+
public CssOverflowAnchor cssOverflowAnchor;
610612

613+
public CssOverflowAnchor getOverflowAnchor() {
614+
if (cssOverflowAnchor == null) {
615+
cssOverflowAnchor =
616+
(CssOverflowAnchor) style.CascadingOrder(new CssOverflowAnchor(),
617+
style, selector);
618+
}
619+
return cssOverflowAnchor;
620+
}
621+
611622
public CssAccentColor getAccentColor() {
612623
if (cssAccentColor == null) {
613624
cssAccentColor =
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 MIT, ERCIM, Keio, Beihang, 2021.
5+
// Please first read the full copyright statement in file COPYRIGHT.html
6+
7+
package org.w3c.css.properties.css3;
8+
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+
16+
/**
17+
* @spec https://www.w3.org/TR/2020/WD-css-scroll-anchoring-1-20201111/#propdef-overflow-anchor
18+
*/
19+
public class CssOverflowAnchor extends org.w3c.css.properties.css.CssOverflowAnchor {
20+
21+
public static final CssIdent[] allowed_values;
22+
23+
static {
24+
String[] _allowed_values = {"auto", "none"};
25+
allowed_values = new CssIdent[_allowed_values.length];
26+
int i = 0;
27+
for (String s : _allowed_values) {
28+
allowed_values[i++] = CssIdent.getIdent(s);
29+
}
30+
}
31+
32+
public static CssIdent getAllowedIdent(CssIdent ident) {
33+
for (CssIdent id : allowed_values) {
34+
if (id.equals(ident)) {
35+
return id;
36+
}
37+
}
38+
return null;
39+
}
40+
41+
/**
42+
* Create new CssOverflowAnchor
43+
*/
44+
public CssOverflowAnchor() {
45+
value = initial;
46+
}
47+
48+
/**
49+
* Create new CssOverflowAnchor
50+
*
51+
* @param expression The expression for this property
52+
* @throws InvalidParamException Values are incorrect
53+
*/
54+
public CssOverflowAnchor(ApplContext ac, CssExpression expression,
55+
boolean check) throws InvalidParamException {
56+
setByUser();
57+
CssValue val = expression.getValue();
58+
59+
if (check && expression.getCount() > 1) {
60+
throw new InvalidParamException("unrecognize", ac);
61+
}
62+
63+
if (val.getType() != CssTypes.CSS_IDENT) {
64+
throw new InvalidParamException("value",
65+
expression.getValue(),
66+
getPropertyName(), ac);
67+
}
68+
if (inherit.equals(val)) {
69+
value = inherit;
70+
} else {
71+
value = getAllowedIdent((CssIdent) val);
72+
if (value == null) {
73+
throw new InvalidParamException("value",
74+
expression.getValue(),
75+
getPropertyName(), ac);
76+
}
77+
}
78+
expression.next();
79+
}
80+
81+
82+
public CssOverflowAnchor(ApplContext ac, CssExpression expression)
83+
throws InvalidParamException {
84+
this(ac, expression, false);
85+
}
86+
87+
}

0 commit comments

Comments
 (0)