RFR: 8336097: UserAgent Styles using lookups are promoted to Author level if look-up is defined in Author stylesheet [v2]

John Hendrikx jhendrikx at openjdk.org
Thu Jul 18 11:54:43 UTC 2024


On Wed, 17 Jul 2024 20:38:03 GMT, Andy Goryachev <angorya at openjdk.org> wrote:

> > First, the order from highest to lowest priority is: `INLINE` (using `Node::setStyle`), `AUTHOR` (from user set stylesheets), `USER` (for setters) and then `USER_AGENT` (a stylesheet like Modena set by FX itself).
> 
> What are the priorities between
> 
> * system stylesheet (modena.css) set via `StyleManager.getInstance().setUserAgentStylesheets()`
> * user agent stylesheet added via `Application.setUserAgentStylesheet()`
> * user agent stylesheet added via `Scene.setUserAgentStylesheet()`
> * user agent stylesheet added via `SubScene.setUserAgentStylesheet()`

Here is the order that stylesheets are added to a style map, from how `StyleManager::findMatchingStyles` works.  The order is from lowest to highest precedence:

## Primary user agent stylesheet:

One of these (only one, first one wins):

- `SubScene` user agent stylesheet
- `Scene` user agent stylesheet (**only** if there was no `SubScene` user agent stylesheet)
-  Application user agent stylesheet **only** if there was no `SubScene` or `Scene` user agent stylesheet (in other words, `Scene` and `SubScene` user agent stylesheets will completely replace modena)

## Additional `Region` user agent stylesheet

Regions can provide a user agent stylesheet by overriding `Region::getUserAgentStyleSheet`.  Only one is added, from the nearest parent, and it does **not** replace the primary user agent stylesheet.

## Author stylesheets, from lowest to highest precedence:

- From `Scene`
   - If a Scene has multiple stylesheets, the first/last stylesheet in the list has lowest/highest precedence respectively.
- Then `Parent` stylesheets
   - The least specific parent's stylesheets (closest to the root) have lowest precedence
   - If a Parent has multiple stylesheets, the first/last stylesheet in the list has lowest/highest precedence respectively.

# Style selection

Styles are grouped per style origin, from lowest to highest precedence:

- User Agent
- Author
- Inline

A style from within a higher precedence group will always be applied first.

Styles within the same style origin group will use specificity (how specific the style is) to determine which should be applied first, with the most specific style taking precedence.

If there are styles with the same specificity, then the style from the nearest `Node`, `Parent` or `Scene` takes precedence (this is determined by the order the stylesheets are managed by `StyleManager` explained in the first part).

If there is still a conflict (ie. two styles with the same precedence, both coming from the same `Node`) then the latest stylesheet added takes precedence.

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

PR Comment: https://git.openjdk.org/jfx/pull/1503#issuecomment-2236307850


More information about the openjfx-dev mailing list