RFR: 8358450: Viewport characteristics media features [v10]
Andy Goryachev
angorya at openjdk.org
Mon Dec 15 22:32:21 UTC 2025
On Sun, 14 Dec 2025 18:57:50 GMT, Michael Strauß <mstrauss at openjdk.org> wrote:
>> Implementation of [viewport characteristics media features](https://www.w3.org/TR/mediaqueries-5/#mf-viewport-characteristics):
>> * `width`
>> * `height`
>> * `aspect-ratio`: width / height
>> * `orientation`: `portrait`, `landscape`
>> * `display-mode`: `fullscreen`, `standalone` (note: `browser` and `minimal-ui` are not supported in JavaFX)
>>
>> Here's a small example how the new media features can be used:
>>
>> @Override
>> public void start(Stage stage) {
>> var button = new Button("Toggle full-screen");
>> button.setOnAction(_ -> stage.setFullScreen(!stage.isFullScreen()));
>> var label = new Label();
>> var root = new BorderPane(button, null, null, label, null);
>> var scene = new Scene(root, 650, 200);
>> BorderPane.setAlignment(label, Pos.CENTER);
>> label.textProperty().bind(scene.widthProperty().map(v -> String.format("Width: %.2f", v.doubleValue())));
>> scene.getStylesheets().add("data:text/css;base64," + Base64.getEncoder().encodeToString("""
>> @media (max-width: 500) {
>> .button {
>> -fx-background-color: red;
>> }
>> }
>>
>> @media (600 < width <= 700) {
>> .button {
>> -fx-background-color: green;
>> }
>> }
>>
>> @media (min-width: 800) {
>> .button {
>> -fx-background-color: yellow;
>> }
>> }
>>
>> @media (display-mode: fullscreen) {
>> .button {
>> -fx-background-color: black !important;
>> }
>> }
>> """.getBytes(StandardCharsets.UTF_8)));
>>
>> stage.initStyle(StageStyle.DECORATED);
>> stage.setScene(scene);
>> stage.show();
>> }
>
> Michael Strauß has updated the pull request with a new target base due to a merge or a rebase. The pull request now contains 14 commits:
>
> - Merge branch 'master' into feature/media-features-viewport-characteristics
> - resolve merge conflicts
> - Merge branch 'master' into feature/media-features-viewport-characteristics
>
> # Conflicts:
> # modules/javafx.graphics/src/test/java/test/javafx/css/CssParser_mediaQuery_Test.java
> - update cssref.html
> - Merge branch 'master' into feature/media-features-viewport-characteristics
> - whitespace, add final modifier
> - Merge branch 'master' into feature/media-features-viewport-characteristics
> - Refactor context awareness
> - Merge branch 'master' into feature/media-features-viewport-characteristics
> - Merge branch 'master' into feature/media-features-viewport-characteristics
> - ... and 4 more: https://git.openjdk.org/jfx/compare/32e667df...19cdaeaa
modules/javafx.graphics/src/main/java/com/sun/javafx/css/media/MediaFeatures.java line 229:
> 227: for (int i = 0; i < lowerCaseText.length(); i++) {
> 228: if (!Character.isDigit(lowerCaseText.charAt(i))) {
> 229: unitIndex = i;
I think this is the place where the parser fails with fractional numbers...
-------------
PR Review Comment: https://git.openjdk.org/jfx/pull/1844#discussion_r2621072700
More information about the openjfx-dev
mailing list