From 6ff2da6e311c8a02ba1d9ab5f760511a3039982f Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Sun, 25 Mar 2012 11:14:19 +0000 Subject: fix node_is_link add dom string globals to css handler svn path=/trunk/netsurf/; revision=13678 --- css/css.c | 135 ++++++++++++++++++++++++++++++++++++--------------------- css/internal.h | 3 ++ css/select.c | 30 ++++++++++--- 3 files changed, 112 insertions(+), 56 deletions(-) (limited to 'css') diff --git a/css/css.c b/css/css.c index b67621c44..99c752a8d 100644 --- a/css/css.c +++ b/css/css.c @@ -19,6 +19,7 @@ #include #include +#include #include "content/content_protected.h" #include "content/fetch.h" @@ -55,7 +56,6 @@ typedef struct { * imports array */ } nscss_import_ctx; -static void nscss_fini(void); static nserror nscss_create(const content_handler *handler, lwc_string *imime_type, const http_parameter *params, llcache_handle *llcache, const char *fallback_charset, @@ -79,58 +79,12 @@ static css_error nscss_register_imports(struct content_css_data *c); static css_error nscss_register_import(struct content_css_data *c, const hlcache_handle *import); -static const content_handler css_content_handler = { - .fini = nscss_fini, - .create = nscss_create, - .process_data = nscss_process_data, - .data_complete = nscss_convert, - .destroy = nscss_destroy, - .clone = nscss_clone, - .matches_quirks = nscss_matches_quirks, - .type = nscss_content_type, - .no_share = false, -}; static lwc_string *css_charset; static css_stylesheet *blank_import; -/** - * Initialise the CSS content handler - */ -nserror nscss_init(void) -{ - lwc_error lerror; - nserror error; - - lerror = lwc_intern_string("charset", SLEN("charset"), &css_charset); - if (lerror != lwc_error_ok) { - return NSERROR_NOMEM; - } - - error = content_factory_register_handler("text/css", - &css_content_handler); - if (error != NSERROR_OK) { - lwc_string_unref(css_charset); - } - - return error; -} - -/** - * Clean up after the CSS content handler - */ -void nscss_fini(void) -{ - if (css_charset != NULL) { - lwc_string_unref(css_charset); - css_charset = NULL; - } - - if (blank_import != NULL) { - css_stylesheet_destroy(blank_import); - blank_import = NULL; - } -} +dom_string *nscss_dom_string_a; +dom_string *nscss_dom_string_href; /** * Initialise a CSS content @@ -812,3 +766,86 @@ css_error nscss_register_import(struct content_css_data *c, return error; } +/** + * Clean up after the CSS content handler + */ +static void nscss_fini(void) +{ +#define CSS_DOM_STRING_UNREF(NAME) \ + do { \ + if (nscss_dom_string_##NAME != NULL) { \ + dom_string_unref(nscss_dom_string_##NAME); \ + nscss_dom_string_##NAME = NULL; \ + } \ + } while (0) \ + + CSS_DOM_STRING_UNREF(href); + CSS_DOM_STRING_UNREF(a); + +#undef CSS_DOM_STRING_UNREF + + + if (css_charset != NULL) { + lwc_string_unref(css_charset); + css_charset = NULL; + } + + if (blank_import != NULL) { + css_stylesheet_destroy(blank_import); + blank_import = NULL; + } +} + +static const content_handler css_content_handler = { + .fini = nscss_fini, + .create = nscss_create, + .process_data = nscss_process_data, + .data_complete = nscss_convert, + .destroy = nscss_destroy, + .clone = nscss_clone, + .matches_quirks = nscss_matches_quirks, + .type = nscss_content_type, + .no_share = false, +}; + +/** + * Initialise the CSS content handler + */ +nserror nscss_init(void) +{ + lwc_error lerror; + nserror error; + dom_exception exc; + + lerror = lwc_intern_string("charset", SLEN("charset"), &css_charset); + if (lerror != lwc_error_ok) { + error = NSERROR_NOMEM; + goto error; + } + + +#define CSS_DOM_STRING_INTERN(NAME) \ + exc = dom_string_create_interned((const uint8_t *)#NAME, \ + sizeof(#NAME) - 1, \ + &nscss_dom_string_##NAME ); \ + if ((exc != DOM_NO_ERR) || (nscss_dom_string_##NAME == NULL)) \ + goto error + + CSS_DOM_STRING_INTERN(a); + CSS_DOM_STRING_INTERN(href); + + +#undef CSS_DOM_STRING_INTERN + + error = content_factory_register_handler("text/css", + &css_content_handler); + if (error != NSERROR_OK) + goto error; + + return NSERROR_OK; + +error: + nscss_fini(); + + return error; +} diff --git a/css/internal.h b/css/internal.h index 0344d6b32..c1777fe58 100644 --- a/css/internal.h +++ b/css/internal.h @@ -24,4 +24,7 @@ css_error nscss_resolve_url(void *pw, const char *base, lwc_string *rel, lwc_string **abs); +extern struct dom_string *nscss_dom_string_a; +extern struct dom_string *nscss_dom_string_href; + #endif diff --git a/css/select.c b/css/select.c index b87bbfc3d..c8a395ba6 100644 --- a/css/select.c +++ b/css/select.c @@ -1627,20 +1627,36 @@ css_error node_is_empty(void *pw, void *node, bool *match) * Callback to determine if a node is a linking element. * * \param pw HTML document - * \param node DOM node + * \param n DOM node * \param match Pointer to location to receive result * \return CSS_OK. * * \post \a match will contain true if the node matches and false otherwise. */ -css_error node_is_link(void *pw, void *node, bool *match) +css_error node_is_link(void *pw, void *n, bool *match) { -#ifdef FIXME - xmlNode *n = node; + dom_node *node = n; + dom_exception exc; + dom_string *node_name = NULL; + + exc = dom_node_get_node_name(node, &node_name); + if ((exc != DOM_NO_ERR) || (node_name == NULL)) { + return CSS_NOMEM; + } + + if (dom_string_caseless_isequal(node_name, nscss_dom_string_a)) { + bool has_href; + exc = dom_element_has_attribute(node, nscss_dom_string_href, &has_href); + if ((exc == DOM_NO_ERR) && (has_href)) { + *match = true; + } else { + *match = false; + } + } else { + *match = false; + } + dom_string_unref(node_name); - *match = (strcasecmp((const char *) n->name, "a") == 0 && - xmlHasProp(n, (const xmlChar *) "href") != NULL); -#endif return CSS_OK; } -- cgit v1.2.3