-
Notifications
You must be signed in to change notification settings - Fork 6.2k
JDK-8292276 : Add named colors from CSS Color Module Level 4 #9825
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JDK-8292276 : Add named colors from CSS Color Module Level 4 #9825
Conversation
|
👋 Welcome back scientificware! A progress list of the required criteria for merging this PR into |
|
@scientificware The following label will be automatically applied to this pull request:
When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command. |
|
First and foremost, you need to add JBS id 8292276 into the PR title. Also, please add a jtreg testcase which should fail before your fix and pass after.I guess JBS has a reproducer which can be made into a jtreg testcase, of which you can see several examples in jdk/test/javax/swing directory. |
CSS Color Module Level 4 W3C Candidate Recommendation Snapshot, 5 July 2022 [7.1 Named Colors](https://www.w3.org/TR/css-color-4/#named-color) - Updates, Copyright year. - Adds relative imports. - Replaces, if ... then ... else statements with a Map called "colorNamed". Code is more readable and easy to maintain. After tests, TreeMap seems slower than Map. Results are available at #12 (comment). Warning : The Previous JDK CSS Orange Color is different from CSS Color Recommendation.
|
Hey there. The current implementation creates a new To get around this, you can do One thing I'd request is to have static Color stringToColor(String str) {
if (str == null) {
return null;
} else if (str.length() == 0) {
return Color.black;
} else if (str.startsWith("rgb(")) {
return parseRGB(str);
} else if (str.startsWith("rgba(")) {
return parseRGBA(str);
} else if (str.charAt(0) == '#') {
return hexToColor(str);
} else if (colorNamed.containsKey(str.toLowerCase(Locale.ROOT))) {
return colorNamed.get(str.toLowerCase(Locale.ROOT));
} else {
return hexToColor(str);
}
}In general, good PR. I'd be interested to know the perf results when the behavior is unchanged, and if the enhanced switch would win out. |
|
@SWinxy Thanks for comments.
~~All color declarations are ready. ~~
I think, I misinterpreted your message ! But could you tell me witch method you prefer, I wrote 4 for tests at scientificware#12
|
This concern only named Colors. For RGB and Hex, the code is the same than I think there is no change.
|
Adds a jtreg test case that fails before JDK-8292276 patch and passes after. Test the Cyan color name. Cyan is the missing color name that originates the PR JDK8292276 : Missing Color NamesIn CSS. Cyan name, as most color names Colors defined in CSS Color Module Level 4, is not referenced in CSS.java. This test fails, if getAttribute doesn't return a cyan Color Object. When a color name is missing getAttribute returns a black Color Object.
|
That's a bit sus for the enhanced switch statement to be significantly slower (7.5x more time than the map). Your methodology still shows that you aren't creating new objects for each invocation and returning the same objects each time. Is that accurate to your performance table? |
|
Yes @SWinxy, you're right. Map and TreeMap implementations return the same object. Therefore comparisons with the current implemention or switch case solution are not relevant. I going to add a test result with Map + your workaround. Presently, the switch case solution is the best in respect of the current behaviors you want to preserve. I integrated all your comments but yesterday, I was busy with the test case and other propositions that could content you. I take time to found the best solution because there are other places in swing html package where such optimisation would be interresting, especially in view factories. |
|
@SWinxy All my apologies, I skipped testing CASE + RGB implementation. I posted it but not tested (previous results were about CASE + Hex.
All the stringToColor codes are available, feel free to make a test. |
|
I mean I think I would prefer the switch over a map (it looks nicer to me). My crude tests showed that the switch is indeed slower, breaking my conception that switch statements are the peak of performance. Other than this request, I have no further comments. |
|
@SWinxy Thanks for your reviews and confirmation tests. |
- by correcting orange definition,
- by adding 132 missing color names,
- including transparent keyword
- but excluding currentcolor keyword.
- by treating RGB and Hex notations in insensitive case mode.
This commit modifies stringToColor method which has no modifier, so only usages are limited to :
- its Class.
- The inner Class ColorValue also without modifier uses it through the method to return the Color Object
- its Package.
- stringToColor is also used by javax.swing.text.html.StyleSheet stringToColor method to publicly return the Color Object.
- conclusion : since Color Object is publicly exposed, one can't change method behavior. This preventing to return a constant Color excepted for the existing String.isEmpty argument.
Refactoring resolving color value and align it with 5.7. Resolving Values Values) will be treated in another PR. Extends JDK-8149631 rgb(...) CSS color values are not parsed properly.
Un caractère de retour à la ligne s'est immiscer dans le nom du dossier.
|
Swing supports CSS1 only, it defines color names for 16 colors:
Would the addition of color names from CSS4 give a wrong impression that Swing implements CSS4? |
|
Hmm .. % java MissingColorNames |
|
The test fails because the content of JDK-8294090 #15262 has not been merged into this PR. |
|
Actually, JDK-8294090 #15262 successfully parses expressions like |
- Add specification block tag. StyleSheet.java : - Add specification block tag.
|
@scientificware This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration! |
|
@scientificware This pull request has been inactive for more than 8 weeks and will now be automatically closed. If you would like to continue working on this pull request in the future, feel free to reopen it! This can be done using the |
Adds Chapter Titles to links. StyleSheet.java : Adds Chapter Titles to links.
getColorComponent(String string, byte[] index) : - Adds missing whitespaces. - Disables last changes.
|
/open |
|
@scientificware This pull request is now open |
|
❗ This change is not yet ready to be integrated. |
|
Test Passed with JDK master patchedTest failed with JDK 23.0.1 |
|
@scientificware This pull request has been inactive for more than 8 weeks and will be automatically closed if another 8 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration! |
|
Still a work in progress. |
It's not a big issue if the PR gets closed. You'll be able to open it again once you're ready with your changes. |
|
@aivanov-jdk It's just a reminder for me. I thought that in draft mode, comments are not propagated. |
I didn't noticed the PR was in the Draft state. You're right, the comments aren't sent for the PRs in draft state to the mailing lists. Yet all the comments will be sent to the mailing list after you make the PR ready to review. GitHub sends notifications to everyone who participated in the PR discussion, it does so even for draft PRs. (I usually track updates to PRs that I review using these direct emails that's sent by GitHub.)
If you like to add comments as a reminder to yourself, I see no problem with it… However, take into account that all the PR comments will be sent to the mailing list. |
|
@scientificware This pull request has been inactive for more than 8 weeks and will be automatically closed if another 8 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration! |
|
@scientificware This pull request has been inactive for more than 16 weeks and will now be automatically closed. If you would like to continue working on this pull request in the future, feel free to reopen it! This can be done using the |
This is referenced in Java Bug Database as
This is tracked in JBS as
JDK-8292276 : Add named colors from CSS Color Module Level 4
Now includes old pull requests:
<rgb()>and<rgba()>function behavioursAdds missing color names.
Aligns the CSS <rgb()> and <rgba()> function behaviours.
Adds the 4 and 8 digits color hex notations to CSS.java.
As defined and described by CSS Color Module Level 4, in CSS.java :
#RRGGBB<Color>syntaxDesigned from : ScientificWare JDK-8292276 : Add named colors from CSS Color Module Level 4
Progress
Issues
Reviewing
Using
gitCheckout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/9825/head:pull/9825$ git checkout pull/9825Update a local copy of the PR:
$ git checkout pull/9825$ git pull https://git.openjdk.org/jdk.git pull/9825/headUsing Skara CLI tools
Checkout this PR locally:
$ git pr checkout 9825View PR using the GUI difftool:
$ git pr show -t 9825Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/9825.diff
Using Webrev
Link to Webrev Comment