Skip to content

Commit ab6283b

Browse files
Allow the text-size-adjust property & check it
This change makes the CSS checker recognize & check the `text-size-adjust` property. The checking behavior conforms to the definition in the Mobile Text Size Adjustment spec at https://drafts.csswg.org/css-size-adjust/
1 parent d4f15aa commit ab6283b

File tree

6 files changed

+225
-0
lines changed

6 files changed

+225
-0
lines changed

org/w3c/css/properties/CSS3Properties.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ text-emphasis: org.w3c.css.properties.css3.CssTextEmpha
125125
text-emphasis-color: org.w3c.css.properties.css3.CssTextEmphasisColor
126126
text-emphasis-position: org.w3c.css.properties.css3.CssTextEmphasisPosition
127127
text-emphasis-style: org.w3c.css.properties.css3.CssTextEmphasisStyle
128+
text-size-adjust: org.w3c.css.properties.css3.CssTextSizeAdjust
128129
text-underline-position: org.w3c.css.properties.css3.CssTextUnderlinePosition
129130
tab-size: org.w3c.css.properties.css3.CssTabSize
130131
hanging-punctuation: org.w3c.css.properties.css3.CssHangingPunctuation

org/w3c/css/properties/CSS3SVGProperties.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ text-emphasis: org.w3c.css.properties.css3.CssTextEmpha
174174
text-emphasis-color: org.w3c.css.properties.css3.CssTextEmphasisColor
175175
text-emphasis-position: org.w3c.css.properties.css3.CssTextEmphasisPosition
176176
text-emphasis-style: org.w3c.css.properties.css3.CssTextEmphasisStyle
177+
text-size-adjust: org.w3c.css.properties.css3.CssTextSizeAdjust
177178
text-underline-position: org.w3c.css.properties.css3.CssTextUnderlinePosition
178179
tab-size: org.w3c.css.properties.css3.CssTabSize
179180
hanging-punctuation: org.w3c.css.properties.css3.CssHangingPunctuation

org/w3c/css/properties/Media.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ text-emphasis: handheld, print, projection, screen, tty, tv
4343
text-emphasis-color: handheld, print, projection, screen, tty, tv
4444
text-emphasis-position: handheld, print, projection, screen, tty, tv
4545
text-emphasis-style: handheld, print, projection, screen, tty, tv
46+
text-size-adjust: handheld, print, projection, screen, tty, tv
4647
line-height: handheld, print, projection, screen, tty, tv
4748
margin-top: handheld, print, projection, screen, tty, tv
4849
margin-bottom: handheld, print, projection, screen, tty, tv
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
// (c) COPYRIGHT MIT, ERCIM, Keio and Beihang, 2018.
2+
// Please first read the full copyright statement in file COPYRIGHT.html
3+
package org.w3c.css.properties.css;
4+
5+
import org.w3c.css.parser.CssStyle;
6+
import org.w3c.css.properties.css3.Css3Style;
7+
import org.w3c.css.util.ApplContext;
8+
import org.w3c.css.util.InvalidParamException;
9+
import org.w3c.css.values.CssExpression;
10+
import org.w3c.css.values.CssValue;
11+
12+
/**
13+
* @since CSS3
14+
*/
15+
public class CssTextSizeAdjust extends CssProperty {
16+
17+
public CssValue value;
18+
19+
/**
20+
* Create a new CssTextSizeAdjust
21+
*/
22+
public CssTextSizeAdjust() {
23+
}
24+
25+
/**
26+
* Creates a new CssTextSizeAdjust
27+
*
28+
* @param expression The expression for this property
29+
* @throws org.w3c.css.util.InvalidParamException
30+
* Expressions are incorrect
31+
*/
32+
public CssTextSizeAdjust(ApplContext ac, CssExpression expression, //
33+
boolean check) throws InvalidParamException {
34+
throw new InvalidParamException("value",
35+
expression.getValue().toString(),
36+
getPropertyName(), ac);
37+
}
38+
39+
public CssTextSizeAdjust(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 "text-size-adjust";
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.cssTextSizeAdjust != null) {
82+
style.addRedefinitionWarning(ac, this);
83+
}
84+
s.cssTextSizeAdjust = 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 CssTextSizeAdjust &&
95+
value.equals(((CssTextSizeAdjust) 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).getTextSizeAdjust();
108+
} else {
109+
return ((Css3Style) style).cssTextSizeAdjust;
110+
}
111+
}
112+
}

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@
174174
import org.w3c.css.properties.css.CssTextEmphasisStyle;
175175
import org.w3c.css.properties.css.CssTextJustify;
176176
import org.w3c.css.properties.css.CssTextOverflow;
177+
import org.w3c.css.properties.css.CssTextSizeAdjust;
177178
import org.w3c.css.properties.css.CssTextUnderlinePosition;
178179
import org.w3c.css.properties.css.CssTouchAction;
179180
import org.w3c.css.properties.css.CssTransform;
@@ -353,6 +354,7 @@ public class Css3Style extends ATSCStyle {
353354
public CssTextEmphasisColor cssTextEmphasisColor;
354355
public CssTextEmphasisPosition cssTextEmphasisPosition;
355356
public CssTextEmphasisStyle cssTextEmphasisStyle;
357+
public CssTextSizeAdjust cssTextSizeAdjust;
356358
public CssTextUnderlinePosition cssTextUnderlinePosition;
357359
public CssHangingPunctuation cssHangingPunctuation;
358360
public CssTabSize cssTabSize;
@@ -1690,6 +1692,15 @@ public CssTextEmphasisStyle getTextEmphasisStyle() {
16901692
return cssTextEmphasisStyle;
16911693
}
16921694

1695+
public CssTextSizeAdjust getTextSizeAdjust() {
1696+
if (cssTextSizeAdjust == null) {
1697+
cssTextSizeAdjust =
1698+
(CssTextSizeAdjust) style.CascadingOrder(
1699+
new CssTextSizeAdjust(), style, selector);
1700+
}
1701+
return cssTextSizeAdjust;
1702+
}
1703+
16931704
public CssTextUnderlinePosition getTextUnderlinePosition() {
16941705
if (cssTextUnderlinePosition == null) {
16951706
cssTextUnderlinePosition =
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
// (c) COPYRIGHT MIT, ERCIM, Keio, Beihang, 2018.
2+
// Please first read the full copyright statement at:
3+
// https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document
4+
5+
package org.w3c.css.properties.css3;
6+
7+
import org.w3c.css.util.ApplContext;
8+
import org.w3c.css.util.InvalidParamException;
9+
import org.w3c.css.values.CssExpression;
10+
import org.w3c.css.values.CssIdent;
11+
import org.w3c.css.values.CssTypes;
12+
import org.w3c.css.values.CssValue;
13+
14+
/**
15+
* @spec https://github.com/w3c/csswg-drafts/blob/d644687e36b3290d62fe0117a94345addf3468af/css-size-adjust-1/Overview.bs
16+
*/
17+
18+
public class CssTextSizeAdjust extends org.w3c.css.properties.css.CssTextSizeAdjust {
19+
20+
public static final CssIdent auto = CssIdent.getIdent("auto");
21+
22+
public static final CssIdent[] allowed_values;
23+
24+
static {
25+
int i = 0;
26+
String[] _allowed_values = {"auto", "none"};
27+
allowed_values = new CssIdent[_allowed_values.length];
28+
i = 0;
29+
for (String s : _allowed_values) {
30+
allowed_values[i++] = CssIdent.getIdent(s);
31+
}
32+
}
33+
34+
public static CssIdent getAllowedIdent(CssIdent ident) {
35+
for (CssIdent id : allowed_values) {
36+
if (id.equals(ident)) {
37+
return id;
38+
}
39+
}
40+
return null;
41+
}
42+
43+
/**
44+
* Create a new CssTextSizeAdjust
45+
*/
46+
public CssTextSizeAdjust() {
47+
value = initial;
48+
}
49+
50+
/**
51+
* Create a new CssTextSizeAdjust
52+
*
53+
* @param expression The expression for this property
54+
* @throws InvalidParamException Incorrect value
55+
*/
56+
public CssTextSizeAdjust(ApplContext ac, CssExpression expression,
57+
boolean check) throws InvalidParamException {
58+
59+
if (check && expression.getCount() > 1) {
60+
throw new InvalidParamException("unrecognize", ac);
61+
}
62+
63+
setByUser();
64+
65+
CssValue val;
66+
67+
val = expression.getValue();
68+
69+
switch (val.getType()) {
70+
case CssTypes.CSS_IDENT:
71+
CssIdent id = (CssIdent) val;
72+
if (inherit.equals(id)) {
73+
value = inherit;
74+
} else {
75+
value = getAllowedIdent(id);
76+
if (value == null) {
77+
throw new InvalidParamException("value", val.toString(),
78+
getPropertyName(), ac);
79+
}
80+
}
81+
case CssTypes.CSS_PERCENTAGE:
82+
value = val;
83+
break;
84+
default:
85+
throw new InvalidParamException("value", val.toString(),
86+
getPropertyName(), ac);
87+
}
88+
}
89+
90+
public CssTextSizeAdjust(ApplContext ac, CssExpression expression)
91+
throws InvalidParamException {
92+
this(ac, expression, false);
93+
}
94+
95+
public boolean isDefault() {
96+
return ((value == auto) || (value == initial));
97+
}
98+
99+
}

0 commit comments

Comments
 (0)