changeset 11093:ece2be9fd8ff

8207387: WebView is not rendering html checkbox and radio buttons Reviewed-by: kcr, mbilla
author arajkumar
date Thu, 19 Jul 2018 11:08:53 +0530
parents c6527569e987
children a3e180fb1506 e477d12ec31e
files modules/javafx.web/src/main/java/com/sun/javafx/webkit/theme/RenderThemeImpl.java modules/javafx.web/src/shims/java/com/sun/javafx/webkit/prism/PrismInvokerShim.java modules/javafx.web/src/shims/java/com/sun/webkit/WebPageShim.java modules/javafx.web/src/test/java/test/javafx/scene/web/FormControlsTest.java
diffstat 4 files changed, 149 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/modules/javafx.web/src/main/java/com/sun/javafx/webkit/theme/RenderThemeImpl.java	Fri Jul 27 06:41:20 2018 -0700
+++ b/modules/javafx.web/src/main/java/com/sun/javafx/webkit/theme/RenderThemeImpl.java	Thu Jul 19 11:08:53 2018 +0530
@@ -261,9 +261,6 @@
     {
         ensureNotDefault();
 
-        if (extParams == null) {
-            return null;
-        }
         FormControl fc = pool.get(id);
         WidgetType type = WidgetType.convert(widgetIndex);
 
@@ -317,26 +314,29 @@
         if (ctrl.isManaged()) {
             ctrl.setManaged(false);
         }
-        if (type == WidgetType.SLIDER) {
-            Slider slider = (Slider)ctrl;
-            extParams.order(ByteOrder.nativeOrder());
-            slider.setOrientation(extParams.getInt()==0
-                ? Orientation.HORIZONTAL
-                : Orientation.VERTICAL);
-            slider.setMax(extParams.getFloat());
-            slider.setMin(extParams.getFloat());
-            slider.setValue(extParams.getFloat());
-        } else if (type == WidgetType.PROGRESSBAR) {
-            ProgressBar progress = (ProgressBar)ctrl;
-            extParams.order(ByteOrder.nativeOrder());
-            progress.setProgress(extParams.getInt() == 1
-                    ? extParams.getFloat()
-                    : progress.INDETERMINATE_PROGRESS);
-        } else if (type == WidgetType.METER) {
-            ProgressBar progress = (ProgressBar) ctrl;
-            extParams.order(ByteOrder.nativeOrder());
-            progress.setProgress(extParams.getFloat());
-            progress.setStyle(getMeterStyle(extParams.getInt()));
+
+        if (extParams != null) {
+            if (type == WidgetType.SLIDER) {
+                Slider slider = (Slider)ctrl;
+                extParams.order(ByteOrder.nativeOrder());
+                slider.setOrientation(extParams.getInt()==0
+                    ? Orientation.HORIZONTAL
+                    : Orientation.VERTICAL);
+                slider.setMax(extParams.getFloat());
+                slider.setMin(extParams.getFloat());
+                slider.setValue(extParams.getFloat());
+            } else if (type == WidgetType.PROGRESSBAR) {
+                ProgressBar progress = (ProgressBar)ctrl;
+                extParams.order(ByteOrder.nativeOrder());
+                progress.setProgress(extParams.getInt() == 1
+                        ? extParams.getFloat()
+                        : progress.INDETERMINATE_PROGRESS);
+            } else if (type == WidgetType.METER) {
+                ProgressBar progress = (ProgressBar) ctrl;
+                extParams.order(ByteOrder.nativeOrder());
+                progress.setProgress(extParams.getFloat());
+                progress.setStyle(getMeterStyle(extParams.getInt()));
+            }
         }
         return new FormControlRef(fc);
     }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/modules/javafx.web/src/shims/java/com/sun/javafx/webkit/prism/PrismInvokerShim.java	Thu Jul 19 11:08:53 2018 +0530
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * 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 www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.sun.javafx.webkit.prism;
+
+public final class PrismInvokerShim {
+    public static void runOnRenderThread(final Runnable r) {
+        PrismInvoker.runOnRenderThread(r);
+    }
+}
+
--- a/modules/javafx.web/src/shims/java/com/sun/webkit/WebPageShim.java	Fri Jul 27 06:41:20 2018 -0700
+++ b/modules/javafx.web/src/shims/java/com/sun/webkit/WebPageShim.java	Thu Jul 19 11:08:53 2018 +0530
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -25,11 +25,27 @@
 
 package com.sun.webkit;
 
+import com.sun.javafx.webkit.prism.PrismInvokerShim;
 import com.sun.webkit.WebPage;
+import com.sun.webkit.graphics.WCRectangle;
 
 public class WebPageShim {
 
     public static int getFramesCount(WebPage page) {
         return page.test_getFramesCount();
     }
+
+    public static void renderContent(WebPage page, int x, int y, int w, int h) {
+        page.setBounds(x, y, w, h);
+        //  WebPage.updateContent will render WebPage into RenderQueue.
+        page.updateContent(new WCRectangle(x, y, w, h));
+        //  WebPage.paint will render RenderQueue into WCGraphicsContext in RenderThread.
+        PrismInvokerShim.runOnRenderThread(() -> {
+            // NullPointerException is expected because we are passing
+            // front buffer WCGraphicsContext as null.
+            try {
+                page.paint(null, x, y, w, h);
+            } catch (NullPointerException e) {}
+        });
+    }
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/modules/javafx.web/src/test/java/test/javafx/scene/web/FormControlsTest.java	Thu Jul 19 11:08:53 2018 +0530
@@ -0,0 +1,76 @@
+/*
+ * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * 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 www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package test.javafx.scene.web;
+
+import com.sun.webkit.WebPageShim;
+
+import java.util.Set;
+import javafx.scene.Node;
+import javafx.scene.web.WebEngineShim;
+
+import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+
+public class FormControlsTest extends TestBase {
+
+    private void testControlRendering(final String html, final String selector) {
+        loadContent(html);
+        submit(() -> {
+            // Render into null buffer.
+            WebPageShim.renderContent(WebEngineShim.getPage(getEngine()), 0, 0, 800, 600);
+            final Set<Node> elements = getView().lookupAll(selector);
+            assertEquals(
+                String.format("%s control doesn't exists as child of WebView", selector),
+                1,
+                elements.size());
+        });
+    }
+
+    @Test public void testRadioButtonRendering() {
+        testControlRendering("<input type='radio'/>", ".radio-button");
+    }
+
+    @Test public void testCheckboxRendering() {
+        testControlRendering("<input type='checkbox'/>", ".check-box");
+    }
+
+    @Test public void testButtonRendering() {
+        testControlRendering("<input type='button'/>", ".button");
+    }
+
+    @Test public void testTextFieldRendering() {
+        testControlRendering("<input type='text'/>", ".text-field");
+    }
+
+    @Test public void testMeterRendering() {
+        testControlRendering("<meter value='0.6'>60%</meter>", ".progress-bar");
+    }
+
+    @Test public void testSliderRendering() {
+        testControlRendering("<input type='range'/>", ".slider");
+    }
+}
+