On Fri, 13 Mar 2026 18:26:20 GMT, Michael Strauß <[email protected]> wrote:
>> The [`@import`](https://www.w3.org/TR/css-cascade-5/#at-import) rule is >> extended to support conditional stylesheet imports: >> >> >> @import [ <url> | <string> ] <media-query-list>? ; >> >> >> Conceptually, a conditional import takes all rules of the referenced >> stylesheet, literally includes them at the location of the `@import` rule, >> and surrounds them with a `@media` rule with the specified >> `<media-query-list>`. >> >> The implementation of this feature extends media queries with a context-free >> evaluation function: >> >> interface MediaQuery { >> TriState evaluate(); // returns TRUE / FALSE / UNKNOWN >> } >> >> >> This mode of evaluation uses Kleene's strong trivalent logic to determine >> whether the media query will always match (it's a tautology), will never >> match (it's a contradiction), or whether it depends on the context or we >> simply don't know. >> >> Using this mechanism, a conditional stylesheet import that can never match >> will be skipped at runtime. Similarly, a conditional stylesheet import that >> will always match doesn't need the `<media-query-list>` at all; its rules >> will be pasted verbatim into the main stylesheet. >> >> Note that this mechanism is _not_ meant to be a full-blown theorem solver. >> It won't detect that, for example, the following import conditions will >> always match: >> >> @import url("stylesheet.css") (width > 1000) or (width <= 1000); >> >> >> Its purpose is an optimization for "obvious" cases. For example, at the >> moment the built-in themes use hard-coded conditions to include user-agent >> stylesheets at runtime: >> >> // in PlatformImpl.java: >> if (isSupported(ConditionalFeature.INPUT_TOUCH)) { >> >> uaStylesheets.add("com/sun/javafx/scene/control/skin/modena/touch.css"); >> } >> >> In the future, we might have a way to test for `ConditionalFeature` flags >> that achieves the same thing, but with a public API available to all theme >> authors: >> >> @import url("com/sun/javafx/scene/control/skin/modena/touch.css") >> (-fx-supports-conditional-feature: input-touch); > > Michael Strauß has updated the pull request with a new target base due to a > merge or a rebase. The pull request now contains eight commits: > > - Merge branch 'master' into feature/conditional-import > > # Conflicts: > # modules/javafx.graphics/src/main/java/javafx/css/CssParser.java > - javadoc change > - javadoc change > - specify capacity of MediaQueryList > - javadoc change > - Merge branch 'master' into feature/conditional-import > - Merge branch 'master' into feature/conditional-import > - Conditional stylesheet imports modules/javafx.graphics/src/main/java/com/sun/javafx/css/media/MediaFeatures.java line 45: > 43: > 44: // Extension point for unit tests to add media features > 45: public static BiFunction<String, Token, MediaQuery> DEFAULT = > (featureName, _) -> { So if I understand correctly, this is only needed for Unit tests? Is there any other way we can test this without having a `public static` variable? modules/javafx.graphics/src/main/java/javafx/css/Stylesheet.java line 315: > 313: private void readBinaryImports(int bssVersion, DataInputStream is, > String[] strings) throws IOException { > 314: for (int i = 0, max = is.readInt(); i < max; i++) { > 315: int queryCount = is.readInt(); This can be replaced by: var importConditions = MediaQueryList.readBinary(is, strings); Is the same code as far as I can see. modules/javafx.graphics/src/main/java/javafx/css/Stylesheet.java line 327: > 325: stylesheet.readBinary(bssVersion, is, strings); > 326: addStylesheetImport(new StylesheetImport(stylesheet, > importConditions)); > 327: } else if (is.skip(stylesheetSizeInBytes) != > stylesheetSizeInBytes) { The javadoc here states: ` The skip method may, for a variety of reasons, end up skipping over some smaller number of bytes, possibly 0. The actual number of bytes skipped is returned. ` Can that be a problem here (Never used BSS, so I'm not sure) ------------- PR Review Comment: https://git.openjdk.org/jfx/pull/2031#discussion_r2937363946 PR Review Comment: https://git.openjdk.org/jfx/pull/2031#discussion_r2937358960 PR Review Comment: https://git.openjdk.org/jfx/pull/2031#discussion_r2937361812
