I am working on a JavaFX application which uses the JavaFX WebView browser to display a Sencha Touch webapp. Long story short, the Sencha Touch application was originally being accessed through a different browser, but in the future it needs to be accessed on a device running the JavaFX WebView. This makes things a little convoluted, but it's generally been a pretty seamless transition.
The issue I'm having comes from our use of the -webkit-mask-image
CSS property. We were using this property to quickly color a number of buttons and other images to fit in with whatever coloring scheme was being used. Unfortunately, the JavaFX WebView seems pretty confused about what to do with -webkit-mask-image
, and all those images were being distorted.
I did my homework and came up with this blog post which describes how to achieve effects similar to -webkit-mask-image
in other browsers, using svg's foreignObject.
As per that article, I added the following html to my Sencha Touch application just to see how it would render in the JavaFX WebView:
<svg width="400px" height="300px">
<defs>
<mask id="mask" maskUnits="userSpaceOnUse" maskContentUnits="userSpaceOnUse">
<image width="400px" height="300px" xlink:href="foo.png"></image>
</mask>
</defs>
<foreignObject width="400px" height="300px" style="mask: url(#mask);">
<div style="display:inline-block;background-color:blue;width:400px;height:300px">
</div>
</foreignObject>
</svg>
The masking image "foo.png" is a white image with some transparencies. When we were using -webkit-mask-image
, the mask image was black, but I inverted it as per the blog post's advice. This actually worked beautifully in Firefox, which I was hoping was good news (because previously our image masking wasn't working in Firefox). Firefox displayed a nice blue div masked by "foo.png". My long nightmare was over!
Except it wasn't. In the JavaFX WebView, it just displays a blue box. To make sure it had access to "foo.png", I tried it as just a regular old <img>
tag, and that displays the image, so that's not the issue.
I did find this bug on OpenJDK, which sounds pretty similar to my issue, although it's still listed as "open" and didn't lead me very far.
Also, I found this question in which the author is trying to do something similar. The difference between this and what I'm trying to do is that, in that solution, he wants to display in image and mask/show certain parts of that image. What I'm trying to do is have a colored div, masked by an image with transparencies. Here's an example:
.something-red {
background-color: red;
width: 400px;
height: 365px;
-webkit-mask-size: 400px;
-webkit-mask-image: url(http://i.imgur.com/cWSCfGl.png);
}
<div class='something-red'>
</div>
My temporary solution has been to replace our image masks with static images that have been pre-colored (by me). This doesn't look as good as it did when we were able to mask images, and of course it also means I'd have to create duplicate images with different colors for any color scheme we wanted to use.
Is there a way to achieve functionality like -webkit-mask-image
in the JavaFX WebView browser? Thank you so much for taking the time to read my question, hopefully I've provided enough information!