Skip to content

Truly independent web browser

LibWeb: Select content in the color of its own color scheme

Andreas Kling7544030efeb8
diff --git a/Libraries/LibWeb/Painting/PaintingRustBridge.cpp b/Libraries/LibWeb/Painting/PaintingRustBridge.cpp
index f92ee976cff..f152faaf4fc 100644
--- a/Libraries/LibWeb/Painting/PaintingRustBridge.cpp
+++ b/Libraries/LibWeb/Painting/PaintingRustBridge.cpp
@@ -617,7 +617,6 @@ Optional<DisplayListRecording> start_rust_display_list_recording(Layout::BegunRe
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);
inputs.image_fallback_color_scheme = to_underlying(document.svg_image_color_scheme().value_or(document.page().preferred_color_scheme()));
diff --git a/Libraries/LibWeb/Rust/src/painting/host/paint.rs b/Libraries/LibWeb/Rust/src/painting/host/paint.rs
index ce6f7790dc9..da5f1052326 100644
--- a/Libraries/LibWeb/Rust/src/painting/host/paint.rs
+++ b/Libraries/LibWeb/Rust/src/painting/host/paint.rs
@@ -44,7 +44,6 @@ pub struct FfiRecordingInputs {
pub inactive_selection_background_light: Color,
pub inactive_selection_background_dark: Color,
pub palette_is_dark: bool,
- pub document_has_supported_color_schemes: bool,
pub document_supports_light_or_dark: bool,
pub image_fallback_color_scheme: u8,
pub accessibility_focus_target: crate::layout::node_data::NodeSlotId,
@@ -152,7 +151,6 @@ impl FfiRecordingInputs {
inactive_selection_background_light: self.inactive_selection_background_light,
inactive_selection_background_dark: self.inactive_selection_background_dark,
palette_is_dark: self.palette_is_dark,
- document_has_supported_color_schemes: self.document_has_supported_color_schemes,
document_supports_light_or_dark: self.document_supports_light_or_dark,
image_fallback_color_scheme: self.image_fallback_color_scheme,
accessibility_focus_target: (!self.accessibility_focus_target.is_invalid())
diff --git a/Libraries/LibWeb/Rust/src/painting/record/inputs.rs b/Libraries/LibWeb/Rust/src/painting/record/inputs.rs
index 845c116a5b0..7037b455979 100644
--- a/Libraries/LibWeb/Rust/src/painting/record/inputs.rs
+++ b/Libraries/LibWeb/Rust/src/painting/record/inputs.rs
@@ -78,7 +78,6 @@ pub(crate) struct RecordingInputs {
pub inactive_selection_background_light: Color,
pub inactive_selection_background_dark: Color,
pub palette_is_dark: bool,
- pub document_has_supported_color_schemes: bool,
// Whether the document's supported color schemes name `light` or `dark`.
pub document_supports_light_or_dark: bool,
// The color scheme an SVG image renders in where neither the box that draws it nor its document opts into one.
diff --git a/Libraries/LibWeb/Rust/src/painting/record/mod.rs b/Libraries/LibWeb/Rust/src/painting/record/mod.rs
index 9066c958da3..c6e542c1970 100644
--- a/Libraries/LibWeb/Rust/src/painting/record/mod.rs
+++ b/Libraries/LibWeb/Rust/src/painting/record/mod.rs
@@ -319,7 +319,7 @@ impl<O: Observer> PaintRecorder<'_, O> {
self.committed_highlight_pseudo_style(HighlightPseudoElement::Selection, node, element_row)
});
let answer = Self::highlight_style_answer(committed, || {
- self.default_selection_style(node, style_source, window_is_focused)
+ self.default_selection_style(style_source, window_is_focused)
});
self.scratch.selection_style_cache.insert(key, answer.clone());
answer
@@ -337,7 +337,7 @@ impl<O: Observer> PaintRecorder<'_, O> {
let committed =
self.committed_highlight_pseudo_style(HighlightPseudoElement::Selection, element_row, element_row);
let answer = Self::highlight_style_answer(committed, || {
- self.default_selection_style(element_row, element_row, window_is_focused)
+ self.default_selection_style(element_row, window_is_focused)
});
self.scratch.selection_style_cache.insert(key, answer.clone());
answer
@@ -362,9 +362,8 @@ impl<O: Observer> PaintRecorder<'_, O> {
let committed = self
.first_non_anonymous_ancestor_row(node)
.and_then(|element_row| self.committed_highlight_pseudo_style(highlight, node, element_row));
- let answer = Self::highlight_style_answer(committed, || {
- self.default_search_text_style(node, style_source, highlight)
- });
+ let answer =
+ Self::highlight_style_answer(committed, || self.default_search_text_style(style_source, highlight));
let cache = if is_current {
&mut self.scratch.search_text_current_style_cache
} else {
@@ -493,11 +492,10 @@ impl<O: Observer> PaintRecorder<'_, O> {
fn default_selection_style(
&self,
- node: crate::layout::node_data::NodeSlotId,
style_source: crate::layout::node_data::NodeSlotId,
window_is_focused: bool,
) -> paint::text::SelectionStyleAnswer {
- let background_color = self.default_selection_background(node, style_source, window_is_focused);
+ let background_color = self.default_selection_background(style_source, window_is_focused);
paint::text::SelectionStyleAnswer {
facts: crate::painting::host::FfiSelectionStyleFacts {
background_color,
@@ -511,12 +509,11 @@ impl<O: Observer> PaintRecorder<'_, O> {
fn default_search_text_style(
&self,
- node: crate::layout::node_data::NodeSlotId,
style_source: crate::layout::node_data::NodeSlotId,
highlight: HighlightPseudoElement,
) -> paint::text::SelectionStyleAnswer {
if highlight == HighlightPseudoElement::SearchTextCurrent {
- let background_color = self.default_selection_background(node, style_source, true);
+ let background_color = self.default_selection_background(style_source, true);
return paint::text::SelectionStyleAnswer {
facts: crate::painting::host::FfiSelectionStyleFacts {
background_color,
@@ -542,24 +539,22 @@ impl<O: Observer> PaintRecorder<'_, O> {
fn default_selection_background(
&self,
- node: crate::layout::node_data::NodeSlotId,
style_source: crate::layout::node_data::NodeSlotId,
window_is_focused: bool,
) -> libgfx_rust::Color {
use crate::css::color_resolution::{PREFERRED_COLOR_SCHEME_DARK, PREFERRED_COLOR_SCHEME_LIGHT};
let inputs = self.inputs;
- let (color_scheme, color_scheme_is_normal) =
- self.source.node_style_if_live(style_source).map_or((0, true), |style| {
- let ui = style.inherited_ui();
- (ui.color_scheme, ui.color_schemes.as_slice().is_empty())
- });
- let use_palette_for_normal_color_scheme = !self.source.node_is_dom_backed(node)
- || (color_scheme_is_normal && !inputs.document_has_supported_color_schemes);
let palette_color_scheme = if inputs.palette_is_dark {
PREFERRED_COLOR_SCHEME_DARK
} else {
PREFERRED_COLOR_SCHEME_LIGHT
};
+ // NB: The selection takes the element's used color scheme, which is light for `normal` unless the document
+ // supports other color schemes, whatever the palette's. Without a style to tell, it takes the palette's.
+ let color_scheme = self
+ .source
+ .node_style_if_live(style_source)
+ .map_or(palette_color_scheme, |style| style.inherited_ui().color_scheme);
let (from_palette, light, dark) = if window_is_focused {
(
inputs.selection_background_from_palette,
@@ -573,7 +568,7 @@ impl<O: Observer> PaintRecorder<'_, O> {
inputs.inactive_selection_background_dark,
)
};
- if color_scheme == palette_color_scheme || use_palette_for_normal_color_scheme {
+ if color_scheme == palette_color_scheme {
from_palette
} else if color_scheme == PREFERRED_COLOR_SCHEME_DARK {
dark