Skip to content

Commit fc6938c

Browse files
committed
proper handling of system colors from color-4
1 parent c8043c1 commit fc6938c

File tree

5 files changed

+66
-7
lines changed

5 files changed

+66
-7
lines changed

org/w3c/css/parser/Frame.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,21 @@ public void addWarning(String warningMessage, String message) {
106106
new String[]{message}, ac));
107107
}
108108

109+
/**
110+
* Adds a warning to this frame with a message.
111+
*
112+
* @param warningMessage the warning message
113+
* (see org.w3c.css.util.Messages.properties).
114+
* @param param1 An add-on message.
115+
* @param param2 An add-on message.
116+
* @see org.w3c.css.util.Warning
117+
*/
118+
public void addWarning(String warningMessage, String param1, String param2) {
119+
warnings.addWarning(new Warning(getSourceFile(), getLine(),
120+
warningMessage, 0,
121+
new String[]{param1, param2}, ac));
122+
}
123+
109124
/**
110125
* Adds a warning to this frame with a message.
111126
*

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,7 @@ error.onlyATSC: \u201C%s\u201D this function is only for the atsc-tv medium
417417
warning.otherprofile: property \u201C%s\u201D does not exist for this profile, but is validated conforming to another profile
418418
warning.deprecated: The value \u201C%s\u201D is deprecated
419419
warning.deprecatedproperty: The property \u201C%s\u201D is deprecated
420+
warning.deprecated_replacement: The value \u201C%s1\u201D is deprecated, use \u201C%s2\u201D instead
420421

421422
warning.float-no-width: In (x)HTML+CSS, floated elements need to have a width declared. Only elements with an intrinsic width (html, img, input, textarea, select, or object) are not affected
422423

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -432,8 +432,9 @@ error.unrecognized.link: La balise link ou l'instruction de traitement\
432432
xml-stylesheet ne sont pas reconnues.
433433

434434
warning.otherprofile: propriété \u201C%s\u201D n'existe pas dans ce profile mais est validée conforme à un autre profile
435-
warning.deprecated: La valeur '\u201C%s\u201D' est déconseillée
436-
warning.deprecatedproperty: La propriété '\u201C%s\u201D' est déconseillée
435+
warning.deprecated: La valeur \u201C%s\u201D est déconseillée
436+
warning.deprecatedproperty: La propriété \u201C%s\u201D est déconseillée
437+
warning.deprecated_replacement: La valeur \u201C%s\u201D est déconseillée, utilisez plutôt \u201C%s2\u201D
437438

438439
#used by org.w3c.css.parser.analyzer.CssParser
439440
error.nocomb: Le Combinateur de sélecteurs \u201C%s\u201D n'est pas admis dans ce profile ou cette version

org/w3c/css/values/CssColor.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
import org.w3c.css.util.CssVersion;
1212
import org.w3c.css.util.InvalidParamException;
1313

14+
import java.util.Locale;
15+
1416
import static org.w3c.css.values.CssOperator.COMMA;
1517
import static org.w3c.css.values.CssOperator.SPACE;
1618

@@ -645,7 +647,7 @@ public void setShortRGBColor(ApplContext ac, String s)
645647
*/
646648
protected void setIdentColor(ApplContext ac, String s)
647649
throws InvalidParamException {
648-
String lower_s = s.toLowerCase();
650+
String lower_s = s.toLowerCase(Locale.ENGLISH);
649651
switch (ac.getCssVersion()) {
650652
case CSS1:
651653
rgb = CssColorCSS1.getRGB(lower_s);
@@ -692,7 +694,12 @@ protected void setIdentColor(ApplContext ac, String s)
692694
}
693695
color = CssColorCSS3.getSystem(lower_s);
694696
if (color != null) {
695-
ac.getFrame().addWarning("deprecated", s);
697+
break;
698+
}
699+
if (CssColorCSS3.getDeprecatedSystem(lower_s) != null) {
700+
ac.getFrame().addWarning("deprecated_replacement", s, color.toString());
701+
// FIXME should we use the replacement in output style?
702+
color = s;
696703
break;
697704
}
698705
color = CssColorCSS3.getIdentColor(lower_s);

org/w3c/css/values/CssColorCSS3.java

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,16 @@
55
package org.w3c.css.values;
66

77
import java.util.HashMap;
8+
import java.util.Locale;
89

910
/**
1011
* @spec https://www.w3.org/TR/2016/WD-css-color-4-20160705/
1112
*/
1213
public class CssColorCSS3 {
1314
protected static final HashMap<String, RGB> definedRGBColorsCSS3;
15+
protected static final HashMap<String, String> definedSystemColorsCSS3;
16+
protected static final HashMap<String, String> definedDeprecatedSystemColorsCSS3;
17+
1418
private static final RGBA trans;
1519

1620
static final CssIdent currentColor = CssIdent.getIdent("currentColor");
@@ -26,10 +30,12 @@ public static RGBA getRGBA(String ident) {
2630
return null;
2731
}
2832

29-
// those are the same as CSS2, let's use that
30-
// and note that they are deprecated...
3133
public static String getSystem(String ident) {
32-
return CssColorCSS2.definedSystemColorsCSS2.get(ident);
34+
return definedSystemColorsCSS3.get(ident);
35+
}
36+
37+
public static String getDeprecatedSystem(String ident) {
38+
return definedDeprecatedSystemColorsCSS3.get(ident);
3339
}
3440

3541
// special case for currentColor and possible ident-only defined colors.
@@ -193,5 +199,34 @@ public static String getIdentColor(String ident) {
193199
definedRGBColorsCSS3.put("whitesmoke", new RGB(true, 245, 245, 245));
194200
definedRGBColorsCSS3.put("yellow", new RGB(true, 255, 255, 0));
195201
definedRGBColorsCSS3.put("yellowgreen", new RGB(true, 154, 205, 50));
202+
203+
// https://www.w3.org/TR/2021/WD-css-color-4-20210601/#typedef-system-color
204+
definedSystemColorsCSS3 = new HashMap<>();
205+
String[] _system_colors = {"Canvas", "CanvasText", "LinkText", "VisitedText", "ActiveText",
206+
"ButtonFace", "ButtonText", "ButtonBorder", "Field", "FieldText", "Highlight",
207+
"HighlightText", "Mark", "MarkText", "GrayText"};
208+
for (String s : _system_colors) {
209+
definedSystemColorsCSS3.put(s.toLowerCase(Locale.ENGLISH), s);
210+
}
211+
212+
// https://www.w3.org/TR/2021/WD-css-color-4-20210601/#deprecated-system-colors
213+
definedDeprecatedSystemColorsCSS3 = new HashMap<>();
214+
String[] _deprecated_system_colors = {"ActiveBorder", "ActiveCaption", "AppWorkspace",
215+
"Background", "ButtonHighlight", "ButtonShadow", "CaptionText",
216+
"InactiveBorder", "InactiveCaption", "InactiveCaptionText", "InfoBackground",
217+
"InfoText", "Menu", "MenuText", "Scrollbar", "ThreeDDarkShadow",
218+
"ThreeDFace", "ThreeDHighlight", "ThreeDLightShadow", "ThreeDShadow",
219+
"Window", "WindowFrame", "WindowText"};
220+
String[] _deprecated_replacement_colors = {"ButtonBorder", "CanvasText", "Canvas",
221+
"Canvas", "ButtonFace", "ButtonFace", "CanvasText",
222+
"ButtonBorder", "Canvas", "GrayText", "Canvas",
223+
"CanvasText", "Canvas", "CanvasText", "Canvas", "ButtonBorder",
224+
"ButtonFace", "ButtonBorder", "ButtonBorder", "ButtonBorder",
225+
"Canvas", "ButtonBorder", "CanvasText"};
226+
for (int i = 0; i < _deprecated_system_colors.length; i++) {
227+
definedDeprecatedSystemColorsCSS3.put(_deprecated_system_colors[i].toLowerCase(Locale.ENGLISH),
228+
_deprecated_replacement_colors[i]);
229+
}
230+
196231
}
197232
}

0 commit comments

Comments
 (0)