Skip to content

Commit

Permalink
Added WebEngine.userStyleSheetLocation property support (empty GWT im…
Browse files Browse the repository at this point in the history
…plementation for now)
  • Loading branch information
salmonb committed Jun 2, 2024
1 parent 17a4d25 commit 8fc1565
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package javafx.scene.web;

import dev.webfx.kit.registry.javafxweb.JavaFxWebRegistry;
import dev.webfx.kit.mapper.peers.javafxweb.engine.WebEnginePeer;
import dev.webfx.kit.registry.javafxweb.JavaFxWebRegistry;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.property.StringProperty;
import javafx.beans.property.StringPropertyBase;
import javafx.concurrent.Worker;
import javafx.event.EventHandler;

Expand Down Expand Up @@ -64,4 +66,35 @@ public Worker<Void> getLoadWorker() {
public Object executeScript(String script) {
return webEnginePeer.executeScript(script);
}

private StringProperty userStyleSheetLocation;

public final void setUserStyleSheetLocation(String value) {
userStyleSheetLocationProperty().set(value);
}

public final String getUserStyleSheetLocation() {
return userStyleSheetLocation == null ? null : userStyleSheetLocation.get();
}

public final StringProperty userStyleSheetLocationProperty() {
if (userStyleSheetLocation == null) {
userStyleSheetLocation = new StringPropertyBase(null) {

@Override public void invalidated() {
webEnginePeer.updateUserStyleSheetLocation(get());
}

@Override public Object getBean() {
return WebEngine.this;
}

@Override public String getName() {
return "userStyleSheetLocation";
}
};
}
return userStyleSheetLocation;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ public interface WebEnginePeer {

Object executeScript(String script);

void updateUserStyleSheetLocation(String userStyleSheetLocation);

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
import dev.webfx.kit.mapper.peers.javafxweb.spi.gwt.HtmlWebViewPeer;
import dev.webfx.kit.util.properties.FXProperties;
import dev.webfx.platform.scheduler.Scheduler;
import elemental2.dom.DomGlobal;
import elemental2.dom.HTMLIFrameElement;
import elemental2.dom.Window;
import elemental2.dom.*;
import javafx.concurrent.Worker;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
Expand All @@ -24,18 +22,26 @@ public GwtWebEnginePeer(WebEngine webEngine) {
FXProperties.runNowAndOnPropertiesChange(e -> updateState(), webView == null ? null : webView.sceneProperty());
}

private Window getScriptWindow() {
Window iFrameWindow = null;
private HTMLIFrameElement getIFrame() {
WebView webView = webEngine.getWebView();
HtmlWebViewPeer peer = webView == null ? null : (HtmlWebViewPeer) webView.getNodePeer();
if (peer != null) {
HTMLIFrameElement iFrame = peer.getIFrame();
if (iFrame != null)
iFrameWindow = iFrame.contentWindow;
}
if (peer != null)
return peer.getIFrame();
return null;
}

private Window getScriptWindow() {
HTMLIFrameElement iFrame = getIFrame();
Window iFrameWindow = iFrame == null ? null : iFrame.contentWindow;
return iFrameWindow != null ? iFrameWindow : DomGlobal.window;
}

private Document getDocument() {
HTMLIFrameElement iFrame = getIFrame();
Document iFrameDocument = iFrame == null ? null : iFrame.contentDocument;
return iFrameDocument != null ? iFrameDocument : DomGlobal.document;
}

private void updateState() {
Window scriptWindow = getScriptWindow();
if (scriptWindow != null)
Expand All @@ -52,4 +58,8 @@ public Object executeScript(String script) {
return GwtJSObject.eval(getScriptWindow(), script);
}

@Override
public void updateUserStyleSheetLocation(String userStyleSheetLocation) {
// TODO
}
}

0 comments on commit 8fc1565

Please sign in to comment.