fix: update NetSurf port & montauk frontend to use new paths for fonts and icons
This commit is contained in:
1 parent
6f3cf99667
commit
35e3d1a0bb
21 files changed
+3376
-34
No files matched your search
@@ -1,14 +1,34 @@
|
||||
diff --git a/frontends/monkey/main.c b/frontends/monkey/main.c
|
||||
index 463f0bea6..578d148e4 100644
|
||||
index 463f0bea6..04b0e1c9f 100644
|
||||
--- a/frontends/monkey/main.c
|
||||
+++ b/frontends/monkey/main.c
|
||||
@@ -422,7 +422,12 @@ main(int argc, char **argv)
|
||||
@@ -422,7 +422,32 @@ main(int argc, char **argv)
|
||||
setbuf(stderr, NULL);
|
||||
|
||||
/* Prep the search paths */
|
||||
+#if defined(__montauk__)
|
||||
+ char bundle_res[PATH_MAX];
|
||||
+ char resource_path[PATH_MAX * 2];
|
||||
+ const char *exec_path = argv[0];
|
||||
+ const char *last_slash = strrchr(exec_path, '/');
|
||||
+ size_t bundle_dir_len = last_slash == NULL ? 0 :
|
||||
+ (size_t)(last_slash - exec_path + 1);
|
||||
+
|
||||
+ /* Locate res/ beside the running ELF so the app bundle is relocatable.
|
||||
+ * MONKEY_RESPATH remains as a fallback for older startup environments. */
|
||||
+ if (bundle_dir_len > 0 &&
|
||||
+ bundle_dir_len + sizeof("res/") <= sizeof(bundle_res)) {
|
||||
+ memcpy(bundle_res, exec_path, bundle_dir_len);
|
||||
+ memcpy(bundle_res + bundle_dir_len, "res/", sizeof("res/"));
|
||||
+ } else {
|
||||
+ snprintf(bundle_res, sizeof(bundle_res), "%s", MONKEY_RESPATH);
|
||||
+ }
|
||||
+
|
||||
+ /* see NS_RESPATH_SEP: ':' is part of a MontaukOS drive path */
|
||||
+ respaths = nsmonkey_init_resource("${HOME}/.netsurf/;${NETSURFRES};"MONKEY_RESPATH";./frontends/monkey/res");
|
||||
+ snprintf(resource_path, sizeof(resource_path),
|
||||
+ "${HOME}/.netsurf/;${NETSURFRES};%s;%s;./frontends/monkey/res",
|
||||
+ bundle_res, MONKEY_RESPATH);
|
||||
+ respaths = nsmonkey_init_resource(resource_path);
|
||||
+#else
|
||||
respaths = nsmonkey_init_resource("${HOME}/.netsurf/:${NETSURFRES}:"MONKEY_RESPATH":./frontends/monkey/res");
|
||||
+#endif
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
diff --git a/content/fetch.c b/content/fetch.c
|
||||
index f066ea40c..a804002c4 100644
|
||||
--- a/content/fetch.c
|
||||
+++ b/content/fetch.c
|
||||
@@ -49,6 +49,9 @@
|
||||
#include "content/fetchers/data.h"
|
||||
#include "content/fetchers/file/file.h"
|
||||
#include "javascript/fetcher.h"
|
||||
+#ifdef WITH_MONTAUK_FETCHER
|
||||
+#include "content/fetchers/montauk.h"
|
||||
+#endif
|
||||
#include "content/urldb.h"
|
||||
|
||||
/** The maximum number of fetchers that can be added */
|
||||
@@ -294,6 +297,13 @@ nserror fetcher_init(void)
|
||||
}
|
||||
#endif
|
||||
|
||||
+#ifdef WITH_MONTAUK_FETCHER
|
||||
+ ret = fetch_montauk_register();
|
||||
+ if (ret != NSERROR_OK) {
|
||||
+ return ret;
|
||||
+ }
|
||||
+#endif
|
||||
+
|
||||
ret = fetch_data_register();
|
||||
if (ret != NSERROR_OK) {
|
||||
return ret;
|
||||
diff --git a/content/fetchers/Makefile b/content/fetchers/Makefile
|
||||
index f7752918a..74eddf5a3 100644
|
||||
--- a/content/fetchers/Makefile
|
||||
+++ b/content/fetchers/Makefile
|
||||
@@ -4,6 +4,10 @@ S_FETCHERS_YES := data.c resource.c
|
||||
S_FETCHERS_NO :=
|
||||
S_FETCHERS_$(NETSURF_USE_CURL) += curl.c
|
||||
|
||||
+ifeq ($(NETSURF_USE_MONTAUK),YES)
|
||||
+S_FETCHERS_YES += montauk.c
|
||||
+endif
|
||||
+
|
||||
S_FETCHERS := $(addprefix fetchers/,$(S_FETCHERS_YES))
|
||||
|
||||
# about fetcher
|
||||
@@ -0,0 +1,236 @@
|
||||
diff --git a/frontends/monkey/browser.h b/frontends/monkey/browser.h
|
||||
--- a/frontends/monkey/browser.h
|
||||
+++ b/frontends/monkey/browser.h
|
||||
@@ -37,1 +37,6 @@ struct gui_window {
|
||||
+#if defined(__montauk__)
|
||||
+ int native_id;
|
||||
+ uint32_t *pixels;
|
||||
+ int clip_x0, clip_y0, clip_x1, clip_y1;
|
||||
+#endif
|
||||
char *host; /* Ignore this, it's in case RING*() gets debugging for fetchers */
|
||||
diff --git a/frontends/monkey/browser.c b/frontends/monkey/browser.c
|
||||
--- a/frontends/monkey/browser.c
|
||||
+++ b/frontends/monkey/browser.c
|
||||
@@ -21,4 +21,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
+#if defined(__montauk__)
|
||||
+#include <montauk.h>
|
||||
+#endif
|
||||
|
||||
@@ -88,3 +91,14 @@ gui_window_create(struct browser_window *bw,
|
||||
ret->width = 800;
|
||||
ret->height = 600;
|
||||
+#if defined(__montauk__)
|
||||
+ mtk_win_result native;
|
||||
+ if (mtk_win_create("NetSurf", ret->width, ret->height, &native) != 0) {
|
||||
+ free(ret);
|
||||
+ return NULL;
|
||||
+ }
|
||||
+ ret->native_id = native.id;
|
||||
+ ret->pixels = (uint32_t *)(uintptr_t)native.pixels;
|
||||
+ ret->clip_x1 = ret->width;
|
||||
+ ret->clip_y1 = ret->height;
|
||||
+#endif
|
||||
|
||||
@@ -107,4 +121,7 @@ gui_window_destroy(struct gui_window *g)
|
||||
{
|
||||
moutf(MOUT_WINDOW, "DESTROY WIN %u", g->win_num);
|
||||
+#if defined(__montauk__)
|
||||
+ mtk_win_destroy(g->native_id);
|
||||
+#endif
|
||||
RING_REMOVE(gw_ring, g);
|
||||
free(g);
|
||||
@@ -569,6 +586,7 @@ monkey_window_handle_redraw(int argc, char **argv)
|
||||
struct redraw_context ctx = {
|
||||
.interactive = true,
|
||||
.background_images = true,
|
||||
- .plot = monkey_plotters
|
||||
+ .plot = monkey_plotters,
|
||||
+ .priv = NULL
|
||||
};
|
||||
|
||||
@@ -597,7 +615,17 @@ monkey_window_handle_redraw(int argc, char **argv)
|
||||
}
|
||||
|
||||
NSLOG(netsurf, INFO, "Issue redraw");
|
||||
+#if defined(__montauk__)
|
||||
+ ctx.priv = gw;
|
||||
+ for (int y = 0; y < gw->height; y++) {
|
||||
+ for (int x = 0; x < gw->width; x++)
|
||||
+ gw->pixels[y * gw->width + x] = 0xffffffffu;
|
||||
+ }
|
||||
+#endif
|
||||
moutf(MOUT_WINDOW, "REDRAW WIN %d START", atoi(argv[2]));
|
||||
browser_window_redraw(gw->bw, gw->scrollx, gw->scrolly, &clip, &ctx);
|
||||
+#if defined(__montauk__)
|
||||
+ mtk_win_present(gw->native_id);
|
||||
+#endif
|
||||
moutf(MOUT_WINDOW, "REDRAW WIN %d STOP", atoi(argv[2]));
|
||||
}
|
||||
diff --git a/frontends/monkey/plot.c b/frontends/monkey/plot.c
|
||||
--- a/frontends/monkey/plot.c
|
||||
+++ b/frontends/monkey/plot.c
|
||||
@@ -23,4 +23,83 @@
|
||||
#include "netsurf/plotters.h"
|
||||
|
||||
#include "monkey/output.h"
|
||||
+#include "monkey/browser.h"
|
||||
+
|
||||
+#if defined(__montauk__)
|
||||
+extern const unsigned char mtk_font_data[] __asm__("_ZN3gui9font_dataE");
|
||||
+
|
||||
+struct bitmap {
|
||||
+ void *ptr;
|
||||
+ size_t rowstride;
|
||||
+ int width;
|
||||
+ int height;
|
||||
+ bool opaque;
|
||||
+};
|
||||
+
|
||||
+static uint32_t native_colour(colour c)
|
||||
+{
|
||||
+ if (c == NS_TRANSPARENT) return 0;
|
||||
+ return 0xff000000u | ((c & 0x0000ffu) << 16) |
|
||||
+ (c & 0x00ff00u) | ((c & 0xff0000u) >> 16);
|
||||
+}
|
||||
+
|
||||
+static void native_pixel(struct gui_window *gw, int x, int y, uint32_t colour)
|
||||
+{
|
||||
+ if (gw == NULL || gw->pixels == NULL || x < gw->clip_x0 || y < gw->clip_y0 ||
|
||||
+ x >= gw->clip_x1 || y >= gw->clip_y1 || x < 0 || y < 0 ||
|
||||
+ x >= gw->width || y >= gw->height || colour == 0) return;
|
||||
+ gw->pixels[y * gw->width + x] = colour;
|
||||
+}
|
||||
+
|
||||
+static void native_fill(struct gui_window *gw, int x0, int y0, int x1, int y1,
|
||||
+ uint32_t colour)
|
||||
+{
|
||||
+ if (gw == NULL || colour == 0) return;
|
||||
+ if (x0 < gw->clip_x0) x0 = gw->clip_x0;
|
||||
+ if (y0 < gw->clip_y0) y0 = gw->clip_y0;
|
||||
+ if (x1 > gw->clip_x1) x1 = gw->clip_x1;
|
||||
+ if (y1 > gw->clip_y1) y1 = gw->clip_y1;
|
||||
+ x0 = x0 < 0 ? 0 : x0; y0 = y0 < 0 ? 0 : y0;
|
||||
+ if (x1 > gw->width) x1 = gw->width;
|
||||
+ if (y1 > gw->height) y1 = gw->height;
|
||||
+ for (int y = y0; y < y1; y++)
|
||||
+ for (int x = x0; x < x1; x++) gw->pixels[y * gw->width + x] = colour;
|
||||
+}
|
||||
+
|
||||
+static void native_line(struct gui_window *gw, int x0, int y0, int x1, int y1,
|
||||
+ uint32_t colour)
|
||||
+{
|
||||
+ int dx = x1 > x0 ? x1 - x0 : x0 - x1, sx = x0 < x1 ? 1 : -1;
|
||||
+ int dy = -(y1 > y0 ? y1 - y0 : y0 - y1), sy = y0 < y1 ? 1 : -1;
|
||||
+ int err = dx + dy;
|
||||
+ for (;;) {
|
||||
+ native_pixel(gw, x0, y0, colour);
|
||||
+ if (x0 == x1 && y0 == y1) break;
|
||||
+ int twice = 2 * err;
|
||||
+ if (twice >= dy) { err += dy; x0 += sx; }
|
||||
+ if (twice <= dx) { err += dx; y0 += sy; }
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
+static void native_text(struct gui_window *gw, int x, int baseline,
|
||||
+ const char *text, size_t length, const struct plot_font_style *style)
|
||||
+{
|
||||
+ int px = plot_style_fixed_to_int(style->size);
|
||||
+ int sx = px > 8 ? px / 8 : 1;
|
||||
+ int sy = px > 16 ? px / 16 : 1;
|
||||
+ int top = baseline - 13 * sy;
|
||||
+ uint32_t colour = native_colour(style->foreground);
|
||||
+ for (size_t i = 0; i < length; i++) {
|
||||
+ unsigned char ch = (unsigned char)text[i];
|
||||
+ if (ch >= 128) continue;
|
||||
+ const unsigned char *glyph = mtk_font_data + ch * 16;
|
||||
+ for (int row = 0; row < 16; row++)
|
||||
+ for (int col = 0; col < 8; col++)
|
||||
+ if (glyph[row] & (0x80u >> col))
|
||||
+ native_fill(gw, x + col * sx, top + row * sy,
|
||||
+ x + (col + 1) * sx, top + (row + 1) * sy, colour);
|
||||
+ x += px > 0 ? px : 8;
|
||||
+ }
|
||||
+}
|
||||
+#endif
|
||||
|
||||
@@ -37,3 +116,12 @@ monkey_plot_clip(const struct redraw_context *ctx, const struct rect *clip)
|
||||
{
|
||||
+#if defined(__montauk__)
|
||||
+ struct gui_window *gw = ctx->priv;
|
||||
+ if (gw != NULL) {
|
||||
+ gw->clip_x0 = clip->x0;
|
||||
+ gw->clip_y0 = clip->y0;
|
||||
+ gw->clip_x1 = clip->x1;
|
||||
+ gw->clip_y1 = clip->y1;
|
||||
+ }
|
||||
+#endif
|
||||
moutf(MOUT_PLOT, "CLIP X0 %d Y0 %d X1 %d Y1 %d",
|
||||
clip->x0, clip->y0, clip->x1, clip->y1);
|
||||
@@ -108,3 +196,6 @@ monkey_plot_line(const struct redraw_context *ctx,
|
||||
{
|
||||
+#if defined(__montauk__)
|
||||
+ native_line(ctx->priv, line->x0, line->y0, line->x1, line->y1, native_colour(style->stroke_colour));
|
||||
+#endif
|
||||
moutf(MOUT_PLOT, "LINE X0 %d Y0 %d X1 %d Y1 %d",
|
||||
line->x0, line->y0, line->x1, line->y1);
|
||||
@@ -132,3 +223,16 @@ monkey_plot_rectangle(const struct redraw_context *ctx,
|
||||
{
|
||||
+#if defined(__montauk__)
|
||||
+ struct gui_window *gw = ctx->priv;
|
||||
+ if (style->fill_type != PLOT_OP_TYPE_NONE)
|
||||
+ native_fill(gw, rect->x0, rect->y0, rect->x1, rect->y1,
|
||||
+ native_colour(style->fill_colour));
|
||||
+ if (style->stroke_type != PLOT_OP_TYPE_NONE) {
|
||||
+ uint32_t c = native_colour(style->stroke_colour);
|
||||
+ native_line(gw, rect->x0, rect->y0, rect->x1 - 1, rect->y0, c);
|
||||
+ native_line(gw, rect->x1 - 1, rect->y0, rect->x1 - 1, rect->y1 - 1, c);
|
||||
+ native_line(gw, rect->x1 - 1, rect->y1 - 1, rect->x0, rect->y1 - 1, c);
|
||||
+ native_line(gw, rect->x0, rect->y1 - 1, rect->x0, rect->y0, c);
|
||||
+ }
|
||||
+#endif
|
||||
moutf(MOUT_PLOT, "RECT X0 %d Y0 %d X1 %d Y1 %d",
|
||||
rect->x0, rect->y0, rect->x1, rect->y1);
|
||||
@@ -222,3 +325,33 @@ monkey_plot_bitmap(const struct redraw_context *ctx,
|
||||
{
|
||||
+#if defined(__montauk__)
|
||||
+ struct gui_window *gw = ctx->priv;
|
||||
+ if (bitmap != NULL && bitmap->ptr != NULL && width > 0 && height > 0) {
|
||||
+ uint32_t *src = bitmap->ptr;
|
||||
+ for (int dy = 0; dy < height; dy++) {
|
||||
+ int sy = (int)((long long)dy * bitmap->height / height);
|
||||
+ for (int dx = 0; dx < width; dx++) {
|
||||
+ int sx = (int)((long long)dx * bitmap->width / width);
|
||||
+ uint32_t p = src[sy * (bitmap->rowstride / 4) + sx];
|
||||
+ unsigned a = p >> 24;
|
||||
+ if (a == 0) continue;
|
||||
+ /* NetSurf bitmap storage is RGBA in memory, which is this
|
||||
+ * little-endian word layout; convert to ARGB framebuffer. */
|
||||
+ uint32_t out = 0xff000000u | ((p & 0xffu) << 16) |
|
||||
+ (p & 0xff00u) | ((p >> 16) & 0xffu);
|
||||
+ if (a != 255) {
|
||||
+ int tx = x + dx, ty = y + dy;
|
||||
+ if (tx >= 0 && ty >= 0 && tx < gw->width && ty < gw->height) {
|
||||
+ uint32_t d = gw->pixels[ty * gw->width + tx];
|
||||
+ unsigned r = (((out >> 16) & 255) * a + ((d >> 16) & 255) * (255-a)) / 255;
|
||||
+ unsigned g = (((out >> 8) & 255) * a + ((d >> 8) & 255) * (255-a)) / 255;
|
||||
+ unsigned b = ((out & 255) * a + (d & 255) * (255-a)) / 255;
|
||||
+ out = 0xff000000u | (r << 16) | (g << 8) | b;
|
||||
+ }
|
||||
+ }
|
||||
+ native_pixel(gw, x + dx, y + dy, out);
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
+#endif
|
||||
moutf(MOUT_PLOT, "BITMAP X %d Y %d WIDTH %d HEIGHT %d",
|
||||
x, y, width, height);
|
||||
@@ -247,3 +380,6 @@ monkey_plot_text(const struct redraw_context *ctx,
|
||||
{
|
||||
+#if defined(__montauk__)
|
||||
+ native_text(ctx->priv, x, y, text, length, fstyle);
|
||||
+#endif
|
||||
moutf(MOUT_PLOT, "TEXT X %d Y %d STR %.*s", x, y, (int)length, text);
|
||||
return NSERROR_OK;
|
||||
@@ -0,0 +1,28 @@
|
||||
diff --git a/frontends/monkey/browser.c b/frontends/monkey/browser.c
|
||||
--- a/frontends/monkey/browser.c
|
||||
+++ b/frontends/monkey/browser.c
|
||||
@@ -172,4 +172,24 @@ static void
|
||||
gui_window_stop_throbber(struct gui_window *g)
|
||||
{
|
||||
+#if defined(__montauk__)
|
||||
+ struct rect clip = {
|
||||
+ .x0 = 0,
|
||||
+ .y0 = 0,
|
||||
+ .x1 = g->width,
|
||||
+ .y1 = g->height
|
||||
+ };
|
||||
+ struct redraw_context ctx = {
|
||||
+ .interactive = true,
|
||||
+ .background_images = true,
|
||||
+ .plot = monkey_plotters,
|
||||
+ .priv = g
|
||||
+ };
|
||||
+ for (int y = 0; y < g->height; y++) {
|
||||
+ for (int x = 0; x < g->width; x++)
|
||||
+ g->pixels[y * g->width + x] = 0xffffffffu;
|
||||
+ }
|
||||
+ browser_window_redraw(g->bw, g->scrollx, g->scrolly, &clip, &ctx);
|
||||
+ mtk_win_present(g->native_id);
|
||||
+#endif
|
||||
moutf(MOUT_WINDOW, "STOP_THROBBER WIN %u", g->win_num);
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
diff --git a/frontends/monkey/plot.c b/frontends/monkey/plot.c
|
||||
--- a/frontends/monkey/plot.c
|
||||
+++ b/frontends/monkey/plot.c
|
||||
@@ -27,7 +27,7 @@
|
||||
#include "monkey/browser.h"
|
||||
|
||||
#if defined(__montauk__)
|
||||
-extern const unsigned char mtk_font_data[] __asm__("_ZN3gui9font_dataE");
|
||||
+#include "content/fetchers/montauk_bridge.h"
|
||||
|
||||
struct bitmap {
|
||||
void *ptr;
|
||||
@@ -69,20 +69,10 @@ static void native_text(struct gui_window *gw, int x, int baseline,
|
||||
const char *text, size_t length, const struct plot_font_style *style)
|
||||
{
|
||||
int px = plot_style_fixed_to_int(style->size);
|
||||
- int sx = px > 8 ? px / 8 : 1;
|
||||
- int sy = px > 16 ? px / 16 : 1;
|
||||
- int top = baseline - 13 * sy;
|
||||
- uint32_t colour = native_colour(style->foreground);
|
||||
- for (size_t i = 0; i < length; i++) {
|
||||
- unsigned char ch = (unsigned char)text[i];
|
||||
- if (ch >= 128) continue;
|
||||
- const unsigned char *glyph = mtk_font_data + ch * 16;
|
||||
- for (int row = 0; row < 16; row++)
|
||||
- for (int col = 0; col < 8; col++)
|
||||
- if (glyph[row] & (0x80u >> col))
|
||||
- native_fill(gw, x + col * sx, top + row * sy,
|
||||
- x + (col + 1) * sx, top + (row + 1) * sy, colour);
|
||||
- x += px > 0 ? px : 8;
|
||||
- }
|
||||
+ if (gw == NULL || gw->pixels == NULL) return;
|
||||
+ mtk_netsurf_font_draw(gw->pixels, gw->width, gw->height,
|
||||
+ gw->clip_x0, gw->clip_y0, gw->clip_x1, gw->clip_y1,
|
||||
+ x, baseline, text, length, native_colour(style->foreground),
|
||||
+ style->family, style->weight, style->flags, px);
|
||||
}
|
||||
#endif
|
||||
diff --git a/frontends/monkey/layout.c b/frontends/monkey/layout.c
|
||||
--- a/frontends/monkey/layout.c
|
||||
+++ b/frontends/monkey/layout.c
|
||||
@@ -30,10 +30,25 @@
|
||||
|
||||
#include "monkey/layout.h"
|
||||
|
||||
+#if defined(__montauk__)
|
||||
+#include "content/fetchers/montauk_bridge.h"
|
||||
+#endif
|
||||
+
|
||||
+static int font_width(const plot_font_style_t *fstyle,
|
||||
+ const char *string, size_t length)
|
||||
+{
|
||||
+#if defined(__montauk__)
|
||||
+ return mtk_netsurf_font_width(fstyle->family, fstyle->weight,
|
||||
+ fstyle->flags, plot_style_fixed_to_int(fstyle->size), string, length);
|
||||
+#else
|
||||
+ return (fstyle->size * utf8_bounded_length(string, length)) / PLOT_STYLE_SCALE;
|
||||
+#endif
|
||||
+}
|
||||
+
|
||||
static nserror nsfont_width(const plot_font_style_t *fstyle,
|
||||
const char *string, size_t length,
|
||||
int *width)
|
||||
{
|
||||
- *width = (fstyle->size * utf8_bounded_length(string, length)) / PLOT_STYLE_SCALE;
|
||||
+ *width = font_width(fstyle, string, length);
|
||||
return NSERROR_OK;
|
||||
}
|
||||
@@ -55,8 +70,22 @@ static nserror nsfont_position_in_string(const plot_font_style_t *fstyle,
|
||||
int x, size_t *char_offset, int *actual_x)
|
||||
{
|
||||
- *char_offset = x / (fstyle->size / PLOT_STYLE_SCALE);
|
||||
- if (*char_offset > length)
|
||||
- *char_offset = length;
|
||||
- *actual_x = *char_offset * (fstyle->size / PLOT_STYLE_SCALE);
|
||||
+ size_t offset = 0, previous = 0;
|
||||
+ int previous_width = 0;
|
||||
+ while (offset < length) {
|
||||
+ previous = offset;
|
||||
+ offset = utf8_next(string, length, offset);
|
||||
+ int next_width = font_width(fstyle, string, offset);
|
||||
+ if (next_width > x) {
|
||||
+ if (x - previous_width > next_width - x) {
|
||||
+ *char_offset = offset; *actual_x = next_width;
|
||||
+ } else {
|
||||
+ *char_offset = previous; *actual_x = previous_width;
|
||||
+ }
|
||||
+ return NSERROR_OK;
|
||||
+ }
|
||||
+ previous_width = next_width;
|
||||
+ }
|
||||
+ *char_offset = length;
|
||||
+ *actual_x = previous_width;
|
||||
return NSERROR_OK;
|
||||
}
|
||||
@@ -90,21 +119,25 @@ static nserror nsfont_split(const plot_font_style_t *fstyle,
|
||||
int x, size_t *char_offset, int *actual_x)
|
||||
{
|
||||
- int c_off = *char_offset = x / (fstyle->size / PLOT_STYLE_SCALE);
|
||||
- if (*char_offset > length) {
|
||||
+ size_t offset = 0, last_space = 0, first_over = length;
|
||||
+ while (offset < length) {
|
||||
+ size_t next = utf8_next(string, length, offset);
|
||||
+ if (string[offset] == ' ') last_space = offset;
|
||||
+ if (font_width(fstyle, string, next) > x) {
|
||||
+ first_over = next;
|
||||
+ break;
|
||||
+ }
|
||||
+ offset = next;
|
||||
+ }
|
||||
+ if (first_over == length && font_width(fstyle, string, length) <= x) {
|
||||
*char_offset = length;
|
||||
+ } else if (last_space != 0) {
|
||||
+ *char_offset = last_space;
|
||||
} else {
|
||||
- while (*char_offset > 0) {
|
||||
- if (string[*char_offset] == ' ')
|
||||
- break;
|
||||
- (*char_offset)--;
|
||||
- }
|
||||
- if (*char_offset == 0) {
|
||||
- *char_offset = c_off;
|
||||
- while (*char_offset < length && string[*char_offset] != ' ') {
|
||||
- (*char_offset)++;
|
||||
- }
|
||||
- }
|
||||
+ *char_offset = first_over;
|
||||
+ while (*char_offset < length && string[*char_offset] != ' ')
|
||||
+ (*char_offset)++;
|
||||
}
|
||||
- *actual_x = *char_offset * (fstyle->size / PLOT_STYLE_SCALE);
|
||||
+ if (*char_offset == 0) *char_offset = first_over != 0 ? first_over : length;
|
||||
+ *actual_x = font_width(fstyle, string, *char_offset);
|
||||
return NSERROR_OK;
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
diff --git a/frontends/monkey/plot.c b/frontends/monkey/plot.c
|
||||
--- a/frontends/monkey/plot.c
|
||||
+++ b/frontends/monkey/plot.c
|
||||
@@ -20,13 +20,21 @@
|
||||
|
||||
#include "utils/utils.h"
|
||||
#include "utils/errors.h"
|
||||
+#include "netsurf/browser.h"
|
||||
#include "netsurf/plotters.h"
|
||||
|
||||
#include "monkey/output.h"
|
||||
#include "monkey/browser.h"
|
||||
|
||||
#if defined(__montauk__)
|
||||
#include "content/fetchers/montauk_bridge.h"
|
||||
+
|
||||
+static int native_font_px(plot_style_fixed point_size)
|
||||
+{
|
||||
+ int pixels = (int)(((int64_t)point_size * browser_get_dpi() +
|
||||
+ 36 * PLOT_STYLE_SCALE) / (72 * PLOT_STYLE_SCALE));
|
||||
+ return pixels > 0 ? pixels : 1;
|
||||
+}
|
||||
|
||||
struct bitmap {
|
||||
void *ptr;
|
||||
@@ -70,6 +78,6 @@ static void native_text(struct gui_window *gw, int x, int baseline,
|
||||
const char *text, size_t length, const struct plot_font_style *style)
|
||||
{
|
||||
- int px = plot_style_fixed_to_int(style->size);
|
||||
+ int px = native_font_px(style->size);
|
||||
if (gw == NULL || gw->pixels == NULL) return;
|
||||
mtk_netsurf_font_draw(gw->pixels, gw->width, gw->height,
|
||||
gw->clip_x0, gw->clip_y0, gw->clip_x1, gw->clip_y1,
|
||||
diff --git a/frontends/monkey/layout.c b/frontends/monkey/layout.c
|
||||
--- a/frontends/monkey/layout.c
|
||||
+++ b/frontends/monkey/layout.c
|
||||
@@ -25,13 +25,21 @@
|
||||
#include <stddef.h>
|
||||
|
||||
#include "utils/utf8.h"
|
||||
+#include "netsurf/browser.h"
|
||||
#include "netsurf/plot_style.h"
|
||||
#include "netsurf/layout.h"
|
||||
|
||||
#include "monkey/layout.h"
|
||||
|
||||
#if defined(__montauk__)
|
||||
#include "content/fetchers/montauk_bridge.h"
|
||||
+
|
||||
+static int native_font_px(plot_style_fixed point_size)
|
||||
+{
|
||||
+ int pixels = (int)(((int64_t)point_size * browser_get_dpi() +
|
||||
+ 36 * PLOT_STYLE_SCALE) / (72 * PLOT_STYLE_SCALE));
|
||||
+ return pixels > 0 ? pixels : 1;
|
||||
+}
|
||||
#endif
|
||||
|
||||
static int font_width(const plot_font_style_t *fstyle,
|
||||
@@ -38,7 +46,7 @@ static int font_width(const plot_font_style_t *fstyle,
|
||||
{
|
||||
#if defined(__montauk__)
|
||||
return mtk_netsurf_font_width(fstyle->family, fstyle->weight,
|
||||
- fstyle->flags, plot_style_fixed_to_int(fstyle->size), string, length);
|
||||
+ fstyle->flags, native_font_px(fstyle->size), string, length);
|
||||
#else
|
||||
return (fstyle->size * utf8_bounded_length(string, length)) / PLOT_STYLE_SCALE;
|
||||
#endif
|
||||
@@ -0,0 +1,544 @@
|
||||
diff --git a/frontends/monkey/Makefile b/frontends/monkey/Makefile
|
||||
index d2dae3e..d83415f 100644
|
||||
--- a/frontends/monkey/Makefile
|
||||
+++ b/frontends/monkey/Makefile
|
||||
@@ -50,7 +50,7 @@ endif
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
# S_MONKEY are sources purely for the MONKEY build
|
||||
-S_FRONTEND := main.c output.c filetype.c schedule.c bitmap.c plot.c browser.c \
|
||||
+S_FRONTEND := main.c output.c filetype.c schedule.c bitmap.c plot.c browser.c montauk_ui.c \
|
||||
download.c 401login.c layout.c dispatch.c fetch.c
|
||||
|
||||
|
||||
diff --git a/frontends/monkey/browser.c b/frontends/monkey/browser.c
|
||||
index 4a33fae..d2b0c78 100644
|
||||
--- a/frontends/monkey/browser.c
|
||||
+++ b/frontends/monkey/browser.c
|
||||
@@ -41,11 +41,92 @@
|
||||
#include "monkey/output.h"
|
||||
#include "monkey/browser.h"
|
||||
#include "monkey/plot.h"
|
||||
+#if defined(__montauk__)
|
||||
+#include "monkey/montauk_ui.h"
|
||||
+#include "content/fetchers/montauk_bridge.h"
|
||||
+#endif
|
||||
|
||||
static uint32_t win_ctr = 0;
|
||||
|
||||
static struct gui_window *gw_ring = NULL;
|
||||
|
||||
+#if defined(__montauk__)
|
||||
+static struct gui_window *native_active;
|
||||
+
|
||||
+struct gui_window *monkey_native_get_window(void)
|
||||
+{
|
||||
+ return native_active != NULL ? native_active : gw_ring;
|
||||
+}
|
||||
+
|
||||
+size_t monkey_native_tab_count(void)
|
||||
+{
|
||||
+ size_t count = 0;
|
||||
+ struct gui_window *item = gw_ring;
|
||||
+ if (item != NULL) do {
|
||||
+ if (native_active == NULL || item->native_id == native_active->native_id) count++;
|
||||
+ item = item->r_next;
|
||||
+ } while (item != gw_ring);
|
||||
+ return count;
|
||||
+}
|
||||
+
|
||||
+struct gui_window *monkey_native_tab_at(size_t index)
|
||||
+{
|
||||
+ struct gui_window *item = gw_ring;
|
||||
+ if (item != NULL) do {
|
||||
+ if (native_active == NULL || item->native_id == native_active->native_id) {
|
||||
+ if (index == 0) return item;
|
||||
+ index--;
|
||||
+ }
|
||||
+ item = item->r_next;
|
||||
+ } while (item != gw_ring);
|
||||
+ return NULL;
|
||||
+}
|
||||
+
|
||||
+void monkey_native_activate_window(struct gui_window *gw)
|
||||
+{
|
||||
+ if (gw != NULL) {
|
||||
+ native_active = gw;
|
||||
+ gw->dirty = true;
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
+void monkey_native_resize_tabs(struct gui_window *gw, int width, int height,
|
||||
+ uint32_t *pixels)
|
||||
+{
|
||||
+ struct gui_window *item = gw_ring;
|
||||
+ if (item != NULL) do {
|
||||
+ if (item->native_id == gw->native_id) {
|
||||
+ item->width = width;
|
||||
+ item->height = height;
|
||||
+ item->pixels = pixels;
|
||||
+ item->dirty = true;
|
||||
+ browser_window_schedule_reformat(item->bw);
|
||||
+ }
|
||||
+ item = item->r_next;
|
||||
+ } while (item != gw_ring);
|
||||
+}
|
||||
+
|
||||
+void monkey_native_set_scale(struct gui_window *gw, int scale)
|
||||
+{
|
||||
+ struct gui_window *item = gw_ring;
|
||||
+ if (scale < 0) scale = 0;
|
||||
+ if (scale > 2) scale = 2;
|
||||
+ if (item != NULL) do {
|
||||
+ if (item->native_id == gw->native_id) {
|
||||
+ struct mtk_netsurf_chrome_metrics metrics;
|
||||
+ mtk_netsurf_chrome_metrics(scale, item->width,
|
||||
+ (int)monkey_native_tab_count(), &metrics);
|
||||
+ item->ui_scale = scale;
|
||||
+ item->chrome_height = metrics.chrome_h;
|
||||
+ item->status_height = metrics.status_h;
|
||||
+ item->dirty = true;
|
||||
+ browser_window_schedule_reformat(item->bw);
|
||||
+ }
|
||||
+ item = item->r_next;
|
||||
+ } while (item != gw_ring);
|
||||
+}
|
||||
+#endif
|
||||
+
|
||||
/* exported function documented in monkey/browser.h */
|
||||
nserror monkey_warn_user(const char *warning, const char *detail)
|
||||
{
|
||||
@@ -88,18 +169,39 @@ gui_window_create(struct browser_window *bw,
|
||||
ret->win_num = win_ctr++;
|
||||
ret->bw = bw;
|
||||
|
||||
- ret->width = 800;
|
||||
- ret->height = 600;
|
||||
+ ret->width = 1000;
|
||||
+ ret->height = 700;
|
||||
#if defined(__montauk__)
|
||||
- mtk_win_result native;
|
||||
- if (mtk_win_create("NetSurf", ret->width, ret->height, &native) != 0) {
|
||||
- free(ret);
|
||||
- return NULL;
|
||||
+ if ((flags & GW_CREATE_TAB) && existing != NULL) {
|
||||
+ ret->width = existing->width;
|
||||
+ ret->height = existing->height;
|
||||
+ ret->native_id = existing->native_id;
|
||||
+ ret->pixels = existing->pixels;
|
||||
+ ret->ui_scale = existing->ui_scale;
|
||||
+ ret->chrome_height = existing->chrome_height;
|
||||
+ ret->status_height = existing->status_height;
|
||||
+ } else {
|
||||
+ mtk_win_result native;
|
||||
+ if (mtk_win_create("NetSurf", ret->width, ret->height, &native) != 0) {
|
||||
+ free(ret);
|
||||
+ return NULL;
|
||||
+ }
|
||||
+ ret->native_id = native.id;
|
||||
+ ret->pixels = (uint32_t *)(uintptr_t)native.pixels;
|
||||
+ ret->ui_scale = mtk_win_getscale();
|
||||
+ if (ret->ui_scale < 0) ret->ui_scale = 0;
|
||||
+ if (ret->ui_scale > 2) ret->ui_scale = 2;
|
||||
+ struct mtk_netsurf_chrome_metrics metrics;
|
||||
+ mtk_netsurf_chrome_metrics(ret->ui_scale, ret->width, 1, &metrics);
|
||||
+ ret->chrome_height = metrics.chrome_h;
|
||||
+ ret->status_height = metrics.status_h;
|
||||
}
|
||||
- ret->native_id = native.id;
|
||||
- ret->pixels = (uint32_t *)(uintptr_t)native.pixels;
|
||||
ret->clip_x1 = ret->width;
|
||||
ret->clip_y1 = ret->height;
|
||||
+ ret->mouse_x = ret->mouse_y = -1;
|
||||
+ ret->dirty = true;
|
||||
+ strcpy(ret->title, "New Tab");
|
||||
+ strcpy(ret->status, "Loading...");
|
||||
#endif
|
||||
|
||||
moutf(MOUT_WINDOW,
|
||||
@@ -112,6 +214,10 @@ gui_window_create(struct browser_window *bw,
|
||||
ret->win_num, ret->width, ret->height);
|
||||
|
||||
RING_INSERT(gw_ring, ret);
|
||||
+#if defined(__montauk__)
|
||||
+ if (native_active == NULL || (flags & GW_CREATE_FOREGROUND))
|
||||
+ native_active = ret;
|
||||
+#endif
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -121,7 +227,16 @@ gui_window_destroy(struct gui_window *g)
|
||||
{
|
||||
moutf(MOUT_WINDOW, "DESTROY WIN %u", g->win_num);
|
||||
#if defined(__montauk__)
|
||||
- mtk_win_destroy(g->native_id);
|
||||
+ mtk_netsurf_address_input_destroy((uintptr_t)g);
|
||||
+ bool shared = false;
|
||||
+ struct gui_window *item = gw_ring;
|
||||
+ if (item != NULL) do {
|
||||
+ if (item != g && item->native_id == g->native_id) shared = true;
|
||||
+ item = item->r_next;
|
||||
+ } while (item != gw_ring);
|
||||
+ if (!shared) mtk_win_destroy(g->native_id);
|
||||
+ if (native_active == g)
|
||||
+ native_active = shared ? (g->r_next != g ? g->r_next : NULL) : NULL;
|
||||
#endif
|
||||
RING_REMOVE(gw_ring, g);
|
||||
free(g);
|
||||
@@ -130,6 +245,13 @@ gui_window_destroy(struct gui_window *g)
|
||||
static void
|
||||
gui_window_set_title(struct gui_window *g, const char *title)
|
||||
{
|
||||
+#if defined(__montauk__)
|
||||
+ if (title != NULL) {
|
||||
+ strncpy(g->title, title, sizeof(g->title) - 1);
|
||||
+ g->title[sizeof(g->title) - 1] = 0;
|
||||
+ g->dirty = true;
|
||||
+ }
|
||||
+#endif
|
||||
moutf(MOUT_WINDOW, "TITLE WIN %u STR %s", g->win_num, title);
|
||||
}
|
||||
|
||||
@@ -146,6 +268,12 @@ gui_window_get_dimensions(struct gui_window *g, int *width, int *height)
|
||||
{
|
||||
*width = g->width;
|
||||
*height = g->height;
|
||||
+#if defined(__montauk__)
|
||||
+ *width = mtk_netsurf_page_view_width(*width);
|
||||
+ *height -= g->chrome_height + g->status_height;
|
||||
+ if (*width < 1) *width = 1;
|
||||
+ if (*height < 1) *height = 1;
|
||||
+#endif
|
||||
|
||||
moutf(MOUT_WINDOW,
|
||||
"GET_DIMENSIONS WIN %u WIDTH %d HEIGHT %d",
|
||||
@@ -169,6 +297,10 @@ gui_window_set_icon(struct gui_window *g, struct hlcache_handle *icon)
|
||||
static void
|
||||
gui_window_start_throbber(struct gui_window *g)
|
||||
{
|
||||
+#if defined(__montauk__)
|
||||
+ g->loading = true;
|
||||
+ g->dirty = true;
|
||||
+#endif
|
||||
moutf(MOUT_WINDOW, "START_THROBBER WIN %u", g->win_num);
|
||||
}
|
||||
|
||||
@@ -176,24 +308,8 @@ static void
|
||||
gui_window_stop_throbber(struct gui_window *g)
|
||||
{
|
||||
#if defined(__montauk__)
|
||||
- struct rect clip = {
|
||||
- .x0 = 0,
|
||||
- .y0 = 0,
|
||||
- .x1 = g->width,
|
||||
- .y1 = g->height
|
||||
- };
|
||||
- struct redraw_context ctx = {
|
||||
- .interactive = true,
|
||||
- .background_images = true,
|
||||
- .plot = monkey_plotters,
|
||||
- .priv = g
|
||||
- };
|
||||
- for (int y = 0; y < g->height; y++) {
|
||||
- for (int x = 0; x < g->width; x++)
|
||||
- g->pixels[y * g->width + x] = 0xffffffffu;
|
||||
- }
|
||||
- browser_window_redraw(g->bw, g->scrollx, g->scrolly, &clip, &ctx);
|
||||
- mtk_win_present(g->native_id);
|
||||
+ g->loading = false;
|
||||
+ g->dirty = true;
|
||||
#endif
|
||||
moutf(MOUT_WINDOW, "STOP_THROBBER WIN %u", g->win_num);
|
||||
}
|
||||
@@ -214,6 +330,9 @@ gui_window_set_scroll(struct gui_window *gw, const struct rect *rect)
|
||||
{
|
||||
gw->scrollx = rect->x0;
|
||||
gw->scrolly = rect->y0;
|
||||
+#if defined(__montauk__)
|
||||
+ gw->dirty = true;
|
||||
+#endif
|
||||
|
||||
moutf(MOUT_WINDOW, "SET_SCROLL WIN %u X %d Y %d",
|
||||
gw->win_num, rect->x0, rect->y0);
|
||||
@@ -231,6 +350,9 @@ gui_window_set_scroll(struct gui_window *gw, const struct rect *rect)
|
||||
static nserror
|
||||
monkey_window_invalidate_area(struct gui_window *gw, const struct rect *rect)
|
||||
{
|
||||
+#if defined(__montauk__)
|
||||
+ gw->dirty = true;
|
||||
+#endif
|
||||
if (rect != NULL) {
|
||||
moutf(MOUT_WINDOW,
|
||||
"INVALIDATE_AREA WIN %u X %d Y %d WIDTH %d HEIGHT %d",
|
||||
@@ -249,8 +371,13 @@ gui_window_update_extent(struct gui_window *g)
|
||||
{
|
||||
int width, height;
|
||||
|
||||
- if (browser_window_get_extents(g->bw, false, &width, &height) != NSERROR_OK)
|
||||
+ if (browser_window_get_extents(g->bw, true, &width, &height) != NSERROR_OK)
|
||||
return;
|
||||
+#if defined(__montauk__)
|
||||
+ g->extent_width = width;
|
||||
+ g->extent_height = height;
|
||||
+ g->dirty = true;
|
||||
+#endif
|
||||
|
||||
moutf(MOUT_WINDOW, "UPDATE_EXTENT WIN %u WIDTH %d HEIGHT %d",
|
||||
g->win_num, width, height);
|
||||
@@ -259,6 +386,13 @@ gui_window_update_extent(struct gui_window *g)
|
||||
static void
|
||||
gui_window_set_status(struct gui_window *g, const char *text)
|
||||
{
|
||||
+#if defined(__montauk__)
|
||||
+ if (text != NULL) {
|
||||
+ strncpy(g->status, text, sizeof(g->status) - 1);
|
||||
+ g->status[sizeof(g->status) - 1] = 0;
|
||||
+ g->dirty = true;
|
||||
+ }
|
||||
+#endif
|
||||
moutf(MOUT_WINDOW, "SET_STATUS WIN %u STR %s", g->win_num, text);
|
||||
}
|
||||
|
||||
@@ -336,11 +470,39 @@ gui_window_set_pointer(struct gui_window *g, gui_pointer_shape shape)
|
||||
static nserror
|
||||
gui_window_set_url(struct gui_window *g, nsurl *url)
|
||||
{
|
||||
+#if defined(__montauk__)
|
||||
+ strncpy(g->address, nsurl_access(url), sizeof(g->address) - 1);
|
||||
+ g->address[sizeof(g->address) - 1] = 0;
|
||||
+ g->dirty = true;
|
||||
+#endif
|
||||
moutf(MOUT_WINDOW, "SET_URL WIN %u URL %s",
|
||||
g->win_num, nsurl_access(url));
|
||||
return NSERROR_OK;
|
||||
}
|
||||
|
||||
+#if defined(__montauk__)
|
||||
+void monkey_native_redraw(struct gui_window *g)
|
||||
+{
|
||||
+ if (g == NULL || g->pixels == NULL) return;
|
||||
+ const int chrome_h = g->chrome_height, status_h = g->status_height;
|
||||
+ int content_h = g->height - chrome_h - status_h;
|
||||
+ if (content_h < 1) content_h = 1;
|
||||
+ for (int y = chrome_h; y < g->height - status_h; y++)
|
||||
+ for (int x = 0; x < g->width; x++)
|
||||
+ g->pixels[y * g->width + x] = 0xffffffffu;
|
||||
+ struct rect clip = { .x0 = 0, .y0 = 0,
|
||||
+ .x1 = mtk_netsurf_page_view_width(g->width), .y1 = content_h };
|
||||
+ struct redraw_context ctx = {
|
||||
+ .interactive = true, .background_images = true,
|
||||
+ .plot = monkey_plotters, .priv = g
|
||||
+ };
|
||||
+ browser_window_redraw(g->bw, -g->scrollx, -g->scrolly, &clip, &ctx);
|
||||
+ monkey_native_draw_chrome(g);
|
||||
+ mtk_win_present(g->native_id);
|
||||
+ g->dirty = false;
|
||||
+}
|
||||
+#endif
|
||||
+
|
||||
static bool
|
||||
gui_window_get_scroll(struct gui_window *g, int *sx, int *sy)
|
||||
{
|
||||
@@ -364,6 +526,13 @@ static void
|
||||
gui_window_place_caret(struct gui_window *g, int x, int y, int height,
|
||||
const struct rect *clip)
|
||||
{
|
||||
+#if defined(__montauk__)
|
||||
+ g->caret_x = x;
|
||||
+ g->caret_y = y;
|
||||
+ g->caret_height = height;
|
||||
+ g->caret_visible = true;
|
||||
+ g->dirty = true;
|
||||
+#endif
|
||||
moutf(MOUT_WINDOW, "PLACE_CARET WIN %u X %d Y %d HEIGHT %d",
|
||||
g->win_num, x, y, height);
|
||||
}
|
||||
@@ -371,6 +540,10 @@ gui_window_place_caret(struct gui_window *g, int x, int y, int height,
|
||||
static void
|
||||
gui_window_remove_caret(struct gui_window *g)
|
||||
{
|
||||
+#if defined(__montauk__)
|
||||
+ g->caret_visible = false;
|
||||
+ g->dirty = true;
|
||||
+#endif
|
||||
moutf(MOUT_WINDOW, "REMOVE_CARET WIN %u", g->win_num);
|
||||
}
|
||||
|
||||
@@ -390,6 +563,18 @@ gui_window_save_link(struct gui_window *g, nsurl *url, const char *title)
|
||||
return NSERROR_OK;
|
||||
}
|
||||
|
||||
+#if defined(__montauk__)
|
||||
+static void gui_window_file_gadget_open(struct gui_window *g,
|
||||
+ struct hlcache_handle *hl, struct form_control *gadget)
|
||||
+{
|
||||
+ char path[512];
|
||||
+ (void)hl;
|
||||
+ if (mtk_netsurf_open_file(path, sizeof(path)))
|
||||
+ browser_window_set_gadget_filename(g->bw, gadget, path);
|
||||
+ g->dirty = true;
|
||||
+}
|
||||
+#endif
|
||||
+
|
||||
static void
|
||||
gui_window_console_log(struct gui_window *g,
|
||||
browser_window_console_source src,
|
||||
@@ -448,6 +633,10 @@ static void
|
||||
gui_window_report_page_info(struct gui_window *g)
|
||||
{
|
||||
const char *state = "***WAH***";
|
||||
+#if defined(__montauk__)
|
||||
+ g->page_state = browser_window_get_page_info_state(g->bw);
|
||||
+ g->dirty = true;
|
||||
+#endif
|
||||
|
||||
switch (browser_window_get_page_info_state(g->bw)) {
|
||||
case PAGE_STATE_UNKNOWN:
|
||||
@@ -911,6 +1100,9 @@ static struct gui_window_table window_table = {
|
||||
.place_caret = gui_window_place_caret,
|
||||
.drag_start = gui_window_drag_start,
|
||||
.save_link = gui_window_save_link,
|
||||
+#if defined(__montauk__)
|
||||
+ .file_gadget_open = gui_window_file_gadget_open,
|
||||
+#endif
|
||||
|
||||
.console_log = gui_window_console_log,
|
||||
};
|
||||
diff --git a/frontends/monkey/browser.h b/frontends/monkey/browser.h
|
||||
index 8e90e0c..09399ab 100644
|
||||
--- a/frontends/monkey/browser.h
|
||||
+++ b/frontends/monkey/browser.h
|
||||
@@ -37,7 +37,19 @@ struct gui_window {
|
||||
#if defined(__montauk__)
|
||||
int native_id;
|
||||
uint32_t *pixels;
|
||||
+ int ui_scale, chrome_height, status_height;
|
||||
+ int mouse_x, mouse_y;
|
||||
int clip_x0, clip_y0, clip_x1, clip_y1;
|
||||
+ int extent_width, extent_height;
|
||||
+ uint8_t dirty, loading, address_focus;
|
||||
+ uint8_t caret_visible;
|
||||
+ uint8_t find_focus, menu_open, page_state;
|
||||
+ int scrollbar_hover, scrollbar_dragging, scrollbar_drag_offset;
|
||||
+ int caret_x, caret_y, caret_height;
|
||||
+ char find_text[256];
|
||||
+ char address[2048];
|
||||
+ char title[128];
|
||||
+ char status[256];
|
||||
#endif
|
||||
char *host; /* Ignore this, it's in case RING*() gets debugging for fetchers */
|
||||
|
||||
@@ -50,6 +62,17 @@ void monkey_window_process_reformats(void);
|
||||
void monkey_window_handle_command(int argc, char **argv);
|
||||
void monkey_kill_browser_windows(void);
|
||||
|
||||
+#if defined(__montauk__)
|
||||
+struct gui_window *monkey_native_get_window(void);
|
||||
+size_t monkey_native_tab_count(void);
|
||||
+struct gui_window *monkey_native_tab_at(size_t index);
|
||||
+void monkey_native_activate_window(struct gui_window *gw);
|
||||
+void monkey_native_resize_tabs(struct gui_window *gw, int width, int height,
|
||||
+ uint32_t *pixels);
|
||||
+void monkey_native_set_scale(struct gui_window *gw, int scale);
|
||||
+void monkey_native_redraw(struct gui_window *gw);
|
||||
+#endif
|
||||
+
|
||||
nserror monkey_warn_user(const char *warning, const char *detail);
|
||||
|
||||
#endif /* NETSURF_MONKEY_BROWSER_H */
|
||||
diff --git a/frontends/monkey/main.c b/frontends/monkey/main.c
|
||||
index 578d148..ebd940a 100644
|
||||
--- a/frontends/monkey/main.c
|
||||
+++ b/frontends/monkey/main.c
|
||||
@@ -46,6 +46,9 @@
|
||||
#include "monkey/401login.h"
|
||||
#include "monkey/filetype.h"
|
||||
#include "monkey/fetch.h"
|
||||
+#if defined(__montauk__)
|
||||
+#include "monkey/montauk_ui.h"
|
||||
+#endif
|
||||
#include "monkey/schedule.h"
|
||||
#include "monkey/bitmap.h"
|
||||
#include "monkey/layout.h"
|
||||
@@ -274,7 +277,7 @@ static struct gui_misc_table monkey_misc_table = {
|
||||
.present_cookies = gui_present_cookies,
|
||||
};
|
||||
|
||||
-static void monkey_run(void)
|
||||
+static void __attribute__((unused)) monkey_run(void)
|
||||
{
|
||||
fd_set read_fd_set, write_fd_set, exc_fd_set;
|
||||
int max_fd;
|
||||
@@ -399,6 +402,10 @@ main(int argc, char **argv)
|
||||
.fetch = monkey_fetch_table,
|
||||
.bitmap = monkey_bitmap_table,
|
||||
.layout = monkey_layout_table,
|
||||
+#if defined(__montauk__)
|
||||
+ .clipboard = &monkey_native_clipboard_table,
|
||||
+ .search = &monkey_native_search_table,
|
||||
+#endif
|
||||
.llcache = filesystem_llcache_table,
|
||||
};
|
||||
|
||||
@@ -491,7 +498,11 @@ main(int argc, char **argv)
|
||||
|
||||
|
||||
moutf(MOUT_GENERIC, "STARTED");
|
||||
+#if defined(__montauk__)
|
||||
+ monkey_native_run(argc > 1 ? argv[1] : NULL);
|
||||
+#else
|
||||
monkey_run();
|
||||
+#endif
|
||||
|
||||
moutf(MOUT_GENERIC, "CLOSING_DOWN");
|
||||
monkey_kill_browser_windows();
|
||||
diff --git a/frontends/monkey/plot.c b/frontends/monkey/plot.c
|
||||
index 6f762f9..f6bf09a 100644
|
||||
--- a/frontends/monkey/plot.c
|
||||
+++ b/frontends/monkey/plot.c
|
||||
@@ -53,6 +53,7 @@ static uint32_t native_colour(colour c)
|
||||
|
||||
static void native_pixel(struct gui_window *gw, int x, int y, uint32_t colour)
|
||||
{
|
||||
+ y += gw->chrome_height;
|
||||
if (gw == NULL || gw->pixels == NULL || x < gw->clip_x0 || y < gw->clip_y0 ||
|
||||
x >= gw->clip_x1 || y >= gw->clip_y1 || x < 0 || y < 0 ||
|
||||
x >= gw->width || y >= gw->height || colour == 0) return;
|
||||
@@ -63,6 +64,7 @@ static void native_fill(struct gui_window *gw, int x0, int y0, int x1, int y1,
|
||||
uint32_t colour)
|
||||
{
|
||||
if (gw == NULL || colour == 0) return;
|
||||
+ y0 += gw->chrome_height; y1 += gw->chrome_height;
|
||||
if (x0 < gw->clip_x0) x0 = gw->clip_x0;
|
||||
if (y0 < gw->clip_y0) y0 = gw->clip_y0;
|
||||
if (x1 > gw->clip_x1) x1 = gw->clip_x1;
|
||||
@@ -96,7 +98,7 @@ static void native_text(struct gui_window *gw, int x, int baseline,
|
||||
if (gw == NULL || gw->pixels == NULL) return;
|
||||
mtk_netsurf_font_draw(gw->pixels, gw->width, gw->height,
|
||||
gw->clip_x0, gw->clip_y0, gw->clip_x1, gw->clip_y1,
|
||||
- x, baseline, text, length, native_colour(style->foreground),
|
||||
+ x, baseline + gw->chrome_height, text, length, native_colour(style->foreground),
|
||||
style->family, style->weight, style->flags, px);
|
||||
}
|
||||
#endif
|
||||
@@ -116,9 +118,9 @@ monkey_plot_clip(const struct redraw_context *ctx, const struct rect *clip)
|
||||
struct gui_window *gw = ctx->priv;
|
||||
if (gw != NULL) {
|
||||
gw->clip_x0 = clip->x0;
|
||||
- gw->clip_y0 = clip->y0;
|
||||
+ gw->clip_y0 = clip->y0 + gw->chrome_height;
|
||||
gw->clip_x1 = clip->x1;
|
||||
- gw->clip_y1 = clip->y1;
|
||||
+ gw->clip_y1 = clip->y1 + gw->chrome_height;
|
||||
}
|
||||
#endif
|
||||
moutf(MOUT_PLOT, "CLIP X0 %d Y0 %d X1 %d Y1 %d",
|
||||
@@ -338,7 +340,7 @@ monkey_plot_bitmap(const struct redraw_context *ctx,
|
||||
uint32_t out = 0xff000000u | ((p & 0xffu) << 16) |
|
||||
(p & 0xff00u) | ((p >> 16) & 0xffu);
|
||||
if (a != 255) {
|
||||
- int tx = x + dx, ty = y + dy;
|
||||
+ int tx = x + dx, ty = y + dy + gw->chrome_height;
|
||||
if (tx >= 0 && ty >= 0 && tx < gw->width && ty < gw->height) {
|
||||
uint32_t d = gw->pixels[ty * gw->width + tx];
|
||||
unsigned r = (((out >> 16) & 255) * a + ((d >> 16) & 255) * (255-a)) / 255;
|
||||
@@ -0,0 +1,113 @@
|
||||
diff --git a/frontends/monkey/download.c b/frontends/monkey/download.c
|
||||
index 1f77439..2eef168 100644
|
||||
--- a/frontends/monkey/download.c
|
||||
+++ b/frontends/monkey/download.c
|
||||
@@ -17,8 +17,13 @@
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
+#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
+#include <string.h>
|
||||
+#if defined(__montauk__)
|
||||
+#include <montauk.h>
|
||||
+#endif
|
||||
|
||||
#include "utils/errors.h"
|
||||
#include "utils/ring.h"
|
||||
@@ -36,6 +41,11 @@ struct gui_download_window {
|
||||
struct gui_window *g;
|
||||
download_context *dlctx;
|
||||
uint32_t dwin_num;
|
||||
+#if defined(__montauk__)
|
||||
+ int file_handle;
|
||||
+ unsigned long offset;
|
||||
+ char path[256];
|
||||
+#endif
|
||||
char *host; /* ignore */
|
||||
};
|
||||
|
||||
@@ -51,6 +61,34 @@ gui_download_window_create(download_context *ctx,
|
||||
ret->g = parent;
|
||||
ret->dwin_num = dwin_ctr++;
|
||||
ret->dlctx = ctx;
|
||||
+#if defined(__montauk__)
|
||||
+ ret->file_handle = -1;
|
||||
+ char user[64] = {0};
|
||||
+ if (_mtk_syscall2(MTK_SYS_GETUSER, (long)user, sizeof(user)) < 0 || user[0] == 0)
|
||||
+ strcpy(user, "admin");
|
||||
+ char directory[192];
|
||||
+ snprintf(directory, sizeof(directory), "0:/users/%s/Downloads", user);
|
||||
+ mtk_mkdir(directory);
|
||||
+ const char *source = download_context_get_filename(ctx);
|
||||
+ char filename[96];
|
||||
+ if (source == NULL || source[0] == 0) source = "download.bin";
|
||||
+ size_t n = 0;
|
||||
+ for (; source[n] != 0 && n + 1 < sizeof(filename); n++) {
|
||||
+ unsigned char c = (unsigned char)source[n];
|
||||
+ filename[n] = (c < 32 || c == '/' || c == '\\' || c == ':') ? '_' : (char)c;
|
||||
+ }
|
||||
+ filename[n] = 0;
|
||||
+ snprintf(ret->path, sizeof(ret->path), "%s/%s", directory, filename);
|
||||
+ ret->file_handle = mtk_create(ret->path);
|
||||
+ if (ret->file_handle < 0) {
|
||||
+ free(ret);
|
||||
+ return NULL;
|
||||
+ }
|
||||
+ if (parent != NULL) {
|
||||
+ snprintf(parent->status, sizeof(parent->status), "Downloading %s", filename);
|
||||
+ parent->dirty = true;
|
||||
+ }
|
||||
+#endif
|
||||
|
||||
RING_INSERT(dw_ring, ret);
|
||||
|
||||
@@ -64,21 +102,47 @@ static nserror
|
||||
gui_download_window_data(struct gui_download_window *dw,
|
||||
const char *data, unsigned int size)
|
||||
{
|
||||
+#if defined(__montauk__)
|
||||
+ if (dw->file_handle < 0 || mtk_write(dw->file_handle,
|
||||
+ (const uint8_t *)data, dw->offset, size) != (int)size)
|
||||
+ return NSERROR_SAVE_FAILED;
|
||||
+ dw->offset += size;
|
||||
+ if (dw->g != NULL) {
|
||||
+ snprintf(dw->g->status, sizeof(dw->g->status), "Downloading: %lu bytes", dw->offset);
|
||||
+ dw->g->dirty = true;
|
||||
+ }
|
||||
+ return NSERROR_OK;
|
||||
+#else
|
||||
moutf(MOUT_DOWNLOAD, "DATA DWIN %u SIZE %u DATA %s",
|
||||
dw->dwin_num, size, data);
|
||||
return NSERROR_OK;
|
||||
+#endif
|
||||
}
|
||||
|
||||
static void
|
||||
gui_download_window_error(struct gui_download_window *dw,
|
||||
const char *error_msg)
|
||||
{
|
||||
+#if defined(__montauk__)
|
||||
+ if (dw->file_handle >= 0) { mtk_close(dw->file_handle); dw->file_handle = -1; }
|
||||
+ if (dw->g != NULL) {
|
||||
+ snprintf(dw->g->status, sizeof(dw->g->status), "Download failed: %s", error_msg);
|
||||
+ dw->g->dirty = true;
|
||||
+ }
|
||||
+#endif
|
||||
moutf(MOUT_DOWNLOAD, "ERROR DWIN %u ERROR %s", dw->dwin_num, error_msg);
|
||||
}
|
||||
|
||||
static void
|
||||
gui_download_window_done(struct gui_download_window *dw)
|
||||
{
|
||||
+#if defined(__montauk__)
|
||||
+ if (dw->file_handle >= 0) { mtk_close(dw->file_handle); dw->file_handle = -1; }
|
||||
+ if (dw->g != NULL) {
|
||||
+ snprintf(dw->g->status, sizeof(dw->g->status), "Saved %s", dw->path);
|
||||
+ dw->g->dirty = true;
|
||||
+ }
|
||||
+#endif
|
||||
moutf(MOUT_DOWNLOAD, "DONE DWIN %u", dw->dwin_num);
|
||||
RING_REMOVE(dw_ring, dw);
|
||||
download_context_destroy(dw->dlctx);
|
||||
@@ -0,0 +1,21 @@
|
||||
diff --git a/frontends/monkey/bitmap.c b/frontends/monkey/bitmap.c
|
||||
index cc13c8b..60104ec 100644
|
||||
--- a/frontends/monkey/bitmap.c
|
||||
+++ b/frontends/monkey/bitmap.c
|
||||
@@ -36,12 +36,16 @@ struct bitmap {
|
||||
|
||||
static void *bitmap_create(int width, int height, enum gui_bitmap_flags flags)
|
||||
{
|
||||
+ if (width <= 0 || height <= 0 || width > 8192 || height > 8192 ||
|
||||
+ (size_t)width * (size_t)height > 32u * 1024u * 1024u)
|
||||
+ return NULL;
|
||||
struct bitmap *ret = calloc(1, sizeof(*ret));
|
||||
if (ret == NULL)
|
||||
return NULL;
|
||||
|
||||
ret->width = width;
|
||||
ret->height = height;
|
||||
+ ret->rowstride = (size_t)width * 4;
|
||||
ret->opaque = (flags & BITMAP_OPAQUE) == BITMAP_OPAQUE;
|
||||
|
||||
ret->ptr = calloc(width, height * 4);
|
||||
Reference in new issue
Block a user