Truly independent web browser
LibWebCommon+LibWeb: Keep a dark color scheme’s selection color
sideshowbarker2919bf87a5e5
diff --git a/Libraries/LibWeb/Painting/PaintingRustBridge.cpp b/Libraries/LibWeb/Painting/PaintingRustBridge.cppindex a63de3a8797..6721848af2a 100644--- a/Libraries/LibWeb/Painting/PaintingRustBridge.cpp+++ b/Libraries/LibWeb/Painting/PaintingRustBridge.cpp@@ -610,12 +610,13 @@ Optional<DisplayListRecording> start_rust_display_list_recording(Layout::BegunReinputs.outline_auto_color = CSS::SystemColor::accent_color(CSS::PreferredColorScheme::Auto);auto palette = document.page().palette();inputs.palette_is_dark = palette.is_dark();- inputs.selection_background_from_palette = CSS::SystemColor::transform_selection_background_color(palette.selection());- inputs.selection_background_light = CSS::SystemColor::transform_selection_background_color(CSS::SystemColor::highlight(CSS::PreferredColorScheme::Light));- inputs.selection_background_dark = CSS::SystemColor::transform_selection_background_color(CSS::SystemColor::highlight(CSS::PreferredColorScheme::Dark));- inputs.inactive_selection_background_from_palette = CSS::SystemColor::transform_selection_background_color(palette.inactive_selection());- inputs.inactive_selection_background_light = CSS::SystemColor::transform_selection_background_color(CSS::SystemColor::inactive_highlight(CSS::PreferredColorScheme::Light));- inputs.inactive_selection_background_dark = CSS::SystemColor::transform_selection_background_color(CSS::SystemColor::inactive_highlight(CSS::PreferredColorScheme::Dark));+ auto palette_color_scheme = palette.is_dark() ? CSS::PreferredColorScheme::Dark : CSS::PreferredColorScheme::Light;+ inputs.selection_background_from_palette = CSS::SystemColor::transform_selection_background_color(palette.selection(), palette_color_scheme);+ inputs.selection_background_light = CSS::SystemColor::transform_selection_background_color(CSS::SystemColor::highlight(CSS::PreferredColorScheme::Light), CSS::PreferredColorScheme::Light);+ inputs.selection_background_dark = CSS::SystemColor::transform_selection_background_color(CSS::SystemColor::highlight(CSS::PreferredColorScheme::Dark), CSS::PreferredColorScheme::Dark);+ inputs.inactive_selection_background_from_palette = CSS::SystemColor::transform_selection_background_color(palette.inactive_selection(), palette_color_scheme);+ inputs.inactive_selection_background_light = CSS::SystemColor::transform_selection_background_color(CSS::SystemColor::inactive_highlight(CSS::PreferredColorScheme::Light), CSS::PreferredColorScheme::Light);+ inputs.inactive_selection_background_dark = CSS::SystemColor::transform_selection_background_color(CSS::SystemColor::inactive_highlight(CSS::PreferredColorScheme::Dark), CSS::PreferredColorScheme::Dark);inputs.document_has_supported_color_schemes = document.supported_color_schemes().has_value();if (auto schemes = document.supported_color_schemes(); schemes.has_value())inputs.document_supports_light_or_dark = schemes->contains_slow("light"_utf16) || schemes->contains_slow("dark"_utf16);diff --git a/Libraries/LibWebCommon/CSS/SystemColor.cpp b/Libraries/LibWebCommon/CSS/SystemColor.cppindex 62b2421cb56..b47dca5ede6 100644--- a/Libraries/LibWebCommon/CSS/SystemColor.cpp+++ b/Libraries/LibWebCommon/CSS/SystemColor.cpp@@ -87,11 +87,16 @@ Color gray_text(PreferredColorScheme)return Color(128, 128, 128);}-Color transform_selection_background_color(Color color)+Color transform_selection_background_color(Color color, PreferredColorScheme scheme){if (color.alpha() < 255)return color;+ // NB: The translucent color below looks like `color` only over white. Over a dark page it comes out much darker, so+ // a dark color scheme keeps the color as it is, at 80% opacity.+ if (scheme == PreferredColorScheme::Dark)+ return color.with_alpha(204);+constexpr int start_alpha = 153; // 60%constexpr int end_alpha = 204; // 80%constexpr int alpha_increment = 17;diff --git a/Libraries/LibWebCommon/CSS/SystemColor.h b/Libraries/LibWebCommon/CSS/SystemColor.hindex 5cfe1ec5c2e..523e4b0485d 100644--- a/Libraries/LibWebCommon/CSS/SystemColor.h+++ b/Libraries/LibWebCommon/CSS/SystemColor.h@@ -24,7 +24,7 @@ WEBCOMMON_API Color canvas_text(PreferredColorScheme);WEBCOMMON_API Color field(PreferredColorScheme);WEBCOMMON_API Color field_text(PreferredColorScheme);WEBCOMMON_API Color gray_text(PreferredColorScheme);-WEBCOMMON_API Color transform_selection_background_color(Color);+WEBCOMMON_API Color transform_selection_background_color(Color, PreferredColorScheme);WEBCOMMON_API Color highlight(PreferredColorScheme);// A muted highlight for selections in windows that do not have focus.WEBCOMMON_API Color inactive_highlight(PreferredColorScheme);