Best headless browser for AI agents. Lite, Fast, High-Compatibility. Built in Rust
Rust ai-agentsai-toolsbrowserbrowser-automationcloud-browserheadlessheadless-browserkitesurfplaywrightpuppeteerrustservoweb-crawlerweb-crawlingweb-scraperweb-scraping
feat(layout): model physical scrollbar insets
ldm0897e8e88a265
diff --git a/Cargo.lock b/Cargo.lockindex fd21f7e01..89eb505b3 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -4469,7 +4469,7 @@ dependencies = [[[package]]name = "taffy"version = "0.13.0"-source = "git+https://github.com/ldm0/taffy?rev=28923cb1d9164245e10566ef8156fa5cfa9633bb#28923cb1d9164245e10566ef8156fa5cfa9633bb"+source = "git+https://github.com/ldm0/taffy?rev=72e1ee73a8b0d3ed1b1717c8e5cc6f570e82d96a#72e1ee73a8b0d3ed1b1717c8e5cc6f570e82d96a"dependencies = ["arrayvec","serde",diff --git a/Cargo.toml b/Cargo.tomlindex 9ab95eeb0..43e175b6a 100644--- a/Cargo.toml+++ b/Cargo.toml@@ -96,7 +96,7 @@ stylo_atoms = { git = "https://github.com/ldm0/stylo", rev = "74cd014af14d84db1fstylo_dom = { git = "https://github.com/ldm0/stylo", rev = "74cd014af14d84db1fc8faed85086895012fc687" }stylo_static_prefs = { git = "https://github.com/ldm0/stylo", rev = "74cd014af14d84db1fc8faed85086895012fc687" }stylo_traits = { git = "https://github.com/ldm0/stylo", rev = "74cd014af14d84db1fc8faed85086895012fc687" }-taffy = { git = "https://github.com/ldm0/taffy", rev = "28923cb1d9164245e10566ef8156fa5cfa9633bb" }+taffy = { git = "https://github.com/ldm0/taffy", rev = "72e1ee73a8b0d3ed1b1717c8e5cc6f570e82d96a" }[workspace.lints.clippy]disallowed_methods = "deny"diff --git a/moli-cdp-smoke/README.md b/moli-cdp-smoke/README.mdindex 1910bb277..950b057a6 100644--- a/moli-cdp-smoke/README.md+++ b/moli-cdp-smoke/README.md@@ -171,11 +171,14 @@ Covered well:block/flex/grid `stable both-edges` numeric sizing, default-visible rootstable gutters, body hidden/auto/clip viewport overflow propagation,`overflow-body-propagation-003`'s `display:contents` exclusion, and an overlay- that occludes a lower painted scrollbar. It also verifies Moli's consume-only- scrollbar corner and screenshot-triggered layout freshness.+ that occludes a lower painted scrollbar. The numeric matrix additionally+ covers padding/border with both box-sizing modes, auto/min/max block sizing,+ aspect-ratio, and physical top/bottom gutters in `vertical-rl`. It also+ verifies Moli's consume-only scrollbar corner and screenshot-triggered layout freshness.The final workflow was calibrated on 2026-08-22 against the headed Xvfbbuild `~/chromium/src/out/Default/chrome` (`Chrome/147.0.7709.0`) and then- passed unchanged against Moli. Chromium/Xvfb routes raw-CDP clicks on its+ extended with the physical-inset matrix on 2026-08-23 against that same+ executable before passing unchanged against Moli. Chromium/Xvfb routes raw-CDP clicks on itsnative scrollbar corner through DOM input, so only that control-consumptionassertion remains Moli-specific.- Chromium-calibrated transformed-iframe input routing through raw CDP: exactdiff --git a/moli-cdp-smoke/moli_cdp_smoke/groups/classic_scrollbar.py b/moli-cdp-smoke/moli_cdp_smoke/groups/classic_scrollbar.pyindex 567245fa3..32d7152a2 100644--- a/moli-cdp-smoke/moli_cdp_smoke/groups/classic_scrollbar.py+++ b/moli-cdp-smoke/moli_cdp_smoke/groups/classic_scrollbar.py@@ -770,6 +770,86 @@ async def _run_viewport_policy_and_numeric_gutter_workflow("both-edge horizontal gutter participates in block/flex/grid numeric layout",)+ await page.set_content(+ """+ <!doctype html>+ <style>+ html, body { margin: 0; }+ .case {+ margin: 0;+ overflow: scroll;+ scrollbar-gutter: stable both-edges;+ }+ .case > div { width: 100%; height: 100%; }+ #border {+ box-sizing: border-box;+ width: 200px; height: 100px;+ padding: 10px; border: 5px solid;+ }+ #content {+ box-sizing: content-box;+ width: 200px; height: 100px;+ padding: 10px; border: 5px solid;+ }+ .auto {+ box-sizing: border-box;+ width: 200px; height: auto;+ min-height: 80px; max-height: 120px;+ }+ #auto-small > div { width: 400px; height: 20px; }+ #auto-mid > div { width: 400px; height: 90px; }+ #auto-large > div { width: 400px; height: 150px; }+ #ratio {+ box-sizing: border-box;+ width: 200px; height: auto;+ aspect-ratio: 2;+ }+ #vertical {+ box-sizing: border-box;+ width: 200px; height: 100px;+ writing-mode: vertical-rl;+ }+ </style>+ <div id="border" class="case"><div></div></div>+ <div id="content" class="case"><div></div></div>+ <div id="auto-small" class="case auto"><div></div></div>+ <div id="auto-mid" class="case auto"><div></div></div>+ <div id="auto-large" class="case auto"><div></div></div>+ <div id="ratio" class="case"><div></div></div>+ <div id="vertical" class="case"><div></div></div>+ """,+ wait_until="domcontentloaded",+ )+ resolved_edge_insets = await page.evaluate(+ """() => [+ "border", "content", "auto-small", "auto-mid", "auto-large", "ratio", "vertical"+ ].map(id => {+ const scroller = document.getElementById(id);+ const child = scroller.firstElementChild;+ const outer = scroller.getBoundingClientRect();+ const inner = child.getBoundingClientRect();+ return [+ scroller.offsetWidth, scroller.offsetHeight,+ scroller.clientWidth, scroller.clientHeight,+ scroller.clientLeft, scroller.clientTop,+ inner.x - outer.x, inner.y - outer.y, inner.width, inner.height,+ ];+ })"""+ )+ assert_equal(+ resolved_edge_insets,+ [+ [200, 100, 160, 75, 20, 5, 30, 15, 140, 55],+ [230, 130, 190, 105, 20, 5, 30, 15, 170, 85],+ [200, 80, 170, 65, 15, 0, 15, 0, 400, 20],+ [200, 105, 170, 90, 15, 0, 15, 0, 400, 90],+ [200, 120, 170, 105, 15, 0, 15, 0, 400, 150],+ [200, 100, 170, 85, 15, 0, 15, 0, 170, 85],+ [200, 100, 185, 70, 0, 15, 0, 15, 185, 70],+ ],+ "physical scrollbar insets participate in box sizing, intrinsic sizing, aspect ratio, and vertical writing mode",+ )+await page.set_content("""<!doctype html>@@ -910,6 +990,7 @@ async def _run_viewport_policy_and_numeric_gutter_workflow({"engine": "moli" if is_moli else "chromium","bothEdges": both_edges,+ "resolvedEdgeInsets": resolved_edge_insets,"bodyHidden": [hidden_before, hidden_wheel, hidden_script],"bodyAuto": [auto_width, auto_wheel],"bodyClip": [clip_width, clip_wheel],diff --git a/moli-layout/src/builder.rs b/moli-layout/src/builder.rsindex 22d51ab3e..952ce9da5 100644--- a/moli-layout/src/builder.rs+++ b/moli-layout/src/builder.rs@@ -330,6 +330,7 @@ whereroot_style.viewport_scrollbar_width(),root_style.viewport_scrollbar_gutter(),root_style.scrollbar_colors(),+ root_style.uses_horizontal_writing_mode(),);}diff --git a/moli-layout/src/pass.rs b/moli-layout/src/pass.rsindex c3a19f114..a5d862090 100644--- a/moli-layout/src/pass.rs+++ b/moli-layout/src/pass.rs@@ -330,43 +330,6 @@ fn compute_world_layout_with_scrollbars<N>(break;}}- offset_leading_scrollbar_gutter_children(world);-}--/// Taffy's scalar scrollbar reservation shrinks the available inline size but-/// always leaves its origin at zero. Move direct numeric children into a-/// physical leading gutter (RTL classic bars and `both-edges`) after the final-/// layout, preserving all of Taffy's percentage and flex/grid sizing work.-fn offset_leading_scrollbar_gutter_children<N>(world: &mut crate::LayoutWorld<N>)-where- N: Copy + std::fmt::Debug + Eq + std::hash::Hash,-{- let root = world.root;- let offsets = world- .boxes- .iter()- .map(|layout_box| {- layout_box.layout_parent.map_or(0.0, |parent| {- if parent == root {- // The synthetic initial containing block already places- // the root and its descendants after a root leading- // gutter.- 0.0- } else if world.is_viewport_defining_body(parent) {- // This body's overflow/gutter has transferred to the- // viewport and must not shift its own children.- 0.0- } else {- world.boxes[parent.index()]- .style- .scrollbar_leading_gutter_thickness(LayoutScrollbarAxis::Vertical, false)- }- })- })- .collect::<Vec<_>>();- for (layout_box, offset) in world.boxes.iter_mut().zip(offsets) {- layout_box.final_layout.location.x += offset;- }}fn css_viewport_dimension(value: f32) -> u32 {diff --git a/moli-layout/src/projection.rs b/moli-layout/src/projection.rsindex 73090e3fa..4cc358369 100644--- a/moli-layout/src/projection.rs+++ b/moli-layout/src/projection.rs@@ -318,6 +318,14 @@ where}}+ fn places_vertical_scrollbar_on_left(&self, id: LayoutBoxId) -> bool {+ id != self.world.root+ && !self.world.is_viewport_defining_body(id)+ && self.world.boxes[id.index()]+ .style+ .places_vertical_scrollbar_on_left(false)+ }+fn establishes_scroll_container(&self, id: LayoutBoxId) -> bool {if id == self.world.root {self.world@@ -419,6 +427,8 @@ whereself.scrollbar_leading_gutter_thickness(box_id, LayoutScrollbarAxis::Vertical);let horizontal_gutter =self.scrollbar_gutter_thickness(box_id, LayoutScrollbarAxis::Horizontal);+ let horizontal_leading_gutter =+ self.scrollbar_leading_gutter_thickness(box_id, LayoutScrollbarAxis::Horizontal);let mut content_box = inset_rect(padding_box,layout.padding.top,@@ -430,6 +440,7 @@ wherecontent_box.width = (content_box.width - vertical_gutter).max(0.0);content_box.height = (content_box.height - horizontal_gutter).max(0.0);content_box.x += vertical_leading_gutter;+ content_box.y += horizontal_leading_gutter;}let margin_box = outset_rect(border_box,@@ -459,6 +470,7 @@ wherevertical_gutter,vertical_leading_gutter,horizontal_gutter,+ horizontal_leading_gutter,);// Scrollable overflow starts at the padding-derived scrollport. A// box's own border is visual geometry, not reachable descendant@@ -494,7 +506,13 @@ where} else {vertical_leading_gutter},- layout.border.top + layout.padding.top,+ layout.border.top+ + layout.padding.top+ + if is_root {+ 0.0+ } else {+ horizontal_leading_gutter+ },);for line in &context.fragments.lines {overflow = overflow.union(offset_rect(line.rect, origin));@@ -606,9 +624,10 @@ whereself.scrollbar_leading_gutter_thickness(id, LayoutScrollbarAxis::Vertical);let horizontal_gutter =self.scrollbar_gutter_thickness(id, LayoutScrollbarAxis::Horizontal);+ let horizontal_leading_gutter =+ self.scrollbar_leading_gutter_thickness(id, LayoutScrollbarAxis::Horizontal);let scrollbar_thickness = self.scrollbar_control_thickness(id);- let rtl =- self.world.boxes[index].style.direction() == crate::style::InlineDirection::Rtl;+ let vertical_scrollbar_on_left = self.places_vertical_scrollbar_on_left(id);let local_scrollport = scrollport_for_box(is_root,self.viewport,@@ -616,11 +635,12 @@ wherevertical_gutter,vertical_leading_gutter,horizontal_gutter,+ horizontal_leading_gutter,);let scrollport = if is_root {LayoutRect::new(vertical_leading_gutter,- 0.0,+ horizontal_leading_gutter,local_scrollport.width,local_scrollport.height,)@@ -673,7 +693,7 @@ wherescrollport.x,scrollport.bottom(),scrollport.width,- horizontal_gutter,+ scrollbar_thickness,);LayoutScrollbarGeometry::new(LayoutScrollbarAxis::Horizontal,@@ -693,7 +713,7 @@ wherevertical_range > f32::EPSILON,).then(|| {- let x = if rtl && !is_root {+ let x = if vertical_scrollbar_on_left {scrollport.x - scrollbar_thickness} else {scrollport.right()@@ -713,14 +733,14 @@ where.filter(|bar| bar.frame.width > 0.0 && bar.frame.height > 0.0);let scrollbar_corner = (vertical_gutter > 0.0 && horizontal_gutter > 0.0).then(|| {LayoutRect::new(- if rtl && !is_root {+ if vertical_scrollbar_on_left {scrollport.x - scrollbar_thickness} else {scrollport.right()},scrollport.bottom(),scrollbar_thickness,- horizontal_gutter,+ scrollbar_thickness,)});self.scroll_extents.push(LayoutScrollExtent {@@ -809,16 +829,26 @@ wherecontinue;};let layout = layout_box.final_layout;- let vertical_leading_gutter = if index == self.world.root.index() {- 0.0- } else {- layout_box- .style- .scrollbar_leading_gutter_thickness(LayoutScrollbarAxis::Vertical, false)- };+ let box_id = LayoutBoxId::from_index(index);+ let vertical_leading_gutter =+ if box_id == self.world.root || self.world.is_viewport_defining_body(box_id) {+ 0.0+ } else {+ layout_box+ .style+ .scrollbar_leading_gutter_thickness(LayoutScrollbarAxis::Vertical, false)+ };+ let horizontal_leading_gutter =+ if box_id == self.world.root || self.world.is_viewport_defining_body(box_id) {+ 0.0+ } else {+ layout_box+ .style+ .scrollbar_leading_gutter_thickness(LayoutScrollbarAxis::Horizontal, false)+ };let content_origin = LayoutPoint::new(layout.border.left + layout.padding.left + vertical_leading_gutter,- layout.border.top + layout.padding.top,+ layout.border.top + layout.padding.top + horizontal_leading_gutter,);for line in &context.fragments.lines {let fragment = self.push_fragment(LayoutFragment {@@ -1359,6 +1389,7 @@ fn scrollport_for_box(vertical_gutter: f32,vertical_leading_gutter: f32,horizontal_gutter: f32,+ horizontal_leading_gutter: f32,) -> LayoutRect {if is_root {return LayoutRect::new(@@ -1372,6 +1403,7 @@ fn scrollport_for_box(scrollport.width = (scrollport.width - vertical_gutter).max(0.0);scrollport.height = (scrollport.height - horizontal_gutter).max(0.0);scrollport.x += vertical_leading_gutter;+ scrollport.y += horizontal_leading_gutter;scrollport}@@ -1394,9 +1426,17 @@ where.style.scrollbar_leading_gutter_thickness(LayoutScrollbarAxis::Vertical, false)};+ let horizontal_leading_gutter =+ if owner_id == world.root || world.is_viewport_defining_body(owner_id) {+ 0.0+ } else {+ owner+ .style+ .scrollbar_leading_gutter_thickness(LayoutScrollbarAxis::Horizontal, false)+ };let content_origin = LayoutPoint::new(owner_layout.border.left + owner_layout.padding.left + vertical_leading_gutter,- owner_layout.border.top + owner_layout.padding.top,+ owner_layout.border.top + owner_layout.padding.top + horizontal_leading_gutter,);let containing_width = (owner_layout.size.width- owner_layout.border.leftdiff --git a/moli-layout/src/style.rs b/moli-layout/src/style.rsindex f5ec9bbcf..d6353aebd 100644--- a/moli-layout/src/style.rs+++ b/moli-layout/src/style.rs@@ -10,7 +10,7 @@ use style::{color::ColorSpace,computed_values::{content_visibility::T as StyloContentVisibility, isolation::T as StyloIsolation,- mix_blend_mode::T as StyloMixBlendMode,+ mix_blend_mode::T as StyloMixBlendMode, writing_mode::T as StyloWritingMode,},properties::ComputedValues,properties::generated::longhands::position::computed_value::T as StyloPosition,@@ -469,6 +469,7 @@ pub struct ResolvedLayoutStyle {text_transform: InlineTextTransform,text_align: parley::Alignment,direction: InlineDirection,+ horizontal_writing_mode: bool,unicode_bidi: InlineUnicodeBidi,vertical_align: InlineVerticalAlign,text_projection_deferred: bool,@@ -523,6 +524,7 @@ impl std::fmt::Debug for ResolvedLayoutStyle {.field("text_transform", &self.text_transform).field("text_align", &self.text_align).field("direction", &self.direction)+ .field("horizontal_writing_mode", &self.horizontal_writing_mode).field("unicode_bidi", &self.unicode_bidi).field("vertical_align", &self.vertical_align).field("text_projection_deferred", &self.text_projection_deferred)@@ -613,6 +615,8 @@ impl ResolvedLayoutStyle {StyloDirection::Ltr => InlineDirection::Ltr,StyloDirection::Rtl => InlineDirection::Rtl,};+ let horizontal_writing_mode =+ computed.clone_writing_mode() == StyloWritingMode::HorizontalTb;let unicode_bidi = match computed.clone_unicode_bidi() {StyloUnicodeBidi::Normal => InlineUnicodeBidi::Normal,StyloUnicodeBidi::Embed => InlineUnicodeBidi::Embed,@@ -837,6 +841,7 @@ impl ResolvedLayoutStyle {text_transform,text_align,direction,+ horizontal_writing_mode,unicode_bidi,vertical_align,text_projection_deferred,@@ -912,6 +917,7 @@ impl ResolvedLayoutStyle {text_transform: InlineTextTransform::None,text_align: parley::Alignment::Start,direction: InlineDirection::Ltr,+ horizontal_writing_mode: true,unicode_bidi: InlineUnicodeBidi::Normal,vertical_align: InlineVerticalAlign::default(),text_projection_deferred: false,@@ -1675,27 +1681,22 @@ impl ResolvedLayoutStyle {pub(crate) fn prepare_scrollbar_layout(&mut self, is_root: bool) {self.revealed_scrollbar_x = self.overflow_x == LayoutOverflowMode::Scroll;self.revealed_scrollbar_y = self.overflow_y == LayoutOverflowMode::Scroll;- let both_edge_gutter = self.reserves_both_edge_vertical_gutter();- self.taffy.scrollbar_width =- self.scrollbar_width.thickness() * if both_edge_gutter { 2.0 } else { 1.0 };+ // Moli resolves CSS scrollbar policy to physical edge insets through+ // `LayoutPartialTree::get_scrollbar_insets`. Keep Taffy's legacy+ // scalar disabled so no algorithm reserves the same gutter twice.+ self.taffy.scrollbar_width = 0.0;self.taffy.overflow.x =self.initial_taffy_overflow(LayoutScrollbarAxis::Horizontal, is_root);self.taffy.overflow.y = self.initial_taffy_overflow(LayoutScrollbarAxis::Vertical, is_root);- // Taffy's scrollbar width is scalar. For `both-edges` it represents- // the two vertical gutters together, so it must not also be used as a- // double-height horizontal scrollbar. Moli's Taffy adapter supplies- // the missing single horizontal reservation to numeric child layout.- if both_edge_gutter && self.revealed_scrollbar_x {- self.taffy.overflow.x = taffy::Overflow::Hidden;- }- // In horizontal writing modes a stable gutter is reserved on the- // inline end whenever vertical overflow could create a scrollbar.if !is_root- && !matches!(self.scrollbar_gutter, LayoutScrollbarGutter::Auto)- && self.overflow_y.creates_scroll_container()+ && self.scrollbar_gutter != LayoutScrollbarGutter::Auto&& self.scrollbar_width != LayoutScrollbarWidth::None{- self.taffy.overflow.y = taffy::Overflow::Scroll;+ if self.horizontal_writing_mode && self.overflow_y.creates_scroll_container() {+ self.taffy.overflow.y = taffy::Overflow::Scroll;+ } else if !self.horizontal_writing_mode && self.overflow_x.creates_scroll_container() {+ self.taffy.overflow.x = taffy::Overflow::Scroll;+ }}}@@ -1745,9 +1746,7 @@ impl ResolvedLayoutStyle {return false;}*revealed = true;- if !(is_root- || axis == LayoutScrollbarAxis::Horizontal && self.reserves_both_edge_vertical_gutter())- {+ if !is_root {match axis {LayoutScrollbarAxis::Horizontal => {self.taffy.overflow.x = taffy::Overflow::Scroll;@@ -1794,39 +1793,11 @@ impl ResolvedLayoutStyle {self.scrollbar_width.thickness()}- /// Extra block-axis reservation that Taffy's scalar scrollbar width- /// cannot express. Under `stable both-edges` the scalar is already used- /// for two vertical gutters, so Moli runs the container's numeric layout- /// against a block size reduced by the real horizontal control and then- /// restores the outer box size.- pub(crate) fn horizontal_scrollbar_layout_compensation(&self) -> f32 {- if self.reserves_both_edge_vertical_gutter() && self.revealed_scrollbar_x {- self.scrollbar_width.thickness()- } else {- 0.0- }- }-pub(crate) fn scrollbar_gutter_thickness(&self, axis: LayoutScrollbarAxis) -> f32 {- if self.scrollbar_width == LayoutScrollbarWidth::None {- return 0.0;- }- let revealed = match axis {- LayoutScrollbarAxis::Horizontal => self.revealed_scrollbar_x,- LayoutScrollbarAxis::Vertical => self.revealed_scrollbar_y,- };- let stable_vertical = axis == LayoutScrollbarAxis::Vertical- && !matches!(self.scrollbar_gutter, LayoutScrollbarGutter::Auto)- && self.overflow_y.creates_scroll_container();- if revealed || stable_vertical {- let thickness = self.scrollbar_width.thickness();- if axis == LayoutScrollbarAxis::Vertical && self.reserves_both_edge_vertical_gutter() {- thickness * 2.0- } else {- thickness- }- } else {- 0.0+ let insets = self.scrollbar_layout_insets(false);+ match axis {+ LayoutScrollbarAxis::Horizontal => insets.top + insets.bottom,+ LayoutScrollbarAxis::Vertical => insets.left + insets.right,}}@@ -1838,25 +1809,64 @@ impl ResolvedLayoutStyle {axis: LayoutScrollbarAxis,is_root: bool,) -> f32 {- if axis != LayoutScrollbarAxis::Vertical || self.scrollbar_gutter_thickness(axis) == 0.0 {- return 0.0;+ let insets = self.scrollbar_layout_insets(is_root);+ match axis {+ LayoutScrollbarAxis::Horizontal => insets.top,+ LayoutScrollbarAxis::Vertical => insets.left,}- // Chromium keeps the viewport scrollbar on the physical right even- // when the root element is RTL. `both-edges` still reserves its- // matching gutter on the physical left.- if self.reserves_both_edge_vertical_gutter()- || (!is_root && self.direction == InlineDirection::Rtl)- {- self.scrollbar_width.thickness()- } else {- 0.0+ }++ /// Physical gutter contract consumed by Taffy's numeric algorithms.+ ///+ /// CSS relation, writing mode, direction and dynamic scrollbar feedback+ /// are resolved here once; Taffy deliberately sees only four edge sizes.+ pub(crate) fn scrollbar_layout_insets(&self, is_root: bool) -> taffy::Rect<f32> {+ if self.scrollbar_width == LayoutScrollbarWidth::None {+ return taffy::Rect::ZERO;+ }+ let thickness = self.scrollbar_width.thickness();+ let mut insets = taffy::Rect::ZERO;++ if self.revealed_scrollbar_x {+ insets.bottom = thickness;+ }+ if self.revealed_scrollbar_y {+ if self.places_vertical_scrollbar_on_left(is_root) {+ insets.left = thickness;+ } else {+ insets.right = thickness;+ }}++ if self.scrollbar_gutter != LayoutScrollbarGutter::Auto {+ if self.horizontal_writing_mode && self.overflow_y.creates_scroll_container() {+ if self.places_vertical_scrollbar_on_left(is_root) {+ insets.left = thickness;+ if self.scrollbar_gutter == LayoutScrollbarGutter::StableBothEdges {+ insets.right = thickness;+ }+ } else {+ insets.right = thickness;+ if self.scrollbar_gutter == LayoutScrollbarGutter::StableBothEdges {+ insets.left = thickness;+ }+ }+ } else if !self.horizontal_writing_mode && self.overflow_x.creates_scroll_container() {+ insets.bottom = thickness;+ if self.scrollbar_gutter == LayoutScrollbarGutter::StableBothEdges {+ insets.top = thickness;+ }+ }+ }+ insets}- fn reserves_both_edge_vertical_gutter(&self) -> bool {- self.scrollbar_gutter == LayoutScrollbarGutter::StableBothEdges- && self.overflow_y.creates_scroll_container()- && self.scrollbar_width != LayoutScrollbarWidth::None+ pub(crate) fn places_vertical_scrollbar_on_left(&self, is_root: bool) -> bool {+ !is_root && self.horizontal_writing_mode && self.direction == InlineDirection::Rtl+ }++ pub(crate) const fn uses_horizontal_writing_mode(&self) -> bool {+ self.horizontal_writing_mode}pub(crate) fn text_leaf_from(parent: &Self) -> Self {@@ -1879,6 +1889,7 @@ impl ResolvedLayoutStyle {text_transform: parent.text_transform,text_align: parent.text_align,direction: parent.direction,+ horizontal_writing_mode: parent.horizontal_writing_mode,unicode_bidi: InlineUnicodeBidi::Normal,vertical_align: parent.vertical_align,text_projection_deferred: parent.text_projection_deferred,@@ -1944,6 +1955,7 @@ impl ResolvedLayoutStyle {text_transform: parent.text_transform,text_align: parent.text_align,direction: parent.direction,+ horizontal_writing_mode: parent.horizontal_writing_mode,unicode_bidi: InlineUnicodeBidi::Normal,vertical_align: parent.vertical_align,text_projection_deferred: parent.text_projection_deferred,diff --git a/moli-layout/src/taffy_tree.rs b/moli-layout/src/taffy_tree.rsindex ac5f3d4f1..81eede259 100644--- a/moli-layout/src/taffy_tree.rs+++ b/moli-layout/src/taffy_tree.rs@@ -9,12 +9,12 @@ use taffy::{LayoutOutput, LayoutPartialTree, Line, MaybeMath, MaybeResolve, NodeId, Point, ResolveOrZero,RoundTree, RunMode, Size, SizingMode, SizingPurpose, Style, TraversePartialTree, TraverseTree,compute_block_layout, compute_cached_layout, compute_flexbox_layout, compute_grid_layout,- compute_hidden_layout, compute_leaf_layout, compute_root_layout, round_layout,+ compute_hidden_layout, compute_leaf_layout_with_scrollbar_insets, compute_root_layout,+ round_layout,};use crate::{- LayoutBoxId, LayoutBoxKind, LayoutCapabilityDiagnostic, LayoutScrollbarAxis, LayoutWorld,- PaintRect, PaintViewport,+ LayoutBoxId, LayoutBoxKind, LayoutCapabilityDiagnostic, LayoutWorld, PaintRect, PaintViewport,form::form_control_context,inline::{InlineFormattingContext, InlineFragments, InlineLinePlacement, InlineObjectRole,@@ -49,15 +49,7 @@ whereworld.viewport_layout.cache.clear();world.viewport_layout.unrounded_layout = Layout::with_order(0);world.viewport_layout.final_layout = Layout::with_order(0);- let vertical_gutter = world- .viewport_scroll_policy- .scrollbar_gutter_thickness(LayoutScrollbarAxis::Vertical);- let vertical_leading_gutter = world- .viewport_scroll_policy- .scrollbar_leading_gutter_thickness(LayoutScrollbarAxis::Vertical);- let horizontal_gutter = world- .viewport_scroll_policy- .scrollbar_gutter_thickness(LayoutScrollbarAxis::Horizontal);+ let viewport_scrollbar_insets = world.viewport_scroll_policy.scrollbar_layout_insets();world.viewport_layout.style = Style {display: Display::Block,box_sizing: BoxSizing::BorderBox,@@ -79,12 +71,10 @@ where// Padding would be wrong here because an absolute/fixed containing// block is its padding box and would still extend underneath the bars.border: taffy::Rect {- left: taffy::LengthPercentage::length(vertical_leading_gutter),- right: taffy::LengthPercentage::length(- (vertical_gutter - vertical_leading_gutter).max(0.0),- ),- top: taffy::LengthPercentage::length(0.0),- bottom: taffy::LengthPercentage::length(horizontal_gutter),+ left: taffy::LengthPercentage::length(viewport_scrollbar_insets.left),+ right: taffy::LengthPercentage::length(viewport_scrollbar_insets.right),+ top: taffy::LengthPercentage::length(viewport_scrollbar_insets.top),+ bottom: taffy::LengthPercentage::length(viewport_scrollbar_insets.bottom),},..Style::default()};@@ -1124,22 +1114,12 @@ fn layout_inline_absolute_child<N>(bottom.map(|bottom| area_height - final_size.height - bottom - resolved_margin.bottom)}).unwrap_or(static_position.y + resolved_margin.top);+ let scrollbar_size = world.get_scrollbar_insets(child.to_taffy()).sum_axes();world.boxes[child.index()].unrounded_layout = Layout {order: 0,size: final_size,content_size: output.content_size,- scrollbar_size: Size {- width: if style.overflow.y == taffy::Overflow::Scroll {- style.scrollbar_width- } else {- 0.0- },- height: if style.overflow.x == taffy::Overflow::Scroll {- style.scrollbar_width- } else {- 0.0- },- },+ scrollbar_size,location: Point {x: area.origin.x + x - numeric_parent_origin.x,y: area.origin.y + y - numeric_parent_origin.y,@@ -1223,6 +1203,23 @@ where}}+ fn get_scrollbar_insets(&self, node_id: NodeId) -> taffy::Rect<f32> {+ if self.is_viewport_taffy_node(node_id) {+ // The synthetic viewport expresses its gutters as non-painted+ // borders so fixed positioning shares the reduced initial+ // containing block. Do not reserve them again as scrollbars.+ return taffy::Rect::ZERO;+ }+ let id = LayoutBoxId::from_taffy(node_id);+ if id == self.root || self.is_viewport_defining_body(id) {+ // Root gutters belong to the synthetic viewport. A defining+ // body's authored overflow has transferred to that same policy.+ taffy::Rect::ZERO+ } else {+ self.boxes[id.index()].style.scrollbar_layout_insets(false)+ }+ }+fn resolve_calc_value(&self, value: *const (), basis: f32) -> f32 {resolve_stylo_calc_value(value, basis)}@@ -1441,47 +1438,7 @@ whereinputs: LayoutInput,block_context: Option<&mut BlockContext<'_>>,) -> LayoutOutput {- let id = LayoutBoxId::from_taffy(node_id);- let horizontal_reservation = if id == self.root || self.boxes[id.index()].is_replaced() {- 0.0- } else {- self.boxes[id.index()]- .style- .horizontal_scrollbar_layout_compensation()- };- if horizontal_reservation <= 0.0 {- return self.compute_child_layout_for_box(node_id, inputs, block_context);- }-- // Taffy exposes one scalar scrollbar width for both axes. A- // `stable both-edges` box needs that scalar to reserve two vertical- // gutters, leaving no way to describe the single horizontal gutter.- // Adapt the container's numeric block-size input here: descendants,- // percentages, flex/grid tracks and intrinsic calculations all see- // the reduced scrollport, while the returned outer border-box keeps- // the size selected by the parent. The root uses the synthetic- // viewport's axis-specific borders and never enters this adapter.- let outer_known_height = inputs.known_dimensions.height;- let inputs = LayoutInput {- known_dimensions: inputs.known_dimensions.map_height(|height| {- height.map(|height| (height - horizontal_reservation).max(0.0))- }),- definite_dimensions: inputs.definite_dimensions.map_height(|height| {- height.map(|height| (height - horizontal_reservation).max(0.0))- }),- available_space: inputs.available_space.map_height(|height| match height {- AvailableSpace::Definite(height) => {- AvailableSpace::Definite((height - horizontal_reservation).max(0.0))- }- AvailableSpace::MinContent => AvailableSpace::MinContent,- AvailableSpace::MaxContent => AvailableSpace::MaxContent,- }),- ..inputs- };- let mut output = self.compute_child_layout_for_box(node_id, inputs, block_context);- output.size.height =- outer_known_height.unwrap_or(output.size.height + horizontal_reservation);- output+ self.compute_child_layout_for_box(node_id, inputs, block_context)}fn compute_child_layout_for_box(@@ -1630,9 +1587,11 @@ where};}- compute_leaf_layout(+ let scrollbar_insets = self.get_scrollbar_insets(id.to_taffy());+ compute_leaf_layout_with_scrollbar_insets(inputs,&style,+ scrollbar_insets,resolve_stylo_calc_value,|known_dimensions, available_space| {if let Some(text) = text.as_deref() {@@ -1659,6 +1618,7 @@ whereinputs: LayoutInput,block_context: Option<&mut BlockContext<'_>>,) -> LayoutOutput {+ let scrollbar_insets = self.get_scrollbar_insets(id.to_taffy());let style = self.boxes[id.index()].style.taffy.clone();let is_floated = box_is_effectively_floated(self, id);// Both Taffy's block-float parent and Moli's IFC float parent@@ -1685,9 +1645,10 @@ where.take().unwrap_or_else(empty_inline_context);let mut measurement = None;- let mut output = compute_leaf_layout(+ let mut output = compute_leaf_layout_with_scrollbar_insets(leaf_inputs,&style,+ scrollbar_insets,resolve_stylo_calc_value,|known_dimensions, available_space| {let result = self.measure_inline_context(@@ -1713,15 +1674,22 @@ wherelet border = style.border.resolve_or_zero(inputs.parent_size.width, resolve_stylo_calc_value);- let content_box_height =- (output.size.height - padding.top - padding.bottom - border.top - border.bottom)- .max(0.0);+ let content_box_height = (output.size.height+ - padding.top+ - padding.bottom+ - border.top+ - border.bottom+ - scrollbar_insets.top+ - scrollbar_insets.bottom)+ .max(0.0);let content_box_size = Size {width: (output.size.width- padding.left- padding.right- border.left- - border.right)+ - border.right+ - scrollbar_insets.left+ - scrollbar_insets.right).max(0.0),height: content_box_height,};@@ -1738,10 +1706,10 @@ where);output.first_baselines.y = measurement.first_baseline- .map(|baseline| baseline + padding.top + border.top);+ .map(|baseline| baseline + padding.top + border.top + scrollbar_insets.top);output.last_baselines.y = measurement.last_baseline- .map(|baseline| baseline + padding.top + border.top);+ .map(|baseline| baseline + padding.top + border.top + scrollbar_insets.top);if measurement.line_placements.iter().any(|line| !line.phantom) {output.margins_can_collapse_through = false;}@@ -1750,8 +1718,8 @@ where&inline_context,&measurement,Point {- x: padding.left + border.left,- y: padding.top + border.top,+ x: padding.left + border.left + scrollbar_insets.left,+ y: padding.top + border.top + scrollbar_insets.top,},content_box_size,self.boxes[id.index()].style.direction(),@@ -2339,6 +2307,7 @@ whereorder: usize,parent_width: Option<f32>,) {+ let scrollbar_size = self.get_scrollbar_insets(child.to_taffy()).sum_axes();let style = &self.boxes[child.index()].style.taffy;let padding = style.padding@@ -2349,19 +2318,6 @@ wherelet margin = style.margin.resolve_or_zero(parent_width, resolve_stylo_calc_value);- let scrollbar_size = Size {- width: if style.overflow.y == taffy::Overflow::Scroll {- style.scrollbar_width- } else {- 0.0- },- height: if style.overflow.x == taffy::Overflow::Scroll {- style.scrollbar_width- } else {- 0.0- },- };-self.boxes[child.index()].unrounded_layout = Layout {order: u32::try_from(order).unwrap_or(u32::MAX),location,diff --git a/moli-layout/src/world.rs b/moli-layout/src/world.rsindex 31b6e5d31..d93a83c61 100644--- a/moli-layout/src/world.rs+++ b/moli-layout/src/world.rs@@ -281,6 +281,7 @@ pub(crate) struct ViewportScrollPolicy {scrollbar_width: LayoutScrollbarWidth,scrollbar_gutter: LayoutScrollbarGutter,scrollbar_colors: Option<LayoutScrollbarColors>,+ horizontal_writing_mode: bool,revealed_scrollbar_x: bool,revealed_scrollbar_y: bool,}@@ -293,6 +294,7 @@ impl Default for ViewportScrollPolicy {scrollbar_width: LayoutScrollbarWidth::Auto,scrollbar_gutter: LayoutScrollbarGutter::Auto,scrollbar_colors: None,+ horizontal_writing_mode: true,revealed_scrollbar_x: false,revealed_scrollbar_y: false,}@@ -306,6 +308,7 @@ impl ViewportScrollPolicy {scrollbar_width: LayoutScrollbarWidth,scrollbar_gutter: LayoutScrollbarGutter,scrollbar_colors: Option<LayoutScrollbarColors>,+ horizontal_writing_mode: bool,) -> Self {Self {defining_box,@@ -313,6 +316,7 @@ impl ViewportScrollPolicy {scrollbar_width,scrollbar_gutter,scrollbar_colors,+ horizontal_writing_mode,revealed_scrollbar_x: false,revealed_scrollbar_y: false,}@@ -397,42 +401,54 @@ impl ViewportScrollPolicy {}pub(crate) fn scrollbar_gutter_thickness(self, axis: LayoutScrollbarAxis) -> f32 {- if self.scrollbar_width == LayoutScrollbarWidth::None {- return 0.0;- }- let revealed = match axis {- LayoutScrollbarAxis::Horizontal => self.revealed_scrollbar_x,- LayoutScrollbarAxis::Vertical => self.revealed_scrollbar_y,- };- let stable_vertical = axis == LayoutScrollbarAxis::Vertical- && self.scrollbar_gutter != LayoutScrollbarGutter::Auto- && self.effective_overflow[1].creates_scroll_container();- if !revealed && !stable_vertical {- return 0.0;- }- let thickness = self.scrollbar_width.thickness();- if axis == LayoutScrollbarAxis::Vertical && self.reserves_both_edge_vertical_gutter() {- thickness * 2.0- } else {- thickness+ let insets = self.scrollbar_layout_insets();+ match axis {+ LayoutScrollbarAxis::Horizontal => insets.top + insets.bottom,+ LayoutScrollbarAxis::Vertical => insets.left + insets.right,}}pub(crate) fn scrollbar_leading_gutter_thickness(self, axis: LayoutScrollbarAxis) -> f32 {- if axis == LayoutScrollbarAxis::Vertical- && self.scrollbar_gutter_thickness(axis) > 0.0- && self.reserves_both_edge_vertical_gutter()- {- self.scrollbar_width.thickness()- } else {- 0.0+ let insets = self.scrollbar_layout_insets();+ match axis {+ LayoutScrollbarAxis::Horizontal => insets.top,+ LayoutScrollbarAxis::Vertical => insets.left,}}- fn reserves_both_edge_vertical_gutter(self) -> bool {- self.scrollbar_gutter == LayoutScrollbarGutter::StableBothEdges- && self.effective_overflow[1].creates_scroll_container()- && self.scrollbar_width != LayoutScrollbarWidth::None+ pub(crate) fn scrollbar_layout_insets(self) -> taffy::Rect<f32> {+ if self.scrollbar_width == LayoutScrollbarWidth::None {+ return taffy::Rect::ZERO;+ }+ let thickness = self.scrollbar_width.thickness();+ let mut insets = taffy::Rect::ZERO;++ if self.revealed_scrollbar_x {+ insets.bottom = thickness;+ }+ // Chromium keeps the viewport's vertical scrollbar on the physical+ // right, including RTL and vertical writing modes.+ if self.revealed_scrollbar_y {+ insets.right = thickness;+ }++ if self.scrollbar_gutter != LayoutScrollbarGutter::Auto {+ if self.horizontal_writing_mode && self.effective_overflow[1].creates_scroll_container()+ {+ insets.right = thickness;+ if self.scrollbar_gutter == LayoutScrollbarGutter::StableBothEdges {+ insets.left = thickness;+ }+ } else if !self.horizontal_writing_mode+ && self.effective_overflow[0].creates_scroll_container()+ {+ insets.bottom = thickness;+ if self.scrollbar_gutter == LayoutScrollbarGutter::StableBothEdges {+ insets.top = thickness;+ }+ }+ }+ insets}}diff --git a/moli-renderer-v8/src/script_vm/tests/dom_elements/dom_surface.rs b/moli-renderer-v8/src/script_vm/tests/dom_elements/dom_surface.rsindex 8555fb212..84aacbd3b 100644--- a/moli-renderer-v8/src/script_vm/tests/dom_elements/dom_surface.rs+++ b/moli-renderer-v8/src/script_vm/tests/dom_elements/dom_surface.rs@@ -1465,6 +1465,94 @@ fn stable_both_edges_horizontal_bar_sizes_percentage_children_in_numeric_layout();}+#[test]+fn physical_scrollbar_insets_cover_box_intrinsic_ratio_and_vertical_writing_layout() {+ let mut vm = new_storage_test_vm("https://physical-scrollbar-insets.test/");+ vm.eval(+ r#"+ (() => {+ if (!document.documentElement) {+ document.appendChild(document.createElement("html"));+ }+ if (!document.body) {+ document.documentElement.appendChild(document.createElement("body"));+ }+ document.documentElement.style.margin = "0";+ document.body.style.margin = "0";+ document.body.innerHTML = `+ <style>+ .case {+ margin: 0;+ overflow: scroll;+ scrollbar-gutter: stable both-edges;+ }+ .case > div { width: 100%; height: 100%; }+ #border {+ box-sizing: border-box;+ width: 200px; height: 100px;+ padding: 10px; border: 5px solid;+ }+ #content {+ box-sizing: content-box;+ width: 200px; height: 100px;+ padding: 10px; border: 5px solid;+ }+ .auto {+ box-sizing: border-box;+ width: 200px; height: auto;+ min-height: 80px; max-height: 120px;+ }+ #auto-small > div { width: 400px; height: 20px; }+ #auto-mid > div { width: 400px; height: 90px; }+ #auto-large > div { width: 400px; height: 150px; }+ #ratio {+ box-sizing: border-box;+ width: 200px; height: auto;+ aspect-ratio: 2;+ }+ #vertical {+ box-sizing: border-box;+ width: 200px; height: 100px;+ writing-mode: vertical-rl;+ }+ </style>+ <div id="border" class="case"><div></div></div>+ <div id="content" class="case"><div></div></div>+ <div id="auto-small" class="case auto"><div></div></div>+ <div id="auto-mid" class="case auto"><div></div></div>+ <div id="auto-large" class="case auto"><div></div></div>+ <div id="ratio" class="case"><div></div></div>+ <div id="vertical" class="case"><div></div></div>`;+ })()+ "#,+ )+ .expect("physical scrollbar inset fixture should initialize");+ refresh_layout_for_test(&mut vm);++ assert_eq!(+ vm.eval(+ r#"+ JSON.stringify([+ "border", "content", "auto-small", "auto-mid", "auto-large", "ratio", "vertical"+ ].map(id => {+ const scroller = document.getElementById(id);+ const child = scroller.firstElementChild;+ const outer = scroller.getBoundingClientRect();+ const inner = child.getBoundingClientRect();+ return [+ scroller.offsetWidth, scroller.offsetHeight,+ scroller.clientWidth, scroller.clientHeight,+ scroller.clientLeft, scroller.clientTop,+ inner.x - outer.x, inner.y - outer.y, inner.width, inner.height,+ ];+ }))+ "#,+ )+ .expect("physical scrollbar inset metrics should evaluate"),+ "[[200,100,160,75,20,5,30,15,140,55],[230,130,190,105,20,5,30,15,170,85],[200,80,170,65,15,0,15,0,400,20],[200,105,170,90,15,0,15,0,400,90],[200,120,170,105,15,0,15,0,400,150],[200,100,170,85,15,0,15,0,170,85],[200,100,185,70,0,15,0,15,185,70]]"+ );+}+#[test]fn nested_and_sibling_scrollbar_drags_stay_bound_to_the_pressed_scroller() {let mut vm = new_storage_test_vm("https://nested-classic-scrollbar-input.test/");