Просмотр исходного кода

Fix tagesschau layout and large-page loading

Let the shared HTTP client survive slow but steady transfers (the idle timeout still catches a stalled peer), and grow the browser attribute arena to 4 MB so the 1.5 MB tagesschau page leaves room for its external CSS selectors.  Treat a flex container on an inline tag (link cards) as a block box, ignore width/height on non-replaced inline boxes, accept minified leading-dot lengths and fractional percent font sizes, support structural pseudo-classes, keep fully transparent borders invisible, and raise the layout recursion budget (a DOM level costs about two units) so deeply nested teaser text is no longer skipped.  Adds ladder 061-066.
Johannes Zellner 1 неделя назад
Родитель
Сommit
b2bdb6517e

+ 43 - 24
browser.c

@@ -815,7 +815,8 @@ static void css_rgb(unsigned short c, char *buf, int cap)
 	snprintf(buf, cap, "rgb(%d, %d, %d)", r, g, b);
 }
 
-static void css_mp_value(char *buf, int cap, int raw, int unit, int px)
+static void css_mp_value(char *buf, int cap, int raw, int unit, int px,
+			 int font_px)
 {
 	if (unit == 4) {
 		snprintf(buf, cap, "auto");
@@ -824,9 +825,11 @@ static void css_mp_value(char *buf, int cap, int raw, int unit, int px)
 	} else if (unit == 1) {
 		snprintf(buf, cap, "%d.%02d%%", raw / 100, raw % 100);
 	} else if (unit == 2) {
-		snprintf(buf, cap, "%d.%02dem", raw / 100, raw % 100);
+		/* Chrome's getComputedStyle() reports used pixel values. */
+		snprintf(buf, cap, "%dpx", font_px * raw / 100);
 	} else if (unit == 3) {
-		snprintf(buf, cap, "%d.%02drem", raw / 100, raw % 100);
+		snprintf(buf, cap, "%dpx",
+			 (int)br_root_font_px() * raw / 100);
 	} else {
 		snprintf(buf, cap, "calc(%d.%02d%% + %dpx)",
 			 raw / 100, raw % 100, px);
@@ -985,7 +988,8 @@ static int js_host_computed(unsigned int node, const char *property,
 			     side == 2 ? st.mb : side == 3 ? st.ml :
 			     side == 4 ? st.pt : side == 5 ? st.pr :
 			     side == 6 ? st.pb : st.pl,
-			     st.mp_unit[side], st.mp_calc_px[side]);
+			     st.mp_unit[side], st.mp_calc_px[side],
+			     st.font_px);
 	} else if (!strcmp(name, "border-top-width") ||
 		   !strcmp(name, "border-right-width") ||
 		   !strcmp(name, "border-bottom-width") ||
@@ -999,7 +1003,7 @@ static int js_host_computed(unsigned int node, const char *property,
 		   !strcmp(name, "border-left-color")) {
 		int side = name[7] == 't' ? 0 : name[7] == 'r' ? 1 :
 			   name[7] == 'b' ? 2 : 3;
-		if (st.border_w[side])
+		if (st.border_w[side] && !st.border_t[side])
 			css_rgb(st.border_c[side], buf, cap);
 		else
 			snprintf(buf, cap, "rgba(0, 0, 0, 0)");
@@ -4125,22 +4129,22 @@ static void draw_border_box(struct ngui *ui, struct ngui_rect r,
 		int i;
 
 		for (i = 0; i < 4; i++)
-			if (st->border_w[i]) {
+			if (st->border_w[i] && !st->border_t[i]) {
 				ngui_fill_rect(ui, r, st->border_c[i]);
 				break;
 			}
 		return;
 	}
-	if (top)
+	if (top && !st->border_t[0])
 		draw_border_side(ui, r.x, r.y, r.w, top, 1,
 				 st->border_c[0], st->border_s[0]);
-	if (bottom)
+	if (bottom && !st->border_t[2])
 		draw_border_side(ui, r.x, r.y + r.h - bottom, r.w, bottom, 1,
 				 st->border_c[2], st->border_s[2]);
-	if (left)
+	if (left && !st->border_t[3])
 		draw_border_side(ui, r.x, r.y + top, r.h - top - bottom,
 				 left, 0, st->border_c[3], st->border_s[3]);
-	if (right)
+	if (right && !st->border_t[1])
 		draw_border_side(ui, r.x + r.w - right, r.y + top,
 				 r.h - top - bottom, right, 0,
 				 st->border_c[1], st->border_s[1]);
@@ -5672,7 +5676,10 @@ static void layout_block(struct lay *l, unsigned int node,
 	int clip_pushed = 0;
 	struct ngui_rect clip_rect;
 
-	if (depth > 24 || st->display == BR_DISPLAY_NONE)
+	/* A DOM level costs about two depth units (layout_block ->
+	 * layout_children), so 48 covers a ~24-level page.  Real news pages
+	 * nest a teaser 12+ levels deep; the old 24 skipped its text. */
+	if (depth > 48 || st->display == BR_DISPLAY_NONE)
 		return;
 	flow_y = l->y;
 	flow_left = l->left;
@@ -5900,7 +5907,8 @@ static void layout_block(struct lay *l, unsigned int node,
 			if (st->has_bg) {
 				int bw = st->border_w[0];
 
-				if (bw > 0 && st->border_c[0] != st->bg &&
+				if (bw > 0 && !st->border_t[0] &&
+				    st->border_c[0] != st->bg &&
 				    box.w > bw * 2 && box.h > bw * 2) {
 					struct ngui_rect inner = {
 						box.x + bw, box.y + bw,
@@ -5922,7 +5930,7 @@ static void layout_block(struct lay *l, unsigned int node,
 							     rtr, rbr, rbl,
 							     st->bg);
 				}
-			} else if (st->border_w[0]) {
+			} else if (st->border_w[0] && !st->border_t[0]) {
 				ngui_frame_round(l->ui, box, rtl, rtr, rbr,
 						 rbl, st->border_w[0],
 						 st->border_c[0]);
@@ -6162,7 +6170,7 @@ static int intrinsic_width(struct ngui *ui, unsigned int node,
 	int line_w = 0, max_w = 0;
 	int flex_row = pst->display == BR_DISPLAY_FLEX && !pst->flex_col;
 
-	if (depth > 12)
+	if (depth > 32)
 		return 0;
 	for (c = doc.nodes[node].first; c; c = doc.nodes[c].next) {
 		struct br_node *nd = &doc.nodes[c];
@@ -6252,10 +6260,14 @@ static int intrinsic_width(struct ngui *ui, unsigned int node,
 				 mp_px(&cs, 1, base) +
 				 cs.border_w[1] + cs.border_w[3];
 
-			if (cs.width_kind == 1)
-				cw += cs.width;
-			else if (cs.width_kind == 2 || cs.width_kind == 3)
-				cw += style_width_px(&cs, base);
+			/* width/height do not apply to non-replaced inline
+			 * boxes.  The tagesschau home label is an inline span
+			 * with width:1px for the mobile icon-only header; using
+			 * that width made the whole subnav collapse to a
+			 * one-character column. */
+			if (cs.width_kind && cs.display != BR_DISPLAY_INLINE)
+				cw += cs.width_kind == 1 ? cs.width :
+				      style_width_px(&cs, base);
 			else
 				cw += intrinsic_width(ui, c, &cs, depth + 1,
 						      base);
@@ -6586,7 +6598,7 @@ static void layout_flex_children(struct lay *l, unsigned int parent,
 	int avail = row_right - row_left;
 	int idx, row_top;
 
-	if (avail < 160 || depth > 24) {
+	if (avail < 160 || depth > 48) {
 		layout_children(l, parent, pst, depth, link);
 		return;
 	}
@@ -6771,7 +6783,7 @@ static void layout_grid_children(struct lay *l, unsigned int parent,
 	int row_y, row_bottom, have_left = 0, have_right = 0;
 	unsigned int c;
 
-	if (avail < 32 || depth > 24)
+	if (avail < 32 || depth > 48)
 		return;
 	if (track_total < 16)
 		track_total = 16;
@@ -6912,7 +6924,7 @@ static void layout_grid_auto(struct lay *l, unsigned int parent,
 	int minw = pst->width_kind == 1 ? pst->width : 200;
 	int ncols, colw, x, y = l->y, start_y = l->y, row_h = 0, col = 0;
 
-	if (avail < 32 || depth > 24) {
+	if (avail < 32 || depth > 48) {
 		layout_children(l, parent, pst, depth, link);
 		return;
 	}
@@ -7361,7 +7373,7 @@ static void layout_table(struct lay *l, unsigned int table,
 	unsigned int r, c;
 	int i, rr, cc;
 
-	if (depth > 24 || table_active) {
+	if (depth > 48 || table_active) {
 		layout_children(l, table, st, depth, link);
 		return;
 	}
@@ -7695,7 +7707,7 @@ static void layout_children(struct lay *l, unsigned int parent,
 {
 	unsigned int n;
 
-	if (depth > 24)
+	if (depth > 48)
 		return;
 	n = doc.nodes[parent].first;
 	while (n) {
@@ -7821,7 +7833,14 @@ static void layout_children(struct lay *l, unsigned int parent,
 			n = layout_inline_blocks(l, n, pst, depth, link);
 			continue;
 		}
-		if (cs.display == BR_DISPLAY_BLOCK || br_tag_is_block(nd->tag))
+		/* A flex container is block-level like any block box even when
+		 * the element is an inline tag such as <a> (a link card with
+		 * display:flex is common on news sites).  Without the block box
+		 * its children were laid out in the parent flow with a 0x0 box
+		 * of their own. */
+		if (cs.display == BR_DISPLAY_BLOCK ||
+		    cs.display == BR_DISPLAY_FLEX ||
+		    br_tag_is_block(nd->tag))
 			layout_block(l, n, &cs, depth + 1, lk);
 		else {
 			layout_children(l, n, &cs, depth + 1, lk);

+ 176 - 10
browser_html.c

@@ -2331,6 +2331,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,
@@ -2540,6 +2541,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;
@@ -2596,10 +2631,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++;
 		}
@@ -2672,10 +2709,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++;
 		}
@@ -2847,6 +2887,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++;
 		}
@@ -2928,6 +2969,7 @@ static int parse_font_px(const char *s, unsigned int len)
 				frac = frac * 10 + (s[i] - '0');
 				fscale *= 10;
 			}
+			digits = 1;
 			i++;
 		}
 	}
@@ -3013,7 +3055,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);
@@ -3046,6 +3090,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++;
 		}
 	}
@@ -3224,8 +3269,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;
@@ -3494,6 +3541,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++;
 		}
@@ -5226,7 +5274,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");
@@ -5291,26 +5339,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) {
@@ -5365,7 +5429,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;
@@ -5388,9 +5452,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)
@@ -5406,6 +5475,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,
@@ -5421,6 +5496,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,
@@ -5791,6 +5870,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;
@@ -5914,6 +6057,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++;
@@ -6296,7 +6449,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++;
@@ -6658,6 +6820,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:
@@ -7132,7 +7298,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)

+ 2 - 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
@@ -155,6 +155,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];

+ 4 - 0
js_browser.c

@@ -2709,6 +2709,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" },

+ 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>

+ 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-060 and 030a pass.  036a needs the POST echo server:
+Status: 010-066 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

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

@@ -83,6 +83,12 @@ a { color: #0645ad; }
 <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>
 </table>
 </body>
 </html>

+ 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) */