Skip to content

Commit

Permalink
Merge pull request #122 from w3c/sideshowbarker/vendor-media-features…
Browse files Browse the repository at this point in the history
…-as-warnings

Treat prefixed media features as vendor extensions
  • Loading branch information
ylafon committed Jan 4, 2018
2 parents cb2a6ab + 2a771cd commit 096fa5a
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 26 deletions.
9 changes: 7 additions & 2 deletions org/w3c/css/parser/CssFouffa.java
Expand Up @@ -24,6 +24,7 @@
import org.w3c.css.util.HTTPURL;
import org.w3c.css.util.InvalidParamException;
import org.w3c.css.util.Util;
import org.w3c.css.util.WarningParamException;
import org.w3c.css.util.Warnings;
import org.w3c.css.values.CssExpression;

Expand Down Expand Up @@ -609,16 +610,19 @@ public MediaFeature handleMediaFeature(AtRuleMedia rule, String feature,

try {
mf = properties.createMediaFeature(ac, rule, feature, expression);
} catch (WarningParamException w) {
ac.getFrame().addWarning(w.getMessage(), feature);
return null;
} catch (InvalidParamException e) {
throw e;
ac.getFrame().addError(new CssError(e));
return null;
} catch (Exception e) {
e.printStackTrace();
if (Util.onDebug) {
e.printStackTrace();
}
throw new InvalidParamException(e.toString(), ac);
}

mf.setOrigin(origin);
// set informations for errors and warnings
mf.setInfo(ac.getFrame().getLine(), ac.getFrame().getSourceFile());
Expand Down Expand Up @@ -646,6 +650,7 @@ public MediaFeature handleMediaFeature(AtRuleMedia rule, String feature,
* @param context The current context
* @see org.w3c.css.parser.CssFouffa#addListener
*/

public void parseDeclarations(CssSelectors context) {
// here we have an example for reusing the parser.
try {
Expand Down
46 changes: 24 additions & 22 deletions org/w3c/css/parser/CssPropertyFactory.java
Expand Up @@ -24,6 +24,7 @@
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.StringTokenizer;

/**
Expand Down Expand Up @@ -107,20 +108,9 @@ public synchronized MediaFeature createMediaFeature(ApplContext ac, AtRule atRul
String classname;
int dashpos = feature.indexOf('-');
feature = feature.toLowerCase();

if (dashpos != -1) {
if (dashpos == 0) {
// vendor media?
try {
AtRuleMedia atRuleMedia = (AtRuleMedia) atRule;
// I don't know this property
// TODO get the latest media it applies to
throw new InvalidParamException("noexistence-media", feature,
atRuleMedia.getCurrentMedia(), ac);
} catch (ClassCastException cce) {
// I don't know this property
throw new InvalidParamException("noexistence", feature, "not media @rule", ac);
}
throw vendorMediaException(ac, atRule, feature);
}
modifier = feature.substring(0, dashpos);
// clash between feature name and modifier...
Expand All @@ -135,16 +125,7 @@ public synchronized MediaFeature createMediaFeature(ApplContext ac, AtRule atRul

classname = properties.getProperty("mediafeature" + "." + feature.toLowerCase());
if (classname == null) {
try {
AtRuleMedia atRuleMedia = (AtRuleMedia) atRule;
// I don't know this property
// TODO get the latest media it applies to
throw new InvalidParamException("noexistence-media", feature,
atRuleMedia.getCurrentMedia(), ac);
} catch (ClassCastException cce) {
// I don't know this property
throw new InvalidParamException("noexistence", feature, "not media @rule", ac);
}
throw vendorMediaException(ac, atRule, feature);
}

try {
Expand All @@ -167,6 +148,27 @@ public synchronized MediaFeature createMediaFeature(ApplContext ac, AtRule atRul
}
}

private Exception vendorMediaException(ApplContext ac, AtRule atRule,
String feature) throws Exception {
// I don't know this property
// TODO get the latest media it applies to
try {
AtRuleMedia atRuleMedia = (AtRuleMedia) atRule;
if (ac.getTreatVendorExtensionsAsWarnings()) {
throw new WarningParamException("vendor-extension",
feature);
} else {
throw new InvalidParamException(
"noexistence-media", feature,
atRuleMedia.getCurrentMedia(), ac);
}
} catch (ClassCastException cce) {
// I don't know this property
throw new InvalidParamException("noexistence", feature,
"not media @rule", ac);
}
}

public synchronized CssProperty createProperty(ApplContext ac, AtRule atRule, String property,
CssExpression expression) throws Exception {
String classname = null;
Expand Down
4 changes: 3 additions & 1 deletion org/w3c/css/parser/analyzer/CssParser.java
Expand Up @@ -1341,7 +1341,9 @@ final public void ignoreStatement() throws ParseException {
jj_consume_token(S);
}
MediaFeature mf = handleMediaFeature(mediaRule, mediaFeatureName, val);
mediaRule.addMediaFeature(mf, ac);
if (mf != null) {
mediaRule.addMediaFeature(mf, ac);
}
}

final public void unused_production_generic_syntax() throws ParseException {CssExpression values = new CssExpression();
Expand Down
4 changes: 3 additions & 1 deletion org/w3c/css/parser/analyzer/CssParser.jj
Expand Up @@ -1021,7 +1021,9 @@ void mediaexpression(AtRuleMedia mediaRule, boolean defaultMedia) :
( <S> )*
( <COLON> ( <S> )* val=mediaexpr() )? <LPARAN> ( <S> )* {
MediaFeature mf = handleMediaFeature(mediaRule, mediaFeatureName, val);
mediaRule.addMediaFeature(mf, ac);
if (mf != null) {
mediaRule.addMediaFeature(mf, ac);
}
}
}

Expand Down

0 comments on commit 096fa5a

Please sign in to comment.