2003-06-30 16:44:03 +04:00
|
|
|
/*
|
|
|
|
* Copyright 2003 Phil Mellor <monkeyson@users.sourceforge.net>
|
2006-11-26 23:11:20 +03:00
|
|
|
* Copyright 2006 James Bursa <bursa@users.sourceforge.net>
|
2004-07-27 00:13:45 +04:00
|
|
|
* Copyright 2004 Andrew Timmins <atimmins@blueyonder.co.uk>
|
2008-08-05 05:30:31 +04:00
|
|
|
* Copyright 2004 John Tytgat <joty@netsurf-browser.org>
|
2006-11-26 23:11:20 +03:00
|
|
|
* Copyright 2006 Richard Wilson <info@tinct.net>
|
2008-04-11 21:51:43 +04:00
|
|
|
* Copyright 2008 Michael Drake <tlsa@netsurf-browser.org>
|
2014-10-20 00:49:46 +04:00
|
|
|
* Copyright 2009 Paul Blokus <paul_pl@users.sourceforge.net>
|
2007-08-08 20:16:03 +04:00
|
|
|
*
|
|
|
|
* This file is part of NetSurf, http://www.netsurf-browser.org/
|
|
|
|
*
|
|
|
|
* NetSurf is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; version 2 of the License.
|
|
|
|
*
|
|
|
|
* NetSurf is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2004-02-25 18:12:58 +03:00
|
|
|
*/
|
|
|
|
|
2014-10-16 12:48:09 +04:00
|
|
|
/**
|
|
|
|
* \file
|
|
|
|
*
|
|
|
|
* Browser window creation and manipulation implementation.
|
2002-09-11 18:24:02 +04:00
|
|
|
*/
|
|
|
|
|
2014-10-16 12:48:09 +04:00
|
|
|
#include "utils/config.h"
|
|
|
|
|
2003-07-18 03:01:02 +04:00
|
|
|
#include <assert.h>
|
|
|
|
#include <limits.h>
|
2003-10-09 19:23:10 +04:00
|
|
|
#include <stdbool.h>
|
2005-08-21 16:04:18 +04:00
|
|
|
#include <stdint.h>
|
2003-07-18 03:01:02 +04:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2008-08-11 20:44:12 +04:00
|
|
|
#include <strings.h>
|
2008-07-29 00:32:51 +04:00
|
|
|
#include <math.h>
|
2016-04-21 15:50:16 +03:00
|
|
|
#include <nsutils/time.h>
|
2010-01-29 14:32:53 +03:00
|
|
|
|
2014-10-16 12:48:09 +04:00
|
|
|
#include "utils/corestrings.h"
|
|
|
|
#include "utils/log.h"
|
|
|
|
#include "utils/messages.h"
|
|
|
|
#include "utils/nsurl.h"
|
|
|
|
#include "utils/utils.h"
|
|
|
|
#include "utils/utf8.h"
|
|
|
|
#include "utils/nsoption.h"
|
2016-06-06 10:59:23 +03:00
|
|
|
#include "netsurf/misc.h"
|
|
|
|
#include "netsurf/window.h"
|
|
|
|
#include "netsurf/content.h"
|
|
|
|
#include "netsurf/plotters.h"
|
2016-04-19 01:04:16 +03:00
|
|
|
#include "content/content_debug.h"
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "content/fetch.h"
|
2010-03-28 16:56:39 +04:00
|
|
|
#include "content/hlcache.h"
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "content/urldb.h"
|
2016-06-06 16:47:27 +03:00
|
|
|
#include "css/utils.h"
|
2014-11-14 00:52:08 +03:00
|
|
|
#include "render/form_internal.h"
|
2014-10-16 12:48:09 +04:00
|
|
|
#include "render/html.h"
|
|
|
|
#include "render/box.h"
|
|
|
|
#include "javascript/js.h"
|
|
|
|
|
2014-02-15 22:43:59 +04:00
|
|
|
#include "desktop/browser_history.h"
|
2012-08-22 15:22:58 +04:00
|
|
|
#include "desktop/browser_private.h"
|
2010-04-06 01:35:38 +04:00
|
|
|
#include "desktop/download.h"
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "desktop/frames.h"
|
2013-07-16 16:15:22 +04:00
|
|
|
#include "desktop/global_history.h"
|
2013-08-27 16:38:23 +04:00
|
|
|
#include "desktop/hotlist.h"
|
2011-02-21 17:48:55 +03:00
|
|
|
#include "desktop/knockout.h"
|
2011-07-06 00:13:28 +04:00
|
|
|
#include "desktop/scrollbar.h"
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "desktop/selection.h"
|
2014-11-06 17:19:15 +03:00
|
|
|
#include "desktop/theme.h"
|
2014-10-16 12:48:09 +04:00
|
|
|
#include "desktop/gui_internal.h"
|
2016-06-30 17:40:10 +03:00
|
|
|
#include "desktop/textinput.h"
|
2002-09-11 18:24:02 +04:00
|
|
|
|
2007-08-07 07:55:18 +04:00
|
|
|
|
2006-11-26 23:11:20 +03:00
|
|
|
/** maximum frame depth */
|
|
|
|
#define FRAME_DEPTH 8
|
|
|
|
|
2003-02-09 15:58:15 +03:00
|
|
|
|
2011-07-06 00:13:28 +04:00
|
|
|
/**
|
|
|
|
* Get position of scrollbar widget within browser window.
|
|
|
|
*
|
|
|
|
* \param bw The browser window
|
|
|
|
* \param horizontal Whether to get position of horizontal scrollbar
|
|
|
|
* \param x Updated to x-coord of top left of scrollbar widget
|
|
|
|
* \param y Updated to y-coord of top left of scrollbar widget
|
|
|
|
*/
|
|
|
|
static inline void browser_window_get_scrollbar_pos(struct browser_window *bw,
|
|
|
|
bool horizontal, int *x, int *y)
|
|
|
|
{
|
|
|
|
if (horizontal) {
|
|
|
|
*x = 0;
|
|
|
|
*y = bw->height - SCROLLBAR_WIDTH;
|
|
|
|
} else {
|
|
|
|
*x = bw->width - SCROLLBAR_WIDTH;
|
|
|
|
*y = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get browser window scrollbar widget length
|
|
|
|
*
|
|
|
|
* \param bw The browser window
|
|
|
|
* \param horizontal Whether to get length of horizontal scrollbar
|
|
|
|
* \return the scrollbar's length
|
|
|
|
*/
|
|
|
|
static inline int browser_window_get_scrollbar_len(struct browser_window *bw,
|
|
|
|
bool horizontal)
|
|
|
|
{
|
|
|
|
if (horizontal)
|
|
|
|
return bw->width - (bw->scroll_y != NULL ? SCROLLBAR_WIDTH : 0);
|
|
|
|
else
|
|
|
|
return bw->height;
|
|
|
|
}
|
|
|
|
|
2015-10-18 12:53:49 +03:00
|
|
|
|
|
|
|
/* exported interface, documented in browser.h */
|
|
|
|
nserror
|
|
|
|
browser_window_get_name(struct browser_window *bw, const char **out_name)
|
|
|
|
{
|
|
|
|
assert(bw != NULL);
|
|
|
|
|
|
|
|
*out_name = bw->name;
|
|
|
|
|
|
|
|
return NSERROR_OK;
|
|
|
|
}
|
|
|
|
|
2017-03-03 12:28:54 +03:00
|
|
|
|
2015-10-18 12:53:49 +03:00
|
|
|
/* exported interface, documented in browser.h */
|
|
|
|
nserror
|
|
|
|
browser_window_set_name(struct browser_window *bw, const char *name)
|
|
|
|
{
|
|
|
|
char *nname = NULL;
|
|
|
|
|
|
|
|
assert(bw != NULL);
|
|
|
|
|
|
|
|
if (name != NULL) {
|
|
|
|
nname = strdup(name);
|
|
|
|
if (nname == NULL) {
|
|
|
|
return NSERROR_NOMEM;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bw->name != NULL) {
|
|
|
|
free(bw->name);
|
|
|
|
}
|
|
|
|
|
|
|
|
bw->name = nname;
|
|
|
|
|
|
|
|
return NSERROR_OK;
|
|
|
|
}
|
|
|
|
|
2017-03-03 12:28:54 +03:00
|
|
|
|
2011-02-11 01:35:41 +03:00
|
|
|
/* exported interface, documented in browser.h */
|
2017-03-02 02:30:29 +03:00
|
|
|
bool
|
|
|
|
browser_window_redraw(struct browser_window *bw,
|
|
|
|
int x, int y,
|
|
|
|
const struct rect *clip,
|
|
|
|
const struct redraw_context *ctx)
|
2011-02-11 01:35:41 +03:00
|
|
|
{
|
2011-06-30 19:48:07 +04:00
|
|
|
struct redraw_context new_ctx = *ctx;
|
2011-02-11 03:14:22 +03:00
|
|
|
int width = 0;
|
|
|
|
int height = 0;
|
2011-02-21 17:48:55 +03:00
|
|
|
bool plot_ok = true;
|
2011-03-15 18:08:10 +03:00
|
|
|
content_type content_type;
|
2011-06-29 00:17:39 +04:00
|
|
|
struct content_redraw_data data;
|
2011-07-06 00:13:28 +04:00
|
|
|
struct rect content_clip;
|
2017-03-02 02:30:29 +03:00
|
|
|
nserror res;
|
2011-02-11 03:14:22 +03:00
|
|
|
|
2011-02-11 01:35:41 +03:00
|
|
|
if (bw == NULL) {
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("NULL browser window");
|
2011-02-11 01:35:41 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-02-11 16:54:08 +03:00
|
|
|
if ((bw->current_content == NULL) &&
|
|
|
|
(bw->children == NULL)) {
|
2011-02-21 17:48:55 +03:00
|
|
|
/* Browser window has no content, render blank fill */
|
2017-02-11 16:54:08 +03:00
|
|
|
ctx->plot->clip(ctx, clip);
|
|
|
|
return (ctx->plot->rectangle(ctx, plot_style_fill_white, clip) == NSERROR_OK);
|
2011-02-11 01:35:41 +03:00
|
|
|
}
|
2011-02-11 03:14:22 +03:00
|
|
|
|
2011-09-04 21:24:45 +04:00
|
|
|
/* Browser window has content OR children (frames) */
|
2014-10-20 00:49:46 +04:00
|
|
|
if ((bw->window != NULL) &&
|
2012-03-22 13:34:34 +04:00
|
|
|
(ctx->plot->option_knockout)) {
|
2011-09-04 21:24:45 +04:00
|
|
|
/* Root browser window: start knockout */
|
2011-06-30 19:48:07 +04:00
|
|
|
knockout_plot_start(ctx, &new_ctx);
|
|
|
|
}
|
2011-02-21 17:48:55 +03:00
|
|
|
|
2017-02-11 16:54:08 +03:00
|
|
|
new_ctx.plot->clip(ctx, clip);
|
2011-02-21 17:48:55 +03:00
|
|
|
|
2011-09-04 21:24:45 +04:00
|
|
|
/* Handle redraw of any browser window children */
|
|
|
|
if (bw->children) {
|
|
|
|
struct browser_window *child;
|
|
|
|
int cur_child;
|
|
|
|
int children = bw->rows * bw->cols;
|
|
|
|
|
2017-02-11 16:54:08 +03:00
|
|
|
if (bw->window != NULL) {
|
2011-09-04 21:24:45 +04:00
|
|
|
/* Root browser window; start with blank fill */
|
2017-02-11 16:54:08 +03:00
|
|
|
plot_ok &= (new_ctx.plot->rectangle(ctx,
|
|
|
|
plot_style_fill_white,
|
|
|
|
clip) == NSERROR_OK);
|
|
|
|
}
|
2011-09-04 21:24:45 +04:00
|
|
|
|
|
|
|
/* Loop through all children of bw */
|
|
|
|
for (cur_child = 0; cur_child < children; cur_child++) {
|
|
|
|
/* Set current child */
|
|
|
|
child = &bw->children[cur_child];
|
|
|
|
|
|
|
|
/* Get frame edge box in global coordinates */
|
|
|
|
content_clip.x0 = (x + child->x) * child->scale;
|
|
|
|
content_clip.y0 = (y + child->y) * child->scale;
|
|
|
|
content_clip.x1 = content_clip.x0 +
|
|
|
|
child->width * child->scale;
|
|
|
|
content_clip.y1 = content_clip.y0 +
|
|
|
|
child->height * child->scale;
|
|
|
|
|
|
|
|
/* Intersect it with clip rectangle */
|
|
|
|
if (content_clip.x0 < clip->x0)
|
|
|
|
content_clip.x0 = clip->x0;
|
|
|
|
if (content_clip.y0 < clip->y0)
|
|
|
|
content_clip.y0 = clip->y0;
|
|
|
|
if (clip->x1 < content_clip.x1)
|
|
|
|
content_clip.x1 = clip->x1;
|
|
|
|
if (clip->y1 < content_clip.y1)
|
|
|
|
content_clip.y1 = clip->y1;
|
|
|
|
|
|
|
|
/* Skip this frame if it lies outside clip rectangle */
|
|
|
|
if (content_clip.x0 >= content_clip.x1 ||
|
2017-02-11 16:54:08 +03:00
|
|
|
content_clip.y0 >= content_clip.y1)
|
2011-09-04 21:24:45 +04:00
|
|
|
continue;
|
|
|
|
|
|
|
|
/* Redraw frame */
|
|
|
|
plot_ok &= browser_window_redraw(child,
|
|
|
|
x + child->x, y + child->y,
|
|
|
|
&content_clip, &new_ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Nothing else to redraw for browser windows with children;
|
2017-02-11 16:54:08 +03:00
|
|
|
* cleanup and return
|
|
|
|
*/
|
2011-09-04 21:24:45 +04:00
|
|
|
if (bw->window != NULL && ctx->plot->option_knockout) {
|
|
|
|
/* Root browser window: knockout end */
|
2017-02-11 16:47:39 +03:00
|
|
|
knockout_plot_end(ctx);
|
2011-09-04 21:24:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return plot_ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Handle browser windows with content to redraw */
|
|
|
|
|
2011-03-15 18:08:10 +03:00
|
|
|
content_type = content_get_type(bw->current_content);
|
|
|
|
if (content_type != CONTENT_HTML && content_type != CONTENT_TEXTPLAIN) {
|
2011-02-13 18:55:53 +03:00
|
|
|
/* Set render area according to scale */
|
2011-02-11 03:14:22 +03:00
|
|
|
width = content_get_width(bw->current_content) * bw->scale;
|
|
|
|
height = content_get_height(bw->current_content) * bw->scale;
|
2011-02-13 18:55:53 +03:00
|
|
|
|
|
|
|
/* Non-HTML may not fill viewport to extents, so plot white
|
|
|
|
* background fill */
|
2017-02-11 16:54:08 +03:00
|
|
|
plot_ok &= (new_ctx.plot->rectangle(&new_ctx,
|
|
|
|
plot_style_fill_white,
|
|
|
|
clip) == NSERROR_OK);
|
2011-02-11 03:14:22 +03:00
|
|
|
}
|
2011-06-29 00:17:39 +04:00
|
|
|
|
|
|
|
/* Set up content redraw data */
|
2011-07-06 00:13:28 +04:00
|
|
|
data.x = x - scrollbar_get_offset(bw->scroll_x);
|
|
|
|
data.y = y - scrollbar_get_offset(bw->scroll_y);
|
2011-06-29 00:17:39 +04:00
|
|
|
data.width = width;
|
|
|
|
data.height = height;
|
|
|
|
|
|
|
|
data.background_colour = 0xFFFFFF;
|
|
|
|
data.scale = bw->scale;
|
|
|
|
data.repeat_x = false;
|
|
|
|
data.repeat_y = false;
|
2011-07-06 00:13:28 +04:00
|
|
|
|
|
|
|
content_clip = *clip;
|
|
|
|
|
|
|
|
if (!bw->window) {
|
|
|
|
int x0 = x * bw->scale;
|
|
|
|
int y0 = y * bw->scale;
|
|
|
|
int x1 = (x + bw->width - ((bw->scroll_y != NULL) ?
|
|
|
|
SCROLLBAR_WIDTH : 0)) * bw->scale;
|
|
|
|
int y1 = (y + bw->height - ((bw->scroll_x != NULL) ?
|
|
|
|
SCROLLBAR_WIDTH : 0)) * bw->scale;
|
|
|
|
|
|
|
|
if (content_clip.x0 < x0) content_clip.x0 = x0;
|
|
|
|
if (content_clip.y0 < y0) content_clip.y0 = y0;
|
|
|
|
if (x1 < content_clip.x1) content_clip.x1 = x1;
|
|
|
|
if (y1 < content_clip.y1) content_clip.y1 = y1;
|
|
|
|
}
|
2014-10-20 00:49:46 +04:00
|
|
|
|
2011-02-21 17:48:55 +03:00
|
|
|
/* Render the content */
|
2011-07-06 00:13:28 +04:00
|
|
|
plot_ok &= content_redraw(bw->current_content, &data,
|
|
|
|
&content_clip, &new_ctx);
|
|
|
|
|
|
|
|
/* Back to full clip rect */
|
2017-02-11 16:54:08 +03:00
|
|
|
new_ctx.plot->clip(&new_ctx, clip);
|
2011-07-06 00:13:28 +04:00
|
|
|
|
|
|
|
if (!bw->window) {
|
|
|
|
/* Render scrollbars */
|
|
|
|
int off_x, off_y;
|
|
|
|
if (bw->scroll_x != NULL) {
|
|
|
|
browser_window_get_scrollbar_pos(bw, true,
|
|
|
|
&off_x, &off_y);
|
2017-03-02 02:30:29 +03:00
|
|
|
res = scrollbar_redraw(bw->scroll_x,
|
2011-07-06 00:13:28 +04:00
|
|
|
x + off_x, y + off_y, clip,
|
|
|
|
bw->scale, &new_ctx);
|
2017-03-02 02:30:29 +03:00
|
|
|
if (res != NSERROR_OK) {
|
|
|
|
plot_ok = false;
|
|
|
|
}
|
2011-07-06 00:13:28 +04:00
|
|
|
}
|
|
|
|
if (bw->scroll_y != NULL) {
|
|
|
|
browser_window_get_scrollbar_pos(bw, false,
|
|
|
|
&off_x, &off_y);
|
2017-03-02 02:30:29 +03:00
|
|
|
res = scrollbar_redraw(bw->scroll_y,
|
2011-07-06 00:13:28 +04:00
|
|
|
x + off_x, y + off_y, clip,
|
|
|
|
bw->scale, &new_ctx);
|
2017-03-02 02:30:29 +03:00
|
|
|
if (res != NSERROR_OK) {
|
|
|
|
plot_ok = false;
|
|
|
|
}
|
2011-07-06 00:13:28 +04:00
|
|
|
}
|
|
|
|
}
|
2014-10-20 00:49:46 +04:00
|
|
|
|
2011-09-04 21:24:45 +04:00
|
|
|
if (bw->window != NULL && ctx->plot->option_knockout) {
|
|
|
|
/* Root browser window: end knockout */
|
2017-02-11 16:47:39 +03:00
|
|
|
knockout_plot_end(ctx);
|
2011-06-30 19:48:07 +04:00
|
|
|
}
|
2011-02-21 17:48:55 +03:00
|
|
|
|
|
|
|
return plot_ok;
|
2011-02-11 01:35:41 +03:00
|
|
|
}
|
|
|
|
|
2017-03-03 12:28:54 +03:00
|
|
|
|
2011-02-13 19:44:32 +03:00
|
|
|
/* exported interface, documented in browser.h */
|
|
|
|
bool browser_window_redraw_ready(struct browser_window *bw)
|
|
|
|
{
|
|
|
|
if (bw == NULL) {
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("NULL browser window");
|
2011-02-13 19:44:32 +03:00
|
|
|
return false;
|
|
|
|
} else if (bw->current_content != NULL) {
|
|
|
|
/* Can't render locked contents */
|
|
|
|
return !content_is_locked(bw->current_content);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-03-03 12:28:54 +03:00
|
|
|
|
2014-02-08 20:01:14 +04:00
|
|
|
/* exported interface, documented in browser_private.h */
|
2011-06-15 00:00:18 +04:00
|
|
|
void browser_window_update_extent(struct browser_window *bw)
|
|
|
|
{
|
2011-09-04 21:24:45 +04:00
|
|
|
if (bw->window != NULL)
|
|
|
|
/* Front end window */
|
2014-01-13 15:38:35 +04:00
|
|
|
guit->window->update_extent(bw->window);
|
2011-09-04 21:24:45 +04:00
|
|
|
else
|
|
|
|
/* Core-managed browser window */
|
2011-07-06 00:13:28 +04:00
|
|
|
browser_window_handle_scrollbars(bw);
|
2011-06-15 00:00:18 +04:00
|
|
|
}
|
|
|
|
|
2017-03-03 12:28:54 +03:00
|
|
|
|
2011-06-15 00:00:18 +04:00
|
|
|
/* exported interface, documented in browser.h */
|
2017-03-03 12:28:54 +03:00
|
|
|
void
|
|
|
|
browser_window_get_position(struct browser_window *bw,
|
|
|
|
bool root,
|
|
|
|
int *pos_x,
|
|
|
|
int *pos_y)
|
2011-06-15 00:00:18 +04:00
|
|
|
{
|
|
|
|
*pos_x = 0;
|
|
|
|
*pos_y = 0;
|
|
|
|
|
|
|
|
assert(bw != NULL);
|
|
|
|
|
|
|
|
while (bw) {
|
|
|
|
switch (bw->browser_window_type) {
|
2011-09-04 21:24:45 +04:00
|
|
|
|
|
|
|
case BROWSER_WINDOW_FRAMESET:
|
|
|
|
*pos_x += bw->x * bw->scale;
|
|
|
|
*pos_y += bw->y * bw->scale;
|
|
|
|
break;
|
|
|
|
|
2011-06-15 00:00:18 +04:00
|
|
|
case BROWSER_WINDOW_NORMAL:
|
|
|
|
/* There is no offset to the root browser window */
|
|
|
|
break;
|
|
|
|
|
2011-12-02 20:10:13 +04:00
|
|
|
case BROWSER_WINDOW_FRAME:
|
|
|
|
/* Iframe and Frame handling is identical;
|
|
|
|
* fall though */
|
2011-09-04 21:24:45 +04:00
|
|
|
case BROWSER_WINDOW_IFRAME:
|
|
|
|
*pos_x += (bw->x - scrollbar_get_offset(bw->scroll_x)) *
|
|
|
|
bw->scale;
|
|
|
|
*pos_y += (bw->y - scrollbar_get_offset(bw->scroll_y)) *
|
|
|
|
bw->scale;
|
2011-06-15 00:00:18 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
bw = bw->parent;
|
|
|
|
|
|
|
|
if (!root) {
|
|
|
|
/* return if we just wanted the position in the parent
|
|
|
|
* browser window. */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-03 12:28:54 +03:00
|
|
|
|
2011-06-24 13:30:33 +04:00
|
|
|
/* exported interface, documented in browser.h */
|
|
|
|
void browser_window_set_position(struct browser_window *bw, int x, int y)
|
|
|
|
{
|
|
|
|
assert(bw != NULL);
|
|
|
|
|
2011-09-04 21:24:45 +04:00
|
|
|
if (bw->window == NULL) {
|
|
|
|
/* Core managed browser window */
|
2011-06-24 13:30:33 +04:00
|
|
|
bw->x = x;
|
|
|
|
bw->y = y;
|
2011-09-04 21:24:45 +04:00
|
|
|
} else {
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("Asked to set position of front end window.");
|
2011-09-04 21:24:45 +04:00
|
|
|
assert(0);
|
2011-06-24 13:30:33 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-27 21:29:49 +04:00
|
|
|
/* exported interface, documented in browser.h */
|
2017-03-03 17:30:39 +03:00
|
|
|
void
|
|
|
|
browser_window_set_drag_type(struct browser_window *bw,
|
|
|
|
browser_drag_type type,
|
|
|
|
const struct rect *rect)
|
2011-06-27 21:29:49 +04:00
|
|
|
{
|
2011-08-24 22:22:22 +04:00
|
|
|
struct browser_window *top_bw = browser_window_get_root(bw);
|
2012-01-11 18:20:26 +04:00
|
|
|
gui_drag_type gtype;
|
2011-08-24 22:22:22 +04:00
|
|
|
|
2017-03-03 17:30:39 +03:00
|
|
|
bw->drag.type = type;
|
2012-01-11 18:20:26 +04:00
|
|
|
|
|
|
|
if (type == DRAGGING_NONE) {
|
2017-03-03 17:30:39 +03:00
|
|
|
top_bw->drag.window = NULL;
|
2012-01-11 18:20:26 +04:00
|
|
|
} else {
|
2017-03-03 17:30:39 +03:00
|
|
|
top_bw->drag.window = bw;
|
2011-08-24 22:22:22 +04:00
|
|
|
|
2012-01-11 18:20:26 +04:00
|
|
|
switch (type) {
|
2013-02-08 19:05:07 +04:00
|
|
|
case DRAGGING_SELECTION:
|
2017-03-03 17:30:39 +03:00
|
|
|
/** \todo tell front end */
|
2013-02-08 19:05:07 +04:00
|
|
|
return;
|
2012-01-11 18:20:26 +04:00
|
|
|
case DRAGGING_SCR_X:
|
|
|
|
case DRAGGING_SCR_Y:
|
|
|
|
case DRAGGING_CONTENT_SCROLLBAR:
|
|
|
|
gtype = GDRAGGING_SCROLLBAR;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
gtype = GDRAGGING_OTHER;
|
|
|
|
break;
|
|
|
|
}
|
2012-01-11 02:02:19 +04:00
|
|
|
|
2014-01-12 21:07:34 +04:00
|
|
|
guit->window->drag_start(top_bw->window, gtype, rect);
|
2012-01-11 18:20:26 +04:00
|
|
|
}
|
2011-06-27 21:29:49 +04:00
|
|
|
}
|
|
|
|
|
2012-02-28 16:20:49 +04:00
|
|
|
/* exported interface, documented in browser.h */
|
|
|
|
browser_drag_type browser_window_get_drag_type(struct browser_window *bw)
|
|
|
|
{
|
2017-03-03 17:30:39 +03:00
|
|
|
return bw->drag.type;
|
2012-02-28 16:20:49 +04:00
|
|
|
}
|
|
|
|
|
2011-06-29 01:09:57 +04:00
|
|
|
/* exported interface, documented in browser.h */
|
|
|
|
struct browser_window * browser_window_get_root(struct browser_window *bw)
|
|
|
|
{
|
2012-08-16 19:26:43 +04:00
|
|
|
while (bw && bw->parent) {
|
2011-06-29 01:09:57 +04:00
|
|
|
bw = bw->parent;
|
|
|
|
}
|
|
|
|
return bw;
|
|
|
|
}
|
2011-07-06 00:13:28 +04:00
|
|
|
|
2011-07-02 20:43:20 +04:00
|
|
|
/* exported interface, documented in browser.h */
|
2013-02-22 16:19:35 +04:00
|
|
|
browser_editor_flags browser_window_get_editor_flags(struct browser_window *bw)
|
2011-07-02 20:43:20 +04:00
|
|
|
{
|
2013-02-22 16:19:35 +04:00
|
|
|
browser_editor_flags ed_flags = BW_EDITOR_NONE;
|
2011-07-02 20:43:20 +04:00
|
|
|
assert(bw->window);
|
2013-02-22 16:19:35 +04:00
|
|
|
assert(bw->parent == NULL);
|
2011-07-02 20:43:20 +04:00
|
|
|
|
2013-02-22 16:19:35 +04:00
|
|
|
if (bw->selection.bw != NULL) {
|
|
|
|
ed_flags |= BW_EDITOR_CAN_COPY;
|
|
|
|
|
|
|
|
if (!bw->selection.read_only)
|
|
|
|
ed_flags |= BW_EDITOR_CAN_CUT;
|
2011-07-02 20:43:20 +04:00
|
|
|
}
|
2013-02-22 16:19:35 +04:00
|
|
|
|
|
|
|
if (bw->can_edit)
|
|
|
|
ed_flags |= BW_EDITOR_CAN_PASTE;
|
|
|
|
|
|
|
|
return ed_flags;
|
2011-07-02 20:43:20 +04:00
|
|
|
}
|
2011-06-29 01:09:57 +04:00
|
|
|
|
2014-10-18 21:53:50 +04:00
|
|
|
/* exported interface, documented in browser.h */
|
|
|
|
bool browser_window_can_select(struct browser_window *bw)
|
|
|
|
{
|
|
|
|
if (bw == NULL || bw->current_content == NULL)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
/* TODO: We shouldn't have to know about specific content types
|
|
|
|
* here. There should be a content_is_selectable() call. */
|
|
|
|
if (content_get_type(bw->current_content) != CONTENT_HTML &&
|
|
|
|
content_get_type(bw->current_content) !=
|
|
|
|
CONTENT_TEXTPLAIN)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-07-13 17:20:26 +04:00
|
|
|
/* exported interface, documented in browser.h */
|
2013-02-22 16:19:35 +04:00
|
|
|
char * browser_window_get_selection(struct browser_window *bw)
|
2011-07-13 17:20:26 +04:00
|
|
|
{
|
|
|
|
assert(bw->window);
|
2013-02-22 16:19:35 +04:00
|
|
|
assert(bw->parent == NULL);
|
2011-07-13 17:20:26 +04:00
|
|
|
|
2013-02-22 16:19:35 +04:00
|
|
|
if (bw->selection.bw == NULL ||
|
|
|
|
bw->selection.bw->current_content == NULL)
|
|
|
|
return NULL;
|
2011-07-13 17:20:26 +04:00
|
|
|
|
2013-02-22 16:19:35 +04:00
|
|
|
return content_get_selection(bw->selection.bw->current_content);
|
2011-07-13 17:20:26 +04:00
|
|
|
}
|
|
|
|
|
2016-05-30 19:32:57 +03:00
|
|
|
/* exported interface, documented in netsurf/browser_window.h */
|
2014-10-18 20:39:03 +04:00
|
|
|
bool browser_window_can_search(struct browser_window *bw)
|
|
|
|
{
|
|
|
|
if (bw == NULL || bw->current_content == NULL)
|
|
|
|
return false;
|
|
|
|
|
2014-10-19 22:12:55 +04:00
|
|
|
/** \todo We shouldn't have to know about specific content
|
|
|
|
* types here. There should be a content_is_searchable() call.
|
|
|
|
*/
|
|
|
|
if ((content_get_type(bw->current_content) != CONTENT_HTML) &&
|
|
|
|
(content_get_type(bw->current_content) != CONTENT_TEXTPLAIN)) {
|
2014-10-18 20:39:03 +04:00
|
|
|
return false;
|
2014-10-19 22:12:55 +04:00
|
|
|
}
|
2014-10-18 20:39:03 +04:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-10-25 15:00:34 +04:00
|
|
|
|
2016-05-30 19:32:57 +03:00
|
|
|
/* exported interface, documented in netsurf/browser_window.h */
|
2014-10-25 15:00:34 +04:00
|
|
|
bool browser_window_is_frameset(struct browser_window *bw)
|
|
|
|
{
|
|
|
|
return (bw->children != NULL);
|
|
|
|
}
|
|
|
|
|
2014-10-25 15:04:11 +04:00
|
|
|
|
2016-05-30 19:32:57 +03:00
|
|
|
/* exported interface, documented in netsurf/browser_window.h */
|
2014-10-25 15:04:11 +04:00
|
|
|
nserror browser_window_get_scrollbar_type(struct browser_window *bw,
|
|
|
|
browser_scrolling *h, browser_scrolling *v)
|
|
|
|
{
|
|
|
|
*h = bw->scrolling;
|
|
|
|
*v = bw->scrolling;
|
|
|
|
|
|
|
|
return NSERROR_OK;
|
|
|
|
}
|
|
|
|
|
2013-02-22 16:19:35 +04:00
|
|
|
/**
|
|
|
|
* Set or remove a selection.
|
|
|
|
*
|
|
|
|
* \param bw browser window with selection
|
|
|
|
* \param selection true if bw has a selection, false if removing selection
|
|
|
|
* \param read_only true iff selection is read only (e.g. can't cut it)
|
|
|
|
*/
|
|
|
|
static void browser_window_set_selection(struct browser_window *bw,
|
|
|
|
bool selection, bool read_only)
|
2011-07-13 17:20:26 +04:00
|
|
|
{
|
2013-02-22 16:19:35 +04:00
|
|
|
struct browser_window *top;
|
|
|
|
|
|
|
|
assert(bw != NULL);
|
|
|
|
|
|
|
|
top = browser_window_get_root(bw);
|
|
|
|
|
|
|
|
assert(top != NULL);
|
2011-07-13 17:20:26 +04:00
|
|
|
|
2013-02-22 16:19:35 +04:00
|
|
|
if (bw != top->selection.bw && top->selection.bw != NULL &&
|
|
|
|
top->selection.bw->current_content != NULL) {
|
|
|
|
/* clear old selection */
|
|
|
|
content_clear_selection(top->selection.bw->current_content);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (selection) {
|
|
|
|
top->selection.bw = bw;
|
|
|
|
} else {
|
|
|
|
top->selection.bw = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
top->selection.read_only = read_only;
|
2011-07-13 17:20:26 +04:00
|
|
|
}
|
|
|
|
|
2011-07-06 00:13:28 +04:00
|
|
|
|
2017-04-26 22:48:54 +03:00
|
|
|
/**
|
|
|
|
* Set the scroll position of a browser window.
|
|
|
|
*
|
|
|
|
* scrolls the viewport to ensure the specified rectangle of the
|
|
|
|
* content is shown.
|
|
|
|
*
|
2017-06-09 19:28:55 +03:00
|
|
|
* \param bw window to scroll
|
2017-04-26 22:48:54 +03:00
|
|
|
* \param rect The rectangle to ensure is shown.
|
|
|
|
* \return NSERROR_OK on success or apropriate error code.
|
|
|
|
*/
|
|
|
|
static nserror
|
|
|
|
browser_window_set_scroll(struct browser_window *bw,
|
|
|
|
const struct rect *rect)
|
|
|
|
{
|
2011-09-04 21:24:45 +04:00
|
|
|
if (bw->window != NULL) {
|
2017-04-26 22:48:54 +03:00
|
|
|
return guit->window->set_scroll(bw->window, rect);
|
2011-07-14 14:27:24 +04:00
|
|
|
}
|
|
|
|
|
2017-04-26 22:48:54 +03:00
|
|
|
if (bw->scroll_x != NULL) {
|
|
|
|
scrollbar_set(bw->scroll_x, rect->x0, false);
|
2011-07-06 00:13:28 +04:00
|
|
|
}
|
2017-04-26 22:48:54 +03:00
|
|
|
if (bw->scroll_y != NULL) {
|
|
|
|
scrollbar_set(bw->scroll_y, rect->y0, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NSERROR_OK;
|
2011-07-06 00:13:28 +04:00
|
|
|
}
|
|
|
|
|
2011-09-06 22:11:10 +04:00
|
|
|
/**
|
2014-11-02 18:46:42 +03:00
|
|
|
* Internal helper for getting the positional features
|
|
|
|
*
|
|
|
|
* \param[in] bw browser window to examine.
|
|
|
|
* \param[in] x x-coordinate of point of interest
|
|
|
|
* \param[in] y y-coordinate of point of interest
|
|
|
|
* \param[out] data Feature structure to update.
|
|
|
|
* \return NSERROR_OK or appropriate error code on faliure.
|
2011-09-06 22:11:10 +04:00
|
|
|
*/
|
2014-11-02 18:46:42 +03:00
|
|
|
static nserror
|
|
|
|
browser_window__get_contextual_content(struct browser_window *bw,
|
|
|
|
int x, int y, struct browser_window_features *data)
|
2011-09-06 22:11:10 +04:00
|
|
|
{
|
2014-11-02 18:46:42 +03:00
|
|
|
nserror ret = NSERROR_OK;
|
|
|
|
|
2011-09-06 22:39:28 +04:00
|
|
|
/* Handle (i)frame scroll offset (core-managed browser windows only) */
|
|
|
|
x += scrollbar_get_offset(bw->scroll_x);
|
|
|
|
y += scrollbar_get_offset(bw->scroll_y);
|
|
|
|
|
2011-09-06 22:11:10 +04:00
|
|
|
if (bw->children) {
|
|
|
|
/* Browser window has children, so pass request on to
|
2014-11-02 18:46:42 +03:00
|
|
|
* appropriate child.
|
|
|
|
*/
|
2011-09-06 22:11:10 +04:00
|
|
|
struct browser_window *bwc;
|
|
|
|
int cur_child;
|
|
|
|
int children = bw->rows * bw->cols;
|
|
|
|
|
|
|
|
/* Loop through all children of bw */
|
|
|
|
for (cur_child = 0; cur_child < children; cur_child++) {
|
|
|
|
/* Set current child */
|
|
|
|
bwc = &bw->children[cur_child];
|
|
|
|
|
|
|
|
/* Skip this frame if (x, y) coord lies outside */
|
2014-11-02 18:46:42 +03:00
|
|
|
if ((x < bwc->x) ||
|
|
|
|
(bwc->x + bwc->width < x) ||
|
|
|
|
(y < bwc->y) ||
|
|
|
|
(bwc->y + bwc->height < y)) {
|
2011-09-06 22:11:10 +04:00
|
|
|
continue;
|
2014-11-02 18:46:42 +03:00
|
|
|
}
|
2011-09-06 22:11:10 +04:00
|
|
|
|
|
|
|
/* Pass request into this child */
|
2014-11-02 18:46:42 +03:00
|
|
|
return browser_window__get_contextual_content(bwc,
|
2011-09-06 22:11:10 +04:00
|
|
|
(x - bwc->x), (y - bwc->y), data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Coordinate not contained by any frame */
|
|
|
|
|
2014-11-02 18:46:42 +03:00
|
|
|
} else if (bw->current_content != NULL) {
|
|
|
|
/* Pass request to content */
|
|
|
|
ret = content_get_contextual_content(bw->current_content,
|
|
|
|
x, y, data);
|
|
|
|
data->main = bw->current_content;
|
|
|
|
}
|
2011-09-06 22:11:10 +04:00
|
|
|
|
2014-11-02 18:46:42 +03:00
|
|
|
return ret;
|
2011-09-06 22:11:10 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* exported interface, documented in browser.h */
|
2014-11-02 18:46:42 +03:00
|
|
|
nserror browser_window_get_features(struct browser_window *bw,
|
|
|
|
int x, int y, struct browser_window_features *data)
|
2011-09-06 22:11:10 +04:00
|
|
|
{
|
2014-11-02 18:46:42 +03:00
|
|
|
/* clear the features structure to empty values */
|
|
|
|
data->link = NULL;
|
2011-09-06 22:11:10 +04:00
|
|
|
data->object = NULL;
|
|
|
|
data->main = NULL;
|
2012-08-21 01:02:37 +04:00
|
|
|
data->form_features = CTX_FORM_NONE;
|
2011-09-06 22:11:10 +04:00
|
|
|
|
2014-11-02 18:46:42 +03:00
|
|
|
return browser_window__get_contextual_content(bw, x, y, data);
|
2011-09-06 22:11:10 +04:00
|
|
|
}
|
|
|
|
|
2011-11-29 18:20:25 +04:00
|
|
|
/* exported interface, documented in browser.h */
|
|
|
|
bool browser_window_scroll_at_point(struct browser_window *bw,
|
|
|
|
int x, int y, int scrx, int scry)
|
|
|
|
{
|
|
|
|
bool handled_scroll = false;
|
|
|
|
assert(bw != NULL);
|
|
|
|
|
2011-12-02 20:10:13 +04:00
|
|
|
/* Handle (i)frame scroll offset (core-managed browser windows only) */
|
|
|
|
x += scrollbar_get_offset(bw->scroll_x);
|
|
|
|
y += scrollbar_get_offset(bw->scroll_y);
|
|
|
|
|
2011-11-29 18:20:25 +04:00
|
|
|
if (bw->children) {
|
|
|
|
/* Browser window has children, so pass request on to
|
|
|
|
* appropriate child */
|
|
|
|
struct browser_window *bwc;
|
|
|
|
int cur_child;
|
|
|
|
int children = bw->rows * bw->cols;
|
|
|
|
|
|
|
|
/* Loop through all children of bw */
|
|
|
|
for (cur_child = 0; cur_child < children; cur_child++) {
|
|
|
|
/* Set current child */
|
|
|
|
bwc = &bw->children[cur_child];
|
|
|
|
|
|
|
|
/* Skip this frame if (x, y) coord lies outside */
|
|
|
|
if (x < bwc->x || bwc->x + bwc->width < x ||
|
|
|
|
y < bwc->y || bwc->y + bwc->height < y)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* Pass request into this child */
|
|
|
|
return browser_window_scroll_at_point(bwc,
|
|
|
|
(x - bwc->x), (y - bwc->y),
|
|
|
|
scrx, scry);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-29 21:47:29 +04:00
|
|
|
/* Try to scroll any current content */
|
|
|
|
if (bw->current_content != NULL && content_scroll_at_point(
|
|
|
|
bw->current_content, x, y, scrx, scry) == true)
|
|
|
|
/* Scroll handled by current content */
|
|
|
|
return true;
|
2011-11-29 18:20:25 +04:00
|
|
|
|
|
|
|
/* Try to scroll this window, if scroll not already handled */
|
|
|
|
if (handled_scroll == false) {
|
|
|
|
if (bw->scroll_y && scrollbar_scroll(bw->scroll_y, scry))
|
|
|
|
handled_scroll = true;
|
|
|
|
|
|
|
|
if (bw->scroll_x && scrollbar_scroll(bw->scroll_x, scrx))
|
|
|
|
handled_scroll = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return handled_scroll;
|
|
|
|
}
|
|
|
|
|
2011-12-02 01:51:04 +04:00
|
|
|
/* exported interface, documented in browser.h */
|
|
|
|
bool browser_window_drop_file_at_point(struct browser_window *bw,
|
|
|
|
int x, int y, char *file)
|
|
|
|
{
|
|
|
|
assert(bw != NULL);
|
|
|
|
|
2011-12-02 20:10:13 +04:00
|
|
|
/* Handle (i)frame scroll offset (core-managed browser windows only) */
|
|
|
|
x += scrollbar_get_offset(bw->scroll_x);
|
|
|
|
y += scrollbar_get_offset(bw->scroll_y);
|
|
|
|
|
2011-12-02 01:51:04 +04:00
|
|
|
if (bw->children) {
|
|
|
|
/* Browser window has children, so pass request on to
|
|
|
|
* appropriate child */
|
|
|
|
struct browser_window *bwc;
|
|
|
|
int cur_child;
|
|
|
|
int children = bw->rows * bw->cols;
|
|
|
|
|
|
|
|
/* Loop through all children of bw */
|
|
|
|
for (cur_child = 0; cur_child < children; cur_child++) {
|
|
|
|
/* Set current child */
|
|
|
|
bwc = &bw->children[cur_child];
|
|
|
|
|
|
|
|
/* Skip this frame if (x, y) coord lies outside */
|
|
|
|
if (x < bwc->x || bwc->x + bwc->width < x ||
|
|
|
|
y < bwc->y || bwc->y + bwc->height < y)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* Pass request into this child */
|
|
|
|
return browser_window_drop_file_at_point(bwc,
|
2011-12-02 20:10:13 +04:00
|
|
|
(x - bwc->x), (y - bwc->y),
|
|
|
|
file);
|
2011-12-02 01:51:04 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Pass file drop on to any content */
|
|
|
|
if (bw->current_content != NULL)
|
|
|
|
return content_drop_file_at_point(bw->current_content,
|
|
|
|
x, y, file);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-05-30 19:32:57 +03:00
|
|
|
/* exported interface, documented in netsurf/browser_window.h */
|
2014-01-05 20:04:35 +04:00
|
|
|
void browser_window_set_gadget_filename(struct browser_window *bw,
|
|
|
|
struct form_control *gadget, const char *fn)
|
|
|
|
{
|
2014-10-20 00:49:46 +04:00
|
|
|
html_set_file_gadget_filename(bw->current_content, gadget, fn);
|
2014-01-05 20:04:35 +04:00
|
|
|
}
|
|
|
|
|
2012-08-20 19:05:30 +04:00
|
|
|
/* exported interface, documented in browser.h */
|
2014-10-20 00:49:46 +04:00
|
|
|
nserror browser_window_debug_dump(struct browser_window *bw,
|
|
|
|
FILE *f, enum content_debug op)
|
2012-08-20 19:05:30 +04:00
|
|
|
{
|
2014-11-07 01:51:46 +03:00
|
|
|
if (bw->current_content != NULL) {
|
|
|
|
return content_debug_dump(bw->current_content, f, op);
|
2014-08-04 03:36:14 +04:00
|
|
|
}
|
2014-11-07 01:51:46 +03:00
|
|
|
return NSERROR_OK;
|
|
|
|
}
|
2014-08-04 03:36:14 +04:00
|
|
|
|
2014-11-07 01:51:46 +03:00
|
|
|
/* exported interface, documented in browser.h */
|
|
|
|
nserror browser_window_debug(struct browser_window *bw, enum content_debug op)
|
|
|
|
{
|
|
|
|
if (bw->current_content != NULL) {
|
|
|
|
return content_debug(bw->current_content, op);
|
|
|
|
}
|
|
|
|
return NSERROR_OK;
|
2012-08-20 19:05:30 +04:00
|
|
|
}
|
|
|
|
|
2013-05-22 21:40:21 +04:00
|
|
|
/** slow script handler
|
|
|
|
*/
|
|
|
|
static bool slow_script(void *ctx)
|
2013-05-20 02:48:55 +04:00
|
|
|
{
|
|
|
|
static int count = 0;
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("Continuing execution %d", count);
|
2013-05-20 02:48:55 +04:00
|
|
|
count++;
|
2013-05-22 21:40:21 +04:00
|
|
|
if (count > 1) {
|
|
|
|
count = 0;
|
2013-05-20 02:48:55 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2011-09-06 22:11:10 +04:00
|
|
|
|
2016-05-30 19:32:57 +03:00
|
|
|
/* exported interface, documented in netsurf/browser_window.h */
|
2014-02-10 18:08:45 +04:00
|
|
|
nserror browser_window_create(enum browser_window_create_flags flags,
|
|
|
|
nsurl *url, nsurl *referrer,
|
|
|
|
struct browser_window *existing,
|
|
|
|
struct browser_window **bw)
|
2002-10-15 14:41:12 +04:00
|
|
|
{
|
2014-02-10 18:08:45 +04:00
|
|
|
gui_window_create_flags gw_flags = GW_CREATE_NONE;
|
|
|
|
struct browser_window *ret;
|
2014-10-30 01:14:48 +03:00
|
|
|
nserror err;
|
2014-02-10 18:08:45 +04:00
|
|
|
|
|
|
|
/* Check parameters */
|
2014-07-25 17:34:46 +04:00
|
|
|
if (flags & BW_CREATE_CLONE) {
|
2014-02-10 18:08:45 +04:00
|
|
|
if (existing == NULL) {
|
|
|
|
assert(0 && "Failed: No existing window provided.");
|
|
|
|
return NSERROR_BAD_PARAMETER;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!(flags & BW_CREATE_HISTORY)) {
|
|
|
|
if (!(flags & BW_CREATE_CLONE) || existing == NULL) {
|
|
|
|
assert(0 && "Failed: Must have existing for history.");
|
|
|
|
return NSERROR_BAD_PARAMETER;
|
|
|
|
}
|
|
|
|
}
|
2006-04-22 22:24:18 +04:00
|
|
|
|
2013-02-14 22:21:11 +04:00
|
|
|
|
2014-02-10 18:08:45 +04:00
|
|
|
if ((ret = calloc(1, sizeof(struct browser_window))) == NULL) {
|
2013-02-14 22:21:11 +04:00
|
|
|
return NSERROR_NOMEM;
|
2004-02-25 18:12:58 +03:00
|
|
|
}
|
2002-09-11 18:24:02 +04:00
|
|
|
|
2007-08-07 11:58:04 +04:00
|
|
|
/* Initialise common parts */
|
2014-10-30 01:14:48 +03:00
|
|
|
err = browser_window_initialise_common(flags, ret, existing);
|
|
|
|
if (err != NSERROR_OK) {
|
|
|
|
browser_window_destroy(ret);
|
|
|
|
return err;
|
|
|
|
}
|
2006-09-02 19:52:41 +04:00
|
|
|
|
|
|
|
/* window characteristics */
|
2014-02-10 18:08:45 +04:00
|
|
|
ret->browser_window_type = BROWSER_WINDOW_NORMAL;
|
2014-10-25 15:04:11 +04:00
|
|
|
ret->scrolling = BW_SCROLLING_YES;
|
2014-02-10 18:08:45 +04:00
|
|
|
ret->border = true;
|
|
|
|
ret->no_resize = true;
|
|
|
|
ret->focus = ret;
|
|
|
|
|
2016-04-21 15:12:56 +03:00
|
|
|
/* initialise last action with creation time */
|
|
|
|
nsu_getmonotonic_ms(&ret->last_action);
|
|
|
|
|
2014-02-10 18:08:45 +04:00
|
|
|
/* The existing gui_window is on the top-level existing
|
|
|
|
* browser_window. */
|
|
|
|
existing = browser_window_get_root(existing);
|
|
|
|
|
|
|
|
/* Set up gui_window creation flags */
|
|
|
|
if (flags & BW_CREATE_TAB)
|
|
|
|
gw_flags |= GW_CREATE_TAB;
|
|
|
|
if (flags & BW_CREATE_CLONE)
|
|
|
|
gw_flags |= GW_CREATE_CLONE;
|
|
|
|
|
|
|
|
ret->window = guit->window->create(ret,
|
|
|
|
(existing != NULL) ? existing->window : NULL,
|
|
|
|
gw_flags);
|
|
|
|
|
|
|
|
if (ret->window == NULL) {
|
|
|
|
browser_window_destroy(ret);
|
2013-02-14 22:21:11 +04:00
|
|
|
return NSERROR_BAD_PARAMETER;
|
2004-02-25 18:12:58 +03:00
|
|
|
}
|
2010-04-24 19:22:17 +04:00
|
|
|
|
2013-02-14 19:09:28 +04:00
|
|
|
if (url != NULL) {
|
2014-02-10 18:08:45 +04:00
|
|
|
enum browser_window_nav_flags nav_flags = BW_NAVIGATE_NONE;
|
2014-02-11 02:40:04 +04:00
|
|
|
if (flags & BW_CREATE_UNVERIFIABLE)
|
|
|
|
nav_flags |= BW_NAVIGATE_UNVERIFIABLE;
|
2014-02-10 18:08:45 +04:00
|
|
|
if (flags & BW_CREATE_HISTORY)
|
|
|
|
nav_flags |= BW_NAVIGATE_HISTORY;
|
|
|
|
browser_window_navigate(ret, url, referrer, nav_flags, NULL,
|
|
|
|
NULL, NULL);
|
2012-01-02 01:42:38 +04:00
|
|
|
}
|
2007-01-27 23:58:20 +03:00
|
|
|
|
2014-02-10 18:08:45 +04:00
|
|
|
if (bw != NULL) {
|
|
|
|
*bw = ret;
|
2013-02-14 22:21:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return NSERROR_OK;
|
2002-09-11 18:24:02 +04:00
|
|
|
}
|
|
|
|
|
2004-02-25 18:12:58 +03:00
|
|
|
|
2014-10-19 22:12:55 +04:00
|
|
|
/* exported internal interface, documented in desktop/browser_private.h */
|
2014-02-15 22:43:59 +04:00
|
|
|
nserror browser_window_initialise_common(enum browser_window_create_flags flags,
|
2014-02-10 18:08:45 +04:00
|
|
|
struct browser_window *bw, struct browser_window *existing)
|
2007-08-07 11:58:04 +04:00
|
|
|
{
|
2014-02-15 22:43:59 +04:00
|
|
|
nserror err;
|
2007-08-07 11:58:04 +04:00
|
|
|
assert(bw);
|
|
|
|
|
2015-08-13 11:48:09 +03:00
|
|
|
/* new javascript context for each window/(i)frame */
|
2015-08-13 14:23:59 +03:00
|
|
|
err = js_newcontext(nsoption_int(script_timeout),
|
|
|
|
slow_script, NULL, &bw->jsctx);
|
|
|
|
if (err != NSERROR_OK)
|
|
|
|
return err;
|
2015-08-13 11:39:04 +03:00
|
|
|
|
2014-02-10 18:08:45 +04:00
|
|
|
if (flags & BW_CREATE_CLONE) {
|
|
|
|
assert(existing != NULL);
|
2014-07-06 21:34:34 +04:00
|
|
|
|
|
|
|
/* clone history */
|
2014-02-15 22:43:59 +04:00
|
|
|
err = browser_window_history_clone(existing, bw);
|
2014-07-06 21:34:34 +04:00
|
|
|
|
|
|
|
/* copy the scale */
|
|
|
|
bw->scale = existing->scale;
|
2014-02-10 18:08:45 +04:00
|
|
|
} else {
|
2014-07-06 21:34:34 +04:00
|
|
|
/* create history */
|
2014-02-15 22:43:59 +04:00
|
|
|
err = browser_window_history_create(bw);
|
2014-07-06 21:34:34 +04:00
|
|
|
|
|
|
|
/* default scale */
|
|
|
|
bw->scale = (float) nsoption_int(scale) / 100.0;
|
2014-02-10 18:08:45 +04:00
|
|
|
}
|
2007-08-07 11:58:04 +04:00
|
|
|
|
2014-02-15 22:43:59 +04:00
|
|
|
if (err != NSERROR_OK)
|
|
|
|
return err;
|
|
|
|
|
2007-08-07 11:58:04 +04:00
|
|
|
/* window characteristics */
|
|
|
|
bw->refresh_interval = -1;
|
|
|
|
|
2017-03-03 17:30:39 +03:00
|
|
|
bw->drag.type = DRAGGING_NONE;
|
2010-02-11 02:37:06 +03:00
|
|
|
|
2011-07-06 00:13:28 +04:00
|
|
|
bw->scroll_x = NULL;
|
|
|
|
bw->scroll_y = NULL;
|
|
|
|
|
2011-06-15 00:00:18 +04:00
|
|
|
bw->focus = NULL;
|
|
|
|
|
2010-02-11 13:58:26 +03:00
|
|
|
/* initialise status text cache */
|
2017-03-03 12:28:54 +03:00
|
|
|
bw->status.text = NULL;
|
|
|
|
bw->status.text_len = 0;
|
|
|
|
bw->status.match = 0;
|
|
|
|
bw->status.miss = 0;
|
2014-02-15 22:43:59 +04:00
|
|
|
|
|
|
|
return NSERROR_OK;
|
2007-08-07 11:58:04 +04:00
|
|
|
}
|
|
|
|
|
2009-01-30 08:07:07 +03:00
|
|
|
/**
|
2013-02-14 19:09:28 +04:00
|
|
|
* implements the download operation of a window navigate
|
2009-01-30 08:07:07 +03:00
|
|
|
*/
|
2014-10-20 00:49:46 +04:00
|
|
|
static nserror
|
2013-02-14 19:09:28 +04:00
|
|
|
browser_window_download(struct browser_window *bw,
|
|
|
|
nsurl *url,
|
2014-10-20 00:49:46 +04:00
|
|
|
nsurl *nsref,
|
2013-02-14 19:09:28 +04:00
|
|
|
uint32_t fetch_flags,
|
|
|
|
bool fetch_is_post,
|
|
|
|
llcache_post_data *post)
|
2009-01-30 08:07:07 +03:00
|
|
|
{
|
2013-02-14 19:09:28 +04:00
|
|
|
llcache_handle *l;
|
|
|
|
struct browser_window *root;
|
|
|
|
nserror error;
|
2009-01-30 08:07:07 +03:00
|
|
|
|
2013-02-14 19:09:28 +04:00
|
|
|
root = browser_window_get_root(bw);
|
|
|
|
assert(root != NULL);
|
2009-01-30 08:07:07 +03:00
|
|
|
|
2013-02-14 19:09:28 +04:00
|
|
|
fetch_flags |= LLCACHE_RETRIEVE_FORCE_FETCH;
|
|
|
|
fetch_flags |= LLCACHE_RETRIEVE_STREAM_DATA;
|
|
|
|
|
2014-10-20 00:49:46 +04:00
|
|
|
error = llcache_handle_retrieve(url, fetch_flags, nsref,
|
2013-02-14 19:09:28 +04:00
|
|
|
fetch_is_post ? post : NULL,
|
|
|
|
NULL, NULL, &l);
|
|
|
|
if (error == NSERROR_NO_FETCH_HANDLER) {
|
|
|
|
/* no internal handler for this type, call out to frontend */
|
2016-04-16 00:50:28 +03:00
|
|
|
error = guit->misc->launch_url(url);
|
2013-02-14 19:09:28 +04:00
|
|
|
} else if (error != NSERROR_OK) {
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("Failed to fetch download: %d", error);
|
2013-02-14 19:09:28 +04:00
|
|
|
} else {
|
|
|
|
error = download_context_create(l, root->window);
|
|
|
|
if (error != NSERROR_OK) {
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("Failed creating download context: %d", error);
|
2013-02-14 19:09:28 +04:00
|
|
|
llcache_handle_abort(l);
|
|
|
|
llcache_handle_release(l);
|
|
|
|
}
|
|
|
|
}
|
2007-01-27 23:58:20 +03:00
|
|
|
|
2013-02-14 19:09:28 +04:00
|
|
|
return error;
|
2007-01-27 23:58:20 +03:00
|
|
|
}
|
|
|
|
|
2010-03-28 16:56:39 +04:00
|
|
|
|
2013-07-12 16:50:17 +04:00
|
|
|
static bool browser_window_check_throbber(struct browser_window *bw)
|
|
|
|
{
|
|
|
|
int children, index;
|
2004-02-25 18:12:58 +03:00
|
|
|
|
2013-07-12 16:50:17 +04:00
|
|
|
if (bw->throbbing)
|
|
|
|
return true;
|
2011-09-28 15:26:30 +04:00
|
|
|
|
2013-07-12 16:50:17 +04:00
|
|
|
if (bw->children) {
|
|
|
|
children = bw->rows * bw->cols;
|
|
|
|
for (index = 0; index < children; index++) {
|
|
|
|
if (browser_window_check_throbber(&bw->children[index]))
|
|
|
|
return true;
|
2011-02-22 00:47:55 +03:00
|
|
|
}
|
2004-11-23 02:29:50 +03:00
|
|
|
}
|
2013-07-12 16:50:17 +04:00
|
|
|
if (bw->iframes) {
|
|
|
|
for (index = 0; index < bw->iframe_count; index++) {
|
|
|
|
if (browser_window_check_throbber(&bw->iframes[index]))
|
|
|
|
return true;
|
2005-03-20 06:35:50 +03:00
|
|
|
}
|
2004-08-07 02:19:13 +04:00
|
|
|
}
|
2013-07-12 16:50:17 +04:00
|
|
|
return false;
|
|
|
|
}
|
2004-08-07 02:19:13 +04:00
|
|
|
|
2010-03-28 16:56:39 +04:00
|
|
|
|
2013-07-12 16:50:17 +04:00
|
|
|
/**
|
|
|
|
* Start the busy indicator.
|
|
|
|
*
|
2014-10-19 22:12:55 +04:00
|
|
|
* \param bw browser window
|
2013-07-12 16:50:17 +04:00
|
|
|
*/
|
2011-10-10 12:56:34 +04:00
|
|
|
|
2013-07-12 16:50:17 +04:00
|
|
|
static void browser_window_start_throbber(struct browser_window *bw)
|
|
|
|
{
|
|
|
|
bw->throbbing = true;
|
2012-06-11 02:17:30 +04:00
|
|
|
|
2013-07-12 16:50:17 +04:00
|
|
|
while (bw->parent)
|
|
|
|
bw = bw->parent;
|
2012-06-11 02:17:30 +04:00
|
|
|
|
2014-01-12 21:07:34 +04:00
|
|
|
guit->window->start_throbber(bw->window);
|
2013-07-12 16:50:17 +04:00
|
|
|
}
|
2012-06-11 02:17:30 +04:00
|
|
|
|
2004-08-07 02:19:13 +04:00
|
|
|
|
2013-07-12 16:50:17 +04:00
|
|
|
/**
|
|
|
|
* Stop the busy indicator.
|
|
|
|
*
|
|
|
|
* \param bw browser window
|
|
|
|
*/
|
|
|
|
static void browser_window_stop_throbber(struct browser_window *bw)
|
|
|
|
{
|
|
|
|
bw->throbbing = false;
|
2013-02-14 19:09:28 +04:00
|
|
|
|
2013-07-12 16:50:17 +04:00
|
|
|
while (bw->parent)
|
|
|
|
bw = bw->parent;
|
2013-02-14 19:09:28 +04:00
|
|
|
|
2014-01-12 14:27:41 +04:00
|
|
|
if (!browser_window_check_throbber(bw)) {
|
2014-01-12 21:07:34 +04:00
|
|
|
guit->window->stop_throbber(bw->window);
|
2014-01-12 14:27:41 +04:00
|
|
|
}
|
2002-09-11 18:24:02 +04:00
|
|
|
}
|
|
|
|
|
2011-10-07 22:12:47 +04:00
|
|
|
|
|
|
|
|
2011-10-07 03:31:55 +04:00
|
|
|
/**
|
|
|
|
* Callback for fetchcache() for browser window favicon fetches.
|
2017-03-03 13:41:43 +03:00
|
|
|
*
|
|
|
|
* \param c content handle of favicon
|
|
|
|
* \param event The event to process
|
|
|
|
* \param pw a context containing the browser window
|
|
|
|
* \return NSERROR_OK on success else appropriate error code.
|
2011-10-07 03:31:55 +04:00
|
|
|
*/
|
2017-03-03 13:41:43 +03:00
|
|
|
static nserror
|
|
|
|
browser_window_favicon_callback(hlcache_handle *c,
|
|
|
|
const hlcache_event *event,
|
|
|
|
void *pw)
|
2011-10-07 03:31:55 +04:00
|
|
|
{
|
|
|
|
struct browser_window *bw = pw;
|
|
|
|
|
|
|
|
switch (event->type) {
|
|
|
|
case CONTENT_MSG_DONE:
|
2017-03-03 13:41:43 +03:00
|
|
|
if (bw->favicon.current != NULL) {
|
2014-10-20 00:49:46 +04:00
|
|
|
content_status status =
|
2017-03-03 13:41:43 +03:00
|
|
|
content_get_status(bw->favicon.current);
|
2011-10-07 22:12:47 +04:00
|
|
|
|
|
|
|
if ((status == CONTENT_STATUS_READY) ||
|
2011-10-08 14:22:34 +04:00
|
|
|
(status == CONTENT_STATUS_DONE))
|
2017-03-03 13:41:43 +03:00
|
|
|
content_close(bw->favicon.current);
|
2011-10-07 22:12:47 +04:00
|
|
|
|
2017-03-03 13:41:43 +03:00
|
|
|
hlcache_handle_release(bw->favicon.current);
|
2011-10-07 22:12:47 +04:00
|
|
|
}
|
|
|
|
|
2017-03-03 13:41:43 +03:00
|
|
|
bw->favicon.current = c;
|
|
|
|
bw->favicon.loading = NULL;
|
2011-10-07 22:12:47 +04:00
|
|
|
|
2014-10-20 00:49:46 +04:00
|
|
|
/* content_get_bitmap on the hlcache_handle should give
|
2017-03-03 13:41:43 +03:00
|
|
|
* the favicon bitmap at this point
|
2011-10-07 22:12:47 +04:00
|
|
|
*/
|
2014-01-12 21:07:34 +04:00
|
|
|
guit->window->set_icon(bw->window, c);
|
2011-10-07 03:31:55 +04:00
|
|
|
break;
|
|
|
|
|
2011-10-07 22:12:47 +04:00
|
|
|
case CONTENT_MSG_ERROR:
|
2017-08-28 13:04:42 +03:00
|
|
|
case CONTENT_MSG_ERRORCODE:
|
2011-10-07 22:12:47 +04:00
|
|
|
|
|
|
|
/* clean up after ourselves */
|
2017-03-03 13:41:43 +03:00
|
|
|
if (c == bw->favicon.loading) {
|
|
|
|
bw->favicon.loading = NULL;
|
|
|
|
} else if (c == bw->favicon.current) {
|
|
|
|
bw->favicon.current = NULL;
|
2011-10-07 22:12:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
hlcache_handle_release(c);
|
|
|
|
|
2017-03-03 13:41:43 +03:00
|
|
|
if (bw->favicon.failed == false) {
|
2011-10-08 02:22:15 +04:00
|
|
|
nsurl *nsref = NULL;
|
|
|
|
nsurl *nsurl;
|
|
|
|
nserror error;
|
|
|
|
|
2017-03-03 13:41:43 +03:00
|
|
|
bw->favicon.failed = true;
|
2011-10-08 02:22:15 +04:00
|
|
|
|
|
|
|
error = nsurl_create("resource:favicon.ico", &nsurl);
|
|
|
|
if (error != NSERROR_OK) {
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("Unable to create default location url");
|
2011-10-08 02:22:15 +04:00
|
|
|
} else {
|
|
|
|
hlcache_handle_retrieve(nsurl,
|
2014-10-20 00:49:46 +04:00
|
|
|
HLCACHE_RETRIEVE_SNIFF_TYPE,
|
2011-10-08 14:22:34 +04:00
|
|
|
nsref, NULL,
|
|
|
|
browser_window_favicon_callback,
|
2014-10-20 00:49:46 +04:00
|
|
|
bw, NULL, CONTENT_IMAGE,
|
2017-03-03 13:41:43 +03:00
|
|
|
&bw->favicon.loading);
|
2011-10-08 02:22:15 +04:00
|
|
|
|
|
|
|
nsurl_unref(nsurl);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2011-10-07 22:12:47 +04:00
|
|
|
break;
|
|
|
|
|
2011-10-07 03:31:55 +04:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return NSERROR_OK;
|
|
|
|
}
|
2002-09-11 18:24:02 +04:00
|
|
|
|
2017-03-03 13:41:43 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* update the favicon associated with the browser window
|
|
|
|
*
|
|
|
|
* \param c the page content handle.
|
|
|
|
* \param bw A top level browser window.
|
|
|
|
* \param link A link context or NULL to attempt fallback scanning.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
browser_window_update_favicon(hlcache_handle *c,
|
|
|
|
struct browser_window *bw,
|
|
|
|
struct content_rfc5988_link *link)
|
2011-10-07 22:12:47 +04:00
|
|
|
{
|
2011-10-07 22:49:16 +04:00
|
|
|
nsurl *nsref = NULL;
|
|
|
|
nsurl *nsurl;
|
|
|
|
nserror error;
|
2011-10-07 22:12:47 +04:00
|
|
|
|
2011-10-07 22:49:16 +04:00
|
|
|
assert(c != NULL);
|
|
|
|
assert(bw !=NULL);
|
2011-10-08 01:49:29 +04:00
|
|
|
|
|
|
|
if (bw->window == NULL)
|
|
|
|
/* Not top-level browser window; not interested */
|
|
|
|
return;
|
2014-10-20 00:49:46 +04:00
|
|
|
|
2011-10-07 22:12:47 +04:00
|
|
|
/* already fetching the favicon - use that */
|
2017-03-03 13:41:43 +03:00
|
|
|
if (bw->favicon.loading != NULL)
|
2011-10-07 22:12:47 +04:00
|
|
|
return;
|
|
|
|
|
2017-03-03 13:41:43 +03:00
|
|
|
bw->favicon.failed = false;
|
2011-10-08 02:22:15 +04:00
|
|
|
|
2011-10-07 22:49:16 +04:00
|
|
|
if (link == NULL) {
|
2014-01-25 03:13:18 +04:00
|
|
|
/* Look for "icon" */
|
|
|
|
link = content_find_rfc5988_link(c, corestring_lwc_icon);
|
2011-10-07 22:49:16 +04:00
|
|
|
}
|
2011-10-07 22:12:47 +04:00
|
|
|
|
|
|
|
if (link == NULL) {
|
2014-01-25 03:13:18 +04:00
|
|
|
/* Look for "shortcut icon" */
|
|
|
|
link = content_find_rfc5988_link(c,
|
|
|
|
corestring_lwc_shortcut_icon);
|
2011-10-07 22:12:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (link == NULL) {
|
2011-10-08 00:47:34 +04:00
|
|
|
lwc_string *scheme;
|
2011-10-08 04:06:43 +04:00
|
|
|
bool speculative_default = false;
|
2014-01-25 01:47:15 +04:00
|
|
|
bool match;
|
2011-10-08 00:47:34 +04:00
|
|
|
|
2011-12-04 18:55:23 +04:00
|
|
|
nsurl = hlcache_handle_get_url(c);
|
2011-10-08 00:47:34 +04:00
|
|
|
|
|
|
|
scheme = nsurl_get_component(nsurl, NSURL_SCHEME);
|
|
|
|
|
2014-10-20 00:49:46 +04:00
|
|
|
/* If the document was fetched over http(s), then speculate
|
2011-10-08 04:06:43 +04:00
|
|
|
* that there's a favicon living at /favicon.ico */
|
2014-01-25 01:47:15 +04:00
|
|
|
if ((lwc_string_caseless_isequal(scheme, corestring_lwc_http,
|
|
|
|
&match) == lwc_error_ok && match) ||
|
|
|
|
(lwc_string_caseless_isequal(scheme, corestring_lwc_https,
|
|
|
|
&match) == lwc_error_ok && match)) {
|
2011-10-08 04:06:43 +04:00
|
|
|
speculative_default = true;
|
|
|
|
}
|
2011-10-08 00:47:34 +04:00
|
|
|
|
|
|
|
lwc_string_unref(scheme);
|
|
|
|
|
2011-10-08 04:06:43 +04:00
|
|
|
if (speculative_default) {
|
2011-10-08 00:47:34 +04:00
|
|
|
/* no favicon via link, try for the default location */
|
|
|
|
error = nsurl_join(nsurl, "/favicon.ico", &nsurl);
|
|
|
|
} else {
|
2017-03-03 13:41:43 +03:00
|
|
|
bw->favicon.failed = true;
|
2011-10-08 01:03:45 +04:00
|
|
|
error = nsurl_create("resource:favicon.ico", &nsurl);
|
2011-10-08 00:47:34 +04:00
|
|
|
}
|
2011-10-07 22:12:47 +04:00
|
|
|
if (error != NSERROR_OK) {
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("Unable to create default location url");
|
2011-10-07 22:12:47 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
2011-10-08 02:18:27 +04:00
|
|
|
nsurl = nsurl_ref(link->href);
|
2011-10-07 22:12:47 +04:00
|
|
|
}
|
|
|
|
|
2011-10-07 22:49:16 +04:00
|
|
|
if (link == NULL) {
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("fetching general favicon from '%s'", nsurl_access(nsurl));
|
2011-10-07 22:49:16 +04:00
|
|
|
} else {
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("fetching favicon rel:%s '%s'", lwc_string_data(link->rel), nsurl_access(nsurl));
|
2011-10-07 22:49:16 +04:00
|
|
|
}
|
|
|
|
|
2014-10-20 00:49:46 +04:00
|
|
|
hlcache_handle_retrieve(nsurl, HLCACHE_RETRIEVE_SNIFF_TYPE,
|
|
|
|
nsref, NULL, browser_window_favicon_callback,
|
2017-03-03 13:41:43 +03:00
|
|
|
bw, NULL, CONTENT_IMAGE, &bw->favicon.loading);
|
2011-10-07 22:12:47 +04:00
|
|
|
|
|
|
|
nsurl_unref(nsurl);
|
|
|
|
}
|
|
|
|
|
2014-10-19 22:12:55 +04:00
|
|
|
/**
|
|
|
|
* window callback errorcode handling.
|
|
|
|
*/
|
2014-10-20 00:49:46 +04:00
|
|
|
static void
|
2012-10-18 00:52:43 +04:00
|
|
|
browser_window_callback_errorcode(hlcache_handle *c,
|
2014-10-20 00:49:46 +04:00
|
|
|
struct browser_window *bw,
|
2012-10-18 00:52:43 +04:00
|
|
|
nserror code)
|
|
|
|
{
|
|
|
|
const char* message;
|
|
|
|
|
2012-11-26 21:20:15 +04:00
|
|
|
message = messages_get_errorcode(code);
|
2012-10-18 00:52:43 +04:00
|
|
|
|
|
|
|
browser_window_set_status(bw, message);
|
|
|
|
|
|
|
|
/* Only warn the user about errors in top-level windows */
|
|
|
|
if (bw->browser_window_type == BROWSER_WINDOW_NORMAL) {
|
2016-04-26 14:50:16 +03:00
|
|
|
guit->misc->warning(message, NULL);
|
2012-10-18 00:52:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (c == bw->loading_content) {
|
|
|
|
bw->loading_content = NULL;
|
|
|
|
} else if (c == bw->current_content) {
|
|
|
|
bw->current_content = NULL;
|
2013-02-22 16:19:35 +04:00
|
|
|
browser_window_remove_caret(bw, false);
|
2012-10-18 00:52:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
hlcache_handle_release(c);
|
|
|
|
|
|
|
|
browser_window_stop_throbber(bw);
|
|
|
|
}
|
|
|
|
|
2013-07-12 16:50:17 +04:00
|
|
|
|
2004-02-25 18:12:58 +03:00
|
|
|
/**
|
2013-07-12 16:50:17 +04:00
|
|
|
* Handle meta http-equiv refresh time elapsing by loading a new page.
|
|
|
|
*
|
2014-10-19 22:12:55 +04:00
|
|
|
* \param p browser window to refresh with new page
|
2004-02-25 18:12:58 +03:00
|
|
|
*/
|
2013-07-12 16:50:17 +04:00
|
|
|
static void browser_window_refresh(void *p)
|
2002-09-11 18:24:02 +04:00
|
|
|
{
|
2013-07-12 16:50:17 +04:00
|
|
|
struct browser_window *bw = p;
|
|
|
|
nsurl *url;
|
|
|
|
nsurl *refresh;
|
|
|
|
hlcache_handle *parent = NULL;
|
2014-02-11 02:40:04 +04:00
|
|
|
enum browser_window_nav_flags flags = BW_NAVIGATE_UNVERIFIABLE;
|
2010-04-06 01:35:38 +04:00
|
|
|
|
2013-07-12 16:50:17 +04:00
|
|
|
assert(bw->current_content != NULL &&
|
2014-10-20 00:49:46 +04:00
|
|
|
(content_get_status(bw->current_content) ==
|
2013-07-12 16:50:17 +04:00
|
|
|
CONTENT_STATUS_READY ||
|
2014-10-20 00:49:46 +04:00
|
|
|
content_get_status(bw->current_content) ==
|
2013-07-12 16:50:17 +04:00
|
|
|
CONTENT_STATUS_DONE));
|
2004-06-28 03:24:11 +04:00
|
|
|
|
2013-07-12 16:50:17 +04:00
|
|
|
/* Ignore if the refresh URL has gone
|
|
|
|
* (may happen if a fetch error occurred) */
|
|
|
|
refresh = content_get_refresh_url(bw->current_content);
|
|
|
|
if (refresh == NULL)
|
|
|
|
return;
|
2006-11-26 23:11:20 +03:00
|
|
|
|
2013-07-12 16:50:17 +04:00
|
|
|
/* mark this content as invalid so it gets flushed from the cache */
|
|
|
|
content_invalidate_reuse_data(bw->current_content);
|
2010-03-30 02:33:21 +04:00
|
|
|
|
2013-07-12 16:50:17 +04:00
|
|
|
url = hlcache_handle_get_url(bw->current_content);
|
|
|
|
if ((url == NULL) || (nsurl_compare(url, refresh, NSURL_COMPLETE))) {
|
2014-02-10 18:08:45 +04:00
|
|
|
flags |= BW_NAVIGATE_HISTORY;
|
2013-07-12 16:50:17 +04:00
|
|
|
}
|
2006-11-26 23:11:20 +03:00
|
|
|
|
2013-07-12 16:50:17 +04:00
|
|
|
/* Treat an (almost) immediate refresh in a top-level browser window as
|
|
|
|
* if it were an HTTP redirect, and thus make the resulting fetch
|
|
|
|
* verifiable.
|
|
|
|
*
|
|
|
|
* See fetchcache.c for why redirected fetches should be verifiable at
|
|
|
|
* all.
|
|
|
|
*/
|
|
|
|
if (bw->refresh_interval <= 100 && bw->parent == NULL) {
|
2014-02-11 02:40:04 +04:00
|
|
|
flags &= ~BW_NAVIGATE_UNVERIFIABLE;
|
2013-07-12 16:50:17 +04:00
|
|
|
} else {
|
|
|
|
parent = bw->current_content;
|
|
|
|
}
|
|
|
|
|
|
|
|
browser_window_navigate(bw,
|
|
|
|
refresh,
|
|
|
|
url,
|
|
|
|
flags,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
parent);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Transfer the loading_content to a new download window.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void browser_window_convert_to_download(struct browser_window *bw,
|
|
|
|
llcache_handle *stream)
|
|
|
|
{
|
|
|
|
struct browser_window *root = browser_window_get_root(bw);
|
|
|
|
nserror error;
|
|
|
|
|
|
|
|
assert(root != NULL);
|
|
|
|
|
|
|
|
error = download_context_create(stream, root->window);
|
|
|
|
if (error != NSERROR_OK) {
|
|
|
|
llcache_handle_abort(stream);
|
|
|
|
llcache_handle_release(stream);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* remove content from browser window */
|
|
|
|
hlcache_handle_release(bw->loading_content);
|
|
|
|
bw->loading_content = NULL;
|
|
|
|
|
|
|
|
browser_window_stop_throbber(bw);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2016-03-22 20:52:24 +03:00
|
|
|
* Browser window content event callback handler.
|
2013-07-12 16:50:17 +04:00
|
|
|
*/
|
2017-03-03 12:28:54 +03:00
|
|
|
static nserror
|
|
|
|
browser_window_callback(hlcache_handle *c,
|
|
|
|
const hlcache_event *event,
|
|
|
|
void *pw)
|
2013-07-12 16:50:17 +04:00
|
|
|
{
|
|
|
|
struct browser_window *bw = pw;
|
2016-04-26 12:26:00 +03:00
|
|
|
nserror res = NSERROR_OK;
|
2013-07-12 16:50:17 +04:00
|
|
|
|
|
|
|
switch (event->type) {
|
|
|
|
case CONTENT_MSG_DOWNLOAD:
|
|
|
|
assert(bw->loading_content == c);
|
|
|
|
|
|
|
|
browser_window_convert_to_download(bw, event->data.download);
|
|
|
|
|
|
|
|
if (bw->current_content != NULL) {
|
2014-02-08 16:07:13 +04:00
|
|
|
browser_window_refresh_url_bar(bw);
|
2013-07-12 16:50:17 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CONTENT_MSG_LOADING:
|
|
|
|
assert(bw->loading_content == c);
|
|
|
|
|
|
|
|
#ifdef WITH_THEME_INSTALL
|
|
|
|
if (content_get_type(c) == CONTENT_THEME) {
|
|
|
|
theme_install_start(c);
|
|
|
|
bw->loading_content = NULL;
|
|
|
|
browser_window_stop_throbber(bw);
|
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
bw->refresh_interval = -1;
|
2014-10-20 00:49:46 +04:00
|
|
|
browser_window_set_status(bw,
|
2013-07-12 16:50:17 +04:00
|
|
|
content_get_status_message(c));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CONTENT_MSG_READY:
|
|
|
|
{
|
|
|
|
int width, height;
|
|
|
|
|
|
|
|
assert(bw->loading_content == c);
|
|
|
|
|
|
|
|
if (bw->current_content != NULL) {
|
2014-10-20 00:49:46 +04:00
|
|
|
content_status status =
|
2010-03-28 16:56:39 +04:00
|
|
|
content_get_status(bw->current_content);
|
|
|
|
|
|
|
|
if (status == CONTENT_STATUS_READY ||
|
|
|
|
status == CONTENT_STATUS_DONE)
|
2006-11-26 23:11:20 +03:00
|
|
|
content_close(bw->current_content);
|
2010-03-28 16:56:39 +04:00
|
|
|
|
|
|
|
hlcache_handle_release(bw->current_content);
|
2006-11-26 23:11:20 +03:00
|
|
|
}
|
2010-03-28 16:56:39 +04:00
|
|
|
|
2010-04-14 13:23:46 +04:00
|
|
|
bw->current_content = c;
|
|
|
|
bw->loading_content = NULL;
|
|
|
|
|
2010-03-30 02:33:21 +04:00
|
|
|
/* Format the new content to the correct dimensions */
|
2011-06-15 00:00:18 +04:00
|
|
|
browser_window_get_dimensions(bw, &width, &height, true);
|
2011-06-24 13:30:33 +04:00
|
|
|
content_reformat(c, false, width, height);
|
2010-03-30 02:33:21 +04:00
|
|
|
|
2013-02-22 16:19:35 +04:00
|
|
|
browser_window_remove_caret(bw, false);
|
2010-03-28 16:56:39 +04:00
|
|
|
|
2013-10-23 16:48:26 +04:00
|
|
|
if (bw->window != NULL) {
|
2014-01-13 02:55:26 +04:00
|
|
|
guit->window->new_content(bw->window);
|
2010-03-28 16:56:39 +04:00
|
|
|
|
2014-02-08 16:07:13 +04:00
|
|
|
browser_window_refresh_url_bar(bw);
|
2013-10-23 16:48:26 +04:00
|
|
|
}
|
2010-03-28 16:56:39 +04:00
|
|
|
|
2009-04-08 15:07:30 +04:00
|
|
|
/* new content; set scroll_to_top */
|
|
|
|
browser_window_update(bw, true);
|
2012-08-20 17:22:28 +04:00
|
|
|
content_open(c, bw, 0, 0);
|
2010-03-28 16:56:39 +04:00
|
|
|
browser_window_set_status(bw, content_get_status_message(c));
|
2006-11-26 23:11:20 +03:00
|
|
|
|
|
|
|
/* history */
|
2009-04-05 23:17:24 +04:00
|
|
|
if (bw->history_add && bw->history) {
|
2012-10-08 23:34:04 +04:00
|
|
|
nsurl *url = hlcache_handle_get_url(c);
|
2010-03-28 16:56:39 +04:00
|
|
|
|
|
|
|
if (urldb_add_url(url)) {
|
|
|
|
urldb_set_url_title(url, content_get_title(c));
|
|
|
|
urldb_update_url_visit_data(url);
|
2014-10-20 00:49:46 +04:00
|
|
|
urldb_set_url_content_type(url,
|
2010-03-28 16:56:39 +04:00
|
|
|
content_get_type(c));
|
2013-07-16 16:15:22 +04:00
|
|
|
|
2010-03-28 16:56:39 +04:00
|
|
|
/* This is safe as we've just added the URL */
|
2013-09-02 15:29:16 +04:00
|
|
|
global_history_add(urldb_get_url(url));
|
2006-02-16 02:09:55 +03:00
|
|
|
}
|
2014-10-30 01:47:25 +03:00
|
|
|
/** \todo Urldb / Thumbnails / Local history brokenness
|
2013-10-24 14:48:23 +04:00
|
|
|
*
|
|
|
|
* We add to local history after calling urldb_add_url
|
|
|
|
* rather than in the block above. If urldb_add_url
|
|
|
|
* fails (as it will for urls like "about:about",
|
|
|
|
* "about:config" etc), there would be no local history
|
|
|
|
* node, and later calls to history_update will either
|
|
|
|
* explode or overwrite the node for the previous URL.
|
|
|
|
*
|
|
|
|
* We call it after, rather than before urldb_add_url
|
2015-04-25 01:49:49 +03:00
|
|
|
* because history_add calls bitmap render, which
|
2013-10-24 14:48:23 +04:00
|
|
|
* tries to register the thumbnail with urldb. That
|
|
|
|
* thumbnail registration fails if the url doesn't
|
|
|
|
* exist in urldb already, and only urldb-registered
|
|
|
|
* thumbnails get freed. So if we called history_add
|
|
|
|
* before urldb_add_url we would leak thumbnails for
|
|
|
|
* all newly visited URLs. With the history_add call
|
|
|
|
* after, we only leak the thumbnails when urldb does
|
|
|
|
* not add the URL.
|
|
|
|
*/
|
2014-02-15 22:43:59 +04:00
|
|
|
browser_window_history_add(bw, c, bw->frag_id);
|
2006-11-26 23:11:20 +03:00
|
|
|
}
|
2011-07-13 17:20:26 +04:00
|
|
|
|
2006-11-26 23:11:20 +03:00
|
|
|
/* frames */
|
2016-04-26 12:26:00 +03:00
|
|
|
if ((content_get_type(c) == CONTENT_HTML) &&
|
|
|
|
(html_get_frameset(c) != NULL)) {
|
|
|
|
res = browser_window_create_frameset(bw,
|
2010-03-28 16:56:39 +04:00
|
|
|
html_get_frameset(c));
|
2016-04-26 12:26:00 +03:00
|
|
|
}
|
2014-10-20 00:49:46 +04:00
|
|
|
if (content_get_type(c) == CONTENT_HTML &&
|
2010-03-28 16:56:39 +04:00
|
|
|
html_get_iframe(c) != NULL)
|
|
|
|
browser_window_create_iframes(bw, html_get_iframe(c));
|
2010-03-30 02:33:21 +04:00
|
|
|
}
|
2006-11-26 23:11:20 +03:00
|
|
|
break;
|
2003-12-22 01:10:15 +03:00
|
|
|
|
2006-11-26 23:11:20 +03:00
|
|
|
case CONTENT_MSG_DONE:
|
|
|
|
assert(bw->current_content == c);
|
|
|
|
|
2011-07-06 00:13:28 +04:00
|
|
|
if (bw->window == NULL) {
|
|
|
|
/* Updated browser window's scrollbars.
|
|
|
|
* TODO: do this before CONTENT_MSG_DONE */
|
|
|
|
browser_window_reformat(bw, true,
|
|
|
|
bw->width, bw->height);
|
|
|
|
browser_window_handle_scrollbars(bw);
|
|
|
|
}
|
|
|
|
|
2009-04-05 23:17:24 +04:00
|
|
|
browser_window_update(bw, false);
|
2010-03-28 16:56:39 +04:00
|
|
|
browser_window_set_status(bw, content_get_status_message(c));
|
2006-11-26 23:11:20 +03:00
|
|
|
browser_window_stop_throbber(bw);
|
2011-10-07 22:49:16 +04:00
|
|
|
browser_window_update_favicon(c, bw, NULL);
|
2010-03-28 16:56:39 +04:00
|
|
|
|
2014-02-15 22:43:59 +04:00
|
|
|
browser_window_history_update(bw, c);
|
2013-09-02 15:29:16 +04:00
|
|
|
hotlist_update_url(hlcache_handle_get_url(c));
|
2010-03-28 16:56:39 +04:00
|
|
|
|
2014-03-08 18:13:27 +04:00
|
|
|
if (bw->refresh_interval != -1) {
|
2016-04-16 00:50:28 +03:00
|
|
|
guit->misc->schedule(bw->refresh_interval * 10,
|
2006-11-27 00:04:42 +03:00
|
|
|
browser_window_refresh, bw);
|
2014-03-08 18:13:27 +04:00
|
|
|
}
|
2006-11-26 23:11:20 +03:00
|
|
|
break;
|
2003-12-22 01:10:15 +03:00
|
|
|
|
2012-10-18 00:52:43 +04:00
|
|
|
case CONTENT_MSG_ERRORCODE:
|
|
|
|
browser_window_callback_errorcode(c, bw, event->data.errorcode);
|
|
|
|
break;
|
|
|
|
|
2006-11-26 23:11:20 +03:00
|
|
|
case CONTENT_MSG_ERROR:
|
2010-03-28 16:56:39 +04:00
|
|
|
browser_window_set_status(bw, event->data.error);
|
2007-03-12 01:08:57 +03:00
|
|
|
|
|
|
|
/* Only warn the user about errors in top-level windows */
|
2016-04-26 14:50:16 +03:00
|
|
|
if (bw->browser_window_type == BROWSER_WINDOW_NORMAL) {
|
|
|
|
guit->misc->warning(event->data.error, NULL);
|
|
|
|
}
|
2007-03-12 01:08:57 +03:00
|
|
|
|
2006-11-26 23:11:20 +03:00
|
|
|
if (c == bw->loading_content)
|
2010-03-28 16:56:39 +04:00
|
|
|
bw->loading_content = NULL;
|
2006-11-26 23:11:20 +03:00
|
|
|
else if (c == bw->current_content) {
|
2010-03-28 16:56:39 +04:00
|
|
|
bw->current_content = NULL;
|
2013-02-22 16:19:35 +04:00
|
|
|
browser_window_remove_caret(bw, false);
|
2006-11-26 23:11:20 +03:00
|
|
|
}
|
2010-03-28 16:56:39 +04:00
|
|
|
|
|
|
|
hlcache_handle_release(c);
|
|
|
|
|
2006-11-26 23:11:20 +03:00
|
|
|
browser_window_stop_throbber(bw);
|
|
|
|
break;
|
2003-12-30 02:09:39 +03:00
|
|
|
|
2013-05-27 17:51:00 +04:00
|
|
|
case CONTENT_MSG_REDIRECT:
|
|
|
|
if (urldb_add_url(event->data.redirect.from))
|
|
|
|
urldb_update_url_visit_data(event->data.redirect.from);
|
|
|
|
break;
|
|
|
|
|
2006-11-26 23:11:20 +03:00
|
|
|
case CONTENT_MSG_STATUS:
|
2012-08-15 22:00:50 +04:00
|
|
|
if (event->data.explicit_status_text == NULL) {
|
|
|
|
/* Object content's status text updated */
|
2012-08-19 14:33:37 +04:00
|
|
|
const char *status = NULL;
|
|
|
|
if (bw->loading_content != NULL)
|
|
|
|
/* Give preference to any loading content */
|
|
|
|
status = content_get_status_message(
|
|
|
|
bw->loading_content);
|
|
|
|
|
|
|
|
if (status == NULL)
|
|
|
|
status = content_get_status_message(c);
|
|
|
|
|
|
|
|
if (status != NULL)
|
|
|
|
browser_window_set_status(bw, status);
|
2012-08-15 22:00:50 +04:00
|
|
|
} else {
|
|
|
|
/* Object content wants to set explicit message */
|
|
|
|
browser_window_set_status(bw,
|
|
|
|
event->data.explicit_status_text);
|
|
|
|
}
|
2006-11-26 23:11:20 +03:00
|
|
|
break;
|
2003-12-30 02:09:39 +03:00
|
|
|
|
2006-11-26 23:11:20 +03:00
|
|
|
case CONTENT_MSG_REFORMAT:
|
|
|
|
if (c == bw->current_content &&
|
2010-03-28 16:56:39 +04:00
|
|
|
content_get_type(c) == CONTENT_HTML) {
|
2007-01-03 18:15:54 +03:00
|
|
|
/* reposition frames */
|
2010-03-28 16:56:39 +04:00
|
|
|
if (html_get_frameset(c) != NULL)
|
2007-01-03 18:15:54 +03:00
|
|
|
browser_window_recalculate_frameset(bw);
|
2007-01-27 23:58:20 +03:00
|
|
|
/* reflow iframe positions */
|
2010-03-28 16:56:39 +04:00
|
|
|
if (html_get_iframe(c) != NULL)
|
2006-12-30 05:10:46 +03:00
|
|
|
browser_window_recalculate_iframes(bw);
|
2006-11-26 23:11:20 +03:00
|
|
|
}
|
2010-03-28 16:56:39 +04:00
|
|
|
|
2013-03-27 17:57:10 +04:00
|
|
|
/* Hide any caret, but don't remove it */
|
|
|
|
browser_window_remove_caret(bw, true);
|
2010-03-28 16:56:39 +04:00
|
|
|
|
2011-06-24 13:30:33 +04:00
|
|
|
if (!(event->data.background)) {
|
|
|
|
/* Reformatted content should be redrawn */
|
|
|
|
browser_window_update(bw, false);
|
|
|
|
}
|
2006-11-26 23:11:20 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CONTENT_MSG_REDRAW:
|
2011-07-06 19:34:49 +04:00
|
|
|
{
|
|
|
|
struct rect rect = {
|
|
|
|
.x0 = event->data.redraw.x,
|
|
|
|
.y0 = event->data.redraw.y,
|
|
|
|
.x1 = event->data.redraw.x + event->data.redraw.width,
|
|
|
|
.y1 = event->data.redraw.y + event->data.redraw.height
|
|
|
|
};
|
2011-09-04 21:24:45 +04:00
|
|
|
|
2011-07-06 19:34:49 +04:00
|
|
|
browser_window_update_box(bw, &rect);
|
|
|
|
}
|
2006-11-26 23:11:20 +03:00
|
|
|
break;
|
2006-02-23 18:06:54 +03:00
|
|
|
|
2006-11-26 23:11:20 +03:00
|
|
|
case CONTENT_MSG_REFRESH:
|
2010-03-28 16:56:39 +04:00
|
|
|
bw->refresh_interval = event->data.delay * 100;
|
2006-11-26 23:11:20 +03:00
|
|
|
break;
|
2014-10-20 00:49:46 +04:00
|
|
|
|
2011-10-07 03:31:55 +04:00
|
|
|
case CONTENT_MSG_LINK: /* content has an rfc5988 link element */
|
|
|
|
{
|
2014-01-25 03:13:18 +04:00
|
|
|
bool match;
|
2011-10-07 22:12:47 +04:00
|
|
|
|
2014-01-25 03:13:18 +04:00
|
|
|
/* Handle "icon" and "shortcut icon" */
|
|
|
|
if ((lwc_string_caseless_isequal(
|
|
|
|
event->data.rfc5988_link->rel,
|
|
|
|
corestring_lwc_icon,
|
|
|
|
&match) == lwc_error_ok && match) ||
|
|
|
|
(lwc_string_caseless_isequal(
|
|
|
|
event->data.rfc5988_link->rel,
|
|
|
|
corestring_lwc_shortcut_icon,
|
|
|
|
&match) == lwc_error_ok && match)) {
|
2011-10-08 04:06:43 +04:00
|
|
|
/* it's a favicon perhaps start a fetch for it */
|
2011-10-08 14:22:34 +04:00
|
|
|
browser_window_update_favicon(c, bw,
|
|
|
|
event->data.rfc5988_link);
|
2011-06-15 00:00:18 +04:00
|
|
|
}
|
2011-10-07 03:31:55 +04:00
|
|
|
}
|
2011-01-07 16:10:20 +03:00
|
|
|
break;
|
2006-01-25 09:52:38 +03:00
|
|
|
|
2014-10-20 00:49:46 +04:00
|
|
|
case CONTENT_MSG_GETCTX:
|
2012-06-11 02:17:30 +04:00
|
|
|
/* only the content object created by the browser
|
2014-10-20 00:49:46 +04:00
|
|
|
* window requires a new global compartment object
|
2012-06-11 02:17:30 +04:00
|
|
|
*/
|
2012-06-26 22:55:57 +04:00
|
|
|
assert(bw->loading_content == c);
|
2012-07-07 03:14:50 +04:00
|
|
|
if (js_newcompartment(bw->jsctx,
|
|
|
|
bw,
|
|
|
|
hlcache_handle_get_content(c)) != NULL) {
|
2012-06-11 02:17:30 +04:00
|
|
|
*(event->data.jscontext) = bw->jsctx;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2012-08-14 02:32:58 +04:00
|
|
|
case CONTENT_MSG_SCROLL:
|
2017-04-26 22:48:54 +03:00
|
|
|
{
|
|
|
|
struct rect rect = {
|
|
|
|
.x0 = event->data.scroll.x0,
|
|
|
|
.y0 = event->data.scroll.y0,
|
|
|
|
};
|
|
|
|
|
2012-08-14 02:32:58 +04:00
|
|
|
/* Content wants to be scrolled */
|
2017-04-26 22:48:54 +03:00
|
|
|
if (bw->current_content != c) {
|
2012-08-14 02:32:58 +04:00
|
|
|
break;
|
2017-04-26 22:48:54 +03:00
|
|
|
}
|
2012-08-14 02:32:58 +04:00
|
|
|
|
|
|
|
if (event->data.scroll.area) {
|
2017-04-26 22:48:54 +03:00
|
|
|
rect.x1 = event->data.scroll.x1;
|
|
|
|
rect.y1 = event->data.scroll.y1;
|
2012-08-14 02:32:58 +04:00
|
|
|
} else {
|
2017-04-26 22:48:54 +03:00
|
|
|
rect.x1 = event->data.scroll.x0;
|
|
|
|
rect.y1 = event->data.scroll.y0;
|
2012-08-14 02:32:58 +04:00
|
|
|
}
|
2017-04-26 22:48:54 +03:00
|
|
|
browser_window_set_scroll(bw, &rect);
|
2012-08-14 02:32:58 +04:00
|
|
|
|
|
|
|
break;
|
2017-04-26 22:48:54 +03:00
|
|
|
}
|
2012-08-14 02:32:58 +04:00
|
|
|
|
2012-08-16 23:20:49 +04:00
|
|
|
case CONTENT_MSG_DRAGSAVE:
|
|
|
|
{
|
|
|
|
/* Content wants drag save of a content */
|
|
|
|
struct browser_window *root = browser_window_get_root(bw);
|
2012-08-19 15:46:42 +04:00
|
|
|
hlcache_handle *save = event->data.dragsave.content;
|
|
|
|
|
|
|
|
if (save == NULL) {
|
|
|
|
save = c;
|
|
|
|
}
|
2012-08-16 23:20:49 +04:00
|
|
|
|
|
|
|
switch(event->data.dragsave.type) {
|
|
|
|
case CONTENT_SAVE_ORIG:
|
2014-01-14 02:54:19 +04:00
|
|
|
guit->window->drag_save_object(root->window, save,
|
|
|
|
GUI_SAVE_OBJECT_ORIG);
|
2012-08-16 23:20:49 +04:00
|
|
|
break;
|
2014-01-14 02:54:19 +04:00
|
|
|
|
2012-08-16 23:20:49 +04:00
|
|
|
case CONTENT_SAVE_NATIVE:
|
2014-01-14 02:54:19 +04:00
|
|
|
guit->window->drag_save_object(root->window, save,
|
|
|
|
GUI_SAVE_OBJECT_NATIVE);
|
2012-08-16 23:20:49 +04:00
|
|
|
break;
|
2014-01-14 02:54:19 +04:00
|
|
|
|
2012-08-16 23:20:49 +04:00
|
|
|
case CONTENT_SAVE_COMPLETE:
|
2014-01-14 02:54:19 +04:00
|
|
|
guit->window->drag_save_object(root->window, save,
|
|
|
|
GUI_SAVE_COMPLETE);
|
2012-08-16 23:20:49 +04:00
|
|
|
break;
|
2014-01-14 02:54:19 +04:00
|
|
|
|
2012-08-16 23:20:49 +04:00
|
|
|
case CONTENT_SAVE_SOURCE:
|
2014-01-14 02:54:19 +04:00
|
|
|
guit->window->drag_save_object(root->window, save,
|
|
|
|
GUI_SAVE_SOURCE);
|
2012-08-16 23:20:49 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2012-08-17 02:26:05 +04:00
|
|
|
case CONTENT_MSG_SAVELINK:
|
|
|
|
{
|
|
|
|
/* Content wants a link to be saved */
|
|
|
|
struct browser_window *root = browser_window_get_root(bw);
|
2014-01-12 21:07:34 +04:00
|
|
|
guit->window->save_link(root->window,
|
2012-08-17 02:26:05 +04:00
|
|
|
event->data.savelink.url,
|
|
|
|
event->data.savelink.title);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2012-08-17 13:01:15 +04:00
|
|
|
case CONTENT_MSG_POINTER:
|
|
|
|
/* Content wants to have specific mouse pointer */
|
|
|
|
browser_window_set_pointer(bw, event->data.pointer);
|
|
|
|
break;
|
|
|
|
|
2013-02-08 17:22:53 +04:00
|
|
|
case CONTENT_MSG_DRAG:
|
|
|
|
{
|
|
|
|
browser_drag_type bdt = DRAGGING_NONE;
|
|
|
|
|
|
|
|
switch (event->data.drag.type) {
|
|
|
|
case CONTENT_DRAG_NONE:
|
|
|
|
bdt = DRAGGING_NONE;
|
|
|
|
break;
|
|
|
|
case CONTENT_DRAG_SCROLL:
|
2013-02-08 19:05:07 +04:00
|
|
|
bdt = DRAGGING_CONTENT_SCROLLBAR;
|
2013-02-08 17:22:53 +04:00
|
|
|
break;
|
|
|
|
case CONTENT_DRAG_SELECTION:
|
2013-02-08 19:05:07 +04:00
|
|
|
bdt = DRAGGING_SELECTION;
|
2013-02-08 17:22:53 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
browser_window_set_drag_type(bw, bdt, event->data.drag.rect);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2013-02-22 16:19:35 +04:00
|
|
|
case CONTENT_MSG_CARET:
|
|
|
|
switch (event->data.caret.type) {
|
|
|
|
case CONTENT_CARET_REMOVE:
|
|
|
|
browser_window_remove_caret(bw, false);
|
|
|
|
break;
|
|
|
|
case CONTENT_CARET_HIDE:
|
|
|
|
browser_window_remove_caret(bw, true);
|
|
|
|
break;
|
|
|
|
case CONTENT_CARET_SET_POS:
|
|
|
|
browser_window_place_caret(bw,
|
|
|
|
event->data.caret.pos.x,
|
|
|
|
event->data.caret.pos.y,
|
2013-03-05 18:51:16 +04:00
|
|
|
event->data.caret.pos.height,
|
|
|
|
event->data.caret.pos.clip);
|
2013-02-22 16:19:35 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CONTENT_MSG_SELECTION:
|
|
|
|
browser_window_set_selection(bw,
|
|
|
|
event->data.selection.selection,
|
|
|
|
event->data.selection.read_only);
|
|
|
|
break;
|
|
|
|
|
2014-10-24 20:57:15 +04:00
|
|
|
case CONTENT_MSG_SELECTMENU:
|
|
|
|
if (event->data.select_menu.gadget->type == GADGET_SELECT) {
|
|
|
|
struct browser_window *root =
|
|
|
|
browser_window_get_root(bw);
|
2014-10-24 23:45:21 +04:00
|
|
|
guit->window->create_form_select_menu(root->window,
|
2014-10-24 20:57:15 +04:00
|
|
|
event->data.select_menu.gadget);
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
2014-01-05 20:04:35 +04:00
|
|
|
case CONTENT_MSG_GADGETCLICK:
|
|
|
|
if (event->data.gadget_click.gadget->type == GADGET_FILE) {
|
2014-10-24 23:18:57 +04:00
|
|
|
struct browser_window *root =
|
|
|
|
browser_window_get_root(bw);
|
|
|
|
guit->window->file_gadget_open(root->window, c,
|
2014-01-05 20:04:35 +04:00
|
|
|
event->data.gadget_click.gadget);
|
|
|
|
}
|
2014-10-20 00:49:46 +04:00
|
|
|
|
2014-01-05 20:04:35 +04:00
|
|
|
break;
|
2014-10-20 00:49:46 +04:00
|
|
|
|
2006-11-26 23:11:20 +03:00
|
|
|
default:
|
2014-01-05 18:39:08 +04:00
|
|
|
break;
|
2004-02-25 18:12:58 +03:00
|
|
|
}
|
2010-03-28 16:56:39 +04:00
|
|
|
|
2016-04-26 12:26:00 +03:00
|
|
|
return res;
|
2002-09-11 18:24:02 +04:00
|
|
|
}
|
|
|
|
|
2004-02-25 18:12:58 +03:00
|
|
|
|
2013-07-12 16:50:17 +04:00
|
|
|
/* Have to forward declare browser_window_destroy_internal */
|
|
|
|
static void browser_window_destroy_internal(struct browser_window *bw);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Close and destroy all child browser window.
|
2011-06-15 00:00:18 +04:00
|
|
|
*
|
2013-07-12 16:50:17 +04:00
|
|
|
* \param bw browser window
|
2011-06-15 00:00:18 +04:00
|
|
|
*/
|
2013-07-12 16:50:17 +04:00
|
|
|
static void browser_window_destroy_children(struct browser_window *bw)
|
2011-06-15 00:00:18 +04:00
|
|
|
{
|
2013-07-12 16:50:17 +04:00
|
|
|
int i;
|
2011-06-15 00:00:18 +04:00
|
|
|
|
2013-07-12 16:50:17 +04:00
|
|
|
if (bw->children) {
|
|
|
|
for (i = 0; i < (bw->rows * bw->cols); i++)
|
|
|
|
browser_window_destroy_internal(&bw->children[i]);
|
|
|
|
free(bw->children);
|
|
|
|
bw->children = NULL;
|
|
|
|
bw->rows = 0;
|
|
|
|
bw->cols = 0;
|
|
|
|
}
|
|
|
|
if (bw->iframes) {
|
|
|
|
for (i = 0; i < bw->iframe_count; i++)
|
|
|
|
browser_window_destroy_internal(&bw->iframes[i]);
|
|
|
|
free(bw->iframes);
|
|
|
|
bw->iframes = NULL;
|
|
|
|
bw->iframe_count = 0;
|
2011-06-15 00:00:18 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-04-26 11:43:18 +03:00
|
|
|
/**
|
|
|
|
* internal scheduled reformat callback.
|
|
|
|
*
|
|
|
|
* scheduled reformat callback to allow reformats from unthreaded context.
|
|
|
|
*
|
|
|
|
* \param vbw The browser window to be reformatted
|
|
|
|
*/
|
|
|
|
static void scheduled_reformat(void *vbw)
|
|
|
|
{
|
|
|
|
struct browser_window *bw = vbw;
|
|
|
|
int width;
|
|
|
|
int height;
|
|
|
|
nserror res;
|
|
|
|
|
|
|
|
res = guit->window->get_dimensions(bw->window, &width, &height, false);
|
|
|
|
if (res == NSERROR_OK) {
|
|
|
|
browser_window_reformat(bw, false, width, height);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-07-12 16:50:17 +04:00
|
|
|
/**
|
|
|
|
* Release all memory associated with a browser window.
|
2011-06-24 13:30:33 +04:00
|
|
|
*
|
2013-07-12 16:50:17 +04:00
|
|
|
* \param bw browser window
|
2011-06-24 13:30:33 +04:00
|
|
|
*/
|
2014-10-19 22:12:55 +04:00
|
|
|
static void browser_window_destroy_internal(struct browser_window *bw)
|
2011-06-24 13:30:33 +04:00
|
|
|
{
|
|
|
|
assert(bw);
|
|
|
|
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("Destroying window");
|
2011-06-24 13:30:33 +04:00
|
|
|
|
2014-03-08 18:13:27 +04:00
|
|
|
if (bw->children != NULL || bw->iframes != NULL) {
|
2013-07-12 16:50:17 +04:00
|
|
|
browser_window_destroy_children(bw);
|
2014-03-08 18:13:27 +04:00
|
|
|
}
|
2011-06-24 13:30:33 +04:00
|
|
|
|
2015-10-31 17:05:03 +03:00
|
|
|
/* Destroy scrollbars */
|
|
|
|
if (bw->scroll_x != NULL) {
|
|
|
|
scrollbar_destroy(bw->scroll_x);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bw->scroll_y != NULL) {
|
|
|
|
scrollbar_destroy(bw->scroll_y);
|
|
|
|
}
|
|
|
|
|
2014-06-30 19:40:56 +04:00
|
|
|
/* clear any pending callbacks */
|
2016-04-16 00:50:28 +03:00
|
|
|
guit->misc->schedule(-1, browser_window_refresh, bw);
|
2014-06-30 19:40:56 +04:00
|
|
|
/* The ugly cast here is so the reformat function can be
|
|
|
|
* passed a gui window pointer in its API rather than void*
|
|
|
|
*/
|
2017-04-26 11:43:18 +03:00
|
|
|
LOG("Clearing reformat schedule for browser window %p", bw);
|
|
|
|
guit->misc->schedule(-1, scheduled_reformat, bw);
|
2004-02-25 18:12:58 +03:00
|
|
|
|
2013-07-12 16:50:17 +04:00
|
|
|
/* If this brower window is not the root window, and has focus, unset
|
|
|
|
* the root browser window's focus pointer. */
|
|
|
|
if (!bw->window) {
|
|
|
|
struct browser_window *top = browser_window_get_root(bw);
|
2004-06-28 03:24:11 +04:00
|
|
|
|
2013-07-12 16:50:17 +04:00
|
|
|
if (top->focus == bw)
|
|
|
|
top->focus = top;
|
2011-11-24 04:13:19 +04:00
|
|
|
|
2013-07-12 16:50:17 +04:00
|
|
|
if (top->selection.bw == bw) {
|
|
|
|
browser_window_set_selection(top, false, false);
|
|
|
|
}
|
2010-04-06 01:35:38 +04:00
|
|
|
}
|
2004-02-25 18:12:58 +03:00
|
|
|
|
2014-10-20 00:49:46 +04:00
|
|
|
/* Destruction order is important: we must ensure that the frontend
|
|
|
|
* destroys any window(s) associated with this browser window before
|
|
|
|
* we attempt any destructive cleanup.
|
2013-07-12 16:50:17 +04:00
|
|
|
*/
|
2002-09-11 18:24:02 +04:00
|
|
|
|
2013-07-12 16:50:17 +04:00
|
|
|
if (bw->window) {
|
|
|
|
/* Only the root window has a GUI window */
|
2014-01-12 21:07:34 +04:00
|
|
|
guit->window->destroy(bw->window);
|
2013-07-12 16:50:17 +04:00
|
|
|
}
|
2004-02-25 18:12:58 +03:00
|
|
|
|
2013-07-12 16:50:17 +04:00
|
|
|
if (bw->loading_content != NULL) {
|
|
|
|
hlcache_handle_abort(bw->loading_content);
|
|
|
|
hlcache_handle_release(bw->loading_content);
|
|
|
|
bw->loading_content = NULL;
|
|
|
|
}
|
2006-11-27 00:04:42 +03:00
|
|
|
|
2013-07-12 16:50:17 +04:00
|
|
|
if (bw->current_content != NULL) {
|
|
|
|
content_status status = content_get_status(bw->current_content);
|
2014-10-20 00:49:46 +04:00
|
|
|
if (status == CONTENT_STATUS_READY ||
|
2013-07-12 16:50:17 +04:00
|
|
|
status == CONTENT_STATUS_DONE)
|
|
|
|
content_close(bw->current_content);
|
2006-11-27 00:04:42 +03:00
|
|
|
|
2013-07-12 16:50:17 +04:00
|
|
|
hlcache_handle_release(bw->current_content);
|
|
|
|
bw->current_content = NULL;
|
|
|
|
}
|
2008-02-27 21:38:41 +03:00
|
|
|
|
2017-03-03 13:41:43 +03:00
|
|
|
if (bw->favicon.loading != NULL) {
|
|
|
|
hlcache_handle_abort(bw->favicon.loading);
|
|
|
|
hlcache_handle_release(bw->favicon.loading);
|
|
|
|
bw->favicon.loading = NULL;
|
2013-07-12 16:50:17 +04:00
|
|
|
}
|
2006-11-27 00:04:42 +03:00
|
|
|
|
2017-03-03 13:41:43 +03:00
|
|
|
if (bw->favicon.current != NULL) {
|
|
|
|
content_status status = content_get_status(bw->favicon.current);
|
2006-11-27 00:04:42 +03:00
|
|
|
|
2013-07-12 16:50:17 +04:00
|
|
|
if (status == CONTENT_STATUS_READY ||
|
2017-03-03 13:41:43 +03:00
|
|
|
status == CONTENT_STATUS_DONE) {
|
|
|
|
content_close(bw->favicon.current);
|
|
|
|
}
|
2006-11-27 00:04:42 +03:00
|
|
|
|
2017-03-03 13:41:43 +03:00
|
|
|
hlcache_handle_release(bw->favicon.current);
|
|
|
|
bw->favicon.current = NULL;
|
2009-03-10 12:10:43 +03:00
|
|
|
}
|
2013-02-14 19:09:28 +04:00
|
|
|
|
2013-07-12 16:50:17 +04:00
|
|
|
if (bw->box != NULL) {
|
|
|
|
bw->box->iframe = NULL;
|
|
|
|
bw->box = NULL;
|
|
|
|
}
|
2013-02-14 19:09:28 +04:00
|
|
|
|
2013-07-12 16:50:17 +04:00
|
|
|
if (bw->jsctx != NULL) {
|
|
|
|
js_destroycontext(bw->jsctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* These simply free memory, so are safe here */
|
|
|
|
|
2017-03-03 13:41:43 +03:00
|
|
|
if (bw->frag_id != NULL) {
|
2013-07-12 16:50:17 +04:00
|
|
|
lwc_string_unref(bw->frag_id);
|
2017-03-03 13:41:43 +03:00
|
|
|
}
|
2013-07-12 16:50:17 +04:00
|
|
|
|
2014-02-15 22:43:59 +04:00
|
|
|
browser_window_history_destroy(bw);
|
2013-07-12 16:50:17 +04:00
|
|
|
|
|
|
|
free(bw->name);
|
2017-03-03 12:28:54 +03:00
|
|
|
free(bw->status.text);
|
|
|
|
bw->status.text = NULL;
|
|
|
|
LOG("Status text cache match:miss %d:%d", bw->status.match, bw->status.miss);
|
2006-11-27 00:04:42 +03:00
|
|
|
}
|
|
|
|
|
2014-02-08 16:07:13 +04:00
|
|
|
/**
|
|
|
|
* Update URL bar for a given browser window to given URL
|
|
|
|
*
|
|
|
|
* \param bw Browser window to update URL bar for.
|
|
|
|
* \param url URL for content displayed by bw including any fragment.
|
|
|
|
*/
|
2014-10-29 03:17:11 +03:00
|
|
|
static inline nserror
|
|
|
|
browser_window_refresh_url_bar_internal(struct browser_window *bw, nsurl *url)
|
2014-02-08 16:07:13 +04:00
|
|
|
{
|
|
|
|
assert(bw);
|
|
|
|
assert(url);
|
|
|
|
|
2014-10-29 03:17:11 +03:00
|
|
|
if ((bw->parent != NULL) || (bw->window == NULL)) {
|
|
|
|
/* Not root window or no gui window so do not set a URL */
|
|
|
|
return NSERROR_OK;
|
2014-02-08 16:07:13 +04:00
|
|
|
}
|
|
|
|
|
2014-11-03 01:30:45 +03:00
|
|
|
return guit->window->set_url(bw->window, url);
|
2014-02-08 16:07:13 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-05-30 19:32:57 +03:00
|
|
|
/* exported interface, documented in netsurf/browser_window.h */
|
2014-10-19 22:12:55 +04:00
|
|
|
void browser_window_destroy(struct browser_window *bw)
|
|
|
|
{
|
|
|
|
/* can't destoy child windows on their own */
|
|
|
|
assert(!bw->parent);
|
2014-02-08 16:07:13 +04:00
|
|
|
|
2014-10-19 22:12:55 +04:00
|
|
|
/* destroy */
|
|
|
|
browser_window_destroy_internal(bw);
|
|
|
|
free(bw);
|
|
|
|
}
|
|
|
|
|
2016-05-30 19:32:57 +03:00
|
|
|
/* exported interface, documented in netsurf/browser_window.h */
|
2014-10-29 03:17:11 +03:00
|
|
|
nserror browser_window_refresh_url_bar(struct browser_window *bw)
|
2014-02-08 16:07:13 +04:00
|
|
|
{
|
2014-10-29 03:17:11 +03:00
|
|
|
nserror ret;
|
|
|
|
nsurl *display_url;
|
|
|
|
|
2014-02-08 16:07:13 +04:00
|
|
|
assert(bw);
|
|
|
|
|
|
|
|
if (bw->parent != NULL) {
|
|
|
|
/* Not root window; don't set a URL in GUI URL bar */
|
2014-10-29 03:17:11 +03:00
|
|
|
return NSERROR_OK;
|
2014-02-08 16:07:13 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (bw->current_content == NULL) {
|
2014-10-29 03:17:11 +03:00
|
|
|
/* no content so return about:blank */
|
|
|
|
ret = browser_window_refresh_url_bar_internal(bw,
|
|
|
|
corestring_nsurl_about_blank);
|
|
|
|
} else if (bw->frag_id == NULL) {
|
|
|
|
ret = browser_window_refresh_url_bar_internal(bw,
|
2014-02-08 16:07:13 +04:00
|
|
|
hlcache_handle_get_url(bw->current_content));
|
|
|
|
} else {
|
|
|
|
/* Combine URL and Fragment */
|
2014-10-29 03:17:11 +03:00
|
|
|
ret = nsurl_refragment(
|
2014-02-08 16:07:13 +04:00
|
|
|
hlcache_handle_get_url(bw->current_content),
|
|
|
|
bw->frag_id, &display_url);
|
2014-10-29 03:17:11 +03:00
|
|
|
if (ret == NSERROR_OK) {
|
|
|
|
ret = browser_window_refresh_url_bar_internal(bw,
|
|
|
|
display_url);
|
|
|
|
nsurl_unref(display_url);
|
2014-02-08 16:07:13 +04:00
|
|
|
}
|
|
|
|
}
|
2014-10-29 03:17:11 +03:00
|
|
|
|
|
|
|
return ret;
|
2014-02-08 16:07:13 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-05-30 19:32:57 +03:00
|
|
|
/* exported interface documented in netsurf/browser_window.h */
|
2017-03-03 12:28:54 +03:00
|
|
|
nserror
|
|
|
|
browser_window_navigate(struct browser_window *bw,
|
2013-07-12 16:50:17 +04:00
|
|
|
nsurl *url,
|
|
|
|
nsurl *referrer,
|
|
|
|
enum browser_window_nav_flags flags,
|
|
|
|
char *post_urlenc,
|
|
|
|
struct fetch_multipart_data *post_multipart,
|
|
|
|
hlcache_handle *parent)
|
2002-09-11 18:24:02 +04:00
|
|
|
{
|
2013-07-12 16:50:17 +04:00
|
|
|
hlcache_handle *c;
|
|
|
|
int depth = 0;
|
|
|
|
struct browser_window *cur;
|
|
|
|
uint32_t fetch_flags = 0;
|
|
|
|
bool fetch_is_post = (post_urlenc != NULL || post_multipart != NULL);
|
|
|
|
llcache_post_data post;
|
|
|
|
hlcache_child_context child;
|
|
|
|
nserror error;
|
2006-09-02 19:52:41 +04:00
|
|
|
|
2013-07-12 16:50:17 +04:00
|
|
|
assert(bw);
|
|
|
|
assert(url);
|
2010-03-28 16:56:39 +04:00
|
|
|
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("bw %p, url %s", bw, nsurl_access(url));
|
2013-07-12 16:50:17 +04:00
|
|
|
|
|
|
|
/* don't allow massively nested framesets */
|
|
|
|
for (cur = bw; cur->parent; cur = cur->parent) {
|
|
|
|
depth++;
|
|
|
|
}
|
|
|
|
if (depth > FRAME_DEPTH) {
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("frame depth too high.");
|
2013-07-12 16:50:17 +04:00
|
|
|
return NSERROR_FRAME_DEPTH;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set up retrieval parameters */
|
2014-02-11 02:40:04 +04:00
|
|
|
if (!(flags & BW_NAVIGATE_UNVERIFIABLE)) {
|
2013-07-12 16:50:17 +04:00
|
|
|
fetch_flags |= LLCACHE_RETRIEVE_VERIFIABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (post_multipart != NULL) {
|
|
|
|
post.type = LLCACHE_POST_MULTIPART;
|
|
|
|
post.data.multipart = post_multipart;
|
|
|
|
} else if (post_urlenc != NULL) {
|
|
|
|
post.type = LLCACHE_POST_URL_ENCODED;
|
|
|
|
post.data.urlenc = post_urlenc;
|
|
|
|
}
|
|
|
|
|
2014-11-07 15:33:34 +03:00
|
|
|
child.charset = content_get_encoding(parent, CONTENT_ENCODING_NORMAL);
|
2013-07-12 16:50:17 +04:00
|
|
|
if ((parent != NULL) && (content_get_type(parent) == CONTENT_HTML)) {
|
|
|
|
child.quirks = content_get_quirks(parent);
|
|
|
|
}
|
|
|
|
|
|
|
|
url = nsurl_ref(url);
|
|
|
|
|
|
|
|
if (referrer != NULL) {
|
|
|
|
referrer = nsurl_ref(referrer);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get download out of the way */
|
2014-02-10 18:08:45 +04:00
|
|
|
if ((flags & BW_NAVIGATE_DOWNLOAD) != 0) {
|
2014-10-20 00:49:46 +04:00
|
|
|
error = browser_window_download(bw,
|
|
|
|
url,
|
|
|
|
referrer,
|
|
|
|
fetch_flags,
|
|
|
|
fetch_is_post,
|
2013-07-12 16:50:17 +04:00
|
|
|
&post);
|
|
|
|
nsurl_unref(url);
|
|
|
|
if (referrer != NULL) {
|
|
|
|
nsurl_unref(referrer);
|
|
|
|
}
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bw->frag_id != NULL) {
|
|
|
|
lwc_string_unref(bw->frag_id);
|
|
|
|
}
|
|
|
|
bw->frag_id = NULL;
|
|
|
|
|
|
|
|
if (nsurl_has_component(url, NSURL_FRAGMENT)) {
|
|
|
|
bool same_url = false;
|
|
|
|
|
|
|
|
bw->frag_id = nsurl_get_component(url, NSURL_FRAGMENT);
|
|
|
|
|
|
|
|
/* Compare new URL with existing one (ignoring fragments) */
|
2014-10-20 00:49:46 +04:00
|
|
|
if ((bw->current_content != NULL) &&
|
2013-07-12 16:50:17 +04:00
|
|
|
(hlcache_handle_get_url(bw->current_content) != NULL)) {
|
|
|
|
same_url = nsurl_compare(url,
|
2013-07-12 18:31:43 +04:00
|
|
|
hlcache_handle_get_url(
|
|
|
|
bw->current_content),
|
2013-07-12 16:50:17 +04:00
|
|
|
NSURL_COMPLETE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* if we're simply moving to another ID on the same page,
|
|
|
|
* don't bother to fetch, just update the window.
|
|
|
|
*/
|
2014-10-20 00:49:46 +04:00
|
|
|
if ((same_url) &&
|
|
|
|
(fetch_is_post == false) &&
|
2013-07-12 16:50:17 +04:00
|
|
|
(nsurl_has_component(url, NSURL_QUERY) == false)) {
|
|
|
|
nsurl_unref(url);
|
|
|
|
|
|
|
|
if (referrer != NULL) {
|
|
|
|
nsurl_unref(referrer);
|
|
|
|
}
|
|
|
|
|
2014-02-10 18:08:45 +04:00
|
|
|
if ((flags & BW_NAVIGATE_HISTORY) != 0) {
|
2014-10-20 00:49:46 +04:00
|
|
|
browser_window_history_add(bw,
|
2013-07-12 16:50:17 +04:00
|
|
|
bw->current_content, bw->frag_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
browser_window_update(bw, false);
|
|
|
|
|
|
|
|
if (bw->current_content != NULL) {
|
2014-02-08 16:07:13 +04:00
|
|
|
browser_window_refresh_url_bar(bw);
|
2013-07-12 16:50:17 +04:00
|
|
|
}
|
|
|
|
return NSERROR_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
browser_window_stop(bw);
|
|
|
|
browser_window_remove_caret(bw, false);
|
|
|
|
browser_window_destroy_children(bw);
|
|
|
|
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("Loading '%s'", nsurl_access(url));
|
2013-07-12 16:50:17 +04:00
|
|
|
|
|
|
|
browser_window_set_status(bw, messages_get("Loading"));
|
2014-02-10 18:08:45 +04:00
|
|
|
bw->history_add = (flags & BW_NAVIGATE_HISTORY);
|
2013-07-12 16:50:17 +04:00
|
|
|
|
|
|
|
/* Verifiable fetches may trigger a download */
|
2014-02-11 02:40:04 +04:00
|
|
|
if (!(flags & BW_NAVIGATE_UNVERIFIABLE)) {
|
2013-07-12 16:50:17 +04:00
|
|
|
fetch_flags |= HLCACHE_RETRIEVE_MAY_DOWNLOAD;
|
|
|
|
}
|
|
|
|
|
|
|
|
error = hlcache_handle_retrieve(url,
|
|
|
|
fetch_flags | HLCACHE_RETRIEVE_SNIFF_TYPE,
|
|
|
|
referrer,
|
|
|
|
fetch_is_post ? &post : NULL,
|
|
|
|
browser_window_callback, bw,
|
|
|
|
parent != NULL ? &child : NULL,
|
|
|
|
CONTENT_ANY, &c);
|
|
|
|
|
|
|
|
switch (error) {
|
|
|
|
case NSERROR_OK:
|
|
|
|
bw->loading_content = c;
|
|
|
|
browser_window_start_throbber(bw);
|
2014-10-29 03:17:11 +03:00
|
|
|
error = browser_window_refresh_url_bar_internal(bw, url);
|
2013-07-12 16:50:17 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case NSERROR_NO_FETCH_HANDLER: /* no handler for this type */
|
2014-10-29 03:17:11 +03:00
|
|
|
/** \todo does this always try and download even
|
|
|
|
* unverifiable content?
|
|
|
|
*/
|
2016-04-16 00:50:28 +03:00
|
|
|
error = guit->misc->launch_url(url);
|
2013-07-12 16:50:17 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
default: /* report error to user */
|
|
|
|
browser_window_set_status(bw, messages_get_errorcode(error));
|
|
|
|
/** @todo should the caller report the error? */
|
2016-04-26 14:50:16 +03:00
|
|
|
guit->misc->warning(messages_get_errorcode(error), NULL);
|
2013-07-12 16:50:17 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
nsurl_unref(url);
|
|
|
|
if (referrer != NULL) {
|
|
|
|
nsurl_unref(referrer);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Record time */
|
2016-04-21 15:12:56 +03:00
|
|
|
nsu_getmonotonic_ms(&bw->last_action);
|
2013-07-12 16:50:17 +04:00
|
|
|
|
|
|
|
return error;
|
2004-02-25 18:12:58 +03:00
|
|
|
}
|
2003-12-22 01:10:15 +03:00
|
|
|
|
2002-09-11 18:24:02 +04:00
|
|
|
|
2014-10-18 13:16:00 +04:00
|
|
|
/* Exported interface, documented in browser.h */
|
|
|
|
bool browser_window_up_available(struct browser_window *bw)
|
|
|
|
{
|
|
|
|
bool result = false;
|
|
|
|
|
|
|
|
if (bw != NULL && bw->current_content != NULL) {
|
|
|
|
nsurl *parent;
|
|
|
|
nserror err = nsurl_parent(hlcache_handle_get_url(
|
|
|
|
bw->current_content), &parent);
|
|
|
|
if (err == NSERROR_OK) {
|
|
|
|
result = nsurl_compare(hlcache_handle_get_url(
|
|
|
|
bw->current_content), parent,
|
|
|
|
NSURL_COMPLETE) == false;
|
|
|
|
nsurl_unref(parent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-10-17 12:51:10 +04:00
|
|
|
/* Exported interface, documented in browser.h */
|
|
|
|
nserror browser_window_navigate_up(struct browser_window *bw, bool new_window)
|
|
|
|
{
|
|
|
|
nsurl *current, *parent;
|
|
|
|
nserror err;
|
|
|
|
|
|
|
|
if (bw == NULL)
|
|
|
|
return NSERROR_BAD_PARAMETER;
|
|
|
|
|
|
|
|
current = browser_window_get_url(bw);
|
|
|
|
|
|
|
|
err = nsurl_parent(current, &parent);
|
|
|
|
if (err != NSERROR_OK) {
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nsurl_compare(current, parent, NSURL_COMPLETE) == true) {
|
|
|
|
/* Can't go up to parent from here */
|
|
|
|
nsurl_unref(parent);
|
|
|
|
return NSERROR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (new_window) {
|
|
|
|
err = browser_window_create(BW_CREATE_CLONE,
|
|
|
|
parent, NULL, bw, NULL);
|
|
|
|
} else {
|
|
|
|
err = browser_window_navigate(bw, parent, NULL,
|
|
|
|
BW_NAVIGATE_HISTORY, NULL, NULL, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsurl_unref(parent);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-02-08 19:00:08 +04:00
|
|
|
/* Exported interface, documented in browser.h */
|
2014-07-06 21:34:34 +04:00
|
|
|
nsurl* browser_window_get_url(struct browser_window *bw)
|
2014-02-08 19:00:08 +04:00
|
|
|
{
|
|
|
|
assert(bw != NULL);
|
|
|
|
|
|
|
|
if (bw->current_content != NULL) {
|
|
|
|
return hlcache_handle_get_url(bw->current_content);
|
|
|
|
|
|
|
|
} else if (bw->loading_content != NULL) {
|
|
|
|
/* TODO: should we return this? */
|
|
|
|
return hlcache_handle_get_url(bw->loading_content);
|
|
|
|
}
|
|
|
|
|
|
|
|
return corestring_nsurl_about_blank;
|
|
|
|
}
|
|
|
|
|
2014-07-06 21:34:34 +04:00
|
|
|
/* Exported interface, documented in browser.h */
|
|
|
|
const char* browser_window_get_title(struct browser_window *bw)
|
|
|
|
{
|
|
|
|
assert(bw != NULL);
|
|
|
|
|
|
|
|
if (bw->current_content != NULL) {
|
|
|
|
return content_get_title(bw->current_content);
|
|
|
|
}
|
|
|
|
|
2014-10-29 03:17:11 +03:00
|
|
|
/* no content so return about:blank */
|
|
|
|
return nsurl_access(corestring_nsurl_about_blank);
|
2014-07-06 21:34:34 +04:00
|
|
|
}
|
2014-02-08 19:00:08 +04:00
|
|
|
|
2014-02-09 17:07:39 +04:00
|
|
|
/* Exported interface, documented in browser.h */
|
|
|
|
struct history * browser_window_get_history(struct browser_window *bw)
|
|
|
|
{
|
|
|
|
assert(bw != NULL);
|
|
|
|
|
|
|
|
return bw->history;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-02-08 19:31:44 +04:00
|
|
|
/* Exported interface, documented in browser.h */
|
|
|
|
bool browser_window_has_content(struct browser_window *bw)
|
|
|
|
{
|
|
|
|
assert(bw != NULL);
|
|
|
|
|
|
|
|
if (bw->current_content == NULL) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-07-21 04:13:10 +04:00
|
|
|
/* Exported interface, documented in browser.h */
|
|
|
|
struct hlcache_handle *browser_window_get_content(struct browser_window *bw)
|
|
|
|
{
|
|
|
|
return bw->current_content;
|
|
|
|
}
|
2014-02-08 19:31:44 +04:00
|
|
|
|
2014-02-08 20:03:06 +04:00
|
|
|
/* Exported interface, documented in browser.h */
|
|
|
|
nserror browser_window_get_extents(struct browser_window *bw, bool scaled,
|
|
|
|
int *width, int *height)
|
|
|
|
{
|
|
|
|
assert(bw != NULL);
|
|
|
|
|
|
|
|
if (bw->current_content == NULL) {
|
|
|
|
*width = 0;
|
|
|
|
*height = 0;
|
|
|
|
return NSERROR_BAD_CONTENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
*width = content_get_width(bw->current_content);
|
|
|
|
*height = content_get_height(bw->current_content);
|
|
|
|
|
|
|
|
if (scaled) {
|
|
|
|
*width *= bw->scale;
|
|
|
|
*height *= bw->scale;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NSERROR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-10-19 22:12:55 +04:00
|
|
|
/* exported internal interface, documented in desktop/browser_private.h */
|
2013-07-12 16:50:17 +04:00
|
|
|
void browser_window_get_dimensions(struct browser_window *bw,
|
|
|
|
int *width, int *height, bool scaled)
|
2004-02-25 18:12:58 +03:00
|
|
|
{
|
2013-07-12 16:50:17 +04:00
|
|
|
assert(bw);
|
2006-09-06 04:15:10 +04:00
|
|
|
|
2013-07-12 16:50:17 +04:00
|
|
|
if (bw->window == NULL) {
|
|
|
|
/* Core managed browser window */
|
|
|
|
*width = bw->width;
|
|
|
|
*height = bw->height;
|
|
|
|
} else {
|
|
|
|
/* Front end window */
|
2014-01-13 15:38:35 +04:00
|
|
|
guit->window->get_dimensions(bw->window, width, height, scaled);
|
2013-07-12 16:50:17 +04:00
|
|
|
}
|
2006-09-02 19:52:41 +04:00
|
|
|
}
|
|
|
|
|
2006-09-06 04:15:10 +04:00
|
|
|
|
2014-10-19 22:12:55 +04:00
|
|
|
/* Exported interface, documented in browser.h */
|
2013-07-12 16:50:17 +04:00
|
|
|
void browser_window_set_dimensions(struct browser_window *bw,
|
|
|
|
int width, int height)
|
|
|
|
{
|
|
|
|
assert(bw);
|
|
|
|
|
|
|
|
if (bw->window == NULL) {
|
|
|
|
/* Core managed browser window */
|
|
|
|
bw->width = width;
|
|
|
|
bw->height = height;
|
|
|
|
} else {
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("Asked to set dimensions of front end window.");
|
2013-07-12 16:50:17 +04:00
|
|
|
assert(0);
|
2006-09-02 19:52:41 +04:00
|
|
|
}
|
2004-02-25 18:12:58 +03:00
|
|
|
}
|
2004-01-05 05:10:59 +03:00
|
|
|
|
2013-07-12 16:50:17 +04:00
|
|
|
|
2017-04-26 22:48:54 +03:00
|
|
|
/**
|
|
|
|
* scroll to a fragment if present
|
|
|
|
*
|
|
|
|
* \param bw browser window
|
|
|
|
* \return true if the scroll was sucessful
|
|
|
|
*/
|
|
|
|
static bool frag_scroll(struct browser_window *bw)
|
|
|
|
{
|
|
|
|
struct rect rect;
|
|
|
|
|
|
|
|
if (bw->frag_id == NULL) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!html_get_id_offset(bw->current_content,
|
|
|
|
bw->frag_id,
|
|
|
|
&rect.x0,
|
|
|
|
&rect.y0)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
rect.x1 = rect.x0;
|
|
|
|
rect.y1 = rect.y0;
|
|
|
|
if (browser_window_set_scroll(bw, &rect) == NSERROR_OK) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-10-19 22:12:55 +04:00
|
|
|
/* Exported interface, documented in browser.h */
|
2010-03-28 16:56:39 +04:00
|
|
|
void browser_window_update(struct browser_window *bw, bool scroll_to_top)
|
2004-02-25 18:12:58 +03:00
|
|
|
{
|
2017-04-26 22:48:54 +03:00
|
|
|
static const struct rect zrect = {
|
|
|
|
.x0 = 0,
|
|
|
|
.y0 = 0,
|
|
|
|
.x1 = 0,
|
|
|
|
.y1 = 0
|
|
|
|
};
|
2004-07-06 00:19:52 +04:00
|
|
|
|
2017-04-26 22:48:54 +03:00
|
|
|
if (bw->current_content == NULL) {
|
2004-02-25 18:12:58 +03:00
|
|
|
return;
|
2017-04-26 22:48:54 +03:00
|
|
|
}
|
2004-01-05 05:10:59 +03:00
|
|
|
|
2011-06-15 00:00:18 +04:00
|
|
|
switch (bw->browser_window_type) {
|
2011-09-04 21:24:45 +04:00
|
|
|
|
2011-06-15 00:00:18 +04:00
|
|
|
case BROWSER_WINDOW_NORMAL:
|
|
|
|
/* Root browser window, constituting a front end window/tab */
|
2014-01-12 21:07:34 +04:00
|
|
|
guit->window->set_title(bw->window,
|
2011-06-15 00:00:18 +04:00
|
|
|
content_get_title(bw->current_content));
|
|
|
|
|
|
|
|
browser_window_update_extent(bw);
|
|
|
|
|
|
|
|
/* if frag_id exists, then try to scroll to it */
|
2012-07-24 19:19:49 +04:00
|
|
|
/** @todo don't do this if the user has scrolled */
|
2017-04-26 22:48:54 +03:00
|
|
|
if (!frag_scroll(bw)) {
|
2017-03-03 12:28:54 +03:00
|
|
|
if (scroll_to_top) {
|
2017-04-26 22:48:54 +03:00
|
|
|
browser_window_set_scroll(bw, &zrect);
|
2017-03-03 12:28:54 +03:00
|
|
|
}
|
2011-06-15 00:00:18 +04:00
|
|
|
}
|
2004-01-05 05:10:59 +03:00
|
|
|
|
2017-04-19 18:23:08 +03:00
|
|
|
guit->window->invalidate(bw->window, NULL);
|
2004-01-05 05:10:59 +03:00
|
|
|
|
2011-06-15 00:00:18 +04:00
|
|
|
break;
|
2011-09-04 21:24:45 +04:00
|
|
|
|
2011-06-15 00:00:18 +04:00
|
|
|
case BROWSER_WINDOW_IFRAME:
|
|
|
|
/* Internal iframe browser window */
|
2012-10-11 16:06:51 +04:00
|
|
|
assert(bw->parent != NULL);
|
|
|
|
assert(bw->parent->current_content != NULL);
|
2011-06-15 00:00:18 +04:00
|
|
|
|
2011-07-06 00:13:28 +04:00
|
|
|
browser_window_update_extent(bw);
|
|
|
|
|
2017-04-26 22:48:54 +03:00
|
|
|
if (scroll_to_top) {
|
|
|
|
browser_window_set_scroll(bw, &zrect);
|
|
|
|
}
|
2011-07-06 00:13:28 +04:00
|
|
|
|
|
|
|
/* if frag_id exists, then try to scroll to it */
|
2012-07-24 19:19:49 +04:00
|
|
|
/** @todo don't do this if the user has scrolled */
|
2017-04-26 22:48:54 +03:00
|
|
|
frag_scroll(bw);
|
2009-03-24 01:22:30 +03:00
|
|
|
|
2011-06-15 00:00:18 +04:00
|
|
|
html_redraw_a_box(bw->parent->current_content, bw->box);
|
|
|
|
break;
|
2011-09-04 21:24:45 +04:00
|
|
|
|
|
|
|
case BROWSER_WINDOW_FRAME:
|
|
|
|
{
|
|
|
|
struct rect rect;
|
|
|
|
browser_window_update_extent(bw);
|
|
|
|
|
2017-04-26 22:48:54 +03:00
|
|
|
if (scroll_to_top) {
|
|
|
|
browser_window_set_scroll(bw, &zrect);
|
|
|
|
}
|
2011-09-04 21:24:45 +04:00
|
|
|
|
|
|
|
/* if frag_id exists, then try to scroll to it */
|
2012-07-24 19:19:49 +04:00
|
|
|
/** @todo don't do this if the user has scrolled */
|
2017-04-26 22:48:54 +03:00
|
|
|
frag_scroll(bw);
|
2011-09-04 21:24:45 +04:00
|
|
|
|
2011-12-05 17:49:34 +04:00
|
|
|
rect.x0 = scrollbar_get_offset(bw->scroll_x);
|
|
|
|
rect.y0 = scrollbar_get_offset(bw->scroll_y);
|
|
|
|
rect.x1 = rect.x0 + bw->width;
|
|
|
|
rect.y1 = rect.y0 + bw->height;
|
2011-09-04 21:24:45 +04:00
|
|
|
|
|
|
|
browser_window_update_box(bw, &rect);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
case BROWSER_WINDOW_FRAMESET:
|
|
|
|
/* Nothing to do */
|
|
|
|
break;
|
2009-04-05 23:17:24 +04:00
|
|
|
}
|
2011-06-15 00:00:18 +04:00
|
|
|
}
|
|
|
|
|
2016-05-30 19:32:57 +03:00
|
|
|
/* Exported interface, documented in netsurf/browser_window.h */
|
2011-07-06 19:34:49 +04:00
|
|
|
void browser_window_update_box(struct browser_window *bw, struct rect *rect)
|
2011-06-15 00:00:18 +04:00
|
|
|
{
|
|
|
|
int pos_x;
|
|
|
|
int pos_y;
|
|
|
|
struct browser_window *top;
|
|
|
|
|
2011-09-04 21:24:45 +04:00
|
|
|
assert(bw);
|
2011-06-15 00:00:18 +04:00
|
|
|
|
2011-09-04 21:24:45 +04:00
|
|
|
if (bw->window != NULL) {
|
|
|
|
/* Front end window */
|
2017-04-19 18:23:08 +03:00
|
|
|
guit->window->invalidate(bw->window, rect);
|
2011-09-04 21:24:45 +04:00
|
|
|
} else {
|
|
|
|
/* Core managed browser window */
|
2011-06-15 00:00:18 +04:00
|
|
|
browser_window_get_position(bw, true, &pos_x, &pos_y);
|
2004-08-07 02:19:13 +04:00
|
|
|
|
2011-06-29 01:09:57 +04:00
|
|
|
top = browser_window_get_root(bw);
|
2011-06-15 00:00:18 +04:00
|
|
|
|
2011-07-06 19:34:49 +04:00
|
|
|
rect->x0 += pos_x / bw->scale;
|
|
|
|
rect->y0 += pos_y / bw->scale;
|
|
|
|
rect->x1 += pos_x / bw->scale;
|
|
|
|
rect->y1 += pos_y / bw->scale;
|
2011-06-15 00:00:18 +04:00
|
|
|
|
2017-04-19 18:23:08 +03:00
|
|
|
guit->window->invalidate(top->window, rect);
|
2011-06-15 00:00:18 +04:00
|
|
|
}
|
2002-09-11 18:24:02 +04:00
|
|
|
}
|
|
|
|
|
2016-05-30 19:32:57 +03:00
|
|
|
/* Exported interface, documented in netsurf/browser_window.h */
|
2004-02-25 18:12:58 +03:00
|
|
|
void browser_window_stop(struct browser_window *bw)
|
|
|
|
{
|
2006-09-02 19:52:41 +04:00
|
|
|
int children, index;
|
2006-09-06 04:15:10 +04:00
|
|
|
|
2010-03-28 16:56:39 +04:00
|
|
|
if (bw->loading_content != NULL) {
|
2010-04-04 16:41:19 +04:00
|
|
|
hlcache_handle_abort(bw->loading_content);
|
2010-03-28 16:56:39 +04:00
|
|
|
hlcache_handle_release(bw->loading_content);
|
|
|
|
bw->loading_content = NULL;
|
2004-02-25 18:12:58 +03:00
|
|
|
}
|
2003-12-28 19:17:31 +03:00
|
|
|
|
2010-03-28 16:56:39 +04:00
|
|
|
if (bw->current_content != NULL && content_get_status(
|
|
|
|
bw->current_content) != CONTENT_STATUS_DONE) {
|
2010-04-04 16:41:19 +04:00
|
|
|
nserror error;
|
2014-10-20 00:49:46 +04:00
|
|
|
assert(content_get_status(bw->current_content) ==
|
2010-03-28 16:56:39 +04:00
|
|
|
CONTENT_STATUS_READY);
|
2010-04-04 16:41:19 +04:00
|
|
|
error = hlcache_handle_abort(bw->current_content);
|
|
|
|
assert(error == NSERROR_OK);
|
2004-02-25 18:12:58 +03:00
|
|
|
}
|
2003-12-22 01:10:15 +03:00
|
|
|
|
2016-04-16 00:50:28 +03:00
|
|
|
guit->misc->schedule(-1, browser_window_refresh, bw);
|
2006-09-06 04:15:10 +04:00
|
|
|
|
2006-09-02 19:52:41 +04:00
|
|
|
if (bw->children) {
|
|
|
|
children = bw->rows * bw->cols;
|
|
|
|
for (index = 0; index < children; index++)
|
|
|
|
browser_window_stop(&bw->children[index]);
|
|
|
|
}
|
|
|
|
if (bw->iframes) {
|
|
|
|
children = bw->iframe_count;
|
|
|
|
for (index = 0; index < children; index++)
|
|
|
|
browser_window_stop(&bw->iframes[index]);
|
|
|
|
}
|
2006-01-25 11:25:38 +03:00
|
|
|
|
2010-04-12 14:57:41 +04:00
|
|
|
if (bw->current_content != NULL) {
|
2014-02-08 16:07:13 +04:00
|
|
|
browser_window_refresh_url_bar(bw);
|
2010-04-12 14:57:41 +04:00
|
|
|
}
|
|
|
|
|
2004-02-25 18:12:58 +03:00
|
|
|
browser_window_stop_throbber(bw);
|
|
|
|
}
|
2003-10-25 23:20:13 +04:00
|
|
|
|
|
|
|
|
2016-05-30 19:32:57 +03:00
|
|
|
/* Exported interface, documented in netsurf/browser_window.h */
|
2004-06-29 23:08:19 +04:00
|
|
|
void browser_window_reload(struct browser_window *bw, bool all)
|
2004-06-23 00:39:16 +04:00
|
|
|
{
|
2010-03-28 16:56:39 +04:00
|
|
|
hlcache_handle *c;
|
2004-06-29 23:08:19 +04:00
|
|
|
unsigned int i;
|
|
|
|
|
2010-03-28 16:56:39 +04:00
|
|
|
if (bw->current_content == NULL || bw->loading_content != NULL)
|
2004-06-23 00:39:16 +04:00
|
|
|
return;
|
|
|
|
|
2010-03-28 16:56:39 +04:00
|
|
|
if (all && content_get_type(bw->current_content) == CONTENT_HTML) {
|
|
|
|
struct html_stylesheet *sheets;
|
2011-03-12 20:47:46 +03:00
|
|
|
struct content_html_object *object;
|
2010-03-28 16:56:39 +04:00
|
|
|
unsigned int count;
|
|
|
|
|
2004-06-29 23:08:19 +04:00
|
|
|
c = bw->current_content;
|
2010-03-28 16:56:39 +04:00
|
|
|
|
2004-06-29 23:08:19 +04:00
|
|
|
/* invalidate objects */
|
2011-03-12 20:47:46 +03:00
|
|
|
object = html_get_objects(c, &count);
|
2010-03-28 16:56:39 +04:00
|
|
|
|
2011-03-12 20:47:46 +03:00
|
|
|
for (; object != NULL; object = object->next) {
|
|
|
|
if (object->content != NULL)
|
|
|
|
content_invalidate_reuse_data(object->content);
|
2004-06-29 23:08:19 +04:00
|
|
|
}
|
2010-03-28 16:56:39 +04:00
|
|
|
|
2004-06-29 23:08:19 +04:00
|
|
|
/* invalidate stylesheets */
|
2010-03-28 16:56:39 +04:00
|
|
|
sheets = html_get_stylesheets(c, &count);
|
|
|
|
|
|
|
|
for (i = STYLESHEET_START; i != count; i++) {
|
2013-02-27 07:11:10 +04:00
|
|
|
if (sheets[i].sheet != NULL) {
|
|
|
|
content_invalidate_reuse_data(sheets[i].sheet);
|
2010-03-28 16:56:39 +04:00
|
|
|
}
|
2004-06-29 23:08:19 +04:00
|
|
|
}
|
|
|
|
}
|
2010-03-28 16:56:39 +04:00
|
|
|
|
|
|
|
content_invalidate_reuse_data(bw->current_content);
|
|
|
|
|
2013-02-14 19:09:28 +04:00
|
|
|
browser_window_navigate(bw,
|
|
|
|
hlcache_handle_get_url(bw->current_content),
|
|
|
|
NULL,
|
2014-02-11 02:40:04 +04:00
|
|
|
BW_NAVIGATE_NONE,
|
2013-02-14 19:09:28 +04:00
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
2004-06-23 00:39:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-05-30 19:32:57 +03:00
|
|
|
/* Exported interface, documented in netsurf/browser_window.h */
|
2004-02-25 18:12:58 +03:00
|
|
|
void browser_window_set_status(struct browser_window *bw, const char *text)
|
|
|
|
{
|
2010-02-11 02:37:06 +03:00
|
|
|
int text_len;
|
|
|
|
/* find topmost window */
|
2006-09-02 19:52:41 +04:00
|
|
|
while (bw->parent)
|
|
|
|
bw = bw->parent;
|
2010-02-11 02:37:06 +03:00
|
|
|
|
2017-03-03 12:28:54 +03:00
|
|
|
if ((bw->status.text != NULL) &&
|
|
|
|
(strcmp(text, bw->status.text) == 0)) {
|
2010-02-11 02:37:06 +03:00
|
|
|
/* status text is unchanged */
|
2017-03-03 12:28:54 +03:00
|
|
|
bw->status.match++;
|
2010-02-11 02:37:06 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* status text is changed */
|
2014-10-20 00:49:46 +04:00
|
|
|
|
2010-02-11 02:37:06 +03:00
|
|
|
text_len = strlen(text);
|
|
|
|
|
2017-03-03 12:28:54 +03:00
|
|
|
if ((bw->status.text == NULL) || (bw->status.text_len < text_len)) {
|
2010-02-11 02:37:06 +03:00
|
|
|
/* no current string allocation or it is not long enough */
|
2017-03-03 12:28:54 +03:00
|
|
|
free(bw->status.text);
|
|
|
|
bw->status.text = strdup(text);
|
|
|
|
bw->status.text_len = text_len;
|
2010-02-11 02:37:06 +03:00
|
|
|
} else {
|
|
|
|
/* current allocation has enough space */
|
2017-03-03 12:28:54 +03:00
|
|
|
memcpy(bw->status.text, text, text_len + 1);
|
2010-02-11 02:37:06 +03:00
|
|
|
}
|
|
|
|
|
2017-03-03 12:28:54 +03:00
|
|
|
bw->status.miss++;
|
|
|
|
guit->window->set_status(bw->window, bw->status.text);
|
2002-09-11 18:24:02 +04:00
|
|
|
}
|
|
|
|
|
2004-07-18 21:38:01 +04:00
|
|
|
|
2016-05-30 19:32:57 +03:00
|
|
|
/* Exported interface, documented in netsurf/browser_window.h */
|
2011-06-15 00:00:18 +04:00
|
|
|
void browser_window_set_pointer(struct browser_window *bw,
|
2012-08-17 01:21:08 +04:00
|
|
|
browser_pointer_shape shape)
|
2004-04-01 04:26:05 +04:00
|
|
|
{
|
2011-06-29 01:09:57 +04:00
|
|
|
struct browser_window *root = browser_window_get_root(bw);
|
2012-08-17 01:21:08 +04:00
|
|
|
gui_pointer_shape gui_shape;
|
2012-08-17 01:44:25 +04:00
|
|
|
bool loading;
|
2016-04-21 15:12:56 +03:00
|
|
|
uint64_t ms_now;
|
2011-06-15 00:00:18 +04:00
|
|
|
|
|
|
|
assert(root);
|
2013-07-12 16:50:17 +04:00
|
|
|
assert(root->window);
|
2011-06-15 00:00:18 +04:00
|
|
|
|
2016-04-21 15:12:56 +03:00
|
|
|
loading = ((bw->loading_content != NULL) ||
|
|
|
|
((bw->current_content != NULL) &&
|
|
|
|
(content_get_status(bw->current_content) == CONTENT_STATUS_READY)));
|
|
|
|
|
|
|
|
nsu_getmonotonic_ms(&ms_now);
|
2012-01-02 01:42:38 +04:00
|
|
|
|
2016-04-21 15:12:56 +03:00
|
|
|
if (loading && ((ms_now - bw->last_action) < 1000)) {
|
2013-07-12 16:50:17 +04:00
|
|
|
/* If loading and less than 1 second since last link followed,
|
|
|
|
* force progress indicator pointer */
|
|
|
|
gui_shape = GUI_POINTER_PROGRESS;
|
2011-10-29 02:27:50 +04:00
|
|
|
|
2013-07-12 16:50:17 +04:00
|
|
|
} else if (shape == BROWSER_POINTER_AUTO) {
|
|
|
|
/* Up to browser window to decide */
|
2016-04-21 15:12:56 +03:00
|
|
|
if (loading) {
|
2013-07-12 16:50:17 +04:00
|
|
|
gui_shape = GUI_POINTER_PROGRESS;
|
2016-04-21 15:12:56 +03:00
|
|
|
} else {
|
2013-07-12 16:50:17 +04:00
|
|
|
gui_shape = GUI_POINTER_DEFAULT;
|
2016-04-21 15:12:56 +03:00
|
|
|
}
|
2011-10-29 02:27:50 +04:00
|
|
|
|
2013-07-12 16:50:17 +04:00
|
|
|
} else {
|
|
|
|
/* Use what we were told */
|
|
|
|
gui_shape = (gui_pointer_shape)shape;
|
|
|
|
}
|
2011-01-17 11:35:20 +03:00
|
|
|
|
2014-01-13 18:51:27 +04:00
|
|
|
guit->window->set_pointer(root->window, gui_shape);
|
2006-09-02 19:52:41 +04:00
|
|
|
}
|
|
|
|
|
2017-04-26 11:43:18 +03:00
|
|
|
|
2016-05-30 19:32:57 +03:00
|
|
|
/* exported function documented in netsurf/browser_window.h */
|
2014-06-30 19:40:56 +04:00
|
|
|
nserror browser_window_schedule_reformat(struct browser_window *bw)
|
|
|
|
{
|
2017-04-26 11:43:18 +03:00
|
|
|
if (bw->window == NULL) {
|
|
|
|
return NSERROR_BAD_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
guit->misc->schedule(0, scheduled_reformat, bw);
|
|
|
|
|
2014-06-30 19:40:56 +04:00
|
|
|
return NSERROR_OK;
|
|
|
|
}
|
2006-09-02 19:52:41 +04:00
|
|
|
|
2006-11-27 00:04:42 +03:00
|
|
|
|
2016-05-30 19:32:57 +03:00
|
|
|
/* exported function documented in netsurf/browser_window.h */
|
2011-06-24 13:30:33 +04:00
|
|
|
void browser_window_reformat(struct browser_window *bw, bool background,
|
|
|
|
int width, int height)
|
2006-11-27 00:04:42 +03:00
|
|
|
{
|
2010-03-28 16:56:39 +04:00
|
|
|
hlcache_handle *c = bw->current_content;
|
2006-11-27 00:04:42 +03:00
|
|
|
|
2010-03-28 16:56:39 +04:00
|
|
|
if (c == NULL)
|
2006-11-27 00:04:42 +03:00
|
|
|
return;
|
|
|
|
|
2011-06-15 15:46:07 +04:00
|
|
|
if (bw->browser_window_type != BROWSER_WINDOW_IFRAME) {
|
|
|
|
/* Iframe dimensions are already scaled in parent's layout */
|
2011-07-06 00:13:28 +04:00
|
|
|
width /= bw->scale;
|
2011-06-15 15:46:07 +04:00
|
|
|
height /= bw->scale;
|
2011-09-04 21:24:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (bw->window == NULL) {
|
|
|
|
/* Core managed browser window; subtract scrollbar width */
|
2011-07-06 00:13:28 +04:00
|
|
|
width -= bw->scroll_y ? SCROLLBAR_WIDTH : 0;
|
|
|
|
height -= bw->scroll_x ? SCROLLBAR_WIDTH : 0;
|
|
|
|
|
|
|
|
width = width > 0 ? width : 0;
|
|
|
|
height = height > 0 ? height : 0;
|
2011-06-15 15:46:07 +04:00
|
|
|
}
|
|
|
|
|
2011-06-24 13:30:33 +04:00
|
|
|
content_reformat(c, background, width, height);
|
2006-11-27 00:04:42 +03:00
|
|
|
}
|
|
|
|
|
2014-10-19 22:12:55 +04:00
|
|
|
/**
|
2015-04-15 01:08:02 +03:00
|
|
|
* Set browser window scale.
|
2014-10-19 22:12:55 +04:00
|
|
|
*
|
|
|
|
* \param bw Browser window.
|
|
|
|
* \param scale value.
|
|
|
|
*/
|
2013-07-12 16:50:17 +04:00
|
|
|
static void browser_window_set_scale_internal(struct browser_window *bw,
|
|
|
|
float scale)
|
2006-11-27 00:04:42 +03:00
|
|
|
{
|
2007-03-25 23:32:41 +04:00
|
|
|
int i;
|
2010-03-28 16:56:39 +04:00
|
|
|
hlcache_handle *c;
|
2007-08-07 07:55:18 +04:00
|
|
|
|
2007-10-28 20:05:39 +03:00
|
|
|
if (fabs(bw->scale-scale) < 0.0001)
|
2007-08-07 07:55:18 +04:00
|
|
|
return;
|
2010-03-28 16:56:39 +04:00
|
|
|
|
2007-08-07 07:55:18 +04:00
|
|
|
bw->scale = scale;
|
|
|
|
c = bw->current_content;
|
2010-03-28 16:56:39 +04:00
|
|
|
|
|
|
|
if (c != NULL) {
|
2011-10-08 14:22:34 +04:00
|
|
|
if (content_can_reformat(c) == false) {
|
2009-04-05 23:17:24 +04:00
|
|
|
browser_window_update(bw, false);
|
2011-10-08 14:22:34 +04:00
|
|
|
} else {
|
2014-06-30 19:40:56 +04:00
|
|
|
browser_window_schedule_reformat(bw);
|
2011-10-08 14:22:34 +04:00
|
|
|
}
|
2007-08-07 07:55:18 +04:00
|
|
|
}
|
2006-11-26 23:11:20 +03:00
|
|
|
|
|
|
|
for (i = 0; i < (bw->cols * bw->rows); i++)
|
|
|
|
browser_window_set_scale_internal(&bw->children[i], scale);
|
|
|
|
for (i = 0; i < bw->iframe_count; i++)
|
|
|
|
browser_window_set_scale_internal(&bw->iframes[i], scale);
|
|
|
|
}
|
|
|
|
|
2009-03-31 15:06:09 +04:00
|
|
|
|
2016-05-30 19:32:57 +03:00
|
|
|
/* exported interface documented in netsurf/browser_window.h */
|
2013-07-12 16:50:17 +04:00
|
|
|
void browser_window_set_scale(struct browser_window *bw, float scale, bool all)
|
|
|
|
{
|
|
|
|
while (bw->parent && all)
|
|
|
|
bw = bw->parent;
|
|
|
|
|
|
|
|
browser_window_set_scale_internal(bw, scale);
|
|
|
|
|
|
|
|
if (bw->parent)
|
|
|
|
bw = bw->parent;
|
|
|
|
|
|
|
|
browser_window_recalculate_frameset(bw);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-05-30 19:32:57 +03:00
|
|
|
/* exported interface documented in netsurf/browser_window.h */
|
2012-02-28 02:43:25 +04:00
|
|
|
float browser_window_get_scale(struct browser_window *bw)
|
|
|
|
{
|
2014-11-21 14:48:43 +03:00
|
|
|
if (bw == NULL) {
|
|
|
|
return 1.0;
|
|
|
|
}
|
|
|
|
|
2012-02-28 02:43:25 +04:00
|
|
|
return bw->scale;
|
|
|
|
}
|
|
|
|
|
2014-10-19 22:12:55 +04:00
|
|
|
/**
|
|
|
|
* Find browser window.
|
|
|
|
*
|
|
|
|
* \param bw Browser window.
|
|
|
|
* \param target Name of target.
|
|
|
|
* \param depth Depth to scan.
|
|
|
|
* \param page The browser window page.
|
|
|
|
* \param rdepth The rdepth.
|
|
|
|
* \param bw_target the output browser window.
|
|
|
|
*/
|
2013-07-12 16:50:17 +04:00
|
|
|
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)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if ((bw->name) && (!strcasecmp(bw->name, target))) {
|
|
|
|
if ((bw == page) || (depth > *rdepth)) {
|
|
|
|
*rdepth = depth;
|
|
|
|
*bw_target = bw;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((!bw->children) && (!bw->iframes))
|
|
|
|
return;
|
|
|
|
|
|
|
|
depth++;
|
|
|
|
|
|
|
|
if (bw->children != NULL) {
|
|
|
|
for (i = 0; i < (bw->cols * bw->rows); i++) {
|
|
|
|
if ((bw->children[i].name) &&
|
2014-10-20 00:49:46 +04:00
|
|
|
(!strcasecmp(bw->children[i].name,
|
2013-07-12 16:50:17 +04:00
|
|
|
target))) {
|
2014-10-20 00:49:46 +04:00
|
|
|
if ((page == &bw->children[i]) ||
|
2013-07-12 16:50:17 +04:00
|
|
|
(depth > *rdepth)) {
|
|
|
|
*rdepth = depth;
|
|
|
|
*bw_target = &bw->children[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (bw->children[i].children)
|
|
|
|
browser_window_find_target_internal(
|
|
|
|
&bw->children[i],
|
2014-10-20 00:49:46 +04:00
|
|
|
target, depth, page,
|
2013-07-12 16:50:17 +04:00
|
|
|
rdepth, bw_target);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bw->iframes != NULL) {
|
|
|
|
for (i = 0; i < bw->iframe_count; i++)
|
2014-10-20 00:49:46 +04:00
|
|
|
browser_window_find_target_internal(&bw->iframes[i],
|
2013-07-12 16:50:17 +04:00
|
|
|
target, depth, page, rdepth, bw_target);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-05-30 19:32:57 +03:00
|
|
|
/* exported interface documented in netsurf/browser_window.h */
|
2008-11-29 03:24:09 +03:00
|
|
|
struct browser_window *browser_window_find_target(struct browser_window *bw,
|
|
|
|
const char *target, browser_mouse_state mouse)
|
2006-09-02 19:52:41 +04:00
|
|
|
{
|
|
|
|
struct browser_window *bw_target;
|
|
|
|
struct browser_window *top;
|
2010-03-28 16:56:39 +04:00
|
|
|
hlcache_handle *c;
|
2006-09-02 19:52:41 +04:00
|
|
|
int rdepth;
|
2013-02-14 22:21:11 +04:00
|
|
|
nserror error;
|
2006-09-06 04:15:10 +04:00
|
|
|
|
2006-09-02 19:52:41 +04:00
|
|
|
/* use the base target if we don't have one */
|
|
|
|
c = bw->current_content;
|
2010-03-28 16:56:39 +04:00
|
|
|
if (target == NULL && c != NULL && content_get_type(c) == CONTENT_HTML)
|
|
|
|
target = html_get_base_target(c);
|
|
|
|
if (target == NULL)
|
2007-04-08 03:08:31 +04:00
|
|
|
target = TARGET_SELF;
|
2006-09-02 19:52:41 +04:00
|
|
|
|
2008-11-29 03:24:09 +03:00
|
|
|
/* 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))) &&
|
2012-03-22 13:34:34 +04:00
|
|
|
(!nsoption_bool(target_blank))) {
|
2008-11-29 03:24:09 +03:00
|
|
|
/* not a mouse button 2 click
|
|
|
|
* not a mouse button 1 click with ctrl pressed
|
|
|
|
* configured to ignore target="_blank" */
|
2007-04-08 21:49:42 +04:00
|
|
|
if ((target == TARGET_BLANK) || (!strcasecmp(target, "_blank")))
|
|
|
|
return bw;
|
|
|
|
}
|
2006-09-02 19:52:41 +04:00
|
|
|
|
2007-04-08 03:08:31 +04:00
|
|
|
/* handle reserved keywords */
|
2014-10-20 00:49:46 +04:00
|
|
|
if (((nsoption_bool(button_2_tab)) &&
|
2012-03-22 13:34:34 +04:00
|
|
|
(mouse & BROWSER_MOUSE_CLICK_2))||
|
|
|
|
((!nsoption_bool(button_2_tab)) &&
|
|
|
|
((mouse & BROWSER_MOUSE_CLICK_1) &&
|
|
|
|
(mouse & BROWSER_MOUSE_MOD_2))) ||
|
2014-10-20 00:49:46 +04:00
|
|
|
((nsoption_bool(button_2_tab)) &&
|
2012-03-22 13:34:34 +04:00
|
|
|
((target == TARGET_BLANK) ||
|
|
|
|
(!strcasecmp(target, "_blank"))))) {
|
2008-11-29 03:24:09 +03:00
|
|
|
/* 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"
|
|
|
|
*/
|
2014-02-10 18:08:45 +04:00
|
|
|
error = browser_window_create(BW_CREATE_TAB |
|
|
|
|
BW_CREATE_HISTORY |
|
|
|
|
BW_CREATE_CLONE,
|
2013-02-14 22:21:11 +04:00
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
bw,
|
|
|
|
&bw_target);
|
|
|
|
if (error != NSERROR_OK) {
|
2008-11-29 03:24:09 +03:00
|
|
|
return bw;
|
2013-02-14 22:21:11 +04:00
|
|
|
}
|
2008-11-29 03:24:09 +03:00
|
|
|
return bw_target;
|
2012-03-22 13:34:34 +04:00
|
|
|
} else if (((!nsoption_bool(button_2_tab)) &&
|
|
|
|
(mouse & BROWSER_MOUSE_CLICK_2)) ||
|
|
|
|
((nsoption_bool(button_2_tab)) &&
|
|
|
|
((mouse & BROWSER_MOUSE_CLICK_1) &&
|
|
|
|
(mouse & BROWSER_MOUSE_MOD_2))) ||
|
2014-10-20 00:49:46 +04:00
|
|
|
((!nsoption_bool(button_2_tab)) &&
|
2012-03-22 13:34:34 +04:00
|
|
|
((target == TARGET_BLANK) ||
|
|
|
|
(!strcasecmp(target, "_blank"))))) {
|
2008-11-29 03:24:09 +03:00
|
|
|
/* 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"
|
|
|
|
*/
|
2014-02-10 18:08:45 +04:00
|
|
|
error = browser_window_create(BW_CREATE_HISTORY |
|
|
|
|
BW_CREATE_CLONE,
|
2013-02-14 22:21:11 +04:00
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
bw,
|
|
|
|
&bw_target);
|
|
|
|
if (error != NSERROR_OK) {
|
2007-04-08 03:08:31 +04:00
|
|
|
return bw;
|
2013-02-14 22:21:11 +04:00
|
|
|
}
|
2007-04-08 03:08:31 +04:00
|
|
|
return bw_target;
|
|
|
|
} else if ((target == TARGET_SELF) || (!strcasecmp(target, "_self"))) {
|
2006-09-02 19:52:41 +04:00
|
|
|
return bw;
|
2008-11-29 03:24:09 +03:00
|
|
|
} else if ((target == TARGET_PARENT) ||
|
|
|
|
(!strcasecmp(target, "_parent"))) {
|
2006-09-02 19:52:41 +04:00
|
|
|
if (bw->parent)
|
|
|
|
return bw->parent;
|
|
|
|
return bw;
|
|
|
|
} else if ((target == TARGET_TOP) || (!strcasecmp(target, "_top"))) {
|
|
|
|
while (bw->parent)
|
|
|
|
bw = bw->parent;
|
|
|
|
return bw;
|
|
|
|
}
|
2006-09-06 04:15:10 +04:00
|
|
|
|
2006-09-02 19:52:41 +04:00
|
|
|
/* find frame according to B.8, ie using the following priorities:
|
|
|
|
*
|
|
|
|
* 1) current frame
|
|
|
|
* 2) closest to front
|
|
|
|
*/
|
|
|
|
rdepth = -1;
|
2007-04-08 03:08:31 +04:00
|
|
|
bw_target = NULL;
|
2006-09-02 19:52:41 +04:00
|
|
|
for (top = bw; top->parent; top = top->parent);
|
2009-03-31 15:06:09 +04:00
|
|
|
browser_window_find_target_internal(top, target, 0, bw, &rdepth,
|
|
|
|
&bw_target);
|
2007-04-08 03:08:31 +04:00
|
|
|
if (bw_target)
|
|
|
|
return bw_target;
|
2007-08-07 11:58:04 +04:00
|
|
|
|
2007-04-08 03:08:31 +04:00
|
|
|
/* we require a new window using the target name */
|
2012-03-22 13:34:34 +04:00
|
|
|
if (!nsoption_bool(target_blank))
|
2007-04-08 03:08:31 +04:00
|
|
|
return bw;
|
2012-03-22 13:34:34 +04:00
|
|
|
|
2014-02-10 18:08:45 +04:00
|
|
|
error = browser_window_create(BW_CREATE_CLONE | BW_CREATE_HISTORY,
|
2013-02-14 22:21:11 +04:00
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
bw,
|
|
|
|
&bw_target);
|
|
|
|
if (error != NSERROR_OK) {
|
2007-04-08 03:08:31 +04:00
|
|
|
return bw;
|
2013-02-14 22:21:11 +04:00
|
|
|
}
|
2007-08-07 11:58:04 +04:00
|
|
|
|
2009-03-31 15:06:09 +04:00
|
|
|
/* frame names should begin with an alphabetic character (a-z,A-Z),
|
|
|
|
* however in practice you get things such as '_new' and '2left'. The
|
|
|
|
* only real effect this has is when giving out names as it can be
|
|
|
|
* assumed that an author intended '_new' to create a new nameless
|
|
|
|
* window (ie '_blank') whereas in the case of '2left' the intention
|
|
|
|
* was for a new named window. As such we merely special case windows
|
|
|
|
* that begin with an underscore. */
|
2007-04-08 03:08:31 +04:00
|
|
|
if (target[0] != '_') {
|
|
|
|
bw_target->name = strdup(target);
|
|
|
|
if (!bw_target->name)
|
2016-04-26 14:50:16 +03:00
|
|
|
guit->misc->warning("NoMemory", NULL);
|
2007-04-08 03:08:31 +04:00
|
|
|
}
|
2006-09-02 19:52:41 +04:00
|
|
|
return bw_target;
|
|
|
|
}
|
|
|
|
|
2013-07-12 16:50:17 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Handles the end of a drag operation in a browser window.
|
|
|
|
*
|
|
|
|
* \param bw browser window
|
|
|
|
* \param mouse state of mouse buttons and modifier keys
|
|
|
|
* \param x coordinate of mouse
|
|
|
|
* \param y coordinate of mouse
|
|
|
|
*
|
2014-10-19 22:12:55 +04:00
|
|
|
* \todo Remove this function, once these things are associated with content,
|
2013-07-12 16:50:17 +04:00
|
|
|
* rather than bw.
|
|
|
|
*/
|
|
|
|
static void browser_window_mouse_drag_end(struct browser_window *bw,
|
|
|
|
browser_mouse_state mouse, int x, int y)
|
2006-09-02 19:52:41 +04:00
|
|
|
{
|
2013-07-12 16:50:17 +04:00
|
|
|
int scr_x, scr_y;
|
2006-09-06 04:15:10 +04:00
|
|
|
|
2017-03-03 17:30:39 +03:00
|
|
|
switch (bw->drag.type) {
|
2013-07-12 16:50:17 +04:00
|
|
|
case DRAGGING_SELECTION:
|
|
|
|
case DRAGGING_OTHER:
|
|
|
|
case DRAGGING_CONTENT_SCROLLBAR:
|
|
|
|
/* Drag handled by content handler */
|
|
|
|
break;
|
2006-09-02 19:52:41 +04:00
|
|
|
|
2013-07-12 16:50:17 +04:00
|
|
|
case DRAGGING_SCR_X:
|
2006-09-06 04:15:10 +04:00
|
|
|
|
2013-07-12 16:50:17 +04:00
|
|
|
browser_window_get_scrollbar_pos(bw, true, &scr_x, &scr_y);
|
2009-11-22 16:35:41 +03:00
|
|
|
|
2013-07-12 16:50:17 +04:00
|
|
|
scr_x = x - scr_x - scrollbar_get_offset(bw->scroll_x);
|
|
|
|
scr_y = y - scr_y - scrollbar_get_offset(bw->scroll_y);
|
2009-11-22 16:35:41 +03:00
|
|
|
|
2013-07-12 16:50:17 +04:00
|
|
|
scrollbar_mouse_drag_end(bw->scroll_x, mouse, scr_x, scr_y);
|
|
|
|
|
2017-03-03 17:30:39 +03:00
|
|
|
bw->drag.type = DRAGGING_NONE;
|
2013-07-12 16:50:17 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DRAGGING_SCR_Y:
|
|
|
|
|
|
|
|
browser_window_get_scrollbar_pos(bw, false, &scr_x, &scr_y);
|
|
|
|
|
|
|
|
scr_x = x - scr_x - scrollbar_get_offset(bw->scroll_x);
|
|
|
|
scr_y = y - scr_y - scrollbar_get_offset(bw->scroll_y);
|
|
|
|
|
|
|
|
scrollbar_mouse_drag_end(bw->scroll_y, mouse, scr_x, scr_y);
|
|
|
|
|
2017-03-03 17:30:39 +03:00
|
|
|
bw->drag.type = DRAGGING_NONE;
|
2013-07-12 16:50:17 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
browser_window_set_drag_type(bw, DRAGGING_NONE, NULL);
|
|
|
|
break;
|
2006-09-02 19:52:41 +04:00
|
|
|
}
|
2003-10-25 18:13:49 +04:00
|
|
|
}
|
|
|
|
|
2004-02-25 18:12:58 +03:00
|
|
|
|
2016-05-30 19:32:57 +03:00
|
|
|
/* exported interface documented in netsurf/browser_window.h */
|
2005-04-15 09:52:25 +04:00
|
|
|
void browser_window_mouse_track(struct browser_window *bw,
|
|
|
|
browser_mouse_state mouse, int x, int y)
|
2004-10-18 01:11:29 +04:00
|
|
|
{
|
2010-03-28 16:56:39 +04:00
|
|
|
hlcache_handle *c = bw->current_content;
|
2011-07-06 00:13:28 +04:00
|
|
|
const char *status = NULL;
|
2012-08-17 01:21:08 +04:00
|
|
|
browser_pointer_shape pointer = BROWSER_POINTER_DEFAULT;
|
2009-05-28 18:35:12 +04:00
|
|
|
|
2017-03-03 17:30:39 +03:00
|
|
|
if (bw->window != NULL && bw->drag.window && bw != bw->drag.window) {
|
2011-09-04 21:24:45 +04:00
|
|
|
/* This is the root browser window and there's an active drag
|
|
|
|
* in a sub window.
|
|
|
|
* Pass the mouse action straight on to that bw. */
|
2017-03-03 17:30:39 +03:00
|
|
|
struct browser_window *drag_bw = bw->drag.window;
|
2011-09-04 21:24:45 +04:00
|
|
|
int off_x = 0;
|
|
|
|
int off_y = 0;
|
2011-08-24 22:22:22 +04:00
|
|
|
|
2011-09-04 21:24:45 +04:00
|
|
|
browser_window_get_position(drag_bw, true, &off_x, &off_y);
|
|
|
|
|
|
|
|
if (drag_bw->browser_window_type == BROWSER_WINDOW_FRAME) {
|
|
|
|
browser_window_mouse_track(drag_bw, mouse,
|
|
|
|
x - off_x, y - off_y);
|
|
|
|
|
|
|
|
} else if (drag_bw->browser_window_type ==
|
|
|
|
BROWSER_WINDOW_IFRAME) {
|
|
|
|
browser_window_mouse_track(drag_bw, mouse,
|
2011-08-24 22:22:22 +04:00
|
|
|
x - off_x / bw->scale,
|
|
|
|
y - off_y / bw->scale);
|
2011-09-04 21:24:45 +04:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bw->children) {
|
|
|
|
/* Browser window has children (frames) */
|
|
|
|
struct browser_window *child;
|
|
|
|
int cur_child;
|
|
|
|
int children = bw->rows * bw->cols;
|
|
|
|
|
|
|
|
for (cur_child = 0; cur_child < children; cur_child++) {
|
|
|
|
|
|
|
|
child = &bw->children[cur_child];
|
|
|
|
|
|
|
|
if (x < child->x || y < child->y ||
|
|
|
|
child->x + child->width < x ||
|
|
|
|
child->y + child->height < y) {
|
|
|
|
/* Click not in this child */
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* It's this child that contains the mouse; pass
|
|
|
|
* mouse action on to child */
|
|
|
|
browser_window_mouse_track(child, mouse,
|
|
|
|
x - child->x + scrollbar_get_offset(
|
|
|
|
child->scroll_x),
|
|
|
|
y - child->y + scrollbar_get_offset(
|
|
|
|
child->scroll_y));
|
|
|
|
|
|
|
|
/* Mouse action was for this child, we're done */
|
2011-08-24 22:22:22 +04:00
|
|
|
return;
|
|
|
|
}
|
2011-09-04 21:24:45 +04:00
|
|
|
|
|
|
|
/* Odd if we reached here, but nothing else can use the click
|
|
|
|
* when there are children. */
|
|
|
|
return;
|
2011-08-24 22:22:22 +04:00
|
|
|
}
|
|
|
|
|
2017-03-03 17:30:39 +03:00
|
|
|
if (c == NULL && bw->drag.type != DRAGGING_FRAME) {
|
2005-08-21 14:52:17 +04:00
|
|
|
return;
|
2017-03-03 17:30:39 +03:00
|
|
|
}
|
2004-10-18 01:11:29 +04:00
|
|
|
|
2017-03-03 17:30:39 +03:00
|
|
|
if (bw->drag.type != DRAGGING_NONE && !mouse) {
|
2005-04-15 09:52:25 +04:00
|
|
|
browser_window_mouse_drag_end(bw, mouse, x, y);
|
|
|
|
}
|
2009-05-28 18:35:12 +04:00
|
|
|
|
2011-07-13 17:20:26 +04:00
|
|
|
/* Browser window's horizontal scrollbar */
|
2017-03-03 17:30:39 +03:00
|
|
|
if (bw->scroll_x != NULL && bw->drag.type != DRAGGING_SCR_Y) {
|
2011-07-06 00:13:28 +04:00
|
|
|
int scr_x, scr_y;
|
|
|
|
browser_window_get_scrollbar_pos(bw, true, &scr_x, &scr_y);
|
|
|
|
scr_x = x - scr_x - scrollbar_get_offset(bw->scroll_x);
|
|
|
|
scr_y = y - scr_y - scrollbar_get_offset(bw->scroll_y);
|
|
|
|
|
2017-03-03 17:30:39 +03:00
|
|
|
if ((bw->drag.type == DRAGGING_SCR_X) ||
|
|
|
|
(scr_x > 0 &&
|
|
|
|
scr_x < browser_window_get_scrollbar_len(bw, true) &&
|
|
|
|
scr_y > 0 &&
|
|
|
|
scr_y < SCROLLBAR_WIDTH &&
|
|
|
|
bw->drag.type == DRAGGING_NONE)) {
|
2011-08-25 00:44:47 +04:00
|
|
|
/* Start a scrollbar drag, or continue existing drag */
|
2013-03-11 16:57:33 +04:00
|
|
|
status = scrollbar_mouse_status_to_message(
|
|
|
|
scrollbar_mouse_action(
|
|
|
|
bw->scroll_x, mouse,
|
|
|
|
scr_x, scr_y));
|
2012-08-17 01:21:08 +04:00
|
|
|
pointer = BROWSER_POINTER_DEFAULT;
|
2011-07-06 00:13:28 +04:00
|
|
|
|
2017-03-03 17:30:39 +03:00
|
|
|
if (status != NULL) {
|
2011-07-06 00:13:28 +04:00
|
|
|
browser_window_set_status(bw, status);
|
2017-03-03 17:30:39 +03:00
|
|
|
}
|
2011-07-06 00:13:28 +04:00
|
|
|
|
|
|
|
browser_window_set_pointer(bw, pointer);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-13 17:20:26 +04:00
|
|
|
/* Browser window's vertical scrollbar */
|
2011-07-06 00:13:28 +04:00
|
|
|
if (bw->scroll_y != NULL) {
|
|
|
|
int scr_x, scr_y;
|
|
|
|
browser_window_get_scrollbar_pos(bw, false, &scr_x, &scr_y);
|
|
|
|
scr_x = x - scr_x - scrollbar_get_offset(bw->scroll_x);
|
|
|
|
scr_y = y - scr_y - scrollbar_get_offset(bw->scroll_y);
|
|
|
|
|
2017-03-03 17:30:39 +03:00
|
|
|
if ((bw->drag.type == DRAGGING_SCR_Y) ||
|
|
|
|
(scr_y > 0 &&
|
|
|
|
scr_y < browser_window_get_scrollbar_len(bw, false) &&
|
|
|
|
scr_x > 0 &&
|
|
|
|
scr_x < SCROLLBAR_WIDTH &&
|
|
|
|
bw->drag.type == DRAGGING_NONE)) {
|
2011-08-25 00:44:47 +04:00
|
|
|
/* Start a scrollbar drag, or continue existing drag */
|
2013-03-11 16:57:33 +04:00
|
|
|
status = scrollbar_mouse_status_to_message(
|
|
|
|
scrollbar_mouse_action(
|
|
|
|
bw->scroll_y, mouse,
|
|
|
|
scr_x, scr_y));
|
2012-08-17 01:21:08 +04:00
|
|
|
pointer = BROWSER_POINTER_DEFAULT;
|
2011-07-06 00:13:28 +04:00
|
|
|
|
2017-03-03 17:30:39 +03:00
|
|
|
if (status != NULL) {
|
2011-07-06 00:13:28 +04:00
|
|
|
browser_window_set_status(bw, status);
|
2017-03-03 17:30:39 +03:00
|
|
|
}
|
2011-07-06 00:13:28 +04:00
|
|
|
|
|
|
|
browser_window_set_pointer(bw, pointer);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-03 17:30:39 +03:00
|
|
|
if (bw->drag.type == DRAGGING_FRAME) {
|
2011-09-06 14:24:28 +04:00
|
|
|
browser_window_resize_frame(bw, bw->x + x, bw->y + y);
|
2017-03-03 17:30:39 +03:00
|
|
|
} else if (bw->drag.type == DRAGGING_PAGE_SCROLL) {
|
2005-08-21 14:52:17 +04:00
|
|
|
/* mouse movement since drag started */
|
2017-04-26 22:48:54 +03:00
|
|
|
struct rect rect;
|
|
|
|
|
|
|
|
rect.x0 = bw->drag.start_x - x;
|
|
|
|
rect.y0 = bw->drag.start_y - y;
|
2005-04-15 09:52:25 +04:00
|
|
|
|
2005-08-21 14:52:17 +04:00
|
|
|
/* new scroll offsets */
|
2017-04-26 22:48:54 +03:00
|
|
|
rect.x0 += bw->drag.start_scroll_x;
|
|
|
|
rect.y0 += bw->drag.start_scroll_y;
|
2005-04-15 09:52:25 +04:00
|
|
|
|
2017-04-26 22:48:54 +03:00
|
|
|
bw->drag.start_scroll_x = rect.x1 = rect.x0;
|
|
|
|
bw->drag.start_scroll_y = rect.y1 = rect.y0;
|
2005-04-15 09:52:25 +04:00
|
|
|
|
2017-04-26 22:48:54 +03:00
|
|
|
browser_window_set_scroll(bw, &rect);
|
2009-05-28 18:35:12 +04:00
|
|
|
} else {
|
|
|
|
assert(c != NULL);
|
2010-06-04 13:35:08 +04:00
|
|
|
content_mouse_track(c, bw, mouse, x, y);
|
2005-04-15 09:52:25 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-05-30 19:32:57 +03:00
|
|
|
/* exported interface documented in netsurf/browser_window.h */
|
2010-06-04 13:35:08 +04:00
|
|
|
void browser_window_mouse_click(struct browser_window *bw,
|
2005-04-15 09:52:25 +04:00
|
|
|
browser_mouse_state mouse, int x, int y)
|
|
|
|
{
|
2010-06-04 13:35:08 +04:00
|
|
|
hlcache_handle *c = bw->current_content;
|
2011-07-06 00:13:28 +04:00
|
|
|
const char *status = NULL;
|
2012-08-17 01:21:08 +04:00
|
|
|
browser_pointer_shape pointer = BROWSER_POINTER_DEFAULT;
|
2009-07-21 14:59:53 +04:00
|
|
|
|
2011-09-04 21:24:45 +04:00
|
|
|
if (bw->children) {
|
|
|
|
/* Browser window has children (frames) */
|
|
|
|
struct browser_window *child;
|
|
|
|
int cur_child;
|
|
|
|
int children = bw->rows * bw->cols;
|
|
|
|
|
|
|
|
for (cur_child = 0; cur_child < children; cur_child++) {
|
|
|
|
|
|
|
|
child = &bw->children[cur_child];
|
|
|
|
|
|
|
|
if (x < child->x || y < child->y ||
|
|
|
|
child->x + child->width < x ||
|
|
|
|
child->y + child->height < y) {
|
|
|
|
/* Click not in this child */
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* It's this child that contains the click; pass it
|
|
|
|
* on to child. */
|
|
|
|
browser_window_mouse_click(child, mouse,
|
|
|
|
x - child->x + scrollbar_get_offset(
|
|
|
|
child->scroll_x),
|
|
|
|
y - child->y + scrollbar_get_offset(
|
|
|
|
child->scroll_y));
|
|
|
|
|
|
|
|
/* Mouse action was for this child, we're done */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-06-04 13:35:08 +04:00
|
|
|
if (!c)
|
|
|
|
return;
|
2006-02-16 02:09:55 +03:00
|
|
|
|
2011-07-06 00:13:28 +04:00
|
|
|
if (bw->scroll_x != NULL) {
|
|
|
|
int scr_x, scr_y;
|
|
|
|
browser_window_get_scrollbar_pos(bw, true, &scr_x, &scr_y);
|
2011-08-25 17:34:48 +04:00
|
|
|
scr_x = x - scr_x - scrollbar_get_offset(bw->scroll_x);
|
|
|
|
scr_y = y - scr_y - scrollbar_get_offset(bw->scroll_y);
|
2011-07-06 00:13:28 +04:00
|
|
|
|
|
|
|
if (scr_x > 0 && scr_x < browser_window_get_scrollbar_len(bw,
|
|
|
|
true) &&
|
|
|
|
scr_y > 0 && scr_y < SCROLLBAR_WIDTH) {
|
2013-03-11 16:57:33 +04:00
|
|
|
status = scrollbar_mouse_status_to_message(
|
|
|
|
scrollbar_mouse_action(
|
|
|
|
bw->scroll_x, mouse,
|
|
|
|
scr_x, scr_y));
|
2012-08-17 01:21:08 +04:00
|
|
|
pointer = BROWSER_POINTER_DEFAULT;
|
2011-07-06 00:13:28 +04:00
|
|
|
|
|
|
|
if (status != NULL)
|
|
|
|
browser_window_set_status(bw, status);
|
|
|
|
|
|
|
|
browser_window_set_pointer(bw, pointer);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bw->scroll_y != NULL) {
|
|
|
|
int scr_x, scr_y;
|
|
|
|
browser_window_get_scrollbar_pos(bw, false, &scr_x, &scr_y);
|
2011-08-25 17:34:48 +04:00
|
|
|
scr_x = x - scr_x - scrollbar_get_offset(bw->scroll_x);
|
|
|
|
scr_y = y - scr_y - scrollbar_get_offset(bw->scroll_y);
|
2011-07-06 00:13:28 +04:00
|
|
|
|
|
|
|
if (scr_y > 0 && scr_y < browser_window_get_scrollbar_len(bw,
|
|
|
|
false) &&
|
|
|
|
scr_x > 0 && scr_x < SCROLLBAR_WIDTH) {
|
2013-03-11 16:57:33 +04:00
|
|
|
status = scrollbar_mouse_status_to_message(
|
|
|
|
scrollbar_mouse_action(
|
|
|
|
bw->scroll_y, mouse,
|
|
|
|
scr_x, scr_y));
|
2012-08-17 01:21:08 +04:00
|
|
|
pointer = BROWSER_POINTER_DEFAULT;
|
2011-07-06 00:13:28 +04:00
|
|
|
|
|
|
|
if (status != NULL)
|
|
|
|
browser_window_set_status(bw, status);
|
|
|
|
|
|
|
|
browser_window_set_pointer(bw, pointer);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-04 13:35:08 +04:00
|
|
|
switch (content_get_type(c)) {
|
|
|
|
case CONTENT_HTML:
|
|
|
|
case CONTENT_TEXTPLAIN:
|
2013-02-22 16:19:35 +04:00
|
|
|
{
|
|
|
|
/* Give bw focus */
|
|
|
|
struct browser_window *root_bw = browser_window_get_root(bw);
|
|
|
|
if (bw != root_bw->focus) {
|
|
|
|
browser_window_remove_caret(bw, false);
|
|
|
|
browser_window_set_selection(bw, false, true);
|
|
|
|
root_bw->focus = bw;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Pass mouse action to content */
|
2010-06-04 13:35:08 +04:00
|
|
|
content_mouse_action(c, bw, mouse, x, y);
|
2013-02-22 16:19:35 +04:00
|
|
|
}
|
2005-04-15 09:52:25 +04:00
|
|
|
break;
|
2010-06-04 13:35:08 +04:00
|
|
|
default:
|
|
|
|
if (mouse & BROWSER_MOUSE_MOD_2) {
|
2014-01-14 02:54:19 +04:00
|
|
|
if (mouse & BROWSER_MOUSE_DRAG_2) {
|
|
|
|
guit->window->drag_save_object(bw->window, c,
|
|
|
|
GUI_SAVE_OBJECT_NATIVE);
|
|
|
|
} else if (mouse & BROWSER_MOUSE_DRAG_1) {
|
|
|
|
guit->window->drag_save_object(bw->window, c,
|
|
|
|
GUI_SAVE_OBJECT_ORIG);
|
|
|
|
}
|
|
|
|
} else if (mouse & (BROWSER_MOUSE_DRAG_1 |
|
2010-06-04 13:35:08 +04:00
|
|
|
BROWSER_MOUSE_DRAG_2)) {
|
|
|
|
browser_window_page_drag_start(bw, x, y);
|
2012-08-17 01:21:08 +04:00
|
|
|
browser_window_set_pointer(bw, BROWSER_POINTER_MOVE);
|
2006-02-16 02:09:55 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-04-15 09:52:25 +04:00
|
|
|
|
2016-05-30 19:32:57 +03:00
|
|
|
/* exported interface documented in netsurf/browser_window.h */
|
2005-07-24 11:00:47 +04:00
|
|
|
void browser_window_redraw_rect(struct browser_window *bw, int x, int y,
|
|
|
|
int width, int height)
|
2005-04-15 09:52:25 +04:00
|
|
|
{
|
2010-03-28 16:56:39 +04:00
|
|
|
content_request_redraw(bw->current_content, x, y, width, height);
|
2005-04-15 09:52:25 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-05-30 19:32:57 +03:00
|
|
|
/* exported interface documented in netsurf/browser_window.h */
|
2005-04-15 09:52:25 +04:00
|
|
|
void browser_window_page_drag_start(struct browser_window *bw, int x, int y)
|
|
|
|
{
|
2013-05-04 20:01:00 +04:00
|
|
|
assert(bw != NULL);
|
|
|
|
|
2012-01-11 02:02:19 +04:00
|
|
|
browser_window_set_drag_type(bw, DRAGGING_PAGE_SCROLL, NULL);
|
2005-04-15 09:52:25 +04:00
|
|
|
|
2017-03-03 17:30:39 +03:00
|
|
|
bw->drag.start_x = x;
|
|
|
|
bw->drag.start_y = y;
|
2005-04-15 09:52:25 +04:00
|
|
|
|
2011-09-04 21:24:45 +04:00
|
|
|
if (bw->window != NULL) {
|
|
|
|
/* Front end window */
|
2017-03-03 17:30:39 +03:00
|
|
|
guit->window->get_scroll(bw->window,
|
|
|
|
&bw->drag.start_scroll_x,
|
|
|
|
&bw->drag.start_scroll_y);
|
2005-04-15 09:52:25 +04:00
|
|
|
|
2014-01-13 02:55:26 +04:00
|
|
|
guit->window->scroll_start(bw->window);
|
2011-09-04 21:24:45 +04:00
|
|
|
} else {
|
|
|
|
/* Core managed browser window */
|
2017-03-03 17:30:39 +03:00
|
|
|
bw->drag.start_scroll_x = scrollbar_get_offset(bw->scroll_x);
|
|
|
|
bw->drag.start_scroll_y = scrollbar_get_offset(bw->scroll_y);
|
2011-06-15 00:00:18 +04:00
|
|
|
}
|
2005-04-15 09:52:25 +04:00
|
|
|
}
|
2009-03-24 01:22:30 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
2016-05-30 19:32:57 +03:00
|
|
|
/* exported interface documented in netsurf/browser_window.h */
|
2009-03-24 01:22:30 +03:00
|
|
|
bool browser_window_back_available(struct browser_window *bw)
|
|
|
|
{
|
2014-02-15 22:43:59 +04:00
|
|
|
return (bw && bw->history &&
|
|
|
|
browser_window_history_back_available(bw));
|
2009-03-24 01:22:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-05-30 19:32:57 +03:00
|
|
|
/* exported interface documented in netsurf/browser_window.h */
|
2009-03-24 01:22:30 +03:00
|
|
|
bool browser_window_forward_available(struct browser_window *bw)
|
|
|
|
{
|
2014-02-15 22:43:59 +04:00
|
|
|
return (bw && bw->history &&
|
|
|
|
browser_window_history_forward_available(bw));
|
2009-03-24 01:22:30 +03:00
|
|
|
}
|
|
|
|
|
2016-05-30 19:32:57 +03:00
|
|
|
/* exported interface documented in netsurf/browser_window.h */
|
2009-03-24 01:22:30 +03:00
|
|
|
bool browser_window_reload_available(struct browser_window *bw)
|
|
|
|
{
|
|
|
|
return (bw && bw->current_content && !bw->loading_content);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-05-30 19:32:57 +03:00
|
|
|
/* exported interface documented in netsurf/browser_window.h */
|
2009-03-24 01:22:30 +03:00
|
|
|
bool browser_window_stop_available(struct browser_window *bw)
|
|
|
|
{
|
|
|
|
return (bw && (bw->loading_content ||
|
|
|
|
(bw->current_content &&
|
2014-10-20 00:49:46 +04:00
|
|
|
(content_get_status(bw->current_content) !=
|
2010-03-28 16:56:39 +04:00
|
|
|
CONTENT_STATUS_DONE))));
|
2009-03-24 01:22:30 +03:00
|
|
|
}
|
2014-10-13 05:34:10 +04:00
|
|
|
|
|
|
|
/* exported interface documented in browser.h */
|
|
|
|
nserror browser_set_dpi(int dpi)
|
|
|
|
{
|
|
|
|
nscss_screen_dpi = INTTOFIX(dpi);
|
|
|
|
|
|
|
|
return NSERROR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* exported interface documented in browser.h */
|
|
|
|
int browser_get_dpi(void)
|
|
|
|
{
|
|
|
|
return FIXTOINT(nscss_screen_dpi);
|
|
|
|
}
|