-
Notifications
You must be signed in to change notification settings - Fork 583
8388313: ContextMenu.show(node, side,x, y) evaluates CSS multiple times. #2215
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -64,6 +64,8 @@ | |||||||||
| import test.com.sun.javafx.scene.control.infrastructure.KeyEventFirer; | ||||||||||
| import test.com.sun.javafx.scene.control.infrastructure.MouseEventFirer; | ||||||||||
| import test.com.sun.javafx.scene.control.infrastructure.StageLoader; | ||||||||||
| import javafx.scene.control.skin.ButtonSkin; | ||||||||||
| import java.util.concurrent.atomic.AtomicInteger; | ||||||||||
|
|
||||||||||
| public class ContextMenuTest { | ||||||||||
|
|
||||||||||
|
|
@@ -695,6 +697,32 @@ private ContextMenu createContextMenuAndShowSubMenu() { | |||||||||
| assertEquals(anchorBounds.getMinY(), cmBounds.getMinY(), 0.0); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| @Test public void test_css_skin_counter() { | ||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Or something like that would be suggestion to better express what we test here
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's now named |
||||||||||
| anchorBtn.getScene().getStylesheets().add( | ||||||||||
| getClass().getResource("test_css_skin_counter.css").toExternalForm() | ||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you could create a data url CSS, then you don't need a separate CSS file. jfx/modules/javafx.graphics/src/test/java/test/javafx/scene/CssStyleHelperTest.java Line 943 in 1718958
jfx/modules/javafx.graphics/src/test/java/test/javafx/scene/CssStyleHelperTest.java Lines 968 to 970 in 1718958
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Used it, by making the method public. |
||||||||||
| ); | ||||||||||
| anchorBtn.getStyleClass().add("anchor"); | ||||||||||
| AtomicInteger skinCounter = new AtomicInteger(0); | ||||||||||
| Button button = new Button(); | ||||||||||
| button.skinProperty().subscribe(skin -> { | ||||||||||
| System.out.println("new Skin: " + skin); | ||||||||||
| new Exception().printStackTrace(); | ||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. looks like debugging code?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed them. |
||||||||||
| skinCounter.incrementAndGet(); | ||||||||||
| }); | ||||||||||
| menuItem.setGraphic(button); | ||||||||||
| ContextMenu cm = createContextMenu(false); | ||||||||||
| cm.show(anchorBtn, Side.TOP, 0, 0); | ||||||||||
|
|
||||||||||
| Bounds anchorBounds = anchorBtn.localToScreen(anchorBtn.getLayoutBounds()); | ||||||||||
| Node cmNode = cm.getScene().getRoot(); | ||||||||||
| Bounds cmBounds = cm.getScene().getRoot().localToScreen(cmNode.getLayoutBounds()); | ||||||||||
|
|
||||||||||
| assertEquals(anchorBounds.getMinX(), cmBounds.getMinX(), 0.0); | ||||||||||
| assertEquals(anchorBounds.getMinY(), cmBounds.getMaxY(), 0.0); | ||||||||||
|
|
||||||||||
| assertEquals(2, skinCounter.get()); | ||||||||||
| } | ||||||||||
|
|
||||||||||
|
FlorianKirmaier marked this conversation as resolved.
|
||||||||||
|
|
||||||||||
| @Test public void test_position_withCSS() { | ||||||||||
| anchorBtn.getScene().getStylesheets().add( | ||||||||||
|
|
@@ -775,4 +803,11 @@ private ContextMenu createContextMenuAndShowSubMenu() { | |||||||||
| assertEquals(0, padding.getLeft(), 0.0); | ||||||||||
| anchorBtn.setGraphic(null); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| public static class ButtonSkin1 extends ButtonSkin { | ||||||||||
| public ButtonSkin1(Button button) { super(button); } | ||||||||||
| } | ||||||||||
| public static class ButtonSkin2 extends ButtonSkin { | ||||||||||
| public ButtonSkin2(Button button) { super(button); } | ||||||||||
| } | ||||||||||
| } | ||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| .button { -fx-skin: "test.javafx.scene.control.ContextMenuTest$ButtonSkin1"; } | ||
| .anchor .button { -fx-skin: "test.javafx.scene.control.ContextMenuTest$ButtonSkin2"; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those seem to be set already later in
doShow->show->showImpl.And also the stylesheet is applied there as well. So I wonder if can instead just remove the stylesheet stuff below and this as well, and let be done later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, this is basically the heart of the PR.
We have to set all this before the layout is computed at:
Which happens before the show.
The double-assignment is a bit odd.
But the other solution would be to split the show() into a "preShow()" which prepares CSS and owners.
Which would be a bigger change.