Просмотр исходного кода

Show larger pages and queue link clicks

Johannes Zellner 2 недель назад
Родитель
Сommit
b5d44984ab
3 измененных файлов с 49 добавлено и 16 удалено
  1. 18 7
      AGENTS.md
  2. 27 5
      browser.c
  3. 4 4
      browser_html.h

+ 18 - 7
AGENTS.md

@@ -192,7 +192,9 @@ run area), so adding code no longer moves any address.
   capture window, so a click that starts in a window still gets its release
   capture window, so a click that starts in a window still gets its release
   after the pointer leaves.  The userland `ngui.c/h` immediate-mode toolkit
   after the pointer leaves.  The userland `ngui.c/h` immediate-mode toolkit
   builds on those: clipped RGB565 primitives, buttons, text input, procedural
   builds on those: clipped RGB565 primitives, buttons, text input, procedural
-  icons and scrolling panes.  `files` (`ucmd_files.c`) is its first user.
+  icons and scrolling panes.  `files` (`ucmd_files.c`) is its first user;
+  `gallery` (`gallery.c`) is the live showcase of every control and primitive
+  the toolkit exports.
 - **Graphics**: `vga.c/h`, `vga_copy.S`, `blit.c/h`, `gpu.c`, `ati.c`, `nvidia.c`,
 - **Graphics**: `vga.c/h`, `vga_copy.S`, `blit.c/h`, `gpu.c`, `ati.c`, `nvidia.c`,
   `nv50.c`, `pci.h` — VESA LFB + shadow buffer.  Drawing goes into a
   `nv50.c`, `pci.h` — VESA LFB + shadow buffer.  Drawing goes into a
   `struct surface` render target: `vga_target()` is the screen's shadow buffer
   `struct surface` render target: `vga_target()` is the screen's shadow buffer
@@ -421,12 +423,21 @@ run area), so adding code no longer moves any address.
   `cd` (the shell passes arguments verbatim).  The one argument is passed as a
   `cd` (the shell passes arguments verbatim).  The one argument is passed as a
   C string on the top of the user stack (`process_create_user(..., arg)`), so
   C string on the top of the user stack (`process_create_user(..., arg)`), so
   `_start(const char *arg)` needs no crt0.  `ngui.c/h` is the shared userland
   `_start(const char *arg)` needs no crt0.  `ngui.c/h` is the shared userland
-  GUI toolkit linked into `ucmd_files.c` (buttons, text fields, icons, layout
-  cuts and scroll panes); `files` opens the selected text file through
+  GUI toolkit linked into `ucmd_files.c` and the external `gallery.elf`
+  (buttons, text fields, icons, layout cuts and scroll panes); `files` opens
+  the selected text file through
   `/ramfs/bin/edit`, image files through `/ramfs/bin/view`, and `.htm`/`.html`
   `/ramfs/bin/edit`, image files through `/ramfs/bin/view`, and `.htm`/`.html`
   files through `/ramfs/bin/browser`.  `ngui_end_ex()`
   files through `/ramfs/bin/browser`.  `ngui_end_ex()`
   is the variant that runs the bookkeeping without publishing the canvas, for
   is the variant that runs the bookkeeping without publishing the canvas, for
   apps that poll input without redrawing.
   apps that poll input without redrawing.
+- **Gallery**: `gallery.c` is the ngui widget gallery: typography and
+  truncation, the drawing primitives and clip stack, the theme palette, all
+  nine icons, live buttons/icon buttons, text fields with event feedback, a
+  nested draggable scroll pane and the `ngui_cut_*` layout helpers.  It is a
+  disk app (`GALLERY` on `root.img`, or `/share`/FAT mounts) like the browser
+  because the embedded command pack is tight against the `0x7F000` wall;
+  `ucmd_gallery.c` is the tiny `bin/gallery` launcher, and `make gallery-dev`
+  uploads the real app to a board's `/share`.
 - **Browser**: `ucmd_browser.c` is a tiny `bin/browser` launcher; the real
 - **Browser**: `ucmd_browser.c` is a tiny `bin/browser` launcher; the real
   browser is the external `BROWSER` on `root.img` (also looked up in `/share`
   browser is the external `BROWSER` on `root.img` (also looked up in `/share`
   and on IDE/SATA FAT mounts) because it links ngui, the full image library,
   and on IDE/SATA FAT mounts) because it links ngui, the full image library,
@@ -459,9 +470,9 @@ run area), so adding code no longer moves any address.
   under `/share`, while the browser keeps drawing and scrolling its own
   under `/share`, while the browser keeps drawing and scrolling its own
   window.  The helper asks for identity encoding because inflating multi-MB
   window.  The helper asks for identity encoding because inflating multi-MB
   pages in the browser process stalled the UI; if a server still sends gzip,
   pages in the browser process stalled the UI; if a server still sends gzip,
-  the browser's inflate has a progress hook that pumps the UI.  Page and
-  image buffers come from `SYS_MEM_ALLOC`; the DOM uses fixed static
-  arenas (2560 nodes, 128 KB attributes, 1792 rules), and page bodies are
+  the browser's inflate has a progress hook that pumps the UI.  Page, image
+  and CSS scratch buffers come from `SYS_MEM_ALLOC`; the DOM uses fixed static
+  arenas (6144 nodes, 512 KB attributes, 2304 rules), and page bodies are
   capped at 2 MB with CSS sheets up to 832 KB (six sheets).  Images are
   capped at 2 MB with CSS sheets up to 832 KB (six sheets).  Images are
   decoded once into a shared 24 MB arena and copied to a display bitmap at
   decoded once into a shared 24 MB arena and copied to a display bitmap at
   most 1000 px wide (up to 16 images, 512 KB files / 8 MP decodes), so 4K
   most 1000 px wide (up to 16 images, 512 KB files / 8 MP decodes), so 4K
@@ -564,7 +575,7 @@ nested). `/` is the read-only VFS root listing the mounted filesystems (the
 filesystem commands operate inside a mount, e.g. `cat /floppy1/HELLO.TXT`).
 filesystem commands operate inside a mount, e.g. `cat /floppy1/HELLO.TXT`).
 
 
 `cpuinfo`, `ls`, `cat`, `save`, `rm`, `mkdir`, `rmdir`, `meminfo`, `top`, `spin`,
 `cpuinfo`, `ls`, `cat`, `save`, `rm`, `mkdir`, `rmdir`, `meminfo`, `top`, `spin`,
-`clock`, `colors`, `files`, `view`, `sensors`, `mouseinfo`, `storage`, `netinfo`, `netip`, `netdns`, `host`, `dhcp`, `ping`,
+`clock`, `colors`, `files`, `gallery`, `view`, `sensors`, `mouseinfo`, `storage`, `netinfo`, `netip`, `netdns`, `host`, `dhcp`, `ping`,
 `pong`, `netsend`, `netrecv`, `netlog`, `netconsole`, `netregs`, `netloop`,
 `pong`, `netsend`, `netrecv`, `netlog`, `netconsole`, `netregs`, `netloop`,
 `netreset`, `websrv`, `curl` and `hello` are files in `/ramfs/bin` (packed by the
 `netreset`, `websrv`, `curl` and `hello` are files in `/ramfs/bin` (packed by the
 Makefile), found through the shell's PATH; the rest are kernel commands
 Makefile), found through the shell's PATH; the rest are kernel commands

+ 27 - 5
browser.c

@@ -97,7 +97,7 @@ static unsigned int heap_used = 0;
  * image.  This keeps 4K screenshots inside the 32 MB heap.  The two halves
  * image.  This keeps 4K screenshots inside the 32 MB heap.  The two halves
  * double as the gzip input scratch for page/CSS fetches, where the heap has
  * double as the gzip input scratch for page/CSS fetches, where the heap has
  * no room for another multi-megabyte body. */
  * no room for another multi-megabyte body. */
-static unsigned char image_io_buf[2u * BR_IMG_FILE_MAX];
+static unsigned char *image_io_buf;
 #define image_file_buf (image_io_buf)
 #define image_file_buf (image_io_buf)
 #define image_comp_buf (image_io_buf + BR_IMG_FILE_MAX)
 #define image_comp_buf (image_io_buf + BR_IMG_FILE_MAX)
 #define BR_PAGE_COMP_MAX (2u * BR_IMG_FILE_MAX)
 #define BR_PAGE_COMP_MAX (2u * BR_IMG_FILE_MAX)
@@ -105,6 +105,8 @@ static struct inflate image_inflate_ws;
 static unsigned char *image_arena;
 static unsigned char *image_arena;
 static unsigned int image_arena_size;
 static unsigned int image_arena_size;
 
 
+static void *heap_alloc(unsigned int bytes, unsigned int align);
+
 #if BR_CSS_MAX + BR_CSS_COMP_MAX > 2u * BR_IMG_FILE_MAX
 #if BR_CSS_MAX + BR_CSS_COMP_MAX > 2u * BR_IMG_FILE_MAX
 #error "CSS scratch must fit in image_io_buf"
 #error "CSS scratch must fit in image_io_buf"
 #endif
 #endif
@@ -123,6 +125,8 @@ static char history[BR_HISTORY][BR_URL_MAX];
 static int hist_len, hist_pos;
 static int hist_len, hist_pos;
 
 
 static char click_url[BR_URL_MAX];
 static char click_url[BR_URL_MAX];
+static char wait_click_url[BR_URL_MAX];
+static int wait_nav;
 static int quit;
 static int quit;
 
 
 static struct ngui_rect page_rect;
 static struct ngui_rect page_rect;
@@ -279,6 +283,11 @@ static int heap_start(void)
 	}
 	}
 	heap_size = BR_HEAP_INIT;
 	heap_size = BR_HEAP_INIT;
 	heap_used = 0;
 	heap_used = 0;
+	image_io_buf = (unsigned char *)heap_alloc(2u * BR_IMG_FILE_MAX, 16);
+	if (!image_io_buf) {
+		heap_size = heap_used = 0;
+		return -1;
+	}
 	return 0;
 	return 0;
 }
 }
 
 
@@ -287,6 +296,7 @@ static void heap_clear(void)
 	u_mem_free();
 	u_mem_free();
 	heap = 0;
 	heap = 0;
 	heap_size = heap_used = 0;
 	heap_size = heap_used = 0;
+	image_io_buf = 0;
 	image_arena = 0;
 	image_arena = 0;
 	image_arena_size = 0;
 	image_arena_size = 0;
 }
 }
@@ -728,6 +738,7 @@ struct fetch_meta {
 };
 };
 
 
 static void draw(unsigned int *action);
 static void draw(unsigned int *action);
+static void handle_page_click(unsigned int *action);
 static int fetch_helper_tty = -2;
 static int fetch_helper_tty = -2;
 static struct fetch_meta fetch_meta;
 static struct fetch_meta fetch_meta;
 
 
@@ -770,6 +781,12 @@ static void worker_wait_ui(void)
 	if (!ngui_begin(&ui))
 	if (!ngui_begin(&ui))
 		return;
 		return;
 	draw(&action);
 	draw(&action);
+	handle_page_click(&action);
+	if ((action & ACT_NAV) && click_url[0]) {
+		s_copy(wait_click_url, click_url, sizeof(wait_click_url));
+		wait_nav = 1;
+		click_url[0] = '\0';
+	}
 	if (!ngui_focus(&ui) && ngui_scroll_keys(&ui, &page_scroll))
 	if (!ngui_focus(&ui) && ngui_scroll_keys(&ui, &page_scroll))
 		ngui_invalidate(&ui);
 		ngui_invalidate(&ui);
 	ngui_end(&ui);
 	ngui_end(&ui);
@@ -2100,7 +2117,7 @@ static unsigned int layout_float_group(struct lay *l, unsigned int first,
 			n = nd->next;
 			n = nd->next;
 			continue;
 			continue;
 		}
 		}
-		if (!cs.float_left)
+		if (!cs.float_left || cs.display != BR_DISPLAY_BLOCK)
 			break;
 			break;
 		if (cs.width_kind == 2)
 		if (cs.width_kind == 2)
 			colw = (row_right - row_left) * (int)cs.width / 100;
 			colw = (row_right - row_left) * (int)cs.width / 100;
@@ -2204,7 +2221,7 @@ static void layout_children(struct lay *l, unsigned int parent,
 			n = nd->next;
 			n = nd->next;
 			continue;
 			continue;
 		}
 		}
-		if (cs.float_left) {
+		if (cs.float_left && cs.display == BR_DISPLAY_BLOCK) {
 			n = layout_float_group(l, n, pst, depth, link);
 			n = layout_float_group(l, n, pst, depth, link);
 			continue;
 			continue;
 		}
 		}
@@ -2502,7 +2519,7 @@ static void handle_page_click(unsigned int *action)
 	int node;
 	int node;
 	char url[BR_URL_MAX];
 	char url[BR_URL_MAX];
 
 
-	if (!ui.pressed || !ui.inside)
+	if (!ui.pressed)
 		return;
 		return;
 	if (ui.press_x < page_rect.x ||
 	if (ui.press_x < page_rect.x ||
 	    ui.press_x >= page_rect.x + page_rect.w - 12 ||
 	    ui.press_x >= page_rect.x + page_rect.w - 12 ||
@@ -2548,6 +2565,7 @@ void _start(const char *arg)
 		unsigned int action = 0;
 		unsigned int action = 0;
 		unsigned int now;
 		unsigned int now;
 
 
+		click_url[0] = '\0';
 		if (preload_active) {
 		if (preload_active) {
 			if (preload_wait)
 			if (preload_wait)
 				preload_wait = 0;
 				preload_wait = 0;
@@ -2559,7 +2577,11 @@ void _start(const char *arg)
 			preload_pending = 0;
 			preload_pending = 0;
 			preload_active = 1;
 			preload_active = 1;
 		}
 		}
-		click_url[0] = '\0';
+		if (wait_nav) {
+			s_copy(click_url, wait_click_url, sizeof(click_url));
+			action |= ACT_NAV;
+			wait_nav = 0;
+		}
 		now = u_ticks_ms();
 		now = u_ticks_ms();
 		if (status_until && (int)(now - status_until) >= 0) {
 		if (status_until && (int)(now - status_until) >= 0) {
 			status_text[0] = '\0';
 			status_text[0] = '\0';

+ 4 - 4
browser_html.h

@@ -6,11 +6,11 @@
 #ifndef BROWSER_HTML_H
 #ifndef BROWSER_HTML_H
 #define BROWSER_HTML_H
 #define BROWSER_HTML_H
 
 
-#define BR_MAX_NODES     2560
-#define BR_TEXT_SIZE     32768
-#define BR_ATTR_SIZE     131072
+#define BR_MAX_NODES     6144
+#define BR_TEXT_SIZE     65536
+#define BR_ATTR_SIZE     524288
 #define BR_CSS_SIZE      12288
 #define BR_CSS_SIZE      12288
-#define BR_MAX_RULES     1792
+#define BR_MAX_RULES     2304
 #define BR_DECLS         16
 #define BR_DECLS         16
 #define BR_TITLE_MAX     96
 #define BR_TITLE_MAX     96