Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fec405a3 authored by Tobias Sargeant's avatar Tobias Sargeant
Browse files

[webview] Add a force dark WebSetting

Force dark mode is a tristate:

- never invert colours for webview content
- always invert colours
- follow the parent view behaviour

Test: CTS test, after WebView implementation.
Bug: 120599879
Change-Id: Ib11358bc3a3cbc5e55c0ec184084c7d205acf60c
parent f9632160
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -52988,6 +52988,7 @@ package android.webkit {
    method public abstract boolean getDomStorageEnabled();
    method public abstract java.lang.String getFantasyFontFamily();
    method public abstract java.lang.String getFixedFontFamily();
    method public abstract int getForceDarkMode();
    method public abstract boolean getJavaScriptCanOpenWindowsAutomatically();
    method public abstract boolean getJavaScriptEnabled();
    method public abstract android.webkit.WebSettings.LayoutAlgorithm getLayoutAlgorithm();
@@ -53034,6 +53035,7 @@ package android.webkit {
    method public abstract deprecated void setEnableSmoothTransition(boolean);
    method public abstract void setFantasyFontFamily(java.lang.String);
    method public abstract void setFixedFontFamily(java.lang.String);
    method public abstract void setForceDarkMode(int);
    method public abstract deprecated void setGeolocationDatabasePath(java.lang.String);
    method public abstract void setGeolocationEnabled(boolean);
    method public abstract void setJavaScriptCanOpenWindowsAutomatically(boolean);
@@ -53064,6 +53066,9 @@ package android.webkit {
    method public abstract void setUserAgentString(java.lang.String);
    method public abstract boolean supportMultipleWindows();
    method public abstract boolean supportZoom();
    field public static final int FORCE_DARK_AUTO = 0; // 0x0
    field public static final int FORCE_DARK_OFF = -1; // 0xffffffff
    field public static final int FORCE_DARK_ON = 1; // 0x1
    field public static final int LOAD_CACHE_ELSE_NETWORK = 1; // 0x1
    field public static final int LOAD_CACHE_ONLY = 3; // 0x3
    field public static final int LOAD_DEFAULT = -1; // 0xffffffff
+53 −0
Original line number Diff line number Diff line
@@ -224,6 +224,42 @@ public abstract class WebSettings {
     */
    public static final int MIXED_CONTENT_COMPATIBILITY_MODE = 2;

    /** @hide */
    @IntDef(prefix = { "FORCE_DARK_" }, value = {
            FORCE_DARK_OFF,
            FORCE_DARK_AUTO,
            FORCE_DARK_ON
    })
    @Retention(RetentionPolicy.SOURCE)
    public @interface ForceDarkMode {}

    /**
     * Used with {@link #setForceDarkMode}
     *
     * Disable force dark, irrespective of the force dark mode of the WebView parent. In this mode,
     * WebView content will always be rendered as-is, regardless of whether native views are being
     * automatically darkened.
     */
    public static final int FORCE_DARK_OFF = -1;

    /**
     * Used with {@link #setForceDarkMode}
     *
     * Enable force dark, dependent on the state of the WebView parent. If the WebView parent view
     * is being automatically rendered in dark mode, then WebView content will be rendered so as to
     * emulate a dark theme. WebViews that are not attached to the view hierarchy will not be
     * inverted.
     */
    public static final int FORCE_DARK_AUTO = 0;

    /**
     * Used with {@link #setForceDarkMode}
     *
     * Unconditionally enable force dark. In this mode WebView content will always be rendered so
     * as to emulate a dark theme.
     */
    public static final int FORCE_DARK_ON = +1;

    /**
     * Enables dumping the pages navigation cache to a text file. The default
     * is {@code false}.
@@ -1428,6 +1464,23 @@ public abstract class WebSettings {
    public abstract boolean getSafeBrowsingEnabled();


    /**
     * Set the force dark mode for this WebView.
     */
    public void setForceDarkMode(@ForceDarkMode int forceDarkMode) {
        // Stub implementation to satisfy Roboelectrc shadows that don't override this yet.
    }

    /**
     * Get the force dark mode for this WebView.
     *
     * @return the currently set force dark mode.
     */
    public @ForceDarkMode int getForceDarkMode() {
        // Stub implementation to satisfy Roboelectrc shadows that don't override this yet.
        return FORCE_DARK_AUTO;
    }

    /**
     * @hide
     */