diff options
Diffstat (limited to 'src/select')
-rw-r--r-- | src/select/hash.c | 6 | ||||
-rw-r--r-- | src/select/hash.h | 4 | ||||
-rw-r--r-- | src/select/properties.c | 138 | ||||
-rw-r--r-- | src/select/propset.h | 22 | ||||
-rw-r--r-- | src/select/select.c | 228 |
5 files changed, 200 insertions, 198 deletions
diff --git a/src/select/hash.c b/src/select/hash.c index 2a30a5f..f471861 100644 --- a/src/select/hash.c +++ b/src/select/hash.c @@ -29,7 +29,7 @@ struct css_selector_hash { static hash_entry empty_slot; static inline uint32_t _hash(const css_selector *sel); -static inline uint32_t _hash_name(const parserutils_hash_entry *name); +static inline uint32_t _hash_name(lwc_string *name); /** * Create a hash @@ -225,7 +225,7 @@ css_error css_selector_hash_remove(css_selector_hash *hash, * If nothing matches, CSS_OK will be returned and **matched == NULL */ css_error css_selector_hash_find(css_selector_hash *hash, - const parserutils_hash_entry *name, + lwc_string *name, const css_selector ***matched) { uint32_t index, mask; @@ -310,7 +310,7 @@ uint32_t _hash(const css_selector *sel) * \param name Name to hash * \return hash value */ -uint32_t _hash_name(const parserutils_hash_entry *name) +uint32_t _hash_name(lwc_string *name) { return (uint32_t) (((uintptr_t) name) & 0xffffffff); } diff --git a/src/select/hash.h b/src/select/hash.h index 2f388b7..b116021 100644 --- a/src/select/hash.h +++ b/src/select/hash.h @@ -8,7 +8,7 @@ #ifndef css_select_hash_h_ #define css_select_hash_h_ -#include <parserutils/utils/hash.h> +#include <libwapcaplet/libwapcaplet.h> #include <libcss/errors.h> #include <libcss/functypes.h> @@ -28,7 +28,7 @@ css_error css_selector_hash_remove(css_selector_hash *hash, const struct css_selector *selector); css_error css_selector_hash_find(css_selector_hash *hash, - const parserutils_hash_entry *name, + lwc_string *name, const struct css_selector ***matched); css_error css_selector_hash_iterate(css_selector_hash *hash, const struct css_selector **current, diff --git a/src/select/properties.c b/src/select/properties.c index 7ac0e36..710e3fc 100644 --- a/src/select/properties.c +++ b/src/select/properties.c @@ -11,7 +11,7 @@ static css_error cascade_bg_border_color(uint32_t opv, css_style *style, static css_error cascade_uri_none(uint32_t opv, css_style *style, css_select_state *state, css_error (*fun)(css_computed_style *, uint8_t, - const parserutils_hash_entry *)); + lwc_string *)); static css_error cascade_border_style(uint32_t opv, css_style *style, css_select_state *state, css_error (*fun)(css_computed_style *, uint8_t)); @@ -641,13 +641,12 @@ static css_error cascade_content(uint32_t opv, css_style *style, value = CSS_CONTENT_NONE; } else { value = CSS_CONTENT_SET; - - while (v != CONTENT_NORMAL) { - css_computed_content_item *temp; - parserutils_hash_entry *he = - *((parserutils_hash_entry **) style->bytecode); - - temp = state->result->alloc(content, + + while (v != CONTENT_NORMAL) { + lwc_string *he = *((lwc_string **) style->bytecode); + css_computed_content_item *temp; + + temp = state->result->alloc(content, (n_contents + 1) * sizeof(css_computed_content_item), state->result->pw); @@ -667,26 +666,23 @@ static css_error cascade_content(uint32_t opv, css_style *style, content[n_contents].type = CSS_COMPUTED_CONTENT_COUNTER; - content[n_contents].data.counter.name.data = (uint8_t *) he->data; - content[n_contents].data.counter.name.len = he->len; + content[n_contents].data.counter.name = he; content[n_contents].data.counter.style = v >> CONTENT_COUNTER_STYLE_SHIFT; break; case CONTENT_COUNTERS: { - parserutils_hash_entry *sep; + lwc_string *sep; advance_bytecode(style, sizeof(he)); - sep = *((parserutils_hash_entry **) + sep = *((lwc_string **) style->bytecode); advance_bytecode(style, sizeof(sep)); content[n_contents].type = CSS_COMPUTED_CONTENT_COUNTERS; - content[n_contents].data.counters.name.data = (uint8_t *) he->data; - content[n_contents].data.counters.name.len = he->len; - content[n_contents].data.counters.sep.data = (uint8_t *) sep->data; - content[n_contents].data.counters.sep.len = sep->len; + content[n_contents].data.counters.name = he; + content[n_contents].data.counters.sep = sep; content[n_contents].data.counters.style = v >> CONTENT_COUNTERS_STYLE_SHIFT; } break; @@ -695,24 +691,21 @@ static css_error cascade_content(uint32_t opv, css_style *style, content[n_contents].type = CSS_COMPUTED_CONTENT_URI; - content[n_contents].data.uri.data = (uint8_t *) he->data; - content[n_contents].data.uri.len = he->len; + content[n_contents].data.uri = he; break; case CONTENT_ATTR: advance_bytecode(style, sizeof(he)); content[n_contents].type = CSS_COMPUTED_CONTENT_ATTR; - content[n_contents].data.attr.data = (uint8_t *) he->data; - content[n_contents].data.attr.len = he->len; + content[n_contents].data.attr = he; break; case CONTENT_STRING: advance_bytecode(style, sizeof(he)); content[n_contents].type = CSS_COMPUTED_CONTENT_STRING; - content[n_contents].data.string.data = (uint8_t *) he->data; - content[n_contents].data.string.len = he->len; + content[n_contents].data.string = he; break; case CONTENT_OPEN_QUOTE: content[n_contents].type = @@ -829,21 +822,21 @@ static css_error cascade_cursor(uint32_t opv, css_style *style, css_select_state *state) { uint16_t value = CSS_CURSOR_INHERIT; - css_string *uris = NULL; + lwc_string **uris = NULL; uint32_t n_uris = 0; if (isInherit(opv) == false) { uint32_t v = getValue(opv); while (v == CURSOR_URI) { - parserutils_hash_entry *uri; - css_string *temp; + lwc_string *uri; + lwc_string **temp; - uri = *((parserutils_hash_entry **) style->bytecode); + uri = *((lwc_string **) style->bytecode); advance_bytecode(style, sizeof(uri)); temp = state->result->alloc(uris, - (n_uris + 1) * sizeof(css_string), + (n_uris + 1) * sizeof(lwc_string *), state->result->pw); if (temp == NULL) { if (uris != NULL) { @@ -855,8 +848,7 @@ static css_error cascade_cursor(uint32_t opv, css_style *style, uris = temp; - uris[n_uris].data = (uint8_t *) uri->data; - uris[n_uris].len = uri->len; + uris[n_uris] = uri; n_uris++; @@ -921,10 +913,10 @@ static css_error cascade_cursor(uint32_t opv, css_style *style, /* Terminate array with blank entry, if needed */ if (n_uris > 0) { - css_string *temp; + lwc_string **temp; temp = state->result->alloc(uris, - (n_uris + 1) * sizeof(css_string), + (n_uris + 1) * sizeof(lwc_string *), state->result->pw); if (temp == NULL) { state->result->alloc(uris, 0, state->result->pw); @@ -933,8 +925,7 @@ static css_error cascade_cursor(uint32_t opv, css_style *style, uris = temp; - uris[n_uris].data = NULL; - uris[n_uris].len = 0; + uris[n_uris] = NULL; } if (outranks_existing(getOpcode(opv), isImportant(opv), state)) { @@ -1163,20 +1154,20 @@ static css_error cascade_font_family(uint32_t opv, css_style *style, css_select_state *state) { uint16_t value = CSS_FONT_FAMILY_INHERIT; - css_string *fonts = NULL; + lwc_string **fonts = NULL; uint32_t n_fonts = 0; if (isInherit(opv) == false) { uint32_t v = getValue(opv); while (v != FONT_FAMILY_END) { - const parserutils_hash_entry *font = NULL; - css_string *temp; + lwc_string *font = NULL; + lwc_string **temp; switch (v) { case FONT_FAMILY_STRING: case FONT_FAMILY_IDENT_LIST: - font = *((parserutils_hash_entry **) + font = *((lwc_string **) style->bytecode); advance_bytecode(style, sizeof(font)); break; @@ -1208,7 +1199,7 @@ static css_error cascade_font_family(uint32_t opv, css_style *style, /** \todo Do this at bytecode generation time? */ if (value == CSS_FONT_FAMILY_INHERIT && font != NULL) { temp = state->result->alloc(fonts, - (n_fonts + 1) * sizeof(css_string), + (n_fonts + 1) * sizeof(lwc_string *), state->result->pw); if (temp == NULL) { if (fonts != NULL) { @@ -1220,8 +1211,7 @@ static css_error cascade_font_family(uint32_t opv, css_style *style, fonts = temp; - fonts[n_fonts].data = (uint8_t *) font->data; - fonts[n_fonts].len = font->len; + fonts[n_fonts] = font; n_fonts++; } @@ -1233,10 +1223,10 @@ static css_error cascade_font_family(uint32_t opv, css_style *style, /* Terminate array with blank entry, if needed */ if (n_fonts > 0) { - css_string *temp; + lwc_string **temp; temp = state->result->alloc(fonts, - (n_fonts + 1) * sizeof(css_string), + (n_fonts + 1) * sizeof(lwc_string *), state->result->pw); if (temp == NULL) { state->result->alloc(fonts, 0, state->result->pw); @@ -1245,8 +1235,7 @@ static css_error cascade_font_family(uint32_t opv, css_style *style, fonts = temp; - fonts[n_fonts].data = NULL; - fonts[n_fonts].len = 0; + fonts[n_fonts] = NULL; } if (outranks_existing(getOpcode(opv), isImportant(opv), state)) { @@ -2015,14 +2004,14 @@ static css_error cascade_play_during(uint32_t opv, css_style *style, css_select_state *state) { uint16_t value = 0; - parserutils_hash_entry *uri = NULL; + lwc_string *uri = NULL; if (isInherit(opv) == false) { switch (getValue(opv)) { case PLAY_DURING_URI: value = 0; - uri = *((parserutils_hash_entry **) style->bytecode); + uri = *((lwc_string **) style->bytecode); advance_bytecode(style, sizeof(uri)); break; case PLAY_DURING_AUTO: @@ -2088,7 +2077,7 @@ static css_error cascade_quotes(uint32_t opv, css_style *style, css_select_state *state) { uint16_t value = CSS_QUOTES_INHERIT; - css_string *quotes = NULL; + lwc_string **quotes = NULL; uint32_t n_quotes = 0; if (isInherit(opv) == false) { @@ -2097,14 +2086,14 @@ static css_error cascade_quotes(uint32_t opv, css_style *style, value = CSS_QUOTES_STRING; while (v != QUOTES_NONE) { - parserutils_hash_entry *quote; - css_string *temp; + lwc_string *quote; + lwc_string **temp; - quote = *((parserutils_hash_entry **) style->bytecode); + quote = *((lwc_string **) style->bytecode); advance_bytecode(style, sizeof(quote)); temp = state->result->alloc(quotes, - (n_quotes + 1) * sizeof(css_string), + (n_quotes + 1) * sizeof(lwc_string *), state->result->pw); if (temp == NULL) { if (quotes != NULL) { @@ -2116,8 +2105,7 @@ static css_error cascade_quotes(uint32_t opv, css_style *style, quotes = temp; - quotes[n_quotes].data = (uint8_t *) quote->data; - quotes[n_quotes].len = quote->len; + quotes[n_quotes] = quote; n_quotes++; @@ -2128,10 +2116,10 @@ static css_error cascade_quotes(uint32_t opv, css_style *style, /* Terminate array, if required */ if (n_quotes > 0) { - css_string *temp; + lwc_string **temp; temp = state->result->alloc(quotes, - (n_quotes + 1) * sizeof(css_string), + (n_quotes + 1) * sizeof(lwc_string *), state->result->pw); if (temp == NULL) { state->result->alloc(quotes, 0, state->result->pw); @@ -2140,8 +2128,7 @@ static css_error cascade_quotes(uint32_t opv, css_style *style, quotes = temp; - quotes[n_quotes].data = NULL; - quotes[n_quotes].len = 0; + quotes[n_quotes] = NULL; } if (outranks_existing(getOpcode(opv), isImportant(opv), state)) { @@ -2650,20 +2637,20 @@ static css_error cascade_voice_family(uint32_t opv, css_style *style, css_select_state *state) { uint16_t value = 0; - css_string *voices = NULL; + lwc_string **voices = NULL; uint32_t n_voices = 0; if (isInherit(opv) == false) { uint32_t v = getValue(opv); while (v != VOICE_FAMILY_END) { - const parserutils_hash_entry *voice = NULL; - css_string *temp; + lwc_string *voice = NULL; + lwc_string **temp; switch (v) { case VOICE_FAMILY_STRING: case VOICE_FAMILY_IDENT_LIST: - voice = *((parserutils_hash_entry **) + voice = *((lwc_string **) style->bytecode); advance_bytecode(style, sizeof(voice)); break; @@ -2687,7 +2674,7 @@ static css_error cascade_voice_family(uint32_t opv, css_style *style, /** \todo Do this at bytecode generation time? */ if (value == 0 && voice != NULL) { temp = state->result->alloc(voices, - (n_voices + 1) * sizeof(css_string), + (n_voices + 1) * sizeof(lwc_string *), state->result->pw); if (temp == NULL) { if (voices != NULL) { @@ -2699,8 +2686,7 @@ static css_error cascade_voice_family(uint32_t opv, css_style *style, voices = temp; - voices[n_voices].data = (uint8_t *) voice->data; - voices[n_voices].len = voice->len; + voices[n_voices] = voice; n_voices++; } @@ -2712,10 +2698,10 @@ static css_error cascade_voice_family(uint32_t opv, css_style *style, /* Terminate array with blank entry, if needed */ if (n_voices > 0) { - css_string *temp; + lwc_string **temp; temp = state->result->alloc(voices, - (n_voices + 1) * sizeof(css_string), + (n_voices + 1) * sizeof(lwc_string *), state->result->pw); if (temp == NULL) { state->result->alloc(voices, 0, state->result->pw); @@ -2724,8 +2710,7 @@ static css_error cascade_voice_family(uint32_t opv, css_style *style, voices = temp; - voices[n_voices].data = NULL; - voices[n_voices].len = 0; + voices[n_voices] = NULL; } if (outranks_existing(getOpcode(opv), isImportant(opv), state)) { @@ -2940,10 +2925,10 @@ css_error cascade_bg_border_color(uint32_t opv, css_style *style, css_error cascade_uri_none(uint32_t opv, css_style *style, css_select_state *state, css_error (*fun)(css_computed_style *, uint8_t, - const parserutils_hash_entry *)) + lwc_string *)) { uint16_t value = CSS_BACKGROUND_IMAGE_INHERIT; - parserutils_hash_entry *uri = NULL; + lwc_string *uri = NULL; if (isInherit(opv) == false) { switch (getValue(opv)) { @@ -2952,7 +2937,7 @@ css_error cascade_uri_none(uint32_t opv, css_style *style, break; case BACKGROUND_IMAGE_URI: value = CSS_BACKGROUND_IMAGE_IMAGE; - uri = *((parserutils_hash_entry **) style->bytecode); + uri = *((lwc_string **) style->bytecode); advance_bytecode(style, sizeof(uri)); break; } @@ -3243,10 +3228,10 @@ css_error cascade_counter_increment_reset(uint32_t opv, css_style *style, while (v != COUNTER_INCREMENT_NONE) { css_computed_counter *temp; - parserutils_hash_entry *name; + lwc_string *name; css_fixed val = 0; - name = *((parserutils_hash_entry **) + name = *((lwc_string **) style->bytecode); advance_bytecode(style, sizeof(name)); @@ -3267,9 +3252,7 @@ css_error cascade_counter_increment_reset(uint32_t opv, css_style *style, counters = temp; - counters[n_counters].name.data = - (uint8_t *) name->data; - counters[n_counters].name.len = name->len; + counters[n_counters].name = name; counters[n_counters].value = val; n_counters++; @@ -3299,8 +3282,7 @@ css_error cascade_counter_increment_reset(uint32_t opv, css_style *style, counters = temp; - counters[n_counters].name.data = NULL; - counters[n_counters].name.len = 0; + counters[n_counters].name = NULL; counters[n_counters].value = 0; } diff --git a/src/select/propset.h b/src/select/propset.h index 64f7829..730822a 100644 --- a/src/select/propset.h +++ b/src/select/propset.h @@ -219,7 +219,7 @@ static inline css_error set_counter_reset( #define CURSOR_MASK 0xf8 static inline css_error set_cursor( css_computed_style *style, uint8_t type, - css_string *urls) + lwc_string **urls) { uint8_t *bits; @@ -244,7 +244,7 @@ static inline css_error set_cursor( #define QUOTES_MASK 0x6 static inline css_error set_quotes( css_computed_style *style, uint8_t type, - css_string *quotes) + lwc_string **quotes) { uint8_t *bits; @@ -480,7 +480,7 @@ static inline css_error set_border_left_width( #define BACKGROUND_IMAGE_MASK 0x1 static inline css_error set_background_image( css_computed_style *style, uint8_t type, - const parserutils_hash_entry *url) + lwc_string *url) { uint8_t *bits = &style->bits[BACKGROUND_IMAGE_INDEX]; @@ -489,11 +489,9 @@ static inline css_error set_background_image( ((type & 0x1) << BACKGROUND_IMAGE_SHIFT); if (url != NULL) { - style->background_image.data = (uint8_t *) url->data; - style->background_image.len = url->len; + style->background_image = url; } else { - style->background_image.data = NULL; - style->background_image.len = 0; + style->background_image = NULL; } return CSS_OK; @@ -528,7 +526,7 @@ static inline css_error set_color( #define LIST_STYLE_IMAGE_MASK 0x1 static inline css_error set_list_style_image( css_computed_style *style, uint8_t type, - const parserutils_hash_entry *url) + lwc_string *url) { uint8_t *bits = &style->bits[LIST_STYLE_IMAGE_INDEX]; @@ -537,11 +535,9 @@ static inline css_error set_list_style_image( ((type & 0x1) << LIST_STYLE_IMAGE_SHIFT); if (url != NULL) { - style->list_style_image.data = (uint8_t *) url->data; - style->list_style_image.len = url->len; + style->list_style_image = url; } else { - style->list_style_image.data = NULL; - style->list_style_image.len = 0; + style->list_style_image = NULL; } return CSS_OK; @@ -1444,7 +1440,7 @@ static inline css_error set_text_decoration( #define FONT_FAMILY_MASK 0x7 static inline css_error set_font_family( css_computed_style *style, uint8_t type, - css_string *names) + lwc_string **names) { uint8_t *bits = &style->bits[FONT_FAMILY_INDEX]; diff --git a/src/select/select.c b/src/select/select.c index f48db9a..0c31ae4 100644 --- a/src/select/select.c +++ b/src/select/select.c @@ -8,8 +8,6 @@ #include <assert.h> #include <string.h> -#include <parserutils/utils/hash.h> - #include <libcss/computed.h> #include <libcss/select.h> @@ -58,17 +56,17 @@ typedef struct css_select_state { uint32_t current_specificity; /* Specificity of current rule */ /* Useful interned strings */ - const parserutils_hash_entry *universal; - const parserutils_hash_entry *first_child; - const parserutils_hash_entry *link; - const parserutils_hash_entry *visited; - const parserutils_hash_entry *hover; - const parserutils_hash_entry *active; - const parserutils_hash_entry *focus; - const parserutils_hash_entry *first_line; - const parserutils_hash_entry *first_letter; - const parserutils_hash_entry *before; - const parserutils_hash_entry *after; + lwc_string *universal; + lwc_string *first_child; + lwc_string *link; + lwc_string *visited; + lwc_string *hover; + lwc_string *active; + lwc_string *focus; + lwc_string *first_line; + lwc_string *first_letter; + lwc_string *before; + lwc_string *after; prop_state props[N_OPCODES]; } css_select_state; @@ -82,7 +80,7 @@ static css_error match_selectors_in_sheet(css_select_ctx *ctx, static css_error match_selector_chain(css_select_ctx *ctx, const css_selector *selector, css_select_state *state); static css_error match_named_combinator(css_select_ctx *ctx, - css_combinator type, const parserutils_hash_entry *name, + css_combinator type, lwc_string *name, css_select_state *state, void *node, void **next_node); static css_error match_universal_combinator(css_select_ctx *ctx, css_combinator type, const css_selector *selector, @@ -449,7 +447,7 @@ css_error css_select_style(css_select_ctx *ctx, void *node, if ((ctx->sheets[i]->media & media) != 0) { error = select_from_sheet(ctx, ctx->sheets[i], &state); if (error != CSS_OK) - return error; + goto cleanup; } } @@ -478,26 +476,63 @@ css_error css_select_style(css_select_ctx *ctx, void *node, if (properties[i].group == GROUP_NORMAL) { error = properties[i].initial(result); if (error != CSS_OK) - return error; + goto cleanup; } else if (properties[i].group == GROUP_UNCOMMON && result->uncommon != NULL) { error = properties[i].initial(result); if (error != CSS_OK) - return error; + goto cleanup; } else if (properties[i].group == GROUP_PAGE && result->page != NULL) { error = properties[i].initial(result); if (error != CSS_OK) - return error; + goto cleanup; } else if (properties[i].group == GROUP_AURAL && result->aural != NULL) { error = properties[i].initial(result); if (error != CSS_OK) - return error; + goto cleanup; } } - return CSS_OK; + error = CSS_OK; +cleanup: + if (ctx->sheets[0] != NULL) { + if (state.universal != NULL) + lwc_context_string_unref(ctx->sheets[0]->dictionary, + state.universal); + if (state.first_child != NULL) + lwc_context_string_unref(ctx->sheets[0]->dictionary, + state.first_child); + if (state.link != NULL) + lwc_context_string_unref(ctx->sheets[0]->dictionary, + state.link); + if (state.visited != NULL) + lwc_context_string_unref(ctx->sheets[0]->dictionary, + state.visited); + if (state.hover != NULL) + lwc_context_string_unref(ctx->sheets[0]->dictionary, + state.hover); + if (state.active != NULL) + lwc_context_string_unref(ctx->sheets[0]->dictionary, + state.active); + if (state.focus != NULL) + lwc_context_string_unref(ctx->sheets[0]->dictionary, + state.focus); + if (state.first_line != NULL) + lwc_context_string_unref(ctx->sheets[0]->dictionary, + state.first_line); + if (state.first_letter != NULL) + lwc_context_string_unref(ctx->sheets[0]->dictionary, + state.first_letter); + if (state.before != NULL) + lwc_context_string_unref(ctx->sheets[0]->dictionary, + state.before); + if (state.after != NULL) + lwc_context_string_unref(ctx->sheets[0]->dictionary, + state.after); + } + return error; } /****************************************************************************** @@ -566,77 +601,80 @@ css_error select_from_sheet(css_select_ctx *ctx, const css_stylesheet *sheet, css_error intern_strings_for_sheet(css_select_ctx *ctx, const css_stylesheet *sheet, css_select_state *state) { - parserutils_error perror; + lwc_error error; UNUSED(ctx); /* Universal selector */ - perror = parserutils_hash_insert(sheet->dictionary, - (const uint8_t *) "*", SLEN("*"), &state->universal); - if (perror != PARSERUTILS_OK) - return css_error_from_parserutils_error(perror); + if (state->universal != NULL) + return CSS_OK; + + error = lwc_context_intern(sheet->dictionary, + "*", SLEN("*"), &state->universal); + if (error != lwc_error_ok) + return css_error_from_lwc_error(error); /* Pseudo classes */ - perror = parserutils_hash_insert(sheet->dictionary, - (const uint8_t *) "first-child", SLEN("first-child"), + error = lwc_context_intern(sheet->dictionary, + "first-child", SLEN("first-child"), &state->first_child); - if (perror != PARSERUTILS_OK) - return css_error_from_parserutils_error(perror); + if (error != lwc_error_ok) + return css_error_from_lwc_error(error); - perror = parserutils_hash_insert(sheet->dictionary, - (const uint8_t *) "link", SLEN("link"), + error = lwc_context_intern(sheet->dictionary, + "link", SLEN("link"), &state->link); - if (perror != PARSERUTILS_OK) - return css_error_from_parserutils_error(perror); + if (error != lwc_error_ok) + return css_error_from_lwc_error(error); - perror = parserutils_hash_insert(sheet->dictionary, - (const uint8_t *) "visited", SLEN("visited"), + error = lwc_context_intern(sheet->dictionary, + "visited", SLEN("visited"), &state->visited); - if (perror != PARSERUTILS_OK) - return css_error_from_parserutils_error(perror); + if (error != lwc_error_ok) + return css_error_from_lwc_error(error); - perror = parserutils_hash_insert(sheet->dictionary, - (const uint8_t *) "hover", SLEN("hover"), + error = lwc_context_intern(sheet->dictionary, + "hover", SLEN("hover"), &state->hover); - if (perror != PARSERUTILS_OK) - return css_error_from_parserutils_error(perror); + if (error != lwc_error_ok) + return css_error_from_lwc_error(error); - perror = parserutils_hash_insert(sheet->dictionary, - (const uint8_t *) "active", SLEN("active"), + error = lwc_context_intern(sheet->dictionary, + "active", SLEN("active"), &state->active); - if (perror != PARSERUTILS_OK) - return css_error_from_parserutils_error(perror); + if (error != lwc_error_ok) + return css_error_from_lwc_error(error); - perror = parserutils_hash_insert(sheet->dictionary, - (const uint8_t *) "focus", SLEN("focus"), + error = lwc_context_intern(sheet->dictionary, + "focus", SLEN("focus"), &state->focus); - if (perror != PARSERUTILS_OK) - return css_error_from_parserutils_error(perror); + if (error != lwc_error_ok) + return css_error_from_lwc_error(error); /* Pseudo elements */ - perror = parserutils_hash_insert(sheet->dictionary, - (const uint8_t *) "first-line", SLEN("first-line"), + error = lwc_context_intern(sheet->dictionary, + "first-line", SLEN("first-line"), &state->first_line); - if (perror != PARSERUTILS_OK) - return css_error_from_parserutils_error(perror); + if (error != lwc_error_ok) + return css_error_from_lwc_error(error); - perror = parserutils_hash_insert(sheet->dictionary, - (const uint8_t *) "first_letter", SLEN("first-letter"), + error = lwc_context_intern(sheet->dictionary, + "first_letter", SLEN("first-letter"), &state->first_letter); - if (perror != PARSERUTILS_OK) - return css_error_from_parserutils_error(perror); + if (error != lwc_error_ok) + return css_error_from_lwc_error(error); - perror = parserutils_hash_insert(sheet->dictionary, - (const uint8_t *) "before", SLEN("before"), + error = lwc_context_intern(sheet->dictionary, + "before", SLEN("before"), &state->before); - if (perror != PARSERUTILS_OK) - return css_error_from_parserutils_error(perror); + if (error != lwc_error_ok) + return css_error_from_lwc_error(error); - perror = parserutils_hash_insert(sheet->dictionary, - (const uint8_t *) "after", SLEN("after"), + error = lwc_context_intern(sheet->dictionary, + "after", SLEN("after"), &state->after); - if (perror != PARSERUTILS_OK) - return css_error_from_parserutils_error(perror); + if (error != lwc_error_ok) + return css_error_from_lwc_error(error); return CSS_OK; } @@ -644,60 +682,55 @@ css_error intern_strings_for_sheet(css_select_ctx *ctx, css_error match_selectors_in_sheet(css_select_ctx *ctx, const css_stylesheet *sheet, css_select_state *state) { - const parserutils_hash_entry *element; + lwc_string *element; const css_selector **selectors; - const uint8_t *name; - size_t len; - parserutils_error perror; css_error error; /* Get node's name */ - error = state->handler->node_name(state->pw, state->node, &name, &len); + error = state->handler->node_name(state->pw, state->node, sheet->dictionary, &element); if (error != CSS_OK) return error; - /* Intern it */ - perror = parserutils_hash_insert(sheet->dictionary, - name, len, &element); - 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; + goto cleanup; /* Process any matching selectors */ while (*selectors != NULL) { error = match_selector_chain(ctx, *selectors, state); if (error != CSS_OK) - return error; + goto cleanup; error = css_selector_hash_iterate(sheet->selectors, selectors, &selectors); if (error != CSS_OK) - return error; + goto cleanup; } /* Find hash chain for universal selector */ error = css_selector_hash_find(sheet->selectors, state->universal, &selectors); if (error != CSS_OK) - return error; + goto cleanup; /* Process any matching selectors */ while (*selectors != NULL) { error = match_selector_chain(ctx, *selectors, state); if (error != CSS_OK) - return error; + goto cleanup; error = css_selector_hash_iterate(sheet->selectors, selectors, &selectors); if (error != CSS_OK) - return error; + goto cleanup; } - return CSS_OK; + + error = CSS_OK; +cleanup: + lwc_context_string_unref(sheet->dictionary, element); + return error; } css_error match_selector_chain(css_select_ctx *ctx, @@ -761,7 +794,7 @@ css_error match_selector_chain(css_select_ctx *ctx, } css_error match_named_combinator(css_select_ctx *ctx, css_combinator type, - const parserutils_hash_entry *name, css_select_state *state, + lwc_string *name, css_select_state *state, void *node, void **next_node) { css_error error; @@ -771,19 +804,19 @@ css_error match_named_combinator(css_select_ctx *ctx, css_combinator type, switch (type) { case CSS_COMBINATOR_ANCESTOR: error = state->handler->named_ancestor_node(state->pw, node, - name->data, name->len, next_node); + name, next_node); if (error != CSS_OK) return error; break; case CSS_COMBINATOR_PARENT: error = state->handler->named_parent_node(state->pw, node, - name->data, name->len, next_node); + name, next_node); if (error != CSS_OK) return error; break; case CSS_COMBINATOR_SIBLING: error = state->handler->named_sibling_node(state->pw, node, - name->data, name->len, next_node); + name, next_node); if (error != CSS_OK) return error; break; @@ -890,13 +923,11 @@ css_error match_detail(css_select_ctx *ctx, void *node, switch (detail->type) { case CSS_SELECTOR_CLASS: error = state->handler->node_has_class(state->pw, node, - detail->name->data, detail->name->len, - match); + detail->name, match); break; case CSS_SELECTOR_ID: error = state->handler->node_has_id(state->pw, node, - detail->name->data, detail->name->len, - match); + detail->name, match); break; case CSS_SELECTOR_PSEUDO_CLASS: if (detail->name == state->first_child) { @@ -942,26 +973,19 @@ css_error match_detail(css_select_ctx *ctx, void *node, break; case CSS_SELECTOR_ATTRIBUTE: error = state->handler->node_has_attribute(state->pw, node, - detail->name->data, detail->name->len, - match); + detail->name, match); break; case CSS_SELECTOR_ATTRIBUTE_EQUAL: error = state->handler->node_has_attribute_equal(state->pw, - node, detail->name->data, detail->name->len, - detail->value->data, detail->value->len, - match); + node, detail->name, detail->value, match); break; case CSS_SELECTOR_ATTRIBUTE_DASHMATCH: error = state->handler->node_has_attribute_dashmatch(state->pw, - node, detail->name->data, detail->name->len, - detail->value->data, detail->value->len, - match); + node, detail->name, detail->value, match); break; case CSS_SELECTOR_ATTRIBUTE_INCLUDES: error = state->handler->node_has_attribute_includes(state->pw, - node, detail->name->data, detail->name->len, - detail->value->data, detail->value->len, - match); + node, detail->name, detail->value, match); break; } |