From b7736bae2f37675be55b1c89d33b03e8603b2946 Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Sun, 12 Jan 2014 17:07:34 +0000 Subject: split gui operations into core and window and move more operations into tables --- desktop/browser.c | 20 +++++------ desktop/gui.h | 76 ++++++++++++++++++++++++++------------- desktop/gui_factory.c | 99 +++++++++++++++++++++++++++++++++++++++++---------- desktop/searchweb.c | 2 +- 4 files changed, 143 insertions(+), 54 deletions(-) (limited to 'desktop') 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,43 +65,75 @@ struct gui_download_window; struct browser_window; struct form_control; -/** Graphical user interface function table +/** Graphical user interface window function table * - * function table implementing GUI interface to browser core + * function table implementing window operations */ -struct gui_table { +struct gui_window_table { /* Mandantory entries */ - /** 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); + struct gui_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); + void (*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); + void (*set_title)(struct gui_window *g, const char *title); /** set the navigation url. */ - void (*window_set_url)(struct gui_window *g, const char *url); + void (*set_url)(struct gui_window *g, const char *url); /** start the navigation throbber. */ - void (*window_start_throbber)(struct gui_window *g); + void (*start_throbber)(struct gui_window *g); /** stop the navigation throbber. */ - void (*window_stop_throbber)(struct gui_window *g); + 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 + */ +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); + + + /* Optional entries */ + + /** called to allow the gui to cleanup */ + void (*quit)(void); + + /** + * 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 the mandantory fields are set */ - if (gt->poll == NULL) { + /* check table is present */ + if (gt == NULL) { return NSERROR_BAD_PARAMETER; } - if (gt->window_create == NULL) { - return NSERROR_BAD_PARAMETER; + + /* check subtables */ + err = verify_window_register(gt->window); + if (err != NSERROR_OK) { + return err; } - if (gt->window_destroy == NULL) { + + /* 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->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: -- cgit v1.2.3