2005-03-26 04:12:27 +03: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
|
|
|
|
* Copyright 2005 James Bursa <bursa@users.sourceforge.net>
|
|
|
|
* Copyright 2003 Phil Mellor <monkeyson@users.sourceforge.net>
|
|
|
|
* Copyright 2005 John M Bell <jmb202@ecs.soton.ac.uk>
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** \file
|
|
|
|
* Conversion of XML tree to box tree (implementation).
|
|
|
|
*/
|
|
|
|
|
2005-04-17 20:56:41 +04:00
|
|
|
#define _GNU_SOURCE /* for strndup */
|
2005-03-26 04:12:27 +03:00
|
|
|
#include <assert.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include "libxml/HTMLparser.h"
|
|
|
|
#include "netsurf/utils/config.h"
|
|
|
|
#include "netsurf/content/content.h"
|
|
|
|
#include "netsurf/css/css.h"
|
|
|
|
#include "netsurf/desktop/options.h"
|
|
|
|
#include "netsurf/render/box.h"
|
|
|
|
#include "netsurf/render/form.h"
|
|
|
|
#include "netsurf/render/html.h"
|
|
|
|
#ifdef riscos
|
|
|
|
#include "netsurf/desktop/gui.h"
|
|
|
|
#endif
|
2005-04-28 05:17:52 +04:00
|
|
|
//#define NDEBUG
|
2005-03-26 04:12:27 +03:00
|
|
|
#include "netsurf/utils/log.h"
|
|
|
|
#include "netsurf/utils/messages.h"
|
2005-04-09 13:47:37 +04:00
|
|
|
#include "netsurf/utils/talloc.h"
|
2005-03-26 04:12:27 +03:00
|
|
|
#include "netsurf/utils/url.h"
|
|
|
|
#include "netsurf/utils/utils.h"
|
|
|
|
|
|
|
|
|
|
|
|
/** MultiLength, as defined by HTML 4.01. */
|
|
|
|
struct box_multi_length {
|
|
|
|
enum { LENGTH_PX, LENGTH_PERCENT, LENGTH_RELATIVE } type;
|
|
|
|
float value;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static const content_type image_types[] = {
|
|
|
|
#ifdef WITH_JPEG
|
|
|
|
CONTENT_JPEG,
|
|
|
|
#endif
|
|
|
|
#ifdef WITH_GIF
|
|
|
|
CONTENT_GIF,
|
|
|
|
#endif
|
2006-02-25 21:51:51 +03:00
|
|
|
#ifdef WITH_BMP
|
|
|
|
CONTENT_BMP,
|
2005-03-26 04:12:27 +03:00
|
|
|
#endif
|
|
|
|
#ifdef WITH_MNG
|
2006-02-25 21:51:51 +03:00
|
|
|
CONTENT_PNG,
|
2005-03-26 04:12:27 +03:00
|
|
|
CONTENT_JNG,
|
|
|
|
CONTENT_MNG,
|
|
|
|
#endif
|
|
|
|
#ifdef WITH_SPRITE
|
|
|
|
CONTENT_SPRITE,
|
|
|
|
#endif
|
|
|
|
#ifdef WITH_DRAW
|
|
|
|
CONTENT_DRAW,
|
2005-12-10 17:31:33 +03:00
|
|
|
#endif
|
|
|
|
#ifdef WITH_ARTWORKS
|
|
|
|
CONTENT_ARTWORKS,
|
2005-03-26 04:12:27 +03:00
|
|
|
#endif
|
|
|
|
CONTENT_UNKNOWN };
|
|
|
|
|
|
|
|
#define MAX_SPAN (100)
|
|
|
|
|
|
|
|
|
2005-08-21 02:52:20 +04:00
|
|
|
/* the strings are not important, since we just compare the pointers */
|
|
|
|
const char *TARGET_SELF = "_self";
|
|
|
|
const char *TARGET_PARENT = "_parent";
|
|
|
|
const char *TARGET_TOP = "_top";
|
|
|
|
|
|
|
|
|
2005-03-26 04:12:27 +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,
|
2006-06-26 08:52:34 +04:00
|
|
|
struct box *containing_block,
|
2005-08-23 02:49:52 +04:00
|
|
|
char *href, const char *target, char *title);
|
2005-03-28 23:17:06 +04:00
|
|
|
bool box_construct_element(xmlNode *n, struct content *content,
|
|
|
|
struct css_style *parent_style,
|
|
|
|
struct box *parent, struct box **inline_container,
|
2006-06-26 08:52:34 +04:00
|
|
|
struct box *containing_block,
|
2005-08-23 02:49:52 +04:00
|
|
|
char *href, const char *target, char *title);
|
2005-03-28 23:17:06 +04:00
|
|
|
bool box_construct_text(xmlNode *n, struct content *content,
|
|
|
|
struct css_style *parent_style,
|
|
|
|
struct box *parent, struct box **inline_container,
|
2005-08-23 02:49:52 +04:00
|
|
|
char *href, const char *target, char *title);
|
2005-03-28 23:17:06 +04:00
|
|
|
static struct css_style * box_get_style(struct content *c,
|
2005-03-26 04:12:27 +03:00
|
|
|
struct css_style *parent_style,
|
|
|
|
xmlNode *n);
|
2005-03-28 23:17:06 +04:00
|
|
|
static void box_solve_display(struct css_style *style, bool root);
|
2005-04-10 21:08:49 +04:00
|
|
|
static void box_set_cellpadding(struct box *box, int value);
|
2005-04-14 23:54:24 +04:00
|
|
|
static void box_set_table_border(struct box *box, int value, colour color);
|
2005-03-26 04:12:27 +03:00
|
|
|
static void box_text_transform(char *s, unsigned int len,
|
|
|
|
css_text_transform tt);
|
2005-04-09 13:47:37 +04:00
|
|
|
#define BOX_SPECIAL_PARAMS xmlNode *n, struct content *content, \
|
|
|
|
struct box *box, bool *convert_children
|
|
|
|
static bool box_a(BOX_SPECIAL_PARAMS);
|
|
|
|
static bool box_body(BOX_SPECIAL_PARAMS);
|
|
|
|
static bool box_br(BOX_SPECIAL_PARAMS);
|
|
|
|
static bool box_image(BOX_SPECIAL_PARAMS);
|
|
|
|
static bool box_form(BOX_SPECIAL_PARAMS);
|
|
|
|
static bool box_textarea(BOX_SPECIAL_PARAMS);
|
|
|
|
static bool box_select(BOX_SPECIAL_PARAMS);
|
|
|
|
static bool box_input(BOX_SPECIAL_PARAMS);
|
|
|
|
static bool box_input_text(BOX_SPECIAL_PARAMS, bool password);
|
|
|
|
static bool box_button(BOX_SPECIAL_PARAMS);
|
|
|
|
static bool box_frameset(BOX_SPECIAL_PARAMS);
|
2005-03-26 04:12:27 +03:00
|
|
|
static bool box_select_add_option(struct form_control *control, xmlNode *n);
|
2005-04-09 13:47:37 +04:00
|
|
|
static bool box_object(BOX_SPECIAL_PARAMS);
|
|
|
|
static bool box_embed(BOX_SPECIAL_PARAMS);
|
2006-04-04 14:56:21 +04:00
|
|
|
static bool box_pre(BOX_SPECIAL_PARAMS);
|
2005-04-10 02:56:34 +04:00
|
|
|
/*static bool box_applet(BOX_SPECIAL_PARAMS);*/
|
2005-04-09 13:47:37 +04:00
|
|
|
static bool box_iframe(BOX_SPECIAL_PARAMS);
|
2005-04-10 21:08:49 +04:00
|
|
|
static bool box_get_attribute(xmlNode *n, const char *attribute,
|
|
|
|
void *context, char **value);
|
2005-03-26 04:12:27 +03:00
|
|
|
static struct box_multi_length *box_parse_multi_lengths(const char *s,
|
2005-04-09 13:47:37 +04:00
|
|
|
unsigned int *count, void *context);
|
2005-03-26 04:12:27 +03:00
|
|
|
|
|
|
|
|
|
|
|
/* element_table must be sorted by name */
|
|
|
|
struct element_entry {
|
|
|
|
char name[10]; /* element type */
|
2005-04-09 13:47:37 +04:00
|
|
|
bool (*convert)(BOX_SPECIAL_PARAMS);
|
2005-03-26 04:12:27 +03:00
|
|
|
};
|
|
|
|
static const struct element_entry element_table[] = {
|
|
|
|
{"a", box_a},
|
|
|
|
/* {"applet", box_applet},*/
|
|
|
|
{"body", box_body},
|
|
|
|
{"br", box_br},
|
|
|
|
{"button", box_button},
|
|
|
|
{"embed", box_embed},
|
|
|
|
{"form", box_form},
|
|
|
|
{"frameset", box_frameset},
|
|
|
|
{"iframe", box_iframe},
|
|
|
|
{"img", box_image},
|
|
|
|
{"input", box_input},
|
|
|
|
{"object", box_object},
|
2006-04-04 14:56:21 +04:00
|
|
|
{"pre", box_pre},
|
2005-03-26 04:12:27 +03:00
|
|
|
{"select", box_select},
|
|
|
|
{"textarea", box_textarea}
|
|
|
|
};
|
|
|
|
#define ELEMENT_TABLE_COUNT (sizeof(element_table) / sizeof(element_table[0]))
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool xml_to_box(xmlNode *n, struct content *c)
|
|
|
|
{
|
|
|
|
struct box root;
|
|
|
|
struct box *inline_container = 0;
|
|
|
|
|
|
|
|
assert(c->type == CONTENT_HTML);
|
|
|
|
|
|
|
|
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;
|
2006-06-26 08:52:34 +04:00
|
|
|
root.absolute_children = NULL;
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
c->data.html.style = talloc_memdup(c, &css_base_style,
|
|
|
|
sizeof css_base_style);
|
2005-03-26 04:12:27 +03:00
|
|
|
if (!c->data.html.style)
|
|
|
|
return false;
|
|
|
|
c->data.html.style->font_size.value.length.value =
|
|
|
|
option_font_size * 0.1;
|
2006-01-03 02:31:29 +03:00
|
|
|
/* and get the default font family from the options */
|
|
|
|
c->data.html.style->font_family = option_font_default;
|
2005-03-26 04:12:27 +03:00
|
|
|
|
|
|
|
c->data.html.object_count = 0;
|
|
|
|
c->data.html.object = 0;
|
|
|
|
|
|
|
|
if (!convert_xml_to_box(n, c, c->data.html.style, &root,
|
2006-06-26 08:52:34 +04:00
|
|
|
&inline_container, 0, 0, 0, 0))
|
2005-03-26 04:12:27 +03:00
|
|
|
return false;
|
2006-03-27 05:04:56 +04:00
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
if (!box_normalise_block(&root, c))
|
2005-03-26 04:12:27 +03:00
|
|
|
return false;
|
|
|
|
|
|
|
|
c->data.html.layout = root.children;
|
|
|
|
c->data.html.layout->parent = NULL;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* mapping from CSS display to box type
|
|
|
|
* this table must be in sync with css/css_enums */
|
|
|
|
static const box_type box_map[] = {
|
|
|
|
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,*/
|
|
|
|
BOX_INLINE_BLOCK, /*CSS_DISPLAY_INLINE_BLOCK,*/
|
|
|
|
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,*/
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
2006-06-26 08:52:34 +04:00
|
|
|
* \param containing_block current containing block for absolutes, as defined
|
|
|
|
* by CSS 2.1 10.1 4
|
2005-08-23 02:49:52 +04:00
|
|
|
* \param href current link URL, or 0 if not in a link
|
|
|
|
* \param target current link target, or 0 if none
|
|
|
|
* \param title current title, or 0 if none
|
2005-03-26 04:12:27 +03:00
|
|
|
* \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,
|
2006-06-26 08:52:34 +04:00
|
|
|
struct box *containing_block,
|
2005-08-23 02:49:52 +04:00
|
|
|
char *href, const char *target, char *title)
|
2005-03-28 23:17:06 +04:00
|
|
|
{
|
|
|
|
switch (n->type) {
|
|
|
|
case XML_ELEMENT_NODE:
|
|
|
|
return box_construct_element(n, content, parent_style, parent,
|
2006-06-26 08:52:34 +04:00
|
|
|
inline_container, containing_block,
|
|
|
|
href, target, title);
|
2005-03-28 23:17:06 +04:00
|
|
|
case XML_TEXT_NODE:
|
|
|
|
return box_construct_text(n, content, parent_style, parent,
|
2005-08-23 02:49:52 +04:00
|
|
|
inline_container, href, target, title);
|
2005-03-28 23:17:06 +04:00
|
|
|
default:
|
|
|
|
/* not an element or text node: ignore it (eg. comment) */
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Construct the box tree for an XML element.
|
|
|
|
*
|
|
|
|
* \param n XML node of type XML_ELEMENT_NODE
|
|
|
|
* \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
|
2006-06-26 08:52:34 +04:00
|
|
|
* \param containing_block current containing block for absolutes, as defined
|
|
|
|
* by CSS 2.1 10.1 4
|
2005-08-23 02:49:52 +04:00
|
|
|
* \param href current link URL, or 0 if not in a link
|
|
|
|
* \param target current link target, or 0 if none
|
|
|
|
* \param title current title, or 0 if none
|
2005-03-28 23:17:06 +04:00
|
|
|
* \return true on success, false on memory exhaustion
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool box_construct_element(xmlNode *n, struct content *content,
|
|
|
|
struct css_style *parent_style,
|
|
|
|
struct box *parent, struct box **inline_container,
|
2006-06-26 08:52:34 +04:00
|
|
|
struct box *containing_block,
|
2005-08-23 02:49:52 +04:00
|
|
|
char *href, const char *target, char *title)
|
2005-03-26 04:12:27 +03:00
|
|
|
{
|
2005-04-09 13:47:37 +04:00
|
|
|
bool convert_children = true;
|
|
|
|
char *id = 0;
|
|
|
|
char *s;
|
2005-03-26 04:12:27 +03:00
|
|
|
struct box *box = 0;
|
|
|
|
struct box *inline_container_c;
|
2006-06-26 08:52:34 +04:00
|
|
|
struct box *containing_block_c;
|
2005-06-06 00:54:37 +04:00
|
|
|
struct box *inline_end;
|
2005-03-26 04:12:27 +03:00
|
|
|
struct css_style *style = 0;
|
2005-03-28 23:17:06 +04:00
|
|
|
struct element_entry *element;
|
2005-04-14 23:54:24 +04:00
|
|
|
colour border_color;
|
2005-04-10 21:08:49 +04:00
|
|
|
xmlChar *title0;
|
2005-04-09 13:47:37 +04:00
|
|
|
xmlNode *c;
|
2005-03-26 04:12:27 +03:00
|
|
|
|
|
|
|
assert(n);
|
2005-03-28 23:17:06 +04:00
|
|
|
assert(n->type == XML_ELEMENT_NODE);
|
2005-03-26 04:12:27 +03:00
|
|
|
assert(parent_style);
|
|
|
|
assert(parent);
|
|
|
|
assert(inline_container);
|
|
|
|
|
2005-03-28 23:17:06 +04:00
|
|
|
gui_multitask();
|
2006-04-04 14:56:21 +04:00
|
|
|
|
|
|
|
/* In case the parent is a pre block, we clear the
|
|
|
|
* strip_leading_newline flag since it is not used if we
|
|
|
|
* follow the pre with a tag
|
|
|
|
*/
|
|
|
|
parent->strip_leading_newline = 0;
|
|
|
|
|
2005-03-28 23:17:06 +04:00
|
|
|
style = box_get_style(content, parent_style, n);
|
|
|
|
if (!style)
|
2005-04-09 13:47:37 +04:00
|
|
|
return false;
|
2005-03-28 23:17:06 +04:00
|
|
|
if (style->display == CSS_DISPLAY_NONE) {
|
2005-04-09 13:47:37 +04:00
|
|
|
talloc_free(style);
|
|
|
|
return true;
|
2005-03-28 23:17:06 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* extract title attribute, if present */
|
|
|
|
if ((title0 = xmlGetProp(n, (const xmlChar *) "title"))) {
|
2005-04-09 13:47:37 +04:00
|
|
|
char *title1 = squash_whitespace(title0);
|
2005-03-28 23:17:06 +04:00
|
|
|
xmlFree(title0);
|
2005-04-09 13:47:37 +04:00
|
|
|
if (!title1)
|
|
|
|
return false;
|
|
|
|
title = talloc_strdup(content, title1);
|
|
|
|
free(title1);
|
2005-03-28 23:17:06 +04:00
|
|
|
if (!title)
|
2005-04-09 13:47:37 +04:00
|
|
|
return false;
|
2005-03-28 23:17:06 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* extract id attribute, if present */
|
2005-04-10 21:08:49 +04:00
|
|
|
if (!box_get_attribute(n, "id", content, &id))
|
|
|
|
return false;
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
/* create box for this element */
|
2005-08-23 02:49:52 +04:00
|
|
|
box = box_create(style, href, target, title, id, content);
|
2005-04-09 13:47:37 +04:00
|
|
|
if (!box)
|
|
|
|
return false;
|
|
|
|
/* set box type from style */
|
|
|
|
box->type = box_map[style->display];
|
|
|
|
|
2005-03-28 23:17:06 +04:00
|
|
|
/* special elements */
|
|
|
|
element = bsearch((const char *) n->name, element_table,
|
|
|
|
ELEMENT_TABLE_COUNT, sizeof(element_table[0]),
|
|
|
|
(int (*)(const void *, const void *)) strcmp);
|
|
|
|
if (element) {
|
|
|
|
/* a special convert function exists for this element */
|
2005-04-09 13:47:37 +04:00
|
|
|
if (!element->convert(n, content, box, &convert_children))
|
|
|
|
return false;
|
|
|
|
href = box->href;
|
2005-08-23 02:49:52 +04:00
|
|
|
target = box->target;
|
2005-03-28 23:17:06 +04:00
|
|
|
}
|
2005-07-03 00:08:24 +04:00
|
|
|
if (style->display == CSS_DISPLAY_NONE) {
|
|
|
|
talloc_free(style);
|
|
|
|
box_free_box(box);
|
|
|
|
return true;
|
|
|
|
}
|
2005-03-28 23:17:06 +04:00
|
|
|
|
2006-06-26 08:52:34 +04:00
|
|
|
/* determine if this is a new containing block */
|
|
|
|
if (style->position == CSS_POSITION_ABSOLUTE ||
|
|
|
|
style->position == CSS_POSITION_RELATIVE ||
|
|
|
|
style->position == CSS_POSITION_FIXED ||
|
|
|
|
!containing_block)
|
|
|
|
containing_block_c = box;
|
|
|
|
else
|
|
|
|
containing_block_c = containing_block;
|
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
if (!*inline_container &&
|
|
|
|
(box->type == BOX_INLINE ||
|
|
|
|
box->type == BOX_BR ||
|
2005-03-28 23:17:06 +04:00
|
|
|
box->type == BOX_INLINE_BLOCK ||
|
|
|
|
style->float_ == CSS_FLOAT_LEFT ||
|
2005-04-09 13:47:37 +04:00
|
|
|
style->float_ == CSS_FLOAT_RIGHT)) {
|
|
|
|
/* this is the first inline in a block: make a container */
|
2005-08-23 02:49:52 +04:00
|
|
|
*inline_container = box_create(0, 0, 0, 0, 0, content);
|
2005-04-09 13:47:37 +04:00
|
|
|
if (!*inline_container)
|
|
|
|
return false;
|
|
|
|
(*inline_container)->type = BOX_INLINE_CONTAINER;
|
|
|
|
box_add_child(parent, *inline_container);
|
|
|
|
}
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
if (box->type == BOX_INLINE || box->type == BOX_BR) {
|
|
|
|
/* inline box: add to tree and recurse */
|
|
|
|
box_add_child(*inline_container, box);
|
2005-06-08 02:52:56 +04:00
|
|
|
if (convert_children && n->children) {
|
2005-06-06 00:54:37 +04:00
|
|
|
for (c = n->children; c; c = c->next)
|
|
|
|
if (!convert_xml_to_box(c, content, style,
|
|
|
|
parent, inline_container,
|
2006-06-26 08:52:34 +04:00
|
|
|
containing_block_c,
|
2005-08-23 02:49:52 +04:00
|
|
|
href, target, title))
|
2005-06-06 00:54:37 +04:00
|
|
|
return false;
|
2005-08-23 02:49:52 +04:00
|
|
|
inline_end = box_create(style, href, target, title, id,
|
2005-06-06 00:54:37 +04:00
|
|
|
content);
|
|
|
|
if (!inline_end)
|
2005-04-09 13:47:37 +04:00
|
|
|
return false;
|
2005-06-06 00:54:37 +04:00
|
|
|
inline_end->type = BOX_INLINE_END;
|
|
|
|
if (*inline_container)
|
|
|
|
box_add_child(*inline_container, inline_end);
|
|
|
|
else
|
|
|
|
box_add_child(box->parent, inline_end);
|
|
|
|
box->inline_end = inline_end;
|
|
|
|
inline_end->inline_end = box;
|
|
|
|
}
|
2005-04-09 13:47:37 +04:00
|
|
|
} else if (box->type == BOX_INLINE_BLOCK) {
|
|
|
|
/* inline block box: add to tree and recurse */
|
|
|
|
box_add_child(*inline_container, box);
|
|
|
|
inline_container_c = 0;
|
|
|
|
for (c = n->children; convert_children && c; c = c->next)
|
|
|
|
if (!convert_xml_to_box(c, content, style, box,
|
2005-08-23 02:49:52 +04:00
|
|
|
&inline_container_c,
|
2006-06-26 08:52:34 +04:00
|
|
|
containing_block_c,
|
|
|
|
href, target, title))
|
|
|
|
return false;
|
|
|
|
} else if ((style->position == CSS_POSITION_ABSOLUTE ||
|
|
|
|
style->position == CSS_POSITION_FIXED) &&
|
|
|
|
containing_block) {
|
|
|
|
/* absolutely positioned */
|
|
|
|
box_add_absolute_child(containing_block, box);
|
|
|
|
inline_container_c = 0;
|
|
|
|
for (c = n->children; convert_children && c; c = c->next)
|
|
|
|
if (!convert_xml_to_box(c, content, style, box,
|
|
|
|
&inline_container_c,
|
|
|
|
containing_block_c,
|
2005-08-23 02:49:52 +04:00
|
|
|
href, target, title))
|
2005-04-09 13:47:37 +04:00
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
if (style->float_ == CSS_FLOAT_LEFT ||
|
|
|
|
style->float_ == CSS_FLOAT_RIGHT) {
|
2005-03-28 23:17:06 +04:00
|
|
|
/* float: insert a float box between the parent and
|
|
|
|
* current node */
|
2005-08-23 02:49:52 +04:00
|
|
|
parent = box_create(0, href, target, title, 0, content);
|
2005-03-28 23:17:06 +04:00
|
|
|
if (!parent)
|
2005-04-09 13:47:37 +04:00
|
|
|
return false;
|
2005-03-28 23:17:06 +04:00
|
|
|
if (style->float_ == CSS_FLOAT_LEFT)
|
|
|
|
parent->type = BOX_FLOAT_LEFT;
|
|
|
|
else
|
|
|
|
parent->type = BOX_FLOAT_RIGHT;
|
|
|
|
box_add_child(*inline_container, parent);
|
2005-03-26 04:12:27 +03:00
|
|
|
}
|
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
/* non-inline box: add to tree and recurse */
|
|
|
|
box_add_child(parent, box);
|
2005-03-28 23:17:06 +04:00
|
|
|
inline_container_c = 0;
|
2005-04-09 13:47:37 +04:00
|
|
|
for (c = n->children; convert_children && c; c = c->next)
|
|
|
|
if (!convert_xml_to_box(c, content, style, box,
|
2005-08-23 02:49:52 +04:00
|
|
|
&inline_container_c,
|
2006-06-26 08:52:34 +04:00
|
|
|
containing_block_c,
|
2005-08-23 02:49:52 +04:00
|
|
|
href, target, title))
|
2005-04-09 13:47:37 +04:00
|
|
|
return false;
|
|
|
|
if (style->float_ == CSS_FLOAT_NONE)
|
|
|
|
/* new inline container unless this is a float */
|
|
|
|
*inline_container = 0;
|
2005-03-28 23:17:06 +04:00
|
|
|
}
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
/* misc. attributes that can't be handled in box_get_style() */
|
|
|
|
if ((s = (char *) xmlGetProp(n, (const xmlChar *) "colspan"))) {
|
2005-03-28 23:17:06 +04:00
|
|
|
box->columns = strtol(s, NULL, 10);
|
|
|
|
if (MAX_SPAN < box->columns)
|
|
|
|
box->columns = 1;
|
|
|
|
xmlFree(s);
|
|
|
|
}
|
2005-04-09 13:47:37 +04:00
|
|
|
if ((s = (char *) xmlGetProp(n, (const xmlChar *) "rowspan"))) {
|
2005-03-28 23:17:06 +04:00
|
|
|
box->rows = strtol(s, NULL, 10);
|
|
|
|
if (MAX_SPAN < box->rows)
|
|
|
|
box->rows = 1;
|
|
|
|
xmlFree(s);
|
2005-03-26 04:12:27 +03:00
|
|
|
}
|
2005-04-14 23:54:24 +04:00
|
|
|
if (strcmp((const char *) n->name, "table") == 0) {
|
|
|
|
border_color = 0x888888; /* default colour */
|
|
|
|
if ((s = (char *) xmlGetProp(n,
|
|
|
|
(const xmlChar *) "cellpadding"))) {
|
2005-04-27 23:13:30 +04:00
|
|
|
char *endp;
|
|
|
|
long value = strtol(s, &endp, 10);
|
|
|
|
if (*endp == 0 && 0 <= value && value < 1000)
|
|
|
|
/* % not implemented */
|
2005-04-14 23:54:24 +04:00
|
|
|
box_set_cellpadding(box, value);
|
|
|
|
xmlFree(s);
|
|
|
|
}
|
|
|
|
if ((s = (char *) xmlGetProp(n,
|
|
|
|
(const xmlChar *) "bordercolor"))) {
|
|
|
|
unsigned int r, g, b;
|
|
|
|
if (s[0] == '#' && sscanf(s + 1, "%2x%2x%2x", &r, &g, &b) == 3)
|
|
|
|
border_color = (b << 16) | (g << 8) | r;
|
|
|
|
else if (s[0] != '#')
|
|
|
|
border_color = named_colour(s);
|
|
|
|
xmlFree(s);
|
|
|
|
}
|
|
|
|
if ((s = (char *) xmlGetProp(n,
|
|
|
|
(const xmlChar *) "border"))) {
|
|
|
|
int value = atoi(s);
|
|
|
|
if (!strrchr(s, '%') && 0 < value) /* % not implemented */
|
|
|
|
box_set_table_border(box, value, border_color);
|
|
|
|
xmlFree(s);
|
|
|
|
}
|
2005-04-09 13:47:37 +04:00
|
|
|
}
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2005-04-29 05:33:50 +04:00
|
|
|
/* transfer <tr height="n"> down to the <td> elements */
|
|
|
|
if (strcmp((const char *) n->name, "tr") == 0) {
|
|
|
|
if ((s = (char *) xmlGetProp(n,
|
|
|
|
(const xmlChar *) "height"))) {
|
|
|
|
float value = atof(s);
|
|
|
|
if (value < 0 || strlen(s) == 0) {
|
|
|
|
/* ignore negative values and height="" */
|
|
|
|
} else if (strrchr(s, '%')) {
|
|
|
|
/* the specification doesn't make clear what
|
|
|
|
* percentage heights mean, so ignore them */
|
|
|
|
} else {
|
|
|
|
/* The tree is not normalized yet, so accept cells not
|
|
|
|
* in rows and rows not in row groups. */
|
|
|
|
struct box *child;
|
|
|
|
float current;
|
|
|
|
for (child = box->children; child; child = child->next) {
|
|
|
|
if (child->type == BOX_TABLE_CELL) {
|
|
|
|
current = css_len2px(
|
|
|
|
&child->style->height.length,
|
|
|
|
child->style);
|
|
|
|
value = (value > current) ?
|
|
|
|
value : current;
|
|
|
|
child->style->height.height =
|
|
|
|
CSS_HEIGHT_LENGTH;
|
|
|
|
child->style->height.length.unit =
|
|
|
|
CSS_UNIT_PX;
|
|
|
|
child->style->height.length.value =
|
|
|
|
value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
xmlFree(s);
|
|
|
|
}
|
|
|
|
}
|
2005-05-22 03:30:19 +04:00
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
/* fetch any background image for this box */
|
|
|
|
if (style->background_image.type == CSS_BACKGROUND_IMAGE_URI) {
|
|
|
|
if (!html_fetch_object(content, style->background_image.uri,
|
|
|
|
box, image_types, content->available_width,
|
2005-08-21 02:52:20 +04:00
|
|
|
1000, true, 0))
|
2005-03-28 23:17:06 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Construct the box tree for an XML text node.
|
|
|
|
*
|
|
|
|
* \param n XML node of type XML_TEXT_NODE
|
|
|
|
* \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
|
2005-08-23 02:49:52 +04:00
|
|
|
* \param href current link URL, or 0 if not in a link
|
|
|
|
* \param target current link target, or 0 if none
|
|
|
|
* \param title current title, or 0 if none
|
2005-03-28 23:17:06 +04:00
|
|
|
* \return true on success, false on memory exhaustion
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool box_construct_text(xmlNode *n, struct content *content,
|
|
|
|
struct css_style *parent_style,
|
|
|
|
struct box *parent, struct box **inline_container,
|
2005-08-23 02:49:52 +04:00
|
|
|
char *href, const char *target, char *title)
|
2005-03-28 23:17:06 +04:00
|
|
|
{
|
|
|
|
struct box *box = 0;
|
|
|
|
|
|
|
|
assert(n);
|
|
|
|
assert(n->type == XML_TEXT_NODE);
|
|
|
|
assert(parent_style);
|
|
|
|
assert(parent);
|
|
|
|
assert(inline_container);
|
|
|
|
|
|
|
|
if (parent_style->white_space == CSS_WHITE_SPACE_NORMAL ||
|
|
|
|
parent_style->white_space == CSS_WHITE_SPACE_NOWRAP) {
|
2005-03-26 04:12:27 +03:00
|
|
|
char *text = squash_whitespace(n->content);
|
|
|
|
if (!text)
|
2005-04-09 13:47:37 +04:00
|
|
|
return false;
|
2005-03-26 04:12:27 +03:00
|
|
|
|
|
|
|
/* if the text is just a space, combine it with the preceding
|
|
|
|
* text node, if any */
|
|
|
|
if (text[0] == ' ' && text[1] == 0) {
|
|
|
|
if (*inline_container) {
|
|
|
|
assert((*inline_container)->last != 0);
|
|
|
|
(*inline_container)->last->space = 1;
|
|
|
|
}
|
|
|
|
free(text);
|
2005-04-09 13:47:37 +04:00
|
|
|
return true;
|
2005-03-26 04:12:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!*inline_container) {
|
|
|
|
/* this is the first inline node: make a container */
|
2005-08-23 02:49:52 +04:00
|
|
|
*inline_container = box_create(0, 0, 0, 0, 0, content);
|
2005-04-25 01:49:28 +04:00
|
|
|
if (!*inline_container) {
|
2005-03-26 04:12:27 +03:00
|
|
|
free(text);
|
2005-04-09 13:47:37 +04:00
|
|
|
return false;
|
2005-03-26 04:12:27 +03:00
|
|
|
}
|
|
|
|
(*inline_container)->type = BOX_INLINE_CONTAINER;
|
|
|
|
box_add_child(parent, *inline_container);
|
|
|
|
}
|
|
|
|
|
2005-08-23 02:49:52 +04:00
|
|
|
box = box_create(parent_style, href, target, title, 0, content);
|
2005-03-26 04:12:27 +03:00
|
|
|
if (!box) {
|
|
|
|
free(text);
|
2005-04-09 13:47:37 +04:00
|
|
|
return false;
|
2005-03-26 04:12:27 +03:00
|
|
|
}
|
2005-05-23 01:50:14 +04:00
|
|
|
box->type = BOX_TEXT;
|
2005-04-09 13:47:37 +04:00
|
|
|
box->text = talloc_strdup(content, text);
|
|
|
|
free(text);
|
|
|
|
if (!box->text)
|
|
|
|
return false;
|
|
|
|
box->length = strlen(box->text);
|
2005-03-26 04:12:27 +03:00
|
|
|
/* strip ending space char off */
|
2005-04-25 01:49:28 +04:00
|
|
|
if (box->length > 1 && box->text[box->length - 1] == ' ') {
|
2005-03-26 04:12:27 +03:00
|
|
|
box->space = 1;
|
|
|
|
box->length--;
|
|
|
|
}
|
|
|
|
if (parent_style->text_transform != CSS_TEXT_TRANSFORM_NONE)
|
|
|
|
box_text_transform(box->text, box->length,
|
|
|
|
parent_style->text_transform);
|
|
|
|
if (parent_style->white_space == CSS_WHITE_SPACE_NOWRAP) {
|
|
|
|
unsigned int i;
|
2005-04-25 01:49:28 +04:00
|
|
|
for (i = 0; i != box->length &&
|
|
|
|
box->text[i] != ' '; ++i)
|
2005-03-26 04:12:27 +03:00
|
|
|
; /* no body */
|
|
|
|
if (i != box->length) {
|
|
|
|
/* there is a space in text block and we
|
|
|
|
* want all spaces to be converted to NBSP
|
|
|
|
*/
|
2005-04-09 13:47:37 +04:00
|
|
|
/*box->text = cnv_space2nbsp(text);
|
2005-03-26 04:12:27 +03:00
|
|
|
if (!box->text) {
|
|
|
|
free(text);
|
|
|
|
goto no_memory;
|
|
|
|
}
|
2005-04-09 13:47:37 +04:00
|
|
|
box->length = strlen(box->text);*/
|
2005-03-26 04:12:27 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
box_add_child(*inline_container, box);
|
|
|
|
if (box->text[0] == ' ') {
|
|
|
|
box->length--;
|
|
|
|
memmove(box->text, &box->text[1], box->length);
|
|
|
|
if (box->prev != NULL)
|
|
|
|
box->prev->space = 1;
|
|
|
|
}
|
|
|
|
|
2005-03-28 23:17:06 +04:00
|
|
|
} else {
|
2005-03-26 04:12:27 +03:00
|
|
|
/* white-space: pre */
|
|
|
|
char *text = cnv_space2nbsp(n->content);
|
|
|
|
char *current;
|
|
|
|
/* note: pre-wrap/pre-line are unimplemented */
|
|
|
|
assert(parent_style->white_space == CSS_WHITE_SPACE_PRE ||
|
|
|
|
parent_style->white_space ==
|
|
|
|
CSS_WHITE_SPACE_PRE_LINE ||
|
|
|
|
parent_style->white_space ==
|
|
|
|
CSS_WHITE_SPACE_PRE_WRAP);
|
|
|
|
if (!text)
|
2005-04-09 13:47:37 +04:00
|
|
|
return false;
|
2005-03-26 04:12:27 +03:00
|
|
|
if (parent_style->text_transform != CSS_TEXT_TRANSFORM_NONE)
|
|
|
|
box_text_transform(text, strlen(text),
|
|
|
|
parent_style->text_transform);
|
|
|
|
current = text;
|
2006-03-27 03:52:22 +04:00
|
|
|
|
|
|
|
/* swallow a single leading new line */
|
2006-04-04 14:56:21 +04:00
|
|
|
if (parent->strip_leading_newline) {
|
|
|
|
switch (*current) {
|
|
|
|
case '\n':
|
|
|
|
current++; break;
|
|
|
|
case '\r':
|
|
|
|
current++;
|
|
|
|
if (*current == '\n') current++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
parent->strip_leading_newline = 0;
|
2006-03-27 03:52:22 +04:00
|
|
|
}
|
|
|
|
|
2005-03-26 04:12:27 +03:00
|
|
|
do {
|
|
|
|
size_t len = strcspn(current, "\r\n");
|
|
|
|
char old = current[len];
|
|
|
|
current[len] = 0;
|
|
|
|
if (!*inline_container) {
|
2005-08-23 02:49:52 +04:00
|
|
|
*inline_container = box_create(0, 0, 0, 0, 0,
|
2005-04-09 13:47:37 +04:00
|
|
|
content);
|
2005-03-26 04:12:27 +03:00
|
|
|
if (!*inline_container) {
|
|
|
|
free(text);
|
2005-04-09 13:47:37 +04:00
|
|
|
return false;
|
2005-03-26 04:12:27 +03:00
|
|
|
}
|
|
|
|
(*inline_container)->type =
|
|
|
|
BOX_INLINE_CONTAINER;
|
|
|
|
box_add_child(parent, *inline_container);
|
|
|
|
}
|
2005-08-23 02:49:52 +04:00
|
|
|
box = box_create(parent_style, href, target, title, 0,
|
|
|
|
content);
|
2005-03-26 04:12:27 +03:00
|
|
|
if (!box) {
|
|
|
|
free(text);
|
2005-04-09 13:47:37 +04:00
|
|
|
return false;
|
2005-03-26 04:12:27 +03:00
|
|
|
}
|
2005-05-23 01:50:14 +04:00
|
|
|
box->type = BOX_TEXT;
|
2005-04-09 13:47:37 +04:00
|
|
|
box->text = talloc_strdup(content, current);
|
2005-03-26 04:12:27 +03:00
|
|
|
if (!box->text) {
|
|
|
|
free(text);
|
2005-04-09 13:47:37 +04:00
|
|
|
return false;
|
2005-03-26 04:12:27 +03:00
|
|
|
}
|
|
|
|
box->length = strlen(box->text);
|
|
|
|
box_add_child(*inline_container, box);
|
|
|
|
current[len] = old;
|
|
|
|
current += len;
|
|
|
|
if (current[0] == '\r' && current[1] == '\n') {
|
|
|
|
current += 2;
|
|
|
|
*inline_container = 0;
|
|
|
|
} else if (current[0] != 0) {
|
|
|
|
current++;
|
|
|
|
*inline_container = 0;
|
|
|
|
}
|
|
|
|
} while (*current);
|
|
|
|
free(text);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct css_style * box_get_style(struct content *c,
|
|
|
|
struct css_style *parent_style,
|
|
|
|
xmlNode *n)
|
|
|
|
{
|
|
|
|
char *s;
|
|
|
|
struct css_style *style;
|
|
|
|
struct css_style *style_new;
|
|
|
|
char *url;
|
|
|
|
url_func_result res;
|
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
style = talloc_memdup(c, parent_style, sizeof *style);
|
2005-03-26 04:12:27 +03:00
|
|
|
if (!style)
|
|
|
|
return 0;
|
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
style_new = talloc_memdup(c, &css_blank_style, sizeof *style_new);
|
|
|
|
if (!style_new)
|
2005-03-26 04:12:27 +03:00
|
|
|
return 0;
|
2005-05-22 03:30:19 +04:00
|
|
|
css_get_style(c->data.html.working_stylesheet, n, style_new);
|
2005-03-26 04:12:27 +03:00
|
|
|
css_cascade(style, style_new);
|
|
|
|
|
|
|
|
/* style_new isn't needed past this point */
|
2005-04-09 13:47:37 +04:00
|
|
|
talloc_free(style_new);
|
2005-03-26 04:12:27 +03:00
|
|
|
|
|
|
|
/* This property only applies to the body element, if you believe
|
|
|
|
* the spec. Many browsers seem to allow it on other elements too,
|
|
|
|
* so let's be generic ;) */
|
2005-04-29 05:33:50 +04:00
|
|
|
if (((s = (char *) xmlGetProp(n, (const xmlChar *) "background"))) &&
|
|
|
|
(style->background_image.type == CSS_BACKGROUND_IMAGE_NONE)) {
|
2005-03-26 04:12:27 +03:00
|
|
|
res = url_join(s, c->data.html.base_url, &url);
|
2005-04-09 13:47:37 +04:00
|
|
|
xmlFree(s);
|
2005-03-26 04:12:27 +03:00
|
|
|
if (res == URL_FUNC_NOMEM) {
|
|
|
|
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;
|
2005-04-09 13:47:37 +04:00
|
|
|
style->background_image.uri = talloc_strdup(
|
|
|
|
c, url);
|
|
|
|
free(url);
|
|
|
|
if (!style->background_image.uri)
|
|
|
|
return 0;
|
2005-03-26 04:12:27 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-05-22 03:30:19 +04:00
|
|
|
if (((s = (char *) xmlGetProp(n, (const xmlChar *) "bgcolor"))) &&
|
2005-04-29 05:33:50 +04:00
|
|
|
(style->background_color == TRANSPARENT)) {
|
2005-03-26 04:12:27 +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;
|
|
|
|
else if (s[0] != '#')
|
|
|
|
style->background_color = named_colour(s);
|
|
|
|
xmlFree(s);
|
|
|
|
}
|
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
if ((s = (char *) xmlGetProp(n, (const xmlChar *) "color"))) {
|
2005-03-26 04:12:27 +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;
|
|
|
|
else if (s[0] != '#')
|
|
|
|
style->color = named_colour(s);
|
|
|
|
xmlFree(s);
|
|
|
|
}
|
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
if ((s = (char *) xmlGetProp(n, (const xmlChar *) "height"))) {
|
2005-03-26 04:12:27 +03:00
|
|
|
float value = atof(s);
|
|
|
|
if (value < 0 || strlen(s) == 0) {
|
|
|
|
/* ignore negative values and height="" */
|
|
|
|
} else if (strrchr(s, '%')) {
|
|
|
|
/* the specification doesn't make clear what
|
|
|
|
* percentage heights mean, so ignore them */
|
|
|
|
} else {
|
|
|
|
style->height.height = CSS_HEIGHT_LENGTH;
|
|
|
|
style->height.length.unit = CSS_UNIT_PX;
|
|
|
|
style->height.length.value = value;
|
|
|
|
}
|
|
|
|
xmlFree(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strcmp((const char *) n->name, "input") == 0) {
|
2005-04-09 13:47:37 +04:00
|
|
|
if ((s = (char *) xmlGetProp(n, (const xmlChar *) "size"))) {
|
2005-03-26 04:12:27 +03:00
|
|
|
int size = atoi(s);
|
|
|
|
if (0 < size) {
|
2005-04-09 13:47:37 +04:00
|
|
|
char *type = (char *) xmlGetProp(n,
|
|
|
|
(const xmlChar *) "type");
|
2005-03-26 04:12:27 +03:00
|
|
|
style->width.width = CSS_WIDTH_LENGTH;
|
|
|
|
if (!type || strcasecmp(type, "text") == 0 ||
|
2005-04-09 13:47:37 +04:00
|
|
|
strcasecmp(type, "password") == 0)
|
|
|
|
/* in characters for text, password */
|
|
|
|
style->width.value.length.unit =
|
|
|
|
CSS_UNIT_EX;
|
2005-03-26 04:12:27 +03:00
|
|
|
else if (strcasecmp(type, "file") != 0)
|
2005-04-09 13:47:37 +04:00
|
|
|
/* in pixels otherwise; ignore width
|
|
|
|
* on file, because we do them
|
|
|
|
* differently to most browsers */
|
|
|
|
style->width.value.length.unit =
|
|
|
|
CSS_UNIT_PX;
|
2005-03-26 04:12:27 +03:00
|
|
|
style->width.value.length.value = size;
|
|
|
|
if (type)
|
|
|
|
xmlFree(type);
|
|
|
|
}
|
|
|
|
xmlFree(s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strcmp((const char *) n->name, "body") == 0) {
|
2005-04-09 13:47:37 +04:00
|
|
|
if ((s = (char *) xmlGetProp(n, (const xmlChar *) "text"))) {
|
2005-03-26 04:12:27 +03:00
|
|
|
unsigned int r, g, b;
|
2005-04-09 13:47:37 +04:00
|
|
|
if (s[0] == '#' && sscanf(s + 1, "%2x%2x%2x",
|
|
|
|
&r, &g, &b) == 3)
|
2005-03-26 04:12:27 +03:00
|
|
|
style->color = (b << 16) | (g << 8) | r;
|
|
|
|
else if (s[0] != '#')
|
|
|
|
style->color = named_colour(s);
|
|
|
|
xmlFree(s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
if ((s = (char *) xmlGetProp(n, (const xmlChar *) "width"))) {
|
2005-03-26 04:12:27 +03:00
|
|
|
float value = atof(s);
|
|
|
|
if (value < 0 || strlen(s) == 0) {
|
|
|
|
/* ignore negative values and width="" */
|
|
|
|
} else if (strrchr(s, '%')) {
|
|
|
|
style->width.width = CSS_WIDTH_PERCENT;
|
|
|
|
style->width.value.percent = value;
|
|
|
|
} else {
|
|
|
|
style->width.width = CSS_WIDTH_LENGTH;
|
|
|
|
style->width.value.length.unit = CSS_UNIT_PX;
|
|
|
|
style->width.value.length.value = value;
|
|
|
|
}
|
|
|
|
xmlFree(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strcmp((const char *) n->name, "textarea") == 0) {
|
2005-04-09 13:47:37 +04:00
|
|
|
if ((s = (char *) xmlGetProp(n, (const xmlChar *) "rows"))) {
|
2005-03-26 04:12:27 +03: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);
|
|
|
|
}
|
2005-04-09 13:47:37 +04:00
|
|
|
if ((s = (char *) xmlGetProp(n, (const xmlChar *) "cols"))) {
|
2005-03-26 04:12:27 +03: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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
if (0 <= value) {
|
|
|
|
style->border_spacing.border_spacing =
|
|
|
|
CSS_BORDER_SPACING_LENGTH;
|
|
|
|
style->border_spacing.horz.unit =
|
|
|
|
style->border_spacing.vert.unit =
|
|
|
|
CSS_UNIT_PX;
|
|
|
|
style->border_spacing.horz.value =
|
|
|
|
style->border_spacing.vert.value =
|
|
|
|
value;
|
|
|
|
}
|
|
|
|
}
|
2005-06-26 05:55:20 +04:00
|
|
|
xmlFree(s);
|
2005-03-26 04:12:27 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-28 05:17:52 +04:00
|
|
|
if ((strcmp((const char *) n->name, "img") == 0) ||
|
|
|
|
(strcmp((const char *) n->name, "applet") == 0)) {
|
|
|
|
if ((s = (char *) xmlGetProp(n,
|
|
|
|
(const xmlChar *) "hspace"))) {
|
|
|
|
if (!strrchr(s, '%')) { /* % not implemented */
|
|
|
|
int value = atoi(s);
|
|
|
|
if (0 <= value) {
|
|
|
|
style->margin[LEFT].margin =
|
|
|
|
CSS_MARGIN_LENGTH;
|
|
|
|
style->margin[LEFT].value.length.value =
|
|
|
|
value;
|
|
|
|
style->margin[LEFT].value.length.unit =
|
|
|
|
CSS_UNIT_PX;
|
|
|
|
style->margin[RIGHT].margin =
|
|
|
|
CSS_MARGIN_LENGTH;
|
|
|
|
style->margin[RIGHT].value.length.value =
|
|
|
|
value;
|
|
|
|
style->margin[RIGHT].value.length.unit =
|
|
|
|
CSS_UNIT_PX;
|
|
|
|
}
|
|
|
|
}
|
2005-06-26 05:55:20 +04:00
|
|
|
xmlFree(s);
|
2005-04-28 05:17:52 +04:00
|
|
|
}
|
|
|
|
if ((s = (char *) xmlGetProp(n,
|
|
|
|
(const xmlChar *) "vspace"))) {
|
|
|
|
if (!strrchr(s, '%')) { /* % not implemented */
|
|
|
|
int value = atoi(s);
|
|
|
|
if (0 <= value) {
|
|
|
|
style->margin[TOP].margin =
|
|
|
|
CSS_MARGIN_LENGTH;
|
|
|
|
style->margin[TOP].value.length.value =
|
|
|
|
value;
|
|
|
|
style->margin[TOP].value.length.unit =
|
|
|
|
CSS_UNIT_PX;
|
|
|
|
style->margin[BOTTOM].margin =
|
|
|
|
CSS_MARGIN_LENGTH;
|
|
|
|
style->margin[BOTTOM].value.length.value =
|
|
|
|
value;
|
|
|
|
style->margin[BOTTOM].value.length.unit =
|
|
|
|
CSS_UNIT_PX;
|
|
|
|
}
|
|
|
|
}
|
2005-06-26 05:55:20 +04:00
|
|
|
xmlFree(s);
|
2005-04-28 05:17:52 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
if ((s = (char *) xmlGetProp(n, (const xmlChar *) "style"))) {
|
2005-03-26 04:12:27 +03:00
|
|
|
struct css_style *astyle;
|
|
|
|
astyle = css_duplicate_style(&css_empty_style);
|
|
|
|
if (!astyle) {
|
|
|
|
xmlFree(s);
|
|
|
|
css_free_style(style);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
css_parse_property_list(c, astyle, s);
|
|
|
|
css_cascade(style, astyle);
|
|
|
|
css_free_style(astyle);
|
|
|
|
xmlFree(s);
|
|
|
|
}
|
|
|
|
|
2005-03-28 23:17:06 +04:00
|
|
|
box_solve_display(style, !n->parent);
|
|
|
|
|
2005-03-26 04:12:27 +03:00
|
|
|
return style;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-03-28 23:17:06 +04:00
|
|
|
/**
|
|
|
|
* Calculate 'display' based on 'display', 'position', and 'float', as given
|
|
|
|
* by CSS 2.1 9.7.
|
|
|
|
*
|
|
|
|
* \param style style to update
|
|
|
|
* \param root this is the root element
|
|
|
|
*/
|
|
|
|
|
|
|
|
void box_solve_display(struct css_style *style, bool root)
|
|
|
|
{
|
|
|
|
if (style->display == CSS_DISPLAY_NONE) /* 1. */
|
|
|
|
return;
|
|
|
|
else if (style->position == CSS_POSITION_ABSOLUTE ||
|
|
|
|
style->position == CSS_POSITION_FIXED) /* 2. */
|
|
|
|
style->float_ = CSS_FLOAT_NONE;
|
|
|
|
else if (style->float_ != CSS_FLOAT_NONE) /* 3. */
|
|
|
|
;
|
|
|
|
else if (root) /* 4. */
|
|
|
|
;
|
|
|
|
else /* 5. */
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* map specified value to computed value using table given in 9.7 */
|
|
|
|
if (style->display == CSS_DISPLAY_INLINE_TABLE)
|
|
|
|
style->display = CSS_DISPLAY_TABLE;
|
|
|
|
else if (style->display == CSS_DISPLAY_LIST_ITEM ||
|
|
|
|
style->display == CSS_DISPLAY_TABLE)
|
|
|
|
; /* same as specified */
|
|
|
|
else
|
|
|
|
style->display = CSS_DISPLAY_BLOCK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
/**
|
|
|
|
* Set the cellpadding on a table.
|
|
|
|
*
|
|
|
|
* \param box box to set cellpadding on
|
|
|
|
* \param value padding in pixels
|
|
|
|
*
|
|
|
|
* The descendants of the box are searched for table cells, and the padding is
|
|
|
|
* set on each one.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void box_set_cellpadding(struct box *box, int value)
|
|
|
|
{
|
|
|
|
/* The tree is not normalized yet, so accept cells not in rows and
|
|
|
|
* rows not in row groups. */
|
|
|
|
struct box *child;
|
|
|
|
for (child = box->children; child; child = child->next) {
|
|
|
|
switch (child->type) {
|
|
|
|
case BOX_TABLE_ROW_GROUP:
|
|
|
|
case BOX_TABLE_ROW:
|
|
|
|
box_set_cellpadding(child, value);
|
|
|
|
break;
|
|
|
|
case BOX_TABLE_CELL:
|
|
|
|
for (unsigned int i = 0; i != 4; i++) {
|
|
|
|
child->style->padding[i].padding =
|
|
|
|
CSS_PADDING_LENGTH;
|
|
|
|
child->style->padding[i].value.length.value =
|
|
|
|
value;
|
|
|
|
child->style->padding[i].value.length.unit =
|
|
|
|
CSS_UNIT_PX;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-04-14 23:54:24 +04:00
|
|
|
/**
|
|
|
|
* Set the borders on a table.
|
|
|
|
*
|
|
|
|
* \param box box to set cellpadding on
|
|
|
|
* \param value border in pixels
|
|
|
|
*
|
|
|
|
* The descendants of the box are searched for table cells, and the border is
|
|
|
|
* set on each one.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void box_set_table_border(struct box *box, int value, colour color)
|
|
|
|
{
|
|
|
|
struct box *child;
|
|
|
|
|
|
|
|
if (box->type == BOX_TABLE) {
|
|
|
|
for (unsigned int i = 0; i != 4; i++) {
|
2005-04-28 06:35:03 +04:00
|
|
|
if (box->style->border[i].style ==
|
2005-04-28 19:57:07 +04:00
|
|
|
CSS_BORDER_STYLE_NONE) {
|
2005-04-28 06:35:03 +04:00
|
|
|
box->style->border[i].color = color;
|
|
|
|
box->style->border[i].width.width =
|
|
|
|
CSS_BORDER_WIDTH_LENGTH;
|
|
|
|
box->style->border[i].width.value.value =
|
|
|
|
value;
|
|
|
|
box->style->border[i].width.value.unit =
|
|
|
|
CSS_UNIT_PX;
|
|
|
|
box->style->border[i].style =
|
|
|
|
CSS_BORDER_STYLE_OUTSET;
|
|
|
|
}
|
2005-04-14 23:54:24 +04:00
|
|
|
}
|
|
|
|
}
|
2005-04-15 03:17:37 +04:00
|
|
|
|
2005-04-14 23:54:24 +04:00
|
|
|
/* The tree is not normalized yet, so accept cells not in rows and
|
|
|
|
* rows not in row groups. */
|
|
|
|
for (child = box->children; child; child = child->next) {
|
|
|
|
switch (child->type) {
|
|
|
|
case BOX_TABLE_ROW_GROUP:
|
|
|
|
case BOX_TABLE_ROW:
|
|
|
|
box_set_table_border(child, value, color);
|
|
|
|
break;
|
|
|
|
case BOX_TABLE_CELL:
|
|
|
|
for (unsigned int i = 0; i != 4; i++) {
|
2005-04-28 06:35:03 +04:00
|
|
|
if (child->style->border[i].style ==
|
2005-04-28 19:57:07 +04:00
|
|
|
CSS_BORDER_STYLE_NONE) {
|
2005-04-28 06:35:03 +04:00
|
|
|
child->style->border[i].color = color;
|
|
|
|
child->style->border[i].width.width =
|
|
|
|
CSS_BORDER_WIDTH_LENGTH;
|
|
|
|
child->style->border[i].width.value.value =
|
|
|
|
1;
|
|
|
|
child->style->border[i].width.value.unit =
|
|
|
|
CSS_UNIT_PX;
|
|
|
|
child->style->border[i].style =
|
|
|
|
CSS_BORDER_STYLE_INSET;
|
|
|
|
}
|
2005-04-14 23:54:24 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-03-26 04:12:27 +03:00
|
|
|
/**
|
|
|
|
* Apply the CSS text-transform property to given text for its ASCII chars.
|
|
|
|
*
|
|
|
|
* \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:
|
|
|
|
for (i = 0; i < len; ++i)
|
|
|
|
if (s[i] < 0x80)
|
|
|
|
s[i] = toupper(s[i]);
|
|
|
|
break;
|
|
|
|
case CSS_TEXT_TRANSFORM_LOWERCASE:
|
|
|
|
for (i = 0; i < len; ++i)
|
|
|
|
if (s[i] < 0x80)
|
|
|
|
s[i] = tolower(s[i]);
|
|
|
|
break;
|
|
|
|
case CSS_TEXT_TRANSFORM_CAPITALIZE:
|
|
|
|
if (s[0] < 0x80)
|
|
|
|
s[0] = toupper(s[0]);
|
|
|
|
for (i = 1; i < len; ++i)
|
|
|
|
if (s[i] < 0x80 && isspace(s[i - 1]))
|
|
|
|
s[i] = toupper(s[i]);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
/**
|
|
|
|
* \name Special case element handlers
|
2005-03-26 04:12:27 +03:00
|
|
|
*
|
2005-04-10 21:08:49 +04:00
|
|
|
* These functions are called by box_construct_element() when an element is
|
|
|
|
* being converted, according to the entries in element_table.
|
2005-04-09 13:47:37 +04:00
|
|
|
*
|
|
|
|
* The parameters are the xmlNode, the content for the document, and a partly
|
|
|
|
* filled in box structure for the element.
|
2005-03-26 04:12:27 +03:00
|
|
|
*
|
2005-04-09 13:47:37 +04:00
|
|
|
* Return true on success, false on memory exhaustion. Set *convert_children
|
|
|
|
* to false if children of this element in the XML tree should be skipped (for
|
|
|
|
* example, if they have been processed in some special way already).
|
2005-03-26 04:12:27 +03:00
|
|
|
*
|
2005-04-09 13:47:37 +04:00
|
|
|
* Elements ordered as in the HTML 4.01 specification. Section numbers in
|
|
|
|
* brackets [] refer to the spec.
|
|
|
|
*
|
|
|
|
* \{
|
2005-03-26 04:12:27 +03:00
|
|
|
*/
|
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
/**
|
|
|
|
* Document body [7.5.1].
|
|
|
|
*/
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
bool box_body(BOX_SPECIAL_PARAMS)
|
|
|
|
{
|
|
|
|
content->data.html.background_colour = box->style->background_color;
|
|
|
|
return true;
|
|
|
|
}
|
2005-03-26 04:12:27 +03:00
|
|
|
|
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
/**
|
|
|
|
* Forced line break [9.3.2].
|
|
|
|
*/
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
bool box_br(BOX_SPECIAL_PARAMS)
|
|
|
|
{
|
|
|
|
box->type = BOX_BR;
|
|
|
|
return true;
|
|
|
|
}
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2006-04-04 14:56:21 +04:00
|
|
|
/**
|
|
|
|
* Preformatted text [9.3.4].
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool box_pre(BOX_SPECIAL_PARAMS)
|
|
|
|
{
|
|
|
|
box->strip_leading_newline = 1;
|
|
|
|
return true;
|
|
|
|
}
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
/**
|
|
|
|
* Anchor [12.2].
|
|
|
|
*/
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
bool box_a(BOX_SPECIAL_PARAMS)
|
2005-03-26 04:12:27 +03:00
|
|
|
{
|
2005-04-10 21:08:49 +04:00
|
|
|
bool ok;
|
|
|
|
char *url;
|
|
|
|
xmlChar *s;
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2005-04-10 21:08:49 +04:00
|
|
|
if ((s = xmlGetProp(n, (const xmlChar *) "href"))) {
|
|
|
|
ok = box_extract_link((const char *) s,
|
|
|
|
content->data.html.base_url, &url);
|
2005-04-09 13:47:37 +04:00
|
|
|
xmlFree(s);
|
2005-04-10 21:08:49 +04:00
|
|
|
if (!ok)
|
2005-04-09 13:47:37 +04:00
|
|
|
return false;
|
2005-04-10 21:08:49 +04:00
|
|
|
if (url) {
|
|
|
|
box->href = talloc_strdup(content, url);
|
2005-08-21 02:52:20 +04:00
|
|
|
free(url);
|
2005-04-10 21:08:49 +04:00
|
|
|
if (!box->href)
|
|
|
|
return false;
|
|
|
|
}
|
2005-04-09 13:47:37 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* name and id share the same namespace */
|
2005-04-10 21:08:49 +04:00
|
|
|
if (!box_get_attribute(n, "name", content, &box->id))
|
|
|
|
return false;
|
2005-04-09 13:47:37 +04:00
|
|
|
|
2005-08-21 02:52:20 +04:00
|
|
|
/* target frame [16.3] */
|
|
|
|
if ((s = xmlGetProp(n, (const xmlChar *) "target"))) {
|
|
|
|
if (!strcmp(s, "_blank") || !strcmp(s, "_top"))
|
|
|
|
box->target = TARGET_TOP;
|
|
|
|
else if (!strcmp(s, "_parent"))
|
|
|
|
box->target = TARGET_PARENT;
|
|
|
|
else if (!strcmp(s, "_self"))
|
|
|
|
/* the default may have been overridden by a
|
|
|
|
* <base target=...>, so this is different to 0 */
|
|
|
|
box->target = TARGET_SELF;
|
|
|
|
else if (('a' <= s[0] && s[0] <= 'z') ||
|
|
|
|
('A' <= s[0] && s[0] <= 'Z')) { /* [6.16] */
|
|
|
|
box->target = talloc_strdup(content, s);
|
|
|
|
if (!box->target) {
|
|
|
|
xmlFree(s);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
xmlFree(s);
|
|
|
|
}
|
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
return true;
|
2005-03-26 04:12:27 +03:00
|
|
|
}
|
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Embedded image [13.2].
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool box_image(BOX_SPECIAL_PARAMS)
|
2005-03-26 04:12:27 +03:00
|
|
|
{
|
2005-04-14 01:58:28 +04:00
|
|
|
bool ok;
|
|
|
|
char *s, *url;
|
|
|
|
xmlChar *alt, *src;
|
2005-03-26 04:12:27 +03:00
|
|
|
|
|
|
|
/* handle alt text */
|
2005-04-14 01:58:28 +04:00
|
|
|
if ((alt = xmlGetProp(n, (const xmlChar *) "alt"))) {
|
|
|
|
s = squash_whitespace(alt);
|
|
|
|
xmlFree(alt);
|
2005-04-09 13:47:37 +04:00
|
|
|
if (!s)
|
|
|
|
return false;
|
|
|
|
box->text = talloc_strdup(content, s);
|
|
|
|
free(s);
|
2005-03-26 04:12:27 +03:00
|
|
|
if (!box->text)
|
2005-04-09 13:47:37 +04:00
|
|
|
return false;
|
2005-03-26 04:12:27 +03:00
|
|
|
box->length = strlen(box->text);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* imagemap associated with this image */
|
2005-04-10 21:08:49 +04:00
|
|
|
if (!box_get_attribute(n, "usemap", content, &box->usemap))
|
|
|
|
return false;
|
|
|
|
if (box->usemap && box->usemap[0] == '#')
|
|
|
|
box->usemap++;
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2005-04-14 01:58:28 +04:00
|
|
|
/* get image URL */
|
|
|
|
if (!(src = xmlGetProp(n, (const xmlChar *) "src")))
|
2005-04-09 13:47:37 +04:00
|
|
|
return true;
|
2005-04-14 01:58:28 +04:00
|
|
|
if (!box_extract_link((char *) src, content->data.html.base_url, &url))
|
2005-04-09 13:47:37 +04:00
|
|
|
return false;
|
2005-04-14 01:58:28 +04:00
|
|
|
xmlFree(src);
|
|
|
|
if (!url)
|
2005-04-09 13:47:37 +04:00
|
|
|
return true;
|
2005-03-26 04:12:27 +03:00
|
|
|
|
|
|
|
/* start fetch */
|
2005-04-14 01:58:28 +04:00
|
|
|
ok = html_fetch_object(content, url, box, image_types,
|
2005-08-21 02:52:20 +04:00
|
|
|
content->available_width, 1000, false, 0);
|
2005-04-09 13:47:37 +04:00
|
|
|
free(url);
|
2005-04-14 01:58:28 +04:00
|
|
|
return ok;
|
2005-03-26 04:12:27 +03:00
|
|
|
}
|
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Generic embedded object [13.3].
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool box_object(BOX_SPECIAL_PARAMS)
|
2005-03-26 04:12:27 +03:00
|
|
|
{
|
2005-04-14 01:58:28 +04:00
|
|
|
struct object_params *params;
|
|
|
|
struct object_param *param;
|
|
|
|
xmlChar *codebase, *classid, *data;
|
2005-04-09 13:47:37 +04:00
|
|
|
xmlNode *c;
|
2005-04-14 01:58:28 +04:00
|
|
|
struct box *inline_container = 0;
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2005-04-10 21:08:49 +04:00
|
|
|
if (!box_get_attribute(n, "usemap", content, &box->usemap))
|
|
|
|
return false;
|
|
|
|
if (box->usemap && box->usemap[0] == '#')
|
|
|
|
box->usemap++;
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2005-04-14 01:58:28 +04:00
|
|
|
params = talloc(content, struct object_params);
|
|
|
|
if (!params)
|
2005-04-10 21:08:49 +04:00
|
|
|
return false;
|
2005-04-14 01:58:28 +04:00
|
|
|
params->data = 0;
|
|
|
|
params->type = 0;
|
|
|
|
params->codetype = 0;
|
|
|
|
params->codebase = 0;
|
|
|
|
params->classid = 0;
|
|
|
|
params->params = 0;
|
|
|
|
|
|
|
|
/* codebase, classid, and data are URLs (codebase is the base for the
|
|
|
|
* other two) */
|
|
|
|
if ((codebase = xmlGetProp(n, (const xmlChar *) "codebase"))) {
|
|
|
|
if (!box_extract_link((char *) codebase,
|
|
|
|
content->data.html.base_url, ¶ms->codebase))
|
|
|
|
return false;
|
|
|
|
xmlFree(codebase);
|
|
|
|
}
|
|
|
|
if (!params->codebase)
|
|
|
|
params->codebase = content->data.html.base_url;
|
|
|
|
|
|
|
|
if ((classid = xmlGetProp(n, (const xmlChar *) "codebase"))) {
|
|
|
|
if (!box_extract_link((char *) classid, params->codebase,
|
|
|
|
¶ms->classid))
|
|
|
|
return false;
|
|
|
|
xmlFree(classid);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((data = xmlGetProp(n, (const xmlChar *) "data"))) {
|
|
|
|
if (!box_extract_link((char *) data, params->codebase,
|
|
|
|
¶ms->data))
|
|
|
|
return false;
|
|
|
|
xmlFree(data);
|
|
|
|
}
|
|
|
|
if (!params->data)
|
|
|
|
/* objects without data are ignored */
|
|
|
|
return true;
|
|
|
|
|
2006-03-27 05:04:56 +04:00
|
|
|
/* Don't include ourself */
|
|
|
|
if (strcmp(content->data.html.base_url, params->data) == 0)
|
|
|
|
return true;
|
|
|
|
|
2005-04-14 01:58:28 +04:00
|
|
|
/* codetype and type are MIME types */
|
|
|
|
if (!box_get_attribute(n, "codetype", params, ¶ms->codetype))
|
2005-04-10 21:08:49 +04:00
|
|
|
return false;
|
2005-04-14 01:58:28 +04:00
|
|
|
if (!box_get_attribute(n, "type", params, ¶ms->type))
|
2005-04-10 21:08:49 +04:00
|
|
|
return false;
|
2005-04-14 01:58:28 +04:00
|
|
|
if (params->type && content_lookup(params->type) == CONTENT_OTHER)
|
|
|
|
/* can't handle this MIME type */
|
|
|
|
return true;
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2005-04-14 01:58:28 +04:00
|
|
|
/* add parameters to linked list */
|
2005-04-09 13:47:37 +04:00
|
|
|
for (c = n->children; c; c = c->next) {
|
|
|
|
if (c->type != XML_ELEMENT_NODE)
|
|
|
|
continue;
|
|
|
|
if (strcmp((const char *) c->name, "param") != 0)
|
2005-04-14 01:58:28 +04:00
|
|
|
/* The first non-param child is the start of the alt
|
|
|
|
* html. Therefore, we should break out of this loop. */
|
2005-03-26 04:12:27 +03:00
|
|
|
break;
|
|
|
|
|
2005-04-14 01:58:28 +04:00
|
|
|
param = talloc(params, struct object_param);
|
|
|
|
if (!param)
|
2005-04-09 13:47:37 +04:00
|
|
|
return false;
|
2005-04-14 01:58:28 +04:00
|
|
|
param->name = 0;
|
|
|
|
param->value = 0;
|
|
|
|
param->type = 0;
|
|
|
|
param->valuetype = 0;
|
|
|
|
param->next = 0;
|
2005-04-09 13:47:37 +04:00
|
|
|
|
2005-04-14 01:58:28 +04:00
|
|
|
if (!box_get_attribute(c, "name", param, ¶m->name))
|
2005-04-10 21:08:49 +04:00
|
|
|
return false;
|
2005-04-14 01:58:28 +04:00
|
|
|
if (!box_get_attribute(c, "value", param, ¶m->value))
|
2005-04-10 21:08:49 +04:00
|
|
|
return false;
|
2005-04-14 01:58:28 +04:00
|
|
|
if (!box_get_attribute(c, "type", param, ¶m->type))
|
2005-04-10 21:08:49 +04:00
|
|
|
return false;
|
2005-04-14 01:58:28 +04:00
|
|
|
if (!box_get_attribute(c, "valuetype", param,
|
|
|
|
¶m->valuetype))
|
2005-04-10 21:08:49 +04:00
|
|
|
return false;
|
2005-04-14 01:58:28 +04:00
|
|
|
if (!param->valuetype)
|
|
|
|
param->valuetype = "data";
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2005-04-14 01:58:28 +04:00
|
|
|
param->next = params->params;
|
|
|
|
params->params = param;
|
2005-03-26 04:12:27 +03:00
|
|
|
}
|
|
|
|
|
2005-04-14 01:58:28 +04:00
|
|
|
box->object_params = params;
|
2005-04-09 13:47:37 +04:00
|
|
|
|
2005-04-14 01:58:28 +04:00
|
|
|
/* start fetch (MIME type is ok or not specified) */
|
|
|
|
if (!html_fetch_object(content, params->data, box, 0,
|
2005-08-21 02:52:20 +04:00
|
|
|
content->available_width, 1000, false, 0))
|
2005-04-14 01:58:28 +04:00
|
|
|
return false;
|
|
|
|
|
|
|
|
/* convert children and place into fallback */
|
|
|
|
for (c = n->children; c; c = c->next) {
|
|
|
|
if (!convert_xml_to_box(c, content, box->style, box,
|
2006-06-26 08:52:34 +04:00
|
|
|
&inline_container, 0, 0, 0, 0))
|
2005-04-14 01:58:28 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
box->fallback = box->children;
|
|
|
|
box->children = box->last = 0;
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2005-04-14 01:58:28 +04:00
|
|
|
*convert_children = false;
|
2005-04-09 13:47:37 +04:00
|
|
|
return true;
|
2005-03-26 04:12:27 +03:00
|
|
|
}
|
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
|
2005-04-14 01:58:28 +04:00
|
|
|
#if 0 /**
|
2005-04-09 13:47:37 +04:00
|
|
|
* "Java applet" [13.4].
|
|
|
|
*
|
|
|
|
* \todo This needs reworking to be compliant to the spec
|
|
|
|
* For now, we simply ignore all applet tags.
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct box_result box_applet(xmlNode *n, struct box_status *status,
|
2005-03-26 04:12:27 +03:00
|
|
|
struct css_style *style)
|
|
|
|
{
|
|
|
|
struct box *box;
|
2005-04-09 13:47:37 +04:00
|
|
|
struct object_params *po;
|
2005-04-14 01:58:28 +04:00
|
|
|
struct object_param *pp = NULL;
|
2005-04-09 13:47:37 +04:00
|
|
|
char *s;
|
|
|
|
xmlNode *c;
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
po = calloc(1, sizeof(struct object_params));
|
|
|
|
if (!po)
|
2005-03-26 04:12:27 +03:00
|
|
|
return (struct box_result) {0, false, true};
|
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
box = box_create(style, status->href, 0, status->id,
|
|
|
|
status->content->data.html.box_pool);
|
|
|
|
if (!box) {
|
|
|
|
free(po);
|
|
|
|
return (struct box_result) {0, false, true};
|
2005-03-26 04:12:27 +03:00
|
|
|
}
|
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
/* archive */
|
|
|
|
if ((s = (char *) xmlGetProp(n, (const xmlChar *) "archive")) != NULL) {
|
|
|
|
/** \todo tokenise this comma separated list */
|
|
|
|
LOG(("archive '%s'", s));
|
|
|
|
po->data = strdup(s);
|
|
|
|
xmlFree(s);
|
|
|
|
if (!po->data)
|
|
|
|
goto no_memory;
|
2005-03-26 04:12:27 +03:00
|
|
|
}
|
2005-04-09 13:47:37 +04:00
|
|
|
/* code */
|
|
|
|
if ((s = (char *) xmlGetProp(n, (const xmlChar *) "code")) != NULL) {
|
|
|
|
LOG(("applet '%s'", s));
|
|
|
|
po->classid = strdup(s);
|
|
|
|
xmlFree(s);
|
|
|
|
if (!po->classid)
|
|
|
|
goto no_memory;
|
2005-03-26 04:12:27 +03:00
|
|
|
}
|
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
/* object codebase */
|
|
|
|
if ((s = (char *) xmlGetProp(n, (const xmlChar *) "codebase")) != NULL) {
|
|
|
|
po->codebase = strdup(s);
|
|
|
|
LOG(("codebase: %s", s));
|
2005-03-26 04:12:27 +03:00
|
|
|
xmlFree(s);
|
2005-04-09 13:47:37 +04:00
|
|
|
if (!po->codebase)
|
2005-03-26 04:12:27 +03:00
|
|
|
goto no_memory;
|
|
|
|
}
|
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
/* 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 (c->type != XML_ELEMENT_NODE)
|
|
|
|
continue;
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
if (strcmp((const char *) c->name, "param") == 0) {
|
2005-04-14 01:58:28 +04:00
|
|
|
pp = calloc(1, sizeof(struct object_param));
|
2005-04-09 13:47:37 +04:00
|
|
|
if (!pp)
|
|
|
|
goto no_memory;
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
if ((s = (char *) xmlGetProp(c, (const xmlChar *) "name")) != NULL) {
|
|
|
|
pp->name = strdup(s);
|
|
|
|
xmlFree(s);
|
|
|
|
if (!pp->name)
|
|
|
|
goto no_memory;
|
|
|
|
}
|
|
|
|
if ((s = (char *) xmlGetProp(c, (const xmlChar *) "value")) != NULL) {
|
|
|
|
pp->value = strdup(s);
|
|
|
|
xmlFree(s);
|
|
|
|
if (!pp->value)
|
|
|
|
goto no_memory;
|
|
|
|
}
|
|
|
|
if ((s = (char *) xmlGetProp(c, (const xmlChar *) "type")) != NULL) {
|
|
|
|
pp->type = strdup(s);
|
|
|
|
xmlFree(s);
|
|
|
|
if (!pp->type)
|
|
|
|
goto no_memory;
|
|
|
|
}
|
|
|
|
if ((s = (char *) xmlGetProp(c, (const xmlChar *) "valuetype")) != NULL) {
|
|
|
|
pp->valuetype = strdup(s);
|
|
|
|
xmlFree(s);
|
|
|
|
if (!pp->valuetype)
|
|
|
|
goto no_memory;
|
|
|
|
} else {
|
|
|
|
pp->valuetype = strdup("data");
|
|
|
|
if (!pp->valuetype)
|
|
|
|
goto no_memory;
|
|
|
|
}
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
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.
|
|
|
|
*/
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
box->object_params = po;
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
/* start fetch */
|
|
|
|
if (plugin_decode(status->content, box))
|
|
|
|
return (struct box_result) {box, false, false};
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
return (struct box_result) {box, true, false};
|
2005-03-26 04:12:27 +03:00
|
|
|
|
|
|
|
no_memory:
|
2005-04-09 13:47:37 +04:00
|
|
|
if (pp && pp != po->params) {
|
|
|
|
/* ran out of memory creating parameter struct */
|
|
|
|
free(pp->name);
|
|
|
|
free(pp->value);
|
|
|
|
free(pp->type);
|
|
|
|
free(pp->valuetype);
|
|
|
|
free(pp);
|
|
|
|
}
|
|
|
|
|
|
|
|
box_free_object_params(po);
|
|
|
|
box_free_box(box);
|
|
|
|
|
|
|
|
return (struct box_result) {0, false, true};
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Window subdivision [16.2.1].
|
2005-03-26 04:12:27 +03:00
|
|
|
*/
|
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
bool box_frameset(BOX_SPECIAL_PARAMS)
|
2005-03-26 04:12:27 +03:00
|
|
|
{
|
2005-04-09 13:47:37 +04:00
|
|
|
unsigned int row, col;
|
|
|
|
unsigned int rows = 1, cols = 1;
|
|
|
|
int object_width, object_height;
|
2005-08-21 02:52:20 +04:00
|
|
|
char *s, *s1, *url, *name;
|
2005-04-09 13:47:37 +04:00
|
|
|
struct box *row_box;
|
|
|
|
struct box *cell_box;
|
|
|
|
struct box *frameset_box;
|
|
|
|
struct css_style *style = box->style;
|
|
|
|
struct css_style *row_style;
|
|
|
|
struct css_style *cell_style;
|
|
|
|
struct box_multi_length *row_height = 0, *col_width = 0;
|
|
|
|
xmlNode *c;
|
|
|
|
url_func_result res;
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
box->type = BOX_TABLE;
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
/* parse rows and columns */
|
|
|
|
if ((s = (char *) xmlGetProp(n, (const xmlChar *) "rows"))) {
|
|
|
|
row_height = box_parse_multi_lengths(s, &rows, content);
|
2005-03-26 04:12:27 +03:00
|
|
|
xmlFree(s);
|
2005-04-09 13:47:37 +04:00
|
|
|
if (!row_height)
|
|
|
|
return false;
|
|
|
|
}
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
if ((s = (char *) xmlGetProp(n, (const xmlChar *) "cols"))) {
|
|
|
|
col_width = box_parse_multi_lengths(s, &cols, content);
|
|
|
|
xmlFree(s);
|
|
|
|
if (!col_width)
|
|
|
|
return false;
|
|
|
|
}
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
LOG(("rows %u, cols %u", rows, cols));
|
|
|
|
|
|
|
|
box->min_width = 1;
|
|
|
|
box->max_width = 10000;
|
|
|
|
box->col = talloc_array(content, struct column, cols);
|
|
|
|
if (!box->col)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* create the frameset table */
|
|
|
|
c = n->children;
|
|
|
|
for (row = 0; c && row != rows; row++) {
|
|
|
|
row_style = talloc_memdup(content, style, sizeof *style);
|
|
|
|
if (!row_style)
|
|
|
|
return false;
|
|
|
|
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;
|
|
|
|
}*/
|
2005-08-23 02:49:52 +04:00
|
|
|
row_box = box_create(row_style, 0, 0, 0, 0, content);
|
2005-04-09 13:47:37 +04:00
|
|
|
if (!row_box)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
/* estimate frame width */
|
|
|
|
object_width = content->available_width;
|
|
|
|
if (col_width && col_width[col].type == LENGTH_PX)
|
|
|
|
object_width = col_width[col].value;
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
cell_style = talloc_memdup(content, style,
|
|
|
|
sizeof *style);
|
|
|
|
if (!cell_style)
|
|
|
|
return false;
|
|
|
|
cell_style->overflow = CSS_OVERFLOW_AUTO;
|
|
|
|
|
2005-08-23 02:49:52 +04:00
|
|
|
cell_box = box_create(cell_style, 0, 0, 0, 0, content);
|
2005-04-09 13:47:37 +04:00
|
|
|
if (!cell_box)
|
|
|
|
return false;
|
|
|
|
cell_box->type = BOX_TABLE_CELL;
|
|
|
|
box_add_child(row_box, cell_box);
|
|
|
|
|
|
|
|
if (strcmp((const char *) c->name, "frameset") == 0) {
|
|
|
|
LOG(("frameset"));
|
|
|
|
frameset_box = box_create(cell_style, 0, 0, 0,
|
2005-08-23 02:49:52 +04:00
|
|
|
0, content);
|
2005-04-09 13:47:37 +04:00
|
|
|
if (!frameset_box)
|
|
|
|
return false;
|
2005-04-17 20:56:41 +04:00
|
|
|
if (!box_frameset(c, content, frameset_box, 0))
|
2005-04-09 13:47:37 +04:00
|
|
|
return false;
|
|
|
|
box_add_child(cell_box, frameset_box);
|
|
|
|
|
|
|
|
c = c->next;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(s = (char *) xmlGetProp(c,
|
|
|
|
(const xmlChar *) "src"))) {
|
|
|
|
c = c->next;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
s1 = strip(s);
|
|
|
|
res = url_join(s1, content->data.html.base_url, &url);
|
|
|
|
xmlFree(s);
|
|
|
|
/* if url is equivalent to the parent's url,
|
|
|
|
* we've got infinite inclusion. stop it here.
|
|
|
|
* also bail if url_join failed.
|
|
|
|
*/
|
|
|
|
if (res != URL_FUNC_OK || strcasecmp(url,
|
|
|
|
content->data.html.base_url) == 0) {
|
|
|
|
LOG(("url_join failed"));
|
|
|
|
c = c->next;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2005-08-21 02:52:20 +04:00
|
|
|
name = xmlGetProp(c, (const xmlChar *) "name");
|
|
|
|
|
|
|
|
LOG(("frame, url '%s', name '%s'", url, name));
|
2005-04-09 13:47:37 +04:00
|
|
|
|
|
|
|
if (!html_fetch_object(content, url,
|
2005-08-08 01:28:48 +04:00
|
|
|
cell_box, 0,
|
2005-08-21 02:52:20 +04:00
|
|
|
object_width, object_height, false,
|
|
|
|
name))
|
2005-04-09 13:47:37 +04:00
|
|
|
return false;
|
|
|
|
free(url);
|
|
|
|
|
2005-08-21 02:52:20 +04:00
|
|
|
if (name)
|
|
|
|
xmlFree(name);
|
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
c = c->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
talloc_free(row_height);
|
|
|
|
talloc_free(col_width);
|
|
|
|
|
|
|
|
style->width.width = CSS_WIDTH_PERCENT;
|
|
|
|
style->width.value.percent = 100;
|
|
|
|
|
|
|
|
if (convert_children)
|
|
|
|
*convert_children = false;
|
2005-03-26 04:12:27 +03:00
|
|
|
return true;
|
2005-04-09 13:47:37 +04:00
|
|
|
}
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Inline subwindow [16.5].
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool box_iframe(BOX_SPECIAL_PARAMS)
|
|
|
|
{
|
2005-04-14 01:58:28 +04:00
|
|
|
bool ok;
|
|
|
|
char *url;
|
|
|
|
xmlChar *src;
|
2005-04-09 13:47:37 +04:00
|
|
|
|
2005-04-14 01:58:28 +04:00
|
|
|
/* get frame URL */
|
|
|
|
if (!(src = xmlGetProp(n, (const xmlChar *) "src")))
|
|
|
|
return true;
|
|
|
|
if (!box_extract_link((char *) src, content->data.html.base_url, &url))
|
2005-04-09 13:47:37 +04:00
|
|
|
return false;
|
2005-04-14 01:58:28 +04:00
|
|
|
if (!url)
|
|
|
|
return true;
|
2005-04-09 13:47:37 +04:00
|
|
|
|
2006-03-27 05:04:56 +04:00
|
|
|
/* Don't include ourself */
|
|
|
|
if (strcmp(content->data.html.base_url, url) == 0) {
|
|
|
|
free(url);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
/* start fetch */
|
2005-04-14 01:58:28 +04:00
|
|
|
ok = html_fetch_object(content, url, box, 0,
|
2005-08-21 02:52:20 +04:00
|
|
|
content->available_width, 0, false, 0);
|
2005-06-26 05:55:20 +04:00
|
|
|
|
2005-04-14 01:58:28 +04:00
|
|
|
free(url);
|
|
|
|
return ok;
|
2005-03-26 04:12:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
/**
|
|
|
|
* Interactive form [17.3].
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool box_form(BOX_SPECIAL_PARAMS)
|
|
|
|
{
|
2005-07-03 19:57:10 +04:00
|
|
|
char *xmlaction, *action, *method, *enctype, *charset;
|
2005-04-09 13:47:37 +04:00
|
|
|
form_method fmethod;
|
|
|
|
struct form *form;
|
|
|
|
|
2005-07-03 19:57:10 +04:00
|
|
|
if (!(xmlaction = (char *)
|
|
|
|
xmlGetProp(n, (const xmlChar *) "action"))) {
|
|
|
|
/* the action attribute is required, but many forms fail to
|
|
|
|
* specify it. In the case where it is _not_ specified,
|
|
|
|
* follow other browsers and make the form action the
|
|
|
|
* URI of the page the form is contained in. */
|
|
|
|
action = strdup("");
|
|
|
|
} else {
|
|
|
|
action = strdup(xmlaction);
|
|
|
|
xmlFree(xmlaction);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!action)
|
|
|
|
return false;
|
2005-04-09 13:47:37 +04: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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
xmlFree(method);
|
|
|
|
}
|
|
|
|
|
2005-04-16 09:09:33 +04:00
|
|
|
/* acceptable encoding(s) for form data */
|
2005-06-26 05:55:20 +04:00
|
|
|
charset = (char *) xmlGetProp(n, (const xmlChar *) "accept-charset");
|
2005-04-16 09:09:33 +04:00
|
|
|
|
2005-06-26 05:55:20 +04:00
|
|
|
form = form_new(action, fmethod, charset,
|
|
|
|
content->data.html.encoding);
|
2005-04-09 13:47:37 +04:00
|
|
|
if (!form) {
|
2005-07-03 19:57:10 +04:00
|
|
|
free(action);
|
2005-06-26 05:55:20 +04:00
|
|
|
xmlFree(charset);
|
2005-04-09 13:47:37 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
form->prev = content->data.html.forms;
|
|
|
|
content->data.html.forms = form;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Form control [17.4].
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool box_input(BOX_SPECIAL_PARAMS)
|
2005-03-26 04:12:27 +03:00
|
|
|
{
|
|
|
|
struct form_control *gadget = NULL;
|
|
|
|
char *s, *type, *url;
|
|
|
|
url_func_result res;
|
|
|
|
|
|
|
|
type = (char *) xmlGetProp(n, (const xmlChar *) "type");
|
|
|
|
|
|
|
|
if (type && strcasecmp(type, "password") == 0) {
|
2005-04-09 13:47:37 +04:00
|
|
|
if (!box_input_text(n, content, box, 0, true))
|
2005-03-26 04:12:27 +03:00
|
|
|
goto no_memory;
|
|
|
|
gadget = box->gadget;
|
|
|
|
gadget->box = box;
|
|
|
|
|
|
|
|
} else if (type && strcasecmp(type, "file") == 0) {
|
|
|
|
box->type = BOX_INLINE_BLOCK;
|
|
|
|
box->gadget = gadget = form_new_control(GADGET_FILE);
|
|
|
|
if (!gadget)
|
|
|
|
goto no_memory;
|
|
|
|
gadget->box = box;
|
|
|
|
|
|
|
|
} else if (type && strcasecmp(type, "hidden") == 0) {
|
|
|
|
/* no box for hidden inputs */
|
2005-07-03 00:08:24 +04:00
|
|
|
box->style->display = CSS_DISPLAY_NONE;
|
|
|
|
|
2005-03-26 04:12:27 +03:00
|
|
|
gadget = form_new_control(GADGET_HIDDEN);
|
|
|
|
if (!gadget)
|
|
|
|
goto no_memory;
|
|
|
|
|
|
|
|
if ((s = (char *) xmlGetProp(n, (const xmlChar *) "value"))) {
|
|
|
|
gadget->value = strdup(s);
|
|
|
|
xmlFree(s);
|
|
|
|
if (!gadget->value)
|
|
|
|
goto no_memory;
|
|
|
|
gadget->length = strlen(gadget->value);
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (type && (strcasecmp(type, "checkbox") == 0 ||
|
|
|
|
strcasecmp(type, "radio") == 0)) {
|
|
|
|
box->gadget = gadget = form_new_control(type[0] == 'c' ||
|
|
|
|
type[0] == 'C' ? GADGET_CHECKBOX :
|
|
|
|
GADGET_RADIO);
|
|
|
|
if (!gadget)
|
|
|
|
goto no_memory;
|
|
|
|
gadget->box = box;
|
|
|
|
|
|
|
|
gadget->selected = xmlHasProp(n, (const xmlChar *) "checked");
|
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
if ((s = (char *) xmlGetProp(n, (const xmlChar *) "value"))) {
|
2005-03-26 04:12:27 +03:00
|
|
|
gadget->value = strdup(s);
|
|
|
|
xmlFree(s);
|
|
|
|
if (!gadget->value)
|
|
|
|
goto no_memory;
|
|
|
|
gadget->length = strlen(gadget->value);
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (type && (strcasecmp(type, "submit") == 0 ||
|
|
|
|
strcasecmp(type, "reset") == 0)) {
|
|
|
|
struct box *inline_container, *inline_box;
|
2005-04-09 13:47:37 +04:00
|
|
|
if (!box_button(n, content, box, 0))
|
2005-03-26 04:12:27 +03:00
|
|
|
goto no_memory;
|
2005-08-23 02:49:52 +04:00
|
|
|
inline_container = box_create(0, 0, 0, 0, 0, content);
|
2005-03-26 04:12:27 +03:00
|
|
|
if (!inline_container)
|
|
|
|
goto no_memory;
|
|
|
|
inline_container->type = BOX_INLINE_CONTAINER;
|
2005-08-23 02:49:52 +04:00
|
|
|
inline_box = box_create(box->style, 0, 0, box->title, 0,
|
|
|
|
content);
|
2005-03-26 04:12:27 +03:00
|
|
|
if (!inline_box)
|
|
|
|
goto no_memory;
|
2005-05-25 00:21:47 +04:00
|
|
|
inline_box->type = BOX_TEXT;
|
2005-03-26 04:12:27 +03:00
|
|
|
if (box->gadget->value != NULL)
|
2005-04-09 13:47:37 +04:00
|
|
|
inline_box->text = talloc_strdup(content,
|
|
|
|
box->gadget->value);
|
2005-03-26 04:12:27 +03:00
|
|
|
else if (box->gadget->type == GADGET_SUBMIT)
|
2005-04-09 13:47:37 +04:00
|
|
|
inline_box->text = talloc_strdup(content,
|
|
|
|
messages_get("Form_Submit"));
|
2005-03-26 04:12:27 +03:00
|
|
|
else
|
2005-04-09 13:47:37 +04:00
|
|
|
inline_box->text = talloc_strdup(content,
|
|
|
|
messages_get("Form_Reset"));
|
2005-03-26 04:12:27 +03:00
|
|
|
if (!inline_box->text)
|
|
|
|
goto no_memory;
|
|
|
|
inline_box->length = strlen(inline_box->text);
|
|
|
|
box_add_child(inline_container, inline_box);
|
|
|
|
box_add_child(box, inline_container);
|
|
|
|
|
|
|
|
} else if (type && strcasecmp(type, "button") == 0) {
|
|
|
|
struct box *inline_container, *inline_box;
|
2005-04-09 13:47:37 +04:00
|
|
|
if (!box_button(n, content, box, 0))
|
2005-03-26 04:12:27 +03:00
|
|
|
goto no_memory;
|
2005-08-23 02:49:52 +04:00
|
|
|
inline_container = box_create(0, 0, 0, 0, 0, content);
|
2005-03-26 04:12:27 +03:00
|
|
|
if (!inline_container)
|
|
|
|
goto no_memory;
|
|
|
|
inline_container->type = BOX_INLINE_CONTAINER;
|
2005-08-23 02:49:52 +04:00
|
|
|
inline_box = box_create(box->style, 0, 0, box->title, 0,
|
|
|
|
content);
|
2005-03-26 04:12:27 +03:00
|
|
|
if (!inline_box)
|
|
|
|
goto no_memory;
|
2005-05-25 00:21:47 +04:00
|
|
|
inline_box->type = BOX_TEXT;
|
2005-03-26 04:12:27 +03:00
|
|
|
if ((s = (char *) xmlGetProp(n, (const xmlChar *) "value")))
|
2005-04-09 13:47:37 +04:00
|
|
|
inline_box->text = talloc_strdup(content, s);
|
2005-03-26 04:12:27 +03:00
|
|
|
else
|
2005-04-09 13:47:37 +04:00
|
|
|
inline_box->text = talloc_strdup(content, "Button");
|
2005-03-26 04:12:27 +03:00
|
|
|
if (!inline_box->text)
|
|
|
|
goto no_memory;
|
|
|
|
inline_box->length = strlen(inline_box->text);
|
|
|
|
box_add_child(inline_container, inline_box);
|
|
|
|
box_add_child(box, inline_container);
|
|
|
|
|
|
|
|
} else if (type && strcasecmp(type, "image") == 0) {
|
|
|
|
box->gadget = gadget = form_new_control(GADGET_IMAGE);
|
|
|
|
if (!gadget)
|
|
|
|
goto no_memory;
|
|
|
|
gadget->box = box;
|
|
|
|
gadget->type = GADGET_IMAGE;
|
2005-04-09 13:47:37 +04:00
|
|
|
if ((s = (char *) xmlGetProp(n, (const xmlChar*) "src"))) {
|
|
|
|
res = url_join(s, content->data.html.base_url, &url);
|
|
|
|
xmlFree(s);
|
2005-03-26 04:12:27 +03:00
|
|
|
/* if url is equivalent to the parent's url,
|
|
|
|
* we've got infinite inclusion. stop it here.
|
|
|
|
* also bail if url_join failed.
|
|
|
|
*/
|
|
|
|
if (res == URL_FUNC_OK &&
|
2005-04-09 13:47:37 +04:00
|
|
|
strcasecmp(url, content->data.
|
|
|
|
html.base_url) != 0) {
|
|
|
|
if (!html_fetch_object(content, url,
|
|
|
|
box, image_types,
|
|
|
|
content->available_width,
|
2005-08-21 02:52:20 +04:00
|
|
|
1000, false, 0)) {
|
2005-04-09 13:47:37 +04:00
|
|
|
free(url);
|
2005-03-26 04:12:27 +03:00
|
|
|
goto no_memory;
|
2005-04-09 13:47:37 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
free(url);
|
2005-03-26 04:12:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
/* the default type is "text" */
|
2005-04-09 13:47:37 +04:00
|
|
|
if (!box_input_text(n, content, box, 0, false))
|
2005-03-26 04:12:27 +03:00
|
|
|
goto no_memory;
|
|
|
|
gadget = box->gadget;
|
|
|
|
gadget->box = box;
|
|
|
|
}
|
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
if (type)
|
2005-03-26 04:12:27 +03:00
|
|
|
xmlFree(type);
|
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
if (gadget) {
|
|
|
|
if (content->data.html.forms)
|
|
|
|
form_add_control(content->data.html.forms, gadget);
|
2005-03-26 04:12:27 +03:00
|
|
|
s = (char *) xmlGetProp(n, (const xmlChar *) "name");
|
|
|
|
if (s) {
|
|
|
|
gadget->name = strdup(s);
|
|
|
|
xmlFree(s);
|
|
|
|
if (!gadget->name)
|
|
|
|
goto no_memory;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
*convert_children = false;
|
|
|
|
return true;
|
2005-03-26 04:12:27 +03:00
|
|
|
|
|
|
|
no_memory:
|
|
|
|
if (type)
|
|
|
|
xmlFree(type);
|
|
|
|
if (gadget)
|
|
|
|
form_free_control(gadget);
|
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
return false;
|
2005-03-26 04:12:27 +03:00
|
|
|
}
|
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper function for box_input().
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool box_input_text(BOX_SPECIAL_PARAMS, bool password)
|
2005-03-26 04:12:27 +03:00
|
|
|
{
|
|
|
|
char *s;
|
|
|
|
struct box *inline_container, *inline_box;
|
|
|
|
|
|
|
|
box->type = BOX_INLINE_BLOCK;
|
2005-04-09 13:47:37 +04:00
|
|
|
box->gadget = form_new_control((password) ? GADGET_PASSWORD :
|
|
|
|
GADGET_TEXTBOX);
|
2005-03-26 04:12:27 +03:00
|
|
|
if (!box->gadget)
|
|
|
|
return 0;
|
|
|
|
box->gadget->box = box;
|
|
|
|
|
|
|
|
box->gadget->maxlength = 100;
|
2005-04-09 13:47:37 +04:00
|
|
|
if ((s = (char *) xmlGetProp(n, (const xmlChar *) "maxlength"))) {
|
2005-03-26 04:12:27 +03:00
|
|
|
box->gadget->maxlength = atoi(s);
|
|
|
|
xmlFree(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
s = (char *) xmlGetProp(n, (const xmlChar *) "value");
|
|
|
|
box->gadget->value = strdup((s != NULL) ? s : "");
|
2005-04-09 13:47:37 +04:00
|
|
|
box->gadget->initial_value = strdup((box->gadget->value != NULL) ?
|
|
|
|
box->gadget->value : "");
|
2005-03-26 04:12:27 +03:00
|
|
|
if (s)
|
|
|
|
xmlFree(s);
|
|
|
|
if (box->gadget->value == NULL || box->gadget->initial_value == NULL) {
|
|
|
|
box_free(box);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
box->gadget->length = strlen(box->gadget->value);
|
|
|
|
|
2005-08-23 02:49:52 +04:00
|
|
|
inline_container = box_create(0, 0, 0, 0, 0, content);
|
2005-03-26 04:12:27 +03:00
|
|
|
if (!inline_container)
|
|
|
|
return 0;
|
|
|
|
inline_container->type = BOX_INLINE_CONTAINER;
|
2005-08-23 02:49:52 +04:00
|
|
|
inline_box = box_create(box->style, 0, 0, box->title, 0, content);
|
2005-03-26 04:12:27 +03:00
|
|
|
if (!inline_box)
|
|
|
|
return 0;
|
2005-05-25 00:21:47 +04:00
|
|
|
inline_box->type = BOX_TEXT;
|
2005-03-26 04:12:27 +03:00
|
|
|
if (password) {
|
|
|
|
inline_box->length = strlen(box->gadget->value);
|
2005-04-09 13:47:37 +04:00
|
|
|
inline_box->text = talloc_array(content, char,
|
|
|
|
inline_box->length + 1);
|
2005-03-26 04:12:27 +03:00
|
|
|
if (!inline_box->text)
|
|
|
|
return 0;
|
|
|
|
memset(inline_box->text, '*', inline_box->length);
|
|
|
|
inline_box->text[inline_box->length] = '\0';
|
|
|
|
} else {
|
2005-04-09 13:47:37 +04:00
|
|
|
/* replace spaces/TABs with hard spaces to prevent line
|
|
|
|
* wrapping */
|
|
|
|
char *text = cnv_space2nbsp(box->gadget->value);
|
|
|
|
if (!text)
|
|
|
|
return 0;
|
|
|
|
inline_box->text = talloc_strdup(content, text);
|
|
|
|
free(text);
|
2005-03-26 04:12:27 +03:00
|
|
|
if (!inline_box->text)
|
|
|
|
return 0;
|
|
|
|
inline_box->length = strlen(inline_box->text);
|
|
|
|
}
|
|
|
|
box_add_child(inline_container, inline_box);
|
|
|
|
box_add_child(box, inline_container);
|
|
|
|
|
|
|
|
return box;
|
|
|
|
}
|
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Push button [17.5].
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool box_button(BOX_SPECIAL_PARAMS)
|
2005-03-26 04:12:27 +03:00
|
|
|
{
|
|
|
|
xmlChar *s;
|
|
|
|
char *type = (char *) xmlGetProp(n, (const xmlChar *) "type");
|
2005-04-09 13:47:37 +04:00
|
|
|
|
2005-03-26 04:12:27 +03:00
|
|
|
box->type = BOX_INLINE_BLOCK;
|
|
|
|
|
|
|
|
if (!type || strcasecmp(type, "submit") == 0) {
|
|
|
|
box->gadget = form_new_control(GADGET_SUBMIT);
|
|
|
|
} else if (strcasecmp(type, "reset") == 0) {
|
|
|
|
box->gadget = form_new_control(GADGET_RESET);
|
|
|
|
} else {
|
|
|
|
/* type="button" or unknown: just render the contents */
|
|
|
|
xmlFree(type);
|
2005-04-09 13:47:37 +04:00
|
|
|
return true;
|
2005-03-26 04:12:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (type)
|
|
|
|
xmlFree(type);
|
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
if (!box->gadget)
|
|
|
|
return false;
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
if (content->data.html.forms)
|
|
|
|
form_add_control(content->data.html.forms, box->gadget);
|
2005-03-26 04:12:27 +03:00
|
|
|
box->gadget->box = box;
|
|
|
|
if ((s = xmlGetProp(n, (const xmlChar *) "name")) != NULL) {
|
|
|
|
box->gadget->name = strdup((char *) s);
|
|
|
|
xmlFree(s);
|
2005-04-09 13:47:37 +04:00
|
|
|
if (!box->gadget->name)
|
|
|
|
return false;
|
2005-03-26 04:12:27 +03:00
|
|
|
}
|
|
|
|
if ((s = xmlGetProp(n, (const xmlChar *) "value")) != NULL) {
|
|
|
|
box->gadget->value = strdup((char *) s);
|
|
|
|
xmlFree(s);
|
2005-04-09 13:47:37 +04:00
|
|
|
if (!box->gadget->value)
|
|
|
|
return false;
|
2005-03-26 04:12:27 +03:00
|
|
|
}
|
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
return true;
|
2005-03-26 04:12:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2005-04-09 13:47:37 +04:00
|
|
|
* Option selector [17.6].
|
2005-03-26 04:12:27 +03:00
|
|
|
*/
|
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
bool box_select(BOX_SPECIAL_PARAMS)
|
|
|
|
{
|
|
|
|
struct box *inline_container;
|
|
|
|
struct box *inline_box;
|
|
|
|
struct form_control *gadget;
|
|
|
|
char* s;
|
|
|
|
xmlNode *c, *c2;
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
gadget = form_new_control(GADGET_SELECT);
|
|
|
|
if (!gadget)
|
|
|
|
return false;
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
gadget->data.select.multiple = false;
|
|
|
|
if ((s = (char *) xmlGetProp(n, (const xmlChar *) "multiple"))) {
|
|
|
|
gadget->data.select.multiple = true;
|
2005-03-26 04:12:27 +03:00
|
|
|
xmlFree(s);
|
|
|
|
}
|
|
|
|
|
2005-04-09 13:47:37 +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;
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
for (c = n->children; c; c = c->next) {
|
|
|
|
if (strcmp((const char *) c->name, "option") == 0) {
|
|
|
|
if (!box_select_add_option(gadget, c))
|
|
|
|
goto no_memory;
|
|
|
|
} else if (strcmp((const char *) c->name, "optgroup") == 0) {
|
|
|
|
for (c2 = c->children; c2; c2 = c2->next) {
|
|
|
|
if (strcmp((const char *) c2->name,
|
|
|
|
"option") == 0) {
|
|
|
|
if (!box_select_add_option(gadget, c2))
|
|
|
|
goto no_memory;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-03-26 04:12:27 +03:00
|
|
|
}
|
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
if (gadget->data.select.num_items == 0) {
|
|
|
|
/* no options: ignore entire select */
|
|
|
|
form_free_control(gadget);
|
|
|
|
return true;
|
2005-03-26 04:12:27 +03:00
|
|
|
}
|
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
if ((s = (char *) xmlGetProp(n, (const xmlChar *) "name"))) {
|
|
|
|
gadget->name = strdup(s);
|
2005-03-26 04:12:27 +03:00
|
|
|
xmlFree(s);
|
2005-04-09 13:47:37 +04:00
|
|
|
if (!gadget->name)
|
2005-03-26 04:12:27 +03:00
|
|
|
goto no_memory;
|
|
|
|
}
|
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
box->type = BOX_INLINE_BLOCK;
|
|
|
|
box->gadget = gadget;
|
|
|
|
gadget->box = box;
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2005-08-23 02:49:52 +04:00
|
|
|
inline_container = box_create(0, 0, 0, 0, 0, content);
|
2005-04-09 13:47:37 +04:00
|
|
|
if (!inline_container)
|
|
|
|
goto no_memory;
|
|
|
|
inline_container->type = BOX_INLINE_CONTAINER;
|
2005-08-23 02:49:52 +04:00
|
|
|
inline_box = box_create(box->style, 0, 0, box->title, 0, content);
|
2005-04-09 13:47:37 +04:00
|
|
|
if (!inline_box)
|
|
|
|
goto no_memory;
|
2005-05-25 00:21:47 +04:00
|
|
|
inline_box->type = BOX_TEXT;
|
2005-04-09 13:47:37 +04:00
|
|
|
box_add_child(inline_container, inline_box);
|
|
|
|
box_add_child(box, inline_container);
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
if (!gadget->data.select.multiple &&
|
|
|
|
gadget->data.select.num_selected == 0) {
|
|
|
|
gadget->data.select.current = gadget->data.select.items;
|
|
|
|
gadget->data.select.current->initial_selected =
|
|
|
|
gadget->data.select.current->selected = true;
|
|
|
|
gadget->data.select.num_selected = 1;
|
2005-03-26 04:12:27 +03:00
|
|
|
}
|
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
if (gadget->data.select.num_selected == 0)
|
2005-04-15 03:17:37 +04:00
|
|
|
inline_box->text = talloc_strdup(content,
|
|
|
|
messages_get("Form_None"));
|
2005-04-09 13:47:37 +04:00
|
|
|
else if (gadget->data.select.num_selected == 1)
|
|
|
|
inline_box->text = talloc_strdup(content,
|
|
|
|
gadget->data.select.current->text);
|
|
|
|
else
|
2005-04-15 03:17:37 +04:00
|
|
|
inline_box->text = talloc_strdup(content,
|
|
|
|
messages_get("Form_Many"));
|
2005-04-09 13:47:37 +04:00
|
|
|
if (!inline_box->text)
|
|
|
|
goto no_memory;
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
inline_box->length = strlen(inline_box->text);
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
if (content->data.html.forms)
|
|
|
|
form_add_control(content->data.html.forms, box->gadget);
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
*convert_children = false;
|
|
|
|
return true;
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
no_memory:
|
|
|
|
form_free_control(gadget);
|
|
|
|
return false;
|
2005-03-26 04:12:27 +03:00
|
|
|
}
|
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
|
2005-03-26 04:12:27 +03:00
|
|
|
/**
|
2005-04-09 13:47:37 +04:00
|
|
|
* Add an option to a form select control (helper function for box_select()).
|
|
|
|
*
|
|
|
|
* \param control select containing the option
|
|
|
|
* \param n xml element node for <option>
|
|
|
|
* \return true on success, false on memory exhaustion
|
2005-03-26 04:12:27 +03:00
|
|
|
*/
|
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
bool box_select_add_option(struct form_control *control, xmlNode *n)
|
|
|
|
{
|
|
|
|
char *value = 0;
|
|
|
|
char *text = 0;
|
|
|
|
bool selected;
|
|
|
|
xmlChar *content;
|
|
|
|
xmlChar *s;
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
content = xmlNodeGetContent(n);
|
|
|
|
if (!content)
|
|
|
|
goto no_memory;
|
|
|
|
text = squash_whitespace(content);
|
|
|
|
xmlFree(content);
|
|
|
|
if (!text)
|
|
|
|
goto no_memory;
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
if ((s = (char *) xmlGetProp(n, (const xmlChar *) "value"))) {
|
|
|
|
value = strdup(s);
|
2005-03-26 04:12:27 +03:00
|
|
|
xmlFree(s);
|
2005-04-09 13:47:37 +04:00
|
|
|
} else
|
|
|
|
value = strdup(text);
|
|
|
|
if (!value)
|
|
|
|
goto no_memory;
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
selected = xmlHasProp(n, (const xmlChar *) "selected");
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
if (!form_add_option(control, value, text, selected))
|
|
|
|
goto no_memory;
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
return true;
|
2005-03-26 04:12:27 +03:00
|
|
|
|
|
|
|
no_memory:
|
2005-04-09 13:47:37 +04:00
|
|
|
free(value);
|
|
|
|
free(text);
|
|
|
|
return false;
|
2005-03-26 04:12:27 +03:00
|
|
|
}
|
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
|
2005-03-26 04:12:27 +03:00
|
|
|
/**
|
2005-04-09 13:47:37 +04:00
|
|
|
* Multi-line text field [17.7].
|
2005-03-26 04:12:27 +03:00
|
|
|
*/
|
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
bool box_textarea(BOX_SPECIAL_PARAMS)
|
|
|
|
{
|
|
|
|
/* A textarea is an INLINE_BLOCK containing a single INLINE_CONTAINER,
|
2005-05-25 00:21:47 +04:00
|
|
|
* which contains the text as runs of TEXT separated by BR. There is
|
|
|
|
* at least one TEXT. The first and last boxes are TEXT.
|
2005-04-09 13:47:37 +04:00
|
|
|
* Consecutive BR may not be present. These constraints are satisfied
|
2005-05-25 00:21:47 +04:00
|
|
|
* by using a 0-length TEXT for blank lines. */
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
xmlChar *text, *current;
|
|
|
|
struct box *inline_container, *inline_box, *br_box;
|
|
|
|
char *s;
|
|
|
|
size_t len;
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
box->type = BOX_INLINE_BLOCK;
|
|
|
|
box->gadget = form_new_control(GADGET_TEXTAREA);
|
|
|
|
if (!box->gadget)
|
|
|
|
return false;
|
|
|
|
box->gadget->box = box;
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
if ((s = (char *) xmlGetProp(n, (const xmlChar *) "name"))) {
|
|
|
|
box->gadget->name = strdup(s);
|
2005-03-26 04:12:27 +03:00
|
|
|
xmlFree(s);
|
2005-04-09 13:47:37 +04:00
|
|
|
if (!box->gadget->name)
|
|
|
|
return false;
|
2005-03-26 04:12:27 +03:00
|
|
|
}
|
|
|
|
|
2005-08-23 02:49:52 +04:00
|
|
|
inline_container = box_create(0, 0, 0, box->title, 0, content);
|
2005-04-09 13:47:37 +04:00
|
|
|
if (!inline_container)
|
|
|
|
return false;
|
|
|
|
inline_container->type = BOX_INLINE_CONTAINER;
|
|
|
|
box_add_child(box, inline_container);
|
|
|
|
|
|
|
|
current = text = xmlNodeGetContent(n);
|
|
|
|
while (1) {
|
2005-05-25 00:21:47 +04:00
|
|
|
/* BOX_TEXT */
|
2005-04-09 13:47:37 +04:00
|
|
|
len = strcspn(current, "\r\n");
|
|
|
|
s = talloc_strndup(content, current, len);
|
|
|
|
if (!s) {
|
|
|
|
xmlFree(content);
|
|
|
|
return false;
|
2005-03-26 04:12:27 +03:00
|
|
|
}
|
|
|
|
|
2005-08-23 02:49:52 +04:00
|
|
|
inline_box = box_create(box->style, 0, 0, box->title, 0,
|
|
|
|
content);
|
2005-04-09 13:47:37 +04:00
|
|
|
if (!inline_box)
|
|
|
|
return false;
|
2005-05-25 00:21:47 +04:00
|
|
|
inline_box->type = BOX_TEXT;
|
2005-04-09 13:47:37 +04:00
|
|
|
inline_box->text = s;
|
|
|
|
inline_box->length = len;
|
|
|
|
box_add_child(inline_container, inline_box);
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
current += len;
|
|
|
|
if (current[0] == 0)
|
|
|
|
/* finished */
|
|
|
|
break;
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
/* BOX_BR */
|
2005-08-23 02:49:52 +04:00
|
|
|
br_box = box_create(box->style, 0, 0, box->title, 0, content);
|
2005-04-09 13:47:37 +04:00
|
|
|
if (!br_box)
|
|
|
|
return false;
|
|
|
|
br_box->type = BOX_BR;
|
|
|
|
box_add_child(inline_container, br_box);
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
if (current[0] == '\r' && current[1] == '\n')
|
|
|
|
current += 2;
|
|
|
|
else
|
|
|
|
current++;
|
2005-03-26 04:12:27 +03:00
|
|
|
}
|
2005-04-09 13:47:37 +04:00
|
|
|
xmlFree(text);
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
if (content->data.html.forms)
|
|
|
|
form_add_control(content->data.html.forms, box->gadget);
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
*convert_children = false;
|
|
|
|
return true;
|
2005-03-26 04:12:27 +03:00
|
|
|
}
|
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
|
2005-03-26 04:12:27 +03:00
|
|
|
/**
|
2005-04-09 13:47:37 +04:00
|
|
|
* Embedded object (not in any HTML specification:
|
|
|
|
* see http://wp.netscape.com/assist/net_sites/new_html3_prop.html )
|
2005-03-26 04:12:27 +03:00
|
|
|
*/
|
2005-04-09 13:47:37 +04:00
|
|
|
|
|
|
|
bool box_embed(BOX_SPECIAL_PARAMS)
|
2005-03-26 04:12:27 +03:00
|
|
|
{
|
2005-04-14 01:58:28 +04:00
|
|
|
struct object_params *params;
|
|
|
|
struct object_param *param;
|
|
|
|
xmlChar *src;
|
2005-04-09 13:47:37 +04:00
|
|
|
xmlAttr *a;
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2005-04-14 01:58:28 +04:00
|
|
|
params = talloc(content, struct object_params);
|
|
|
|
if (!params)
|
2005-04-09 13:47:37 +04:00
|
|
|
return false;
|
2005-04-14 01:58:28 +04:00
|
|
|
params->data = 0;
|
|
|
|
params->type = 0;
|
|
|
|
params->codetype = 0;
|
|
|
|
params->codebase = 0;
|
|
|
|
params->classid = 0;
|
|
|
|
params->params = 0;
|
|
|
|
|
|
|
|
/* src is a URL */
|
|
|
|
if (!(src = xmlGetProp(n, (const xmlChar *) "src")))
|
|
|
|
return true;
|
|
|
|
if (!box_extract_link((char *) src, content->data.html.base_url,
|
|
|
|
¶ms->data))
|
|
|
|
return false;
|
|
|
|
xmlFree(src);
|
|
|
|
if (!params->data)
|
|
|
|
return true;
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2006-03-27 05:04:56 +04:00
|
|
|
/* Don't include ourself */
|
|
|
|
if (strcmp(content->data.html.base_url, params->data) == 0)
|
|
|
|
return true;
|
|
|
|
|
2005-04-14 01:58:28 +04:00
|
|
|
/* add attributes as parameters to linked list */
|
2005-04-09 13:47:37 +04:00
|
|
|
for (a = n->properties; a; a = a->next) {
|
2005-04-14 01:58:28 +04:00
|
|
|
if (strcasecmp((const char *) a->name, "src") == 0)
|
|
|
|
continue;
|
|
|
|
if (!a->children || !a->children->content)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
param = talloc(content, struct object_param);
|
|
|
|
if (!param)
|
|
|
|
return false;
|
|
|
|
param->name = talloc_strdup(content, (const char *) a->name);
|
|
|
|
param->value = talloc_strdup(content,
|
|
|
|
(char *) a->children->content);
|
|
|
|
param->type = 0;
|
|
|
|
param->valuetype = "data";
|
|
|
|
param->next = 0;
|
|
|
|
|
|
|
|
if (!param->name || !param->value)
|
2005-04-09 13:47:37 +04:00
|
|
|
return false;
|
|
|
|
|
2005-04-14 01:58:28 +04:00
|
|
|
param->next = params->params;
|
|
|
|
params->params = param;
|
|
|
|
}
|
2005-04-09 13:47:37 +04:00
|
|
|
|
2005-04-14 01:58:28 +04:00
|
|
|
box->object_params = params;
|
2005-03-26 04:12:27 +03:00
|
|
|
|
|
|
|
/* start fetch */
|
2005-04-14 01:58:28 +04:00
|
|
|
return html_fetch_object(content, params->data, box, 0,
|
2005-08-21 02:52:20 +04:00
|
|
|
content->available_width, 1000, false, 0);
|
2005-04-09 13:47:37 +04:00
|
|
|
}
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
/**
|
|
|
|
* \}
|
|
|
|
*/
|
2005-03-26 04:12:27 +03:00
|
|
|
|
|
|
|
|
2005-04-10 21:08:49 +04:00
|
|
|
/**
|
|
|
|
* Get the value of an XML element's attribute.
|
|
|
|
*
|
|
|
|
* \param n xmlNode, of type XML_ELEMENT_NODE
|
|
|
|
* \param attribute name of attribute
|
|
|
|
* \param context talloc context for result buffer
|
|
|
|
* \param value updated to value, if the attribute is present
|
|
|
|
* \return true on success, false if attribute present but memory exhausted
|
|
|
|
*
|
|
|
|
* Note that returning true does not imply that the attribute was found. If the
|
|
|
|
* attribute was not found, *value will be unchanged.
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool box_get_attribute(xmlNode *n, const char *attribute,
|
|
|
|
void *context, char **value)
|
|
|
|
{
|
|
|
|
xmlChar *s = xmlGetProp(n, (const xmlChar *) attribute);
|
|
|
|
if (!s)
|
|
|
|
return true;
|
|
|
|
*value = talloc_strdup(context, s);
|
|
|
|
xmlFree(s);
|
|
|
|
if (!*value)
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Extract a URL from a relative link, handling junk like whitespace and
|
|
|
|
* attempting to read a real URL from "javascript:" links.
|
|
|
|
*
|
|
|
|
* \param rel relative URL taken from page
|
|
|
|
* \param base base for relative URLs
|
|
|
|
* \param result updated to target URL on heap, unchanged if extract failed
|
|
|
|
* \return true on success, false on memory exhaustion
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool box_extract_link(const char *rel, const char *base, char **result)
|
|
|
|
{
|
|
|
|
char *s, *s1, *apos0 = 0, *apos1 = 0, *quot0 = 0, *quot1 = 0;
|
|
|
|
unsigned int i, j, end;
|
|
|
|
url_func_result res;
|
|
|
|
|
|
|
|
s1 = s = malloc(3 * strlen(rel) + 1);
|
|
|
|
if (!s)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
/* copy to s, removing white space and control characters */
|
|
|
|
for (i = 0; rel[i] && isspace(rel[i]); i++)
|
|
|
|
;
|
|
|
|
for (end = strlen(rel); end != i && isspace(rel[end - 1]); end--)
|
|
|
|
;
|
|
|
|
for (j = 0; i != end; i++) {
|
|
|
|
if ((unsigned char) rel[i] < 0x20) {
|
|
|
|
; /* skip control characters */
|
|
|
|
} else if (rel[i] == ' ') {
|
|
|
|
s[j++] = '%';
|
|
|
|
s[j++] = '2';
|
|
|
|
s[j++] = '0';
|
|
|
|
} else {
|
|
|
|
s[j++] = rel[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
s[j] = 0;
|
|
|
|
|
|
|
|
/* extract first quoted string out of "javascript:" link */
|
|
|
|
if (strncmp(s, "javascript:", 11) == 0) {
|
|
|
|
apos0 = strchr(s, '\'');
|
|
|
|
if (apos0)
|
|
|
|
apos1 = strchr(apos0 + 1, '\'');
|
|
|
|
quot0 = strchr(s, '"');
|
|
|
|
if (quot0)
|
|
|
|
quot1 = strchr(quot0 + 1, '"');
|
|
|
|
if (apos0 && apos1 && (!quot0 || !quot1 || apos0 < quot0)) {
|
|
|
|
*apos1 = 0;
|
|
|
|
s1 = apos0 + 1;
|
|
|
|
} else if (quot0 && quot1) {
|
|
|
|
*quot1 = 0;
|
|
|
|
s1 = quot0 + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* construct absolute URL */
|
|
|
|
res = url_join(s1, base, result);
|
|
|
|
free(s);
|
|
|
|
if (res == URL_FUNC_NOMEM)
|
|
|
|
return false;
|
|
|
|
else if (res == URL_FUNC_FAILED)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-03-26 04:12:27 +03:00
|
|
|
/**
|
|
|
|
* Parse a multi-length-list, as defined by HTML 4.01.
|
|
|
|
*
|
2005-04-09 13:47:37 +04:00
|
|
|
* \param s string to parse
|
|
|
|
* \param count updated to number of entries
|
|
|
|
* \param context talloc context block
|
2005-03-26 04:12:27 +03:00
|
|
|
* \return array of struct box_multi_length, or 0 on memory exhaustion
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct box_multi_length *box_parse_multi_lengths(const char *s,
|
2005-04-09 13:47:37 +04:00
|
|
|
unsigned int *count, void *context)
|
2005-03-26 04:12:27 +03:00
|
|
|
{
|
|
|
|
char *end;
|
|
|
|
unsigned int i, n;
|
|
|
|
struct box_multi_length *length;
|
|
|
|
|
|
|
|
for (i = 0, n = 1; s[i]; i++)
|
|
|
|
if (s[i] == ',')
|
|
|
|
n++;
|
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
length = talloc_array(context, struct box_multi_length, n);
|
|
|
|
if (!length)
|
2005-03-26 04:12:27 +03:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
for (i = 0; i != n; i++) {
|
|
|
|
while (isspace(*s))
|
|
|
|
s++;
|
|
|
|
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;
|
|
|
|
}
|