2003-06-30 16:44:03 +04:00
|
|
|
/*
|
|
|
|
* This file is part of NetSurf, http://netsurf.sourceforge.net/
|
|
|
|
* Licensed under the GNU General Public License,
|
|
|
|
* http://www.opensource.org/licenses/gpl-license
|
2004-02-15 23:39:53 +03:00
|
|
|
* Copyright 2004 James Bursa <bursa@users.sourceforge.net>
|
2003-06-30 16:44:03 +04:00
|
|
|
* Copyright 2003 Phil Mellor <monkeyson@users.sourceforge.net>
|
|
|
|
* Copyright 2003 John M Bell <jmb202@ecs.soton.ac.uk>
|
2002-05-04 23:57:18 +04:00
|
|
|
*/
|
|
|
|
|
2004-07-19 18:31:31 +04:00
|
|
|
/** \file
|
|
|
|
* Conversion of XML tree to box tree (implementation).
|
|
|
|
*/
|
|
|
|
|
2002-05-04 23:57:18 +04:00
|
|
|
#include <assert.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <stdio.h>
|
2003-07-15 02:57:45 +04:00
|
|
|
#include <stdbool.h>
|
2002-05-04 23:57:18 +04:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include "libxml/HTMLparser.h"
|
2004-01-05 05:10:59 +03:00
|
|
|
#include "netsurf/utils/config.h"
|
2003-10-25 18:13:49 +04:00
|
|
|
#include "netsurf/content/content.h"
|
2003-04-04 19:19:32 +04:00
|
|
|
#include "netsurf/css/css.h"
|
2004-02-14 02:07:42 +03:00
|
|
|
#include "netsurf/desktop/options.h"
|
2002-08-18 20:46:45 +04:00
|
|
|
#include "netsurf/render/box.h"
|
2003-07-18 03:01:02 +04:00
|
|
|
#include "netsurf/render/font.h"
|
2003-10-25 04:35:49 +04:00
|
|
|
#include "netsurf/render/form.h"
|
2003-07-05 01:17:53 +04:00
|
|
|
#include "netsurf/render/html.h"
|
2003-06-17 23:24:21 +04:00
|
|
|
#ifdef riscos
|
|
|
|
#include "netsurf/desktop/gui.h"
|
2004-06-03 01:06:18 +04:00
|
|
|
#endif
|
2004-01-05 05:10:59 +03:00
|
|
|
#ifdef WITH_PLUGIN
|
2003-05-31 22:47:00 +04:00
|
|
|
#include "netsurf/riscos/plugin.h"
|
2003-07-15 02:57:45 +04:00
|
|
|
#endif
|
2003-06-17 23:24:21 +04:00
|
|
|
#define NDEBUG
|
2003-05-31 22:47:00 +04:00
|
|
|
#include "netsurf/utils/log.h"
|
2003-09-27 03:22:00 +04:00
|
|
|
#include "netsurf/utils/messages.h"
|
2004-01-02 15:04:04 +03:00
|
|
|
#include "netsurf/utils/pool.h"
|
2004-03-02 21:02:41 +03:00
|
|
|
#include "netsurf/utils/url.h"
|
2003-02-09 15:58:15 +03:00
|
|
|
#include "netsurf/utils/utils.h"
|
2002-05-04 23:57:18 +04:00
|
|
|
|
|
|
|
|
2004-05-21 18:26:59 +04:00
|
|
|
/** Status of box tree construction. */
|
|
|
|
struct box_status {
|
2003-07-05 01:17:53 +04:00
|
|
|
struct content *content;
|
|
|
|
char *href;
|
|
|
|
char *title;
|
2004-10-18 01:10:19 +04:00
|
|
|
struct form *current_form;
|
2004-08-07 02:19:13 +04:00
|
|
|
char *id;
|
2003-07-05 01:17:53 +04:00
|
|
|
};
|
|
|
|
|
2004-05-21 18:26:59 +04:00
|
|
|
/** Return type for special case element functions. */
|
|
|
|
struct box_result {
|
|
|
|
/** Box for element, if any, 0 otherwise. */
|
|
|
|
struct box *box;
|
|
|
|
/** Children of this element should be converted. */
|
|
|
|
bool convert_children;
|
|
|
|
/** Memory was exhausted when handling the element. */
|
|
|
|
bool memory_error;
|
|
|
|
};
|
|
|
|
|
|
|
|
/** MultiLength, as defined by HTML 4.01. */
|
|
|
|
struct box_multi_length {
|
|
|
|
enum { LENGTH_PX, LENGTH_PERCENT, LENGTH_RELATIVE } type;
|
|
|
|
float value;
|
2003-04-15 21:53:00 +04:00
|
|
|
};
|
|
|
|
|
2004-06-09 23:55:06 +04:00
|
|
|
static const content_type image_types[] = {
|
|
|
|
#ifdef WITH_JPEG
|
|
|
|
CONTENT_JPEG,
|
|
|
|
#endif
|
|
|
|
#ifdef WITH_GIF
|
|
|
|
CONTENT_GIF,
|
|
|
|
#endif
|
|
|
|
#ifdef WITH_PNG
|
|
|
|
CONTENT_PNG,
|
|
|
|
#endif
|
2004-07-16 23:47:03 +04:00
|
|
|
#ifdef WITH_MNG
|
|
|
|
CONTENT_JNG,
|
|
|
|
CONTENT_MNG,
|
|
|
|
#endif
|
2004-06-09 23:55:06 +04:00
|
|
|
#ifdef WITH_SPRITE
|
|
|
|
CONTENT_SPRITE,
|
|
|
|
#endif
|
|
|
|
#ifdef WITH_DRAW
|
|
|
|
CONTENT_DRAW,
|
|
|
|
#endif
|
|
|
|
CONTENT_UNKNOWN };
|
2004-05-21 18:26:59 +04:00
|
|
|
|
2004-09-04 00:32:57 +04:00
|
|
|
#define MAX_SPAN ( 100 )
|
|
|
|
|
|
|
|
struct span_info {
|
|
|
|
unsigned int row_span;
|
|
|
|
bool auto_row;
|
|
|
|
bool auto_column;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct columns {
|
|
|
|
unsigned int current_column;
|
|
|
|
bool extra;
|
|
|
|
/* Number of columns in main part of table 1..max columns */
|
|
|
|
unsigned int num_columns;
|
|
|
|
/* Information about columns in main table,
|
|
|
|
array 0 to num_columns - 1 */
|
|
|
|
struct span_info *spans;
|
|
|
|
/* Number of columns that have cells after a colspan 0 */
|
|
|
|
unsigned int extra_columns;
|
|
|
|
/* Number of rows in table */
|
|
|
|
unsigned int num_rows;
|
|
|
|
};
|
|
|
|
|
2004-12-10 01:22:13 +03:00
|
|
|
static bool convert_xml_to_box(xmlNode *n, struct content *content,
|
|
|
|
struct css_style *parent_style,
|
|
|
|
struct box *parent, struct box **inline_container,
|
2004-05-21 18:26:59 +04:00
|
|
|
struct box_status status);
|
2004-12-10 01:22:13 +03:00
|
|
|
struct css_style * box_get_style(struct content *c,
|
|
|
|
struct css_style *parent_style,
|
|
|
|
xmlNode *n);
|
2004-03-15 01:49:40 +03:00
|
|
|
static void box_text_transform(char *s, unsigned int len,
|
|
|
|
css_text_transform tt);
|
2004-05-21 18:26:59 +04:00
|
|
|
static struct box_result box_a(xmlNode *n, struct box_status *status,
|
2003-07-05 01:17:53 +04:00
|
|
|
struct css_style *style);
|
2004-05-21 18:26:59 +04:00
|
|
|
static struct box_result box_body(xmlNode *n, struct box_status *status,
|
2003-08-31 01:45:03 +04:00
|
|
|
struct css_style *style);
|
2004-05-21 18:26:59 +04:00
|
|
|
static struct box_result box_br(xmlNode *n, struct box_status *status,
|
2004-04-18 19:19:53 +04:00
|
|
|
struct css_style *style);
|
2004-05-21 18:26:59 +04:00
|
|
|
static struct box_result box_image(xmlNode *n, struct box_status *status,
|
2003-07-05 01:17:53 +04:00
|
|
|
struct css_style *style);
|
2004-05-21 18:26:59 +04:00
|
|
|
static struct box_result box_form(xmlNode *n, struct box_status *status,
|
2003-07-05 01:17:53 +04:00
|
|
|
struct css_style *style);
|
2004-05-21 18:26:59 +04:00
|
|
|
static struct box_result box_textarea(xmlNode *n, struct box_status *status,
|
2003-07-05 01:17:53 +04:00
|
|
|
struct css_style *style);
|
2004-05-21 18:26:59 +04:00
|
|
|
static struct box_result box_select(xmlNode *n, struct box_status *status,
|
2003-07-05 01:17:53 +04:00
|
|
|
struct css_style *style);
|
2004-05-21 18:26:59 +04:00
|
|
|
static struct box_result box_input(xmlNode *n, struct box_status *status,
|
2003-09-27 03:22:00 +04:00
|
|
|
struct css_style *style);
|
2004-05-21 18:26:59 +04:00
|
|
|
static struct box *box_input_text(xmlNode *n, struct box_status *status,
|
2004-05-04 02:05:40 +04:00
|
|
|
struct css_style *style, bool password);
|
2004-05-21 18:26:59 +04:00
|
|
|
static struct box_result box_button(xmlNode *n, struct box_status *status,
|
2003-07-05 01:17:53 +04:00
|
|
|
struct css_style *style);
|
2004-05-21 18:26:59 +04:00
|
|
|
static struct box_result box_frameset(xmlNode *n, struct box_status *status,
|
2004-04-02 22:13:23 +04:00
|
|
|
struct css_style *style);
|
2004-12-13 01:00:30 +03:00
|
|
|
static bool box_select_add_option(struct form_control *control, xmlNode *n);
|
2004-01-02 15:04:04 +03:00
|
|
|
static void box_normalise_block(struct box *block, pool box_pool);
|
|
|
|
static void box_normalise_table(struct box *table, pool box_pool);
|
2004-09-04 00:32:57 +04:00
|
|
|
static void box_normalise_table_spans( struct box *table );
|
2004-08-14 19:07:21 +04:00
|
|
|
static void box_normalise_table_row_group(struct box *row_group,
|
2004-09-04 00:32:57 +04:00
|
|
|
struct columns *col_info,
|
2004-01-02 15:04:04 +03:00
|
|
|
pool box_pool);
|
2004-08-14 19:07:21 +04:00
|
|
|
static void box_normalise_table_row(struct box *row,
|
2004-09-04 00:32:57 +04:00
|
|
|
struct columns *col_info,
|
2004-01-02 15:04:04 +03:00
|
|
|
pool box_pool);
|
2004-09-04 00:32:57 +04:00
|
|
|
static unsigned int calculate_table_row( struct columns *col_info,
|
|
|
|
unsigned int col_span, unsigned int row_span );
|
2004-01-02 15:04:04 +03:00
|
|
|
static void box_normalise_inline_container(struct box *cont, pool box_pool);
|
2003-03-04 14:59:36 +03:00
|
|
|
static void box_free_box(struct box *box);
|
2004-05-21 18:26:59 +04:00
|
|
|
static struct box_result box_object(xmlNode *n, struct box_status *status,
|
2003-07-08 02:10:51 +04:00
|
|
|
struct css_style *style);
|
2004-05-21 18:26:59 +04:00
|
|
|
static struct box_result box_embed(xmlNode *n, struct box_status *status,
|
2003-07-08 02:10:51 +04:00
|
|
|
struct css_style *style);
|
2004-05-21 18:26:59 +04:00
|
|
|
static struct box_result box_applet(xmlNode *n, struct box_status *status,
|
2003-07-08 02:10:51 +04:00
|
|
|
struct css_style *style);
|
2004-05-21 18:26:59 +04:00
|
|
|
static struct box_result box_iframe(xmlNode *n, struct box_status *status,
|
2003-08-25 02:39:55 +04:00
|
|
|
struct css_style *style);
|
2003-07-10 01:33:01 +04:00
|
|
|
static bool plugin_decode(struct content* content, char* url, struct box* box,
|
2004-08-14 18:30:12 +04:00
|
|
|
struct object_params* po);
|
2004-05-21 18:26:59 +04:00
|
|
|
static struct box_multi_length *box_parse_multi_lengths(const char *s,
|
|
|
|
unsigned int *count);
|
2004-10-18 01:10:19 +04:00
|
|
|
static bool box_contains_point(struct box *box, int x, int y);
|
2003-07-05 01:17:53 +04:00
|
|
|
|
2004-08-02 00:28:02 +04:00
|
|
|
#define box_is_float(box) (box->type == BOX_FLOAT_LEFT || \
|
|
|
|
box->type == BOX_FLOAT_RIGHT)
|
|
|
|
|
2003-07-05 01:17:53 +04:00
|
|
|
/* element_table must be sorted by name */
|
|
|
|
struct element_entry {
|
|
|
|
char name[10]; /* element type */
|
2004-05-21 18:26:59 +04:00
|
|
|
struct box_result (*convert)(xmlNode *n, struct box_status *status,
|
2003-07-05 01:17:53 +04:00
|
|
|
struct css_style *style);
|
|
|
|
};
|
|
|
|
static const struct element_entry element_table[] = {
|
|
|
|
{"a", box_a},
|
2003-07-17 18:26:15 +04:00
|
|
|
{"applet", box_applet},
|
2003-08-31 01:45:03 +04:00
|
|
|
{"body", box_body},
|
2004-04-18 19:19:53 +04:00
|
|
|
{"br", box_br},
|
2003-09-27 03:22:00 +04:00
|
|
|
{"button", box_button},
|
|
|
|
{"embed", box_embed},
|
2003-07-05 01:17:53 +04:00
|
|
|
{"form", box_form},
|
2004-04-02 22:13:23 +04:00
|
|
|
{"frameset", box_frameset},
|
2003-08-25 02:39:55 +04:00
|
|
|
{"iframe", box_iframe},
|
2003-07-05 01:17:53 +04:00
|
|
|
{"img", box_image},
|
|
|
|
{"input", box_input},
|
2003-07-08 02:10:51 +04:00
|
|
|
{"object", box_object},
|
2003-07-05 01:17:53 +04:00
|
|
|
{"select", box_select},
|
|
|
|
{"textarea", box_textarea}
|
|
|
|
};
|
|
|
|
#define ELEMENT_TABLE_COUNT (sizeof(element_table) / sizeof(element_table[0]))
|
2002-05-04 23:57:18 +04:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
2003-10-09 19:22:48 +04:00
|
|
|
* Add a child to a box tree node.
|
2002-05-04 23:57:18 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
void box_add_child(struct box * parent, struct box * child)
|
|
|
|
{
|
2003-01-02 16:26:43 +03:00
|
|
|
if (parent->children != 0) { /* has children already */
|
2002-05-04 23:57:18 +04:00
|
|
|
parent->last->next = child;
|
2003-01-02 16:26:43 +03:00
|
|
|
child->prev = parent->last;
|
|
|
|
} else { /* this is the first child */
|
2002-05-04 23:57:18 +04:00
|
|
|
parent->children = child;
|
2003-01-02 16:26:43 +03:00
|
|
|
child->prev = 0;
|
|
|
|
}
|
2002-05-04 23:57:18 +04:00
|
|
|
|
|
|
|
parent->last = child;
|
|
|
|
child->parent = parent;
|
|
|
|
}
|
|
|
|
|
2003-10-09 19:22:48 +04:00
|
|
|
|
2002-06-27 03:27:30 +04:00
|
|
|
/**
|
2003-10-09 19:22:48 +04:00
|
|
|
* Create a box tree node.
|
2004-12-10 01:22:13 +03:00
|
|
|
*
|
|
|
|
* \param style style for the box (not copied)
|
|
|
|
* \param href href for the box (copied), or 0
|
|
|
|
* \param title title for the box (copied), or 0
|
|
|
|
* \param id id for the box (copied), or 0
|
|
|
|
* \param box_pool pool to allocate box from
|
|
|
|
* \return allocated and initialised box, or 0 on memory exhaustion
|
2002-06-27 03:27:30 +04:00
|
|
|
*/
|
|
|
|
|
2003-07-05 20:16:15 +04:00
|
|
|
struct box * box_create(struct css_style * style,
|
2004-08-14 16:57:02 +04:00
|
|
|
const char *href, const char *title, const char *id,
|
|
|
|
pool box_pool)
|
2002-06-27 03:27:30 +04:00
|
|
|
{
|
2004-02-02 03:22:59 +03:00
|
|
|
unsigned int i;
|
2004-08-14 16:57:02 +04:00
|
|
|
struct box *box;
|
2004-12-10 01:22:13 +03:00
|
|
|
char *href1 = 0;
|
|
|
|
char *title1 = 0;
|
|
|
|
char *id1 = 0;
|
|
|
|
|
|
|
|
if (href)
|
|
|
|
href1 = strdup(href);
|
|
|
|
if (title)
|
|
|
|
title1 = strdup(title);
|
|
|
|
if (id)
|
|
|
|
id1 = strdup(id);
|
|
|
|
if ((href && !href1) || (title && !title1) || (id && !id1)) {
|
|
|
|
free(href1);
|
|
|
|
free(title1);
|
|
|
|
free(id1);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
box = pool_alloc(box_pool, sizeof (struct box));
|
|
|
|
if (!box) {
|
|
|
|
free(href1);
|
|
|
|
free(title1);
|
|
|
|
free(id1);
|
|
|
|
return 0;
|
|
|
|
}
|
2004-08-14 16:57:02 +04:00
|
|
|
|
2003-07-05 20:16:15 +04:00
|
|
|
box->type = BOX_INLINE;
|
2002-06-27 03:27:30 +04:00
|
|
|
box->style = style;
|
2004-08-14 16:57:02 +04:00
|
|
|
box->x = box->y = 0;
|
2002-09-19 23:54:43 +04:00
|
|
|
box->width = UNKNOWN_WIDTH;
|
2004-08-14 16:57:02 +04:00
|
|
|
box->height = 0;
|
|
|
|
box->descendant_x0 = box->descendant_y0 = 0;
|
|
|
|
box->descendant_x1 = box->descendant_y1 = 0;
|
|
|
|
for (i = 0; i != 4; i++)
|
|
|
|
box->margin[i] = box->padding[i] = box->border[i] = 0;
|
2004-08-26 03:56:49 +04:00
|
|
|
box->scroll_x = box->scroll_y = 0;
|
2004-08-14 16:57:02 +04:00
|
|
|
box->min_width = 0;
|
2002-09-18 23:36:28 +04:00
|
|
|
box->max_width = UNKNOWN_MAX_WIDTH;
|
2004-08-14 16:57:02 +04:00
|
|
|
box->text = NULL;
|
|
|
|
box->length = 0;
|
2003-07-05 01:17:53 +04:00
|
|
|
box->space = 0;
|
2003-09-10 01:43:44 +04:00
|
|
|
box->clone = 0;
|
2003-09-20 01:23:19 +04:00
|
|
|
box->style_clone = 0;
|
2004-12-10 01:22:13 +03:00
|
|
|
box->href = href1;
|
|
|
|
box->title = title1;
|
2004-08-14 16:57:02 +04:00
|
|
|
box->columns = 1;
|
|
|
|
box->rows = 1;
|
2003-07-07 01:10:12 +04:00
|
|
|
box->start_column = 0;
|
2004-08-14 16:57:02 +04:00
|
|
|
box->next = NULL;
|
|
|
|
box->prev = NULL;
|
|
|
|
box->children = NULL;
|
|
|
|
box->last = NULL;
|
|
|
|
box->parent = NULL;
|
|
|
|
box->float_children = NULL;
|
|
|
|
box->next_float = NULL;
|
|
|
|
box->col = NULL;
|
|
|
|
box->font = NULL;
|
|
|
|
box->gadget = NULL;
|
|
|
|
box->usemap = NULL;
|
2004-12-10 01:22:13 +03:00
|
|
|
box->id = id1;
|
2004-08-14 16:57:02 +04:00
|
|
|
box->background = NULL;
|
|
|
|
box->object = NULL;
|
|
|
|
box->object_params = NULL;
|
|
|
|
|
2002-06-27 03:27:30 +04:00
|
|
|
return box;
|
|
|
|
}
|
2002-05-04 23:57:18 +04:00
|
|
|
|
2002-09-12 01:19:24 +04:00
|
|
|
|
2003-10-09 19:22:48 +04:00
|
|
|
/**
|
|
|
|
* Insert a new box as a sibling to a box in a tree.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void box_insert_sibling(struct box *box, struct box *new_box)
|
|
|
|
{
|
|
|
|
new_box->parent = box->parent;
|
|
|
|
new_box->prev = box;
|
|
|
|
new_box->next = box->next;
|
|
|
|
box->next = new_box;
|
|
|
|
if (new_box->next)
|
|
|
|
new_box->next->prev = new_box;
|
|
|
|
else if (new_box->parent)
|
|
|
|
new_box->parent->last = new_box;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-04-15 21:53:00 +04:00
|
|
|
/**
|
2004-12-10 01:22:13 +03:00
|
|
|
* Construct a box tree from an xml tree and stylesheets.
|
|
|
|
*
|
|
|
|
* \param n xml tree
|
|
|
|
* \param c content of type CONTENT_HTML to construct box tree in
|
|
|
|
* \return true on success, false on memory exhaustion
|
2003-04-15 21:53:00 +04:00
|
|
|
*/
|
|
|
|
|
2004-12-10 01:22:13 +03:00
|
|
|
bool xml_to_box(xmlNode *n, struct content *c)
|
2003-04-15 21:53:00 +04:00
|
|
|
{
|
2004-10-18 01:10:19 +04:00
|
|
|
struct box root;
|
2004-08-07 02:19:13 +04:00
|
|
|
struct box_status status = {c, 0, 0, 0, 0};
|
2004-12-10 01:22:13 +03:00
|
|
|
struct box *inline_container = 0;
|
2003-04-15 21:53:00 +04:00
|
|
|
|
|
|
|
assert(c->type == CONTENT_HTML);
|
|
|
|
|
2004-10-18 01:10:19 +04:00
|
|
|
root.type = BOX_BLOCK;
|
|
|
|
root.style = NULL;
|
|
|
|
root.next = NULL;
|
|
|
|
root.prev = NULL;
|
|
|
|
root.children = NULL;
|
|
|
|
root.last = NULL;
|
|
|
|
root.parent = NULL;
|
|
|
|
root.float_children = NULL;
|
|
|
|
root.next_float = NULL;
|
2003-04-15 21:53:00 +04:00
|
|
|
|
2004-12-10 01:22:13 +03:00
|
|
|
c->data.html.style = malloc(sizeof (struct css_style));
|
|
|
|
if (!c->data.html.style)
|
|
|
|
return false;
|
2003-04-15 21:53:00 +04:00
|
|
|
memcpy(c->data.html.style, &css_base_style, sizeof(struct css_style));
|
2004-10-18 01:10:19 +04:00
|
|
|
c->data.html.style->font_size.value.length.value =
|
|
|
|
option_font_size * 0.1;
|
2004-07-06 00:19:52 +04:00
|
|
|
c->data.html.fonts = nsfont_new_set();
|
2004-12-10 01:22:13 +03:00
|
|
|
if (!c->data.html.fonts) {
|
|
|
|
free(c->data.html.style);
|
|
|
|
return false;
|
|
|
|
}
|
2003-04-15 21:53:00 +04:00
|
|
|
|
|
|
|
c->data.html.object_count = 0;
|
2004-12-10 01:22:13 +03:00
|
|
|
c->data.html.object = 0;
|
2003-04-15 21:53:00 +04:00
|
|
|
|
2004-12-10 01:22:13 +03:00
|
|
|
convert_xml_to_box(n, c, c->data.html.style, &root, &inline_container,
|
|
|
|
status);
|
2004-10-18 01:10:19 +04:00
|
|
|
box_normalise_block(&root, c->data.html.box_pool);
|
|
|
|
|
|
|
|
c->data.html.layout = root.children;
|
|
|
|
c->data.html.layout->parent = NULL;
|
2004-12-10 01:22:13 +03:00
|
|
|
|
|
|
|
return true;
|
2003-04-15 21:53:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-07-05 20:16:15 +04:00
|
|
|
/* mapping from CSS display to box type
|
|
|
|
* this table must be in sync with css/css_enums */
|
2004-08-14 18:30:12 +04:00
|
|
|
static const box_type box_map[] = {
|
2003-07-05 20:16:15 +04:00
|
|
|
0, /*CSS_DISPLAY_INHERIT,*/
|
|
|
|
BOX_INLINE, /*CSS_DISPLAY_INLINE,*/
|
|
|
|
BOX_BLOCK, /*CSS_DISPLAY_BLOCK,*/
|
|
|
|
BOX_BLOCK, /*CSS_DISPLAY_LIST_ITEM,*/
|
|
|
|
BOX_INLINE, /*CSS_DISPLAY_RUN_IN,*/
|
2003-09-22 02:47:08 +04:00
|
|
|
BOX_INLINE_BLOCK, /*CSS_DISPLAY_INLINE_BLOCK,*/
|
2003-07-05 20:16:15 +04:00
|
|
|
BOX_TABLE, /*CSS_DISPLAY_TABLE,*/
|
|
|
|
BOX_TABLE, /*CSS_DISPLAY_INLINE_TABLE,*/
|
|
|
|
BOX_TABLE_ROW_GROUP, /*CSS_DISPLAY_TABLE_ROW_GROUP,*/
|
|
|
|
BOX_TABLE_ROW_GROUP, /*CSS_DISPLAY_TABLE_HEADER_GROUP,*/
|
|
|
|
BOX_TABLE_ROW_GROUP, /*CSS_DISPLAY_TABLE_FOOTER_GROUP,*/
|
|
|
|
BOX_TABLE_ROW, /*CSS_DISPLAY_TABLE_ROW,*/
|
|
|
|
BOX_INLINE, /*CSS_DISPLAY_TABLE_COLUMN_GROUP,*/
|
|
|
|
BOX_INLINE, /*CSS_DISPLAY_TABLE_COLUMN,*/
|
|
|
|
BOX_TABLE_CELL, /*CSS_DISPLAY_TABLE_CELL,*/
|
|
|
|
BOX_INLINE /*CSS_DISPLAY_TABLE_CAPTION,*/
|
|
|
|
};
|
|
|
|
|
2004-12-10 01:22:13 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Recursively construct a box tree from an xml tree and stylesheets.
|
|
|
|
*
|
|
|
|
* \param n fragment of xml tree
|
|
|
|
* \param content content of type CONTENT_HTML that is being processed
|
|
|
|
* \param parent_style style at this point in xml tree
|
|
|
|
* \param parent parent in box tree
|
|
|
|
* \param inline_container current inline container box, or 0, updated to
|
|
|
|
* new current inline container on exit
|
|
|
|
* \param status status for forms etc.
|
|
|
|
* \return true on success, false on memory exhaustion
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool convert_xml_to_box(xmlNode *n, struct content *content,
|
|
|
|
struct css_style *parent_style,
|
|
|
|
struct box *parent, struct box **inline_container,
|
2004-05-21 18:26:59 +04:00
|
|
|
struct box_status status)
|
2002-05-04 23:57:18 +04:00
|
|
|
{
|
2004-12-10 01:22:13 +03:00
|
|
|
struct box *box = 0;
|
|
|
|
struct box *inline_container_c;
|
|
|
|
struct css_style *style = 0;
|
|
|
|
xmlNode *c;
|
|
|
|
char *s;
|
|
|
|
xmlChar *title0, *id0;
|
|
|
|
char *title = 0, *id = 0;
|
2004-05-21 18:26:59 +04:00
|
|
|
bool convert_children = true;
|
2003-09-20 01:23:19 +04:00
|
|
|
char *href_in = status.href;
|
2002-05-04 23:57:18 +04:00
|
|
|
|
2004-12-10 01:22:13 +03:00
|
|
|
assert(n);
|
|
|
|
assert(parent_style);
|
|
|
|
assert(parent);
|
|
|
|
assert(inline_container);
|
2002-09-11 18:24:02 +04:00
|
|
|
|
2002-05-04 23:57:18 +04:00
|
|
|
if (n->type == XML_ELEMENT_NODE) {
|
2003-07-05 01:17:53 +04:00
|
|
|
struct element_entry *element;
|
|
|
|
|
2004-03-30 15:45:48 +04:00
|
|
|
gui_multitask();
|
|
|
|
|
2004-12-10 01:22:13 +03:00
|
|
|
style = box_get_style(content, parent_style, n);
|
2003-04-13 16:50:10 +04:00
|
|
|
if (style->display == CSS_DISPLAY_NONE) {
|
|
|
|
free(style);
|
2003-09-20 01:23:19 +04:00
|
|
|
goto end;
|
2003-04-13 16:50:10 +04:00
|
|
|
}
|
2003-04-15 21:53:00 +04:00
|
|
|
/* floats are treated as blocks */
|
2004-12-10 01:22:13 +03:00
|
|
|
if (style->float_ == CSS_FLOAT_LEFT ||
|
|
|
|
style->float_ == CSS_FLOAT_RIGHT)
|
2003-04-15 21:53:00 +04:00
|
|
|
if (style->display == CSS_DISPLAY_INLINE)
|
|
|
|
style->display = CSS_DISPLAY_BLOCK;
|
2002-08-12 03:01:02 +04:00
|
|
|
|
2003-07-01 02:21:51 +04:00
|
|
|
/* extract title attribute, if present */
|
2004-12-10 01:22:13 +03:00
|
|
|
if ((title0 = xmlGetProp(n, (const xmlChar *) "title"))) {
|
2004-07-06 00:19:52 +04:00
|
|
|
status.title = title = squash_whitespace(title0);
|
2004-05-11 20:40:12 +04:00
|
|
|
xmlFree(title0);
|
2004-12-10 01:22:13 +03:00
|
|
|
if (!title)
|
|
|
|
goto no_memory;
|
2003-07-01 02:21:51 +04:00
|
|
|
}
|
|
|
|
|
2004-08-07 02:19:13 +04:00
|
|
|
/* extract id attribute, if present */
|
2004-12-10 01:22:13 +03:00
|
|
|
if ((id0 = xmlGetProp(n, (const xmlChar *) "id"))) {
|
|
|
|
status.id = id = squash_whitespace(id0);
|
|
|
|
xmlFree(id0);
|
|
|
|
if (!id)
|
|
|
|
goto no_memory;
|
2004-08-07 02:19:13 +04:00
|
|
|
}
|
|
|
|
|
2003-01-07 02:53:40 +03:00
|
|
|
/* special elements */
|
2003-07-05 01:17:53 +04:00
|
|
|
element = bsearch((const char *) n->name, element_table,
|
|
|
|
ELEMENT_TABLE_COUNT, sizeof(element_table[0]),
|
|
|
|
(int (*)(const void *, const void *)) strcmp);
|
2004-12-10 01:22:13 +03:00
|
|
|
if (element) {
|
2003-07-05 20:16:15 +04:00
|
|
|
/* a special convert function exists for this element */
|
2004-12-10 01:22:13 +03:00
|
|
|
struct box_result res =
|
|
|
|
element->convert(n, &status, style);
|
2003-07-05 01:17:53 +04:00
|
|
|
box = res.box;
|
|
|
|
convert_children = res.convert_children;
|
2004-12-10 01:22:13 +03:00
|
|
|
if (res.memory_error)
|
|
|
|
goto no_memory;
|
|
|
|
if (!box) {
|
2003-07-05 20:16:15 +04:00
|
|
|
/* no box for this element */
|
2004-12-10 01:22:13 +03:00
|
|
|
assert(!convert_children);
|
2003-09-20 01:23:19 +04:00
|
|
|
free(style);
|
|
|
|
goto end;
|
2003-07-05 20:16:15 +04:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* general element */
|
2004-08-07 02:19:13 +04:00
|
|
|
box = box_create(style, status.href, title, id,
|
2004-01-02 15:04:04 +03:00
|
|
|
content->data.html.box_pool);
|
2004-12-10 01:22:13 +03:00
|
|
|
if (!box)
|
|
|
|
goto no_memory;
|
2003-01-07 02:53:40 +03:00
|
|
|
}
|
2004-04-18 19:19:53 +04:00
|
|
|
/* set box type from style if it has not been set already */
|
|
|
|
if (box->type == BOX_INLINE)
|
|
|
|
box->type = box_map[style->display];
|
2003-01-07 02:53:40 +03:00
|
|
|
|
|
|
|
} else if (n->type == XML_TEXT_NODE) {
|
2003-10-08 01:34:39 +04:00
|
|
|
/* text node: added to inline container below */
|
|
|
|
|
|
|
|
} else {
|
|
|
|
/* not an element or text node: ignore it (eg. comment) */
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
content->size += sizeof(struct box) + sizeof(struct css_style);
|
|
|
|
|
|
|
|
if (n->type == XML_TEXT_NODE &&
|
|
|
|
(parent_style->white_space == CSS_WHITE_SPACE_NORMAL ||
|
|
|
|
parent_style->white_space == CSS_WHITE_SPACE_NOWRAP)) {
|
2004-07-06 00:19:52 +04:00
|
|
|
char *text = squash_whitespace(n->content);
|
2004-12-10 01:22:13 +03:00
|
|
|
if (!text)
|
|
|
|
goto no_memory;
|
2003-03-26 00:51:29 +03:00
|
|
|
|
2003-07-05 01:17:53 +04:00
|
|
|
/* if the text is just a space, combine it with the preceding
|
|
|
|
* text node, if any */
|
2003-01-07 02:53:40 +03:00
|
|
|
if (text[0] == ' ' && text[1] == 0) {
|
2004-12-10 01:22:13 +03:00
|
|
|
if (*inline_container) {
|
|
|
|
assert((*inline_container)->last != 0);
|
|
|
|
(*inline_container)->last->space = 1;
|
2003-01-07 02:53:40 +03:00
|
|
|
}
|
2004-05-21 18:26:59 +04:00
|
|
|
free(text);
|
2003-09-20 01:23:19 +04:00
|
|
|
goto end;
|
2002-12-31 01:56:30 +03:00
|
|
|
}
|
2003-07-05 01:17:53 +04:00
|
|
|
|
2004-12-10 01:22:13 +03:00
|
|
|
if (!*inline_container) {
|
2003-10-08 01:34:39 +04:00
|
|
|
/* this is the first inline node: make a container */
|
2004-12-10 01:22:13 +03:00
|
|
|
*inline_container = box_create(0, 0, 0, 0,
|
2004-01-02 15:04:04 +03:00
|
|
|
content->data.html.box_pool);
|
2004-12-10 01:22:13 +03:00
|
|
|
if (!*inline_container) {
|
|
|
|
free(text);
|
|
|
|
goto no_memory;
|
|
|
|
}
|
|
|
|
(*inline_container)->type = BOX_INLINE_CONTAINER;
|
|
|
|
box_add_child(parent, *inline_container);
|
2003-10-08 01:34:39 +04:00
|
|
|
}
|
|
|
|
|
2004-08-07 02:19:13 +04:00
|
|
|
box = box_create(parent_style, status.href, title, id,
|
2004-01-02 15:04:04 +03:00
|
|
|
content->data.html.box_pool);
|
2004-12-10 01:22:13 +03:00
|
|
|
if (!box) {
|
|
|
|
free(text);
|
|
|
|
goto no_memory;
|
|
|
|
}
|
2003-10-25 04:35:49 +04:00
|
|
|
box->text = text;
|
2003-09-20 01:23:19 +04:00
|
|
|
box->style_clone = 1;
|
2003-07-05 01:17:53 +04:00
|
|
|
box->length = strlen(text);
|
2004-07-06 00:19:52 +04:00
|
|
|
/* strip ending space char off */
|
|
|
|
if (box->length > 1 && text[box->length - 1] == ' ') {
|
2003-07-05 01:17:53 +04:00
|
|
|
box->space = 1;
|
|
|
|
box->length--;
|
|
|
|
}
|
2004-03-15 01:49:40 +03:00
|
|
|
if (parent_style->text_transform != CSS_TEXT_TRANSFORM_NONE)
|
|
|
|
box_text_transform(box->text, box->length,
|
|
|
|
parent_style->text_transform);
|
2003-10-08 01:34:39 +04:00
|
|
|
if (parent_style->white_space == CSS_WHITE_SPACE_NOWRAP) {
|
2003-12-27 05:03:48 +03:00
|
|
|
unsigned int i;
|
2004-07-06 00:19:52 +04:00
|
|
|
for (i = 0; i != box->length && text[i] != ' '; ++i)
|
2004-12-10 01:22:13 +03:00
|
|
|
; /* no body */
|
2004-07-06 00:19:52 +04:00
|
|
|
if (i != box->length) {
|
|
|
|
/* there is a space in text block and we
|
|
|
|
* want all spaces to be converted to NBSP
|
|
|
|
*/
|
2004-12-10 01:22:13 +03:00
|
|
|
box->text = cnv_space2nbsp(text);
|
|
|
|
if (!box->text) {
|
|
|
|
free(text);
|
|
|
|
goto no_memory;
|
|
|
|
}
|
2004-07-06 00:19:52 +04:00
|
|
|
}
|
2003-10-08 01:34:39 +04:00
|
|
|
}
|
2004-07-06 00:19:52 +04:00
|
|
|
box->font = nsfont_open(content->data.html.fonts, box->style);
|
2003-07-05 01:17:53 +04:00
|
|
|
|
2004-12-10 01:22:13 +03:00
|
|
|
box_add_child(*inline_container, box);
|
2004-07-06 00:19:52 +04:00
|
|
|
if (box->text[0] == ' ') {
|
2003-10-08 01:34:39 +04:00
|
|
|
box->length--;
|
2004-07-06 00:19:52 +04:00
|
|
|
memmove(box->text, &box->text[1], box->length);
|
|
|
|
if (box->prev != NULL)
|
2003-10-08 01:34:39 +04:00
|
|
|
box->prev->space = 1;
|
|
|
|
}
|
2003-09-20 01:23:19 +04:00
|
|
|
goto end;
|
2003-01-07 02:53:40 +03:00
|
|
|
|
2003-10-08 01:34:39 +04:00
|
|
|
} else if (n->type == XML_TEXT_NODE) {
|
|
|
|
/* white-space: pre */
|
2004-07-06 00:19:52 +04:00
|
|
|
char *text = cnv_space2nbsp(n->content);
|
2003-10-08 01:34:39 +04:00
|
|
|
char *current;
|
|
|
|
assert(parent_style->white_space == CSS_WHITE_SPACE_PRE);
|
2004-12-10 01:22:13 +03:00
|
|
|
if (!text)
|
|
|
|
goto no_memory;
|
2004-03-15 01:49:40 +03:00
|
|
|
if (parent_style->text_transform != CSS_TEXT_TRANSFORM_NONE)
|
|
|
|
box_text_transform(text, strlen(text),
|
|
|
|
parent_style->text_transform);
|
2003-10-08 01:34:39 +04:00
|
|
|
current = text;
|
|
|
|
do {
|
|
|
|
size_t len = strcspn(current, "\r\n");
|
|
|
|
char old = current[len];
|
|
|
|
current[len] = 0;
|
2004-12-10 01:22:13 +03:00
|
|
|
if (!*inline_container) {
|
|
|
|
*inline_container = box_create(0, 0, 0, 0,
|
2004-01-02 15:04:04 +03:00
|
|
|
content->data.html.box_pool);
|
2004-12-10 01:22:13 +03:00
|
|
|
if (!*inline_container) {
|
|
|
|
free(text);
|
|
|
|
goto no_memory;
|
|
|
|
}
|
|
|
|
(*inline_container)->type =
|
|
|
|
BOX_INLINE_CONTAINER;
|
|
|
|
box_add_child(parent, *inline_container);
|
2003-10-08 01:34:39 +04:00
|
|
|
}
|
2004-01-02 15:04:04 +03:00
|
|
|
box = box_create(parent_style, status.href, title,
|
2004-08-07 02:19:13 +04:00
|
|
|
id, content->data.html.box_pool);
|
2004-12-10 01:22:13 +03:00
|
|
|
if (!box) {
|
|
|
|
free(text);
|
|
|
|
goto no_memory;
|
|
|
|
}
|
2003-10-08 01:34:39 +04:00
|
|
|
box->type = BOX_INLINE;
|
|
|
|
box->style_clone = 1;
|
2004-12-10 01:22:13 +03:00
|
|
|
box->text = strdup(current);
|
|
|
|
if (!box->text) {
|
|
|
|
free(text);
|
|
|
|
goto no_memory;
|
|
|
|
}
|
2003-10-08 01:34:39 +04:00
|
|
|
box->length = strlen(box->text);
|
2004-12-10 01:22:13 +03:00
|
|
|
box->font = nsfont_open(content->data.html.fonts,
|
|
|
|
box->style);
|
|
|
|
box_add_child(*inline_container, box);
|
2003-10-08 01:34:39 +04:00
|
|
|
current[len] = old;
|
|
|
|
current += len;
|
2003-10-08 03:47:57 +04:00
|
|
|
if (current[0] == '\r' && current[1] == '\n') {
|
2003-10-08 01:34:39 +04:00
|
|
|
current += 2;
|
2004-12-10 01:22:13 +03:00
|
|
|
*inline_container = 0;
|
2003-10-08 03:47:57 +04:00
|
|
|
} else if (current[0] != 0) {
|
2003-10-08 01:34:39 +04:00
|
|
|
current++;
|
2004-12-10 01:22:13 +03:00
|
|
|
*inline_container = 0;
|
2003-10-08 03:47:57 +04:00
|
|
|
}
|
2003-10-08 01:34:39 +04:00
|
|
|
} while (*current);
|
2004-05-21 18:26:59 +04:00
|
|
|
free(text);
|
2003-10-08 01:34:39 +04:00
|
|
|
goto end;
|
2003-07-05 01:17:53 +04:00
|
|
|
|
2003-10-08 01:34:39 +04:00
|
|
|
} else if (box->type == BOX_INLINE ||
|
2003-09-22 02:47:08 +04:00
|
|
|
box->type == BOX_INLINE_BLOCK ||
|
2003-07-05 01:17:53 +04:00
|
|
|
style->float_ == CSS_FLOAT_LEFT ||
|
2004-04-18 19:19:53 +04:00
|
|
|
style->float_ == CSS_FLOAT_RIGHT ||
|
|
|
|
box->type == BOX_BR) {
|
2003-07-05 01:17:53 +04:00
|
|
|
/* this is an inline box */
|
2004-12-10 01:22:13 +03:00
|
|
|
if (!*inline_container) {
|
2003-01-02 16:26:43 +03:00
|
|
|
/* this is the first inline node: make a container */
|
2004-12-10 01:22:13 +03:00
|
|
|
*inline_container = box_create(0, 0, 0, 0,
|
2004-01-02 15:04:04 +03:00
|
|
|
content->data.html.box_pool);
|
2004-12-10 01:22:13 +03:00
|
|
|
if (!*inline_container)
|
|
|
|
goto no_memory;
|
|
|
|
(*inline_container)->type = BOX_INLINE_CONTAINER;
|
|
|
|
box_add_child(parent, *inline_container);
|
2002-05-22 01:32:35 +04:00
|
|
|
}
|
2003-01-07 02:53:40 +03:00
|
|
|
|
2004-04-18 19:19:53 +04:00
|
|
|
if (box->type == BOX_INLINE || box->type == BOX_BR) {
|
2003-07-05 20:16:15 +04:00
|
|
|
/* inline box: add to tree and recurse */
|
2004-12-10 01:22:13 +03:00
|
|
|
box_add_child(*inline_container, box);
|
2003-07-05 20:16:15 +04:00
|
|
|
if (convert_children) {
|
|
|
|
for (c = n->children; c != 0; c = c->next)
|
2004-12-10 01:22:13 +03:00
|
|
|
if (!convert_xml_to_box(c, content,
|
|
|
|
style, parent,
|
|
|
|
inline_container,
|
|
|
|
status))
|
|
|
|
goto no_memory;
|
2003-07-05 20:16:15 +04:00
|
|
|
}
|
2003-09-20 01:23:19 +04:00
|
|
|
goto end;
|
2003-09-22 02:47:08 +04:00
|
|
|
} else if (box->type == BOX_INLINE_BLOCK) {
|
|
|
|
/* inline block box: add to tree and recurse */
|
2004-12-10 01:22:13 +03:00
|
|
|
box_add_child(*inline_container, box);
|
2003-09-22 02:47:08 +04:00
|
|
|
if (convert_children) {
|
|
|
|
inline_container_c = 0;
|
|
|
|
for (c = n->children; c != 0; c = c->next)
|
2004-12-10 01:22:13 +03:00
|
|
|
if (!convert_xml_to_box(c, content,
|
|
|
|
style, box,
|
|
|
|
&inline_container_c,
|
|
|
|
status))
|
|
|
|
goto no_memory;
|
2003-09-22 02:47:08 +04:00
|
|
|
}
|
|
|
|
goto end;
|
2003-07-05 01:17:53 +04:00
|
|
|
} else {
|
2004-12-10 01:22:13 +03:00
|
|
|
/* float: insert a float box between the parent and
|
|
|
|
* current node */
|
|
|
|
assert(style->float_ == CSS_FLOAT_LEFT ||
|
|
|
|
style->float_ == CSS_FLOAT_RIGHT);
|
2004-08-07 02:19:13 +04:00
|
|
|
parent = box_create(0, status.href, title, id,
|
2004-01-02 15:04:04 +03:00
|
|
|
content->data.html.box_pool);
|
2004-12-10 01:22:13 +03:00
|
|
|
if (!parent)
|
|
|
|
goto no_memory;
|
2003-07-05 20:16:15 +04:00
|
|
|
if (style->float_ == CSS_FLOAT_LEFT)
|
|
|
|
parent->type = BOX_FLOAT_LEFT;
|
|
|
|
else
|
|
|
|
parent->type = BOX_FLOAT_RIGHT;
|
2004-12-10 01:22:13 +03:00
|
|
|
box_add_child(*inline_container, parent);
|
|
|
|
if (box->type == BOX_INLINE ||
|
|
|
|
box->type == BOX_INLINE_BLOCK)
|
2003-07-05 23:51:10 +04:00
|
|
|
box->type = BOX_BLOCK;
|
2002-05-05 01:17:06 +04:00
|
|
|
}
|
2002-06-29 00:14:04 +04:00
|
|
|
}
|
2002-05-05 01:17:06 +04:00
|
|
|
|
2003-07-05 01:17:53 +04:00
|
|
|
assert(n->type == XML_ELEMENT_NODE);
|
2003-07-05 20:16:15 +04:00
|
|
|
|
|
|
|
/* non-inline box: add to tree and recurse */
|
|
|
|
box_add_child(parent, box);
|
|
|
|
if (convert_children) {
|
|
|
|
inline_container_c = 0;
|
|
|
|
for (c = n->children; c != 0; c = c->next)
|
2004-12-10 01:22:13 +03:00
|
|
|
if (!convert_xml_to_box(c, content, style,
|
|
|
|
box, &inline_container_c, status))
|
|
|
|
goto no_memory;
|
2003-07-05 20:16:15 +04:00
|
|
|
}
|
|
|
|
if (style->float_ == CSS_FLOAT_NONE)
|
|
|
|
/* new inline container unless this is a float */
|
2004-12-10 01:22:13 +03:00
|
|
|
*inline_container = 0;
|
2003-07-05 01:17:53 +04:00
|
|
|
|
2004-08-14 18:30:12 +04:00
|
|
|
if ((s = (char *) xmlGetProp(n, (const xmlChar *) "colspan")) != NULL) {
|
2004-09-04 00:32:57 +04:00
|
|
|
box->columns = strtol(s, NULL, 10);
|
|
|
|
if ( MAX_SPAN < box->columns ) {
|
|
|
|
box->columns = 1;
|
|
|
|
}
|
2003-07-05 20:16:15 +04:00
|
|
|
xmlFree(s);
|
|
|
|
}
|
2004-08-14 18:30:12 +04:00
|
|
|
if ((s = (char *) xmlGetProp(n, (const xmlChar *) "rowspan")) != NULL) {
|
2004-09-04 00:32:57 +04:00
|
|
|
box->rows = strtol(s, NULL, 10);
|
|
|
|
if ( MAX_SPAN < box->rows ) {
|
2003-07-05 23:51:10 +04:00
|
|
|
box->rows = 1;
|
2004-09-04 00:32:57 +04:00
|
|
|
}
|
2003-07-05 23:51:10 +04:00
|
|
|
xmlFree(s);
|
|
|
|
}
|
2002-05-04 23:57:18 +04:00
|
|
|
|
2003-09-20 01:23:19 +04:00
|
|
|
end:
|
|
|
|
free(title);
|
2004-08-07 02:19:13 +04:00
|
|
|
free(id);
|
2003-09-20 01:23:19 +04:00
|
|
|
if (!href_in)
|
|
|
|
xmlFree(status.href);
|
|
|
|
|
2004-06-09 23:55:06 +04:00
|
|
|
/* Now fetch any background image for this box */
|
2004-06-10 03:13:55 +04:00
|
|
|
if (box && box->style && box->style->background_image.type ==
|
|
|
|
CSS_BACKGROUND_IMAGE_URI) {
|
|
|
|
char *url = strdup(box->style->background_image.uri);
|
2004-12-10 01:22:13 +03:00
|
|
|
if (!url)
|
|
|
|
return false;
|
2004-06-10 03:13:55 +04:00
|
|
|
/* start fetch */
|
|
|
|
html_fetch_object(content, url, box, image_types,
|
|
|
|
content->available_width, 1000, true);
|
|
|
|
}
|
2004-06-09 23:55:06 +04:00
|
|
|
|
2004-12-10 01:22:13 +03:00
|
|
|
return true;
|
|
|
|
|
|
|
|
no_memory:
|
|
|
|
free(title);
|
|
|
|
free(id);
|
|
|
|
if (!href_in)
|
|
|
|
xmlFree(status.href);
|
|
|
|
if (style && !box)
|
|
|
|
free(style);
|
|
|
|
|
|
|
|
return false;
|
2002-05-04 23:57:18 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-09-08 22:11:56 +04:00
|
|
|
/**
|
2004-12-13 01:00:30 +03:00
|
|
|
* Get the style for an element.
|
|
|
|
*
|
|
|
|
* \param c content of type CONTENT_HTML that is being processed
|
|
|
|
* \param parent_style style at this point in xml tree
|
|
|
|
* \param n node in xml tree
|
|
|
|
* \return the new style, or 0 on memory exhaustion
|
2003-07-05 01:17:53 +04:00
|
|
|
*
|
|
|
|
* The style is collected from three sources:
|
|
|
|
* 1. any styles for this element in the document stylesheet(s)
|
|
|
|
* 2. non-CSS HTML attributes
|
|
|
|
* 3. the 'style' attribute
|
2002-05-22 01:32:35 +04:00
|
|
|
*/
|
|
|
|
|
2004-06-09 23:55:06 +04:00
|
|
|
struct css_style * box_get_style(struct content *c,
|
2004-12-10 01:22:13 +03:00
|
|
|
struct css_style *parent_style,
|
|
|
|
xmlNode *n)
|
2002-05-22 01:32:35 +04:00
|
|
|
{
|
2004-12-13 01:00:30 +03:00
|
|
|
char *s;
|
2003-04-06 01:38:06 +04:00
|
|
|
unsigned int i;
|
2004-12-10 01:22:13 +03:00
|
|
|
unsigned int stylesheet_count = c->data.html.stylesheet_count;
|
2004-12-13 01:00:30 +03:00
|
|
|
struct content **stylesheet = c->data.html.stylesheet_content;
|
|
|
|
struct css_style *style;
|
|
|
|
struct css_style style_new;
|
|
|
|
char *url;
|
|
|
|
url_func_result res;
|
|
|
|
|
|
|
|
style = malloc(sizeof (struct css_style));
|
|
|
|
if (!style)
|
|
|
|
return 0;
|
2002-05-22 01:32:35 +04:00
|
|
|
|
|
|
|
memcpy(style, parent_style, sizeof(struct css_style));
|
2004-01-02 15:04:04 +03:00
|
|
|
memcpy(&style_new, &css_blank_style, sizeof(struct css_style));
|
2003-04-06 01:38:06 +04:00
|
|
|
for (i = 0; i != stylesheet_count; i++) {
|
2004-12-13 01:00:30 +03:00
|
|
|
if (stylesheet[i]) {
|
2003-04-06 01:38:06 +04:00
|
|
|
assert(stylesheet[i]->type == CONTENT_CSS);
|
2004-01-02 15:04:04 +03:00
|
|
|
css_get_style(stylesheet[i], n, &style_new);
|
2003-04-06 01:38:06 +04:00
|
|
|
}
|
|
|
|
}
|
2004-01-02 15:04:04 +03:00
|
|
|
css_cascade(style, &style_new);
|
2002-05-22 01:32:35 +04:00
|
|
|
|
2004-06-09 23:55:06 +04:00
|
|
|
/* This property only applies to the body element, if you believe
|
2004-12-13 01:00:30 +03:00
|
|
|
* the spec. Many browsers seem to allow it on other elements too,
|
|
|
|
* so let's be generic ;) */
|
|
|
|
if ((s = (char *) xmlGetProp(n, (const xmlChar *) "background"))) {
|
|
|
|
res = url_join(s, c->data.html.base_url, &url);
|
|
|
|
if (res == URL_FUNC_NOMEM) {
|
|
|
|
free(style);
|
|
|
|
return 0;
|
|
|
|
} else if (res == URL_FUNC_OK) {
|
|
|
|
/* if url is equivalent to the parent's url,
|
|
|
|
* we've got infinite inclusion: ignore */
|
|
|
|
if (strcmp(url, c->data.html.base_url) == 0)
|
|
|
|
free(url);
|
|
|
|
else {
|
|
|
|
style->background_image.type =
|
|
|
|
CSS_BACKGROUND_IMAGE_URI;
|
|
|
|
style->background_image.uri = url;
|
|
|
|
}
|
|
|
|
}
|
2004-07-13 18:03:02 +04:00
|
|
|
xmlFree(s);
|
2004-06-09 23:55:06 +04:00
|
|
|
}
|
|
|
|
|
2004-08-14 18:30:12 +04:00
|
|
|
if ((s = (char *) xmlGetProp(n, (const xmlChar *) "bgcolor")) != NULL) {
|
2002-12-27 23:35:32 +03:00
|
|
|
unsigned int r, g, b;
|
|
|
|
if (s[0] == '#' && sscanf(s + 1, "%2x%2x%2x", &r, &g, &b) == 3)
|
|
|
|
style->background_color = (b << 16) | (g << 8) | r;
|
2003-04-13 16:50:10 +04:00
|
|
|
else if (s[0] != '#')
|
|
|
|
style->background_color = named_colour(s);
|
2003-04-25 12:03:15 +04:00
|
|
|
xmlFree(s);
|
2002-12-27 23:35:32 +03:00
|
|
|
}
|
|
|
|
|
2004-08-14 18:30:12 +04:00
|
|
|
if ((s = (char *) xmlGetProp(n, (const xmlChar *) "color")) != NULL) {
|
2002-12-27 23:35:32 +03:00
|
|
|
unsigned int r, g, b;
|
|
|
|
if (s[0] == '#' && sscanf(s + 1, "%2x%2x%2x", &r, &g, &b) == 3)
|
|
|
|
style->color = (b << 16) | (g << 8) | r;
|
2003-04-13 16:50:10 +04:00
|
|
|
else if (s[0] != '#')
|
|
|
|
style->color = named_colour(s);
|
2003-04-25 12:03:15 +04:00
|
|
|
xmlFree(s);
|
2002-12-27 23:35:32 +03:00
|
|
|
}
|
|
|
|
|
2004-08-14 18:30:12 +04:00
|
|
|
if ((s = (char *) xmlGetProp(n, (const xmlChar *) "height")) != NULL) {
|
2003-08-28 00:09:57 +04:00
|
|
|
float value = atof(s);
|
2004-08-02 03:09:17 +04:00
|
|
|
if (value < 0 || strlen(s) == 0) {
|
|
|
|
/* ignore negative values and height="" */
|
2003-08-28 00:09:57 +04:00
|
|
|
} else if (strrchr(s, '%')) {
|
2004-12-13 01:00:30 +03:00
|
|
|
/* the specification doesn't make clear what
|
2004-08-14 18:30:12 +04:00
|
|
|
* percentage heights mean, so ignore them */
|
|
|
|
} else {
|
2003-08-28 00:09:57 +04:00
|
|
|
style->height.height = CSS_HEIGHT_LENGTH;
|
|
|
|
style->height.length.unit = CSS_UNIT_PX;
|
|
|
|
style->height.length.value = value;
|
2003-07-15 22:06:31 +04:00
|
|
|
}
|
2003-04-25 12:03:15 +04:00
|
|
|
xmlFree(s);
|
2003-01-07 02:53:40 +03:00
|
|
|
}
|
|
|
|
|
2003-09-20 03:36:17 +04:00
|
|
|
if (strcmp((const char *) n->name, "input") == 0) {
|
2004-08-14 18:30:12 +04:00
|
|
|
if ((s = (char *) xmlGetProp(n, (const xmlChar *) "size")) != NULL) {
|
2003-09-20 03:36:17 +04:00
|
|
|
int size = atoi(s);
|
|
|
|
if (0 < size) {
|
|
|
|
char *type = (char *) xmlGetProp(n, (const xmlChar *) "type");
|
|
|
|
style->width.width = CSS_WIDTH_LENGTH;
|
2004-05-04 02:05:40 +04:00
|
|
|
if (!type || strcasecmp(type, "text") == 0 ||
|
|
|
|
strcasecmp(type, "password") == 0)
|
2004-05-05 20:33:15 +04:00
|
|
|
/* in characters for text, password, file */
|
2003-09-20 03:36:17 +04:00
|
|
|
style->width.value.length.unit = CSS_UNIT_EX;
|
2004-05-05 20:33:15 +04:00
|
|
|
else if (strcasecmp(type, "file") != 0)
|
2003-09-20 03:36:17 +04:00
|
|
|
/* in pixels otherwise */
|
|
|
|
style->width.value.length.unit = CSS_UNIT_PX;
|
|
|
|
style->width.value.length.value = size;
|
|
|
|
if (type)
|
|
|
|
xmlFree(type);
|
|
|
|
}
|
|
|
|
xmlFree(s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-01-08 02:24:43 +03:00
|
|
|
if (strcmp((const char *) n->name, "body") == 0) {
|
2004-08-14 18:30:12 +04:00
|
|
|
if ((s = (char *) xmlGetProp(n, (const xmlChar *) "text")) != NULL) {
|
2003-01-08 02:24:43 +03:00
|
|
|
unsigned int r, g, b;
|
|
|
|
if (s[0] == '#' && sscanf(s + 1, "%2x%2x%2x", &r, &g, &b) == 3)
|
|
|
|
style->color = (b << 16) | (g << 8) | r;
|
2003-04-13 16:50:10 +04:00
|
|
|
else if (s[0] != '#')
|
|
|
|
style->color = named_colour(s);
|
2003-04-25 12:03:15 +04:00
|
|
|
xmlFree(s);
|
2003-01-08 02:24:43 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-08-14 18:30:12 +04:00
|
|
|
if ((s = (char *) xmlGetProp(n, (const xmlChar *) "width")) != NULL) {
|
2003-08-28 00:09:57 +04:00
|
|
|
float value = atof(s);
|
2004-08-02 03:09:17 +04:00
|
|
|
if (value < 0 || strlen(s) == 0) {
|
|
|
|
/* ignore negative values and width="" */
|
2003-08-28 00:09:57 +04:00
|
|
|
} else if (strrchr(s, '%')) {
|
2002-08-12 03:01:02 +04:00
|
|
|
style->width.width = CSS_WIDTH_PERCENT;
|
2003-08-28 00:09:57 +04:00
|
|
|
style->width.value.percent = value;
|
2002-08-12 03:01:02 +04:00
|
|
|
} else {
|
|
|
|
style->width.width = CSS_WIDTH_LENGTH;
|
|
|
|
style->width.value.length.unit = CSS_UNIT_PX;
|
2003-08-28 00:09:57 +04:00
|
|
|
style->width.value.length.value = value;
|
2002-08-12 03:01:02 +04:00
|
|
|
}
|
2003-04-25 12:03:15 +04:00
|
|
|
xmlFree(s);
|
2002-05-22 01:32:35 +04:00
|
|
|
}
|
|
|
|
|
2003-09-22 02:47:08 +04:00
|
|
|
if (strcmp((const char *) n->name, "textarea") == 0) {
|
2004-08-14 18:30:12 +04:00
|
|
|
if ((s = (char *) xmlGetProp(n, (const xmlChar *) "rows")) != NULL) {
|
2003-09-22 02:47:08 +04:00
|
|
|
int value = atoi(s);
|
|
|
|
if (0 < value) {
|
|
|
|
style->height.height = CSS_HEIGHT_LENGTH;
|
|
|
|
style->height.length.unit = CSS_UNIT_EM;
|
|
|
|
style->height.length.value = value;
|
|
|
|
}
|
|
|
|
xmlFree(s);
|
|
|
|
}
|
2004-08-14 18:30:12 +04:00
|
|
|
if ((s = (char *) xmlGetProp(n, (const xmlChar *) "cols")) != NULL) {
|
2003-09-22 02:47:08 +04:00
|
|
|
int value = atoi(s);
|
|
|
|
if (0 < value) {
|
|
|
|
style->width.width = CSS_WIDTH_LENGTH;
|
|
|
|
style->width.value.length.unit = CSS_UNIT_EX;
|
|
|
|
style->width.value.length.value = value;
|
|
|
|
}
|
|
|
|
xmlFree(s);
|
|
|
|
}
|
|
|
|
}
|
2003-10-25 04:35:49 +04:00
|
|
|
|
2004-12-06 00:42:08 +03:00
|
|
|
if (strcmp((const char *) n->name, "table") == 0) {
|
|
|
|
if ((s = (char *) xmlGetProp(n,
|
|
|
|
(const xmlChar *) "cellspacing"))) {
|
|
|
|
if (!strrchr(s, '%')) { /* % not implemented */
|
|
|
|
int value = atoi(s);
|
2004-12-10 01:22:13 +03:00
|
|
|
if (0 <= value) {
|
2004-12-06 00:42:08 +03:00
|
|
|
style->border_spacing.border_spacing =
|
|
|
|
CSS_BORDER_SPACING_LENGTH;
|
|
|
|
style->border_spacing.horz.unit =
|
|
|
|
style->border_spacing.vert.unit =
|
|
|
|
CSS_UNIT_PX;
|
2004-12-07 01:31:22 +03:00
|
|
|
style->border_spacing.horz.value =
|
2004-12-06 00:42:08 +03:00
|
|
|
style->border_spacing.vert.value =
|
|
|
|
value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-08-14 18:30:12 +04:00
|
|
|
if ((s = (char *) xmlGetProp(n, (const xmlChar *) "style")) != NULL) {
|
2004-01-02 15:04:04 +03:00
|
|
|
struct css_style astyle;
|
|
|
|
memcpy(&astyle, &css_empty_style, sizeof(struct css_style));
|
2004-06-11 16:51:40 +04:00
|
|
|
css_parse_property_list(c, &astyle, s);
|
2004-01-02 15:04:04 +03:00
|
|
|
css_cascade(style, &astyle);
|
2003-04-25 12:03:15 +04:00
|
|
|
xmlFree(s);
|
2002-05-22 01:32:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return style;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-03-15 01:49:40 +03:00
|
|
|
/**
|
2004-07-06 00:19:52 +04:00
|
|
|
* Apply the CSS text-transform property to given text for its ASCII chars.
|
2004-03-15 01:49:40 +03:00
|
|
|
*
|
|
|
|
* \param s string to transform
|
|
|
|
* \param len length of s
|
|
|
|
* \param tt transform type
|
|
|
|
*/
|
|
|
|
|
|
|
|
void box_text_transform(char *s, unsigned int len,
|
|
|
|
css_text_transform tt)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
if (len == 0)
|
|
|
|
return;
|
|
|
|
switch (tt) {
|
|
|
|
case CSS_TEXT_TRANSFORM_UPPERCASE:
|
2004-07-06 00:19:52 +04:00
|
|
|
for (i = 0; i < len; ++i)
|
|
|
|
if (s[i] < 0x80)
|
|
|
|
s[i] = toupper(s[i]);
|
2004-03-15 01:49:40 +03:00
|
|
|
break;
|
|
|
|
case CSS_TEXT_TRANSFORM_LOWERCASE:
|
2004-07-06 00:19:52 +04:00
|
|
|
for (i = 0; i < len; ++i)
|
|
|
|
if (s[i] < 0x80)
|
|
|
|
s[i] = tolower(s[i]);
|
2004-03-15 01:49:40 +03:00
|
|
|
break;
|
|
|
|
case CSS_TEXT_TRANSFORM_CAPITALIZE:
|
2004-07-06 00:19:52 +04:00
|
|
|
if (s[0] < 0x80)
|
|
|
|
s[0] = toupper(s[0]);
|
|
|
|
for (i = 1; i < len; ++i)
|
|
|
|
if (s[i] < 0x80 && isspace(s[i - 1]))
|
2004-03-15 01:49:40 +03:00
|
|
|
s[i] = toupper(s[i]);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-01-24 20:08:16 +03:00
|
|
|
/*
|
2003-07-05 01:17:53 +04:00
|
|
|
* Special case elements
|
|
|
|
*
|
|
|
|
* These functions are called by convert_xml_to_box when an element is being
|
|
|
|
* converted, according to the entries in element_table (top of file).
|
|
|
|
*
|
|
|
|
* The parameters are the xmlNode, a status structure for the conversion, and
|
|
|
|
* the style found for the element.
|
|
|
|
*
|
|
|
|
* If a box is created, it is returned in the result structure. The
|
|
|
|
* convert_children field should be 1 if convert_xml_to_box should convert the
|
|
|
|
* node's children recursively, 0 if it should ignore them (presumably they
|
2003-07-05 20:16:15 +04:00
|
|
|
* have been processed in some way by the function). If box is 0, no box will
|
|
|
|
* be created for that element, and convert_children must be 0.
|
2003-07-05 01:17:53 +04:00
|
|
|
*/
|
2004-05-21 18:26:59 +04:00
|
|
|
struct box_result box_a(xmlNode *n, struct box_status *status,
|
2003-07-05 01:17:53 +04:00
|
|
|
struct css_style *style)
|
|
|
|
{
|
2003-07-05 20:16:15 +04:00
|
|
|
struct box *box;
|
2004-08-07 02:19:13 +04:00
|
|
|
char *s, *s1;
|
|
|
|
char *id = status->id;
|
|
|
|
|
2004-08-14 18:30:12 +04:00
|
|
|
if ((s = (char *) xmlGetProp(n, (const xmlChar *) "href")) != NULL)
|
2003-07-05 01:17:53 +04:00
|
|
|
status->href = s;
|
2004-08-07 02:19:13 +04:00
|
|
|
|
|
|
|
/* name and id share the same namespace */
|
2004-08-14 18:30:12 +04:00
|
|
|
if ((s1 = (char *) xmlGetProp(n, (const xmlChar *) "name")) != NULL) {
|
2004-08-07 02:19:13 +04:00
|
|
|
if (status->id && strcmp(status->id, s1) == 0) {
|
|
|
|
/* both specified and they match => ok */
|
|
|
|
id = status->id;
|
|
|
|
}
|
2004-12-13 01:00:30 +03:00
|
|
|
else if (!status->id) {
|
2004-08-07 02:19:13 +04:00
|
|
|
/* only name specified */
|
|
|
|
id = squash_whitespace(s1);
|
2004-12-13 01:00:30 +03:00
|
|
|
if (!id) {
|
|
|
|
xmlFree(s1);
|
|
|
|
return (struct box_result) {0, false, true};
|
|
|
|
}
|
|
|
|
} else
|
2004-08-07 02:19:13 +04:00
|
|
|
/* both specified but no match */
|
|
|
|
id = 0;
|
|
|
|
|
|
|
|
xmlFree(s1);
|
|
|
|
}
|
|
|
|
|
|
|
|
box = box_create(style, status->href, status->title, id,
|
2004-01-02 15:04:04 +03:00
|
|
|
status->content->data.html.box_pool);
|
2004-08-07 02:19:13 +04:00
|
|
|
|
|
|
|
if (id && id != status->id)
|
|
|
|
free(id);
|
|
|
|
|
2004-12-13 01:00:30 +03:00
|
|
|
if (!box)
|
|
|
|
return (struct box_result) {0, false, true};
|
|
|
|
|
2004-05-21 18:26:59 +04:00
|
|
|
return (struct box_result) {box, true, false};
|
2003-07-05 01:17:53 +04:00
|
|
|
}
|
|
|
|
|
2004-05-21 18:26:59 +04:00
|
|
|
struct box_result box_body(xmlNode *n, struct box_status *status,
|
2003-08-31 01:45:03 +04:00
|
|
|
struct css_style *style)
|
|
|
|
{
|
|
|
|
struct box *box;
|
|
|
|
status->content->data.html.background_colour = style->background_color;
|
2004-08-14 18:30:12 +04:00
|
|
|
box = box_create(style, status->href, status->title, status->id,
|
2004-01-02 15:04:04 +03:00
|
|
|
status->content->data.html.box_pool);
|
2004-12-13 01:00:30 +03:00
|
|
|
if (!box)
|
|
|
|
return (struct box_result) {0, false, true};
|
2004-05-21 18:26:59 +04:00
|
|
|
return (struct box_result) {box, true, false};
|
2003-08-31 01:45:03 +04:00
|
|
|
}
|
|
|
|
|
2004-05-21 18:26:59 +04:00
|
|
|
struct box_result box_br(xmlNode *n, struct box_status *status,
|
2004-04-18 19:19:53 +04:00
|
|
|
struct css_style *style)
|
|
|
|
{
|
|
|
|
struct box *box;
|
2004-08-07 02:19:13 +04:00
|
|
|
box = box_create(style, status->href, status->title, status->id,
|
2004-04-18 19:19:53 +04:00
|
|
|
status->content->data.html.box_pool);
|
2004-12-13 01:00:30 +03:00
|
|
|
if (!box)
|
|
|
|
return (struct box_result) {0, false, true};
|
2004-04-18 19:19:53 +04:00
|
|
|
box->type = BOX_BR;
|
2004-05-21 18:26:59 +04:00
|
|
|
return (struct box_result) {box, false, false};
|
2004-04-18 19:19:53 +04:00
|
|
|
}
|
|
|
|
|
2004-05-21 18:26:59 +04:00
|
|
|
struct box_result box_image(xmlNode *n, struct box_status *status,
|
2003-07-05 01:17:53 +04:00
|
|
|
struct css_style *style)
|
|
|
|
{
|
|
|
|
struct box *box;
|
2004-03-27 01:16:31 +03:00
|
|
|
char *s, *url, *s1, *map;
|
2003-09-10 01:43:44 +04:00
|
|
|
xmlChar *s2;
|
2004-08-09 20:11:58 +04:00
|
|
|
url_func_result res;
|
2003-07-05 01:17:53 +04:00
|
|
|
|
2004-08-07 02:19:13 +04:00
|
|
|
box = box_create(style, status->href, status->title, status->id,
|
2004-01-02 15:04:04 +03:00
|
|
|
status->content->data.html.box_pool);
|
2004-12-13 01:00:30 +03:00
|
|
|
if (!box)
|
|
|
|
return (struct box_result) {0, false, true};
|
2003-07-05 01:17:53 +04:00
|
|
|
|
|
|
|
/* handle alt text */
|
2004-08-14 18:30:12 +04:00
|
|
|
if ((s2 = xmlGetProp(n, (const xmlChar *) "alt")) != NULL) {
|
2004-07-06 00:19:52 +04:00
|
|
|
box->text = squash_whitespace(s2);
|
2004-12-13 01:00:30 +03:00
|
|
|
xmlFree(s2);
|
|
|
|
if (!box->text)
|
|
|
|
return (struct box_result) {0, false, true};
|
2003-07-05 01:17:53 +04:00
|
|
|
box->length = strlen(box->text);
|
2004-07-06 00:19:52 +04:00
|
|
|
box->font = nsfont_open(status->content->data.html.fonts, style);
|
2003-09-10 01:43:44 +04:00
|
|
|
}
|
2003-07-05 01:17:53 +04:00
|
|
|
|
2004-03-27 01:16:31 +03:00
|
|
|
/* imagemap associated with this image */
|
2004-08-14 18:30:12 +04:00
|
|
|
if ((map = xmlGetProp(n, (const xmlChar *) "usemap")) != NULL) {
|
2004-12-13 01:00:30 +03:00
|
|
|
if (map[0] == '#')
|
|
|
|
box->usemap = strdup(map + 1);
|
|
|
|
else
|
|
|
|
box->usemap = strdup(map);
|
2004-07-13 18:03:02 +04:00
|
|
|
xmlFree(map);
|
2004-12-13 01:00:30 +03:00
|
|
|
if (!box->usemap) {
|
|
|
|
free(box->text);
|
|
|
|
return (struct box_result) {0, false, true};
|
|
|
|
}
|
2004-03-27 01:16:31 +03:00
|
|
|
}
|
|
|
|
|
2004-12-13 01:00:30 +03:00
|
|
|
/* img without src is an error */
|
|
|
|
if ((s = (char *) xmlGetProp(n, (const xmlChar *) "src")) == NULL)
|
|
|
|
return (struct box_result) {box, false, false};
|
|
|
|
|
2004-01-24 20:12:32 +03:00
|
|
|
/* remove leading and trailing whitespace */
|
|
|
|
s1 = strip(s);
|
2004-08-09 20:11:58 +04:00
|
|
|
res = url_join(s1, status->content->data.html.base_url, &url);
|
2004-12-13 01:00:30 +03:00
|
|
|
xmlFree(s);
|
|
|
|
if (res == URL_FUNC_NOMEM) {
|
|
|
|
free(box->text);
|
|
|
|
return (struct box_result) {0, false, true};
|
|
|
|
} else if (res == URL_FUNC_FAILED) {
|
2004-05-21 18:26:59 +04:00
|
|
|
return (struct box_result) {box, false, false};
|
2004-04-02 22:13:23 +04:00
|
|
|
}
|
2003-12-26 03:17:55 +03:00
|
|
|
|
2004-12-13 01:00:30 +03:00
|
|
|
if (strcmp(url, status->content->data.html.base_url) == 0)
|
|
|
|
/* if url is equivalent to the parent's url,
|
|
|
|
* we've got infinite inclusion: ignore */
|
|
|
|
return (struct box_result) {box, false, false};
|
2003-07-05 01:17:53 +04:00
|
|
|
|
|
|
|
/* start fetch */
|
2004-05-21 18:26:59 +04:00
|
|
|
html_fetch_object(status->content, url, box, image_types,
|
2004-06-10 03:13:55 +04:00
|
|
|
status->content->available_width, 1000, false);
|
2003-07-05 01:17:53 +04:00
|
|
|
|
2004-05-21 18:26:59 +04:00
|
|
|
return (struct box_result) {box, false, false};
|
2003-07-05 01:17:53 +04:00
|
|
|
}
|
|
|
|
|
2004-05-21 18:26:59 +04:00
|
|
|
struct box_result box_form(xmlNode *n, struct box_status *status,
|
2003-07-05 01:17:53 +04:00
|
|
|
struct css_style *style)
|
|
|
|
{
|
2004-12-13 01:00:30 +03:00
|
|
|
char *action, *method, *enctype;
|
|
|
|
form_method fmethod;
|
2003-07-05 20:16:15 +04:00
|
|
|
struct box *box;
|
2003-10-25 04:35:49 +04:00
|
|
|
struct form *form;
|
|
|
|
|
2004-08-07 02:19:13 +04:00
|
|
|
box = box_create(style, status->href, status->title, status->id,
|
2004-01-02 15:04:04 +03:00
|
|
|
status->content->data.html.box_pool);
|
2004-12-13 01:00:30 +03:00
|
|
|
if (!box)
|
|
|
|
return (struct box_result) {0, false, true};
|
2003-10-25 04:35:49 +04:00
|
|
|
|
2004-12-13 01:00:30 +03:00
|
|
|
if (!(action = (char *) xmlGetProp(n, (const xmlChar *) "action"))) {
|
2003-10-25 18:13:49 +04:00
|
|
|
/* the action attribute is required */
|
2004-05-21 18:26:59 +04:00
|
|
|
return (struct box_result) {box, true, false};
|
2003-10-25 04:35:49 +04:00
|
|
|
}
|
|
|
|
|
2004-12-13 01:00:30 +03:00
|
|
|
fmethod = method_GET;
|
|
|
|
if ((method = (char *) xmlGetProp(n, (const xmlChar *) "method"))) {
|
|
|
|
if (strcasecmp(method, "post") == 0) {
|
|
|
|
fmethod = method_POST_URLENC;
|
|
|
|
if ((enctype = (char *) xmlGetProp(n,
|
|
|
|
(const xmlChar *) "enctype"))) {
|
|
|
|
if (strcasecmp(enctype,
|
|
|
|
"multipart/form-data") == 0)
|
|
|
|
fmethod = method_POST_MULTIPART;
|
|
|
|
xmlFree(enctype);
|
2003-10-25 18:13:49 +04:00
|
|
|
}
|
|
|
|
}
|
2004-12-13 01:00:30 +03:00
|
|
|
xmlFree(method);
|
2003-10-25 04:35:49 +04:00
|
|
|
}
|
|
|
|
|
2004-12-13 01:00:30 +03:00
|
|
|
status->current_form = form = form_new(action, fmethod);
|
|
|
|
if (!form) {
|
|
|
|
xmlFree(action);
|
|
|
|
return (struct box_result) {0, false, true};
|
|
|
|
}
|
2003-10-25 04:35:49 +04:00
|
|
|
|
2004-05-21 18:26:59 +04:00
|
|
|
return (struct box_result) {box, true, false};
|
2003-07-05 01:17:53 +04:00
|
|
|
}
|
|
|
|
|
2004-05-21 18:26:59 +04:00
|
|
|
struct box_result box_textarea(xmlNode *n, struct box_status *status,
|
2003-07-05 01:17:53 +04:00
|
|
|
struct css_style *style)
|
|
|
|
{
|
2004-07-19 18:31:31 +04:00
|
|
|
/* A textarea is an INLINE_BLOCK containing a single INLINE_CONTAINER,
|
|
|
|
* which contains the text as runs of INLINE separated by BR. There is
|
|
|
|
* at least one INLINE. The first and last boxes are INLINE.
|
|
|
|
* Consecutive BR may not be present. These constraints are satisfied
|
|
|
|
* by using a 0-length INLINE for blank lines. */
|
|
|
|
|
2003-09-22 02:47:08 +04:00
|
|
|
xmlChar *content, *current;
|
2004-07-19 18:31:31 +04:00
|
|
|
struct box *box, *inline_container, *inline_box, *br_box;
|
|
|
|
char *s;
|
|
|
|
size_t len;
|
2003-07-05 01:17:53 +04:00
|
|
|
|
2004-08-07 02:19:13 +04:00
|
|
|
box = box_create(style, NULL, 0, status->id,
|
2004-01-02 15:04:04 +03:00
|
|
|
status->content->data.html.box_pool);
|
2004-12-13 01:00:30 +03:00
|
|
|
if (!box)
|
|
|
|
return (struct box_result) {0, false, true};
|
2004-04-18 19:19:53 +04:00
|
|
|
box->type = BOX_INLINE_BLOCK;
|
2004-05-21 18:26:59 +04:00
|
|
|
box->gadget = form_new_control(GADGET_TEXTAREA);
|
2004-12-13 01:00:30 +03:00
|
|
|
if (!box->gadget)
|
2004-05-21 18:26:59 +04:00
|
|
|
return (struct box_result) {0, false, true};
|
2003-10-02 02:48:39 +04:00
|
|
|
box->gadget->box = box;
|
2003-07-05 01:17:53 +04:00
|
|
|
|
2004-08-14 18:30:12 +04:00
|
|
|
if ((s = (char *) xmlGetProp(n, (const xmlChar *) "name")) != NULL) {
|
2004-05-21 18:26:59 +04:00
|
|
|
box->gadget->name = strdup(s);
|
|
|
|
xmlFree(s);
|
2004-12-13 01:00:30 +03:00
|
|
|
if (!box->gadget->name)
|
2004-05-21 18:26:59 +04:00
|
|
|
return (struct box_result) {0, false, true};
|
|
|
|
}
|
|
|
|
|
2004-08-07 02:19:13 +04:00
|
|
|
inline_container = box_create(0, 0, 0, 0,
|
2004-07-19 18:31:31 +04:00
|
|
|
status->content->data.html.box_pool);
|
2004-12-13 01:00:30 +03:00
|
|
|
if (!inline_container)
|
|
|
|
return (struct box_result) {0, false, true};
|
2004-07-19 18:31:31 +04:00
|
|
|
inline_container->type = BOX_INLINE_CONTAINER;
|
|
|
|
box_add_child(box, inline_container);
|
|
|
|
|
2003-09-22 02:47:08 +04:00
|
|
|
current = content = xmlNodeGetContent(n);
|
2004-07-19 18:31:31 +04:00
|
|
|
while (1) {
|
|
|
|
/* BOX_INLINE */
|
|
|
|
len = strcspn(current, "\r\n");
|
|
|
|
s = strndup(current, len);
|
|
|
|
if (!s) {
|
|
|
|
box_free(box);
|
|
|
|
xmlFree(content);
|
|
|
|
return (struct box_result) {NULL, false, false};
|
|
|
|
}
|
|
|
|
|
2004-08-07 02:19:13 +04:00
|
|
|
inline_box = box_create(style, 0, 0, 0,
|
2004-01-02 15:04:04 +03:00
|
|
|
status->content->data.html.box_pool);
|
2004-12-13 01:00:30 +03:00
|
|
|
if (!inline_box)
|
|
|
|
return (struct box_result) {0, false, true};
|
2003-09-22 02:47:08 +04:00
|
|
|
inline_box->type = BOX_INLINE;
|
|
|
|
inline_box->style_clone = 1;
|
2004-07-19 18:31:31 +04:00
|
|
|
inline_box->text = s;
|
|
|
|
inline_box->length = len;
|
|
|
|
inline_box->font = nsfont_open(status->content->data.html.fonts,
|
|
|
|
style);
|
2003-09-22 02:47:08 +04:00
|
|
|
box_add_child(inline_container, inline_box);
|
2004-07-19 18:31:31 +04:00
|
|
|
|
2003-09-22 02:47:08 +04:00
|
|
|
current += len;
|
2004-07-19 18:31:31 +04:00
|
|
|
if (current[0] == 0)
|
|
|
|
/* finished */
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* BOX_BR */
|
2004-08-07 02:19:13 +04:00
|
|
|
br_box = box_create(style, 0, 0, 0,
|
2004-07-19 18:31:31 +04:00
|
|
|
status->content->data.html.box_pool);
|
2004-12-13 01:00:30 +03:00
|
|
|
if (!br_box)
|
|
|
|
return (struct box_result) {0, false, true};
|
2004-07-19 18:31:31 +04:00
|
|
|
br_box->type = BOX_BR;
|
|
|
|
br_box->style_clone = 1;
|
|
|
|
box_add_child(inline_container, br_box);
|
|
|
|
|
2003-10-08 01:34:39 +04:00
|
|
|
if (current[0] == '\r' && current[1] == '\n')
|
|
|
|
current += 2;
|
2004-07-19 18:31:31 +04:00
|
|
|
else
|
2003-10-08 01:34:39 +04:00
|
|
|
current++;
|
2004-07-19 18:31:31 +04:00
|
|
|
}
|
2003-09-22 02:47:08 +04:00
|
|
|
xmlFree(content);
|
2003-07-05 01:17:53 +04:00
|
|
|
|
2004-12-13 01:00:30 +03:00
|
|
|
if (status->current_form)
|
|
|
|
form_add_control(status->current_form, box->gadget);
|
|
|
|
|
2004-05-21 18:26:59 +04:00
|
|
|
return (struct box_result) {box, false, false};
|
2003-07-05 01:17:53 +04:00
|
|
|
}
|
|
|
|
|
2004-05-21 18:26:59 +04:00
|
|
|
struct box_result box_select(xmlNode *n, struct box_status *status,
|
2003-07-05 01:17:53 +04:00
|
|
|
struct css_style *style)
|
|
|
|
{
|
2003-10-02 02:48:39 +04:00
|
|
|
struct box *box;
|
|
|
|
struct box *inline_container;
|
|
|
|
struct box *inline_box;
|
2004-05-21 18:26:59 +04:00
|
|
|
struct form_control *gadget;
|
2003-07-05 01:17:53 +04:00
|
|
|
char* s;
|
2003-10-02 02:48:39 +04:00
|
|
|
xmlNode *c, *c2;
|
2003-07-05 01:17:53 +04:00
|
|
|
|
2004-05-21 18:26:59 +04:00
|
|
|
gadget = form_new_control(GADGET_SELECT);
|
2004-05-22 02:51:02 +04:00
|
|
|
if (!gadget)
|
2004-05-21 18:26:59 +04:00
|
|
|
return (struct box_result) {0, false, true};
|
|
|
|
|
2003-10-02 02:48:39 +04:00
|
|
|
gadget->data.select.multiple = false;
|
2004-08-14 18:30:12 +04:00
|
|
|
if ((s = (char *) xmlGetProp(n, (const xmlChar *) "multiple")) != NULL) {
|
2003-10-02 02:48:39 +04:00
|
|
|
gadget->data.select.multiple = true;
|
|
|
|
xmlFree(s);
|
2003-07-05 01:17:53 +04:00
|
|
|
}
|
|
|
|
|
2003-10-02 02:48:39 +04:00
|
|
|
gadget->data.select.items = NULL;
|
|
|
|
gadget->data.select.last_item = NULL;
|
|
|
|
gadget->data.select.num_items = 0;
|
|
|
|
gadget->data.select.num_selected = 0;
|
2003-07-05 01:17:53 +04:00
|
|
|
|
2004-12-13 01:00:30 +03:00
|
|
|
for (c = n->children; c; c = c->next) {
|
2003-07-05 01:17:53 +04:00
|
|
|
if (strcmp((const char *) c->name, "option") == 0) {
|
2004-12-13 01:00:30 +03:00
|
|
|
if (!box_select_add_option(gadget, c))
|
|
|
|
goto no_memory;
|
2003-10-02 02:48:39 +04:00
|
|
|
} else if (strcmp((const char *) c->name, "optgroup") == 0) {
|
|
|
|
for (c2 = c->children; c2; c2 = c2->next) {
|
2004-12-13 01:00:30 +03:00
|
|
|
if (strcmp((const char *) c2->name,
|
|
|
|
"option") == 0) {
|
|
|
|
if (!box_select_add_option(gadget, c2))
|
|
|
|
goto no_memory;
|
2003-10-02 02:48:39 +04:00
|
|
|
}
|
|
|
|
}
|
2003-07-05 01:17:53 +04:00
|
|
|
}
|
|
|
|
}
|
2003-10-02 02:48:39 +04:00
|
|
|
|
|
|
|
if (gadget->data.select.num_items == 0) {
|
|
|
|
/* no options: ignore entire select */
|
2004-05-21 18:26:59 +04:00
|
|
|
form_free_control(gadget);
|
|
|
|
return (struct box_result) {0, false, false};
|
2003-10-02 02:48:39 +04:00
|
|
|
}
|
|
|
|
|
2004-08-14 18:30:12 +04:00
|
|
|
if ((s = (char *) xmlGetProp(n, (const xmlChar *) "name")) != NULL) {
|
2004-05-21 18:26:59 +04:00
|
|
|
gadget->name = strdup(s);
|
|
|
|
xmlFree(s);
|
2004-12-13 01:00:30 +03:00
|
|
|
if (!gadget->name)
|
|
|
|
goto no_memory;
|
2003-10-02 02:48:39 +04:00
|
|
|
}
|
|
|
|
|
2004-12-13 01:00:30 +03:00
|
|
|
box = box_create(style, NULL, 0, status->id,
|
|
|
|
status->content->data.html.box_pool);
|
|
|
|
if (!box)
|
|
|
|
goto no_memory;
|
2004-04-18 19:19:53 +04:00
|
|
|
box->type = BOX_INLINE_BLOCK;
|
2003-10-02 02:48:39 +04:00
|
|
|
box->gadget = gadget;
|
|
|
|
gadget->box = box;
|
|
|
|
|
2004-08-07 02:19:13 +04:00
|
|
|
inline_container = box_create(0, 0, 0, 0,
|
2004-01-02 15:04:04 +03:00
|
|
|
status->content->data.html.box_pool);
|
2004-12-13 01:00:30 +03:00
|
|
|
if (!inline_container)
|
|
|
|
goto no_memory;
|
2003-10-02 02:48:39 +04:00
|
|
|
inline_container->type = BOX_INLINE_CONTAINER;
|
2004-08-07 02:19:13 +04:00
|
|
|
inline_box = box_create(style, 0, 0, 0,
|
2004-01-02 15:04:04 +03:00
|
|
|
status->content->data.html.box_pool);
|
2004-12-13 01:00:30 +03:00
|
|
|
if (!inline_box)
|
|
|
|
goto no_memory;
|
2003-10-02 02:48:39 +04:00
|
|
|
inline_box->type = BOX_INLINE;
|
|
|
|
inline_box->style_clone = 1;
|
|
|
|
box_add_child(inline_container, inline_box);
|
|
|
|
box_add_child(box, inline_container);
|
|
|
|
|
|
|
|
if (!gadget->data.select.multiple &&
|
|
|
|
gadget->data.select.num_selected == 0) {
|
|
|
|
gadget->data.select.current = gadget->data.select.items;
|
2003-10-02 15:13:21 +04:00
|
|
|
gadget->data.select.current->initial_selected =
|
|
|
|
gadget->data.select.current->selected = true;
|
2003-10-02 02:48:39 +04:00
|
|
|
gadget->data.select.num_selected = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gadget->data.select.num_selected == 0)
|
2004-12-13 01:00:30 +03:00
|
|
|
inline_box->text = strdup(messages_get("Form_None"));
|
2003-10-02 02:48:39 +04:00
|
|
|
else if (gadget->data.select.num_selected == 1)
|
2004-12-13 01:00:30 +03:00
|
|
|
inline_box->text = strdup(gadget->data.select.current->text);
|
2003-10-02 02:48:39 +04:00
|
|
|
else
|
2004-12-13 01:00:30 +03:00
|
|
|
inline_box->text = strdup(messages_get("Form_Many"));
|
|
|
|
if (!inline_box->text)
|
|
|
|
goto no_memory;
|
2003-10-02 02:48:39 +04:00
|
|
|
|
|
|
|
inline_box->length = strlen(inline_box->text);
|
2004-07-06 00:19:52 +04:00
|
|
|
inline_box->font = nsfont_open(status->content->data.html.fonts, style);
|
2003-10-02 02:48:39 +04:00
|
|
|
|
2004-12-13 01:00:30 +03:00
|
|
|
if (status->current_form)
|
|
|
|
form_add_control(status->current_form, gadget);
|
2003-07-05 01:17:53 +04:00
|
|
|
|
2004-12-13 01:00:30 +03:00
|
|
|
return (struct box_result) {box, false, false};
|
2004-07-20 00:59:10 +04:00
|
|
|
|
2004-12-13 01:00:30 +03:00
|
|
|
no_memory:
|
|
|
|
form_free_control(gadget);
|
|
|
|
return (struct box_result) {0, false, true};
|
|
|
|
}
|
2004-07-06 00:19:52 +04:00
|
|
|
|
2003-10-02 02:48:39 +04:00
|
|
|
|
2004-12-13 01:00:30 +03:00
|
|
|
/**
|
|
|
|
* Add an option to a form select control.
|
|
|
|
*
|
|
|
|
* \param control select containing the option
|
|
|
|
* \param n xml element node for <option>
|
|
|
|
* \return true on success, false on memory exhaustion
|
|
|
|
*/
|
2003-07-05 01:17:53 +04:00
|
|
|
|
2004-12-13 01:00:30 +03:00
|
|
|
bool box_select_add_option(struct form_control *control, xmlNode *n)
|
|
|
|
{
|
|
|
|
char *value = 0;
|
|
|
|
char *text = 0;
|
|
|
|
bool selected;
|
|
|
|
xmlChar *content;
|
|
|
|
xmlChar *s;
|
|
|
|
|
|
|
|
content = xmlNodeGetContent(n);
|
|
|
|
if (!content)
|
|
|
|
goto no_memory;
|
|
|
|
text = squash_whitespace(content);
|
|
|
|
xmlFree(content);
|
|
|
|
if (!text)
|
|
|
|
goto no_memory;
|
2003-10-02 02:48:39 +04:00
|
|
|
|
2004-12-13 01:00:30 +03:00
|
|
|
if ((s = (char *) xmlGetProp(n, (const xmlChar *) "value"))) {
|
|
|
|
value = strdup(s);
|
2004-05-22 02:51:02 +04:00
|
|
|
xmlFree(s);
|
2004-12-13 01:00:30 +03:00
|
|
|
} else
|
|
|
|
value = strdup(text);
|
|
|
|
if (!value)
|
|
|
|
goto no_memory;
|
2003-10-25 18:13:49 +04:00
|
|
|
|
2004-12-13 01:00:30 +03:00
|
|
|
selected = xmlHasProp(n, (const xmlChar *) "selected");
|
2003-07-05 01:17:53 +04:00
|
|
|
|
2004-12-13 01:00:30 +03:00
|
|
|
if (!form_add_option(control, value, text, selected))
|
|
|
|
goto no_memory;
|
2003-07-05 01:17:53 +04:00
|
|
|
|
2004-12-13 01:00:30 +03:00
|
|
|
return true;
|
|
|
|
|
|
|
|
no_memory:
|
|
|
|
free(value);
|
|
|
|
free(text);
|
|
|
|
return false;
|
2003-07-05 01:17:53 +04:00
|
|
|
}
|
|
|
|
|
2004-07-20 00:59:10 +04:00
|
|
|
|
2004-05-21 18:26:59 +04:00
|
|
|
struct box_result box_input(xmlNode *n, struct box_status *status,
|
2003-07-05 01:17:53 +04:00
|
|
|
struct css_style *style)
|
|
|
|
{
|
2004-07-20 00:40:11 +04:00
|
|
|
struct box* box = NULL;
|
|
|
|
struct form_control *gadget = NULL;
|
2003-09-09 23:25:28 +04:00
|
|
|
char *s, *type, *url;
|
2004-08-09 20:11:58 +04:00
|
|
|
url_func_result res;
|
2003-07-05 01:17:53 +04:00
|
|
|
|
|
|
|
type = (char *) xmlGetProp(n, (const xmlChar *) "type");
|
|
|
|
|
2004-05-04 02:05:40 +04:00
|
|
|
if (type && strcasecmp(type, "password") == 0) {
|
|
|
|
box = box_input_text(n, status, style, true);
|
2003-09-29 03:41:07 +04:00
|
|
|
gadget = box->gadget;
|
2003-10-02 02:48:39 +04:00
|
|
|
gadget->box = box;
|
2004-05-04 02:05:40 +04:00
|
|
|
|
|
|
|
} else if (type && strcasecmp(type, "file") == 0) {
|
2004-08-07 02:19:13 +04:00
|
|
|
box = box_create(style, NULL, 0, status->id,
|
2004-05-04 02:05:40 +04:00
|
|
|
status->content->data.html.box_pool);
|
|
|
|
box->type = BOX_INLINE_BLOCK;
|
2004-05-21 18:26:59 +04:00
|
|
|
box->gadget = gadget = form_new_control(GADGET_FILE);
|
|
|
|
if (!gadget) {
|
|
|
|
box_free_box(box);
|
|
|
|
xmlFree(type);
|
|
|
|
return (struct box_result) {0, false, true};
|
|
|
|
}
|
2003-10-02 02:48:39 +04:00
|
|
|
gadget->box = box;
|
2004-07-06 00:19:52 +04:00
|
|
|
box->font = nsfont_open(status->content->data.html.fonts, style);
|
2004-05-04 02:05:40 +04:00
|
|
|
|
|
|
|
} else if (type && strcasecmp(type, "hidden") == 0) {
|
2003-07-05 20:16:15 +04:00
|
|
|
/* no box for hidden inputs */
|
2004-05-21 18:26:59 +04:00
|
|
|
gadget = form_new_control(GADGET_HIDDEN);
|
|
|
|
if (!gadget) {
|
|
|
|
xmlFree(type);
|
|
|
|
return (struct box_result) {0, false, true};
|
|
|
|
}
|
2003-07-05 01:17:53 +04:00
|
|
|
|
2004-08-14 18:30:12 +04:00
|
|
|
if ((s = (char *) xmlGetProp(n, (const xmlChar *) "value")) != NULL) {
|
2004-05-21 18:26:59 +04:00
|
|
|
gadget->value = strdup(s);
|
|
|
|
xmlFree(s);
|
|
|
|
if (!gadget->value) {
|
|
|
|
form_free_control(gadget);
|
|
|
|
xmlFree(type);
|
|
|
|
return (struct box_result) {0, false, true};
|
|
|
|
}
|
2004-07-20 00:40:11 +04:00
|
|
|
gadget->length = strlen(gadget->value);
|
2004-05-21 18:26:59 +04:00
|
|
|
}
|
2004-05-04 02:05:40 +04:00
|
|
|
|
|
|
|
} else if (type && (strcasecmp(type, "checkbox") == 0 ||
|
|
|
|
strcasecmp(type, "radio") == 0)) {
|
2004-08-07 02:19:13 +04:00
|
|
|
box = box_create(style, NULL, 0, status->id,
|
2004-01-02 15:04:04 +03:00
|
|
|
status->content->data.html.box_pool);
|
2004-07-20 00:40:11 +04:00
|
|
|
box->gadget = gadget = form_new_control((type[0] == 'c' || type[0] == 'C') ? GADGET_CHECKBOX : GADGET_RADIO);
|
2004-05-21 18:26:59 +04:00
|
|
|
if (!gadget) {
|
|
|
|
box_free_box(box);
|
|
|
|
xmlFree(type);
|
|
|
|
return (struct box_result) {0, false, true};
|
|
|
|
}
|
2003-10-02 02:48:39 +04:00
|
|
|
gadget->box = box;
|
2003-07-05 01:17:53 +04:00
|
|
|
|
2004-08-14 18:30:12 +04:00
|
|
|
if ((s = (char *) xmlGetProp(n, (const xmlChar *) "checked")) != NULL) {
|
2004-05-22 03:42:26 +04:00
|
|
|
gadget->selected = true;
|
2003-07-05 01:17:53 +04:00
|
|
|
xmlFree(s);
|
|
|
|
}
|
|
|
|
|
2004-08-14 18:30:12 +04:00
|
|
|
if ((s = (char *) xmlGetProp(n, (const xmlChar *) "value")) != NULL) {
|
2004-05-21 18:26:59 +04:00
|
|
|
gadget->value = strdup(s);
|
|
|
|
xmlFree(s);
|
|
|
|
if (!gadget->value) {
|
|
|
|
box_free_box(box);
|
|
|
|
xmlFree(type);
|
|
|
|
return (struct box_result) {0, false, true};
|
|
|
|
}
|
2004-07-20 00:40:11 +04:00
|
|
|
gadget->length = strlen(gadget->value);
|
2004-05-21 18:26:59 +04:00
|
|
|
}
|
2004-05-04 02:05:40 +04:00
|
|
|
|
|
|
|
} else if (type && (strcasecmp(type, "submit") == 0 ||
|
|
|
|
strcasecmp(type, "reset") == 0)) {
|
2004-05-21 18:26:59 +04:00
|
|
|
struct box_result result = box_button(n, status, style);
|
2003-09-27 03:22:00 +04:00
|
|
|
struct box *inline_container, *inline_box;
|
|
|
|
box = result.box;
|
2004-08-07 02:19:13 +04:00
|
|
|
inline_container = box_create(0, 0, 0, 0,
|
2004-01-02 15:04:04 +03:00
|
|
|
status->content->data.html.box_pool);
|
2003-09-27 03:22:00 +04:00
|
|
|
inline_container->type = BOX_INLINE_CONTAINER;
|
2004-08-07 02:19:13 +04:00
|
|
|
inline_box = box_create(style, 0, 0, 0,
|
2004-01-02 15:04:04 +03:00
|
|
|
status->content->data.html.box_pool);
|
2003-09-27 03:22:00 +04:00
|
|
|
inline_box->type = BOX_INLINE;
|
|
|
|
inline_box->style_clone = 1;
|
2004-07-06 00:19:52 +04:00
|
|
|
if (box->gadget->value != NULL)
|
|
|
|
inline_box->text = strdup(box->gadget->value);
|
2003-09-27 03:22:00 +04:00
|
|
|
else if (box->gadget->type == GADGET_SUBMIT)
|
2004-07-06 00:19:52 +04:00
|
|
|
inline_box->text = strdup(messages_get("Form_Submit"));
|
2003-07-05 01:17:53 +04:00
|
|
|
else
|
2004-07-06 00:19:52 +04:00
|
|
|
inline_box->text = strdup(messages_get("Form_Reset"));
|
|
|
|
if (inline_box->text == NULL) {
|
|
|
|
box_free(inline_box);
|
|
|
|
box_free(inline_container);
|
|
|
|
box_free(box);
|
|
|
|
xmlFree(type);
|
|
|
|
return (struct box_result) {NULL, false, false};
|
|
|
|
}
|
2003-09-27 03:22:00 +04:00
|
|
|
inline_box->length = strlen(inline_box->text);
|
2004-07-06 00:19:52 +04:00
|
|
|
inline_box->font = nsfont_open(status->content->data.html.fonts, style);
|
2003-09-27 03:22:00 +04:00
|
|
|
box_add_child(inline_container, inline_box);
|
|
|
|
box_add_child(box, inline_container);
|
2004-05-04 02:05:40 +04:00
|
|
|
|
|
|
|
} else if (type && strcasecmp(type, "button") == 0) {
|
2004-08-14 18:30:12 +04:00
|
|
|
struct box_result result = box_button(n, status, style);
|
2004-03-21 00:56:43 +03:00
|
|
|
struct box *inline_container, *inline_box;
|
|
|
|
box = result.box;
|
2004-08-07 02:19:13 +04:00
|
|
|
inline_container = box_create(0, 0, 0, 0,
|
2004-03-21 00:56:43 +03:00
|
|
|
status->content->data.html.box_pool);
|
|
|
|
inline_container->type = BOX_INLINE_CONTAINER;
|
2004-08-07 02:19:13 +04:00
|
|
|
inline_box = box_create(style, 0, 0, 0,
|
2004-03-21 00:56:43 +03:00
|
|
|
status->content->data.html.box_pool);
|
|
|
|
inline_box->type = BOX_INLINE;
|
|
|
|
inline_box->style_clone = 1;
|
2004-08-14 18:30:12 +04:00
|
|
|
if ((s = (char *) xmlGetProp(n, (const xmlChar *) "value")) != NULL) {
|
|
|
|
inline_box->text = s;
|
2004-03-21 00:56:43 +03:00
|
|
|
}
|
2004-03-21 01:15:40 +03:00
|
|
|
else {
|
2004-08-14 18:30:12 +04:00
|
|
|
inline_box->text = xstrdup("Button");
|
2004-03-21 01:15:40 +03:00
|
|
|
}
|
2004-03-21 00:56:43 +03:00
|
|
|
inline_box->length = strlen(inline_box->text);
|
2004-07-06 00:19:52 +04:00
|
|
|
inline_box->font = nsfont_open(status->content->data.html.fonts, style);
|
2004-03-21 00:56:43 +03:00
|
|
|
box_add_child(inline_container, inline_box);
|
|
|
|
box_add_child(box, inline_container);
|
2004-05-04 02:05:40 +04:00
|
|
|
|
|
|
|
} else if (type && strcasecmp(type, "image") == 0) {
|
2004-08-14 18:30:12 +04:00
|
|
|
box = box_create(style, NULL, 0, status->id,
|
2004-01-02 15:04:04 +03:00
|
|
|
status->content->data.html.box_pool);
|
2004-08-14 18:30:12 +04:00
|
|
|
box->gadget = gadget = form_new_control(GADGET_IMAGE);
|
2004-05-21 18:26:59 +04:00
|
|
|
if (!gadget) {
|
|
|
|
box_free_box(box);
|
|
|
|
xmlFree(type);
|
|
|
|
return (struct box_result) {0, false, true};
|
|
|
|
}
|
2003-10-02 02:48:39 +04:00
|
|
|
gadget->box = box;
|
2004-06-10 03:13:55 +04:00
|
|
|
gadget->type = GADGET_IMAGE;
|
2004-08-14 18:30:12 +04:00
|
|
|
if ((s = (char *) xmlGetProp(n, (const xmlChar*) "src")) != NULL) {
|
2004-08-09 20:11:58 +04:00
|
|
|
res = url_join(s, status->content->data.html.base_url, &url);
|
2004-07-13 18:03:02 +04:00
|
|
|
/* if url is equivalent to the parent's url,
|
|
|
|
* we've got infinite inclusion. stop it here.
|
|
|
|
* also bail if url_join failed.
|
|
|
|
*/
|
2004-08-09 20:11:58 +04:00
|
|
|
if (res == URL_FUNC_OK &&
|
|
|
|
strcasecmp(url, status->content->data.html.base_url) != 0)
|
2004-06-10 03:13:55 +04:00
|
|
|
html_fetch_object(status->content, url, box,
|
|
|
|
image_types,
|
|
|
|
status->content->available_width,
|
|
|
|
1000, false);
|
|
|
|
xmlFree(s);
|
|
|
|
}
|
2004-05-04 02:05:40 +04:00
|
|
|
|
|
|
|
} else {
|
|
|
|
/* the default type is "text" */
|
|
|
|
box = box_input_text(n, status, style, false);
|
|
|
|
gadget = box->gadget;
|
|
|
|
gadget->box = box;
|
2003-09-09 23:25:28 +04:00
|
|
|
}
|
2003-07-05 01:17:53 +04:00
|
|
|
|
|
|
|
if (type != 0)
|
|
|
|
xmlFree(type);
|
|
|
|
|
|
|
|
if (gadget != 0) {
|
2003-10-27 03:34:09 +03:00
|
|
|
if (status->current_form)
|
|
|
|
form_add_control(status->current_form, gadget);
|
2003-12-11 22:06:39 +03:00
|
|
|
else
|
2004-05-21 18:26:59 +04:00
|
|
|
gadget->form = 0;
|
|
|
|
s = (char *) xmlGetProp(n, (const xmlChar *) "name");
|
|
|
|
if (s) {
|
|
|
|
gadget->name = strdup(s);
|
|
|
|
xmlFree(s);
|
|
|
|
if (!gadget->name) {
|
|
|
|
box_free_box(box);
|
|
|
|
return (struct box_result) {0, false, true};
|
|
|
|
}
|
|
|
|
}
|
2003-07-05 01:17:53 +04:00
|
|
|
}
|
|
|
|
|
2004-05-21 18:26:59 +04:00
|
|
|
return (struct box_result) {box, false, false};
|
2003-07-05 01:17:53 +04:00
|
|
|
}
|
|
|
|
|
2004-05-21 18:26:59 +04:00
|
|
|
struct box *box_input_text(xmlNode *n, struct box_status *status,
|
2004-05-04 02:05:40 +04:00
|
|
|
struct css_style *style, bool password)
|
2003-09-29 03:41:07 +04:00
|
|
|
{
|
|
|
|
char *s;
|
2004-08-07 02:19:13 +04:00
|
|
|
struct box *box = box_create(style, 0, 0, status->id,
|
2004-01-02 15:04:04 +03:00
|
|
|
status->content->data.html.box_pool);
|
2003-09-29 03:41:07 +04:00
|
|
|
struct box *inline_container, *inline_box;
|
2004-04-18 19:19:53 +04:00
|
|
|
box->type = BOX_INLINE_BLOCK;
|
2003-09-29 03:41:07 +04:00
|
|
|
|
2004-07-20 00:40:11 +04:00
|
|
|
box->gadget = form_new_control((password) ? GADGET_PASSWORD : GADGET_TEXTBOX);
|
2003-10-02 02:48:39 +04:00
|
|
|
box->gadget->box = box;
|
2003-09-29 03:41:07 +04:00
|
|
|
|
|
|
|
box->gadget->maxlength = 100;
|
2004-08-14 18:30:12 +04:00
|
|
|
if ((s = (char *) xmlGetProp(n, (const xmlChar *) "maxlength")) != NULL) {
|
2003-09-29 03:41:07 +04:00
|
|
|
box->gadget->maxlength = atoi(s);
|
|
|
|
xmlFree(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
s = (char *) xmlGetProp(n, (const xmlChar *) "value");
|
2004-07-06 00:19:52 +04:00
|
|
|
box->gadget->value = strdup((s != NULL) ? s : "");
|
2004-07-20 00:40:11 +04:00
|
|
|
box->gadget->initial_value = strdup((box->gadget->value != NULL) ? box->gadget->value : "");
|
2003-09-29 03:41:07 +04:00
|
|
|
if (s)
|
|
|
|
xmlFree(s);
|
2004-07-06 00:19:52 +04:00
|
|
|
if (box->gadget->value == NULL || box->gadget->initial_value == NULL) {
|
|
|
|
box_free(box);
|
|
|
|
return NULL;
|
|
|
|
}
|
2004-07-20 00:40:11 +04:00
|
|
|
box->gadget->length = strlen(box->gadget->value);
|
2003-09-29 03:41:07 +04:00
|
|
|
|
2004-08-07 02:19:13 +04:00
|
|
|
inline_container = box_create(0, 0, 0, 0,
|
2004-01-02 15:04:04 +03:00
|
|
|
status->content->data.html.box_pool);
|
2003-09-29 03:41:07 +04:00
|
|
|
inline_container->type = BOX_INLINE_CONTAINER;
|
2004-08-07 02:19:13 +04:00
|
|
|
inline_box = box_create(style, 0, 0, 0,
|
2004-01-02 15:04:04 +03:00
|
|
|
status->content->data.html.box_pool);
|
2003-09-29 03:41:07 +04:00
|
|
|
inline_box->type = BOX_INLINE;
|
|
|
|
inline_box->style_clone = 1;
|
|
|
|
if (password) {
|
2004-07-06 00:19:52 +04:00
|
|
|
inline_box->length = strlen(box->gadget->value);
|
|
|
|
inline_box->text = malloc(inline_box->length + 1);
|
|
|
|
memset(inline_box->text, '*', inline_box->length);
|
|
|
|
inline_box->text[inline_box->length] = '\0';
|
2003-09-29 03:41:07 +04:00
|
|
|
} else {
|
2004-07-06 00:19:52 +04:00
|
|
|
/* replace spaces/TABs with hard spaces to prevent line wrapping */
|
|
|
|
inline_box->text = cnv_space2nbsp(box->gadget->value);
|
|
|
|
inline_box->length = strlen(inline_box->text);
|
2003-09-29 03:41:07 +04:00
|
|
|
}
|
2004-07-06 00:19:52 +04:00
|
|
|
inline_box->font = nsfont_open(status->content->data.html.fonts, style);
|
2003-09-29 03:41:07 +04:00
|
|
|
box_add_child(inline_container, inline_box);
|
|
|
|
box_add_child(box, inline_container);
|
|
|
|
|
|
|
|
return box;
|
|
|
|
}
|
|
|
|
|
2004-05-21 18:26:59 +04:00
|
|
|
struct box_result box_button(xmlNode *n, struct box_status *status,
|
2003-09-27 03:22:00 +04:00
|
|
|
struct css_style *style)
|
|
|
|
{
|
2004-05-21 18:26:59 +04:00
|
|
|
xmlChar *s;
|
2003-09-27 03:22:00 +04:00
|
|
|
char *type = (char *) xmlGetProp(n, (const xmlChar *) "type");
|
2004-08-07 02:19:13 +04:00
|
|
|
struct box *box = box_create(style, 0, 0, status->id,
|
2004-01-02 15:04:04 +03:00
|
|
|
status->content->data.html.box_pool);
|
2004-04-18 19:19:53 +04:00
|
|
|
box->type = BOX_INLINE_BLOCK;
|
2003-09-27 03:22:00 +04:00
|
|
|
|
|
|
|
if (!type || strcasecmp(type, "submit") == 0) {
|
2004-05-21 18:26:59 +04:00
|
|
|
box->gadget = form_new_control(GADGET_SUBMIT);
|
2003-09-27 03:22:00 +04:00
|
|
|
} else if (strcasecmp(type, "reset") == 0) {
|
2004-05-21 18:26:59 +04:00
|
|
|
box->gadget = form_new_control(GADGET_RESET);
|
2003-09-27 03:22:00 +04:00
|
|
|
} else {
|
|
|
|
/* type="button" or unknown: just render the contents */
|
|
|
|
xmlFree(type);
|
2004-05-21 18:26:59 +04:00
|
|
|
return (struct box_result) {box, true, false};
|
2003-09-27 03:22:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (type)
|
|
|
|
xmlFree(type);
|
|
|
|
|
2004-05-21 18:26:59 +04:00
|
|
|
if (!box->gadget) {
|
|
|
|
box_free_box(box);
|
|
|
|
return (struct box_result) {0, false, true};
|
|
|
|
}
|
|
|
|
|
2003-10-27 03:34:09 +03:00
|
|
|
if (status->current_form)
|
|
|
|
form_add_control(status->current_form, box->gadget);
|
2003-12-11 22:06:39 +03:00
|
|
|
else
|
|
|
|
box->gadget->form = 0;
|
2003-10-02 02:48:39 +04:00
|
|
|
box->gadget->box = box;
|
2004-08-14 18:30:12 +04:00
|
|
|
if ((s = xmlGetProp(n, (const xmlChar *) "name")) != NULL) {
|
2004-05-21 18:26:59 +04:00
|
|
|
box->gadget->name = strdup((char *) s);
|
|
|
|
xmlFree(s);
|
|
|
|
if (!box->gadget->name) {
|
|
|
|
box_free_box(box);
|
|
|
|
return (struct box_result) {0, false, true};
|
|
|
|
}
|
|
|
|
}
|
2004-08-14 18:30:12 +04:00
|
|
|
if ((s = xmlGetProp(n, (const xmlChar *) "value")) != NULL) {
|
2004-05-21 18:26:59 +04:00
|
|
|
box->gadget->value = strdup((char *) s);
|
|
|
|
xmlFree(s);
|
|
|
|
if (!box->gadget->value) {
|
|
|
|
box_free_box(box);
|
|
|
|
return (struct box_result) {0, false, true};
|
|
|
|
}
|
|
|
|
}
|
2003-09-27 03:22:00 +04:00
|
|
|
|
2004-05-21 18:26:59 +04:00
|
|
|
return (struct box_result) {box, true, false};
|
2003-09-27 03:22:00 +04:00
|
|
|
}
|
|
|
|
|
2003-07-05 01:17:53 +04:00
|
|
|
|
2002-09-08 22:11:56 +04:00
|
|
|
/**
|
2004-08-01 17:08:19 +04:00
|
|
|
* Print a box tree to stderr.
|
2002-05-04 23:57:18 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
void box_dump(struct box * box, unsigned int depth)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
struct box * c;
|
2002-06-19 01:24:21 +04:00
|
|
|
|
2002-05-04 23:57:18 +04:00
|
|
|
for (i = 0; i < depth; i++)
|
2002-06-19 01:24:21 +04:00
|
|
|
fprintf(stderr, " ");
|
2002-05-04 23:57:18 +04:00
|
|
|
|
2004-10-18 01:10:19 +04:00
|
|
|
fprintf(stderr, "%p ", box);
|
2004-03-15 01:49:40 +03:00
|
|
|
fprintf(stderr, "x%i y%i w%i h%i ", box->x, box->y, box->width, box->height);
|
2003-12-27 05:03:48 +03:00
|
|
|
if ((unsigned long)box->max_width != UNKNOWN_MAX_WIDTH)
|
2004-03-15 01:49:40 +03:00
|
|
|
fprintf(stderr, "min%i max%i ", box->min_width, box->max_width);
|
2004-08-01 17:08:19 +04:00
|
|
|
fprintf(stderr, "(%i %i %i %i) ",
|
|
|
|
box->descendant_x0, box->descendant_y0,
|
|
|
|
box->descendant_x1, box->descendant_y1);
|
2002-05-04 23:57:18 +04:00
|
|
|
|
|
|
|
switch (box->type) {
|
2004-08-01 17:08:19 +04:00
|
|
|
case BOX_BLOCK: fprintf(stderr, "BLOCK "); break;
|
|
|
|
case BOX_INLINE_CONTAINER: fprintf(stderr, "INLINE_CONTAINER "); break;
|
|
|
|
case BOX_INLINE: fprintf(stderr, "INLINE "); break;
|
|
|
|
case BOX_INLINE_BLOCK: fprintf(stderr, "INLINE_BLOCK "); break;
|
|
|
|
case BOX_TABLE: fprintf(stderr, "TABLE [columns %i] ",
|
2004-08-14 18:30:12 +04:00
|
|
|
box->columns); break;
|
2004-08-01 17:08:19 +04:00
|
|
|
case BOX_TABLE_ROW: fprintf(stderr, "TABLE_ROW "); break;
|
|
|
|
case BOX_TABLE_CELL: fprintf(stderr, "TABLE_CELL [columns %i, "
|
2004-08-14 18:30:12 +04:00
|
|
|
"start %i, rows %i] ", box->columns,
|
|
|
|
box->start_column, box->rows); break;
|
2004-08-01 17:08:19 +04:00
|
|
|
case BOX_TABLE_ROW_GROUP: fprintf(stderr, "TABLE_ROW_GROUP "); break;
|
|
|
|
case BOX_FLOAT_LEFT: fprintf(stderr, "FLOAT_LEFT "); break;
|
|
|
|
case BOX_FLOAT_RIGHT: fprintf(stderr, "FLOAT_RIGHT "); break;
|
|
|
|
case BOX_BR: fprintf(stderr, "BR "); break;
|
2002-06-19 01:24:21 +04:00
|
|
|
default: fprintf(stderr, "Unknown box type ");
|
2002-05-04 23:57:18 +04:00
|
|
|
}
|
2003-09-10 01:43:44 +04:00
|
|
|
if (box->text)
|
|
|
|
fprintf(stderr, "'%.*s' ", (int) box->length, box->text);
|
2004-02-01 07:45:55 +03:00
|
|
|
if (box->space)
|
2004-08-14 18:30:12 +04:00
|
|
|
fprintf(stderr, "space ");
|
2003-09-10 01:43:44 +04:00
|
|
|
if (box->object)
|
|
|
|
fprintf(stderr, "(object '%s') ", box->object->url);
|
2002-06-19 01:24:21 +04:00
|
|
|
if (box->style)
|
|
|
|
css_dump_style(box->style);
|
2002-08-12 03:01:02 +04:00
|
|
|
if (box->href != 0)
|
2004-08-07 02:19:13 +04:00
|
|
|
fprintf(stderr, " -> '%s'", box->href);
|
2003-07-01 02:21:51 +04:00
|
|
|
if (box->title != 0)
|
2004-08-07 02:19:13 +04:00
|
|
|
fprintf(stderr, " [%s]", box->title);
|
|
|
|
if (box->id != 0)
|
|
|
|
fprintf(stderr, " <%s>", box->id);
|
2004-10-18 01:10:19 +04:00
|
|
|
if (box->float_children)
|
|
|
|
fprintf(stderr, " float_children %p", box->float_children);
|
|
|
|
if (box->next_float)
|
|
|
|
fprintf(stderr, " next_float %p", box->next_float);
|
2002-06-19 01:24:21 +04:00
|
|
|
fprintf(stderr, "\n");
|
|
|
|
|
2002-05-04 23:57:18 +04:00
|
|
|
for (c = box->children; c != 0; c = c->next)
|
|
|
|
box_dump(c, depth + 1);
|
|
|
|
}
|
|
|
|
|
2002-08-18 20:46:45 +04:00
|
|
|
|
2002-09-08 22:11:56 +04:00
|
|
|
/**
|
|
|
|
* ensure the box tree is correctly nested
|
2003-01-02 16:26:43 +03:00
|
|
|
*
|
|
|
|
* parent permitted child nodes
|
2003-09-22 02:47:08 +04:00
|
|
|
* BLOCK, INLINE_BLOCK BLOCK, INLINE_CONTAINER, TABLE
|
2004-04-18 19:19:53 +04:00
|
|
|
* INLINE_CONTAINER INLINE, INLINE_BLOCK, FLOAT_LEFT, FLOAT_RIGHT, BR
|
2003-01-02 16:26:43 +03:00
|
|
|
* INLINE none
|
|
|
|
* TABLE at least 1 TABLE_ROW_GROUP
|
|
|
|
* TABLE_ROW_GROUP at least 1 TABLE_ROW
|
|
|
|
* TABLE_ROW at least 1 TABLE_CELL
|
|
|
|
* TABLE_CELL BLOCK, INLINE_CONTAINER, TABLE (same as BLOCK)
|
|
|
|
* FLOAT_(LEFT|RIGHT) exactly 1 BLOCK or TABLE
|
2002-08-18 20:46:45 +04:00
|
|
|
*/
|
|
|
|
|
2004-01-02 15:04:04 +03:00
|
|
|
void box_normalise_block(struct box *block, pool box_pool)
|
2002-08-18 20:46:45 +04:00
|
|
|
{
|
|
|
|
struct box *child;
|
2003-01-02 16:26:43 +03:00
|
|
|
struct box *next_child;
|
2002-08-18 20:46:45 +04:00
|
|
|
struct box *table;
|
|
|
|
struct css_style *style;
|
|
|
|
|
2003-01-02 16:26:43 +03:00
|
|
|
assert(block != 0);
|
2004-07-06 00:19:52 +04:00
|
|
|
LOG(("block %p, block->type %u", block, block->type));
|
2003-09-22 02:47:08 +04:00
|
|
|
assert(block->type == BOX_BLOCK || block->type == BOX_INLINE_BLOCK ||
|
|
|
|
block->type == BOX_TABLE_CELL);
|
2003-07-05 01:17:53 +04:00
|
|
|
gui_multitask();
|
2002-08-18 20:46:45 +04:00
|
|
|
|
2003-01-02 16:26:43 +03:00
|
|
|
for (child = block->children; child != 0; child = next_child) {
|
|
|
|
LOG(("child %p, child->type = %d", child, child->type));
|
|
|
|
next_child = child->next; /* child may be destroyed */
|
2002-08-18 20:46:45 +04:00
|
|
|
switch (child->type) {
|
|
|
|
case BOX_BLOCK:
|
|
|
|
/* ok */
|
2004-01-02 15:04:04 +03:00
|
|
|
box_normalise_block(child, box_pool);
|
2002-08-18 20:46:45 +04:00
|
|
|
break;
|
|
|
|
case BOX_INLINE_CONTAINER:
|
2004-01-02 15:04:04 +03:00
|
|
|
box_normalise_inline_container(child, box_pool);
|
2002-08-18 20:46:45 +04:00
|
|
|
break;
|
|
|
|
case BOX_TABLE:
|
2004-01-02 15:04:04 +03:00
|
|
|
box_normalise_table(child, box_pool);
|
2002-08-18 20:46:45 +04:00
|
|
|
break;
|
|
|
|
case BOX_INLINE:
|
2003-09-22 02:47:08 +04:00
|
|
|
case BOX_INLINE_BLOCK:
|
2002-08-18 20:46:45 +04:00
|
|
|
case BOX_FLOAT_LEFT:
|
|
|
|
case BOX_FLOAT_RIGHT:
|
2004-04-18 19:19:53 +04:00
|
|
|
case BOX_BR:
|
2002-08-18 20:46:45 +04:00
|
|
|
/* should have been wrapped in inline
|
|
|
|
container by convert_xml_to_box() */
|
|
|
|
assert(0);
|
|
|
|
break;
|
|
|
|
case BOX_TABLE_ROW_GROUP:
|
|
|
|
case BOX_TABLE_ROW:
|
|
|
|
case BOX_TABLE_CELL:
|
|
|
|
/* insert implied table */
|
|
|
|
style = xcalloc(1, sizeof(struct css_style));
|
2004-07-06 00:19:52 +04:00
|
|
|
assert(block->style != NULL);
|
2002-08-18 20:46:45 +04:00
|
|
|
memcpy(style, block->style, sizeof(struct css_style));
|
|
|
|
css_cascade(style, &css_blank_style);
|
2004-08-07 02:19:13 +04:00
|
|
|
table = box_create(style, block->href, 0, 0, box_pool);
|
2003-07-05 20:16:15 +04:00
|
|
|
table->type = BOX_TABLE;
|
2003-01-02 16:26:43 +03:00
|
|
|
if (child->prev == 0)
|
2002-08-18 20:46:45 +04:00
|
|
|
block->children = table;
|
|
|
|
else
|
2003-01-02 16:26:43 +03:00
|
|
|
child->prev->next = table;
|
|
|
|
table->prev = child->prev;
|
2002-08-18 20:46:45 +04:00
|
|
|
while (child != 0 && (
|
|
|
|
child->type == BOX_TABLE_ROW_GROUP ||
|
|
|
|
child->type == BOX_TABLE_ROW ||
|
|
|
|
child->type == BOX_TABLE_CELL)) {
|
|
|
|
box_add_child(table, child);
|
2004-04-18 19:19:53 +04:00
|
|
|
next_child = child->next;
|
|
|
|
child->next = 0;
|
|
|
|
child = next_child;
|
2002-08-18 20:46:45 +04:00
|
|
|
}
|
2003-01-02 16:26:43 +03:00
|
|
|
table->last->next = 0;
|
|
|
|
table->next = next_child = child;
|
2004-04-18 19:19:53 +04:00
|
|
|
if (table->next)
|
|
|
|
table->next->prev = table;
|
2002-09-18 23:36:28 +04:00
|
|
|
table->parent = block;
|
2004-01-02 15:04:04 +03:00
|
|
|
box_normalise_table(table, box_pool);
|
2002-08-18 20:46:45 +04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
assert(0);
|
|
|
|
}
|
|
|
|
}
|
2003-01-02 16:26:43 +03:00
|
|
|
LOG(("block %p done", block));
|
2002-08-18 20:46:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-09-04 00:32:57 +04:00
|
|
|
void box_normalise_table_spans( struct box *table )
|
|
|
|
{
|
|
|
|
struct box *table_row_group;
|
|
|
|
struct box *table_row;
|
|
|
|
struct box *table_cell;
|
|
|
|
unsigned int last_column;
|
|
|
|
unsigned int max_extra = 0;
|
|
|
|
bool extra;
|
|
|
|
bool force = false;
|
|
|
|
unsigned int rows_left = table->rows;
|
|
|
|
|
|
|
|
/* Scan table filling in table the width and height of table cells for
|
|
|
|
cells with colspan = 0 or rowspan = 0. Ignore the colspan and
|
|
|
|
rowspan of any cells that that follow an colspan = 0 */
|
|
|
|
for (table_row_group = table->children; table_row_group != NULL;
|
|
|
|
table_row_group = table_row_group->next) {
|
|
|
|
for (table_row = table_row_group->children; NULL != table_row;
|
|
|
|
table_row = table_row->next){
|
|
|
|
last_column = 0;
|
|
|
|
extra = false;
|
|
|
|
for (table_cell = table_row->children; NULL != table_cell;
|
|
|
|
table_cell = table_cell->next) {
|
|
|
|
/* We hae reached the end of the row, and have passed
|
|
|
|
a cell with colspan = 0 so ignore col and row spans */
|
|
|
|
if ( force || extra || ( table_cell->start_column + 1 <=
|
|
|
|
last_column )) {
|
|
|
|
extra = true;
|
|
|
|
table_cell->columns = 1;
|
|
|
|
table_cell->rows = 1;
|
|
|
|
if ( table_cell->start_column <= max_extra ) {
|
|
|
|
max_extra = table_cell->start_column + 1;
|
|
|
|
}
|
|
|
|
table_cell->start_column += table->columns;
|
|
|
|
} else {
|
|
|
|
/* Fill out the number of columns or the number of rows
|
|
|
|
if necessary */
|
|
|
|
if ( 0 == table_cell->columns ) {
|
|
|
|
table_cell->columns = table->columns -
|
|
|
|
table_cell->start_column;
|
|
|
|
if (( 0 == table_cell->start_column ) &&
|
|
|
|
( 0 == table_cell->rows )) {
|
|
|
|
force = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
assert( 0 != table_cell->columns );
|
|
|
|
if ( 0 == table_cell->rows ) {
|
|
|
|
table_cell->rows = rows_left;
|
|
|
|
}
|
|
|
|
assert( 0 != table_cell->rows );
|
|
|
|
last_column = table_cell->start_column + 1;
|
|
|
|
}
|
2004-10-18 01:10:19 +04:00
|
|
|
}
|
2004-09-04 00:32:57 +04:00
|
|
|
rows_left--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
table->columns += max_extra;
|
|
|
|
}
|
|
|
|
|
2004-01-02 15:04:04 +03:00
|
|
|
void box_normalise_table(struct box *table, pool box_pool)
|
2002-08-18 20:46:45 +04:00
|
|
|
{
|
|
|
|
struct box *child;
|
2003-01-02 16:26:43 +03:00
|
|
|
struct box *next_child;
|
2002-08-18 20:46:45 +04:00
|
|
|
struct box *row_group;
|
|
|
|
struct css_style *style;
|
2004-09-04 00:32:57 +04:00
|
|
|
struct columns col_info;
|
|
|
|
/* struct span_info *span_info = xcalloc(2, sizeof(span_info[0]));
|
|
|
|
unsigned int table_columns = 1;*/
|
2002-08-18 20:46:45 +04:00
|
|
|
|
2003-01-02 16:26:43 +03:00
|
|
|
assert(table != 0);
|
2002-08-18 20:46:45 +04:00
|
|
|
assert(table->type == BOX_TABLE);
|
2003-01-02 16:26:43 +03:00
|
|
|
LOG(("table %p", table));
|
2004-09-04 00:32:57 +04:00
|
|
|
col_info.num_columns = 1;
|
|
|
|
col_info.current_column = 0;
|
|
|
|
col_info.spans = xcalloc( 2, sizeof( *col_info.spans));
|
|
|
|
col_info.spans[0].row_span = col_info.spans[1].row_span = 0;
|
|
|
|
col_info.spans[0].auto_row = col_info.spans[0].auto_column =
|
|
|
|
col_info.spans[1].auto_row = col_info.spans[1].auto_column = false;
|
|
|
|
col_info.num_rows = col_info.extra_columns = 0;
|
|
|
|
col_info.extra = false;
|
2002-08-18 20:46:45 +04:00
|
|
|
|
2003-01-02 16:26:43 +03:00
|
|
|
for (child = table->children; child != 0; child = next_child) {
|
|
|
|
next_child = child->next;
|
2002-08-18 20:46:45 +04:00
|
|
|
switch (child->type) {
|
|
|
|
case BOX_TABLE_ROW_GROUP:
|
|
|
|
/* ok */
|
2004-09-04 00:32:57 +04:00
|
|
|
box_normalise_table_row_group(child, &col_info, box_pool);
|
2002-08-18 20:46:45 +04:00
|
|
|
break;
|
|
|
|
case BOX_BLOCK:
|
|
|
|
case BOX_INLINE_CONTAINER:
|
|
|
|
case BOX_TABLE:
|
|
|
|
case BOX_TABLE_ROW:
|
|
|
|
case BOX_TABLE_CELL:
|
|
|
|
/* insert implied table row group */
|
|
|
|
style = xcalloc(1, sizeof(struct css_style));
|
2004-07-06 00:19:52 +04:00
|
|
|
assert(table->style != NULL);
|
2002-08-18 20:46:45 +04:00
|
|
|
memcpy(style, table->style, sizeof(struct css_style));
|
|
|
|
css_cascade(style, &css_blank_style);
|
2004-01-02 15:04:04 +03:00
|
|
|
row_group = box_create(style, table->href, 0,
|
2004-08-07 02:19:13 +04:00
|
|
|
0, box_pool);
|
2003-07-05 20:16:15 +04:00
|
|
|
row_group->type = BOX_TABLE_ROW_GROUP;
|
2003-01-02 16:26:43 +03:00
|
|
|
if (child->prev == 0)
|
2002-08-18 20:46:45 +04:00
|
|
|
table->children = row_group;
|
|
|
|
else
|
2003-01-02 16:26:43 +03:00
|
|
|
child->prev->next = row_group;
|
|
|
|
row_group->prev = child->prev;
|
2002-08-18 20:46:45 +04:00
|
|
|
while (child != 0 && (
|
|
|
|
child->type == BOX_BLOCK ||
|
|
|
|
child->type == BOX_INLINE_CONTAINER ||
|
|
|
|
child->type == BOX_TABLE ||
|
|
|
|
child->type == BOX_TABLE_ROW ||
|
|
|
|
child->type == BOX_TABLE_CELL)) {
|
|
|
|
box_add_child(row_group, child);
|
2004-04-18 19:19:53 +04:00
|
|
|
next_child = child->next;
|
|
|
|
child->next = 0;
|
|
|
|
child = next_child;
|
2002-08-18 20:46:45 +04:00
|
|
|
}
|
2003-01-02 16:26:43 +03:00
|
|
|
row_group->last->next = 0;
|
|
|
|
row_group->next = next_child = child;
|
2004-04-18 19:19:53 +04:00
|
|
|
if (row_group->next)
|
|
|
|
row_group->next->prev = row_group;
|
2002-09-18 23:36:28 +04:00
|
|
|
row_group->parent = table;
|
2004-09-04 00:32:57 +04:00
|
|
|
box_normalise_table_row_group(row_group, &col_info, box_pool);
|
2002-08-18 20:46:45 +04:00
|
|
|
break;
|
|
|
|
case BOX_INLINE:
|
2003-09-22 02:47:08 +04:00
|
|
|
case BOX_INLINE_BLOCK:
|
2002-08-18 20:46:45 +04:00
|
|
|
case BOX_FLOAT_LEFT:
|
|
|
|
case BOX_FLOAT_RIGHT:
|
2004-04-18 19:19:53 +04:00
|
|
|
case BOX_BR:
|
2002-08-18 20:46:45 +04:00
|
|
|
/* should have been wrapped in inline
|
|
|
|
container by convert_xml_to_box() */
|
|
|
|
assert(0);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
fprintf(stderr, "%i\n", child->type);
|
|
|
|
assert(0);
|
|
|
|
}
|
|
|
|
}
|
2003-01-02 16:26:43 +03:00
|
|
|
|
2004-09-04 00:32:57 +04:00
|
|
|
table->columns = col_info.num_columns;
|
|
|
|
table->rows = col_info.num_rows;
|
|
|
|
free(col_info.spans);
|
|
|
|
|
|
|
|
box_normalise_table_spans( table );
|
2003-07-07 01:10:12 +04:00
|
|
|
|
2003-01-02 16:26:43 +03:00
|
|
|
if (table->children == 0) {
|
|
|
|
LOG(("table->children == 0, removing"));
|
|
|
|
if (table->prev == 0)
|
|
|
|
table->parent->children = table->next;
|
|
|
|
else
|
|
|
|
table->prev->next = table->next;
|
|
|
|
if (table->next != 0)
|
|
|
|
table->next->prev = table->prev;
|
2003-09-20 01:23:19 +04:00
|
|
|
box_free(table);
|
2003-01-02 16:26:43 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
LOG(("table %p done", table));
|
2002-08-18 20:46:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-09-04 00:32:57 +04:00
|
|
|
static void box_normalise_table_row_group(struct box *row_group,
|
|
|
|
struct columns *col_info,
|
2004-01-02 15:04:04 +03:00
|
|
|
pool box_pool)
|
2002-08-18 20:46:45 +04:00
|
|
|
{
|
|
|
|
struct box *child;
|
2003-01-02 16:26:43 +03:00
|
|
|
struct box *next_child;
|
2002-08-18 20:46:45 +04:00
|
|
|
struct box *row;
|
|
|
|
struct css_style *style;
|
|
|
|
|
2003-01-02 16:26:43 +03:00
|
|
|
assert(row_group != 0);
|
2002-08-18 20:46:45 +04:00
|
|
|
assert(row_group->type == BOX_TABLE_ROW_GROUP);
|
2003-01-02 16:26:43 +03:00
|
|
|
LOG(("row_group %p", row_group));
|
2002-08-18 20:46:45 +04:00
|
|
|
|
2003-01-02 16:26:43 +03:00
|
|
|
for (child = row_group->children; child != 0; child = next_child) {
|
|
|
|
next_child = child->next;
|
2002-08-18 20:46:45 +04:00
|
|
|
switch (child->type) {
|
|
|
|
case BOX_TABLE_ROW:
|
|
|
|
/* ok */
|
2004-09-04 00:32:57 +04:00
|
|
|
box_normalise_table_row(child, col_info,
|
|
|
|
box_pool);
|
2002-08-18 20:46:45 +04:00
|
|
|
break;
|
|
|
|
case BOX_BLOCK:
|
|
|
|
case BOX_INLINE_CONTAINER:
|
|
|
|
case BOX_TABLE:
|
|
|
|
case BOX_TABLE_ROW_GROUP:
|
|
|
|
case BOX_TABLE_CELL:
|
|
|
|
/* insert implied table row */
|
|
|
|
style = xcalloc(1, sizeof(struct css_style));
|
2004-07-06 00:19:52 +04:00
|
|
|
assert(row_group->style != NULL);
|
2002-08-18 20:46:45 +04:00
|
|
|
memcpy(style, row_group->style, sizeof(struct css_style));
|
|
|
|
css_cascade(style, &css_blank_style);
|
2004-01-02 15:04:04 +03:00
|
|
|
row = box_create(style, row_group->href, 0,
|
2004-08-07 02:19:13 +04:00
|
|
|
0, box_pool);
|
2003-07-05 20:16:15 +04:00
|
|
|
row->type = BOX_TABLE_ROW;
|
2003-01-02 16:26:43 +03:00
|
|
|
if (child->prev == 0)
|
2002-08-18 20:46:45 +04:00
|
|
|
row_group->children = row;
|
|
|
|
else
|
2003-01-02 16:26:43 +03:00
|
|
|
child->prev->next = row;
|
|
|
|
row->prev = child->prev;
|
2002-08-18 20:46:45 +04:00
|
|
|
while (child != 0 && (
|
|
|
|
child->type == BOX_BLOCK ||
|
|
|
|
child->type == BOX_INLINE_CONTAINER ||
|
|
|
|
child->type == BOX_TABLE ||
|
|
|
|
child->type == BOX_TABLE_ROW_GROUP ||
|
|
|
|
child->type == BOX_TABLE_CELL)) {
|
|
|
|
box_add_child(row, child);
|
2004-04-18 19:19:53 +04:00
|
|
|
next_child = child->next;
|
|
|
|
child->next = 0;
|
|
|
|
child = next_child;
|
2002-08-18 20:46:45 +04:00
|
|
|
}
|
2003-01-02 16:26:43 +03:00
|
|
|
row->last->next = 0;
|
|
|
|
row->next = next_child = child;
|
2004-04-18 19:19:53 +04:00
|
|
|
if (row->next)
|
|
|
|
row->next->prev = row;
|
2002-09-18 23:36:28 +04:00
|
|
|
row->parent = row_group;
|
2004-09-04 00:32:57 +04:00
|
|
|
box_normalise_table_row(row, col_info,
|
|
|
|
box_pool);
|
2002-08-18 20:46:45 +04:00
|
|
|
break;
|
|
|
|
case BOX_INLINE:
|
2003-09-22 02:47:08 +04:00
|
|
|
case BOX_INLINE_BLOCK:
|
2002-08-18 20:46:45 +04:00
|
|
|
case BOX_FLOAT_LEFT:
|
|
|
|
case BOX_FLOAT_RIGHT:
|
2004-04-18 19:19:53 +04:00
|
|
|
case BOX_BR:
|
2002-08-18 20:46:45 +04:00
|
|
|
/* should have been wrapped in inline
|
|
|
|
container by convert_xml_to_box() */
|
|
|
|
assert(0);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
assert(0);
|
|
|
|
}
|
|
|
|
}
|
2003-01-02 16:26:43 +03:00
|
|
|
|
|
|
|
if (row_group->children == 0) {
|
|
|
|
LOG(("row_group->children == 0, removing"));
|
|
|
|
if (row_group->prev == 0)
|
|
|
|
row_group->parent->children = row_group->next;
|
|
|
|
else
|
|
|
|
row_group->prev->next = row_group->next;
|
|
|
|
if (row_group->next != 0)
|
|
|
|
row_group->next->prev = row_group->prev;
|
2003-09-20 01:23:19 +04:00
|
|
|
box_free(row_group);
|
2003-01-02 16:26:43 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
LOG(("row_group %p done", row_group));
|
2002-08-18 20:46:45 +04:00
|
|
|
}
|
|
|
|
|
2004-09-04 00:32:57 +04:00
|
|
|
static unsigned int calculate_table_row( struct columns *col_info,
|
|
|
|
unsigned int col_span, unsigned int row_span )
|
|
|
|
{
|
|
|
|
unsigned int cell_start_col;
|
|
|
|
unsigned int cell_end_col;
|
|
|
|
unsigned int i;
|
2002-08-18 20:46:45 +04:00
|
|
|
|
2004-09-04 00:32:57 +04:00
|
|
|
if ( !col_info->extra ) {
|
|
|
|
/* skip columns with cells spanning from above */
|
|
|
|
while (( col_info->spans[col_info->current_column].row_span != 0 ) &&
|
|
|
|
( !col_info->spans[col_info->current_column].auto_column )) {
|
|
|
|
col_info->current_column++;
|
|
|
|
}
|
|
|
|
if ( col_info->spans[col_info->current_column].auto_column ) {
|
|
|
|
col_info->extra = true;
|
|
|
|
col_info->current_column = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cell_start_col = col_info->current_column;
|
|
|
|
|
|
|
|
/* If the current table cell follows a cell with colspan=0,
|
|
|
|
ignore both colspan and rowspan just assume it is a standard
|
|
|
|
size cell */
|
|
|
|
if ( col_info->extra ) {
|
|
|
|
col_info->current_column++;
|
|
|
|
col_info->extra_columns = col_info->current_column;
|
|
|
|
} else {
|
|
|
|
/* If span to end of table, assume spaning single column
|
|
|
|
at the moment */
|
|
|
|
cell_end_col = cell_start_col + (( 0 == col_span ) ? 1 : col_span );
|
|
|
|
|
|
|
|
if ( col_info->num_columns < cell_end_col ) {
|
|
|
|
col_info->spans = xrealloc( col_info->spans,
|
|
|
|
sizeof( *col_info->spans ) * ( cell_end_col + 1 ));
|
|
|
|
col_info->num_columns = cell_end_col;
|
2004-10-18 01:10:19 +04:00
|
|
|
|
2004-09-04 00:32:57 +04:00
|
|
|
/* Mark new final column as sentinal */
|
|
|
|
col_info->spans[ cell_end_col ].row_span = 0;
|
|
|
|
col_info->spans[ cell_end_col ].auto_row =
|
|
|
|
col_info->spans[ cell_end_col ].auto_column =
|
|
|
|
false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( 0 == col_span ) {
|
|
|
|
col_info->spans[ cell_start_col ].auto_column = true;
|
|
|
|
col_info->spans[ cell_start_col ].row_span = row_span;
|
|
|
|
col_info->spans[ cell_start_col ].auto_row = ( 0 == row_span );
|
|
|
|
} else {
|
|
|
|
for (i = cell_start_col; i < cell_end_col; i++) {
|
|
|
|
col_info->spans[ i ].row_span = ( 0 == row_span ) ?
|
|
|
|
1 : row_span;
|
|
|
|
col_info->spans[ i ].auto_row = ( 0 == row_span );
|
|
|
|
col_info->spans[ i ].auto_column = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( 0 == col_span ) {
|
|
|
|
col_info->spans[ cell_end_col ].auto_column = true;
|
|
|
|
}
|
|
|
|
col_info->current_column = cell_end_col;
|
|
|
|
}
|
|
|
|
|
|
|
|
return cell_start_col;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void box_normalise_table_row(struct box *row,
|
|
|
|
struct columns *col_info,
|
2004-01-02 15:04:04 +03:00
|
|
|
pool box_pool)
|
2002-08-18 20:46:45 +04:00
|
|
|
{
|
|
|
|
struct box *child;
|
2003-01-02 16:26:43 +03:00
|
|
|
struct box *next_child;
|
2002-08-18 20:46:45 +04:00
|
|
|
struct box *cell;
|
|
|
|
struct css_style *style;
|
2004-09-04 00:32:57 +04:00
|
|
|
unsigned int i;
|
2002-08-18 20:46:45 +04:00
|
|
|
|
2003-01-02 16:26:43 +03:00
|
|
|
assert(row != 0);
|
2002-08-18 20:46:45 +04:00
|
|
|
assert(row->type == BOX_TABLE_ROW);
|
2003-01-02 16:26:43 +03:00
|
|
|
LOG(("row %p", row));
|
2002-08-18 20:46:45 +04:00
|
|
|
|
2003-01-02 16:26:43 +03:00
|
|
|
for (child = row->children; child != 0; child = next_child) {
|
|
|
|
next_child = child->next;
|
2002-08-18 20:46:45 +04:00
|
|
|
switch (child->type) {
|
|
|
|
case BOX_TABLE_CELL:
|
|
|
|
/* ok */
|
2004-01-02 15:04:04 +03:00
|
|
|
box_normalise_block(child, box_pool);
|
2003-07-07 01:10:12 +04:00
|
|
|
cell = child;
|
2002-08-18 20:46:45 +04:00
|
|
|
break;
|
|
|
|
case BOX_BLOCK:
|
|
|
|
case BOX_INLINE_CONTAINER:
|
|
|
|
case BOX_TABLE:
|
|
|
|
case BOX_TABLE_ROW_GROUP:
|
|
|
|
case BOX_TABLE_ROW:
|
|
|
|
/* insert implied table cell */
|
|
|
|
style = xcalloc(1, sizeof(struct css_style));
|
2004-07-06 00:19:52 +04:00
|
|
|
assert(row->style != NULL);
|
2002-08-18 20:46:45 +04:00
|
|
|
memcpy(style, row->style, sizeof(struct css_style));
|
|
|
|
css_cascade(style, &css_blank_style);
|
2004-08-07 02:19:13 +04:00
|
|
|
cell = box_create(style, row->href, 0, 0, box_pool);
|
2003-07-05 20:16:15 +04:00
|
|
|
cell->type = BOX_TABLE_CELL;
|
2003-01-02 16:26:43 +03:00
|
|
|
if (child->prev == 0)
|
2002-08-18 20:46:45 +04:00
|
|
|
row->children = cell;
|
|
|
|
else
|
2003-01-02 16:26:43 +03:00
|
|
|
child->prev->next = cell;
|
|
|
|
cell->prev = child->prev;
|
2002-08-18 20:46:45 +04:00
|
|
|
while (child != 0 && (
|
|
|
|
child->type == BOX_BLOCK ||
|
|
|
|
child->type == BOX_INLINE_CONTAINER ||
|
|
|
|
child->type == BOX_TABLE ||
|
|
|
|
child->type == BOX_TABLE_ROW_GROUP ||
|
|
|
|
child->type == BOX_TABLE_ROW)) {
|
|
|
|
box_add_child(cell, child);
|
2004-04-18 19:19:53 +04:00
|
|
|
next_child = child->next;
|
|
|
|
child->next = 0;
|
|
|
|
child = next_child;
|
2002-08-18 20:46:45 +04:00
|
|
|
}
|
2003-01-02 16:26:43 +03:00
|
|
|
cell->last->next = 0;
|
|
|
|
cell->next = next_child = child;
|
2004-04-18 19:19:53 +04:00
|
|
|
if (cell->next)
|
|
|
|
cell->next->prev = cell;
|
2002-09-18 23:36:28 +04:00
|
|
|
cell->parent = row;
|
2004-01-02 15:04:04 +03:00
|
|
|
box_normalise_block(cell, box_pool);
|
2002-08-18 20:46:45 +04:00
|
|
|
break;
|
|
|
|
case BOX_INLINE:
|
2003-09-22 02:47:08 +04:00
|
|
|
case BOX_INLINE_BLOCK:
|
2002-08-18 20:46:45 +04:00
|
|
|
case BOX_FLOAT_LEFT:
|
|
|
|
case BOX_FLOAT_RIGHT:
|
2004-04-18 19:19:53 +04:00
|
|
|
case BOX_BR:
|
2002-08-18 20:46:45 +04:00
|
|
|
/* should have been wrapped in inline
|
|
|
|
container by convert_xml_to_box() */
|
|
|
|
assert(0);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
assert(0);
|
|
|
|
}
|
2003-07-07 01:10:12 +04:00
|
|
|
|
2004-09-04 00:32:57 +04:00
|
|
|
cell->start_column = calculate_table_row( col_info, cell->columns, cell->rows );
|
2002-08-18 20:46:45 +04:00
|
|
|
}
|
2003-07-07 01:10:12 +04:00
|
|
|
|
2004-09-04 00:32:57 +04:00
|
|
|
for ( i = 0; i < col_info->num_columns; i++ ) {
|
|
|
|
if (( col_info->spans[i].row_span != 0 ) && ( !col_info->spans[i].auto_row )) {
|
|
|
|
col_info->spans[i].row_span--;
|
|
|
|
if (( col_info->spans[i].auto_column ) && ( 0 == col_info->spans[i].row_span )) {
|
|
|
|
col_info->spans[i].auto_column = false;
|
|
|
|
}
|
2004-10-18 01:10:19 +04:00
|
|
|
}
|
2004-09-04 00:32:57 +04:00
|
|
|
}
|
|
|
|
col_info->current_column = 0;
|
|
|
|
col_info->extra = false;
|
2003-07-08 22:49:14 +04:00
|
|
|
|
2003-01-02 16:26:43 +03:00
|
|
|
if (row->children == 0) {
|
|
|
|
LOG(("row->children == 0, removing"));
|
|
|
|
if (row->prev == 0)
|
|
|
|
row->parent->children = row->next;
|
|
|
|
else
|
|
|
|
row->prev->next = row->next;
|
|
|
|
if (row->next != 0)
|
|
|
|
row->next->prev = row->prev;
|
2003-09-20 01:23:19 +04:00
|
|
|
box_free(row);
|
2004-09-04 00:32:57 +04:00
|
|
|
} else {
|
|
|
|
col_info->num_rows++;
|
2003-01-02 16:26:43 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
LOG(("row %p done", row));
|
2002-08-18 20:46:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-01-02 15:04:04 +03:00
|
|
|
void box_normalise_inline_container(struct box *cont, pool box_pool)
|
2002-08-18 20:46:45 +04:00
|
|
|
{
|
|
|
|
struct box *child;
|
2003-01-02 16:26:43 +03:00
|
|
|
struct box *next_child;
|
2002-08-18 20:46:45 +04:00
|
|
|
|
2003-01-02 16:26:43 +03:00
|
|
|
assert(cont != 0);
|
2002-08-18 20:46:45 +04:00
|
|
|
assert(cont->type == BOX_INLINE_CONTAINER);
|
2003-01-02 16:26:43 +03:00
|
|
|
LOG(("cont %p", cont));
|
2002-08-18 20:46:45 +04:00
|
|
|
|
2003-01-02 16:26:43 +03:00
|
|
|
for (child = cont->children; child != 0; child = next_child) {
|
|
|
|
next_child = child->next;
|
2002-08-18 20:46:45 +04:00
|
|
|
switch (child->type) {
|
|
|
|
case BOX_INLINE:
|
2004-04-18 19:19:53 +04:00
|
|
|
case BOX_BR:
|
2002-08-18 20:46:45 +04:00
|
|
|
/* ok */
|
|
|
|
break;
|
2003-09-22 02:47:08 +04:00
|
|
|
case BOX_INLINE_BLOCK:
|
|
|
|
/* ok */
|
2004-01-02 15:04:04 +03:00
|
|
|
box_normalise_block(child, box_pool);
|
2003-09-22 02:47:08 +04:00
|
|
|
break;
|
2002-08-18 20:46:45 +04:00
|
|
|
case BOX_FLOAT_LEFT:
|
|
|
|
case BOX_FLOAT_RIGHT:
|
|
|
|
/* ok */
|
|
|
|
assert(child->children != 0);
|
|
|
|
switch (child->children->type) {
|
|
|
|
case BOX_BLOCK:
|
2004-01-02 15:04:04 +03:00
|
|
|
box_normalise_block(child->children,
|
|
|
|
box_pool);
|
2002-08-18 20:46:45 +04:00
|
|
|
break;
|
|
|
|
case BOX_TABLE:
|
2004-01-02 15:04:04 +03:00
|
|
|
box_normalise_table(child->children,
|
|
|
|
box_pool);
|
2002-08-18 20:46:45 +04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
assert(0);
|
|
|
|
}
|
2003-09-05 23:19:05 +04:00
|
|
|
if (child->children == 0) {
|
|
|
|
/* the child has destroyed itself: remove float */
|
|
|
|
if (child->prev == 0)
|
|
|
|
child->parent->children = child->next;
|
|
|
|
else
|
|
|
|
child->prev->next = child->next;
|
|
|
|
if (child->next != 0)
|
|
|
|
child->next->prev = child->prev;
|
2003-09-20 01:23:19 +04:00
|
|
|
box_free(child);
|
2003-09-05 23:19:05 +04:00
|
|
|
}
|
2002-08-18 20:46:45 +04:00
|
|
|
break;
|
|
|
|
case BOX_BLOCK:
|
|
|
|
case BOX_INLINE_CONTAINER:
|
|
|
|
case BOX_TABLE:
|
|
|
|
case BOX_TABLE_ROW_GROUP:
|
|
|
|
case BOX_TABLE_ROW:
|
|
|
|
case BOX_TABLE_CELL:
|
|
|
|
default:
|
|
|
|
assert(0);
|
|
|
|
}
|
|
|
|
}
|
2003-01-02 16:26:43 +03:00
|
|
|
LOG(("cont %p done", cont));
|
2002-08-18 20:46:45 +04:00
|
|
|
}
|
2002-09-08 22:11:56 +04:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
2004-05-21 18:26:59 +04:00
|
|
|
* Free a box tree recursively.
|
2002-09-08 22:11:56 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
void box_free(struct box *box)
|
|
|
|
{
|
2003-09-20 01:23:19 +04:00
|
|
|
struct box *child, *next;
|
2002-09-08 22:11:56 +04:00
|
|
|
|
2003-09-20 01:23:19 +04:00
|
|
|
/* free children first */
|
|
|
|
for (child = box->children; child; child = next) {
|
|
|
|
next = child->next;
|
|
|
|
box_free(child);
|
|
|
|
}
|
2002-09-08 22:11:56 +04:00
|
|
|
|
|
|
|
/* last this box */
|
2003-01-02 16:26:43 +03:00
|
|
|
box_free_box(box);
|
|
|
|
}
|
|
|
|
|
2004-05-21 18:26:59 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Free a single box structure.
|
|
|
|
*/
|
|
|
|
|
2003-01-02 16:26:43 +03:00
|
|
|
void box_free_box(struct box *box)
|
|
|
|
{
|
2003-09-20 01:23:19 +04:00
|
|
|
if (!box->clone) {
|
2004-05-21 18:26:59 +04:00
|
|
|
if (box->gadget)
|
|
|
|
form_free_control(box->gadget);
|
2003-09-20 01:23:19 +04:00
|
|
|
free(box->href);
|
|
|
|
free(box->title);
|
|
|
|
free(box->col);
|
|
|
|
if (!box->style_clone)
|
|
|
|
free(box->style);
|
2002-12-30 01:27:35 +03:00
|
|
|
}
|
2002-12-30 05:06:03 +03:00
|
|
|
|
2004-05-21 18:26:59 +04:00
|
|
|
free(box->usemap);
|
2003-07-01 02:21:51 +04:00
|
|
|
free(box->text);
|
2004-08-07 02:19:13 +04:00
|
|
|
free(box->id);
|
2003-07-15 02:57:45 +04:00
|
|
|
/* TODO: free object_params */
|
2002-09-08 22:11:56 +04:00
|
|
|
}
|
2002-12-30 01:27:35 +03:00
|
|
|
|
2003-04-15 21:53:00 +04:00
|
|
|
|
2003-05-31 22:47:00 +04:00
|
|
|
/**
|
|
|
|
* add an object to the box tree
|
|
|
|
*/
|
2004-05-21 18:26:59 +04:00
|
|
|
struct box_result box_object(xmlNode *n, struct box_status *status,
|
2003-07-08 02:10:51 +04:00
|
|
|
struct css_style *style)
|
2003-05-31 22:47:00 +04:00
|
|
|
{
|
|
|
|
struct box *box;
|
2003-07-10 01:33:01 +04:00
|
|
|
struct object_params *po;
|
2003-07-17 18:26:15 +04:00
|
|
|
struct plugin_params* pp;
|
2004-03-27 01:16:31 +03:00
|
|
|
char *s, *url = NULL, *map;
|
2003-07-17 18:26:15 +04:00
|
|
|
xmlNode *c;
|
2004-08-09 20:11:58 +04:00
|
|
|
url_func_result res;
|
2002-12-31 01:56:30 +03:00
|
|
|
|
2004-08-07 02:19:13 +04:00
|
|
|
box = box_create(style, status->href, 0, status->id,
|
2004-01-02 15:04:04 +03:00
|
|
|
status->content->data.html.box_pool);
|
2003-07-08 02:10:51 +04:00
|
|
|
|
2004-08-14 18:30:12 +04:00
|
|
|
po = xcalloc(1, sizeof(*po));
|
2003-05-31 22:47:00 +04:00
|
|
|
|
2004-08-14 18:30:12 +04:00
|
|
|
/* initialise po struct */
|
|
|
|
po->data = 0;
|
|
|
|
po->type = 0;
|
|
|
|
po->codetype = 0;
|
|
|
|
po->codebase = 0;
|
|
|
|
po->classid = 0;
|
|
|
|
po->params = 0;
|
|
|
|
|
|
|
|
/* object data */
|
|
|
|
if ((s = (char *) xmlGetProp(n, (const xmlChar *) "data")) != NULL) {
|
2004-08-09 20:11:58 +04:00
|
|
|
res = url_join(s, status->content->data.html.base_url, &url);
|
2004-07-13 18:03:02 +04:00
|
|
|
/* if url is equivalent to the parent's url,
|
|
|
|
* we've got infinite inclusion. stop it here.
|
|
|
|
* also bail if url_join failed.
|
|
|
|
*/
|
2004-08-09 20:11:58 +04:00
|
|
|
if (res != URL_FUNC_OK || strcasecmp(url, status->content->data.html.base_url) == 0) {
|
2004-07-06 00:19:52 +04:00
|
|
|
free(po);
|
|
|
|
xmlFree(s);
|
2004-12-10 01:22:13 +03:00
|
|
|
return (struct box_result) {0, true, true};
|
2004-07-06 00:19:52 +04:00
|
|
|
}
|
|
|
|
po->data = strdup(s);
|
|
|
|
LOG(("object '%s'", po->data));
|
|
|
|
xmlFree(s);
|
2003-05-31 22:47:00 +04:00
|
|
|
}
|
|
|
|
|
2004-03-27 01:16:31 +03:00
|
|
|
/* imagemap associated with this object */
|
2004-08-14 18:30:12 +04:00
|
|
|
if ((map = xmlGetProp(n, (const xmlChar *) "usemap")) != NULL) {
|
|
|
|
box->usemap = (map[0] == '#') ? xstrdup(map+1) : xstrdup(map);
|
|
|
|
xmlFree(map);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* object type */
|
|
|
|
if ((s = (char *) xmlGetProp(n, (const xmlChar *) "type")) != NULL) {
|
|
|
|
po->type = strdup(s);
|
|
|
|
LOG(("type: %s", s));
|
|
|
|
xmlFree(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* object codetype */
|
|
|
|
if ((s = (char *) xmlGetProp(n, (const xmlChar *) "codetype")) != NULL) {
|
|
|
|
po->codetype = strdup(s);
|
|
|
|
LOG(("codetype: %s", s));
|
|
|
|
xmlFree(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* object codebase */
|
|
|
|
if ((s = (char *) xmlGetProp(n, (const xmlChar *) "codebase")) != NULL) {
|
|
|
|
po->codebase = strdup(s);
|
|
|
|
LOG(("codebase: %s", s));
|
|
|
|
xmlFree(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* object classid */
|
|
|
|
if ((s = (char *) xmlGetProp(n, (const xmlChar *) "classid")) != NULL) {
|
|
|
|
po->classid = strdup(s);
|
|
|
|
LOG(("classid: %s", s));
|
|
|
|
xmlFree(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* parameters
|
|
|
|
* parameter data is stored in a singly linked list.
|
|
|
|
* po->params points to the head of the list.
|
|
|
|
* new parameters are added to the head of the list.
|
|
|
|
*/
|
|
|
|
for (c = n->children; c != NULL; c = c->next) {
|
|
|
|
if (strcmp((const char *) c->name, "param") == 0) {
|
|
|
|
pp = xcalloc(1, sizeof(*pp));
|
|
|
|
|
|
|
|
/* initialise pp struct */
|
|
|
|
pp->name = 0;
|
|
|
|
pp->value = 0;
|
|
|
|
pp->valuetype = 0;
|
|
|
|
pp->type = 0;
|
|
|
|
pp->next = 0;
|
|
|
|
|
|
|
|
if ((s = (char *) xmlGetProp(c, (const xmlChar *) "name")) != NULL) {
|
|
|
|
pp->name = strdup(s);
|
|
|
|
xmlFree(s);
|
|
|
|
}
|
|
|
|
if ((s = (char *) xmlGetProp(c, (const xmlChar *) "value")) != NULL) {
|
|
|
|
pp->value = strdup(s);
|
|
|
|
xmlFree(s);
|
|
|
|
}
|
|
|
|
if ((s = (char *) xmlGetProp(c, (const xmlChar *) "type")) != NULL) {
|
|
|
|
pp->type = strdup(s);
|
|
|
|
xmlFree(s);
|
|
|
|
}
|
|
|
|
if ((s = (char *) xmlGetProp(c, (const xmlChar *) "valuetype")) != NULL) {
|
|
|
|
pp->valuetype = strdup(s);
|
|
|
|
xmlFree(s);
|
|
|
|
} else {
|
|
|
|
pp->valuetype = strdup("data");
|
|
|
|
}
|
|
|
|
|
|
|
|
pp->next = po->params;
|
|
|
|
po->params = pp;
|
|
|
|
} else {
|
|
|
|
/* The first non-param child is the start
|
|
|
|
* of the alt html. Therefore, we should
|
|
|
|
* break out of this loop.
|
|
|
|
*/
|
|
|
|
/** \todo: following statement is *not* breaking the loop ?! Is comment or code wrong here ? */
|
|
|
|
continue;
|
|
|
|
}
|
2003-07-17 18:26:15 +04:00
|
|
|
}
|
2003-07-10 01:33:01 +04:00
|
|
|
|
|
|
|
box->object_params = po;
|
2003-05-31 22:47:00 +04:00
|
|
|
|
|
|
|
/* start fetch */
|
2003-07-10 01:33:01 +04:00
|
|
|
if (plugin_decode(status->content, url, box, po))
|
2004-05-21 18:26:59 +04:00
|
|
|
return (struct box_result) {box, false, false};
|
2003-05-31 22:47:00 +04:00
|
|
|
|
2004-05-21 18:26:59 +04:00
|
|
|
return (struct box_result) {box, true, false};
|
2003-05-31 22:47:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* add an embed to the box tree
|
|
|
|
*/
|
|
|
|
|
2004-05-21 18:26:59 +04:00
|
|
|
struct box_result box_embed(xmlNode *n, struct box_status *status,
|
2003-07-08 02:10:51 +04:00
|
|
|
struct css_style *style)
|
2003-05-31 22:47:00 +04:00
|
|
|
{
|
|
|
|
struct box *box;
|
2003-07-10 01:33:01 +04:00
|
|
|
struct object_params *po;
|
2003-08-25 02:39:55 +04:00
|
|
|
struct plugin_params *pp;
|
2003-12-27 05:03:48 +03:00
|
|
|
char *s, *url = NULL;
|
2003-08-25 02:39:55 +04:00
|
|
|
xmlAttr *a;
|
2004-08-09 20:11:58 +04:00
|
|
|
url_func_result res;
|
2003-05-31 22:47:00 +04:00
|
|
|
|
2004-08-07 02:19:13 +04:00
|
|
|
box = box_create(style, status->href, 0, status->id,
|
2004-01-02 15:04:04 +03:00
|
|
|
status->content->data.html.box_pool);
|
2003-05-31 22:47:00 +04:00
|
|
|
|
|
|
|
po = xcalloc(1, sizeof(*po));
|
|
|
|
|
2003-07-08 02:10:51 +04:00
|
|
|
/* initialise po struct */
|
2004-08-14 18:30:12 +04:00
|
|
|
po->data = 0;
|
|
|
|
po->type = 0;
|
|
|
|
po->codetype = 0;
|
|
|
|
po->codebase = 0;
|
|
|
|
po->classid = 0;
|
|
|
|
po->params = 0;
|
2003-07-08 02:10:51 +04:00
|
|
|
|
2003-05-31 22:47:00 +04:00
|
|
|
/* embed src */
|
2004-08-14 18:30:12 +04:00
|
|
|
if ((s = (char *) xmlGetProp(n, (const xmlChar *) "src")) != NULL) {
|
2004-08-09 20:11:58 +04:00
|
|
|
res = url_join(s, status->content->data.html.base_url, &url);
|
2004-07-13 18:03:02 +04:00
|
|
|
/* if url is equivalent to the parent's url,
|
|
|
|
* we've got infinite inclusion. stop it here.
|
|
|
|
* also bail if url_join failed.
|
|
|
|
*/
|
2004-08-09 20:11:58 +04:00
|
|
|
if (res != URL_FUNC_OK || strcasecmp(url, status->content->data.html.base_url) == 0) {
|
2004-07-06 00:19:52 +04:00
|
|
|
free(po);
|
|
|
|
xmlFree(s);
|
2004-12-10 01:22:13 +03:00
|
|
|
return (struct box_result) {0, false, true};
|
2004-07-06 00:19:52 +04:00
|
|
|
}
|
|
|
|
LOG(("embed '%s'", url));
|
2004-08-14 18:30:12 +04:00
|
|
|
po->data = strdup(s);
|
|
|
|
xmlFree(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* we munge all other attributes into a plugin_parameter structure
|
|
|
|
*/
|
|
|
|
for (a=n->properties; a != NULL; a=a->next) {
|
|
|
|
pp = xcalloc(1, sizeof(*pp));
|
|
|
|
|
|
|
|
/* initialise pp struct */
|
|
|
|
pp->name = 0;
|
|
|
|
pp->value = 0;
|
|
|
|
pp->valuetype = 0;
|
|
|
|
pp->type = 0;
|
|
|
|
pp->next = 0;
|
|
|
|
|
|
|
|
if (strcasecmp((const char*)a->name, "src") != 0) {
|
|
|
|
pp->name = strdup((const char*)a->name);
|
|
|
|
pp->value = strdup((char*)a->children->content);
|
|
|
|
pp->valuetype = strdup("data");
|
|
|
|
pp->next = po->params;
|
|
|
|
po->params = pp;
|
|
|
|
}
|
|
|
|
}
|
2003-08-25 02:39:55 +04:00
|
|
|
|
2003-07-10 01:33:01 +04:00
|
|
|
box->object_params = po;
|
|
|
|
|
2004-08-14 18:30:12 +04:00
|
|
|
/* start fetch */
|
2003-07-08 02:10:51 +04:00
|
|
|
plugin_decode(status->content, url, box, po);
|
2003-05-31 22:47:00 +04:00
|
|
|
|
2004-05-21 18:26:59 +04:00
|
|
|
return (struct box_result) {box, false, false};
|
2003-05-31 22:47:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* add an applet to the box tree
|
|
|
|
*/
|
|
|
|
|
2004-05-21 18:26:59 +04:00
|
|
|
struct box_result box_applet(xmlNode *n, struct box_status *status,
|
2003-07-08 02:10:51 +04:00
|
|
|
struct css_style *style)
|
2003-05-31 22:47:00 +04:00
|
|
|
{
|
|
|
|
struct box *box;
|
2003-07-17 18:26:15 +04:00
|
|
|
struct object_params *po;
|
|
|
|
struct plugin_params *pp;
|
2003-12-27 05:03:48 +03:00
|
|
|
char *s, *url = NULL;
|
2003-07-17 18:26:15 +04:00
|
|
|
xmlNode *c;
|
2004-08-09 20:11:58 +04:00
|
|
|
url_func_result res;
|
2003-05-31 22:47:00 +04:00
|
|
|
|
2004-08-07 02:19:13 +04:00
|
|
|
box = box_create(style, status->href, 0, status->id,
|
2004-01-02 15:04:04 +03:00
|
|
|
status->content->data.html.box_pool);
|
2003-05-31 22:47:00 +04:00
|
|
|
|
2003-07-17 18:26:15 +04:00
|
|
|
po = xcalloc(1, sizeof(*po));
|
2003-05-31 22:47:00 +04:00
|
|
|
|
2003-07-17 18:26:15 +04:00
|
|
|
/* initialise po struct */
|
2004-08-14 18:30:12 +04:00
|
|
|
po->data = 0;
|
|
|
|
po->type = 0;
|
|
|
|
po->codetype = 0;
|
|
|
|
po->codebase = 0;
|
|
|
|
po->classid = 0;
|
|
|
|
po->params = 0;
|
2003-07-17 18:26:15 +04:00
|
|
|
|
2003-12-26 03:17:55 +03:00
|
|
|
/* code */
|
2004-08-14 18:30:12 +04:00
|
|
|
if ((s = (char *) xmlGetProp(n, (const xmlChar *) "code")) != NULL) {
|
2004-08-09 20:11:58 +04:00
|
|
|
res = url_join(s, status->content->data.html.base_url, &url);
|
2004-07-13 18:03:02 +04:00
|
|
|
/* if url is equivalent to the parent's url,
|
|
|
|
* we've got infinite inclusion. stop it here.
|
|
|
|
* also bail if url_join failed.
|
|
|
|
*/
|
2004-08-09 20:11:58 +04:00
|
|
|
if (res != URL_FUNC_OK || strcasecmp(url, status->content->data.html.base_url) == 0) {
|
2003-12-26 03:17:55 +03:00
|
|
|
free(po);
|
|
|
|
xmlFree(s);
|
2004-05-21 18:26:59 +04:00
|
|
|
return (struct box_result) {box, true, false};
|
2003-12-26 03:17:55 +03:00
|
|
|
}
|
|
|
|
LOG(("applet '%s'", url));
|
|
|
|
po->classid = strdup(s);
|
|
|
|
xmlFree(s);
|
|
|
|
}
|
2003-07-17 18:26:15 +04:00
|
|
|
|
2004-08-14 18:30:12 +04:00
|
|
|
/* object codebase */
|
|
|
|
if ((s = (char *) xmlGetProp(n, (const xmlChar *) "codebase")) != NULL) {
|
|
|
|
po->codebase = strdup(s);
|
|
|
|
LOG(("codebase: %s", s));
|
|
|
|
xmlFree(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* parameters
|
|
|
|
* parameter data is stored in a singly linked list.
|
|
|
|
* po->params points to the head of the list.
|
|
|
|
* new parameters are added to the head of the list.
|
|
|
|
*/
|
|
|
|
for (c = n->children; c != 0; c = c->next) {
|
|
|
|
if (strcmp((const char *) c->name, "param") == 0) {
|
|
|
|
pp = xcalloc(1, sizeof(*pp));
|
|
|
|
|
|
|
|
/* initialise pp struct */
|
|
|
|
pp->name = 0;
|
|
|
|
pp->value = 0;
|
|
|
|
pp->valuetype = 0;
|
|
|
|
pp->type = 0;
|
|
|
|
pp->next = 0;
|
|
|
|
|
|
|
|
if ((s = (char *) xmlGetProp(c, (const xmlChar *) "name")) != NULL) {
|
|
|
|
pp->name = strdup(s);
|
|
|
|
xmlFree(s);
|
|
|
|
}
|
|
|
|
if ((s = (char *) xmlGetProp(c, (const xmlChar *) "value")) != NULL) {
|
|
|
|
pp->value = strdup(s);
|
|
|
|
xmlFree(s);
|
|
|
|
}
|
|
|
|
if ((s = (char *) xmlGetProp(c, (const xmlChar *) "type")) != NULL) {
|
|
|
|
pp->type = strdup(s);
|
|
|
|
xmlFree(s);
|
|
|
|
}
|
|
|
|
if ((s = (char *) xmlGetProp(c, (const xmlChar *) "valuetype")) != NULL) {
|
|
|
|
pp->valuetype = strdup(s);
|
|
|
|
xmlFree(s);
|
|
|
|
} else {
|
|
|
|
pp->valuetype = strdup("data");
|
|
|
|
}
|
|
|
|
|
|
|
|
pp->next = po->params;
|
|
|
|
po->params = pp;
|
|
|
|
} else {
|
|
|
|
/* The first non-param child is the start
|
|
|
|
* of the alt html. Therefore, we should
|
|
|
|
* break out of this loop.
|
|
|
|
*/
|
|
|
|
/** \todo: following statement is *not* breaking the loop ?! Is comment or code wrong here ? */
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
box->object_params = po;
|
2003-09-18 01:47:21 +04:00
|
|
|
|
2003-05-31 22:47:00 +04:00
|
|
|
/* start fetch */
|
2004-08-14 18:30:12 +04:00
|
|
|
if (plugin_decode(status->content, url, box, po))
|
|
|
|
return (struct box_result) {box, false, false};
|
2003-05-31 22:47:00 +04:00
|
|
|
|
2004-08-14 18:30:12 +04:00
|
|
|
return (struct box_result) {box, true, false};
|
2003-05-31 22:47:00 +04:00
|
|
|
}
|
2003-07-10 01:33:01 +04:00
|
|
|
|
2003-08-25 02:39:55 +04:00
|
|
|
/**
|
|
|
|
* box_iframe
|
|
|
|
* add an iframe to the box tree
|
|
|
|
* TODO - implement GUI nested wimp stuff 'cos this looks naff atm. (16_5)
|
|
|
|
*/
|
2004-05-21 18:26:59 +04:00
|
|
|
struct box_result box_iframe(xmlNode *n, struct box_status *status,
|
2003-08-25 02:39:55 +04:00
|
|
|
struct css_style *style)
|
|
|
|
{
|
2004-08-14 18:30:12 +04:00
|
|
|
struct box *box;
|
2003-08-25 02:39:55 +04:00
|
|
|
struct object_params *po;
|
2003-12-27 05:03:48 +03:00
|
|
|
char *s, *url = NULL;
|
2004-08-09 20:11:58 +04:00
|
|
|
url_func_result res;
|
2003-08-25 02:39:55 +04:00
|
|
|
|
2004-08-07 02:19:13 +04:00
|
|
|
box = box_create(style, status->href, 0, status->id,
|
2004-01-02 15:04:04 +03:00
|
|
|
status->content->data.html.box_pool);
|
2003-08-25 02:39:55 +04:00
|
|
|
|
|
|
|
po = xcalloc(1, sizeof(*po));
|
|
|
|
|
|
|
|
/* initialise po struct */
|
2004-08-14 18:30:12 +04:00
|
|
|
po->data = 0;
|
|
|
|
po->type = 0;
|
|
|
|
po->codetype = 0;
|
|
|
|
po->codebase = 0;
|
|
|
|
po->classid = 0;
|
|
|
|
po->params = 0;
|
2003-08-25 02:39:55 +04:00
|
|
|
|
|
|
|
/* iframe src */
|
2004-08-14 18:30:12 +04:00
|
|
|
if ((s = (char *) xmlGetProp(n, (const xmlChar *) "src")) != NULL) {
|
2004-08-09 20:11:58 +04:00
|
|
|
res = url_join(s, status->content->data.html.base_url, &url);
|
2004-07-13 18:03:02 +04:00
|
|
|
/* if url is equivalent to the parent's url,
|
|
|
|
* we've got infinite inclusion. stop it here.
|
|
|
|
* also bail if url_join failed.
|
|
|
|
*/
|
2004-08-09 20:11:58 +04:00
|
|
|
if (res != URL_FUNC_OK || strcasecmp(url, status->content->data.html.base_url) == 0) {
|
2003-12-26 03:17:55 +03:00
|
|
|
free(po);
|
|
|
|
xmlFree(s);
|
2004-12-10 01:22:13 +03:00
|
|
|
return (struct box_result) {0, false, true};
|
2003-12-26 03:17:55 +03:00
|
|
|
}
|
|
|
|
LOG(("embed '%s'", url));
|
|
|
|
po->data = strdup(s);
|
|
|
|
xmlFree(s);
|
|
|
|
}
|
2003-08-25 02:39:55 +04:00
|
|
|
|
|
|
|
box->object_params = po;
|
|
|
|
|
2004-08-14 18:30:12 +04:00
|
|
|
/* start fetch */
|
2003-08-25 02:39:55 +04:00
|
|
|
plugin_decode(status->content, url, box, po);
|
|
|
|
|
2004-05-21 18:26:59 +04:00
|
|
|
return (struct box_result) {box, false, false};
|
2003-08-25 02:39:55 +04:00
|
|
|
}
|
2003-07-10 01:33:01 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* plugin_decode
|
|
|
|
* This function checks that the contents of the plugin_object struct
|
|
|
|
* are valid. If they are, it initiates the fetch process. If they are
|
|
|
|
* not, it exits, leaving the box structure as it was on entry. This is
|
|
|
|
* necessary as there are multiple ways of declaring an object's attributes.
|
|
|
|
*
|
|
|
|
* Returns false if the object could not be handled.
|
2003-12-26 03:17:55 +03:00
|
|
|
*
|
2004-08-14 18:30:12 +04:00
|
|
|
* TODO: plug failure leaks
|
2003-07-10 01:33:01 +04:00
|
|
|
*/
|
|
|
|
bool plugin_decode(struct content* content, char* url, struct box* box,
|
2004-08-14 18:30:12 +04:00
|
|
|
struct object_params* po)
|
2003-07-10 01:33:01 +04:00
|
|
|
{
|
2004-08-14 18:30:12 +04:00
|
|
|
struct plugin_params * pp;
|
|
|
|
url_func_result res;
|
|
|
|
|
|
|
|
/* Check if the codebase attribute is defined.
|
|
|
|
* If it is not, set it to the codebase of the current document.
|
|
|
|
*/
|
|
|
|
if (po->codebase == 0)
|
|
|
|
res = url_join("./", content->data.html.base_url, &po->codebase);
|
|
|
|
else
|
|
|
|
res = url_join(po->codebase, content->data.html.base_url, &po->codebase);
|
|
|
|
|
|
|
|
if (res != URL_FUNC_OK)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
/* Set basehref */
|
|
|
|
po->basehref = strdup(content->data.html.base_url);
|
|
|
|
|
|
|
|
/* Check that we have some data specified.
|
|
|
|
* First, check the data attribute.
|
|
|
|
* Second, check the classid attribute.
|
|
|
|
* The data attribute takes precedence.
|
|
|
|
* If neither are specified or if classid begins "clsid:",
|
|
|
|
* we can't handle this object.
|
|
|
|
*/
|
|
|
|
if (po->data == 0 && po->classid == 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (po->data == 0 && po->classid != 0) {
|
|
|
|
if (strncasecmp(po->classid, "clsid:", 6) == 0) {
|
|
|
|
/* Flash */
|
|
|
|
if (strcasecmp(po->classid, "clsid:D27CDB6E-AE6D-11cf-96B8-444553540000") == 0) {
|
|
|
|
for (pp = po->params;
|
|
|
|
pp != 0 && strcasecmp(pp->name, "movie") != 0;
|
|
|
|
pp = pp->next)
|
|
|
|
/* no body */;
|
|
|
|
if (pp == 0)
|
|
|
|
return false;
|
|
|
|
res = url_join(pp->value, po->basehref, &url);
|
|
|
|
if (res != URL_FUNC_OK)
|
|
|
|
return false;
|
|
|
|
/* munge the codebase */
|
|
|
|
res = url_join("./",
|
|
|
|
content->data.html.base_url,
|
|
|
|
&po->codebase);
|
|
|
|
if (res != URL_FUNC_OK)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
LOG(("ActiveX object - n0"));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
res = url_join(po->classid, po->codebase, &url);
|
|
|
|
if (res != URL_FUNC_OK)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
/* The java plugin doesn't need the .class extension
|
|
|
|
* so we strip it.
|
|
|
|
*/
|
|
|
|
if (strcasecmp(&po->classid[strlen(po->classid)-6],
|
|
|
|
".class") == 0)
|
|
|
|
po->classid[strlen(po->classid)-6] = 0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
res = url_join(po->data, po->codebase, &url);
|
|
|
|
if (res != URL_FUNC_OK)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if the declared mime type is understandable.
|
|
|
|
* Checks type and codetype attributes.
|
|
|
|
*/
|
|
|
|
if (po->type != 0 && content_lookup(po->type) == CONTENT_OTHER)
|
|
|
|
return false;
|
|
|
|
if (po->codetype != 0 && content_lookup(po->codetype) == CONTENT_OTHER)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
/* If we've got to here, the object declaration has provided us with
|
|
|
|
* enough data to enable us to have a go at downloading and
|
|
|
|
* displaying it.
|
|
|
|
*
|
|
|
|
* We may still find that the object has a MIME type that we can't
|
|
|
|
* handle when we fetch it (if the type was not specified or is
|
|
|
|
* different to that given in the attributes).
|
|
|
|
*/
|
|
|
|
html_fetch_object(content, url, box, 0, 1000, 1000, false);
|
|
|
|
|
|
|
|
return true;
|
2003-07-10 01:33:01 +04:00
|
|
|
}
|
2004-04-02 22:13:23 +04:00
|
|
|
|
2003-09-03 21:52:45 +04:00
|
|
|
|
2004-05-21 18:26:59 +04:00
|
|
|
struct box_result box_frameset(xmlNode *n, struct box_status *status,
|
2004-04-02 22:13:23 +04:00
|
|
|
struct css_style *style)
|
|
|
|
{
|
|
|
|
unsigned int row, col;
|
|
|
|
unsigned int rows = 1, cols = 1;
|
2004-05-21 18:26:59 +04:00
|
|
|
int object_width, object_height;
|
2004-04-02 22:13:23 +04:00
|
|
|
char *s, *s1, *url;
|
|
|
|
struct box *box;
|
|
|
|
struct box *row_box;
|
|
|
|
struct box *cell_box;
|
2004-05-21 18:26:59 +04:00
|
|
|
struct box *object_box;
|
2004-04-02 22:13:23 +04:00
|
|
|
struct css_style *row_style;
|
2004-12-06 00:42:08 +03:00
|
|
|
struct css_style *cell_style;
|
|
|
|
struct css_style *object_style;
|
2004-05-21 18:26:59 +04:00
|
|
|
struct box_result r;
|
|
|
|
struct box_multi_length *row_height = 0, *col_width = 0;
|
2004-04-02 22:13:23 +04:00
|
|
|
xmlNode *c;
|
2004-08-09 20:11:58 +04:00
|
|
|
url_func_result res;
|
2004-04-02 22:13:23 +04:00
|
|
|
|
2004-08-07 02:19:13 +04:00
|
|
|
box = box_create(style, 0, status->title, status->id,
|
2004-04-02 22:13:23 +04:00
|
|
|
status->content->data.html.box_pool);
|
|
|
|
box->type = BOX_TABLE;
|
|
|
|
|
2004-05-21 18:26:59 +04:00
|
|
|
/* parse rows and columns */
|
2004-08-14 18:30:12 +04:00
|
|
|
if ((s = (char *) xmlGetProp(n, (const xmlChar *) "rows")) != NULL) {
|
2004-05-21 18:26:59 +04:00
|
|
|
row_height = box_parse_multi_lengths(s, &rows);
|
|
|
|
xmlFree(s);
|
|
|
|
if (!row_height) {
|
|
|
|
box_free_box(box);
|
|
|
|
return (struct box_result) {0, false, true};
|
|
|
|
}
|
|
|
|
}
|
2004-04-02 22:13:23 +04:00
|
|
|
|
2004-08-14 18:30:12 +04:00
|
|
|
if ((s = (char *) xmlGetProp(n, (const xmlChar *) "cols")) != NULL) {
|
2004-05-21 18:26:59 +04:00
|
|
|
col_width = box_parse_multi_lengths(s, &cols);
|
|
|
|
xmlFree(s);
|
|
|
|
if (!col_width) {
|
|
|
|
free(row_height);
|
|
|
|
box_free_box(box);
|
|
|
|
return (struct box_result) {0, false, true};
|
|
|
|
}
|
|
|
|
}
|
2004-04-02 22:13:23 +04:00
|
|
|
|
|
|
|
LOG(("rows %u, cols %u", rows, cols));
|
|
|
|
|
2004-05-21 18:26:59 +04:00
|
|
|
box->min_width = 1;
|
|
|
|
box->max_width = 10000;
|
|
|
|
box->col = malloc(sizeof box->col[0] * cols);
|
|
|
|
if (!box->col) {
|
|
|
|
free(row_height);
|
|
|
|
free(col_width);
|
|
|
|
box_free_box(box);
|
|
|
|
return (struct box_result) {0, false, true};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (col_width) {
|
|
|
|
for (col = 0; col != cols; col++) {
|
|
|
|
if (col_width[col].type == LENGTH_PX) {
|
|
|
|
box->col[col].type = COLUMN_WIDTH_FIXED;
|
|
|
|
box->col[col].width = col_width[col].value;
|
|
|
|
} else if (col_width[col].type == LENGTH_PERCENT) {
|
|
|
|
box->col[col].type = COLUMN_WIDTH_PERCENT;
|
|
|
|
box->col[col].width = col_width[col].value;
|
|
|
|
} else {
|
|
|
|
box->col[col].type = COLUMN_WIDTH_RELATIVE;
|
|
|
|
box->col[col].width = col_width[col].value;
|
|
|
|
}
|
|
|
|
box->col[col].min = 1;
|
|
|
|
box->col[col].max = 10000;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
box->col[0].type = COLUMN_WIDTH_RELATIVE;
|
|
|
|
box->col[0].width = 1;
|
|
|
|
box->col[0].min = 1;
|
|
|
|
box->col[0].max = 10000;
|
|
|
|
}
|
|
|
|
|
2004-04-02 22:13:23 +04:00
|
|
|
/* create the frameset table */
|
|
|
|
c = n->children;
|
|
|
|
for (row = 0; c && row != rows; row++) {
|
|
|
|
row_style = malloc(sizeof (struct css_style));
|
2004-05-21 18:26:59 +04:00
|
|
|
if (!row_style) {
|
2004-12-06 00:42:08 +03:00
|
|
|
box_free(box);
|
2004-05-21 18:26:59 +04:00
|
|
|
free(row_height);
|
|
|
|
free(col_width);
|
2004-12-06 00:42:08 +03:00
|
|
|
return (struct box_result) {0, false, true};
|
2004-05-21 18:26:59 +04:00
|
|
|
}
|
2004-04-02 22:13:23 +04:00
|
|
|
memcpy(row_style, style, sizeof (struct css_style));
|
2004-05-21 18:26:59 +04:00
|
|
|
object_height = 1000; /** \todo get available height */
|
|
|
|
/* if (row_height) {
|
|
|
|
row_style->height.height = CSS_HEIGHT_LENGTH;
|
|
|
|
row_style->height.length.unit = CSS_UNIT_PX;
|
|
|
|
if (row_height[row].type == LENGTH_PERCENT)
|
|
|
|
row_style->height.length.value = 1000 *
|
|
|
|
row_height[row].value / 100;
|
|
|
|
else if (row_height[row].type == LENGTH_RELATIVE)
|
|
|
|
row_style->height.length.value = 100 *
|
|
|
|
row_height[row].value;
|
|
|
|
else
|
|
|
|
row_style->height.length.value =
|
|
|
|
row_height[row].value;
|
|
|
|
object_height = row_style->height.length.value;
|
|
|
|
}*/
|
2004-08-07 02:19:13 +04:00
|
|
|
row_box = box_create(row_style, 0, 0, 0,
|
2004-04-02 22:13:23 +04:00
|
|
|
status->content->data.html.box_pool);
|
|
|
|
row_box->type = BOX_TABLE_ROW;
|
|
|
|
box_add_child(box, row_box);
|
|
|
|
|
|
|
|
for (col = 0; c && col != cols; col++) {
|
|
|
|
while (c && !(c->type == XML_ELEMENT_NODE && (
|
|
|
|
strcmp((const char *) c->name, "frame") == 0 ||
|
|
|
|
strcmp((const char *) c->name, "frameset") == 0
|
|
|
|
)))
|
|
|
|
c = c->next;
|
|
|
|
if (!c)
|
|
|
|
break;
|
|
|
|
|
2004-05-21 18:26:59 +04:00
|
|
|
/* estimate frame width */
|
|
|
|
object_width = status->content->available_width;
|
|
|
|
if (col_width && col_width[col].type == LENGTH_PX)
|
|
|
|
object_width = col_width[col].value;
|
|
|
|
|
2004-12-06 00:42:08 +03:00
|
|
|
cell_style = malloc(sizeof (struct css_style));
|
|
|
|
if (!cell_style) {
|
|
|
|
box_free(box);
|
|
|
|
free(row_height);
|
|
|
|
free(col_width);
|
|
|
|
return (struct box_result) {0, false, true};
|
|
|
|
}
|
|
|
|
memcpy(cell_style, style, sizeof (struct css_style));
|
|
|
|
css_cascade(cell_style, &css_blank_style);
|
|
|
|
cell_style->overflow = CSS_OVERFLOW_AUTO;
|
|
|
|
|
|
|
|
cell_box = box_create(cell_style, 0, 0, 0,
|
2004-05-21 18:26:59 +04:00
|
|
|
status->content->data.html.box_pool);
|
2004-04-02 22:13:23 +04:00
|
|
|
cell_box->type = BOX_TABLE_CELL;
|
|
|
|
box_add_child(row_box, cell_box);
|
|
|
|
|
|
|
|
if (strcmp((const char *) c->name, "frameset") == 0) {
|
|
|
|
LOG(("frameset"));
|
|
|
|
r = box_frameset(c, status, style);
|
2004-05-21 18:26:59 +04:00
|
|
|
if (r.memory_error) {
|
|
|
|
box_free(box);
|
|
|
|
free(row_height);
|
|
|
|
free(col_width);
|
|
|
|
return (struct box_result) {0, false,
|
|
|
|
true};
|
|
|
|
}
|
|
|
|
r.box->style_clone = 1;
|
2004-04-02 22:13:23 +04:00
|
|
|
box_add_child(cell_box, r.box);
|
|
|
|
|
|
|
|
c = c->next;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2004-12-06 00:42:08 +03:00
|
|
|
object_style = malloc(sizeof (struct css_style));
|
|
|
|
if (!object_style) {
|
|
|
|
box_free(box);
|
|
|
|
free(row_height);
|
|
|
|
free(col_width);
|
|
|
|
return (struct box_result) {0, false, true};
|
|
|
|
}
|
|
|
|
memcpy(object_style, style, sizeof (struct css_style));
|
|
|
|
if (col_width && col_width[col].type == LENGTH_PX) {
|
|
|
|
object_style->width.width = CSS_WIDTH_LENGTH;
|
|
|
|
object_style->width.value.length.unit =
|
|
|
|
CSS_UNIT_PX;
|
2004-12-10 01:22:13 +03:00
|
|
|
object_style->width.value.length.value =
|
|
|
|
object_width;
|
|
|
|
}
|
2004-12-06 00:42:08 +03:00
|
|
|
|
|
|
|
object_box = box_create(object_style, 0, 0, 0,
|
2004-05-21 18:26:59 +04:00
|
|
|
status->content->data.html.box_pool);
|
|
|
|
object_box->type = BOX_BLOCK;
|
|
|
|
box_add_child(cell_box, object_box);
|
|
|
|
|
2004-08-14 18:30:12 +04:00
|
|
|
if ((s = (char *) xmlGetProp(c, (const xmlChar *) "src")) == NULL) {
|
2004-04-02 22:13:23 +04:00
|
|
|
c = c->next;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
s1 = strip(s);
|
2004-08-09 20:11:58 +04:00
|
|
|
res = url_join(s1, status->content->data.html.base_url, &url);
|
2004-07-13 18:03:02 +04:00
|
|
|
/* if url is equivalent to the parent's url,
|
|
|
|
* we've got infinite inclusion. stop it here.
|
|
|
|
* also bail if url_join failed.
|
|
|
|
*/
|
2004-08-09 20:11:58 +04:00
|
|
|
if (res != URL_FUNC_OK || strcasecmp(url, status->content->data.html.base_url) == 0) {
|
2004-04-02 22:13:23 +04:00
|
|
|
xmlFree(s);
|
|
|
|
c = c->next;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
LOG(("frame, url '%s'", url));
|
|
|
|
|
2004-05-21 18:26:59 +04:00
|
|
|
html_fetch_object(status->content, url, object_box, 0,
|
2004-06-10 03:13:55 +04:00
|
|
|
object_width, object_height, false);
|
2004-04-02 22:13:23 +04:00
|
|
|
xmlFree(s);
|
|
|
|
|
|
|
|
c = c->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-05-21 18:26:59 +04:00
|
|
|
free(row_height);
|
|
|
|
free(col_width);
|
|
|
|
|
|
|
|
style->width.width = CSS_WIDTH_PERCENT;
|
|
|
|
style->width.value.percent = 100;
|
|
|
|
|
|
|
|
return (struct box_result) {box, false, false};
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Parse a multi-length-list, as defined by HTML 4.01.
|
|
|
|
*
|
|
|
|
* \param s string to parse
|
|
|
|
* \param count updated to number of entries
|
|
|
|
* \return array of struct box_multi_length, or 0 on memory exhaustion
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct box_multi_length *box_parse_multi_lengths(const char *s,
|
|
|
|
unsigned int *count)
|
|
|
|
{
|
|
|
|
char *end;
|
2004-08-14 18:30:12 +04:00
|
|
|
unsigned int i, n;
|
2004-05-21 18:26:59 +04:00
|
|
|
struct box_multi_length *length;
|
|
|
|
|
2004-08-14 18:30:12 +04:00
|
|
|
for (i = 0, n = 1; s[i]; i++)
|
2004-05-21 18:26:59 +04:00
|
|
|
if (s[i] == ',')
|
|
|
|
n++;
|
|
|
|
|
2004-08-14 18:30:12 +04:00
|
|
|
if ((length = malloc(sizeof *length * n)) == NULL)
|
|
|
|
return NULL;
|
2004-05-21 18:26:59 +04:00
|
|
|
|
|
|
|
for (i = 0; i != n; i++) {
|
2004-05-21 21:08:48 +04:00
|
|
|
while (isspace(*s))
|
|
|
|
s++;
|
2004-05-21 18:26:59 +04:00
|
|
|
length[i].value = strtof(s, &end);
|
|
|
|
if (length[i].value <= 0)
|
|
|
|
length[i].value = 1;
|
|
|
|
s = end;
|
|
|
|
switch (*s) {
|
|
|
|
case '%': length[i].type = LENGTH_PERCENT; break;
|
|
|
|
case '*': length[i].type = LENGTH_RELATIVE; break;
|
|
|
|
default: length[i].type = LENGTH_PX; break;
|
|
|
|
}
|
|
|
|
while (*s && *s != ',')
|
|
|
|
s++;
|
|
|
|
if (*s == ',')
|
|
|
|
s++;
|
|
|
|
}
|
|
|
|
|
|
|
|
*count = n;
|
|
|
|
return length;
|
2004-04-02 22:13:23 +04:00
|
|
|
}
|
2004-07-18 03:32:09 +04:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Find the absolute coordinates of a box.
|
|
|
|
*
|
|
|
|
* \param box the box to calculate coordinates of
|
|
|
|
* \param x updated to x coordinate
|
|
|
|
* \param y updated to y coordinate
|
|
|
|
*/
|
|
|
|
|
|
|
|
void box_coords(struct box *box, int *x, int *y)
|
|
|
|
{
|
|
|
|
*x = box->x;
|
|
|
|
*y = box->y;
|
|
|
|
while (box->parent) {
|
2004-08-02 00:28:02 +04:00
|
|
|
if (box_is_float(box)) {
|
2004-07-18 03:32:09 +04:00
|
|
|
do {
|
|
|
|
box = box->parent;
|
|
|
|
} while (!box->float_children);
|
|
|
|
} else
|
|
|
|
box = box->parent;
|
2004-10-18 01:10:19 +04:00
|
|
|
*x += box->x - box->scroll_x;
|
|
|
|
*y += box->y - box->scroll_y;
|
2004-07-18 03:32:09 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Find the boxes at a point.
|
|
|
|
*
|
|
|
|
* \param box box to search children of
|
2004-10-18 01:10:19 +04:00
|
|
|
* \param x point to find, in global document coordinates
|
2004-07-18 03:32:09 +04:00
|
|
|
* \param y point to find, in global document coordinates
|
|
|
|
* \param box_x position of box, in global document coordinates, updated
|
|
|
|
* to position of returned box, if any
|
|
|
|
* \param box_y position of box, in global document coordinates, updated
|
|
|
|
* to position of returned box, if any
|
|
|
|
* \param content updated to content of object that returned box is in, if any
|
|
|
|
* \return box at given point, or 0 if none found
|
|
|
|
*
|
|
|
|
* To find all the boxes in the heirarchy at a certain point, use code like
|
|
|
|
* this:
|
|
|
|
* \code
|
|
|
|
* struct box *box = top_of_document_to_search;
|
|
|
|
* int box_x = 0, box_y = 0;
|
|
|
|
* struct content *content = document_to_search;
|
|
|
|
*
|
|
|
|
* while ((box = box_at_point(box, x, y, &box_x, &box_y, &content))) {
|
|
|
|
* // process box
|
|
|
|
* }
|
|
|
|
* \endcode
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct box *box_at_point(struct box *box, int x, int y,
|
|
|
|
int *box_x, int *box_y,
|
|
|
|
struct content **content)
|
|
|
|
{
|
2004-08-02 00:28:02 +04:00
|
|
|
int bx = *box_x, by = *box_y;
|
|
|
|
struct box *child, *sibling;
|
2004-07-18 03:32:09 +04:00
|
|
|
|
|
|
|
assert(box);
|
|
|
|
|
|
|
|
/* drill into HTML objects */
|
|
|
|
if (box->object) {
|
|
|
|
if (box->object->type == CONTENT_HTML &&
|
|
|
|
box->object->data.html.layout) {
|
|
|
|
*content = box->object;
|
|
|
|
box = box->object->data.html.layout;
|
|
|
|
} else {
|
2004-08-02 00:28:02 +04:00
|
|
|
goto siblings;
|
2004-07-18 03:32:09 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* consider floats first, since they will often overlap other boxes */
|
|
|
|
for (child = box->float_children; child; child = child->next_float) {
|
2004-10-18 01:10:19 +04:00
|
|
|
if (box_contains_point(child, x - bx, y - by)) {
|
|
|
|
*box_x += child->x - child->scroll_x;
|
|
|
|
*box_y += child->y - child->scroll_y;
|
2004-07-18 03:32:09 +04:00
|
|
|
return child;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* non-float children */
|
|
|
|
for (child = box->children; child; child = child->next) {
|
2004-08-02 00:28:02 +04:00
|
|
|
if (box_is_float(child))
|
2004-07-18 03:32:09 +04:00
|
|
|
continue;
|
2004-10-18 01:10:19 +04:00
|
|
|
if (box_contains_point(child, x - bx, y - by)) {
|
|
|
|
*box_x += child->x - child->scroll_x;
|
|
|
|
*box_y += child->y - child->scroll_y;
|
2004-07-18 03:32:09 +04:00
|
|
|
return child;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-08-02 00:28:02 +04:00
|
|
|
siblings:
|
|
|
|
/* siblings and siblings of ancestors */
|
|
|
|
while (box) {
|
|
|
|
if (!box_is_float(box)) {
|
2004-10-18 01:10:19 +04:00
|
|
|
bx -= box->x - box->scroll_x;
|
|
|
|
by -= box->y - box->scroll_y;
|
2004-08-02 00:28:02 +04:00
|
|
|
for (sibling = box->next; sibling;
|
|
|
|
sibling = sibling->next) {
|
|
|
|
if (box_is_float(sibling))
|
|
|
|
continue;
|
2004-10-18 01:10:19 +04:00
|
|
|
if (box_contains_point(sibling,
|
|
|
|
x - bx, y - by)) {
|
|
|
|
*box_x = bx + sibling->x -
|
|
|
|
sibling->scroll_x;
|
|
|
|
*box_y = by + sibling->y -
|
|
|
|
sibling->scroll_y;
|
2004-08-02 00:28:02 +04:00
|
|
|
return sibling;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
box = box->parent;
|
|
|
|
} else {
|
2004-10-18 01:10:19 +04:00
|
|
|
bx -= box->x - box->scroll_x;
|
|
|
|
by -= box->y - box->scroll_y;
|
2004-08-02 00:28:02 +04:00
|
|
|
for (sibling = box->next_float; sibling;
|
|
|
|
sibling = sibling->next_float) {
|
2004-10-18 01:10:19 +04:00
|
|
|
if (box_contains_point(sibling,
|
|
|
|
x - bx, y - by)) {
|
|
|
|
*box_x = bx + sibling->x -
|
|
|
|
sibling->scroll_x;
|
|
|
|
*box_y = by + sibling->y -
|
|
|
|
sibling->scroll_y;
|
2004-08-02 00:28:02 +04:00
|
|
|
return sibling;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
do {
|
|
|
|
box = box->parent;
|
|
|
|
} while (!box->float_children);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-07-18 03:32:09 +04:00
|
|
|
return 0;
|
|
|
|
}
|
2004-07-18 21:38:01 +04:00
|
|
|
|
|
|
|
|
2004-10-18 01:10:19 +04:00
|
|
|
/**
|
|
|
|
* Determine if a point lies within a box.
|
|
|
|
*
|
|
|
|
* \param box box to consider
|
|
|
|
* \param x coordinate relative to box parent
|
|
|
|
* \param y coordinate relative to box parent
|
|
|
|
* \return true if the point is within the box or a descendant box
|
|
|
|
*
|
|
|
|
* This is a helper function for box_at_point().
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool box_contains_point(struct box *box, int x, int y)
|
|
|
|
{
|
2004-11-20 03:02:56 +03:00
|
|
|
if (box->style && box->style->overflow != CSS_OVERFLOW_VISIBLE) {
|
2004-10-18 01:10:19 +04:00
|
|
|
if (box->x <= x &&
|
|
|
|
x < box->x + box->padding[LEFT] + box->width +
|
|
|
|
box->padding[RIGHT] &&
|
|
|
|
box->y <= y &&
|
|
|
|
y < box->y + box->padding[TOP] + box->height +
|
|
|
|
box->padding[BOTTOM])
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
if (box->x + box->descendant_x0 <= x &&
|
|
|
|
x < box->x + box->descendant_x1 &&
|
|
|
|
box->y + box->descendant_y0 <= y &&
|
|
|
|
y < box->y + box->descendant_y1)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-07-18 21:38:01 +04:00
|
|
|
/**
|
|
|
|
* Find the box containing an object at the given coordinates, if any.
|
|
|
|
*
|
|
|
|
* \param c content to search, must have type CONTENT_HTML
|
|
|
|
* \param x coordinates in document units
|
|
|
|
* \param y coordinates in document units
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct box *box_object_at_point(struct content *c, int x, int y)
|
|
|
|
{
|
|
|
|
struct box *box = c->data.html.layout;
|
|
|
|
int box_x = 0, box_y = 0;
|
|
|
|
struct content *content = c;
|
|
|
|
struct box *object_box = 0;
|
|
|
|
|
|
|
|
assert(c->type == CONTENT_HTML);
|
|
|
|
|
2004-08-14 18:30:12 +04:00
|
|
|
while ((box = box_at_point(box, x, y, &box_x, &box_y, &content)) != NULL) {
|
2004-07-18 21:38:01 +04:00
|
|
|
if (box->style &&
|
|
|
|
box->style->visibility == CSS_VISIBILITY_HIDDEN)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (box->object)
|
|
|
|
object_box = box;
|
|
|
|
}
|
|
|
|
|
|
|
|
return object_box;
|
|
|
|
}
|
2004-08-07 02:19:13 +04:00
|
|
|
|
2004-08-26 02:11:38 +04:00
|
|
|
|
2004-08-07 02:19:13 +04:00
|
|
|
/**
|
2004-08-26 02:11:38 +04:00
|
|
|
* Find a box based upon its id attribute.
|
2004-08-07 02:19:13 +04:00
|
|
|
*
|
|
|
|
* \param box box to search
|
|
|
|
* \param id id to look for
|
|
|
|
* \return the box or 0 if not found
|
|
|
|
*/
|
2004-08-14 18:30:12 +04:00
|
|
|
struct box *box_find_by_id(struct box *box, const char *id)
|
2004-08-07 02:19:13 +04:00
|
|
|
{
|
|
|
|
struct box *a, *b;
|
|
|
|
|
2004-08-26 02:11:38 +04:00
|
|
|
if (box->id != NULL && strcmp(id, box->id) == 0)
|
2004-08-07 02:19:13 +04:00
|
|
|
return box;
|
|
|
|
|
|
|
|
for (a = box->children; a; a = a->next) {
|
2004-08-26 02:11:38 +04:00
|
|
|
if ((b = box_find_by_id(a, id)) != NULL)
|
2004-08-07 02:19:13 +04:00
|
|
|
return b;
|
|
|
|
}
|
|
|
|
|
2004-08-14 18:30:12 +04:00
|
|
|
return NULL;
|
2004-08-07 02:19:13 +04:00
|
|
|
}
|