Browse Source

Use the dark ngui theme for browser pages

Johannes Zellner 2 weeks ago
parent
commit
c6d70128bb
5 changed files with 50 additions and 29 deletions
  1. 9 3
      AGENTS.md
  2. 15 16
      browser.c
  3. 16 2
      browser_html.c
  4. 2 0
      browser_html.h
  5. 8 8
      testdata/browser/demo.html

+ 9 - 3
AGENTS.md

@@ -447,8 +447,11 @@ run area), so adding code no longer moves any address.
   `@media (min-width/max-width)` blocks are evaluated against a fixed 1000 px
   `@media (min-width/max-width)` blocks are evaluated against a fixed 1000 px
   desktop viewport; `@font-face`/`@import`/`@keyframes` are skipped.  Inline
   desktop viewport; `@font-face`/`@import`/`@keyframes` are skipped.  Inline
   `<svg>` subtrees and closed `<details>` are skipped (not renderable), and
   `<svg>` subtrees and closed `<details>` are skipped (not renderable), and
-  `<video>` gets a placeholder box.  `browser.c` owns a 960x640 window, the
-  layout/render, URL bar, history, status bar and inline `<img>` decoding.
+  `<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
+  inline `<img>` decoding.
   Page and image buffers come from `SYS_MEM_ALLOC`; the DOM uses fixed static
   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
   arenas (2560 nodes, 128 KB attributes, 1792 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
@@ -990,7 +993,10 @@ and the WM falls back to polling (`io_keyboard_irq_masked()`).
     rescales the cached bitmap on every repaint.  Video/audio elements are
     rescales the cached bitmap on every repaint.  Video/audio elements are
     placeholders, and pages that depend on `display:grid`/flex or CSS
     placeholders, and pages that depend on `display:grid`/flex or CSS
     variables (tagesschau's player and ad slots, for example) can show empty
     variables (tagesschau's player and ad slots, for example) can show empty
-    bordered boxes or miss colours.  TLS is phase A (no certificate
+    bordered boxes or miss colours.  Because the default canvas is dark, a
+    page that sets dark text but relies on the browser's default white
+    background can be hard to read; pages with their own full background and
+    colour rules are unaffected.  TLS is phase A (no certificate
     verification); `https` is shown as unverified.  The disk app is loaded
     verification); `https` is shown as unverified.  The disk app is loaded
     from FAT at spawn time, so a cold floppy start takes a few seconds; the
     from FAT at spawn time, so a cold floppy start takes a few seconds; the
     8 KB user stack means the layout state is deliberately static.
     8 KB user stack means the layout state is deliberately static.

+ 15 - 16
browser.c

@@ -38,10 +38,7 @@
 
 
 #define BR_IMG_RGB565(r, g, b) \
 #define BR_IMG_RGB565(r, g, b) \
 	((unsigned short)((((r) >> 3) << 11) | (((g) >> 2) << 5) | ((b) >> 3)))
 	((unsigned short)((((r) >> 3) << 11) | (((g) >> 2) << 5) | ((b) >> 3)))
-#define BR_WHITE  0xFFFF
-#define BR_BLACK  0x0000
 #define BR_GRAY   0x8410
 #define BR_GRAY   0x8410
-#define BR_LINK   0x001B
 
 
 enum {
 enum {
 	ID_URL = 1,
 	ID_URL = 1,
@@ -398,7 +395,7 @@ static int decode_image_data(const unsigned char *data, unsigned int len,
 		return -1;
 		return -1;
 	}
 	}
 	for (i = 0; i < (unsigned int)dw * (unsigned int)dh; i++)
 	for (i = 0; i < (unsigned int)dw * (unsigned int)dh; i++)
-		px[i] = BR_WHITE;
+		px[i] = ui.theme.bg;
 
 
 	{
 	{
 		struct img_blit b;
 		struct img_blit b;
@@ -413,8 +410,8 @@ static int decode_image_data(const unsigned char *data, unsigned int len,
 		b.x = 0;
 		b.x = 0;
 		b.y = 0;
 		b.y = 0;
 		b.scale = ((unsigned int)dw << 16) / decoded.w;
 		b.scale = ((unsigned int)dw << 16) / decoded.w;
-		b.bg = BR_WHITE;
-		b.bg2 = BR_WHITE;
+		b.bg = ui.theme.bg;
+		b.bg2 = ui.theme.bg;
 		b.flags = IMG_BLIT_OVER_DST;
 		b.flags = IMG_BLIT_OVER_DST;
 		img_draw(&decoded, &b);
 		img_draw(&decoded, &b);
 	}
 	}
@@ -1280,12 +1277,12 @@ static void load_home(int push)
 	{
 	{
 		static const char home[] =
 		static const char home[] =
 			"<html><head><title>Nebs Browser</title><style>"
 			"<html><head><title>Nebs Browser</title><style>"
-			"body { margin: 10px; color: #222222; }"
-			"h1 { color: #2255cc; }"
-			".box { background-color: #eeeeff; margin: 12px; "
+			"body { margin: 10px; color: #e4e6f0; }"
+			"h1 { color: #7fb0ff; }"
+			".box { background-color: #262b3a; margin: 12px; "
 			"padding: 10px; }"
 			"padding: 10px; }"
-			"a { color: #0033cc; }"
-			"pre { background-color: #f4f4f4; }"
+			"a { color: #7fb0ff; }"
+			"pre { background-color: #32384a; }"
 			"</style></head><body>"
 			"</style></head><body>"
 			"<h1>Nebs Browser</h1>"
 			"<h1>Nebs Browser</h1>"
 			"<p>A small HTML/CSS browser built on <b>ngui</b>, the "
 			"<p>A small HTML/CSS browser built on <b>ngui</b>, the "
@@ -1366,8 +1363,8 @@ static struct br_style base_style(void)
 {
 {
 	struct br_style s = { 0 };
 	struct br_style s = { 0 };
 
 
-	s.color = BR_BLACK;
-	s.bg = BR_WHITE;
+	s.color = ui.theme.text;
+	s.bg = ui.theme.bg;
 	s.has_bg = 0;
 	s.has_bg = 0;
 	s.border_color = 0;
 	s.border_color = 0;
 	s.scale = 1;
 	s.scale = 1;
@@ -1435,8 +1432,8 @@ static void flush_line(struct lay *l)
 					b.y = l->line_y;
 					b.y = l->line_y;
 					b.scale = ((unsigned int)r->iw << 16) /
 					b.scale = ((unsigned int)r->iw << 16) /
 						  bi->img.w;
 						  bi->img.w;
-					b.bg = BR_WHITE;
-					b.bg2 = BR_WHITE;
+					b.bg = ui.theme.bg;
+					b.bg2 = ui.theme.bg;
 					b.flags = IMG_BLIT_OVER_DST;
 					b.flags = IMG_BLIT_OVER_DST;
 					img_draw(&bi->img, &b);
 					img_draw(&bi->img, &b);
 				}
 				}
@@ -2259,7 +2256,7 @@ static void draw_page(struct ngui_rect page)
 	int old_panel, old_dim;
 	int old_panel, old_dim;
 
 
 	page_rect = page;
 	page_rect = page;
-	ngui_fill_rect(&ui, page, BR_WHITE);
+	ngui_fill_rect(&ui, page, ui.theme.bg);
 	if (!doc.nnode || (page_loading && doc.nnode <= 1)) {
 	if (!doc.nnode || (page_loading && doc.nnode <= 1)) {
 		const char *s = page_loading ? "Loading..." : "No page";
 		const char *s = page_loading ? "Loading..." : "No page";
 		int w = (int)ngui_text_width(s);
 		int w = (int)ngui_text_width(s);
@@ -2433,6 +2430,8 @@ void _start(const char *arg)
 	ngui_init(&ui, (unsigned short *)wi.fb, (int)wi.width, (int)wi.height);
 	ngui_init(&ui, (unsigned short *)wi.fb, (int)wi.width, (int)wi.height);
 	url_in.placeholder = "http://...";
 	url_in.placeholder = "http://...";
 	br_doc_init(&doc);
 	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(BR_VIEWPORT_W);
 	if (u_getcwd(cwd, sizeof(cwd)) != 0 || !cwd[0])
 	if (u_getcwd(cwd, sizeof(cwd)) != 0 || !cwd[0])
 		s_copy(cwd, "/", sizeof(cwd));
 		s_copy(cwd, "/", sizeof(cwd));

+ 16 - 2
browser_html.c

@@ -1392,6 +1392,20 @@ static unsigned int skip_at_rule(const char *s, unsigned int len,
 }
 }
 
 
 static unsigned int viewport_w = 1024;
 static unsigned int viewport_w = 1024;
+static unsigned short theme_text = 0x0000;
+static unsigned short theme_bg = 0xFFFF;
+static unsigned short theme_panel = 0xEF5D;
+static unsigned short theme_link = 0x001B;
+
+void br_set_theme(unsigned short text, unsigned short bg,
+		  unsigned short panel, unsigned short link)
+{
+	theme_text = text;
+	theme_bg = bg;
+	theme_panel = panel;
+	theme_link = link;
+}
+
 
 
 void br_set_viewport(unsigned int width)
 void br_set_viewport(unsigned int width)
 {
 {
@@ -1990,13 +2004,13 @@ void br_style_for(struct br_doc *d, unsigned int node,
 		break;
 		break;
 	case BR_TAG_PRE:
 	case BR_TAG_PRE:
 		out->mt = out->mb = 8; out->pl = 8;
 		out->mt = out->mb = 8; out->pl = 8;
-		out->has_bg = 1; out->bg = 0xEF5D;
+		out->has_bg = 1; out->bg = theme_panel;
 		break;
 		break;
 	case BR_TAG_CENTER:
 	case BR_TAG_CENTER:
 		out->align = BR_ALIGN_CENTER;
 		out->align = BR_ALIGN_CENTER;
 		break;
 		break;
 	case BR_TAG_A:
 	case BR_TAG_A:
-		out->color = 0x001B; out->underline = 1;
+		out->color = theme_link; out->underline = 1;
 		break;
 		break;
 	case BR_TAG_B: case BR_TAG_STRONG:
 	case BR_TAG_B: case BR_TAG_STRONG:
 		out->bold = 1;
 		out->bold = 1;

+ 2 - 0
browser_html.h

@@ -144,6 +144,8 @@ unsigned int br_parse_image_doc(struct br_doc *d, const char *src);
 /* External CSS is parsed by the browser after br_parse(); parse the inline
 /* External CSS is parsed by the browser after br_parse(); parse the inline
  * <style> blocks last so the cascade order matches the document. */
  * <style> blocks last so the cascade order matches the document. */
 void br_set_viewport(unsigned int width);
 void br_set_viewport(unsigned int width);
+void br_set_theme(unsigned short text, unsigned short bg,
+		  unsigned short panel, unsigned short link);
 void br_parse_css_text(struct br_doc *d, const char *css, unsigned int len);
 void br_parse_css_text(struct br_doc *d, const char *css, unsigned int len);
 void br_parse_inline_css(struct br_doc *d);
 void br_parse_inline_css(struct br_doc *d);
 void br_reset_styles(struct br_doc *d);
 void br_reset_styles(struct br_doc *d);

+ 8 - 8
testdata/browser/demo.html

@@ -2,12 +2,12 @@
 <head>
 <head>
 <title>Nebs demo</title>
 <title>Nebs demo</title>
 <style>
 <style>
-body { margin: 10px; color: #222222; }
-h1 { color: #cc3300; }
-h2 { color: #2255cc; }
-.note { background-color: #fff4cc; margin: 10px; padding: 8px; }
-pre { background-color: #eeeeee; padding: 6px; }
-a { color: #0044cc; }
+body { margin: 10px; color: #e4e6f0; }
+h1 { color: #ff8a66; }
+h2 { color: #7fb0ff; }
+.note { background-color: #2a2f3f; margin: 10px; padding: 8px; }
+pre { background-color: #32384a; padding: 6px; }
+a { color: #7fb0ff; }
 td { padding-right: 18px; }
 td { padding-right: 18px; }
 </style>
 </style>
 </head>
 </head>
@@ -18,8 +18,8 @@ Nebs browser: HTML, a little CSS and an inline image, with no JavaScript.</p>
 
 
 <div class="note">
 <div class="note">
 <b>Inline styles and classes:</b>
 <b>Inline styles and classes:</b>
-<span style="color:#008000;">green span</span>,
-<span style="background-color:#ddddff;">light background</span>,
+<span style="color:#7ee787;">green span</span>,
+<span style="background-color:#32384a;">light background</span>,
 <b>bold</b>, <u>underlined</u> and <a href="TEST.TXT">a relative link</a>.
 <b>bold</b>, <u>underlined</u> and <a href="TEST.TXT">a relative link</a>.
 </div>
 </div>