Skip to content

Commit

Permalink
8181775: JavaFX WebView does not calculate border-radius properly
Browse files Browse the repository at this point in the history
Reviewed-by: kcr, ajoseph
  • Loading branch information
bhaweshkc authored and kevinrushforth committed Aug 10, 2020
1 parent 5c596b1 commit f216c5f
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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(
"<!DOCTYPE html>\n" +
"<html>\n" +
" <head>\n" +
" <style>\n" +
" button {\n" +
" background-color: black; color: white; display: block; font-size: 32px;\n" +
" width: 200px; height: 100px; padding: 0; border: none;\n" +
" border-radius: 32px;\n" +
" }\n" +
" .bad0 {\n" +
" background-color: red;\n" +
" }\n" +
" .bad1 {\n" +
" border-bottom-left-radius: 0;\n" +
" background-color: blue;\n" +
" }\n" +
" .bad2 {\n" +
" border-bottom-left-radius: 0;\n" +
" border-bottom-right-radius: 0;\n" +
" background-color: green;\n" +
" }\n" +
" .bad3 {\n" +
" border-bottom-left-radius: 0;\n" +
" border-bottom-right-radius: 0;\n" +
" border-top-right-radius: 0;\n" +
" }\n" +
" </style>\n" +
" </head>\n" +
" <body style='margin: 0px 0px;'>\n" +
" <button class=\"bad0\">A</button>\n" +
" <button class=\"bad1\">B</button>\n" +
" <button class=\"bad2\">C</button>\n" +
" <button class=\"bad3\">D</button>\n" +
" </body>\n" +
"</html>"
);
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));
});
}
}

0 comments on commit f216c5f

Please sign in to comment.