Przeglądaj źródła

browser: hover events and Bootstrap tooltips

- Dispatch mouseover/mouseout (bubbling, with relatedTarget) and
  mouseenter/mouseleave on the ancestors entered/left when the element
  under the pointer changes; jQuery's mouseenter and Bootstrap tooltips
  build on them.
- Geometry reads after a DOM change run a synchronous layout first
  (forced reflow, budgeted to 40 ms per 100 ms); documentElement
  clientWidth/clientHeight report the viewport.
- Absolute/fixed boxes with opacity:0 or visibility:hidden keep a
  measurable box (not painted, not hit-tested); an auto width with one
  horizontal offset is shrink-to-fit; absolute/fixed children no longer
  widen a shrink-to-fit parent or end a float row.
- <a href=""> is a link (hand cursor, click target).
- browser-host: {move:X,Y} key moves the headless pointer for hover tests.
Johannes Zellner 1 dzień temu
rodzic
commit
35d464536c

+ 20 - 2
AGENTS.md

@@ -138,7 +138,8 @@ make clean
   compat ladder without a display; `--keys 'clo{down}{enter}'` types into
   the headless window (100 ms per key from 300 ms after the first frame;
   `{enter} {esc} {tab} {bs} {del} {up} {down} {left} {right} {ctrl-l}
-  {wait}`, and `{click:X,Y}` for a left click at canvas coordinates).  It needs the multilib `lib32-sdl3`,
+  {wait}`, `{click:X,Y}` for a left click at canvas coordinates and
+  `{move:X,Y}` to only move the pointer, for hover).  It needs the multilib `lib32-sdl3`,
   `lib32-wayland` and `lib32-libxkbcommon`; host sockets replace the NebOS TCP
   stack and the kernel/WM paths are not exercised.
 - QEMU guests default to 1 GB (`QEMU_MEM`), the lowmem size (`MM_MAX_PHYS`
@@ -1995,7 +1996,24 @@ it to `0x7E00`.  The kernel region itself only has one wall (`_end` below
   `offsetWidth`/`clientWidth` of an element without a laid-out box report
   the viewport width (Vue apps measure on mount and picked a phone layout
   for 0), and `window` gets a `resize` event after the first layout of a
-  scripted page and whenever the page width changes.  The logged-in
+  scripted page and whenever the page width changes.  A geometry read
+  after a DOM change (`offsetWidth`, `getBoundingClientRect`, ...) runs a
+  synchronous layout first (`js_force_layout()`: measure + render into the
+  page back buffer, at most 40 ms per 100 ms), like a browser's forced
+  reflow; `documentElement.clientWidth/Height` are the viewport.
+  **Hover**: each frame the element under the pointer (`hover_target()`:
+  the innermost box, or the link/control hit inside it) is compared with
+  the last one, and `page_hover_events()` dispatches `mouseout`/
+  `mouseover` (bubbling, with `relatedTarget`) and `mouseleave`/
+  `mouseenter` on the ancestors left/entered (`js_browser_mouse_event()`),
+  which is what jQuery's `mouseenter` and Bootstrap tooltips listen to;
+  there is no `mousemove`.  An absolute/fixed box with `opacity: 0` or
+  `visibility: hidden` keeps its box (laid out, not painted, not
+  hit-tested) so scripts can measure it; in-flow ones are still dropped.
+  An absolute/fixed box with an auto width and one horizontal offset is
+  shrink-to-fit, absolute/fixed children add nothing to a parent's
+  shrink-to-fit width and do not end a float row, and `<a href="">` is a
+  link to the page itself.  The logged-in
   dashboard (sidebar with expandable groups, header, app grid, hash-routed
   views) was verified in QEMU against a local stand-in that proxies the
   public dashboard assets and mocks `/api/v1` and the OIDC endpoints.  The

+ 1 - 1
docs/development.html

@@ -239,7 +239,7 @@
 					<tr><td><code>make test-chat</code></td><td>Host tests (ASan/UBSan) for the chat client's JSON parser, cookie jar and the OIDC login page/reply/config parsers.</td></tr>
 					<tr><td><code>make test-chat-e2e</code></td><td>Boots QEMU with an NE2000 on slirp, starts <code>tools/mock_chat.py</code> and drives <code>chat</code> through QMP: native login, send, live poll, read marker, older paging, browse/join, new DM, saved-session resume and sign-out.  <code>CHAT_E2E=--totp|--consent|--passkey|--wrong</code> runs a login variant.</td></tr>
 					<tr><td><code>make compat-serve</code></td><td>Serve the browser compatibility ladder from <code>testdata/browser/compat/</code> on port 8000 for the board or QEMU guest.</td></tr>
-					<tr><td><code>make browser-host</code></td><td>Build the Linux SDL3 development harness (<code>browser-host</code> and its <code>host-curl</code> helper). It implements the ring-3 <code>SYS_*</code> ABI with host files, BSD sockets, <code>fork/exec</code> and an SDL3 window, so pages render and accept input without QEMU. Run <code>./browser-host [--size WxH] [--root DIR] URL|FILE</code>; <code>--headless --wait 3000 --shot out.ppm</code> writes the canvas without a display, and <code>--keys 'clo{down}{enter}'</code> types into it (one key per 100 ms; <code>{enter}</code>, <code>{esc}</code>, <code>{tab}</code>, <code>{bs}</code>, <code>{del}</code>, arrows, <code>{ctrl-l}</code>, <code>{wait}</code>, and <code>{click:X,Y}</code> for a left click at canvas coordinates). Needs the 32-bit SDL3/Wayland libraries (<code>lib32-sdl3</code>, <code>lib32-wayland</code>, <code>lib32-libxkbcommon</code>).</td></tr>
+					<tr><td><code>make browser-host</code></td><td>Build the Linux SDL3 development harness (<code>browser-host</code> and its <code>host-curl</code> helper). It implements the ring-3 <code>SYS_*</code> ABI with host files, BSD sockets, <code>fork/exec</code> and an SDL3 window, so pages render and accept input without QEMU. Run <code>./browser-host [--size WxH] [--root DIR] URL|FILE</code>; <code>--headless --wait 3000 --shot out.ppm</code> writes the canvas without a display, and <code>--keys 'clo{down}{enter}'</code> types into it (one key per 100 ms; <code>{enter}</code>, <code>{esc}</code>, <code>{tab}</code>, <code>{bs}</code>, <code>{del}</code>, arrows, <code>{ctrl-l}</code>, <code>{wait}</code>, <code>{click:X,Y}</code> for a left click at canvas coordinates, and <code>{move:X,Y}</code> to only move the pointer, for hover). Needs the 32-bit SDL3/Wayland libraries (<code>lib32-sdl3</code>, <code>lib32-wayland</code>, <code>lib32-libxkbcommon</code>).</td></tr>
 					<tr><td><code>make fonts</code></td><td>Regenerate the checked-in Arimo/Liberation Mono subsets with <code>pyftsubset</code>.</td></tr>
 				</tbody>
 			</table>

Plik diff jest za duży
+ 0 - 0
docs/userland.html


+ 2 - 1
host/main.c

@@ -6,7 +6,8 @@
  * --keys types into a headless window, one key every 100 ms from 300 ms
  * after the first frame: plain characters, plus {enter} {esc} {tab} {bs}
  * {del} {up} {down} {left} {right} {ctrl-l}, {wait} (a 1 s pause) and
- * {click:X,Y} (a left click at canvas coordinates X,Y).
+ * {click:X,Y} (a left click at canvas coordinates X,Y) and {move:X,Y}
+ * (move the pointer there without a click, for hover).
  */
 #include <signal.h>
 #include <stdio.h>

+ 10 - 1
host/window_headless.c

@@ -109,7 +109,8 @@ void host_headless_pump(unsigned int timeout_ms)
 }
 
 /* --keys `{click:X,Y}`: the pointer moves there and a left press is
- * queued, its release on the next event poll. */
+ * queued, its release on the next event poll; `{move:X,Y}` only moves
+ * it (hover). */
 static int ptr_x, ptr_y;
 static unsigned int ptr_buttons;
 static int click_pending;       /* 1 press queued, 2 release queued */
@@ -176,6 +177,14 @@ int host_headless_key(void)
 	if (!*key_pos || now < key_due)
 		return 0;
 	code = (unsigned char)*key_pos++;
+	if (code == '{' && !strncmp(key_pos, "move:", 5)) {
+		const char *end = strchr(key_pos, '}');
+
+		sscanf(key_pos + 5, "%d,%d", &ptr_x, &ptr_y);
+		key_pos = end ? end + 1 : key_pos + strlen(key_pos);
+		key_due = now + 300;
+		return 0;
+	}
 	if (code == '{' && !strncmp(key_pos, "click:", 6)) {
 		const char *end = strchr(key_pos, '}');
 

+ 231 - 5
user/apps/browser/browser.c

@@ -814,9 +814,19 @@ static void js_host_changed(void)
 	ngui_invalidate(&ui);
 }
 
+static void js_force_layout(void);
+
 static int js_host_rect(unsigned int node, int *x, int *y, int *w, int *h)
 {
-	if (node >= BR_MAX_NODES || !layout_boxes[node].valid)
+	if (node >= BR_MAX_NODES)
+		return 0;
+	/* A geometry read after a DOM change gets a synchronous layout, like
+	 * a browser's forced reflow: Bootstrap's tooltip inserts itself,
+	 * reads offsetWidth, then moves itself twice with $.offset(), which
+	 * reads its own current position each time. */
+	if (!layout_valid)
+		js_force_layout();
+	if (!layout_boxes[node].valid)
 		return 0;
 	*x = layout_boxes[node].x - page_rect.x;
 	*y = layout_boxes[node].y - page_rect.y;
@@ -9228,6 +9238,9 @@ static void draw_image_block(struct lay *l, unsigned int node, int x, int y,
 	}
 }
 
+static int intrinsic_width(struct ngui *ui, unsigned int node,
+			   const struct br_style *pst, int depth, int base);
+
 static void layout_block(struct lay *l, unsigned int node,
 			 const struct br_style *st, int depth,
 			 unsigned short link)
@@ -9316,6 +9329,40 @@ static void layout_block(struct lay *l, unsigned int node,
 				      mp_px(st, 0, old_right - old_left) -
 				      mp_px(st, 2, old_right - old_left);
 		}
+		/* An auto width placed by one horizontal offset is
+		 * shrink-to-fit (CSS 2.1 10.3.7): a Bootstrap tooltip or a
+		 * dropdown is as wide as its content, not its containing
+		 * block.  With neither offset the box keeps the containing
+		 * width, since `inset: 0` overlays are not parsed and only
+		 * stretch that way; an empty measure keeps it too. */
+		if (st->width_kind == 0 && st->left_set != st->right_set) {
+			int cb_l = st->pos == 2 ? page_rect.x : flow_left;
+			int cb_r = st->pos == 2 ? page_rect.x +
+					page_rect.w - 12 : flow_right;
+			int avail = cb_r - cb_l - (st->left_set ? st->left :
+						   st->right);
+			int w = intrinsic_width(l->ui, node, st, 0,
+						cb_r - cb_l);
+
+			if (w > 0) {
+				w += mp_px(st, 7, cb_r - cb_l) +
+				     mp_px(st, 5, cb_r - cb_l) +
+				     mp_px(st, 3, cb_r - cb_l) +
+				     mp_px(st, 1, cb_r - cb_l) +
+				     st->border_w[1] + st->border_w[3];
+				if (st->max_width_kind == 1 &&
+				    w > (int)st->max_width)
+					w = (int)st->max_width;
+				if (avail > 8 && w > avail)
+					w = avail;
+				if (st->right_set) {
+					l->right = cb_r - st->right;
+					l->left = l->right - w;
+				} else {
+					l->right = l->left + w;
+				}
+			}
+		}
 		/* `left: 100%` parks a box (Docusaurus' "Skip to main
 		 * content" link) past the containing block's right edge
 		 * until it is focused.  An auto width then has no room: it
@@ -9878,7 +9925,11 @@ static int intrinsic_width(struct ngui *ui, unsigned int node,
 			continue;
 		}
 		br_style_for(&doc, c, pst, &cs);
-		if (cs.display == BR_DISPLAY_NONE)
+		/* Absolute/fixed children take no room in the parent's
+		 * shrink-to-fit width: a shown Bootstrap tooltip widened the
+		 * floated navbar list and slid the hovered item away. */
+		if (cs.display == BR_DISPLAY_NONE || cs.pos == 1 ||
+		    cs.pos == 2)
 			continue;
 		if (nd->tag == BR_TAG_BR) {
 			if (line_w > max_w)
@@ -10043,6 +10094,19 @@ static unsigned int layout_float_group(struct lay *l, unsigned int first,
 		/* A float blockifies its box: Bootstrap floats inline
 		 * anchors too (the navbar brand and its text links), and
 		 * their padding must be honoured. */
+		/* An absolute/fixed sibling is out of flow and does not end
+		 * the row: Bootstrap inserts its tooltip right after the
+		 * hovered navbar <li>, and the row used to break there. */
+		if (!cs.float_left && (cs.pos == 1 || cs.pos == 2)) {
+			int sy = l->y, sl = l->left, sr = l->right;
+
+			layout_out_of_flow(l, n, &cs, depth, lk);
+			l->y = sy;
+			l->left = sl;
+			l->right = sr;
+			n = nd->next;
+			continue;
+		}
 		if (!cs.float_left)
 			break;
 		if (nd->tag == BR_TAG_A && nd->href_off)
@@ -12389,11 +12453,16 @@ static void render_page(int left, int right, int y0)
 
 		for (i = 0; i < ndeferred; i++) {
 			struct br_style st;
+			int hide;
 
 			br_style_for(&doc, deferred[i].node, &base, &st);
 			if (st.display == BR_DISPLAY_NONE)
 				continue;
-			l->draw = 1;
+			/* A transparent or visibility:hidden positioned box
+			 * still gets its boxes (scripts measure it) but no
+			 * paint and no hit rectangles. */
+			hide = st.opacity_hidden || st.vis_hidden;
+			l->draw = !hide;
 			l->left = deferred[i].flow_left;
 			l->right = deferred[i].flow_right;
 			l->y = deferred[i].flow_y;
@@ -12458,7 +12527,7 @@ static void render_page(int left, int right, int y0)
 					continue;
 				clip.h = ch;
 				ngui_push_clip(&ui, clip);
-				if (st.has_bg)
+				if (st.has_bg && !hide)
 					ngui_fill_rect(&ui, clip, st.bg);
 				layout_block(l, deferred[i].node, &st, 0,
 					     deferred[i].link);
@@ -13052,6 +13121,53 @@ static void draw_page(struct ngui_rect page)
 		img_stat_paint += u_ticks_ms() - t0;
 }
 
+/* Lay the page out now, into the page back buffer, so scripts read real
+ * boxes for nodes they just inserted.  Absolute/fixed boxes only get their
+ * boxes in the painting pass, so this is a full render; the next frame
+ * repaints the screen as usual.  Skipped while the page has never been
+ * drawn (no viewport yet) or without the back buffer. */
+static void js_force_layout(void)
+{
+	static int busy;
+	unsigned short *saved_px = ui.px;
+	int saved_w = ui.w, saved_h = ui.h;
+	struct ngui_rect page = page_rect;
+
+	static unsigned int window_t0, spent;
+	unsigned int t0 = u_ticks_ms();
+
+	if (busy || !page_backbuf || pagebuf_w != ui.w ||
+	    pagebuf_h != ui.h || page.w < 40 || page.h < 40 ||
+	    layout_right <= layout_left)
+		return;
+	/* Budget: a script that alternates writes and reads (an animation
+	 * loop) would otherwise re-render the page on every read.  Past
+	 * 40 ms of forced layouts in a 100 ms window it reads the last
+	 * layout, as before. */
+	if (t0 - window_t0 >= 100) {
+		window_t0 = t0;
+		spent = 0;
+	}
+	if (spent >= 40)
+		return;
+	busy = 1;
+	ui.px = page_backbuf;
+	layout_view_h = page.h;
+	layout_content_h = measure_page(layout_left, layout_right);
+	layout_valid = 1;
+	layout_nnode = doc.nnode;
+	ngui_push_clip(&ui, page);
+	render_page(layout_left, layout_right, page.y - page_scroll.offset);
+	ngui_pop_clip(&ui);
+	ui.px = saved_px;
+	ui.w = saved_w;
+	ui.h = saved_h;
+	page_cache_valid = 0;
+	ngui_invalidate(&ui);
+	spent += u_ticks_ms() - t0;
+	busy = 0;
+}
+
 static void draw_status(struct ngui_rect r)
 {
 	static char msg[BR_URL_MAX + 32];   /* leaf: off the 128 KB stack */
@@ -13697,6 +13813,25 @@ static int link_fragment_nav(unsigned int node)
 	return 1;
 }
 
+/* A positioned box laid out while transparent or visibility:hidden (or
+ * inside one): it has a box for scripts but must not catch the pointer. */
+static int node_invisible(unsigned int n)
+{
+	unsigned int guard = 0;
+
+	while (n < doc.nnode && guard++ < 64) {
+		struct br_style st;
+
+		style_for_node(n, &st);
+		if (st.opacity_hidden || st.vis_hidden)
+			return 1;
+		if (n == 0)
+			break;
+		n = doc.nodes[n].parent;
+	}
+	return 0;
+}
+
 /* The innermost laid-out box under a screen point: the smallest valid box
  * that contains it (the last one wins a tie, i.e. the later/deeper node).
  * Used to deliver clicks to elements that are neither links nor controls
@@ -13714,7 +13849,7 @@ static unsigned int find_box_hit(int x, int y)
 		    y >= b->y + b->h)
 			continue;
 		area = (unsigned int)b->w * (unsigned int)b->h;
-		if (area <= best_area) {
+		if (area <= best_area && !node_invisible(i)) {
 			best = i;
 			best_area = area;
 		}
@@ -13722,6 +13857,96 @@ static unsigned int find_box_hit(int x, int y)
 	return best;
 }
 
+/* The element under the pointer for hover events: the innermost laid-out
+ * box, or the link/control hit inside it (an inline <a> has no box of its
+ * own but a hit rectangle).  -1 when none. */
+static int hover_node = -1;
+
+static int node_contains(unsigned int a, unsigned int n)
+{
+	unsigned int guard = 0;
+
+	while (n < doc.nnode && guard++ < BR_MAX_NODES) {
+		if (n == a)
+			return 1;
+		if (n == 0)
+			return 0;
+		n = doc.nodes[n].parent;
+	}
+	return 0;
+}
+
+static int hover_target(void)
+{
+	int h, x = ui.mouse_x, y = ui.mouse_y;
+	unsigned int b;
+
+	if (!ui.inside || ui.buttons || sug_visible() ||
+	    x < page_rect.x || x >= page_rect.x + page_rect.w - 12 ||
+	    y < page_rect.y || y >= page_rect.y + page_rect.h)
+		return -1;
+	h = find_hit(x, y);
+	b = find_box_hit(x, y);
+	if (h && (!b || node_contains(b, (unsigned int)h)))
+		return h;
+	if (b)
+		return (int)b;
+	return h ? h : -1;
+}
+
+/* mouseover/mouseout (bubbling, with relatedTarget) at the old and new
+ * element, and mouseleave/mouseenter on every ancestor that was left or
+ * entered (outermost first for enter), like a browser's boundary events.
+ * jQuery 1.11 builds its mouseenter (Bootstrap tooltips) from mouseover
+ * and relatedTarget. */
+static void page_hover_events(void)
+{
+	int now, old, cx, cy, path[64], np = 0, i;
+	unsigned int n;
+
+	if (!js_browser_active()) {
+		hover_node = -1;
+		return;
+	}
+	now = hover_target();
+	if (now >= (int)doc.nnode)
+		now = -1;
+	if (now == hover_node)
+		return;
+	old = hover_node;
+	if (old >= (int)doc.nnode)
+		old = -1;
+	hover_node = now;
+	cx = ui.mouse_x - page_rect.x;
+	cy = ui.mouse_y - page_rect.y;
+	if (old >= 0) {
+		js_browser_mouse_event((unsigned int)old, "mouseout", 1, now,
+				       cx, cy);
+		for (n = (unsigned int)old, i = 0;
+		     n < doc.nnode && i < 64 &&
+		     !(now >= 0 && node_contains(n, (unsigned int)now)); i++) {
+			js_browser_mouse_event(n, "mouseleave", 0, now, cx, cy);
+			if (n == 0)
+				break;
+			n = doc.nodes[n].parent;
+		}
+	}
+	if (now < 0 || now >= (int)doc.nnode)
+		return;
+	js_browser_mouse_event((unsigned int)now, "mouseover", 1, old, cx, cy);
+	for (n = (unsigned int)now;
+	     n < doc.nnode && np < 64 &&
+	     !(old >= 0 && node_contains(n, (unsigned int)old));) {
+		path[np++] = (int)n;
+		if (n == 0)
+			break;
+		n = doc.nodes[n].parent;
+	}
+	for (i = np - 1; i >= 0; i--)
+		js_browser_mouse_event((unsigned int)path[i], "mouseenter", 0,
+				       old, cx, cy);
+}
+
 static void handle_page_click(unsigned int *action)
 {
 	int node;
@@ -13856,6 +14081,7 @@ void _start(const char *arg)
 			draw(&action);
 			handle_keys(&action);
 			handle_page_click(&action);
+			page_hover_events();
 			ngui_end(&ui);
 		}
 		if (action & ACT_NAV) {

+ 27 - 4
user/apps/browser/browser_html.c

@@ -599,6 +599,24 @@ static unsigned int store_attr(struct br_doc *d, const char *s,
 	}
 }
 
+/* href is stored even when empty: `<a href="">` is a link to the page
+ * itself (a hand cursor, a click target; scripts usually cancel the
+ * click, like Bootstrap's data-toggle="modal").  Offset 0 would mean "no
+ * href", so an empty value gets its own NUL byte. */
+static unsigned int store_href(struct br_doc *d, const char *s,
+			       unsigned int len)
+{
+	unsigned int off;
+
+	if (len)
+		return store_attr(d, s, len, BR_URL_ATTR_MAX);
+	if (d->attrs_used + 2 >= BR_ATTR_SIZE)
+		return 0;
+	off = d->attrs_used;
+	d->attrs[d->attrs_used++] = '\0';
+	return off;
+}
+
 static const char *attr_ptr(struct br_doc *d, unsigned int off)
 {
 	return off ? d->attrs + off : "";
@@ -1734,7 +1752,7 @@ 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, BR_URL_ATTR_MAX) : 0;
+		n->href_off = store_href(d, value, len);
 	else if (same_string(name, "src"))
 		n->src_off = len ? store_attr(d, value, len, BR_URL_ATTR_MAX) : 0;
 	else if (same_string(name, "alt"))
@@ -2310,8 +2328,7 @@ 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,
-						 BR_URL_ATTR_MAX);
+			n->href_off = store_href(d, s + vstart, vlen);
 		else if (str_eq(name, "class"))
 			n->class_off = store_attr(d, s + vstart, vlen,
 						  BR_CLASS_MAX);
@@ -9522,7 +9539,13 @@ void br_style_for(struct br_doc *d, unsigned int node,
 	resolve_size_units(out);
 	if (!cascade_pe && (d->nodes[node].flags & BR_NODE_HIDDEN))
 		out->display = BR_DISPLAY_NONE;
-	if (out->vis_hidden || out->opacity_hidden ||
+	/* Invisible in-flow content is dropped (it would otherwise take
+	 * space this engine cannot hide well).  An absolute/fixed box keeps
+	 * its display: it moves nothing, and scripts measure it while it is
+	 * still transparent (Bootstrap's tooltip is `opacity: 0` until it
+	 * gets `.in`).  The layout lays it out without painting it. */
+	if (((out->vis_hidden || out->opacity_hidden) &&
+	     out->pos != 1 && out->pos != 2) ||
 	    (out->overflow_hidden && out->height_kind == 1 &&
 	     out->height == 0))
 		out->display = BR_DISPLAY_NONE;

+ 47 - 0
user/apps/browser/js_browser.c

@@ -898,6 +898,41 @@ int js_browser_event(unsigned int node, const char *type, int bubbles,
 	return rv;
 }
 
+int js_browser_mouse_event(unsigned int node, const char *type,
+			   int bubbles, int related, int x, int y)
+{
+	int slot, rv;
+
+	if (!J || !D)
+		return 1;
+	for (slot = 0; slot < JS_EVENT_SLOTS; slot++)
+		if (!events[slot].used)
+			break;
+	if (slot == JS_EVENT_SLOTS)
+		return 1;
+	js_setlimit(J, JS_RUN_LIMIT, 0);
+	js_newobject(J);
+	js_pushnumber(J, x); js_setproperty(J, -2, "clientX");
+	js_pushnumber(J, y); js_setproperty(J, -2, "clientY");
+	js_pushnumber(J, x); js_setproperty(J, -2, "pageX");
+	js_pushnumber(J, y); js_setproperty(J, -2, "pageY");
+	js_pushnumber(J, x); js_setproperty(J, -2, "screenX");
+	js_pushnumber(J, y); js_setproperty(J, -2, "screenY");
+	js_pushnumber(J, 0); js_setproperty(J, -2, "button");
+	js_pushnumber(J, 0); js_setproperty(J, -2, "buttons");
+	js_pushnumber(J, 0); js_setproperty(J, -2, "which");
+	if (related >= 0)
+		push_node(J, (unsigned int)related + 1);
+	else
+		js_pushnull(J);
+	js_setproperty(J, -2, "relatedTarget");
+	/* -1: the object on top (index 0 would mean "none supplied"). */
+	rv = dispatch_object(J, node, -1, type, bubbles, 1);
+	js_pop(J, 2);
+	js_runjobs(J);
+	return rv;
+}
+
 static unsigned int node_type_value(unsigned int node)
 {
 	struct br_node *n;
@@ -2366,6 +2401,18 @@ static int node_has(js_State *state, void *p, const char *name)
 	    !strcmp(name, "scrollWidth") || !strcmp(name, "scrollHeight")) {
 		int x = 0, y = 0, w = 0, h = 0;
 
+		/* The root element's client size is the viewport: jQuery's
+		 * $(window).height() reads documentElement.clientHeight, and
+		 * Bootstrap's tooltip clamps itself to that (0 pushed every
+		 * tooltip above the page). */
+		if (n->type == BR_NODE_ELEM && n->tag == BR_TAG_HTML &&
+		    (!strcmp(name, "clientWidth") ||
+		     !strcmp(name, "clientHeight"))) {
+			js_pushnumber(state, !strcmp(name, "clientWidth") ?
+				      (host.width ? (int)host.width : 1024) :
+				      (host.height ? (int)host.height : 768));
+			return 1;
+		}
 		/* Before the first layout an element has no box; a block's
 		 * width is then best guessed as the viewport (Vue apps measure
 		 * offsetWidth on mount and pick a phone layout for 0).  A

+ 7 - 0
user/apps/browser/js_browser.h

@@ -90,6 +90,13 @@ void js_browser_tick(void);
 int js_browser_event(unsigned int node, const char *type, int bubbles,
 		     int cancelable);
 
+/* Dispatch a mouse event (mouseover/mouseout/mouseenter/mouseleave/
+ * mousemove) at a node with client coordinates and relatedTarget (a node
+ * index, or -1 for null).  Returns 0 when a handler called
+ * preventDefault(). */
+int js_browser_mouse_event(unsigned int node, const char *type,
+			   int bubbles, int related, int x, int y);
+
 int js_browser_active(void);
 
 #endif

Niektóre pliki nie zostały wyświetlone z powodu dużej ilości zmienionych plików