Przeglądaj źródła

Improve browser layout for details, SVG and absolute posters

Keep a closed details summary and hide only its body, treat SVG as a replaced block with fractional viewBox and fill support, include item margins/padding in flex outer widths with CSS-default nowrap, sum flex-row intrinsic widths, and lay out absolute images against the nearest positioned containing block. Adds ladder 056-059.
Johannes Zellner 1 tydzień temu
rodzic
commit
294775f232

+ 145 - 17
browser.c

@@ -197,6 +197,7 @@ struct lay {
 	int line_x, line_y, line_h;
 	int line_left, line_right;
 	int parent_top;
+	int cb_left, cb_right, cb_top;  /* containing block for absolute boxes */
 	int run_x;
 	int align;
 	int depth;
@@ -5503,8 +5504,10 @@ static void draw_svg(struct ngui *ui, unsigned node,
 
 			r.x = ox + (int)nd->svg_x * dw / vw;
 			r.y = oy + (int)nd->svg_y * dh / vh;
-			r.w = (int)nd->width_attr * dw / vw;
-			r.h = (int)nd->height_attr * dh / vh;
+			r.w = nd->width_pct ? dw * nd->width_attr / 100 :
+			      (int)nd->width_attr * dw / vw;
+			r.h = nd->height_pct ? dh * nd->height_attr / 100 :
+			      (int)nd->height_attr * dh / vh;
 			if (r.w < 1)
 				r.w = 1;
 			if (r.h < 1)
@@ -5537,10 +5540,11 @@ static void draw_svg(struct ngui *ui, unsigned node,
 					  oy + (int)nd->height_attr * dh / vh,
 					  st.border_c[0]);
 		} else if (s_eq(nm, "path")) {
-			if (st.border_w[0] && nd->src_off)
+			unsigned short pc = st.has_bg ? st.bg : st.border_c[0];
+
+			if ((st.has_bg || st.border_w[0]) && nd->src_off)
 				svg_path(ui, doc.attrs + nd->src_off,
-					 ox, oy, dw, dh, vw, vh,
-					 st.border_c[0]);
+					 ox, oy, dw, dh, vw, vh, pc);
 		} else if (s_eq(nm, "text")) {
 			unsigned int t = nd->first;
 			const char *s;
@@ -5573,16 +5577,95 @@ static void draw_svg(struct ngui *ui, unsigned node,
 	}
 }
 
+/* Size and paint a block-level/absolutely positioned <img>.  Inline images
+ * keep using add_image_run(); this covers the CSS `position:absolute;
+ * width:100%` poster pattern used by news sites. */
+static void image_block_size(unsigned int node, const struct br_style *st,
+			     int cbw, int *out_w, int *out_h)
+{
+	struct br_node *nd = &doc.nodes[node];
+	int idx = nd->img_index;
+	int iw = 0, ih = 0, w, h;
+
+	if (idx >= 0 && idx < image_count && images[idx].state == 1) {
+		iw = (int)images[idx].img.w;
+		ih = (int)images[idx].img.h;
+		if (iw <= 0 || ih <= 0) {
+			iw = (int)images[idx].native_w;
+			ih = (int)images[idx].native_h;
+		}
+	}
+	if (st->width_kind)
+		w = style_width_px(st, cbw);
+	else if (nd->width_attr)
+		w = nd->width_pct ? cbw * nd->width_attr / 100 :
+		    (int)nd->width_attr;
+	else if (iw)
+		w = iw;
+	else
+		w = 64;
+	if (w < 8)
+		w = 8;
+	if (cbw > 0 && w > cbw)
+		w = cbw;
+	if (st->height_kind)
+		h = style_height_px(st, cbw);
+	else if (nd->height_attr)
+		h = nd->height_pct ? cbw * nd->height_attr / 100 :
+		    (int)nd->height_attr;
+	else if (iw && ih)
+		h = w * ih / iw;
+	else
+		h = 64;
+	if (h < 8)
+		h = 8;
+	*out_w = w;
+	*out_h = h;
+}
+
+static void draw_image_block(struct lay *l, unsigned int node, int x, int y,
+			     int dw, int dh)
+{
+	int idx = doc.nodes[node].img_index;
+
+	if (idx >= 0 && idx < image_count && images[idx].state == 1) {
+		struct img_blit b;
+
+		b.dst = l->ui->px;
+		b.dst_w = l->ui->w;
+		b.dst_h = l->ui->h;
+		b.clip_x = page_rect.x;
+		b.clip_y = page_rect.y;
+		b.clip_w = page_rect.w - 12;
+		b.clip_h = page_rect.h;
+		b.x = x;
+		b.y = y;
+		b.scale = ((unsigned int)dw << 16) / images[idx].img.w;
+		b.bg = ui.theme.bg;
+		b.bg2 = ui.theme.bg;
+		b.flags = IMG_BLIT_OVER_DST;
+		img_draw(&images[idx].img, &b);
+	} else if (l->draw) {
+		ngui_fill_rect(l->ui, (struct ngui_rect){x, y, dw, dh},
+			       0xD69A);
+		ngui_frame(l->ui, (struct ngui_rect){x, y, dw, dh}, 0x8410);
+		ngui_text(l->ui, x + 8, y + 8, "[image]", 0x4208);
+	}
+}
+
 static void layout_block(struct lay *l, unsigned int node,
 			 const struct br_style *st, int depth,
 			 unsigned short link)
 {
 	int old_left = l->left, old_right = l->right, old_align = l->align;
 	int saved_parent_top = l->parent_top;
+	int saved_cb_left = l->cb_left, saved_cb_right = l->cb_right;
+	int saved_cb_top = l->cb_top;
 	int top, l0, r0;
 	int flow_y, flow_left, flow_right, positioned, relative, sticky, shifted;
 	int cbw, ml, mr, bl, br, pl, pr, bt, bb, pt, pb;
 	int deco_w, deco_h, content_w, content_h, box_h;
+	int img_dh = 0;
 	int definite_w = 0;
 	int normal_top = 0;
 	int rel_dx = 0, rel_dy = 0;
@@ -5747,6 +5830,13 @@ static void layout_block(struct lay *l, unsigned int node,
 			mr = free_w;
 		}
 	}
+	if (doc.nodes[node].tag == BR_TAG_IMG) {
+		int iw, ih;
+
+		image_block_size(node, st, cbw, &iw, &ih);
+		content_w = iw;
+		img_dh = ih;
+	}
 	l0 = old_left + ml;
 	r0 = l0 + deco_w + content_w;
 	if (r0 < l0 + 8)
@@ -5787,6 +5877,13 @@ static void layout_block(struct lay *l, unsigned int node,
 		r0 += rel_dx;
 	}
 	l->parent_top = top;
+	if (st->pos != 0) {
+		/* Positioned boxes establish the containing block for their
+		 * absolutely positioned descendants. */
+		l->cb_left = l0;
+		l->cb_right = r0;
+		l->cb_top = top;
+	}
 	if (l->draw && block_h[node] &&
 	    top < page_rect.y + page_rect.h &&
 	    top + block_h[node] > page_rect.y) {
@@ -5840,6 +5937,9 @@ static void layout_block(struct lay *l, unsigned int node,
 				draw_border_box(l->ui, box, st);
 		}
 	}
+	if (l->draw && doc.nodes[node].tag == BR_TAG_IMG)
+		draw_image_block(l, node, l0 + bl + pl, top + bt + pt,
+				 content_w, img_dh);
 	if (l->draw && st->overflow_hidden && block_h[node] > 0 &&
 	    l->ui && l->ui->nclip < 4) {
 		clip_rect.x = l0 + bl;
@@ -5959,7 +6059,9 @@ static void layout_block(struct lay *l, unsigned int node,
 			l->y = l->float_bottom;
 		l->float_active = 0;
 	}
-	if (st->height_kind &&
+	if (doc.nodes[node].tag == BR_TAG_IMG) {
+		content_h = img_dh;
+	} else if (st->height_kind &&
 	    !((doc.nodes[node].tag == BR_TAG_HTML ||
 	       doc.nodes[node].tag == BR_TAG_BODY) &&
 	      st->height_kind == 2)) {
@@ -6026,6 +6128,9 @@ static void layout_block(struct lay *l, unsigned int node,
 		l->right = flow_right;
 	}
 	l->parent_top = saved_parent_top;
+	l->cb_left = saved_cb_left;
+	l->cb_right = saved_cb_right;
+	l->cb_top = saved_cb_top;
 }
 
 
@@ -6055,6 +6160,7 @@ static int intrinsic_width(struct ngui *ui, unsigned int node,
 {
 	unsigned int c;
 	int line_w = 0, max_w = 0;
+	int flex_row = pst->display == BR_DISPLAY_FLEX && !pst->flex_col;
 
 	if (depth > 12)
 		return 0;
@@ -6144,10 +6250,18 @@ static int intrinsic_width(struct ngui *ui, unsigned int node,
 				 mp_px(&cs, 5, base) +
 				 mp_px(&cs, 3, base) +
 				 mp_px(&cs, 1, base) +
-				 cs.border_w[1] + cs.border_w[3] +
-				 intrinsic_width(ui, c, &cs, depth + 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);
+			else
+				cw += intrinsic_width(ui, c, &cs, depth + 1,
+						      base);
 
-			if (cs.float_left || cs.display == BR_DISPLAY_INLINE ||
+			if (flex_row || cs.float_left ||
+			    cs.display == BR_DISPLAY_INLINE ||
 			    cs.display == BR_DISPLAY_INLINE_BLOCK) {
 				line_w += cw;
 			} else {
@@ -6353,11 +6467,14 @@ static int flex_item_width(struct lay *l, unsigned int n,
 			w = 64;
 	} else {
 		w = intrinsic_width(l->ui, n, cs, 0, avail);
-		w += mp_px(cs, 7, avail);
-		w += mp_px(cs, 5, avail);
-		w += mp_px(cs, 3, avail);
-		w += mp_px(cs, 1, avail);
 	}
+	/* Explicit widths are content-box sizes; the flex item's outer width
+	 * must include padding, borders and margins. */
+	w += mp_px(cs, 7, avail);
+	w += mp_px(cs, 5, avail);
+	w += mp_px(cs, 3, avail);
+	w += mp_px(cs, 1, avail);
+	w += cs->border_w[1] + cs->border_w[3];
 	if (w < 24)
 		w = 24;
 	if (w > avail)
@@ -6532,7 +6649,9 @@ static void layout_flex_children(struct lay *l, unsigned int parent,
 		while (idx < nitem) {
 			int add = it[idx].w + (count ? gap : 0);
 
-			if (count && pst->flex_wrap != 2 &&
+			/* CSS default is nowrap; only flex-wrap: wrap (1)
+			 * starts a new row. */
+			if (count && pst->flex_wrap == 1 &&
 			    row_w + add > avail)
 				break;
 			row_w += add;
@@ -7634,9 +7753,12 @@ static void layout_children(struct lay *l, unsigned int parent,
 				ndeferred++;
 			} else if (l->draw && ndeferred < 16) {
 				deferred[ndeferred].node = n;
-				deferred[ndeferred].flow_y = l->y;
-				deferred[ndeferred].flow_left = l->left;
-				deferred[ndeferred].flow_right = l->right;
+				deferred[ndeferred].flow_y =
+					cs.pos == 1 ? l->cb_top : l->y;
+				deferred[ndeferred].flow_left =
+					cs.pos == 1 ? l->cb_left : l->left;
+				deferred[ndeferred].flow_right =
+					cs.pos == 1 ? l->cb_right : l->right;
 				deferred[ndeferred].link = lk;
 				deferred[ndeferred].z_index = cs.z_index;
 				deferred[ndeferred].z_set = cs.z_set;
@@ -7741,6 +7863,9 @@ static int measure_page(int left, int right)
 	l->align = BR_ALIGN_LEFT;
 	l->float_active = 0;
 	l->parent_top = 0;
+	l->cb_left = left;
+	l->cb_right = right;
+	l->cb_top = 0;
 	l->depth = 0;
 	l->nruns = 0;
 	l->space_pending = 0;
@@ -7795,6 +7920,9 @@ static void render_page(int left, int right, int y0)
 	l->align = BR_ALIGN_LEFT;
 	l->float_active = 0;
 	l->parent_top = 0;
+	l->cb_left = left;
+	l->cb_right = right;
+	l->cb_top = y0;
 	l->depth = 0;
 	l->nruns = 0;
 	l->space_pending = 0;

+ 45 - 10
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++;
@@ -7021,6 +7030,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 +7069,32 @@ void br_style_for(struct br_doc *d, unsigned int node,
 		if (parse_color(v, s_len(v), &c))
 			out->color = c;
 	}
+	/* SVG fill/stroke attributes; CSS declarations still win below. */
+	{
+		const char *fa = br_find_attr(d, node, "fill");
+		const char *sa = br_find_attr(d, node, "stroke");
+		unsigned short c;
+
+		if (fa && parse_color(fa, s_len(fa), &c)) {
+			out->bg = c;
+			out->has_bg = 1;
+			out->color = c;
+		}
+		if (sa && parse_color(sa, s_len(sa), &c)) {
+			out->border_c[0] = c;
+			out->border_w[0] = 1;
+		}
+	}
+
+	/* 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++) {
@@ -7484,16 +7525,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;

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

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

@@ -0,0 +1,57 @@
+<!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>
+<div id="result">checking...</div>
+<script>
+setTimeout(function () {
+  function R(id) { return document.getElementById(id).getBoundingClientRect(); }
+  function B(id) { return getComputedStyle(document.getElementById(id)).backgroundColor; }
+  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 === 'rgb(0, 90, 189)' &&
+           r2 === 'rgb(176, 0, 32)';
+
+  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>

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

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

@@ -78,6 +78,10 @@ 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>
 </table>
 </body>
 </html>