Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions modules/javafx.graphics/src/main/java/javafx/scene/Node.java
Original file line number Diff line number Diff line change
Expand Up @@ -8651,6 +8651,12 @@ private void preprocessMouseEvent(MouseEvent e) {
}

void markDirtyLayoutBranch() {
if (this instanceof Parent p && p.layoutRoot) { // is this node a layout root?
markAsDirtyLayoutRoot(p);

return; // No need to propagate flags any further up the hierarchy
}

Parent p = getParent();
while (p != null && p.layoutFlag == LayoutFlags.CLEAN) {
p.setLayoutFlag(LayoutFlags.DIRTY_BRANCH);
Expand All @@ -8660,9 +8666,23 @@ void markDirtyLayoutBranch() {
getSubScene().setDirtyLayout(p);
}
}
else if (p.layoutRoot) {
markAsDirtyLayoutRoot(p);

return; // No need to propagate flags any further up the hierarchy
}

p = p.getParent();
}
}

private void markAsDirtyLayoutRoot(Parent p) {
Toolkit.getToolkit().requestNextPulse();
Scene s = getScene();

if (s != null) {
s.addToDirtyLayoutList(p);
}
}

private boolean isWindowShowing() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1021,7 +1021,7 @@ private void markDirtyLayout(boolean local, boolean forceParentLayout) {
* rendered. This is batched up asynchronously to happen once per
* "pulse", or frame of animation.
* <p>
* If this parent is either a layout root or unmanaged, then it will be
* If this parent is either a scene root or unmanaged, then it will be
* added directly to the scene's dirty layout list, otherwise requestParentLayout
* will be invoked.
* @since JavaFX 8.0
Expand Down
23 changes: 23 additions & 0 deletions modules/javafx.graphics/src/main/java/javafx/scene/Scene.java
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,21 @@ void unregisterClearInitialCssStageFlag(Node node) {
clearInitialCssStateNodes.remove(node);
}

/**
* A set of nodes that are layout roots and are in need of layout. Any unmanaged
* {@link Parent} is considered a layout root. If a child of such a node
* requests layout, the layout root will be added to this set, to be laid
* out on the next layout pass.
*
* @see Node#managedProperty()
* @see Parent#requestLayout()
*/
private final Set<Parent> dirtyLayoutRoots = new HashSet<>();

void addToDirtyLayoutList(Parent layoutRoot) {
dirtyLayoutRoots.add(layoutRoot);
}

void doLayoutPass() {
if (peer != null) {
peer.layoutOverlay();
Expand All @@ -654,6 +669,14 @@ void doLayoutPass() {
if (r != null) {
r.layout();
}

Set<Parent> copy = new HashSet<>(dirtyLayoutRoots);

dirtyLayoutRoots.clear();

for (Parent parent : copy) {
parent.layout();
}
}

/**
Expand Down