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

Render google.com: inert noscript, 4 KB URLs and author-styled controls

google.com showed only its "Klicke hier ... nicht automatisch
weitergeleitet" fallback.  Its <noscript> holds a meta refresh and
`table,div,span,p{display:none}`, and the parser treated noscript content
as live DOM/CSS although scripting is always on.  <noscript> is now a
raw-text, display:none element (HTML's scripting-enabled parsing).

The page's form controls then rendered in the dark UI theme:

  - Google's stylesheet URL (~720 B) and main script URL (~3.7 KB) were
    truncated by 512 B browser URLs, 480 B href/src attributes, the curl
    helper's 768 B request file and uhttp's 1 KB paths.  All are 4 KB now
    (BR_URL_MAX, BR_URL_ATTR_MAX, UHTTP_PATH_MAX; header lines 4.5 KB).
  - ~94 KB of inline <style> overflowed the 64 KB BR_CSS_SIZE, dropping
    the form-control rules; it is 256 KB.
  - Inputs, textareas and buttons with author CSS (background, border or
    radius) are painted with that background/border/radius and text
    colour and sized from padding, height, min-width and margins;
    unstyled controls keep the ngui theme.  `background: transparent|none`
    is now a cascaded value (PROP_BG_NONE shares PROP_BG's slot).

Layout fixes found on the same page:

  - float shrink-to-fit width includes borders ("Anmelden" wrapped);
  - a max-width clamp makes the width definite, so margin:auto centres;
  - a flex row under 160 px stays a row when its items fit;
  - align-self overrides the row's align-items;
  - forced-colors/prefers-contrast/hover/pointer media features are
    answered for a normal-contrast mouse screen (Google's forced-colors
    border no longer applies);
  - U+2010..2015 map to '-'.

Large leaf buffers in uhttp and the browser are static to spare the
128 KB ring-3 stack.  New compat pages 072 (styled controls) and 073
(noscript) fail on the old build and pass now; pages 001-071 render
pixel-identical in browser-host.
Johannes Zellner пре 5 дана
родитељ
комит
7254b400be

+ 22 - 3
AGENTS.md

@@ -1627,7 +1627,21 @@ it to `0x7E00`.  The kernel region itself only has one wall (`_end` below
   `value`/`checked`/`selectedIndex` properties read/write the live control
   state.  Forms expose `elements`/`length`/`submit()`/`reset()`; typing and
   checkbox/select changes fire `input` and `change`, and submit/reset fire
-  their cancellable events.  Flex/grid, basic tables, inline SVG and CSS
+  their cancellable events.  A control with author CSS (background, border
+  or radius -- `background:transparent;border:none` counts, which is why
+  `background: transparent|none` is a real cascaded value, `PROP_BG_NONE`)
+  is painted with that background/border/radius and text colour and sized
+  from its padding, height, min-width and margins (buttons border-box);
+  unstyled controls keep the ngui theme look.  Scripting is always on, so
+  `<noscript>` is a raw-text, `display:none` element: google.com's
+  noscript meta refresh plus `table,div,span,p{display:none}` used to hide
+  the whole page.  URLs (`BR_URL_MAX`, `href`/`src` attributes, the helper
+  request/meta files, `UHTTP_PATH_MAX`) hold 4 KB: google.com's script URL
+  is ~3.7 KB.  Inline `<style>` text is collected up to 256 KB
+  (`BR_CSS_SIZE`; google.com inlines ~94 KB).  Media features with a known
+  answer are evaluated (`forced-colors: none`, normal contrast,
+  `hover: hover`, `pointer: fine`); unknown ones stay true.  Flex/grid,
+  basic tables, inline SVG and CSS
   variables are supported (see known issue 22 for the remaining CSS and DOM
   gaps).  `SYS_SPAWN`
   loads FAT ELFs through `kmalloc` now (the old 16 KB `fat_load_buf` is gone)
@@ -1685,7 +1699,7 @@ it to `0x7E00`.  The kernel region itself only has one wall (`_end` below
   deletion); uhttp stores every `Set-Cookie` (redirects too), sends matching
   cookies on each hop, splits requests/bodies into 1024-byte TLS records or
   MSS-sized TCP sends, takes `accept`/`extra_headers`, follows up to 8
-  redirects with 1 KB paths and 1.5 KB header lines, and treats 1xx/204/304
+  redirects with 4 KB paths and 4.5 KB header lines, and treats 1xx/204/304
   as bodyless.  `ujson.c/h` is the arena JSON DOM parser (caller-owned node
   and string pools, \uXXXX/surrogates to UTF-8, depth 48).  Host tests:
   `make test-chat`; `tools/mock_chat.py` mocks Chat + the OIDC provider on
@@ -2487,7 +2501,12 @@ and the WM falls back to polling (`io_keyboard_irq_masked()`).
     painting without moving flow (and joins the deferred stack when it has a
     z-index), and `position:sticky` supports top and
     bottom offsets and clamps to the containing block.  `prefers-color-scheme`
-    media queries are ignored so the page's base palette is used.  Block
+    media queries are ignored so the page's base palette is used, and
+    `forced-colors`/`prefers-contrast`/`hover`/`pointer` are answered for a
+    normal-contrast mouse screen.  A flex row narrower than 160 px is still a
+    row when its items fit, and `align-self` overrides the row's
+    `align-items`; a clamped `max-width` makes `margin: auto` centre the
+    box.  Block
     `width`/`max-width`/`min-width`, content-box `height` with `min`/`max`,
     `box-sizing: border-box`, `margin: 0 auto` and `calc(percent ± px)`
     work in widths, margins/padding, heights and min/max;

Разлика између датотеке није приказан због своје велике величине
+ 1 - 1
docs/network.html


Разлика између датотеке није приказан због своје велике величине
+ 0 - 0
docs/userland.html


+ 40 - 0
testdata/browser/compat/072-styled-controls.html

@@ -0,0 +1,40 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+<meta charset="utf-8">
+<title>072 author-styled form controls</title>
+<style>
+  body { background: #ffffff; color: #202020; font-family: sans-serif;
+         margin: 12px; font-size: 14px; }
+  .pane { float: left; width: 330px; margin-right: 20px; }
+  /* A: real controls styled like google.com's search page */
+  .A input[type="submit"] { background-color: #e8eaed; border: 1px solid #e8eaed;
+         border-radius: 8px; color: #3c4043; padding: 0 16px; height: 36px;
+         margin: 11px 4px; font-size: 14px; }
+  .A .box, .B .box { border: 1px solid #9aa0a6; border-radius: 22px;
+         height: 44px; background: #ffffff; }
+  .A textarea { width: 100%; background-color: transparent; border: none;
+         padding: 0; margin: 0; resize: none; font-size: 16px; }
+  /* B: the same look built from plain boxes */
+  .B .btn { display: inline-block; background: #e8eaed; border: 1px solid #e8eaed;
+         border-radius: 8px; color: #3c4043; padding: 9px 16px;
+         margin: 11px 4px; }
+  /* Only for forced-colors (high contrast): must not apply here. */
+  @media (forced-colors: active) { .A input[type="submit"] { border: 3px solid #ff0000; } }
+</style>
+</head>
+<body>
+<h1>072 &mdash; author-styled controls</h1>
+<p>A control with author background/border/radius is painted with that
+   style (not the dark UI theme); a transparent borderless textarea is
+   invisible inside its rounded box.  A and B must look alike.</p>
+<div class="pane A">
+  <div class="box"><textarea rows="1"></textarea></div>
+  <center><input type="submit" value="Search"><input type="submit" value="Lucky"></center>
+</div>
+<div class="pane B">
+  <div class="box"></div>
+  <center><span class="btn">Search</span><span class="btn">Lucky</span></center>
+</div>
+</body>
+</html>

+ 21 - 0
testdata/browser/compat/073-noscript.html

@@ -0,0 +1,21 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+<meta charset="utf-8">
+<title>073 noscript with scripting enabled</title>
+<style>
+  body { background: #ffffff; color: #202020; font-family: sans-serif;
+         margin: 12px; font-size: 18px; }
+  #result { background: #c8f0c8; color: #000000; padding: 8px; margin-top: 12px; }
+</style>
+</head>
+<body>
+<h1>073 &mdash; noscript</h1>
+<p>Scripting is on, so <code>&lt;noscript&gt;</code> content is raw text:
+   its style and meta refresh must not apply (google.com hides every div
+   this way).  The green NOSCRIPT-OK line must be visible and no
+   "NOSCRIPT-FAIL" text may appear.</p>
+<noscript><meta http-equiv="refresh" content="0;url=about:blank"><style>div,p{display:none}</style><span>NOSCRIPT-FAIL</span></noscript>
+<div id="result">NOSCRIPT-OK</div>
+</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-071 and 030a pass.  036a needs the POST echo server:
+Status: 010-073 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

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

@@ -94,6 +94,8 @@ a { color: #0645ad; }
 <tr><td>069</td><td><a href="069-inline-flex-tail.html">inline-flex tail</a></td><td>inline-flex around text stays in the line</td><td class="pass">PASS</td></tr>
 <tr><td>070</td><td><a href="070-many-absolute.html">many absolute boxes</a></td><td>more than 16 absolute boxes keep their containing block</td><td class="pass">PASS</td></tr>
 <tr><td>071</td><td><a href="071-modern-js.html">modern JavaScript</a></td><td>classes, private fields, arrows, templates, destructuring, Map/Set, optional chaining, async/await</td><td class="pass">PASS</td></tr>
+<tr><td>072</td><td><a href="072-styled-controls.html">author-styled controls</a></td><td>inputs/textarea with author background, border, radius, padding and height; forced-colors media is false</td><td class="pass">PASS</td></tr>
+<tr><td>073</td><td><a href="073-noscript.html">noscript</a></td><td>with scripting on, noscript content (style, meta refresh) is inert</td><td class="pass">PASS</td></tr>
 </table>
 </body>
 </html>

+ 217 - 44
user/apps/browser/browser.c

@@ -74,7 +74,7 @@ static unsigned int decode_arena_size;
 #define SCRIPT_CACHE_PREFIX   "bjs-"
 #define BR_MAX_SHEETS   6
 #define BR_HISTORY      16
-#define BR_URL_MAX      512
+#define BR_URL_MAX      4096   /* = UHTTP_PATH_MAX: google.com's JS URL is ~3.7 KB */
 #define BR_STATUS_MAX   200
 
 #define BR_IMG_RGB565(r, g, b) \
@@ -308,6 +308,10 @@ static int s_eq(const char *a, const char *b);
 static void form_key(int k);
 static void form_click(unsigned int node);
 static void style_for_node(unsigned int node, struct br_style *out);
+static int form_author_styled(const struct br_style *st);
+static int css_radius(const struct br_style *st, int corner, int w, int h);
+static void form_paint_author(struct ngui *ui, struct ngui_rect box,
+			      const struct br_style *st, int focused);
 
 static int form_disabled(unsigned int node)
 {
@@ -2708,7 +2712,7 @@ static int path_dir(const char *path, char *out, unsigned int cap)
 static int resolve_link(const char *base, const char *href, char *out,
 			unsigned int cap)
 {
-	char joined[BR_URL_MAX];
+	static char joined[BR_URL_MAX];   /* leaf: off the stack */
 
 	if (!href || !href[0] || href[0] == '#')
 		return -1;
@@ -2743,7 +2747,7 @@ static int resolve_link(const char *base, const char *href, char *out,
 		return 0;
 	}
 	{
-		char dir[BR_URL_MAX];
+		static char dir[BR_URL_MAX];
 		unsigned int n = 0;
 
 		if (s_eq(base, "about:home"))
@@ -3195,7 +3199,7 @@ static int fetch_worker_submit_req(struct fetch_worker *w, const char *url,
 				   unsigned int dec_h, char *err,
 				   unsigned int errcap)
 {
-	static char req[1024];
+	static char req[BR_URL_MAX + 256];
 	unsigned int n = 0;
 
 	fetch_seq++;
@@ -3270,7 +3274,7 @@ static int fetch_worker_submit_req(struct fetch_worker *w, const char *url,
 static int fetch_worker_read_meta(struct fetch_worker *w, char *err,
 				  unsigned int errcap)
 {
-	static char meta[1024];
+	static char meta[BR_URL_MAX + 1024];
 	char *p;
 	int rn, mseq;
 
@@ -6274,6 +6278,35 @@ static void flush_line(struct lay *l)
 						}
 						tl = fs->len;
 					}
+					struct br_style fst;
+					int author, tx = x + 6, pr = 6;
+
+					style_for_node(node, &fst);
+					author = form_author_styled(&fst);
+					if (author) {
+						/* The page styled the control:
+						 * its background, border, radius
+						 * and text colour. */
+						form_paint_author(l->ui, box, &fst,
+								  focused);
+						tx = x + fst.border_w[3] +
+						     mp_px(&fst, 7, w);
+						pr = fst.border_w[1] +
+						     mp_px(&fst, 5, w);
+						if (tx < x + 2 && !editable)
+							tx = x + 2;
+						if (!disabled)
+							fg = editable && fs &&
+							     !fs->len ?
+							     0x8410 : fst.color;
+						if (!editable) {
+							int tw0 = (int)
+							    run_text_width(l->ui,
+								r, txt, tl);
+
+							tx = x + (w - tw0) / 2;
+						}
+					} else {
 					/* The box is drawn in theme colours, so
 					 * the text is too: the page's CSS colour
 					 * (dark on a light page) would vanish on
@@ -6286,21 +6319,24 @@ static void flush_line(struct lay *l)
 					ngui_frame(l->ui, box,
 						   focused ? l->ui->theme.accent :
 						   l->ui->theme.border);
+					}
 					/* A value wider than the field shows its
 					 * tail (where typing happens). */
-					if (editable && fs && fs->len && w > 12) {
+					if (editable && fs && fs->len &&
+					    w > (tx - x) + pr) {
 						int tw = (int)run_text_width(l->ui,
 							r, txt, tl);
+						int room = w - (tx - x) - pr;
 
-						if (tw > w - 12)
-							scroll = tw - (w - 12);
+						if (tw > room)
+							scroll = tw - room;
 					}
 					ngui_push_clip(l->ui, (struct ngui_rect){
 						x + 1, ry + 1,
 						w > 2 ? w - 2 : 1,
 						hh > 2 ? hh - 2 : 1 });
 					ngui_text_px_face(l->ui, run_face(r),
-							  x + 6 - scroll,
+							  tx - scroll,
 							  ry + (hh - r->font_px) / 2 - 1,
 							  txt, tl, fg, r->font_px,
 							  r->bold, r->italic, r->mono);
@@ -6314,7 +6350,7 @@ static void flush_line(struct lay *l)
 								fs->caret : fs->len);
 						ngui_fill_rect(l->ui,
 							(struct ngui_rect){
-								x + 6 + cw - scroll,
+								tx + cw - scroll,
 								ry + 4, 1,
 								hh > 8 ? hh - 8 : 1
 							},
@@ -6994,6 +7030,22 @@ static void list_marker_text(char *m, unsigned int cap, int style, int idx)
 	m[n] = '\0';
 }
 
+/* A control the page styled itself (background, border or radius in author
+ * CSS -- `background:transparent;border:none` counts) is painted with that
+ * style, sized from its padding/height and keeps the page's text colour.
+ * Unstyled controls keep the ngui theme look. */
+static int form_author_styled(const struct br_style *st)
+{
+	int i;
+
+	if (st->bg_set)
+		return 1;
+	for (i = 0; i < 4; i++)
+		if (st->border_w[i] || st->radius[i])
+			return 1;
+	return 0;
+}
+
 /* Set by the layout when the control is stretched to its line: a flex item
  * (its box width was assigned by the flex row) or a child of a flex column,
  * whose default align-items: stretch makes inputs full width. */
@@ -7009,7 +7061,9 @@ static void add_form_run(struct lay *l, unsigned int node,
 	struct lay_run *r;
 	int kind = form_kind_of(node);
 	int disabled = form_disabled(node);
-	int tw, w = 120, h = 20, i;
+	int author = form_author_styled(st);
+	int tw, w = 120, h = 20, i, line_w, pad_x, pad_y;
+	int ml = 0, mr = 0, mt = 0, mb = 0;
 
 	if (!fs)
 		return;
@@ -7047,34 +7101,87 @@ static void add_form_run(struct lay *l, unsigned int node,
 		}
 	}
 	tw = (int)face_text_width(l->ui, st, text, s_len(text));
+	line_w = l->line_right - l->line_left;
+	pad_x = mp_px(st, 7, line_w) + mp_px(st, 5, line_w) +
+		st->border_w[1] + st->border_w[3];
+	pad_y = mp_px(st, 4, line_w) + mp_px(st, 6, line_w) +
+		st->border_w[0] + st->border_w[2];
 	if (kind == FORM_BUTTON || kind == FORM_SUBMIT || kind == FORM_RESET) {
-		w = tw + 18;
-		if (w < 64)
-			w = 64;
-		h = 22;
-	} else if (kind == FORM_TEXT || kind == FORM_PASSWORD) {
-		int line_w = l->line_right - l->line_left;
-
-		if (st->width_kind == 1)
-			w = st->width;
-		else if (st->width_kind == 2)
-			w = css_size(st->width_kind, st->width, line_w);
-		else if (form_fill_line || st->display == BR_DISPLAY_BLOCK)
+		/* Buttons are border-box in every UA stylesheet: an
+		 * explicit width/height is the whole box. */
+		if (author || pad_x) {
+			w = tw + pad_x;
+		} else {
+			w = tw + 18;
+			if (w < 64)
+				w = 64;
+		}
+		if (st->width_kind)
+			w = style_width_px(st, line_w);
+		if (st->min_width_kind == 1 && w < (int)st->min_width)
+			w = st->min_width;
+		if (st->height_kind == 1)
+			h = st->height;
+		else if (author)
+			h = st->font_px + 6 + pad_y;
+		else
+			h = 22;
+	} else if (kind == FORM_TEXT || kind == FORM_PASSWORD ||
+		   kind == FORM_TEXTAREA) {
+		int fill = form_fill_line || st->display == BR_DISPLAY_BLOCK ||
+			   st->display == BR_DISPLAY_FLEX;
+		int boxed = st->box_sizing ? 0 : pad_x;
+
+		if (st->width_kind)
+			w = style_width_px(st, line_w) + boxed;
+		else if (fill)
 			w = line_w - (l->line_x - l->line_left);
 		else
-			w = 120;
-		/* Taller fields for large text (min-height/padding on login
-		 * pages): keep the box around the glyphs. */
-		if (st->font_px + 8 > h)
+			w = kind == FORM_TEXTAREA ? 180 : 120;
+		if (kind == FORM_TEXTAREA) {
+			const char *ra = br_find_attr(&doc, node, "rows");
+			int rows = 0;
+			int lh = st->line_h_px ? st->line_h_px :
+				 st->font_px * 5 / 4;
+
+			while (ra && *ra >= '0' && *ra <= '9')
+				rows = rows * 10 + (*ra++ - '0');
+			if (rows < 1 || rows > 40)
+				rows = 2;
+			h = author ? rows * lh + pad_y : 40;
+		} else if (author) {
+			h = st->font_px + 8 + pad_y;
+		} else if (st->font_px + 8 > h) {
+			/* Taller fields for large text (min-height/padding
+			 * on login pages): keep the box around the glyphs. */
 			h = st->font_px + 8;
+		}
+		if (st->height_kind == 1)
+			h = st->height + (st->box_sizing ? 0 : pad_y);
+		if (st->min_height_kind == 1 && h < (int)st->min_height)
+			h = st->min_height;
 	} else if (kind == FORM_SELECT) {
 		w = st->width_kind == 1 ? st->width : 120;
 	}
-	if (w > l->line_right - l->line_left)
-		w = l->line_right - l->line_left;
+	if (author) {
+		/* Inline margins (Google's `margin:11px 4px` between its
+		 * two submit buttons). */
+		ml = mp_px(st, 3, line_w);
+		mr = mp_px(st, 1, line_w);
+		mt = mp_px(st, 0, line_w);
+		mb = mp_px(st, 2, line_w);
+		if (ml < 0 || ml > 64) ml = 0;
+		if (mr < 0 || mr > 64) mr = 0;
+		if (mt < 0 || mt > 64) mt = 0;
+		if (mb < 0 || mb > 64) mb = 0;
+	}
+	if (w > line_w - ml - mr)
+		w = line_w - ml - mr;
 	if (w < 8)
 		w = 8;
-	if (l->line_x + w > l->line_right &&
+	if (h > 400)
+		h = 400;
+	if (l->line_x + ml + w > l->line_right &&
 	    (l->nruns > 0 || l->line_x > l->line_left))
 		flush_line(l);
 	if (l->nruns >= 96)
@@ -7084,12 +7191,13 @@ static void add_form_run(struct lay *l, unsigned int node,
 		l->line_h = 0;
 		start_line(l, st);
 	}
+	l->line_x += ml;
 	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->dy = 0;
+	r->dy = (signed short)mt;
 	r->has_lit = 1;
 	for (i = 0; i + 1 < (int)sizeof(r->lit) && text[i]; i++)
 		r->lit[i] = text[i];
@@ -7109,15 +7217,60 @@ static void add_form_run(struct lay *l, unsigned int node,
 	r->form_disabled = (unsigned char)disabled;
 	if (node < BR_MAX_NODES) {
 		layout_boxes[node].x = l->line_x;
-		layout_boxes[node].y = l->line_y;
+		layout_boxes[node].y = l->line_y + mt;
 		layout_boxes[node].w = w;
 		layout_boxes[node].h = h;
 		layout_boxes[node].valid = 1;
 	}
 	l->line_x += w;
 	l->run_x = l->line_x;
-	if (l->line_h < h)
-		l->line_h = h;
+	l->line_x += mr;
+	if (l->line_h < h + mt + mb)
+		l->line_h = h + mt + mb;
+}
+
+/* Background, border and corner radius of an author-styled control, the
+ * same decoration rules as a block box. */
+static void form_paint_author(struct ngui *ui, struct ngui_rect box,
+			      const struct br_style *st, int focused)
+{
+	int rtl = css_radius(st, 0, box.w, box.h);
+	int rtr = css_radius(st, 1, box.w, box.h);
+	int rbr = css_radius(st, 2, box.w, box.h);
+	int rbl = css_radius(st, 3, box.w, box.h);
+	int bw = st->border_t[0] ? 0 : st->border_w[0];
+
+	(void)focused;
+	if (box.w <= 0 || box.h <= 0)
+		return;
+	if (rtl || rtr || rbr || rbl) {
+		if (bw > 0 && st->has_bg && st->border_c[0] != st->bg &&
+		    box.w > bw * 2 && box.h > bw * 2) {
+			struct ngui_rect in = { box.x + bw, box.y + bw,
+						box.w - bw * 2,
+						box.h - bw * 2 };
+
+			ngui_fill_round_rect(ui, box, rtl, rtr, rbr, rbl,
+					     st->border_c[0]);
+			ngui_fill_round_rect(ui, in,
+					     rtl > bw ? rtl - bw : 0,
+					     rtr > bw ? rtr - bw : 0,
+					     rbr > bw ? rbr - bw : 0,
+					     rbl > bw ? rbl - bw : 0, st->bg);
+		} else if (st->has_bg) {
+			ngui_fill_round_rect(ui, box, rtl, rtr, rbr, rbl,
+					     st->bg);
+		} else if (bw > 0) {
+			ngui_frame_round(ui, box, rtl, rtr, rbr, rbl, bw,
+					 st->border_c[0]);
+		}
+		return;
+	}
+	if (st->has_bg)
+		ngui_fill_rect(ui, box, st->bg);
+	if (st->border_w[0] || st->border_w[1] || st->border_w[2] ||
+	    st->border_w[3])
+		draw_border_box(ui, box, st);
 }
 
 /* A poster wrapper is absolutely positioned over the media slot; the
@@ -8342,8 +8495,12 @@ static void layout_block(struct lay *l, unsigned int node,
 			 css_size(st->max_width_kind, st->max_width, cbw);
 		int max_box = st->box_sizing ? mw : mw + deco_w;
 
-		if (content_w + deco_w > max_box)
+		/* A clamped auto width is used as the width, so auto
+		 * margins share the rest (Google's 688 px search box). */
+		if (content_w + deco_w > max_box) {
 			content_w = max_box - deco_w;
+			definite_w = 1;
+		}
 	}
 	if (st->min_width_kind) {
 		int mw = st->min_width_kind == 3 ?
@@ -8963,11 +9120,14 @@ static unsigned int layout_float_group(struct lay *l, unsigned int first,
 		} else {
 			int base = row_right - row_left;
 
+			/* Shrink-to-fit outer width: borders too (Google's
+			 * 1px-bordered "Anmelden" pill wrapped otherwise). */
 			colw = intrinsic_width(l->ui, n, &cs, 0, base) +
 			       mp_px(&cs, 7, base) +
 			       mp_px(&cs, 5, base) +
 			       mp_px(&cs, 3, base) +
-			       mp_px(&cs, 1, base);
+			       mp_px(&cs, 1, base) +
+			       cs.border_w[1] + cs.border_w[3];
 			if (colw < 8)
 				colw = 8;
 		}
@@ -9301,7 +9461,7 @@ static void layout_flex_children(struct lay *l, unsigned int parent,
 	int idx, row_top;
 	unsigned char row_align = l->align;
 
-	if (avail < 160 || depth > 48) {
+	if (avail < 8 || depth > 48) {
 		layout_children(l, parent, pst, depth, link);
 		return;
 	}
@@ -9338,6 +9498,14 @@ static void layout_flex_children(struct lay *l, unsigned int parent,
 			fixed += flex_item_width(l, c, &cs, avail);
 		nitem++;
 	}
+	/* A narrow container (an icon row sized to its content, Google's
+	 * mic + lens buttons) is still a row when its items fit; only a
+	 * narrow one that would overflow or squeeze growing items falls
+	 * back to block flow. */
+	if (avail < 160 && (grow_count || fixed > avail)) {
+		layout_children(l, parent, pst, depth, link);
+		return;
+	}
 	grow_w = grow_count ? (avail - fixed) / grow_count : 0;
 	if (grow_w < 96)
 		grow_w = 96;
@@ -9416,12 +9584,17 @@ static void layout_flex_children(struct lay *l, unsigned int parent,
 			br_style_for(&doc, node, pst, &cs);
 			cs.width_kind = 0;
 			cs.max_width_kind = 0;
-			if (l->draw && pst->align_items &&
-			    row_h > block_h[node]) {
-				if (pst->align_items == 1)
-					yoff = (row_h - block_h[node]) / 2;
-				else if (pst->align_items == 2)
-					yoff = row_h - block_h[node];
+			{
+				int ai = cs.align_self ? cs.align_self - 1 :
+					 pst->align_items;
+
+				if (l->draw && ai && row_h > block_h[node]) {
+					if (ai == 1)
+						yoff = (row_h -
+							block_h[node]) / 2;
+					else if (ai == 2)
+						yoff = row_h - block_h[node];
+				}
 			}
 			l->left = x;
 			l->right = x + it[start + k].w;
@@ -11031,7 +11204,7 @@ static void draw_page(struct ngui_rect page)
 
 static void draw_status(struct ngui_rect r)
 {
-	char msg[BR_URL_MAX + 32];
+	static char msg[BR_URL_MAX + 32];   /* leaf: off the 128 KB stack */
 	unsigned int n = 0;
 	int hover = page_hover_node();
 	unsigned short color;

+ 114 - 11
user/apps/browser/browser_html.c

@@ -409,7 +409,8 @@ static void decode_entity(const char *s, unsigned int len, unsigned int *pos,
 	if (ok && code) {
 		if (code == 0x00A0)
 			emit(out, cap, n, ' ');
-		else if (code == 0x2013 || code == 0x2014)
+		else if ((code >= 0x2010 && code <= 0x2015) ||
+			 code == 0x2212)          /* hyphens, dashes */
 			emit(out, cap, n, '-');
 		else if (code == 0x2018 || code == 0x2019)
 			emit(out, cap, n, '\'');
@@ -484,7 +485,7 @@ static unsigned int decode_text(const char *s, unsigned int len, char *out,
 					  (((unsigned char)s[i + 1] & 0x3F) << 6) |
 					  ((unsigned char)s[i + 2] & 0x3F);
 			i += 3;
-			if (cp == 0x2013 || cp == 0x2014) {
+			if ((cp >= 0x2010 && cp <= 0x2015) || cp == 0x2212) {
 				emit(out, cap, &n, '-');
 			} else if (cp == 0x2018 || cp == 0x2019) {
 				emit(out, cap, &n, '\'');
@@ -1653,9 +1654,9 @@ static void attr_note_known(struct br_doc *d, struct br_node *n,
 		n->style_off = len ? store_attr(d, value, len,
 						       BR_STYLE_ATTR_MAX) : 0;
 	else if (same_string(name, "href"))
-		n->href_off = len ? store_attr(d, value, len, 480) : 0;
+		n->href_off = len ? store_attr(d, value, len, BR_URL_ATTR_MAX) : 0;
 	else if (same_string(name, "src"))
-		n->src_off = len ? store_attr(d, value, len, 400) : 0;
+		n->src_off = len ? store_attr(d, value, len, BR_URL_ATTR_MAX) : 0;
 	else if (same_string(name, "alt"))
 		n->alt_off = len ? store_attr(d, value, len, 120) : 0;
 	else if (same_string(name, "rel"))
@@ -2204,7 +2205,8 @@ static void parse_attrs(struct br_doc *d, struct br_node *n,
 		}
 		note_attr_flag(n, name);
 		if (str_eq(name, "href"))
-			n->href_off = store_attr(d, s + vstart, vlen, 480);
+			n->href_off = store_attr(d, s + vstart, vlen,
+						 BR_URL_ATTR_MAX);
 		else if (str_eq(name, "class"))
 			n->class_off = store_attr(d, s + vstart, vlen,
 						  BR_CLASS_MAX);
@@ -2214,7 +2216,8 @@ static void parse_attrs(struct br_doc *d, struct br_node *n,
 			n->style_off = store_attr(d, s + vstart, vlen,
 						  BR_STYLE_ATTR_MAX);
 		else if (str_eq(name, "src"))
-			n->src_off = store_attr(d, s + vstart, vlen, 400);
+			n->src_off = store_attr(d, s + vstart, vlen,
+						BR_URL_ATTR_MAX);
 		else if (str_eq(name, "alt"))
 			n->alt_off = store_attr(d, s + vstart, vlen, 120);
 		else if (str_eq(name, "color"))
@@ -2373,7 +2376,8 @@ static int in_svg(const struct br_doc *d, unsigned int node)
 }
 
 enum {
-	PROP_COLOR, PROP_BG, PROP_BG_IMAGE, PROP_BG_REPEAT,
+	PROP_COLOR, PROP_BG, PROP_BG_NONE, PROP_ALIGN_SELF, PROP_BG_IMAGE,
+	PROP_BG_REPEAT,
 	PROP_BG_POS_X_KIND, PROP_BG_POS_X, PROP_BG_POS_Y_KIND, PROP_BG_POS_Y,
 	PROP_BG_SIZE_KIND, PROP_BG_SIZE_W, PROP_BG_SIZE_H,
 	PROP_FONT_PX, PROP_FONT_UNIT,
@@ -4551,7 +4555,7 @@ static void content_put(char *out, unsigned int *n, unsigned int cap,
 {
 	const char *sub = 0;
 
-	if (cp == 0x2013 || cp == 0x2014 || cp == 0x2212)
+	if ((cp >= 0x2010 && cp <= 0x2015) || cp == 0x2212)
 		sub = "-";
 	else if (cp == 0x2018 || cp == 0x2019 || cp == 0x201A)
 		sub = "'";
@@ -4844,7 +4848,14 @@ static void parse_decls(struct br_doc *d, const char *s,
 					decl_add(out, nout, PROP_BG_REPEAT, 3,
 						 important);
 			}
-			if (parse_color(s + vstart, vend - vstart, &c))
+			/* `transparent`/`none` are real values: they must
+			 * beat a lower-specificity colour (and tell form
+			 * controls the author styled them). */
+			if (color_is_transparent(s + vstart, vend - vstart) ||
+			    (vend - vstart == 4 &&
+			     ci_eq_n(s + vstart, "none", 4)))
+				decl_add(out, nout, PROP_BG_NONE, 1, important);
+			else if (parse_color(s + vstart, vend - vstart, &c))
 				decl_add(out, nout, PROP_BG, c, important);
 			else if (is_bg &&
 				 find_color_last(s + vstart, vend - vstart, &c))
@@ -5033,6 +5044,22 @@ static void parse_decls(struct br_doc *d, const char *s,
 						 "end"))
 				j = 2;
 			decl_add(out, nout, PROP_JUSTIFY, j, important);
+		} else if (str_eq(prop, "align-self")) {
+			/* 0 auto (the container's align-items), else
+			 * align-items + 1. */
+			int a = 1;
+
+			if (contains_ci_len(s + vstart, vend - vstart, "auto"))
+				a = 0;
+			else if (contains_ci_len(s + vstart, vend - vstart,
+						 "center"))
+				a = 2;
+			else if (contains_ci_len(s + vstart, vend - vstart,
+						 "flex-end") ||
+				 contains_ci_len(s + vstart, vend - vstart,
+						 "end"))
+				a = 3;
+			decl_add(out, nout, PROP_ALIGN_SELF, a, important);
 		} else if (str_eq(prop, "align-items")) {
 			int a = 0;
 
@@ -6055,6 +6082,41 @@ static int media_feature_matches(const char *s, unsigned int len)
 		 * flipping to their light media override. */
 		return 0;
 	}
+	{
+		/* Environment features with a known answer: a mouse-driven
+		 * screen with normal contrast and no forced colours.  Google
+		 * puts `border:1px solid CanvasText` on its buttons inside
+		 * `(forced-colors:active)`. */
+		static const struct { const char *name, *yes; } env[] = {
+			{ "forced-colors", "none" },
+			{ "-ms-high-contrast", "" },
+			{ "prefers-contrast", "no-preference" },
+			{ "inverted-colors", "none" },
+			{ "any-hover", "hover" },
+			{ "hover", "hover" },
+			{ "any-pointer", "fine" },
+			{ "pointer", "fine" },
+		};
+		unsigned int k;
+
+		for (k = 0; k < sizeof(env) / sizeof(env[0]); k++) {
+			unsigned int nl = s_len(env[k].name), j;
+
+			if (len < nl || !ci_eq_n(s, env[k].name, nl) ||
+			    (len > nl && s[nl] != ':' && !is_space(s[nl])))
+				continue;
+			for (j = nl; j < len && s[j] != ':'; j++)
+				;
+			if (j >= len)           /* boolean form: (hover) */
+				return env[k].yes[0] &&
+				       !ci_eq_n(env[k].yes, "none", 4);
+			j++;
+			while (j < len && is_space(s[j]))
+				j++;
+			return env[k].yes[0] && len - j == s_len(env[k].yes) &&
+			       ci_eq_n(s + j, env[k].yes, len - j);
+		}
+	}
 	if (len >= 9 && ci_eq_n(s, "min-width", 9)) {
 		for (i = 9; i < len && s[i] != ':'; i++)
 			;
@@ -7563,6 +7625,11 @@ static void apply_decl(struct br_style *st, const struct br_decl *dcl)
 	case PROP_BG:
 		st->bg = (unsigned short)dcl->val;
 		st->has_bg = 1;
+		st->bg_set = 1;
+		break;
+	case PROP_BG_NONE:
+		st->has_bg = 0;
+		st->bg_set = 1;
 		break;
 	case PROP_BG_IMAGE:
 		st->bg_image = (unsigned short)dcl->val;
@@ -7840,6 +7907,9 @@ static void apply_decl(struct br_style *st, const struct br_decl *dcl)
 	case PROP_ALIGN_ITEMS:
 		st->align_items = (unsigned char)dcl->val;
 		break;
+	case PROP_ALIGN_SELF:
+		st->align_self = (unsigned char)dcl->val;
+		break;
 	case PROP_GRID_NCOLS:
 		st->grid_ncols = (unsigned char)dcl->val;
 		break;
@@ -7930,6 +8000,9 @@ static void cascade_decl(struct br_style *st, const struct br_decl *dcl,
 
 	if (p >= PROP_COUNT)
 		return;
+	/* A transparent background competes with a colour for one slot. */
+	if (p == PROP_BG_NONE)
+		p = PROP_BG;
 	if (dcl->important) {
 		if (spec >= best_imp[p]) {
 			apply_decl(st, dcl);
@@ -7955,6 +8028,7 @@ void br_style_for(struct br_doc *d, unsigned int node,
 
 	*out = *parent;
 	out->has_bg = 0;
+	out->bg_set = 0;
 	out->bg_image = 0;
 	out->bg_repeat = 0;
 	out->bg_pos_x_kind = out->bg_pos_y_kind = 0;
@@ -7989,7 +8063,7 @@ void br_style_for(struct br_doc *d, unsigned int node,
 		out->mp_calc_px[i] = 0;
 	}
 	out->flex_grow = out->flex_col = out->flex_wrap = 0;
-	out->justify = out->align_items = 0;
+	out->justify = out->align_items = out->align_self = 0;
 	out->grid_ncols = out->grid_gap = out->grid_slot = 0;
 	out->grid_auto = 0;
 	out->aspect_w = out->aspect_h = 0;
@@ -8028,6 +8102,7 @@ void br_style_for(struct br_doc *d, unsigned int node,
 	case BR_TAG_BASE:
 	case BR_TAG_SCRIPT:
 	case BR_TAG_STYLE:
+	case BR_TAG_NOSCRIPT:                   /* scripting is always on */
 	case BR_TAG_TEMPLATE:                   /* inert until cloned by script */
 		out->display = BR_DISPLAY_NONE;
 		break;
@@ -8421,7 +8496,7 @@ static unsigned int script_src_attr(struct br_doc *d, const char *s,
 			ve = i;
 		}
 		if (ne > ns && ci_eq_n(s + ns, "src", ne - ns))
-			return store_attr(d, s + vs, ve - vs, 400);
+			return store_attr(d, s + vs, ve - vs, BR_URL_ATTR_MAX);
 	}
 	return 0;
 }
@@ -8679,6 +8754,34 @@ int br_parse(struct br_doc *d, const char *html, unsigned int len)
 					i++;
 				continue;
 			}
+			/* Scripting is always enabled, so <noscript> is a
+			 * raw-text element (HTML "in head/in body, scripting
+			 * flag set"): its markup must not reach the DOM or the
+			 * cascade.  google.com puts a meta refresh and
+			 * `table,div,span,p{display:none}` in one, which hid
+			 * the whole page and left only the "click here" link. */
+			if (tag == BR_TAG_NOSCRIPT && !selfclose) {
+				int p = find_ci(html, len, "</noscript", 10, i);
+				unsigned int end = p >= 0 ? (unsigned int)p : len;
+				unsigned int idx;
+
+				idx = node_append(d, stack[sp], BR_NODE_ELEM,
+						  (unsigned char)tag);
+				if (idx) {
+					parse_attrs(d, &d->nodes[idx],
+						    html + attr_start,
+						    attr_end - attr_start);
+					if (end > i)
+						append_raw_text(d, idx, html + i,
+								end - i);
+				}
+				i = p >= 0 ? (unsigned int)p + 10 : len;
+				while (i < len && html[i] != '>')
+					i++;
+				if (i < len)
+					i++;
+				continue;
+			}
 			if (stack_has_svg(d, stack, sp) &&
 			    (tag == BR_TAG_TITLE ||
 			     (tag == BR_TAG_UNKNOWN &&

+ 6 - 1
user/apps/browser/browser_html.h

@@ -9,7 +9,7 @@
 #define BR_MAX_NODES     16384
 #define BR_TEXT_SIZE     524288
 #define BR_ATTR_SIZE     4194304
-#define BR_CSS_SIZE      65536
+#define BR_CSS_SIZE      262144  /* inline <style> text; google.com has ~94 KB */
 #define BR_MAX_RULES     8192
 #define BR_RULE_FALLBACK 256
 #define BR_MAX_FACES     8
@@ -22,6 +22,9 @@
 #define BR_DECLS         48
 #define BR_TITLE_MAX     96
 #define BR_MAX_SCRIPTS   32
+/* href/src values: google.com links its main script with a ~3.7 KB URL.
+ * Matches BR_URL_MAX in browser.c and UHTTP_PATH_MAX. */
+#define BR_URL_ATTR_MAX  4095
 
 /* Node types. */
 #define BR_NODE_TEXT     0
@@ -118,6 +121,7 @@ struct br_style {
 	unsigned char bg_size_kind; /* 0 auto/stretch, 1 px, 2 percent, 3 cover, 4 contain */
 	unsigned short bg_size_w, bg_size_h;
 	unsigned char has_bg;
+	unsigned char bg_set;       /* author set background (colour or transparent) */
 	unsigned char font_px;      /* 8..48 */
 	unsigned short font_raw;    /* font-size before unit resolution */
 	unsigned char font_unit;    /* 0 inherited, 1 px, 2 em, 3 rem, 4 % */
@@ -138,6 +142,7 @@ struct br_style {
 	unsigned char flex_wrap;    /* flex-wrap: wrap */
 	unsigned char justify;      /* 0 start, 1 center, 2 end, 3 between, 4 around */
 	unsigned char align_items;  /* 0 start/stretch, 1 center, 2 end */
+	unsigned char align_self;   /* 0 auto, else align_items + 1 */
 	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 */

+ 2 - 1
user/apps/browser/js_browser.c

@@ -1560,7 +1560,8 @@ static void serialize_node(struct sbuf *b, unsigned int node, int depth)
 		int raw = par < D->nnode &&
 			  D->nodes[par].type == BR_NODE_ELEM &&
 			  (D->nodes[par].tag == BR_TAG_SCRIPT ||
-			   D->nodes[par].tag == BR_TAG_STYLE);
+			   D->nodes[par].tag == BR_TAG_STYLE ||
+			   D->nodes[par].tag == BR_TAG_NOSCRIPT);
 
 		if (raw)
 			sb_put(b, D->text + n->text_off, n->text_len);

+ 4 - 4
user/apps/curl/ucmd_curl.c

@@ -241,7 +241,7 @@ static void fetch_decode(const unsigned char *data, unsigned int len,
 static void fetch_fail(unsigned int status, int err, const char *ctype,
 		       const char *enc, const char *final)
 {
-	char meta[768];
+	static char meta[UHTTP_PATH_MAX + UHTTP_HOST_MAX + 256];
 	unsigned int n = 0;
 
 	app_dec(meta, &n, status, sizeof(meta)); app_ch(meta, &n, '\n', sizeof(meta));
@@ -351,7 +351,7 @@ static void write_meta(unsigned int seq, int with_seq, struct uhttp *h,
 		       int err, unsigned int body_len, unsigned int body_trunc,
 		       const struct fetch_times *t, const struct fetch_px *px)
 {
-	char meta[1024];
+	static char meta[UHTTP_PATH_MAX + UHTTP_HOST_MAX + 1024];
 	unsigned int n = 0;
 
 	if (with_seq) {
@@ -455,7 +455,7 @@ static void helper_fetch(struct uhttp *h, const char *url, unsigned int cap,
 static void fetch_once(void)
 {
 	static struct uhttp h;
-	char req[768];
+	static char req[UHTTP_PATH_MAX + UHTTP_HOST_MAX + 256];
 	struct fetch_times times;
 
 	fetch_paths_init(0, -1);
@@ -512,7 +512,7 @@ static void fetch_once(void)
 static void fetch_serve(const char *arg)
 {
 	static struct uhttp h;
-	char req[768];
+	static char req[UHTTP_PATH_MAX + UHTTP_HOST_MAX + 256];
 	struct fetch_times times;
 	unsigned char *buf, *post;
 	unsigned int last_seq = 0, idle = 0, session = 0;

+ 7 - 5
user/lib/uhttp/uhttp.c

@@ -180,9 +180,11 @@ static int path_normalize_part(char *path);
 /* Normalize an absolute URL path in place: collapse "//", "." and "..".
  * Only the path: a query or fragment is kept verbatim (it may carry a URL,
  * e.g. ?redirect_uri=https://host/cb).  0 ok, -1 too long. */
+/* Path buffers are static (4 KB each): these helpers are leaves and ring-3
+ * processes are single-threaded, so they need not live on the 128 KB stack. */
 static int path_normalize(char *path)
 {
-	char rest[UHTTP_PATH_MAX];
+	static char rest[UHTTP_PATH_MAX];
 	unsigned int q = 0, i, n;
 	int rv;
 
@@ -207,7 +209,7 @@ static int path_normalize(char *path)
 
 static int path_normalize_part(char *path)
 {
-	char tmp[UHTTP_PATH_MAX];
+	static char tmp[UHTTP_PATH_MAX];
 	unsigned int i, o = 1, len = 0, start, seglen, j;
 	int trailing;
 
@@ -257,7 +259,7 @@ static int path_normalize_part(char *path)
 /* Apply a Location header to the current URL. */
 static int url_apply_location(struct uhttp_url *u, const char *loc)
 {
-	char joined[UHTTP_PATH_MAX];
+	static char joined[UHTTP_PATH_MAX];
 	char scheme[8];
 	unsigned int i, dirlen = 1, n = 0;
 
@@ -270,7 +272,7 @@ static int url_apply_location(struct uhttp_url *u, const char *loc)
 		if (s_len(scheme) + s_len(loc) + 1 > UHTTP_LOC_MAX)
 			return -1;
 		{
-			char full[UHTTP_LOC_MAX];
+			static char full[UHTTP_LOC_MAX];
 			unsigned int k = 0;
 			while (scheme[k]) {
 				full[k] = scheme[k];
@@ -313,7 +315,7 @@ static int url_apply_location(struct uhttp_url *u, const char *loc)
 int uhttp_resolve(const char *base, const char *href, char *out,
 		  unsigned int cap)
 {
-	struct uhttp_url u;
+	static struct uhttp_url u;
 
 	if (!base || !href || !out || cap == 0)
 		return UHTTP_ERR_URL;

+ 4 - 4
user/lib/uhttp/uhttp.h

@@ -15,11 +15,11 @@
 #include "uhttp_cookie.h"
 
 #define UHTTP_HOST_MAX       128
-#define UHTTP_PATH_MAX       1024   /* path + query (OIDC URLs are long) */
-#define UHTTP_LOC_MAX        1280
-#define UHTTP_LINE_MAX       1536   /* Location / Set-Cookie header lines */
+#define UHTTP_PATH_MAX       4096   /* path + query (google.com JS ~3.7 KB) */
+#define UHTTP_LOC_MAX        4352
+#define UHTTP_LINE_MAX       4608   /* Location / Set-Cookie header lines */
 #define UHTTP_READER_MAX     16384
-#define UHTTP_REQ_MAX        4096   /* request line + headers */
+#define UHTTP_REQ_MAX        8192   /* request line + headers */
 #define UHTTP_MAX_REDIRECTS  8
 #define UHTTP_IDLE_TIMEOUT_MS  10000
 /* Backstop only: the idle timeout above catches a stalled peer, so slow but

Неке датотеке нису приказане због велике количине промена