[project @ 2003-12-21 22:10:15 by jmb]

Tidy up and integrate frames code. Still incomplete.

svn path=/import/netsurf/; revision=439
This commit is contained in:
John Mark Bell 2003-12-21 22:10:15 +00:00
parent 96bbdbc7ab
commit adc3476157
9 changed files with 282 additions and 322 deletions

View File

@ -110,7 +110,7 @@ void browser_window_forward(struct browser_window* bw)
}
struct browser_window* create_browser_window(int flags, int width, int height)
struct browser_window* create_browser_window(int flags, int width, int height, struct browser_window *parent)
{
struct browser_window* bw;
bw = (struct browser_window*) xcalloc(1, sizeof(struct browser_window));
@ -130,7 +130,20 @@ struct browser_window* create_browser_window(int flags, int width, int height)
bw->url = NULL;
bw->caret_callback = 0;
bw->parent = parent;
if (bw->parent != NULL) {
bw->parent->children = xrealloc(bw->parent->children,
(bw->parent->no_children+1) *
sizeof(struct browser_window));
bw->parent->children[bw->parent->no_children] = bw;
bw->parent->no_children++;
bw->window = NULL; /* This is filled in by frame_add_instance */
}
else {
bw->window = gui_create_browser_window(bw);
}
return bw;
}
@ -141,11 +154,30 @@ void browser_window_set_status(struct browser_window* bw, const char* text)
gui_window_set_status(bw->window, text);
}
void browser_window_destroy(struct browser_window* bw)
void browser_window_destroy(struct browser_window* bw, bool self)
{
unsigned int i;
LOG(("bw = %p", bw));
assert(bw != 0);
if (bw->no_children == 0 && bw->parent != NULL) { /* leaf node -> delete */
if (bw->current_content != NULL) {
if (bw->current_content->status == CONTENT_STATUS_DONE)
content_remove_instance(bw->current_content, bw, 0, 0, 0, &bw->current_content_state);
login_list_remove(bw->current_content->url);
}
xfree(bw->url);
xfree(bw);
return;
}
for (i=0; i!=bw->no_children; i++) { /* non-leaf node -> kill children */
browser_window_destroy(bw->children[i], true);
}
/* all children killed -> remove this node */
if (self || bw->parent != NULL) {
if (bw->current_content != NULL) {
if (bw->current_content->status == CONTENT_STATUS_DONE)
content_remove_instance(bw->current_content, bw, 0, 0, 0, &bw->current_content_state);
@ -158,9 +190,13 @@ void browser_window_destroy(struct browser_window* bw)
xfree(bw->url);
gui_window_destroy(bw->window);
xfree(bw->children);
xfree(bw);
}
else {
bw->no_children = 0;
xfree(bw->children);
}
LOG(("end"));
}
@ -173,6 +209,9 @@ void browser_window_open_location_historical(struct browser_window* bw,
assert(bw != 0 && url != 0);
if (bw->url != NULL)
browser_window_destroy(bw, false);
if ((li = login_list_get(url)) == NULL) {
if (bw->current_content != NULL) {
@ -1186,7 +1225,7 @@ void browser_window_follow_link(struct browser_window* bw,
char *url = url_join((char*) click_boxes[i].box->href, bw->url);
struct browser_window* bw_new;
bw_new = create_browser_window(browser_TITLE | browser_TOOLBAR
| browser_SCROLL_X_ALWAYS | browser_SCROLL_Y_ALWAYS, 640, 480);
| browser_SCROLL_X_ALWAYS | browser_SCROLL_Y_ALWAYS, 640, 480, NULL);
gui_window_show(bw_new->window);
browser_window_open_location(bw_new, url);
free(url);

View File

@ -54,6 +54,10 @@ struct browser_window
void (*caret_callback)(struct browser_window *bw, char key, void *p);
void *caret_p;
struct browser_window *parent;
unsigned int no_children;
struct browser_window **children;
};
@ -88,8 +92,8 @@ struct box_selection
/* public functions */
struct browser_window* create_browser_window(int flags, int width, int height);
void browser_window_destroy(struct browser_window* bw);
struct browser_window* create_browser_window(int flags, int width, int height, struct browser_window *parent);
void browser_window_destroy(struct browser_window* bw, bool self);
void browser_window_open_location(struct browser_window* bw, const char* url);
void browser_window_open_location_historical(struct browser_window* bw,
const char* url, char *post_urlenc,

View File

@ -7,48 +7,181 @@
#include <stdbool.h>
#include "netsurf/desktop/browser.h"
#include "netsurf/desktop/gui.h"
#include "netsurf/riscos/frames.h"
#ifndef TEST
#include "netsurf/riscos/gui.h"
/*#ifndef TEST
# define NDEBUG
#endif
#endif*/
#include "netsurf/utils/log.h"
#include "netsurf/utils/utils.h"
#ifdef TEST
# include <stdio.h>
#endif
#include "oslib/os.h"
#include "oslib/wimp.h"
static struct frame_list fl = {0, 0, &fl, &fl};
static struct frame_list *flist = &fl;
void frame_add_instance_to_list(struct content *c, struct browser_window *parent, struct content *page, struct box *box, struct object_params *params, void **state, struct browser_window *bw, gui_window *g);
void frame_remove_instance_from_list(struct content *c);
struct frame_list *frame_get_instance_from_list(struct content *c);
/* -------------------------------------------------------------------- *
* List handling stuff *
* -------------------------------------------------------------------- */
void frame_add_instance(struct content *c, struct browser_window *parent,
struct content *page, struct box *box,
struct object_params *params, void **state)
{
wimp_window w;
struct browser_window *bw = NULL;
os_error *e;
gui_window *g = (gui_window*)xcalloc(1, sizeof(gui_window));
bw = create_browser_window(parent->flags, parent->format_width,
parent->format_height, parent);
w.visible.x0 = 346;
w.visible.x1 = 370;
w.visible.y0 = 664;
w.visible.y1 = 610;
w.xscroll = w.yscroll = 0;
w.next = wimp_TOP;
w.flags = wimp_WINDOW_NEW_FORMAT | wimp_WINDOW_MOVEABLE;
w.title_fg = wimp_COLOUR_TRANSPARENT;
w.title_bg = wimp_COLOUR_WHITE;
w.work_fg = wimp_COLOUR_VERY_LIGHT_GREY;
w.work_bg = wimp_COLOUR_RED;
w.scroll_outer = wimp_COLOUR_DARK_GREY;
w.scroll_inner = wimp_COLOUR_MID_LIGHT_GREY;
w.highlight_bg = wimp_COLOUR_CREAM;
w.extra_flags = 0;
w.extent.x0 = 0;
w.extent.y0 = -8192;
w.extent.x1 = 8192;
w.extent.y1 = 0;
w.title_flags = wimp_ICON_HCENTRED | wimp_ICON_VCENTRED;
w.work_flags = wimp_BUTTON_CLICK << wimp_ICON_BUTTON_TYPE_SHIFT;
w.xmin = 1;
w.ymin = 0;
w.icon_count = 0;
LOG(("Creating frame"));
e = xwimp_create_window(&w, &g->window);
if (e) {
LOG(("%s", e->errmess));
return;
}
g->type = GUI_BROWSER_WINDOW;
g->data.browser.bw = bw;
g->data.browser.toolbar = 0;
g->redraw_safety = SAFE;
g->data.browser.reformat_pending = false;
g->data.browser.old_width = 0;
bw->current_content = c;
bw->window = g;
LOG(("Adding to list"));
frame_add_instance_to_list(c, parent, page, box, params, state, bw, g);
LOG(("Done"));
}
void frame_remove_instance(struct content *c, struct browser_window *bw,
struct content *page, struct box *box,
struct object_params *params, void **state)
{
struct frame_list *f;
f = frame_get_instance_from_list(c);
wimp_close_window(f->g->window);
wimp_delete_window(f->g->window);
frame_remove_instance_from_list(c);
}
void frame_reshape_instance(struct content *c, struct browser_window *bw,
struct content *page, struct box *box,
struct object_params *params, void **state)
{
struct frame_list *f;
unsigned long x, y;
int x0, y1;
os_box b;
wimp_window_state s;
LOG(("Reshaping frame"));
f = frame_get_instance_from_list(c);
if (f == NULL) {
LOG(("Couldn't find frame"));
return;
}
s.w = bw->window->window;
wimp_get_window_state(&s);
LOG(("ParentWindow: [(%d,%d),(%d,%d)]", s.visible.x0, s.visible.y0,
s.visible.x1, s.visible.y1));
x0 = s.visible.x0 - s.xscroll;
y1 = s.visible.y1 - s.yscroll;
LOG(("%d,%d", x0, y1));
box_coords(box, &x, &y);
b.x0 = x0 + ((int)x << 1);
b.y1 = y1 - (((int)y << 1));
b.x1 = (b.x0 + (box->width << 1));
b.y0 = (b.y1 - (box->height << 1));
/*if(b.x1 > (s.visible.x1-s.xscroll)) {
b.x1 -= 16;
}*/
s.w = f->g->window;
s.visible = b;
LOG(("Opening frame window : [(%d,%d),(%d,%d)]",b.x0,b.y0,b.x1,b.y1));
xwimp_open_window_nested((wimp_open*)&s, bw->window->window, 0);
}
static struct frame_list pl = {0, 0, 0, 0, 0, 0, 0, 0, &pl, &pl};
static struct frame_list *plist = &pl;
/**
* Adds a new frameset associated with a browser window to the list
* Adds a plugin instance to the list of plugin instances.
*/
void frameset_add_to_list(struct browser_window *bw, struct frame *frame) {
void frame_add_instance_to_list(struct content *c, struct browser_window *parent, struct content *page, struct box *box, struct object_params *params, void **state, struct browser_window *bw, gui_window *g) {
struct frame_list *nfl = xcalloc(1, sizeof(*nfl));
struct frame_list *npl = xcalloc(1, sizeof(*npl));
LOG(("adding %p to list", frame));
nfl->frame = frame;
nfl->bw = bw;
nfl->prev = flist->prev;
nfl->next = flist;
flist->prev->next = nfl;
flist->prev = nfl;
npl->c = c;
npl->parent = parent;
npl->page = page;
npl->box = box;
npl->params = params;
npl->state = state;
npl->bw = bw;
npl->g = g;
npl->prev = plist->prev;
npl->next = plist;
plist->prev->next = npl;
plist->prev = npl;
LOG(("Added Frame %p", npl));
}
/**
* Removes a frameset associated with a browser window to the list
* Removes a plugin instance from the list of plugin instances
*/
void frameset_remove_from_list(struct browser_window *bw) {
void frame_remove_instance_from_list(struct content *c) {
struct frame_list *temp = frameset_get_from_list(bw);
struct frame_list *temp =
frame_get_instance_from_list(c);
if(temp != NULL) {
delete_tree(temp->frame);
LOG(("Removed Frame %p", temp));
temp->prev->next = temp->next;
temp->next->prev = temp->prev;
xfree(temp);
@ -56,250 +189,20 @@ void frameset_remove_from_list(struct browser_window *bw) {
}
/**
* Retrieves a frameset from the list
* Returns a frame_list struct pointer or NULL is nothing is found
* Retrieves an instance of a plugin from the list of plugin instances
* returns NULL if no instance is found
*/
struct frame_list *frameset_get_from_list(struct browser_window *bw) {
struct frame_list *frame_get_instance_from_list(struct content *c) {
struct frame_list *nfl;
struct frame_list *npl;
for(nfl = flist->next; (nfl != flist) && (nfl->bw != bw);
nfl = nfl->next)
for(npl = plist->next; (npl != plist)
&& (npl->c != c);
npl = npl->next)
;
if(nfl != flist)
return nfl;
if(npl != plist)
return npl;
return NULL;
}
/**
* Retrieves a frame from the list/tree structure.
* Returns a frame struct pointer or NULL if nothing is found
*/
struct frame *frame_get_from_list(struct browser_window *bw, struct box *b,
bool strict) {
struct frame_list *nfl;
struct frame *f=0;
for(nfl = flist->next; (nfl != flist); nfl = nfl->next) {
LOG(("checking tree %p",nfl->frame));
if ((f = get_frame_from_tree(nfl->frame, bw, b, strict))) {
LOG(("returning f: %p", f));
return f;
}
}
return NULL;
}
/* -------------------------------------------------------------------- *
* Tree handling stuff *
* -------------------------------------------------------------------- */
/**
* Adds a new frame to the tree
* Creates a new tree if appropriate.
*/
void add_frame_to_tree (struct browser_window *parent_bw, struct box *box,
struct browser_window *bw, struct content *c,
char *name) {
struct frame *nrf;
struct frame *parent;
struct frame *nf = xcalloc(1, sizeof(*nf));
unsigned int i;
/* get parent node */
if ((parent = frame_get_from_list(parent_bw, box, false)) == NULL) {
LOG(("no tree found - creating new"));
nrf = xcalloc(1, sizeof(*nrf));
nrf->win = parent_bw;
nrf->box = (struct box*)-1;
nrf->c = 0;
nrf->name = xstrdup("_top");
nrf->parent = 0;
nrf->no_children = 0;
nrf->children = xcalloc(0,1);
frameset_add_to_list(parent_bw, nrf);
parent = frame_get_from_list(parent_bw, (struct box*)-1, true);
}
LOG(("got parent"));
nf->win = bw;
nf->box = box;
nf->c = c;
nf->name = xstrdup(name);
nf->parent = parent;
nf->no_children = 0;
LOG(("adding frame to tree"));
i = parent->no_children;
parent->children =
xrealloc(parent->children, (i+1) * sizeof(struct frame));
parent->children[i] = nf;
parent->no_children++;
}
/**
* Retrieves a frame from the tree.
* If 'strict' is true, tests for both bw and box. Otherwise, just tests bw.
* Returns the frame or NULL.
*/
struct frame *get_frame_from_tree(struct frame *root,
struct browser_window *bw,
struct box *b,
bool strict) {
int i;
if (!root) {
LOG(("tree was empty"));
return NULL; /* empty tree */
}
if (strict) {
if (root->parent != 0) { /* has a parent node => check that */
LOG(("(%p, %p),(%p, %p)", root->parent->win, bw, root->box, b));
if (root->parent->win == bw && root->box == b) { /* found frame */
LOG(("found frame %p", root));
return root;
}
}
else { /* no parent node => check this one */
LOG(("(%p, %p),(%p, %p)", root->win, bw, root->box, b));
if (root->win == bw && root->box == b) { /* found frame */
LOG(("found frame %p", root));
return root;
}
}
}
else {
if (root->parent != 0) { /* has a parent node => check that */
LOG(("(%p, %p),(%p, %p)", root->parent->win, bw, root->box, b));
if (root->parent->win == bw) { /* found frame */
LOG(("found frame %p", root));
return root;
}
else if (root->win == bw) {
LOG(("adding as child of '%s'", root->name));
return root;
}
}
else { /* no parent node => check this one */
LOG(("(%p, %p),(%p, %p)", root->win, bw, root->box, b));
if (root->win == bw) { /* found frame */
LOG(("found frame %p", root));
return root;
}
}
}
if (root->no_children == 0)
return NULL;
for (i=0; i!=root->no_children; i++) { /* not found so recurse */
return get_frame_from_tree(root->children[i], bw, b, strict);
}
return NULL;
}
/**
* Deletes a complete tree.
*/
void delete_tree(struct frame *root) {
int i;
if (!root) return; /* empty tree */
if (root->no_children == 0) { /* leaf node => delete and return */
LOG(("deleting '%s'", root->name));
xfree(root->name);
xfree(root);
return;
}
for (i=0; i!=root->no_children; i++) { /* non-leaf node
=> kill children */
delete_tree(root->children[i]);
}
/* all children killed => remove this node */
LOG(("deleting '%s'", root->name));
xfree(root->name);
xfree(root);
}
#ifdef TEST
void traverse_tree(struct frame *root, int depth) {
int i;
if (!root) return; /* empty tree */
if (root->no_children == 0) {
for (i=0; i!=(depth+1); i++)
printf("\t");
printf("frame: %p (%s)\n", root, root->name);
return;
}
else {
for(i=0; i!=(depth+1); i++)
printf("\t");
printf("frame: %p (%s)\n", root, root->name);
}
for (i=0; i!=root->no_children; i++) { /* not found so recurse */
traverse_tree(root->children[i], (depth+1));
}
return;
}
void dump_all_frame_moose(void) {
struct frame_list *nfl;
for (nfl=flist->next; nfl!=flist; nfl=nfl->next) {
printf("bw: %p\n", nfl->bw);
traverse_tree(nfl->frame, 0);
printf("\n");
}
}
int main (void) {
struct frame *f;
add_frame_to_tree(1, 1, 1, 3, "test");
add_frame_to_tree(0, 2, 2, 5, "moo");
add_frame_to_tree(0, 3, 3, 1, "moose");
add_frame_to_tree(2, 4, 4, 2, "elk");
dump_all_frame_moose();
f = frame_get_from_list(1, 1, true);
if (f)
printf("%s: %d, %d\n", f->name, f->win, f->c);
else
printf("couldn't find 1,1\n");
frameset_remove_from_list(1);
f = frame_get_from_list(2, 4, true);
if (f)
printf("%s: %d, %d\n", f->name, f->win, f->c);
else
printf("couldn't find 2,4\n");
dump_all_frame_moose();
return 0;
}
#endif

View File

@ -30,6 +30,8 @@
*
* where the left frame is main.html with three sub frames (top, mid, end)
* and the entire page is index.html with two sub frames (nav, main)
*
* This is hung off the browser window structure.
*/
#ifndef _NETSURF_RISCOS_FRAMES_H_
@ -40,36 +42,29 @@
#include "netsurf/render/box.h"
#include "netsurf/riscos/gui.h"
#include "oslib/wimp.h"
struct frame_list {
struct frame *frame; /**< top most frame (ie root of tree) */
struct browser_window *bw; /**< main window */
struct frame_list *next; /**< next in list */
struct frame_list *prev; /**< previous in list */
struct content *c;
struct browser_window *parent;
struct content *page;
struct box *box;
struct object_params *params;
void **state;
struct browser_window *bw;
gui_window *g;
struct frame_list *next;
struct frame_list *prev;
};
struct frame {
struct browser_window *win; /**< window in which this frame appears */
struct box *box; /**< box in parent window containing this frame */
struct content *c; /**< content of this frame */
char *name; /**< name of this frame */
struct frame *parent; /**< parent frame */
unsigned int no_children; /**< number of children this frame has */
struct frame **children; /**< child frames */
};
void frameset_add_to_list(struct browser_window *bw, struct frame *frame);
void frameset_remove_from_list(struct browser_window *bw);
struct frame_list *frameset_get_from_list(struct browser_window *bw);
struct frame *frame_get_from_list(struct browser_window *bw, struct box *b,
bool strict);
void add_frame_to_tree (struct browser_window *pbw, struct box *box,
struct browser_window *bw, struct content *c,
char *name);
struct frame *get_frame_from_tree(struct frame *root,
struct browser_window *bw,
struct box *b, bool strict);
void delete_tree(struct frame *root);
void frame_add_instance(struct content *c, struct browser_window *bw,
struct content *page, struct box *box,
struct object_params *params, void **state);
void frame_remove_instance(struct content *c, struct browser_window *bw,
struct content *page, struct box *box,
struct object_params *params, void **state);
void frame_reshape_instance(struct content *c, struct browser_window *bw,
struct content *page, struct box *box,
struct object_params *params, void **state);
#endif

View File

@ -251,7 +251,7 @@ void gui_poll(bool active)
case wimp_CLOSE_WINDOW_REQUEST :
g = ro_lookup_gui_from_w(block.close.w);
if (g != NULL)
browser_window_destroy(g->data.browser.bw);
browser_window_destroy(g->data.browser.bw, true);
else
ro_gui_dialog_close(&(block.close.w));
break;
@ -577,7 +577,7 @@ void ro_gui_icon_bar_click(wimp_pointer* pointer)
{
struct browser_window* bw;
bw = create_browser_window(browser_TITLE | browser_TOOLBAR
| browser_SCROLL_X_ALWAYS | browser_SCROLL_Y_ALWAYS, 640, 480);
| browser_SCROLL_X_ALWAYS | browser_SCROLL_Y_ALWAYS, 640, 480, NULL);
gui_window_show(bw->window);
browser_window_open_location(bw, HOME_URL);
wimp_set_caret_position(bw->window->data.browser.toolbar,
@ -844,7 +844,7 @@ void ro_msg_dataopen(wimp_message *message)
/* create a new window with the file */
bw = create_browser_window(browser_TITLE | browser_TOOLBAR |
browser_SCROLL_X_ALWAYS | browser_SCROLL_Y_ALWAYS, 640, 480);
browser_SCROLL_X_ALWAYS | browser_SCROLL_Y_ALWAYS, 640, 480, NULL);
gui_window_show(bw->window);
url = ro_path_to_url(message->data.data_xfer.file_name);
browser_window_open_location(bw, url);
@ -888,7 +888,7 @@ void ro_gui_open_help_page (void)
struct browser_window *bw;
bw = create_browser_window(browser_TITLE | browser_TOOLBAR |
browser_SCROLL_X_ALWAYS |
browser_SCROLL_Y_ALWAYS, 640, 480);
browser_SCROLL_Y_ALWAYS, 640, 480, NULL);
gui_window_show(bw->window);
browser_window_open_location(bw, HELP_URL);
wimp_set_caret_position(bw->window->data.browser.toolbar,

View File

@ -21,7 +21,12 @@ void html_add_instance(struct content *c, struct browser_window *bw,
if (c->data.html.object[i].content == 0)
continue;
if (c->data.html.object[i].content->type == CONTENT_HTML)
LOG(("html object"));
frame_add_instance(c->data.html.object[i].content,
bw, c,
c->data.html.object[i].box,
c->data.html.object[i].box->object_params,
&c->data.html.object[i].box->object_state);
else
content_add_instance(c->data.html.object[i].content,
bw, c,
c->data.html.object[i].box,
@ -39,6 +44,13 @@ void html_reshape_instance(struct content *c, struct browser_window *bw,
for (i = 0; i != c->data.html.object_count; i++) {
if (c->data.html.object[i].content == 0)
continue;
if (c->data.html.object[i].content->type == CONTENT_HTML)
frame_reshape_instance(c->data.html.object[i].content,
bw, c,
c->data.html.object[i].box,
c->data.html.object[i].box->object_params,
&c->data.html.object[i].box->object_state);
else
content_reshape_instance(c->data.html.object[i].content,
bw, c,
c->data.html.object[i].box,
@ -55,6 +67,13 @@ void html_remove_instance(struct content *c, struct browser_window *bw,
for (i = 0; i != c->data.html.object_count; i++) {
if (c->data.html.object[i].content == 0)
continue;
if (c->data.html.object[i].content->type == CONTENT_HTML)
frame_remove_instance(c->data.html.object[i].content,
bw, c,
c->data.html.object[i].box,
c->data.html.object[i].box->object_params,
&c->data.html.object[i].box->object_state);
else
content_remove_instance(c->data.html.object[i].content,
bw, c,
c->data.html.object[i].box,

View File

@ -1290,7 +1290,7 @@ void plugin_url_access(wimp_message *message) {
struct browser_window *bwnew;
bwnew = create_browser_window(browser_TITLE
| browser_TOOLBAR | browser_SCROLL_X_ALWAYS
| browser_SCROLL_Y_ALWAYS, 640, 480);
| browser_SCROLL_Y_ALWAYS, 640, 480, NULL);
gui_window_show(bwnew->window);
bwnew->url = xstrdup(url);
browser_window_open_location(bwnew, url);

View File

@ -72,7 +72,7 @@ void ro_uri_message_received(uri_full_message_process* uri_message)
}
bw = create_browser_window(browser_TITLE | browser_TOOLBAR
| browser_SCROLL_X_ALWAYS | browser_SCROLL_Y_ALWAYS, 640, 480);
| browser_SCROLL_X_ALWAYS | browser_SCROLL_Y_ALWAYS, 640, 480, NULL);
gui_window_show(bw->window);
browser_window_open_location(bw, uri_requested);

View File

@ -701,7 +701,7 @@ bool ro_gui_window_keypress(gui_window *g, int key, bool toolbar)
return true;
case wimp_KEY_CONTROL + wimp_KEY_F2: /* Close window. */
browser_window_destroy(g->data.browser.bw);
browser_window_destroy(g->data.browser.bw, true);
return true;
case wimp_KEY_RETURN: