From f1f3155ef6f28fb8595920e5423336b39bba4ed0 Mon Sep 17 00:00:00 2001 From: Daniel Silverstone Date: Sat, 14 Feb 2009 22:55:32 +0000 Subject: Port libcss to libwapcaplet. It passes the tests, perhaps we need more of them. Lifetimes of lwc_string objects really need attention before we can consider this finished. svn path=/trunk/libcss/; revision=6517 --- include/libcss/computed.h | 52 +++++++++++++++++++++++---------------------- include/libcss/libcss.h | 2 ++ include/libcss/select.h | 36 ++++++++++++------------------- include/libcss/stylesheet.h | 4 ++-- include/libcss/types.h | 8 ------- 5 files changed, 45 insertions(+), 57 deletions(-) (limited to 'include') diff --git a/include/libcss/computed.h b/include/libcss/computed.h index 37e0b41..e8ab3b5 100644 --- a/include/libcss/computed.h +++ b/include/libcss/computed.h @@ -8,6 +8,8 @@ #ifndef libcss_computed_h_ #define libcss_computed_h_ +#include + #include #include #include @@ -29,23 +31,23 @@ enum css_computed_content_type { typedef struct css_computed_content_item { uint8_t type; union { - css_string string; - css_string uri; - css_string attr; + lwc_string *string; + lwc_string *uri; + lwc_string *attr; struct { - css_string name; + lwc_string *name; uint8_t style; } counter; struct { - css_string name; - css_string sep; + lwc_string *name; + lwc_string *sep; uint8_t style; } counters; } data; } css_computed_content_item; typedef struct css_computed_counter { - css_string name; + lwc_string *name; css_fixed value; } css_computed_counter; @@ -137,9 +139,9 @@ typedef struct css_computed_uncommon { css_computed_counter *counter_increment; css_computed_counter *counter_reset; - css_string *quotes; + lwc_string **quotes; - css_string *cursor; + lwc_string **cursor; css_computed_content_item *content; } css_computed_uncommon; @@ -181,7 +183,7 @@ struct css_computed_style { * Dimensions are encoded as a fixed point value + 4 bits of unit data * * background_color 2 4 - * background_image 1 sizeof(css_string) + * background_image 1 sizeof(lwc_string) * background_position 1 + 2(4) 2(4) * border_top_color 2 4 * border_right_color 2 4 @@ -199,7 +201,7 @@ struct css_computed_style { * font_size 4 + 4 4 * height 2 + 4 4 * line_height 2 + 4 4 - * list_style_image 1 sizeof(css_string) + * list_style_image 1 sizeof(lwc_string) * margin_top 2 + 4 4 * margin_right 2 + 4 4 * margin_bottom 2 + 4 4 @@ -217,7 +219,7 @@ struct css_computed_style { * width 2 + 4 4 * z_index 2 4 * --- --- - * 181 bits 140 + 2sizeof(css_string) bytes + * 181 bits 140 + 2sizeof(lwc_string) bytes * * Encode font family as an array of string objects, terminated with a * blank entry. @@ -227,13 +229,13 @@ struct css_computed_style { * 3 bits sizeof(ptr) * * ___ ___ - * 267 bits 140 + 2sizeof(css_string) + + * 267 bits 140 + 2sizeof(lwc_string) + * sizeof(ptr) bytes * - * 34 bytes 140 + 2sizeof(css_string) + + * 34 bytes 140 + 2sizeof(lwc_string) + * sizeof(ptr) bytes * =================== - * 174 + 2sizeof(css_string) + sizeof(ptr) bytes + * 174 + 2sizeof(lwc_string) + sizeof(ptr) bytes * * Bit allocations: * @@ -278,7 +280,7 @@ struct css_computed_style { uint8_t unused[2]; css_color background_color; - css_string background_image; + lwc_string *background_image; css_fixed background_position[2]; css_color border_color[4]; @@ -297,7 +299,7 @@ struct css_computed_style { css_fixed line_height; - css_string list_style_image; + lwc_string *list_style_image; css_fixed margin[4]; @@ -317,7 +319,7 @@ struct css_computed_style { css_fixed z_index; - css_string *font_family; + lwc_string **font_family; css_computed_uncommon *uncommon;/**< Uncommon properties */ void *aural; /**< Aural properties */ @@ -549,7 +551,7 @@ static inline uint8_t css_computed_counter_reset( #define CURSOR_MASK 0xf8 static inline uint8_t css_computed_cursor( const css_computed_style *style, - const css_string **urls) + lwc_string ***urls) { if (style->uncommon != NULL) { uint8_t bits = style->uncommon->bits[CURSOR_INDEX]; @@ -573,7 +575,7 @@ static inline uint8_t css_computed_cursor( #define QUOTES_MASK 0x6 static inline uint8_t css_computed_quotes( const css_computed_style *style, - const css_string **quotes) + lwc_string ***quotes) { if (style->uncommon != NULL) { uint8_t bits = style->uncommon->bits[QUOTES_INDEX]; @@ -834,14 +836,14 @@ static inline uint8_t css_computed_border_left_width( #define BACKGROUND_IMAGE_MASK 0x1 static inline uint8_t css_computed_background_image( const css_computed_style *style, - const css_string **url) + lwc_string **url) { uint8_t bits = style->bits[BACKGROUND_IMAGE_INDEX]; bits &= BACKGROUND_IMAGE_MASK; bits >>= BACKGROUND_IMAGE_SHIFT; /* 1bit: type */ - *url = &style->background_image; + *url = style->background_image; return bits; } @@ -874,14 +876,14 @@ static inline uint8_t css_computed_color( #define LIST_STYLE_IMAGE_MASK 0x1 static inline uint8_t css_computed_list_style_image( const css_computed_style *style, - const css_string **url) + lwc_string **url) { uint8_t bits = style->bits[LIST_STYLE_IMAGE_INDEX]; bits &= LIST_STYLE_IMAGE_MASK; bits >>= LIST_STYLE_IMAGE_SHIFT; /* 1bit: type */ - *url = &style->list_style_image; + *url = style->list_style_image; return bits; } @@ -1805,7 +1807,7 @@ static inline uint8_t css_computed_text_decoration( #define FONT_FAMILY_MASK 0x7 static inline uint8_t css_computed_font_family( const css_computed_style *style, - const css_string **names) + lwc_string ***names) { uint8_t bits = style->bits[FONT_FAMILY_INDEX]; bits &= FONT_FAMILY_MASK; diff --git a/include/libcss/libcss.h b/include/libcss/libcss.h index 84a8be7..de82a22 100644 --- a/include/libcss/libcss.h +++ b/include/libcss/libcss.h @@ -8,6 +8,8 @@ #ifndef libcss_h_ #define libcss_h_ +#include + #include #include #include diff --git a/include/libcss/select.h b/include/libcss/select.h index bb3f1ff..6d774ec 100644 --- a/include/libcss/select.h +++ b/include/libcss/select.h @@ -8,6 +8,8 @@ #ifndef libcss_select_h_ #define libcss_select_h_ +#include + #include #include #include @@ -21,42 +23,33 @@ enum css_pseudo_element { }; typedef struct css_select_handler { - css_error (*node_name)(void *pw, void *node, const uint8_t **name, - size_t *len); + css_error (*node_name)(void *pw, void *node, + lwc_context *dict, lwc_string **name); css_error (*named_ancestor_node)(void *pw, void *node, - const uint8_t *name, size_t len, - void **ancestor); + lwc_string *name, void **ancestor); css_error (*named_parent_node)(void *pw, void *node, - const uint8_t *name, size_t len, - void **parent); + lwc_string *name, void **parent); css_error (*named_sibling_node)(void *pw, void *node, - const uint8_t *name, size_t len, - void **sibling); + lwc_string *name, void **sibling); css_error (*parent_node)(void *pw, void *node, void **parent); css_error (*sibling_node)(void *pw, void *node, void **sibling); css_error (*node_has_class)(void *pw, void *node, - const uint8_t *name, size_t len, - bool *match); + lwc_string *name, bool *match); css_error (*node_has_id)(void *pw, void *node, - const uint8_t *name, size_t len, - bool *match); + lwc_string *name, bool *match); css_error (*node_has_attribute)(void *pw, void *node, - const uint8_t *name, size_t len, - bool *match); + lwc_string *name, bool *match); css_error (*node_has_attribute_equal)(void *pw, void *node, - const uint8_t *name, size_t nlen, - const uint8_t *value, size_t vlen, + lwc_string *name, lwc_string *value, bool *match); css_error (*node_has_attribute_dashmatch)(void *pw, void *node, - const uint8_t *name, size_t nlen, - const uint8_t *value, size_t vlen, + lwc_string *name, lwc_string *value, bool *match); css_error (*node_has_attribute_includes)(void *pw, void *node, - const uint8_t *name, size_t nlen, - const uint8_t *value, size_t vlen, + lwc_string *name, lwc_string *value, bool *match); css_error (*node_is_first_child)(void *pw, void *node, bool *match); @@ -66,8 +59,7 @@ typedef struct css_select_handler { css_error (*node_is_active)(void *pw, void *node, bool *match); css_error (*node_is_focus)(void *pw, void *node, bool *match); css_error (*node_is_lang)(void *pw, void *node, - const uint8_t *lang, size_t len, - bool *match); + lwc_string *lang, bool *match); } css_select_handler; css_error css_select_ctx_create(css_allocator_fn alloc, void *pw, diff --git a/include/libcss/stylesheet.h b/include/libcss/stylesheet.h index eb14ad3..dd4bc81 100644 --- a/include/libcss/stylesheet.h +++ b/include/libcss/stylesheet.h @@ -13,7 +13,7 @@ css_error css_stylesheet_create(css_language_level level, const char *charset, const char *url, const char *title, - css_origin origin, uint64_t media, + css_origin origin, uint64_t media, lwc_context *dict, css_allocator_fn alloc, void *alloc_pw, css_stylesheet **stylesheet); css_error css_stylesheet_destroy(css_stylesheet *sheet); @@ -23,7 +23,7 @@ css_error css_stylesheet_append_data(css_stylesheet *sheet, css_error css_stylesheet_data_done(css_stylesheet *sheet); css_error css_stylesheet_next_pending_import(css_stylesheet *parent, - css_string *url, uint64_t *media); + lwc_string **url, uint64_t *media); css_error css_stylesheet_register_import(css_stylesheet *parent, css_stylesheet *child); diff --git a/include/libcss/types.h b/include/libcss/types.h index 95c28b4..a08ffb4 100644 --- a/include/libcss/types.h +++ b/include/libcss/types.h @@ -68,14 +68,6 @@ typedef enum css_origin { CSS_ORIGIN_AUTHOR = 2 /**< Author stylesheet */ } css_origin; -/** - * String type - */ -typedef struct css_string { - size_t len; - uint8_t *data; -} css_string; - /** CSS colour -- RRGGBBAA */ typedef uint32_t css_color; -- cgit v1.2.3