-
Notifications
You must be signed in to change notification settings - Fork 521
8350917: Allow parent nodes to provide CSS styleable properties for child nodes #1714
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
base: master
Are you sure you want to change the base?
Conversation
👋 Welcome back jhendrikx! A progress list of the required criteria for merging this PR into |
❗ This change is not yet ready to be integrated. |
ff29324
to
e80c611
Compare
@mstr2 / Dirk Lemmermann : This is a proof of concept PR for parent provided properties. I've adapted HBox / VBox only in this PR, and I probably need to update the CSS documentation still. I've opted to leave out the static HBox / VBox method to get these as a property (ie.
|
e80c611
to
38e77a9
Compare
@hjohn Please do not rebase or force-push to an active PR as it invalidates existing review comments. Note for future reference, the bots always squash all changes into a single commit automatically as part of the integration. See OpenJDK Developers’ Guide for more information. |
/reviewer 2 reviewers |
@kevinrushforth Only the author (@hjohn) is allowed to issue the |
@kevinrushforth has indicated that a compatibility and specification (CSR) request is needed for this pull request. @hjohn please create a CSR request for issue JDK-8350917 with the correct fix version. This pull request cannot be integrated until the CSR request is approved. |
/reviewer 2 reviewers |
That's weird isn't it? |
@hjohn Syntax:
|
/reviewers 2 reviewers |
Well, oops.
No, it was my mistake. There are two different Skara commands with two different meanings and very similar spelling:
I meant the first one. I accidentally typed the second. |
@mstr2 could you have a look? |
@@ -461,6 +462,8 @@ private StyleMap getStyleMap(Styleable styleable) { | |||
private boolean forceSlowpath = false; | |||
} | |||
|
|||
private record StylingContext(Node node, CalculatedValue font, StyleMap styleMap, Set<PseudoClass> pseudoClasses) {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might not be a good trade-off to create lots of transient objects on a hot path just to save a few arguments in the calling convention. This would be a nice improvement once we have value types in Java.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I checked this before hand, there is quite a bit more going on in creating the cache keys (see getTransitionStates
), and I think this extra object will therefore be lost in the noise.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still think that it doesn’t carry its weight (bundling up private method arguments in the same translation unit is not a big win). It will increase churn on the GC, even if slightly, and many of these decisions taken together may cause it to run more often or earlier.
* Note: this method does not provide CSS meta data for <b>this</b> Styleable, | ||
* only for its direct children! | ||
* | ||
* @return an immutable list of CSS meta data, never {@code null} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we don't specify that getCssMetaData()
should never return null, we should consider also not specifying it here. Alternatively, maybe we should add the non-null requirement to the existing getCssMetaData()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That might be a good idea, as there are several places in CssStyleHelper
where getCssMetaData
is assumed to be non-null already (and also a few locations where it is assumed it can be null
). In other words, if the function would return null
, FX would break currently.
For example, recalculateRelativeSizeProperties
will do:
final List<CssMetaData<? extends Styleable, ?>> styleables = node.getCssMetaData();
final int numStyleables = styleables.size();
Which would be an NPE.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think then you can do this as part of this PR, since you’re already touching the Styleable
interface.
name = name.substring(4); | ||
} | ||
|
||
String propertyName = name + " (parent property)"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think a more sensible naming scheme would be something like "VBox.margin", which should be supplied as an argument and not generated on the fly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can change that to whatever you like. Be aware this is only for the toString
(both getBean
and getName
are optional methods to implement).
|
||
@SuppressWarnings("unchecked") | ||
StyleableObjectProperty<T> castProperty = (StyleableObjectProperty<T>) child.getProperties() | ||
.computeIfAbsent(cssMetaData, k -> createChildConstraintProperty(child, cssMetaData)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we're on a hot path here, I'd like to see this work without unnecessary memory allocations:
- Check
hasProperties()
before callinggetProperties()
. - Don't use
computeIfAbsent()
since it requires a capturing lambda.
return castProperty.getValue(); | ||
} | ||
|
||
if (value != null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How would the value ever be anything other than a StyleableObjectProperty
, since setChildConstraint()
always creates a StyleableObjectProperty
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, this is not handled well. It was intended to mimic a standard value with the property being created (like the lazy property pattern), but it doesn't work here.
In theory, as the property map is public, one could set the key to something else (not easily mind you, you'd need to iterate to find the keys as they're no longer predictable String
s). So, I'll remove this code, and just ignore any bad value and proceed with returning the default value.
Your approach for this enhancement looks good. Do you plan to add styleable properties for the other layout containers too? |
I would like to, I was thinking of doing that in a separate PR as there are quite a few (and I think they would need documentation as well). I think there's |
@hjohn 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! |
@hjohn 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 |
This would also address https://bugs.openjdk.org/browse/JDK-8092347 |
/open |
@hjohn This pull request is now open |
Progress
Error
Issue
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jfx.git pull/1714/head:pull/1714
$ git checkout pull/1714
Update a local copy of the PR:
$ git checkout pull/1714
$ git pull https://git.openjdk.org/jfx.git pull/1714/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 1714
View PR using the GUI difftool:
$ git pr show -t 1714
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jfx/pull/1714.diff
Using Webrev
Link to Webrev Comment