From f216c5fe113c56af4b37f542edf7afb3650e7842 Mon Sep 17 00:00:00 2001 From: Bhawesh Choudhary Date: Mon, 10 Aug 2020 12:21:02 +0000 Subject: [PATCH] 8181775: JavaFX WebView does not calculate border-radius properly Reviewed-by: kcr, ajoseph --- .../graphics/java/GraphicsContextJava.cpp | 39 +++++++--- .../java/test/javafx/scene/web/CSSTest.java | 74 +++++++++++++++++++ 2 files changed, 104 insertions(+), 9 deletions(-) diff --git a/modules/javafx.web/src/main/native/Source/WebCore/platform/graphics/java/GraphicsContextJava.cpp b/modules/javafx.web/src/main/native/Source/WebCore/platform/graphics/java/GraphicsContextJava.cpp index cb147e560cd..ba22b5ab4f5 100644 --- a/modules/javafx.web/src/main/native/Source/WebCore/platform/graphics/java/GraphicsContextJava.cpp +++ b/modules/javafx.web/src/main/native/Source/WebCore/platform/graphics/java/GraphicsContextJava.cpp @@ -878,15 +878,36 @@ void GraphicsContext::fillRoundedRect(const FloatRoundedRect& rect, const Color& if (paintingDisabled()) return; - platformContext()->rq().freeSpace(56) - << (jint)com_sun_webkit_graphics_GraphicsDecoder_FILL_ROUNDED_RECT - << (jfloat)rect.rect().x() << (jfloat)rect.rect().y() - << (jfloat)rect.rect().width() << (jfloat)rect.rect().height() - << (jfloat)rect.radii().topLeft().width() << (jfloat)rect.radii().topLeft().height() - << (jfloat)rect.radii().topRight().width() << (jfloat)rect.radii().topRight().height() - << (jfloat)rect.radii().bottomLeft().width() << (jfloat)rect.radii().bottomLeft().height() - << (jfloat)rect.radii().bottomRight().width() << (jfloat)rect.radii().bottomRight().height() - << (jint)color.rgb().value(); + if (rect.radii().topLeft().width() == rect.radii().topRight().width() && + rect.radii().topRight().width() == rect.radii().bottomRight().width() && + rect.radii().bottomRight().width() == rect.radii().bottomLeft().width() && + rect.radii().topLeft().height() == rect.radii().topRight().height() && + rect.radii().topRight().height() == rect.radii().bottomRight().height() && + rect.radii().bottomRight().height() == rect.radii().bottomLeft().height()) { + platformContext()->rq().freeSpace(56) + << (jint)com_sun_webkit_graphics_GraphicsDecoder_FILL_ROUNDED_RECT + << (jfloat)rect.rect().x() << (jfloat)rect.rect().y() + << (jfloat)rect.rect().width() << (jfloat)rect.rect().height() + << (jfloat)rect.radii().topLeft().width() << (jfloat)rect.radii().topLeft().height() + << (jfloat)rect.radii().topRight().width() << (jfloat)rect.radii().topRight().height() + << (jfloat)rect.radii().bottomLeft().width() << (jfloat)rect.radii().bottomLeft().height() + << (jfloat)rect.radii().bottomRight().width() << (jfloat)rect.radii().bottomRight().height() + << (jint)color.rgb().value(); + } + else { + WindRule oldFillRule = fillRule(); + Color oldFillColor = fillColor(); + + setFillRule(WindRule::EvenOdd); + setFillColor(color); + + Path roundedRectPath; + roundedRectPath.addRoundedRect(rect); + fillPath(roundedRectPath); + + setFillRule(oldFillRule); + setFillColor(oldFillColor); + } } void GraphicsContext::fillRectWithRoundedHole(const FloatRect& frect, const FloatRoundedRect& roundedHoleRect, const Color& color) diff --git a/modules/javafx.web/src/test/java/test/javafx/scene/web/CSSTest.java b/modules/javafx.web/src/test/java/test/javafx/scene/web/CSSTest.java index be6e50dc872..5baf15c137c 100644 --- a/modules/javafx.web/src/test/java/test/javafx/scene/web/CSSTest.java +++ b/modules/javafx.web/src/test/java/test/javafx/scene/web/CSSTest.java @@ -27,14 +27,24 @@ import static javafx.concurrent.Worker.State.FAILED; import static javafx.concurrent.Worker.State.SUCCEEDED; + +import com.sun.webkit.WebPage; +import com.sun.webkit.WebPageShim; + +import java.awt.image.BufferedImage; +import java.awt.Color; import java.io.File; import javafx.concurrent.Worker.State; import javafx.scene.Scene; import javafx.scene.text.FontSmoothingType; +import javafx.scene.web.WebEngineShim; import org.junit.Test; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertNotNull; public class CSSTest extends TestBase { @@ -284,4 +294,68 @@ private void testMaxHeight(double expected) { load(new File(FILE)); assertEquals("Loading Long SelectorList completed successfully", SUCCEEDED, getLoadState()); } + + @Test public void testBorderRadiusPropertyRendering() { + loadContent( + "\n" + + "\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + "" + ); + submit(() -> { + final WebPage webPage = WebEngineShim.getPage(getEngine()); + assertNotNull(webPage); + final BufferedImage img = WebPageShim.paint(webPage, 0, 0, 800, 600); + assertNotNull(img); + + final Color pixelAt0x0 = new Color(img.getRGB(0, 0), true); + assertFalse("Color should not be red:" + pixelAt0x0, isColorsSimilar(Color.RED, pixelAt0x0, 1)); + final Color pixelAt199x0 = new Color(img.getRGB(199, 0), true); + assertFalse("Color should not be red:" + pixelAt199x0, isColorsSimilar(Color.RED, pixelAt199x0, 1)); + final Color pixelAt0x99 = new Color(img.getRGB(0, 99), true); + assertFalse("Color should not be red:" + pixelAt0x99, isColorsSimilar(Color.RED, pixelAt0x99, 1)); + final Color pixelAt199x99 = new Color(img.getRGB(199, 99), true); + assertFalse("Color should not be red:" + pixelAt199x99, isColorsSimilar(Color.RED, pixelAt199x99, 1)); + + final Color pixelAt0x100 = new Color(img.getRGB(0, 100), true); + assertFalse("Color should not be blue:" + pixelAt0x100, isColorsSimilar(Color.BLUE, pixelAt0x100, 1)); + final Color pixelAt199x100 = new Color(img.getRGB(199, 100), true); + assertFalse("Color should not be blue:" + pixelAt199x100, isColorsSimilar(Color.BLUE, pixelAt199x100, 1)); + final Color pixel0x199 = new Color(img.getRGB(0, 199), true); + assertTrue("Color should be opaque blue:" + pixel0x199, isColorsSimilar(Color.BLUE, pixel0x199, 1)); + final Color pixelAt199x199 = new Color(img.getRGB(199, 199), true); + assertFalse("Color should not be blue:" + pixelAt199x199, isColorsSimilar(Color.BLUE, pixelAt199x199, 1)); + }); + } }