Truly independent web browser
LibWeb: Apply the root element’s scrollbar-color to the viewport
sideshowbarker17eded8c4a60
diff --git a/Libraries/LibWeb/Rust/src/layout/tree_builder.rs b/Libraries/LibWeb/Rust/src/layout/tree_builder.rsindex fb1378bbd3a..5b5d48a229d 100644--- a/Libraries/LibWeb/Rust/src/layout/tree_builder.rs+++ b/Libraries/LibWeb/Rust/src/layout/tree_builder.rs@@ -1529,7 +1529,7 @@ impl TreeBuildJob {}// https://drafts.csswg.org/css-scrollbars/#scrollbar-width- // UAs must apply the scrollbar-color value set on the root element to the viewport.+ // UAs must apply the scrollbar-width value set on the root element to the viewport.// The document element is the document's only DOM child the style mirror holds: a doctype, a// comment and a processing instruction hold no place in its child sequence, and a document// can have no text child.diff --git a/Libraries/LibWeb/Rust/src/painting/chrome_geometry.rs b/Libraries/LibWeb/Rust/src/painting/chrome_geometry.rsindex 514ebf0f320..09cb44a27f2 100644--- a/Libraries/LibWeb/Rust/src/painting/chrome_geometry.rs+++ b/Libraries/LibWeb/Rust/src/painting/chrome_geometry.rs@@ -478,7 +478,16 @@ pub(crate) fn scrollbar_colors_for_paint(let Some(style) = arena.node_style_if_live(slot) else {return (Color::TRANSPARENT, Color::TRANSPARENT);};- let colors = style.inherited_ui().scrollbar_color;+ // https://drafts.csswg.org/css-scrollbars/#scrollbar-color+ // UAs must apply the scrollbar-color value set on the root element to the viewport.+ let color_style = if arena.node_kind_if_live(slot) == Some(NodeKind::Viewport) {+ style_queries::document_element_box_under(arena, slot)+ .and_then(|root| arena.node_style_if_live(root))+ .unwrap_or(style)+ } else {+ style+ };+ let colors = color_style.inherited_ui().scrollbar_color;if !colors.is_auto {return (Color(colors.thumb_color), Color(colors.track_color));}diff --git a/Libraries/LibWeb/Rust/src/painting/scroll_snap.rs b/Libraries/LibWeb/Rust/src/painting/scroll_snap.rsindex 9d08517020a..c521b158674 100644--- a/Libraries/LibWeb/Rust/src/painting/scroll_snap.rs+++ b/Libraries/LibWeb/Rust/src/painting/scroll_snap.rs@@ -15,7 +15,7 @@ use crate::css::css_enums::{scroll_snap_align, scroll_snap_axis, scroll_snap_stop, scroll_snap_strictness, writing_mode,};use crate::css::css_pixels::{CssPixelRect, CssPixels};-use crate::layout::node_data::{NodeFlag, NodeKind, NodeSlotId};+use crate::layout::node_data::{NodeKind, NodeSlotId};use crate::layout::node_facts;use crate::painting::chrome_geometry::{maximum_scroll_offset, minimum_scroll_offset};use crate::painting::host::{FfiSnapAreaGeometry, FfiSnapAxes, FfiSnapContainerGeometry};@@ -29,7 +29,7 @@ use libgfx_rust::{FloatMatrix4x4, FloatPoint, FloatRect};/// specified on the root element apply to the viewport rather than to its own box.fn snap_style_source(arena: &impl PaintRead, snap_container: NodeSlotId) -> Option<NodeSlotId> {if arena.node_kind_if_live(snap_container) == Some(NodeKind::Viewport) {- document_element_box_under(arena, snap_container)+ style_queries::document_element_box_under(arena, snap_container)} else {Some(snap_container)}@@ -65,19 +65,6 @@ fn snap_axes_of_style(style: ComputedValuesView<'_>) -> FfiSnapAxes {}}-fn document_element_box_under(arena: &impl PaintRead, parent: NodeSlotId) -> Option<NodeSlotId> {- arena.children(parent).find_map(|child| {- let flags = arena.node_flags_if_live(child);- if flags & NodeFlag::IsDocumentElement as u32 != 0 {- return Some(child);- }- if flags & NodeFlag::Anonymous as u32 != 0 {- return document_element_box_under(arena, child);- }- None- })-}-// https://drafts.csswg.org/css-scroll-snap-1/#scroll-padding// For a scroll snap container this region also defines the scroll snapport, the area of the// scrollport that is used as the alignment container for the scroll snap areas when calculatingdiff --git a/Libraries/LibWeb/Rust/src/painting/style_queries.rs b/Libraries/LibWeb/Rust/src/painting/style_queries.rsindex d99dd14bb63..0f2c697e999 100644--- a/Libraries/LibWeb/Rust/src/painting/style_queries.rs+++ b/Libraries/LibWeb/Rust/src/painting/style_queries.rs@@ -218,6 +218,20 @@ pub(crate) fn kind_is_svg_element_box(kind: NodeKind) -> bool {node_facts::kind_is_svg_box(kind) || matches!(kind, NodeKind::SVGSVGBox | NodeKind::SVGForeignObjectBox)}+/// The document element's box among `parent`'s children, looking through anonymous wrappers.+pub(crate) fn document_element_box_under(arena: &impl PaintRead, parent: NodeSlotId) -> Option<NodeSlotId> {+ arena.children(parent).find_map(|child| {+ let flags = arena.node_flags_if_live(child);+ if flags & NodeFlag::IsDocumentElement as u32 != 0 {+ return Some(child);+ }+ if flags & NodeFlag::Anonymous as u32 != 0 {+ return document_element_box_under(arena, child);+ }+ None+ })+}+pub(crate) fn node_is_root_element(arena: &impl PaintRead, node: NodeSlotId) -> bool {let flags = arena.node_flags_if_live(node);flags & NodeFlag::Anonymous as u32 == 0 && flags & NodeFlag::IsHtmlHtmlElement as u32 != 0