Skip to content
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

8342703: CSS transition is not started when initial value was not specified #1607

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

mstr2
Copy link
Collaborator

@mstr2 mstr2 commented Oct 21, 2024

When the initial value of a styleable property is not specified in a stylesheet, no transition is started:

.button {
    transition: -fx-opacity 1s;
}

.button:hover {
    -fx-opacity: 0.5;
}

The expected behavior is that a transition is started in this case, since the default value of -fx-opacity is 1.

The reason for this bug is that StyleableProperty implementations do not start a CSS transition when the value is applied for the first time. The intention behind this is that a node that is added to the scene graph should not start transitions. CSS transitions should only be started after the node has been shown for the first time.

The logic to detect this situation is currently as follows:

    // If this.origin == null, we're setting the value for the first time.
    // No transition should be started in this case.
    TransitionDefinition transition = this.origin != null && getBean() instanceof Node node ?
        NodeHelper.findTransitionDefinition(node, getCssMetaData()) : null;

However, this does not work. When no initial style is specified in the stylesheet, this.origin will not be set, and thus no transition will be started even after the node has been shown. The new logic works like this:

A Node.initialCssState flag is added. Initially, this is true. Manually calling applyCss or similar methods will not clear this flag, as we consider all manual CSS processing to be part of the "initial CSS state". Only at the end of Scene.doCSSPass will this flag be cleared on all nodes that have expressed their interest. This mechanism ensures that a node will be eligible for CSS transitions only after the following conditions have been satisfied:

  1. The node was added to a scene graph
  2. CSS processing was completed for a scene pulse

/reviewers 2


Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed (2 reviews required, with at least 1 Reviewer, 1 Author)

Issue

  • JDK-8342703: CSS transition is not started when initial value was not specified (Bug - P4)

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jfx.git pull/1607/head:pull/1607
$ git checkout pull/1607

Update a local copy of the PR:
$ git checkout pull/1607
$ git pull https://git.openjdk.org/jfx.git pull/1607/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 1607

View PR using the GUI difftool:
$ git pr show -t 1607

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jfx/pull/1607.diff

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Oct 21, 2024

👋 Welcome back mstrauss! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented Oct 21, 2024

❗ This change is not yet ready to be integrated.
See the Progress checklist in the description for automated requirements.

@openjdk openjdk bot added the rfr Ready for review label Oct 21, 2024
@openjdk
Copy link

openjdk bot commented Oct 21, 2024

@mstr2
The total number of required reviews for this PR (including the jcheck configuration and the last /reviewers command) is now set to 2 (with at least 1 Reviewer, 1 Author).

@mlbridge
Copy link

mlbridge bot commented Oct 21, 2024

Webrevs

@bridgekeeper
Copy link

bridgekeeper bot commented Nov 18, 2024

@mstr2 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!

* is completed. Nodes will use this event to determine whether they are in their initial
* CSS state (see {@link Node#initialCssState}.
*/
private final Set<Node> clearInitialCssStateNodes = Collections.newSetFromMap(new IdentityHashMap<>());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not use a normal HashSet? What advantage has this approach?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HashSet uses Object.equals, which can be overridden by user code, and this would break the logic. It's the instance that wants to be notified.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, I never ever did that for Nodes (and I don't know why I would need to), but you are right, it is indeed possible and therefore a possible scenario.

Copy link
Collaborator

@hjohn hjohn Nov 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is overly cautious. Overriding equals on a class that did not implement equals in a hierarchy you don't control is not a very reasonable scenario. You will not be able to call super.equals with reasonable results if the hierarchy did not implement it in the first place. This is because there may be private data that you can't access for your equality comparison (and Node has lots of that). We also use WeakHashMaps in several areas already with subtypes of Nodes as keys (I found Region, Parent and TreeView being used as keys), so this kind of override should probably be documented as being unsupported on Node.

Perhaps it should even be made final so FX internals can rely on it being correct.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. I think we should make Node.equals() final in this case.

@bridgekeeper
Copy link

bridgekeeper bot commented Dec 23, 2024

@mstr2 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 /open pull request command.

@bridgekeeper bridgekeeper bot closed this Dec 23, 2024
@mstr2
Copy link
Collaborator Author

mstr2 commented Dec 23, 2024

/open

@openjdk openjdk bot reopened this Dec 23, 2024
@openjdk
Copy link

openjdk bot commented Dec 23, 2024

@mstr2 This pull request is now open

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rfr Ready for review
Development

Successfully merging this pull request may close these issues.

4 participants