Skip to content

Commit 514cb23

Browse files
Emit error for deprecated media features
When the CSS3 profile is selected, this change causes an error to be emitted for the following deprecated media features: device-aspect-ratio, device-height, device-width — as well as for their corresponding min- and max- prefixed versions. https://www.w3.org/TR/2017/CR-mediaqueries-4-20170905/#mf-deprecated states: > The following media features are deprecated. They kept for backward > compatibility, but are not appropriate for newly written style sheets. > Authors must not use them. Otherwise, without this change, no messages (not even warnings) are reported for the (mis)use of those media features.
1 parent a87e32e commit 514cb23

File tree

5 files changed

+29
-97
lines changed

5 files changed

+29
-97
lines changed

org/w3c/css/atrules/css/media/MediaFeature.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package org.w3c.css.atrules.css.media;
22

33
import org.w3c.css.css.StyleSheetOrigin;
4+
import org.w3c.css.parser.analyzer.ParseException;
5+
import org.w3c.css.parser.CssError;
6+
import org.w3c.css.util.ApplContext;
7+
import org.w3c.css.util.InvalidParamException;
48
import org.w3c.css.values.CssValue;
59

610
public abstract class MediaFeature implements StyleSheetOrigin {
@@ -52,6 +56,18 @@ public String getCombinator() {
5256
return combinator;
5357
}
5458

59+
public void reportDeprecatedMediaFeature(ApplContext ac, String modifier) {
60+
String feature;
61+
if (modifier != null) {
62+
feature = String.format("%s-%s", modifier, getFeatureName());
63+
} else {
64+
feature = getFeatureName();
65+
}
66+
ac.getFrame().addError(new CssError(new ParseException(
67+
String.format(ac.getMsg().getString("deprecatedmediafeature"),
68+
feature))));
69+
}
70+
5571
/**
5672
* Update the source file and the line.
5773
* Overrides this method for a macro

org/w3c/css/atrules/css3/media/MediaDeviceAspectRatio.java

Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,12 @@
88
import org.w3c.css.atrules.css.media.MediaFeature;
99
import org.w3c.css.atrules.css.media.MediaRangeFeature;
1010
import org.w3c.css.util.ApplContext;
11-
import org.w3c.css.util.InvalidParamException;
1211
import org.w3c.css.values.CssExpression;
1312
import org.w3c.css.values.CssTypes;
1413
import org.w3c.css.values.CssValue;
1514

1615
/**
17-
* @spec http://www.w3.org/TR/2012/REC-css3-mediaqueries-20120619/#device-aspect-ratio
16+
* @spec https://www.w3.org/TR/2017/CR-mediaqueries-4-20170905/#mf-deprecated
1817
*/
1918
@Deprecated
2019
public class MediaDeviceAspectRatio extends MediaRangeFeature {
@@ -33,36 +32,12 @@ public MediaDeviceAspectRatio() {
3332
* Values are incorrect
3433
*/
3534
public MediaDeviceAspectRatio(ApplContext ac, String modifier,
36-
CssExpression expression, boolean check)
37-
throws InvalidParamException {
38-
39-
if (expression != null) {
40-
if (expression.getCount() > 1) {
41-
throw new InvalidParamException("unrecognize", ac);
42-
}
43-
if (expression.getCount() == 0) {
44-
throw new InvalidParamException("few-value", getFeatureName(), ac);
45-
}
46-
CssValue val = expression.getValue();
47-
48-
if (val.getType() == CssTypes.CSS_RATIO) {
49-
value = val;
50-
setModifier(ac, modifier);
51-
} else {
52-
throw new InvalidParamException("unrecognize", ac);
53-
}
54-
setModifier(ac, modifier);
55-
} else {
56-
if (modifier != null) {
57-
throw new InvalidParamException("nomodifiershortmedia",
58-
getFeatureName(), ac);
59-
}
60-
}
61-
35+
CssExpression expression, boolean check) {
36+
reportDeprecatedMediaFeature(ac, modifier);
6237
}
6338

6439
public MediaDeviceAspectRatio(ApplContext ac, String modifier, CssExpression expression)
65-
throws InvalidParamException {
40+
{
6641
this(ac, modifier, expression, false);
6742
}
6843

org/w3c/css/atrules/css3/media/MediaDeviceHeight.java

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,12 @@
88
import org.w3c.css.atrules.css.media.MediaFeature;
99
import org.w3c.css.atrules.css.media.MediaRangeFeature;
1010
import org.w3c.css.util.ApplContext;
11-
import org.w3c.css.util.InvalidParamException;
1211
import org.w3c.css.values.CssExpression;
1312
import org.w3c.css.values.CssTypes;
1413
import org.w3c.css.values.CssValue;
1514

1615
/**
17-
* @spec http://www.w3.org/TR/2012/REC-css3-mediaqueries-20120619/#device-height
16+
* @spec https://www.w3.org/TR/2017/CR-mediaqueries-4-20170905/#mf-deprecated
1817
*/
1918
@Deprecated
2019
public class MediaDeviceHeight extends MediaRangeFeature {
@@ -33,41 +32,12 @@ public MediaDeviceHeight() {
3332
* Values are incorrect
3433
*/
3534
public MediaDeviceHeight(ApplContext ac, String modifier,
36-
CssExpression expression, boolean check)
37-
throws InvalidParamException {
38-
39-
if (expression != null) {
40-
if (expression.getCount() > 1) {
41-
throw new InvalidParamException("unrecognize", ac);
42-
}
43-
if (expression.getCount() == 0) {
44-
throw new InvalidParamException("few-value", getFeatureName(), ac);
45-
}
46-
CssValue val = expression.getValue();
47-
48-
switch (val.getType()) {
49-
case CssTypes.CSS_NUMBER:
50-
// a bit stupid as the only value would be 0...
51-
val.getCheckableValue().checkEqualsZero(ac, this);
52-
case CssTypes.CSS_LENGTH:
53-
value = val;
54-
expression.next();
55-
break;
56-
default:
57-
throw new InvalidParamException("value", expression.getValue(),
58-
getFeatureName(), ac);
59-
}
60-
setModifier(ac, modifier);
61-
} else {
62-
if (modifier != null) {
63-
throw new InvalidParamException("nomodifiershortmedia",
64-
getFeatureName(), ac);
65-
}
66-
}
35+
CssExpression expression, boolean check) {
36+
reportDeprecatedMediaFeature(ac, modifier);
6737
}
6838

6939
public MediaDeviceHeight(ApplContext ac, String modifier, CssExpression expression)
70-
throws InvalidParamException {
40+
{
7141
this(ac, modifier, expression, false);
7242
}
7343

org/w3c/css/atrules/css3/media/MediaDeviceWidth.java

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,12 @@
88
import org.w3c.css.atrules.css.media.MediaFeature;
99
import org.w3c.css.atrules.css.media.MediaRangeFeature;
1010
import org.w3c.css.util.ApplContext;
11-
import org.w3c.css.util.InvalidParamException;
1211
import org.w3c.css.values.CssExpression;
1312
import org.w3c.css.values.CssTypes;
1413
import org.w3c.css.values.CssValue;
1514

1615
/**
17-
* @spec http://www.w3.org/TR/2012/REC-css3-mediaqueries-20120619/#device-width
16+
* @spec https://www.w3.org/TR/2017/CR-mediaqueries-4-20170905/#mf-deprecated
1817
*/
1918
@Deprecated
2019
public class MediaDeviceWidth extends MediaRangeFeature {
@@ -33,41 +32,12 @@ public MediaDeviceWidth() {
3332
* Values are incorrect
3433
*/
3534
public MediaDeviceWidth(ApplContext ac, String modifier,
36-
CssExpression expression, boolean check)
37-
throws InvalidParamException {
38-
39-
if (expression != null) {
40-
if (expression.getCount() > 1) {
41-
throw new InvalidParamException("unrecognize", ac);
42-
}
43-
if (expression.getCount() == 0) {
44-
throw new InvalidParamException("few-value", getFeatureName(), ac);
45-
}
46-
CssValue val = expression.getValue();
47-
48-
switch (val.getType()) {
49-
case CssTypes.CSS_NUMBER:
50-
// a bit stupid as the only value would be 0...
51-
val.getCheckableValue().checkEqualsZero(ac, this);
52-
case CssTypes.CSS_LENGTH:
53-
value = val;
54-
expression.next();
55-
break;
56-
default:
57-
throw new InvalidParamException("value", expression.getValue(),
58-
getFeatureName(), ac);
59-
}
60-
setModifier(ac, modifier);
61-
} else {
62-
if (modifier != null) {
63-
throw new InvalidParamException("nomodifiershortmedia",
64-
getFeatureName(), ac);
65-
}
66-
}
35+
CssExpression expression, boolean check) {
36+
reportDeprecatedMediaFeature(ac, modifier);
6737
}
6838

6939
public MediaDeviceWidth(ApplContext ac, String modifier, CssExpression expression)
70-
throws InvalidParamException {
40+
{
7141
this(ac, modifier, expression, false);
7242
}
7343

org/w3c/css/util/Messages.properties.en

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,7 @@ parser.import_not_allowed: @import are not allowed after any valid statement oth
424424
error.bg_order: In the CSS3 background definition, \u201Cbg_position\u201D must occur before / \u201Cbg_size\u201D if both are present
425425

426426
warning.deprecatedmedia: The media \u201C%s\u201D has been deprecated
427+
deprecatedmediafeature: Deprecated media feature \u201C%s\u201D. For guidance, see the Deprecated Media Features section in the current Media Queries specification.
427428
error.nomediarestrictor: Mediarestrictor not defined in this CSS level
428429
error.nomediafeature: Media features are not defined in this CSS level
429430
error.nomodifiershortmedia: No prefixes are allowed for media features with no value

0 commit comments

Comments
 (0)