All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.com.multiplatform.webview.setting.PlatformWebSettings.kt Maven / Gradle / Ivy

There is a newer version: 1.9.40-alpha04
Show newest version
package com.multiplatform.webview.setting

/**
 * Created By Kevin Zou On 2023/9/20
 */
sealed class PlatformWebSettings {
    /**
     * Android web settings
     */
    data class AndroidWebSettings(
        /**
         * whether the WebView should support zooming using its on-screen zoom
         * controls and gestures. The particular zoom mechanisms that should be used
         * can be set with {@link #setBuiltInZoomControls}. This setting does not
         * affect zooming performed using the {@link WebView#zoomIn()} and
         * {@link WebView#zoomOut()} methods. The default is {@code true}.
         *
         * @param support whether the WebView should support zoom
         */
        var supportZoom: Boolean = true,
        /**
         * Enables or disables file access within WebView.
         * Note that this enables or disables file system access only. Assets and resources
         * are still accessible using file:///android_asset and file:///android_res.
         * 

* Note: Apps should not open {@code file://} URLs from any external source in * WebView, don't enable this if your app accepts arbitrary URLs from external sources. * It's recommended to always use * * androidx.webkit.WebViewAssetLoader to access files including assets and resources over * {@code http(s)://} schemes, instead of {@code file://} URLs. To prevent possible security * issues targeting {@link android.os.Build.VERSION_CODES#Q} and earlier, you should explicitly * set this value to {@code false}. *

* The default value is {@code true} for apps targeting * {@link android.os.Build.VERSION_CODES#Q} and below, and {@code false} when targeting * {@link android.os.Build.VERSION_CODES#R} and above. */ var allowFileAccess: Boolean = false, /** * The text zoom of the page in percent. The default is 100. * * @param textZoom the text zoom in percent */ var textZoom: Int = 100, /** * Whether the WebView should enable support for the "viewport" * HTML meta tag or should use a wide viewport. * When the value of the setting is {@code false}, the layout width is always set to the * width of the WebView control in device-independent (CSS) pixels. * When the value is {@code true} and the page contains the viewport meta tag, the value * of the width specified in the tag is used. If the page does not contain the tag or * does not provide a width, then a wide viewport will be used. * */ var useWideViewPort: Boolean = false, /** * The standard font family name. The default is "sans-serif". * * @param font a font family name */ var standardFontFamily: String = "sans-serif", /** * The default font size. The default is 16. * * @param size a non-negative integer between 1 and 72. Any number outside * the specified range will be pinned. */ var defaultFontSize: Int = 16, /** * Sets whether the WebView should load image resources. Note that this method * controls loading of all images, including those embedded using the data * URI scheme. Use {@link #setBlockNetworkImage} to control loading only * of images specified using network URI schemes. Note that if the value of this * setting is changed from {@code false} to {@code true}, all images resources referenced * by content currently displayed by the WebView are loaded automatically. * The default is {@code true}. * * @param flag whether the WebView should load image resources */ var loadsImagesAutomatically: Boolean = true, /** * Control whether algorithmic darkening is allowed. * *

* Note: This API and the behaviour described only apply to apps with * {@code targetSdkVersion} ≥ {@link android.os.Build.VERSION_CODES#TIRAMISU}. * *

* WebView always sets the media query {@code prefers-color-scheme} according to the app's * theme attribute {@link android.R.styleable#Theme_isLightTheme isLightTheme}, i.e. * {@code prefers-color-scheme} is {@code light} if isLightTheme is true or not specified, * otherwise it is {@code dark}. This means that the web content's light or dark style will * be applied automatically to match the app's theme if the content supports it. * *

* Algorithmic darkening is disallowed by default. *

* If the app's theme is dark and it allows algorithmic darkening, WebView will attempt to * darken web content using an algorithm, if the content doesn't define its own dark styles * and doesn't explicitly disable darkening. * *

* If Android is applying Force Dark to WebView then WebView will ignore the value of * this setting and behave as if it were set to true. * *

* The deprecated {@link #setForceDark} and related API are no-ops in apps with * {@code targetSdkVersion} ≥ {@link android.os.Build.VERSION_CODES#TIRAMISU}, * but they still apply to apps with * {@code targetSdkVersion} < {@link android.os.Build.VERSION_CODES#TIRAMISU}. * *

* The below table summarizes how APIs work with different apps. * *

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
AppWeb content which uses {@code prefers-color-scheme}Web content which does not use {@code prefers-color-scheme}
App with {@code isLightTheme} True or not setRenders with the light theme defined by the content author.Renders with the default styling defined by the content author.
App with Android forceDark in effectRenders with the dark theme defined by the content author.Renders with the styling modified to dark colors by an algorithm * if allowed by the content author.
App with {@code isLightTheme} False, * {@code targetSdkVersion} < {@link android.os.Build.VERSION_CODES#TIRAMISU}, * and has {@code FORCE_DARK_AUTO}Renders with the dark theme defined by the content author.Renders with the default styling defined by the content author.
App with {@code isLightTheme} False, * {@code targetSdkVersion} ≥ {@link android.os.Build.VERSION_CODES#TIRAMISU}, * and {@code setAlgorithmicDarkening(false)}Renders with the dark theme defined by the content author.Renders with the default styling defined by the content author.
App with {@code isLightTheme} False, * {@code targetSdkVersion} ≥ {@link android.os.Build.VERSION_CODES#TIRAMISU}, * and {@code setAlgorithmicDarkening(true)}Renders with the dark theme defined by the content author.Renders with the styling modified to dark colors by an algorithm if allowed * by the content author.
*

* */ var isAlgorithmicDarkeningAllowed: Boolean = false, /** * whether Safe Browsing is enabled. Safe Browsing allows WebView to * protect against malware and phishing attacks by verifying the links. */ var safeBrowsingEnabled: Boolean = true, /** * Whether the DOM storage API is enabled. The default value is {@code false}. */ var domStorageEnabled: Boolean = false, ) : PlatformWebSettings() /** * Desktop web settings */ data class DesktopWebSettings( var offScreenRendering: Boolean = false, var transparent: Boolean = false, var disablePopupWindows: Boolean = false, ) : PlatformWebSettings() /** * IOS web settings */ data object IOSWebSettings : PlatformWebSettings() }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy