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
8090547: Allow for transparent backgrounds in WebView #563
8090547: Allow for transparent backgrounds in WebView #563
Conversation
👋 Welcome back jpereda! A progress list of the required criteria for merging this PR into |
Webrevs
|
/reviewers 2 |
@kevinrushforth |
@kevinrushforth has indicated that a compatibility and specification (CSR) request is needed for this pull request. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This new API warrants a brief discussion on the mailing list prior to review. Some things to think about:
-
Should the new
WebView
property be aColor
or should it be aPaint
? -
You propose to add a new CSS element,
-fx-page-fill
. Do we need it or can one of the existing elements work (e.g.,-fx-background-color
)? If we do end up adding a new element, you will need to document it incssref.html
.
* | ||
* Default color: White | ||
* | ||
* @since JavaFX 17 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We no longer use JavaFX
in the version for @since
commands. And it's too late for 17, so this should be:
* @since 18
Mailing list message from José Pereda on openjfx-dev:
`Paint`? WebPage.setBackgroundColor calls: JNIEXPORT void JNICALL Java_com_sun_webkit_WebPage_twkSetBackgroundColor which only admits an int value for the background color (the hash value of frame->view()->setBaseBackgroundColor(...) so I don't see a way to apply anything different than a plain color (with For that reason, I didn't use Paint, but just Color.
can one of the existing elements work (e.g., `-fx-background-color`)? If we If we can't use Paint that also means that we can't use
Ok, I'll fix that. On Fri, Jul 2, 2021 at 2:50 PM Kevin Rushforth <kcr at openjdk.java.net> wrote: -- |
1 similar comment
Mailing list message from José Pereda on openjfx-dev:
`Paint`? WebPage.setBackgroundColor calls: JNIEXPORT void JNICALL Java_com_sun_webkit_WebPage_twkSetBackgroundColor which only admits an int value for the background color (the hash value of frame->view()->setBaseBackgroundColor(...) so I don't see a way to apply anything different than a plain color (with For that reason, I didn't use Paint, but just Color.
can one of the existing elements work (e.g., `-fx-background-color`)? If we If we can't use Paint that also means that we can't use
Ok, I'll fix that. On Fri, Jul 2, 2021 at 2:50 PM Kevin Rushforth <kcr at openjdk.java.net> wrote: -- |
Mailing list message from Johan Vos on openjfx-dev: On Fri, Jul 2, 2021 at 2:50 PM Kevin Rushforth <kcr at openjdk.java.net> wrote:
This is one of the old issues that keeps popping up regularly, and that - Johan |
I'll throw a party when this finally gets fixed! See also: javafxports/openjdk-jfx#277 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The API for the new property looks fine. I left a couple comments on the javadoc.
You can create a Draft CSR when you get a chance. You still need to update cssref.html
and that will need to be part of the CSR.
* Specifies the background color of the webPage, allowing | ||
* some or full transparency. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You might want to split this into two sentences, with the part about allowing for transparent being in the second sentence. Another thing you should indicate is how this interacts with the background color in the HTML file (I presume the one in the file takes precedence?). Also "web page" should be two words.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
* Specifies the background color of the webPage, allowing | ||
* some or full transparency. | ||
* | ||
* Default color: White |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use an @defaultValue
javadoc tag here:
@defaultValue {@code Color.WHITE}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Since my comment may have gone unnoticed because I had to check the aggreement box first: |
@kevinrushforth the CSR was already created here: https://bugs.openjdk.java.net/browse/JDK-8269848 Do I need to update its code with the latest changes of this PR? As for the |
Yes, although you can "batch up" the changes if you like until the review is far enough along that the API is unlikely to change. One comment on the CSR is that the specification section is concerned with interface changes. So you can (and should) elide the body of any public methods and just leave the method signature and API docs. For properties, the private field is often included in the CSR, since that's what you hang the API docs on. For the styleable property, it should be sufficient to include the diffs for
Add it as a commit to this PR (btw, the JBS ID of the CSR is never used directly as an issue resolved by a PR; it is instead associated with a bug or enhancement that is). |
Ok, thanks for the clarifications. I've updated the CSR accordingly, and pushed the change for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left a couple more comments on the API docs, and a few comments / questions on the implementation. I've tested this on Windows, but still need to test on the other two platforms.
modules/javafx.graphics/src/main/java/com/sun/prism/es2/ES2Graphics.java
Outdated
Show resolved
Hide resolved
modules/javafx.web/src/main/java/com/sun/javafx/webkit/prism/WCGraphicsPrismContext.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just have a couple remaining comments.
modules/javafx.web/src/main/java/com/sun/javafx/webkit/prism/WCGraphicsPrismContext.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left a few minor comments, but otherwise this all looks good to me.
Once you make the one requested change to remove the paragraph break, you can also update the CSR with that change and the two other changes I requested in the CSR, and then move the CSR to proposed.
@@ -93,6 +94,7 @@ | |||
private int width, height; | |||
|
|||
private int fontSmoothingType; | |||
private int backgroundIntRgba = 0xFFFFFFFF; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add back the comment about this being Color.WHITE?
|
||
private static int getIntRgba(Color color) { | ||
if (color == null) { | ||
return -1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe: return 0xFFFFFFFF;
? or else assign color = Color.WHITE;
and fall through?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably better then to create a constant?
private static final int DEFAULT_BACKGROUND_INT_RGBA = 0xFFFFFFFF; // Color.WHITE
* level of transparency. | ||
* | ||
* <p>However, if the HTML content being loaded sets its own |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I looked at the generated javadoc and this will read better without a paragraph break.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I looked at the generated javadoc and this will read better without a paragraph break.
When you remove the paragraph break, please also remove the blank line to make it clearer to future readers of the code that it is intended to be part of the same paragraph as the previous sentence.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've also updated the CSR
|
||
private static int getIntRgba(Color color) { | ||
if (color == null) { | ||
return -1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably better then to create a constant?
private static final int DEFAULT_BACKGROUND_INT_RGBA = 0xFFFFFFFF; // Color.WHITE
* level of transparency. | ||
* | ||
* <p>However, if the HTML content being loaded sets its own |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Latest changes look good. The new test fails for me on Linux, though. I tried it both on my Ubuntu 20.04 VM and on an older Ubuntu 16.0.4 physical machine.
I don't think it's just a test issue, either. When the OpenGL pipeline I get some odd looking ghosting around the text while the test is scrolling. Have you tested this on Linux?
Yes, I have been testing on MacOS (11.5.1), Linux (Ubuntu 20.04) and Windows (10) with a manual test. I do a quick visual test with transparent, translucent and solid color, including scrolling and selecting some text. However, the On MacOS and Windows it works fine. On Linux I see this "ghosting" while scrolling, but snapshots are taken on a steady position, and it shouldn't be there. What assertion fails for you? Edit: I've done a few snapshots and now I see that the Linux font is taller and wider and the pixels that work fine on Mac/Windows are now failing on Linux. I'll see if I can fix that and use the same font. |
@kevinrushforth It should be fixed now, the test should pass on the three platforms. |
I'll test on all three platforms and report back. |
The test now passes on one of my Linux machines, but I still see the smearing of the text when scrolling. I took the html file from your test and used it in a simple interactive program using a transparent background that will show the problem. If you run the test program on either Mac or Linux (using the es2 pipeline) and scroll the window, you will see that the scroll area isn't cleared. I found that if the color has any alpha > 0 it works correctly. This means that something is behaving differently with fully transparent (alpha == 0) in the ES2 pipeline. It might be related to why you needed to change the initial fill color for the ES2 pipeline. |
Thanks for testing it, I can reproduce the issue indeed. I had my interactive test too which doesn't fail with alpha = 0, and comparing both tests I realise now that in my case I was using a transparent VBox instead of a Group as a container for the WebView, and later on when I created the system test, I removed such container. If you try:
that should work for you as well... Obviously there is an issue with alpha = 0 in case we use Group or not container at all, vs when we use a Region. The comment at Region::doComputeGeomBounds my be relevant though?
|
Somehow by accident I've found out that doing in
fixes the issue for the Group test (same for no container case). Ultimately, this is the same as calling twice After some testing, I modified this method to get it working with the expected single call with just this change:
which seems to indicate that Does this make sense? |
Interesting.
Even more interesting.
No, it doesn't make sense, since setting the mode to CLEAR before drawing the quad is the right order. The fact that it matters indicates that something very odd is happening with state management. Your experiment was the clue that allowed me to figure out the problem. The problem is that the call to Here is the proposed change:
This will need to be well tested on Linux and Mac (a full set of Robot tests). |
I verified that the above change works, and doesn't cause any regressions that I can see. |
Great finding, thanks for clarifying it. I've tested it successfully too. I'll commit it then. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good to me too.
@jperedadnr This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be:
You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 69 new commits pushed to the
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details. ➡️ To integrate this PR with the above commit message to the |
/integrate |
Going to push as commit f59a057.
Your commit was automatically rebased without conflicts. |
@jperedadnr Pushed as commit f59a057. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
Currently,
WebPage
has already a publicsetBackgroundColor()
method, but the class is not public. Therefore, public API is needed inWebView
to allow developers access to it.In line with the
fontSmoothingType
property, this PR provides public support for setting the background color of a WebPage, by adding apageFill
property, and a CSR is required.The color for the background, that can be opaque, transparent or with any level of opacity, can be set via code or via CSS using
-fx-page-fill
.Unit tests and a system test are provided.
Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jfx pull/563/head:pull/563
$ git checkout pull/563
Update a local copy of the PR:
$ git checkout pull/563
$ git pull https://git.openjdk.java.net/jfx pull/563/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 563
View PR using the GUI difftool:
$ git pr show -t 563
Using diff file
Download this PR as a diff file:
https://git.openjdk.java.net/jfx/pull/563.diff