webui-dev / webui

Use any web browser or WebView as GUI, with your preferred language in the backend and HTML5 in the frontend, all in a lightweight portable lib.
https://webui.me
MIT License
2.35k stars 144 forks source link

Accessibility Request: High Contrast Management #432

Closed malisipi closed 1 week ago

malisipi commented 1 week ago

Motivation

Most of browsers has a high contrast mode that enables if OS is themed by a high contrast theme. Supporting browsers default behavior is good for most usage cases however some devs might want to create custom high contrast theme to ensure high contrast theme is not breaking some UI. Because auto-theming is not working fine for all web applications. It has some problems;

Description

So WebUI needs a option to detect and change behavior of browser about high contrast. It may help give more accessibility for users and more freedom for developers.

Same App Example without High Contrast Theme Same App Example with High Contrast Theme
resim resim

Example code

I wrote some API examples for this situation. (API names and behavior should be re-considered to save consistent.)

(webui::window)->set_browser_high_contrast_support(bool is_enabled){
    // Enables/Disables the browser support
};
bool webui_is_high_contrast_enabled(){
    return bool; // Returns OS high contrast theme enabled
    // Will return OS high theme state, ***not browser support state***
};
function webui_is_high_contrast_enabled(){
    return bool; // Returns OS high contrast theme enabled
    // Will return OS high theme state, ***not browser support state***
}
hassandraga commented 1 week ago

Thank you for the suggestion. Yes it's a good point, but the issue is on Linux the WebUI library may depend on GTK (dev)... I'm not sure yet. Another thing is I don't know if all web browsers support this or not, let's test and see.

malisipi commented 1 week ago

Edge and Chrome is supporting the high contrast mode as I tested. However I am pretty sure about most of Chromium browsers and Firefox are supporting that by default. We should a flag to disable high contrast support.

To make WebUI independent, we can read GTK and KDE config files about the theme and if we detect high contrast enabled, we can report it to the application to disable or change CSS.

I would work about the API support.

malisipi commented 1 week ago

I can disable High Contrast support for Chrome, Firefox and Edge (and probably other untested chromium browser).

Firefox Chrome Edge
resim resim resim

Chromium browsers disable the feature by adding a command line flag however Firefox requires a change on profile. So I created a new profile for Firefox by adding "-NoHC" suffix.

resim

Now, I need to implement OS high contrast theme detection.