Skip to content

Commit a5186a3

Browse files
committed
1 parent 58e34b5 commit a5186a3

File tree

2 files changed

+130
-0
lines changed

2 files changed

+130
-0
lines changed
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
// $Id$
2+
//
3+
// (c) COPYRIGHT MIT, ECRIM and Keio University, 2011
4+
// Please first read the full copyright statement in file COPYRIGHT.html
5+
6+
package org.w3c.css.atrules.css3.media;
7+
8+
import org.w3c.css.atrules.css.media.MediaFeature;
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/2017/CR-mediaqueries-4-20170905/#descdef-media-color-gamut
18+
*/
19+
public class MediaColorGamut extends MediaFeature {
20+
21+
public static final CssIdent[] allowed_values;
22+
23+
static {
24+
String[] _allowed_values = {"srgb", "p3", "rec2020"};
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 getAllowedValue(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 a new MediaColorGamut
43+
*/
44+
public MediaColorGamut() {
45+
}
46+
47+
/**
48+
* Create a new MediaColorGamut
49+
*
50+
* @param expression The expression for this media feature
51+
* @throws org.w3c.css.util.InvalidParamException
52+
* Values are incorrect
53+
*/
54+
public MediaColorGamut(ApplContext ac, String modifier,
55+
CssExpression expression, boolean check)
56+
throws InvalidParamException {
57+
58+
if (modifier != null) {
59+
throw new InvalidParamException("nomodifiermedia",
60+
getFeatureName(), ac);
61+
}
62+
63+
if (expression != null) {
64+
if (expression.getCount() > 1) {
65+
throw new InvalidParamException("unrecognize", ac);
66+
}
67+
if (expression.getCount() == 0) {
68+
throw new InvalidParamException("few-value", getFeatureName(), ac);
69+
}
70+
CssValue val = expression.getValue();
71+
72+
switch (val.getType()) {
73+
case CssTypes.CSS_IDENT:
74+
value = getAllowedValue((CssIdent) val);
75+
if (value != null) {
76+
break;
77+
}
78+
// let it flow through the exception
79+
default:
80+
throw new InvalidParamException("value", expression.getValue(),
81+
getFeatureName(), ac);
82+
}
83+
} else {
84+
// TODO add a warning for value less mediafeature that makes no sense
85+
}
86+
}
87+
88+
public MediaColorGamut(ApplContext ac, String modifier, CssExpression expression)
89+
throws InvalidParamException {
90+
this(ac, modifier, expression, false);
91+
}
92+
93+
// just in case someone wants to call it externally...
94+
public void setModifier(ApplContext ac, String modifier)
95+
throws InvalidParamException {
96+
throw new InvalidParamException("nomodifiermedia",
97+
getFeatureName(), ac);
98+
}
99+
100+
/**
101+
* Returns the value of this media feature.
102+
*/
103+
104+
public Object get() {
105+
return value;
106+
}
107+
108+
/**
109+
* Returns the name of this media feature.
110+
*/
111+
public final String getFeatureName() {
112+
return "color-gamut";
113+
}
114+
115+
/**
116+
* Compares two media features for equality.
117+
*
118+
* @param other The other media features.
119+
*/
120+
public boolean equals(MediaFeature other) {
121+
try {
122+
MediaColorGamut ms = (MediaColorGamut) other;
123+
return (((value == null) && (ms.value == null)) || ((value != null) && value.equals(ms.value)));
124+
} catch (ClassCastException cce) {
125+
return false;
126+
}
127+
128+
}
129+
}

org/w3c/css/properties/CSS3Properties.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,7 @@ mediafeature.orientation: org.w3c.css.atrules.css3.media.MediaOrie
445445
mediafeature.aspect-ratio: org.w3c.css.atrules.css3.media.MediaAspectRatio
446446
mediafeature.device-aspect-ratio: org.w3c.css.atrules.css3.media.MediaDeviceAspectRatio
447447
mediafeature.color: org.w3c.css.atrules.css3.media.MediaColor
448+
mediafeature.color-gamut: org.w3c.css.atrules.css3.media.MediaColorGamut
448449
mediafeature.color-index: org.w3c.css.atrules.css3.media.MediaColorIndex
449450
mediafeature.monochrome: org.w3c.css.atrules.css3.media.MediaMonochrome
450451
mediafeature.overflow-block: org.w3c.css.atrules.css3.media.MediaOverflowBlock

0 commit comments

Comments
 (0)