Skip to content

Commit f216c5f

Browse files
bhaweshkckevinrushforth
authored andcommitted
8181775: JavaFX WebView does not calculate border-radius properly
Reviewed-by: kcr, ajoseph
1 parent 5c596b1 commit f216c5f

File tree

2 files changed

+104
-9
lines changed

2 files changed

+104
-9
lines changed

modules/javafx.web/src/main/native/Source/WebCore/platform/graphics/java/GraphicsContextJava.cpp

+30-9
Original file line numberDiff line numberDiff line change
@@ -878,15 +878,36 @@ void GraphicsContext::fillRoundedRect(const FloatRoundedRect& rect, const Color&
878878
if (paintingDisabled())
879879
return;
880880

881-
platformContext()->rq().freeSpace(56)
882-
<< (jint)com_sun_webkit_graphics_GraphicsDecoder_FILL_ROUNDED_RECT
883-
<< (jfloat)rect.rect().x() << (jfloat)rect.rect().y()
884-
<< (jfloat)rect.rect().width() << (jfloat)rect.rect().height()
885-
<< (jfloat)rect.radii().topLeft().width() << (jfloat)rect.radii().topLeft().height()
886-
<< (jfloat)rect.radii().topRight().width() << (jfloat)rect.radii().topRight().height()
887-
<< (jfloat)rect.radii().bottomLeft().width() << (jfloat)rect.radii().bottomLeft().height()
888-
<< (jfloat)rect.radii().bottomRight().width() << (jfloat)rect.radii().bottomRight().height()
889-
<< (jint)color.rgb().value();
881+
if (rect.radii().topLeft().width() == rect.radii().topRight().width() &&
882+
rect.radii().topRight().width() == rect.radii().bottomRight().width() &&
883+
rect.radii().bottomRight().width() == rect.radii().bottomLeft().width() &&
884+
rect.radii().topLeft().height() == rect.radii().topRight().height() &&
885+
rect.radii().topRight().height() == rect.radii().bottomRight().height() &&
886+
rect.radii().bottomRight().height() == rect.radii().bottomLeft().height()) {
887+
platformContext()->rq().freeSpace(56)
888+
<< (jint)com_sun_webkit_graphics_GraphicsDecoder_FILL_ROUNDED_RECT
889+
<< (jfloat)rect.rect().x() << (jfloat)rect.rect().y()
890+
<< (jfloat)rect.rect().width() << (jfloat)rect.rect().height()
891+
<< (jfloat)rect.radii().topLeft().width() << (jfloat)rect.radii().topLeft().height()
892+
<< (jfloat)rect.radii().topRight().width() << (jfloat)rect.radii().topRight().height()
893+
<< (jfloat)rect.radii().bottomLeft().width() << (jfloat)rect.radii().bottomLeft().height()
894+
<< (jfloat)rect.radii().bottomRight().width() << (jfloat)rect.radii().bottomRight().height()
895+
<< (jint)color.rgb().value();
896+
}
897+
else {
898+
WindRule oldFillRule = fillRule();
899+
Color oldFillColor = fillColor();
900+
901+
setFillRule(WindRule::EvenOdd);
902+
setFillColor(color);
903+
904+
Path roundedRectPath;
905+
roundedRectPath.addRoundedRect(rect);
906+
fillPath(roundedRectPath);
907+
908+
setFillRule(oldFillRule);
909+
setFillColor(oldFillColor);
910+
}
890911
}
891912

892913
void GraphicsContext::fillRectWithRoundedHole(const FloatRect& frect, const FloatRoundedRect& roundedHoleRect, const Color& color)

modules/javafx.web/src/test/java/test/javafx/scene/web/CSSTest.java

+74
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,24 @@
2727

2828
import static javafx.concurrent.Worker.State.FAILED;
2929
import static javafx.concurrent.Worker.State.SUCCEEDED;
30+
31+
import com.sun.webkit.WebPage;
32+
import com.sun.webkit.WebPageShim;
33+
34+
import java.awt.image.BufferedImage;
35+
import java.awt.Color;
3036
import java.io.File;
3137
import javafx.concurrent.Worker.State;
3238
import javafx.scene.Scene;
3339
import javafx.scene.text.FontSmoothingType;
40+
import javafx.scene.web.WebEngineShim;
3441

3542
import org.junit.Test;
3643

3744
import static org.junit.Assert.assertEquals;
45+
import static org.junit.Assert.assertFalse;
46+
import static org.junit.Assert.assertTrue;
47+
import static org.junit.Assert.assertNotNull;
3848

3949
public class CSSTest extends TestBase {
4050

@@ -284,4 +294,68 @@ private void testMaxHeight(double expected) {
284294
load(new File(FILE));
285295
assertEquals("Loading Long SelectorList completed successfully", SUCCEEDED, getLoadState());
286296
}
297+
298+
@Test public void testBorderRadiusPropertyRendering() {
299+
loadContent(
300+
"<!DOCTYPE html>\n" +
301+
"<html>\n" +
302+
" <head>\n" +
303+
" <style>\n" +
304+
" button {\n" +
305+
" background-color: black; color: white; display: block; font-size: 32px;\n" +
306+
" width: 200px; height: 100px; padding: 0; border: none;\n" +
307+
" border-radius: 32px;\n" +
308+
" }\n" +
309+
" .bad0 {\n" +
310+
" background-color: red;\n" +
311+
" }\n" +
312+
" .bad1 {\n" +
313+
" border-bottom-left-radius: 0;\n" +
314+
" background-color: blue;\n" +
315+
" }\n" +
316+
" .bad2 {\n" +
317+
" border-bottom-left-radius: 0;\n" +
318+
" border-bottom-right-radius: 0;\n" +
319+
" background-color: green;\n" +
320+
" }\n" +
321+
" .bad3 {\n" +
322+
" border-bottom-left-radius: 0;\n" +
323+
" border-bottom-right-radius: 0;\n" +
324+
" border-top-right-radius: 0;\n" +
325+
" }\n" +
326+
" </style>\n" +
327+
" </head>\n" +
328+
" <body style='margin: 0px 0px;'>\n" +
329+
" <button class=\"bad0\">A</button>\n" +
330+
" <button class=\"bad1\">B</button>\n" +
331+
" <button class=\"bad2\">C</button>\n" +
332+
" <button class=\"bad3\">D</button>\n" +
333+
" </body>\n" +
334+
"</html>"
335+
);
336+
submit(() -> {
337+
final WebPage webPage = WebEngineShim.getPage(getEngine());
338+
assertNotNull(webPage);
339+
final BufferedImage img = WebPageShim.paint(webPage, 0, 0, 800, 600);
340+
assertNotNull(img);
341+
342+
final Color pixelAt0x0 = new Color(img.getRGB(0, 0), true);
343+
assertFalse("Color should not be red:" + pixelAt0x0, isColorsSimilar(Color.RED, pixelAt0x0, 1));
344+
final Color pixelAt199x0 = new Color(img.getRGB(199, 0), true);
345+
assertFalse("Color should not be red:" + pixelAt199x0, isColorsSimilar(Color.RED, pixelAt199x0, 1));
346+
final Color pixelAt0x99 = new Color(img.getRGB(0, 99), true);
347+
assertFalse("Color should not be red:" + pixelAt0x99, isColorsSimilar(Color.RED, pixelAt0x99, 1));
348+
final Color pixelAt199x99 = new Color(img.getRGB(199, 99), true);
349+
assertFalse("Color should not be red:" + pixelAt199x99, isColorsSimilar(Color.RED, pixelAt199x99, 1));
350+
351+
final Color pixelAt0x100 = new Color(img.getRGB(0, 100), true);
352+
assertFalse("Color should not be blue:" + pixelAt0x100, isColorsSimilar(Color.BLUE, pixelAt0x100, 1));
353+
final Color pixelAt199x100 = new Color(img.getRGB(199, 100), true);
354+
assertFalse("Color should not be blue:" + pixelAt199x100, isColorsSimilar(Color.BLUE, pixelAt199x100, 1));
355+
final Color pixel0x199 = new Color(img.getRGB(0, 199), true);
356+
assertTrue("Color should be opaque blue:" + pixel0x199, isColorsSimilar(Color.BLUE, pixel0x199, 1));
357+
final Color pixelAt199x199 = new Color(img.getRGB(199, 199), true);
358+
assertFalse("Color should not be blue:" + pixelAt199x199, isColorsSimilar(Color.BLUE, pixelAt199x199, 1));
359+
});
360+
}
287361
}

0 commit comments

Comments
 (0)