From 956fffd39e18a79405c6ddf113fc11944de32bf9 Mon Sep 17 00:00:00 2001 From: Bruno Salmon Date: Sun, 2 Jun 2024 10:42:35 +0100 Subject: [PATCH] Added WebView.pageFill property support --- .../main/java/javafx/scene/web/WebView.java | 24 +++++++++++++++---- .../spi/gwt/EmulWebViewPeerBase.java | 6 +++-- .../spi/gwt/EmulWebViewPeerMixin.java | 3 +++ .../javafxweb/spi/gwt/HtmlWebViewPeer.java | 7 ++++++ 4 files changed, 34 insertions(+), 6 deletions(-) diff --git a/webfx-kit/webfx-kit-javafxweb-emul/src/main/java/javafx/scene/web/WebView.java b/webfx-kit/webfx-kit-javafxweb-emul/src/main/java/javafx/scene/web/WebView.java index 6fd4731f4..7998fad79 100644 --- a/webfx-kit/webfx-kit-javafxweb-emul/src/main/java/javafx/scene/web/WebView.java +++ b/webfx-kit/webfx-kit-javafxweb-emul/src/main/java/javafx/scene/web/WebView.java @@ -3,11 +3,9 @@ import com.sun.javafx.geom.BaseBounds; import com.sun.javafx.geom.transform.BaseTransform; import dev.webfx.kit.registry.javafxweb.JavaFxWebRegistry; -import javafx.beans.property.DoubleProperty; -import javafx.beans.property.SimpleDoubleProperty; -import javafx.beans.property.SimpleStringProperty; -import javafx.beans.property.StringProperty; +import javafx.beans.property.*; import javafx.scene.Parent; +import javafx.scene.paint.Color; /** * @author Bruno Salmon @@ -20,6 +18,7 @@ public class WebView extends Parent { private static final double DEFAULT_PREF_HEIGHT = 600; private static final double DEFAULT_MAX_WIDTH = Double.MAX_VALUE; private static final double DEFAULT_MAX_HEIGHT = Double.MAX_VALUE; + private static final Color DEFAULT_PAGE_FILL = Color.WHITE; private final WebEngine engine = new WebEngine(this); @@ -437,6 +436,23 @@ public BaseBounds impl_computeGeomBounds(BaseBounds bounds, BaseTransform tx) { return bounds.deriveWithNewBounds(0, 0, 0, (float) getWidth(), (float) getHeight(), 0); } + private ObjectProperty pageFill; + + public final void setPageFill(Color value) { + pageFillProperty().set(value); + } + + public final Color getPageFill() { + return pageFill == null ? DEFAULT_PAGE_FILL : pageFill.get(); + } + + public final ObjectProperty pageFillProperty() { + if (pageFill == null) { + pageFill = new SimpleObjectProperty<>(DEFAULT_PAGE_FILL); + } + return pageFill; + } + static { JavaFxWebRegistry.registerWebView(); } diff --git a/webfx-kit/webfx-kit-javafxweb-peers-gwt-j2cl/src/main/java/dev/webfx/kit/mapper/peers/javafxweb/spi/gwt/EmulWebViewPeerBase.java b/webfx-kit/webfx-kit-javafxweb-peers-gwt-j2cl/src/main/java/dev/webfx/kit/mapper/peers/javafxweb/spi/gwt/EmulWebViewPeerBase.java index 65cfd9935..2a5da9335 100644 --- a/webfx-kit/webfx-kit-javafxweb-peers-gwt-j2cl/src/main/java/dev/webfx/kit/mapper/peers/javafxweb/spi/gwt/EmulWebViewPeerBase.java +++ b/webfx-kit/webfx-kit-javafxweb-peers-gwt-j2cl/src/main/java/dev/webfx/kit/mapper/peers/javafxweb/spi/gwt/EmulWebViewPeerBase.java @@ -18,14 +18,16 @@ public void bind(N node, SceneRequester sceneRequester) { requestUpdateOnPropertiesChange(sceneRequester , node.urlProperty() , node.loadContentProperty() + , node.pageFillProperty() ); } @Override public boolean updateProperty(ObservableValue changedProperty) { return super.updateProperty(changedProperty) - || updateProperty(node.urlProperty(), changedProperty, mixin::updateUrl) - || updateProperty(node.loadContentProperty(), changedProperty, mixin::updateLoadContent) + || updateProperty(node.urlProperty(), changedProperty, mixin::updateUrl) + || updateProperty(node.loadContentProperty(), changedProperty, mixin::updateLoadContent) + || updateProperty(node.pageFillProperty(), changedProperty, mixin::updatePageFill) ; } diff --git a/webfx-kit/webfx-kit-javafxweb-peers-gwt-j2cl/src/main/java/dev/webfx/kit/mapper/peers/javafxweb/spi/gwt/EmulWebViewPeerMixin.java b/webfx-kit/webfx-kit-javafxweb-peers-gwt-j2cl/src/main/java/dev/webfx/kit/mapper/peers/javafxweb/spi/gwt/EmulWebViewPeerMixin.java index ba01a644a..3321ad276 100644 --- a/webfx-kit/webfx-kit-javafxweb-peers-gwt-j2cl/src/main/java/dev/webfx/kit/mapper/peers/javafxweb/spi/gwt/EmulWebViewPeerMixin.java +++ b/webfx-kit/webfx-kit-javafxweb-peers-gwt-j2cl/src/main/java/dev/webfx/kit/mapper/peers/javafxweb/spi/gwt/EmulWebViewPeerMixin.java @@ -1,6 +1,7 @@ package dev.webfx.kit.mapper.peers.javafxweb.spi.gwt; import dev.webfx.kit.mapper.peers.javafxweb.base.WebViewPeerMixin; +import javafx.scene.paint.Color; import javafx.scene.web.WebView; public interface EmulWebViewPeerMixin @@ -10,4 +11,6 @@ public interface EmulWebViewPeerMixin void updateUrl(String url); void updateLoadContent(String content); + + void updatePageFill(Color pageFill); } diff --git a/webfx-kit/webfx-kit-javafxweb-peers-gwt-j2cl/src/main/java/dev/webfx/kit/mapper/peers/javafxweb/spi/gwt/HtmlWebViewPeer.java b/webfx-kit/webfx-kit-javafxweb-peers-gwt-j2cl/src/main/java/dev/webfx/kit/mapper/peers/javafxweb/spi/gwt/HtmlWebViewPeer.java index d671eaab0..22b21d44a 100644 --- a/webfx-kit/webfx-kit-javafxweb-peers-gwt-j2cl/src/main/java/dev/webfx/kit/mapper/peers/javafxweb/spi/gwt/HtmlWebViewPeer.java +++ b/webfx-kit/webfx-kit-javafxweb-peers-gwt-j2cl/src/main/java/dev/webfx/kit/mapper/peers/javafxweb/spi/gwt/HtmlWebViewPeer.java @@ -2,6 +2,7 @@ import dev.webfx.kit.mapper.peers.javafxgraphics.HasNoChildrenPeers; import dev.webfx.kit.mapper.peers.javafxgraphics.gwtj2cl.html.HtmlNodePeer; +import dev.webfx.kit.mapper.peers.javafxgraphics.gwtj2cl.util.HtmlPaints; import dev.webfx.kit.mapper.peers.javafxgraphics.gwtj2cl.util.HtmlUtil; import dev.webfx.platform.util.Strings; import elemental2.dom.CSSProperties; @@ -9,6 +10,7 @@ import elemental2.dom.HTMLElement; import elemental2.dom.HTMLIFrameElement; import javafx.event.EventHandler; +import javafx.scene.paint.Color; import javafx.scene.web.WebErrorEvent; import javafx.scene.web.WebView; @@ -130,4 +132,9 @@ public void updateLoadContent(String content) { if (content != null) iFrame.srcdoc = content; } + + @Override + public void updatePageFill(Color pageFill) { + HtmlUtil.setStyleAttribute(iFrame, "background", HtmlPaints.toCssColor(pageFill)); + } }