On Wed, 15 Jul 2026 09:54:42 GMT, Florian Kirmaier <[email protected]> 
wrote:

> ### Fix
> The PR replaces applyCss() with reapplyCSS in the nodeOrientation code of 
> Scene.
> applyCss() reapplied styles eagerly - and didn't rebuild the "style maps" 
> resulting in wrong css.
> reapplyCSS() rematches correctly - and also defers it to the next pulse.
> 
> I've added a unit test to: Node_effectiveOrientation_Css_Test.
> 
> ### Test improvements
> Because the whole test class was disabled, I've also investigated which tests 
> are working - and reenabled the working tests.
> This PR also fixes 2 of the previously failing tests in 
> Node_effectiveOrientation_Css_Test - which are now enabled.
> 
> Which are the following tests:
> 
> Node_effectiveOrientation_Css_Test.test_dir_pseudoClass_functions_on_scene_effective_orientation_not_node
> Node_effectiveOrientation_Css_Test.test_SimpleSelector_dir_pseudoClass_with_scene_effective_orientation_rtl
> 
> 
> 
> 
> 
> 
> ---------
> - [x] I confirm that I make this contribution in accordance with the [OpenJDK 
> Interim AI Policy](https://openjdk.org/legal/ai).

> When I change:
> 
> ```java
>        Stylesheet stylesheet = new CssParser().parse(
>                 ".root:dir(rtl) .rect { -fx-fill: #ff0000; }" +
>                 ".root:dir(ltr) .rect { -fx-fill: #00ff00; }" +
>                 ".root .rect { -fx-fill: #0000ff; }"
>         );
> ```
> 
> to:
> 
> ```java
>         Stylesheet stylesheet = new CssParser().parse(
>                 ".root .rect { -fx-fill: #0000ff; }" +
>                 ".root .rect:dir(rtl) { -fx-fill: #ff0000; }" +
>                 ".root .rect:dir(ltr) { -fx-fill: #00ff00; }"
>         );
> ```
> 
> all tests are green.
> 
> In CSS, the order matters. Although the CSS specification documents that the 
> [specifity](https://www.w3.org/TR/selectors-4/#specificity-rules) should be 
> higher with a pseudoclass (so in this case, the order should NOT matter). So 
> JavaFX is not following the CSS specification here, but might be intended 
> (although weird - I would say this is a bug).

I don't know, specificity is encoded a bit weird (only 4 bits, and doesn't 
guard overflows) in `Match`, and is lacking specificity for types (but perhaps 
FX handles this elsewhere).  However, specifically for node orientation, there 
is some exception being made, so perhaps that has something to do with what 
you're seeing?


    Match(final Selector selector, Set<PseudoClass> pseudoClasses, int idCount, 
int styleClassCount) {
        Objects.requireNonNull(selector);
        Objects.requireNonNull(pseudoClasses);

        this.selector = selector;
        this.idCount = idCount;
        this.styleClassCount = styleClassCount;
        this.pseudoClasses = ImmutablePseudoClassSetsCache.of(pseudoClasses);
        int nPseudoClasses = pseudoClasses.size();
        if (selector instanceof SimpleSelector simple) {
            if (simple.getNodeOrientation() != INHERIT) {
                nPseudoClasses += 1;
            }
        }
        specificity = (idCount << 8) | (styleClassCount << 4) | nPseudoClasses;
    }

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

PR Comment: https://git.openjdk.org/jfx/pull/2213#issuecomment-5064535155

Reply via email to