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
|
|
|
*/
|
|
|
|
|
2014-11-12 14:45:07 +03:00
|
|
|
/**
|
|
|
|
* \file
|
2005-03-26 04:12:27 +03:00
|
|
|
* 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>
|
2014-03-08 18:13:27 +04:00
|
|
|
|
2007-05-31 02:39:54 +04:00
|
|
|
#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"
|
2015-05-03 18:10:15 +03:00
|
|
|
#include "css/hints.h"
|
2009-07-24 03:05:34 +04:00
|
|
|
#include "css/select.h"
|
2015-05-03 18:10:15 +03:00
|
|
|
#include "css/utils.h"
|
2013-05-26 01:46:27 +04:00
|
|
|
#include "utils/nsoption.h"
|
2012-07-26 18:57:33 +04:00
|
|
|
#include "utils/corestrings.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/utils.h"
|
2014-10-16 12:48:09 +04:00
|
|
|
#include "desktop/gui_misc.h"
|
|
|
|
#include "desktop/gui_internal.h"
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2014-03-08 18:13:27 +04:00
|
|
|
#include "render/box.h"
|
|
|
|
#include "render/box_textarea.h"
|
2014-11-11 20:11:59 +03:00
|
|
|
#include "render/form_internal.h"
|
2014-03-08 18:13:27 +04:00
|
|
|
#include "render/html_internal.h"
|
|
|
|
|
2011-09-29 23:15:54 +04:00
|
|
|
/**
|
|
|
|
* Context for box tree construction
|
|
|
|
*/
|
|
|
|
struct box_construct_ctx {
|
|
|
|
html_content *content; /**< Content we're constructing for */
|
|
|
|
|
2012-03-24 03:18:04 +04:00
|
|
|
dom_node *n; /**< Current node to process */
|
2011-09-29 23:15:54 +04:00
|
|
|
|
|
|
|
struct box *root_box; /**< Root box in the tree */
|
|
|
|
|
|
|
|
box_construct_complete_cb cb; /**< Callback to invoke on completion */
|
2012-10-03 22:24:58 +04:00
|
|
|
|
2016-01-29 14:29:11 +03:00
|
|
|
int *bctx; /**< talloc context */
|
2011-09-29 23:15:54 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Transient properties for construction of current node
|
|
|
|
*/
|
|
|
|
struct box_construct_props {
|
|
|
|
/** Style from which to inherit, or NULL if none */
|
|
|
|
const css_computed_style *parent_style;
|
|
|
|
/** Current link target, or NULL if none */
|
2011-10-04 00:28:29 +04:00
|
|
|
nsurl *href;
|
2011-09-29 23:15:54 +04:00
|
|
|
/** Current frame target, or NULL if none */
|
|
|
|
const char *target;
|
|
|
|
/** Current title attribute, or NULL if none */
|
|
|
|
const char *title;
|
|
|
|
/** Identity of the current block-level container */
|
|
|
|
struct box *containing_block;
|
|
|
|
/** Current container for inlines, or NULL if none
|
|
|
|
* \note If non-NULL, will be the last child of containing_block */
|
|
|
|
struct box *inline_container;
|
|
|
|
/** Whether the current node is the root of the DOM tree */
|
|
|
|
bool node_is_root;
|
|
|
|
};
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
static const content_type image_types = CONTENT_IMAGE;
|
2005-03-26 04:12:27 +03:00
|
|
|
|
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
|
|
|
|
2011-09-29 23:15:54 +04:00
|
|
|
static void convert_xml_to_box(struct box_construct_ctx *ctx);
|
|
|
|
static bool box_construct_element(struct box_construct_ctx *ctx,
|
|
|
|
bool *convert_children);
|
2012-03-24 03:18:04 +04:00
|
|
|
static void box_construct_element_after(dom_node *n, html_content *content);
|
2011-09-29 23:15:54 +04:00
|
|
|
static bool box_construct_text(struct box_construct_ctx *ctx);
|
2011-05-07 00:40:09 +04:00
|
|
|
static css_select_results * box_get_style(html_content *c,
|
2012-03-24 03:18:04 +04:00
|
|
|
const css_computed_style *parent_style, dom_node *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);
|
2012-03-24 03:18:04 +04:00
|
|
|
#define BOX_SPECIAL_PARAMS dom_node *n, html_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_button(BOX_SPECIAL_PARAMS);
|
|
|
|
static bool box_frameset(BOX_SPECIAL_PARAMS);
|
2012-03-24 03:18:04 +04:00
|
|
|
static bool box_create_frameset(struct content_html_frames *f, dom_node *n,
|
2011-05-07 00:40:09 +04:00
|
|
|
html_content *content);
|
2012-03-24 03:18:04 +04:00
|
|
|
static bool box_select_add_option(struct form_control *control, dom_node *n);
|
2012-07-15 04:17:04 +04:00
|
|
|
static bool box_noscript(BOX_SPECIAL_PARAMS);
|
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-09 13:47:37 +04:00
|
|
|
static bool box_iframe(BOX_SPECIAL_PARAMS);
|
2012-03-24 03:18:04 +04:00
|
|
|
static bool box_get_attribute(dom_node *n, const char *attribute,
|
2005-04-10 21:08:49 +04:00
|
|
|
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},
|
|
|
|
{"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},
|
2012-07-15 04:17:04 +04:00
|
|
|
{"noscript", box_noscript},
|
2005-03-26 04:12:27 +03:00
|
|
|
{"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.
|
|
|
|
*
|
2011-09-29 23:15:54 +04:00
|
|
|
* \param n xml tree
|
|
|
|
* \param c content of type CONTENT_HTML to construct box tree in
|
|
|
|
* \param cb callback to report conversion completion
|
2012-11-26 21:23:03 +04:00
|
|
|
* \return netsurf error code indicating status of call
|
2005-03-26 04:12:27 +03:00
|
|
|
*/
|
|
|
|
|
2012-11-26 21:23:03 +04:00
|
|
|
nserror dom_to_box(dom_node *n, html_content *c, box_construct_complete_cb cb)
|
2005-03-26 04:12:27 +03:00
|
|
|
{
|
2011-09-29 23:15:54 +04:00
|
|
|
struct box_construct_ctx *ctx;
|
2006-03-27 05:04:56 +04:00
|
|
|
|
2012-10-03 22:24:58 +04:00
|
|
|
if (c->bctx == NULL) {
|
|
|
|
/* create a context allocation for this box tree */
|
|
|
|
c->bctx = talloc_zero(0, int);
|
|
|
|
if (c->bctx == NULL) {
|
2012-11-26 21:23:03 +04:00
|
|
|
return NSERROR_NOMEM;
|
2012-10-03 22:24:58 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-29 23:15:54 +04:00
|
|
|
ctx = malloc(sizeof(*ctx));
|
2012-11-26 21:23:03 +04:00
|
|
|
if (ctx == NULL) {
|
|
|
|
return NSERROR_NOMEM;
|
|
|
|
}
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2011-09-29 23:15:54 +04:00
|
|
|
ctx->content = c;
|
2012-07-22 20:52:30 +04:00
|
|
|
ctx->n = dom_node_ref(n);
|
2011-09-29 23:15:54 +04:00
|
|
|
ctx->root_box = NULL;
|
|
|
|
ctx->cb = cb;
|
2012-10-03 22:24:58 +04:00
|
|
|
ctx->bctx = c->bctx;
|
2011-09-29 23:15:54 +04:00
|
|
|
|
2014-03-08 18:13:27 +04:00
|
|
|
return guit->browser->schedule(0, (void *)convert_xml_to_box, ctx);
|
2005-03-26 04:12:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* 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
|
|
|
};
|
|
|
|
|
2012-03-24 22:47:51 +04:00
|
|
|
static inline struct box *box_for_node(dom_node *n)
|
2011-09-29 23:15:54 +04:00
|
|
|
{
|
2012-03-24 22:47:51 +04:00
|
|
|
struct box *box = NULL;
|
|
|
|
dom_exception err;
|
|
|
|
|
2014-01-24 22:58:12 +04:00
|
|
|
err = dom_node_get_user_data(n, corestring_dom___ns_key_box_node_data,
|
|
|
|
(void *) &box);
|
2012-03-24 22:47:51 +04:00
|
|
|
if (err != DOM_NO_ERR)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return box;
|
2011-09-29 23:15:54 +04:00
|
|
|
}
|
|
|
|
|
2012-03-24 22:47:51 +04:00
|
|
|
static inline bool box_is_root(dom_node *n)
|
2011-09-29 23:15:54 +04:00
|
|
|
{
|
2012-03-24 22:47:51 +04:00
|
|
|
dom_node *parent;
|
|
|
|
dom_node_type type;
|
|
|
|
dom_exception err;
|
|
|
|
|
|
|
|
err = dom_node_get_parent_node(n, &parent);
|
|
|
|
if (err != DOM_NO_ERR)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (parent != NULL) {
|
|
|
|
err = dom_node_get_node_type(parent, &type);
|
|
|
|
|
|
|
|
dom_node_unref(parent);
|
|
|
|
|
|
|
|
if (err != DOM_NO_ERR)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (type != DOM_DOCUMENT_NODE)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2011-09-29 23:15:54 +04:00
|
|
|
}
|
2005-03-26 04:12:27 +03:00
|
|
|
|
|
|
|
/**
|
2014-10-15 12:35:43 +04:00
|
|
|
* Find the next node in the DOM tree, completing
|
2011-09-29 23:15:54 +04:00
|
|
|
* element construction where appropriate.
|
2005-03-26 04:12:27 +03:00
|
|
|
*
|
2011-09-29 23:15:54 +04:00
|
|
|
* \param n Current node
|
|
|
|
* \param content Containing content
|
|
|
|
* \param convert_children Whether to consider children of \a n
|
|
|
|
* \return Next node to process, or NULL if complete
|
2012-03-24 22:47:51 +04:00
|
|
|
*
|
|
|
|
* \note \a n will be unreferenced
|
2005-03-26 04:12:27 +03:00
|
|
|
*/
|
2012-03-24 22:47:51 +04:00
|
|
|
static dom_node *next_node(dom_node *n, html_content *content,
|
2011-09-29 23:15:54 +04:00
|
|
|
bool convert_children)
|
|
|
|
{
|
2012-03-24 03:18:04 +04:00
|
|
|
dom_node *next = NULL;
|
2012-03-24 22:47:51 +04:00
|
|
|
bool has_children;
|
|
|
|
dom_exception err;
|
2011-09-29 23:15:54 +04:00
|
|
|
|
2012-03-24 22:47:51 +04:00
|
|
|
err = dom_node_has_child_nodes(n, &has_children);
|
|
|
|
if (err != DOM_NO_ERR) {
|
|
|
|
dom_node_unref(n);
|
|
|
|
return NULL;
|
|
|
|
}
|
2011-09-29 23:15:54 +04:00
|
|
|
|
2012-03-24 22:47:51 +04:00
|
|
|
if (convert_children && has_children) {
|
|
|
|
err = dom_node_get_first_child(n, &next);
|
|
|
|
if (err != DOM_NO_ERR) {
|
|
|
|
dom_node_unref(n);
|
|
|
|
return NULL;
|
|
|
|
}
|
2012-07-22 20:52:30 +04:00
|
|
|
dom_node_unref(n);
|
2011-09-29 23:15:54 +04:00
|
|
|
} else {
|
2012-03-24 22:47:51 +04:00
|
|
|
err = dom_node_get_next_sibling(n, &next);
|
|
|
|
if (err != DOM_NO_ERR) {
|
|
|
|
dom_node_unref(n);
|
|
|
|
return NULL;
|
|
|
|
}
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2012-03-24 22:47:51 +04:00
|
|
|
if (next != NULL) {
|
|
|
|
if (box_for_node(n) != NULL)
|
|
|
|
box_construct_element_after(n, content);
|
|
|
|
dom_node_unref(n);
|
|
|
|
} else {
|
2011-09-29 23:15:54 +04:00
|
|
|
if (box_for_node(n) != NULL)
|
|
|
|
box_construct_element_after(n, content);
|
|
|
|
|
2012-03-24 22:47:51 +04:00
|
|
|
while (box_is_root(n) == false) {
|
|
|
|
dom_node *parent = NULL;
|
|
|
|
dom_node *parent_next = NULL;
|
|
|
|
|
|
|
|
err = dom_node_get_parent_node(n, &parent);
|
|
|
|
if (err != DOM_NO_ERR) {
|
|
|
|
dom_node_unref(n);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(parent != NULL);
|
|
|
|
|
2014-10-15 12:35:43 +04:00
|
|
|
err = dom_node_get_next_sibling(parent,
|
2012-03-24 22:47:51 +04:00
|
|
|
&parent_next);
|
|
|
|
if (err != DOM_NO_ERR) {
|
|
|
|
dom_node_unref(parent);
|
|
|
|
dom_node_unref(n);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (parent_next != NULL) {
|
|
|
|
dom_node_unref(parent_next);
|
2012-07-22 20:52:30 +04:00
|
|
|
dom_node_unref(parent);
|
2012-03-24 22:47:51 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
dom_node_unref(n);
|
|
|
|
n = parent;
|
|
|
|
parent = NULL;
|
|
|
|
|
|
|
|
if (box_for_node(n) != NULL) {
|
|
|
|
box_construct_element_after(
|
|
|
|
n, content);
|
|
|
|
}
|
2011-09-29 23:15:54 +04:00
|
|
|
}
|
|
|
|
|
2012-03-24 22:47:51 +04:00
|
|
|
if (box_is_root(n) == false) {
|
|
|
|
dom_node *parent = NULL;
|
|
|
|
|
|
|
|
err = dom_node_get_parent_node(n, &parent);
|
|
|
|
if (err != DOM_NO_ERR) {
|
|
|
|
dom_node_unref(n);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(parent != NULL);
|
|
|
|
|
|
|
|
err = dom_node_get_next_sibling(parent, &next);
|
|
|
|
if (err != DOM_NO_ERR) {
|
|
|
|
dom_node_unref(parent);
|
|
|
|
dom_node_unref(n);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (box_for_node(parent) != NULL) {
|
2014-10-15 12:35:43 +04:00
|
|
|
box_construct_element_after(parent,
|
2012-03-24 22:47:51 +04:00
|
|
|
content);
|
|
|
|
}
|
|
|
|
|
|
|
|
dom_node_unref(parent);
|
|
|
|
}
|
|
|
|
|
|
|
|
dom_node_unref(n);
|
2011-09-29 23:15:54 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return next;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-10-15 12:35:43 +04:00
|
|
|
* Convert an ELEMENT node to a box tree fragment,
|
2011-09-29 23:15:54 +04:00
|
|
|
* then schedule conversion of the next ELEMENT node
|
|
|
|
*/
|
|
|
|
void convert_xml_to_box(struct box_construct_ctx *ctx)
|
2005-03-28 23:17:06 +04:00
|
|
|
{
|
2012-03-24 03:18:04 +04:00
|
|
|
dom_node *next;
|
2011-10-09 20:54:34 +04:00
|
|
|
bool convert_children;
|
|
|
|
uint32_t num_processed = 0;
|
|
|
|
const uint32_t max_processed_before_yield = 10;
|
2011-09-29 23:15:54 +04:00
|
|
|
|
2011-10-09 20:54:34 +04:00
|
|
|
do {
|
|
|
|
convert_children = true;
|
2011-09-29 23:15:54 +04:00
|
|
|
|
2011-10-09 20:54:34 +04:00
|
|
|
assert(ctx->n != NULL);
|
2011-09-29 23:15:54 +04:00
|
|
|
|
2011-10-09 20:54:34 +04:00
|
|
|
if (box_construct_element(ctx, &convert_children) == false) {
|
|
|
|
ctx->cb(ctx->content, false);
|
2012-03-24 22:47:51 +04:00
|
|
|
dom_node_unref(ctx->n);
|
2011-10-09 20:54:34 +04:00
|
|
|
free(ctx);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Find next element to process, converting text nodes as we go */
|
|
|
|
next = next_node(ctx->n, ctx->content, convert_children);
|
2012-03-24 22:47:51 +04:00
|
|
|
while (next != NULL) {
|
|
|
|
dom_node_type type;
|
|
|
|
dom_exception err;
|
|
|
|
|
|
|
|
err = dom_node_get_node_type(next, &type);
|
|
|
|
if (err != DOM_NO_ERR) {
|
|
|
|
ctx->cb(ctx->content, false);
|
|
|
|
dom_node_unref(next);
|
|
|
|
free(ctx);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (type == DOM_ELEMENT_NODE)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (type == DOM_TEXT_NODE) {
|
2011-10-09 20:54:34 +04:00
|
|
|
ctx->n = next;
|
|
|
|
if (box_construct_text(ctx) == false) {
|
|
|
|
ctx->cb(ctx->content, false);
|
2012-03-24 22:47:51 +04:00
|
|
|
dom_node_unref(ctx->n);
|
2011-10-09 20:54:34 +04:00
|
|
|
free(ctx);
|
|
|
|
return;
|
|
|
|
}
|
2011-09-29 23:15:54 +04:00
|
|
|
}
|
2011-10-09 20:54:34 +04:00
|
|
|
|
|
|
|
next = next_node(next, ctx->content, true);
|
2011-09-29 23:15:54 +04:00
|
|
|
}
|
|
|
|
|
2011-10-09 20:54:34 +04:00
|
|
|
ctx->n = next;
|
2011-09-29 23:15:54 +04:00
|
|
|
|
2011-10-09 20:54:34 +04:00
|
|
|
if (next == NULL) {
|
|
|
|
/* Conversion complete */
|
|
|
|
struct box root;
|
2011-09-29 23:15:54 +04:00
|
|
|
|
2011-10-09 20:54:34 +04:00
|
|
|
memset(&root, 0, sizeof(root));
|
2011-09-29 23:15:54 +04:00
|
|
|
|
2011-10-09 20:54:34 +04:00
|
|
|
root.type = BOX_BLOCK;
|
|
|
|
root.children = root.last = ctx->root_box;
|
|
|
|
root.children->parent = &root;
|
2011-09-29 23:15:54 +04:00
|
|
|
|
2011-10-09 20:54:34 +04:00
|
|
|
/** \todo Remove box_normalise_block */
|
|
|
|
if (box_normalise_block(&root, ctx->content) == false) {
|
|
|
|
ctx->cb(ctx->content, false);
|
|
|
|
} else {
|
|
|
|
ctx->content->layout = root.children;
|
|
|
|
ctx->content->layout->parent = NULL;
|
2011-09-29 23:15:54 +04:00
|
|
|
|
2011-10-09 20:54:34 +04:00
|
|
|
ctx->cb(ctx->content, true);
|
|
|
|
}
|
2011-09-29 23:15:54 +04:00
|
|
|
|
2012-03-24 22:47:51 +04:00
|
|
|
assert(ctx->n == NULL);
|
|
|
|
|
2011-10-09 20:54:34 +04:00
|
|
|
free(ctx);
|
|
|
|
return;
|
2011-09-29 23:15:54 +04:00
|
|
|
}
|
2011-10-09 20:54:34 +04:00
|
|
|
} while (++num_processed < max_processed_before_yield);
|
2011-09-29 23:15:54 +04:00
|
|
|
|
2011-10-09 20:54:34 +04:00
|
|
|
/* More work to do: schedule a continuation */
|
2014-03-08 18:13:27 +04:00
|
|
|
guit->browser->schedule(0, (void *)convert_xml_to_box, ctx);
|
2011-09-29 23:15:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Construct a list marker box
|
|
|
|
*
|
|
|
|
* \param box Box to attach marker to
|
|
|
|
* \param title Current title attribute
|
2014-11-10 23:15:14 +03:00
|
|
|
* \param ctx Box construction context
|
2011-09-29 23:15:54 +04:00
|
|
|
* \param parent Current block-level container
|
2014-11-10 23:15:14 +03:00
|
|
|
* \return true on success, false on memory exhaustion
|
2011-09-29 23:15:54 +04:00
|
|
|
*/
|
2014-10-15 12:35:43 +04:00
|
|
|
static bool box_construct_marker(struct box *box, const char *title,
|
2012-10-03 22:24:58 +04:00
|
|
|
struct box_construct_ctx *ctx, struct box *parent)
|
2011-09-29 23:15:54 +04:00
|
|
|
{
|
|
|
|
lwc_string *image_uri;
|
|
|
|
struct box *marker;
|
|
|
|
|
2014-10-15 12:35:43 +04:00
|
|
|
marker = box_create(NULL, box->style, false, NULL, NULL, title,
|
2012-10-03 22:24:58 +04:00
|
|
|
NULL, ctx->bctx);
|
2011-09-29 23:15:54 +04:00
|
|
|
if (marker == false)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
marker->type = BOX_BLOCK;
|
|
|
|
|
|
|
|
/** \todo marker content (list-style-type) */
|
|
|
|
switch (css_computed_list_style_type(box->style)) {
|
|
|
|
case CSS_LIST_STYLE_TYPE_DISC:
|
|
|
|
/* 2022 BULLET */
|
|
|
|
marker->text = (char *) "\342\200\242";
|
|
|
|
marker->length = 3;
|
|
|
|
break;
|
|
|
|
case CSS_LIST_STYLE_TYPE_CIRCLE:
|
|
|
|
/* 25CB WHITE CIRCLE */
|
|
|
|
marker->text = (char *) "\342\227\213";
|
|
|
|
marker->length = 3;
|
|
|
|
break;
|
|
|
|
case CSS_LIST_STYLE_TYPE_SQUARE:
|
|
|
|
/* 25AA BLACK SMALL SQUARE */
|
|
|
|
marker->text = (char *) "\342\226\252";
|
|
|
|
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:
|
2005-03-28 23:17:06 +04:00
|
|
|
default:
|
2011-09-29 23:15:54 +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
|
|
|
|
* ...
|
|
|
|
*/
|
2014-07-18 12:20:07 +04:00
|
|
|
while (last != NULL && last->list_marker == NULL) {
|
|
|
|
struct box *last_inner = last;
|
|
|
|
|
|
|
|
while (last_inner != NULL) {
|
|
|
|
if (last_inner->list_marker != NULL)
|
|
|
|
break;
|
2014-07-18 12:30:27 +04:00
|
|
|
if (last_inner->type ==
|
|
|
|
BOX_INLINE_CONTAINER ||
|
|
|
|
last_inner->type ==
|
|
|
|
BOX_FLOAT_LEFT ||
|
|
|
|
last_inner->type ==
|
|
|
|
BOX_FLOAT_RIGHT) {
|
|
|
|
last_inner = last_inner->last;
|
|
|
|
} else {
|
|
|
|
last_inner = NULL;
|
|
|
|
}
|
2014-07-18 12:20:07 +04:00
|
|
|
}
|
|
|
|
if (last_inner != NULL) {
|
|
|
|
last = last_inner;
|
|
|
|
} else {
|
|
|
|
last = last->prev;
|
|
|
|
}
|
2011-09-29 23:15:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (last && last->list_marker) {
|
|
|
|
marker->rows = last->list_marker->rows + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-03 22:24:58 +04:00
|
|
|
marker->text = talloc_array(ctx->bctx, char, 20);
|
2011-09-29 23:15:54 +04:00
|
|
|
if (marker->text == NULL)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2014-10-15 12:35:43 +04:00
|
|
|
if (css_computed_list_style_image(box->style, &image_uri) == CSS_LIST_STYLE_IMAGE_URI &&
|
2012-03-22 13:34:34 +04:00
|
|
|
(image_uri != NULL) &&
|
|
|
|
(nsoption_bool(foreground_images) == true)) {
|
2011-10-04 14:23:47 +04:00
|
|
|
nsurl *url;
|
|
|
|
nserror error;
|
|
|
|
|
|
|
|
/* TODO: we get a url out of libcss as a lwc string, but
|
|
|
|
* earlier we already had it as a nsurl after we
|
|
|
|
* nsurl_joined it. Can this be improved?
|
|
|
|
* For now, just making another nsurl. */
|
|
|
|
error = nsurl_create(lwc_string_data(image_uri), &url);
|
|
|
|
if (error != NSERROR_OK)
|
2011-09-29 23:15:54 +04:00
|
|
|
return false;
|
2011-10-04 14:23:47 +04:00
|
|
|
|
2012-10-03 22:24:58 +04:00
|
|
|
if (html_fetch_object(ctx->content, url, marker, image_types,
|
|
|
|
ctx->content->base.available_width, 1000, false) ==
|
2011-10-04 14:23:47 +04:00
|
|
|
false) {
|
|
|
|
nsurl_unref(url);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
nsurl_unref(url);
|
2011-09-29 23:15:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
box->list_marker = marker;
|
|
|
|
marker->parent = box;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Construct the box required for a generated element.
|
|
|
|
*
|
|
|
|
* \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 generated content
|
|
|
|
* \param style Complete computed style for pseudo element, or NULL
|
|
|
|
*
|
|
|
|
* TODO:
|
|
|
|
* This is currently incomplete. It just does enough to support the clearfix
|
|
|
|
* hack. ( http://www.positioniseverything.net/easyclearing.html )
|
|
|
|
*/
|
2012-03-24 03:18:04 +04:00
|
|
|
static void box_construct_generate(dom_node *n, html_content *content,
|
2011-09-29 23:15:54 +04:00
|
|
|
struct box *box, const css_computed_style *style)
|
|
|
|
{
|
|
|
|
struct box *gen = NULL;
|
|
|
|
const css_computed_content_item *c_item;
|
|
|
|
|
|
|
|
/* Nothing to generate if the parent box is not a block */
|
|
|
|
if (box->type != BOX_BLOCK)
|
|
|
|
return;
|
|
|
|
|
2014-10-15 12:35:43 +04:00
|
|
|
/* To determine if an element has a pseudo element, we select
|
|
|
|
* for it and test to see if the returned style's content
|
2011-09-29 23:15:54 +04:00
|
|
|
* property is set to normal. */
|
|
|
|
if (style == NULL ||
|
|
|
|
css_computed_content(style, &c_item) ==
|
|
|
|
CSS_CONTENT_NORMAL) {
|
|
|
|
/* No pseudo element */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* create box for this element */
|
|
|
|
if (css_computed_display(style, box_is_root(n)) == CSS_DISPLAY_BLOCK) {
|
|
|
|
/* currently only support block level elements */
|
|
|
|
|
2014-10-15 12:35:43 +04:00
|
|
|
/** \todo Not wise to drop const from the computed style */
|
2011-09-29 23:15:54 +04:00
|
|
|
gen = box_create(NULL, (css_computed_style *) style,
|
2012-10-03 22:24:58 +04:00
|
|
|
false, NULL, NULL, NULL, NULL, content->bctx);
|
2011-09-29 23:15:54 +04:00
|
|
|
if (gen == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* set box type from computed display */
|
|
|
|
gen->type = box_map[css_computed_display(
|
|
|
|
style, box_is_root(n))];
|
|
|
|
|
|
|
|
box_add_child(box, gen);
|
2005-03-28 23:17:06 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-29 23:15:54 +04:00
|
|
|
/**
|
|
|
|
* Extract transient construction properties
|
|
|
|
*
|
|
|
|
* \param n Current DOM node to convert
|
|
|
|
* \param props Property object to populate
|
|
|
|
*/
|
2014-10-15 12:35:43 +04:00
|
|
|
static void box_extract_properties(dom_node *n,
|
2011-09-29 23:15:54 +04:00
|
|
|
struct box_construct_props *props)
|
|
|
|
{
|
|
|
|
memset(props, 0, sizeof(*props));
|
|
|
|
|
|
|
|
props->node_is_root = box_is_root(n);
|
|
|
|
|
|
|
|
/* Extract properties from containing DOM node */
|
|
|
|
if (props->node_is_root == false) {
|
2012-03-24 22:47:51 +04:00
|
|
|
dom_node *current_node = n;
|
|
|
|
dom_node *parent_node = NULL;
|
2011-09-29 23:15:54 +04:00
|
|
|
struct box *parent_box;
|
2012-03-24 22:47:51 +04:00
|
|
|
dom_exception err;
|
2011-09-29 23:15:54 +04:00
|
|
|
|
|
|
|
/* Find ancestor node containing parent box */
|
2012-03-24 22:47:51 +04:00
|
|
|
while (true) {
|
|
|
|
err = dom_node_get_parent_node(current_node,
|
|
|
|
&parent_node);
|
|
|
|
if (err != DOM_NO_ERR || parent_node == NULL)
|
|
|
|
break;
|
2011-09-29 23:15:54 +04:00
|
|
|
|
2012-03-24 22:47:51 +04:00
|
|
|
parent_box = box_for_node(parent_node);
|
2011-09-29 23:15:54 +04:00
|
|
|
|
2012-03-24 22:47:51 +04:00
|
|
|
if (parent_box != NULL) {
|
|
|
|
props->parent_style = parent_box->style;
|
|
|
|
props->href = parent_box->href;
|
|
|
|
props->target = parent_box->target;
|
|
|
|
props->title = parent_box->title;
|
2011-09-29 23:15:54 +04:00
|
|
|
|
2012-03-24 22:47:51 +04:00
|
|
|
dom_node_unref(parent_node);
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
if (current_node != n)
|
|
|
|
dom_node_unref(current_node);
|
|
|
|
current_node = parent_node;
|
|
|
|
parent_node = NULL;
|
|
|
|
}
|
|
|
|
}
|
2014-10-15 12:35:43 +04:00
|
|
|
|
2011-09-29 23:15:54 +04:00
|
|
|
/* Find containing block (may be parent) */
|
2012-03-24 22:47:51 +04:00
|
|
|
while (true) {
|
|
|
|
struct box *b;
|
|
|
|
|
|
|
|
err = dom_node_get_parent_node(current_node,
|
|
|
|
&parent_node);
|
|
|
|
if (err != DOM_NO_ERR || parent_node == NULL) {
|
|
|
|
if (current_node != n)
|
|
|
|
dom_node_unref(current_node);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (current_node != n)
|
|
|
|
dom_node_unref(current_node);
|
|
|
|
|
|
|
|
b = box_for_node(parent_node);
|
2011-09-29 23:15:54 +04:00
|
|
|
|
|
|
|
/* Children of nodes that created an inline box
|
|
|
|
* will generate boxes which are attached as
|
2014-10-15 12:35:43 +04:00
|
|
|
* _siblings_ of the box generated for their
|
2011-09-29 23:15:54 +04:00
|
|
|
* parent node. Note, however, that we'll still
|
|
|
|
* use the parent node's styling as the parent
|
|
|
|
* style, above. */
|
2014-10-15 12:35:43 +04:00
|
|
|
if (b != NULL && b->type != BOX_INLINE &&
|
2011-09-29 23:15:54 +04:00
|
|
|
b->type != BOX_BR) {
|
|
|
|
props->containing_block = b;
|
2012-03-24 22:47:51 +04:00
|
|
|
|
|
|
|
dom_node_unref(parent_node);
|
2011-09-29 23:15:54 +04:00
|
|
|
break;
|
2012-03-24 22:47:51 +04:00
|
|
|
} else {
|
|
|
|
current_node = parent_node;
|
|
|
|
parent_node = NULL;
|
2011-09-29 23:15:54 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Compute current inline container, if any */
|
2014-10-15 12:35:43 +04:00
|
|
|
if (props->containing_block != NULL &&
|
2011-09-29 23:15:54 +04:00
|
|
|
props->containing_block->last != NULL &&
|
2014-10-15 12:35:43 +04:00
|
|
|
props->containing_block->last->type ==
|
2011-09-29 23:15:54 +04:00
|
|
|
BOX_INLINE_CONTAINER)
|
|
|
|
props->inline_container = props->containing_block->last;
|
|
|
|
}
|
2005-03-28 23:17:06 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Construct the box tree for an XML element.
|
|
|
|
*
|
2011-09-29 23:15:54 +04:00
|
|
|
* \param ctx Tree construction context
|
|
|
|
* \param convert_children Whether to convert children
|
2005-03-28 23:17:06 +04:00
|
|
|
* \return true on success, false on memory exhaustion
|
|
|
|
*/
|
|
|
|
|
2011-09-29 23:15:54 +04:00
|
|
|
bool box_construct_element(struct box_construct_ctx *ctx,
|
|
|
|
bool *convert_children)
|
2005-03-26 04:12:27 +03:00
|
|
|
{
|
2012-03-24 22:47:51 +04:00
|
|
|
dom_string *title0, *s;
|
2011-10-29 15:37:05 +04:00
|
|
|
lwc_string *id = NULL;
|
2012-03-24 22:47:51 +04:00
|
|
|
struct box *box = NULL, *old_box;
|
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;
|
2009-07-24 03:05:34 +04:00
|
|
|
lwc_string *bgimage_uri;
|
2012-03-24 22:47:51 +04:00
|
|
|
dom_exception err;
|
2011-09-29 23:15:54 +04:00
|
|
|
struct box_construct_props props;
|
|
|
|
|
|
|
|
assert(ctx->n != NULL);
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2011-09-29 23:15:54 +04:00
|
|
|
box_extract_properties(ctx->n, &props);
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2011-09-29 23:15:54 +04:00
|
|
|
if (props.containing_block != NULL) {
|
2014-10-15 12:35:43 +04:00
|
|
|
/* In case the containing block is a pre block, we clear
|
|
|
|
* the PRE_STRIP flag since it is not used if we follow
|
2011-09-29 23:15:54 +04:00
|
|
|
* the pre with a tag */
|
|
|
|
props.containing_block->flags &= ~PRE_STRIP;
|
|
|
|
}
|
2006-07-04 01:41:25 +04:00
|
|
|
|
2011-09-29 23:15:54 +04:00
|
|
|
styles = box_get_style(ctx->content, props.parent_style, ctx->n);
|
|
|
|
if (styles == NULL)
|
2005-04-09 13:47:37 +04:00
|
|
|
return false;
|
2005-03-28 23:17:06 +04:00
|
|
|
|
2011-09-29 23:15:54 +04:00
|
|
|
/* Extract title attribute, if present */
|
2014-01-24 22:58:12 +04:00
|
|
|
err = dom_element_get_attribute(ctx->n, corestring_dom_title, &title0);
|
2012-03-24 22:47:51 +04:00
|
|
|
if (err != DOM_NO_ERR)
|
|
|
|
return false;
|
2011-01-05 00:52:43 +03:00
|
|
|
|
2012-03-24 22:47:51 +04:00
|
|
|
if (title0 != NULL) {
|
|
|
|
char *t = squash_whitespace(dom_string_data(title0));
|
|
|
|
|
|
|
|
dom_string_unref(title0);
|
2011-01-05 00:52:43 +03:00
|
|
|
|
2011-09-29 23:15:54 +04:00
|
|
|
if (t == NULL)
|
2005-04-09 13:47:37 +04:00
|
|
|
return false;
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2012-10-03 22:24:58 +04:00
|
|
|
props.title = talloc_strdup(ctx->bctx, t);
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2011-09-29 23:15:54 +04:00
|
|
|
free(t);
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2011-09-29 23:15:54 +04:00
|
|
|
if (props.title == NULL)
|
2005-04-09 13:47:37 +04:00
|
|
|
return false;
|
2005-03-28 23:17:06 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 23:15:54 +04:00
|
|
|
/* Extract id attribute, if present */
|
2014-01-24 22:58:12 +04:00
|
|
|
err = dom_element_get_attribute(ctx->n, corestring_dom_id, &s);
|
2012-03-24 22:47:51 +04:00
|
|
|
if (err != DOM_NO_ERR)
|
|
|
|
return false;
|
2011-10-29 15:37:05 +04:00
|
|
|
|
2012-03-24 22:47:51 +04:00
|
|
|
if (s != NULL) {
|
|
|
|
err = dom_string_intern(s, &id);
|
|
|
|
if (err != DOM_NO_ERR)
|
2011-10-29 15:37:05 +04:00
|
|
|
id = NULL;
|
2012-03-24 22:47:51 +04:00
|
|
|
|
|
|
|
dom_string_unref(s);
|
2011-10-29 15:37:05 +04:00
|
|
|
}
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2011-01-05 22:36:05 +03:00
|
|
|
box = box_create(styles, styles->styles[CSS_PSEUDO_ELEMENT_NONE], false,
|
2011-10-04 00:28:29 +04:00
|
|
|
props.href, props.target, props.title, id,
|
2012-10-03 22:24:58 +04:00
|
|
|
ctx->bctx);
|
2011-09-29 23:15:54 +04:00
|
|
|
if (box == NULL)
|
2005-04-09 13:47:37 +04:00
|
|
|
return false;
|
2011-09-29 23:15:54 +04:00
|
|
|
|
|
|
|
/* If this is the root box, add it to the context */
|
|
|
|
if (props.node_is_root)
|
|
|
|
ctx->root_box = box;
|
|
|
|
|
|
|
|
/* Deal with colspan/rowspan */
|
2014-01-24 22:58:12 +04:00
|
|
|
err = dom_element_get_attribute(ctx->n, corestring_dom_colspan, &s);
|
2012-03-24 22:47:51 +04:00
|
|
|
if (err != DOM_NO_ERR)
|
|
|
|
return false;
|
2011-09-29 23:15:54 +04:00
|
|
|
|
2012-03-24 22:47:51 +04:00
|
|
|
if (s != NULL) {
|
|
|
|
const char *val = dom_string_data(s);
|
|
|
|
|
|
|
|
if ('0' <= val[0] && val[0] <= '9')
|
|
|
|
box->columns = strtol(val, NULL, 10);
|
|
|
|
|
|
|
|
dom_string_unref(s);
|
2011-09-29 23:15:54 +04:00
|
|
|
}
|
|
|
|
|
2014-01-24 22:58:12 +04:00
|
|
|
err = dom_element_get_attribute(ctx->n, corestring_dom_rowspan, &s);
|
2012-03-24 22:47:51 +04:00
|
|
|
if (err != DOM_NO_ERR)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (s != NULL) {
|
|
|
|
const char *val = dom_string_data(s);
|
2011-09-29 23:15:54 +04:00
|
|
|
|
2012-03-24 22:47:51 +04:00
|
|
|
if ('0' <= val[0] && val[0] <= '9')
|
|
|
|
box->rows = strtol(val, NULL, 10);
|
|
|
|
|
|
|
|
dom_string_unref(s);
|
2011-09-29 23:15:54 +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) &&
|
2011-09-29 23:15:54 +04:00
|
|
|
(css_computed_display_static(box->style) ==
|
2009-07-24 03:05:34 +04:00
|
|
|
CSS_DISPLAY_INLINE ||
|
2011-09-29 23:15:54 +04:00
|
|
|
css_computed_display_static(box->style) ==
|
2009-07-24 03:05:34 +04:00
|
|
|
CSS_DISPLAY_INLINE_BLOCK ||
|
2011-09-29 23:15:54 +04: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
|
2011-09-29 23:15:54 +04:00
|
|
|
* into inline block so that the boxes are constructed in an
|
|
|
|
* inline container as if they were not absolutely positioned.
|
2009-07-24 03:05:34 +04:00
|
|
|
* Layout expects and handles this. */
|
|
|
|
box->type = box_map[CSS_DISPLAY_INLINE_BLOCK];
|
2013-07-10 15:27:56 +04:00
|
|
|
} else if (props.node_is_root) {
|
|
|
|
/* Special case for root element: force it to BLOCK, or the
|
|
|
|
* rest of the layout will break. */
|
|
|
|
box->type = BOX_BLOCK;
|
2009-07-24 03:05:34 +04:00
|
|
|
} else {
|
|
|
|
/* Normal mapping */
|
2014-10-15 12:35:43 +04:00
|
|
|
box->type = box_map[css_computed_display(box->style,
|
2011-09-29 23:15:54 +04:00
|
|
|
props.node_is_root)];
|
2009-07-24 03:05:34 +04:00
|
|
|
}
|
2005-04-09 13:47:37 +04:00
|
|
|
|
2012-03-24 22:47:51 +04:00
|
|
|
err = dom_node_get_node_name(ctx->n, &s);
|
|
|
|
if (err != DOM_NO_ERR || s == NULL)
|
|
|
|
return false;
|
|
|
|
|
2011-09-29 23:15:54 +04:00
|
|
|
/* Special elements */
|
2012-03-24 22:47:51 +04:00
|
|
|
element = bsearch(dom_string_data(s), element_table,
|
2005-03-28 23:17:06 +04:00
|
|
|
ELEMENT_TABLE_COUNT, sizeof(element_table[0]),
|
2012-07-08 14:45:27 +04:00
|
|
|
(int (*)(const void *, const void *)) strcasecmp);
|
2012-03-24 22:47:51 +04:00
|
|
|
|
|
|
|
dom_string_unref(s);
|
|
|
|
|
2011-09-29 23:15:54 +04:00
|
|
|
if (element != NULL) {
|
|
|
|
/* A special convert function exists for this element */
|
2014-10-15 12:35:43 +04:00
|
|
|
if (element->convert(ctx->n, ctx->content, box,
|
2011-09-29 23:15:54 +04:00
|
|
|
convert_children) == false)
|
2005-04-09 13:47:37 +04:00
|
|
|
return false;
|
2005-03-28 23:17:06 +04:00
|
|
|
}
|
2008-02-25 19:37:48 +03:00
|
|
|
|
2016-02-09 19:42:28 +03:00
|
|
|
/* Handle the :before pseudo element */
|
|
|
|
if (!(box->flags & IS_REPLACED)) {
|
|
|
|
box_construct_generate(ctx->n, ctx->content, box,
|
|
|
|
box->styles->styles[CSS_PSEUDO_ELEMENT_BEFORE]);
|
|
|
|
}
|
|
|
|
|
2013-07-10 15:27:56 +04:00
|
|
|
if (box->type == BOX_NONE || (css_computed_display(box->style,
|
|
|
|
props.node_is_root) == CSS_DISPLAY_NONE &&
|
|
|
|
props.node_is_root == false)) {
|
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;
|
|
|
|
|
2011-09-29 23:15:54 +04:00
|
|
|
/* Invalidate associated gadget, if any */
|
|
|
|
if (box->gadget != NULL) {
|
2008-02-07 03:50:37 +03:00
|
|
|
box->gadget->box = NULL;
|
|
|
|
box->gadget = NULL;
|
|
|
|
}
|
|
|
|
|
2011-09-29 23:15:54 +04:00
|
|
|
/* Can't do this, because the lifetimes of boxes and gadgets
|
|
|
|
* are inextricably linked. Fortunately, talloc will save us
|
|
|
|
* (for now) */
|
2007-04-06 16:05:25 +04:00
|
|
|
/* box_free_box(box); */
|
2011-09-29 23:15:54 +04:00
|
|
|
|
|
|
|
*convert_children = false;
|
|
|
|
|
2005-07-03 00:08:24 +04:00
|
|
|
return true;
|
|
|
|
}
|
2005-03-28 23:17:06 +04:00
|
|
|
|
2012-11-30 16:29:54 +04:00
|
|
|
/* Attach DOM node to box */
|
2014-01-24 22:58:12 +04:00
|
|
|
err = dom_node_set_user_data(ctx->n,
|
2014-10-15 12:35:43 +04:00
|
|
|
corestring_dom___ns_key_box_node_data, box, NULL,
|
2012-03-25 02:30:28 +04:00
|
|
|
(void *) &old_box);
|
2012-03-24 22:47:51 +04:00
|
|
|
if (err != DOM_NO_ERR)
|
|
|
|
return false;
|
2011-09-29 23:15:54 +04:00
|
|
|
|
2012-11-30 16:29:54 +04:00
|
|
|
/* Attach box to DOM node */
|
|
|
|
box->node = dom_node_ref(ctx->n);
|
|
|
|
|
2011-09-29 23:15:54 +04:00
|
|
|
if (props.inline_container == NULL &&
|
2005-04-09 13:47:37 +04:00
|
|
|
(box->type == BOX_INLINE ||
|
2011-09-29 23:15:54 +04:00
|
|
|
box->type == BOX_BR ||
|
|
|
|
box->type == BOX_INLINE_BLOCK ||
|
|
|
|
css_computed_float(box->style) == CSS_FLOAT_LEFT ||
|
2014-01-04 21:54:43 +04:00
|
|
|
css_computed_float(box->style) == CSS_FLOAT_RIGHT) &&
|
|
|
|
props.node_is_root == false) {
|
2011-09-29 23:15:54 +04:00
|
|
|
/* Found an inline child of a block without a current container
|
|
|
|
* (i.e. this box is the first child of its parent, or was
|
|
|
|
* preceded by block-level siblings) */
|
2014-10-15 12:35:43 +04:00
|
|
|
assert(props.containing_block != NULL &&
|
2014-01-04 21:54:43 +04:00
|
|
|
"Box must have containing block.");
|
2011-09-29 23:15:54 +04:00
|
|
|
|
2014-10-15 12:35:43 +04:00
|
|
|
props.inline_container = box_create(NULL, NULL, false, NULL,
|
2012-10-03 22:24:58 +04:00
|
|
|
NULL, NULL, NULL, ctx->bctx);
|
2011-09-29 23:15:54 +04:00
|
|
|
if (props.inline_container == NULL)
|
2005-04-09 13:47:37 +04:00
|
|
|
return false;
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2011-09-29 23:15:54 +04:00
|
|
|
props.inline_container->type = BOX_INLINE_CONTAINER;
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2011-09-29 23:15:54 +04:00
|
|
|
box_add_child(props.containing_block, props.inline_container);
|
2005-04-09 13:47:37 +04:00
|
|
|
}
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2011-09-29 23:15:54 +04:00
|
|
|
/* Kick off fetch for any background image */
|
2014-10-15 12:35:43 +04:00
|
|
|
if (css_computed_background_image(box->style, &bgimage_uri) ==
|
2011-12-23 23:48:09 +04:00
|
|
|
CSS_BACKGROUND_IMAGE_IMAGE && bgimage_uri != NULL &&
|
2014-09-25 12:50:24 +04:00
|
|
|
nsoption_bool(background_images) == true) {
|
2011-10-04 14:23:47 +04:00
|
|
|
nsurl *url;
|
|
|
|
nserror error;
|
|
|
|
|
|
|
|
/* TODO: we get a url out of libcss as a lwc string, but
|
|
|
|
* earlier we already had it as a nsurl after we
|
|
|
|
* nsurl_joined it. Can this be improved?
|
|
|
|
* For now, just making another nsurl. */
|
|
|
|
error = nsurl_create(lwc_string_data(bgimage_uri), &url);
|
2014-09-25 12:50:24 +04:00
|
|
|
if (error == NSERROR_OK) {
|
|
|
|
/* Fetch image if we got a valid URL */
|
|
|
|
if (html_fetch_object(ctx->content, url, box,
|
|
|
|
image_types,
|
|
|
|
ctx->content->base.available_width,
|
|
|
|
1000, true) == false) {
|
|
|
|
nsurl_unref(url);
|
|
|
|
return false;
|
|
|
|
}
|
2011-10-04 14:23:47 +04:00
|
|
|
nsurl_unref(url);
|
|
|
|
}
|
2011-09-29 23:15:54 +04:00
|
|
|
}
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2011-09-29 23:15:54 +04:00
|
|
|
if (*convert_children)
|
|
|
|
box->flags |= CONVERT_CHILDREN;
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2014-10-15 12:35:43 +04:00
|
|
|
if (box->type == BOX_INLINE || box->type == BOX_BR ||
|
2011-09-29 23:15:54 +04:00
|
|
|
box->type == BOX_INLINE_BLOCK) {
|
2014-10-15 12:35:43 +04:00
|
|
|
/* Inline container must exist, as we'll have
|
2011-09-29 23:15:54 +04:00
|
|
|
* created it above if it didn't */
|
|
|
|
assert(props.inline_container != NULL);
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2011-09-29 23:15:54 +04:00
|
|
|
box_add_child(props.inline_container, box);
|
2005-04-09 13:47:37 +04:00
|
|
|
} else {
|
2011-09-29 23:15:54 +04:00
|
|
|
if (css_computed_display(box->style, props.node_is_root) ==
|
2009-07-24 03:05:34 +04:00
|
|
|
CSS_DISPLAY_LIST_ITEM) {
|
2011-09-29 23:15:54 +04:00
|
|
|
/* List item: compute marker */
|
2012-10-03 22:24:58 +04:00
|
|
|
if (box_construct_marker(box, props.title, ctx,
|
2011-09-29 23:15:54 +04:00
|
|
|
props.containing_block) == false)
|
2006-11-05 15:58:24 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-01-04 21:54:43 +04:00
|
|
|
if (props.node_is_root == false &&
|
|
|
|
(css_computed_float(box->style) ==
|
|
|
|
CSS_FLOAT_LEFT ||
|
2014-10-15 12:35:43 +04:00
|
|
|
css_computed_float(box->style) ==
|
2014-01-04 21:54:43 +04:00
|
|
|
CSS_FLOAT_RIGHT)) {
|
2011-09-29 23:15:54 +04:00
|
|
|
/* Float: insert a float between the parent and box. */
|
|
|
|
struct box *flt = box_create(NULL, NULL, false,
|
2014-10-15 12:35:43 +04:00
|
|
|
props.href, props.target, props.title,
|
2012-10-03 22:24:58 +04:00
|
|
|
NULL, ctx->bctx);
|
2011-09-29 23:15:54 +04:00
|
|
|
if (flt == NULL)
|
2009-04-29 14:44:20 +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_LEFT)
|
2011-09-29 23:15:54 +04:00
|
|
|
flt->type = BOX_FLOAT_LEFT;
|
2009-04-29 14:44:20 +04:00
|
|
|
else
|
2011-09-29 23:15:54 +04:00
|
|
|
flt->type = BOX_FLOAT_RIGHT;
|
|
|
|
|
|
|
|
box_add_child(props.inline_container, flt);
|
|
|
|
box_add_child(flt, box);
|
|
|
|
} else {
|
|
|
|
/* Non-floated block-level box: add to containing block
|
|
|
|
* if there is one. If we're the root box, then there
|
|
|
|
* won't be. */
|
|
|
|
if (props.containing_block != NULL)
|
|
|
|
box_add_child(props.containing_block, box);
|
2009-04-29 14:44:20 +04:00
|
|
|
}
|
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
|
|
|
/**
|
2011-09-29 23:15:54 +04:00
|
|
|
* Complete construction of the box tree for an element.
|
2011-01-05 00:52:43 +03:00
|
|
|
*
|
2011-09-29 23:15:54 +04:00
|
|
|
* \param n DOM node to construct for
|
|
|
|
* \param content Containing document
|
2011-01-05 00:52:43 +03:00
|
|
|
*
|
2011-09-29 23:15:54 +04:00
|
|
|
* This will be called after all children of an element have been processed
|
2011-01-05 00:52:43 +03:00
|
|
|
*/
|
2012-03-24 03:18:04 +04:00
|
|
|
void box_construct_element_after(dom_node *n, html_content *content)
|
2011-01-05 00:52:43 +03:00
|
|
|
{
|
2011-09-29 23:15:54 +04:00
|
|
|
struct box_construct_props props;
|
|
|
|
struct box *box = box_for_node(n);
|
2011-01-05 00:52:43 +03:00
|
|
|
|
2011-09-29 23:15:54 +04:00
|
|
|
assert(box != NULL);
|
2011-01-05 00:52:43 +03:00
|
|
|
|
2011-09-29 23:15:54 +04:00
|
|
|
box_extract_properties(n, &props);
|
2011-01-05 22:36:05 +03:00
|
|
|
|
2011-09-29 23:15:54 +04:00
|
|
|
if (box->type == BOX_INLINE || box->type == BOX_BR) {
|
|
|
|
/* Insert INLINE_END into containing block */
|
|
|
|
struct box *inline_end;
|
2012-03-24 22:47:51 +04:00
|
|
|
bool has_children;
|
|
|
|
dom_exception err;
|
|
|
|
|
|
|
|
err = dom_node_has_child_nodes(n, &has_children);
|
|
|
|
if (err != DOM_NO_ERR)
|
|
|
|
return;
|
2011-09-29 23:15:54 +04:00
|
|
|
|
2014-10-15 12:35:43 +04:00
|
|
|
if (has_children == false ||
|
2011-09-29 23:15:54 +04:00
|
|
|
(box->flags & CONVERT_CHILDREN) == 0) {
|
|
|
|
/* No children, or didn't want children converted */
|
2011-01-05 00:52:43 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-09-29 23:15:54 +04:00
|
|
|
if (props.inline_container == NULL) {
|
|
|
|
/* Create inline container if we don't have one */
|
2014-10-15 12:35:43 +04:00
|
|
|
props.inline_container = box_create(NULL, NULL, false,
|
2012-10-03 22:24:58 +04:00
|
|
|
NULL, NULL, NULL, NULL, content->bctx);
|
2011-09-29 23:15:54 +04:00
|
|
|
if (props.inline_container == NULL)
|
|
|
|
return;
|
2011-01-05 00:52:43 +03:00
|
|
|
|
2011-09-29 23:15:54 +04:00
|
|
|
props.inline_container->type = BOX_INLINE_CONTAINER;
|
|
|
|
|
2014-10-15 12:35:43 +04:00
|
|
|
box_add_child(props.containing_block,
|
2011-09-29 23:15:54 +04:00
|
|
|
props.inline_container);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline_end = box_create(NULL, box->style, false,
|
2014-10-15 12:35:43 +04:00
|
|
|
box->href, box->target, box->title,
|
2011-10-29 16:03:54 +04:00
|
|
|
box->id == NULL ? NULL :
|
2012-10-03 22:24:58 +04:00
|
|
|
lwc_string_ref(box->id), content->bctx);
|
2011-09-29 23:15:54 +04:00
|
|
|
if (inline_end != NULL) {
|
|
|
|
inline_end->type = BOX_INLINE_END;
|
|
|
|
|
|
|
|
assert(props.inline_container != NULL);
|
|
|
|
|
|
|
|
box_add_child(props.inline_container, inline_end);
|
|
|
|
|
|
|
|
box->inline_end = inline_end;
|
|
|
|
inline_end->inline_end = box;
|
|
|
|
}
|
2016-02-09 19:42:28 +03:00
|
|
|
} else if (!(box->flags & IS_REPLACED)) {
|
2011-09-29 23:15:54 +04:00
|
|
|
/* Handle the :after pseudo element */
|
|
|
|
box_construct_generate(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
|
|
|
/**
|
|
|
|
* Construct the box tree for an XML text node.
|
|
|
|
*
|
2011-09-29 23:15:54 +04:00
|
|
|
* \param ctx Tree construction context
|
2005-03-28 23:17:06 +04:00
|
|
|
* \return true on success, false on memory exhaustion
|
|
|
|
*/
|
|
|
|
|
2011-09-29 23:15:54 +04:00
|
|
|
bool box_construct_text(struct box_construct_ctx *ctx)
|
2005-03-28 23:17:06 +04:00
|
|
|
{
|
2011-09-29 23:15:54 +04:00
|
|
|
struct box_construct_props props;
|
|
|
|
struct box *box = NULL;
|
2012-03-24 22:47:51 +04:00
|
|
|
dom_string *content;
|
|
|
|
dom_exception err;
|
2005-03-28 23:17:06 +04:00
|
|
|
|
2011-09-29 23:15:54 +04:00
|
|
|
assert(ctx->n != NULL);
|
2005-03-28 23:17:06 +04:00
|
|
|
|
2011-09-29 23:15:54 +04:00
|
|
|
box_extract_properties(ctx->n, &props);
|
|
|
|
|
|
|
|
assert(props.containing_block != NULL);
|
|
|
|
|
2012-03-24 22:47:51 +04:00
|
|
|
err = dom_characterdata_get_data(ctx->n, &content);
|
|
|
|
if (err != DOM_NO_ERR || content == NULL)
|
|
|
|
return false;
|
|
|
|
|
2014-10-15 12:35:43 +04:00
|
|
|
if (css_computed_white_space(props.parent_style) ==
|
2011-09-29 23:15:54 +04:00
|
|
|
CSS_WHITE_SPACE_NORMAL ||
|
2014-10-15 12:35:43 +04:00
|
|
|
css_computed_white_space(props.parent_style) ==
|
2009-07-24 03:05:34 +04:00
|
|
|
CSS_WHITE_SPACE_NOWRAP) {
|
2012-03-24 22:47:51 +04:00
|
|
|
char *text;
|
|
|
|
|
|
|
|
text = squash_whitespace(dom_string_data(content));
|
|
|
|
|
|
|
|
dom_string_unref(content);
|
|
|
|
|
2011-09-29 23:15:54 +04:00
|
|
|
if (text == NULL)
|
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) {
|
2011-09-29 23:15:54 +04:00
|
|
|
if (props.inline_container != NULL) {
|
|
|
|
assert(props.inline_container->last != NULL);
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2011-09-29 23:15:54 +04:00
|
|
|
props.inline_container->last->space =
|
2011-03-01 23:00:41 +03:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2011-09-29 23:15:54 +04:00
|
|
|
if (props.inline_container == NULL) {
|
|
|
|
/* Child of a block without a current container
|
2014-10-15 12:35:43 +04:00
|
|
|
* (i.e. this box is the first child of its parent, or
|
2011-09-29 23:15:54 +04:00
|
|
|
* was preceded by block-level siblings) */
|
2014-10-15 12:35:43 +04:00
|
|
|
props.inline_container = box_create(NULL, NULL, false,
|
2012-10-03 22:24:58 +04:00
|
|
|
NULL, NULL, NULL, NULL, ctx->bctx);
|
2011-09-29 23:15:54 +04:00
|
|
|
if (props.inline_container == NULL) {
|
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
|
|
|
|
2011-09-29 23:15:54 +04:00
|
|
|
props.inline_container->type = BOX_INLINE_CONTAINER;
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2014-10-15 12:35:43 +04:00
|
|
|
box_add_child(props.containing_block,
|
2011-09-29 23:15:54 +04:00
|
|
|
props.inline_container);
|
2005-03-26 04:12:27 +03:00
|
|
|
}
|
|
|
|
|
2014-10-15 12:35:43 +04:00
|
|
|
/** \todo Dropping const here is not clever */
|
|
|
|
box = box_create(NULL,
|
2011-09-29 23:15:54 +04:00
|
|
|
(css_computed_style *) props.parent_style,
|
2014-10-15 12:35:43 +04:00
|
|
|
false, props.href, props.target, props.title,
|
2012-10-03 22:24:58 +04:00
|
|
|
NULL, ctx->bctx);
|
2011-09-29 23:15:54 +04:00
|
|
|
if (box == NULL) {
|
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-05-23 01:50:14 +04:00
|
|
|
box->type = BOX_TEXT;
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2012-10-03 22:24:58 +04:00
|
|
|
box->text = talloc_strdup(ctx->bctx, text);
|
2005-04-09 13:47:37 +04:00
|
|
|
free(text);
|
2011-09-29 23:15:54 +04:00
|
|
|
if (box->text == NULL)
|
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
|
|
|
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
|
|
|
|
2014-10-15 12:35:43 +04:00
|
|
|
if (css_computed_text_transform(props.parent_style) !=
|
2009-07-24 03:05:34 +04:00
|
|
|
CSS_TEXT_TRANSFORM_NONE)
|
2005-03-26 04:12:27 +03:00
|
|
|
box_text_transform(box->text, box->length,
|
2011-09-29 23:15:54 +04:00
|
|
|
css_computed_text_transform(
|
|
|
|
props.parent_style));
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2011-09-29 23:15:54 +04:00
|
|
|
box_add_child(props.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 */
|
2012-10-03 20:14:11 +04:00
|
|
|
char *text;
|
|
|
|
size_t text_len = dom_string_byte_length(content);
|
|
|
|
size_t i;
|
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 =
|
2011-09-29 23:15:54 +04:00
|
|
|
css_computed_white_space(props.parent_style);
|
2009-07-24 03:05:34 +04:00
|
|
|
|
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);
|
|
|
|
|
2012-10-03 20:14:11 +04:00
|
|
|
text = malloc(text_len + 1);
|
2012-03-24 22:47:51 +04:00
|
|
|
dom_string_unref(content);
|
|
|
|
|
2011-09-29 23:15:54 +04:00
|
|
|
if (text == NULL)
|
2005-04-09 13:47:37 +04:00
|
|
|
return false;
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2012-10-03 20:14:11 +04:00
|
|
|
memcpy(text, dom_string_data(content), text_len);
|
|
|
|
text[text_len] = '\0';
|
|
|
|
|
|
|
|
/* TODO: Handle tabs properly */
|
2012-10-03 20:20:57 +04:00
|
|
|
for (i = 0; i < text_len; i++)
|
2012-10-03 20:14:11 +04:00
|
|
|
if (text[i] == '\t')
|
|
|
|
text[i] = ' ';
|
|
|
|
|
2014-10-15 12:35:43 +04:00
|
|
|
if (css_computed_text_transform(props.parent_style) !=
|
2009-07-24 03:05:34 +04:00
|
|
|
CSS_TEXT_TRANSFORM_NONE)
|
2005-03-26 04:12:27 +03:00
|
|
|
box_text_transform(text, strlen(text),
|
2011-09-29 23:15:54 +04:00
|
|
|
css_computed_text_transform(
|
|
|
|
props.parent_style));
|
2009-07-24 03:05:34 +04:00
|
|
|
|
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 */
|
2011-09-29 23:15:54 +04:00
|
|
|
if (props.containing_block->flags & PRE_STRIP) {
|
2006-04-04 14:56:21 +04:00
|
|
|
switch (*current) {
|
|
|
|
case '\n':
|
2011-09-29 23:15:54 +04:00
|
|
|
current++;
|
|
|
|
break;
|
2006-04-04 14:56:21 +04:00
|
|
|
case '\r':
|
|
|
|
current++;
|
2011-09-29 23:15:54 +04:00
|
|
|
if (*current == '\n')
|
|
|
|
current++;
|
2006-04-04 14:56:21 +04:00
|
|
|
break;
|
|
|
|
}
|
2011-09-29 23:15:54 +04:00
|
|
|
props.containing_block->flags &= ~PRE_STRIP;
|
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");
|
2012-10-03 20:14:11 +04:00
|
|
|
|
2005-03-26 04:12:27 +03:00
|
|
|
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
|
|
|
|
2011-09-29 23:15:54 +04:00
|
|
|
if (props.inline_container == NULL) {
|
|
|
|
/* Child of a block without a current container
|
2014-10-15 12:35:43 +04:00
|
|
|
* (i.e. this box is the first child of its
|
|
|
|
* parent, or was preceded by block-level
|
2011-09-29 23:15:54 +04:00
|
|
|
* siblings) */
|
|
|
|
props.inline_container = box_create(NULL, NULL,
|
2014-10-15 12:35:43 +04:00
|
|
|
false, NULL, NULL, NULL, NULL,
|
2012-10-03 22:24:58 +04:00
|
|
|
ctx->bctx);
|
2011-09-29 23:15:54 +04:00
|
|
|
if (props.inline_container == NULL) {
|
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
|
|
|
|
2014-10-15 12:35:43 +04:00
|
|
|
props.inline_container->type =
|
2005-03-26 04:12:27 +03:00
|
|
|
BOX_INLINE_CONTAINER;
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2014-10-15 12:35:43 +04:00
|
|
|
box_add_child(props.containing_block,
|
2011-09-29 23:15:54 +04:00
|
|
|
props.inline_container);
|
2005-03-26 04:12:27 +03:00
|
|
|
}
|
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,
|
2011-09-29 23:15:54 +04:00
|
|
|
(css_computed_style *) props.parent_style,
|
2014-10-15 12:35:43 +04:00
|
|
|
false, props.href, props.target, props.title,
|
2012-10-03 22:24:58 +04:00
|
|
|
NULL, ctx->bctx);
|
2011-09-29 23:15:54 +04:00
|
|
|
if (box == NULL) {
|
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-05-23 01:50:14 +04:00
|
|
|
box->type = BOX_TEXT;
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2012-10-03 22:24:58 +04:00
|
|
|
box->text = talloc_strdup(ctx->bctx, current);
|
2011-09-29 23:15:54 +04:00
|
|
|
if (box->text == NULL) {
|
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
|
|
|
box->length = strlen(box->text);
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2011-09-29 23:15:54 +04:00
|
|
|
box_add_child(props.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
|
|
|
|
2011-10-04 01:32:32 +04:00
|
|
|
if (current[0] != '\0') {
|
|
|
|
/* Linebreak: create new inline container */
|
|
|
|
props.inline_container = box_create(NULL, NULL,
|
2014-10-15 12:35:43 +04:00
|
|
|
false, NULL, NULL, NULL, NULL,
|
2012-10-03 22:24:58 +04:00
|
|
|
ctx->bctx);
|
2011-10-04 01:32:32 +04:00
|
|
|
if (props.inline_container == NULL) {
|
|
|
|
free(text);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-10-15 12:35:43 +04:00
|
|
|
props.inline_container->type =
|
2011-10-04 01:32:32 +04:00
|
|
|
BOX_INLINE_CONTAINER;
|
|
|
|
|
2014-10-15 12:35:43 +04:00
|
|
|
box_add_child(props.containing_block,
|
2011-10-04 01:32:32 +04:00
|
|
|
props.inline_container);
|
|
|
|
|
|
|
|
if (current[0] == '\r' && current[1] == '\n')
|
|
|
|
current += 2;
|
|
|
|
else
|
|
|
|
current++;
|
2005-03-26 04:12:27 +03:00
|
|
|
}
|
|
|
|
} 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-05-07 00:40:09 +04:00
|
|
|
css_select_results *box_get_style(html_content *c,
|
2012-03-24 03:18:04 +04:00
|
|
|
const css_computed_style *parent_style, dom_node *n)
|
2005-03-26 04:12:27 +03:00
|
|
|
{
|
2012-03-24 22:47:51 +04:00
|
|
|
dom_string *s;
|
|
|
|
dom_exception err;
|
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;
|
2011-05-07 00:40:09 +04:00
|
|
|
nscss_select_ctx ctx;
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2009-07-24 03:05:34 +04:00
|
|
|
/* Firstly, construct inline stylesheet, if any */
|
2014-01-24 22:58:12 +04:00
|
|
|
err = dom_element_get_attribute(n, corestring_dom_style, &s);
|
2012-03-24 22:47:51 +04:00
|
|
|
if (err != DOM_NO_ERR)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (s != NULL) {
|
2009-07-24 03:05:34 +04:00
|
|
|
inline_style = nscss_create_inline_style(
|
2012-03-24 22:47:51 +04:00
|
|
|
(const uint8_t *) dom_string_data(s),
|
|
|
|
dom_string_byte_length(s),
|
2011-10-03 19:56:47 +04:00
|
|
|
c->encoding,
|
2014-09-18 21:07:52 +04:00
|
|
|
nsurl_access(c->base_url),
|
2013-12-14 00:25:08 +04:00
|
|
|
c->quirks != DOM_DOCUMENT_QUIRKS_MODE_NONE);
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2012-03-24 22:47:51 +04:00
|
|
|
dom_string_unref(s);
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2009-07-24 03:05:34 +04:00
|
|
|
if (inline_style == NULL)
|
|
|
|
return NULL;
|
2008-02-25 19:37:48 +03:00
|
|
|
}
|
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
/* Populate selection context */
|
|
|
|
ctx.ctx = c->select_ctx;
|
2012-07-14 19:13:21 +04:00
|
|
|
ctx.quirks = (c->quirks == DOM_DOCUMENT_QUIRKS_MODE_FULL);
|
2011-05-07 00:40:09 +04:00
|
|
|
ctx.base_url = c->base_url;
|
2011-10-08 04:21:59 +04:00
|
|
|
ctx.universal = c->universal;
|
2013-12-19 18:21:15 +04:00
|
|
|
ctx.parent_style = parent_style;
|
2011-05-07 00:40:09 +04:00
|
|
|
|
2013-12-19 18:21:15 +04:00
|
|
|
/* Select style for element */
|
2013-12-14 00:25:08 +04:00
|
|
|
styles = nscss_get_style(&ctx, n, CSS_MEDIA_SCREEN, inline_style);
|
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
|
|
|
|
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))
|
2011-05-07 00:40:09 +04:00
|
|
|
content->background_colour = NS_TRANSPARENT;
|
2009-07-24 03:05:34 +04:00
|
|
|
else
|
2011-05-07 00:40:09 +04:00
|
|
|
content->background_colour = nscss_color_to_ns(color);
|
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
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2011-03-02 22:16:03 +03:00
|
|
|
box->flags |= PRE_STRIP;
|
2006-04-04 14:56:21 +04:00
|
|
|
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;
|
2011-10-04 00:28:29 +04:00
|
|
|
nsurl *url;
|
2012-03-24 22:47:51 +04:00
|
|
|
dom_string *s;
|
|
|
|
dom_exception err;
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2014-01-24 22:58:12 +04:00
|
|
|
err = dom_element_get_attribute(n, corestring_dom_href, &s);
|
2012-03-24 22:47:51 +04:00
|
|
|
if (err == DOM_NO_ERR && s != NULL) {
|
2016-01-21 17:09:57 +03:00
|
|
|
ok = box_extract_link(content, dom_string_data(s),
|
2011-10-04 00:28:29 +04:00
|
|
|
content->base_url, &url);
|
2012-03-24 22:47:51 +04:00
|
|
|
dom_string_unref(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) {
|
2011-10-04 00:28:29 +04:00
|
|
|
if (box->href != NULL)
|
|
|
|
nsurl_unref(box->href);
|
|
|
|
box->href = url;
|
2005-04-10 21:08:49 +04:00
|
|
|
}
|
2005-04-09 13:47:37 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* name and id share the same namespace */
|
2014-01-24 22:58:12 +04:00
|
|
|
err = dom_element_get_attribute(n, corestring_dom_name, &s);
|
2012-03-24 22:47:51 +04:00
|
|
|
if (err == DOM_NO_ERR && s != NULL) {
|
2011-10-29 15:37:05 +04:00
|
|
|
lwc_string *lwc_name;
|
|
|
|
|
2012-03-24 22:47:51 +04:00
|
|
|
err = dom_string_intern(s, &lwc_name);
|
2011-10-29 15:37:05 +04:00
|
|
|
|
2012-03-24 22:47:51 +04:00
|
|
|
dom_string_unref(s);
|
|
|
|
|
|
|
|
if (err == DOM_NO_ERR) {
|
2011-10-29 15:37:05 +04:00
|
|
|
/* name replaces existing id
|
|
|
|
* TODO: really? */
|
|
|
|
if (box->id != NULL)
|
|
|
|
lwc_string_unref(box->id);
|
|
|
|
|
|
|
|
box->id = lwc_name;
|
|
|
|
}
|
|
|
|
}
|
2005-04-09 13:47:37 +04:00
|
|
|
|
2005-08-21 02:52:20 +04:00
|
|
|
/* target frame [16.3] */
|
2014-01-24 22:58:12 +04:00
|
|
|
err = dom_element_get_attribute(n, corestring_dom_target, &s);
|
2012-03-24 22:47:51 +04:00
|
|
|
if (err == DOM_NO_ERR && s != NULL) {
|
2012-07-26 18:57:33 +04:00
|
|
|
if (dom_string_caseless_lwc_isequal(s,
|
|
|
|
corestring_lwc__blank))
|
2006-09-02 19:52:41 +04:00
|
|
|
box->target = TARGET_BLANK;
|
2012-07-26 18:57:33 +04:00
|
|
|
else if (dom_string_caseless_lwc_isequal(s,
|
|
|
|
corestring_lwc__top))
|
2005-08-21 02:52:20 +04:00
|
|
|
box->target = TARGET_TOP;
|
2012-07-26 18:57:33 +04:00
|
|
|
else if (dom_string_caseless_lwc_isequal(s,
|
|
|
|
corestring_lwc__parent))
|
2005-08-21 02:52:20 +04:00
|
|
|
box->target = TARGET_PARENT;
|
2012-07-26 18:57:33 +04:00
|
|
|
else if (dom_string_caseless_lwc_isequal(s,
|
|
|
|
corestring_lwc__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 */
|
2014-10-15 12:35:43 +04:00
|
|
|
box->target = talloc_strdup(content->bctx,
|
2012-03-24 22:47:51 +04:00
|
|
|
dom_string_data(s));
|
2005-08-21 02:52:20 +04:00
|
|
|
if (!box->target) {
|
2012-03-24 22:47:51 +04:00
|
|
|
dom_string_unref(s);
|
2005-08-21 02:52:20 +04:00
|
|
|
return false;
|
|
|
|
}
|
2006-09-02 19:52:41 +04:00
|
|
|
}
|
2012-03-24 22:47:51 +04:00
|
|
|
dom_string_unref(s);
|
2005-08-21 02:52:20 +04: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
|
|
|
|
|
|
|
/**
|
|
|
|
* 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;
|
2012-03-24 22:47:51 +04:00
|
|
|
dom_string *s;
|
|
|
|
dom_exception err;
|
2011-10-04 00:28:29 +04:00
|
|
|
nsurl *url;
|
2011-04-27 17:50:49 +04:00
|
|
|
enum css_width_e wtype;
|
|
|
|
enum css_height_e htype;
|
|
|
|
css_fixed value = 0;
|
|
|
|
css_unit wunit = CSS_UNIT_PX;
|
|
|
|
css_unit hunit = CSS_UNIT_PX;
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2014-10-15 12:35:43 +04:00
|
|
|
if (box->style && css_computed_display(box->style,
|
2012-03-24 22:47:51 +04:00
|
|
|
box_is_root(n)) == CSS_DISPLAY_NONE)
|
2007-04-07 03:48:26 +04:00
|
|
|
return true;
|
|
|
|
|
2005-03-26 04:12:27 +03:00
|
|
|
/* handle alt text */
|
2014-01-24 22:58:12 +04:00
|
|
|
err = dom_element_get_attribute(n, corestring_dom_alt, &s);
|
2012-03-24 22:47:51 +04:00
|
|
|
if (err == DOM_NO_ERR && s != NULL) {
|
|
|
|
char *alt = squash_whitespace(dom_string_data(s));
|
|
|
|
dom_string_unref(s);
|
|
|
|
if (alt == NULL)
|
2005-04-09 13:47:37 +04:00
|
|
|
return false;
|
2012-10-03 22:24:58 +04:00
|
|
|
box->text = talloc_strdup(content->bctx, alt);
|
2012-03-24 22:47:51 +04:00
|
|
|
free(alt);
|
|
|
|
if (box->text == NULL)
|
2005-04-09 13:47:37 +04:00
|
|
|
return false;
|
2005-03-26 04:12:27 +03:00
|
|
|
box->length = strlen(box->text);
|
|
|
|
}
|
|
|
|
|
2012-03-22 13:34:34 +04:00
|
|
|
if (nsoption_bool(foreground_images) == false) {
|
2011-12-23 23:48:09 +04:00
|
|
|
return true;
|
2012-03-22 13:34:34 +04:00
|
|
|
}
|
2011-12-23 23:48:09 +04:00
|
|
|
|
2005-03-26 04:12:27 +03:00
|
|
|
/* imagemap associated with this image */
|
2012-10-05 15:38:25 +04:00
|
|
|
if (!box_get_attribute(n, "usemap", content->bctx, &box->usemap))
|
2005-04-10 21:08:49 +04:00
|
|
|
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 */
|
2014-01-24 22:58:12 +04:00
|
|
|
err = dom_element_get_attribute(n, corestring_dom_src, &s);
|
2012-03-24 22:47:51 +04:00
|
|
|
if (err != DOM_NO_ERR || s == NULL)
|
2005-04-09 13:47:37 +04:00
|
|
|
return true;
|
2012-03-24 22:47:51 +04:00
|
|
|
|
2016-01-21 17:09:57 +03:00
|
|
|
if (box_extract_link(content, dom_string_data(s), content->base_url,
|
2012-03-24 22:47:51 +04:00
|
|
|
&url) == false) {
|
|
|
|
dom_string_unref(s);
|
2005-04-09 13:47:37 +04:00
|
|
|
return false;
|
2012-03-24 22:47:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
dom_string_unref(s);
|
|
|
|
|
|
|
|
if (url == NULL)
|
2005-04-09 13:47:37 +04:00
|
|
|
return true;
|
2005-03-26 04:12:27 +03:00
|
|
|
|
|
|
|
/* start fetch */
|
2016-02-09 19:42:28 +03:00
|
|
|
box->flags |= IS_REPLACED;
|
2011-10-04 14:23:47 +04:00
|
|
|
ok = html_fetch_object(content, url, box, image_types,
|
2011-05-07 00:40:09 +04:00
|
|
|
content->base.available_width, 1000, false);
|
2011-10-04 00:28:29 +04:00
|
|
|
nsurl_unref(url);
|
2011-04-27 17:50:49 +04:00
|
|
|
|
|
|
|
wtype = css_computed_width(box->style, &value, &wunit);
|
|
|
|
htype = css_computed_height(box->style, &value, &hunit);
|
|
|
|
|
|
|
|
if (wtype == CSS_WIDTH_SET && wunit != CSS_UNIT_PCT &&
|
|
|
|
htype == CSS_HEIGHT_SET && hunit != CSS_UNIT_PCT) {
|
|
|
|
/* We know the dimensions the image will be shown at before it's
|
|
|
|
* fetched. */
|
|
|
|
box->flags |= REPLACE_DIM;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2012-07-15 04:17:04 +04:00
|
|
|
/**
|
|
|
|
* Noscript element
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool box_noscript(BOX_SPECIAL_PARAMS)
|
|
|
|
{
|
|
|
|
/* If scripting is enabled, do not display the contents of noscript */
|
2016-01-21 17:11:36 +03:00
|
|
|
if (content->enable_scripting)
|
2012-07-15 04:17:04 +04:00
|
|
|
*convert_children = false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-04 01:04:54 +04:00
|
|
|
/**
|
2014-11-12 14:45:07 +03:00
|
|
|
* Destructor for object_params, for <object> elements
|
2011-10-04 01:04:54 +04:00
|
|
|
*
|
2014-11-12 14:45:07 +03:00
|
|
|
* \param o The object params being destroyed.
|
2011-10-04 01:04:54 +04:00
|
|
|
* \return 0 to allow talloc to continue destroying the tree.
|
|
|
|
*/
|
|
|
|
static int box_object_talloc_destructor(struct object_params *o)
|
|
|
|
{
|
|
|
|
if (o->codebase != NULL)
|
|
|
|
nsurl_unref(o->codebase);
|
|
|
|
if (o->classid != NULL)
|
|
|
|
nsurl_unref(o->classid);
|
|
|
|
if (o->data != NULL)
|
|
|
|
nsurl_unref(o->data);
|
2014-10-15 12:35:43 +04:00
|
|
|
|
2011-10-04 01:04:54 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
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;
|
2012-03-24 22:47:51 +04:00
|
|
|
dom_string *codebase, *classid, *data;
|
2012-03-24 03:18:04 +04:00
|
|
|
dom_node *c;
|
2012-03-24 22:47:51 +04:00
|
|
|
dom_exception err;
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2014-10-15 12:35:43 +04:00
|
|
|
if (box->style && css_computed_display(box->style,
|
2012-03-24 22:47:51 +04:00
|
|
|
box_is_root(n)) == CSS_DISPLAY_NONE)
|
2007-04-07 03:48:26 +04:00
|
|
|
return true;
|
|
|
|
|
2012-10-05 15:38:25 +04:00
|
|
|
if (box_get_attribute(n, "usemap", content->bctx, &box->usemap) ==
|
|
|
|
false)
|
2005-04-10 21:08:49 +04:00
|
|
|
return false;
|
|
|
|
if (box->usemap && box->usemap[0] == '#')
|
|
|
|
box->usemap++;
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2012-10-03 22:24:58 +04:00
|
|
|
params = talloc(content->bctx, struct object_params);
|
2012-03-24 22:47:51 +04:00
|
|
|
if (params == NULL)
|
2005-04-10 21:08:49 +04:00
|
|
|
return false;
|
2011-10-04 01:04:54 +04:00
|
|
|
|
|
|
|
talloc_set_destructor(params, box_object_talloc_destructor);
|
|
|
|
|
2012-03-24 22:47:51 +04:00
|
|
|
params->data = NULL;
|
|
|
|
params->type = NULL;
|
|
|
|
params->codetype = NULL;
|
|
|
|
params->codebase = NULL;
|
|
|
|
params->classid = NULL;
|
|
|
|
params->params = NULL;
|
2005-04-14 01:58:28 +04:00
|
|
|
|
2007-03-23 01:47:24 +03:00
|
|
|
/* codebase, classid, and data are URLs
|
|
|
|
* (codebase is the base for the other two) */
|
2014-01-24 22:58:12 +04:00
|
|
|
err = dom_element_get_attribute(n, corestring_dom_codebase, &codebase);
|
2012-03-24 22:47:51 +04:00
|
|
|
if (err == DOM_NO_ERR && codebase != NULL) {
|
2016-01-21 17:09:57 +03:00
|
|
|
if (box_extract_link(content, dom_string_data(codebase),
|
2014-10-15 12:35:43 +04:00
|
|
|
content->base_url,
|
2012-03-24 22:47:51 +04:00
|
|
|
¶ms->codebase) == false) {
|
|
|
|
dom_string_unref(codebase);
|
2005-04-14 01:58:28 +04:00
|
|
|
return false;
|
2012-03-24 22:47:51 +04:00
|
|
|
}
|
|
|
|
dom_string_unref(codebase);
|
2005-04-14 01:58:28 +04:00
|
|
|
}
|
2012-03-24 22:47:51 +04:00
|
|
|
if (params->codebase == NULL)
|
2011-10-04 00:28:29 +04:00
|
|
|
params->codebase = nsurl_ref(content->base_url);
|
2005-04-14 01:58:28 +04:00
|
|
|
|
2014-01-24 22:58:12 +04:00
|
|
|
err = dom_element_get_attribute(n, corestring_dom_classid, &classid);
|
2012-03-24 22:47:51 +04:00
|
|
|
if (err == DOM_NO_ERR && classid != NULL) {
|
2016-01-21 17:09:57 +03:00
|
|
|
if (box_extract_link(content, dom_string_data(classid),
|
|
|
|
params->codebase, ¶ms->classid) == false) {
|
2012-03-24 22:47:51 +04:00
|
|
|
dom_string_unref(classid);
|
2005-04-14 01:58:28 +04:00
|
|
|
return false;
|
2012-03-24 22:47:51 +04:00
|
|
|
}
|
|
|
|
dom_string_unref(classid);
|
2005-04-14 01:58:28 +04:00
|
|
|
}
|
|
|
|
|
2014-01-24 22:58:12 +04:00
|
|
|
err = dom_element_get_attribute(n, corestring_dom_data, &data);
|
2012-03-24 22:47:51 +04:00
|
|
|
if (err == DOM_NO_ERR && data != NULL) {
|
2016-01-21 17:09:57 +03:00
|
|
|
if (box_extract_link(content, dom_string_data(data),
|
|
|
|
params->codebase, ¶ms->data) == false) {
|
2012-03-24 22:47:51 +04:00
|
|
|
dom_string_unref(data);
|
2005-04-14 01:58:28 +04:00
|
|
|
return false;
|
2012-03-24 22:47:51 +04:00
|
|
|
}
|
|
|
|
dom_string_unref(data);
|
2005-04-14 01:58:28 +04:00
|
|
|
}
|
2007-03-23 01:47:24 +03:00
|
|
|
|
2012-03-24 22:47:51 +04:00
|
|
|
if (params->classid == NULL && params->data == NULL)
|
2007-03-23 01:47:24 +03:00
|
|
|
/* 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 */
|
2012-03-24 22:47:51 +04:00
|
|
|
if (params->classid != NULL && nsurl_compare(content->base_url,
|
2011-10-04 00:28:29 +04:00
|
|
|
params->classid, NSURL_COMPLETE))
|
2007-03-23 01:47:24 +03:00
|
|
|
return true;
|
|
|
|
|
2012-03-24 22:47:51 +04:00
|
|
|
if (params->data != NULL && nsurl_compare(content->base_url,
|
2011-10-04 00:28:29 +04:00
|
|
|
params->data, NSURL_COMPLETE))
|
2006-03-27 05:04:56 +04:00
|
|
|
return true;
|
|
|
|
|
2005-04-14 01:58:28 +04:00
|
|
|
/* codetype and type are MIME types */
|
2014-10-15 12:35:43 +04:00
|
|
|
if (box_get_attribute(n, "codetype", params,
|
2012-03-24 22:47:51 +04:00
|
|
|
¶ms->codetype) == false)
|
2005-04-10 21:08:49 +04:00
|
|
|
return false;
|
2012-03-24 22:47:51 +04:00
|
|
|
if (box_get_attribute(n, "type", params, ¶ms->type) == false)
|
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 */
|
|
|
|
|
2014-10-15 12:35:43 +04:00
|
|
|
if (params->classid != NULL && params->data == NULL &&
|
2011-07-08 12:38:17 +04:00
|
|
|
params->codetype != NULL) {
|
|
|
|
lwc_string *icodetype;
|
|
|
|
lwc_error lerror;
|
|
|
|
|
2014-10-15 12:35:43 +04:00
|
|
|
lerror = lwc_intern_string(params->codetype,
|
2011-07-08 12:38:17 +04:00
|
|
|
strlen(params->codetype), &icodetype);
|
|
|
|
if (lerror != lwc_error_ok)
|
|
|
|
return false;
|
2007-03-23 01:47:24 +03:00
|
|
|
|
2011-07-08 12:38:17 +04:00
|
|
|
if (content_factory_type_from_mime_type(icodetype) ==
|
|
|
|
CONTENT_NONE) {
|
|
|
|
/* can't handle this MIME type */
|
|
|
|
lwc_string_unref(icodetype);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
lwc_string_unref(icodetype);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (params->data != NULL && params->type != NULL) {
|
|
|
|
lwc_string *itype;
|
|
|
|
lwc_error lerror;
|
|
|
|
|
|
|
|
lerror = lwc_intern_string(params->type, strlen(params->type),
|
|
|
|
&itype);
|
|
|
|
if (lerror != lwc_error_ok)
|
|
|
|
return false;
|
|
|
|
|
2014-10-15 12:35:43 +04:00
|
|
|
if (content_factory_type_from_mime_type(itype) ==
|
2011-07-08 12:38:17 +04:00
|
|
|
CONTENT_NONE) {
|
|
|
|
/* can't handle this MIME type */
|
|
|
|
lwc_string_unref(itype);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
lwc_string_unref(itype);
|
|
|
|
}
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2005-04-14 01:58:28 +04:00
|
|
|
/* add parameters to linked list */
|
2012-03-24 22:47:51 +04:00
|
|
|
err = dom_node_get_first_child(n, &c);
|
|
|
|
if (err != DOM_NO_ERR)
|
|
|
|
return false;
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2012-03-24 22:47:51 +04:00
|
|
|
while (c != NULL) {
|
|
|
|
dom_node *next;
|
|
|
|
dom_node_type type;
|
2005-04-09 13:47:37 +04:00
|
|
|
|
2012-03-24 22:47:51 +04:00
|
|
|
err = dom_node_get_node_type(c, &type);
|
|
|
|
if (err != DOM_NO_ERR) {
|
|
|
|
dom_node_unref(c);
|
2005-04-10 21:08:49 +04:00
|
|
|
return false;
|
2012-03-24 22:47:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (type == DOM_ELEMENT_NODE) {
|
|
|
|
dom_string *name;
|
|
|
|
|
|
|
|
err = dom_node_get_node_name(c, &name);
|
|
|
|
if (err != DOM_NO_ERR) {
|
|
|
|
dom_node_unref(c);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-07-26 18:57:33 +04:00
|
|
|
if (!dom_string_caseless_lwc_isequal(name,
|
|
|
|
corestring_lwc_param)) {
|
2014-10-15 12:35:43 +04:00
|
|
|
/* The first non-param child is the start of
|
|
|
|
* the alt html. Therefore, we should break
|
2012-03-24 22:47:51 +04:00
|
|
|
* out of this loop. */
|
|
|
|
dom_node_unref(c);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
param = talloc(params, struct object_param);
|
|
|
|
if (param == NULL) {
|
|
|
|
dom_node_unref(c);
|
2006-09-11 15:55:17 +04:00
|
|
|
return false;
|
2012-03-24 22:47:51 +04:00
|
|
|
}
|
|
|
|
param->name = NULL;
|
|
|
|
param->value = NULL;
|
|
|
|
param->type = NULL;
|
|
|
|
param->valuetype = NULL;
|
|
|
|
param->next = NULL;
|
|
|
|
|
2014-10-15 12:35:43 +04:00
|
|
|
if (box_get_attribute(c, "name", param,
|
2012-03-24 22:47:51 +04:00
|
|
|
¶m->name) == false) {
|
|
|
|
dom_node_unref(c);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-10-15 12:35:43 +04:00
|
|
|
if (box_get_attribute(c, "value", param,
|
2012-03-24 22:47:51 +04:00
|
|
|
¶m->value) == false) {
|
|
|
|
dom_node_unref(c);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-10-15 12:35:43 +04:00
|
|
|
if (box_get_attribute(c, "type", param,
|
2012-03-24 22:47:51 +04:00
|
|
|
¶m->type) == false) {
|
|
|
|
dom_node_unref(c);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (box_get_attribute(c, "valuetype", param,
|
|
|
|
¶m->valuetype) == false) {
|
|
|
|
dom_node_unref(c);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (param->valuetype == NULL) {
|
|
|
|
param->valuetype = talloc_strdup(param, "data");
|
|
|
|
if (param->valuetype == NULL) {
|
|
|
|
dom_node_unref(c);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
param->next = params->params;
|
|
|
|
params->params = param;
|
2006-09-11 15:55:17 +04:00
|
|
|
}
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2012-03-24 22:47:51 +04:00
|
|
|
err = dom_node_get_next_sibling(c, &next);
|
|
|
|
if (err != DOM_NO_ERR) {
|
|
|
|
dom_node_unref(c);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
dom_node_unref(c);
|
|
|
|
c = next;
|
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) */
|
2016-02-09 19:42:28 +03:00
|
|
|
box->flags |= IS_REPLACED;
|
2007-03-23 01:47:24 +03:00
|
|
|
if (!html_fetch_object(content,
|
2011-10-04 14:23:47 +04:00
|
|
|
params->data ? params->data : params->classid,
|
|
|
|
box, CONTENT_ANY, content->base.available_width, 1000,
|
2011-05-07 00:40:09 +04:00
|
|
|
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
|
|
|
|
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
if (content->frameset) {
|
2015-05-28 18:08:46 +03:00
|
|
|
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
|
|
|
|
2012-10-03 22:24:58 +04:00
|
|
|
content->frameset = talloc_zero(content->bctx, struct content_html_frames);
|
2011-05-07 00:40:09 +04:00
|
|
|
if (!content->frameset)
|
2006-09-02 19:52:41 +04:00
|
|
|
return false;
|
2006-09-11 15:55:17 +04:00
|
|
|
|
2012-10-03 22:41:14 +04:00
|
|
|
ok = box_create_frameset(content->frameset, n, content);
|
2006-09-02 19:52:41 +04:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2011-10-04 01:49:28 +04:00
|
|
|
|
|
|
|
/**
|
2014-11-10 23:15:14 +03:00
|
|
|
* Destructor for content_html_frames, for frame elements
|
2011-10-04 01:49:28 +04:00
|
|
|
*
|
2014-11-10 23:15:14 +03:00
|
|
|
* \param f The frame params being destroyed.
|
2011-10-04 01:49:28 +04:00
|
|
|
* \return 0 to allow talloc to continue destroying the tree.
|
|
|
|
*/
|
|
|
|
static int box_frames_talloc_destructor(struct content_html_frames *f)
|
|
|
|
{
|
2011-10-04 02:06:47 +04:00
|
|
|
if (f->url != NULL) {
|
2011-10-04 01:49:28 +04:00
|
|
|
nsurl_unref(f->url);
|
2011-10-04 02:06:47 +04:00
|
|
|
f->url = NULL;
|
|
|
|
}
|
2014-10-15 12:35:43 +04:00
|
|
|
|
2011-10-04 01:49:28 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-03-24 03:18:04 +04:00
|
|
|
bool box_create_frameset(struct content_html_frames *f, dom_node *n,
|
2011-05-07 00:40:09 +04:00
|
|
|
html_content *content) {
|
2006-09-02 19:52:41 +04:00
|
|
|
unsigned int row, col, index, i;
|
2005-04-09 13:47:37 +04:00
|
|
|
unsigned int rows = 1, cols = 1;
|
2012-03-24 22:47:51 +04:00
|
|
|
dom_string *s;
|
|
|
|
dom_exception err;
|
2011-10-04 00:28:29 +04:00
|
|
|
nsurl *url;
|
2006-09-02 19:52:41 +04:00
|
|
|
struct frame_dimension *row_height = 0, *col_width = 0;
|
2012-03-24 22:47:51 +04:00
|
|
|
dom_node *c, *next;
|
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 */
|
2014-01-24 22:58:12 +04:00
|
|
|
err = dom_element_get_attribute(n, corestring_dom_rows, &s);
|
2012-03-24 22:47:51 +04:00
|
|
|
if (err == DOM_NO_ERR && s != NULL) {
|
|
|
|
row_height = box_parse_multi_lengths(dom_string_data(s), &rows);
|
|
|
|
dom_string_unref(s);
|
|
|
|
if (row_height == NULL)
|
2005-04-09 13:47:37 +04:00
|
|
|
return false;
|
2006-09-02 19:52:41 +04:00
|
|
|
} else {
|
|
|
|
row_height = calloc(1, sizeof(struct frame_dimension));
|
2012-03-24 22:47:51 +04:00
|
|
|
if (row_height == NULL)
|
2006-09-02 19:52:41 +04:00
|
|
|
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
|
|
|
|
2014-01-24 22:58:12 +04:00
|
|
|
err = dom_element_get_attribute(n, corestring_dom_cols, &s);
|
2012-03-24 22:47:51 +04:00
|
|
|
if (err == DOM_NO_ERR && s != NULL) {
|
|
|
|
col_width = box_parse_multi_lengths(dom_string_data(s), &cols);
|
|
|
|
dom_string_unref(s);
|
2013-10-26 01:23:18 +04:00
|
|
|
if (col_width == NULL) {
|
|
|
|
free(row_height);
|
2005-04-09 13:47:37 +04:00
|
|
|
return false;
|
2013-10-26 01:23:18 +04:00
|
|
|
}
|
2006-09-02 19:52:41 +04:00
|
|
|
} else {
|
|
|
|
col_width = calloc(1, sizeof(struct frame_dimension));
|
2013-10-26 01:23:18 +04:00
|
|
|
if (col_width == NULL) {
|
|
|
|
free(row_height);
|
2006-09-02 19:52:41 +04:00
|
|
|
return false;
|
2013-10-26 01:23:18 +04:00
|
|
|
}
|
2006-09-02 19:52:41 +04:00
|
|
|
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 */
|
2014-01-24 22:58:12 +04:00
|
|
|
err = dom_element_get_attribute(n, corestring_dom_border, &s);
|
2012-03-24 22:47:51 +04:00
|
|
|
if (err == DOM_NO_ERR && s != NULL) {
|
2014-10-15 12:35:43 +04:00
|
|
|
if ((dom_string_data(s)[0] == '0') &&
|
2012-03-24 22:47:51 +04:00
|
|
|
(dom_string_data(s)[1] == '\0'))
|
2006-09-02 19:52:41 +04:00
|
|
|
default_border = false;
|
2012-03-24 22:47:51 +04:00
|
|
|
dom_string_unref(s);
|
2006-09-02 19:52:41 +04:00
|
|
|
}
|
2012-03-24 22:47:51 +04:00
|
|
|
|
2006-09-02 19:52:41 +04:00
|
|
|
/* common extension: frameborder="yes|no" to control all children */
|
2014-01-24 22:58:12 +04:00
|
|
|
err = dom_element_get_attribute(n, corestring_dom_frameborder, &s);
|
2012-03-24 22:47:51 +04:00
|
|
|
if (err == DOM_NO_ERR && s != NULL) {
|
2012-07-26 18:57:33 +04:00
|
|
|
if (dom_string_caseless_lwc_isequal(s,
|
|
|
|
corestring_lwc_no) == 0)
|
2006-09-02 19:52:41 +04:00
|
|
|
default_border = false;
|
2012-03-24 22:47:51 +04:00
|
|
|
dom_string_unref(s);
|
2006-09-02 19:52:41 +04:00
|
|
|
}
|
2012-03-24 22:47:51 +04:00
|
|
|
|
2008-02-25 19:37:48 +03:00
|
|
|
/* common extension: bordercolor="#RRGGBB|<named colour>" to control
|
|
|
|
*all children */
|
2014-01-24 22:58:12 +04:00
|
|
|
err = dom_element_get_attribute(n, corestring_dom_bordercolor, &s);
|
2012-03-24 22:47:51 +04:00
|
|
|
if (err == DOM_NO_ERR && s != NULL) {
|
2009-07-24 03:05:34 +04:00
|
|
|
css_color color;
|
|
|
|
|
2012-03-24 22:47:51 +04:00
|
|
|
if (nscss_parse_colour(dom_string_data(s), &color))
|
2009-07-24 03:05:34 +04:00
|
|
|
default_border_colour = nscss_color_to_ns(color);
|
|
|
|
|
2012-03-24 22:47:51 +04:00
|
|
|
dom_string_unref(s);
|
2006-09-02 19:52:41 +04:00
|
|
|
}
|
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;
|
2014-10-25 15:04:11 +04:00
|
|
|
f->scrolling = BW_SCROLLING_NO;
|
2012-10-03 23:48:16 +04:00
|
|
|
f->children = talloc_array(content->bctx, struct content_html_frames,
|
2008-02-25 19:37:48 +03:00
|
|
|
(rows * cols));
|
2011-10-04 01:49:28 +04:00
|
|
|
|
|
|
|
talloc_set_destructor(f->children, box_frames_talloc_destructor);
|
|
|
|
|
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;
|
2014-10-25 15:04:11 +04:00
|
|
|
frame->scrolling = BW_SCROLLING_AUTO;
|
2006-09-02 19:52:41 +04:00
|
|
|
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 */
|
2012-03-24 22:47:51 +04:00
|
|
|
err = dom_node_get_first_child(n, &c);
|
|
|
|
if (err != DOM_NO_ERR)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
for (row = 0; c != NULL && row < rows; row++) {
|
|
|
|
for (col = 0; c != NULL && col < cols; col++) {
|
|
|
|
while (c != NULL) {
|
|
|
|
dom_node_type type;
|
|
|
|
dom_string *name;
|
|
|
|
|
|
|
|
err = dom_node_get_node_type(c, &type);
|
|
|
|
if (err != DOM_NO_ERR) {
|
|
|
|
dom_node_unref(c);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = dom_node_get_node_name(c, &name);
|
|
|
|
if (err != DOM_NO_ERR) {
|
|
|
|
dom_node_unref(c);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (type != DOM_ELEMENT_NODE ||
|
2012-07-26 18:57:33 +04:00
|
|
|
(!dom_string_caseless_lwc_isequal(
|
|
|
|
name,
|
|
|
|
corestring_lwc_frame) &&
|
|
|
|
!dom_string_caseless_lwc_isequal(
|
|
|
|
name,
|
|
|
|
corestring_lwc_frameset
|
|
|
|
))) {
|
2014-10-15 12:35:43 +04:00
|
|
|
err = dom_node_get_next_sibling(c,
|
2012-03-24 22:47:51 +04:00
|
|
|
&next);
|
|
|
|
if (err != DOM_NO_ERR) {
|
2013-10-25 22:57:05 +04:00
|
|
|
dom_string_unref(name);
|
2012-03-24 22:47:51 +04:00
|
|
|
dom_node_unref(c);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-10-25 22:57:05 +04:00
|
|
|
dom_string_unref(name);
|
2012-03-24 22:47:51 +04:00
|
|
|
dom_node_unref(c);
|
|
|
|
c = next;
|
2012-04-16 20:14:40 +04:00
|
|
|
} else {
|
|
|
|
/* Got a FRAME or FRAMESET element */
|
2013-10-25 22:57:05 +04:00
|
|
|
dom_string_unref(name);
|
2012-04-16 20:14:40 +04:00
|
|
|
break;
|
2012-03-24 22:47:51 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (c == NULL)
|
2005-04-09 13:47:37 +04:00
|
|
|
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 */
|
2012-03-24 22:47:51 +04:00
|
|
|
err = dom_node_get_node_name(c, &s);
|
|
|
|
if (err != DOM_NO_ERR) {
|
|
|
|
dom_node_unref(c);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-07-26 18:57:33 +04:00
|
|
|
if (dom_string_caseless_lwc_isequal(s,
|
|
|
|
corestring_lwc_frameset)) {
|
2012-03-24 22:47:51 +04:00
|
|
|
dom_string_unref(s);
|
2006-09-02 19:52:41 +04:00
|
|
|
frame->border = 0;
|
2014-10-15 12:35:43 +04:00
|
|
|
if (box_create_frameset(frame, c,
|
2012-03-24 22:47:51 +04:00
|
|
|
content) == false) {
|
|
|
|
dom_node_unref(c);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = dom_node_get_next_sibling(c, &next);
|
|
|
|
if (err != DOM_NO_ERR) {
|
|
|
|
dom_node_unref(c);
|
2005-04-09 13:47:37 +04:00
|
|
|
return false;
|
2012-03-24 22:47:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
dom_node_unref(c);
|
|
|
|
c = next;
|
2005-04-09 13:47:37 +04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2012-03-24 22:47:51 +04:00
|
|
|
dom_string_unref(s);
|
|
|
|
|
2007-01-03 23:11:09 +03:00
|
|
|
/* get frame URL (not required) */
|
|
|
|
url = NULL;
|
2014-01-24 22:58:12 +04:00
|
|
|
err = dom_element_get_attribute(c, corestring_dom_src, &s);
|
2012-03-24 22:47:51 +04:00
|
|
|
if (err == DOM_NO_ERR && s != NULL) {
|
2016-01-21 17:09:57 +03:00
|
|
|
box_extract_link(content, dom_string_data(s),
|
2012-03-24 22:47:51 +04:00
|
|
|
content->base_url, &url);
|
|
|
|
dom_string_unref(s);
|
2006-09-02 19:52:41 +04:00
|
|
|
}
|
2007-01-25 01:53:09 +03:00
|
|
|
|
2007-01-03 23:11:09 +03:00
|
|
|
/* copy url */
|
2012-03-24 22:47:51 +04:00
|
|
|
if (url != NULL) {
|
2007-01-03 23:11:09 +03:00
|
|
|
/* no self-references */
|
2011-10-04 00:28:29 +04:00
|
|
|
if (nsurl_compare(content->base_url, url,
|
2011-10-04 01:49:28 +04:00
|
|
|
NSURL_COMPLETE) == false)
|
2011-10-04 00:28:29 +04:00
|
|
|
frame->url = url;
|
2011-10-04 01:49:28 +04: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 */
|
2014-01-24 22:58:12 +04:00
|
|
|
err = dom_element_get_attribute(c, corestring_dom_name, &s);
|
2012-03-24 22:47:51 +04:00
|
|
|
if (err == DOM_NO_ERR && s != NULL) {
|
2014-10-15 12:35:43 +04:00
|
|
|
frame->name = talloc_strdup(content->bctx,
|
2012-03-24 22:47:51 +04:00
|
|
|
dom_string_data(s));
|
|
|
|
dom_string_unref(s);
|
2006-09-02 19:52:41 +04:00
|
|
|
}
|
2012-03-24 22:47:51 +04:00
|
|
|
|
2014-10-15 12:35:43 +04:00
|
|
|
dom_element_has_attribute(c, corestring_dom_noresize,
|
2012-03-24 22:47:51 +04:00
|
|
|
&frame->no_resize);
|
|
|
|
|
2014-10-15 12:35:43 +04:00
|
|
|
err = dom_element_get_attribute(c, corestring_dom_frameborder,
|
2012-03-24 22:47:51 +04:00
|
|
|
&s);
|
|
|
|
if (err == DOM_NO_ERR && s != NULL) {
|
|
|
|
i = atoi(dom_string_data(s));
|
2006-09-02 19:52:41 +04:00
|
|
|
frame->border = (i != 0);
|
2012-03-24 22:47:51 +04:00
|
|
|
dom_string_unref(s);
|
2006-09-02 19:52:41 +04:00
|
|
|
}
|
2012-03-24 22:47:51 +04:00
|
|
|
|
2014-01-24 22:58:12 +04:00
|
|
|
err = dom_element_get_attribute(c, corestring_dom_scrolling, &s);
|
2012-03-24 22:47:51 +04:00
|
|
|
if (err == DOM_NO_ERR && s != NULL) {
|
2012-07-26 18:57:33 +04:00
|
|
|
if (dom_string_caseless_lwc_isequal(s,
|
|
|
|
corestring_lwc_yes))
|
2014-10-25 15:04:11 +04:00
|
|
|
frame->scrolling = BW_SCROLLING_YES;
|
2012-07-26 18:57:33 +04:00
|
|
|
else if (dom_string_caseless_lwc_isequal(s,
|
|
|
|
corestring_lwc_no))
|
2014-10-25 15:04:11 +04:00
|
|
|
frame->scrolling = BW_SCROLLING_NO;
|
2012-03-24 22:47:51 +04:00
|
|
|
dom_string_unref(s);
|
2006-09-02 19:52:41 +04:00
|
|
|
}
|
2012-03-24 22:47:51 +04:00
|
|
|
|
2014-10-15 12:35:43 +04:00
|
|
|
err = dom_element_get_attribute(c, corestring_dom_marginwidth,
|
2012-03-24 22:47:51 +04:00
|
|
|
&s);
|
|
|
|
if (err == DOM_NO_ERR && s != NULL) {
|
|
|
|
frame->margin_width = atoi(dom_string_data(s));
|
|
|
|
dom_string_unref(s);
|
2006-09-02 19:52:41 +04:00
|
|
|
}
|
2012-03-24 22:47:51 +04:00
|
|
|
|
2014-01-24 22:58:12 +04:00
|
|
|
err = dom_element_get_attribute(c, corestring_dom_marginheight,
|
2012-03-24 22:47:51 +04:00
|
|
|
&s);
|
|
|
|
if (err == DOM_NO_ERR && s != NULL) {
|
|
|
|
frame->margin_height = atoi(dom_string_data(s));
|
|
|
|
dom_string_unref(s);
|
2006-09-02 19:52:41 +04:00
|
|
|
}
|
2012-03-24 22:47:51 +04:00
|
|
|
|
2014-10-15 12:35:43 +04:00
|
|
|
err = dom_element_get_attribute(c, corestring_dom_bordercolor,
|
2012-03-24 22:47:51 +04:00
|
|
|
&s);
|
|
|
|
if (err == DOM_NO_ERR && s != NULL) {
|
2009-07-24 03:05:34 +04:00
|
|
|
css_color color;
|
|
|
|
|
2014-10-15 12:35:43 +04:00
|
|
|
if (nscss_parse_colour(dom_string_data(s),
|
2009-07-24 03:05:34 +04:00
|
|
|
&color))
|
|
|
|
frame->border_colour =
|
|
|
|
nscss_color_to_ns(color);
|
|
|
|
|
2012-03-24 22:47:51 +04:00
|
|
|
dom_string_unref(s);
|
2006-09-02 19:52:41 +04:00
|
|
|
}
|
2005-04-09 13:47:37 +04:00
|
|
|
|
2007-01-03 23:11:09 +03:00
|
|
|
/* advance */
|
2012-03-24 22:47:51 +04:00
|
|
|
err = dom_node_get_next_sibling(c, &next);
|
|
|
|
if (err != DOM_NO_ERR) {
|
|
|
|
dom_node_unref(c);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
dom_node_unref(c);
|
|
|
|
c = next;
|
2005-04-09 13:47:37 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-31 19:13:58 +03:00
|
|
|
/* If the last child wasn't a frame, we still need to unref it */
|
|
|
|
if (c != NULL) {
|
|
|
|
dom_node_unref(c);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2011-10-04 01:49:28 +04:00
|
|
|
/**
|
2014-11-12 14:45:07 +03:00
|
|
|
* Destructor for content_html_iframe, for <iframe> elements
|
2011-10-04 01:49:28 +04:00
|
|
|
*
|
2014-11-12 14:45:07 +03:00
|
|
|
* \param f The iframe params being destroyed.
|
2011-10-04 01:49:28 +04:00
|
|
|
* \return 0 to allow talloc to continue destroying the tree.
|
|
|
|
*/
|
|
|
|
static int box_iframes_talloc_destructor(struct content_html_iframe *f)
|
|
|
|
{
|
2011-10-04 02:06:47 +04:00
|
|
|
if (f->url != NULL) {
|
2011-10-04 01:49:28 +04:00
|
|
|
nsurl_unref(f->url);
|
2011-10-04 02:06:47 +04:00
|
|
|
f->url = NULL;
|
|
|
|
}
|
2014-10-15 12:35:43 +04:00
|
|
|
|
2011-10-04 01:49:28 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
/**
|
|
|
|
* Inline subwindow [16.5].
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool box_iframe(BOX_SPECIAL_PARAMS)
|
|
|
|
{
|
2011-10-04 00:28:29 +04:00
|
|
|
nsurl *url;
|
2012-03-24 22:47:51 +04:00
|
|
|
dom_string *s;
|
|
|
|
dom_exception err;
|
2006-09-02 19:52:41 +04:00
|
|
|
struct content_html_iframe *iframe;
|
|
|
|
int i;
|
2005-04-09 13:47:37 +04:00
|
|
|
|
2014-10-15 12:35:43 +04:00
|
|
|
if (box->style && css_computed_display(box->style,
|
2012-03-24 22:47:51 +04:00
|
|
|
box_is_root(n)) == CSS_DISPLAY_NONE)
|
2011-01-05 04:26:29 +03:00
|
|
|
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 */
|
2014-01-24 22:58:12 +04:00
|
|
|
err = dom_element_get_attribute(n, corestring_dom_src, &s);
|
2012-03-24 22:47:51 +04:00
|
|
|
if (err != DOM_NO_ERR || s == NULL)
|
2005-04-14 01:58:28 +04:00
|
|
|
return true;
|
2016-01-21 17:09:57 +03:00
|
|
|
if (box_extract_link(content, dom_string_data(s), content->base_url,
|
2012-03-24 22:47:51 +04:00
|
|
|
&url) == false) {
|
|
|
|
dom_string_unref(s);
|
2005-04-09 13:47:37 +04:00
|
|
|
return false;
|
2006-09-02 19:52:41 +04:00
|
|
|
}
|
2012-03-24 22:47:51 +04:00
|
|
|
dom_string_unref(s);
|
|
|
|
if (url == NULL)
|
2005-04-14 01:58:28 +04:00
|
|
|
return true;
|
2005-04-09 13:47:37 +04:00
|
|
|
|
2006-09-02 19:52:41 +04:00
|
|
|
/* don't include ourself */
|
2011-10-04 00:28:29 +04:00
|
|
|
if (nsurl_compare(content->base_url, url, NSURL_COMPLETE)) {
|
|
|
|
nsurl_unref(url);
|
2006-03-27 05:04:56 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2006-09-02 19:52:41 +04:00
|
|
|
/* create a new iframe */
|
2012-10-03 22:24:58 +04:00
|
|
|
iframe = talloc(content->bctx, struct content_html_iframe);
|
2012-03-24 22:47:51 +04:00
|
|
|
if (iframe == NULL) {
|
2011-10-04 00:28:29 +04:00
|
|
|
nsurl_unref(url);
|
2006-09-02 19:52:41 +04:00
|
|
|
return false;
|
|
|
|
}
|
2011-10-04 01:49:28 +04:00
|
|
|
|
|
|
|
talloc_set_destructor(iframe, box_iframes_talloc_destructor);
|
|
|
|
|
2006-09-02 19:52:41 +04:00
|
|
|
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;
|
2011-10-04 00:28:29 +04:00
|
|
|
iframe->url = url;
|
2014-10-25 15:04:11 +04:00
|
|
|
iframe->scrolling = BW_SCROLLING_AUTO;
|
2006-09-02 19:52:41 +04:00
|
|
|
iframe->border = true;
|
2010-06-09 13:53:07 +04:00
|
|
|
|
|
|
|
/* Add this iframe to the linked list of iframes */
|
2011-05-07 00:40:09 +04:00
|
|
|
iframe->next = content->iframe;
|
|
|
|
content->iframe = iframe;
|
2006-09-02 19:52:41 +04:00
|
|
|
|
|
|
|
/* fill in specified values */
|
2014-01-24 22:58:12 +04:00
|
|
|
err = dom_element_get_attribute(n, corestring_dom_name, &s);
|
2012-03-24 22:47:51 +04:00
|
|
|
if (err == DOM_NO_ERR && s != NULL) {
|
2012-10-03 22:24:58 +04:00
|
|
|
iframe->name = talloc_strdup(content->bctx, dom_string_data(s));
|
2012-03-24 22:47:51 +04:00
|
|
|
dom_string_unref(s);
|
2006-09-02 19:52:41 +04:00
|
|
|
}
|
2012-03-24 22:47:51 +04:00
|
|
|
|
2014-01-24 22:58:12 +04:00
|
|
|
err = dom_element_get_attribute(n, corestring_dom_frameborder, &s);
|
2012-03-24 22:47:51 +04:00
|
|
|
if (err == DOM_NO_ERR && s != NULL) {
|
|
|
|
i = atoi(dom_string_data(s));
|
2006-09-02 19:52:41 +04:00
|
|
|
iframe->border = (i != 0);
|
2012-03-24 22:47:51 +04:00
|
|
|
dom_string_unref(s);
|
2006-09-02 19:52:41 +04:00
|
|
|
}
|
2012-03-24 22:47:51 +04:00
|
|
|
|
2014-01-24 22:58:12 +04:00
|
|
|
err = dom_element_get_attribute(n, corestring_dom_bordercolor, &s);
|
2012-03-24 22:47:51 +04:00
|
|
|
if (err == DOM_NO_ERR && s != NULL) {
|
2009-07-24 03:05:34 +04:00
|
|
|
css_color color;
|
|
|
|
|
2012-03-24 22:47:51 +04:00
|
|
|
if (nscss_parse_colour(dom_string_data(s), &color))
|
2009-07-24 03:05:34 +04:00
|
|
|
iframe->border_colour = nscss_color_to_ns(color);
|
|
|
|
|
2012-03-24 22:47:51 +04:00
|
|
|
dom_string_unref(s);
|
2006-09-02 19:52:41 +04:00
|
|
|
}
|
2012-03-24 22:47:51 +04:00
|
|
|
|
2014-01-24 22:58:12 +04:00
|
|
|
err = dom_element_get_attribute(n, corestring_dom_scrolling, &s);
|
2012-03-24 22:47:51 +04:00
|
|
|
if (err == DOM_NO_ERR && s != NULL) {
|
2012-07-26 18:57:33 +04:00
|
|
|
if (dom_string_caseless_lwc_isequal(s,
|
|
|
|
corestring_lwc_yes))
|
2014-10-25 15:04:11 +04:00
|
|
|
iframe->scrolling = BW_SCROLLING_YES;
|
2012-07-26 18:57:33 +04:00
|
|
|
else if (dom_string_caseless_lwc_isequal(s,
|
|
|
|
corestring_lwc_no))
|
2014-10-25 15:04:11 +04:00
|
|
|
iframe->scrolling = BW_SCROLLING_NO;
|
2012-03-24 22:47:51 +04:00
|
|
|
dom_string_unref(s);
|
2006-09-02 19:52:41 +04:00
|
|
|
}
|
2012-03-24 22:47:51 +04:00
|
|
|
|
2014-01-24 22:58:12 +04:00
|
|
|
err = dom_element_get_attribute(n, corestring_dom_marginwidth, &s);
|
2012-03-24 22:47:51 +04:00
|
|
|
if (err == DOM_NO_ERR && s != NULL) {
|
|
|
|
iframe->margin_width = atoi(dom_string_data(s));
|
|
|
|
dom_string_unref(s);
|
2006-09-02 19:52:41 +04:00
|
|
|
}
|
2012-03-24 22:47:51 +04:00
|
|
|
|
2014-01-24 22:58:12 +04:00
|
|
|
err = dom_element_get_attribute(n, corestring_dom_marginheight, &s);
|
2012-03-24 22:47:51 +04:00
|
|
|
if (err == DOM_NO_ERR && s != NULL) {
|
|
|
|
iframe->margin_height = atoi(dom_string_data(s));
|
|
|
|
dom_string_unref(s);
|
2006-09-02 19:52:41 +04:00
|
|
|
}
|
2006-09-11 15:55:17 +04:00
|
|
|
|
2006-09-02 19:52:41 +04:00
|
|
|
/* box */
|
|
|
|
assert(box->style);
|
2011-06-15 00:00:18 +04:00
|
|
|
box->flags |= IFRAME;
|
2016-02-09 19:42:28 +03:00
|
|
|
box->flags |= IS_REPLACED;
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-07 02:39:45 +04:00
|
|
|
/**
|
|
|
|
* Helper function for adding textarea widget to box.
|
|
|
|
*
|
|
|
|
* This is a load of hacks to ensure boxes replaced with textareas
|
|
|
|
* can be handled by the layout code.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static bool box_input_text(html_content *html, struct box *box,
|
|
|
|
struct dom_node *node)
|
|
|
|
{
|
|
|
|
struct box *inline_container, *inline_box;
|
|
|
|
|
|
|
|
box->type = BOX_INLINE_BLOCK;
|
|
|
|
|
|
|
|
inline_container = box_create(NULL, 0, false, 0, 0, 0, 0, html->bctx);
|
|
|
|
if (!inline_container)
|
|
|
|
return false;
|
|
|
|
inline_container->type = BOX_INLINE_CONTAINER;
|
|
|
|
inline_box = box_create(NULL, box->style, false, 0, 0, box->title, 0,
|
|
|
|
html->bctx);
|
|
|
|
if (!inline_box)
|
|
|
|
return false;
|
|
|
|
inline_box->type = BOX_TEXT;
|
|
|
|
inline_box->text = talloc_strdup(html->bctx, "");
|
|
|
|
|
|
|
|
box_add_child(inline_container, inline_box);
|
|
|
|
box_add_child(box, inline_container);
|
|
|
|
|
|
|
|
return box_textarea_create_textarea(html, box, node);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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;
|
2012-03-24 22:47:51 +04:00
|
|
|
dom_string *type = NULL;
|
|
|
|
dom_exception err;
|
2011-10-04 14:23:47 +04:00
|
|
|
nsurl *url;
|
|
|
|
nserror error;
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2014-01-24 22:58:12 +04:00
|
|
|
dom_element_get_attribute(n, corestring_dom_type, &type);
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2012-07-14 21:16:37 +04:00
|
|
|
gadget = html_forms_get_control_for_node(content->forms, n);
|
2012-03-24 22:47:51 +04:00
|
|
|
if (gadget == NULL)
|
2009-02-20 14:39:25 +03:00
|
|
|
goto no_memory;
|
|
|
|
box->gadget = gadget;
|
2016-02-09 19:42:28 +03:00
|
|
|
box->flags |= IS_REPLACED;
|
2009-02-20 14:39:25 +03:00
|
|
|
gadget->box = box;
|
2014-02-17 18:38:53 +04:00
|
|
|
gadget->html = content;
|
2009-02-20 14:39:25 +03:00
|
|
|
|
2012-07-26 18:57:33 +04:00
|
|
|
if (type && dom_string_caseless_lwc_isequal(type,
|
|
|
|
corestring_lwc_password)) {
|
2013-02-07 02:39:45 +04:00
|
|
|
if (box_input_text(content, box, n) == false)
|
2005-03-26 04:12:27 +03:00
|
|
|
goto no_memory;
|
2012-07-26 18:57:33 +04:00
|
|
|
|
|
|
|
} else if (type && dom_string_caseless_lwc_isequal(type,
|
|
|
|
corestring_lwc_file)) {
|
2005-03-26 04:12:27 +03:00
|
|
|
box->type = BOX_INLINE_BLOCK;
|
2012-07-26 18:57:33 +04:00
|
|
|
|
|
|
|
} else if (type && dom_string_caseless_lwc_isequal(type,
|
|
|
|
corestring_lwc_hidden)) {
|
2005-03-26 04:12:27 +03:00
|
|
|
/* no box for hidden inputs */
|
2009-07-24 03:05:34 +04:00
|
|
|
box->type = BOX_NONE;
|
2012-07-26 18:57:33 +04:00
|
|
|
|
2014-10-15 12:35:43 +04:00
|
|
|
} else if (type &&
|
2012-07-26 18:57:33 +04:00
|
|
|
(dom_string_caseless_lwc_isequal(type,
|
|
|
|
corestring_lwc_checkbox) ||
|
|
|
|
dom_string_caseless_lwc_isequal(type,
|
|
|
|
corestring_lwc_radio))) {
|
|
|
|
|
2014-10-15 12:35:43 +04:00
|
|
|
} else if (type &&
|
2012-07-26 18:57:33 +04:00
|
|
|
(dom_string_caseless_lwc_isequal(type,
|
|
|
|
corestring_lwc_submit) ||
|
|
|
|
dom_string_caseless_lwc_isequal(type,
|
|
|
|
corestring_lwc_reset) ||
|
|
|
|
dom_string_caseless_lwc_isequal(type,
|
|
|
|
corestring_lwc_button))) {
|
2005-03-26 04:12:27 +03:00
|
|
|
struct box *inline_container, *inline_box;
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2012-03-24 22:47:51 +04:00
|
|
|
if (box_button(n, content, box, 0) == false)
|
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,
|
2012-10-03 22:24:58 +04:00
|
|
|
content->bctx);
|
2012-03-24 22:47:51 +04:00
|
|
|
if (inline_container == NULL)
|
2005-03-26 04:12:27 +03:00
|
|
|
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,
|
2012-10-03 22:24:58 +04:00
|
|
|
box->title, 0, content->bctx);
|
2012-03-24 22:47:51 +04:00
|
|
|
if (inline_box == NULL)
|
2005-03-26 04:12:27 +03:00
|
|
|
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)
|
2012-10-03 22:24:58 +04:00
|
|
|
inline_box->text = talloc_strdup(content->bctx,
|
2005-04-09 13:47:37 +04:00
|
|
|
box->gadget->value);
|
2005-03-26 04:12:27 +03:00
|
|
|
else if (box->gadget->type == GADGET_SUBMIT)
|
2012-10-03 22:24:58 +04:00
|
|
|
inline_box->text = talloc_strdup(content->bctx,
|
2005-04-09 13:47:37 +04:00
|
|
|
messages_get("Form_Submit"));
|
2009-02-20 14:39:25 +03:00
|
|
|
else if (box->gadget->type == GADGET_RESET)
|
2012-10-03 22:24:58 +04:00
|
|
|
inline_box->text = talloc_strdup(content->bctx,
|
2005-04-09 13:47:37 +04:00
|
|
|
messages_get("Form_Reset"));
|
2005-03-26 04:12:27 +03:00
|
|
|
else
|
2014-10-15 12:35:43 +04:00
|
|
|
inline_box->text = talloc_strdup(content->bctx,
|
2012-10-03 22:24:58 +04:00
|
|
|
"Button");
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2012-03-24 22:47:51 +04:00
|
|
|
if (inline_box->text == NULL)
|
2005-03-26 04:12:27 +03:00
|
|
|
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);
|
2012-07-26 18:57:33 +04:00
|
|
|
|
|
|
|
} else if (type && dom_string_caseless_lwc_isequal(type,
|
|
|
|
corestring_lwc_image)) {
|
2005-03-26 04:12:27 +03:00
|
|
|
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,
|
2012-03-24 22:47:51 +04:00
|
|
|
box_is_root(n)) != CSS_DISPLAY_NONE &&
|
2012-03-22 13:34:34 +04:00
|
|
|
nsoption_bool(foreground_images) == true) {
|
2012-03-24 22:47:51 +04:00
|
|
|
dom_string *s;
|
|
|
|
|
2014-01-24 22:58:12 +04:00
|
|
|
err = dom_element_get_attribute(n, corestring_dom_src, &s);
|
2012-03-24 22:47:51 +04:00
|
|
|
if (err == DOM_NO_ERR && s != NULL) {
|
2014-10-15 12:35:43 +04:00
|
|
|
error = nsurl_join(content->base_url,
|
2012-03-24 22:47:51 +04:00
|
|
|
dom_string_data(s), &url);
|
|
|
|
dom_string_unref(s);
|
2011-10-04 14:23:47 +04:00
|
|
|
if (error != NSERROR_OK)
|
|
|
|
goto no_memory;
|
|
|
|
|
2007-04-07 03:48:26 +04:00
|
|
|
/* if url is equivalent to the parent's url,
|
|
|
|
* we've got infinite inclusion. stop it here
|
|
|
|
*/
|
2011-10-04 14:23:47 +04:00
|
|
|
if (nsurl_compare(url, content->base_url,
|
|
|
|
NSURL_COMPLETE) == false) {
|
2007-04-07 03:48:26 +04:00
|
|
|
if (!html_fetch_object(content, url,
|
|
|
|
box, image_types,
|
2011-05-07 00:40:09 +04:00
|
|
|
content->base.
|
2008-02-25 19:37:48 +03:00
|
|
|
available_width,
|
2007-04-07 03:48:26 +04:00
|
|
|
1000, false)) {
|
2011-10-04 14:23:47 +04:00
|
|
|
nsurl_unref(url);
|
2007-04-07 03:48:26 +04:00
|
|
|
goto no_memory;
|
|
|
|
}
|
2006-09-02 19:52:41 +04:00
|
|
|
}
|
2011-10-04 14:23:47 +04:00
|
|
|
nsurl_unref(url);
|
2006-09-02 19:52:41 +04:00
|
|
|
}
|
2005-03-26 04:12:27 +03:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* the default type is "text" */
|
2013-02-07 02:39:45 +04:00
|
|
|
if (box_input_text(content, box, n) == false)
|
2005-03-26 04:12:27 +03:00
|
|
|
goto no_memory;
|
|
|
|
}
|
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
if (type)
|
2012-03-24 22:47:51 +04:00
|
|
|
dom_string_unref(type);
|
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
|
|
|
|
|
|
|
no_memory:
|
|
|
|
if (type)
|
2012-03-24 22:47:51 +04:00
|
|
|
dom_string_unref(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
|
|
|
|
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
|
2012-07-14 21:16:37 +04:00
|
|
|
gadget = html_forms_get_control_for_node(content->forms, n);
|
2009-02-20 14:39:25 +03:00
|
|
|
if (!gadget)
|
|
|
|
return false;
|
|
|
|
|
2014-02-17 18:38:53 +04:00
|
|
|
gadget->html = content;
|
2009-02-20 14:39:25 +03:00
|
|
|
box->gadget = gadget;
|
2016-02-09 19:42:28 +03:00
|
|
|
box->flags |= IS_REPLACED;
|
2009-02-20 14:39:25 +03:00
|
|
|
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;
|
2012-03-24 03:18:04 +04:00
|
|
|
dom_node *c, *c2;
|
2012-03-24 22:47:51 +04:00
|
|
|
dom_node *next, *next2;
|
|
|
|
dom_exception err;
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2012-07-14 21:16:37 +04:00
|
|
|
gadget = html_forms_get_control_for_node(content->forms, n);
|
2012-03-24 22:47:51 +04:00
|
|
|
if (gadget == NULL)
|
2005-04-09 13:47:37 +04:00
|
|
|
return false;
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2014-02-17 18:38:53 +04:00
|
|
|
gadget->html = content;
|
2012-03-24 22:47:51 +04:00
|
|
|
err = dom_node_get_first_child(n, &c);
|
2014-11-10 22:11:01 +03:00
|
|
|
if (err != DOM_NO_ERR) {
|
|
|
|
form_free_control(gadget);
|
2012-03-24 22:47:51 +04:00
|
|
|
return false;
|
2014-11-10 22:11:01 +03:00
|
|
|
}
|
2012-03-24 22:47:51 +04:00
|
|
|
|
|
|
|
while (c != NULL) {
|
|
|
|
dom_string *name;
|
|
|
|
|
|
|
|
err = dom_node_get_node_name(c, &name);
|
|
|
|
if (err != DOM_NO_ERR) {
|
|
|
|
dom_node_unref(c);
|
2014-11-10 22:11:01 +03:00
|
|
|
form_free_control(gadget);
|
2012-03-24 22:47:51 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-07-26 18:57:33 +04:00
|
|
|
if (dom_string_caseless_lwc_isequal(name,
|
|
|
|
corestring_lwc_option)) {
|
2012-03-24 22:47:51 +04:00
|
|
|
dom_string_unref(name);
|
|
|
|
|
|
|
|
if (box_select_add_option(gadget, c) == false) {
|
|
|
|
dom_node_unref(c);
|
2014-11-10 22:40:20 +03:00
|
|
|
form_free_control(gadget);
|
|
|
|
return false;
|
2012-03-24 22:47:51 +04:00
|
|
|
}
|
2012-07-26 18:57:33 +04:00
|
|
|
} else if (dom_string_caseless_lwc_isequal(name,
|
|
|
|
corestring_lwc_optgroup)) {
|
2012-03-24 22:47:51 +04:00
|
|
|
dom_string_unref(name);
|
|
|
|
|
|
|
|
err = dom_node_get_first_child(c, &c2);
|
|
|
|
if (err != DOM_NO_ERR) {
|
|
|
|
dom_node_unref(c);
|
2014-11-30 14:23:30 +03:00
|
|
|
form_free_control(gadget);
|
2012-03-24 22:47:51 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (c2 != NULL) {
|
|
|
|
dom_string *c2_name;
|
|
|
|
|
|
|
|
err = dom_node_get_node_name(c2, &c2_name);
|
|
|
|
if (err != DOM_NO_ERR) {
|
|
|
|
dom_node_unref(c2);
|
|
|
|
dom_node_unref(c);
|
2015-09-04 16:55:43 +03:00
|
|
|
form_free_control(gadget);
|
2012-03-24 22:47:51 +04:00
|
|
|
return false;
|
|
|
|
}
|
2014-10-15 12:35:43 +04:00
|
|
|
|
2012-07-26 18:57:33 +04:00
|
|
|
if (dom_string_caseless_lwc_isequal(c2_name,
|
|
|
|
corestring_lwc_option)) {
|
2012-03-24 22:47:51 +04:00
|
|
|
dom_string_unref(c2_name);
|
|
|
|
|
2014-10-15 12:35:43 +04:00
|
|
|
if (box_select_add_option(gadget,
|
2012-03-24 22:47:51 +04:00
|
|
|
c2) == false) {
|
|
|
|
dom_node_unref(c2);
|
|
|
|
dom_node_unref(c);
|
2014-11-10 22:11:01 +03:00
|
|
|
return false;
|
2012-03-24 22:47:51 +04:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
dom_string_unref(c2_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
err = dom_node_get_next_sibling(c2, &next2);
|
|
|
|
if (err != DOM_NO_ERR) {
|
|
|
|
dom_node_unref(c2);
|
|
|
|
dom_node_unref(c);
|
|
|
|
return false;
|
2005-04-09 13:47:37 +04:00
|
|
|
}
|
2012-03-24 22:47:51 +04:00
|
|
|
|
|
|
|
dom_node_unref(c2);
|
|
|
|
c2 = next2;
|
2005-04-09 13:47:37 +04:00
|
|
|
}
|
2012-03-24 22:47:51 +04:00
|
|
|
} else {
|
|
|
|
dom_string_unref(name);
|
2005-04-09 13:47:37 +04:00
|
|
|
}
|
2014-10-15 12:35:43 +04:00
|
|
|
|
2012-03-24 22:47:51 +04:00
|
|
|
err = dom_node_get_next_sibling(c, &next);
|
|
|
|
if (err != DOM_NO_ERR) {
|
|
|
|
dom_node_unref(c);
|
2014-11-10 22:40:20 +03:00
|
|
|
form_free_control(gadget);
|
2012-03-24 22:47:51 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
dom_node_unref(c);
|
|
|
|
c = next;
|
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 */
|
2014-11-10 22:11:01 +03:00
|
|
|
form_free_control(gadget);
|
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
|
|
|
box->type = BOX_INLINE_BLOCK;
|
|
|
|
box->gadget = gadget;
|
2016-02-09 19:42:28 +03:00
|
|
|
box->flags |= IS_REPLACED;
|
2005-04-09 13:47:37 +04:00
|
|
|
gadget->box = box;
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2012-10-03 22:24:58 +04:00
|
|
|
inline_container = box_create(NULL, 0, false, 0, 0, 0, 0, content->bctx);
|
2012-03-24 22:47:51 +04:00
|
|
|
if (inline_container == NULL)
|
2005-04-09 13:47:37 +04:00
|
|
|
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,
|
2012-10-03 22:24:58 +04:00
|
|
|
content->bctx);
|
2012-03-24 22:47:51 +04:00
|
|
|
if (inline_box == NULL)
|
2005-04-09 13:47:37 +04:00
|
|
|
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
|
|
|
|
2012-03-24 22:47:51 +04:00
|
|
|
if (gadget->data.select.multiple == false &&
|
2005-04-09 13:47:37 +04:00
|
|
|
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;
|
2014-01-24 21:32:49 +04:00
|
|
|
dom_html_option_element_set_selected(
|
|
|
|
gadget->data.select.current->node, true);
|
2005-03-26 04:12:27 +03:00
|
|
|
}
|
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
if (gadget->data.select.num_selected == 0)
|
2012-10-03 22:24:58 +04:00
|
|
|
inline_box->text = talloc_strdup(content->bctx,
|
2005-04-15 03:17:37 +04:00
|
|
|
messages_get("Form_None"));
|
2005-04-09 13:47:37 +04:00
|
|
|
else if (gadget->data.select.num_selected == 1)
|
2012-10-03 22:24:58 +04:00
|
|
|
inline_box->text = talloc_strdup(content->bctx,
|
2005-04-09 13:47:37 +04:00
|
|
|
gadget->data.select.current->text);
|
|
|
|
else
|
2012-10-03 22:24:58 +04:00
|
|
|
inline_box->text = talloc_strdup(content->bctx,
|
2005-04-15 03:17:37 +04:00
|
|
|
messages_get("Form_Many"));
|
2012-03-24 22:47:51 +04:00
|
|
|
if (inline_box->text == NULL)
|
2005-04-09 13:47:37 +04:00
|
|
|
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()).
|
|
|
|
*
|
2014-11-12 19:21:23 +03:00
|
|
|
* \param control select containing the <option>
|
|
|
|
* \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
|
|
|
*/
|
|
|
|
|
2012-03-24 03:18:04 +04:00
|
|
|
bool box_select_add_option(struct form_control *control, dom_node *n)
|
2005-04-09 13:47:37 +04:00
|
|
|
{
|
2012-03-24 22:47:51 +04:00
|
|
|
char *value = NULL;
|
|
|
|
char *text = NULL;
|
|
|
|
char *text_nowrap = NULL;
|
2005-04-09 13:47:37 +04:00
|
|
|
bool selected;
|
2012-03-24 22:47:51 +04:00
|
|
|
dom_string *content, *s;
|
|
|
|
dom_exception err;
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2012-03-24 22:47:51 +04:00
|
|
|
err = dom_node_get_text_content(n, &content);
|
|
|
|
if (err != DOM_NO_ERR)
|
|
|
|
return false;
|
|
|
|
|
2012-09-28 11:27:32 +04:00
|
|
|
if (content != NULL) {
|
|
|
|
text = squash_whitespace(dom_string_data(content));
|
|
|
|
dom_string_unref(content);
|
|
|
|
} else {
|
|
|
|
text = strdup("");
|
|
|
|
}
|
2012-03-24 22:47:51 +04:00
|
|
|
|
|
|
|
if (text == NULL)
|
2005-04-09 13:47:37 +04:00
|
|
|
goto no_memory;
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2014-01-24 22:58:12 +04:00
|
|
|
err = dom_element_get_attribute(n, corestring_dom_value, &s);
|
2012-03-24 22:47:51 +04:00
|
|
|
if (err == DOM_NO_ERR && s != NULL) {
|
|
|
|
value = strdup(dom_string_data(s));
|
|
|
|
dom_string_unref(s);
|
|
|
|
} else {
|
2005-04-09 13:47:37 +04:00
|
|
|
value = strdup(text);
|
2012-03-24 22:47:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (value == NULL)
|
2005-04-09 13:47:37 +04:00
|
|
|
goto no_memory;
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2014-01-24 22:58:12 +04:00
|
|
|
dom_element_has_attribute(n, corestring_dom_selected, &selected);
|
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);
|
2012-03-24 22:47:51 +04:00
|
|
|
if (text_nowrap == NULL)
|
2008-02-25 19:37:48 +03:00
|
|
|
goto no_memory;
|
|
|
|
|
2014-01-04 21:06:10 +04:00
|
|
|
if (form_add_option(control, value, text_nowrap, selected, n) == false)
|
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)
|
|
|
|
{
|
2013-02-07 02:39:45 +04:00
|
|
|
/* Get the form_control for the DOM node */
|
2012-07-14 21:16:37 +04:00
|
|
|
box->gadget = html_forms_get_control_for_node(content->forms, n);
|
2012-03-24 22:47:51 +04:00
|
|
|
if (box->gadget == NULL)
|
2005-04-09 13:47:37 +04:00
|
|
|
return false;
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2016-02-09 19:42:28 +03:00
|
|
|
box->flags |= IS_REPLACED;
|
2014-02-17 18:38:53 +04:00
|
|
|
box->gadget->html = content;
|
2013-02-07 02:39:45 +04:00
|
|
|
box->gadget->box = box;
|
2005-04-09 13:47:37 +04:00
|
|
|
|
2013-02-07 02:39:45 +04:00
|
|
|
if (!box_input_text(content, box, n))
|
2012-03-24 22:47:51 +04:00
|
|
|
return false;
|
|
|
|
|
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;
|
2012-03-24 22:47:51 +04:00
|
|
|
dom_namednodemap *attrs;
|
2012-09-11 16:10:50 +04:00
|
|
|
unsigned long idx;
|
|
|
|
uint32_t num_attrs;
|
2012-03-24 22:47:51 +04:00
|
|
|
dom_string *src;
|
|
|
|
dom_exception err;
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2009-07-24 03:05:34 +04:00
|
|
|
if (box->style && css_computed_display(box->style,
|
2012-03-24 22:47:51 +04:00
|
|
|
box_is_root(n)) == CSS_DISPLAY_NONE)
|
2007-04-07 03:48:26 +04:00
|
|
|
return true;
|
|
|
|
|
2012-10-03 22:24:58 +04:00
|
|
|
params = talloc(content->bctx, struct object_params);
|
2012-03-24 22:47:51 +04:00
|
|
|
if (params == NULL)
|
2005-04-09 13:47:37 +04:00
|
|
|
return false;
|
2011-10-04 01:49:28 +04:00
|
|
|
|
|
|
|
talloc_set_destructor(params, box_object_talloc_destructor);
|
|
|
|
|
2012-03-24 22:47:51 +04:00
|
|
|
params->data = NULL;
|
|
|
|
params->type = NULL;
|
|
|
|
params->codetype = NULL;
|
|
|
|
params->codebase = NULL;
|
|
|
|
params->classid = NULL;
|
|
|
|
params->params = NULL;
|
2005-04-14 01:58:28 +04:00
|
|
|
|
|
|
|
/* src is a URL */
|
2014-01-24 22:58:12 +04:00
|
|
|
err = dom_element_get_attribute(n, corestring_dom_src, &src);
|
2012-03-24 22:47:51 +04:00
|
|
|
if (err != DOM_NO_ERR || src == NULL)
|
2005-04-14 01:58:28 +04:00
|
|
|
return true;
|
2016-01-21 17:09:57 +03:00
|
|
|
if (box_extract_link(content, dom_string_data(src), content->base_url,
|
2012-03-24 22:47:51 +04:00
|
|
|
¶ms->data) == false) {
|
|
|
|
dom_string_unref(src);
|
2005-04-14 01:58:28 +04:00
|
|
|
return false;
|
2012-03-24 22:47:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
dom_string_unref(src);
|
|
|
|
|
|
|
|
if (params->data == NULL)
|
2005-04-14 01:58:28 +04:00
|
|
|
return true;
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2006-03-27 05:04:56 +04:00
|
|
|
/* Don't include ourself */
|
2011-10-04 00:28:29 +04:00
|
|
|
if (nsurl_compare(content->base_url, params->data, NSURL_COMPLETE))
|
2006-03-27 05:04:56 +04:00
|
|
|
return true;
|
|
|
|
|
2005-04-14 01:58:28 +04:00
|
|
|
/* add attributes as parameters to linked list */
|
2012-03-24 22:47:51 +04:00
|
|
|
err = dom_node_get_attributes(n, &attrs);
|
|
|
|
if (err != DOM_NO_ERR)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
err = dom_namednodemap_get_length(attrs, &num_attrs);
|
|
|
|
if (err != DOM_NO_ERR) {
|
|
|
|
dom_namednodemap_unref(attrs);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (idx = 0; idx < num_attrs; idx++) {
|
|
|
|
dom_attr *attr;
|
|
|
|
dom_string *name, *value;
|
|
|
|
|
2012-03-25 02:30:28 +04:00
|
|
|
err = dom_namednodemap_item(attrs, idx, (void *) &attr);
|
2012-03-24 22:47:51 +04:00
|
|
|
if (err != DOM_NO_ERR) {
|
|
|
|
dom_namednodemap_unref(attrs);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = dom_attr_get_name(attr, &name);
|
|
|
|
if (err != DOM_NO_ERR) {
|
|
|
|
dom_namednodemap_unref(attrs);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-07-26 18:57:33 +04:00
|
|
|
if (dom_string_caseless_lwc_isequal(name, corestring_lwc_src)) {
|
2012-03-24 22:47:51 +04:00
|
|
|
dom_string_unref(name);
|
2005-04-14 01:58:28 +04:00
|
|
|
continue;
|
2012-03-24 22:47:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
err = dom_attr_get_value(attr, &value);
|
|
|
|
if (err != DOM_NO_ERR) {
|
|
|
|
dom_string_unref(name);
|
|
|
|
dom_namednodemap_unref(attrs);
|
|
|
|
return false;
|
|
|
|
}
|
2005-04-14 01:58:28 +04:00
|
|
|
|
2012-10-03 22:24:58 +04:00
|
|
|
param = talloc(content->bctx, struct object_param);
|
2012-03-24 22:47:51 +04:00
|
|
|
if (param == NULL) {
|
|
|
|
dom_string_unref(value);
|
|
|
|
dom_string_unref(name);
|
|
|
|
dom_namednodemap_unref(attrs);
|
2005-04-14 01:58:28 +04:00
|
|
|
return false;
|
2012-03-24 22:47:51 +04:00
|
|
|
}
|
|
|
|
|
2012-10-03 22:24:58 +04:00
|
|
|
param->name = talloc_strdup(content->bctx, dom_string_data(name));
|
|
|
|
param->value = talloc_strdup(content->bctx, dom_string_data(value));
|
2012-03-24 22:47:51 +04:00
|
|
|
param->type = NULL;
|
2012-10-03 22:24:58 +04:00
|
|
|
param->valuetype = talloc_strdup(content->bctx, "data");
|
2012-03-24 22:47:51 +04:00
|
|
|
param->next = NULL;
|
|
|
|
|
|
|
|
dom_string_unref(value);
|
|
|
|
dom_string_unref(name);
|
2005-04-14 01:58:28 +04:00
|
|
|
|
2014-10-15 12:35:43 +04:00
|
|
|
if (param->name == NULL || param->value == NULL ||
|
2012-03-24 22:47:51 +04:00
|
|
|
param->valuetype == NULL) {
|
|
|
|
dom_namednodemap_unref(attrs);
|
2005-04-09 13:47:37 +04:00
|
|
|
return false;
|
2012-03-24 22:47:51 +04:00
|
|
|
}
|
2005-04-09 13:47:37 +04:00
|
|
|
|
2005-04-14 01:58:28 +04:00
|
|
|
param->next = params->params;
|
|
|
|
params->params = param;
|
|
|
|
}
|
2005-04-09 13:47:37 +04:00
|
|
|
|
2012-03-24 22:47:51 +04:00
|
|
|
dom_namednodemap_unref(attrs);
|
|
|
|
|
2005-04-14 01:58:28 +04:00
|
|
|
box->object_params = params;
|
2005-03-26 04:12:27 +03:00
|
|
|
|
|
|
|
/* start fetch */
|
2016-02-09 19:42:28 +03:00
|
|
|
box->flags |= IS_REPLACED;
|
2011-10-04 14:23:47 +04:00
|
|
|
return html_fetch_object(content, params->data, box, CONTENT_ANY,
|
|
|
|
content->base.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.
|
|
|
|
*/
|
|
|
|
|
2012-03-24 03:18:04 +04:00
|
|
|
bool box_get_attribute(dom_node *n, const char *attribute,
|
2005-04-10 21:08:49 +04:00
|
|
|
void *context, char **value)
|
|
|
|
{
|
2012-03-24 22:47:51 +04:00
|
|
|
char *result;
|
|
|
|
dom_string *attr, *attr_name;
|
|
|
|
dom_exception err;
|
|
|
|
|
2014-10-15 12:35:43 +04:00
|
|
|
err = dom_string_create_interned((const uint8_t *) attribute,
|
2012-03-24 22:47:51 +04:00
|
|
|
strlen(attribute), &attr_name);
|
|
|
|
if (err != DOM_NO_ERR)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
err = dom_element_get_attribute(n, attr_name, &attr);
|
|
|
|
if (err != DOM_NO_ERR) {
|
|
|
|
dom_string_unref(attr_name);
|
2005-04-10 21:08:49 +04:00
|
|
|
return false;
|
2012-03-24 22:47:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
dom_string_unref(attr_name);
|
|
|
|
|
|
|
|
if (attr != NULL) {
|
|
|
|
result = talloc_strdup(context, dom_string_data(attr));
|
|
|
|
|
|
|
|
dom_string_unref(attr);
|
2014-10-15 12:35:43 +04:00
|
|
|
|
2012-03-24 22:47:51 +04:00
|
|
|
if (result == NULL)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
*value = result;
|
|
|
|
}
|
|
|
|
|
2005-04-10 21:08:49 +04:00
|
|
|
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
|
|
|
|
*/
|
|
|
|
|
2016-01-21 17:09:57 +03:00
|
|
|
bool box_extract_link(const html_content *content,
|
|
|
|
const char *rel, nsurl *base, nsurl **result)
|
2005-04-10 21:08:49 +04:00
|
|
|
{
|
|
|
|
char *s, *s1, *apos0 = 0, *apos1 = 0, *quot0 = 0, *quot1 = 0;
|
|
|
|
unsigned int i, j, end;
|
2011-10-04 00:28:29 +04:00
|
|
|
nserror error;
|
2005-04-10 21:08:49 +04:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2016-01-21 17:11:36 +03:00
|
|
|
if (content->enable_scripting == false) {
|
2013-03-20 01:38:25 +04:00
|
|
|
/* 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, '"');
|
2014-10-15 12:35:43 +04:00
|
|
|
if (apos0 && apos1 &&
|
2013-03-20 01:38:25 +04:00
|
|
|
(!quot0 || !quot1 || apos0 < quot0)) {
|
|
|
|
*apos1 = 0;
|
|
|
|
s1 = apos0 + 1;
|
|
|
|
} else if (quot0 && quot1) {
|
|
|
|
*quot1 = 0;
|
|
|
|
s1 = quot0 + 1;
|
|
|
|
}
|
2005-04-10 21:08:49 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* construct absolute URL */
|
2011-10-04 00:28:29 +04:00
|
|
|
error = nsurl_join(base, s1, result);
|
2005-04-10 21:08:49 +04:00
|
|
|
free(s);
|
2011-10-04 00:28:29 +04:00
|
|
|
if (error != NSERROR_OK) {
|
|
|
|
*result = NULL;
|
2005-04-10 21:08:49 +04:00
|
|
|
return false;
|
2011-10-04 00:28:29 +04:00
|
|
|
}
|
2005-04-10 21:08:49 +04:00
|
|
|
|
|
|
|
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
|
|
|
|