2005-03-26 04:12:27 +03:00
|
|
|
/*
|
|
|
|
* 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>
|
2006-09-02 19:52:41 +04:00
|
|
|
* Copyright 2006 Richard Wilson <info@tinct.net>
|
2008-02-25 19:37:48 +03:00
|
|
|
* Copyright 2008 Michael Drake <tlsa@netsurf-browser.org>
|
2007-08-08 20:16:03 +04:00
|
|
|
*
|
|
|
|
* This file is part of NetSurf, http://www.netsurf-browser.org/
|
|
|
|
*
|
|
|
|
* NetSurf is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; version 2 of the License.
|
|
|
|
*
|
|
|
|
* NetSurf is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2005-03-26 04:12:27 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
/** \file
|
|
|
|
* Conversion of XML tree to box tree (implementation).
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2007-01-30 01:27:15 +03:00
|
|
|
#include <strings.h>
|
2007-05-31 02:39:54 +04:00
|
|
|
#include <libxml/HTMLparser.h>
|
|
|
|
#include <libxml/parserInternals.h>
|
|
|
|
#include "utils/config.h"
|
2010-03-28 16:56:39 +04:00
|
|
|
#include "content/content_protected.h"
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "css/css.h"
|
2009-07-24 03:05:34 +04:00
|
|
|
#include "css/utils.h"
|
|
|
|
#include "css/select.h"
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "desktop/browser.h"
|
|
|
|
#include "desktop/options.h"
|
|
|
|
#include "render/box.h"
|
|
|
|
#include "render/form.h"
|
|
|
|
#include "render/html.h"
|
|
|
|
#include "desktop/gui.h"
|
The core code has always assumed a locale of "C".
Do not change the locale globally, else things will break in weird and
wonderful ways.
Introduce utils/locale.[ch], which provide locale-specific wrappers for various
functions (currently just the <ctype.h> ones).
Fix up the few places I can see that actually require that the underlying
locale is paid attention to.
Some notes:
1) The GTK frontend code has not been touched. It is possible that reading of
numeric values (e.g. from the preferences dialogue) may break with this
change, particularly in locales that use something other than '.' as their
decimal separator.
2) The search code is left unchanged (i.e. assuming a locale of "C").
This may break case insensitive matching of non-ASCII characters.
I doubt that ever actually worked, anyway. In future, it should use
Unicode case conversion to achieve the same effect.
3) The text input handling in the core makes use of isspace() to detect
word boundaries. This is fine for western languages (even in the C locale,
which it's currently assuming). It will, however, break for CJK et. al.
(this has always been the case, rather than being a new issue)
4) text-transform uses locale-specific variants of to{lower,upper}. In future
this should probably be performing Unicode case conversion. This is the
only part of the core code that makes use of locale information.
In future, if you require locale-specific behaviour, do the following:
setlocale(LC_<whatever>, "");
<your operation(s) here>
setlocale(LC_<whatever>, "C");
The first setlocale will change the current locale to the native environment.
The second setlocale will reset the current locale to "C".
Any value other than "" or "C" is probably a bug, unless there's a really
good reason for it.
In the long term, it is expected that all locale-dependent code will reside in
platform frontends -- the core being wholly locale agnostic (though assuming
"C" for things like decimal separators).
svn path=/trunk/netsurf/; revision=4153
2008-05-13 18:37:44 +04:00
|
|
|
#include "utils/locale.h"
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "utils/log.h"
|
|
|
|
#include "utils/messages.h"
|
|
|
|
#include "utils/talloc.h"
|
|
|
|
#include "utils/url.h"
|
|
|
|
#include "utils/utils.h"
|
2005-03-26 04:12:27 +03:00
|
|
|
|
|
|
|
|
|
|
|
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
|
2008-09-16 02:45:44 +04:00
|
|
|
#if defined(WITH_MNG) || defined(WITH_PNG)
|
2006-02-25 21:51:51 +03:00
|
|
|
CONTENT_PNG,
|
2008-09-16 02:45:44 +04:00
|
|
|
#endif
|
|
|
|
#ifdef WITH_MNG
|
2005-03-26 04:12:27 +03:00
|
|
|
CONTENT_JNG,
|
|
|
|
CONTENT_MNG,
|
|
|
|
#endif
|
2008-09-30 16:17:16 +04:00
|
|
|
#if defined(WITH_NS_SVG) || defined(WITH_RSVG)
|
|
|
|
CONTENT_SVG,
|
|
|
|
#endif
|
2008-03-29 16:30:04 +03:00
|
|
|
#if defined(WITH_SPRITE) || defined(WITH_NSSPRITE)
|
2005-03-26 04:12:27 +03:00
|
|
|
CONTENT_SPRITE,
|
|
|
|
#endif
|
|
|
|
#ifdef WITH_DRAW
|
|
|
|
CONTENT_DRAW,
|
2005-12-10 17:31:33 +03:00
|
|
|
#endif
|
|
|
|
#ifdef WITH_ARTWORKS
|
|
|
|
CONTENT_ARTWORKS,
|
2010-10-16 19:26:28 +04:00
|
|
|
#endif
|
|
|
|
#ifdef WITH_WEBP
|
|
|
|
CONTENT_WEBP,
|
2010-10-30 18:23:38 +04:00
|
|
|
#endif
|
|
|
|
#ifdef WITH_AMIGA_ICON
|
|
|
|
CONTENT_AMIGA_ICON,
|
2005-03-26 04:12:27 +03:00
|
|
|
#endif
|
|
|
|
CONTENT_UNKNOWN };
|
|
|
|
|
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";
|
2006-09-02 19:52:41 +04:00
|
|
|
const char *TARGET_BLANK = "_blank";
|
2005-08-21 02:52:20 +04:00
|
|
|
|
2005-03-26 04:12:27 +03:00
|
|
|
static bool convert_xml_to_box(xmlNode *n, struct content *content,
|
2009-07-24 03:05:34 +04:00
|
|
|
const css_computed_style *parent_style,
|
2005-03-26 04:12:27 +03:00
|
|
|
struct box *parent, struct box **inline_container,
|
2009-07-24 03:05:34 +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,
|
2009-07-24 03:05:34 +04:00
|
|
|
const css_computed_style *parent_style,
|
2005-03-28 23:17:06 +04:00
|
|
|
struct box *parent, struct box **inline_container,
|
2009-07-24 03:05:34 +04:00
|
|
|
char *href, const char *target, char *title);
|
2011-01-05 00:52:43 +03:00
|
|
|
void box_construct_after(xmlNode *n, struct content *content,
|
2011-01-05 22:36:05 +03:00
|
|
|
struct box *box, const css_computed_style *after_style);
|
2005-03-28 23:17:06 +04:00
|
|
|
bool box_construct_text(xmlNode *n, struct content *content,
|
2009-07-24 03:05:34 +04:00
|
|
|
const css_computed_style *parent_style,
|
2005-03-28 23:17:06 +04:00
|
|
|
struct box *parent, struct box **inline_container,
|
2005-08-23 02:49:52 +04:00
|
|
|
char *href, const char *target, char *title);
|
2011-01-05 22:36:05 +03:00
|
|
|
static css_select_results * box_get_style(struct content *c,
|
|
|
|
const css_computed_style *parent_style, xmlNode *n);
|
2005-03-26 04:12:27 +03:00
|
|
|
static void box_text_transform(char *s, unsigned int len,
|
2009-08-02 23:19:43 +04:00
|
|
|
enum css_text_transform_e tt);
|
2005-04-09 13:47:37 +04:00
|
|
|
#define BOX_SPECIAL_PARAMS xmlNode *n, struct content *content, \
|
2009-07-24 03:05:34 +04:00
|
|
|
struct box *box, bool *convert_children
|
2005-04-09 13:47:37 +04:00
|
|
|
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_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);
|
2006-09-02 19:52:41 +04:00
|
|
|
static bool box_create_frameset(struct content_html_frames *f, xmlNode *n,
|
|
|
|
struct content *content);
|
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);
|
2006-09-02 19:52:41 +04:00
|
|
|
static struct frame_dimension *box_parse_multi_lengths(const char *s,
|
|
|
|
unsigned int *count);
|
2005-03-26 04:12:27 +03:00
|
|
|
|
|
|
|
/* element_table must be sorted by name */
|
|
|
|
struct element_entry {
|
2006-09-02 19:52:41 +04:00
|
|
|
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},
|
|
|
|
{"frameset", box_frameset},
|
|
|
|
{"iframe", box_iframe},
|
2007-04-02 00:21:58 +04:00
|
|
|
{"image", box_image},
|
2005-03-26 04:12:27 +03:00
|
|
|
{"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;
|
2009-07-24 03:05:34 +04:00
|
|
|
struct box *inline_container = NULL;
|
2005-03-26 04:12:27 +03:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
c->data.html.object_count = 0;
|
|
|
|
c->data.html.object = 0;
|
|
|
|
|
2009-07-24 03:05:34 +04:00
|
|
|
/* The root box's style */
|
|
|
|
if (!convert_xml_to_box(n, c, NULL, &root,
|
|
|
|
&inline_container, 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
|
2009-07-24 03:05:34 +04:00
|
|
|
* this table must be in sync with libcss' css_display enum */
|
2005-03-26 04:12:27 +03:00
|
|
|
static const box_type box_map[] = {
|
|
|
|
0, /*CSS_DISPLAY_INHERIT,*/
|
|
|
|
BOX_INLINE, /*CSS_DISPLAY_INLINE,*/
|
|
|
|
BOX_BLOCK, /*CSS_DISPLAY_BLOCK,*/
|
2006-11-05 15:58:24 +03:00
|
|
|
BOX_BLOCK, /*CSS_DISPLAY_LIST_ITEM,*/
|
2005-03-26 04:12:27 +03:00
|
|
|
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,*/
|
2009-07-24 03:05:34 +04:00
|
|
|
BOX_NONE, /*CSS_DISPLAY_TABLE_COLUMN_GROUP,*/
|
|
|
|
BOX_NONE, /*CSS_DISPLAY_TABLE_COLUMN,*/
|
2005-03-26 04:12:27 +03:00
|
|
|
BOX_TABLE_CELL, /*CSS_DISPLAY_TABLE_CELL,*/
|
2009-07-24 03:05:34 +04:00
|
|
|
BOX_INLINE, /*CSS_DISPLAY_TABLE_CAPTION,*/
|
|
|
|
BOX_NONE /*CSS_DISPLAY_NONE*/
|
2005-03-26 04:12:27 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Recursively construct a box tree from an xml tree and stylesheets.
|
|
|
|
*
|
2006-09-02 19:52:41 +04:00
|
|
|
* \param n fragment of xml tree
|
|
|
|
* \param content content of type CONTENT_HTML that is being processed
|
2009-07-24 03:05:34 +04:00
|
|
|
* \param parent_style style at this point in xml tree, or NULL for root box
|
2006-09-02 19:52:41 +04:00
|
|
|
* \param parent parent in box tree
|
2005-03-26 04:12:27 +03:00
|
|
|
* \param inline_container current inline container box, or 0, updated to
|
2006-09-02 19:52:41 +04:00
|
|
|
* new current inline container on exit
|
|
|
|
* \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,
|
2009-07-24 03:05:34 +04:00
|
|
|
const css_computed_style *parent_style,
|
2005-03-26 04:12:27 +03:00
|
|
|
struct box *parent, struct box **inline_container,
|
2009-07-24 03:05:34 +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,
|
2009-07-24 03:05:34 +04:00
|
|
|
inline_container, 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.
|
|
|
|
*
|
2006-09-02 19:52:41 +04:00
|
|
|
* \param n XML node of type XML_ELEMENT_NODE
|
|
|
|
* \param content content of type CONTENT_HTML that is being processed
|
2009-07-24 03:05:34 +04:00
|
|
|
* \param parent_style style at this point in xml tree, or NULL for root node
|
2006-09-02 19:52:41 +04:00
|
|
|
* \param parent parent in box tree
|
2005-03-28 23:17:06 +04:00
|
|
|
* \param inline_container current inline container box, or 0, updated to
|
2006-09-02 19:52:41 +04:00
|
|
|
* new current inline container on exit
|
|
|
|
* \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,
|
2009-07-24 03:05:34 +04:00
|
|
|
const css_computed_style *parent_style,
|
2005-03-28 23:17:06 +04:00
|
|
|
struct box *parent, struct box **inline_container,
|
2009-07-24 03:05:34 +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;
|
2005-06-06 00:54:37 +04:00
|
|
|
struct box *inline_end;
|
2011-01-05 22:36:05 +03:00
|
|
|
css_select_results *styles = NULL;
|
2005-03-28 23:17:06 +04:00
|
|
|
struct element_entry *element;
|
2005-04-10 21:08:49 +04:00
|
|
|
xmlChar *title0;
|
2005-04-09 13:47:37 +04:00
|
|
|
xmlNode *c;
|
2009-07-24 03:05:34 +04:00
|
|
|
lwc_string *bgimage_uri;
|
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);
|
|
|
|
assert(inline_container);
|
|
|
|
|
2005-03-28 23:17:06 +04:00
|
|
|
gui_multitask();
|
2006-07-04 01:41:25 +04:00
|
|
|
|
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;
|
2006-07-04 01:41:25 +04:00
|
|
|
|
2011-01-05 22:36:05 +03:00
|
|
|
styles = box_get_style(content, parent_style, n);
|
|
|
|
if (!styles)
|
2005-04-09 13:47:37 +04:00
|
|
|
return false;
|
2005-03-28 23:17:06 +04:00
|
|
|
|
|
|
|
/* extract title attribute, if present */
|
|
|
|
if ((title0 = xmlGetProp(n, (const xmlChar *) "title"))) {
|
2008-02-25 20:58:00 +03:00
|
|
|
char *title1 = squash_whitespace((char *) title0);
|
2011-01-05 00:52:43 +03:00
|
|
|
|
2005-03-28 23:17:06 +04:00
|
|
|
xmlFree(title0);
|
2011-01-05 00:52:43 +03:00
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
if (!title1)
|
|
|
|
return false;
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
title = talloc_strdup(content, title1);
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
free(title1);
|
2009-07-24 03:05:34 +04:00
|
|
|
|
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 */
|
2011-01-05 22:36:05 +03:00
|
|
|
box = box_create(styles, styles->styles[CSS_PSEUDO_ELEMENT_NONE], false,
|
|
|
|
href, target, title, id, content);
|
2005-04-09 13:47:37 +04:00
|
|
|
if (!box)
|
|
|
|
return false;
|
2009-07-24 03:05:34 +04:00
|
|
|
/* set box type from computed display */
|
2011-01-05 22:36:05 +03:00
|
|
|
if ((css_computed_position(box->style) == CSS_POSITION_ABSOLUTE ||
|
|
|
|
css_computed_position(box->style) ==
|
|
|
|
CSS_POSITION_FIXED) &&
|
|
|
|
(css_computed_display_static(box->style) ==
|
2009-07-24 03:05:34 +04:00
|
|
|
CSS_DISPLAY_INLINE ||
|
2011-01-05 22:36:05 +03:00
|
|
|
css_computed_display_static(box->style) ==
|
2009-07-24 03:05:34 +04:00
|
|
|
CSS_DISPLAY_INLINE_BLOCK ||
|
2011-01-05 22:36:05 +03:00
|
|
|
css_computed_display_static(box->style) ==
|
2009-07-24 03:05:34 +04:00
|
|
|
CSS_DISPLAY_INLINE_TABLE)) {
|
|
|
|
/* Special case for absolute positioning: make absolute inlines
|
|
|
|
* into inline block so that the boxes are constructed in an
|
|
|
|
* inline container as if they were not absolutely positioned.
|
|
|
|
* Layout expects and handles this. */
|
|
|
|
box->type = box_map[CSS_DISPLAY_INLINE_BLOCK];
|
|
|
|
} else {
|
|
|
|
/* Normal mapping */
|
2011-01-05 22:36:05 +03:00
|
|
|
box->type = box_map[css_computed_display(box->style,
|
2009-07-24 03:05:34 +04:00
|
|
|
n->parent == NULL)];
|
|
|
|
}
|
2005-04-09 13:47:37 +04:00
|
|
|
|
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 */
|
2009-07-24 03:05:34 +04:00
|
|
|
if (!element->convert(n, content, box, &convert_children))
|
2005-04-09 13:47:37 +04:00
|
|
|
return false;
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
href = box->href;
|
2005-08-23 02:49:52 +04:00
|
|
|
target = box->target;
|
2005-03-28 23:17:06 +04:00
|
|
|
}
|
2008-02-25 19:37:48 +03:00
|
|
|
|
2009-07-24 03:05:34 +04:00
|
|
|
if (box->type == BOX_NONE || css_computed_display(box->style,
|
|
|
|
n->parent == NULL) == CSS_DISPLAY_NONE) {
|
2008-02-07 03:50:37 +03:00
|
|
|
/* Free style and invalidate box's style pointer */
|
2011-01-05 22:36:05 +03:00
|
|
|
css_select_results_destroy(styles);
|
|
|
|
box->styles = NULL;
|
2008-02-07 03:50:37 +03:00
|
|
|
box->style = NULL;
|
|
|
|
|
|
|
|
/* If this box has an associated gadget, invalidate the
|
|
|
|
* gadget's box pointer and our pointer to the gadget. */
|
|
|
|
if (box->gadget) {
|
|
|
|
box->gadget->box = NULL;
|
|
|
|
box->gadget = NULL;
|
|
|
|
}
|
|
|
|
|
2007-04-06 16:05:25 +04:00
|
|
|
/* We can't do this, as it will destroy any gadget
|
|
|
|
* associated with the box, thus making any form usage
|
|
|
|
* access freed memory. The box is in the talloc context,
|
|
|
|
* anyway, so will get cleaned up with the content. */
|
|
|
|
/* box_free_box(box); */
|
2005-07-03 00:08:24 +04:00
|
|
|
return true;
|
|
|
|
}
|
2005-03-28 23:17:06 +04:00
|
|
|
|
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 ||
|
2011-01-05 22:36:05 +03:00
|
|
|
css_computed_float(box->style) == CSS_FLOAT_LEFT ||
|
|
|
|
css_computed_float(box->style) == CSS_FLOAT_RIGHT)) {
|
2005-04-09 13:47:37 +04:00
|
|
|
/* this is the first inline in a block: make a container */
|
2011-01-05 22:36:05 +03:00
|
|
|
*inline_container = box_create(NULL, 0, false, 0, 0, 0, 0,
|
|
|
|
content);
|
2005-04-09 13:47:37 +04:00
|
|
|
if (!*inline_container)
|
|
|
|
return false;
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
(*inline_container)->type = BOX_INLINE_CONTAINER;
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
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);
|
2009-07-24 03:05:34 +04:00
|
|
|
|
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)
|
2011-01-05 22:36:05 +03:00
|
|
|
if (!convert_xml_to_box(c, content, box->style,
|
2005-06-06 00:54:37 +04:00
|
|
|
parent, inline_container,
|
2009-07-24 03:05:34 +04:00
|
|
|
href, target, title))
|
2005-06-06 00:54:37 +04:00
|
|
|
return false;
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2011-01-05 22:36:05 +03:00
|
|
|
inline_end = box_create(NULL, box->style, false, href,
|
|
|
|
target, title, id, content);
|
2005-06-06 00:54:37 +04:00
|
|
|
if (!inline_end)
|
2005-04-09 13:47:37 +04:00
|
|
|
return false;
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2005-06-06 00:54:37 +04:00
|
|
|
inline_end->type = BOX_INLINE_END;
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2005-06-06 00:54:37 +04:00
|
|
|
if (*inline_container)
|
|
|
|
box_add_child(*inline_container, inline_end);
|
|
|
|
else
|
|
|
|
box_add_child(box->parent, inline_end);
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2005-06-06 00:54:37 +04:00
|
|
|
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);
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
inline_container_c = 0;
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
for (c = n->children; convert_children && c; c = c->next)
|
2011-01-05 22:36:05 +03:00
|
|
|
if (!convert_xml_to_box(c, content, box->style, box,
|
2005-08-23 02:49:52 +04:00
|
|
|
&inline_container_c,
|
2009-07-24 03:05:34 +04:00
|
|
|
href, target, title))
|
2006-06-26 08:52:34 +04:00
|
|
|
return false;
|
2005-04-09 13:47:37 +04:00
|
|
|
} else {
|
2009-04-29 14:44:20 +04:00
|
|
|
/* list item: compute marker, then treat as non-inline box */
|
2011-01-05 22:36:05 +03:00
|
|
|
if (css_computed_display(box->style, n->parent == NULL) ==
|
2009-07-24 03:05:34 +04:00
|
|
|
CSS_DISPLAY_LIST_ITEM) {
|
|
|
|
lwc_string *image_uri;
|
2006-11-05 15:58:24 +03:00
|
|
|
struct box *marker;
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2011-01-05 22:36:05 +03:00
|
|
|
marker = box_create(NULL, box->style, false, 0, 0,
|
|
|
|
title, 0, content);
|
2006-11-05 15:58:24 +03:00
|
|
|
if (!marker)
|
|
|
|
return false;
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2006-11-05 15:58:24 +03:00
|
|
|
marker->type = BOX_BLOCK;
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2006-11-05 15:58:24 +03:00
|
|
|
/** \todo marker content (list-style-type) */
|
2011-01-05 22:36:05 +03:00
|
|
|
switch (css_computed_list_style_type(box->style)) {
|
2006-11-05 22:50:34 +03:00
|
|
|
case CSS_LIST_STYLE_TYPE_DISC:
|
|
|
|
/* 2022 BULLET */
|
2008-05-26 14:46:45 +04:00
|
|
|
marker->text = (char *) "\342\200\242";
|
2006-11-05 22:50:34 +03:00
|
|
|
marker->length = 3;
|
|
|
|
break;
|
|
|
|
case CSS_LIST_STYLE_TYPE_CIRCLE:
|
2007-05-15 02:57:11 +04:00
|
|
|
/* 25CB WHITE CIRCLE */
|
2008-05-26 14:46:45 +04:00
|
|
|
marker->text = (char *) "\342\227\213";
|
2006-11-05 22:50:34 +03:00
|
|
|
marker->length = 3;
|
|
|
|
break;
|
|
|
|
case CSS_LIST_STYLE_TYPE_SQUARE:
|
2007-05-15 02:57:11 +04:00
|
|
|
/* 25AA BLACK SMALL SQUARE */
|
2008-05-26 14:46:45 +04:00
|
|
|
marker->text = (char *) "\342\226\252";
|
2006-11-05 22:50:34 +03:00
|
|
|
marker->length = 3;
|
|
|
|
break;
|
|
|
|
case CSS_LIST_STYLE_TYPE_DECIMAL:
|
|
|
|
case CSS_LIST_STYLE_TYPE_LOWER_ALPHA:
|
|
|
|
case CSS_LIST_STYLE_TYPE_LOWER_ROMAN:
|
|
|
|
case CSS_LIST_STYLE_TYPE_UPPER_ALPHA:
|
|
|
|
case CSS_LIST_STYLE_TYPE_UPPER_ROMAN:
|
2009-07-24 03:05:34 +04:00
|
|
|
default:
|
2009-04-29 14:44:20 +04:00
|
|
|
if (parent->last) {
|
|
|
|
struct box *last = parent->last;
|
|
|
|
|
|
|
|
/* Drill down into last child of parent
|
|
|
|
* to find the list marker (if any)
|
|
|
|
*
|
|
|
|
* Floated list boxes end up as:
|
|
|
|
*
|
|
|
|
* parent
|
|
|
|
* BOX_INLINE_CONTAINER
|
|
|
|
* BOX_FLOAT_{LEFT,RIGHT}
|
|
|
|
* BOX_BLOCK <-- list box
|
|
|
|
* ...
|
|
|
|
*/
|
|
|
|
while (last != NULL) {
|
|
|
|
if (last->list_marker != NULL)
|
|
|
|
break;
|
|
|
|
|
|
|
|
last = last->last;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (last && last->list_marker) {
|
|
|
|
marker->rows = last->
|
2006-11-05 22:50:34 +03:00
|
|
|
list_marker->rows + 1;
|
2009-04-29 14:44:20 +04:00
|
|
|
}
|
|
|
|
}
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2006-11-05 22:50:34 +03:00
|
|
|
marker->text = talloc_array(content, char, 20);
|
|
|
|
if (!marker->text)
|
|
|
|
return false;
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2006-11-05 22:50:34 +03:00
|
|
|
snprintf(marker->text, 20, "%u.", marker->rows);
|
|
|
|
marker->length = strlen(marker->text);
|
|
|
|
break;
|
|
|
|
case CSS_LIST_STYLE_TYPE_NONE:
|
|
|
|
marker->text = 0;
|
|
|
|
marker->length = 0;
|
|
|
|
break;
|
|
|
|
}
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2011-01-05 22:36:05 +03:00
|
|
|
if (css_computed_list_style_image(box->style,
|
|
|
|
&image_uri) ==
|
2009-07-24 03:05:34 +04:00
|
|
|
CSS_LIST_STYLE_IMAGE_URI &&
|
|
|
|
image_uri != NULL) {
|
2009-07-25 19:47:11 +04:00
|
|
|
if (!html_fetch_object(content,
|
|
|
|
lwc_string_data(image_uri),
|
2011-01-05 22:36:05 +03:00
|
|
|
marker, image_types,
|
2010-09-19 15:27:43 +04:00
|
|
|
content->available_width,
|
2006-11-05 15:58:24 +03:00
|
|
|
1000, false))
|
|
|
|
return false;
|
|
|
|
}
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2006-11-05 15:58:24 +03:00
|
|
|
box->list_marker = marker;
|
|
|
|
marker->parent = box;
|
|
|
|
}
|
|
|
|
|
2009-04-29 14:44:20 +04:00
|
|
|
/* float: insert a float box between the parent and
|
|
|
|
* current node. Note: new parent will be the float */
|
2011-01-05 22:36:05 +03:00
|
|
|
if (css_computed_float(box->style) == CSS_FLOAT_LEFT ||
|
|
|
|
css_computed_float(box->style) ==
|
|
|
|
CSS_FLOAT_RIGHT) {
|
|
|
|
parent = box_create(NULL, 0, false, href, target, title,
|
|
|
|
0, content);
|
2009-04-29 14:44:20 +04:00
|
|
|
if (!parent)
|
|
|
|
return false;
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2011-01-05 22:36:05 +03:00
|
|
|
if (css_computed_float(box->style) == CSS_FLOAT_LEFT)
|
2009-04-29 14:44:20 +04:00
|
|
|
parent->type = BOX_FLOAT_LEFT;
|
|
|
|
else
|
|
|
|
parent->type = BOX_FLOAT_RIGHT;
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2009-04-29 14:44:20 +04:00
|
|
|
box_add_child(*inline_container, parent);
|
|
|
|
}
|
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
/* non-inline box: add to tree and recurse */
|
|
|
|
box_add_child(parent, box);
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2005-03-28 23:17:06 +04:00
|
|
|
inline_container_c = 0;
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
for (c = n->children; convert_children && c; c = c->next)
|
2011-01-05 22:36:05 +03:00
|
|
|
if (!convert_xml_to_box(c, content, box->style, box,
|
2005-08-23 02:49:52 +04:00
|
|
|
&inline_container_c,
|
2009-07-24 03:05:34 +04:00
|
|
|
href, target, title))
|
2005-04-09 13:47:37 +04:00
|
|
|
return false;
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2011-01-05 22:36:05 +03:00
|
|
|
if (css_computed_float(box->style) == CSS_FLOAT_NONE)
|
2005-04-09 13:47:37 +04:00
|
|
|
/* 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"))) {
|
2006-09-02 23:03:49 +04:00
|
|
|
if (isdigit(s[0])) {
|
|
|
|
box->columns = strtol(s, NULL, 10);
|
|
|
|
}
|
2005-03-28 23:17:06 +04:00
|
|
|
xmlFree(s);
|
|
|
|
}
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
if ((s = (char *) xmlGetProp(n, (const xmlChar *) "rowspan"))) {
|
2006-09-02 23:03:49 +04:00
|
|
|
if (isdigit(s[0])) {
|
|
|
|
box->rows = strtol(s, NULL, 10);
|
|
|
|
}
|
2005-03-28 23:17:06 +04:00
|
|
|
xmlFree(s);
|
2005-03-26 04:12:27 +03:00
|
|
|
}
|
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
/* fetch any background image for this box */
|
2011-01-05 22:36:05 +03:00
|
|
|
if (css_computed_background_image(box->style, &bgimage_uri) ==
|
2011-01-05 00:52:43 +03:00
|
|
|
CSS_BACKGROUND_IMAGE_IMAGE &&
|
2009-07-24 03:05:34 +04:00
|
|
|
bgimage_uri != NULL) {
|
2011-01-05 00:52:43 +03:00
|
|
|
if (!html_fetch_object(content,
|
2009-07-25 19:47:11 +04:00
|
|
|
lwc_string_data(bgimage_uri),
|
2005-04-09 13:47:37 +04:00
|
|
|
box, image_types, content->available_width,
|
2006-09-02 19:52:41 +04:00
|
|
|
1000, true))
|
2005-03-28 23:17:06 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-01-05 00:52:43 +03:00
|
|
|
/* handle the :after pseudo element */
|
|
|
|
|
|
|
|
/* TODO: Replace with true implementation.
|
|
|
|
* Currently we only implement enough of this to support the
|
|
|
|
* 'clearfix' hack, which is in widespread use and the layout
|
|
|
|
* of many sites depend on. As such, only bother if box is a
|
|
|
|
* block for now. */
|
|
|
|
if (box->type == BOX_BLOCK) {
|
2011-01-05 22:36:05 +03:00
|
|
|
box_construct_after(n, content, box,
|
|
|
|
box->styles->styles[CSS_PSEUDO_ELEMENT_AFTER]);
|
2011-01-05 00:52:43 +03:00
|
|
|
}
|
|
|
|
|
2005-03-28 23:17:06 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-05 00:52:43 +03:00
|
|
|
/**
|
|
|
|
* Construct the box required for an :after pseudo element.
|
|
|
|
*
|
2011-01-05 22:36:05 +03:00
|
|
|
* \param n XML node of type XML_ELEMENT_NODE
|
|
|
|
* \param content content of type CONTENT_HTML that is being processed
|
|
|
|
* \param box box which may have an :after s
|
|
|
|
* \param after_style complete computed style for after pseudo element
|
2011-01-05 00:52:43 +03:00
|
|
|
*
|
|
|
|
* TODO:
|
|
|
|
* This is currently incomplete. It just does enough to support the clearfix
|
|
|
|
* hack. ( http://www.positioniseverything.net/easyclearing.html )
|
|
|
|
*
|
|
|
|
* To determine if an element has a pseudo element, we select for it and test to
|
|
|
|
* see if the returned style's content property is set to normal.
|
|
|
|
*
|
|
|
|
* We don't actually support generated content yet.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void box_construct_after(xmlNode *n, struct content *content,
|
2011-01-05 22:36:05 +03:00
|
|
|
struct box *box, const css_computed_style *after_style)
|
2011-01-05 00:52:43 +03:00
|
|
|
{
|
|
|
|
struct box *after = 0;
|
|
|
|
const css_computed_content_item *c_item;
|
|
|
|
|
2011-01-05 22:36:05 +03:00
|
|
|
if (after_style == NULL ||
|
|
|
|
css_computed_content(after_style, &c_item) ==
|
|
|
|
CSS_CONTENT_NORMAL) {
|
|
|
|
/* No pseudo element */
|
2011-01-05 00:52:43 +03:00
|
|
|
return;
|
2011-01-05 22:36:05 +03:00
|
|
|
}
|
2011-01-05 00:52:43 +03:00
|
|
|
|
|
|
|
/* create box for this element */
|
2011-01-05 22:36:05 +03:00
|
|
|
if (css_computed_display(after_style, n->parent == NULL) ==
|
2011-01-05 00:52:43 +03:00
|
|
|
CSS_DISPLAY_BLOCK) {
|
2011-01-05 22:36:05 +03:00
|
|
|
/* currently only support block level after elements */
|
|
|
|
|
|
|
|
/** \todo Not wise to drop const from the computed style */
|
|
|
|
after = box_create(NULL, (css_computed_style *)after_style,
|
|
|
|
false, NULL, NULL, NULL, NULL, content);
|
|
|
|
if (after == NULL) {
|
2011-01-05 00:52:43 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* set box type from computed display */
|
2011-02-16 02:08:38 +03:00
|
|
|
after->type = box_map[css_computed_display(
|
|
|
|
after_style, n->parent == NULL)];
|
2011-01-05 00:52:43 +03:00
|
|
|
|
|
|
|
box_add_child(box, after);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-03-28 23:17:06 +04:00
|
|
|
/**
|
|
|
|
* Construct the box tree for an XML text node.
|
|
|
|
*
|
2006-09-02 19:52:41 +04:00
|
|
|
* \param n XML node of type XML_TEXT_NODE
|
|
|
|
* \param content content of type CONTENT_HTML that is being processed
|
2005-03-28 23:17:06 +04:00
|
|
|
* \param parent_style style at this point in xml tree
|
2006-09-02 19:52:41 +04:00
|
|
|
* \param parent parent in box tree
|
2005-03-28 23:17:06 +04:00
|
|
|
* \param inline_container current inline container box, or 0, updated to
|
2006-09-02 19:52:41 +04:00
|
|
|
* new current inline container on exit
|
|
|
|
* \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,
|
2009-07-24 03:05:34 +04:00
|
|
|
const css_computed_style *parent_style,
|
2005-03-28 23:17:06 +04:00
|
|
|
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);
|
|
|
|
|
2009-07-24 03:05:34 +04:00
|
|
|
if (css_computed_white_space(parent_style) == CSS_WHITE_SPACE_NORMAL ||
|
|
|
|
css_computed_white_space(parent_style) ==
|
|
|
|
CSS_WHITE_SPACE_NOWRAP) {
|
2008-02-25 20:58:00 +03:00
|
|
|
char *text = squash_whitespace((char *) n->content);
|
2005-03-26 04:12:27 +03:00
|
|
|
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) {
|
2006-11-05 15:58:24 +03:00
|
|
|
if ((*inline_container)->last == 0) {
|
|
|
|
LOG(("empty inline_container %p",
|
|
|
|
*inline_container));
|
|
|
|
while (parent->parent &&
|
|
|
|
parent->parent->parent)
|
|
|
|
parent = parent->parent;
|
2007-08-20 06:39:49 +04:00
|
|
|
box_dump(stderr, parent, 0);
|
2006-11-05 15:58:24 +03:00
|
|
|
}
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2005-03-26 04:12:27 +03:00
|
|
|
assert((*inline_container)->last != 0);
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2011-03-01 23:00:41 +03:00
|
|
|
(*inline_container)->last->space =
|
|
|
|
UNKNOWN_WIDTH;
|
2005-03-26 04:12:27 +03:00
|
|
|
}
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2005-03-26 04:12:27 +03:00
|
|
|
free(text);
|
2009-07-24 03:05:34 +04:00
|
|
|
|
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 */
|
2011-01-05 22:36:05 +03:00
|
|
|
*inline_container = box_create(NULL, 0, false, 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
|
|
|
}
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2005-03-26 04:12:27 +03:00
|
|
|
(*inline_container)->type = BOX_INLINE_CONTAINER;
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2005-03-26 04:12:27 +03:00
|
|
|
box_add_child(parent, *inline_container);
|
|
|
|
}
|
|
|
|
|
2009-07-24 03:05:34 +04:00
|
|
|
/** \todo Dropping const here is not clever */
|
2011-01-05 22:36:05 +03:00
|
|
|
box = box_create(NULL, (css_computed_style *) parent_style,
|
|
|
|
false, 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
|
|
|
}
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2005-05-23 01:50:14 +04:00
|
|
|
box->type = BOX_TEXT;
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
box->text = talloc_strdup(content, text);
|
|
|
|
free(text);
|
|
|
|
if (!box->text)
|
|
|
|
return false;
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
box->length = strlen(box->text);
|
2009-07-24 03:05:34 +04:00
|
|
|
|
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] == ' ') {
|
2011-03-01 23:00:41 +03:00
|
|
|
box->space = UNKNOWN_WIDTH;
|
2005-03-26 04:12:27 +03:00
|
|
|
box->length--;
|
|
|
|
}
|
2009-07-24 03:05:34 +04:00
|
|
|
|
|
|
|
if (css_computed_text_transform(parent_style) !=
|
|
|
|
CSS_TEXT_TRANSFORM_NONE)
|
2005-03-26 04:12:27 +03:00
|
|
|
box_text_transform(box->text, box->length,
|
2009-07-24 03:05:34 +04:00
|
|
|
css_computed_text_transform(parent_style));
|
|
|
|
|
|
|
|
if (css_computed_white_space(parent_style) ==
|
|
|
|
CSS_WHITE_SPACE_NOWRAP) {
|
2005-03-26 04:12:27 +03:00
|
|
|
unsigned int i;
|
2009-07-24 03:05:34 +04:00
|
|
|
|
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 */
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2005-03-26 04:12:27 +03:00
|
|
|
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);
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2005-03-26 04:12:27 +03:00
|
|
|
if (box->text[0] == ' ') {
|
|
|
|
box->length--;
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2005-03-26 04:12:27 +03:00
|
|
|
memmove(box->text, &box->text[1], box->length);
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2005-03-26 04:12:27 +03:00
|
|
|
if (box->prev != NULL)
|
2011-03-01 23:00:41 +03:00
|
|
|
box->prev->space = UNKNOWN_WIDTH;
|
2005-03-26 04:12:27 +03:00
|
|
|
}
|
|
|
|
|
2005-03-28 23:17:06 +04:00
|
|
|
} else {
|
2005-03-26 04:12:27 +03:00
|
|
|
/* white-space: pre */
|
2008-02-25 20:58:00 +03:00
|
|
|
char *text = cnv_space2nbsp((char *) n->content);
|
2005-03-26 04:12:27 +03:00
|
|
|
char *current;
|
2009-08-02 23:19:43 +04:00
|
|
|
enum css_white_space_e white_space =
|
2009-07-24 03:05:34 +04:00
|
|
|
css_computed_white_space(parent_style);
|
|
|
|
|
2005-03-26 04:12:27 +03:00
|
|
|
/* note: pre-wrap/pre-line are unimplemented */
|
2009-07-24 03:05:34 +04:00
|
|
|
assert(white_space == CSS_WHITE_SPACE_PRE ||
|
|
|
|
white_space == CSS_WHITE_SPACE_PRE_LINE ||
|
|
|
|
white_space == CSS_WHITE_SPACE_PRE_WRAP);
|
|
|
|
|
2005-03-26 04:12:27 +03:00
|
|
|
if (!text)
|
2005-04-09 13:47:37 +04:00
|
|
|
return false;
|
2009-07-24 03:05:34 +04:00
|
|
|
|
|
|
|
if (css_computed_text_transform(parent_style) !=
|
|
|
|
CSS_TEXT_TRANSFORM_NONE)
|
2005-03-26 04:12:27 +03:00
|
|
|
box_text_transform(text, strlen(text),
|
2009-07-24 03:05:34 +04:00
|
|
|
css_computed_text_transform(parent_style));
|
|
|
|
|
2005-03-26 04:12:27 +03:00
|
|
|
current = text;
|
2006-07-04 01:41:25 +04:00
|
|
|
|
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
|
|
|
}
|
2006-07-04 01:41:25 +04:00
|
|
|
|
2005-03-26 04:12:27 +03:00
|
|
|
do {
|
|
|
|
size_t len = strcspn(current, "\r\n");
|
|
|
|
char old = current[len];
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2005-03-26 04:12:27 +03:00
|
|
|
current[len] = 0;
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2005-03-26 04:12:27 +03:00
|
|
|
if (!*inline_container) {
|
2011-01-05 22:36:05 +03:00
|
|
|
*inline_container = box_create(NULL, 0, false,
|
|
|
|
0, 0, 0, 0, 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
|
|
|
}
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2005-03-26 04:12:27 +03:00
|
|
|
(*inline_container)->type =
|
|
|
|
BOX_INLINE_CONTAINER;
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2005-03-26 04:12:27 +03:00
|
|
|
box_add_child(parent, *inline_container);
|
|
|
|
}
|
2009-07-24 03:05:34 +04:00
|
|
|
|
|
|
|
/** \todo Dropping const isn't clever */
|
2011-01-05 22:36:05 +03:00
|
|
|
box = box_create(NULL,
|
|
|
|
(css_computed_style *) parent_style,
|
|
|
|
false, 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
|
|
|
}
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2005-05-23 01:50:14 +04:00
|
|
|
box->type = BOX_TEXT;
|
2009-07-24 03:05:34 +04:00
|
|
|
|
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
|
|
|
}
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2005-03-26 04:12:27 +03:00
|
|
|
box->length = strlen(box->text);
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2005-03-26 04:12:27 +03:00
|
|
|
box_add_child(*inline_container, box);
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2005-03-26 04:12:27 +03:00
|
|
|
current[len] = old;
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2005-03-26 04:12:27 +03:00
|
|
|
current += len;
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2005-03-26 04:12:27 +03:00
|
|
|
if (current[0] == '\r' && current[1] == '\n') {
|
|
|
|
current += 2;
|
|
|
|
*inline_container = 0;
|
|
|
|
} else if (current[0] != 0) {
|
|
|
|
current++;
|
|
|
|
*inline_container = 0;
|
|
|
|
}
|
|
|
|
} while (*current);
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2005-03-26 04:12:27 +03:00
|
|
|
free(text);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the style for an element.
|
|
|
|
*
|
2011-01-05 00:52:43 +03:00
|
|
|
* \param c content of type CONTENT_HTML that is being processed
|
|
|
|
* \param parent_style style at this point in xml tree, or NULL for root
|
|
|
|
* \param n node in xml tree
|
2009-07-24 03:05:34 +04:00
|
|
|
* \return the new style, or NULL on memory exhaustion
|
2005-03-26 04:12:27 +03:00
|
|
|
*/
|
2011-01-05 22:36:05 +03:00
|
|
|
css_select_results *box_get_style(struct content *c,
|
|
|
|
const css_computed_style *parent_style, xmlNode *n)
|
2005-03-26 04:12:27 +03:00
|
|
|
{
|
|
|
|
char *s;
|
2011-01-05 22:36:05 +03:00
|
|
|
int pseudo_element;
|
2011-01-06 14:11:47 +03:00
|
|
|
css_error error;
|
2009-07-24 03:05:34 +04:00
|
|
|
css_stylesheet *inline_style = NULL;
|
2011-01-05 22:36:05 +03:00
|
|
|
css_select_results *styles;
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2009-07-24 03:05:34 +04:00
|
|
|
/* Firstly, construct inline stylesheet, if any */
|
2011-01-06 01:38:37 +03:00
|
|
|
if ((s = (char *) xmlGetProp(n, (const xmlChar *) "style"))) {
|
2009-07-24 03:05:34 +04:00
|
|
|
inline_style = nscss_create_inline_style(
|
|
|
|
(uint8_t *) s, strlen(s),
|
2010-03-28 16:56:39 +04:00
|
|
|
c->data.html.encoding, content__get_url(c),
|
2009-11-15 13:10:00 +03:00
|
|
|
c->data.html.quirks != BINDING_QUIRKS_MODE_NONE,
|
2010-04-30 11:00:58 +04:00
|
|
|
box_style_alloc, NULL);
|
2005-03-26 04:12:27 +03:00
|
|
|
|
|
|
|
xmlFree(s);
|
|
|
|
|
2009-07-24 03:05:34 +04:00
|
|
|
if (inline_style == NULL)
|
|
|
|
return NULL;
|
2008-02-25 19:37:48 +03:00
|
|
|
}
|
|
|
|
|
2009-07-24 03:05:34 +04:00
|
|
|
/* Select partial style for element */
|
2011-01-05 22:36:05 +03:00
|
|
|
styles = nscss_get_style(c, n, CSS_MEDIA_SCREEN, inline_style,
|
|
|
|
box_style_alloc, NULL);
|
2005-04-28 05:17:52 +04:00
|
|
|
|
2009-07-24 03:05:34 +04:00
|
|
|
/* No longer need inline style */
|
|
|
|
if (inline_style != NULL)
|
|
|
|
css_stylesheet_destroy(inline_style);
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2009-07-24 03:05:34 +04:00
|
|
|
/* Failed selecting partial style -- bail out */
|
2011-01-05 23:14:34 +03:00
|
|
|
if (styles == NULL)
|
2009-07-24 03:05:34 +04:00
|
|
|
return NULL;
|
2005-03-28 23:17:06 +04:00
|
|
|
|
2009-07-24 03:05:34 +04:00
|
|
|
/* If there's a parent style, compose with partial to obtain
|
|
|
|
* complete computed style for element */
|
|
|
|
if (parent_style != NULL) {
|
2008-02-25 19:37:48 +03:00
|
|
|
|
2011-01-05 22:36:05 +03:00
|
|
|
/* Complete the computed style, by composing with the parent
|
|
|
|
* element's style */
|
|
|
|
error = css_computed_style_compose(parent_style,
|
|
|
|
styles->styles[CSS_PSEUDO_ELEMENT_NONE],
|
|
|
|
nscss_compute_font_size, NULL,
|
|
|
|
styles->styles[CSS_PSEUDO_ELEMENT_NONE]);
|
2009-07-24 03:05:34 +04:00
|
|
|
if (error != CSS_OK) {
|
2011-01-05 22:36:05 +03:00
|
|
|
css_select_results_destroy(styles);
|
2009-07-24 03:05:34 +04:00
|
|
|
return NULL;
|
2008-02-25 19:37:48 +03:00
|
|
|
}
|
2011-01-05 22:36:05 +03:00
|
|
|
}
|
2008-02-25 19:37:48 +03:00
|
|
|
|
2011-01-05 22:36:05 +03:00
|
|
|
for (pseudo_element = CSS_PSEUDO_ELEMENT_NONE + 1;
|
|
|
|
pseudo_element < CSS_PSEUDO_ELEMENT_COUNT;
|
|
|
|
pseudo_element++) {
|
2011-01-06 14:11:47 +03:00
|
|
|
|
|
|
|
if (pseudo_element == CSS_PSEUDO_ELEMENT_FIRST_LETTER ||
|
|
|
|
pseudo_element == CSS_PSEUDO_ELEMENT_FIRST_LINE)
|
|
|
|
/* TODO: Handle first-line and first-letter pseudo
|
|
|
|
* element computed style completion */
|
|
|
|
continue;
|
2011-01-05 22:36:05 +03:00
|
|
|
|
|
|
|
if (styles->styles[pseudo_element] == NULL)
|
|
|
|
/* There were no rules concerning this pseudo element */
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* Complete the pseudo element's computed style, by composing
|
|
|
|
* with the base element's style */
|
|
|
|
error = css_computed_style_compose(
|
|
|
|
styles->styles[CSS_PSEUDO_ELEMENT_NONE],
|
|
|
|
styles->styles[pseudo_element],
|
|
|
|
nscss_compute_font_size, NULL,
|
|
|
|
styles->styles[pseudo_element]);
|
|
|
|
if (error != CSS_OK) {
|
|
|
|
/* TODO: perhaps this shouldn't be quite so
|
|
|
|
* catastrophic? */
|
|
|
|
css_select_results_destroy(styles);
|
|
|
|
return NULL;
|
|
|
|
}
|
2008-02-25 19:37:48 +03:00
|
|
|
}
|
|
|
|
|
2011-01-05 22:36:05 +03:00
|
|
|
return styles;
|
2005-03-26 04:12:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Apply the CSS text-transform property to given text for its ASCII chars.
|
|
|
|
*
|
2006-09-02 19:52:41 +04:00
|
|
|
* \param s string to transform
|
2005-03-26 04:12:27 +03:00
|
|
|
* \param len length of s
|
2006-09-02 19:52:41 +04:00
|
|
|
* \param tt transform type
|
2005-03-26 04:12:27 +03:00
|
|
|
*/
|
|
|
|
|
2009-08-02 23:19:43 +04:00
|
|
|
void box_text_transform(char *s, unsigned int len, enum css_text_transform_e tt)
|
2005-03-26 04:12:27 +03:00
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
if (len == 0)
|
|
|
|
return;
|
|
|
|
switch (tt) {
|
|
|
|
case CSS_TEXT_TRANSFORM_UPPERCASE:
|
|
|
|
for (i = 0; i < len; ++i)
|
2008-02-25 20:58:00 +03:00
|
|
|
if ((unsigned char) s[i] < 0x80)
|
The core code has always assumed a locale of "C".
Do not change the locale globally, else things will break in weird and
wonderful ways.
Introduce utils/locale.[ch], which provide locale-specific wrappers for various
functions (currently just the <ctype.h> ones).
Fix up the few places I can see that actually require that the underlying
locale is paid attention to.
Some notes:
1) The GTK frontend code has not been touched. It is possible that reading of
numeric values (e.g. from the preferences dialogue) may break with this
change, particularly in locales that use something other than '.' as their
decimal separator.
2) The search code is left unchanged (i.e. assuming a locale of "C").
This may break case insensitive matching of non-ASCII characters.
I doubt that ever actually worked, anyway. In future, it should use
Unicode case conversion to achieve the same effect.
3) The text input handling in the core makes use of isspace() to detect
word boundaries. This is fine for western languages (even in the C locale,
which it's currently assuming). It will, however, break for CJK et. al.
(this has always been the case, rather than being a new issue)
4) text-transform uses locale-specific variants of to{lower,upper}. In future
this should probably be performing Unicode case conversion. This is the
only part of the core code that makes use of locale information.
In future, if you require locale-specific behaviour, do the following:
setlocale(LC_<whatever>, "");
<your operation(s) here>
setlocale(LC_<whatever>, "C");
The first setlocale will change the current locale to the native environment.
The second setlocale will reset the current locale to "C".
Any value other than "" or "C" is probably a bug, unless there's a really
good reason for it.
In the long term, it is expected that all locale-dependent code will reside in
platform frontends -- the core being wholly locale agnostic (though assuming
"C" for things like decimal separators).
svn path=/trunk/netsurf/; revision=4153
2008-05-13 18:37:44 +04:00
|
|
|
s[i] = ls_toupper(s[i]);
|
2005-03-26 04:12:27 +03:00
|
|
|
break;
|
|
|
|
case CSS_TEXT_TRANSFORM_LOWERCASE:
|
|
|
|
for (i = 0; i < len; ++i)
|
2008-02-25 20:58:00 +03:00
|
|
|
if ((unsigned char) s[i] < 0x80)
|
The core code has always assumed a locale of "C".
Do not change the locale globally, else things will break in weird and
wonderful ways.
Introduce utils/locale.[ch], which provide locale-specific wrappers for various
functions (currently just the <ctype.h> ones).
Fix up the few places I can see that actually require that the underlying
locale is paid attention to.
Some notes:
1) The GTK frontend code has not been touched. It is possible that reading of
numeric values (e.g. from the preferences dialogue) may break with this
change, particularly in locales that use something other than '.' as their
decimal separator.
2) The search code is left unchanged (i.e. assuming a locale of "C").
This may break case insensitive matching of non-ASCII characters.
I doubt that ever actually worked, anyway. In future, it should use
Unicode case conversion to achieve the same effect.
3) The text input handling in the core makes use of isspace() to detect
word boundaries. This is fine for western languages (even in the C locale,
which it's currently assuming). It will, however, break for CJK et. al.
(this has always been the case, rather than being a new issue)
4) text-transform uses locale-specific variants of to{lower,upper}. In future
this should probably be performing Unicode case conversion. This is the
only part of the core code that makes use of locale information.
In future, if you require locale-specific behaviour, do the following:
setlocale(LC_<whatever>, "");
<your operation(s) here>
setlocale(LC_<whatever>, "C");
The first setlocale will change the current locale to the native environment.
The second setlocale will reset the current locale to "C".
Any value other than "" or "C" is probably a bug, unless there's a really
good reason for it.
In the long term, it is expected that all locale-dependent code will reside in
platform frontends -- the core being wholly locale agnostic (though assuming
"C" for things like decimal separators).
svn path=/trunk/netsurf/; revision=4153
2008-05-13 18:37:44 +04:00
|
|
|
s[i] = ls_tolower(s[i]);
|
2005-03-26 04:12:27 +03:00
|
|
|
break;
|
|
|
|
case CSS_TEXT_TRANSFORM_CAPITALIZE:
|
2008-02-25 20:58:00 +03:00
|
|
|
if ((unsigned char) s[0] < 0x80)
|
The core code has always assumed a locale of "C".
Do not change the locale globally, else things will break in weird and
wonderful ways.
Introduce utils/locale.[ch], which provide locale-specific wrappers for various
functions (currently just the <ctype.h> ones).
Fix up the few places I can see that actually require that the underlying
locale is paid attention to.
Some notes:
1) The GTK frontend code has not been touched. It is possible that reading of
numeric values (e.g. from the preferences dialogue) may break with this
change, particularly in locales that use something other than '.' as their
decimal separator.
2) The search code is left unchanged (i.e. assuming a locale of "C").
This may break case insensitive matching of non-ASCII characters.
I doubt that ever actually worked, anyway. In future, it should use
Unicode case conversion to achieve the same effect.
3) The text input handling in the core makes use of isspace() to detect
word boundaries. This is fine for western languages (even in the C locale,
which it's currently assuming). It will, however, break for CJK et. al.
(this has always been the case, rather than being a new issue)
4) text-transform uses locale-specific variants of to{lower,upper}. In future
this should probably be performing Unicode case conversion. This is the
only part of the core code that makes use of locale information.
In future, if you require locale-specific behaviour, do the following:
setlocale(LC_<whatever>, "");
<your operation(s) here>
setlocale(LC_<whatever>, "C");
The first setlocale will change the current locale to the native environment.
The second setlocale will reset the current locale to "C".
Any value other than "" or "C" is probably a bug, unless there's a really
good reason for it.
In the long term, it is expected that all locale-dependent code will reside in
platform frontends -- the core being wholly locale agnostic (though assuming
"C" for things like decimal separators).
svn path=/trunk/netsurf/; revision=4153
2008-05-13 18:37:44 +04:00
|
|
|
s[0] = ls_toupper(s[0]);
|
2005-03-26 04:12:27 +03:00
|
|
|
for (i = 1; i < len; ++i)
|
2008-02-27 01:31:38 +03:00
|
|
|
if ((unsigned char) s[i] < 0x80 &&
|
The core code has always assumed a locale of "C".
Do not change the locale globally, else things will break in weird and
wonderful ways.
Introduce utils/locale.[ch], which provide locale-specific wrappers for various
functions (currently just the <ctype.h> ones).
Fix up the few places I can see that actually require that the underlying
locale is paid attention to.
Some notes:
1) The GTK frontend code has not been touched. It is possible that reading of
numeric values (e.g. from the preferences dialogue) may break with this
change, particularly in locales that use something other than '.' as their
decimal separator.
2) The search code is left unchanged (i.e. assuming a locale of "C").
This may break case insensitive matching of non-ASCII characters.
I doubt that ever actually worked, anyway. In future, it should use
Unicode case conversion to achieve the same effect.
3) The text input handling in the core makes use of isspace() to detect
word boundaries. This is fine for western languages (even in the C locale,
which it's currently assuming). It will, however, break for CJK et. al.
(this has always been the case, rather than being a new issue)
4) text-transform uses locale-specific variants of to{lower,upper}. In future
this should probably be performing Unicode case conversion. This is the
only part of the core code that makes use of locale information.
In future, if you require locale-specific behaviour, do the following:
setlocale(LC_<whatever>, "");
<your operation(s) here>
setlocale(LC_<whatever>, "C");
The first setlocale will change the current locale to the native environment.
The second setlocale will reset the current locale to "C".
Any value other than "" or "C" is probably a bug, unless there's a really
good reason for it.
In the long term, it is expected that all locale-dependent code will reside in
platform frontends -- the core being wholly locale agnostic (though assuming
"C" for things like decimal separators).
svn path=/trunk/netsurf/; revision=4153
2008-05-13 18:37:44 +04:00
|
|
|
ls_isspace(s[i - 1]))
|
|
|
|
s[i] = ls_toupper(s[i]);
|
2005-03-26 04:12:27 +03:00
|
|
|
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)
|
|
|
|
{
|
2009-07-24 03:05:34 +04:00
|
|
|
css_color color;
|
|
|
|
|
2011-01-29 22:22:12 +03:00
|
|
|
css_computed_background_color(box->style, &color);
|
|
|
|
if (nscss_color_is_transparent(color))
|
2009-07-24 03:05:34 +04:00
|
|
|
content->data.html.background_colour = NS_TRANSPARENT;
|
|
|
|
else
|
|
|
|
content->data.html.background_colour = nscss_color_to_ns(color);
|
|
|
|
|
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
|
|
|
/**
|
|
|
|
* 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"))) {
|
2008-02-25 20:58:00 +03:00
|
|
|
if (!strcasecmp((const char *) s, "_blank"))
|
2006-09-02 19:52:41 +04:00
|
|
|
box->target = TARGET_BLANK;
|
2008-02-25 20:58:00 +03:00
|
|
|
else if (!strcasecmp((const char *) s, "_top"))
|
2005-08-21 02:52:20 +04:00
|
|
|
box->target = TARGET_TOP;
|
2008-02-25 20:58:00 +03:00
|
|
|
else if (!strcasecmp((const char *) s, "_parent"))
|
2005-08-21 02:52:20 +04:00
|
|
|
box->target = TARGET_PARENT;
|
2008-02-25 20:58:00 +03:00
|
|
|
else if (!strcasecmp((const char *) s, "_self"))
|
2005-08-21 02:52:20 +04:00
|
|
|
/* the default may have been overridden by a
|
|
|
|
* <base target=...>, so this is different to 0 */
|
|
|
|
box->target = TARGET_SELF;
|
2009-06-08 13:34:58 +04:00
|
|
|
else {
|
|
|
|
/* 6.16 says that frame names must begin with [a-zA-Z]
|
|
|
|
* This doesn't match reality, so just take anything */
|
2008-02-25 20:58:00 +03:00
|
|
|
box->target = talloc_strdup(content, (const char *) s);
|
2005-08-21 02:52:20 +04:00
|
|
|
if (!box->target) {
|
|
|
|
xmlFree(s);
|
|
|
|
return false;
|
|
|
|
}
|
2006-09-02 19:52:41 +04:00
|
|
|
}
|
2005-08-21 02:52:20 +04:00
|
|
|
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
|
|
|
|
2009-07-24 03:05:34 +04:00
|
|
|
if (box->style && css_computed_display(box->style,
|
|
|
|
n->parent == NULL) == CSS_DISPLAY_NONE)
|
2007-04-07 03:48:26 +04:00
|
|
|
return true;
|
|
|
|
|
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"))) {
|
2008-02-25 20:58:00 +03:00
|
|
|
s = squash_whitespace((const char *) alt);
|
2005-04-14 01:58:28 +04:00
|
|
|
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,
|
2006-09-02 19:52:41 +04:00
|
|
|
content->available_width, 1000, false);
|
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-03-26 04:12:27 +03:00
|
|
|
|
2009-07-24 03:05:34 +04:00
|
|
|
if (box->style && css_computed_display(box->style,
|
|
|
|
n->parent == NULL) == CSS_DISPLAY_NONE)
|
2007-04-07 03:48:26 +04:00
|
|
|
return true;
|
|
|
|
|
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;
|
|
|
|
|
2007-03-23 01:47:24 +03:00
|
|
|
/* codebase, classid, and data are URLs
|
|
|
|
* (codebase is the base for the other two) */
|
2005-04-14 01:58:28 +04:00
|
|
|
if ((codebase = xmlGetProp(n, (const xmlChar *) "codebase"))) {
|
|
|
|
if (!box_extract_link((char *) codebase,
|
2007-03-23 01:47:24 +03:00
|
|
|
content->data.html.base_url,
|
|
|
|
¶ms->codebase))
|
2005-04-14 01:58:28 +04:00
|
|
|
return false;
|
|
|
|
xmlFree(codebase);
|
|
|
|
}
|
|
|
|
if (!params->codebase)
|
|
|
|
params->codebase = content->data.html.base_url;
|
|
|
|
|
2007-03-23 01:47:24 +03:00
|
|
|
if ((classid = xmlGetProp(n, (const xmlChar *) "classid"))) {
|
2005-04-14 01:58:28 +04:00
|
|
|
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);
|
|
|
|
}
|
2007-03-23 01:47:24 +03:00
|
|
|
|
|
|
|
if (!params->classid && !params->data)
|
|
|
|
/* nothing to embed; ignore */
|
2005-04-14 01:58:28 +04:00
|
|
|
return true;
|
|
|
|
|
2006-03-27 05:04:56 +04:00
|
|
|
/* Don't include ourself */
|
2007-03-23 01:47:24 +03:00
|
|
|
if (params->classid &&
|
|
|
|
strcmp(content->data.html.base_url,
|
|
|
|
params->classid) == 0)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (params->data &&
|
|
|
|
strcmp(content->data.html.base_url,
|
|
|
|
params->data) == 0)
|
2006-03-27 05:04:56 +04:00
|
|
|
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;
|
2007-03-23 01:47:24 +03:00
|
|
|
|
|
|
|
/* classid && !data => classid is used (consult codetype)
|
|
|
|
* (classid || !classid) && data => data is used (consult type)
|
|
|
|
* !classid && !data => invalid; ignored */
|
|
|
|
|
|
|
|
if (params->classid && !params->data && params->codetype &&
|
|
|
|
content_lookup(params->codetype) == CONTENT_OTHER)
|
|
|
|
/* can't handle this MIME type */
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (params->data && params->type &&
|
|
|
|
content_lookup(params->type) == CONTENT_OTHER)
|
2005-04-14 01:58:28 +04:00
|
|
|
/* 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;
|
2006-09-11 15:55:17 +04:00
|
|
|
if (!param->valuetype) {
|
|
|
|
param->valuetype = talloc_strdup(param, "data");
|
|
|
|
if (!param->valuetype)
|
|
|
|
return false;
|
|
|
|
}
|
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) */
|
2007-03-23 01:47:24 +03:00
|
|
|
if (!html_fetch_object(content,
|
|
|
|
params->data ? params->data : params->classid,
|
|
|
|
box, 0, content->available_width, 1000, false))
|
2005-04-14 01:58:28 +04:00
|
|
|
return false;
|
|
|
|
|
|
|
|
*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};
|
|
|
|
|
2010-04-28 01:38:41 +04:00
|
|
|
box = box_create(style, false, status->href, 0, status->id,
|
2005-04-09 13:47:37 +04:00
|
|
|
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
|
|
|
|
2008-02-25 19:37:48 +03:00
|
|
|
if ((s = (char *) xmlGetProp(c,
|
|
|
|
(const xmlChar *) "name")) != NULL) {
|
2005-04-09 13:47:37 +04:00
|
|
|
pp->name = strdup(s);
|
|
|
|
xmlFree(s);
|
|
|
|
if (!pp->name)
|
|
|
|
goto no_memory;
|
|
|
|
}
|
2008-02-25 19:37:48 +03:00
|
|
|
if ((s = (char *) xmlGetProp(c,
|
|
|
|
(const xmlChar *) "value")) != NULL) {
|
2005-04-09 13:47:37 +04:00
|
|
|
pp->value = strdup(s);
|
|
|
|
xmlFree(s);
|
|
|
|
if (!pp->value)
|
|
|
|
goto no_memory;
|
|
|
|
}
|
2008-02-25 19:37:48 +03:00
|
|
|
if ((s = (char *) xmlGetProp(c,
|
|
|
|
(const xmlChar *) "type")) != NULL) {
|
2005-04-09 13:47:37 +04:00
|
|
|
pp->type = strdup(s);
|
|
|
|
xmlFree(s);
|
|
|
|
if (!pp->type)
|
|
|
|
goto no_memory;
|
|
|
|
}
|
2008-02-25 19:37:48 +03:00
|
|
|
if ((s = (char *) xmlGetProp(c, (const xmlChar *)
|
|
|
|
"valuetype")) != NULL) {
|
2005-04-09 13:47:37 +04:00
|
|
|
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
|
|
|
{
|
2006-09-02 19:52:41 +04:00
|
|
|
bool ok;
|
|
|
|
|
|
|
|
if (content->data.html.frameset) {
|
|
|
|
LOG(("Error: multiple framesets in document."));
|
2008-02-25 11:53:04 +03:00
|
|
|
/* Don't convert children */
|
|
|
|
if (convert_children)
|
|
|
|
*convert_children = false;
|
|
|
|
/* And ignore this spurious frameset */
|
2009-07-24 03:05:34 +04:00
|
|
|
box->type = BOX_NONE;
|
2008-02-25 11:53:04 +03:00
|
|
|
return true;
|
2006-09-02 19:52:41 +04:00
|
|
|
}
|
2006-09-11 15:55:17 +04:00
|
|
|
|
2008-02-25 19:37:48 +03:00
|
|
|
content->data.html.frameset = talloc_zero(content,
|
|
|
|
struct content_html_frames);
|
2006-09-02 19:52:41 +04:00
|
|
|
if (!content->data.html.frameset)
|
|
|
|
return false;
|
2006-09-11 15:55:17 +04:00
|
|
|
|
2006-09-02 19:52:41 +04:00
|
|
|
ok = box_create_frameset(content->data.html.frameset, n, content);
|
|
|
|
if (ok)
|
2009-07-24 03:05:34 +04:00
|
|
|
box->type = BOX_NONE;
|
2006-09-02 19:52:41 +04:00
|
|
|
|
|
|
|
if (convert_children)
|
|
|
|
*convert_children = false;
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool box_create_frameset(struct content_html_frames *f, xmlNode *n,
|
|
|
|
struct content *content) {
|
|
|
|
unsigned int row, col, index, i;
|
2005-04-09 13:47:37 +04:00
|
|
|
unsigned int rows = 1, cols = 1;
|
2006-09-02 19:52:41 +04:00
|
|
|
char *s, *url;
|
|
|
|
struct frame_dimension *row_height = 0, *col_width = 0;
|
2005-04-09 13:47:37 +04:00
|
|
|
xmlNode *c;
|
2006-09-02 19:52:41 +04:00
|
|
|
struct content_html_frames *frame;
|
|
|
|
bool default_border = true;
|
|
|
|
colour default_border_colour = 0x000000;
|
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"))) {
|
2006-09-02 19:52:41 +04:00
|
|
|
row_height = box_parse_multi_lengths(s, &rows);
|
2005-03-26 04:12:27 +03:00
|
|
|
xmlFree(s);
|
2005-04-09 13:47:37 +04:00
|
|
|
if (!row_height)
|
|
|
|
return false;
|
2006-09-02 19:52:41 +04:00
|
|
|
} else {
|
|
|
|
row_height = calloc(1, sizeof(struct frame_dimension));
|
|
|
|
if (!row_height)
|
|
|
|
return false;
|
|
|
|
row_height->value = 100;
|
|
|
|
row_height->unit = FRAME_DIMENSION_PERCENT;
|
2005-04-09 13:47:37 +04:00
|
|
|
}
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
if ((s = (char *) xmlGetProp(n, (const xmlChar *) "cols"))) {
|
2006-09-02 19:52:41 +04:00
|
|
|
col_width = box_parse_multi_lengths(s, &cols);
|
2005-04-09 13:47:37 +04:00
|
|
|
xmlFree(s);
|
|
|
|
if (!col_width)
|
|
|
|
return false;
|
2006-09-02 19:52:41 +04:00
|
|
|
} else {
|
|
|
|
col_width = calloc(1, sizeof(struct frame_dimension));
|
|
|
|
if (!col_width)
|
|
|
|
return false;
|
|
|
|
col_width->value = 100;
|
|
|
|
col_width->unit = FRAME_DIMENSION_PERCENT;
|
2005-04-09 13:47:37 +04:00
|
|
|
}
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2006-09-02 19:52:41 +04:00
|
|
|
/* common extension: border="0|1" to control all children */
|
|
|
|
if ((s = (char *) xmlGetProp(n, (const xmlChar *) "border"))) {
|
|
|
|
if ((s[0] == '0') && (s[1] == '\0'))
|
|
|
|
default_border = false;
|
|
|
|
xmlFree(s);
|
|
|
|
}
|
|
|
|
/* common extension: frameborder="yes|no" to control all children */
|
|
|
|
if ((s = (char *) xmlGetProp(n, (const xmlChar *) "frameborder"))) {
|
|
|
|
if (!strcasecmp(s, "no"))
|
|
|
|
default_border = false;
|
|
|
|
xmlFree(s);
|
|
|
|
}
|
2008-02-25 19:37:48 +03:00
|
|
|
/* common extension: bordercolor="#RRGGBB|<named colour>" to control
|
|
|
|
*all children */
|
2006-09-02 19:52:41 +04:00
|
|
|
if ((s = (char *) xmlGetProp(n, (const xmlChar *) "bordercolor"))) {
|
2009-07-24 03:05:34 +04:00
|
|
|
css_color color;
|
|
|
|
|
|
|
|
if (nscss_parse_colour((const char *) s, &color))
|
|
|
|
default_border_colour = nscss_color_to_ns(color);
|
|
|
|
|
2006-09-02 19:52:41 +04:00
|
|
|
xmlFree(s);
|
|
|
|
}
|
2006-09-11 15:55:17 +04:00
|
|
|
|
2006-09-02 19:52:41 +04:00
|
|
|
/* update frameset and create default children */
|
|
|
|
f->cols = cols;
|
|
|
|
f->rows = rows;
|
|
|
|
f->scrolling = SCROLLING_NO;
|
2008-02-25 19:37:48 +03:00
|
|
|
f->children = talloc_array(content, struct content_html_frames,
|
|
|
|
(rows * cols));
|
2006-09-02 19:52:41 +04:00
|
|
|
for (row = 0; row < rows; row++) {
|
|
|
|
for (col = 0; col < cols; col++) {
|
|
|
|
index = (row * cols) + col;
|
|
|
|
frame = &f->children[index];
|
|
|
|
frame->cols = 0;
|
|
|
|
frame->rows = 0;
|
|
|
|
frame->width = col_width[col];
|
|
|
|
frame->height = row_height[row];
|
2007-01-25 01:53:09 +03:00
|
|
|
frame->margin_width = 0;
|
|
|
|
frame->margin_height = 0;
|
2006-09-02 19:52:41 +04:00
|
|
|
frame->name = NULL;
|
|
|
|
frame->url = NULL;
|
|
|
|
frame->no_resize = false;
|
|
|
|
frame->scrolling = SCROLLING_AUTO;
|
|
|
|
frame->border = default_border;
|
|
|
|
frame->border_colour = default_border_colour;
|
|
|
|
frame->children = NULL;
|
2005-04-09 13:47:37 +04:00
|
|
|
}
|
|
|
|
}
|
2006-09-02 19:52:41 +04:00
|
|
|
free(col_width);
|
|
|
|
free(row_height);
|
2005-04-09 13:47:37 +04:00
|
|
|
|
2006-09-02 19:52:41 +04:00
|
|
|
/* create the frameset windows */
|
2005-04-09 13:47:37 +04:00
|
|
|
c = n->children;
|
2006-09-02 19:52:41 +04:00
|
|
|
for (row = 0; c && row < rows; row++) {
|
|
|
|
for (col = 0; c && col < cols; col++) {
|
2005-04-09 13:47:37 +04:00
|
|
|
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;
|
|
|
|
|
2006-09-02 19:52:41 +04:00
|
|
|
/* get current frame */
|
|
|
|
index = (row * cols) + col;
|
|
|
|
frame = &f->children[index];
|
2005-04-09 13:47:37 +04:00
|
|
|
|
2006-09-02 19:52:41 +04:00
|
|
|
/* nest framesets */
|
2005-04-09 13:47:37 +04:00
|
|
|
if (strcmp((const char *) c->name, "frameset") == 0) {
|
2006-09-02 19:52:41 +04:00
|
|
|
frame->border = 0;
|
|
|
|
if (!box_create_frameset(frame, c, content))
|
2005-04-09 13:47:37 +04:00
|
|
|
return false;
|
|
|
|
c = c->next;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2007-01-03 23:11:09 +03:00
|
|
|
/* get frame URL (not required) */
|
|
|
|
url = NULL;
|
|
|
|
if ((s = (char *) xmlGetProp(c,
|
2005-04-09 13:47:37 +04:00
|
|
|
(const xmlChar *) "src"))) {
|
2008-02-25 19:37:48 +03:00
|
|
|
box_extract_link(s, content->data.html.base_url,
|
|
|
|
&url);
|
2006-09-02 19:52:41 +04:00
|
|
|
xmlFree(s);
|
|
|
|
}
|
2007-01-25 01:53:09 +03:00
|
|
|
|
2007-01-03 23:11:09 +03:00
|
|
|
/* copy url */
|
|
|
|
if (url) {
|
|
|
|
/* no self-references */
|
|
|
|
if (strcmp(content->data.html.base_url, url))
|
2008-02-25 19:37:48 +03:00
|
|
|
frame->url = talloc_strdup(content,
|
|
|
|
url);
|
2006-09-02 19:52:41 +04:00
|
|
|
free(url);
|
2007-01-03 23:11:09 +03:00
|
|
|
url = NULL;
|
2006-09-02 19:52:41 +04:00
|
|
|
}
|
2007-01-25 01:53:09 +03:00
|
|
|
|
2006-09-02 19:52:41 +04:00
|
|
|
/* fill in specified values */
|
|
|
|
if ((s = (char *) xmlGetProp(c,
|
|
|
|
(const xmlChar *) "name"))) {
|
|
|
|
frame->name = talloc_strdup(content, s);
|
|
|
|
xmlFree(s);
|
|
|
|
}
|
|
|
|
frame->no_resize = xmlHasProp(c,
|
2009-04-16 16:49:49 +04:00
|
|
|
(const xmlChar *) "noresize") != NULL;
|
2006-09-02 19:52:41 +04:00
|
|
|
if ((s = (char *) xmlGetProp(c,
|
|
|
|
(const xmlChar *) "frameborder"))) {
|
|
|
|
i = atoi(s);
|
|
|
|
frame->border = (i != 0);
|
|
|
|
xmlFree(s);
|
|
|
|
}
|
|
|
|
if ((s = (char *) xmlGetProp(c,
|
|
|
|
(const xmlChar *) "scrolling"))) {
|
|
|
|
if (!strcasecmp(s, "yes"))
|
|
|
|
frame->scrolling = SCROLLING_YES;
|
|
|
|
else if (!strcasecmp(s, "no"))
|
|
|
|
frame->scrolling = SCROLLING_NO;
|
|
|
|
xmlFree(s);
|
|
|
|
}
|
|
|
|
if ((s = (char *) xmlGetProp(c,
|
|
|
|
(const xmlChar *) "marginwidth"))) {
|
|
|
|
frame->margin_width = atoi(s);
|
|
|
|
xmlFree(s);
|
|
|
|
}
|
|
|
|
if ((s = (char *) xmlGetProp(c,
|
|
|
|
(const xmlChar *) "marginheight"))) {
|
2007-01-25 01:53:09 +03:00
|
|
|
frame->margin_height = atoi(s);
|
2006-09-02 19:52:41 +04:00
|
|
|
xmlFree(s);
|
|
|
|
}
|
2008-02-25 19:37:48 +03:00
|
|
|
if ((s = (char *) xmlGetProp(c, (const xmlChar *)
|
|
|
|
"bordercolor"))) {
|
2009-07-24 03:05:34 +04:00
|
|
|
css_color color;
|
|
|
|
|
|
|
|
if (nscss_parse_colour((const char *) s,
|
|
|
|
&color))
|
|
|
|
frame->border_colour =
|
|
|
|
nscss_color_to_ns(color);
|
|
|
|
|
2006-09-02 19:52:41 +04:00
|
|
|
xmlFree(s);
|
|
|
|
}
|
2005-04-09 13:47:37 +04:00
|
|
|
|
2007-01-03 23:11:09 +03:00
|
|
|
/* advance */
|
2005-04-09 13:47:37 +04:00
|
|
|
c = c->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
2006-09-02 19:52:41 +04:00
|
|
|
char *url, *s;
|
|
|
|
struct content_html_iframe *iframe;
|
|
|
|
int i;
|
2005-04-09 13:47:37 +04:00
|
|
|
|
2011-01-05 04:26:29 +03:00
|
|
|
if (box->style && css_computed_display(box->style,
|
|
|
|
n->parent == NULL) == CSS_DISPLAY_NONE)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (box->style && css_computed_visibility(box->style) ==
|
|
|
|
CSS_VISIBILITY_HIDDEN)
|
|
|
|
/* Don't create iframe discriptors for invisible iframes
|
|
|
|
* TODO: handle hidden iframes at browser_window generation
|
|
|
|
* time instead? */
|
|
|
|
return true;
|
|
|
|
|
2005-04-14 01:58:28 +04:00
|
|
|
/* get frame URL */
|
2006-09-02 19:52:41 +04:00
|
|
|
if (!(s = (char *) xmlGetProp(n,
|
|
|
|
(const xmlChar *) "src")))
|
2005-04-14 01:58:28 +04:00
|
|
|
return true;
|
2006-09-02 19:52:41 +04:00
|
|
|
if (!box_extract_link(s, content->data.html.base_url, &url)) {
|
|
|
|
xmlFree(s);
|
2005-04-09 13:47:37 +04:00
|
|
|
return false;
|
2006-09-02 19:52:41 +04:00
|
|
|
}
|
|
|
|
xmlFree(s);
|
2005-04-14 01:58:28 +04:00
|
|
|
if (!url)
|
|
|
|
return true;
|
2005-04-09 13:47:37 +04:00
|
|
|
|
2006-09-02 19:52:41 +04:00
|
|
|
/* don't include ourself */
|
2006-03-27 05:04:56 +04:00
|
|
|
if (strcmp(content->data.html.base_url, url) == 0) {
|
|
|
|
free(url);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2006-09-02 19:52:41 +04:00
|
|
|
/* create a new iframe */
|
|
|
|
iframe = talloc(content, struct content_html_iframe);
|
|
|
|
if (!iframe) {
|
|
|
|
free(url);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
iframe->box = box;
|
2007-01-25 01:53:09 +03:00
|
|
|
iframe->margin_width = 0;
|
|
|
|
iframe->margin_height = 0;
|
2006-09-02 19:52:41 +04:00
|
|
|
iframe->name = NULL;
|
|
|
|
iframe->url = talloc_strdup(content, url);
|
|
|
|
iframe->scrolling = SCROLLING_AUTO;
|
|
|
|
iframe->border = true;
|
2010-06-09 13:53:07 +04:00
|
|
|
|
|
|
|
/* Add this iframe to the linked list of iframes */
|
2006-09-02 19:52:41 +04:00
|
|
|
iframe->next = content->data.html.iframe;
|
|
|
|
content->data.html.iframe = iframe;
|
|
|
|
|
|
|
|
/* fill in specified values */
|
|
|
|
if ((s = (char *) xmlGetProp(n,
|
|
|
|
(const xmlChar *) "name"))) {
|
|
|
|
iframe->name = talloc_strdup(content, s);
|
2006-09-11 15:55:17 +04:00
|
|
|
xmlFree(s);
|
2006-09-02 19:52:41 +04:00
|
|
|
}
|
|
|
|
if ((s = (char *) xmlGetProp(n,
|
|
|
|
(const xmlChar *) "frameborder"))) {
|
|
|
|
i = atoi(s);
|
|
|
|
iframe->border = (i != 0);
|
|
|
|
xmlFree(s);
|
|
|
|
}
|
|
|
|
if ((s = (char *) xmlGetProp(n, (const xmlChar *) "bordercolor"))) {
|
2009-07-24 03:05:34 +04:00
|
|
|
css_color color;
|
|
|
|
|
|
|
|
if (nscss_parse_colour(s, &color))
|
|
|
|
iframe->border_colour = nscss_color_to_ns(color);
|
|
|
|
|
2006-09-02 19:52:41 +04:00
|
|
|
xmlFree(s);
|
|
|
|
}
|
|
|
|
if ((s = (char *) xmlGetProp(n,
|
|
|
|
(const xmlChar *) "scrolling"))) {
|
|
|
|
if (!strcasecmp(s, "yes"))
|
|
|
|
iframe->scrolling = SCROLLING_YES;
|
|
|
|
else if (!strcasecmp(s, "no"))
|
|
|
|
iframe->scrolling = SCROLLING_NO;
|
|
|
|
xmlFree(s);
|
|
|
|
}
|
|
|
|
if ((s = (char *) xmlGetProp(n,
|
|
|
|
(const xmlChar *) "marginwidth"))) {
|
|
|
|
iframe->margin_width = atoi(s);
|
|
|
|
xmlFree(s);
|
|
|
|
}
|
|
|
|
if ((s = (char *) xmlGetProp(n,
|
|
|
|
(const xmlChar *) "marginheight"))) {
|
2007-01-25 01:53:09 +03:00
|
|
|
iframe->margin_height = atoi(s);
|
2006-09-02 19:52:41 +04:00
|
|
|
xmlFree(s);
|
|
|
|
}
|
2006-09-11 15:55:17 +04:00
|
|
|
|
2006-09-02 19:52:41 +04:00
|
|
|
/* release temporary memory */
|
2005-04-14 01:58:28 +04:00
|
|
|
free(url);
|
2006-08-25 00:02:37 +04:00
|
|
|
|
2006-09-02 19:52:41 +04:00
|
|
|
/* box */
|
|
|
|
box->type = BOX_INLINE_BLOCK;
|
|
|
|
assert(box->style);
|
2006-08-25 00:02:37 +04:00
|
|
|
|
2010-06-03 19:15:31 +04:00
|
|
|
/* Showing iframe, so don't show alternate content */
|
2006-09-02 19:52:41 +04:00
|
|
|
if (convert_children)
|
|
|
|
*convert_children = false;
|
|
|
|
return true;
|
2005-03-26 04:12:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
/**
|
|
|
|
* 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");
|
|
|
|
|
2009-02-20 14:39:25 +03:00
|
|
|
gadget = binding_get_control_for_node(content->data.html.parser_binding,
|
|
|
|
n);
|
|
|
|
if (!gadget)
|
|
|
|
goto no_memory;
|
|
|
|
box->gadget = gadget;
|
|
|
|
gadget->box = box;
|
|
|
|
|
2005-03-26 04:12:27 +03:00
|
|
|
if (type && strcasecmp(type, "password") == 0) {
|
2009-07-24 03:05:34 +04:00
|
|
|
if (!box_input_text(n, content, box, 0, true))
|
2005-03-26 04:12:27 +03:00
|
|
|
goto no_memory;
|
|
|
|
} else if (type && strcasecmp(type, "file") == 0) {
|
|
|
|
box->type = BOX_INLINE_BLOCK;
|
|
|
|
} else if (type && strcasecmp(type, "hidden") == 0) {
|
|
|
|
/* no box for hidden inputs */
|
2009-07-24 03:05:34 +04:00
|
|
|
box->type = BOX_NONE;
|
2005-03-26 04:12:27 +03:00
|
|
|
} else if (type && (strcasecmp(type, "checkbox") == 0 ||
|
|
|
|
strcasecmp(type, "radio") == 0)) {
|
|
|
|
} else if (type && (strcasecmp(type, "submit") == 0 ||
|
2009-02-20 14:39:25 +03:00
|
|
|
strcasecmp(type, "reset") == 0 ||
|
|
|
|
strcasecmp(type, "button") == 0)) {
|
2005-03-26 04:12:27 +03:00
|
|
|
struct box *inline_container, *inline_box;
|
2009-07-24 03:05:34 +04:00
|
|
|
|
|
|
|
if (!box_button(n, content, box, 0))
|
2005-03-26 04:12:27 +03:00
|
|
|
goto no_memory;
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2011-01-05 22:36:05 +03:00
|
|
|
inline_container = box_create(NULL, 0, false, 0, 0, 0, 0,
|
|
|
|
content);
|
2005-03-26 04:12:27 +03:00
|
|
|
if (!inline_container)
|
|
|
|
goto no_memory;
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2005-03-26 04:12:27 +03:00
|
|
|
inline_container->type = BOX_INLINE_CONTAINER;
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2011-01-05 22:36:05 +03:00
|
|
|
inline_box = box_create(NULL, box->style, false, 0, 0,
|
|
|
|
box->title, 0, content);
|
2005-03-26 04:12:27 +03:00
|
|
|
if (!inline_box)
|
|
|
|
goto no_memory;
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2005-05-25 00:21:47 +04:00
|
|
|
inline_box->type = BOX_TEXT;
|
2009-07-24 03:05:34 +04:00
|
|
|
|
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"));
|
2009-02-20 14:39:25 +03:00
|
|
|
else if (box->gadget->type == GADGET_RESET)
|
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
|
|
|
else
|
2005-04-09 13:47:37 +04:00
|
|
|
inline_box->text = talloc_strdup(content, "Button");
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2005-03-26 04:12:27 +03:00
|
|
|
if (!inline_box->text)
|
|
|
|
goto no_memory;
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2005-03-26 04:12:27 +03:00
|
|
|
inline_box->length = strlen(inline_box->text);
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2005-03-26 04:12:27 +03:00
|
|
|
box_add_child(inline_container, inline_box);
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2005-03-26 04:12:27 +03:00
|
|
|
box_add_child(box, inline_container);
|
|
|
|
} else if (type && strcasecmp(type, "image") == 0) {
|
|
|
|
gadget->type = GADGET_IMAGE;
|
2007-04-07 03:48:26 +04:00
|
|
|
|
2009-07-24 03:05:34 +04:00
|
|
|
if (box->style && css_computed_display(box->style,
|
|
|
|
n->parent == NULL) != CSS_DISPLAY_NONE) {
|
2007-04-07 03:48:26 +04:00
|
|
|
if ((s = (char *) xmlGetProp(n,
|
|
|
|
(const xmlChar*) "src"))) {
|
|
|
|
res = url_join(s,
|
|
|
|
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) {
|
|
|
|
if (!html_fetch_object(content, url,
|
|
|
|
box, image_types,
|
2008-02-25 19:37:48 +03:00
|
|
|
content->
|
|
|
|
available_width,
|
2007-04-07 03:48:26 +04:00
|
|
|
1000, false)) {
|
|
|
|
free(url);
|
|
|
|
goto no_memory;
|
|
|
|
}
|
2006-09-02 19:52:41 +04:00
|
|
|
}
|
2007-04-07 03:48:26 +04:00
|
|
|
free(url);
|
2006-09-02 19:52:41 +04:00
|
|
|
}
|
2005-03-26 04:12:27 +03:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* the default type is "text" */
|
2009-07-24 03:05:34 +04:00
|
|
|
if (!box_input_text(n, content, box, 0, false))
|
2005-03-26 04:12:27 +03:00
|
|
|
goto no_memory;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
*convert_children = false;
|
|
|
|
return true;
|
2005-03-26 04:12:27 +03:00
|
|
|
|
|
|
|
no_memory:
|
|
|
|
if (type)
|
|
|
|
xmlFree(type);
|
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
|
|
|
{
|
|
|
|
struct box *inline_container, *inline_box;
|
|
|
|
|
|
|
|
box->type = BOX_INLINE_BLOCK;
|
|
|
|
|
2011-01-05 22:36:05 +03:00
|
|
|
inline_container = box_create(NULL, 0, false, 0, 0, 0, 0, content);
|
2005-03-26 04:12:27 +03:00
|
|
|
if (!inline_container)
|
2009-04-16 16:49:49 +04:00
|
|
|
return false;
|
2005-03-26 04:12:27 +03:00
|
|
|
inline_container->type = BOX_INLINE_CONTAINER;
|
2011-01-05 22:36:05 +03:00
|
|
|
inline_box = box_create(NULL, box->style, false, 0, 0, box->title, 0,
|
|
|
|
content);
|
2005-03-26 04:12:27 +03:00
|
|
|
if (!inline_box)
|
2009-04-16 16:49:49 +04:00
|
|
|
return false;
|
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)
|
2009-04-16 16:49:49 +04:00
|
|
|
return false;
|
2005-03-26 04:12:27 +03:00
|
|
|
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)
|
2009-04-16 16:49:49 +04:00
|
|
|
return false;
|
2005-04-09 13:47:37 +04:00
|
|
|
inline_box->text = talloc_strdup(content, text);
|
|
|
|
free(text);
|
2005-03-26 04:12:27 +03:00
|
|
|
if (!inline_box->text)
|
2009-04-16 16:49:49 +04:00
|
|
|
return false;
|
2005-03-26 04:12:27 +03:00
|
|
|
inline_box->length = strlen(inline_box->text);
|
|
|
|
}
|
|
|
|
box_add_child(inline_container, inline_box);
|
|
|
|
box_add_child(box, inline_container);
|
|
|
|
|
2009-04-16 16:49:49 +04:00
|
|
|
return true;
|
2005-03-26 04:12:27 +03:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2009-02-20 14:39:25 +03:00
|
|
|
struct form_control *gadget;
|
|
|
|
|
|
|
|
gadget = binding_get_control_for_node(content->data.html.parser_binding,
|
|
|
|
n);
|
|
|
|
if (!gadget)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
box->gadget = gadget;
|
|
|
|
gadget->box = box;
|
2009-04-17 04:54:27 +04:00
|
|
|
|
2009-02-20 14:39:25 +03:00
|
|
|
box->type = BOX_INLINE_BLOCK;
|
2009-04-29 00:13:10 +04:00
|
|
|
|
2009-02-20 14:39:25 +03:00
|
|
|
/* Just render the contents */
|
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;
|
|
|
|
xmlNode *c, *c2;
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2009-02-20 14:39:25 +03:00
|
|
|
gadget = binding_get_control_for_node(content->data.html.parser_binding,
|
|
|
|
n);
|
2005-04-09 13:47:37 +04:00
|
|
|
if (!gadget)
|
|
|
|
return false;
|
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 */
|
|
|
|
return true;
|
2005-03-26 04:12:27 +03:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2011-01-05 22:36:05 +03:00
|
|
|
inline_container = box_create(NULL, 0, false, 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;
|
2011-01-05 22:36:05 +03:00
|
|
|
inline_box = box_create(NULL, box->style, false, 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
|
|
|
*convert_children = false;
|
|
|
|
return true;
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
no_memory:
|
|
|
|
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
|
2006-09-02 19:52:41 +04:00
|
|
|
* \param n xml element node for <option>
|
2005-04-09 13:47:37 +04:00
|
|
|
* \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;
|
2008-02-25 19:37:48 +03:00
|
|
|
char *text_nowrap = 0;
|
2005-04-09 13:47:37 +04:00
|
|
|
bool selected;
|
|
|
|
xmlChar *content;
|
2008-02-25 20:58:00 +03:00
|
|
|
char *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;
|
2008-02-25 20:58:00 +03:00
|
|
|
text = squash_whitespace((const char *) content);
|
2005-04-09 13:47:37 +04:00
|
|
|
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
|
|
|
|
2009-04-16 16:49:49 +04:00
|
|
|
selected = xmlHasProp(n, (const xmlChar *) "selected") != NULL;
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2008-02-25 19:37:48 +03:00
|
|
|
/* replace spaces/TABs with hard spaces to prevent line wrapping */
|
|
|
|
text_nowrap = cnv_space2nbsp(text);
|
|
|
|
if (!text_nowrap)
|
|
|
|
goto no_memory;
|
|
|
|
|
|
|
|
if (!form_add_option(control, value, text_nowrap, selected))
|
2005-04-09 13:47:37 +04:00
|
|
|
goto no_memory;
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2008-02-25 19:37:48 +03:00
|
|
|
free(text);
|
|
|
|
|
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);
|
2008-02-25 19:37:48 +03:00
|
|
|
free(text_nowrap);
|
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
|
|
|
|
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
|
|
|
|
2006-09-11 15:55:17 +04:00
|
|
|
xmlChar *current, *string;
|
2006-09-10 17:27:08 +04:00
|
|
|
xmlNode *n2;
|
|
|
|
xmlBufferPtr buf;
|
2006-09-11 15:55:17 +04:00
|
|
|
xmlParserCtxtPtr ctxt;
|
2005-04-09 13:47:37 +04:00
|
|
|
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;
|
2009-02-20 14:39:25 +03:00
|
|
|
box->gadget = binding_get_control_for_node(
|
|
|
|
content->data.html.parser_binding, n);
|
2005-04-09 13:47:37 +04:00
|
|
|
if (!box->gadget)
|
|
|
|
return false;
|
|
|
|
box->gadget->box = box;
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2011-01-05 22:36:05 +03:00
|
|
|
inline_container = box_create(NULL, 0, false, 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);
|
|
|
|
|
2009-02-20 14:39:25 +03:00
|
|
|
/** \todo Is it really necessary to reparse the content of a
|
|
|
|
* textarea element to remove entities? Hubbub will do that for us.
|
|
|
|
*/
|
2006-09-10 17:27:08 +04:00
|
|
|
n2 = n->children;
|
|
|
|
buf = xmlBufferCreate();
|
|
|
|
while(n2) {
|
2006-09-11 15:55:17 +04:00
|
|
|
int ret = xmlNodeDump(buf, n2->doc, n2, 0, 0);
|
2006-09-10 17:27:08 +04:00
|
|
|
if (ret == -1) {
|
|
|
|
xmlBufferFree(buf);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
n2 = n2->next;
|
|
|
|
}
|
2006-09-11 15:55:17 +04:00
|
|
|
|
|
|
|
ctxt = xmlCreateDocParserCtxt(buf->content);
|
|
|
|
string = current = NULL;
|
|
|
|
if (ctxt) {
|
|
|
|
string = current = xmlStringDecodeEntities(ctxt,
|
|
|
|
buf->content,
|
2007-02-12 02:21:05 +03:00
|
|
|
XML_SUBSTITUTE_REF,
|
2006-09-11 15:55:17 +04:00
|
|
|
0, 0, 0);
|
2006-09-11 12:02:13 +04:00
|
|
|
xmlFreeParserCtxt(ctxt);
|
|
|
|
}
|
2006-09-11 15:55:17 +04:00
|
|
|
|
|
|
|
if (!string) {
|
|
|
|
/* If we get here, either the parser context failed to be
|
|
|
|
* created or we were unable to decode the entities in the
|
|
|
|
* buffer. Therefore, try to create a blank string in order
|
|
|
|
* to recover. */
|
|
|
|
string = current = xmlStrdup((const xmlChar *) "");
|
|
|
|
if (!string) {
|
|
|
|
xmlBufferFree(buf);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
while (1) {
|
2005-05-25 00:21:47 +04:00
|
|
|
/* BOX_TEXT */
|
2008-02-25 20:58:00 +03:00
|
|
|
len = strcspn((const char *) current, "\r\n");
|
|
|
|
s = talloc_strndup(content, (const char *) current, len);
|
2005-04-09 13:47:37 +04:00
|
|
|
if (!s) {
|
2006-09-11 15:55:17 +04:00
|
|
|
xmlFree(string);
|
2006-09-10 17:27:08 +04:00
|
|
|
xmlBufferFree(buf);
|
2005-04-09 13:47:37 +04:00
|
|
|
return false;
|
2005-03-26 04:12:27 +03:00
|
|
|
}
|
|
|
|
|
2011-01-05 22:36:05 +03:00
|
|
|
inline_box = box_create(NULL, box->style, false, 0, 0,
|
|
|
|
box->title, 0, content);
|
2006-09-10 17:27:08 +04:00
|
|
|
if (!inline_box) {
|
2006-09-11 15:55:17 +04:00
|
|
|
xmlFree(string);
|
2006-09-10 17:27:08 +04:00
|
|
|
xmlBufferFree(buf);
|
2005-04-09 13:47:37 +04:00
|
|
|
return false;
|
2006-09-10 17:27:08 +04:00
|
|
|
}
|
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 */
|
2011-01-05 22:36:05 +03:00
|
|
|
br_box = box_create(NULL, box->style, false, 0, 0, box->title,
|
|
|
|
0, content);
|
2006-09-10 17:27:08 +04:00
|
|
|
if (!br_box) {
|
2006-09-11 15:55:17 +04:00
|
|
|
xmlFree(string);
|
2006-09-10 17:27:08 +04:00
|
|
|
xmlBufferFree(buf);
|
2005-04-09 13:47:37 +04:00
|
|
|
return false;
|
2006-09-10 17:27:08 +04:00
|
|
|
}
|
2005-04-09 13:47:37 +04:00
|
|
|
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
|
|
|
}
|
2006-09-11 15:55:17 +04:00
|
|
|
|
|
|
|
xmlFree(string);
|
2006-09-10 17:27:08 +04:00
|
|
|
xmlBufferFree(buf);
|
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
|
|
|
|
2009-07-24 03:05:34 +04:00
|
|
|
if (box->style && css_computed_display(box->style,
|
|
|
|
n->parent == NULL) == CSS_DISPLAY_NONE)
|
2007-04-07 03:48:26 +04:00
|
|
|
return true;
|
|
|
|
|
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;
|
2006-09-11 15:55:17 +04:00
|
|
|
param->valuetype = talloc_strdup(content, "data");
|
2005-04-14 01:58:28 +04:00
|
|
|
param->next = 0;
|
|
|
|
|
2006-09-11 15:55:17 +04:00
|
|
|
if (!param->name || !param->value || !param->valuetype)
|
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,
|
2006-09-02 19:52:41 +04:00
|
|
|
content->available_width, 1000, false);
|
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.
|
|
|
|
*
|
2006-09-02 19:52:41 +04:00
|
|
|
* \param n xmlNode, of type XML_ELEMENT_NODE
|
2005-04-10 21:08:49 +04:00
|
|
|
* \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;
|
2008-02-25 20:58:00 +03:00
|
|
|
*value = talloc_strdup(context, (const char *) s);
|
2005-04-10 21:08:49 +04:00
|
|
|
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.
|
|
|
|
*
|
2006-09-02 19:52:41 +04:00
|
|
|
* \param rel relative URL taken from page
|
|
|
|
* \param base base for relative URLs
|
2005-04-10 21:08:49 +04:00
|
|
|
* \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.
|
|
|
|
*
|
2006-09-02 19:52:41 +04:00
|
|
|
* \param s string to parse
|
2005-04-09 13:47:37 +04:00
|
|
|
* \param count updated to number of entries
|
2005-03-26 04:12:27 +03:00
|
|
|
* \return array of struct box_multi_length, or 0 on memory exhaustion
|
|
|
|
*/
|
|
|
|
|
2006-09-02 19:52:41 +04:00
|
|
|
struct frame_dimension *box_parse_multi_lengths(const char *s,
|
|
|
|
unsigned int *count)
|
2005-03-26 04:12:27 +03:00
|
|
|
{
|
|
|
|
char *end;
|
|
|
|
unsigned int i, n;
|
2006-09-02 19:52:41 +04:00
|
|
|
struct frame_dimension *length;
|
2005-03-26 04:12:27 +03:00
|
|
|
|
|
|
|
for (i = 0, n = 1; s[i]; i++)
|
|
|
|
if (s[i] == ',')
|
|
|
|
n++;
|
|
|
|
|
2006-09-02 19:52:41 +04:00
|
|
|
length = calloc(n, sizeof(struct frame_dimension));
|
2005-04-09 13:47:37 +04:00
|
|
|
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) {
|
2006-09-02 19:52:41 +04:00
|
|
|
case '%':
|
|
|
|
length[i].unit = FRAME_DIMENSION_PERCENT;
|
|
|
|
break;
|
|
|
|
case '*':
|
|
|
|
length[i].unit = FRAME_DIMENSION_RELATIVE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
length[i].unit = FRAME_DIMENSION_PIXELS;
|
|
|
|
break;
|
2005-03-26 04:12:27 +03:00
|
|
|
}
|
|
|
|
while (*s && *s != ',')
|
|
|
|
s++;
|
|
|
|
if (*s == ',')
|
|
|
|
s++;
|
|
|
|
}
|
|
|
|
|
|
|
|
*count = n;
|
|
|
|
return length;
|
|
|
|
}
|
2007-10-09 20:25:25 +04:00
|
|
|
|