Skip to content
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

8296387: [Tooltip, CSS] -fx-show-delay is only applied to the first tooltip that is shown before it is displayed #1394

Closed
wants to merge 14 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -119,6 +119,7 @@ public class Tooltip extends PopupControl {
private static int TOOLTIP_YOFFSET = 7;

private static TooltipBehavior BEHAVIOR = new TooltipBehavior(false);
private boolean cssForced;

/**
* Associates the given {@link Tooltip} with the given {@link Node}. The tooltip
Expand Down Expand Up @@ -170,6 +171,16 @@ public Tooltip(String text) {
getStyleClass().setAll("tooltip");
}

@Override
protected void show() {
Maran23 marked this conversation as resolved.
Show resolved Hide resolved
// The very first show call is just for us to do the correct CSS processing, so we ignore the request here.
if (!cssForced) {
Maran23 marked this conversation as resolved.
Show resolved Hide resolved
return;
}

super.show();
}

/* *************************************************************************
* *
* Properties *
Expand Down Expand Up @@ -859,7 +870,6 @@ private static class TooltipBehavior {
private double lastMouseY;

private boolean hideOnExit;
private boolean cssForced = false;

TooltipBehavior(final boolean hideOnExit) {
this.hideOnExit = hideOnExit;
Expand Down Expand Up @@ -998,13 +1008,14 @@ private static class TooltipBehavior {
} else {
// Force the CSS to be processed for the tooltip so that it uses the
// appropriate timings for showDelay, showDuration, and hideDelay.
if (!cssForced) {
double opacity = t.getOpacity();
t.setOpacity(0);
if (!t.cssForced) {
// Note that we do not really show the tooltip but rather do all the necessary setup for
// the correct CSS processing.
// In this case we especially need the show method to attach all the stylesheets to us
// from the owner root window.
t.show(owner);
t.hide();
t.setOpacity(opacity);
cssForced = true;
t.bridge.applyCss();
t.cssForced = true;
}

// Start / restart the timer and make sure the tooltip
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -28,6 +28,7 @@
import javafx.css.CssMetaData;
import static test.com.sun.javafx.scene.control.infrastructure.ControlTestUtils.*;

import javafx.scene.input.MouseEvent;
import test.com.sun.javafx.pgstub.StubToolkit;
import com.sun.javafx.tk.Toolkit;
import javafx.beans.property.BooleanProperty;
Expand All @@ -53,6 +54,8 @@
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import test.com.sun.javafx.scene.control.infrastructure.MouseEventGenerator;
import test.com.sun.javafx.scene.control.infrastructure.StageLoader;

public class TooltipTest {
private TooltipShim toolTip;//Empty string
Expand Down Expand Up @@ -318,7 +321,7 @@ public class TooltipTest {

@Test public void whenWrapTextIsSpecifiedViaCSSAndIsNotBound_CssMetaData_isSettable_ReturnsTrue() {
CssMetaData styleable = ((StyleableProperty)toolTip.wrapTextProperty()).getCssMetaData();
assertTrue(styleable.isSettable(toolTip.get_bridge()));
assertTrue(styleable.isSettable(toolTip.get_bridge()));
}

@Test public void canSpecifyWrapTextViaCSS() {
Expand All @@ -328,15 +331,15 @@ public class TooltipTest {

@Test public void whenFontIsBound_CssMetaData_isSettable_ReturnsFalse() {
CssMetaData styleable = ((StyleableProperty)toolTip.fontProperty()).getCssMetaData();
assertTrue(styleable.isSettable(toolTip.get_bridge()));
assertTrue(styleable.isSettable(toolTip.get_bridge()));
ObjectProperty<Font> other = new SimpleObjectProperty<>();
toolTip.fontProperty().bind(other);
assertFalse(styleable.isSettable(toolTip.get_bridge()));
assertFalse(styleable.isSettable(toolTip.get_bridge()));
}

@Test public void whenFontIsSpecifiedViaCSSAndIsNotBound_CssMetaData_isSettable_ReturnsTrue() {
CssMetaData styleable = ((StyleableProperty)toolTip.fontProperty()).getCssMetaData();
assertTrue(styleable.isSettable(toolTip.get_bridge()));
assertTrue(styleable.isSettable(toolTip.get_bridge()));
}

@Test public void canSpecifyFontViaCSS() {
Expand All @@ -349,12 +352,12 @@ public class TooltipTest {
assertTrue(styleable.isSettable(toolTip.get_bridge()));
ObjectProperty<Node> other = new SimpleObjectProperty<>();
toolTip.graphicProperty().bind(other);
assertFalse(styleable.isSettable(toolTip.get_bridge()));
assertFalse(styleable.isSettable(toolTip.get_bridge()));
}

@Test public void whenGraphicIsSpecifiedViaCSSAndIsNotBound_CssMetaData_isSettable_ReturnsTrue() {
CssMetaData styleable = ((StyleableProperty)toolTip.graphicProperty()).getCssMetaData();
assertTrue(styleable.isSettable(toolTip.get_bridge()));
assertTrue(styleable.isSettable(toolTip.get_bridge()));
}

@Ignore("CSS sets graphicProperty indirectly")
Expand All @@ -366,14 +369,14 @@ public class TooltipTest {

@Test public void whenContentDisplayIsBound_CssMetaData_isSettable_ReturnsFalse() {
CssMetaData styleable = ((StyleableProperty)toolTip.contentDisplayProperty()).getCssMetaData();
assertTrue(styleable.isSettable(toolTip.get_bridge()));
assertTrue(styleable.isSettable(toolTip.get_bridge()));
ObjectProperty<ContentDisplay> other = new SimpleObjectProperty<>();
toolTip.contentDisplayProperty().bind(other);
assertFalse(styleable.isSettable(toolTip.get_bridge()));
assertFalse(styleable.isSettable(toolTip.get_bridge()));
}
@Test public void whenContentDisplayIsSpecifiedViaCSSAndIsNotBound_CssMetaData_isSettable_ReturnsTrue() {
@Test public void whenContentDisplayIsSpecifiedViaCSSAndIsNotBound_CssMetaData_isSettable_ReturnsTrue() {
CssMetaData styleable = ((StyleableProperty)toolTip.contentDisplayProperty()).getCssMetaData();
assertTrue(styleable.isSettable(toolTip.get_bridge()));
assertTrue(styleable.isSettable(toolTip.get_bridge()));
}

@Test public void canSpecifyContentDisplayViaCSS() {
Expand All @@ -383,15 +386,15 @@ public class TooltipTest {

@Test public void whenGraphicTextGapIsBound_CssMetaData_isSettable_ReturnsFalse() {
CssMetaData styleable = ((StyleableProperty)toolTip.graphicTextGapProperty()).getCssMetaData();
assertTrue(styleable.isSettable(toolTip.get_bridge()));
assertTrue(styleable.isSettable(toolTip.get_bridge()));
DoubleProperty other = new SimpleDoubleProperty();
toolTip.graphicTextGapProperty().bind(other);
assertFalse(styleable.isSettable(toolTip.get_bridge()));
assertFalse(styleable.isSettable(toolTip.get_bridge()));
}

@Test public void whenGraphicTextGapIsSpecifiedViaCSSAndIsNotBound_CssMetaData_isSettable_ReturnsTrue() {
CssMetaData styleable = ((StyleableProperty)toolTip.graphicTextGapProperty()).getCssMetaData();
assertTrue(styleable.isSettable(toolTip.get_bridge()));
assertTrue(styleable.isSettable(toolTip.get_bridge()));
}

@Test public void canSpecifyGraphicTextGapViaCSS() {
Expand Down Expand Up @@ -531,5 +534,24 @@ public class TooltipTest {
}
}

/**
* A {@link Tooltip} once was showing and quickly hiding itself in order to process the CSS.
* This was changed in <a href="https://bugs.openjdk.org/browse/JDK-8296387">JDK-8296387</a>
* and this test ensure that this is the case.
*/
@Test
public void testTooltipShouldNotBeShownBeforeDelayIsUp() {
toolTip.showingProperty().addListener(inv -> fail());
Rectangle rect1 = new Rectangle(0, 0, 100, 100);

StageLoader stageLoader = new StageLoader(rect1);

Tooltip.install(rect1, toolTip);

MouseEvent mouseEvent = MouseEventGenerator.generateMouseEvent(MouseEvent.MOUSE_MOVED, 1, 1);
rect1.fireEvent(mouseEvent);

stageLoader.dispose();
}

}
Loading