From ab45ecd228d19e0ce6bc17a94a09ea51ef53efe3 Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Sat, 29 Oct 2011 11:37:05 +0000 Subject: Use lwc_string for box->id. svn path=/trunk/netsurf/; revision=13093 --- render/box.c | 14 ++++++++++---- render/box.h | 6 +++--- render/box_construct.c | 33 ++++++++++++++++++++++++++++----- render/html.c | 2 +- render/html.h | 2 +- 5 files changed, 43 insertions(+), 14 deletions(-) (limited to 'render') diff --git a/render/box.c b/render/box.c index e26c2f565..a65094548 100644 --- a/render/box.c +++ b/render/box.c @@ -89,6 +89,9 @@ static int box_talloc_destructor(struct box *b) if (b->href != NULL) nsurl_unref(b->href); + + if (b->id != NULL) + lwc_string_unref(b->id); return 0; } @@ -112,7 +115,7 @@ static int box_talloc_destructor(struct box *b) struct box * box_create(css_select_results *styles, css_computed_style *style, bool style_owned, nsurl *href, const char *target, - const char *title, char *id, void *context) + const char *title, lwc_string *id, void *context) { unsigned int i; struct box *box; @@ -850,11 +853,14 @@ struct box *box_pick_text_box(struct html_content *html, * \return the box or 0 if not found */ -struct box *box_find_by_id(struct box *box, const char *id) +struct box *box_find_by_id(struct box *box, lwc_string *id) { struct box *a, *b; + bool m; - if (box->id != NULL && strcmp(id, box->id) == 0) + if (box->id != NULL && + lwc_string_isequal(id, box->id, &m) == lwc_error_ok && + m == true) return box; for (a = box->children; a; a = a->next) { @@ -952,7 +958,7 @@ void box_dump(FILE *stream, struct box *box, unsigned int depth) if (box->title) fprintf(stream, " [%s]", box->title); if (box->id) - fprintf(stream, " <%s>", box->id); + fprintf(stream, " <%s>", lwc_string_data(box->id)); if (box->type == BOX_INLINE || box->type == BOX_INLINE_END) fprintf(stream, " inline_end %p", box->inline_end); if (box->float_children) diff --git a/render/box.h b/render/box.h index 1df3b94a7..285dfddd2 100644 --- a/render/box.h +++ b/render/box.h @@ -251,7 +251,7 @@ struct box { struct form_control* gadget; char *usemap; /** (Image)map to use with this object, or 0 if none */ - char *id; /**< value of id attribute (or name for anchors) */ + lwc_string *id; /**< value of id attribute (or name for anchors) */ /** Background image for this box, or 0 if none */ struct hlcache_handle *background; @@ -313,7 +313,7 @@ extern const char *TARGET_BLANK; void *box_style_alloc(void *ptr, size_t len, void *pw); struct box * box_create(css_select_results *styles, css_computed_style *style, bool style_owned, nsurl *href, const char *target, - const char *title, char *id, void *context); + const char *title, lwc_string *id, void *context); void box_add_child(struct box *parent, struct box *child); void box_insert_sibling(struct box *box, struct box *new_box); void box_unlink_and_free(struct box *box); @@ -327,7 +327,7 @@ struct box *box_object_at_point(struct hlcache_handle *h, int x, int y); struct box *box_href_at_point(struct hlcache_handle *h, int x, int y); struct box *box_pick_text_box(struct html_content *html, int x, int y, int dir, int *dx, int *dy); -struct box *box_find_by_id(struct box *box, const char *id); +struct box *box_find_by_id(struct box *box, lwc_string *id); bool box_visible(struct box *box); void box_dump(FILE *stream, struct box *box, unsigned int depth); bool box_extract_link(const char *rel, nsurl *base, nsurl **result); diff --git a/render/box_construct.c b/render/box_construct.c index d00dc41e2..fd48eda8f 100644 --- a/render/box_construct.c +++ b/render/box_construct.c @@ -549,7 +549,7 @@ bool box_construct_element(struct box_construct_ctx *ctx, bool *convert_children) { xmlChar *title0, *s; - char *id = NULL; + lwc_string *id = NULL; struct box *box = NULL; css_select_results *styles = NULL; struct element_entry *element; @@ -590,8 +590,15 @@ bool box_construct_element(struct box_construct_ctx *ctx, } /* Extract id attribute, if present */ - if (box_get_attribute(ctx->n, "id", ctx->content, &id) == false) - return false; + s = xmlGetProp(ctx->n, (const xmlChar *) "id"); + if (s) { + lwc_error lerror = lwc_intern_string((const char *) s, + strlen((const char *) s), &id); + xmlFree(s); + + if (lerror != lwc_error_ok) + id = NULL; + } box = box_create(styles, styles->styles[CSS_PSEUDO_ELEMENT_NONE], false, props.href, props.target, props.title, id, @@ -1290,8 +1297,24 @@ bool box_a(BOX_SPECIAL_PARAMS) } /* name and id share the same namespace */ - if (!box_get_attribute(n, "name", content, &box->id)) - return false; + s = xmlGetProp(n, (const xmlChar *) "name"); + if (s) { + lwc_error lerror; + lwc_string *lwc_name; + + lerror = lwc_intern_string((const char *) s, + strlen((const char *) s), &lwc_name); + xmlFree(s); + + if (lerror == lwc_error_ok) { + /* name replaces existing id + * TODO: really? */ + if (box->id != NULL) + lwc_string_unref(box->id); + + box->id = lwc_name; + } + } /* target frame [16.3] */ if ((s = xmlGetProp(n, (const xmlChar *) "target"))) { diff --git a/render/html.c b/render/html.c index ad0c7f4f2..72daa1a11 100644 --- a/render/html.c +++ b/render/html.c @@ -2496,7 +2496,7 @@ struct content_html_object *html_get_objects(hlcache_handle *h, unsigned int *n) * \param y Updated to global y coord iff id found * \return true iff id found */ -bool html_get_id_offset(hlcache_handle *h, const char *frag_id, int *x, int *y) +bool html_get_id_offset(hlcache_handle *h, lwc_string *frag_id, int *x, int *y) { struct box *pos; struct box *layout; diff --git a/render/html.h b/render/html.h index dba1ce427..c8e146d90 100644 --- a/render/html.h +++ b/render/html.h @@ -169,7 +169,7 @@ struct html_stylesheet *html_get_stylesheets(struct hlcache_handle *h, unsigned int *n); struct content_html_object *html_get_objects(struct hlcache_handle *h, unsigned int *n); -bool html_get_id_offset(struct hlcache_handle *h, const char *frag_id, +bool html_get_id_offset(struct hlcache_handle *h, lwc_string *frag_id, int *x, int *y); #endif -- cgit v1.2.3