|
| 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.atrules.css.media.MediaRangeFeature; |
| 10 | +import org.w3c.css.util.ApplContext; |
| 11 | +import org.w3c.css.util.InvalidParamException; |
| 12 | +import org.w3c.css.values.CssComparator; |
| 13 | +import org.w3c.css.values.CssExpression; |
| 14 | +import org.w3c.css.values.CssTypes; |
| 15 | +import org.w3c.css.values.CssValue; |
| 16 | + |
| 17 | +/** |
| 18 | + * @spec https://www.w3.org/TR/2021/WD-mediaqueries-5-20211218/#descdef-media-horizontal-viewport-segments |
| 19 | + */ |
| 20 | +public class MediaHorizontalViewportSegments extends MediaRangeFeature { |
| 21 | + |
| 22 | + /** |
| 23 | + * Create a new MediaHorizontalViewportSegments |
| 24 | + */ |
| 25 | + public MediaHorizontalViewportSegments() { |
| 26 | + } |
| 27 | + |
| 28 | + /** |
| 29 | + * Create a new MediaHorizontalViewportSegments. |
| 30 | + * |
| 31 | + * @param expression The expression for this media feature |
| 32 | + * @throws InvalidParamException |
| 33 | + * Values are incorrect |
| 34 | + */ |
| 35 | + public MediaHorizontalViewportSegments(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 | + value = checkValue(ac, expression, getFeatureName()); |
| 51 | + break; |
| 52 | + case CssTypes.CSS_COMPARATOR: |
| 53 | + // mediaqueries-4 case, expand the comparator and check its value |
| 54 | + if (modifier != null) { |
| 55 | + throw new InvalidParamException("nomodifierrangemedia", |
| 56 | + getFeatureName(), ac); |
| 57 | + } |
| 58 | + CssComparator p = (CssComparator) val; |
| 59 | + value = checkValue(ac, p.getParameters(), getFeatureName()); |
| 60 | + comparator = p.toString(); |
| 61 | + expression.next(); |
| 62 | + if (!expression.end()) { |
| 63 | + val = expression.getValue(); |
| 64 | + if (val.getType() != CssTypes.CSS_COMPARATOR) { |
| 65 | + throw new InvalidParamException("unrecognize", ac); |
| 66 | + } |
| 67 | + CssComparator p2; |
| 68 | + p2 = (CssComparator) val; |
| 69 | + otherValue = checkValue(ac, p2.getParameters(), getFeatureName()); |
| 70 | + otherComparator = p2.toString(); |
| 71 | + checkComparators(ac, p, p2, getFeatureName()); |
| 72 | + } |
| 73 | + break; |
| 74 | + default: |
| 75 | + throw new InvalidParamException("value", expression.getValue(), |
| 76 | + getFeatureName(), ac); |
| 77 | + } |
| 78 | + expression.next(); |
| 79 | + setModifier(ac, modifier); |
| 80 | + } else { |
| 81 | + if (modifier != null) { |
| 82 | + throw new InvalidParamException("nomodifiershortmedia", |
| 83 | + getFeatureName(), ac); |
| 84 | + } |
| 85 | + } |
| 86 | + } |
| 87 | + |
| 88 | + public MediaHorizontalViewportSegments(ApplContext ac, String modifier, CssExpression expression) |
| 89 | + throws InvalidParamException { |
| 90 | + this(ac, modifier, expression, false); |
| 91 | + } |
| 92 | + |
| 93 | + static CssValue checkValue(ApplContext ac, CssExpression expression, String caller) |
| 94 | + throws InvalidParamException { |
| 95 | + if (expression.getCount() == 0) { |
| 96 | + throw new InvalidParamException("few-value", caller, ac); |
| 97 | + } |
| 98 | + CssValue val = expression.getValue(); |
| 99 | + CssValue value = null; |
| 100 | + |
| 101 | + switch (val.getType()) { |
| 102 | + case CssTypes.CSS_NUMBER: |
| 103 | + val.getCheckableValue().checkInteger(ac, caller); |
| 104 | + value = val; |
| 105 | + break; |
| 106 | + default: |
| 107 | + throw new InvalidParamException("value", expression.getValue(), |
| 108 | + caller, ac); |
| 109 | + } |
| 110 | + return value; |
| 111 | + } |
| 112 | + |
| 113 | + /** |
| 114 | + * Returns the value of this media feature. |
| 115 | + */ |
| 116 | + |
| 117 | + public Object get() { |
| 118 | + return value; |
| 119 | + } |
| 120 | + |
| 121 | + /** |
| 122 | + * Returns the name of this media feature. |
| 123 | + */ |
| 124 | + public final String getFeatureName() { |
| 125 | + return "horizontal-viewport-segments"; |
| 126 | + } |
| 127 | + |
| 128 | + /** |
| 129 | + * Compares two media features for equality. |
| 130 | + * |
| 131 | + * @param other The other media features. |
| 132 | + */ |
| 133 | + public boolean equals(MediaFeature other) { |
| 134 | + try { |
| 135 | + MediaHorizontalViewportSegments mm = (MediaHorizontalViewportSegments) other; |
| 136 | + return (((value == null) && (mm.value == null)) || ((value != null) && value.equals(mm.value))) |
| 137 | + && (((modifier == null) && (mm.modifier == null)) || ((modifier != null) && modifier.equals(mm.modifier))); |
| 138 | + } catch (ClassCastException cce) { |
| 139 | + return false; |
| 140 | + } |
| 141 | + |
| 142 | + } |
| 143 | +} |
0 commit comments