Truly independent web browser
LibWeb: Keep the own color of text in default selections
Andreas Kling5fccf59dbccd
diff --git a/Libraries/LibWeb/Rust/src/painting/chrome_geometry.rs b/Libraries/LibWeb/Rust/src/painting/chrome_geometry.rsindex a5af97d3f5d..fcf9bf71c98 100644--- a/Libraries/LibWeb/Rust/src/painting/chrome_geometry.rs+++ b/Libraries/LibWeb/Rust/src/painting/chrome_geometry.rs@@ -479,7 +479,7 @@ pub(crate) struct ScrollbarColors {/// The color behind what `slot` paints, as far as background colors tell: the canvas's, with the backgrounds of `slot`/// and its ancestors composited over it. Background images, and content of other boxes painted underneath, don't count.-pub(crate) fn estimated_backdrop_color(+fn estimated_backdrop_color(arena: &impl PaintRead,slot: NodeSlotId,root_background_source: RootBackgroundSource,diff --git a/Libraries/LibWeb/Rust/src/painting/record/mod.rs b/Libraries/LibWeb/Rust/src/painting/record/mod.rsindex 92395ae25ab..9066c958da3 100644--- a/Libraries/LibWeb/Rust/src/painting/record/mod.rs+++ b/Libraries/LibWeb/Rust/src/painting/record/mod.rs@@ -501,9 +501,6 @@ impl<O: Observer> PaintRecorder<'_, O> {paint::text::SelectionStyleAnswer {facts: crate::painting::host::FfiSelectionStyleFacts {background_color,- text_color: self- .readable_selection_text_color(node, style_source, background_color)- .into(),wash_color: background_color,..Default::default()},@@ -512,41 +509,6 @@ impl<O: Observer> PaintRecorder<'_, O> {}}- /// The color the default selection draws its text in, where the text's own color would be hard to read on the- /// selection: black or white, whichever stands out more. The text otherwise keeps its own color.- fn readable_selection_text_color(- &self,- node: crate::layout::node_data::NodeSlotId,- style_source: crate::layout::node_data::NodeSlotId,- selection_background: libgfx_rust::Color,- ) -> Option<libgfx_rust::Color> {- use libgfx_rust::Color;- // The contrast WCAG asks of normal-size text.- const MINIMUM_CONTRAST_RATIO: f64 = 4.5;-- let style = self.source.node_style_if_live(style_source)?;- let text_color = Color(style.inherited_text().webkit_text_fill_color);- let uncaptured = &self.inputs.uncaptured;- let backdrop = crate::painting::chrome_geometry::estimated_backdrop_color(- self.source,- node,- uncaptured.root_background_source,- uncaptured.canvas_color.blend(uncaptured.background_color),- );- let behind_text = backdrop.blend(selection_background);- if behind_text.contrast_ratio(behind_text.blend(text_color)) >= MINIMUM_CONTRAST_RATIO {- return None;- }- let (black, white) = (Color::from_rgb(0, 0, 0), Color::from_rgb(255, 255, 255));- Some(- if behind_text.contrast_ratio(black) >= behind_text.contrast_ratio(white) {- black- } else {- white- },- )- }-fn default_search_text_style(&self,node: crate::layout::node_data::NodeSlotId,diff --git a/Tests/LibWeb/Ref/expected/selection-default-color-scheme-ref.html b/Tests/LibWeb/Ref/expected/selection-default-color-scheme-ref.htmlindex 34037109954..1b8c1990f93 100644--- a/Tests/LibWeb/Ref/expected/selection-default-color-scheme-ref.html+++ b/Tests/LibWeb/Ref/expected/selection-default-color-scheme-ref.html@@ -7,7 +7,7 @@ p {}.selected-light {background: rgba(101, 2, 0, 0.8);- color: white;+ color: black;}.selected-dark {background: rgba(61, 174, 233, 0.5);diff --git a/Tests/LibWeb/Ref/expected/selection-default-link-ref.html b/Tests/LibWeb/Ref/expected/selection-default-link-ref.htmlindex f8ba6bad3e9..6b34ad4075c 100644--- a/Tests/LibWeb/Ref/expected/selection-default-link-ref.html+++ b/Tests/LibWeb/Ref/expected/selection-default-link-ref.html@@ -6,7 +6,7 @@ td {}.selected {background: rgba(101, 2, 0, 0.8);- color: white;+ color: #000000;text-decoration: none;}</style>diff --git a/Tests/LibWeb/Ref/expected/selection-default-normal-forced-dark-color-scheme-ref.html b/Tests/LibWeb/Ref/expected/selection-default-normal-forced-dark-color-scheme-ref.htmlindex 306b3669ba1..beb18f68d5c 100644--- a/Tests/LibWeb/Ref/expected/selection-default-normal-forced-dark-color-scheme-ref.html+++ b/Tests/LibWeb/Ref/expected/selection-default-normal-forced-dark-color-scheme-ref.html@@ -7,7 +7,7 @@ p {}.selected {background: rgba(101, 2, 0, 0.8);- color: white;+ color: black;}</style>diff --git a/Tests/LibWeb/Ref/expected/selection-with-image-ref.html b/Tests/LibWeb/Ref/expected/selection-with-image-ref.htmlindex 28e97742d48..3b6d2a3432c 100644--- a/Tests/LibWeb/Ref/expected/selection-with-image-ref.html+++ b/Tests/LibWeb/Ref/expected/selection-with-image-ref.html@@ -1,7 +1,7 @@<!DOCTYPE html><style>img { width: 50px; height: 50px; vertical-align: middle; }-.selected { background: rgba(101, 2, 0, 0.8); color: white; }+.selected { background: rgba(101, 2, 0, 0.8); color: black; }.img-wrapper {display: inline-block;position: relative;diff --git a/Tests/LibWeb/Screenshot/expected-macos/selection-text-color.png b/Tests/LibWeb/Screenshot/expected-macos/selection-text-color.pngindex c1cab0b8e7a..e44388ffc2d 100644Binary files a/Tests/LibWeb/Screenshot/expected-macos/selection-text-color.png and b/Tests/LibWeb/Screenshot/expected-macos/selection-text-color.png differdiff --git a/Tests/LibWeb/Screenshot/expected/selection-text-color.png b/Tests/LibWeb/Screenshot/expected/selection-text-color.pngindex 3f7b9e2e80d..93f88f9b9db 100644Binary files a/Tests/LibWeb/Screenshot/expected/selection-text-color.png and b/Tests/LibWeb/Screenshot/expected/selection-text-color.png differdiff --git a/Tests/LibWeb/Text/expected/display_list/page-focus-rendering.txt b/Tests/LibWeb/Text/expected/display_list/page-focus-rendering.txtindex 5e002175cf1..e612eeb871a 100644--- a/Tests/LibWeb/Text/expected/display_list/page-focus-rendering.txt+++ b/Tests/LibWeb/Text/expected/display_list/page-focus-rendering.txt@@ -13,7 +13,7 @@ FillRectWithRoundedCorners@s1/e0 rect=[0,0 70x20] color=rgb(255, 255, 255)FillRoundedRectRing@s1/e0 rect=[0,0 70x20] corner_radii=[4x4,4x4,4x4,4x4] widths=[1,1,1,1] color=rgb(118, 118, 118)DrawGlyphRun@s1/c0/e0 rect=[3,3 24x14] translation=[3,14] color=rgb(0, 0, 0) inline_clips=[clip=[3,4 8x12]]FillRect@s1/c0/e0 rect=[11,3 15x14] color=rgba(101, 2, 0, 0.8)-DrawGlyphRun@s1/c0/e0 rect=[3,3 24x14] translation=[3,14] color=rgb(255, 255, 255) inline_clips=[clip=[11,4 15x12]]+DrawGlyphRun@s1/c0/e0 rect=[3,3 24x14] translation=[3,14] color=rgb(0, 0, 0) inline_clips=[clip=[11,4 15x12]]FillRoundedRectRing@s1/e0 rect=[-2,-2 74x24] corner_radii=[6x6,6x6,6x6,6x6] widths=[2,2,2,2] color=rgb(61, 174, 233)DrawLine@s1/e0 from=[65,17] to=[67,15] color=rgba(255, 255, 255, 0.392) thickness=1 style=SolidDrawLine@s1/e0 from=[64,17] to=[67,14] color=rgba(0, 0, 0, 0.392) thickness=1 style=Solid@@ -22,7 +22,7 @@ DrawLine@s1/e0 from=[61,17] to=[67,11] color=rgba(0, 0, 0, 0.392) thickness=1 stDrawLine@s1/e0 from=[59,17] to=[67,9] color=rgba(255, 255, 255, 0.392) thickness=1 style=SolidDrawLine@s1/e0 from=[58,17] to=[67,8] color=rgba(0, 0, 0, 0.392) thickness=1 style=SolidFillRect@s1/e0 rect=[0,23 23x16] color=rgba(101, 2, 0, 0.8)-DrawGlyphRun@s1/e0 rect=[0,23 24x16] translation=[0,36] color=rgb(255, 255, 255)+DrawGlyphRun@s1/e0 rect=[0,23 24x16] translation=[0,36] color=rgb(0, 0, 0)-- unfocused --AccumulatedVisualContext Tree:@@ -39,7 +39,7 @@ FillRectWithRoundedCorners@s1/e0 rect=[0,0 70x20] color=rgb(255, 255, 255)FillRoundedRectRing@s1/e0 rect=[0,0 70x20] corner_radii=[4x4,4x4,4x4,4x4] widths=[1,1,1,1] color=rgb(118, 118, 118)DrawGlyphRun@s1/c0/e0 rect=[3,3 24x14] translation=[3,14] color=rgb(0, 0, 0) inline_clips=[clip=[3,4 8x12]]FillRect@s1/c0/e0 rect=[11,3 15x14] color=rgba(16, 16, 16, 0.667)-DrawGlyphRun@s1/c0/e0 rect=[3,3 24x14] translation=[3,14] color=rgb(255, 255, 255) inline_clips=[clip=[11,4 15x12]]+DrawGlyphRun@s1/c0/e0 rect=[3,3 24x14] translation=[3,14] color=rgb(0, 0, 0) inline_clips=[clip=[11,4 15x12]]DrawLine@s1/e0 from=[65,17] to=[67,15] color=rgba(255, 255, 255, 0.392) thickness=1 style=SolidDrawLine@s1/e0 from=[64,17] to=[67,14] color=rgba(0, 0, 0, 0.392) thickness=1 style=SolidDrawLine@s1/e0 from=[62,17] to=[67,12] color=rgba(255, 255, 255, 0.392) thickness=1 style=Solid@@ -47,7 +47,7 @@ DrawLine@s1/e0 from=[61,17] to=[67,11] color=rgba(0, 0, 0, 0.392) thickness=1 stDrawLine@s1/e0 from=[59,17] to=[67,9] color=rgba(255, 255, 255, 0.392) thickness=1 style=SolidDrawLine@s1/e0 from=[58,17] to=[67,8] color=rgba(0, 0, 0, 0.392) thickness=1 style=SolidFillRect@s1/e0 rect=[0,23 23x16] color=rgba(16, 16, 16, 0.667)-DrawGlyphRun@s1/e0 rect=[0,23 24x16] translation=[0,36] color=rgb(255, 255, 255)+DrawGlyphRun@s1/e0 rect=[0,23 24x16] translation=[0,36] color=rgb(0, 0, 0)-- focused again --AccumulatedVisualContext Tree:@@ -64,7 +64,7 @@ FillRectWithRoundedCorners@s1/e0 rect=[0,0 70x20] color=rgb(255, 255, 255)FillRoundedRectRing@s1/e0 rect=[0,0 70x20] corner_radii=[4x4,4x4,4x4,4x4] widths=[1,1,1,1] color=rgb(118, 118, 118)DrawGlyphRun@s1/c0/e0 rect=[3,3 24x14] translation=[3,14] color=rgb(0, 0, 0) inline_clips=[clip=[3,4 8x12]]FillRect@s1/c0/e0 rect=[11,3 15x14] color=rgba(101, 2, 0, 0.8)-DrawGlyphRun@s1/c0/e0 rect=[3,3 24x14] translation=[3,14] color=rgb(255, 255, 255) inline_clips=[clip=[11,4 15x12]]+DrawGlyphRun@s1/c0/e0 rect=[3,3 24x14] translation=[3,14] color=rgb(0, 0, 0) inline_clips=[clip=[11,4 15x12]]FillRoundedRectRing@s1/e0 rect=[-2,-2 74x24] corner_radii=[6x6,6x6,6x6,6x6] widths=[2,2,2,2] color=rgb(61, 174, 233)DrawLine@s1/e0 from=[65,17] to=[67,15] color=rgba(255, 255, 255, 0.392) thickness=1 style=SolidDrawLine@s1/e0 from=[64,17] to=[67,14] color=rgba(0, 0, 0, 0.392) thickness=1 style=Solid@@ -73,7 +73,7 @@ DrawLine@s1/e0 from=[61,17] to=[67,11] color=rgba(0, 0, 0, 0.392) thickness=1 stDrawLine@s1/e0 from=[59,17] to=[67,9] color=rgba(255, 255, 255, 0.392) thickness=1 style=SolidDrawLine@s1/e0 from=[58,17] to=[67,8] color=rgba(0, 0, 0, 0.392) thickness=1 style=SolidFillRect@s1/e0 rect=[0,23 23x16] color=rgba(101, 2, 0, 0.8)-DrawGlyphRun@s1/e0 rect=[0,23 24x16] translation=[0,36] color=rgb(255, 255, 255)+DrawGlyphRun@s1/e0 rect=[0,23 24x16] translation=[0,36] color=rgb(0, 0, 0)-- caret, focused --AccumulatedVisualContext Tree:diff --git a/Tests/LibWeb/Text/expected/display_list/selection-default-keeps-text-color.txt b/Tests/LibWeb/Text/expected/display_list/selection-default-keeps-text-color.txtnew file mode 100644index 00000000000..ba3255a94a3--- /dev/null+++ b/Tests/LibWeb/Text/expected/display_list/selection-default-keeps-text-color.txt@@ -0,0 +1,3 @@+off-black: selection rgba(101, 2, 0, 0.8), text rgb(26, 26, 46)+light: selection rgba(101, 2, 0, 0.8), text rgb(244, 244, 244)+decorated: selection rgba(101, 2, 0, 0.8), text rgb(26, 26, 46)diff --git a/Tests/LibWeb/Text/expected/display_list/selection-default-text-contrast.txt b/Tests/LibWeb/Text/expected/display_list/selection-default-text-contrast.txtdeleted file mode 100644index 7452ad2dbe8..00000000000--- a/Tests/LibWeb/Text/expected/display_list/selection-default-text-contrast.txt+++ /dev/null@@ -1,3 +0,0 @@-off-black: selection rgba(101, 2, 0, 0.8), text rgb(255, 255, 255)-light: selection rgba(101, 2, 0, 0.8), text rgb(244, 244, 244)-decorated: selection rgba(101, 2, 0, 0.8), text rgb(255, 255, 255)diff --git a/Tests/LibWeb/Text/expected/display_list/text-decoration-underline-partial-selection.txt b/Tests/LibWeb/Text/expected/display_list/text-decoration-underline-partial-selection.txtindex 8c26a1e8aa6..69ac0baba60 100644--- a/Tests/LibWeb/Text/expected/display_list/text-decoration-underline-partial-selection.txt+++ b/Tests/LibWeb/Text/expected/display_list/text-decoration-underline-partial-selection.txt@@ -13,6 +13,6 @@ DrawGlyphRun@s1/e0 rect=[8,-17 169x100] translation=[8,63] color=rgb(0, 0, 0) inDrawLine@s1/e0 from=[116,70] to=[153,70] color=rgb(0, 0, 0) thickness=10 style=SolidDrawLine@s1/e0 from=[165,70] to=[177,70] color=rgb(0, 0, 0) thickness=10 style=SolidFillRect@s1/e0 rect=[69,-17 47x100] color=rgba(101, 2, 0, 0.8)-DrawGlyphRun@s1/e0 rect=[8,-17 169x100] translation=[8,63] color=rgb(255, 255, 255) inline_clips=[clip=[69,-15 47x91]]-DrawLine@s1/e0 from=[109,70] to=[116,70] color=rgb(255, 255, 255) thickness=10 style=Solid+DrawGlyphRun@s1/e0 rect=[8,-17 169x100] translation=[8,63] color=rgb(0, 0, 0) inline_clips=[clip=[69,-15 47x91]]+DrawLine@s1/e0 from=[109,70] to=[116,70] color=rgb(0, 0, 0) thickness=10 style=Soliddiff --git a/Tests/LibWeb/Text/expected/display_list/text-input-clip-is-not-rounded.txt b/Tests/LibWeb/Text/expected/display_list/text-input-clip-is-not-rounded.txtindex 14381135081..c8c4c1b0d0f 100644--- a/Tests/LibWeb/Text/expected/display_list/text-input-clip-is-not-rounded.txt+++ b/Tests/LibWeb/Text/expected/display_list/text-input-clip-is-not-rounded.txt@@ -10,6 +10,6 @@ AccumulatedVisualContext Tree:DisplayList:FillRect@s1/c1/e0 rect=[8,11 23x13] color=rgba(101, 2, 0, 0.8)-DrawGlyphRun@s1/c1/e0 rect=[8,11 23x13] translation=[8,21] color=rgb(255, 255, 255)+DrawGlyphRun@s1/c1/e0 rect=[8,11 23x13] translation=[8,21] color=rgb(0, 0, 0)FillRoundedRectRing@s1/e0 rect=[6,9 160x17] corner_radii=[8x8,8x8,8x8,8x8] widths=[2,2,2,2] color=rgb(61, 174, 233)diff --git a/Tests/LibWeb/Text/input/display_list/selection-default-text-contrast.html b/Tests/LibWeb/Text/input/display_list/selection-default-keeps-text-color.htmlsimilarity index 100%rename from Tests/LibWeb/Text/input/display_list/selection-default-text-contrast.htmlrename to Tests/LibWeb/Text/input/display_list/selection-default-keeps-text-color.html