From bd065d4a434755e67642a071e255cba596de8d1e Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Wed, 15 Jan 2014 19:37:05 +0000 Subject: split browser gui operations up --- 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 +- 7 files changed, 147 insertions(+), 84 deletions(-) (limited to 'desktop') 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 { - - /* sub tables */ - - /** Window sub table */ - struct gui_window_table *window; +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); - /** 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; - } - - /* 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; + /* clipboard table */ + if (gt->clipboard == NULL) { + /* set default clipboard table */ + gt->clipboard = &default_clipboard_table; } - 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; -- cgit v1.2.3