From 7897a98a4c7475e116f406ab173139c959d6dfb6 Mon Sep 17 00:00:00 2001 From: James Bursa Date: Wed, 25 Feb 2004 15:12:58 +0000 Subject: [project @ 2004-02-25 15:12:57 by bursa] Implement scaling; rewrite desktop/browser; add riscos/thumbnail; rewrite history. svn path=/import/netsurf/; revision=566 --- desktop/browser.c | 1542 +++++++++++++++++++++++++++-------------------------- desktop/browser.h | 104 ++-- desktop/gui.h | 13 +- 3 files changed, 847 insertions(+), 812 deletions(-) (limited to 'desktop') diff --git a/desktop/browser.c b/desktop/browser.c index ef29aa80b..f6c157697 100644 --- a/desktop/browser.c +++ b/desktop/browser.c @@ -3,7 +3,11 @@ * Licensed under the GNU General Public License, * http://www.opensource.org/licenses/gpl-license * Copyright 2003 Phil Mellor - * Copyright 2003 James Bursa + * Copyright 2004 James Bursa + */ + +/** \file + * Browser window creation and manipulation (implementation). */ #include @@ -13,10 +17,7 @@ #include #include #include -#include "curl/curl.h" -#include "libxml/debugXML.h" #include "netsurf/utils/config.h" -#include "netsurf/content/cache.h" #include "netsurf/content/fetchcache.h" #include "netsurf/css/css.h" #ifdef WITH_AUTH @@ -31,7 +32,20 @@ #include "netsurf/utils/messages.h" #include "netsurf/utils/utils.h" -static void browser_window_start_throbber(struct browser_window* bw); + +static void browser_window_callback(content_msg msg, struct content *c, + void *p1, void *p2, const char *error); +static void browser_window_convert_to_download(struct browser_window *bw, + content_msg msg); +static void browser_window_start_throbber(struct browser_window *bw); +static void browser_window_stop_throbber(struct browser_window *bw); +static void browser_window_update(struct browser_window *bw, + bool scroll_to_top); +static void browser_window_set_status(struct browser_window *bw, + const char *text); +static void download_window_callback(content_msg msg, struct content *c, + void *p1, void *p2, const char *error); + static void browser_window_text_selection(struct browser_window* bw, unsigned long click_x, unsigned long click_y, int click_type); static void browser_window_clear_text_selection(struct browser_window* bw); @@ -42,17 +56,6 @@ static int redraw_box_list(struct browser_window* bw, struct box* current, static void browser_window_redraw_boxes(struct browser_window* bw, struct box_position* start, struct box_position* end); static void browser_window_follow_link(struct browser_window* bw, unsigned long click_x, unsigned long click_y, int click_type); -static void browser_window_open_location_post(struct browser_window* bw, - const char* url0 -#ifdef WITH_POST - , char *post_urlenc, - struct form_successful_control *post_multipart -#endif - ); -static void browser_window_callback(content_msg msg, struct content *c, - void *p1, void *p2, const char *error); -static void download_window_callback(content_msg msg, struct content *c, - void *p1, void *p2, const char *error); static void clear_radio_gadgets(struct browser_window* bw, struct box* box, struct form_control* group); static void gui_redraw_gadget2(struct browser_window* bw, struct box* box, struct form_control* g, unsigned long x, unsigned long y); @@ -74,366 +77,367 @@ static void browser_window_place_caret(struct browser_window *bw, int x, int y, int height, void (*callback)(struct browser_window *bw, char key, void *p), void *p); -void browser_window_start_throbber(struct browser_window* bw) -{ - bw->throbbing = 1; - gui_window_start_throbber(bw->window); - return; -} +/** + * Create and open a new browser window with the given page. + * + * \param url URL to start fetching in the new window (copied) + */ -void browser_window_stop_throbber(struct browser_window* bw) +void browser_window_create(const char *url) { - bw->throbbing = 0; - gui_window_stop_throbber(bw->window); -} + struct browser_window *bw; + bw = malloc(sizeof *bw); + if (!bw) { + warn_user("NoMemory"); + return; + } -void browser_window_reformat(struct browser_window* bw, int scroll_to_top) -{ - LOG(("bw = %p", bw)); - - assert(bw != 0); - if (bw->current_content == NULL) - return; - - if (bw->current_content->title == 0) - gui_window_set_title(bw->window, bw->url); - else - gui_window_set_title(bw->window, bw->current_content->title); - gui_window_set_extent(bw->window, bw->current_content->width, bw->current_content->height); - if (scroll_to_top) - gui_window_set_scroll(bw->window, 0, 0); - gui_window_redraw_window(bw->window); - - LOG(("done")); + bw->current_content = 0; + bw->loading_content = 0; + bw->history = history_create(); + bw->throbbing = false; + bw->caret_callback = 0; + bw->window = gui_create_browser_window(bw); + if (!bw->window) { + free(bw); + return; + } + + browser_window_go(bw, url); } -void browser_window_back(struct browser_window* bw) + +/** + * Start fetching a page in a browser window. + * + * \param bw browser window + * \param url URL to start fetching (copied) + * + * Any existing fetches in the window are aborted. + */ + +void browser_window_go(struct browser_window *bw, const char *url) { + browser_window_go_post(bw, url, 0, 0, true); } -void browser_window_forward(struct browser_window* bw) + +/** + * Start fetching a page in a browser window, POSTing form data. + * + * \param bw browser window + * \param url URL to start fetching (copied) + * \param post_urlenc url encoded post data, or 0 if none + * \param post_multipart multipart post data, or 0 if none + * \param history_add add to window history + * + * Any existing fetches in the window are aborted. + * + * If post_urlenc and post_multipart are 0 the url is fetched using GET. + * + * The page is not added to the window history if add_history is false. This + * should be used when returning to a page in the window history. + */ + +void browser_window_go_post(struct browser_window *bw, const char *url, + char *post_urlenc, + struct form_successful_control *post_multipart, + bool history_add) { + struct content *c; + + browser_window_stop(bw); + + browser_window_set_status(bw, "Opening page..."); + bw->history_add = history_add; + bw->time0 = clock(); + c = fetchcache(url, 0, + browser_window_callback, bw, 0, + gui_window_get_width(bw->window), 0, + false, + post_urlenc, post_multipart, + true); + if (!c) { + browser_window_set_status(bw, "Unable to fetch document"); + return; + } + bw->loading_content = c; + browser_window_start_throbber(bw); + + if (c->status == CONTENT_STATUS_READY) { + browser_window_callback(CONTENT_MSG_READY, c, bw, 0, 0); + + } else if (c->status == CONTENT_STATUS_DONE) { + browser_window_callback(CONTENT_MSG_READY, c, bw, 0, 0); + if (c->type == CONTENT_OTHER) + download_window_callback(CONTENT_MSG_DONE, c, bw, 0, 0); + else + browser_window_callback(CONTENT_MSG_DONE, c, bw, 0, 0); + } } -struct browser_window* create_browser_window(int flags, int width, int height -#ifdef WITH_FRAMES -, struct browser_window *parent -#endif -) +/** + * Callback for fetchcache() for browser window fetches. + */ + +void browser_window_callback(content_msg msg, struct content *c, + void *p1, void *p2, const char *error) { - struct browser_window* bw; - bw = (struct browser_window*) xcalloc(1, sizeof(struct browser_window)); + struct browser_window *bw = p1; + char status[40]; - bw->flags = flags; - bw->throbbing = 0; - bw->format_width = width; - bw->format_height = height; + if (c->type == CONTENT_OTHER) { + browser_window_convert_to_download(bw, msg); + return; + } - bw->scale.mult = 1; - bw->scale.div = 1; + switch (msg) { + case CONTENT_MSG_LOADING: + break; - bw->current_content = NULL; - bw->loading_content = NULL; - bw->history_entry = 0; + case CONTENT_MSG_READY: + assert(bw->loading_content == c); + + if (bw->current_content) { + if (bw->current_content->status == + CONTENT_STATUS_DONE) + content_remove_instance( + bw->current_content, + bw, 0, 0, + 0, + &bw->current_content_state); + content_remove_user(bw->current_content, + browser_window_callback, + bw, 0); + } + bw->current_content = c; + bw->loading_content = 0; + bw->caret_callback = 0; + gui_window_set_url(bw->window, c->url); + browser_window_update(bw, true); + browser_window_set_status(bw, c->status_message); + if (bw->history_add) + history_add(bw->history, c); + break; - bw->url = NULL; - bw->caret_callback = 0; + case CONTENT_MSG_DONE: + assert(bw->current_content == c); + + content_add_instance(c, bw, 0, 0, 0, + &bw->current_content_state); + browser_window_update(bw, false); + content_reshape_instance(c, bw, 0, 0, 0, + &bw->current_content_state); + sprintf(status, "Page complete (%gs)", + ((float) (clock() - bw->time0)) / + CLOCKS_PER_SEC); + browser_window_set_status(bw, status); + browser_window_stop_throbber(bw); + history_update(bw->history, c); + break; -#ifdef WITH_FRAMES - bw->parent = parent; + case CONTENT_MSG_ERROR: + browser_window_set_status(bw, error); + if (c == bw->loading_content) + bw->loading_content = 0; + else if (c == bw->current_content) + bw->current_content = 0; + browser_window_stop_throbber(bw); + break; - if (bw->parent != NULL) { - bw->parent->children = xrealloc(bw->parent->children, - (bw->parent->no_children+1) * - sizeof(struct browser_window)); - bw->parent->children[bw->parent->no_children] = bw; - bw->parent->no_children++; + case CONTENT_MSG_STATUS: + browser_window_set_status(bw, c->status_message); + break; - bw->window = NULL; /* This is filled in by frame_add_instance */ - } - else { -#endif + case CONTENT_MSG_REDIRECT: + bw->loading_content = 0; + browser_window_set_status(bw, "Redirecting"); + /* error actually holds the new URL */ + browser_window_go(bw, error); + break; - bw->window = gui_create_browser_window(bw); + case CONTENT_MSG_REFORMAT: + browser_window_update(bw, false); + break; -#ifdef WITH_FRAMES - } +#ifdef WITH_AUTH + case CONTENT_MSG_AUTH: + gui_401login_open(bw, c, error); + if (c == bw->loading_content) + bw->loading_content = 0; + else if (c == bw->current_content) + bw->current_content = 0; + browser_window_stop_throbber(bw); + break; #endif - return bw; + default: + assert(0); + } } -void browser_window_set_status(struct browser_window* bw, const char* text) + +/** + * Transfer the loading_content to a new download window. + */ + +void browser_window_convert_to_download(struct browser_window *bw, + content_msg msg) { - if (bw->window != NULL) - gui_window_set_status(bw->window, text); + gui_window *download_window; + struct content *c = bw->loading_content; + assert(c); + + /* create download window and add content to it */ + download_window = gui_create_download_window(c); + content_add_user(c, download_window_callback, download_window, 0); + + if (msg == CONTENT_MSG_DONE) + download_window_callback(CONTENT_MSG_DONE, c, download_window, + 0, 0); + + /* remove content from browser window */ + bw->loading_content = 0; + content_remove_user(c, browser_window_callback, bw, 0); + browser_window_stop_throbber(bw); } -void browser_window_destroy(struct browser_window* bw -#ifdef WITH_FRAMES -, bool self -#endif -) + +/** + * Start the busy indicator. + * + * \param bw browser window + */ + +void browser_window_start_throbber(struct browser_window *bw) { - /*unsigned int i;*/ - LOG(("bw = %p", bw)); - assert(bw != 0); - -#ifdef WITH_FRAMES - if (bw->no_children == 0 && bw->parent != NULL) { /* leaf node -> delete */ - if (bw->current_content != NULL) { - if (bw->current_content->status == CONTENT_STATUS_DONE) - content_remove_instance(bw->current_content, bw, 0, 0, 0, &bw->current_content_state); -#ifdef WITH_AUTH - login_list_remove(bw->current_content->url); -#endif - } - xfree(bw->url); - xfree(bw); + bw->throbbing = true; + gui_window_start_throbber(bw->window); +} - return; - } - for (i=0; i!=bw->no_children; i++) { /* non-leaf node -> kill children */ - browser_window_destroy(bw->children[i], true); - } +/** + * Stop the busy indicator. + * + * \param bw browser window + */ - /* all children killed -> remove this node */ - if (self || bw->parent != NULL) { -#endif +void browser_window_stop_throbber(struct browser_window *bw) +{ + bw->throbbing = false; + gui_window_stop_throbber(bw->window); +} - if (bw->current_content != NULL) { - if (bw->current_content->status == CONTENT_STATUS_DONE) - content_remove_instance(bw->current_content, bw, 0, 0, 0, &bw->current_content_state); - content_remove_user(bw->current_content, browser_window_callback, bw, 0); -#ifdef WITH_AUTH - login_list_remove(bw->current_content->url); -#endif - } - if (bw->loading_content != NULL) { - content_remove_user(bw->loading_content, browser_window_callback, bw, 0); - } - xfree(bw->url); - gui_window_destroy(bw->window); +/** + * Redraw browser window, set extent to content, and update title. + * + * \param bw browser_window + * \param scroll_to_top move view to top of page + */ -#ifdef WITH_FRAMES - xfree(bw->children); -#endif +void browser_window_update(struct browser_window *bw, + bool scroll_to_top) +{ + if (!bw->current_content) + return; - xfree(bw); + if (bw->current_content->title) + gui_window_set_title(bw->window, bw->current_content->title); + else + gui_window_set_title(bw->window, bw->current_content->url); -#ifdef WITH_FRAMES - } - else { - bw->no_children = 0; - xfree(bw->children); - } -#endif + gui_window_set_extent(bw->window, bw->current_content->width, + bw->current_content->height); - LOG(("end")); + if (scroll_to_top) + gui_window_set_scroll(bw->window, 0, 0); + + gui_window_redraw_window(bw->window); } -void browser_window_open_location_historical(struct browser_window* bw, - const char* url -#ifdef WITH_POST - , char *post_urlenc, - struct form_successful_control *post_multipart -#endif - ) -{ -#ifdef WITH_AUTH - struct login *li; -#endif - LOG(("bw = %p, url = %s", bw, url)); - assert(bw != 0 && url != 0); +/** + * Stop all fetching activity in a browser window. + * + * \param bw browser window + */ - /* Check window still exists, if not, don't bother going any further */ - if (!gui_window_in_list(bw->window)) return; +void browser_window_stop(struct browser_window *bw) +{ + if (bw->loading_content) { + content_remove_user(bw->loading_content, + browser_window_callback, bw, 0); + bw->loading_content = 0; + } -#ifdef WITH_FRAMES - if (bw->url != NULL) - browser_window_destroy(bw, false); -#endif + if (bw->current_content && + bw->current_content->status != CONTENT_STATUS_DONE) { + assert(bw->current_content->status == CONTENT_STATUS_READY); + /** \todo implement content_stop */ + } -#ifdef WITH_AUTH - if ((li = login_list_get(url)) == NULL) { + browser_window_stop_throbber(bw); +} - if (bw->current_content != NULL) { - login_list_remove(bw->current_content->url); - } - } -#endif - browser_window_set_status(bw, "Opening page..."); - browser_window_start_throbber(bw); - bw->time0 = clock(); - bw->history_add = false; - bw->loading_content = fetchcache(url, 0, browser_window_callback, bw, 0, - gui_window_get_width(bw->window), 0, false -#ifdef WITH_POST - ,post_urlenc, post_multipart -#endif -#ifdef WITH_COOKIES - , true -#endif - ); - if (bw->loading_content == 0) { - browser_window_set_status(bw, "Unable to fetch document"); - return; - } - if (bw->loading_content->status == CONTENT_STATUS_READY) - browser_window_callback(CONTENT_MSG_READY, bw->loading_content, bw, 0, 0); - else if (bw->loading_content->status == CONTENT_STATUS_DONE) - browser_window_callback(CONTENT_MSG_DONE, bw->loading_content, bw, 0, 0); - - LOG(("end")); +/** + * Change the status bar of a browser window. + * + * \param bw browser window + * \param text new status text (copied) + */ + +void browser_window_set_status(struct browser_window *bw, const char *text) +{ + gui_window_set_status(bw->window, text); } -void browser_window_open_location(struct browser_window* bw, const char* url0) + +/** + * Close and destroy a browser window. + * + * \param bw browser window + */ + +void browser_window_destroy(struct browser_window *bw) { - browser_window_open_location_post(bw, url0 -#ifdef WITH_POST - , 0, 0 -#endif - ); + if (bw->loading_content) { + content_remove_user(bw->loading_content, + browser_window_callback, bw, 0); + bw->loading_content = 0; + } + + if (bw->current_content) { + if (bw->current_content->status == CONTENT_STATUS_DONE) + content_remove_instance(bw->current_content, bw, 0, + 0, 0, &bw->current_content_state); + content_remove_user(bw->current_content, + browser_window_callback, bw, 0); + } + + history_destroy(bw->history); + gui_window_destroy(bw->window); + + free(bw); } -void browser_window_open_location_post(struct browser_window* bw, - const char* url -#ifdef WITH_POST - , char *post_urlenc, - struct form_successful_control *post_multipart -#endif - ) + + +void browser_window_back(struct browser_window* bw) { - char *url1; - LOG(("bw = %p, url = %s", bw, url)); - assert(bw != 0 && url != 0); - url1 = url_join(url, 0); - if (!url1) - return; - browser_window_open_location_historical(bw, url1 -#ifdef WITH_POST - , post_urlenc, post_multipart -#endif - ); - bw->history_add = true; - free(url1); - LOG(("end")); } -void browser_window_callback(content_msg msg, struct content *c, - void *p1, void *p2, const char *error) +void browser_window_forward(struct browser_window* bw) { - struct browser_window* bw = p1; - gui_safety previous_safety; - char status[40]; - - switch (msg) - { - case CONTENT_MSG_LOADING: - case CONTENT_MSG_READY: - case CONTENT_MSG_DONE: - if (c->type == CONTENT_OTHER) { - gui_window *download_window; - assert(bw->loading_content == c); - - /* create download window and add content to it */ - download_window = gui_create_download_window(c); - content_add_user(c, download_window_callback, download_window, 0); - if (msg == CONTENT_MSG_DONE) - download_window_callback(CONTENT_MSG_DONE, c, download_window, 0, 0); - - /* remove content from browser window */ - bw->loading_content = 0; - content_remove_user(c, browser_window_callback, bw, 0); - browser_window_stop_throbber(bw); - - break; - } - - if (msg == CONTENT_MSG_LOADING) - break; - - previous_safety = gui_window_set_redraw_safety(bw->window, UNSAFE); - if (bw->loading_content == c) { - if (bw->url != 0) - xfree(bw->url); - bw->url = xstrdup(c->url); - - gui_window_set_url(bw->window, bw->url); - - if (bw->current_content != NULL) - { - if (bw->current_content->status == CONTENT_STATUS_DONE) - content_remove_instance(bw->current_content, bw, 0, 0, 0, &bw->current_content_state); - content_remove_user(bw->current_content, browser_window_callback, bw, 0); - } - bw->current_content = c; - bw->loading_content = 0; - bw->caret_callback = 0; - if (bw->history_add) - bw->history_entry = history_add(bw->history_entry, bw->url, - bw->current_content->title); - bw->history_add = false; - } - gui_window_set_redraw_safety(bw->window, previous_safety); - if (bw->current_content->status == CONTENT_STATUS_DONE) { - content_add_instance(bw->current_content, bw, 0, 0, 0, &bw->current_content_state); - browser_window_reformat(bw, 0); - content_reshape_instance(bw->current_content, bw, 0, 0, 0, &bw->current_content_state); - sprintf(status, "Page complete (%gs)", ((float) (clock() - bw->time0)) / CLOCKS_PER_SEC); - browser_window_set_status(bw, status); - browser_window_stop_throbber(bw); - } else { - browser_window_reformat(bw, 1); - browser_window_set_status(bw, c->status_message); - } - break; - - case CONTENT_MSG_ERROR: - browser_window_set_status(bw, error); - if (c == bw->loading_content) - bw->loading_content = 0; - else if (c == bw->current_content) - bw->current_content = 0; - browser_window_stop_throbber(bw); - break; - - case CONTENT_MSG_STATUS: - browser_window_set_status(bw, c->status_message); - break; - - case CONTENT_MSG_REDIRECT: - bw->loading_content = 0; - browser_window_set_status(bw, "Redirecting"); - /* error actually holds the new URL */ - browser_window_open_location(bw, error); - break; - - case CONTENT_MSG_REFORMAT: - browser_window_reformat(bw, 0); - break; +} -#ifdef WITH_AUTH - case CONTENT_MSG_AUTH: - gui_401login_open(bw, c, error); - if (c == bw->loading_content) - bw->loading_content = 0; - else if (c == bw->current_content) - bw->current_content = 0; - browser_window_stop_throbber(bw); - break; -#endif - default: - assert(0); - } -} +/** + * Callback for fetchcache() for download window fetches. + */ void download_window_callback(content_msg msg, struct content *c, void *p1, void *p2, const char *error) @@ -454,13 +458,12 @@ void download_window_callback(content_msg msg, struct content *c, break; case CONTENT_MSG_READY: - /* not possible for CONTENT_OTHER */ - assert(0); break; case CONTENT_MSG_LOADING: case CONTENT_MSG_REDIRECT: - /* not possible at this point, handled above */ + /* not possible at this point, handled in + browser_window_callback() */ assert(0); break; @@ -474,49 +477,53 @@ void download_window_callback(content_msg msg, struct content *c, } } -void clear_radio_gadgets(struct browser_window* bw, struct box* box, struct form_control* group) +void clear_radio_gadgets(struct browser_window *bw, struct box *box, + struct form_control *group) { - struct box* c; + struct box *c; if (box == NULL) return; - if (box->gadget != 0) - { - if (box->gadget->type == GADGET_RADIO && box->gadget->name != 0 && box->gadget != group) - { - if (strcmp(box->gadget->name, group->name) == 0) - { - if (box->gadget->data.radio.selected) - { - box->gadget->data.radio.selected = 0; + if (box->gadget != 0) { + if (box->gadget->type == GADGET_RADIO + && box->gadget->name != 0 && box->gadget != group) { + if (strcmp(box->gadget->name, group->name) == 0) { + if (box->gadget->data.radio.selected) { + box->gadget->data.radio.selected = + 0; gui_redraw_gadget(bw, box->gadget); } } } } - for (c = box->children; c != 0; c = c->next) - if (c->type != BOX_FLOAT_LEFT && c->type != BOX_FLOAT_RIGHT) - clear_radio_gadgets(bw, c, group); + for (c = box->children; c != 0; c = c->next) + if (c->type != BOX_FLOAT_LEFT + && c->type != BOX_FLOAT_RIGHT) + clear_radio_gadgets(bw, c, group); - for (c = box->float_children; c != 0; c = c->next_float) - clear_radio_gadgets(bw, c, group); + for (c = box->float_children; c != 0; c = c->next_float) + clear_radio_gadgets(bw, c, group); } -void gui_redraw_gadget2(struct browser_window* bw, struct box* box, struct form_control* g, - unsigned long x, unsigned long y) +void gui_redraw_gadget2(struct browser_window *bw, struct box *box, + struct form_control *g, unsigned long x, + unsigned long y) { - struct box* c; + struct box *c; - if (box->gadget == g) - { - gui_window_redraw(bw->window, x + box->x, y + box->y, x + box->x + box->width, y+box->y + box->height); + if (box->gadget == g) { + gui_window_redraw(bw->window, x + box->x, y + box->y, + x + box->x + box->width, + y + box->y + box->height); } - for (c = box->children; c != 0; c = c->next) - if (c->type != BOX_FLOAT_LEFT && c->type != BOX_FLOAT_RIGHT) - gui_redraw_gadget2(bw, c, g, box->x + x, box->y + y); + for (c = box->children; c != 0; c = c->next) + if (c->type != BOX_FLOAT_LEFT + && c->type != BOX_FLOAT_RIGHT) + gui_redraw_gadget2(bw, c, g, box->x + x, + box->y + y); - for (c = box->float_children; c != 0; c = c->next_float) - gui_redraw_gadget2(bw, c, g, box->x + x, box->y + y); + for (c = box->float_children; c != 0; c = c->next_float) + gui_redraw_gadget2(bw, c, g, box->x + x, box->y + y); } void gui_redraw_gadget(struct browser_window* bw, struct form_control* g) @@ -1209,378 +1216,422 @@ bool browser_window_key_press(struct browser_window *bw, char key) } -int browser_window_action(struct browser_window* bw, struct browser_action* act) +int browser_window_action(struct browser_window *bw, + struct browser_action *act) { - switch (act->type) - { - case act_MOUSE_AT: - browser_window_follow_link(bw, act->data.mouse.x, act->data.mouse.y, 0); - break; - case act_MOUSE_CLICK: - return browser_window_gadget_click(bw, act->data.mouse.x, act->data.mouse.y); - break; - case act_CLEAR_SELECTION: - browser_window_text_selection(bw, act->data.mouse.x, act->data.mouse.y, 0); - break; - case act_START_NEW_SELECTION: - browser_window_text_selection(bw, act->data.mouse.x, act->data.mouse.y, 1); - break; - case act_ALTER_SELECTION: - browser_window_text_selection(bw, act->data.mouse.x, act->data.mouse.y, 2); - break; - case act_FOLLOW_LINK: - browser_window_follow_link(bw, act->data.mouse.x, act->data.mouse.y, 1); - break; - case act_FOLLOW_LINK_NEW_WINDOW: - browser_window_follow_link(bw, act->data.mouse.x, act->data.mouse.y, 2); - break; - case act_GADGET_SELECT: - browser_window_gadget_select(bw, act->data.gadget_select.g, act->data.gadget_select.item); - default: - break; - } - return 0; + switch (act->type) { + case act_MOUSE_AT: + browser_window_follow_link(bw, act->data.mouse.x, + act->data.mouse.y, 0); + break; + case act_MOUSE_CLICK: + return browser_window_gadget_click(bw, act->data.mouse.x, + act->data.mouse.y); + break; + case act_CLEAR_SELECTION: + browser_window_text_selection(bw, act->data.mouse.x, + act->data.mouse.y, 0); + break; + case act_START_NEW_SELECTION: + browser_window_text_selection(bw, act->data.mouse.x, + act->data.mouse.y, 1); + break; + case act_ALTER_SELECTION: + browser_window_text_selection(bw, act->data.mouse.x, + act->data.mouse.y, 2); + break; + case act_FOLLOW_LINK: + browser_window_follow_link(bw, act->data.mouse.x, + act->data.mouse.y, 1); + break; + case act_FOLLOW_LINK_NEW_WINDOW: + browser_window_follow_link(bw, act->data.mouse.x, + act->data.mouse.y, 2); + break; + case act_GADGET_SELECT: + browser_window_gadget_select(bw, act->data.gadget_select.g, + act->data.gadget_select.item); + default: + break; + } + return 0; } -void box_under_area(struct box* box, unsigned long x, unsigned long y, unsigned long ox, unsigned long oy, - struct box_selection** found, int* count, int* plot_index) +void box_under_area(struct box *box, unsigned long x, unsigned long y, + unsigned long ox, unsigned long oy, + struct box_selection **found, int *count, + int *plot_index) { - struct box* c; - - if (box == NULL) - return; + struct box *c; - *plot_index = *plot_index + 1; + if (box == NULL) + return; - if (x >= box->x + ox && x <= box->x + ox + box->width && - y >= box->y + oy && y <= box->y + oy + box->height) - { - *found = xrealloc(*found, sizeof(struct box_selection) * (*count + 1)); - (*found)[*count].box = box; - (*found)[*count].actual_x = box->x + ox; - (*found)[*count].actual_y = box->y + oy; - (*found)[*count].plot_index = *plot_index; - *count = *count + 1; - } + *plot_index = *plot_index + 1; + + if (x >= box->x + ox && x <= box->x + ox + box->width && + y >= box->y + oy && y <= box->y + oy + box->height) { + *found = + xrealloc(*found, + sizeof(struct box_selection) * (*count + 1)); + (*found)[*count].box = box; + (*found)[*count].actual_x = box->x + ox; + (*found)[*count].actual_y = box->y + oy; + (*found)[*count].plot_index = *plot_index; + *count = *count + 1; + } - for (c = box->children; c != 0; c = c->next) - if (c->type != BOX_FLOAT_LEFT && c->type != BOX_FLOAT_RIGHT) - box_under_area(c, x, y, box->x + ox, box->y + oy, found, count, plot_index); + for (c = box->children; c != 0; c = c->next) + if (c->type != BOX_FLOAT_LEFT + && c->type != BOX_FLOAT_RIGHT) + box_under_area(c, x, y, box->x + ox, box->y + oy, + found, count, plot_index); - for (c = box->float_children; c != 0; c = c->next_float) - box_under_area(c, x, y, box->x + ox, box->y + oy, found, count, plot_index); + for (c = box->float_children; c != 0; c = c->next_float) + box_under_area(c, x, y, box->x + ox, box->y + oy, found, + count, plot_index); - return; + return; } -void browser_window_follow_link(struct browser_window* bw, - unsigned long click_x, unsigned long click_y, int click_type) +void browser_window_follow_link(struct browser_window *bw, + unsigned long click_x, + unsigned long click_y, int click_type) { - struct box_selection* click_boxes; - int found, plot_index; - int i; - int done = 0; - - found = 0; - click_boxes = NULL; - plot_index = 0; - - if (bw->current_content->type != CONTENT_HTML) - return; - - box_under_area(bw->current_content->data.html.layout->children, - click_x, click_y, 0, 0, &click_boxes, &found, &plot_index); - - if (found == 0) - return; - - for (i = found - 1; i >= 0; i--) - { - if (click_boxes[i].box->style->visibility == CSS_VISIBILITY_HIDDEN) - continue; - if (click_boxes[i].box->href != NULL) - { - char *url = url_join((char*) click_boxes[i].box->href, - bw->current_content->data.html.base_url); - if (!url) - continue; - - if (click_type == 1) { - browser_window_open_location(bw, url); - } - else if (click_type == 2) - { - struct browser_window* bw_new; - bw_new = create_browser_window(browser_TITLE | browser_TOOLBAR - | browser_SCROLL_X_ALWAYS | browser_SCROLL_Y_ALWAYS, 640, 480 -#ifdef WITH_FRAMES - , NULL -#endif - ); - gui_window_show(bw_new->window); - browser_window_open_location(bw_new, url); - } - else if (click_type == 0) - { - browser_window_set_status(bw, url); - done = 1; - } - free(url); - break; - } - if (click_type == 0 && click_boxes[i].box->title != NULL) - { - browser_window_set_status(bw, click_boxes[i].box->title); - done = 1; - break; - } - } - - if (click_type == 0 && done == 0) { - if (bw->loading_content != 0) - browser_window_set_status(bw, bw->loading_content->status_message); - else - browser_window_set_status(bw, bw->current_content->status_message); - } - - free(click_boxes); - - return; + struct box_selection *click_boxes; + int found, plot_index; + int i; + int done = 0; + + found = 0; + click_boxes = NULL; + plot_index = 0; + + if (bw->current_content->type != CONTENT_HTML) + return; + + box_under_area(bw->current_content->data.html.layout->children, + click_x, click_y, 0, 0, &click_boxes, &found, + &plot_index); + + if (found == 0) + return; + + for (i = found - 1; i >= 0; i--) { + if (click_boxes[i].box->style->visibility == + CSS_VISIBILITY_HIDDEN) + continue; + if (click_boxes[i].box->href != NULL) { + char *url = + url_join((char *) click_boxes[i].box->href, + bw->current_content->data.html. + base_url); + if (!url) + continue; + + if (click_type == 1) { + browser_window_go(bw, url); + } else if (click_type == 2) { + browser_window_create(url); + } else if (click_type == 0) { + browser_window_set_status(bw, url); + done = 1; + } + free(url); + break; + } + if (click_type == 0 && click_boxes[i].box->title != NULL) { + browser_window_set_status(bw, + click_boxes[i].box-> + title); + done = 1; + break; + } + } + + if (click_type == 0 && done == 0) { + if (bw->loading_content != 0) + browser_window_set_status(bw, + bw->loading_content-> + status_message); + else + browser_window_set_status(bw, + bw->current_content-> + status_message); + } + + free(click_boxes); + + return; } -void browser_window_text_selection(struct browser_window* bw, - unsigned long click_x, unsigned long click_y, int click_type) +void browser_window_text_selection(struct browser_window *bw, + unsigned long click_x, + unsigned long click_y, int click_type) { - struct box_selection* click_boxes; - int found, plot_index; - int i; - - if (click_type == 0 /* click_CLEAR_SELECTION */ ) - { - browser_window_clear_text_selection(bw); - return; - } - - found = 0; - click_boxes = NULL; - plot_index = 0; - - assert(bw->current_content->type == CONTENT_HTML); - box_under_area(bw->current_content->data.html.layout->children, - click_x, click_y, 0, 0, &click_boxes, &found, &plot_index); - - if (found == 0) - return; - - for (i = found - 1; i >= 0; i--) - { - if (click_boxes[i].box->type == BOX_INLINE) - { - struct box_position new_pos; - struct box_position* start; - struct box_position* end; - int click_char_offset, click_pixel_offset; - - /* shortcuts */ - start = &(bw->current_content->data.html.text_selection.start); - end = &(bw->current_content->data.html.text_selection.end); - - if (click_boxes[i].box->text && click_boxes[i].box->font) - { - font_position_in_string(click_boxes[i].box->text, - click_boxes[i].box->font, click_boxes[i].box->length, - click_x - click_boxes[i].actual_x, - &click_char_offset, &click_pixel_offset); - } - else - { - click_char_offset = 0; - click_pixel_offset = 0; - } - - new_pos.box = click_boxes[i].box; - new_pos.actual_box_x = click_boxes[i].actual_x; - new_pos.actual_box_y = click_boxes[i].actual_y; - new_pos.plot_index = click_boxes[i].plot_index; - new_pos.char_offset = click_char_offset; - new_pos.pixel_offset = click_pixel_offset; - - if (click_type == 1 /* click_START_SELECTION */ ) - { - /* update both start and end */ - browser_window_clear_text_selection(bw); - bw->current_content->data.html.text_selection.altering = alter_UNKNOWN; - bw->current_content->data.html.text_selection.selected = 1; - memcpy(start, &new_pos, sizeof(struct box_position)); - memcpy(end, &new_pos, sizeof(struct box_position)); - i = -1; - } - else if (bw->current_content->data.html.text_selection.selected == 1 && - click_type == 2 /* click_ALTER_SELECTION */) - { - /* alter selection */ - - if (bw->current_content->data.html.text_selection.altering - != alter_UNKNOWN) - { - if (bw->current_content->data.html.text_selection.altering - == alter_START) - { - if (box_position_gt(&new_pos,end)) - { - bw->current_content->data.html.text_selection.altering - = alter_END; - browser_window_change_text_selection(bw, end, &new_pos); - } - else - browser_window_change_text_selection(bw, &new_pos, end); - } - else - { - if (box_position_lt(&new_pos,start)) - { - bw->current_content->data.html.text_selection.altering - = alter_START; - browser_window_change_text_selection(bw, &new_pos, start); - } - else - browser_window_change_text_selection(bw, start, &new_pos); - } - i = -1; - } - else - { - /* work out whether the start or end is being dragged */ - - int click_start_distance = 0; - int click_end_distance = 0; - - int inside_block = 0; - int before_start = 0; - int after_end = 0; - - if (box_position_lt(&new_pos, start)) - before_start = 1; - - if (box_position_gt(&new_pos, end)) - after_end = 1; - - if (!box_position_lt(&new_pos, start) - && !box_position_gt(&new_pos, end)) - inside_block = 1; - - if (inside_block == 1) - { - click_start_distance = box_position_distance(start, &new_pos); - click_end_distance = box_position_distance(end, &new_pos); - } - - if (before_start == 1 - || (after_end == 0 && inside_block == 1 - && click_start_distance < click_end_distance)) - { - /* alter the start position */ - bw->current_content->data.html.text_selection.altering - = alter_START; - browser_window_change_text_selection(bw, &new_pos, end); - i = -1; - } - else if (after_end == 1 - || (before_start == 0 && inside_block == 1 - && click_start_distance >= click_end_distance)) - { - /* alter the end position */ - bw->current_content->data.html.text_selection.altering = alter_END; - browser_window_change_text_selection(bw, start, &new_pos); - i = -1; - } - } - } - } - } + struct box_selection *click_boxes; + int found, plot_index; + int i; - free(click_boxes); + if (click_type == 0 /* click_CLEAR_SELECTION */ ) { + browser_window_clear_text_selection(bw); + return; + } - return; + found = 0; + click_boxes = NULL; + plot_index = 0; + + assert(bw->current_content->type == CONTENT_HTML); + box_under_area(bw->current_content->data.html.layout->children, + click_x, click_y, 0, 0, &click_boxes, &found, + &plot_index); + + if (found == 0) + return; + + for (i = found - 1; i >= 0; i--) { + if (click_boxes[i].box->type == BOX_INLINE) { + struct box_position new_pos; + struct box_position *start; + struct box_position *end; + int click_char_offset, click_pixel_offset; + + /* shortcuts */ + start = + &(bw->current_content->data.html. + text_selection.start); + end = + &(bw->current_content->data.html. + text_selection.end); + + if (click_boxes[i].box->text + && click_boxes[i].box->font) { + font_position_in_string(click_boxes[i]. + box->text, + click_boxes[i]. + box->font, + click_boxes[i]. + box->length, + click_x - + click_boxes[i]. + actual_x, + &click_char_offset, + &click_pixel_offset); + } else { + click_char_offset = 0; + click_pixel_offset = 0; + } + + new_pos.box = click_boxes[i].box; + new_pos.actual_box_x = click_boxes[i].actual_x; + new_pos.actual_box_y = click_boxes[i].actual_y; + new_pos.plot_index = click_boxes[i].plot_index; + new_pos.char_offset = click_char_offset; + new_pos.pixel_offset = click_pixel_offset; + + if (click_type == 1 /* click_START_SELECTION */ ) { + /* update both start and end */ + browser_window_clear_text_selection(bw); + bw->current_content->data.html. + text_selection.altering = + alter_UNKNOWN; + bw->current_content->data.html. + text_selection.selected = 1; + memcpy(start, &new_pos, + sizeof(struct box_position)); + memcpy(end, &new_pos, + sizeof(struct box_position)); + i = -1; + } else if (bw->current_content->data.html. + text_selection.selected == 1 + && click_type == + 2 /* click_ALTER_SELECTION */ ) { + /* alter selection */ + + if (bw->current_content->data.html. + text_selection.altering != + alter_UNKNOWN) { + if (bw->current_content->data.html. + text_selection.altering == + alter_START) { + if (box_position_gt + (&new_pos, end)) { + bw->current_content->data.html.text_selection.altering = alter_END; + browser_window_change_text_selection + (bw, end, + &new_pos); + } else + browser_window_change_text_selection + (bw, &new_pos, + end); + } else { + if (box_position_lt + (&new_pos, start)) { + bw->current_content->data.html.text_selection.altering = alter_START; + browser_window_change_text_selection + (bw, &new_pos, + start); + } else + browser_window_change_text_selection + (bw, start, + &new_pos); + } + i = -1; + } else { + /* work out whether the start or end is being dragged */ + + int click_start_distance = 0; + int click_end_distance = 0; + + int inside_block = 0; + int before_start = 0; + int after_end = 0; + + if (box_position_lt + (&new_pos, start)) + before_start = 1; + + if (box_position_gt(&new_pos, end)) + after_end = 1; + + if (!box_position_lt + (&new_pos, start) + && !box_position_gt(&new_pos, + end)) + inside_block = 1; + + if (inside_block == 1) { + click_start_distance = + box_position_distance + (start, &new_pos); + click_end_distance = + box_position_distance + (end, &new_pos); + } + + if (before_start == 1 + || (after_end == 0 + && inside_block == 1 + && click_start_distance < + click_end_distance)) { + /* alter the start position */ + bw->current_content->data. + html.text_selection. + altering = alter_START; + browser_window_change_text_selection + (bw, &new_pos, end); + i = -1; + } else if (after_end == 1 + || (before_start == 0 + && inside_block == 1 + && + click_start_distance + >= + click_end_distance)) + { + /* alter the end position */ + bw->current_content->data. + html.text_selection. + altering = alter_END; + browser_window_change_text_selection + (bw, start, &new_pos); + i = -1; + } + } + } + } + } + + free(click_boxes); + + return; } -void browser_window_clear_text_selection(struct browser_window* bw) +void browser_window_clear_text_selection(struct browser_window *bw) { - struct box_position* old_start; - struct box_position* old_end; + struct box_position *old_start; + struct box_position *old_end; - assert(bw->current_content->type == CONTENT_HTML); - old_start = &(bw->current_content->data.html.text_selection.start); - old_end = &(bw->current_content->data.html.text_selection.end); + assert(bw->current_content->type == CONTENT_HTML); + old_start = &(bw->current_content->data.html.text_selection.start); + old_end = &(bw->current_content->data.html.text_selection.end); - if (bw->current_content->data.html.text_selection.selected == 1) - { - bw->current_content->data.html.text_selection.selected = 0; - browser_window_redraw_boxes(bw, old_start, old_end); - } + if (bw->current_content->data.html.text_selection.selected == 1) { + bw->current_content->data.html.text_selection.selected = 0; + browser_window_redraw_boxes(bw, old_start, old_end); + } - bw->current_content->data.html.text_selection.altering = alter_UNKNOWN; + bw->current_content->data.html.text_selection.altering = + alter_UNKNOWN; } -void browser_window_change_text_selection(struct browser_window* bw, - struct box_position* new_start, struct box_position* new_end) +void browser_window_change_text_selection(struct browser_window *bw, + struct box_position *new_start, + struct box_position *new_end) { - struct box_position start; - struct box_position end; - - assert(bw->current_content->type == CONTENT_HTML); - memcpy(&start, &(bw->current_content->data.html.text_selection.start), sizeof(struct box_position)); - memcpy(&end, &(bw->current_content->data.html.text_selection.end), sizeof(struct box_position)); - - if (!box_position_eq(new_start, &start)) - { - if (box_position_lt(new_start, &start)) - browser_window_redraw_boxes(bw, new_start, &start); - else - browser_window_redraw_boxes(bw, &start, new_start); - memcpy(&start, new_start, sizeof(struct box_position)); - } - - if (!box_position_eq(new_end, &end)) - { - if (box_position_lt(new_end, &end)) - browser_window_redraw_boxes(bw, new_end, &end); - else - browser_window_redraw_boxes(bw, &end, new_end); - memcpy(&end, new_end, sizeof(struct box_position)); - } - - memcpy(&(bw->current_content->data.html.text_selection.start), &start, sizeof(struct box_position)); - memcpy(&(bw->current_content->data.html.text_selection.end), &end, sizeof(struct box_position)); - - bw->current_content->data.html.text_selection.selected = 1; + struct box_position start; + struct box_position end; + + assert(bw->current_content->type == CONTENT_HTML); + memcpy(&start, + &(bw->current_content->data.html.text_selection.start), + sizeof(struct box_position)); + memcpy(&end, &(bw->current_content->data.html.text_selection.end), + sizeof(struct box_position)); + + if (!box_position_eq(new_start, &start)) { + if (box_position_lt(new_start, &start)) + browser_window_redraw_boxes(bw, new_start, &start); + else + browser_window_redraw_boxes(bw, &start, new_start); + memcpy(&start, new_start, sizeof(struct box_position)); + } + + if (!box_position_eq(new_end, &end)) { + if (box_position_lt(new_end, &end)) + browser_window_redraw_boxes(bw, new_end, &end); + else + browser_window_redraw_boxes(bw, &end, new_end); + memcpy(&end, new_end, sizeof(struct box_position)); + } + + memcpy(&(bw->current_content->data.html.text_selection.start), + &start, sizeof(struct box_position)); + memcpy(&(bw->current_content->data.html.text_selection.end), &end, + sizeof(struct box_position)); + + bw->current_content->data.html.text_selection.selected = 1; } -int box_position_lt(struct box_position* x, struct box_position* y) +int box_position_lt(struct box_position *x, struct box_position *y) { - return (x->plot_index < y->plot_index || - (x->plot_index == y->plot_index && x->char_offset < y->char_offset)); + return (x->plot_index < y->plot_index || + (x->plot_index == y->plot_index + && x->char_offset < y->char_offset)); } -int box_position_gt(struct box_position* x, struct box_position* y) +int box_position_gt(struct box_position *x, struct box_position *y) { - return (x->plot_index > y->plot_index || - (x->plot_index == y->plot_index && x->char_offset > y->char_offset)); + return (x->plot_index > y->plot_index || + (x->plot_index == y->plot_index + && x->char_offset > y->char_offset)); } -int box_position_eq(struct box_position* x, struct box_position* y) +int box_position_eq(struct box_position *x, struct box_position *y) { - return (x->plot_index == y->plot_index && x->char_offset == y->char_offset); + return (x->plot_index == y->plot_index + && x->char_offset == y->char_offset); } -int box_position_distance(struct box_position* x, struct box_position* y) +int box_position_distance(struct box_position *x, struct box_position *y) { - int dx = (y->actual_box_x + y->pixel_offset) - - (x->actual_box_x + x->pixel_offset); - int dy = (y->actual_box_y + y->box->height / 2) - - (x->actual_box_y + x->box->height / 2); - return dx*dx + dy*dy; + int dx = (y->actual_box_x + y->pixel_offset) + - (x->actual_box_x + x->pixel_offset); + int dy = (y->actual_box_y + y->box->height / 2) + - (x->actual_box_y + x->box->height / 2); + return dx * dx + dy * dy; } unsigned long redraw_min_x = LONG_MAX; @@ -1588,74 +1639,77 @@ unsigned long redraw_min_y = LONG_MAX; unsigned long redraw_max_x = 0; unsigned long redraw_max_y = 0; -int redraw_box_list(struct browser_window* bw, struct box* current, - unsigned long x, unsigned long y, struct box_position* start, - struct box_position* end, int* plot) +int redraw_box_list(struct browser_window *bw, struct box *current, + unsigned long x, unsigned long y, + struct box_position *start, struct box_position *end, + int *plot) { - struct box* c; - - if (current == start->box) - *plot = 1; - - if (*plot >= 1 && current->type == BOX_INLINE) - { - unsigned long minx = x + current->x; - unsigned long miny = y + current->y; - unsigned long maxx = x + current->x + current->width; - unsigned long maxy = y + current->y + current->height; - - if (minx < redraw_min_x) - redraw_min_x = minx; - if (miny < redraw_min_y) - redraw_min_y = miny; - if (maxx > redraw_max_x) - redraw_max_x = maxx; - if (maxy > redraw_max_y) - redraw_max_y = maxy; - - *plot = 2; - } - - if (current == end->box) - return 1; - - for (c = current->children; c != 0; c = c->next) - if (c->type != BOX_FLOAT_LEFT && c->type != BOX_FLOAT_RIGHT) - if (redraw_box_list(bw, c, x + current->x, y + current->y, - start, end, plot) == 1) - return 1; - - for (c = current->float_children; c != 0; c = c->next_float) - if (redraw_box_list(bw, c, x + current->x, y + current->y, - start, end, plot) == 1) - return 1; - - return 0; + struct box *c; + + if (current == start->box) + *plot = 1; + + if (*plot >= 1 && current->type == BOX_INLINE) { + unsigned long minx = x + current->x; + unsigned long miny = y + current->y; + unsigned long maxx = x + current->x + current->width; + unsigned long maxy = y + current->y + current->height; + + if (minx < redraw_min_x) + redraw_min_x = minx; + if (miny < redraw_min_y) + redraw_min_y = miny; + if (maxx > redraw_max_x) + redraw_max_x = maxx; + if (maxy > redraw_max_y) + redraw_max_y = maxy; + + *plot = 2; + } + + if (current == end->box) + return 1; + + for (c = current->children; c != 0; c = c->next) + if (c->type != BOX_FLOAT_LEFT + && c->type != BOX_FLOAT_RIGHT) + if (redraw_box_list + (bw, c, x + current->x, y + current->y, start, + end, plot) == 1) + return 1; + + for (c = current->float_children; c != 0; c = c->next_float) + if (redraw_box_list(bw, c, x + current->x, y + current->y, + start, end, plot) == 1) + return 1; + + return 0; } -void browser_window_redraw_boxes(struct browser_window* bw, struct box_position* start, struct box_position* end) +void browser_window_redraw_boxes(struct browser_window *bw, + struct box_position *start, + struct box_position *end) { - int plot = 0; + int plot = 0; - assert(bw->current_content->type == CONTENT_HTML); - if (box_position_eq(start, end)) - return; + assert(bw->current_content->type == CONTENT_HTML); + if (box_position_eq(start, end)) + return; - redraw_min_x = LONG_MAX; - redraw_min_y = LONG_MAX; - redraw_max_x = 0; - redraw_max_y = 0; + redraw_min_x = LONG_MAX; + redraw_min_y = LONG_MAX; + redraw_max_x = 0; + redraw_max_y = 0; - redraw_box_list(bw, bw->current_content->data.html.layout, - 0,0, start, end, &plot); + redraw_box_list(bw, bw->current_content->data.html.layout, + 0, 0, start, end, &plot); - if (plot == 2) - gui_window_redraw(bw->window, redraw_min_x, redraw_min_y, - redraw_max_x, redraw_max_y); + if (plot == 2) + gui_window_redraw(bw->window, redraw_min_x, redraw_min_y, + redraw_max_x, redraw_max_y); } - /** * Collect controls and submit a form. */ @@ -1685,26 +1739,22 @@ void browser_form_submit(struct browser_window *bw, struct form *form, url1 = url_join(url, base); if (!url1) break; - browser_window_open_location(bw, url1); + browser_window_go(bw, url1); break; -#ifdef WITH_POST + case method_POST_URLENC: data = form_url_encode(success); url = url_join(form->action, base); if (!url) break; - browser_window_open_location_post(bw, url, data, 0); + browser_window_go_post(bw, url, data, 0, true); break; case method_POST_MULTIPART: url = url_join(form->action, base); - browser_window_open_location_post(bw, url, 0, success); + browser_window_go_post(bw, url, 0, success, true); break; -#else - case method_POST_URLENC: - case method_POST_MULTIPART: - break; -#endif + default: assert(0); } diff --git a/desktop/browser.h b/desktop/browser.h index ead88eb82..3f2bae61a 100644 --- a/desktop/browser.h +++ b/desktop/browser.h @@ -3,7 +3,11 @@ * Licensed under the GNU General Public License, * http://www.opensource.org/licenses/gpl-license * Copyright 2003 Phil Mellor - * Copyright 2003 James Bursa + * Copyright 2004 James Bursa + */ + +/** \file + * Browser window creation and manipulation (interface). */ #ifndef _NETSURF_DESKTOP_BROWSER_H_ @@ -14,47 +18,39 @@ #include "netsurf/utils/config.h" #include "netsurf/content/content.h" #include "netsurf/desktop/gui.h" -#include "netsurf/render/box.h" - -typedef int browser_window_flags; -#define browser_TOOLBAR ((browser_window_flags) 1) -#define browser_TITLE ((browser_window_flags) 2) -#define browser_SCROLL_X_NONE ((browser_window_flags) 4) -#define browser_SCROLL_X_AUTO ((browser_window_flags) 8) -#define browser_SCROLL_X_ALWAYS ((browser_window_flags) 16) -#define browser_SCROLL_Y_NONE ((browser_window_flags) 32) -#define browser_SCROLL_Y_AUTO ((browser_window_flags) 64) -#define browser_SCROLL_Y_ALWAYS ((browser_window_flags) 128) - -typedef int action_buttons; -#define act_BUTTON_NORMAL ((action_buttons) 4) -#define act_BUTTON_ALTERNATIVE ((action_buttons) 1) -#define act_BUTTON_CONTEXT_MENU ((action_buttons) 2) -struct history_entry; +struct box; +struct history; +/** Browser window data. */ struct browser_window { - unsigned long format_width; - unsigned long format_height; - struct { int mult; int div; } scale; + /** Page currently displayed, or 0. Must have status READY or DONE. */ + struct content *current_content; + /** Instance state pointer for current_content. */ + void *current_content_state; + /** Page being loaded, or 0. */ + struct content *loading_content; - struct content* current_content; - void *current_content_state; - struct content* loading_content; - struct history_entry *history_entry; - bool history_add; - clock_t time0; + /** Window history structure. */ + struct history *history; - char* url; + /** Handler for keyboard input, or 0. */ + void (*caret_callback)(struct browser_window *bw, char key, void *p); + /** User parameter for caret_callback. */ + void *caret_p; - browser_window_flags flags; - gui_window* window; + /** Platform specific window handle. */ + gui_window *window; + + /** Busy indicator is active. */ + bool throbbing; + /** Add loading_content to the window history when it loads. */ + bool history_add; + /** Start time of fetching loading_content. */ + clock_t time0; - int throbbing; - void (*caret_callback)(struct browser_window *bw, char key, void *p); - void *caret_p; #ifdef WITH_FRAMES struct browser_window *parent; unsigned int no_children; @@ -75,7 +71,6 @@ struct browser_action struct { unsigned long x; unsigned long y; - action_buttons buttons; } mouse; struct { struct form_control* g; @@ -92,32 +87,21 @@ struct box_selection int plot_index; }; -/* public functions */ -struct browser_window* create_browser_window(int flags, int width, int height -#ifdef WITH_FRAMES -, struct browser_window *parent -#endif -); -void browser_window_destroy(struct browser_window* bw -#ifdef WITH_FRAMES -, bool self -#endif -); -void browser_window_open_location(struct browser_window* bw, const char* url); -void browser_window_open_location_historical(struct browser_window* bw, - const char* url -#ifdef WITH_POST - , char *post_urlenc, - struct form_successful_control *post_multipart -#endif - ); -int browser_window_action(struct browser_window* bw, struct browser_action* act); -void browser_window_set_status(struct browser_window* bw, const char* text); +void browser_window_create(const char *url); +void browser_window_go(struct browser_window *bw, const char *url); +void browser_window_go_post(struct browser_window *bw, const char *url, + char *post_urlenc, + struct form_successful_control *post_multipart, + bool history_add); +void browser_window_stop(struct browser_window *bw); +void browser_window_destroy(struct browser_window *bw); void browser_window_back(struct browser_window* bw); void browser_window_forward(struct browser_window* bw); +int browser_window_action(struct browser_window* bw, struct browser_action* act); + void box_under_area(struct box* box, unsigned long x, unsigned long y, unsigned long ox, unsigned long oy, struct box_selection** found, int* count, int* plot_index); @@ -128,12 +112,12 @@ int box_position_distance(struct box_position* x, struct box_position* y); void gui_redraw_gadget(struct browser_window* bw, struct form_control* g); -void browser_window_stop_throbber(struct browser_window* bw); -void browser_window_reformat(struct browser_window* bw, int scroll_to_top); - bool browser_window_key_press(struct browser_window *bw, char key); -struct history_entry * history_add(struct history_entry *current, - char *url, char *title); +/* In platform specific history.c. */ +struct history *history_create(void); +void history_add(struct history *history, struct content *content); +void history_update(struct history *history, struct content *content); +void history_destroy(struct history *history); #endif diff --git a/desktop/gui.h b/desktop/gui.h index 61b3088b5..3554a87ee 100644 --- a/desktop/gui.h +++ b/desktop/gui.h @@ -3,15 +3,16 @@ * Licensed under the GNU General Public License, * http://www.opensource.org/licenses/gpl-license * Copyright 2003 Phil Mellor - * Copyright 2003 James Bursa + * Copyright 2004 James Bursa + */ + +/** \file + * Interface to platform-specific gui functions. */ #ifndef _NETSURF_DESKTOP_GUI_H_ #define _NETSURF_DESKTOP_GUI_H_ -typedef enum { GUI_BROWSER_WINDOW, GUI_DOWNLOAD_WINDOW } gui_window_type; -typedef enum { SAFE, UNSAFE } gui_safety; - struct gui_window; typedef struct gui_window gui_window; @@ -43,8 +44,6 @@ void gui_multitask(void); void gui_poll(bool active); void gui_quit(void); -gui_safety gui_window_set_redraw_safety(gui_window* g, gui_safety s); - void gui_window_start_throbber(gui_window* g); void gui_window_stop_throbber(gui_window* g); @@ -52,4 +51,6 @@ void gui_gadget_combo(struct browser_window* bw, struct form_control* g, unsigne void gui_window_place_caret(gui_window *g, int x, int y, int height); +void warn_user(const char *warning); + #endif -- cgit v1.2.3