diff options
author | John Mark Bell <jmb@netsurf-browser.org> | 2009-02-09 12:43:25 +0000 |
---|---|---|
committer | John Mark Bell <jmb@netsurf-browser.org> | 2009-02-09 12:43:25 +0000 |
commit | 932213b80d817b8646505dfb4af322c9742c12d2 (patch) | |
tree | 39c09c3e8fcf7da464ceb51c23eb3725e1513425 /src/select/select.c | |
parent | 9a6b565eed95b0237cb74f39256f6b76f137dbfc (diff) | |
download | libcss-932213b80d817b8646505dfb4af322c9742c12d2.tar.gz libcss-932213b80d817b8646505dfb4af322c9742c12d2.tar.bz2 |
Iterate over the selectors in a stylesheet which match the current node's name.
svn path=/trunk/libcss/; revision=6400
Diffstat (limited to 'src/select/select.c')
-rw-r--r-- | src/select/select.c | 79 |
1 files changed, 76 insertions, 3 deletions
diff --git a/src/select/select.c b/src/select/select.c index ca1a157..40bfc48 100644 --- a/src/select/select.c +++ b/src/select/select.c @@ -7,12 +7,15 @@ #include <string.h> +#include <parserutils/utils/hash.h> + #include <libcss/computed.h> #include <libcss/select.h> #include "stylesheet.h" #include "select/hash.h" #include "select/propset.h" +#include "utils/parserutilserror.h" #include "utils/utils.h" /** @@ -62,6 +65,8 @@ static css_error select_from_sheet(css_select_ctx *ctx, const css_stylesheet *sheet, css_select_state *state); static css_error match_selectors_in_sheet(css_select_ctx *ctx, const css_stylesheet *sheet, css_select_state *state); +static css_error match_selector(css_select_ctx *ctx, + const css_selector *selector, css_select_state *state); /** * Create a selection context @@ -359,12 +364,80 @@ css_error select_from_sheet(css_select_ctx *ctx, const css_stylesheet *sheet, css_error match_selectors_in_sheet(css_select_ctx *ctx, const css_stylesheet *sheet, css_select_state *state) { + const parserutils_hash_entry *universal; + const parserutils_hash_entry *element; + const css_selector **selectors; + const uint8_t *name; + size_t len; + parserutils_error perror; + css_error error; + + /** \todo Get node's name */ +#if 0 + error = ...(state->pw, state->node, &name, &len); + if (error != CSS_OK) + return error; +#else + name = NULL; + len = 0; +#endif + + /* Intern it */ + perror = parserutils_hash_insert(sheet->dictionary, + name, len, &element); + if (perror != PARSERUTILS_OK) + return css_error_from_parserutils_error(perror); + + /* Intern universal selector string */ + perror = parserutils_hash_insert(sheet->dictionary, + (const uint8_t *) "*", 1, &universal); + if (perror != PARSERUTILS_OK) + return css_error_from_parserutils_error(perror); + + /* Find hash chain that applies to current node */ + error = css_selector_hash_find(sheet->selectors, element, &selectors); + if (error != CSS_OK) + return error; + + /* Process any matching selectors */ + while (*selectors != NULL) { + error = match_selector(ctx, *selectors, state); + if (error != CSS_OK) + return error; + + error = css_selector_hash_iterate(sheet->selectors, selectors, + &selectors); + if (error != CSS_OK) + return error; + } + + /* Find hash chain for universal selector */ + error = css_selector_hash_find(sheet->selectors, universal, &selectors); + if (error != CSS_OK) + return error; + + /* Process any matching selectors */ + while (*selectors != NULL) { + error = match_selector(ctx, *selectors, state); + if (error != CSS_OK) + return error; + + error = css_selector_hash_iterate(sheet->selectors, selectors, + &selectors); + if (error != CSS_OK) + return error; + } + + return CSS_OK; +} + +css_error match_selector(css_select_ctx *ctx, const css_selector *selector, + css_select_state *state) +{ UNUSED(ctx); - UNUSED(sheet); + UNUSED(selector); UNUSED(state); - /** \todo Implement */ - return CSS_OK; } |