Skip to content

Commit

Permalink
Merge pull request #35 from kadampabookings/staging
Browse files Browse the repository at this point in the history
July work
  • Loading branch information
salmonb authored Jul 20, 2024
2 parents ba28727 + 2f2ede1 commit 8f0c16a
Show file tree
Hide file tree
Showing 16 changed files with 353 additions and 160 deletions.
1 change: 0 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
</repository>
</repositories>


<build>
<pluginManagement>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,8 @@ public static void fireEvent(EventTarget eventTarget, Event event) {
// back to the browser even if it has been consumed by JavaFX. This is the purpose of the propagateToPeerEvent field.
private static Event propagateToPeerEvent;

// This setter can be called by the control (or behaviour) that consumed the event in JavaFX to request WebFX to
// not stop its propagation, but pass it to the peer.
// This setter is called by TextInputControl that consumed an event in JavaFX (to stop its propagation in JavaFX),
// but still requests WebFX to pass the event to the html peer to solve the case explained above.
public static void setPropagateToPeerEvent(Event propagateToPeerEvent) {
Event.propagateToPeerEvent = propagateToPeerEvent;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package com.sun.javafx.scene.control.behavior;

import javafx.event.Event;
import javafx.scene.control.TextInputControl;
import javafx.scene.input.KeyEvent;

import java.util.List;

Expand All @@ -23,22 +21,6 @@ public abstract class TextInputControlBehavior<T extends TextInputControl> exten
*/
public TextInputControlBehavior(T textInputControl, List<KeyBinding> bindings) {
super(textInputControl, bindings);
// Although the key events are entirely managed by the peer, we consume them in JavaFX to not propagate these
// events to further JavaFX controls.
textInputControl.addEventHandler(KeyEvent.ANY, e -> {
if (textInputControl.isFocused()) {
// Exception is made for accelerators such as Enter or ESC, as they should be passed beyond this control
switch (e.getCode()) {
case ENTER:
case ESCAPE:
return;
}
// Otherwise, we stop the propagation in JavaFX
e.consume();
// But we still ask WebFX to propagate them to the peer.
Event.setPropagateToPeerEvent(e); // See WebFX comments on Event class for more explanation.
}
});
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import dev.webfx.kit.mapper.peers.javafxgraphics.markers.HasPromptTextProperty;
import dev.webfx.kit.mapper.peers.javafxgraphics.markers.HasTextProperty;
import javafx.beans.property.*;
import javafx.event.Event;
import javafx.scene.input.KeyEvent;
import javafx.scene.text.Font;

/**
Expand Down Expand Up @@ -98,4 +100,23 @@ public interface SelectableTextInputControlPeer {
void selectRange(int anchor, int caretPosition);

}

{
// Although the key events are entirely managed by the html peer, we consume them in JavaFX to not propagate
// these events to further JavaFX controls.
addEventHandler(KeyEvent.ANY, e -> {
if (isFocused()) {
// Exception is made for accelerators such as Enter or ESC, as they should be passed beyond this control
switch (e.getCode()) {
case ENTER:
case ESCAPE:
return;
}
// Otherwise, we stop the propagation in JavaFX
e.consume();
// But we still ask WebFX to propagate them to the peer.
Event.setPropagateToPeerEvent(e); // See WebFX comments on Event class for more explanation.
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import javafx.collections.ListChangeListener;
import javafx.collections.ObservableList;
import javafx.scene.layout.LayoutFlags;
import javafx.scene.layout.PreferenceResizableNode;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -412,14 +411,6 @@ public double getBaselineOffset() {
break;
}
performingLayout = true;
// Temporary webfx code to automatically bind the height to the preferred height
if (bindHeightToPrefHeight) {
PreferenceResizableNode resizableNode = (PreferenceResizableNode) this;
double prefHeight = resizableNode.getPrefHeight();
if (prefHeight == -1)
prefHeight = resizableNode.prefHeight(resizableNode.getWidth());
resizableNode.setHeight(prefHeight);
}
layoutChildren();
// Intended fall-through
case DIRTY_BRANCH:
Expand All @@ -438,17 +429,6 @@ public double getBaselineOffset() {
}
}

// Temporary webfx field to automatically bind the height to the preferred height
private boolean bindHeightToPrefHeight;

public void setBindHeightToPrefHeight(boolean bindHeightToPrefHeight) {
if (this instanceof PreferenceResizableNode)
this.bindHeightToPrefHeight = bindHeightToPrefHeight;
else
throw new IllegalStateException("Parent.setBindHeightToPrefHeight() can be called only if implementing PreferenceResizableNode");
}


/**
* Invoked during the layout pass to layout the children in this
* {@code Parent}. By default it will only set the size of managed,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2935,39 +2935,97 @@ public String getName() {
return onKeyTyped;
}

// PENDING_DOC_REVIEW
/**
* Sets the handler to use for this event type. There can only be one such
* handler specified at a time. This handler is guaranteed to be called
* first. This is used for registering the user-defined onFoo event
* handlers.
* Registers an event handler to this scene. The handler is called when the
* scene receives an {@code Event} of the specified type during the bubbling
* phase of event delivery.
*
* @param <T> the specific event class of the handler
* @param eventType the event type to associate with the given eventHandler
* @param eventHandler the handler to register, or null to unregister
* @throws NullPointerException if the event type is null
* @param eventType the type of the events to receive by the handler
* @param eventHandler the handler to register
* @throws NullPointerException if the event type or handler is null
*/
protected final <T extends Event> void setEventHandler(
public final <T extends Event> void addEventHandler(
final EventType<T> eventType,
final EventHandler<? super T> eventHandler) {
getInternalEventDispatcher().getEventHandlerManager()
.setEventHandler(eventType, eventHandler);
.addEventHandler(eventType, eventHandler);
}

// PENDING_DOC_REVIEW
/**
* Registers an event handler to this scene. The handler is called when the
* scene receives an {@code Event} of the specified type during the bubbling
* phase of event delivery.
* Unregisters a previously registered event handler from this scene. One
* handler might have been registered for different event types, so the
* caller needs to specify the particular event type from which to
* unregister the handler.
*
* @param <T> the specific event class of the handler
* @param eventType the type of the events to receive by the handler
* @param eventHandler the handler to register
* @param eventType the event type from which to unregister
* @param eventHandler the handler to unregister
* @throws NullPointerException if the event type or handler is null
*/
public final <T extends Event> void addEventHandler(
public final <T extends Event> void removeEventHandler(
final EventType<T> eventType,
final EventHandler<? super T> eventHandler) {
getInternalEventDispatcher().getEventHandlerManager()
.addEventHandler(eventType, eventHandler);
.removeEventHandler(eventType,
eventHandler);
}

// PENDING_DOC_REVIEW
/**
* Registers an event filter to this scene. The filter is called when the
* scene receives an {@code Event} of the specified type during the
* capturing phase of event delivery.
*
* @param <T> the specific event class of the filter
* @param eventType the type of the events to receive by the filter
* @param eventFilter the filter to register
* @throws NullPointerException if the event type or filter is null
*/
public final <T extends Event> void addEventFilter(
final EventType<T> eventType,
final EventHandler<? super T> eventFilter) {
getInternalEventDispatcher().getEventHandlerManager()
.addEventFilter(eventType, eventFilter);
}

// PENDING_DOC_REVIEW
/**
* Unregisters a previously registered event filter from this scene. One
* filter might have been registered for different event types, so the
* caller needs to specify the particular event type from which to
* unregister the filter.
*
* @param <T> the specific event class of the filter
* @param eventType the event type from which to unregister
* @param eventFilter the filter to unregister
* @throws NullPointerException if the event type or filter is null
*/
public final <T extends Event> void removeEventFilter(
final EventType<T> eventType,
final EventHandler<? super T> eventFilter) {
getInternalEventDispatcher().getEventHandlerManager()
.removeEventFilter(eventType, eventFilter);
}

/**
* Sets the handler to use for this event type. There can only be one such
* handler specified at a time. This handler is guaranteed to be called
* first. This is used for registering the user-defined onFoo event
* handlers.
*
* @param <T> the specific event class of the handler
* @param eventType the event type to associate with the given eventHandler
* @param eventHandler the handler to register, or null to unregister
* @throws NullPointerException if the event type is null
*/
protected final <T extends Event> void setEventHandler(
final EventType<T> eventType,
final EventHandler<? super T> eventHandler) {
getInternalEventDispatcher().getEventHandlerManager()
.setEventHandler(eventType, eventHandler);
}

/**
Expand Down
1 change: 0 additions & 1 deletion webfx-kit/webfx-kit-javafxgraphics-fat-j2cl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

<artifactId>webfx-kit-javafxgraphics-fat-j2cl</artifactId>


<build>
<plugins>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ body {
opacity: 50%;
}

/* When fill and stroke are not set by application code, we make them transparent by default like in JavaFX (otherwise
the browser will make them black). */
fx-svgpath svg {
fill: none;
stroke: none;
/* Applying the default JavaFX behaviour for SVGPath */
fx-svgpath svg path:not([fill]):not([stroke]) { /* if the application code didn't set neither fill nor stroke */
fill: black; /* then the fill is black */
}

fx-svgpath svg path:not([fill])[stroke] { /* if the application code set the stroke but not the fill */
fill: transparent; /* then the fill is transparent */
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package dev.webfx.kit.mapper.peers.javafxgraphics.gwtj2cl.html;

import dev.webfx.kit.mapper.peers.javafxgraphics.HasNoChildrenPeers;
import dev.webfx.kit.mapper.peers.javafxgraphics.base.RegionPeerBase;
import dev.webfx.kit.mapper.peers.javafxgraphics.base.RegionPeerMixin;
import dev.webfx.kit.mapper.peers.javafxgraphics.gwtj2cl.html.layoutmeasurable.HtmlLayoutMeasurable;
import dev.webfx.kit.mapper.peers.javafxgraphics.gwtj2cl.util.HtmlUtil;
import javafx.scene.layout.Region;

/**
* @author Bruno Salmon
*/
public final class HtmlBrowserRegionPeer
<N extends Region, NB extends RegionPeerBase<N, NB, NM>, NM extends RegionPeerMixin<N, NB, NM>>

extends HtmlRegionPeer<N, NB, NM> implements HtmlLayoutMeasurable, HasNoChildrenPeers {

public HtmlBrowserRegionPeer(String tagName) {
super((NB) new RegionPeerBase(), HtmlUtil.createElement(tagName));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
/**
* @author Bruno Salmon
*/
public final class HtmlLayoutPeer
public final class HtmlJavaFXRegionPeer
<N extends Region, NB extends RegionPeerBase<N, NB, NM>, NM extends RegionPeerMixin<N, NB, NM>>

extends HtmlRegionPeer<N, NB, NM>
implements NoWrapWhiteSpacePeer {

public HtmlLayoutPeer(String tag) {
public HtmlJavaFXRegionPeer(String tag) {
super((NB) new RegionPeerBase<N, NB, NM>(), HtmlUtil.createElement(tag));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dev.webfx.kit.mapper.peers.javafxgraphics.gwtj2cl.html;

import dev.webfx.kit.mapper.peers.javafxgraphics.HasNoChildrenPeers;
import dev.webfx.kit.mapper.peers.javafxgraphics.base.RegionPeerBase;
import dev.webfx.kit.mapper.peers.javafxgraphics.base.RegionPeerMixin;
import dev.webfx.kit.mapper.peers.javafxgraphics.gwtj2cl.util.DomType;
Expand All @@ -25,15 +26,22 @@ public abstract class HtmlRegionPeer
extends HtmlNodePeer<N, NB, NM>
implements RegionPeerMixin<N, NB, NM> {

private final HTMLElement fxBackground = createBehindElement("fx-background");
private final HTMLElement fxBorder = createBehindElement("fx-border");
private final HTMLElement fxBackground;
private final HTMLElement fxBorder;

protected HtmlRegionPeer(NB base, HTMLElement element) {
super(base, element);
fxBorder.style.boxSizing = "border-box";
HTMLElement fxChildren = createBehindElement("fx-children");
setChildrenContainer(fxChildren);
HtmlUtil.setChildren(element, fxBackground, fxBorder, fxChildren);
if (this instanceof HasNoChildrenPeers) {
fxBackground = element;
fxBorder = element;
} else {
fxBackground = createBehindElement("fx-background");
fxBorder = createBehindElement("fx-border");
fxBorder.style.boxSizing = "border-box";
HTMLElement fxChildren = createBehindElement("fx-children");
setChildrenContainer(fxChildren);
HtmlUtil.setChildren(element, fxBackground, fxBorder, fxChildren);
}
}

private static HTMLElement createBehindElement(String tag) {
Expand Down Expand Up @@ -92,7 +100,7 @@ protected HTMLElement getBorderElement() {

@Override
protected HTMLElement getEffectElement() {
return fxBackground;
return getBackgroundElement();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ body {
opacity: 50%;
}

/* When fill and stroke are not set by application code, we make them transparent by default like in JavaFX (otherwise
the browser will make them black). */
fx-svgpath svg {
fill: none;
stroke: none;
/* Applying the default JavaFX behaviour for SVGPath */
fx-svgpath svg path:not([fill]):not([stroke]) { /* if the application code didn't set neither fill nor stroke */
fill: black; /* then the fill is black */
}

fx-svgpath svg path:not([fill])[stroke] { /* if the application code set the stroke but not the fill */
fill: transparent; /* then the fill is transparent */
}
Loading

0 comments on commit 8f0c16a

Please sign in to comment.