Author: bursa
Date: Sun Nov 26 20:11:20 2006
New Revision: 3070
URL: http://svn.semichrome.net?rev=3D3070&view=3Drev
Log:
Move frames-related code out of browser.c into a new file. Remove some brow=
ser_window calls from html.c.
Added:
trunk/netsurf/desktop/frames.c
trunk/netsurf/desktop/frames.h
Modified:
trunk/netsurf/desktop/browser.c
trunk/netsurf/desktop/browser.h
trunk/netsurf/render/html.c
Modified: trunk/netsurf/desktop/browser.c
URL: http://svn.semichrome.net/trunk/netsurf/desktop/browser.c?rev=3D3070&r=
1=3D3069&r2=3D3070&view=3Ddiff
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- trunk/netsurf/desktop/browser.c (original)
+++ trunk/netsurf/desktop/browser.c Sun Nov 26 20:11:20 2006
@@ -3,9 +3,10 @@
* Licensed under the GNU General Public License,
* http://www.opensource.org/licenses/gpl-license
* Copyright 2003 Phil Mellor <monkeyson@...>
- * Copyright 2005 James Bursa <bursa@...>
+ * Copyright 2006 James Bursa <bursa@...>
* Copyright 2004 Andrew Timmins <atimmins@...>
* Copyright 2004 John Tytgat <John.Tytgat@...>
+ * Copyright 2006 Richard Wilson <info@...>
*/
=20
/** \file
@@ -30,6 +31,7 @@
#include "netsurf/desktop/401login.h"
#endif
#include "netsurf/desktop/browser.h"
+#include "netsurf/desktop/frames.h"
#include "netsurf/desktop/history_core.h"
#include "netsurf/desktop/gui.h"
#include "netsurf/desktop/options.h"
@@ -49,22 +51,15 @@
#include "netsurf/utils/utils.h"
#include "netsurf/utils/utf8.h"
=20
-/** maximum frame resize margin */
-#define FRAME_RESIZE 6
+/** browser window which is being redrawn. Valid only during redraw. */
+struct browser_window *current_redraw_browser;
+
+/** fake content for <a> being saved as a link */
+struct content browser_window_href_content;
=20
/** maximum frame depth */
#define FRAME_DEPTH 8
=20
-/** browser window which is being redrawn. Valid only during redraw. */
-struct browser_window *current_redraw_browser;
-
-/** fake content for <a> being saved as a link */
-struct content browser_window_href_content;
-
-static void browser_window_set_scale_internal(struct browser_window *bw, f=
loat scale);
-static void browser_window_resize_frame(struct browser_window *bw, int x, =
int y);
-static bool browser_window_resolve_frame_dimension(struct browser_window *=
bw,
- struct browser_window *sibling, int x, int y, bool width, bool height);
static void browser_window_callback(content_msg msg, struct content *c,
intptr_t p1, intptr_t p2, union content_msg_data data);
static void browser_window_refresh(void *p);
@@ -74,18 +69,21 @@
static void browser_window_stop_throbber(struct browser_window *bw);
static void browser_window_set_status(struct browser_window *bw,
const char *text);
-static void browser_window_set_pointer(struct gui_window *g, gui_pointer_s=
hape shape);
+static void browser_window_set_pointer(struct gui_window *g,
+ gui_pointer_shape shape);
static void download_window_callback(fetch_msg msg, void *p, const void *d=
ata,
unsigned long size);
static void browser_window_destroy_children(struct browser_window *bw);
static void browser_window_destroy_internal(struct browser_window *bw);
-static struct browser_window *browser_window_find_target(struct browser_wi=
ndow *bw, const char *target);
-static void browser_window_find_target_internal(struct browser_window *bw,=
const char *target,
- int depth, struct browser_window *page, int *rdepth, struct browser_wind=
ow **bw_target);
+static void browser_window_set_scale_internal(struct browser_window *bw,
+ float scale);
+static struct browser_window *browser_window_find_target(
+ struct browser_window *bw, const char *target);
+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);
static void browser_window_mouse_action_html(struct browser_window *bw,
browser_mouse_state mouse, int x, int y);
-static bool browser_window_resize_frames(struct browser_window *bw, browse=
r_mouse_state mouse,
- int x, int y, gui_pointer_shape *pointer, const char **status, bool *act=
ion);
static void browser_window_mouse_action_text(struct browser_window *bw,
browser_mouse_state mouse, int x, int y);
static void browser_window_mouse_track_html(struct browser_window *bw,
@@ -117,7 +115,8 @@
* \param referer The referring uri
*/
=20
-struct browser_window *browser_window_create(const char *url, struct brows=
er_window *clone,
+struct browser_window *browser_window_create(const char *url,
+ struct browser_window *clone,
char *referer, bool history_add)
{
struct browser_window *bw;
@@ -156,582 +155,6 @@
if (url)
browser_window_go(bw, url, referer, history_add);
return bw;
-}
-
-
-/**
- * Returns the browser window that is responsible for the child.
- *
- * \param bw The browser window to find the owner of
- * \return the browser window's owner
- */
-
-struct browser_window *browser_window_owner(struct browser_window *bw) {
- /* an iframe's parent is just the parent window */
- if (bw->browser_window_type =3D=3D BROWSER_WINDOW_IFRAME)
- return bw->parent;
-
- /* the parent of a frameset is either a NORMAL window or an IFRAME */
- while (bw->parent) {
- switch (bw->browser_window_type) {
- case BROWSER_WINDOW_NORMAL:
- case BROWSER_WINDOW_IFRAME:
- return bw;
- case BROWSER_WINDOW_FRAME:
- case BROWSER_WINDOW_FRAMESET:
- bw =3D bw->parent;
- break;
- }
- }
- return bw;
-}
-
-
-/**
- * Create and open a iframes for a browser window.
- *
- * \param bw The browser window to create iframes for
- * \param iframe The iframes to create
- */
-
-void browser_window_create_iframes(struct browser_window *bw,
- struct content_html_iframe *iframe) {
- struct browser_window *window;
- struct content_html_iframe *cur;
- int iframes =3D 0;
- int index;
-
- for (cur =3D iframe; cur; cur =3D cur->next)
- iframes++;
- bw->iframes =3D calloc(iframes, sizeof(*bw));
- if (!bw->iframes)
- return;
- bw->iframe_count =3D iframes;
-
- index =3D 0;
- for (cur =3D iframe; cur; cur =3D cur->next) {
- window =3D &(bw->iframes[index++]);
-
- /* content */
- window->history =3D history_create();
- window->sel =3D selection_create(window);
- window->refresh_interval =3D -1;
-
- /* window characteristics */
- window->drag_type =3D DRAGGING_NONE;
- window->browser_window_type =3D BROWSER_WINDOW_IFRAME;
- window->scrolling =3D cur->scrolling;
- window->border =3D cur->border;
- window->border_colour =3D cur->border_colour;
- window->no_resize =3D true;
- window->margin_width =3D cur->margin_width;
- window->margin_height =3D cur->margin_height;
- if (cur->name)
- window->name =3D strdup(cur->name);
-
- /* linking */
- window->box =3D cur->box;
- window->parent =3D bw;
-
- /* gui window */
- window->window =3D gui_create_browser_window(window, bw);
- }
-
- /* calculate dimensions */
- gui_window_update_extent(bw->window);
- browser_window_recalculate_iframes(bw);
-
- index =3D 0;
- for (cur =3D iframe; cur; cur =3D cur->next) {
- window =3D &(bw->iframes[index++]);
- if (cur->url)
- browser_window_go(window, cur->url, NULL, true);
- }
-}
-
-
-/**
- * Recalculate iframe positions following a resize.
- *
- * \param bw The browser window to reposition iframes for
- */
-
-void browser_window_recalculate_iframes(struct browser_window *bw) {
- struct browser_window *window;
- struct rect rect;
- int bw_width, bw_height;
- int index;
-
- assert(bw);
-
- /* update window dimensions */
- gui_window_get_dimensions(bw->window, &bw_width, &bw_height, false);
- if (!bw->parent) {
- bw->x0 =3D 0;
- bw->y0 =3D 0;
- bw->x1 =3D bw_width;
- bw->y1 =3D bw_height;
- }
-
- for (index =3D 0; index < bw->iframe_count; index++) {
- window =3D &(bw->iframes[index]);
- box_bounds(window->box, &rect);
- gui_window_position_frame(window->window, rect.x0, rect.y0,
- rect.x1, rect.y1);
- }
-}
-
-
-/**
- * Create and open aframeset for a browser window.
- *
- * \param bw The browser window to create the frameset for
- * \param iframe The frameset to create
- */
-
-void browser_window_create_frameset(struct browser_window *bw,
- struct content_html_frames *frameset) {
- int row, col, index;
- struct content_html_frames *frame;
- struct browser_window *window;
-
- /* we use a 3 stage approach such that the content is initially formatted=
to the
- * correct frameset dimensions */
- assert(bw && frameset);
-
- /* create children */
- assert(bw->children =3D=3D NULL);
- assert(frameset->cols + frameset->rows !=3D 0);
-
- bw->children =3D calloc((frameset->cols * frameset->rows), sizeof(*bw));
- if (!bw->children)
- return;
- bw->cols =3D frameset->cols;
- bw->rows =3D frameset->rows;
- for (row =3D 0; row < bw->rows; row++) {
- for (col =3D 0; col < bw->cols; col++) {
- index =3D (row * bw->cols) + col;
- frame =3D &frameset->children[index];
- window =3D &bw->children[index];
-
- /* content */
- window->history =3D history_create();
- window->sel =3D selection_create(window);
- window->refresh_interval =3D -1;
-
- /* window characteristics */
- window->drag_type =3D DRAGGING_NONE;
- if (frame->children)
- window->browser_window_type =3D BROWSER_WINDOW_FRAMESET;
- else
- window->browser_window_type =3D BROWSER_WINDOW_FRAME;
- window->scrolling =3D frame->scrolling;
- window->border =3D frame->border;
- window->border_colour =3D frame->border_colour;
- window->no_resize =3D frame->no_resize;
- window->frame_width =3D frame->width;
- window->frame_height =3D frame->height;
- window->margin_width =3D frame->margin_width;
- window->margin_height =3D frame->margin_height;
- if (frame->name)
- window->name =3D strdup(frame->name);
-
- /* linking */
- window->parent =3D bw;
-
- /* gui window */
- window->window =3D gui_create_browser_window(window, bw);
- if (frame->children)
- browser_window_create_frameset(window, frame);
- }
- }
-
- /* calculate dimensions */
- gui_window_update_extent(bw->window);
- browser_window_recalculate_frameset(bw);
-
- /* launch content */
- for (row =3D 0; row < bw->rows; row++) {
- for (col =3D 0; col < bw->cols; col++) {
- index =3D (row * bw->cols) + col;
- frame =3D &frameset->children[index];
- window =3D &bw->children[index];
-
- if (frame->url)
- browser_window_go(window, frame->url, NULL, true);
- }
- }
-}
-
-
-/**
- * Recalculate frameset positions following a resize.
- *
- * \param bw The browser window to reposition framesets for
- */
-
-void browser_window_recalculate_frameset(struct browser_window *bw) {
- int widths[bw->cols][bw->rows];
- int heights[bw->cols][bw->rows];
- int bw_width, bw_height;
- int avail_width, avail_height;
- int row, row2, col, index;
- struct browser_window *window;
- float relative;
- int size, extent;
- int x, y;
-
- assert(bw);
-
- /* window dimensions */
- if (!bw->parent) {
- gui_window_get_dimensions(bw->window, &bw_width, &bw_height, false);
- bw->x0 =3D 0;
- bw->y0 =3D 0;
- bw->x1 =3D bw_width;
- bw->y1 =3D bw_height;
- } else {
- bw_width =3D bw->x1 - bw->x0;
- bw_height =3D bw->y1 - bw->y0;
- }
- bw_width++;
- bw_height++;
-
- /* widths */
- for (row =3D 0; row < bw->rows; row++) {
- avail_width =3D bw_width;
- relative =3D 0;
- for (col =3D 0; col < bw->cols; col++) {
- index =3D (row * bw->cols) + col;
- window =3D &bw->children[index];
-
- switch (window->frame_width.unit) {
- case FRAME_DIMENSION_PIXELS:
- widths[col][row] =3D window->frame_width.value *
- gui_window_get_scale(window->window);
- if (window->border) {
- if (col !=3D 0)
- widths[col][row] +=3D 1;
- if (col !=3D bw->cols - 1)
- widths[col][row] +=3D 1;
- }
- break;
- case FRAME_DIMENSION_PERCENT:
- widths[col][row] =3D bw_width * window->frame_width.value / 100;
- break;
- case FRAME_DIMENSION_RELATIVE:
- widths[col][row] =3D 0;
- relative +=3D window->frame_width.value;
- break;
- }
- avail_width -=3D widths[col][row];
- }
-
- /* try to distribute remainder to relative values in preference */
- if ((relative > 0) && (avail_width > 0)) {
- for (col =3D 0; col < bw->cols; col++) {
- index =3D (row * bw->cols) + col;
- window =3D &bw->children[index];
-
- if (window->frame_width.unit =3D=3D FRAME_DIMENSION_RELATIVE) {
- size =3D avail_width * window->frame_width.value / relative;
- avail_width -=3D size;
- relative -=3D window->frame_width.value;
- widths[col][row] +=3D size;
- }
- }
- } else if (bw_width !=3D avail_width) {
- /* proportionally distribute error */
- extent =3D bw_width - avail_width;
- for (col =3D 0; col < bw->cols; col++) {
- index =3D (row * bw->cols) + col;
- window =3D &bw->children[index];
-
- if (col =3D=3D bw->cols - 1) {
- widths[col][row] =3D bw_width;
- } else {
- size =3D bw_width * widths[col][row] / extent;
- bw_width -=3D size;
- extent -=3D widths[col][row];
- widths[col][row] =3D size;
- }
- }
- }
- }
-
- /* heights */
- for (col =3D 0; col < bw->cols; col++) {
- avail_height =3D bw_height;
- relative =3D 0;
- for (row =3D 0; row < bw->rows; row++) {
- index =3D (row * bw->cols) + col;
- window =3D &bw->children[index];
-
- switch (window->frame_height.unit) {
- case FRAME_DIMENSION_PIXELS:
- heights[col][row] =3D window->frame_height.value *
- gui_window_get_scale(window->window);
- if (window->border) {
- if (row !=3D 0)
- heights[col][row] +=3D 1;
- if (row !=3D bw->rows - 1)
- heights[col][row] +=3D 1;
- }
- break;
- case FRAME_DIMENSION_PERCENT:
- heights[col][row] =3D bw_height *
- window->frame_height.value / 100;
- break;
- case FRAME_DIMENSION_RELATIVE:
- heights[col][row] =3D 0;
- relative +=3D window->frame_height.value;
- break;
- }
- avail_height -=3D heights[col][row];
- }
-
- if (avail_height =3D=3D 0)
- continue;
-
- /* try to distribute remainder to relative values in preference */
- if ((relative > 0) && (avail_height > 0)) {
- for (row =3D 0; row < bw->rows; row++) {
- index =3D (row * bw->cols) + col;
- window =3D &bw->children[index];
-
- if (window->frame_height.unit =3D=3D FRAME_DIMENSION_RELATIVE) {
- size =3D avail_height * window->frame_height.value / relative;
- avail_height -=3D size;
- relative -=3D window->frame_height.value;
- heights[col][row] +=3D size;
- }
- }
- } else if (bw_height !=3D avail_height) {
- /* proportionally distribute error */
- extent =3D bw_height - avail_height;
- for (row =3D 0; row < bw->rows; row++) {
- index =3D (row * bw->cols) + col;
- window =3D &bw->children[index];
-
- if (row =3D=3D bw->rows - 1) {
- heights[col][row] =3D bw_height;
- } else {
- size =3D bw_height * heights[col][row] / extent;
- bw_height -=3D size;
- extent -=3D heights[col][row];
- heights[col][row] =3D size;
- }
- }
- }
- }
-
- /* position frames and calculate children */
- for (row =3D 0; row < bw->rows; row++) {
- x =3D 0;
- for (col =3D 0; col < bw->cols; col++) {
- index =3D (row * bw->cols) + col;
- window =3D &bw->children[index];
-
- y =3D 0;
- for (row2 =3D 0; row2 < row; row2++)
- y+=3D heights[col][row2];
- gui_window_position_frame(window->window, x, y,
- x + widths[col][row] - 1,
- y + heights[col][row] - 1);
- x +=3D widths[col][row];
- if (window->children)
- browser_window_recalculate_frameset(window);
- }
- }
-}
-
-
-/**
- * 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)
- */
-void browser_window_set_scale(struct browser_window *bw, float scale, bool=
all) {
- while (bw->parent && all)
- bw =3D bw->parent;
- browser_window_set_scale_internal(bw, scale);
- if (bw->parent)
- bw =3D bw->parent;
- browser_window_recalculate_frameset(bw);
-}
-
-void browser_window_set_scale_internal(struct browser_window *bw, float sc=
ale) {
- int i;
-
- gui_window_set_scale(bw->window, scale);
-
- for (i =3D 0; i < (bw->cols * bw->rows); i++)
- browser_window_set_scale_internal(&bw->children[i], scale);
- for (i =3D 0; i < bw->iframe_count; i++)
- browser_window_set_scale_internal(&bw->iframes[i], scale);
-}
-
-
-/**
- * Resize a browser window that is a frame.
- *
- * \param bw The browser window to resize
- */
-
-void browser_window_resize_frame(struct browser_window *bw, int x, int y) {
- struct browser_window *parent;
- struct browser_window *sibling;
- int col =3D -1, row =3D -1, i;
- bool change =3D false;
-
- parent =3D bw->parent;
- assert(parent);
-
- /* get frame location */
- for (i =3D 0; i < (parent->cols * parent->rows); i++) {
- if (&parent->children[i] =3D=3D bw) {
- col =3D i % parent->cols;
- row =3D i / parent->cols;
- }
- }
- assert((col >=3D 0) && (row >=3D 0));
-
- sibling =3D NULL;
- if (bw->drag_resize_left)
- sibling =3D &parent->children[row * parent->cols + (col - 1)];
- else if (bw->drag_resize_right)
- sibling =3D &parent->children[row * parent->cols + (col + 1)];
- if (sibling)
- change |=3D browser_window_resolve_frame_dimension(bw, sibling, x, y, tr=
ue, false);
-
- sibling =3D NULL;
- if (bw->drag_resize_up)
- sibling =3D &parent->children[(row - 1) * parent->cols + col];
- else if (bw->drag_resize_down)
- sibling =3D &parent->children[(row + 1) * parent->cols + col];
- if (sibling)
- change |=3D browser_window_resolve_frame_dimension(bw, sibling, x, y, fa=
lse, true);
-
- if (change)
- browser_window_recalculate_frameset(parent);
-}
-
-
-bool browser_window_resolve_frame_dimension(struct browser_window *bw, str=
uct browser_window *sibling,
- int x, int y, bool width, bool height) {
- int bw_dimension, sibling_dimension;
- int bw_pixels, sibling_pixels;
- struct frame_dimension *bw_d, *sibling_d;
- float total_new;
- int frame_size;
-
- assert(!(width && height));
-
- /* extend/shrink the box to the pointer */
- if (width) {
- if (bw->drag_resize_left)
- bw_dimension =3D bw->x1 - x;
- else
- bw_dimension =3D x - bw->x0;
- bw_pixels =3D (bw->x1 - bw->x0);
- sibling_pixels =3D (sibling->x1 - sibling->x0);
- bw_d =3D &bw->frame_width;
- sibling_d =3D &sibling->frame_width;
- frame_size =3D bw->parent->x1 - bw->parent->x0;
- } else {
- if (bw->drag_resize_up)
- bw_dimension =3D bw->y1 - y;
- else
- bw_dimension =3D y - bw->y0;
- bw_pixels =3D (bw->y1 - bw->y0);
- sibling_pixels =3D (sibling->y1 - sibling->y0);
- bw_d =3D &bw->frame_height;
- sibling_d =3D &sibling->frame_height;
- frame_size =3D bw->parent->y1 - bw->parent->y0;
- }
- sibling_dimension =3D bw_pixels + sibling_pixels - bw_dimension;
-
- /* check for no change or no frame size*/
- if ((bw_dimension =3D=3D bw_pixels) || (frame_size =3D=3D 0))
- return false;
- /* check for both being 0 */
- total_new =3D bw_dimension + sibling_dimension;
- if ((bw_dimension + sibling_dimension) =3D=3D 0)
- return false;
-
- /* our frame dimensions are now known to be:
- *
- * <-- frame_size --> [VISIBLE PIXELS]
- * |<-- bw_pixels -->|<-- sibling_pixels -->| [VISIBLE PIXELS, BEFORE R=
ESIZE]
- * |<-- bw_d->value-->|<-- sibling_d->value-->| [SPECIFIED UNITS, BEFORE =
RESIZE]
- * |<--bw_dimension-->|<--sibling_dimension-->| [VISIBLE PIXELS, AFTER RE=
SIZE]
- * |<-- total_new -->| [VISIBLE PIXELS, AFTER RE=
SIZE]
- *
- * when we resize, we must retain the original unit specification such th=
at any
- * subsequent resizing of the parent window will recalculate the page as =
the
- * author specified.
- *
- * if the units of both frames are the same then we can resize the values=
simply
- * by updating the values to be a percentage of the original widths.
- */
- if (bw_d->unit =3D=3D sibling_d->unit) {
- float total_specified =3D bw_d->value + sibling_d->value;
- bw_d->value =3D (total_specified * bw_dimension) / total_new;
- sibling_d->value =3D total_specified - bw_d->value;
- return true;
- }
-
- /* if one of the sizes is relative then we don't alter the relative width=
and
- * just let it reflow across. the non-relative (pixel/percentage) value c=
an
- * simply be resolved to the specified width that will result in the requ=
ired
- * dimension.
- */
- if (bw_d->unit =3D=3D FRAME_DIMENSION_RELATIVE) {
- if ((sibling_pixels =3D=3D 0) && (bw_dimension =3D=3D 0))
- return false;
- if (sibling_d->value =3D=3D 0)
- bw_d->value =3D 1;
- if (sibling_pixels =3D=3D 0)
- sibling_d->value =3D (sibling_d->value * bw_pixels) / bw_dimension;
- else
- sibling_d->value =3D
- (sibling_d->value * sibling_dimension) / sibling_pixels;
-
- /* todo: the availble resize may have changed, update the drag box */
- return true;
- } else if (sibling_d->unit =3D=3D FRAME_DIMENSION_RELATIVE) {
- if ((bw_pixels =3D=3D 0) && (sibling_dimension =3D=3D 0))
- return false;
- if (bw_d->value =3D=3D 0)
- bw_d->value =3D 1;
- if (bw_pixels =3D=3D 0)
- bw_d->value =3D (bw_d->value * sibling_pixels) / sibling_dimension;
- else
- bw_d->value =3D (bw_d->value * bw_dimension) / bw_pixels;
-
- /* todo: the availble resize may have changed, update the drag box */
- return true;
- }
-
- /* finally we have a pixel/percentage mix. unlike relative values, percen=
tages
- * can easily be backwards-calculated as they can simply be scaled like p=
ixel
- * values
- */
- if (bw_d->unit =3D=3D FRAME_DIMENSION_PIXELS) {
- float total_specified =3D bw_d->value + frame_size * sibling_d->value / =
100;
- bw_d->value =3D (total_specified * bw_dimension) / total_new;
- sibling_d->value =3D (total_specified - bw_d->value) * 100 / frame_size;
- return true;
- } else if (sibling_d->unit =3D=3D FRAME_DIMENSION_PIXELS) {
- float total_specified =3D bw_d->value * frame_size / 100 + sibling_d->va=
lue;
- sibling_d->value =3D (total_specified * sibling_dimension) / total_new;
- bw_d->value =3D (total_specified - sibling_d->value) * 100 / frame_size;
- return true;
- }
- assert(!"Invalid frame dimension unit");
- return false;
}
=20
=20
@@ -901,196 +324,201 @@
=20
=20
switch (msg) {
- case CONTENT_MSG_LOADING:
- assert(bw->loading_content =3D=3D c);
-
- if (c->type =3D=3D CONTENT_OTHER)
- browser_window_convert_to_download(bw);
+ case CONTENT_MSG_LOADING:
+ assert(bw->loading_content =3D=3D c);
+
+ if (c->type =3D=3D CONTENT_OTHER)
+ browser_window_convert_to_download(bw);
#ifdef WITH_THEME_INSTALL
- else if (c->type =3D=3D CONTENT_THEME) {
- theme_install_start(c);
- bw->loading_content =3D 0;
- content_remove_user(c, browser_window_callback,
- (intptr_t) bw, 0);
- browser_window_stop_throbber(bw);
- }
+ else if (c->type =3D=3D CONTENT_THEME) {
+ theme_install_start(c);
+ bw->loading_content =3D 0;
+ content_remove_user(c, browser_window_callback,
+ (intptr_t) bw, 0);
+ browser_window_stop_throbber(bw);
+ }
#endif
- else {
- if (bw->frag_id)
- snprintf(url, sizeof url, "%s#%s",
- c->url, bw->frag_id);
- else
- snprintf(url, sizeof url, "%s",
- c->url);
- url[sizeof url - 1] =3D 0;
- gui_window_set_url(bw->window, url);
- bw->refresh_interval =3D -1;
- }
- break;
-
- case CONTENT_MSG_READY:
- assert(bw->loading_content =3D=3D c);
-
- if (bw->current_content) {
- if (bw->current_content->status =3D=3D
- CONTENT_STATUS_READY ||
- bw->current_content->status =3D=3D
- CONTENT_STATUS_DONE)
- content_close(bw->current_content);
- content_remove_user(bw->current_content,
- browser_window_callback,
- (intptr_t) bw, 0);
- }
- bw->current_content =3D c;
- bw->loading_content =3D NULL;
- browser_window_remove_caret(bw);
- bw->scrolling_box =3D NULL;
- gui_window_new_content(bw->window);
+ else {
if (bw->frag_id)
snprintf(url, sizeof url, "%s#%s",
- c->url, bw->frag_id);
+ c->url, bw->frag_id);
else
snprintf(url, sizeof url, "%s", c->url);
url[sizeof url - 1] =3D 0;
gui_window_set_url(bw->window, url);
- browser_window_update(bw, true);
- content_open(c, bw, 0, 0, 0, 0);
- browser_window_set_status(bw, c->status_message);
- if ((bw->history_add) && (bw->history)) {
- history_add(bw->history, c, bw->frag_id);
- if (urldb_add_url(c->url)) {
- urldb_set_url_title(c->url,
- c->title ? c->title : c->url);
- urldb_update_url_visit_data(c->url);
- urldb_set_url_content_type(c->url,
- c->type);
- /* This is safe as we've just
- * added the URL */
- global_history_add(
- urldb_get_url(c->url));
- }
- }
- switch (c->type) {
- case CONTENT_HTML:
- selection_init(bw->sel, bw->current_content->data.html.layout);
- break;
- case CONTENT_TEXTPLAIN:
- selection_init(bw->sel, NULL);
- break;
- default:
- break;
- }
- break;
-
- case CONTENT_MSG_DONE:
- assert(bw->current_content =3D=3D c);
-
- browser_window_update(bw, false);
- sprintf(status, messages_get("Complete"),
- ((float) (clock() - bw->time0)) /
- CLOCKS_PER_SEC);
- browser_window_set_status(bw, status);
- browser_window_stop_throbber(bw);
- history_update(bw->history, c);
- hotlist_visited(c);
- free(bw->referer);
- bw->referer =3D 0;
- if (bw->refresh_interval !=3D -1)
- schedule(bw->refresh_interval,
- browser_window_refresh, bw);
- break;
-
- case CONTENT_MSG_ERROR:
- browser_window_set_status(bw, data.error);
- warn_user(data.error, 0);
- if (c =3D=3D bw->loading_content)
- bw->loading_content =3D 0;
- else if (c =3D=3D bw->current_content) {
- bw->current_content =3D 0;
- browser_window_remove_caret(bw);
- bw->scrolling_box =3D NULL;
- selection_init(bw->sel, NULL);
- }
- browser_window_stop_throbber(bw);
- free(bw->referer);
- bw->referer =3D 0;
- break;
-
- case CONTENT_MSG_STATUS:
- browser_window_set_status(bw, c->status_message);
- break;
-
- case CONTENT_MSG_REDIRECT:
+ bw->refresh_interval =3D -1;
+ }
+ break;
+
+ case CONTENT_MSG_READY:
+ assert(bw->loading_content =3D=3D c);
+
+ if (bw->current_content) {
+ if (bw->current_content->status =3D=3D
+ CONTENT_STATUS_READY ||
+ bw->current_content->status =3D=3D
+ CONTENT_STATUS_DONE)
+ content_close(bw->current_content);
+ content_remove_user(bw->current_content,
+ browser_window_callback,
+ (intptr_t) bw, 0);
+ }
+ bw->current_content =3D c;
+ bw->loading_content =3D NULL;
+ browser_window_remove_caret(bw);
+ bw->scrolling_box =3D NULL;
+ gui_window_new_content(bw->window);
+ if (bw->frag_id)
+ snprintf(url, sizeof url, "%s#%s", c->url, bw->frag_id);
+ else
+ snprintf(url, sizeof url, "%s", c->url);
+ url[sizeof url - 1] =3D 0;
+ gui_window_set_url(bw->window, url);
+ browser_window_update(bw, true);
+ content_open(c, bw, 0, 0, 0, 0);
+ browser_window_set_status(bw, c->status_message);
+
+ /* history */
+ if (bw->history_add && bw->history) {
+ history_add(bw->history, c, bw->frag_id);
+ if (urldb_add_url(c->url)) {
+ urldb_set_url_title(c->url,
+ c->title ? c->title : c->url);
+ urldb_update_url_visit_data(c->url);
+ urldb_set_url_content_type(c->url,
+ c->type);
+ /* This is safe as we've just
+ * added the URL */
+ global_history_add(
+ urldb_get_url(c->url));
+ }
+ }
+
+ /* text selection */
+ if (c->type =3D=3D CONTENT_HTML)
+ selection_init(bw->sel,
+ bw->current_content->data.html.layout);
+ if (c->type =3D=3D CONTENT_TEXTPLAIN)
+ selection_init(bw->sel, NULL);
+
+ /* frames */
+ if (c->type =3D=3D CONTENT_HTML && c->data.html.frameset)
+ browser_window_create_frameset(bw,
+ c->data.html.frameset);
+ if (c->type =3D=3D CONTENT_HTML && c->data.html.iframe)
+ browser_window_create_iframes(bw, c->data.html.iframe);
+
+ break;
+
+ case CONTENT_MSG_DONE:
+ assert(bw->current_content =3D=3D c);
+
+ browser_window_update(bw, false);
+ sprintf(status, messages_get("Complete"),
+ ((float) (clock() - bw->time0)) /
+ CLOCKS_PER_SEC);
+ browser_window_set_status(bw, status);
+ browser_window_stop_throbber(bw);
+ history_update(bw->history, c);
+ hotlist_visited(c);
+ free(bw->referer);
+ bw->referer =3D 0;
+ if (bw->refresh_interval !=3D -1)
+ schedule(bw->refresh_interval,
+ browser_window_refresh, bw);
+ break;
+
+ case CONTENT_MSG_ERROR:
+ browser_window_set_status(bw, data.error);
+ warn_user(data.error, 0);
+ if (c =3D=3D bw->loading_content)
bw->loading_content =3D 0;
- browser_window_set_status(bw,
- messages_get("Redirecting"));
- /* the spec says nothing about referrers and
- * redirects =3D> follow Mozilla and preserve the
- * referer across the redirect */
- browser_window_go_post(bw, data.redirect, 0, 0,
- bw->history_add, bw->referer,
- bw->download);
- break;
-
- case CONTENT_MSG_REFORMAT:
- if (c =3D=3D bw->current_content &&
- c->type =3D=3D CONTENT_HTML) {
- /* box tree may have changed, need to relabel */
- selection_reinit(bw->sel, c->data.html.layout);
- }
- if (bw->move_callback)
- bw->move_callback(bw, bw->caret_p);
- browser_window_update(bw, false);
- break;
-
- case CONTENT_MSG_REDRAW:
- gui_window_update_box(bw->window, &data);
- break;
-
- case CONTENT_MSG_NEWPTR:
- bw->loading_content =3D c;
- break;
+ else if (c =3D=3D bw->current_content) {
+ bw->current_content =3D 0;
+ browser_window_remove_caret(bw);
+ bw->scrolling_box =3D NULL;
+ selection_init(bw->sel, NULL);
+ }
+ browser_window_stop_throbber(bw);
+ free(bw->referer);
+ bw->referer =3D 0;
+ break;
+
+ case CONTENT_MSG_STATUS:
+ browser_window_set_status(bw, c->status_message);
+ break;
+
+ case CONTENT_MSG_REDIRECT:
+ bw->loading_content =3D 0;
+ browser_window_set_status(bw,
+ messages_get("Redirecting"));
+ /* the spec says nothing about referrers and
+ * redirects =3D> follow Mozilla and preserve the
+ * referer across the redirect */
+ browser_window_go_post(bw, data.redirect, 0, 0,
+ bw->history_add, bw->referer,
+ bw->download);
+ break;
+
+ case CONTENT_MSG_REFORMAT:
+ if (c =3D=3D bw->current_content &&
+ c->type =3D=3D CONTENT_HTML) {
+ /* box tree may have changed, need to relabel */
+ selection_reinit(bw->sel, c->data.html.layout);
+ }
+ if (bw->move_callback)
+ bw->move_callback(bw, bw->caret_p);
+ browser_window_update(bw, false);
+ break;
+
+ case CONTENT_MSG_REDRAW:
+ gui_window_update_box(bw->window, &data);
+ break;
+
+ case CONTENT_MSG_NEWPTR:
+ bw->loading_content =3D c;
+ break;
=20
#ifdef WITH_AUTH
- case CONTENT_MSG_AUTH:
- gui_401login_open(bw, c, data.auth_realm);
- if (c =3D=3D bw->loading_content)
- bw->loading_content =3D 0;
- else if (c =3D=3D bw->current_content) {
- bw->current_content =3D 0;
- browser_window_remove_caret(bw);
- bw->scrolling_box =3D NULL;
- selection_init(bw->sel, NULL);
- }
- browser_window_stop_throbber(bw);
- free(bw->referer);
- bw->referer =3D 0;
- break;
+ case CONTENT_MSG_AUTH:
+ gui_401login_open(bw, c, data.auth_realm);
+ if (c =3D=3D bw->loading_content)
+ bw->loading_content =3D 0;
+ else if (c =3D=3D bw->current_content) {
+ bw->current_content =3D 0;
+ browser_window_remove_caret(bw);
+ bw->scrolling_box =3D NULL;
+ selection_init(bw->sel, NULL);
+ }
+ browser_window_stop_throbber(bw);
+ free(bw->referer);
+ bw->referer =3D 0;
+ break;
#endif
=20
#ifdef WITH_SSL
- case CONTENT_MSG_SSL:
- gui_cert_verify(bw, c, data.ssl.certs, data.ssl.num);
- if (c =3D=3D bw->loading_content)
- bw->loading_content =3D 0;
- else if (c =3D=3D bw->current_content) {
- bw->current_content =3D 0;
- browser_window_remove_caret(bw);
- bw->scrolling_box =3D NULL;
- selection_init(bw->sel, NULL);
- }
- browser_window_stop_throbber(bw);
- free(bw->referer);
- bw->referer =3D 0;
- break;
+ case CONTENT_MSG_SSL:
+ gui_cert_verify(bw, c, data.ssl.certs, data.ssl.num);
+ if (c =3D=3D bw->loading_content)
+ bw->loading_content =3D 0;
+ else if (c =3D=3D bw->current_content) {
+ bw->current_content =3D 0;
+ browser_window_remove_caret(bw);
+ bw->scrolling_box =3D NULL;
+ selection_init(bw->sel, NULL);
+ }
+ browser_window_stop_throbber(bw);
+ free(bw->referer);
+ bw->referer =3D 0;
+ break;
#endif
=20
- case CONTENT_MSG_REFRESH:
- bw->refresh_interval =3D data.delay * 100;
- break;
-
- default:
- assert(0);
+ case CONTENT_MSG_REFRESH:
+ bw->refresh_interval =3D data.delay * 100;
+ break;
+
+ default:
+ assert(0);
}
}
=20
@@ -1437,6 +865,64 @@
=20
free(bw->name);
free(bw->frag_id);
+}
+
+
+/**
+ * Returns the browser window that is responsible for the child.
+ *
+ * \param bw The browser window to find the owner of
+ * \return the browser window's owner
+ */
+
+struct browser_window *browser_window_owner(struct browser_window *bw)
+{
+ /* an iframe's parent is just the parent window */
+ if (bw->browser_window_type =3D=3D BROWSER_WINDOW_IFRAME)
+ return bw->parent;
+
+ /* the parent of a frameset is either a NORMAL window or an IFRAME */
+ while (bw->parent) {
+ switch (bw->browser_window_type) {
+ case BROWSER_WINDOW_NORMAL:
+ case BROWSER_WINDOW_IFRAME:
+ return bw;
+ case BROWSER_WINDOW_FRAME:
+ case BROWSER_WINDOW_FRAMESET:
+ bw =3D bw->parent;
+ break;
+ }
+ }
+ return bw;
+}
+
+
+/**
+ * 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)
+ */
+
+void browser_window_set_scale(struct browser_window *bw, float scale, bool=
all) {
+ while (bw->parent && all)
+ bw =3D bw->parent;
+ browser_window_set_scale_internal(bw, scale);
+ if (bw->parent)
+ bw =3D bw->parent;
+ browser_window_recalculate_frameset(bw);
+}
+
+void browser_window_set_scale_internal(struct browser_window *bw, float sc=
ale) {
+ int i;
+
+ gui_window_set_scale(bw->window, scale);
+
+ for (i =3D 0; i < (bw->cols * bw->rows); i++)
+ browser_window_set_scale_internal(&bw->children[i], scale);
+ for (i =3D 0; i < bw->iframe_count; i++)
+ browser_window_set_scale_internal(&bw->iframes[i], scale);
}
=20
=20
@@ -1990,107 +1476,6 @@
browser_window_set_pointer(bw->window, pointer);
}
=20
-bool browser_window_resize_frames(struct browser_window *bw, browser_mouse=
_state mouse, int x, int y,
- gui_pointer_shape *pointer, const char **status, bool *action) {
- bool left, right, up, down;
- int i, resize_margin;
-
- if ((x < bw->x0) || (x > bw->x1) || (y < bw->y0) || (y > bw->y1))
- return false;
-
- if ((!bw->no_resize) && (bw->parent)) {
- resize_margin =3D FRAME_RESIZE;
- if (resize_margin * 2 > (bw->x1 - bw->x0))
- resize_margin =3D (bw->x1 - bw->x0) / 2;
- left =3D (x < bw->x0 + resize_margin);
- right =3D (x > bw->x1 - resize_margin);
- resize_margin =3D FRAME_RESIZE;
- if (resize_margin * 2 > (bw->y1 - bw->y0))
- resize_margin =3D (bw->y1 - bw->y0) / 2;
- up =3D (y < bw->y0 + resize_margin);
- down =3D (y > bw->y1 - resize_margin);
-
- /* check if the edges can actually be moved */
- if (left || right || up || down) {
- int row =3D -1, col =3D -1;
- switch (bw->browser_window_type) {
- case BROWSER_WINDOW_NORMAL:
- case BROWSER_WINDOW_IFRAME:
- assert(0);
- break;
- case BROWSER_WINDOW_FRAME:
- case BROWSER_WINDOW_FRAMESET:
- assert(bw->parent);
- break;
- }
- for (i =3D 0; i < (bw->parent->cols * bw->parent->rows); i++) {
- if (&bw->parent->children[i] =3D=3D bw) {
- col =3D i % bw->parent->cols;
- row =3D i / bw->parent->cols;
- }
- }
- assert((row >=3D 0) && (col >=3D 0));
-
- left &=3D (col > 0);
- right &=3D (col < bw->parent->cols - 1) & (!left);
- up &=3D (row > 0);
- down &=3D (row < bw->parent->rows - 1) & (!up);
- }
-
- if (left || right || up || down) {
- if (left) {
- if (down)
- *pointer =3D GUI_POINTER_LD;
- else if (up)
- *pointer =3D GUI_POINTER_LU;
- else
- *pointer =3D GUI_POINTER_LEFT;
- } else if (right) {
- if (down)
- *pointer =3D GUI_POINTER_RD;
- else if (up)
- *pointer =3D GUI_POINTER_RU;
- else
- *pointer =3D GUI_POINTER_RIGHT;
- } else if (up) {
- *pointer =3D GUI_POINTER_UP;
- } else {
- *pointer =3D GUI_POINTER_DOWN;
- }
- if (mouse & (BROWSER_MOUSE_DRAG_1 | BROWSER_MOUSE_DRAG_2)) {
- bw->drag_type =3D DRAGGING_FRAME;
- bw->drag_start_x =3D x;
- bw->drag_start_y =3D y;
- bw->drag_resize_left =3D left;
- bw->drag_resize_right =3D right;
- bw->drag_resize_up =3D up;
- bw->drag_resize_down =3D down;
- gui_window_frame_resize_start(bw->window);
-
- *status =3D messages_get("FrameDrag");
- *action =3D true;
- }
- return true;
- }
- }
-
- if (bw->children) {
- for (i =3D 0; i < (bw->cols * bw->rows); i++)
- if (browser_window_resize_frames(&bw->children[i], mouse, x, y, pointer=
, status,
- action))
- return true;
- }
- if (bw->iframes) {
- for (i =3D 0; i < bw->iframe_count; i++)
- if (browser_window_resize_frames(&bw->iframes[i], mouse, x, y, pointer,=
status,
- action))
- return true;
- }
- return false;
-}
-
-
-
=20
/**
* Handle mouse clicks and movements in a TEXTPLAIN content window.
Modified: trunk/netsurf/desktop/browser.h
URL: http://svn.semichrome.net/trunk/netsurf/desktop/browser.h?rev=3D3070&r=
1=3D3069&r2=3D3070&view=3Ddiff
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- trunk/netsurf/desktop/browser.h (original)
+++ trunk/netsurf/desktop/browser.h Sun Nov 26 20:11:20 2006
@@ -182,23 +182,17 @@
=20
struct browser_window * browser_window_create(const char *url,
struct browser_window *clone, char *referer, bool history_add);
-struct browser_window * browser_window_owner(struct browser_window *bw);
void browser_window_go(struct browser_window *bw, const char *url,
char *referer, bool history_add);
void browser_window_go_post(struct browser_window *bw, const char *url,
char *post_urlenc,
struct form_successful_control *post_multipart,
bool history_add, char *referer, bool download);
+void browser_window_update(struct browser_window *bw, bool scroll_to_top);
void browser_window_stop(struct browser_window *bw);
void browser_window_reload(struct browser_window *bw, bool all);
void browser_window_destroy(struct browser_window *bw);
-void browser_window_update(struct browser_window *bw, bool scroll_to_top);
-void browser_window_create_iframes(struct browser_window *bw,
- struct content_html_iframe *iframe);
-void browser_window_recalculate_iframes(struct browser_window *bw);
-void browser_window_create_frameset(struct browser_window *bw,
- struct content_html_frames *frameset);
-void browser_window_recalculate_frameset(struct browser_window *bw);
+struct browser_window * browser_window_owner(struct browser_window *bw);
void browser_window_set_scale(struct browser_window *bw, float scale, bool=
all);
=20
void browser_window_mouse_click(struct browser_window *bw,
Added: trunk/netsurf/desktop/frames.c
URL: http://svn.semichrome.net/trunk/netsurf/desktop/frames.c?rev=3D3070&vi=
ew=3Dauto
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- trunk/netsurf/desktop/frames.c (added)
+++ trunk/netsurf/desktop/frames.c Sun Nov 26 20:11:20 2006
@@ -1,0 +1,662 @@
+/*
+ * This file is part of NetSurf, http://netsurf.sourceforge.net/
+ * Licensed under the GNU General Public License,
+ * http://www.opensource.org/licenses/gpl-license
+ * Copyright 2006 Richard Wilson <info@...>
+ */
+
+/** \file
+ * Frame and frameset creation and manipulation (implementation).
+ */
+
+#include <assert.h>
+#include <ctype.h>
+#include <limits.h>
+#include <stdbool.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+#include "netsurf/utils/config.h"
+#include "netsurf/desktop/browser.h"
+#include "netsurf/desktop/frames.h"
+#include "netsurf/desktop/history_core.h"
+#include "netsurf/desktop/gui.h"
+#include "netsurf/desktop/selection.h"
+#include "netsurf/utils/log.h"
+#include "netsurf/utils/messages.h"
+#include "netsurf/utils/utils.h"
+
+/** maximum frame resize margin */
+#define FRAME_RESIZE 6
+
+/** browser window which is being redrawn. Valid only during redraw. */
+struct browser_window *current_redraw_browser;
+
+/** fake content for <a> being saved as a link */
+struct content browser_window_href_content;
+
+static bool browser_window_resolve_frame_dimension(struct browser_window *=
bw,
+ struct browser_window *sibling, int x, int y, bool width,
+ bool height);
+
+
+/**
+ * Create and open a iframes for a browser window.
+ *
+ * \param bw The browser window to create iframes for
+ * \param iframe The iframes to create
+ */
+
+void browser_window_create_iframes(struct browser_window *bw,
+ struct content_html_iframe *iframe) {
+ struct browser_window *window;
+ struct content_html_iframe *cur;
+ int iframes =3D 0;
+ int index;
+
+ for (cur =3D iframe; cur; cur =3D cur->next)
+ iframes++;
+ bw->iframes =3D calloc(iframes, sizeof(*bw));
+ if (!bw->iframes)
+ return;
+ bw->iframe_count =3D iframes;
+
+ index =3D 0;
+ for (cur =3D iframe; cur; cur =3D cur->next) {
+ window =3D &(bw->iframes[index++]);
+
+ /* content */
+ window->history =3D history_create();
+ window->sel =3D selection_create(window);
+ window->refresh_interval =3D -1;
+
+ /* window characteristics */
+ window->drag_type =3D DRAGGING_NONE;
+ window->browser_window_type =3D BROWSER_WINDOW_IFRAME;
+ window->scrolling =3D cur->scrolling;
+ window->border =3D cur->border;
+ window->border_colour =3D cur->border_colour;
+ window->no_resize =3D true;
+ window->margin_width =3D cur->margin_width;
+ window->margin_height =3D cur->margin_height;
+ if (cur->name)
+ window->name =3D strdup(cur->name);
+
+ /* linking */
+ window->box =3D cur->box;
+ window->parent =3D bw;
+
+ /* gui window */
+ window->window =3D gui_create_browser_window(window, bw);
+ }
+
+ /* calculate dimensions */
+ gui_window_update_extent(bw->window);
+ browser_window_recalculate_iframes(bw);
+
+ index =3D 0;
+ for (cur =3D iframe; cur; cur =3D cur->next) {
+ window =3D &(bw->iframes[index++]);
+ if (cur->url)
+ browser_window_go(window, cur->url, NULL, true);
+ }
+}
+
+
+/**
+ * Recalculate iframe positions following a resize.
+ *
+ * \param bw The browser window to reposition iframes for
+ */
+
+void browser_window_recalculate_iframes(struct browser_window *bw) {
+ struct browser_window *window;
+ struct rect rect;
+ int bw_width, bw_height;
+ int index;
+
+ assert(bw);
+
+ /* update window dimensions */
+ gui_window_get_dimensions(bw->window, &bw_width, &bw_height, false);
+ if (!bw->parent) {
+ bw->x0 =3D 0;
+ bw->y0 =3D 0;
+ bw->x1 =3D bw_width;
+ bw->y1 =3D bw_height;
+ }
+
+ for (index =3D 0; index < bw->iframe_count; index++) {
+ window =3D &(bw->iframes[index]);
+ box_bounds(window->box, &rect);
+ gui_window_position_frame(window->window, rect.x0, rect.y0,
+ rect.x1, rect.y1);
+ }
+}
+
+
+/**
+ * Create and open a frameset for a browser window.
+ *
+ * \param bw The browser window to create the frameset for
+ * \param iframe The frameset to create
+ */
+
+void browser_window_create_frameset(struct browser_window *bw,
+ struct content_html_frames *frameset) {
+ int row, col, index;
+ struct content_html_frames *frame;
+ struct browser_window *window;
+
+ /* we use a 3 stage approach such that the content is initially formatted=
to the
+ * correct frameset dimensions */
+ assert(bw && frameset);
+
+ /* create children */
+ assert(bw->children =3D=3D NULL);
+ assert(frameset->cols + frameset->rows !=3D 0);
+
+ bw->children =3D calloc((frameset->cols * frameset->rows), sizeof(*bw));
+ if (!bw->children)
+ return;
+ bw->cols =3D frameset->cols;
+ bw->rows =3D frameset->rows;
+ for (row =3D 0; row < bw->rows; row++) {
+ for (col =3D 0; col < bw->cols; col++) {
+ index =3D (row * bw->cols) + col;
+ frame =3D &frameset->children[index];
+ window =3D &bw->children[index];
+
+ /* content */
+ window->history =3D history_create();
+ window->sel =3D selection_create(window);
+ window->refresh_interval =3D -1;
+
+ /* window characteristics */
+ window->drag_type =3D DRAGGING_NONE;
+ if (frame->children)
+ window->browser_window_type =3D BROWSER_WINDOW_FRAMESET;
+ else
+ window->browser_window_type =3D BROWSER_WINDOW_FRAME;
+ window->scrolling =3D frame->scrolling;
+ window->border =3D frame->border;
+ window->border_colour =3D frame->border_colour;
+ window->no_resize =3D frame->no_resize;
+ window->frame_width =3D frame->width;
+ window->frame_height =3D frame->height;
+ window->margin_width =3D frame->margin_width;
+ window->margin_height =3D frame->margin_height;
+ if (frame->name)
+ window->name =3D strdup(frame->name);
+
+ /* linking */
+ window->parent =3D bw;
+
+ /* gui window */
+ window->window =3D gui_create_browser_window(window, bw);
+ if (frame->children)
+ browser_window_create_frameset(window, frame);
+ }
+ }
+
+ /* calculate dimensions */
+ gui_window_update_extent(bw->window);
+ browser_window_recalculate_frameset(bw);
+
+ /* launch content */
+ for (row =3D 0; row < bw->rows; row++) {
+ for (col =3D 0; col < bw->cols; col++) {
+ index =3D (row * bw->cols) + col;
+ frame =3D &frameset->children[index];
+ window =3D &bw->children[index];
+
+ if (frame->url)
+ browser_window_go(window, frame->url, NULL, true);
+ }
+ }
+}
+
+
+/**
+ * Recalculate frameset positions following a resize.
+ *
+ * \param bw The browser window to reposition framesets for
+ */
+
+void browser_window_recalculate_frameset(struct browser_window *bw) {
+ int widths[bw->cols][bw->rows];
+ int heights[bw->cols][bw->rows];
+ int bw_width, bw_height;
+ int avail_width, avail_height;
+ int row, row2, col, index;
+ struct browser_window *window;
+ float relative;
+ int size, extent;
+ int x, y;
+
+ assert(bw);
+
+ /* window dimensions */
+ if (!bw->parent) {
+ gui_window_get_dimensions(bw->window, &bw_width, &bw_height, false);
+ bw->x0 =3D 0;
+ bw->y0 =3D 0;
+ bw->x1 =3D bw_width;
+ bw->y1 =3D bw_height;
+ } else {
+ bw_width =3D bw->x1 - bw->x0;
+ bw_height =3D bw->y1 - bw->y0;
+ }
+ bw_width++;
+ bw_height++;
+
+ /* widths */
+ for (row =3D 0; row < bw->rows; row++) {
+ avail_width =3D bw_width;
+ relative =3D 0;
+ for (col =3D 0; col < bw->cols; col++) {
+ index =3D (row * bw->cols) + col;
+ window =3D &bw->children[index];
+
+ switch (window->frame_width.unit) {
+ case FRAME_DIMENSION_PIXELS:
+ widths[col][row] =3D window->frame_width.value *
+ gui_window_get_scale(window->window);
+ if (window->border) {
+ if (col !=3D 0)
+ widths[col][row] +=3D 1;
+ if (col !=3D bw->cols - 1)
+ widths[col][row] +=3D 1;
+ }
+ break;
+ case FRAME_DIMENSION_PERCENT:
+ widths[col][row] =3D bw_width * window->frame_width.value / 100;
+ break;
+ case FRAME_DIMENSION_RELATIVE:
+ widths[col][row] =3D 0;
+ relative +=3D window->frame_width.value;
+ break;
+ }
+ avail_width -=3D widths[col][row];
+ }
+
+ /* try to distribute remainder to relative values in preference */
+ if ((relative > 0) && (avail_width > 0)) {
+ for (col =3D 0; col < bw->cols; col++) {
+ index =3D (row * bw->cols) + col;
+ window =3D &bw->children[index];
+
+ if (window->frame_width.unit =3D=3D FRAME_DIMENSION_RELATIVE) {
+ size =3D avail_width * window->frame_width.value / relative;
+ avail_width -=3D size;
+ relative -=3D window->frame_width.value;
+ widths[col][row] +=3D size;
+ }
+ }
+ } else if (bw_width !=3D avail_width) {
+ /* proportionally distribute error */
+ extent =3D bw_width - avail_width;
+ for (col =3D 0; col < bw->cols; col++) {
+ index =3D (row * bw->cols) + col;
+ window =3D &bw->children[index];
+
+ if (col =3D=3D bw->cols - 1) {
+ widths[col][row] =3D bw_width;
+ } else {
+ size =3D bw_width * widths[col][row] / extent;
+ bw_width -=3D size;
+ extent -=3D widths[col][row];
+ widths[col][row] =3D size;
+ }
+ }
+ }
+ }
+
+ /* heights */
+ for (col =3D 0; col < bw->cols; col++) {
+ avail_height =3D bw_height;
+ relative =3D 0;
+ for (row =3D 0; row < bw->rows; row++) {
+ index =3D (row * bw->cols) + col;
+ window =3D &bw->children[index];
+
+ switch (window->frame_height.unit) {
+ case FRAME_DIMENSION_PIXELS:
+ heights[col][row] =3D window->frame_height.value *
+ gui_window_get_scale(window->window);
+ if (window->border) {
+ if (row !=3D 0)
+ heights[col][row] +=3D 1;
+ if (row !=3D bw->rows - 1)
+ heights[col][row] +=3D 1;
+ }
+ break;
+ case FRAME_DIMENSION_PERCENT:
+ heights[col][row] =3D bw_height *
+ window->frame_height.value / 100;
+ break;
+ case FRAME_DIMENSION_RELATIVE:
+ heights[col][row] =3D 0;
+ relative +=3D window->frame_height.value;
+ break;
+ }
+ avail_height -=3D heights[col][row];
+ }
+
+ if (avail_height =3D=3D 0)
+ continue;
+
+ /* try to distribute remainder to relative values in preference */
+ if ((relative > 0) && (avail_height > 0)) {
+ for (row =3D 0; row < bw->rows; row++) {
+ index =3D (row * bw->cols) + col;
+ window =3D &bw->children[index];
+
+ if (window->frame_height.unit =3D=3D FRAME_DIMENSION_RELATIVE) {
+ size =3D avail_height * window->frame_height.value / relative;
+ avail_height -=3D size;
+ relative -=3D window->frame_height.value;
+ heights[col][row] +=3D size;
+ }
+ }
+ } else if (bw_height !=3D avail_height) {
+ /* proportionally distribute error */
+ extent =3D bw_height - avail_height;
+ for (row =3D 0; row < bw->rows; row++) {
+ index =3D (row * bw->cols) + col;
+ window =3D &bw->children[index];
+
+ if (row =3D=3D bw->rows - 1) {
+ heights[col][row] =3D bw_height;
+ } else {
+ size =3D bw_height * heights[col][row] / extent;
+ bw_height -=3D size;
+ extent -=3D heights[col][row];
+ heights[col][row] =3D size;
+ }
+ }
+ }
+ }
+
+ /* position frames and calculate children */
+ for (row =3D 0; row < bw->rows; row++) {
+ x =3D 0;
+ for (col =3D 0; col < bw->cols; col++) {
+ index =3D (row * bw->cols) + col;
+ window =3D &bw->children[index];
+
+ y =3D 0;
+ for (row2 =3D 0; row2 < row; row2++)
+ y+=3D heights[col][row2];
+ gui_window_position_frame(window->window, x, y,
+ x + widths[col][row] - 1,
+ y + heights[col][row] - 1);
+ x +=3D widths[col][row];
+ if (window->children)
+ browser_window_recalculate_frameset(window);
+ }
+ }
+}
+
+
+/**
+ * Resize a browser window that is a frame.
+ *
+ * \param bw The browser window to resize
+ */
+
+void browser_window_resize_frame(struct browser_window *bw, int x, int y) {
+ struct browser_window *parent;
+ struct browser_window *sibling;
+ int col =3D -1, row =3D -1, i;
+ bool change =3D false;
+
+ parent =3D bw->parent;
+ assert(parent);
+
+ /* get frame location */
+ for (i =3D 0; i < (parent->cols * parent->rows); i++) {
+ if (&parent->children[i] =3D=3D bw) {
+ col =3D i % parent->cols;
+ row =3D i / parent->cols;
+ }
+ }
+ assert((col >=3D 0) && (row >=3D 0));
+
+ sibling =3D NULL;
+ if (bw->drag_resize_left)
+ sibling =3D &parent->children[row * parent->cols + (col - 1)];
+ else if (bw->drag_resize_right)
+ sibling =3D &parent->children[row * parent->cols + (col + 1)];
+ if (sibling)
+ change |=3D browser_window_resolve_frame_dimension(bw, sibling, x, y, tr=
ue, false);
+
+ sibling =3D NULL;
+ if (bw->drag_resize_up)
+ sibling =3D &parent->children[(row - 1) * parent->cols + col];
+ else if (bw->drag_resize_down)
+ sibling =3D &parent->children[(row + 1) * parent->cols + col];
+ if (sibling)
+ change |=3D browser_window_resolve_frame_dimension(bw, sibling, x, y, fa=
lse, true);
+
+ if (change)
+ browser_window_recalculate_frameset(parent);
+}
+
+
+bool browser_window_resolve_frame_dimension(struct browser_window *bw, str=
uct browser_window *sibling,
+ int x, int y, bool width, bool height) {
+ int bw_dimension, sibling_dimension;
+ int bw_pixels, sibling_pixels;
+ struct frame_dimension *bw_d, *sibling_d;
+ float total_new;
+ int frame_size;
+
+ assert(!(width && height));
+
+ /* extend/shrink the box to the pointer */
+ if (width) {
+ if (bw->drag_resize_left)
+ bw_dimension =3D bw->x1 - x;
+ else
+ bw_dimension =3D x - bw->x0;
+ bw_pixels =3D (bw->x1 - bw->x0);
+ sibling_pixels =3D (sibling->x1 - sibling->x0);
+ bw_d =3D &bw->frame_width;
+ sibling_d =3D &sibling->frame_width;
+ frame_size =3D bw->parent->x1 - bw->parent->x0;
+ } else {
+ if (bw->drag_resize_up)
+ bw_dimension =3D bw->y1 - y;
+ else
+ bw_dimension =3D y - bw->y0;
+ bw_pixels =3D (bw->y1 - bw->y0);
+ sibling_pixels =3D (sibling->y1 - sibling->y0);
+ bw_d =3D &bw->frame_height;
+ sibling_d =3D &sibling->frame_height;
+ frame_size =3D bw->parent->y1 - bw->parent->y0;
+ }
+ sibling_dimension =3D bw_pixels + sibling_pixels - bw_dimension;
+
+ /* check for no change or no frame size*/
+ if ((bw_dimension =3D=3D bw_pixels) || (frame_size =3D=3D 0))
+ return false;
+ /* check for both being 0 */
+ total_new =3D bw_dimension + sibling_dimension;
+ if ((bw_dimension + sibling_dimension) =3D=3D 0)
+ return false;
+
+ /* our frame dimensions are now known to be:
+ *
+ * <-- frame_size --> [VISIBLE PIXELS]
+ * |<-- bw_pixels -->|<-- sibling_pixels -->| [VISIBLE PIXELS, BEFORE R=
ESIZE]
+ * |<-- bw_d->value-->|<-- sibling_d->value-->| [SPECIFIED UNITS, BEFORE =
RESIZE]
+ * |<--bw_dimension-->|<--sibling_dimension-->| [VISIBLE PIXELS, AFTER RE=
SIZE]
+ * |<-- total_new -->| [VISIBLE PIXELS, AFTER RE=
SIZE]
+ *
+ * when we resize, we must retain the original unit specification such th=
at any
+ * subsequent resizing of the parent window will recalculate the page as =
the
+ * author specified.
+ *
+ * if the units of both frames are the same then we can resize the values=
simply
+ * by updating the values to be a percentage of the original widths.
+ */
+ if (bw_d->unit =3D=3D sibling_d->unit) {
+ float total_specified =3D bw_d->value + sibling_d->value;
+ bw_d->value =3D (total_specified * bw_dimension) / total_new;
+ sibling_d->value =3D total_specified - bw_d->value;
+ return true;
+ }
+
+ /* if one of the sizes is relative then we don't alter the relative width=
and
+ * just let it reflow across. the non-relative (pixel/percentage) value c=
an
+ * simply be resolved to the specified width that will result in the requ=
ired
+ * dimension.
+ */
+ if (bw_d->unit =3D=3D FRAME_DIMENSION_RELATIVE) {
+ if ((sibling_pixels =3D=3D 0) && (bw_dimension =3D=3D 0))
+ return false;
+ if (sibling_d->value =3D=3D 0)
+ bw_d->value =3D 1;
+ if (sibling_pixels =3D=3D 0)
+ sibling_d->value =3D (sibling_d->value * bw_pixels) / bw_dimension;
+ else
+ sibling_d->value =3D
+ (sibling_d->value * sibling_dimension) / sibling_pixels;
+
+ /* todo: the availble resize may have changed, update the drag box */
+ return true;
+ } else if (sibling_d->unit =3D=3D FRAME_DIMENSION_RELATIVE) {
+ if ((bw_pixels =3D=3D 0) && (sibling_dimension =3D=3D 0))
+ return false;
+ if (bw_d->value =3D=3D 0)
+ bw_d->value =3D 1;
+ if (bw_pixels =3D=3D 0)
+ bw_d->value =3D (bw_d->value * sibling_pixels) / sibling_dimension;
+ else
+ bw_d->value =3D (bw_d->value * bw_dimension) / bw_pixels;
+
+ /* todo: the availble resize may have changed, update the drag box */
+ return true;
+ }
+
+ /* finally we have a pixel/percentage mix. unlike relative values, percen=
tages
+ * can easily be backwards-calculated as they can simply be scaled like p=
ixel
+ * values
+ */
+ if (bw_d->unit =3D=3D FRAME_DIMENSION_PIXELS) {
+ float total_specified =3D bw_d->value + frame_size * sibling_d->value / =
100;
+ bw_d->value =3D (total_specified * bw_dimension) / total_new;
+ sibling_d->value =3D (total_specified - bw_d->value) * 100 / frame_size;
+ return true;
+ } else if (sibling_d->unit =3D=3D FRAME_DIMENSION_PIXELS) {
+ float total_specified =3D bw_d->value * frame_size / 100 + sibling_d->va=
lue;
+ sibling_d->value =3D (total_specified * sibling_dimension) / total_new;
+ bw_d->value =3D (total_specified - sibling_d->value) * 100 / frame_size;
+ return true;
+ }
+ assert(!"Invalid frame dimension unit");
+ return false;
+}
+
+
+bool browser_window_resize_frames(struct browser_window *bw, browser_mouse=
_state mouse, int x, int y,
+ gui_pointer_shape *pointer, const char **status, bool *action) {
+ bool left, right, up, down;
+ int i, resize_margin;
+
+ if ((x < bw->x0) || (x > bw->x1) || (y < bw->y0) || (y > bw->y1))
+ return false;
+
+ if ((!bw->no_resize) && (bw->parent)) {
+ resize_margin =3D FRAME_RESIZE;
+ if (resize_margin * 2 > (bw->x1 - bw->x0))
+ resize_margin =3D (bw->x1 - bw->x0) / 2;
+ left =3D (x < bw->x0 + resize_margin);
+ right =3D (x > bw->x1 - resize_margin);
+ resize_margin =3D FRAME_RESIZE;
+ if (resize_margin * 2 > (bw->y1 - bw->y0))
+ resize_margin =3D (bw->y1 - bw->y0) / 2;
+ up =3D (y < bw->y0 + resize_margin);
+ down =3D (y > bw->y1 - resize_margin);
+
+ /* check if the edges can actually be moved */
+ if (left || right || up || down) {
+ int row =3D -1, col =3D -1;
+ switch (bw->browser_window_type) {
+ case BROWSER_WINDOW_NORMAL:
+ case BROWSER_WINDOW_IFRAME:
+ assert(0);
+ break;
+ case BROWSER_WINDOW_FRAME:
+ case BROWSER_WINDOW_FRAMESET:
+ assert(bw->parent);
+ break;
+ }
+ for (i =3D 0; i < (bw->parent->cols * bw->parent->rows); i++) {
+ if (&bw->parent->children[i] =3D=3D bw) {
+ col =3D i % bw->parent->cols;
+ row =3D i / bw->parent->cols;
+ }
+ }
+ assert((row >=3D 0) && (col >=3D 0));
+
+ left &=3D (col > 0);
+ right &=3D (col < bw->parent->cols - 1) & (!left);
+ up &=3D (row > 0);
+ down &=3D (row < bw->parent->rows - 1) & (!up);
+ }
+
+ if (left || right || up || down) {
+ if (left) {
+ if (down)
+ *pointer =3D GUI_POINTER_LD;
+ else if (up)
+ *pointer =3D GUI_POINTER_LU;
+ else
+ *pointer =3D GUI_POINTER_LEFT;
+ } else if (right) {
+ if (down)
+ *pointer =3D GUI_POINTER_RD;
+ else if (up)
+ *pointer =3D GUI_POINTER_RU;
+ else
+ *pointer =3D GUI_POINTER_RIGHT;
+ } else if (up) {
+ *pointer =3D GUI_POINTER_UP;
+ } else {
+ *pointer =3D GUI_POINTER_DOWN;
+ }
+ if (mouse & (BROWSER_MOUSE_DRAG_1 | BROWSER_MOUSE_DRAG_2)) {
+ bw->drag_type =3D DRAGGING_FRAME;
+ bw->drag_start_x =3D x;
+ bw->drag_start_y =3D y;
+ bw->drag_resize_left =3D left;
+ bw->drag_resize_right =3D right;
+ bw->drag_resize_up =3D up;
+ bw->drag_resize_down =3D down;
+ gui_window_frame_resize_start(bw->window);
+
+ *status =3D messages_get("FrameDrag");
+ *action =3D true;
+ }
+ return true;
+ }
+ }
+
+ if (bw->children) {
+ for (i =3D 0; i < (bw->cols * bw->rows); i++)
+ if (browser_window_resize_frames(&bw->children[i], mouse, x, y, pointer=
, status,
+ action))
+ return true;
+ }
+ if (bw->iframes) {
+ for (i =3D 0; i < bw->iframe_count; i++)
+ if (browser_window_resize_frames(&bw->iframes[i], mouse, x, y, pointer,=
status,
+ action))
+ return true;
+ }
+ return false;
+}
+
Added: trunk/netsurf/desktop/frames.h
URL: http://svn.semichrome.net/trunk/netsurf/desktop/frames.h?rev=3D3070&vi=
ew=3Dauto
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- trunk/netsurf/desktop/frames.h (added)
+++ trunk/netsurf/desktop/frames.h Sun Nov 26 20:11:20 2006
@@ -1,0 +1,30 @@
+/*
+ * This file is part of NetSurf, http://netsurf.sourceforge.net/
+ * Licensed under the GNU General Public License,
+ * http://www.opensource.org/licenses/gpl-license
+ * Copyright 2006 Richard Wilson <info@...>
+ */
+
+/** \file
+ * Frame and frameset creation and manipulation (interface).
+ */
+
+#ifndef _NETSURF_DESKTOP_FRAMES_H_
+#define _NETSURF_DESKTOP_FRAMES_H_
+
+#include "netsurf/desktop/browser.h"
+#include "netsurf/desktop/gui.h"
+
+
+void browser_window_create_iframes(struct browser_window *bw,
+ struct content_html_iframe *iframe);
+void browser_window_recalculate_iframes(struct browser_window *bw);
+void browser_window_create_frameset(struct browser_window *bw,
+ struct content_html_frames *frameset);
+void browser_window_recalculate_frameset(struct browser_window *bw);
+bool browser_window_resize_frames(struct browser_window *bw,
+ browser_mouse_state mouse, int x, int y,
+ gui_pointer_shape *pointer, const char **status, bool *action);
+void browser_window_resize_frame(struct browser_window *bw, int x, int y);
+
+#endif
Modified: trunk/netsurf/render/html.c
URL: http://svn.semichrome.net/trunk/netsurf/render/html.c?rev=3D3070&r1=3D=
3069&r2=3D3070&view=3Ddiff
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- trunk/netsurf/render/html.c (original)
+++ trunk/netsurf/render/html.c Sun Nov 26 20:11:20 2006
@@ -1563,11 +1563,6 @@
c->data.html.object[i].box,
c->data.html.object[i].box->object_params);
}
-
- if (c->data.html.frameset)
- browser_window_create_frameset(bw, c->data.html.frameset);
- if (c->data.html.iframe)
- browser_window_create_iframes(bw, c->data.html.iframe);
}
=20
=20
|