fix(lite): a table's caption is laid out and drawn, as in Chromium (owner: "go ahead and yes use tauri's plugin:http")

Blitz's table construction skipped <caption>: no box, nothing drawn,
so a caption's text was missing from books. A table's captions are now
blocks across its border box, above the grid or below it (caption-side),
their margins inside the table's box, and the table is at least as wide
as their min-content widths (its columns take the extra width), as
Chromium lays out CSS 2's table wrapper. Taffy lays the grid out with the
captions' heights added to its top and bottom padding, and the table's
background and border go around the grid only, as the fieldset's go
around its content below the legend. A table without a caption takes
the same path as before.

A caption's min-content width is measured width-only. A full measure
wraps the caption's text at that width, and when the caption's own
layout at the table's width then comes from the layout cache (a second
pass, as after the body's width changes) nothing wraps it back:
its box kept two lines' height while its text ran a word per line over
the rows below.

Test: tauri-runtime-blitz tests/table_caption.rs. Two tests check
Chromium's rects and pixel columns for the same page (Playwright).
Without the change they fail: the captions' rects are 0,0,0,0 and the
tables 7 px short, and no caption is painted, the table's border at its
top. A collapsed-borders table is checked by what its caption does
(spans it at its top, 7 px; the grid 7 px lower), since Lite sizes the
collapsed borders themselves differently (QA.md section 6, now with the
cell's whole border and the table's padding, found by this test).
The third lays a caption out, changes the body's width and lays it out
again: with a full min-content measure it fails with lines
"38 18 18 18 18 18 18" for "38 91 42" (the caption's height, then each
line's width). All three pass with the change.
cargo test -p blitz-qjs-script -p tauri-runtime-blitz -p anyrender_cairo:
248 passed; -p blitz-dom -p blitz-html: 176 passed.

Real use: the reader-tables parity scenario (next commit: tables.epub,
a caption above its table and a long one below, Kindle size in e-ink)
passes 3/3 steps against Readest on Linux (CEF), with the same boxes
and ink. With the full min-content measure it passed 1/3, the captions'
text a word per line. Not run on the Kindle.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Huang Xin 2026-11-30 02:47:27 +08:00
parent 6e1f6f6198
commit 8e050cf3ab
No known key found for this signature in database
GPG key ID: FEB86D637D085E7D
4 changed files with 531 additions and 35 deletions

View file

@ -215,8 +215,7 @@ while KOReader is open; close the owner's Lite only after 5 idle minutes and reo
| PDF | Doesn't open: "DOMMatrix is not defined" | pdf.js needs DOMMatrix, Path2D and a 2D canvas; Lite's canvas has no context | Open: owner's decision (large) |
| Vertical text (ja) | Laid out horizontally | Blitz has no vertical writing modes | Open: owner's decision (large) |
| Ids that name a document or form property (`target`, `title`, `action`...) | Readest drops them from a section, Lite keeps most: a link to one lands at its element in Lite, at the section start in Readest, and Lite's CFIs carry the id | Readest's DOMPurify drops an `id` that is `in document` or `in` a form; Lite's document and form lack 193 and 222 of Chromium's property names | Open: matching would mean every name; Readest's own behavior is the owner's to decide |
| Tables | A `<caption>` isn't drawn: no box, no text, and the table's box leaves it out (51 px tall where Chromium's is 58 with a 7 px caption) | Blitz's table construction skips captions | Open: text missing from books, next to fix |
| Tables, collapsed borders | The outer border takes the cells' width when the table's own is wider (a 40x30 table where Chromium's is 44x34) | Blitz's border-collapse resolution | Open |
| Tables, collapsed borders | The outer border takes the cells' width when the table's own is wider (a 40x30 table where Chromium's is 44x34); a cell's box takes its whole border where Chromium's takes half (24x14 where Chromium's is 23x13, with 1 px borders); the table's padding applies, where Chromium ignores it | Blitz's border-collapse resolution | Open |
| Steps after a tap | Readest's tapped element (or what replaced it there) keeps `:hover` | The harness clicks with a mouse that stays in CEF; Lite gets a finger | Harness: reader-links step 5's darker gray button passes the ink check |
| Comic and fixed-layout pages | Boxes in hidden page frames: Readest gives a `display: none` frame's document no boxes and a frame with no `src` an empty `about:blank` document; Lite lays out the first and gives the second no document | Blitz | Open, nothing visible (format-cbz, every step) |
| Placeholders | Drawn at the field's font size and in full ink: Add OPDS Catalog's are 16 px where Readest's are 14 (`placeholder:text-sm`; the Custom Headers one wraps to four lines), and the disabled OPDS search box's is solid where Readest's is light gray | Lite paints a placeholder with its `::placeholder` color only, not its font size or `opacity` (daisyUI gives a disabled input's 0.2) | Open, next after captions (opds-catalog steps 3-8, 10-12) |

View file

@ -0,0 +1,165 @@
//! A table's `<caption>`, as in Chromium: it spans the table's border box, above the grid (below
//! it with `caption-side: bottom`), its margins inside the table's box. The table's rect takes
//! the captions in, a caption wider than the grid widens the table (its columns take the extra
//! width), and the table's background and border go around the grid only. Blitz skipped captions:
//! no box, nothing drawn, so a caption's text was missing from books. Expected values are
//! Chromium's for the same page (fixed-size boxes, no text but the Bullet caption's).
use anyrender::PaintScene as _;
use blitz_dom::{Document as _, DocumentConfig};
use blitz_paint::paint_scene;
use blitz_qjs_script::QjsDocument;
use blitz_traits::shell::{ColorScheme, Viewport};
use peniko::{Color, Fill, kurbo::Rect};
fn page() -> String {
let b = |w: u32, h: u32| format!("<div style=\"width:{w}px;height:{h}px\"></div>");
format!(
"<!DOCTYPE html><html><style>body{{margin:0}} table{{border:3px solid #000;padding:2px;margin:5px;border-spacing:2px;background:#0f0}} td{{padding:1px;background:#00f}} caption{{background:#f00}}</style><body>
<table id=t1><caption id=c1>{}</caption><tr><td id=d1>{}</td></tr></table>
<table id=t2 style=\"caption-side:bottom\"><caption id=c2>{}</caption><tr><td id=d2>{}</td></tr></table>
<table id=t3><caption id=c3 style=\"margin:4px 1px\">{}</caption><tr><td id=d3>{}</td></tr></table>
<table id=t4 style=\"border-collapse:collapse;border-width:1px;padding:0\"><caption id=c4>{}</caption><tr><td id=d4 style=\"border:1px solid\">{}</td></tr></table>
<table id=t4b style=\"border-collapse:collapse;border-width:1px;padding:0\"><tr><td id=d4b style=\"border:1px solid\">{}</td></tr></table>
<table id=t5><caption id=c5 style=\"font:16px/19px Bullet;background:#fff\">•••</caption><tr><td>{}</td></tr></table>
</body></html>",
b(10, 7),
b(20, 10),
b(10, 7),
b(20, 10),
b(60, 5),
b(20, 10),
b(10, 7),
b(20, 10),
b(20, 10),
b(20, 10)
)
}
fn doc() -> QjsDocument {
let config = DocumentConfig {
viewport: Some(Viewport::new(400, 400, 1.0, ColorScheme::Light)),
..DocumentConfig::default()
};
let mut doc = QjsDocument::from_html(&page(), config);
doc.inner_mut().resolve(0.0);
doc
}
#[test]
fn a_caption_has_its_box_in_the_table_s() {
let mut doc = doc();
doc.eval(
"const r = (id) => { const b = document.getElementById(id).getBoundingClientRect(); return `${id}=${b.x},${b.y},${b.width},${b.height}`; };
console.log(['t1', 'c1', 'd1', 't2', 'c2', 'd2', 't3', 'c3', 'd3'].map(r).join(' '));
const b = (id) => document.getElementById(id).getBoundingClientRect();
const [t4, c4, d4, t4b, d4b] = ['t4', 'c4', 'd4', 't4b', 'd4b'].map(b);
console.log(`t4: caption at top ${c4.x === t4.x && c4.y === t4.y && c4.width === t4.width} ${c4.height} taller ${t4.height - t4b.height} grid ${d4.y - t4.y - (d4b.y - t4b.y)} same width ${t4.width === t4b.width}`);",
"test",
);
assert_eq!(doc.take_js_errors(), Vec::<String>::new());
assert_eq!(
doc.take_messages(),
[
"log: t1=5,5,36,33 c1=5,5,36,7 d1=12,19,22,12 t2=5,43,36,33 c2=5,69,36,7 d2=12,50,22,12 t3=5,81,62,39 c3=6,85,60,5 d3=12,101,48,12",
// A collapsed-borders table, by how its caption places it (Lite sizes the collapsed
// borders themselves differently: QA.md section 6).
"log: t4: caption at top true 7 taller 7 grid 7 same width true",
]
);
}
/// A caption wider than the grid wraps at the table's width, and still does after the table is
/// laid out again (here for a narrower body). Measuring the caption's min-content width used to
/// wrap its text at that width, and the caption's own layout then came from the cache: its box
/// kept two lines' height while its text ran over five, into the rows below.
#[test]
fn a_caption_s_text_wraps_at_the_table_s_width_after_a_relayout() {
let html = "<!DOCTYPE html><html><body style=\"margin:0\"><table style=\"border-spacing:0\"><caption id=c style=\"font:16px/19px Bullet\">•• •• •• •• •• ••</caption><tr><td style=\"padding:0\"><div style=\"width:100px;height:10px\"></div></td></tr></table></body></html>";
let config = DocumentConfig {
viewport: Some(Viewport::new(400, 400, 1.0, ColorScheme::Light)),
..DocumentConfig::default()
};
let mut doc = QjsDocument::from_html(html, config);
let lines = "{ const c = document.getElementById('c'); const r = document.createRange(); r.selectNodeContents(c);
console.log(`${c.getBoundingClientRect().height} ${[...r.getClientRects()].map((l) => Math.round(l.width)).join(' ')}`); }";
doc.inner_mut().resolve(0.0);
doc.eval(lines, "test");
doc.eval("document.body.style.width = '350px'", "test");
doc.inner_mut().resolve(0.0);
doc.eval(lines, "test");
assert_eq!(doc.take_js_errors(), Vec::<String>::new());
assert_eq!(doc.take_messages(), ["log: 38 91 42", "log: 38 91 42"]);
}
#[test]
fn a_caption_is_drawn_and_the_table_s_box_goes_around_the_grid() {
let mut doc = doc();
doc.eval(
"const b = document.getElementById('c5').getBoundingClientRect(); console.log([b.x, b.y, b.right, b.bottom].join(' '));",
"test",
);
let caption: Vec<usize> = doc.take_messages()[0]
.strip_prefix("log: ")
.unwrap()
.split(' ')
.map(|v| v.parse::<f64>().unwrap() as usize)
.collect();
let (w, h) = (400, 400);
let mut surface = cairo::ImageSurface::create(cairo::Format::Rgb24, w, h).unwrap();
let mut caches = anyrender_cairo::Caches::new();
{
let cr = cairo::Context::new(&surface).unwrap();
let mut scene = anyrender_cairo::CairoScene::new(cr, &mut caches);
let page = Rect::new(0.0, 0.0, w as f64, h as f64);
scene.fill(Fill::NonZero, Default::default(), Color::WHITE, None, &page);
paint_scene(
&mut scene,
&mut doc.inner_mut(),
1.0,
w as u32,
h as u32,
0,
0,
);
}
surface.flush();
let stride = surface.stride() as usize;
let data = surface.data().unwrap();
let px = |x: usize, y: usize| {
let p = &data[y * stride + x * 4..];
(p[2], p[1], p[0])
};
let name = |x: usize, y: usize| match px(x, y) {
(255, 255, 255) => 'w',
(255, 0, 0) => 'r',
(0, 0, 0) => 'k',
(0, 255, 0) => 'g',
(0, 0, 255) => 'b',
_ => '?',
};
// Columns down tables 1 to 3: the caption (r), the table's border (k) and background (g)
// around the grid only, a cell (b).
let columns: Vec<String> = [6, 8, 20]
.iter()
.map(|&x| format!("{x}: {}", (0..122).map(|y| name(x, y)).collect::<String>()))
.collect();
assert_eq!(
columns,
[
"6: wwwwwrrrrrrrkkkkkkkkkkkkkkkkkkkkkkkkkkwwwwwkkkkkkkkkkkkkkkkkkkkkkkkkkrrrrrrrwwwwwwwwwrrrrrwwwwkkkkkkkkkkkkkkkkkkkkkkkkkkww",
"8: wwwwwrrrrrrrkkkggggggggggggggggggggkkkwwwwwkkkggggggggggggggggggggkkkrrrrrrrwwwwwwwwwrrrrrwwwwkkkggggggggggggggggggggkkkww",
"20: wwwwwrrrrrrrkkkggggbbbbbbbbbbbbggggkkkwwwwwkkkggggbbbbbbbbbbbbggggkkkrrrrrrrwwwwwwwwwrrrrrwwwwkkkggggbbbbbbbbbbbbggggkkkww",
]
);
// The caption's text: ink in its box.
let (x0, y0, x1, y1) = (caption[0], caption[1], caption[2], caption[3]);
let ink = (y0..y1)
.flat_map(|y| (x0..x1).map(move |x| (x, y)))
.filter(|&(x, y)| px(x, y).0 < 128)
.count();
assert!(
y1 > y0 && ink > 0,
"no ink in the caption's box {caption:?}"
);
}

View file

@ -267,6 +267,14 @@
Chromium (`table_track_box`): a row spans the columns over its track, a group its rows, and
with collapsed borders each reaches the middle of the borders around it. Blitz lays out only
the cells, so they were 0,0,0,0 (and a parity capture of any page showing a table differed).
- `blitz-dom` layout, layout/table; `blitz-paint` render: a table's `<caption>`s, as in Chromium
(CSS 2's table wrapper box): each is a block across the table's border box, above the grid or
below it (`caption-side`), its margins inside the table's box, and the table is at least as
wide as their min-content widths. Taffy lays the grid out with the captions' heights added to
its top and bottom padding; the table's background and border go around the grid only. A
caption's min-content width is measured width-only, since a full measure wraps its text at that
width and a cached layout at the table's width doesn't wrap it back. Blitz skipped captions (no
box, nothing drawn), so their text was missing from books.
- `blitz-dom` node: an inline element's fragments leave out the box placed for an absolutely
positioned descendant unless the element has nothing else on that line (an empty positioned
link is still the containing block of its `::before`). That box sits before the collapsible

View file

@ -3219,7 +3219,7 @@ diff -ruN blitz/packages/blitz-dom/src/layout/mod.rs blitz/packages/blitz-dom/sr
}
output
}
@@ -206,15 +245,263 @@
@@ -206,15 +245,427 @@
node: &'a Node,
) -> stylo_taffy::TaffyStyloStyle<ComputedStyleRef<'a>> {
#[cfg(feature = "writing-mode")]
@ -3245,7 +3245,7 @@ diff -ruN blitz/packages/blitz-dom/src/layout/mod.rs blitz/packages/blitz-dom/sr
{
- node.layout_style()
+ style.flags |= stylo_taffy::StyleFlags::RENDERED_LEGEND;
+ }
}
+ style
+ }
+
@ -3310,7 +3310,7 @@ diff -ruN blitz/packages/blitz-dom/src/layout/mod.rs blitz/packages/blitz-dom/sr
+ shown |= bar_y;
+ }
+ }
}
+ }
+ (shown != current).then_some(shown)
+ }
+
@ -3441,6 +3441,170 @@ diff -ruN blitz/packages/blitz-dom/src/layout/mod.rs blitz/packages/blitz-dom/sr
+ output
+ }
+
+ /// A table with captions, as Chromium lays it out (CSS 2's table wrapper box): each caption
+ /// spans the table's border box, above the grid or below it (`caption-side`), its margins
+ /// inside the table's box, and the table is at least as wide as the captions' min-content
+ /// widths (its columns take the extra width). Taffy lays the grid out with the captions'
+ /// heights added to its top and bottom padding. Returns the layout and the height of the
+ /// captions above the grid.
+ fn compute_captioned_table_layout(
+ &mut self,
+ node_id: NodeId,
+ inputs: taffy::tree::LayoutInput,
+ ctx: &Arc<table::TableContext>,
+ ) -> (taffy::tree::LayoutOutput, f32) {
+ use style::values::computed::table::CaptionSide;
+ let parent_width = inputs.parent_size.width;
+ let caption_input =
+ |run_mode, width: Option<f32>, available: AvailableSpace, parent: Option<f32>| {
+ taffy::LayoutInput {
+ known_dimensions: Size {
+ width,
+ height: None,
+ },
+ known_dimensions_are_definite: Size {
+ width: true,
+ height: true,
+ },
+ parent_size: Size {
+ width: parent,
+ height: None,
+ },
+ available_space: Size {
+ width: available,
+ height: AvailableSpace::MaxContent,
+ },
+ sizing_mode: taffy::SizingMode::InherentSize,
+ axis: taffy::RequestedAxis::Both,
+ run_mode,
+ vertical_margins_are_collapsible: Line::FALSE,
+ }
+ };
+ let width = match inputs.known_dimensions.width {
+ Some(width) => width,
+ None => {
+ let mut min = 0.0f32;
+ for &caption in &ctx.captions {
+ let margin = self.nodes[caption]
+ .layout_style()
+ .margin()
+ .resolve_or_zero(parent_width, resolve_calc_value);
+ // A width-only measure: a full one would wrap the caption's text at its
+ // min-content width, and a cached layout at the table's width wouldn't wrap
+ // it back.
+ let input = taffy::LayoutInput {
+ axis: taffy::RequestedAxis::Horizontal,
+ ..caption_input(
+ RunMode::ComputeSize,
+ None,
+ AvailableSpace::MinContent,
+ parent_width,
+ )
+ };
+ let size = self
+ .compute_child_layout(taffy_node_id(caption), input)
+ .size;
+ min = min.max(size.width + margin.horizontal_axis_sum());
+ }
+ let mut grid = TableTreeWrapper {
+ doc: self,
+ ctx: Arc::clone(ctx),
+ style: None,
+ };
+ let input = taffy::LayoutInput {
+ run_mode: RunMode::ComputeSize,
+ ..inputs
+ };
+ compute_grid_layout(&mut grid, node_id, input)
+ .size
+ .width
+ .max(min)
+ }
+ };
+ let (mut top, mut bottom) = (0.0f32, 0.0f32);
+ let mut placed = Vec::with_capacity(ctx.captions.len());
+ for &caption in &ctx.captions {
+ let (below, border, padding, margin) = {
+ let node = &self.nodes[caption];
+ let below = node
+ .primary_styles()
+ .is_some_and(|s| s.get_inherited_table().caption_side == CaptionSide::Bottom);
+ let style = node.layout_style();
+ let resolve = |r: taffy::Rect<taffy::LengthPercentage>| {
+ r.resolve_or_zero(Some(width), resolve_calc_value)
+ };
+ (
+ below,
+ resolve(style.border()),
+ resolve(style.padding()),
+ style
+ .margin()
+ .resolve_or_zero(Some(width), resolve_calc_value),
+ )
+ };
+ let inner = (width - margin.horizontal_axis_sum()).max(0.0);
+ let input = caption_input(
+ inputs.run_mode,
+ Some(inner),
+ AvailableSpace::Definite(inner),
+ Some(width),
+ );
+ let out = self.compute_child_layout(taffy_node_id(caption), input);
+ let height = margin.vertical_axis_sum() + out.size.height;
+ if below {
+ bottom += height;
+ } else {
+ top += height;
+ }
+ placed.push((caption, below, out, border, padding, margin));
+ }
+ let mut style = ctx.style.clone();
+ let padding = style
+ .padding
+ .resolve_or_zero(parent_width, resolve_calc_value);
+ style.padding.top = taffy::style_helpers::length(padding.top + top);
+ style.padding.bottom = taffy::style_helpers::length(padding.bottom + bottom);
+ let mut grid = TableTreeWrapper {
+ doc: self,
+ ctx: Arc::clone(ctx),
+ style: Some(style),
+ };
+ let input = taffy::LayoutInput {
+ known_dimensions: Size {
+ width: Some(width),
+ height: inputs.known_dimensions.height,
+ },
+ ..inputs
+ };
+ let output = compute_grid_layout(&mut grid, node_id, input);
+ if inputs.run_mode == RunMode::PerformLayout {
+ let (mut above, mut below_y) = (0.0, output.size.height - bottom);
+ for (caption, below, out, border, padding, margin) in placed {
+ let y = if below { &mut below_y } else { &mut above };
+ let location = taffy::Point {
+ x: margin.left,
+ y: *y + margin.top,
+ };
+ *y += margin.vertical_axis_sum() + out.size.height;
+ let order = self.nodes[caption].unrounded_layout().order;
+ self.set_unrounded_layout(
+ taffy_node_id(caption),
+ &taffy::Layout {
+ order,
+ location,
+ size: out.size,
+ scrollable_overflow_rect: out.scrollable_overflow_rect,
+ scrollbar_size: Size::ZERO,
+ border,
+ padding,
+ margin,
+ },
+ );
+ }
+ }
+ (output, top)
+ }
+
+ /// Whether `node` is `position: relative` with a percentage `top` or `bottom` and its
+ /// containing block (its layout parent) has an indefinite height, so those act as `auto`.
+ fn in_indefinite_height(&self, node: &Node) -> bool {
@ -3486,7 +3650,7 @@ diff -ruN blitz/packages/blitz-dom/src/layout/mod.rs blitz/packages/blitz-dom/sr
}
fn dispatch_child_layout(
@@ -240,6 +527,7 @@
@@ -240,6 +691,7 @@
});
let font_size = font_styles.map(|s| s.0);
let resolved_line_height = font_styles.map(|s| s.1);
@ -3494,7 +3658,7 @@ diff -ruN blitz/packages/blitz-dom/src/layout/mod.rs blitz/packages/blitz-dom/sr
match &mut node.data {
NodeData::Text(data) => {
@@ -309,20 +597,7 @@
@@ -309,20 +761,7 @@
.resolve_or_zero(inputs.parent_size.width, resolve_calc_value)
};
let content_width = (output.size.width - pb.horizontal_axis_sum()).max(0.0);
@ -3516,7 +3680,7 @@ diff -ruN blitz/packages/blitz-dom/src/layout/mod.rs blitz/packages/blitz-dom/sr
}
return output;
}
@@ -333,7 +608,7 @@
@@ -333,7 +772,7 @@
Some("hidden") => {
return taffy::LayoutOutput::HIDDEN;
}
@ -3525,7 +3689,7 @@ diff -ruN blitz/packages/blitz-dom/src/layout/mod.rs blitz/packages/blitz-dom/sr
return compute_leaf_layout(
inputs,
&node.layout_style(),
@@ -357,7 +632,7 @@
@@ -357,7 +796,7 @@
);
}
None | Some("text" | "password" | "email" | "tel" | "url" | "search") => {
@ -3534,7 +3698,7 @@ diff -ruN blitz/packages/blitz-dom/src/layout/mod.rs blitz/packages/blitz-dom/sr
inputs,
&node.layout_style(),
resolve_calc_value,
@@ -370,6 +645,28 @@
@@ -370,6 +809,28 @@
height: resolved_line_height.unwrap_or(16.0),
},
);
@ -3563,7 +3727,44 @@ diff -ruN blitz/packages/blitz-dom/src/layout/mod.rs blitz/packages/blitz-dom/sr
}
_ => {}
}
@@ -586,6 +883,10 @@
@@ -532,15 +993,22 @@
};
let context = Arc::clone(context);
- let mut table_wrapper = TableTreeWrapper {
- doc: self,
- ctx: context,
+ let (mut output, caption_top) = if context.captions.is_empty() {
+ let mut table_wrapper = TableTreeWrapper {
+ doc: self,
+ ctx: Arc::clone(&context),
+ style: None,
+ };
+ (
+ compute_grid_layout(&mut table_wrapper, node_id, inputs),
+ 0.0,
+ )
+ } else {
+ self.compute_captioned_table_layout(node_id, inputs, &context)
};
- let mut output = compute_grid_layout(&mut table_wrapper, node_id, inputs);
// Absolutely positioned children take no part in the table grid. Their
// static position is the top-left of the table's content box.
- let context = table_wrapper.ctx;
if inputs.run_mode == RunMode::PerformLayout && !context.oof_children.is_empty()
{
let style = &context.style;
@@ -553,7 +1021,7 @@
.resolve_or_zero(parent_width, resolve_calc_value);
let static_position = taffy::Point {
x: padding.left + border.left,
- y: padding.top + border.top,
+ y: caption_top + padding.top + border.top,
}
.map(|pos| AxisStaticPosition::from_edge(pos, AxisStaticEdge::Start));
let in_flow_count = context.cells.len();
@@ -586,6 +1054,10 @@
return self.compute_inline_layout(dom_node_id(node_id), inputs, block_ctx);
}
@ -3574,7 +3775,7 @@ diff -ruN blitz/packages/blitz-dom/src/layout/mod.rs blitz/packages/blitz-dom/sr
// The default CSS file will set
match node.taffy_display() {
Display::Block => compute_block_layout(self, node_id, inputs, block_ctx),
@@ -652,18 +953,22 @@
@@ -652,18 +1124,22 @@
fn get_core_container_style(&self, node_id: NodeId) -> Self::CoreContainerStyle<'_> {
#[cfg(feature = "writing-mode")]
@ -3602,7 +3803,7 @@ diff -ruN blitz/packages/blitz-dom/src/layout/mod.rs blitz/packages/blitz-dom/sr
}
fn set_unrounded_layout(&mut self, node_id: NodeId, layout: &Layout) {
@@ -846,13 +1151,45 @@
@@ -846,13 +1322,45 @@
}
}
@ -3650,7 +3851,7 @@ diff -ruN blitz/packages/blitz-dom/src/layout/mod.rs blitz/packages/blitz-dom/sr
}
fn is_out_of_flow(&self, node_id: NodeId) -> bool {
@@ -972,3 +1309,25 @@
@@ -972,3 +1480,25 @@
})
}
}
@ -3919,6 +4120,84 @@ diff -ruN blitz/packages/blitz-dom/src/layout/sticky.rs blitz/packages/blitz-dom
+ Some((dx, dy))
+ }
+}
diff -ruN blitz/packages/blitz-dom/src/layout/table.rs blitz/packages/blitz-dom/src/layout/table.rs
--- blitz/packages/blitz-dom/src/layout/table.rs
+++ blitz/packages/blitz-dom/src/layout/table.rs
@@ -34,6 +34,8 @@
pub struct TableTreeWrapper<'a, 'doc> {
pub(crate) doc: &'a mut LayoutPassState<'doc>,
pub(crate) ctx: Arc<TableContext>,
+ /// The grid's style when it isn't `ctx.style`: with captions, more padding for them.
+ pub(crate) style: Option<taffy::Style<Atom>>,
}
// Deliberately not `Clone`: `style` may hold raw pointers into `calc_values`.
@@ -49,6 +51,9 @@
pub computed_grid_info: AtomicRefCell<Option<DetailedGridInfo<Atom>>>,
pub border_style: Option<ServoArc<Border>>,
pub border_collapse: BorderCollapse,
+ /// The table's captions (`display: table-caption` children, in tree order), laid out above
+ /// or below the grid in the table's box rather than in the grid.
+ pub captions: Vec<NodeId>,
/// Backing storage for `calc()` track sizes synthesised by the table layout code.
/// Taffy stores calc values as raw pointers, so these must outlive the `style`.
#[allow(dead_code)]
@@ -241,6 +246,21 @@
drop(stylo_styles);
+ let captions: Vec<NodeId> = children
+ .iter()
+ .copied()
+ .filter(|&id| {
+ let node = &doc.nodes[id];
+ node.is_element()
+ && node
+ .display_style()
+ .is_some_and(|d| d.outside() == DisplayOutside::TableCaption)
+ && !node
+ .primary_styles()
+ .is_some_and(|s| s.clone_position().is_absolutely_positioned())
+ })
+ .collect();
+
let mut columns: Vec<TableColumn> = Vec::new();
let mut column_sizes: Vec<taffy::TrackSizingFunction> = Vec::new();
for child_id in children.iter().copied() {
@@ -271,7 +291,7 @@
};
for order in 0..3 {
for child_id in children.iter().copied() {
- if row_group_order(doc, child_id) != order {
+ if captions.contains(&child_id) || row_group_order(doc, child_id) != order {
continue;
}
collect_table_cells(
@@ -415,6 +435,7 @@
.iter()
.map(|cell| cell.node_id)
.chain(oof_children.iter().map(|(node_id, _)| *node_id))
+ .chain(captions.iter().copied())
.collect();
let root_node = &mut doc.nodes[table_root_node_id];
root_node.children = children;
@@ -429,6 +450,7 @@
computed_grid_info: AtomicRefCell::new(None),
border_collapse,
border_style: first_cell_border,
+ captions,
calc_values,
},
layout_children,
@@ -801,7 +823,7 @@
type CustomIdent = Atom;
fn get_core_container_style(&self, _node_id: taffy::NodeId) -> &taffy::Style<Atom> {
- &self.ctx.style
+ self.style.as_ref().unwrap_or(&self.ctx.style)
}
fn resolve_calc_value(&self, calc_ptr: *const (), parent_size: f32) -> f32 {
diff -ruN blitz/packages/blitz-dom/src/lib.rs blitz/packages/blitz-dom/src/lib.rs
--- blitz/packages/blitz-dom/src/lib.rs
+++ blitz/packages/blitz-dom/src/lib.rs
@ -7211,17 +7490,23 @@ diff -ruN blitz/packages/blitz-paint/src/render.rs blitz/packages/blitz-paint/sr
// If the element has a CSS `mask`, then push an isolation layer for the
// masked content. The mask is applied when the layer is popped below.
let mask_layer_pushed = cx.maybe_push_css_mask_layer(scene);
@@ -642,14 +678,28 @@
@@ -642,14 +678,34 @@
filter,
backdrop_filter,
|scene| {
+ // A fieldset paints its box under its legend.
+ let fieldset = paints_own_box.then(|| cx.fieldset_box()).flatten();
+ let box_cx = fieldset.as_ref().map(|(frame, _)| ElementCx {
+ frame: frame.clone(),
+ style: cx.style.clone(),
+ ..cx
+ });
+ // A table with captions paints its box around its grid.
+ let grid = paints_own_box.then(|| cx.table_grid_box()).flatten();
+ let box_cx = fieldset
+ .as_ref()
+ .map(|(frame, _)| frame)
+ .or(grid.as_ref())
+ .map(|frame| ElementCx {
+ frame: frame.clone(),
+ style: cx.style.clone(),
+ ..cx
+ });
+ let box_cx = box_cx.as_ref().unwrap_or(&cx);
if paints_own_box {
- cx.draw_background(scene);
@ -7243,7 +7528,7 @@ diff -ruN blitz/packages/blitz-paint/src/render.rs blitz/packages/blitz-paint/sr
}
cx.stroke_devtools(scene);
@@ -683,12 +733,12 @@
@@ -683,12 +739,12 @@
cx.draw_svg(scene);
#[cfg(feature = "custom-widget")]
cx.draw_custom_widget(scene);
@ -7258,7 +7543,7 @@ diff -ruN blitz/packages/blitz-paint/src/render.rs blitz/packages/blitz-paint/sr
},
);
@@ -699,6 +749,12 @@
@@ -699,6 +755,12 @@
cx.transform = unscrolled_transform;
cx.draw_scrollbars(scene);
}
@ -7271,7 +7556,7 @@ diff -ruN blitz/packages/blitz-paint/src/render.rs blitz/packages/blitz-paint/sr
},
);
@@ -708,6 +764,10 @@
@@ -708,6 +770,10 @@
},
);
@ -7282,7 +7567,7 @@ diff -ruN blitz/packages/blitz-paint/src/render.rs blitz/packages/blitz-paint/sr
self.layer_manager
.maybe_pop_layer(scene, blend_layer_pushed);
self.layer_manager
@@ -794,8 +854,13 @@
@@ -794,8 +860,13 @@
/// The transform from an SVG's rendered tree to a viewport of the given size.
#[cfg(feature = "svg")]
@ -7298,7 +7583,7 @@ diff -ruN blitz/packages/blitz-paint/src/render.rs blitz/packages/blitz-paint/sr
Affine::new([t.sx, t.ky, t.kx, t.sy, t.tx, t.ty].map(f64::from))
}
@@ -836,6 +901,43 @@
@@ -836,6 +907,82 @@
custom_widget_scene: Option<&'a Scene>,
}
@ -7337,12 +7622,51 @@ diff -ruN blitz/packages/blitz-paint/src/render.rs blitz/packages/blitz-paint/sr
+ clip.extend(gap.to_path(0.1));
+ Some((painted, clip))
+ }
+
+ /// The box a table with captions paints its background and border in: its border box less
+ /// the captions above and below the grid, with their margins.
+ fn table_grid_box(&self) -> Option<CssBox> {
+ use style::values::computed::table::CaptionSide;
+ let blitz_dom::node::SpecialElementData::TableRoot(table) = &self.element.special_data
+ else {
+ return None;
+ };
+ if table.captions.is_empty() {
+ return None;
+ }
+ let tree = self.node.tree();
+ let (mut top, mut bottom) = (0.0f32, self.node.final_layout().size.height);
+ for &id in &table.captions {
+ let node = &tree[id];
+ let l = node.final_layout();
+ if node
+ .primary_styles()
+ .is_some_and(|s| s.get_inherited_table().caption_side == CaptionSide::Bottom)
+ {
+ bottom = bottom.min(l.location.y - l.margin.top);
+ } else {
+ top = top.max(l.location.y + l.size.height + l.margin.bottom);
+ }
+ }
+ let s = self.scale;
+ let frame = &self.frame;
+ let mut border_box = frame.border_box;
+ border_box.y0 = frame.border_box.y0 + top as f64 * s;
+ border_box.y1 = (frame.border_box.y0 + bottom as f64 * s).max(border_box.y0);
+ Some(CssBox::new(
+ border_box,
+ frame.border_width,
+ frame.padding_width,
+ frame.outline_width,
+ frame.border_radii,
+ ))
+ }
+}
+
/// Converts parley BoundingBox into peniko Rect
fn convert_rect(rect: &parley::BoundingBox) -> kurbo::Rect {
peniko::kurbo::Rect::new(rect.x0, rect.y0, rect.x1, rect.y1)
@@ -995,16 +1097,34 @@
@@ -995,16 +1142,34 @@
self.node.id,
);
@ -7381,7 +7705,7 @@ diff -ruN blitz/packages/blitz-paint/src/render.rs blitz/packages/blitz-paint/sr
// Render text
let mut draw_text_context = self.context.draw_text_context.borrow_mut();
@@ -1020,6 +1140,28 @@
@@ -1020,6 +1185,28 @@
self.node.id,
&mut draw_text_context,
);
@ -7410,7 +7734,7 @@ diff -ruN blitz/packages/blitz-paint/src/render.rs blitz/packages/blitz-paint/sr
}
}
@@ -1076,6 +1218,37 @@
@@ -1076,6 +1263,37 @@
};
}
@ -7448,7 +7772,7 @@ diff -ruN blitz/packages/blitz-paint/src/render.rs blitz/packages/blitz-paint/sr
// Render text
let mut draw_text_context = self.context.draw_text_context.borrow_mut();
crate::text::stroke_text(
@@ -1152,6 +1325,63 @@
@@ -1152,6 +1370,63 @@
}
}
@ -7512,7 +7836,7 @@ diff -ruN blitz/packages/blitz-paint/src/render.rs blitz/packages/blitz-paint/sr
fn draw_children(
&self,
scene: &mut impl PaintScene,
@@ -1183,7 +1413,9 @@
@@ -1183,7 +1458,9 @@
// the viewport and do not scroll with it, so cancel out the viewport
// scroll (applied in `paint_scene`). A fixed box contained by a
// transformed ancestor scrolls with it like any out-of-flow box.
@ -7523,7 +7847,7 @@ diff -ruN blitz/packages/blitz-paint/src/render.rs blitz/packages/blitz-paint/sr
let child_transform = if child.taffy_position() == taffy::Position::Fixed
&& Some(self.node.id) == self.context.root_element_id
{
@@ -1193,6 +1425,15 @@
@@ -1193,6 +1470,15 @@
y: scroll.y * self.scale,
})
} else if let Some(offset) = child.lifted_paint_offset(self.node.id) {
@ -7539,7 +7863,7 @@ diff -ruN blitz/packages/blitz-paint/src/render.rs blitz/packages/blitz-paint/sr
parent_style_transform.pre_translate(kurbo::Vec2 {
x: offset.x as f64 * self.scale,
y: offset.y as f64 * self.scale,
@@ -1200,7 +1441,37 @@
@@ -1200,7 +1486,37 @@
} else {
parent_style_transform
};
@ -7578,7 +7902,7 @@ diff -ruN blitz/packages/blitz-paint/src/render.rs blitz/packages/blitz-paint/sr
}
}
@@ -1269,7 +1540,7 @@
@@ -1269,7 +1585,7 @@
let x = x + x_offset.px() as f64;
let y = y + y_offset.px() as f64;
@ -7587,7 +7911,7 @@ diff -ruN blitz/packages/blitz-paint/src/render.rs blitz/packages/blitz-paint/sr
let transform = (self.transform * viewport).then_translate(Vec2 { x, y });
self.with_replaced_content_clip(
@@ -1377,19 +1648,28 @@
@@ -1377,19 +1693,28 @@
}
}
@ -7625,7 +7949,7 @@ diff -ruN blitz/packages/blitz-paint/src/render.rs blitz/packages/blitz-paint/sr
&sub_doc,
scale,
width,
@@ -1398,6 +1678,15 @@
@@ -1398,6 +1723,15 @@
initial_y,
self.custom_widget_scenes,
);