Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8269848

Allow for transparent backgrounds in WebView

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P4 P4
    • jfx18
    • javafx
    • None
    • web
    • source, binary, behavioral
    • minimal
    • The default value for the new property preserves backward compatibility.
    • Java API
    • JDK

      Summary

      Add pageFill property to WebView, allowing setting its background color with any level of opacity.

      Problem

      WebPage::setBackgroundColor is a public method that allows setting the background color of the WebView, but WebPage has no public access.

      Current workarounds make use of reflection to get access to such method, as a first step to set the WebView's background color.

      Solution

      A new public property can be added to WebView to allow accessing WebPage::setBackgroundColor, in the same line as WebVew::fontSmoothingType property access WebPage::setFontSmoothingType. This property will allow setting the WebView color via code and also via CSS, so a private new styleable property is also required in WebView.

      Since the WebKit implementation only supports a single plain color, the property has to use Color and not Paint. The CSS element has to be a new one, and -fx-background-color can't be used.

      Specification

      The following property and methods are added to WebView:

      /**
       * Specifies the background color of the web page.
       *
       * With this property, the WebView control's background
       * can have any solid color, including some or complete
       * level of transparency.
       * However, if the HTML content being loaded set its own
       * background color, it will take precedence.
       *
       * @defaultValue {@code Color.WHITE}
       *
       * @since 18
       */
      private ObjectProperty<Color> pageFill;
      
      public final void setPageFill(Color value);
      
      public final Color getPageFill();
      
      public final ObjectProperty<Color> pageFillProperty();

      Including this styleable property (cssref.html) that only applies to WebView:

         <tr>
           <th class="propertyname" scope="row">-fx-page-fill</th>
             <td class="value"><a href="#typecolor" class="typeref">&lt;color&gt;</a></td>
             <td>white</td>
             <td>&nbsp;</td>
          </tr>

            jpereda Jose Pereda
            josmithjfx John Smith (Inactive)
            Kevin Rushforth
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: