On Mon, 17 May 2021 08:30:26 GMT, Ambarish Rapte <ara...@openjdk.org> wrote:

> Issue:
> When css file is added to a `Scene.getStylesheets()` of a Scene which has few 
> controls in addition to a Label then css style of a different control gets 
> applied to Label after Stage is hidden and shown. This is a regression of 
> [JDK-8204568](https://bugs.openjdk.java.net/browse/JDK-8204568).
> 
> The sample program attached to JBS adds a Label, Button, CheckBox and another 
> Label to Scene. The css style of the Button gets applied to second Label 
> after Stage is hidden and shown.
> 
> Fix: Do not `recalculateRelativeSizeProperties()` when 
> `resetToInitialValues()` is in progress.
> After Stage is hidden and shown, the css style is reset to initial value in 
> method `resetToInitialValues()`, which resets the font size of a Control to 
> default font size. This reset results in execution of method 
> `recalculateRelativeSizeProperties()` that was added as part of fix for 
> JDK-8204568. `recalculateRelativeSizeProperties()` uses `getStyleMap()` to 
> get `StyleMap` of the node. In this case `getStyleMap()` returns an incorrect 
> `StyleMap` as the reset is still in progress. 
> 
> A comment is added in this fix to explain how the StyleMap is stored and 
> retrieved.
> Added a system test which fails before and passes after this fix.

Looks good to me, tested the proposed patch, and it works as expected.
Just added two minor comments.

modules/javafx.graphics/src/main/java/javafx/scene/CssStyleHelper.java line 456:

> 454:     }
> 455: 
> 456:     private boolean resetInProgress = false;

Add a new line?

modules/javafx.graphics/src/main/java/javafx/scene/CssStyleHelper.java line 607:

> 605:             //    CssStyleHelper.CacheContainer.smapId as key.
> 606:             //    So, when resetToInitialValues() is in progress: the 
> StyleManager.styleMapList gets updated
> 607:             //    and getStyleMap(node) may return an incorrect StyleMap 
> for a given node.

Probably a better wording could be:

//    When resetToInitialValues() is in progress, the StyleManager.styleMapList 
gets updated, therefore
//    calls to getStyleMap(node) should be avoided, as it may return an 
incorrect StyleMap for a given node.

-------------

PR: https://git.openjdk.java.net/jfx/pull/504

Reply via email to