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>
|
2009-08-14 14:37:33 +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
|
|
|
*/
|
|
|
|
|
|
|
|
/** \file
|
|
|
|
* Browser window creation and manipulation (implementation).
|
2002-09-11 18:24:02 +04:00
|
|
|
*/
|
|
|
|
|
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>
|
2010-01-29 14:32:53 +03:00
|
|
|
|
2006-10-01 22:10:55 +04:00
|
|
|
#include "curl/curl.h"
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "utils/config.h"
|
2010-06-04 13:35:08 +04:00
|
|
|
#include "content/content.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"
|
|
|
|
#include "desktop/401login.h"
|
|
|
|
#include "desktop/browser.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"
|
|
|
|
#include "desktop/history_core.h"
|
2010-10-05 23:14:46 +04:00
|
|
|
#include "desktop/hotlist.h"
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "desktop/gui.h"
|
2011-02-21 17:48:55 +03:00
|
|
|
#include "desktop/knockout.h"
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "desktop/options.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"
|
|
|
|
#include "desktop/textinput.h"
|
2011-02-11 01:35:41 +03:00
|
|
|
#include "desktop/plotters.h"
|
|
|
|
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "render/form.h"
|
2010-06-04 13:35:08 +04:00
|
|
|
#include "render/html.h"
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "render/textplain.h"
|
|
|
|
#include "utils/log.h"
|
|
|
|
#include "utils/messages.h"
|
2011-09-28 15:26:30 +04:00
|
|
|
#include "utils/nsurl.h"
|
2011-03-14 01:50:54 +03:00
|
|
|
#include "utils/schedule.h"
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "utils/url.h"
|
|
|
|
#include "utils/utils.h"
|
|
|
|
#include "utils/utf8.h"
|
2002-09-11 18:24:02 +04:00
|
|
|
|
2007-08-07 07:55:18 +04:00
|
|
|
/** one or more windows require a reformat */
|
|
|
|
bool browser_reformat_pending;
|
|
|
|
|
2006-11-26 23:11:20 +03:00
|
|
|
/** maximum frame depth */
|
|
|
|
#define FRAME_DEPTH 8
|
|
|
|
|
2010-03-28 16:56:39 +04:00
|
|
|
static nserror browser_window_callback(hlcache_handle *c,
|
|
|
|
const hlcache_event *event, void *pw);
|
2006-01-25 09:52:38 +03:00
|
|
|
static void browser_window_refresh(void *p);
|
2006-09-02 19:52:41 +04:00
|
|
|
static bool browser_window_check_throbber(struct browser_window *bw);
|
2010-04-06 01:35:38 +04:00
|
|
|
static void browser_window_convert_to_download(struct browser_window *bw,
|
|
|
|
llcache_handle *stream);
|
2004-02-25 18:12:58 +03:00
|
|
|
static void browser_window_start_throbber(struct browser_window *bw);
|
|
|
|
static void browser_window_stop_throbber(struct browser_window *bw);
|
2006-09-02 19:52:41 +04:00
|
|
|
static void browser_window_destroy_children(struct browser_window *bw);
|
|
|
|
static void browser_window_destroy_internal(struct browser_window *bw);
|
2006-11-26 23:11:20 +03:00
|
|
|
static void browser_window_set_scale_internal(struct browser_window *bw,
|
|
|
|
float scale);
|
|
|
|
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);
|
2011-06-27 22:19:47 +04:00
|
|
|
static void browser_window_mouse_drag_end(struct browser_window *bw,
|
|
|
|
browser_mouse_state mouse, int x, int y);
|
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;
|
|
|
|
}
|
|
|
|
|
2011-02-11 01:35:41 +03:00
|
|
|
/* exported interface, documented in browser.h */
|
2011-02-11 22:36:33 +03:00
|
|
|
bool browser_window_redraw(struct browser_window *bw, int x, int y,
|
2011-06-30 19:48:07 +04:00
|
|
|
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;
|
2011-02-11 03:14:22 +03:00
|
|
|
|
2011-02-11 01:35:41 +03:00
|
|
|
if (bw == NULL) {
|
|
|
|
LOG(("NULL browser window"));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-09-04 21:24:45 +04: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 */
|
2011-06-30 19:48:07 +04:00
|
|
|
ctx->plot->clip(clip);
|
|
|
|
return ctx->plot->rectangle(clip->x0, clip->y0,
|
|
|
|
clip->x1, clip->y1,
|
2011-02-11 22:36:33 +03:00
|
|
|
plot_style_fill_white);
|
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) */
|
|
|
|
|
|
|
|
if (bw->window != NULL && ctx->plot->option_knockout) {
|
|
|
|
/* 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
|
|
|
|
2011-06-30 19:48:07 +04:00
|
|
|
new_ctx.plot->clip(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;
|
|
|
|
|
|
|
|
if (bw->window != NULL)
|
|
|
|
/* Root browser window; start with blank fill */
|
|
|
|
plot_ok &= new_ctx.plot->rectangle(clip->x0, clip->y0,
|
|
|
|
clip->x1, clip->y1,
|
|
|
|
plot_style_fill_white);
|
|
|
|
|
|
|
|
/* 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 ||
|
|
|
|
content_clip.y0 >= content_clip.y1)
|
|
|
|
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;
|
|
|
|
* cleanup and return */
|
|
|
|
if (bw->window != NULL && ctx->plot->option_knockout) {
|
|
|
|
/* Root browser window: knockout end */
|
|
|
|
knockout_plot_end();
|
|
|
|
}
|
|
|
|
|
|
|
|
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 */
|
2011-06-30 19:48:07 +04:00
|
|
|
plot_ok &= new_ctx.plot->rectangle(clip->x0, clip->y0,
|
2011-02-21 17:48:55 +03:00
|
|
|
clip->x1, clip->y1, plot_style_fill_white);
|
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;
|
|
|
|
}
|
2011-02-11 01:35:41 +03: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 */
|
|
|
|
new_ctx.plot->clip(clip);
|
|
|
|
|
|
|
|
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);
|
|
|
|
plot_ok &= scrollbar_redraw(bw->scroll_x,
|
|
|
|
x + off_x, y + off_y, clip,
|
|
|
|
bw->scale, &new_ctx);
|
|
|
|
}
|
|
|
|
if (bw->scroll_y != NULL) {
|
|
|
|
browser_window_get_scrollbar_pos(bw, false,
|
|
|
|
&off_x, &off_y);
|
|
|
|
plot_ok &= scrollbar_redraw(bw->scroll_y,
|
|
|
|
x + off_x, y + off_y, clip,
|
|
|
|
bw->scale, &new_ctx);
|
|
|
|
}
|
|
|
|
}
|
2011-02-21 17:48:55 +03:00
|
|
|
|
2011-09-04 21:24:45 +04:00
|
|
|
if (bw->window != NULL && ctx->plot->option_knockout) {
|
|
|
|
/* Root browser window: end knockout */
|
2011-02-21 17:48:55 +03:00
|
|
|
knockout_plot_end();
|
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
|
|
|
}
|
|
|
|
|
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) {
|
|
|
|
LOG(("NULL browser window"));
|
|
|
|
return false;
|
|
|
|
} else if (bw->current_content != NULL) {
|
|
|
|
/* Can't render locked contents */
|
|
|
|
return !content_is_locked(bw->current_content);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-06-15 00:00:18 +04:00
|
|
|
/* exported interface, documented in browser.h */
|
|
|
|
void browser_window_update_extent(struct browser_window *bw)
|
|
|
|
{
|
2011-09-04 21:24:45 +04:00
|
|
|
if (bw->window != NULL)
|
|
|
|
/* Front end window */
|
2011-06-15 00:00:18 +04:00
|
|
|
gui_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
|
|
|
}
|
|
|
|
|
|
|
|
/* exported interface, documented in browser.h */
|
|
|
|
void browser_window_get_position(struct browser_window *bw, bool root,
|
|
|
|
int *pos_x, int *pos_y)
|
|
|
|
{
|
|
|
|
*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_FRAME:
|
|
|
|
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-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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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 {
|
|
|
|
LOG(("Asked to set position of front end window."));
|
|
|
|
assert(0);
|
2011-06-24 13:30:33 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-27 21:29:49 +04:00
|
|
|
/* exported interface, documented in browser.h */
|
|
|
|
void browser_window_set_drag_type(struct browser_window *bw,
|
|
|
|
browser_drag_type type)
|
|
|
|
{
|
2011-08-24 22:22:22 +04:00
|
|
|
struct browser_window *top_bw = browser_window_get_root(bw);
|
|
|
|
|
|
|
|
if (type == DRAGGING_NONE)
|
|
|
|
top_bw->drag_window = NULL;
|
|
|
|
else
|
|
|
|
top_bw->drag_window = bw;
|
|
|
|
|
2011-06-27 21:29:49 +04:00
|
|
|
bw->drag_type = type;
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
while (bw && !bw->window && bw->parent) {
|
|
|
|
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 */
|
|
|
|
bool browser_window_has_selection(struct browser_window *bw)
|
|
|
|
{
|
|
|
|
assert(bw->window);
|
|
|
|
|
2011-07-13 17:20:26 +04:00
|
|
|
if (bw->cur_sel != NULL && selection_defined(bw->cur_sel)) {
|
2011-07-02 20:43:20 +04:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2011-06-29 01:09:57 +04:00
|
|
|
|
2011-07-13 17:20:26 +04:00
|
|
|
/* exported interface, documented in browser.h */
|
|
|
|
void browser_window_set_selection(struct browser_window *bw,
|
|
|
|
struct selection *s)
|
|
|
|
{
|
|
|
|
assert(bw->window);
|
|
|
|
|
|
|
|
if (bw->cur_sel != s && bw->cur_sel != NULL) {
|
|
|
|
/* Clear any existing selection */
|
|
|
|
selection_clear(bw->cur_sel, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Replace current selection pointer */
|
|
|
|
if (s == NULL && bw->current_content != NULL) {
|
|
|
|
bw->cur_sel = content_get_selection(bw->current_content);
|
|
|
|
} else {
|
|
|
|
bw->cur_sel = s;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* exported interface, documented in browser.h */
|
|
|
|
struct selection *browser_window_get_selection(struct browser_window *bw)
|
|
|
|
{
|
|
|
|
assert(bw->window);
|
|
|
|
|
|
|
|
return bw->cur_sel;
|
|
|
|
}
|
|
|
|
|
2011-07-14 14:27:24 +04:00
|
|
|
/* exported interface, documented in browser.h */
|
|
|
|
void browser_window_scroll_visible(struct browser_window *bw,
|
|
|
|
const struct rect *rect)
|
|
|
|
{
|
|
|
|
assert(bw != NULL);
|
2011-07-06 00:13:28 +04:00
|
|
|
|
2011-09-04 21:24:45 +04:00
|
|
|
if (bw->window != NULL) {
|
|
|
|
/* Front end window */
|
2011-07-14 14:27:24 +04:00
|
|
|
gui_window_scroll_visible(bw->window,
|
|
|
|
rect->x0, rect->y0, rect->x1, rect->y1);
|
2011-09-04 21:24:45 +04:00
|
|
|
} else {
|
|
|
|
/* Core managed browser window */
|
2011-07-14 14:27:24 +04:00
|
|
|
if (bw->scroll_x != NULL)
|
|
|
|
scrollbar_set(bw->scroll_x, rect->x0, false);
|
|
|
|
if (bw->scroll_y != NULL)
|
|
|
|
scrollbar_set(bw->scroll_y, rect->y0, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* exported interface, documented in browser.h */
|
|
|
|
void browser_window_set_scroll(struct browser_window *bw, int x, int y)
|
2011-07-06 00:13:28 +04:00
|
|
|
{
|
|
|
|
if (bw->window != NULL) {
|
|
|
|
gui_window_set_scroll(bw->window, x, y);
|
|
|
|
} else {
|
|
|
|
if (bw->scroll_x != NULL)
|
|
|
|
scrollbar_set(bw->scroll_x, x, false);
|
|
|
|
if (bw->scroll_y != NULL)
|
|
|
|
scrollbar_set(bw->scroll_y, y, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-06 22:11:10 +04:00
|
|
|
/**
|
|
|
|
* Internal helper for browser_window_get_contextual_content
|
|
|
|
*/
|
|
|
|
static void browser_window__get_contextual_content(struct browser_window *bw,
|
|
|
|
int x, int y, struct contextual_content *data)
|
|
|
|
{
|
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
|
|
|
|
* 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 */
|
|
|
|
browser_window__get_contextual_content(bwc,
|
|
|
|
(x - bwc->x), (y - bwc->y), data);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Coordinate not contained by any frame */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bw->current_content == NULL)
|
|
|
|
/* No content; nothing to set */
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Pass request to content */
|
|
|
|
content_get_contextual_content(bw->current_content, x, y, data);
|
|
|
|
data->main = bw->current_content;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* exported interface, documented in browser.h */
|
|
|
|
void browser_window_get_contextual_content(struct browser_window *bw,
|
|
|
|
int x, int y, struct contextual_content *data)
|
|
|
|
{
|
|
|
|
data->link_url = NULL;
|
|
|
|
data->object = NULL;
|
|
|
|
data->main = NULL;
|
|
|
|
|
|
|
|
browser_window__get_contextual_content(bw, x, y, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-02-25 18:12:58 +03:00
|
|
|
/**
|
2011-06-15 00:00:18 +04:00
|
|
|
* Create and open a new root browser window with the given page.
|
2004-02-25 18:12:58 +03:00
|
|
|
*
|
2006-09-02 19:52:41 +04:00
|
|
|
* \param url URL to start fetching in the new window (copied)
|
2005-01-03 05:09:20 +03:00
|
|
|
* \param clone The browser window to clone
|
2007-01-27 23:58:20 +03:00
|
|
|
* \param referer The referring uri (copied), or 0 if none
|
2004-02-25 18:12:58 +03:00
|
|
|
*/
|
2002-10-15 14:41:12 +04:00
|
|
|
|
2006-11-26 23:11:20 +03:00
|
|
|
struct browser_window *browser_window_create(const char *url,
|
|
|
|
struct browser_window *clone,
|
2009-04-05 23:17:24 +04:00
|
|
|
const char *referer, bool history_add, bool new_tab)
|
2002-10-15 14:41:12 +04:00
|
|
|
{
|
2004-02-25 18:12:58 +03:00
|
|
|
struct browser_window *bw;
|
2011-06-15 00:00:18 +04:00
|
|
|
struct browser_window *top;
|
2002-09-11 18:24:02 +04:00
|
|
|
|
2009-04-05 23:17:24 +04:00
|
|
|
assert(clone || history_add);
|
2006-04-22 22:24:18 +04:00
|
|
|
|
2006-09-02 19:52:41 +04:00
|
|
|
if ((bw = calloc(1, sizeof *bw)) == NULL) {
|
2004-05-07 23:14:54 +04:00
|
|
|
warn_user("NoMemory", 0);
|
2006-07-05 05:23:25 +04:00
|
|
|
return NULL;
|
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 */
|
|
|
|
browser_window_initialise_common(bw, clone);
|
2006-09-02 19:52:41 +04:00
|
|
|
|
|
|
|
/* window characteristics */
|
|
|
|
bw->browser_window_type = BROWSER_WINDOW_NORMAL;
|
2008-08-24 17:05:53 +04:00
|
|
|
bw->scrolling = SCROLLING_YES;
|
2006-09-02 19:52:41 +04:00
|
|
|
bw->border = true;
|
|
|
|
bw->no_resize = true;
|
2009-07-14 19:53:12 +04:00
|
|
|
bw->last_action = wallclock();
|
2011-06-22 17:52:56 +04:00
|
|
|
bw->focus = bw;
|
2011-06-16 13:07:13 +04:00
|
|
|
|
2006-09-02 19:52:41 +04:00
|
|
|
/* gui window */
|
2011-06-15 00:00:18 +04:00
|
|
|
/* from the front end's pov, it clones the top level browser window,
|
|
|
|
* so find that. */
|
2011-06-29 01:09:57 +04:00
|
|
|
top = browser_window_get_root(clone);
|
2011-06-15 00:00:18 +04:00
|
|
|
|
|
|
|
bw->window = gui_create_browser_window(bw, top, new_tab);
|
|
|
|
|
2010-04-24 19:22:17 +04:00
|
|
|
if (bw->window == NULL) {
|
2006-09-02 19:52:41 +04:00
|
|
|
browser_window_destroy(bw);
|
2006-07-05 05:23:25 +04:00
|
|
|
return NULL;
|
2004-02-25 18:12:58 +03:00
|
|
|
}
|
2010-04-24 19:22:17 +04:00
|
|
|
|
2006-07-05 05:23:25 +04:00
|
|
|
if (url)
|
2009-04-05 23:17:24 +04:00
|
|
|
browser_window_go(bw, url, referer, history_add);
|
2007-01-27 23:58:20 +03:00
|
|
|
|
2009-12-18 02:55:02 +03:00
|
|
|
|
2006-07-05 05:23:25 +04:00
|
|
|
return bw;
|
2002-09-11 18:24:02 +04:00
|
|
|
}
|
|
|
|
|
2004-02-25 18:12:58 +03:00
|
|
|
|
2007-08-07 11:58:04 +04:00
|
|
|
/**
|
|
|
|
* Initialise common parts of a browser window
|
|
|
|
*
|
|
|
|
* \param bw The window to initialise
|
|
|
|
* \param clone The window to clone, or NULL if none
|
|
|
|
*/
|
|
|
|
void browser_window_initialise_common(struct browser_window *bw,
|
|
|
|
struct browser_window *clone)
|
|
|
|
{
|
|
|
|
assert(bw);
|
|
|
|
|
|
|
|
if (!clone)
|
|
|
|
bw->history = history_create();
|
|
|
|
else
|
|
|
|
bw->history = history_clone(clone->history);
|
|
|
|
|
|
|
|
/* window characteristics */
|
2011-07-13 17:20:26 +04:00
|
|
|
bw->cur_sel = NULL;
|
2011-08-24 16:29:30 +04:00
|
|
|
bw->cur_search = NULL;
|
2007-08-07 11:58:04 +04:00
|
|
|
bw->refresh_interval = -1;
|
|
|
|
|
|
|
|
bw->reformat_pending = false;
|
|
|
|
bw->drag_type = DRAGGING_NONE;
|
|
|
|
bw->scale = (float) option_scale / 100.0;
|
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 */
|
2010-02-11 02:37:06 +03:00
|
|
|
bw->status_text = NULL;
|
|
|
|
bw->status_text_len = 0;
|
2010-02-11 13:58:26 +03:00
|
|
|
bw->status_match = 0;
|
|
|
|
bw->status_miss = 0;
|
2007-08-07 11:58:04 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-02-25 18:12:58 +03:00
|
|
|
/**
|
|
|
|
* Start fetching a page in a browser window.
|
|
|
|
*
|
2006-09-02 19:52:41 +04:00
|
|
|
* \param bw browser window
|
|
|
|
* \param url URL to start fetching (copied)
|
2007-01-27 23:58:20 +03:00
|
|
|
* \param referer the referring uri (copied), or 0 if none
|
2004-02-25 18:12:58 +03:00
|
|
|
*
|
|
|
|
* Any existing fetches in the window are aborted.
|
|
|
|
*/
|
|
|
|
|
2004-10-01 04:06:49 +04:00
|
|
|
void browser_window_go(struct browser_window *bw, const char *url,
|
2009-04-05 23:17:24 +04:00
|
|
|
const char *referer, bool history_add)
|
2002-10-15 14:41:12 +04:00
|
|
|
{
|
2007-01-27 23:58:20 +03:00
|
|
|
/* All fetches passing through here are verifiable
|
|
|
|
* (i.e are the result of user action) */
|
2009-04-05 23:17:24 +04:00
|
|
|
browser_window_go_post(bw, url, 0, 0, history_add, referer,
|
2009-07-10 04:26:37 +04:00
|
|
|
false, true, NULL);
|
2002-10-15 14:41:12 +04:00
|
|
|
}
|
|
|
|
|
2004-02-25 18:12:58 +03:00
|
|
|
|
2009-01-30 08:07:07 +03:00
|
|
|
/**
|
|
|
|
* Start a download of the given URL from a browser window.
|
|
|
|
*
|
|
|
|
* \param bw browser window
|
|
|
|
* \param url URL to start downloading (copied)
|
|
|
|
* \param referer the referring uri (copied), or 0 if none
|
|
|
|
*/
|
|
|
|
|
|
|
|
void browser_window_download(struct browser_window *bw, const char *url,
|
2009-07-10 04:26:37 +04:00
|
|
|
const char *referer)
|
2009-01-30 08:07:07 +03:00
|
|
|
{
|
2009-07-10 04:26:37 +04:00
|
|
|
browser_window_go_post(bw, url, 0, 0, false, referer,
|
|
|
|
true, true, NULL);
|
2009-01-30 08:07:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-01-27 23:58:20 +03:00
|
|
|
/**
|
|
|
|
* Start fetching a page in a browser window.
|
|
|
|
*
|
|
|
|
* \param bw browser window
|
|
|
|
* \param url URL to start fetching (copied)
|
|
|
|
* \param referer the referring uri (copied), or 0 if none
|
|
|
|
*
|
|
|
|
* Any existing fetches in the window are aborted.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void browser_window_go_unverifiable(struct browser_window *bw,
|
2009-07-10 04:26:37 +04:00
|
|
|
const char *url, const char *referer, bool history_add,
|
2010-03-28 16:56:39 +04:00
|
|
|
hlcache_handle *parent)
|
2007-01-27 23:58:20 +03:00
|
|
|
{
|
|
|
|
/* All fetches passing through here are unverifiable
|
|
|
|
* (i.e are not the result of user action) */
|
2009-04-05 23:17:24 +04:00
|
|
|
browser_window_go_post(bw, url, 0, 0, history_add, referer,
|
2009-07-10 04:26:37 +04:00
|
|
|
false, false, parent);
|
2007-01-27 23:58:20 +03:00
|
|
|
}
|
|
|
|
|
2004-02-25 18:12:58 +03:00
|
|
|
/**
|
|
|
|
* Start fetching a page in a browser window, POSTing form data.
|
|
|
|
*
|
2006-09-02 19:52:41 +04:00
|
|
|
* \param bw browser window
|
|
|
|
* \param url URL to start fetching (copied)
|
|
|
|
* \param post_urlenc url encoded post data, or 0 if none
|
2004-02-25 18:12:58 +03:00
|
|
|
* \param post_multipart multipart post data, or 0 if none
|
2009-03-17 15:26:41 +03:00
|
|
|
* \param add_to_history add to window history
|
2007-01-27 23:58:20 +03:00
|
|
|
* \param referer the referring uri (copied), or 0 if none
|
2006-09-02 19:52:41 +04:00
|
|
|
* \param download download, rather than render the uri
|
2007-01-27 23:58:20 +03:00
|
|
|
* \param verifiable this transaction is verifiable
|
2009-07-10 04:26:37 +04:00
|
|
|
* \param parent Parent content, or NULL
|
2004-02-25 18:12:58 +03:00
|
|
|
*
|
|
|
|
* Any existing fetches in the window are aborted.
|
|
|
|
*
|
|
|
|
* If post_urlenc and post_multipart are 0 the url is fetched using GET.
|
|
|
|
*
|
2009-03-24 01:22:30 +03:00
|
|
|
* The page is not added to the window history if add_to_history is false.
|
2009-03-17 15:26:41 +03:00
|
|
|
* This should be used when returning to a page in the window history.
|
2004-02-25 18:12:58 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
void browser_window_go_post(struct browser_window *bw, const char *url,
|
|
|
|
char *post_urlenc,
|
2010-03-28 16:56:39 +04:00
|
|
|
struct fetch_multipart_data *post_multipart,
|
2009-03-17 15:26:41 +03:00
|
|
|
bool add_to_history, const char *referer, bool download,
|
2010-03-28 16:56:39 +04:00
|
|
|
bool verifiable, hlcache_handle *parent)
|
2002-10-15 14:41:12 +04:00
|
|
|
{
|
2010-03-28 16:56:39 +04:00
|
|
|
hlcache_handle *c;
|
2006-09-05 21:59:29 +04:00
|
|
|
int depth = 0;
|
|
|
|
struct browser_window *cur;
|
2010-03-28 16:56:39 +04:00
|
|
|
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;
|
2004-06-11 03:55:23 +04:00
|
|
|
|
2011-10-03 19:56:47 +04:00
|
|
|
nsurl *nsref = NULL;
|
|
|
|
nsurl *nsurl;
|
|
|
|
|
2004-06-11 03:55:23 +04:00
|
|
|
LOG(("bw %p, url %s", bw, url));
|
2006-03-25 23:30:35 +03:00
|
|
|
assert(bw);
|
|
|
|
assert(url);
|
2006-09-06 04:15:10 +04:00
|
|
|
|
2006-09-05 21:59:29 +04:00
|
|
|
/* don't allow massively nested framesets */
|
|
|
|
for (cur = bw; cur->parent; cur = cur->parent)
|
|
|
|
depth++;
|
|
|
|
if (depth > FRAME_DEPTH) {
|
2007-01-27 23:58:20 +03:00
|
|
|
LOG(("frame depth too high."));
|
2006-09-05 21:59:29 +04:00
|
|
|
return;
|
|
|
|
}
|
2004-03-10 23:45:27 +03:00
|
|
|
|
2010-03-28 16:56:39 +04:00
|
|
|
/* Set up retrieval parameters */
|
|
|
|
if (verifiable)
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2010-04-17 00:55:17 +04:00
|
|
|
if (parent != NULL && content_get_type(parent) == CONTENT_HTML) {
|
|
|
|
child.charset = html_get_encoding(parent);
|
|
|
|
child.quirks = content_get_quirks(parent);
|
2010-03-28 16:56:39 +04:00
|
|
|
}
|
|
|
|
|
2011-10-03 19:56:47 +04:00
|
|
|
error = nsurl_create(url, &nsurl);
|
|
|
|
if (error != NSERROR_OK) {
|
2004-03-10 23:45:27 +03:00
|
|
|
return;
|
|
|
|
}
|
2004-02-25 18:12:58 +03:00
|
|
|
|
2011-10-03 19:56:47 +04:00
|
|
|
if (referer != NULL) {
|
|
|
|
error = nsurl_create(referer, &nsref);
|
2011-09-28 15:26:30 +04:00
|
|
|
if (error != NSERROR_OK) {
|
2011-10-03 19:56:47 +04:00
|
|
|
nsurl_unref(nsurl);
|
2011-09-28 15:26:30 +04:00
|
|
|
return;
|
|
|
|
}
|
2011-10-03 19:56:47 +04:00
|
|
|
}
|
2011-09-28 15:26:30 +04:00
|
|
|
|
2011-10-03 19:56:47 +04:00
|
|
|
/* Get download out of the way */
|
|
|
|
if (download) {
|
|
|
|
llcache_handle *l;
|
2010-03-28 16:56:39 +04:00
|
|
|
|
2010-04-06 01:35:38 +04:00
|
|
|
fetch_flags |= LLCACHE_RETRIEVE_FORCE_FETCH;
|
|
|
|
fetch_flags |= LLCACHE_RETRIEVE_STREAM_DATA;
|
|
|
|
|
2011-09-28 15:26:30 +04:00
|
|
|
error = llcache_handle_retrieve(nsurl, fetch_flags, nsref,
|
2010-04-06 01:35:38 +04:00
|
|
|
fetch_is_post ? &post : NULL,
|
|
|
|
NULL, NULL, &l);
|
2011-02-22 00:47:55 +03:00
|
|
|
if (error == NSERROR_NO_FETCH_HANDLER) {
|
2011-10-03 19:56:47 +04:00
|
|
|
gui_launch_url(nsurl_access(nsurl));
|
2011-02-22 00:47:55 +03:00
|
|
|
} else if (error != NSERROR_OK) {
|
2010-03-28 16:56:39 +04:00
|
|
|
LOG(("Failed to fetch download: %d", error));
|
2011-02-22 00:47:55 +03:00
|
|
|
} else {
|
|
|
|
error = download_context_create(l, bw->window);
|
|
|
|
if (error != NSERROR_OK) {
|
|
|
|
LOG(("Failed creating download context: %d",
|
|
|
|
error));
|
|
|
|
llcache_handle_abort(l);
|
|
|
|
llcache_handle_release(l);
|
|
|
|
}
|
|
|
|
}
|
2010-03-28 16:56:39 +04:00
|
|
|
|
2011-09-28 15:26:30 +04:00
|
|
|
nsurl_unref(nsurl);
|
|
|
|
if (nsref != NULL)
|
|
|
|
nsurl_unref(nsref);
|
2010-03-28 16:56:39 +04:00
|
|
|
|
2004-11-23 02:29:50 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-02-03 15:04:48 +03:00
|
|
|
free(bw->frag_id);
|
|
|
|
bw->frag_id = NULL;
|
2006-10-01 22:10:55 +04:00
|
|
|
|
2011-10-03 19:56:47 +04:00
|
|
|
if (nsurl_enquire(nsurl, NSURL_FRAGMENT)) {
|
|
|
|
lwc_string *lwc_frag;
|
2008-02-03 15:04:48 +03:00
|
|
|
bool same_url = false;
|
|
|
|
|
2011-10-03 19:56:47 +04:00
|
|
|
lwc_frag = nsurl_get_component(nsurl, NSURL_FRAGMENT);
|
|
|
|
|
|
|
|
bw->frag_id = strdup(lwc_string_data(lwc_frag));
|
|
|
|
|
|
|
|
if (bw->frag_id == NULL) {
|
|
|
|
nsurl_unref(nsurl);
|
|
|
|
if (nsref != NULL)
|
|
|
|
nsurl_unref(nsref);
|
|
|
|
lwc_string_unref(lwc_frag);
|
|
|
|
warn_user("NoMemory", 0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
lwc_string_unref(lwc_frag);
|
2008-02-03 15:04:48 +03:00
|
|
|
|
|
|
|
/* Compare new URL with existing one (ignoring fragments) */
|
2010-03-28 16:56:39 +04:00
|
|
|
if (bw->current_content != NULL &&
|
|
|
|
content_get_url(bw->current_content) != NULL) {
|
2011-10-03 19:56:47 +04:00
|
|
|
same_url = nsurl_compare(nsurl,
|
|
|
|
content_get_url(bw->current_content),
|
|
|
|
NSURL_COMPLETE);
|
2006-10-01 22:10:55 +04:00
|
|
|
}
|
|
|
|
|
2005-03-20 06:35:50 +03:00
|
|
|
/* if we're simply moving to another ID on the same page,
|
2006-02-24 23:43:45 +03:00
|
|
|
* don't bother to fetch, just update the window.
|
2005-03-20 06:35:50 +03:00
|
|
|
*/
|
2010-03-28 16:56:39 +04:00
|
|
|
if (same_url && fetch_is_post == false &&
|
2011-10-03 19:56:47 +04:00
|
|
|
nsurl_enquire(nsurl, NSURL_QUERY) == false) {
|
|
|
|
nsurl_unref(nsurl);
|
|
|
|
if (nsref != NULL)
|
|
|
|
nsurl_unref(nsref);
|
2009-03-17 15:26:41 +03:00
|
|
|
if (add_to_history)
|
|
|
|
history_add(bw->history, bw->current_content,
|
|
|
|
bw->frag_id);
|
2009-04-05 23:17:24 +04:00
|
|
|
browser_window_update(bw, false);
|
2010-03-28 16:56:39 +04:00
|
|
|
if (bw->current_content != NULL) {
|
2009-03-31 15:06:09 +04:00
|
|
|
browser_window_refresh_url_bar(bw,
|
2010-03-28 16:56:39 +04:00
|
|
|
content_get_url(bw->current_content),
|
|
|
|
bw->frag_id);
|
2009-03-30 19:46:26 +04:00
|
|
|
}
|
2005-03-20 06:35:50 +03:00
|
|
|
return;
|
|
|
|
}
|
2004-08-07 02:19:13 +04:00
|
|
|
}
|
|
|
|
|
2005-03-21 02:42:23 +03:00
|
|
|
browser_window_stop(bw);
|
|
|
|
browser_window_remove_caret(bw);
|
2006-09-02 19:52:41 +04:00
|
|
|
browser_window_destroy_children(bw);
|
2005-03-21 02:42:23 +03:00
|
|
|
|
2011-10-03 19:56:47 +04:00
|
|
|
LOG(("Loading '%s'", nsurl_access(nsurl)));
|
2006-09-07 02:15:58 +04:00
|
|
|
|
2004-02-27 20:45:19 +03:00
|
|
|
browser_window_set_status(bw, messages_get("Loading"));
|
2009-04-05 23:17:24 +04:00
|
|
|
bw->history_add = add_to_history;
|
2010-03-28 16:56:39 +04:00
|
|
|
|
2011-10-10 12:56:34 +04:00
|
|
|
/* Only permit requests for root contents to become downloads */
|
|
|
|
if (bw->window != NULL)
|
|
|
|
fetch_flags |= HLCACHE_RETRIEVE_MAY_DOWNLOAD;
|
|
|
|
|
2011-10-03 19:56:47 +04:00
|
|
|
error = hlcache_handle_retrieve(nsurl,
|
2011-10-10 12:56:34 +04:00
|
|
|
fetch_flags | HLCACHE_RETRIEVE_SNIFF_TYPE,
|
2011-10-03 19:56:47 +04:00
|
|
|
nsref,
|
2010-03-30 02:33:21 +04:00
|
|
|
fetch_is_post ? &post : NULL,
|
2010-03-28 16:56:39 +04:00
|
|
|
browser_window_callback, bw,
|
2010-04-04 21:17:24 +04:00
|
|
|
parent != NULL ? &child : NULL,
|
2011-05-07 00:40:09 +04:00
|
|
|
CONTENT_ANY, &c);
|
2010-03-28 16:56:39 +04:00
|
|
|
if (error == NSERROR_NO_FETCH_HANDLER) {
|
2011-10-03 19:56:47 +04:00
|
|
|
gui_launch_url(nsurl_access(nsurl));
|
|
|
|
nsurl_unref(nsurl);
|
|
|
|
if (nsref != NULL)
|
|
|
|
nsurl_unref(nsref);
|
2010-03-28 16:56:39 +04:00
|
|
|
return;
|
|
|
|
} else if (error != NSERROR_OK) {
|
2011-10-03 19:56:47 +04:00
|
|
|
nsurl_unref(nsurl);
|
|
|
|
if (nsref != NULL)
|
|
|
|
nsurl_unref(nsref);
|
2004-06-11 03:55:23 +04:00
|
|
|
browser_window_set_status(bw, messages_get("NoMemory"));
|
|
|
|
warn_user("NoMemory", 0);
|
2004-02-25 18:12:58 +03:00
|
|
|
return;
|
|
|
|
}
|
2004-08-07 02:19:13 +04:00
|
|
|
|
2004-02-25 18:12:58 +03:00
|
|
|
bw->loading_content = c;
|
|
|
|
browser_window_start_throbber(bw);
|
2011-10-03 19:56:47 +04:00
|
|
|
browser_window_refresh_url_bar(bw, nsurl, NULL);
|
|
|
|
|
|
|
|
nsurl_unref(nsurl);
|
|
|
|
if (nsref != NULL)
|
|
|
|
nsurl_unref(nsref);
|
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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static nserror browser_window_favicon_callback(hlcache_handle *c,
|
|
|
|
const hlcache_event *event, void *pw)
|
|
|
|
{
|
|
|
|
struct browser_window *bw = pw;
|
|
|
|
|
|
|
|
switch (event->type) {
|
|
|
|
case CONTENT_MSG_DONE:
|
2011-10-07 22:12:47 +04:00
|
|
|
if (bw->current_favicon != NULL) {
|
|
|
|
content_status status =
|
|
|
|
content_get_status(bw->current_favicon);
|
|
|
|
|
|
|
|
if ((status == CONTENT_STATUS_READY) ||
|
2011-10-08 14:22:34 +04:00
|
|
|
(status == CONTENT_STATUS_DONE))
|
2011-10-07 22:12:47 +04:00
|
|
|
content_close(bw->current_favicon);
|
|
|
|
|
|
|
|
hlcache_handle_release(bw->current_favicon);
|
|
|
|
}
|
|
|
|
|
|
|
|
bw->current_favicon = c;
|
|
|
|
bw->loading_favicon = NULL;
|
|
|
|
|
|
|
|
/* content_get_bitmap on the hlcache_handle should give
|
|
|
|
* us the favicon bitmap at this point
|
|
|
|
*/
|
2011-10-08 14:22:34 +04:00
|
|
|
gui_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:
|
|
|
|
|
|
|
|
/* clean up after ourselves */
|
|
|
|
if (c == bw->loading_favicon)
|
|
|
|
bw->loading_favicon = NULL;
|
|
|
|
else if (c == bw->current_favicon) {
|
|
|
|
bw->current_favicon = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
hlcache_handle_release(c);
|
|
|
|
|
2011-10-08 02:22:15 +04:00
|
|
|
if (bw->failed_favicon == false) {
|
|
|
|
nsurl *nsref = NULL;
|
|
|
|
nsurl *nsurl;
|
|
|
|
nserror error;
|
|
|
|
|
|
|
|
bw->failed_favicon = true;
|
|
|
|
|
|
|
|
error = nsurl_create("resource:favicon.ico", &nsurl);
|
|
|
|
if (error != NSERROR_OK) {
|
|
|
|
LOG(("Unable to create default location url"));
|
|
|
|
} else {
|
|
|
|
|
|
|
|
hlcache_handle_retrieve(nsurl,
|
|
|
|
HLCACHE_RETRIEVE_SNIFF_TYPE,
|
2011-10-08 14:22:34 +04:00
|
|
|
nsref, NULL,
|
|
|
|
browser_window_favicon_callback,
|
|
|
|
bw, NULL, CONTENT_IMAGE,
|
2011-10-08 02:22:15 +04:00
|
|
|
&bw->loading_favicon);
|
|
|
|
|
|
|
|
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
|
|
|
|
2011-10-07 22:12:47 +04:00
|
|
|
static void browser_window_update_favicon(hlcache_handle *c,
|
2011-10-08 14:22:34 +04:00
|
|
|
struct browser_window *bw, struct content_rfc5988_link *link)
|
2011-10-07 22:12:47 +04:00
|
|
|
{
|
|
|
|
lwc_string *icon_str;
|
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;
|
2011-10-07 22:49:16 +04:00
|
|
|
|
2011-10-07 22:12:47 +04:00
|
|
|
/* already fetching the favicon - use that */
|
|
|
|
if (bw->loading_favicon != NULL)
|
|
|
|
return;
|
|
|
|
|
2011-10-08 02:22:15 +04:00
|
|
|
bw->failed_favicon = false;
|
|
|
|
|
2011-10-07 22:49:16 +04:00
|
|
|
if (link == NULL) {
|
|
|
|
/* look for favicon metadata link */
|
2011-10-08 04:06:43 +04:00
|
|
|
if (lwc_intern_string("icon", SLEN("icon"),
|
|
|
|
&icon_str) == lwc_error_ok) {
|
|
|
|
link = content_find_rfc5988_link(c, icon_str);
|
|
|
|
lwc_string_unref(icon_str);
|
|
|
|
}
|
2011-10-07 22:49:16 +04:00
|
|
|
}
|
2011-10-07 22:12:47 +04:00
|
|
|
|
|
|
|
if (link == NULL) {
|
2011-10-08 04:06:43 +04:00
|
|
|
if (lwc_intern_string("shortcut icon", SLEN("shortcut icon"),
|
|
|
|
&icon_str) == lwc_error_ok) {
|
2011-10-08 14:22:34 +04:00
|
|
|
link = content_find_rfc5988_link(c, icon_str);
|
2011-10-08 04:06:43 +04:00
|
|
|
lwc_string_unref(icon_str);
|
|
|
|
}
|
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;
|
2011-10-08 00:47:34 +04:00
|
|
|
|
|
|
|
nsurl = content_get_url(c);
|
|
|
|
|
|
|
|
scheme = nsurl_get_component(nsurl, NSURL_SCHEME);
|
|
|
|
|
2011-10-08 04:06:43 +04:00
|
|
|
/* If the document was fetched over http(s), then speculate
|
|
|
|
* that there's a favicon living at /favicon.ico */
|
|
|
|
if ((lwc_string_length(scheme) == SLEN("HTTP") &&
|
|
|
|
strcasecmp(lwc_string_data(scheme),
|
|
|
|
"http") == 0) ||
|
|
|
|
(lwc_string_length(scheme) == SLEN("HTTPS") &&
|
|
|
|
strcasecmp(lwc_string_data(scheme),
|
|
|
|
"https") == 0)) {
|
|
|
|
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 {
|
2011-10-08 02:22:15 +04:00
|
|
|
bw->failed_favicon = 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) {
|
|
|
|
LOG(("Unable to create default location url"));
|
|
|
|
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) {
|
|
|
|
LOG(("fetching general favicon from '%s'",
|
|
|
|
nsurl_access(nsurl)));
|
|
|
|
} else {
|
2011-10-08 14:22:34 +04:00
|
|
|
LOG(("fetching favicon rel:%s '%s'",
|
|
|
|
lwc_string_data(link->rel),
|
|
|
|
nsurl_access(nsurl)));
|
2011-10-07 22:49:16 +04:00
|
|
|
}
|
|
|
|
|
2011-10-08 14:22:34 +04:00
|
|
|
hlcache_handle_retrieve(nsurl, HLCACHE_RETRIEVE_SNIFF_TYPE,
|
|
|
|
nsref, NULL, browser_window_favicon_callback,
|
|
|
|
bw, NULL, CONTENT_IMAGE, &bw->loading_favicon);
|
2011-10-07 22:12:47 +04:00
|
|
|
|
|
|
|
nsurl_unref(nsurl);
|
|
|
|
}
|
|
|
|
|
2004-02-25 18:12:58 +03:00
|
|
|
/**
|
|
|
|
* Callback for fetchcache() for browser window fetches.
|
|
|
|
*/
|
|
|
|
|
2010-03-28 16:56:39 +04:00
|
|
|
nserror browser_window_callback(hlcache_handle *c,
|
|
|
|
const hlcache_event *event, void *pw)
|
2002-09-11 18:24:02 +04:00
|
|
|
{
|
2010-03-28 16:56:39 +04:00
|
|
|
struct browser_window *bw = pw;
|
2002-09-11 18:24:02 +04:00
|
|
|
|
2010-03-28 16:56:39 +04:00
|
|
|
switch (event->type) {
|
2010-04-06 01:35:38 +04:00
|
|
|
case CONTENT_MSG_DOWNLOAD:
|
|
|
|
assert(bw->loading_content == c);
|
|
|
|
|
|
|
|
browser_window_convert_to_download(bw, event->data.download);
|
|
|
|
|
2010-04-12 14:57:41 +04:00
|
|
|
if (bw->current_content != NULL) {
|
2011-10-08 14:22:34 +04:00
|
|
|
browser_window_refresh_url_bar(bw,
|
|
|
|
content_get_url(bw->current_content),
|
2010-04-12 14:57:41 +04:00
|
|
|
bw->frag_id);
|
|
|
|
}
|
2010-04-06 01:35:38 +04:00
|
|
|
break;
|
|
|
|
|
2006-11-26 23:11:20 +03:00
|
|
|
case CONTENT_MSG_LOADING:
|
|
|
|
assert(bw->loading_content == c);
|
2004-06-28 03:24:11 +04:00
|
|
|
|
2005-01-14 01:42:39 +03:00
|
|
|
#ifdef WITH_THEME_INSTALL
|
2010-04-06 01:35:38 +04:00
|
|
|
if (content_get_type(c) == CONTENT_THEME) {
|
2006-11-26 23:11:20 +03:00
|
|
|
theme_install_start(c);
|
2010-03-28 16:56:39 +04:00
|
|
|
bw->loading_content = NULL;
|
2006-11-26 23:11:20 +03:00
|
|
|
browser_window_stop_throbber(bw);
|
2010-04-06 01:35:38 +04:00
|
|
|
} else
|
2005-01-14 01:42:39 +03:00
|
|
|
#endif
|
2010-04-06 01:35:38 +04:00
|
|
|
{
|
2006-11-26 23:11:20 +03:00
|
|
|
bw->refresh_interval = -1;
|
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
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CONTENT_MSG_READY:
|
2010-03-30 02:33:21 +04:00
|
|
|
{
|
|
|
|
int width, height;
|
|
|
|
|
2006-11-26 23:11:20 +03:00
|
|
|
assert(bw->loading_content == c);
|
|
|
|
|
2010-03-28 16:56:39 +04:00
|
|
|
if (bw->current_content != NULL) {
|
|
|
|
content_status status =
|
|
|
|
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
|
|
|
|
2006-11-26 23:11:20 +03:00
|
|
|
browser_window_remove_caret(bw);
|
2010-03-28 16:56:39 +04:00
|
|
|
|
2011-06-15 00:48:58 +04:00
|
|
|
if (bw->window)
|
|
|
|
gui_window_new_content(bw->window);
|
2010-03-28 16:56:39 +04:00
|
|
|
|
|
|
|
browser_window_refresh_url_bar(bw,
|
|
|
|
content_get_url(bw->current_content),
|
|
|
|
bw->frag_id);
|
|
|
|
|
2009-04-08 15:07:30 +04:00
|
|
|
/* new content; set scroll_to_top */
|
|
|
|
browser_window_update(bw, true);
|
2011-03-11 02:13:03 +03:00
|
|
|
content_open(c, bw, 0, 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) {
|
2011-10-03 19:56:47 +04:00
|
|
|
const char *url = nsurl_access(content_get_url(c));
|
2010-03-28 16:56:39 +04:00
|
|
|
|
2006-11-26 23:11:20 +03:00
|
|
|
history_add(bw->history, c, bw->frag_id);
|
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);
|
|
|
|
urldb_set_url_content_type(url,
|
|
|
|
content_get_type(c));
|
|
|
|
/* This is safe as we've just added the URL */
|
|
|
|
global_history_add(urldb_get_url(url));
|
2006-02-16 02:09:55 +03:00
|
|
|
}
|
2006-11-26 23:11:20 +03:00
|
|
|
}
|
2011-07-13 17:20:26 +04:00
|
|
|
|
|
|
|
if (bw->window != NULL) {
|
|
|
|
browser_window_set_selection(bw,
|
|
|
|
content_get_selection(c));
|
|
|
|
}
|
2004-02-25 18:12:58 +03:00
|
|
|
|
2006-11-26 23:11:20 +03:00
|
|
|
/* frames */
|
2010-03-28 16:56:39 +04:00
|
|
|
if (content_get_type(c) == CONTENT_HTML &&
|
|
|
|
html_get_frameset(c) != NULL)
|
|
|
|
browser_window_create_frameset(bw,
|
|
|
|
html_get_frameset(c));
|
|
|
|
if (content_get_type(c) == CONTENT_HTML &&
|
|
|
|
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
|
|
|
|
2006-11-26 23:11:20 +03:00
|
|
|
history_update(bw->history, c);
|
|
|
|
hotlist_visited(c);
|
2010-03-28 16:56:39 +04:00
|
|
|
|
2006-11-26 23:11:20 +03:00
|
|
|
if (bw->refresh_interval != -1)
|
|
|
|
schedule(bw->refresh_interval,
|
2006-11-27 00:04:42 +03:00
|
|
|
browser_window_refresh, bw);
|
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_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 */
|
|
|
|
if (bw->browser_window_type == BROWSER_WINDOW_NORMAL)
|
2010-03-28 16:56:39 +04:00
|
|
|
warn_user(event->data.error, 0);
|
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;
|
2006-11-26 23:11:20 +03:00
|
|
|
browser_window_remove_caret(bw);
|
|
|
|
}
|
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
|
|
|
|
2006-11-26 23:11:20 +03:00
|
|
|
case CONTENT_MSG_STATUS:
|
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
|
|
|
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
|
|
|
|
2006-11-26 23:11:20 +03:00
|
|
|
if (bw->move_callback)
|
2011-07-07 21:50:04 +04:00
|
|
|
bw->move_callback(bw, bw->caret_p1, bw->caret_p2);
|
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
|
|
|
|
|
|
|
if (bw->browser_window_type == BROWSER_WINDOW_FRAME) {
|
|
|
|
rect.x0 -= scrollbar_get_offset(bw->scroll_x);
|
|
|
|
rect.y0 -= scrollbar_get_offset(bw->scroll_y);
|
|
|
|
rect.x1 -= scrollbar_get_offset(bw->scroll_x);
|
|
|
|
rect.y1 -= scrollbar_get_offset(bw->scroll_y);
|
|
|
|
}
|
|
|
|
|
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;
|
2011-01-07 16:10:20 +03:00
|
|
|
|
2011-10-07 03:31:55 +04:00
|
|
|
case CONTENT_MSG_LINK: /* content has an rfc5988 link element */
|
|
|
|
{
|
2011-10-07 22:12:47 +04:00
|
|
|
lwc_string *icon_str;
|
|
|
|
lwc_string *shortcut_icon_str;
|
2011-10-08 04:06:43 +04:00
|
|
|
bool icon_match = false;
|
|
|
|
bool shortcut_icon_match = false;
|
|
|
|
|
|
|
|
if (lwc_intern_string("icon", SLEN("icon"),
|
|
|
|
&icon_str) == lwc_error_ok) {
|
|
|
|
lwc_string_caseless_isequal(
|
|
|
|
event->data.rfc5988_link->rel,
|
|
|
|
icon_str, &icon_match);
|
|
|
|
lwc_string_unref(icon_str);
|
|
|
|
}
|
2011-10-07 22:12:47 +04:00
|
|
|
|
2011-10-08 04:06:43 +04:00
|
|
|
if (lwc_intern_string("shortcut icon", SLEN("shortcut icon"),
|
|
|
|
&shortcut_icon_str) == lwc_error_ok) {
|
|
|
|
lwc_string_caseless_isequal(
|
|
|
|
event->data.rfc5988_link->rel,
|
|
|
|
shortcut_icon_str,
|
|
|
|
&shortcut_icon_match);
|
|
|
|
lwc_string_unref(shortcut_icon_str);
|
|
|
|
}
|
2011-10-07 22:12:47 +04:00
|
|
|
|
2011-10-07 22:49:16 +04:00
|
|
|
if (icon_match || shortcut_icon_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
|
|
|
|
2006-11-26 23:11:20 +03:00
|
|
|
default:
|
|
|
|
assert(0);
|
2004-02-25 18:12:58 +03:00
|
|
|
}
|
2010-03-28 16:56:39 +04:00
|
|
|
|
|
|
|
return NSERROR_OK;
|
2002-09-11 18:24:02 +04:00
|
|
|
}
|
|
|
|
|
2004-02-25 18:12:58 +03:00
|
|
|
|
2011-06-15 00:00:18 +04:00
|
|
|
/*
|
|
|
|
* Get the dimensions of the area a browser window occupies
|
|
|
|
*
|
|
|
|
* \param bw The browser window to get dimensions of
|
|
|
|
* \param width Updated to the browser window viewport width
|
|
|
|
* \param height Updated to the browser window viewport height
|
|
|
|
* \param scaled Whether we want the height with scale applied
|
|
|
|
*/
|
|
|
|
|
|
|
|
void browser_window_get_dimensions(struct browser_window *bw,
|
|
|
|
int *width, int *height, bool scaled)
|
|
|
|
{
|
2011-06-24 13:30:33 +04:00
|
|
|
assert(bw);
|
2011-06-15 00:00:18 +04:00
|
|
|
|
2011-09-04 21:24:45 +04:00
|
|
|
if (bw->window == NULL) {
|
|
|
|
/* Core managed browser window */
|
2011-06-24 13:30:33 +04:00
|
|
|
*width = bw->width;
|
|
|
|
*height = bw->height;
|
2011-09-04 21:24:45 +04:00
|
|
|
} else {
|
|
|
|
/* Front end window */
|
2011-06-15 00:00:18 +04:00
|
|
|
gui_window_get_dimensions(bw->window, width, height, scaled);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-06-24 13:30:33 +04:00
|
|
|
/*
|
|
|
|
* Set the dimensions of the area a browser window occupies
|
|
|
|
*
|
|
|
|
* \param bw The browser window to set dimensions of
|
|
|
|
* \param width Width in pixels
|
|
|
|
* \param height Height in pixels
|
|
|
|
*/
|
|
|
|
|
|
|
|
void browser_window_set_dimensions(struct browser_window *bw,
|
|
|
|
int width, int height)
|
|
|
|
{
|
|
|
|
assert(bw);
|
|
|
|
|
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->width = width;
|
|
|
|
bw->height = height;
|
2011-09-04 21:24:45 +04:00
|
|
|
} else {
|
|
|
|
LOG(("Asked to set dimensions of front end window."));
|
|
|
|
assert(0);
|
2011-06-24 13:30:33 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-02-25 18:12:58 +03:00
|
|
|
/**
|
|
|
|
* Transfer the loading_content to a new download window.
|
|
|
|
*/
|
|
|
|
|
2010-04-06 01:35:38 +04:00
|
|
|
void browser_window_convert_to_download(struct browser_window *bw,
|
|
|
|
llcache_handle *stream)
|
2002-09-11 18:24:02 +04:00
|
|
|
{
|
2010-04-06 01:35:38 +04:00
|
|
|
nserror error;
|
2004-06-28 03:24:11 +04:00
|
|
|
|
2010-04-06 01:35:38 +04:00
|
|
|
error = download_context_create(stream, bw->window);
|
|
|
|
if (error != NSERROR_OK) {
|
|
|
|
llcache_handle_abort(stream);
|
|
|
|
llcache_handle_release(stream);
|
2004-02-25 18:12:58 +03:00
|
|
|
|
2010-04-06 01:35:38 +04:00
|
|
|
return;
|
|
|
|
}
|
2004-02-25 18:12:58 +03:00
|
|
|
|
|
|
|
/* remove content from browser window */
|
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
|
|
|
browser_window_stop_throbber(bw);
|
2002-09-11 18:24:02 +04:00
|
|
|
}
|
|
|
|
|
2004-02-25 18:12:58 +03:00
|
|
|
|
2006-11-27 00:04:42 +03:00
|
|
|
/**
|
|
|
|
* Handle meta http-equiv refresh time elapsing by loading a new page.
|
|
|
|
*
|
|
|
|
* \param p browser window to refresh with new page
|
|
|
|
*/
|
|
|
|
|
|
|
|
void browser_window_refresh(void *p)
|
|
|
|
{
|
|
|
|
struct browser_window *bw = p;
|
2009-04-05 23:17:24 +04:00
|
|
|
bool history_add = true;
|
2010-03-28 16:56:39 +04:00
|
|
|
const char *url;
|
|
|
|
const char *refresh;
|
2006-11-27 00:04:42 +03:00
|
|
|
|
2010-03-28 16:56:39 +04:00
|
|
|
assert(bw->current_content != NULL &&
|
|
|
|
(content_get_status(bw->current_content) ==
|
|
|
|
CONTENT_STATUS_READY ||
|
|
|
|
content_get_status(bw->current_content) ==
|
|
|
|
CONTENT_STATUS_DONE));
|
2008-02-27 21:38:41 +03:00
|
|
|
|
2008-04-07 13:00:21 +04:00
|
|
|
/* Ignore if the refresh URL has gone
|
2008-02-27 21:38:41 +03:00
|
|
|
* (may happen if a fetch error occurred) */
|
2011-10-03 19:56:47 +04:00
|
|
|
refresh = nsurl_access(content_get_refresh_url(bw->current_content));
|
2010-03-28 16:56:39 +04:00
|
|
|
if (refresh == NULL)
|
2008-02-27 21:38:41 +03:00
|
|
|
return;
|
2006-11-27 00:04:42 +03:00
|
|
|
|
|
|
|
/* mark this content as invalid so it gets flushed from the cache */
|
2010-03-28 16:56:39 +04:00
|
|
|
content_invalidate_reuse_data(bw->current_content);
|
2006-11-27 00:04:42 +03:00
|
|
|
|
2011-10-03 19:56:47 +04:00
|
|
|
url = nsurl_access(content_get_url(bw->current_content));
|
2010-03-28 16:56:39 +04:00
|
|
|
if (url != NULL && strcmp(url, refresh) == 0)
|
2009-04-05 23:17:24 +04:00
|
|
|
history_add = false;
|
2006-11-27 00:04:42 +03:00
|
|
|
|
2009-03-10 12:10:43 +03:00
|
|
|
/* Treat an (almost) immediate refresh in a top-level browser window as
|
2009-03-24 01:22:30 +03:00
|
|
|
* if it were an HTTP redirect, and thus make the resulting fetch
|
2009-03-10 12:10:43 +03:00
|
|
|
* verifiable.
|
|
|
|
*
|
|
|
|
* See fetchcache.c for why redirected fetches should be verifiable at
|
|
|
|
* all.
|
|
|
|
*/
|
2009-03-10 12:14:25 +03:00
|
|
|
if (bw->refresh_interval <= 100 && bw->parent == NULL) {
|
2010-03-28 16:56:39 +04:00
|
|
|
browser_window_go(bw, refresh, url, history_add);
|
2009-03-10 12:10:43 +03:00
|
|
|
} else {
|
2010-03-28 16:56:39 +04:00
|
|
|
browser_window_go_unverifiable(bw, refresh, url, history_add,
|
2009-07-10 04:26:37 +04:00
|
|
|
bw->current_content);
|
2009-03-10 12:10:43 +03:00
|
|
|
}
|
2006-11-27 00:04:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-02-25 18:12:58 +03:00
|
|
|
/**
|
|
|
|
* Start the busy indicator.
|
|
|
|
*
|
|
|
|
* \param bw browser window
|
|
|
|
*/
|
|
|
|
|
|
|
|
void browser_window_start_throbber(struct browser_window *bw)
|
2002-09-11 18:24:02 +04:00
|
|
|
{
|
2004-02-25 18:12:58 +03:00
|
|
|
bw->throbbing = true;
|
2006-09-02 19:52:41 +04:00
|
|
|
|
|
|
|
while (bw->parent)
|
|
|
|
bw = bw->parent;
|
2010-03-28 16:56:39 +04:00
|
|
|
|
2004-02-25 18:12:58 +03:00
|
|
|
gui_window_start_throbber(bw->window);
|
|
|
|
}
|
2003-12-22 01:10:15 +03:00
|
|
|
|
2002-09-11 18:24:02 +04:00
|
|
|
|
2004-02-25 18:12:58 +03:00
|
|
|
/**
|
|
|
|
* Stop the busy indicator.
|
|
|
|
*
|
|
|
|
* \param bw browser window
|
|
|
|
*/
|
2002-09-11 18:24:02 +04:00
|
|
|
|
2004-02-25 18:12:58 +03:00
|
|
|
void browser_window_stop_throbber(struct browser_window *bw)
|
|
|
|
{
|
|
|
|
bw->throbbing = false;
|
2006-09-06 04:15:10 +04:00
|
|
|
|
2006-09-02 19:52:41 +04:00
|
|
|
while (bw->parent)
|
|
|
|
bw = bw->parent;
|
2006-09-06 04:15:10 +04:00
|
|
|
|
2006-09-02 19:52:41 +04:00
|
|
|
if (!browser_window_check_throbber(bw))
|
|
|
|
gui_window_stop_throbber(bw->window);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool browser_window_check_throbber(struct browser_window *bw)
|
|
|
|
{
|
|
|
|
int children, index;
|
2006-09-06 04:15:10 +04:00
|
|
|
|
2006-09-02 19:52:41 +04:00
|
|
|
if (bw->throbbing)
|
|
|
|
return true;
|
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++) {
|
|
|
|
if (browser_window_check_throbber(&bw->children[index]))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (bw->iframes) {
|
|
|
|
for (index = 0; index < bw->iframe_count; index++) {
|
|
|
|
if (browser_window_check_throbber(&bw->iframes[index]))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2004-02-25 18:12:58 +03:00
|
|
|
}
|
2004-01-05 05:10:59 +03:00
|
|
|
|
2004-02-25 18:12:58 +03:00
|
|
|
/**
|
|
|
|
* Redraw browser window, set extent to content, and update title.
|
|
|
|
*
|
2006-09-02 19:52:41 +04:00
|
|
|
* \param bw browser_window
|
2004-02-25 18:12:58 +03:00
|
|
|
* \param scroll_to_top move view to top of page
|
|
|
|
*/
|
2004-01-05 05:10:59 +03:00
|
|
|
|
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
|
|
|
{
|
2009-04-05 23:17:24 +04:00
|
|
|
int x, y;
|
2004-07-06 00:19:52 +04:00
|
|
|
|
2010-03-28 16:56:39 +04:00
|
|
|
if (bw->current_content == NULL)
|
2004-02-25 18:12:58 +03:00
|
|
|
return;
|
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 */
|
|
|
|
gui_window_set_title(bw->window,
|
|
|
|
content_get_title(bw->current_content));
|
|
|
|
|
|
|
|
browser_window_update_extent(bw);
|
|
|
|
|
|
|
|
if (scroll_to_top)
|
2011-07-06 00:13:28 +04:00
|
|
|
browser_window_set_scroll(bw, 0, 0);
|
2011-06-15 00:00:18 +04:00
|
|
|
|
|
|
|
/* if frag_id exists, then try to scroll to it */
|
|
|
|
/** \TODO don't do this if the user has scrolled */
|
|
|
|
if (bw->frag_id && html_get_id_offset(bw->current_content,
|
|
|
|
bw->frag_id, &x, &y)) {
|
2011-07-06 00:13:28 +04:00
|
|
|
browser_window_set_scroll(bw, x, y);
|
2011-06-15 00:00:18 +04:00
|
|
|
}
|
2004-01-05 05:10:59 +03:00
|
|
|
|
2011-06-15 00:00:18 +04:00
|
|
|
gui_window_redraw_window(bw->window);
|
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 */
|
|
|
|
|
2011-07-06 00:13:28 +04:00
|
|
|
browser_window_update_extent(bw);
|
|
|
|
|
|
|
|
if (scroll_to_top)
|
|
|
|
browser_window_set_scroll(bw, 0, 0);
|
|
|
|
|
|
|
|
/* if frag_id exists, then try to scroll to it */
|
|
|
|
/** \TODO don't do this if the user has scrolled */
|
|
|
|
if (bw->frag_id && html_get_id_offset(bw->current_content,
|
|
|
|
bw->frag_id, &x, &y)) {
|
|
|
|
browser_window_set_scroll(bw, x, y);
|
|
|
|
}
|
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);
|
|
|
|
|
|
|
|
if (scroll_to_top)
|
|
|
|
browser_window_set_scroll(bw, 0, 0);
|
|
|
|
|
|
|
|
/* if frag_id exists, then try to scroll to it */
|
|
|
|
/** \TODO don't do this if the user has scrolled */
|
|
|
|
if (bw->frag_id && html_get_id_offset(bw->current_content,
|
|
|
|
bw->frag_id, &x, &y)) {
|
|
|
|
browser_window_set_scroll(bw, x, y);
|
|
|
|
}
|
|
|
|
|
|
|
|
rect.x0 = 0;
|
|
|
|
rect.y0 = 0;
|
|
|
|
rect.x1 = bw->width;
|
|
|
|
rect.y1 = bw->height;
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
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 */
|
|
|
|
gui_window_update_box(bw->window, rect);
|
|
|
|
} 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
|
|
|
|
2011-07-06 19:34:49 +04:00
|
|
|
gui_window_update_box(top->window, rect);
|
2011-06-15 00:00:18 +04:00
|
|
|
}
|
2002-09-11 18:24:02 +04:00
|
|
|
}
|
|
|
|
|
2002-12-23 23:06:21 +03:00
|
|
|
|
2004-02-25 18:12:58 +03:00
|
|
|
/**
|
|
|
|
* Stop all fetching activity in a browser window.
|
|
|
|
*
|
|
|
|
* \param bw browser window
|
|
|
|
*/
|
2002-09-11 18:24:02 +04:00
|
|
|
|
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;
|
2010-03-28 16:56:39 +04:00
|
|
|
assert(content_get_status(bw->current_content) ==
|
|
|
|
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
|
|
|
|
2006-01-25 11:25:38 +03:00
|
|
|
schedule_remove(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) {
|
|
|
|
browser_window_refresh_url_bar(bw,
|
2011-10-03 19:56:47 +04:00
|
|
|
content_get_url(bw->current_content),
|
|
|
|
bw->frag_id);
|
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
|
|
|
|
|
|
|
|
2004-06-23 00:39:16 +04:00
|
|
|
/**
|
|
|
|
* Reload the page in a browser window.
|
|
|
|
*
|
|
|
|
* \param bw browser window
|
2004-06-29 23:08:19 +04:00
|
|
|
* \param all whether to reload all objects associated with the page
|
2004-06-23 00:39:16 +04:00
|
|
|
*/
|
|
|
|
|
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++) {
|
|
|
|
if (sheets[i].type == HTML_STYLESHEET_EXTERNAL &&
|
|
|
|
sheets[i].data.external != NULL) {
|
|
|
|
content_invalidate_reuse_data(
|
|
|
|
sheets[i].data.external);
|
|
|
|
}
|
2004-06-29 23:08:19 +04:00
|
|
|
}
|
|
|
|
}
|
2010-03-28 16:56:39 +04:00
|
|
|
|
|
|
|
content_invalidate_reuse_data(bw->current_content);
|
|
|
|
|
2011-10-03 19:56:47 +04:00
|
|
|
browser_window_go(bw, nsurl_access(
|
|
|
|
content_get_url(bw->current_content)), 0, false);
|
2004-06-23 00:39:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-02-25 18:12:58 +03:00
|
|
|
/**
|
|
|
|
* Change the status bar of a browser window.
|
|
|
|
*
|
2006-09-02 19:52:41 +04:00
|
|
|
* \param bw browser window
|
2004-02-25 18:12:58 +03:00
|
|
|
* \param text new status text (copied)
|
|
|
|
*/
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
if ((bw->status_text != NULL) &&
|
|
|
|
(strcmp(text, bw->status_text) == 0)) {
|
|
|
|
/* status text is unchanged */
|
|
|
|
bw->status_match++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* status text is changed */
|
|
|
|
|
|
|
|
text_len = strlen(text);
|
|
|
|
|
|
|
|
if ((bw->status_text == NULL) || (bw->status_text_len < text_len)) {
|
|
|
|
/* no current string allocation or it is not long enough */
|
|
|
|
free(bw->status_text);
|
|
|
|
bw->status_text = strdup(text);
|
|
|
|
bw->status_text_len = text_len;
|
|
|
|
} else {
|
|
|
|
/* current allocation has enough space */
|
|
|
|
memcpy(bw->status_text, text, text_len + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
bw->status_miss++;
|
2010-02-11 03:10:58 +03:00
|
|
|
gui_window_set_status(bw->window, bw->status_text);
|
2002-09-11 18:24:02 +04:00
|
|
|
}
|
|
|
|
|
2004-07-18 21:38:01 +04:00
|
|
|
|
2004-04-01 04:26:05 +04:00
|
|
|
/**
|
|
|
|
* Change the shape of the mouse pointer
|
|
|
|
*
|
|
|
|
* \param shape shape to use
|
|
|
|
*/
|
|
|
|
|
2011-06-15 00:00:18 +04:00
|
|
|
void browser_window_set_pointer(struct browser_window *bw,
|
|
|
|
gui_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);
|
2011-06-15 00:00:18 +04:00
|
|
|
|
|
|
|
assert(root);
|
|
|
|
assert(root->window);
|
|
|
|
|
|
|
|
gui_window_set_pointer(root->window, shape);
|
2004-04-01 04:26:05 +04:00
|
|
|
}
|
|
|
|
|
2004-02-25 18:12:58 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Close and destroy a browser window.
|
|
|
|
*
|
|
|
|
* \param bw browser window
|
|
|
|
*/
|
|
|
|
|
|
|
|
void browser_window_destroy(struct browser_window *bw)
|
2003-10-25 18:13:49 +04:00
|
|
|
{
|
2006-09-02 19:52:41 +04:00
|
|
|
/* can't destoy child windows on their own */
|
|
|
|
assert(!bw->parent);
|
|
|
|
|
|
|
|
/* destroy */
|
|
|
|
browser_window_destroy_internal(bw);
|
|
|
|
free(bw);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Close and destroy all child browser window.
|
|
|
|
*
|
|
|
|
* \param bw browser window
|
|
|
|
*/
|
|
|
|
|
|
|
|
void browser_window_destroy_children(struct browser_window *bw)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Release all memory associated with a browser window.
|
|
|
|
*
|
|
|
|
* \param bw browser window
|
|
|
|
*/
|
|
|
|
|
|
|
|
void browser_window_destroy_internal(struct browser_window *bw)
|
|
|
|
{
|
|
|
|
assert(bw);
|
|
|
|
|
2006-12-30 03:34:26 +03:00
|
|
|
LOG(("Destroying window"));
|
|
|
|
|
2010-03-28 16:56:39 +04:00
|
|
|
if (bw->children != NULL || bw->iframes != NULL)
|
2006-09-02 19:52:41 +04:00
|
|
|
browser_window_destroy_children(bw);
|
2010-03-28 16:56:39 +04:00
|
|
|
|
2011-01-17 11:28:22 +03:00
|
|
|
schedule_remove(browser_window_refresh, bw);
|
|
|
|
|
2011-06-15 00:00:18 +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) {
|
2011-06-29 01:09:57 +04:00
|
|
|
struct browser_window *top = browser_window_get_root(bw);
|
2011-06-15 00:00:18 +04:00
|
|
|
|
|
|
|
if (top->focus == bw)
|
2011-06-22 17:52:56 +04:00
|
|
|
top->focus = top;
|
2011-07-13 17:20:26 +04:00
|
|
|
|
|
|
|
if (bw->current_content != NULL &&
|
|
|
|
top->cur_sel == content_get_selection(
|
|
|
|
bw->current_content)) {
|
|
|
|
browser_window_set_selection(top, NULL);
|
|
|
|
}
|
2011-06-15 00:00:18 +04:00
|
|
|
}
|
|
|
|
|
2011-01-17 11:28:22 +03: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.
|
|
|
|
*/
|
|
|
|
|
2011-06-15 00:00:18 +04:00
|
|
|
if (bw->window) {
|
|
|
|
/* Only the root window has a GUI window */
|
|
|
|
gui_window_destroy(bw->window);
|
|
|
|
}
|
2011-01-17 11:28:22 +03:00
|
|
|
|
2010-03-28 16:56:39 +04:00
|
|
|
if (bw->loading_content != NULL) {
|
2011-07-23 21:53:57 +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
|
|
|
}
|
2010-03-28 16:56:39 +04:00
|
|
|
|
|
|
|
if (bw->current_content != NULL) {
|
|
|
|
content_status status = content_get_status(bw->current_content);
|
|
|
|
if (status == CONTENT_STATUS_READY ||
|
|
|
|
status == CONTENT_STATUS_DONE)
|
2004-08-12 02:08:26 +04:00
|
|
|
content_close(bw->current_content);
|
2010-03-28 16:56:39 +04:00
|
|
|
|
|
|
|
hlcache_handle_release(bw->current_content);
|
|
|
|
bw->current_content = NULL;
|
2004-02-25 18:12:58 +03:00
|
|
|
}
|
|
|
|
|
2011-10-07 22:12:47 +04:00
|
|
|
if (bw->loading_favicon != NULL) {
|
|
|
|
hlcache_handle_abort(bw->loading_favicon);
|
|
|
|
hlcache_handle_release(bw->loading_favicon);
|
|
|
|
bw->loading_favicon = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bw->current_favicon != NULL) {
|
|
|
|
content_status status = content_get_status(bw->current_favicon);
|
2011-10-07 03:31:55 +04:00
|
|
|
|
|
|
|
if (status == CONTENT_STATUS_READY ||
|
|
|
|
status == CONTENT_STATUS_DONE)
|
2011-10-07 22:12:47 +04:00
|
|
|
content_close(bw->current_favicon);
|
2011-10-07 03:31:55 +04:00
|
|
|
|
2011-10-07 22:12:47 +04:00
|
|
|
hlcache_handle_release(bw->current_favicon);
|
|
|
|
bw->current_favicon = NULL;
|
2011-10-07 03:31:55 +04:00
|
|
|
}
|
|
|
|
|
2011-06-15 00:00:18 +04:00
|
|
|
if (bw->box != NULL) {
|
|
|
|
bw->box->iframe = NULL;
|
|
|
|
bw->box = NULL;
|
|
|
|
}
|
|
|
|
|
2011-01-17 11:35:20 +03:00
|
|
|
/* These simply free memory, so are safe here */
|
|
|
|
history_destroy(bw->history);
|
|
|
|
|
2006-09-02 19:52:41 +04:00
|
|
|
free(bw->name);
|
2004-08-07 02:19:13 +04:00
|
|
|
free(bw->frag_id);
|
2010-02-11 02:37:06 +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-09-02 19:52:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-11-27 00:04:42 +03:00
|
|
|
/**
|
|
|
|
* Reformat a browser window contents to a new width or height.
|
|
|
|
*
|
|
|
|
* \param bw the browser window to reformat
|
|
|
|
* \param width new width
|
|
|
|
* \param height new height
|
|
|
|
*/
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-11-26 23:11:20 +03:00
|
|
|
/**
|
|
|
|
* Sets the scale of a browser window
|
|
|
|
*
|
|
|
|
* \param bw The browser window to scale
|
|
|
|
* \param scale The new scale
|
|
|
|
* \param all Scale all windows in the tree (ie work up aswell as down)
|
|
|
|
*/
|
|
|
|
|
2006-11-27 18:35:18 +03:00
|
|
|
void browser_window_set_scale(struct browser_window *bw, float scale, bool all)
|
2006-11-27 00:04:42 +03:00
|
|
|
{
|
2006-11-26 23:11:20 +03:00
|
|
|
while (bw->parent && all)
|
|
|
|
bw = bw->parent;
|
2010-03-28 16:56:39 +04:00
|
|
|
|
2006-11-26 23:11:20 +03:00
|
|
|
browser_window_set_scale_internal(bw, scale);
|
2010-03-28 16:56:39 +04:00
|
|
|
|
2006-11-26 23:11:20 +03:00
|
|
|
if (bw->parent)
|
|
|
|
bw = bw->parent;
|
2010-03-28 16:56:39 +04:00
|
|
|
|
2006-11-26 23:11:20 +03:00
|
|
|
browser_window_recalculate_frameset(bw);
|
|
|
|
}
|
|
|
|
|
2006-11-27 00:04:42 +03:00
|
|
|
void browser_window_set_scale_internal(struct browser_window *bw, float scale)
|
|
|
|
{
|
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 {
|
2007-08-07 07:55:18 +04:00
|
|
|
bw->reformat_pending = true;
|
|
|
|
browser_reformat_pending = true;
|
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
|
|
|
|
|
|
|
/**
|
|
|
|
* Update URL bar for a given browser window to given URL
|
|
|
|
*
|
|
|
|
* \param bw Browser window to update URL bar for.
|
2009-03-31 15:12:36 +04:00
|
|
|
* \param url URL for content displayed by bw, excluding any fragment.
|
|
|
|
* \param frag Additional fragment. May be NULL if none.
|
2009-03-31 15:06:09 +04:00
|
|
|
*/
|
|
|
|
|
2011-10-03 19:56:47 +04:00
|
|
|
void browser_window_refresh_url_bar(struct browser_window *bw, nsurl *url,
|
2009-03-30 19:46:26 +04:00
|
|
|
const char *frag)
|
2009-03-31 15:06:09 +04:00
|
|
|
{
|
2009-03-30 19:46:26 +04:00
|
|
|
char *url_buf;
|
2009-03-31 16:55:23 +04:00
|
|
|
|
|
|
|
assert(bw);
|
|
|
|
assert(url);
|
|
|
|
|
2011-06-15 00:00:18 +04:00
|
|
|
if (bw->parent != NULL) {
|
|
|
|
/* Not root window; don't set a URL in GUI URL bar */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-03-31 16:55:23 +04:00
|
|
|
if (frag == NULL) {
|
|
|
|
/* With no fragment, we may as well pass url straight through
|
|
|
|
* saving a malloc, copy, free cycle.
|
|
|
|
*/
|
2011-10-03 19:56:47 +04:00
|
|
|
gui_window_set_url(bw->window, nsurl_access(url));
|
2009-03-31 16:55:23 +04:00
|
|
|
} else {
|
2011-10-08 16:22:29 +04:00
|
|
|
url_buf = malloc(nsurl_length(url) + 1 /* # */ +
|
2009-03-31 16:55:23 +04:00
|
|
|
strlen(frag) + 1 /* \0 */);
|
|
|
|
if (url_buf != NULL) {
|
|
|
|
/* This sprintf is safe because of the above size
|
|
|
|
* calculation, thus we don't need snprintf
|
|
|
|
*/
|
2011-10-03 19:56:47 +04:00
|
|
|
sprintf(url_buf, "%s#%s", nsurl_access(url), frag);
|
2009-03-31 16:55:23 +04:00
|
|
|
gui_window_set_url(bw->window, url_buf);
|
|
|
|
free(url_buf);
|
|
|
|
} else {
|
|
|
|
warn_user("NoMemory", 0);
|
|
|
|
}
|
|
|
|
}
|
2009-03-30 19:46:26 +04:00
|
|
|
}
|
2006-11-26 23:11:20 +03:00
|
|
|
|
2006-09-02 19:52:41 +04:00
|
|
|
/**
|
|
|
|
* Locate a browser window in the specified stack according.
|
|
|
|
*
|
|
|
|
* \param bw the browser_window to search all relatives of
|
|
|
|
* \param target the target to locate
|
2007-04-08 03:08:31 +04:00
|
|
|
* \param new_window always return a new window (ie 'Open Link in New Window')
|
2006-09-02 19:52:41 +04:00
|
|
|
*/
|
2006-09-06 04:15:10 +04:00
|
|
|
|
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;
|
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))) &&
|
|
|
|
(!option_target_blank)) {
|
|
|
|
/* 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 */
|
2008-11-29 03:24:09 +03:00
|
|
|
if (((option_button_2_tab) && (mouse & BROWSER_MOUSE_CLICK_2)) ||
|
|
|
|
((!option_button_2_tab) &&
|
|
|
|
((mouse & BROWSER_MOUSE_CLICK_1) &&
|
|
|
|
(mouse & BROWSER_MOUSE_MOD_2))) ||
|
|
|
|
((option_button_2_tab) && ((target == TARGET_BLANK) ||
|
|
|
|
(!strcasecmp(target, "_blank"))))) {
|
|
|
|
/* open in new tab if:
|
|
|
|
* - button_2 opens in new tab and button_2 was pressed
|
|
|
|
* OR
|
|
|
|
* - button_2 doesn't open in new tabs and button_1 was
|
|
|
|
* pressed with ctrl held
|
|
|
|
* OR
|
|
|
|
* - button_2 opens in new tab and the link target is "_blank"
|
|
|
|
*/
|
|
|
|
bw_target = browser_window_create(NULL, bw, NULL, false, true);
|
|
|
|
if (!bw_target)
|
|
|
|
return bw;
|
|
|
|
return bw_target;
|
|
|
|
} else if (((!option_button_2_tab) &&
|
|
|
|
(mouse & BROWSER_MOUSE_CLICK_2)) ||
|
|
|
|
((option_button_2_tab) &&
|
|
|
|
((mouse & BROWSER_MOUSE_CLICK_1) &&
|
|
|
|
(mouse & BROWSER_MOUSE_MOD_2))) ||
|
|
|
|
((!option_button_2_tab) && ((target == TARGET_BLANK) ||
|
|
|
|
(!strcasecmp(target, "_blank"))))) {
|
|
|
|
/* open in new window if:
|
|
|
|
* - button_2 doesn't open in new tabs and button_2 was pressed
|
|
|
|
* OR
|
|
|
|
* - button_2 opens in new tab and button_1 was pressed with
|
|
|
|
* ctrl held
|
|
|
|
* OR
|
|
|
|
* - button_2 doesn't open in new tabs and the link target is
|
|
|
|
* "_blank"
|
|
|
|
*/
|
2008-08-24 14:31:38 +04:00
|
|
|
bw_target = browser_window_create(NULL, bw, NULL, false, false);
|
2007-04-08 03:08:31 +04:00
|
|
|
if (!bw_target)
|
|
|
|
return bw;
|
|
|
|
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 */
|
|
|
|
if (!option_target_blank)
|
|
|
|
return bw;
|
2008-08-24 14:31:38 +04:00
|
|
|
bw_target = browser_window_create(NULL, bw, NULL, false, false);
|
2007-04-08 03:08:31 +04:00
|
|
|
if (!bw_target)
|
|
|
|
return bw;
|
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)
|
|
|
|
warn_user("NoMemory", 0);
|
|
|
|
}
|
2006-09-02 19:52:41 +04:00
|
|
|
return bw_target;
|
|
|
|
}
|
|
|
|
|
2009-03-31 15:06:09 +04:00
|
|
|
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)
|
2006-09-02 19:52:41 +04:00
|
|
|
{
|
|
|
|
int i;
|
2006-09-06 04:15:10 +04:00
|
|
|
|
2006-09-02 19:52:41 +04:00
|
|
|
if ((bw->name) && (!strcasecmp(bw->name, target))) {
|
|
|
|
if ((bw == page) || (depth > *rdepth)) {
|
|
|
|
*rdepth = depth;
|
|
|
|
*bw_target = bw;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((!bw->children) && (!bw->iframes))
|
|
|
|
return;
|
2006-09-06 04:15:10 +04:00
|
|
|
|
2006-09-02 19:52:41 +04:00
|
|
|
depth++;
|
2009-11-22 16:35:41 +03:00
|
|
|
|
|
|
|
if (bw->children != NULL) {
|
|
|
|
for (i = 0; i < (bw->cols * bw->rows); i++) {
|
|
|
|
if ((bw->children[i].name) &&
|
|
|
|
(!strcasecmp(bw->children[i].name,
|
|
|
|
target))) {
|
|
|
|
if ((page == &bw->children[i]) ||
|
|
|
|
(depth > *rdepth)) {
|
|
|
|
*rdepth = depth;
|
|
|
|
*bw_target = &bw->children[i];
|
|
|
|
}
|
2006-09-02 19:52:41 +04:00
|
|
|
}
|
2009-11-22 16:35:41 +03:00
|
|
|
if (bw->children[i].children)
|
|
|
|
browser_window_find_target_internal(
|
|
|
|
&bw->children[i],
|
|
|
|
target, depth, page,
|
|
|
|
rdepth, bw_target);
|
2006-09-02 19:52:41 +04:00
|
|
|
}
|
2009-11-22 16:35:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (bw->iframes != NULL) {
|
|
|
|
for (i = 0; i < bw->iframe_count; i++)
|
|
|
|
browser_window_find_target_internal(&bw->iframes[i],
|
2009-03-31 15:06:09 +04:00
|
|
|
target, depth, page, rdepth, bw_target);
|
2006-09-02 19:52:41 +04:00
|
|
|
}
|
2003-10-25 18:13:49 +04:00
|
|
|
}
|
|
|
|
|
2004-02-25 18:12:58 +03:00
|
|
|
|
2004-10-18 01:11:29 +04:00
|
|
|
/**
|
2011-06-27 22:19:47 +04:00
|
|
|
* Handle non-click mouse action in a browser window. (drag ends, movements)
|
2004-10-18 01:11:29 +04:00
|
|
|
*
|
2006-09-02 19:52:41 +04:00
|
|
|
* \param bw browser window
|
2005-04-15 09:52:25 +04:00
|
|
|
* \param mouse state of mouse buttons and modifier keys
|
2006-09-02 19:52:41 +04:00
|
|
|
* \param x coordinate of mouse
|
|
|
|
* \param y coordinate of mouse
|
2004-10-18 01:11:29 +04:00
|
|
|
*/
|
|
|
|
|
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;
|
|
|
|
gui_pointer_shape pointer = GUI_POINTER_DEFAULT;
|
2009-05-28 18:35:12 +04:00
|
|
|
|
2011-09-04 21:24:45 +04:00
|
|
|
if (bw->window != NULL && bw->drag_window && bw != bw->drag_window) {
|
|
|
|
/* 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. */
|
|
|
|
struct browser_window *drag_bw = bw->drag_window;
|
|
|
|
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) {
|
|
|
|
off_x -= scrollbar_get_offset(drag_bw->scroll_x);
|
|
|
|
off_y -= scrollbar_get_offset(drag_bw->scroll_y);
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2009-05-28 18:35:12 +04:00
|
|
|
if (c == NULL && bw->drag_type != DRAGGING_FRAME)
|
2005-08-21 14:52:17 +04:00
|
|
|
return;
|
2004-10-18 01:11:29 +04:00
|
|
|
|
2005-04-15 09:52:25 +04:00
|
|
|
if (bw->drag_type != DRAGGING_NONE && !mouse) {
|
|
|
|
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 */
|
2011-08-25 00:44:47 +04: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);
|
|
|
|
|
|
|
|
if ((scr_x > 0 && scr_x < browser_window_get_scrollbar_len(bw,
|
|
|
|
true) &&
|
2011-08-25 00:44:47 +04:00
|
|
|
scr_y > 0 && scr_y < SCROLLBAR_WIDTH &&
|
|
|
|
bw->drag_type == DRAGGING_NONE) ||
|
2011-07-06 00:13:28 +04:00
|
|
|
bw->drag_type == DRAGGING_SCR_X) {
|
2011-08-25 00:44:47 +04:00
|
|
|
/* Start a scrollbar drag, or continue existing drag */
|
2011-07-06 00:13:28 +04:00
|
|
|
status = scrollbar_mouse_action(bw->scroll_x, mouse,
|
|
|
|
scr_x, scr_y);
|
|
|
|
pointer = GUI_POINTER_DEFAULT;
|
|
|
|
|
|
|
|
if (status != NULL)
|
|
|
|
browser_window_set_status(bw, status);
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
if ((scr_y > 0 && scr_y < browser_window_get_scrollbar_len(bw,
|
|
|
|
false) &&
|
2011-08-25 00:44:47 +04:00
|
|
|
scr_x > 0 && scr_x < SCROLLBAR_WIDTH &&
|
|
|
|
bw->drag_type == DRAGGING_NONE) ||
|
2011-07-06 00:13:28 +04:00
|
|
|
bw->drag_type == DRAGGING_SCR_Y) {
|
2011-08-25 00:44:47 +04:00
|
|
|
/* Start a scrollbar drag, or continue existing drag */
|
2011-07-06 00:13:28 +04:00
|
|
|
status = scrollbar_mouse_action(bw->scroll_y, mouse,
|
|
|
|
scr_x, scr_y);
|
|
|
|
pointer = GUI_POINTER_DEFAULT;
|
|
|
|
|
|
|
|
if (status != NULL)
|
|
|
|
browser_window_set_status(bw, status);
|
|
|
|
|
|
|
|
browser_window_set_pointer(bw, pointer);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-09-02 19:52:41 +04: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);
|
2006-09-02 19:52:41 +04:00
|
|
|
} else if (bw->drag_type == DRAGGING_PAGE_SCROLL) {
|
2005-08-21 14:52:17 +04:00
|
|
|
/* mouse movement since drag started */
|
2006-09-02 19:52:41 +04:00
|
|
|
int scrollx = bw->drag_start_x - x;
|
|
|
|
int scrolly = bw->drag_start_y - y;
|
2005-04-15 09:52:25 +04:00
|
|
|
|
2005-08-21 14:52:17 +04:00
|
|
|
/* new scroll offsets */
|
2006-09-02 19:52:41 +04:00
|
|
|
scrollx += bw->drag_start_scroll_x;
|
|
|
|
scrolly += bw->drag_start_scroll_y;
|
2005-04-15 09:52:25 +04:00
|
|
|
|
2006-09-02 19:52:41 +04:00
|
|
|
bw->drag_start_scroll_x = scrollx;
|
|
|
|
bw->drag_start_scroll_y = scrolly;
|
2005-04-15 09:52:25 +04:00
|
|
|
|
2011-07-06 00:13:28 +04:00
|
|
|
browser_window_set_scroll(bw, scrollx, scrolly);
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2010-06-04 13:35:08 +04:00
|
|
|
* Handle mouse clicks in a browser window.
|
2005-04-15 09:52:25 +04:00
|
|
|
*
|
2006-09-02 19:52:41 +04:00
|
|
|
* \param bw browser window
|
2006-02-16 02:09:55 +03:00
|
|
|
* \param mouse state of mouse buttons and modifier keys
|
2006-09-02 19:52:41 +04:00
|
|
|
* \param x coordinate of mouse
|
|
|
|
* \param y coordinate of mouse
|
2005-04-15 09:52:25 +04:00
|
|
|
*/
|
|
|
|
|
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;
|
|
|
|
gui_pointer_shape pointer = GUI_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) {
|
|
|
|
status = scrollbar_mouse_action(bw->scroll_x, mouse,
|
|
|
|
scr_x, scr_y);
|
|
|
|
pointer = GUI_POINTER_DEFAULT;
|
|
|
|
|
|
|
|
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) {
|
|
|
|
status = scrollbar_mouse_action(bw->scroll_y, mouse,
|
|
|
|
scr_x, scr_y);
|
|
|
|
pointer = GUI_POINTER_DEFAULT;
|
|
|
|
|
|
|
|
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:
|
|
|
|
content_mouse_action(c, bw, mouse, x, y);
|
2005-04-15 09:52:25 +04:00
|
|
|
break;
|
2010-06-04 13:35:08 +04:00
|
|
|
default:
|
|
|
|
if (mouse & BROWSER_MOUSE_MOD_2) {
|
|
|
|
if (mouse & BROWSER_MOUSE_DRAG_2)
|
|
|
|
gui_drag_save_object(GUI_SAVE_OBJECT_NATIVE, c,
|
|
|
|
bw->window);
|
|
|
|
else if (mouse & BROWSER_MOUSE_DRAG_1)
|
|
|
|
gui_drag_save_object(GUI_SAVE_OBJECT_ORIG, c,
|
|
|
|
bw->window);
|
|
|
|
}
|
|
|
|
else if (mouse & (BROWSER_MOUSE_DRAG_1 |
|
|
|
|
BROWSER_MOUSE_DRAG_2)) {
|
|
|
|
browser_window_page_drag_start(bw, x, y);
|
2011-06-15 00:00:18 +04:00
|
|
|
browser_window_set_pointer(bw, GUI_POINTER_MOVE);
|
2006-02-16 02:09:55 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handles the end of a drag operation in a browser window.
|
|
|
|
*
|
2006-09-02 19:52:41 +04:00
|
|
|
* \param bw browser window
|
2006-02-16 02:09:55 +03:00
|
|
|
* \param mouse state of mouse buttons and modifier keys
|
2006-09-02 19:52:41 +04:00
|
|
|
* \param x coordinate of mouse
|
|
|
|
* \param y coordinate of mouse
|
2011-06-15 00:00:18 +04:00
|
|
|
*
|
2011-06-27 22:19:47 +04:00
|
|
|
* TODO: Remove this function, once these things are associated with content,
|
|
|
|
* rather than bw.
|
2006-02-16 02:09:55 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
void browser_window_mouse_drag_end(struct browser_window *bw,
|
|
|
|
browser_mouse_state mouse, int x, int y)
|
|
|
|
{
|
2011-07-06 00:13:28 +04:00
|
|
|
int scr_x, scr_y;
|
|
|
|
|
2006-02-16 02:09:55 +03:00
|
|
|
switch (bw->drag_type) {
|
2011-06-27 21:29:49 +04:00
|
|
|
case DRAGGING_SELECTION:
|
2011-07-13 17:20:26 +04:00
|
|
|
/* Drag handled by content handler */
|
2011-06-27 21:29:49 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DRAGGING_OTHER:
|
2011-06-28 15:15:39 +04:00
|
|
|
/* Drag handled by content handler */
|
2011-06-27 21:29:49 +04:00
|
|
|
break;
|
2005-04-15 09:52:25 +04:00
|
|
|
|
2011-07-06 00:13:28 +04:00
|
|
|
case DRAGGING_SCR_X:
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
scrollbar_mouse_drag_end(bw->scroll_x, mouse, scr_x, scr_y);
|
|
|
|
|
|
|
|
bw->drag_type = DRAGGING_NONE;
|
|
|
|
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);
|
|
|
|
|
|
|
|
bw->drag_type = DRAGGING_NONE;
|
|
|
|
break;
|
|
|
|
|
2010-06-04 13:35:08 +04:00
|
|
|
default:
|
2011-09-07 16:27:37 +04:00
|
|
|
browser_window_set_drag_type(bw, DRAGGING_NONE);
|
2010-06-04 13:35:08 +04:00
|
|
|
break;
|
2002-12-31 01:56:30 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-04-15 09:52:25 +04:00
|
|
|
/**
|
|
|
|
* Redraw a rectangular region of a browser window
|
|
|
|
*
|
2006-09-02 19:52:41 +04:00
|
|
|
* \param bw browser window to be redrawn
|
|
|
|
* \param x x co-ord of top-left
|
|
|
|
* \param y y co-ord of top-left
|
2005-04-15 09:52:25 +04:00
|
|
|
* \param width width of rectangle
|
|
|
|
* \param height height of rectangle
|
|
|
|
*/
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Start drag scrolling the contents of the browser window
|
|
|
|
*
|
|
|
|
* \param bw browser window
|
|
|
|
* \param x x ordinate of initial mouse position
|
|
|
|
* \param y y ordinate
|
|
|
|
*/
|
|
|
|
|
|
|
|
void browser_window_page_drag_start(struct browser_window *bw, int x, int y)
|
|
|
|
{
|
|
|
|
bw->drag_type = DRAGGING_PAGE_SCROLL;
|
|
|
|
|
2006-09-02 19:52:41 +04: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 */
|
2011-06-15 00:00:18 +04:00
|
|
|
gui_window_get_scroll(bw->window, &bw->drag_start_scroll_x,
|
|
|
|
&bw->drag_start_scroll_y);
|
2005-04-15 09:52:25 +04:00
|
|
|
|
2011-06-15 00:00:18 +04:00
|
|
|
gui_window_scroll_start(bw->window);
|
2011-09-04 21:24:45 +04:00
|
|
|
} else {
|
|
|
|
/* Core managed browser window */
|
2011-08-24 23:26:45 +04: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
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check availability of Back action for a given browser window
|
|
|
|
*
|
|
|
|
* \param bw browser window
|
|
|
|
* \return true if Back action is available
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool browser_window_back_available(struct browser_window *bw)
|
|
|
|
{
|
|
|
|
return (bw && bw->history && history_back_available(bw->history));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check availability of Forward action for a given browser window
|
|
|
|
*
|
|
|
|
* \param bw browser window
|
|
|
|
* \return true if Forward action is available
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool browser_window_forward_available(struct browser_window *bw)
|
|
|
|
{
|
|
|
|
return (bw && bw->history && history_forward_available(bw->history));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check availability of Reload action for a given browser window
|
|
|
|
*
|
|
|
|
* \param bw browser window
|
|
|
|
* \return true if Reload action is available
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool browser_window_reload_available(struct browser_window *bw)
|
|
|
|
{
|
|
|
|
return (bw && bw->current_content && !bw->loading_content);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check availability of Stop action for a given browser window
|
|
|
|
*
|
|
|
|
* \param bw browser window
|
|
|
|
* \return true if Stop action is available
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool browser_window_stop_available(struct browser_window *bw)
|
|
|
|
{
|
|
|
|
return (bw && (bw->loading_content ||
|
|
|
|
(bw->current_content &&
|
2010-03-28 16:56:39 +04:00
|
|
|
(content_get_status(bw->current_content) !=
|
|
|
|
CONTENT_STATUS_DONE))));
|
2009-03-24 01:22:30 +03:00
|
|
|
}
|