Skip to content

Commit

Permalink
Added WebView.pageFill property support
Browse files Browse the repository at this point in the history
  • Loading branch information
salmonb committed Jun 2, 2024
1 parent 8fc1565 commit 956fffd
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);

Expand Down Expand Up @@ -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<Color> 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<Color> pageFillProperty() {
if (pageFill == null) {
pageFill = new SimpleObjectProperty<>(DEFAULT_PAGE_FILL);
}
return pageFill;
}

static {
JavaFxWebRegistry.registerWebView();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -10,4 +11,6 @@ public interface EmulWebViewPeerMixin
void updateUrl(String url);

void updateLoadContent(String content);

void updatePageFill(Color pageFill);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

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;
import elemental2.dom.DomGlobal;
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;

Expand Down Expand Up @@ -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));
}
}

0 comments on commit 956fffd

Please sign in to comment.