From 9bd355e30c1f6aa57d42fe4f2fa6e9f521f002a4 Mon Sep 17 00:00:00 2001 From: Chris Young Date: Thu, 2 Jan 2014 18:50:59 +0000 Subject: [PATCH 001/773] Convert download filename to local charset --- amiga/Makefile.target | 2 +- amiga/download.c | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/amiga/Makefile.target b/amiga/Makefile.target index da9b252c9..484c57dcb 100644 --- a/amiga/Makefile.target +++ b/amiga/Makefile.target @@ -109,7 +109,7 @@ AMIGA_LIBRARIES := parserutils.library nsgif.library nsbmp.library iconv.library AMIGA_LIBS := $(addprefix /Libs/,$(AMIGA_LIBRARIES)) AMIGA_SHARED_OBJS := libjpeg.so.12 libcurl.so.7 librtmp.so.0 libsvgtiny.so.0 \ libssl.so.1.0.0 libcrypto.so.1.0.0 libcss.so.0 libwapcaplet.so.0 libpng12.so \ - libdom.so.0 libhubbub.so.0 libtre.so.5 libintl.so + libdom.so.0 libhubbub.so.0 libtre.so.5 libintl.so libparserutils.so.0 AMIGA_SOBJS := $(addprefix /SObjs/,$(AMIGA_SHARED_OBJS)) AMIGA_DISTRIBUTION_FILES := amiga/dist/* AMIGA_INSTALL_TARGET_DIR := NetSurf_Amiga diff --git a/amiga/download.c b/amiga/download.c index 52baedb24..d33b723d1 100644 --- a/amiga/download.c +++ b/amiga/download.c @@ -92,6 +92,7 @@ struct gui_download_window *gui_download_window_create(download_context *ctx, const char *mime_type = download_context_get_mime_type(ctx); unsigned long total_size = download_context_get_total_length(ctx); struct gui_download_window *dw; + char *dl_filename = ami_utf8_easy(download_context_get_filename(ctx)); APTR va[3]; dw = AllocVecTags(sizeof(struct gui_download_window), AVT_ClearWithValue, 0, TAG_DONE); @@ -107,9 +108,9 @@ struct gui_download_window *gui_download_window_create(download_context *ctx, if(AslRequestTags(savereq, ASLFR_Window, gui->shared->win, ASLFR_SleepWindow, TRUE, - ASLFR_TitleText,messages_get("NetSurf"), - ASLFR_Screen,scrn, - ASLFR_InitialFile, download_context_get_filename(ctx), + ASLFR_TitleText, messages_get("NetSurf"), + ASLFR_Screen, scrn, + ASLFR_InitialFile, dl_filename, TAG_DONE)) { strlcpy(dw->fname, savereq->fr_Drawer, 1024); @@ -127,6 +128,7 @@ struct gui_download_window *gui_download_window_create(download_context *ctx, } } + if(dl_filename) ami_utf8_free(dl_filename); dw->size = total_size; dw->downloaded = 0; if(gui) dw->bw = gui->shared->bw; From 286ee3834c7a20d3963b9cf288a6d091d3fb50f2 Mon Sep 17 00:00:00 2001 From: Steve Fryatt Date: Thu, 2 Jan 2014 22:22:18 +0000 Subject: [PATCH 002/773] In framesets, F8 views source for frame under pointer if applicable. --- riscos/window.c | 64 +++++++++++++++++++++++++++---------------------- 1 file changed, 36 insertions(+), 28 deletions(-) diff --git a/riscos/window.c b/riscos/window.c index f6b274a20..208f50c7b 100644 --- a/riscos/window.c +++ b/riscos/window.c @@ -1800,7 +1800,6 @@ bool ro_gui_window_keypress(wimp_key *key) struct gui_window *g; hlcache_handle *h; os_error *error; - wimp_pointer pointer; uint32_t c = (uint32_t) key->c; g = (struct gui_window *) ro_gui_wimp_event_get_user_data(key->w); @@ -1809,14 +1808,6 @@ bool ro_gui_window_keypress(wimp_key *key) h = g->bw->current_content; - error = xwimp_get_pointer_info(&pointer); - if (error) { - LOG(("xwimp_get_pointer_info: 0x%x: %s\n", - error->errnum, error->errmess)); - warn_user("WimpError", error->errmess); - return false; - } - /* First send the key to the browser window, eg. form fields. */ if ((unsigned)c < 0x20 || (0x7f <= c && c <= 0x9f) || @@ -1893,7 +1884,7 @@ bool ro_gui_window_keypress(wimp_key *key) bool ro_gui_window_toolbar_keypress(void *data, wimp_key *key) { - struct gui_window *g = (struct gui_window *) data; + struct gui_window *g = (struct gui_window *) data; if (g != NULL) return ro_gui_window_handle_local_keypress(g, key, true); @@ -1917,20 +1908,38 @@ bool ro_gui_window_toolbar_keypress(void *data, wimp_key *key) bool ro_gui_window_handle_local_keypress(struct gui_window *g, wimp_key *key, bool is_toolbar) { - hlcache_handle *h; - const char *toolbar_url; - float scale; - uint32_t c = (uint32_t) key->c; - wimp_scroll_direction xscroll = wimp_SCROLL_NONE; - wimp_scroll_direction yscroll = wimp_SCROLL_NONE; - nsurl *url; - nserror error; + hlcache_handle *h; + struct contextual_content cont; + os_error *ro_error; + wimp_pointer pointer; + os_coord pos; + const char *toolbar_url; + float scale; + uint32_t c = (uint32_t) key->c; + wimp_scroll_direction xscroll = wimp_SCROLL_NONE; + wimp_scroll_direction yscroll = wimp_SCROLL_NONE; + nsurl *url; + nserror error; if (g == NULL) return false; + ro_error = xwimp_get_pointer_info(&pointer); + if (ro_error) { + LOG(("xwimp_get_pointer_info: 0x%x: %s\n", + ro_error->errnum, ro_error->errmess)); + warn_user("WimpError", ro_error->errmess); + return false; + } + + if (!ro_gui_window_to_window_pos(g, pointer.pos.x, pointer.pos.y, &pos)) + return false; + + h = g->bw->current_content; + browser_window_get_contextual_content(g->bw, pos.x, pos.y, &cont); + switch (c) { case IS_WIMP_KEY + wimp_KEY_F1: /* Help. */ { @@ -2015,7 +2024,7 @@ bool ro_gui_window_handle_local_keypress(struct gui_window *g, wimp_key *key, return true; case IS_WIMP_KEY + wimp_KEY_F8: /* View source */ - ro_gui_view_source(h); + ro_gui_view_source((cont.main != NULL) ? cont.main : h); return true; case IS_WIMP_KEY + wimp_KEY_F9: @@ -2848,10 +2857,10 @@ bool ro_gui_window_menu_select(wimp_w w, wimp_i i, wimp_menu *menu, error = nsurl_create(current_menu_url, &url); if (error == NSERROR_OK) { error = browser_window_navigate(bw, - url, - hlcache_handle_get_url(h), - BROWSER_WINDOW_DOWNLOAD | - BROWSER_WINDOW_VERIFIABLE, + url, + hlcache_handle_get_url(h), + BROWSER_WINDOW_DOWNLOAD | + BROWSER_WINDOW_VERIFIABLE, NULL, NULL, NULL); @@ -3035,12 +3044,12 @@ bool ro_gui_window_menu_select(wimp_w w, wimp_i i, wimp_menu *menu, } break; case BROWSER_WINDOW_STAGGER: - nsoption_set_bool(window_stagger, + nsoption_set_bool(window_stagger, !nsoption_bool(window_stagger)); ro_gui_save_options(); break; case BROWSER_WINDOW_COPY: - nsoption_set_bool(window_size_clone, + nsoption_set_bool(window_size_clone, !nsoption_bool(window_size_clone)); ro_gui_save_options(); break; @@ -3637,7 +3646,7 @@ void ro_gui_window_toolbar_click(void *data, case TOOLBAR_URL_ADJUST_HOTLIST: ro_gui_window_action_remove_bookmark(g); break; - + default: break; } @@ -3749,7 +3758,7 @@ void ro_gui_window_toolbar_click(void *data, warn_user(messages_get_errorcode(error), 0); } else { /* do it without loading the content - * into the new window + * into the new window */ ro_gui_window_navigate_up(new_bw->window, nsurl_access(hlcache_handle_get_url(h))); @@ -5255,4 +5264,3 @@ bool ro_gui_alt_pressed(void) xosbyte1(osbyte_SCAN_KEYBOARD, 2 ^ 0x80, 0, &alt); return (alt == 0xff); } - From bf8c88dbec9d66dadaa584d80702c1653fda1c08 Mon Sep 17 00:00:00 2001 From: Steve Fryatt Date: Thu, 2 Jan 2014 22:25:23 +0000 Subject: [PATCH 003/773] Update copyright header dates for recent commits. --- riscos/gui/url_bar.c | 9 ++++----- riscos/hotlist.c | 5 ++--- riscos/hotlist.h | 3 +-- riscos/window.c | 2 +- 4 files changed, 8 insertions(+), 11 deletions(-) diff --git a/riscos/gui/url_bar.c b/riscos/gui/url_bar.c index 845f8b3e8..62956a9ab 100644 --- a/riscos/gui/url_bar.c +++ b/riscos/gui/url_bar.c @@ -1,6 +1,6 @@ /* * Copyright 2004, 2005 Richard Wilson - * Copyright 2011 Stephen Fryatt + * Copyright 2011-2013 Stephen Fryatt * * This file is part of NetSurf, http://www.netsurf-browser.org/ * @@ -1013,9 +1013,9 @@ static void ro_gui_url_bar_set_hotlist(struct url_bar *url_bar, bool set) { if (url_bar == NULL || set == url_bar->hotlist.set) return; - + url_bar->hotlist.set = set; - + if (!url_bar->hidden) { xwimp_force_redraw(url_bar->window, url_bar->hotlist.extent.x0, @@ -1097,7 +1097,7 @@ bool ro_gui_url_bar_test_for_text_field_keypress(struct url_bar *url_bar, return false; /* Update hotlist indicator */ - + url = (const char *) url_bar->text_buffer; if (url != NULL && nsurl_create(url, &n) == NSERROR_OK) { ro_gui_url_bar_set_hotlist(url_bar, ro_gui_hotlist_has_page(n)); @@ -1278,4 +1278,3 @@ void ro_gui_url_bar_fini(void) hlcache_handle_release(url_bar_res[i].c); } } - diff --git a/riscos/hotlist.c b/riscos/hotlist.c index f47d05e9c..eeaddd00f 100644 --- a/riscos/hotlist.c +++ b/riscos/hotlist.c @@ -1,6 +1,6 @@ /* * Copyright 2004, 2005 Richard Wilson - * Copyright 2010 Stephen Fryatt + * Copyright 2010, 2013 Stephen Fryatt * * This file is part of NetSurf, http://www.netsurf-browser.org/ * @@ -220,7 +220,7 @@ void ro_gui_hotlist_open(void) os_error *error; char command[2048]; - if (nsoption_bool(external_hotlists) && + if (nsoption_bool(external_hotlists) && nsoption_charp(external_hotlist_app) != NULL && *nsoption_charp(external_hotlist_app) != '\0') { snprintf(command, sizeof(command), "Filer_Run %s", @@ -732,4 +732,3 @@ void ro_gui_hotlist_url_drop(wimp_message *message, const char *url) nsurl_unref(nsurl); } #endif - diff --git a/riscos/hotlist.h b/riscos/hotlist.h index 4cb5a1ff3..70cb183c9 100644 --- a/riscos/hotlist.h +++ b/riscos/hotlist.h @@ -1,6 +1,6 @@ /* * Copyright 2006 Richard Wilson - * Copyright 2010 Stephen Fryatt + * Copyright 2010, 2013 Stephen Fryatt * * This file is part of NetSurf, http://www.netsurf-browser.org/ * @@ -51,4 +51,3 @@ void ro_gui_hotlist_remove_page(nsurl *url); bool ro_gui_hotlist_has_page(nsurl *url); #endif - diff --git a/riscos/window.c b/riscos/window.c index 208f50c7b..c314c748b 100644 --- a/riscos/window.c +++ b/riscos/window.c @@ -5,7 +5,7 @@ * Copyright 2004 Andrew Timmins * Copyright 2005 Richard Wilson * Copyright 2005 Adrian Lees - * Copyright 2010, 2011 Stephen Fryatt + * Copyright 2010-2014 Stephen Fryatt * * This file is part of NetSurf, http://www.netsurf-browser.org/ * From 8d82cd9963942cd9e78081c27639f69557ca4f08 Mon Sep 17 00:00:00 2001 From: Chris Young Date: Fri, 3 Jan 2014 00:26:45 +0000 Subject: [PATCH 004/773] Attempt fix/workaround of bug #2034 --- amiga/menu.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/amiga/menu.c b/amiga/menu.c index a9185e823..59d244112 100644 --- a/amiga/menu.c +++ b/amiga/menu.c @@ -61,6 +61,7 @@ #include "desktop/hotlist.h" #include "desktop/browser_private.h" #include "desktop/gui.h" +#include "desktop/local_history.h" #include "desktop/textinput.h" #include "utils/messages.h" #include "utils/schedule.h" @@ -715,6 +716,7 @@ static void ami_menu_item_project_newtab(struct Hook *hook, APTR window, struct struct gui_window_2 *gwin; nsurl *url; nserror error; + struct browser_window *bw = NULL; GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); @@ -726,12 +728,16 @@ static void ami_menu_item_project_newtab(struct Hook *hook, APTR window, struct url, NULL, gwin->bw, - NULL); + &bw); nsurl_unref(url); } if (error != NSERROR_OK) { warn_user(messages_get_errorcode(error), 0); + return; } + + history_destroy(bw->history); + bw->history = history_create(); } static void ami_menu_item_project_open(struct Hook *hook, APTR window, struct IntuiMessage *msg) From c25728b01179b8e53f8022d14363b8a81a8c25d5 Mon Sep 17 00:00:00 2001 From: Chris Young Date: Fri, 3 Jan 2014 18:17:25 +0000 Subject: [PATCH 005/773] Move new blank tab into own function --- amiga/gui.c | 30 +++++++++++++++++++++++++++++- amiga/gui.h | 3 ++- amiga/menu.c | 24 ++---------------------- 3 files changed, 33 insertions(+), 24 deletions(-) diff --git a/amiga/gui.c b/amiga/gui.c index c28ea583f..22d5b428d 100644 --- a/amiga/gui.c +++ b/amiga/gui.c @@ -1,5 +1,5 @@ /* - * Copyright 2008-2013 Chris Young + * Copyright 2008-2014 Chris Young * * This file is part of NetSurf, http://www.netsurf-browser.org/ * @@ -3139,6 +3139,34 @@ void ami_gui_tabs_toggle_all(void) } while(node = nnode); } +nserror ami_gui_new_blank_tab(struct gui_window_2 *gwin) +{ + nsurl *url; + nserror error; + struct browser_window *bw = NULL; + + error = nsurl_create(nsoption_charp(homepage_url), &url); + if (error == NSERROR_OK) { + error = browser_window_create(BROWSER_WINDOW_VERIFIABLE | + BROWSER_WINDOW_HISTORY | + BROWSER_WINDOW_TAB, + url, + NULL, + gwin->bw, + &bw); + nsurl_unref(url); + } + if (error != NSERROR_OK) { + warn_user(messages_get_errorcode(error), 0); + return error; + } + + history_destroy(bw->history); + bw->history = history_create(); + + return NSERROR_OK; +} + struct gui_window *gui_create_browser_window(struct browser_window *bw, struct browser_window *clone, bool new_tab) { diff --git a/amiga/gui.h b/amiga/gui.h index 85e5854ea..4ec329eb8 100755 --- a/amiga/gui.h +++ b/amiga/gui.h @@ -1,5 +1,5 @@ /* - * Copyright 2008-2012 Chris Young + * Copyright 2008-2014 Chris Young * * This file is part of NetSurf, http://www.netsurf-browser.org/ * @@ -164,6 +164,7 @@ void ami_gui_hotlist_toolbar_update_all(void); void ami_gui_tabs_toggle_all(void); bool ami_locate_resource(char *fullpath, const char *file); void ami_gui_update_hotlist_button(struct gui_window_2 *gwin); +nserror ami_gui_new_blank_tab(struct gui_window_2 *gwin); struct TextFont *origrpfont; struct MinList *window_list; diff --git a/amiga/menu.c b/amiga/menu.c index 59d244112..26f5c2b81 100644 --- a/amiga/menu.c +++ b/amiga/menu.c @@ -714,30 +714,10 @@ static void ami_menu_item_project_newwin(struct Hook *hook, APTR window, struct static void ami_menu_item_project_newtab(struct Hook *hook, APTR window, struct IntuiMessage *msg) { struct gui_window_2 *gwin; - nsurl *url; nserror error; - struct browser_window *bw = NULL; + GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); - - - error = nsurl_create(nsoption_charp(homepage_url), &url); - if (error == NSERROR_OK) { - error = browser_window_create(BROWSER_WINDOW_VERIFIABLE | - BROWSER_WINDOW_HISTORY | - BROWSER_WINDOW_TAB, - url, - NULL, - gwin->bw, - &bw); - nsurl_unref(url); - } - if (error != NSERROR_OK) { - warn_user(messages_get_errorcode(error), 0); - return; - } - - history_destroy(bw->history); - bw->history = history_create(); + error = ami_gui_new_blank_tab(gwin); } static void ami_menu_item_project_open(struct Hook *hook, APTR window, struct IntuiMessage *msg) From 845923adfc21dae8b434a4abc8efa34d81257ea8 Mon Sep 17 00:00:00 2001 From: Chris Young Date: Fri, 3 Jan 2014 18:20:47 +0000 Subject: [PATCH 006/773] Make the new tab button also use the new blank tab function. This fixes bug 2034 --- amiga/gui.c | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) diff --git a/amiga/gui.c b/amiga/gui.c index 22d5b428d..103d3a1e8 100644 --- a/amiga/gui.c +++ b/amiga/gui.c @@ -1780,24 +1780,7 @@ void ami_handle_msg(void) break; case GID_ADDTAB: - { - nserror error; - - error = nsurl_create(nsoption_charp(homepage_url), &url); - if (error == NSERROR_OK) { - error = browser_window_create(BROWSER_WINDOW_VERIFIABLE | - BROWSER_WINDOW_HISTORY | - BROWSER_WINDOW_TAB, - url, - NULL, - gwin->bw, - NULL); - nsurl_unref(url); - } - if (error != NSERROR_OK) { - warn_user(messages_get_errorcode(error), 0); - } - } + ami_gui_new_blank_tab(gwin); break; case GID_URL: From 8b253a215134c104f853165b4a674ffc24be8cbe Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Sat, 4 Jan 2014 14:00:16 +0000 Subject: [PATCH 007/773] Improve min/max-height handling on replaced elements. --- render/layout.c | 119 ++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 96 insertions(+), 23 deletions(-) diff --git a/render/layout.c b/render/layout.c index 9bd1156ab..7de049080 100644 --- a/render/layout.c +++ b/render/layout.c @@ -75,7 +75,8 @@ static struct box* layout_next_margin_block(struct box *box, struct box *block, int viewport_height, int *max_pos_margin, int *max_neg_margin); static bool layout_block_object(struct box *block); static void layout_get_object_dimensions(struct box *box, - int *width, int *height, int min_width, int max_width); + int *width, int *height, int min_width, int max_width, + int min_height, int max_height); static void layout_block_find_dimensions(int available_width, int viewport_height, int lm, int rm, struct box *box); @@ -88,7 +89,8 @@ static void layout_float_find_dimensions(int available_width, static void layout_find_dimensions(int available_width, int viewport_height, struct box *box, const css_computed_style *style, int *width, int *height, int *max_width, int *min_width, - int margin[4], int padding[4], struct box_border border[4]); + int *max_height, int *min_height, int margin[4], int padding[4], + struct box_border border[4]); static void layout_tweak_form_dimensions(struct box *box, bool percentage, int available_width, bool setwidth, int *dimension); static int layout_clear(struct box *fl, enum css_clear_e clear); @@ -229,7 +231,8 @@ bool layout_block_context(struct box *block, int viewport_height, if (!layout_block_object(block)) return false; layout_get_object_dimensions(block, &temp_width, - &block->height, INT_MIN, INT_MAX); + &block->height, INT_MIN, INT_MAX, + INT_MIN, INT_MAX); return true; } else if (block->flags & REPLACE_DIM) { return true; @@ -903,8 +906,8 @@ struct box* layout_next_margin_block(struct box *box, struct box *block, viewport_height, box, box->style, NULL, NULL, NULL, NULL, - box->margin, box->padding, - box->border); + NULL, NULL, box->margin, + box->padding, box->border); /* Apply top margin */ if (*max_pos_margin < box->margin[TOP]) @@ -977,8 +980,8 @@ struct box* layout_next_margin_block(struct box *box, struct box *block, viewport_height, box, box->style, NULL, NULL, NULL, NULL, - box->margin, box->padding, - box->border); + NULL, NULL, box->margin, + box->padding, box->border); } } } @@ -1029,12 +1032,14 @@ bool layout_block_object(struct box *block) * \param height Height value in px or AUTO. If AUTO, updated to value in px. * \param min_width Box's min width, as given by layout_find_dimensions. * \param max_width Box's max width, as given by layout_find_dimensions. + * \param min_height Box's min height, as given by layout_find_dimensions. + * \param max_height Box's max height, as given by layout_find_dimensions. * * See CSS 2.1 sections 10.3 and 10.6. */ void layout_get_object_dimensions(struct box *box, int *width, int *height, - int min_width, int max_width) + int min_width, int max_width, int min_height, int max_height) { assert(box->object != NULL); assert(width != NULL && height != NULL); @@ -1050,6 +1055,7 @@ void layout_get_object_dimensions(struct box *box, int *width, int *height, *width = intrinsic_width; *height = intrinsic_height; + /* Deal with min/max-width first */ if (min_width > 0 && min_width > *width) { *width = min_width; scaled = true; @@ -1060,10 +1066,28 @@ void layout_get_object_dimensions(struct box *box, int *width, int *height, } if (scaled && (intrinsic_width != 0)) { + /* Update height */ *height = (*width * intrinsic_height) / intrinsic_width; } + scaled = false; + /* Deal with min/max-height */ + if (min_height > 0 && min_height > *height) { + *height = min_height; + scaled = true; + } + if (max_height >= 0 && max_height < *height) { + *height = max_height; + scaled = true; + } + + if (scaled && (intrinsic_height != 0)) { + /* Update width */ + *width = (*height * intrinsic_width) / + intrinsic_height; + } + } else if (*width == AUTO) { /* Have given height; width is calculated from the given height * and ratio of intrinsic dimensions */ @@ -1116,7 +1140,7 @@ void layout_block_find_dimensions(int available_width, int viewport_height, int lm, int rm, struct box *box) { int width, max_width, min_width; - int height; + int height, max_height, min_height; int *margin = box->margin; int *padding = box->padding; struct box_border *border = box->border; @@ -1124,13 +1148,13 @@ void layout_block_find_dimensions(int available_width, int viewport_height, layout_find_dimensions(available_width, viewport_height, box, style, &width, &height, &max_width, &min_width, - margin, padding, border); + &max_height, &min_height, margin, padding, border); if (box->object && !(box->flags & REPLACE_DIM) && content_get_type(box->object) != CONTENT_HTML) { /* block-level replaced element, see 10.3.4 and 10.6.2 */ layout_get_object_dimensions(box, &width, &height, - min_width, max_width); + min_width, max_width, min_height, max_height); } box->width = layout_solve_width(box, available_width, width, lm, rm, @@ -1430,7 +1454,7 @@ int layout_solve_width(struct box *box, int available_width, int width, void layout_float_find_dimensions(int available_width, const css_computed_style *style, struct box *box) { - int width, height, max_width, min_width; + int width, height, max_width, min_width, max_height, min_height; int *margin = box->margin; int *padding = box->padding; struct box_border *border = box->border; @@ -1440,7 +1464,8 @@ void layout_float_find_dimensions(int available_width, SCROLLBAR_WIDTH : 0; layout_find_dimensions(available_width, -1, box, style, &width, &height, - &max_width, &min_width, margin, padding, border); + &max_width, &min_width, &max_height, &min_height, + margin, padding, border); if (margin[LEFT] == AUTO) margin[LEFT] = 0; @@ -1457,7 +1482,7 @@ void layout_float_find_dimensions(int available_width, /* Floating replaced element, with intrinsic width or height. * See 10.3.6 and 10.6.2 */ layout_get_object_dimensions(box, &width, &height, - min_width, max_width); + min_width, max_width, min_height, max_height); } else if (box->gadget && (box->gadget->type == GADGET_TEXTBOX || box->gadget->type == GADGET_PASSWORD || box->gadget->type == GADGET_FILE || @@ -1555,6 +1580,8 @@ void layout_float_find_dimensions(int available_width, * \param height updated to height, may be NULL * \param max_width updated to max-width, may be NULL * \param min_width updated to min-width, may be NULL + * \param max_height updated to max-height, may be NULL + * \param min_height updated to min-height, may be NULL * \param margin[4] filled with margins, may be NULL * \param padding[4] filled with paddings, may be NULL * \param border[4] filled with border widths, may be NULL @@ -1563,7 +1590,8 @@ void layout_float_find_dimensions(int available_width, void layout_find_dimensions(int available_width, int viewport_height, struct box *box, const css_computed_style *style, int *width, int *height, int *max_width, int *min_width, - int margin[4], int padding[4], struct box_border border[4]) + int *max_height, int *min_height, int margin[4], int padding[4], + struct box_border border[4]) { struct box *containing_block = NULL; unsigned int i; @@ -1750,6 +1778,48 @@ void layout_find_dimensions(int available_width, int viewport_height, } } + if (max_height) { + enum css_max_height_e type; + css_fixed value = 0; + css_unit unit = CSS_UNIT_PX; + + type = css_computed_max_height(style, &value, &unit); + + if (type == CSS_MAX_HEIGHT_SET) { + if (unit == CSS_UNIT_PCT) { + /* TODO: handle percentage */ + *max_height = -1; + } else { + *max_height = FIXTOINT(nscss_len2px(value, unit, + style)); + } + } else { + /* Inadmissible */ + *max_height = -1; + } + } + + if (min_height) { + enum css_min_height_e type; + css_fixed value = 0; + css_unit unit = CSS_UNIT_PX; + + type = css_computed_min_height(style, &value, &unit); + + if (type == CSS_MIN_HEIGHT_SET) { + if (unit == CSS_UNIT_PCT) { + /* TODO: handle percentage */ + *min_height = 0; + } else { + *min_height = FIXTOINT(nscss_len2px(value, unit, + style)); + } + } else { + /* Inadmissible */ + *min_height = 0; + } + } + for (i = 0; i != 4; i++) { if (margin) { enum css_margin_e type = CSS_MARGIN_AUTO; @@ -2297,7 +2367,7 @@ bool layout_line(struct box *first, int *width, int *y, #endif for (x = 0, b = first; x <= x1 - x0 && b != 0; b = b->next) { - int min_width, max_width; + int min_width, max_width, min_height, max_height; assert(b->type == BOX_INLINE || b->type == BOX_INLINE_BLOCK || b->type == BOX_FLOAT_LEFT || @@ -2347,7 +2417,8 @@ bool layout_line(struct box *first, int *width, int *y, if (b->type == BOX_INLINE) { /* calculate borders, margins, and padding */ layout_find_dimensions(*width, -1, b, b->style, 0, 0, - 0, 0, b->margin, b->padding, b->border); + 0, 0, 0, 0, b->margin, b->padding, + b->border); for (i = 0; i != 4; i++) if (b->margin[i] == AUTO) b->margin[i] = 0; @@ -2454,11 +2525,12 @@ bool layout_line(struct box *first, int *width, int *y, layout_find_dimensions(*width, -1, b, b->style, &b->width, &b->height, &max_width, &min_width, - NULL, NULL, NULL); + &max_height, &min_height, NULL, NULL, NULL); if (b->object && !(b->flags & REPLACE_DIM)) { layout_get_object_dimensions(b, &b->width, &b->height, - min_width, max_width); + min_width, max_width, + min_height, max_height); } else if (b->flags & IFRAME) { /* TODO: should we look at the content dimensions? */ if (b->width == AUTO) @@ -3185,6 +3257,7 @@ struct box *layout_minmax_line(struct box *first, int temp_height = height; layout_get_object_dimensions(b, &width, &temp_height, + INT_MIN, INT_MAX, INT_MIN, INT_MAX); } @@ -3412,7 +3485,7 @@ bool layout_table(struct box *table, int available_width, /* find margins, paddings, and borders for table and cells */ layout_find_dimensions(available_width, -1, table, style, 0, 0, 0, 0, - table->margin, table->padding, table->border); + 0, 0, table->margin, table->padding, table->border); for (row_group = table->children; row_group; row_group = row_group->next) { for (row = row_group->children; row; row = row->next) { @@ -3420,8 +3493,8 @@ bool layout_table(struct box *table, int available_width, assert(c->style); table_used_border_for_cell(c); layout_find_dimensions(available_width, -1, - c, c->style, 0, 0, 0, 0, 0, - c->padding, c->border); + c, c->style, 0, 0, 0, 0, 0, 0, + 0, c->padding, c->border); if (css_computed_overflow(c->style) == CSS_OVERFLOW_SCROLL || css_computed_overflow(c->style) == @@ -4518,7 +4591,7 @@ bool layout_absolute(struct box *box, struct box *containing_block, box->float_container = containing_block; layout_find_dimensions(available_width, -1, box, box->style, &width, &height, &max_width, &min_width, - margin, padding, border); + 0, 0, margin, padding, border); box->float_container = NULL; /* 10.3.7 */ From 838359194e423fb5c568fca75f9ab6e00600be6c Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Sat, 4 Jan 2014 14:48:58 +0000 Subject: [PATCH 008/773] Return message to client when textarea is modified. --- desktop/textarea.c | 9 +++++++++ desktop/textarea.h | 7 ++++++- render/box_textarea.c | 4 ++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/desktop/textarea.c b/desktop/textarea.c index bfa07ad4f..f9712ac84 100644 --- a/desktop/textarea.c +++ b/desktop/textarea.c @@ -160,6 +160,7 @@ static void textarea_normalise_text(struct textarea *ta, unsigned int b_start, unsigned int b_len) { bool multi = (ta->flags & TEXTAREA_MULTILINE) ? true : false; + struct textarea_msg msg; unsigned int index; /* Remove CR characters. If it's a CRLF pair delete the CR, or replace @@ -187,6 +188,14 @@ static void textarea_normalise_text(struct textarea *ta, ta->text.data[b_start + index] = ' '; } + /* Build text modified message */ + msg.ta = ta; + msg.type = TEXTAREA_MSG_TEXT_MODIFIED; + msg.data.modified.text = ta->text.data; + msg.data.modified.len = ta->text.len; + + /* Pass message to client */ + ta->callback(ta->data, &msg); } diff --git a/desktop/textarea.h b/desktop/textarea.h index 016f15a10..1c24dd1cc 100644 --- a/desktop/textarea.h +++ b/desktop/textarea.h @@ -51,7 +51,8 @@ typedef enum { TEXTAREA_MSG_DRAG_REPORT, /**< Textarea drag start/end report */ TEXTAREA_MSG_SELECTION_REPORT, /**< Textarea text selection presence */ TEXTAREA_MSG_REDRAW_REQUEST, /**< Textarea redraw request */ - TEXTAREA_MSG_CARET_UPDATE /**< Textarea caret */ + TEXTAREA_MSG_CARET_UPDATE, /**< Textarea caret */ + TEXTAREA_MSG_TEXT_MODIFIED /**< Textarea text modified */ } textarea_msg_type; struct textarea_msg { @@ -77,6 +78,10 @@ struct textarea_msg { struct rect *clip; /**< Carret clip rect */ } pos; /**< With _CARET_SET_POS */ } caret; /**< With _CARET_UPDATE */ + struct { + const char *text; /**< UTF8 text */ + unsigned int len; /**< Byte length of text */ + } modified; /**< With _TEXT_MODIFIED */ } data; /**< Depends on msg type */ }; diff --git a/render/box_textarea.c b/render/box_textarea.c index 546a39e04..d34c4c4a4 100644 --- a/render/box_textarea.c +++ b/render/box_textarea.c @@ -204,6 +204,10 @@ static void box_textarea_callback(void *data, struct textarea_msg *msg) msg->data.caret.pos.clip); } break; + + case TEXTAREA_MSG_TEXT_MODIFIED: + /* TODO */ + break; } } From c239a98dd9b93f32418bd8636dd1051cb8a02c36 Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Sat, 4 Jan 2014 16:00:07 +0000 Subject: [PATCH 009/773] Native RO builds have been unsupported for a year, and the doc is out of date. --- Docs/BUILDING-RISC_OS | 121 ------------------------------------------ 1 file changed, 121 deletions(-) delete mode 100644 Docs/BUILDING-RISC_OS diff --git a/Docs/BUILDING-RISC_OS b/Docs/BUILDING-RISC_OS deleted file mode 100644 index 7e61bd22f..000000000 --- a/Docs/BUILDING-RISC_OS +++ /dev/null @@ -1,121 +0,0 @@ --------------------------------------------------------------------------------- - Build Instructions for RISC OS NetSurf 16 July 2012 --------------------------------------------------------------------------------- - - This document provides instructions for building the RISC OS NetSurf - natively on a RISC OS computer and provides guidance on obtaining NetSurf's - build dependencies. - - RISC OS NetSurf should work on RISC OS 4.02 and above. - - | Note: This guide assumes that you have the RISC OS SVN client installed, - | and that you have used it to fetch the NetSurf source. It also - | assumes that you have the following requirements installed: - | - | + OSLib 6.80 or later - | + Perl 5.8.8 or later - | + GCC 3.4.6 release 3 or later - | + The latest NSTools - - If you want to cross-compile NetSurf for RISC OS, use the BUILDING-ROCross - document. - - - Building and executing NetSurf -================================ - - | Note: The version of make supplied with RISC OS GCC 3 is old and has a bug - | that prevents NetSurf from building. Either ensure that NSTools is - | seen before GCC, or replace the make inside "!GCC.bin" with the make - | from "!NSTools.bin". - | The minimum version of make that works is v3.81. You can check what - | version you have by running, '*make --version'. - - | Note: The pre-built libraries currently supplied in NSTools are AOF format, - | and will not work with GCC4, which requires them to be in ELF format. - | If you want to build NetSurf with GCC4, you will need to build the - | libraries yourself. See "Obtaining NetSurf's dependencies" below for - | details. - - You can examine the contents of Makefile.defaults and enable and disable - features as you see fit by creating a Makefile.config file. The default - settings will work fine. - - You should then obtain NetSurf's dependencies, keeping in mind which options - you have enabled in the configuration file. See the next section for - specifics. - - Once done, to build RISC OS NetSurf on a RISC OS system, set the CSD to the - directory containing the NetSurf sources, set the next slot to at least - 6000K, and in a TaskWindow, simply run: - - *make - - If that produces errors, you probably don't have some of NetSurf's build - dependencies installed, or your libraries may be out of date. - - See "Obtaining NetSurf's dependencies" below. Or turn off the complaining - features in a Makefile.config file. You may need to "make clean" before - attempting to build after installing the dependencies. - - Once NetSurf is compiled, the !RunImage is put into the !NetSurf - application directory, so you can simply double click it as normal. - - To confirm that you're running your own development NetSurf build, view the - Info window from the NetSurf iconbar menu. The Version string should read - - #.0 (Development) - - where # is the next major release version number. - - - Obtaining NetSurf's build dependencies -======================================== - - NSTools contains all of the tools needed to build NetSurf, such as make, - uname and ccres. It also contains pre-built libraries. - - Currently NSTools contains libraries which are in a format that are in a - format which is compatible with RISC OS GCC3 but not RISC OS GCC4. Until - NSTools is updated with GCC4 compatible libraries, it is recommended that - you use GCC3 for native builds. - - The NSTools on the web site is not auto-built, so it may not always have - the latest versions of the NetSurf project's own libraries. In this case - you will need to build the libraries yourself and update your copy of - NSTools. - - Fetching the sources ----------------------- - - Use SVN to obtain the latest versions of each of the libraries. To do this, - set the CSD to a directory where you want to keep your copies of the library - sources, and run the appropriate commands from the Docs/LIBRARIES file. - - The above will create a directory for each of the libraries containing their - sources. - - | Note: We advise enabling iconv() support in libparserutils, which vastly - | increases the number of supported character sets. To do this, - | create a file called Makefile.config.override in the libparserutils - | directory, containing the following line: - | - | CFLAGS += -DWITH_ICONV_FILTER - | - | For more information, consult the libparserutils README file. - - Updating NSTools' copies of the libraries -------------------------------------------- - - Set the CSD to the directory of the library you want to build, set your next - slot to at least 6000K and in a TaskWindow, run - - *svn update - - This updates your local copy of the source to the latest version. To build - and install the library into NSTools, run: - - *make install - - | Note: If you are using GCC3, you may get a warning from AR when you run - | make. This can be ignored. From 5a408069c95674bc6e591d0f3a65d3d810746a0f Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Sun, 22 Dec 2013 14:10:55 +0000 Subject: [PATCH 010/773] remove lcms dependancy as NetSurf does not directaly use it. The dependancy probbaly comes from our historical use of libmng, even then the libmng pkg-config should bring it in. --- Docs/BUILDING-GTK | 4 ++-- Docs/env.sh | 2 +- gtk/Makefile.target | 1 - monkey/Makefile.target | 2 +- 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/Docs/BUILDING-GTK b/Docs/BUILDING-GTK index 16b15a4af..35fcd02db 100644 --- a/Docs/BUILDING-GTK +++ b/Docs/BUILDING-GTK @@ -67,7 +67,7 @@ Debian-like OS: $ apt-get install libgtk2.0-dev libcurl3-dev libmng-dev - $ apt-get install librsvg2-dev liblcms1-dev libjpeg-dev + $ apt-get install librsvg2-dev libjpeg-dev If you want to build with gtk 3 replace libgtk2.0-dev with libgtk-3-dev @@ -85,7 +85,7 @@ Fedora: $ yum install curl-devel libmng-devel - $ yum install librsvg2-devel lcms-devel expat-devel + $ yum install librsvg2-devel expat-devel Other: diff --git a/Docs/env.sh b/Docs/env.sh index db2729c0c..8946e46e2 100644 --- a/Docs/env.sh +++ b/Docs/env.sh @@ -53,7 +53,7 @@ NS_BROWSER="netsurf" # deb packages NS_DEV_DEB="build-essential pkg-config git gperf" NS_TOOL_DEB="flex bison" -NS_GTK_DEB="libgtk2.0-dev libcurl3-dev libmng-dev librsvg2-dev liblcms1-dev libjpeg-dev libmozjs-dev" +NS_GTK_DEB="libgtk2.0-dev libcurl3-dev libmng-dev librsvg2-dev libjpeg-dev libmozjs-dev" #add target specific libraries if [ "x${TARGET_ABI}" = "xriscos" ]; then diff --git a/gtk/Makefile.target b/gtk/Makefile.target index ae67fd7f4..426c4affd 100644 --- a/gtk/Makefile.target +++ b/gtk/Makefile.target @@ -62,7 +62,6 @@ $(eval $(call pkg_config_find_and_add,libcurl,Curl )) $(eval $(call pkg_config_find_and_add,gtk+-$(NETSURF_GTK_MAJOR).0,GTK-$(NETSURF_GTK_MAJOR))) $(eval $(call pkg_config_find_and_add,gthread-2.0,GThread2)) $(eval $(call pkg_config_find_and_add,gmodule-2.0,GModule2)) -$(eval $(call pkg_config_find_and_add,lcms,lcms)) CFLAGS += $(GTKCFLAGS) diff --git a/monkey/Makefile.target b/monkey/Makefile.target index 6c60ca1c5..6bea07d46 100644 --- a/monkey/Makefile.target +++ b/monkey/Makefile.target @@ -47,7 +47,7 @@ MONKEYCFLAGS := -std=c99 -Dmonkey -Dnsmonkey \ $(shell $(PKG_CONFIG) --cflags openssl) \ $(shell xml2-config --cflags) -MONKEYLDFLAGS := -lm $(shell $(PKG_CONFIG) --cflags --libs glib-2.0 lcms) +MONKEYLDFLAGS := -lm CFLAGS += $(MONKEYCFLAGS) From c43c456d0505c2b9ee117bf1f5f40fb9be36f1a1 Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Sat, 4 Jan 2014 16:26:02 +0000 Subject: [PATCH 011/773] Use dom_string_isequal, not lwc_string_isequal, for dom strings. --- css/select.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/css/select.c b/css/select.c index ee0e7dacd..0202737b8 100644 --- a/css/select.c +++ b/css/select.c @@ -219,11 +219,9 @@ static void nscss_dom_user_data_handler(dom_node_operation operation, struct dom_node *dst) { css_error error; - bool match; - if (lwc_string_isequal(corestring_dom___ns_key_libcss_node_data, - key, &match) != lwc_error_ok || match == false || - data == NULL) { + if (dom_string_isequal(corestring_dom___ns_key_libcss_node_data, + key) == false || data == NULL) { return; } From f7916866e3e4a81a2ba69d75b04ee6c45673429e Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Sat, 4 Jan 2014 17:07:11 +0000 Subject: [PATCH 012/773] remove all references to using libMNG --- !NetSurf/Resources/en/licence.html,faf | 34 - !NetSurf/Resources/it/licence.html,faf | 37 +- Docs/BUILDING-AmigaCross | 4 - Docs/BUILDING-AmigaOS | 6 +- Docs/BUILDING-BeOS | 4 +- Docs/BUILDING-Framebuffer | 10 +- Docs/BUILDING-GTK | 10 +- Docs/BUILDING-ROCross | 2 - Docs/env.sh | 2 +- Makefile | 1 - Makefile.config.example | 7 +- Makefile.defaults | 10 +- amiga/Makefile.defaults | 4 - amiga/Makefile.target | 1 - atari/Makefile.defaults | 2 - atari/Makefile.target | 1 - beos/Makefile.target | 2 - cocoa/Makefile.defaults | 1 - framebuffer/Makefile.target | 2 - image/Makefile | 1 - image/image.c | 12 - image/mng.c | 832 ------------------------- image/mng.h | 29 - riscos/Makefile.target | 1 - windows/Makefile.defaults | 3 - windows/Makefile.target | 1 - 26 files changed, 18 insertions(+), 1001 deletions(-) delete mode 100644 image/mng.c delete mode 100644 image/mng.h diff --git a/!NetSurf/Resources/en/licence.html,faf b/!NetSurf/Resources/en/licence.html,faf index 6375c56da..7b3aef628 100644 --- a/!NetSurf/Resources/en/licence.html,faf +++ b/!NetSurf/Resources/en/licence.html,faf @@ -158,12 +158,6 @@ version.

MIT -
libmng
-
-© 2000–2007 Gerard Juyn, Glenn Randers-Pehrson -MNG -
-
OSLib
© 1994–1998 Jonathan Coxhead and contributors @@ -642,34 +636,6 @@ ltmain.sh). Another support script, install-sh, is copyright by X Consortium but is also freely distributable. - -

MNG Licence

-
The MNG Library is supplied "AS IS". The Contributing Authors -disclaim all warranties, expressed or implied, including, without -limitation, the warranties of merchantability and of fitness for any -purpose. The Contributing Authors assume no liability for direct, -indirect, incidental, special, exemplary, or consequential damages, -which may result from the use of the MNG Library, even if advised of -the possibility of such damage. - -Permission is hereby granted to use, copy, modify, and distribute this -source code, or portions hereof, for any purpose, without fee, subject -to the following restrictions: - -1. The origin of this source code must not be misrepresented; - you must not claim that you wrote the original software. - -2. Altered versions must be plainly marked as such and must not be - misrepresented as being the original source. - -3. This Copyright notice may not be removed or altered from any source - or altered source distribution. - -The Contributing Authors specifically permit, without fee, and -encourage the use of this source code as a component to supporting -the MNG and JNG file format in commercial products. If you use this -source code in a product, acknowledgment would be highly appreciated. -

OSLib Licence

diff --git a/!NetSurf/Resources/it/licence.html,faf b/!NetSurf/Resources/it/licence.html,faf index 1fa93b39e..b0a6c8ae3 100644 --- a/!NetSurf/Resources/it/licence.html,faf +++ b/!NetSurf/Resources/it/licence.html,faf @@ -150,13 +150,7 @@ dl.components > dd > span + span {
MIT
-
libmng
-
-© 2000–2007 Gerard Juyn, Glenn Randers-Pehrson -MNG -
- -
OSLib
+q
OSLib
© 1994–1998 Jonathan Coxhead and contributors OSLib @@ -631,35 +625,6 @@ ltmain.sh). Another support script, install-sh, is copyright by X Consortium but is also freely distributable. - -

Licenza MNG

-
The MNG Library is supplied "AS IS". The Contributing Authors -disclaim all warranties, expressed or implied, including, without -limitation, the warranties of merchantability and of fitness for any -purpose. The Contributing Authors assume no liability for direct, -indirect, incidental, special, exemplary, or consequential damages, -which may result from the use of the MNG Library, even if advised of -the possibility of such damage. - -Permission is hereby granted to use, copy, modify, and distribute this -source code, or portions hereof, for any purpose, without fee, subject -to the following restrictions: - -1. The origin of this source code must not be misrepresented; - you must not claim that you wrote the original software. - -2. Altered versions must be plainly marked as such and must not be - misrepresented as being the original source. - -3. This Copyright notice may not be removed or altered from any source - or altered source distribution. - -The Contributing Authors specifically permit, without fee, and -encourage the use of this source code as a component to supporting -the MNG and JNG file format in commercial products. If you use this -source code in a product, acknowledgment would be highly appreciated. -
-

Licenza OSLib

The copyright holder has granted a small relaxation of the diff --git a/Docs/BUILDING-AmigaCross b/Docs/BUILDING-AmigaCross index da2e2adf0..32762cd5b 100644 --- a/Docs/BUILDING-AmigaCross +++ b/Docs/BUILDING-AmigaCross @@ -70,10 +70,6 @@ openssl libpng -libmng -http://www.aminet.net/dev/lib/libmng_so.lha -http://www.aminet.net/dev/lib/libmng.lha - liblcms http://www.aminet.net/dev/lib/liblcms_so.lha http://www.aminet.net/dev/lib/liblcms_so.lha diff --git a/Docs/BUILDING-AmigaOS b/Docs/BUILDING-AmigaOS index 4dabf4f11..c15db573f 100644 --- a/Docs/BUILDING-AmigaOS +++ b/Docs/BUILDING-AmigaOS @@ -91,13 +91,13 @@ 1> makelink sdk:local/newlib/lib/libcurl.so sobjs:libcurl-7.16.so soft - libmng + libpng -------- - NetSurf uses libMNG to display MNG and PNG files. + NetSurf uses libPNG to display PNG files. It builds without any problems on OS4, or available from Aminet: - http://www.aminet.net/package/dev/lib/libmng_so + http://www.aminet.net/package/dev/lib/libpng_so OpenSSL diff --git a/Docs/BUILDING-BeOS b/Docs/BUILDING-BeOS index 83ced0e93..8d33a6808 100644 --- a/Docs/BUILDING-BeOS +++ b/Docs/BUILDING-BeOS @@ -89,10 +89,10 @@ TODO - libmng + libpng -------- - NetSurf uses libMNG to display MNG and PNG files. + NetSurf uses libPNG to display PNG files. It should build just fine on BeOS. diff --git a/Docs/BUILDING-Framebuffer b/Docs/BUILDING-Framebuffer index 63ef02dd6..9cbd66065 100644 --- a/Docs/BUILDING-Framebuffer +++ b/Docs/BUILDING-Framebuffer @@ -218,7 +218,7 @@ Index: framebuffer/font_freetype.c Debian-like OS: - $ apt-get install libcurl3-dev libmng-dev + $ apt-get install libcurl3-dev libpng-dev Recent OS versions might need libcurl4-dev instead of libcurl3-dev but note that when it has not been built with OpenSSL, the SSL_CTX is not @@ -228,15 +228,11 @@ Index: framebuffer/font_freetype.c Fedora: - $ yum install curl-devel libmng-devel lcms-devel + $ yum install curl-devel libpng-devel lcms-devel Other: - You'll need to install the development resources for libcurl3 and libmng. - - Note that if you don't require MNG or JNG image support, NetSurf can be - configured to use libpng instead of libmng. If you wish to do this, install - the libpng development package instead. + You'll need to install the development resources for libcurl3 and libpng. The NetSurf project's libraries --------------------------------- diff --git a/Docs/BUILDING-GTK b/Docs/BUILDING-GTK index 35fcd02db..4641924f8 100644 --- a/Docs/BUILDING-GTK +++ b/Docs/BUILDING-GTK @@ -66,7 +66,7 @@ Debian-like OS: - $ apt-get install libgtk2.0-dev libcurl3-dev libmng-dev + $ apt-get install libgtk2.0-dev libcurl3-dev libpng-dev $ apt-get install librsvg2-dev libjpeg-dev If you want to build with gtk 3 replace libgtk2.0-dev with libgtk-3-dev @@ -84,17 +84,13 @@ Fedora: - $ yum install curl-devel libmng-devel + $ yum install curl-devel libpng-devel $ yum install librsvg2-devel expat-devel Other: You'll need to install the development resources for libglade2, libcurl3, - libmng and librsvg. - - Note that if you don't require MNG or JNG image support, NetSurf can be - configured to use libpng instead of libmng. If you wish to do this, install - the libpng development package instead. + libpng and librsvg. The NetSurf project's libraries --------------------------------- diff --git a/Docs/BUILDING-ROCross b/Docs/BUILDING-ROCross index f82ff2ad7..e28847f8d 100644 --- a/Docs/BUILDING-ROCross +++ b/Docs/BUILDING-ROCross @@ -56,8 +56,6 @@ $ ../autobuilder/build libpng12-0 - $ ../autobuilder/build libmng1 - $ ../autobuilder/build oslib B. NetSurf libraries diff --git a/Docs/env.sh b/Docs/env.sh index 8946e46e2..27ae2e92d 100644 --- a/Docs/env.sh +++ b/Docs/env.sh @@ -53,7 +53,7 @@ NS_BROWSER="netsurf" # deb packages NS_DEV_DEB="build-essential pkg-config git gperf" NS_TOOL_DEB="flex bison" -NS_GTK_DEB="libgtk2.0-dev libcurl3-dev libmng-dev librsvg2-dev libjpeg-dev libmozjs-dev" +NS_GTK_DEB="libgtk2.0-dev libcurl3-dev libpng-dev librsvg2-dev libjpeg-dev libmozjs-dev" #add target specific libraries if [ "x${TARGET_ABI}" = "xriscos" ]; then diff --git a/Makefile b/Makefile index 32b1afd07..1638f3228 100644 --- a/Makefile +++ b/Makefile @@ -432,7 +432,6 @@ endif include Makefile.defaults $(eval $(call feature_enabled,JPEG,-DWITH_JPEG,-ljpeg,JPEG (libjpeg))) -$(eval $(call feature_enabled,MNG,-DWITH_MNG,-lmng,JNG/MNG/PNG (libmng))) $(eval $(call feature_enabled,HARU_PDF,-DWITH_PDF_EXPORT,-lhpdf -lpng,PDF export (haru))) $(eval $(call feature_enabled,LIBICONV_PLUG,-DLIBICONV_PLUG,,glibc internal iconv)) diff --git a/Makefile.config.example b/Makefile.config.example index a142d4610..8737e5372 100644 --- a/Makefile.config.example +++ b/Makefile.config.example @@ -8,10 +8,9 @@ # To see the available config options, look at Makefile.defaults, but make any # alterations in your Makefile.config - -### To enable/disable MNG support, uncomment the appropriate line below. -# override NETSURF_USE_MNG := YES -# override NETSURF_USE_MNG := NO +### To enable/disable PNG support, uncomment the appropriate line below. +# override NETSURF_USE_PNG := YES +# override NETSURF_USE_PNG := NO ### To enable/disable SVGTiny support, uncomment the appropriate line below. # override NETSURF_USE_NSSVG := YES diff --git a/Makefile.defaults b/Makefile.defaults index 515f4a042..e11fa1fb6 100644 --- a/Makefile.defaults +++ b/Makefile.defaults @@ -43,16 +43,10 @@ NETSURF_USE_GIF := YES # Valid options: YES, NO (highly recommended) NETSURF_USE_JPEG := YES -# Enable NetSurf's use of libpng for displaying PNGs. If MNG and PNG -# are both enabled then NetSurf will choose libpng for PNGs, leaving -# MNGs and JNGs to libmng. -# Valid options: YES, NO (at least one of PNG/MNG highly recommended) +# Enable NetSurf's use of libpng for displaying PNGs. +# Valid options: YES, NO (highly recommended) NETSURF_USE_PNG := YES -# Enable NetSurf's use of libmng for displaying MNGs, JNGs and PNGs -# Valid options: YES, NO (at least one of PNG/MNG highly recommended) -NETSURF_USE_MNG := YES - # Enable NetSurf's use of libwebp for displaying WebPs # Valid options: YES, NO NETSURF_USE_WEBP := NO diff --git a/amiga/Makefile.defaults b/amiga/Makefile.defaults index 5ff1b69c3..35c35ae76 100644 --- a/amiga/Makefile.defaults +++ b/amiga/Makefile.defaults @@ -10,10 +10,6 @@ # Valid options: YES, NO, AUTO NETSURF_USE_ROSPRITE := NO - # Enable NetSurf's use of libmng for displaying MNGs, JNGs and PNGs - # Valid options: YES, NO (at least one of PNG/MNG/DT highly recommended) - NETSURF_USE_MNG := NO - # Enable NetSurf's use of libwebp for displaying WebPs # Valid options: YES, NO NETSURF_USE_WEBP := NO diff --git a/amiga/Makefile.target b/amiga/Makefile.target index 484c57dcb..b3220a142 100644 --- a/amiga/Makefile.target +++ b/amiga/Makefile.target @@ -23,7 +23,6 @@ ifeq ($(HOST),amiga) $(eval $(call feature_enabled,GIF,-DWITH_GIF,-lnsgif,GIF (libnsgif))) $(eval $(call feature_enabled,PNG,-DWITH_PNG,-lpng,PNG (libpng) )) $(eval $(call feature_enabled,NSSVG,-DWITH_NS_SVG,-lsvgtiny,SVG (libsvgtiny))) - $(eval $(call feature_enabled,MNG,,-llcms -ljpeg,PNG/JNG/MNG (libmng))) $(eval $(call feature_enabled,WEBP,-DWITH_WEBP,-lwebp,WebP (libwebp))) $(eval $(call feature_enabled,VIDEO,-DWITH_VIDEO -I /SDK/local/newlib/include/glib-2.0,-lgstreamer-0.10 -lglib-2.0 -lgobject-2.0 -lgmodule-2.0 -lgthread-2.0 -lintl -lffi,Video (libgstreamer))) $(eval $(call feature_enabled,JS,-DXP_UNIX -DWITH_JS -DJS_VERSION=185,-lstdc++ -lmozjs185,JavaScript)) diff --git a/atari/Makefile.defaults b/atari/Makefile.defaults index ccc9b49ce..d4ef0232b 100644 --- a/atari/Makefile.defaults +++ b/atari/Makefile.defaults @@ -22,8 +22,6 @@ # Valid options: YES, NO, AUTO NETSURF_USE_NSSVG := AUTO - NETSURF_USE_MNG := NO - # Enable Spidermonkey JavaScript engine # Valid options: YES, NO NETSURF_USE_MOZJS := NO diff --git a/atari/Makefile.target b/atari/Makefile.target index 283361355..bc79b0625 100644 --- a/atari/Makefile.target +++ b/atari/Makefile.target @@ -35,7 +35,6 @@ endif FREETYPE_FONT_CFLAGS := $(shell freetype-config --cflags) -DWITH_FREETYPE_FONT_DRIVER SPIDERMONKEY_CFLAGS := -DWITH_MOZJS -DXP_UNIX -DJS_HAS_FILE_OBJECT=0 -DJSOPTION_JIT=0 -DPOSIX_SOURCE -D_BSD_SOURCE -$(eval $(call feature_enabled,MNG,-DWITH_MNG,-lmng,PNG/MNG/JNG (libmng))) $(eval $(call feature_enabled,PNG,-DWITH_PNG,-lpng,PNG (libpng))) $(eval $(call feature_enabled,MOZJS,$(SPIDERMONKEY_CFLAGS),-ljs,JavaScript (Spidermonkey))) $(eval $(call feature_enabled,ATARI_FREETYPE_FONT,$(FREETYPE_FONT_CFLAGS),-lfreetype,(Freetype))) diff --git a/beos/Makefile.target b/beos/Makefile.target index 499ec16e9..81e2a951e 100644 --- a/beos/Makefile.target +++ b/beos/Makefile.target @@ -32,7 +32,6 @@ RSRC_BEOS = $(addprefix $(OBJROOT)/,$(subst /,_,$(patsubst %.rdef,%.rsrc,$(RDEF_ RESOURCES = $(RSRC_BEOS) ifeq ($(HOST),beos) CFLAGS += -I/boot/home/config/include \ - -I/boot/home/config/include/libmng \ -I/boot/home/config/include/hubbub \ -I/boot/home/config/include/libcss \ -I/boot/home/config/include/parserutils @@ -42,7 +41,6 @@ ifeq ($(HOST),beos) ifneq ($(wildcard /boot/develop/lib/*/libnetwork.so),) # Haiku CFLAGS += -I/boot/common/include \ - -I/boot/common/include/libmng \ -I/boot/common/include/hubbub \ -I/boot/common/include/libcss \ -I/boot/common/include/parserutils diff --git a/cocoa/Makefile.defaults b/cocoa/Makefile.defaults index b2f64ec56..24517490c 100644 --- a/cocoa/Makefile.defaults +++ b/cocoa/Makefile.defaults @@ -22,7 +22,6 @@ # Valid options: YES, NO, AUTO NETSURF_USE_NSSVG := AUTO - NETSURF_USE_MNG := NO NETSURF_USE_BMP := NO NETSURF_USE_GIF := NO NETSURF_USE_PNG := NO diff --git a/framebuffer/Makefile.target b/framebuffer/Makefile.target index d423e298f..5c658925e 100644 --- a/framebuffer/Makefile.target +++ b/framebuffer/Makefile.target @@ -2,8 +2,6 @@ # Framebuffer target setup # ---------------------------------------------------------------------------- - -$(eval $(call feature_enabled,MNG,-DWITH_MNG,-lmng,PNG/MNG/JNG (libmng))) $(eval $(call feature_enabled,PNG,-DWITH_PNG,-lpng,PNG (libpng) )) ifeq ($(NETSURF_FB_FONTLIB),freetype) diff --git a/image/Makefile b/image/Makefile index becd944cd..9992c5443 100644 --- a/image/Makefile +++ b/image/Makefile @@ -6,7 +6,6 @@ S_IMAGE_NO := S_IMAGE_$(NETSURF_USE_BMP) += bmp.c ico.c S_IMAGE_$(NETSURF_USE_GIF) += gif.c S_IMAGE_$(NETSURF_USE_JPEG) += jpeg.c -S_IMAGE_$(NETSURF_USE_MNG) += mng.c S_IMAGE_$(NETSURF_USE_ROSPRITE) += nssprite.c S_IMAGE_$(NETSURF_USE_PNG) += png.c S_IMAGE_$(NETSURF_USE_NSSVG) += svg.c diff --git a/image/image.c b/image/image.c index becf221b9..97ab2c0a3 100644 --- a/image/image.c +++ b/image/image.c @@ -31,7 +31,6 @@ #include "image/gif.h" #include "image/ico.h" #include "image/jpeg.h" -#include "image/mng.h" #include "image/nssprite.h" #include "image/png.h" #include "image/rsvg.h" @@ -73,18 +72,7 @@ nserror image_init(void) return error; #endif -#ifdef WITH_MNG - error = nsmng_init(); - if (error != NSERROR_OK) - return error; - - error = nsjpng_init(); - if (error != NSERROR_OK) - return error; -#endif - #ifdef WITH_PNG - /* Prefer libpng over libmng for pngs by registering later */ error = nspng_init(); if (error != NSERROR_OK) return error; diff --git a/image/mng.c b/image/mng.c deleted file mode 100644 index 325d1d192..000000000 --- a/image/mng.c +++ /dev/null @@ -1,832 +0,0 @@ -/* - * Copyright 2005 Richard Wilson - * - * This file is part of NetSurf, http://www.netsurf-browser.org/ - * - * NetSurf is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License. - * - * NetSurf is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -/** \file - * Content for image/mng, image/png, and image/jng (implementation). - */ - -#include -#include -#include -#include -#include -#include -#include -#include "content/content_protected.h" -#include "utils/nsoption.h" -#include "desktop/plotters.h" -#include "image/bitmap.h" -#include "image/mng.h" -#include "utils/log.h" -#include "utils/messages.h" -#include "utils/schedule.h" -#include "utils/utils.h" - -/* This implementation does not currently support dynamic MNGs or any - * form of colour/gamma correction, - */ - -typedef struct nsmng_content -{ - struct content base; - - bool opaque_test_pending; - bool read_start; - bool read_resume; - int read_size; - bool waiting; - bool displayed; - void *handle; - - struct bitmap *bitmap; /**< Created NetSurf bitmap */ -} nsmng_content; - - -#ifndef MNG_INTERNAL_MEMMNGMT - -/** - * Memory allocation callback for libmng. - */ - -static mng_ptr nsmng_alloc(mng_size_t n) -{ - return calloc(1, n); -} - - -/** - * Memory free callback for libmng. - */ - -static void nsmng_free(mng_ptr p, mng_size_t n) -{ - free(p); -} - -#endif - -/** - * Broadcasts an error message and returns false - * - * \param c the content to broadcast for - * \return Appropriate error - */ -static nserror nsmng_broadcast_error(nsmng_content *c, mng_retcode code) -{ - union content_msg_data msg_data; - char error[100]; - - assert(c != NULL); - - if (code == MNG_OUTOFMEMORY) { - msg_data.error = messages_get("NoMemory"); - content_broadcast(&c->base, CONTENT_MSG_ERROR, msg_data); - return NSERROR_NOMEM; - } - - snprintf(error, sizeof error, messages_get("MNGError"), code); - msg_data.error = error; - content_broadcast(&c->base, CONTENT_MSG_ERROR, msg_data); - return NSERROR_MNG_ERROR; -} - -/* CALLBACKS REQUIRED FOR libmng READING */ - -static mng_bool nsmng_openstream(mng_handle mng) -{ - assert(mng != NULL); - return MNG_TRUE; -} - -static mng_bool nsmng_readdata(mng_handle mng, mng_ptr buffer, mng_uint32 size, - mng_uint32 *bytesread) -{ - nsmng_content *c; - const char *data; - unsigned long data_size; - - assert(mng != NULL); - assert(buffer != NULL); - assert(bytesread != NULL); - - /* Get our content back - */ - c = (nsmng_content *) mng_get_userdata(mng); - assert(c != NULL); - - /* Copy any data we have (maximum of 'size') - */ - data = content__get_source_data(&c->base, &data_size); - - *bytesread = ((data_size - c->read_size) < size) ? - (data_size - c->read_size) : size; - - if ((*bytesread) > 0) { - memcpy(buffer, data + c->read_size, *bytesread); - c->read_size += *bytesread; - } - - /* Return success - */ - return MNG_TRUE; -} - -static mng_bool nsmng_closestream(mng_handle mng) -{ - assert(mng != NULL); - return MNG_TRUE; -} - -static mng_bool nsmng_processheader(mng_handle mng, mng_uint32 width, - mng_uint32 height) -{ - nsmng_content *c; - union content_msg_data msg_data; - uint8_t *buffer; - - assert(mng != NULL); - - /* This function is called when the header has been read and we - know the dimensions of the canvas. - */ - c = (nsmng_content *) mng_get_userdata(mng); - assert(c != NULL); - - c->bitmap = bitmap_create(width, height, BITMAP_NEW); - if (c->bitmap == NULL) { - msg_data.error = messages_get("NoMemory"); - content_broadcast(&c->base, CONTENT_MSG_ERROR, msg_data); - LOG(("Insufficient memory to create canvas.")); - return MNG_FALSE; - } - - /* Get the buffer to ensure that it is allocated and the calls in - * nsmng_getcanvasline() succeed. */ - buffer = bitmap_get_buffer(c->bitmap); - if (buffer == NULL) { - msg_data.error = messages_get("NoMemory"); - content_broadcast(&c->base, CONTENT_MSG_ERROR, msg_data); - LOG(("Insufficient memory to create canvas.")); - return MNG_FALSE; - } - - /* Initialise the content size - */ - c->base.width = width; - c->base.height = height; - - /* Set the canvas style - */ - if (mng_set_canvasstyle(mng, MNG_CANVAS_RGBA8) != MNG_NOERROR) { - LOG(("Error setting canvas style.")); - } - - /* Return success - */ - return MNG_TRUE; -} - - -/* END OF CALLBACKS REQUIRED FOR READING -*/ - - -static bool nsmng_process_data(struct content *c, const char *data, unsigned int size) -{ - nsmng_content *mng = (nsmng_content *) c; - mng_retcode status; - - assert(c != NULL); - assert(data != NULL); - - /* We only need to do any processing if we're starting/resuming reading. - */ - if ((!mng->read_resume) && (!mng->read_start)) - return true; - - /* Try to start processing, or process some more data - */ - if (mng->read_start) { - status = mng_read(mng->handle); - mng->read_start = false; - } else { - status = mng_read_resume(mng->handle); - } - mng->read_resume = (status == MNG_NEEDMOREDATA); - if ((status != MNG_NOERROR) && (status != MNG_NEEDMOREDATA)) { - LOG(("Failed to start/continue reading (%i).", status)); - return nsmng_broadcast_error(mng, status) == NSERROR_OK; - } - - /* Continue onwards - */ - return true; -} - -/* START OF CALLBACKS REQUIRED FOR DISPLAYING -*/ - - -static mng_ptr nsmng_getcanvasline(mng_handle mng, mng_uint32 line) -{ - nsmng_content *c; - - assert(mng != NULL); - - /* Get our content back - */ - c = (nsmng_content *) mng_get_userdata(mng); - assert(c != NULL); - - /* Calculate the address - */ - return bitmap_get_buffer(c->bitmap) + - bitmap_get_rowstride(c->bitmap) * line; -} - -static mng_bool nsmng_refresh(mng_handle mng, mng_uint32 x, mng_uint32 y, - mng_uint32 w, mng_uint32 h) -{ - union content_msg_data data; - nsmng_content *c; - - assert(mng != NULL); - - /* Get our content back - */ - c = (nsmng_content *) mng_get_userdata(mng); - assert(c != NULL); - - /* Set the minimum redraw area - */ - data.redraw.x = x; - data.redraw.y = y; - data.redraw.width = w; - data.redraw.height = h; - - /* Set the redraw area to the whole canvas to ensure that if - we can redraw something to trigger animation later then we do - */ -/* data.redraw.x = 0; - data.redraw.y = 0; - data.redraw.width = c->width; - data.redraw.height = c->height; -*/ - /* Always redraw everything - */ - data.redraw.full_redraw = true; - - /* Set the object characteristics - */ - data.redraw.object = &c->base; - data.redraw.object_x = 0; - data.redraw.object_y = 0; - data.redraw.object_width = c->base.width; - data.redraw.object_height = c->base.height; - - /* Only attempt to force the redraw if we've been requested to - * display the image in the first place (i.e. nsmng_redraw has - * been called). This avoids the situation of forcibly redrawing - * an image that shouldn't be shown (e.g. if the image is a fallback - * for an object that can't be rendered) - */ - if (c->displayed) - content_broadcast(&c->base, CONTENT_MSG_REDRAW, data); - - return MNG_TRUE; -} - -/** - * Animates to the next frame - */ -static void nsmng_animate(void *p) -{ - nsmng_content *c; - - assert(p != NULL); - - c = (nsmng_content *) p; - - /* If we used the last animation we advance, if not we try again later - */ - if (c->base.user_list->next == NULL) { - c->waiting = true; - } else { - c->waiting = false; - mng_display_resume(c->handle); - c->opaque_test_pending = true; - if (c->bitmap) - bitmap_modified(c->bitmap); - } -} - -static mng_bool nsmng_settimer(mng_handle mng, mng_uint32 msecs) -{ - nsmng_content *c; - - assert(mng != NULL); - - /* Get our content back - */ - c = (nsmng_content *) mng_get_userdata(mng); - assert(c != NULL); - - /* Perform the scheduling - */ - schedule(msecs / 10, nsmng_animate, c); - return MNG_TRUE; -} - -/** - * Get the wall-clock time in milliseconds since some fixed time. - */ - -static mng_uint32 nsmng_gettickcount(mng_handle mng) -{ - static bool start = true; - static time_t t0; - struct timeval tv; -#if defined(__SVR4) && defined(__sun) || defined(__NetBSD__) || \ - defined(__APPLE__) - /* Solaris, NetBSD, and OS X don't have this structure, and ignore the - * second parameter to gettimeofday() - */ - int tz; -#else - struct timezone tz; -#endif - assert(mng != NULL); - - gettimeofday(&tv, &tz); - if (start) { - t0 = tv.tv_sec; - start = false; - } - - return (tv.tv_sec - t0) * 1000 + tv.tv_usec / 1000; -} - -/* END OF CALLBACKS REQUIRED FOR DISPLAYING -*/ - -static mng_bool nsmng_errorproc(mng_handle mng, mng_int32 code, - mng_int8 severity, mng_chunkid chunktype, mng_uint32 chunkseq, - mng_int32 extra1, mng_int32 extra2, mng_pchar text) -{ - nsmng_content *c; - char chunk[5]; - - assert(mng != NULL); - - c = (nsmng_content *) mng_get_userdata(mng); - assert(c != NULL); - - chunk[0] = (char)((chunktype >> 24) & 0xFF); - chunk[1] = (char)((chunktype >> 16) & 0xFF); - chunk[2] = (char)((chunktype >> 8) & 0xFF); - chunk[3] = (char)((chunktype ) & 0xFF); - chunk[4] = '\0'; - - LOG(("error playing '%s' chunk %s (%d):", - content_get_url(&c->base), chunk, chunkseq)); - LOG(("code %d severity %d extra1 %d extra2 %d text:'%s'", code, - severity, extra1, extra2, text)); - - return (0); -} - -static nserror nsmng_create_mng_data(nsmng_content *c) -{ - mng_retcode code; - union content_msg_data msg_data; - - assert(c != NULL); - - /* Initialise the library - */ -#ifdef MNG_INTERNAL_MEMMNGMT - c->handle = mng_initialize(c, MNG_NULL, MNG_NULL, MNG_NULL); -#else - c->handle = mng_initialize(c, nsmng_alloc, nsmng_free, MNG_NULL); -#endif - if (c->handle == MNG_NULL) { - LOG(("Unable to initialise MNG library.")); - msg_data.error = messages_get("NoMemory"); - content_broadcast(&c->base, CONTENT_MSG_ERROR, msg_data); - return NSERROR_NOMEM; - } - - /* We need to decode in suspension mode - */ - code = mng_set_suspensionmode(c->handle, MNG_TRUE); - if (code) { - LOG(("Unable to set suspension mode.")); - return nsmng_broadcast_error(c, code); - } - - /* We need to register our callbacks - */ - code = mng_setcb_openstream(c->handle, nsmng_openstream); - if (code) { - LOG(("Unable to set openstream callback.")); - return nsmng_broadcast_error(c, code); - } - code = mng_setcb_readdata(c->handle, nsmng_readdata); - if (code) { - LOG(("Unable to set readdata callback.")); - return nsmng_broadcast_error(c, code); - } - code = mng_setcb_closestream(c->handle, nsmng_closestream); - if (code) { - LOG(("Unable to set closestream callback.")); - return nsmng_broadcast_error(c, code); - } - code = mng_setcb_processheader(c->handle, nsmng_processheader); - if (code) { - LOG(("Unable to set processheader callback.")); - return nsmng_broadcast_error(c, code); - } - - /* Register our callbacks for displaying - */ - code = mng_setcb_getcanvasline(c->handle, nsmng_getcanvasline); - if (code) { - LOG(("Unable to set getcanvasline callback.")); - return nsmng_broadcast_error(c, code); - } - code = mng_setcb_refresh(c->handle, nsmng_refresh); - if (code) { - LOG(("Unable to set refresh callback.")); - return nsmng_broadcast_error(c, code); - } - code = mng_setcb_gettickcount(c->handle, nsmng_gettickcount); - if (code) { - LOG(("Unable to set gettickcount callback.")); - return nsmng_broadcast_error(c, code); - } - code = mng_setcb_settimer(c->handle, nsmng_settimer); - if (code) { - LOG(("Unable to set settimer callback.")); - return nsmng_broadcast_error(c, code); - } - - /* register error handling function */ - code = mng_setcb_errorproc(c->handle, nsmng_errorproc); - if (code) { - LOG(("Unable to set errorproc")); - return nsmng_broadcast_error(c, code); - } - - /* Initialise the reading - */ - c->read_start = true; - c->read_resume = false; - c->read_size = 0; - c->waiting = false; - - c->displayed = false; - - return NSERROR_OK; -} - -static nserror nsmng_create(const content_handler *handler, - lwc_string *imime_type, const struct http_parameter *params, - llcache_handle *llcache, const char *fallback_charset, - bool quirks, struct content **c) -{ - nsmng_content *mng; - nserror error; - - mng = calloc(1, sizeof(nsmng_content)); - if (mng == NULL) - return NSERROR_NOMEM; - - error = content__init(&mng->base, handler, imime_type, params, - llcache, fallback_charset, quirks); - if (error != NSERROR_OK) { - free(mng); - return error; - } - - error = nsmng_create_mng_data(mng); - if (error != NSERROR_OK) { - free(mng); - return error; - } - - *c = (struct content *) mng; - - return NSERROR_OK; -} - - - -static bool nsmng_convert(struct content *c) -{ - nsmng_content *mng = (nsmng_content *) c; - mng_retcode status; - unsigned long size; - char *title; - - assert(c != NULL); - - content__get_source_data(c, &size); - - /* by this point, the png should have been parsed - * and the bitmap created, so ensure that's the case - */ - if (mng->bitmap == NULL) { - return nsmng_broadcast_error(mng, -1) == NSERROR_OK; - } - - - /* set title text */ - title = messages_get_buff("MNGTitle", - nsurl_access_leaf(llcache_handle_get_url(c->llcache)), - c->width, c->height); - if (title != NULL) { - content__set_title(c, title); - free(title); - } - - c->size += c->width * c->height * 4; - content_set_ready(c); - content_set_done(c); - /* Done: update status bar */ - content_set_status(c, ""); - - /* jmb: I'm really not sure that this should be here. - * The *_convert functions are for converting a content into a - * displayable format. They should not, however, do anything which - * could cause the content to be displayed; the content may have - * hidden visibility or be a fallback for an object; this - * information is not available here (nor is there any need for it - * to be). - * The specific issue here is that mng_display calls the display - * callbacks, which include nsmng_refresh. nsmng_refresh forces - * a content to be redrawn regardless of whether it should be - * displayed or not. - */ - /* Start displaying - */ - status = mng_display(mng->handle); - if ((status != MNG_NOERROR) && (status != MNG_NEEDTIMERWAIT)) { - LOG(("Unable to start display (%i)", status)); - return nsmng_broadcast_error(mng, status) == NSERROR_OK; - } - bitmap_modified(mng->bitmap); - - /* Optimise the plotting of MNG */ - mng->opaque_test_pending = false; - - return true; -} - -static bool nsjpng_convert(struct content *c) -{ - nsmng_content *mng = (nsmng_content *) c; - mng_retcode status; - unsigned long size; - char *title; - mng_handle handle; - - assert(c != NULL); - - content__get_source_data(c, &size); - - /* by this point, the png should have been parsed - * and the bitmap created, so ensure that's the case - */ - if (mng->bitmap == NULL) { - return nsmng_broadcast_error(mng, -1) == NSERROR_OK; - } - - /* set title text */ - title = messages_get_buff("PNGTitle", - nsurl_access_leaf(llcache_handle_get_url(c->llcache)), - c->width, c->height); - if (title != NULL) { - content__set_title(c, title); - free(title); - } - - c->size += c->width * c->height * 4; - content_set_ready(c); - content_set_done(c); - /* Done: update status bar */ - content_set_status(c, ""); - - /* jmb: I'm really not sure that this should be here. - * The *_convert functions are for converting a content into a - * displayable format. They should not, however, do anything which - * could cause the content to be displayed; the content may have - * hidden visibility or be a fallback for an object; this - * information is not available here (nor is there any need for it - * to be). - * The specific issue here is that mng_display calls the display - * callbacks, which include nsmng_refresh. nsmng_refresh forces - * a content to be redrawn regardless of whether it should be - * displayed or not. - */ - /* Start displaying - */ - status = mng_display(mng->handle); - if ((status != MNG_NOERROR) && (status != MNG_NEEDTIMERWAIT)) { - LOG(("Unable to start display (%i)", status)); - return nsmng_broadcast_error(mng, status) == NSERROR_OK; - } - bitmap_modified(mng->bitmap); - - /* Optimise the plotting of JNG/PNGs - */ - mng->opaque_test_pending = true; - bitmap_set_opaque(mng->bitmap, false); - - /* free associated memory */ - - handle = mng->handle; - - mng_cleanup(&handle); - - mng->handle = NULL; - - return true; -} - -static void nsmng_destroy(struct content *c) -{ - nsmng_content *mng = (nsmng_content *) c; - - assert (c != NULL); - - /* Cleanup the MNG structure and release the canvas memory - */ - schedule_remove(nsmng_animate, c); - - if (mng->handle != NULL) { - mng_handle handle = mng->handle; - - mng_cleanup(&handle); - - mng->handle = NULL; - } - - if (mng->bitmap) { - bitmap_destroy(mng->bitmap); - } -} - - -static bool nsmng_redraw(struct content *c, struct content_redraw_data *data, - const struct rect *clip, const struct redraw_context *ctx) -{ - nsmng_content *mng = (nsmng_content *) c; - bool ret; - bitmap_flags_t flags = BITMAPF_NONE; - - /* mark image as having been requested to display */ - mng->displayed = true; - - if ((mng->bitmap) && - (mng->opaque_test_pending)) { - bitmap_set_opaque(mng->bitmap, bitmap_test_opaque(mng->bitmap)); - mng->opaque_test_pending = false; - } - - if (data->repeat_x) - flags |= BITMAPF_REPEAT_X; - if (data->repeat_y) - flags |= BITMAPF_REPEAT_Y; - - ret = ctx->plot->bitmap(data->x, data->y, data->width, data->height, - mng->bitmap, data->background_colour, flags); - - /* Check if we need to restart the animation */ - if ((mng->waiting) && - (nsoption_bool(animate_images))) { - nsmng_animate(c); - } - - return ret; -} - - -static nserror nsmng_clone(const struct content *old, struct content **newc) -{ - nsmng_content *mng; - nserror error; - const char *data; - unsigned long size; - - mng = calloc(1, sizeof(nsmng_content)); - if (mng == NULL) - return NSERROR_NOMEM; - - error = content__clone(old, &mng->base); - if (error != NSERROR_OK) { - content_destroy(&mng->base); - return error; - } - - /* Simply replay create/process/convert */ - error = nsmng_create_mng_data(mng); - if (error != NSERROR_OK) { - content_destroy(&mng->base); - return error; - } - - data = content__get_source_data(&mng->base, &size); - if (size > 0) { - if (nsmng_process_data(&mng->base, data, size) == false) { - content_destroy(&mng->base); - return NSERROR_CLONE_FAILED; - } - } - - if (old->status == CONTENT_STATUS_READY || - old->status == CONTENT_STATUS_DONE) { - if (nsmng_convert(&mng->base) == false) { - content_destroy(&mng->base); - return NSERROR_CLONE_FAILED; - } - } - - *newc = (struct content *) mng; - - return NSERROR_OK; -} - -static void *nsmng_get_internal(const struct content *c, void *context) -{ - nsmng_content *mng = (nsmng_content *)c; - - return mng->bitmap; -} - -static content_type nsmng_content_type(void) -{ - return CONTENT_IMAGE; -} - -/* register handler for mng types */ -static const content_handler nsmng_content_handler = { - .create = nsmng_create, - .process_data = nsmng_process_data, - .data_complete = nsmng_convert, - .destroy = nsmng_destroy, - .redraw = nsmng_redraw, - .clone = nsmng_clone, - .get_internal = nsmng_get_internal, - .type = nsmng_content_type, - .no_share = false, -}; - -static const char *nsmng_types[] = { - /* MNG types*/ - "image/mng", - "image/x-mng", - "video/mng", - "video/x-mng", -}; - -CONTENT_FACTORY_REGISTER_TYPES(nsmng, nsmng_types, nsmng_content_handler); - -/* register handler for jng and png types */ -static const content_handler nsjpng_content_handler = { - .create = nsmng_create, - .process_data = nsmng_process_data, - .data_complete = nsjpng_convert, - .destroy = nsmng_destroy, - .redraw = nsmng_redraw, - .clone = nsmng_clone, - .get_internal = nsmng_get_internal, - .type = nsmng_content_type, - .no_share = false, -}; - - -static const char *nsjpng_types[] = { - /* JNG types*/ - "image/jng", - "image/x-jng", - /* PNG types*/ - "image/png", - "image/x-png" -}; - -CONTENT_FACTORY_REGISTER_TYPES(nsjpng, nsjpng_types, nsjpng_content_handler); diff --git a/image/mng.h b/image/mng.h deleted file mode 100644 index 7ad779904..000000000 --- a/image/mng.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2004 Richard Wilson - * - * This file is part of NetSurf, http://www.netsurf-browser.org/ - * - * NetSurf is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License. - * - * NetSurf is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -/** \file - * Content for image/mng, image/png, and image/jng (interface). - */ - -#ifndef _NETSURF_IMAGE_MNG_H_ -#define _NETSURF_IMAGE_MNG_H_ - -nserror nsmng_init(void); -nserror nsjpng_init(void); - -#endif diff --git a/riscos/Makefile.target b/riscos/Makefile.target index 3d64e24f9..05e66c829 100644 --- a/riscos/Makefile.target +++ b/riscos/Makefile.target @@ -45,7 +45,6 @@ RESOURCES = $(TPD_RISCOS) split-messages CFLAGS += $(WARNFLAGS) -Driscos -std=c99 -D_BSD_SOURCE -D_POSIX_C_SOURCE \ -mpoke-function-name -fno-strict-aliasing -CFLAGS += -I$(GCCSDK_INSTALL_ENV)/include -I$(GCCSDK_INSTALL_ENV)/include/libmng ifeq ($(HOST),riscos) CFLAGS += -I -mthrowback endif diff --git a/windows/Makefile.defaults b/windows/Makefile.defaults index 68fb7af66..10c9abbf7 100644 --- a/windows/Makefile.defaults +++ b/windows/Makefile.defaults @@ -14,9 +14,6 @@ # Valid options: YES, NO NETSURF_USE_LIBICONV_PLUG := NO - # mng support does not currently build on windows - NETSURF_USE_MNG := NO - # no pdf support NETSURF_USE_HARU_PDF := NO diff --git a/windows/Makefile.target b/windows/Makefile.target index 1cdb4a61a..cad28b575 100644 --- a/windows/Makefile.target +++ b/windows/Makefile.target @@ -16,7 +16,6 @@ $(eval $(call feature_enabled,BMP,-DWITH_BMP,-lnsbmp,BMP (libnsbmp))) $(eval $(call feature_enabled,GIF,-DWITH_GIF,-lnsgif,GIF (libnsgif))) $(eval $(call feature_enabled,PNG,-DWITH_PNG,-lpng,PNG (libpng) )) $(eval $(call feature_enabled,NSSVG,-DWITH_NS_SVG,-lsvgtiny,SVG (libsvgtiny))) -$(eval $(call feature_enabled,MNG,,-llcms -ljpeg,PNG/JNG/MNG (libmng))) ifneq ($(PKG_CONFIG),) $(eval $(call pkg_config_find_and_add,zlib,ZLib)) From 0aa488288caa69738032a7f68d3b75ab1e776c61 Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Sat, 4 Jan 2014 17:54:43 +0000 Subject: [PATCH 013/773] Fix longstanding bug where floating root element caused assertion. Bug #394. --- render/box_construct.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/render/box_construct.c b/render/box_construct.c index a72f918f8..b259e6a1f 100644 --- a/render/box_construct.c +++ b/render/box_construct.c @@ -1013,12 +1013,13 @@ bool box_construct_element(struct box_construct_ctx *ctx, box->type == BOX_BR || box->type == BOX_INLINE_BLOCK || css_computed_float(box->style) == CSS_FLOAT_LEFT || - css_computed_float(box->style) == CSS_FLOAT_RIGHT)) { + css_computed_float(box->style) == CSS_FLOAT_RIGHT) && + props.node_is_root == false) { /* Found an inline child of a block without a current container * (i.e. this box is the first child of its parent, or was * preceded by block-level siblings) */ assert(props.containing_block != NULL && - "Root box must not be inline or floated"); + "Box must have containing block."); props.inline_container = box_create(NULL, NULL, false, NULL, NULL, NULL, NULL, ctx->bctx); @@ -1073,9 +1074,11 @@ bool box_construct_element(struct box_construct_ctx *ctx, return false; } - if (css_computed_float(box->style) == CSS_FLOAT_LEFT || + if (props.node_is_root == false && + (css_computed_float(box->style) == + CSS_FLOAT_LEFT || css_computed_float(box->style) == - CSS_FLOAT_RIGHT) { + CSS_FLOAT_RIGHT)) { /* Float: insert a float between the parent and box. */ struct box *flt = box_create(NULL, NULL, false, props.href, props.target, props.title, From 068b07494bc5491705da6b5056bd442efc3b797f Mon Sep 17 00:00:00 2001 From: Daniel Silverstone Date: Sat, 4 Jan 2014 15:37:51 +0000 Subject: [PATCH 014/773] Retrieve text area content from the textarea api --- render/box_textarea.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/render/box_textarea.c b/render/box_textarea.c index d34c4c4a4..3c312a85f 100644 --- a/render/box_textarea.c +++ b/render/box_textarea.c @@ -241,7 +241,7 @@ bool box_textarea_create_textarea(html_content *html, return false; /* Get the textarea's initial content */ - err = dom_node_get_text_content(node, &dom_text); + err = dom_html_text_area_element_get_value(textarea, &dom_text); if (err != DOM_NO_ERR) return false; From 533cfa27dadb05c30f641d274bde91c7d5f3b457 Mon Sep 17 00:00:00 2001 From: Daniel Silverstone Date: Sat, 4 Jan 2014 16:30:09 +0000 Subject: [PATCH 015/773] Ensure textual input boxes re-update the DOM with new values --- render/box_textarea.c | 4 +++- render/form.c | 37 +++++++++++++++++++++++++++++++++++++ render/form.h | 3 +++ 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/render/box_textarea.c b/render/box_textarea.c index 3c312a85f..099dcc8e0 100644 --- a/render/box_textarea.c +++ b/render/box_textarea.c @@ -206,7 +206,9 @@ static void box_textarea_callback(void *data, struct textarea_msg *msg) break; case TEXTAREA_MSG_TEXT_MODIFIED: - /* TODO */ + form_gadget_update_value(d->html, gadget, + strndup(msg->data.modified.text, + msg->data.modified.len)); break; } } diff --git a/render/form.c b/render/form.c index ebe9b6f28..254d2cffb 100644 --- a/render/form.c +++ b/render/form.c @@ -1539,3 +1539,40 @@ void form_submit(nsurl *page_url, struct browser_window *target, fetch_multipart_data_destroy(success); free(data); } + +void form_gadget_update_value(struct html_content *html, + struct form_control *control, char *value) +{ + switch (control->type) { + case GADGET_HIDDEN: + case GADGET_TEXTBOX: + case GADGET_TEXTAREA: + case GADGET_PASSWORD: + case GADGET_FILE: + if (control->value != NULL) { + free(control->value); + } + control->value = value; + if (control->node != NULL) { + dom_exception err; + dom_string *str; + err = dom_string_create((uint8_t *)value, + strlen(value), &str); + if (err == DOM_NO_ERR) { + if (control->type == GADGET_TEXTAREA) + err = dom_html_text_area_element_set_value( + (dom_html_text_area_element *)(control->node), + str); + else + err = dom_html_input_element_set_value( + (dom_html_input_element *)(control->node), + str); + dom_string_unref(str); + } + } + break; + default: + /* Do nothing */ + break; + } +} diff --git a/render/form.h b/render/form.h index 9088ca293..c03ea8e99 100644 --- a/render/form.h +++ b/render/form.h @@ -183,4 +183,7 @@ void form_submit(nsurl *page_url, struct browser_window *target, struct form *form, struct form_control *submit_button); void form_radio_set(struct html_content *html, struct form_control *radio); +void form_gadget_update_value(struct html_content *html, + struct form_control *control, char *value); + #endif From a5bb596eb3444a314cc32ff3062889d814df951d Mon Sep 17 00:00:00 2001 From: Daniel Silverstone Date: Sat, 4 Jan 2014 16:30:52 +0000 Subject: [PATCH 016/773] Ensure that file inputs update the dom node and annotate with the unencoded filename --- render/html.c | 55 ++++++++++++++++++++++++++++++++++++++++++--- utils/corestrings.c | 4 +++- utils/corestrings.h | 1 + 3 files changed, 56 insertions(+), 4 deletions(-) diff --git a/render/html.c b/render/html.c index 1e7350cf1..49bb019dd 100644 --- a/render/html.c +++ b/render/html.c @@ -1685,6 +1685,47 @@ html_scroll_at_point(struct content *c, int x, int y, int scrx, int scry) return false; } +/** Helper for file gadgets to store their filename unencoded on the + * dom node associated with the gadget. + * + * \todo Get rid of this crap eventually + */ +static void html__dom_user_data_handler(dom_node_operation operation, + dom_string *key, void *_data, struct dom_node *src, + struct dom_node *dst) +{ + char *oldfile; + char *data = (char *)_data; + + if (!dom_string_isequal(corestring_dom___ns_key_libcss_node_data, + key) || data == NULL) { + return; + } + + switch (operation) { + case DOM_NODE_CLONED: + if (dom_node_set_user_data(dst, + corestring_dom___ns_key_file_name_node_data, + strdup(data), html__dom_user_data_handler, + &oldfile) == DOM_NO_ERR) { + if (oldfile != NULL) + free(oldfile); + } + break; + + case DOM_NODE_RENAMED: + case DOM_NODE_IMPORTED: + case DOM_NODE_ADOPTED: + break; + + case DOM_NODE_DELETED: + free(data); + break; + default: + LOG(("User data operation not handled.")); + assert(0); + } +} /** * Drop a file onto a content at a particular point, or determine if a file @@ -1752,7 +1793,7 @@ static bool html_drop_file_at_point(struct content *c, int x, int y, char *file) if (file_box) { /* File dropped on file input */ utf8_convert_ret ret; - char *utf8_fn; + char *utf8_fn, *oldfile = NULL; ret = utf8_from_local_encoding(file, 0, &utf8_fn); @@ -1765,8 +1806,16 @@ static bool html_drop_file_at_point(struct content *c, int x, int y, char *file) } /* Found: update form input */ - free(file_box->gadget->value); - file_box->gadget->value = utf8_fn; + form_gadget_update_value(html, file_box->gadget, utf8_fn); + + /* corestring_dom___ns_key_file_name_node_data */ + if (dom_node_set_user_data((dom_node *)file_box->gadget->node, + corestring_dom___ns_key_file_name_node_data, + strdup(file), html__dom_user_data_handler, + &oldfile) == DOM_NO_ERR) { + if (oldfile != NULL) + free(oldfile); + } /* Redraw box. */ html__redraw_a_box(html, file_box); diff --git a/utils/corestrings.c b/utils/corestrings.c index efdd0e07f..8623d127b 100644 --- a/utils/corestrings.c +++ b/utils/corestrings.c @@ -233,7 +233,7 @@ dom_string *corestring_dom_vspace; dom_string *corestring_dom_waiting; dom_string *corestring_dom_width; dom_string *corestring_dom___ns_key_libcss_node_data; - +dom_string *corestring_dom___ns_key_file_name_node_data; /* * Free the core strings @@ -464,6 +464,7 @@ void corestrings_fini(void) CSS_DOM_STRING_UNREF(waiting); CSS_DOM_STRING_UNREF(width); CSS_DOM_STRING_UNREF(__ns_key_libcss_node_data); + CSS_DOM_STRING_UNREF(__ns_key_file_name_node_data); #undef CSS_DOM_STRING_UNREF } @@ -725,6 +726,7 @@ nserror corestrings_init(void) CSS_DOM_STRING_INTERN(waiting); CSS_DOM_STRING_INTERN(width); CSS_DOM_STRING_INTERN(__ns_key_libcss_node_data); + CSS_DOM_STRING_INTERN(__ns_key_file_name_node_data); #undef CSS_DOM_STRING_INTERN exc = dom_string_create_interned((const uint8_t *) "text/javascript", diff --git a/utils/corestrings.h b/utils/corestrings.h index c50cc3113..a8c345946 100644 --- a/utils/corestrings.h +++ b/utils/corestrings.h @@ -239,6 +239,7 @@ extern struct dom_string *corestring_dom_vspace; extern struct dom_string *corestring_dom_waiting; extern struct dom_string *corestring_dom_width; extern struct dom_string *corestring_dom___ns_key_libcss_node_data; +extern struct dom_string *corestring_dom___ns_key_file_name_node_data; #endif From 0516e4c069db9e0edf601a5f17e702237e3cb9d5 Mon Sep 17 00:00:00 2001 From: Daniel Silverstone Date: Sat, 4 Jan 2014 16:33:30 +0000 Subject: [PATCH 017/773] Reflect toggling of 'selected' in the DOM --- render/html_interaction.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/render/html_interaction.c b/render/html_interaction.c index 6f4d9bd51..f18daebd4 100644 --- a/render/html_interaction.c +++ b/render/html_interaction.c @@ -617,6 +617,9 @@ void html_mouse_action(struct content *c, struct browser_window *bw, status = messages_get("FormCheckbox"); if (mouse & BROWSER_MOUSE_CLICK_1) { gadget->selected = !gadget->selected; + dom_html_input_element_set_checked( + (dom_html_input_element *)(gadget->node), + gadget->selected); html__redraw_a_box(html, gadget_box); } break; From 9b8988dd23e2adc14b8f5ee7a3e47bbe4982dc73 Mon Sep 17 00:00:00 2001 From: Daniel Silverstone Date: Sat, 4 Jan 2014 17:06:10 +0000 Subject: [PATCH 018/773] Reflect changes to select boxes into the DOM --- render/box_construct.c | 2 +- render/form.c | 10 +++++++++- render/form.h | 3 ++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/render/box_construct.c b/render/box_construct.c index b259e6a1f..4d9796932 100644 --- a/render/box_construct.c +++ b/render/box_construct.c @@ -2853,7 +2853,7 @@ bool box_select_add_option(struct form_control *control, dom_node *n) if (text_nowrap == NULL) goto no_memory; - if (form_add_option(control, value, text_nowrap, selected) == false) + if (form_add_option(control, value, text_nowrap, selected, n) == false) goto no_memory; free(text); diff --git a/render/form.c b/render/form.c index 254d2cffb..aa6661cfa 100644 --- a/render/form.c +++ b/render/form.c @@ -278,10 +278,11 @@ void form_free_control(struct form_control *control) * \param value value of option, used directly (not copied) * \param text text for option, used directly (not copied) * \param selected this option is selected + * \param node the DOM node this option is associated with * \return true on success, false on memory exhaustion */ bool form_add_option(struct form_control *control, char *value, char *text, - bool selected) + bool selected, void *node) { struct form_option *option; @@ -312,6 +313,8 @@ bool form_add_option(struct form_control *control, char *value, char *text, control->data.select.num_items++; + option->node = node; + return true; } @@ -1140,12 +1143,15 @@ static void form__select_process_selection(html_content *html, if (control->data.select.multiple) { if (o->selected) { o->selected = false; + dom_html_option_element_set_selected(o->node, false); control->data.select.num_selected--; } else { o->selected = true; + dom_html_option_element_set_selected(o->node, true); control->data.select.num_selected++; } } else { + dom_html_option_element_set_selected(o->node, true); o->selected = true; } } @@ -1434,11 +1440,13 @@ void form_radio_set(html_content *html, if (control->selected) { control->selected = false; + dom_html_input_element_set_checked(control->node, false); html__redraw_a_box(html, control->box); } } radio->selected = true; + dom_html_input_element_set_checked(radio->node, true); html__redraw_a_box(html, radio->box); } diff --git a/render/form.h b/render/form.h index c03ea8e99..b538c3b33 100644 --- a/render/form.h +++ b/render/form.h @@ -126,6 +126,7 @@ struct form_control { /** Option in a select. */ struct form_option { + void *node; /**< Corresponding DOM node */ bool selected; bool initial_selected; char *value; @@ -154,7 +155,7 @@ struct form_control *form_new_control(void *node, form_control_type type); void form_add_control(struct form *form, struct form_control *control); void form_free_control(struct form_control *control); bool form_add_option(struct form_control *control, char *value, char *text, - bool selected); + bool selected, void *node); bool form_successful_controls(struct form *form, struct form_control *submit_button, struct fetch_multipart_data **successful_controls); From a1725caf865bef1e5d26fbba21836116ad117dbb Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Sat, 4 Jan 2014 18:06:34 +0000 Subject: [PATCH 019/773] fix mngectony makefiles --- monkey/Makefile.target | 2 +- riscos/Makefile.target | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/monkey/Makefile.target b/monkey/Makefile.target index 6bea07d46..52407542d 100644 --- a/monkey/Makefile.target +++ b/monkey/Makefile.target @@ -47,7 +47,7 @@ MONKEYCFLAGS := -std=c99 -Dmonkey -Dnsmonkey \ $(shell $(PKG_CONFIG) --cflags openssl) \ $(shell xml2-config --cflags) -MONKEYLDFLAGS := -lm +MONKEYLDFLAGS := -lm $(shell $(PKG_CONFIG) --cflags --libs glib-2.0) CFLAGS += $(MONKEYCFLAGS) diff --git a/riscos/Makefile.target b/riscos/Makefile.target index 05e66c829..2f5bbb150 100644 --- a/riscos/Makefile.target +++ b/riscos/Makefile.target @@ -45,6 +45,7 @@ RESOURCES = $(TPD_RISCOS) split-messages CFLAGS += $(WARNFLAGS) -Driscos -std=c99 -D_BSD_SOURCE -D_POSIX_C_SOURCE \ -mpoke-function-name -fno-strict-aliasing +CFLAGS += -I$(GCCSDK_INSTALL_ENV)/include ifeq ($(HOST),riscos) CFLAGS += -I -mthrowback endif From 748b13c8bad9f7c900284396286b6f60e053f683 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Revol?= Date: Mon, 30 Dec 2013 15:32:50 +0100 Subject: [PATCH 020/773] beos: Fix permission on temp directories creation TODO: use filename_initialize() instead when it's fixed. --- beos/gui.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/beos/gui.cpp b/beos/gui.cpp index 04a52bbd7..537c3a5a2 100644 --- a/beos/gui.cpp +++ b/beos/gui.cpp @@ -620,7 +620,7 @@ void gui_init(int argc, char** argv) check_homedir(); // make sure the cache dir exists - create_directory(TEMP_FILENAME_PREFIX, 0600); + create_directory(TEMP_FILENAME_PREFIX, 0700); //nsbeos_completion_init(); From d69997c8a323bb593f642830b28ed0c4d7de476c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Revol?= Date: Mon, 30 Dec 2013 15:40:12 +0100 Subject: [PATCH 021/773] beos: Add missing call to lwc_string_unref() --- beos/gui.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/beos/gui.cpp b/beos/gui.cpp index 537c3a5a2..131173c64 100644 --- a/beos/gui.cpp +++ b/beos/gui.cpp @@ -918,10 +918,11 @@ void nsbeos_gui_view_source(struct hlcache_handle *content) return; } lwc_string *mime = content_get_mime_type(content); - const char *mime_string = lwc_string_data(mime); - if (mime) + if (mime) { file.WriteAttr("BEOS:TYPE", B_MIME_STRING_TYPE, 0LL, - mime_string, lwc_string_length(mime) + 1); + lwc_string_data(mime), lwc_string_length(mime) + 1); + lwc_string_unref(mime); + } } From 6f4e293311faa6bf485d40eb15f684b6559241a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Revol?= Date: Mon, 30 Dec 2013 16:18:53 +0100 Subject: [PATCH 022/773] beos: Load Messages files for current language For now we just check for LC_MESSAGES in the environment, which should even work in BeOS. Someday we should probably use Haiku's BLocale API instead. --- beos/gui.cpp | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/beos/gui.cpp b/beos/gui.cpp index 131173c64..7c8418215 100644 --- a/beos/gui.cpp +++ b/beos/gui.cpp @@ -512,6 +512,20 @@ static bool nslog_stream_configure(FILE *fptr) return true; } +static BPath get_messages_path() +{ + BPath p("/boot/apps/netsurf/res"); + // TODO: use Haiku's BLocale stuff + BString lang(getenv("LC_MESSAGES")); + lang.Truncate(2); + BDirectory d(p.Path()); + if (!d.Contains(lang.String(), B_DIRECTORY_NODE)) + lang = "en"; + p.Append(lang.String()); + p.Append("Messages"); + return p; +} + /** Normal entry point from OS */ int main(int argc, char** argv) { @@ -527,8 +541,6 @@ int main(int argc, char** argv) new NSBrowserApplication; } - const char* messages = "/boot/apps/netsurf/res/en/Messages"; - /* initialise logging. Not fatal if it fails but not much we * can do about it either. */ @@ -543,7 +555,8 @@ int main(int argc, char** argv) nsoption_commandline(&argc, argv, NULL); /* common initialisation */ - ret = netsurf_init(messages); + BPath messages = get_messages_path(); + ret = netsurf_init(messages.Path()); if (ret != NSERROR_OK) { die("NetSurf failed to initialise"); } @@ -567,8 +580,6 @@ int gui_init_replicant(int argc, char** argv) options.Append("x-vnd.NetSurf"); } - const char* messages = "/boot/apps/netsurf/res/en/Messages"; - /* initialise logging. Not fatal if it fails but not much we * can do about it either. */ @@ -585,7 +596,8 @@ int gui_init_replicant(int argc, char** argv) nsoption_commandline(&argc, argv, NULL); /* common initialisation */ - ret = netsurf_init(messages); + BPath messages = get_messages_path(); + ret = netsurf_init(messages.Path()); if (ret != NSERROR_OK) { // FIXME: must not die when in replicant! die("NetSurf failed to initialise"); From f3455a755662794d6aebaf642d00eb35398ac3f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Revol?= Date: Tue, 31 Dec 2013 13:40:51 +0100 Subject: [PATCH 023/773] beos: Remove unused Tracker button bitmaps We never used them, and we now have better looking HVIF ones anyway. --- beos/res.h | 12 ---- beos/res.rdef | 196 -------------------------------------------------- 2 files changed, 208 deletions(-) diff --git a/beos/res.h b/beos/res.h index 4e6497815..278ffb545 100644 --- a/beos/res.h +++ b/beos/res.h @@ -16,15 +16,3 @@ * along with this program. If not, see . */ -enum { - R_ResizeHandle = 1000, - R_ResBackNavActive = 1042, - R_ResBackNavInactive = 1043, - R_ResForwNavActive = 1044, - R_ResForwNavInactive = 1045, - R_ResUpNavActive = 1046, - R_ResUpNavInactive = 1047, - R_ResBackNavActiveSel = 1048, - R_ResForwNavActiveSel = 1049, - R_ResUpNavActiveSel = 1050 -}; diff --git a/beos/res.rdef b/beos/res.rdef index 862d6d0f1..1cf31f287 100644 --- a/beos/res.rdef +++ b/beos/res.rdef @@ -106,202 +106,6 @@ resource(1, "BEOS:FILE_TYPES") message { "types" = "application/x-vnd.Be.URL.https" }; -resource(R_ResizeHandle) archive(, 0x00000000) BBitmap { - "_frame" = rect { 0.0, 0.0, 13.0, 13.0 }, - "_cspace" = 4, - "_bmflags" = 1, - "_rowbytes" = 16, - "_data" = array { - $"1B1B1B1B1B1B1B1B1B1B1B1B133F3F3F1B1B1B1B1B1B1B1B1B1B1B1B133F3F3F" - $"1B1B1B1B1B1B1B1B1B1B1B1B133F3F3F1B1B1B1B1B1B1B1B1B0C1B1B133F3F3F" - $"1B1B1B1B1B1B1B1B1B1B3F1B133F3F3F1B1B1B1B1B1B1B1B1B1B1B1B133F3F3F" - $"1B1B1B1B1B1B0C1B1B0D1B1B133F3F3F1B1B1B1B1B1B1B3F1B1B3F1B133F3F3F" - $"1B1B1B1B1B1B1B1B1B1B1B1B133F3F3F1B1B1B0C1B1B0D1B1B0C1B1B133F3F3F" - $"1B1B1B1B3F1B1B3F1B1B3F1B133F3F3F1B1B1B1B1B1B1B1B1B1B1B1B133F3F3F" - $"131313131313131313131313133F3F3F3F3F3F3F3F3F3F3F3F3F3F3F3F3F3F3F" - } -}; - -resource(R_ResBackNavActive) archive(, 0x00000000) BBitmap { - "_frame" = rect { 0.0, 0.0, 18.0, 16.0 }, - "_cspace" = 4, - "_bmflags" = 1, - "_rowbytes" = 20, - "_data" = array { - $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF3FFFFFFFFFFFFFFF3B3B18FFFF" - $"FFFFFFFFFFFFFF3FFFFFFFFFFFFF3B353B1418FFFFFFFFFFFFFFFF3FFFFFFFFF" - $"FF3B35353B1418FFFFFFFFFFFFFFFF3FFFFFFFFF3B3435353B3B3B3B3B3B3B3B" - $"18FFFF3FFFFFFF3B34343535363637373737373B1418FF3FFFFF3B3434343535" - $"363637373737373B1418FF3FFF3B343434353536363637373737373B1418FF3F" - $"FF183B3535353536363637373737373B1418FF3FFFFF183B3536363636373737" - $"3737373B1418FF3FFFFFFF183B3636373B3B3B3B3B3B3B3B1418FF3FFFFFFFFF" - $"183B37373B141414141414141418FF3FFFFFFFFFFF183B373B14181818181818" - $"18FFFF3FFFFFFFFFFFFF183B3B1418FFFFFFFFFFFFFFFF3FFFFFFFFFFFFFFF18" - $"141418FFFFFFFFFFFFFFFF3FFFFFFFFFFFFFFFFF1818FFFFFFFFFFFFFFFFFF3F" - $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF3F" - } -}; - -resource(R_ResBackNavInactive) archive(, 0x00000000) BBitmap { - "_frame" = rect { 0.0, 0.0, 18.0, 16.0 }, - "_cspace" = 4, - "_bmflags" = 1, - "_rowbytes" = 20, - "_data" = array { - $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF3FFFFFFFFFFFFFFF0000FFFFFF" - $"FFFFFFFFFFFFFF3FFFFFFFFFFFFF001800FFFFFFFFFFFFFFFFFFFF3FFFFFFFFF" - $"FF00181800FFFFFFFFFFFFFFFFFFFF3FFFFFFFFF001C18180000000000000000" - $"FFFFFF3FFFFFFF001C1C18181515111111111100FFFFFF3FFFFF001C1C1C1818" - $"1515111111111100FFFFFF3FFF001C1C1C1818151515111111111100FFFFFF3F" - $"FFFF0018181818151515111111111100FFFFFF3FFFFFFF001815151515111111" - $"11111100FFFFFF3FFFFFFFFF001515110000000000000000FFFFFF3FFFFFFFFF" - $"FF00111100FFFFFFFFFFFFFFFFFFFF3FFFFFFFFFFFFF001100FFFFFFFFFFFFFF" - $"FFFFFF3FFFFFFFFFFFFFFF0000FFFFFFFFFFFFFFFFFFFF3FFFFFFFFFFFFFFFFF" - $"FFFFFFFFFFFFFFFFFFFFFF3FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF3F" - $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF3F" - } -}; - -resource(R_ResForwNavActive) archive(, 0x00000000) BBitmap { - "_frame" = rect { 0.0, 0.0, 18.0, 16.0 }, - "_cspace" = 4, - "_bmflags" = 1, - "_rowbytes" = 20, - "_data" = array { - $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF3FFFFFFFFFFFFFFFFF3B3B18FF" - $"FFFFFFFFFFFFFF3FFFFFFFFFFFFFFFFF3B353B18FFFFFFFFFFFFFF3FFFFFFFFF" - $"FFFFFFFF3B35363B18FFFFFFFFFFFF3FFF3B3B3B3B3B3B3B3B3536363B18FFFF" - $"FFFFFF3FFF3B34343434353535363636373B18FFFFFFFF3FFF3B343434353535" - $"3536363637373B18FFFFFF3FFF3B343435353535363636373737373B18FFFF3F" - $"FF3B3535353535363636373737373B141418FF3FFF3B35353536363636373737" - $"373B141418FFFF3FFF3B3B3B3B3B3B3B3B3737373B141418FFFFFF3FFF181414" - $"141414143B37373B141418FFFFFFFF3FFFFF1818181818183B373B141418FFFF" - $"FFFFFF3FFFFFFFFFFFFFFFFF3B3B141418FFFFFFFFFFFF3FFFFFFFFFFFFFFFFF" - $"18141418FFFFFFFFFFFFFF3FFFFFFFFFFFFFFFFFFF1818FFFFFFFFFFFFFFFF3F" - $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF3F" - } -}; - -resource(R_ResForwNavInactive) archive(, 0x00000000) BBitmap { - "_frame" = rect { 0.0, 0.0, 18.0, 16.0 }, - "_cspace" = 4, - "_bmflags" = 1, - "_rowbytes" = 20, - "_data" = array { - $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF3FFFFFFFFFFFFFFFFF0000FFFF" - $"FFFFFFFFFFFFFF3FFFFFFFFFFFFFFFFF001800FFFFFFFFFFFFFFFF3FFFFFFFFF" - $"FFFFFFFF00181500FFFFFFFFFFFFFF3FFF000000000000000018151500FFFFFF" - $"FFFFFF3FFF001C1C1C1C1818181515151100FFFFFFFFFF3FFF001C1C1C181818" - $"18151515111100FFFFFFFF3FFF001C1C181818181515151111111100FFFFFF3F" - $"FF0018181818181515151111111100FFFFFFFF3FFF0018181815151515111111" - $"1100FFFFFFFFFF3FFF000000000000000011111100FFFFFFFFFFFF3FFFFFFFFF" - $"FFFFFFFF00111100FFFFFFFFFFFFFF3FFFFFFFFFFFFFFFFF001100FFFFFFFFFF" - $"FFFFFF3FFFFFFFFFFFFFFFFF0000FFFFFFFFFFFFFFFFFF3FFFFFFFFFFFFFFFFF" - $"FFFFFFFFFFFFFFFFFFFFFF3FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF3F" - $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF3F" - } -}; - -resource(R_ResUpNavActive) archive(, 0x00000000) BBitmap { - "_frame" = rect { 0.0, 0.0, 17.0, 16.0 }, - "_cspace" = 4, - "_bmflags" = 1, - "_rowbytes" = 20, - "_data" = array { - $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF3F3FFFFFFFFFFFFFFFFF00FFFFFF" - $"FFFFFFFFFFFF3F3FFFFFFFFFFFFFFF00E50018FFFFFFFFFFFFFF3F3FFFFFFFFF" - $"FFFF00E5BDBD0018FFFFFFFFFFFF3F3FFFFFFFFFFF00E5BDBDBDBD0018FFFFFF" - $"FFFF3F3FFFFFFFFF00E5BDBDBDBDBDBD0018FFFFFFFF3F3FFFFFFF00E5BDBDBD" - $"BDBDBDBDBD0018FFFFFF3F3FFFFF00E5E5E5BDBDBDBDBD9898980018FFFF3F3F" - $"FF00000000E5BDBDBDBDBD980000000018FF3F3FFFFF141400E5BDBDBDBDBD98" - $"00141418FFFF3F3FFFFFFF1800E5BDBDBDBDBD98001418FFFFFF3F3FFFFFFFFF" - $"00E5BDBDBDBDBD98001418FFFFFF3F3FFFFFFFFF00E5989898989898001418FF" - $"FFFF3F3FFFFFFFFF0000000000000000001418FFFFFF3F3FFFFFFFFF18141414" - $"141414141418FFFFFFFF3F3FFFFFFFFFFF181818181818181818FFFFFFFF3F3F" - $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF3F3F" - } -}; - -resource(R_ResUpNavInactive) archive(, 0x00000000) BBitmap { - "_frame" = rect { 0.0, 0.0, 17.0, 16.0 }, - "_cspace" = 4, - "_bmflags" = 1, - "_rowbytes" = 20, - "_data" = array { - $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF3F3FFFFFFFFFFFFFFFFF00FFFFFF" - $"FFFFFFFFFFFF3F3FFFFFFFFFFFFFFF001C00FFFFFFFFFFFFFFFF3F3FFFFFFFFF" - $"FFFF001C171700FFFFFFFFFFFFFF3F3FFFFFFFFFFF001C1717171700FFFFFFFF" - $"FFFF3F3FFFFFFFFF001C17171717171700FFFFFFFFFF3F3FFFFFFF001C171717" - $"171717171700FFFFFFFF3F3FFFFF001C1C1C171717171712121200FFFFFF3F3F" - $"FF000000001C17171717171200000000FFFF3F3FFFFFFFFF001C171717171712" - $"00FFFFFFFFFF3F3FFFFFFFFF001C17171717171200FFFFFFFFFF3F3FFFFFFFFF" - $"001C17171717171200FFFFFFFFFF3F3FFFFFFFFF001C12121212121200FFFFFF" - $"FFFF3F3FFFFFFFFF000000000000000000FFFFFFFFFF3F3FFFFFFFFFFFFFFFFF" - $"FFFFFFFFFFFFFFFFFFFF3F3FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF3F3F" - $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF3F3F" - } -}; - -resource(R_ResBackNavActiveSel) archive(, 0x00000000) BBitmap { - "_frame" = rect { 0.0, 0.0, 18.0, 16.0 }, - "_cspace" = 4, - "_bmflags" = 1, - "_rowbytes" = 20, - "_data" = array { - $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF3FFFFFFFFFFFFFFF3B3BFFFFFF" - $"FFFFFFFFFFFFFF3FFFFFFFFFFFFF3B353BFFFFFFFFFFFFFFFFFFFF3FFFFFFFFF" - $"FF3B35353BFFFFFFFFFFFFFFFFFFFF3FFFFFFFFF3B3435353B3B3B3B3B3B3B3B" - $"FFFFFF3FFFFFFF3B34343535363637373737373BFFFFFF3FFFFF3B3434343535" - $"363637373737373BFFFFFF3FFF3B343434353536363637373737373BFFFFFF3F" - $"FFFF3B3535353536363637373737373BFFFFFF3FFFFFFF3B3536363636373737" - $"3737373BFFFFFF3FFFFFFFFF3B3636373B3B3B3B3B3B3B3BFFFFFF3FFFFFFFFF" - $"FF3B37373BFFFFFFFFFFFFFFFFFFFF3FFFFFFFFFFFFF3B373BFFFFFFFFFFFFFF" - $"FFFFFF3FFFFFFFFFFFFFFF3B3BFFFFFFFFFFFFFFFFFFFF3FFFFFFFFFFFFFFFFF" - $"FFFFFFFFFFFFFFFFFFFFFF3FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF3F" - $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF3F" - } -}; - -resource(R_ResForwNavActiveSel) archive(, 0x00000000) BBitmap { - "_frame" = rect { 0.0, 0.0, 18.0, 16.0 }, - "_cspace" = 4, - "_bmflags" = 1, - "_rowbytes" = 20, - "_data" = array { - $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF3FFFFFFFFFFFFFFFFF3B3BFFFF" - $"FFFFFFFFFFFFFF3FFFFFFFFFFFFFFFFF3B353BFFFFFFFFFFFFFFFF3FFFFFFFFF" - $"FFFFFFFF3B35363BFFFFFFFFFFFFFF3FFF3B3B3B3B3B3B3B3B3536363BFFFFFF" - $"FFFFFF3FFF3B34343434353535363636373BFFFFFFFFFF3FFF3B343434353535" - $"3536363637373BFFFFFFFF3FFF3B343435353535363636373737373BFFFFFF3F" - $"FF3B3535353535363636373737373BFFFFFFFF3FFF3B35353536363636373737" - $"373BFFFFFFFFFF3FFF3B3B3B3B3B3B3B3B3737373BFFFFFFFFFFFF3FFFFFFFFF" - $"FFFFFFFF3B37373BFFFFFFFFFFFFFF3FFFFFFFFFFFFFFFFF3B373BFFFFFFFFFF" - $"FFFFFF3FFFFFFFFFFFFFFFFF3B3BFFFFFFFFFFFFFFFFFF3FFFFFFFFFFFFFFFFF" - $"FFFFFFFFFFFFFFFFFFFFFF3FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF3F" - $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF3F" - } -}; - -resource(R_ResUpNavActiveSel) archive(, 0x00000000) BBitmap { - "_frame" = rect { 0.0, 0.0, 17.0, 16.0 }, - "_cspace" = 4, - "_bmflags" = 1, - "_rowbytes" = 20, - "_data" = array { - $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF3F3FFFFFFFFFFFFFFFFF00FFFFFF" - $"FFFFFFFFFFFF3F3FFFFFFFFFFFFFFF00E500FFFFFFFFFFFFFFFF3F3FFFFFFFFF" - $"FFFF00E5BDBD00FFFFFFFFFFFFFF3F3FFFFFFFFFFF00E5BDBDBDBD00FFFFFFFF" - $"FFFF3F3FFFFFFFFF00E5BDBDBDBDBDBD00FFFFFFFFFF3F3FFFFFFF00E5BDBDBD" - $"BDBDBDBDBD00FFFFFFFF3F3FFFFF00E5E5E5BDBDBDBDBD98989800FFFFFF3F3F" - $"FF00000000E5BDBDBDBDBD9800000000FFFF3F3FFFFFFFFF00E5BDBDBDBDBD98" - $"00FFFFFFFFFF3F3FFFFFFFFF00E5BDBDBDBDBD9800FFFFFFFFFF3F3FFFFFFFFF" - $"00E5BDBDBDBDBD9800FFFFFFFFFF3F3FFFFFFFFF00E598989898989800FFFFFF" - $"FFFF3F3FFFFFFFFF000000000000000000FFFFFFFFFF3F3FFFFFFFFFFFFFFFFF" - $"FFFFFFFFFFFFFFFFFFFF3F3FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF3F3F" - $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF3F3F" - } -}; - resource(101, "BEOS:ICON") #'VICN' array { $"6E6369660A02010203AE259A400198BFFA65AE20E548AF9547F2037F30A0FFFF" $"00E8F1FDFFF131A0FFFB02000602B83B85BC57333C5733B83B8549EAE1481199" From 053897d07db6b5824864adeefee382d3199d328f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Revol?= Date: Tue, 31 Dec 2013 14:01:20 +0100 Subject: [PATCH 024/773] beos: Move some resources around Move app signature and supported filetypes before icons for more visibility. --- beos/res.rdef | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/beos/res.rdef b/beos/res.rdef index 1cf31f287..efa2991f0 100644 --- a/beos/res.rdef +++ b/beos/res.rdef @@ -37,6 +37,21 @@ resource(502, "welcome.html") #'data' import "res/en/welcome.html,faf"; resource(1, "BEOS:APP_FLAGS") (#'APPF') $"01000000"; +resource(1, "BEOS:APP_SIG") (#'MIMS') "application/x-vnd.NetSurf"; + +resource(1, "BEOS:FILE_TYPES") message { + "types" = "text/html", + "types" = "image/gif", + "types" = "image/jpeg", + "types" = "application/x-vnd.Be-bookmark", + "types" = "text", + "types" = "application/x-vnd.Be-doc_bookmark", + "types" = "application/x-vnd.Be.URL.file", + "types" = "application/x-vnd.Be.URL.ftp", + "types" = "application/x-vnd.Be.URL.http", + "types" = "application/x-vnd.Be.URL.https" +}; + resource(101, "BEOS:L:STD_ICON") #'ICON' array { $"FFFFFFFFFFFFFFFFFFFFFF0E0A00D600D6000AAF0EFFFFFFFFFFFFFFFFFFFFFF" $"FFFFFFFFFFFFFFFF0E0A000001DED5D5D5DE020000090EFFFFFFFFFFFFFFFFFF" @@ -91,21 +106,6 @@ resource(101, "BEOS:M:STD_ICON") #'MICN' array { $"FFFFFFFF0E0B000500000A0EFFFFFFFF" }; -resource(1, "BEOS:APP_SIG") (#'MIMS') "application/x-vnd.NetSurf"; - -resource(1, "BEOS:FILE_TYPES") message { - "types" = "text/html", - "types" = "image/gif", - "types" = "image/jpeg", - "types" = "application/x-vnd.Be-bookmark", - "types" = "text", - "types" = "application/x-vnd.Be-doc_bookmark", - "types" = "application/x-vnd.Be.URL.file", - "types" = "application/x-vnd.Be.URL.ftp", - "types" = "application/x-vnd.Be.URL.http", - "types" = "application/x-vnd.Be.URL.https" -}; - resource(101, "BEOS:ICON") #'VICN' array { $"6E6369660A02010203AE259A400198BFFA65AE20E548AF9547F2037F30A0FFFF" $"00E8F1FDFFF131A0FFFB02000602B83B85BC57333C5733B83B8549EAE1481199" From da504bbbb86b01fa6aad60ad7bf5d5925856b0ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Revol?= Date: Tue, 31 Dec 2013 14:09:54 +0100 Subject: [PATCH 025/773] beos: Add comments to resources definition file --- beos/res.rdef | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/beos/res.rdef b/beos/res.rdef index efa2991f0..daad9dee3 100644 --- a/beos/res.rdef +++ b/beos/res.rdef @@ -29,16 +29,18 @@ resource(406, "throbber6.png") #'data' import "res/throbber/throbber6.png"; resource(407, "throbber7.png") #'data' import "res/throbber/throbber7.png"; resource(408, "throbber8.png") #'data' import "res/throbber/throbber8.png"; -/* */ +/* files exported as resource:// via rsrc:// mapping */ resource(500, "credits.html") #'data' import "res/en/credits.html,faf"; resource(501, "licence.html") #'data' import "res/en/licence.html,faf"; resource(502, "welcome.html") #'data' import "res/en/welcome.html,faf"; - +/* application flags (multiple launch) */ resource(1, "BEOS:APP_FLAGS") (#'APPF') $"01000000"; +/* application MIME signature */ resource(1, "BEOS:APP_SIG") (#'MIMS') "application/x-vnd.NetSurf"; +/* list of supported MIME types */ resource(1, "BEOS:FILE_TYPES") message { "types" = "text/html", "types" = "image/gif", @@ -52,6 +54,7 @@ resource(1, "BEOS:FILE_TYPES") message { "types" = "application/x-vnd.Be.URL.https" }; +/* BeOS large (32x32) icon */ resource(101, "BEOS:L:STD_ICON") #'ICON' array { $"FFFFFFFFFFFFFFFFFFFFFF0E0A00D600D6000AAF0EFFFFFFFFFFFFFFFFFFFFFF" $"FFFFFFFFFFFFFFFF0E0A000001DED5D5D5DE020000090EFFFFFFFFFFFFFFFFFF" @@ -87,6 +90,7 @@ resource(101, "BEOS:L:STD_ICON") #'ICON' array { $"FFFFFFFFFFFFFFFFFFFFFFFF0E0B000A0A0A0D0EFFFFFFFFFFFFFFFFFFFFFFFF" }; +/* BeOS small (16x16) icon */ resource(101, "BEOS:M:STD_ICON") #'MICN' array { $"FFFFFFFF0E0900020205000DFFFFFFFF" $"FFFFFF09038E66666C6C93DD000EFFFF" @@ -106,6 +110,7 @@ resource(101, "BEOS:M:STD_ICON") #'MICN' array { $"FFFFFFFF0E0B000500000A0EFFFFFFFF" }; +/* Haiku vector icon */ resource(101, "BEOS:ICON") #'VICN' array { $"6E6369660A02010203AE259A400198BFFA65AE20E548AF9547F2037F30A0FFFF" $"00E8F1FDFFF131A0FFFB02000602B83B85BC57333C5733B83B8549EAE1481199" @@ -167,8 +172,10 @@ resource(101, "BEOS:ICON") #'VICN' array { $"00000000000040012FBD3E023BCFC400190117850004" }; +/* ZETA SVG icon descriptor */ resource(101, "BEOS:D:STD_ICON") (#'iICO') $"4944585A055300"; +/* ZETA SVG compressed icon */ resource(101, "BEOS:V:STD_ICON") #'zICO' array { $"7A10000078DAED57DD6EDB3618BDEF5310CA4D03C40C7F3E8A6466B7C002AC37" $"2C066CCD03B8B1EC6853A44052B3644FBFF351769C7601D68B41BB5814C03AA2" From 917f8ca804bbbacc631cce414608cb989866f6ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Revol?= Date: Tue, 31 Dec 2013 14:28:09 +0100 Subject: [PATCH 026/773] beos: Drop duplicate throbber PNG resources They are also added with another path by the makefile. --- beos/gui.cpp | 2 +- beos/res.rdef | 11 ----------- 2 files changed, 1 insertion(+), 12 deletions(-) diff --git a/beos/gui.cpp b/beos/gui.cpp index 7c8418215..4b60d7c36 100644 --- a/beos/gui.cpp +++ b/beos/gui.cpp @@ -643,7 +643,7 @@ void gui_init(int argc, char** argv) { #define STROF(n) #n #define FIND_THROB(n) filenames[(n)] = \ - "throbber" STROF(n) ".png"; + "throbber/throbber" STROF(n) ".png"; char *filenames[9]; FIND_THROB(0); FIND_THROB(1); diff --git a/beos/res.rdef b/beos/res.rdef index daad9dee3..97dc59dd7 100644 --- a/beos/res.rdef +++ b/beos/res.rdef @@ -18,17 +18,6 @@ #include "res.h" -/* throbber */ -resource(400, "throbber0.png") #'data' import "res/throbber/throbber0.png"; -resource(401, "throbber1.png") #'data' import "res/throbber/throbber1.png"; -resource(402, "throbber2.png") #'data' import "res/throbber/throbber2.png"; -resource(403, "throbber3.png") #'data' import "res/throbber/throbber3.png"; -resource(404, "throbber4.png") #'data' import "res/throbber/throbber4.png"; -resource(405, "throbber5.png") #'data' import "res/throbber/throbber5.png"; -resource(406, "throbber6.png") #'data' import "res/throbber/throbber6.png"; -resource(407, "throbber7.png") #'data' import "res/throbber/throbber7.png"; -resource(408, "throbber8.png") #'data' import "res/throbber/throbber8.png"; - /* files exported as resource:// via rsrc:// mapping */ resource(500, "credits.html") #'data' import "res/en/credits.html,faf"; resource(501, "licence.html") #'data' import "res/en/licence.html,faf"; From e1e1b5c45b0f0e443fb7d64db5d5056c92426822 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Revol?= Date: Tue, 31 Dec 2013 14:44:12 +0100 Subject: [PATCH 027/773] beos: Export icons/ resources with a lowercase i That's what GTK does, and it fixes the dirlist icons too. --- beos/Makefile.target | 2 +- beos/res/{Icons => icons} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename beos/res/{Icons => icons} (100%) diff --git a/beos/Makefile.target b/beos/Makefile.target index 81e2a951e..847850bb9 100644 --- a/beos/Makefile.target +++ b/beos/Makefile.target @@ -101,7 +101,7 @@ RDEP_BEOS := \ adblock.css beosdefault.css default.css internal.css quirks.css \ netsurf.png ca-bundle.txt RDEP_BEOS := $(addprefix beos/res/,$(RDEP_BEOS)) \ - $(wildcard beos/res/Icons/*.png) \ + $(wildcard beos/res/icons/*.png) \ $(wildcard beos/res/throbber/throbber*.png) diff --git a/beos/res/Icons b/beos/res/icons similarity index 100% rename from beos/res/Icons rename to beos/res/icons From 3c5317cf54aebe40e8aaa2a6e107579c33184449 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Revol?= Date: Tue, 31 Dec 2013 15:13:36 +0100 Subject: [PATCH 028/773] beos: Fix embedded files in resources - drop the remaining hardcoded files in rdef file - add favicon.png - remove en/ symlink - add real folders with symlinks for translated files like GTK Note the Messages files are also included although the current code is not able to load them from the resources. - add symlinks for html files to the en/ version (TODO: try to remap automatically) --- beos/Makefile.target | 6 ++++-- beos/res.rdef | 5 +---- beos/res/credits.html | 1 + beos/res/de/Messages | 1 + beos/res/de/welcome.html | 1 + beos/res/en | 1 - beos/res/en/Messages | 1 + beos/res/en/credits.html | 1 + beos/res/en/licence.html | 1 + beos/res/en/welcome.html | 1 + beos/res/favicon.png | 1 + beos/res/fr/Messages | 1 + beos/res/it/Messages | 1 + beos/res/it/credits.html | 1 + beos/res/it/licence.html | 1 + beos/res/it/welcome.html | 1 + beos/res/ja/welcome.html | 1 + beos/res/licence.html | 1 + beos/res/nl/Messages | 1 + beos/res/welcome.html | 1 + 20 files changed, 22 insertions(+), 7 deletions(-) create mode 120000 beos/res/credits.html create mode 120000 beos/res/de/Messages create mode 120000 beos/res/de/welcome.html delete mode 120000 beos/res/en create mode 120000 beos/res/en/Messages create mode 120000 beos/res/en/credits.html create mode 120000 beos/res/en/licence.html create mode 120000 beos/res/en/welcome.html create mode 120000 beos/res/favicon.png create mode 120000 beos/res/fr/Messages create mode 120000 beos/res/it/Messages create mode 120000 beos/res/it/credits.html create mode 120000 beos/res/it/licence.html create mode 120000 beos/res/it/welcome.html create mode 120000 beos/res/ja/welcome.html create mode 120000 beos/res/licence.html create mode 120000 beos/res/nl/Messages create mode 120000 beos/res/welcome.html diff --git a/beos/Makefile.target b/beos/Makefile.target index 847850bb9..ed7532dc2 100644 --- a/beos/Makefile.target +++ b/beos/Makefile.target @@ -99,9 +99,11 @@ RDEF_IMP_BEOS := $(addprefix $(OBJROOT)/,$(subst /,_,$(RDEF_IMP_BEOS))) RDEP_BEOS := \ adblock.css beosdefault.css default.css internal.css quirks.css \ - netsurf.png ca-bundle.txt + netsurf.png favicon.png ca-bundle.txt \ + credits.html licence.html welcome.html RDEP_BEOS := $(addprefix beos/res/,$(RDEP_BEOS)) \ - $(wildcard beos/res/icons/*.png) \ + $(wildcard beos/res/icons/*.png) \ + $(wildcard beos/res/??/*) \ $(wildcard beos/res/throbber/throbber*.png) diff --git a/beos/res.rdef b/beos/res.rdef index 97dc59dd7..07012356c 100644 --- a/beos/res.rdef +++ b/beos/res.rdef @@ -18,10 +18,7 @@ #include "res.h" -/* files exported as resource:// via rsrc:// mapping */ -resource(500, "credits.html") #'data' import "res/en/credits.html,faf"; -resource(501, "licence.html") #'data' import "res/en/licence.html,faf"; -resource(502, "welcome.html") #'data' import "res/en/welcome.html,faf"; +/* files exported as resource: via rsrc:// mapping are added by the makefile */ /* application flags (multiple launch) */ resource(1, "BEOS:APP_FLAGS") (#'APPF') $"01000000"; diff --git a/beos/res/credits.html b/beos/res/credits.html new file mode 120000 index 000000000..ca85d3d27 --- /dev/null +++ b/beos/res/credits.html @@ -0,0 +1 @@ +en/credits.html \ No newline at end of file diff --git a/beos/res/de/Messages b/beos/res/de/Messages new file mode 120000 index 000000000..2f1fc39c3 --- /dev/null +++ b/beos/res/de/Messages @@ -0,0 +1 @@ +../../../!NetSurf/Resources/de/Messages \ No newline at end of file diff --git a/beos/res/de/welcome.html b/beos/res/de/welcome.html new file mode 120000 index 000000000..b2ddfc796 --- /dev/null +++ b/beos/res/de/welcome.html @@ -0,0 +1 @@ +../../../!NetSurf/Resources/de/welcome.html,faf \ No newline at end of file diff --git a/beos/res/en b/beos/res/en deleted file mode 120000 index d1dfaa9d2..000000000 --- a/beos/res/en +++ /dev/null @@ -1 +0,0 @@ -../../!NetSurf/Resources/en \ No newline at end of file diff --git a/beos/res/en/Messages b/beos/res/en/Messages new file mode 120000 index 000000000..72c9eff90 --- /dev/null +++ b/beos/res/en/Messages @@ -0,0 +1 @@ +../../../!NetSurf/Resources/en/Messages \ No newline at end of file diff --git a/beos/res/en/credits.html b/beos/res/en/credits.html new file mode 120000 index 000000000..1ba17392b --- /dev/null +++ b/beos/res/en/credits.html @@ -0,0 +1 @@ +../../../!NetSurf/Resources/en/credits.html,faf \ No newline at end of file diff --git a/beos/res/en/licence.html b/beos/res/en/licence.html new file mode 120000 index 000000000..147dd6db2 --- /dev/null +++ b/beos/res/en/licence.html @@ -0,0 +1 @@ +../../../!NetSurf/Resources/en/licence.html,faf \ No newline at end of file diff --git a/beos/res/en/welcome.html b/beos/res/en/welcome.html new file mode 120000 index 000000000..28362130a --- /dev/null +++ b/beos/res/en/welcome.html @@ -0,0 +1 @@ +../../../!NetSurf/Resources/en/welcome.html,faf \ No newline at end of file diff --git a/beos/res/favicon.png b/beos/res/favicon.png new file mode 120000 index 000000000..d968c3827 --- /dev/null +++ b/beos/res/favicon.png @@ -0,0 +1 @@ +../../gtk/res/favicon.png \ No newline at end of file diff --git a/beos/res/fr/Messages b/beos/res/fr/Messages new file mode 120000 index 000000000..a42cf08f4 --- /dev/null +++ b/beos/res/fr/Messages @@ -0,0 +1 @@ +../../../!NetSurf/Resources/fr/Messages \ No newline at end of file diff --git a/beos/res/it/Messages b/beos/res/it/Messages new file mode 120000 index 000000000..d4c5c2956 --- /dev/null +++ b/beos/res/it/Messages @@ -0,0 +1 @@ +../../../!NetSurf/Resources/it/Messages \ No newline at end of file diff --git a/beos/res/it/credits.html b/beos/res/it/credits.html new file mode 120000 index 000000000..6e1e15ed5 --- /dev/null +++ b/beos/res/it/credits.html @@ -0,0 +1 @@ +../../../!NetSurf/Resources/it/credits.html,faf \ No newline at end of file diff --git a/beos/res/it/licence.html b/beos/res/it/licence.html new file mode 120000 index 000000000..3a7c056b6 --- /dev/null +++ b/beos/res/it/licence.html @@ -0,0 +1 @@ +../../../!NetSurf/Resources/it/licence.html,faf \ No newline at end of file diff --git a/beos/res/it/welcome.html b/beos/res/it/welcome.html new file mode 120000 index 000000000..dea1e839c --- /dev/null +++ b/beos/res/it/welcome.html @@ -0,0 +1 @@ +../../../!NetSurf/Resources/it/welcome.html,faf \ No newline at end of file diff --git a/beos/res/ja/welcome.html b/beos/res/ja/welcome.html new file mode 120000 index 000000000..827796f02 --- /dev/null +++ b/beos/res/ja/welcome.html @@ -0,0 +1 @@ +../../../!NetSurf/Resources/ja/welcome.html,faf \ No newline at end of file diff --git a/beos/res/licence.html b/beos/res/licence.html new file mode 120000 index 000000000..86f8c54bf --- /dev/null +++ b/beos/res/licence.html @@ -0,0 +1 @@ +en/licence.html \ No newline at end of file diff --git a/beos/res/nl/Messages b/beos/res/nl/Messages new file mode 120000 index 000000000..d484ebd29 --- /dev/null +++ b/beos/res/nl/Messages @@ -0,0 +1 @@ +../../../!NetSurf/Resources/nl/Messages \ No newline at end of file diff --git a/beos/res/welcome.html b/beos/res/welcome.html new file mode 120000 index 000000000..1abdc5e8a --- /dev/null +++ b/beos/res/welcome.html @@ -0,0 +1 @@ +en/welcome.html \ No newline at end of file From f8517f2e51ccd3852edfcc813e9fe5ac7f7a2319 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Revol?= Date: Tue, 31 Dec 2013 16:05:15 +0100 Subject: [PATCH 029/773] beos: remap resource:favicon.ico to favicon.png We don't use it yet though. --- beos/gui.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/beos/gui.cpp b/beos/gui.cpp index 4b60d7c36..204c11caf 100644 --- a/beos/gui.cpp +++ b/beos/gui.cpp @@ -352,10 +352,16 @@ nsurl *gui_get_resource_url(const char *path) { nsurl *url = NULL; BString u("rsrc:///"); + + /* default.css -> beosdefault.css */ if (strcmp(path, "default.css") == 0) - u << "beosdefault.css"; - else - u << path; + path = "beosdefault.css"; + + /* favicon.ico -> favicon.png */ + if (strcmp(path, "favicon.ico") == 0) + path = "favicon.png"; + + u << path; LOG(("(%s) -> '%s'\n", path, u.String())); nsurl_create(u.String(), &url); return url; From fc782f55ba6ddc4e325a97e941aa1a2f21b78fb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Revol?= Date: Tue, 31 Dec 2013 17:37:21 +0100 Subject: [PATCH 030/773] beos: Add a resize knob to replicants The view resizes the base view by the relative mouse movement. TODO: Add a bitmap to draw, for now it's ugly green. --- beos/scaffolding.cpp | 90 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) diff --git a/beos/scaffolding.cpp b/beos/scaffolding.cpp index 252a816dc..3718f9492 100644 --- a/beos/scaffolding.cpp +++ b/beos/scaffolding.cpp @@ -154,6 +154,86 @@ extern int main(int argc, char** argv); // in fetch_rsrc.cpp extern BResources *gAppResources; +// #pragma mark - class NSResizeKnob + +class NSResizeKnob : public BView { +public: + NSResizeKnob(BRect frame, BView *target); +virtual ~NSResizeKnob(); + +virtual void MouseDown(BPoint where); +virtual void MouseUp(BPoint where); +virtual void MouseMoved(BPoint where, uint32 code, + const BMessage* dragMessage); + +virtual void Draw(BRect updateRect); + +void SetBitmap(const BBitmap *bitmap); + +private: + const BBitmap *fBitmap; + BView *fTarget; + BPoint fOffset; +}; + +NSResizeKnob::NSResizeKnob(BRect frame, BView *target) + : BView(frame, "NSResizeKnob", B_FOLLOW_BOTTOM | B_FOLLOW_RIGHT, B_WILL_DRAW), + fBitmap(NULL), + fTarget(target), + fOffset(-1, -1) +{ + SetViewColor(0, 255, 0); +} + + +NSResizeKnob::~NSResizeKnob() +{ +} + + +void +NSResizeKnob::MouseDown(BPoint where) +{ + SetMouseEventMask(B_POINTER_EVENTS, + B_NO_POINTER_HISTORY | B_LOCK_WINDOW_FOCUS); + fOffset = where; +} + + +void +NSResizeKnob::MouseUp(BPoint where) +{ + fOffset.Set(-1, -1); +} + + +void +NSResizeKnob::MouseMoved(BPoint where, uint32 code, + const BMessage* dragMessage) +{ + if (fOffset.x >= 0) { + fTarget->ResizeBy(where.x - fOffset.x, where.y - fOffset.y); + } +} + + +void +NSResizeKnob::Draw(BRect updateRect) +{ + if (!fBitmap) + return; + DrawBitmap(fBitmap); +} + + +void +NSResizeKnob::SetBitmap(const BBitmap *bitmap) +{ + fBitmap = bitmap; + Invalidate(); +} + + // #pragma mark - class NSThrobber class NSThrobber : public BView { @@ -1128,6 +1208,16 @@ void nsbeos_attach_toplevel_view(nsbeos_scaffolding *g, BView *view) g->top_view->AddChild(g->scroll_view); + // for replicants, add a NSResizeKnob to allow resizing + if (!g->window) { + BRect frame = g->scroll_view->Bounds(); + frame.left = frame.right - B_V_SCROLL_BAR_WIDTH; + frame.top = frame.bottom - B_H_SCROLL_BAR_HEIGHT; + NSResizeKnob *knob = new NSResizeKnob(frame, g->top_view); + //TODO: set bitmap + g->scroll_view->AddChild(knob); + } + view->MakeFocus(); // resize the horiz scrollbar to make room for the status bar and add it. From 92afacbe6fde01cdbf8cc02076e0a40d8581682e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Revol?= Date: Wed, 1 Jan 2014 17:07:02 +0100 Subject: [PATCH 031/773] beos: Add icon in url bar A bit hackish, flickers on resize, but it works. --- beos/scaffolding.cpp | 107 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 104 insertions(+), 3 deletions(-) diff --git a/beos/scaffolding.cpp b/beos/scaffolding.cpp index 3718f9492..36ba9ea63 100644 --- a/beos/scaffolding.cpp +++ b/beos/scaffolding.cpp @@ -24,6 +24,7 @@ #include #include +#include #include #include #include @@ -65,6 +66,7 @@ extern "C" { #include "utils/utils.h" #include "utils/log.h" } +#include "beos/bitmap.h" #include "beos/gui.h" #include "beos/plotters.h" #include "beos/scaffolding.h" @@ -154,6 +156,85 @@ extern int main(int argc, char** argv); // in fetch_rsrc.cpp extern BResources *gAppResources; +// #pragma mark - class NSIconTextControl + +class NSIconTextControl : public BTextControl { +public: + NSIconTextControl(BRect frame, const char* name, + const char* label, const char* initialText, + BMessage* message, + uint32 resizeMode + = B_FOLLOW_LEFT | B_FOLLOW_TOP, + uint32 flags = B_WILL_DRAW | B_NAVIGABLE); +virtual ~NSIconTextControl(); + +virtual void FrameResized(float newWidth, float newHeight); + +void SetBitmap(const BBitmap *bitmap); +void FixupTextRect(); + +private: + const BBitmap *fBitmap; + BView *fBitmapView; +}; + +NSIconTextControl::NSIconTextControl(BRect frame, const char* name, + const char* label, const char* initialText, + BMessage* message, + uint32 resizeMode, + uint32 flags) + : BTextControl(frame, name, label, initialText, message, resizeMode, flags), + fBitmap(NULL), + fBitmapView(NULL) +{ + BRect r(TextView()->TextRect()); + BRect frame = r; + frame.right = frame.left + 15; + frame.bottom = frame.top + 15; + frame.OffsetBy(-2, (r.IntegerHeight() - 16) / 2); + fBitmapView = new BView(frame, "iconview", B_FOLLOW_NONE, 0); + FixupTextRect(); + + TextView()->AddChild(fBitmapView); +} + + +NSIconTextControl::~NSIconTextControl() +{ +} + + +void +NSIconTextControl::FrameResized(float newWidth, float newHeight) +{ + BTextControl::FrameResized(newWidth, newHeight); + FixupTextRect(); + Invalidate(); +} + + +void +NSIconTextControl::SetBitmap(const BBitmap *bitmap) +{ + fBitmapView->SetViewBitmap(bitmap); + fBitmapView->Invalidate(); +} + + +void +NSIconTextControl::FixupTextRect() +{ + // FIXME: this flickers on resize, quite ugly + BRect r(TextView()->TextRect()); + + // in case this ever gets fixed... + if (r.left > 10) + return; + r.left += r.bottom - r.top; + TextView()->SetTextRect(r); +} + + // #pragma mark - class NSResizeKnob class NSResizeKnob : public BView { @@ -1890,9 +1971,12 @@ nsbeos_scaffolding *nsbeos_new_scaffolding(struct gui_window *toplevel) rect.InsetBySelf(5, 5); message = new BMessage('urle'); message->AddPointer("scaffolding", g); - g->url_bar = new BTextControl(rect, "url_bar", "url", "", message, + g->url_bar = new NSIconTextControl(rect, "url_bar", "", "", message, B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP); - g->url_bar->SetDivider(g->url_bar->StringWidth("url ")); + g->url_bar->SetDivider(0); + rect = g->url_bar->TextView()->TextRect(); + rect.left += 16; + g->url_bar->TextView()->SetTextRect(rect); g->tool_bar->AddChild(g->url_bar); @@ -2026,8 +2110,25 @@ void gui_window_stop_throbber(struct gui_window* _g) /** * add retrieved favicon to the gui */ -void gui_window_set_icon(struct gui_window *g, hlcache_handle *icon) +void gui_window_set_icon(struct gui_window *_g, hlcache_handle *icon) { + BBitmap *bitmap = NULL; + struct bitmap *bmp_icon; + + bmp_icon = (icon != NULL) ? content_get_bitmap(icon) : NULL; + + if (bmp_icon) { + bitmap = nsbeos_bitmap_get_primary(bmp_icon); + } + + struct beos_scaffolding *g = nsbeos_get_scaffold(_g); + + if (!g->top_view->LockLooper()) + return; + + dynamic_cast(g->url_bar)->SetBitmap(bitmap); + + g->top_view->UnlockLooper(); } /** From bd89e5a0883b4c5444ec41ff7c70bb9053ef2442 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Revol?= Date: Wed, 1 Jan 2014 17:41:23 +0100 Subject: [PATCH 032/773] beos: Fix background color for control on replicants Still some redundancy there but it works. --- beos/scaffolding.cpp | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/beos/scaffolding.cpp b/beos/scaffolding.cpp index 36ba9ea63..26ca2e952 100644 --- a/beos/scaffolding.cpp +++ b/beos/scaffolding.cpp @@ -606,13 +606,23 @@ NSBaseView::AllAttached() g->url_bar->SetTarget(this); - SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); + rgb_color c = ui_color(B_PANEL_BACKGROUND_COLOR); + SetViewColor(c); - g->tool_bar->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); - g->dragger->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); + g->tool_bar->SetViewColor(c); + g->back_button->SetViewColor(c); + g->forward_button->SetViewColor(c); + g->stop_button->SetViewColor(c); + g->reload_button->SetViewColor(c); + g->home_button->SetViewColor(c); + g->url_bar->SetViewColor(c); + g->throbber->SetViewColor(c); + g->scroll_view->SetViewColor(c); - g->status_bar->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); - g->status_bar->SetLowColor(ui_color(B_PANEL_BACKGROUND_COLOR)) ; + g->dragger->SetViewColor(c); + + g->status_bar->SetViewColor(c); + g->status_bar->SetLowColor(c); #if defined(__HAIKU__) || defined(B_DANO_VERSION) g->status_bar->SetHighColor(ui_color(B_PANEL_TEXT_COLOR)); #endif @@ -1344,6 +1354,8 @@ void nsbeos_attach_toplevel_view(nsbeos_scaffolding *g, BView *view) g->url_bar->SetTarget(view); + nsbeos_scaffolding_update_colors(g); + if (g->window) { recursively_set_menu_items_target(g->menu_bar, view); From 967d930477bc8080295e197c44ebd052bbd1963d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Revol?= Date: Wed, 1 Jan 2014 18:08:13 +0100 Subject: [PATCH 033/773] beos: Fix opening about from replicant popup --- beos/scaffolding.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/beos/scaffolding.cpp b/beos/scaffolding.cpp index 26ca2e952..1790cf06b 100644 --- a/beos/scaffolding.cpp +++ b/beos/scaffolding.cpp @@ -66,6 +66,7 @@ extern "C" { #include "utils/utils.h" #include "utils/log.h" } +#include "beos/about.h" #include "beos/bitmap.h" #include "beos/gui.h" #include "beos/plotters.h" @@ -402,6 +403,7 @@ NSBaseView::MessageReceived(BMessage *message) { switch (message->what) { case B_SIMPLE_DATA: + case B_ABOUT_REQUESTED: case B_ARGV_RECEIVED: case B_REFS_RECEIVED: case B_COPY: @@ -777,6 +779,15 @@ void nsbeos_scaffolding_dispatch_event(nsbeos_scaffolding *scaffold, BMessage *m case B_QUIT_REQUESTED: nsbeos_scaffolding_destroy(scaffold); break; + case B_ABOUT_REQUESTED: + { + nsbeos_about(NULL); + /* XXX: doesn't work yet! bug in rsrc:/ + BString url("rsrc:/about.en.html,text/html"); + browser_window_create(url.String(), NULL, NULL, true, false); + */ + break; + } case B_NETPOSITIVE_DOWN: //XXX WRITEME break; From 0dc8cd66256e9a9235f2976fcfed2797cc50c865 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Revol?= Date: Wed, 1 Jan 2014 18:19:55 +0100 Subject: [PATCH 034/773] beos: Fix about box --- beos/about.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/beos/about.cpp b/beos/about.cpp index bfe836e62..f8447fa2a 100644 --- a/beos/about.cpp +++ b/beos/about.cpp @@ -114,7 +114,14 @@ void nsbeos_about(struct gui_window *gui) alert->AddToSubset(w); } } + + // make space for controls + alert->ResizeBy(200, 640); + alert->MoveTo(alert->AlertPosition(alert->Frame().Width() + 1, + alert->Frame().Height() + 1)); + tv->SetStylable(true); + tv->ResizeBy(200, 640); add_section(tv, name, description); add_section(tv, NULL, copyright); add_section(tv, "authors", authors); @@ -123,10 +130,5 @@ void nsbeos_about(struct gui_window *gui) add_section(tv, "documenters", documenters); add_section(tv, url_label, url); - // make space for controls - alert->ResizeBy(200, 500); - alert->MoveTo(alert->AlertPosition(alert->Frame().Width() + 1, - alert->Frame().Height() + 1)); - alert->Go(NULL); } From 1025a49cb6c0eee0b66ac74eb5f639001643fe90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Revol?= Date: Wed, 1 Jan 2014 19:21:59 +0100 Subject: [PATCH 035/773] beos: if no gui window, pass the first one to nsbeos_about() --- beos/window.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/beos/window.cpp b/beos/window.cpp index 5c5df96b3..b743ec0c2 100644 --- a/beos/window.cpp +++ b/beos/window.cpp @@ -463,11 +463,9 @@ void nsbeos_dispatch_event(BMessage *message) break; case B_ABOUT_REQUESTED: { + if (gui == NULL) + gui = window_list; nsbeos_about(gui); - /* XXX: doesn't work yet! bug in rsrc:/ - BString url("rsrc:/about.en.html,text/html"); - browser_window_create(url.String(), NULL, NULL, true, false); - */ break; } case _UPDATE_: From f713cdd90b1b13d790f5e062a28c729aa98f6933 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Revol?= Date: Wed, 1 Jan 2014 19:23:28 +0100 Subject: [PATCH 036/773] beos: Add credits and licence buttons to about box We'll simplify it to just mention version infos like on atari. --- beos/about.cpp | 21 +++++++++++++++---- beos/scaffolding.cpp | 49 +++++++++++++++++++++++++++++++++++++++----- beos/scaffolding.h | 3 +++ 3 files changed, 64 insertions(+), 9 deletions(-) diff --git a/beos/about.cpp b/beos/about.cpp index f8447fa2a..3f7adf7fc 100644 --- a/beos/about.cpp +++ b/beos/about.cpp @@ -28,6 +28,8 @@ extern "C" { #include "beos/window.h" #include +#include +#include #include #include #include @@ -102,18 +104,29 @@ static void add_section(BTextView *textview, const char *header, void nsbeos_about(struct gui_window *gui) { BAlert *alert; - alert = new BAlert("about", "", /*"HomePage",*/ "Ok"); + alert = new BAlert("about", "", "Credits", "Licence", "Ok"); //XXX: i18n-ize BTextView *tv = alert->TextView(); + BHandler *target = be_app; + BMessage *message = new BMessage(ABOUT_BUTTON); + BInvoker *invoker = NULL; if (gui) { - alert->SetFeel(B_MODAL_SUBSET_WINDOW_FEEL); nsbeos_scaffolding *s = nsbeos_get_scaffold(gui); if (s) { NSBrowserWindow *w = nsbeos_get_bwindow_for_scaffolding(s); - if (w) + if (w) { + alert->SetFeel(B_MODAL_SUBSET_WINDOW_FEEL); alert->AddToSubset(w); + } + NSBaseView *v = nsbeos_get_baseview_for_scaffolding(s); + if (v) { + if (w) + message->AddPointer("Window", w); + target = v; + } } } + invoker = new BInvoker(message, target); // make space for controls alert->ResizeBy(200, 640); @@ -130,5 +143,5 @@ void nsbeos_about(struct gui_window *gui) add_section(tv, "documenters", documenters); add_section(tv, url_label, url); - alert->Go(NULL); + alert->Go(invoker); } diff --git a/beos/scaffolding.cpp b/beos/scaffolding.cpp index 1790cf06b..a67ab50f8 100644 --- a/beos/scaffolding.cpp +++ b/beos/scaffolding.cpp @@ -502,6 +502,7 @@ NSBaseView::MessageReceived(BMessage *message) case TOOLBAR_THROBBER: case TOOLBAR_EDIT: case CHOICES_SHOW: + case ABOUT_BUTTON: case APPLICATION_QUIT: if (Window()) Window()->DetachCurrentMessage(); @@ -781,11 +782,7 @@ void nsbeos_scaffolding_dispatch_event(nsbeos_scaffolding *scaffold, BMessage *m break; case B_ABOUT_REQUESTED: { - nsbeos_about(NULL); - /* XXX: doesn't work yet! bug in rsrc:/ - BString url("rsrc:/about.en.html,text/html"); - browser_window_create(url.String(), NULL, NULL, true, false); - */ + nsbeos_about(scaffold->top_level); break; } case B_NETPOSITIVE_DOWN: @@ -1198,6 +1195,43 @@ void nsbeos_scaffolding_dispatch_event(nsbeos_scaffolding *scaffold, BMessage *m break; case CHOICES_SHOW: break; + case ABOUT_BUTTON: + /* XXX: doesn't work yet! bug in rsrc:/ + BString url("rsrc:/about.en.html,text/html"); + browser_window_create(url.String(), NULL, NULL, true, false); + */ + { + int32 button; + if (message->FindInt32("which", &button) == B_OK) { + const char *goto_url = NULL; + nserror nserr; + nsurl *url; + switch (button) { + case 0: + goto_url = "about:credits"; + break; + case 1: + goto_url = "about:licence"; + break; + default: + break; + } + if (goto_url == NULL) + break; + nserr = nsurl_create(goto_url, &url); + if (nserr == NSERROR_OK) { + nserr = browser_window_navigate(bw, + url, NULL, + (browser_window_nav_flags)(BROWSER_WINDOW_HISTORY | BROWSER_WINDOW_VERIFIABLE), + NULL, NULL, NULL); + nsurl_unref(url); + } + if (nserr != NSERROR_OK) { + warn_user(messages_get_errorcode(nserr), 0); + } + } + } + break; case APPLICATION_QUIT: netsurf_quit = true; break; @@ -1276,6 +1310,11 @@ NSBrowserWindow *nsbeos_get_bwindow_for_scaffolding(nsbeos_scaffolding *scaffold return scaffold->window; } +NSBaseView *nsbeos_get_baseview_for_scaffolding(nsbeos_scaffolding *scaffold) +{ + return scaffold->top_view; +} + static void recursively_set_menu_items_target(BMenu *menu, BHandler *handler) { menu->SetTargetForItems(handler); diff --git a/beos/scaffolding.h b/beos/scaffolding.h index 7b7080322..1b78d54a8 100644 --- a/beos/scaffolding.h +++ b/beos/scaffolding.h @@ -173,6 +173,7 @@ typedef enum { /* misc actions */ CHOICES_SHOW, + ABOUT_BUTTON, APPLICATION_QUIT, } menu_action; @@ -181,6 +182,8 @@ NSBrowserWindow *nsbeos_find_last_window(void); NSBrowserWindow *nsbeos_get_bwindow_for_scaffolding(nsbeos_scaffolding *scaffold); +NSBaseView *nsbeos_get_baseview_for_scaffolding(nsbeos_scaffolding *scaffold); + nsbeos_scaffolding *nsbeos_new_scaffolding(struct gui_window *toplevel); bool nsbeos_scaffolding_is_busy(nsbeos_scaffolding *scaffold); From a7ef9dc4abb57e0d0675de6befc8c639ea9c3a3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Revol?= Date: Wed, 1 Jan 2014 19:35:21 +0100 Subject: [PATCH 037/773] beos: Simplify about box Just print some version infos, the buttons are there for credits and licence. --- beos/about.cpp | 96 +++++++------------------------------------------- 1 file changed, 13 insertions(+), 83 deletions(-) diff --git a/beos/about.cpp b/beos/about.cpp index 3f7adf7fc..1c43c4606 100644 --- a/beos/about.cpp +++ b/beos/about.cpp @@ -22,6 +22,9 @@ #include extern "C" { #include "utils/log.h" +#include "utils/testament.h" +#include "utils/useragent.h" +#include "curl/curlver.h" } #include "beos/about.h" #include "beos/scaffolding.h" @@ -30,83 +33,23 @@ extern "C" { #include #include #include -#include #include -#include -static const char *authors[] = { - "John-Mark Bell", "James Bursa", "Michael Drake", - "Rob Kendrick", "Adrian Lees", "Vincent Sanders", - "Daniel Silverstone", "Richard Wilson", - "\nContributors:", "Kevin Bagust", "Stefaan Claes", - "Matthew Hambley", "Rob Jackson", "Jeffrey Lee", "Phil Mellor", - "Philip Pemberton", "Darren Salt", "Andrew Timmins", - "John Tytgat", "Chris Williams", - "\nGoogle Summer of Code Contributors:", "Adam Blokus", - "Sean Fox", "Michael Lester", "Andrew Sidwell", NULL -}; - -static const char *translators[] = { "Sebastian Barthel", "Bruno D'Arcangeli", - "Gerard van Katwijk", "Jérôme Mathevet", "Simon Voortman.", NULL -}; -static const char *artists[] = { - "Michael Drake", "\nContributors:", "Andrew Duffell", - "John Duffell", "Richard Hallas", "Phil Mellor", NULL -}; - -static const char *documenters[] = { - "John-Mark Bell", "James Bursa", "Michael Drake", - "Richard Wilson", "\nContributors:", "James Shaw", NULL -}; - -static const char *name = "NetSurf"; -static const char *description = - "Small as a mouse, fast as a cheetah, and available for free.\n" - "NetSurf is a web browser for RISC OS and UNIX-like platforms."; -static const char *url = "http://www.netsurf-browser.org/"; -static const char *url_label = "NetSurf Website"; -static const char *copyright = - "Copyright © 2003 - 2008 The NetSurf Developers"; - -static void add_section(BTextView *textview, const char *header, - const char *text) -{ - BFont titleFont; - titleFont.SetSize(titleFont.Size() + 10); - BFont textFont; - text_run_array titleRuns = { 1, { 0, titleFont, { 0, 0, 0, 255 } } }; - text_run_array textRuns = { 1, { 0, textFont, { 0, 0, 0, 255 } } }; - BString h(header); - BString t(text); - h << "\n"; - t << "\n\n"; - if (header) - textview->Insert(h.String(), &titleRuns); - if (text) - textview->Insert(t.String(), &textRuns); -} - -static void add_section(BTextView *textview, const char *header, - const char **texts) -{ - BString t; - while (*texts) { - t << *texts; - t << ", "; - texts++; - } - add_section(textview, header, t.String()); -} /** * Creates the about alert */ void nsbeos_about(struct gui_window *gui) { - BAlert *alert; - alert = new BAlert("about", "", "Credits", "Licence", "Ok"); - //XXX: i18n-ize - BTextView *tv = alert->TextView(); + BString text; + text << "Netsurf : " << user_agent_string() << "\n"; + text << "Version : " << netsurf_version << "\n"; + text << "Build ID : " << WT_REVID << "\n"; + text << "Date : " << WT_COMPILEDATE << "\n"; + text << "cURL : " << LIBCURL_VERSION << "\n"; + + BAlert *alert = new BAlert("about", text.String(), "Credits", "Licence", "Ok"); + BHandler *target = be_app; BMessage *message = new BMessage(ABOUT_BUTTON); BInvoker *invoker = NULL; @@ -128,20 +71,7 @@ void nsbeos_about(struct gui_window *gui) } invoker = new BInvoker(message, target); - // make space for controls - alert->ResizeBy(200, 640); - alert->MoveTo(alert->AlertPosition(alert->Frame().Width() + 1, - alert->Frame().Height() + 1)); - - tv->SetStylable(true); - tv->ResizeBy(200, 640); - add_section(tv, name, description); - add_section(tv, NULL, copyright); - add_section(tv, "authors", authors); - add_section(tv, "translators", translators); - add_section(tv, "artists", artists); - add_section(tv, "documenters", documenters); - add_section(tv, url_label, url); + //TODO: i18n-ize alert->Go(invoker); } From 3a1bf5c20fe9e30117dabadbfc9277a6ec3eb295 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Revol?= Date: Wed, 1 Jan 2014 19:53:42 +0100 Subject: [PATCH 038/773] beos: Also set LowColor on toolbar buttons when attached --- beos/scaffolding.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/beos/scaffolding.cpp b/beos/scaffolding.cpp index a67ab50f8..06184f24e 100644 --- a/beos/scaffolding.cpp +++ b/beos/scaffolding.cpp @@ -614,10 +614,15 @@ NSBaseView::AllAttached() g->tool_bar->SetViewColor(c); g->back_button->SetViewColor(c); + g->back_button->SetLowColor(c); g->forward_button->SetViewColor(c); + g->forward_button->SetLowColor(c); g->stop_button->SetViewColor(c); + g->stop_button->SetLowColor(c); g->reload_button->SetViewColor(c); + g->reload_button->SetLowColor(c); g->home_button->SetViewColor(c); + g->home_button->SetLowColor(c); g->url_bar->SetViewColor(c); g->throbber->SetViewColor(c); g->scroll_view->SetViewColor(c); From 6c63adb1c1b7ecdc6666d6b84ec3b354ce8c37ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Revol?= Date: Sat, 4 Jan 2014 20:22:26 +0100 Subject: [PATCH 039/773] beos: Remove Messages symlinks in res/*/ It seems the messages files aren't generated early enough anymore, so building the resources fails. We can't load them from the resource yet anyway. --- beos/res/de/Messages | 1 - beos/res/en/Messages | 1 - beos/res/fr/Messages | 1 - beos/res/it/Messages | 1 - beos/res/nl/Messages | 1 - 5 files changed, 5 deletions(-) delete mode 120000 beos/res/de/Messages delete mode 120000 beos/res/en/Messages delete mode 120000 beos/res/fr/Messages delete mode 120000 beos/res/it/Messages delete mode 120000 beos/res/nl/Messages diff --git a/beos/res/de/Messages b/beos/res/de/Messages deleted file mode 120000 index 2f1fc39c3..000000000 --- a/beos/res/de/Messages +++ /dev/null @@ -1 +0,0 @@ -../../../!NetSurf/Resources/de/Messages \ No newline at end of file diff --git a/beos/res/en/Messages b/beos/res/en/Messages deleted file mode 120000 index 72c9eff90..000000000 --- a/beos/res/en/Messages +++ /dev/null @@ -1 +0,0 @@ -../../../!NetSurf/Resources/en/Messages \ No newline at end of file diff --git a/beos/res/fr/Messages b/beos/res/fr/Messages deleted file mode 120000 index a42cf08f4..000000000 --- a/beos/res/fr/Messages +++ /dev/null @@ -1 +0,0 @@ -../../../!NetSurf/Resources/fr/Messages \ No newline at end of file diff --git a/beos/res/it/Messages b/beos/res/it/Messages deleted file mode 120000 index d4c5c2956..000000000 --- a/beos/res/it/Messages +++ /dev/null @@ -1 +0,0 @@ -../../../!NetSurf/Resources/it/Messages \ No newline at end of file diff --git a/beos/res/nl/Messages b/beos/res/nl/Messages deleted file mode 120000 index d484ebd29..000000000 --- a/beos/res/nl/Messages +++ /dev/null @@ -1 +0,0 @@ -../../../!NetSurf/Resources/nl/Messages \ No newline at end of file From 581d87757601286fbb8250abc8d2bd185dddecb7 Mon Sep 17 00:00:00 2001 From: Daniel Silverstone Date: Sat, 4 Jan 2014 19:34:04 +0000 Subject: [PATCH 040/773] In theory, store raw filenames and pass them through for file upload. Untested due to no file-upload in GTK frontend just yet --- content/fetch.c | 2 ++ content/fetch.h | 1 + content/fetchers/curl.c | 2 +- render/form.c | 25 ++++++++++++++++++++++++- 4 files changed, 28 insertions(+), 2 deletions(-) diff --git a/content/fetch.c b/content/fetch.c index 1ff925ae3..ffc907891 100644 --- a/content/fetch.c +++ b/content/fetch.c @@ -665,6 +665,8 @@ void fetch_multipart_data_destroy(struct fetch_multipart_data *list) next = list->next; free(list->name); free(list->value); + if (list->file) + free(list->rawfile); free(list); } } diff --git a/content/fetch.h b/content/fetch.h index d23b3cd4b..a173f7f30 100644 --- a/content/fetch.h +++ b/content/fetch.h @@ -79,6 +79,7 @@ struct fetch_multipart_data { bool file; /**< Item is a file */ char *name; /**< Name of item */ char *value; /**< Item value */ + char *rawfile; /**< Raw filename if file is true */ struct fetch_multipart_data *next; /**< Next in linked list */ }; diff --git a/content/fetchers/curl.c b/content/fetchers/curl.c index 1dfc44631..7578ad4cb 100644 --- a/content/fetchers/curl.c +++ b/content/fetchers/curl.c @@ -1301,7 +1301,7 @@ fetch_curl_post_convert(const struct fetch_multipart_data *control) char *mimetype = fetch_mimetype(control->value); code = curl_formadd(&post, &last, CURLFORM_COPYNAME, control->name, - CURLFORM_FILE, control->value, + CURLFORM_FILE, control->rawfile, CURLFORM_FILENAME, leafname, CURLFORM_CONTENTTYPE, (mimetype != 0 ? mimetype : "text/plain"), diff --git a/render/form.c b/render/form.c index aa6661cfa..a4b882a64 100644 --- a/render/form.c +++ b/render/form.c @@ -50,6 +50,7 @@ #include "render/html.h" #include "render/html_internal.h" #include "render/layout.h" +#include "utils/corestrings.h" #include "utils/log.h" #include "utils/messages.h" #include "utils/talloc.h" @@ -346,7 +347,7 @@ bool form_successful_controls(struct form *form, struct fetch_multipart_data sentinel, *last_success, *success_new; char *value = NULL; bool had_submit = false; - char *charset; + char *charset, *rawfile_temp; last_success = &sentinel; sentinel.next = NULL; @@ -598,6 +599,28 @@ bool form_successful_controls(struct form *form, goto no_memory; } + /* Retrieve the filename from the DOM annotation */ + if (dom_node_get_user_data( + control->node, + corestring_dom___ns_key_file_name_node_data, + &rawfile_temp) != DOM_NO_ERR) { + LOG(("unable to get rawfile")); + goto no_memory; + } + + if (rawfile_temp == NULL) { + /* No annotation means the file was not + */ + success_new->rawfile = strdup(""); + } else { + success_new->rawfile = strdup(rawfile_temp); + } + + if (success_new->rawfile == NULL) { + LOG(("strdup failed")); + goto no_memory; + } + continue; break; From 2a18cef82b84037b14f5e470c70ab70e433add5e Mon Sep 17 00:00:00 2001 From: Daniel Silverstone Date: Sat, 4 Jan 2014 20:53:43 +0000 Subject: [PATCH 041/773] Shunt around the file multipart stuff a bit to try and fix the segfault --- render/form.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/render/form.c b/render/form.c index a4b882a64..9ac52392e 100644 --- a/render/form.c +++ b/render/form.c @@ -590,15 +590,7 @@ bool form_successful_controls(struct form *form, success_new->value = ENCODE_ITEM(control->value ? control->value : ""); - success_new->next = 0; - last_success->next = success_new; - last_success = success_new; - if (!success_new->name || - !success_new->value) { - LOG(("strdup failed")); - goto no_memory; - } - + success_new->rawfile = NULL; /* Retrieve the filename from the DOM annotation */ if (dom_node_get_user_data( control->node, @@ -621,6 +613,15 @@ bool form_successful_controls(struct form *form, goto no_memory; } + success_new->next = 0; + last_success->next = success_new; + last_success = success_new; + if (!success_new->name || + !success_new->value) { + LOG(("strdup failed")); + goto no_memory; + } + continue; break; From de42f8880e49bc32825d13a4ba0c7ed6e4295b81 Mon Sep 17 00:00:00 2001 From: Daniel Silverstone Date: Sat, 4 Jan 2014 21:15:52 +0000 Subject: [PATCH 042/773] Add a bunch of logging to try and help track down the issue with rawfile handling, sorry guys --- content/fetch.c | 4 +++- content/fetchers/curl.c | 1 + render/form.c | 5 +++-- render/html.c | 4 ++++ 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/content/fetch.c b/content/fetch.c index ffc907891..5b9aba1b0 100644 --- a/content/fetch.c +++ b/content/fetch.c @@ -665,8 +665,10 @@ void fetch_multipart_data_destroy(struct fetch_multipart_data *list) next = list->next; free(list->name); free(list->value); - if (list->file) + if (list->file) { + LOG(("Freeing rawfile: %s", list->rawfile)); free(list->rawfile); + } free(list); } } diff --git a/content/fetchers/curl.c b/content/fetchers/curl.c index 7578ad4cb..1fada9d0a 100644 --- a/content/fetchers/curl.c +++ b/content/fetchers/curl.c @@ -1299,6 +1299,7 @@ fetch_curl_post_convert(const struct fetch_multipart_data *control) code, control->name)); } else { char *mimetype = fetch_mimetype(control->value); + LOG(("XYZZY: Using rawfile of %s", control->rawfile)); code = curl_formadd(&post, &last, CURLFORM_COPYNAME, control->name, CURLFORM_FILE, control->rawfile, diff --git a/render/form.c b/render/form.c index 9ac52392e..fe18e4336 100644 --- a/render/form.c +++ b/render/form.c @@ -592,14 +592,15 @@ bool form_successful_controls(struct form *form, control->value : ""); success_new->rawfile = NULL; /* Retrieve the filename from the DOM annotation */ + LOG(("XYZZY: Attempting to retrieve data")); if (dom_node_get_user_data( control->node, corestring_dom___ns_key_file_name_node_data, &rawfile_temp) != DOM_NO_ERR) { - LOG(("unable to get rawfile")); + LOG(("XYZZY: unable to get rawfile")); goto no_memory; } - + LOG(("XYZZY: Got raw filename: %s", rawfile_temp)); if (rawfile_temp == NULL) { /* No annotation means the file was not */ diff --git a/render/html.c b/render/html.c index 49bb019dd..c1e831571 100644 --- a/render/html.c +++ b/render/html.c @@ -1704,6 +1704,7 @@ static void html__dom_user_data_handler(dom_node_operation operation, switch (operation) { case DOM_NODE_CLONED: + LOG(("XYZZY: Cloned, so copying to the new location")); if (dom_node_set_user_data(dst, corestring_dom___ns_key_file_name_node_data, strdup(data), html__dom_user_data_handler, @@ -1719,6 +1720,7 @@ static void html__dom_user_data_handler(dom_node_operation operation, break; case DOM_NODE_DELETED: + LOG(("XYZZY: Freeing data due to node deletion")); free(data); break; default: @@ -1809,10 +1811,12 @@ static bool html_drop_file_at_point(struct content *c, int x, int y, char *file) form_gadget_update_value(html, file_box->gadget, utf8_fn); /* corestring_dom___ns_key_file_name_node_data */ + LOG(("XYZZY: Setting userdata to %s", file)); if (dom_node_set_user_data((dom_node *)file_box->gadget->node, corestring_dom___ns_key_file_name_node_data, strdup(file), html__dom_user_data_handler, &oldfile) == DOM_NO_ERR) { + LOG(("XYZZY: Userdata used to be %s", oldfile)); if (oldfile != NULL) free(oldfile); } From 33f94c265e34c6ec2a9c0603f814deda47f77849 Mon Sep 17 00:00:00 2001 From: Daniel Silverstone Date: Sat, 4 Jan 2014 21:49:03 +0000 Subject: [PATCH 043/773] Support cloning rawfile data --- content/fetch.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/content/fetch.c b/content/fetch.c index 5b9aba1b0..a9a9049f2 100644 --- a/content/fetch.c +++ b/content/fetch.c @@ -639,6 +639,21 @@ struct fetch_multipart_data *fetch_multipart_data_clone( return NULL; } + if (clone->file) { + clone->rawfile = strdup(list->rawfile); + if (clone->rawfile == NULL) { + free(clone->value); + free(clone->name); + free(clone); + if (result != NULL) + fetch_multipart_data_destroy(result); + + return NULL; + } + } else { + clone->rawfile = NULL; + } + clone->next = NULL; if (result == NULL) From b4f986084885a366220d86d91be84be5dad7a0bc Mon Sep 17 00:00:00 2001 From: Daniel Silverstone Date: Sat, 4 Jan 2014 22:05:23 +0000 Subject: [PATCH 044/773] Remove logging now that file upload *seems* to work --- content/fetchers/curl.c | 1 - render/form.c | 5 ++--- render/html.c | 4 ---- 3 files changed, 2 insertions(+), 8 deletions(-) diff --git a/content/fetchers/curl.c b/content/fetchers/curl.c index 1fada9d0a..7578ad4cb 100644 --- a/content/fetchers/curl.c +++ b/content/fetchers/curl.c @@ -1299,7 +1299,6 @@ fetch_curl_post_convert(const struct fetch_multipart_data *control) code, control->name)); } else { char *mimetype = fetch_mimetype(control->value); - LOG(("XYZZY: Using rawfile of %s", control->rawfile)); code = curl_formadd(&post, &last, CURLFORM_COPYNAME, control->name, CURLFORM_FILE, control->rawfile, diff --git a/render/form.c b/render/form.c index fe18e4336..9ac52392e 100644 --- a/render/form.c +++ b/render/form.c @@ -592,15 +592,14 @@ bool form_successful_controls(struct form *form, control->value : ""); success_new->rawfile = NULL; /* Retrieve the filename from the DOM annotation */ - LOG(("XYZZY: Attempting to retrieve data")); if (dom_node_get_user_data( control->node, corestring_dom___ns_key_file_name_node_data, &rawfile_temp) != DOM_NO_ERR) { - LOG(("XYZZY: unable to get rawfile")); + LOG(("unable to get rawfile")); goto no_memory; } - LOG(("XYZZY: Got raw filename: %s", rawfile_temp)); + if (rawfile_temp == NULL) { /* No annotation means the file was not */ diff --git a/render/html.c b/render/html.c index c1e831571..49bb019dd 100644 --- a/render/html.c +++ b/render/html.c @@ -1704,7 +1704,6 @@ static void html__dom_user_data_handler(dom_node_operation operation, switch (operation) { case DOM_NODE_CLONED: - LOG(("XYZZY: Cloned, so copying to the new location")); if (dom_node_set_user_data(dst, corestring_dom___ns_key_file_name_node_data, strdup(data), html__dom_user_data_handler, @@ -1720,7 +1719,6 @@ static void html__dom_user_data_handler(dom_node_operation operation, break; case DOM_NODE_DELETED: - LOG(("XYZZY: Freeing data due to node deletion")); free(data); break; default: @@ -1811,12 +1809,10 @@ static bool html_drop_file_at_point(struct content *c, int x, int y, char *file) form_gadget_update_value(html, file_box->gadget, utf8_fn); /* corestring_dom___ns_key_file_name_node_data */ - LOG(("XYZZY: Setting userdata to %s", file)); if (dom_node_set_user_data((dom_node *)file_box->gadget->node, corestring_dom___ns_key_file_name_node_data, strdup(file), html__dom_user_data_handler, &oldfile) == DOM_NO_ERR) { - LOG(("XYZZY: Userdata used to be %s", oldfile)); if (oldfile != NULL) free(oldfile); } From 40387901e4b353c1b12e5e8a54214f43ac46c168 Mon Sep 17 00:00:00 2001 From: John-Mark Bell Date: Sun, 5 Jan 2014 10:37:37 +0000 Subject: [PATCH 045/773] Env: we need libmozjs185. Install it explicitly. --- Docs/env.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Docs/env.sh b/Docs/env.sh index 27ae2e92d..57334febd 100644 --- a/Docs/env.sh +++ b/Docs/env.sh @@ -53,7 +53,7 @@ NS_BROWSER="netsurf" # deb packages NS_DEV_DEB="build-essential pkg-config git gperf" NS_TOOL_DEB="flex bison" -NS_GTK_DEB="libgtk2.0-dev libcurl3-dev libpng-dev librsvg2-dev libjpeg-dev libmozjs-dev" +NS_GTK_DEB="libgtk2.0-dev libcurl3-dev libpng-dev librsvg2-dev libjpeg-dev libmozjs185-dev" #add target specific libraries if [ "x${TARGET_ABI}" = "xriscos" ]; then From 88278faa20aec727e2c0e355bcc4601c396b8fdd Mon Sep 17 00:00:00 2001 From: John-Mark Bell Date: Sun, 5 Jan 2014 10:48:43 +0000 Subject: [PATCH 046/773] Env: also install libhtml-parser-perl --- Docs/env.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Docs/env.sh b/Docs/env.sh index 57334febd..7b5aedd1d 100644 --- a/Docs/env.sh +++ b/Docs/env.sh @@ -52,7 +52,7 @@ NS_BROWSER="netsurf" # deb packages NS_DEV_DEB="build-essential pkg-config git gperf" -NS_TOOL_DEB="flex bison" +NS_TOOL_DEB="flex bison libhtml-parser-perl" NS_GTK_DEB="libgtk2.0-dev libcurl3-dev libpng-dev librsvg2-dev libjpeg-dev libmozjs185-dev" #add target specific libraries From b80da8bf0b6662062881214bc19bbe8cbe1ec2f4 Mon Sep 17 00:00:00 2001 From: Chris Young Date: Sun, 5 Jan 2014 12:07:53 +0000 Subject: [PATCH 047/773] Add Javascript build ability to cross-compiled target --- amiga/Makefile.target | 1 + 1 file changed, 1 insertion(+) diff --git a/amiga/Makefile.target b/amiga/Makefile.target index b3220a142..7b04f3763 100644 --- a/amiga/Makefile.target +++ b/amiga/Makefile.target @@ -46,6 +46,7 @@ else $(eval $(call pkg_config_find_and_add_enabled,PNG,libpng,PNG)) $(eval $(call pkg_config_find_and_add_enabled,NSSVG,libsvgtiny,NSSVG)) $(eval $(call pkg_config_find_and_add_enabled,AMIGA_CAIRO,cairo,Cairo)) + $(eval $(call feature_enabled,MOZJS,-DXP_AMIGA -DWITH_MOZJS -DJS_VERSION=170 -DJSVERSION_LATEST=170 -DJSOPTION_JIT=0 -DJSCLASS_GLOBAL_FLAGS=0,-ljs,JavaScript)) $(eval $(call feature_enabled,AMIGA_ICON,-DWITH_AMIGA_ICON,,Amiga icon)) $(eval $(call feature_enabled,AMIGA_DATATYPES,-DWITH_AMIGA_DATATYPES,,DataTypes)) From 32468516e31ee16f6d63923aeb2af8714dfe1a1a Mon Sep 17 00:00:00 2001 From: John-Mark Bell Date: Sun, 5 Jan 2014 14:34:04 +0000 Subject: [PATCH 048/773] Speculatively start image fetches as we parse the document. --- desktop/save_complete.c | 2 +- render/html.c | 35 +++++++++++++++++++++++++++++++++++ render/html_object.c | 26 +++++++++++++++++--------- 3 files changed, 53 insertions(+), 10 deletions(-) diff --git a/desktop/save_complete.c b/desktop/save_complete.c index 0c67654a6..efe223747 100644 --- a/desktop/save_complete.c +++ b/desktop/save_complete.c @@ -435,7 +435,7 @@ static bool save_complete_save_html_objects(save_complete_ctx *ctx, object = html_get_objects(c, &count); for (; object != NULL; object = object->next) { - if (object->content != NULL) { + if (object->content != NULL || object->box != NULL) { if (save_complete_save_html_object(ctx, object->content) == false) return false; diff --git a/render/html.c b/render/html.c index 49bb019dd..04b2fda18 100644 --- a/render/html.c +++ b/render/html.c @@ -507,6 +507,37 @@ static nserror html_meta_refresh_process_element(html_content *c, dom_node *n) return error; } +static bool html_process_img(html_content *c, dom_node *node) +{ + dom_string *src; + nsurl *url; + nserror err; + dom_exception exc; + bool success; + + /* Do nothing if foreground images are disabled */ + if (nsoption_bool(foreground_images) == false) { + return true; + } + + exc = dom_element_get_attribute(node, corestring_dom_src, &src); + if (exc != DOM_NO_ERR || src == NULL) { + return true; + } + + err = nsurl_join(c->base_url, dom_string_data(src), &url); + if (err != NSERROR_OK) { + dom_string_unref(src); + return false; + } + dom_string_unref(src); + + /* Speculatively fetch the image */ + success = html_fetch_object(c, url, NULL, CONTENT_IMAGE, 0, 0, false); + nsurl_unref(url); + + return success; +} /** * Complete conversion of an HTML document @@ -608,6 +639,10 @@ dom_default_action_DOMNodeInserted_cb(struct dom_event *evt, void *pw) name, corestring_lwc_title) && htmlc->title == NULL) { htmlc->title = dom_node_ref(node); + } else if (dom_string_caseless_lwc_isequal( + name, corestring_lwc_img)) { + html_process_img(htmlc, + (dom_node *) node); } dom_string_unref(name); diff --git a/render/html_object.c b/render/html_object.c index f4975e9ba..6cd08c1ef 100644 --- a/render/html_object.c +++ b/render/html_object.c @@ -123,6 +123,9 @@ html_object_callback(hlcache_handle *object, assert(c->base.status != CONTENT_STATUS_ERROR); box = o->box; + if (box == NULL && event->type != CONTENT_MSG_ERROR) { + return NSERROR_OK; + } switch (event->type) { case CONTENT_MSG_LOADING: @@ -181,11 +184,13 @@ html_object_callback(hlcache_handle *object, o->content = NULL; - c->base.active--; - LOG(("%d fetches active", c->base.active)); + if (box != NULL) { + c->base.active--; + LOG(("%d fetches active", c->base.active)); - content_add_error(&c->base, "?", 0); - html_object_failed(box, c, o->background); + content_add_error(&c->base, "?", 0); + html_object_failed(box, c, o->background); + } break; case CONTENT_MSG_STATUS: @@ -464,7 +469,7 @@ html_object_callback(hlcache_handle *object, * then reformat the page to display newly fetched objects */ else if (nsoption_bool(incremental_reflow) && event->type == CONTENT_MSG_DONE && - !(box->flags & REPLACE_DIM) && + box != NULL && !(box->flags & REPLACE_DIM) && (c->base.status == CONTENT_STATUS_READY || c->base.status == CONTENT_STATUS_DONE) && (wallclock() > c->base.reformat_time)) { @@ -491,6 +496,7 @@ static bool html_replace_object(struct content_html_object *object, nsurl *url) nserror error; assert(object != NULL); + assert(object->box != NULL); c = (html_content *) object->parent; @@ -562,7 +568,7 @@ nserror html_object_open_objects(html_content *html, struct browser_window *bw) for (object = html->object_list; object != NULL; object = next) { next = object->next; - if (object->content == NULL) + if (object->content == NULL || object->box == NULL) continue; if (content_get_type(object->content) == CONTENT_NONE) @@ -621,7 +627,7 @@ nserror html_object_close_objects(html_content *html) for (object = html->object_list; object != NULL; object = next) { next = object->next; - if (object->content == NULL) + if (object->content == NULL || object->box == NULL) continue; if (content_get_type(object->content) == CONTENT_NONE) @@ -701,8 +707,10 @@ bool html_fetch_object(html_content *c, nsurl *url, struct box *box, c->object_list = object; c->num_objects++; - c->base.active++; - LOG(("%d fetches active", c->base.active)); + if (box != NULL) { + c->base.active++; + LOG(("%d fetches active", c->base.active)); + } return true; } From 1bd4a34a271e4f839298f56d8e45f02dfa9d378b Mon Sep 17 00:00:00 2001 From: Rob Kendrick Date: Sun, 5 Jan 2014 14:39:08 +0000 Subject: [PATCH 049/773] Remove asserts for default cases from all content message handlers; this is laborious and is no longer useful for catching bugs. --- css/css.c | 13 +------------ desktop/browser.c | 2 +- desktop/searchweb.c | 8 +------- gtk/theme.c | 14 ++------------ render/html_css.c | 10 +--------- render/html_object.c | 6 +----- render/html_script.c | 30 +++--------------------------- riscos/theme_install.c | 6 ------ 8 files changed, 10 insertions(+), 79 deletions(-) diff --git a/css/css.c b/css/css.c index f8aa71a03..803906692 100644 --- a/css/css.c +++ b/css/css.c @@ -655,19 +655,8 @@ nserror nscss_import(hlcache_handle *handle, /* Already released handle */ break; - case CONTENT_MSG_LOADING: - case CONTENT_MSG_READY: - case CONTENT_MSG_STATUS: - case CONTENT_MSG_REDIRECT: - /* messages content handler will legitamately recive - * but does not need to handle - */ - break; - default: - /* all other messages are unexpected and fatal */ - LOG(("Unhandled message type %d", event->type)); - assert(0); + break; } /* Preserve out-of-memory. Anything else is OK */ diff --git a/desktop/browser.c b/desktop/browser.c index d159a5599..83b06bac5 100644 --- a/desktop/browser.c +++ b/desktop/browser.c @@ -1556,7 +1556,7 @@ static nserror browser_window_callback(hlcache_handle *c, break; default: - assert(0); + break; } return NSERROR_OK; diff --git a/desktop/searchweb.c b/desktop/searchweb.c index 87e3e21f1..4c050d97a 100644 --- a/desktop/searchweb.c +++ b/desktop/searchweb.c @@ -304,9 +304,6 @@ nserror search_web_ico_callback(hlcache_handle *ico, const hlcache_event *event, void *pw) { switch (event->type) { - case CONTENT_MSG_LOADING: - case CONTENT_MSG_READY: - break; case CONTENT_MSG_DONE: LOG(("got favicon '%s'", nsurl_access(hlcache_handle_get_url(ico)))); @@ -322,11 +319,8 @@ nserror search_web_ico_callback(hlcache_handle *ico, search_web_retrieve_ico(true); break; - case CONTENT_MSG_STATUS: - break; - default: - assert(0); + break; } return NSERROR_OK; diff --git a/gtk/theme.c b/gtk/theme.c index 9d50c5931..ff0144cc8 100644 --- a/gtk/theme.c +++ b/gtk/theme.c @@ -793,11 +793,8 @@ theme_install_callback(hlcache_handle *c, const hlcache_event *event, void *pw) { switch (event->type) { - case CONTENT_MSG_READY: - break; - case CONTENT_MSG_DONE: - { + case CONTENT_MSG_DONE: { const char *source_data; unsigned long source_size; @@ -807,21 +804,14 @@ theme_install_callback(hlcache_handle *c, warn_user("ThemeInvalid", 0); hlcache_handle_release(c); + break; } - break; case CONTENT_MSG_ERROR: warn_user(event->data.error, 0); break; - case CONTENT_MSG_STATUS: - break; - - case CONTENT_MSG_LOADING: - case CONTENT_MSG_REFORMAT: - case CONTENT_MSG_REDRAW: default: - assert(0); break; } diff --git a/render/html_css.c b/render/html_css.c index 88c67697d..ad24804a9 100644 --- a/render/html_css.c +++ b/render/html_css.c @@ -97,14 +97,6 @@ html_convert_css_callback(hlcache_handle *css, assert(i != parent->stylesheet_count); switch (event->type) { - case CONTENT_MSG_LOADING: - break; - - case CONTENT_MSG_READY: - break; - - case CONTENT_MSG_REDIRECT: - break; case CONTENT_MSG_DONE: LOG(("done stylesheet slot %d '%s'", i, @@ -143,7 +135,7 @@ html_convert_css_callback(hlcache_handle *css, return NSERROR_OK; default: - assert(0); + break; } if (html_can_begin_conversion(parent)) { diff --git a/render/html_object.c b/render/html_object.c index f4975e9ba..7b34c4a7e 100644 --- a/render/html_object.c +++ b/render/html_object.c @@ -203,10 +203,6 @@ html_object_callback(hlcache_handle *object, } break; - case CONTENT_MSG_REFORMAT: - case CONTENT_MSG_REDIRECT: - break; - case CONTENT_MSG_REDRAW: if (c->base.status != CONTENT_STATUS_LOADING) { union content_msg_data data = event->data; @@ -440,7 +436,7 @@ html_object_callback(hlcache_handle *object, break; default: - assert(0); + break; } if (c->base.status == CONTENT_STATUS_READY && c->base.active == 0 && diff --git a/render/html_script.c b/render/html_script.c index 4aa8aff11..4a82bcd70 100644 --- a/render/html_script.c +++ b/render/html_script.c @@ -172,8 +172,6 @@ convert_script_async_cb(hlcache_handle *script, parent->base.active--; LOG(("%d fetches active", parent->base.active)); - - break; case CONTENT_MSG_ERROR: @@ -188,11 +186,8 @@ convert_script_async_cb(hlcache_handle *script, break; - case CONTENT_MSG_STATUS: - break; - default: - assert(0); + break; } return NSERROR_OK; @@ -219,11 +214,6 @@ convert_script_defer_cb(hlcache_handle *script, assert(i != parent->scripts_count); switch (event->type) { - case CONTENT_MSG_LOADING: - break; - - case CONTENT_MSG_READY: - break; case CONTENT_MSG_DONE: LOG(("script %d done '%s'", i, @@ -245,11 +235,8 @@ convert_script_defer_cb(hlcache_handle *script, break; - case CONTENT_MSG_STATUS: - break; - default: - assert(0); + break; } /* if there are no active fetches remaining begin post parse @@ -333,19 +320,8 @@ convert_script_sync_cb(hlcache_handle *script, break; - case CONTENT_MSG_LOADING: - case CONTENT_MSG_READY: - case CONTENT_MSG_STATUS: - case CONTENT_MSG_REDIRECT: - /* messages content handler will legitamately recive - * but does not need to handle - */ - break; - default: - /* all other messages are unexpected and fatal */ - LOG(("Unhandled message type %d", event->type)); - assert(0); + break; } /* if there are no active fetches remaining begin post parse diff --git a/riscos/theme_install.c b/riscos/theme_install.c index 0d436dce8..82377facf 100644 --- a/riscos/theme_install.c +++ b/riscos/theme_install.c @@ -89,8 +89,6 @@ nserror theme_install_callback(hlcache_handle *handle, int author_indent = 0; switch (event->type) { - case CONTENT_MSG_READY: - break; case CONTENT_MSG_DONE: { @@ -129,11 +127,7 @@ nserror theme_install_callback(hlcache_handle *handle, warn_user(event->data.error, 0); break; - case CONTENT_MSG_STATUS: - break; - default: - assert(0); break; } From b1e6c63a2f00a84c1774d7a5165a7518d8bd7b4d Mon Sep 17 00:00:00 2001 From: Daniel Silverstone Date: Sun, 5 Jan 2014 15:50:23 +0000 Subject: [PATCH 050/773] Rewrite form_successful_controls() to use the DOM. This stops image inputs from working temporarily, but makes inputs inside display:none work correctly. As such, this is a net-win. --- render/form.c | 514 +++++++++++++++++++++++++++++++++++++++++++- render/form.h | 3 + utils/corestrings.c | 36 ++++ utils/corestrings.h | 15 ++ 4 files changed, 563 insertions(+), 5 deletions(-) diff --git a/render/form.c b/render/form.c index 9ac52392e..48648b103 100644 --- a/render/form.c +++ b/render/form.c @@ -88,7 +88,7 @@ static plot_font_style_t plot_fstyle_entry = { }; static char *form_acceptable_charset(struct form *form); -static char *form_encode_item(const char *item, const char *charset, +static char *form_encode_item(const char *item, uint32_t len, const char *charset, const char *fallback); static void form_select_menu_clicked(struct form_control *control, int x, int y); @@ -320,6 +320,509 @@ bool form_add_option(struct form_control *control, char *value, char *text, } +/** + * Identify 'successful' controls via the DOM. + * + * All text strings in the successful controls list will be in the charset most + * appropriate for submission. Therefore, no utf8_to_* processing should be + * performed upon them. + * + * \todo The chosen charset needs to be made available such that it can be + * included in the submission request (e.g. in the fetch's Content-Type header) + * + * \param form form to search for successful controls + * \param submit_button control used to submit the form, if any + * \param successful_controls updated to point to linked list of + * fetch_multipart_data, 0 if no controls + * \return true on success, false on memory exhaustion + * + * See HTML 4.01 section 17.13.2. + */ +bool form_successful_controls_dom(struct form *_form, + struct form_control *_submit_button, + struct fetch_multipart_data **successful_controls) +{ + dom_html_form_element *form = _form->node; + dom_html_element *submit_button = (_submit_button != NULL) ? _submit_button->node : NULL; + dom_html_collection *form_elements = NULL; + dom_html_options_collection *options = NULL; + dom_node *form_element = NULL, *option_element = NULL; + dom_exception err; + dom_string *nodename = NULL, *inputname = NULL, *inputvalue = NULL, *inputtype = NULL; + struct fetch_multipart_data sentinel, *last_success, *success_new; + bool had_submit = false, element_disabled; + char *charset, *rawfile_temp = NULL, *basename; + uint32_t index, element_count; + + last_success = &sentinel; + sentinel.next = NULL; + + LOG(("XYZZY: Yay, let's look for a form")); + + /** \todo Replace this call with something DOMish */ + charset = form_acceptable_charset(_form); + if (charset == NULL) { + LOG(("failed to find charset")); + return false; + } + +#define ENCODE_ITEM(i) (((i) == NULL) ? ( \ + form_encode_item("", 0, charset, _form->document_charset) \ + ):( \ + form_encode_item(dom_string_data(i), dom_string_byte_length(i), \ + charset, _form->document_charset) \ + )) + + err = dom_html_form_element_get_elements(form, &form_elements); + + if (err != DOM_NO_ERR) { + LOG(("Could not get form elements")); + goto dom_no_memory; + } + + LOG(("Reffed %p", form_elements)); + + err = dom_html_collection_get_length(form_elements, &element_count); + + if (err != DOM_NO_ERR) { + LOG(("Could not get form element count")); + goto dom_no_memory; + } + + for (index = 0; index < element_count; index++) { + if (form_element != NULL) { + LOG(("Unreffed %p", form_element)); + dom_node_unref(form_element); + form_element = NULL; + } + if (nodename != NULL) { + dom_string_unref(nodename); + nodename = NULL; + } + if (inputname != NULL) { + dom_string_unref(inputname); + inputname = NULL; + } + if (inputvalue != NULL) { + dom_string_unref(inputvalue); + inputvalue = NULL; + } + if (inputtype != NULL) { + dom_string_unref(inputtype); + inputtype = NULL; + } + if (options != NULL) { + dom_html_options_collection_unref(options); + options = NULL; + } + err = dom_html_collection_item(form_elements, + index, &form_element); + if (err != DOM_NO_ERR) { + LOG(("Could not retrieve form element %d", index)); + goto dom_no_memory; + } + LOG(("Reffed %p", form_element)); + /* Form elements are one of: + * HTMLInputElement + * HTMLTextAreaElement + * HTMLSelectElement + */ + err = dom_node_get_node_name(form_element, &nodename); + if (err != DOM_NO_ERR) { + LOG(("Could not get node name")); + goto dom_no_memory; + } + LOG(("Found a node(%p): `%*s`", nodename, + dom_string_byte_length(nodename), + dom_string_data(nodename))); + if (dom_string_isequal(nodename, corestring_dom_TEXTAREA)) { + err = dom_html_text_area_element_get_disabled( + (dom_html_text_area_element *)form_element, + &element_disabled); + if (err != DOM_NO_ERR) { + LOG(("Could not get text area disabled property")); + goto dom_no_memory; + } + err = dom_html_text_area_element_get_name( + (dom_html_text_area_element *)form_element, + &inputname); + if (err != DOM_NO_ERR) { + LOG(("Could not get text area name property")); + goto dom_no_memory; + } + } else if (dom_string_isequal(nodename, corestring_dom_SELECT)) { + err = dom_html_select_element_get_disabled( + (dom_html_select_element *)form_element, + &element_disabled); + if (err != DOM_NO_ERR) { + LOG(("Could not get select disabled property")); + goto dom_no_memory; + } + err = dom_html_select_element_get_name( + (dom_html_select_element *)form_element, + &inputname); + if (err != DOM_NO_ERR) { + LOG(("Could not get select name property")); + goto dom_no_memory; + } + } else if (dom_string_isequal(nodename, corestring_dom_INPUT)) { + err = dom_html_input_element_get_disabled( + (dom_html_input_element *)form_element, + &element_disabled); + if (err != DOM_NO_ERR) { + LOG(("Could not get input disabled property")); + goto dom_no_memory; + } + err = dom_html_input_element_get_name( + (dom_html_input_element *)form_element, + &inputname); + if (err != DOM_NO_ERR) { + LOG(("Could not get input name property")); + goto dom_no_memory; + } + } else if (dom_string_isequal(nodename, corestring_dom_BUTTON)) { + /* It was a button, no fair */ + continue; + } else { + /* Unknown element type came through! */ + LOG(("Unknown element type: %*s", + dom_string_byte_length(nodename), + dom_string_data(nodename))); + goto dom_no_memory; + } + if (element_disabled) + continue; + if (inputname == NULL) + continue; + + if (dom_string_isequal(nodename, corestring_dom_TEXTAREA)) { + err = dom_html_text_area_element_get_value( + (dom_html_text_area_element *)form_element, + &inputvalue); + if (err != DOM_NO_ERR) { + LOG(("Could not get text area content")); + goto dom_no_memory; + } + } else if (dom_string_isequal(nodename, corestring_dom_SELECT)) { + uint32_t options_count, option_index; + err = dom_html_select_element_get_options( + (dom_html_select_element *)form_element, + &options); + if (err != DOM_NO_ERR) { + LOG(("Could not get select options collection")); + goto dom_no_memory; + } + err = dom_html_options_collection_get_length( + options, &options_count); + if (err != DOM_NO_ERR) { + LOG(("Could not get select options collection length")); + goto dom_no_memory; + } + for(option_index = 0; option_index < options_count; + ++option_index) { + bool selected; + if (option_element != NULL) { + dom_node_unref(option_element); + option_element = NULL; + } + if (inputvalue != NULL) { + dom_string_unref(inputvalue); + inputvalue = NULL; + } + err = dom_html_options_collection_item( + options, option_index, &option_element); + if (err != DOM_NO_ERR) { + LOG(("Could not get options item %d", option_index)); + goto dom_no_memory; + } + err = dom_html_option_element_get_selected( + (dom_html_option_element *)option_element, + &selected); + if (err != DOM_NO_ERR) { + LOG(("Could not get option selected property")); + goto dom_no_memory; + } + if (!selected) + continue; + err = dom_html_option_element_get_value( + (dom_html_option_element *)option_element, + &inputvalue); + if (err != DOM_NO_ERR) { + LOG(("Could not get option value")); + goto dom_no_memory; + } + + success_new = calloc(1, sizeof(*success_new)); + if (success_new == NULL) { + LOG(("Could not allocate data for option")); + goto dom_no_memory; + } + + last_success->next = success_new; + last_success = success_new; + + success_new->name = ENCODE_ITEM(inputname); + if (success_new->name == NULL) { + LOG(("Could not encode name for option")); + goto dom_no_memory; + } + success_new->value = ENCODE_ITEM(inputvalue); + if (success_new->value == NULL) { + LOG(("Could not encode value for option")); + goto dom_no_memory; + } + } + continue; + } else if (dom_string_isequal(nodename, corestring_dom_INPUT)) { + /* Things to consider here */ + /* Buttons -- only if the successful control */ + /* radio and checkbox -- only if selected */ + /* file -- also get the rawfile */ + /* everything else -- just value */ + err = dom_html_input_element_get_type( + (dom_html_input_element *) form_element, + &inputtype); + if (err != DOM_NO_ERR) { + LOG(("Could not get input element type")); + goto dom_no_memory; + } + if (dom_string_caseless_isequal( + inputtype, corestring_dom_submit)) { + LOG(("Examining submit button")); + if (submit_button == NULL && !had_submit) + /* no button used, and first submit + * node found, so use it + */ + had_submit = true; + else if ((dom_node *)submit_button != + (dom_node *)form_element) + continue; + err = dom_html_input_element_get_value( + (dom_html_input_element *)form_element, + &inputvalue); + if (err != DOM_NO_ERR) { + LOG(("Could not get submit button value")); + goto dom_no_memory; + } + /* Drop through to report the successful button */ + } else if (dom_string_caseless_isequal( + inputtype, corestring_dom_image)) { + /* We *ONLY* use an image input if it was the + * thing which activated us + */ + LOG(("Examining image button")); + if ((dom_node *)submit_button != + (dom_node *)form_element) + continue; + + basename = ENCODE_ITEM(inputname); + + success_new = calloc(1, sizeof(*success_new)); + if (success_new == NULL) { + free(basename); + LOG(("Could not allocate data for image.x")); + goto dom_no_memory; + } + + last_success->next = success_new; + last_success = success_new; + + success_new->name = malloc(strlen(basename) + 3); + if (success_new->name == NULL) { + free(basename); + LOG(("Could not allocate name for image.x")); + goto dom_no_memory; + } + success_new->value = malloc(20); + if (success_new->value == NULL) { + free(basename); + LOG(("Could not allocate value for image.x")); + goto dom_no_memory; + } + sprintf(success_new->name, "%s.x", basename); + /** \todo Store this on the node and + * retrieve it here + */ + sprintf(success_new->value, "%d", 0); + + success_new = calloc(1, sizeof(*success_new)); + if (success_new == NULL) { + free(basename); + LOG(("Could not allocate data for image.y")); + goto dom_no_memory; + } + + last_success->next = success_new; + last_success = success_new; + + success_new->name = malloc(strlen(basename) + 3); + if (success_new->name == NULL) { + free(basename); + LOG(("Could not allocate name for image.y")); + goto dom_no_memory; + } + success_new->value = malloc(20); + if (success_new->value == NULL) { + free(basename); + LOG(("Could not allocate value for image.y")); + goto dom_no_memory; + } + sprintf(success_new->name, "%s.y", basename); + /** \todo Store this on the node and + * retrieve it here + */ + sprintf(success_new->value, "%d", 0); + free(basename); + continue; + } else if (dom_string_caseless_isequal( + inputtype, corestring_dom_radio) || + dom_string_caseless_isequal( + inputtype, corestring_dom_checkbox)) { + LOG(("Examining radio or checkbox")); + err = dom_html_input_element_get_value( + (dom_html_input_element *)form_element, + &inputvalue); + if (err != DOM_NO_ERR) { + LOG(("Could not get input element value")); + goto dom_no_memory; + } + if (inputvalue == NULL) + inputvalue = dom_string_ref( + corestring_dom_on); + /* Fall through to simple allocation */ + } else if (dom_string_caseless_isequal( + inputtype, corestring_dom_file)) { + LOG(("Examining file input")); + err = dom_html_input_element_get_value( + (dom_html_input_element *)form_element, + &inputvalue); + if (err != DOM_NO_ERR) { + LOG(("Could not get file value")); + goto dom_no_memory; + } + err = dom_node_get_user_data( + form_element, + corestring_dom___ns_key_file_name_node_data, + &rawfile_temp); + if (err != DOM_NO_ERR) { + LOG(("Could not get file rawname")); + goto dom_no_memory; + } + rawfile_temp = strdup(rawfile_temp != NULL ? + rawfile_temp : + ""); + if (rawfile_temp == NULL) { + LOG(("Could not copy file rawname")); + goto dom_no_memory; + } + /* Fall out to the allocation */ + } else if (dom_string_caseless_isequal( + inputtype, corestring_dom_reset) || + dom_string_caseless_isequal( + inputtype, corestring_dom_button)) { + /* Skip these */ + LOG(("Skipping RESET and BUTTON")); + continue; + } else { + /* Everything else is treated as text values */ + LOG(("Retrieving generic input text")); + err = dom_html_input_element_get_value( + (dom_html_input_element *)form_element, + &inputvalue); + if (err != DOM_NO_ERR) { + LOG(("Could not get input value")); + goto dom_no_memory; + } + /* Fall out to the allocation */ + } + } + + success_new = calloc(1, sizeof(*success_new)); + if (success_new == NULL) { + LOG(("Could not allocate data for generic")); + goto dom_no_memory; + } + + last_success->next = success_new; + last_success = success_new; + + success_new->name = ENCODE_ITEM(inputname); + if (success_new->name == NULL) { + LOG(("Could not encode name for generic")); + goto dom_no_memory; + } + success_new->value = ENCODE_ITEM(inputvalue); + if (success_new->value == NULL) { + LOG(("Could not encode value for generic")); + goto dom_no_memory; + } + if (rawfile_temp != NULL) { + success_new->file = true; + success_new->rawfile = rawfile_temp; + rawfile_temp = NULL; + } + } + + free(charset); + if (form_element != NULL) { + LOG(("Unreffed %p", form_element)); + dom_node_unref(form_element); + } + if (form_elements != NULL) { + LOG(("Unreffed %p", form_elements)); + dom_html_collection_unref(form_elements); + } + if (nodename != NULL) + dom_string_unref(nodename); + if (inputname != NULL) + dom_string_unref(inputname); + if (inputvalue != NULL) + dom_string_unref(inputvalue); + if (options != NULL) + dom_html_options_collection_unref(options); + if (option_element != NULL) + dom_node_unref(option_element); + if (inputtype != NULL) + dom_string_unref(inputtype); + if (rawfile_temp != NULL) + free(rawfile_temp); + *successful_controls = sentinel.next; + + for (success_new = *successful_controls; success_new != NULL; + success_new = success_new->next) { + LOG(("%p -> %s=%s", success_new, success_new->name, success_new->value)); + LOG(("%p -> file=%s rawfile=%s", success_new, + success_new->file ? "yes" : "no", success_new->rawfile)); + } + return true; + +dom_no_memory: + free(charset); + fetch_multipart_data_destroy(sentinel.next); + + if (form_elements != NULL) + dom_html_collection_unref(form_elements); + if (form_element != NULL) + dom_node_unref(form_element); + if (nodename != NULL) + dom_string_unref(nodename); + if (inputname != NULL) + dom_string_unref(inputname); + if (inputvalue != NULL) + dom_string_unref(inputvalue); + if (options != NULL) + dom_html_options_collection_unref(options); + if (option_element != NULL) + dom_node_unref(option_element); + if (inputtype != NULL) + dom_string_unref(inputtype); + if (rawfile_temp != NULL) + free(rawfile_temp); + + return false; +} +#undef ENCODE_ITEM + /** * Identify 'successful' controls. * @@ -356,7 +859,7 @@ bool form_successful_controls(struct form *form, if (charset == NULL) return false; -#define ENCODE_ITEM(i) form_encode_item((i), charset, form->document_charset) +#define ENCODE_ITEM(i) form_encode_item((i), 0, charset, form->document_charset) for (control = form->controls; control; control = control->next) { /* ignore disabled controls */ @@ -812,12 +1315,13 @@ char *form_acceptable_charset(struct form *form) * \todo Return charset used? * * \param item String to convert + * \param len Length of string to convert * \param charset Destination charset * \param fallback Fallback charset (may be NULL), * used iff converting to charset fails * \return Pointer to converted string (on heap, caller frees), or NULL */ -char *form_encode_item(const char *item, const char *charset, +char *form_encode_item(const char *item, uint32_t len, const char *charset, const char *fallback) { utf8_convert_ret err; @@ -833,7 +1337,7 @@ char *form_encode_item(const char *item, const char *charset, if (err == UTF8_CONVERT_BADENC) { /* charset not understood, try without transliteration */ snprintf(cset, sizeof cset, "%s", charset); - err = utf8_to_enc(item, cset, 0, &ret); + err = utf8_to_enc(item, cset, len, &ret); if (err == UTF8_CONVERT_BADENC) { /* nope, try fallback charset (if any) */ @@ -1490,7 +1994,7 @@ void form_submit(nsurl *page_url, struct browser_window *target, assert(form != NULL); - if (form_successful_controls(form, submit_button, &success) == false) { + if (form_successful_controls_dom(form, submit_button, &success) == false) { warn_user("NoMemory", 0); return; } diff --git a/render/form.h b/render/form.h index b538c3b33..e65206d33 100644 --- a/render/form.h +++ b/render/form.h @@ -159,6 +159,9 @@ bool form_add_option(struct form_control *control, char *value, char *text, bool form_successful_controls(struct form *form, struct form_control *submit_button, struct fetch_multipart_data **successful_controls); +bool form_successful_controls_dom(struct form *form, + struct form_control *submit_button, + struct fetch_multipart_data **successful_controls); bool form_open_select_menu(void *client_data, struct form_control *control, diff --git a/utils/corestrings.c b/utils/corestrings.c index 8623d127b..9050ffe48 100644 --- a/utils/corestrings.c +++ b/utils/corestrings.c @@ -232,6 +232,16 @@ dom_string *corestring_dom_volumechange; dom_string *corestring_dom_vspace; dom_string *corestring_dom_waiting; dom_string *corestring_dom_width; +dom_string *corestring_dom_BUTTON; +dom_string *corestring_dom_INPUT; +dom_string *corestring_dom_SELECT; +dom_string *corestring_dom_TEXTAREA; +dom_string *corestring_dom_button; +dom_string *corestring_dom_image; +dom_string *corestring_dom_radio; +dom_string *corestring_dom_checkbox; +dom_string *corestring_dom_file; +dom_string *corestring_dom_on; dom_string *corestring_dom___ns_key_libcss_node_data; dom_string *corestring_dom___ns_key_file_name_node_data; @@ -463,6 +473,19 @@ void corestrings_fini(void) CSS_DOM_STRING_UNREF(vspace); CSS_DOM_STRING_UNREF(waiting); CSS_DOM_STRING_UNREF(width); + /* DOM node names, not really CSS */ + CSS_DOM_STRING_UNREF(BUTTON); + CSS_DOM_STRING_UNREF(INPUT); + CSS_DOM_STRING_UNREF(SELECT); + CSS_DOM_STRING_UNREF(TEXTAREA); + /* DOM input types, not really CSS */ + CSS_DOM_STRING_UNREF(button); + CSS_DOM_STRING_UNREF(image); + CSS_DOM_STRING_UNREF(radio); + CSS_DOM_STRING_UNREF(checkbox); + CSS_DOM_STRING_UNREF(file); + CSS_DOM_STRING_UNREF(on); + /* DOM userdata keys, not really CSS */ CSS_DOM_STRING_UNREF(__ns_key_libcss_node_data); CSS_DOM_STRING_UNREF(__ns_key_file_name_node_data); #undef CSS_DOM_STRING_UNREF @@ -725,6 +748,19 @@ nserror corestrings_init(void) CSS_DOM_STRING_INTERN(vspace); CSS_DOM_STRING_INTERN(waiting); CSS_DOM_STRING_INTERN(width); + /* DOM node names, not really CSS */ + CSS_DOM_STRING_INTERN(BUTTON); + CSS_DOM_STRING_INTERN(INPUT); + CSS_DOM_STRING_INTERN(SELECT); + CSS_DOM_STRING_INTERN(TEXTAREA); + /* DOM input types, not really CSS */ + CSS_DOM_STRING_INTERN(button); + CSS_DOM_STRING_INTERN(image); + CSS_DOM_STRING_INTERN(radio); + CSS_DOM_STRING_INTERN(checkbox); + CSS_DOM_STRING_INTERN(file); + CSS_DOM_STRING_INTERN(on); + /* DOM userdata keys, not really CSS */ CSS_DOM_STRING_INTERN(__ns_key_libcss_node_data); CSS_DOM_STRING_INTERN(__ns_key_file_name_node_data); #undef CSS_DOM_STRING_INTERN diff --git a/utils/corestrings.h b/utils/corestrings.h index a8c345946..839d86522 100644 --- a/utils/corestrings.h +++ b/utils/corestrings.h @@ -238,6 +238,21 @@ extern struct dom_string *corestring_dom_volumechange; extern struct dom_string *corestring_dom_vspace; extern struct dom_string *corestring_dom_waiting; extern struct dom_string *corestring_dom_width; +/* DOM node types */ +extern struct dom_string *corestring_dom_BUTTON; +extern struct dom_string *corestring_dom_INPUT; +extern struct dom_string *corestring_dom_SELECT; +extern struct dom_string *corestring_dom_TEXTAREA; +/* DOM input node types */ +extern struct dom_string *corestring_dom_button; +/* extern struct dom_string *corestring_dom_submit; */ +/* extern struct dom_string *corestring_dom_reset; */ +extern struct dom_string *corestring_dom_image; +extern struct dom_string *corestring_dom_radio; +extern struct dom_string *corestring_dom_checkbox; +extern struct dom_string *corestring_dom_file; +extern struct dom_string *corestring_dom_on; +/* DOM userdata keys */ extern struct dom_string *corestring_dom___ns_key_libcss_node_data; extern struct dom_string *corestring_dom___ns_key_file_name_node_data; From d8ad3b8e7893630d3866bc56c90f6f7556ab1740 Mon Sep 17 00:00:00 2001 From: Rob Kendrick Date: Sun, 5 Jan 2014 16:01:03 +0000 Subject: [PATCH 051/773] Add new gui entry point for file open dialogue requests --- amiga/gui.c | 12 ++++++++++-- atari/gui.c | 7 +++++++ beos/gui.cpp | 8 ++++++++ cocoa/gui.m | 7 +++++++ desktop/gui.h | 3 ++- gtk/gui.c | 9 ++++++--- monkey/browser.c | 7 +++++++ riscos/gui.c | 8 ++++++++ 8 files changed, 55 insertions(+), 6 deletions(-) diff --git a/amiga/gui.c b/amiga/gui.c index 103d3a1e8..76185e949 100644 --- a/amiga/gui.c +++ b/amiga/gui.c @@ -4232,8 +4232,8 @@ static void ami_gui_window_update_box_deferred(struct gui_window *g, bool draw) static bool ami_gui_window_update_box_deferred_check(struct MinList *deferred_rects, const struct rect *new_rect) { - struct nsObject *node; - struct nsObject *nnode; +struct nsObject *node; +struct nsObject *nnode; struct rect *rect; if(IsMinListEmpty(deferred_rects)) return true; @@ -5137,3 +5137,11 @@ void ami_gui_splash_close(Object *win_obj) { if(win_obj) DisposeObject(win_obj); } + +void gui_file_gadget_open(struct browser_window *bw, hlcache_handle *hl, + struct form_control *gadget) +{ + LOG(("File open dialog rquest for %p/%p", bw, gadget)); + /* browser_window_set_gadget_filename(bw, gadget, "filename"); */ +} + diff --git a/atari/gui.c b/atari/gui.c index e52a6589c..badb4206c 100644 --- a/atari/gui.c +++ b/atari/gui.c @@ -1098,6 +1098,13 @@ static void gui_init2(int argc, char** argv) toolbar_init(); } +void gui_file_gadget_open(struct browser_window *bw, hlcache_handle *hl, + struct form_control *gadget) +{ + LOG(("File open dialog rquest for %p/%p", bw, gadget)); + /* browser_window_set_gadget_filename(bw, gadget, "filename"); */ +} + /* #define WITH_DBG_LOGFILE 1 */ /** Entry point from OS. * diff --git a/beos/gui.cpp b/beos/gui.cpp index 204c11caf..6c9d1ed12 100644 --- a/beos/gui.cpp +++ b/beos/gui.cpp @@ -1164,3 +1164,11 @@ bool path_add_part(char *path, int length, const char *newpart) return true; } + +void gui_file_gadget_open(struct browser_window *bw, hlcache_handle *hl, + struct form_control *gadget) +{ + LOG(("File open dialog rquest for %p/%p", bw, gadget)); + /* browser_window_set_gadget_filename(bw, gadget, "filename"); */ +} + diff --git a/cocoa/gui.m b/cocoa/gui.m index b2ff01dc0..3804ad249 100644 --- a/cocoa/gui.m +++ b/cocoa/gui.m @@ -324,3 +324,10 @@ void gui_401login_open(nsurl *url, const char *realm, cb( false, cbpw ); } +void gui_file_gadget_open(struct browser_window *bw, hlcache_handle *hl, + struct form_control *gadget) +{ + LOG(("File open dialog rquest for %p/%p", bw, gadget)); + /* browser_window_set_gadget_filename(bw, gadget, "filename"); */ +} + diff --git a/desktop/gui.h b/desktop/gui.h index 9d35e1727..4bbf08718 100644 --- a/desktop/gui.h +++ b/desktop/gui.h @@ -116,7 +116,8 @@ void gui_drag_save_selection(struct gui_window *g, const char *selection); void gui_start_selection(struct gui_window *g); void gui_clear_selection(struct gui_window *g); - +void gui_file_gadget_open(struct browser_window *bw, hlcache_handle *hl, + struct form_control *gadget); /** * Core asks front end for clipboard contents. diff --git a/gtk/gui.c b/gtk/gui.c index 649c4a239..0f815a7a2 100644 --- a/gtk/gui.c +++ b/gtk/gui.c @@ -681,9 +681,12 @@ void gui_quit(void) gtk_fetch_filetype_fin(); } - - - +void gui_file_gadget_open(struct browser_window *bw, hlcache_handle *hl, + struct form_control *gadget) +{ + LOG(("File open dialog rquest for %p/%p", bw, gadget)); + /* browser_window_set_gadget_filename(bw, gadget, "plinth"); */ +} static void nsgtk_select_menu_clicked(GtkCheckMenuItem *checkmenuitem, gpointer user_data) diff --git a/monkey/browser.c b/monkey/browser.c index 09ecf4b11..47fb07bc1 100644 --- a/monkey/browser.c +++ b/monkey/browser.c @@ -390,6 +390,13 @@ gui_window_save_link(struct gui_window *g, const char *url, g->win_num, url, title); } +void gui_file_gadget_open(struct browser_window *bw, hlcache_handle *hl, + struct form_control *gadget) +{ + LOG(("File open dialog rquest for %p/%p", bw, gadget)); + /* browser_window_set_gadget_filename(bw, gadget, "filename"); */ +} + /**** Handlers ****/ diff --git a/riscos/gui.c b/riscos/gui.c index bb1a318de..0c8ebecc7 100644 --- a/riscos/gui.c +++ b/riscos/gui.c @@ -2423,3 +2423,11 @@ bool path_add_part(char *path, int length, const char *newpart) return true; } + +void gui_file_gadget_open(struct browser_window *bw, hlcache_handle *hl, + struct form_control *gadget) +{ + LOG(("File open dialog rquest for %p/%p", bw, gadget)); + /* browser_window_set_gadget_filename(bw, gadget, "filename"); */ +} + From 0d7f1cfc93008add9a082c2c54de8427ac0f1786 Mon Sep 17 00:00:00 2001 From: Rob Kendrick Date: Sun, 5 Jan 2014 16:04:35 +0000 Subject: [PATCH 052/773] Add infrastructure for calling front ends to set file gadget filenames via clicking in addition to drag-and-drop --- content/content.h | 7 ++++- desktop/browser.c | 17 ++++++++++- desktop/browser.h | 3 ++ render/html.c | 70 ++++++++++++++++++++++++++------------------ render/html.h | 2 ++ render/html_object.c | 1 + 6 files changed, 69 insertions(+), 31 deletions(-) diff --git a/content/content.h b/content/content.h index 467fa6055..91a6ae9df 100644 --- a/content/content.h +++ b/content/content.h @@ -83,7 +83,8 @@ typedef enum { CONTENT_MSG_POINTER, /**< Wants a specific mouse pointer set */ CONTENT_MSG_SELECTION, /**< A selection made or cleared */ CONTENT_MSG_CARET, /**< Caret movement / hiding */ - CONTENT_MSG_DRAG /**< A drag started or ended */ + CONTENT_MSG_DRAG, /**< A drag started or ended */ + CONTENT_MSG_GADGETCLICK/**< A gadget has been clicked on (mainly for file) */ } content_msg; /** RFC5988 metadata link */ @@ -190,6 +191,10 @@ union content_msg_data { } type; const struct rect *rect; } drag; + /** CONTENT_MSG_GADGETCLICK - User clicked on a form gadget */ + struct { + struct form_control *gadget; + } gadget_click; }; /** parameters to content redraw */ diff --git a/desktop/browser.c b/desktop/browser.c index 83b06bac5..3d279f727 100644 --- a/desktop/browser.c +++ b/desktop/browser.c @@ -661,6 +661,13 @@ bool browser_window_drop_file_at_point(struct browser_window *bw, return false; } +void browser_window_set_gadget_filename(struct browser_window *bw, + struct form_control *gadget, const char *fn) +{ + html_set_file_gadget_filename(bw->current_content, + gadget, fn); +} + /* exported interface, documented in browser.h */ void browser_window_debug_dump(struct browser_window *bw, FILE *f) { @@ -1162,7 +1169,7 @@ static void browser_window_convert_to_download(struct browser_window *bw, /** - * Callback for fetchcache() for browser window fetches. + * Callback handler for content event messages. */ static nserror browser_window_callback(hlcache_handle *c, @@ -1555,6 +1562,14 @@ static nserror browser_window_callback(hlcache_handle *c, event->data.selection.read_only); break; + case CONTENT_MSG_GADGETCLICK: + if (event->data.gadget_click.gadget->type == GADGET_FILE) { + gui_file_gadget_open(bw, c, + event->data.gadget_click.gadget); + } + + break; + default: break; } diff --git a/desktop/browser.h b/desktop/browser.h index ee55e72c4..0ca2e009b 100644 --- a/desktop/browser.h +++ b/desktop/browser.h @@ -173,6 +173,9 @@ bool browser_window_scroll_at_point(struct browser_window *bw, bool browser_window_drop_file_at_point(struct browser_window *bw, int x, int y, char *file); +void browser_window_set_gadget_filename(struct browser_window *bw, + struct form_control *gadget, const char *fn); + void browser_window_refresh_url_bar(struct browser_window *bw, nsurl *url, lwc_string *frag); diff --git a/render/html.c b/render/html.c index c1e831571..103dec14f 100644 --- a/render/html.c +++ b/render/html.c @@ -1729,6 +1729,46 @@ static void html__dom_user_data_handler(dom_node_operation operation, } } +static void html__set_file_gadget_filename(struct content *c, + struct form_control *gadget, const char *fn) +{ + utf8_convert_ret ret; + char *utf8_fn, *oldfile = NULL; + html_content *html = (html_content *)c; + struct box *file_box = gadget->box; + + ret = utf8_from_local_encoding(fn,0, &utf8_fn); + if (ret != UTF8_CONVERT_OK) { + assert(ret != UTF8_CONVERT_BADENC); + LOG(("utf8_from_local_encoding failed")); + /* Load was for us - just no memory */ + return; + } + + form_gadget_update_value(html, gadget, utf8_fn); + + /* corestring_dom___ns_key_file_name_node_data */ + LOG(("XYZZY: Setting userdata to %s", fn)); + if (dom_node_set_user_data((dom_node *)file_box->gadget->node, + corestring_dom___ns_key_file_name_node_data, + strdup(fn), html__dom_user_data_handler, + &oldfile) == DOM_NO_ERR) { + LOG(("XYZZY: Userdata used to be %s", oldfile)); + if (oldfile != NULL) + free(oldfile); + } + + /* Redraw box. */ + html__redraw_a_box(html, file_box); +} + +void html_set_file_gadget_filename(struct hlcache_handle *hl, + struct form_control *gadget, const char *fn) +{ + return html__set_file_gadget_filename(hlcache_handle_get_content(hl), + gadget, fn); +} + /** * Drop a file onto a content at a particular point, or determine if a file * may be dropped onto the content at given point. @@ -1794,35 +1834,7 @@ static bool html_drop_file_at_point(struct content *c, int x, int y, char *file) /* Handle the drop */ if (file_box) { /* File dropped on file input */ - utf8_convert_ret ret; - char *utf8_fn, *oldfile = NULL; - - ret = utf8_from_local_encoding(file, 0, - &utf8_fn); - if (ret != UTF8_CONVERT_OK) { - /* A bad encoding should never happen */ - assert(ret != UTF8_CONVERT_BADENC); - LOG(("utf8_from_local_encoding failed")); - /* Load was for us - just no memory */ - return true; - } - - /* Found: update form input */ - form_gadget_update_value(html, file_box->gadget, utf8_fn); - - /* corestring_dom___ns_key_file_name_node_data */ - LOG(("XYZZY: Setting userdata to %s", file)); - if (dom_node_set_user_data((dom_node *)file_box->gadget->node, - corestring_dom___ns_key_file_name_node_data, - strdup(file), html__dom_user_data_handler, - &oldfile) == DOM_NO_ERR) { - LOG(("XYZZY: Userdata used to be %s", oldfile)); - if (oldfile != NULL) - free(oldfile); - } - - /* Redraw box. */ - html__redraw_a_box(html, file_box); + html__set_file_gadget_filename(c, box->gadget, file); } else { /* File dropped on text input */ diff --git a/render/html.h b/render/html.h index 162541d72..7ca75e713 100644 --- a/render/html.h +++ b/render/html.h @@ -178,6 +178,8 @@ struct content_html_frames *html_get_frameset(struct hlcache_handle *h); struct content_html_iframe *html_get_iframe(struct hlcache_handle *h); nsurl *html_get_base_url(struct hlcache_handle *h); const char *html_get_base_target(struct hlcache_handle *h); +void html_set_file_gadget_filename(struct hlcache_handle *hl, + struct form_control *gadget, const char *fn); /** * Retrieve stylesheets used by HTML document diff --git a/render/html_object.c b/render/html_object.c index 7b34c4a7e..15ca7ed3b 100644 --- a/render/html_object.c +++ b/render/html_object.c @@ -368,6 +368,7 @@ html_object_callback(hlcache_handle *object, case CONTENT_MSG_SAVELINK: case CONTENT_MSG_POINTER: + case CONTENT_MSG_GADGETCLICK: /* These messages are for browser window layer. * we're not interested, so pass them on. */ content_broadcast(&c->base, event->type, event->data); From 6bf609a1a4b313d49e5a657b2cf421c092aa1414 Mon Sep 17 00:00:00 2001 From: Daniel Silverstone Date: Sun, 5 Jan 2014 16:14:17 +0000 Subject: [PATCH 053/773] Support image inputs --- render/form.c | 24 ++++++++++------ render/form.h | 5 ++++ render/html.c | 2 +- render/html_interaction.c | 60 +++++++++++++++++++++++++++++++++++++-- utils/corestrings.c | 3 ++ utils/corestrings.h | 1 + 6 files changed, 84 insertions(+), 11 deletions(-) diff --git a/render/form.c b/render/form.c index 48648b103..b55ec171c 100644 --- a/render/form.c +++ b/render/form.c @@ -353,6 +353,7 @@ bool form_successful_controls_dom(struct form *_form, bool had_submit = false, element_disabled; char *charset, *rawfile_temp = NULL, *basename; uint32_t index, element_count; + struct image_input_coords *coords; last_success = &sentinel; sentinel.next = NULL; @@ -615,6 +616,19 @@ bool form_successful_controls_dom(struct form *_form, (dom_node *)form_element) continue; + err = dom_node_get_user_data( + form_element, + corestring_dom___ns_key_image_coords_node_data, + &coords); + if (err != DOM_NO_ERR) { + LOG(("Could not get image XY data")); + goto dom_no_memory; + } + if (coords == NULL) { + LOG(("No XY data on the image input")); + goto dom_no_memory; + } + basename = ENCODE_ITEM(inputname); success_new = calloc(1, sizeof(*success_new)); @@ -640,10 +654,7 @@ bool form_successful_controls_dom(struct form *_form, goto dom_no_memory; } sprintf(success_new->name, "%s.x", basename); - /** \todo Store this on the node and - * retrieve it here - */ - sprintf(success_new->value, "%d", 0); + sprintf(success_new->value, "%d", coords->x); success_new = calloc(1, sizeof(*success_new)); if (success_new == NULL) { @@ -668,10 +679,7 @@ bool form_successful_controls_dom(struct form *_form, goto dom_no_memory; } sprintf(success_new->name, "%s.y", basename); - /** \todo Store this on the node and - * retrieve it here - */ - sprintf(success_new->value, "%d", 0); + sprintf(success_new->value, "%d", coords->y); free(basename); continue; } else if (dom_string_caseless_isequal( diff --git a/render/form.h b/render/form.h index e65206d33..78211ee19 100644 --- a/render/form.h +++ b/render/form.h @@ -134,6 +134,11 @@ struct form_option { struct form_option* next; }; +struct image_input_coords { + int x; + int y; +}; + /** * Called by the select menu when it wants an area to be redrawn. The * coordinates are menu origin relative. diff --git a/render/html.c b/render/html.c index 04b2fda18..25147a0a0 100644 --- a/render/html.c +++ b/render/html.c @@ -1732,7 +1732,7 @@ static void html__dom_user_data_handler(dom_node_operation operation, char *oldfile; char *data = (char *)_data; - if (!dom_string_isequal(corestring_dom___ns_key_libcss_node_data, + if (!dom_string_isequal(corestring_dom___ns_key_file_name_node_data, key) || data == NULL) { return; } diff --git a/render/html_interaction.c b/render/html_interaction.c index f18daebd4..5d69c987f 100644 --- a/render/html_interaction.c +++ b/render/html_interaction.c @@ -45,8 +45,10 @@ #include "render/imagemap.h" #include "render/search.h" #include "javascript/js.h" +#include "utils/corestrings.h" #include "utils/messages.h" #include "utils/utils.h" +#include "utils/log.h" /** @@ -228,6 +230,47 @@ void html_mouse_track(struct content *c, struct browser_window *bw, html_mouse_action(c, bw, mouse, x, y); } +/** Helper for file gadgets to store their filename unencoded on the + * dom node associated with the gadget. + * + * \todo Get rid of this crap eventually + */ +static void html__image_coords_dom_user_data_handler(dom_node_operation operation, + dom_string *key, void *_data, struct dom_node *src, + struct dom_node *dst) +{ + struct image_input_coords *oldcoords, *coords = _data, *newcoords; + + if (!dom_string_isequal(corestring_dom___ns_key_image_coords_node_data, + key) || coords == NULL) { + return; + } + + switch (operation) { + case DOM_NODE_CLONED: + newcoords = calloc(1, sizeof(*newcoords)); + *newcoords = *coords; + if (dom_node_set_user_data(dst, + corestring_dom___ns_key_image_coords_node_data, + newcoords, html__image_coords_dom_user_data_handler, + &oldcoords) == DOM_NO_ERR) { + free(oldcoords); + } + break; + + case DOM_NODE_RENAMED: + case DOM_NODE_IMPORTED: + case DOM_NODE_ADOPTED: + break; + + case DOM_NODE_DELETED: + free(coords); + break; + default: + LOG(("User data operation not handled.")); + assert(0); + } +} /** * Handle mouse clicks and movements in an HTML content window. @@ -630,8 +673,21 @@ void html_mouse_action(struct content *c, struct browser_window *bw, break; case GADGET_IMAGE: if (mouse & BROWSER_MOUSE_CLICK_1) { - gadget->data.image.mx = x - gadget_box_x; - gadget->data.image.my = y - gadget_box_y; + struct image_input_coords *coords, *oldcoords; + /** \todo Find a way to not ignore errors */ + coords = calloc(1, sizeof(*coords)); + if (coords == NULL) { + return; + } + coords->x = x - gadget_box_x; + coords->y = y - gadget_box_y; + if (dom_node_set_user_data( + gadget->node, + corestring_dom___ns_key_image_coords_node_data, + coords, html__image_coords_dom_user_data_handler, + &oldcoords) != DOM_NO_ERR) + return; + free(oldcoords); } /* drop through */ case GADGET_SUBMIT: diff --git a/utils/corestrings.c b/utils/corestrings.c index 9050ffe48..e60a75bdc 100644 --- a/utils/corestrings.c +++ b/utils/corestrings.c @@ -244,6 +244,7 @@ dom_string *corestring_dom_file; dom_string *corestring_dom_on; dom_string *corestring_dom___ns_key_libcss_node_data; dom_string *corestring_dom___ns_key_file_name_node_data; +dom_string *corestring_dom___ns_key_image_coords_node_data; /* * Free the core strings @@ -488,6 +489,7 @@ void corestrings_fini(void) /* DOM userdata keys, not really CSS */ CSS_DOM_STRING_UNREF(__ns_key_libcss_node_data); CSS_DOM_STRING_UNREF(__ns_key_file_name_node_data); + CSS_DOM_STRING_UNREF(__ns_key_image_coords_node_data); #undef CSS_DOM_STRING_UNREF } @@ -763,6 +765,7 @@ nserror corestrings_init(void) /* DOM userdata keys, not really CSS */ CSS_DOM_STRING_INTERN(__ns_key_libcss_node_data); CSS_DOM_STRING_INTERN(__ns_key_file_name_node_data); + CSS_DOM_STRING_INTERN(__ns_key_image_coords_node_data); #undef CSS_DOM_STRING_INTERN exc = dom_string_create_interned((const uint8_t *) "text/javascript", diff --git a/utils/corestrings.h b/utils/corestrings.h index 839d86522..90fef5aaa 100644 --- a/utils/corestrings.h +++ b/utils/corestrings.h @@ -255,6 +255,7 @@ extern struct dom_string *corestring_dom_on; /* DOM userdata keys */ extern struct dom_string *corestring_dom___ns_key_libcss_node_data; extern struct dom_string *corestring_dom___ns_key_file_name_node_data; +extern struct dom_string *corestring_dom___ns_key_image_coords_node_data; #endif From 0d5960a68cc031758dd17edf7e83c342c13ea144 Mon Sep 17 00:00:00 2001 From: Daniel Silverstone Date: Sun, 5 Jan 2014 16:14:45 +0000 Subject: [PATCH 054/773] Remove old form_successful_controls --- render/form.c | 349 -------------------------------------------------- 1 file changed, 349 deletions(-) diff --git a/render/form.c b/render/form.c index b55ec171c..761fc4c69 100644 --- a/render/form.c +++ b/render/form.c @@ -831,355 +831,6 @@ dom_no_memory: } #undef ENCODE_ITEM -/** - * Identify 'successful' controls. - * - * All text strings in the successful controls list will be in the charset most - * appropriate for submission. Therefore, no utf8_to_* processing should be - * performed upon them. - * - * \todo The chosen charset needs to be made available such that it can be - * included in the submission request (e.g. in the fetch's Content-Type header) - * - * \param form form to search for successful controls - * \param submit_button control used to submit the form, if any - * \param successful_controls updated to point to linked list of - * fetch_multipart_data, 0 if no controls - * \return true on success, false on memory exhaustion - * - * See HTML 4.01 section 17.13.2. - */ -bool form_successful_controls(struct form *form, - struct form_control *submit_button, - struct fetch_multipart_data **successful_controls) -{ - struct form_control *control; - struct form_option *option; - struct fetch_multipart_data sentinel, *last_success, *success_new; - char *value = NULL; - bool had_submit = false; - char *charset, *rawfile_temp; - - last_success = &sentinel; - sentinel.next = NULL; - - charset = form_acceptable_charset(form); - if (charset == NULL) - return false; - -#define ENCODE_ITEM(i) form_encode_item((i), 0, charset, form->document_charset) - - for (control = form->controls; control; control = control->next) { - /* ignore disabled controls */ - if (control->disabled) - continue; - - /* ignore controls with no name */ - if (!control->name) - continue; - - switch (control->type) { - case GADGET_HIDDEN: - if (control->value) - value = ENCODE_ITEM(control->value); - else - value = ENCODE_ITEM(""); - if (!value) { - LOG(("failed to duplicate value" - "'%s' for control %s", - control->value, - control->name)); - goto no_memory; - } - break; - - case GADGET_RADIO: - case GADGET_CHECKBOX: - /* ignore checkboxes and radio buttons which - * aren't selected */ - if (!control->selected) - continue; - if (control->value) - value = ENCODE_ITEM(control->value); - else - value = ENCODE_ITEM("on"); - if (!value) { - LOG(("failed to duplicate" - "value '%s' for" - "control %s", - control->value, - control->name)); - goto no_memory; - } - break; - - case GADGET_SELECT: - /* select */ - for (option = control->data.select.items; - option != NULL; - option = option->next) { - if (!option->selected) - continue; - success_new = - malloc(sizeof(*success_new)); - if (!success_new) { - LOG(("malloc failed")); - goto no_memory; - } - success_new->file = false; - success_new->name = - ENCODE_ITEM(control->name); - success_new->value = - ENCODE_ITEM(option->value); - success_new->next = NULL; - last_success->next = success_new; - last_success = success_new; - if (!success_new->name || - !success_new->value) { - LOG(("strdup failed")); - goto no_memory; - } - } - - continue; - break; - - case GADGET_TEXTBOX: - case GADGET_PASSWORD: - case GADGET_TEXTAREA: - { - char *v2; - int ta_len = textarea_get_text( - control->data.text.ta, - NULL, 0); - - value = malloc(ta_len); - if (!value) { - LOG(("failed handling textarea")); - goto no_memory; - } - textarea_get_text(control->data.text.ta, - value, ta_len); - - if (control->type == GADGET_TEXTAREA && - value[0] == '\0') { - /* Textarea not submitted if empty */ - free(value); - continue; - } - - v2 = ENCODE_ITEM(value); - if (!v2) { - LOG(("failed handling textarea")); - free(value); - goto no_memory; - } - - free(value); - value = v2; - } - break; - - case GADGET_IMAGE: { - /* image */ - size_t len; - char *name; - - if (control != submit_button) - /* only the activated submit button - * is successful */ - continue; - - name = ENCODE_ITEM(control->name); - if (name == NULL) - goto no_memory; - - len = strlen(name) + 3; - - /* x */ - success_new = malloc(sizeof(*success_new)); - if (!success_new) { - free(name); - LOG(("malloc failed")); - goto no_memory; - } - success_new->file = false; - success_new->name = malloc(len); - success_new->value = malloc(20); - if (!success_new->name || - !success_new->value) { - free(success_new->name); - free(success_new->value); - free(success_new); - free(name); - LOG(("malloc failed")); - goto no_memory; - } - sprintf(success_new->name, "%s.x", name); - sprintf(success_new->value, "%i", - control->data.image.mx); - success_new->next = 0; - last_success->next = success_new; - last_success = success_new; - - /* y */ - success_new = malloc(sizeof(*success_new)); - if (!success_new) { - free(name); - LOG(("malloc failed")); - goto no_memory; - } - success_new->file = false; - success_new->name = malloc(len); - success_new->value = malloc(20); - if (!success_new->name || - !success_new->value) { - free(success_new->name); - free(success_new->value); - free(success_new); - free(name); - LOG(("malloc failed")); - goto no_memory; - } - sprintf(success_new->name, "%s.y", name); - sprintf(success_new->value, "%i", - control->data.image.my); - success_new->next = 0; - last_success->next = success_new; - last_success = success_new; - - free(name); - - continue; - break; - } - - case GADGET_SUBMIT: - if (!submit_button && !had_submit) - /* no submit button specified, so - * use first declared in form */ - had_submit = true; - else if (control != submit_button) - /* only the activated submit button - * is successful */ - continue; - if (control->value) - value = ENCODE_ITEM(control->value); - else - value = ENCODE_ITEM(""); - if (!value) { - LOG(("failed to duplicate value" - "'%s' for control %s", - control->value, - control->name)); - goto no_memory; - } - break; - - case GADGET_RESET: - /* ignore reset */ - continue; - break; - - case GADGET_FILE: - /* file */ - /* Handling of blank file entries is - * implementation defined - we're perfectly - * within our rights to treat it as an - * unsuccessful control. Unfortunately, every - * other browser submits the field with - * a blank filename and no content. So, - * that's what we have to do, too. - */ - success_new = malloc(sizeof(*success_new)); - if (!success_new) { - LOG(("malloc failed")); - goto no_memory; - } - success_new->file = true; - success_new->name = ENCODE_ITEM(control->name); - success_new->value = - ENCODE_ITEM(control->value ? - control->value : ""); - success_new->rawfile = NULL; - /* Retrieve the filename from the DOM annotation */ - if (dom_node_get_user_data( - control->node, - corestring_dom___ns_key_file_name_node_data, - &rawfile_temp) != DOM_NO_ERR) { - LOG(("unable to get rawfile")); - goto no_memory; - } - - if (rawfile_temp == NULL) { - /* No annotation means the file was not - */ - success_new->rawfile = strdup(""); - } else { - success_new->rawfile = strdup(rawfile_temp); - } - - if (success_new->rawfile == NULL) { - LOG(("strdup failed")); - goto no_memory; - } - - success_new->next = 0; - last_success->next = success_new; - last_success = success_new; - if (!success_new->name || - !success_new->value) { - LOG(("strdup failed")); - goto no_memory; - } - - continue; - break; - - case GADGET_BUTTON: - /* Ignore it */ - continue; - break; - - default: - assert(0); - break; - } - - success_new = malloc(sizeof(*success_new)); - if (!success_new) { - LOG(("malloc failed")); - free(value); - goto no_memory; - } - success_new->file = false; - success_new->name = ENCODE_ITEM(control->name); - success_new->value = value; - success_new->next = NULL; - last_success->next = success_new; - last_success = success_new; - if (!success_new->name) { - LOG(("failed to duplicate name '%s'", - control->name)); - goto no_memory; - } - } - - free(charset); - - *successful_controls = sentinel.next; - return true; - -no_memory: - warn_user("NoMemory", 0); - free(charset); - fetch_multipart_data_destroy(sentinel.next); - return false; - -#undef ENCODE_ITEM -} - - /** * Encode controls using application/x-www-form-urlencoded. * From 550c8cd73c06f0984ce22b844d5a216d332cee43 Mon Sep 17 00:00:00 2001 From: Rob Kendrick Date: Sun, 5 Jan 2014 16:45:32 +0000 Subject: [PATCH 055/773] Change gui_file_gadget_interface to pass gui_window not browser_window, add GTK implementation that of course does not work. --- amiga/gui.c | 2 +- atari/gui.c | 2 +- beos/gui.cpp | 2 +- cocoa/gui.m | 2 +- desktop/browser.c | 2 +- desktop/gui.h | 2 +- gtk/gui.c | 7 ------- gtk/window.c | 32 ++++++++++++++++++++++++++++++++ monkey/browser.c | 2 +- riscos/gui.c | 2 +- 10 files changed, 40 insertions(+), 15 deletions(-) diff --git a/amiga/gui.c b/amiga/gui.c index 76185e949..8027eeba0 100644 --- a/amiga/gui.c +++ b/amiga/gui.c @@ -5138,7 +5138,7 @@ void ami_gui_splash_close(Object *win_obj) if(win_obj) DisposeObject(win_obj); } -void gui_file_gadget_open(struct browser_window *bw, hlcache_handle *hl, +void gui_file_gadget_open(struct gui_window *g, hlcache_handle *hl, struct form_control *gadget) { LOG(("File open dialog rquest for %p/%p", bw, gadget)); diff --git a/atari/gui.c b/atari/gui.c index badb4206c..3b3e98943 100644 --- a/atari/gui.c +++ b/atari/gui.c @@ -1098,7 +1098,7 @@ static void gui_init2(int argc, char** argv) toolbar_init(); } -void gui_file_gadget_open(struct browser_window *bw, hlcache_handle *hl, +void gui_file_gadget_open(struct gui_window *g, hlcache_handle *hl, struct form_control *gadget) { LOG(("File open dialog rquest for %p/%p", bw, gadget)); diff --git a/beos/gui.cpp b/beos/gui.cpp index 6c9d1ed12..42edc61aa 100644 --- a/beos/gui.cpp +++ b/beos/gui.cpp @@ -1165,7 +1165,7 @@ bool path_add_part(char *path, int length, const char *newpart) return true; } -void gui_file_gadget_open(struct browser_window *bw, hlcache_handle *hl, +void gui_file_gadget_open(struct gui_window *g, hlcache_handle *hl, struct form_control *gadget) { LOG(("File open dialog rquest for %p/%p", bw, gadget)); diff --git a/cocoa/gui.m b/cocoa/gui.m index 3804ad249..7ee2372f3 100644 --- a/cocoa/gui.m +++ b/cocoa/gui.m @@ -324,7 +324,7 @@ void gui_401login_open(nsurl *url, const char *realm, cb( false, cbpw ); } -void gui_file_gadget_open(struct browser_window *bw, hlcache_handle *hl, +void gui_file_gadget_open(struct gui_window *g, hlcache_handle *hl, struct form_control *gadget) { LOG(("File open dialog rquest for %p/%p", bw, gadget)); diff --git a/desktop/browser.c b/desktop/browser.c index 3d279f727..6ec31d22f 100644 --- a/desktop/browser.c +++ b/desktop/browser.c @@ -1564,7 +1564,7 @@ static nserror browser_window_callback(hlcache_handle *c, case CONTENT_MSG_GADGETCLICK: if (event->data.gadget_click.gadget->type == GADGET_FILE) { - gui_file_gadget_open(bw, c, + gui_file_gadget_open(bw->window, c, event->data.gadget_click.gadget); } diff --git a/desktop/gui.h b/desktop/gui.h index 4bbf08718..26a9f4b43 100644 --- a/desktop/gui.h +++ b/desktop/gui.h @@ -116,7 +116,7 @@ void gui_drag_save_selection(struct gui_window *g, const char *selection); void gui_start_selection(struct gui_window *g); void gui_clear_selection(struct gui_window *g); -void gui_file_gadget_open(struct browser_window *bw, hlcache_handle *hl, +void gui_file_gadget_open(struct gui_window *g, hlcache_handle *hl, struct form_control *gadget); /** diff --git a/gtk/gui.c b/gtk/gui.c index 0f815a7a2..77b72f874 100644 --- a/gtk/gui.c +++ b/gtk/gui.c @@ -681,13 +681,6 @@ void gui_quit(void) gtk_fetch_filetype_fin(); } -void gui_file_gadget_open(struct browser_window *bw, hlcache_handle *hl, - struct form_control *gadget) -{ - LOG(("File open dialog rquest for %p/%p", bw, gadget)); - /* browser_window_set_gadget_filename(bw, gadget, "plinth"); */ -} - static void nsgtk_select_menu_clicked(GtkCheckMenuItem *checkmenuitem, gpointer user_data) { diff --git a/gtk/window.c b/gtk/window.c index 8f449ced2..8f05c3799 100644 --- a/gtk/window.c +++ b/gtk/window.c @@ -1162,3 +1162,35 @@ void gui_window_get_dimensions(struct gui_window *g, int *width, int *height, LOG(("width: %i", *width)); LOG(("height: %i", *height)); } + +void gui_file_gadget_open(struct gui_window *g, hlcache_handle *hl, + struct form_control *gadget) +{ + GtkWidget *dialog; + + LOG(("Awooga.")); + + dialog = gtk_file_chooser_dialog_new("Select File", + nsgtk_scaffolding_window(g->scaffold), + GTK_FILE_CHOOSER_ACTION_OPEN, + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, + NULL); + + LOG(("*** open dialog: %p", dialog)); + + int ret = gtk_dialog_run(GTK_DIALOG(dialog)); + LOG(("*** return value: %d", ret)); + if (ret == GTK_RESPONSE_ACCEPT) { + char *filename; + + filename = gtk_file_chooser_get_filename( + GTK_FILE_CHOOSER(dialog)); + + browser_window_set_gadget_filename(g->bw, gadget, filename); + + g_free(filename); + } + + gtk_widget_destroy(dialog); +} diff --git a/monkey/browser.c b/monkey/browser.c index 47fb07bc1..7c28cf8a3 100644 --- a/monkey/browser.c +++ b/monkey/browser.c @@ -390,7 +390,7 @@ gui_window_save_link(struct gui_window *g, const char *url, g->win_num, url, title); } -void gui_file_gadget_open(struct browser_window *bw, hlcache_handle *hl, +void gui_file_gadget_open(struct gui_browser *g, hlcache_handle *hl, struct form_control *gadget) { LOG(("File open dialog rquest for %p/%p", bw, gadget)); diff --git a/riscos/gui.c b/riscos/gui.c index 0c8ebecc7..900915483 100644 --- a/riscos/gui.c +++ b/riscos/gui.c @@ -2424,7 +2424,7 @@ bool path_add_part(char *path, int length, const char *newpart) return true; } -void gui_file_gadget_open(struct browser_window *bw, hlcache_handle *hl, +void gui_file_gadget_open(struct gui_window *g, hlcache_handle *hl, struct form_control *gadget) { LOG(("File open dialog rquest for %p/%p", bw, gadget)); From ef5c516ee372d29ca636fa0f7bd422c312be0acf Mon Sep 17 00:00:00 2001 From: Daniel Silverstone Date: Sun, 5 Jan 2014 17:01:27 +0000 Subject: [PATCH 056/773] Restore missing message send --- render/html_interaction.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/render/html_interaction.c b/render/html_interaction.c index f18daebd4..b04d42586 100644 --- a/render/html_interaction.c +++ b/render/html_interaction.c @@ -685,6 +685,10 @@ void html_mouse_action(struct content *c, struct browser_window *bw, break; case GADGET_FILE: status = messages_get("FormFile"); + if (mouse & BROWSER_MOUSE_CLICK_1) { + msg_data.gadget_click.gadget = gadget; + content_broadcast(c, CONTENT_MSG_GADGETCLICK, msg_data); + } break; case GADGET_BUTTON: /* This gadget cannot be activated */ From ff0112309147a9d9f8f66bc65108715db02f9447 Mon Sep 17 00:00:00 2001 From: Rob Kendrick Date: Sun, 5 Jan 2014 17:14:10 +0000 Subject: [PATCH 057/773] Change FatMessages so drop instructions are click instructions for some frontends --- resources/FatMessages | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/resources/FatMessages b/resources/FatMessages index 2d74f3d6d..22f7890d7 100644 --- a/resources/FatMessages +++ b/resources/FatMessages @@ -2611,7 +2611,12 @@ de.all.Form_Many:(Viele) fr.all.Form_Many:(Plusieurs) it.all.Form_Many:(Molti) nl.all.Form_Many:(Veel) -en.all.Form_Drop:Drop file here +en.gtk.Form_Drop:Click to select file +en.ro.Form_Drop:Drop file here +en.ami.Form_Drop:Drop file here +en.beos.Form_Drop:Drop file here +en.fb.Form_Drop:Click to select file +en.osx.Form_Drop:Click to select file de.all.Form_Drop:Datei hier hinziehen fr.all.Form_Drop:Déposer les fichiers ici it.all.Form_Drop:Inserisci un file qui From d24ee91311e9c86a5743bc6d7036c7e873dd29fa Mon Sep 17 00:00:00 2001 From: Rob Kendrick Date: Sun, 5 Jan 2014 17:16:26 +0000 Subject: [PATCH 058/773] Under GTK, file gadgets are more like buttons --- gtk/res/gtkdefault.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gtk/res/gtkdefault.css b/gtk/res/gtkdefault.css index 9021eedd9..300c13add 100644 --- a/gtk/res/gtkdefault.css +++ b/gtk/res/gtkdefault.css @@ -12,7 +12,7 @@ input { font-size: 95%; border: medium inset #ddd; } input[type=button], input[type=reset], input[type=submit], button { background-color: #ddd; border: medium outset #ddd; } input[type=checkbox], input[type=radio] { font-size: 105%; } -input[type=file] { background-color: #ddd; border: medium inset #ddd; } +input[type=file] { background-color: #ddd; border: medium outset #ddd; } select { background-color: #ddd; border: medium inset #ddd; font-size: 95%; } select:after { border-left:4px ridge #ddd; } From 692d4a328c7ba7cbf13c66c5da67ac1e9bb323b2 Mon Sep 17 00:00:00 2001 From: Daniel Silverstone Date: Sun, 5 Jan 2014 17:21:59 +0000 Subject: [PATCH 059/773] Fix some log statements --- amiga/gui.c | 2 +- atari/gui.c | 2 +- beos/gui.cpp | 2 +- cocoa/gui.m | 2 +- monkey/browser.c | 2 +- riscos/gui.c | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/amiga/gui.c b/amiga/gui.c index 8027eeba0..bfb5d09ff 100644 --- a/amiga/gui.c +++ b/amiga/gui.c @@ -5141,7 +5141,7 @@ void ami_gui_splash_close(Object *win_obj) void gui_file_gadget_open(struct gui_window *g, hlcache_handle *hl, struct form_control *gadget) { - LOG(("File open dialog rquest for %p/%p", bw, gadget)); + LOG(("File open dialog rquest for %p/%p", g, gadget)); /* browser_window_set_gadget_filename(bw, gadget, "filename"); */ } diff --git a/atari/gui.c b/atari/gui.c index 3b3e98943..e02c5434a 100644 --- a/atari/gui.c +++ b/atari/gui.c @@ -1101,7 +1101,7 @@ static void gui_init2(int argc, char** argv) void gui_file_gadget_open(struct gui_window *g, hlcache_handle *hl, struct form_control *gadget) { - LOG(("File open dialog rquest for %p/%p", bw, gadget)); + LOG(("File open dialog rquest for %p/%p", g, gadget)); /* browser_window_set_gadget_filename(bw, gadget, "filename"); */ } diff --git a/beos/gui.cpp b/beos/gui.cpp index 42edc61aa..32bd3a2d5 100644 --- a/beos/gui.cpp +++ b/beos/gui.cpp @@ -1168,7 +1168,7 @@ bool path_add_part(char *path, int length, const char *newpart) void gui_file_gadget_open(struct gui_window *g, hlcache_handle *hl, struct form_control *gadget) { - LOG(("File open dialog rquest for %p/%p", bw, gadget)); + LOG(("File open dialog rquest for %p/%p", g, gadget)); /* browser_window_set_gadget_filename(bw, gadget, "filename"); */ } diff --git a/cocoa/gui.m b/cocoa/gui.m index 7ee2372f3..449b52c82 100644 --- a/cocoa/gui.m +++ b/cocoa/gui.m @@ -327,7 +327,7 @@ void gui_401login_open(nsurl *url, const char *realm, void gui_file_gadget_open(struct gui_window *g, hlcache_handle *hl, struct form_control *gadget) { - LOG(("File open dialog rquest for %p/%p", bw, gadget)); + LOG(("File open dialog rquest for %p/%p", g, gadget)); /* browser_window_set_gadget_filename(bw, gadget, "filename"); */ } diff --git a/monkey/browser.c b/monkey/browser.c index 7c28cf8a3..5cd18359a 100644 --- a/monkey/browser.c +++ b/monkey/browser.c @@ -393,7 +393,7 @@ gui_window_save_link(struct gui_window *g, const char *url, void gui_file_gadget_open(struct gui_browser *g, hlcache_handle *hl, struct form_control *gadget) { - LOG(("File open dialog rquest for %p/%p", bw, gadget)); + LOG(("File open dialog rquest for %p/%p", g, gadget)); /* browser_window_set_gadget_filename(bw, gadget, "filename"); */ } diff --git a/riscos/gui.c b/riscos/gui.c index 900915483..ae5ea383e 100644 --- a/riscos/gui.c +++ b/riscos/gui.c @@ -2427,7 +2427,7 @@ bool path_add_part(char *path, int length, const char *newpart) void gui_file_gadget_open(struct gui_window *g, hlcache_handle *hl, struct form_control *gadget) { - LOG(("File open dialog rquest for %p/%p", bw, gadget)); + LOG(("File open dialog rquest for %p/%p", g, gadget)); /* browser_window_set_gadget_filename(bw, gadget, "filename"); */ } From f97c1fc605caf49b73a11f960dc9a6c869e97abe Mon Sep 17 00:00:00 2001 From: Daniel Silverstone Date: Sun, 5 Jan 2014 17:33:08 +0000 Subject: [PATCH 060/773] Add some more frontend stubs and fix up some others --- cocoa/gui.m | 1 + framebuffer/gui.c | 7 +++++++ monkey/browser.c | 2 +- windows/gui.c | 7 +++++++ 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/cocoa/gui.m b/cocoa/gui.m index 449b52c82..72f64bf04 100644 --- a/cocoa/gui.m +++ b/cocoa/gui.m @@ -32,6 +32,7 @@ #import "desktop/textinput.h" #import "desktop/401login.h" #import "utils/utils.h" +#import "utils/log.h" #import "image/ico.h" #import "content/fetchers/resource.h" diff --git a/framebuffer/gui.c b/framebuffer/gui.c index b4bb3ef43..08cb31318 100644 --- a/framebuffer/gui.c +++ b/framebuffer/gui.c @@ -1988,6 +1988,13 @@ gui_cert_verify(nsurl *url, cb(false, cbpw); } +void gui_file_gadget_open(struct gui_window *g, hlcache_handle *hl, + struct form_control *gadget) +{ + LOG(("File open dialog rquest for %p/%p", g, gadget)); + /* browser_window_set_gadget_filename(bw, gadget, "filename"); */ +} + /* * Local Variables: * c-basic-offset:8 diff --git a/monkey/browser.c b/monkey/browser.c index 5cd18359a..73549f36a 100644 --- a/monkey/browser.c +++ b/monkey/browser.c @@ -390,7 +390,7 @@ gui_window_save_link(struct gui_window *g, const char *url, g->win_num, url, title); } -void gui_file_gadget_open(struct gui_browser *g, hlcache_handle *hl, +void gui_file_gadget_open(struct gui_window *g, hlcache_handle *hl, struct form_control *gadget) { LOG(("File open dialog rquest for %p/%p", g, gadget)); diff --git a/windows/gui.c b/windows/gui.c index 767f6812e..e20369a65 100644 --- a/windows/gui.c +++ b/windows/gui.c @@ -73,6 +73,13 @@ static const char windowclassname_main[] = "nswsmainwindow"; static struct nsws_pointers nsws_pointer; +void gui_file_gadget_open(struct gui_window *g, hlcache_handle *hl, + struct form_control *gadget) +{ + LOG(("File open dialog rquest for %p/%p", g, gadget)); + /* browser_window_set_gadget_filename(bw, gadget, "filename"); */ +} + void gui_poll(bool active) { MSG Msg; /* message from system */ From b2fff176df8236a2f5957e579a2905833ecc3a6e Mon Sep 17 00:00:00 2001 From: Chris Young Date: Sun, 5 Jan 2014 22:55:34 +0000 Subject: [PATCH 061/773] This shouldn't be UTF-8 --- amiga/context_menu.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/amiga/context_menu.c b/amiga/context_menu.c index 2ad2b89d9..1aa8f7ac2 100644 --- a/amiga/context_menu.c +++ b/amiga/context_menu.c @@ -742,17 +742,11 @@ static uint32 ami_context_menu_hook(struct Hook *hook,Object *item,APTR reserved strlcpy(fname,filereq->fr_Drawer,1024); AddPart(fname,filereq->fr_File,1024); - if(utf8_from_local_encoding(fname,0,&utf8_fn) != UTF8_CONVERT_OK) - { - warn_user("NoMemory",""); - break; - } - browser_window_drop_file_at_point( file_input->bw, file_input->x, file_input->y, - utf8_fn); + fname); } break; From 4eff5ddf719e429b463f4615dc4c80c6683a18cd Mon Sep 17 00:00:00 2001 From: Chris Young Date: Sun, 5 Jan 2014 23:04:28 +0000 Subject: [PATCH 062/773] Add file upload request on click --- amiga/gui.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/amiga/gui.c b/amiga/gui.c index bfb5d09ff..3a0dd97c5 100644 --- a/amiga/gui.c +++ b/amiga/gui.c @@ -5142,6 +5142,18 @@ void gui_file_gadget_open(struct gui_window *g, hlcache_handle *hl, struct form_control *gadget) { LOG(("File open dialog rquest for %p/%p", g, gadget)); - /* browser_window_set_gadget_filename(bw, gadget, "filename"); */ + + if(AslRequestTags(filereq, + ASLFR_Window, g->shared->win, + ASLFR_SleepWindow, TRUE, + ASLFR_TitleText, messages_get("NetSurf"), + ASLFR_Screen, scrn, + ASLFR_DoSaveMode, FALSE, + TAG_DONE)) { + char fname[1024]; + strlcpy(fname, filereq->fr_Drawer, 1024); + AddPart(fname, filereq->fr_File, 1024); + browser_window_set_gadget_filename(g->shared->bw, gadget, fname); + } } From 2a34df8dccdc6b8534a2158e71f0593e96fb9204 Mon Sep 17 00:00:00 2001 From: Chris Young Date: Sun, 5 Jan 2014 23:08:08 +0000 Subject: [PATCH 063/773] Update description to reflect reality --- resources/FatMessages | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/resources/FatMessages b/resources/FatMessages index 22f7890d7..50b39dd57 100644 --- a/resources/FatMessages +++ b/resources/FatMessages @@ -2613,7 +2613,7 @@ it.all.Form_Many:(Molti) nl.all.Form_Many:(Veel) en.gtk.Form_Drop:Click to select file en.ro.Form_Drop:Drop file here -en.ami.Form_Drop:Drop file here +en.ami.Form_Drop:Click or drop file here en.beos.Form_Drop:Drop file here en.fb.Form_Drop:Click to select file en.osx.Form_Drop:Click to select file @@ -4815,12 +4815,12 @@ nl.ro.HelpCacheConfig3:\Tamount of memory to be used for caching content. en.ro.HelpCacheConfig4:\Sreduce the amount of memory. de.ro.HelpCacheConfig4:Klicken mit AUSWAHL verringert die Größe des Cachespeichers. fr.ro.HelpCacheConfig4:\Sréduire la quantité de mémoire. -it.ro.HelpCacheConfig4:\Sriduce la quantit di memoria. +it.ro.HelpCacheConfig4:\Sriduce la quantità di memoria. nl.ro.HelpCacheConfig4:\Sreduce the amount of memory. en.ro.HelpCacheConfig5:\Sincrease the amount of memory. de.ro.HelpCacheConfig5:Klicken mit AUSWAHL vergrößert die Größe des Cachespeichers. fr.ro.HelpCacheConfig5:\Saugmenter la quantité de mémoire. -it.ro.HelpCacheConfig5:\Saumenta la quantit di memoria. +it.ro.HelpCacheConfig5:\Saumenta la quantità di memoria. nl.ro.HelpCacheConfig5:\Sincrease the amount of memory. en.ro.HelpCacheConfig7:\Sreset the Cache options back to their default values. de.ro.HelpCacheConfig7:Stellt die Standardeinstellungen wieder her. From 69da9a55e16f0a09690ca5fc5cb0b0e1d0fe9c24 Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Mon, 6 Jan 2014 13:27:34 +0000 Subject: [PATCH 064/773] Assert a bit earlier when front end tries to redraw SSL cert viewer that it's destroyed. --- desktop/tree.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/desktop/tree.c b/desktop/tree.c index 6097c22a6..4611a7747 100644 --- a/desktop/tree.c +++ b/desktop/tree.c @@ -133,6 +133,10 @@ static bool treeview_test_init(struct tree *tree) switch (tree->flags) { case TREE_COOKIES: + assert(ssl_current_session == NULL && + "Call sslcert_viewer_init directly, " + "this compat. layer can't cope with simultanious " + "sslcert viewers"); err = cookie_manager_init(&cw_t, (struct core_window *)tree); if (err != NSERROR_OK) warn_user("Couldn't init new cookie manager.", 0); @@ -180,7 +184,10 @@ static bool treeview_test_fini(struct tree *tree) warn_user("Couldn't finalise hotlist.", 0); break; case TREE_SSLCERT: + assert(ssl_current_session != NULL && + "Can't use sslcert window after sslcert_viewer_fini()"); err = sslcert_viewer_fini(ssl_current_session); + ssl_current_session = NULL; if (err != NSERROR_OK) warn_user("Couldn't finalise sslcert viewer.", 0); break; @@ -206,6 +213,8 @@ static bool treeview_test_redraw(struct tree *tree, int x, int y, switch (tree->flags) { case TREE_SSLCERT: + assert(ssl_current_session != NULL && + "Can't use sslcert window after sslcert_viewer_fini()"); sslcert_viewer_redraw(ssl_current_session, x, y, &clip, ctx); return true; case TREE_COOKIES: @@ -227,6 +236,8 @@ static bool treeview_test_mouse_action(struct tree *tree, { switch (tree->flags) { case TREE_SSLCERT: + assert(ssl_current_session != NULL && + "Can't use sslcert window after sslcert_viewer_fini()"); sslcert_viewer_mouse_action(ssl_current_session, mouse, x, y); return true; case TREE_COOKIES: @@ -247,6 +258,8 @@ static bool treeview_test_keypress(struct tree *tree, uint32_t key) { switch (tree->flags) { case TREE_SSLCERT: + assert(ssl_current_session != NULL && + "Can't use sslcert window after sslcert_viewer_fini()"); sslcert_viewer_keypress(ssl_current_session, key); return true; case TREE_COOKIES: From 870c7096842725f354708963c9630deb1c5386fc Mon Sep 17 00:00:00 2001 From: Chris Young Date: Mon, 6 Jan 2014 18:29:05 +0000 Subject: [PATCH 065/773] Get Composite() to befriend the screen's BitMap to ensure they are on the same graphics board. This should fix the slowness when multiple graphics cards are installed. --- amiga/bitmap.c | 2 +- amiga/plotters.c | 2 ++ amiga/thumbnail.c | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/amiga/bitmap.c b/amiga/bitmap.c index c07f45c67..f25ac2b81 100644 --- a/amiga/bitmap.c +++ b/amiga/bitmap.c @@ -453,7 +453,7 @@ static struct BitMap *ami_bitmap_get_truecolour(struct bitmap *bitmap,int width, COMPTAG_DestHeight,height, COMPTAG_OffsetX,0, COMPTAG_OffsetY,0, - COMPTAG_FriendBitMap,friendbm, + COMPTAG_FriendBitMap, scrn->RastPort.BitMap, TAG_DONE); #endif } diff --git a/amiga/plotters.c b/amiga/plotters.c index 6683fc58b..05db67f48 100755 --- a/amiga/plotters.c +++ b/amiga/plotters.c @@ -711,6 +711,7 @@ static bool ami_bitmap(int x, int y, int width, int height, struct bitmap *bitma COMPTAG_SrcHeight,height, COMPTAG_OffsetX,x, COMPTAG_OffsetY,y, + COMPTAG_FriendBitMap, scrn->RastPort.BitMap, TAG_DONE); #endif } @@ -873,6 +874,7 @@ static void ami_bitmap_tile_hook(struct Hook *hook,struct RastPort *rp,struct Ba COMPTAG_SrcHeight,bfbm->height, COMPTAG_OffsetX,xf, COMPTAG_OffsetY,yf, + COMPTAG_FriendBitMap, scrn->RastPort.BitMap, TAG_DONE); #endif } diff --git a/amiga/thumbnail.c b/amiga/thumbnail.c index 61102feff..51630be96 100755 --- a/amiga/thumbnail.c +++ b/amiga/thumbnail.c @@ -84,6 +84,7 @@ bool thumbnail_create(hlcache_handle *content, struct bitmap *bitmap, COMPTAG_DestHeight,bitmap->height, COMPTAG_OffsetX,0, COMPTAG_OffsetY,0, + COMPTAG_FriendBitMap, scrn->RastPort.BitMap, TAG_DONE); } else From be6f4d3997989012210ee3413c5186c7fb0ee29a Mon Sep 17 00:00:00 2001 From: Chris Young Date: Mon, 6 Jan 2014 18:37:43 +0000 Subject: [PATCH 066/773] Probably shouldn't override thumbnail source alpha --- amiga/thumbnail.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/amiga/thumbnail.c b/amiga/thumbnail.c index 51630be96..9c149129d 100755 --- a/amiga/thumbnail.c +++ b/amiga/thumbnail.c @@ -69,7 +69,7 @@ bool thumbnail_create(hlcache_handle *content, struct bitmap *bitmap, if(GfxBase->LibNode.lib_Version >= 53) // AutoDoc says v52, but this function isn't in OS4.0, so checking for v53 (OS4.1) { float resample_scale = bitmap->width / (float)plot_width; - uint32 flags = COMPFLAG_IgnoreDestAlpha | COMPFLAG_SrcAlphaOverride; + uint32 flags = COMPFLAG_IgnoreDestAlpha; if(nsoption_bool(scale_quality)) flags |= COMPFLAG_SrcFilter; CompositeTags(COMPOSITE_Src,browserglob.bm,bitmap->nativebm, From 28e670f52da46819f8f18844a407bf9ad93043cd Mon Sep 17 00:00:00 2001 From: Daniel Silverstone Date: Mon, 6 Jan 2014 18:50:25 +0000 Subject: [PATCH 067/773] Support 'checked' properly in new form handler --- render/form.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/render/form.c b/render/form.c index 761fc4c69..49d6f217c 100644 --- a/render/form.c +++ b/render/form.c @@ -350,7 +350,7 @@ bool form_successful_controls_dom(struct form *_form, dom_exception err; dom_string *nodename = NULL, *inputname = NULL, *inputvalue = NULL, *inputtype = NULL; struct fetch_multipart_data sentinel, *last_success, *success_new; - bool had_submit = false, element_disabled; + bool had_submit = false, element_disabled, checked; char *charset, *rawfile_temp = NULL, *basename; uint32_t index, element_count; struct image_input_coords *coords; @@ -687,6 +687,15 @@ bool form_successful_controls_dom(struct form *_form, dom_string_caseless_isequal( inputtype, corestring_dom_checkbox)) { LOG(("Examining radio or checkbox")); + err = dom_html_input_element_get_checked( + (dom_html_input_element *)form_element, + &checked); + if (err != DOM_NO_ERR) { + LOG(("Could not get input element checked")); + goto dom_no_memory; + } + if (!checked) + continue; err = dom_html_input_element_get_value( (dom_html_input_element *)form_element, &inputvalue); From b415c2f9ff8ff4938343237f50c97f31ce6d5a95 Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Mon, 6 Jan 2014 22:22:41 +0000 Subject: [PATCH 068/773] fixup logic error in save complete as directed by jmb --- desktop/save_complete.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/desktop/save_complete.c b/desktop/save_complete.c index efe223747..3e5234af4 100644 --- a/desktop/save_complete.c +++ b/desktop/save_complete.c @@ -435,7 +435,7 @@ static bool save_complete_save_html_objects(save_complete_ctx *ctx, object = html_get_objects(c, &count); for (; object != NULL; object = object->next) { - if (object->content != NULL || object->box != NULL) { + if ((object->content != NULL) && (object->box != NULL)) { if (save_complete_save_html_object(ctx, object->content) == false) return false; From 277bcec7c6234823390903087dd553c9838c013c Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Fri, 10 Jan 2014 14:32:29 +0000 Subject: [PATCH 069/773] stop system colours being anything to do with frontends --- css/css.c | 6 +++--- css/select.c | 4 ++-- desktop/gui.h | 9 --------- desktop/netsurf.c | 7 +++++-- desktop/netsurf.h | 8 +++++++- desktop/scrollbar.c | 7 ++++--- desktop/system_colour.c | 36 +++++++++++++++++++----------------- desktop/system_colour.h | 40 ++++++++++++++++++++++++++++++++++++++++ desktop/treeview.c | 14 +++++++------- 9 files changed, 87 insertions(+), 44 deletions(-) create mode 100644 desktop/system_colour.h diff --git a/css/css.c b/css/css.c index 803906692..364511875 100644 --- a/css/css.c +++ b/css/css.c @@ -26,7 +26,7 @@ #include "content/hlcache.h" #include "css/css.h" #include "css/internal.h" -#include "desktop/gui.h" +#include "desktop/system_colour.h" #include "render/html.h" #include "utils/utils.h" #include "utils/http.h" @@ -221,7 +221,7 @@ static nserror nscss_create_css_data(struct content_css_data *c, params.resolve_pw = NULL; params.import = nscss_handle_import; params.import_pw = c; - params.color = gui_system_colour; + params.color = ns_system_colour; params.color_pw = NULL; params.font = NULL; params.font_pw = NULL; @@ -767,7 +767,7 @@ css_error nscss_register_import(struct content_css_data *c, params.resolve_pw = NULL; params.import = NULL; params.import_pw = NULL; - params.color = gui_system_colour; + params.color = ns_system_colour; params.color_pw = NULL; params.font = NULL; params.font_pw = NULL; diff --git a/css/select.c b/css/select.c index 0202737b8..885cdecfd 100644 --- a/css/select.c +++ b/css/select.c @@ -26,7 +26,7 @@ #include "css/internal.h" #include "css/select.h" #include "css/utils.h" -#include "desktop/gui.h" +#include "desktop/system_colour.h" #include "utils/nsoption.h" #include "utils/corestrings.h" #include "utils/log.h" @@ -185,7 +185,7 @@ css_stylesheet *nscss_create_inline_style(const uint8_t *data, size_t len, params.resolve_pw = NULL; params.import = NULL; params.import_pw = NULL; - params.color = gui_system_colour; + params.color = ns_system_colour; params.color_pw = NULL; params.font = NULL; params.font_pw = NULL; diff --git a/desktop/gui.h b/desktop/gui.h index 26a9f4b43..9317e8576 100644 --- a/desktop/gui.h +++ b/desktop/gui.h @@ -169,13 +169,4 @@ void gui_cert_verify(nsurl *url, const struct ssl_cert_info *certs, */ nsurl* gui_get_resource_url(const char *path); -/** css callback to obtain named system colours from a frontend. */ -css_error gui_system_colour(void *pw, lwc_string *name, css_color *color); - -/** Obtain a named system colour from a frontend. */ -colour gui_system_colour_char(const char *name); - -bool gui_system_colour_init(void); -void gui_system_colour_finalize(void); - #endif diff --git a/desktop/netsurf.c b/desktop/netsurf.c index fa026dc6a..36b0b589a 100644 --- a/desktop/netsurf.c +++ b/desktop/netsurf.c @@ -39,6 +39,7 @@ #include "desktop/netsurf.h" #include "desktop/401login.h" #include "desktop/browser.h" +#include "desktop/system_colour.h" #include "desktop/gui.h" #include "utils/nsoption.h" #include "desktop/searchweb.h" @@ -211,7 +212,9 @@ nserror netsurf_init(const char *messages) hlcache_initialise(&hlcache_parameters); /* Initialize system colours */ - gui_system_colour_init(); + error = ns_system_colour_init(); + if (error != NSERROR_OK) + return error; js_initialise(); @@ -270,7 +273,7 @@ void netsurf_exit(void) urldb_destroy(); LOG(("Destroying System colours")); - gui_system_colour_finalize(); + ns_system_colour_finalize(); corestrings_fini(); LOG(("Remaining lwc strings:")); diff --git a/desktop/netsurf.h b/desktop/netsurf.h index bfdb647ff..aa1796f7c 100644 --- a/desktop/netsurf.h +++ b/desktop/netsurf.h @@ -28,8 +28,14 @@ extern const char * const netsurf_version; extern const int netsurf_version_major; extern const int netsurf_version_minor; +/** Initialise netsurf core */ nserror netsurf_init(const char *messages); -extern void netsurf_exit(void); + +/** Run primary event loop */ extern int netsurf_main_loop(void); +/** finalise NetSurf core */ +extern void netsurf_exit(void); + + #endif diff --git a/desktop/scrollbar.c b/desktop/scrollbar.c index d24ea727a..dadb82801 100644 --- a/desktop/scrollbar.c +++ b/desktop/scrollbar.c @@ -25,6 +25,7 @@ #include #include +#include "desktop/system_colour.h" #include "desktop/mouse.h" #include "desktop/scrollbar.h" #include "utils/nsoption.h" @@ -190,9 +191,9 @@ bool scrollbar_redraw(struct scrollbar *s, int x, int y, int v[6]; /* array of triangle vertices */ int x0, y0, x1, y1; - colour bg_fill_colour = gui_system_colour_char("Scrollbar"); - colour fg_fill_colour = gui_system_colour_char("ButtonFace"); - colour arrow_fill_colour = gui_system_colour_char("ButtonText"); + colour bg_fill_colour = ns_system_colour_char("Scrollbar"); + colour fg_fill_colour = ns_system_colour_char("ButtonFace"); + colour arrow_fill_colour = ns_system_colour_char("ButtonText"); plot_style_t bg_fill_style = { .fill_type = PLOT_OP_TYPE_SOLID, diff --git a/desktop/system_colour.c b/desktop/system_colour.c index 4ef170981..178c03536 100644 --- a/desktop/system_colour.c +++ b/desktop/system_colour.c @@ -21,45 +21,47 @@ * */ +#include + +#include "utils/config.h" #include "utils/utils.h" #include "utils/log.h" #include "css/utils.h" -#include "desktop/gui.h" +#include "desktop/system_colour.h" #include "utils/nsoption.h" - #define colour_list_len ((NSOPTION_SYS_COLOUR_END - NSOPTION_SYS_COLOUR_START) + 1) static lwc_string *colour_list[colour_list_len]; -static lwc_string **gui_system_colour_pw = NULL; +static lwc_string **ns_system_colour_pw = NULL; -bool gui_system_colour_init(void) +nserror ns_system_colour_init(void) { unsigned int ccount; - if (gui_system_colour_pw != NULL) - return false; + if (ns_system_colour_pw != NULL) + return NSERROR_INIT_FAILED; /* Intern colour strings */ for (ccount = 0; ccount < colour_list_len; ccount++) { struct nsoption_s *opt; opt = &nsoptions[ccount + NSOPTION_SYS_COLOUR_START]; - if (lwc_intern_string(opt->key + SLEN("sys_colour_"), - opt->key_len - SLEN("sys_colour_"), + if (lwc_intern_string(opt->key + SLEN("sys_colour_"), + opt->key_len - SLEN("sys_colour_"), &(colour_list[ccount])) != lwc_error_ok) { - return false; + return NSERROR_NOMEM; } } - gui_system_colour_pw = colour_list; - - return true; + ns_system_colour_pw = colour_list; + + return NSERROR_OK; } -void gui_system_colour_finalize(void) +void ns_system_colour_finalize(void) { unsigned int ccount; @@ -68,7 +70,7 @@ void gui_system_colour_finalize(void) } } -colour gui_system_colour_char(const char *name) +colour ns_system_colour_char(const char *name) { colour ret = 0; unsigned int ccount; @@ -83,19 +85,19 @@ colour gui_system_colour_char(const char *name) return ret; } -css_error gui_system_colour(void *pw, lwc_string *name, css_color *colour) +css_error ns_system_colour(void *pw, lwc_string *name, css_color *colour) { unsigned int ccount; bool match; for (ccount = 0; ccount < colour_list_len; ccount++) { - if (lwc_string_caseless_isequal(name, + if (lwc_string_caseless_isequal(name, colour_list[ccount], &match) == lwc_error_ok && match) { *colour = ns_color_to_nscss(nsoptions[ccount + NSOPTION_SYS_COLOUR_START].value.c); return CSS_OK; } - } + } return CSS_INVALID; } diff --git a/desktop/system_colour.h b/desktop/system_colour.h new file mode 100644 index 000000000..b5d4baad4 --- /dev/null +++ b/desktop/system_colour.h @@ -0,0 +1,40 @@ +/* + * Copyright 2014 vincent Sanders + * + * This file is part of NetSurf, http://www.netsurf-browser.org/ + * + * NetSurf is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * NetSurf is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** \file + * Interface to system colour values. + */ + +#ifndef _NETSURF_DESKTOP_SYSTEM_COLOUR_H_ +#define _NETSURF_DESKTOP_SYSTEM_COLOUR_H_ + +#include + +#include "utils/errors.h" +#include "desktop/plot_style.h" + +/** css callback to obtain named system colours. */ +css_error ns_system_colour(void *pw, lwc_string *name, css_color *color); + +/** Obtain a named system colour from a frontend. */ +colour ns_system_colour_char(const char *name); + +nserror ns_system_colour_init(void); +void ns_system_colour_finalize(void); + +#endif diff --git a/desktop/treeview.c b/desktop/treeview.c index a137c46c5..d380882b1 100644 --- a/desktop/treeview.c +++ b/desktop/treeview.c @@ -21,7 +21,7 @@ */ #include "css/utils.h" -#include "desktop/gui.h" +#include "desktop/system_colour.h" #include "desktop/knockout.h" #include "desktop/plotters.h" #include "desktop/textarea.h" @@ -3466,15 +3466,15 @@ static void treeview_init_plot_styles(int font_pt_size) plot_style_even.bg.stroke_width = 0; plot_style_even.bg.stroke_colour = 0; plot_style_even.bg.fill_type = PLOT_OP_TYPE_SOLID; - plot_style_even.bg.fill_colour = gui_system_colour_char("Window"); + plot_style_even.bg.fill_colour = ns_system_colour_char("Window"); /* Text colour */ plot_style_even.text.family = PLOT_FONT_FAMILY_SANS_SERIF; plot_style_even.text.size = font_pt_size * FONT_SIZE_SCALE; plot_style_even.text.weight = 400; plot_style_even.text.flags = FONTF_NONE; - plot_style_even.text.foreground = gui_system_colour_char("WindowText"); - plot_style_even.text.background = gui_system_colour_char("Window"); + plot_style_even.text.foreground = ns_system_colour_char("WindowText"); + plot_style_even.text.background = ns_system_colour_char("Window"); /* Entry field text colour */ plot_style_even.itext = plot_style_even.text; @@ -3484,13 +3484,13 @@ static void treeview_init_plot_styles(int font_pt_size) /* Selected background colour */ plot_style_even.sbg = plot_style_even.bg; - plot_style_even.sbg.fill_colour = gui_system_colour_char("Highlight"); + plot_style_even.sbg.fill_colour = ns_system_colour_char("Highlight"); /* Selected text colour */ plot_style_even.stext = plot_style_even.text; plot_style_even.stext.foreground = - gui_system_colour_char("HighlightText"); - plot_style_even.stext.background = gui_system_colour_char("Highlight"); + ns_system_colour_char("HighlightText"); + plot_style_even.stext.background = ns_system_colour_char("Highlight"); /* Selected entry field text colour */ plot_style_even.sitext = plot_style_even.stext; From 303a29a89c966d48ee349fc1a350777d981bd683 Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Fri, 10 Jan 2014 15:55:29 +0000 Subject: [PATCH 070/773] cleanups to fix new clang warnings --- content/dirlist.c | 2 -- render/imagemap.c | 8 ++++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/content/dirlist.c b/content/dirlist.c index 433e21026..0c0e2aee2 100644 --- a/content/dirlist.c +++ b/content/dirlist.c @@ -27,8 +27,6 @@ #include "content/dirlist.h" #include "utils/messages.h" -static const char footer[] = "
\n\n\n"; - static int dirlist_filesize_calculate(unsigned long *bytesize); static int dirlist_filesize_value(unsigned long bytesize); static char* dirlist_filesize_unit(unsigned long bytesize); diff --git a/render/imagemap.c b/render/imagemap.c index 433ae68be..870db7e3a 100644 --- a/render/imagemap.c +++ b/render/imagemap.c @@ -524,7 +524,7 @@ imagemap_addtolist(dom_node *n, nsurl *base_url, } num++; - val = strtok('\0', ","); + val = strtok(NULL, ","); } break; case IMAGEMAP_CIRCLE: @@ -543,7 +543,7 @@ imagemap_addtolist(dom_node *n, nsurl *base_url, } num++; - val = strtok('\0', ","); + val = strtok(NULL, ","); } break; case IMAGEMAP_POLY: @@ -553,7 +553,7 @@ imagemap_addtolist(dom_node *n, nsurl *base_url, while (val != NULL) { x = atoi(val); - val = strtok('\0', ","); + val = strtok(NULL, ","); if (val == NULL) break; @@ -577,7 +577,7 @@ imagemap_addtolist(dom_node *n, nsurl *base_url, new_map->bounds.poly.ycoords[num - 1] = y; num++; - val = strtok('\0', ","); + val = strtok(NULL, ","); } new_map->bounds.poly.num = num - 1; From ef76dd468d5eefbad32ebfd2486ff79bb39c080a Mon Sep 17 00:00:00 2001 From: Chris Young Date: Fri, 10 Jan 2014 20:03:22 +0000 Subject: [PATCH 071/773] Tentatively enable AmigaGuide help --- amiga/gui.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/amiga/gui.c b/amiga/gui.c index 3a0dd97c5..f223fc6ab 100644 --- a/amiga/gui.c +++ b/amiga/gui.c @@ -399,7 +399,7 @@ void ami_open_resources(void) TAG_DONE))) die(messages_get("NoMemory")); ami_file_req_init(); - //ami_help_init(NULL); + ami_help_init(NULL); } static UWORD ami_system_colour_scrollbar_fgpen(struct DrawInfo *drinfo) @@ -760,7 +760,7 @@ void ami_openscreen(void) ami_font_setdevicedpi(id); ami_set_screen_defaults(scrn); - //ami_help_new_screen(scrn); + ami_help_new_screen(scrn); } void ami_openscreenfirst(void) @@ -2120,7 +2120,7 @@ void ami_handle_msg(void) break; case RAWKEY_HELP: // help - //ami_help_open(AMI_HELP_GUI); + ami_help_open(AMI_HELP_GUI); break; } } @@ -2769,7 +2769,7 @@ void gui_quit(void) FreeSysObject(ASOT_PORT,appport); FreeSysObject(ASOT_PORT,sport); - //ami_help_free(); + ami_help_free(); ami_file_req_free(); ami_openurl_close(); From 9fd344172a27e63f7be1eca5131efa738d368356 Mon Sep 17 00:00:00 2001 From: Chris Young Date: Fri, 10 Jan 2014 20:32:20 +0000 Subject: [PATCH 072/773] Enforce the use of popupmenu.library >=53.11 Older versions have a dangerous bug which manifests itself as a deadlock or a crash. --- amiga/gui.c | 18 +++++++++++++++++- amiga/gui.h | 2 ++ amiga/gui_options.c | 1 + 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/amiga/gui.c b/amiga/gui.c index f223fc6ab..296132712 100644 --- a/amiga/gui.c +++ b/amiga/gui.c @@ -87,6 +87,7 @@ #include #include #include +#include #include #include @@ -580,9 +581,11 @@ static nserror ami_set_options(struct nsoption_s *defaults) } } + if(popupmenu_lib_ok == FALSE) + nsoption_set_bool(context_menu, false); + #ifndef __amigaos4__ nsoption_set_bool(download_notify, false); - nsoption_set_bool(context_menu, false); nsoption_set_bool(font_antialiasing, false); nsoption_set_bool(truecolour_mouse_pointers, false); #endif @@ -999,6 +1002,19 @@ int main(int argc, char** argv) nserror ret; Object *splash_window = ami_gui_splash_open(); + /* Open popupmenu.library just to check the version. + * Versions older than 53.11 are dangerous, so we + * forcibly disable context menus if these are in use. + */ + popupmenu_lib_ok = FALSE; + if(PopupMenuBase = OpenLibrary("popupmenu.library", 53)) { + LOG(("popupmenu.library v%d.%d", + PopupMenuBase->lib_Version, PopupMenuBase->lib_Revision)); + if(LIB_IS_AT_LEAST((struct Library *)PopupMenuBase, 53, 11)) + popupmenu_lib_ok = TRUE; + CloseLibrary(PopupMenuBase); + } + user = GetVar("user", temp, 1024, GVF_GLOBAL_ONLY); current_user = ASPrintf("%s", (user == -1) ? "Default" : temp); current_user_dir = ASPrintf("PROGDIR:Users/%s", current_user); diff --git a/amiga/gui.h b/amiga/gui.h index 4ec329eb8..947066063 100755 --- a/amiga/gui.h +++ b/amiga/gui.h @@ -176,4 +176,6 @@ struct browser_window *curbw; struct gui_globals browserglob; uint32 ami_appid; BOOL ami_autoscroll; +BOOL popupmenu_lib_ok; #endif + diff --git a/amiga/gui_options.c b/amiga/gui_options.c index 1bf20ad47..a5568dac6 100755 --- a/amiga/gui_options.c +++ b/amiga/gui_options.c @@ -1328,6 +1328,7 @@ void ami_gui_opts_open(void) GA_RelVerify, TRUE, GA_Text, gadlab[GID_OPTS_CONTEXTMENU], GA_Selected, nsoption_bool(context_menu), + GA_Disabled, !popupmenu_lib_ok, CheckBoxEnd, #endif LAYOUT_AddChild, gow->objects[GID_OPTS_FASTSCROLL] = CheckBoxObject, From 78e8077a5a81bbb032146d11f052e30090e552fd Mon Sep 17 00:00:00 2001 From: Chris Young Date: Fri, 10 Jan 2014 20:35:49 +0000 Subject: [PATCH 073/773] Re-enable the RAmiga-U shortcut to activate the URL bar, now it is safe to do so. --- amiga/gui.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/amiga/gui.c b/amiga/gui.c index 296132712..6e5e38f08 100644 --- a/amiga/gui.c +++ b/amiga/gui.c @@ -2063,13 +2063,12 @@ void ami_handle_msg(void) if(browser_window_reload_available(gwin->bw)) browser_window_reload(gwin->bw,false); break; -/* + case 'u': // open url if((nsoption_bool(kiosk_mode) == false)) ActivateLayoutGadget((struct Gadget *)gwin->objects[GID_MAIN], gwin->win, NULL, (uint32)gwin->objects[GID_URL]); break; -*/ } } else From a856439afb743c7fa16f51108862b99a1f56c82a Mon Sep 17 00:00:00 2001 From: Chris Young Date: Fri, 10 Jan 2014 20:46:58 +0000 Subject: [PATCH 074/773] Re-add proper notification of ability to close public screen. --- amiga/gui.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/amiga/gui.c b/amiga/gui.c index 6e5e38f08..3140bb61e 100644 --- a/amiga/gui.c +++ b/amiga/gui.c @@ -160,6 +160,7 @@ Class *urlStringClass; BOOL locked_screen = FALSE; BOOL screen_closed = FALSE; +ULONG screen_signal = -1; struct MsgPort *applibport = NULL; ULONG applibsig = 0; BOOL refresh_search_ico = FALSE; @@ -401,6 +402,7 @@ void ami_open_resources(void) ami_file_req_init(); ami_help_init(NULL); + screen_signal = AllocSignal(-1); /* for screen closure notification */ } static UWORD ami_system_colour_scrollbar_fgpen(struct DrawInfo *drinfo) @@ -730,6 +732,7 @@ void ami_openscreen(void) SA_PubName, "NetSurf", SA_LikeWorkbench, TRUE, SA_Compositing, compositing, + SA_PubSig, screen_signal, TAG_DONE); if(scrn) @@ -2734,15 +2737,16 @@ void ami_quit_netsurf_delayed(void) void ami_gui_close_screen(struct Screen *scrn, BOOL locked_screen) { + ULONG scrnsig = 1 << screen_signal; + if(scrn == NULL) return; if(CloseScreen(scrn)) return; if(locked_screen == TRUE) return; /* If this is our own screen, wait for visitor windows to close */ LOG(("Waiting for visitor windows to close...")); - do { - Delay(50); - } while (CloseScreen(scrn) == FALSE); + Wait(scrnsig); + CloseScreen(scrn); } void gui_quit(void) @@ -2769,6 +2773,7 @@ void gui_quit(void) LOG(("Closing screen")); ami_gui_close_screen(scrn, locked_screen); FreeVec(nsscreentitle); + FreeSignal(screen_signal); LOG(("Freeing menu items")); ami_context_menu_free(); From d3c392c3d3b516f05fbf71020b2f6774ce20ce8c Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Sat, 11 Jan 2014 14:20:30 +0000 Subject: [PATCH 075/773] Initial conversion of netsurf gui to callback vtable --- amiga/gui.c | 183 ++++++++++++++++--------------- atari/gui.c | 11 +- beos/gui.cpp | 248 +++++++++++++++++++++--------------------- beos/scaffolding.cpp | 4 - cocoa/NetsurfApp.m | 2 +- cocoa/gui.h | 2 + cocoa/gui.m | 13 ++- desktop/Makefile | 2 +- desktop/gui.h | 36 ++++-- desktop/gui_factory.c | 33 ++++++ desktop/gui_factory.h | 30 +++++ desktop/netsurf.c | 12 +- desktop/netsurf.h | 4 +- framebuffer/gui.c | 202 +++++++++++++++++----------------- gtk/gui.c | 207 ++++++++++++++++++----------------- monkey/main.c | 9 +- monkey/poll.c | 2 +- monkey/poll.h | 2 + riscos/gui.c | 12 +- windows/main.c | 12 +- 20 files changed, 574 insertions(+), 452 deletions(-) create mode 100644 desktop/gui_factory.c create mode 100644 desktop/gui_factory.h diff --git a/amiga/gui.c b/amiga/gui.c index 3140bb61e..2037ba41c 100644 --- a/amiga/gui.c +++ b/amiga/gui.c @@ -993,93 +993,6 @@ static void gui_init2(int argc, char** argv) } } -/** Normal entry point from OS */ -int main(int argc, char** argv) -{ - setbuf(stderr, NULL); - char messages[100]; - char script[1024]; - char temp[1024]; - BPTR lock = 0; - int32 user = 0; - nserror ret; - Object *splash_window = ami_gui_splash_open(); - - /* Open popupmenu.library just to check the version. - * Versions older than 53.11 are dangerous, so we - * forcibly disable context menus if these are in use. - */ - popupmenu_lib_ok = FALSE; - if(PopupMenuBase = OpenLibrary("popupmenu.library", 53)) { - LOG(("popupmenu.library v%d.%d", - PopupMenuBase->lib_Version, PopupMenuBase->lib_Revision)); - if(LIB_IS_AT_LEAST((struct Library *)PopupMenuBase, 53, 11)) - popupmenu_lib_ok = TRUE; - CloseLibrary(PopupMenuBase); - } - - user = GetVar("user", temp, 1024, GVF_GLOBAL_ONLY); - current_user = ASPrintf("%s", (user == -1) ? "Default" : temp); - current_user_dir = ASPrintf("PROGDIR:Users/%s", current_user); - - if(lock = CreateDirTree(current_user_dir)) - UnLock(lock); - - current_user_options = ASPrintf("%s/Choices", current_user_dir); - - ami_mime_init("PROGDIR:Resources/mimetypes"); - sprintf(temp, "%s/mimetypes.user", current_user_dir); - ami_mime_init(temp); - ami_schedule_open_timer(); - ami_schedule_create(); - - amiga_plugin_hack_init(); - amiga_datatypes_init(); - - /* initialise logging. Not fatal if it fails but not much we - * can do about it either. - */ - nslog_init(NULL, &argc, argv); - - /* user options setup */ - ret = nsoption_init(ami_set_options, &nsoptions, &nsoptions_default); - if (ret != NSERROR_OK) { - die("Options failed to initialise"); - } - nsoption_read(current_user_options, NULL); - nsoption_commandline(&argc, argv, NULL); - - if(ami_locate_resource(messages, "Messages") == false) - die("Cannot open Messages file"); - - ret = netsurf_init(messages); - if (ret != NSERROR_OK) { - die("NetSurf failed to initialise"); - } - - amiga_icon_init(); - - gui_init(argc, argv); - gui_init2(argc, argv); - - ami_gui_splash_close(splash_window); - - strlcpy(script, nsoption_charp(arexx_dir), 1024); - AddPart(script, nsoption_charp(arexx_startup), 1024); - ami_arexx_execute(script); - - netsurf_main_loop(); - - strlcpy(script, nsoption_charp(arexx_dir), 1024); - AddPart(script, nsoption_charp(arexx_shutdown), 1024); - ami_arexx_execute(script); - - netsurf_exit(); - - ami_mime_free(); - - return 0; -} void ami_gui_history(struct gui_window_2 *gwin, bool back) { @@ -2567,7 +2480,7 @@ static void ami_gui_fetch_callback(void *p) */ } -void gui_poll(bool active) +static void gui_poll(bool active) { if(active) schedule(0, ami_gui_fetch_callback, NULL); ami_get_msg(); @@ -2749,7 +2662,7 @@ void ami_gui_close_screen(struct Screen *scrn, BOOL locked_screen) CloseScreen(scrn); } -void gui_quit(void) +static void gui_quit(void) { int i; @@ -5177,3 +5090,95 @@ void gui_file_gadget_open(struct gui_window *g, hlcache_handle *hl, } } +static struct gui_table ami_gui_table = { + .poll = &gui_poll, + .quit = &gui_quit, +}; + +/** Normal entry point from OS */ +int main(int argc, char** argv) +{ + setbuf(stderr, NULL); + char messages[100]; + char script[1024]; + char temp[1024]; + BPTR lock = 0; + int32 user = 0; + nserror ret; + Object *splash_window = ami_gui_splash_open(); + + /* Open popupmenu.library just to check the version. + * Versions older than 53.11 are dangerous, so we + * forcibly disable context menus if these are in use. + */ + popupmenu_lib_ok = FALSE; + if(PopupMenuBase = OpenLibrary("popupmenu.library", 53)) { + LOG(("popupmenu.library v%d.%d", + PopupMenuBase->lib_Version, PopupMenuBase->lib_Revision)); + if(LIB_IS_AT_LEAST((struct Library *)PopupMenuBase, 53, 11)) + popupmenu_lib_ok = TRUE; + CloseLibrary(PopupMenuBase); + } + + user = GetVar("user", temp, 1024, GVF_GLOBAL_ONLY); + current_user = ASPrintf("%s", (user == -1) ? "Default" : temp); + current_user_dir = ASPrintf("PROGDIR:Users/%s", current_user); + + if(lock = CreateDirTree(current_user_dir)) + UnLock(lock); + + current_user_options = ASPrintf("%s/Choices", current_user_dir); + + ami_mime_init("PROGDIR:Resources/mimetypes"); + sprintf(temp, "%s/mimetypes.user", current_user_dir); + ami_mime_init(temp); + ami_schedule_open_timer(); + ami_schedule_create(); + + amiga_plugin_hack_init(); + amiga_datatypes_init(); + + /* initialise logging. Not fatal if it fails but not much we + * can do about it either. + */ + nslog_init(NULL, &argc, argv); + + /* user options setup */ + ret = nsoption_init(ami_set_options, &nsoptions, &nsoptions_default); + if (ret != NSERROR_OK) { + die("Options failed to initialise"); + } + nsoption_read(current_user_options, NULL); + nsoption_commandline(&argc, argv, NULL); + + if (ami_locate_resource(messages, "Messages") == false) + die("Cannot open Messages file"); + + ret = netsurf_init(messages, &ami_gui_table); + if (ret != NSERROR_OK) { + die("NetSurf failed to initialise"); + } + + amiga_icon_init(); + + gui_init(argc, argv); + gui_init2(argc, argv); + + ami_gui_splash_close(splash_window); + + strlcpy(script, nsoption_charp(arexx_dir), 1024); + AddPart(script, nsoption_charp(arexx_startup), 1024); + ami_arexx_execute(script); + + netsurf_main_loop(); + + strlcpy(script, nsoption_charp(arexx_dir), 1024); + AddPart(script, nsoption_charp(arexx_shutdown), 1024); + ami_arexx_execute(script); + + netsurf_exit(); + + ami_mime_free(); + + return 0; +} diff --git a/atari/gui.c b/atari/gui.c index e02c5434a..a5657368c 100644 --- a/atari/gui.c +++ b/atari/gui.c @@ -115,7 +115,7 @@ short aes_msg_out[8]; -void gui_poll(bool active) +static void gui_poll(bool active) { struct gui_window *tmp; @@ -854,7 +854,7 @@ struct gui_window * gui_get_input_window(void) return(input_window); } -void gui_quit(void) +static void gui_quit(void) { LOG(("")); @@ -1105,6 +1105,11 @@ void gui_file_gadget_open(struct gui_window *g, hlcache_handle *hl, /* browser_window_set_gadget_filename(bw, gadget, "filename"); */ } +static struct gui_table atari_gui_table = { + .poll = &gui_poll, + .quit = &gui_quit, +}; + /* #define WITH_DBG_LOGFILE 1 */ /** Entry point from OS. * @@ -1153,7 +1158,7 @@ int main(int argc, char** argv) /* common initialisation */ LOG(("Initialising core...")); - ret = netsurf_init(messages); + ret = netsurf_init(messages, atari_gui_table); if (ret != NSERROR_OK) { die("NetSurf failed to initialise"); } diff --git a/beos/gui.cpp b/beos/gui.cpp index 32bd3a2d5..486085de3 100644 --- a/beos/gui.cpp +++ b/beos/gui.cpp @@ -78,8 +78,6 @@ extern "C" { static void *myrealloc(void *ptr, size_t len, void *pw); -void gui_init(int argc, char** argv); - /* Where to search for shared resources. Must have trailing / */ #define RESPATH "/boot/apps/netsurf/res/" @@ -367,42 +365,6 @@ nsurl *gui_get_resource_url(const char *path) return url; } -static void gui_init2(int argc, char** argv) -{ - const char *addr; - nsurl *url; - nserror error; - - if (argc > 1) { - addr = argv[1]; - } else if (nsoption_charp(homepage_url) != NULL) { - addr = nsoption_charp(homepage_url); - } else { - addr = NETSURF_HOMEPAGE; - } - - /* create an initial browser window */ - error = nsurl_create(addr, &url); - if (error == NSERROR_OK) { - error = browser_window_create((browser_window_nav_flags) - (BROWSER_WINDOW_VERIFIABLE | BROWSER_WINDOW_HISTORY), - url, - NULL, - NULL, - NULL); - nsurl_unref(url); - } - if (error != NSERROR_OK) { - warn_user(messages_get_errorcode(error), 0); - } - - if (gFirstRefsReceived) { - // resend the refs we got before having a window to send them to - be_app_messenger.SendMessage(gFirstRefsReceived); - delete gFirstRefsReceived; - gFirstRefsReceived = NULL; - } -} #if !defined(__HAIKU__) && !defined(B_BEOS_VERSION_DANO) @@ -532,91 +494,12 @@ static BPath get_messages_path() return p; } -/** Normal entry point from OS */ -int main(int argc, char** argv) -{ - nserror ret; - BPath options; - if (find_directory(B_USER_SETTINGS_DIRECTORY, &options, true) == B_OK) { - options.Append("x-vnd.NetSurf"); - } - - if (!replicated) { - // create the Application object before trying to use messages - // so we can open an alert in case of error. - new NSBrowserApplication; - } - - /* initialise logging. Not fatal if it fails but not much we - * can do about it either. - */ - nslog_init(nslog_stream_configure, &argc, argv); - - /* user options setup */ - ret = nsoption_init(set_defaults, &nsoptions, &nsoptions_default); - if (ret != NSERROR_OK) { - die("Options failed to initialise"); - } - nsoption_read(options.Path(), NULL); - nsoption_commandline(&argc, argv, NULL); - - /* common initialisation */ - BPath messages = get_messages_path(); - ret = netsurf_init(messages.Path()); - if (ret != NSERROR_OK) { - die("NetSurf failed to initialise"); - } - - gui_init(argc, argv); - gui_init2(argc, argv); - - netsurf_main_loop(); - - netsurf_exit(); - - return 0; -} - -/** called when replicated from NSBaseView::Instantiate() */ -int gui_init_replicant(int argc, char** argv) -{ - nserror ret; - BPath options; - if (find_directory(B_USER_SETTINGS_DIRECTORY, &options, true) == B_OK) { - options.Append("x-vnd.NetSurf"); - } - - /* initialise logging. Not fatal if it fails but not much we - * can do about it either. - */ - nslog_init(nslog_stream_configure, &argc, argv); - - // FIXME: use options as readonly for replicants - /* user options setup */ - ret = nsoption_init(set_defaults, &nsoptions, &nsoptions_default); - if (ret != NSERROR_OK) { - // FIXME: must not die when in replicant! - die("Options failed to initialise"); - } - nsoption_read(options.Path(), NULL); - nsoption_commandline(&argc, argv, NULL); - - /* common initialisation */ - BPath messages = get_messages_path(); - ret = netsurf_init(messages.Path()); - if (ret != NSERROR_OK) { - // FIXME: must not die when in replicant! - die("NetSurf failed to initialise"); - } - - gui_init(argc, argv); - gui_init2(argc, argv); - - return 0; -} - -void gui_init(int argc, char** argv) + +static void gui_init(int argc, char** argv) { + const char *addr; + nsurl *url; + nserror error; char buf[PATH_MAX]; if (pipe(sEventPipe) < 0) @@ -746,6 +629,36 @@ void gui_init(int argc, char** argv) if (!replicated) be_app->Unlock(); + if (argc > 1) { + addr = argv[1]; + } else if (nsoption_charp(homepage_url) != NULL) { + addr = nsoption_charp(homepage_url); + } else { + addr = NETSURF_HOMEPAGE; + } + + /* create an initial browser window */ + error = nsurl_create(addr, &url); + if (error == NSERROR_OK) { + error = browser_window_create((browser_window_nav_flags) + (BROWSER_WINDOW_VERIFIABLE | BROWSER_WINDOW_HISTORY), + url, + NULL, + NULL, + NULL); + nsurl_unref(url); + } + if (error != NSERROR_OK) { + warn_user(messages_get_errorcode(error), 0); + } + + if (gFirstRefsReceived) { + // resend the refs we got before having a window to send them to + be_app_messenger.SendMessage(gFirstRefsReceived); + delete gFirstRefsReceived; + gFirstRefsReceived = NULL; + } + } @@ -783,7 +696,7 @@ void nsbeos_pipe_message_top(BMessage *message, BWindow *_this, struct beos_scaf } -void gui_poll(bool active) +static void gui_poll(bool active) { CURLMcode code; fd_set read_fd_set, write_fd_set, exc_fd_set; @@ -858,7 +771,7 @@ void gui_poll(bool active) } -void gui_quit(void) +static void gui_quit(void) { urldb_save_cookies(nsoption_charp(cookie_jar)); urldb_save(nsoption_charp(url_file)); @@ -1172,3 +1085,90 @@ void gui_file_gadget_open(struct gui_window *g, hlcache_handle *hl, /* browser_window_set_gadget_filename(bw, gadget, "filename"); */ } + +static struct gui_table beos_gui_table = { + .poll = &gui_poll, + .quit = &gui_quit, +}; + + +/** Normal entry point from OS */ +int main(int argc, char** argv) +{ + nserror ret; + BPath options; + if (find_directory(B_USER_SETTINGS_DIRECTORY, &options, true) == B_OK) { + options.Append("x-vnd.NetSurf"); + } + + if (!replicated) { + // create the Application object before trying to use messages + // so we can open an alert in case of error. + new NSBrowserApplication; + } + + /* initialise logging. Not fatal if it fails but not much we + * can do about it either. + */ + nslog_init(nslog_stream_configure, &argc, argv); + + /* user options setup */ + ret = nsoption_init(set_defaults, &nsoptions, &nsoptions_default); + if (ret != NSERROR_OK) { + die("Options failed to initialise"); + } + nsoption_read(options.Path(), NULL); + nsoption_commandline(&argc, argv, NULL); + + /* common initialisation */ + BPath messages = get_messages_path(); + ret = netsurf_init(messages.Path(), &beos_gui_table); + if (ret != NSERROR_OK) { + die("NetSurf failed to initialise"); + } + + gui_init(argc, argv); + + netsurf_main_loop(); + + netsurf_exit(); + + return 0; +} + +/** called when replicated from NSBaseView::Instantiate() */ +int gui_init_replicant(int argc, char** argv) +{ + nserror ret; + BPath options; + if (find_directory(B_USER_SETTINGS_DIRECTORY, &options, true) == B_OK) { + options.Append("x-vnd.NetSurf"); + } + + /* initialise logging. Not fatal if it fails but not much we + * can do about it either. + */ + nslog_init(nslog_stream_configure, &argc, argv); + + // FIXME: use options as readonly for replicants + /* user options setup */ + ret = nsoption_init(set_defaults, &nsoptions, &nsoptions_default); + if (ret != NSERROR_OK) { + // FIXME: must not die when in replicant! + die("Options failed to initialise"); + } + nsoption_read(options.Path(), NULL); + nsoption_commandline(&argc, argv, NULL); + + /* common initialisation */ + BPath messages = get_messages_path(); + ret = netsurf_init(messages.Path(), &beos_gui_table); + if (ret != NSERROR_OK) { + // FIXME: must not die when in replicant! + die("NetSurf failed to initialise"); + } + + gui_init(argc, argv); + + return 0; +} diff --git a/beos/scaffolding.cpp b/beos/scaffolding.cpp index 06184f24e..51235b6d0 100644 --- a/beos/scaffolding.cpp +++ b/beos/scaffolding.cpp @@ -558,10 +558,6 @@ NSBaseView::Instantiate(BMessage *archive) replicated = true; //TODO:FIXME: fix replicants - // netsurf_init() needs different args now... - //netsurf_init(2, info->args); - //return NULL; - // do as much as possible in this thread to avoid deadlocks gui_init_replicant(2, info->args); diff --git a/cocoa/NetsurfApp.m b/cocoa/NetsurfApp.m index 33e3bfa43..844904f1c 100644 --- a/cocoa/NetsurfApp.m +++ b/cocoa/NetsurfApp.m @@ -203,7 +203,7 @@ int main( int argc, char **argv ) nsoption_commandline(&argc, argv, NULL); /* common initialisation */ - error = netsurf_init(messages); + error = netsurf_init(messages, cocoa_gui_table); if (error != NSERROR_OK) { die("NetSurf failed to initialise"); } diff --git a/cocoa/gui.h b/cocoa/gui.h index 413727fe6..6ceefa848 100644 --- a/cocoa/gui.h +++ b/cocoa/gui.h @@ -27,3 +27,5 @@ extern NSString * const kAlwaysCancelDownload; extern NSString * const kAlwaysCloseMultipleTabs; void cocoa_autorelease( void ); + +extern struct gui_table *cocoa_gui_table; diff --git a/cocoa/gui.m b/cocoa/gui.m index 72f64bf04..425bd9cb7 100644 --- a/cocoa/gui.m +++ b/cocoa/gui.m @@ -55,7 +55,7 @@ nsurl *gui_get_resource_url(const char *path) return url; } -void gui_poll(bool active) +static void gui_poll(bool active) { cocoa_autorelease(); @@ -68,11 +68,6 @@ void gui_poll(bool active) } } -void gui_quit(void) -{ - // nothing to do -} - struct browser_window; struct gui_window *gui_create_browser_window(struct browser_window *bw, @@ -332,3 +327,9 @@ void gui_file_gadget_open(struct gui_window *g, hlcache_handle *hl, /* browser_window_set_gadget_filename(bw, gadget, "filename"); */ } +static struct gui_table gui_table = { + .poll = &gui_poll, +}; + +struct gui_table *cocoa_gui_table = &gui_table; + diff --git a/desktop/Makefile b/desktop/Makefile index f7020074e..0e2e460de 100644 --- a/desktop/Makefile +++ b/desktop/Makefile @@ -13,7 +13,7 @@ desktop/version.c: testament utils/testament.h # S_BROWSER are sources related to full browsers but are common # between RISC OS, GTK, BeOS and AmigaOS builds S_BROWSER := browser.c download.c frames.c local_history.c netsurf.c \ - save_complete.c save_text.c selection.c textinput.c + save_complete.c save_text.c selection.c textinput.c gui_factory.c S_BROWSER := $(addprefix desktop/,$(S_BROWSER)) diff --git a/desktop/gui.h b/desktop/gui.h index 9317e8576..2bda996fd 100644 --- a/desktop/gui.h +++ b/desktop/gui.h @@ -24,6 +24,18 @@ #ifndef _NETSURF_DESKTOP_GUI_H_ #define _NETSURF_DESKTOP_GUI_H_ +#include + +#include +#include + +#include "utils/config.h" +#include "content/hlcache.h" +#include "desktop/download.h" +#include "desktop/mouse.h" +#include "desktop/search.h" +#include "utils/errors.h" + typedef enum { GUI_SAVE_SOURCE, GUI_SAVE_DRAW, @@ -53,20 +65,22 @@ struct gui_download_window; struct browser_window; struct form_control; -#include +/** Graphical user interface function table + * + * function table implementing GUI interface to browser core + */ +struct gui_table { + /** called to let the frontend update its state and run any + * I/O operations. + */ + void (*poll)(bool active); /* Mandantory */ -#include -#include + /** called to allow the gui to cleanup */ + void (*quit)(void); /* optional */ -#include "utils/config.h" -#include "content/hlcache.h" -#include "desktop/download.h" -#include "desktop/mouse.h" -#include "desktop/search.h" -#include "utils/errors.h" +}; -void gui_poll(bool active); -void gui_quit(void); +extern struct gui_table *guit; /* the gui vtable */ struct gui_window *gui_create_browser_window(struct browser_window *bw, struct browser_window *clone, bool new_tab); diff --git a/desktop/gui_factory.c b/desktop/gui_factory.c new file mode 100644 index 000000000..fe7536353 --- /dev/null +++ b/desktop/gui_factory.c @@ -0,0 +1,33 @@ + +#include "desktop/gui.h" +#include "desktop/gui_factory.h" + +struct gui_table *guit = NULL; + + +static void gui_default_quit(void) +{ +} + +nserror gui_factory_register(struct gui_table *gt) +{ + /* ensure not already initialised */ + if (guit != NULL) { + return NSERROR_INIT_FAILED; + } + + /* check the mandantory fields are set */ + + if (gt->poll == NULL) { + return NSERROR_BAD_PARAMETER; + } + + /* fill in the optional entries with defaults */ + if (gt->quit == NULL) { + gt->quit = &gui_default_quit; + } + + guit = gt; + + return NSERROR_OK; +} diff --git a/desktop/gui_factory.h b/desktop/gui_factory.h new file mode 100644 index 000000000..66303eac1 --- /dev/null +++ b/desktop/gui_factory.h @@ -0,0 +1,30 @@ +/* + * Copyright 2014 vincent Sanders + * + * This file is part of NetSurf, http://www.netsurf-browser.org/ + * + * NetSurf is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * NetSurf is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** \file + * Interface to gui interface factory + */ + +#ifndef _NETSURF_DESKTOP_GUI_FACTORY_H_ +#define _NETSURF_DESKTOP_GUI_FACTORY_H_ + +struct gui_table; + +nserror gui_factory_register(struct gui_table *gt); + +#endif diff --git a/desktop/netsurf.c b/desktop/netsurf.c index 36b0b589a..10dc7ba68 100644 --- a/desktop/netsurf.c +++ b/desktop/netsurf.c @@ -41,6 +41,7 @@ #include "desktop/browser.h" #include "desktop/system_colour.h" #include "desktop/gui.h" +#include "desktop/gui_factory.h" #include "utils/nsoption.h" #include "desktop/searchweb.h" @@ -116,7 +117,7 @@ static nserror netsurf_llcache_query_handler(const llcache_query *query, * Initialise components used by gui NetSurf. */ -nserror netsurf_init(const char *messages) +nserror netsurf_init(const char *messages, struct gui_table *gt) { nserror error; struct utsname utsname; @@ -150,6 +151,11 @@ nserror netsurf_init(const char *messages) utsname.nodename, utsname.release, utsname.version, utsname.machine)); + /* register the gui handlers */ + error = gui_factory_register(gt); + if (error != NSERROR_OK) + return error; + messages_load(messages); /* corestrings init */ @@ -228,7 +234,7 @@ nserror netsurf_init(const char *messages) int netsurf_main_loop(void) { while (!netsurf_quit) { - gui_poll(fetch_active); + guit->poll(fetch_active); hlcache_poll(); } @@ -244,7 +250,7 @@ void netsurf_exit(void) hlcache_stop(); LOG(("Closing GUI")); - gui_quit(); + guit->quit(); LOG(("Finalising JavaScript")); js_finalise(); diff --git a/desktop/netsurf.h b/desktop/netsurf.h index aa1796f7c..e6858ad66 100644 --- a/desktop/netsurf.h +++ b/desktop/netsurf.h @@ -28,8 +28,10 @@ extern const char * const netsurf_version; extern const int netsurf_version_major; extern const int netsurf_version_minor; +struct gui_table; + /** Initialise netsurf core */ -nserror netsurf_init(const char *messages); +nserror netsurf_init(const char *messages, struct gui_table *gt); /** Run primary event loop */ extern int netsurf_main_loop(void); diff --git a/framebuffer/gui.c b/framebuffer/gui.c index 08cb31318..1439c3c2d 100644 --- a/framebuffer/gui.c +++ b/framebuffer/gui.c @@ -555,104 +555,9 @@ static bool nslog_stream_configure(FILE *fptr) return true; } -/** Entry point from OS. - * - * /param argc The number of arguments in the string vector. - * /param argv The argument string vector. - * /return The return code to the OS - */ -int -main(int argc, char** argv) -{ - struct browser_window *bw; - char *options; - char *messages; - nsurl *url; - nserror ret; - nsfb_t *nsfb; - - respaths = fb_init_resource(NETSURF_FB_RESPATH":"NETSURF_FB_FONTPATH); - - /* initialise logging. Not fatal if it fails but not much we - * can do about it either. - */ - nslog_init(nslog_stream_configure, &argc, argv); - - /* user options setup */ - ret = nsoption_init(set_defaults, &nsoptions, &nsoptions_default); - if (ret != NSERROR_OK) { - die("Options failed to initialise"); - } - options = filepath_find(respaths, "Choices"); - nsoption_read(options, nsoptions); - free(options); - nsoption_commandline(&argc, argv, nsoptions); - - /* common initialisation */ - messages = filepath_find(respaths, "Messages"); - ret = netsurf_init(messages); - free(messages); - if (ret != NSERROR_OK) { - die("NetSurf failed to initialise"); - } - - /* Override, since we have no support for non-core SELECT menu */ - nsoption_set_bool(core_select_menu, true); - - if (process_cmdline(argc,argv) != true) - die("unable to process command line.\n"); - - nsfb = framebuffer_initialise(fename, fewidth, feheight, febpp); - if (nsfb == NULL) - die("Unable to initialise framebuffer"); - - framebuffer_set_cursor(&pointer_image); - - if (fb_font_init() == false) - die("Unable to initialise the font system"); - - fbtk = fbtk_init(nsfb); - - fbtk_enable_oskb(fbtk); - - urldb_load_cookies(nsoption_charp(cookie_file)); - - /* create an initial browser window */ - - LOG(("calling browser_window_create")); - - ret = nsurl_create(feurl, &url); - if (ret == NSERROR_OK) { - ret = browser_window_create(BROWSER_WINDOW_VERIFIABLE | - BROWSER_WINDOW_HISTORY, - url, - NULL, - NULL, - &bw); - nsurl_unref(url); - } - if (ret != NSERROR_OK) { - warn_user(messages_get_errorcode(ret), 0); - } else { - netsurf_main_loop(); - - browser_window_destroy(bw); - } - - netsurf_exit(); - - if (fb_font_finalise() == false) - LOG(("Font finalisation failed.")); - - /* finalise options */ - nsoption_finalise(nsoptions, nsoptions_default); - - return 0; -} -void -gui_poll(bool active) +static void gui_poll(bool active) { nsfb_event_t event; int timeout; /* timeout in miliseconds */ @@ -678,8 +583,7 @@ gui_poll(bool active) } -void -gui_quit(void) +static void gui_quit(void) { LOG(("gui_quit")); @@ -1995,6 +1899,108 @@ void gui_file_gadget_open(struct gui_window *g, hlcache_handle *hl, /* browser_window_set_gadget_filename(bw, gadget, "filename"); */ } + +static struct gui_table framebuffer_gui_table = { + .poll = &gui_poll, + .quit = &gui_quit, +}; + +/** Entry point from OS. + * + * /param argc The number of arguments in the string vector. + * /param argv The argument string vector. + * /return The return code to the OS + */ +int +main(int argc, char** argv) +{ + struct browser_window *bw; + char *options; + char *messages; + nsurl *url; + nserror ret; + nsfb_t *nsfb; + + respaths = fb_init_resource(NETSURF_FB_RESPATH":"NETSURF_FB_FONTPATH); + + /* initialise logging. Not fatal if it fails but not much we + * can do about it either. + */ + nslog_init(nslog_stream_configure, &argc, argv); + + /* user options setup */ + ret = nsoption_init(set_defaults, &nsoptions, &nsoptions_default); + if (ret != NSERROR_OK) { + die("Options failed to initialise"); + } + options = filepath_find(respaths, "Choices"); + nsoption_read(options, nsoptions); + free(options); + nsoption_commandline(&argc, argv, nsoptions); + + /* common initialisation */ + messages = filepath_find(respaths, "Messages"); + ret = netsurf_init(messages, &framebuffer_gui_table); + free(messages); + if (ret != NSERROR_OK) { + die("NetSurf failed to initialise"); + } + + /* Override, since we have no support for non-core SELECT menu */ + nsoption_set_bool(core_select_menu, true); + + if (process_cmdline(argc,argv) != true) + die("unable to process command line.\n"); + + nsfb = framebuffer_initialise(fename, fewidth, feheight, febpp); + if (nsfb == NULL) + die("Unable to initialise framebuffer"); + + framebuffer_set_cursor(&pointer_image); + + if (fb_font_init() == false) + die("Unable to initialise the font system"); + + fbtk = fbtk_init(nsfb); + + fbtk_enable_oskb(fbtk); + + urldb_load_cookies(nsoption_charp(cookie_file)); + + /* create an initial browser window */ + + LOG(("calling browser_window_create")); + + ret = nsurl_create(feurl, &url); + if (ret == NSERROR_OK) { + ret = browser_window_create(BROWSER_WINDOW_VERIFIABLE | + BROWSER_WINDOW_HISTORY, + url, + NULL, + NULL, + &bw); + nsurl_unref(url); + } + if (ret != NSERROR_OK) { + warn_user(messages_get_errorcode(ret), 0); + } else { + netsurf_main_loop(); + + browser_window_destroy(bw); + } + + netsurf_exit(); + + if (fb_font_finalise() == false) + LOG(("Font finalisation failed.")); + + /* finalise options */ + nsoption_finalise(nsoptions, nsoptions_default); + + return 0; +} + + /* * Local Variables: * c-basic-offset:8 diff --git a/gtk/gui.c b/gtk/gui.c index 77b72f874..da602e189 100644 --- a/gtk/gui.c +++ b/gtk/gui.c @@ -183,7 +183,7 @@ nsgtk_new_ui(char **respath, const char *name, GtkBuilder **pglade) filepath = filepath_find(respath, resname); if (filepath == NULL) { - snprintf(errorstr, NEW_GLADE_ERROR_SIZE, + snprintf(errorstr, NEW_GLADE_ERROR_SIZE, "Unable to locate %s glade template file.\n", name); die(errorstr); } @@ -192,7 +192,7 @@ nsgtk_new_ui(char **respath, const char *name, GtkBuilder **pglade) if (!gtk_builder_add_from_file(builder, filepath, &error)) { g_warning ("Couldn't load builder file: %s", error->message); g_error_free (error); - snprintf(errorstr, NEW_GLADE_ERROR_SIZE, + snprintf(errorstr, NEW_GLADE_ERROR_SIZE, "Unable to load glade %s window definitions.\n", name); die(errorstr); @@ -212,7 +212,7 @@ nsgtk_new_ui(char **respath, const char *name, GtkBuilder **pglade) /** * Load definitions from glade files. */ -static void +static void nsgtk_init_glade(char **respath) { GtkBuilder *gladeWarning; @@ -334,7 +334,7 @@ nsurl *gui_get_resource_url(const char *path) /* favicon.ico -> favicon.png */ if (strcmp(path, "favicon.ico") == 0) - path = "favicon.png"; + path = "favicon.png"; raw = path_to_url(filepath_sfind(respaths, buf, path)); if (raw != NULL) { @@ -357,32 +357,32 @@ static void gui_init(int argc, char** argv, char **respath) nsurl *url; nserror error; - /* find the languages file */ + /* find the languages file */ languages_file_location = filepath_find(respath, "languages"); - if ((languages_file_location == NULL) || + if ((languages_file_location == NULL) || (strlen(languages_file_location) < 10)) { - die("Unable to find resources.\n"); + die("Unable to find resources.\n"); } - /* find the theme list file */ + /* find the theme list file */ themelist_file_location = filepath_find(respath, "themelist"); if ((themelist_file_location != NULL) && (strlen(themelist_file_location) < 10)) { free(themelist_file_location); themelist_file_location = NULL; } - if (themelist_file_location == NULL) { + if (themelist_file_location == NULL) { LOG(("Unable to find themelist - disabling")); } - /* Obtain resources path location. + /* Obtain resources path location. * * Uses the directory the languages file was found in, * @todo find and slaughter all references to this! */ res_dir_location = calloc(1, strlen(languages_file_location) - 8); - memcpy(res_dir_location, - languages_file_location, + memcpy(res_dir_location, + languages_file_location, strlen(languages_file_location) - 9); LOG(("Using '%s' for resource path", res_dir_location)); @@ -411,7 +411,7 @@ static void gui_init(int argc, char** argv, char **respath) free(resource_filename); if (favicon_pixbuf == NULL) { favicon_pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, false, 8, 16,16); - + } } @@ -419,7 +419,7 @@ static void gui_init(int argc, char** argv, char **respath) toolbar_indices_file_location = filepath_find(respath, "toolbarIndices"); LOG(("Using '%s' as custom toolbar settings file", toolbar_indices_file_location)); - /* load throbber images */ + /* load throbber images */ if (nsgtk_throbber_init(respath, THROBBER_FRAMES) == false) die("Unable to load throbber image.\n"); @@ -535,75 +535,15 @@ static void nsgtk_check_homedir(void) */ static bool nslog_stream_configure(FILE *fptr) { - /* set log stream to be non-buffering */ + /* set log stream to be non-buffering */ setbuf(fptr, NULL); return true; } -/** - * Main entry point from OS. - */ -int main(int argc, char** argv) -{ - char *messages; - char *options; - nserror ret; - - /* check home directory is available */ - nsgtk_check_homedir(); - - respaths = nsgtk_init_resource("${HOME}/.netsurf/:${NETSURFRES}:"GTK_RESPATH":./gtk/res"); - - gtk_init(&argc, &argv); - - /* initialise logging. Not fatal if it fails but not much we - * can do about it either. - */ - nslog_init(nslog_stream_configure, &argc, argv); - - /* user options setup */ - ret = nsoption_init(set_defaults, &nsoptions, &nsoptions_default); - if (ret != NSERROR_OK) { - fprintf(stderr, "Options failed to initialise (%s)\n", - messages_get_errorcode(ret)); - return 1; - } - options = filepath_find(respaths, "Choices"); - nsoption_read(options, nsoptions); - free(options); - nsoption_commandline(&argc, argv, nsoptions); - check_options(respaths); /* check user options */ - - /* common initialisation */ - messages = filepath_find(respaths, "Messages"); - ret = netsurf_init(messages); - free(messages); - if (ret != NSERROR_OK) { - fprintf(stderr, "NetSurf core failed to initialise (%s)\n", - messages_get_errorcode(ret)); - return 1; - } - - /* run the browser */ - gui_init(argc, argv, respaths); - - /* Ensure all scaffoldings are destroyed before we go into exit */ - while (scaf_list != NULL) { - nsgtk_scaffolding_destroy(scaf_list); - } - - /* common finalisation */ - netsurf_exit(); - - /* finalise options */ - nsoption_finalise(nsoptions, nsoptions_default); - - return 0; -} -void gui_poll(bool active) +static void gui_poll(bool active) { CURLMcode code; fd_set read_fd_set, write_fd_set, exc_fd_set; @@ -613,7 +553,7 @@ void gui_poll(bool active) bool block = true; schedule_run(); - + if (browser_reformat_pending) block = false; @@ -666,8 +606,15 @@ void gui_poll(bool active) } -void gui_quit(void) +static void gui_quit(void) { + LOG(("Quitting GUI")); + + /* Ensure all scaffoldings are destroyed before we go into exit */ + while (scaf_list != NULL) { + nsgtk_scaffolding_destroy(scaf_list); + } + nsgtk_download_destroy(); urldb_save_cookies(nsoption_charp(cookie_jar)); urldb_save(nsoption_charp(url_file)); @@ -729,7 +676,7 @@ void gui_create_form_select_menu(struct browser_window *bw, } -void gui_window_save_link(struct gui_window *g, const char *url, +void gui_window_save_link(struct gui_window *g, const char *url, const char *title) { } @@ -772,11 +719,11 @@ void die(const char * const error) } -void gui_cert_verify(nsurl *url, const struct ssl_cert_info *certs, +void gui_cert_verify(nsurl *url, const struct ssl_cert_info *certs, unsigned long num, nserror (*cb)(bool proceed, void *pw), void *cbpw) -{ - static struct nsgtk_treeview *ssl_window; +{ + static struct nsgtk_treeview *ssl_window; struct sslcert_session_data *data; GtkButton *accept, *reject; void **session; @@ -784,7 +731,7 @@ void gui_cert_verify(nsurl *url, const struct ssl_cert_info *certs, GtkScrolledWindow *scrolled; GtkDrawingArea *drawing_area; GError* error = NULL; - GtkBuilder* builder; + GtkBuilder* builder; builder = gtk_builder_new (); if (!gtk_builder_add_from_file(builder, glade_file_location->ssl, &error)) { @@ -808,28 +755,28 @@ void gui_cert_verify(nsurl *url, const struct ssl_cert_info *certs, ssl_window = nsgtk_treeview_create(TREE_SSLCERT, window, scrolled, drawing_area); - + if (ssl_window == NULL) { free(session); return; } - + accept = GTK_BUTTON(gtk_builder_get_object(builder, "sslaccept")); - reject = GTK_BUTTON(gtk_builder_get_object(builder, "sslreject")); + reject = GTK_BUTTON(gtk_builder_get_object(builder, "sslreject")); session[0] = builder; session[1] = ssl_window; session[2] = data; - + #define CONNECT(obj, sig, callback, ptr) \ - g_signal_connect(G_OBJECT(obj), (sig), G_CALLBACK(callback), (ptr)) - + g_signal_connect(G_OBJECT(obj), (sig), G_CALLBACK(callback), (ptr)) + CONNECT(accept, "clicked", nsgtk_ssl_accept, session); CONNECT(reject, "clicked", nsgtk_ssl_reject, session); CONNECT(window, "delete_event", G_CALLBACK(nsgtk_ssl_delete_event), (gpointer)session); - - gtk_widget_show(GTK_WIDGET(window)); + + gtk_widget_show(GTK_WIDGET(window)); } void nsgtk_ssl_accept(GtkButton *w, gpointer data) @@ -840,7 +787,7 @@ void nsgtk_ssl_accept(GtkButton *w, gpointer data) struct sslcert_session_data *ssl_data = session[2]; sslcert_viewer_accept(ssl_data); - + nsgtk_treeview_destroy(wnd); g_object_unref(G_OBJECT(x)); free(session); @@ -854,7 +801,7 @@ void nsgtk_ssl_reject(GtkWidget *w, gpointer data) struct sslcert_session_data *ssl_data = session[2]; sslcert_viewer_reject(ssl_data); - + nsgtk_treeview_destroy(wnd); g_object_unref(G_OBJECT(x)); free(session); @@ -906,7 +853,7 @@ char *path_to_url(const char *path) if (path == NULL) { return NULL; } - + urllen = strlen(path) + FILE_SCHEME_PREFIX_LEN + 1; url = malloc(urllen); @@ -916,7 +863,7 @@ char *path_to_url(const char *path) if (*path == '/') { path++; /* file: paths are already absolute */ - } + } snprintf(url, urllen, "%s%s", FILE_SCHEME_PREFIX, path); @@ -1057,7 +1004,7 @@ uint32_t gtk_gui_gdkkey_to_nskey(GdkEventKey *key) * now. I hope. */ switch (key->keyval) { - + case GDK_KEY(Tab): return KEY_TAB; @@ -1137,12 +1084,12 @@ uint32_t gtk_gui_gdkkey_to_nskey(GdkEventKey *key) case GDK_KEY(Super_L): case GDK_KEY(Super_R): case GDK_KEY(Hyper_L): - case GDK_KEY(Hyper_R): + case GDK_KEY(Hyper_R): return 0; - default: + default: return gdk_keyval_to_unicode(key->keyval); - } + } } /** @@ -1183,3 +1130,65 @@ bool path_add_part(char *path, int length, const char *newpart) return true; } + + +static struct gui_table nsgtk_gui_table = { + .poll = &gui_poll, + .quit = &gui_quit, +}; + +/** + * Main entry point from OS. + */ +int main(int argc, char** argv) +{ + char *messages; + char *options; + nserror ret; + + /* check home directory is available */ + nsgtk_check_homedir(); + + respaths = nsgtk_init_resource("${HOME}/.netsurf/:${NETSURFRES}:"GTK_RESPATH":./gtk/res"); + + gtk_init(&argc, &argv); + + /* initialise logging. Not fatal if it fails but not much we + * can do about it either. + */ + nslog_init(nslog_stream_configure, &argc, argv); + + /* user options setup */ + ret = nsoption_init(set_defaults, &nsoptions, &nsoptions_default); + if (ret != NSERROR_OK) { + fprintf(stderr, "Options failed to initialise (%s)\n", + messages_get_errorcode(ret)); + return 1; + } + options = filepath_find(respaths, "Choices"); + nsoption_read(options, nsoptions); + free(options); + nsoption_commandline(&argc, argv, nsoptions); + check_options(respaths); /* check user options */ + + /* common initialisation */ + messages = filepath_find(respaths, "Messages"); + ret = netsurf_init(messages, &nsgtk_gui_table); + free(messages); + if (ret != NSERROR_OK) { + fprintf(stderr, "NetSurf core failed to initialise (%s)\n", + messages_get_errorcode(ret)); + return 1; + } + + /* run the browser */ + gui_init(argc, argv, respaths); + + /* common finalisation */ + netsurf_exit(); + + /* finalise options */ + nsoption_finalise(nsoptions, nsoptions_default); + + return 0; +} diff --git a/monkey/main.c b/monkey/main.c index 95432e3c7..2e23f55d6 100644 --- a/monkey/main.c +++ b/monkey/main.c @@ -55,7 +55,7 @@ nsmonkey_init_resource(const char *resource_path) return respath; } -void gui_quit(void) +static void gui_quit(void) { urldb_save_cookies(nsoption_charp(cookie_jar)); urldb_save(nsoption_charp(url_file)); @@ -113,6 +113,11 @@ static bool nslog_stream_configure(FILE *fptr) return true; } +static struct gui_table monkey_gui_table = { + .poll = &monkey_poll, + .quit = &gui_quit, +}; + int main(int argc, char **argv) { @@ -146,7 +151,7 @@ main(int argc, char **argv) /* common initialisation */ messages = filepath_find(respaths, "Messages"); - ret = netsurf_init(messages); + ret = netsurf_init(messages, &monkey_gui_table); free(messages); if (ret != NSERROR_OK) { die("NetSurf failed to initialise"); diff --git a/monkey/poll.c b/monkey/poll.c index 024005b89..414d458bd 100644 --- a/monkey/poll.c +++ b/monkey/poll.c @@ -88,7 +88,7 @@ monkey_prepare_input(void) } void -gui_poll(bool active) +monkey_poll(bool active) { CURLMcode code; fd_set read_fd_set, write_fd_set, exc_fd_set; diff --git a/monkey/poll.h b/monkey/poll.h index 1aebe6856..4195958c9 100644 --- a/monkey/poll.h +++ b/monkey/poll.h @@ -21,4 +21,6 @@ void monkey_prepare_input(void); +void monkey_poll(bool active); + #endif /* NETSURF_MONKEY_POLL_H */ diff --git a/riscos/gui.c b/riscos/gui.c index ae5ea383e..5a6668bfd 100644 --- a/riscos/gui.c +++ b/riscos/gui.c @@ -837,6 +837,12 @@ static bool nslog_stream_configure(FILE *fptr) return true; } +static struct gui_table riscos_gui_table = { + .poll = &gui_poll, + .quit = &gui_quit, +}; + + /** Normal entry point from OS */ int main(int argc, char** argv) { @@ -891,7 +897,7 @@ int main(int argc, char** argv) } /* common initialisation */ - ret = netsurf_init(path); + ret = netsurf_init(path, &riscos_gui_table); if (ret != NSERROR_OK) { die("NetSurf failed to initialise"); } @@ -919,7 +925,7 @@ int main(int argc, char** argv) * Close down the gui (RISC OS). */ -void gui_quit(void) +static void gui_quit(void) { urldb_save_cookies(nsoption_charp(cookie_jar)); urldb_save(nsoption_charp(url_save)); @@ -1024,7 +1030,7 @@ void ro_gui_cleanup(void) * \param active return as soon as possible */ -void gui_poll(bool active) +static void gui_poll(bool active) { wimp_event_no event; wimp_block block; diff --git a/windows/main.c b/windows/main.c index 69a152d9b..320c7e4fb 100644 --- a/windows/main.c +++ b/windows/main.c @@ -60,11 +60,6 @@ void gui_launch_url(const char *url) { } -void gui_quit(void) -{ - LOG(("gui_quit")); -} - /** * Ensures output logging stream is available */ @@ -96,6 +91,11 @@ static nserror set_defaults(struct nsoption_s *defaults) return NSERROR_OK; } +static struct gui_table win32_gui_table = { + .poll = &gui_poll, +}; + + /** * Entry point from operating system **/ @@ -157,7 +157,7 @@ WinMain(HINSTANCE hInstance, HINSTANCE hLastInstance, LPSTR lpcli, int ncmd) /* common initialisation */ messages = filepath_find(respaths, "messages"); - ret = netsurf_init(messages); + ret = netsurf_init(messages, &win32_gui_table); free(messages); if (ret != NSERROR_OK) { free(options_file_location); From c8496df3df7d059528f2d5e735be5c55bfa75ef6 Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Sat, 11 Jan 2014 22:34:12 +0000 Subject: [PATCH 076/773] move window creation and destruction into table --- amiga/gui.c | 14 +++++++++----- atari/gui.c | 20 +++++++++++--------- beos/gui.cpp | 6 ++++-- beos/window.cpp | 5 +++-- beos/window.h | 6 ++++++ cocoa/gui.m | 9 ++++++--- desktop/browser.c | 6 ++---- desktop/gui.h | 14 ++++++++++---- desktop/gui_factory.c | 9 ++++++++- framebuffer/gui.c | 16 +++++++++------- gtk/gui.c | 6 ++++-- gtk/window.c | 9 +++++---- gtk/window.h | 2 ++ monkey/browser.c | 5 +++-- monkey/browser.h | 5 +++++ monkey/main.c | 8 +++++--- riscos/gui.c | 6 ++++-- riscos/window.c | 2 +- riscos/window.h | 4 ++++ windows/gui.c | 20 ++++++++++++++------ windows/gui.h | 2 ++ windows/main.c | 5 +---- 22 files changed, 118 insertions(+), 61 deletions(-) diff --git a/amiga/gui.c b/amiga/gui.c index 2037ba41c..3a655f52d 100644 --- a/amiga/gui.c +++ b/amiga/gui.c @@ -3083,8 +3083,10 @@ nserror ami_gui_new_blank_tab(struct gui_window_2 *gwin) return NSERROR_OK; } -struct gui_window *gui_create_browser_window(struct browser_window *bw, - struct browser_window *clone, bool new_tab) +static struct gui_window * +gui_window_create(struct browser_window *bw, + struct browser_window *clone, + bool new_tab) { struct gui_window *g = NULL; bool closegadg=TRUE; @@ -3788,7 +3790,7 @@ void ami_close_all_tabs(struct gui_window_2 *gwin) } } -void gui_window_destroy(struct gui_window *g) +static void gui_window_destroy(struct gui_window *g) { struct Node *ptab; ULONG ptabnum = 0; @@ -5091,8 +5093,10 @@ void gui_file_gadget_open(struct gui_window *g, hlcache_handle *hl, } static struct gui_table ami_gui_table = { - .poll = &gui_poll, - .quit = &gui_quit, + .poll = gui_poll, + .quit = gui_quit, + .window_create = gui_window_create, + .window_destroy = gui_window_destroy, }; /** Normal entry point from OS */ diff --git a/atari/gui.c b/atari/gui.c index a5657368c..3ac267a9b 100644 --- a/atari/gui.c +++ b/atari/gui.c @@ -186,10 +186,10 @@ static void gui_poll(bool active) } -struct gui_window * -gui_create_browser_window(struct browser_window *bw, - struct browser_window *clone, - bool new_tab) { +static struct gui_window * +gui_window_create(struct browser_window *bw, + struct browser_window *clone, + bool new_tab) { struct gui_window *gw=NULL; LOG(( "gw: %p, BW: %p, clone %p, tab: %d\n" , gw, bw, clone, (int)new_tab @@ -233,7 +233,7 @@ gui_create_browser_window(struct browser_window *bw, } -void gui_window_destroy(struct gui_window *w) +static void gui_window_destroy(struct gui_window *w) { if (w == NULL) return; @@ -1101,13 +1101,15 @@ static void gui_init2(int argc, char** argv) void gui_file_gadget_open(struct gui_window *g, hlcache_handle *hl, struct form_control *gadget) { - LOG(("File open dialog rquest for %p/%p", g, gadget)); - /* browser_window_set_gadget_filename(bw, gadget, "filename"); */ + LOG(("File open dialog rquest for %p/%p", g, gadget)); + /* browser_window_set_gadget_filename(bw, gadget, "filename"); */ } static struct gui_table atari_gui_table = { - .poll = &gui_poll, - .quit = &gui_quit, + .poll = gui_poll, + .quit = gui_quit, + .window_create = gui_window_create, + .window_destroy = gui_window_destroy, }; /* #define WITH_DBG_LOGFILE 1 */ diff --git a/beos/gui.cpp b/beos/gui.cpp index 486085de3..22c45598d 100644 --- a/beos/gui.cpp +++ b/beos/gui.cpp @@ -1087,8 +1087,10 @@ void gui_file_gadget_open(struct gui_window *g, hlcache_handle *hl, static struct gui_table beos_gui_table = { - .poll = &gui_poll, - .quit = &gui_quit, + .poll = gui_poll, + .quit = gui_quit, + .window_create = gui_window_create, + .window_destroy = gui_window_destroy, }; diff --git a/beos/window.cpp b/beos/window.cpp index b743ec0c2..e2c17d7e0 100644 --- a/beos/window.cpp +++ b/beos/window.cpp @@ -335,8 +335,9 @@ float nsbeos_get_scale_for_gui(struct gui_window *g) } /* Create a gui_window */ -struct gui_window *gui_create_browser_window(struct browser_window *bw, - struct browser_window *clone, bool new_tab) +struct gui_window *gui_window_create(struct browser_window *bw, + struct browser_window *clone, + bool new_tab) { struct gui_window *g; /**< what we're creating to return */ diff --git a/beos/window.h b/beos/window.h index fc8a4f832..012fbe06f 100644 --- a/beos/window.h +++ b/beos/window.h @@ -61,4 +61,10 @@ void nsbeos_window_destroy_browser(struct gui_window *g); struct browser_window *nsbeos_get_browser_window(struct gui_window *g); + +struct gui_window *gui_window_create(struct browser_window *bw, + struct browser_window *clone, + bool new_tab); +void gui_window_destroy(struct gui_window *g); + #endif /* NETSURF_BEOS_WINDOW_H */ diff --git a/cocoa/gui.m b/cocoa/gui.m index 425bd9cb7..fa80814eb 100644 --- a/cocoa/gui.m +++ b/cocoa/gui.m @@ -70,8 +70,9 @@ static void gui_poll(bool active) struct browser_window; -struct gui_window *gui_create_browser_window(struct browser_window *bw, - struct browser_window *clone, bool new_tab) +static struct gui_window *gui_window_create(struct browser_window *bw, + struct browser_window *clone, + bool new_tab) { BrowserWindowController *window = nil; @@ -93,7 +94,7 @@ struct gui_window *gui_create_browser_window(struct browser_window *bw, return (struct gui_window *)result; } -void gui_window_destroy(struct gui_window *g) +static void gui_window_destroy(struct gui_window *g) { BrowserViewController *vc = (BrowserViewController *)g; @@ -329,6 +330,8 @@ void gui_file_gadget_open(struct gui_window *g, hlcache_handle *hl, static struct gui_table gui_table = { .poll = &gui_poll, + .window_create = gui_window_create, + .window_destroy = gui_window_destroy, }; struct gui_table *cocoa_gui_table = &gui_table; diff --git a/desktop/browser.c b/desktop/browser.c index 6ec31d22f..aceb8fb65 100644 --- a/desktop/browser.c +++ b/desktop/browser.c @@ -732,9 +732,7 @@ browser_window_create(enum browser_window_nav_flags flags, * so find that. */ top = browser_window_get_root(clone); - bw->window = gui_create_browser_window(bw, - top, - ((flags & BROWSER_WINDOW_TAB) != 0)); + bw->window = guit->window_create(bw, top, ((flags & BROWSER_WINDOW_TAB) != 0)); if (bw->window == NULL) { browser_window_destroy(bw); @@ -1644,7 +1642,7 @@ void browser_window_destroy_internal(struct browser_window *bw) if (bw->window) { /* Only the root window has a GUI window */ - gui_window_destroy(bw->window); + guit->window_destroy(bw->window); } if (bw->loading_content != NULL) { diff --git a/desktop/gui.h b/desktop/gui.h index 2bda996fd..940eef0a5 100644 --- a/desktop/gui.h +++ b/desktop/gui.h @@ -75,16 +75,22 @@ struct gui_table { */ void (*poll)(bool active); /* Mandantory */ + /** create a gui window for a browser window */ + struct gui_window *(*window_create)(struct browser_window *bw, + struct browser_window *clone, + bool new_tab); /* Mandantory */ + + /** destroy previously created gui window */ + void (*window_destroy)(struct gui_window *g); /* Mandantory */ + + /** called to allow the gui to cleanup */ - void (*quit)(void); /* optional */ + void (*quit)(void); /* Optional */ }; extern struct gui_table *guit; /* the gui vtable */ -struct gui_window *gui_create_browser_window(struct browser_window *bw, - struct browser_window *clone, bool new_tab); -void gui_window_destroy(struct gui_window *g); void gui_window_set_title(struct gui_window *g, const char *title); void gui_window_redraw_window(struct gui_window *g); void gui_window_update_box(struct gui_window *g, diff --git a/desktop/gui_factory.c b/desktop/gui_factory.c index fe7536353..9a4fa396a 100644 --- a/desktop/gui_factory.c +++ b/desktop/gui_factory.c @@ -16,11 +16,18 @@ nserror gui_factory_register(struct gui_table *gt) return NSERROR_INIT_FAILED; } - /* check the mandantory fields are set */ + /* check the mandantory fields are set */ if (gt->poll == NULL) { return NSERROR_BAD_PARAMETER; } + if (gt->window_create == NULL) { + return NSERROR_BAD_PARAMETER; + } + if (gt->window_destroy == NULL) { + return NSERROR_BAD_PARAMETER; + } + /* fill in the optional entries with defaults */ if (gt->quit == NULL) { diff --git a/framebuffer/gui.c b/framebuffer/gui.c index 1439c3c2d..12145fd80 100644 --- a/framebuffer/gui.c +++ b/framebuffer/gui.c @@ -1501,10 +1501,10 @@ create_normal_browser_window(struct gui_window *gw, int furniture_width) } -struct gui_window * -gui_create_browser_window(struct browser_window *bw, - struct browser_window *clone, - bool new_tab) +static struct gui_window * +gui_window_create(struct browser_window *bw, + struct browser_window *clone, + bool new_tab) { struct gui_window *gw; @@ -1527,7 +1527,7 @@ gui_create_browser_window(struct browser_window *bw, return gw; } -void +static void gui_window_destroy(struct gui_window *gw) { fbtk_destroy_widget(gw->window); @@ -1901,8 +1901,10 @@ void gui_file_gadget_open(struct gui_window *g, hlcache_handle *hl, static struct gui_table framebuffer_gui_table = { - .poll = &gui_poll, - .quit = &gui_quit, + .poll = gui_poll, + .quit = gui_quit, + .window_create = gui_window_create, + .window_destroy = gui_window_destroy, }; /** Entry point from OS. diff --git a/gtk/gui.c b/gtk/gui.c index da602e189..c94b9c836 100644 --- a/gtk/gui.c +++ b/gtk/gui.c @@ -1133,8 +1133,10 @@ bool path_add_part(char *path, int length, const char *newpart) static struct gui_table nsgtk_gui_table = { - .poll = &gui_poll, - .quit = &gui_quit, + .poll = gui_poll, + .quit = gui_quit, + .window_create = gui_window_create, + .window_destroy = gui_window_destroy, }; /** diff --git a/gtk/window.c b/gtk/window.c index 8f05c3799..aabaacbb8 100644 --- a/gtk/window.c +++ b/gtk/window.c @@ -655,10 +655,11 @@ static void window_destroy(GtkWidget *widget, gpointer data) browser_window_destroy(gw->bw); } -/* Core interface docuemnted in desktop/gui.h to create a gui_window */ -struct gui_window *gui_create_browser_window(struct browser_window *bw, - struct browser_window *clone, - bool new_tab) +/* Core interface documented in desktop/gui.h to create a gui_window */ +struct gui_window * +gui_window_create(struct browser_window *bw, + struct browser_window *clone, + bool new_tab) { struct gui_window *g; /**< what we're creating to return */ GError* error = NULL; diff --git a/gtk/window.h b/gtk/window.h index 2def42dd5..9ff036e85 100644 --- a/gtk/window.h +++ b/gtk/window.h @@ -48,5 +48,7 @@ struct gui_window *nsgtk_window_iterate(struct gui_window *g); GtkWidget *nsgtk_window_get_tab(struct gui_window *g); void nsgtk_window_set_tab(struct gui_window *g, GtkWidget *w); +struct gui_window *gui_window_create(struct browser_window *bw, struct browser_window *clone, bool new_tab); +void gui_window_destroy(struct gui_window *g); #endif /* NETSURF_GTK_WINDOW_H */ diff --git a/monkey/browser.c b/monkey/browser.c index 73549f36a..b9e583c1f 100644 --- a/monkey/browser.c +++ b/monkey/browser.c @@ -88,8 +88,9 @@ monkey_kill_browser_windows(void) } struct gui_window * -gui_create_browser_window(struct browser_window *bw, - struct browser_window *clone, bool new_tab) +gui_window_create(struct browser_window *bw, + struct browser_window *clone, + bool new_tab) { struct gui_window *ret = calloc(sizeof(*ret), 1); if (ret == NULL) diff --git a/monkey/browser.h b/monkey/browser.h index 3ccbe7a91..0b1fd8d13 100644 --- a/monkey/browser.h +++ b/monkey/browser.h @@ -42,4 +42,9 @@ void monkey_window_process_reformats(void); void monkey_window_handle_command(int argc, char **argv); void monkey_kill_browser_windows(void); + + +struct gui_window *gui_window_create(struct browser_window *bw, struct browser_window *clone, bool new_tab); +void gui_window_destroy(struct gui_window *g); + #endif /* NETSURF_MONKEY_BROWSER_H */ diff --git a/monkey/main.c b/monkey/main.c index 2e23f55d6..2ef3bb98f 100644 --- a/monkey/main.c +++ b/monkey/main.c @@ -55,7 +55,7 @@ nsmonkey_init_resource(const char *resource_path) return respath; } -static void gui_quit(void) +static void monkey_quit(void) { urldb_save_cookies(nsoption_charp(cookie_jar)); urldb_save(nsoption_charp(url_file)); @@ -114,8 +114,10 @@ static bool nslog_stream_configure(FILE *fptr) } static struct gui_table monkey_gui_table = { - .poll = &monkey_poll, - .quit = &gui_quit, + .poll = monkey_poll, + .quit = monkey_quit, + .window_create = gui_window_create, + .window_destroy = gui_window_destroy, }; int diff --git a/riscos/gui.c b/riscos/gui.c index 5a6668bfd..460036573 100644 --- a/riscos/gui.c +++ b/riscos/gui.c @@ -838,8 +838,10 @@ static bool nslog_stream_configure(FILE *fptr) } static struct gui_table riscos_gui_table = { - .poll = &gui_poll, - .quit = &gui_quit, + .poll = gui_poll, + .quit = gui_quit, + .window_create = gui_window_create, + .window_destroy = gui_window_destroy, }; diff --git a/riscos/window.c b/riscos/window.c index c314c748b..892c24e1d 100644 --- a/riscos/window.c +++ b/riscos/window.c @@ -379,7 +379,7 @@ void ro_gui_window_initialise(void) * \return gui_window, or 0 on error and error reported */ -struct gui_window *gui_create_browser_window(struct browser_window *bw, +struct gui_window *gui_window_create(struct browser_window *bw, struct browser_window *clone, bool new_tab) { int screen_width, screen_height, win_width, win_height, scroll_width; diff --git a/riscos/window.h b/riscos/window.h index adbd999f9..a59a9423c 100644 --- a/riscos/window.h +++ b/riscos/window.h @@ -29,5 +29,9 @@ void ro_gui_window_initialise(void); bool ro_gui_window_check_menu(wimp_menu *menu); +struct gui_window *gui_window_create(struct browser_window *bw, struct browser_window *clone, bool new_tab); +void gui_window_destroy(struct gui_window *g); + + #endif diff --git a/windows/gui.c b/windows/gui.c index e20369a65..a01b6c4df 100644 --- a/windows/gui.c +++ b/windows/gui.c @@ -80,7 +80,7 @@ void gui_file_gadget_open(struct gui_window *g, hlcache_handle *hl, /* browser_window_set_gadget_filename(bw, gadget, "filename"); */ } -void gui_poll(bool active) +static void gui_poll(bool active) { MSG Msg; /* message from system */ BOOL bRet; /* message fetch result */ @@ -1220,10 +1220,10 @@ static HWND nsws_window_create(struct gui_window *gw) * create a new gui_window to contain a browser_window * \param bw the browser_window to connect to the new gui_window */ -struct gui_window * -gui_create_browser_window(struct browser_window *bw, - struct browser_window *clone, - bool new_tab) +static struct gui_window * +gui_window_create(struct browser_window *bw, + struct browser_window *clone, + bool new_tab) { struct gui_window *gw; @@ -1399,7 +1399,7 @@ struct browser_window *gui_window_browser_window(struct gui_window *w) /** * window cleanup code */ -void gui_window_destroy(struct gui_window *w) +static void gui_window_destroy(struct gui_window *w) { if (w == NULL) return; @@ -1883,3 +1883,11 @@ nsws_create_main_class(HINSTANCE hinstance) { return ret; } + +static struct gui_table gui_table = { + .poll = gui_poll, + .window_create = gui_window_create, + .window_destroy = gui_window_destroy, +}; + +struct gui_table *win32_gui_table = &gui_table; diff --git a/windows/gui.h b/windows/gui.h index 9bcba592e..29c7f8485 100644 --- a/windows/gui.h +++ b/windows/gui.h @@ -24,6 +24,8 @@ #include "desktop/gui.h" #include "windows/localhistory.h" +extern struct gui_table *win32_gui_table; + extern HINSTANCE hInstance; /* bounding box */ diff --git a/windows/main.c b/windows/main.c index 320c7e4fb..5f20a70d1 100644 --- a/windows/main.c +++ b/windows/main.c @@ -91,9 +91,6 @@ static nserror set_defaults(struct nsoption_s *defaults) return NSERROR_OK; } -static struct gui_table win32_gui_table = { - .poll = &gui_poll, -}; /** @@ -157,7 +154,7 @@ WinMain(HINSTANCE hInstance, HINSTANCE hLastInstance, LPSTR lpcli, int ncmd) /* common initialisation */ messages = filepath_find(respaths, "messages"); - ret = netsurf_init(messages, &win32_gui_table); + ret = netsurf_init(messages, win32_gui_table); free(messages); if (ret != NSERROR_OK) { free(options_file_location); From 56bb9582b16dfd45bbd1665adaf87c6c5986aed3 Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Sun, 12 Jan 2014 10:27:41 +0000 Subject: [PATCH 077/773] move set title, set url, start and stop throbber window operations to gui table --- amiga/gui.c | 10 ++++++++-- amiga/theme.h | 5 +++++ atari/gui.c | 14 ++++++++++---- beos/gui.cpp | 7 +++++++ beos/scaffolding.h | 5 +++++ cocoa/gui.m | 14 ++++++++++---- desktop/browser.c | 13 +++++++------ desktop/gui.h | 39 +++++++++++++++++++++++++-------------- desktop/gui_factory.c | 30 +++++++++++++++++++++++++++++- framebuffer/gui.c | 17 ++++++++--------- gtk/gui.c | 6 ++++++ gtk/scaffolding.h | 7 +++++++ monkey/browser.h | 4 ++++ monkey/main.c | 6 ++++++ riscos/gui.c | 6 ++++++ riscos/window.h | 6 ++++++ windows/gui.c | 14 ++++++++++---- 17 files changed, 159 insertions(+), 44 deletions(-) diff --git a/amiga/gui.c b/amiga/gui.c index 3a655f52d..463334676 100644 --- a/amiga/gui.c +++ b/amiga/gui.c @@ -3896,7 +3896,7 @@ static void gui_window_destroy(struct gui_window *g) win_destroyed = true; } -void gui_window_set_title(struct gui_window *g, const char *title) +static void gui_window_set_title(struct gui_window *g, const char *title) { struct Node *node; ULONG cur_tab = 0; @@ -4592,7 +4592,7 @@ void gui_window_set_status(struct gui_window *g, const char *text) } } -void gui_window_set_url(struct gui_window *g, const char *url) +static void gui_window_set_url(struct gui_window *g, const char *url) { ULONG cur_tab = 0; @@ -5095,8 +5095,14 @@ void gui_file_gadget_open(struct gui_window *g, hlcache_handle *hl, static struct gui_table ami_gui_table = { .poll = gui_poll, .quit = gui_quit, + .window_create = gui_window_create, .window_destroy = gui_window_destroy, + + .window_set_title = gui_window_set_title, + .window_set_url = gui_window_set_url, + .window_start_throbber = gui_window_start_throbber, + .window_stop_throbber = gui_window_stop_throbber, }; /** Normal entry point from OS */ diff --git a/amiga/theme.h b/amiga/theme.h index 3c3931c12..b47c015e1 100644 --- a/amiga/theme.h +++ b/amiga/theme.h @@ -41,4 +41,9 @@ void ami_reset_pointer(struct gui_window_2 *gwin); * and ALWAYS in preference to SetWindowPointer(), as it features more pointers and uses * the correct ones specified in user preferences. */ void ami_update_pointer(struct Window *win, gui_pointer_shape shape); + +void gui_window_start_throbber(struct gui_window *g); +void gui_window_stop_throbber(struct gui_window *g); + + #endif diff --git a/atari/gui.c b/atari/gui.c index 3ac267a9b..de088a47e 100644 --- a/atari/gui.c +++ b/atari/gui.c @@ -288,7 +288,7 @@ void gui_window_get_dimensions(struct gui_window *w, int *width, int *height, *height = rect.g_h; } -void gui_window_set_title(struct gui_window *gw, const char *title) +static void gui_window_set_title(struct gui_window *gw, const char *title) { if (gw == NULL) @@ -540,7 +540,7 @@ void gui_window_hide_pointer(struct gui_window *w) } -void gui_window_set_url(struct gui_window *w, const char *url) +static void gui_window_set_url(struct gui_window *w, const char *url) { int l; @@ -594,7 +594,7 @@ static void throbber_advance( void * data ) schedule(100, throbber_advance, gw ); } -void gui_window_start_throbber(struct gui_window *w) +static void gui_window_start_throbber(struct gui_window *w) { GRECT work; if (w == NULL) @@ -605,7 +605,7 @@ void gui_window_start_throbber(struct gui_window *w) rendering = true; } -void gui_window_stop_throbber(struct gui_window *w) +static void gui_window_stop_throbber(struct gui_window *w) { if (w == NULL) return; @@ -1108,8 +1108,14 @@ void gui_file_gadget_open(struct gui_window *g, hlcache_handle *hl, static struct gui_table atari_gui_table = { .poll = gui_poll, .quit = gui_quit, + .window_create = gui_window_create, .window_destroy = gui_window_destroy, + + .window_set_title = gui_window_set_title, + .window_set_url = gui_window_set_url, + .window_start_throbber = gui_window_start_throbber, + .window_stop_throbber = gui_window_stop_throbber, }; /* #define WITH_DBG_LOGFILE 1 */ diff --git a/beos/gui.cpp b/beos/gui.cpp index 22c45598d..c5e2fe482 100644 --- a/beos/gui.cpp +++ b/beos/gui.cpp @@ -1089,8 +1089,15 @@ void gui_file_gadget_open(struct gui_window *g, hlcache_handle *hl, static struct gui_table beos_gui_table = { .poll = gui_poll, .quit = gui_quit, + .window_create = gui_window_create, .window_destroy = gui_window_destroy, + + .window_set_title = gui_window_set_title, + .window_set_url = gui_window_set_url, + .window_start_throbber = gui_window_start_throbber, + .window_stop_throbber = gui_window_stop_throbber, + }; diff --git a/beos/scaffolding.h b/beos/scaffolding.h index 1b78d54a8..210499fc7 100644 --- a/beos/scaffolding.h +++ b/beos/scaffolding.h @@ -200,5 +200,10 @@ void nsbeos_scaffolding_destroy(nsbeos_scaffolding *scaffold); void nsbeos_scaffolding_popup_menu(nsbeos_scaffolding *g, BPoint where); +void gui_window_set_title(struct gui_window *_g, const char *title); +void gui_window_set_url(struct gui_window *_g, const char *url); +void gui_window_start_throbber(struct gui_window* _g); +void gui_window_stop_throbber(struct gui_window* _g); + #endif /* NETSURF_BEOS_SCAFFOLDING_H */ diff --git a/cocoa/gui.m b/cocoa/gui.m index fa80814eb..80f811416 100644 --- a/cocoa/gui.m +++ b/cocoa/gui.m @@ -102,7 +102,7 @@ static void gui_window_destroy(struct gui_window *g) [vc release]; } -void gui_window_set_title(struct gui_window *g, const char *title) +static void gui_window_set_title(struct gui_window *g, const char *title) { [(BrowserViewController *)g setTitle: [NSString stringWithUTF8String: title]]; } @@ -209,18 +209,18 @@ void gui_window_hide_pointer(struct gui_window *g) { } -void gui_window_set_url(struct gui_window *g, const char *url) +static void gui_window_set_url(struct gui_window *g, const char *url) { [(BrowserViewController *)g setUrl: [NSString stringWithUTF8String: url]]; } -void gui_window_start_throbber(struct gui_window *g) +static void gui_window_start_throbber(struct gui_window *g) { [(BrowserViewController *)g setIsProcessing: YES]; [(BrowserViewController *)g updateBackForward]; } -void gui_window_stop_throbber(struct gui_window *g) +static void gui_window_stop_throbber(struct gui_window *g) { [(BrowserViewController *)g setIsProcessing: NO]; [(BrowserViewController *)g updateBackForward]; @@ -330,8 +330,14 @@ void gui_file_gadget_open(struct gui_window *g, hlcache_handle *hl, static struct gui_table gui_table = { .poll = &gui_poll, + .window_create = gui_window_create, .window_destroy = gui_window_destroy, + + .window_set_title = gui_window_set_title, + .window_set_url = gui_window_set_url, + .window_start_throbber = gui_window_start_throbber, + .window_stop_throbber = gui_window_stop_throbber, }; struct gui_table *cocoa_gui_table = &gui_table; diff --git a/desktop/browser.c b/desktop/browser.c index aceb8fb65..e01595fcc 100644 --- a/desktop/browser.c +++ b/desktop/browser.c @@ -866,7 +866,7 @@ static void browser_window_start_throbber(struct browser_window *bw) while (bw->parent) bw = bw->parent; - gui_window_start_throbber(bw->window); + guit->window_start_throbber(bw->window); } @@ -883,8 +883,9 @@ static void browser_window_stop_throbber(struct browser_window *bw) while (bw->parent) bw = bw->parent; - if (!browser_window_check_throbber(bw)) - gui_window_stop_throbber(bw->window); + if (!browser_window_check_throbber(bw)) { + guit->window_stop_throbber(bw->window); + } } @@ -1958,7 +1959,7 @@ void browser_window_update(struct browser_window *bw, bool scroll_to_top) case BROWSER_WINDOW_NORMAL: /* Root browser window, constituting a front end window/tab */ - gui_window_set_title(bw->window, + guit->window_set_title(bw->window, content_get_title(bw->current_content)); browser_window_update_extent(bw); @@ -2358,7 +2359,7 @@ void browser_window_refresh_url_bar(struct browser_window *bw, nsurl *url, /* With no fragment, we may as well pass url straight through * saving a malloc, copy, free cycle. */ - gui_window_set_url(bw->window, nsurl_access(url)); + guit->window_set_url(bw->window, nsurl_access(url)); } else { nsurl *display_url; nserror error; @@ -2369,7 +2370,7 @@ void browser_window_refresh_url_bar(struct browser_window *bw, nsurl *url, return; } - gui_window_set_url(bw->window, nsurl_access(display_url)); + guit->window_set_url(bw->window, nsurl_access(display_url)); nsurl_unref(display_url); } } diff --git a/desktop/gui.h b/desktop/gui.h index 940eef0a5..26e1792f8 100644 --- a/desktop/gui.h +++ b/desktop/gui.h @@ -70,28 +70,42 @@ struct form_control; * function table implementing GUI interface to browser core */ struct gui_table { + + /* Mandantory entries */ + /** called to let the frontend update its state and run any * I/O operations. */ - void (*poll)(bool active); /* Mandantory */ + void (*poll)(bool active); - /** create a gui window for a browser window */ - struct gui_window *(*window_create)(struct browser_window *bw, - struct browser_window *clone, - bool new_tab); /* Mandantory */ + /** create a gui window for a browsing context */ + struct gui_window *(*window_create)(struct browser_window *bw, struct browser_window *clone, bool new_tab); /** destroy previously created gui window */ - void (*window_destroy)(struct gui_window *g); /* Mandantory */ + void (*window_destroy)(struct gui_window *g); + /* Optional entries */ + /** called to allow the gui to cleanup */ - void (*quit)(void); /* Optional */ + void (*quit)(void); + + /** set the window title. */ + void (*window_set_title)(struct gui_window *g, const char *title); + + /** set the navigation url. */ + void (*window_set_url)(struct gui_window *g, const char *url); + + /** start the navigation throbber. */ + void (*window_start_throbber)(struct gui_window *g); + + /** stop the navigation throbber. */ + void (*window_stop_throbber)(struct gui_window *g); }; extern struct gui_table *guit; /* the gui vtable */ -void gui_window_set_title(struct gui_window *g, const char *title); void gui_window_redraw_window(struct gui_window *g); void gui_window_update_box(struct gui_window *g, const struct rect *rect); @@ -105,9 +119,6 @@ void gui_window_update_extent(struct gui_window *g); void gui_window_set_status(struct gui_window *g, const char *text); void gui_window_set_pointer(struct gui_window *g, gui_pointer_shape shape); void gui_window_hide_pointer(struct gui_window *g); -void gui_window_set_url(struct gui_window *g, const char *url); -void gui_window_start_throbber(struct gui_window *g); -void gui_window_stop_throbber(struct gui_window *g); void gui_window_set_icon(struct gui_window *g, hlcache_handle *icon); void gui_window_set_search_ico(hlcache_handle *ico); void gui_window_place_caret(struct gui_window *g, int x, int y, int height, @@ -119,12 +130,12 @@ bool gui_window_scroll_start(struct gui_window *g); bool gui_window_drag_start(struct gui_window *g, gui_drag_type type, const struct rect *rect); -void gui_window_save_link(struct gui_window *g, const char *url, +void gui_window_save_link(struct gui_window *g, const char *url, const char *title); struct gui_download_window *gui_download_window_create(download_context *ctx, struct gui_window *parent); -nserror gui_download_window_data(struct gui_download_window *dw, +nserror gui_download_window_data(struct gui_download_window *dw, const char *data, unsigned int size); void gui_download_window_error(struct gui_download_window *dw, const char *error_msg); @@ -172,7 +183,7 @@ void gui_launch_url(const char *url); struct ssl_cert_info; -void gui_cert_verify(nsurl *url, const struct ssl_cert_info *certs, +void gui_cert_verify(nsurl *url, const struct ssl_cert_info *certs, unsigned long num, nserror (*cb)(bool proceed, void *pw), void *cbpw); diff --git a/desktop/gui_factory.c b/desktop/gui_factory.c index 9a4fa396a..c760218ec 100644 --- a/desktop/gui_factory.c +++ b/desktop/gui_factory.c @@ -9,6 +9,22 @@ static void gui_default_quit(void) { } +static void gui_default_window_set_title(struct gui_window *g, const char *title) +{ +} + +static void gui_default_window_set_url(struct gui_window *g, const char *url) +{ +} + +static void gui_default_window_start_throbber(struct gui_window *g) +{ +} + +static void gui_default_window_stop_throbber(struct gui_window *g) +{ +} + nserror gui_factory_register(struct gui_table *gt) { /* ensure not already initialised */ @@ -31,7 +47,19 @@ nserror gui_factory_register(struct gui_table *gt) /* fill in the optional entries with defaults */ if (gt->quit == NULL) { - gt->quit = &gui_default_quit; + gt->quit = gui_default_quit; + } + if (gt->window_set_title == NULL) { + gt->window_set_title = gui_default_window_set_title; + } + if (gt->window_set_url == NULL) { + gt->window_set_url = gui_default_window_set_url; + } + if (gt->window_start_throbber == NULL) { + gt->window_start_throbber = gui_default_window_start_throbber; + } + if (gt->window_stop_throbber == NULL) { + gt->window_stop_throbber = gui_default_window_stop_throbber; } guit = gt; diff --git a/framebuffer/gui.c b/framebuffer/gui.c index 12145fd80..5a903c31e 100644 --- a/framebuffer/gui.c +++ b/framebuffer/gui.c @@ -1535,12 +1535,6 @@ gui_window_destroy(struct gui_window *gw) free(gw); } -void -gui_window_set_title(struct gui_window *g, const char *title) -{ - LOG(("%p, %s", g, title)); -} - void gui_window_redraw_window(struct gui_window *g) { @@ -1657,7 +1651,7 @@ gui_window_hide_pointer(struct gui_window *g) { } -void +static void gui_window_set_url(struct gui_window *g, const char *url) { fbtk_set_text(g->url, url); @@ -1720,14 +1714,14 @@ throbber_advance(void *pw) } } -void +static void gui_window_start_throbber(struct gui_window *g) { g->throbber_index = 0; schedule(10, throbber_advance, g); } -void +static void gui_window_stop_throbber(struct gui_window *gw) { gw->throbber_index = -1; @@ -1903,8 +1897,13 @@ void gui_file_gadget_open(struct gui_window *g, hlcache_handle *hl, static struct gui_table framebuffer_gui_table = { .poll = gui_poll, .quit = gui_quit, + .window_create = gui_window_create, .window_destroy = gui_window_destroy, + + .window_set_url = gui_window_set_url, + .window_start_throbber = gui_window_start_throbber, + .window_stop_throbber = gui_window_stop_throbber, }; /** Entry point from OS. diff --git a/gtk/gui.c b/gtk/gui.c index c94b9c836..1905f20dc 100644 --- a/gtk/gui.c +++ b/gtk/gui.c @@ -1135,8 +1135,14 @@ bool path_add_part(char *path, int length, const char *newpart) static struct gui_table nsgtk_gui_table = { .poll = gui_poll, .quit = gui_quit, + .window_create = gui_window_create, .window_destroy = gui_window_destroy, + + .window_set_title = gui_window_set_title, + .window_set_url = gui_window_set_url, + .window_start_throbber = gui_window_start_throbber, + .window_stop_throbber = gui_window_stop_throbber, }; /** diff --git a/gtk/scaffolding.h b/gtk/scaffolding.h index 79e3fa0df..b1f11bbdf 100644 --- a/gtk/scaffolding.h +++ b/gtk/scaffolding.h @@ -177,4 +177,11 @@ gboolean nsgtk_window_url_changed(GtkWidget *, GdkEventKey *, gpointer); nserror nsgtk_scaffolding_new_tab(struct gui_window *gw); +/* core acessors */ +void gui_window_set_title(struct gui_window *g, const char *title); +void gui_window_set_url(struct gui_window *g, const char *url); +void gui_window_start_throbber(struct gui_window *g); +void gui_window_stop_throbber(struct gui_window *g); + + #endif /* NETSURF_GTK_SCAFFOLDING_H */ diff --git a/monkey/browser.h b/monkey/browser.h index 0b1fd8d13..ab4e59bbb 100644 --- a/monkey/browser.h +++ b/monkey/browser.h @@ -46,5 +46,9 @@ void monkey_kill_browser_windows(void); struct gui_window *gui_window_create(struct browser_window *bw, struct browser_window *clone, bool new_tab); void gui_window_destroy(struct gui_window *g); +void gui_window_set_title(struct gui_window *g, const char *title); +void gui_window_set_url(struct gui_window *g, const char *url); +void gui_window_start_throbber(struct gui_window *g); +void gui_window_stop_throbber(struct gui_window *g); #endif /* NETSURF_MONKEY_BROWSER_H */ diff --git a/monkey/main.c b/monkey/main.c index 2ef3bb98f..73803f536 100644 --- a/monkey/main.c +++ b/monkey/main.c @@ -116,8 +116,14 @@ static bool nslog_stream_configure(FILE *fptr) static struct gui_table monkey_gui_table = { .poll = monkey_poll, .quit = monkey_quit, + .window_create = gui_window_create, .window_destroy = gui_window_destroy, + + .window_set_title = gui_window_set_title, + .window_set_url = gui_window_set_url, + .window_start_throbber = gui_window_start_throbber, + .window_stop_throbber = gui_window_stop_throbber, }; int diff --git a/riscos/gui.c b/riscos/gui.c index 460036573..ee4c59105 100644 --- a/riscos/gui.c +++ b/riscos/gui.c @@ -840,8 +840,14 @@ static bool nslog_stream_configure(FILE *fptr) static struct gui_table riscos_gui_table = { .poll = gui_poll, .quit = gui_quit, + .window_create = gui_window_create, .window_destroy = gui_window_destroy, + + .window_set_title = gui_window_set_title, + .window_set_url = gui_window_set_url, + .window_start_throbber = gui_window_start_throbber, + .window_stop_throbber = gui_window_stop_throbber, }; diff --git a/riscos/window.h b/riscos/window.h index a59a9423c..8614ce0d2 100644 --- a/riscos/window.h +++ b/riscos/window.h @@ -29,9 +29,15 @@ void ro_gui_window_initialise(void); bool ro_gui_window_check_menu(wimp_menu *menu); +/* core acessors */ struct gui_window *gui_window_create(struct browser_window *bw, struct browser_window *clone, bool new_tab); void gui_window_destroy(struct gui_window *g); +void gui_window_set_title(struct gui_window *g, const char *title); +void gui_window_set_url(struct gui_window *g, const char *url); +void gui_window_start_throbber(struct gui_window *g); +void gui_window_stop_throbber(struct gui_window *g); + #endif diff --git a/windows/gui.c b/windows/gui.c index a01b6c4df..6f0dfd874 100644 --- a/windows/gui.c +++ b/windows/gui.c @@ -1422,7 +1422,7 @@ static void gui_window_destroy(struct gui_window *w) * set window title * \param title the [url] */ -void gui_window_set_title(struct gui_window *w, const char *title) +static void gui_window_set_title(struct gui_window *w, const char *title) { if (w == NULL) return; @@ -1654,7 +1654,7 @@ void gui_window_hide_pointer(struct gui_window *w) { } -void gui_window_set_url(struct gui_window *w, const char *url) +static void gui_window_set_url(struct gui_window *w, const char *url) { if (w == NULL) return; @@ -1662,7 +1662,7 @@ void gui_window_set_url(struct gui_window *w, const char *url) } -void gui_window_start_throbber(struct gui_window *w) +static void gui_window_start_throbber(struct gui_window *w) { if (w == NULL) return; @@ -1687,7 +1687,7 @@ void gui_window_start_throbber(struct gui_window *w) Animate_Play(w->throbber, 0, -1, -1); } -void gui_window_stop_throbber(struct gui_window *w) +static void gui_window_stop_throbber(struct gui_window *w) { if (w == NULL) return; @@ -1886,8 +1886,14 @@ nsws_create_main_class(HINSTANCE hinstance) { static struct gui_table gui_table = { .poll = gui_poll, + .window_create = gui_window_create, .window_destroy = gui_window_destroy, + + .window_set_title = gui_window_set_title, + .window_set_url = gui_window_set_url, + .window_start_throbber = gui_window_start_throbber, + .window_stop_throbber = gui_window_stop_throbber, }; struct gui_table *win32_gui_table = &gui_table; From b7736bae2f37675be55b1c89d33b03e8603b2946 Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Sun, 12 Jan 2014 17:07:34 +0000 Subject: [PATCH 078/773] split gui operations into core and window and move more operations into tables --- amiga/download.h | 3 + amiga/gui.c | 157 +++++++++++++++++++++----------------- atari/gui.c | 41 ++++------ beos/gui.cpp | 17 +---- beos/scaffolding.cpp | 9 --- beos/scaffolding.h | 2 +- beos/window.cpp | 22 ++++-- beos/window.h | 9 +-- cocoa/gui.m | 39 ++++------ desktop/browser.c | 20 ++--- desktop/gui.h | 78 ++++++++++++------- desktop/gui_factory.c | 99 +++++++++++++++++++----- desktop/searchweb.c | 2 +- framebuffer/gui.c | 44 +++-------- gtk/dialogs/preferences.c | 4 +- gtk/gui.c | 18 ++--- gtk/scaffolding.c | 5 +- gtk/scaffolding.h | 2 +- gtk/toolbar.c | 4 +- gtk/window.c | 26 +++++-- gtk/window.h | 5 +- monkey/browser.c | 39 ++++++---- monkey/browser.h | 10 +-- monkey/main.c | 11 +-- riscos/gui.c | 10 +-- riscos/window.c | 43 ++++++----- riscos/window.h | 12 +-- windows/gui.c | 38 +++------ 28 files changed, 391 insertions(+), 378 deletions(-) diff --git a/amiga/download.h b/amiga/download.h index ed09a8057..2febbe908 100755 --- a/amiga/download.h +++ b/amiga/download.h @@ -36,4 +36,7 @@ void ami_download_window_abort(struct gui_download_window *dw); BOOL ami_download_window_event(struct gui_download_window *dw); void ami_free_download_list(struct List *dllist); BOOL ami_download_check_overwrite(const char *file, struct Window *win, ULONG size); + +void gui_window_save_link(struct gui_window *g, const char *url, const char *title); + #endif diff --git a/amiga/gui.c b/amiga/gui.c index 463334676..f7c9b92a5 100644 --- a/amiga/gui.c +++ b/amiga/gui.c @@ -1318,6 +1318,69 @@ void ami_gui_menu_update_all(void) } while(node = nnode); } +/** + * function to add retrieved favicon to gui + */ +static void gui_window_set_icon(struct gui_window *g, hlcache_handle *icon) +{ + struct BitMap *bm = NULL; + struct IBox *bbox; + ULONG cur_tab = 0; + struct bitmap *icon_bitmap; + + if(nsoption_bool(kiosk_mode) == true) return; + if(!g) return; + + if(g->tab_node && (g->shared->tabs > 1)) GetAttr(CLICKTAB_Current, + g->shared->objects[GID_TABS], + (ULONG *)&cur_tab); + + if ((icon != NULL) && ((icon_bitmap = content_get_bitmap(icon)) != NULL)) + { + bm = ami_bitmap_get_native(icon_bitmap, 16, 16, + g->shared->win->RPort->BitMap); + } + + if((cur_tab == g->tab) || (g->shared->tabs <= 1)) + { + GetAttr(SPACE_AreaBox, g->shared->objects[GID_ICON], (ULONG *)&bbox); + + RefreshGList((struct Gadget *)g->shared->objects[GID_ICON], + g->shared->win, NULL, 1); + + if(bm) + { + ULONG tag, tag_data, minterm; + + if(ami_plot_screen_is_palettemapped() == false) { + tag = BLITA_UseSrcAlpha; + tag_data = !icon_bitmap->opaque; + minterm = 0xc0; + } else { + tag = BLITA_MaskPlane; + tag_data = (ULONG)ami_bitmap_get_mask(icon_bitmap, 16, 16, bm); + minterm = (ABC|ABNC|ANBC); + } + + BltBitMapTags(BLITA_SrcX, 0, + BLITA_SrcY, 0, + BLITA_DestX, bbox->Left, + BLITA_DestY, bbox->Top, + BLITA_Width, 16, + BLITA_Height, 16, + BLITA_Source, bm, + BLITA_Dest, g->shared->win->RPort, + BLITA_SrcType, BLITT_BITMAP, + BLITA_DestType, BLITT_RASTPORT, + BLITA_Minterm, minterm, + tag, tag_data, + TAG_DONE); + } + } + + g->favicon = icon; +} + void ami_handle_msg(void) { struct IntuiMessage *message = NULL; @@ -2166,7 +2229,7 @@ void ami_handle_msg(void) if(refresh_search_ico) { - gui_window_set_search_ico(NULL); + gui_set_search_ico(NULL); refresh_search_ico = FALSE; } @@ -4611,68 +4674,6 @@ static void gui_window_set_url(struct gui_window *g, const char *url) ami_update_buttons(g->shared); } -/** - * function to add retrieved favicon to gui - */ -void gui_window_set_icon(struct gui_window *g, hlcache_handle *icon) -{ - struct BitMap *bm = NULL; - struct IBox *bbox; - ULONG cur_tab = 0; - struct bitmap *icon_bitmap; - - if(nsoption_bool(kiosk_mode) == true) return; - if(!g) return; - - if(g->tab_node && (g->shared->tabs > 1)) GetAttr(CLICKTAB_Current, - g->shared->objects[GID_TABS], - (ULONG *)&cur_tab); - - if ((icon != NULL) && ((icon_bitmap = content_get_bitmap(icon)) != NULL)) - { - bm = ami_bitmap_get_native(icon_bitmap, 16, 16, - g->shared->win->RPort->BitMap); - } - - if((cur_tab == g->tab) || (g->shared->tabs <= 1)) - { - GetAttr(SPACE_AreaBox, g->shared->objects[GID_ICON], (ULONG *)&bbox); - - RefreshGList((struct Gadget *)g->shared->objects[GID_ICON], - g->shared->win, NULL, 1); - - if(bm) - { - ULONG tag, tag_data, minterm; - - if(ami_plot_screen_is_palettemapped() == false) { - tag = BLITA_UseSrcAlpha; - tag_data = !icon_bitmap->opaque; - minterm = 0xc0; - } else { - tag = BLITA_MaskPlane; - tag_data = (ULONG)ami_bitmap_get_mask(icon_bitmap, 16, 16, bm); - minterm = (ABC|ABNC|ANBC); - } - - BltBitMapTags(BLITA_SrcX, 0, - BLITA_SrcY, 0, - BLITA_DestX, bbox->Left, - BLITA_DestY, bbox->Top, - BLITA_Width, 16, - BLITA_Height, 16, - BLITA_Source, bm, - BLITA_Dest, g->shared->win->RPort, - BLITA_SrcType, BLITT_BITMAP, - BLITA_DestType, BLITT_RASTPORT, - BLITA_Minterm, minterm, - tag, tag_data, - TAG_DONE); - } - } - - g->favicon = icon; -} static uint32 ami_set_favicon_render_hook(struct Hook *hook, APTR space, struct gpRender *msg) @@ -4687,7 +4688,7 @@ static uint32 ami_set_favicon_render_hook(struct Hook *hook, APTR space, * \param ico may be NULL for local calls; then access current cache from * search_web_ico() */ -void gui_window_set_search_ico(hlcache_handle *ico) +static void gui_set_search_ico(hlcache_handle *ico) { struct BitMap *bm = NULL; struct IBox *bbox; @@ -4849,7 +4850,7 @@ bool gui_window_scroll_start(struct gui_window *g) return true; } -bool gui_window_drag_start(struct gui_window *g, gui_drag_type type, +static bool gui_window_drag_start(struct gui_window *g, gui_drag_type type, const struct rect *rect) { g->shared->drag_op = type; @@ -5092,17 +5093,29 @@ void gui_file_gadget_open(struct gui_window *g, hlcache_handle *hl, } } +static struct gui_window_table ami_window_table = { + .create = gui_window_create, + .destroy = gui_window_destroy, + + .set_icon = gui_window_set_icon, + .set_title = gui_window_set_title, + .set_url = gui_window_set_url, + + .drag_start = gui_window_drag_start, + .start_throbber = gui_window_start_throbber, + .stop_throbber = gui_window_stop_throbber, + + /* from download */ + .save_link = gui_window_save_link, +}; + + static struct gui_table ami_gui_table = { .poll = gui_poll, .quit = gui_quit, + .set_search_ico = gui_set_search_ico, - .window_create = gui_window_create, - .window_destroy = gui_window_destroy, - - .window_set_title = gui_window_set_title, - .window_set_url = gui_window_set_url, - .window_start_throbber = gui_window_start_throbber, - .window_stop_throbber = gui_window_stop_throbber, + .window = &ami_window_table, }; /** Normal entry point from OS */ diff --git a/atari/gui.c b/atari/gui.c index de088a47e..24577c5aa 100644 --- a/atari/gui.c +++ b/atari/gui.c @@ -646,7 +646,7 @@ gui_window_remove_caret(struct gui_window *w) return; } -void +static void gui_window_set_icon(struct gui_window *g, hlcache_handle *icon) { struct bitmap *bmp_icon; @@ -658,12 +658,6 @@ gui_window_set_icon(struct gui_window *g, hlcache_handle *icon) } } -void -gui_window_set_search_ico(hlcache_handle *ico) -{ - TODO(); -} - void gui_window_new_content(struct gui_window *w) { struct gemtk_wm_scroll_info_s *slid = gemtk_wm_get_scroll_info(w->root->win); @@ -679,19 +673,6 @@ bool gui_window_scroll_start(struct gui_window *w) return true; } -bool gui_window_drag_start(struct gui_window *g, gui_drag_type type, - const struct rect *rect) -{ - TODO(); - return true; -} - -void gui_window_save_link(struct gui_window *g, const char *url, - const char *title) -{ - LOG(("%s -> %s", title, url )); - TODO(); -} void gui_drag_save_object(gui_save_type type, hlcache_handle *c, struct gui_window *w) @@ -1105,17 +1086,23 @@ void gui_file_gadget_open(struct gui_window *g, hlcache_handle *hl, /* browser_window_set_gadget_filename(bw, gadget, "filename"); */ } +static struct gui_window_table atari_window_table = { + .create = gui_window_create, + .destroy = gui_window_destroy, + + .set_title = gui_window_set_title, + .set_url = gui_window_set_url, + .set_icon = gui_window_set_icon, + + .start_throbber = gui_window_start_throbber, + .stop_throbber = gui_window_stop_throbber, +}; + static struct gui_table atari_gui_table = { .poll = gui_poll, .quit = gui_quit, - .window_create = gui_window_create, - .window_destroy = gui_window_destroy, - - .window_set_title = gui_window_set_title, - .window_set_url = gui_window_set_url, - .window_start_throbber = gui_window_start_throbber, - .window_stop_throbber = gui_window_stop_throbber, + .window = &atari_window_table; }; /* #define WITH_DBG_LOGFILE 1 */ diff --git a/beos/gui.cpp b/beos/gui.cpp index c5e2fe482..42a681c30 100644 --- a/beos/gui.cpp +++ b/beos/gui.cpp @@ -791,11 +791,6 @@ void gui_create_form_select_menu(struct browser_window *bw, CALLED(); } -void -gui_window_save_link(struct gui_window *g, const char *url, const char *title) -{ -} - /** * Send the source of a content to a text editor. */ @@ -1089,15 +1084,6 @@ void gui_file_gadget_open(struct gui_window *g, hlcache_handle *hl, static struct gui_table beos_gui_table = { .poll = gui_poll, .quit = gui_quit, - - .window_create = gui_window_create, - .window_destroy = gui_window_destroy, - - .window_set_title = gui_window_set_title, - .window_set_url = gui_window_set_url, - .window_start_throbber = gui_window_start_throbber, - .window_stop_throbber = gui_window_stop_throbber, - }; @@ -1131,6 +1117,9 @@ int main(int argc, char** argv) /* common initialisation */ BPath messages = get_messages_path(); + + beos_gui_table.window = beos_gui_window_table; + ret = netsurf_init(messages.Path(), &beos_gui_table); if (ret != NSERROR_OK) { die("NetSurf failed to initialise"); diff --git a/beos/scaffolding.cpp b/beos/scaffolding.cpp index 51235b6d0..f302efcb4 100644 --- a/beos/scaffolding.cpp +++ b/beos/scaffolding.cpp @@ -2194,15 +2194,6 @@ void gui_window_set_icon(struct gui_window *_g, hlcache_handle *icon) g->top_view->UnlockLooper(); } -/** -* set gui display of a retrieved favicon representing the search provider -* \param ico may be NULL for local calls; then access current cache from -* search_web_ico() -*/ -void gui_window_set_search_ico(hlcache_handle *ico) -{ -} - void nsbeos_scaffolding_popup_menu(nsbeos_scaffolding *g, BPoint where) { diff --git a/beos/scaffolding.h b/beos/scaffolding.h index 210499fc7..fe726147c 100644 --- a/beos/scaffolding.h +++ b/beos/scaffolding.h @@ -204,6 +204,6 @@ void gui_window_set_title(struct gui_window *_g, const char *title); void gui_window_set_url(struct gui_window *_g, const char *url); void gui_window_start_throbber(struct gui_window* _g); void gui_window_stop_throbber(struct gui_window* _g); - +void gui_window_set_icon(struct gui_window *_g, hlcache_handle *icon); #endif /* NETSURF_BEOS_SCAFFOLDING_H */ diff --git a/beos/window.cpp b/beos/window.cpp index e2c17d7e0..c4a3784e5 100644 --- a/beos/window.cpp +++ b/beos/window.cpp @@ -335,7 +335,7 @@ float nsbeos_get_scale_for_gui(struct gui_window *g) } /* Create a gui_window */ -struct gui_window *gui_window_create(struct browser_window *bw, +static struct gui_window *gui_window_create(struct browser_window *bw, struct browser_window *clone, bool new_tab) { @@ -957,7 +957,7 @@ void nsbeos_window_destroy_browser(struct gui_window *g) browser_window_destroy(g->bw); } -void gui_window_destroy(struct gui_window *g) +static void gui_window_destroy(struct gui_window *g) { if (!g) return; @@ -1284,11 +1284,6 @@ bool gui_window_scroll_start(struct gui_window *g) return true; } -bool gui_window_drag_start(struct gui_window *g, gui_drag_type type, - const struct rect *rect) -{ - return true; -} void gui_drag_save_object(gui_save_type type, hlcache_handle *c, struct gui_window *g) @@ -1384,3 +1379,16 @@ void gui_window_get_dimensions(struct gui_window *g, int *width, int *height, } } +static struct gui_window_table gui_window_table = { + .create = gui_window_create, + .destroy = gui_window_destroy, + + /* from scaffold */ + .set_icon = gui_window_set_icon, + .set_title = gui_window_set_title, + .set_url = gui_window_set_url, + .start_throbber = gui_window_start_throbber, + .stop_throbber = gui_window_stop_throbber, +}; + +struct gui_window_table *beos_gui_window_table = &gui_window_table; diff --git a/beos/window.h b/beos/window.h index 012fbe06f..4bd38de4e 100644 --- a/beos/window.h +++ b/beos/window.h @@ -25,6 +25,8 @@ extern "C" { } #include "beos/scaffolding.h" +extern struct gui_window_table *beos_gui_window_table; + class NSBrowserFrameView : public BView { public: NSBrowserFrameView(BRect frame, struct gui_window *gui); @@ -48,7 +50,6 @@ private: void nsbeos_dispatch_event(BMessage *message); - void nsbeos_reflow_all_windows(void); void nsbeos_window_process_reformats(void); @@ -61,10 +62,4 @@ void nsbeos_window_destroy_browser(struct gui_window *g); struct browser_window *nsbeos_get_browser_window(struct gui_window *g); - -struct gui_window *gui_window_create(struct browser_window *bw, - struct browser_window *clone, - bool new_tab); -void gui_window_destroy(struct gui_window *g); - #endif /* NETSURF_BEOS_WINDOW_H */ diff --git a/cocoa/gui.m b/cocoa/gui.m index 80f811416..fcec64192 100644 --- a/cocoa/gui.m +++ b/cocoa/gui.m @@ -226,7 +226,7 @@ static void gui_window_stop_throbber(struct gui_window *g) [(BrowserViewController *)g updateBackForward]; } -void gui_window_set_icon(struct gui_window *g, hlcache_handle *icon) +static void gui_window_set_icon(struct gui_window *g, hlcache_handle *icon) { NSBitmapImageRep *bmp = icon != NULL ? (NSBitmapImageRep *)content_get_bitmap( icon ) : NULL; @@ -243,11 +243,6 @@ void gui_window_set_icon(struct gui_window *g, hlcache_handle *icon) [image release]; } -void gui_window_set_search_ico(hlcache_handle *ico) -{ - UNIMPL(); -} - void gui_window_place_caret(struct gui_window *g, int x, int y, int height, const struct rect *clip) { @@ -270,18 +265,6 @@ bool gui_window_scroll_start(struct gui_window *g) return true; } -bool gui_window_drag_start(struct gui_window *g, gui_drag_type type, - const struct rect *rect) -{ - return true; -} - -void gui_window_save_link(struct gui_window *g, const char *url, - const char *title) -{ - UNIMPL(); -} - void gui_drag_save_object(gui_save_type type, hlcache_handle *c, struct gui_window *g) { @@ -328,16 +311,22 @@ void gui_file_gadget_open(struct gui_window *g, hlcache_handle *hl, /* browser_window_set_gadget_filename(bw, gadget, "filename"); */ } +static struct gui_window_table cocoa_window_table = { + .create = gui_window_create, + .destroy = gui_window_destroy, + + .set_title = gui_window_set_title, + .set_url = gui_window_set_url, + .set_icon = gui_window_set_icon, + + .start_throbber = gui_window_start_throbber, + .stop_throbber = gui_window_stop_throbber, +}; + static struct gui_table gui_table = { .poll = &gui_poll, - .window_create = gui_window_create, - .window_destroy = gui_window_destroy, - - .window_set_title = gui_window_set_title, - .window_set_url = gui_window_set_url, - .window_start_throbber = gui_window_start_throbber, - .window_stop_throbber = gui_window_stop_throbber, + .window = &cocoa_window_table, }; struct gui_table *cocoa_gui_table = &gui_table; diff --git a/desktop/browser.c b/desktop/browser.c index e01595fcc..bef6eb109 100644 --- a/desktop/browser.c +++ b/desktop/browser.c @@ -391,7 +391,7 @@ void browser_window_set_drag_type(struct browser_window *bw, break; } - gui_window_drag_start(top_bw->window, gtype, rect); + guit->window->drag_start(top_bw->window, gtype, rect); } } @@ -732,7 +732,7 @@ browser_window_create(enum browser_window_nav_flags flags, * so find that. */ top = browser_window_get_root(clone); - bw->window = guit->window_create(bw, top, ((flags & BROWSER_WINDOW_TAB) != 0)); + bw->window = guit->window->create(bw, top, ((flags & BROWSER_WINDOW_TAB) != 0)); if (bw->window == NULL) { browser_window_destroy(bw); @@ -866,7 +866,7 @@ static void browser_window_start_throbber(struct browser_window *bw) while (bw->parent) bw = bw->parent; - guit->window_start_throbber(bw->window); + guit->window->start_throbber(bw->window); } @@ -884,7 +884,7 @@ static void browser_window_stop_throbber(struct browser_window *bw) bw = bw->parent; if (!browser_window_check_throbber(bw)) { - guit->window_stop_throbber(bw->window); + guit->window->stop_throbber(bw->window); } } @@ -918,7 +918,7 @@ static nserror browser_window_favicon_callback(hlcache_handle *c, /* content_get_bitmap on the hlcache_handle should give * us the favicon bitmap at this point */ - gui_window_set_icon(bw->window, c); + guit->window->set_icon(bw->window, c); break; case CONTENT_MSG_ERROR: @@ -1507,7 +1507,7 @@ static nserror browser_window_callback(hlcache_handle *c, { /* Content wants a link to be saved */ struct browser_window *root = browser_window_get_root(bw); - gui_window_save_link(root->window, + guit->window->save_link(root->window, event->data.savelink.url, event->data.savelink.title); } @@ -1643,7 +1643,7 @@ void browser_window_destroy_internal(struct browser_window *bw) if (bw->window) { /* Only the root window has a GUI window */ - guit->window_destroy(bw->window); + guit->window->destroy(bw->window); } if (bw->loading_content != NULL) { @@ -1959,7 +1959,7 @@ void browser_window_update(struct browser_window *bw, bool scroll_to_top) case BROWSER_WINDOW_NORMAL: /* Root browser window, constituting a front end window/tab */ - guit->window_set_title(bw->window, + guit->window->set_title(bw->window, content_get_title(bw->current_content)); browser_window_update_extent(bw); @@ -2359,7 +2359,7 @@ void browser_window_refresh_url_bar(struct browser_window *bw, nsurl *url, /* With no fragment, we may as well pass url straight through * saving a malloc, copy, free cycle. */ - guit->window_set_url(bw->window, nsurl_access(url)); + guit->window->set_url(bw->window, nsurl_access(url)); } else { nsurl *display_url; nserror error; @@ -2370,7 +2370,7 @@ void browser_window_refresh_url_bar(struct browser_window *bw, nsurl *url, return; } - guit->window_set_url(bw->window, nsurl_access(display_url)); + guit->window->set_url(bw->window, nsurl_access(display_url)); nsurl_unref(display_url); } } diff --git a/desktop/gui.h b/desktop/gui.h index 26e1792f8..96062ddae 100644 --- a/desktop/gui.h +++ b/desktop/gui.h @@ -65,6 +65,45 @@ struct gui_download_window; struct browser_window; struct form_control; +/** Graphical user interface window function table + * + * function table implementing window operations + */ +struct gui_window_table { + + /* Mandantory entries */ + + /** create a gui window for a browsing context */ + struct gui_window *(*create)(struct browser_window *bw, struct browser_window *clone, bool new_tab); + + /** destroy previously created gui window */ + void (*destroy)(struct gui_window *g); + + + /* Optional entries */ + + /** set the window title. */ + void (*set_title)(struct gui_window *g, const char *title); + + /** set the navigation url. */ + void (*set_url)(struct gui_window *g, const char *url); + + /** start the navigation throbber. */ + void (*start_throbber)(struct gui_window *g); + + /** stop the navigation throbber. */ + void (*stop_throbber)(struct gui_window *g); + + /** start a drag operation within a window */ + bool (*drag_start)(struct gui_window *g, gui_drag_type type, const struct rect *rect); + + /** save link operation */ + void (*save_link)(struct gui_window *g, const char *url, const char *title); + + /** set favicon */ + void (*set_icon)(struct gui_window *g, hlcache_handle *icon); +}; + /** Graphical user interface function table * * function table implementing GUI interface to browser core @@ -73,35 +112,28 @@ struct gui_table { /* Mandantory entries */ + /* sub tables */ + struct gui_window_table *window; /* window sub table */ + /** called to let the frontend update its state and run any * I/O operations. */ void (*poll)(bool active); - /** create a gui window for a browsing context */ - struct gui_window *(*window_create)(struct browser_window *bw, struct browser_window *clone, bool new_tab); - - /** destroy previously created gui window */ - void (*window_destroy)(struct gui_window *g); - /* Optional entries */ /** called to allow the gui to cleanup */ void (*quit)(void); - /** set the window title. */ - void (*window_set_title)(struct gui_window *g, const char *title); - - /** set the navigation url. */ - void (*window_set_url)(struct gui_window *g, const char *url); - - /** start the navigation throbber. */ - void (*window_start_throbber)(struct gui_window *g); - - /** stop the navigation throbber. */ - void (*window_stop_throbber)(struct gui_window *g); - + /** + * set gui display of a retrieved favicon representing the + * search provider + * + * \param ico may be NULL for local calls; then access current + * cache from search_web_ico() + */ + void (*set_search_ico)(hlcache_handle *ico); }; extern struct gui_table *guit; /* the gui vtable */ @@ -119,19 +151,12 @@ void gui_window_update_extent(struct gui_window *g); void gui_window_set_status(struct gui_window *g, const char *text); void gui_window_set_pointer(struct gui_window *g, gui_pointer_shape shape); void gui_window_hide_pointer(struct gui_window *g); -void gui_window_set_icon(struct gui_window *g, hlcache_handle *icon); -void gui_window_set_search_ico(hlcache_handle *ico); void gui_window_place_caret(struct gui_window *g, int x, int y, int height, const struct rect *clip); void gui_window_remove_caret(struct gui_window *g); void gui_window_new_content(struct gui_window *g); bool gui_window_scroll_start(struct gui_window *g); -bool gui_window_drag_start(struct gui_window *g, gui_drag_type type, - const struct rect *rect); - -void gui_window_save_link(struct gui_window *g, const char *url, - const char *title); struct gui_download_window *gui_download_window_create(download_context *ctx, struct gui_window *parent); @@ -150,6 +175,8 @@ void gui_clear_selection(struct gui_window *g); void gui_file_gadget_open(struct gui_window *g, hlcache_handle *hl, struct form_control *gadget); +void gui_launch_url(const char *url); + /** * Core asks front end for clipboard contents. * @@ -179,7 +206,6 @@ void gui_set_clipboard(const char *buffer, size_t length, void gui_create_form_select_menu(struct browser_window *bw, struct form_control *control); -void gui_launch_url(const char *url); struct ssl_cert_info; diff --git a/desktop/gui_factory.c b/desktop/gui_factory.c index c760218ec..3ced1901f 100644 --- a/desktop/gui_factory.c +++ b/desktop/gui_factory.c @@ -25,41 +25,104 @@ static void gui_default_window_stop_throbber(struct gui_window *g) { } +static bool +gui_default_window_drag_start(struct gui_window *g, + gui_drag_type type, + const struct rect *rect) +{ + return true; +} + +static void +gui_default_window_save_link(struct gui_window *g, + const char *url, + const char *title) +{ +} + +static void +gui_default_window_set_icon(struct gui_window *g, hlcache_handle *icon) +{ +} + +static void +gui_default_set_search_ico(hlcache_handle *ico) +{ +} + +/** verify window table is valid */ +static nserror verify_window_register(struct gui_window_table *gwt) +{ + /* check table is present */ + if (gwt == NULL) { + return NSERROR_BAD_PARAMETER; + } + + /* check the mandantory fields are set */ + if (gwt->create == NULL) { + return NSERROR_BAD_PARAMETER; + } + if (gwt->destroy == NULL) { + return NSERROR_BAD_PARAMETER; + } + + /* fill in the optional entries with defaults */ + if (gwt->set_title == NULL) { + gwt->set_title = gui_default_window_set_title; + } + if (gwt->set_url == NULL) { + gwt->set_url = gui_default_window_set_url; + } + if (gwt->start_throbber == NULL) { + gwt->start_throbber = gui_default_window_start_throbber; + } + if (gwt->stop_throbber == NULL) { + gwt->stop_throbber = gui_default_window_stop_throbber; + } + if (gwt->drag_start == NULL) { + gwt->drag_start = gui_default_window_drag_start; + } + if (gwt->save_link == NULL) { + gwt->save_link = gui_default_window_save_link; + } + if (gwt->set_icon == NULL) { + gwt->set_icon = gui_default_window_set_icon; + } + + return NSERROR_OK; +} + nserror gui_factory_register(struct gui_table *gt) { + nserror err; + /* ensure not already initialised */ if (guit != NULL) { return NSERROR_INIT_FAILED; } + /* check table is present */ + if (gt == NULL) { + return NSERROR_BAD_PARAMETER; + } + + /* check subtables */ + err = verify_window_register(gt->window); + if (err != NSERROR_OK) { + return err; + } /* check the mandantory fields are set */ if (gt->poll == NULL) { return NSERROR_BAD_PARAMETER; } - if (gt->window_create == NULL) { - return NSERROR_BAD_PARAMETER; - } - if (gt->window_destroy == NULL) { - return NSERROR_BAD_PARAMETER; - } - /* fill in the optional entries with defaults */ if (gt->quit == NULL) { gt->quit = gui_default_quit; } - if (gt->window_set_title == NULL) { - gt->window_set_title = gui_default_window_set_title; - } - if (gt->window_set_url == NULL) { - gt->window_set_url = gui_default_window_set_url; - } - if (gt->window_start_throbber == NULL) { - gt->window_start_throbber = gui_default_window_start_throbber; - } - if (gt->window_stop_throbber == NULL) { - gt->window_stop_throbber = gui_default_window_stop_throbber; + if (gt->set_search_ico == NULL) { + gt->set_search_ico = gui_default_set_search_ico; } guit = gt; diff --git a/desktop/searchweb.c b/desktop/searchweb.c index 4c050d97a..321edd0b6 100644 --- a/desktop/searchweb.c +++ b/desktop/searchweb.c @@ -307,7 +307,7 @@ nserror search_web_ico_callback(hlcache_handle *ico, case CONTENT_MSG_DONE: LOG(("got favicon '%s'", nsurl_access(hlcache_handle_get_url(ico)))); - gui_window_set_search_ico(search_ico); + guit->set_search_ico(search_ico); break; case CONTENT_MSG_ERROR: diff --git a/framebuffer/gui.c b/framebuffer/gui.c index 5a903c31e..c9a0d311e 100644 --- a/framebuffer/gui.c +++ b/framebuffer/gui.c @@ -1788,35 +1788,6 @@ gui_window_scroll_start(struct gui_window *g) return true; } -bool -gui_window_drag_start(struct gui_window *g, gui_drag_type type, - const struct rect *rect) -{ - return true; -} - -void -gui_window_save_link(struct gui_window *g, const char *url, const char *title) -{ -} - -/** - * set favicon - */ -void -gui_window_set_icon(struct gui_window *g, hlcache_handle *icon) -{ -} - -/** - * set gui display of a retrieved favicon representing the search provider - * \param ico may be NULL for local calls; then access current cache from - * search_web_ico() - */ -void -gui_window_set_search_ico(hlcache_handle *ico) -{ -} struct gui_download_window * gui_download_window_create(download_context *ctx, struct gui_window *parent) @@ -1893,17 +1864,20 @@ void gui_file_gadget_open(struct gui_window *g, hlcache_handle *hl, /* browser_window_set_gadget_filename(bw, gadget, "filename"); */ } +static struct gui_window_table framebuffer_gui_window_table = { + .create = gui_window_create, + .destroy = gui_window_destroy, + + .set_url = gui_window_set_url, + .start_throbber = gui_window_start_throbber, + .stop_throbber = gui_window_stop_throbber, +}; static struct gui_table framebuffer_gui_table = { .poll = gui_poll, .quit = gui_quit, - .window_create = gui_window_create, - .window_destroy = gui_window_destroy, - - .window_set_url = gui_window_set_url, - .window_start_throbber = gui_window_start_throbber, - .window_stop_throbber = gui_window_stop_throbber, + .window = &framebuffer_gui_window_table, }; /** Entry point from OS. diff --git a/gtk/dialogs/preferences.c b/gtk/dialogs/preferences.c index 0669f8d9f..18c8d7b6c 100644 --- a/gtk/dialogs/preferences.c +++ b/gtk/dialogs/preferences.c @@ -944,9 +944,7 @@ nsgtk_preferences_comboSearch_changed(GtkComboBox *widget, struct ppref *priv) search_web_retrieve_ico(false); /* callback may handle changing gui */ - if (search_web_ico() != NULL) { - gui_window_set_search_ico(search_web_ico()); - } + gui_set_search_ico(search_web_ico()); /* set entry */ name = search_web_provider_name(); diff --git a/gtk/gui.c b/gtk/gui.c index 1905f20dc..0a89f0ee3 100644 --- a/gtk/gui.c +++ b/gtk/gui.c @@ -676,11 +676,6 @@ void gui_create_form_select_menu(struct browser_window *bw, } -void gui_window_save_link(struct gui_window *g, const char *url, - const char *title) -{ -} - void gui_launch_url(const char *url) { gboolean ok; @@ -1132,17 +1127,11 @@ bool path_add_part(char *path, int length, const char *newpart) } + static struct gui_table nsgtk_gui_table = { .poll = gui_poll, .quit = gui_quit, - - .window_create = gui_window_create, - .window_destroy = gui_window_destroy, - - .window_set_title = gui_window_set_title, - .window_set_url = gui_window_set_url, - .window_start_throbber = gui_window_start_throbber, - .window_stop_throbber = gui_window_stop_throbber, + .set_search_ico = gui_set_search_ico, }; /** @@ -1181,6 +1170,9 @@ int main(int argc, char** argv) /* common initialisation */ messages = filepath_find(respaths, "Messages"); + + nsgtk_gui_table.window = nsgtk_gui_window_table; + ret = netsurf_init(messages, &nsgtk_gui_table); free(messages); if (ret != NSERROR_OK) { diff --git a/gtk/scaffolding.c b/gtk/scaffolding.c index b39283cc6..098d5e121 100644 --- a/gtk/scaffolding.c +++ b/gtk/scaffolding.c @@ -2147,8 +2147,7 @@ nsgtk_scaffolding *nsgtk_new_scaffolding(struct gui_window *toplevel) nsgtk_theme_implement(g); /* set web search ico */ - if (search_web_ico() != NULL) - gui_window_set_search_ico(search_web_ico()); + gui_set_search_ico(search_web_ico()); /* finally, show the window. */ gtk_widget_show(GTK_WIDGET(g->window)); @@ -2261,7 +2260,7 @@ nsgtk_scaffolding_set_icon(struct gui_window *gw) gtk_widget_show_all(GTK_WIDGET(sc->buttons[URL_BAR_ITEM]->button)); } -void gui_window_set_search_ico(hlcache_handle *ico) +void gui_set_search_ico(hlcache_handle *ico) { struct bitmap *srch_bitmap; nsgtk_scaffolding *current; diff --git a/gtk/scaffolding.h b/gtk/scaffolding.h index b1f11bbdf..43eb41b19 100644 --- a/gtk/scaffolding.h +++ b/gtk/scaffolding.h @@ -182,6 +182,6 @@ void gui_window_set_title(struct gui_window *g, const char *title); void gui_window_set_url(struct gui_window *g, const char *url); void gui_window_start_throbber(struct gui_window *g); void gui_window_stop_throbber(struct gui_window *g); - +void gui_set_search_ico(hlcache_handle *ico); #endif /* NETSURF_GTK_SCAFFOLDING_H */ diff --git a/gtk/toolbar.c b/gtk/toolbar.c index d543ca5fd..8453f4e27 100644 --- a/gtk/toolbar.c +++ b/gtk/toolbar.c @@ -449,8 +449,8 @@ void nsgtk_toolbar_close(nsgtk_scaffolding *g) TRUE); /* update favicon etc */ nsgtk_scaffolding_set_top_level(nsgtk_scaffolding_top_level(g)); - if (search_web_ico()) - gui_window_set_search_ico(search_web_ico()); + + gui_set_search_ico(search_web_ico()); } /** diff --git a/gtk/window.c b/gtk/window.c index aabaacbb8..075678cb0 100644 --- a/gtk/window.c +++ b/gtk/window.c @@ -656,7 +656,7 @@ static void window_destroy(GtkWidget *widget, gpointer data) } /* Core interface documented in desktop/gui.h to create a gui_window */ -struct gui_window * +static struct gui_window * gui_window_create(struct browser_window *bw, struct browser_window *clone, bool new_tab) @@ -838,7 +838,7 @@ void nsgtk_window_destroy_browser(struct gui_window *gw) gtk_widget_destroy(gw->container); } -void gui_window_destroy(struct gui_window *g) +static void gui_window_destroy(struct gui_window *g) { LOG(("gui_window: %p", g)); assert(g != NULL); @@ -861,7 +861,7 @@ void gui_window_destroy(struct gui_window *g) /** * set favicon */ -void gui_window_set_icon(struct gui_window *gw, hlcache_handle *icon) +static void gui_window_set_icon(struct gui_window *gw, hlcache_handle *icon) { struct bitmap *icon_bitmap = NULL; @@ -1128,11 +1128,6 @@ bool gui_window_scroll_start(struct gui_window *g) return true; } -bool gui_window_drag_start(struct gui_window *g, gui_drag_type type, - const struct rect *rect) -{ - return true; -} void gui_drag_save_object(gui_save_type type, hlcache_handle *c, struct gui_window *g) @@ -1195,3 +1190,18 @@ void gui_file_gadget_open(struct gui_window *g, hlcache_handle *hl, gtk_widget_destroy(dialog); } + +static struct gui_window_table gui_window_table = { + .create = gui_window_create, + .destroy = gui_window_destroy, + + .set_icon = gui_window_set_icon, + + /* from scaffold */ + .set_title = gui_window_set_title, + .set_url = gui_window_set_url, + .start_throbber = gui_window_start_throbber, + .stop_throbber = gui_window_stop_throbber, +}; + +struct gui_window_table *nsgtk_gui_window_table = &gui_window_table; diff --git a/gtk/window.h b/gtk/window.h index 9ff036e85..b6953a99e 100644 --- a/gtk/window.h +++ b/gtk/window.h @@ -32,7 +32,7 @@ typedef enum nsgtk_window_signals { extern struct gui_window *window_list; extern int temp_open_background; - +extern struct gui_window_table *nsgtk_gui_window_table; struct browser_window *nsgtk_get_browser_window(struct gui_window *g); nsgtk_scaffolding *nsgtk_get_scaffold(struct gui_window *g); @@ -48,7 +48,4 @@ struct gui_window *nsgtk_window_iterate(struct gui_window *g); GtkWidget *nsgtk_window_get_tab(struct gui_window *g); void nsgtk_window_set_tab(struct gui_window *g, GtkWidget *w); -struct gui_window *gui_window_create(struct browser_window *bw, struct browser_window *clone, bool new_tab); -void gui_window_destroy(struct gui_window *g); - #endif /* NETSURF_GTK_WINDOW_H */ diff --git a/monkey/browser.c b/monkey/browser.c index b9e583c1f..ed0398142 100644 --- a/monkey/browser.c +++ b/monkey/browser.c @@ -87,7 +87,7 @@ monkey_kill_browser_windows(void) } } -struct gui_window * +static struct gui_window * gui_window_create(struct browser_window *bw, struct browser_window *clone, bool new_tab) @@ -112,7 +112,7 @@ gui_window_create(struct browser_window *bw, return ret; } -void +static void gui_window_destroy(struct gui_window *g) { fprintf(stdout, "WINDOW DESTROY WIN %u\n", g->win_num); @@ -120,7 +120,7 @@ gui_window_destroy(struct gui_window *g) free(g); } -void +static void gui_window_set_title(struct gui_window *g, const char *title) { fprintf(stdout, "WINDOW TITLE WIN %u STR %s\n", g->win_num, title); @@ -148,19 +148,19 @@ gui_window_new_content(struct gui_window *g) fprintf(stdout, "WINDOW NEW_CONTENT WIN %u\n", g->win_num); } -void +static void gui_window_set_icon(struct gui_window *g, hlcache_handle *icon) { fprintf(stdout, "WINDOW NEW_ICON WIN %u\n", g->win_num); } -void +static void gui_window_start_throbber(struct gui_window *g) { fprintf(stdout, "WINDOW START_THROBBER WIN %u\n", g->win_num); } -void +static void gui_window_stop_throbber(struct gui_window *g) { fprintf(stdout, "WINDOW STOP_THROBBER WIN %u\n", g->win_num); @@ -270,7 +270,7 @@ gui_window_set_pointer(struct gui_window *g, gui_pointer_shape shape) fprintf(stdout, "WINDOW SET_POINTER WIN %u POINTER %s\n", g->win_num, ptr_name); } -void +static void gui_window_set_url(struct gui_window *g, const char *url) { fprintf(stdout, "WINDOW SET_URL WIN %u URL %s\n", g->win_num, url); @@ -301,11 +301,6 @@ gui_window_scroll_start(struct gui_window *g) return true; } -void -gui_window_set_search_ico(hlcache_handle *ico) -{ -} - void gui_window_scroll_visible(struct gui_window *g, int x0, int y0, int x1, int y1) @@ -367,7 +362,7 @@ gui_window_remove_caret(struct gui_window *g) fprintf(stdout, "WINDOW REMOVE_CARET WIN %u\n", g->win_num); } -bool +static bool gui_window_drag_start(struct gui_window *g, gui_drag_type type, const struct rect *rect) { @@ -383,7 +378,7 @@ gui_create_form_select_menu(struct browser_window *bw, bw->window->win_num); } -void +static void gui_window_save_link(struct gui_window *g, const char *url, const char *title) { @@ -567,3 +562,19 @@ monkey_window_handle_command(int argc, char **argv) } } + +static struct gui_window_table gui_window_table = { + .create = gui_window_create, + .destroy = gui_window_destroy, + + .set_title = gui_window_set_title, + .set_url = gui_window_set_url, + .set_icon = gui_window_set_icon, + + .drag_start = gui_window_drag_start, + .save_link = gui_window_save_link, + .start_throbber = gui_window_start_throbber, + .stop_throbber = gui_window_stop_throbber, +}; + +struct gui_window_table *monkey_gui_window_table = &gui_window_table; diff --git a/monkey/browser.h b/monkey/browser.h index ab4e59bbb..892c615ab 100644 --- a/monkey/browser.h +++ b/monkey/browser.h @@ -36,6 +36,8 @@ struct gui_window { }; +extern struct gui_window_table *monkey_gui_window_table; + struct gui_window *monkey_find_window_by_num(uint32_t win_num); struct gui_window *monkey_find_window_by_content(hlcache_handle *content); void monkey_window_process_reformats(void); @@ -43,12 +45,4 @@ void monkey_window_process_reformats(void); void monkey_window_handle_command(int argc, char **argv); void monkey_kill_browser_windows(void); - -struct gui_window *gui_window_create(struct browser_window *bw, struct browser_window *clone, bool new_tab); -void gui_window_destroy(struct gui_window *g); -void gui_window_set_title(struct gui_window *g, const char *title); -void gui_window_set_url(struct gui_window *g, const char *url); -void gui_window_start_throbber(struct gui_window *g); -void gui_window_stop_throbber(struct gui_window *g); - #endif /* NETSURF_MONKEY_BROWSER_H */ diff --git a/monkey/main.c b/monkey/main.c index 73803f536..c6aa60f10 100644 --- a/monkey/main.c +++ b/monkey/main.c @@ -116,14 +116,6 @@ static bool nslog_stream_configure(FILE *fptr) static struct gui_table monkey_gui_table = { .poll = monkey_poll, .quit = monkey_quit, - - .window_create = gui_window_create, - .window_destroy = gui_window_destroy, - - .window_set_title = gui_window_set_title, - .window_set_url = gui_window_set_url, - .window_start_throbber = gui_window_start_throbber, - .window_stop_throbber = gui_window_stop_throbber, }; int @@ -159,6 +151,9 @@ main(int argc, char **argv) /* common initialisation */ messages = filepath_find(respaths, "Messages"); + + monkey_gui_table.window = monkey_gui_window_table; + ret = netsurf_init(messages, &monkey_gui_table); free(messages); if (ret != NSERROR_OK) { diff --git a/riscos/gui.c b/riscos/gui.c index ee4c59105..2854744df 100644 --- a/riscos/gui.c +++ b/riscos/gui.c @@ -840,14 +840,6 @@ static bool nslog_stream_configure(FILE *fptr) static struct gui_table riscos_gui_table = { .poll = gui_poll, .quit = gui_quit, - - .window_create = gui_window_create, - .window_destroy = gui_window_destroy, - - .window_set_title = gui_window_set_title, - .window_set_url = gui_window_set_url, - .window_start_throbber = gui_window_start_throbber, - .window_stop_throbber = gui_window_stop_throbber, }; @@ -905,6 +897,8 @@ int main(int argc, char** argv) } /* common initialisation */ + riscos_gui_table.window = riscos_gui_window_table; + ret = netsurf_init(path, &riscos_gui_table); if (ret != NSERROR_OK) { die("NetSurf failed to initialise"); diff --git a/riscos/window.c b/riscos/window.c index 892c24e1d..7285cbc90 100644 --- a/riscos/window.c +++ b/riscos/window.c @@ -379,7 +379,7 @@ void ro_gui_window_initialise(void) * \return gui_window, or 0 on error and error reported */ -struct gui_window *gui_window_create(struct browser_window *bw, +static struct gui_window *gui_window_create(struct browser_window *bw, struct browser_window *clone, bool new_tab) { int screen_width, screen_height, win_width, win_height, scroll_width; @@ -600,7 +600,7 @@ struct gui_window *gui_window_create(struct browser_window *bw, * \param g gui_window to destroy */ -void gui_window_destroy(struct gui_window *g) +static void gui_window_destroy(struct gui_window *g) { os_error *error; wimp_w w; @@ -651,7 +651,7 @@ void gui_window_destroy(struct gui_window *g) * \param title new window title, copied */ -void gui_window_set_title(struct gui_window *g, const char *title) +static void gui_window_set_title(struct gui_window *g, const char *title) { int scale_disp; @@ -1061,7 +1061,7 @@ void gui_window_hide_pointer(struct gui_window *g) * \param url new url for address bar */ -void gui_window_set_url(struct gui_window *g, const char *url) +static void gui_window_set_url(struct gui_window *g, const char *url) { if (!g->toolbar) return; @@ -1077,7 +1077,7 @@ void gui_window_set_url(struct gui_window *g, const char *url) * \param g window with start of load */ -void gui_window_start_throbber(struct gui_window *g) +static void gui_window_start_throbber(struct gui_window *g) { ro_gui_window_update_toolbar_buttons(g); ro_gui_menu_refresh(ro_gui_browser_window_menu); @@ -1093,7 +1093,7 @@ void gui_window_start_throbber(struct gui_window *g) * \param g window with start of load */ -void gui_window_stop_throbber(struct gui_window *g) +static void gui_window_stop_throbber(struct gui_window *g) { ro_gui_window_update_toolbar_buttons(g); ro_gui_menu_refresh(ro_gui_browser_window_menu); @@ -1105,7 +1105,7 @@ void gui_window_stop_throbber(struct gui_window *g) * set favicon */ -void gui_window_set_icon(struct gui_window *g, hlcache_handle *icon) +static void gui_window_set_icon(struct gui_window *g, hlcache_handle *icon) { if (g == NULL || g->toolbar == NULL) return; @@ -1113,15 +1113,6 @@ void gui_window_set_icon(struct gui_window *g, hlcache_handle *icon) ro_toolbar_set_site_favicon(g->toolbar, icon); } -/** -* set gui display of a retrieved favicon representing the search provider -* \param ico may be NULL for local calls; then access current cache from -* search_web_ico() -*/ -void gui_window_set_search_ico(hlcache_handle *ico) -{ -} - /** * Place the caret in a browser window. * @@ -1260,7 +1251,7 @@ bool gui_window_scroll_start(struct gui_window *g) * \return true iff succesful */ -bool gui_window_drag_start(struct gui_window *g, gui_drag_type type, +static bool gui_window_drag_start(struct gui_window *g, gui_drag_type type, const struct rect *rect) { wimp_pointer pointer; @@ -1319,7 +1310,7 @@ bool gui_window_drag_start(struct gui_window *g, gui_drag_type type, * \param g gui_window containing the content * \param c the content to save */ -void gui_window_save_link(struct gui_window *g, const char *url, +static void gui_window_save_link(struct gui_window *g, const char *url, const char *title) { ro_gui_save_prepare(GUI_SAVE_LINK_URL, NULL, NULL, url, title); @@ -5264,3 +5255,19 @@ bool ro_gui_alt_pressed(void) xosbyte1(osbyte_SCAN_KEYBOARD, 2 ^ 0x80, 0, &alt); return (alt == 0xff); } + +static struct gui_window_table gui_window_table = { + .create = gui_window_create, + .destroy = gui_window_destroy, + + .set_icon = gui_window_set_icon, + .set_title = gui_window_set_title, + .set_url = gui_window_set_url, + + .save_link = gui_window_save_link, + .drag_start = gui_window_drag_start, + .start_throbber = gui_window_start_throbber, + .stop_throbber = gui_window_stop_throbber, +}; + +struct gui_window_table *riscos_gui_window_table = &gui_window_table; diff --git a/riscos/window.h b/riscos/window.h index 8614ce0d2..679fa9801 100644 --- a/riscos/window.h +++ b/riscos/window.h @@ -25,19 +25,11 @@ #ifndef _NETSURF_RISCOS_WINDOW_H_ #define _NETSURF_RISCOS_WINDOW_H_ +extern struct gui_window_table *riscos_gui_window_table; + void ro_gui_window_initialise(void); bool ro_gui_window_check_menu(wimp_menu *menu); -/* core acessors */ -struct gui_window *gui_window_create(struct browser_window *bw, struct browser_window *clone, bool new_tab); -void gui_window_destroy(struct gui_window *g); - -void gui_window_set_title(struct gui_window *g, const char *title); -void gui_window_set_url(struct gui_window *g, const char *url); -void gui_window_start_throbber(struct gui_window *g); -void gui_window_stop_throbber(struct gui_window *g); - - #endif diff --git a/windows/gui.c b/windows/gui.c index 6f0dfd874..74ad173ee 100644 --- a/windows/gui.c +++ b/windows/gui.c @@ -1737,15 +1737,6 @@ gui_window_remove_caret(struct gui_window *w) HideCaret(w->drawingarea); } -void -gui_window_set_icon(struct gui_window *g, hlcache_handle *icon) -{ -} - -void -gui_window_set_search_ico(hlcache_handle *ico) -{ -} void gui_window_new_content(struct gui_window *w) { @@ -1756,16 +1747,6 @@ bool gui_window_scroll_start(struct gui_window *w) return true; } -bool gui_window_drag_start(struct gui_window *g, gui_drag_type type, - const struct rect *rect) -{ - return true; -} - -void gui_window_save_link(struct gui_window *g, const char *url, - const char *title) -{ -} void gui_drag_save_object(gui_save_type type, hlcache_handle *c, struct gui_window *w) @@ -1884,16 +1865,21 @@ nsws_create_main_class(HINSTANCE hinstance) { return ret; } +static struct gui_window_table win32_window_table = { + .create = gui_window_create, + .destroy = gui_window_destroy, + + .set_title = gui_window_set_title, + .set_url = gui_window_set_url, + + .start_throbber = gui_window_start_throbber, + .stop_throbber = gui_window_stop_throbber, +}; + static struct gui_table gui_table = { .poll = gui_poll, - .window_create = gui_window_create, - .window_destroy = gui_window_destroy, - - .window_set_title = gui_window_set_title, - .window_set_url = gui_window_set_url, - .window_start_throbber = gui_window_start_throbber, - .window_stop_throbber = gui_window_stop_throbber, + .window = &win32_window_table, }; struct gui_table *win32_gui_table = &gui_table; From 4b49b4ac775a1e3ca0c59f390f3f2427e31bce2b Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Sun, 12 Jan 2014 22:55:26 +0000 Subject: [PATCH 079/773] move more optional window operations into table including removing unused hide_pointer operation altogether --- amiga/gui.c | 14 ++----------- amiga/theme.c | 5 ----- atari/gui.c | 22 ++------------------ beos/window.cpp | 21 +++---------------- cocoa/gui.m | 18 ++-------------- desktop/browser.c | 6 +++--- desktop/gui.h | 31 +++++++++++++++++++++++----- desktop/gui_factory.c | 48 ++++++++++++++++++++++++++++++++----------- framebuffer/gui.c | 23 --------------------- gtk/window.c | 20 ------------------ monkey/browser.c | 9 +++++--- riscos/window.c | 28 +++++++------------------ windows/gui.c | 21 ------------------- 13 files changed, 87 insertions(+), 179 deletions(-) diff --git a/amiga/gui.c b/amiga/gui.c index f7c9b92a5..8c2f43e73 100644 --- a/amiga/gui.c +++ b/amiga/gui.c @@ -4545,12 +4545,6 @@ void gui_window_set_scroll(struct gui_window *g, int sx, int sy) // g->shared->new_content = false; } -void gui_window_scroll_visible(struct gui_window *g, int x0, int y0, - int x1, int y1) -{ - gui_window_set_scroll(g, x0, y0); -} - void gui_window_get_dimensions(struct gui_window *g, int *width, int *height, bool scaled) { @@ -4825,7 +4819,7 @@ void gui_window_remove_caret(struct gui_window *g) g->c_h = 0; } -void gui_window_new_content(struct gui_window *g) +static void gui_window_new_content(struct gui_window *g) { hlcache_handle *c; @@ -4845,11 +4839,6 @@ void gui_window_new_content(struct gui_window *g) ami_gui_update_hotlist_button(g->shared); } -bool gui_window_scroll_start(struct gui_window *g) -{ - return true; -} - static bool gui_window_drag_start(struct gui_window *g, gui_drag_type type, const struct rect *rect) { @@ -5102,6 +5091,7 @@ static struct gui_window_table ami_window_table = { .set_url = gui_window_set_url, .drag_start = gui_window_drag_start, + .new_content = gui_window_new_content, .start_throbber = gui_window_start_throbber, .stop_throbber = gui_window_stop_throbber, diff --git a/amiga/theme.c b/amiga/theme.c index 03ce01aeb..0da15acee 100644 --- a/amiga/theme.c +++ b/amiga/theme.c @@ -275,11 +275,6 @@ void ami_update_pointer(struct Window *win, gui_pointer_shape shape) } } -void gui_window_hide_pointer(struct gui_window *g) -{ - ami_set_pointer(g->shared, AMI_GUI_POINTER_BLANK, true); -} - void ami_init_mouse_pointers(void) { if(LIB_IS_AT_LEAST((struct Library *)IntuitionBase, 53, 42)) return; diff --git a/atari/gui.c b/atari/gui.c index 24577c5aa..7aa0dee07 100644 --- a/atari/gui.c +++ b/atari/gui.c @@ -418,13 +418,6 @@ void gui_window_set_scroll(struct gui_window *w, int sx, int sy) } -void gui_window_scroll_visible(struct gui_window *w, int x0, int y0, int x1, int y1) -{ - LOG(("%s:(%p, %d, %d, %d, %d)", __func__, w, x0, y0, x1, y1)); - gui_window_set_scroll(w,x0,y0); -} - - /* It seems this method is called when content size got adjusted, so that we can adjust scroll info. We also have to call it when tab change occurs. @@ -534,11 +527,6 @@ void gui_window_set_pointer(struct gui_window *gw, gui_pointer_shape shape) } } -void gui_window_hide_pointer(struct gui_window *w) -{ - TODO(); -} - static void gui_window_set_url(struct gui_window *w, const char *url) { @@ -658,7 +646,7 @@ gui_window_set_icon(struct gui_window *g, hlcache_handle *icon) } } -void gui_window_new_content(struct gui_window *w) +static void gui_window_new_content(struct gui_window *w) { struct gemtk_wm_scroll_info_s *slid = gemtk_wm_get_scroll_info(w->root->win); slid->x_pos = 0; @@ -667,13 +655,6 @@ void gui_window_new_content(struct gui_window *w) gui_window_redraw_window(w); } -bool gui_window_scroll_start(struct gui_window *w) -{ - TODO(); - return true; -} - - void gui_drag_save_object(gui_save_type type, hlcache_handle *c, struct gui_window *w) { @@ -1094,6 +1075,7 @@ static struct gui_window_table atari_window_table = { .set_url = gui_window_set_url, .set_icon = gui_window_set_icon, + .new_content = gui_window_new_content, .start_throbber = gui_window_start_throbber, .stop_throbber = gui_window_stop_throbber, }; diff --git a/beos/window.cpp b/beos/window.cpp index c4a3784e5..66bb90640 100644 --- a/beos/window.cpp +++ b/beos/window.cpp @@ -406,12 +406,6 @@ static struct gui_window *gui_window_create(struct browser_window *bw, } -void gui_window_scroll_visible(struct gui_window *g, int x0, int y0, - int x1, int y1) -{ - gui_window_set_scroll(g, x0, y0); -} - void nsbeos_dispatch_event(BMessage *message) { struct gui_window *gui = NULL; @@ -1215,11 +1209,6 @@ void gui_window_set_pointer(struct gui_window *g, gui_pointer_shape shape) delete cursor; } -void gui_window_hide_pointer(struct gui_window *g) -{ - //XXX no BView::HideCursor... use empty one -} - void gui_window_place_caret(struct gui_window *g, int x, int y, int height, const struct rect *clip) { @@ -1263,7 +1252,7 @@ void gui_window_remove_caret(struct gui_window *g) g->view->UnlockLooper(); } -void gui_window_new_content(struct gui_window *g) +static void gui_window_new_content(struct gui_window *g) { if (!g->toplevel) return; @@ -1279,12 +1268,6 @@ void gui_window_new_content(struct gui_window *g) g->view->UnlockLooper(); } -bool gui_window_scroll_start(struct gui_window *g) -{ - return true; -} - - void gui_drag_save_object(gui_save_type type, hlcache_handle *c, struct gui_window *g) { @@ -1383,6 +1366,8 @@ static struct gui_window_table gui_window_table = { .create = gui_window_create, .destroy = gui_window_destroy, + .new_content = gui_window_new_content, + /* from scaffold */ .set_icon = gui_window_set_icon, .set_title = gui_window_set_title, diff --git a/cocoa/gui.m b/cocoa/gui.m index fcec64192..a94cbadb2 100644 --- a/cocoa/gui.m +++ b/cocoa/gui.m @@ -135,12 +135,6 @@ void gui_window_set_scroll(struct gui_window *g, int sx, int sy) [[(BrowserViewController *)g browserView] scrollPoint: cocoa_point( sx, sy )]; } -void gui_window_scroll_visible(struct gui_window *g, int x0, int y0, - int x1, int y1) -{ - gui_window_set_scroll( g, x0, y0 ); -} - void gui_window_get_dimensions(struct gui_window *g, int *width, int *height, bool scaled) { @@ -205,10 +199,6 @@ void gui_window_set_pointer(struct gui_window *g, gui_pointer_shape shape) } } -void gui_window_hide_pointer(struct gui_window *g) -{ -} - static void gui_window_set_url(struct gui_window *g, const char *url) { [(BrowserViewController *)g setUrl: [NSString stringWithUTF8String: url]]; @@ -255,16 +245,11 @@ void gui_window_remove_caret(struct gui_window *g) [[(BrowserViewController *)g browserView] removeCaret]; } -void gui_window_new_content(struct gui_window *g) +static void gui_window_new_content(struct gui_window *g) { [(BrowserViewController *)g contentUpdated]; } -bool gui_window_scroll_start(struct gui_window *g) -{ - return true; -} - void gui_drag_save_object(gui_save_type type, hlcache_handle *c, struct gui_window *g) { @@ -319,6 +304,7 @@ static struct gui_window_table cocoa_window_table = { .set_url = gui_window_set_url, .set_icon = gui_window_set_icon, + .new_content = gui_window_new_content, .start_throbber = gui_window_start_throbber, .stop_throbber = gui_window_stop_throbber, }; diff --git a/desktop/browser.c b/desktop/browser.c index bef6eb109..7c29468c3 100644 --- a/desktop/browser.c +++ b/desktop/browser.c @@ -484,7 +484,7 @@ void browser_window_scroll_visible(struct browser_window *bw, if (bw->window != NULL) { /* Front end window */ - gui_window_scroll_visible(bw->window, + guit->window->scroll_visible(bw->window, rect->x0, rect->y0, rect->x1, rect->y1); } else { /* Core managed browser window */ @@ -1233,7 +1233,7 @@ static nserror browser_window_callback(hlcache_handle *c, browser_window_remove_caret(bw, false); if (bw->window != NULL) { - gui_window_new_content(bw->window); + guit->window->new_content(bw->window); browser_window_refresh_url_bar(bw, hlcache_handle_get_url(bw->current_content), @@ -2949,7 +2949,7 @@ void browser_window_page_drag_start(struct browser_window *bw, int x, int y) gui_window_get_scroll(bw->window, &bw->drag_start_scroll_x, &bw->drag_start_scroll_y); - gui_window_scroll_start(bw->window); + guit->window->scroll_start(bw->window); } else { /* Core managed browser window */ bw->drag_start_scroll_x = scrollbar_get_offset(bw->scroll_x); diff --git a/desktop/gui.h b/desktop/gui.h index 96062ddae..1ab871f33 100644 --- a/desktop/gui.h +++ b/desktop/gui.h @@ -102,6 +102,32 @@ struct gui_window_table { /** set favicon */ void (*set_icon)(struct gui_window *g, hlcache_handle *icon); + + /** + * Scrolls the specified area of a browser window into view. + * + * \param g gui_window to scroll + * \param x0 left point to ensure visible + * \param y0 bottom point to ensure visible + * \param x1 right point to ensure visible + * \param y1 top point to ensure visible + */ + void (*scroll_visible)(struct gui_window *g, int x0, int y0, int x1, int y1); + + /** + * Starts drag scrolling of a browser window + * + * \param g the window to scroll + */ + bool (*scroll_start)(struct gui_window *g); + + /** + * Called when the gui_window has new content. + * + * \param g the gui_window that has new content + */ + void (*new_content)(struct gui_window *g); + }; /** Graphical user interface function table @@ -143,19 +169,14 @@ void gui_window_update_box(struct gui_window *g, const struct rect *rect); bool gui_window_get_scroll(struct gui_window *g, int *sx, int *sy); void gui_window_set_scroll(struct gui_window *g, int sx, int sy); -void gui_window_scroll_visible(struct gui_window *g, int x0, int y0, - int x1, int y1); void gui_window_get_dimensions(struct gui_window *g, int *width, int *height, bool scaled); void gui_window_update_extent(struct gui_window *g); void gui_window_set_status(struct gui_window *g, const char *text); void gui_window_set_pointer(struct gui_window *g, gui_pointer_shape shape); -void gui_window_hide_pointer(struct gui_window *g); void gui_window_place_caret(struct gui_window *g, int x, int y, int height, const struct rect *clip); void gui_window_remove_caret(struct gui_window *g); -void gui_window_new_content(struct gui_window *g); -bool gui_window_scroll_start(struct gui_window *g); struct gui_download_window *gui_download_window_create(download_context *ctx, diff --git a/desktop/gui_factory.c b/desktop/gui_factory.c index 3ced1901f..73fb016e4 100644 --- a/desktop/gui_factory.c +++ b/desktop/gui_factory.c @@ -9,6 +9,11 @@ static void gui_default_quit(void) { } +static void gui_default_set_search_ico(hlcache_handle *ico) +{ +} + + static void gui_default_window_set_title(struct gui_window *g, const char *title) { } @@ -25,31 +30,41 @@ static void gui_default_window_stop_throbber(struct gui_window *g) { } -static bool -gui_default_window_drag_start(struct gui_window *g, - gui_drag_type type, - const struct rect *rect) +static bool gui_default_window_drag_start(struct gui_window *g, + gui_drag_type type, + const struct rect *rect) { return true; } -static void -gui_default_window_save_link(struct gui_window *g, - const char *url, - const char *title) +static void gui_default_window_save_link(struct gui_window *g, + const char *url, + const char *title) { } -static void -gui_default_window_set_icon(struct gui_window *g, hlcache_handle *icon) +static void gui_default_window_set_icon(struct gui_window *g, + hlcache_handle *icon) { } -static void -gui_default_set_search_ico(hlcache_handle *ico) +static void gui_default_window_scroll_visible(struct gui_window *g, + int x0, int y0, + int x1, int y1) +{ + gui_window_set_scroll(g, x0, y0); +} + +static void gui_default_window_new_content(struct gui_window *g) { } +static bool gui_default_window_scroll_start(struct gui_window *g) +{ + return true; +} + + /** verify window table is valid */ static nserror verify_window_register(struct gui_window_table *gwt) { @@ -88,6 +103,15 @@ static nserror verify_window_register(struct gui_window_table *gwt) if (gwt->set_icon == NULL) { gwt->set_icon = gui_default_window_set_icon; } + if (gwt->scroll_visible == NULL) { + gwt->scroll_visible = gui_default_window_scroll_visible; + } + if (gwt->new_content == NULL) { + gwt->new_content = gui_default_window_new_content; + } + if (gwt->scroll_start == NULL) { + gwt->scroll_start = gui_default_window_scroll_start; + } return NSERROR_OK; } diff --git a/framebuffer/gui.c b/framebuffer/gui.c index c9a0d311e..9dd35b6f9 100644 --- a/framebuffer/gui.c +++ b/framebuffer/gui.c @@ -1574,12 +1574,6 @@ gui_window_set_scroll(struct gui_window *gw, int sx, int sy) widget_scroll_y(gw, sy * gw->bw->scale, true); } -void -gui_window_scroll_visible(struct gui_window *g, int x0, int y0, - int x1, int y1) -{ - LOG(("%s:(%p, %d, %d, %d, %d)", __func__, g, x0, y0, x1, y1)); -} void gui_window_get_dimensions(struct gui_window *g, @@ -1646,11 +1640,6 @@ gui_window_set_pointer(struct gui_window *g, gui_pointer_shape shape) } } -void -gui_window_hide_pointer(struct gui_window *g) -{ -} - static void gui_window_set_url(struct gui_window *g, const char *url) { @@ -1777,18 +1766,6 @@ gui_window_remove_caret(struct gui_window *g) } } -void -gui_window_new_content(struct gui_window *g) -{ -} - -bool -gui_window_scroll_start(struct gui_window *g) -{ - return true; -} - - struct gui_download_window * gui_download_window_create(download_context *ctx, struct gui_window *parent) { diff --git a/gtk/window.c b/gtk/window.c index 075678cb0..7f3db864a 100644 --- a/gtk/window.c +++ b/gtk/window.c @@ -987,13 +987,6 @@ void gui_window_set_scroll(struct gui_window *g, int sx, int sy) gtk_adjustment_set_value(hadj, x); } -void gui_window_scroll_visible(struct gui_window *g, int x0, int y0, - int x1, int y1) -{ - gui_window_set_scroll(g,x0,y0); -} - - void gui_window_update_extent(struct gui_window *g) { if (!g->bw->current_content) @@ -1099,10 +1092,6 @@ void gui_window_set_pointer(struct gui_window *g, gui_pointer_shape shape) nsgdk_cursor_unref(cursor); } -void gui_window_hide_pointer(struct gui_window *g) -{ - -} void gui_window_place_caret(struct gui_window *g, int x, int y, int height, const struct rect *clip) @@ -1118,15 +1107,6 @@ void gui_window_place_caret(struct gui_window *g, int x, int y, int height, gtk_widget_grab_focus(GTK_WIDGET(g->layout)); } -void gui_window_new_content(struct gui_window *g) -{ - -} - -bool gui_window_scroll_start(struct gui_window *g) -{ - return true; -} void gui_drag_save_object(gui_save_type type, hlcache_handle *c, diff --git a/monkey/browser.c b/monkey/browser.c index ed0398142..985174d82 100644 --- a/monkey/browser.c +++ b/monkey/browser.c @@ -142,7 +142,7 @@ gui_window_get_dimensions(struct gui_window *g, int *width, int *height, *height = g->height; } -void +static void gui_window_new_content(struct gui_window *g) { fprintf(stdout, "WINDOW NEW_CONTENT WIN %u\n", g->win_num); @@ -293,7 +293,7 @@ gui_window_get_scroll(struct gui_window *g, int *sx, int *sy) return true; } -bool +static bool gui_window_scroll_start(struct gui_window *g) { fprintf(stdout, "WINDOW SCROLL_START WIN %u\n", g->win_num); @@ -301,7 +301,7 @@ gui_window_scroll_start(struct gui_window *g) return true; } -void +static void gui_window_scroll_visible(struct gui_window *g, int x0, int y0, int x1, int y1) { @@ -573,6 +573,9 @@ static struct gui_window_table gui_window_table = { .drag_start = gui_window_drag_start, .save_link = gui_window_save_link, + .scroll_visible = gui_window_scroll_visible, + .scroll_start = gui_window_scroll_start, + .new_content = gui_window_new_content, .start_throbber = gui_window_start_throbber, .stop_throbber = gui_window_stop_throbber, }; diff --git a/riscos/window.c b/riscos/window.c index 7285cbc90..af045b2a4 100644 --- a/riscos/window.c +++ b/riscos/window.c @@ -831,7 +831,7 @@ void gui_window_set_scroll(struct gui_window *g, int sx, int sy) * \param x1 right point to ensure visible * \param y1 top point to ensure visible */ -void gui_window_scroll_visible(struct gui_window *g, int x0, int y0, int x1, int y1) +static void gui_window_scroll_visible(struct gui_window *g, int x0, int y0, int x1, int y1) { wimp_window_state state; os_error *error; @@ -1037,23 +1037,6 @@ void gui_window_set_pointer(struct gui_window *g, gui_pointer_shape shape) } -/** - * Remove the mouse pointer from the screen - */ - -void gui_window_hide_pointer(struct gui_window *g) -{ - os_error *error; - - error = xwimpspriteop_set_pointer_shape(NULL, 0x30, 0, 0, 0, 0); - if (error) { - LOG(("xwimpspriteop_set_pointer_shape: 0x%x: %s", - error->errnum, error->errmess)); - warn_user("WimpError", error->errmess); - } -} - - /** * Set the contents of a window's address bar. * @@ -1172,7 +1155,7 @@ void gui_window_remove_caret(struct gui_window *g) * \param g the gui_window that has new content */ -void gui_window_new_content(struct gui_window *g) +static void gui_window_new_content(struct gui_window *g) { ro_gui_menu_refresh(ro_gui_browser_window_menu); ro_gui_window_update_toolbar_buttons(g); @@ -1184,10 +1167,10 @@ void gui_window_new_content(struct gui_window *g) /** * Starts drag scrolling of a browser window * - * \param gw gui window + * \param g the window to scroll */ -bool gui_window_scroll_start(struct gui_window *g) +static bool gui_window_scroll_start(struct gui_window *g) { wimp_window_info_base info; wimp_pointer pointer; @@ -5266,6 +5249,9 @@ static struct gui_window_table gui_window_table = { .save_link = gui_window_save_link, .drag_start = gui_window_drag_start, + .scroll_visible = gui_window_scroll_visible, + .scroll_start = gui_window_scroll_start, + .new_content = gui_window_new_content, .start_throbber = gui_window_start_throbber, .stop_throbber = gui_window_stop_throbber, }; diff --git a/windows/gui.c b/windows/gui.c index 74ad173ee..6e04e3e97 100644 --- a/windows/gui.c +++ b/windows/gui.c @@ -1543,12 +1543,6 @@ void gui_window_set_scroll(struct gui_window *w, int sx, int sy) } -void gui_window_scroll_visible(struct gui_window *w, int x0, int y0, - int x1, int y1) -{ - LOG(("scroll visible (%p, %d, %d, %d, %d)", w, x0, y0, x1, y1)); -} - void gui_window_get_dimensions(struct gui_window *w, int *width, int *height, bool scaled) { @@ -1650,10 +1644,6 @@ struct nsws_pointers *nsws_get_pointers(void) return &nsws_pointer; } -void gui_window_hide_pointer(struct gui_window *w) -{ -} - static void gui_window_set_url(struct gui_window *w, const char *url) { if (w == NULL) @@ -1737,17 +1727,6 @@ gui_window_remove_caret(struct gui_window *w) HideCaret(w->drawingarea); } - -void gui_window_new_content(struct gui_window *w) -{ -} - -bool gui_window_scroll_start(struct gui_window *w) -{ - return true; -} - - void gui_drag_save_object(gui_save_type type, hlcache_handle *c, struct gui_window *w) { From 5a962586fb161651fc612ed8a8f6da99d8d22f65 Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Sun, 12 Jan 2014 23:50:54 +0000 Subject: [PATCH 080/773] move mandantory window update and redraw operations into table --- amiga/gui.c | 6 ++++-- atari/gui.c | 6 ++++-- beos/window.cpp | 6 ++++-- cocoa/gui.m | 6 ++++-- desktop/browser.c | 6 +++--- desktop/gui.h | 18 +++++++++++++++--- desktop/gui_factory.c | 6 ++++++ framebuffer/gui.c | 6 ++++-- gtk/window.c | 6 ++++-- monkey/browser.c | 6 ++++-- riscos/print.c | 1 + riscos/window.c | 5 ++++- windows/gui.c | 28 +++++++++++++++------------- 13 files changed, 72 insertions(+), 34 deletions(-) diff --git a/amiga/gui.c b/amiga/gui.c index 8c2f43e73..9ed3559f2 100644 --- a/amiga/gui.c +++ b/amiga/gui.c @@ -4184,7 +4184,7 @@ static void ami_do_redraw_limits(struct gui_window *g, struct browser_window *bw return; } -void gui_window_redraw_window(struct gui_window *g) +static void gui_window_redraw_window(struct gui_window *g) { ULONG cur_tab = 0; @@ -4262,7 +4262,7 @@ struct nsObject *nnode; return true; } -void gui_window_update_box(struct gui_window *g, const struct rect *rect) +static void gui_window_update_box(struct gui_window *g, const struct rect *rect) { struct nsObject *nsobj; struct rect *deferred_rect; @@ -5085,6 +5085,8 @@ void gui_file_gadget_open(struct gui_window *g, hlcache_handle *hl, static struct gui_window_table ami_window_table = { .create = gui_window_create, .destroy = gui_window_destroy, + .redraw = gui_window_redraw_window, + .update = gui_window_update_box, .set_icon = gui_window_set_icon, .set_title = gui_window_set_title, diff --git a/atari/gui.c b/atari/gui.c index 7aa0dee07..cfb6b86d6 100644 --- a/atari/gui.c +++ b/atari/gui.c @@ -363,7 +363,7 @@ void gui_window_set_scale(struct gui_window *gw, float scale) browser_window_reformat(gw->browser->bw, false, width, heigth); } -void gui_window_redraw_window(struct gui_window *gw) +static void gui_window_redraw_window(struct gui_window *gw) { CMP_BROWSER b; GRECT rect; @@ -374,7 +374,7 @@ void gui_window_redraw_window(struct gui_window *gw) window_schedule_redraw_grect(gw->root, &rect); } -void gui_window_update_box(struct gui_window *gw, const struct rect *rect) +static void gui_window_update_box(struct gui_window *gw, const struct rect *rect) { GRECT area; struct gemtk_wm_scroll_info_s *slid; @@ -1070,6 +1070,8 @@ void gui_file_gadget_open(struct gui_window *g, hlcache_handle *hl, static struct gui_window_table atari_window_table = { .create = gui_window_create, .destroy = gui_window_destroy, + .redraw = gui_window_redraw_window, + .update = gui_window_update_box, .set_title = gui_window_set_title, .set_url = gui_window_set_url, diff --git a/beos/window.cpp b/beos/window.cpp index 66bb90640..beee9642e 100644 --- a/beos/window.cpp +++ b/beos/window.cpp @@ -1014,7 +1014,7 @@ void nsbeos_redraw_caret(struct gui_window *g) g->view->UnlockLooper(); } -void gui_window_redraw_window(struct gui_window *g) +static void gui_window_redraw_window(struct gui_window *g) { if (g->view == NULL) return; @@ -1029,7 +1029,7 @@ void gui_window_redraw_window(struct gui_window *g) g->view->UnlockLooper(); } -void gui_window_update_box(struct gui_window *g, const struct rect *rect) +static void gui_window_update_box(struct gui_window *g, const struct rect *rect) { hlcache_handle *c = g->bw->current_content; @@ -1365,6 +1365,8 @@ void gui_window_get_dimensions(struct gui_window *g, int *width, int *height, static struct gui_window_table gui_window_table = { .create = gui_window_create, .destroy = gui_window_destroy, + .redraw = gui_window_redraw_window, + .update = gui_window_update_box, .new_content = gui_window_new_content, diff --git a/cocoa/gui.m b/cocoa/gui.m index a94cbadb2..5909fcddc 100644 --- a/cocoa/gui.m +++ b/cocoa/gui.m @@ -107,12 +107,12 @@ static void gui_window_set_title(struct gui_window *g, const char *title) [(BrowserViewController *)g setTitle: [NSString stringWithUTF8String: title]]; } -void gui_window_redraw_window(struct gui_window *g) +static void gui_window_redraw_window(struct gui_window *g) { [[(BrowserViewController *)g browserView] setNeedsDisplay: YES]; } -void gui_window_update_box(struct gui_window *g, const struct rect *rect) +static void gui_window_update_box(struct gui_window *g, const struct rect *rect) { const NSRect nsrect = cocoa_scaled_rect_wh( [(BrowserViewController *)g browser]->scale, rect->x0, rect->y0, @@ -299,6 +299,8 @@ void gui_file_gadget_open(struct gui_window *g, hlcache_handle *hl, static struct gui_window_table cocoa_window_table = { .create = gui_window_create, .destroy = gui_window_destroy, + .redraw = gui_window_redraw_window, + .update = gui_window_update_box, .set_title = gui_window_set_title, .set_url = gui_window_set_url, diff --git a/desktop/browser.c b/desktop/browser.c index 7c29468c3..6d260a538 100644 --- a/desktop/browser.c +++ b/desktop/browser.c @@ -1974,7 +1974,7 @@ void browser_window_update(struct browser_window *bw, bool scroll_to_top) browser_window_set_scroll(bw, x, y); } - gui_window_redraw_window(bw->window); + guit->window->redraw(bw->window); break; @@ -2040,7 +2040,7 @@ void browser_window_update_box(struct browser_window *bw, struct rect *rect) if (bw->window != NULL) { /* Front end window */ - gui_window_update_box(bw->window, rect); + guit->window->update(bw->window, rect); } else { /* Core managed browser window */ browser_window_get_position(bw, true, &pos_x, &pos_y); @@ -2052,7 +2052,7 @@ void browser_window_update_box(struct browser_window *bw, struct rect *rect) rect->x1 += pos_x / bw->scale; rect->y1 += pos_y / bw->scale; - gui_window_update_box(top->window, rect); + guit->window->update(top->window, rect); } } diff --git a/desktop/gui.h b/desktop/gui.h index 1ab871f33..0b7bdcca6 100644 --- a/desktop/gui.h +++ b/desktop/gui.h @@ -79,6 +79,21 @@ struct gui_window_table { /** destroy previously created gui window */ void (*destroy)(struct gui_window *g); + /** + * Force a redraw of the entire contents of a window. + * + * \param g gui_window to redraw + */ + void (*redraw)(struct gui_window *g); + + /** + * Redraw an area of a window. + * + * \param g gui_window + * \param rect area to redraw + */ + void (*update)(struct gui_window *g, const struct rect *rect); + /* Optional entries */ @@ -164,9 +179,6 @@ struct gui_table { extern struct gui_table *guit; /* the gui vtable */ -void gui_window_redraw_window(struct gui_window *g); -void gui_window_update_box(struct gui_window *g, - const struct rect *rect); bool gui_window_get_scroll(struct gui_window *g, int *sx, int *sy); void gui_window_set_scroll(struct gui_window *g, int sx, int sy); void gui_window_get_dimensions(struct gui_window *g, int *width, int *height, diff --git a/desktop/gui_factory.c b/desktop/gui_factory.c index 73fb016e4..9cf328557 100644 --- a/desktop/gui_factory.c +++ b/desktop/gui_factory.c @@ -80,6 +80,12 @@ static nserror verify_window_register(struct gui_window_table *gwt) if (gwt->destroy == NULL) { return NSERROR_BAD_PARAMETER; } + if (gwt->redraw == NULL) { + return NSERROR_BAD_PARAMETER; + } + if (gwt->update == NULL) { + return NSERROR_BAD_PARAMETER; + } /* fill in the optional entries with defaults */ if (gwt->set_title == NULL) { diff --git a/framebuffer/gui.c b/framebuffer/gui.c index 9dd35b6f9..aefc24bdb 100644 --- a/framebuffer/gui.c +++ b/framebuffer/gui.c @@ -1535,13 +1535,13 @@ gui_window_destroy(struct gui_window *gw) free(gw); } -void +static void gui_window_redraw_window(struct gui_window *g) { fb_queue_redraw(g->browser, 0, 0, fbtk_get_width(g->browser), fbtk_get_height(g->browser) ); } -void +static void gui_window_update_box(struct gui_window *g, const struct rect *rect) { struct browser_widget_s *bwidget = fbtk_get_userpw(g->browser); @@ -1844,6 +1844,8 @@ void gui_file_gadget_open(struct gui_window *g, hlcache_handle *hl, static struct gui_window_table framebuffer_gui_window_table = { .create = gui_window_create, .destroy = gui_window_destroy, + .redraw = gui_window_redraw_window, + .update = gui_window_update_box, .set_url = gui_window_set_url, .start_throbber = gui_window_start_throbber, diff --git a/gtk/window.c b/gtk/window.c index 7f3db864a..0ea67edb9 100644 --- a/gtk/window.c +++ b/gtk/window.c @@ -919,12 +919,12 @@ void gui_window_remove_caret(struct gui_window *g) } -void gui_window_redraw_window(struct gui_window *g) +static void gui_window_redraw_window(struct gui_window *g) { gtk_widget_queue_draw(GTK_WIDGET(g->layout)); } -void gui_window_update_box(struct gui_window *g, const struct rect *rect) +static void gui_window_update_box(struct gui_window *g, const struct rect *rect) { int sx, sy; hlcache_handle *c = g->bw->current_content; @@ -1174,6 +1174,8 @@ void gui_file_gadget_open(struct gui_window *g, hlcache_handle *hl, static struct gui_window_table gui_window_table = { .create = gui_window_create, .destroy = gui_window_destroy, + .redraw = gui_window_redraw_window, + .update = gui_window_update_box, .set_icon = gui_window_set_icon, diff --git a/monkey/browser.c b/monkey/browser.c index 985174d82..33f302089 100644 --- a/monkey/browser.c +++ b/monkey/browser.c @@ -126,7 +126,7 @@ gui_window_set_title(struct gui_window *g, const char *title) fprintf(stdout, "WINDOW TITLE WIN %u STR %s\n", g->win_num, title); } -void +static void gui_window_redraw_window(struct gui_window *g) { fprintf(stdout, "WINDOW REDRAW WIN %u\n", g->win_num); @@ -174,7 +174,7 @@ gui_window_set_scroll(struct gui_window *g, int sx, int sy) fprintf(stdout, "WINDOW SET_SCROLL WIN %u X %d Y %d\n", g->win_num, sx, sy); } -void +static void gui_window_update_box(struct gui_window *g, const struct rect *rect) { fprintf(stdout, "WINDOW UPDATE_BOX WIN %u X %d Y %d WIDTH %d HEIGHT %d\n", @@ -566,6 +566,8 @@ monkey_window_handle_command(int argc, char **argv) static struct gui_window_table gui_window_table = { .create = gui_window_create, .destroy = gui_window_destroy, + .redraw = gui_window_redraw_window, + .update = gui_window_update_box, .set_title = gui_window_set_title, .set_url = gui_window_set_url, diff --git a/riscos/print.c b/riscos/print.c index 0df77ef6b..09d4aaefb 100644 --- a/riscos/print.c +++ b/riscos/print.c @@ -90,6 +90,7 @@ static unsigned int print_fonts_count; /** Error in print_fonts_plot_text() or print_fonts_callback(). */ static const char *print_fonts_error; +void gui_window_redraw_window(struct gui_window *g); static bool ro_gui_print_click(wimp_pointer *pointer); static bool ro_gui_print_apply(wimp_w w); diff --git a/riscos/window.c b/riscos/window.c index af045b2a4..3975773a0 100644 --- a/riscos/window.c +++ b/riscos/window.c @@ -89,6 +89,7 @@ #include "utils/utils.h" #include "utils/messages.h" +void gui_window_redraw_window(struct gui_window *g); static void gui_window_set_extent(struct gui_window *g, int width, int height); @@ -710,7 +711,7 @@ void gui_window_redraw_window(struct gui_window *g) * \param data content_msg_data union with filled in redraw data */ -void gui_window_update_box(struct gui_window *g, const struct rect *rect) +static void gui_window_update_box(struct gui_window *g, const struct rect *rect) { bool use_buffer; int x0, y0, x1, y1; @@ -5242,6 +5243,8 @@ bool ro_gui_alt_pressed(void) static struct gui_window_table gui_window_table = { .create = gui_window_create, .destroy = gui_window_destroy, + .redraw = gui_window_redraw_window, + .update = gui_window_update_box, .set_icon = gui_window_set_icon, .set_title = gui_window_set_title, diff --git a/windows/gui.c b/windows/gui.c index 6e04e3e97..e40414eac 100644 --- a/windows/gui.c +++ b/windows/gui.c @@ -723,6 +723,18 @@ nsws_window_resize(struct gui_window *gw, return 0; } +/** + * redraw the whole window + */ +static void gui_window_redraw_window(struct gui_window *gw) +{ + /* LOG(("gw:%p", gw)); */ + if (gw == NULL) + return; + + RedrawWindow(gw->drawingarea, NULL, NULL, RDW_INVALIDATE | RDW_NOERASE); +} + static LRESULT nsws_window_command(HWND hwnd, @@ -1439,19 +1451,7 @@ static void gui_window_set_title(struct gui_window *w, const char *title) free(fulltitle); } -/** - * redraw the whole window - */ -void gui_window_redraw_window(struct gui_window *gw) -{ - /* LOG(("gw:%p", gw)); */ - if (gw == NULL) - return; - - RedrawWindow(gw->drawingarea, NULL, NULL, RDW_INVALIDATE | RDW_NOERASE); -} - -void gui_window_update_box(struct gui_window *gw, const struct rect *rect) +static void gui_window_update_box(struct gui_window *gw, const struct rect *rect) { /* LOG(("gw:%p %f,%f %f,%f", gw, data->redraw.x, data->redraw.y, data->redraw.width, data->redraw.height)); */ @@ -1847,6 +1847,8 @@ nsws_create_main_class(HINSTANCE hinstance) { static struct gui_window_table win32_window_table = { .create = gui_window_create, .destroy = gui_window_destroy, + .redraw = gui_window_redraw_window, + .update = gui_window_update_box, .set_title = gui_window_set_title, .set_url = gui_window_set_url, From 7227c29bbacbc796e9f549cf21e8bd978fde5114 Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Mon, 13 Jan 2014 01:08:15 +0000 Subject: [PATCH 081/773] move window scroll getter and setter into operations table --- amiga/gui.c | 9 +++++++-- atari/ctxmenu.c | 1 + atari/gui.c | 5 ++++- atari/rootwin.c | 2 ++ beos/window.cpp | 6 ++++-- cocoa/gui.m | 6 ++++-- desktop/browser.c | 4 ++-- desktop/gui.h | 21 +++++++++++++++++++-- desktop/gui_factory.c | 8 +++++++- framebuffer/gui.c | 6 ++++-- gtk/window.c | 31 +++++++++++++++++-------------- monkey/browser.c | 6 ++++-- riscos/window.c | 6 ++++-- windows/drawable.c | 2 ++ windows/gui.c | 7 ++++++- 15 files changed, 87 insertions(+), 33 deletions(-) diff --git a/amiga/gui.c b/amiga/gui.c index 9ed3559f2..7c3a72afe 100644 --- a/amiga/gui.c +++ b/amiga/gui.c @@ -200,6 +200,9 @@ static void ami_gui_window_update_box_deferred(struct gui_window *g, bool draw); static void ami_do_redraw(struct gui_window_2 *g); static void ami_schedule_redraw_remove(struct gui_window_2 *gwin); +static bool gui_window_get_scroll(struct gui_window *g, int *sx, int *sy); +static void gui_window_set_scroll(struct gui_window *g, int sx, int sy); + /* accessors for default options - user option is updated if it is set as per default */ #define nsoption_default_set_int(OPTION, VALUE) \ if (nsoptions_default[NSOPTION_##OPTION].value.i == nsoptions[NSOPTION_##OPTION].value.i) \ @@ -4480,13 +4483,13 @@ void ami_get_vscroll_pos(struct gui_window_2 *gwin, ULONG *ys) *ys /= gwin->bw->scale; } -bool gui_window_get_scroll(struct gui_window *g, int *sx, int *sy) +static bool gui_window_get_scroll(struct gui_window *g, int *sx, int *sy) { ami_get_hscroll_pos(g->shared, (ULONG *)sx); ami_get_vscroll_pos(g->shared, (ULONG *)sy); } -void gui_window_set_scroll(struct gui_window *g, int sx, int sy) +static void gui_window_set_scroll(struct gui_window *g, int sx, int sy) { struct IBox *bbox; ULONG cur_tab = 0; @@ -5087,6 +5090,8 @@ static struct gui_window_table ami_window_table = { .destroy = gui_window_destroy, .redraw = gui_window_redraw_window, .update = gui_window_update_box, + .get_scroll = gui_window_get_scroll, + .set_scroll = gui_window_set_scroll, .set_icon = gui_window_set_icon, .set_title = gui_window_set_title, diff --git a/atari/ctxmenu.c b/atari/ctxmenu.c index fb687b809..ae918c6a5 100644 --- a/atari/ctxmenu.c +++ b/atari/ctxmenu.c @@ -58,6 +58,7 @@ #define CNT_INTERACTIVE 512 #define CNT_IMG 1024 +bool gui_window_get_scroll(struct gui_window *w, int *sx, int *sy); struct s_context_info { unsigned long flags; diff --git a/atari/gui.c b/atari/gui.c index cfb6b86d6..cb1b123bd 100644 --- a/atari/gui.c +++ b/atari/gui.c @@ -113,6 +113,7 @@ EVMULT_IN aes_event_in = { EVMULT_OUT aes_event_out; short aes_msg_out[8]; +bool gui_window_get_scroll(struct gui_window *w, int *sx, int *sy); static void gui_poll(bool active) @@ -404,7 +405,7 @@ bool gui_window_get_scroll(struct gui_window *w, int *sx, int *sy) return( true ); } -void gui_window_set_scroll(struct gui_window *w, int sx, int sy) +static void gui_window_set_scroll(struct gui_window *w, int sx, int sy) { int units = 0; if ((w == NULL) @@ -1072,6 +1073,8 @@ static struct gui_window_table atari_window_table = { .destroy = gui_window_destroy, .redraw = gui_window_redraw_window, .update = gui_window_update_box, + .get_scroll = gui_window_get_scroll, + .set_scroll = gui_window_set_scroll, .set_title = gui_window_set_title, .set_url = gui_window_set_url, diff --git a/atari/rootwin.c b/atari/rootwin.c index 3c89e6d55..0f3413c3d 100755 --- a/atari/rootwin.c +++ b/atari/rootwin.c @@ -85,6 +85,8 @@ static bool on_content_mouse_click(ROOTWIN *rootwin); static bool on_content_mouse_move(ROOTWIN *rootwin, GRECT *content_area); static void toolbar_redraw_cb(GUIWIN *win, uint16_t msg, GRECT *clip); +bool gui_window_get_scroll(struct gui_window *w, int *sx, int *sy); + static bool redraw_active = false; static const struct redraw_context rootwin_rdrw_ctx = { diff --git a/beos/window.cpp b/beos/window.cpp index beee9642e..5fd177bb7 100644 --- a/beos/window.cpp +++ b/beos/window.cpp @@ -1051,7 +1051,7 @@ static void gui_window_update_box(struct gui_window *g, const struct rect *rect) g->view->UnlockLooper(); } -bool gui_window_get_scroll(struct gui_window *g, int *sx, int *sy) +static bool gui_window_get_scroll(struct gui_window *g, int *sx, int *sy) { //CALLED(); if (g->view == NULL) @@ -1069,7 +1069,7 @@ bool gui_window_get_scroll(struct gui_window *g, int *sx, int *sy) return true; } -void gui_window_set_scroll(struct gui_window *g, int sx, int sy) +static void gui_window_set_scroll(struct gui_window *g, int sx, int sy) { //CALLED(); if (g->view == NULL) @@ -1367,6 +1367,8 @@ static struct gui_window_table gui_window_table = { .destroy = gui_window_destroy, .redraw = gui_window_redraw_window, .update = gui_window_update_box, + .get_scroll = gui_window_get_scroll, + .set_scroll = gui_window_set_scroll, .new_content = gui_window_new_content, diff --git a/cocoa/gui.m b/cocoa/gui.m index 5909fcddc..d193fa9c9 100644 --- a/cocoa/gui.m +++ b/cocoa/gui.m @@ -120,7 +120,7 @@ static void gui_window_update_box(struct gui_window *g, const struct rect *rect) [[(BrowserViewController *)g browserView] setNeedsDisplayInRect: nsrect]; } -bool gui_window_get_scroll(struct gui_window *g, int *sx, int *sy) +static bool gui_window_get_scroll(struct gui_window *g, int *sx, int *sy) { NSCParameterAssert( g != NULL && sx != NULL && sy != NULL ); @@ -130,7 +130,7 @@ bool gui_window_get_scroll(struct gui_window *g, int *sx, int *sy) return true; } -void gui_window_set_scroll(struct gui_window *g, int sx, int sy) +static void gui_window_set_scroll(struct gui_window *g, int sx, int sy) { [[(BrowserViewController *)g browserView] scrollPoint: cocoa_point( sx, sy )]; } @@ -301,6 +301,8 @@ static struct gui_window_table cocoa_window_table = { .destroy = gui_window_destroy, .redraw = gui_window_redraw_window, .update = gui_window_update_box, + .get_scroll = gui_window_get_scroll, + .set_scroll = gui_window_set_scroll, .set_title = gui_window_set_title, .set_url = gui_window_set_url, diff --git a/desktop/browser.c b/desktop/browser.c index 6d260a538..3a286eecf 100644 --- a/desktop/browser.c +++ b/desktop/browser.c @@ -499,7 +499,7 @@ void browser_window_scroll_visible(struct browser_window *bw, void browser_window_set_scroll(struct browser_window *bw, int x, int y) { if (bw->window != NULL) { - gui_window_set_scroll(bw->window, x, y); + guit->window->set_scroll(bw->window, x, y); } else { if (bw->scroll_x != NULL) scrollbar_set(bw->scroll_x, x, false); @@ -2946,7 +2946,7 @@ void browser_window_page_drag_start(struct browser_window *bw, int x, int y) if (bw->window != NULL) { /* Front end window */ - gui_window_get_scroll(bw->window, &bw->drag_start_scroll_x, + guit->window->get_scroll(bw->window, &bw->drag_start_scroll_x, &bw->drag_start_scroll_y); guit->window->scroll_start(bw->window); diff --git a/desktop/gui.h b/desktop/gui.h index 0b7bdcca6..bf922737b 100644 --- a/desktop/gui.h +++ b/desktop/gui.h @@ -94,6 +94,25 @@ struct gui_window_table { */ void (*update)(struct gui_window *g, const struct rect *rect); + /** + * Get the scroll position of a browser window. + * + * \param g gui_window + * \param sx receives x ordinate of point at top-left of window + * \param sy receives y ordinate of point at top-left of window + * \return true iff successful + */ + bool (*get_scroll)(struct gui_window *g, int *sx, int *sy); + + /** + * Set the scroll position of a browser window. + * + * \param g gui_window to scroll + * \param sx point to place at top-left of window + * \param sy point to place at top-left of window + */ + void (*set_scroll)(struct gui_window *g, int sx, int sy); + /* Optional entries */ @@ -179,8 +198,6 @@ struct gui_table { extern struct gui_table *guit; /* the gui vtable */ -bool gui_window_get_scroll(struct gui_window *g, int *sx, int *sy); -void gui_window_set_scroll(struct gui_window *g, int sx, int sy); void gui_window_get_dimensions(struct gui_window *g, int *width, int *height, bool scaled); void gui_window_update_extent(struct gui_window *g); diff --git a/desktop/gui_factory.c b/desktop/gui_factory.c index 9cf328557..a4cc1c9a9 100644 --- a/desktop/gui_factory.c +++ b/desktop/gui_factory.c @@ -52,7 +52,7 @@ static void gui_default_window_scroll_visible(struct gui_window *g, int x0, int y0, int x1, int y1) { - gui_window_set_scroll(g, x0, y0); + guit->window->set_scroll(g, x0, y0); } static void gui_default_window_new_content(struct gui_window *g) @@ -86,6 +86,12 @@ static nserror verify_window_register(struct gui_window_table *gwt) if (gwt->update == NULL) { return NSERROR_BAD_PARAMETER; } + if (gwt->get_scroll == NULL) { + return NSERROR_BAD_PARAMETER; + } + if (gwt->set_scroll == NULL) { + return NSERROR_BAD_PARAMETER; + } /* fill in the optional entries with defaults */ if (gwt->set_title == NULL) { diff --git a/framebuffer/gui.c b/framebuffer/gui.c index aefc24bdb..13d0421d1 100644 --- a/framebuffer/gui.c +++ b/framebuffer/gui.c @@ -1552,7 +1552,7 @@ gui_window_update_box(struct gui_window *g, const struct rect *rect) rect->y1 - bwidget->scrolly); } -bool +static bool gui_window_get_scroll(struct gui_window *g, int *sx, int *sy) { struct browser_widget_s *bwidget = fbtk_get_userpw(g->browser); @@ -1563,7 +1563,7 @@ gui_window_get_scroll(struct gui_window *g, int *sx, int *sy) return true; } -void +static void gui_window_set_scroll(struct gui_window *gw, int sx, int sy) { struct browser_widget_s *bwidget = fbtk_get_userpw(gw->browser); @@ -1846,6 +1846,8 @@ static struct gui_window_table framebuffer_gui_window_table = { .destroy = gui_window_destroy, .redraw = gui_window_redraw_window, .update = gui_window_update_box, + .get_scroll = gui_window_get_scroll, + .set_scroll = gui_window_set_scroll, .set_url = gui_window_set_url, .start_throbber = gui_window_start_throbber, diff --git a/gtk/window.c b/gtk/window.c index 0ea67edb9..e6da490e6 100644 --- a/gtk/window.c +++ b/gtk/window.c @@ -888,6 +888,20 @@ static void gui_window_set_icon(struct gui_window *gw, hlcache_handle *icon) nsgtk_scaffolding_set_icon(gw); } +static bool gui_window_get_scroll(struct gui_window *g, int *sx, int *sy) +{ + GtkAdjustment *vadj = nsgtk_layout_get_vadjustment(g->layout); + GtkAdjustment *hadj = nsgtk_layout_get_hadjustment(g->layout); + + assert(vadj); + assert(hadj); + + *sy = (int)(gtk_adjustment_get_value(vadj)); + *sx = (int)(gtk_adjustment_get_value(hadj)); + + return true; +} + static void nsgtk_redraw_caret(struct gui_window *g) { int sx, sy; @@ -948,21 +962,8 @@ void gui_window_set_status(struct gui_window *g, const char *text) gtk_label_set_text(g->status_bar, text); } -bool gui_window_get_scroll(struct gui_window *g, int *sx, int *sy) -{ - GtkAdjustment *vadj = nsgtk_layout_get_vadjustment(g->layout); - GtkAdjustment *hadj = nsgtk_layout_get_hadjustment(g->layout); - assert(vadj); - assert(hadj); - - *sy = (int)(gtk_adjustment_get_value(vadj)); - *sx = (int)(gtk_adjustment_get_value(hadj)); - - return true; -} - -void gui_window_set_scroll(struct gui_window *g, int sx, int sy) +static void gui_window_set_scroll(struct gui_window *g, int sx, int sy) { GtkAdjustment *vadj = nsgtk_layout_get_vadjustment(g->layout); GtkAdjustment *hadj = nsgtk_layout_get_hadjustment(g->layout); @@ -1176,6 +1177,8 @@ static struct gui_window_table gui_window_table = { .destroy = gui_window_destroy, .redraw = gui_window_redraw_window, .update = gui_window_update_box, + .get_scroll = gui_window_get_scroll, + .set_scroll = gui_window_set_scroll, .set_icon = gui_window_set_icon, diff --git a/monkey/browser.c b/monkey/browser.c index 33f302089..706034cf2 100644 --- a/monkey/browser.c +++ b/monkey/browser.c @@ -166,7 +166,7 @@ gui_window_stop_throbber(struct gui_window *g) fprintf(stdout, "WINDOW STOP_THROBBER WIN %u\n", g->win_num); } -void +static void gui_window_set_scroll(struct gui_window *g, int sx, int sy) { g->scrollx = sx; @@ -283,7 +283,7 @@ gui_drag_save_object(gui_save_type type, hlcache_handle *c, /* Ignore? */ } -bool +static bool gui_window_get_scroll(struct gui_window *g, int *sx, int *sy) { fprintf(stdout, "WINDOW GET_SCROLL WIN %u X %d Y %d\n", @@ -568,6 +568,8 @@ static struct gui_window_table gui_window_table = { .destroy = gui_window_destroy, .redraw = gui_window_redraw_window, .update = gui_window_update_box, + .get_scroll = gui_window_get_scroll, + .set_scroll = gui_window_set_scroll, .set_title = gui_window_set_title, .set_url = gui_window_set_url, diff --git a/riscos/window.c b/riscos/window.c index 3975773a0..f722ab187 100644 --- a/riscos/window.c +++ b/riscos/window.c @@ -766,7 +766,7 @@ static void gui_window_update_box(struct gui_window *g, const struct rect *rect) * \return true iff successful */ -bool gui_window_get_scroll(struct gui_window *g, int *sx, int *sy) +static bool gui_window_get_scroll(struct gui_window *g, int *sx, int *sy) { wimp_window_state state; os_error *error; @@ -799,7 +799,7 @@ bool gui_window_get_scroll(struct gui_window *g, int *sx, int *sy) * \param sy point to place at top-left of window */ -void gui_window_set_scroll(struct gui_window *g, int sx, int sy) +static void gui_window_set_scroll(struct gui_window *g, int sx, int sy) { wimp_window_state state; os_error *error; @@ -5245,6 +5245,8 @@ static struct gui_window_table gui_window_table = { .destroy = gui_window_destroy, .redraw = gui_window_redraw_window, .update = gui_window_update_box, + .get_scroll = gui_window_get_scroll, + .set_scroll = gui_window_set_scroll, .set_icon = gui_window_set_icon, .set_title = gui_window_set_title, diff --git a/windows/drawable.c b/windows/drawable.c index 8e35d306c..34b8958dc 100644 --- a/windows/drawable.c +++ b/windows/drawable.c @@ -37,6 +37,8 @@ static const char windowclassname_drawable[] = "nswsdrawablewindow"; +void gui_window_set_scroll(struct gui_window *w, int sx, int sy); + /** * Handle wheel scroll messages. */ diff --git a/windows/gui.c b/windows/gui.c index e40414eac..de6634ab7 100644 --- a/windows/gui.c +++ b/windows/gui.c @@ -73,6 +73,9 @@ static const char windowclassname_main[] = "nswsmainwindow"; static struct nsws_pointers nsws_pointer; +void gui_window_set_scroll(struct gui_window *w, int sx, int sy); +static bool gui_window_get_scroll(struct gui_window *w, int *sx, int *sy); + void gui_file_gadget_open(struct gui_window *g, hlcache_handle *hl, struct form_control *gadget) { @@ -1469,7 +1472,7 @@ static void gui_window_update_box(struct gui_window *gw, const struct rect *rect } -bool gui_window_get_scroll(struct gui_window *w, int *sx, int *sy) +static bool gui_window_get_scroll(struct gui_window *w, int *sx, int *sy) { LOG(("get scroll")); if (w == NULL) @@ -1849,6 +1852,8 @@ static struct gui_window_table win32_window_table = { .destroy = gui_window_destroy, .redraw = gui_window_redraw_window, .update = gui_window_update_box, + .get_scroll = gui_window_get_scroll, + .set_scroll = gui_window_set_scroll, .set_title = gui_window_set_title, .set_url = gui_window_set_url, From d70e371cd99d35859b0514884163447fa793738a Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Mon, 13 Jan 2014 11:38:35 +0000 Subject: [PATCH 082/773] move two more mandantory window operations to table --- amiga/gui.c | 7 ++++--- atari/gui.c | 11 ++++++++--- beos/window.cpp | 6 ++++-- cocoa/gui.m | 6 ++++-- desktop/browser.c | 4 ++-- desktop/gui.h | 31 ++++++++++++++++++++++++++++--- desktop/gui_factory.c | 7 +++++++ framebuffer/gui.c | 6 ++++-- gtk/window.c | 6 ++++-- monkey/browser.c | 7 ++++--- riscos/window.c | 7 ++++--- windows/gui.c | 6 ++++-- 12 files changed, 77 insertions(+), 27 deletions(-) diff --git a/amiga/gui.c b/amiga/gui.c index 7c3a72afe..c69b3f07a 100644 --- a/amiga/gui.c +++ b/amiga/gui.c @@ -4548,7 +4548,7 @@ static void gui_window_set_scroll(struct gui_window *g, int sx, int sy) // g->shared->new_content = false; } -void gui_window_get_dimensions(struct gui_window *g, int *width, int *height, +static void gui_window_get_dimensions(struct gui_window *g, int *width, int *height, bool scaled) { struct IBox *bbox; @@ -4566,7 +4566,7 @@ void gui_window_get_dimensions(struct gui_window *g, int *width, int *height, } } -void gui_window_update_extent(struct gui_window *g) +static void gui_window_update_extent(struct gui_window *g) { struct IBox *bbox, zbox; ULONG cur_tab = 0; @@ -5092,11 +5092,12 @@ static struct gui_window_table ami_window_table = { .update = gui_window_update_box, .get_scroll = gui_window_get_scroll, .set_scroll = gui_window_set_scroll, + .get_dimensions = gui_window_get_dimensions, + .update_extent = gui_window_update_extent, .set_icon = gui_window_set_icon, .set_title = gui_window_set_title, .set_url = gui_window_set_url, - .drag_start = gui_window_drag_start, .new_content = gui_window_new_content, .start_throbber = gui_window_start_throbber, diff --git a/atari/gui.c b/atari/gui.c index cb1b123bd..8357a0b0a 100644 --- a/atari/gui.c +++ b/atari/gui.c @@ -278,8 +278,11 @@ static void gui_window_destroy(struct gui_window *w) } } -void gui_window_get_dimensions(struct gui_window *w, int *width, int *height, - bool scaled) +static void +gui_window_get_dimensions(struct gui_window *w, + int *width, + int *height, + bool scaled) { if (w == NULL) return; @@ -423,7 +426,7 @@ static void gui_window_set_scroll(struct gui_window *w, int sx, int sy) so that we can adjust scroll info. We also have to call it when tab change occurs. */ -void gui_window_update_extent(struct gui_window *gw) +static void gui_window_update_extent(struct gui_window *gw) { if( gw->browser->bw->current_content != NULL ) { @@ -1075,6 +1078,8 @@ static struct gui_window_table atari_window_table = { .update = gui_window_update_box, .get_scroll = gui_window_get_scroll, .set_scroll = gui_window_set_scroll, + .get_dimensions = gui_window_get_dimensions, + .update_extent = gui_window_update_extent, .set_title = gui_window_set_title, .set_url = gui_window_set_url, diff --git a/beos/window.cpp b/beos/window.cpp index 5fd177bb7..cff33a35b 100644 --- a/beos/window.cpp +++ b/beos/window.cpp @@ -1087,7 +1087,7 @@ static void gui_window_set_scroll(struct gui_window *g, int sx, int sy) } -void gui_window_update_extent(struct gui_window *g) +static void gui_window_update_extent(struct gui_window *g) { //CALLED(); if (!g->bw->current_content) @@ -1347,7 +1347,7 @@ void gui_set_clipboard(const char *buffer, size_t length, } } -void gui_window_get_dimensions(struct gui_window *g, int *width, int *height, +static void gui_window_get_dimensions(struct gui_window *g, int *width, int *height, bool scaled) { if (g->view && g->view->LockLooper()) { @@ -1369,6 +1369,8 @@ static struct gui_window_table gui_window_table = { .update = gui_window_update_box, .get_scroll = gui_window_get_scroll, .set_scroll = gui_window_set_scroll, + .get_dimensions = gui_window_get_dimensions, + .update_extent = gui_window_update_extent, .new_content = gui_window_new_content, diff --git a/cocoa/gui.m b/cocoa/gui.m index d193fa9c9..f674a7cb0 100644 --- a/cocoa/gui.m +++ b/cocoa/gui.m @@ -135,7 +135,7 @@ static void gui_window_set_scroll(struct gui_window *g, int sx, int sy) [[(BrowserViewController *)g browserView] scrollPoint: cocoa_point( sx, sy )]; } -void gui_window_get_dimensions(struct gui_window *g, int *width, int *height, +static void gui_window_get_dimensions(struct gui_window *g, int *width, int *height, bool scaled) { NSCParameterAssert( width != NULL && height != NULL ); @@ -150,7 +150,7 @@ void gui_window_get_dimensions(struct gui_window *g, int *width, int *height, *height = cocoa_pt_to_px( NSHeight( frame ) ); } -void gui_window_update_extent(struct gui_window *g) +static void gui_window_update_extent(struct gui_window *g) { BrowserViewController * const window = (BrowserViewController *)g; @@ -303,6 +303,8 @@ static struct gui_window_table cocoa_window_table = { .update = gui_window_update_box, .get_scroll = gui_window_get_scroll, .set_scroll = gui_window_set_scroll, + .get_dimensions = gui_window_get_dimensions, + .update_extent = gui_window_update_extent, .set_title = gui_window_set_title, .set_url = gui_window_set_url, diff --git a/desktop/browser.c b/desktop/browser.c index 3a286eecf..5b34dd555 100644 --- a/desktop/browser.c +++ b/desktop/browser.c @@ -300,7 +300,7 @@ void browser_window_update_extent(struct browser_window *bw) { if (bw->window != NULL) /* Front end window */ - gui_window_update_extent(bw->window); + guit->window->update_extent(bw->window); else /* Core-managed browser window */ browser_window_handle_scrollbars(bw); @@ -1912,7 +1912,7 @@ void browser_window_get_dimensions(struct browser_window *bw, *height = bw->height; } else { /* Front end window */ - gui_window_get_dimensions(bw->window, width, height, scaled); + guit->window->get_dimensions(bw->window, width, height, scaled); } } diff --git a/desktop/gui.h b/desktop/gui.h index bf922737b..02012fa8f 100644 --- a/desktop/gui.h +++ b/desktop/gui.h @@ -82,6 +82,8 @@ struct gui_window_table { /** * Force a redraw of the entire contents of a window. * + * @todo this API should be merged with update. + * * \param g gui_window to redraw */ void (*redraw)(struct gui_window *g); @@ -113,6 +115,31 @@ struct gui_window_table { */ void (*set_scroll)(struct gui_window *g, int sx, int sy); + /** + * Find the current dimensions of a browser window's content area. + * + * @todo The implementations of this are buggy and its only + * used from frames code. + * + * \param g gui_window to measure + * \param width receives width of window + * \param height receives height of window + * \param scaled whether to return scaled values + */ + void (*get_dimensions)(struct gui_window *g, int *width, int *height, bool scaled); + + /** + * Update the extent of the inside of a browser window to that of the + * current content. + * + * @todo this is used to update scroll bars does it need + * renaming? some frontends (windows) do not even implement it. + * + * \param g gui_window to update the extent of + */ + void (*update_extent)(struct gui_window *g); + + /* Optional entries */ @@ -198,9 +225,7 @@ struct gui_table { extern struct gui_table *guit; /* the gui vtable */ -void gui_window_get_dimensions(struct gui_window *g, int *width, int *height, - bool scaled); -void gui_window_update_extent(struct gui_window *g); + void gui_window_set_status(struct gui_window *g, const char *text); void gui_window_set_pointer(struct gui_window *g, gui_pointer_shape shape); void gui_window_place_caret(struct gui_window *g, int x, int y, int height, diff --git a/desktop/gui_factory.c b/desktop/gui_factory.c index a4cc1c9a9..62ec8c565 100644 --- a/desktop/gui_factory.c +++ b/desktop/gui_factory.c @@ -92,6 +92,13 @@ static nserror verify_window_register(struct gui_window_table *gwt) if (gwt->set_scroll == NULL) { return NSERROR_BAD_PARAMETER; } + if (gwt->get_dimensions == NULL) { + return NSERROR_BAD_PARAMETER; + } + if (gwt->update_extent == NULL) { + return NSERROR_BAD_PARAMETER; + } + /* fill in the optional entries with defaults */ if (gwt->set_title == NULL) { diff --git a/framebuffer/gui.c b/framebuffer/gui.c index 13d0421d1..cbf9fb9c5 100644 --- a/framebuffer/gui.c +++ b/framebuffer/gui.c @@ -1575,7 +1575,7 @@ gui_window_set_scroll(struct gui_window *gw, int sx, int sy) } -void +static void gui_window_get_dimensions(struct gui_window *g, int *width, int *height, @@ -1590,7 +1590,7 @@ gui_window_get_dimensions(struct gui_window *g, } } -void +static void gui_window_update_extent(struct gui_window *gw) { float scale = gw->bw->scale; @@ -1848,6 +1848,8 @@ static struct gui_window_table framebuffer_gui_window_table = { .update = gui_window_update_box, .get_scroll = gui_window_get_scroll, .set_scroll = gui_window_set_scroll, + .get_dimensions = gui_window_get_dimensions, + .update_extent = gui_window_update_extent, .set_url = gui_window_set_url, .start_throbber = gui_window_start_throbber, diff --git a/gtk/window.c b/gtk/window.c index e6da490e6..14b9f3f7b 100644 --- a/gtk/window.c +++ b/gtk/window.c @@ -988,7 +988,7 @@ static void gui_window_set_scroll(struct gui_window *g, int sx, int sy) gtk_adjustment_set_value(hadj, x); } -void gui_window_update_extent(struct gui_window *g) +static void gui_window_update_extent(struct gui_window *g) { if (!g->bw->current_content) return; @@ -1121,7 +1121,7 @@ void gui_drag_save_selection(struct gui_window *g, const char *selection) } -void gui_window_get_dimensions(struct gui_window *g, int *width, int *height, +static void gui_window_get_dimensions(struct gui_window *g, int *width, int *height, bool scaled) { GtkAllocation alloc; @@ -1179,6 +1179,8 @@ static struct gui_window_table gui_window_table = { .update = gui_window_update_box, .get_scroll = gui_window_get_scroll, .set_scroll = gui_window_set_scroll, + .get_dimensions = gui_window_get_dimensions, + .update_extent = gui_window_update_extent, .set_icon = gui_window_set_icon, diff --git a/monkey/browser.c b/monkey/browser.c index 706034cf2..51ff93e95 100644 --- a/monkey/browser.c +++ b/monkey/browser.c @@ -132,7 +132,7 @@ gui_window_redraw_window(struct gui_window *g) fprintf(stdout, "WINDOW REDRAW WIN %u\n", g->win_num); } -void +static void gui_window_get_dimensions(struct gui_window *g, int *width, int *height, bool scaled) { @@ -183,7 +183,7 @@ gui_window_update_box(struct gui_window *g, const struct rect *rect) } -void +static void gui_window_update_extent(struct gui_window *g) { if (!g->bw->current_content) @@ -570,11 +570,12 @@ static struct gui_window_table gui_window_table = { .update = gui_window_update_box, .get_scroll = gui_window_get_scroll, .set_scroll = gui_window_set_scroll, + .get_dimensions = gui_window_get_dimensions, + .update_extent = gui_window_update_extent, .set_title = gui_window_set_title, .set_url = gui_window_set_url, .set_icon = gui_window_set_icon, - .drag_start = gui_window_drag_start, .save_link = gui_window_save_link, .scroll_visible = gui_window_scroll_visible, diff --git a/riscos/window.c b/riscos/window.c index f722ab187..833bc2b3d 100644 --- a/riscos/window.c +++ b/riscos/window.c @@ -916,7 +916,7 @@ static void gui_window_scroll_visible(struct gui_window *g, int x0, int y0, int * \param scaled whether to return scaled values */ -void gui_window_get_dimensions(struct gui_window *g, int *width, int *height, bool scaled) +static void gui_window_get_dimensions(struct gui_window *g, int *width, int *height, bool scaled) { /* use the cached window sizes */ *width = g->old_width / 2; @@ -935,7 +935,7 @@ void gui_window_get_dimensions(struct gui_window *g, int *width, int *height, bo * \param g gui_window to update the extent of */ -void gui_window_update_extent(struct gui_window *g) +static void gui_window_update_extent(struct gui_window *g) { os_error *error; wimp_window_info info; @@ -5247,11 +5247,12 @@ static struct gui_window_table gui_window_table = { .update = gui_window_update_box, .get_scroll = gui_window_get_scroll, .set_scroll = gui_window_set_scroll, + .get_dimensions = gui_window_get_dimensions, + .update_extent = gui_window_update_extent, .set_icon = gui_window_set_icon, .set_title = gui_window_set_title, .set_url = gui_window_set_url, - .save_link = gui_window_save_link, .drag_start = gui_window_drag_start, .scroll_visible = gui_window_scroll_visible, diff --git a/windows/gui.c b/windows/gui.c index de6634ab7..cb68fa237 100644 --- a/windows/gui.c +++ b/windows/gui.c @@ -1546,7 +1546,7 @@ void gui_window_set_scroll(struct gui_window *w, int sx, int sy) } -void gui_window_get_dimensions(struct gui_window *w, int *width, int *height, +static void gui_window_get_dimensions(struct gui_window *w, int *width, int *height, bool scaled) { if (w == NULL) @@ -1558,7 +1558,7 @@ void gui_window_get_dimensions(struct gui_window *w, int *width, int *height, *height = w->height; } -void gui_window_update_extent(struct gui_window *w) +static void gui_window_update_extent(struct gui_window *w) { } @@ -1854,6 +1854,8 @@ static struct gui_window_table win32_window_table = { .update = gui_window_update_box, .get_scroll = gui_window_get_scroll, .set_scroll = gui_window_set_scroll, + .get_dimensions = gui_window_get_dimensions, + .update_extent = gui_window_update_extent, .set_title = gui_window_set_title, .set_url = gui_window_set_url, From e82d83f1847ebc369a5f48a18217a8f5fecf3824 Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Mon, 13 Jan 2014 14:51:27 +0000 Subject: [PATCH 083/773] move four more optional window operations to table --- amiga/gui.c | 12 ++++++--- amiga/theme.h | 2 +- atari/gui.c | 9 ++++--- atari/gui.h | 5 +++- beos/scaffolding.h | 3 ++- beos/window.cpp | 10 +++++--- cocoa/gui.m | 13 ++++++---- desktop/browser.c | 4 +-- desktop/gui.h | 57 ++++++++++++++++++++++++++++++++++++------- desktop/gui_factory.c | 38 ++++++++++++++++++++++++++--- desktop/textinput.c | 7 +++--- framebuffer/gui.c | 12 ++++++--- gtk/window.c | 13 +++++++--- monkey/browser.c | 12 ++++++--- riscos/gui.h | 1 + riscos/window.c | 57 +++++++++++++++++++++++-------------------- windows/gui.c | 16 ++++++------ 17 files changed, 192 insertions(+), 79 deletions(-) diff --git a/amiga/gui.c b/amiga/gui.c index c69b3f07a..4592eda7a 100644 --- a/amiga/gui.c +++ b/amiga/gui.c @@ -4613,7 +4613,7 @@ static void gui_window_update_extent(struct gui_window *g) g->shared->new_content = true; } -void gui_window_set_status(struct gui_window *g, const char *text) +static void gui_window_set_status(struct gui_window *g, const char *text) { ULONG cur_tab = 0; char *utf8text; @@ -4768,7 +4768,7 @@ static uint32 ami_set_throbber_render_hook(struct Hook *hook, APTR space, return 0; } -void gui_window_place_caret(struct gui_window *g, int x, int y, int height, +static void gui_window_place_caret(struct gui_window *g, int x, int y, int height, const struct rect *clip) { struct IBox *bbox; @@ -4805,7 +4805,7 @@ void gui_window_place_caret(struct gui_window *g, int x, int y, int height, OnMenu(g->shared->win, AMI_MENU_PASTE); } -void gui_window_remove_caret(struct gui_window *g) +static void gui_window_remove_caret(struct gui_window *g) { struct IBox *bbox; int xs,ys; @@ -5098,8 +5098,14 @@ static struct gui_window_table ami_window_table = { .set_icon = gui_window_set_icon, .set_title = gui_window_set_title, .set_url = gui_window_set_url, + .set_status = gui_window_set_status, + .place_caret = gui_window_place_caret, + .remove_caret = gui_window_remove_caret, .drag_start = gui_window_drag_start, .new_content = gui_window_new_content, + + /* from theme */ + .set_pointer = gui_window_set_pointer, .start_throbber = gui_window_start_throbber, .stop_throbber = gui_window_stop_throbber, diff --git a/amiga/theme.h b/amiga/theme.h index b47c015e1..e81db33dd 100644 --- a/amiga/theme.h +++ b/amiga/theme.h @@ -44,6 +44,6 @@ void ami_update_pointer(struct Window *win, gui_pointer_shape shape); void gui_window_start_throbber(struct gui_window *g); void gui_window_stop_throbber(struct gui_window *g); - +void gui_window_set_pointer(struct gui_window *g, gui_pointer_shape shape); #endif diff --git a/atari/gui.c b/atari/gui.c index 8357a0b0a..26a47aad1 100644 --- a/atari/gui.c +++ b/atari/gui.c @@ -612,7 +612,7 @@ static void gui_window_stop_throbber(struct gui_window *w) } /* Place caret in window */ -void gui_window_place_caret(struct gui_window *w, int x, int y, int height, +static void gui_window_place_caret(struct gui_window *w, int x, int y, int height, const struct rect *clip) { window_place_caret(w->root, 1, x, y, height, NULL); @@ -624,7 +624,7 @@ void gui_window_place_caret(struct gui_window *w, int x, int y, int height, /** * clear window caret */ -void +static void gui_window_remove_caret(struct gui_window *w) { if (w == NULL) @@ -1084,7 +1084,10 @@ static struct gui_window_table atari_window_table = { .set_title = gui_window_set_title, .set_url = gui_window_set_url, .set_icon = gui_window_set_icon, - + .set_status = gui_window_set_status, + .set_pointer = gui_window_set_pointer, + .place_caret = gui_window_place_caret, + .remove_caret = gui_window_remove_caret, .new_content = gui_window_new_content, .start_throbber = gui_window_start_throbber, .stop_throbber = gui_window_stop_throbber, diff --git a/atari/gui.h b/atari/gui.h index a1519f375..d552bc87b 100755 --- a/atari/gui.h +++ b/atari/gui.h @@ -163,6 +163,9 @@ extern struct gui_window *window_list; void gui_set_input_gui_window(struct gui_window *gw); struct gui_window *gui_get_input_window(void); char *gui_window_get_url(struct gui_window *gw); -char * gui_window_get_title(struct gui_window *gw); +char *gui_window_get_title(struct gui_window *gw); + +void gui_window_set_status(struct gui_window *w, const char *text); +void gui_window_set_pointer(struct gui_window *gw, gui_pointer_shape shape); #endif diff --git a/beos/scaffolding.h b/beos/scaffolding.h index fe726147c..2dd364d08 100644 --- a/beos/scaffolding.h +++ b/beos/scaffolding.h @@ -202,8 +202,9 @@ void nsbeos_scaffolding_popup_menu(nsbeos_scaffolding *g, BPoint where); void gui_window_set_title(struct gui_window *_g, const char *title); void gui_window_set_url(struct gui_window *_g, const char *url); +void gui_window_set_icon(struct gui_window *_g, hlcache_handle *icon); +void gui_window_set_status(struct gui_window *_g, const char *text); void gui_window_start_throbber(struct gui_window* _g); void gui_window_stop_throbber(struct gui_window* _g); -void gui_window_set_icon(struct gui_window *_g, hlcache_handle *icon); #endif /* NETSURF_BEOS_SCAFFOLDING_H */ diff --git a/beos/window.cpp b/beos/window.cpp index cff33a35b..84199242d 100644 --- a/beos/window.cpp +++ b/beos/window.cpp @@ -1169,7 +1169,7 @@ const uint8 kWatch2CursorBits[] = { }; -void gui_window_set_pointer(struct gui_window *g, gui_pointer_shape shape) +static void gui_window_set_pointer(struct gui_window *g, gui_pointer_shape shape) { BCursor *cursor = NULL; bool allocated = false; @@ -1209,7 +1209,7 @@ void gui_window_set_pointer(struct gui_window *g, gui_pointer_shape shape) delete cursor; } -void gui_window_place_caret(struct gui_window *g, int x, int y, int height, +static void gui_window_place_caret(struct gui_window *g, int x, int y, int height, const struct rect *clip) { //CALLED(); @@ -1230,7 +1230,7 @@ void gui_window_place_caret(struct gui_window *g, int x, int y, int height, g->view->UnlockLooper(); } -void gui_window_remove_caret(struct gui_window *g) +static void gui_window_remove_caret(struct gui_window *g) { int oh = g->careth; @@ -1373,11 +1373,15 @@ static struct gui_window_table gui_window_table = { .update_extent = gui_window_update_extent, .new_content = gui_window_new_content, + .set_pointer = gui_window_set_pointer, + .place_caret = gui_window_place_caret, + .remove_caret = gui_window_remove_caret, /* from scaffold */ .set_icon = gui_window_set_icon, .set_title = gui_window_set_title, .set_url = gui_window_set_url, + .set_status = gui_window_set_status, .start_throbber = gui_window_start_throbber, .stop_throbber = gui_window_stop_throbber, }; diff --git a/cocoa/gui.m b/cocoa/gui.m index f674a7cb0..59d823d96 100644 --- a/cocoa/gui.m +++ b/cocoa/gui.m @@ -161,12 +161,12 @@ static void gui_window_update_extent(struct gui_window *g) [[window browserView] setMinimumSize: cocoa_scaled_size( browser->scale, width, height )]; } -void gui_window_set_status(struct gui_window *g, const char *text) +static void gui_window_set_status(struct gui_window *g, const char *text) { [(BrowserViewController *)g setStatus: [NSString stringWithUTF8String: text]]; } -void gui_window_set_pointer(struct gui_window *g, gui_pointer_shape shape) +static void gui_window_set_pointer(struct gui_window *g, gui_pointer_shape shape) { switch (shape) { case GUI_POINTER_DEFAULT: @@ -233,14 +233,14 @@ static void gui_window_set_icon(struct gui_window *g, hlcache_handle *icon) [image release]; } -void gui_window_place_caret(struct gui_window *g, int x, int y, int height, +static void gui_window_place_caret(struct gui_window *g, int x, int y, int height, const struct rect *clip) { [[(BrowserViewController *)g browserView] addCaretAt: cocoa_point( x, y ) height: cocoa_px_to_pt( height )]; } -void gui_window_remove_caret(struct gui_window *g) +static void gui_window_remove_caret(struct gui_window *g) { [[(BrowserViewController *)g browserView] removeCaret]; } @@ -309,7 +309,10 @@ static struct gui_window_table cocoa_window_table = { .set_title = gui_window_set_title, .set_url = gui_window_set_url, .set_icon = gui_window_set_icon, - + .set_status = gui_window_set_status, + .set_pointer = gui_window_set_pointer, + .place_caret = gui_window_place_caret, + .remove_caret = gui_window_remove_caret, .new_content = gui_window_new_content, .start_throbber = gui_window_start_throbber, .stop_throbber = gui_window_stop_throbber, diff --git a/desktop/browser.c b/desktop/browser.c index 5b34dd555..59cb4d44a 100644 --- a/desktop/browser.c +++ b/desktop/browser.c @@ -2193,7 +2193,7 @@ void browser_window_set_status(struct browser_window *bw, const char *text) } bw->status_miss++; - gui_window_set_status(bw->window, bw->status_text); + guit->window->set_status(bw->window, bw->status_text); } @@ -2235,7 +2235,7 @@ void browser_window_set_pointer(struct browser_window *bw, gui_shape = (gui_pointer_shape)shape; } - gui_window_set_pointer(root->window, gui_shape); + guit->window->set_pointer(root->window, gui_shape); } diff --git a/desktop/gui.h b/desktop/gui.h index 02012fa8f..3f533d224 100644 --- a/desktop/gui.h +++ b/desktop/gui.h @@ -143,12 +143,55 @@ struct gui_window_table { /* Optional entries */ - /** set the window title. */ + /** + * Set the title of a window. + * + * \param g window to update + * \param title new window title + */ void (*set_title)(struct gui_window *g, const char *title); /** set the navigation url. */ void (*set_url)(struct gui_window *g, const char *url); + /** set favicon */ + void (*set_icon)(struct gui_window *g, hlcache_handle *icon); + + + + /** + * Set the status bar of a browser window. + * + * \param g gui_window to update + * \param text new status text + */ + void (*set_status)(struct gui_window *g, const char *text); + + /** + * Change mouse pointer shape + */ + void (*set_pointer)(struct gui_window *g, gui_pointer_shape shape); + + /** + * Place the caret in a browser window. + * + * \param g window with caret + * \param x coordinates of caret + * \param y coordinates of caret + * \param height height of caret + * \param clip clip rectangle, or NULL if none + */ + void (*place_caret)(struct gui_window *g, int x, int y, int height, const struct rect *clip); + + /** + * Remove the caret, if present. + * + * \param g window with caret + */ + void (*remove_caret)(struct gui_window *g); + + + /** start the navigation throbber. */ void (*start_throbber)(struct gui_window *g); @@ -161,12 +204,13 @@ struct gui_window_table { /** save link operation */ void (*save_link)(struct gui_window *g, const char *url, const char *title); - /** set favicon */ - void (*set_icon)(struct gui_window *g, hlcache_handle *icon); - /** * Scrolls the specified area of a browser window into view. * + * @todo investigate if this can be merged with set_scroll + * which is what the default implementation used by most + * toolkits uses. + * * \param g gui_window to scroll * \param x0 left point to ensure visible * \param y0 bottom point to ensure visible @@ -226,11 +270,6 @@ struct gui_table { extern struct gui_table *guit; /* the gui vtable */ -void gui_window_set_status(struct gui_window *g, const char *text); -void gui_window_set_pointer(struct gui_window *g, gui_pointer_shape shape); -void gui_window_place_caret(struct gui_window *g, int x, int y, int height, - const struct rect *clip); -void gui_window_remove_caret(struct gui_window *g); struct gui_download_window *gui_download_window_create(download_context *ctx, diff --git a/desktop/gui_factory.c b/desktop/gui_factory.c index 62ec8c565..e03e7dae0 100644 --- a/desktop/gui_factory.c +++ b/desktop/gui_factory.c @@ -59,11 +59,31 @@ static void gui_default_window_new_content(struct gui_window *g) { } + static bool gui_default_window_scroll_start(struct gui_window *g) { return true; } +static void gui_default_window_set_pointer(struct gui_window *g, + gui_pointer_shape shape) +{ +} + +static void gui_default_window_set_status(struct gui_window *g, + const char *text) +{ +} + +static void gui_default_window_place_caret(struct gui_window *g, + int x, int y, int height, + const struct rect *clip) +{ +} + +static void gui_default_window_remove_caret(struct gui_window *g) +{ +} /** verify window table is valid */ static nserror verify_window_register(struct gui_window_table *gwt) @@ -107,6 +127,21 @@ static nserror verify_window_register(struct gui_window_table *gwt) if (gwt->set_url == NULL) { gwt->set_url = gui_default_window_set_url; } + if (gwt->set_icon == NULL) { + gwt->set_icon = gui_default_window_set_icon; + } + if (gwt->set_status == NULL) { + gwt->set_status = gui_default_window_set_status; + } + if (gwt->set_pointer == NULL) { + gwt->set_pointer = gui_default_window_set_pointer; + } + if (gwt->place_caret == NULL) { + gwt->place_caret = gui_default_window_place_caret; + } + if (gwt->remove_caret == NULL) { + gwt->remove_caret = gui_default_window_remove_caret; + } if (gwt->start_throbber == NULL) { gwt->start_throbber = gui_default_window_start_throbber; } @@ -119,9 +154,6 @@ static nserror verify_window_register(struct gui_window_table *gwt) if (gwt->save_link == NULL) { gwt->save_link = gui_default_window_save_link; } - if (gwt->set_icon == NULL) { - gwt->set_icon = gui_default_window_set_icon; - } if (gwt->scroll_visible == NULL) { gwt->scroll_visible = gui_default_window_scroll_visible; } diff --git a/desktop/textinput.c b/desktop/textinput.c index e804829fa..95c321eaa 100644 --- a/desktop/textinput.c +++ b/desktop/textinput.c @@ -85,7 +85,7 @@ void browser_window_place_caret(struct browser_window *bw, int x, int y, /* TODO: intersect with bw viewport */ - gui_window_place_caret(root_bw->window, x, y, height * bw->scale, crp); + guit->window->place_caret(root_bw->window, x, y, height * bw->scale, crp); /* Set focus browser window */ root_bw->focus = bw; @@ -110,8 +110,9 @@ void browser_window_remove_caret(struct browser_window *bw, bool only_hide) else root_bw->can_edit = false; - if (root_bw->window) - gui_window_remove_caret(root_bw->window); + if (root_bw->window) { + guit->window->remove_caret(root_bw->window); + } } diff --git a/framebuffer/gui.c b/framebuffer/gui.c index cbf9fb9c5..a9457fafe 100644 --- a/framebuffer/gui.c +++ b/framebuffer/gui.c @@ -1604,13 +1604,13 @@ gui_window_update_extent(struct gui_window *gw) fbtk_get_height(gw->browser), 100); } -void +static void gui_window_set_status(struct gui_window *g, const char *text) { fbtk_set_text(g->status, text); } -void +static void gui_window_set_pointer(struct gui_window *g, gui_pointer_shape shape) { switch (shape) { @@ -1737,7 +1737,7 @@ gui_window_remove_caret_cb(fbtk_widget_t *widget) } } -void +static void gui_window_place_caret(struct gui_window *g, int x, int y, int height, const struct rect *clip) { @@ -1755,7 +1755,7 @@ gui_window_place_caret(struct gui_window *g, int x, int y, int height, y + height - bwidget->scrolly); } -void +static void gui_window_remove_caret(struct gui_window *g) { int c_x, c_y, c_h; @@ -1852,6 +1852,10 @@ static struct gui_window_table framebuffer_gui_window_table = { .update_extent = gui_window_update_extent, .set_url = gui_window_set_url, + .set_status = gui_window_set_status, + .set_pointer = gui_window_set_pointer, + .place_caret = gui_window_place_caret, + .remove_caret = gui_window_remove_caret, .start_throbber = gui_window_start_throbber, .stop_throbber = gui_window_stop_throbber, }; diff --git a/gtk/window.c b/gtk/window.c index 14b9f3f7b..f7a348230 100644 --- a/gtk/window.c +++ b/gtk/window.c @@ -916,7 +916,7 @@ static void nsgtk_redraw_caret(struct gui_window *g) } -void gui_window_remove_caret(struct gui_window *g) +static void gui_window_remove_caret(struct gui_window *g) { int sx, sy; int oh = g->careth; @@ -955,7 +955,7 @@ static void gui_window_update_box(struct gui_window *g, const struct rect *rect) (rect->y1 - rect->y0) * g->bw->scale); } -void gui_window_set_status(struct gui_window *g, const char *text) +static void gui_window_set_status(struct gui_window *g, const char *text) { assert(g); assert(g->status_bar); @@ -1009,7 +1009,8 @@ static GdkCursor *nsgtk_create_menu_cursor(void) return cursor; } -void gui_window_set_pointer(struct gui_window *g, gui_pointer_shape shape) +static void gui_window_set_pointer(struct gui_window *g, + gui_pointer_shape shape) { GdkCursor *cursor = NULL; GdkCursorType cursortype; @@ -1094,7 +1095,7 @@ void gui_window_set_pointer(struct gui_window *g, gui_pointer_shape shape) } -void gui_window_place_caret(struct gui_window *g, int x, int y, int height, +static void gui_window_place_caret(struct gui_window *g, int x, int y, int height, const struct rect *clip) { nsgtk_redraw_caret(g); @@ -1183,6 +1184,10 @@ static struct gui_window_table gui_window_table = { .update_extent = gui_window_update_extent, .set_icon = gui_window_set_icon, + .set_status = gui_window_set_status, + .set_pointer = gui_window_set_pointer, + .place_caret = gui_window_place_caret, + .remove_caret = gui_window_remove_caret, /* from scaffold */ .set_title = gui_window_set_title, diff --git a/monkey/browser.c b/monkey/browser.c index 51ff93e95..c2e98f493 100644 --- a/monkey/browser.c +++ b/monkey/browser.c @@ -195,13 +195,13 @@ gui_window_update_extent(struct gui_window *g) content_get_height(g->bw->current_content)); } -void +static void gui_window_set_status(struct gui_window *g, const char *text) { fprintf(stdout, "WINDOW SET_STATUS WIN %u STR %s\n", g->win_num, text); } -void +static void gui_window_set_pointer(struct gui_window *g, gui_pointer_shape shape) { const char *ptr_name = "UNKNOWN"; @@ -348,7 +348,7 @@ void gui_set_clipboard(const char *buffer, size_t length, { } -void +static void gui_window_place_caret(struct gui_window *g, int x, int y, int height, const struct rect *clip) { @@ -356,7 +356,7 @@ gui_window_place_caret(struct gui_window *g, int x, int y, int height, g->win_num, x, y, height); } -void +static void gui_window_remove_caret(struct gui_window *g) { fprintf(stdout, "WINDOW REMOVE_CARET WIN %u\n", g->win_num); @@ -576,6 +576,10 @@ static struct gui_window_table gui_window_table = { .set_title = gui_window_set_title, .set_url = gui_window_set_url, .set_icon = gui_window_set_icon, + .set_status = gui_window_set_status, + .set_pointer = gui_window_set_pointer, + .place_caret = gui_window_place_caret, + .remove_caret = gui_window_remove_caret, .drag_start = gui_window_drag_start, .save_link = gui_window_save_link, .scroll_visible = gui_window_scroll_visible, diff --git a/riscos/gui.h b/riscos/gui.h index 827af8108..1abb40fba 100644 --- a/riscos/gui.h +++ b/riscos/gui.h @@ -154,6 +154,7 @@ browser_mouse_state ro_gui_mouse_drag_state(wimp_mouse_state buttons, bool ro_gui_shift_pressed(void); bool ro_gui_ctrl_pressed(void); bool ro_gui_alt_pressed(void); +void gui_window_set_pointer(struct gui_window *g, gui_pointer_shape shape); /* in history.c */ void ro_gui_history_init(void); diff --git a/riscos/window.c b/riscos/window.c index 833bc2b3d..feb7f8979 100644 --- a/riscos/window.c +++ b/riscos/window.c @@ -372,6 +372,30 @@ void ro_gui_window_initialise(void) * Interface With Core */ +/** + * Place the caret in a browser window. + * + * \param g window with caret + * \param x coordinates of caret + * \param y coordinates of caret + * \param height height of caret + * \param clip clip rectangle, or NULL if none + */ + +static void gui_window_place_caret(struct gui_window *g, int x, int y, int height, + const struct rect *clip) +{ + os_error *error; + + error = xwimp_set_caret_position(g->window, -1, + x * 2, -(y + height) * 2, height * 2, -1); + if (error) { + LOG(("xwimp_set_caret_position: 0x%x: %s", + error->errnum, error->errmess)); + warn_user("WimpError", error->errmess); + } +} + /** * Create and open a new browser window. * @@ -987,7 +1011,7 @@ static void gui_window_update_extent(struct gui_window *g) * \param text new status text */ -void gui_window_set_status(struct gui_window *g, const char *text) +static void gui_window_set_status(struct gui_window *g, const char *text) { if (g->status_bar) ro_gui_status_bar_set_text(g->status_bar, text); @@ -1097,29 +1121,6 @@ static void gui_window_set_icon(struct gui_window *g, hlcache_handle *icon) ro_toolbar_set_site_favicon(g->toolbar, icon); } -/** - * Place the caret in a browser window. - * - * \param g window with caret - * \param x coordinates of caret - * \param y coordinates of caret - * \param height height of caret - * \param clip clip rectangle, or NULL if none - */ - -void gui_window_place_caret(struct gui_window *g, int x, int y, int height, - const struct rect *clip) -{ - os_error *error; - - error = xwimp_set_caret_position(g->window, -1, - x * 2, -(y + height) * 2, height * 2, -1); - if (error) { - LOG(("xwimp_set_caret_position: 0x%x: %s", - error->errnum, error->errmess)); - warn_user("WimpError", error->errmess); - } -} /** @@ -1128,7 +1129,7 @@ void gui_window_place_caret(struct gui_window *g, int x, int y, int height, * \param g window with caret */ -void gui_window_remove_caret(struct gui_window *g) +static void gui_window_remove_caret(struct gui_window *g) { wimp_caret caret; os_error *error; @@ -5250,9 +5251,13 @@ static struct gui_window_table gui_window_table = { .get_dimensions = gui_window_get_dimensions, .update_extent = gui_window_update_extent, - .set_icon = gui_window_set_icon, .set_title = gui_window_set_title, .set_url = gui_window_set_url, + .set_icon = gui_window_set_icon, + .set_status = gui_window_set_status, + .set_pointer = gui_window_set_pointer, + .place_caret = gui_window_place_caret, + .remove_caret = gui_window_remove_caret, .save_link = gui_window_save_link, .drag_start = gui_window_drag_start, .scroll_visible = gui_window_scroll_visible, diff --git a/windows/gui.c b/windows/gui.c index cb68fa237..aa1cbec8b 100644 --- a/windows/gui.c +++ b/windows/gui.c @@ -1566,7 +1566,7 @@ static void gui_window_update_extent(struct gui_window *w) /** * set the status bar message */ -void gui_window_set_status(struct gui_window *w, const char *text) +static void gui_window_set_status(struct gui_window *w, const char *text) { if (w == NULL) return; @@ -1576,7 +1576,7 @@ void gui_window_set_status(struct gui_window *w, const char *text) /** * set the pointer shape */ -void gui_window_set_pointer(struct gui_window *w, gui_pointer_shape shape) +static void gui_window_set_pointer(struct gui_window *w, gui_pointer_shape shape) { if (w == NULL) return; @@ -1708,8 +1708,8 @@ static void gui_window_stop_throbber(struct gui_window *w) /** * place caret in window */ -void gui_window_place_caret(struct gui_window *w, int x, int y, int height, - const struct rect *clip) +static void gui_window_place_caret(struct gui_window *w, int x, int y, + int height, const struct rect *clip) { if (w == NULL) return; @@ -1722,8 +1722,7 @@ void gui_window_place_caret(struct gui_window *w, int x, int y, int height, /** * clear window caret */ -void -gui_window_remove_caret(struct gui_window *w) +static void gui_window_remove_caret(struct gui_window *w) { if (w == NULL) return; @@ -1859,7 +1858,10 @@ static struct gui_window_table win32_window_table = { .set_title = gui_window_set_title, .set_url = gui_window_set_url, - + .set_status = gui_window_set_status, + .set_pointer = gui_window_set_pointer, + .place_caret = gui_window_place_caret, + .remove_caret = gui_window_remove_caret, .start_throbber = gui_window_start_throbber, .stop_throbber = gui_window_stop_throbber, }; From d18c8ed4521714c3fff3cca64685b8192ca0e075 Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Mon, 13 Jan 2014 22:54:19 +0000 Subject: [PATCH 084/773] move teh final optional window operations into the table --- amiga/clipboard.c | 11 ----- amiga/clipboard.h | 2 + amiga/drag.c | 4 +- amiga/drag.h | 3 ++ amiga/gui.c | 6 ++- atari/gui.c | 32 ------------- beos/gui.cpp | 8 ---- beos/window.cpp | 18 +------- cocoa/gui.m | 15 ------ cocoa/selection.m | 9 ---- desktop/browser.c | 37 ++++++++------- desktop/gui.h | 102 +++++++++++++++++++++-------------------- desktop/gui_factory.c | 34 ++++++++++++++ desktop/selection.c | 6 +-- framebuffer/gui.c | 29 ------------ gtk/selection.c | 11 ----- gtk/window.c | 28 +++++------ monkey/browser.c | 28 ----------- riscos/gui.c | 7 --- riscos/save.c | 4 +- riscos/save.h | 3 ++ riscos/textselection.c | 14 ------ riscos/textselection.h | 2 + riscos/window.c | 7 +++ windows/gui.c | 24 ---------- 25 files changed, 150 insertions(+), 294 deletions(-) diff --git a/amiga/clipboard.c b/amiga/clipboard.c index d37fb1aec..18598798c 100644 --- a/amiga/clipboard.c +++ b/amiga/clipboard.c @@ -107,17 +107,6 @@ void gui_start_selection(struct gui_window *g) OnMenu(g->shared->win, AMI_MENU_CUT); } -void gui_clear_selection(struct gui_window *g) -{ - if(!g) return; - if(!g->shared->win) return; - if(nsoption_bool(kiosk_mode) == true) return; - - OffMenu(g->shared->win, AMI_MENU_CLEAR); - OffMenu(g->shared->win, AMI_MENU_CUT); - OffMenu(g->shared->win, AMI_MENU_COPY); -} - char *ami_clipboard_cat_collection(struct CollectionItem *ci, LONG codeset, size_t *text_length) { struct CollectionItem *ci_new = NULL, *ci_next, *ci_curr = ci; diff --git a/amiga/clipboard.h b/amiga/clipboard.h index cf3f74087..88de64340 100755 --- a/amiga/clipboard.h +++ b/amiga/clipboard.h @@ -26,6 +26,8 @@ struct selection; struct gui_window; struct gui_window_2; +void gui_start_selection(struct gui_window *g); + void ami_clipboard_init(void); void ami_clipboard_free(void); void ami_drag_selection(struct gui_window *g); diff --git a/amiga/drag.c b/amiga/drag.c index 1123ba265..f8944d3a5 100644 --- a/amiga/drag.c +++ b/amiga/drag.c @@ -50,8 +50,8 @@ ULONG drag_icon_width; ULONG drag_icon_height; BOOL drag_in_progress = FALSE; -void gui_drag_save_object(gui_save_type type, hlcache_handle *c, - struct gui_window *g) +void gui_drag_save_object(struct gui_window *g, hlcache_handle *c, + gui_save_type type) { const char *filetype = NULL; diff --git a/amiga/drag.h b/amiga/drag.h index 218aa67f8..cfe9719ce 100644 --- a/amiga/drag.h +++ b/amiga/drag.h @@ -26,6 +26,9 @@ int drag_save; void *drag_save_data; struct gui_window *drag_save_gui; +void gui_drag_save_selection(struct gui_window *g, const char *selection); +void gui_drag_save_object(struct gui_window *g, hlcache_handle *c, gui_save_type type); + void ami_drag_save(struct Window *win); void ami_drag_icon_show(struct Window *win, const char *type); void ami_drag_icon_close(struct Window *win); diff --git a/amiga/gui.c b/amiga/gui.c index 4592eda7a..13c32cd8b 100644 --- a/amiga/gui.c +++ b/amiga/gui.c @@ -5066,7 +5066,7 @@ void ami_gui_splash_close(Object *win_obj) if(win_obj) DisposeObject(win_obj); } -void gui_file_gadget_open(struct gui_window *g, hlcache_handle *hl, +static void gui_file_gadget_open(struct gui_window *g, hlcache_handle *hl, struct form_control *gadget) { LOG(("File open dialog rquest for %p/%p", g, gadget)); @@ -5103,6 +5103,10 @@ static struct gui_window_table ami_window_table = { .remove_caret = gui_window_remove_caret, .drag_start = gui_window_drag_start, .new_content = gui_window_new_content, + .file_gadget_open = gui_file_gadget_open, + .drag_save_object = gui_drag_save_object, + .drag_save_selection =gui_drag_save_selection, + .start_selection = gui_start_selection, /* from theme */ .set_pointer = gui_window_set_pointer, diff --git a/atari/gui.c b/atari/gui.c index 26a47aad1..c2109c985 100644 --- a/atari/gui.c +++ b/atari/gui.c @@ -445,13 +445,6 @@ static void gui_window_update_extent(struct gui_window *gw) } -void gui_clear_selection(struct gui_window *g) -{ - -} - - - /** * set the pointer shape */ @@ -659,24 +652,6 @@ static void gui_window_new_content(struct gui_window *w) gui_window_redraw_window(w); } -void gui_drag_save_object(gui_save_type type, hlcache_handle *c, - struct gui_window *w) -{ - LOG(("")); - TODO(); -} - -void gui_drag_save_selection(struct gui_window *g, const char *selection) -{ - LOG(("")); - TODO(); -} - -void gui_start_selection(struct gui_window *w) -{ - -} - /** * Core asks front end for clipboard contents. @@ -1064,13 +1039,6 @@ static void gui_init2(int argc, char** argv) toolbar_init(); } -void gui_file_gadget_open(struct gui_window *g, hlcache_handle *hl, - struct form_control *gadget) -{ - LOG(("File open dialog rquest for %p/%p", g, gadget)); - /* browser_window_set_gadget_filename(bw, gadget, "filename"); */ -} - static struct gui_window_table atari_window_table = { .create = gui_window_create, .destroy = gui_window_destroy, diff --git a/beos/gui.cpp b/beos/gui.cpp index 42a681c30..efac0bb4c 100644 --- a/beos/gui.cpp +++ b/beos/gui.cpp @@ -1073,14 +1073,6 @@ bool path_add_part(char *path, int length, const char *newpart) return true; } -void gui_file_gadget_open(struct gui_window *g, hlcache_handle *hl, - struct form_control *gadget) -{ - LOG(("File open dialog rquest for %p/%p", g, gadget)); - /* browser_window_set_gadget_filename(bw, gadget, "filename"); */ -} - - static struct gui_table beos_gui_table = { .poll = gui_poll, .quit = gui_quit, diff --git a/beos/window.cpp b/beos/window.cpp index 84199242d..a7bdf411e 100644 --- a/beos/window.cpp +++ b/beos/window.cpp @@ -1268,18 +1268,7 @@ static void gui_window_new_content(struct gui_window *g) g->view->UnlockLooper(); } -void gui_drag_save_object(gui_save_type type, hlcache_handle *c, - struct gui_window *g) -{ - -} - -void gui_drag_save_selection(struct gui_window *g, const char *selection) -{ - -} - -void gui_start_selection(struct gui_window *g) +static void gui_start_selection(struct gui_window *g) { if (!g->view->LockLooper()) return; @@ -1289,10 +1278,6 @@ void gui_start_selection(struct gui_window *g) g->view->UnlockLooper(); } -void gui_clear_selection(struct gui_window *g) -{ -} - void gui_get_clipboard(char **buffer, size_t *length) { BMessage *clip; @@ -1376,6 +1361,7 @@ static struct gui_window_table gui_window_table = { .set_pointer = gui_window_set_pointer, .place_caret = gui_window_place_caret, .remove_caret = gui_window_remove_caret, + .start_selection = gui_start_selection, /* from scaffold */ .set_icon = gui_window_set_icon, diff --git a/cocoa/gui.m b/cocoa/gui.m index 59d823d96..40dc8e191 100644 --- a/cocoa/gui.m +++ b/cocoa/gui.m @@ -250,15 +250,6 @@ static void gui_window_new_content(struct gui_window *g) [(BrowserViewController *)g contentUpdated]; } -void gui_drag_save_object(gui_save_type type, hlcache_handle *c, - struct gui_window *g) -{ -} - -void gui_drag_save_selection(struct gui_window *g, const char *selection) -{ -} - void gui_create_form_select_menu(struct browser_window *bw, struct form_control *control) @@ -289,12 +280,6 @@ void gui_401login_open(nsurl *url, const char *realm, cb( false, cbpw ); } -void gui_file_gadget_open(struct gui_window *g, hlcache_handle *hl, - struct form_control *gadget) -{ - LOG(("File open dialog rquest for %p/%p", g, gadget)); - /* browser_window_set_gadget_filename(bw, gadget, "filename"); */ -} static struct gui_window_table cocoa_window_table = { .create = gui_window_create, diff --git a/cocoa/selection.m b/cocoa/selection.m index 237c61ce2..daa64bf08 100644 --- a/cocoa/selection.m +++ b/cocoa/selection.m @@ -25,15 +25,6 @@ static NSMutableString *cocoa_clipboard_string; -void gui_start_selection(struct gui_window *g) -{ -} - -void gui_clear_selection(struct gui_window *g) -{ -} - - /** * Core asks front end for clipboard contents. * diff --git a/desktop/browser.c b/desktop/browser.c index 59cb4d44a..30aeead0c 100644 --- a/desktop/browser.c +++ b/desktop/browser.c @@ -1484,20 +1484,23 @@ static nserror browser_window_callback(hlcache_handle *c, switch(event->data.dragsave.type) { case CONTENT_SAVE_ORIG: - gui_drag_save_object(GUI_SAVE_OBJECT_ORIG, save, - root->window); + guit->window->drag_save_object(root->window, save, + GUI_SAVE_OBJECT_ORIG); break; + case CONTENT_SAVE_NATIVE: - gui_drag_save_object(GUI_SAVE_OBJECT_NATIVE, save, - root->window); + guit->window->drag_save_object(root->window, save, + GUI_SAVE_OBJECT_NATIVE); break; + case CONTENT_SAVE_COMPLETE: - gui_drag_save_object(GUI_SAVE_COMPLETE, save, - root->window); + guit->window->drag_save_object(root->window, save, + GUI_SAVE_COMPLETE); break; + case CONTENT_SAVE_SOURCE: - gui_drag_save_object(GUI_SAVE_SOURCE, save, - root->window); + guit->window->drag_save_object(root->window, save, + GUI_SAVE_SOURCE); break; } } @@ -1563,7 +1566,7 @@ static nserror browser_window_callback(hlcache_handle *c, case CONTENT_MSG_GADGETCLICK: if (event->data.gadget_click.gadget->type == GADGET_FILE) { - gui_file_gadget_open(bw->window, c, + guit->window->file_gadget_open(bw->window, c, event->data.gadget_click.gadget); } @@ -2893,14 +2896,14 @@ void browser_window_mouse_click(struct browser_window *bw, break; default: if (mouse & BROWSER_MOUSE_MOD_2) { - if (mouse & BROWSER_MOUSE_DRAG_2) - gui_drag_save_object(GUI_SAVE_OBJECT_NATIVE, c, - bw->window); - else if (mouse & BROWSER_MOUSE_DRAG_1) - gui_drag_save_object(GUI_SAVE_OBJECT_ORIG, c, - bw->window); - } - else if (mouse & (BROWSER_MOUSE_DRAG_1 | + if (mouse & BROWSER_MOUSE_DRAG_2) { + guit->window->drag_save_object(bw->window, c, + GUI_SAVE_OBJECT_NATIVE); + } else if (mouse & BROWSER_MOUSE_DRAG_1) { + guit->window->drag_save_object(bw->window, c, + GUI_SAVE_OBJECT_ORIG); + } + } else if (mouse & (BROWSER_MOUSE_DRAG_1 | BROWSER_MOUSE_DRAG_2)) { browser_window_page_drag_start(bw, x, y); browser_window_set_pointer(bw, BROWSER_POINTER_MOVE); diff --git a/desktop/gui.h b/desktop/gui.h index 3f533d224..8d65893d0 100644 --- a/desktop/gui.h +++ b/desktop/gui.h @@ -157,8 +157,6 @@ struct gui_window_table { /** set favicon */ void (*set_icon)(struct gui_window *g, hlcache_handle *icon); - - /** * Set the status bar of a browser window. * @@ -190,8 +188,6 @@ struct gui_window_table { */ void (*remove_caret)(struct gui_window *g); - - /** start the navigation throbber. */ void (*start_throbber)(struct gui_window *g); @@ -233,6 +229,19 @@ struct gui_window_table { */ void (*new_content)(struct gui_window *g); + /** + * Called when file chooser gadget is activated + */ + void (*file_gadget_open)(struct gui_window *g, hlcache_handle *hl, struct form_control *gadget); + + /** object dragged to window*/ + void (*drag_save_object)(struct gui_window *g, hlcache_handle *c, gui_save_type type); + + /** drag selection save */ + void (*drag_save_selection)(struct gui_window *g, const char *selection); + + /** selection started */ + void (*start_selection)(struct gui_window *g); }; /** Graphical user interface function table @@ -280,52 +289,7 @@ void gui_download_window_error(struct gui_download_window *dw, const char *error_msg); void gui_download_window_done(struct gui_download_window *dw); -void gui_drag_save_object(gui_save_type type, hlcache_handle *c, - struct gui_window *g); -void gui_drag_save_selection(struct gui_window *g, const char *selection); -void gui_start_selection(struct gui_window *g); -void gui_clear_selection(struct gui_window *g); -void gui_file_gadget_open(struct gui_window *g, hlcache_handle *hl, - struct form_control *gadget); - -void gui_launch_url(const char *url); - -/** - * Core asks front end for clipboard contents. - * - * \param buffer UTF-8 text, allocated by front end, ownership yeilded to core - * \param length Byte length of UTF-8 text in buffer - */ -void gui_get_clipboard(char **buffer, size_t *length); - -typedef struct nsnsclipboard_styles { - size_t start; /**< Start of run */ - - plot_font_style_t style; /**< Style to give text run */ -} nsclipboard_styles; -/** - * Core tells front end to put given text in clipboard - * - * \param buffer UTF-8 text, owned by core - * \param length Byte length of UTF-8 text in buffer - * \param styles Array of styles given to text runs, owned by core, or NULL - * \param n_styles Number of text run styles in array - */ -void gui_set_clipboard(const char *buffer, size_t length, - nsclipboard_styles styles[], int n_styles); - - - -void gui_create_form_select_menu(struct browser_window *bw, - struct form_control *control); - - -struct ssl_cert_info; - -void gui_cert_verify(nsurl *url, const struct ssl_cert_info *certs, - unsigned long num, nserror (*cb)(bool proceed, void *pw), - void *cbpw); /** * Callback to translate resource to full url. @@ -340,4 +304,44 @@ void gui_cert_verify(nsurl *url, const struct ssl_cert_info *certs, */ nsurl* gui_get_resource_url(const char *path); + +void gui_launch_url(const char *url); + +void gui_create_form_select_menu(struct browser_window *bw, + struct form_control *control); + +/** + * Core asks front end for clipboard contents. + * + * \param buffer UTF-8 text, allocated by front end, ownership yeilded to core + * \param length Byte length of UTF-8 text in buffer + */ +void gui_get_clipboard(char **buffer, size_t *length); + +typedef struct nsnsclipboard_styles { + size_t start; /**< Start of run */ + + plot_font_style_t style; /**< Style to give text run */ +} nsclipboard_styles; + +/** + * Core tells front end to put given text in clipboard + * + * \param buffer UTF-8 text, owned by core + * \param length Byte length of UTF-8 text in buffer + * \param styles Array of styles given to text runs, owned by core, or NULL + * \param n_styles Number of text run styles in array + */ +void gui_set_clipboard(const char *buffer, size_t length, + nsclipboard_styles styles[], int n_styles); + + + +struct ssl_cert_info; + +void gui_cert_verify(nsurl *url, const struct ssl_cert_info *certs, + unsigned long num, nserror (*cb)(bool proceed, void *pw), + void *cbpw); + + #endif diff --git a/desktop/gui_factory.c b/desktop/gui_factory.c index e03e7dae0..8ebf3515a 100644 --- a/desktop/gui_factory.c +++ b/desktop/gui_factory.c @@ -85,6 +85,28 @@ static void gui_default_window_remove_caret(struct gui_window *g) { } +static void gui_default_window_file_gadget_open(struct gui_window *g, + hlcache_handle *hl, + struct form_control *gadget) +{ +} + +static void gui_default_window_drag_save_object(struct gui_window *g, + hlcache_handle *c, + gui_save_type type) +{ +} + +static void gui_default_window_drag_save_selection(struct gui_window *g, + const char *selection) +{ +} + +static void gui_default_window_start_selection(struct gui_window *g) +{ +} + + /** verify window table is valid */ static nserror verify_window_register(struct gui_window_table *gwt) { @@ -163,6 +185,18 @@ static nserror verify_window_register(struct gui_window_table *gwt) if (gwt->scroll_start == NULL) { gwt->scroll_start = gui_default_window_scroll_start; } + if (gwt->file_gadget_open == NULL) { + gwt->file_gadget_open = gui_default_window_file_gadget_open; + } + if (gwt->drag_save_object == NULL) { + gwt->drag_save_object = gui_default_window_drag_save_object; + } + if (gwt->drag_save_selection == NULL) { + gwt->drag_save_selection = gui_default_window_drag_save_selection; + } + if (gwt->start_selection == NULL) { + gwt->start_selection = gui_default_window_start_selection; + } return NSERROR_OK; } diff --git a/desktop/selection.c b/desktop/selection.c index 13a1293e3..ca383c179 100644 --- a/desktop/selection.c +++ b/desktop/selection.c @@ -274,7 +274,7 @@ bool selection_click(struct selection *s, browser_mouse_state mouse, (modkeys && (mouse & BROWSER_MOUSE_DRAG_2)))) { /* drag-saving selection */ char *sel = selection_get_copy(s); - gui_drag_save_selection(top->window, sel); + guit->window->drag_save_selection(top->window, sel); free(sel); } else if (!modkeys) { @@ -293,7 +293,7 @@ bool selection_click(struct selection *s, browser_mouse_state mouse, s->drag_state = DRAG_END; - gui_start_selection(top->window); + guit->window->start_selection(top->window); } else if (mouse & BROWSER_MOUSE_DRAG_2) { @@ -312,7 +312,7 @@ bool selection_click(struct selection *s, browser_mouse_state mouse, s->drag_state = DRAG_START; } - gui_start_selection(top->window); + guit->window->start_selection(top->window); } else if (mouse & BROWSER_MOUSE_CLICK_2) { diff --git a/framebuffer/gui.c b/framebuffer/gui.c index a9457fafe..eff0a98e1 100644 --- a/framebuffer/gui.c +++ b/framebuffer/gui.c @@ -1791,28 +1791,6 @@ gui_download_window_done(struct gui_download_window *dw) { } -void -gui_drag_save_object(gui_save_type type, - hlcache_handle *c, - struct gui_window *w) -{ -} - -void -gui_drag_save_selection(struct gui_window *g, const char *selection) -{ -} - -void -gui_start_selection(struct gui_window *g) -{ -} - -void -gui_clear_selection(struct gui_window *g) -{ -} - void gui_create_form_select_menu(struct browser_window *bw, struct form_control *control) @@ -1834,13 +1812,6 @@ gui_cert_verify(nsurl *url, cb(false, cbpw); } -void gui_file_gadget_open(struct gui_window *g, hlcache_handle *hl, - struct form_control *gadget) -{ - LOG(("File open dialog rquest for %p/%p", g, gadget)); - /* browser_window_set_gadget_filename(bw, gadget, "filename"); */ -} - static struct gui_window_table framebuffer_gui_window_table = { .create = gui_window_create, .destroy = gui_window_destroy, diff --git a/gtk/selection.c b/gtk/selection.c index b0978b385..8bdc0f8c8 100644 --- a/gtk/selection.c +++ b/gtk/selection.c @@ -30,17 +30,6 @@ static GString *current_selection = NULL; static GtkClipboard *clipboard; - - -void gui_start_selection(struct gui_window *g) -{ - gtk_widget_grab_focus(GTK_WIDGET(nsgtk_window_get_layout(g))); -} - -void gui_clear_selection(struct gui_window *g) -{ -} - /** * Core asks front end for clipboard contents. * diff --git a/gtk/window.c b/gtk/window.c index f7a348230..8b66be60d 100644 --- a/gtk/window.c +++ b/gtk/window.c @@ -28,6 +28,7 @@ #include "content/hlcache.h" #include "gtk/window.h" +#include "gtk/selection.h" #include "desktop/browser_private.h" #include "desktop/mouse.h" #include "utils/nsoption.h" @@ -1110,18 +1111,6 @@ static void gui_window_place_caret(struct gui_window *g, int x, int y, int heigh } - -void gui_drag_save_object(gui_save_type type, hlcache_handle *c, - struct gui_window *g) -{ - -} - -void gui_drag_save_selection(struct gui_window *g, const char *selection) -{ - -} - static void gui_window_get_dimensions(struct gui_window *g, int *width, int *height, bool scaled) { @@ -1141,13 +1130,18 @@ static void gui_window_get_dimensions(struct gui_window *g, int *width, int *hei LOG(("height: %i", *height)); } -void gui_file_gadget_open(struct gui_window *g, hlcache_handle *hl, - struct form_control *gadget) +static void gui_window_start_selection(struct gui_window *g) +{ + gtk_widget_grab_focus(GTK_WIDGET(g->layout)); +} + +static void +gui_window_file_gadget_open(struct gui_window *g, + hlcache_handle *hl, + struct form_control *gadget) { GtkWidget *dialog; - LOG(("Awooga.")); - dialog = gtk_file_chooser_dialog_new("Select File", nsgtk_scaffolding_window(g->scaffold), GTK_FILE_CHOOSER_ACTION_OPEN, @@ -1188,6 +1182,8 @@ static struct gui_window_table gui_window_table = { .set_pointer = gui_window_set_pointer, .place_caret = gui_window_place_caret, .remove_caret = gui_window_remove_caret, + .file_gadget_open = gui_window_file_gadget_open, + .start_selection = gui_window_start_selection, /* from scaffold */ .set_title = gui_window_set_title, diff --git a/monkey/browser.c b/monkey/browser.c index c2e98f493..7cada343e 100644 --- a/monkey/browser.c +++ b/monkey/browser.c @@ -276,13 +276,6 @@ gui_window_set_url(struct gui_window *g, const char *url) fprintf(stdout, "WINDOW SET_URL WIN %u URL %s\n", g->win_num, url); } -void -gui_drag_save_object(gui_save_type type, hlcache_handle *c, - struct gui_window *g) -{ - /* Ignore? */ -} - static bool gui_window_get_scroll(struct gui_window *g, int *sx, int *sy) { @@ -309,21 +302,6 @@ gui_window_scroll_visible(struct gui_window *g, int x0, int y0, g->win_num, x0, y0, x1, y1); } -void -gui_drag_save_selection(struct gui_window *g, const char *selection) -{ -} - -void -gui_start_selection(struct gui_window *g) -{ -} - -void -gui_clear_selection(struct gui_window *g) -{ -} - /** * Core asks front end for clipboard contents. * @@ -386,12 +364,6 @@ gui_window_save_link(struct gui_window *g, const char *url, g->win_num, url, title); } -void gui_file_gadget_open(struct gui_window *g, hlcache_handle *hl, - struct form_control *gadget) -{ - LOG(("File open dialog rquest for %p/%p", g, gadget)); - /* browser_window_set_gadget_filename(bw, gadget, "filename"); */ -} /**** Handlers ****/ diff --git a/riscos/gui.c b/riscos/gui.c index 2854744df..f7caf02da 100644 --- a/riscos/gui.c +++ b/riscos/gui.c @@ -2432,10 +2432,3 @@ bool path_add_part(char *path, int length, const char *newpart) return true; } -void gui_file_gadget_open(struct gui_window *g, hlcache_handle *hl, - struct form_control *gadget) -{ - LOG(("File open dialog rquest for %p/%p", g, gadget)); - /* browser_window_set_gadget_filename(bw, gadget, "filename"); */ -} - diff --git a/riscos/save.c b/riscos/save.c index 4d1740397..59222c49a 100644 --- a/riscos/save.c +++ b/riscos/save.c @@ -357,8 +357,8 @@ bool ro_gui_save_ok(wimp_w w) * \param g gui window */ -void gui_drag_save_object(gui_save_type save_type, hlcache_handle *c, - struct gui_window *g) +void gui_drag_save_object(struct gui_window *g, hlcache_handle *c, + gui_save_type save_type) { wimp_pointer pointer; char icon_buf[20]; diff --git a/riscos/save.h b/riscos/save.h index 34a4a6ba9..0c917664a 100644 --- a/riscos/save.h +++ b/riscos/save.h @@ -27,6 +27,9 @@ #include "oslib/wimp.h" #include "desktop/gui.h" +void gui_drag_save_object(struct gui_window *g, hlcache_handle *c, gui_save_type save_type); +void gui_drag_save_selection(struct gui_window *g, const char *selection); + wimp_w ro_gui_saveas_create(const char *template_name); void ro_gui_saveas_quit(void); void ro_gui_save_prepare(gui_save_type save_type, struct hlcache_handle *h, diff --git a/riscos/textselection.c b/riscos/textselection.c index ab8ea5c3a..73b5246e3 100644 --- a/riscos/textselection.c +++ b/riscos/textselection.c @@ -186,20 +186,6 @@ static void ro_gui_selection_drag_end(wimp_dragged *drag, void *data) browser_window_mouse_track(g->bw, 0, pos.x, pos.y); } - -/** - * Perform tasks after a selection has been cleared. - * - * \param g gui window - */ - -void gui_clear_selection(struct gui_window *g) -{ - /* Refresh any open menu, in case it's the browser window menu. */ - ro_gui_menu_refresh(0); -} - - /** * Core tells front end to put given text in clipboard * diff --git a/riscos/textselection.h b/riscos/textselection.h index c6f96f0e9..a4f436ddc 100644 --- a/riscos/textselection.h +++ b/riscos/textselection.h @@ -26,6 +26,8 @@ #include "oslib/wimp.h" #include "desktop/gui.h" +void gui_start_selection(struct gui_window *g); + typedef void (*ro_gui_selection_prepare_paste_cb)(void *pw); void ro_gui_selection_prepare_paste(wimp_w w, diff --git a/riscos/window.c b/riscos/window.c index feb7f8979..e4c515c36 100644 --- a/riscos/window.c +++ b/riscos/window.c @@ -5265,6 +5265,13 @@ static struct gui_window_table gui_window_table = { .new_content = gui_window_new_content, .start_throbber = gui_window_start_throbber, .stop_throbber = gui_window_stop_throbber, + + /* from save */ + .drag_save_object = gui_drag_save_object, + .drag_save_selection =gui_drag_save_selection, + + /* from textselection */ + .start_selection = gui_start_selection, }; struct gui_window_table *riscos_gui_window_table = &gui_window_table; diff --git a/windows/gui.c b/windows/gui.c index aa1cbec8b..c813c8b46 100644 --- a/windows/gui.c +++ b/windows/gui.c @@ -76,12 +76,6 @@ static struct nsws_pointers nsws_pointer; void gui_window_set_scroll(struct gui_window *w, int sx, int sy); static bool gui_window_get_scroll(struct gui_window *w, int *sx, int *sy); -void gui_file_gadget_open(struct gui_window *g, hlcache_handle *hl, - struct form_control *gadget) -{ - LOG(("File open dialog rquest for %p/%p", g, gadget)); - /* browser_window_set_gadget_filename(bw, gadget, "filename"); */ -} static void gui_poll(bool active) { @@ -1729,24 +1723,6 @@ static void gui_window_remove_caret(struct gui_window *w) HideCaret(w->drawingarea); } -void gui_drag_save_object(gui_save_type type, hlcache_handle *c, - struct gui_window *w) -{ -} - - -void gui_drag_save_selection(struct gui_window *g, const char *selection) -{ -} - -void gui_start_selection(struct gui_window *w) -{ -} - -void gui_clear_selection(struct gui_window *w) -{ -} - /** * Core asks front end for clipboard contents. * From 8dfe22515312a8ecf4da974feb31b0f5e7f317e5 Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Tue, 14 Jan 2014 16:04:02 +0000 Subject: [PATCH 085/773] move download operations to download table --- amiga/download.c | 17 +++++-- amiga/download.h | 2 + amiga/gui.c | 2 + atari/download.c | 20 ++++++--- atari/download.h | 2 + atari/gui.c | 3 ++ beos/download.cpp | 17 +++++-- beos/download.h | 1 + beos/gui.cpp | 5 +++ cocoa/DownloadWindowController.h | 2 + cocoa/DownloadWindowController.m | 17 +++++-- cocoa/NetsurfApp.m | 2 + desktop/download.c | 8 ++-- desktop/gui.h | 35 +++++++++------ desktop/gui_factory.c | 77 +++++++++++++++++++++++++++++--- framebuffer/gui.c | 24 ---------- gtk/download.c | 30 +++++-------- gtk/download.h | 2 + gtk/gui.c | 1 + monkey/browser.h | 1 + monkey/download.c | 17 +++++-- monkey/main.c | 1 + riscos/download.c | 17 +++++-- riscos/gui.c | 1 + riscos/gui.h | 1 + windows/download.c | 18 ++++++-- windows/download.h | 2 + windows/main.c | 3 ++ 28 files changed, 232 insertions(+), 96 deletions(-) diff --git a/amiga/download.c b/amiga/download.c index d33b723d1..60190ce17 100644 --- a/amiga/download.c +++ b/amiga/download.c @@ -85,7 +85,7 @@ enum { int downloads_in_progress = 0; -struct gui_download_window *gui_download_window_create(download_context *ctx, +static struct gui_download_window *gui_download_window_create(download_context *ctx, struct gui_window *gui) { const char *url = download_context_get_url(ctx); @@ -193,7 +193,7 @@ struct gui_download_window *gui_download_window_create(download_context *ctx, return dw; } -nserror gui_download_window_data(struct gui_download_window *dw, +static nserror gui_download_window_data(struct gui_download_window *dw, const char *data, unsigned int size) { APTR va[3]; @@ -227,7 +227,7 @@ nserror gui_download_window_data(struct gui_download_window *dw, return NSERROR_OK; } -void gui_download_window_error(struct gui_download_window *dw, +static void gui_download_window_error(struct gui_download_window *dw, const char *error_msg) { warn_user("Unwritten",""); @@ -242,7 +242,7 @@ void ami_download_window_abort(struct gui_download_window *dw) gui_download_window_done(dw); } -void gui_download_window_done(struct gui_download_window *dw) +static void gui_download_window_done(struct gui_download_window *dw) { struct dlnode *dln,*dln2 = NULL; struct browser_window *bw = dw->bw; @@ -432,3 +432,12 @@ BOOL ami_download_check_overwrite(const char *file, struct Window *win, ULONG si if(res == 1) return TRUE; else return FALSE; } + +static struct gui_download_table gui_download_table = { + .create = gui_download_window_create, + .data = gui_download_window_data, + .error = gui_download_window_error, + .done = gui_download_window_done, +}; + +struct gui_download_table *amiga_gui_download_table = &gui_download_table; diff --git a/amiga/download.h b/amiga/download.h index 2febbe908..d9e637ede 100755 --- a/amiga/download.h +++ b/amiga/download.h @@ -23,6 +23,8 @@ #include "amiga/gui.h" +extern struct gui_download_table *amiga_gui_download_table; + struct download_context; struct gui_download_window; diff --git a/amiga/gui.c b/amiga/gui.c index 13c32cd8b..708ca09fe 100644 --- a/amiga/gui.c +++ b/amiga/gui.c @@ -5185,6 +5185,8 @@ int main(int argc, char** argv) if (ami_locate_resource(messages, "Messages") == false) die("Cannot open Messages file"); + ami_gui_table.download = amiga_gui_download_table; + ret = netsurf_init(messages, &ami_gui_table); if (ret != NSERROR_OK) { die("NetSurf failed to initialise"); diff --git a/atari/download.c b/atari/download.c index e4a45e82e..4da9ef345 100755 --- a/atari/download.c +++ b/atari/download.c @@ -246,8 +246,8 @@ static char * select_filepath( const char * path, const char * filename ) return(ret); } -struct gui_download_window * gui_download_window_create(download_context *ctx, - struct gui_window *parent) +static struct gui_download_window * +gui_download_window_create(download_context *ctx, struct gui_window *parent) { const char *filename; char *destination; @@ -359,7 +359,7 @@ struct gui_download_window * gui_download_window_create(download_context *ctx, } -nserror gui_download_window_data(struct gui_download_window *dw, +static nserror gui_download_window_data(struct gui_download_window *dw, const char *data, unsigned int size) { @@ -415,7 +415,7 @@ nserror gui_download_window_data(struct gui_download_window *dw, return NSERROR_OK; } -void gui_download_window_error(struct gui_download_window *dw, +static void gui_download_window_error(struct gui_download_window *dw, const char *error_msg) { LOG(("%s", error_msg)); @@ -426,7 +426,7 @@ void gui_download_window_error(struct gui_download_window *dw, // TODO: change abort to close } -void gui_download_window_done(struct gui_download_window *dw) +static void gui_download_window_done(struct gui_download_window *dw) { OBJECT * tree; LOG(("")); @@ -454,3 +454,13 @@ void gui_download_window_done(struct gui_download_window *dw) } gui_window_set_status(input_window, messages_get("Done") ); } + +static struct gui_download_table gui_download_table = { + .create = gui_download_window_create, + .data = gui_download_window_data, + .error = gui_download_window_error, + .done = gui_download_window_done, +}; + +struct gui_download_table *atari_gui_download_table = &gui_download_table; + diff --git a/atari/download.h b/atari/download.h index e25893d4a..a5da60538 100755 --- a/atari/download.h +++ b/atari/download.h @@ -58,4 +58,6 @@ struct gui_download_window { bool close_on_finish; }; +struct gui_download_table *atari_gui_download_table; + #endif diff --git a/atari/gui.c b/atari/gui.c index c2109c985..3128de772 100644 --- a/atari/gui.c +++ b/atari/gui.c @@ -1116,6 +1116,9 @@ int main(int argc, char** argv) /* common initialisation */ LOG(("Initialising core...")); + + atari_gui_table.download = nsgtk_gui_download_table; + ret = netsurf_init(messages, atari_gui_table); if (ret != NSERROR_OK) { die("NetSurf failed to initialise"); diff --git a/beos/download.cpp b/beos/download.cpp index e20281c2f..b62ab2ffb 100644 --- a/beos/download.cpp +++ b/beos/download.cpp @@ -178,7 +178,7 @@ NSDownloadWindow::Failure(const char* error) } -struct gui_download_window *gui_download_window_create(download_context *ctx, +static struct gui_download_window *gui_download_window_create(download_context *ctx, struct gui_window *parent) { struct gui_download_window *download = (struct gui_download_window*)malloc(sizeof *download); @@ -209,7 +209,7 @@ struct gui_download_window *gui_download_window_create(download_context *ctx, } -nserror gui_download_window_data(struct gui_download_window *dw, +static nserror gui_download_window_data(struct gui_download_window *dw, const char *data, unsigned int size) { dw->window->Progress(size); @@ -222,7 +222,7 @@ nserror gui_download_window_data(struct gui_download_window *dw, } -void gui_download_window_error(struct gui_download_window *dw, +static void gui_download_window_error(struct gui_download_window *dw, const char *error_msg) { dw->window->Failure(error_msg); @@ -232,7 +232,7 @@ void gui_download_window_error(struct gui_download_window *dw, } -void gui_download_window_done(struct gui_download_window *dw) +static void gui_download_window_done(struct gui_download_window *dw) { dw->window->Success(); @@ -248,3 +248,12 @@ void gui_download_window_done(struct gui_download_window *dw) dw->storageLock->Unlock(); } +static struct gui_download_table gui_download_table = { + .create = gui_download_window_create, + .data = gui_download_window_data, + .error = gui_download_window_error, + .done = gui_download_window_done, +}; + +struct gui_download_table *beos_gui_download_table = &gui_download_table; + diff --git a/beos/download.h b/beos/download.h index 9c8d3adcd..962f3b7d9 100644 --- a/beos/download.h +++ b/beos/download.h @@ -16,3 +16,4 @@ * along with this program. If not, see . */ +struct gui_download_table *beos_gui_download_table; diff --git a/beos/gui.cpp b/beos/gui.cpp index efac0bb4c..45a0e6bc7 100644 --- a/beos/gui.cpp +++ b/beos/gui.cpp @@ -1111,6 +1111,7 @@ int main(int argc, char** argv) BPath messages = get_messages_path(); beos_gui_table.window = beos_gui_window_table; + beos_gui_table.download = beos_gui_download_table; ret = netsurf_init(messages.Path(), &beos_gui_table); if (ret != NSERROR_OK) { @@ -1152,6 +1153,10 @@ int gui_init_replicant(int argc, char** argv) /* common initialisation */ BPath messages = get_messages_path(); + + beos_gui_table.window = beos_gui_window_table; + beos_gui_table.download = beos_gui_download_table; + ret = netsurf_init(messages.Path(), &beos_gui_table); if (ret != NSERROR_OK) { // FIXME: must not die when in replicant! diff --git a/cocoa/DownloadWindowController.h b/cocoa/DownloadWindowController.h index b93c24c65..0d049da15 100644 --- a/cocoa/DownloadWindowController.h +++ b/cocoa/DownloadWindowController.h @@ -18,6 +18,7 @@ #import +struct gui_download_table *cocoa_gui_download_table; @interface DownloadWindowController : NSWindowController { struct download_context *context; @@ -50,3 +51,4 @@ - (void) abort; @end + diff --git a/cocoa/DownloadWindowController.m b/cocoa/DownloadWindowController.m index 82be52e51..634257008 100644 --- a/cocoa/DownloadWindowController.m +++ b/cocoa/DownloadWindowController.m @@ -327,7 +327,7 @@ static NSString *cocoa_time_string( unsigned seconds ) #pragma mark - #pragma mark NetSurf interface functions -struct gui_download_window *gui_download_window_create(download_context *ctx, +static struct gui_download_window *gui_download_window_create(download_context *ctx, struct gui_window *parent) { DownloadWindowController * const window = [[DownloadWindowController alloc] initWithContext: ctx]; @@ -338,21 +338,21 @@ struct gui_download_window *gui_download_window_create(download_context *ctx, return (struct gui_download_window *)window; } -nserror gui_download_window_data(struct gui_download_window *dw, +static nserror gui_download_window_data(struct gui_download_window *dw, const char *data, unsigned int size) { DownloadWindowController * const window = (DownloadWindowController *)dw; return [window receivedData: [NSData dataWithBytes: data length: size]] ? NSERROR_OK : NSERROR_SAVE_FAILED; } -void gui_download_window_error(struct gui_download_window *dw, +static void gui_download_window_error(struct gui_download_window *dw, const char *error_msg) { DownloadWindowController * const window = (DownloadWindowController *)dw; [window showError: [NSString stringWithUTF8String: error_msg]]; } -void gui_download_window_done(struct gui_download_window *dw) +static void gui_download_window_done(struct gui_download_window *dw) { DownloadWindowController * const window = (DownloadWindowController *)dw; [window downloadDone]; @@ -376,3 +376,12 @@ static void cocoa_unregister_download( DownloadWindowController *download ) [cocoa_all_downloads removeObject: download]; } + +static struct gui_download_table gui_download_table = { + .create = gui_download_window_create, + .data = gui_download_window_data, + .error = gui_download_window_error, + .done = gui_download_window_done, +}; + +struct gui_download_table *cocoa_gui_download_table = &gui_download_table; diff --git a/cocoa/NetsurfApp.m b/cocoa/NetsurfApp.m index 844904f1c..a64c99376 100644 --- a/cocoa/NetsurfApp.m +++ b/cocoa/NetsurfApp.m @@ -203,6 +203,8 @@ int main( int argc, char **argv ) nsoption_commandline(&argc, argv, NULL); /* common initialisation */ + cocoa_gui_table->download = cocoa_gui_download_table; + error = netsurf_init(messages, cocoa_gui_table); if (error != NSERROR_OK) { die("NetSurf failed to initialise"); diff --git a/desktop/download.c b/desktop/download.c index b775eb18e..98c6b6dd0 100644 --- a/desktop/download.c +++ b/desktop/download.c @@ -160,7 +160,7 @@ static nserror download_context_process_headers(download_context *ctx) } /* Create the frontend window */ - ctx->window = gui_download_window_create(ctx, ctx->parent); + ctx->window = guit->download->create(ctx, ctx->parent); if (ctx->window == NULL) { free(ctx->filename); ctx->filename = NULL; @@ -210,7 +210,7 @@ static nserror download_callback(llcache_handle *handle, if (error == NSERROR_OK) { /** \todo Lose ugly cast */ - error = gui_download_window_data(ctx->window, + error = guit->download->data(ctx->window, (char *) event->data.data.buf, event->data.data.len); if (error != NSERROR_OK) @@ -222,7 +222,7 @@ static nserror download_callback(llcache_handle *handle, case LLCACHE_EVENT_DONE: /* There may be no associated window if there was no data or headers */ if (ctx->window != NULL) - gui_download_window_done(ctx->window); + guit->download->done(ctx->window); else download_context_destroy(ctx); @@ -230,7 +230,7 @@ static nserror download_callback(llcache_handle *handle, case LLCACHE_EVENT_ERROR: if (ctx->window != NULL) - gui_download_window_error(ctx->window, event->data.msg); + guit->download->error(ctx->window, event->data.msg); else download_context_destroy(ctx); diff --git a/desktop/gui.h b/desktop/gui.h index 8d65893d0..50e8c67d9 100644 --- a/desktop/gui.h +++ b/desktop/gui.h @@ -244,16 +244,34 @@ struct gui_window_table { void (*start_selection)(struct gui_window *g); }; +/** + * function table for download windows + */ +struct gui_download_table { + struct gui_download_window *(*create)(download_context *ctx, struct gui_window *parent); + + nserror (*data)(struct gui_download_window *dw, const char *data, unsigned int size); + + void (*error)(struct gui_download_window *dw, const char *error_msg); + + void (*done)(struct gui_download_window *dw); +}; + /** Graphical user interface function table * * function table implementing GUI interface to browser core */ struct gui_table { - /* Mandantory entries */ - /* sub tables */ - struct gui_window_table *window; /* window sub table */ + + /** Window sub table */ + struct gui_window_table *window; + + /** Downlaod sub table */ + struct gui_download_table *download; + + /* Mandantory entries */ /** called to let the frontend update its state and run any * I/O operations. @@ -280,17 +298,6 @@ extern struct gui_table *guit; /* the gui vtable */ - -struct gui_download_window *gui_download_window_create(download_context *ctx, - struct gui_window *parent); -nserror gui_download_window_data(struct gui_download_window *dw, - const char *data, unsigned int size); -void gui_download_window_error(struct gui_download_window *dw, - const char *error_msg); -void gui_download_window_done(struct gui_download_window *dw); - - - /** * Callback to translate resource to full url. * diff --git a/desktop/gui_factory.c b/desktop/gui_factory.c index 8ebf3515a..7f76eaccb 100644 --- a/desktop/gui_factory.c +++ b/desktop/gui_factory.c @@ -5,13 +5,6 @@ struct gui_table *guit = NULL; -static void gui_default_quit(void) -{ -} - -static void gui_default_set_search_ico(hlcache_handle *ico) -{ -} static void gui_default_window_set_title(struct gui_window *g, const char *title) @@ -201,6 +194,68 @@ static nserror verify_window_register(struct gui_window_table *gwt) return NSERROR_OK; } + +static struct gui_download_window * +gui_default_download_create(download_context *ctx, struct gui_window *parent) +{ + return NULL; +} + +static nserror gui_default_download_data(struct gui_download_window *dw, + const char *data, unsigned int size) +{ + return NSERROR_OK; +} + +static void gui_default_download_error(struct gui_download_window *dw, + const char *error_msg) +{ +} + +static void gui_default_download_done(struct gui_download_window *dw) +{ +} + +static struct gui_download_table default_download_table = { + .create = gui_default_download_create, + .data = gui_default_download_data, + .error = gui_default_download_error, + .done = gui_default_download_done, +}; + +/** verify download window table is valid */ +static nserror verify_download_register(struct gui_download_table *gdt) +{ + /* check table is present */ + if (gdt == NULL) { + return NSERROR_BAD_PARAMETER; + } + + /* all enties are mandantory */ + if (gdt->create == NULL) { + return NSERROR_BAD_PARAMETER; + } + if (gdt->data == NULL) { + return NSERROR_BAD_PARAMETER; + } + if (gdt->error == NULL) { + return NSERROR_BAD_PARAMETER; + } + if (gdt->done == NULL) { + return NSERROR_BAD_PARAMETER; + } + + return NSERROR_OK; +} + +static void gui_default_quit(void) +{ +} + +static void gui_default_set_search_ico(hlcache_handle *ico) +{ +} + nserror gui_factory_register(struct gui_table *gt) { nserror err; @@ -220,6 +275,14 @@ nserror gui_factory_register(struct gui_table *gt) if (err != NSERROR_OK) { return err; } + if (gt->download == NULL) { + /* set default download table */ + gt->download = &default_download_table; + } + err = verify_download_register(gt->download); + if (err != NSERROR_OK) { + return err; + } /* check the mandantory fields are set */ if (gt->poll == NULL) { diff --git a/framebuffer/gui.c b/framebuffer/gui.c index eff0a98e1..c71872067 100644 --- a/framebuffer/gui.c +++ b/framebuffer/gui.c @@ -1766,30 +1766,6 @@ gui_window_remove_caret(struct gui_window *g) } } -struct gui_download_window * -gui_download_window_create(download_context *ctx, struct gui_window *parent) -{ - return NULL; -} - -nserror -gui_download_window_data(struct gui_download_window *dw, - const char *data, - unsigned int size) -{ - return NSERROR_OK; -} - -void -gui_download_window_error(struct gui_download_window *dw, - const char *error_msg) -{ -} - -void -gui_download_window_done(struct gui_download_window *dw) -{ -} void gui_create_form_select_menu(struct browser_window *bw, diff --git a/gtk/download.c b/gtk/download.c index e882ec798..1eb53403e 100644 --- a/gtk/download.c +++ b/gtk/download.c @@ -712,8 +712,8 @@ static void nsgtk_download_store_create_item (struct gui_download_window *dl) NSGTK_DOWNLOAD, dl, -1); } -struct gui_download_window *gui_download_window_create(download_context *ctx, - struct gui_window *gui) +static struct gui_download_window * +gui_download_window_create(download_context *ctx, struct gui_window *gui) { const char *url = download_context_get_url(ctx); unsigned long total_size = download_context_get_total_length(ctx); @@ -797,7 +797,7 @@ struct gui_download_window *gui_download_window_create(download_context *ctx, } -nserror gui_download_window_data(struct gui_download_window *dw, +static nserror gui_download_window_data(struct gui_download_window *dw, const char *data, unsigned int size) { g_io_channel_write_chars(dw->write, data, size, NULL, &dw->error); @@ -820,13 +820,13 @@ nserror gui_download_window_data(struct gui_download_window *dw, } -void gui_download_window_error(struct gui_download_window *dw, +static void gui_download_window_error(struct gui_download_window *dw, const char *error_msg) { } -void gui_download_window_done(struct gui_download_window *dw) +static void gui_download_window_done(struct gui_download_window *dw) { g_io_channel_shutdown(dw->write, TRUE, &dw->error); g_io_channel_unref(dw->write); @@ -845,17 +845,11 @@ void gui_download_window_done(struct gui_download_window *dw) } +static struct gui_download_table gui_download_table = { + .create = gui_download_window_create, + .data = gui_download_window_data, + .error = gui_download_window_error, + .done = gui_download_window_done, +}; - - - - - - - - - - - - - +struct gui_download_table *nsgtk_gui_download_table = &gui_download_table; diff --git a/gtk/download.h b/gtk/download.h index e85c4126a..393009dc4 100644 --- a/gtk/download.h +++ b/gtk/download.h @@ -27,4 +27,6 @@ bool nsgtk_check_for_downloads(GtkWindow *parent); void nsgtk_download_show(GtkWindow *parent); void nsgtk_download_add(gchar *url, gchar *destination); +struct gui_download_table *nsgtk_gui_download_table; + #endif diff --git a/gtk/gui.c b/gtk/gui.c index 0a89f0ee3..0501ec3f6 100644 --- a/gtk/gui.c +++ b/gtk/gui.c @@ -1172,6 +1172,7 @@ int main(int argc, char** argv) messages = filepath_find(respaths, "Messages"); nsgtk_gui_table.window = nsgtk_gui_window_table; + nsgtk_gui_table.download = nsgtk_gui_download_table; ret = netsurf_init(messages, &nsgtk_gui_table); free(messages); diff --git a/monkey/browser.h b/monkey/browser.h index 892c615ab..6c74a412c 100644 --- a/monkey/browser.h +++ b/monkey/browser.h @@ -37,6 +37,7 @@ struct gui_window { }; extern struct gui_window_table *monkey_gui_window_table; +extern struct gui_download_table *monkey_gui_download_table; struct gui_window *monkey_find_window_by_num(uint32_t win_num); struct gui_window *monkey_find_window_by_content(hlcache_handle *content); diff --git a/monkey/download.c b/monkey/download.c index d706dd6e0..46d54dc0c 100644 --- a/monkey/download.c +++ b/monkey/download.c @@ -34,7 +34,7 @@ struct gui_download_window { static struct gui_download_window *dw_ring = NULL; -struct gui_download_window * +static struct gui_download_window * gui_download_window_create(download_context *ctx, struct gui_window *parent) { @@ -52,7 +52,7 @@ gui_download_window_create(download_context *ctx, return ret; } -nserror +static nserror gui_download_window_data(struct gui_download_window *dw, const char *data, unsigned int size) { @@ -61,7 +61,7 @@ gui_download_window_data(struct gui_download_window *dw, return NSERROR_OK; } -void +static void gui_download_window_error(struct gui_download_window *dw, const char *error_msg) { @@ -69,7 +69,7 @@ gui_download_window_error(struct gui_download_window *dw, dw->dwin_num, error_msg); } -void +static void gui_download_window_done(struct gui_download_window *dw) { fprintf(stdout, "DOWNLOAD_WINDOW DONE DWIN %u\n", @@ -77,3 +77,12 @@ gui_download_window_done(struct gui_download_window *dw) RING_REMOVE(dw_ring, dw); free(dw); } + +static struct gui_download_table gui_download_table = { + .create = gui_download_window_create, + .data = gui_download_window_data, + .error = gui_download_window_error, + .done = gui_download_window_done, +}; + +struct gui_download_table *monkey_gui_download_table = &gui_download_table; diff --git a/monkey/main.c b/monkey/main.c index c6aa60f10..ce7906e03 100644 --- a/monkey/main.c +++ b/monkey/main.c @@ -153,6 +153,7 @@ main(int argc, char **argv) messages = filepath_find(respaths, "Messages"); monkey_gui_table.window = monkey_gui_window_table; + monkey_gui_table.download = monkey_gui_download_table; ret = netsurf_init(messages, &monkey_gui_table); free(messages); diff --git a/riscos/download.c b/riscos/download.c index ebd981dca..aeeeeffbd 100644 --- a/riscos/download.c +++ b/riscos/download.c @@ -215,7 +215,7 @@ const char *ro_gui_download_temp_name(struct gui_download_window *dw) * reported */ -struct gui_download_window *gui_download_window_create(download_context *ctx, +static struct gui_download_window *gui_download_window_create(download_context *ctx, struct gui_window *gui) { const char *url = download_context_get_url(ctx); @@ -445,7 +445,7 @@ struct gui_download_window *gui_download_window_create(download_context *ctx, * \return NSERROR_OK on success, appropriate error otherwise */ -nserror gui_download_window_data(struct gui_download_window *dw, +static nserror gui_download_window_data(struct gui_download_window *dw, const char *data, unsigned int size) { while (true) { @@ -714,7 +714,7 @@ void ro_gui_download_window_hide_caret(struct gui_download_window *dw) * \param error_msg error message */ -void gui_download_window_error(struct gui_download_window *dw, +static void gui_download_window_error(struct gui_download_window *dw, const char *error_msg) { os_error *error; @@ -766,7 +766,7 @@ void gui_download_window_error(struct gui_download_window *dw, * \param dw download window */ -void gui_download_window_done(struct gui_download_window *dw) +static void gui_download_window_done(struct gui_download_window *dw) { os_error *error; @@ -1631,3 +1631,12 @@ bool ro_gui_download_prequit(void) } return true; } + +static struct gui_download_table gui_download_table = { + .create = gui_download_window_create, + .data = gui_download_window_data, + .error = gui_download_window_error, + .done = gui_download_window_done, +}; + +struct gui_download_table *riscos_gui_download_table = &gui_download_table; diff --git a/riscos/gui.c b/riscos/gui.c index f7caf02da..60b14833c 100644 --- a/riscos/gui.c +++ b/riscos/gui.c @@ -898,6 +898,7 @@ int main(int argc, char** argv) /* common initialisation */ riscos_gui_table.window = riscos_gui_window_table; + riscos_gui_table.download = riscos_gui_download_table; ret = netsurf_init(path, &riscos_gui_table); if (ret != NSERROR_OK) { diff --git a/riscos/gui.h b/riscos/gui.h index 1abb40fba..38f3fc60c 100644 --- a/riscos/gui.h +++ b/riscos/gui.h @@ -123,6 +123,7 @@ const char *ro_gui_default_language(void); void ro_gui_download_init(void); void ro_gui_download_datasave_ack(wimp_message *message); bool ro_gui_download_prequit(void); +extern struct gui_download_table *riscos_gui_download_table; /* in 401login.c */ void ro_gui_401login_init(void); diff --git a/windows/download.c b/windows/download.c index 635e3b604..5bf9798aa 100644 --- a/windows/download.c +++ b/windows/download.c @@ -45,7 +45,7 @@ static void nsws_download_update_label(void *p); static void nsws_download_update_progress(void *p); static void nsws_download_clear_data(struct gui_download_window *w); -struct gui_download_window * +static struct gui_download_window * gui_download_window_create(download_context *ctx, struct gui_window *gui) { if (downloading) { @@ -259,7 +259,8 @@ void nsws_download_clear_data(struct gui_download_window *w) } -nserror gui_download_window_data(struct gui_download_window *w, const char *data, +static nserror +gui_download_window_data(struct gui_download_window *w, const char *data, unsigned int size) { if ((w == NULL) || (w->file == NULL)) @@ -279,13 +280,13 @@ nserror gui_download_window_data(struct gui_download_window *w, const char *data return NSERROR_OK; } -void gui_download_window_error(struct gui_download_window *w, +static void gui_download_window_error(struct gui_download_window *w, const char *error_msg) { LOG(("error %s", error_msg)); } -void gui_download_window_done(struct gui_download_window *w) +static void gui_download_window_done(struct gui_download_window *w) { if (w == NULL) return; @@ -295,3 +296,12 @@ void gui_download_window_done(struct gui_download_window *w) nsws_download_clear_data(w); } +static struct gui_download_table gui_download_table = { + .create = gui_download_window_create, + .data = gui_download_window_data, + .error = gui_download_window_error, + .done = gui_download_window_done, +}; + +struct gui_download_table *win32_gui_download_table = &gui_download_table; + diff --git a/windows/download.h b/windows/download.h index 777777da5..c1b13bf65 100644 --- a/windows/download.h +++ b/windows/download.h @@ -60,4 +60,6 @@ struct gui_download_window { void nsws_download_window_init(struct gui_window *); +struct gui_download_table *win32_gui_download_table; + #endif diff --git a/windows/main.c b/windows/main.c index 5f20a70d1..eb63357af 100644 --- a/windows/main.c +++ b/windows/main.c @@ -154,6 +154,9 @@ WinMain(HINSTANCE hInstance, HINSTANCE hLastInstance, LPSTR lpcli, int ncmd) /* common initialisation */ messages = filepath_find(respaths, "messages"); + + win32_gui_table->download = nsgtk_gui_download_table; + ret = netsurf_init(messages, win32_gui_table); free(messages); if (ret != NSERROR_OK) { From 667d4a0a4938e1bfe54eb5b56cd4313b6579534d Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Tue, 14 Jan 2014 20:05:14 +0000 Subject: [PATCH 086/773] confine the gui table acessor to the gui factory header --- desktop/browser.c | 1 + desktop/download.c | 1 + desktop/gui.h | 14 +++++++------- desktop/gui_factory.h | 2 ++ desktop/searchweb.c | 1 + desktop/selection.c | 1 + desktop/textinput.c | 1 + 7 files changed, 14 insertions(+), 7 deletions(-) diff --git a/desktop/browser.c b/desktop/browser.c index 30aeead0c..3ae613d08 100644 --- a/desktop/browser.c +++ b/desktop/browser.c @@ -47,6 +47,7 @@ #include "desktop/frames.h" #include "desktop/global_history.h" #include "desktop/gui.h" +#include "desktop/gui_factory.h" #include "desktop/hotlist.h" #include "desktop/knockout.h" #include "desktop/local_history.h" diff --git a/desktop/download.c b/desktop/download.c index 98c6b6dd0..14390c78a 100644 --- a/desktop/download.c +++ b/desktop/download.c @@ -27,6 +27,7 @@ #include "content/llcache.h" #include "desktop/download.h" #include "desktop/gui.h" +#include "desktop/gui_factory.h" #include "utils/http.h" #include "utils/url.h" #include "utils/utils.h" diff --git a/desktop/gui.h b/desktop/gui.h index 50e8c67d9..2780325f5 100644 --- a/desktop/gui.h +++ b/desktop/gui.h @@ -64,6 +64,13 @@ struct gui_window; struct gui_download_window; struct browser_window; struct form_control; +struct ssl_cert_info; + +typedef struct nsnsclipboard_styles { + size_t start; /**< Start of run */ + + plot_font_style_t style; /**< Style to give text run */ +} nsclipboard_styles; /** Graphical user interface window function table * @@ -294,7 +301,6 @@ struct gui_table { void (*set_search_ico)(hlcache_handle *ico); }; -extern struct gui_table *guit; /* the gui vtable */ @@ -325,11 +331,6 @@ void gui_create_form_select_menu(struct browser_window *bw, */ void gui_get_clipboard(char **buffer, size_t *length); -typedef struct nsnsclipboard_styles { - size_t start; /**< Start of run */ - - plot_font_style_t style; /**< Style to give text run */ -} nsclipboard_styles; /** * Core tells front end to put given text in clipboard @@ -344,7 +345,6 @@ void gui_set_clipboard(const char *buffer, size_t length, -struct ssl_cert_info; void gui_cert_verify(nsurl *url, const struct ssl_cert_info *certs, unsigned long num, nserror (*cb)(bool proceed, void *pw), diff --git a/desktop/gui_factory.h b/desktop/gui_factory.h index 66303eac1..c70ca8f37 100644 --- a/desktop/gui_factory.h +++ b/desktop/gui_factory.h @@ -25,6 +25,8 @@ struct gui_table; +extern struct gui_table *guit; /* the gui vtable */ + nserror gui_factory_register(struct gui_table *gt); #endif diff --git a/desktop/searchweb.c b/desktop/searchweb.c index 321edd0b6..63e17ee90 100644 --- a/desktop/searchweb.c +++ b/desktop/searchweb.c @@ -27,6 +27,7 @@ #include "content/hlcache.h" #include "desktop/browser.h" #include "desktop/gui.h" +#include "desktop/gui_factory.h" #include "utils/nsoption.h" #include "desktop/searchweb.h" #include "utils/config.h" diff --git a/desktop/selection.c b/desktop/selection.c index ca383c179..fc91f1dbb 100644 --- a/desktop/selection.c +++ b/desktop/selection.c @@ -30,6 +30,7 @@ #include "desktop/browser_private.h" #include "desktop/gui.h" +#include "desktop/gui_factory.h" #include "desktop/mouse.h" #include "desktop/plotters.h" #include "desktop/save_text.h" diff --git a/desktop/textinput.c b/desktop/textinput.c index 95c321eaa..c61b838fe 100644 --- a/desktop/textinput.c +++ b/desktop/textinput.c @@ -31,6 +31,7 @@ #include "desktop/browser_private.h" #include "desktop/gui.h" +#include "desktop/gui_factory.h" #include "desktop/mouse.h" #include "desktop/scrollbar.h" #include "desktop/selection.h" From 0075eab1949e4de071b3649c68ba402b8ffce6fb Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Tue, 14 Jan 2014 23:31:54 +0000 Subject: [PATCH 087/773] move remaining gui operations to table --- amiga/clipboard.h | 3 + amiga/context_menu.h | 3 + amiga/gui.c | 8 +- amiga/launch.h | 3 + amiga/sslcert.h | 4 + atari/gui.c | 28 ++---- content/fetchers/resource.c | 3 +- desktop/browser.c | 4 +- desktop/gui.h | 95 ++++++++++--------- desktop/gui_factory.c | 52 +++++++++++ desktop/netsurf.c | 2 +- desktop/textarea.c | 4 +- framebuffer/clipboard.c | 3 +- framebuffer/clipboard.h | 26 ++++++ framebuffer/findfile.h | 2 + framebuffer/gui.c | 25 +---- render/html_interaction.c | 3 +- riscos/gui.c | 180 +++++++++++++++++++----------------- riscos/gui.h | 10 ++ windows/gui.c | 19 +--- windows/main.c | 7 +- 21 files changed, 280 insertions(+), 204 deletions(-) create mode 100644 framebuffer/clipboard.h diff --git a/amiga/clipboard.h b/amiga/clipboard.h index 88de64340..57004547d 100755 --- a/amiga/clipboard.h +++ b/amiga/clipboard.h @@ -27,6 +27,9 @@ struct gui_window; struct gui_window_2; void gui_start_selection(struct gui_window *g); +void gui_get_clipboard(char **buffer, size_t *length); +void gui_set_clipboard(const char *buffer, size_t length, nsclipboard_styles styles[], int n_styles); + void ami_clipboard_init(void); void ami_clipboard_free(void); diff --git a/amiga/context_menu.h b/amiga/context_menu.h index 60224f4e6..69ccdff68 100755 --- a/amiga/context_menu.h +++ b/amiga/context_menu.h @@ -27,4 +27,7 @@ void ami_context_menu_free(void); BOOL ami_context_menu_mouse_trap(struct gui_window_2 *gwin, BOOL trap); void ami_context_menu_show(struct gui_window_2 *gwin, int x, int y); void ami_context_menu_show_tree(struct tree *tree, struct Window *win, int type); + +void gui_create_form_select_menu(struct browser_window *bw, struct form_control *control); + #endif diff --git a/amiga/gui.c b/amiga/gui.c index 708ca09fe..9e433101e 100644 --- a/amiga/gui.c +++ b/amiga/gui.c @@ -624,7 +624,7 @@ void ami_amiupdate(void) } } -nsurl *gui_get_resource_url(const char *path) +static nsurl *gui_get_resource_url(const char *path) { char buf[1024]; char path2[1024]; @@ -5122,6 +5122,12 @@ static struct gui_table ami_gui_table = { .poll = gui_poll, .quit = gui_quit, .set_search_ico = gui_set_search_ico, + .get_resource_url = gui_get_resource_url, + .launch_url = gui_launch_url, + .create_form_select_menu = gui_create_form_select_menu, + .get_clipboard = gui_get_clipboard, + .set_clipboard = gui_set_clipboard, + .cert_verify = gui_cert_verify, .window = &ami_window_table, }; diff --git a/amiga/launch.h b/amiga/launch.h index 40f7dae30..7baa6ca27 100755 --- a/amiga/launch.h +++ b/amiga/launch.h @@ -25,4 +25,7 @@ void ami_openurl_open(void); void ami_openurl_close(void); + +void gui_launch_url(const char *url); + #endif diff --git a/amiga/sslcert.h b/amiga/sslcert.h index e308f6231..b55cac8b6 100644 --- a/amiga/sslcert.h +++ b/amiga/sslcert.h @@ -19,5 +19,9 @@ #ifndef AMIGA_SSLCERT_H #define AMIGA_SSLCERT_H +void gui_cert_verify(nsurl *url, + const struct ssl_cert_info *certs, unsigned long num, + nserror (*cb)(bool proceed, void *pw), void *cbpw); + void ami_ssl_free(struct treeview_window *twin); #endif diff --git a/atari/gui.c b/atari/gui.c index 3128de772..924ac686a 100644 --- a/atari/gui.c +++ b/atari/gui.c @@ -659,7 +659,7 @@ static void gui_window_new_content(struct gui_window *w) * \param buffer UTF-8 text, allocated by front end, ownership yeilded to core * \param length Byte length of UTF-8 text in buffer */ -void gui_get_clipboard(char **buffer, size_t *length) +static void gui_get_clipboard(char **buffer, size_t *length) { char *clip; size_t clip_len; @@ -701,7 +701,7 @@ void gui_get_clipboard(char **buffer, size_t *length) * \param styles Array of styles given to text runs, owned by core, or NULL * \param n_styles Number of text run styles in array */ -void gui_set_clipboard(const char *buffer, size_t length, +static void gui_set_clipboard(const char *buffer, size_t length, nsclipboard_styles styles[], int n_styles) { if (length > 0 && buffer != NULL) { @@ -721,22 +721,6 @@ void gui_set_clipboard(const char *buffer, size_t length, } } - -void gui_create_form_select_menu(struct browser_window *bw, - struct form_control *control) -{ - TODO(); -} - -/** - * Broadcast an URL that we can't handle. - */ -void gui_launch_url(const char *url) -{ - TODO(); - LOG(("launch file: %s\n", url)); -} - void gui_401login_open(nsurl *url, const char *realm, nserror (*cb)(bool proceed, void *pw), void *cbpw) { @@ -756,7 +740,7 @@ void gui_401login_open(nsurl *url, const char *realm, } -void gui_cert_verify(nsurl *url, const struct ssl_cert_info *certs, +static void gui_cert_verify(nsurl *url, const struct ssl_cert_info *certs, unsigned long num, nserror (*cb)(bool proceed, void *pw), void *cbpw) { @@ -913,7 +897,7 @@ static inline void create_cursor(int flags, short mode, void * form, } } -nsurl *gui_get_resource_url(const char *path) +static nsurl *gui_get_resource_url(const char *path) { char buf[PATH_MAX]; char *raw; @@ -1064,6 +1048,10 @@ static struct gui_window_table atari_window_table = { static struct gui_table atari_gui_table = { .poll = gui_poll, .quit = gui_quit, + .get_resource_url = gui_get_resource_url, + .get_clipboard = gui_get_clipboard, + .set_clipboard = gui_set_clipboard, + .cert_verify = gui_cert_verify, .window = &atari_window_table; }; diff --git a/content/fetchers/resource.c b/content/fetchers/resource.c index 0119c6b3b..5dca8b378 100644 --- a/content/fetchers/resource.c +++ b/content/fetchers/resource.c @@ -42,6 +42,7 @@ #include "content/fetchers/resource.h" #include "content/urldb.h" #include "desktop/gui.h" +#include "desktop/gui_factory.h" #include "utils/nsoption.h" #include "utils/log.h" #include "utils/messages.h" @@ -206,7 +207,7 @@ static bool fetch_resource_initialise(lwc_string *scheme) } } - e->url = gui_get_resource_url(fetch_resource_paths[i]); + e->url = guit->get_resource_url(fetch_resource_paths[i]); if (e->url == NULL) { lwc_string_unref(e->path); } else { diff --git a/desktop/browser.c b/desktop/browser.c index 3ae613d08..55cb779bf 100644 --- a/desktop/browser.c +++ b/desktop/browser.c @@ -814,7 +814,7 @@ browser_window_download(struct browser_window *bw, NULL, NULL, &l); if (error == NSERROR_NO_FETCH_HANDLER) { /* no internal handler for this type, call out to frontend */ - gui_launch_url(nsurl_access(url)); + guit->launch_url(nsurl_access(url)); } else if (error != NSERROR_OK) { LOG(("Failed to fetch download: %d", error)); } else { @@ -1873,7 +1873,7 @@ nserror browser_window_navigate(struct browser_window *bw, case NSERROR_NO_FETCH_HANDLER: /* no handler for this type */ /** @todo does this always try and download even unverifiable content? */ - gui_launch_url(nsurl_access(url)); + guit->launch_url(nsurl_access(url)); break; default: /* report error to user */ diff --git a/desktop/gui.h b/desktop/gui.h index 2780325f5..12cf91a50 100644 --- a/desktop/gui.h +++ b/desktop/gui.h @@ -280,7 +280,8 @@ struct gui_table { /* Mandantory entries */ - /** called to let the frontend update its state and run any + /** + * called to let the frontend update its state and run any * I/O operations. */ void (*poll)(bool active); @@ -299,56 +300,58 @@ struct gui_table { * cache from search_web_ico() */ void (*set_search_ico)(hlcache_handle *ico); + + /** + * Callback to translate resource to full url. + * + * Transforms a resource: path into a full URL. The returned URL + * is used as the target for a redirect. The caller takes ownership of + * the returned nsurl including unrefing it when finished with it. + * + * \param path The path of the resource to locate. + * \return A string containing the full URL of the target object or + * NULL if no suitable resource can be found. + */ + nsurl* (*get_resource_url)(const char *path); + + /** + * core has no fetcher for url + */ + void (*launch_url)(const char *url); + + /** + * create a form select menu + */ + void (*create_form_select_menu)(struct browser_window *bw, struct form_control *control); + + /** + * Core asks front end for clipboard contents. + * + * \param buffer UTF-8 text, allocated by front end, ownership yeilded to core + * \param length Byte length of UTF-8 text in buffer + */ + void (*get_clipboard)(char **buffer, size_t *length); + + /** + * Core tells front end to put given text in clipboard + * + * \param buffer UTF-8 text, owned by core + * \param length Byte length of UTF-8 text in buffer + * \param styles Array of styles given to text runs, owned by core, or NULL + * \param n_styles Number of text run styles in array + */ + void (*set_clipboard)(const char *buffer, size_t length, nsclipboard_styles styles[], int n_styles); + + /** + * verify certificate + */ + void (*cert_verify)(nsurl *url, const struct ssl_cert_info *certs, unsigned long num, nserror (*cb)(bool proceed, void *pw), void *cbpw); + }; -/** - * Callback to translate resource to full url. - * - * Transforms a resource: path into a full URL. The returned URL - * is used as the target for a redirect. The caller takes ownership of - * the returned nsurl including unrefing it when finished with it. - * - * \param path The path of the resource to locate. - * \return A string containing the full URL of the target object or - * NULL if no suitable resource can be found. - */ -nsurl* gui_get_resource_url(const char *path); - - -void gui_launch_url(const char *url); - -void gui_create_form_select_menu(struct browser_window *bw, - struct form_control *control); - -/** - * Core asks front end for clipboard contents. - * - * \param buffer UTF-8 text, allocated by front end, ownership yeilded to core - * \param length Byte length of UTF-8 text in buffer - */ -void gui_get_clipboard(char **buffer, size_t *length); - - -/** - * Core tells front end to put given text in clipboard - * - * \param buffer UTF-8 text, owned by core - * \param length Byte length of UTF-8 text in buffer - * \param styles Array of styles given to text runs, owned by core, or NULL - * \param n_styles Number of text run styles in array - */ -void gui_set_clipboard(const char *buffer, size_t length, - nsclipboard_styles styles[], int n_styles); - - - - -void gui_cert_verify(nsurl *url, const struct ssl_cert_info *certs, - unsigned long num, nserror (*cb)(bool proceed, void *pw), - void *cbpw); #endif diff --git a/desktop/gui_factory.c b/desktop/gui_factory.c index 7f76eaccb..cb01fc45e 100644 --- a/desktop/gui_factory.c +++ b/desktop/gui_factory.c @@ -256,6 +256,40 @@ static void gui_default_set_search_ico(hlcache_handle *ico) { } +static nsurl *gui_default_get_resource_url(const char *path) +{ + return NULL; +} + +static void gui_default_launch_url(const char *url) +{ +} + +static void gui_default_create_form_select_menu(struct browser_window *bw, + struct form_control *control) +{ +} + +static void gui_default_get_clipboard(char **buffer, size_t *length) +{ + *buffer = NULL; + *length = 0; +} + +static void gui_default_set_clipboard(const char *buffer, size_t length, + nsclipboard_styles styles[], int n_styles) +{ +} + +static void gui_default_cert_verify(nsurl *url, + const struct ssl_cert_info *certs, + unsigned long num, + nserror (*cb)(bool proceed, void *pw), + void *cbpw) +{ + cb(false, cbpw); +} + nserror gui_factory_register(struct gui_table *gt) { nserror err; @@ -296,6 +330,24 @@ nserror gui_factory_register(struct gui_table *gt) if (gt->set_search_ico == NULL) { gt->set_search_ico = gui_default_set_search_ico; } + if (gt->get_resource_url == NULL) { + gt->get_resource_url = gui_default_get_resource_url; + } + if (gt->launch_url == NULL) { + gt->launch_url = gui_default_launch_url; + } + if (gt->create_form_select_menu == NULL) { + gt->create_form_select_menu = gui_default_create_form_select_menu; + } + if (gt->get_clipboard == NULL) { + gt->get_clipboard = gui_default_get_clipboard; + } + if (gt->set_clipboard == NULL) { + gt->set_clipboard = gui_default_set_clipboard; + } + if (gt->cert_verify == NULL) { + gt->cert_verify = gui_default_cert_verify; + } guit = gt; diff --git a/desktop/netsurf.c b/desktop/netsurf.c index 10dc7ba68..1c36a3fe7 100644 --- a/desktop/netsurf.c +++ b/desktop/netsurf.c @@ -103,7 +103,7 @@ static nserror netsurf_llcache_query_handler(const llcache_query *query, /* For now, do nothing, as this query type isn't emitted yet */ break; case LLCACHE_QUERY_SSL: - gui_cert_verify(query->url, query->data.ssl.certs, + guit->cert_verify(query->url, query->data.ssl.certs, query->data.ssl.num, cb, cbpw); break; } diff --git a/desktop/textarea.c b/desktop/textarea.c index f9712ac84..423767274 100644 --- a/desktop/textarea.c +++ b/desktop/textarea.c @@ -1417,7 +1417,7 @@ static bool textarea_replace_text_internal(struct textarea *ta, size_t b_start, /* Place CUTs on clipboard */ if (add_to_clipboard) { - gui_set_clipboard(ta->show->data + b_start, b_end - b_start, + guit->set_clipboard(ta->show->data + b_start, b_end - b_start, NULL, 0); } @@ -2484,7 +2484,7 @@ bool textarea_keypress(struct textarea *ta, uint32_t key) if (readonly) break; - gui_get_clipboard(&clipboard, &clipboard_length); + guit->get_clipboard(&clipboard, &clipboard_length); if (clipboard == NULL) return false; diff --git a/framebuffer/clipboard.c b/framebuffer/clipboard.c index 46a1bb018..4f9831340 100644 --- a/framebuffer/clipboard.c +++ b/framebuffer/clipboard.c @@ -26,6 +26,7 @@ #include "desktop/browser.h" #include "desktop/gui.h" #include "framebuffer/gui.h" +#include "framebuffer/clipboard.h" #include "utils/log.h" @@ -36,8 +37,6 @@ static struct gui_clipboard { } gui_clipboard; - - /** * Core asks front end for clipboard contents. * diff --git a/framebuffer/clipboard.h b/framebuffer/clipboard.h new file mode 100644 index 000000000..bc71a5565 --- /dev/null +++ b/framebuffer/clipboard.h @@ -0,0 +1,26 @@ +/* + * Copyright 2008 Vincent Sanders + * + * This file is part of NetSurf, http://www.netsurf-browser.org/ + * + * NetSurf is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * NetSurf is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef NETSURF_FB_CLIPBOARD_H +#define NETSURF_FB_CLIPBOARD_H + +void gui_get_clipboard(char **buffer, size_t *length); +void gui_set_clipboard(const char *buffer, size_t length, + nsclipboard_styles styles[], int n_styles); + +#endif diff --git a/framebuffer/findfile.h b/framebuffer/findfile.h index 1f3db6eb1..130bd3eb4 100644 --- a/framebuffer/findfile.h +++ b/framebuffer/findfile.h @@ -29,4 +29,6 @@ extern char **respaths; */ char **fb_init_resource(const char *resource_path); +nsurl *gui_get_resource_url(const char *path); + #endif /* NETSURF_FB_FINDFILE_H */ diff --git a/framebuffer/gui.c b/framebuffer/gui.c index c71872067..8b90b52f7 100644 --- a/framebuffer/gui.c +++ b/framebuffer/gui.c @@ -54,6 +54,7 @@ #include "framebuffer/findfile.h" #include "framebuffer/image_data.h" #include "framebuffer/font.h" +#include "framebuffer/clipboard.h" #include "content/urldb.h" #include "desktop/local_history.h" @@ -1767,27 +1768,6 @@ gui_window_remove_caret(struct gui_window *g) } -void -gui_create_form_select_menu(struct browser_window *bw, - struct form_control *control) -{ -} - -void -gui_launch_url(const char *url) -{ -} - -void -gui_cert_verify(nsurl *url, - const struct ssl_cert_info *certs, - unsigned long num, - nserror (*cb)(bool proceed, void *pw), - void *cbpw) -{ - cb(false, cbpw); -} - static struct gui_window_table framebuffer_gui_window_table = { .create = gui_window_create, .destroy = gui_window_destroy, @@ -1810,6 +1790,9 @@ static struct gui_window_table framebuffer_gui_window_table = { static struct gui_table framebuffer_gui_table = { .poll = gui_poll, .quit = gui_quit, + .get_resource_url = gui_get_resource_url, + .get_clipboard = gui_get_clipboard, + .set_clipboard = gui_set_clipboard, .window = &framebuffer_gui_window_table, }; diff --git a/render/html_interaction.c b/render/html_interaction.c index 84c64ca20..0170c8d8d 100644 --- a/render/html_interaction.c +++ b/render/html_interaction.c @@ -30,6 +30,7 @@ #include "content/content.h" #include "desktop/browser.h" +#include "desktop/gui_factory.h" #include "desktop/frames.h" #include "desktop/mouse.h" #include "utils/nsoption.h" @@ -654,7 +655,7 @@ void html_mouse_action(struct content *c, struct browser_window *bw, c); pointer = BROWSER_POINTER_DEFAULT; } else if (mouse & BROWSER_MOUSE_CLICK_1) - gui_create_form_select_menu(bw, gadget); + guit->create_form_select_menu(bw, gadget); break; case GADGET_CHECKBOX: status = messages_get("FormCheckbox"); diff --git a/riscos/gui.c b/riscos/gui.c index 60b14833c..ccf07e5d9 100644 --- a/riscos/gui.c +++ b/riscos/gui.c @@ -252,7 +252,7 @@ static void ro_msg_save_desktop(wimp_message *message); static void ro_msg_window_info(wimp_message *message); static void ro_gui_view_source_bounce(wimp_message *message); -nsurl *gui_get_resource_url(const char *path) +static nsurl *gui_get_resource_url(const char *path) { static const char base_url[] = "file:///NetSurf:/Resources/"; size_t path_len, length; @@ -837,91 +837,6 @@ static bool nslog_stream_configure(FILE *fptr) return true; } -static struct gui_table riscos_gui_table = { - .poll = gui_poll, - .quit = gui_quit, -}; - - -/** Normal entry point from OS */ -int main(int argc, char** argv) -{ - char path[40]; - int length; - char logging_env[2]; - os_var_type type; - int used = -1; /* slightly better with older OSLib versions */ - os_error *error; - nserror ret; - - /* Consult NetSurf$Logging environment variable to decide if logging - * is required. */ - error = xos_read_var_val_size("NetSurf$Logging", 0, os_VARTYPE_STRING, - &used, NULL, &type); - if (error != NULL || type != os_VARTYPE_STRING || used != -2) { - verbose_log = true; - } else { - error = xos_read_var_val("NetSurf$Logging", logging_env, - sizeof(logging_env), 0, os_VARTYPE_STRING, - &used, NULL, &type); - if (error != NULL || logging_env[0] != '0') { - verbose_log = true; - } else { - verbose_log = false; - } - } - - /* initialise logging. Not fatal if it fails but not much we - * can do about it either. - */ - nslog_init(nslog_stream_configure, &argc, argv); - - /* user options setup */ - ret = nsoption_init(set_defaults, &nsoptions, &nsoptions_default); - if (ret != NSERROR_OK) { - die("Options failed to initialise"); - } - nsoption_read("NetSurf:Choices", NULL); - nsoption_commandline(&argc, argv, NULL); - - /* Choose the interface language to use */ - ro_gui_choose_language(); - - /* select language-specific Messages */ - if (((length = snprintf(path, - sizeof(path), - "NetSurf:Resources.%s.Messages", - nsoption_charp(language))) < 0) || - (length >= (int)sizeof(path))) { - die("Failed to locate Messages resource."); - } - - /* common initialisation */ - riscos_gui_table.window = riscos_gui_window_table; - riscos_gui_table.download = riscos_gui_download_table; - - ret = netsurf_init(path, &riscos_gui_table); - if (ret != NSERROR_OK) { - die("NetSurf failed to initialise"); - } - - artworks_init(); - draw_init(); - sprite_init(); - - /* Load some extra RISC OS specific Messages */ - messages_load("NetSurf:Resources.LangNames"); - - gui_init(argc, argv); - - gui_init2(argc, argv); - - netsurf_main_loop(); - - netsurf_exit(); - - return 0; -} /** @@ -2272,7 +2187,7 @@ void ro_gui_dump_browser_window(struct browser_window *bw) * Broadcast an URL that we can't handle. */ -void gui_launch_url(const char *url) +static void gui_launch_url(const char *url) { /* Try ant broadcast first */ ro_url_broadcast(url); @@ -2433,3 +2348,94 @@ bool path_add_part(char *path, int length, const char *newpart) return true; } +static struct gui_table riscos_gui_table = { + .poll = gui_poll, + .quit = gui_quit, + .get_resource_url = gui_get_resource_url, + .launch_url = gui_launch_url, + .create_form_select_menu = gui_create_form_select_menu, + .get_clipboard = gui_get_clipboard, + .set_clipboard = gui_set_clipboard, + .cert_verify = gui_cert_verify, +}; + + +/** Normal entry point from OS */ +int main(int argc, char** argv) +{ + char path[40]; + int length; + char logging_env[2]; + os_var_type type; + int used = -1; /* slightly better with older OSLib versions */ + os_error *error; + nserror ret; + + /* Consult NetSurf$Logging environment variable to decide if logging + * is required. */ + error = xos_read_var_val_size("NetSurf$Logging", 0, os_VARTYPE_STRING, + &used, NULL, &type); + if (error != NULL || type != os_VARTYPE_STRING || used != -2) { + verbose_log = true; + } else { + error = xos_read_var_val("NetSurf$Logging", logging_env, + sizeof(logging_env), 0, os_VARTYPE_STRING, + &used, NULL, &type); + if (error != NULL || logging_env[0] != '0') { + verbose_log = true; + } else { + verbose_log = false; + } + } + + /* initialise logging. Not fatal if it fails but not much we + * can do about it either. + */ + nslog_init(nslog_stream_configure, &argc, argv); + + /* user options setup */ + ret = nsoption_init(set_defaults, &nsoptions, &nsoptions_default); + if (ret != NSERROR_OK) { + die("Options failed to initialise"); + } + nsoption_read("NetSurf:Choices", NULL); + nsoption_commandline(&argc, argv, NULL); + + /* Choose the interface language to use */ + ro_gui_choose_language(); + + /* select language-specific Messages */ + if (((length = snprintf(path, + sizeof(path), + "NetSurf:Resources.%s.Messages", + nsoption_charp(language))) < 0) || + (length >= (int)sizeof(path))) { + die("Failed to locate Messages resource."); + } + + /* common initialisation */ + riscos_gui_table.window = riscos_gui_window_table; + riscos_gui_table.download = riscos_gui_download_table; + + ret = netsurf_init(path, &riscos_gui_table); + if (ret != NSERROR_OK) { + die("NetSurf failed to initialise"); + } + + artworks_init(); + draw_init(); + sprite_init(); + + /* Load some extra RISC OS specific Messages */ + messages_load("NetSurf:Resources.LangNames"); + + gui_init(argc, argv); + + gui_init2(argc, argv); + + netsurf_main_loop(); + + netsurf_exit(); + + return 0; +} diff --git a/riscos/gui.h b/riscos/gui.h index 38f3fc60c..9fbc2eb28 100644 --- a/riscos/gui.h +++ b/riscos/gui.h @@ -156,6 +156,7 @@ bool ro_gui_shift_pressed(void); bool ro_gui_ctrl_pressed(void); bool ro_gui_alt_pressed(void); void gui_window_set_pointer(struct gui_window *g, gui_pointer_shape shape); +void gui_create_form_select_menu(struct browser_window *bw, struct form_control *control); /* in history.c */ void ro_gui_history_init(void); @@ -201,6 +202,15 @@ extern int ro_plot_origin_y; /* in theme_install.c */ bool ro_gui_theme_install_apply(wimp_w w); +/* in textselection.c */ +void gui_get_clipboard(char **buffer, size_t *length); +void gui_set_clipboard(const char *buffer, size_t length, nsclipboard_styles styles[], int n_styles); + +/* in sslcert.c */ +void gui_cert_verify(nsurl *url, + const struct ssl_cert_info *certs, unsigned long num, + nserror (*cb)(bool proceed, void *pw), void *cbpw); + /* icon numbers */ #define ICON_STATUS_RESIZE 0 #define ICON_STATUS_TEXT 1 diff --git a/windows/gui.c b/windows/gui.c index c813c8b46..fc0af679e 100644 --- a/windows/gui.c +++ b/windows/gui.c @@ -1729,7 +1729,7 @@ static void gui_window_remove_caret(struct gui_window *w) * \param buffer UTF-8 text, allocated by front end, ownership yeilded to core * \param length Byte length of UTF-8 text in buffer */ -void gui_get_clipboard(char **buffer, size_t *length) +static void gui_get_clipboard(char **buffer, size_t *length) { /* TODO: Implement this */ HANDLE clipboard_handle; @@ -1751,7 +1751,7 @@ void gui_get_clipboard(char **buffer, size_t *length) * \param styles Array of styles given to text runs, owned by core, or NULL * \param n_styles Number of text run styles in array */ -void gui_set_clipboard(const char *buffer, size_t length, +static void gui_set_clipboard(const char *buffer, size_t length, nsclipboard_styles styles[], int n_styles) { /* TODO: Implement this */ @@ -1777,19 +1777,6 @@ void gui_set_clipboard(const char *buffer, size_t length, } -void gui_create_form_select_menu(struct browser_window *bw, - struct form_control *control) -{ -} - - -void gui_cert_verify(nsurl *url, const struct ssl_cert_info *certs, - unsigned long num, - nserror (*cb)(bool proceed, void *pw), void *cbpw) -{ - cb(false, cbpw); -} - /** * Create the main window class. */ @@ -1844,6 +1831,8 @@ static struct gui_window_table win32_window_table = { static struct gui_table gui_table = { .poll = gui_poll, + .get_clipboard = gui_get_clipboard, + .set_clipboard = gui_set_clipboard, .window = &win32_window_table, }; diff --git a/windows/main.c b/windows/main.c index eb63357af..997d98120 100644 --- a/windows/main.c +++ b/windows/main.c @@ -41,7 +41,7 @@ static char **respaths; /** resource search path vector. */ char *options_file_location; -nsurl *gui_get_resource_url(const char *path) +static nsurl *gui_get_resource_url(const char *path) { char buf[PATH_MAX]; char *raw; @@ -56,10 +56,6 @@ nsurl *gui_get_resource_url(const char *path) return url; } -void gui_launch_url(const char *url) -{ -} - /** * Ensures output logging stream is available */ @@ -156,6 +152,7 @@ WinMain(HINSTANCE hInstance, HINSTANCE hLastInstance, LPSTR lpcli, int ncmd) messages = filepath_find(respaths, "messages"); win32_gui_table->download = nsgtk_gui_download_table; + win32_gui_table->get_resource_url = get_resource_url; ret = netsurf_init(messages, win32_gui_table); free(messages); From 68eaec5cb4208ee80e7c0610361405fd01fc1b69 Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Wed, 15 Jan 2014 12:28:55 +0000 Subject: [PATCH 088/773] complete move of remaining core gui functions --- beos/gui.cpp | 24 ++++++++---------------- beos/window.h | 3 +++ cocoa/gui.m | 18 +++++++++++++----- cocoa/selection.h | 2 ++ cocoa/selection.m | 1 + desktop/selection.c | 2 +- desktop/textarea.c | 2 ++ framebuffer/findfile.h | 2 ++ gtk/gui.c | 16 ++++++++++++---- gtk/selection.h | 4 ++++ monkey/browser.c | 32 -------------------------------- monkey/cert.c | 6 ++++-- monkey/cert.h | 4 ++++ monkey/main.c | 8 ++++++-- 14 files changed, 62 insertions(+), 62 deletions(-) create mode 100644 cocoa/selection.h create mode 100644 monkey/cert.h diff --git a/beos/gui.cpp b/beos/gui.cpp index 45a0e6bc7..33337d8ff 100644 --- a/beos/gui.cpp +++ b/beos/gui.cpp @@ -346,7 +346,7 @@ static int32 bapp_thread(void *arg) return 0; } -nsurl *gui_get_resource_url(const char *path) +static nsurl *gui_get_resource_url(const char *path) { nsurl *url = NULL; BString u("rsrc:///"); @@ -784,13 +784,6 @@ static void gui_quit(void) } - -void gui_create_form_select_menu(struct browser_window *bw, - struct form_control *control) -{ - CALLED(); -} - /** * Send the source of a content to a text editor. */ @@ -888,7 +881,7 @@ void nsbeos_gui_view_source(struct hlcache_handle *content) * Broadcast an URL that we can't handle. */ -void gui_launch_url(const char *url) +static void gui_launch_url(const char *url) { status_t status; // try to open it as an URI @@ -949,13 +942,6 @@ void die(const char * const error) exit(EXIT_FAILURE); } -void gui_cert_verify(nsurl *url, const struct ssl_cert_info *certs, - unsigned long num, nserror (*cb)(bool proceed, void *pw), - void *cbpw) -{ - CALLED(); -} - static void nsbeos_create_ssl_verify_window(struct browser_window *bw, hlcache_handle *c, const struct ssl_cert_info *certs, unsigned long num) @@ -1076,6 +1062,12 @@ bool path_add_part(char *path, int length, const char *newpart) static struct gui_table beos_gui_table = { .poll = gui_poll, .quit = gui_quit, + + .get_resource_url = gui_get_resource_url, + .launch_url = gui_launch_url, + + .get_clipboard = gui_get_clipboard, + .set_clipboard = gui_set_clipboard, }; diff --git a/beos/window.h b/beos/window.h index 4bd38de4e..8e98841c7 100644 --- a/beos/window.h +++ b/beos/window.h @@ -62,4 +62,7 @@ void nsbeos_window_destroy_browser(struct gui_window *g); struct browser_window *nsbeos_get_browser_window(struct gui_window *g); +void gui_get_clipboard(char **buffer, size_t *length); +void gui_set_clipboard(const char *buffer, size_t length, nsclipboard_styles styles[], int n_styles); + #endif /* NETSURF_BEOS_WINDOW_H */ diff --git a/cocoa/gui.m b/cocoa/gui.m index 40dc8e191..2c3680994 100644 --- a/cocoa/gui.m +++ b/cocoa/gui.m @@ -24,6 +24,7 @@ #import "cocoa/BrowserViewController.h" #import "cocoa/BrowserWindowController.h" #import "cocoa/FormSelectMenu.h" +#import "cocoa/selection.h" #import "desktop/gui.h" #import "desktop/netsurf.h" @@ -46,7 +47,7 @@ NSString * const kAlwaysCloseMultipleTabs = @"AlwaysCloseMultipleTabs"; #define UNIMPL() NSLog( @"Function '%s' unimplemented", __func__ ) -nsurl *gui_get_resource_url(const char *path) +static nsurl *gui_get_resource_url(const char *path) { nsurl *url = NULL; NSString *nspath = [[NSBundle mainBundle] pathForResource: [NSString stringWithUTF8String: path] ofType: @""]; @@ -251,7 +252,7 @@ static void gui_window_new_content(struct gui_window *g) } -void gui_create_form_select_menu(struct browser_window *bw, +static void gui_create_form_select_menu(struct browser_window *bw, struct form_control *control) { FormSelectMenu *menu = [[FormSelectMenu alloc] initWithControl: control forWindow: bw]; @@ -259,14 +260,14 @@ void gui_create_form_select_menu(struct browser_window *bw, [menu release]; } -void gui_launch_url(const char *url) +static void gui_launch_url(const char *url) { [[NSWorkspace sharedWorkspace] openURL: [NSURL URLWithString: [NSString stringWithUTF8String: url]]]; } struct ssl_cert_info; -void gui_cert_verify(nsurl *url, const struct ssl_cert_info *certs, +static void gui_cert_verify(nsurl *url, const struct ssl_cert_info *certs, unsigned long num, nserror (*cb)(bool proceed, void *pw), void *cbpw) { @@ -304,7 +305,14 @@ static struct gui_window_table cocoa_window_table = { }; static struct gui_table gui_table = { - .poll = &gui_poll, + .poll = gui_poll, + .get_resource_url = gui_get_resource_url, + .launch_url = gui_launch_url, + .create_form_select_menu = gui_create_form_select_menu, + .cert_verify = gui_cert_verify, + + .get_clipboard = gui_get_clipboard, + .set_clipboard = gui_set_clipboard, .window = &cocoa_window_table, }; diff --git a/cocoa/selection.h b/cocoa/selection.h new file mode 100644 index 000000000..14b6e763f --- /dev/null +++ b/cocoa/selection.h @@ -0,0 +1,2 @@ +void gui_get_clipboard(char **buffer, size_t *length); +void gui_set_clipboard(const char *buffer, size_t length, nsclipboard_styles styles[], int n_styles); diff --git a/cocoa/selection.m b/cocoa/selection.m index daa64bf08..e95a78441 100644 --- a/cocoa/selection.m +++ b/cocoa/selection.m @@ -19,6 +19,7 @@ #import #import "cocoa/BrowserViewController.h" +#import "cocoa/selection.h" #import "desktop/browser_private.h" diff --git a/desktop/selection.c b/desktop/selection.c index fc91f1dbb..7535f6915 100644 --- a/desktop/selection.c +++ b/desktop/selection.c @@ -845,7 +845,7 @@ bool selection_copy_to_clipboard(struct selection *s) return false; } - gui_set_clipboard(sel_string.buffer, sel_string.length, + guit->set_clipboard(sel_string.buffer, sel_string.length, sel_string.styles, sel_string.n_styles); free(sel_string.buffer); diff --git a/desktop/textarea.c b/desktop/textarea.c index 423767274..14747252d 100644 --- a/desktop/textarea.c +++ b/desktop/textarea.c @@ -24,11 +24,13 @@ #include #include #include "css/utils.h" + #include "desktop/mouse.h" #include "desktop/textarea.h" #include "desktop/textinput.h" #include "desktop/plotters.h" #include "desktop/scrollbar.h" +#include "desktop/gui_factory.h" #include "render/font.h" #include "utils/log.h" #include "utils/utf8.h" diff --git a/framebuffer/findfile.h b/framebuffer/findfile.h index 130bd3eb4..ca40c7751 100644 --- a/framebuffer/findfile.h +++ b/framebuffer/findfile.h @@ -19,6 +19,8 @@ #ifndef NETSURF_FB_FINDFILE_H #define NETSURF_FB_FINDFILE_H +#include "utils/nsurl.h" + extern char **respaths; /** Create an array of valid paths to search for resources. diff --git a/gtk/gui.c b/gtk/gui.c index 0501ec3f6..9dea700e4 100644 --- a/gtk/gui.c +++ b/gtk/gui.c @@ -55,6 +55,7 @@ #include "desktop/textinput.h" #include "desktop/tree.h" #include "css/utils.h" + #include "gtk/compat.h" #include "gtk/completion.h" #include "gtk/cookies.h" @@ -67,6 +68,7 @@ #include "gtk/treeview.h" #include "gtk/window.h" #include "gtk/schedule.h" +#include "gtk/selection.h" #include "render/form.h" #include "utils/filepath.h" @@ -322,7 +324,7 @@ static void check_options(char **respath) } -nsurl *gui_get_resource_url(const char *path) +static nsurl *gui_get_resource_url(const char *path) { char buf[PATH_MAX]; char *raw; @@ -635,7 +637,7 @@ static void nsgtk_select_menu_clicked(GtkCheckMenuItem *checkmenuitem, select_menu_control, (intptr_t)user_data); } -void gui_create_form_select_menu(struct browser_window *bw, +static void gui_create_form_select_menu(struct browser_window *bw, struct form_control *control) { @@ -676,7 +678,7 @@ void gui_create_form_select_menu(struct browser_window *bw, } -void gui_launch_url(const char *url) +static void gui_launch_url(const char *url) { gboolean ok; GError *error = NULL; @@ -714,7 +716,7 @@ void die(const char * const error) } -void gui_cert_verify(nsurl *url, const struct ssl_cert_info *certs, +static void gui_cert_verify(nsurl *url, const struct ssl_cert_info *certs, unsigned long num, nserror (*cb)(bool proceed, void *pw), void *cbpw) { @@ -1132,6 +1134,12 @@ static struct gui_table nsgtk_gui_table = { .poll = gui_poll, .quit = gui_quit, .set_search_ico = gui_set_search_ico, + .get_resource_url = gui_get_resource_url, + .launch_url = gui_launch_url, + .create_form_select_menu = gui_create_form_select_menu, + .get_clipboard = gui_get_clipboard, + .set_clipboard = gui_set_clipboard, + .cert_verify = gui_cert_verify, }; /** diff --git a/gtk/selection.h b/gtk/selection.h index c2a0b35f4..0d3ec7371 100644 --- a/gtk/selection.h +++ b/gtk/selection.h @@ -22,4 +22,8 @@ #include #include "desktop/gui.h" +void gui_get_clipboard(char **buffer, size_t *length); +void gui_set_clipboard(const char *buffer, size_t length, nsclipboard_styles styles[], int n_styles); + + #endif diff --git a/monkey/browser.c b/monkey/browser.c index 7cada343e..97bd0be8b 100644 --- a/monkey/browser.c +++ b/monkey/browser.c @@ -302,30 +302,6 @@ gui_window_scroll_visible(struct gui_window *g, int x0, int y0, g->win_num, x0, y0, x1, y1); } -/** - * Core asks front end for clipboard contents. - * - * \param buffer UTF-8 text, allocated by front end, ownership yeilded to core - * \param length Byte length of UTF-8 text in buffer - */ -void gui_get_clipboard(char **buffer, size_t *length) -{ -} - - -/** - * Core tells front end to put given text in clipboard - * - * \param buffer UTF-8 text, owned by core - * \param length Byte length of UTF-8 text in buffer - * \param styles Array of styles given to text runs, owned by core, or NULL - * \param n_styles Number of text run styles in array - */ -void gui_set_clipboard(const char *buffer, size_t length, - nsclipboard_styles styles[], int n_styles) -{ -} - static void gui_window_place_caret(struct gui_window *g, int x, int y, int height, const struct rect *clip) @@ -348,14 +324,6 @@ gui_window_drag_start(struct gui_window *g, gui_drag_type type, return false; } -void -gui_create_form_select_menu(struct browser_window *bw, - struct form_control *control) -{ - fprintf(stdout, "WINDOW SELECT_MENU WIN %u\n", - bw->window->win_num); -} - static void gui_window_save_link(struct gui_window *g, const char *url, const char *title) diff --git a/monkey/cert.c b/monkey/cert.c index 0aa01f3a7..48359e8c2 100644 --- a/monkey/cert.c +++ b/monkey/cert.c @@ -16,11 +16,13 @@ * along with this program. If not, see . */ +#include +#include + #include "desktop/gui.h" #include "utils/ring.h" -#include -#include +#include "monkey/cert.h" typedef struct monkey_cert { struct monkey_cert *r_next, *r_prev; diff --git a/monkey/cert.h b/monkey/cert.h new file mode 100644 index 000000000..2780f4f57 --- /dev/null +++ b/monkey/cert.h @@ -0,0 +1,4 @@ +void +gui_cert_verify(nsurl *url, const struct ssl_cert_info *certs, + unsigned long num, nserror (*cb)(bool proceed, void *pw), + void *cbpw); diff --git a/monkey/main.c b/monkey/main.c index ce7906e03..419543e29 100644 --- a/monkey/main.c +++ b/monkey/main.c @@ -25,6 +25,7 @@ #include "monkey/poll.h" #include "monkey/dispatch.h" #include "monkey/browser.h" +#include "monkey/cert.h" #include "content/urldb.h" #include "content/fetchers/resource.h" @@ -64,7 +65,7 @@ static void monkey_quit(void) gtk_fetch_filetype_fin(); } -nsurl *gui_get_resource_url(const char *path) +static nsurl *gui_get_resource_url(const char *path) { char buf[PATH_MAX]; char *raw; @@ -79,7 +80,7 @@ nsurl *gui_get_resource_url(const char *path) return url; } -void +static void gui_launch_url(const char *url) { fprintf(stdout, "GENERIC LAUNCH URL %s\n", url); @@ -116,6 +117,9 @@ static bool nslog_stream_configure(FILE *fptr) static struct gui_table monkey_gui_table = { .poll = monkey_poll, .quit = monkey_quit, + .get_resource_url = gui_get_resource_url, + .launch_url = gui_launch_url, + .cert_verify = gui_cert_verify, }; int From bd065d4a434755e67642a071e255cba596de8d1e Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Wed, 15 Jan 2014 19:37:05 +0000 Subject: [PATCH 089/773] split browser gui operations up --- amiga/download.c | 4 +- amiga/download.h | 2 +- amiga/gui.c | 23 +++--- atari/download.c | 5 +- atari/download.h | 4 +- atari/gui.c | 22 +++--- beos/download.cpp | 4 +- beos/download.h | 2 +- beos/gui.cpp | 32 +++++---- beos/window.cpp | 4 +- beos/window.h | 2 +- cocoa/NetsurfApp.m | 10 ++- cocoa/gui.h | 6 +- cocoa/gui.m | 23 +++--- content/fetchers/resource.c | 2 +- desktop/browser.c | 4 +- desktop/gui.h | 73 +++++++++++-------- desktop/gui_factory.c | 140 ++++++++++++++++++++++++------------ desktop/netsurf.c | 6 +- desktop/searchweb.c | 2 +- desktop/selection.c | 2 +- desktop/textarea.c | 4 +- framebuffer/clipboard.c | 10 ++- framebuffer/clipboard.h | 4 +- framebuffer/gui.c | 13 ++-- gtk/download.c | 4 +- gtk/download.h | 4 +- gtk/gui.c | 19 ++--- gtk/window.c | 4 +- gtk/window.h | 2 +- monkey/browser.c | 4 +- monkey/browser.h | 6 +- monkey/download.c | 4 +- monkey/main.c | 11 +-- render/html_interaction.c | 2 +- riscos/download.c | 4 +- riscos/gui.c | 18 +++-- riscos/gui.h | 2 +- windows/download.c | 4 +- windows/download.h | 4 +- windows/gui.c | 19 +++-- windows/gui.h | 4 +- windows/main.c | 13 ++-- 43 files changed, 323 insertions(+), 208 deletions(-) diff --git a/amiga/download.c b/amiga/download.c index 60190ce17..4f4c39b20 100644 --- a/amiga/download.c +++ b/amiga/download.c @@ -433,11 +433,11 @@ BOOL ami_download_check_overwrite(const char *file, struct Window *win, ULONG si else return FALSE; } -static struct gui_download_table gui_download_table = { +static struct gui_download_table download_table = { .create = gui_download_window_create, .data = gui_download_window_data, .error = gui_download_window_error, .done = gui_download_window_done, }; -struct gui_download_table *amiga_gui_download_table = &gui_download_table; +struct gui_download_table *amiga_download_table = &download_table; diff --git a/amiga/download.h b/amiga/download.h index d9e637ede..95d71ecfe 100755 --- a/amiga/download.h +++ b/amiga/download.h @@ -23,7 +23,7 @@ #include "amiga/gui.h" -extern struct gui_download_table *amiga_gui_download_table; +extern struct gui_download_table *amiga_download_table; struct download_context; struct gui_download_window; diff --git a/amiga/gui.c b/amiga/gui.c index 9e433101e..27e747a05 100644 --- a/amiga/gui.c +++ b/amiga/gui.c @@ -5085,7 +5085,7 @@ static void gui_file_gadget_open(struct gui_window *g, hlcache_handle *hl, } } -static struct gui_window_table ami_window_table = { +static struct gui_window_table amiga_window_table = { .create = gui_window_create, .destroy = gui_window_destroy, .redraw = gui_window_redraw_window, @@ -5117,19 +5117,19 @@ static struct gui_window_table ami_window_table = { .save_link = gui_window_save_link, }; +static struct gui_clipboard_table amiga_clipboard_table = { + .get = gui_get_clipboard, + .set = gui_set_clipboard, +}; -static struct gui_table ami_gui_table = { +static struct gui_browser_table amiga_browser_table = { .poll = gui_poll, .quit = gui_quit, .set_search_ico = gui_set_search_ico, .get_resource_url = gui_get_resource_url, .launch_url = gui_launch_url, .create_form_select_menu = gui_create_form_select_menu, - .get_clipboard = gui_get_clipboard, - .set_clipboard = gui_set_clipboard, .cert_verify = gui_cert_verify, - - .window = &ami_window_table, }; /** Normal entry point from OS */ @@ -5143,6 +5143,12 @@ int main(int argc, char** argv) int32 user = 0; nserror ret; Object *splash_window = ami_gui_splash_open(); + struct gui_table amiga_gui_table = { + .browser = &amiga_browser_table, + .window = &amiga_window_table, + .clipboard = &amiga_clipboard_table, + .download = amiga_download_table, + }; /* Open popupmenu.library just to check the version. * Versions older than 53.11 are dangerous, so we @@ -5190,10 +5196,7 @@ int main(int argc, char** argv) if (ami_locate_resource(messages, "Messages") == false) die("Cannot open Messages file"); - - ami_gui_table.download = amiga_gui_download_table; - - ret = netsurf_init(messages, &ami_gui_table); + ret = netsurf_init(messages, &amiga_gui_table); if (ret != NSERROR_OK) { die("NetSurf failed to initialise"); } diff --git a/atari/download.c b/atari/download.c index 4da9ef345..8d4786e23 100755 --- a/atari/download.c +++ b/atari/download.c @@ -455,12 +455,11 @@ static void gui_download_window_done(struct gui_download_window *dw) gui_window_set_status(input_window, messages_get("Done") ); } -static struct gui_download_table gui_download_table = { +static struct gui_download_table download_table = { .create = gui_download_window_create, .data = gui_download_window_data, .error = gui_download_window_error, .done = gui_download_window_done, }; -struct gui_download_table *atari_gui_download_table = &gui_download_table; - +struct gui_download_table *atari_download_table = &download_table; diff --git a/atari/download.h b/atari/download.h index a5da60538..82f89c050 100755 --- a/atari/download.h +++ b/atari/download.h @@ -19,6 +19,8 @@ #ifndef NS_ATARI_DOWNLOAD_H #define NS_ATARI_DOWNLOAD_H +extern struct gui_download_table *atari_download_table; + #define MAX_SLEN_LBL_DONE 64 #define MAX_SLEN_LBL_PERCENT 5 #define MAX_SLEN_LBL_SPEED 13 @@ -58,6 +60,4 @@ struct gui_download_window { bool close_on_finish; }; -struct gui_download_table *atari_gui_download_table; - #endif diff --git a/atari/gui.c b/atari/gui.c index 924ac686a..49e3046e2 100644 --- a/atari/gui.c +++ b/atari/gui.c @@ -1045,15 +1045,16 @@ static struct gui_window_table atari_window_table = { .stop_throbber = gui_window_stop_throbber, }; -static struct gui_table atari_gui_table = { +static struct gui_clipboard_table atari_clipboard_table = { + .get = gui_get_clipboard, + .set = gui_set_clipboard, +}; + +static struct gui_browser_table atari_browser_table = { .poll = gui_poll, .quit = gui_quit, .get_resource_url = gui_get_resource_url, - .get_clipboard = gui_get_clipboard, - .set_clipboard = gui_set_clipboard, .cert_verify = gui_cert_verify, - - .window = &atari_window_table; }; /* #define WITH_DBG_LOGFILE 1 */ @@ -1071,6 +1072,12 @@ int main(int argc, char** argv) struct stat stat_buf; nsurl *url; nserror ret; + struct gui_table atari_gui_table = { + .browser = &atari_browser_table, + .window = &atari_window_table, + .clipboard = &atari_clipboard_table, + .download = atari_download_table, + }; /* @todo logging file descriptor update belongs in a nslog_init callback */ setbuf(stderr, NULL); @@ -1104,10 +1111,7 @@ int main(int argc, char** argv) /* common initialisation */ LOG(("Initialising core...")); - - atari_gui_table.download = nsgtk_gui_download_table; - - ret = netsurf_init(messages, atari_gui_table); + ret = netsurf_init(messages, &atari_gui_table); if (ret != NSERROR_OK) { die("NetSurf failed to initialise"); } diff --git a/beos/download.cpp b/beos/download.cpp index b62ab2ffb..2e259bccf 100644 --- a/beos/download.cpp +++ b/beos/download.cpp @@ -248,12 +248,12 @@ static void gui_download_window_done(struct gui_download_window *dw) dw->storageLock->Unlock(); } -static struct gui_download_table gui_download_table = { +static struct gui_download_table download_table = { .create = gui_download_window_create, .data = gui_download_window_data, .error = gui_download_window_error, .done = gui_download_window_done, }; -struct gui_download_table *beos_gui_download_table = &gui_download_table; +struct gui_download_table *beos_download_table = &download_table; diff --git a/beos/download.h b/beos/download.h index 962f3b7d9..245ee8641 100644 --- a/beos/download.h +++ b/beos/download.h @@ -16,4 +16,4 @@ * along with this program. If not, see . */ -struct gui_download_table *beos_gui_download_table; +struct gui_download_table *beos_download_table; diff --git a/beos/gui.cpp b/beos/gui.cpp index 33337d8ff..3ee47c9e9 100644 --- a/beos/gui.cpp +++ b/beos/gui.cpp @@ -1059,15 +1059,17 @@ bool path_add_part(char *path, int length, const char *newpart) return true; } -static struct gui_table beos_gui_table = { +static struct gui_clipboard_table beos_clipboard_table = { + .get = gui_get_clipboard, + .set = gui_set_clipboard, +}; + +static struct gui_browser_table beos_browser_table = { .poll = gui_poll, .quit = gui_quit, .get_resource_url = gui_get_resource_url, .launch_url = gui_launch_url, - - .get_clipboard = gui_get_clipboard, - .set_clipboard = gui_set_clipboard, }; @@ -1076,6 +1078,13 @@ int main(int argc, char** argv) { nserror ret; BPath options; + struct gui_table beos_gui_table = { + .browser = &beos_browser_table, + .window = beos_window_table, + .clipboard = &beos_clipboard_table, + .download = beos_download_table, + }; + if (find_directory(B_USER_SETTINGS_DIRECTORY, &options, true) == B_OK) { options.Append("x-vnd.NetSurf"); } @@ -1101,10 +1110,6 @@ int main(int argc, char** argv) /* common initialisation */ BPath messages = get_messages_path(); - - beos_gui_table.window = beos_gui_window_table; - beos_gui_table.download = beos_gui_download_table; - ret = netsurf_init(messages.Path(), &beos_gui_table); if (ret != NSERROR_OK) { die("NetSurf failed to initialise"); @@ -1124,6 +1129,13 @@ int gui_init_replicant(int argc, char** argv) { nserror ret; BPath options; + struct gui_table beos_gui_table = { + .browser = &beos_browser_table, + .window = beos_window_table, + .clipboard = &beos_clipboard_table, + .download = beos_download_table, + }; + if (find_directory(B_USER_SETTINGS_DIRECTORY, &options, true) == B_OK) { options.Append("x-vnd.NetSurf"); } @@ -1145,10 +1157,6 @@ int gui_init_replicant(int argc, char** argv) /* common initialisation */ BPath messages = get_messages_path(); - - beos_gui_table.window = beos_gui_window_table; - beos_gui_table.download = beos_gui_download_table; - ret = netsurf_init(messages.Path(), &beos_gui_table); if (ret != NSERROR_OK) { // FIXME: must not die when in replicant! diff --git a/beos/window.cpp b/beos/window.cpp index a7bdf411e..fc46eba96 100644 --- a/beos/window.cpp +++ b/beos/window.cpp @@ -1347,7 +1347,7 @@ static void gui_window_get_dimensions(struct gui_window *g, int *width, int *hei } } -static struct gui_window_table gui_window_table = { +static struct gui_window_table window_table = { .create = gui_window_create, .destroy = gui_window_destroy, .redraw = gui_window_redraw_window, @@ -1372,4 +1372,4 @@ static struct gui_window_table gui_window_table = { .stop_throbber = gui_window_stop_throbber, }; -struct gui_window_table *beos_gui_window_table = &gui_window_table; +struct gui_window_table *beos_window_table = &window_table; diff --git a/beos/window.h b/beos/window.h index 8e98841c7..fb67517d2 100644 --- a/beos/window.h +++ b/beos/window.h @@ -25,7 +25,7 @@ extern "C" { } #include "beos/scaffolding.h" -extern struct gui_window_table *beos_gui_window_table; +extern struct gui_window_table *beos_window_table; class NSBrowserFrameView : public BView { public: diff --git a/cocoa/NetsurfApp.m b/cocoa/NetsurfApp.m index a64c99376..62f684ddc 100644 --- a/cocoa/NetsurfApp.m +++ b/cocoa/NetsurfApp.m @@ -183,6 +183,12 @@ int main( int argc, char **argv ) { nsurl *url; nserror error; + struct gui_table cocoa_gui_table = { + .browser = cocoa_browser_table, + .window = cocoa_window_table, + .clipboard = cocoa_clipboard_table, + .download = cocoa_download_table, + }; cocoa_autorelease(); @@ -203,9 +209,7 @@ int main( int argc, char **argv ) nsoption_commandline(&argc, argv, NULL); /* common initialisation */ - cocoa_gui_table->download = cocoa_gui_download_table; - - error = netsurf_init(messages, cocoa_gui_table); + error = netsurf_init(messages, &cocoa_gui_table); if (error != NSERROR_OK) { die("NetSurf failed to initialise"); } diff --git a/cocoa/gui.h b/cocoa/gui.h index 6ceefa848..757140030 100644 --- a/cocoa/gui.h +++ b/cocoa/gui.h @@ -18,6 +18,10 @@ #import +extern struct gui_window_table *cocoa_window_table; +extern struct gui_clipboard_table *cocoa_clipboard_table; +extern struct gui_browser_table *cocoa_browser_table; + extern NSString * const kCookiesFileOption; extern NSString * const kURLsFileOption; extern NSString * const kHotlistFileOption; @@ -27,5 +31,3 @@ extern NSString * const kAlwaysCancelDownload; extern NSString * const kAlwaysCloseMultipleTabs; void cocoa_autorelease( void ); - -extern struct gui_table *cocoa_gui_table; diff --git a/cocoa/gui.m b/cocoa/gui.m index 2c3680994..c2cadfe5a 100644 --- a/cocoa/gui.m +++ b/cocoa/gui.m @@ -282,7 +282,7 @@ void gui_401login_open(nsurl *url, const char *realm, } -static struct gui_window_table cocoa_window_table = { +static struct gui_window_table window_table = { .create = gui_window_create, .destroy = gui_window_destroy, .redraw = gui_window_redraw_window, @@ -304,18 +304,25 @@ static struct gui_window_table cocoa_window_table = { .stop_throbber = gui_window_stop_throbber, }; -static struct gui_table gui_table = { +struct gui_window_table *cocoa_window_table = &window_table; + + +static struct gui_clipboard_table clipboard_table = { + .get_clipboard = gui_get_clipboard, + .set_clipboard = gui_set_clipboard, +}; + +struct gui_clipboard_table *cocoa_clipboard_table = &clipboard_table; + + +static struct gui_browser_table browser_table = { .poll = gui_poll, .get_resource_url = gui_get_resource_url, .launch_url = gui_launch_url, .create_form_select_menu = gui_create_form_select_menu, .cert_verify = gui_cert_verify, - - .get_clipboard = gui_get_clipboard, - .set_clipboard = gui_set_clipboard, - - .window = &cocoa_window_table, }; -struct gui_table *cocoa_gui_table = &gui_table; +struct gui_browser_table *cocoa_browser_table = &browser_table; + diff --git a/content/fetchers/resource.c b/content/fetchers/resource.c index 5dca8b378..d1b21b741 100644 --- a/content/fetchers/resource.c +++ b/content/fetchers/resource.c @@ -207,7 +207,7 @@ static bool fetch_resource_initialise(lwc_string *scheme) } } - e->url = guit->get_resource_url(fetch_resource_paths[i]); + e->url = guit->browser->get_resource_url(fetch_resource_paths[i]); if (e->url == NULL) { lwc_string_unref(e->path); } else { diff --git a/desktop/browser.c b/desktop/browser.c index 55cb779bf..d65033097 100644 --- a/desktop/browser.c +++ b/desktop/browser.c @@ -814,7 +814,7 @@ browser_window_download(struct browser_window *bw, NULL, NULL, &l); if (error == NSERROR_NO_FETCH_HANDLER) { /* no internal handler for this type, call out to frontend */ - guit->launch_url(nsurl_access(url)); + guit->browser->launch_url(nsurl_access(url)); } else if (error != NSERROR_OK) { LOG(("Failed to fetch download: %d", error)); } else { @@ -1873,7 +1873,7 @@ nserror browser_window_navigate(struct browser_window *bw, case NSERROR_NO_FETCH_HANDLER: /* no handler for this type */ /** @todo does this always try and download even unverifiable content? */ - guit->launch_url(nsurl_access(url)); + guit->browser->launch_url(nsurl_access(url)); break; default: /* report error to user */ diff --git a/desktop/gui.h b/desktop/gui.h index 12cf91a50..686bb59d4 100644 --- a/desktop/gui.h +++ b/desktop/gui.h @@ -264,20 +264,35 @@ struct gui_download_table { void (*done)(struct gui_download_window *dw); }; -/** Graphical user interface function table - * - * function table implementing GUI interface to browser core +/** + * function table for clipboard operations */ -struct gui_table { +struct gui_clipboard_table { + /** + * Core asks front end for clipboard contents. + * + * \param buffer UTF-8 text, allocated by front end, ownership yeilded to core + * \param length Byte length of UTF-8 text in buffer + */ + void (*get)(char **buffer, size_t *length); - /* sub tables */ - - /** Window sub table */ - struct gui_window_table *window; - - /** Downlaod sub table */ - struct gui_download_table *download; + /** + * Core tells front end to put given text in clipboard + * + * \param buffer UTF-8 text, owned by core + * \param length Byte length of UTF-8 text in buffer + * \param styles Array of styles given to text runs, owned by core, or NULL + * \param n_styles Number of text run styles in array + */ + void (*set)(const char *buffer, size_t length, nsclipboard_styles styles[], int n_styles); +}; +/** Graphical user interface browser misc function table + * + * function table implementing GUI interface to miscelaneous browser + * functionality + */ +struct gui_browser_table { /* Mandantory entries */ /** @@ -318,30 +333,12 @@ struct gui_table { * core has no fetcher for url */ void (*launch_url)(const char *url); - + /** * create a form select menu */ void (*create_form_select_menu)(struct browser_window *bw, struct form_control *control); - /** - * Core asks front end for clipboard contents. - * - * \param buffer UTF-8 text, allocated by front end, ownership yeilded to core - * \param length Byte length of UTF-8 text in buffer - */ - void (*get_clipboard)(char **buffer, size_t *length); - - /** - * Core tells front end to put given text in clipboard - * - * \param buffer UTF-8 text, owned by core - * \param length Byte length of UTF-8 text in buffer - * \param styles Array of styles given to text runs, owned by core, or NULL - * \param n_styles Number of text run styles in array - */ - void (*set_clipboard)(const char *buffer, size_t length, nsclipboard_styles styles[], int n_styles); - /** * verify certificate */ @@ -350,8 +347,24 @@ struct gui_table { }; +/** Graphical user interface function table + * + * function table implementing GUI interface to browser core + */ +struct gui_table { + /** Browser table */ + struct gui_browser_table *browser; + /** Window table */ + struct gui_window_table *window; + + /** Download table */ + struct gui_download_table *download; + + /** Clipboard table */ + struct gui_clipboard_table *clipboard; +}; #endif diff --git a/desktop/gui_factory.c b/desktop/gui_factory.c index cb01fc45e..f47b73007 100644 --- a/desktop/gui_factory.c +++ b/desktop/gui_factory.c @@ -195,6 +195,7 @@ static nserror verify_window_register(struct gui_window_table *gwt) } + static struct gui_download_window * gui_default_download_create(download_context *ctx, struct gui_window *parent) { @@ -216,12 +217,6 @@ static void gui_default_download_done(struct gui_download_window *dw) { } -static struct gui_download_table default_download_table = { - .create = gui_default_download_create, - .data = gui_default_download_data, - .error = gui_default_download_error, - .done = gui_default_download_done, -}; /** verify download window table is valid */ static nserror verify_download_register(struct gui_download_table *gdt) @@ -248,6 +243,35 @@ static nserror verify_download_register(struct gui_download_table *gdt) return NSERROR_OK; } +static void gui_default_get_clipboard(char **buffer, size_t *length) +{ + *buffer = NULL; + *length = 0; +} + +static void gui_default_set_clipboard(const char *buffer, size_t length, + nsclipboard_styles styles[], int n_styles) +{ +} + +static nserror verify_clipboard_register(struct gui_clipboard_table *gct) +{ + /* check table is present */ + if (gct == NULL) { + return NSERROR_BAD_PARAMETER; + } + + /* optional operations */ + if (gct->get == NULL) { + gct->get = gui_default_get_clipboard; + } + if (gct->set == NULL) { + gct->set = gui_default_set_clipboard; + } + return NSERROR_OK; +} + + static void gui_default_quit(void) { } @@ -270,16 +294,6 @@ static void gui_default_create_form_select_menu(struct browser_window *bw, { } -static void gui_default_get_clipboard(char **buffer, size_t *length) -{ - *buffer = NULL; - *length = 0; -} - -static void gui_default_set_clipboard(const char *buffer, size_t length, - nsclipboard_styles styles[], int n_styles) -{ -} static void gui_default_cert_verify(nsurl *url, const struct ssl_cert_info *certs, @@ -290,6 +304,55 @@ static void gui_default_cert_verify(nsurl *url, cb(false, cbpw); } + +static nserror verify_browser_register(struct gui_browser_table *gbt) +{ + /* check table is present */ + if (gbt == NULL) { + return NSERROR_BAD_PARAMETER; + } + + /* check the mandantory fields are set */ + if (gbt->poll == NULL) { + return NSERROR_BAD_PARAMETER; + } + + /* fill in the optional entries with defaults */ + if (gbt->quit == NULL) { + gbt->quit = gui_default_quit; + } + if (gbt->set_search_ico == NULL) { + gbt->set_search_ico = gui_default_set_search_ico; + } + if (gbt->get_resource_url == NULL) { + gbt->get_resource_url = gui_default_get_resource_url; + } + if (gbt->launch_url == NULL) { + gbt->launch_url = gui_default_launch_url; + } + if (gbt->create_form_select_menu == NULL) { + gbt->create_form_select_menu = gui_default_create_form_select_menu; + } + if (gbt->cert_verify == NULL) { + gbt->cert_verify = gui_default_cert_verify; + } + return NSERROR_OK; +} + + + +static struct gui_download_table default_download_table = { + .create = gui_default_download_create, + .data = gui_default_download_data, + .error = gui_default_download_error, + .done = gui_default_download_done, +}; + +static struct gui_clipboard_table default_clipboard_table = { + .get = gui_default_get_clipboard, + .set = gui_default_set_clipboard, +}; + nserror gui_factory_register(struct gui_table *gt) { nserror err; @@ -304,11 +367,19 @@ nserror gui_factory_register(struct gui_table *gt) return NSERROR_BAD_PARAMETER; } - /* check subtables */ + /* browser table */ + err = verify_browser_register(gt->browser); + if (err != NSERROR_OK) { + return err; + } + + /* window table */ err = verify_window_register(gt->window); if (err != NSERROR_OK) { return err; } + + /* download table */ if (gt->download == NULL) { /* set default download table */ gt->download = &default_download_table; @@ -318,35 +389,14 @@ nserror gui_factory_register(struct gui_table *gt) return err; } - /* check the mandantory fields are set */ - if (gt->poll == NULL) { - return NSERROR_BAD_PARAMETER; + /* clipboard table */ + if (gt->clipboard == NULL) { + /* set default clipboard table */ + gt->clipboard = &default_clipboard_table; } - - /* fill in the optional entries with defaults */ - if (gt->quit == NULL) { - gt->quit = gui_default_quit; - } - if (gt->set_search_ico == NULL) { - gt->set_search_ico = gui_default_set_search_ico; - } - if (gt->get_resource_url == NULL) { - gt->get_resource_url = gui_default_get_resource_url; - } - if (gt->launch_url == NULL) { - gt->launch_url = gui_default_launch_url; - } - if (gt->create_form_select_menu == NULL) { - gt->create_form_select_menu = gui_default_create_form_select_menu; - } - if (gt->get_clipboard == NULL) { - gt->get_clipboard = gui_default_get_clipboard; - } - if (gt->set_clipboard == NULL) { - gt->set_clipboard = gui_default_set_clipboard; - } - if (gt->cert_verify == NULL) { - gt->cert_verify = gui_default_cert_verify; + err = verify_clipboard_register(gt->clipboard); + if (err != NSERROR_OK) { + return err; } guit = gt; diff --git a/desktop/netsurf.c b/desktop/netsurf.c index 1c36a3fe7..5589f51a5 100644 --- a/desktop/netsurf.c +++ b/desktop/netsurf.c @@ -103,7 +103,7 @@ static nserror netsurf_llcache_query_handler(const llcache_query *query, /* For now, do nothing, as this query type isn't emitted yet */ break; case LLCACHE_QUERY_SSL: - guit->cert_verify(query->url, query->data.ssl.certs, + guit->browser->cert_verify(query->url, query->data.ssl.certs, query->data.ssl.num, cb, cbpw); break; } @@ -234,7 +234,7 @@ nserror netsurf_init(const char *messages, struct gui_table *gt) int netsurf_main_loop(void) { while (!netsurf_quit) { - guit->poll(fetch_active); + guit->browser->poll(fetch_active); hlcache_poll(); } @@ -250,7 +250,7 @@ void netsurf_exit(void) hlcache_stop(); LOG(("Closing GUI")); - guit->quit(); + guit->browser->quit(); LOG(("Finalising JavaScript")); js_finalise(); diff --git a/desktop/searchweb.c b/desktop/searchweb.c index 63e17ee90..30b424cb3 100644 --- a/desktop/searchweb.c +++ b/desktop/searchweb.c @@ -308,7 +308,7 @@ nserror search_web_ico_callback(hlcache_handle *ico, case CONTENT_MSG_DONE: LOG(("got favicon '%s'", nsurl_access(hlcache_handle_get_url(ico)))); - guit->set_search_ico(search_ico); + guit->browser->set_search_ico(search_ico); break; case CONTENT_MSG_ERROR: diff --git a/desktop/selection.c b/desktop/selection.c index 7535f6915..96c7e0c3c 100644 --- a/desktop/selection.c +++ b/desktop/selection.c @@ -845,7 +845,7 @@ bool selection_copy_to_clipboard(struct selection *s) return false; } - guit->set_clipboard(sel_string.buffer, sel_string.length, + guit->clipboard->set(sel_string.buffer, sel_string.length, sel_string.styles, sel_string.n_styles); free(sel_string.buffer); diff --git a/desktop/textarea.c b/desktop/textarea.c index 14747252d..209a6c6d7 100644 --- a/desktop/textarea.c +++ b/desktop/textarea.c @@ -1419,7 +1419,7 @@ static bool textarea_replace_text_internal(struct textarea *ta, size_t b_start, /* Place CUTs on clipboard */ if (add_to_clipboard) { - guit->set_clipboard(ta->show->data + b_start, b_end - b_start, + guit->clipboard->set(ta->show->data + b_start, b_end - b_start, NULL, 0); } @@ -2486,7 +2486,7 @@ bool textarea_keypress(struct textarea *ta, uint32_t key) if (readonly) break; - guit->get_clipboard(&clipboard, &clipboard_length); + guit->clipboard->get(&clipboard, &clipboard_length); if (clipboard == NULL) return false; diff --git a/framebuffer/clipboard.c b/framebuffer/clipboard.c index 4f9831340..b4bd296c6 100644 --- a/framebuffer/clipboard.c +++ b/framebuffer/clipboard.c @@ -43,7 +43,7 @@ static struct gui_clipboard { * \param buffer UTF-8 text, allocated by front end, ownership yeilded to core * \param length Byte length of UTF-8 text in buffer */ -void gui_get_clipboard(char **buffer, size_t *length) +static void gui_get_clipboard(char **buffer, size_t *length) { *buffer = NULL; *length = 0; @@ -72,7 +72,7 @@ void gui_get_clipboard(char **buffer, size_t *length) * \param styles Array of styles given to text runs, owned by core, or NULL * \param n_styles Number of text run styles in array */ -void gui_set_clipboard(const char *buffer, size_t length, +static void gui_set_clipboard(const char *buffer, size_t length, nsclipboard_styles styles[], int n_styles) { if (gui_clipboard.buffer_len < length + 1) { @@ -94,3 +94,9 @@ void gui_set_clipboard(const char *buffer, size_t length, gui_clipboard.buffer[gui_clipboard.length] = '\0'; } +static struct gui_clipboard_table clipboard_table = { + .get = gui_get_clipboard, + .set = gui_set_clipboard, +}; + +struct gui_clipboard_table *framebuffer_clipboard_table = &clipboard_table; diff --git a/framebuffer/clipboard.h b/framebuffer/clipboard.h index bc71a5565..b5f7b0f29 100644 --- a/framebuffer/clipboard.h +++ b/framebuffer/clipboard.h @@ -19,8 +19,6 @@ #ifndef NETSURF_FB_CLIPBOARD_H #define NETSURF_FB_CLIPBOARD_H -void gui_get_clipboard(char **buffer, size_t *length); -void gui_set_clipboard(const char *buffer, size_t length, - nsclipboard_styles styles[], int n_styles); +extern struct gui_clipboard_table *framebuffer_clipboard_table; #endif diff --git a/framebuffer/gui.c b/framebuffer/gui.c index 8b90b52f7..b2edc030a 100644 --- a/framebuffer/gui.c +++ b/framebuffer/gui.c @@ -1768,7 +1768,7 @@ gui_window_remove_caret(struct gui_window *g) } -static struct gui_window_table framebuffer_gui_window_table = { +static struct gui_window_table framebuffer_window_table = { .create = gui_window_create, .destroy = gui_window_destroy, .redraw = gui_window_redraw_window, @@ -1787,14 +1787,10 @@ static struct gui_window_table framebuffer_gui_window_table = { .stop_throbber = gui_window_stop_throbber, }; -static struct gui_table framebuffer_gui_table = { +static struct gui_browser_table framebuffer_browser_table = { .poll = gui_poll, .quit = gui_quit, .get_resource_url = gui_get_resource_url, - .get_clipboard = gui_get_clipboard, - .set_clipboard = gui_set_clipboard, - - .window = &framebuffer_gui_window_table, }; /** Entry point from OS. @@ -1812,6 +1808,11 @@ main(int argc, char** argv) nsurl *url; nserror ret; nsfb_t *nsfb; + struct gui_table framebuffer_gui_table = { + .browser = &framebuffer_browser_table, + .window = &framebuffer_window_table, + .clipboard = framebuffer_clipboard_table, + }; respaths = fb_init_resource(NETSURF_FB_RESPATH":"NETSURF_FB_FONTPATH); diff --git a/gtk/download.c b/gtk/download.c index 1eb53403e..3d287d4d2 100644 --- a/gtk/download.c +++ b/gtk/download.c @@ -845,11 +845,11 @@ static void gui_download_window_done(struct gui_download_window *dw) } -static struct gui_download_table gui_download_table = { +static struct gui_download_table download_table = { .create = gui_download_window_create, .data = gui_download_window_data, .error = gui_download_window_error, .done = gui_download_window_done, }; -struct gui_download_table *nsgtk_gui_download_table = &gui_download_table; +struct gui_download_table *nsgtk_download_table = &download_table; diff --git a/gtk/download.h b/gtk/download.h index 393009dc4..a6e624fbd 100644 --- a/gtk/download.h +++ b/gtk/download.h @@ -21,12 +21,12 @@ #include +struct gui_download_table *nsgtk_download_table; + bool nsgtk_download_init(const char *glade_file_location); void nsgtk_download_destroy (void); bool nsgtk_check_for_downloads(GtkWindow *parent); void nsgtk_download_show(GtkWindow *parent); void nsgtk_download_add(gchar *url, gchar *destination); -struct gui_download_table *nsgtk_gui_download_table; - #endif diff --git a/gtk/gui.c b/gtk/gui.c index 9dea700e4..c3ee22850 100644 --- a/gtk/gui.c +++ b/gtk/gui.c @@ -1128,17 +1128,18 @@ bool path_add_part(char *path, int length, const char *newpart) return true; } +static struct gui_clipboard_table nsgtk_clipboard_table = { + .get = gui_get_clipboard, + .set = gui_set_clipboard, +}; - -static struct gui_table nsgtk_gui_table = { +static struct gui_browser_table nsgtk_browser_table = { .poll = gui_poll, .quit = gui_quit, .set_search_ico = gui_set_search_ico, .get_resource_url = gui_get_resource_url, .launch_url = gui_launch_url, .create_form_select_menu = gui_create_form_select_menu, - .get_clipboard = gui_get_clipboard, - .set_clipboard = gui_set_clipboard, .cert_verify = gui_cert_verify, }; @@ -1150,6 +1151,12 @@ int main(int argc, char** argv) char *messages; char *options; nserror ret; + struct gui_table nsgtk_gui_table = { + .browser = &nsgtk_browser_table, + .window = nsgtk_window_table, + .clipboard = &nsgtk_clipboard_table, + .download = nsgtk_download_table, + }; /* check home directory is available */ nsgtk_check_homedir(); @@ -1178,10 +1185,6 @@ int main(int argc, char** argv) /* common initialisation */ messages = filepath_find(respaths, "Messages"); - - nsgtk_gui_table.window = nsgtk_gui_window_table; - nsgtk_gui_table.download = nsgtk_gui_download_table; - ret = netsurf_init(messages, &nsgtk_gui_table); free(messages); if (ret != NSERROR_OK) { diff --git a/gtk/window.c b/gtk/window.c index 8b66be60d..0ba3c5052 100644 --- a/gtk/window.c +++ b/gtk/window.c @@ -1167,7 +1167,7 @@ gui_window_file_gadget_open(struct gui_window *g, gtk_widget_destroy(dialog); } -static struct gui_window_table gui_window_table = { +static struct gui_window_table window_table = { .create = gui_window_create, .destroy = gui_window_destroy, .redraw = gui_window_redraw_window, @@ -1192,4 +1192,4 @@ static struct gui_window_table gui_window_table = { .stop_throbber = gui_window_stop_throbber, }; -struct gui_window_table *nsgtk_gui_window_table = &gui_window_table; +struct gui_window_table *nsgtk_window_table = &window_table; diff --git a/gtk/window.h b/gtk/window.h index b6953a99e..e242b6e7a 100644 --- a/gtk/window.h +++ b/gtk/window.h @@ -23,6 +23,7 @@ #include "desktop/browser.h" #include "gtk/scaffolding.h" +extern struct gui_window_table *nsgtk_window_table; typedef enum nsgtk_window_signals { NSGTK_WINDOW_SIGNAL_CLICK, @@ -32,7 +33,6 @@ typedef enum nsgtk_window_signals { extern struct gui_window *window_list; extern int temp_open_background; -extern struct gui_window_table *nsgtk_gui_window_table; struct browser_window *nsgtk_get_browser_window(struct gui_window *g); nsgtk_scaffolding *nsgtk_get_scaffold(struct gui_window *g); diff --git a/monkey/browser.c b/monkey/browser.c index 97bd0be8b..85e25d9ea 100644 --- a/monkey/browser.c +++ b/monkey/browser.c @@ -503,7 +503,7 @@ monkey_window_handle_command(int argc, char **argv) } -static struct gui_window_table gui_window_table = { +static struct gui_window_table window_table = { .create = gui_window_create, .destroy = gui_window_destroy, .redraw = gui_window_redraw_window, @@ -529,4 +529,4 @@ static struct gui_window_table gui_window_table = { .stop_throbber = gui_window_stop_throbber, }; -struct gui_window_table *monkey_gui_window_table = &gui_window_table; +struct gui_window_table *monkey_window_table = &window_table; diff --git a/monkey/browser.h b/monkey/browser.h index 6c74a412c..959c6a1e6 100644 --- a/monkey/browser.h +++ b/monkey/browser.h @@ -22,6 +22,9 @@ #include "desktop/browser.h" #include "content/hlcache.h" +extern struct gui_window_table *monkey_window_table; +extern struct gui_download_table *monkey_download_table; + struct gui_window { struct gui_window *r_next; struct gui_window *r_prev; @@ -36,9 +39,6 @@ struct gui_window { }; -extern struct gui_window_table *monkey_gui_window_table; -extern struct gui_download_table *monkey_gui_download_table; - struct gui_window *monkey_find_window_by_num(uint32_t win_num); struct gui_window *monkey_find_window_by_content(hlcache_handle *content); void monkey_window_process_reformats(void); diff --git a/monkey/download.c b/monkey/download.c index 46d54dc0c..d2e3b4b24 100644 --- a/monkey/download.c +++ b/monkey/download.c @@ -78,11 +78,11 @@ gui_download_window_done(struct gui_download_window *dw) free(dw); } -static struct gui_download_table gui_download_table = { +static struct gui_download_table download_table = { .create = gui_download_window_create, .data = gui_download_window_data, .error = gui_download_window_error, .done = gui_download_window_done, }; -struct gui_download_table *monkey_gui_download_table = &gui_download_table; +struct gui_download_table *monkey_download_table = &download_table; diff --git a/monkey/main.c b/monkey/main.c index 419543e29..22aaf1e06 100644 --- a/monkey/main.c +++ b/monkey/main.c @@ -114,7 +114,7 @@ static bool nslog_stream_configure(FILE *fptr) return true; } -static struct gui_table monkey_gui_table = { +static struct gui_browser_table monkey_browser_table = { .poll = monkey_poll, .quit = monkey_quit, .get_resource_url = gui_get_resource_url, @@ -129,6 +129,11 @@ main(int argc, char **argv) char *options; char buf[PATH_MAX]; nserror ret; + struct gui_table monkey_gui_table = { + .browser = &monkey_browser_table, + .window = monkey_window_table, + .download = monkey_download_table, + }; /* Unbuffer stdin/out/err */ setbuf(stdin, NULL); @@ -155,10 +160,6 @@ main(int argc, char **argv) /* common initialisation */ messages = filepath_find(respaths, "Messages"); - - monkey_gui_table.window = monkey_gui_window_table; - monkey_gui_table.download = monkey_gui_download_table; - ret = netsurf_init(messages, &monkey_gui_table); free(messages); if (ret != NSERROR_OK) { diff --git a/render/html_interaction.c b/render/html_interaction.c index 0170c8d8d..415e7b1cf 100644 --- a/render/html_interaction.c +++ b/render/html_interaction.c @@ -655,7 +655,7 @@ void html_mouse_action(struct content *c, struct browser_window *bw, c); pointer = BROWSER_POINTER_DEFAULT; } else if (mouse & BROWSER_MOUSE_CLICK_1) - guit->create_form_select_menu(bw, gadget); + guit->browser->create_form_select_menu(bw, gadget); break; case GADGET_CHECKBOX: status = messages_get("FormCheckbox"); diff --git a/riscos/download.c b/riscos/download.c index aeeeeffbd..3a02c9c90 100644 --- a/riscos/download.c +++ b/riscos/download.c @@ -1632,11 +1632,11 @@ bool ro_gui_download_prequit(void) return true; } -static struct gui_download_table gui_download_table = { +static struct gui_download_table download_table = { .create = gui_download_window_create, .data = gui_download_window_data, .error = gui_download_window_error, .done = gui_download_window_done, }; -struct gui_download_table *riscos_gui_download_table = &gui_download_table; +struct gui_download_table *riscos_download_table = &download_table; diff --git a/riscos/gui.c b/riscos/gui.c index ccf07e5d9..50c1bdf62 100644 --- a/riscos/gui.c +++ b/riscos/gui.c @@ -2348,14 +2348,17 @@ bool path_add_part(char *path, int length, const char *newpart) return true; } -static struct gui_table riscos_gui_table = { +static struct gui_clipboard_table riscos_clipboard_table = { + .get = gui_get_clipboard, + .set = gui_set_clipboard, +}; + +static struct gui_browser_table riscos_browser_table = { .poll = gui_poll, .quit = gui_quit, .get_resource_url = gui_get_resource_url, .launch_url = gui_launch_url, .create_form_select_menu = gui_create_form_select_menu, - .get_clipboard = gui_get_clipboard, - .set_clipboard = gui_set_clipboard, .cert_verify = gui_cert_verify, }; @@ -2370,6 +2373,12 @@ int main(int argc, char** argv) int used = -1; /* slightly better with older OSLib versions */ os_error *error; nserror ret; + struct gui_table riscos_gui_table = { + .browser = &riscos_browser_table, + .window = riscos_window_table, + .clipboard = &riscos_clipboard_table, + .download = riscos_download_table, + }; /* Consult NetSurf$Logging environment variable to decide if logging * is required. */ @@ -2414,9 +2423,6 @@ int main(int argc, char** argv) } /* common initialisation */ - riscos_gui_table.window = riscos_gui_window_table; - riscos_gui_table.download = riscos_gui_download_table; - ret = netsurf_init(path, &riscos_gui_table); if (ret != NSERROR_OK) { die("NetSurf failed to initialise"); diff --git a/riscos/gui.h b/riscos/gui.h index 9fbc2eb28..b45bd472c 100644 --- a/riscos/gui.h +++ b/riscos/gui.h @@ -123,7 +123,7 @@ const char *ro_gui_default_language(void); void ro_gui_download_init(void); void ro_gui_download_datasave_ack(wimp_message *message); bool ro_gui_download_prequit(void); -extern struct gui_download_table *riscos_gui_download_table; +extern struct gui_download_table *riscos_download_table; /* in 401login.c */ void ro_gui_401login_init(void); diff --git a/windows/download.c b/windows/download.c index 5bf9798aa..189baa819 100644 --- a/windows/download.c +++ b/windows/download.c @@ -296,12 +296,12 @@ static void gui_download_window_done(struct gui_download_window *w) nsws_download_clear_data(w); } -static struct gui_download_table gui_download_table = { +static struct gui_download_table download_table = { .create = gui_download_window_create, .data = gui_download_window_data, .error = gui_download_window_error, .done = gui_download_window_done, }; -struct gui_download_table *win32_gui_download_table = &gui_download_table; +struct gui_download_table *win32_download_table = &download_table; diff --git a/windows/download.h b/windows/download.h index c1b13bf65..a53fab89f 100644 --- a/windows/download.h +++ b/windows/download.h @@ -23,6 +23,8 @@ #include #include "desktop/gui.h" +struct gui_download_table *win32_download_table; + typedef enum { DOWNLOAD_NONE, DOWNLOAD_WORKING, @@ -60,6 +62,4 @@ struct gui_download_window { void nsws_download_window_init(struct gui_window *); -struct gui_download_table *win32_gui_download_table; - #endif diff --git a/windows/gui.c b/windows/gui.c index fc0af679e..fa748254c 100644 --- a/windows/gui.c +++ b/windows/gui.c @@ -1809,7 +1809,7 @@ nsws_create_main_class(HINSTANCE hinstance) { return ret; } -static struct gui_window_table win32_window_table = { +static struct gui_window_table window_table = { .create = gui_window_create, .destroy = gui_window_destroy, .redraw = gui_window_redraw_window, @@ -1829,12 +1829,17 @@ static struct gui_window_table win32_window_table = { .stop_throbber = gui_window_stop_throbber, }; -static struct gui_table gui_table = { - .poll = gui_poll, - .get_clipboard = gui_get_clipboard, - .set_clipboard = gui_set_clipboard, +struct gui_window_table *win32_window_table = &window_table; - .window = &win32_window_table, +static struct gui_clipboard_table clipboard_table = { + .get = gui_get_clipboard, + .set = gui_set_clipboard, }; -struct gui_table *win32_gui_table = &gui_table; +struct gui_clipboard_table *win32_clipboard_table = &clipboard_table; + +static struct gui_table browser_table = { + .poll = gui_poll, +}; + +struct gui_browser_table *win32_browser_table = &browser_table; diff --git a/windows/gui.h b/windows/gui.h index 29c7f8485..3372dcc21 100644 --- a/windows/gui.h +++ b/windows/gui.h @@ -24,7 +24,9 @@ #include "desktop/gui.h" #include "windows/localhistory.h" -extern struct gui_table *win32_gui_table; +extern struct gui_window_table *win32_window_table; +extern struct gui_clipboard_table *win32_clipboard_table; +extern struct gui_browser_table *win32_browser_table; extern HINSTANCE hInstance; diff --git a/windows/main.c b/windows/main.c index 997d98120..638db6c5c 100644 --- a/windows/main.c +++ b/windows/main.c @@ -104,6 +104,13 @@ WinMain(HINSTANCE hInstance, HINSTANCE hLastInstance, LPSTR lpcli, int ncmd) const char *addr; nsurl *url; nserror error; + struct gui_table win32_gui_table = { + .browser = win32_browser_table, + .window = win32_window_table, + .clipboard = win32_clipboard_table, + .download = win32_download_table, + }; + win32_gui_table->browser->get_resource_url = get_resource_url; if (SLEN(lpcli) > 0) { argvw = CommandLineToArgvW(GetCommandLineW(), &argc); @@ -150,11 +157,7 @@ WinMain(HINSTANCE hInstance, HINSTANCE hLastInstance, LPSTR lpcli, int ncmd) /* common initialisation */ messages = filepath_find(respaths, "messages"); - - win32_gui_table->download = nsgtk_gui_download_table; - win32_gui_table->get_resource_url = get_resource_url; - - ret = netsurf_init(messages, win32_gui_table); + ret = netsurf_init(messages, &win32_gui_table); free(messages); if (ret != NSERROR_OK) { free(options_file_location); From 38cb39339a8f1f9a0afb69340a404fd767db5a79 Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Thu, 16 Jan 2014 00:01:25 +0000 Subject: [PATCH 090/773] move filename_from_path and path_add_part into gui operation tables --- amiga/gui.c | 29 +++++++++++++++++++++++++++++ amiga/misc.c | 27 --------------------------- atari/gui.c | 23 +++++++++++++++++++++++ atari/misc.c | 22 ---------------------- atari/misc.h | 2 ++ beos/gui.cpp | 7 ++++--- cocoa/gui.m | 16 ++++++++++++++++ cocoa/utils.m | 13 ------------- content/fetchers/curl.c | 3 ++- content/fetchers/file.c | 3 ++- desktop/gui.h | 18 ++++++++++++++++++ desktop/gui_factory.c | 7 +++++++ desktop/gui_factory.h | 2 +- desktop/save_complete.c | 7 ++++--- framebuffer/gui.c | 39 +++++++++++++++++++++++++++++++++++++++ framebuffer/misc.c | 37 ------------------------------------- gtk/gui.c | 6 ++++-- monkey/main.c | 41 +++++++++++++++++++++++++++++++++++++++++ monkey/utils.c | 38 -------------------------------------- riscos/gui.c | 6 ++++-- utils/utils.h | 3 +-- windows/gui.c | 39 +++++++++++++++++++++++++++++++++++++++ windows/misc.c | 38 -------------------------------------- 23 files changed, 236 insertions(+), 190 deletions(-) diff --git a/amiga/gui.c b/amiga/gui.c index 27e747a05..d651ef11e 100644 --- a/amiga/gui.c +++ b/amiga/gui.c @@ -209,6 +209,33 @@ static void gui_window_set_scroll(struct gui_window *g, int sx, int sy); nsoptions[NSOPTION_##OPTION].value.i = VALUE; \ nsoptions_default[NSOPTION_##OPTION].value.i = VALUE +/** + * Return the filename part of a full path + * + * \param path full path and filename + * \return filename (will be freed with free()) + */ + +static char *filename_from_path(char *path) +{ + return strdup(FilePart(path)); +} + +/** + * Add a path component/filename to an existing path + * + * \param path buffer containing path + free space + * \param length length of buffer "path" + * \param newpart string containing path component to add to path + * \return true on success + */ + +static bool path_add_part(char *path, int length, const char *newpart) +{ + if(AddPart(path, newpart, length)) return true; + else return false; +} + STRPTR ami_locale_langs(void) { struct Locale *locale; @@ -5130,6 +5157,8 @@ static struct gui_browser_table amiga_browser_table = { .launch_url = gui_launch_url, .create_form_select_menu = gui_create_form_select_menu, .cert_verify = gui_cert_verify, + .filename_from_path = filename_from_path, + .path_add_part = path_add_part, }; /** Normal entry point from OS */ diff --git a/amiga/misc.c b/amiga/misc.c index 003a5fb6e..ac9d2453e 100755 --- a/amiga/misc.c +++ b/amiga/misc.c @@ -172,33 +172,6 @@ char *path_to_url(const char *path) return r; } -/** - * Return the filename part of a full path - * - * \param path full path and filename - * \return filename (will be freed with free()) - */ - -char *filename_from_path(char *path) -{ - return strdup(FilePart(path)); -} - -/** - * Add a path component/filename to an existing path - * - * \param path buffer containing path + free space - * \param length length of buffer "path" - * \param newpart string containing path component to add to path - * \return true on success - */ - -bool path_add_part(char *path, int length, const char *newpart) -{ - if(AddPart(path, newpart, length)) return true; - else return false; -} - /** * returns a string with escape chars translated. * (based on remove_underscores from utils.c) diff --git a/atari/gui.c b/atari/gui.c index 49e3046e2..55a23a84a 100644 --- a/atari/gui.c +++ b/atari/gui.c @@ -115,6 +115,27 @@ short aes_msg_out[8]; bool gui_window_get_scroll(struct gui_window *w, int *sx, int *sy); +/** + * Return the filename part of a full path + * + * \param path full path and filename + * \return filename (will be freed with free()) + */ +static char *filename_from_path(char *path) +{ + char *leafname; + + leafname = strrchr(path, '\\'); + if( !leafname ) + leafname = strrchr(path, '/'); + if (!leafname) + leafname = path; + else + leafname += 1; + + return strdup(leafname); +} + static void gui_poll(bool active) { @@ -1055,6 +1076,8 @@ static struct gui_browser_table atari_browser_table = { .quit = gui_quit, .get_resource_url = gui_get_resource_url, .cert_verify = gui_cert_verify, + .filename_from_path = filename_from_path, + .path_add_part = path_add_part, }; /* #define WITH_DBG_LOGFILE 1 */ diff --git a/atari/misc.c b/atari/misc.c index d330859b9..ca9e993d9 100755 --- a/atari/misc.c +++ b/atari/misc.c @@ -70,28 +70,6 @@ void die(const char *error) exit(1); } -/** - * Return the filename part of a full path - * - * \param path full path and filename - * \return filename (will be freed with free()) - */ - -char *filename_from_path(char *path) -{ - char *leafname; - - leafname = strrchr(path, '\\'); - if( !leafname ) - leafname = strrchr(path, '/'); - if (!leafname) - leafname = path; - else - leafname += 1; - - return strdup(leafname); -} - /** * Add a path component/filename to an existing path * diff --git a/atari/misc.h b/atari/misc.h index 8d1719ce8..1bb5e8131 100755 --- a/atari/misc.h +++ b/atari/misc.h @@ -66,4 +66,6 @@ const char * file_select(const char * title, const char * name); */ long nkc_to_input_key(short nkc, long * ucs4_out); +bool path_add_part(char *path, int length, const char *newpart); + #endif diff --git a/beos/gui.cpp b/beos/gui.cpp index 3ee47c9e9..3600e85d0 100644 --- a/beos/gui.cpp +++ b/beos/gui.cpp @@ -1027,7 +1027,7 @@ static void *myrealloc(void *ptr, size_t len, void *pw) * \return filename (will be freed with free()) */ -char *filename_from_path(char *path) +static char *filename_from_path(char *path) { char *leafname; @@ -1049,7 +1049,7 @@ char *filename_from_path(char *path) * \return true on success */ -bool path_add_part(char *path, int length, const char *newpart) +static bool path_add_part(char *path, int length, const char *newpart) { if(path[strlen(path) - 1] != '/') strncat(path, "/", length); @@ -1067,9 +1067,10 @@ static struct gui_clipboard_table beos_clipboard_table = { static struct gui_browser_table beos_browser_table = { .poll = gui_poll, .quit = gui_quit, - .get_resource_url = gui_get_resource_url, .launch_url = gui_launch_url, + .filename_from_path = filename_from_path, + .path_add_part = path_add_part, }; diff --git a/cocoa/gui.m b/cocoa/gui.m index c2cadfe5a..f9cb2e4c7 100644 --- a/cocoa/gui.m +++ b/cocoa/gui.m @@ -281,6 +281,20 @@ void gui_401login_open(nsurl *url, const char *realm, cb( false, cbpw ); } +static char *filename_from_path(char *path) +{ + return strdup( [[[NSString stringWithUTF8String: path] lastPathComponent] UTF8String] ); +} + +static bool path_add_part(char *path, int length, const char *newpart) +{ + NSString *newPath = [[NSString stringWithUTF8String: path] stringByAppendingPathComponent: [NSString stringWithUTF8String: newpart]]; + + strncpy( path, [newPath UTF8String], length ); + + return true; +} + static struct gui_window_table window_table = { .create = gui_window_create, @@ -321,6 +335,8 @@ static struct gui_browser_table browser_table = { .launch_url = gui_launch_url, .create_form_select_menu = gui_create_form_select_menu, .cert_verify = gui_cert_verify, + .filename_from_path = filename_from_path, + .path_add_part = path_add_part, }; struct gui_browser_table *cocoa_browser_table = &browser_table; diff --git a/cocoa/utils.m b/cocoa/utils.m index cd9313d34..61226ad2a 100644 --- a/cocoa/utils.m +++ b/cocoa/utils.m @@ -41,16 +41,3 @@ void PDF_Password(char **owner_pass, char **user_pass, char *path) UNIMPL(); } -char *filename_from_path(char *path) -{ - return strdup( [[[NSString stringWithUTF8String: path] lastPathComponent] UTF8String] ); -} - -bool path_add_part(char *path, int length, const char *newpart) -{ - NSString *newPath = [[NSString stringWithUTF8String: path] stringByAppendingPathComponent: [NSString stringWithUTF8String: newpart]]; - - strncpy( path, [newPath UTF8String], length ); - - return true; -} diff --git a/content/fetchers/curl.c b/content/fetchers/curl.c index 7578ad4cb..92d4625b5 100644 --- a/content/fetchers/curl.c +++ b/content/fetchers/curl.c @@ -45,6 +45,7 @@ #include "content/fetchers/curl.h" #include "content/urldb.h" #include "desktop/netsurf.h" +#include "desktop/gui_factory.h" #include "utils/nsoption.h" #include "utils/log.h" #include "utils/messages.h" @@ -1268,7 +1269,7 @@ fetch_curl_post_convert(const struct fetch_multipart_data *control) if (control->file) { char *leafname = 0; - leafname = filename_from_path(control->value); + leafname = guit->browser->filename_from_path(control->value); if (leafname == NULL) continue; diff --git a/content/fetchers/file.c b/content/fetchers/file.c index c574c2160..26ef9069b 100644 --- a/content/fetchers/file.c +++ b/content/fetchers/file.c @@ -47,6 +47,7 @@ #include "content/fetchers/file.h" #include "content/urldb.h" #include "desktop/netsurf.h" +#include "desktop/gui_factory.h" #include "utils/nsoption.h" #include "utils/errors.h" #include "utils/log.h" @@ -574,7 +575,7 @@ static void fetch_file_process_dir(struct fetch_file_context *ctx, continue; strncpy(urlpath, ctx->path, sizeof urlpath); - if (path_add_part(urlpath, sizeof urlpath, + if (guit->browser->path_add_part(urlpath, sizeof urlpath, ent->d_name) == false) continue; diff --git a/desktop/gui.h b/desktop/gui.h index 686bb59d4..102aade45 100644 --- a/desktop/gui.h +++ b/desktop/gui.h @@ -344,6 +344,24 @@ struct gui_browser_table { */ void (*cert_verify)(nsurl *url, const struct ssl_cert_info *certs, unsigned long num, nserror (*cb)(bool proceed, void *pw), void *cbpw); + /** + * Return the filename part of a full path + * + * \param path full path and filename + * \return filename (will be freed with free()) + */ + char *(*filename_from_path)(char *path); + + /** + * Add a path component/filename to an existing path + * + * \param path buffer containing path + free space + * \param length length of buffer "path" + * \param newpart string containing path component to add to path + * \return true on success + */ + bool (*path_add_part)(char *path, int length, const char *newpart); + }; diff --git a/desktop/gui_factory.c b/desktop/gui_factory.c index f47b73007..cd5031b0d 100644 --- a/desktop/gui_factory.c +++ b/desktop/gui_factory.c @@ -316,6 +316,13 @@ static nserror verify_browser_register(struct gui_browser_table *gbt) if (gbt->poll == NULL) { return NSERROR_BAD_PARAMETER; } + if (gbt->filename_from_path == NULL) { + return NSERROR_BAD_PARAMETER; + } + if (gbt->path_add_part == NULL) { + return NSERROR_BAD_PARAMETER; + } + /* fill in the optional entries with defaults */ if (gbt->quit == NULL) { diff --git a/desktop/gui_factory.h b/desktop/gui_factory.h index c70ca8f37..50b5eb31e 100644 --- a/desktop/gui_factory.h +++ b/desktop/gui_factory.h @@ -23,7 +23,7 @@ #ifndef _NETSURF_DESKTOP_GUI_FACTORY_H_ #define _NETSURF_DESKTOP_GUI_FACTORY_H_ -struct gui_table; +#include "desktop/gui.h" extern struct gui_table *guit; /* the gui vtable */ diff --git a/desktop/save_complete.c b/desktop/save_complete.c index 3e5234af4..bd2ed4dea 100644 --- a/desktop/save_complete.c +++ b/desktop/save_complete.c @@ -37,6 +37,7 @@ #include "content/hlcache.h" #include "css/css.h" #include "desktop/save_complete.h" +#include "desktop/gui_factory.h" #include "render/box.h" #include "render/html.h" #include "utils/corestrings.h" @@ -147,7 +148,7 @@ static bool save_complete_save_buffer(save_complete_ctx *ctx, char fullpath[PATH_MAX]; strncpy(fullpath, ctx->path, sizeof fullpath); - error = path_add_part(fullpath, sizeof fullpath, leafname); + error = guit->browser->path_add_part(fullpath, sizeof fullpath, leafname); if (error == false) { warn_user("NoMemory", NULL); return false; @@ -1048,7 +1049,7 @@ static bool save_complete_save_html_document(save_complete_ctx *ctx, else snprintf(filename, sizeof filename, "%p", c); - error = path_add_part(fullpath, sizeof fullpath, filename); + error = guit->browser->path_add_part(fullpath, sizeof fullpath, filename); if (error == false) { warn_user("NoMemory", NULL); return false; @@ -1125,7 +1126,7 @@ static bool save_complete_inventory(save_complete_ctx *ctx) char fullpath[PATH_MAX]; strncpy(fullpath, ctx->path, sizeof fullpath); - error = path_add_part(fullpath, sizeof fullpath, "Inventory"); + error = guit->browser->path_add_part(fullpath, sizeof fullpath, "Inventory"); if (error == false) { warn_user("NoMemory", NULL); return false; diff --git a/framebuffer/gui.c b/framebuffer/gui.c index b2edc030a..76ed397d3 100644 --- a/framebuffer/gui.c +++ b/framebuffer/gui.c @@ -1767,6 +1767,43 @@ gui_window_remove_caret(struct gui_window *g) } } +/** + * Return the filename part of a full path + * + * \param path full path and filename + * \return filename (will be freed with free()) + */ +static char *filename_from_path(char *path) +{ + char *leafname; + + leafname = strrchr(path, '/'); + if (!leafname) + leafname = path; + else + leafname += 1; + + return strdup(leafname); +} + +/** + * Add a path component/filename to an existing path + * + * \param path buffer containing path + free space + * \param length length of buffer "path" + * \param newpart string containing path component to add to path + * \return true on success + */ + +static bool path_add_part(char *path, int length, const char *newpart) +{ + if(path[strlen(path) - 1] != '/') + strncat(path, "/", length); + + strncat(path, newpart, length); + + return true; +} static struct gui_window_table framebuffer_window_table = { .create = gui_window_create, @@ -1791,6 +1828,8 @@ static struct gui_browser_table framebuffer_browser_table = { .poll = gui_poll, .quit = gui_quit, .get_resource_url = gui_get_resource_url, + .filename_from_path = filename_from_path, + .path_add_part = path_add_part, }; /** Entry point from OS. diff --git a/framebuffer/misc.c b/framebuffer/misc.c index 2dd03677d..f5ad045a0 100644 --- a/framebuffer/misc.c +++ b/framebuffer/misc.c @@ -37,40 +37,3 @@ void die(const char *error) exit(1); } -/** - * Return the filename part of a full path - * - * \param path full path and filename - * \return filename (will be freed with free()) - */ -char *filename_from_path(char *path) -{ - char *leafname; - - leafname = strrchr(path, '/'); - if (!leafname) - leafname = path; - else - leafname += 1; - - return strdup(leafname); -} - -/** - * Add a path component/filename to an existing path - * - * \param path buffer containing path + free space - * \param length length of buffer "path" - * \param newpart string containing path component to add to path - * \return true on success - */ - -bool path_add_part(char *path, int length, const char *newpart) -{ - if(path[strlen(path) - 1] != '/') - strncat(path, "/", length); - - strncat(path, newpart, length); - - return true; -} diff --git a/gtk/gui.c b/gtk/gui.c index c3ee22850..1028528ed 100644 --- a/gtk/gui.c +++ b/gtk/gui.c @@ -1096,7 +1096,7 @@ uint32_t gtk_gui_gdkkey_to_nskey(GdkEventKey *key) * \return filename (will be freed with free()) */ -char *filename_from_path(char *path) +static char *filename_from_path(char *path) { char *leafname; @@ -1118,7 +1118,7 @@ char *filename_from_path(char *path) * \return true on success */ -bool path_add_part(char *path, int length, const char *newpart) +static bool path_add_part(char *path, int length, const char *newpart) { if(path[strlen(path) - 1] != '/') strncat(path, "/", length); @@ -1141,6 +1141,8 @@ static struct gui_browser_table nsgtk_browser_table = { .launch_url = gui_launch_url, .create_form_select_menu = gui_create_form_select_menu, .cert_verify = gui_cert_verify, + .filename_from_path = filename_from_path, + .path_add_part = path_add_part, }; /** diff --git a/monkey/main.c b/monkey/main.c index 22aaf1e06..1922393a8 100644 --- a/monkey/main.c +++ b/monkey/main.c @@ -114,12 +114,53 @@ static bool nslog_stream_configure(FILE *fptr) return true; } +/** + * Return the filename part of a full path + * + * \param path full path and filename + * \return filename (will be freed with free()) + */ + +static char *filename_from_path(char *path) +{ + char *leafname; + + leafname = strrchr(path, '/'); + if (!leafname) + leafname = path; + else + leafname += 1; + + return strdup(leafname); +} + +/** + * Add a path component/filename to an existing path + * + * \param path buffer containing path + free space + * \param length length of buffer "path" + * \param newpart string containing path component to add to path + * \return true on success + */ + +static bool path_add_part(char *path, int length, const char *newpart) +{ + if(path[strlen(path) - 1] != '/') + strncat(path, "/", length); + + strncat(path, newpart, length); + + return true; +} + static struct gui_browser_table monkey_browser_table = { .poll = monkey_poll, .quit = monkey_quit, .get_resource_url = gui_get_resource_url, .launch_url = gui_launch_url, .cert_verify = gui_cert_verify, + .filename_from_path = filename_from_path, + .path_add_part = path_add_part, }; int diff --git a/monkey/utils.c b/monkey/utils.c index 3e09106f7..aa7245533 100644 --- a/monkey/utils.c +++ b/monkey/utils.c @@ -70,44 +70,6 @@ char *url_to_path(const char *url) return respath; } -/** - * Return the filename part of a full path - * - * \param path full path and filename - * \return filename (will be freed with free()) - */ - -char *filename_from_path(char *path) -{ - char *leafname; - - leafname = strrchr(path, '/'); - if (!leafname) - leafname = path; - else - leafname += 1; - - return strdup(leafname); -} - -/** - * Add a path component/filename to an existing path - * - * \param path buffer containing path + free space - * \param length length of buffer "path" - * \param newpart string containing path component to add to path - * \return true on success - */ - -bool path_add_part(char *path, int length, const char *newpart) -{ - if(path[strlen(path) - 1] != '/') - strncat(path, "/", length); - - strncat(path, newpart, length); - - return true; -} void warn_user(const char *warning, const char *detail) { diff --git a/riscos/gui.c b/riscos/gui.c index 50c1bdf62..c780abfcf 100644 --- a/riscos/gui.c +++ b/riscos/gui.c @@ -2288,7 +2288,7 @@ void PDF_Password(char **owner_pass, char **user_pass, char *path) * \return filename (will be freed with free()) */ -char *filename_from_path(char *path) +static char *filename_from_path(char *path) { char *leafname; char *temp; @@ -2326,7 +2326,7 @@ char *filename_from_path(char *path) * \return true on success */ -bool path_add_part(char *path, int length, const char *newpart) +static bool path_add_part(char *path, int length, const char *newpart) { size_t path_len = strlen(path); @@ -2360,6 +2360,8 @@ static struct gui_browser_table riscos_browser_table = { .launch_url = gui_launch_url, .create_form_select_menu = gui_create_form_select_menu, .cert_verify = gui_cert_verify, + .filename_from_path = filename_from_path, + .path_add_part = path_add_part, }; diff --git a/utils/utils.h b/utils/utils.h index f2241ae07..e3b3647ea 100644 --- a/utils/utils.h +++ b/utils/utils.h @@ -188,6 +188,5 @@ query_id query_user(const char *query, const char *detail, const query_callback *cb, void *pw, const char *yes, const char *no); void query_close(query_id); void PDF_Password(char **owner_pass, char **user_pass, char *path); -char *filename_from_path(char *path); -bool path_add_part(char *path, int length, const char *newpart); + #endif diff --git a/windows/gui.c b/windows/gui.c index fa748254c..40124671d 100644 --- a/windows/gui.c +++ b/windows/gui.c @@ -1809,6 +1809,43 @@ nsws_create_main_class(HINSTANCE hinstance) { return ret; } +/** + * Return the filename part of a full path + * + * \param path full path and filename + * \return filename (will be freed with free()) + */ +static char *filename_from_path(char *path) +{ + char *leafname; + + leafname = strrchr(path, '\\'); + if (!leafname) + leafname = path; + else + leafname += 1; + + return strdup(leafname); +} + +/** + * Add a path component/filename to an existing path + * + * \param path buffer containing path + free space + * \param length length of buffer "path" + * \param newpart string containing path component to add to path + * \return true on success + */ +static bool path_add_part(char *path, int length, const char *newpart) +{ + if(path[strlen(path) - 1] != '\\') + strncat(path, "\\", length); + + strncat(path, newpart, length); + + return true; +} + static struct gui_window_table window_table = { .create = gui_window_create, .destroy = gui_window_destroy, @@ -1840,6 +1877,8 @@ struct gui_clipboard_table *win32_clipboard_table = &clipboard_table; static struct gui_table browser_table = { .poll = gui_poll, + .filename_from_path = filename_from_path, + .path_add_part = path_add_part, }; struct gui_browser_table *win32_browser_table = &browser_table; diff --git a/windows/misc.c b/windows/misc.c index d820a5bca..b60eb512c 100644 --- a/windows/misc.c +++ b/windows/misc.c @@ -43,41 +43,3 @@ void die(const char *error) exit(1); } -/** - * Return the filename part of a full path - * - * \param path full path and filename - * \return filename (will be freed with free()) - */ - -char *filename_from_path(char *path) -{ - char *leafname; - - leafname = strrchr(path, '\\'); - if (!leafname) - leafname = path; - else - leafname += 1; - - return strdup(leafname); -} - -/** - * Add a path component/filename to an existing path - * - * \param path buffer containing path + free space - * \param length length of buffer "path" - * \param newpart string containing path component to add to path - * \return true on success - */ - -bool path_add_part(char *path, int length, const char *newpart) -{ - if(path[strlen(path) - 1] != '\\') - strncat(path, "\\", length); - - strncat(path, newpart, length); - - return true; -} From d47fed45245ddcecfb69d1e951ce627bdb6a44ff Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Thu, 16 Jan 2014 00:52:17 +0000 Subject: [PATCH 091/773] move 401 login into operation table --- amiga/gui.c | 1 + amiga/login.c | 1 - amiga/login.h | 4 ++++ atari/gui.c | 4 ++-- atari/login.c | 3 +-- beos/gui.cpp | 2 +- beos/gui.h | 3 +++ beos/login.cpp | 1 - cocoa/gui.m | 8 -------- desktop/401login.h | 31 ------------------------------- desktop/browser.c | 1 - desktop/gui.h | 35 ++++++++++++++++++++--------------- desktop/gui_factory.c | 9 +++++++++ desktop/netsurf.c | 4 +--- framebuffer/Makefile.target | 2 +- framebuffer/login.c | 25 ------------------------- gtk/gui.c | 1 + gtk/gui.h | 6 +++++- gtk/login.c | 1 - monkey/401login.c | 3 ++- monkey/401login.h | 9 +++++++++ monkey/main.c | 2 ++ riscos/401login.c | 1 - riscos/gui.c | 1 + riscos/gui.h | 2 ++ utils/utils.h | 4 +++- windows/Makefile.target | 2 +- windows/login.c | 25 ------------------------- 28 files changed, 69 insertions(+), 122 deletions(-) delete mode 100644 desktop/401login.h delete mode 100644 framebuffer/login.c create mode 100644 monkey/401login.h delete mode 100644 windows/login.c diff --git a/amiga/gui.c b/amiga/gui.c index d651ef11e..ad172207b 100644 --- a/amiga/gui.c +++ b/amiga/gui.c @@ -5159,6 +5159,7 @@ static struct gui_browser_table amiga_browser_table = { .cert_verify = gui_cert_verify, .filename_from_path = filename_from_path, .path_add_part = path_add_part, + .login = gui_401login_open, }; /** Normal entry point from OS */ diff --git a/amiga/login.c b/amiga/login.c index 816ece675..05d5d2470 100755 --- a/amiga/login.c +++ b/amiga/login.c @@ -16,7 +16,6 @@ * along with this program. If not, see . */ -#include "desktop/401login.h" #include "amiga/os3support.h" #include "amiga/gui.h" #include "amiga/object.h" diff --git a/amiga/login.h b/amiga/login.h index 2ad5d8bdc..e3f77901f 100755 --- a/amiga/login.h +++ b/amiga/login.h @@ -24,4 +24,8 @@ struct gui_login_window; BOOL ami_401login_event(struct gui_login_window *lw); + +void gui_401login_open(nsurl *url, const char *realm, + nserror (*cb)(bool proceed, void *pw), void *cbpw); + #endif diff --git a/atari/gui.c b/atari/gui.c index 55a23a84a..95cfe55ed 100644 --- a/atari/gui.c +++ b/atari/gui.c @@ -38,7 +38,6 @@ #include "desktop/local_history.h" #include "desktop/plotters.h" #include "desktop/netsurf.h" -#include "desktop/401login.h" #include "utils/nsoption.h" #include "desktop/save_complete.h" @@ -742,7 +741,7 @@ static void gui_set_clipboard(const char *buffer, size_t length, } } -void gui_401login_open(nsurl *url, const char *realm, +static void gui_401login_open(nsurl *url, const char *realm, nserror (*cb)(bool proceed, void *pw), void *cbpw) { bool bres; @@ -1078,6 +1077,7 @@ static struct gui_browser_table atari_browser_table = { .cert_verify = gui_cert_verify, .filename_from_path = filename_from_path, .path_add_part = path_add_part, + .login = gui_401login_open, }; /* #define WITH_DBG_LOGFILE 1 */ diff --git a/atari/login.c b/atari/login.c index 461a2f985..81636aebb 100755 --- a/atari/login.c +++ b/atari/login.c @@ -16,18 +16,17 @@ * along with this program. If not, see . */ -#include "desktop/401login.h" #include #include #include #include #include + #include "utils/config.h" #include "content/content.h" #include "content/hlcache.h" #include "content/urldb.h" #include "desktop/browser.h" -#include "desktop/401login.h" #include "desktop/gui.h" #include "utils/errors.h" #include "utils/utils.h" diff --git a/beos/gui.cpp b/beos/gui.cpp index 3600e85d0..4a6475894 100644 --- a/beos/gui.cpp +++ b/beos/gui.cpp @@ -49,7 +49,6 @@ extern "C" { #include "content/fetchers/curl.h" #include "content/fetchers/resource.h" #include "content/urldb.h" -#include "desktop/401login.h" #include "desktop/browser_private.h" #include "desktop/gui.h" #include "desktop/netsurf.h" @@ -1071,6 +1070,7 @@ static struct gui_browser_table beos_browser_table = { .launch_url = gui_launch_url, .filename_from_path = filename_from_path, .path_add_part = path_add_part, + .login = gui_401login_open, }; diff --git a/beos/gui.h b/beos/gui.h index b9d66320c..ea1a8ad3a 100644 --- a/beos/gui.h +++ b/beos/gui.h @@ -32,6 +32,9 @@ extern bool replicated; int gui_init_replicant(int argc, char** argv); +extern "C" void gui_401login_open(nsurl *url, const char *realm, + nserror (*cb)(bool proceed, void *pw), void *cbpw); + extern char *options_file_location; diff --git a/beos/login.cpp b/beos/login.cpp index 90cadde7b..5cd7a3c83 100644 --- a/beos/login.cpp +++ b/beos/login.cpp @@ -31,7 +31,6 @@ extern "C" { #include "content/content.h" #include "content/urldb.h" #include "desktop/browser.h" -#include "desktop/401login.h" #include "desktop/gui.h" #include "utils/messages.h" #include "utils/url.h" diff --git a/cocoa/gui.m b/cocoa/gui.m index f9cb2e4c7..a49ea9ea2 100644 --- a/cocoa/gui.m +++ b/cocoa/gui.m @@ -31,7 +31,6 @@ #import "desktop/browser_private.h" #import "utils/nsoption.h" #import "desktop/textinput.h" -#import "desktop/401login.h" #import "utils/utils.h" #import "utils/log.h" #import "image/ico.h" @@ -274,13 +273,6 @@ static void gui_cert_verify(nsurl *url, const struct ssl_cert_info *certs, cb( false, cbpw ); } - -void gui_401login_open(nsurl *url, const char *realm, - nserror (*cb)(bool proceed, void *pw), void *cbpw) -{ - cb( false, cbpw ); -} - static char *filename_from_path(char *path) { return strdup( [[[NSString stringWithUTF8String: path] lastPathComponent] UTF8String] ); diff --git a/desktop/401login.h b/desktop/401login.h deleted file mode 100644 index 1c8140bae..000000000 --- a/desktop/401login.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2003 John M Bell - * - * This file is part of NetSurf, http://www.netsurf-browser.org/ - * - * NetSurf is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License. - * - * NetSurf is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef NETSURF_DESKTOP_401LOGIN_H -#define NETSURF_DESKTOP_401LOGIN_H - -#include - -#include "utils/config.h" -#include "utils/nsurl.h" -#include "utils/errors.h" - -void gui_401login_open(nsurl *url, const char *realm, - nserror (*cb)(bool proceed, void *pw), void *cbpw); - -#endif diff --git a/desktop/browser.c b/desktop/browser.c index d65033097..f66e27576 100644 --- a/desktop/browser.c +++ b/desktop/browser.c @@ -41,7 +41,6 @@ #include "content/fetch.h" #include "content/hlcache.h" #include "content/urldb.h" -#include "desktop/401login.h" #include "desktop/browser_private.h" #include "desktop/download.h" #include "desktop/frames.h" diff --git a/desktop/gui.h b/desktop/gui.h index 102aade45..cd116e9c1 100644 --- a/desktop/gui.h +++ b/desktop/gui.h @@ -301,6 +301,23 @@ struct gui_browser_table { */ void (*poll)(bool active); + /** + * Return the filename part of a full path + * + * \param path full path and filename + * \return filename (will be freed with free()) + */ + char *(*filename_from_path)(char *path); + + /** + * Add a path component/filename to an existing path + * + * \param path buffer containing path + free space + * \param length length of buffer "path" + * \param newpart string containing path component to add to path + * \return true on success + */ + bool (*path_add_part)(char *path, int length, const char *newpart); /* Optional entries */ @@ -345,22 +362,10 @@ struct gui_browser_table { void (*cert_verify)(nsurl *url, const struct ssl_cert_info *certs, unsigned long num, nserror (*cb)(bool proceed, void *pw), void *cbpw); /** - * Return the filename part of a full path - * - * \param path full path and filename - * \return filename (will be freed with free()) + * Prompt user for login */ - char *(*filename_from_path)(char *path); - - /** - * Add a path component/filename to an existing path - * - * \param path buffer containing path + free space - * \param length length of buffer "path" - * \param newpart string containing path component to add to path - * \return true on success - */ - bool (*path_add_part)(char *path, int length, const char *newpart); + void (*login)(nsurl *url, const char *realm, + nserror (*cb)(bool proceed, void *pw), void *cbpw); }; diff --git a/desktop/gui_factory.c b/desktop/gui_factory.c index cd5031b0d..1bd683df7 100644 --- a/desktop/gui_factory.c +++ b/desktop/gui_factory.c @@ -304,6 +304,12 @@ static void gui_default_cert_verify(nsurl *url, cb(false, cbpw); } +static void gui_default_401login_open(nsurl *url, const char *realm, + nserror (*cb)(bool proceed, void *pw), void *cbpw) +{ + cb(false, cbpw); +} + static nserror verify_browser_register(struct gui_browser_table *gbt) { @@ -343,6 +349,9 @@ static nserror verify_browser_register(struct gui_browser_table *gbt) if (gbt->cert_verify == NULL) { gbt->cert_verify = gui_default_cert_verify; } + if (gbt->login == NULL) { + gbt->login = gui_default_401login_open; + } return NSERROR_OK; } diff --git a/desktop/netsurf.c b/desktop/netsurf.c index 5589f51a5..d294073ba 100644 --- a/desktop/netsurf.c +++ b/desktop/netsurf.c @@ -37,10 +37,8 @@ #include "image/image.h" #include "image/image_cache.h" #include "desktop/netsurf.h" -#include "desktop/401login.h" #include "desktop/browser.h" #include "desktop/system_colour.h" -#include "desktop/gui.h" #include "desktop/gui_factory.h" #include "utils/nsoption.h" #include "desktop/searchweb.h" @@ -96,7 +94,7 @@ static nserror netsurf_llcache_query_handler(const llcache_query *query, { switch (query->type) { case LLCACHE_QUERY_AUTH: - gui_401login_open(query->url, query->data.auth.realm, cb, cbpw); + guit->browser->login(query->url, query->data.auth.realm, cb, cbpw); break; case LLCACHE_QUERY_REDIRECT: /** \todo Need redirect query dialog */ diff --git a/framebuffer/Makefile.target b/framebuffer/Makefile.target index 5c658925e..58a504b17 100644 --- a/framebuffer/Makefile.target +++ b/framebuffer/Makefile.target @@ -135,7 +135,7 @@ $(eval $(foreach V,$(filter FB_IMAGE_%,$(.VARIABLES)),$(call convert_image,$($(V # S_FRAMEBUFFER are sources purely for the framebuffer build S_FRAMEBUFFER := gui.c framebuffer.c schedule.c \ - thumbnail.c misc.c bitmap.c filetype.c login.c findfile.c \ + thumbnail.c misc.c bitmap.c filetype.c findfile.c \ localhistory.c clipboard.c S_FRAMEBUFFER_FBTK := fbtk.c event.c fill.c bitmap.c user.c window.c \ diff --git a/framebuffer/login.c b/framebuffer/login.c deleted file mode 100644 index 7a5e195f4..000000000 --- a/framebuffer/login.c +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright 2008 Vincent Sanders - * - * This file is part of NetSurf, http://www.netsurf-browser.org/ - * - * NetSurf is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License. - * - * NetSurf is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "desktop/401login.h" - -void gui_401login_open(nsurl *url, const char *realm, - nserror (*cb)(bool proceed, void *pw), void *cbpw) -{ - cb(false, cbpw); -} diff --git a/gtk/gui.c b/gtk/gui.c index 1028528ed..39dc885da 100644 --- a/gtk/gui.c +++ b/gtk/gui.c @@ -1143,6 +1143,7 @@ static struct gui_browser_table nsgtk_browser_table = { .cert_verify = gui_cert_verify, .filename_from_path = filename_from_path, .path_add_part = path_add_part, + .login = gui_401login_open, }; /** diff --git a/gtk/gui.h b/gtk/gui.h index 72794b231..65a6e0742 100644 --- a/gtk/gui.h +++ b/gtk/gui.h @@ -29,7 +29,8 @@ #include #include #include -//#include + +#include "utils/nsurl.h" struct glade_file_location_s { char *netsurf; @@ -60,5 +61,8 @@ extern GdkPixbuf *favicon_pixbuf; /* favicon default pixbuf */ uint32_t gtk_gui_gdkkey_to_nskey(GdkEventKey *); +extern void gui_401login_open(nsurl *url, const char *realm, + nserror (*cb)(bool proceed, void *pw), void *cbpw); + #endif /* GTK_GUI_H */ diff --git a/gtk/login.c b/gtk/login.c index 3b8d68254..baf37d094 100644 --- a/gtk/login.c +++ b/gtk/login.c @@ -28,7 +28,6 @@ #include "content/hlcache.h" #include "content/urldb.h" #include "desktop/browser.h" -#include "desktop/401login.h" #include "desktop/gui.h" #include "utils/messages.h" #include "utils/url.h" diff --git a/monkey/401login.c b/monkey/401login.c index 605a21aa9..8b4d33d7d 100644 --- a/monkey/401login.c +++ b/monkey/401login.c @@ -16,12 +16,13 @@ * along with this program. If not, see . */ -#include "desktop/401login.h" #include "utils/ring.h" #include #include +#include "monkey/401login.h" + typedef struct monkey401 { struct monkey401 *r_next, *r_prev; uint32_t num; diff --git a/monkey/401login.h b/monkey/401login.h new file mode 100644 index 000000000..e78355ea2 --- /dev/null +++ b/monkey/401login.h @@ -0,0 +1,9 @@ + +#include + +#include "utils/nsurl.h" +#include "utils/errors.h" + + +void gui_401login_open(nsurl *url, const char *realm, + nserror (*cb)(bool proceed, void *pw), void *cbpw); diff --git a/monkey/main.c b/monkey/main.c index 1922393a8..b6f5c434d 100644 --- a/monkey/main.c +++ b/monkey/main.c @@ -26,6 +26,7 @@ #include "monkey/dispatch.h" #include "monkey/browser.h" #include "monkey/cert.h" +#include "monkey/401login.h" #include "content/urldb.h" #include "content/fetchers/resource.h" @@ -161,6 +162,7 @@ static struct gui_browser_table monkey_browser_table = { .cert_verify = gui_cert_verify, .filename_from_path = filename_from_path, .path_add_part = path_add_part, + .login = gui_401login_open, }; int diff --git a/riscos/401login.c b/riscos/401login.c index 6740f54e5..e6772b820 100644 --- a/riscos/401login.c +++ b/riscos/401login.c @@ -27,7 +27,6 @@ #include "content/hlcache.h" #include "content/urldb.h" #include "desktop/browser.h" -#include "desktop/401login.h" #include "desktop/gui.h" #include "riscos/dialog.h" #include "riscos/wimp_event.h" diff --git a/riscos/gui.c b/riscos/gui.c index c780abfcf..f7dc6c962 100644 --- a/riscos/gui.c +++ b/riscos/gui.c @@ -2362,6 +2362,7 @@ static struct gui_browser_table riscos_browser_table = { .cert_verify = gui_cert_verify, .filename_from_path = filename_from_path, .path_add_part = path_add_part, + .login = gui_401login_open, }; diff --git a/riscos/gui.h b/riscos/gui.h index b45bd472c..89a539300 100644 --- a/riscos/gui.h +++ b/riscos/gui.h @@ -127,6 +127,8 @@ extern struct gui_download_table *riscos_download_table; /* in 401login.c */ void ro_gui_401login_init(void); +void gui_401login_open(nsurl *url, const char *realm, + nserror (*cb)(bool proceed, void *pw), void *cbpw); /* in window.c */ bool ro_gui_window_dataload(struct gui_window *g, wimp_message *message); diff --git a/utils/utils.h b/utils/utils.h index e3b3647ea..d56330e10 100644 --- a/utils/utils.h +++ b/utils/utils.h @@ -184,9 +184,11 @@ inline static char digit2uppercase_hex(unsigned char digit) { /* Platform specific functions */ void die(const char * const error); void warn_user(const char *warning, const char *detail); +void PDF_Password(char **owner_pass, char **user_pass, char *path); + +/* only riscos */ query_id query_user(const char *query, const char *detail, const query_callback *cb, void *pw, const char *yes, const char *no); void query_close(query_id); -void PDF_Password(char **owner_pass, char **user_pass, char *path); #endif diff --git a/windows/Makefile.target b/windows/Makefile.target index cad28b575..87544e3db 100644 --- a/windows/Makefile.target +++ b/windows/Makefile.target @@ -65,7 +65,7 @@ S_RESOURCES := windows_resource.o # S_WINDOWS are sources purely for the windows build S_WINDOWS := main.c window.c gui.c drawable.c misc.c plot.c findfile.c \ font.c bitmap.c about.c prefs.c download.c filetype.c \ - localhistory.c login.c schedule.c thumbnail.c windbg.c + localhistory.c schedule.c thumbnail.c windbg.c S_WINDOWS := $(addprefix windows/,$(S_WINDOWS)) # This is the final source build list diff --git a/windows/login.c b/windows/login.c deleted file mode 100644 index 7a5e195f4..000000000 --- a/windows/login.c +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright 2008 Vincent Sanders - * - * This file is part of NetSurf, http://www.netsurf-browser.org/ - * - * NetSurf is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License. - * - * NetSurf is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "desktop/401login.h" - -void gui_401login_open(nsurl *url, const char *realm, - nserror (*cb)(bool proceed, void *pw), void *cbpw) -{ - cb(false, cbpw); -} From 444d3ac94a1d19a30963c38ad605deec778f3c27 Mon Sep 17 00:00:00 2001 From: John-Mark Bell Date: Thu, 16 Jan 2014 01:35:51 +0000 Subject: [PATCH 092/773] Silence warning --- riscos/window.c | 1 - 1 file changed, 1 deletion(-) diff --git a/riscos/window.c b/riscos/window.c index c314c748b..c08f0277b 100644 --- a/riscos/window.c +++ b/riscos/window.c @@ -1799,7 +1799,6 @@ bool ro_gui_window_keypress(wimp_key *key) { struct gui_window *g; hlcache_handle *h; - os_error *error; uint32_t c = (uint32_t) key->c; g = (struct gui_window *) ro_gui_wimp_event_get_user_data(key->w); From a2247a75a3dab9d583617299a88d0e76c923f83b Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Thu, 16 Jan 2014 13:24:14 +0000 Subject: [PATCH 093/773] cleanup copyright headers and some doc comments --- desktop/gui.h | 9 +-------- desktop/gui_factory.c | 23 +++++++++++++++++++++-- desktop/gui_factory.h | 9 ++++++++- framebuffer/gui.c | 5 +++-- riscos/query.h | 4 ++++ utils/utils.h | 5 ----- 6 files changed, 37 insertions(+), 18 deletions(-) diff --git a/desktop/gui.h b/desktop/gui.h index cd116e9c1..5252737f9 100644 --- a/desktop/gui.h +++ b/desktop/gui.h @@ -1,6 +1,5 @@ /* - * Copyright 2003 Phil Mellor - * Copyright 2004 James Bursa + * Copyright 2014 Vincent Sanders * * This file is part of NetSurf, http://www.netsurf-browser.org/ * @@ -26,14 +25,8 @@ #include -#include -#include - -#include "utils/config.h" #include "content/hlcache.h" #include "desktop/download.h" -#include "desktop/mouse.h" -#include "desktop/search.h" #include "utils/errors.h" typedef enum { diff --git a/desktop/gui_factory.c b/desktop/gui_factory.c index 1bd683df7..104f4906d 100644 --- a/desktop/gui_factory.c +++ b/desktop/gui_factory.c @@ -1,12 +1,29 @@ +/* + * Copyright 2014 Vincent Sanders + * + * This file is part of NetSurf, http://www.netsurf-browser.org/ + * + * NetSurf is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * NetSurf is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ #include "desktop/gui.h" #include "desktop/gui_factory.h" +/** The global GUI interface table */ struct gui_table *guit = NULL; - static void gui_default_window_set_title(struct gui_window *g, const char *title) { } @@ -254,6 +271,7 @@ static void gui_default_set_clipboard(const char *buffer, size_t length, { } +/** verify clipboard table is valid */ static nserror verify_clipboard_register(struct gui_clipboard_table *gct) { /* check table is present */ @@ -310,7 +328,7 @@ static void gui_default_401login_open(nsurl *url, const char *realm, cb(false, cbpw); } - +/** verify browser table is valid */ static nserror verify_browser_register(struct gui_browser_table *gbt) { /* check table is present */ @@ -369,6 +387,7 @@ static struct gui_clipboard_table default_clipboard_table = { .set = gui_default_set_clipboard, }; +/* exported interface documented in desktop/gui_factory.h */ nserror gui_factory_register(struct gui_table *gt) { nserror err; diff --git a/desktop/gui_factory.h b/desktop/gui_factory.h index 50b5eb31e..dc94b3a16 100644 --- a/desktop/gui_factory.h +++ b/desktop/gui_factory.h @@ -25,8 +25,15 @@ #include "desktop/gui.h" -extern struct gui_table *guit; /* the gui vtable */ +/** The global operation table */ +extern struct gui_table *guit; +/** register and verify global operation table + * + * @param gt The global table to register + * @return NSERROR_OK on success or error code on faliure. On faliure + * global table will not be initialised + */ nserror gui_factory_register(struct gui_table *gt); #endif diff --git a/framebuffer/gui.c b/framebuffer/gui.c index 76ed397d3..d89315957 100644 --- a/framebuffer/gui.c +++ b/framebuffer/gui.c @@ -1826,10 +1826,11 @@ static struct gui_window_table framebuffer_window_table = { static struct gui_browser_table framebuffer_browser_table = { .poll = gui_poll, - .quit = gui_quit, - .get_resource_url = gui_get_resource_url, .filename_from_path = filename_from_path, .path_add_part = path_add_part, + + .quit = gui_quit, + .get_resource_url = gui_get_resource_url, }; /** Entry point from OS. diff --git a/riscos/query.h b/riscos/query.h index 92e3e292e..10a67e73b 100644 --- a/riscos/query.h +++ b/riscos/query.h @@ -29,4 +29,8 @@ query_id query_user_xy(const char *query, const char *detail, void ro_gui_query_init(void); void ro_gui_query_window_bring_to_front(query_id id); +query_id query_user(const char *query, const char *detail, + const query_callback *cb, void *pw, const char *yes, const char *no); +void query_close(query_id); + #endif diff --git a/utils/utils.h b/utils/utils.h index d56330e10..ed19cb33f 100644 --- a/utils/utils.h +++ b/utils/utils.h @@ -186,9 +186,4 @@ void die(const char * const error); void warn_user(const char *warning, const char *detail); void PDF_Password(char **owner_pass, char **user_pass, char *path); -/* only riscos */ -query_id query_user(const char *query, const char *detail, - const query_callback *cb, void *pw, const char *yes, const char *no); -void query_close(query_id); - #endif From 54b7482f785dc647a5369328efea467d6ee0d5e8 Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Thu, 16 Jan 2014 14:28:25 +0000 Subject: [PATCH 094/773] fix up riscos build errors --- riscos/download.c | 102 +++++++++++++++++++++---------------------- riscos/gui.c | 2 +- riscos/gui.h | 1 + riscos/gui/url_bar.c | 1 + riscos/hotlist.c | 1 + riscos/wimp_event.c | 1 + riscos/window.c | 6 +-- riscos/window.h | 4 +- 8 files changed, 62 insertions(+), 56 deletions(-) diff --git a/riscos/download.c b/riscos/download.c index 3a02c9c90..d0149b66c 100644 --- a/riscos/download.c +++ b/riscos/download.c @@ -435,6 +435,57 @@ static struct gui_download_window *gui_download_window_create(download_context * return dw; } +/** + * Handle failed downloads. + * + * \param dw download window + * \param error_msg error message + */ + +static void gui_download_window_error(struct gui_download_window *dw, + const char *error_msg) +{ + os_error *error; + + if (dw->ctx != NULL) + download_context_destroy(dw->ctx); + dw->ctx = NULL; + dw->error = true; + + schedule_remove(ro_gui_download_update_status_wrapper, dw); + + /* place error message in status icon in red */ + strncpy(dw->status, error_msg, sizeof dw->status); + error = xwimp_set_icon_state(dw->window, + ICON_DOWNLOAD_STATUS, + wimp_COLOUR_RED << wimp_ICON_FG_COLOUR_SHIFT, + wimp_ICON_FG_COLOUR); + if (error) { + LOG(("xwimp_set_icon_state: 0x%x: %s", + error->errnum, error->errmess)); + warn_user("WimpError", error->errmess); + } + + /* grey out pathname icon */ + error = xwimp_set_icon_state(dw->window, ICON_DOWNLOAD_PATH, + wimp_ICON_SHADED, 0); + if (error) { + LOG(("xwimp_set_icon_state: 0x%x: %s", + error->errnum, error->errmess)); + warn_user("WimpError", error->errmess); + } + + /* grey out file icon */ + error = xwimp_set_icon_state(dw->window, ICON_DOWNLOAD_ICON, + wimp_ICON_SHADED, wimp_ICON_SHADED); + if (error) { + LOG(("xwimp_set_icon_state: 0x%x: %s", + error->errnum, error->errmess)); + warn_user("WimpError", error->errmess); + } + + ro_gui_download_window_hide_caret(dw); +} /** * Handle received download data. @@ -707,57 +758,6 @@ void ro_gui_download_window_hide_caret(struct gui_download_window *dw) } -/** - * Handle failed downloads. - * - * \param dw download window - * \param error_msg error message - */ - -static void gui_download_window_error(struct gui_download_window *dw, - const char *error_msg) -{ - os_error *error; - - if (dw->ctx != NULL) - download_context_destroy(dw->ctx); - dw->ctx = NULL; - dw->error = true; - - schedule_remove(ro_gui_download_update_status_wrapper, dw); - - /* place error message in status icon in red */ - strncpy(dw->status, error_msg, sizeof dw->status); - error = xwimp_set_icon_state(dw->window, - ICON_DOWNLOAD_STATUS, - wimp_COLOUR_RED << wimp_ICON_FG_COLOUR_SHIFT, - wimp_ICON_FG_COLOUR); - if (error) { - LOG(("xwimp_set_icon_state: 0x%x: %s", - error->errnum, error->errmess)); - warn_user("WimpError", error->errmess); - } - - /* grey out pathname icon */ - error = xwimp_set_icon_state(dw->window, ICON_DOWNLOAD_PATH, - wimp_ICON_SHADED, 0); - if (error) { - LOG(("xwimp_set_icon_state: 0x%x: %s", - error->errnum, error->errmess)); - warn_user("WimpError", error->errmess); - } - - /* grey out file icon */ - error = xwimp_set_icon_state(dw->window, ICON_DOWNLOAD_ICON, - wimp_ICON_SHADED, wimp_ICON_SHADED); - if (error) { - LOG(("xwimp_set_icon_state: 0x%x: %s", - error->errnum, error->errmess)); - warn_user("WimpError", error->errmess); - } - - ro_gui_download_window_hide_caret(dw); -} /** diff --git a/riscos/gui.c b/riscos/gui.c index f7dc6c962..6160956c7 100644 --- a/riscos/gui.c +++ b/riscos/gui.c @@ -948,7 +948,7 @@ void ro_gui_cleanup(void) * \param active return as soon as possible */ -static void gui_poll(bool active) +void gui_poll(bool active) { wimp_event_no event; wimp_block block; diff --git a/riscos/gui.h b/riscos/gui.h index 89a539300..c3dce1cb8 100644 --- a/riscos/gui.h +++ b/riscos/gui.h @@ -118,6 +118,7 @@ void ro_gui_dump_browser_window(struct browser_window *bw); void ro_gui_drag_box_start(wimp_pointer *pointer); bool ro_gui_prequit(void); const char *ro_gui_default_language(void); +void gui_poll(bool active); /* exported for riscos/wimp_event.c:722 */ /* in download.c */ void ro_gui_download_init(void); diff --git a/riscos/gui/url_bar.c b/riscos/gui/url_bar.c index 62956a9ab..49930934f 100644 --- a/riscos/gui/url_bar.c +++ b/riscos/gui/url_bar.c @@ -36,6 +36,7 @@ #include "riscos/url_suggest.h" #include "riscos/wimp.h" #include "riscos/wimp_event.h" +#include "riscos/window.h" #include "utils/log.h" #include "utils/messages.h" #include "utils/utils.h" diff --git a/riscos/hotlist.c b/riscos/hotlist.c index eeaddd00f..791035331 100644 --- a/riscos/hotlist.c +++ b/riscos/hotlist.c @@ -45,6 +45,7 @@ #include "riscos/treeview.h" #include "riscos/wimp.h" #include "riscos/wimp_event.h" +#include "riscos/query.h" #include "utils/log.h" #include "utils/messages.h" #include "utils/schedule.h" diff --git a/riscos/wimp_event.c b/riscos/wimp_event.c index e87962039..1811498ea 100644 --- a/riscos/wimp_event.c +++ b/riscos/wimp_event.c @@ -32,6 +32,7 @@ #include "oslib/serviceinternational.h" #include "oslib/wimp.h" #include "desktop/gui.h" +#include "riscos/gui.h" #include "riscos/dialog.h" #include "riscos/menus.h" #include "riscos/ucstables.h" diff --git a/riscos/window.c b/riscos/window.c index 0d31b663a..2221425c3 100644 --- a/riscos/window.c +++ b/riscos/window.c @@ -1069,7 +1069,7 @@ void gui_window_set_pointer(struct gui_window *g, gui_pointer_shape shape) * \param url new url for address bar */ -static void gui_window_set_url(struct gui_window *g, const char *url) +void gui_window_set_url(struct gui_window *g, const char *url) { if (!g->toolbar) return; @@ -5240,7 +5240,7 @@ bool ro_gui_alt_pressed(void) return (alt == 0xff); } -static struct gui_window_table gui_window_table = { +static struct gui_window_table window_table = { .create = gui_window_create, .destroy = gui_window_destroy, .redraw = gui_window_redraw_window, @@ -5273,4 +5273,4 @@ static struct gui_window_table gui_window_table = { .start_selection = gui_start_selection, }; -struct gui_window_table *riscos_gui_window_table = &gui_window_table; +struct gui_window_table *riscos_window_table = &window_table; diff --git a/riscos/window.h b/riscos/window.h index 679fa9801..b55f1120d 100644 --- a/riscos/window.h +++ b/riscos/window.h @@ -25,11 +25,13 @@ #ifndef _NETSURF_RISCOS_WINDOW_H_ #define _NETSURF_RISCOS_WINDOW_H_ -extern struct gui_window_table *riscos_gui_window_table; +extern struct gui_window_table *riscos_window_table; void ro_gui_window_initialise(void); bool ro_gui_window_check_menu(wimp_menu *menu); +void gui_window_set_url(struct gui_window *g, const char *url); + #endif From ba4788108b7e5c33920d3cc55b4f378d26233e11 Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Thu, 16 Jan 2014 14:43:48 +0000 Subject: [PATCH 095/773] fixup amiga build errors --- amiga/clipboard.c | 9 ++++++++- amiga/clipboard.h | 6 +++--- amiga/download.c | 30 +++++++++++++++--------------- amiga/gui.c | 12 +++++++----- amiga/sslcert.h | 1 + 5 files changed, 34 insertions(+), 24 deletions(-) diff --git a/amiga/clipboard.c b/amiga/clipboard.c index 18598798c..8df441e02 100644 --- a/amiga/clipboard.c +++ b/amiga/clipboard.c @@ -215,7 +215,7 @@ void gui_get_clipboard(char **buffer, size_t *length) CloseIFF(iffh); } -void gui_set_clipboard(const char *buffer, size_t length, +static void gui_set_clipboard(const char *buffer, size_t length, nsclipboard_styles styles[], int n_styles) { char *text; @@ -376,3 +376,10 @@ bool ami_easy_clipboard_svg(struct hlcache_handle *c) return true; } #endif + +static struct gui_clipboard_table clipboard_table = { + .get = gui_get_clipboard, + .set = gui_set_clipboard, +}; + +struct gui_clipboard_table *amiga_clipboard_table = &clipboard_table; diff --git a/amiga/clipboard.h b/amiga/clipboard.h index 57004547d..db6fc35cc 100755 --- a/amiga/clipboard.h +++ b/amiga/clipboard.h @@ -25,11 +25,11 @@ struct hlcache_handle; struct selection; struct gui_window; struct gui_window_2; +struct gui_clipboard_table; + +extern struct gui_clipboard_table *amiga_clipboard_table; void gui_start_selection(struct gui_window *g); -void gui_get_clipboard(char **buffer, size_t *length); -void gui_set_clipboard(const char *buffer, size_t length, nsclipboard_styles styles[], int n_styles); - void ami_clipboard_init(void); void ami_clipboard_free(void); diff --git a/amiga/download.c b/amiga/download.c index 4f4c39b20..a65fad99f 100644 --- a/amiga/download.c +++ b/amiga/download.c @@ -227,21 +227,6 @@ static nserror gui_download_window_data(struct gui_download_window *dw, return NSERROR_OK; } -static void gui_download_window_error(struct gui_download_window *dw, - const char *error_msg) -{ - warn_user("Unwritten",""); - dw->result = AMINS_DLOAD_ERROR; - gui_download_window_done(dw); -} - -void ami_download_window_abort(struct gui_download_window *dw) -{ - download_context_abort(dw->ctx); - dw->result = AMINS_DLOAD_ABORT; - gui_download_window_done(dw); -} - static void gui_download_window_done(struct gui_download_window *dw) { struct dlnode *dln,*dln2 = NULL; @@ -299,6 +284,21 @@ static void gui_download_window_done(struct gui_download_window *dw) } } +static void gui_download_window_error(struct gui_download_window *dw, + const char *error_msg) +{ + warn_user("Unwritten",""); + dw->result = AMINS_DLOAD_ERROR; + gui_download_window_done(dw); +} + +void ami_download_window_abort(struct gui_download_window *dw) +{ + download_context_abort(dw->ctx); + dw->result = AMINS_DLOAD_ABORT; + gui_download_window_done(dw); +} + BOOL ami_download_window_event(struct gui_download_window *dw) { /* return TRUE if window destroyed */ diff --git a/amiga/gui.c b/amiga/gui.c index ad172207b..554f4eb6a 100644 --- a/amiga/gui.c +++ b/amiga/gui.c @@ -69,6 +69,7 @@ #include "amiga/theme.h" #include "amiga/tree.h" #include "amiga/utf8.h" +#include "amiga/sslcert.h" /* Custom StringView class */ #include "amiga/stringview/stringview.h" @@ -202,6 +203,11 @@ static void ami_schedule_redraw_remove(struct gui_window_2 *gwin); static bool gui_window_get_scroll(struct gui_window *g, int *sx, int *sy); static void gui_window_set_scroll(struct gui_window *g, int sx, int sy); +static void gui_window_remove_caret(struct gui_window *g); +static void gui_set_search_ico(hlcache_handle *ico); +static void gui_window_place_caret(struct gui_window *g, int x, int y, int height, const struct rect *clip); + + /* accessors for default options - user option is updated if it is set as per default */ #define nsoption_default_set_int(OPTION, VALUE) \ @@ -5144,10 +5150,6 @@ static struct gui_window_table amiga_window_table = { .save_link = gui_window_save_link, }; -static struct gui_clipboard_table amiga_clipboard_table = { - .get = gui_get_clipboard, - .set = gui_set_clipboard, -}; static struct gui_browser_table amiga_browser_table = { .poll = gui_poll, @@ -5176,7 +5178,7 @@ int main(int argc, char** argv) struct gui_table amiga_gui_table = { .browser = &amiga_browser_table, .window = &amiga_window_table, - .clipboard = &amiga_clipboard_table, + .clipboard = amiga_clipboard_table, .download = amiga_download_table, }; diff --git a/amiga/sslcert.h b/amiga/sslcert.h index b55cac8b6..953142e98 100644 --- a/amiga/sslcert.h +++ b/amiga/sslcert.h @@ -24,4 +24,5 @@ void gui_cert_verify(nsurl *url, nserror (*cb)(bool proceed, void *pw), void *cbpw); void ami_ssl_free(struct treeview_window *twin); + #endif From fb1120c21294c6c8d53df5585bcd9e668f812e04 Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Thu, 16 Jan 2014 15:00:43 +0000 Subject: [PATCH 096/773] fix windows build error --- windows/download.h | 2 +- windows/gui.c | 2 +- windows/main.c | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/windows/download.h b/windows/download.h index a53fab89f..974f1ecd2 100644 --- a/windows/download.h +++ b/windows/download.h @@ -23,7 +23,7 @@ #include #include "desktop/gui.h" -struct gui_download_table *win32_download_table; +extern struct gui_download_table *win32_download_table; typedef enum { DOWNLOAD_NONE, diff --git a/windows/gui.c b/windows/gui.c index 40124671d..f476c5ae9 100644 --- a/windows/gui.c +++ b/windows/gui.c @@ -1875,7 +1875,7 @@ static struct gui_clipboard_table clipboard_table = { struct gui_clipboard_table *win32_clipboard_table = &clipboard_table; -static struct gui_table browser_table = { +static struct gui_browser_table browser_table = { .poll = gui_poll, .filename_from_path = filename_from_path, .path_add_part = path_add_part, diff --git a/windows/main.c b/windows/main.c index 638db6c5c..ac75ab568 100644 --- a/windows/main.c +++ b/windows/main.c @@ -36,6 +36,7 @@ #include "windows/findfile.h" #include "windows/drawable.h" #include "windows/gui.h" +#include "windows/download.h" static char **respaths; /** resource search path vector. */ @@ -110,7 +111,7 @@ WinMain(HINSTANCE hInstance, HINSTANCE hLastInstance, LPSTR lpcli, int ncmd) .clipboard = win32_clipboard_table, .download = win32_download_table, }; - win32_gui_table->browser->get_resource_url = get_resource_url; + win32_gui_table->browser->get_resource_url = gui_get_resource_url; if (SLEN(lpcli) > 0) { argvw = CommandLineToArgvW(GetCommandLineW(), &argc); From 6cfa3cce638b85807dc280150aad4200d5d12c39 Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Thu, 16 Jan 2014 15:07:14 +0000 Subject: [PATCH 097/773] fix atari build errors --- atari/gui.c | 3 ++- atari/gui.h | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/atari/gui.c b/atari/gui.c index 95cfe55ed..2180080cc 100644 --- a/atari/gui.c +++ b/atari/gui.c @@ -73,6 +73,7 @@ #include "atari/osspec.h" #include "atari/search.h" #include "atari/deskmenu.h" +#include "atari/download.h" #include "cflib.h" #define TODO() (0)/*printf("%s Unimplemented!\n", __FUNCTION__)*/ @@ -254,7 +255,7 @@ gui_window_create(struct browser_window *bw, } -static void gui_window_destroy(struct gui_window *w) +void gui_window_destroy(struct gui_window *w) { if (w == NULL) return; diff --git a/atari/gui.h b/atari/gui.h index d552bc87b..978c0d093 100755 --- a/atari/gui.h +++ b/atari/gui.h @@ -167,5 +167,8 @@ char *gui_window_get_title(struct gui_window *gw); void gui_window_set_status(struct gui_window *w, const char *text); void gui_window_set_pointer(struct gui_window *gw, gui_pointer_shape shape); +void gui_window_destroy(struct gui_window *w); +void gui_window_set_scale(struct gui_window *gw, float scale); +float gui_window_get_scale(struct gui_window *gw); #endif From 55bf16d754bc180e2b6520c3fadd751545db9805 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Revol?= Date: Thu, 16 Jan 2014 16:05:09 +0100 Subject: [PATCH 098/773] beos: Better implementation of NSIconTextControl for the url bar Instead of adding a child view we draw the bitmap over the child. Fixup the TextRect also in Draw() which is called just before the TextView's Draw(). It flickers a little less, and also respects the background color of the text control when using a desktop theme. Also drop a useless dynamic_cast. --- beos/scaffolding.cpp | 85 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 66 insertions(+), 19 deletions(-) diff --git a/beos/scaffolding.cpp b/beos/scaffolding.cpp index f302efcb4..aede7aec4 100644 --- a/beos/scaffolding.cpp +++ b/beos/scaffolding.cpp @@ -83,6 +83,7 @@ extern "C" { struct beos_history_window; +class NSIconTextControl; class NSBrowserWindow; class NSThrobber; @@ -106,7 +107,7 @@ struct beos_scaffolding { BControl *reload_button; BControl *home_button; - BTextControl *url_bar; + NSIconTextControl *url_bar; //BMenuField *url_bar_completion; NSThrobber *throbber; @@ -159,6 +160,8 @@ extern BResources *gAppResources; // #pragma mark - class NSIconTextControl +#define ICON_WIDTH 16 + class NSIconTextControl : public BTextControl { public: NSIconTextControl(BRect frame, const char* name, @@ -166,17 +169,22 @@ public: BMessage* message, uint32 resizeMode = B_FOLLOW_LEFT | B_FOLLOW_TOP, - uint32 flags = B_WILL_DRAW | B_NAVIGABLE); + uint32 flags + = B_WILL_DRAW | B_NAVIGABLE | B_DRAW_ON_CHILDREN); virtual ~NSIconTextControl(); virtual void FrameResized(float newWidth, float newHeight); +virtual void Draw(BRect updateRect); +virtual void DrawAfterChildren(BRect updateRect); +virtual void AttachedToWindow(); void SetBitmap(const BBitmap *bitmap); void FixupTextRect(); private: - const BBitmap *fBitmap; - BView *fBitmapView; + BPoint fIconOffset; + BRect fIconFrame; + const BBitmap *fIconBitmap; }; NSIconTextControl::NSIconTextControl(BRect frame, const char* name, @@ -185,23 +193,23 @@ NSIconTextControl::NSIconTextControl(BRect frame, const char* name, uint32 resizeMode, uint32 flags) : BTextControl(frame, name, label, initialText, message, resizeMode, flags), - fBitmap(NULL), - fBitmapView(NULL) + fIconOffset(0,0), + fIconBitmap(NULL) { - BRect r(TextView()->TextRect()); + BRect r(Bounds()); BRect frame = r; - frame.right = frame.left + 15; - frame.bottom = frame.top + 15; - frame.OffsetBy(-2, (r.IntegerHeight() - 16) / 2); - fBitmapView = new BView(frame, "iconview", B_FOLLOW_NONE, 0); + frame.right = frame.left + ICON_WIDTH - 1; + frame.bottom = frame.top + ICON_WIDTH - 1; + frame.OffsetBy((int32)((r.IntegerHeight() - ICON_WIDTH + 3) / 2), + (int32)((r.IntegerHeight() - ICON_WIDTH + 1) / 2)); + fIconFrame = frame; FixupTextRect(); - - TextView()->AddChild(fBitmapView); } NSIconTextControl::~NSIconTextControl() { + delete fIconBitmap; } @@ -210,15 +218,51 @@ NSIconTextControl::FrameResized(float newWidth, float newHeight) { BTextControl::FrameResized(newWidth, newHeight); FixupTextRect(); - Invalidate(); +} + + +void +NSIconTextControl::Draw(BRect updateRect) +{ + FixupTextRect(); + BTextControl::Draw(updateRect); +} + + +void +NSIconTextControl::DrawAfterChildren(BRect updateRect) +{ + BTextControl::DrawAfterChildren(updateRect); + + PushState(); + + SetDrawingMode(B_OP_ALPHA); + DrawBitmap(fIconBitmap, fIconFrame); + + //XXX: is this needed? + PopState(); +} + + +void +NSIconTextControl::AttachedToWindow() +{ + BTextControl::AttachedToWindow(); + FixupTextRect(); } void NSIconTextControl::SetBitmap(const BBitmap *bitmap) { - fBitmapView->SetViewBitmap(bitmap); - fBitmapView->Invalidate(); + delete fIconBitmap; + fIconBitmap = NULL; + + // keep a copy + if (bitmap) + fIconBitmap = new BBitmap(bitmap); + // invalidate just the icon area + Invalidate(fIconFrame); } @@ -228,14 +272,17 @@ NSIconTextControl::FixupTextRect() // FIXME: this flickers on resize, quite ugly BRect r(TextView()->TextRect()); - // in case this ever gets fixed... - if (r.left > 10) + // don't fix the fix + if (r.left > ICON_WIDTH) return; + r.left += r.bottom - r.top; TextView()->SetTextRect(r); } +#undef ICON_WIDTH + // #pragma mark - class NSResizeKnob class NSResizeKnob : public BView { @@ -2189,7 +2236,7 @@ void gui_window_set_icon(struct gui_window *_g, hlcache_handle *icon) if (!g->top_view->LockLooper()) return; - dynamic_cast(g->url_bar)->SetBitmap(bitmap); + g->url_bar->SetBitmap(bitmap); g->top_view->UnlockLooper(); } From b1bb708d4f20e899f5ff8df46b6b4297380b6748 Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Thu, 16 Jan 2014 15:17:48 +0000 Subject: [PATCH 099/773] fix cocoa build --- cocoa/DownloadWindowController.h | 2 +- cocoa/DownloadWindowController.m | 4 ++-- cocoa/NetsurfApp.m | 2 ++ cocoa/gui.m | 10 ---------- cocoa/selection.h | 21 +++++++++++++++++++-- cocoa/selection.m | 7 +++++++ 6 files changed, 31 insertions(+), 15 deletions(-) diff --git a/cocoa/DownloadWindowController.h b/cocoa/DownloadWindowController.h index 0d049da15..798ebd1b6 100644 --- a/cocoa/DownloadWindowController.h +++ b/cocoa/DownloadWindowController.h @@ -18,7 +18,7 @@ #import -struct gui_download_table *cocoa_gui_download_table; +struct gui_download_table *cocoa_download_table; @interface DownloadWindowController : NSWindowController { struct download_context *context; diff --git a/cocoa/DownloadWindowController.m b/cocoa/DownloadWindowController.m index 634257008..c46d7967b 100644 --- a/cocoa/DownloadWindowController.m +++ b/cocoa/DownloadWindowController.m @@ -377,11 +377,11 @@ static void cocoa_unregister_download( DownloadWindowController *download ) } -static struct gui_download_table gui_download_table = { +static struct gui_download_table download_table = { .create = gui_download_window_create, .data = gui_download_window_data, .error = gui_download_window_error, .done = gui_download_window_done, }; -struct gui_download_table *cocoa_gui_download_table = &gui_download_table; +struct gui_download_table *cocoa_download_table = &download_table; diff --git a/cocoa/NetsurfApp.m b/cocoa/NetsurfApp.m index 62f684ddc..08946ad7d 100644 --- a/cocoa/NetsurfApp.m +++ b/cocoa/NetsurfApp.m @@ -20,6 +20,8 @@ #import "cocoa/NetsurfApp.h" #import "cocoa/gui.h" #import "cocoa/plotter.h" +#inport "cocoa/DownloadWindowController.h" +#import "cocoa/selection.h" #import "desktop/gui.h" #import "content/urldb.h" diff --git a/cocoa/gui.m b/cocoa/gui.m index a49ea9ea2..4d43fe4f0 100644 --- a/cocoa/gui.m +++ b/cocoa/gui.m @@ -24,7 +24,6 @@ #import "cocoa/BrowserViewController.h" #import "cocoa/BrowserWindowController.h" #import "cocoa/FormSelectMenu.h" -#import "cocoa/selection.h" #import "desktop/gui.h" #import "desktop/netsurf.h" @@ -312,15 +311,6 @@ static struct gui_window_table window_table = { struct gui_window_table *cocoa_window_table = &window_table; - -static struct gui_clipboard_table clipboard_table = { - .get_clipboard = gui_get_clipboard, - .set_clipboard = gui_set_clipboard, -}; - -struct gui_clipboard_table *cocoa_clipboard_table = &clipboard_table; - - static struct gui_browser_table browser_table = { .poll = gui_poll, .get_resource_url = gui_get_resource_url, diff --git a/cocoa/selection.h b/cocoa/selection.h index 14b6e763f..67331ea83 100644 --- a/cocoa/selection.h +++ b/cocoa/selection.h @@ -1,2 +1,19 @@ -void gui_get_clipboard(char **buffer, size_t *length); -void gui_set_clipboard(const char *buffer, size_t length, nsclipboard_styles styles[], int n_styles); +/* + * Copyright 2011 Sven Weidauer + * + * This file is part of NetSurf, http://www.netsurf-browser.org/ + * + * NetSurf is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * NetSurf is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +struct gui_clipboard_table *cocoa_clipboard_table; diff --git a/cocoa/selection.m b/cocoa/selection.m index e95a78441..d511337d3 100644 --- a/cocoa/selection.m +++ b/cocoa/selection.m @@ -21,6 +21,7 @@ #import "cocoa/BrowserViewController.h" #import "cocoa/selection.h" +#import "desktop/gui.h" #import "desktop/browser_private.h" @@ -96,3 +97,9 @@ void gui_set_clipboard(const char *buffer, size_t length, } } +static struct gui_clipboard_table clipboard_table = { + .get = gui_get_clipboard, + .set = gui_set_clipboard, +}; + +struct gui_clipboard_table *cocoa_clipboard_table = &clipboard_table; From 2f478eb5d7690206f2feb92e2e215a5ec8f968c7 Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Thu, 16 Jan 2014 15:21:12 +0000 Subject: [PATCH 100/773] fix missing forward declaration --- atari/gui.c | 1 + windows/main.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/atari/gui.c b/atari/gui.c index 2180080cc..b2ac6f715 100644 --- a/atari/gui.c +++ b/atari/gui.c @@ -114,6 +114,7 @@ EVMULT_OUT aes_event_out; short aes_msg_out[8]; bool gui_window_get_scroll(struct gui_window *w, int *sx, int *sy); +static void gui_window_set_url(struct gui_window *w, const char *url); /** * Return the filename part of a full path diff --git a/windows/main.c b/windows/main.c index ac75ab568..8dc9d45cb 100644 --- a/windows/main.c +++ b/windows/main.c @@ -111,7 +111,7 @@ WinMain(HINSTANCE hInstance, HINSTANCE hLastInstance, LPSTR lpcli, int ncmd) .clipboard = win32_clipboard_table, .download = win32_download_table, }; - win32_gui_table->browser->get_resource_url = gui_get_resource_url; + win32_browser_table->get_resource_url = gui_get_resource_url; if (SLEN(lpcli) > 0) { argvw = CommandLineToArgvW(GetCommandLineW(), &argc); From aaa6b558a912e8296e6df716a5bef5e0923b6073 Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Thu, 16 Jan 2014 15:26:48 +0000 Subject: [PATCH 101/773] fix typo in cocoa import --- cocoa/NetsurfApp.m | 2 +- cocoa/selection.m | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cocoa/NetsurfApp.m b/cocoa/NetsurfApp.m index 08946ad7d..158c195e6 100644 --- a/cocoa/NetsurfApp.m +++ b/cocoa/NetsurfApp.m @@ -20,7 +20,7 @@ #import "cocoa/NetsurfApp.h" #import "cocoa/gui.h" #import "cocoa/plotter.h" -#inport "cocoa/DownloadWindowController.h" +#import "cocoa/DownloadWindowController.h" #import "cocoa/selection.h" #import "desktop/gui.h" diff --git a/cocoa/selection.m b/cocoa/selection.m index d511337d3..c8d6c7d5e 100644 --- a/cocoa/selection.m +++ b/cocoa/selection.m @@ -33,7 +33,7 @@ static NSMutableString *cocoa_clipboard_string; * \param buffer UTF-8 text, allocated by front end, ownership yeilded to core * \param length Byte length of UTF-8 text in buffer */ -void gui_get_clipboard(char **buffer, size_t *length) +static void gui_get_clipboard(char **buffer, size_t *length) { NSPasteboard *pb = [NSPasteboard generalPasteboard]; NSString *string = [pb stringForType: NSStringPboardType]; @@ -63,7 +63,7 @@ void gui_get_clipboard(char **buffer, size_t *length) * \param styles Array of styles given to text runs, owned by core, or NULL * \param n_styles Number of text run styles in array */ -void gui_set_clipboard(const char *buffer, size_t length, +static void gui_set_clipboard(const char *buffer, size_t length, nsclipboard_styles styles[], int n_styles) { /* Empty clipboard string */ From 7c71ad4f5a0fe6d4bce4eb9f65ececed36de2014 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Revol?= Date: Thu, 16 Jan 2014 16:59:45 +0100 Subject: [PATCH 102/773] whitespace --- beos/gui.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/beos/gui.h b/beos/gui.h index ea1a8ad3a..24223a18d 100644 --- a/beos/gui.h +++ b/beos/gui.h @@ -22,7 +22,7 @@ #include #include #include - + #ifndef B_BEOS_VERSION_DANO #define B_UI_SETTINGS_CHANGED '_UIC' #endif From 90742e6b4bb39b8821c08c95022fcdbee9e81557 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Revol?= Date: Thu, 16 Jan 2014 17:27:31 +0100 Subject: [PATCH 103/773] beos: Fix build gcc2 doesn't know about named initializers in C++... --- beos/download.cpp | 8 ++++---- beos/download.h | 2 +- beos/font.cpp | 1 + beos/gui.cpp | 39 ++++++++++++++++++++----------------- beos/gui_options.cpp | 1 + beos/window.cpp | 46 +++++++++++++++++++++++++------------------- 6 files changed, 54 insertions(+), 43 deletions(-) diff --git a/beos/download.cpp b/beos/download.cpp index 2e259bccf..8a55e9de1 100644 --- a/beos/download.cpp +++ b/beos/download.cpp @@ -249,10 +249,10 @@ static void gui_download_window_done(struct gui_download_window *dw) } static struct gui_download_table download_table = { - .create = gui_download_window_create, - .data = gui_download_window_data, - .error = gui_download_window_error, - .done = gui_download_window_done, + gui_download_window_create, + gui_download_window_data, + gui_download_window_error, + gui_download_window_done, }; struct gui_download_table *beos_download_table = &download_table; diff --git a/beos/download.h b/beos/download.h index 245ee8641..0ce387efc 100644 --- a/beos/download.h +++ b/beos/download.h @@ -16,4 +16,4 @@ * along with this program. If not, see . */ -struct gui_download_table *beos_download_table; +extern struct gui_download_table *beos_download_table; diff --git a/beos/font.cpp b/beos/font.cpp index 5636743f5..b262562d3 100644 --- a/beos/font.cpp +++ b/beos/font.cpp @@ -36,6 +36,7 @@ extern "C" { #include "utils/utils.h" #include "utils/log.h" #include "utils/nsoption.h" +#include "utils/nsurl.h" } #include "beos/gui.h" diff --git a/beos/gui.cpp b/beos/gui.cpp index 4a6475894..9e730a0c8 100644 --- a/beos/gui.cpp +++ b/beos/gui.cpp @@ -70,7 +70,7 @@ extern "C" { #include "beos/window.h" #include "beos/throbber.h" #include "beos/filetype.h" -//#include "beos/download.h" +#include "beos/download.h" #include "beos/schedule.h" #include "beos/fetch_rsrc.h" #include "beos/scaffolding.h" @@ -1059,18 +1059,21 @@ static bool path_add_part(char *path, int length, const char *newpart) } static struct gui_clipboard_table beos_clipboard_table = { - .get = gui_get_clipboard, - .set = gui_set_clipboard, + gui_get_clipboard, + gui_set_clipboard, }; static struct gui_browser_table beos_browser_table = { - .poll = gui_poll, - .quit = gui_quit, - .get_resource_url = gui_get_resource_url, - .launch_url = gui_launch_url, - .filename_from_path = filename_from_path, - .path_add_part = path_add_part, - .login = gui_401login_open, + gui_poll, + filename_from_path, + path_add_part, + gui_quit, + NULL, //set_search_ico + gui_get_resource_url, + gui_launch_url, + NULL, //create_form_select_menu + NULL, //cert_verify + gui_401login_open }; @@ -1080,10 +1083,10 @@ int main(int argc, char** argv) nserror ret; BPath options; struct gui_table beos_gui_table = { - .browser = &beos_browser_table, - .window = beos_window_table, - .clipboard = &beos_clipboard_table, - .download = beos_download_table, + &beos_browser_table, + beos_window_table, + beos_download_table, + &beos_clipboard_table }; if (find_directory(B_USER_SETTINGS_DIRECTORY, &options, true) == B_OK) { @@ -1131,10 +1134,10 @@ int gui_init_replicant(int argc, char** argv) nserror ret; BPath options; struct gui_table beos_gui_table = { - .browser = &beos_browser_table, - .window = beos_window_table, - .clipboard = &beos_clipboard_table, - .download = beos_download_table, + &beos_browser_table, + beos_window_table, + beos_download_table, + &beos_clipboard_table }; if (find_directory(B_USER_SETTINGS_DIRECTORY, &options, true) == B_OK) { diff --git a/beos/gui_options.cpp b/beos/gui_options.cpp index 2c56cf710..035c62941 100644 --- a/beos/gui_options.cpp +++ b/beos/gui_options.cpp @@ -24,6 +24,7 @@ extern "C" { #include "utils/log.h" #include "utils/nsoption.h" +#include "utils/nsurl.h" } #include "beos/gui.h" #include "beos/scaffolding.h" diff --git a/beos/window.cpp b/beos/window.cpp index fc46eba96..5863c06ae 100644 --- a/beos/window.cpp +++ b/beos/window.cpp @@ -1348,28 +1348,34 @@ static void gui_window_get_dimensions(struct gui_window *g, int *width, int *hei } static struct gui_window_table window_table = { - .create = gui_window_create, - .destroy = gui_window_destroy, - .redraw = gui_window_redraw_window, - .update = gui_window_update_box, - .get_scroll = gui_window_get_scroll, - .set_scroll = gui_window_set_scroll, - .get_dimensions = gui_window_get_dimensions, - .update_extent = gui_window_update_extent, - - .new_content = gui_window_new_content, - .set_pointer = gui_window_set_pointer, - .place_caret = gui_window_place_caret, - .remove_caret = gui_window_remove_caret, - .start_selection = gui_start_selection, + gui_window_create, + gui_window_destroy, + gui_window_redraw_window, + gui_window_update_box, + gui_window_get_scroll, + gui_window_set_scroll, + gui_window_get_dimensions, + gui_window_update_extent, /* from scaffold */ - .set_icon = gui_window_set_icon, - .set_title = gui_window_set_title, - .set_url = gui_window_set_url, - .set_status = gui_window_set_status, - .start_throbber = gui_window_start_throbber, - .stop_throbber = gui_window_stop_throbber, + gui_window_set_title, + gui_window_set_url, + gui_window_set_icon, + gui_window_set_status, + gui_window_set_pointer, + gui_window_place_caret, + gui_window_remove_caret, + gui_window_start_throbber, + gui_window_stop_throbber, + NULL, //drag_start + NULL, //save_link + NULL, //scroll_visible + NULL, //scroll_start + gui_window_new_content, + NULL, //file_gadget_open + NULL, //drag_save_object + NULL, //drag_save_selection + gui_start_selection }; struct gui_window_table *beos_window_table = &window_table; From c74bf433c3357935a150ccc617d593eb1f673194 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Revol?= Date: Thu, 16 Jan 2014 18:12:41 +0100 Subject: [PATCH 104/773] beos: Fix updating system colors --- beos/gui.cpp | 10 +++++++--- beos/scaffolding.cpp | 3 +-- beos/window.cpp | 3 +-- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/beos/gui.cpp b/beos/gui.cpp index 9e730a0c8..feac53a29 100644 --- a/beos/gui.cpp +++ b/beos/gui.cpp @@ -128,6 +128,7 @@ NSBrowserApplication::MessageReceived(BMessage *message) { switch (message->what) { case B_REFS_RECEIVED: + case B_UI_SETTINGS_CHANGED: // messages for top-level // we'll just send them to the first window case 'back': @@ -468,6 +469,11 @@ static nserror set_defaults(struct nsoption_s *defaults) return NSERROR_OK; } +void nsbeos_update_system_ui_colors(void) +{ + set_defaults(nsoptions); +} + /** * Ensures output logging stream is correctly configured */ @@ -511,9 +517,7 @@ static void gui_init(int argc, char** argv) return; } - // ui_color() gives hardcoded values before BApplication is created. - //FIXME: - //nsbeos_update_system_ui_colors(); + nsbeos_update_system_ui_colors(); fetch_rsrc_register(); diff --git a/beos/scaffolding.cpp b/beos/scaffolding.cpp index aede7aec4..c673f19a5 100644 --- a/beos/scaffolding.cpp +++ b/beos/scaffolding.cpp @@ -929,8 +929,7 @@ void nsbeos_scaffolding_dispatch_event(nsbeos_scaffolding *scaffold, BMessage *m break; } case B_UI_SETTINGS_CHANGED: - //FIXME: - //nsbeos_update_system_ui_colors(); + nsbeos_update_system_ui_colors(); nsbeos_scaffolding_update_colors(scaffold); break; case B_NETPOSITIVE_OPEN_URL: diff --git a/beos/window.cpp b/beos/window.cpp index 5863c06ae..0040a1d0c 100644 --- a/beos/window.cpp +++ b/beos/window.cpp @@ -643,8 +643,7 @@ void nsbeos_dispatch_event(BMessage *message) case B_MOUSE_WHEEL_CHANGED: break; case B_UI_SETTINGS_CHANGED: - //FIXME: - //nsbeos_update_system_ui_colors(); + nsbeos_update_system_ui_colors(); break; case 'nsLO': // login { From 18c8f5f46f18a4f2be330cfc850f6e18a0742e98 Mon Sep 17 00:00:00 2001 From: Chris Young Date: Sat, 18 Jan 2014 21:23:02 +0000 Subject: [PATCH 105/773] Let the frontend construct the correct URL for the default search ico. This fixes bug #2057 --- desktop/searchweb.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/desktop/searchweb.c b/desktop/searchweb.c index 30b424cb3..d42919d2d 100644 --- a/desktop/searchweb.c +++ b/desktop/searchweb.c @@ -236,14 +236,7 @@ void search_web_retrieve_ico(bool localdefault) if (localdefault) { if (search_default_ico_location == NULL) return; - url = malloc(SLEN("file://") + strlen( - search_default_ico_location) + 1); - if (url == NULL) { - warn_user(messages_get("NoMemory"), 0); - return; - } - strcpy(url, "file://"); - strcat(url, search_default_ico_location); + url = path_to_url(search_default_ico_location); } else { url = search_web_ico_name(); } From 96546838d1477584bebb8dc5d2f0b2aa11aef99c Mon Sep 17 00:00:00 2001 From: Chris Young Date: Sat, 18 Jan 2014 21:35:02 +0000 Subject: [PATCH 106/773] Debug logging --- amiga/gui.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/amiga/gui.c b/amiga/gui.c index 554f4eb6a..6df83dbab 100644 --- a/amiga/gui.c +++ b/amiga/gui.c @@ -862,6 +862,7 @@ static void gui_init2(int argc, char** argv) if(rarray[A_URL]) { + LOG(("URL %s specified on command line", rarray[A_URL])); temp_homepage_url = (char *)strdup((char *)rarray[A_URL]); if(notalreadyrunning) @@ -886,10 +887,13 @@ static void gui_init2(int argc, char** argv) if(rarray[A_FORCE]) { + LOG(("FORCE specified on command line")); notalreadyrunning = TRUE; } FreeArgs(args); + } else { + LOG(("ReadArgs failed to parse command line")); } } else From e43fbb39144f7aa5897d1125caaf091902f16def Mon Sep 17 00:00:00 2001 From: Chris Young Date: Sat, 18 Jan 2014 22:10:18 +0000 Subject: [PATCH 107/773] Fix ReadArgs() argument parsing. Collect any parameters we're not interested in and pass those to nsoption_commandline directly. --- amiga/gui.c | 129 +++++++++++++++++++++++++++++++--------------------- 1 file changed, 78 insertions(+), 51 deletions(-) diff --git a/amiga/gui.c b/amiga/gui.c index 6df83dbab..b7ee133fa 100644 --- a/amiga/gui.c +++ b/amiga/gui.c @@ -169,6 +169,9 @@ BOOL refresh_favicon = FALSE; BOOL refresh_throbber = FALSE; struct Hook newprefs_hook; +STRPTR temp_homepage_url = NULL; +bool cli_force = false; + static char *current_user; static char *current_user_dir; @@ -812,15 +815,10 @@ void ami_openscreenfirst(void) ami_theme_throbber_setup(); } -static void gui_init2(int argc, char** argv) +static void ami_gui_commandline(int *argc, char **argv) { - struct Screen *screen; - nsurl *url; - nserror error; - struct browser_window *bw = NULL; + int new_argc = 0; struct RDArgs *args; - STRPTR temp_homepage_url = NULL; - BOOL notalreadyrunning; STRPTR template = "NSOPTS/M,URL/K,FORCE/S"; long rarray[] = {0,0,0}; enum @@ -830,6 +828,55 @@ static void gui_init2(int argc, char** argv) A_FORCE }; + if(*argc == 0) return; // argc==0 is started from wb + + if(args = ReadArgs(template, rarray, NULL)) { + if(rarray[A_URL]) { + LOG(("URL %s specified on command line", rarray[A_URL])); + temp_homepage_url = (char *)strdup((char *)rarray[A_URL]); + } + + if(rarray[A_FORCE]) { + LOG(("FORCE specified on command line")); + cli_force = true; + } + + if(rarray[A_NSOPTS]) { + /* The NSOPTS/M parameter specified in the ReadArgs template is + * special. The /M means it collects all arguments that can't + * be assigned to any other parameter, and stores them in an + * array. We collect these and pass them as a fake argc/argv + * to nsoption_commandline(). + * This trickery is necessary because if ReadArgs() is called + * first, nsoption_commandline() can no longer parse (fetch?) + * the arguments. If nsoption_commandline() is called first, + * then ReadArgs cannot fetch the arguments. + */ + char **p = (char **)rarray[A_NSOPTS]; + do { + LOG(("Arg [%d] assigned to NSOPTS/M by ReadArgs: %s", new_argc, *p)); + new_argc++; + p++; + } while(*p != NULL); + + nsoption_commandline(&new_argc, (char **)rarray[A_NSOPTS], NULL); + } + + FreeArgs(args); + } else { + LOG(("ReadArgs failed to parse command line")); + } +} + + +static void gui_init2(int argc, char** argv) +{ + struct Screen *screen; + BOOL notalreadyrunning; + nsurl *url; + nserror error; + struct browser_window *bw = NULL; + notalreadyrunning = ami_arexx_init(); /* Treeview init code ends up calling a font function which needs this */ @@ -852,52 +899,32 @@ static void gui_init2(int argc, char** argv) search_web_provider_details(nsoption_int(search_provider)); - if(argc) // argc==0 is started from wb - { - if(args = ReadArgs(template,rarray,NULL)) - { - if (notalreadyrunning && - (nsoption_bool(startup_no_window) == false)) - ami_openscreenfirst(); + if (notalreadyrunning && + (nsoption_bool(startup_no_window) == false)) + ami_openscreenfirst(); - if(rarray[A_URL]) - { - LOG(("URL %s specified on command line", rarray[A_URL])); - temp_homepage_url = (char *)strdup((char *)rarray[A_URL]); - - if(notalreadyrunning) - { - error = nsurl_create(temp_homepage_url, &url); - if (error == NSERROR_OK) { - error = browser_window_create(BROWSER_WINDOW_VERIFIABLE | - BROWSER_WINDOW_HISTORY, - url, - NULL, - NULL, - &bw); - nsurl_unref(url); - } - if (error != NSERROR_OK) { - warn_user(messages_get_errorcode(error), 0); - } - - free(temp_homepage_url); - } - } - - if(rarray[A_FORCE]) - { - LOG(("FORCE specified on command line")); - notalreadyrunning = TRUE; - } - - FreeArgs(args); - } else { - LOG(("ReadArgs failed to parse command line")); + if(temp_homepage_url && notalreadyrunning) { + error = nsurl_create(temp_homepage_url, &url); + if (error == NSERROR_OK) { + error = browser_window_create(BROWSER_WINDOW_VERIFIABLE | + BROWSER_WINDOW_HISTORY, + url, + NULL, + NULL, + &bw); + nsurl_unref(url); } + if (error != NSERROR_OK) { + warn_user(messages_get_errorcode(error), 0); + } + free(temp_homepage_url); } - else - { + + if(cli_force == true) { + notalreadyrunning = TRUE; + } + + if(argc == 0) { // WB struct WBStartup *WBenchMsg = (struct WBStartup *)argv; struct WBArg *wbarg; int first=0,i=0; @@ -5228,7 +5255,7 @@ int main(int argc, char** argv) die("Options failed to initialise"); } nsoption_read(current_user_options, NULL); - nsoption_commandline(&argc, argv, NULL); + ami_gui_commandline(&argc, argv); /* calls nsoption_commandline */ if (ami_locate_resource(messages, "Messages") == false) die("Cannot open Messages file"); From 977ae8efc6cc543d98ac8c5261b32cb348dbb47e Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Sun, 19 Jan 2014 10:51:14 +0000 Subject: [PATCH 108/773] remove all forward declarations from hlcache.c --- content/hlcache.c | 838 +++++++++++++++++++++++----------------------- 1 file changed, 414 insertions(+), 424 deletions(-) diff --git a/content/hlcache.c b/content/hlcache.c index e8b2836db..618f4fd1e 100644 --- a/content/hlcache.c +++ b/content/hlcache.c @@ -94,23 +94,426 @@ struct hlcache_s { static struct hlcache_s *hlcache = NULL; -static void hlcache_clean(void *ignored); +/****************************************************************************** + * High-level cache internals * + ******************************************************************************/ -static nserror hlcache_llcache_callback(llcache_handle *handle, - const llcache_event *event, void *pw); -static nserror hlcache_migrate_ctx(hlcache_retrieval_ctx *ctx, - lwc_string *effective_type); + +/** + * Attempt to clean the cache + */ +static void hlcache_clean(void *ignored) +{ + hlcache_entry *entry, *next; + + for (entry = hlcache->content_list; entry != NULL; entry = next) { + next = entry->next; + + if (entry->content == NULL) + continue; + + if (content__get_status(entry->content) == + CONTENT_STATUS_LOADING) + continue; + + if (content_count_users(entry->content) != 0) + continue; + + /** \todo This is over-zealous: all unused contents + * will be immediately destroyed. Ideally, we want to + * purge all unused contents that are using stale + * source data, and enough fresh contents such that + * the cache fits in the configured cache size limit. + */ + + /* Remove entry from cache */ + if (entry->prev == NULL) + hlcache->content_list = entry->next; + else + entry->prev->next = entry->next; + + if (entry->next != NULL) + entry->next->prev = entry->prev; + + /* Destroy content */ + content_destroy(entry->content); + + /* Destroy entry */ + free(entry); + } + + /* Attempt to clean the llcache */ + llcache_clean(); + + /* Re-schedule ourselves */ + schedule(hlcache->params.bg_clean_time / 10, hlcache_clean, NULL); +} + +/** + * Determine if the specified MIME type is acceptable + * + * \param mime_type MIME type to consider + * \param accepted_types Array of acceptable types, or NULL for any + * \param computed_type Pointer to location to receive computed type of object + * \return True if the type is acceptable, false otherwise + */ static bool hlcache_type_is_acceptable(lwc_string *mime_type, - content_type accepted_types, content_type *computed_type); + content_type accepted_types, content_type *computed_type) +{ + content_type type; + + type = content_factory_type_from_mime_type(mime_type); + + *computed_type = type; + + return ((accepted_types & type) != 0); +} + +/** + * Veneer between content callback API and hlcache callback API + * + * \param c Content to emit message for + * \param msg Message to emit + * \param data Data for message + * \param pw Pointer to private data (hlcache_handle) + */ +static void hlcache_content_callback(struct content *c, content_msg msg, + union content_msg_data data, void *pw) +{ + hlcache_handle *handle = pw; + hlcache_event event; + nserror error = NSERROR_OK; + + event.type = msg; + event.data = data; + + if (handle->cb != NULL) + error = handle->cb(handle, &event, handle->pw); + + if (error != NSERROR_OK) + LOG(("Error in callback: %d", error)); +} + +/** + * Find a content for the high-level cache handle + * + * \param ctx High-level cache retrieval context + * \param effective_type Effective MIME type of content + * \return NSERROR_OK on success, + * NSERROR_NEED_DATA on success where data is needed, + * appropriate error otherwise + * + * \pre handle::state == HLCACHE_HANDLE_NEW + * \pre Headers must have been received for associated low-level handle + * \post Low-level handle is either released, or associated with new content + * \post High-level handle is registered with content + */ static nserror hlcache_find_content(hlcache_retrieval_ctx *ctx, - lwc_string *effective_type); -static void hlcache_content_callback(struct content *c, - content_msg msg, union content_msg_data data, void *pw); + lwc_string *effective_type) +{ + hlcache_entry *entry; + hlcache_event event; + nserror error = NSERROR_OK; + + /* Search list of cached contents for a suitable one */ + for (entry = hlcache->content_list; entry != NULL; entry = entry->next) { + hlcache_handle entry_handle = { entry, NULL, NULL }; + const llcache_handle *entry_llcache; + + if (entry->content == NULL) + continue; + + /* Ignore contents in the error state */ + if (content_get_status(&entry_handle) == CONTENT_STATUS_ERROR) + continue; + + /* Ensure that content is shareable */ + if (content_is_shareable(entry->content) == false) + continue; + + /* Ensure that quirks mode is acceptable */ + if (content_matches_quirks(entry->content, + ctx->child.quirks) == false) + continue; + + /* Ensure that content uses same low-level object as + * low-level handle */ + entry_llcache = content_get_llcache_handle(entry->content); + + if (llcache_handle_references_same_object(entry_llcache, + ctx->llcache)) + break; + } + + if (entry == NULL) { + /* No existing entry, so need to create one */ + entry = malloc(sizeof(hlcache_entry)); + if (entry == NULL) + return NSERROR_NOMEM; + + /* Create content using llhandle */ + entry->content = content_factory_create_content(ctx->llcache, + ctx->child.charset, ctx->child.quirks, + effective_type); + if (entry->content == NULL) { + free(entry); + return NSERROR_NOMEM; + } + + /* Insert into cache */ + entry->prev = NULL; + entry->next = hlcache->content_list; + if (hlcache->content_list != NULL) + hlcache->content_list->prev = entry; + hlcache->content_list = entry; + + /* Signal to caller that we created a content */ + error = NSERROR_NEED_DATA; + + hlcache->miss_count++; + } else { + /* Found a suitable content: no longer need low-level handle */ + llcache_handle_release(ctx->llcache); + hlcache->hit_count++; + } + + /* Associate handle with content */ + if (content_add_user(entry->content, + hlcache_content_callback, ctx->handle) == false) + return NSERROR_NOMEM; + + /* Associate cache entry with handle */ + ctx->handle->entry = entry; + + /* Catch handle up with state of content */ + if (ctx->handle->cb != NULL) { + content_status status = content_get_status(ctx->handle); + + if (status == CONTENT_STATUS_LOADING) { + event.type = CONTENT_MSG_LOADING; + ctx->handle->cb(ctx->handle, &event, ctx->handle->pw); + } else if (status == CONTENT_STATUS_READY) { + event.type = CONTENT_MSG_LOADING; + ctx->handle->cb(ctx->handle, &event, ctx->handle->pw); + + if (ctx->handle->cb != NULL) { + event.type = CONTENT_MSG_READY; + ctx->handle->cb(ctx->handle, &event, + ctx->handle->pw); + } + } else if (status == CONTENT_STATUS_DONE) { + event.type = CONTENT_MSG_LOADING; + ctx->handle->cb(ctx->handle, &event, ctx->handle->pw); + + if (ctx->handle->cb != NULL) { + event.type = CONTENT_MSG_READY; + ctx->handle->cb(ctx->handle, &event, + ctx->handle->pw); + } + + if (ctx->handle->cb != NULL) { + event.type = CONTENT_MSG_DONE; + ctx->handle->cb(ctx->handle, &event, + ctx->handle->pw); + } + } + } + + return error; +} + +/** + * Migrate a retrieval context into its final destination content + * + * \param ctx Context to migrate + * \param effective_type The effective MIME type of the content, or NULL + * \return NSERROR_OK on success, + * NSERROR_NEED_DATA on success where data is needed, + * appropriate error otherwise + */ +static nserror hlcache_migrate_ctx(hlcache_retrieval_ctx *ctx, + lwc_string *effective_type) +{ + content_type type = CONTENT_NONE; + nserror error = NSERROR_OK; + + ctx->migrate_target = true; + + if (effective_type != NULL && + hlcache_type_is_acceptable(effective_type, + ctx->accepted_types, &type)) { + error = hlcache_find_content(ctx, effective_type); + if (error != NSERROR_OK && error != NSERROR_NEED_DATA) { + if (ctx->handle->cb != NULL) { + hlcache_event hlevent; + + hlevent.type = CONTENT_MSG_ERROR; + hlevent.data.error = messages_get("MiscError"); + + ctx->handle->cb(ctx->handle, &hlevent, + ctx->handle->pw); + } + + llcache_handle_abort(ctx->llcache); + llcache_handle_release(ctx->llcache); + } + } else if (type == CONTENT_NONE && + (ctx->flags & HLCACHE_RETRIEVE_MAY_DOWNLOAD)) { + /* Unknown type, and we can download, so convert */ + llcache_handle_force_stream(ctx->llcache); + + if (ctx->handle->cb != NULL) { + hlcache_event hlevent; + + hlevent.type = CONTENT_MSG_DOWNLOAD; + hlevent.data.download = ctx->llcache; + + ctx->handle->cb(ctx->handle, &hlevent, + ctx->handle->pw); + } + + /* Ensure caller knows we need data */ + error = NSERROR_NEED_DATA; + } else { + /* Unacceptable type: report error */ + if (ctx->handle->cb != NULL) { + hlcache_event hlevent; + + hlevent.type = CONTENT_MSG_ERROR; + hlevent.data.error = messages_get("UnacceptableType"); + + ctx->handle->cb(ctx->handle, &hlevent, + ctx->handle->pw); + } + + llcache_handle_abort(ctx->llcache); + llcache_handle_release(ctx->llcache); + } + + ctx->migrate_target = false; + + /* No longer require retrieval context */ + RING_REMOVE(hlcache->retrieval_ctx_ring, ctx); + free((char *) ctx->child.charset); + free(ctx); + + return error; +} + +/** + * Handler for low-level cache events + * + * \param handle Handle for which event is issued + * \param event Event data + * \param pw Pointer to client-specific data + * \return NSERROR_OK on success, appropriate error otherwise + */ +static nserror hlcache_llcache_callback(llcache_handle *handle, + const llcache_event *event, void *pw) +{ + hlcache_retrieval_ctx *ctx = pw; + lwc_string *effective_type = NULL; + nserror error; + + assert(ctx->llcache == handle); + + switch (event->type) { + case LLCACHE_EVENT_HAD_HEADERS: + error = mimesniff_compute_effective_type(handle, NULL, 0, + ctx->flags & HLCACHE_RETRIEVE_SNIFF_TYPE, + ctx->accepted_types == CONTENT_IMAGE, + &effective_type); + if (error == NSERROR_OK || error == NSERROR_NOT_FOUND) { + /* If the sniffer was successful or failed to find + * a Content-Type header when sniffing was + * prohibited, we must migrate the retrieval context. */ + error = hlcache_migrate_ctx(ctx, effective_type); + + if (effective_type != NULL) + lwc_string_unref(effective_type); + } + + /* No need to report that we need data: + * we'll get some anyway if there is any */ + if (error == NSERROR_NEED_DATA) + error = NSERROR_OK; + + return error; + + break; + case LLCACHE_EVENT_HAD_DATA: + error = mimesniff_compute_effective_type(handle, + event->data.data.buf, event->data.data.len, + ctx->flags & HLCACHE_RETRIEVE_SNIFF_TYPE, + ctx->accepted_types == CONTENT_IMAGE, + &effective_type); + if (error != NSERROR_OK) { + assert(0 && "MIME sniff failed with data"); + } + + error = hlcache_migrate_ctx(ctx, effective_type); + + lwc_string_unref(effective_type); + + return error; + + break; + case LLCACHE_EVENT_DONE: + /* DONE event before we could determine the effective MIME type. + */ + error = mimesniff_compute_effective_type(handle, + NULL, 0, false, false, &effective_type); + if (error == NSERROR_OK) { + error = hlcache_migrate_ctx(ctx, effective_type); + + lwc_string_unref(effective_type); + + return error; + } + + if (ctx->handle->cb != NULL) { + hlcache_event hlevent; + + hlevent.type = CONTENT_MSG_ERROR; + hlevent.data.error = messages_get("BadType"); + + ctx->handle->cb(ctx->handle, &hlevent, ctx->handle->pw); + } + break; + case LLCACHE_EVENT_ERROR: + if (ctx->handle->cb != NULL) { + hlcache_event hlevent; + + hlevent.type = CONTENT_MSG_ERROR; + hlevent.data.error = event->data.msg; + + ctx->handle->cb(ctx->handle, &hlevent, ctx->handle->pw); + } + break; + case LLCACHE_EVENT_PROGRESS: + break; + case LLCACHE_EVENT_REDIRECT: + if (ctx->handle->cb != NULL) { + hlcache_event hlevent; + + hlevent.type = CONTENT_MSG_REDIRECT; + hlevent.data.redirect.from = event->data.redirect.from; + hlevent.data.redirect.to = event->data.redirect.to; + + ctx->handle->cb(ctx->handle, &hlevent, ctx->handle->pw); + } + break; + } + + return NSERROR_OK; +} + /****************************************************************************** * Public API * ******************************************************************************/ + nserror hlcache_initialise(const struct hlcache_parameters *hlcache_parameters) { @@ -295,7 +698,7 @@ nserror hlcache_handle_release(hlcache_handle *handle) RING_ITERATE_START(struct hlcache_retrieval_ctx, hlcache->retrieval_ctx_ring, ictx) { - if (ictx->handle == handle && + if (ictx->handle == handle && ictx->migrate_target == false) { /* This is the nascent context for us, * so abort the fetch */ @@ -347,7 +750,7 @@ nserror hlcache_handle_abort(hlcache_handle *handle) RING_ITERATE_START(struct hlcache_retrieval_ctx, hlcache->retrieval_ctx_ring, ictx) { - if (ictx->handle == handle && + if (ictx->handle == handle && ictx->migrate_target == false) { /* This is the nascent context for us, * so abort the fetch */ @@ -448,416 +851,3 @@ nsurl *hlcache_handle_get_url(const hlcache_handle *handle) return result; } - -/****************************************************************************** - * High-level cache internals * - ******************************************************************************/ - -/** - * Attempt to clean the cache - */ -void hlcache_clean(void *ignored) -{ - hlcache_entry *entry, *next; - - for (entry = hlcache->content_list; entry != NULL; entry = next) { - next = entry->next; - - if (entry->content == NULL) - continue; - - if (content__get_status(entry->content) == - CONTENT_STATUS_LOADING) - continue; - - if (content_count_users(entry->content) != 0) - continue; - - /** \todo This is over-zealous: all unused contents - * will be immediately destroyed. Ideally, we want to - * purge all unused contents that are using stale - * source data, and enough fresh contents such that - * the cache fits in the configured cache size limit. - */ - - /* Remove entry from cache */ - if (entry->prev == NULL) - hlcache->content_list = entry->next; - else - entry->prev->next = entry->next; - - if (entry->next != NULL) - entry->next->prev = entry->prev; - - /* Destroy content */ - content_destroy(entry->content); - - /* Destroy entry */ - free(entry); - } - - /* Attempt to clean the llcache */ - llcache_clean(); - - /* Re-schedule ourselves */ - schedule(hlcache->params.bg_clean_time / 10, hlcache_clean, NULL); -} - -/** - * Handler for low-level cache events - * - * \param handle Handle for which event is issued - * \param event Event data - * \param pw Pointer to client-specific data - * \return NSERROR_OK on success, appropriate error otherwise - */ -nserror hlcache_llcache_callback(llcache_handle *handle, - const llcache_event *event, void *pw) -{ - hlcache_retrieval_ctx *ctx = pw; - lwc_string *effective_type = NULL; - nserror error; - - assert(ctx->llcache == handle); - - switch (event->type) { - case LLCACHE_EVENT_HAD_HEADERS: - error = mimesniff_compute_effective_type(handle, NULL, 0, - ctx->flags & HLCACHE_RETRIEVE_SNIFF_TYPE, - ctx->accepted_types == CONTENT_IMAGE, - &effective_type); - if (error == NSERROR_OK || error == NSERROR_NOT_FOUND) { - /* If the sniffer was successful or failed to find - * a Content-Type header when sniffing was - * prohibited, we must migrate the retrieval context. */ - error = hlcache_migrate_ctx(ctx, effective_type); - - if (effective_type != NULL) - lwc_string_unref(effective_type); - } - - /* No need to report that we need data: - * we'll get some anyway if there is any */ - if (error == NSERROR_NEED_DATA) - error = NSERROR_OK; - - return error; - - break; - case LLCACHE_EVENT_HAD_DATA: - error = mimesniff_compute_effective_type(handle, - event->data.data.buf, event->data.data.len, - ctx->flags & HLCACHE_RETRIEVE_SNIFF_TYPE, - ctx->accepted_types == CONTENT_IMAGE, - &effective_type); - if (error != NSERROR_OK) { - assert(0 && "MIME sniff failed with data"); - } - - error = hlcache_migrate_ctx(ctx, effective_type); - - lwc_string_unref(effective_type); - - return error; - - break; - case LLCACHE_EVENT_DONE: - /* DONE event before we could determine the effective MIME type. - */ - error = mimesniff_compute_effective_type(handle, - NULL, 0, false, false, &effective_type); - if (error == NSERROR_OK) { - error = hlcache_migrate_ctx(ctx, effective_type); - - lwc_string_unref(effective_type); - - return error; - } - - if (ctx->handle->cb != NULL) { - hlcache_event hlevent; - - hlevent.type = CONTENT_MSG_ERROR; - hlevent.data.error = messages_get("BadType"); - - ctx->handle->cb(ctx->handle, &hlevent, ctx->handle->pw); - } - break; - case LLCACHE_EVENT_ERROR: - if (ctx->handle->cb != NULL) { - hlcache_event hlevent; - - hlevent.type = CONTENT_MSG_ERROR; - hlevent.data.error = event->data.msg; - - ctx->handle->cb(ctx->handle, &hlevent, ctx->handle->pw); - } - break; - case LLCACHE_EVENT_PROGRESS: - break; - case LLCACHE_EVENT_REDIRECT: - if (ctx->handle->cb != NULL) { - hlcache_event hlevent; - - hlevent.type = CONTENT_MSG_REDIRECT; - hlevent.data.redirect.from = event->data.redirect.from; - hlevent.data.redirect.to = event->data.redirect.to; - - ctx->handle->cb(ctx->handle, &hlevent, ctx->handle->pw); - } - break; - } - - return NSERROR_OK; -} - -/** - * Migrate a retrieval context into its final destination content - * - * \param ctx Context to migrate - * \param effective_type The effective MIME type of the content, or NULL - * \return NSERROR_OK on success, - * NSERROR_NEED_DATA on success where data is needed, - * appropriate error otherwise - */ -nserror hlcache_migrate_ctx(hlcache_retrieval_ctx *ctx, - lwc_string *effective_type) -{ - content_type type = CONTENT_NONE; - nserror error = NSERROR_OK; - - ctx->migrate_target = true; - - if (effective_type != NULL && - hlcache_type_is_acceptable(effective_type, - ctx->accepted_types, &type)) { - error = hlcache_find_content(ctx, effective_type); - if (error != NSERROR_OK && error != NSERROR_NEED_DATA) { - if (ctx->handle->cb != NULL) { - hlcache_event hlevent; - - hlevent.type = CONTENT_MSG_ERROR; - hlevent.data.error = messages_get("MiscError"); - - ctx->handle->cb(ctx->handle, &hlevent, - ctx->handle->pw); - } - - llcache_handle_abort(ctx->llcache); - llcache_handle_release(ctx->llcache); - } - } else if (type == CONTENT_NONE && - (ctx->flags & HLCACHE_RETRIEVE_MAY_DOWNLOAD)) { - /* Unknown type, and we can download, so convert */ - llcache_handle_force_stream(ctx->llcache); - - if (ctx->handle->cb != NULL) { - hlcache_event hlevent; - - hlevent.type = CONTENT_MSG_DOWNLOAD; - hlevent.data.download = ctx->llcache; - - ctx->handle->cb(ctx->handle, &hlevent, - ctx->handle->pw); - } - - /* Ensure caller knows we need data */ - error = NSERROR_NEED_DATA; - } else { - /* Unacceptable type: report error */ - if (ctx->handle->cb != NULL) { - hlcache_event hlevent; - - hlevent.type = CONTENT_MSG_ERROR; - hlevent.data.error = messages_get("UnacceptableType"); - - ctx->handle->cb(ctx->handle, &hlevent, - ctx->handle->pw); - } - - llcache_handle_abort(ctx->llcache); - llcache_handle_release(ctx->llcache); - } - - ctx->migrate_target = false; - - /* No longer require retrieval context */ - RING_REMOVE(hlcache->retrieval_ctx_ring, ctx); - free((char *) ctx->child.charset); - free(ctx); - - return error; -} - -/** - * Determine if the specified MIME type is acceptable - * - * \param mime_type MIME type to consider - * \param accepted_types Array of acceptable types, or NULL for any - * \param computed_type Pointer to location to receive computed type of object - * \return True if the type is acceptable, false otherwise - */ -bool hlcache_type_is_acceptable(lwc_string *mime_type, - content_type accepted_types, content_type *computed_type) -{ - content_type type; - - type = content_factory_type_from_mime_type(mime_type); - - *computed_type = type; - - return ((accepted_types & type) != 0); -} - -/** - * Find a content for the high-level cache handle - * - * \param ctx High-level cache retrieval context - * \param effective_type Effective MIME type of content - * \return NSERROR_OK on success, - * NSERROR_NEED_DATA on success where data is needed, - * appropriate error otherwise - * - * \pre handle::state == HLCACHE_HANDLE_NEW - * \pre Headers must have been received for associated low-level handle - * \post Low-level handle is either released, or associated with new content - * \post High-level handle is registered with content - */ -nserror hlcache_find_content(hlcache_retrieval_ctx *ctx, - lwc_string *effective_type) -{ - hlcache_entry *entry; - hlcache_event event; - nserror error = NSERROR_OK; - - /* Search list of cached contents for a suitable one */ - for (entry = hlcache->content_list; entry != NULL; entry = entry->next) { - hlcache_handle entry_handle = { entry, NULL, NULL }; - const llcache_handle *entry_llcache; - - if (entry->content == NULL) - continue; - - /* Ignore contents in the error state */ - if (content_get_status(&entry_handle) == CONTENT_STATUS_ERROR) - continue; - - /* Ensure that content is shareable */ - if (content_is_shareable(entry->content) == false) - continue; - - /* Ensure that quirks mode is acceptable */ - if (content_matches_quirks(entry->content, - ctx->child.quirks) == false) - continue; - - /* Ensure that content uses same low-level object as - * low-level handle */ - entry_llcache = content_get_llcache_handle(entry->content); - - if (llcache_handle_references_same_object(entry_llcache, - ctx->llcache)) - break; - } - - if (entry == NULL) { - /* No existing entry, so need to create one */ - entry = malloc(sizeof(hlcache_entry)); - if (entry == NULL) - return NSERROR_NOMEM; - - /* Create content using llhandle */ - entry->content = content_factory_create_content(ctx->llcache, - ctx->child.charset, ctx->child.quirks, - effective_type); - if (entry->content == NULL) { - free(entry); - return NSERROR_NOMEM; - } - - /* Insert into cache */ - entry->prev = NULL; - entry->next = hlcache->content_list; - if (hlcache->content_list != NULL) - hlcache->content_list->prev = entry; - hlcache->content_list = entry; - - /* Signal to caller that we created a content */ - error = NSERROR_NEED_DATA; - - hlcache->miss_count++; - } else { - /* Found a suitable content: no longer need low-level handle */ - llcache_handle_release(ctx->llcache); - hlcache->hit_count++; - } - - /* Associate handle with content */ - if (content_add_user(entry->content, - hlcache_content_callback, ctx->handle) == false) - return NSERROR_NOMEM; - - /* Associate cache entry with handle */ - ctx->handle->entry = entry; - - /* Catch handle up with state of content */ - if (ctx->handle->cb != NULL) { - content_status status = content_get_status(ctx->handle); - - if (status == CONTENT_STATUS_LOADING) { - event.type = CONTENT_MSG_LOADING; - ctx->handle->cb(ctx->handle, &event, ctx->handle->pw); - } else if (status == CONTENT_STATUS_READY) { - event.type = CONTENT_MSG_LOADING; - ctx->handle->cb(ctx->handle, &event, ctx->handle->pw); - - if (ctx->handle->cb != NULL) { - event.type = CONTENT_MSG_READY; - ctx->handle->cb(ctx->handle, &event, - ctx->handle->pw); - } - } else if (status == CONTENT_STATUS_DONE) { - event.type = CONTENT_MSG_LOADING; - ctx->handle->cb(ctx->handle, &event, ctx->handle->pw); - - if (ctx->handle->cb != NULL) { - event.type = CONTENT_MSG_READY; - ctx->handle->cb(ctx->handle, &event, - ctx->handle->pw); - } - - if (ctx->handle->cb != NULL) { - event.type = CONTENT_MSG_DONE; - ctx->handle->cb(ctx->handle, &event, - ctx->handle->pw); - } - } - } - - return error; -} - -/** - * Veneer between content callback API and hlcache callback API - * - * \param c Content to emit message for - * \param msg Message to emit - * \param data Data for message - * \param pw Pointer to private data (hlcache_handle) - */ -void hlcache_content_callback(struct content *c, content_msg msg, - union content_msg_data data, void *pw) -{ - hlcache_handle *handle = pw; - hlcache_event event; - nserror error = NSERROR_OK; - - event.type = msg; - event.data = data; - - if (handle->cb != NULL) - error = handle->cb(handle, &event, handle->pw); - - if (error != NSERROR_OK) - LOG(("Error in callback: %d", error)); -} From 4987a3a8a7baccf0fe546c5ff8ff02c6f769d439 Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Sun, 19 Jan 2014 18:17:32 +0000 Subject: [PATCH 109/773] remove forward refs from content/fetch.c and cleanup doc comments --- content/fetch.c | 638 +++++++++++++++++++++------------------------- content/fetch.h | 160 +++++++++--- desktop/netsurf.c | 5 +- 3 files changed, 422 insertions(+), 381 deletions(-) diff --git a/content/fetch.c b/content/fetch.c index a9a9049f2..2d53b3149 100644 --- a/content/fetch.c +++ b/content/fetch.c @@ -85,7 +85,7 @@ struct fetch { lwc_string *host; /**< Host part of URL, interned */ long http_code; /**< HTTP response code, or 0. */ scheme_fetcher *ops; /**< Fetcher operations for this fetch, - NULL if not set. */ + NULL if not set. */ void *fetcher_handle; /**< The handle for the fetcher. */ bool fetch_is_active; /**< This fetch is active. */ struct fetch *r_prev; /**< Previous active fetch in ::fetch_ring. */ @@ -96,101 +96,16 @@ static struct fetch *fetch_ring = 0; /**< Ring of active fetches. */ static struct fetch *queue_ring = 0; /**< Ring of queued fetches */ #define fetch_ref_fetcher(F) F->refcount++ -static void fetch_unref_fetcher(scheme_fetcher *fetcher); -static void fetch_dispatch_jobs(void); -static bool fetch_choose_and_dispatch(void); -static bool fetch_dispatch_job(struct fetch *fetch); /* Static lwc_strings */ static lwc_string *fetch_http_lwc; static lwc_string *fetch_https_lwc; +/****************************************************************************** + * fetch internals * + ******************************************************************************/ -/** - * Initialise the fetcher. - */ - -void fetch_init(void) -{ - fetch_curl_register(); - fetch_data_register(); - fetch_file_register(); - fetch_resource_register(); - fetch_about_register(); - fetch_active = false; - - if (lwc_intern_string("http", SLEN("http"), &fetch_http_lwc) != - lwc_error_ok) { - die("Failed to initialise the fetch module " - "(couldn't intern \"http\")."); - } - - if (lwc_intern_string("https", SLEN("https"), &fetch_https_lwc) != - lwc_error_ok) { - die("Failed to initialise the fetch module " - "(couldn't intern \"https\")."); - } -} - - -/** - * Clean up for quit. - * - * Must be called before exiting. - */ - -void fetch_quit(void) -{ - while (fetchers != NULL) { - if (fetchers->refcount != 1) { - LOG(("Fetcher for scheme %s still active?!", - lwc_string_data(fetchers->scheme_name))); - /* We shouldn't do this, but... */ - fetchers->refcount = 1; - } - fetch_unref_fetcher(fetchers); - } - - lwc_string_unref(fetch_http_lwc); - lwc_string_unref(fetch_https_lwc); -} - - -bool fetch_add_fetcher(lwc_string *scheme, - fetcher_initialise initialiser, - fetcher_can_fetch can_fetch, - fetcher_setup_fetch setup_fetch, - fetcher_start_fetch start_fetch, - fetcher_abort_fetch abort_fetch, - fetcher_free_fetch free_fetch, - fetcher_poll_fetcher poll_fetcher, - fetcher_finalise finaliser) -{ - scheme_fetcher *new_fetcher; - if (!initialiser(scheme)) - return false; - new_fetcher = malloc(sizeof(scheme_fetcher)); - if (new_fetcher == NULL) { - finaliser(scheme); - return false; - } - new_fetcher->scheme_name = scheme; - new_fetcher->refcount = 0; - new_fetcher->can_fetch = can_fetch; - new_fetcher->setup_fetch = setup_fetch; - new_fetcher->start_fetch = start_fetch; - new_fetcher->abort_fetch = abort_fetch; - new_fetcher->free_fetch = free_fetch; - new_fetcher->poll_fetcher = poll_fetcher; - new_fetcher->finaliser = finaliser; - new_fetcher->next_fetcher = fetchers; - fetchers = new_fetcher; - fetch_ref_fetcher(new_fetcher); - return true; -} - - -void fetch_unref_fetcher(scheme_fetcher *fetcher) +static void fetch_unref_fetcher(scheme_fetcher *fetcher) { if (--fetcher->refcount == 0) { fetcher->finaliser(fetcher->scheme_name); @@ -201,169 +116,76 @@ void fetch_unref_fetcher(scheme_fetcher *fetcher) fetchers->prev_fetcher = NULL; } else { fetcher->prev_fetcher->next_fetcher = - fetcher->next_fetcher; + fetcher->next_fetcher; if (fetcher->next_fetcher != NULL) fetcher->next_fetcher->prev_fetcher = - fetcher->prev_fetcher; + fetcher->prev_fetcher; } free(fetcher); } } - /** - * Start fetching data for the given URL. - * - * The function returns immediately. The fetch may be queued for later - * processing. - * - * A pointer to an opaque struct fetch is returned, which can be passed to - * fetch_abort() to abort the fetch at any time. Returns 0 if memory is - * exhausted (or some other fatal error occurred). - * - * The caller must supply a callback function which is called when anything - * interesting happens. The callback function is first called with msg - * FETCH_HEADER, with the header in data, then one or more times - * with FETCH_DATA with some data for the url, and finally with - * FETCH_FINISHED. Alternatively, FETCH_ERROR indicates an error occurred: - * data contains an error message. FETCH_REDIRECT may replace the FETCH_HEADER, - * FETCH_DATA, FETCH_FINISHED sequence if the server sends a replacement URL. - * + * Dispatch a single job */ - -struct fetch * fetch_start(nsurl *url, nsurl *referer, - fetch_callback callback, - void *p, bool only_2xx, const char *post_urlenc, - const struct fetch_multipart_data *post_multipart, - bool verifiable, bool downgrade_tls, - const char *headers[]) +static bool fetch_dispatch_job(struct fetch *fetch) { - struct fetch *fetch; - scheme_fetcher *fetcher = fetchers; - lwc_string *scheme; - bool match; - - fetch = malloc(sizeof (*fetch)); - if (fetch == NULL) - return NULL; - - /* The URL we're fetching must have a scheme */ - scheme = nsurl_get_component(url, NSURL_SCHEME); - assert(scheme != NULL); - + RING_REMOVE(queue_ring, fetch); #ifdef DEBUG_FETCH_VERBOSE - LOG(("fetch %p, url '%s'", fetch, nsurl_access(url))); + LOG(("Attempting to start fetch %p, fetcher %p, url %s", fetch, + fetch->fetcher_handle, nsurl_access(fetch->url))); #endif - - /* construct a new fetch structure */ - fetch->callback = callback; - fetch->url = nsurl_ref(url); - fetch->verifiable = verifiable; - fetch->p = p; - fetch->http_code = 0; - fetch->r_prev = NULL; - fetch->r_next = NULL; - fetch->referer = NULL; - fetch->send_referer = false; - fetch->fetcher_handle = NULL; - fetch->ops = NULL; - fetch->fetch_is_active = false; - fetch->host = nsurl_get_component(url, NSURL_HOST); - - if (referer != NULL) { - lwc_string *ref_scheme; - fetch->referer = nsurl_ref(referer); - - ref_scheme = nsurl_get_component(referer, NSURL_SCHEME); - /* Not a problem if referer has no scheme */ - - /* Determine whether to send the Referer header */ - if (nsoption_bool(send_referer) && ref_scheme != NULL) { - /* User permits us to send the header - * Only send it if: - * 1) The fetch and referer schemes match - * or 2) The fetch is https and the referer is http - * - * This ensures that referer information is only sent - * across schemes in the special case of an https - * request from a page served over http. The inverse - * (https -> http) should not send the referer (15.1.3) - */ - bool match1; - bool match2; - if (lwc_string_isequal(scheme, ref_scheme, - &match) != lwc_error_ok) { - match = false; - } - if (lwc_string_isequal(scheme, fetch_https_lwc, - &match1) != lwc_error_ok) { - match1 = false; - } - if (lwc_string_isequal(ref_scheme, fetch_http_lwc, - &match2) != lwc_error_ok) { - match2= false; - } - if (match == true || (match1 == true && match2 == true)) - fetch->send_referer = true; - } - if (ref_scheme != NULL) - lwc_string_unref(ref_scheme); + if (!fetch->ops->start_fetch(fetch->fetcher_handle)) { + RING_INSERT(queue_ring, fetch); /* Put it back on the end of the queue */ + return false; + } else { + RING_INSERT(fetch_ring, fetch); + fetch->fetch_is_active = true; + return true; } - - /* Pick the scheme ops */ - while (fetcher) { - if ((lwc_string_isequal(fetcher->scheme_name, scheme, - &match) == lwc_error_ok) && (match == true)) { - fetch->ops = fetcher; - break; - } - fetcher = fetcher->next_fetcher; - } - - if (fetch->ops == NULL) - goto failed; - - /* Got a scheme fetcher, try and set up the fetch */ - fetch->fetcher_handle = fetch->ops->setup_fetch(fetch, url, - only_2xx, downgrade_tls, - post_urlenc, post_multipart, - headers); - - if (fetch->fetcher_handle == NULL) - goto failed; - - /* Rah, got it, so ref the fetcher. */ - fetch_ref_fetcher(fetch->ops); - - /* these aren't needed past here */ - lwc_string_unref(scheme); - - /* Dump us in the queue and ask the queue to run. */ - RING_INSERT(queue_ring, fetch); - fetch_dispatch_jobs(); - - return fetch; - -failed: - lwc_string_unref(scheme); - - if (fetch->host != NULL) - lwc_string_unref(fetch->host); - if (fetch->url != NULL) - nsurl_unref(fetch->url); - if (fetch->referer != NULL) - nsurl_unref(fetch->referer); - - free(fetch); - - return NULL; } +/** + * Choose and dispatch a single job. Return false if we failed to dispatch + * anything. + * + * We don't check the overall dispatch size here because we're not called unless + * there is room in the fetch queue for us. + */ +static bool fetch_choose_and_dispatch(void) +{ + bool same_host; + struct fetch *queueitem; + queueitem = queue_ring; + do { + /* We can dispatch the selected item if there is room in the + * fetch ring + */ + int countbyhost; + RING_COUNTBYLWCHOST(struct fetch, fetch_ring, countbyhost, + queueitem->host); + if (countbyhost < nsoption_int(max_fetchers_per_host)) { + /* We can dispatch this item in theory */ + return fetch_dispatch_job(queueitem); + } + /* skip over other items with the same host */ + same_host = true; + while (same_host == true && queueitem->r_next != queue_ring) { + if (lwc_string_isequal(queueitem->host, + queueitem->r_next->host, &same_host) == + lwc_error_ok && same_host == true) { + queueitem = queueitem->r_next; + } + } + queueitem = queueitem->r_next; + } while (queueitem != queue_ring); + return false; +} /** * Dispatch as many jobs as we have room to dispatch. */ -void fetch_dispatch_jobs(void) +static void fetch_dispatch_jobs(void) { int all_active, all_queued; #ifdef DEBUG_FETCH_VERBOSE @@ -412,85 +234,231 @@ void fetch_dispatch_jobs(void) #endif } +/****************************************************************************** + * Public API * + ******************************************************************************/ -/** - * Choose and dispatch a single job. Return false if we failed to dispatch - * anything. - * - * We don't check the overall dispatch size here because we're not called unless - * there is room in the fetch queue for us. - */ -bool fetch_choose_and_dispatch(void) +/* exported interface documented in content/fetch.h */ +nserror fetch_init(void) { - bool same_host; - struct fetch *queueitem; - queueitem = queue_ring; - do { - /* We can dispatch the selected item if there is room in the - * fetch ring - */ - int countbyhost; - RING_COUNTBYLWCHOST(struct fetch, fetch_ring, countbyhost, - queueitem->host); - if (countbyhost < nsoption_int(max_fetchers_per_host)) { - /* We can dispatch this item in theory */ - return fetch_dispatch_job(queueitem); - } - /* skip over other items with the same host */ - same_host = true; - while (same_host == true && queueitem->r_next != queue_ring) { - if (lwc_string_isequal(queueitem->host, - queueitem->r_next->host, &same_host) == - lwc_error_ok && same_host == true) { - queueitem = queueitem->r_next; - } - } - queueitem = queueitem->r_next; - } while (queueitem != queue_ring); - return false; -} - - -/** - * Dispatch a single job - */ -bool fetch_dispatch_job(struct fetch *fetch) -{ - RING_REMOVE(queue_ring, fetch); -#ifdef DEBUG_FETCH_VERBOSE - LOG(("Attempting to start fetch %p, fetcher %p, url %s", fetch, - fetch->fetcher_handle, nsurl_access(fetch->url))); -#endif - if (!fetch->ops->start_fetch(fetch->fetcher_handle)) { - RING_INSERT(queue_ring, fetch); /* Put it back on the end of the queue */ - return false; - } else { - RING_INSERT(fetch_ring, fetch); - fetch->fetch_is_active = true; - return true; + if (lwc_intern_string("http", SLEN("http"), &fetch_http_lwc) != + lwc_error_ok) { + LOG(("Failed to initialise the fetch module " + "(couldn't intern \"http\").")); + return NSERROR_INIT_FAILED; } + + if (lwc_intern_string("https", SLEN("https"), &fetch_https_lwc) != + lwc_error_ok) { + LOG(("Failed to initialise the fetch module " + "(couldn't intern \"https\").")); + return NSERROR_INIT_FAILED; + } + + fetch_curl_register(); + fetch_data_register(); + fetch_file_register(); + fetch_resource_register(); + fetch_about_register(); + + fetch_active = false; + + return NSERROR_OK; } +/* exported interface documented in content/fetch.h */ +void fetch_quit(void) +{ + while (fetchers != NULL) { + if (fetchers->refcount != 1) { + LOG(("Fetcher for scheme %s still active?!", + lwc_string_data(fetchers->scheme_name))); + /* We shouldn't do this, but... */ + fetchers->refcount = 1; + } + fetch_unref_fetcher(fetchers); + } -/** - * Abort a fetch. - */ + lwc_string_unref(fetch_http_lwc); + lwc_string_unref(fetch_https_lwc); +} +/* exported interface documented in content/fetch.h */ +bool fetch_add_fetcher(lwc_string *scheme, + fetcher_initialise initialiser, + fetcher_can_fetch can_fetch, + fetcher_setup_fetch setup_fetch, + fetcher_start_fetch start_fetch, + fetcher_abort_fetch abort_fetch, + fetcher_free_fetch free_fetch, + fetcher_poll_fetcher poll_fetcher, + fetcher_finalise finaliser) +{ + scheme_fetcher *new_fetcher; + if (!initialiser(scheme)) + return false; + new_fetcher = malloc(sizeof(scheme_fetcher)); + if (new_fetcher == NULL) { + finaliser(scheme); + return false; + } + new_fetcher->scheme_name = scheme; + new_fetcher->refcount = 0; + new_fetcher->can_fetch = can_fetch; + new_fetcher->setup_fetch = setup_fetch; + new_fetcher->start_fetch = start_fetch; + new_fetcher->abort_fetch = abort_fetch; + new_fetcher->free_fetch = free_fetch; + new_fetcher->poll_fetcher = poll_fetcher; + new_fetcher->finaliser = finaliser; + new_fetcher->next_fetcher = fetchers; + fetchers = new_fetcher; + fetch_ref_fetcher(new_fetcher); + + return true; +} + +/* exported interface documented in content/fetch.h */ +struct fetch * fetch_start(nsurl *url, nsurl *referer, + fetch_callback callback, + void *p, bool only_2xx, const char *post_urlenc, + const struct fetch_multipart_data *post_multipart, + bool verifiable, bool downgrade_tls, + const char *headers[]) +{ + struct fetch *fetch; + scheme_fetcher *fetcher = fetchers; + lwc_string *scheme; + bool match; + + fetch = malloc(sizeof (*fetch)); + if (fetch == NULL) + return NULL; + + /* The URL we're fetching must have a scheme */ + scheme = nsurl_get_component(url, NSURL_SCHEME); + assert(scheme != NULL); + +#ifdef DEBUG_FETCH_VERBOSE + LOG(("fetch %p, url '%s'", fetch, nsurl_access(url))); +#endif + + /* construct a new fetch structure */ + fetch->callback = callback; + fetch->url = nsurl_ref(url); + fetch->verifiable = verifiable; + fetch->p = p; + fetch->http_code = 0; + fetch->r_prev = NULL; + fetch->r_next = NULL; + fetch->referer = NULL; + fetch->send_referer = false; + fetch->fetcher_handle = NULL; + fetch->ops = NULL; + fetch->fetch_is_active = false; + fetch->host = nsurl_get_component(url, NSURL_HOST); + + if (referer != NULL) { + lwc_string *ref_scheme; + fetch->referer = nsurl_ref(referer); + + ref_scheme = nsurl_get_component(referer, NSURL_SCHEME); + /* Not a problem if referer has no scheme */ + + /* Determine whether to send the Referer header */ + if (nsoption_bool(send_referer) && ref_scheme != NULL) { + /* User permits us to send the header + * Only send it if: + * 1) The fetch and referer schemes match + * or 2) The fetch is https and the referer is http + * + * This ensures that referer information is only sent + * across schemes in the special case of an https + * request from a page served over http. The inverse + * (https -> http) should not send the referer (15.1.3) + */ + bool match1; + bool match2; + if (lwc_string_isequal(scheme, ref_scheme, + &match) != lwc_error_ok) { + match = false; + } + if (lwc_string_isequal(scheme, fetch_https_lwc, + &match1) != lwc_error_ok) { + match1 = false; + } + if (lwc_string_isequal(ref_scheme, fetch_http_lwc, + &match2) != lwc_error_ok) { + match2= false; + } + if (match == true || (match1 == true && match2 == true)) + fetch->send_referer = true; + } + if (ref_scheme != NULL) + lwc_string_unref(ref_scheme); + } + + /* Pick the scheme ops */ + while (fetcher) { + if ((lwc_string_isequal(fetcher->scheme_name, scheme, + &match) == lwc_error_ok) && (match == true)) { + fetch->ops = fetcher; + break; + } + fetcher = fetcher->next_fetcher; + } + + if (fetch->ops == NULL) + goto failed; + + /* Got a scheme fetcher, try and set up the fetch */ + fetch->fetcher_handle = fetch->ops->setup_fetch(fetch, url, + only_2xx, downgrade_tls, + post_urlenc, post_multipart, + headers); + + if (fetch->fetcher_handle == NULL) + goto failed; + + /* Rah, got it, so ref the fetcher. */ + fetch_ref_fetcher(fetch->ops); + + /* these aren't needed past here */ + lwc_string_unref(scheme); + + /* Dump us in the queue and ask the queue to run. */ + RING_INSERT(queue_ring, fetch); + fetch_dispatch_jobs(); + + return fetch; + +failed: + lwc_string_unref(scheme); + + if (fetch->host != NULL) + lwc_string_unref(fetch->host); + if (fetch->url != NULL) + nsurl_unref(fetch->url); + if (fetch->referer != NULL) + nsurl_unref(fetch->referer); + + free(fetch); + + return NULL; +} + +/* exported interface documented in content/fetch.h */ void fetch_abort(struct fetch *f) { assert(f); #ifdef DEBUG_FETCH_VERBOSE LOG(("fetch %p, fetcher %p, url '%s'", f, f->fetcher_handle, - nsurl_access(f->url))); + nsurl_access(f->url))); #endif f->ops->abort_fetch(f->fetcher_handle); } - -/** - * Free a fetch structure and associated resources. - */ - +/* exported interface documented in content/fetch.h */ void fetch_free(struct fetch *f) { #ifdef DEBUG_FETCH_VERBOSE @@ -503,16 +471,10 @@ void fetch_free(struct fetch *f) nsurl_unref(f->referer); if (f->host != NULL) lwc_string_unref(f->host); - free(f); + free(f); } - -/** - * Do some work on current fetches. - * - * Must be called regularly to make progress on fetches. - */ - +/* exported interface documented in content/fetch.h */ void fetch_poll(void) { scheme_fetcher *fetcher = fetchers; @@ -533,14 +495,7 @@ void fetch_poll(void) } } - -/** - * Check if a URL's scheme can be fetched. - * - * \param url URL to check - * \return true if the scheme is supported - */ - +/* exported interface documented in content/fetch.h */ bool fetch_can_fetch(const nsurl *url) { scheme_fetcher *fetcher = fetchers; @@ -560,11 +515,7 @@ bool fetch_can_fetch(const nsurl *url) return fetcher == NULL ? false : fetcher->can_fetch(url); } - -/** - * Change the callback function for a fetch. - */ - +/* exported interface documented in content/fetch.h */ void fetch_change_callback(struct fetch *fetch, fetch_callback callback, void *p) @@ -574,22 +525,13 @@ void fetch_change_callback(struct fetch *fetch, fetch->p = p; } - -/** - * Get the HTTP response code. - */ - +/* exported interface documented in content/fetch.h */ long fetch_http_code(struct fetch *fetch) { return fetch->http_code; } -/** - * Determine if a fetch was verifiable - * - * \param fetch Fetch to consider - * \return Verifiable status of fetch - */ +/* exported interface documented in content/fetch.h */ bool fetch_get_verifiable(struct fetch *fetch) { assert(fetch); @@ -597,14 +539,9 @@ bool fetch_get_verifiable(struct fetch *fetch) return fetch->verifiable; } -/** - * Clone a linked list of fetch_multipart_data. - * - * \param list List to clone - * \return Pointer to head of cloned list, or NULL on failure - */ -struct fetch_multipart_data *fetch_multipart_data_clone( - const struct fetch_multipart_data *list) +/* exported interface documented in content/fetch.h */ +struct fetch_multipart_data * +fetch_multipart_data_clone(const struct fetch_multipart_data *list) { struct fetch_multipart_data *clone, *last = NULL; struct fetch_multipart_data *result = NULL; @@ -667,11 +604,7 @@ struct fetch_multipart_data *fetch_multipart_data_clone( return result; } -/** - * Free a linked list of fetch_multipart_data. - * - * \param list Pointer to head of list to free - */ +/* exported interface documented in content/fetch.h */ void fetch_multipart_data_destroy(struct fetch_multipart_data *list) { struct fetch_multipart_data *next; @@ -688,6 +621,7 @@ void fetch_multipart_data_destroy(struct fetch_multipart_data *list) } } +/* exported interface documented in content/fetch.h */ void fetch_send_callback(const fetch_msg *msg, struct fetch *fetch) { @@ -695,15 +629,17 @@ fetch_send_callback(const fetch_msg *msg, struct fetch *fetch) } +/* exported interface documented in content/fetch.h */ void fetch_remove_from_queues(struct fetch *fetch) { - int all_active, all_queued; + int all_active; - /* Go ahead and free the fetch properly now */ #ifdef DEBUG_FETCH_VERBOSE + int all_queued; LOG(("Fetch %p, fetcher %p can be freed", fetch, fetch->fetcher_handle)); #endif + /* Go ahead and free the fetch properly now */ if (fetch->fetch_is_active) { RING_REMOVE(fetch_ring, fetch); } else { @@ -711,19 +647,21 @@ void fetch_remove_from_queues(struct fetch *fetch) } RING_GETSIZE(struct fetch, fetch_ring, all_active); - RING_GETSIZE(struct fetch, queue_ring, all_queued); fetch_active = (all_active > 0); #ifdef DEBUG_FETCH_VERBOSE LOG(("Fetch ring is now %d elements.", all_active)); + + RING_GETSIZE(struct fetch, queue_ring, all_queued); + LOG(("Queue ring is now %d elements.", all_queued)); #endif } -void -fetch_set_http_code(struct fetch *fetch, long http_code) +/* exported interface documented in content/fetch.h */ +void fetch_set_http_code(struct fetch *fetch, long http_code) { #ifdef DEBUG_FETCH_VERBOSE LOG(("Setting HTTP code to %ld", http_code)); @@ -731,6 +669,7 @@ fetch_set_http_code(struct fetch *fetch, long http_code) fetch->http_code = http_code; } +/* exported interface documented in content/fetch.h */ const char *fetch_get_referer_to_send(struct fetch *fetch) { if (fetch->send_referer) @@ -738,8 +677,8 @@ const char *fetch_get_referer_to_send(struct fetch *fetch) return NULL; } -void -fetch_set_cookie(struct fetch *fetch, const char *data) +/* exported interface documented in content/fetch.h */ +void fetch_set_cookie(struct fetch *fetch, const char *data) { assert(fetch && data); @@ -762,4 +701,3 @@ fetch_set_cookie(struct fetch *fetch, const char *data) urldb_set_cookie(data, fetch->url, fetch->referer); } } - diff --git a/content/fetch.h b/content/fetch.h index a173f7f30..09b7c8d44 100644 --- a/content/fetch.h +++ b/content/fetch.h @@ -99,29 +99,136 @@ extern bool fetch_active; typedef void (*fetch_callback)(const fetch_msg *msg, void *p); - -void fetch_init(void); -struct fetch * fetch_start(nsurl *url, nsurl *referer, - fetch_callback callback, - void *p, bool only_2xx, const char *post_urlenc, - const struct fetch_multipart_data *post_multipart, - bool verifiable, bool downgrade_tls, - const char *headers[]); -void fetch_abort(struct fetch *f); -void fetch_poll(void); -void fetch_quit(void); +/** @todo these calls should be in a file_table in gui_factory */ const char *fetch_filetype(const char *unix_path); char *fetch_mimetype(const char *ro_path); + + +/** + * Initialise the fetcher. + * + * @return NSERROR_OK or error code + */ +nserror fetch_init(void); + +/** + * Start fetching data for the given URL. + * + * The function returns immediately. The fetch may be queued for later + * processing. + * + * A pointer to an opaque struct fetch is returned, which can be passed to + * fetch_abort() to abort the fetch at any time. Returns NULL if memory is + * exhausted (or some other fatal error occurred). + * + * The caller must supply a callback function which is called when anything + * interesting happens. The callback function is first called with msg + * FETCH_HEADER, with the header in data, then one or more times + * with FETCH_DATA with some data for the url, and finally with + * FETCH_FINISHED. Alternatively, FETCH_ERROR indicates an error occurred: + * data contains an error message. FETCH_REDIRECT may replace the FETCH_HEADER, + * FETCH_DATA, FETCH_FINISHED sequence if the server sends a replacement URL. + * + */ +struct fetch *fetch_start(nsurl *url, nsurl *referer, + fetch_callback callback, + void *p, bool only_2xx, const char *post_urlenc, + const struct fetch_multipart_data *post_multipart, + bool verifiable, bool downgrade_tls, + const char *headers[]); + +/** + * Abort a fetch. + */ +void fetch_abort(struct fetch *f); + +/** + * Do some work on current fetches. + * + * Must be called regularly to make progress on fetches. + */ +void fetch_poll(void); + +/** + * Clean up for quit. + * + * Must be called before exiting. + */ +void fetch_quit(void); + +/** + * Check if a URL's scheme can be fetched. + * + * \param url URL to check + * \return true if the scheme is supported + */ bool fetch_can_fetch(const nsurl *url); + +/** + * Change the callback function for a fetch. + */ void fetch_change_callback(struct fetch *fetch, - fetch_callback callback, - void *p); + fetch_callback callback, + void *p); + +/** + * Get the HTTP response code. + */ long fetch_http_code(struct fetch *fetch); + +/** + * Determine if a fetch was verifiable + * + * \param fetch Fetch to consider + * \return Verifiable status of fetch + */ bool fetch_get_verifiable(struct fetch *fetch); +/** + * Free a linked list of fetch_multipart_data. + * + * \param list Pointer to head of list to free + */ void fetch_multipart_data_destroy(struct fetch_multipart_data *list); -struct fetch_multipart_data *fetch_multipart_data_clone( - const struct fetch_multipart_data *list); + +/** + * Clone a linked list of fetch_multipart_data. + * + * \param list List to clone + * \return Pointer to head of cloned list, or NULL on failure + */ +struct fetch_multipart_data *fetch_multipart_data_clone(const struct fetch_multipart_data *list); + +/** + * send message to fetch + */ +void fetch_send_callback(const fetch_msg *msg, struct fetch *fetch); + +/** + * remove a queued fetch + */ +void fetch_remove_from_queues(struct fetch *fetch); + +/** + * Free a fetch structure and associated resources. + */ +void fetch_free(struct fetch *f); + +/** + * set the http code of a fetch + */ +void fetch_set_http_code(struct fetch *fetch, long http_code); + +/** + * get the referer from the fetch + */ +const char *fetch_get_referer_to_send(struct fetch *fetch); + +/** + * set cookie data on a fetch + */ +void fetch_set_cookie(struct fetch *fetch, const char *data); + /* API for fetchers themselves */ @@ -151,20 +258,13 @@ typedef void (*fetcher_finalise)(lwc_string *scheme); * \return true iff success */ bool fetch_add_fetcher(lwc_string *scheme, - fetcher_initialise initialiser, - fetcher_can_fetch can_fetch, - fetcher_setup_fetch setup_fetch, - fetcher_start_fetch start_fetch, - fetcher_abort_fetch abort_fetch, - fetcher_free_fetch free_fetch, - fetcher_poll_fetcher poll_fetcher, - fetcher_finalise finaliser); - -void fetch_send_callback(const fetch_msg *msg, struct fetch *fetch); -void fetch_remove_from_queues(struct fetch *fetch); -void fetch_free(struct fetch *f); -void fetch_set_http_code(struct fetch *fetch, long http_code); -const char *fetch_get_referer_to_send(struct fetch *fetch); -void fetch_set_cookie(struct fetch *fetch, const char *data); + fetcher_initialise initialiser, + fetcher_can_fetch can_fetch, + fetcher_setup_fetch setup_fetch, + fetcher_start_fetch start_fetch, + fetcher_abort_fetch abort_fetch, + fetcher_free_fetch free_fetch, + fetcher_poll_fetcher poll_fetcher, + fetcher_finalise finaliser); #endif diff --git a/desktop/netsurf.c b/desktop/netsurf.c index d294073ba..76da91a89 100644 --- a/desktop/netsurf.c +++ b/desktop/netsurf.c @@ -210,7 +210,10 @@ nserror netsurf_init(const char *messages, struct gui_table *gt) setlocale(LC_ALL, "C"); - fetch_init(); + /* initialise the fetchers */ + error = fetch_init(); + if (error != NSERROR_OK) + return error; /* Initialise the hlcache and allow it to init the llcache for us */ hlcache_initialise(&hlcache_parameters); From 8e1fe5d1a9501e7a9b50be41994ed3e92b9cc6ae Mon Sep 17 00:00:00 2001 From: John-Mark Bell Date: Sun, 19 Jan 2014 22:51:28 +0000 Subject: [PATCH 110/773] Atari: run correct freetype-config --- atari/Makefile.target | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/atari/Makefile.target b/atari/Makefile.target index bc79b0625..60f6e8056 100644 --- a/atari/Makefile.target +++ b/atari/Makefile.target @@ -10,6 +10,7 @@ # the netsurf environment! STRIP := $(wildcard $(GCCSDK_INSTALL_CROSSBIN)/*strip) STACK := $(wildcard $(GCCSDK_INSTALL_CROSSBIN)/*stack) +FT2CF := $(GCCSDK_INSTALL_ENV)/bin/freetype-config ifeq ($(ATARIARCH),68000) PRGSUFFIX := 000.app @@ -32,7 +33,7 @@ endif # non-pkgconfig components -FREETYPE_FONT_CFLAGS := $(shell freetype-config --cflags) -DWITH_FREETYPE_FONT_DRIVER +FREETYPE_FONT_CFLAGS := $(shell $(FT2CF) --cflags) -DWITH_FREETYPE_FONT_DRIVER SPIDERMONKEY_CFLAGS := -DWITH_MOZJS -DXP_UNIX -DJS_HAS_FILE_OBJECT=0 -DJSOPTION_JIT=0 -DPOSIX_SOURCE -D_BSD_SOURCE $(eval $(call feature_enabled,PNG,-DWITH_PNG,-lpng,PNG (libpng))) From 4a014b61befdf1ad54c9fcf90071977e7b3cbe12 Mon Sep 17 00:00:00 2001 From: John-Mark Bell Date: Fri, 17 Jan 2014 01:09:24 +0000 Subject: [PATCH 111/773] Enable TLS 1.2 support again. --- content/fetchers/curl.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/content/fetchers/curl.c b/content/fetchers/curl.c index 92d4625b5..bc6b2c338 100644 --- a/content/fetchers/curl.c +++ b/content/fetchers/curl.c @@ -688,16 +688,14 @@ fetch_curl_sslctxfun(CURL *curl_handle, void *_sslctx, void *parm) parm); if (f->downgrade_tls) { + /* Disable TLS 1.1/1.2 if the server can't cope with them */ #ifdef SSL_OP_NO_TLSv1_1 - /* Disable TLS1.1, if the server can't cope with it */ options |= SSL_OP_NO_TLSv1_1; #endif - } - #ifdef SSL_OP_NO_TLSv1_2 - /* Disable TLS1.2, as it causes some servers to stall. */ - options |= SSL_OP_NO_TLSv1_2; + options |= SSL_OP_NO_TLSv1_2; #endif + } SSL_CTX_set_options(sslctx, options); From 3f3b64bf222975546498b9db28e962cf99fb88f1 Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Tue, 21 Jan 2014 11:13:36 +0000 Subject: [PATCH 112/773] Fix scaled rendering clip rect bottom calculation. --- desktop/textarea.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/desktop/textarea.c b/desktop/textarea.c index 209a6c6d7..0f0bd54e8 100644 --- a/desktop/textarea.c +++ b/desktop/textarea.c @@ -2157,7 +2157,7 @@ void textarea_redraw(struct textarea *ta, int x, int y, colour bg, float scale, scale) r.y1 = y + (ta->vis_height - ta->border_width - (ta->bar_x != NULL ? SCROLLBAR_WIDTH : - 0) * scale); + 0)) * scale; } if (line0 > 0) From aa380ed47a465e812e235e4c7a3706de905d4d2d Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Tue, 21 Jan 2014 14:37:46 +0000 Subject: [PATCH 113/773] More scaled rendering improvements. Partial redraws of scaled textareas can't work atm, since neither the textarea nor content is aware of scale. --- desktop/textarea.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/desktop/textarea.c b/desktop/textarea.c index 0f0bd54e8..fa0b2fd05 100644 --- a/desktop/textarea.c +++ b/desktop/textarea.c @@ -2078,10 +2078,17 @@ void textarea_redraw(struct textarea *ta, int x, int y, colour bg, float scale, r = *clip; - if (r.x1 < x || r.x0 > x + ta->vis_width || r.y1 < y || - r.y0 > y + ta->vis_height) - /* Textarea outside the clipping rectangle */ + /* Nothing to render if textarea is outside clip rectangle */ + if (r.x1 < x || r.y1 < y) return; + if (scale == 1.0) { + if (r.x0 > x + ta->vis_width || r.y0 > y + ta->vis_height) + return; + } else { + if (r.x0 > x + ta->vis_width * scale || + r.y0 > y + ta->vis_height * scale) + return; + } if (ta->lines == NULL) /* Nothing to redraw */ @@ -2264,6 +2271,8 @@ void textarea_redraw(struct textarea *ta, int x, int y, colour bg, float scale, &right); } else { right = ta->lines[line].width; + if (scale != 1.0) + right *= scale; } right += x + ta->border_width + ta->pad_left - ta->scroll_x; From 4684e9665d2ddff50f4a8e9a16d73224d2617180 Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Tue, 21 Jan 2014 15:01:18 +0000 Subject: [PATCH 114/773] Deselect other options when select option is selected, and it's not a multi-select. --- render/form.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/render/form.c b/render/form.c index 49d6f217c..5ce8056de 100644 --- a/render/form.c +++ b/render/form.c @@ -520,7 +520,7 @@ bool form_successful_controls_dom(struct form *_form, goto dom_no_memory; } for(option_index = 0; option_index < options_count; - ++option_index) { + ++option_index) { bool selected; if (option_element != NULL) { dom_node_unref(option_element); @@ -1335,19 +1335,23 @@ static void form__select_process_selection(html_content *html, count++, o = o->next) { if (!control->data.select.multiple) o->selected = false; + dom_html_option_element_set_selected(o->node, false); if (count == item) { if (control->data.select.multiple) { if (o->selected) { o->selected = false; - dom_html_option_element_set_selected(o->node, false); + dom_html_option_element_set_selected( + o->node, false); control->data.select.num_selected--; } else { o->selected = true; - dom_html_option_element_set_selected(o->node, true); + dom_html_option_element_set_selected( + o->node, true); control->data.select.num_selected++; } } else { - dom_html_option_element_set_selected(o->node, true); + dom_html_option_element_set_selected( + o->node, true); o->selected = true; } } From 047569339406f2be1637ae4cee5dd0c9a9c2328f Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Wed, 22 Jan 2014 23:19:57 +0000 Subject: [PATCH 115/773] create table for fetcher operations and move all operations into it --- amiga/filetype.c | 6 --- amiga/filetype.h | 3 ++ amiga/gui.c | 12 +++-- atari/filetype.c | 2 + atari/filetype.h | 2 + atari/gui.c | 19 +++++-- beos/filetype.cpp | 6 --- beos/filetype.h | 1 + beos/gui.cpp | 17 ++++-- cocoa/NetsurfApp.m | 1 + cocoa/fetch.h | 19 +++++++ cocoa/fetch.m | 8 +-- cocoa/gui.h | 1 + cocoa/gui.m | 17 ++++-- content/fetch.h | 5 -- content/fetchers/curl.c | 4 +- content/fetchers/file.c | 8 +-- content/fetchers/resource.c | 2 +- desktop/gui.h | 102 +++++++++++++++++++++++++----------- desktop/gui_factory.c | 61 +++++++++++++++------ desktop/save_complete.c | 6 +-- framebuffer/filetype.c | 2 + framebuffer/filetype.h | 25 +++++++++ framebuffer/gui.c | 16 ++++-- gtk/filetype.c | 5 -- gtk/filetype.h | 1 + gtk/gui.c | 14 +++-- monkey/filetype.c | 14 ++--- monkey/filetype.h | 5 +- monkey/main.c | 39 ++++++++------ riscos/gui.c | 14 +++-- riscos/gui.h | 2 + windows/filetype.c | 2 + windows/filetype.h | 25 +++++++++ windows/gui.c | 15 +++++- windows/gui.h | 1 + windows/main.c | 1 + 37 files changed, 343 insertions(+), 140 deletions(-) create mode 100644 atari/filetype.h create mode 100644 cocoa/fetch.h create mode 100644 framebuffer/filetype.h create mode 100644 windows/filetype.h diff --git a/amiga/filetype.c b/amiga/filetype.c index 39e874ab0..0cb4ac454 100644 --- a/amiga/filetype.c +++ b/amiga/filetype.c @@ -144,12 +144,6 @@ const char *fetch_filetype(const char *unix_path) return mimetype; } - -char *fetch_mimetype(const char *ro_path) -{ - return strdup(fetch_filetype(ro_path)); -} - const char *ami_content_type_to_file_type(content_type type) { switch(type) diff --git a/amiga/filetype.h b/amiga/filetype.h index 851dddf36..e99f5950c 100644 --- a/amiga/filetype.h +++ b/amiga/filetype.h @@ -27,6 +27,8 @@ struct hlcache_handle; struct ami_mime_entry; +const char *fetch_filetype(const char *unix_path); + nserror ami_mime_init(const char *mimefile); void ami_mime_free(void); void ami_mime_entry_free(struct ami_mime_entry *mimeentry); @@ -46,4 +48,5 @@ bool ami_mime_compare(struct hlcache_handle *c, const char *type); /* deprecated */ const char *ami_content_type_to_file_type(content_type type); + #endif diff --git a/amiga/gui.c b/amiga/gui.c index b7ee133fa..6bad1dbee 100644 --- a/amiga/gui.c +++ b/amiga/gui.c @@ -5181,17 +5181,22 @@ static struct gui_window_table amiga_window_table = { .save_link = gui_window_save_link, }; +static struct gui_fetch_table amiga_fetch_table = { + .filename_from_path = filename_from_path, + .path_add_part = path_add_part, + .filetype = fetch_filetype, + + .get_resource_url = gui_get_resource_url, +}; static struct gui_browser_table amiga_browser_table = { .poll = gui_poll, + .quit = gui_quit, .set_search_ico = gui_set_search_ico, - .get_resource_url = gui_get_resource_url, .launch_url = gui_launch_url, .create_form_select_menu = gui_create_form_select_menu, .cert_verify = gui_cert_verify, - .filename_from_path = filename_from_path, - .path_add_part = path_add_part, .login = gui_401login_open, }; @@ -5211,6 +5216,7 @@ int main(int argc, char** argv) .window = &amiga_window_table, .clipboard = amiga_clipboard_table, .download = amiga_download_table, + .fetch = &amiga_fetch_table, }; /* Open popupmenu.library just to check the version. diff --git a/atari/filetype.c b/atari/filetype.c index 99daf470c..9b73a0508 100755 --- a/atari/filetype.c +++ b/atari/filetype.c @@ -26,6 +26,8 @@ #include "utils/url.h" #include "utils/log.h" #include "content/fetch.h" + +#include "atari/filetype.h" /** * filetype -- determine the MIME type of a local file diff --git a/atari/filetype.h b/atari/filetype.h new file mode 100644 index 000000000..54d915bf5 --- /dev/null +++ b/atari/filetype.h @@ -0,0 +1,2 @@ +char *fetch_mimetype(const char *ro_path); +const char *fetch_filetype(const char *unix_path); diff --git a/atari/gui.c b/atari/gui.c index b2ac6f715..0267148d2 100644 --- a/atari/gui.c +++ b/atari/gui.c @@ -74,6 +74,7 @@ #include "atari/search.h" #include "atari/deskmenu.h" #include "atari/download.h" +#include "atari/filetype.h" #include "cflib.h" #define TODO() (0)/*printf("%s Unimplemented!\n", __FUNCTION__)*/ @@ -1072,13 +1073,20 @@ static struct gui_clipboard_table atari_clipboard_table = { .set = gui_set_clipboard, }; -static struct gui_browser_table atari_browser_table = { - .poll = gui_poll, - .quit = gui_quit, - .get_resource_url = gui_get_resource_url, - .cert_verify = gui_cert_verify, +static struct gui_fetch_table atari_fetch_table = { .filename_from_path = filename_from_path, .path_add_part = path_add_part, + .filetype = fetch_filetype, + + .get_resource_url = gui_get_resource_url, + .mimetype = fetch_mimetype, +}; + +static struct gui_browser_table atari_browser_table = { + .poll = gui_poll, + + .quit = gui_quit, + .cert_verify = gui_cert_verify, .login = gui_401login_open, }; @@ -1102,6 +1110,7 @@ int main(int argc, char** argv) .window = &atari_window_table, .clipboard = &atari_clipboard_table, .download = atari_download_table, + .fetch = &atari_fetch_table, }; /* @todo logging file descriptor update belongs in a nslog_init callback */ diff --git a/beos/filetype.cpp b/beos/filetype.cpp index 7975041ac..d5bd3d77b 100644 --- a/beos/filetype.cpp +++ b/beos/filetype.cpp @@ -135,9 +135,3 @@ const char *fetch_filetype(const char *unix_path) return type; } - -char *fetch_mimetype(const char *unix_path) -{ - return strdup(fetch_filetype(unix_path)); -} - diff --git a/beos/filetype.h b/beos/filetype.h index ab0ef410f..72252dbd0 100644 --- a/beos/filetype.h +++ b/beos/filetype.h @@ -18,3 +18,4 @@ void beos_fetch_filetype_init(void); void beos_fetch_filetype_fin(void); +const char *fetch_filetype(const char *unix_path); diff --git a/beos/gui.cpp b/beos/gui.cpp index feac53a29..ca176c83f 100644 --- a/beos/gui.cpp +++ b/beos/gui.cpp @@ -1067,13 +1067,18 @@ static struct gui_clipboard_table beos_clipboard_table = { gui_set_clipboard, }; +static struct gui_fetch_table beos_fetch_table = { + filename_from_path, + path_add_part, + fetch_filetype, + gui_get_resource_url, + NULL //fetch_mimetype +}; + static struct gui_browser_table beos_browser_table = { gui_poll, - filename_from_path, - path_add_part, gui_quit, NULL, //set_search_ico - gui_get_resource_url, gui_launch_url, NULL, //create_form_select_menu NULL, //cert_verify @@ -1090,7 +1095,8 @@ int main(int argc, char** argv) &beos_browser_table, beos_window_table, beos_download_table, - &beos_clipboard_table + &beos_clipboard_table, + &beos_fetch_table }; if (find_directory(B_USER_SETTINGS_DIRECTORY, &options, true) == B_OK) { @@ -1141,7 +1147,8 @@ int gui_init_replicant(int argc, char** argv) &beos_browser_table, beos_window_table, beos_download_table, - &beos_clipboard_table + &beos_clipboard_table, + &beos_fetch_table }; if (find_directory(B_USER_SETTINGS_DIRECTORY, &options, true) == B_OK) { diff --git a/cocoa/NetsurfApp.m b/cocoa/NetsurfApp.m index 158c195e6..5643efd6c 100644 --- a/cocoa/NetsurfApp.m +++ b/cocoa/NetsurfApp.m @@ -190,6 +190,7 @@ int main( int argc, char **argv ) .window = cocoa_window_table, .clipboard = cocoa_clipboard_table, .download = cocoa_download_table, + .fetch = cocoa_fetch_table, }; cocoa_autorelease(); diff --git a/cocoa/fetch.h b/cocoa/fetch.h new file mode 100644 index 000000000..4a50b6e8d --- /dev/null +++ b/cocoa/fetch.h @@ -0,0 +1,19 @@ +/* + * Copyright 2011 Sven Weidauer + * + * This file is part of NetSurf, http://www.netsurf-browser.org/ + * + * NetSurf is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * NetSurf is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +const char *fetch_filetype(const char *unix_path); diff --git a/cocoa/fetch.m b/cocoa/fetch.m index ff1496246..b1c7aea9e 100644 --- a/cocoa/fetch.m +++ b/cocoa/fetch.m @@ -21,6 +21,8 @@ #import "utils/log.h" #import "content/fetch.h" +#import "cocoa/fetch.h" + static char cocoafiletype[200]; static const struct mimemap_s { @@ -91,9 +93,3 @@ const char *fetch_filetype(const char *unix_path) return cocoafiletype; } - - -char *fetch_mimetype(const char *ro_path) -{ - return strdup( fetch_filetype( ro_path ) ); -} diff --git a/cocoa/gui.h b/cocoa/gui.h index 757140030..55b69072e 100644 --- a/cocoa/gui.h +++ b/cocoa/gui.h @@ -20,6 +20,7 @@ extern struct gui_window_table *cocoa_window_table; extern struct gui_clipboard_table *cocoa_clipboard_table; +extern struct gui_fetch_table *cocoa_fetch_table; extern struct gui_browser_table *cocoa_browser_table; extern NSString * const kCookiesFileOption; diff --git a/cocoa/gui.m b/cocoa/gui.m index 4d43fe4f0..2a97df39d 100644 --- a/cocoa/gui.m +++ b/cocoa/gui.m @@ -24,6 +24,7 @@ #import "cocoa/BrowserViewController.h" #import "cocoa/BrowserWindowController.h" #import "cocoa/FormSelectMenu.h" +#import "cocoa/fetch.h" #import "desktop/gui.h" #import "desktop/netsurf.h" @@ -311,16 +312,22 @@ static struct gui_window_table window_table = { struct gui_window_table *cocoa_window_table = &window_table; +static struct gui_fetch_table fetch_table = { + .filename_from_path = filename_from_path, + .path_add_part = path_add_part, + .filetype = fetch_filetype, + + .get_resource_url = gui_get_resource_url, +}; + +struct gui_fetch_table *cocoa_fetch_table = &fetch_table; + static struct gui_browser_table browser_table = { .poll = gui_poll, - .get_resource_url = gui_get_resource_url, + .launch_url = gui_launch_url, .create_form_select_menu = gui_create_form_select_menu, .cert_verify = gui_cert_verify, - .filename_from_path = filename_from_path, - .path_add_part = path_add_part, }; struct gui_browser_table *cocoa_browser_table = &browser_table; - - diff --git a/content/fetch.h b/content/fetch.h index 09b7c8d44..f20b4f2d2 100644 --- a/content/fetch.h +++ b/content/fetch.h @@ -99,11 +99,6 @@ extern bool fetch_active; typedef void (*fetch_callback)(const fetch_msg *msg, void *p); -/** @todo these calls should be in a file_table in gui_factory */ -const char *fetch_filetype(const char *unix_path); -char *fetch_mimetype(const char *ro_path); - - /** * Initialise the fetcher. * diff --git a/content/fetchers/curl.c b/content/fetchers/curl.c index bc6b2c338..f3a8385a1 100644 --- a/content/fetchers/curl.c +++ b/content/fetchers/curl.c @@ -1267,7 +1267,7 @@ fetch_curl_post_convert(const struct fetch_multipart_data *control) if (control->file) { char *leafname = 0; - leafname = guit->browser->filename_from_path(control->value); + leafname = guit->fetch->filename_from_path(control->value); if (leafname == NULL) continue; @@ -1297,7 +1297,7 @@ fetch_curl_post_convert(const struct fetch_multipart_data *control) LOG(("curl_formadd: %d (%s)", code, control->name)); } else { - char *mimetype = fetch_mimetype(control->value); + char *mimetype = guit->fetch->mimetype(control->value); code = curl_formadd(&post, &last, CURLFORM_COPYNAME, control->name, CURLFORM_FILE, control->rawfile, diff --git a/content/fetchers/file.c b/content/fetchers/file.c index 26ef9069b..83c408e5a 100644 --- a/content/fetchers/file.c +++ b/content/fetchers/file.c @@ -305,7 +305,7 @@ static void fetch_file_process_plain(struct fetch_file_context *ctx, /* content type */ if (fetch_file_send_header(ctx, "Content-Type: %s", - fetch_filetype(ctx->path))) + guit->fetch->filetype(ctx->path))) goto fetch_file_process_aborted; /* content length */ @@ -385,7 +385,7 @@ fetch_file_process_aborted: /* content type */ if (fetch_file_send_header(ctx, "Content-Type: %s", - fetch_filetype(ctx->path))) + guit->fetch->filetype(ctx->path))) goto fetch_file_process_aborted; /* content length */ @@ -575,7 +575,7 @@ static void fetch_file_process_dir(struct fetch_file_context *ctx, continue; strncpy(urlpath, ctx->path, sizeof urlpath); - if (guit->browser->path_add_part(urlpath, sizeof urlpath, + if (guit->fetch->path_add_part(urlpath, sizeof urlpath, ent->d_name) == false) continue; @@ -608,7 +608,7 @@ static void fetch_file_process_dir(struct fetch_file_context *ctx, false, path, ent->d_name, - fetch_filetype(urlpath), + guit->fetch->filetype(urlpath), ent_stat.st_size, datebuf, timebuf, buffer, sizeof(buffer)); diff --git a/content/fetchers/resource.c b/content/fetchers/resource.c index d1b21b741..cce816aa5 100644 --- a/content/fetchers/resource.c +++ b/content/fetchers/resource.c @@ -207,7 +207,7 @@ static bool fetch_resource_initialise(lwc_string *scheme) } } - e->url = guit->browser->get_resource_url(fetch_resource_paths[i]); + e->url = guit->fetch->get_resource_url(fetch_resource_paths[i]); if (e->url == NULL) { lwc_string_unref(e->path); } else { diff --git a/desktop/gui.h b/desktop/gui.h index 5252737f9..724355d10 100644 --- a/desktop/gui.h +++ b/desktop/gui.h @@ -280,6 +280,75 @@ struct gui_clipboard_table { void (*set)(const char *buffer, size_t length, nsclipboard_styles styles[], int n_styles); }; +/** + * function table for fetcher operations + */ +struct gui_fetch_table { + /* Mandantory entries */ + + /** + * Return the filename part of a full path + * + * @note used in curl fetcher + * + * \param path full path and filename + * \return filename (will be freed with free()) + */ + char *(*filename_from_path)(char *path); + + /** + * Add a path component/filename to an existing path + * + * @note used in save complete and file fetcher + * + * \param path buffer containing path + free space + * \param length length of buffer "path" + * \param newpart string containing path component to add to path + * \return true on success + */ + bool (*path_add_part)(char *path, int length, const char *newpart); + + /** + * Determine the MIME type of a local file. + * + * @note used in file fetcher + * + * \param unix_path Unix style path to file on disk + * \return Pointer to MIME type string (should not be freed) - + * invalidated on next call to fetch_filetype. + */ + const char *(*filetype)(const char *unix_path); + + + /* Optional entries */ + + /** + * Callback to translate resource to full url. + * + * @note used in resource fetcher + * + * Transforms a resource: path into a full URL. The returned URL + * is used as the target for a redirect. The caller takes ownership of + * the returned nsurl including unrefing it when finished with it. + * + * \param path The path of the resource to locate. + * \return A string containing the full URL of the target object or + * NULL if no suitable resource can be found. + */ + nsurl* (*get_resource_url)(const char *path); + + /** + * Find a MIME type for a local file + * + * @note used in file fetcher + * + * \param ro_path RISC OS style path to file on disk + * \return MIME type string (on heap, caller should free), or NULL + */ + char *(*mimetype)(const char *ro_path); + +}; + /** Graphical user interface browser misc function table * * function table implementing GUI interface to miscelaneous browser @@ -294,23 +363,6 @@ struct gui_browser_table { */ void (*poll)(bool active); - /** - * Return the filename part of a full path - * - * \param path full path and filename - * \return filename (will be freed with free()) - */ - char *(*filename_from_path)(char *path); - - /** - * Add a path component/filename to an existing path - * - * \param path buffer containing path + free space - * \param length length of buffer "path" - * \param newpart string containing path component to add to path - * \return true on success - */ - bool (*path_add_part)(char *path, int length, const char *newpart); /* Optional entries */ @@ -326,19 +378,6 @@ struct gui_browser_table { */ void (*set_search_ico)(hlcache_handle *ico); - /** - * Callback to translate resource to full url. - * - * Transforms a resource: path into a full URL. The returned URL - * is used as the target for a redirect. The caller takes ownership of - * the returned nsurl including unrefing it when finished with it. - * - * \param path The path of the resource to locate. - * \return A string containing the full URL of the target object or - * NULL if no suitable resource can be found. - */ - nsurl* (*get_resource_url)(const char *path); - /** * core has no fetcher for url */ @@ -380,6 +419,9 @@ struct gui_table { /** Clipboard table */ struct gui_clipboard_table *clipboard; + + /** Fetcher table */ + struct gui_fetch_table *fetch; }; diff --git a/desktop/gui_factory.c b/desktop/gui_factory.c index 104f4906d..06b5383ba 100644 --- a/desktop/gui_factory.c +++ b/desktop/gui_factory.c @@ -289,6 +289,46 @@ static nserror verify_clipboard_register(struct gui_clipboard_table *gct) return NSERROR_OK; } +static nsurl *gui_default_get_resource_url(const char *path) +{ + return NULL; +} + +static char *gui_default_mimetype(const char *path) +{ + return strdup(guit->fetch->filetype(path)); +} + +/** verify fetch table is valid */ +static nserror verify_fetch_register(struct gui_fetch_table *gft) +{ + /* check table is present */ + if (gft == NULL) { + return NSERROR_BAD_PARAMETER; + } + + /* check the mandantory fields are set */ + if (gft->filename_from_path == NULL) { + return NSERROR_BAD_PARAMETER; + } + if (gft->path_add_part == NULL) { + return NSERROR_BAD_PARAMETER; + } + if (gft->filetype == NULL) { + return NSERROR_BAD_PARAMETER; + } + + + /* fill in the optional entries with defaults */ + if (gft->get_resource_url == NULL) { + gft->get_resource_url = gui_default_get_resource_url; + } + if (gft->mimetype == NULL) { + gft->mimetype = gui_default_mimetype; + } + + return NSERROR_OK; +} static void gui_default_quit(void) { @@ -298,11 +338,6 @@ static void gui_default_set_search_ico(hlcache_handle *ico) { } -static nsurl *gui_default_get_resource_url(const char *path) -{ - return NULL; -} - static void gui_default_launch_url(const char *url) { } @@ -340,13 +375,6 @@ static nserror verify_browser_register(struct gui_browser_table *gbt) if (gbt->poll == NULL) { return NSERROR_BAD_PARAMETER; } - if (gbt->filename_from_path == NULL) { - return NSERROR_BAD_PARAMETER; - } - if (gbt->path_add_part == NULL) { - return NSERROR_BAD_PARAMETER; - } - /* fill in the optional entries with defaults */ if (gbt->quit == NULL) { @@ -355,9 +383,6 @@ static nserror verify_browser_register(struct gui_browser_table *gbt) if (gbt->set_search_ico == NULL) { gbt->set_search_ico = gui_default_set_search_ico; } - if (gbt->get_resource_url == NULL) { - gbt->get_resource_url = gui_default_get_resource_url; - } if (gbt->launch_url == NULL) { gbt->launch_url = gui_default_launch_url; } @@ -414,6 +439,12 @@ nserror gui_factory_register(struct gui_table *gt) return err; } + /* fetch table */ + err = verify_fetch_register(gt->fetch); + if (err != NSERROR_OK) { + return err; + } + /* download table */ if (gt->download == NULL) { /* set default download table */ diff --git a/desktop/save_complete.c b/desktop/save_complete.c index bd2ed4dea..da87a65fe 100644 --- a/desktop/save_complete.c +++ b/desktop/save_complete.c @@ -148,7 +148,7 @@ static bool save_complete_save_buffer(save_complete_ctx *ctx, char fullpath[PATH_MAX]; strncpy(fullpath, ctx->path, sizeof fullpath); - error = guit->browser->path_add_part(fullpath, sizeof fullpath, leafname); + error = guit->fetch->path_add_part(fullpath, sizeof fullpath, leafname); if (error == false) { warn_user("NoMemory", NULL); return false; @@ -1049,7 +1049,7 @@ static bool save_complete_save_html_document(save_complete_ctx *ctx, else snprintf(filename, sizeof filename, "%p", c); - error = guit->browser->path_add_part(fullpath, sizeof fullpath, filename); + error = guit->fetch->path_add_part(fullpath, sizeof fullpath, filename); if (error == false) { warn_user("NoMemory", NULL); return false; @@ -1126,7 +1126,7 @@ static bool save_complete_inventory(save_complete_ctx *ctx) char fullpath[PATH_MAX]; strncpy(fullpath, ctx->path, sizeof fullpath); - error = guit->browser->path_add_part(fullpath, sizeof fullpath, "Inventory"); + error = guit->fetch->path_add_part(fullpath, sizeof fullpath, "Inventory"); if (error == false) { warn_user("NoMemory", NULL); return false; diff --git a/framebuffer/filetype.c b/framebuffer/filetype.c index 84e286d0c..ce71e337a 100644 --- a/framebuffer/filetype.c +++ b/framebuffer/filetype.c @@ -22,6 +22,8 @@ #include "utils/log.h" #include "utils/utils.h" +#include "framebuffer/filetype.h" + /** * filetype -- determine the MIME type of a local file */ diff --git a/framebuffer/filetype.h b/framebuffer/filetype.h new file mode 100644 index 000000000..d11aacb5b --- /dev/null +++ b/framebuffer/filetype.h @@ -0,0 +1,25 @@ +/* + * Copyright 2014 Vincent Sanders + * + * This file is part of NetSurf, http://www.netsurf-browser.org/ + * + * NetSurf is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * NetSurf is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef NETSURF_FB_FILETYPE_H +#define NETSURF_FB_FILETYPE_H + +const char *fetch_filetype(const char *unix_path); +char *fetch_mimetype(const char *ro_path); + +#endif diff --git a/framebuffer/gui.c b/framebuffer/gui.c index d89315957..82af56d9e 100644 --- a/framebuffer/gui.c +++ b/framebuffer/gui.c @@ -1,5 +1,5 @@ /* - * Copyright 2008 Vincent Sanders + * Copyright 2008, 2014 Vincent Sanders * * This file is part of NetSurf, http://www.netsurf-browser.org/ * @@ -55,6 +55,7 @@ #include "framebuffer/image_data.h" #include "framebuffer/font.h" #include "framebuffer/clipboard.h" +#include "framebuffer/filetype.h" #include "content/urldb.h" #include "desktop/local_history.h" @@ -1824,13 +1825,19 @@ static struct gui_window_table framebuffer_window_table = { .stop_throbber = gui_window_stop_throbber, }; -static struct gui_browser_table framebuffer_browser_table = { - .poll = gui_poll, +static struct gui_fetch_table framebuffer_fetch_table = { .filename_from_path = filename_from_path, .path_add_part = path_add_part, + .filetype = fetch_filetype, + + .get_resource_url = gui_get_resource_url, + .mimetype = fetch_mimetype, +}; + +static struct gui_browser_table framebuffer_browser_table = { + .poll = gui_poll, .quit = gui_quit, - .get_resource_url = gui_get_resource_url, }; /** Entry point from OS. @@ -1852,6 +1859,7 @@ main(int argc, char** argv) .browser = &framebuffer_browser_table, .window = &framebuffer_window_table, .clipboard = framebuffer_clipboard_table, + .fetch = &framebuffer_fetch_table, }; respaths = fb_init_resource(NETSURF_FB_RESPATH":"NETSURF_FB_FONTPATH); diff --git a/gtk/filetype.c b/gtk/filetype.c index 2ae59d867..a949b14d5 100644 --- a/gtk/filetype.c +++ b/gtk/filetype.c @@ -207,11 +207,6 @@ const char *fetch_filetype(const char *unix_path) return type != NULL ? type : "text/plain"; } -char *fetch_mimetype(const char *unix_path) -{ - return strdup(fetch_filetype(unix_path)); -} - #ifdef TEST_RIG int main(int argc, char *argv[]) diff --git a/gtk/filetype.h b/gtk/filetype.h index 8bf98db7c..68bb9c0ff 100644 --- a/gtk/filetype.h +++ b/gtk/filetype.h @@ -19,3 +19,4 @@ void gtk_fetch_filetype_init(const char *mimefile); void gtk_fetch_filetype_fin(void); +const char *fetch_filetype(const char *unix_path); diff --git a/gtk/gui.c b/gtk/gui.c index 39dc885da..d6d35029d 100644 --- a/gtk/gui.c +++ b/gtk/gui.c @@ -1133,16 +1133,23 @@ static struct gui_clipboard_table nsgtk_clipboard_table = { .set = gui_set_clipboard, }; +static struct gui_fetch_table nsgtk_fetch_table = { + .filename_from_path = filename_from_path, + .path_add_part = path_add_part, + .filetype = fetch_filetype, + + .get_resource_url = gui_get_resource_url, + +}; + static struct gui_browser_table nsgtk_browser_table = { .poll = gui_poll, + .quit = gui_quit, .set_search_ico = gui_set_search_ico, - .get_resource_url = gui_get_resource_url, .launch_url = gui_launch_url, .create_form_select_menu = gui_create_form_select_menu, .cert_verify = gui_cert_verify, - .filename_from_path = filename_from_path, - .path_add_part = path_add_part, .login = gui_401login_open, }; @@ -1159,6 +1166,7 @@ int main(int argc, char** argv) .window = nsgtk_window_table, .clipboard = &nsgtk_clipboard_table, .download = nsgtk_download_table, + .fetch = &nsgtk_fetch_table, }; /* check home directory is available */ diff --git a/monkey/filetype.c b/monkey/filetype.c index f89f2358c..db9c49ab4 100644 --- a/monkey/filetype.c +++ b/monkey/filetype.c @@ -26,14 +26,15 @@ #include #include -#include "gtk/filetype.h" #include "content/fetch.h" #include "utils/log.h" #include "utils/hashtable.h" +#include "monkey/filetype.h" + static struct hash_table *mime_hash = NULL; -void gtk_fetch_filetype_init(const char *mimefile) +void monkey_fetch_filetype_init(const char *mimefile) { struct stat statbuf; FILE *fh = NULL; @@ -143,12 +144,12 @@ void gtk_fetch_filetype_init(const char *mimefile) fclose(fh); } -void gtk_fetch_filetype_fin(void) +void monkey_fetch_filetype_fin(void) { hash_destroy(mime_hash); } -const char *fetch_filetype(const char *unix_path) +const char *monkey_fetch_filetype(const char *unix_path) { struct stat statbuf; char *ext; @@ -195,11 +196,6 @@ const char *fetch_filetype(const char *unix_path) return type != NULL ? type : "text/plain"; } -char *fetch_mimetype(const char *unix_path) -{ - return strdup(fetch_filetype(unix_path)); -} - #ifdef TEST_RIG int main(int argc, char *argv[]) diff --git a/monkey/filetype.h b/monkey/filetype.h index 8bf98db7c..6c16db01b 100644 --- a/monkey/filetype.h +++ b/monkey/filetype.h @@ -17,5 +17,6 @@ * along with this program. If not, see . */ -void gtk_fetch_filetype_init(const char *mimefile); -void gtk_fetch_filetype_fin(void); +void monkey_fetch_filetype_init(const char *mimefile); +void monkey_fetch_filetype_fin(void); +const char *monkey_fetch_filetype(const char *unix_path); diff --git a/monkey/main.c b/monkey/main.c index b6f5c434d..1135f0e53 100644 --- a/monkey/main.c +++ b/monkey/main.c @@ -63,7 +63,7 @@ static void monkey_quit(void) urldb_save(nsoption_charp(url_file)); free(nsoption_charp(cookie_file)); free(nsoption_charp(cookie_jar)); - gtk_fetch_filetype_fin(); + monkey_fetch_filetype_fin(); } static nsurl *gui_get_resource_url(const char *path) @@ -124,15 +124,15 @@ static bool nslog_stream_configure(FILE *fptr) static char *filename_from_path(char *path) { - char *leafname; + char *leafname; - leafname = strrchr(path, '/'); - if (!leafname) - leafname = path; - else - leafname += 1; + leafname = strrchr(path, '/'); + if (!leafname) + leafname = path; + else + leafname += 1; - return strdup(leafname); + return strdup(leafname); } /** @@ -146,22 +146,28 @@ static char *filename_from_path(char *path) static bool path_add_part(char *path, int length, const char *newpart) { - if(path[strlen(path) - 1] != '/') - strncat(path, "/", length); + if(path[strlen(path) - 1] != '/') + strncat(path, "/", length); - strncat(path, newpart, length); + strncat(path, newpart, length); - return true; + return true; } +static struct gui_fetch_table monkey_fetch_table = { + .filename_from_path = filename_from_path, + .path_add_part = path_add_part, + .filetype = monkey_fetch_filetype, + + .get_resource_url = gui_get_resource_url, +}; + static struct gui_browser_table monkey_browser_table = { .poll = monkey_poll, + .quit = monkey_quit, - .get_resource_url = gui_get_resource_url, .launch_url = gui_launch_url, .cert_verify = gui_cert_verify, - .filename_from_path = filename_from_path, - .path_add_part = path_add_part, .login = gui_401login_open, }; @@ -176,6 +182,7 @@ main(int argc, char **argv) .browser = &monkey_browser_table, .window = monkey_window_table, .download = monkey_download_table, + .fetch = &monkey_fetch_table, }; /* Unbuffer stdin/out/err */ @@ -210,7 +217,7 @@ main(int argc, char **argv) } filepath_sfinddef(respaths, buf, "mime.types", "/etc/"); - gtk_fetch_filetype_init(buf); + monkey_fetch_filetype_init(buf); urldb_load(nsoption_charp(url_file)); urldb_load_cookies(nsoption_charp(cookie_file)); diff --git a/riscos/gui.c b/riscos/gui.c index 6160956c7..8495dd6aa 100644 --- a/riscos/gui.c +++ b/riscos/gui.c @@ -2353,15 +2353,22 @@ static struct gui_clipboard_table riscos_clipboard_table = { .set = gui_set_clipboard, }; +static struct gui_fetch_table riscos_fetch_table = { + .filename_from_path = filename_from_path, + .path_add_part = path_add_part, + .filetype = fetch_filetype, + + .get_resource_url = gui_get_resource_url, + .mimetype = fetch_mimetype, +}; + static struct gui_browser_table riscos_browser_table = { .poll = gui_poll, + .quit = gui_quit, - .get_resource_url = gui_get_resource_url, .launch_url = gui_launch_url, .create_form_select_menu = gui_create_form_select_menu, .cert_verify = gui_cert_verify, - .filename_from_path = filename_from_path, - .path_add_part = path_add_part, .login = gui_401login_open, }; @@ -2381,6 +2388,7 @@ int main(int argc, char** argv) .window = riscos_window_table, .clipboard = &riscos_clipboard_table, .download = riscos_download_table, + .fetch = &riscos_fetch_table, }; /* Consult NetSurf$Logging environment variable to decide if logging diff --git a/riscos/gui.h b/riscos/gui.h index c3dce1cb8..3eeb56273 100644 --- a/riscos/gui.h +++ b/riscos/gui.h @@ -167,6 +167,8 @@ void ro_gui_history_open(struct browser_window *bw, struct history *history, bool pointer); /* in filetype.c */ +const char *fetch_filetype(const char *unix_path); +char *fetch_mimetype(const char *ro_path); int ro_content_filetype(struct hlcache_handle *c); int ro_content_native_type(struct hlcache_handle *c); int ro_content_filetype_from_mime_type(lwc_string *mime_type); diff --git a/windows/filetype.c b/windows/filetype.c index 7ad862b8b..5c6485659 100644 --- a/windows/filetype.c +++ b/windows/filetype.c @@ -22,6 +22,8 @@ #include "utils/log.h" #include "utils/utils.h" +#include "windows/filetype.h" + /** * filetype -- determine the MIME type of a local file */ diff --git a/windows/filetype.h b/windows/filetype.h new file mode 100644 index 000000000..e5017eaf4 --- /dev/null +++ b/windows/filetype.h @@ -0,0 +1,25 @@ +/* + * Copyright 2014 Vincent Sanders + * + * This file is part of NetSurf, http://www.netsurf-browser.org/ + * + * NetSurf is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * NetSurf is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef _NETSURF_WINDOWS_FILETYPE_H_ +#define _NETSURF_WINDOWS_FILETYPE_H_ + +const char *fetch_filetype(const char *unix_path); +char *fetch_mimetype(const char *ro_path); + +#endif diff --git a/windows/gui.c b/windows/gui.c index f476c5ae9..a6b2facaf 100644 --- a/windows/gui.c +++ b/windows/gui.c @@ -56,6 +56,7 @@ #include "windows/schedule.h" #include "windows/findfile.h" #include "windows/windbg.h" +#include "windows/filetype.h" HINSTANCE hInstance; /** win32 application instance handle. */ @@ -1868,6 +1869,7 @@ static struct gui_window_table window_table = { struct gui_window_table *win32_window_table = &window_table; + static struct gui_clipboard_table clipboard_table = { .get = gui_get_clipboard, .set = gui_set_clipboard, @@ -1875,10 +1877,19 @@ static struct gui_clipboard_table clipboard_table = { struct gui_clipboard_table *win32_clipboard_table = &clipboard_table; -static struct gui_browser_table browser_table = { - .poll = gui_poll, + +static struct gui_fetch_table fetch_table = { .filename_from_path = filename_from_path, .path_add_part = path_add_part, + .filetype = fetch_filetype, + + .mimetype = fetch_mimetype, +}; +struct gui_fetch_table *win32_fetch_table = &fetch_table; + + +static struct gui_browser_table browser_table = { + .poll = gui_poll, }; struct gui_browser_table *win32_browser_table = &browser_table; diff --git a/windows/gui.h b/windows/gui.h index 3372dcc21..1ff849d73 100644 --- a/windows/gui.h +++ b/windows/gui.h @@ -26,6 +26,7 @@ extern struct gui_window_table *win32_window_table; extern struct gui_clipboard_table *win32_clipboard_table; +extern struct gui_fetch_table *win32_fetch_table; extern struct gui_browser_table *win32_browser_table; extern HINSTANCE hInstance; diff --git a/windows/main.c b/windows/main.c index 8dc9d45cb..ac5231e07 100644 --- a/windows/main.c +++ b/windows/main.c @@ -110,6 +110,7 @@ WinMain(HINSTANCE hInstance, HINSTANCE hLastInstance, LPSTR lpcli, int ncmd) .window = win32_window_table, .clipboard = win32_clipboard_table, .download = win32_download_table, + .fetch = win32_fetch_table, }; win32_browser_table->get_resource_url = gui_get_resource_url; From 233904c7ed17002b434aa9c312976f2d4dfc08d9 Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Thu, 23 Jan 2014 00:09:59 +0000 Subject: [PATCH 116/773] fix build faliures from fetch table operation refactor --- amiga/file.c | 2 +- windows/main.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/amiga/file.c b/amiga/file.c index 937fb9052..9500b4084 100644 --- a/amiga/file.c +++ b/amiga/file.c @@ -62,7 +62,7 @@ static const ULONG ami_file_asl_mime_hook(struct Hook *mh, strcpy(fname,fr->fr_Drawer); AddPart(fname,ap->ap_Info.fib_FileName,1024); - mt = fetch_mimetype(fname); + mt = strdup(fetch_filetype(fname)); lerror = lwc_intern_string(mt, strlen(mt), &lwc_mt); if (lerror != lwc_error_ok) return FALSE; diff --git a/windows/main.c b/windows/main.c index ac5231e07..94e0eee2e 100644 --- a/windows/main.c +++ b/windows/main.c @@ -112,7 +112,7 @@ WinMain(HINSTANCE hInstance, HINSTANCE hLastInstance, LPSTR lpcli, int ncmd) .download = win32_download_table, .fetch = win32_fetch_table, }; - win32_browser_table->get_resource_url = gui_get_resource_url; + win32_fetch_table->get_resource_url = gui_get_resource_url; if (SLEN(lpcli) > 0) { argvw = CommandLineToArgvW(GetCommandLineW(), &argc); From 69778e29457cc0fbe65361e0db460908b89a8459 Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Fri, 24 Jan 2014 08:39:01 +0000 Subject: [PATCH 117/773] move framebuffer fetch operations to their own module --- framebuffer/Makefile.target | 2 +- framebuffer/fetch.c | 186 ++++++++++++++++++++++++++++ framebuffer/{filetype.h => fetch.h} | 8 +- framebuffer/filetype.c | 61 --------- framebuffer/findfile.c | 68 ---------- framebuffer/findfile.h | 4 - framebuffer/gui.c | 49 +------- 7 files changed, 193 insertions(+), 185 deletions(-) create mode 100644 framebuffer/fetch.c rename framebuffer/{filetype.h => fetch.h} (82%) delete mode 100644 framebuffer/filetype.c diff --git a/framebuffer/Makefile.target b/framebuffer/Makefile.target index 58a504b17..0ce796be0 100644 --- a/framebuffer/Makefile.target +++ b/framebuffer/Makefile.target @@ -135,7 +135,7 @@ $(eval $(foreach V,$(filter FB_IMAGE_%,$(.VARIABLES)),$(call convert_image,$($(V # S_FRAMEBUFFER are sources purely for the framebuffer build S_FRAMEBUFFER := gui.c framebuffer.c schedule.c \ - thumbnail.c misc.c bitmap.c filetype.c findfile.c \ + thumbnail.c misc.c bitmap.c fetch.c findfile.c \ localhistory.c clipboard.c S_FRAMEBUFFER_FBTK := fbtk.c event.c fill.c bitmap.c user.c window.c \ diff --git a/framebuffer/fetch.c b/framebuffer/fetch.c new file mode 100644 index 000000000..2e304c222 --- /dev/null +++ b/framebuffer/fetch.c @@ -0,0 +1,186 @@ +/* + * Copyright 2014 Vincent Sanders + * + * This file is part of NetSurf, http://www.netsurf-browser.org/ + * + * NetSurf is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * NetSurf is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** \file + * Interfaces for fetch table. + */ + +#include +#include + +#include "desktop/gui.h" +#include "utils/url.h" +#include "utils/log.h" +#include "utils/filepath.h" + +#include "framebuffer/findfile.h" +#include "framebuffer/fetch.h" + +/** + * Return the filename part of a full path + * + * \param path full path and filename + * \return filename (will be freed with free()) + */ +static char *filename_from_path(char *path) +{ + char *leafname; + + leafname = strrchr(path, '/'); + if (!leafname) + leafname = path; + else + leafname += 1; + + return strdup(leafname); +} + +/** + * Add a path component/filename to an existing path + * + * \param path buffer containing path + free space + * \param length length of buffer "path" + * \param newpart string containing path component to add to path + * \return true on success + */ +static bool path_add_part(char *path, int length, const char *newpart) +{ + if(path[strlen(path) - 1] != '/') + strncat(path, "/", length); + + strncat(path, newpart, length); + + return true; +} + +char *path_to_url(const char *path) +{ + int urllen; + char *url; + + if (path == NULL) + return NULL; + + urllen = strlen(path) + FILE_SCHEME_PREFIX_LEN + 1; + url = malloc(urllen); + + if (*path == '/') { + path++; /* file: paths are already absolute */ + } + + snprintf(url, urllen, "%s%s", FILE_SCHEME_PREFIX, path); + + return url; +} + + +char *url_to_path(const char *url) +{ + char *path; + char *respath; + url_func_result res; /* result from url routines */ + + res = url_path(url, &path); + if (res != URL_FUNC_OK) { + return NULL; + } + + res = url_unescape(path, &respath); + free(path); + if (res != URL_FUNC_OK) { + return NULL; + } + + return respath; +} + +/** + * Translate resource to full url. + * + * Transforms a resource: path into a full URL. The returned URL + * is used as the target for a redirect. The caller takes ownership of + * the returned nsurl including unrefing it when finished with it. + * + * \param path The path of the resource to locate. + * \return A string containing the full URL of the target object or + * NULL if no suitable resource can be found. + */ +static nsurl *get_resource_url(const char *path) +{ + char buf[PATH_MAX]; + char *raw; + nsurl *url = NULL; + + if (strcmp(path, "favicon.ico") == 0) + path = "favicon.png"; + + raw = path_to_url(filepath_sfind(respaths, buf, path)); + if (raw != NULL) { + nsurl_create(raw, &url); + free(raw); + } + + return url; +} + +/** + * filetype -- determine the MIME type of a local file + */ +static const char *fetch_filetype(const char *unix_path) +{ + int l; + LOG(("unix path %s", unix_path)); + l = strlen(unix_path); + if (2 < l && strcasecmp(unix_path + l - 3, "css") == 0) + return "text/css"; + if (2 < l && strcasecmp(unix_path + l - 3, "f79") == 0) + return "text/css"; + if (2 < l && strcasecmp(unix_path + l - 3, "jpg") == 0) + return "image/jpeg"; + if (3 < l && strcasecmp(unix_path + l - 4, "jpeg") == 0) + return "image/jpeg"; + if (2 < l && strcasecmp(unix_path + l - 3, "gif") == 0) + return "image/gif"; + if (2 < l && strcasecmp(unix_path + l - 3, "png") == 0) + return "image/png"; + if (2 < l && strcasecmp(unix_path + l - 3, "b60") == 0) + return "image/png"; + if (2 < l && strcasecmp(unix_path + l - 3, "jng") == 0) + return "image/jng"; + if (2 < l && strcasecmp(unix_path + l - 3, "svg") == 0) + return "image/svg"; + return "text/html"; +} + + +static char *fetch_mimetype(const char *ro_path) +{ + return strdup("text/plain"); +} + +/* table for fetch operations */ +static struct gui_fetch_table fetch_table = { + .filename_from_path = filename_from_path, + .path_add_part = path_add_part, + .filetype = fetch_filetype, + + .get_resource_url = get_resource_url, + .mimetype = fetch_mimetype, +}; + +struct gui_fetch_table *framebuffer_fetch_table = &fetch_table; diff --git a/framebuffer/filetype.h b/framebuffer/fetch.h similarity index 82% rename from framebuffer/filetype.h rename to framebuffer/fetch.h index d11aacb5b..718b08300 100644 --- a/framebuffer/filetype.h +++ b/framebuffer/fetch.h @@ -16,10 +16,10 @@ * along with this program. If not, see . */ -#ifndef NETSURF_FB_FILETYPE_H -#define NETSURF_FB_FILETYPE_H -const char *fetch_filetype(const char *unix_path); -char *fetch_mimetype(const char *ro_path); +#ifndef NETSURF_FB_FETCH_H +#define NETSURF_FB_FETCH_H + +struct gui_fetch_table *framebuffer_fetch_table; #endif diff --git a/framebuffer/filetype.c b/framebuffer/filetype.c deleted file mode 100644 index ce71e337a..000000000 --- a/framebuffer/filetype.c +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright 2003 James Bursa - * - * This file is part of NetSurf, http://www.netsurf-browser.org/ - * - * NetSurf is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License. - * - * NetSurf is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include -#include -#include "content/fetch.h" -#include "utils/log.h" -#include "utils/utils.h" - -#include "framebuffer/filetype.h" - -/** - * filetype -- determine the MIME type of a local file - */ - -const char *fetch_filetype(const char *unix_path) -{ - int l; - LOG(("unix path %s", unix_path)); - l = strlen(unix_path); - if (2 < l && strcasecmp(unix_path + l - 3, "css") == 0) - return "text/css"; - if (2 < l && strcasecmp(unix_path + l - 3, "f79") == 0) - return "text/css"; - if (2 < l && strcasecmp(unix_path + l - 3, "jpg") == 0) - return "image/jpeg"; - if (3 < l && strcasecmp(unix_path + l - 4, "jpeg") == 0) - return "image/jpeg"; - if (2 < l && strcasecmp(unix_path + l - 3, "gif") == 0) - return "image/gif"; - if (2 < l && strcasecmp(unix_path + l - 3, "png") == 0) - return "image/png"; - if (2 < l && strcasecmp(unix_path + l - 3, "b60") == 0) - return "image/png"; - if (2 < l && strcasecmp(unix_path + l - 3, "jng") == 0) - return "image/jng"; - if (2 < l && strcasecmp(unix_path + l - 3, "svg") == 0) - return "image/svg"; - return "text/html"; -} - - -char *fetch_mimetype(const char *ro_path) -{ - return strdup("text/plain"); -} diff --git a/framebuffer/findfile.c b/framebuffer/findfile.c index 821a66305..67312f452 100644 --- a/framebuffer/findfile.c +++ b/framebuffer/findfile.c @@ -16,19 +16,9 @@ * along with this program. If not, see . */ -#include -#include -#include #include -#include -#include - -#include #include "utils/filepath.h" -#include "utils/log.h" -#include "utils/url.h" -#include "desktop/gui.h" #include "framebuffer/findfile.h" @@ -57,64 +47,6 @@ fb_init_resource(const char *resource_path) } -char *path_to_url(const char *path) -{ - int urllen; - char *url; - - if (path == NULL) - return NULL; - - urllen = strlen(path) + FILE_SCHEME_PREFIX_LEN + 1; - url = malloc(urllen); - - if (*path == '/') { - path++; /* file: paths are already absolute */ - } - - snprintf(url, urllen, "%s%s", FILE_SCHEME_PREFIX, path); - - return url; -} - - -char *url_to_path(const char *url) -{ - char *path; - char *respath; - url_func_result res; /* result from url routines */ - - res = url_path(url, &path); - if (res != URL_FUNC_OK) { - return NULL; - } - - res = url_unescape(path, &respath); - free(path); - if (res != URL_FUNC_OK) { - return NULL; - } - - return respath; -} - -nsurl *gui_get_resource_url(const char *path) -{ - char buf[PATH_MAX]; - char *raw; - nsurl *url = NULL; - - if (strcmp(path, "favicon.ico") == 0) - path = "favicon.png"; - - raw = path_to_url(filepath_sfind(respaths, buf, path)); - if (raw != NULL) { - nsurl_create(raw, &url); - free(raw); - } - - return url; -} /* * Local Variables: diff --git a/framebuffer/findfile.h b/framebuffer/findfile.h index ca40c7751..1f3db6eb1 100644 --- a/framebuffer/findfile.h +++ b/framebuffer/findfile.h @@ -19,8 +19,6 @@ #ifndef NETSURF_FB_FINDFILE_H #define NETSURF_FB_FINDFILE_H -#include "utils/nsurl.h" - extern char **respaths; /** Create an array of valid paths to search for resources. @@ -31,6 +29,4 @@ extern char **respaths; */ char **fb_init_resource(const char *resource_path); -nsurl *gui_get_resource_url(const char *path); - #endif /* NETSURF_FB_FINDFILE_H */ diff --git a/framebuffer/gui.c b/framebuffer/gui.c index 82af56d9e..e7f456d8b 100644 --- a/framebuffer/gui.c +++ b/framebuffer/gui.c @@ -55,7 +55,7 @@ #include "framebuffer/image_data.h" #include "framebuffer/font.h" #include "framebuffer/clipboard.h" -#include "framebuffer/filetype.h" +#include "framebuffer/fetch.h" #include "content/urldb.h" #include "desktop/local_history.h" @@ -1768,43 +1768,6 @@ gui_window_remove_caret(struct gui_window *g) } } -/** - * Return the filename part of a full path - * - * \param path full path and filename - * \return filename (will be freed with free()) - */ -static char *filename_from_path(char *path) -{ - char *leafname; - - leafname = strrchr(path, '/'); - if (!leafname) - leafname = path; - else - leafname += 1; - - return strdup(leafname); -} - -/** - * Add a path component/filename to an existing path - * - * \param path buffer containing path + free space - * \param length length of buffer "path" - * \param newpart string containing path component to add to path - * \return true on success - */ - -static bool path_add_part(char *path, int length, const char *newpart) -{ - if(path[strlen(path) - 1] != '/') - strncat(path, "/", length); - - strncat(path, newpart, length); - - return true; -} static struct gui_window_table framebuffer_window_table = { .create = gui_window_create, @@ -1825,14 +1788,6 @@ static struct gui_window_table framebuffer_window_table = { .stop_throbber = gui_window_stop_throbber, }; -static struct gui_fetch_table framebuffer_fetch_table = { - .filename_from_path = filename_from_path, - .path_add_part = path_add_part, - .filetype = fetch_filetype, - - .get_resource_url = gui_get_resource_url, - .mimetype = fetch_mimetype, -}; static struct gui_browser_table framebuffer_browser_table = { .poll = gui_poll, @@ -1859,7 +1814,7 @@ main(int argc, char** argv) .browser = &framebuffer_browser_table, .window = &framebuffer_window_table, .clipboard = framebuffer_clipboard_table, - .fetch = &framebuffer_fetch_table, + .fetch = framebuffer_fetch_table, }; respaths = fb_init_resource(NETSURF_FB_RESPATH":"NETSURF_FB_FONTPATH); From b38dfd793966611c386e4a9c7f5772a16b5e88b8 Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Fri, 24 Jan 2014 11:54:53 +0000 Subject: [PATCH 118/773] ensure monkey command dispatch frees argument vector (coverity 1127054) --- monkey/dispatch.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/monkey/dispatch.c b/monkey/dispatch.c index c1b3edce4..c186a89ce 100644 --- a/monkey/dispatch.c +++ b/monkey/dispatch.c @@ -81,6 +81,9 @@ monkey_process_command(void) } } RING_ITERATE_END(handler_ring, handler); - if (fn != NULL) + if (fn != NULL) { fn(argc, argv); + } + + free(argv); } From b7e372cf84e00b2231ecf84dc6a7c65c8d42f501 Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Fri, 24 Jan 2014 12:11:10 +0000 Subject: [PATCH 119/773] ensure imagemap lists are freed on error paths (coverity 1109880) --- render/imagemap.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/render/imagemap.c b/render/imagemap.c index 870db7e3a..cb853ce21 100644 --- a/render/imagemap.c +++ b/render/imagemap.c @@ -304,6 +304,10 @@ imagemap_extract(html_content *c) if (name != NULL) { struct mapentry *entry = NULL; if (imagemap_extract_map(node, c, &entry) == false) { + if (entry != NULL) { + imagemap_freelist(entry); + } + dom_string_unref(name); dom_node_unref(node); ret = NSERROR_NOMEM; /** @todo check this */ @@ -317,6 +321,8 @@ imagemap_extract(html_content *c) */ if ((entry != NULL) && (imagemap_add(c, name, entry) == false)) { + imagemap_freelist(entry); + dom_string_unref(name); dom_node_unref(node); ret = NSERROR_NOMEM; /** @todo check this */ From 05dc1c1305e1de0fc77ac4671c336e96413911b0 Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Fri, 24 Jan 2014 14:21:27 +0000 Subject: [PATCH 120/773] Fix Coverity-spotted issue. (Fixes behaviour for multiple selects.) Also minor optimisation. --- render/form.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/render/form.c b/render/form.c index 5ce8056de..32c38be4b 100644 --- a/render/form.c +++ b/render/form.c @@ -1333,9 +1333,10 @@ static void form__select_process_selection(html_content *html, for (count = 0, o = control->data.select.items; o != NULL; count++, o = o->next) { - if (!control->data.select.multiple) + if (!control->data.select.multiple && o->selected) { o->selected = false; dom_html_option_element_set_selected(o->node, false); + } if (count == item) { if (control->data.select.multiple) { if (o->selected) { From 20e789955dc3d1e720193713306b44e1ffec0516 Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Fri, 24 Jan 2014 17:32:49 +0000 Subject: [PATCH 121/773] Ensure first option gets selected when the markup doesn't specify any options as selected. --- render/box_construct.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/render/box_construct.c b/render/box_construct.c index 4d9796932..3d077e8cd 100644 --- a/render/box_construct.c +++ b/render/box_construct.c @@ -2780,6 +2780,8 @@ bool box_select(BOX_SPECIAL_PARAMS) gadget->data.select.current->initial_selected = gadget->data.select.current->selected = true; gadget->data.select.num_selected = 1; + dom_html_option_element_set_selected( + gadget->data.select.current->node, true); } if (gadget->data.select.num_selected == 0) From 72510f550bf42cf660faf1a1929cb6df59bf86fd Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Fri, 24 Jan 2014 18:58:12 +0000 Subject: [PATCH 122/773] Use corestrings in box construction. --- render/box.h | 2 - render/box_construct.c | 204 +++++++++-------------------------------- render/html.c | 6 -- utils/corestrings.c | 45 +++++++++ utils/corestrings.h | 15 +++ 5 files changed, 102 insertions(+), 170 deletions(-) diff --git a/render/box.h b/render/box.h index 878ebc8d3..e781a66ec 100644 --- a/render/box.h +++ b/render/box.h @@ -339,8 +339,6 @@ bool box_handle_scrollbars(struct content *c, struct box *box, bool box_vscrollbar_present(const struct box *box); bool box_hscrollbar_present(const struct box *box); -nserror box_construct_init(void); -void box_construct_fini(void); nserror dom_to_box(struct dom_node *n, struct html_content *c, box_construct_complete_cb cb); diff --git a/render/box_construct.c b/render/box_construct.c index 3d077e8cd..ce21b70f7 100644 --- a/render/box_construct.c +++ b/render/box_construct.c @@ -210,134 +210,13 @@ static const box_type box_map[] = { BOX_NONE /*CSS_DISPLAY_NONE*/ }; -/** Key for box userdata on DOM elements (== '__ns_box') */ -static dom_string *kstr_box_key; -static dom_string *kstr_title; -static dom_string *kstr_id; -static dom_string *kstr_colspan; -static dom_string *kstr_rowspan; -static dom_string *kstr_style; -static dom_string *kstr_href; -static dom_string *kstr_name; -static dom_string *kstr_target; -static dom_string *kstr_alt; -static dom_string *kstr_src; -static dom_string *kstr_codebase; -static dom_string *kstr_classid; -static dom_string *kstr_data; -static dom_string *kstr_rows; -static dom_string *kstr_cols; -static dom_string *kstr_border; -static dom_string *kstr_frameborder; -static dom_string *kstr_bordercolor; -static dom_string *kstr_noresize; -static dom_string *kstr_scrolling; -static dom_string *kstr_marginwidth; -static dom_string *kstr_marginheight; -static dom_string *kstr_type; -static dom_string *kstr_value; -static dom_string *kstr_selected; - -nserror box_construct_init(void) -{ - dom_exception err; - - err = dom_string_create_interned((const uint8_t *) "__ns_box", - SLEN("__ns_box"), &kstr_box_key); - if (err != DOM_NO_ERR || kstr_box_key == NULL) - goto error; - -#define BOX_CONSTRUCT_STRING_INTERN(NAME) \ - err = dom_string_create_interned((const uint8_t *)#NAME, \ - sizeof(#NAME) - 1, \ - &kstr_##NAME ); \ - if ((err != DOM_NO_ERR) || (kstr_##NAME == NULL)) \ - goto error - - BOX_CONSTRUCT_STRING_INTERN(title); - BOX_CONSTRUCT_STRING_INTERN(id); - BOX_CONSTRUCT_STRING_INTERN(colspan); - BOX_CONSTRUCT_STRING_INTERN(rowspan); - BOX_CONSTRUCT_STRING_INTERN(style); - BOX_CONSTRUCT_STRING_INTERN(href); - BOX_CONSTRUCT_STRING_INTERN(name); - BOX_CONSTRUCT_STRING_INTERN(target); - BOX_CONSTRUCT_STRING_INTERN(alt); - BOX_CONSTRUCT_STRING_INTERN(src); - BOX_CONSTRUCT_STRING_INTERN(codebase); - BOX_CONSTRUCT_STRING_INTERN(classid); - BOX_CONSTRUCT_STRING_INTERN(data); - BOX_CONSTRUCT_STRING_INTERN(rows); - BOX_CONSTRUCT_STRING_INTERN(cols); - BOX_CONSTRUCT_STRING_INTERN(border); - BOX_CONSTRUCT_STRING_INTERN(frameborder); - BOX_CONSTRUCT_STRING_INTERN(bordercolor); - BOX_CONSTRUCT_STRING_INTERN(noresize); - BOX_CONSTRUCT_STRING_INTERN(scrolling); - BOX_CONSTRUCT_STRING_INTERN(marginwidth); - BOX_CONSTRUCT_STRING_INTERN(marginheight); - BOX_CONSTRUCT_STRING_INTERN(type); - BOX_CONSTRUCT_STRING_INTERN(value); - BOX_CONSTRUCT_STRING_INTERN(selected); - -#undef BOX_CONSTRUCT_STRING_INTERN - - return NSERROR_OK; - -error: - return NSERROR_NOMEM; -} - -void box_construct_fini(void) -{ - if (kstr_box_key != NULL) { - dom_string_unref(kstr_box_key); - kstr_box_key = NULL; - } - -#define BOX_CONSTRUCT_STRING_UNREF(NAME) \ - do { \ - if (kstr_##NAME != NULL) { \ - dom_string_unref(kstr_##NAME); \ - kstr_##NAME = NULL; \ - } \ - } while (0) \ - - BOX_CONSTRUCT_STRING_UNREF(title); - BOX_CONSTRUCT_STRING_UNREF(id); - BOX_CONSTRUCT_STRING_UNREF(colspan); - BOX_CONSTRUCT_STRING_UNREF(rowspan); - BOX_CONSTRUCT_STRING_UNREF(style); - BOX_CONSTRUCT_STRING_UNREF(href); - BOX_CONSTRUCT_STRING_UNREF(name); - BOX_CONSTRUCT_STRING_UNREF(target); - BOX_CONSTRUCT_STRING_UNREF(alt); - BOX_CONSTRUCT_STRING_UNREF(src); - BOX_CONSTRUCT_STRING_UNREF(codebase); - BOX_CONSTRUCT_STRING_UNREF(classid); - BOX_CONSTRUCT_STRING_UNREF(data); - BOX_CONSTRUCT_STRING_UNREF(rows); - BOX_CONSTRUCT_STRING_UNREF(cols); - BOX_CONSTRUCT_STRING_UNREF(border); - BOX_CONSTRUCT_STRING_UNREF(frameborder); - BOX_CONSTRUCT_STRING_UNREF(bordercolor); - BOX_CONSTRUCT_STRING_UNREF(noresize); - BOX_CONSTRUCT_STRING_UNREF(scrolling); - BOX_CONSTRUCT_STRING_UNREF(marginwidth); - BOX_CONSTRUCT_STRING_UNREF(marginheight); - BOX_CONSTRUCT_STRING_UNREF(type); - BOX_CONSTRUCT_STRING_UNREF(value); - BOX_CONSTRUCT_STRING_UNREF(selected); - -#undef BOX_CONSTRUCT_DOM_STRING_UNREF -} - static inline struct box *box_for_node(dom_node *n) { struct box *box = NULL; dom_exception err; - err = dom_node_get_user_data(n, kstr_box_key, (void *) &box); + err = dom_node_get_user_data(n, corestring_dom___ns_key_box_node_data, + (void *) &box); if (err != DOM_NO_ERR) return NULL; @@ -859,7 +738,7 @@ bool box_construct_element(struct box_construct_ctx *ctx, return false; /* Extract title attribute, if present */ - err = dom_element_get_attribute(ctx->n, kstr_title, &title0); + err = dom_element_get_attribute(ctx->n, corestring_dom_title, &title0); if (err != DOM_NO_ERR) return false; @@ -880,7 +759,7 @@ bool box_construct_element(struct box_construct_ctx *ctx, } /* Extract id attribute, if present */ - err = dom_element_get_attribute(ctx->n, kstr_id, &s); + err = dom_element_get_attribute(ctx->n, corestring_dom_id, &s); if (err != DOM_NO_ERR) return false; @@ -903,7 +782,7 @@ bool box_construct_element(struct box_construct_ctx *ctx, ctx->root_box = box; /* Deal with colspan/rowspan */ - err = dom_element_get_attribute(ctx->n, kstr_colspan, &s); + err = dom_element_get_attribute(ctx->n, corestring_dom_colspan, &s); if (err != DOM_NO_ERR) return false; @@ -916,7 +795,7 @@ bool box_construct_element(struct box_construct_ctx *ctx, dom_string_unref(s); } - err = dom_element_get_attribute(ctx->n, kstr_rowspan, &s); + err = dom_element_get_attribute(ctx->n, corestring_dom_rowspan, &s); if (err != DOM_NO_ERR) return false; @@ -1000,7 +879,8 @@ bool box_construct_element(struct box_construct_ctx *ctx, } /* Attach DOM node to box */ - err = dom_node_set_user_data(ctx->n, kstr_box_key, box, NULL, + err = dom_node_set_user_data(ctx->n, + corestring_dom___ns_key_box_node_data, box, NULL, (void *) &old_box); if (err != DOM_NO_ERR) return false; @@ -1433,7 +1313,7 @@ css_select_results *box_get_style(html_content *c, nscss_select_ctx ctx; /* Firstly, construct inline stylesheet, if any */ - err = dom_element_get_attribute(n, kstr_style, &s); + err = dom_element_get_attribute(n, corestring_dom_style, &s); if (err != DOM_NO_ERR) return NULL; @@ -1575,7 +1455,7 @@ bool box_a(BOX_SPECIAL_PARAMS) dom_string *s; dom_exception err; - err = dom_element_get_attribute(n, kstr_href, &s); + err = dom_element_get_attribute(n, corestring_dom_href, &s); if (err == DOM_NO_ERR && s != NULL) { ok = box_extract_link(dom_string_data(s), content->base_url, &url); @@ -1590,7 +1470,7 @@ bool box_a(BOX_SPECIAL_PARAMS) } /* name and id share the same namespace */ - err = dom_element_get_attribute(n, kstr_name, &s); + err = dom_element_get_attribute(n, corestring_dom_name, &s); if (err == DOM_NO_ERR && s != NULL) { lwc_string *lwc_name; @@ -1609,7 +1489,7 @@ bool box_a(BOX_SPECIAL_PARAMS) } /* target frame [16.3] */ - err = dom_element_get_attribute(n, kstr_target, &s); + err = dom_element_get_attribute(n, corestring_dom_target, &s); if (err == DOM_NO_ERR && s != NULL) { if (dom_string_caseless_lwc_isequal(s, corestring_lwc__blank)) @@ -1663,7 +1543,7 @@ bool box_image(BOX_SPECIAL_PARAMS) return true; /* handle alt text */ - err = dom_element_get_attribute(n, kstr_alt, &s); + err = dom_element_get_attribute(n, corestring_dom_alt, &s); if (err == DOM_NO_ERR && s != NULL) { char *alt = squash_whitespace(dom_string_data(s)); dom_string_unref(s); @@ -1687,7 +1567,7 @@ bool box_image(BOX_SPECIAL_PARAMS) box->usemap++; /* get image URL */ - err = dom_element_get_attribute(n, kstr_src, &s); + err = dom_element_get_attribute(n, corestring_dom_src, &s); if (err != DOM_NO_ERR || s == NULL) return true; @@ -1790,7 +1670,7 @@ bool box_object(BOX_SPECIAL_PARAMS) /* codebase, classid, and data are URLs * (codebase is the base for the other two) */ - err = dom_element_get_attribute(n, kstr_codebase, &codebase); + err = dom_element_get_attribute(n, corestring_dom_codebase, &codebase); if (err == DOM_NO_ERR && codebase != NULL) { if (box_extract_link(dom_string_data(codebase), content->base_url, @@ -1803,7 +1683,7 @@ bool box_object(BOX_SPECIAL_PARAMS) if (params->codebase == NULL) params->codebase = nsurl_ref(content->base_url); - err = dom_element_get_attribute(n, kstr_classid, &classid); + err = dom_element_get_attribute(n, corestring_dom_classid, &classid); if (err == DOM_NO_ERR && classid != NULL) { if (box_extract_link(dom_string_data(classid), params->codebase, ¶ms->classid) == false) { @@ -1813,7 +1693,7 @@ bool box_object(BOX_SPECIAL_PARAMS) dom_string_unref(classid); } - err = dom_element_get_attribute(n, kstr_data, &data); + err = dom_element_get_attribute(n, corestring_dom_data, &data); if (err == DOM_NO_ERR && data != NULL) { if (box_extract_link(dom_string_data(data), params->codebase, ¶ms->data) == false) { @@ -2052,7 +1932,7 @@ bool box_create_frameset(struct content_html_frames *f, dom_node *n, colour default_border_colour = 0x000000; /* parse rows and columns */ - err = dom_element_get_attribute(n, kstr_rows, &s); + err = dom_element_get_attribute(n, corestring_dom_rows, &s); if (err == DOM_NO_ERR && s != NULL) { row_height = box_parse_multi_lengths(dom_string_data(s), &rows); dom_string_unref(s); @@ -2066,7 +1946,7 @@ bool box_create_frameset(struct content_html_frames *f, dom_node *n, row_height->unit = FRAME_DIMENSION_PERCENT; } - err = dom_element_get_attribute(n, kstr_cols, &s); + err = dom_element_get_attribute(n, corestring_dom_cols, &s); if (err == DOM_NO_ERR && s != NULL) { col_width = box_parse_multi_lengths(dom_string_data(s), &cols); dom_string_unref(s); @@ -2085,7 +1965,7 @@ bool box_create_frameset(struct content_html_frames *f, dom_node *n, } /* common extension: border="0|1" to control all children */ - err = dom_element_get_attribute(n, kstr_border, &s); + err = dom_element_get_attribute(n, corestring_dom_border, &s); if (err == DOM_NO_ERR && s != NULL) { if ((dom_string_data(s)[0] == '0') && (dom_string_data(s)[1] == '\0')) @@ -2094,7 +1974,7 @@ bool box_create_frameset(struct content_html_frames *f, dom_node *n, } /* common extension: frameborder="yes|no" to control all children */ - err = dom_element_get_attribute(n, kstr_frameborder, &s); + err = dom_element_get_attribute(n, corestring_dom_frameborder, &s); if (err == DOM_NO_ERR && s != NULL) { if (dom_string_caseless_lwc_isequal(s, corestring_lwc_no) == 0) @@ -2104,7 +1984,7 @@ bool box_create_frameset(struct content_html_frames *f, dom_node *n, /* common extension: bordercolor="#RRGGBB|" to control *all children */ - err = dom_element_get_attribute(n, kstr_bordercolor, &s); + err = dom_element_get_attribute(n, corestring_dom_bordercolor, &s); if (err == DOM_NO_ERR && s != NULL) { css_color color; @@ -2233,7 +2113,7 @@ bool box_create_frameset(struct content_html_frames *f, dom_node *n, /* get frame URL (not required) */ url = NULL; - err = dom_element_get_attribute(c, kstr_src, &s); + err = dom_element_get_attribute(c, corestring_dom_src, &s); if (err == DOM_NO_ERR && s != NULL) { box_extract_link(dom_string_data(s), content->base_url, &url); @@ -2250,17 +2130,17 @@ bool box_create_frameset(struct content_html_frames *f, dom_node *n, } /* fill in specified values */ - err = dom_element_get_attribute(c, kstr_name, &s); + err = dom_element_get_attribute(c, corestring_dom_name, &s); if (err == DOM_NO_ERR && s != NULL) { frame->name = talloc_strdup(content->bctx, dom_string_data(s)); dom_string_unref(s); } - dom_element_has_attribute(c, kstr_noresize, + dom_element_has_attribute(c, corestring_dom_noresize, &frame->no_resize); - err = dom_element_get_attribute(c, kstr_frameborder, + err = dom_element_get_attribute(c, corestring_dom_frameborder, &s); if (err == DOM_NO_ERR && s != NULL) { i = atoi(dom_string_data(s)); @@ -2268,7 +2148,7 @@ bool box_create_frameset(struct content_html_frames *f, dom_node *n, dom_string_unref(s); } - err = dom_element_get_attribute(c, kstr_scrolling, &s); + err = dom_element_get_attribute(c, corestring_dom_scrolling, &s); if (err == DOM_NO_ERR && s != NULL) { if (dom_string_caseless_lwc_isequal(s, corestring_lwc_yes)) @@ -2279,21 +2159,21 @@ bool box_create_frameset(struct content_html_frames *f, dom_node *n, dom_string_unref(s); } - err = dom_element_get_attribute(c, kstr_marginwidth, + err = dom_element_get_attribute(c, corestring_dom_marginwidth, &s); if (err == DOM_NO_ERR && s != NULL) { frame->margin_width = atoi(dom_string_data(s)); dom_string_unref(s); } - err = dom_element_get_attribute(c, kstr_marginheight, + err = dom_element_get_attribute(c, corestring_dom_marginheight, &s); if (err == DOM_NO_ERR && s != NULL) { frame->margin_height = atoi(dom_string_data(s)); dom_string_unref(s); } - err = dom_element_get_attribute(c, kstr_bordercolor, + err = dom_element_get_attribute(c, corestring_dom_bordercolor, &s); if (err == DOM_NO_ERR && s != NULL) { css_color color; @@ -2363,7 +2243,7 @@ bool box_iframe(BOX_SPECIAL_PARAMS) return true; /* get frame URL */ - err = dom_element_get_attribute(n, kstr_src, &s); + err = dom_element_get_attribute(n, corestring_dom_src, &s); if (err != DOM_NO_ERR || s == NULL) return true; if (box_extract_link(dom_string_data(s), content->base_url, @@ -2403,20 +2283,20 @@ bool box_iframe(BOX_SPECIAL_PARAMS) content->iframe = iframe; /* fill in specified values */ - err = dom_element_get_attribute(n, kstr_name, &s); + err = dom_element_get_attribute(n, corestring_dom_name, &s); if (err == DOM_NO_ERR && s != NULL) { iframe->name = talloc_strdup(content->bctx, dom_string_data(s)); dom_string_unref(s); } - err = dom_element_get_attribute(n, kstr_frameborder, &s); + err = dom_element_get_attribute(n, corestring_dom_frameborder, &s); if (err == DOM_NO_ERR && s != NULL) { i = atoi(dom_string_data(s)); iframe->border = (i != 0); dom_string_unref(s); } - err = dom_element_get_attribute(n, kstr_bordercolor, &s); + err = dom_element_get_attribute(n, corestring_dom_bordercolor, &s); if (err == DOM_NO_ERR && s != NULL) { css_color color; @@ -2426,7 +2306,7 @@ bool box_iframe(BOX_SPECIAL_PARAMS) dom_string_unref(s); } - err = dom_element_get_attribute(n, kstr_scrolling, &s); + err = dom_element_get_attribute(n, corestring_dom_scrolling, &s); if (err == DOM_NO_ERR && s != NULL) { if (dom_string_caseless_lwc_isequal(s, corestring_lwc_yes)) @@ -2437,13 +2317,13 @@ bool box_iframe(BOX_SPECIAL_PARAMS) dom_string_unref(s); } - err = dom_element_get_attribute(n, kstr_marginwidth, &s); + err = dom_element_get_attribute(n, corestring_dom_marginwidth, &s); if (err == DOM_NO_ERR && s != NULL) { iframe->margin_width = atoi(dom_string_data(s)); dom_string_unref(s); } - err = dom_element_get_attribute(n, kstr_marginheight, &s); + err = dom_element_get_attribute(n, corestring_dom_marginheight, &s); if (err == DOM_NO_ERR && s != NULL) { iframe->margin_height = atoi(dom_string_data(s)); dom_string_unref(s); @@ -2504,7 +2384,7 @@ bool box_input(BOX_SPECIAL_PARAMS) nsurl *url; nserror error; - dom_element_get_attribute(n, kstr_type, &type); + dom_element_get_attribute(n, corestring_dom_type, &type); gadget = html_forms_get_control_for_node(content->forms, n); if (gadget == NULL) @@ -2589,7 +2469,7 @@ bool box_input(BOX_SPECIAL_PARAMS) nsoption_bool(foreground_images) == true) { dom_string *s; - err = dom_element_get_attribute(n, kstr_src, &s); + err = dom_element_get_attribute(n, corestring_dom_src, &s); if (err == DOM_NO_ERR && s != NULL) { error = nsurl_join(content->base_url, dom_string_data(s), &url); @@ -2837,7 +2717,7 @@ bool box_select_add_option(struct form_control *control, dom_node *n) if (text == NULL) goto no_memory; - err = dom_element_get_attribute(n, kstr_value, &s); + err = dom_element_get_attribute(n, corestring_dom_value, &s); if (err == DOM_NO_ERR && s != NULL) { value = strdup(dom_string_data(s)); dom_string_unref(s); @@ -2848,7 +2728,7 @@ bool box_select_add_option(struct form_control *control, dom_node *n) if (value == NULL) goto no_memory; - dom_element_has_attribute(n, kstr_selected, &selected); + dom_element_has_attribute(n, corestring_dom_selected, &selected); /* replace spaces/TABs with hard spaces to prevent line wrapping */ text_nowrap = cnv_space2nbsp(text); @@ -2924,7 +2804,7 @@ bool box_embed(BOX_SPECIAL_PARAMS) params->params = NULL; /* src is a URL */ - err = dom_element_get_attribute(n, kstr_src, &src); + err = dom_element_get_attribute(n, corestring_dom_src, &src); if (err != DOM_NO_ERR || src == NULL) return true; if (box_extract_link(dom_string_data(src), content->base_url, diff --git a/render/html.c b/render/html.c index e10f1e930..0a7ab2453 100644 --- a/render/html.c +++ b/render/html.c @@ -2180,8 +2180,6 @@ static content_type html_content_type(void) static void html_fini(void) { - box_construct_fini(); - html_css_fini(); } @@ -2221,10 +2219,6 @@ nserror html_init(void) if (error != NSERROR_OK) goto error; - error = box_construct_init(); - if (error != NSERROR_OK) - goto error; - for (i = 0; i < NOF_ELEMENTS(html_types); i++) { error = content_factory_register_handler(html_types[i], &html_content_handler); diff --git a/utils/corestrings.c b/utils/corestrings.c index e60a75bdc..85bced5ab 100644 --- a/utils/corestrings.c +++ b/utils/corestrings.c @@ -116,6 +116,7 @@ lwc_string *corestring_lwc__top; /* dom_string strings */ dom_string *corestring_dom_a; +dom_string *corestring_dom_alt; dom_string *corestring_dom_abort; dom_string *corestring_dom_afterprint; dom_string *corestring_dom_align; @@ -136,14 +137,18 @@ dom_string *corestring_dom_cellspacing; dom_string *corestring_dom_change; dom_string *corestring_dom_charset; dom_string *corestring_dom_class; +dom_string *corestring_dom_classid; dom_string *corestring_dom_click; dom_string *corestring_dom_close; +dom_string *corestring_dom_codebase; dom_string *corestring_dom_color; dom_string *corestring_dom_cols; +dom_string *corestring_dom_colspan; dom_string *corestring_dom_content; dom_string *corestring_dom_contextmenu; dom_string *corestring_dom_coords; dom_string *corestring_dom_cuechange; +dom_string *corestring_dom_data; dom_string *corestring_dom_dblclick; dom_string *corestring_dom_defer; dom_string *corestring_dom_DOMAttrModified; @@ -162,6 +167,7 @@ dom_string *corestring_dom_emptied; dom_string *corestring_dom_ended; dom_string *corestring_dom_error; dom_string *corestring_dom_focus; +dom_string *corestring_dom_frameborder; dom_string *corestring_dom_hashchange; dom_string *corestring_dom_height; dom_string *corestring_dom_href; @@ -180,6 +186,8 @@ dom_string *corestring_dom_loadeddata; dom_string *corestring_dom_loadedmetadata; dom_string *corestring_dom_loadstart; dom_string *corestring_dom_map; +dom_string *corestring_dom_marginheight; +dom_string *corestring_dom_marginwidth; dom_string *corestring_dom_media; dom_string *corestring_dom_message; dom_string *corestring_dom_mousedown; @@ -190,6 +198,7 @@ dom_string *corestring_dom_mouseup; dom_string *corestring_dom_mousewheel; dom_string *corestring_dom_name; dom_string *corestring_dom_nohref; +dom_string *corestring_dom_noresize; dom_string *corestring_dom_offline; dom_string *corestring_dom_online; dom_string *corestring_dom_pagehide; @@ -206,10 +215,13 @@ dom_string *corestring_dom_rel; dom_string *corestring_dom_reset; dom_string *corestring_dom_resize; dom_string *corestring_dom_rows; +dom_string *corestring_dom_rowspan; dom_string *corestring_dom_scroll; +dom_string *corestring_dom_scrolling; dom_string *corestring_dom_seeked; dom_string *corestring_dom_seeking; dom_string *corestring_dom_select; +dom_string *corestring_dom_selected; dom_string *corestring_dom_shape; dom_string *corestring_dom_show; dom_string *corestring_dom_size; @@ -224,9 +236,11 @@ dom_string *corestring_dom_target; dom_string *corestring_dom_text; dom_string *corestring_dom_text_javascript; dom_string *corestring_dom_timeupdate; +dom_string *corestring_dom_title; dom_string *corestring_dom_type; dom_string *corestring_dom_unload; dom_string *corestring_dom_valign; +dom_string *corestring_dom_value; dom_string *corestring_dom_vlink; dom_string *corestring_dom_volumechange; dom_string *corestring_dom_vspace; @@ -242,6 +256,7 @@ dom_string *corestring_dom_radio; dom_string *corestring_dom_checkbox; dom_string *corestring_dom_file; dom_string *corestring_dom_on; +dom_string *corestring_dom___ns_key_box_node_data; dom_string *corestring_dom___ns_key_libcss_node_data; dom_string *corestring_dom___ns_key_file_name_node_data; dom_string *corestring_dom___ns_key_image_coords_node_data; @@ -361,6 +376,7 @@ void corestrings_fini(void) CSS_DOM_STRING_UNREF(abort); CSS_DOM_STRING_UNREF(afterprint); CSS_DOM_STRING_UNREF(align); + CSS_DOM_STRING_UNREF(alt); CSS_DOM_STRING_UNREF(area); CSS_DOM_STRING_UNREF(async); CSS_DOM_STRING_UNREF(background); @@ -378,14 +394,18 @@ void corestrings_fini(void) CSS_DOM_STRING_UNREF(change); CSS_DOM_STRING_UNREF(charset); CSS_DOM_STRING_UNREF(class); + CSS_DOM_STRING_UNREF(classid); CSS_DOM_STRING_UNREF(click); CSS_DOM_STRING_UNREF(close); + CSS_DOM_STRING_UNREF(codebase); CSS_DOM_STRING_UNREF(color); CSS_DOM_STRING_UNREF(cols); + CSS_DOM_STRING_UNREF(colspan); CSS_DOM_STRING_UNREF(content); CSS_DOM_STRING_UNREF(contextmenu); CSS_DOM_STRING_UNREF(coords); CSS_DOM_STRING_UNREF(cuechange); + CSS_DOM_STRING_UNREF(data); CSS_DOM_STRING_UNREF(dblclick); CSS_DOM_STRING_UNREF(defer); CSS_DOM_STRING_UNREF(DOMAttrModified); @@ -404,6 +424,7 @@ void corestrings_fini(void) CSS_DOM_STRING_UNREF(ended); CSS_DOM_STRING_UNREF(error); CSS_DOM_STRING_UNREF(focus); + CSS_DOM_STRING_UNREF(frameborder); CSS_DOM_STRING_UNREF(hashchange); CSS_DOM_STRING_UNREF(height); CSS_DOM_STRING_UNREF(href); @@ -422,6 +443,8 @@ void corestrings_fini(void) CSS_DOM_STRING_UNREF(loadedmetadata); CSS_DOM_STRING_UNREF(loadstart); CSS_DOM_STRING_UNREF(map); + CSS_DOM_STRING_UNREF(marginheight); + CSS_DOM_STRING_UNREF(marginwidth); CSS_DOM_STRING_UNREF(media); CSS_DOM_STRING_UNREF(message); CSS_DOM_STRING_UNREF(mousedown); @@ -432,6 +455,7 @@ void corestrings_fini(void) CSS_DOM_STRING_UNREF(mousewheel); CSS_DOM_STRING_UNREF(name); CSS_DOM_STRING_UNREF(nohref); + CSS_DOM_STRING_UNREF(noresize); CSS_DOM_STRING_UNREF(offline); CSS_DOM_STRING_UNREF(online); CSS_DOM_STRING_UNREF(pagehide); @@ -448,10 +472,13 @@ void corestrings_fini(void) CSS_DOM_STRING_UNREF(reset); CSS_DOM_STRING_UNREF(resize); CSS_DOM_STRING_UNREF(rows); + CSS_DOM_STRING_UNREF(rowspan); CSS_DOM_STRING_UNREF(scroll); + CSS_DOM_STRING_UNREF(scrolling); CSS_DOM_STRING_UNREF(seeked); CSS_DOM_STRING_UNREF(seeking); CSS_DOM_STRING_UNREF(select); + CSS_DOM_STRING_UNREF(selected); CSS_DOM_STRING_UNREF(shape); CSS_DOM_STRING_UNREF(show); CSS_DOM_STRING_UNREF(size); @@ -466,9 +493,11 @@ void corestrings_fini(void) CSS_DOM_STRING_UNREF(text); CSS_DOM_STRING_UNREF(text_javascript); CSS_DOM_STRING_UNREF(timeupdate); + CSS_DOM_STRING_UNREF(title); CSS_DOM_STRING_UNREF(type); CSS_DOM_STRING_UNREF(unload); CSS_DOM_STRING_UNREF(valign); + CSS_DOM_STRING_UNREF(value); CSS_DOM_STRING_UNREF(vlink); CSS_DOM_STRING_UNREF(volumechange); CSS_DOM_STRING_UNREF(vspace); @@ -487,6 +516,7 @@ void corestrings_fini(void) CSS_DOM_STRING_UNREF(file); CSS_DOM_STRING_UNREF(on); /* DOM userdata keys, not really CSS */ + CSS_DOM_STRING_UNREF(__ns_key_box_node_data); CSS_DOM_STRING_UNREF(__ns_key_libcss_node_data); CSS_DOM_STRING_UNREF(__ns_key_file_name_node_data); CSS_DOM_STRING_UNREF(__ns_key_image_coords_node_data); @@ -638,6 +668,7 @@ nserror corestrings_init(void) CSS_DOM_STRING_INTERN(abort); CSS_DOM_STRING_INTERN(afterprint); CSS_DOM_STRING_INTERN(align); + CSS_DOM_STRING_INTERN(alt); CSS_DOM_STRING_INTERN(area); CSS_DOM_STRING_INTERN(async); CSS_DOM_STRING_INTERN(background); @@ -655,14 +686,18 @@ nserror corestrings_init(void) CSS_DOM_STRING_INTERN(change); CSS_DOM_STRING_INTERN(charset); CSS_DOM_STRING_INTERN(class); + CSS_DOM_STRING_INTERN(classid); CSS_DOM_STRING_INTERN(click); CSS_DOM_STRING_INTERN(close); + CSS_DOM_STRING_INTERN(codebase); CSS_DOM_STRING_INTERN(color); CSS_DOM_STRING_INTERN(cols); + CSS_DOM_STRING_INTERN(colspan); CSS_DOM_STRING_INTERN(content); CSS_DOM_STRING_INTERN(contextmenu); CSS_DOM_STRING_INTERN(coords); CSS_DOM_STRING_INTERN(cuechange); + CSS_DOM_STRING_INTERN(data); CSS_DOM_STRING_INTERN(dblclick); CSS_DOM_STRING_INTERN(defer); CSS_DOM_STRING_INTERN(DOMAttrModified); @@ -681,6 +716,7 @@ nserror corestrings_init(void) CSS_DOM_STRING_INTERN(ended); CSS_DOM_STRING_INTERN(error); CSS_DOM_STRING_INTERN(focus); + CSS_DOM_STRING_INTERN(frameborder); CSS_DOM_STRING_INTERN(hashchange); CSS_DOM_STRING_INTERN(height); CSS_DOM_STRING_INTERN(href); @@ -699,6 +735,8 @@ nserror corestrings_init(void) CSS_DOM_STRING_INTERN(loadedmetadata); CSS_DOM_STRING_INTERN(loadstart); CSS_DOM_STRING_INTERN(map); + CSS_DOM_STRING_INTERN(marginheight); + CSS_DOM_STRING_INTERN(marginwidth); CSS_DOM_STRING_INTERN(media); CSS_DOM_STRING_INTERN(message); CSS_DOM_STRING_INTERN(mousedown); @@ -709,6 +747,7 @@ nserror corestrings_init(void) CSS_DOM_STRING_INTERN(mousewheel); CSS_DOM_STRING_INTERN(name); CSS_DOM_STRING_INTERN(nohref); + CSS_DOM_STRING_INTERN(noresize); CSS_DOM_STRING_INTERN(offline); CSS_DOM_STRING_INTERN(online); CSS_DOM_STRING_INTERN(pagehide); @@ -725,10 +764,13 @@ nserror corestrings_init(void) CSS_DOM_STRING_INTERN(reset); CSS_DOM_STRING_INTERN(resize); CSS_DOM_STRING_INTERN(rows); + CSS_DOM_STRING_INTERN(rowspan); CSS_DOM_STRING_INTERN(scroll); + CSS_DOM_STRING_INTERN(scrolling); CSS_DOM_STRING_INTERN(seeked); CSS_DOM_STRING_INTERN(seeking); CSS_DOM_STRING_INTERN(select); + CSS_DOM_STRING_INTERN(selected); CSS_DOM_STRING_INTERN(shape); CSS_DOM_STRING_INTERN(show); CSS_DOM_STRING_INTERN(size); @@ -742,9 +784,11 @@ nserror corestrings_init(void) CSS_DOM_STRING_INTERN(target); CSS_DOM_STRING_INTERN(text); CSS_DOM_STRING_INTERN(timeupdate); + CSS_DOM_STRING_INTERN(title); CSS_DOM_STRING_INTERN(type); CSS_DOM_STRING_INTERN(unload); CSS_DOM_STRING_INTERN(valign); + CSS_DOM_STRING_INTERN(value); CSS_DOM_STRING_INTERN(vlink); CSS_DOM_STRING_INTERN(volumechange); CSS_DOM_STRING_INTERN(vspace); @@ -763,6 +807,7 @@ nserror corestrings_init(void) CSS_DOM_STRING_INTERN(file); CSS_DOM_STRING_INTERN(on); /* DOM userdata keys, not really CSS */ + CSS_DOM_STRING_INTERN(__ns_key_box_node_data); CSS_DOM_STRING_INTERN(__ns_key_libcss_node_data); CSS_DOM_STRING_INTERN(__ns_key_file_name_node_data); CSS_DOM_STRING_INTERN(__ns_key_image_coords_node_data); diff --git a/utils/corestrings.h b/utils/corestrings.h index 90fef5aaa..411f9cef2 100644 --- a/utils/corestrings.h +++ b/utils/corestrings.h @@ -122,6 +122,7 @@ struct dom_string; /* dom_string strings */ extern struct dom_string *corestring_dom_a; +extern struct dom_string *corestring_dom_alt; extern struct dom_string *corestring_dom_abort; extern struct dom_string *corestring_dom_afterprint; extern struct dom_string *corestring_dom_align; @@ -142,14 +143,18 @@ extern struct dom_string *corestring_dom_cellspacing; extern struct dom_string *corestring_dom_change; extern struct dom_string *corestring_dom_charset; extern struct dom_string *corestring_dom_class; +extern struct dom_string *corestring_dom_classid; extern struct dom_string *corestring_dom_click; extern struct dom_string *corestring_dom_close; +extern struct dom_string *corestring_dom_codebase; extern struct dom_string *corestring_dom_color; extern struct dom_string *corestring_dom_cols; +extern struct dom_string *corestring_dom_colspan; extern struct dom_string *corestring_dom_content; extern struct dom_string *corestring_dom_contextmenu; extern struct dom_string *corestring_dom_coords; extern struct dom_string *corestring_dom_cuechange; +extern struct dom_string *corestring_dom_data; extern struct dom_string *corestring_dom_dblclick; extern struct dom_string *corestring_dom_defer; extern struct dom_string *corestring_dom_DOMAttrModified; @@ -168,6 +173,7 @@ extern struct dom_string *corestring_dom_emptied; extern struct dom_string *corestring_dom_ended; extern struct dom_string *corestring_dom_error; extern struct dom_string *corestring_dom_focus; +extern struct dom_string *corestring_dom_frameborder; extern struct dom_string *corestring_dom_hashchange; extern struct dom_string *corestring_dom_height; extern struct dom_string *corestring_dom_href; @@ -186,6 +192,8 @@ extern struct dom_string *corestring_dom_loadeddata; extern struct dom_string *corestring_dom_loadedmetadata; extern struct dom_string *corestring_dom_loadstart; extern struct dom_string *corestring_dom_map; +extern struct dom_string *corestring_dom_marginheight; +extern struct dom_string *corestring_dom_marginwidth; extern struct dom_string *corestring_dom_media; extern struct dom_string *corestring_dom_message; extern struct dom_string *corestring_dom_mousedown; @@ -196,6 +204,7 @@ extern struct dom_string *corestring_dom_mouseup; extern struct dom_string *corestring_dom_mousewheel; extern struct dom_string *corestring_dom_name; extern struct dom_string *corestring_dom_nohref; +extern struct dom_string *corestring_dom_noresize; extern struct dom_string *corestring_dom_offline; extern struct dom_string *corestring_dom_online; extern struct dom_string *corestring_dom_pagehide; @@ -212,10 +221,13 @@ extern struct dom_string *corestring_dom_rel; extern struct dom_string *corestring_dom_reset; extern struct dom_string *corestring_dom_resize; extern struct dom_string *corestring_dom_rows; +extern struct dom_string *corestring_dom_rowspan; extern struct dom_string *corestring_dom_scroll; +extern struct dom_string *corestring_dom_scrolling; extern struct dom_string *corestring_dom_seeked; extern struct dom_string *corestring_dom_seeking; extern struct dom_string *corestring_dom_select; +extern struct dom_string *corestring_dom_selected; extern struct dom_string *corestring_dom_shape; extern struct dom_string *corestring_dom_show; extern struct dom_string *corestring_dom_size; @@ -230,9 +242,11 @@ extern struct dom_string *corestring_dom_target; extern struct dom_string *corestring_dom_text; extern struct dom_string *corestring_dom_text_javascript; extern struct dom_string *corestring_dom_timeupdate; +extern struct dom_string *corestring_dom_title; extern struct dom_string *corestring_dom_type; extern struct dom_string *corestring_dom_unload; extern struct dom_string *corestring_dom_valign; +extern struct dom_string *corestring_dom_value; extern struct dom_string *corestring_dom_vlink; extern struct dom_string *corestring_dom_volumechange; extern struct dom_string *corestring_dom_vspace; @@ -253,6 +267,7 @@ extern struct dom_string *corestring_dom_checkbox; extern struct dom_string *corestring_dom_file; extern struct dom_string *corestring_dom_on; /* DOM userdata keys */ +extern struct dom_string *corestring_dom___ns_key_box_node_data; extern struct dom_string *corestring_dom___ns_key_libcss_node_data; extern struct dom_string *corestring_dom___ns_key_file_name_node_data; extern struct dom_string *corestring_dom___ns_key_image_coords_node_data; From c4e2fff5a4670fd555c56a2b2ed232f210aaa2d5 Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Fri, 24 Jan 2014 19:25:07 +0000 Subject: [PATCH 123/773] Use corestrings for fetch module's lwc strings. --- content/fetch.c | 26 +++----------------------- utils/corestrings.c | 3 +++ utils/corestrings.h | 1 + 3 files changed, 7 insertions(+), 23 deletions(-) diff --git a/content/fetch.c b/content/fetch.c index 2d53b3149..4736670ff 100644 --- a/content/fetch.c +++ b/content/fetch.c @@ -45,6 +45,7 @@ #include "content/fetchers/file.h" #include "content/urldb.h" #include "desktop/netsurf.h" +#include "utils/corestrings.h" #include "utils/nsoption.h" #include "utils/log.h" #include "utils/messages.h" @@ -97,10 +98,6 @@ static struct fetch *queue_ring = 0; /**< Ring of queued fetches */ #define fetch_ref_fetcher(F) F->refcount++ -/* Static lwc_strings */ -static lwc_string *fetch_http_lwc; -static lwc_string *fetch_https_lwc; - /****************************************************************************** * fetch internals * ******************************************************************************/ @@ -241,20 +238,6 @@ static void fetch_dispatch_jobs(void) /* exported interface documented in content/fetch.h */ nserror fetch_init(void) { - if (lwc_intern_string("http", SLEN("http"), &fetch_http_lwc) != - lwc_error_ok) { - LOG(("Failed to initialise the fetch module " - "(couldn't intern \"http\").")); - return NSERROR_INIT_FAILED; - } - - if (lwc_intern_string("https", SLEN("https"), &fetch_https_lwc) != - lwc_error_ok) { - LOG(("Failed to initialise the fetch module " - "(couldn't intern \"https\").")); - return NSERROR_INIT_FAILED; - } - fetch_curl_register(); fetch_data_register(); fetch_file_register(); @@ -278,9 +261,6 @@ void fetch_quit(void) } fetch_unref_fetcher(fetchers); } - - lwc_string_unref(fetch_http_lwc); - lwc_string_unref(fetch_https_lwc); } /* exported interface documented in content/fetch.h */ @@ -383,11 +363,11 @@ struct fetch * fetch_start(nsurl *url, nsurl *referer, &match) != lwc_error_ok) { match = false; } - if (lwc_string_isequal(scheme, fetch_https_lwc, + if (lwc_string_isequal(scheme, corestring_lwc_https, &match1) != lwc_error_ok) { match1 = false; } - if (lwc_string_isequal(ref_scheme, fetch_http_lwc, + if (lwc_string_isequal(ref_scheme, corestring_lwc_http, &match2) != lwc_error_ok) { match2= false; } diff --git a/utils/corestrings.c b/utils/corestrings.c index 85bced5ab..ebe7c9932 100644 --- a/utils/corestrings.c +++ b/utils/corestrings.c @@ -59,6 +59,7 @@ lwc_string *corestring_lwc_head; lwc_string *corestring_lwc_hidden; lwc_string *corestring_lwc_hr; lwc_string *corestring_lwc_html; +lwc_string *corestring_lwc_http; lwc_string *corestring_lwc_https; lwc_string *corestring_lwc_iframe; lwc_string *corestring_lwc_image; @@ -307,6 +308,7 @@ void corestrings_fini(void) CSS_LWC_STRING_UNREF(hidden); CSS_LWC_STRING_UNREF(hr); CSS_LWC_STRING_UNREF(html); + CSS_LWC_STRING_UNREF(http); CSS_LWC_STRING_UNREF(https); CSS_LWC_STRING_UNREF(iframe); CSS_LWC_STRING_UNREF(image); @@ -579,6 +581,7 @@ nserror corestrings_init(void) CSS_LWC_STRING_INTERN(hidden); CSS_LWC_STRING_INTERN(hr); CSS_LWC_STRING_INTERN(html); + CSS_LWC_STRING_INTERN(http); CSS_LWC_STRING_INTERN(https); CSS_LWC_STRING_INTERN(iframe); CSS_LWC_STRING_INTERN(image); diff --git a/utils/corestrings.h b/utils/corestrings.h index 411f9cef2..5c3349f04 100644 --- a/utils/corestrings.h +++ b/utils/corestrings.h @@ -63,6 +63,7 @@ extern lwc_string *corestring_lwc_head; extern lwc_string *corestring_lwc_hidden; extern lwc_string *corestring_lwc_hr; extern lwc_string *corestring_lwc_html; +extern lwc_string *corestring_lwc_http; extern lwc_string *corestring_lwc_https; extern lwc_string *corestring_lwc_iframe; extern lwc_string *corestring_lwc_image; From 178f3945b8502d5fd483e0d0814d169b4b9bad2f Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Fri, 24 Jan 2014 19:31:50 +0000 Subject: [PATCH 124/773] Just use corestring refs. --- content/fetchers/curl.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/content/fetchers/curl.c b/content/fetchers/curl.c index f3a8385a1..90c9c138c 100644 --- a/content/fetchers/curl.c +++ b/content/fetchers/curl.c @@ -46,6 +46,7 @@ #include "content/urldb.h" #include "desktop/netsurf.h" #include "desktop/gui_factory.h" +#include "utils/corestrings.h" #include "utils/nsoption.h" #include "utils/log.h" #include "utils/messages.h" @@ -236,18 +237,10 @@ void fetch_curl_register(void) for (i = 0; data->protocols[i]; i++) { if (strcmp(data->protocols[i], "http") == 0) { - if (lwc_intern_string("http", SLEN("http"), - &scheme) != lwc_error_ok) { - die("Failed to initialise the fetch module " - "(couldn't intern \"http\")."); - } + scheme = lwc_string_ref(corestring_lwc_http); } else if (strcmp(data->protocols[i], "https") == 0) { - if (lwc_intern_string("https", SLEN("https"), - &scheme) != lwc_error_ok) { - die("Failed to initialise the fetch module " - "(couldn't intern \"https\")."); - } + scheme = lwc_string_ref(corestring_lwc_https); } else { /* Ignore non-http(s) protocols */ From e32dc31b04b8db0c27ef666e85a0cd058302fb15 Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Fri, 24 Jan 2014 19:58:51 +0000 Subject: [PATCH 125/773] Use corestring ref. --- content/fetchers/file.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/content/fetchers/file.c b/content/fetchers/file.c index 83c408e5a..7b93ab172 100644 --- a/content/fetchers/file.c +++ b/content/fetchers/file.c @@ -48,6 +48,7 @@ #include "content/urldb.h" #include "desktop/netsurf.h" #include "desktop/gui_factory.h" +#include "utils/corestrings.h" #include "utils/nsoption.h" #include "utils/errors.h" #include "utils/log.h" @@ -734,12 +735,7 @@ static void fetch_file_poll(lwc_string *scheme) void fetch_file_register(void) { - lwc_string *scheme; - - if (lwc_intern_string("file", SLEN("file"), &scheme) != lwc_error_ok) { - die("Failed to initialise the fetch module " - "(couldn't intern \"file\")."); - } + lwc_string *scheme = lwc_string_ref(corestring_lwc_file); fetch_add_fetcher(scheme, fetch_file_initialise, From 14238615a43f3c0f57790ab4b54fd44204695179 Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Fri, 24 Jan 2014 20:08:41 +0000 Subject: [PATCH 126/773] Use corestrings for "about", "data", and "resource". --- content/fetchers/about.c | 9 ++------- content/fetchers/data.c | 8 ++------ content/fetchers/resource.c | 9 ++------- utils/corestrings.c | 9 +++++++++ utils/corestrings.h | 3 +++ 5 files changed, 18 insertions(+), 20 deletions(-) diff --git a/content/fetchers/about.c b/content/fetchers/about.c index cac8b2b01..8e973a9cc 100644 --- a/content/fetchers/about.c +++ b/content/fetchers/about.c @@ -48,6 +48,7 @@ #include "content/urldb.h" #include "desktop/netsurf.h" #include "utils/nsoption.h" +#include "utils/corestrings.h" #include "utils/log.h" #include "utils/messages.h" #include "utils/url.h" @@ -839,13 +840,7 @@ static void fetch_about_poll(lwc_string *scheme) void fetch_about_register(void) { - lwc_string *scheme; - - if (lwc_intern_string("about", SLEN("about"), - &scheme) != lwc_error_ok) { - die("Failed to initialise the fetch module " - "(couldn't intern \"about\")."); - } + lwc_string *scheme = lwc_string_ref(corestring_lwc_about); fetch_add_fetcher(scheme, fetch_about_initialise, diff --git a/content/fetchers/data.c b/content/fetchers/data.c index fbaa24780..e192812a7 100644 --- a/content/fetchers/data.c +++ b/content/fetchers/data.c @@ -34,6 +34,7 @@ #include "content/fetchers/data.h" #include "content/urldb.h" #include "desktop/netsurf.h" +#include "utils/corestrings.h" #include "utils/nsoption.h" #include "utils/log.h" #include "utils/messages.h" @@ -326,12 +327,7 @@ static void fetch_data_poll(lwc_string *scheme) void fetch_data_register(void) { - lwc_string *scheme; - - if (lwc_intern_string("data", SLEN("data"), &scheme) != lwc_error_ok) { - die("Failed to initialise the fetch module " - "(couldn't intern \"data\")."); - } + lwc_string *scheme = lwc_string_ref(corestring_lwc_data); fetch_add_fetcher(scheme, fetch_data_initialise, diff --git a/content/fetchers/resource.c b/content/fetchers/resource.c index cce816aa5..b2791b432 100644 --- a/content/fetchers/resource.c +++ b/content/fetchers/resource.c @@ -43,6 +43,7 @@ #include "content/urldb.h" #include "desktop/gui.h" #include "desktop/gui_factory.h" +#include "utils/corestrings.h" #include "utils/nsoption.h" #include "utils/log.h" #include "utils/messages.h" @@ -356,13 +357,7 @@ static void fetch_resource_poll(lwc_string *scheme) void fetch_resource_register(void) { - lwc_string *scheme; - - if (lwc_intern_string("resource", SLEN("resource"), - &scheme) != lwc_error_ok) { - die("Failed to initialise the fetch module " - "(couldn't intern \"resource\")."); - } + lwc_string *scheme = lwc_string_ref(corestring_lwc_resource); fetch_add_fetcher(scheme, fetch_resource_initialise, diff --git a/utils/corestrings.c b/utils/corestrings.c index ebe7c9932..1a0c962da 100644 --- a/utils/corestrings.c +++ b/utils/corestrings.c @@ -27,6 +27,7 @@ /* lwc_string strings */ lwc_string *corestring_lwc_a; +lwc_string *corestring_lwc_about; lwc_string *corestring_lwc_abscenter; lwc_string *corestring_lwc_absmiddle; lwc_string *corestring_lwc_align; @@ -42,6 +43,7 @@ lwc_string *corestring_lwc_charset; lwc_string *corestring_lwc_checkbox; lwc_string *corestring_lwc_circle; lwc_string *corestring_lwc_col; +lwc_string *corestring_lwc_data; lwc_string *corestring_lwc_default; lwc_string *corestring_lwc_div; lwc_string *corestring_lwc_embed; @@ -88,6 +90,7 @@ lwc_string *corestring_lwc_rect; lwc_string *corestring_lwc_rectangle; lwc_string *corestring_lwc_refresh; lwc_string *corestring_lwc_reset; +lwc_string *corestring_lwc_resource; lwc_string *corestring_lwc_right; lwc_string *corestring_lwc_search; lwc_string *corestring_lwc_select; @@ -276,6 +279,7 @@ void corestrings_fini(void) } while (0) CSS_LWC_STRING_UNREF(a); + CSS_LWC_STRING_UNREF(about); CSS_LWC_STRING_UNREF(abscenter); CSS_LWC_STRING_UNREF(absmiddle); CSS_LWC_STRING_UNREF(align); @@ -291,6 +295,7 @@ void corestrings_fini(void) CSS_LWC_STRING_UNREF(checkbox); CSS_LWC_STRING_UNREF(circle); CSS_LWC_STRING_UNREF(col); + CSS_LWC_STRING_UNREF(data); CSS_LWC_STRING_UNREF(default); CSS_LWC_STRING_UNREF(div); CSS_LWC_STRING_UNREF(embed); @@ -337,6 +342,7 @@ void corestrings_fini(void) CSS_LWC_STRING_UNREF(rectangle); CSS_LWC_STRING_UNREF(refresh); CSS_LWC_STRING_UNREF(reset); + CSS_LWC_STRING_UNREF(resource); CSS_LWC_STRING_UNREF(right); CSS_LWC_STRING_UNREF(search); CSS_LWC_STRING_UNREF(select); @@ -549,6 +555,7 @@ nserror corestrings_init(void) } while(0) CSS_LWC_STRING_INTERN(a); + CSS_LWC_STRING_INTERN(about); CSS_LWC_STRING_INTERN(abscenter); CSS_LWC_STRING_INTERN(absmiddle); CSS_LWC_STRING_INTERN(align); @@ -564,6 +571,7 @@ nserror corestrings_init(void) CSS_LWC_STRING_INTERN(checkbox); CSS_LWC_STRING_INTERN(circle); CSS_LWC_STRING_INTERN(col); + CSS_LWC_STRING_INTERN(data); CSS_LWC_STRING_INTERN(default); CSS_LWC_STRING_INTERN(div); CSS_LWC_STRING_INTERN(embed); @@ -609,6 +617,7 @@ nserror corestrings_init(void) CSS_LWC_STRING_INTERN(rectangle); CSS_LWC_STRING_INTERN(refresh); CSS_LWC_STRING_INTERN(reset); + CSS_LWC_STRING_INTERN(resource); CSS_LWC_STRING_INTERN(right); CSS_LWC_STRING_INTERN(search); CSS_LWC_STRING_INTERN(select); diff --git a/utils/corestrings.h b/utils/corestrings.h index 5c3349f04..555b916b5 100644 --- a/utils/corestrings.h +++ b/utils/corestrings.h @@ -31,6 +31,7 @@ void corestrings_fini(void); /* lwc_string strings */ extern lwc_string *corestring_lwc_a; +extern lwc_string *corestring_lwc_about; extern lwc_string *corestring_lwc_abscenter; extern lwc_string *corestring_lwc_absmiddle; extern lwc_string *corestring_lwc_align; @@ -46,6 +47,7 @@ extern lwc_string *corestring_lwc_charset; extern lwc_string *corestring_lwc_checkbox; extern lwc_string *corestring_lwc_circle; extern lwc_string *corestring_lwc_col; +extern lwc_string *corestring_lwc_data; extern lwc_string *corestring_lwc_default; extern lwc_string *corestring_lwc_div; extern lwc_string *corestring_lwc_embed; @@ -92,6 +94,7 @@ extern lwc_string *corestring_lwc_rect; extern lwc_string *corestring_lwc_rectangle; extern lwc_string *corestring_lwc_refresh; extern lwc_string *corestring_lwc_reset; +extern lwc_string *corestring_lwc_resource; extern lwc_string *corestring_lwc_right; extern lwc_string *corestring_lwc_search; extern lwc_string *corestring_lwc_select; From 0a6e5fcb6d07abb29aa87d758e873f14850e09f2 Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Fri, 24 Jan 2014 20:14:26 +0000 Subject: [PATCH 127/773] Use corestring. --- css/css.c | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/css/css.c b/css/css.c index 364511875..2b4f60a78 100644 --- a/css/css.c +++ b/css/css.c @@ -28,6 +28,7 @@ #include "css/internal.h" #include "desktop/system_colour.h" #include "render/html.h" +#include "utils/corestrings.h" #include "utils/utils.h" #include "utils/http.h" #include "utils/log.h" @@ -111,7 +112,6 @@ static css_error nscss_register_import(struct content_css_data *c, const hlcache_handle *import); -static lwc_string *css_charset; static css_stylesheet *blank_import; @@ -146,7 +146,7 @@ nserror nscss_create(const content_handler *handler, } /* Find charset specified on HTTP layer, if any */ - error = http_parameter_list_find_item(params, css_charset, + error = http_parameter_list_find_item(params, corestring_lwc_charset, &charset_value); if (error != NSERROR_OK || lwc_string_length(charset_value) == 0) { /* No charset specified, use fallback, if any */ @@ -800,11 +800,6 @@ css_error nscss_register_import(struct content_css_data *c, */ static void nscss_fini(void) { - if (css_charset != NULL) { - lwc_string_unref(css_charset); - css_charset = NULL; - } - if (blank_import != NULL) { css_stylesheet_destroy(blank_import); blank_import = NULL; @@ -828,15 +823,8 @@ static const content_handler css_content_handler = { */ nserror nscss_init(void) { - lwc_error lerror; nserror error; - lerror = lwc_intern_string("charset", SLEN("charset"), &css_charset); - if (lerror != lwc_error_ok) { - error = NSERROR_NOMEM; - goto error; - } - error = content_factory_register_handler("text/css", &css_content_handler); if (error != NSERROR_OK) From 2075ad7ff43a103ea7712ede150ada8234e3780e Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Fri, 24 Jan 2014 20:19:20 +0000 Subject: [PATCH 128/773] Use corestrings. --- content/llcache.c | 34 ++++++---------------------------- 1 file changed, 6 insertions(+), 28 deletions(-) diff --git a/content/llcache.c b/content/llcache.c index f2e519f49..e4baec63e 100644 --- a/content/llcache.c +++ b/content/llcache.c @@ -29,6 +29,7 @@ #include "content/fetch.h" #include "content/llcache.h" #include "content/urldb.h" +#include "utils/corestrings.h" #include "utils/log.h" #include "utils/messages.h" #include "utils/nsurl.h" @@ -162,11 +163,6 @@ struct llcache_s { /** low level cache state */ static struct llcache_s *llcache = NULL; -/* Static lwc_strings */ -static lwc_string *llcache_file_lwc; -static lwc_string *llcache_about_lwc; -static lwc_string *llcache_resource_lwc; - /* forward referenced callback function */ static void llcache_fetch_callback(const fetch_msg *msg, void *p); @@ -1272,16 +1268,16 @@ static nserror llcache_fetch_redirect(llcache_object *object, const char *target scheme = nsurl_get_component(url, NSURL_SCHEME); /* resource: and about: are allowed to redirect anywhere */ - if ((lwc_string_isequal(object_scheme, llcache_resource_lwc, + if ((lwc_string_isequal(object_scheme, corestring_lwc_resource, &match) == lwc_error_ok && match == false) && - (lwc_string_isequal(object_scheme, llcache_about_lwc, + (lwc_string_isequal(object_scheme, corestring_lwc_about, &match) == lwc_error_ok && match == false)) { /* file, about and resource are not valid redirect targets */ - if ((lwc_string_isequal(object_scheme, llcache_file_lwc, + if ((lwc_string_isequal(object_scheme, corestring_lwc_file, &match) == lwc_error_ok && match == true) || - (lwc_string_isequal(object_scheme, llcache_about_lwc, + (lwc_string_isequal(object_scheme, corestring_lwc_about, &match) == lwc_error_ok && match == true) || - (lwc_string_isequal(object_scheme, llcache_resource_lwc, + (lwc_string_isequal(object_scheme, corestring_lwc_resource, &match) == lwc_error_ok && match == true)) { lwc_string_unref(object_scheme); lwc_string_unref(scheme); @@ -2287,19 +2283,6 @@ llcache_initialise(llcache_query_callback cb, void *pw, uint32_t llcache_limit) llcache->query_cb_pw = pw; llcache->limit = llcache_limit; - /* Create static scheme strings */ - if (lwc_intern_string("file", SLEN("file"), - &llcache_file_lwc) != lwc_error_ok) - return NSERROR_NOMEM; - - if (lwc_intern_string("about", SLEN("about"), - &llcache_about_lwc) != lwc_error_ok) - return NSERROR_NOMEM; - - if (lwc_intern_string("resource", SLEN("resource"), - &llcache_resource_lwc) != lwc_error_ok) - return NSERROR_NOMEM; - LOG(("llcache initialised with a limit of %d bytes", llcache_limit)); return NSERROR_OK; @@ -2352,11 +2335,6 @@ void llcache_finalise(void) llcache_object_destroy(object); } - /* Unref static scheme lwc strings */ - lwc_string_unref(llcache_file_lwc); - lwc_string_unref(llcache_about_lwc); - lwc_string_unref(llcache_resource_lwc); - free(llcache); llcache = NULL; } From d64754aca433697a16ba9b1e56f2dc5de3fc0bd4 Mon Sep 17 00:00:00 2001 From: Chris Young Date: Fri, 24 Jan 2014 20:35:31 +0000 Subject: [PATCH 129/773] Ensure the screen actually gets closed before NetSurf quits. --- amiga/gui.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/amiga/gui.c b/amiga/gui.c index 6bad1dbee..a9c72c9e9 100644 --- a/amiga/gui.c +++ b/amiga/gui.c @@ -2787,9 +2787,13 @@ void ami_gui_close_screen(struct Screen *scrn, BOOL locked_screen) if(locked_screen == TRUE) return; /* If this is our own screen, wait for visitor windows to close */ - LOG(("Waiting for visitor windows to close...")); + LOG(("Waiting for visitor windows to close... (signal)")); Wait(scrnsig); - CloseScreen(scrn); + + while (CloseScreen(scrn) == FALSE) { + LOG(("Still waiting for visitor windows to close... (polling)")); + Delay(50); + } } static void gui_quit(void) From dab6d7961ea6fb70aa6021e5dc7a189915b0c10c Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Fri, 24 Jan 2014 21:47:15 +0000 Subject: [PATCH 130/773] Actually use the fact scheme is interned. --- desktop/browser.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/desktop/browser.c b/desktop/browser.c index f66e27576..d94a2872a 100644 --- a/desktop/browser.c +++ b/desktop/browser.c @@ -60,6 +60,7 @@ #include "render/form.h" #include "render/html.h" #include "render/box.h" +#include "utils/corestrings.h" #include "utils/log.h" #include "utils/messages.h" #include "utils/nsurl.h" @@ -1004,6 +1005,7 @@ static void browser_window_update_favicon(hlcache_handle *c, if (link == NULL) { lwc_string *scheme; bool speculative_default = false; + bool match; nsurl = hlcache_handle_get_url(c); @@ -1011,12 +1013,10 @@ static void browser_window_update_favicon(hlcache_handle *c, /* If the document was fetched over http(s), then speculate * that there's a favicon living at /favicon.ico */ - if ((lwc_string_length(scheme) == SLEN("HTTP") && - strcasecmp(lwc_string_data(scheme), - "http") == 0) || - (lwc_string_length(scheme) == SLEN("HTTPS") && - strcasecmp(lwc_string_data(scheme), - "https") == 0)) { + if ((lwc_string_caseless_isequal(scheme, corestring_lwc_http, + &match) == lwc_error_ok && match) || + (lwc_string_caseless_isequal(scheme, corestring_lwc_https, + &match) == lwc_error_ok && match)) { speculative_default = true; } From 5787f8335ea552e9011d989fc5d6473833bc1126 Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Fri, 24 Jan 2014 23:13:18 +0000 Subject: [PATCH 131/773] Simplify and optimise icon handling. --- desktop/browser.c | 54 +++++++++++++-------------------------------- utils/corestrings.c | 12 ++++++++++ utils/corestrings.h | 10 +++++---- 3 files changed, 33 insertions(+), 43 deletions(-) diff --git a/desktop/browser.c b/desktop/browser.c index d94a2872a..a33c1b6eb 100644 --- a/desktop/browser.c +++ b/desktop/browser.c @@ -967,7 +967,6 @@ static nserror browser_window_favicon_callback(hlcache_handle *c, static void browser_window_update_favicon(hlcache_handle *c, struct browser_window *bw, struct content_rfc5988_link *link) { - lwc_string *icon_str; nsurl *nsref = NULL; nsurl *nsurl; nserror error; @@ -986,20 +985,14 @@ static void browser_window_update_favicon(hlcache_handle *c, bw->failed_favicon = false; if (link == NULL) { - /* look for favicon metadata link */ - if (lwc_intern_string("icon", SLEN("icon"), - &icon_str) == lwc_error_ok) { - link = content_find_rfc5988_link(c, icon_str); - lwc_string_unref(icon_str); - } + /* Look for "icon" */ + link = content_find_rfc5988_link(c, corestring_lwc_icon); } if (link == NULL) { - if (lwc_intern_string("shortcut icon", SLEN("shortcut icon"), - &icon_str) == lwc_error_ok) { - link = content_find_rfc5988_link(c, icon_str); - lwc_string_unref(icon_str); - } + /* Look for "shortcut icon" */ + link = content_find_rfc5988_link(c, + corestring_lwc_shortcut_icon); } if (link == NULL) { @@ -1404,34 +1397,17 @@ static nserror browser_window_callback(hlcache_handle *c, case CONTENT_MSG_LINK: /* content has an rfc5988 link element */ { - lwc_string *icon_str; - lwc_string *shortcut_icon_str; - bool icon_match = false; - bool shortcut_icon_match = false; + bool match; - if (lwc_intern_string("icon", SLEN("icon"), - &icon_str) == lwc_error_ok) { - if (lwc_string_caseless_isequal( - event->data.rfc5988_link->rel, - icon_str, - &icon_match) != lwc_error_ok) { - icon_match = false; - } - lwc_string_unref(icon_str); - } - - if (lwc_intern_string("shortcut icon", SLEN("shortcut icon"), - &shortcut_icon_str) == lwc_error_ok) { - if (lwc_string_caseless_isequal( - event->data.rfc5988_link->rel, - shortcut_icon_str, - &shortcut_icon_match) != lwc_error_ok) { - shortcut_icon_match = false; - } - lwc_string_unref(shortcut_icon_str); - } - - if (icon_match || shortcut_icon_match) { + /* Handle "icon" and "shortcut icon" */ + if ((lwc_string_caseless_isequal( + event->data.rfc5988_link->rel, + corestring_lwc_icon, + &match) == lwc_error_ok && match) || + (lwc_string_caseless_isequal( + event->data.rfc5988_link->rel, + corestring_lwc_shortcut_icon, + &match) == lwc_error_ok && match)) { /* it's a favicon perhaps start a fetch for it */ browser_window_update_favicon(c, bw, event->data.rfc5988_link); diff --git a/utils/corestrings.c b/utils/corestrings.c index 1a0c962da..47279c335 100644 --- a/utils/corestrings.c +++ b/utils/corestrings.c @@ -63,6 +63,7 @@ lwc_string *corestring_lwc_hr; lwc_string *corestring_lwc_html; lwc_string *corestring_lwc_http; lwc_string *corestring_lwc_https; +lwc_string *corestring_lwc_icon; lwc_string *corestring_lwc_iframe; lwc_string *corestring_lwc_image; lwc_string *corestring_lwc_img; @@ -94,6 +95,7 @@ lwc_string *corestring_lwc_resource; lwc_string *corestring_lwc_right; lwc_string *corestring_lwc_search; lwc_string *corestring_lwc_select; +lwc_string *corestring_lwc_shortcut_icon; lwc_string *corestring_lwc_src; lwc_string *corestring_lwc_style; lwc_string *corestring_lwc_submit; @@ -315,6 +317,7 @@ void corestrings_fini(void) CSS_LWC_STRING_UNREF(html); CSS_LWC_STRING_UNREF(http); CSS_LWC_STRING_UNREF(https); + CSS_LWC_STRING_UNREF(icon); CSS_LWC_STRING_UNREF(iframe); CSS_LWC_STRING_UNREF(image); CSS_LWC_STRING_UNREF(img); @@ -346,6 +349,7 @@ void corestrings_fini(void) CSS_LWC_STRING_UNREF(right); CSS_LWC_STRING_UNREF(search); CSS_LWC_STRING_UNREF(select); + CSS_LWC_STRING_UNREF(shortcut_icon); CSS_LWC_STRING_UNREF(src); CSS_LWC_STRING_UNREF(style); CSS_LWC_STRING_UNREF(submit); @@ -591,6 +595,7 @@ nserror corestrings_init(void) CSS_LWC_STRING_INTERN(html); CSS_LWC_STRING_INTERN(http); CSS_LWC_STRING_INTERN(https); + CSS_LWC_STRING_INTERN(icon); CSS_LWC_STRING_INTERN(iframe); CSS_LWC_STRING_INTERN(image); CSS_LWC_STRING_INTERN(img); @@ -655,6 +660,13 @@ nserror corestrings_init(void) goto error; } + lerror = lwc_intern_string("shortcut icon", SLEN("shortcut icon"), + &corestring_lwc_shortcut_icon); + if ((lerror != lwc_error_ok) || (corestring_lwc_shortcut_icon == NULL)) { + error = NSERROR_NOMEM; + goto error; + } + lerror = lwc_intern_string("text/css", SLEN("text/css"), &corestring_lwc_text_css); if ((lerror != lwc_error_ok) || (corestring_lwc_text_css == NULL)) { diff --git a/utils/corestrings.h b/utils/corestrings.h index 555b916b5..78fcd1560 100644 --- a/utils/corestrings.h +++ b/utils/corestrings.h @@ -67,6 +67,7 @@ extern lwc_string *corestring_lwc_hr; extern lwc_string *corestring_lwc_html; extern lwc_string *corestring_lwc_http; extern lwc_string *corestring_lwc_https; +extern lwc_string *corestring_lwc_icon; extern lwc_string *corestring_lwc_iframe; extern lwc_string *corestring_lwc_image; extern lwc_string *corestring_lwc_img; @@ -77,7 +78,7 @@ extern lwc_string *corestring_lwc_li; extern lwc_string *corestring_lwc_link; extern lwc_string *corestring_lwc_meta; extern lwc_string *corestring_lwc_middle; -extern lwc_string *corestring_lwc_multipart_form_data; +extern lwc_string *corestring_lwc_multipart_form_data; /* multipart/form-data */ extern lwc_string *corestring_lwc_no; extern lwc_string *corestring_lwc_noscript; extern lwc_string *corestring_lwc_object; @@ -98,6 +99,7 @@ extern lwc_string *corestring_lwc_resource; extern lwc_string *corestring_lwc_right; extern lwc_string *corestring_lwc_search; extern lwc_string *corestring_lwc_select; +extern lwc_string *corestring_lwc_shortcut_icon; /* shortcut icon */ extern lwc_string *corestring_lwc_src; extern lwc_string *corestring_lwc_style; extern lwc_string *corestring_lwc_submit; @@ -107,7 +109,7 @@ extern lwc_string *corestring_lwc_td; extern lwc_string *corestring_lwc_text; extern lwc_string *corestring_lwc_textarea; extern lwc_string *corestring_lwc_texttop; -extern lwc_string *corestring_lwc_text_css; +extern lwc_string *corestring_lwc_text_css; /* text/css */ extern lwc_string *corestring_lwc_tfoot; extern lwc_string *corestring_lwc_th; extern lwc_string *corestring_lwc_thead; @@ -183,7 +185,7 @@ extern struct dom_string *corestring_dom_height; extern struct dom_string *corestring_dom_href; extern struct dom_string *corestring_dom_hreflang; extern struct dom_string *corestring_dom_hspace; -extern struct dom_string *corestring_dom_http_equiv; +extern struct dom_string *corestring_dom_http_equiv; /* http-equiv */ extern struct dom_string *corestring_dom_id; extern struct dom_string *corestring_dom_input; extern struct dom_string *corestring_dom_invalid; @@ -244,7 +246,7 @@ extern struct dom_string *corestring_dom_submit; extern struct dom_string *corestring_dom_suspend; extern struct dom_string *corestring_dom_target; extern struct dom_string *corestring_dom_text; -extern struct dom_string *corestring_dom_text_javascript; +extern struct dom_string *corestring_dom_text_javascript; /* text/javascript */ extern struct dom_string *corestring_dom_timeupdate; extern struct dom_string *corestring_dom_title; extern struct dom_string *corestring_dom_type; From ae6874d3088a46a3d02c64ec7e466baaf03a991f Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Fri, 24 Jan 2014 23:19:46 +0000 Subject: [PATCH 132/773] Just ref a corestring. --- utils/nsurl.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/utils/nsurl.c b/utils/nsurl.c index 61f849e5f..77cbc6d15 100644 --- a/utils/nsurl.c +++ b/utils/nsurl.c @@ -26,6 +26,7 @@ #include #include +#include "utils/corestrings.h" #include "utils/errors.h" #include "utils/log.h" #include "utils/nsurl.h" @@ -819,11 +820,8 @@ static nserror nsurl__create_from_section(const char * const url_s, switch (section) { case URL_SCHEME: if (length == 0) { - /* No scheme, assuming http, and add to URL */ - if (lwc_intern_string("http", SLEN("http"), - &url->scheme) != lwc_error_ok) { - return NSERROR_NOMEM; - } + /* No scheme, assuming http */ + url->scheme = lwc_string_ref(corestring_lwc_http); } else { /* Add scheme to URL */ if (lwc_intern_string(norm_start, length, From 96e5368d34d960dd1aa71dcac81079f331adfab6 Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Sat, 25 Jan 2014 09:53:54 +0000 Subject: [PATCH 133/773] Use corestring. --- desktop/download.c | 12 ++---------- utils/corestrings.c | 3 +++ utils/corestrings.h | 1 + 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/desktop/download.c b/desktop/download.c index 14390c78a..b5427b405 100644 --- a/desktop/download.c +++ b/desktop/download.c @@ -28,6 +28,7 @@ #include "desktop/download.h" #include "desktop/gui.h" #include "desktop/gui_factory.h" +#include "utils/corestrings.h" #include "utils/http.h" #include "utils/url.h" #include "utils/utils.h" @@ -114,26 +115,18 @@ static nserror download_context_process_headers(download_context *ctx) http_header = llcache_handle_get_header(ctx->llcache, "Content-Disposition"); if (http_header != NULL) { - lwc_string *filename; lwc_string *filename_value; http_content_disposition *disposition; - if (lwc_intern_string("filename", SLEN("filename"), - &filename) != lwc_error_ok) { - http_content_type_destroy(content_type); - return NSERROR_NOMEM; - } - error = http_parse_content_disposition(http_header, &disposition); if (error != NSERROR_OK) { - lwc_string_unref(filename); http_content_type_destroy(content_type); return error; } error = http_parameter_list_find_item(disposition->parameters, - filename, &filename_value); + corestring_lwc_filename, &filename_value); if (error == NSERROR_OK) { ctx->filename = download_parse_filename( lwc_string_data(filename_value)); @@ -141,7 +134,6 @@ static nserror download_context_process_headers(download_context *ctx) } http_content_disposition_destroy(disposition); - lwc_string_unref(filename); } ctx->mime_type = lwc_string_ref(content_type->media_type); diff --git a/utils/corestrings.c b/utils/corestrings.c index 47279c335..c51a38fd7 100644 --- a/utils/corestrings.c +++ b/utils/corestrings.c @@ -48,6 +48,7 @@ lwc_string *corestring_lwc_default; lwc_string *corestring_lwc_div; lwc_string *corestring_lwc_embed; lwc_string *corestring_lwc_file; +lwc_string *corestring_lwc_filename; lwc_string *corestring_lwc_font; lwc_string *corestring_lwc_frame; lwc_string *corestring_lwc_frameset; @@ -302,6 +303,7 @@ void corestrings_fini(void) CSS_LWC_STRING_UNREF(div); CSS_LWC_STRING_UNREF(embed); CSS_LWC_STRING_UNREF(file); + CSS_LWC_STRING_UNREF(filename); CSS_LWC_STRING_UNREF(font); CSS_LWC_STRING_UNREF(frame); CSS_LWC_STRING_UNREF(frameset); @@ -580,6 +582,7 @@ nserror corestrings_init(void) CSS_LWC_STRING_INTERN(div); CSS_LWC_STRING_INTERN(embed); CSS_LWC_STRING_INTERN(file); + CSS_LWC_STRING_INTERN(filename); CSS_LWC_STRING_INTERN(font); CSS_LWC_STRING_INTERN(frame); CSS_LWC_STRING_INTERN(frameset); diff --git a/utils/corestrings.h b/utils/corestrings.h index 78fcd1560..1f34ada6a 100644 --- a/utils/corestrings.h +++ b/utils/corestrings.h @@ -52,6 +52,7 @@ extern lwc_string *corestring_lwc_default; extern lwc_string *corestring_lwc_div; extern lwc_string *corestring_lwc_embed; extern lwc_string *corestring_lwc_file; +extern lwc_string *corestring_lwc_filename; extern lwc_string *corestring_lwc_font; extern lwc_string *corestring_lwc_frame; extern lwc_string *corestring_lwc_frameset; From 46b8fbaeac4dd1e35945ae1338056156e5b3b86b Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Sat, 25 Jan 2014 10:00:33 +0000 Subject: [PATCH 134/773] Use corestring. --- render/textplain.c | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/render/textplain.c b/render/textplain.c index 892e03e57..5254e6aba 100644 --- a/render/textplain.c +++ b/render/textplain.c @@ -46,6 +46,7 @@ #include "render/textplain.h" #include "render/html.h" #include "render/search.h" +#include "utils/corestrings.h" #include "utils/http.h" #include "utils/log.h" #include "utils/messages.h" @@ -159,7 +160,6 @@ static const content_handler textplain_content_handler = { .no_share = true, }; -static lwc_string *textplain_charset; static lwc_string *textplain_default_charset; /** @@ -170,16 +170,9 @@ nserror textplain_init(void) lwc_error lerror; nserror error; - lerror = lwc_intern_string("charset", SLEN("charset"), - &textplain_charset); - if (lerror != lwc_error_ok) { - return NSERROR_NOMEM; - } - lerror = lwc_intern_string("Windows-1252", SLEN("Windows-1252"), &textplain_default_charset); if (lerror != lwc_error_ok) { - lwc_string_unref(textplain_charset); return NSERROR_NOMEM; } @@ -187,7 +180,6 @@ nserror textplain_init(void) &textplain_content_handler); if (error != NSERROR_OK) { lwc_string_unref(textplain_default_charset); - lwc_string_unref(textplain_charset); } return error; @@ -202,11 +194,6 @@ void textplain_fini(void) lwc_string_unref(textplain_default_charset); textplain_default_charset = NULL; } - - if (textplain_charset != NULL) { - lwc_string_unref(textplain_charset); - textplain_charset = NULL; - } } /** @@ -233,7 +220,7 @@ nserror textplain_create(const content_handler *handler, return error; } - error = http_parameter_list_find_item(params, textplain_charset, + error = http_parameter_list_find_item(params, corestring_lwc_charset, &encoding); if (error != NSERROR_OK) { encoding = lwc_string_ref(textplain_default_charset); From 8ce0a10670e655d9e3a4f31fedd34baf1a3189b9 Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Sat, 25 Jan 2014 23:00:22 +0000 Subject: [PATCH 135/773] move path_to_url and url_to_path to fetch operation table --- amiga/gui.c | 2 + amiga/misc.h | 4 + atari/findfile.h | 5 +- atari/gui.c | 2 + beos/gui.cpp | 26 ++-- cocoa/BrowserViewController.m | 1 + cocoa/Makefile.target | 1 - cocoa/NetsurfApp.m | 1 - cocoa/fetch.h | 4 +- cocoa/fetch.m | 61 +++++++- cocoa/gui.h | 1 - cocoa/gui.m | 32 ----- content/fetchers/file.c | 4 +- desktop/gui.h | 16 +++ desktop/gui_factory.c | 6 + desktop/searchweb.c | 2 +- framebuffer/fetch.c | 19 ++- gtk/Makefile.target | 2 +- gtk/dialogs/source.c | 17 +-- gtk/{filetype.c => fetch.c} | 199 ++++++++++++++++++++------ gtk/{filetype.h => fetch.h} | 12 +- gtk/gui.c | 120 +--------------- gtk/gui.h | 2 + monkey/Makefile.target | 2 +- monkey/fetch.c | 145 +++++++++++++++++++ cocoa/url.m => monkey/fetch.h | 19 +-- monkey/main.c | 107 +++----------- monkey/utils.c | 44 ------ riscos/gui.c | 261 +++++++++++++++++----------------- utils/url.h | 3 - windows/findfile.h | 3 + windows/gui.c | 2 + 32 files changed, 613 insertions(+), 512 deletions(-) rename gtk/{filetype.c => fetch.c} (59%) rename gtk/{filetype.h => fetch.h} (79%) create mode 100644 monkey/fetch.c rename cocoa/url.m => monkey/fetch.h (60%) diff --git a/amiga/gui.c b/amiga/gui.c index a9c72c9e9..074dfafa6 100644 --- a/amiga/gui.c +++ b/amiga/gui.c @@ -5189,6 +5189,8 @@ static struct gui_fetch_table amiga_fetch_table = { .filename_from_path = filename_from_path, .path_add_part = path_add_part, .filetype = fetch_filetype, + .path_to_url = path_to_url, + .url_to_path = url_to_path, .get_resource_url = gui_get_resource_url, }; diff --git a/amiga/misc.h b/amiga/misc.h index 34a85fa90..60f249c2c 100644 --- a/amiga/misc.h +++ b/amiga/misc.h @@ -18,6 +18,10 @@ #ifndef AMIGA_MISC_H #define AMIGA_MISC_H + char *translate_escape_chars(const char *s); int32 ami_warn_user_multi(const char *body, const char *opt1, const char *opt2, struct Window *win); +char *url_to_path(const char *url); +char *path_to_url(const char *path); + #endif diff --git a/atari/findfile.h b/atari/findfile.h index e87f7cff7..cced0092c 100755 --- a/atari/findfile.h +++ b/atari/findfile.h @@ -21,6 +21,9 @@ #define NS_ATARI_FINDFILE_H extern char *atari_find_resource(char *buf, const char *filename, const char *def); -char * local_file_to_url( const char * filename ); +char *local_file_to_url(const char *filename); + +char *path_to_url(const char *path_in); +char *url_to_path(const char *url); #endif /* NETSURF_ATARI_FINDFILE_H */ diff --git a/atari/gui.c b/atari/gui.c index 0267148d2..f1f557e2e 100644 --- a/atari/gui.c +++ b/atari/gui.c @@ -1077,6 +1077,8 @@ static struct gui_fetch_table atari_fetch_table = { .filename_from_path = filename_from_path, .path_add_part = path_add_part, .filetype = fetch_filetype, + .path_to_url = path_to_url, + .url_to_path = url_to_path, .get_resource_url = gui_get_resource_url, .mimetype = fetch_mimetype, diff --git a/beos/gui.cpp b/beos/gui.cpp index ca176c83f..05e06373c 100644 --- a/beos/gui.cpp +++ b/beos/gui.cpp @@ -786,6 +786,17 @@ static void gui_quit(void) fetch_rsrc_unregister(); } +static char *url_to_path(const char *url) +{ + char *url_path = curl_unescape(url, 0); + char *path; + + /* return the absolute path including leading / */ + path = strdup(url_path + (FILE_SCHEME_PREFIX_LEN - 1)); + curl_free(url_path); + + return path; +} /** * Send the source of a content to a text editor. @@ -983,7 +994,7 @@ utf8_convert_ret utf8_from_local_encoding(const char *string, size_t len, return UTF8_CONVERT_OK; } -char *path_to_url(const char *path) +static char *path_to_url(const char *path) { int urllen = strlen(path) + FILE_SCHEME_PREFIX_LEN + 1; char *url = (char *)malloc(urllen); @@ -1001,17 +1012,6 @@ char *path_to_url(const char *path) return url; } -char *url_to_path(const char *url) -{ - char *url_path = curl_unescape(url, 0); - char *path; - - /* return the absolute path including leading / */ - path = strdup(url_path + (FILE_SCHEME_PREFIX_LEN - 1)); - curl_free(url_path); - - return path; -} static void *myrealloc(void *ptr, size_t len, void *pw) { @@ -1071,6 +1071,8 @@ static struct gui_fetch_table beos_fetch_table = { filename_from_path, path_add_part, fetch_filetype, + path_to_url, + url_to_path, gui_get_resource_url, NULL //fetch_mimetype }; diff --git a/cocoa/BrowserViewController.m b/cocoa/BrowserViewController.m index 77ee57bd1..956654aba 100644 --- a/cocoa/BrowserViewController.m +++ b/cocoa/BrowserViewController.m @@ -19,6 +19,7 @@ #import "cocoa/BrowserViewController.h" #import "cocoa/BrowserView.h" #import "cocoa/BrowserWindowController.h" +#import "cocoa/fetch.h" #import "desktop/browser_private.h" #import "desktop/local_history.h" diff --git a/cocoa/Makefile.target b/cocoa/Makefile.target index 8bd13c29b..49f67f085 100644 --- a/cocoa/Makefile.target +++ b/cocoa/Makefile.target @@ -95,7 +95,6 @@ S_COCOA := \ schedule.m \ selection.m \ thumbnail.m \ - url.m \ utf8.m \ utils.m \ ArrowBox.m \ diff --git a/cocoa/NetsurfApp.m b/cocoa/NetsurfApp.m index 5643efd6c..32ad8f1fb 100644 --- a/cocoa/NetsurfApp.m +++ b/cocoa/NetsurfApp.m @@ -25,7 +25,6 @@ #import "desktop/gui.h" #import "content/urldb.h" -#import "content/fetch.h" #import "css/utils.h" #import "desktop/gui.h" #import "desktop/local_history.h" diff --git a/cocoa/fetch.h b/cocoa/fetch.h index 4a50b6e8d..5d2e9288d 100644 --- a/cocoa/fetch.h +++ b/cocoa/fetch.h @@ -16,4 +16,6 @@ * along with this program. If not, see . */ -const char *fetch_filetype(const char *unix_path); +extern struct gui_fetch_table *cocoa_fetch_table; + +char *url_to_path(const char *url); diff --git a/cocoa/fetch.m b/cocoa/fetch.m index b1c7aea9e..7bf00e0ba 100644 --- a/cocoa/fetch.m +++ b/cocoa/fetch.m @@ -19,7 +19,7 @@ #import #import "utils/log.h" -#import "content/fetch.h" +#import "desktop/gui.h" #import "cocoa/fetch.h" @@ -42,9 +42,9 @@ static const struct mimemap_s { }; -const char *fetch_filetype(const char *unix_path) +static const char *fetch_filetype(const char *unix_path) { - NSString *uti; + NSString *uti; NSString *mimeType = nil; NSError *utiError = nil; @@ -58,7 +58,7 @@ const char *fetch_filetype(const char *unix_path) LOG(("uti call failed")); - strncpy(cocoafiletype, "text/html", sizeof(cocoafiletype)); + strncpy(cocoafiletype, "text/html", sizeof(cocoafiletype)); return cocoafiletype; } @@ -83,13 +83,60 @@ const char *fetch_filetype(const char *unix_path) eidx++; } - strncpy(cocoafiletype, - cocoamimemap[eidx].mimetype, + strncpy(cocoafiletype, + cocoamimemap[eidx].mimetype, sizeof(cocoafiletype)); } } LOG(( "\tMIME type for '%s' is '%s'", unix_path, cocoafiletype )); - + return cocoafiletype; } + +char *url_to_path(const char *url) +{ + NSURL *nsurl = [NSURL URLWithString: [NSString stringWithUTF8String: url]]; + return strdup([[nsurl path] UTF8String]); +} + +static char *path_to_url(const char *path) +{ + return strdup( [[[NSURL fileURLWithPath: [NSString stringWithUTF8String: path]] + absoluteString] UTF8String] ); +} + +static char *filename_from_path(char *path) +{ + return strdup( [[[NSString stringWithUTF8String: path] lastPathComponent] UTF8String] ); +} + +static bool path_add_part(char *path, int length, const char *newpart) +{ + NSString *newPath = [[NSString stringWithUTF8String: path] stringByAppendingPathComponent: [NSString stringWithUTF8String: newpart]]; + + strncpy( path, [newPath UTF8String], length ); + + return true; +} + +static nsurl *gui_get_resource_url(const char *path) +{ + nsurl *url = NULL; + NSString *nspath = [[NSBundle mainBundle] pathForResource: [NSString stringWithUTF8String: path] ofType: @""]; + if (nspath == nil) return NULL; + nsurl_create([[[NSURL fileURLWithPath: nspath] absoluteString] UTF8String], &url); + return url; +} + +static struct gui_fetch_table fetch_table = { + .filename_from_path = filename_from_path, + .path_add_part = path_add_part, + .filetype = fetch_filetype, + .path_to_url = path_to_url, + .url_to_path = url_to_path, + + .get_resource_url = gui_get_resource_url, +}; + +struct gui_fetch_table *cocoa_fetch_table = &fetch_table; diff --git a/cocoa/gui.h b/cocoa/gui.h index 55b69072e..757140030 100644 --- a/cocoa/gui.h +++ b/cocoa/gui.h @@ -20,7 +20,6 @@ extern struct gui_window_table *cocoa_window_table; extern struct gui_clipboard_table *cocoa_clipboard_table; -extern struct gui_fetch_table *cocoa_fetch_table; extern struct gui_browser_table *cocoa_browser_table; extern NSString * const kCookiesFileOption; diff --git a/cocoa/gui.m b/cocoa/gui.m index 2a97df39d..750d9fca4 100644 --- a/cocoa/gui.m +++ b/cocoa/gui.m @@ -46,15 +46,6 @@ NSString * const kAlwaysCloseMultipleTabs = @"AlwaysCloseMultipleTabs"; #define UNIMPL() NSLog( @"Function '%s' unimplemented", __func__ ) -static nsurl *gui_get_resource_url(const char *path) -{ - nsurl *url = NULL; - NSString *nspath = [[NSBundle mainBundle] pathForResource: [NSString stringWithUTF8String: path] ofType: @""]; - if (nspath == nil) return NULL; - nsurl_create([[[NSURL fileURLWithPath: nspath] absoluteString] UTF8String], &url); - return url; -} - static void gui_poll(bool active) { cocoa_autorelease(); @@ -273,20 +264,6 @@ static void gui_cert_verify(nsurl *url, const struct ssl_cert_info *certs, cb( false, cbpw ); } -static char *filename_from_path(char *path) -{ - return strdup( [[[NSString stringWithUTF8String: path] lastPathComponent] UTF8String] ); -} - -static bool path_add_part(char *path, int length, const char *newpart) -{ - NSString *newPath = [[NSString stringWithUTF8String: path] stringByAppendingPathComponent: [NSString stringWithUTF8String: newpart]]; - - strncpy( path, [newPath UTF8String], length ); - - return true; -} - static struct gui_window_table window_table = { .create = gui_window_create, @@ -312,15 +289,6 @@ static struct gui_window_table window_table = { struct gui_window_table *cocoa_window_table = &window_table; -static struct gui_fetch_table fetch_table = { - .filename_from_path = filename_from_path, - .path_add_part = path_add_part, - .filetype = fetch_filetype, - - .get_resource_url = gui_get_resource_url, -}; - -struct gui_fetch_table *cocoa_fetch_table = &fetch_table; static struct gui_browser_table browser_table = { .poll = gui_poll, diff --git a/content/fetchers/file.c b/content/fetchers/file.c index 7b93ab172..00d5cc5f1 100644 --- a/content/fetchers/file.c +++ b/content/fetchers/file.c @@ -142,7 +142,7 @@ fetch_file_setup(struct fetch *fetchh, if (ctx == NULL) return NULL; - ctx->path = url_to_path(nsurl_access(url)); + ctx->path = guit->fetch->url_to_path(nsurl_access(url)); if (ctx->path == NULL) { free(ctx); return NULL; @@ -600,7 +600,7 @@ static void fetch_file_process_dir(struct fetch_file_context *ctx, } } - if((path = path_to_url(urlpath)) == NULL) + if((path = guit->fetch->path_to_url(urlpath)) == NULL) continue; if (S_ISREG(ent_stat.st_mode)) { diff --git a/desktop/gui.h b/desktop/gui.h index 724355d10..da609b1e3 100644 --- a/desktop/gui.h +++ b/desktop/gui.h @@ -319,6 +319,22 @@ struct gui_fetch_table { */ const char *(*filetype)(const char *unix_path); + /** + * Convert a pathname to a file: URL. + * + * \param path pathname + * \return URL, allocated on heap, or NULL on failure + */ + char *(*path_to_url)(const char *path); + + /** + * Convert a file: URL to a pathname. + * + * \param url a file: URL + * \return pathname, allocated on heap, or NULL on failure + */ + char *(*url_to_path)(const char *url); + /* Optional entries */ diff --git a/desktop/gui_factory.c b/desktop/gui_factory.c index 06b5383ba..dfe775571 100644 --- a/desktop/gui_factory.c +++ b/desktop/gui_factory.c @@ -317,6 +317,12 @@ static nserror verify_fetch_register(struct gui_fetch_table *gft) if (gft->filetype == NULL) { return NSERROR_BAD_PARAMETER; } + if (gft->path_to_url == NULL) { + return NSERROR_BAD_PARAMETER; + } + if (gft->url_to_path == NULL) { + return NSERROR_BAD_PARAMETER; + } /* fill in the optional entries with defaults */ diff --git a/desktop/searchweb.c b/desktop/searchweb.c index d42919d2d..b3f6162a6 100644 --- a/desktop/searchweb.c +++ b/desktop/searchweb.c @@ -236,7 +236,7 @@ void search_web_retrieve_ico(bool localdefault) if (localdefault) { if (search_default_ico_location == NULL) return; - url = path_to_url(search_default_ico_location); + url = guit->fetch->path_to_url(search_default_ico_location); } else { url = search_web_ico_name(); } diff --git a/framebuffer/fetch.c b/framebuffer/fetch.c index 2e304c222..0c9b90f7c 100644 --- a/framebuffer/fetch.c +++ b/framebuffer/fetch.c @@ -68,7 +68,13 @@ static bool path_add_part(char *path, int length, const char *newpart) return true; } -char *path_to_url(const char *path) +/** + * Convert a pathname to a file: URL. + * + * \param path pathname + * \return URL, allocated on heap, or NULL on failure + */ +static char *path_to_url(const char *path) { int urllen; char *url; @@ -88,8 +94,13 @@ char *path_to_url(const char *path) return url; } - -char *url_to_path(const char *url) +/** + * Convert a file: URL to a pathname. + * + * \param url a file: URL + * \return pathname, allocated on heap, or NULL on failure + */ +static char *url_to_path(const char *url) { char *path; char *respath; @@ -178,6 +189,8 @@ static struct gui_fetch_table fetch_table = { .filename_from_path = filename_from_path, .path_add_part = path_add_part, .filetype = fetch_filetype, + .path_to_url = path_to_url, + .url_to_path = url_to_path, .get_resource_url = get_resource_url, .mimetype = fetch_mimetype, diff --git a/gtk/Makefile.target b/gtk/Makefile.target index 426c4affd..ec19d1b36 100644 --- a/gtk/Makefile.target +++ b/gtk/Makefile.target @@ -108,7 +108,7 @@ $(eval $(foreach V,$(filter GTK_IMAGE_%,$(.VARIABLES)),$(call convert_image,$($( # S_GTK are sources purely for the GTK build S_GTK := font_pango.c bitmap.c gui.c schedule.c thumbnail.c plotters.c \ treeview.c scaffolding.c gdk.c completion.c login.c throbber.c \ - selection.c history.c window.c filetype.c download.c menu.c \ + selection.c history.c window.c fetch.c download.c menu.c \ print.c search.c tabs.c theme.c toolbar.c gettext.c \ compat.c cookies.c hotlist.c \ $(addprefix dialogs/,preferences.c about.c source.c) diff --git a/gtk/dialogs/source.c b/gtk/dialogs/source.c index 5306bdc16..a7c98152e 100644 --- a/gtk/dialogs/source.c +++ b/gtk/dialogs/source.c @@ -23,13 +23,6 @@ #include #include -#include "gtk/compat.h" -#include "gtk/dialogs/source.h" -#include "gtk/dialogs/about.h" -#include "gtk/window.h" -#include "gtk/gui.h" -#include "gtk/print.h" -#include "gtk/selection.h" #include "desktop/browser_private.h" #include "desktop/netsurf.h" #include "desktop/print.h" @@ -42,9 +35,17 @@ #include "render/font.h" #include "content/content.h" #include "content/content_type.h" - #include "utils/log.h" +#include "gtk/compat.h" +#include "gtk/dialogs/source.h" +#include "gtk/dialogs/about.h" +#include "gtk/window.h" +#include "gtk/gui.h" +#include "gtk/print.h" +#include "gtk/selection.h" +#include "gtk/fetch.h" + struct nsgtk_source_window { gchar *url; char *data; diff --git a/gtk/filetype.c b/gtk/fetch.c similarity index 59% rename from gtk/filetype.c rename to gtk/fetch.c index a949b14d5..f4a42b5f8 100644 --- a/gtk/filetype.c +++ b/gtk/fetch.c @@ -1,6 +1,5 @@ /* - * Copyright 2007 Rob Kendrick - * Copyright 2007 Vincent Sanders + * Copyright 2014 vincent Sanders * * This file is part of NetSurf, http://www.netsurf-browser.org/ * @@ -18,18 +17,18 @@ */ #include -#include -#include -#include -#include #include #include #include -#include "gtk/filetype.h" -#include "content/fetch.h" -#include "utils/log.h" #include "utils/hashtable.h" +#include "utils/url.h" +#include "utils/log.h" +#include "utils/filepath.h" +#include "desktop/gui.h" + +#include "gtk/gui.h" +#include "gtk/fetch.h" static struct hash_table *mime_hash = NULL; @@ -43,9 +42,8 @@ void gtk_fetch_filetype_init(const char *mimefile) /* first, check to see if /etc/mime.types in preference */ if ((stat("/etc/mime.types", &statbuf) == 0) && - S_ISREG(statbuf.st_mode)) { + S_ISREG(statbuf.st_mode)) { mimefile = "/etc/mime.types"; - } fh = fopen(mimefile, "r"); @@ -75,25 +73,30 @@ void gtk_fetch_filetype_init(const char *mimefile) while (!feof(fh)) { char line[256], *ptr, *type, *ext; + if (fgets(line, 256, fh) == NULL) - break; + break; + if (!feof(fh) && line[0] != '#') { ptr = line; /* search for the first non-whitespace character */ - while (isspace(*ptr)) + while (isspace(*ptr)) { ptr++; + } /* is this line empty other than leading whitespace? */ - if (*ptr == '\n' || *ptr == '\0') + if (*ptr == '\n' || *ptr == '\0') { continue; + } type = ptr; /* search for the first non-whitespace char or NUL or * NL */ - while (*ptr && (!isspace(*ptr)) && *ptr != '\n') + while (*ptr && (!isspace(*ptr)) && *ptr != '\n') { ptr++; + } if (*ptr == '\0' || *ptr == '\n') { /* this mimetype has no extensions - read next @@ -106,8 +109,9 @@ void gtk_fetch_filetype_init(const char *mimefile) /* search for the first non-whitespace character which * will be the first filename extenion */ - while (isspace(*ptr)) + while (isspace(*ptr)) { ptr++; + } while(true) { ext = ptr; @@ -115,9 +119,11 @@ void gtk_fetch_filetype_init(const char *mimefile) /* search for the first whitespace char or * NUL or NL which is the end of the ext. */ - while (*ptr && (!isspace(*ptr)) && - *ptr != '\n') + while (*ptr && + (!isspace(*ptr)) && + *ptr != '\n') { ptr++; + } if (*ptr == '\0' || *ptr == '\n') { /* special case for last extension on @@ -134,8 +140,11 @@ void gtk_fetch_filetype_init(const char *mimefile) /* search for the first non-whitespace char or * NUL or NL, to find start of next ext. */ - while (*ptr && (isspace(*ptr)) && *ptr != '\n') + while (*ptr && + (isspace(*ptr)) && + *ptr != '\n') { ptr++; + } } } } @@ -162,8 +171,9 @@ const char *fetch_filetype(const char *unix_path) return "text/plain"; } - if (S_ISDIR(statbuf.st_mode)) + if (S_ISDIR(statbuf.st_mode)) { return "application/x-netsurf-directory"; + } l = strlen(unix_path); @@ -184,11 +194,13 @@ const char *fetch_filetype(const char *unix_path) } ptr = unix_path + strlen(unix_path); - while (*ptr != '.' && *ptr != '/') + while (*ptr != '.' && *ptr != '/') { ptr--; + } - if (*ptr != '.') + if (*ptr != '.') { return "text/plain"; + } ext = strdup(ptr + 1); /* skip the . */ @@ -196,7 +208,7 @@ const char *fetch_filetype(const char *unix_path) * copy is lower case too. */ lowerchar = ext; - while(*lowerchar) { + while (*lowerchar) { *lowerchar = tolower(*lowerchar); lowerchar++; } @@ -204,31 +216,132 @@ const char *fetch_filetype(const char *unix_path) type = hash_get(mime_hash, ext); free(ext); - return type != NULL ? type : "text/plain"; + if (type == NULL) { + type = "text/plain"; + } + + return type; } -#ifdef TEST_RIG - -int main(int argc, char *argv[]) +/** + * Return the filename part of a full path + * + * \param path full path and filename + * \return filename (will be freed with free()) + */ +static char *filename_from_path(char *path) { - unsigned int c1, *c2; - const char *key; + char *leafname; - gtk_fetch_filetype_init("./mime.types"); - - c1 = 0; c2 = 0; - - while ( (key = hash_iterate(mime_hash, &c1, &c2)) != NULL) { - printf("%s ", key); + leafname = strrchr(path, '/'); + if (!leafname) { + leafname = path; + } else { + leafname += 1; } - printf("\n"); - - if (argc > 1) { - printf("%s maps to %s\n", argv[1], fetch_filetype(argv[1])); - } - - gtk_fetch_filetype_fin(); + return strdup(leafname); } -#endif +/** + * Add a path component/filename to an existing path + * + * \param path buffer containing path + free space + * \param length length of buffer "path" + * \param newpart string containing path component to add to path + * \return true on success + */ +static bool path_add_part(char *path, int length, const char *newpart) +{ + if (path[strlen(path) - 1] != '/') { + strncat(path, "/", length); + } + + strncat(path, newpart, length); + + return true; +} + +char *path_to_url(const char *path) +{ + int urllen; + char *url; + + if (path == NULL) { + return NULL; + } + + urllen = strlen(path) + FILE_SCHEME_PREFIX_LEN + 1; + + url = malloc(urllen); + if (url == NULL) { + return NULL; + } + + if (*path == '/') { + path++; /* file: paths are already absolute */ + } + + snprintf(url, urllen, "%s%s", FILE_SCHEME_PREFIX, path); + + return url; +} + + +static char *url_to_path(const char *url) +{ + char *path; + char *respath; + url_func_result res; /* result from url routines */ + + res = url_path(url, &path); + if (res != URL_FUNC_OK) { + return NULL; + } + + res = url_unescape(path, &respath); + free(path); + if (res != URL_FUNC_OK) { + return NULL; + } + + return respath; +} + +static nsurl *gui_get_resource_url(const char *path) +{ + char buf[PATH_MAX]; + char *raw; + nsurl *url = NULL; + + /* default.css -> gtkdefault.css */ + if (strcmp(path, "default.css") == 0) { + path = "gtkdefault.css"; + } + + /* favicon.ico -> favicon.png */ + if (strcmp(path, "favicon.ico") == 0) { + path = "favicon.png"; + } + + raw = path_to_url(filepath_sfind(respaths, buf, path)); + if (raw != NULL) { + nsurl_create(raw, &url); + free(raw); + } + + return url; +} + +static struct gui_fetch_table fetch_table = { + .filename_from_path = filename_from_path, + .path_add_part = path_add_part, + .filetype = fetch_filetype, + .path_to_url = path_to_url, + .url_to_path = url_to_path, + + .get_resource_url = gui_get_resource_url, + +}; + +struct gui_fetch_table *nsgtk_fetch_table = &fetch_table; diff --git a/gtk/filetype.h b/gtk/fetch.h similarity index 79% rename from gtk/filetype.h rename to gtk/fetch.h index 68bb9c0ff..400a06a35 100644 --- a/gtk/filetype.h +++ b/gtk/fetch.h @@ -1,6 +1,5 @@ /* - * Copyright 2007 Rob Kendrick - * Copyright 2007 Vincent Sanders + * Copyright 2014 Vincent Sanders * * This file is part of NetSurf, http://www.netsurf-browser.org/ * @@ -17,6 +16,15 @@ * along with this program. If not, see . */ +#ifndef NETSURF_GTK_FETCH_H +#define NETSURF_GTK_FETCH_H + +struct gui_fetch_table *nsgtk_fetch_table; + void gtk_fetch_filetype_init(const char *mimefile); void gtk_fetch_filetype_fin(void); const char *fetch_filetype(const char *unix_path); + +char *path_to_url(const char *path); + +#endif diff --git a/gtk/gui.c b/gtk/gui.c index d6d35029d..ad80e8941 100644 --- a/gtk/gui.c +++ b/gtk/gui.c @@ -60,7 +60,7 @@ #include "gtk/completion.h" #include "gtk/cookies.h" #include "gtk/download.h" -#include "gtk/filetype.h" +#include "gtk/fetch.h" #include "gtk/gui.h" #include "gtk/history.h" #include "gtk/hotlist.h" @@ -109,7 +109,7 @@ static void nsgtk_PDF_no_pass(GtkButton *w, gpointer data); #define THROBBER_FRAMES 9 -static char **respaths; /** resource search path vector */ +char **respaths; /** resource search path vector */ /** Create an array of valid paths to search for resources. * @@ -324,28 +324,6 @@ static void check_options(char **respath) } -static nsurl *gui_get_resource_url(const char *path) -{ - char buf[PATH_MAX]; - char *raw; - nsurl *url = NULL; - - /* default.css -> gtkdefault.css */ - if (strcmp(path, "default.css") == 0) - path = "gtkdefault.css"; - - /* favicon.ico -> favicon.png */ - if (strcmp(path, "favicon.ico") == 0) - path = "favicon.png"; - - raw = path_to_url(filepath_sfind(respaths, buf, path)); - if (raw != NULL) { - nsurl_create(raw, &url); - free(raw); - } - - return url; -} /** @@ -842,51 +820,6 @@ utf8_convert_ret utf8_from_local_encoding(const char *string, size_t len, } -char *path_to_url(const char *path) -{ - int urllen; - char *url; - - if (path == NULL) { - return NULL; - } - - urllen = strlen(path) + FILE_SCHEME_PREFIX_LEN + 1; - - url = malloc(urllen); - if (url == NULL) { - return NULL; - } - - if (*path == '/') { - path++; /* file: paths are already absolute */ - } - - snprintf(url, urllen, "%s%s", FILE_SCHEME_PREFIX, path); - - return url; -} - - -char *url_to_path(const char *url) -{ - char *path; - char *respath; - url_func_result res; /* result from url routines */ - - res = url_path(url, &path); - if (res != URL_FUNC_OK) { - return NULL; - } - - res = url_unescape(path, &respath); - free(path); - if (res != URL_FUNC_OK) { - return NULL; - } - - return respath; -} #ifdef WITH_PDF_EXPORT @@ -1089,59 +1022,12 @@ uint32_t gtk_gui_gdkkey_to_nskey(GdkEventKey *key) } } -/** - * Return the filename part of a full path - * - * \param path full path and filename - * \return filename (will be freed with free()) - */ - -static char *filename_from_path(char *path) -{ - char *leafname; - - leafname = strrchr(path, '/'); - if (!leafname) - leafname = path; - else - leafname += 1; - - return strdup(leafname); -} - -/** - * Add a path component/filename to an existing path - * - * \param path buffer containing path + free space - * \param length length of buffer "path" - * \param newpart string containing path component to add to path - * \return true on success - */ - -static bool path_add_part(char *path, int length, const char *newpart) -{ - if(path[strlen(path) - 1] != '/') - strncat(path, "/", length); - - strncat(path, newpart, length); - - return true; -} static struct gui_clipboard_table nsgtk_clipboard_table = { .get = gui_get_clipboard, .set = gui_set_clipboard, }; -static struct gui_fetch_table nsgtk_fetch_table = { - .filename_from_path = filename_from_path, - .path_add_part = path_add_part, - .filetype = fetch_filetype, - - .get_resource_url = gui_get_resource_url, - -}; - static struct gui_browser_table nsgtk_browser_table = { .poll = gui_poll, @@ -1166,7 +1052,7 @@ int main(int argc, char** argv) .window = nsgtk_window_table, .clipboard = &nsgtk_clipboard_table, .download = nsgtk_download_table, - .fetch = &nsgtk_fetch_table, + .fetch = nsgtk_fetch_table, }; /* check home directory is available */ diff --git a/gtk/gui.h b/gtk/gui.h index 65a6e0742..dc1f2b340 100644 --- a/gtk/gui.h +++ b/gtk/gui.h @@ -59,6 +59,8 @@ extern char *themelist_file_location; extern GdkPixbuf *favicon_pixbuf; /* favicon default pixbuf */ +extern char **respaths; /** resource search path vector */ + uint32_t gtk_gui_gdkkey_to_nskey(GdkEventKey *); extern void gui_401login_open(nsurl *url, const char *realm, diff --git a/monkey/Makefile.target b/monkey/Makefile.target index 52407542d..7c0f167d3 100644 --- a/monkey/Makefile.target +++ b/monkey/Makefile.target @@ -68,7 +68,7 @@ endif # S_MONKEY are sources purely for the MONKEY build S_MONKEY := main.c utils.c filetype.c schedule.c \ bitmap.c plot.c browser.c download.c thumbnail.c \ - 401login.c cert.c font.c poll.c dispatch.c + 401login.c cert.c font.c poll.c dispatch.c fetch.c S_MONKEY := $(addprefix monkey/,$(S_MONKEY)) diff --git a/monkey/fetch.c b/monkey/fetch.c new file mode 100644 index 000000000..668ad0e64 --- /dev/null +++ b/monkey/fetch.c @@ -0,0 +1,145 @@ +/* + * Copyright 2014 Vincent Sanders + * + * This file is part of NetSurf, http://www.netsurf-browser.org/ + * + * NetSurf is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * NetSurf is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include +#include +#include +#include + +#include "desktop/gui.h" +#include "utils/url.h" +#include "utils/nsurl.h" +#include "utils/filepath.h" + +#include "monkey/filetype.h" +#include "monkey/fetch.h" + +extern char **respaths; + + +static char *path_to_url(const char *path) +{ + int urllen; + char *url; + + if (path == NULL) { + return NULL; + } + + urllen = strlen(path) + FILE_SCHEME_PREFIX_LEN + 1; + + url = malloc(urllen); + if (url == NULL) { + return NULL; + } + + if (*path == '/') { + path++; /* file: paths are already absolute */ + } + + snprintf(url, urllen, "%s%s", FILE_SCHEME_PREFIX, path); + + return url; +} + +static char *url_to_path(const char *url) +{ + char *path; + char *respath; + url_func_result res; /* result from url routines */ + + res = url_path(url, &path); + if (res != URL_FUNC_OK) { + return NULL; + } + + res = url_unescape(path, &respath); + free(path); + if (res != URL_FUNC_OK) { + return NULL; + } + + return respath; +} + +/** + * Return the filename part of a full path + * + * \param path full path and filename + * \return filename (will be freed with free()) + */ + +static char *filename_from_path(char *path) +{ + char *leafname; + + leafname = strrchr(path, '/'); + if (!leafname) + leafname = path; + else + leafname += 1; + + return strdup(leafname); +} + +/** + * Add a path component/filename to an existing path + * + * \param path buffer containing path + free space + * \param length length of buffer "path" + * \param newpart string containing path component to add to path + * \return true on success + */ + +static bool path_add_part(char *path, int length, const char *newpart) +{ + if(path[strlen(path) - 1] != '/') + strncat(path, "/", length); + + strncat(path, newpart, length); + + return true; +} + +static nsurl *gui_get_resource_url(const char *path) +{ + char buf[PATH_MAX]; + char *raw; + nsurl *url = NULL; + + raw = path_to_url(filepath_sfind(respaths, buf, path)); + if (raw != NULL) { + nsurl_create(raw, &url); + free(raw); + } + + return url; +} + +static struct gui_fetch_table fetch_table = { + .filename_from_path = filename_from_path, + .path_add_part = path_add_part, + .filetype = monkey_fetch_filetype, + .path_to_url = path_to_url, + .url_to_path = url_to_path, + + .get_resource_url = gui_get_resource_url, +}; + +struct gui_fetch_table *monkey_fetch_table = &fetch_table; diff --git a/cocoa/url.m b/monkey/fetch.h similarity index 60% rename from cocoa/url.m rename to monkey/fetch.h index 931f459a3..59e8696d1 100644 --- a/cocoa/url.m +++ b/monkey/fetch.h @@ -1,5 +1,5 @@ /* - * Copyright 2011 Sven Weidauer + * Copyright 2014 Vincent Sanders * * This file is part of NetSurf, http://www.netsurf-browser.org/ * @@ -16,19 +16,4 @@ * along with this program. If not, see . */ -#import - -#import "utils/url.h" - - -char *url_to_path(const char *url) -{ - NSURL *nsurl = [NSURL URLWithString: [NSString stringWithUTF8String: url]]; - return strdup([[nsurl path] UTF8String]); -} - -char *path_to_url(const char *path) -{ - return strdup( [[[NSURL fileURLWithPath: [NSString stringWithUTF8String: path]] - absoluteString] UTF8String] ); -} +struct gui_fetch_table *monkey_fetch_table; diff --git a/monkey/main.c b/monkey/main.c index 1135f0e53..07ce7eeeb 100644 --- a/monkey/main.c +++ b/monkey/main.c @@ -20,13 +20,14 @@ #include #include -#include "monkey/filetype.h" #include "utils/nsoption.h" #include "monkey/poll.h" #include "monkey/dispatch.h" #include "monkey/browser.h" #include "monkey/cert.h" #include "monkey/401login.h" +#include "monkey/filetype.h" +#include "monkey/fetch.h" #include "content/urldb.h" #include "content/fetchers/resource.h" @@ -36,49 +37,34 @@ #include "utils/filepath.h" #include "utils/url.h" -static char **respaths; /** resource search path vector */ +char **respaths; /** resource search path vector */ /* Stolen from gtk/gui.c */ static char ** nsmonkey_init_resource(const char *resource_path) { - const gchar * const *langv; - char **pathv; /* resource path string vector */ - char **respath; /* resource paths vector */ + const gchar * const *langv; + char **pathv; /* resource path string vector */ + char **respath; /* resource paths vector */ - pathv = filepath_path_to_strvec(resource_path); + pathv = filepath_path_to_strvec(resource_path); - langv = g_get_language_names(); + langv = g_get_language_names(); - respath = filepath_generate(pathv, langv); + respath = filepath_generate(pathv, langv); - filepath_free_strvec(pathv); + filepath_free_strvec(pathv); - return respath; + return respath; } static void monkey_quit(void) { - urldb_save_cookies(nsoption_charp(cookie_jar)); - urldb_save(nsoption_charp(url_file)); - free(nsoption_charp(cookie_file)); - free(nsoption_charp(cookie_jar)); - monkey_fetch_filetype_fin(); -} - -static nsurl *gui_get_resource_url(const char *path) -{ - char buf[PATH_MAX]; - char *raw; - nsurl *url = NULL; - - raw = path_to_url(filepath_sfind(respaths, buf, path)); - if (raw != NULL) { - nsurl_create(raw, &url); - free(raw); - } - - return url; + urldb_save_cookies(nsoption_charp(cookie_jar)); + urldb_save(nsoption_charp(url_file)); + free(nsoption_charp(cookie_file)); + free(nsoption_charp(cookie_jar)); + monkey_fetch_filetype_fin(); } static void @@ -115,53 +101,6 @@ static bool nslog_stream_configure(FILE *fptr) return true; } -/** - * Return the filename part of a full path - * - * \param path full path and filename - * \return filename (will be freed with free()) - */ - -static char *filename_from_path(char *path) -{ - char *leafname; - - leafname = strrchr(path, '/'); - if (!leafname) - leafname = path; - else - leafname += 1; - - return strdup(leafname); -} - -/** - * Add a path component/filename to an existing path - * - * \param path buffer containing path + free space - * \param length length of buffer "path" - * \param newpart string containing path component to add to path - * \return true on success - */ - -static bool path_add_part(char *path, int length, const char *newpart) -{ - if(path[strlen(path) - 1] != '/') - strncat(path, "/", length); - - strncat(path, newpart, length); - - return true; -} - -static struct gui_fetch_table monkey_fetch_table = { - .filename_from_path = filename_from_path, - .path_add_part = path_add_part, - .filetype = monkey_fetch_filetype, - - .get_resource_url = gui_get_resource_url, -}; - static struct gui_browser_table monkey_browser_table = { .poll = monkey_poll, @@ -182,14 +121,14 @@ main(int argc, char **argv) .browser = &monkey_browser_table, .window = monkey_window_table, .download = monkey_download_table, - .fetch = &monkey_fetch_table, + .fetch = monkey_fetch_table, }; /* Unbuffer stdin/out/err */ setbuf(stdin, NULL); setbuf(stdout, NULL); setbuf(stderr, NULL); - + /* Prep the search paths */ respaths = nsmonkey_init_resource("${HOME}/.netsurf/:${NETSURFRES}:"MONKEY_RESPATH":./monkey/res"); @@ -215,22 +154,22 @@ main(int argc, char **argv) if (ret != NSERROR_OK) { die("NetSurf failed to initialise"); } - + filepath_sfinddef(respaths, buf, "mime.types", "/etc/"); monkey_fetch_filetype_init(buf); - + urldb_load(nsoption_charp(url_file)); urldb_load_cookies(nsoption_charp(cookie_file)); - + monkey_prepare_input(); monkey_register_handler("QUIT", quit_handler); monkey_register_handler("WINDOW", monkey_window_handle_command); - + fprintf(stdout, "GENERIC STARTED\n"); netsurf_main_loop(); fprintf(stdout, "GENERIC CLOSING_DOWN\n"); monkey_kill_browser_windows(); - + netsurf_exit(); fprintf(stdout, "GENERIC FINISHED\n"); diff --git a/monkey/utils.c b/monkey/utils.c index aa7245533..88776a90f 100644 --- a/monkey/utils.c +++ b/monkey/utils.c @@ -25,50 +25,6 @@ #include "utils/url.h" #include "utils/utf8.h" -char *path_to_url(const char *path) -{ - int urllen; - char *url; - - if (path == NULL) { - return NULL; - } - - urllen = strlen(path) + FILE_SCHEME_PREFIX_LEN + 1; - - url = malloc(urllen); - if (url == NULL) { - return NULL; - } - - if (*path == '/') { - path++; /* file: paths are already absolute */ - } - - snprintf(url, urllen, "%s%s", FILE_SCHEME_PREFIX, path); - - return url; -} - -char *url_to_path(const char *url) -{ - char *path; - char *respath; - url_func_result res; /* result from url routines */ - - res = url_path(url, &path); - if (res != URL_FUNC_OK) { - return NULL; - } - - res = url_unescape(path, &respath); - free(path); - if (res != URL_FUNC_OK) { - return NULL; - } - - return respath; -} void warn_user(const char *warning, const char *detail) diff --git a/riscos/gui.c b/riscos/gui.c index 8495dd6aa..43e2f3a4e 100644 --- a/riscos/gui.c +++ b/riscos/gui.c @@ -719,6 +719,135 @@ void ro_gui_check_resolvers(void) } } +/** + * Convert a RISC OS pathname to a file: URL. + * + * \param path RISC OS pathname + * \return URL, allocated on heap, or 0 on failure + */ + +static char *path_to_url(const char *path) +{ + int spare; + char *canonical_path; /* canonicalised RISC OS path */ + char *unix_path; /* unix path */ + char *escurl; + os_error *error; + url_func_result url_err; + int urllen; + char *url; /* resulting url */ + + /* calculate the canonical risc os path */ + error = xosfscontrol_canonicalise_path(path, 0, 0, 0, 0, &spare); + if (error) { + LOG(("xosfscontrol_canonicalise_path failed: 0x%x: %s", + error->errnum, error->errmess)); + warn_user("PathToURL", error->errmess); + return NULL; + } + + canonical_path = malloc(1 - spare); + if (canonical_path == NULL) { + LOG(("malloc failed")); + warn_user("NoMemory", 0); + free(canonical_path); + return NULL; + } + + error = xosfscontrol_canonicalise_path(path, canonical_path, 0, 0, 1 - spare, 0); + if (error) { + LOG(("xosfscontrol_canonicalise_path failed: 0x%x: %s", + error->errnum, error->errmess)); + warn_user("PathToURL", error->errmess); + free(canonical_path); + return NULL; + } + + /* create a unix path from teh cananocal risc os one */ + unix_path = __unixify(canonical_path, __RISCOSIFY_NO_REVERSE_SUFFIX, NULL, 0, 0); + + if (unix_path == NULL) { + LOG(("__unixify failed: %s", canonical_path)); + free(canonical_path); + return NULL; + } + free(canonical_path); + + /* convert the unix path into a url */ + urllen = strlen(unix_path) + FILE_SCHEME_PREFIX_LEN + 1; + url = malloc(urllen); + if (url == NULL) { + LOG(("Unable to allocate url")); + free(unix_path); + return NULL; + } + + if (*unix_path == '/') { + snprintf(url, urllen, "%s%s", FILE_SCHEME_PREFIX, unix_path + 1); + } else { + snprintf(url, urllen, "%s%s", FILE_SCHEME_PREFIX, unix_path); + } + free(unix_path); + + /* We don't want '/' to be escaped. */ + url_err = url_escape(url, FILE_SCHEME_PREFIX_LEN, false, "/", &escurl); + free(url); url = NULL; + if (url_err != URL_FUNC_OK) { + LOG(("url_escape failed: %s", url)); + return NULL; + } + + return escurl; +} + + +/** + * Convert a file: URL to a RISC OS pathname. + * + * \param url a file: URL + * \return RISC OS pathname, allocated on heap, or 0 on failure + */ + +static char *url_to_path(const char *url) +{ + char *path; + char *filename; + char *respath; + url_func_result res; /* result from url routines */ + char *r; + + res = url_path(url, &path); + if (res != URL_FUNC_OK) { + warn_user("NoMemory", 0); + return NULL; + } + + res = url_unescape(path, &respath); + free(path); + if (res != URL_FUNC_OK) { + return NULL; + } + + /* RISC OS path should not be more than 100 characters longer */ + filename = malloc(strlen(respath) + 100); + if (!filename) { + free(respath); + warn_user("NoMemory", 0); + return NULL; + } + + r = __riscosify(respath, 0, __RISCOSIFY_NO_SUFFIX, + filename, strlen(respath) + 100, 0); + + free(respath); + if (r == 0) { + free(filename); + LOG(("__riscosify failed")); + return NULL; + } + + return filename; +} /** * Last-minute gui init, after all other modules have initialised. @@ -838,7 +967,6 @@ static bool nslog_stream_configure(FILE *fptr) } - /** * Close down the gui (RISC OS). */ @@ -1873,135 +2001,6 @@ void ro_msg_window_info(wimp_message *message) } -/** - * Convert a RISC OS pathname to a file: URL. - * - * \param path RISC OS pathname - * \return URL, allocated on heap, or 0 on failure - */ - -char *path_to_url(const char *path) -{ - int spare; - char *canonical_path; /* canonicalised RISC OS path */ - char *unix_path; /* unix path */ - char *escurl; - os_error *error; - url_func_result url_err; - int urllen; - char *url; /* resulting url */ - - /* calculate the canonical risc os path */ - error = xosfscontrol_canonicalise_path(path, 0, 0, 0, 0, &spare); - if (error) { - LOG(("xosfscontrol_canonicalise_path failed: 0x%x: %s", - error->errnum, error->errmess)); - warn_user("PathToURL", error->errmess); - return NULL; - } - - canonical_path = malloc(1 - spare); - if (canonical_path == NULL) { - LOG(("malloc failed")); - warn_user("NoMemory", 0); - free(canonical_path); - return NULL; - } - - error = xosfscontrol_canonicalise_path(path, canonical_path, 0, 0, 1 - spare, 0); - if (error) { - LOG(("xosfscontrol_canonicalise_path failed: 0x%x: %s", - error->errnum, error->errmess)); - warn_user("PathToURL", error->errmess); - free(canonical_path); - return NULL; - } - - /* create a unix path from teh cananocal risc os one */ - unix_path = __unixify(canonical_path, __RISCOSIFY_NO_REVERSE_SUFFIX, NULL, 0, 0); - - if (unix_path == NULL) { - LOG(("__unixify failed: %s", canonical_path)); - free(canonical_path); - return NULL; - } - free(canonical_path); - - /* convert the unix path into a url */ - urllen = strlen(unix_path) + FILE_SCHEME_PREFIX_LEN + 1; - url = malloc(urllen); - if (url == NULL) { - LOG(("Unable to allocate url")); - free(unix_path); - return NULL; - } - - if (*unix_path == '/') { - snprintf(url, urllen, "%s%s", FILE_SCHEME_PREFIX, unix_path + 1); - } else { - snprintf(url, urllen, "%s%s", FILE_SCHEME_PREFIX, unix_path); - } - free(unix_path); - - /* We don't want '/' to be escaped. */ - url_err = url_escape(url, FILE_SCHEME_PREFIX_LEN, false, "/", &escurl); - free(url); url = NULL; - if (url_err != URL_FUNC_OK) { - LOG(("url_escape failed: %s", url)); - return NULL; - } - - return escurl; -} - - -/** - * Convert a file: URL to a RISC OS pathname. - * - * \param url a file: URL - * \return RISC OS pathname, allocated on heap, or 0 on failure - */ - -char *url_to_path(const char *url) -{ - char *path; - char *filename; - char *respath; - url_func_result res; /* result from url routines */ - char *r; - - res = url_path(url, &path); - if (res != URL_FUNC_OK) { - warn_user("NoMemory", 0); - return NULL; - } - - res = url_unescape(path, &respath); - free(path); - if (res != URL_FUNC_OK) { - return NULL; - } - - /* RISC OS path should not be more than 100 characters longer */ - filename = malloc(strlen(respath) + 100); - if (!filename) { - free(respath); - warn_user("NoMemory", 0); - return NULL; - } - - r = __riscosify(respath, 0, __RISCOSIFY_NO_SUFFIX, - filename, strlen(respath) + 100, 0); - - free(respath); - if (r == 0) { - free(filename); - LOG(("__riscosify failed")); - return NULL; - } - - return filename; -} /** @@ -2357,6 +2356,8 @@ static struct gui_fetch_table riscos_fetch_table = { .filename_from_path = filename_from_path, .path_add_part = path_add_part, .filetype = fetch_filetype, + .path_to_url = path_to_url, + .url_to_path = url_to_path, .get_resource_url = gui_get_resource_url, .mimetype = fetch_mimetype, diff --git a/utils/url.h b/utils/url.h index 7c716d723..621e62f0d 100644 --- a/utils/url.h +++ b/utils/url.h @@ -58,7 +58,4 @@ url_func_result url_escape(const char *unescaped, size_t toskip, url_func_result url_unescape(const char *str, char **result); url_func_result url_path(const char *url, char **result); -char *path_to_url(const char *path); -char *url_to_path(const char *url); - #endif diff --git a/windows/findfile.h b/windows/findfile.h index 5f8c7290c..8a3e719ec 100644 --- a/windows/findfile.h +++ b/windows/findfile.h @@ -23,5 +23,8 @@ extern char *nsws_find_resource(char *buf, const char *filename, const char *def char **nsws_init_resource(const char *resource_path); +char *path_to_url(const char *path); +char *url_to_path(const char *url); + #endif /* _NETSURF_WINDOWS_FINDFILE_H_ */ diff --git a/windows/gui.c b/windows/gui.c index a6b2facaf..6ac4f6155 100644 --- a/windows/gui.c +++ b/windows/gui.c @@ -1882,6 +1882,8 @@ static struct gui_fetch_table fetch_table = { .filename_from_path = filename_from_path, .path_add_part = path_add_part, .filetype = fetch_filetype, + .path_to_url = path_to_url, + .url_to_path = url_to_path, .mimetype = fetch_mimetype, }; From dc074042e9f4bcd7d3ccf09fcd81f9b11a0517d0 Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Sat, 25 Jan 2014 23:21:28 +0000 Subject: [PATCH 136/773] fix errors in url_to_path tfetch table changes --- cocoa/NetsurfApp.m | 1 + riscos/gui.c | 2 +- riscos/gui.h | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/cocoa/NetsurfApp.m b/cocoa/NetsurfApp.m index 32ad8f1fb..5c359114c 100644 --- a/cocoa/NetsurfApp.m +++ b/cocoa/NetsurfApp.m @@ -22,6 +22,7 @@ #import "cocoa/plotter.h" #import "cocoa/DownloadWindowController.h" #import "cocoa/selection.h" +#import "cocoa/fetch.h" #import "desktop/gui.h" #import "content/urldb.h" diff --git a/riscos/gui.c b/riscos/gui.c index 43e2f3a4e..69d5b2932 100644 --- a/riscos/gui.c +++ b/riscos/gui.c @@ -808,7 +808,7 @@ static char *path_to_url(const char *path) * \return RISC OS pathname, allocated on heap, or 0 on failure */ -static char *url_to_path(const char *url) +char *url_to_path(const char *url) { char *path; char *filename; diff --git a/riscos/gui.h b/riscos/gui.h index 3eeb56273..32710b442 100644 --- a/riscos/gui.h +++ b/riscos/gui.h @@ -119,6 +119,7 @@ void ro_gui_drag_box_start(wimp_pointer *pointer); bool ro_gui_prequit(void); const char *ro_gui_default_language(void); void gui_poll(bool active); /* exported for riscos/wimp_event.c:722 */ +char *url_to_path(const char *url); /* in download.c */ void ro_gui_download_init(void); From 0ab5fe7c02ccbbd9a898c483219a9317b19834d0 Mon Sep 17 00:00:00 2001 From: Steve Fryatt Date: Sun, 26 Jan 2014 13:30:08 +0000 Subject: [PATCH 137/773] Improve URL handling in URL Bar. Rationalise handling of UTF8, so that URLs are always converted into local encoding even if there is no URL icon present. In addition, make preliminary hotlist test in set_url() use local encoding, in line with all subsequent checks. Make handling of over-length URLs more sensible: warn user and completely blank the URL bar. --- resources/FatMessages | 5 ++++ riscos/gui/url_bar.c | 61 ++++++++++++++++++++++++++++++++++++------- 2 files changed, 56 insertions(+), 10 deletions(-) diff --git a/resources/FatMessages b/resources/FatMessages index 50b39dd57..ff5a761d8 100644 --- a/resources/FatMessages +++ b/resources/FatMessages @@ -2916,6 +2916,11 @@ de.all.NoMemory:Zu wenig Speicher. Bitte mehr Speicher zur Verfügung stellen un fr.all.NoMemory:NetSurf a besoin de plus de mémoire. Veuillez libérer de la mémoire et réessayer. it.all.NoMemory:Memoria insufficiente per l'esecuzione di NetSurf. Per favore liberane un pò e riprova nuovamente. nl.all.NoMemory:NetSurf krijgt gebrek aan geheugen. Maak wat geheugen vrij en probeer het dan nog eens. +en.ro.LongURL:The URL for this page is too long for NetSurf to display. +de.ro.LongURL:The URL for this page is too long for NetSurf to display. +fr.ro.LongURL:The URL for this page is too long for NetSurf to display. +it.ro.LongURL:The URL for this page is too long for NetSurf to display. +nl.ro.LongURL:The URL for this page is too long for NetSurf to display. en.ro.FontBadInst:An error occurred when initialising fonts due to the presence of obsolete copies of the ROM fonts on disc. NetSurf will exit and launch a program which will attempt to fix this. de.ro.FontBadInst:Font-Initialisierung fehlerhaft. Obsolete Kopien von ROM Fonts auf dem lokalem Speichermedium. Fehlerbehebung startet. fr.ro.FontBadInst:Une erreur s'est produite lors de l'initialisation des fontes à cause de la présence de copies obsolètes de fontes ROM sur disque. NetSurf va sortir et lancer un programme qui va tenter de réparer cela. diff --git a/riscos/gui/url_bar.c b/riscos/gui/url_bar.c index 49930934f..0b6bd1c99 100644 --- a/riscos/gui/url_bar.c +++ b/riscos/gui/url_bar.c @@ -39,6 +39,7 @@ #include "riscos/window.h" #include "utils/log.h" #include "utils/messages.h" +#include "utils/utf8.h" #include "utils/utils.h" #define URLBAR_HEIGHT 52 @@ -50,7 +51,6 @@ #define URLBAR_GRIGHT_GUTTER 8 #define URLBAR_FAVICON_NAME_LENGTH 12 #define URLBAR_INITIAL_LENGTH 256 -#define URLBAR_EXTEND_LENGTH 128 struct url_bar { /** The applied theme (or NULL to use the default) */ @@ -942,24 +942,65 @@ void ro_gui_url_bar_set_url(struct url_bar *url_bar, const char *url, { wimp_caret caret; os_error *error; - const char *set_url; + char *local_text = NULL; + const char *set_url, *local_url; nsurl *n; - if (url_bar == NULL || url_bar->text_buffer == NULL) + if (url_bar == NULL || url_bar->text_buffer == NULL || url == NULL) return; - if (nsurl_create(url, &n) == NSERROR_OK) { + /* Before we do anything with the URL, get it into local encoding so + * that behaviour is consistant with the rest of the URL Bar module + * (which will act on the icon's text buffer, which is always in local + * encoding). + */ + + if (is_utf8) { + utf8_convert_ret err; + + err = utf8_to_local_encoding(url, 0, &local_text); + if (err != UTF8_CONVERT_OK) { + /* A bad encoding should never happen, so assert this */ + assert(err != UTF8_CONVERT_BADENC); + LOG(("utf8_to_enc failed")); + /* Paranoia */ + local_text = NULL; + } + local_url = (local_text != NULL) ? local_text : url; + } else { + local_url = url; + } + + /* Copy the text into the icon buffer. If the text is too long, blank + * the buffer and warn the user. + */ + + if (strlen(local_url) >= url_bar->text_size) { + strncpy(url_bar->text_buffer, "", url_bar->text_size); + warn_user("LongURL", NULL); + LOG(("Long URL (%d chars): %s", strlen(url), url)); + } else { + strncpy(url_bar->text_buffer, local_url, url_bar->text_size); + } + + if (local_text != NULL) + free(local_text); + + /* Set the hotlist flag. */ + + if (nsurl_create(url_bar->text_buffer, &n) == NSERROR_OK) { ro_gui_url_bar_set_hotlist(url_bar, ro_gui_hotlist_has_page(n)); nsurl_unref(n); } - if (url_bar->text_icon == -1) { - strncpy(url_bar->text_buffer, url, url_bar->text_size); - return; - } + /* If there's no icon, then there's nothing else to do... */ - ro_gui_set_icon_string(url_bar->window, url_bar->text_icon, - url, is_utf8); + if (url_bar->text_icon == -1) + return; + + /* ...if there is, redraw the icon and fix the caret's position. */ + + ro_gui_redraw_icon(url_bar->window, url_bar->text_icon); error = xwimp_get_caret_position(&caret); if (error) { From 89992958d251cbb1cbd634a0dd89d1161de35041 Mon Sep 17 00:00:00 2001 From: Steve Fryatt Date: Sun, 26 Jan 2014 13:41:41 +0000 Subject: [PATCH 138/773] Increase maximum size of a URL in the URL Bar to 2047 characters plus terminator. --- riscos/gui/url_bar.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/riscos/gui/url_bar.c b/riscos/gui/url_bar.c index 0b6bd1c99..b66b2afc3 100644 --- a/riscos/gui/url_bar.c +++ b/riscos/gui/url_bar.c @@ -50,7 +50,7 @@ #define URLBAR_MIN_WIDTH 52 #define URLBAR_GRIGHT_GUTTER 8 #define URLBAR_FAVICON_NAME_LENGTH 12 -#define URLBAR_INITIAL_LENGTH 256 +#define URLBAR_URL_LENGTH 2048 struct url_bar { /** The applied theme (or NULL to use the default) */ @@ -167,7 +167,7 @@ struct url_bar *ro_gui_url_bar_create(struct theme_descriptor *theme) url_bar->hotlist.extent.x1 = 0; url_bar->hotlist.extent.y1 = 0; - url_bar->text_size = URLBAR_INITIAL_LENGTH; + url_bar->text_size = URLBAR_URL_LENGTH; url_bar->text_buffer = malloc(url_bar->text_size); strncpy(url_bar->text_buffer, "", url_bar->text_size); From def97156d3c0cbeacf2996859f16f727d44eb4e8 Mon Sep 17 00:00:00 2001 From: Steve Fryatt Date: Sun, 26 Jan 2014 14:35:57 +0000 Subject: [PATCH 139/773] Make Open URL dialogue allocate memory for the URL field. Add global constant for URL length, to manage both URL Bar and Open URL. --- riscos/dialog.c | 75 ++++++++++++++++++++++++++++++++++++++------ riscos/gui.h | 4 +++ riscos/gui/url_bar.c | 4 +-- riscos/templates/de | 2 +- riscos/templates/en | 2 +- riscos/templates/fr | 2 +- riscos/templates/nl | 2 +- 7 files changed, 76 insertions(+), 15 deletions(-) diff --git a/riscos/dialog.c b/riscos/dialog.c index 147dce9f8..5fe1d27d6 100644 --- a/riscos/dialog.c +++ b/riscos/dialog.c @@ -85,6 +85,7 @@ static struct { } persistent_dialog[MAX_PERSISTENT]; +static bool ro_gui_dialog_open_url_init(void); static bool ro_gui_dialog_openurl_apply(wimp_w w); static bool ro_gui_dialog_open_url_menu_prepare(wimp_w w, wimp_i i, wimp_menu *menu, wimp_pointer *pointer); @@ -161,15 +162,7 @@ void ro_gui_dialog_init(void) ro_gui_wimp_event_set_help_prefix(dialog_url_complete, "HelpAutoURL"); /* open URL */ - dialog_openurl = ro_gui_dialog_create("open_url"); - ro_gui_wimp_event_register_menu_gright(dialog_openurl, ICON_OPENURL_URL, - ICON_OPENURL_MENU, ro_gui_url_suggest_menu); - ro_gui_wimp_event_register_cancel(dialog_openurl, ICON_OPENURL_CANCEL); - ro_gui_wimp_event_register_ok(dialog_openurl, ICON_OPENURL_OPEN, - ro_gui_dialog_openurl_apply); - ro_gui_wimp_event_register_menu_prepare(dialog_openurl, - ro_gui_dialog_open_url_menu_prepare); - ro_gui_wimp_event_set_help_prefix(dialog_openurl, "HelpOpenURL"); + ro_gui_dialog_open_url_init(); /* scale view */ dialog_zoom = ro_gui_dialog_create("zoom"); @@ -702,6 +695,70 @@ void ro_gui_dialog_update_zoom(struct gui_window *g) { } +/** + * Create the Open URL dialogue, allocating storage for the URL field icon + * as we go. + * + * \return true on success; false on failure (although errors with + * the templates or memory allocation will exit via die()). + */ + +static bool ro_gui_dialog_open_url_init(void) +{ + wimp_window *definition; + char *buffer; + os_error *error; + + definition = ro_gui_dialog_load_template("open_url"); + + /* _load_template() should die on any error, so we trust its data. */ + + assert(definition != NULL); + + /* Create the dialogue, with modifications. */ + + if ((definition->icons[ICON_OPENURL_URL].flags & wimp_ICON_INDIRECTED) + == 0) { + LOG(("open_url URL icon not indirected")); + xwimp_close_template(); + die("Template"); + } + + buffer = malloc(RO_GUI_MAX_URL_SIZE); + if (buffer == NULL) { + xwimp_close_template(); + die("NoMemory"); + } + + definition->icons[ICON_OPENURL_URL].data.indirected_text.text = buffer; + definition->icons[ICON_OPENURL_URL].data.indirected_text.size = + RO_GUI_MAX_URL_SIZE; + definition->sprite_area = gui_sprites; + + error = xwimp_create_window(definition, &dialog_openurl); + if (error != NULL) { + LOG(("xwimp_create_window: 0x%x: %s", + error->errnum, error->errmess)); + xwimp_close_template(); + die(error->errmess); + } + + free(definition); + + ro_gui_wimp_event_register_menu_gright(dialog_openurl, ICON_OPENURL_URL, + ICON_OPENURL_MENU, ro_gui_url_suggest_menu); + ro_gui_wimp_event_register_cancel(dialog_openurl, ICON_OPENURL_CANCEL); + ro_gui_wimp_event_register_ok(dialog_openurl, ICON_OPENURL_OPEN, + ro_gui_dialog_openurl_apply); + ro_gui_wimp_event_register_menu_prepare(dialog_openurl, + ro_gui_dialog_open_url_menu_prepare); + ro_gui_wimp_event_set_help_prefix(dialog_openurl, "HelpOpenURL"); + + return true; +} + + + bool ro_gui_dialog_openurl_apply(wimp_w w) { const char *urltxt; char *url2; diff --git a/riscos/gui.h b/riscos/gui.h index 32710b442..051834a09 100644 --- a/riscos/gui.h +++ b/riscos/gui.h @@ -35,6 +35,10 @@ #define THUMBNAIL_WIDTH 100 #define THUMBNAIL_HEIGHT 86 +/* The maximum size for user-editable URLs in the RISC OS GUI. */ + +#define RO_GUI_MAX_URL_SIZE 2048 + extern int os_version; extern const char * NETSURF_DIR; diff --git a/riscos/gui/url_bar.c b/riscos/gui/url_bar.c index b66b2afc3..829419db3 100644 --- a/riscos/gui/url_bar.c +++ b/riscos/gui/url_bar.c @@ -30,6 +30,7 @@ #include "oslib/os.h" #include "oslib/osspriteop.h" #include "oslib/wimp.h" +#include "riscos/gui.h" #include "riscos/hotlist.h" #include "riscos/gui/url_bar.h" #include "riscos/theme.h" @@ -50,7 +51,6 @@ #define URLBAR_MIN_WIDTH 52 #define URLBAR_GRIGHT_GUTTER 8 #define URLBAR_FAVICON_NAME_LENGTH 12 -#define URLBAR_URL_LENGTH 2048 struct url_bar { /** The applied theme (or NULL to use the default) */ @@ -167,7 +167,7 @@ struct url_bar *ro_gui_url_bar_create(struct theme_descriptor *theme) url_bar->hotlist.extent.x1 = 0; url_bar->hotlist.extent.y1 = 0; - url_bar->text_size = URLBAR_URL_LENGTH; + url_bar->text_size = RO_GUI_MAX_URL_SIZE; url_bar->text_buffer = malloc(url_bar->text_size); strncpy(url_bar->text_buffer, "", url_bar->text_size); diff --git a/riscos/templates/de b/riscos/templates/de index 905d57ec0..190d38a48 100644 --- a/riscos/templates/de +++ b/riscos/templates/de @@ -1683,7 +1683,7 @@ wimp_window { icon_fg:wimp_COLOUR_BLACK icon_bg:wimp_COLOUR_WHITE text.text:"" - text.size:128 + text.size:1 text.validation:"Pptr_write;Kta" } wimp_icon { diff --git a/riscos/templates/en b/riscos/templates/en index a943b1e91..fed72b3ee 100644 --- a/riscos/templates/en +++ b/riscos/templates/en @@ -1891,7 +1891,7 @@ wimp_window { icon_fg:wimp_COLOUR_BLACK icon_bg:wimp_COLOUR_WHITE text.text:"" - text.size:128 + text.size:1 text.validation:"Pptr_write;Kta" } wimp_icon { diff --git a/riscos/templates/fr b/riscos/templates/fr index 30bcbfaf5..2acc5780e 100644 --- a/riscos/templates/fr +++ b/riscos/templates/fr @@ -1695,7 +1695,7 @@ wimp_window { icon_fg:wimp_COLOUR_BLACK icon_bg:wimp_COLOUR_WHITE text.text:"" - text.size:128 + text.size:1 text.validation:"Pptr_write;Kta" } wimp_icon { diff --git a/riscos/templates/nl b/riscos/templates/nl index dcc8af5f4..8e7725f9e 100644 --- a/riscos/templates/nl +++ b/riscos/templates/nl @@ -1895,7 +1895,7 @@ wimp_window { icon_fg:wimp_COLOUR_BLACK icon_bg:wimp_COLOUR_WHITE text.text:"" - text.size:128 + text.size:1 text.validation:"Pptr_write;Kta" } wimp_icon { From cdc4041942be67ee8b70206e7a1bf6f72514e532 Mon Sep 17 00:00:00 2001 From: Steve Fryatt Date: Sun, 26 Jan 2014 15:15:49 +0000 Subject: [PATCH 140/773] Add belt and braces to ensure that URL Bar content is always cleanly terminated. --- riscos/gui/url_bar.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/riscos/gui/url_bar.c b/riscos/gui/url_bar.c index 829419db3..f77c6e7af 100644 --- a/riscos/gui/url_bar.c +++ b/riscos/gui/url_bar.c @@ -976,11 +976,14 @@ void ro_gui_url_bar_set_url(struct url_bar *url_bar, const char *url, */ if (strlen(local_url) >= url_bar->text_size) { - strncpy(url_bar->text_buffer, "", url_bar->text_size); + strncpy(url_bar->text_buffer, "", url_bar->text_size - 1); + url_bar->text_buffer[url_bar->text_size - 1] = '\0'; warn_user("LongURL", NULL); LOG(("Long URL (%d chars): %s", strlen(url), url)); } else { - strncpy(url_bar->text_buffer, local_url, url_bar->text_size); + strncpy(url_bar->text_buffer, local_url, + url_bar->text_size - 1); + url_bar->text_buffer[url_bar->text_size - 1] = '\0'; } if (local_text != NULL) From 27fdcb90f2b9ecaeea39f1c673d7978deaeb1d53 Mon Sep 17 00:00:00 2001 From: Steve Fryatt Date: Sun, 26 Jan 2014 16:28:56 +0000 Subject: [PATCH 141/773] Update copyright dates in modified files. --- riscos/dialog.c | 1 + riscos/gui/url_bar.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/riscos/dialog.c b/riscos/dialog.c index 5fe1d27d6..434702384 100644 --- a/riscos/dialog.c +++ b/riscos/dialog.c @@ -5,6 +5,7 @@ * Copyright 2005 Richard Wilson * Copyright 2004 Andrew Timmins * Copyright 2005 Adrian Lees + * Copyright 2014 Stephen Fryatt * * This file is part of NetSurf, http://www.netsurf-browser.org/ * diff --git a/riscos/gui/url_bar.c b/riscos/gui/url_bar.c index f77c6e7af..d7647402b 100644 --- a/riscos/gui/url_bar.c +++ b/riscos/gui/url_bar.c @@ -1,6 +1,6 @@ /* * Copyright 2004, 2005 Richard Wilson - * Copyright 2011-2013 Stephen Fryatt + * Copyright 2011-2014 Stephen Fryatt * * This file is part of NetSurf, http://www.netsurf-browser.org/ * From 443d6f3e04682f3112162d2ddf7c67224652e424 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Revol?= Date: Tue, 28 Jan 2014 15:14:34 +0100 Subject: [PATCH 142/773] beos: Account for change in atomic_add() prototype in Haiku Since the scheduler branch merge, atomic_add() takes a pointer to int32, doesn't require the target to be volatile anymore. --- beos/window.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/beos/window.cpp b/beos/window.cpp index 0040a1d0c..5009c260b 100644 --- a/beos/window.cpp +++ b/beos/window.cpp @@ -80,7 +80,7 @@ struct gui_window { // those are the last queued event of their kind, // we can safely drop others and avoid wasting cpu. // number of pending resizes - vint32 pending_resizes; + int32 pending_resizes; // accumulated rects of pending redraws //volatile BMessage *lastRedraw; // UNUSED YET From 4b760c7e499e2f5cb1d06242d5f186e14e94496a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Revol?= Date: Tue, 28 Jan 2014 15:15:49 +0100 Subject: [PATCH 143/773] beos: Fix build Add missing header due to moved function. --- beos/fetch_rsrc.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/beos/fetch_rsrc.cpp b/beos/fetch_rsrc.cpp index c52cafe8c..08fc0c73c 100644 --- a/beos/fetch_rsrc.cpp +++ b/beos/fetch_rsrc.cpp @@ -44,6 +44,7 @@ extern "C" { #include "utils/base64.h" } #include "beos/fetch_rsrc.h" +#include "beos/filetype.h" #include "beos/gui.h" #include From 654da2ffb5abf2afe9532f1d0cb77ed88f8a97cc Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Tue, 28 Jan 2014 21:40:13 +0000 Subject: [PATCH 144/773] move utf8 conversion routines to use nserror instead of their own error enum --- amiga/clipboard.c | 2 +- amiga/font.c | 6 +- amiga/utf8.c | 10 +- atari/encoding.c | 12 +- atari/gui.c | 14 +-- atari/plot/font_internal.c | 2 +- atari/plot/font_vdi.c | 2 +- atari/rootwin.c | 6 +- atari/toolbar.c | 4 +- beos/gui.cpp | 14 +-- cocoa/utf8.m | 9 +- desktop/global_history.c | 9 +- desktop/hotlist.c | 9 +- desktop/save_complete.c | 17 ++- desktop/save_text.c | 4 +- framebuffer/font_freetype.c | 8 +- framebuffer/font_internal.c | 10 +- framebuffer/font_internal.h | 2 +- gtk/dialogs/source.c | 12 +- gtk/gui.c | 14 +-- monkey/utils.c | 12 +- render/form.c | 14 +-- render/html.c | 12 +- riscos/download.c | 20 ++-- riscos/gui/url_bar.c | 6 +- riscos/help.c | 6 +- riscos/menus.c | 11 +- riscos/query.c | 10 +- riscos/save.c | 12 +- riscos/textselection.c | 8 +- riscos/ucstables.c | 56 +++++---- riscos/wimp.c | 12 +- riscos/window.c | 16 +-- utils/utf8.c | 220 ++++++++++++------------------------ utils/utf8.h | 132 +++++++++++++++++++--- windows/font.c | 10 +- windows/font.h | 2 +- 37 files changed, 366 insertions(+), 359 deletions(-) diff --git a/amiga/clipboard.c b/amiga/clipboard.c index 8df441e02..d39e89e4a 100644 --- a/amiga/clipboard.c +++ b/amiga/clipboard.c @@ -246,7 +246,7 @@ static void gui_set_clipboard(const char *buffer, size_t length, if(nsoption_bool(clipboard_write_utf8)) { WriteChunkBytes(iffh, buffer, length); } else { - if(utf8_to_local_encoding(buffer, length, &text) == UTF8_CONVERT_OK) { + if(utf8_to_local_encoding(buffer, length, &text) == NSERROR_OK) { char *p; p = text; diff --git a/amiga/font.c b/amiga/font.c index 36c810428..3430a4ea3 100755 --- a/amiga/font.c +++ b/amiga/font.c @@ -212,7 +212,7 @@ bool nsfont_position_in_string(const plot_font_style_t *fstyle, ULONG emwidth = (ULONG)NSA_FONT_EMWIDTH(fstyle->size); int32 tempx; - if(utf8_to_enc(string,"UTF-16",length,(char **)&utf16) != UTF8_CONVERT_OK) return false; + if(utf8_to_enc(string,"UTF-16",length,(char **)&utf16) != NSERROR_OK) return false; outf16 = utf16; if(!(ofont = ami_open_outline_font(fstyle, 0))) return false; @@ -301,7 +301,7 @@ bool nsfont_split(const plot_font_style_t *fstyle, int32 tempx = 0; ULONG emwidth = (ULONG)NSA_FONT_EMWIDTH(fstyle->size); - if(utf8_to_enc((char *)string,"UTF-16",length,(char **)&utf16) != UTF8_CONVERT_OK) return false; + if(utf8_to_enc((char *)string,"UTF-16",length,(char **)&utf16) != NSERROR_OK) return false; outf16 = utf16; if(!(ofont = ami_open_outline_font(fstyle, 0))) return false; @@ -732,7 +732,7 @@ ULONG ami_unicode_text(struct RastPort *rp, const char *string, ULONG length, if(!string || string[0]=='\0') return 0; if(!length) return 0; - if(utf8_to_enc(string,"UTF-16",length,(char **)&utf16) != UTF8_CONVERT_OK) return 0; + if(utf8_to_enc(string,"UTF-16",length,(char **)&utf16) != NSERROR_OK) return 0; outf16 = utf16; if(!(ofont = ami_open_outline_font(fstyle, 0))) return 0; diff --git a/amiga/utf8.c b/amiga/utf8.c index a620ac181..d182492e9 100755 --- a/amiga/utf8.c +++ b/amiga/utf8.c @@ -34,7 +34,7 @@ char *ami_utf8_easy(const char *string) { char *localtext; - if(utf8_to_local_encoding(string,strlen(string),&localtext) == UTF8_CONVERT_OK) + if(utf8_to_local_encoding(string,strlen(string),&localtext) == NSERROR_OK) { return localtext; } @@ -48,7 +48,7 @@ char *ami_to_utf8_easy(const char *string) { char *localtext; - if(utf8_from_local_encoding(string,strlen(string),&localtext) == UTF8_CONVERT_OK) + if(utf8_from_local_encoding(string,strlen(string),&localtext) == NSERROR_OK) { return localtext; } @@ -58,8 +58,7 @@ char *ami_to_utf8_easy(const char *string) } } -utf8_convert_ret utf8_from_local_encoding(const char *string, size_t len, - char **result) +nserror utf8_from_local_encoding(const char *string, size_t len, char **result) { const char *encname = "ISO-8859-1"; @@ -73,8 +72,7 @@ utf8_convert_ret utf8_from_local_encoding(const char *string, size_t len, return utf8_from_enc(string,encname,len,result,NULL); } -utf8_convert_ret utf8_to_local_encoding(const char *string, size_t len, - char **result) +nserror utf8_to_local_encoding(const char *string, size_t len, char **result) { const char *encname = "ISO-8859-1"; diff --git a/atari/encoding.c b/atari/encoding.c index 0212d51c4..626f57ae8 100644 --- a/atari/encoding.c +++ b/atari/encoding.c @@ -21,23 +21,21 @@ /* TODO: this need a rework..., encoding to atari st doesn|t always work. ( gui_add_to_clipboard...) */ -utf8_convert_ret utf8_to_local_encoding(const char *string, +nserror utf8_to_local_encoding(const char *string, size_t len, char **result) { - utf8_convert_ret r; + nserror r; r = utf8_to_enc(string, "ATARIST", len, result); - if(r != UTF8_CONVERT_OK) { + if(r != NSERROR_OK) { r = utf8_to_enc(string, "UTF-8", len, result); - assert( r == UTF8_CONVERT_OK ); + assert( r == NSERROR_OK ); } return r; } -utf8_convert_ret utf8_from_local_encoding(const char *string, - size_t len, - char **result) +nserror utf8_from_local_encoding(const char *string, size_t len, char **result) { return utf8_from_enc(string, "ATARIST", len, result, NULL); } diff --git a/atari/gui.c b/atari/gui.c index f1f557e2e..af5e1f8ba 100644 --- a/atari/gui.c +++ b/atari/gui.c @@ -326,7 +326,7 @@ static void gui_window_set_title(struct gui_window *gw, const char *title) int l; char * conv; l = strlen(title)+1; - if (utf8_to_local_encoding(title, l-1, &conv) == UTF8_CONVERT_OK ) { + if (utf8_to_local_encoding(title, l-1, &conv) == NSERROR_OK ) { l = MIN((uint32_t)atari_sysinfo.aes_max_win_title_len, strlen(conv)); if(gw->title == NULL) gw->title = malloc(l); @@ -699,16 +699,16 @@ static void gui_get_clipboard(char **buffer, size_t *length) // clipboard is in atari encoding, convert it to utf8: char *utf8 = NULL; - utf8_convert_ret ret; + nserror ret; clip_len = strlen(clip); if (clip_len > 0) { ret = utf8_to_local_encoding(clip, clip_len, &utf8); - if (ret == UTF8_CONVERT_OK && utf8 != NULL) { + if (ret == NSERROR_OK && utf8 != NULL) { *buffer = utf8; *length = strlen(utf8); } else { - assert(ret == UTF8_CONVERT_OK && utf8 != NULL); + assert(ret == NSERROR_OK && utf8 != NULL); } } @@ -731,14 +731,14 @@ static void gui_set_clipboard(const char *buffer, size_t length, // convert utf8 input to atari encoding: - utf8_convert_ret ret; + nserror ret; char *clip = NULL; ret = utf8_to_local_encoding(buffer,length, &clip); - if (ret == UTF8_CONVERT_OK) { + if (ret == NSERROR_OK) { scrap_txt_write(clip); } else { - assert(ret == UTF8_CONVERT_OK); + assert(ret == NSERROR_OK); } free(clip); } diff --git a/atari/plot/font_internal.c b/atari/plot/font_internal.c index 2b0025a71..e3c806cfe 100644 --- a/atari/plot/font_internal.c +++ b/atari/plot/font_internal.c @@ -72,7 +72,7 @@ fb_get_font(const plot_font_style_t *fstyle) } } -static utf8_convert_ret utf8_to_font_encoding(const struct fb_font_desc* font, +static nserror utf8_to_font_encoding(const struct fb_font_desc* font, const char *string, size_t len, char **result) diff --git a/atari/plot/font_vdi.c b/atari/plot/font_vdi.c index 340759f02..0c914b82b 100755 --- a/atari/plot/font_vdi.c +++ b/atari/plot/font_vdi.c @@ -267,7 +267,7 @@ static int text( FONT_PLOTTER self, int x, int y, const char *text, size_t leng short fx=0; GRECT canvas; char *lstr = NULL; - assert( utf8_to_local_encoding(text, length, &lstr) == UTF8_CONVERT_OK); + assert( utf8_to_local_encoding(text, length, &lstr) == NSERROR_OK); assert( lstr != NULL ); int slen = strlen(lstr); diff --git a/atari/rootwin.c b/atari/rootwin.c index 0f3413c3d..8942263ad 100755 --- a/atari/rootwin.c +++ b/atari/rootwin.c @@ -1510,15 +1510,15 @@ static void on_file_dropped(ROOTWIN *rootwin, short msg[8]) mx+sx, my+sy, NULL); if(processed == true) { - utf8_convert_ret ret; + nserror ret; char *utf8_fn; ret = utf8_from_local_encoding(buff, 0, &utf8_fn); - if (ret != UTF8_CONVERT_OK) { + if (ret != NSERROR_OK) { free(buff); /* A bad encoding should never happen */ LOG(("utf8_from_local_encoding failed")); - assert(ret != UTF8_CONVERT_BADENC); + assert(ret != NSERROR_BAD_ENCODING); /* no memory */ goto error; } diff --git a/atari/toolbar.c b/atari/toolbar.c index fd9051dd9..8044d160d 100644 --- a/atari/toolbar.c +++ b/atari/toolbar.c @@ -740,11 +740,11 @@ bool toolbar_key_input(struct s_toolbar *tb, short nkc) int clip_length = strlen( clip ); if ( clip_length > 0 ) { char *utf8; - utf8_convert_ret res; + nserror res; /* Clipboard is in local encoding so * convert to UTF8 */ res = utf8_from_local_encoding( clip, clip_length, &utf8 ); - if ( res == UTF8_CONVERT_OK ) { + if ( res == NSERROR_OK ) { toolbar_set_url(tb, utf8); free(utf8); ret = true; diff --git a/beos/gui.cpp b/beos/gui.cpp index 05e06373c..97117e04b 100644 --- a/beos/gui.cpp +++ b/beos/gui.cpp @@ -964,8 +964,7 @@ static void nsbeos_create_ssl_verify_window(struct browser_window *bw, } -utf8_convert_ret utf8_to_local_encoding(const char *string, size_t len, - char **result) +nserror utf8_to_local_encoding(const char *string, size_t len, char **result) { assert(string && result); @@ -974,13 +973,12 @@ utf8_convert_ret utf8_to_local_encoding(const char *string, size_t len, *result = strndup(string, len); if (!(*result)) - return UTF8_CONVERT_NOMEM; + return NSERROR_NOMEM; - return UTF8_CONVERT_OK; + return NSERROR_OK; } -utf8_convert_ret utf8_from_local_encoding(const char *string, size_t len, - char **result) +nserror utf8_from_local_encoding(const char *string, size_t len, char **result) { assert(string && result); @@ -989,9 +987,9 @@ utf8_convert_ret utf8_from_local_encoding(const char *string, size_t len, *result = strndup(string, len); if (!(*result)) - return UTF8_CONVERT_NOMEM; + return NSERROR_NOMEM; - return UTF8_CONVERT_OK; + return NSERROR_OK; } static char *path_to_url(const char *path) diff --git a/cocoa/utf8.m b/cocoa/utf8.m index 2ec829888..7b69918d0 100644 --- a/cocoa/utf8.m +++ b/cocoa/utf8.m @@ -20,21 +20,20 @@ #import "utils/utf8.h" -utf8_convert_ret utf8_to_local_encoding(const char *string, size_t len, +nserror utf8_to_local_encoding(const char *string, size_t len, char **result) { NSCParameterAssert( NULL != result ); char *newString = malloc( len + 1 ); - if (NULL == newString) return UTF8_CONVERT_NOMEM; + if (NULL == newString) return NSERROR_NOMEM; memcpy( newString, string, len ); newString[len] = 0; *result = newString; - return UTF8_CONVERT_OK; + return NSERROR_OK; } -utf8_convert_ret utf8_from_local_encoding(const char *string, size_t len, - char **result) +nserror utf8_from_local_encoding(const char *string, size_t len, char **result) { /* same function, local encoding = UTF-8 */ return utf8_to_local_encoding( string, len, result ); diff --git a/desktop/global_history.c b/desktop/global_history.c index e8d99efc2..9d0e47e34 100644 --- a/desktop/global_history.c +++ b/desktop/global_history.c @@ -828,21 +828,21 @@ static nserror global_history_export_enter_cb(void *ctx, void *node_data, enum treeview_node_type type, bool *abort) { struct treeview_export_walk_ctx *tw = ctx; + nserror ret; if (type == TREE_NODE_ENTRY) { struct global_history_entry *e = node_data; - utf8_convert_ret ret; char *t_text; char *u_text; ret = utf8_to_html(e->data[GH_TITLE].value, "iso-8859-1", e->data[GH_TITLE].value_len, &t_text); - if (ret != UTF8_CONVERT_OK) + if (ret != NSERROR_OK) return NSERROR_SAVE_FAILED; ret = utf8_to_html(e->data[GH_URL].value, "iso-8859-1", e->data[GH_URL].value_len, &u_text); - if (ret != UTF8_CONVERT_OK) { + if (ret != NSERROR_OK) { free(t_text); return NSERROR_SAVE_FAILED; } @@ -855,12 +855,11 @@ static nserror global_history_export_enter_cb(void *ctx, void *node_data, } else if (type == TREE_NODE_FOLDER) { struct global_history_folder *f = node_data; - utf8_convert_ret ret; char *f_text; ret = utf8_to_html(f->data.value, "iso-8859-1", f->data.value_len, &f_text); - if (ret != UTF8_CONVERT_OK) + if (ret != NSERROR_OK) return NSERROR_SAVE_FAILED; fprintf(tw->fp, "
  • %s

    \n