Use lwc_string for box->id.

svn path=/trunk/netsurf/; revision=13093
This commit is contained in:
Michael Drake 2011-10-29 11:37:05 +00:00
parent 62900af515
commit ab45ecd228
6 changed files with 46 additions and 17 deletions

View File

@ -1482,7 +1482,7 @@ void browser_window_update(struct browser_window *bw, bool scroll_to_top)
/* if frag_id exists, then try to scroll to it */
/** \TODO don't do this if the user has scrolled */
if (bw->frag_id && html_get_id_offset(bw->current_content,
lwc_string_data(bw->frag_id), &x, &y)) {
bw->frag_id, &x, &y)) {
browser_window_set_scroll(bw, x, y);
}
@ -1501,7 +1501,7 @@ void browser_window_update(struct browser_window *bw, bool scroll_to_top)
/* if frag_id exists, then try to scroll to it */
/** \TODO don't do this if the user has scrolled */
if (bw->frag_id && html_get_id_offset(bw->current_content,
lwc_string_data(bw->frag_id), &x, &y)) {
bw->frag_id, &x, &y)) {
browser_window_set_scroll(bw, x, y);
}
@ -1519,7 +1519,7 @@ void browser_window_update(struct browser_window *bw, bool scroll_to_top)
/* if frag_id exists, then try to scroll to it */
/** \TODO don't do this if the user has scrolled */
if (bw->frag_id && html_get_id_offset(bw->current_content,
lwc_string_data(bw->frag_id), &x, &y)) {
bw->frag_id, &x, &y)) {
browser_window_set_scroll(bw, x, y);
}

View File

@ -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)

View File

@ -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);

View File

@ -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"))) {

View File

@ -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;

View File

@ -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