Преглед на файлове

Fix Bootstrap navbar layout and enlarge canvas windows

Inline floats are blockified, so Bootstrap's floated navbar brand keeps its
padding: the Cloudron logo and wordmark sit centred with normal breathing
room instead of at the page edge.  Intrinsic widths now size images from
their CSS height and count the space after an inline image, so the collapsed
nav no longer over-measures and wraps; the nav stays right-aligned on one row.

@media width rules use the browser canvas width instead of a fixed 1000 px
viewport, so a 960 px window gets the site's 768-991 px rules.

The kernel WM's 1024 px canvas cap is replaced by a 2048 px sanity bound plus
the framebuffer check, so a window can grow to fill a 1280x800 panel.  The
browser opens at 1100x700, falling back to 960x640 and 780x540 on smaller
screens.

Verified on live cloudron.io and the local docs site; make all, make uefi,
make test-images and make test-uefi pass.
Johannes Zellner преди 1 седмица
родител
ревизия
ee9f80a602
променени са 6 файла, в които са добавени 71 реда и са изтрити 31 реда
  1. 12 9
      AGENTS.md
  2. 45 16
      browser.c
  3. 2 1
      docs/graphics.html
  4. 4 3
      docs/userland.html
  5. 2 2
      wm.c
  6. 6 0
      wm.h

+ 12 - 9
AGENTS.md

@@ -674,13 +674,15 @@ it to `0x7E00`.  The kernel region itself only has one wall (`_end` below
   weights, `!important`, line-height, alignment, margins, padding, borders,
   `list-style: none`, `text-transform: uppercase`, `display`, percentage
   `width`/`height`/`max-width`, and basic `float: left/right` columns.
-  `@media (min-width/max-width)` blocks are evaluated against a fixed 1000 px
-  desktop viewport; `@font-face`/`@import`/`@keyframes` are skipped.  Inline
+  `@media (min-width/max-width)` blocks are evaluated against the browser
+  canvas width when the page is parsed; `@font-face`/`@import`/`@keyframes` are
+  skipped.  Inline
   `<svg>` subtrees and closed `<details>` are skipped (not renderable), and
   `<video>` gets a placeholder box.  The default page canvas follows
   `ngui_theme_dark` (dark page, light text, `theme.panel` for `<pre>`);
   a site's own `background-color`/`color` CSS still overrides it.  `browser.c`
-  owns a 960x640 window, the layout/render, URL bar, history, status bar and
+  opens at 1100x700 (960x640 and 780x540 fallbacks on smaller screens), the
+  layout/render, URL bar, history, status bar and
   inline `<img>` decoding.  Images are fetched one per main-loop iteration
   (so text and scrolling stay responsive) and only when their measured
   position is within the viewport plus 160 px; deferred images are loaded as
@@ -1280,12 +1282,13 @@ and the WM falls back to polling (`io_keyboard_irq_masked()`).
     percentage columns); flex/grid items still use them.  Float support is
     the basic Bootstrap-grid case: consecutive floated blocks are laid side
     by side with percentage/px widths, left floats pack from the row's left
-    edge and right floats from its right edge, there is no `clear`,
-    percentage margins are approximated as pixels, and a float without a
-    width uses a text-width estimate.  `@media` width
-    blocks are evaluated against a fixed 1000 px desktop viewport (so
-    narrow/adaptive pages get the desktop rules, not their mobile layout),
-    and pseudo-classes are never matched.  `font-size` now maps to real pixel
+    edge and right floats from its right edge, inline floats are blockified
+    (Bootstrap floats the navbar brand and its text links), there is no
+    `clear`, percentage margins are approximated as pixels, and a float
+    without a width uses a text-width estimate.  `@media` width
+    blocks are evaluated against the canvas width at page-parse time, so a
+    window resize does not re-evaluate them until the next load, and
+    pseudo-classes are never matched.  `font-size` now maps to real pixel
     sizes (8..48), `font-weight` selects the bold face, `font-style: italic`
     selects the italic face, `font-family: monospace` selects Liberation Mono,
     and `em`/`rem` use a 16 px root.  Text is Latin-1 only (non-Latin-1

+ 45 - 16
browser.c

@@ -18,10 +18,10 @@
 #include "img.h"
 #include "inflate.h"
 
-#define BR_W            960
-#define BR_H            640
-/* CSS media queries are evaluated as a desktop browser. */
-#define BR_VIEWPORT_W   1000
+/* Start wide enough for the desktop nav; smaller screens fall back to
+ * 960x640 and 780x540, which still fit a 1024x768 panel. */
+#define BR_W            1100
+#define BR_H            700
 #define BR_TOOLBAR_H    30
 #define BR_STATUS_H     18
 
@@ -1489,6 +1489,7 @@ static void load_page(const char *url, int local, int push)
 			decode_direct_image(body, len, node);
 		s_copy(page_title, "Image", sizeof(page_title));
 	} else {
+		br_set_viewport(ui.w);
 		br_parse(&doc, (const char *)body, len);
 		s_copy(page_title, doc.title[0] ? doc.title : page_url,
 		       sizeof(page_title));
@@ -1578,6 +1579,7 @@ static void load_home(int push)
 			"<pre>javascript: not supported\nforms: not supported"
 			"\nimages: PNG JPEG GIF BMP TGA PNM ICO</pre>"
 			"</body></html>";
+		br_set_viewport(ui.w);
 		br_parse(&doc, home, sizeof(home) - 1);
 		br_parse_inline_css(&doc);
 		br_reset_styles(&doc);
@@ -2783,6 +2785,7 @@ static int intrinsic_width(struct ngui *ui, unsigned int node,
 			} else {
 				unsigned int ti = 0;
 				int first = 1;
+				int lead = w > 0 && tn > 0 && text_space(t[0]);
 				int sp = (int)ngui_text_width_px(ui, " ", 1,
 					pst->font_px, pst->bold, pst->italic,
 					pst->mono);
@@ -2797,8 +2800,9 @@ static int intrinsic_width(struct ngui *ui, unsigned int node,
 						ti++;
 					if (ti == ts)
 						break;
-					if (!first)
+					if (!first || lead)
 						w += sp;
+					lead = 0;
 					w += (int)ngui_text_width_px(ui,
 						t + ts, ti - ts,
 						pst->font_px, pst->bold,
@@ -2811,22 +2815,42 @@ static int intrinsic_width(struct ngui *ui, unsigned int node,
 		br_style_for(&doc, c, pst, &cs);
 		if (cs.display == BR_DISPLAY_NONE)
 			continue;
-		if (cs.float_left)
-			w += 8;
 		if (nd->tag == BR_TAG_BR) {
 			w += 8;
 			continue;
 		}
 		if (nd->tag == BR_TAG_IMG) {
+			/* Measure the image as layout will draw it: a CSS or
+			 * attribute height keeps the intrinsic aspect ratio, and
+			 * a CSS width overrides the native pixel width.  Bootstrap
+			 * sizes the Cloudron logo with height:40px only. */
 			int idx = nd->img_index;
+			int iw = 0, ih = 0;
 
 			if (idx >= 0 && idx < image_count &&
-			    images[idx].state == 1)
-				w += (int)images[idx].img.w;
-			else if (nd->width_attr)
+			    images[idx].state == 1) {
+				iw = (int)images[idx].native_w;
+				ih = (int)images[idx].native_h;
+				if (iw <= 0 || ih <= 0) {
+					iw = (int)images[idx].img.w;
+					ih = (int)images[idx].img.h;
+				}
+			}
+			if (cs.width_kind == 1) {
+				w += cs.width;
+			} else if (cs.width_kind == 2) {
+				w += 64;
+			} else if (nd->width_attr) {
 				w += nd->width_attr;
-			else
+			} else if (nd->height_attr && iw && ih) {
+				w += iw * (int)nd->height_attr / ih;
+			} else if (cs.height_kind == 1 && iw && ih) {
+				w += iw * (int)cs.height / ih;
+			} else if (iw) {
+				w += iw;
+			} else {
 				w += 64;
+			}
 			continue;
 		}
 		w += cs.pl + cs.pr + cs.ml + cs.mr;
@@ -2872,7 +2896,10 @@ static unsigned int layout_float_group(struct lay *l, unsigned int first,
 			n = nd->next;
 			continue;
 		}
-		if (!cs.float_left || cs.display != BR_DISPLAY_BLOCK)
+		/* A float blockifies its box: Bootstrap floats inline
+		 * anchors too (the navbar brand and its text links), and
+		 * their padding must be honoured. */
+		if (!cs.float_left)
 			break;
 		if (nd->tag == BR_TAG_A && nd->href_off)
 			lk = (unsigned short)n;
@@ -2883,7 +2910,7 @@ static unsigned int layout_float_group(struct lay *l, unsigned int first,
 			colw = (int)cs.width;
 		else {
 			colw = intrinsic_width(l->ui, n, &cs, 0) +
-			       cs.pl + cs.pr + cs.ml + cs.mr + 8;
+			       cs.pl + cs.pr + cs.ml + cs.mr;
 			if (colw < 8)
 				colw = 8;
 		}
@@ -3654,7 +3681,7 @@ static void layout_children(struct lay *l, unsigned int parent,
 			n = nd->next;
 			continue;
 		}
-		if (cs.float_left && cs.display == BR_DISPLAY_BLOCK) {
+		if (cs.float_left) {
 			n = layout_float_group(l, n, pst, depth, lk);
 			continue;
 		}
@@ -4092,7 +4119,9 @@ void _start(const char *arg)
 {
 	struct win_info wi;
 
-	if (u_win_create(BR_W, BR_H, "Browser", &wi) != 0) {
+	if (u_win_create(BR_W, BR_H, "Browser", &wi) != 0 &&
+	    u_win_create(960, 640, "Browser", &wi) != 0 &&
+	    u_win_create(780, 540, "Browser", &wi) != 0) {
 		u_puts("browser: no graphics window\n");
 		u_exit(1);
 	}
@@ -4101,7 +4130,7 @@ void _start(const char *arg)
 	br_doc_init(&doc);
 	br_set_theme(ui.theme.text, ui.theme.bg, ui.theme.panel,
 		     ui.theme.accent);
-	br_set_viewport(BR_VIEWPORT_W);
+	br_set_viewport(wi.width);
 	if (u_getcwd(cwd, sizeof(cwd)) != 0 || !cwd[0])
 		s_copy(cwd, "/", sizeof(cwd));
 	heap_clear();

+ 2 - 1
docs/graphics.html

@@ -235,7 +235,8 @@
 			without reading another process's memory.
 			<code>SYS_WM_RESIZE</code> (WM side) and
 			<code>SYS_WIN_ACK_RESIZE</code> (client side) swap in a resized
-			canvas.
+			canvas; the content size is bounded by the framebuffer, so a
+			window can grow to the edge of the screen.
 		</p>
 		<div class="note">
 			<p><strong>Buttons fire on the release edge.</strong> The toolkit keeps

+ 4 - 3
docs/userland.html

@@ -320,14 +320,15 @@
 		<h2>Browser</h2>
 		<p>
 			The real browser is <code>bin/browser.app</code> in the pack. It links
-			ngui, the image library, inflate, TLS and uhttp. It owns a 960×640
-			window, a URL bar, history, a status bar and inline images. Network
+			ngui, the image library, inflate, TLS and uhttp. It opens at
+			1100×700 (960×640 and 780×540 fallbacks on smaller screens), with a
+			URL bar, history, a status bar and inline images. Network
 			work runs in a headless <code>curl __fetch</code> helper that writes
 			the body and metadata under <code>/share</code>, so the UI keeps
 			drawing and scrolling.
 		</p>
 		<ul>
-			<li><strong>HTML/CSS subset.</strong> External and inline stylesheets, tag/class/id and descendant/child selectors, colours, backgrounds, real <code>font-size</code> (8–48 px), bold/italic faces, <code>font-family: monospace</code>, margins, padding, borders, alignment, percentage widths, basic floats and <code>@media</code> blocks evaluated at a fixed 1000 px viewport. Text is Latin-1; there is no shaping, bidi or <code>@font-face</code> yet.</li>
+			<li><strong>HTML/CSS subset.</strong> External and inline stylesheets, tag/class/id and descendant/child selectors, colours, backgrounds, real <code>font-size</code> (8–48 px), bold/italic faces, <code>font-family: monospace</code>, margins, padding, borders, alignment, percentage widths, basic floats and <code>@media</code> blocks evaluated at the browser canvas width when the page is parsed. Text is Latin-1; there is no shaping, bidi or <code>@font-face</code> yet.</li>
 			<li><strong>Not supported.</strong> JavaScript, forms, pseudo-classes, border-radius clipping of descendants, gradients/box-shadow/transitions and CSS <code>color-mix</code>. Flex rows, card grids, basic tables, inline SVG and CSS variables are supported.</li>
 			<li><strong>Caps.</strong> 2 MB page body, 832 KB CSS, 6144 DOM nodes, 4608 rules, 16 images. Each image gets an <code>img_estimate()</code>-sized decode arena that is freed after the scaled bitmap is made; navigation calls <code>heap_reset()</code> and unmaps the page heap.</li>
 			<li><strong>Fetching.</strong> Each network fetch starts a one-shot helper process and a fresh TCP/TLS connection; images load one per loop within the viewport plus 160 px.</li>

+ 2 - 2
wm.c

@@ -190,7 +190,7 @@ int wm_server_win_create(const struct win_create *in, struct win_info *out)
 		return -1;
 	cw = in->w;
 	ch = in->h;
-	if (cw == 0 || ch == 0 || cw > 1024 || ch > 1024)
+	if (cw == 0 || ch == 0 || cw > WM_WIN_MAX_W || ch > WM_WIN_MAX_H)
 		return -1;
 	if (cw + 2 > vga_fb_width() || ch + WM_TITLE_H + 2 > vga_fb_height())
 		return -1;
@@ -477,7 +477,7 @@ int wm_server_resize(unsigned int index, unsigned int cw, unsigned int ch)
 	w = &windows[index];
 	if (!w->canvas_window || !process_is_alive(w->pid))
 		return -1;
-	if (cw < 160 || ch < 80 || cw > 1024 || ch > 1024)
+	if (cw < 160 || ch < 80 || cw > WM_WIN_MAX_W || ch > WM_WIN_MAX_H)
 		return -1;
 	if (cw + 2 > vga_fb_width() || ch + WM_TITLE_H + 2 > vga_fb_height())
 		return -1;

+ 6 - 0
wm.h

@@ -8,6 +8,12 @@
 
 #define MAX_WINDOWS WM_MAX_WINDOWS
 
+/* Hard sanity bound for a canvas window (stops size arithmetic wrapping);
+ * the framebuffer check below it is the real limit.  The old 1024 px cap
+ * left a 1280x800 panel unable to enlarge a window past 1024. */
+#define WM_WIN_MAX_W 2048
+#define WM_WIN_MAX_H 2048
+
 struct window {
 	int used;
 	unsigned int x, y;       /* pixel origin (title bar top-left) */