Skip to content


8298167: Opacity in WebView not working anymore
Browse files Browse the repository at this point in the history
Backport-of: 8136b11
  • Loading branch information
kevinrushforth committed Feb 11, 2023
1 parent 822dfe3 commit e0b7eda
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -610,8 +610,10 @@ bool GraphicsContextJava::supportsTransparencyLayers() const
return true;

void GraphicsContextJava::beginPlatformTransparencyLayer(float opacity)
void GraphicsContextJava::beginTransparencyLayer(float opacity)

if (paintingDisabled())

Expand All @@ -620,13 +622,15 @@ void GraphicsContextJava::beginPlatformTransparencyLayer(float opacity)
<< opacity;

void GraphicsContextJava::endPlatformTransparencyLayer()
void GraphicsContextJava::endTransparencyLayer()
if (paintingDisabled())

<< (jint)com_sun_webkit_graphics_GraphicsDecoder_ENDTRANSPARENCYLAYER;


void GraphicsContextJava::clearRect(const FloatRect& rect)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ class WEBCORE_EXPORT GraphicsContextJava final : public GraphicsContext {
FloatRect roundToDevicePixels(const FloatRect& frect, RoundingMode) override;

bool supportsTransparencyLayers() const override;
void beginPlatformTransparencyLayer(float opacity);
void endPlatformTransparencyLayer();
void beginTransparencyLayer(float opacity) override;
void endTransparencyLayer() override;

void translate(float x, float y) override;
void rotate(float radians) override;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit if you need additional information or have any
* questions.

package test.javafx.scene.web;

import com.sun.webkit.WebPage;
import com.sun.webkit.WebPageShim;
import java.awt.Color;
import java.awt.image.BufferedImage;
import javafx.scene.web.WebEngineShim;
import org.junit.Test;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

public class OpacityTest extends TestBase {
* @test
* @bug 8298167
* summary
* Loads black-background areas with different opacity values: 1.0, 0.5, and 0.0.
* Checks if the areas are rendered with black, gray, and white colors accordigly.
* Colors are taken from the center of each area.
@Test public void testOpacity() {
loadContent("<html>\n" +
"<body style='margin: 0px;'>\n" +
"<p style='opacity: 1.0; height: 100px; margin: 0px; background-color:#000; color: #fff;'>text</p>\n" +
"<p style='opacity: 0.5; height: 100px; margin: 0px; background-color:#000; color: #fff;'>text</p>\n" +
"<p style='opacity: 0.0; height: 100px; margin: 0px; background-color:#000; color: #fff;'>text</p>\n" +
"</body>\n" +
submit(() -> {
final WebPage webPage = WebEngineShim.getPage(getEngine());
final BufferedImage img = WebPageShim.paint(webPage, 0, 0, 800, 600);

final Color pixelAt400x50 = new Color(img.getRGB(400, 50), true);
assertTrue("Color should be black:" + pixelAt400x50, isColorsSimilar(Color.BLACK, pixelAt400x50, 1));
final Color pixelAt400x150 = new Color(img.getRGB(400, 150), true);
assertTrue("Color should be gray:" + pixelAt400x150, isColorsSimilar(Color.GRAY, pixelAt400x150, 1));
final Color pixelAt400x250 = new Color(img.getRGB(400, 250), true);
assertTrue("Color should be white:" + pixelAt400x250, isColorsSimilar(Color.WHITE, pixelAt400x250, 1));

1 comment on commit e0b7eda

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.