1
0

8 Revīzijas 3b2607df02 ... 094a42f397

Autors SHA1 Ziņojums Datums
  Johannes Zellner 094a42f397 Fix the X201 rootfs load with a protected-mode pack copy 1 nedēļu atpakaļ
  Johannes Zellner 13291ce526 Render inline SVG and fix tagesschau.de layout gaps 1 nedēļu atpakaļ
  Johannes Zellner a1e381e370 Drain the fetch helpers' log tty so cross-origin loads cannot hang 1 nedēļu atpakaļ
  Johannes Zellner c1edf1b343 Fix stalled keep-alive requests and image decode bursts 1 nedēļu atpakaļ
  Johannes Zellner b2bdb6517e Fix tagesschau layout and large-page loading 1 nedēļu atpakaļ
  Johannes Zellner f1db581539 Use green for the top-bar battery icon 1 nedēļu atpakaļ
  Johannes Zellner 80f115360f Map legacy -webkit-box display to block 1 nedēļu atpakaļ
  Johannes Zellner 294775f232 Improve browser layout for details, SVG and absolute posters 1 nedēļu atpakaļ

+ 1 - 0
.gitignore

@@ -16,6 +16,7 @@ text_canvas_test
 ufont_test
 ufont_test_asan
 touchpad_gesture_test
+svg_test
 libc.a
 malloc_test
 format_test

+ 56 - 27
AGENTS.md

@@ -81,6 +81,7 @@ make test-libc  # host tests for ring-3 malloc, stdio, math, div64 and setjmp
 make test-mujs  # host smoke test for the vendored MuJS engine
 make test-font  # host TrueType parser/rasterizer specimen test
 make test-font-asan  # ASan/UBSan variant
+make test-svg   # host tests for the inline-SVG rasterizer (ASan/UBSan)
 make test-touchpad  # host tests for the contact gesture engine
 make test-wpa   # host tests for the WPA2-PSK supplicant (SHA-1/PBKDF2/PRF/AES, 4-way)
 make test-chat  # host tests: JSON parser, cookie jar, chat login parsers (ASan)
@@ -139,9 +140,12 @@ make clean
    enables A20, reads the `NBROOT1` rootfs header at the boot sector's
    `pack_lba` field and copies the gzip pack directly to `PACK_HIGH_ADDR`
    (`0x900000`, above the 8 MB VGA-shadow reserve) in 16 KB chunks through
-   the `0x3000` staging buffer with INT 15h AH=87h.  The BIOS block move uses
-   24-bit descriptor bases; `paging_prepare_cpu()` clears the CR4/EFER state
-   the X201's BIOS leaves behind.  The stage then picks the best VBE mode
+   the `0x3000` staging buffer with a temporary flat protected-mode
+   `rep movsb` (`pm_copy`).  The X201 BIOS's INT 15h AH=87h block move
+   silently copies zeros to this range, which left the kernel with an empty
+   pack; the CPU copy is used instead.  `paging_prepare_cpu()` still clears
+   the CR4/EFER state a BIOS protected-mode call can leave behind.  The
+   stage then picks the best VBE mode
    (≥16 bpp, LFB, fits VRAM, ≤1280px), writes mode info to `0x600` and the
    12-dword `struct boot_info` (magic/checksum/rsdp/flags/pack range) to
    `0x500`, enters protected mode and jumps to `kernel_entry` (`entry.S`,
@@ -289,8 +293,8 @@ it to `0x7E00`.  The kernel region itself only has one wall (`_end` below
   LFB (uncacheable) and enables CR0.PG/WP. Before the switch it clears stale
   translation controls a BIOS protected-mode call can leave behind
   (`CR4.PAE/PGE/LA57/PCIDE/SMEP/SMAP` and `EFER.LME`); the X201's legacy
-  stage used to return from `INT 15h AH=87h` with `CR4` set, and the first
-  `CR0.PG` write then triple-faulted.  The LFB PDE range is computed from
+  stage historically returned from `INT 15h AH=87h` with `CR4` set, and the
+  first `CR0.PG` write then triple-faulted.  The LFB PDE range is computed from
   the page index (a base above `0xFF000000` used to wrap `base + 16 MB` and
   map nothing), and `mm_init` reserves a low LFB range so the boot console
   cannot overwrite the page directory.  Each process gets a page directory
@@ -911,8 +915,9 @@ it to `0x7E00`.  The kernel region itself only has one wall (`_end` below
   `USER_BASE` (`0x40000000`), packed by `mkpack` into `cmds.pack` (as
   `bin/<name>`), gzipped to `cmds_pack_gz.bin` and wrapped by `mkrootfs`
   with a `NBROOT1` header.  The pack is the system rootfs: the boot path
-  loads it into RAM (legacy high-memory AH=87h copy / UEFI / kexec staging)
-  and `ramfs_init` takes a private page-allocated copy, mounted read-only at
+  loads it into RAM (legacy high-memory protected-mode copy / UEFI / kexec
+  staging) and `ramfs_init` takes a private page-allocated copy, mounted
+  read-only at
   `/ramfs`.  The
   shell finds them through PATH (`/ramfs/bin` by default), loads the whole
   ELF through the VFS and spawns it as a ring-3 process; `hello` is just
@@ -991,10 +996,26 @@ it to `0x7E00`.  The kernel region itself only has one wall (`_end` below
   `@font-face` loads one regular TTF per family from a local path or HTTP URL
   (the browser fetches remote faces before layout).  The compatibility
   ladder is `testdata/browser/compat/`
-  (`make compat-serve`); pages 010–046 and 030a pass (036a needs the
-  POST echo server).  Inline
-  `<svg>` subtrees and closed `<details>` are skipped (not renderable), and
-  `<video>` gets a placeholder box.  The default page canvas follows
+  (`make compat-serve`); pages 010–070 and 030a pass (036a needs the
+  POST echo server).  Closed `<details>` are skipped and `<video>` gets a
+  placeholder box.  Inline `<svg>` is rendered by `svg_raster.c/h`
+  (freestanding, host test `make test-svg`): every path command including
+  curves and elliptical arcs, `rect`/`circle`/`ellipse`/`line`/`polyline`/
+  `polygon`, `<g>`/`<a>`/nested `<svg>`/`<use>` of a `<symbol>`, `transform`
+  lists, viewBox + `preserveAspectRatio`, nonzero/even-odd fill, strokes,
+  `opacity`/`fill-opacity`, `currentColor`, and a gradient `url(#id)` painted
+  as the average of its stops.  Coverage is antialiased (4 vertical
+  subsamples, exact horizontal spans) into an RGB565 + alpha layer that is
+  cached per node and size (`SVG_CACHE_PIXELS`, page heap, dropped before
+  `heap_reset()`) and blitted on repaint; `<text>` is drawn on top each
+  frame.  SVG paint is its own inherited style state (`fill_mode`/`fill`/
+  `stroke_mode`/`stroke`/`stroke_w`, `BR_PAINT_*`): CSS `fill`/`stroke` on an
+  HTML element no longer paint its background or border, and
+  `getComputedStyle` exposes `fill`/`stroke`.  `line-height` in `rem` is an
+  absolute length, and an `inline-flex` box with only inline content stays in
+  the text line.  Up to `BR_MAX_DEFERRED` (256) absolute/fixed boxes are
+  painted after the flow; past that a box is painted in place against its
+  containing block.  The default page canvas follows
   `ngui_theme_dark` (dark page, light text, `theme.panel` for `<pre>`), but
   the `html`/`body` background fills the whole page canvas, so a site's white
   page has no dark side gutters; other `background-color`/`color` CSS still
@@ -1025,11 +1046,15 @@ it to `0x7E00`.  The kernel region itself only has one wall (`_end` below
   but parsed/executed in document order; one above-fold image starts downloading
   before the script phase so it overlaps the script fetches and execution.
   Each helper keeps its own
-  TCP/TLS connection (TLS stays per-process).  Idle helpers stay warm for a
-  same-origin navigation (reload or another page on the same host) so it
-  reuses the TCP/TLS connection instead of paying a spawn and handshake; a
-  navigation to another origin stops them first, so the previous page's image
-  and TLS connections cannot stall the new fetch.  Helpers also exit after
+  TCP/TLS connection (TLS stays per-process).  Idle helpers stay warm across
+  navigations, so a same-origin load reuses the TCP/TLS connection and a
+  cross-origin job just drops the old one in `uhttp_open`; only busy helpers
+  are killed when the page changes.  The helpers' DNS/TLS log lines (and the
+  browser's own `[js]` lines, since `u_tty_create()` rebinds its output) go to
+  a private 4 KB tty that nobody renders; the browser drains and discards it
+  from every poll loop (`fetch_tty_drain`), because a full tty ring blocks its
+  writers, and `tty_write` drops rather than sleeps when the ring's owner
+  writes to its own full ring.  Helpers also exit after
   ten idle seconds, and the browser stops them at once when its window loses
   focus, so raw commands can acquire the NIC.  A page fetch that fails with a
   DNS error is torn down and tried once more after half a second.  The helper
@@ -1298,8 +1323,9 @@ gzip flag).  The build rejects a pack above the `PACK_MAX` cap (2 MB,
 `CMDS_GZ_MAX` in the Makefile, `PACK_MAX` in `vesa_stage.S`);
 `libdeflate` buys several KB over `gzip -9` and is still preferred.  The boot
 path loads the gz pack into RAM — the legacy stage copies it directly to
-`0x900000` with INT 15h AH=87h, the UEFI loader into a loader-data buffer
-below 512 MB, kexec via its staging buffer — and `ramfs_init()`
+`0x900000` with its protected-mode `rep movsb`, the UEFI loader into a
+loader-data buffer below 512 MB, kexec via its staging buffer — and
+`ramfs_init()`
 inflates it into page-allocated memory and mounts it read-only at `/ramfs`.
 The kernel image no longer contains it, so the pack no longer moves `_end`;
 the high-memory legacy path supports up to 2 MB (known issue 8).  The UI
@@ -1725,9 +1751,10 @@ and the WM falls back to polling (`io_keyboard_irq_masked()`).
 8. The rootfs pack is inflated into one contiguous page-allocated run at
    boot, capped by `RAMFS_MAX_DECOMPRESSED` (8 MB); a larger pack fails to
    load (the USB rootfs partition is 8 MB, so this only bites if the cap is
-   raised without a bigger partition).  The legacy stage now copies the
-   compressed pack directly to `0x900000` with INT 15h AH=87h, so the cap is
-   `PACK_MAX` 2 MB (raised from 1 MB for the WiFi firmware).  The browser and
+   raised without a bigger partition).  The legacy stage copies the
+   compressed pack directly to `0x900000` with a protected-mode
+   `rep movsb`, so the cap is `PACK_MAX` 2 MB (raised from 1 MB for the WiFi
+   firmware).  The browser and
    its ring-3 dependencies are compiled with function sections and linked
    with `--gc-sections`; the current full pack with the UI fonts, the
    1,036,312-byte WiFi firmware and `install/kernel.bin` is ~1.26 MiB gzip
@@ -1824,8 +1851,10 @@ and the WM falls back to polling (`io_keyboard_irq_masked()`).
     CSS custom properties (`var()`), flex rows with wrap/grow/gap/justify/
     align, two-track and `repeat(auto-fit, minmax(...))` grids, inline-block
     runs, basic proportional table columns, table rowspan/colspan/percentage
-    columns and inline SVG (`rect`, `line`, `path` with M/L/H/V, and `text`) are
-    supported.
+    columns and inline SVG (filled/stroked geometry, `use`/`symbol`,
+    transforms; gradients, patterns, clip paths, masks, filters, markers and
+    `textPath` are not rendered, a gradient paints its average stop colour)
+    are supported.
     `position:fixed`/`absolute` boxes are deferred and painted above the
     flow; `z-index` sorts that deferred list; `position:relative` shifts
     painting without moving flow (and joins the deferred stack when it has a
@@ -1869,10 +1898,10 @@ and the WM falls back to polling (`io_keyboard_irq_masked()`).
     and private `/share/bf*N` files; images are prefetched in parallel and
     decoded as jobs complete.  Stylesheet and external-script bodies are
     downloaded in parallel but parsed/executed in document order, and one
-    image starts before the script phase.  Idle helpers stay warm for
-    same-origin navigations; a cross-origin navigation stops them first, as
-    does losing focus (or ten idle seconds), so their sockets do not block raw
-    commands or the new page.  The helper requests gzip; a page
+    image starts before the script phase.  Idle helpers stay warm across
+    navigations (a cross-origin job drops the old connection); losing focus
+    or ten idle seconds stops them, so their sockets do not block raw
+    commands.  The helper requests gzip; a page
     that is only small when compressed can exceed the 2 MB page/832 KB CSS
     caps.  Video/audio elements are placeholders.  Bare `&` characters are
     consumed by the entity decoder instead of looping forever.  A page with

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 12 - 3
Makefile


Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 811 - 209
browser.c


+ 375 - 47
browser_html.c

@@ -2058,6 +2058,15 @@ static int parse_svg_viewbox(const char *s, unsigned int len,
 			i++;
 			any = 1;
 		}
+		/* viewBox values are commonly fractional ("0 0 340.16
+		 * 340.16").  Consume the fraction so it is not mistaken for
+		 * the next number; the integer part is enough for the aspect
+		 * ratio used by the renderer. */
+		if (i < len && s[i] == '.') {
+			i++;
+			while (i < len && s[i] >= '0' && s[i] <= '9')
+				i++;
+		}
 		if (!any) {
 			if (i < len)
 				i++;
@@ -2307,6 +2316,83 @@ static int str_eq(const char *a, const char *b)
 
 /* ---- CSS ---- */
 
+static int parse_color(const char *s, unsigned int len, unsigned short *out);
+
+int br_parse_color(const char *s, unsigned int len, unsigned short *out)
+{
+	return parse_color(s, len, out);
+}
+
+/* SVG paint value -> BR_PAINT_* (0 when unrecognised). */
+static int paint_mode(const char *s, unsigned int len, unsigned short *c)
+{
+	while (len && is_space(*s)) {
+		s++;
+		len--;
+	}
+	while (len && is_space(s[len - 1]))
+		len--;
+	if (!len)
+		return 0;
+	if (len == 4 && ci_eq_n(s, "none", 4))
+		return BR_PAINT_NONE;
+	if (len == 12 && ci_eq_n(s, "currentcolor", 12))
+		return BR_PAINT_CURRENT;
+	if (len > 4 && ci_eq_n(s, "url(", 4))
+		return BR_PAINT_URL;
+	if (len == 11 && ci_eq_n(s, "transparent", 11))
+		return BR_PAINT_NONE;
+	if (parse_color(s, len, c))
+		return BR_PAINT_COLOR;
+	return 0;
+}
+
+/* A plain SVG length ("1.5", "2px") in 1/16 units; -1 when not a number. */
+static int svg_len16(const char *s, unsigned int len)
+{
+	unsigned int i = 0;
+	int v = 0, frac = 0, digits = 0;
+
+	while (i < len && is_space(s[i]))
+		i++;
+	while (i < len && s[i] >= '0' && s[i] <= '9') {
+		if (v < 4000)
+			v = v * 10 + (s[i] - '0');
+		i++;
+		digits++;
+	}
+	if (i < len && s[i] == '.') {
+		int scale = 1;
+
+		i++;
+		while (i < len && s[i] >= '0' && s[i] <= '9') {
+			if (scale < 10000) {
+				frac = frac * 10 + (s[i] - '0');
+				scale *= 10;
+			}
+			i++;
+			digits++;
+		}
+		frac = frac * 16 / scale;
+	}
+	if (!digits)
+		return -1;
+	return v * 16 + frac;
+}
+
+/* Inside an <svg> subtree (including the <svg> element itself). */
+static int in_svg(const struct br_doc *d, unsigned int node)
+{
+	unsigned int k;
+
+	for (k = 0; node && node < d->nnode && k < 64; k++) {
+		if (d->nodes[node].tag == BR_TAG_SVG)
+			return 1;
+		node = d->nodes[node].parent;
+	}
+	return 0;
+}
+
 enum {
 	PROP_COLOR, PROP_BG, PROP_BG_IMAGE, PROP_BG_REPEAT,
 	PROP_BG_POS_X_KIND, PROP_BG_POS_X, PROP_BG_POS_Y_KIND, PROP_BG_POS_Y,
@@ -2322,6 +2408,7 @@ enum {
 	PROP_BW_T, PROP_BW_R, PROP_BW_B, PROP_BW_L,
 	PROP_BC_T, PROP_BC_R, PROP_BC_B, PROP_BC_L,
 	PROP_BS_T, PROP_BS_R, PROP_BS_B, PROP_BS_L,
+	PROP_BT_T, PROP_BT_R, PROP_BT_B, PROP_BT_L,
 	PROP_RADIUS_TL, PROP_RADIUS_TR, PROP_RADIUS_BR, PROP_RADIUS_BL,
 	PROP_LIST_NONE, PROP_LIST_STYLE, PROP_NOWRAP,
 	PROP_WIDTH, PROP_WIDTH_KIND, PROP_MAXW, PROP_MAXW_KIND,
@@ -2346,6 +2433,8 @@ enum {
 	PROP_TRANSFORM_PAINT, PROP_SCALE_X, PROP_SCALE_Y, PROP_ROTATE,
 	PROP_ORIGIN_X_KIND, PROP_ORIGIN_X, PROP_ORIGIN_Y_KIND, PROP_ORIGIN_Y,
 	PROP_VIS_HIDDEN, PROP_OPACITY_HIDDEN, PROP_OVERFLOW_HIDDEN,
+	PROP_FILL_MODE, PROP_FILL, PROP_STROKE_MODE, PROP_STROKE,
+	PROP_STROKE_W, PROP_FILL_RULE,
 	PROP_COUNT
 };
 
@@ -2531,6 +2620,40 @@ static int parse_color(const char *s, unsigned int len, unsigned short *out)
 	}
 }
 
+/* Fully transparent colours have no RGB565 representation.  They are common
+ * as pre-allocated borders ("border:.1rem solid #0000") that become visible
+ * only on hover; painting them black would draw an outline around every
+ * pill and card. */
+static int color_is_transparent(const char *s, unsigned int len)
+{
+	unsigned int i = 0, n = 0;
+	int last = 0, prev = 0, d;
+
+	while (i < len && is_space(s[i]))
+		i++;
+	if (i + 11 <= len && ci_eq_n(s + i, "transparent", 11))
+		return 1;
+	if (i >= len || s[i] != '#')
+		return 0;
+	i++;
+	while (i < len && hexval(s[i]) >= 0) {
+		d = hexval(s[i]);
+		prev = last;
+		last = d;
+		n++;
+		i++;
+	}
+	while (i < len && is_space(s[i]))
+		i++;
+	if (i != len)
+		return 0;
+	if (n == 4)
+		return last == 0;
+	if (n == 8)
+		return prev == 0 && last == 0;
+	return 0;
+}
+
 static int register_bg_url(const char *s, unsigned int len)
 {
 	unsigned int i, j, n;
@@ -2587,10 +2710,12 @@ static int parse_len(const char *s, unsigned int len, unsigned int *pos)
 	}
 	if (i < len && s[i] == '.') {
 		i++;
+		/* Minified CSS writes ".5rem" without a leading zero. */
 		while (i < len && s[i] >= '0' && s[i] <= '9') {
 			if (frac < 2) {
 				v = v * 10 + (s[i] - '0');
 				frac++;
+				digits = 1;
 			}
 			i++;
 		}
@@ -2663,10 +2788,13 @@ static int parse_css_len(const char *s, unsigned int len,
 	}
 	if (i < len && s[i] == '.') {
 		i++;
+		/* Leading-dot fractions are common in minified CSS
+		 * (".5rem", ".3rem"). */
 		while (i < len && s[i] >= '0' && s[i] <= '9') {
 			if (frac < 2) {
 				v = v * 10 + (s[i] - '0');
 				frac++;
+				digits = 1;
 			}
 			i++;
 		}
@@ -2838,6 +2966,7 @@ static int parse_size(const char *s, unsigned int len, unsigned short *val,
 			if (frac < 2) {
 				v = v * 10 + (unsigned int)(s[i] - '0');
 				frac++;
+				digits = 1;
 			}
 			i++;
 		}
@@ -2919,6 +3048,7 @@ static int parse_font_px(const char *s, unsigned int len)
 				frac = frac * 10 + (s[i] - '0');
 				fscale *= 10;
 			}
+			digits = 1;
 			i++;
 		}
 	}
@@ -3004,7 +3134,9 @@ static int parse_font_size(const char *s, unsigned int len,
 		*raw = (unsigned short)v100;
 		*unit = 2;
 	} else if (i < len && s[i] == '%') {
-		*raw = (unsigned short)(v100 / 100);
+		/* Keep hundredths: 62.5% is a common root size and truncating
+		 * it to 62% makes every rem 1px too small. */
+		*raw = (unsigned short)v100;
 		*unit = 4;
 	} else {
 		*raw = (unsigned short)(v100 / 100);
@@ -3037,6 +3169,7 @@ static int parse_line_height(const char *s, unsigned int len,
 		while (i < len && s[i] >= '0' && s[i] <= '9' && fscale < 1000) {
 			frac = frac * 10 + (s[i] - '0');
 			fscale *= 10;
+			digits = 1;
 			i++;
 		}
 	}
@@ -3049,6 +3182,12 @@ static int parse_line_height(const char *s, unsigned int len,
 	else if (i < len && s[i] == '%')
 		is_pct = 1;
 	v1000 = whole * 1000 + frac * 1000 / fscale;
+	/* rem is an absolute length (the root font is known by the time
+	 * rules are parsed, as for font-size); em behaves like a multiplier. */
+	if (i + 3 <= len && ci_eq_n(s + i, "rem", 3)) {
+		v1000 = v1000 * root_font_px;
+		is_px = 1;
+	}
 	if (is_px) {
 		int v = v1000 / 1000;
 
@@ -3064,8 +3203,8 @@ static int parse_line_height(const char *s, unsigned int len,
 			v = v1000 / 1000;
 		if (v < 50)
 			v = 50;
-		if (v > 400)
-			v = 400;
+		if (v > 255)            /* stored in an unsigned char */
+			v = 255;
 		*pct = (unsigned char)v;
 	}
 	return 1;
@@ -3145,6 +3284,14 @@ static int parse_display(const char *s, unsigned int len)
 	if (i == 4 && ci_eq_n(s, "flex", 4))
 		return BR_DISPLAY_FLEX;
 	if (i == 11 && ci_eq_n(s, "inline-flex", 11))
+		return BR_DISPLAY_FLEX | BR_DISPLAY_INLINE_FLAG;
+	/* Legacy -webkit-box is the line-clamp idiom; render it as a normal
+	 * block instead of an inline box. */
+	if (i == 11 && ci_eq_n(s, "-webkit-box", 11))
+		return BR_DISPLAY_BLOCK;
+	if (i == 8 && ci_eq_n(s, "-moz-box", 8))
+		return BR_DISPLAY_BLOCK;
+	if (i == 11 && ci_eq_n(s, "-ms-flexbox", 11))
 		return BR_DISPLAY_FLEX;
 	if (i == 5 && ci_eq_n(s, "table", 5))
 		return BR_DISPLAY_BLOCK;
@@ -3207,8 +3354,10 @@ static int bg_number(const char *s, unsigned int len, signed short *val,
 	}
 	if (i < len && s[i] == '.') {
 		i++;
-		while (i < len && s[i] >= '0' && s[i] <= '9')
+		while (i < len && s[i] >= '0' && s[i] <= '9') {
+			digits = 1;
 			i++;
+		}
 	}
 	if (!digits)
 		return 0;
@@ -3477,6 +3626,7 @@ static int parse_fixed_100(const char *s, unsigned int len,
 			if (fd < 2) {
 				frac = frac * 10 + (s[i] - '0');
 				fd++;
+				digits = 1;
 			}
 			i++;
 		}
@@ -4432,34 +4582,32 @@ static void parse_decls(struct br_doc *d, const char *s,
 			unsigned short c;
 			if (parse_color(s + vstart, vend - vstart, &c))
 				decl_add(out, nout, PROP_COLOR, c, important);
-		} else if (str_eq(prop, "fill")) {
-			unsigned short c;
-
-			if (parse_color(s + vstart, vend - vstart, &c)) {
-				decl_add(out, nout, PROP_BG, c, important);
-				decl_add(out, nout, PROP_COLOR, c, important);
-			}
-		} else if (str_eq(prop, "stroke")) {
+		} else if (str_eq(prop, "fill") || str_eq(prop, "stroke")) {
+			/* SVG paint only: an HTML element's fill never paints
+			 * its background (tagesschau sets fill on buttons). */
+			int is_fill = prop[0] == 'f';
 			unsigned short c;
-
-			if (parse_color(s + vstart, vend - vstart, &c)) {
-				decl_add(out, nout, PROP_BORDER_COLOR, c,
-					 important);
-				decl_add(out, nout, PROP_BORDER_W, 1, important);
+			int mode = paint_mode(s + vstart, vend - vstart, &c);
+
+			if (mode) {
+				decl_add(out, nout, is_fill ? PROP_FILL_MODE :
+					 PROP_STROKE_MODE, mode, important);
+				if (mode == BR_PAINT_COLOR)
+					decl_add(out, nout, is_fill ? PROP_FILL :
+						 PROP_STROKE, (short)c,
+						 important);
 			}
 		} else if (str_eq(prop, "stroke-width")) {
-			unsigned int j = vstart;
-			int sw = 0;
+			int sw = svg_len16(s + vstart, vend - vstart);
 
-			while (j < vend && s[j] >= '0' && s[j] <= '9') {
-				sw = sw * 10 + (s[j] - '0');
-				j++;
-			}
-			if (sw < 1)
-				sw = 1;
-			if (sw > 3)
-				sw = 3;
-			decl_add(out, nout, PROP_BORDER_W, sw, important);
+			if (sw >= 0)
+				decl_add(out, nout, PROP_STROKE_W, sw,
+					 important);
+		} else if (str_eq(prop, "fill-rule")) {
+			decl_add(out, nout, PROP_FILL_RULE,
+				 contains_ci_len(s + vstart, vend - vstart,
+						 "evenodd") ? 1 : 0,
+				 important);
 		} else if (str_eq(prop, "text-anchor")) {
 			int a = BR_ALIGN_LEFT;
 
@@ -5209,7 +5357,7 @@ static void parse_decls(struct br_doc *d, const char *s,
 			const char *v = s + vstart;
 			unsigned int vl = vend - vstart;
 			unsigned int pos = 0, ts, te;
-			int widths[4], colors[4], styles[4];
+			int widths[4], colors[4], styles[4], trans[4];
 			int nw = 0, nc = 0, ns = 0;
 			int side = -1;
 			int is_wl = str_eq(prop, "border-width");
@@ -5274,26 +5422,42 @@ static void parse_decls(struct br_doc *d, const char *s,
 				}
 			} else if (is_cl) {
 				unsigned short c;
+				int t;
 
 				while (nc < 4 && next_token(v, vl, &pos,
 							    &ts, &te)) {
-					if (!parse_color(v + ts, te - ts, &c))
+					t = color_is_transparent(v + ts,
+								 te - ts);
+					if (!t && !parse_color(v + ts,
+							       te - ts, &c))
 						break;
-					colors[nc++] = c;
+					colors[nc] = t ? 0 : c;
+					trans[nc] = t;
+					nc++;
 				}
 				if (nc) {
-					if (is_cl == 1)
+					if (is_cl == 1) {
 						expand_four(colors, nc);
+						expand_four(trans, nc);
+					}
 					if (side >= 0 && is_cl == 2) {
 						decl_add(out, nout,
 							 PROP_BC_T + side,
 							 colors[0], important);
+						decl_add(out, nout,
+							 PROP_BT_T + side,
+							 trans[0], important);
 					} else {
-						for (i = 0; i < 4; i++)
+						for (i = 0; i < 4; i++) {
 							decl_add(out, nout,
 								 PROP_BC_T + i,
 								 colors[i],
 								 important);
+							decl_add(out, nout,
+								 PROP_BT_T + i,
+								 trans[i],
+								 important);
+						}
 					}
 				}
 			} else if (is_sl) {
@@ -5348,7 +5512,7 @@ static void parse_decls(struct br_doc *d, const char *s,
 				}
 			} else {
 				int bw = -1, bc = -1, style_none = 0;
-				int bstyle = -1;
+				int bstyle = -1, btrans = 0;
 
 				while (next_token(v, vl, &pos, &ts, &te)) {
 					unsigned short c;
@@ -5371,9 +5535,14 @@ static void parse_decls(struct br_doc *d, const char *s,
 					} else if (parse_len_token(v + ts,
 								   te - ts, &x)) {
 						bw = x;
+					} else if (color_is_transparent(v + ts,
+									te - ts)) {
+						bc = 0;
+						btrans = 1;
 					} else if (parse_color(v + ts,
 							       te - ts, &c)) {
 						bc = c;
+						btrans = 0;
 					}
 				}
 				if (style_none)
@@ -5389,6 +5558,12 @@ static void parse_decls(struct br_doc *d, const char *s,
 						decl_add(out, nout,
 							 PROP_BORDER_COLOR, bc,
 							 important);
+					if (bc >= 0)
+						for (i = 0; i < 4; i++)
+							decl_add(out, nout,
+								 PROP_BT_T + i,
+								 btrans,
+								 important);
 					if (bstyle >= 0)
 						for (i = 0; i < 4; i++)
 							decl_add(out, nout,
@@ -5404,6 +5579,10 @@ static void parse_decls(struct br_doc *d, const char *s,
 						decl_add(out, nout,
 							 PROP_BC_T + side, bc,
 							 important);
+					if (bc >= 0)
+						decl_add(out, nout,
+							 PROP_BT_T + side,
+							 btrans, important);
 					if (bstyle >= 0)
 						decl_add(out, nout,
 							 PROP_BS_T + side,
@@ -5774,6 +5953,70 @@ static unsigned int selector_specificity(const char *s, unsigned int len);
 
 static int css_collect_only;
 
+/* Simple structural pseudo-classes that can be answered from the node tree.
+ * Returns the token length or 0.  Kept in sync with compound_match(). */
+static unsigned int structural_pseudo_len(const char *s, unsigned int i,
+					  unsigned int end)
+{
+	static const struct {
+		const char *name;
+		unsigned char len;
+	} p[] = {
+		{ ":first-child", 12 }, { ":last-child", 11 },
+		{ ":first-of-type", 14 }, { ":last-of-type", 13 },
+		{ ":only-child", 11 }, { ":only-of-type", 13 },
+	};
+	unsigned int k;
+
+	for (k = 0; k < sizeof(p) / sizeof(p[0]); k++) {
+		unsigned int l = p[k].len;
+
+		if (i + l <= end && ci_eq_n(s + i, p[k].name, l) &&
+		    (i + l == end || !is_ident(s[i + l])))
+			return l;
+	}
+	return 0;
+}
+
+static int structural_pseudo_match(struct br_doc *d, unsigned int node,
+				   const char *name, unsigned int len)
+{
+	unsigned int parent = d->nodes[node].parent;
+	unsigned int c;
+	int before = 0, after = 0;
+	int of_type = contains_ci_len(name, len, "of-type");
+	unsigned int tag = d->nodes[node].tag;
+
+	if (!parent)
+		/* The root element is the only element child of the
+		 * document node. */
+		return 1;
+	for (c = d->nodes[parent].first; c && c != node;
+	     c = d->nodes[c].next) {
+		if (d->nodes[c].type != BR_NODE_ELEM)
+			continue;
+		if (of_type && d->nodes[c].tag != tag)
+			continue;
+		before = 1;
+		break;
+	}
+	for (c = d->nodes[node].next; c; c = d->nodes[c].next) {
+		if (d->nodes[c].type != BR_NODE_ELEM)
+			continue;
+		if (of_type && d->nodes[c].tag != tag)
+			continue;
+		after = 1;
+		break;
+	}
+	if (contains_ci_len(name, len, "first"))
+		return !before;
+	if (contains_ci_len(name, len, "last"))
+		return !after;
+	if (contains_ci_len(name, len, "only"))
+		return !before && !after;
+	return 0;
+}
+
 static void parse_css(struct br_doc *d, const char *s, unsigned int len)
 {
 	unsigned int i = 0;
@@ -5897,6 +6140,16 @@ static void parse_css(struct br_doc *d, const char *s, unsigned int len)
 							k = n;
 							continue;
 						}
+						{
+							unsigned int sl =
+								structural_pseudo_len(
+									s, k, e);
+
+							if (sl) {
+								k += sl;
+								continue;
+							}
+						}
 						break;
 					}
 					k++;
@@ -6279,7 +6532,16 @@ static int compound_match(struct br_doc *d, unsigned int node, const char *s,
 				i = e + 1;
 				got = 1;
 			} else {
-				return 0;  /* other pseudo-classes are not modelled */
+				unsigned int sl = structural_pseudo_len(s, i,
+									len);
+
+				if (!sl)
+					return 0;  /* other pseudo-classes are
+						    * not modelled */
+				if (!structural_pseudo_match(d, node, s + i, sl))
+					return 0;
+				i += sl;
+				got = 1;
 			}
 		} else {
 			i++;
@@ -6574,7 +6836,9 @@ static void apply_decl(struct br_style *st, const struct br_decl *dcl)
 		st->overline = (unsigned char)(dcl->val != 0);
 		break;
 	case PROP_DISPLAY:
-		st->display = (unsigned char)dcl->val;
+		st->display = (unsigned char)(dcl->val &
+					      ~BR_DISPLAY_INLINE_FLAG);
+		st->inline_flex = (dcl->val & BR_DISPLAY_INLINE_FLAG) != 0;
 		st->list_item = 0;
 		break;
 	case PROP_VIS_HIDDEN:
@@ -6583,6 +6847,24 @@ static void apply_decl(struct br_style *st, const struct br_decl *dcl)
 	case PROP_OPACITY_HIDDEN:
 		st->opacity_hidden = (unsigned char)(dcl->val != 0);
 		break;
+	case PROP_FILL_MODE:
+		st->fill_mode = (unsigned char)dcl->val;
+		break;
+	case PROP_FILL:
+		st->fill = (unsigned short)dcl->val;
+		break;
+	case PROP_STROKE_MODE:
+		st->stroke_mode = (unsigned char)dcl->val;
+		break;
+	case PROP_STROKE:
+		st->stroke = (unsigned short)dcl->val;
+		break;
+	case PROP_STROKE_W:
+		st->stroke_w = (unsigned short)dcl->val;
+		break;
+	case PROP_FILL_RULE:
+		st->fill_evenodd = (unsigned char)(dcl->val != 0);
+		break;
 	case PROP_OVERFLOW_HIDDEN:
 		st->overflow_hidden = (unsigned char)(dcl->val != 0);
 		break;
@@ -6641,6 +6923,10 @@ static void apply_decl(struct br_style *st, const struct br_decl *dcl)
 	case PROP_BS_R: st->border_s[1] = (unsigned char)dcl->val; break;
 	case PROP_BS_B: st->border_s[2] = (unsigned char)dcl->val; break;
 	case PROP_BS_L: st->border_s[3] = (unsigned char)dcl->val; break;
+	case PROP_BT_T: st->border_t[0] = (unsigned char)dcl->val; break;
+	case PROP_BT_R: st->border_t[1] = (unsigned char)dcl->val; break;
+	case PROP_BT_B: st->border_t[2] = (unsigned char)dcl->val; break;
+	case PROP_BT_L: st->border_t[3] = (unsigned char)dcl->val; break;
 	case PROP_RADIUS_TL:
 	case PROP_RADIUS_TR:
 	case PROP_RADIUS_BR:
@@ -6924,6 +7210,7 @@ void br_style_for(struct br_doc *d, unsigned int node,
 	out->origin_x = out->origin_y = 50;
 	out->origin_x_kind = out->origin_y_kind = 1;
 	out->vis_hidden = out->opacity_hidden = 0;
+	out->inline_flex = 0;
 	out->overflow_hidden = 0;
 	tag = d->nodes[node].tag;
 	out->display = br_tag_is_block(tag) ? BR_DISPLAY_BLOCK :
@@ -7021,6 +7308,12 @@ void br_style_for(struct br_doc *d, unsigned int node,
 	case BR_TAG_VIDEO:
 		out->display = BR_DISPLAY_BLOCK;
 		break;
+	case BR_TAG_SVG:
+		/* The renderer treats an SVG as one replaced box; keeping it
+		 * block-level also gives it a usable intrinsic width inside
+		 * flex items such as a header logo. */
+		out->display = BR_DISPLAY_BLOCK;
+		break;
 	default:
 		break;
 	}
@@ -7054,6 +7347,47 @@ void br_style_for(struct br_doc *d, unsigned int node,
 		if (parse_color(v, s_len(v), &c))
 			out->color = c;
 	}
+	/* SVG presentation attributes; CSS declarations still win below. */
+	if (in_svg(d, node)) {
+		const char *fa = br_find_attr(d, node, "fill");
+		const char *sa = br_find_attr(d, node, "stroke");
+		const char *wa = br_find_attr(d, node, "stroke-width");
+		const char *ra = br_find_attr(d, node, "fill-rule");
+		const char *ca = br_find_attr(d, node, "color");
+		unsigned short c;
+		int mode;
+
+		if (ca && parse_color(ca, s_len(ca), &c))
+			out->color = c;
+		if (fa && (mode = paint_mode(fa, s_len(fa), &c)) != 0) {
+			out->fill_mode = (unsigned char)mode;
+			if (mode == BR_PAINT_COLOR)
+				out->fill = c;
+		}
+		if (sa && (mode = paint_mode(sa, s_len(sa), &c)) != 0) {
+			out->stroke_mode = (unsigned char)mode;
+			if (mode == BR_PAINT_COLOR)
+				out->stroke = c;
+		}
+		if (wa) {
+			int sw = svg_len16(wa, s_len(wa));
+
+			if (sw >= 0)
+				out->stroke_w = (unsigned short)sw;
+		}
+		if (ra)
+			out->fill_evenodd = same_string(ra, "evenodd");
+	}
+
+	/* UA behaviour for a closed <details>: only its <summary> is shown.
+	 * Author CSS below can still override this. */
+	if (tag != BR_TAG_SUMMARY && d->nodes[node].parent) {
+		unsigned int p = d->nodes[node].parent;
+
+		if (p < d->nnode && d->nodes[p].tag == BR_TAG_DETAILS &&
+		    !br_find_attr(d, p, "open"))
+			out->display = BR_DISPLAY_NONE;
+	}
 
 	rule_collect(d, node);
 	for (i = 0; i < nrule_matches; i++) {
@@ -7083,7 +7417,7 @@ void br_style_for(struct br_doc *d, unsigned int node,
 		else if (out->font_unit == 3)
 			px = root_font_px * out->font_raw / 100;
 		else if (out->font_unit == 4)
-			px = parent->font_px * out->font_raw / 100;
+			px = parent->font_px * out->font_raw / 10000;
 		if (px < 8)
 			px = 8;
 		if (px > 72)
@@ -7484,16 +7818,10 @@ int br_parse(struct br_doc *d, const char *html, unsigned int len)
 				i = skip_element(html, len, i, name, n);
 				continue;
 			}
-			if (tag == BR_TAG_DETAILS && !selfclose &&
-			    !has_attr_token(html + attr_start,
-					    attr_end - attr_start, "open")) {
-				/* Closed <details> is collapsed (and this browser has
-				 * no script to open it); skipping the subtree keeps
-				 * mobile mega-menus out of the node arena. */
-				int p = find_ci(html, len, "</details>", 10, i);
-				i = p >= 0 ? (unsigned int)p + 10 : len;
-				continue;
-			}
+			/* A closed <details> is collapsed at style time, not
+			 * parse time: the <summary> (the hamburger button on
+			 * tagesschau and many mobile menus) must stay in the
+			 * DOM. */
 			if (tag == BR_TAG_STYLE) {
 				int p = find_ci(html, len, "</style", 7, i);
 				unsigned int end = p >= 0 ? (unsigned int)p : len;

+ 18 - 1
browser_html.h

@@ -8,7 +8,7 @@
 
 #define BR_MAX_NODES     16384
 #define BR_TEXT_SIZE     524288
-#define BR_ATTR_SIZE     1048576
+#define BR_ATTR_SIZE     4194304
 #define BR_CSS_SIZE      65536
 #define BR_MAX_RULES     8192
 #define BR_RULE_FALLBACK 256
@@ -56,6 +56,8 @@
 #define BR_DISPLAY_FLEX   3
 #define BR_DISPLAY_GRID   4
 #define BR_DISPLAY_INLINE_BLOCK 5
+/* Decl-only bit: display:inline-flex is FLEX plus st->inline_flex. */
+#define BR_DISPLAY_INLINE_FLAG 0x40
 
 /* Text alignment. */
 #define BR_ALIGN_LEFT   0
@@ -155,6 +157,7 @@ struct br_style {
 	unsigned char uppercase;    /* text-transform: uppercase (inherited) */
 	unsigned char border_w[4];  /* top, right, bottom, left */
 	unsigned char border_s[4];  /* BR_BORDER_* per side */
+	unsigned char border_t[4];  /* 1 = fully transparent border side */
 	/* border-radius in pixels, one entry per corner: TL, TR, BR, BL.
 	 * Percentages are stored as 255 so they clamp to the box half. */
 	unsigned char radius[4];
@@ -187,8 +190,20 @@ struct br_style {
 	 * 5 calc (the raw value is the percent, mp_calc_px the px part) */
 	unsigned char mp_unit[8];
 	signed short mp_calc_px[8];
+	/* SVG paint (inherited, like CSS fill/stroke): BR_PAINT_* modes.
+	 * stroke_w is in 1/16 user units; 0 means the default 1. */
+	unsigned char fill_mode, stroke_mode, fill_evenodd;
+	unsigned short fill, stroke;
+	unsigned short stroke_w;
+	unsigned char inline_flex;  /* display:inline-flex (not inherited) */
 };
 
+#define BR_PAINT_UNSET   0    /* fill: black, stroke: none */
+#define BR_PAINT_COLOR   1
+#define BR_PAINT_NONE    2
+#define BR_PAINT_CURRENT 3    /* currentColor -> style color */
+#define BR_PAINT_URL     4    /* url(#id): resolved from the attribute */
+
 struct br_node {
 	unsigned char type;
 	unsigned char tag;
@@ -294,6 +309,8 @@ void br_set_viewport(unsigned int width);
 void br_set_theme(unsigned short text, unsigned short bg,
 		  unsigned short panel, unsigned short link);
 void br_parse_css_text(struct br_doc *d, const char *css, unsigned int len);
+/* CSS colour value (names, #hex, rgb()/rgba()) -> RGB565; 1 on success. */
+int  br_parse_color(const char *s, unsigned int len, unsigned short *out);
 void br_parse_inline_css(struct br_doc *d);
 void br_reset_styles(struct br_doc *d);
 

+ 8 - 6
docs/boot.html

@@ -163,7 +163,7 @@
 		<ol>
 			<li>Probe the <code>INT 15h</code> E820 memory map into <code>0x1000</code>.</li>
 			<li>Enable A20 and read the <code>NBROOT1</code> rootfs header at the boot sector's <code>pack_lba</code> field.</li>
-			<li>Copy the compressed pack directly to <code>0x900000</code> above the 8 MB VGA-shadow reserve, in 16 KB staging chunks at <code>0x3000</code>, using the BIOS block move <code>INT 15h AH=87h</code>.</li>
+			<li>Copy the compressed pack directly to <code>0x900000</code> above the 8 MB VGA-shadow reserve, in 16 KB staging chunks at <code>0x3000</code>, using a temporary flat protected-mode <code>rep movsb</code>. The X201 BIOS's <code>INT 15h AH=87h</code> block move silently copies zeros to this range, so the CPU copy is used instead.</li>
 			<li>Pick the best VBE mode: at least 16 bpp, a linear framebuffer, it must fit the card's VRAM, and the width must be at most 1280 pixels. Mode information is written to <code>0x600</code>; the 12-dword boot-info block goes to <code>0x500</code>.</li>
 			<li>Enter protected mode and jump to <code>kernel_entry</code>.</li>
 		</ol>
@@ -179,11 +179,13 @@
 
 		<div class="note">
 			<p><strong>BIOS state after the move.</strong> The X201's BIOS
-			leaves translation bits behind after <code>AH=87h</code>;
-			<span class="file">paging.c</span> clears CR4.PAE/PGE/LA57/PCIDE/
-			SMEP/SMAP and EFER.LME before it enables paging. The block move
-			keeps the pack safe until <span class="file">ramfs.c</span> takes a
-			private page-allocated copy and releases the boot region.</p>
+			historically left translation bits behind after
+			<code>AH=87h</code>; <span class="file">paging.c</span> still clears
+			CR4.PAE/PGE/LA57/PCIDE/SMEP/SMAP and EFER.LME before it enables
+			paging, because other BIOS protected-mode calls can do the same.
+			The protected-mode copy keeps the pack safe until
+			<span class="file">ramfs.c</span> takes a private page-allocated
+			copy and releases the boot region.</p>
 		</div>
 	</section>
 

+ 1 - 0
docs/development.html

@@ -185,6 +185,7 @@
 					<tr><td><code>make test-libc</code></td><td>Host tests for the ring-3 malloc, stdio/float formatting, math, 64-bit division helpers and setjmp/longjmp.</td></tr>
 					<tr><td><code>make test-mujs</code></td><td>Host smoke test for the vendored MuJS engine: arithmetic, strings, Math, Date, JSON, exceptions and the run limit.</td></tr>
 					<tr><td><code>make test-font</code> / <code>test-font-asan</code></td><td>Host specimen test for the fixed-point TrueType parser/rasterizer and glyph cache, with an AddressSanitizer/UBSan variant.</td></tr>
+					<tr><td><code>make test-svg</code></td><td>Host tests (ASan/UBSan) for the inline-SVG rasterizer: exact rect coverage, antialiased edges, relative commands, nonzero vs even-odd, circle area, curves and arcs, transforms, number grammar and strokes; <code>./svg_test out.ppm</code> writes a specimen.</td></tr>
 					<tr><td><code>make test-touchpad</code></td><td>Host tests for the device-independent contact gesture engine: taps, right-click zones, physical-button latch, two-finger scroll, direction and pointer re-anchoring.</td></tr>
 					<tr><td><code>make test-chat</code></td><td>Host tests (ASan/UBSan) for the chat client's JSON parser, cookie jar and the OIDC login page/reply/config parsers.</td></tr>
 					<tr><td><code>make test-chat-e2e</code></td><td>Boots QEMU with an NE2000 on slirp, starts <code>tools/mock_chat.py</code> and drives <code>chat</code> through QMP: native login, send, live poll, read marker, older paging, browse/join, new DM, saved-session resume and sign-out.  <code>CHAT_E2E=--totp|--consent|--passkey|--wrong</code> runs a login variant.</td></tr>

+ 1 - 1
docs/network.html

@@ -396,7 +396,7 @@
 			<li><strong>curl</strong> — <code>http://</code> or <code>https://</code> GET with DNS, ARP, redirects (up to five hops), chunked decoding, status/headers/body dump and a TLS warning.</li>
 			<li><strong>uhttp</strong> — shared ring-3 HTTP/1.1 client used by curl, the browser and chat: URL parsing, redirects (up to eight hops; 1 KB paths and 1.5 KB header lines, enough for OIDC URLs), chunked decoding, timeouts and TLS.  Requests and bodies of any size are split into pieces the transport accepts (1024-byte TLS records, one peer MSS for plain TCP).  Optional per-request fields set the <code>Accept</code> header, extra header lines and a cookie jar; 1xx/204/304 responses are treated as bodyless so keep-alive does not wait for an idle timeout.</li>
 			<li><strong>uhttp_cookie</strong> — the cookie jar (<span class="file">uhttp_cookie.c</span>, 24 cookies of up to 768 bytes).  Every <code>Set-Cookie</code>, including those on redirect responses, is stored; matching cookies are sent on every request and redirect hop.  Cookies are host-only (<code>Domain</code> is ignored), <code>Path</code> is a prefix match, <code>Secure</code> cookies only go over https, and <code>Max-Age&lt;=0</code> or a 1970 <code>Expires</code> deletes a cookie.  The jar outlives the connection, so a cross-origin redirect that reconnects keeps the session.</li>
-			<li><strong>browser</strong> — runs network fetches in up to four headless <code>curl __serve</code> workers, each with its own request/body/meta files under <code>/share/bf&lt;session&gt;_&lt;slot&gt;*</code>.  The session id comes from the browser pid, so multiple browser windows do not share queue files.  Stylesheet and external-script bodies are downloaded in parallel but parsed/executed in document order; one image starts before the script phase, and the remaining images are prefetched in parallel and decoded as jobs complete, so the UI keeps drawing and scrolling.  Each worker keeps its own TCP/TLS connection; same-origin navigations reuse idle helpers, while a cross-origin navigation stops them first, and helpers also exit after ten idle seconds or when the window loses focus.  A DNS failure is retried once after tearing the helpers down.  The status bar reports the page's total, header and first-byte times.</li>
+			<li><strong>browser</strong> — runs network fetches in up to four headless <code>curl __serve</code> workers, each with its own request/body/meta files under <code>/share/bf&lt;session&gt;_&lt;slot&gt;*</code>.  The session id comes from the browser pid, so multiple browser windows do not share queue files.  Stylesheet and external-script bodies are downloaded in parallel but parsed/executed in document order; one image starts before the script phase, and the remaining images are prefetched in parallel and decoded as jobs complete, so the UI keeps drawing and scrolling.  Each worker keeps its own TCP/TLS connection; idle helpers stay warm across navigations (a cross-origin job just drops the old connection, and only busy helpers are killed), and helpers also exit after ten idle seconds or when the window loses focus.  A DNS failure is retried once after tearing the helpers down.  The helpers' DNS/TLS log lines go to a private tty that the browser drains and discards from every poll loop; a full tty ring blocks its writers, so an undrained one used to hang every helper after about sixteen TLS connections.  The status bar reports the page's total, header and first-byte times.</li>
 			<li><strong>websrv</strong> — the server side, speaking HTTP/1.1 + WebDAV over the TCP listener; see <a href="filesystems.html#webdav">Filesystems → WebDAV</a>.</li>
 		</ul>
 		<p>

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 0 - 0
docs/userland.html


+ 5 - 0
js_browser.c

@@ -2690,6 +2690,7 @@ static const struct computed_prop computed_props[] = {
 	{ "display", "display" }, { "position", "position" },
 	{ "width", "width" }, { "height", "height" },
 	{ "color", "color" }, { "backgroundColor", "background-color" },
+	{ "fill", "fill" }, { "stroke", "stroke" },
 	{ "fontSize", "font-size" }, { "fontWeight", "font-weight" },
 	{ "fontStyle", "font-style" }, { "fontFamily", "font-family" },
 	{ "textAlign", "text-align" }, { "float", "float" },
@@ -2709,6 +2710,10 @@ static const struct computed_prop computed_props[] = {
 	{ "borderRightWidth", "border-right-width" },
 	{ "borderBottomWidth", "border-bottom-width" },
 	{ "borderLeftWidth", "border-left-width" },
+	{ "borderTopColor", "border-top-color" },
+	{ "borderRightColor", "border-right-color" },
+	{ "borderBottomColor", "border-bottom-color" },
+	{ "borderLeftColor", "border-left-color" },
 	{ "backgroundImage", "background-image" },
 	{ "backgroundRepeat", "background-repeat" },
 	{ "backgroundPosition", "background-position" },

+ 924 - 0
svg_raster.c

@@ -0,0 +1,924 @@
+/* svg_raster: SVG geometry flattening + antialiased scanline fill.
+ * See svg_raster.h. */
+
+#include "svg_raster.h"
+#include <stdlib.h>
+#include <math.h>
+
+#define SVGR_PI 3.14159265358979323846
+
+/* ---- numbers and transforms ---- */
+
+static int is_ws(char c)
+{
+	return c == ' ' || c == '\t' || c == '\n' || c == '\r' || c == '\f';
+}
+
+static const char *skip_sep(const char *p)
+{
+	while (is_ws(*p) || *p == ',')
+		p++;
+	return p;
+}
+
+double svgr_num(const char **pp, int *ok)
+{
+	const char *p = skip_sep(*pp);
+	double v = 0, scale = 1;
+	int neg = 0, digits = 0;
+
+	if (*p == '-' || *p == '+') {
+		neg = *p == '-';
+		p++;
+	}
+	while (*p >= '0' && *p <= '9') {
+		v = v * 10 + (*p - '0');
+		p++;
+		digits++;
+	}
+	if (*p == '.') {
+		p++;
+		while (*p >= '0' && *p <= '9') {
+			scale /= 10;
+			v += (*p - '0') * scale;
+			p++;
+			digits++;
+		}
+	}
+	if (!digits) {
+		if (ok)
+			*ok = 0;
+		return 0;
+	}
+	if ((*p == 'e' || *p == 'E') &&
+	    ((p[1] >= '0' && p[1] <= '9') ||
+	     ((p[1] == '-' || p[1] == '+') && p[2] >= '0' && p[2] <= '9'))) {
+		int eneg = 0, e = 0;
+
+		p++;
+		if (*p == '-' || *p == '+') {
+			eneg = *p == '-';
+			p++;
+		}
+		while (*p >= '0' && *p <= '9') {
+			if (e < 300)
+				e = e * 10 + (*p - '0');
+			p++;
+		}
+		while (e-- > 0)
+			v = eneg ? v / 10 : v * 10;
+	}
+	*pp = p;
+	if (ok)
+		*ok = 1;
+	return neg ? -v : v;
+}
+
+void svgr_mat_mul(double out[6], const double a[6], const double b[6])
+{
+	double r[6];
+
+	r[0] = a[0] * b[0] + a[2] * b[1];
+	r[1] = a[1] * b[0] + a[3] * b[1];
+	r[2] = a[0] * b[2] + a[2] * b[3];
+	r[3] = a[1] * b[2] + a[3] * b[3];
+	r[4] = a[0] * b[4] + a[2] * b[5] + a[4];
+	r[5] = a[1] * b[4] + a[3] * b[5] + a[5];
+	out[0] = r[0];
+	out[1] = r[1];
+	out[2] = r[2];
+	out[3] = r[3];
+	out[4] = r[4];
+	out[5] = r[5];
+}
+
+static int name_is(const char *p, const char *name, const char **end)
+{
+	while (*name) {
+		char c = *p;
+
+		if (c >= 'A' && c <= 'Z')
+			c = (char)(c - 'A' + 'a');
+		if (c != *name)
+			return 0;
+		p++;
+		name++;
+	}
+	*end = p;
+	return 1;
+}
+
+void svgr_transform(double m[6], const char *s)
+{
+	const char *p = s;
+
+	while (p && *p) {
+		double v[6], t[6] = { 1, 0, 0, 1, 0, 0 };
+		int n = 0, ok = 1, kind;
+		const char *q;
+
+		p = skip_sep(p);
+		if (!*p)
+			break;
+		if (name_is(p, "matrix", &q))
+			kind = 0;
+		else if (name_is(p, "translate", &q))
+			kind = 1;
+		else if (name_is(p, "scale", &q))
+			kind = 2;
+		else if (name_is(p, "rotate", &q))
+			kind = 3;
+		else if (name_is(p, "skewx", &q))
+			kind = 4;
+		else if (name_is(p, "skewy", &q))
+			kind = 5;
+		else
+			return;
+		p = q;
+		while (is_ws(*p))
+			p++;
+		if (*p != '(')
+			return;
+		p++;
+		while (n < 6) {
+			const char *save = p;
+			double x = svgr_num(&p, &ok);
+
+			if (!ok) {
+				p = save;
+				break;
+			}
+			v[n++] = x;
+		}
+		p = skip_sep(p);
+		if (*p != ')')
+			return;
+		p++;
+		switch (kind) {
+		case 0:
+			if (n != 6)
+				return;
+			t[0] = v[0]; t[1] = v[1]; t[2] = v[2];
+			t[3] = v[3]; t[4] = v[4]; t[5] = v[5];
+			break;
+		case 1:
+			if (n < 1)
+				return;
+			t[4] = v[0];
+			t[5] = n > 1 ? v[1] : 0;
+			break;
+		case 2:
+			if (n < 1)
+				return;
+			t[0] = v[0];
+			t[3] = n > 1 ? v[1] : v[0];
+			break;
+		case 3: {
+			double a, c, sn;
+
+			if (n < 1)
+				return;
+			a = v[0] * SVGR_PI / 180.0;
+			c = cos(a);
+			sn = sin(a);
+			t[0] = c; t[1] = sn; t[2] = -sn; t[3] = c;
+			if (n >= 3) {
+				t[4] = v[1] - c * v[1] + sn * v[2];
+				t[5] = v[2] - sn * v[1] - c * v[2];
+			}
+			break;
+		}
+		case 4:
+			if (n < 1)
+				return;
+			t[2] = tan(v[0] * SVGR_PI / 180.0);
+			break;
+		default:
+			if (n < 1)
+				return;
+			t[1] = tan(v[0] * SVGR_PI / 180.0);
+			break;
+		}
+		svgr_mat_mul(m, m, t);
+	}
+}
+
+/* ---- geometry ---- */
+
+void svgr_init(struct svgr *r, void *buf, unsigned int cap)
+{
+	r->pt = (float *)buf;
+	r->fl = (unsigned char *)buf + cap * 2 * sizeof(float);
+	r->cap = cap;
+	r->n = 0;
+	r->overflow = 0;
+	r->m[0] = 1; r->m[1] = 0; r->m[2] = 0;
+	r->m[3] = 1; r->m[4] = 0; r->m[5] = 0;
+	r->open = 0;
+	r->sp = 0;
+	r->last = 0;
+	r->cx = r->cy = r->sx = r->sy = r->lcx = r->lcy = 0;
+}
+
+void svgr_reset(struct svgr *r, const double m[6])
+{
+	unsigned int i;
+
+	r->n = 0;
+	r->overflow = 0;
+	for (i = 0; i < 6; i++)
+		r->m[i] = m[i];
+	r->open = 0;
+	r->sp = 0;
+	r->last = 0;
+	r->cx = r->cy = r->sx = r->sy = r->lcx = r->lcy = 0;
+}
+
+static void add_dev(struct svgr *r, double x, double y, unsigned char fl)
+{
+	if (r->n >= r->cap) {
+		r->overflow = 1;
+		return;
+	}
+	/* Keep coordinates sane: a wild transform must not overflow the
+	 * float -> int conversions in the scanline code. */
+	if (x < -100000)
+		x = -100000;
+	if (x > 100000)
+		x = 100000;
+	if (y < -100000)
+		y = -100000;
+	if (y > 100000)
+		y = 100000;
+	r->pt[2 * r->n] = (float)x;
+	r->pt[2 * r->n + 1] = (float)y;
+	r->fl[r->n] = fl;
+	r->n++;
+}
+
+static void add_user(struct svgr *r, double x, double y, unsigned char fl)
+{
+	const double *m = r->m;
+
+	add_dev(r, m[0] * x + m[2] * y + m[4], m[1] * x + m[3] * y + m[5], fl);
+}
+
+void svgr_move(struct svgr *r, double x, double y)
+{
+	r->sp = r->n;
+	add_user(r, x, y, SVGR_PT_START);
+	r->open = 1;
+	r->cx = r->sx = x;
+	r->cy = r->sy = y;
+	r->lcx = x;
+	r->lcy = y;
+}
+
+void svgr_line(struct svgr *r, double x, double y)
+{
+	if (!r->open)
+		svgr_move(r, r->cx, r->cy);
+	add_user(r, x, y, 0);
+	r->cx = r->lcx = x;
+	r->cy = r->lcy = y;
+}
+
+/* Device-space length of a control polygon, for the flattening step. */
+static double dev_len(const struct svgr *r, const double *xy, int npts)
+{
+	const double *m = r->m;
+	double len = 0, px = 0, py = 0;
+	int i;
+
+	for (i = 0; i < npts; i++) {
+		double x = m[0] * xy[2 * i] + m[2] * xy[2 * i + 1] + m[4];
+		double y = m[1] * xy[2 * i] + m[3] * xy[2 * i + 1] + m[5];
+
+		if (i)
+			len += sqrt((x - px) * (x - px) + (y - py) * (y - py));
+		px = x;
+		py = y;
+	}
+	return len;
+}
+
+static int seg_count(double len)
+{
+	int n = (int)(len / 3.0) + 1;
+
+	if (n > 64)
+		n = 64;
+	return n;
+}
+
+void svgr_cubic(struct svgr *r, double x1, double y1, double x2, double y2,
+		double x, double y)
+{
+	double xy[8];
+	double x0 = r->cx, y0 = r->cy;
+	int i, n;
+
+	if (!r->open)
+		svgr_move(r, x0, y0);
+	xy[0] = x0; xy[1] = y0; xy[2] = x1; xy[3] = y1;
+	xy[4] = x2; xy[5] = y2; xy[6] = x; xy[7] = y;
+	n = seg_count(dev_len(r, xy, 4));
+	for (i = 1; i <= n; i++) {
+		double t = (double)i / n, u = 1 - t;
+		double a = u * u * u, b = 3 * u * u * t, c = 3 * u * t * t,
+		       d = t * t * t;
+
+		add_user(r, a * x0 + b * x1 + c * x2 + d * x,
+			 a * y0 + b * y1 + c * y2 + d * y, 0);
+	}
+	r->cx = x;
+	r->cy = y;
+	r->lcx = x2;
+	r->lcy = y2;
+}
+
+void svgr_quad(struct svgr *r, double x1, double y1, double x, double y)
+{
+	double xy[6];
+	double x0 = r->cx, y0 = r->cy;
+	int i, n;
+
+	if (!r->open)
+		svgr_move(r, x0, y0);
+	xy[0] = x0; xy[1] = y0; xy[2] = x1; xy[3] = y1; xy[4] = x; xy[5] = y;
+	n = seg_count(dev_len(r, xy, 3));
+	for (i = 1; i <= n; i++) {
+		double t = (double)i / n, u = 1 - t;
+
+		add_user(r, u * u * x0 + 2 * u * t * x1 + t * t * x,
+			 u * u * y0 + 2 * u * t * y1 + t * t * y, 0);
+	}
+	r->cx = x;
+	r->cy = y;
+	r->lcx = x1;
+	r->lcy = y1;
+}
+
+static double vec_angle(double ux, double uy, double vx, double vy)
+{
+	return atan2(ux * vy - uy * vx, ux * vx + uy * vy);
+}
+
+/* Endpoint -> center parameterization (SVG 1.1 implementation notes F.6). */
+void svgr_arc(struct svgr *r, double rx, double ry, double rot, int large,
+	      int sweep, double x, double y)
+{
+	double x0 = r->cx, y0 = r->cy;
+	double phi, cp, sp, dx2, dy2, x1p, y1p, lam, sq, num, den, coef;
+	double cxp, cyp, cx, cy, th1, dth, scale;
+	int i, n;
+
+	if (!r->open)
+		svgr_move(r, x0, y0);
+	if (x0 == x && y0 == y)
+		return;
+	rx = fabs(rx);
+	ry = fabs(ry);
+	if (rx == 0 || ry == 0) {
+		svgr_line(r, x, y);
+		return;
+	}
+	phi = rot * SVGR_PI / 180.0;
+	cp = cos(phi);
+	sp = sin(phi);
+	dx2 = (x0 - x) / 2;
+	dy2 = (y0 - y) / 2;
+	x1p = cp * dx2 + sp * dy2;
+	y1p = -sp * dx2 + cp * dy2;
+	lam = (x1p * x1p) / (rx * rx) + (y1p * y1p) / (ry * ry);
+	if (lam > 1) {
+		sq = sqrt(lam);
+		rx *= sq;
+		ry *= sq;
+	}
+	num = rx * rx * ry * ry - rx * rx * y1p * y1p - ry * ry * x1p * x1p;
+	den = rx * rx * y1p * y1p + ry * ry * x1p * x1p;
+	coef = (den > 0 && num > 0) ? sqrt(num / den) : 0;
+	if (large == sweep)
+		coef = -coef;
+	cxp = coef * rx * y1p / ry;
+	cyp = -coef * ry * x1p / rx;
+	cx = cp * cxp - sp * cyp + (x0 + x) / 2;
+	cy = sp * cxp + cp * cyp + (y0 + y) / 2;
+	th1 = vec_angle(1, 0, (x1p - cxp) / rx, (y1p - cyp) / ry);
+	dth = vec_angle((x1p - cxp) / rx, (y1p - cyp) / ry,
+			(-x1p - cxp) / rx, (-y1p - cyp) / ry);
+	if (!sweep && dth > 0)
+		dth -= 2 * SVGR_PI;
+	else if (sweep && dth < 0)
+		dth += 2 * SVGR_PI;
+	scale = sqrt(fabs(r->m[0] * r->m[3] - r->m[1] * r->m[2]));
+	n = seg_count(fabs(dth) * (rx > ry ? rx : ry) * scale);
+	if (n < 2)
+		n = 2;
+	for (i = 1; i <= n; i++) {
+		double t = th1 + dth * i / n;
+		double ex = rx * cos(t), ey = ry * sin(t);
+
+		if (i == n)
+			add_user(r, x, y, 0);
+		else
+			add_user(r, cp * ex - sp * ey + cx,
+				 sp * ex + cp * ey + cy, 0);
+	}
+	r->cx = r->lcx = x;
+	r->cy = r->lcy = y;
+}
+
+void svgr_close(struct svgr *r)
+{
+	if (r->open && r->sp < r->n)
+		r->fl[r->sp] |= SVGR_PT_CLOSED;
+	r->open = 0;
+	r->cx = r->lcx = r->sx;
+	r->cy = r->lcy = r->sy;
+}
+
+static const char *read_flag(const char *p, int *flag, int *ok)
+{
+	p = skip_sep(p);
+	if (*p == '0' || *p == '1') {
+		*flag = *p - '0';
+		*ok = 1;
+		return p + 1;
+	}
+	*ok = 0;
+	return p;
+}
+
+int svgr_path(struct svgr *r, const char *d)
+{
+	const char *p = d;
+	char cmd = 0;
+
+	r->last = 0;
+	while (p && *p) {
+		double a[7];
+		int fresh = 0, rel, need, i, ok = 1;
+		char c;
+
+		p = skip_sep(p);
+		if (!*p)
+			break;
+		if ((*p >= 'A' && *p <= 'Z') || (*p >= 'a' && *p <= 'z')) {
+			cmd = *p++;
+			fresh = 1;
+		} else if (!cmd) {
+			return -1;
+		}
+		rel = cmd >= 'a' && cmd <= 'z';
+		c = rel ? (char)(cmd - 'a' + 'A') : cmd;
+		if (c == 'Z') {
+			if (!fresh)
+				return -1;
+			svgr_close(r);
+			r->last = 'Z';
+			continue;
+		}
+		switch (c) {
+		case 'M': case 'L': case 'T': need = 2; break;
+		case 'H': case 'V': need = 1; break;
+		case 'C': need = 6; break;
+		case 'S': case 'Q': need = 4; break;
+		case 'A': need = 7; break;
+		default: return -1;
+		}
+		for (i = 0; i < need && ok; i++) {
+			if (c == 'A' && (i == 3 || i == 4)) {
+				int f = 0;
+
+				p = read_flag(p, &f, &ok);
+				a[i] = f;
+			} else {
+				a[i] = svgr_num(&p, &ok);
+			}
+		}
+		if (!ok)
+			return -1;
+		if (rel) {
+			double ox = r->cx, oy = r->cy;
+
+			switch (c) {
+			case 'H': a[0] += ox; break;
+			case 'V': a[0] += oy; break;
+			case 'A': a[5] += ox; a[6] += oy; break;
+			default:
+				for (i = 0; i + 1 < need; i += 2) {
+					a[i] += ox;
+					a[i + 1] += oy;
+				}
+			}
+		}
+		switch (c) {
+		case 'M':
+			if (fresh)
+				svgr_move(r, a[0], a[1]);
+			else
+				svgr_line(r, a[0], a[1]);
+			break;
+		case 'L':
+			svgr_line(r, a[0], a[1]);
+			break;
+		case 'H':
+			svgr_line(r, a[0], r->cy);
+			break;
+		case 'V':
+			svgr_line(r, r->cx, a[0]);
+			break;
+		case 'C':
+			svgr_cubic(r, a[0], a[1], a[2], a[3], a[4], a[5]);
+			break;
+		case 'S': {
+			double x1 = r->cx, y1 = r->cy;
+
+			if (r->last == 'C' || r->last == 'S') {
+				x1 = 2 * r->cx - r->lcx;
+				y1 = 2 * r->cy - r->lcy;
+			}
+			svgr_cubic(r, x1, y1, a[0], a[1], a[2], a[3]);
+			break;
+		}
+		case 'Q':
+			svgr_quad(r, a[0], a[1], a[2], a[3]);
+			break;
+		case 'T': {
+			double x1 = r->cx, y1 = r->cy;
+
+			if (r->last == 'Q' || r->last == 'T') {
+				x1 = 2 * r->cx - r->lcx;
+				y1 = 2 * r->cy - r->lcy;
+			}
+			svgr_quad(r, x1, y1, a[0], a[1]);
+			break;
+		}
+		case 'A':
+			svgr_arc(r, a[0], a[1], a[2], (int)a[3], (int)a[4],
+				 a[5], a[6]);
+			break;
+		}
+		r->last = c;
+		/* Extra coordinate pairs after a moveto are linetos. */
+		if (c == 'M')
+			cmd = rel ? 'l' : 'L';
+	}
+	return 0;
+}
+
+void svgr_rect(struct svgr *r, double x, double y, double w, double h,
+	       double rx, double ry)
+{
+	if (w <= 0 || h <= 0)
+		return;
+	if (rx < 0)
+		rx = 0;
+	if (ry < 0)
+		ry = 0;
+	if (rx > w / 2)
+		rx = w / 2;
+	if (ry > h / 2)
+		ry = h / 2;
+	if (rx == 0 || ry == 0) {
+		svgr_move(r, x, y);
+		svgr_line(r, x + w, y);
+		svgr_line(r, x + w, y + h);
+		svgr_line(r, x, y + h);
+		svgr_close(r);
+		return;
+	}
+	svgr_move(r, x + rx, y);
+	svgr_line(r, x + w - rx, y);
+	svgr_arc(r, rx, ry, 0, 0, 1, x + w, y + ry);
+	svgr_line(r, x + w, y + h - ry);
+	svgr_arc(r, rx, ry, 0, 0, 1, x + w - rx, y + h);
+	svgr_line(r, x + rx, y + h);
+	svgr_arc(r, rx, ry, 0, 0, 1, x, y + h - ry);
+	svgr_line(r, x, y + ry);
+	svgr_arc(r, rx, ry, 0, 0, 1, x + rx, y);
+	svgr_close(r);
+}
+
+void svgr_ellipse(struct svgr *r, double cx, double cy, double rx, double ry)
+{
+	if (rx <= 0 || ry <= 0)
+		return;
+	svgr_move(r, cx + rx, cy);
+	svgr_arc(r, rx, ry, 0, 0, 1, cx - rx, cy);
+	svgr_arc(r, rx, ry, 0, 0, 1, cx + rx, cy);
+	svgr_close(r);
+}
+
+void svgr_points(struct svgr *r, const char *pts, int close)
+{
+	const char *p = pts;
+	int first = 1, ok = 1;
+
+	while (p && *p) {
+		double x = svgr_num(&p, &ok), y;
+
+		if (!ok)
+			break;
+		y = svgr_num(&p, &ok);
+		if (!ok)
+			break;
+		if (first)
+			svgr_move(r, x, y);
+		else
+			svgr_line(r, x, y);
+		first = 0;
+	}
+	if (!first && close)
+		svgr_close(r);
+}
+
+/* ---- scanline fill ---- */
+
+struct edge {
+	float x0, y0, x1, y1;   /* y0 < y1 */
+	float dxdy;
+	int dir;
+	int next;               /* bucket chain */
+};
+
+struct cross {
+	float x;
+	int dir;
+};
+
+static void composite_row(struct svgr_layer *L, int y, const int *cov,
+			  int x0, int x1, unsigned short color,
+			  unsigned int alpha)
+{
+	unsigned int sr = (color >> 11) & 31, sg = (color >> 5) & 63,
+		     sb = color & 31;
+	int x;
+
+	for (x = x0; x <= x1; x++) {
+		int c = cov[x];
+		unsigned int sa, da, oa, idx;
+		unsigned short d;
+
+		if (c <= 0)
+			continue;
+		if (c > 256)
+			c = 256;
+		sa = (unsigned int)c * alpha / 256;
+		if (!sa)
+			continue;
+		idx = (unsigned int)y * (unsigned int)L->w + (unsigned int)x;
+		da = L->a[idx];
+		if (sa >= 255 || !da) {
+			L->px[idx] = color;
+			oa = sa + da * (255 - sa) / 255;
+			L->a[idx] = (unsigned char)(oa > 255 ? 255 : oa);
+			continue;
+		}
+		d = L->px[idx];
+		{
+			unsigned int dw = da * (255 - sa) / 255;
+			unsigned int r5, g6, b5;
+
+			oa = sa + dw;
+			r5 = (sr * sa + ((d >> 11) & 31) * dw) / oa;
+			g6 = (sg * sa + ((d >> 5) & 63) * dw) / oa;
+			b5 = (sb * sa + (d & 31) * dw) / oa;
+			L->px[idx] = (unsigned short)((r5 << 11) | (g6 << 5) |
+						      b5);
+			L->a[idx] = (unsigned char)(oa > 255 ? 255 : oa);
+		}
+	}
+}
+
+static void span_add(int *cov, int w, float xa, float xb, int *minx,
+		     int *maxx)
+{
+	int ia, ib, i;
+
+	if (xa < 0)
+		xa = 0;
+	if (xb > (float)w)
+		xb = (float)w;
+	if (xb <= xa)
+		return;
+	ia = (int)xa;
+	ib = (int)xb;
+	if (ia < *minx)
+		*minx = ia;
+	if ((ib < w ? ib : w - 1) > *maxx)
+		*maxx = ib < w ? ib : w - 1;
+	if (ia == ib) {
+		cov[ia] += (int)(64.0f * (xb - xa) + 0.5f);
+		return;
+	}
+	cov[ia] += (int)(64.0f * ((float)(ia + 1) - xa) + 0.5f);
+	for (i = ia + 1; i < ib; i++)
+		cov[i] += 64;
+	if (ib < w)
+		cov[ib] += (int)(64.0f * (xb - (float)ib) + 0.5f);
+}
+
+void svgr_fill(struct svgr *r, struct svgr_layer *L, unsigned short color,
+	       unsigned int alpha, int evenodd)
+{
+	struct edge *e;
+	struct cross *xs;
+	int *head, *active, *cov;
+	unsigned int i, ne = 0, start = 0;
+	int nact = 0, y, ymin_all = L->h, ymax_all = -1;
+
+	if (r->n < 2 || L->w <= 0 || L->h <= 0 || !alpha)
+		return;
+	e = (struct edge *)malloc((r->n + 1) * sizeof(*e));
+	xs = (struct cross *)malloc((r->n + 1) * sizeof(*xs));
+	head = (int *)malloc((unsigned int)L->h * sizeof(int));
+	active = (int *)malloc((r->n + 1) * sizeof(int));
+	cov = (int *)malloc(((unsigned int)L->w + 1) * sizeof(int));
+	if (!e || !xs || !head || !active || !cov)
+		goto out;
+	for (i = 0; i < (unsigned int)L->h; i++)
+		head[i] = -1;
+	for (i = 0; i <= (unsigned int)L->w; i++)
+		cov[i] = 0;
+
+	/* Edges: consecutive points of each subpath, plus the implicit
+	 * closing edge (fills always close). */
+	for (i = 0; i < r->n; i++) {
+		unsigned int j;
+		float ax, ay, bx, by;
+
+		if (i + 1 < r->n && !(r->fl[i + 1] & SVGR_PT_START))
+			j = i + 1;
+		else
+			j = start;
+		if (i + 1 >= r->n || (r->fl[i + 1] & SVGR_PT_START))
+			start = i + 1;
+		ax = r->pt[2 * i];
+		ay = r->pt[2 * i + 1];
+		bx = r->pt[2 * j];
+		by = r->pt[2 * j + 1];
+		if (ay == by || j == i)
+			continue;
+		if (ay < by) {
+			e[ne].x0 = ax; e[ne].y0 = ay;
+			e[ne].x1 = bx; e[ne].y1 = by;
+			e[ne].dir = 1;
+		} else {
+			e[ne].x0 = bx; e[ne].y0 = by;
+			e[ne].x1 = ax; e[ne].y1 = ay;
+			e[ne].dir = -1;
+		}
+		if (e[ne].y1 <= 0 || e[ne].y0 >= (float)L->h)
+			continue;
+		e[ne].dxdy = (e[ne].x1 - e[ne].x0) / (e[ne].y1 - e[ne].y0);
+		{
+			int row = e[ne].y0 < 0 ? 0 : (int)e[ne].y0;
+			int last = (int)e[ne].y1;
+
+			if (row >= L->h)
+				continue;
+			if (last >= L->h)
+				last = L->h - 1;
+			if (row < ymin_all)
+				ymin_all = row;
+			if (last > ymax_all)
+				ymax_all = last;
+			e[ne].next = head[row];
+			head[row] = (int)ne;
+		}
+		ne++;
+	}
+
+	for (y = ymin_all; y <= ymax_all && y < L->h; y++) {
+		int k, minx = L->w, maxx = -1, a;
+
+		for (a = head[y]; a >= 0; a = e[a].next)
+			active[nact++] = a;
+		/* drop finished edges */
+		for (k = 0; k < nact;) {
+			if (e[active[k]].y1 <= (float)y)
+				active[k] = active[--nact];
+			else
+				k++;
+		}
+		if (!nact)
+			continue;
+		for (k = 0; k < 4; k++) {
+			float sy = (float)y + ((float)k + 0.5f) * 0.25f;
+			int nx = 0, q, wind = 0;
+
+			for (q = 0; q < nact; q++) {
+				struct edge *ed = &e[active[q]];
+				int t;
+				float x;
+
+				if (sy < ed->y0 || sy >= ed->y1)
+					continue;
+				x = ed->x0 + (sy - ed->y0) * ed->dxdy;
+				/* insertion sort by x */
+				t = nx++;
+				while (t > 0 && xs[t - 1].x > x) {
+					xs[t] = xs[t - 1];
+					t--;
+				}
+				xs[t].x = x;
+				xs[t].dir = ed->dir;
+			}
+			for (q = 0; q + 1 < nx; q++) {
+				int inside;
+
+				wind += xs[q].dir;
+				inside = evenodd ? (wind & 1) : wind != 0;
+				if (inside)
+					span_add(cov, L->w, xs[q].x,
+						 xs[q + 1].x, &minx, &maxx);
+			}
+		}
+		if (maxx >= minx) {
+			composite_row(L, y, cov, minx, maxx, color, alpha);
+			for (k = minx; k <= maxx; k++)
+				cov[k] = 0;
+		}
+	}
+out:
+	free(e);
+	free(xs);
+	free(head);
+	free(active);
+	free(cov);
+}
+
+/* Strokes become filled geometry: one quad per segment, all with the same
+ * winding, plus an octagon at each joint, filled with the nonzero rule so
+ * the overlaps union. */
+void svgr_stroke(struct svgr *r, struct svgr_layer *L, double width,
+		 unsigned short color, unsigned int alpha)
+{
+	struct svgr s;
+	unsigned int i, start = 0, cap;
+	double hw = width / 2;
+	void *buf;
+	int joins = width > 1.5;
+
+	if (r->n < 2 || width <= 0)
+		return;
+	if (hw < 0.35)
+		hw = 0.35;
+	cap = r->n * (joins ? 12 : 4) + 16;
+	buf = malloc(cap * (2 * sizeof(float) + 1));
+	if (!buf)
+		return;
+	svgr_init(&s, buf, cap);
+	for (i = 0; i < r->n; i++) {
+		unsigned int j;
+		int closing = 0;
+		double ax, ay, bx, by, dx, dy, len, nx, ny;
+
+		if (r->fl[i] & SVGR_PT_START)
+			start = i;
+		if (i + 1 < r->n && !(r->fl[i + 1] & SVGR_PT_START)) {
+			j = i + 1;
+		} else {
+			if (!(r->fl[start] & SVGR_PT_CLOSED))
+				continue;
+			j = start;
+			closing = 1;
+		}
+		(void)closing;
+		ax = r->pt[2 * i];
+		ay = r->pt[2 * i + 1];
+		bx = r->pt[2 * j];
+		by = r->pt[2 * j + 1];
+		dx = bx - ax;
+		dy = by - ay;
+		len = sqrt(dx * dx + dy * dy);
+		if (len < 1e-6)
+			continue;
+		nx = -dy / len * hw;
+		ny = dx / len * hw;
+		add_dev(&s, ax + nx, ay + ny, SVGR_PT_START);
+		add_dev(&s, bx + nx, by + ny, 0);
+		add_dev(&s, bx - nx, by - ny, 0);
+		add_dev(&s, ax - nx, ay - ny, 0);
+		if (joins) {
+			/* The quad above runs clockwise in device space
+			 * (y down) for every direction; draw the octagon in
+			 * the same sense. */
+			int k;
+			double sgn = (nx * dy - ny * dx) > 0 ? 1 : -1;
+
+			for (k = 0; k < 8; k++) {
+				double ang = sgn * k * SVGR_PI / 4;
+
+				add_dev(&s, bx + hw * cos(ang),
+					by + hw * sin(ang),
+					k ? 0 : SVGR_PT_START);
+			}
+		}
+	}
+	svgr_fill(&s, L, color, alpha, 0);
+	free(buf);
+}

+ 74 - 0
svg_raster.h

@@ -0,0 +1,74 @@
+/* svg_raster: a small freestanding SVG geometry rasterizer.
+ *
+ * Shapes are flattened into device-space polylines (path data with every
+ * SVG command, including curves and elliptical arcs, plus rect/ellipse/
+ * polygon helpers), transformed by an affine matrix, and then filled with
+ * the nonzero or even-odd rule or stroked.  Coverage is antialiased with
+ * four vertical subsamples and exact horizontal span coverage, and is
+ * composited "over" into an RGB565 + 8-bit alpha layer, so a whole <svg>
+ * can be rendered once and blitted on every repaint.
+ *
+ * Nothing here knows about the DOM: browser.c walks the SVG tree, resolves
+ * paint and transforms, and drives this module.  Host test: svg_test.c. */
+#ifndef SVG_RASTER_H
+#define SVG_RASTER_H
+
+struct svgr_layer {
+	unsigned short *px;     /* RGB565, w*h */
+	unsigned char *a;       /* coverage/alpha, w*h */
+	int w, h;
+};
+
+struct svgr {
+	float *pt;              /* x,y pairs in device space */
+	unsigned char *fl;      /* SVGR_PT_* per point */
+	unsigned int n, cap;
+	int overflow;
+	double m[6];            /* user -> device: a b c d e f */
+	/* path state, user space */
+	double cx, cy, sx, sy, lcx, lcy;
+	char last;              /* previous command (upper case) */
+	int open;               /* a subpath is in progress */
+	unsigned int sp;        /* index of the current subpath's first point */
+};
+
+#define SVGR_PT_START  1    /* first point of a subpath */
+#define SVGR_PT_CLOSED 2    /* set on a subpath's first point when closed */
+
+/* buf must hold cap points: cap * (2 * sizeof(float) + 1) bytes. */
+void svgr_init(struct svgr *r, void *buf, unsigned int cap);
+void svgr_reset(struct svgr *r, const double m[6]);
+
+void svgr_move(struct svgr *r, double x, double y);
+void svgr_line(struct svgr *r, double x, double y);
+void svgr_cubic(struct svgr *r, double x1, double y1, double x2, double y2,
+		double x, double y);
+void svgr_quad(struct svgr *r, double x1, double y1, double x, double y);
+void svgr_arc(struct svgr *r, double rx, double ry, double rot, int large,
+	      int sweep, double x, double y);
+void svgr_close(struct svgr *r);
+
+/* Parse SVG path data ("M10 10h5c..."); returns 0, -1 on a parse error
+ * (whatever was valid before the error is kept, as browsers do). */
+int svgr_path(struct svgr *r, const char *d);
+void svgr_rect(struct svgr *r, double x, double y, double w, double h,
+	       double rx, double ry);
+void svgr_ellipse(struct svgr *r, double cx, double cy, double rx, double ry);
+/* "x1,y1 x2,y2 ..."; close != 0 for <polygon>. */
+void svgr_points(struct svgr *r, const char *pts, int close);
+
+/* Composite the current geometry into the layer. alpha 0..255. */
+void svgr_fill(struct svgr *r, struct svgr_layer *L, unsigned short color,
+	       unsigned int alpha, int evenodd);
+/* width is in device pixels. */
+void svgr_stroke(struct svgr *r, struct svgr_layer *L, double width,
+		 unsigned short color, unsigned int alpha);
+
+/* Number/transform helpers shared with the DOM side. */
+double svgr_num(const char **pp, int *ok);
+/* Multiply: out = a * b (apply b first, then a). */
+void svgr_mat_mul(double out[6], const double a[6], const double b[6]);
+/* Parse a transform list and post-multiply it onto m. */
+void svgr_transform(double m[6], const char *s);
+
+#endif

+ 176 - 0
svg_test.c

@@ -0,0 +1,176 @@
+/* Host test for svg_raster.c: coverage of basic shapes, fill rules, path
+ * commands, transforms and strokes.  `./svg_test out.ppm` also writes a
+ * specimen image. */
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "svg_raster.h"
+
+#define W 160
+#define H 120
+
+static unsigned short px[W * H];
+static unsigned char al[W * H];
+static struct svgr_layer L = { px, al, W, H };
+static unsigned char ptbuf[8192 * 9];
+static struct svgr R;
+static int fails;
+
+static void clear(void)
+{
+	memset(px, 0, sizeof(px));
+	memset(al, 0, sizeof(al));
+}
+
+static const double ident[6] = { 1, 0, 0, 1, 0, 0 };
+
+static void check(const char *what, int cond)
+{
+	if (!cond) {
+		printf("FAIL %s\n", what);
+		fails++;
+	}
+}
+
+static unsigned int sum_alpha(void)
+{
+	unsigned int i, s = 0;
+
+	for (i = 0; i < W * H; i++)
+		s += al[i];
+	return s;
+}
+
+static void path_fill(const char *d, const double m[6], int evenodd)
+{
+	svgr_reset(&R, m);
+	svgr_path(&R, d);
+	svgr_fill(&R, &L, 0xFFFF, 255, evenodd);
+}
+
+int main(int argc, char **argv)
+{
+	double m[6];
+	unsigned int s;
+
+	svgr_init(&R, ptbuf, 8192);
+
+	/* axis-aligned rect: exact coverage */
+	clear();
+	path_fill("M10 10 H30 V20 H10 Z", ident, 0);
+	check("rect inside", al[15 * W + 15] == 255);
+	check("rect outside", al[5 * W + 5] == 0 && al[15 * W + 30] == 0);
+	s = sum_alpha();
+	check("rect area", s > 200 * 250 && s <= 200 * 255);
+
+	/* half-pixel edge antialiasing */
+	clear();
+	path_fill("M10.5 10 L20 10 L20 20 L10.5 20 Z", ident, 0);
+	check("half pixel", al[15 * W + 10] > 100 && al[15 * W + 10] < 160);
+
+	/* relative commands, implicit lineto after m, and h/v */
+	clear();
+	path_fill("m10 10 20 0 0 10 h-20z", ident, 0);
+	check("relative", al[15 * W + 15] == 255 && al[15 * W + 31] == 0);
+
+	/* nonzero vs even-odd: two nested squares, same direction */
+	clear();
+	path_fill("M0 0H40V40H0Z M10 10H30V30H10Z", ident, 0);
+	check("nonzero hole filled", al[20 * W + 20] == 255);
+	clear();
+	path_fill("M0 0H40V40H0Z M10 10H30V30H10Z", ident, 1);
+	check("evenodd hole", al[20 * W + 20] == 0 && al[5 * W + 5] == 255);
+
+	/* circle via arcs: area ~ pi r^2 */
+	clear();
+	svgr_reset(&R, ident);
+	svgr_ellipse(&R, 50, 50, 20, 20);
+	svgr_fill(&R, &L, 0xFFFF, 255, 0);
+	s = sum_alpha() / 255;
+	check("circle area", s > 1220 && s < 1290);
+	check("circle centre", al[50 * W + 50] == 255);
+
+	/* cubic + smooth cubic + quadratic + arc in one path */
+	clear();
+	path_fill("M10 60 C10 20 50 20 50 60 S90 100 90 60 Q120 20 150 60 "
+		  "A20 20 0 0 1 110 60 Z", ident, 0);
+	check("curves drew", sum_alpha() > 255 * 500);
+
+	/* transform: scale(2) translate(5,5) of a 10x10 square */
+	clear();
+	memcpy(m, ident, sizeof(m));
+	svgr_transform(m, "scale(2) translate(5 5)");
+	path_fill("M0 0h10v10h-10z", m, 0);
+	check("transform", al[15 * W + 15] == 255 && al[31 * W + 31] == 0 &&
+	      al[9 * W + 9] == 0);
+	memcpy(m, ident, sizeof(m));
+	svgr_transform(m, "rotate(90 20 20)");
+	check("rotate about point", (int)(m[4] + 0.5) == 40 &&
+	      (int)(m[5] + 0.5) == 0);
+
+	/* number grammar: ".5.5", exponents, negative separators */
+	{
+		const char *p = ".5.5-1e1";
+		int ok;
+		double a = svgr_num(&p, &ok), b = svgr_num(&p, &ok),
+		       c = svgr_num(&p, &ok);
+
+		check("numbers", a == 0.5 && b == 0.5 && c == -10 && ok);
+	}
+
+	/* stroke: a 4px horizontal line */
+	clear();
+	svgr_reset(&R, ident);
+	svgr_move(&R, 10, 50);
+	svgr_line(&R, 60, 50);
+	svgr_stroke(&R, &L, 4, 0xFFFF, 255);
+	check("stroke body", al[49 * W + 30] == 255 && al[51 * W + 30] == 255);
+	check("stroke edge", al[45 * W + 30] == 0);
+
+	/* the tagesschau burger (cubic caps, s commands, implicit repeats) */
+	clear();
+	memcpy(m, ident, sizeof(m));
+	m[0] = m[3] = 3;
+	path_fill("M1.5,9.02h32c0.83,0,1.5-0.67,1.5-1.5s-0.67-1.5-1.5-1.5h-32"
+		  "C0.67,6.02,0,6.69,0,7.52S0.67,9.02,1.5,9.02z", m, 0);
+	check("burger bar", al[22 * W + 50] == 255 && al[30 * W + 50] == 0);
+
+	if (argc > 1) {
+		FILE *f = fopen(argv[1], "wb");
+		int i;
+
+		clear();
+		memcpy(m, ident, sizeof(m));
+		m[0] = m[3] = 0.22;
+		m[4] = 2;
+		m[5] = 20;
+		path_fill("M101.9,71.9c0,11-7.6,22.3-19,22.3c-6.5,0-10.7-3.8-10.7-9.7"
+			  "c0-6.3,5.4-13.8,29.8-13.8v1.2H101.9z M114.9,102.9c-0.1-6.1-0.3-13.5-0.3-20.2"
+			  "V54.8c0-14-5.8-23.4-26-23.4c-9.3,0-17.8,2.3-24.5,5.1l1.3,10.9"
+			  "c6.1-3.7,14.5-5.8,21.2-5.8c11.6,0,15.4,5.2,15.4,15v5.2"
+			  "c-26.5,0-42.2,9.7-42.2,25.1c0,11.1,7.9,17.4,19.5,17.4"
+			  "s20.5-6.6,23.8-15.2c-0.4,4-0.4,9-0.4,14h12.2V102.9z", m, 0);
+		svgr_reset(&R, ident);
+		svgr_ellipse(&R, 110, 60, 30, 20);
+		svgr_fill(&R, &L, 0x001F, 200, 0);
+		svgr_reset(&R, ident);
+		svgr_move(&R, 60, 100);
+		svgr_line(&R, 150, 80);
+		svgr_line(&R, 150, 110);
+		svgr_stroke(&R, &L, 3, 0xF800, 255);
+		fprintf(f, "P6\n%d %d\n255\n", W, H);
+		for (i = 0; i < W * H; i++) {
+			unsigned int a = al[i], c = px[i];
+			unsigned int r = ((c >> 11) & 31) * 255 / 31,
+				     g = ((c >> 5) & 63) * 255 / 63,
+				     b = (c & 31) * 255 / 31;
+
+			fputc((int)(r * a / 255), f);
+			fputc((int)(g * a / 255), f);
+			fputc((int)(b * a / 255), f);
+		}
+		fclose(f);
+	}
+	printf("%s (%d failures)\n", fails ? "FAIL" : "ok", fails);
+	return fails ? 1 : 0;
+}

+ 54 - 0
testdata/browser/compat/056-details-summary.html

@@ -0,0 +1,54 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+<meta charset="utf-8">
+<title>056 details summary</title>
+<style>
+  body { background: #ffffff; color: #202020; font-family: sans-serif;
+         margin: 12px; font-size: 18px; }
+  summary { background: #eeeeff; padding: 6px; }
+  #hidden-content { background: #ffdddd; padding: 6px; }
+  #open-content { background: #ddffdd; padding: 6px; }
+  #result { background: #ffc8c8; color: #000000; padding: 8px;
+            margin-top: 12px; }
+</style>
+</head>
+<body>
+<h1>056 &mdash; closed details keeps its summary</h1>
+<p>A closed <code>&lt;details&gt;</code> must keep the summary (the hamburger
+   button on many news sites) in the layout and hide only the rest.</p>
+
+<details id="closed">
+  <summary id="closed-summary">CLOSED SUMMARY</summary>
+  <div id="hidden-content">THIS MUST BE HIDDEN</div>
+</details>
+
+<details id="open" open>
+  <summary id="open-summary">OPEN SUMMARY</summary>
+  <div id="open-content">THIS MUST BE VISIBLE</div>
+</details>
+
+<div id="result">checking...</div>
+<script>
+setTimeout(function () {
+  var s = document.getElementById('closed-summary');
+  var h = document.getElementById('hidden-content');
+  var o = document.getElementById('open-content');
+  var sr = s.getBoundingClientRect();
+  var hd = getComputedStyle(h).display;
+  var od = getComputedStyle(o).display;
+  var ok = sr.width > 50 && sr.height > 0 &&
+           hd === 'none' && od !== 'none';
+
+  var r = document.getElementById('result');
+  if (r) {
+    r.style.background = ok ? '#c8f0c8' : '#ffc8c8';
+    r.textContent = (ok ? 'DETAILS-OK ' : 'DETAILS-FAIL ') +
+                    'summary=' + Math.round(sr.width) + 'x' +
+                    Math.round(sr.height) +
+                    ' hidden=' + hd + ' open=' + od;
+  }
+}, 300);
+</script>
+</body>
+</html>

+ 57 - 0
testdata/browser/compat/057-flex-outer-width.html

@@ -0,0 +1,57 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+<meta charset="utf-8">
+<title>057 flex outer widths</title>
+<style>
+  body { background: #ffffff; color: #202020; font-family: sans-serif;
+         margin: 12px; font-size: 18px; }
+  #row { display: flex; width: 600px; height: 80px; background: #eeeeee; }
+  #a { width: 100px; margin-left: 20px; margin-right: 10px; padding: 5px;
+       background: #ffdddd; }
+  #b { flex-grow: 1; background: #ddffdd; }
+  #nowrap { display: flex; width: 600px; height: 30px; background: #eeeeff;
+            margin-top: 12px; }
+  #nowrap > div { width: 300px; height: 20px; background: #ddddff;
+                  margin-right: 10px; }
+  #result { background: #ffc8c8; color: #000000; padding: 8px;
+            margin-top: 12px; }
+</style>
+</head>
+<body>
+<h1>057 &mdash; flex outer widths and default nowrap</h1>
+<p>Explicit widths are content-box sizes: the flex line must include the
+   item's margins, padding and borders.  A flex row without
+   <code>flex-wrap</code> must stay on one line.</p>
+
+<div id="row"><div id="a">A</div><div id="b">B</div></div>
+<div id="nowrap"><div>1</div><div>2</div><div>3</div></div>
+<div id="result">checking...</div>
+<script>
+setTimeout(function () {
+  function R(id) { return document.getElementById(id).getBoundingClientRect(); }
+  var a = R('a'), b = R('b');
+  var n = document.getElementById('nowrap').children;
+  var n0 = n[0].getBoundingClientRect();
+  var n2 = n[2].getBoundingClientRect();
+  /* In one nowrap row the third 300px item overflows past the first two
+     (x > 500); if it wrapped it would start back at the container's left. */
+  var same_row = n2.left > n0.left + 500;
+
+  var ok = Math.abs(a.width - 110) <= 2 &&
+           Math.abs(b.width - 460) <= 10 &&
+           b.left > a.left + 100 &&
+           same_row;
+
+  var r = document.getElementById('result');
+  if (r) {
+    r.style.background = ok ? '#c8f0c8' : '#ffc8c8';
+    r.textContent = (ok ? 'FLEX-OK ' : 'FLEX-FAIL ') +
+                    'a=' + Math.round(a.left) + ',' + Math.round(a.width) +
+                    ' b=' + Math.round(b.left) + ',' + Math.round(b.width) +
+                    ' nowrap=' + same_row;
+  }
+}, 300);
+</script>
+</body>
+</html>

+ 60 - 0
testdata/browser/compat/058-svg-viewbox-fill.html

@@ -0,0 +1,60 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+<meta charset="utf-8">
+<title>058 SVG viewBox and fill</title>
+<style>
+  body { background: #ffffff; color: #202020; font-family: sans-serif;
+         margin: 12px; font-size: 18px; }
+  .icon { width: 60px; height: 60px; background: #eeeeee; }
+  .wide { width: 150px; height: 30px; background: #eeeeee; margin-top: 8px; }
+  #result { background: #ffc8c8; color: #000000; padding: 8px;
+            margin-top: 12px; }
+</style>
+</head>
+<body>
+<h1>058 &mdash; SVG viewBox and fill</h1>
+<p>Fractional viewBox numbers must not truncate the height, and
+   <code>width="100%"</code>/<code>fill</code> on a child must fill the box.</p>
+
+<div class="icon">
+  <svg id="svg1" viewBox="0 0 340.16 340.16">
+    <rect id="rect1" width="100%" height="100%" fill="#005AB4"></rect>
+  </svg>
+</div>
+<div class="wide">
+  <svg id="svg2" viewBox="0 0 692 140">
+    <rect id="rect2" width="100%" height="100%" fill="#B00020"></rect>
+  </svg>
+</div>
+<p><span id="c1" style="color:#005AB4">blue</span>
+   <span id="c2" style="color:#B00020">red</span></p>
+<div id="result">checking...</div>
+<script>
+setTimeout(function () {
+  function R(id) { return document.getElementById(id).getBoundingClientRect(); }
+  /* SVG paint is `fill`, never the element's background. */
+  function B(id) { return getComputedStyle(document.getElementById(id)).fill; }
+  var s1 = R('svg1'), s2 = R('svg2');
+  var r1 = B('rect1'), r2 = B('rect2');
+  var ok = Math.abs(s1.width - 60) <= 2 &&
+           Math.abs(s1.height - 60) <= 2 &&
+           Math.abs(s2.width - 150) <= 2 &&
+           Math.abs(s2.height - 30) <= 2 &&
+           r1 === getComputedStyle(document.getElementById('c1')).color &&
+           r2 === getComputedStyle(document.getElementById('c2')).color;
+
+  var r = document.getElementById('result');
+  if (r) {
+    r.style.background = ok ? '#c8f0c8' : '#ffc8c8';
+    r.textContent = (ok ? 'SVG-OK ' : 'SVG-FAIL ') +
+                    'icon=' + Math.round(s1.width) + 'x' +
+                    Math.round(s1.height) +
+                    ' wide=' + Math.round(s2.width) + 'x' +
+                    Math.round(s2.height) +
+                    ' fills=' + r1 + '/' + r2;
+  }
+}, 300);
+</script>
+</body>
+</html>

+ 52 - 0
testdata/browser/compat/059-absolute-image.html

@@ -0,0 +1,52 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+<meta charset="utf-8">
+<title>059 absolute image and containing block</title>
+<style>
+  body { background: #ffffff; color: #202020; font-family: sans-serif;
+         margin: 12px; font-size: 18px; }
+  #outer { position: relative; margin-left: 100px; margin-top: 20px;
+           width: 480px; height: 240px; background: #eeeeee;
+           overflow: hidden; }
+  #abs { position: absolute; top: 10px; left: 20px; width: 50px;
+         height: 20px; background: #cc2222; }
+  #poster { position: absolute; top: 0; left: 0; width: 100%;
+            height: auto; }
+  #result { background: #ffc8c8; color: #000000; padding: 8px;
+            margin-top: 12px; }
+</style>
+</head>
+<body>
+<h1>059 &mdash; absolute image and containing block</h1>
+<p>An absolutely positioned poster must use its nearest positioned ancestor
+   as the origin, and its percentage width must fill that block.</p>
+
+<div id="outer">
+  <div id="abs"></div>
+  <img id="poster" src="TILE.PNG" alt="">
+</div>
+<div id="result">checking...</div>
+<script>
+setTimeout(function () {
+  function R(id) { return document.getElementById(id).getBoundingClientRect(); }
+  var o = R('outer'), a = R('abs'), p = R('poster');
+  var ok = Math.abs(a.left - (o.left + 20)) <= 2 &&
+           Math.abs(a.top - (o.top + 10)) <= 2 &&
+           Math.abs(p.left - o.left) <= 2 &&
+           Math.abs(p.top - o.top) <= 2 &&
+           Math.abs(p.width - o.width) <= 2;
+
+  var r = document.getElementById('result');
+  if (r) {
+    r.style.background = ok ? '#c8f0c8' : '#ffc8c8';
+    r.textContent = (ok ? 'ABS-OK ' : 'ABS-FAIL ') +
+                    'outer=' + Math.round(o.left) + ',' + Math.round(o.top) +
+                    ' abs=' + Math.round(a.left) + ',' + Math.round(a.top) +
+                    ' poster=' + Math.round(p.left) + ',' + Math.round(p.top) +
+                    ' ' + Math.round(p.width) + 'x' + Math.round(p.height);
+  }
+}, 300);
+</script>
+</body>
+</html>

+ 38 - 0
testdata/browser/compat/060-webkit-box.html

@@ -0,0 +1,38 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+<meta charset="utf-8">
+<title>060 legacy -webkit-box</title>
+<style>
+  body { background: #ffffff; color: #202020; font-family: sans-serif;
+         margin: 12px; font-size: 18px; }
+  #box { display: -webkit-box; -webkit-box-orient: vertical;
+         -webkit-line-clamp: 2; width: 260px; overflow: hidden;
+         background: #eeeeff; font-size: 24px; }
+  #result { background: #ffc8c8; color: #000000; padding: 8px;
+            margin-top: 12px; }
+</style>
+</head>
+<body>
+<h1>060 &mdash; legacy -webkit-box</h1>
+<p>The line-clamp idiom must render as a normal block so the text keeps its
+   height and remains visible.</p>
+<div id="box"><span>alpha beta</span><span>gamma delta</span></div>
+<div id="result">checking...</div>
+<script>
+setTimeout(function () {
+  var b = document.getElementById('box');
+  var r = b.getBoundingClientRect();
+  var d = getComputedStyle(b).display;
+  var ok = d === 'block' && r.height > 10 && r.width > 200;
+  var out = document.getElementById('result');
+  if (out) {
+    out.style.background = ok ? '#c8f0c8' : '#ffc8c8';
+    out.textContent = (ok ? 'WEBKIT-BOX-OK ' : 'WEBKIT-BOX-FAIL ') +
+                      'display=' + d + ' ' + Math.round(r.width) + 'x' +
+                      Math.round(r.height);
+  }
+}, 300);
+</script>
+</body>
+</html>

+ 66 - 0
testdata/browser/compat/061-inline-width.html

@@ -0,0 +1,66 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+<meta charset="utf-8">
+<title>061 inline width and intrinsic flex size</title>
+<style>
+  body { background: #ffffff; color: #202020; font-family: sans-serif;
+         margin: 12px; font-size: 18px; }
+  #bar { display: flex; align-items: center; width: 620px; height: 60px;
+         overflow: hidden; background: #f4f4f4; }
+  #main { z-index: 2; }
+  #home { margin: 0 3px 0 0; }
+  #homeLink { display: block; padding: 11px 12px; }
+  /* the tagesschau mobile icon-only idiom: a 1px inline label */
+  #label { display: inline; position: relative; width: 1px; height: 1px;
+           overflow: hidden; }
+  #sub { width: 100%; overflow: hidden; background: #e8e8ff; }
+  #sub ul { list-style: none; margin: 0; padding: 0; display: flex; }
+  #sub li { white-space: nowrap; padding: 4px 10px; }
+  #result { background: #ffc8c8; color: #000000; padding: 8px;
+            margin-top: 12px; }
+</style>
+</head>
+<body>
+<h1>061 &mdash; inline width and intrinsic flex size</h1>
+<p>Width/height do not apply to a non-replaced inline box.  A 1px inline
+   label must not shrink its block ancestor, and the flex row must size the
+   left item from the real text width.</p>
+
+<div id="bar">
+  <div id="main">
+    <div id="home">
+      <a id="homeLink" href="#"><span id="label">Startseite</span></a>
+    </div>
+  </div>
+  <div id="sub"><ul><li>Aigner</li><li>Ukraine</li><li>Klima</li></ul></div>
+</div>
+<div id="result">checking...</div>
+<script>
+setTimeout(function () {
+  function R(id) { return document.getElementById(id).getBoundingClientRect(); }
+  var main = R('main'), link = R('homeLink');
+  var bar = R('bar'), sub = R('sub');
+  /* getBoundingClientRect() reports no box for a plain inline span, so
+     check that the label is still inline and that its text gave the link
+     a text-sized box. */
+  var labelInline = getComputedStyle(document.getElementById('label')).display;
+  var ok = main.width > 80 &&
+           link.width > 80 &&
+           labelInline === 'inline' &&
+           Math.abs(bar.height - 60) <= 2 &&
+           sub.left >= main.right - 2;
+
+  var r = document.getElementById('result');
+  if (r) {
+    r.style.background = ok ? '#c8f0c8' : '#ffc8c8';
+    r.textContent = (ok ? 'INLINE-WIDTH-OK ' : 'INLINE-WIDTH-FAIL ') +
+                    'main=' + Math.round(main.width) +
+                    ' link=' + Math.round(link.width) +
+                    ' label=' + labelInline +
+                    ' sub=' + Math.round(sub.left);
+  }
+}, 300);
+</script>
+</body>
+</html>

+ 55 - 0
testdata/browser/compat/062-flex-link-box.html

@@ -0,0 +1,55 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+<meta charset="utf-8">
+<title>062 flex container on an inline element</title>
+<style>
+  body { background: #ffffff; color: #202020; font-family: sans-serif;
+         margin: 12px; font-size: 18px; }
+  /* an <a> is inline by tag but a flex container is block-level */
+  #card { display: flex; width: 520px; background: #eeeeee; }
+  #thumb { width: 90px; height: 90px; background: #cccccc; }
+  #body { flex-grow: 1; }
+  #h { margin: 0 0 4px; font-size: 22px; }
+  #p { margin: 0; }
+  #after { background: #ddffdd; }
+  #result { background: #ffc8c8; color: #000000; padding: 8px;
+            margin-top: 12px; }
+</style>
+</head>
+<body>
+<h1>062 &mdash; flex container on an inline element</h1>
+<p>A link card uses <code>&lt;a style="display:flex"&gt;</code>: the link must
+   get a block-level box with a real height and the next block must start
+   below it.</p>
+
+<a id="card" href="#">
+  <div id="thumb"></div>
+  <div id="body"><h2 id="h">Headline</h2><p id="p">Teaser text body</p></div>
+</a>
+<div id="after">after the card</div>
+<div id="result">checking...</div>
+<script>
+setTimeout(function () {
+  function R(id) { return document.getElementById(id).getBoundingClientRect(); }
+  var card = R('card'), body = R('body'), h = R('h'), after = R('after');
+  var ok = card.height >= 88 &&
+           card.width >= 500 &&
+           body.width > 350 &&
+           h.height > 10 &&
+           after.top >= card.bottom - 1;
+
+  var r = document.getElementById('result');
+  if (r) {
+    r.style.background = ok ? '#c8f0c8' : '#ffc8c8';
+    r.textContent = (ok ? 'FLEX-LINK-OK ' : 'FLEX-LINK-FAIL ') +
+                    'card=' + Math.round(card.width) + 'x' +
+                    Math.round(card.height) +
+                    ' body=' + Math.round(body.width) +
+                    ' h=' + Math.round(h.height) +
+                    ' after=' + Math.round(after.top);
+  }
+}, 300);
+</script>
+</body>
+</html>

+ 51 - 0
testdata/browser/compat/063-css-leading-dot.html

@@ -0,0 +1,51 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+<meta charset="utf-8">
+<title>063 leading-dot CSS lengths</title>
+<style>
+  html { font-size: 62.5%; }
+  body { background: #ffffff; color: #202020; font-family: sans-serif;
+         margin: 12px; font-size: 18px; }
+  #box { margin: 0 .5rem; padding: .3rem .7rem; border-radius: .8rem;
+         width: 10rem; height: 3rem; line-height: .9;
+         background: #eeeeff; }
+  #b { border: .2rem solid #333333; }
+  #result { background: #ffc8c8; color: #000000; padding: 8px;
+            margin-top: 12px; }
+</style>
+</head>
+<body>
+<h1>063 &mdash; leading-dot CSS lengths</h1>
+<p>Minified stylesheets write fractional lengths as <code>.5rem</code> rather
+   than <code>0.5rem</code>; every length parser must accept that.</p>
+<div id="box">box</div>
+<div id="b">bordered</div>
+<div id="result">checking...</div>
+<script>
+setTimeout(function () {
+  var b = document.getElementById('box');
+  var cs = getComputedStyle(b);
+  var r = b.getBoundingClientRect();
+  var bb = document.getElementById('b');
+  var bw = getComputedStyle(bb).borderTopWidth;
+  var ok = cs.marginLeft === '5px' &&
+           cs.paddingLeft === '7px' &&
+           cs.paddingTop === '3px' &&
+           Math.abs(r.width - 114) <= 2 &&
+           Math.abs(r.height - 36) <= 2 &&
+           bw === '2px';
+
+  var out = document.getElementById('result');
+  if (out) {
+    out.style.background = ok ? '#c8f0c8' : '#ffc8c8';
+    out.textContent = (ok ? 'LEADING-DOT-OK ' : 'LEADING-DOT-FAIL ') +
+                      'm=' + cs.marginLeft + ' p=' + cs.paddingTop + '/' +
+                      cs.paddingLeft +
+                      ' ' + Math.round(r.width) + 'x' + Math.round(r.height) +
+                      ' border=' + bw;
+  }
+}, 300);
+</script>
+</body>
+</html>

+ 54 - 0
testdata/browser/compat/064-structural-pseudo.html

@@ -0,0 +1,54 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+<meta charset="utf-8">
+<title>064 structural pseudo-classes</title>
+<style>
+  body { background: #ffffff; color: #202020; font-family: sans-serif;
+         margin: 12px; font-size: 18px; }
+  #list { padding-top: 30px; background: #f4f4f4; }
+  #list > div { margin-top: 20px; padding-top: 10px; height: 30px;
+                background: #dddddd; }
+  #list > div:first-child { margin-top: 0; padding-top: 0; }
+  #list > span { display: block; font-weight: bold; }
+  #list > span:first-of-type { color: #00ff00; }
+  #list > span:last-of-type { color: #0000ff; }
+  #result { background: #ffc8c8; color: #000000; padding: 8px;
+            margin-top: 12px; }
+</style>
+</head>
+<body>
+<h1>064 &mdash; structural pseudo-classes</h1>
+<p>A first child loses its own top margin/padding (the tagesschau first
+   teaser uses this to sit directly under the header), and first/last of
+   type select among siblings of the same tag.</p>
+
+<div id="list">
+  <div id="a">A</div>
+  <div id="b">B</div>
+  <span id="s1">S1</span>
+  <span id="s2">S2</span>
+</div>
+<div id="result">checking...</div>
+<script>
+setTimeout(function () {
+  function R(id) { return document.getElementById(id).getBoundingClientRect(); }
+  function C(id) { return getComputedStyle(document.getElementById(id)); }
+  var list = R('list'), a = R('a'), b = R('b');
+  var ok = Math.abs((a.top - list.top) - 30) <= 2 &&
+           Math.abs((b.top - a.bottom) - 20) <= 2 &&
+           C('s1').color === 'rgb(0, 255, 0)' &&
+           C('s2').color === 'rgb(0, 0, 255)';
+
+  var r = document.getElementById('result');
+  if (r) {
+    r.style.background = ok ? '#c8f0c8' : '#ffc8c8';
+    r.textContent = (ok ? 'PSEUDO-OK ' : 'PSEUDO-FAIL ') +
+                    'a=' + Math.round(a.top - list.top) +
+                    ' gap=' + Math.round(b.top - a.bottom) +
+                    ' colors=' + C('s1').color + '/' + C('s2').color;
+  }
+}, 300);
+</script>
+</body>
+</html>

+ 44 - 0
testdata/browser/compat/065-transparent-border.html

@@ -0,0 +1,44 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+<meta charset="utf-8">
+<title>065 transparent borders</title>
+<style>
+  body { background: #ffffff; color: #202020; font-family: sans-serif;
+         margin: 12px; font-size: 18px; }
+  #pill { display: inline-block; border: 1px solid #0000;
+          border-radius: 12px; background: #e4e4e4; padding: 3px 7px; }
+  #solid { display: inline-block; border: 2px solid #112233;
+           padding: 4px 8px; margin-left: 10px; }
+  #result { background: #ffc8c8; color: #000000; padding: 8px;
+            margin-top: 12px; }
+</style>
+</head>
+<body>
+<h1>065 &mdash; transparent borders</h1>
+<p>A pre-allocated transparent border must keep its width but paint no
+   outline; only a visible colour may reach the screen.</p>
+
+<div id="pill">Aigner</div>
+<div id="solid">solid</div>
+<div id="result">checking...</div>
+<script>
+setTimeout(function () {
+  function C(id) { return getComputedStyle(document.getElementById(id)); }
+  var p = C('pill'), s = C('solid');
+  var ok = p.borderTopWidth === '1px' &&
+           p.borderTopColor === 'rgba(0, 0, 0, 0)' &&
+           s.borderTopWidth === '2px' &&
+           s.borderTopColor !== 'rgba(0, 0, 0, 0)';
+
+  var r = document.getElementById('result');
+  if (r) {
+    r.style.background = ok ? '#c8f0c8' : '#ffc8c8';
+    r.textContent = (ok ? 'TRANSPARENT-BORDER-OK ' : 'TRANSPARENT-BORDER-FAIL ') +
+                    'pill=' + p.borderTopWidth + '/' + p.borderTopColor +
+                    ' solid=' + s.borderTopWidth + '/' + s.borderTopColor;
+  }
+}, 300);
+</script>
+</body>
+</html>

+ 49 - 0
testdata/browser/compat/066-deep-nesting.html

@@ -0,0 +1,49 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+<meta charset="utf-8">
+<title>066 deep nesting</title>
+<style>
+  body { background: #ffffff; color: #202020; font-family: sans-serif;
+         margin: 12px; font-size: 18px; }
+  #n0 { background: #f4f4f4; padding: 2px; }
+  #deep { background: #dddddd; margin: 6px 0; }
+  #result { background: #ffc8c8; color: #000000; padding: 8px;
+            margin-top: 12px; }
+</style>
+</head>
+<body>
+<h1>066 &mdash; deep nesting</h1>
+<p>News pages wrap a teaser in many layout containers.  Text at a realistic
+   nesting depth must still be laid out.</p>
+
+<div id="n0"><div id="n1"><div id="n2"><div id="n3">
+<div id="n4"><div id="n5"><div id="n6"><div id="n7">
+<div id="n8"><div id="n9"><div id="n10"><div id="n11">
+<div id="n12"><div id="n13"><div id="n14"><div id="n15">
+<h2 id="deep">Deep content headline</h2>
+<p>Deep content body text.</p>
+</div></div></div></div></div></div></div></div>
+</div></div></div></div></div></div></div></div>
+
+<div id="result">checking...</div>
+<script>
+setTimeout(function () {
+  var d = document.getElementById('deep');
+  var r = d.getBoundingClientRect();
+  var style = getComputedStyle(d);
+  var ok = r.height > 10 && r.width > 100 &&
+           style.display === 'block';
+
+  var out = document.getElementById('result');
+  if (out) {
+    out.style.background = ok ? '#c8f0c8' : '#ffc8c8';
+    out.textContent = (ok ? 'DEEP-OK ' : 'DEEP-FAIL ') +
+                      Math.round(r.left) + ',' + Math.round(r.top) + ' ' +
+                      Math.round(r.width) + 'x' + Math.round(r.height) +
+                      ' display=' + style.display;
+  }
+}, 300);
+</script>
+</body>
+</html>

+ 64 - 0
testdata/browser/compat/067-svg-geometry.html

@@ -0,0 +1,64 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+<meta charset="utf-8">
+<title>067 SVG geometry and paint</title>
+<style>
+  body { background: #ffffff; color: #202020; font-family: sans-serif;
+         margin: 12px; font-size: 18px; }
+  .pane { float: left; width: 200px; height: 140px; margin-right: 20px;
+          background: #eeeeee; }
+  .icon { fill: currentColor; color: #008000; }
+  #result { clear: both; background: #ffc8c8; color: #000000; padding: 8px;
+            margin-top: 12px; }
+</style>
+</head>
+<body>
+<h1>067 &mdash; SVG geometry and paint</h1>
+<p>Filled curves, arcs, circles, groups with transforms, &lt;use&gt; of a
+   symbol, fill-rule, strokes and gradient paint.  Expected: a blue disc, a
+   red ring with a hole, a green chevron, a black stroked zigzag and a
+   mid-blue square (the average of its gradient stops).</p>
+
+<div class="pane">
+  <svg width="200" height="140" viewBox="0 0 200 140">
+    <defs>
+      <linearGradient id="g1"><stop offset="0" stop-color="#0000ff"/>
+        <stop offset="1" style="stop-color:#000080"/></linearGradient>
+      <symbol id="chev" viewBox="0 0 24 24">
+        <path d="M9 5l7 7-7 7-1.4-1.4L13.2 12 7.6 6.4z"/>
+      </symbol>
+    </defs>
+    <circle id="disc" cx="35" cy="35" r="25" fill="#2040c0"/>
+    <g fill="#c02020" transform="translate(100 35)">
+      <path id="ring" fill-rule="evenodd"
+            d="M0-25a25 25 0 1 1 0 50a25 25 0 1 1 0-50zM0-12a12 12 0 1 0 0 24a12 12 0 1 0 0-24z"/>
+    </g>
+    <use class="icon" href="#chev" x="140" y="10" width="50" height="50"/>
+    <polyline id="zig" points="10,120 40,80 70,120 100,80" fill="none"
+              stroke="#000000" stroke-width="4"/>
+    <rect id="grad" x="130" y="80" width="50" height="50" fill="url(#g1)"/>
+  </svg>
+</div>
+<p><span id="c1" style="color:#2040c0">blue</span>
+   <span id="c2" style="color:#c02020">red</span></p>
+<div id="result">checking...</div>
+<script>
+setTimeout(function () {
+  function F(id, p) { return getComputedStyle(document.getElementById(id))[p]; }
+  var disc = F('disc', 'fill'), ring = F('ring', 'fill'),
+      zig = F('zig', 'fill'), zs = F('zig', 'stroke'),
+      bg = F('disc', 'backgroundColor');
+  var ok = disc === F('c1', 'color') && ring === F('c2', 'color') &&
+           zig === 'none' && zs === 'rgb(0, 0, 0)' &&
+           bg === 'rgba(0, 0, 0, 0)';
+  var r = document.getElementById('result');
+  if (r) {
+    r.style.background = ok ? '#c8f0c8' : '#ffc8c8';
+    r.textContent = (ok ? 'SVGPAINT-OK ' : 'SVGPAINT-FAIL ') + disc + ' ' +
+                    ring + ' ' + zig + '/' + zs + ' bg=' + bg;
+  }
+}, 300);
+</script>
+</body>
+</html>

+ 39 - 0
testdata/browser/compat/068-rem-line-height.html

@@ -0,0 +1,39 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+<meta charset="utf-8">
+<title>068 rem line-height</title>
+<style>
+  html { font-size: 62.5%; }
+  body { background: #ffffff; color: #202020; font-family: sans-serif;
+         margin: 12px; font-size: 18px; }
+  #a { font-size: 1.8rem; line-height: 2.4rem; margin: 0;
+       background: #e0e0ff; }
+  #b { font-size: 18px; line-height: 24px; margin: 8px 0 0 0;
+       background: #e0ffe0; }
+  #result { background: #ffc8c8; color: #000000; padding: 8px;
+            margin-top: 12px; }
+</style>
+</head>
+<body>
+<h1>068 &mdash; rem line-height</h1>
+<p>With a 10px root, <code>line-height: 2.4rem</code> is 24px, not a 2.4&times;
+   multiplier.  Both blocks must be the same height.</p>
+<p id="a">one<br>two<br>three</p>
+<p id="b">one<br>two<br>three</p>
+<div id="result">checking...</div>
+<script>
+setTimeout(function () {
+  function R(id) { return document.getElementById(id).getBoundingClientRect(); }
+  var a = R('a'), b = R('b');
+  var ok = Math.abs(a.height - b.height) <= 2 && a.height < 100;
+  var r = document.getElementById('result');
+  if (r) {
+    r.style.background = ok ? '#c8f0c8' : '#ffc8c8';
+    r.textContent = (ok ? 'REMLH-OK ' : 'REMLH-FAIL ') + 'a=' +
+                    Math.round(a.height) + ' b=' + Math.round(b.height);
+  }
+}, 300);
+</script>
+</body>
+</html>

+ 39 - 0
testdata/browser/compat/069-inline-flex-tail.html

@@ -0,0 +1,39 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+<meta charset="utf-8">
+<title>069 inline-flex tail</title>
+<style>
+  body { background: #ffffff; color: #202020; font-family: sans-serif;
+         margin: 12px; font-size: 18px; }
+  p { width: 600px; line-height: 24px; margin: 0 0 8px 0; }
+  #a { background: #e0e0ff; }
+  #b { background: #e0ffe0; }
+  .more { display: inline-flex; align-items: center; font-weight: bold;
+          color: #0050a0; }
+  #result { background: #ffc8c8; color: #000000; padding: 8px;
+            margin-top: 12px; }
+</style>
+</head>
+<body>
+<h1>069 &mdash; inline-flex tail</h1>
+<p>An <code>inline-flex</code> span with only text continues the line, like
+   an inline-block (news teasers end their text with one).</p>
+<p id="a">Short teaser text. <span class="more">more</span></p>
+<p id="b">Short teaser text. <b style="color:#0050a0">more</b></p>
+<div id="result">checking...</div>
+<script>
+setTimeout(function () {
+  function R(id) { return document.getElementById(id).getBoundingClientRect(); }
+  var a = R('a'), b = R('b');
+  var ok = Math.abs(a.height - b.height) <= 2 && a.height < 40;
+  var r = document.getElementById('result');
+  if (r) {
+    r.style.background = ok ? '#c8f0c8' : '#ffc8c8';
+    r.textContent = (ok ? 'INLFLEX-OK ' : 'INLFLEX-FAIL ') + 'a=' +
+                    Math.round(a.height) + ' b=' + Math.round(b.height);
+  }
+}, 300);
+</script>
+</body>
+</html>

+ 70 - 0
testdata/browser/compat/070-many-absolute.html

@@ -0,0 +1,70 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+<meta charset="utf-8">
+<title>070 many absolute boxes</title>
+<style>
+  body { background: #ffffff; color: #202020; font-family: sans-serif;
+         margin: 12px; font-size: 18px; }
+  .box { position: relative; float: left; width: 60px; height: 0;
+         padding-top: 40px; margin: 0 8px 8px 0; background: #eeeeee; }
+  .abs { position: absolute; top: 0; left: 0; width: 100%; height: 40px;
+         background: #2060c0; }
+  #result { clear: both; background: #ffc8c8; color: #000000; padding: 8px;
+            margin-top: 12px; }
+</style>
+</head>
+<body>
+<h1>070 &mdash; many absolute boxes</h1>
+<p>Thirty padding-top aspect boxes, each covered by an absolutely positioned
+   child at <code>top: 0</code>.  Every box must be solid blue (news front
+   pages have one such poster per teaser).</p>
+<div class="box"><div class="abs" id="a0"></div></div>
+<div class="box"><div class="abs" id="a1"></div></div>
+<div class="box"><div class="abs" id="a2"></div></div>
+<div class="box"><div class="abs" id="a3"></div></div>
+<div class="box"><div class="abs" id="a4"></div></div>
+<div class="box"><div class="abs" id="a5"></div></div>
+<div class="box"><div class="abs" id="a6"></div></div>
+<div class="box"><div class="abs" id="a7"></div></div>
+<div class="box"><div class="abs" id="a8"></div></div>
+<div class="box"><div class="abs" id="a9"></div></div>
+<div class="box"><div class="abs" id="a10"></div></div>
+<div class="box"><div class="abs" id="a11"></div></div>
+<div class="box"><div class="abs" id="a12"></div></div>
+<div class="box"><div class="abs" id="a13"></div></div>
+<div class="box"><div class="abs" id="a14"></div></div>
+<div class="box"><div class="abs" id="a15"></div></div>
+<div class="box"><div class="abs" id="a16"></div></div>
+<div class="box"><div class="abs" id="a17"></div></div>
+<div class="box"><div class="abs" id="a18"></div></div>
+<div class="box"><div class="abs" id="a19"></div></div>
+<div class="box"><div class="abs" id="a20"></div></div>
+<div class="box"><div class="abs" id="a21"></div></div>
+<div class="box"><div class="abs" id="a22"></div></div>
+<div class="box"><div class="abs" id="a23"></div></div>
+<div class="box"><div class="abs" id="a24"></div></div>
+<div class="box"><div class="abs" id="a25"></div></div>
+<div class="box"><div class="abs" id="a26"></div></div>
+<div class="box"><div class="abs" id="a27"></div></div>
+<div class="box"><div class="abs" id="a28"></div></div>
+<div class="box"><div class="abs" id="a29"></div></div>
+<div id="result">checking...</div>
+<script>
+setTimeout(function () {
+  function R(el) { return el.getBoundingClientRect(); }
+  var bad = 0, i;
+  for (i = 0; i < 30; i++) {
+    var a = document.getElementById('a' + i);
+    if (Math.abs(R(a).top - R(a.parentNode).top) > 2)
+      bad++;
+  }
+  var r = document.getElementById('result');
+  if (r) {
+    r.style.background = bad ? '#ffc8c8' : '#c8f0c8';
+    r.textContent = (bad ? 'ABS30-FAIL ' : 'ABS30-OK ') + bad + ' misplaced';
+  }
+}, 300);
+</script>
+</body>
+</html>

+ 1 - 1
testdata/browser/compat/README

@@ -17,7 +17,7 @@ Serve this directory from the host and open it on the board:
   browser http://<host>:8000/            # board
   browser http://10.0.2.2:8000/         # QEMU with -netdev user
 
-Status: 010-055 and 030a pass.  036a needs the POST echo server:
+Status: 010-070 and 030a pass.  036a needs the POST echo server:
 
   python3 testdata/browser/compat/post_server.py
   browser /floppy1/036a.htm      # action is http://10.0.2.2:8765/echo

+ 15 - 0
testdata/browser/compat/index.html

@@ -78,6 +78,21 @@ a { color: #0645ad; }
 <tr><td>053</td><td><a href="053-background-shorthand.html">background shorthand</a></td><td>position before the slash and size after it</td><td class="pass">PASS</td></tr>
 <tr><td>054</td><td><a href="054-event-constructors.html">event constructors</a></td><td>CustomEvent detail/bubbles, MouseEvent fields, preventDefault</td><td class="pass">PASS</td></tr>
 <tr><td>055</td><td><a href="055-inline-events.html">inline events</a></td><td>onclick with this, bubbling, return false and entity-decoded attributes</td><td class="pass">PASS</td></tr>
+<tr><td>056</td><td><a href="056-details-summary.html">details summary</a></td><td>a closed details keeps its summary and hides the rest</td><td class="pass">PASS</td></tr>
+<tr><td>057</td><td><a href="057-flex-outer-width.html">flex outer widths</a></td><td>margins/padding in flex item widths, default nowrap</td><td class="pass">PASS</td></tr>
+<tr><td>058</td><td><a href="058-svg-viewbox-fill.html">SVG viewBox and fill</a></td><td>fractional viewBox, percentage rect and fill attribute</td><td class="pass">PASS</td></tr>
+<tr><td>059</td><td><a href="059-absolute-image.html">absolute image</a></td><td>poster fills its positioned ancestor, percentage width</td><td class="pass">PASS</td></tr>
+<tr><td>060</td><td><a href="060-webkit-box.html">legacy -webkit-box</a></td><td>line-clamp display renders as a block</td><td class="pass">PASS</td></tr>
+<tr><td>061</td><td><a href="061-inline-width.html">inline width</a></td><td>width does not apply to inline boxes; intrinsic flex size</td><td class="pass">PASS</td></tr>
+<tr><td>062</td><td><a href="062-flex-link-box.html">flex link box</a></td><td>display:flex on an inline element gets a block-level box</td><td class="pass">PASS</td></tr>
+<tr><td>063</td><td><a href="063-css-leading-dot.html">leading-dot CSS lengths</a></td><td>minified .5rem margins, padding, radius and borders</td><td class="pass">PASS</td></tr>
+<tr><td>064</td><td><a href="064-structural-pseudo.html">structural pseudo-classes</a></td><td>first-child drops margins/padding; first/last-of-type</td><td class="pass">PASS</td></tr>
+<tr><td>065</td><td><a href="065-transparent-border.html">transparent borders</a></td><td>a transparent border keeps its width but paints nothing</td><td class="pass">PASS</td></tr>
+<tr><td>066</td><td><a href="066-deep-nesting.html">deep nesting</a></td><td>text 16 containers deep is still laid out</td><td class="pass">PASS</td></tr>
+<tr><td>067</td><td><a href="067-svg-geometry.html">SVG geometry and paint</a></td><td>curves, arcs, circle, g transform, use/symbol, fill-rule, stroke, gradient paint</td><td class="pass">PASS</td></tr>
+<tr><td>068</td><td><a href="068-rem-line-height.html">rem line-height</a></td><td>line-height in rem is a length, not a multiplier</td><td class="pass">PASS</td></tr>
+<tr><td>069</td><td><a href="069-inline-flex-tail.html">inline-flex tail</a></td><td>inline-flex around text stays in the line</td><td class="pass">PASS</td></tr>
+<tr><td>070</td><td><a href="070-many-absolute.html">many absolute boxes</a></td><td>more than 16 absolute boxes keep their containing block</td><td class="pass">PASS</td></tr>
 </table>
 </body>
 </html>

+ 7 - 0
tty.c

@@ -115,8 +115,15 @@ int tty_write(int id, const char *buf, unsigned int len)
 		unsigned int next = (t->head + 1) % TTY_BUF;
 
 		if (next == t->tail) {
+			struct process *cur = current_proc();
+
 			if (!process_is_alive(t->owner))
 				return -1;
+			/* The owner is the only reader: sleeping on its own
+			 * full ring can never make progress.  Drop instead
+			 * (the browser rebinds itself to its helpers' tty). */
+			if (cur && cur->pid == t->owner)
+				return -1;
 			process_sleep_ms(1);
 			continue;
 		}

+ 6 - 13
ucmd_wm.c

@@ -321,22 +321,18 @@ static unsigned int pct_text(char *b, int pct)
 	return n;
 }
 
-static unsigned int batt_color(int pct, int charging, int ac)
+static unsigned int batt_color(int pct)
 {
 	if (pct <= 10)
 		return 0xFF5050u;
-	if (pct <= 20)
-		return 0xFFD250u;
-	if (charging || ac > 0)
-		return 0x55FF55u;
-	return 0x55D2FFu;
+	return 0x55FF55u;
 }
 
 /* Battery pictogram: outline, terminal and a fill proportional to the
  * percentage.  A critical charge turns the outline red as well. */
 static void bar_icon_battery(int x, int y, int pct, unsigned int c)
 {
-	unsigned int frame = pct <= 10 ? c : 0xD2D2D2u;
+	unsigned int frame = c;
 	unsigned int fill = (unsigned int)((14 * pct + 99) / 100);
 
 	usurf_fill(&screen, x + 1, y + 2, 18, 2, frame);
@@ -347,7 +343,7 @@ static void bar_icon_battery(int x, int y, int pct, unsigned int c)
 	if (fill > 14)
 		fill = 14;
 	if (fill)
-		usurf_fill(&screen, x + 3, y + 4, fill, 8, c);
+		usurf_fill(&screen, x + 3, y + 4, fill, 10, c);
 }
 
 /* AC plug pictogram: two prongs and the body, kept compact in height. */
@@ -384,8 +380,7 @@ static void bar_draw_tooltip(void)
 	lw = usurf_text_width(&screen, lb);
 	tx = bar_pwr_tip_x + ((int)bar_pwr_tip_w - (int)lw) / 2;
 	usurf_text(&screen, tx, bar_pwr_tip_y + 3, lb,
-		   batt_color(bar_batt_pct, bar_batt_charging, bar_ac_online),
-		   0, 0, fbw, fbh);
+		   batt_color(bar_batt_pct), 0, 0, fbw, fbh);
 }
 
 /* Publish the geometry computed by draw_bar() and redraw the tooltip. */
@@ -490,9 +485,7 @@ static void draw_bar(void)
 				else
 					bar_icon_battery(px, BAR_PWR_Y,
 							 bar_batt_pct,
-							 batt_color(bar_batt_pct,
-								    bar_batt_charging,
-								    bar_ac_online));
+							 batt_color(bar_batt_pct));
 				bar_pwr_x = px;
 				right = px - 8;
 				if (bar_pwr_hot && bar_batt_pct >= 0) {

+ 20 - 7
uhttp.c

@@ -574,7 +574,8 @@ static unsigned int req_app_dec(char *buf, unsigned int pos, unsigned int cap,
 
 /* Read the status line and headers of the current response.  Returns 0 and
  * sets redirect/location when the response is a redirect with a target. */
-static int read_response_head(struct uhttp *h, char *location, int *have_loc)
+static int read_response_head(struct uhttp *h, char *location, int *have_loc,
+			      unsigned int timeout_ms)
 {
 	char line[UHTTP_LINE_MAX];
 	unsigned int status = 0;
@@ -597,7 +598,7 @@ static int read_response_head(struct uhttp *h, char *location, int *have_loc)
 	*have_loc = 0;
 	location[0] = '\0';
 
-	rv = reader_readline(h, line, sizeof(line), UHTTP_IDLE_TIMEOUT_MS);
+	rv = reader_readline(h, line, sizeof(line), timeout_ms);
 	if (rv < 0)
 		return (h->error == UHTTP_ERR_RESET) ? UHTTP_ERR_RESET :
 						       UHTTP_ERR_TIMEOUT;
@@ -605,9 +606,17 @@ static int read_response_head(struct uhttp *h, char *location, int *have_loc)
 	h->resp.status = (int)status;
 	if (h->hooks && h->hooks->status)
 		h->hooks->status(h->hooks->ctx, (int)status, line);
+	/* HTTP/1.0 has no persistent connections unless the response
+	 * explicitly opts in.  Ignoring this kept a half-closed socket for
+	 * the next request, which then waited for a response that could not
+	 * arrive: the next batch of images appeared to hang. */
+	if (line[0] == 'H' && line[1] == 'T' && line[2] == 'T' &&
+	    line[3] == 'P' && line[4] == '/' && line[5] == '1' &&
+	    line[6] == '.' && line[7] == '0')
+		h->peer_close = 1;
 
 	for (;;) {
-		rv = reader_readline(h, line, sizeof(line), UHTTP_IDLE_TIMEOUT_MS);
+		rv = reader_readline(h, line, sizeof(line), timeout_ms);
 		if (rv < 0)
 			return (h->error == UHTTP_ERR_RESET) ? UHTTP_ERR_RESET :
 							       UHTTP_ERR_TIMEOUT;
@@ -633,9 +642,11 @@ static int read_response_head(struct uhttp *h, char *location, int *have_loc)
 		} else if (hdr_match(line, "location")) {
 			copy_after_colon(line, location, UHTTP_LOC_MAX);
 			*have_loc = location[0] != '\0';
-		} else if (hdr_match(line, "connection") &&
-			   contains_ci(line, "close")) {
-			h->peer_close = 1;
+		} else if (hdr_match(line, "connection")) {
+			if (contains_ci(line, "close"))
+				h->peer_close = 1;
+			else if (contains_ci(line, "keep-alive"))
+				h->peer_close = 0;
 		} else if (h->jar && hdr_match(line, "set-cookie")) {
 			char *v = line + 11;    /* past "set-cookie:" */
 
@@ -808,7 +819,9 @@ int uhttp_open(struct uhttp *h, const char *url, unsigned int flags,
 			rv = send_request(h, flags);
 			if (rv == 0)
 				rv = read_response_head(h, location,
-							&have_loc);
+							&have_loc,
+							used_reuse ? 3000 :
+							UHTTP_IDLE_TIMEOUT_MS);
 			if (rv == 0)
 				break;
 			if (!used_reuse)

+ 4 - 1
uhttp.h

@@ -22,7 +22,10 @@
 #define UHTTP_REQ_MAX        4096   /* request line + headers */
 #define UHTTP_MAX_REDIRECTS  8
 #define UHTTP_IDLE_TIMEOUT_MS  10000
-#define UHTTP_TOTAL_TIMEOUT_MS 60000
+/* Backstop only: the idle timeout above catches a stalled peer, so slow but
+ * steady links (a 1.5 MB news page on emulated hardware, a big image over a
+ * poor connection) must not be cut off after a minute. */
+#define UHTTP_TOTAL_TIMEOUT_MS 300000
 
 /* uhttp_open flags. */
 #define UHTTP_GZIP  1   /* send Accept-Encoding: gzip (caller decodes) */

+ 48 - 48
vesa_stage.S

@@ -4,8 +4,11 @@
  * Called by the boot sector in real mode (CS=0, IP=0x7E00).
  * Probes the E820 map, loads the compressed command-pack rootfs in 16 KB
  * chunks through the 0x3000 staging buffer and copies each chunk straight
- * above the 8 MB VGA-shadow reserve (PACK_HIGH_ADDR) with the BIOS block
- * move (INT 15h AH=87h), walks the VBE mode list and picks the best mode (highest resolution,
+ * above the 8 MB VGA-shadow reserve (PACK_HIGH_ADDR) with a temporary
+ * flat protected-mode rep movsb.  The X201 BIOS silently turns the
+ * equivalent INT 15h AH=87h block move into zeros for this range, which
+ * left the kernel with an empty pack.  The stage then walks the VBE mode
+ * list and picks the best mode (highest resolution,
  * >= 16 bpp, LFB, fits in VRAM), writes the mode info to 0x600 and the boot
  * info to 0x500, then enables A20, enters protected mode and jumps to
  * kernel_entry.  Because the pack never occupies the low gap behind the
@@ -194,8 +197,7 @@ load_loop:
 	movl  $PACK_HIGH_ADDR, %eax
 	addl  pack_off, %eax
 	movl  %eax, copy_dst
-	call  bios_copy
-	jc    pack_fail
+	call  pm_copy
 	movl  chunk_sectors, %eax
 	shll  $9, %eax
 	addl  %eax, pack_off
@@ -470,31 +472,48 @@ print_str:
 	popw  %ax
 	ret
 
-/* ---- Copy a chunk to high memory with INT 15h AH=87h ------------------
- * in: copy_dst (24-bit), copy_len; source is 0x3000.
- * Copies in 16-bit words; returns with CF set on failure.  The kernel's
- * paging_prepare_cpu() sanitizes the CR4/EFER state this BIOS call can
- * leave behind on the X201. */
-bios_copy:
-	movl  copy_dst, %eax
-	movw  %ax, bios_gdt + 0x1A      /* dest base 15:0 */
-	shrl  $16, %eax
-	movb  %al, bios_gdt + 0x1C      /* dest base 23:16 */
+/* ---- Flat protected-mode copy -----------------------------------------
+ * The X201 BIOS silently turns INT 15h AH=87h into zeros for this range.
+ * Enter temporary protected mode, copy with a flat rep movsb, then return
+ * to real mode.  SS/ESP are left untouched; only DS/ES are widened. */
+pm_copy:
+	cli
+	lgdt  stage2_gdtr
+	movl  %cr0, %eax
+	orl   $1, %eax
+	movl  %eax, %cr0
+	.byte 0x66, 0xea
+	.long pm_copy32
+	.word 0x08
+.code32
+pm_copy32:
+	movw  $0x10, %ax
+	movw  %ax, %ds
+	movw  %ax, %es
+	cld
+	movl  $0x3000, %esi
+	movl  copy_dst, %edi
 	movl  copy_len, %ecx
-	addl  $1, %ecx                  /* round up for an odd final byte */
-	shrl  $1, %ecx                  /* AH=87h counts words */
-	jz    bios_copy_done
+	rep movsb
+	/* Leave through a 16-bit protected-mode code segment before
+	 * clearing PE, then return to real mode. */
+	.byte 0xea
+	.long pm_copy16pm
+	.word 0x18
+.code16
+pm_copy16pm:
+	movl  %cr0, %eax
+	andl  $0xfffffffe, %eax
+	movl  %eax, %cr0
+	.byte 0xea
+	.word pm_copy16
+	.word 0x0000
+pm_copy16:
 	xorw  %ax, %ax
+	movw  %ax, %ds
 	movw  %ax, %es
-	movw  $bios_gdt, %si
-	movw  $0x8700, %ax
-	int   $0x15
-	jc    bios_copy_fail
-bios_copy_done:
-	clc
-	ret
-bios_copy_fail:
-	stc
+	movw  %ax, %fs
+	movw  %ax, %gs
 	ret
 
 /* ---- Hex print (EAX, 8 digits) ----------------------------------------- */
@@ -583,33 +602,14 @@ stage2_gdt:
 	.byte 0x00, 0x9a, 0xcf, 0x00
 	.word 0xffff, 0x0000
 	.byte 0x00, 0x92, 0xcf, 0x00
+	/* 16-bit code: base 0, 4 GB limit, D=0 */
+	.word 0xffff, 0x0000
+	.byte 0x00, 0x9a, 0x8f, 0x00
 stage2_gdt_end:
 stage2_gdtr:
 	.word stage2_gdt_end - stage2_gdt - 1
 	.long stage2_gdt
 
-/* ---- INT 15h AH=87h descriptor table (48 bytes) -----------------------
- * 16 zero bytes, source descriptor at 0x10 (0x3000, 64 KB), destination
- * at 0x18 (patched per chunk), 16 zero bytes. */
-.align 16
-bios_gdt:
-	.quad 0
-	.quad 0
-	/* source: limit 0xFFFF, base 0x3000, access 0x93, 16-bit data */
-	.word 0xFFFF
-	.word 0x3000
-	.byte 0x00
-	.byte 0x93
-	.word 0x0000
-	/* destination: limit 0xFFFF, base patched, access 0x93 */
-	.word 0xFFFF
-	.word 0x0000
-	.byte 0x00
-	.byte 0x93
-	.word 0x0000
-	.quad 0
-	.quad 0
-
 /* ---- Stage variables --------------------------------------------------- */
 .align 4
 stage_drive:    .byte 0

Daži faili netika attēloti, jo izmaiņu fails ir pārāk liels