From 77de9c13364ab754a5490156afe26e56882f728b Mon Sep 17 00:00:00 2001 From: John Mark Bell Date: Mon, 3 Jan 2005 02:09:20 +0000 Subject: [project @ 2005-01-03 02:09:20 by jmb] Shift + Click == download svn path=/import/netsurf/; revision=1429 --- content/content.c | 1 + content/content.h | 1 + content/fetchcache.c | 12 +++++++--- content/fetchcache.h | 3 ++- css/css.c | 4 ++-- debug/netsurfd.c | 2 +- desktop/browser.c | 67 +++++++++++++++++++++++++++++++++------------------- desktop/browser.h | 9 +++++-- gtk/gtk_window.c | 2 +- render/html.c | 12 +++++----- riscos/401login.c | 4 ++-- riscos/gui.c | 2 +- riscos/history.c | 2 +- riscos/menus.c | 4 ++-- riscos/plugin.c | 3 ++- riscos/window.c | 19 ++++++++++----- 16 files changed, 94 insertions(+), 53 deletions(-) diff --git a/content/content.c b/content/content.c index 7dd85a668..7bade8760 100644 --- a/content/content.c +++ b/content/content.c @@ -279,6 +279,7 @@ struct content * content_create(const char *url) c->source_size = 0; c->total_size = 0; c->no_error_pages = false; + c->download = false; c->error_count = 0; c->prev = 0; diff --git a/content/content.h b/content/content.h index da565c711..387fc7a37 100644 --- a/content/content.h +++ b/content/content.h @@ -242,6 +242,7 @@ struct content { unsigned long total_size; /**< Total data size, 0 if unknown. */ bool no_error_pages; /**< Used by fetchcache(). */ + bool download; /**< Used by fetchcache(). */ /** Array of first n rendering errors or warnings. */ struct { diff --git a/content/fetchcache.c b/content/fetchcache.c index 81c608b9e..32e201081 100644 --- a/content/fetchcache.c +++ b/content/fetchcache.c @@ -53,6 +53,7 @@ static void fetchcache_error_page(struct content *c, const char *error); * \param post_urlenc url encoded post data, or 0 if none * \param post_multipart multipart post data, or 0 if none * \param cookies send and accept cookies + * \param download download, rather than render content * \return a new content, or 0 on memory exhaustion * * On success, call fetchcache_go() to start work on the new content. @@ -66,7 +67,8 @@ struct content * fetchcache(const char *url, bool no_error_pages, char *post_urlenc, struct form_successful_control *post_multipart, - bool cookies) + bool cookies, + bool download) { struct content *c; char *url1; @@ -105,6 +107,7 @@ struct content * fetchcache(const char *url, c->width = width; c->height = height; c->no_error_pages = no_error_pages; + c->download = download; return c; } @@ -223,8 +226,11 @@ void fetchcache_callback(fetch_msg msg, void *p, const char *data, return; } type = content_lookup(mime_type); - LOG(("FETCH_TYPE, type %u", type)); - res = content_set_type(c, type, mime_type, params); + LOG(("FETCH_TYPE, type %u", c->download ? + CONTENT_OTHER : type)); + res = content_set_type(c, + c->download ? CONTENT_OTHER : type, + mime_type, params); free(mime_type); for (i = 0; params[i]; i++) free(params[i]); diff --git a/content/fetchcache.h b/content/fetchcache.h index f20ab6cf9..68fe3fd7f 100644 --- a/content/fetchcache.h +++ b/content/fetchcache.h @@ -29,7 +29,8 @@ struct content * fetchcache(const char *url, bool no_error_pages, char *post_urlenc, struct form_successful_control *post_multipart, - bool cookies); + bool cookies, + bool download); void fetchcache_go(struct content *content, char *referer, void (*callback)(content_msg msg, struct content *c, void *p1, void *p2, union content_msg_data data), diff --git a/css/css.c b/css/css.c index 844f4af49..a4bb10f47 100644 --- a/css/css.c +++ b/css/css.c @@ -681,7 +681,7 @@ void css_atimport(struct content *c, struct css_node *node) c->data.css.import_url[i] = url1; c->data.css.import_content[i] = fetchcache(c->data.css.import_url[i], css_atimport_callback, c, (void *) i, - c->width, c->height, true, 0, 0, false); + c->width, c->height, true, 0, 0, false, false); if (c->data.css.import_content[i]) { c->active++; fetchcache_go(c->data.css.import_content[i], c->url, @@ -743,7 +743,7 @@ void css_atimport_callback(content_msg msg, struct content *css, c->data.css.import_url[i], css_atimport_callback, c, (void *) i, css->width, css->height, true, 0, 0, - false); + false, false); if (c->data.css.import_content[i]) { c->active++; fetchcache_go(c->data.css.import_content[i], diff --git a/debug/netsurfd.c b/debug/netsurfd.c index 3a98221b3..b5b72efde 100644 --- a/debug/netsurfd.c +++ b/debug/netsurfd.c @@ -73,7 +73,7 @@ int main(int argc, char *argv[]) url[strlen(url) - 1] = 0; destroyed = 0; c = fetchcache(url, callback, 0, 0, 1000, 1000, false, - 0, 0, true); + 0, 0, true, false); if (c) { fetchcache_go(c, 0, callback, 0, 0, 0, 0, true); done = c->status == CONTENT_STATUS_DONE; diff --git a/desktop/browser.c b/desktop/browser.c index dbab40852..734fde5ae 100644 --- a/desktop/browser.c +++ b/desktop/browser.c @@ -88,9 +88,9 @@ static void browser_form_submit(struct browser_window *bw, struct form *form, /** * Create and open a new browser window with the given page. * - * \param url URL to start fetching in the new window (copied) - * \param clone The browser window to clone - * \param referer The referring uri + * \param url URL to start fetching in the new window (copied) + * \param clone The browser window to clone + * \param referer The referring uri */ void browser_window_create(const char *url, struct browser_window *clone, @@ -112,28 +112,30 @@ void browser_window_create(const char *url, struct browser_window *clone, bw->drag_type = DRAGGING_NONE; bw->scrolling_box = NULL; bw->referer = NULL; + bw->download = false; if ((bw->window = gui_create_browser_window(bw, clone)) == NULL) { free(bw); return; } - browser_window_go(bw, url, referer); + browser_window_go(bw, url, referer, false); } /** * Start fetching a page in a browser window. * - * \param bw browser window - * \param url URL to start fetching (copied) - * \param referer the referring uri + * \param bw browser window + * \param url URL to start fetching (copied) + * \param referer the referring uri + * \param download download, rather than render the uri * * Any existing fetches in the window are aborted. */ void browser_window_go(struct browser_window *bw, const char *url, - char* referer) + char* referer, bool download) { - browser_window_go_post(bw, url, 0, 0, true, referer); + browser_window_go_post(bw, url, 0, 0, true, referer, download); } @@ -146,6 +148,7 @@ void browser_window_go(struct browser_window *bw, const char *url, * \param post_multipart multipart post data, or 0 if none * \param history_add add to window history * \param referer the referring uri + * \param download download, rather than render the uri * * Any existing fetches in the window are aborted. * @@ -158,7 +161,7 @@ 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, char *referer) + bool history_add, char *referer, bool download) { struct content *c; char *url2; @@ -198,7 +201,7 @@ void browser_window_go_post(struct browser_window *bw, const char *url, c = fetchcache(url2, browser_window_callback, bw, 0, gui_window_get_width(bw->window), 0, false, - post_urlenc, post_multipart, true); + post_urlenc, post_multipart, true, download); free(url2); if (!c) { browser_window_set_status(bw, messages_get("NoMemory")); @@ -214,6 +217,8 @@ void browser_window_go_post(struct browser_window *bw, const char *url, bw->referer = strdup(referer); } + bw->download = download; + fetchcache_go(c, option_send_referer ? referer : 0, browser_window_callback, bw, 0, post_urlenc, post_multipart, true); @@ -307,7 +312,8 @@ void browser_window_callback(content_msg msg, struct content *c, /* the spec says nothing about referrers and * redirects => follow Mozilla and preserve the * referer across the redirect */ - browser_window_go(bw, data.redirect, bw->referer); + browser_window_go(bw, data.redirect, bw->referer, + bw->download); break; case CONTENT_MSG_REFORMAT: @@ -505,7 +511,8 @@ void browser_window_reload(struct browser_window *bw, bool all) } } bw->current_content->fresh = false; - browser_window_go_post(bw, bw->current_content->url, 0, 0, false, 0); + browser_window_go_post(bw, bw->current_content->url, 0, 0, + false, 0, false); } @@ -719,23 +726,27 @@ void browser_window_mouse_click_html(struct browser_window *bw, case GADGET_SELECT: status = messages_get("FormSelect"); pointer = GUI_POINTER_MENU; - if (click == BROWSER_MOUSE_CLICK_1) + if (click == BROWSER_MOUSE_CLICK_1 || + click == BROWSER_MOUSE_CLICK_1_MOD) gui_create_form_select_menu(bw, gadget); break; case GADGET_CHECKBOX: status = messages_get("FormCheckbox"); - if (click == BROWSER_MOUSE_CLICK_1) { + if (click == BROWSER_MOUSE_CLICK_1 || + click == BROWSER_MOUSE_CLICK_1_MOD) { gadget->selected = !gadget->selected; browser_redraw_box(gadget_content, gadget_box); } break; case GADGET_RADIO: status = messages_get("FormRadio"); - if (click == BROWSER_MOUSE_CLICK_1) + if (click == BROWSER_MOUSE_CLICK_1 || + click == BROWSER_MOUSE_CLICK_1_MOD) browser_radio_set(gadget_content, gadget); break; case GADGET_IMAGE: - if (click == BROWSER_MOUSE_CLICK_1) { + if (click == BROWSER_MOUSE_CLICK_1 || + click == BROWSER_MOUSE_CLICK_1_MOD) { gadget->data.image.mx = x - gadget_box_x; gadget->data.image.my = y - gadget_box_y; } @@ -750,7 +761,8 @@ void browser_window_mouse_click_html(struct browser_window *bw, gadget->form->action); status = status_buffer; pointer = GUI_POINTER_POINT; - if (click == BROWSER_MOUSE_CLICK_1) + if (click == BROWSER_MOUSE_CLICK_1 || + click == BROWSER_MOUSE_CLICK_1_MOD) browser_form_submit(bw, gadget->form, gadget); } else { @@ -760,7 +772,8 @@ void browser_window_mouse_click_html(struct browser_window *bw, case GADGET_TEXTAREA: status = messages_get("FormTextarea"); pointer = GUI_POINTER_CARET; - if (click == BROWSER_MOUSE_CLICK_1) + if (click == BROWSER_MOUSE_CLICK_1 || + click == BROWSER_MOUSE_CLICK_1_MOD) browser_window_textarea_click(bw, gadget_box, gadget_box_x, @@ -772,7 +785,8 @@ void browser_window_mouse_click_html(struct browser_window *bw, case GADGET_PASSWORD: status = messages_get("FormTextbox"); pointer = GUI_POINTER_CARET; - if (click == BROWSER_MOUSE_CLICK_1) + if (click == BROWSER_MOUSE_CLICK_1 || + click == BROWSER_MOUSE_CLICK_1_MOD) browser_window_input_click(bw, gadget_box, gadget_box_x, @@ -806,11 +820,15 @@ void browser_window_mouse_click_html(struct browser_window *bw, pointer = GUI_POINTER_POINT; if (click == BROWSER_MOUSE_CLICK_1) { - browser_window_go(bw, url, c->url); + browser_window_go(bw, url, c->url, false); } else if (click == BROWSER_MOUSE_CLICK_2) { browser_window_create(url, bw, c->url); } + else if (click == BROWSER_MOUSE_CLICK_1_MOD || + click == BROWSER_MOUSE_CLICK_2_MOD) { + browser_window_go(bw, url, c->url, true); + } } else if (title) { status = title; @@ -1942,7 +1960,8 @@ void browser_form_submit(struct browser_window *bw, struct form *form, res = url_join(url, base, &url1); if (res != URL_FUNC_OK) break; - browser_window_go(bw, url1, bw->current_content->url); + browser_window_go(bw, url1, + bw->current_content->url, false); break; case method_POST_URLENC: @@ -1956,7 +1975,7 @@ void browser_form_submit(struct browser_window *bw, struct form *form, if (res != URL_FUNC_OK) break; browser_window_go_post(bw, url, data, 0, true, - bw->current_content->url); + bw->current_content->url, false); break; case method_POST_MULTIPART: @@ -1964,7 +1983,7 @@ void browser_form_submit(struct browser_window *bw, struct form *form, if (res != URL_FUNC_OK) break; browser_window_go_post(bw, url, 0, success, true, - bw->current_content->url); + bw->current_content->url, false); break; default: diff --git a/desktop/browser.h b/desktop/browser.h index 750cf329b..2a2776411 100644 --- a/desktop/browser.h +++ b/desktop/browser.h @@ -70,6 +70,9 @@ struct browser_window { /** Referer for current fetch, or 0. */ char *referer; + + /** Current fetch is download */ + bool download; }; @@ -78,17 +81,19 @@ typedef enum { BROWSER_MOUSE_CLICK_2, BROWSER_MOUSE_HOVER, BROWSER_MOUSE_DRAG, /**< CLICK is continuing as a drag. */ + BROWSER_MOUSE_CLICK_1_MOD, + BROWSER_MOUSE_CLICK_2_MOD, } browser_mouse_click; void browser_window_create(const char *url, struct browser_window *clone, char *referer); void browser_window_go(struct browser_window *bw, const char *url, - char *referer); + char *referer, bool download); void browser_window_go_post(struct browser_window *bw, const char *url, char *post_urlenc, struct form_successful_control *post_multipart, - bool history_add, char *referer); + bool history_add, char *referer, bool download); void browser_window_stop(struct browser_window *bw); void browser_window_reload(struct browser_window *bw, bool all); void browser_window_destroy(struct browser_window *bw); diff --git a/gtk/gtk_window.c b/gtk/gtk_window.c index 3a8081b3e..ced6ac6bd 100644 --- a/gtk/gtk_window.c +++ b/gtk/gtk_window.c @@ -210,7 +210,7 @@ gboolean gui_window_url_key_press_event(GtkWidget *widget, referer = g->bw->current_content->url; browser_window_go(g->bw, gtk_entry_get_text(GTK_ENTRY(g->url_bar)), - referer); + referer, false); return TRUE; } diff --git a/render/html.c b/render/html.c index 6d934e22e..068260d3d 100644 --- a/render/html.c +++ b/render/html.c @@ -439,7 +439,7 @@ bool html_find_stylesheets(struct content *c, xmlNode *head) default_stylesheet_url, html_convert_css_callback, c, (void *) STYLESHEET_BASE, c->width, c->height, - true, 0, 0, false); + true, 0, 0, false, false); if (!c->data.html.stylesheet_content[STYLESHEET_BASE]) return false; c->active++; @@ -452,7 +452,7 @@ bool html_find_stylesheets(struct content *c, xmlNode *head) fetchcache(adblock_stylesheet_url, html_convert_css_callback, c, (void *) STYLESHEET_ADBLOCK, c->width, - c->height, true, 0, 0, false); + c->height, true, 0, 0, false, false); if (!c->data.html.stylesheet_content[STYLESHEET_ADBLOCK]) return false; c->active++; @@ -520,7 +520,7 @@ bool html_find_stylesheets(struct content *c, xmlNode *head) c->data.html.stylesheet_content[i] = fetchcache(url, html_convert_css_callback, c, (void *) i, c->width, c->height, - true, 0, 0, false); + true, 0, 0, false, false); if (!c->data.html.stylesheet_content[i]) return false; c->active++; @@ -675,7 +675,7 @@ void html_convert_css_callback(content_msg msg, struct content *css, data.redirect, html_convert_css_callback, c, (void *) i, css->width, css->height, - true, 0, 0, false); + true, 0, 0, false, false); if (c->data.html.stylesheet_content[i]) { c->active++; fetchcache_go(c->data.html.stylesheet_content[i], @@ -741,7 +741,7 @@ bool html_fetch_object(struct content *c, char *url, struct box *box, /* start fetch */ c->data.html.object[i].content = fetchcache(url, html_object_callback, c, (void *) i, available_width, available_height, - true, 0, 0, false); + true, 0, 0, false, false); if (!c->data.html.object[i].content) return false; c->active++; @@ -830,7 +830,7 @@ void html_object_callback(content_msg msg, struct content *object, data.redirect, html_object_callback, c, (void * ) i, 0, 0, true, - 0, 0, false); + 0, 0, false, false); if (!c->data.html.object[i].content) { /** \todo report oom */ } else { diff --git a/riscos/401login.c b/riscos/401login.c index 4f68d463d..449864638 100644 --- a/riscos/401login.c +++ b/riscos/401login.c @@ -103,7 +103,7 @@ bool ro_gui_401login_keypress(wimp_key *key) case wimp_KEY_RETURN: get_unamepwd(); ro_gui_dialog_close(dialog_401li); - browser_window_go(bwin, url, 0); + browser_window_go(bwin, url, 0, false); return true; } @@ -122,7 +122,7 @@ void ro_gui_401login_click(wimp_pointer *pointer) case ICON_401LOGIN_LOGIN: get_unamepwd(); ro_gui_dialog_close(dialog_401li); - browser_window_go(bwin, url, 0); + browser_window_go(bwin, url, 0, false); break; case ICON_401LOGIN_CANCEL: ro_gui_dialog_close(dialog_401li); diff --git a/riscos/gui.c b/riscos/gui.c index 4b5856efb..8ef2d561f 100644 --- a/riscos/gui.c +++ b/riscos/gui.c @@ -1179,7 +1179,7 @@ void ro_msg_dataload(wimp_message *message) return; if (g) { - browser_window_go(g->bw, url, 0); + browser_window_go(g->bw, url, 0, false); } else { if ((hotlist_tree) && ((wimp_w)hotlist_tree->handle == message->data.data_xfer.w)) { diff --git a/riscos/history.c b/riscos/history.c index 7901ed3ae..ebd4e7def 100644 --- a/riscos/history.c +++ b/riscos/history.c @@ -675,7 +675,7 @@ void history_go(struct browser_window *bw, struct history_entry *entry) else url = entry->url; - browser_window_go_post(bw, url, 0, 0, false, 0); + browser_window_go_post(bw, url, 0, 0, false, 0, false); if (entry->frag_id) free(url); diff --git a/riscos/menus.c b/riscos/menus.c index 4ca41b989..8c27d38bb 100644 --- a/riscos/menus.c +++ b/riscos/menus.c @@ -952,12 +952,12 @@ void ro_gui_menu_selection(wimp_selection *selection) case 0: /* Home */ if (option_homepage_url && option_homepage_url[0]) { browser_window_go_post(current_gui->bw, option_homepage_url, - 0, 0, true, 0); + 0, 0, true, 0, false); } else { snprintf(url, sizeof url, "file://Docs/intro_%s", option_language); - browser_window_go_post(current_gui->bw, url, 0, 0, true, 0); + browser_window_go_post(current_gui->bw, url, 0, 0, true, 0, false); } break; case 1: /* Back */ diff --git a/riscos/plugin.c b/riscos/plugin.c index 03692c262..ec35d20d1 100644 --- a/riscos/plugin.c +++ b/riscos/plugin.c @@ -800,7 +800,8 @@ void plugin_url_access(wimp_message *message) strcasecmp(window, "_parent") == 0 || strcasecmp(window, "_top") == 0 || strcasecmp(window, "") == 0) { - browser_window_go(c->data.plugin.bw, url, 0); + browser_window_go(c->data.plugin.bw, url, + 0, false); } else if (strcasecmp(window, "_blank") == 0) { browser_window_create(url, NULL, 0); diff --git a/riscos/window.c b/riscos/window.c index 7054cacf6..0f9dfbe6c 100644 --- a/riscos/window.c +++ b/riscos/window.c @@ -19,6 +19,7 @@ #include #include #include "oslib/colourtrans.h" +#include "oslib/osbyte.h" #include "oslib/osspriteop.h" #include "oslib/wimp.h" #include "oslib/wimpspriteop.h" @@ -1142,7 +1143,7 @@ void ro_gui_toolbar_click(struct gui_window *g, wimp_pointer *pointer) if (option_homepage_url && option_homepage_url[0]) { if (pointer->buttons == wimp_CLICK_SELECT) { browser_window_go_post(g->bw, option_homepage_url, - 0, 0, true, 0); + 0, 0, true, 0, false); } else { browser_window_create(option_homepage_url, NULL, 0); } @@ -1151,7 +1152,7 @@ void ro_gui_toolbar_click(struct gui_window *g, wimp_pointer *pointer) "file://Docs/intro_%s", option_language); if (pointer->buttons == wimp_CLICK_SELECT) { - browser_window_go_post(g->bw, url, 0, 0, true, 0); + browser_window_go_post(g->bw, url, 0, 0, true, 0, false); } else { browser_window_create(url, NULL, 0); } @@ -1239,12 +1240,14 @@ void ro_gui_status_click(struct gui_window *g, wimp_pointer *pointer) void ro_gui_window_click(struct gui_window *g, wimp_pointer *pointer) { - int x, y; + int x, y, shift; wimp_window_state state; os_error *error; assert(g); + xosbyte1(osbyte_SCAN_KEYBOARD, 0 ^ 0x80, 0, &shift); + state.w = pointer->w; error = xwimp_get_window_state(&state); if (error) { @@ -1274,9 +1277,13 @@ void ro_gui_window_click(struct gui_window *g, wimp_pointer *pointer) ro_gui_create_menu(browser_menu, pointer->pos.x, pointer->pos.y, g); else if (pointer->buttons == wimp_CLICK_SELECT) - browser_window_mouse_click(g->bw, BROWSER_MOUSE_CLICK_1, x, y); + browser_window_mouse_click(g->bw, + (shift == 0xff) ? BROWSER_MOUSE_CLICK_1_MOD + : BROWSER_MOUSE_CLICK_1, x, y); else if (pointer->buttons == wimp_CLICK_ADJUST) - browser_window_mouse_click(g->bw, BROWSER_MOUSE_CLICK_2, x, y); + browser_window_mouse_click(g->bw, + (shift == 0xff) ? BROWSER_MOUSE_CLICK_2_MOD + : BROWSER_MOUSE_CLICK_2, x, y); } @@ -1511,7 +1518,7 @@ bool ro_gui_window_keypress(struct gui_window *g, int key, bool toolbar) res = url_normalize(toolbar_url, &url); if (res == URL_FUNC_OK) { gui_window_set_url(g, url); - browser_window_go(g->bw, url, 0); + browser_window_go(g->bw, url, 0, false); free(url); } return true; -- cgit v1.2.3