Преглед изворни кода

Improve browser CSS and page compatibility

Resolve CSS custom properties and :root rules, add a basic flex row layout, render form controls, and accept long stylesheet URLs.  Identify the fetch helper as a desktop browser and compile the browser-specific objects for size so the rootfs stays under the legacy pack cap.
Johannes Zellner пре 2 недеља
родитељ
комит
c36d9c33a6
7 измењених фајлова са 1009 додато и 24 уклоњено
  1. 4 2
      Makefile
  2. 409 4
      browser.c
  3. 573 12
      browser_html.c
  4. 17 0
      browser_html.h
  5. 2 2
      ucmd_curl.c
  6. 2 2
      uhttp.c
  7. 2 2
      uhttp.h

+ 4 - 2
Makefile

@@ -639,11 +639,13 @@ ucmd_curl.elf: ucmd_curl.o uhttp.o $(TLSLIB_OBJS) ucmd.ld
 
 # browser: the real app is a disk image (BROWSER) because it links ngui, the
 # image library, TLS and uhttp.  ucmd_browser.c is the tiny PATH launcher.
+# Compile the two large browser-specific objects for size: the legacy rootfs
+# pack has a hard low-memory cap and is already close to it.
 browser_html.o: browser_html.c browser_html.h
-	$(CC) $(CFLAGS) -o $@ $<
+	$(CC) $(CFLAGS) -Os -o $@ $<
 
 browser.o: browser.c ucmd_lib.h syscall.h wm_abi.h ngui.h browser_html.h uhttp.h img.h inflate.h
-	$(CC) $(CFLAGS) -o $@ $<
+	$(CC) $(CFLAGS) -Os -o $@ $<
 
 browser.elf: browser.o browser_html.o uhttp.o ngui.o font_8x16.o $(IMGLIB_OBJS) inflate.o $(TLSLIB_OBJS) ucmd.ld
 	$(LD) -T ucmd.ld -z max-page-size=0x100 -nostdlib -m elf_i386 -o $@ $(filter-out ucmd.ld,$^)

+ 409 - 4
browser.c

@@ -33,7 +33,7 @@
 #define BR_CSS_COMP_MAX (192u * 1024u)
 #define BR_MAX_SHEETS   6
 #define BR_HISTORY      16
-#define BR_URL_MAX      320
+#define BR_URL_MAX      512
 #define BR_STATUS_MAX   200
 
 #define BR_IMG_RGB565(r, g, b) \
@@ -804,7 +804,7 @@ static void worker_wait_ui(void)
 static int worker_fetch(const char *url, unsigned int cap,
 			struct fetch_meta *m, char *err, unsigned int errcap)
 {
-	static char req[512], meta[1024];
+	static char req[768], meta[1024];
 	char *p;
 	unsigned int n = 0, deadline, i;
 	int rn, pid;
@@ -1552,6 +1552,8 @@ static int run_width(const struct lay_run *r)
 {
 	if (r->img >= 0)
 		return r->iw;
+	if (r->img == -2)
+		return r->iw;
 	{
 		unsigned int n = r->has_lit ? s_len(r->lit) : r->len;
 		return (int)(n * (unsigned int)(8 * r->scale) +
@@ -1581,7 +1583,19 @@ static void flush_line(struct lay *l)
 
 		x += r->gap;
 		if (l->draw) {
-			if (r->img >= 0) {
+			if (r->img == -2) {
+				int hh = r->ih ? r->ih : 20;
+
+				ngui_fill_rect(l->ui,
+					(struct ngui_rect){x, l->line_y, w, hh},
+					l->ui->theme.panel_alt);
+				ngui_frame(l->ui,
+					(struct ngui_rect){x, l->line_y, w, hh},
+					l->ui->theme.border);
+				ngui_text_styled(l->ui, x + 6, l->line_y + 2,
+						 r->lit, s_len(r->lit), r->color,
+						 r->scale, r->bold);
+			} else if (r->img >= 0) {
 				struct br_image *bi = &images[r->img];
 				if (bi->state == 1) {
 					struct img_blit b;
@@ -1987,9 +2001,84 @@ static int list_index(unsigned int parent, unsigned int node)
 	return (int)n + 1;
 }
 
+static const char *form_text(unsigned int node)
+{
+	const char *v = br_value(&doc, node);
+	const char *p = br_placeholder(&doc, node);
+	const char *t = br_type(&doc, node);
+
+	if (s_eq(t, "hidden"))
+		return 0;
+	if (s_eq(t, "submit") || s_eq(t, "button") || s_eq(t, "reset"))
+		return v[0] ? v : "Button";
+	if (v[0])
+		return v;
+	if (p[0])
+		return p;
+	if (doc.nodes[node].tag == BR_TAG_TEXTAREA)
+		return "Text";
+	if (doc.nodes[node].tag == BR_TAG_SELECT)
+		return "Select";
+	return "Search";
+}
+
+static void add_form_run(struct lay *l, unsigned int node,
+			 const struct br_style *st, unsigned short href)
+{
+	const char *text = form_text(node);
+	struct lay_run *r;
+	int tw, w, h = 20, i;
+
+	if (!text)
+		return;
+	tw = (int)s_len(text) * 8 * st->scale;
+	if (st->width_kind == 1)
+		w = st->width;
+	else if (st->width_kind == 2)
+		w = (l->right - l->left) * (int)st->width / 100;
+	else
+		w = tw + 18;
+	if (w < 64)
+		w = 64;
+	if (w > l->right - l->left)
+		w = l->right - l->left;
+	if (w < 8)
+		w = 8;
+	if (l->line_x + w > l->right &&
+	    (l->nruns > 0 || l->line_x > l->left))
+		flush_line(l);
+	if (l->nruns >= 96)
+		return;
+	r = &l->runs[l->nruns++];
+	r->gap = (unsigned short)(l->line_x - l->run_x);
+	r->off = r->len = 0;
+	r->color = st->color;
+	r->href = href;
+	r->has_lit = 1;
+	for (i = 0; i + 1 < (int)sizeof(r->lit) && text[i]; i++)
+		r->lit[i] = text[i];
+	r->lit[i] = '\0';
+	r->img = -2;
+	r->iw = (unsigned short)w;
+	r->ih = (unsigned short)h;
+	r->scale = st->scale;
+	r->bold = st->bold;
+	r->underline = 0;
+	l->line_x += w;
+	l->run_x = l->line_x;
+	if (l->line_h < h)
+		l->line_h = h;
+}
+
 static void layout_children(struct lay *l, unsigned int parent,
 			    const struct br_style *pst, int depth,
 			    unsigned short link);
+static void layout_flex_children(struct lay *l, unsigned int parent,
+				 const struct br_style *pst, int depth,
+				 unsigned short link);
+static void layout_grid_children(struct lay *l, unsigned int parent,
+				 const struct br_style *pst, int depth,
+				 unsigned short link);
 
 static void layout_block(struct lay *l, unsigned int node,
 			 const struct br_style *st, int depth,
@@ -2000,6 +2089,15 @@ static void layout_block(struct lay *l, unsigned int node,
 
 	if (depth > 24 || st->display == BR_DISPLAY_NONE)
 		return;
+	if (doc.nodes[node].tag == BR_TAG_INPUT ||
+	    doc.nodes[node].tag == BR_TAG_TEXTAREA ||
+	    doc.nodes[node].tag == BR_TAG_SELECT) {
+		if (!(doc.nodes[node].tag == BR_TAG_INPUT &&
+		      s_eq(br_type(&doc, node), "hidden")))
+			add_form_run(l, node, st, link);
+		l->y += 20;
+		return;
+	}
 	flush_line(l);
 	l->y += st->mt;
 	top = l->y;
@@ -2074,7 +2172,13 @@ static void layout_block(struct lay *l, unsigned int node,
 					  st->color);
 			}
 		}
-		layout_children(l, node, st, depth + 1, link);
+		if (st->display == BR_DISPLAY_GRID && st->grid_ncols >= 2 &&
+		    st->grid_gap > 0)
+			layout_grid_children(l, node, st, depth + 1, link);
+		else if (st->display == BR_DISPLAY_FLEX && !st->flex_col)
+			layout_flex_children(l, node, st, depth + 1, link);
+		else
+			layout_children(l, node, st, depth + 1, link);
 	}
 	flush_line(l);
 	l->y += st->pb;
@@ -2240,6 +2344,299 @@ static unsigned int layout_float_group(struct lay *l, unsigned int first,
 	return n;
 }
 
+/* A deliberately simple flex row: items are placed left to right, grow
+ * items share the leftover width, and a row wraps when the next item does not
+ * fit.  It is enough for site headers, cards and Wikipedia's main-page boxes;
+ * flex-direction: column uses the normal block path. */
+static int flex_item_width(struct lay *l, unsigned int n,
+			   const struct br_style *cs, int avail)
+{
+	struct br_node *nd = &doc.nodes[n];
+
+	(void)l;
+	int w;
+
+	if (cs->width_kind == 2)
+		w = avail * (int)cs->width / 100;
+	else if (cs->width_kind == 1)
+		w = (int)cs->width;
+	else if (nd->tag == BR_TAG_IMG) {
+		int idx = nd->img_index;
+
+		if (idx >= 0 && idx < image_count &&
+		    images[idx].state == 1)
+			w = (int)images[idx].img.w;
+		else if (nd->width_attr)
+			w = (int)nd->width_attr;
+		else
+			w = 64;
+	} else {
+		w = intrinsic_width(n, cs, 0);
+		w += cs->pl + cs->pr + cs->ml + cs->mr;
+	}
+	if (w < 24)
+		w = 24;
+	if (w > avail)
+		w = avail;
+	return w;
+}
+
+static void layout_flex_children(struct lay *l, unsigned int parent,
+				 const struct br_style *pst, int depth,
+				 unsigned short link)
+{
+	unsigned int n, c;
+	int row_left = l->left, row_right = l->right;
+	int avail = row_right - row_left;
+	int grow_count = 0, fixed = 0, grow_w;
+	int x = row_left, row_top = l->y, row_bottom = l->y, any = 0;
+
+	if (avail < 160 || depth > 24) {
+		layout_children(l, parent, pst, depth, link);
+		return;
+	}
+
+	/* If direct text is not just whitespace, normal block flow handles it
+	 * better than pretending it is a flex item. */
+	for (c = doc.nodes[parent].first; c; c = doc.nodes[c].next) {
+		struct br_node *nd = &doc.nodes[c];
+
+		if (nd->type == BR_NODE_TEXT && !text_node_blank(nd)) {
+			layout_children(l, parent, pst, depth, link);
+			return;
+		}
+	}
+
+	for (c = doc.nodes[parent].first; c; c = doc.nodes[c].next) {
+		struct br_node *nd = &doc.nodes[c];
+		struct br_style cs;
+
+		if (nd->type == BR_NODE_TEXT)
+			continue;
+		br_style_for(&doc, c, pst, &cs);
+		if (cs.display == BR_DISPLAY_NONE)
+			continue;
+		if (cs.flex_grow && !cs.width_kind)
+			grow_count++;
+		else
+			fixed += flex_item_width(l, c, &cs, avail);
+	}
+	grow_w = grow_count ? (avail - fixed) / grow_count : 0;
+	if (grow_w < 96)
+		grow_w = 96;
+
+	n = doc.nodes[parent].first;
+	while (n) {
+		struct br_node *nd = &doc.nodes[n];
+		struct br_style cs;
+		unsigned short lk = link;
+		int colw;
+
+		if (nd->type == BR_NODE_TEXT) {
+			n = nd->next;
+			continue;
+		}
+		br_style_for(&doc, n, pst, &cs);
+		if (cs.display == BR_DISPLAY_NONE) {
+			n = nd->next;
+			continue;
+		}
+		if (nd->tag == BR_TAG_A && nd->href_off)
+			lk = (unsigned short)n;
+		if (cs.flex_grow && !cs.width_kind)
+			colw = grow_w;
+		else
+			colw = flex_item_width(l, n, &cs, avail);
+		if (colw > row_right - row_left)
+			colw = row_right - row_left;
+		if (any && x + colw > row_right) {
+			row_top = row_bottom;
+			row_bottom = row_top;
+			x = row_left;
+		}
+		l->left = x;
+		l->right = x + colw;
+		if (l->right < l->left + 8)
+			l->right = l->left + 8;
+		l->y = row_top;
+		l->line_x = l->left;
+		l->run_x = l->left;
+		l->line_y = l->y;
+		l->line_h = 0;
+		l->nruns = 0;
+		l->space_pending = 0;
+		l->align = cs.align;
+		layout_block(l, n, &cs, depth + 1, lk);
+		if (l->y > row_bottom)
+			row_bottom = l->y;
+		x += colw;
+		any++;
+		n = nd->next;
+	}
+	l->left = row_left;
+	l->right = row_right;
+	l->y = row_bottom;
+	l->line_x = l->left;
+	l->run_x = l->left;
+	l->line_y = l->y;
+	l->line_h = 0;
+	l->nruns = 0;
+	l->space_pending = 0;
+}
+
+/* Two-column CSS grid: track sizes from grid-template-columns (px, %, fr)
+ * plus the grid-area hints used by site shells (site notice/footer full
+ * width, column-start left, page-content right).  Anything more elaborate
+ * falls back to normal block flow. */
+static int grid_track_width(unsigned char kind, unsigned short val,
+			    int avail, int other)
+{
+	if (kind == 2)
+		return avail * (int)val / 100;
+	if (kind == 1)
+		return val;
+	return other;
+}
+
+static void layout_grid_children(struct lay *l, unsigned int parent,
+				 const struct br_style *pst, int depth,
+				 unsigned short link)
+{
+	unsigned int n;
+	int row_left = l->left, row_right = l->right;
+	int avail = row_right - row_left;
+	int gap = pst->grid_gap;
+	int track_total = avail - gap;
+	int col0, col1, x0, x1;
+	int row_y, row_bottom, have_left = 0, have_right = 0;
+	unsigned int c;
+
+	if (avail < 32 || depth > 24)
+		return;
+	if (track_total < 16)
+		track_total = 16;
+
+	col0 = grid_track_width((unsigned char)(pst->width_kind),
+				pst->width, track_total, 0);
+	col1 = grid_track_width((unsigned char)(pst->max_width_kind),
+				pst->max_width, track_total, 0);
+	if (pst->width_kind == 3 && pst->max_width_kind == 3) {
+		int w0 = pst->width ? pst->width : 1;
+		int w1 = pst->max_width ? pst->max_width : 1;
+
+		col0 = track_total * w0 / (w0 + w1);
+		col1 = track_total - col0;
+	} else if (pst->width_kind == 3) {
+		col0 = track_total - col1;
+		if (col0 < 24)
+			col0 = 24;
+	} else if (pst->max_width_kind == 3) {
+		col1 = track_total - col0;
+		if (col1 < 24)
+			col1 = 24;
+	}
+	if (col0 < 24)
+		col0 = 24;
+	if (col1 < 24)
+		col1 = 24;
+	if (col0 + col1 > track_total) {
+		col1 = track_total - col0;
+		if (col1 < 24)
+			col1 = 24;
+	}
+	x0 = row_left;
+	x1 = row_left + col0 + gap;
+
+	/* Direct text makes a grid ambiguous; use block flow instead. */
+	for (c = doc.nodes[parent].first; c; c = doc.nodes[c].next) {
+		struct br_node *nd = &doc.nodes[c];
+
+		if (nd->type == BR_NODE_TEXT && !text_node_blank(nd)) {
+			layout_children(l, parent, pst, depth, link);
+			return;
+		}
+	}
+
+	row_y = row_bottom = l->y;
+	n = doc.nodes[parent].first;
+	while (n) {
+		struct br_node *nd = &doc.nodes[n];
+		struct br_style cs;
+		unsigned short lk = link;
+		int slot, x, w;
+
+		if (nd->type == BR_NODE_TEXT) {
+			n = nd->next;
+			continue;
+		}
+		br_style_for(&doc, n, pst, &cs);
+		if (cs.display == BR_DISPLAY_NONE) {
+			n = nd->next;
+			continue;
+		}
+		if (nd->tag == BR_TAG_A && nd->href_off)
+			lk = (unsigned short)n;
+		slot = cs.grid_slot;
+		if (!slot) {
+			if (!have_left)
+				slot = 2;
+			else if (!have_right)
+				slot = 3;
+			else
+				slot = 2;
+		}
+		if (slot == 1) {
+			if (have_left || have_right) {
+				row_y = row_bottom;
+				have_left = have_right = 0;
+			}
+			x = row_left;
+			w = avail;
+		} else if (slot == 2) {
+			if (have_left) {
+				row_y = row_bottom;
+				have_left = have_right = 0;
+			}
+			x = x0;
+			w = col0;
+			have_left = 1;
+		} else {
+			if (have_right) {
+				row_y = row_bottom;
+				have_left = have_right = 0;
+			}
+			x = x1;
+			w = col1;
+			have_right = 1;
+		}
+		l->left = x;
+		l->right = x + w;
+		if (l->right < l->left + 8)
+			l->right = l->left + 8;
+		l->y = row_y;
+		l->line_x = l->left;
+		l->run_x = l->left;
+		l->line_y = l->y;
+		l->line_h = 0;
+		l->nruns = 0;
+		l->space_pending = 0;
+		l->align = cs.align;
+		layout_block(l, n, &cs, depth + 1, lk);
+		if (l->y > row_bottom)
+			row_bottom = l->y;
+		n = nd->next;
+	}
+	l->left = row_left;
+	l->right = row_right;
+	l->y = row_bottom;
+	l->line_x = l->left;
+	l->run_x = l->left;
+	l->line_y = l->y;
+	l->line_h = 0;
+	l->nruns = 0;
+	l->space_pending = 0;
+}
+
 static void layout_children(struct lay *l, unsigned int parent,
 			    const struct br_style *pst, int depth,
 			    unsigned short link)
@@ -2282,6 +2679,14 @@ static void layout_children(struct lay *l, unsigned int parent,
 			n = nd->next;
 			continue;
 		}
+		if (nd->tag == BR_TAG_INPUT || nd->tag == BR_TAG_TEXTAREA ||
+		    nd->tag == BR_TAG_SELECT) {
+			if (!(nd->tag == BR_TAG_INPUT &&
+			      s_eq(br_type(&doc, n), "hidden")))
+				add_form_run(l, n, &cs, lk);
+			n = nd->next;
+			continue;
+		}
 		if (nd->tag == BR_TAG_IMG) {
 			add_image_run(l, n, &cs, lk);
 			n = nd->next;

+ 573 - 12
browser_html.c

@@ -4,6 +4,8 @@
 
 #include "browser_html.h"
 
+static int is_space(char c);
+
 /* ---- storage (one document per process) ---- */
 
 static struct br_node nodes_store[BR_MAX_NODES];
@@ -392,6 +394,147 @@ static const char *attr_ptr(struct br_doc *d, unsigned int off)
 	return off ? d->attrs + off : "";
 }
 
+/* Copy a raw CSS string into the attr arena (no entity decoding). */
+static unsigned int store_raw(struct br_doc *d, const char *s,
+			      unsigned int len, unsigned int limit)
+{
+	unsigned int off;
+
+	if (len > limit)
+		len = limit;
+	if (!len || d->attrs_used + len + 1 > BR_ATTR_SIZE)
+		return 0;
+	off = d->attrs_used;
+	{
+		unsigned int i;
+
+		for (i = 0; i < len; i++)
+			d->attrs[off + i] = s[i];
+	}
+	d->attrs[off + len] = '\0';
+	d->attrs_used += len + 1;
+	return off;
+}
+
+static unsigned int css_var_find(struct br_doc *d, const char *name,
+				 unsigned int nlen)
+{
+	unsigned int i;
+
+	for (i = 0; i < d->nvars; i++) {
+		const char *n = attr_ptr(d, d->var_name[i]);
+		unsigned int j;
+
+		if (s_len(n) != nlen)
+			continue;
+		for (j = 0; j < nlen && n[j] == name[j]; j++)
+			;
+		if (j == nlen)
+			return i;
+	}
+	return BR_MAX_VARS;
+}
+
+static void css_var_set(struct br_doc *d, const char *name,
+			unsigned int nlen, const char *val, unsigned int vlen)
+{
+	unsigned int i, noff, voff;
+
+	if (nlen < 3 || name[0] != '-' || name[1] != '-' || !vlen)
+		return;
+	noff = store_raw(d, name, nlen, 63);
+	voff = store_raw(d, val, vlen, 199);
+	if (!noff || !voff)
+		return;
+	i = css_var_find(d, name, nlen);
+	if (i >= BR_MAX_VARS) {
+		if (d->nvars >= BR_MAX_VARS)
+			return;
+		i = d->nvars++;
+		d->var_name[i] = noff;
+	}
+	d->var_val[i] = voff;
+}
+
+/* Find the end of a declaration value: the next ';' outside quotes and
+ * parentheses.  The caller passes the position just after the ':'. */
+static unsigned int css_value_end(const char *s, unsigned int len,
+				  unsigned int i)
+{
+	int depth = 0;
+	char quote = 0;
+
+	while (i < len) {
+		char c = s[i];
+
+		if (quote) {
+			if (c == quote)
+				quote = 0;
+			else if (c == '\\' && i + 1 < len)
+				i++;
+		} else if (c == '"' || c == '\'') {
+			quote = c;
+		} else if (c == '(') {
+			depth++;
+		} else if (c == ')' && depth > 0) {
+			depth--;
+		} else if (c == ';' && depth == 0) {
+			break;
+		}
+		i++;
+	}
+	return i;
+}
+
+/* Collect --custom-property definitions from one declaration block. */
+static void css_collect_block(struct br_doc *d, const char *s,
+			      unsigned int len)
+{
+	unsigned int i = 0;
+
+	while (i < len) {
+		unsigned int pstart, pend, vstart, vend;
+
+		while (i < len && (is_space(s[i]) || s[i] == ';'))
+			i++;
+		if (i >= len)
+			break;
+		pstart = i;
+		while (i < len && s[i] != ':' && s[i] != ';')
+			i++;
+		pend = i;
+		if (i >= len || s[i] != ':') {
+			if (i < len)
+				i++;
+			continue;
+		}
+		i++;
+		vstart = i;
+		i = css_value_end(s, len, i);
+		vend = i;
+		if (i < len)
+			i++;
+		while (pstart < pend && is_space(s[pstart]))
+			pstart++;
+		while (pend > pstart && is_space(s[pend - 1]))
+			pend--;
+		while (vstart < vend && is_space(s[vstart]))
+			vstart++;
+		while (vend > vstart && is_space(s[vend - 1]))
+			vend--;
+		if (vend - vstart >= 10 &&
+		    ci_eq_n(s + vend - 10, "!important", 10)) {
+			vend -= 10;
+			while (vend > vstart && is_space(s[vend - 1]))
+				vend--;
+		}
+		if (pend - pstart >= 3 && s[pstart] == '-' &&
+		    s[pstart + 1] == '-')
+			css_var_set(d, s + pstart, pend - pstart,
+				    s + vstart, vend - vstart);
+	}
+}
+
 const char *br_href(struct br_doc *d, unsigned int node)
 {
 	return attr_ptr(d, d->nodes[node].href_off);
@@ -412,6 +555,21 @@ const char *br_rel(struct br_doc *d, unsigned int node)
 	return attr_ptr(d, d->nodes[node].rel_off);
 }
 
+const char *br_value(struct br_doc *d, unsigned int node)
+{
+	return attr_ptr(d, d->nodes[node].src_off);
+}
+
+const char *br_placeholder(struct br_doc *d, unsigned int node)
+{
+	return attr_ptr(d, d->nodes[node].alt_off);
+}
+
+const char *br_type(struct br_doc *d, unsigned int node)
+{
+	return attr_ptr(d, d->nodes[node].rel_off);
+}
+
 /* ---- document setup / node append ---- */
 
 void br_doc_init(struct br_doc *d)
@@ -426,6 +584,7 @@ void br_doc_init(struct br_doc *d)
 	d->rules = rule_store;
 	d->attrs_used = 1;      /* offset 0 = "no attribute" */
 	d->attrs[0] = '\0';
+	d->nvars = 0;
 	d->root = 0;
 }
 
@@ -440,6 +599,7 @@ static void doc_reset(struct br_doc *d)
 	d->nrules = 0;
 	d->title[0] = '\0';
 	d->inline_css_len = 0;
+	d->nvars = 0;
 	d->truncated = 0;
 	d->plain = 0;
 	for (i = 0; i < BR_MAX_NODES; i++) {
@@ -592,7 +752,7 @@ static void parse_attrs(struct br_doc *d, struct br_node *n,
 			continue;
 		}
 		if (str_eq(name, "href"))
-			n->href_off = store_attr(d, s + vstart, vlen, 220);
+			n->href_off = store_attr(d, s + vstart, vlen, 480);
 		else if (str_eq(name, "class"))
 			n->class_off = store_attr(d, s + vstart, vlen, 120);
 		else if (str_eq(name, "id"))
@@ -600,13 +760,22 @@ static void parse_attrs(struct br_doc *d, struct br_node *n,
 		else if (str_eq(name, "style"))
 			n->style_off = store_attr(d, s + vstart, vlen, 240);
 		else if (str_eq(name, "src"))
-			n->src_off = store_attr(d, s + vstart, vlen, 220);
+			n->src_off = store_attr(d, s + vstart, vlen, 400);
 		else if (str_eq(name, "alt"))
 			n->alt_off = store_attr(d, s + vstart, vlen, 120);
 		else if (str_eq(name, "color"))
 			n->color_off = store_attr(d, s + vstart, vlen, 32);
 		else if (str_eq(name, "rel"))
 			n->rel_off = store_attr(d, s + vstart, vlen, 64);
+		else if (str_eq(name, "value"))
+			n->src_off = store_attr(d, s + vstart, vlen, 220);
+		else if (str_eq(name, "placeholder") &&
+			 (n->tag == BR_TAG_INPUT || n->tag == BR_TAG_TEXTAREA))
+			n->alt_off = store_attr(d, s + vstart, vlen, 120);
+		else if (str_eq(name, "type") &&
+			 (n->tag == BR_TAG_INPUT || n->tag == BR_TAG_BUTTON ||
+			  n->tag == BR_TAG_SELECT || n->tag == BR_TAG_TEXTAREA))
+			n->rel_off = store_attr(d, s + vstart, vlen, 40);
 		else if (str_eq(name, "width")) {
 			n->width_attr = (unsigned short)parse_uint(s + vstart, vlen);
 			if (vlen && s[vstart + vlen - 1] == '%')
@@ -637,7 +806,8 @@ enum {
 	PROP_BORDER_W, PROP_BORDER_COLOR, PROP_LIST_NONE,
 	PROP_WIDTH, PROP_WIDTH_KIND, PROP_MAXW, PROP_MAXW_KIND,
 	PROP_HEIGHT, PROP_HEIGHT_KIND, PROP_LH_PCT, PROP_LH_PX, PROP_UPPER,
-	PROP_FLOAT,
+	PROP_FLOAT, PROP_FLEX_GROW, PROP_FLEX_COL, PROP_FLEX_WRAP,
+	PROP_GRID_NCOLS, PROP_GRID_GAP, PROP_GRID_SLOT,
 	PROP_COUNT
 };
 
@@ -1069,12 +1239,19 @@ static int parse_display(const char *s, unsigned int len)
 	if (i == 10 && ci_eq_n(s, "list-item", 10))
 		return BR_DISPLAY_BLOCK;
 	if (i == 4 && ci_eq_n(s, "flex", 4))
-		return BR_DISPLAY_BLOCK;
+		return BR_DISPLAY_FLEX;
+	if (i == 10 && ci_eq_n(s, "inline-flex", 10))
+		return BR_DISPLAY_FLEX;
 	if (i == 5 && ci_eq_n(s, "table", 5))
 		return BR_DISPLAY_BLOCK;
 	if (i == 10 && ci_eq_n(s, "table-cell", 10))
 		return BR_DISPLAY_INLINE;
-	if (i == 5 && ci_eq_n(s, "grid", 5))
+	/* Grid shells are common on news/wiki pages, but the two-column
+	 * heuristic is not reliable for their nested area templates yet.
+	 * Collapse them to block flow so the content stays readable. */
+	if (i == 4 && ci_eq_n(s, "grid", 4))
+		return BR_DISPLAY_BLOCK;
+	if (i == 11 && ci_eq_n(s, "inline-grid", 11))
 		return BR_DISPLAY_BLOCK;
 	return BR_DISPLAY_INLINE;
 }
@@ -1130,9 +1307,275 @@ static int parse_border_width(const char *s, unsigned int len)
 	return -1;
 }
 
-static void parse_decls(const char *s, unsigned int len, struct br_decl *out,
+
+/* Expand var(--name[, fallback]) references.  Returns the expanded length;
+ * the input is copied verbatim when it contains no var(). */
+static unsigned int css_expand_vars(struct br_doc *d, const char *s,
+				    unsigned int len, char *out,
+				    unsigned int cap, int depth)
+{
+	unsigned int i = 0, n = 0;
+
+	if (depth > 8)
+		return 0;
+	while (i < len && n + 1 < cap) {
+		unsigned int p, inner, close, comma, nlen, fstart;
+		char quote;
+		int parens;
+
+		if (!(i + 4 <= len && ci_eq_n(s + i, "var(", 4))) {
+			out[n++] = s[i++];
+			continue;
+		}
+		p = i + 4;
+		quote = 0;
+		parens = 1;
+		while (p < len && parens) {
+			char c = s[p];
+
+			if (quote) {
+				if (c == quote)
+					quote = 0;
+				else if (c == '\\' && p + 1 < len)
+					p++;
+			} else if (c == '"' || c == '\'') {
+				quote = c;
+			} else if (c == '(') {
+				parens++;
+			} else if (c == ')') {
+				parens--;
+			}
+			p++;
+		}
+		if (parens) {
+			out[n++] = s[i++];
+			continue;
+		}
+		close = p - 1;
+		inner = i + 4;
+		while (inner < close && is_space(s[inner]))
+			inner++;
+		comma = inner;
+		parens = 0;
+		quote = 0;
+		while (comma < close) {
+			char c = s[comma];
+
+			if (quote) {
+				if (c == quote)
+					quote = 0;
+			} else if (c == '"' || c == '\'') {
+				quote = c;
+			} else if (c == '(') {
+				parens++;
+			} else if (c == ')' && parens > 0) {
+				parens--;
+			} else if (c == ',' && parens == 0) {
+				break;
+			}
+			comma++;
+		}
+		nlen = comma - inner;
+		while (nlen && is_space(s[inner + nlen - 1]))
+			nlen--;
+		fstart = comma < close ? comma + 1 : close;
+		while (fstart < close && is_space(s[fstart]))
+			fstart++;
+		if (nlen >= 3 && s[inner] == '-' && s[inner + 1] == '-') {
+			unsigned int vi = css_var_find(d, s + inner, nlen);
+
+			if (vi < BR_MAX_VARS) {
+				const char *v = attr_ptr(d, d->var_val[vi]);
+				unsigned int vn = css_expand_vars(d, v, s_len(v),
+								  out + n,
+								  cap - n, depth + 1);
+				n += vn;
+			} else if (fstart < close) {
+				unsigned int vn = css_expand_vars(d, s + fstart,
+								  close - fstart,
+								  out + n, cap - n,
+								  depth + 1);
+				n += vn;
+			}
+		} else if (fstart < close) {
+			unsigned int vn = css_expand_vars(d, s + fstart,
+							  close - fstart,
+							  out + n, cap - n,
+							  depth + 1);
+			n += vn;
+		}
+		i = p;
+	}
+	out[n] = '\0';
+	return n;
+}
+
+
+static unsigned int grid_skip_sep(const char *s, unsigned int len,
+				  unsigned int i)
+{
+	while (i < len && (is_space(s[i]) || s[i] == ','))
+		i++;
+	return i;
+}
+
+/* Parse one grid track (px, %, rem/em, fr, auto, or the second minmax()
+ * argument).  Returns 1 on success. */
+static int parse_grid_track(const char *s, unsigned int len,
+			    unsigned int *pp, unsigned short *val,
+			    unsigned char *kind)
+{
+	unsigned int i = grid_skip_sep(s, len, *pp);
+	unsigned int whole = 0, frac = 0, scale = 1;
+	int any = 0;
+
+	if (i + 7 <= len && ci_eq_n(s + i, "minmax(", 7)) {
+		unsigned int j = i + 7;
+
+		while (j < len && s[j] != ',')
+			j++;
+		if (j >= len)
+			return 0;
+		i = j + 1;
+		while (i < len && is_space(s[i]))
+			i++;
+	}
+	if (i + 7 <= len && ci_eq_n(s + i, "repeat(", 7)) {
+		int depth = 1;
+
+		i += 7;
+		while (i < len && depth) {
+			if (s[i] == '(')
+				depth++;
+			else if (s[i] == ')')
+				depth--;
+			i++;
+		}
+		*pp = i;
+		return 0;
+	}
+	while (i < len && s[i] >= '0' && s[i] <= '9') {
+		whole = whole * 10 + (unsigned int)(s[i] - '0');
+		i++;
+		any = 1;
+	}
+	if (i < len && s[i] == '.') {
+		i++;
+		while (i < len && s[i] >= '0' && s[i] <= '9') {
+			if (scale < 1000) {
+				frac = frac * 10 + (unsigned int)(s[i] - '0');
+				scale *= 10;
+			}
+			i++;
+			any = 1;
+		}
+	}
+	if (!any) {
+		if (i + 4 <= len && ci_eq_n(s + i, "auto", 4)) {
+			*val = 1;
+			*kind = 3;
+			*pp = i + 4;
+			return 1;
+		}
+		return 0;
+	}
+	if (i + 2 <= len && ci_eq_n(s + i, "fr", 2)) {
+		*val = (unsigned short)(whole ? whole : 1);
+		*kind = 3;
+		i += 2;
+	} else if (i < len && s[i] == '%') {
+		*val = (unsigned short)(whole > 1000 ? 1000 : whole);
+		*kind = 2;
+		i++;
+	} else if (i + 3 <= len && ci_eq_n(s + i, "rem", 3)) {
+		*val = (unsigned short)(whole * 16 + frac * 16 / scale);
+		*kind = 1;
+		i += 3;
+	} else if (i + 2 <= len && ci_eq_n(s + i, "em", 2)) {
+		*val = (unsigned short)(whole * 16 + frac * 16 / scale);
+		*kind = 1;
+		i += 2;
+	} else {
+		*val = (unsigned short)(whole > 1000 ? 1000 : whole);
+		*kind = 1;
+		if (i + 2 <= len && ci_eq_n(s + i, "px", 2))
+			i += 2;
+	}
+	while (i < len && s[i] != ')' && !is_space(s[i]) && s[i] != ',')
+		i++;
+	*pp = i;
+	return 1;
+}
+
+static int parse_grid_cols(const char *s, unsigned int len,
+			   unsigned short val[2], unsigned char kind[2])
+{
+	unsigned int pos = 0;
+	int n = 0;
+
+	while (n < 2) {
+		unsigned int before = pos;
+
+		if (!parse_grid_track(s, len, &pos, &val[n], &kind[n]))
+			break;
+		n++;
+		if (pos <= before)
+			break;
+		while (pos < len && is_space(s[pos]))
+			pos++;
+		if (pos >= len)
+			break;
+	}
+	return n;
+}
+
+static int parse_grid_slot(const char *s, unsigned int len)
+{
+	if (contains_ci_len(s, len, "footer") ||
+	    contains_ci_len(s, len, "header") ||
+	    contains_ci_len(s, len, "sitenotice") ||
+	    contains_ci_len(s, len, "navbar"))
+		return 1;
+	if (contains_ci_len(s, len, "columnstart") ||
+	    contains_ci_len(s, len, "sidebar") ||
+	    contains_ci_len(s, len, "left") ||
+	    contains_ci_len(s, len, "start"))
+		return 2;
+	if (contains_ci_len(s, len, "pagecontent") ||
+	    contains_ci_len(s, len, "content") ||
+	    contains_ci_len(s, len, "main") ||
+	    contains_ci_len(s, len, "right") ||
+	    contains_ci_len(s, len, "end"))
+		return 3;
+	return 0;
+}
+
+static int css_has_var(const char *s, unsigned int len)
+{
+	unsigned int i;
+
+	for (i = 0; i + 4 <= len; i++)
+		if ((s[i] == 'v' || s[i] == 'V') &&
+		    ci_eq_n(s + i, "var(", 4))
+			return 1;
+	return 0;
+}
+
+static void parse_decls(struct br_doc *d, const char *s,
+			unsigned int len, struct br_decl *out,
 			unsigned int *nout)
 {
+	static char expanded[4096];
+
+	if (css_has_var(s, len)) {
+		unsigned int elen = css_expand_vars(d, s, len, expanded,
+						   sizeof(expanded), 0);
+
+		if (elen) {
+			s = expanded;
+			len = elen;
+		}
+	}
 	unsigned int i = 0;
 
 	*nout = 0;
@@ -1244,6 +1687,74 @@ static void parse_decls(const char *s, unsigned int len, struct br_decl *out,
 				 ci_eq_n(s + vstart, "right", 5))
 				f = 2;
 			decl_add(out, nout, PROP_FLOAT, f, important);
+		} else if (str_eq(prop, "flex-grow") ||
+			   str_eq(prop, "flex")) {
+			unsigned int q = vstart;
+			int g = 0;
+
+			while (q < vend && (s[q] == ' ' || s[q] == '\t'))
+				q++;
+			while (q < vend && s[q] >= '0' && s[q] <= '9') {
+				g = g * 10 + (s[q] - '0');
+				q++;
+			}
+			if (g > 100)
+				g = 100;
+			decl_add(out, nout, PROP_FLEX_GROW, g, important);
+		} else if (str_eq(prop, "flex-direction")) {
+			decl_add(out, nout, PROP_FLEX_COL,
+				 contains_ci_len(s + vstart, vend - vstart,
+						  "column"), important);
+		} else if (str_eq(prop, "flex-wrap")) {
+			int wrap = contains_ci_len(s + vstart, vend - vstart,
+						   "wrap") &&
+				   !contains_ci_len(s + vstart, vend - vstart,
+						    "nowrap");
+			decl_add(out, nout, PROP_FLEX_WRAP, wrap, important);
+		} else if (str_eq(prop, "grid-template-columns") ||
+			   str_eq(prop, "grid-template")) {
+			const char *v = s + vstart;
+			unsigned int vl = vend - vstart;
+			unsigned short val[2];
+			unsigned char kind[2];
+			int n, q;
+
+			if (str_eq(prop, "grid-template")) {
+				for (q = 0; q < (int)vl; q++)
+					if (v[q] == '/') {
+						q++;
+						while (q < (int)vl && is_space(v[q]))
+							q++;
+						v += q;
+						vl -= (unsigned int)q;
+						break;
+					}
+			}
+			n = parse_grid_cols(v, vl, val, kind);
+			if (n > 0) {
+				decl_add(out, nout, PROP_WIDTH, val[0], important);
+				decl_add(out, nout, PROP_WIDTH_KIND, kind[0], important);
+				decl_add(out, nout, PROP_GRID_NCOLS, n, important);
+			}
+			if (n > 1) {
+				decl_add(out, nout, PROP_MAXW, val[1], important);
+				decl_add(out, nout, PROP_MAXW_KIND, kind[1], important);
+			}
+		} else if (str_eq(prop, "gap") || str_eq(prop, "column-gap")) {
+			unsigned int gp = 0;
+			unsigned short gv = 0;
+			unsigned char gk = 1;
+
+			if (parse_grid_track(s, vend, &gp, &gv, &gk) && gk == 1) {
+				if (gv > 120)
+					gv = 120;
+				decl_add(out, nout, PROP_GRID_GAP, gv, important);
+			}
+		} else if (str_eq(prop, "grid-area")) {
+			int slot = parse_grid_slot(s + vstart, vend - vstart);
+
+			if (slot)
+				decl_add(out, nout, PROP_GRID_SLOT, slot, important);
 		} else if (str_eq(prop, "width") ||
 			   str_eq(prop, "max-width") ||
 			   str_eq(prop, "height")) {
@@ -1531,6 +2042,8 @@ static int media_list_matches(const char *s, unsigned int len)
 	return 0;
 }
 
+static int css_collect_only;
+
 static void parse_css(struct br_doc *d, const char *s, unsigned int len)
 {
 	unsigned int i = 0;
@@ -1601,7 +2114,10 @@ static void parse_css(struct br_doc *d, const char *s, unsigned int len)
 			send--;
 		if (sstart == send)
 			continue;
-		parse_decls(s + bstart, bend - bstart, decls, &nd);
+		css_collect_block(d, s + bstart, bend - bstart);
+		if (css_collect_only)
+			continue;
+		parse_decls(d, s + bstart, bend - bstart, decls, &nd);
 		if (!nd)
 			continue;
 		/* Split a comma-separated selector list into separate rules. */
@@ -1623,10 +2139,20 @@ static void parse_css(struct br_doc *d, const char *s, unsigned int len)
 				 * pseudo-classes or attribute tests: they need
 				 * state/attributes we do not model.  The other
 				 * selectors in the list still apply. */
-				for (k = j; k < e; k++)
+				for (k = j; k < e; ) {
 					if (s[k] == '+' || s[k] == '~' ||
-					    s[k] == ':' || s[k] == '[')
+					    s[k] == '[')
+						break;
+					if (s[k] == ':') {
+						if (k + 5 <= e &&
+						    ci_eq_n(s + k, ":root", 5)) {
+							k += 5;
+							continue;
+						}
 						break;
+					}
+					k++;
+				}
 				if (k < e) {
 					j = q + 1;
 					if (q >= send)
@@ -1654,13 +2180,20 @@ static void parse_css(struct br_doc *d, const char *s, unsigned int len)
 
 void br_parse_css_text(struct br_doc *d, const char *css, unsigned int len)
 {
+	css_collect_only = 1;
+	parse_css(d, css, len);
+	css_collect_only = 0;
 	parse_css(d, css, len);
 }
 
 void br_parse_inline_css(struct br_doc *d)
 {
-	if (d->inline_css_len)
+	if (d->inline_css_len) {
+		css_collect_only = 1;
+		parse_css(d, css_store, d->inline_css_len);
+		css_collect_only = 0;
 		parse_css(d, css_store, d->inline_css_len);
+	}
 	d->inline_css_len = 0;
 }
 
@@ -1754,7 +2287,15 @@ static int compound_match(struct br_doc *d, unsigned int node, const char *s,
 				return 0;
 			got = 1;
 		} else if (s[i] == ':') {
-			return 0;      /* pseudo-classes are not modelled */
+			if (i + 5 <= len && ci_eq_n(s + i, ":root", 5) &&
+			    (i + 5 == len || !is_ident(s[i + 5]))) {
+				if (d->nodes[node].tag != BR_TAG_HTML)
+					return 0;
+				i += 5;
+				got = 1;
+			} else {
+				return 0;  /* other pseudo-classes are not modelled */
+			}
 		} else {
 			i++;
 		}
@@ -1922,6 +2463,24 @@ static void apply_decl(struct br_style *st, const struct br_decl *dcl)
 	case PROP_FLOAT:
 		st->float_left = (unsigned char)dcl->val;
 		break;
+	case PROP_FLEX_GROW:
+		st->flex_grow = (unsigned char)dcl->val;
+		break;
+	case PROP_FLEX_COL:
+		st->flex_col = (unsigned char)(dcl->val != 0);
+		break;
+	case PROP_FLEX_WRAP:
+		st->flex_wrap = (unsigned char)(dcl->val != 0);
+		break;
+	case PROP_GRID_NCOLS:
+		st->grid_ncols = (unsigned char)dcl->val;
+		break;
+	case PROP_GRID_GAP:
+		st->grid_gap = (unsigned char)dcl->val;
+		break;
+	case PROP_GRID_SLOT:
+		st->grid_slot = (unsigned char)dcl->val;
+		break;
 	default:
 		break;
 	}
@@ -1966,6 +2525,8 @@ void br_style_for(struct br_doc *d, unsigned int node,
 	out->width_kind = out->max_width_kind = out->height_kind = 0;
 	out->mt = out->mr = out->mb = out->ml = 0;
 	out->pt = out->pr = out->pb = out->pl = 0;
+	out->flex_grow = out->flex_col = out->flex_wrap = 0;
+	out->grid_ncols = out->grid_gap = out->grid_slot = 0;
 	tag = d->nodes[node].tag;
 	out->display = br_tag_is_block(tag) ? BR_DISPLAY_BLOCK :
 					      BR_DISPLAY_INLINE;
@@ -2061,7 +2622,7 @@ void br_style_for(struct br_doc *d, unsigned int node,
 		unsigned int nd, k;
 		const char *v = attr_ptr(d, d->nodes[node].style_off);
 
-		parse_decls(v, s_len(v), decls, &nd);
+		parse_decls(d, v, s_len(v), decls, &nd);
 		for (k = 0; k < nd; k++)
 			cascade_decl(out, &decls[k], 1000, best, best_imp);
 	}

+ 17 - 0
browser_html.h

@@ -11,6 +11,7 @@
 #define BR_ATTR_SIZE     524288
 #define BR_CSS_SIZE      12288
 #define BR_MAX_RULES     2304
+#define BR_MAX_VARS      512
 #define BR_DECLS         16
 #define BR_TITLE_MAX     96
 
@@ -27,6 +28,8 @@
 #define BR_DISPLAY_INLINE 0
 #define BR_DISPLAY_BLOCK  1
 #define BR_DISPLAY_NONE   2
+#define BR_DISPLAY_FLEX   3
+#define BR_DISPLAY_GRID   4
 
 /* Text alignment. */
 #define BR_ALIGN_LEFT   0
@@ -67,6 +70,12 @@ struct br_style {
 	unsigned char align;        /* BR_ALIGN_* */
 	unsigned char display;      /* BR_DISPLAY_* */
 	unsigned char float_left;   /* float: left/right */
+	unsigned char flex_grow;    /* flex-grow, 0..100 */
+	unsigned char flex_col;     /* flex-direction: column */
+	unsigned char flex_wrap;    /* flex-wrap: wrap */
+	unsigned char grid_ncols;   /* 1 or 2 supported */
+	unsigned char grid_gap;     /* px */
+	unsigned char grid_slot;    /* 0 auto, 1 full, 2 left, 3 right */
 	unsigned char no_bullet;    /* list-style: none (inherited) */
 	unsigned char uppercase;    /* text-transform: uppercase (inherited) */
 	unsigned char border_w;
@@ -134,6 +143,11 @@ struct br_doc {
 	unsigned int nrules;
 	char title[BR_TITLE_MAX];
 	unsigned int inline_css_len;
+	/* CSS custom properties, stored in the attr arena.  A pragmatic
+	 * single table: the last definition wins, which matches :root. */
+	unsigned int var_name[BR_MAX_VARS];
+	unsigned int var_val[BR_MAX_VARS];
+	unsigned int nvars;
 	int truncated;
 	int plain;                  /* text/plain: one preformatted text node */
 };
@@ -167,5 +181,8 @@ const char *br_href(struct br_doc *d, unsigned int node);
 const char *br_src(struct br_doc *d, unsigned int node);
 const char *br_alt(struct br_doc *d, unsigned int node);
 const char *br_rel(struct br_doc *d, unsigned int node);
+const char *br_value(struct br_doc *d, unsigned int node);
+const char *br_placeholder(struct br_doc *d, unsigned int node);
+const char *br_type(struct br_doc *d, unsigned int node);
 
 #endif

+ 2 - 2
ucmd_curl.c

@@ -116,7 +116,7 @@ static void fetch_fail(unsigned int status, int err, const char *ctype,
 static void fetch_once(void)
 {
 	static struct uhttp h;
-	char req[512];
+	char req[768];
 	char meta[768];
 	unsigned char *buf, *body;
 	unsigned int cap = 0, total = 0, n = 0;
@@ -153,7 +153,7 @@ static void fetch_once(void)
 	}
 
 	uhttp_init(&h);
-	h.user_agent = "nebos-browser-fetch/0.1";
+	h.user_agent = "Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0 Safari/537.36";
 	rv = uhttp_open(&h, req + i, 0, 0);
 	/* The browser cancels a page load by killing our predecessor.  It can
 	 * still own the single NIC receiver for a tick or two, so a fresh

+ 2 - 2
uhttp.c

@@ -585,7 +585,7 @@ static int read_response_head(struct uhttp *h, char *location, int *have_loc)
 
 static int send_request(struct uhttp *h, unsigned int flags)
 {
-	char req[640];
+	char req[1024];
 	unsigned int n = 0;
 	int rv;
 
@@ -621,7 +621,7 @@ void uhttp_init(struct uhttp *h)
 
 	for (i = 0; i < sizeof(*h); i++)
 		((unsigned char *)h)[i] = 0;
-	h->user_agent = "nebos-uhttp/0.1";
+	h->user_agent = "Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0 Safari/537.36";
 }
 
 static int host_same(const char *a, const char *b)

+ 2 - 2
uhttp.h

@@ -14,8 +14,8 @@
 #include "ucmd_lib.h"
 
 #define UHTTP_HOST_MAX       128
-#define UHTTP_PATH_MAX       192
-#define UHTTP_LOC_MAX        256
+#define UHTTP_PATH_MAX       512
+#define UHTTP_LOC_MAX        640
 #define UHTTP_LINE_MAX       320
 #define UHTTP_READER_MAX     2048
 #define UHTTP_MAX_REDIRECTS  5