[project @ 2004-08-11 19:02:32 by bursa]

Start work on removing instances and making content types non-shareable. Clean up some #includes.

svn path=/import/netsurf/; revision=1211
This commit is contained in:
James Bursa 2004-08-11 19:02:32 +00:00
parent dba4904ddb
commit bc727dda1c
11 changed files with 114 additions and 28 deletions

View File

@ -20,6 +20,7 @@
#include "netsurf/utils/config.h"
#include "netsurf/content/content.h"
#include "netsurf/content/fetch.h"
#include "netsurf/content/fetchcache.h"
#include "netsurf/css/css.h"
#include "netsurf/desktop/options.h"
#include "netsurf/render/html.h"
@ -163,49 +164,52 @@ struct handler_entry {
void (*reshape_instance)(struct content *c, struct browser_window *bw,
struct content *page, struct box *box,
struct object_params *params, void **state);
/** There must be one content per user for this type. */
bool no_share;
};
/** A table of handler functions, indexed by ::content_type.
* Must be ordered as enum ::content_type. */
static const struct handler_entry handler_map[] = {
{html_create, html_process_data, html_convert,
html_reformat, html_destroy, html_stop, html_redraw,
html_add_instance, html_remove_instance, html_reshape_instance},
html_add_instance, html_remove_instance, html_reshape_instance,
true},
{textplain_create, html_process_data, textplain_convert,
0, 0, 0, 0, 0, 0, 0},
{0, 0, css_convert, 0, css_destroy, 0, 0, 0, 0, 0},
0, 0, 0, 0, 0, 0, 0, true},
{0, 0, css_convert, 0, css_destroy, 0, 0, 0, 0, 0, false},
#ifdef WITH_JPEG
{nsjpeg_create, 0, nsjpeg_convert,
0, nsjpeg_destroy, 0, nsjpeg_redraw, 0, 0, 0},
0, nsjpeg_destroy, 0, nsjpeg_redraw, 0, 0, 0, false},
#endif
#ifdef WITH_GIF
{nsgif_create, 0, nsgif_convert,
0, nsgif_destroy, 0, nsgif_redraw, 0, 0, 0},
0, nsgif_destroy, 0, nsgif_redraw, 0, 0, 0, false},
#endif
#ifdef WITH_PNG
{nsmng_create, nsmng_process_data, nsmng_convert,
0, nsmng_destroy, 0, nsmng_redraw, 0, 0, 0},
0, nsmng_destroy, 0, nsmng_redraw, 0, 0, 0, false},
#endif
#ifdef WITH_MNG
{nsmng_create, nsmng_process_data, nsmng_convert,
0, nsmng_destroy, 0, nsmng_redraw, 0, 0, 0},
0, nsmng_destroy, 0, nsmng_redraw, 0, 0, 0, false},
{nsmng_create, nsmng_process_data, nsmng_convert,
0, nsmng_destroy, 0, nsmng_redraw, 0, 0, 0},
0, nsmng_destroy, 0, nsmng_redraw, 0, 0, 0, false},
#endif
#ifdef WITH_SPRITE
{sprite_create, sprite_process_data, sprite_convert,
0, sprite_destroy, 0, sprite_redraw, 0, 0, 0},
0, sprite_destroy, 0, sprite_redraw, 0, 0, 0, false},
#endif
#ifdef WITH_DRAW
{0, 0, draw_convert,
0, draw_destroy, 0, draw_redraw, 0, 0, 0},
0, draw_destroy, 0, draw_redraw, 0, 0, 0, false},
#endif
#ifdef WITH_PLUGIN
{plugin_create, 0, plugin_convert,
0, plugin_destroy, 0, plugin_redraw,
plugin_add_instance, plugin_remove_instance,
plugin_reshape_instance},
plugin_reshape_instance, true},
#endif
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, false}
};
#define HANDLER_MAP_COUNT (sizeof(handler_map) / sizeof(handler_map[0]))
@ -286,6 +290,9 @@ struct content * content_create(const char *url)
c->total_size = 0;
c->no_error_pages = false;
c->error_count = 0;
c->owning_bw = 0;
c->owning_box = 0;
c->params = 0;
c->prev = 0;
c->next = content_list;
@ -304,7 +311,7 @@ struct content * content_create(const char *url)
* \return content if found, or 0
*
* Searches the list of contents for one corresponding to the given url, and
* which is fresh.
* which is fresh and shareable.
*/
struct content * content_get(const char *url)
@ -312,9 +319,20 @@ struct content * content_get(const char *url)
struct content *c;
for (c = content_list; c; c = c->next) {
if (c->fresh && c->status != CONTENT_STATUS_ERROR &&
strcmp(c->url, url) == 0)
return c;
if (!c->fresh)
/* not fresh */
continue;
if (c->status == CONTENT_STATUS_ERROR)
/* error state */
continue;
if (c->type != CONTENT_UNKNOWN &&
handler_map[c->type].no_share &&
c->user_list->next)
/* not shareable, and has a user already */
continue;
if (strcmp(c->url, url))
continue;
return c;
}
return 0;
@ -341,6 +359,10 @@ bool content_set_type(struct content *c, content_type type,
const char *mime_type, const char *params[])
{
union content_msg_data msg_data;
struct content *clone;
void (*callback)(content_msg msg, struct content *c, void *p1,
void *p2, union content_msg_data data);
void *p1, *p2;
assert(c != 0);
assert(c->status == CONTENT_STATUS_TYPE_UNKNOWN);
@ -360,6 +382,36 @@ bool content_set_type(struct content *c, content_type type,
c->type = type;
c->status = CONTENT_STATUS_LOADING;
if (handler_map[type].no_share && c->user_list->next &&
c->user_list->next->next) {
/* type not shareable, and more than one user: split into
* a content per user */
while (c->user_list->next->next) {
clone = content_create(c->url);
if (!clone) {
c->type = CONTENT_UNKNOWN;
c->status = CONTENT_STATUS_ERROR;
msg_data.error = messages_get("NoMemory");
content_broadcast(c, CONTENT_MSG_ERROR,
msg_data);
warn_user("NoMemory", 0);
return false;
}
clone->width = c->width;
clone->height = c->height;
clone->fresh = c->fresh;
callback = c->user_list->next->next->callback;
p1 = c->user_list->next->next->p1;
p2 = c->user_list->next->next->p2;
content_add_user(clone, callback, p1, p2);
content_remove_user(c, callback, p1, p2);
content_broadcast(clone, CONTENT_MSG_NEWPTR, msg_data);
fetchcache_go(clone, 0, callback, p1, p2, 0, 0, false);
}
}
if (handler_map[type].create) {
if (!handler_map[type].create(c, params)) {
c->type = CONTENT_UNKNOWN;

View File

@ -35,6 +35,7 @@
* content_create -> TYPE_UNKNOWN [style=bold];
* TYPE_UNKNOWN -> content_set_type [style=bold];
* content_set_type -> LOADING [label=MSG_LOADING, style=bold];
* content_set_type -> LOADING [label="MSG_NEWPTR\nMSG_LOADING",style=bold];
* content_set_type -> ERROR [label=MSG_ERROR];
* LOADING -> content_process_data [style=bold];
* content_process_data -> LOADING [style=bold];
@ -95,8 +96,6 @@
#include "netsurf/utils/config.h"
#include "netsurf/content/content_type.h"
#include "netsurf/css/css.h"
#include "netsurf/render/box.h"
#include "netsurf/render/font.h"
#include "netsurf/render/html.h"
#ifdef WITH_JPEG
#include "netsurf/riscos/jpeg.h"
@ -121,7 +120,11 @@
#endif
struct box;
struct browser_window;
struct content;
struct fetch;
struct object_params;
/** Used in callbacks to indicate what has occurred. */
@ -134,6 +137,7 @@ typedef enum {
CONTENT_MSG_REDIRECT, /**< replacement URL */
CONTENT_MSG_REFORMAT, /**< content_reformat done */
CONTENT_MSG_REDRAW, /**< needs redraw (eg. new animation frame) */
CONTENT_MSG_NEWPTR, /**< address of structure has changed */
#ifdef WITH_AUTH
CONTENT_MSG_AUTH /**< authentication required */
#endif
@ -244,6 +248,17 @@ struct content {
} error_list[40];
unsigned int error_count; /**< Number of valid error entries. */
/** Browser window that this content is in, valid only if
* handler_map[type].no_share and 1 user, 0 if not visible. */
struct browser_window *owning_bw;
/** Box window that this content is in, valid only if
* handler_map[type].no_share and 1 user, 0 if not in an HTML tree. */
struct box *owning_box;
/** Parameters of <object> or <embed>, valid only if
* handler_map[type].no_share and 1 user, 0 if not in an <object> or
* <embed>. */
struct object_params *params;
struct content *prev; /**< Previous in global content list. */
struct content *next; /**< Next in global content list. */
};
@ -253,9 +268,6 @@ extern const char *content_type_name[];
extern const char *content_status_name[];
struct browser_window;
content_type content_lookup(const char *mime_type);
struct content * content_create(const char *url);
struct content * content_get(const char *url);

View File

@ -751,6 +751,10 @@ void css_atimport_callback(content_msg msg, struct content *css,
}
break;
case CONTENT_MSG_NEWPTR:
c->data.css.import_content[i] = css;
break;
default:
assert(0);
}

View File

@ -284,6 +284,10 @@ void browser_window_callback(content_msg msg, struct content *c,
gui_window_update_box(bw->window, &data);
break;
case CONTENT_MSG_NEWPTR:
bw->loading_content = c;
break;
#ifdef WITH_AUTH
case CONTENT_MSG_AUTH:
gui_401login_open(bw, c, data.auth_realm);

View File

@ -76,15 +76,13 @@
#include <limits.h>
#include <stdbool.h>
#include "libxml/HTMLparser.h"
#include "netsurf/utils/config.h"
#include "netsurf/content/content_type.h"
#include "netsurf/css/css.h"
#include "netsurf/render/font.h"
#include "netsurf/utils/pool.h"
struct box;
struct column;
struct css_style;
struct font_data;
/** Type of a struct box. */

View File

@ -24,6 +24,8 @@
#include "netsurf/desktop/gui.h"
#endif
#include "netsurf/desktop/options.h"
#include "netsurf/render/box.h"
#include "netsurf/render/font.h"
#include "netsurf/render/html.h"
#include "netsurf/render/layout.h"
#include "netsurf/utils/log.h"
@ -586,6 +588,10 @@ void html_convert_css_callback(content_msg msg, struct content *css,
}
break;
case CONTENT_MSG_NEWPTR:
c->data.html.stylesheet_content[i] = css;
break;
#ifdef WITH_AUTH
case CONTENT_MSG_AUTH:
c->data.html.stylesheet_content[i] = 0;
@ -743,6 +749,10 @@ void html_object_callback(content_msg msg, struct content *object,
content_broadcast(c, CONTENT_MSG_REDRAW, data);
break;
case CONTENT_MSG_NEWPTR:
c->data.html.object[i].content = object;
break;
#ifdef WITH_AUTH
case CONTENT_MSG_AUTH:
c->data.html.object[i].content = 0;

View File

@ -22,6 +22,8 @@
#include "netsurf/utils/config.h"
#include "netsurf/content/content.h"
#include "netsurf/css/css.h"
#include "netsurf/render/box.h"
#include "netsurf/render/font.h"
#include "netsurf/render/form.h"
#include "netsurf/render/html.h"
#include "netsurf/riscos/gui.h"

View File

@ -19,6 +19,7 @@
#include "oslib/wimp.h"
#include "oslib/wimpspriteop.h"
#include "netsurf/desktop/gui.h"
#include "netsurf/render/box.h"
#include "netsurf/render/form.h"
#include "netsurf/riscos/gui.h"
#include "netsurf/riscos/help.h"
@ -653,7 +654,6 @@ void ro_gui_popup_menu(wimp_menu *menu, wimp_w w, wimp_i i)
void ro_gui_menu_selection(wimp_selection *selection)
{
char url[80];
int length;
wimp_pointer pointer;
wimp_window_state state;
os_error *error;

View File

@ -17,6 +17,7 @@
#include "netsurf/utils/config.h"
#include "netsurf/content/content.h"
#include "netsurf/render/box.h"
#include "netsurf/render/font.h"
#include "netsurf/render/html.h"
#include "netsurf/render/layout.h"

View File

@ -21,6 +21,8 @@
#include "netsurf/content/content.h"
#include "netsurf/css/css.h"
#include "netsurf/desktop/gui.h"
#include "netsurf/render/box.h"
#include "netsurf/render/font.h"
#include "netsurf/render/form.h"
#include "netsurf/render/layout.h"
#include "netsurf/riscos/save_draw.h"

View File

@ -21,8 +21,10 @@
#include "oslib/osspriteop.h"
#include "oslib/wimp.h"
#include "oslib/wimpspriteop.h"
#include "netsurf/css/css.h"
#include "netsurf/utils/config.h"
#include "netsurf/css/css.h"
#include "netsurf/render/box.h"
#include "netsurf/render/form.h"
#include "netsurf/riscos/buffer.h"
#include "netsurf/riscos/gui.h"
#include "netsurf/riscos/options.h"
@ -30,7 +32,6 @@
#include "netsurf/riscos/thumbnail.h"
#include "netsurf/riscos/toolbar.h"
#include "netsurf/riscos/wimp.h"
#include "netsurf/render/form.h"
#include "netsurf/utils/log.h"
#include "netsurf/utils/url.h"
#include "netsurf/utils/utils.h"