Skip to content

Commit bbedd8e

Browse files
committed
support 'none' in rgb colors
1 parent 6ebbcd1 commit bbedd8e

8 files changed

Lines changed: 2725 additions & 2485 deletions

File tree

src/main/java/org/htmlunit/cssparser/dom/CSSValueImpl.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,8 @@ public CSSPrimitiveValueType getPrimitiveType() {
384384
return CSSPrimitiveValueType.CSS_KHZ;
385385
case IDENT:
386386
return CSSPrimitiveValueType.CSS_IDENT;
387+
case NONE:
388+
return CSSPrimitiveValueType.CSS_IDENT;
387389
case STRING_VALUE:
388390
return CSSPrimitiveValueType.CSS_STRING;
389391
case ATTR:
@@ -473,6 +475,10 @@ public String getStringValue() throws DOMException {
473475
return "inherit";
474476
}
475477

478+
if (lu.getLexicalUnitType() == LexicalUnitType.NONE) {
479+
return "none";
480+
}
481+
476482
// for rgba values we are using this type
477483
if (lu.getLexicalUnitType() == LexicalUnitType.FUNCTION
478484
|| lu.getLexicalUnitType() == LexicalUnitType.FUNCTION_CALC) {

src/main/java/org/htmlunit/cssparser/dom/RGBColorImpl.java

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,10 @@ public RGBColorImpl(final String function, final LexicalUnit lu) throws DOMExcep
5353
function_ = functionLC;
5454

5555
LexicalUnit next = lu;
56+
if (next == null) {
57+
throw new DOMException(DOMException.SYNTAX_ERR, function_ + " requires at least three values.");
58+
}
5659

57-
final boolean percentage = LexicalUnitType.PERCENTAGE == next.getLexicalUnitType();
5860
red_ = getPart(next);
5961

6062
next = next.getNextLexicalUnit();
@@ -64,18 +66,22 @@ public RGBColorImpl(final String function, final LexicalUnit lu) throws DOMExcep
6466

6567
commaSeparated_ = next.getLexicalUnitType() == LexicalUnitType.OPERATOR_COMMA;
6668
if (commaSeparated_) {
69+
if (red_.getLexicalUnitType() == LexicalUnitType.NONE) {
70+
throw new DOMException(DOMException.SYNTAX_ERR,
71+
function_ + " has to use blank as separator if none is used.");
72+
}
73+
6774
next = next.getNextLexicalUnit();
6875
if (next == null) {
6976
throw new DOMException(DOMException.SYNTAX_ERR, function_ + " requires at least three values.");
7077
}
7178

72-
if (percentage && LexicalUnitType.PERCENTAGE != next.getLexicalUnitType()) {
73-
throw new DOMException(DOMException.SYNTAX_ERR, function_ + " mixing numbers and percentages.");
74-
}
75-
if (!percentage && LexicalUnitType.PERCENTAGE == next.getLexicalUnitType()) {
76-
throw new DOMException(DOMException.SYNTAX_ERR, function_ + " mixing numbers and percentages.");
77-
}
7879
green_ = getPart(next);
80+
if (green_.getLexicalUnitType() == LexicalUnitType.NONE) {
81+
throw new DOMException(DOMException.SYNTAX_ERR,
82+
function_ + " has to use blank as separator if none is used.");
83+
}
84+
7985
next = next.getNextLexicalUnit();
8086
if (next == null) {
8187
throw new DOMException(DOMException.SYNTAX_ERR, function_ + " requires at least three values.");
@@ -90,13 +96,11 @@ public RGBColorImpl(final String function, final LexicalUnit lu) throws DOMExcep
9096
throw new DOMException(DOMException.SYNTAX_ERR, function_ + "b requires at least three values.");
9197
}
9298

93-
if (percentage && LexicalUnitType.PERCENTAGE != next.getLexicalUnitType()) {
94-
throw new DOMException(DOMException.SYNTAX_ERR, function_ + " mixing numbers and percentages.");
95-
}
96-
if (!percentage && LexicalUnitType.PERCENTAGE == next.getLexicalUnitType()) {
97-
throw new DOMException(DOMException.SYNTAX_ERR, function_ + " mixing numbers and percentages.");
98-
}
9999
blue_ = getPart(next);
100+
if (blue_.getLexicalUnitType() == LexicalUnitType.NONE) {
101+
throw new DOMException(DOMException.SYNTAX_ERR,
102+
function_ + " has to use blank as separator if none is used.");
103+
}
100104

101105
next = next.getNextLexicalUnit();
102106
if (next == null) {
@@ -112,19 +116,18 @@ public RGBColorImpl(final String function, final LexicalUnit lu) throws DOMExcep
112116
}
113117

114118
alpha_ = getPart(next);
119+
if (alpha_.getLexicalUnitType() == LexicalUnitType.NONE) {
120+
throw new DOMException(DOMException.SYNTAX_ERR,
121+
function_ + " has to use blank as separator if none is used.");
122+
}
123+
115124
next = next.getNextLexicalUnit();
116125
if (next != null) {
117126
throw new DOMException(DOMException.SYNTAX_ERR, "Too many parameters for " + function_ + " function.");
118127
}
119128
return;
120129
}
121130

122-
if (percentage && LexicalUnitType.PERCENTAGE != next.getLexicalUnitType()) {
123-
throw new DOMException(DOMException.SYNTAX_ERR, function_ + " mixing numbers and percentages.");
124-
}
125-
if (!percentage && LexicalUnitType.PERCENTAGE == next.getLexicalUnitType()) {
126-
throw new DOMException(DOMException.SYNTAX_ERR, function_ + " mixing numbers and percentages.");
127-
}
128131
green_ = getPart(next);
129132
next = next.getNextLexicalUnit();
130133
if (next == null) {
@@ -135,12 +138,6 @@ public RGBColorImpl(final String function, final LexicalUnit lu) throws DOMExcep
135138
function_ + " requires consitent separators (blank or comma).");
136139
}
137140

138-
if (percentage && LexicalUnitType.PERCENTAGE != next.getLexicalUnitType()) {
139-
throw new DOMException(DOMException.SYNTAX_ERR, function_ + " mixing numbers and percentages.");
140-
}
141-
if (!percentage && LexicalUnitType.PERCENTAGE == next.getLexicalUnitType()) {
142-
throw new DOMException(DOMException.SYNTAX_ERR, function_ + " mixing numbers and percentages.");
143-
}
144141
blue_ = getPart(next);
145142
next = next.getNextLexicalUnit();
146143
if (next == null) {
@@ -165,7 +162,8 @@ public RGBColorImpl(final String function, final LexicalUnit lu) throws DOMExcep
165162
private static CSSValueImpl getPart(final LexicalUnit next) {
166163
if (LexicalUnitType.PERCENTAGE == next.getLexicalUnitType()
167164
|| LexicalUnitType.INTEGER == next.getLexicalUnitType()
168-
|| LexicalUnitType.REAL == next.getLexicalUnitType()) {
165+
|| LexicalUnitType.REAL == next.getLexicalUnitType()
166+
|| LexicalUnitType.NONE == next.getLexicalUnitType()) {
169167
return new CSSValueImpl(next, true);
170168
}
171169

src/main/java/org/htmlunit/cssparser/parser/LexicalUnit.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,14 @@ enum LexicalUnitType {
9393
COUNTER_FUNCTION,
9494
/** COUNTERS_FUNCTION. */
9595
COUNTERS_FUNCTION,
96+
9697
/** RGBCOLOR. */
9798
RGBCOLOR,
9899
/** HSLCOLOR. */
99100
HSLCOLOR,
101+
/** NONE. */
102+
NONE,
103+
100104
/** DEGREE. */
101105
DEGREE,
102106
/** GRADIAN. */
@@ -105,6 +109,7 @@ enum LexicalUnitType {
105109
RADIAN,
106110
/** TURN. */
107111
TURN,
112+
108113
/** MILLISECOND. */
109114
MILLISECOND,
110115
/** SECOND. */

src/main/java/org/htmlunit/cssparser/parser/LexicalUnitImpl.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,9 @@ public String getCssText() {
409409
appendParams(sb);
410410
sb.append(")");
411411
break;
412+
case NONE:
413+
sb.append("none");
414+
break;
412415
case IDENT:
413416
sb.append(getStringValue());
414417
break;
@@ -1076,6 +1079,14 @@ public static LexicalUnit createHslColor(final LexicalUnit prev, final String fu
10761079
return new LexicalUnitImpl(prev, LexicalUnitType.HSLCOLOR, funct, params);
10771080
}
10781081

1082+
/**
1083+
* @param prev the previous LexicalUnit
1084+
* @return lexical unit with type rgb color
1085+
*/
1086+
public static LexicalUnit createNone(final LexicalUnit prev) {
1087+
return new LexicalUnitImpl(prev, LexicalUnitType.NONE);
1088+
}
1089+
10791090
/**
10801091
* @param prev the previous LexicalUnit
10811092
* @param params the params

0 commit comments

Comments
 (0)