Move tab opening logic to same place as new window opening. Make option for "Tabbed browsing", which is enabled by default. Someone who knows how to work glade could add the "Tabbed browsing" option to the choices dialogue. When a link is opened in a new tab, don't change tab.

svn path=/trunk/netsurf/; revision=5816
This commit is contained in:
Michael Drake 2008-11-29 00:24:09 +00:00
parent d7bc286801
commit 0bdff38416
4 changed files with 121 additions and 73 deletions

View File

@ -98,7 +98,8 @@ static void browser_window_destroy_internal(struct browser_window *bw);
static void browser_window_set_scale_internal(struct browser_window *bw,
float scale);
static struct browser_window *browser_window_find_target(
struct browser_window *bw, const char *target, bool new_window);
struct browser_window *bw, const char *target,
browser_mouse_state mouse);
static void browser_window_find_target_internal(struct browser_window *bw,
const char *target, int depth, struct browser_window *page,
int *rdepth, struct browser_window **bw_target);
@ -1073,8 +1074,8 @@ void browser_window_set_scale_internal(struct browser_window *bw, float scale)
* \param new_window always return a new window (ie 'Open Link in New Window')
*/
struct browser_window *browser_window_find_target(struct browser_window *bw, const char *target,
bool new_window)
struct browser_window *browser_window_find_target(struct browser_window *bw,
const char *target, browser_mouse_state mouse)
{
struct browser_window *bw_target;
struct browser_window *top;
@ -1088,21 +1089,62 @@ struct browser_window *browser_window_find_target(struct browser_window *bw, con
if (!target)
target = TARGET_SELF;
/* allow the simple case of target="_blank" to be ignored if requested */
if ((!new_window) && (!option_target_blank)) {
/* allow the simple case of target="_blank" to be ignored if requested
*/
if ((!(mouse & BROWSER_MOUSE_CLICK_2)) &&
(!((mouse & BROWSER_MOUSE_CLICK_2) &&
(mouse & BROWSER_MOUSE_MOD_2))) &&
(!option_target_blank)) {
/* not a mouse button 2 click
* not a mouse button 1 click with ctrl pressed
* configured to ignore target="_blank" */
if ((target == TARGET_BLANK) || (!strcasecmp(target, "_blank")))
return bw;
}
/* handle reserved keywords */
if ((new_window) || ((target == TARGET_BLANK) || (!strcasecmp(target, "_blank")))) {
if (((option_button_2_tab) && (mouse & BROWSER_MOUSE_CLICK_2)) ||
((!option_button_2_tab) &&
((mouse & BROWSER_MOUSE_CLICK_1) &&
(mouse & BROWSER_MOUSE_MOD_2))) ||
((option_button_2_tab) && ((target == TARGET_BLANK) ||
(!strcasecmp(target, "_blank"))))) {
/* open in new tab if:
* - button_2 opens in new tab and button_2 was pressed
* OR
* - button_2 doesn't open in new tabs and button_1 was
* pressed with ctrl held
* OR
* - button_2 opens in new tab and the link target is "_blank"
*/
bw_target = browser_window_create(NULL, bw, NULL, false, true);
if (!bw_target)
return bw;
return bw_target;
} else if (((!option_button_2_tab) &&
(mouse & BROWSER_MOUSE_CLICK_2)) ||
((option_button_2_tab) &&
((mouse & BROWSER_MOUSE_CLICK_1) &&
(mouse & BROWSER_MOUSE_MOD_2))) ||
((!option_button_2_tab) && ((target == TARGET_BLANK) ||
(!strcasecmp(target, "_blank"))))) {
/* open in new window if:
* - button_2 doesn't open in new tabs and button_2 was pressed
* OR
* - button_2 opens in new tab and button_1 was pressed with
* ctrl held
* OR
* - button_2 doesn't open in new tabs and the link target is
* "_blank"
*/
bw_target = browser_window_create(NULL, bw, NULL, false, false);
if (!bw_target)
return bw;
return bw_target;
} else if ((target == TARGET_SELF) || (!strcasecmp(target, "_self"))) {
return bw;
} else if ((target == TARGET_PARENT) || (!strcasecmp(target, "_parent"))) {
} else if ((target == TARGET_PARENT) ||
(!strcasecmp(target, "_parent"))) {
if (bw->parent)
return bw->parent;
return bw;
@ -1539,10 +1581,6 @@ void browser_window_mouse_action_html(struct browser_window *bw,
/* force download of link */
browser_window_go_post(bw, url, 0, 0, false,
c->url, true, true, 0);
} else if (mouse & BROWSER_MOUSE_CLICK_1 &&
mouse & BROWSER_MOUSE_MOD_2) {
/* open link in new tab */
browser_window_create(url, bw, c->url, true, true);
} else if (mouse & BROWSER_MOUSE_CLICK_2 &&
mouse & BROWSER_MOUSE_MOD_1) {
free(browser_window_href_content.url);
@ -1648,13 +1686,11 @@ void browser_window_mouse_action_html(struct browser_window *bw,
switch (action) {
case ACTION_SUBMIT:
browser_form_submit(bw,
browser_window_find_target(bw, target,
(mouse & BROWSER_MOUSE_CLICK_2)),
browser_window_find_target(bw, target, mouse),
gadget->form, gadget);
break;
case ACTION_GO:
browser_window_go(browser_window_find_target(bw, target,
(mouse & BROWSER_MOUSE_CLICK_2)),
browser_window_go(browser_window_find_target(bw, target, mouse),
url, c->url, true);
break;
case ACTION_NONE:

View File

@ -186,6 +186,9 @@ bool option_suppress_curl_debug = true;
/** Whether to allow target="_blank" */
bool option_target_blank = true;
/** Whether second mouse button opens in new tab */
bool option_button_2_tab = true;
EXTRA_OPTION_DEFINE
@ -194,64 +197,73 @@ struct {
enum { OPTION_BOOL, OPTION_INTEGER, OPTION_STRING } type;
void *p;
} option_table[] = {
{ "http_proxy", OPTION_BOOL, &option_http_proxy },
{ "http_proxy_host", OPTION_STRING, &option_http_proxy_host },
{ "http_proxy_port", OPTION_INTEGER, &option_http_proxy_port },
{ "http_proxy_auth", OPTION_INTEGER, &option_http_proxy_auth },
{ "http_proxy_auth_user", OPTION_STRING, &option_http_proxy_auth_user },
{ "http_proxy_auth_pass", OPTION_STRING, &option_http_proxy_auth_pass },
{ "font_size", OPTION_INTEGER, &option_font_size },
{ "font_min_size", OPTION_INTEGER, &option_font_min_size },
{ "font_sans", OPTION_STRING, &option_font_sans },
{ "font_serif", OPTION_STRING, &option_font_serif },
{ "font_mono", OPTION_STRING, &option_font_mono },
{ "font_cursive", OPTION_STRING, &option_font_cursive },
{ "font_fantasy", OPTION_STRING, &option_font_fantasy },
{ "accept_language", OPTION_STRING, &option_accept_language },
{ "accept_charset", OPTION_STRING, &option_accept_charset },
{ "memory_cache_size", OPTION_INTEGER, &option_memory_cache_size },
{ "disc_cache_age", OPTION_INTEGER, &option_disc_cache_age },
{ "block_advertisements", OPTION_BOOL, &option_block_ads },
{ "minimum_gif_delay", OPTION_INTEGER, &option_minimum_gif_delay },
{ "send_referer", OPTION_BOOL, &option_send_referer },
{ "animate_images", OPTION_BOOL, &option_animate_images },
{ "expire_url", OPTION_INTEGER, &option_expire_url },
{ "font_default", OPTION_INTEGER, &option_font_default },
{ "ca_bundle", OPTION_STRING, &option_ca_bundle },
{ "ca_path", OPTION_STRING, &option_ca_path },
{ "cookie_file", OPTION_STRING, &option_cookie_file },
{ "cookie_jar", OPTION_STRING, &option_cookie_jar },
{ "homepage_url", OPTION_STRING, &option_homepage_url },
{ "url_suggestion", OPTION_BOOL, &option_url_suggestion },
{ "window_x", OPTION_INTEGER, &option_window_x },
{ "window_y", OPTION_INTEGER, &option_window_y },
{ "window_width", OPTION_INTEGER, &option_window_width },
{ "window_height", OPTION_INTEGER, &option_window_height },
{ "window_screen_width", OPTION_INTEGER, &option_window_screen_width },
{ "window_screen_height",OPTION_INTEGER, &option_window_screen_height },
{ "toolbar_status_size", OPTION_INTEGER, &option_toolbar_status_width },
{ "scale", OPTION_INTEGER, &option_scale },
{ "incremental_reflow", OPTION_BOOL, &option_incremental_reflow },
{ "min_reflow_period", OPTION_INTEGER, &option_min_reflow_period },
{ "http_proxy", OPTION_BOOL, &option_http_proxy },
{ "http_proxy_host", OPTION_STRING, &option_http_proxy_host },
{ "http_proxy_port", OPTION_INTEGER, &option_http_proxy_port },
{ "http_proxy_auth", OPTION_INTEGER, &option_http_proxy_auth },
{ "http_proxy_auth_user",
OPTION_STRING, &option_http_proxy_auth_user },
{ "http_proxy_auth_pass",
OPTION_STRING, &option_http_proxy_auth_pass },
{ "font_size", OPTION_INTEGER, &option_font_size },
{ "font_min_size", OPTION_INTEGER, &option_font_min_size },
{ "font_sans", OPTION_STRING, &option_font_sans },
{ "font_serif", OPTION_STRING, &option_font_serif },
{ "font_mono", OPTION_STRING, &option_font_mono },
{ "font_cursive", OPTION_STRING, &option_font_cursive },
{ "font_fantasy", OPTION_STRING, &option_font_fantasy },
{ "accept_language", OPTION_STRING, &option_accept_language },
{ "accept_charset", OPTION_STRING, &option_accept_charset },
{ "memory_cache_size", OPTION_INTEGER, &option_memory_cache_size },
{ "disc_cache_age", OPTION_INTEGER, &option_disc_cache_age },
{ "block_advertisements",
OPTION_BOOL, &option_block_ads },
{ "minimum_gif_delay", OPTION_INTEGER, &option_minimum_gif_delay },
{ "send_referer", OPTION_BOOL, &option_send_referer },
{ "animate_images", OPTION_BOOL, &option_animate_images },
{ "expire_url", OPTION_INTEGER, &option_expire_url },
{ "font_default", OPTION_INTEGER, &option_font_default },
{ "ca_bundle", OPTION_STRING, &option_ca_bundle },
{ "ca_path", OPTION_STRING, &option_ca_path },
{ "cookie_file", OPTION_STRING, &option_cookie_file },
{ "cookie_jar", OPTION_STRING, &option_cookie_jar },
{ "homepage_url", OPTION_STRING, &option_homepage_url },
{ "url_suggestion", OPTION_BOOL, &option_url_suggestion },
{ "window_x", OPTION_INTEGER, &option_window_x },
{ "window_y", OPTION_INTEGER, &option_window_y },
{ "window_width", OPTION_INTEGER, &option_window_width },
{ "window_height", OPTION_INTEGER, &option_window_height },
{ "window_screen_width",
OPTION_INTEGER, &option_window_screen_width },
{ "window_screen_height",
OPTION_INTEGER, &option_window_screen_height },
{ "toolbar_status_size",
OPTION_INTEGER, &option_toolbar_status_width },
{ "scale", OPTION_INTEGER, &option_scale },
{ "incremental_reflow", OPTION_BOOL, &option_incremental_reflow },
{ "min_reflow_period", OPTION_INTEGER, &option_min_reflow_period },
/* Fetcher options */
{ "max_fetchers", OPTION_INTEGER, &option_max_fetchers },
{ "max_fetchers", OPTION_INTEGER, &option_max_fetchers },
{ "max_fetchers_per_host",
OPTION_INTEGER, &option_max_fetchers_per_host },
OPTION_INTEGER, &option_max_fetchers_per_host },
{ "max_cached_fetch_handles",
OPTION_INTEGER, &option_max_cached_fetch_handles },
{ "suppress_curl_debug", OPTION_BOOL, &option_suppress_curl_debug },
{ "target_blank",
OPTION_BOOL, &option_target_blank },
{ "margin_top", OPTION_INTEGER, &option_margin_top},
{ "margin_bottom", OPTION_INTEGER, &option_margin_bottom},
{ "margin_left", OPTION_INTEGER, &option_margin_left},
{ "margin_right", OPTION_INTEGER, &option_margin_right},
{ "export_scale", OPTION_INTEGER, &option_export_scale},
{ "suppress_images", OPTION_BOOL, &option_suppress_images},
{ "remove_backgrounds", OPTION_BOOL, &option_remove_backgrounds},
{ "enable_loosening", OPTION_BOOL, &option_enable_loosening},
{ "enable_PDF_compression", OPTION_BOOL, &option_enable_PDF_compression},
{ "enable_PDF_password", OPTION_BOOL, &option_enable_PDF_password},
OPTION_INTEGER, &option_max_cached_fetch_handles },
{ "suppress_curl_debug",OPTION_BOOL, &option_suppress_curl_debug },
{ "target_blank", OPTION_BOOL, &option_target_blank },
{ "button_2_tab", OPTION_BOOL, &option_button_2_tab },
/* PDF / Print options*/
{ "margin_top", OPTION_INTEGER, &option_margin_top},
{ "margin_bottom", OPTION_INTEGER, &option_margin_bottom},
{ "margin_left", OPTION_INTEGER, &option_margin_left},
{ "margin_right", OPTION_INTEGER, &option_margin_right},
{ "export_scale", OPTION_INTEGER, &option_export_scale},
{ "suppress_images", OPTION_BOOL, &option_suppress_images},
{ "remove_backgrounds", OPTION_BOOL, &option_remove_backgrounds},
{ "enable_loosening", OPTION_BOOL, &option_enable_loosening},
{ "enable_PDF_compression",
OPTION_BOOL, &option_enable_PDF_compression},
{ "enable_PDF_password",
OPTION_BOOL, &option_enable_PDF_password},
EXTRA_OPTION_TABLE
};

View File

@ -71,6 +71,7 @@ extern char *option_cookie_file;
extern char *option_cookie_jar;
extern char *option_homepage_url;
extern bool option_target_blank;
extern bool option_button_2_tab;
extern bool option_url_suggestion;
extern int option_window_x;
extern int option_window_y;

View File

@ -63,7 +63,6 @@ void nsgtk_tab_add(struct gui_window *window)
GTK_WIDGET(window->scrolledwindow), tabBox);
gtk_widget_show_all(GTK_WIDGET(window->scrolledwindow));
gtk_notebook_set_current_page(tabs, page);
}
void nsgtk_tab_visibility_update(GtkNotebook *notebook, GtkWidget *child,
@ -172,10 +171,10 @@ void nsgtk_tab_close_current(GtkNotebook *notebook)
GtkWidget *window = gtk_notebook_get_nth_page(notebook, curr_page);
struct gui_window *gw = g_object_get_data(G_OBJECT(window),
"gui_window");
if (gtk_notebook_get_n_pages(notebook) < 2)
return; /* wicked things happen if we close the last tab */
gtk_notebook_remove_page(notebook, curr_page);
nsgtk_window_destroy_browser(gw);
}