diff options
Diffstat (limited to 'src/select')
160 files changed, 13190 insertions, 6667 deletions
diff --git a/src/select/.gitignore b/src/select/.gitignore new file mode 100644 index 0000000..3901713 --- /dev/null +++ b/src/select/.gitignore @@ -0,0 +1,3 @@ +__pycache__ +*.pyc + diff --git a/src/select/Makefile b/src/select/Makefile index e937191..e237d46 100644 --- a/src/select/Makefile +++ b/src/select/Makefile @@ -1,4 +1,8 @@ # Sources -DIR_SOURCES := arena.c computed.c dispatch.c hash.c select.c font_face.c +.PHONY: select_generator +select_generator: + python3 src/select/select_generator.py + +DIR_SOURCES := arena.c computed.c dispatch.c hash.c select.c strings.c font_face.c format_list_style.c unit.c include $(NSBUILD)/Makefile.subdir diff --git a/src/select/arena.c b/src/select/arena.c index baadc9f..c2e22f6 100644 --- a/src/select/arena.c +++ b/src/select/arena.c @@ -15,37 +15,15 @@ #define TU_SIZE 3037 #define TS_SIZE 5101 -struct css_computed_uncommon *table_u[TU_SIZE]; struct css_computed_style *table_s[TS_SIZE]; -static inline uint32_t css__arena_hash_uncommon(struct css_computed_uncommon *u) -{ - return css__arena_hash((const uint8_t *) &u->i, sizeof(u->i)); -} - - static inline uint32_t css__arena_hash_style(struct css_computed_style *s) { return css__arena_hash((const uint8_t *) &s->i, sizeof(s->i)); } -static inline bool arena__compare_computed_page( - const struct css_computed_page *a, - const struct css_computed_page *b) -{ - if (a == NULL && b == NULL) { - return true; - - } else if (a == NULL || b == NULL) { - return false; - } - - return memcmp(a, b, sizeof(struct css_computed_page)) == 0; -} - - static inline bool arena__compare_computed_content_item( const struct css_computed_content_item *a, const struct css_computed_content_item *b) @@ -119,11 +97,17 @@ static inline bool arena__compare_string_list( } -static inline bool css__arena_uncommon_is_equal( - struct css_computed_uncommon *a, - struct css_computed_uncommon *b) +static inline bool css__arena_style_is_equal( + struct css_computed_style *a, + struct css_computed_style *b) { - if (memcmp(&a->i, &b->i, sizeof(struct css_computed_uncommon_i)) != 0) { + if (memcmp(&a->i, &b->i, sizeof(struct css_computed_style_i)) != 0) { + return false; + } + + if (!arena__compare_string_list( + a->font_family, + b->font_family)) { return false; } @@ -151,82 +135,16 @@ static inline bool css__arena_uncommon_is_equal( return false; } - return true; -} - - -static inline bool css__arena_style_is_equal( - struct css_computed_style *a, - struct css_computed_style *b) -{ - if (memcmp(&a->i, &b->i, sizeof(struct css_computed_style_i)) != 0) { - return false; - } - - if (!arena__compare_string_list( - a->font_family, - b->font_family)) { - return false; - } - if (!arena__compare_string_list( a->quotes, b->quotes)) { return false; } - if (!arena__compare_computed_page( - a->page, - b->page)) { - return false; - } - return true; } -static void css__arena_intern_uncommon( - struct css_computed_uncommon **uncommon) -{ - struct css_computed_uncommon *u = *uncommon; - uint32_t hash, index; - - /* Need to intern the uncommon block */ - hash = css__arena_hash_uncommon(u); - index = hash % TU_SIZE; - u->bin = index; - - if (table_u[index] == NULL) { - /* Can just insert */ - table_u[index] = u; - u->count = 1; - } else { - /* Check for existing */ - struct css_computed_uncommon *l = table_u[index]; - struct css_computed_uncommon *existing = NULL; - - do { - if (css__arena_uncommon_is_equal(l, u)) { - existing = l; - break; - } - l = l->next; - } while (l != NULL); - - if (existing != NULL) { - css__computed_uncommon_destroy(u); - existing->count++; - *uncommon = existing; - } else { - /* Add to list */ - u->next = table_u[index]; - table_u[index] = u; - u->count = 1; - } - } -} - - /* Internally exported function, documented in src/select/arena.h */ css_error css__arena_intern_style(struct css_computed_style **style) { @@ -238,13 +156,6 @@ css_error css__arena_intern_style(struct css_computed_style **style) return CSS_BADPARM; } - if (s->i.uncommon != NULL) { - if (s->i.uncommon->count != 0) { - return CSS_BADPARM; - } - css__arena_intern_uncommon(&s->i.uncommon); - } - /* Need to intern the style block */ hash = css__arena_hash_style(s); index = hash % TS_SIZE; @@ -268,7 +179,6 @@ css_error css__arena_intern_style(struct css_computed_style **style) } while (l != NULL); if (existing != NULL) { - s->i.uncommon = NULL; css_computed_style_destroy(s); existing->count++; *style = existing; @@ -320,43 +230,3 @@ enum css_error css__arena_remove_style(struct css_computed_style *style) return CSS_OK; } - - -/* Internally exported function, documented in src/select/arena.h */ -enum css_error css__arena_remove_uncommon_style( - struct css_computed_uncommon *uncommon) -{ - uint32_t index = uncommon->bin; - - if (table_u[index] == NULL) { - return CSS_BADPARM; - - } else { - /* Check for existing */ - struct css_computed_uncommon *l = table_u[index]; - struct css_computed_uncommon *existing = NULL; - struct css_computed_uncommon *prev = NULL; - - do { - if (css__arena_uncommon_is_equal(l, uncommon)) { - existing = l; - break; - } - prev = l; - l = l->next; - } while (l != NULL); - - if (existing != NULL) { - if (prev != NULL) { - prev->next = existing->next; - } else { - table_u[index] = existing->next; - } - } else { - return CSS_BADPARM; - } - } - - return CSS_OK; -} - diff --git a/src/select/arena.h b/src/select/arena.h index af06050..5da5a5d 100644 --- a/src/select/arena.h +++ b/src/select/arena.h @@ -10,7 +10,6 @@ #define css_select_arena_h_ struct css_computed_style; -struct css_computed_uncommon; /* * Add computed style to the style sharing arena, or exchange for existing @@ -32,14 +31,5 @@ enum css_error css__arena_intern_style(struct css_computed_style **style); */ enum css_error css__arena_remove_style(struct css_computed_style *style); -/* - * Remove a computed style's uncommon block from the style sharing arena - * - * \params uncommon The uncommon style to remove from the style sharing arena - * \return CSS_OK on success or appropriate error otherwise. - */ -enum css_error css__arena_remove_uncommon_style( - struct css_computed_uncommon *uncommon); - #endif diff --git a/src/select/arena_hash.h b/src/select/arena_hash.h index 58abcd4..449284f 100644 --- a/src/select/arena_hash.h +++ b/src/select/arena_hash.h @@ -49,8 +49,8 @@ static inline uint32_t css__arena_hash(const uint8_t *data, size_t len) /* Hash any left over bytes */ switch (len) { - case 3: h ^= data[2] << 16; - case 2: h ^= data[1] << 8; + case 3: h ^= data[2] << 16; /* Fall through */ + case 2: h ^= data[1] << 8; /* Fall through */ case 1: h ^= data[0]; h *= m; } diff --git a/src/select/assets.py b/src/select/assets.py new file mode 100644 index 0000000..67c6b6b --- /dev/null +++ b/src/select/assets.py @@ -0,0 +1,30 @@ +# This file is part of LibCSS. +# Licensed under the MIT License, +# http://www.opensource.org/licenses/mit-license.php +# Copyright 2017 Lucas Neves <lcneves@gmail.com> + +copyright = '''\ +/* + * This file is part of LibCSS + * Licensed under the MIT License, + * http://www.opensource.org/licenses/mit-license.php + * Copyright 2017 The NetSurf Project + */ +''' + +assets = {} + +assets['computed.h'] = {} +assets['computed.h']['header'] = copyright +assets['computed.h']['footer'] = '' + +assets['propset.h'] = {} +assets['propset.h']['header'] = copyright + ''' +/** Default values are 'initial value', unless the property is inherited, + * in which case it is 'inherit'. */''' +assets['propset.h']['footer'] = '' + +assets['propget.h'] = {} +assets['propget.h']['header'] = copyright +assets['propget.h']['footer'] = '' + diff --git a/src/select/autogenerated_computed.h b/src/select/autogenerated_computed.h new file mode 100644 index 0000000..40005c1 --- /dev/null +++ b/src/select/autogenerated_computed.h @@ -0,0 +1,285 @@ +/* + * This file is part of LibCSS + * Licensed under the MIT License, + * http://www.opensource.org/licenses/mit-license.php + * Copyright 2017 The NetSurf Project + */ + + +struct css_computed_style_i { +/* + * Property Size (bits) Size (bytes) + * --- --- --- + * align_content 3 + * align_items 3 + * align_self 3 + * background_attachment 2 + * background_color 2 4 + * background_image 1 sizeof(ptr) + * background_position 1 + 10 8 + * background_repeat 3 + * border_bottom_color 2 4 + * border_bottom_style 4 + * border_bottom_width 3 + 5 4 + * border_collapse 2 + * border_left_color 2 4 + * border_left_style 4 + * border_left_width 3 + 5 4 + * border_right_color 2 4 + * border_right_style 4 + * border_right_width 3 + 5 4 + * border_spacing 1 + 10 8 + * border_top_color 2 4 + * border_top_style 4 + * border_top_width 3 + 5 4 + * bottom 2 + 5 4 + * box_sizing 2 + * break_after 4 + * break_before 4 + * break_inside 4 + * caption_side 2 + * clear 3 + * clip 6 + 20 16 + * color 1 4 + * column_count 2 4 + * column_fill 2 + * column_gap 2 + 5 4 + * column_rule_color 2 4 + * column_rule_style 4 + * column_rule_width 3 + 5 4 + * column_span 2 + * column_width 2 + 5 4 + * direction 2 + * display 5 + * empty_cells 2 + * fill_opacity 1 4 + * flex_basis 2 + 5 4 + * flex_direction 3 + * flex_grow 1 4 + * flex_shrink 1 4 + * flex_wrap 2 + * float 2 + * font_size 4 + 5 4 + * font_style 2 + * font_variant 2 + * font_weight 4 + * height 2 + 5 4 + * justify_content 3 + * left 2 + 5 4 + * letter_spacing 2 + 5 4 + * line_height 2 + 5 4 + * list_style_image 1 sizeof(ptr) + * list_style_position 2 + * list_style_type 6 + * margin_bottom 2 + 5 4 + * margin_left 2 + 5 4 + * margin_right 2 + 5 4 + * margin_top 2 + 5 4 + * max_height 2 + 5 4 + * max_width 2 + 5 4 + * min_height 2 + 5 4 + * min_width 2 + 5 4 + * opacity 1 4 + * order 1 4 + * orphans 1 4 + * outline_color 2 4 + * outline_style 4 + * outline_width 3 + 5 4 + * overflow_x 3 + * overflow_y 3 + * padding_bottom 1 + 5 4 + * padding_left 1 + 5 4 + * padding_right 1 + 5 4 + * padding_top 1 + 5 4 + * page_break_after 3 + * page_break_before 3 + * page_break_inside 2 + * position 3 + * right 2 + 5 4 + * stroke_opacity 1 4 + * table_layout 2 + * text_align 4 + * text_decoration 5 + * text_indent 1 + 5 4 + * text_transform 3 + * top 2 + 5 4 + * unicode_bidi 2 + * vertical_align 4 + 5 4 + * visibility 2 + * white_space 3 + * widows 1 4 + * width 2 + 5 4 + * word_spacing 2 + 5 4 + * writing_mode 2 + * z_index 2 4 + * + * Encode content as an array of content items, terminated with a blank entry. + * + * content 2 sizeof(ptr) + * + * Encode counter_increment as an array of name, value pairs, terminated with a + * blank entry. + * + * counter_increment 1 sizeof(ptr) + * + * Encode counter_reset as an array of name, value pairs, terminated with a + * blank entry. + * + * counter_reset 1 sizeof(ptr) + * + * Encode cursor uri(s) as an array of string objects, terminated with a blank + * entry + * + * cursor 5 sizeof(ptr) + * + * Encode font family as an array of string objects, terminated with a blank + * entry. + * + * font_family 3 sizeof(ptr) + * + * Encode quotes as an array of string objects, terminated with a blank entry. + * + * quotes 1 sizeof(ptr) + * + * --- --- --- + * 464 bits 236 + 8sizeof(ptr) bytes + * =================== + * 294 + 8sizeof(ptr) bytes + * + * Bit allocations: + * + * 0 bbbbbbbboooooooorrrrrrrrdddddddd + * border_top_width; border_right_width; border_left_width; border_bottom_width + * + * 1 fffffffffooooooooccccccccwwwwwww + * font_size; outline_width; column_rule_width; word_spacing + * + * 2 cccccccccccccccccccccccccctttttt + * clip; text_indent + * + * 3 cccccccooooooobbbbbbbppppppttttt + * column_width; column_gap; bottom; padding_top; text_decoration + * + * 4 wwwwwwwtttttttrrrrrrrmmmmmmmeeee + * width; top; right; min_width; text_align + * + * 5 mmmmmmmaaaaaaaxxxxxxxrrrrrrroooo + * min_height; max_width; max_height; margin_top; outline_style + * + * 6 mmmmmmmaaaaaaarrrrrrrlllllllffff + * margin_right; margin_left; margin_bottom; line_height; font_weight + * + * 7 llllllleeeeeeehhhhhhhfffffffcccc + * letter_spacing; left; height; flex_basis; column_rule_style + * + * 8 ppppppaaaaaaddddddlllllliiiiiwww + * padding_right; padding_left; padding_bottom; list_style_type; display; + * white_space + * + * 9 cccccbbbbrrrreeeeooooddddllllttt + * cursor; break_inside; break_before; break_after; border_top_style; + * border_right_style; border_left_style; text_transform + * + * 10 bbbaaallliiizzwwvvuuttppoossffnn + * background_repeat; align_self; align_items; align_content; z_index; + * writing_mode; visibility; unicode_bidi; table_layout; page_break_inside; + * outline_color; list_style_position; font_variant; font_style + * + * 11 fflleeddccoouummnnaabbrriittppBB + * float; flex_wrap; empty_cells; direction; content; column_span; + * column_rule_color; column_fill; column_count; caption_side; box_sizing; + * border_top_color; border_right_color; border_left_color; border_collapse; + * border_bottom_color + * + * 12 bbbbbbbbbbbaaaaaaaaaaavvvvvvvvvw + * border_spacing; background_position; vertical_align; widows + * + * 13 bbbbpppaaagggooovvvjjjffflllcccs + * border_bottom_style; position; page_break_before; page_break_after; + * overflow_y; overflow_x; justify_content; font_family; flex_direction; clear; + * stroke_opacity + * + * 14 bbaaqorplfeicuCk................ + * background_color; background_attachment; quotes; orphans; order; opacity; + * list_style_image; flex_shrink; flex_grow; fill_opacity; counter_reset; + * counter_increment; color; background_image + */ + uint32_t bits[15]; + + css_color background_color; + lwc_string *background_image; + css_fixed background_position_a; + css_fixed background_position_b; + css_color border_bottom_color; + css_fixed border_bottom_width; + css_color border_left_color; + css_fixed border_left_width; + css_color border_right_color; + css_fixed border_right_width; + css_fixed border_spacing_a; + css_fixed border_spacing_b; + css_color border_top_color; + css_fixed border_top_width; + css_fixed bottom; + css_fixed clip_a; + css_fixed clip_b; + css_fixed clip_c; + css_fixed clip_d; + css_color color; + int32_t column_count; + css_fixed column_gap; + css_color column_rule_color; + css_fixed column_rule_width; + css_fixed column_width; + css_fixed fill_opacity; + css_fixed flex_basis; + css_fixed flex_grow; + css_fixed flex_shrink; + css_fixed font_size; + css_fixed height; + css_fixed left; + css_fixed letter_spacing; + css_fixed line_height; + lwc_string *list_style_image; + css_fixed margin_bottom; + css_fixed margin_left; + css_fixed margin_right; + css_fixed margin_top; + css_fixed max_height; + css_fixed max_width; + css_fixed min_height; + css_fixed min_width; + css_fixed opacity; + int32_t order; + int32_t orphans; + css_color outline_color; + css_fixed outline_width; + css_fixed padding_bottom; + css_fixed padding_left; + css_fixed padding_right; + css_fixed padding_top; + css_fixed right; + css_fixed stroke_opacity; + css_fixed text_indent; + css_fixed top; + css_fixed vertical_align; + int32_t widows; + css_fixed width; + css_fixed word_spacing; + int32_t z_index; +}; + +struct css_computed_style { + struct css_computed_style_i i; + + css_computed_content_item *content; + css_computed_counter *counter_increment; + css_computed_counter *counter_reset; + lwc_string **cursor; + lwc_string **font_family; + lwc_string **quotes; + + struct css_computed_style *next; + uint32_t count; + uint32_t bin; +}; diff --git a/src/select/autogenerated_propget.h b/src/select/autogenerated_propget.h new file mode 100644 index 0000000..d1f7ffb --- /dev/null +++ b/src/select/autogenerated_propget.h @@ -0,0 +1,3114 @@ +/* + * This file is part of LibCSS + * Licensed under the MIT License, + * http://www.opensource.org/licenses/mit-license.php + * Copyright 2017 The NetSurf Project + */ + + +#define ALIGN_CONTENT_INDEX 10 +#define ALIGN_CONTENT_SHIFT 20 +#define ALIGN_CONTENT_MASK 0x700000 +static inline uint8_t get_align_content_bits(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[ALIGN_CONTENT_INDEX]; + bits &= ALIGN_CONTENT_MASK; + bits >>= ALIGN_CONTENT_SHIFT; + + /* 3bits: ttt : type */ + return (bits & 0x7); +} +static inline uint8_t get_align_content(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[ALIGN_CONTENT_INDEX]; + bits &= ALIGN_CONTENT_MASK; + bits >>= ALIGN_CONTENT_SHIFT; + + /* 3bits: ttt : type */ + + return (bits & 0x7); +} +#undef ALIGN_CONTENT_INDEX +#undef ALIGN_CONTENT_SHIFT +#undef ALIGN_CONTENT_MASK + +#define ALIGN_ITEMS_INDEX 10 +#define ALIGN_ITEMS_SHIFT 23 +#define ALIGN_ITEMS_MASK 0x3800000 +static inline uint8_t get_align_items_bits(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[ALIGN_ITEMS_INDEX]; + bits &= ALIGN_ITEMS_MASK; + bits >>= ALIGN_ITEMS_SHIFT; + + /* 3bits: ttt : type */ + return (bits & 0x7); +} +static inline uint8_t get_align_items(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[ALIGN_ITEMS_INDEX]; + bits &= ALIGN_ITEMS_MASK; + bits >>= ALIGN_ITEMS_SHIFT; + + /* 3bits: ttt : type */ + + return (bits & 0x7); +} +#undef ALIGN_ITEMS_INDEX +#undef ALIGN_ITEMS_SHIFT +#undef ALIGN_ITEMS_MASK + +#define ALIGN_SELF_INDEX 10 +#define ALIGN_SELF_SHIFT 26 +#define ALIGN_SELF_MASK 0x1c000000 +static inline uint8_t get_align_self_bits(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[ALIGN_SELF_INDEX]; + bits &= ALIGN_SELF_MASK; + bits >>= ALIGN_SELF_SHIFT; + + /* 3bits: ttt : type */ + return (bits & 0x7); +} +static inline uint8_t get_align_self(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[ALIGN_SELF_INDEX]; + bits &= ALIGN_SELF_MASK; + bits >>= ALIGN_SELF_SHIFT; + + /* 3bits: ttt : type */ + + return (bits & 0x7); +} +#undef ALIGN_SELF_INDEX +#undef ALIGN_SELF_SHIFT +#undef ALIGN_SELF_MASK + +#define BACKGROUND_ATTACHMENT_INDEX 14 +#define BACKGROUND_ATTACHMENT_SHIFT 28 +#define BACKGROUND_ATTACHMENT_MASK 0x30000000 +static inline uint8_t get_background_attachment_bits(const css_computed_style + *style) +{ + uint32_t bits = style->i.bits[BACKGROUND_ATTACHMENT_INDEX]; + bits &= BACKGROUND_ATTACHMENT_MASK; + bits >>= BACKGROUND_ATTACHMENT_SHIFT; + + /* 2bits: tt : type */ + return (bits & 0x3); +} +static inline uint8_t get_background_attachment(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[BACKGROUND_ATTACHMENT_INDEX]; + bits &= BACKGROUND_ATTACHMENT_MASK; + bits >>= BACKGROUND_ATTACHMENT_SHIFT; + + /* 2bits: tt : type */ + + return (bits & 0x3); +} +#undef BACKGROUND_ATTACHMENT_INDEX +#undef BACKGROUND_ATTACHMENT_SHIFT +#undef BACKGROUND_ATTACHMENT_MASK + +#define BACKGROUND_COLOR_INDEX 14 +#define BACKGROUND_COLOR_SHIFT 30 +#define BACKGROUND_COLOR_MASK 0xc0000000 +static inline uint8_t get_background_color_bits(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[BACKGROUND_COLOR_INDEX]; + bits &= BACKGROUND_COLOR_MASK; + bits >>= BACKGROUND_COLOR_SHIFT; + + /* 2bits: tt : type */ + return (bits & 0x3); +} +static inline uint8_t get_background_color(const css_computed_style *style, + css_color *color) +{ + uint32_t bits = style->i.bits[BACKGROUND_COLOR_INDEX]; + bits &= BACKGROUND_COLOR_MASK; + bits >>= BACKGROUND_COLOR_SHIFT; + + /* 2bits: tt : type */ + *color = style->i.background_color; + + return (bits & 0x3); +} +#undef BACKGROUND_COLOR_INDEX +#undef BACKGROUND_COLOR_SHIFT +#undef BACKGROUND_COLOR_MASK + +#define BACKGROUND_IMAGE_INDEX 14 +#define BACKGROUND_IMAGE_SHIFT 16 +#define BACKGROUND_IMAGE_MASK 0x10000 +static inline uint8_t get_background_image_bits(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[BACKGROUND_IMAGE_INDEX]; + bits &= BACKGROUND_IMAGE_MASK; + bits >>= BACKGROUND_IMAGE_SHIFT; + + /* 1bit: t : type */ + return (bits & 0x1); +} +static inline uint8_t get_background_image(const css_computed_style *style, + lwc_string **string) +{ + uint32_t bits = style->i.bits[BACKGROUND_IMAGE_INDEX]; + bits &= BACKGROUND_IMAGE_MASK; + bits >>= BACKGROUND_IMAGE_SHIFT; + + /* 1bit: t : type */ + *string = style->i.background_image; + + return (bits & 0x1); +} +#undef BACKGROUND_IMAGE_INDEX +#undef BACKGROUND_IMAGE_SHIFT +#undef BACKGROUND_IMAGE_MASK + +#define BACKGROUND_POSITION_INDEX 12 +#define BACKGROUND_POSITION_SHIFT 10 +#define BACKGROUND_POSITION_MASK 0x1ffc00 +static inline uint8_t get_background_position_bits(const css_computed_style + *style) +{ + uint32_t bits = style->i.bits[BACKGROUND_POSITION_INDEX]; + bits &= BACKGROUND_POSITION_MASK; + bits >>= BACKGROUND_POSITION_SHIFT; + + /* 11bits: aaaaabbbbbt : unit_a | unit_b | type */ + return (bits & 0x1); +} +static inline uint8_t get_background_position(const css_computed_style *style, + css_fixed *length_a, css_unit *unit_a, css_fixed *length_b, + css_unit *unit_b) +{ + uint32_t bits = style->i.bits[BACKGROUND_POSITION_INDEX]; + bits &= BACKGROUND_POSITION_MASK; + bits >>= BACKGROUND_POSITION_SHIFT; + + /* 11bits: aaaaabbbbbt : unit_a | unit_b | type */ + if ((bits & 0x1) == CSS_BACKGROUND_POSITION_SET) { + *length_a = style->i.background_position_a; + *length_b = style->i.background_position_b; + *unit_a = bits >> 6; + *unit_b = (bits & 0x3e) >> 1; + } + + return (bits & 0x1); +} +#undef BACKGROUND_POSITION_INDEX +#undef BACKGROUND_POSITION_SHIFT +#undef BACKGROUND_POSITION_MASK + +#define BACKGROUND_REPEAT_INDEX 10 +#define BACKGROUND_REPEAT_SHIFT 29 +#define BACKGROUND_REPEAT_MASK 0xe0000000 +static inline uint8_t get_background_repeat_bits(const css_computed_style + *style) +{ + uint32_t bits = style->i.bits[BACKGROUND_REPEAT_INDEX]; + bits &= BACKGROUND_REPEAT_MASK; + bits >>= BACKGROUND_REPEAT_SHIFT; + + /* 3bits: ttt : type */ + return (bits & 0x7); +} +static inline uint8_t get_background_repeat(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[BACKGROUND_REPEAT_INDEX]; + bits &= BACKGROUND_REPEAT_MASK; + bits >>= BACKGROUND_REPEAT_SHIFT; + + /* 3bits: ttt : type */ + + return (bits & 0x7); +} +#undef BACKGROUND_REPEAT_INDEX +#undef BACKGROUND_REPEAT_SHIFT +#undef BACKGROUND_REPEAT_MASK + +#define BORDER_BOTTOM_COLOR_INDEX 11 +#define BORDER_BOTTOM_COLOR_SHIFT 0 +#define BORDER_BOTTOM_COLOR_MASK 0x3 +static inline uint8_t get_border_bottom_color_bits(const css_computed_style + *style) +{ + uint32_t bits = style->i.bits[BORDER_BOTTOM_COLOR_INDEX]; + bits &= BORDER_BOTTOM_COLOR_MASK; + bits >>= BORDER_BOTTOM_COLOR_SHIFT; + + /* 2bits: tt : type */ + return (bits & 0x3); +} +static inline uint8_t get_border_bottom_color(const css_computed_style *style, + css_color *color) +{ + uint32_t bits = style->i.bits[BORDER_BOTTOM_COLOR_INDEX]; + bits &= BORDER_BOTTOM_COLOR_MASK; + bits >>= BORDER_BOTTOM_COLOR_SHIFT; + + /* 2bits: tt : type */ + *color = style->i.border_bottom_color; + + return (bits & 0x3); +} +#undef BORDER_BOTTOM_COLOR_INDEX +#undef BORDER_BOTTOM_COLOR_SHIFT +#undef BORDER_BOTTOM_COLOR_MASK + +#define BORDER_BOTTOM_STYLE_INDEX 13 +#define BORDER_BOTTOM_STYLE_SHIFT 28 +#define BORDER_BOTTOM_STYLE_MASK 0xf0000000 +static inline uint8_t get_border_bottom_style_bits(const css_computed_style + *style) +{ + uint32_t bits = style->i.bits[BORDER_BOTTOM_STYLE_INDEX]; + bits &= BORDER_BOTTOM_STYLE_MASK; + bits >>= BORDER_BOTTOM_STYLE_SHIFT; + + /* 4bits: tttt : type */ + return (bits & 0xf); +} +static inline uint8_t get_border_bottom_style(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[BORDER_BOTTOM_STYLE_INDEX]; + bits &= BORDER_BOTTOM_STYLE_MASK; + bits >>= BORDER_BOTTOM_STYLE_SHIFT; + + /* 4bits: tttt : type */ + + return (bits & 0xf); +} +#undef BORDER_BOTTOM_STYLE_INDEX +#undef BORDER_BOTTOM_STYLE_SHIFT +#undef BORDER_BOTTOM_STYLE_MASK + +#define BORDER_BOTTOM_WIDTH_INDEX 0 +#define BORDER_BOTTOM_WIDTH_SHIFT 0 +#define BORDER_BOTTOM_WIDTH_MASK 0xff +static inline uint8_t get_border_bottom_width_bits(const css_computed_style + *style) +{ + uint32_t bits = style->i.bits[BORDER_BOTTOM_WIDTH_INDEX]; + bits &= BORDER_BOTTOM_WIDTH_MASK; + bits >>= BORDER_BOTTOM_WIDTH_SHIFT; + + /* 8bits: uuuuuttt : unit | type */ + return (bits & 0x7); +} +static inline uint8_t get_border_bottom_width(const css_computed_style *style, + css_fixed *length, css_unit *unit) +{ + uint32_t bits = style->i.bits[BORDER_BOTTOM_WIDTH_INDEX]; + bits &= BORDER_BOTTOM_WIDTH_MASK; + bits >>= BORDER_BOTTOM_WIDTH_SHIFT; + + /* 8bits: uuuuuttt : unit | type */ + if ((bits & 0x7) == CSS_BORDER_WIDTH_WIDTH) { + *length = style->i.border_bottom_width; + *unit = bits >> 3; + } + + return (bits & 0x7); +} +#undef BORDER_BOTTOM_WIDTH_INDEX +#undef BORDER_BOTTOM_WIDTH_SHIFT +#undef BORDER_BOTTOM_WIDTH_MASK + +#define BORDER_COLLAPSE_INDEX 11 +#define BORDER_COLLAPSE_SHIFT 2 +#define BORDER_COLLAPSE_MASK 0xc +static inline uint8_t get_border_collapse_bits(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[BORDER_COLLAPSE_INDEX]; + bits &= BORDER_COLLAPSE_MASK; + bits >>= BORDER_COLLAPSE_SHIFT; + + /* 2bits: tt : type */ + return (bits & 0x3); +} +static inline uint8_t get_border_collapse(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[BORDER_COLLAPSE_INDEX]; + bits &= BORDER_COLLAPSE_MASK; + bits >>= BORDER_COLLAPSE_SHIFT; + + /* 2bits: tt : type */ + + return (bits & 0x3); +} +#undef BORDER_COLLAPSE_INDEX +#undef BORDER_COLLAPSE_SHIFT +#undef BORDER_COLLAPSE_MASK + +#define BORDER_LEFT_COLOR_INDEX 11 +#define BORDER_LEFT_COLOR_SHIFT 4 +#define BORDER_LEFT_COLOR_MASK 0x30 +static inline uint8_t get_border_left_color_bits(const css_computed_style + *style) +{ + uint32_t bits = style->i.bits[BORDER_LEFT_COLOR_INDEX]; + bits &= BORDER_LEFT_COLOR_MASK; + bits >>= BORDER_LEFT_COLOR_SHIFT; + + /* 2bits: tt : type */ + return (bits & 0x3); +} +static inline uint8_t get_border_left_color(const css_computed_style *style, + css_color *color) +{ + uint32_t bits = style->i.bits[BORDER_LEFT_COLOR_INDEX]; + bits &= BORDER_LEFT_COLOR_MASK; + bits >>= BORDER_LEFT_COLOR_SHIFT; + + /* 2bits: tt : type */ + *color = style->i.border_left_color; + + return (bits & 0x3); +} +#undef BORDER_LEFT_COLOR_INDEX +#undef BORDER_LEFT_COLOR_SHIFT +#undef BORDER_LEFT_COLOR_MASK + +#define BORDER_LEFT_STYLE_INDEX 9 +#define BORDER_LEFT_STYLE_SHIFT 3 +#define BORDER_LEFT_STYLE_MASK 0x78 +static inline uint8_t get_border_left_style_bits(const css_computed_style + *style) +{ + uint32_t bits = style->i.bits[BORDER_LEFT_STYLE_INDEX]; + bits &= BORDER_LEFT_STYLE_MASK; + bits >>= BORDER_LEFT_STYLE_SHIFT; + + /* 4bits: tttt : type */ + return (bits & 0xf); +} +static inline uint8_t get_border_left_style(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[BORDER_LEFT_STYLE_INDEX]; + bits &= BORDER_LEFT_STYLE_MASK; + bits >>= BORDER_LEFT_STYLE_SHIFT; + + /* 4bits: tttt : type */ + + return (bits & 0xf); +} +#undef BORDER_LEFT_STYLE_INDEX +#undef BORDER_LEFT_STYLE_SHIFT +#undef BORDER_LEFT_STYLE_MASK + +#define BORDER_LEFT_WIDTH_INDEX 0 +#define BORDER_LEFT_WIDTH_SHIFT 8 +#define BORDER_LEFT_WIDTH_MASK 0xff00 +static inline uint8_t get_border_left_width_bits(const css_computed_style + *style) +{ + uint32_t bits = style->i.bits[BORDER_LEFT_WIDTH_INDEX]; + bits &= BORDER_LEFT_WIDTH_MASK; + bits >>= BORDER_LEFT_WIDTH_SHIFT; + + /* 8bits: uuuuuttt : unit | type */ + return (bits & 0x7); +} +static inline uint8_t get_border_left_width(const css_computed_style *style, + css_fixed *length, css_unit *unit) +{ + uint32_t bits = style->i.bits[BORDER_LEFT_WIDTH_INDEX]; + bits &= BORDER_LEFT_WIDTH_MASK; + bits >>= BORDER_LEFT_WIDTH_SHIFT; + + /* 8bits: uuuuuttt : unit | type */ + if ((bits & 0x7) == CSS_BORDER_WIDTH_WIDTH) { + *length = style->i.border_left_width; + *unit = bits >> 3; + } + + return (bits & 0x7); +} +#undef BORDER_LEFT_WIDTH_INDEX +#undef BORDER_LEFT_WIDTH_SHIFT +#undef BORDER_LEFT_WIDTH_MASK + +#define BORDER_RIGHT_COLOR_INDEX 11 +#define BORDER_RIGHT_COLOR_SHIFT 6 +#define BORDER_RIGHT_COLOR_MASK 0xc0 +static inline uint8_t get_border_right_color_bits(const css_computed_style + *style) +{ + uint32_t bits = style->i.bits[BORDER_RIGHT_COLOR_INDEX]; + bits &= BORDER_RIGHT_COLOR_MASK; + bits >>= BORDER_RIGHT_COLOR_SHIFT; + + /* 2bits: tt : type */ + return (bits & 0x3); +} +static inline uint8_t get_border_right_color(const css_computed_style *style, + css_color *color) +{ + uint32_t bits = style->i.bits[BORDER_RIGHT_COLOR_INDEX]; + bits &= BORDER_RIGHT_COLOR_MASK; + bits >>= BORDER_RIGHT_COLOR_SHIFT; + + /* 2bits: tt : type */ + *color = style->i.border_right_color; + + return (bits & 0x3); +} +#undef BORDER_RIGHT_COLOR_INDEX +#undef BORDER_RIGHT_COLOR_SHIFT +#undef BORDER_RIGHT_COLOR_MASK + +#define BORDER_RIGHT_STYLE_INDEX 9 +#define BORDER_RIGHT_STYLE_SHIFT 7 +#define BORDER_RIGHT_STYLE_MASK 0x780 +static inline uint8_t get_border_right_style_bits(const css_computed_style + *style) +{ + uint32_t bits = style->i.bits[BORDER_RIGHT_STYLE_INDEX]; + bits &= BORDER_RIGHT_STYLE_MASK; + bits >>= BORDER_RIGHT_STYLE_SHIFT; + + /* 4bits: tttt : type */ + return (bits & 0xf); +} +static inline uint8_t get_border_right_style(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[BORDER_RIGHT_STYLE_INDEX]; + bits &= BORDER_RIGHT_STYLE_MASK; + bits >>= BORDER_RIGHT_STYLE_SHIFT; + + /* 4bits: tttt : type */ + + return (bits & 0xf); +} +#undef BORDER_RIGHT_STYLE_INDEX +#undef BORDER_RIGHT_STYLE_SHIFT +#undef BORDER_RIGHT_STYLE_MASK + +#define BORDER_RIGHT_WIDTH_INDEX 0 +#define BORDER_RIGHT_WIDTH_SHIFT 16 +#define BORDER_RIGHT_WIDTH_MASK 0xff0000 +static inline uint8_t get_border_right_width_bits(const css_computed_style + *style) +{ + uint32_t bits = style->i.bits[BORDER_RIGHT_WIDTH_INDEX]; + bits &= BORDER_RIGHT_WIDTH_MASK; + bits >>= BORDER_RIGHT_WIDTH_SHIFT; + + /* 8bits: uuuuuttt : unit | type */ + return (bits & 0x7); +} +static inline uint8_t get_border_right_width(const css_computed_style *style, + css_fixed *length, css_unit *unit) +{ + uint32_t bits = style->i.bits[BORDER_RIGHT_WIDTH_INDEX]; + bits &= BORDER_RIGHT_WIDTH_MASK; + bits >>= BORDER_RIGHT_WIDTH_SHIFT; + + /* 8bits: uuuuuttt : unit | type */ + if ((bits & 0x7) == CSS_BORDER_WIDTH_WIDTH) { + *length = style->i.border_right_width; + *unit = bits >> 3; + } + + return (bits & 0x7); +} +#undef BORDER_RIGHT_WIDTH_INDEX +#undef BORDER_RIGHT_WIDTH_SHIFT +#undef BORDER_RIGHT_WIDTH_MASK + +#define BORDER_SPACING_INDEX 12 +#define BORDER_SPACING_SHIFT 21 +#define BORDER_SPACING_MASK 0xffe00000 +static inline uint8_t get_border_spacing_bits(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[BORDER_SPACING_INDEX]; + bits &= BORDER_SPACING_MASK; + bits >>= BORDER_SPACING_SHIFT; + + /* 11bits: aaaaabbbbbt : unit_a | unit_b | type */ + return (bits & 0x1); +} +static inline uint8_t get_border_spacing(const css_computed_style *style, + css_fixed *length_a, css_unit *unit_a, css_fixed *length_b, + css_unit *unit_b) +{ + uint32_t bits = style->i.bits[BORDER_SPACING_INDEX]; + bits &= BORDER_SPACING_MASK; + bits >>= BORDER_SPACING_SHIFT; + + /* 11bits: aaaaabbbbbt : unit_a | unit_b | type */ + if ((bits & 0x1) == CSS_BORDER_SPACING_SET) { + *length_a = style->i.border_spacing_a; + *length_b = style->i.border_spacing_b; + *unit_a = bits >> 6; + *unit_b = (bits & 0x3e) >> 1; + } + + return (bits & 0x1); +} +#undef BORDER_SPACING_INDEX +#undef BORDER_SPACING_SHIFT +#undef BORDER_SPACING_MASK + +#define BORDER_TOP_COLOR_INDEX 11 +#define BORDER_TOP_COLOR_SHIFT 8 +#define BORDER_TOP_COLOR_MASK 0x300 +static inline uint8_t get_border_top_color_bits(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[BORDER_TOP_COLOR_INDEX]; + bits &= BORDER_TOP_COLOR_MASK; + bits >>= BORDER_TOP_COLOR_SHIFT; + + /* 2bits: tt : type */ + return (bits & 0x3); +} +static inline uint8_t get_border_top_color(const css_computed_style *style, + css_color *color) +{ + uint32_t bits = style->i.bits[BORDER_TOP_COLOR_INDEX]; + bits &= BORDER_TOP_COLOR_MASK; + bits >>= BORDER_TOP_COLOR_SHIFT; + + /* 2bits: tt : type */ + *color = style->i.border_top_color; + + return (bits & 0x3); +} +#undef BORDER_TOP_COLOR_INDEX +#undef BORDER_TOP_COLOR_SHIFT +#undef BORDER_TOP_COLOR_MASK + +#define BORDER_TOP_STYLE_INDEX 9 +#define BORDER_TOP_STYLE_SHIFT 11 +#define BORDER_TOP_STYLE_MASK 0x7800 +static inline uint8_t get_border_top_style_bits(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[BORDER_TOP_STYLE_INDEX]; + bits &= BORDER_TOP_STYLE_MASK; + bits >>= BORDER_TOP_STYLE_SHIFT; + + /* 4bits: tttt : type */ + return (bits & 0xf); +} +static inline uint8_t get_border_top_style(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[BORDER_TOP_STYLE_INDEX]; + bits &= BORDER_TOP_STYLE_MASK; + bits >>= BORDER_TOP_STYLE_SHIFT; + + /* 4bits: tttt : type */ + + return (bits & 0xf); +} +#undef BORDER_TOP_STYLE_INDEX +#undef BORDER_TOP_STYLE_SHIFT +#undef BORDER_TOP_STYLE_MASK + +#define BORDER_TOP_WIDTH_INDEX 0 +#define BORDER_TOP_WIDTH_SHIFT 24 +#define BORDER_TOP_WIDTH_MASK 0xff000000 +static inline uint8_t get_border_top_width_bits(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[BORDER_TOP_WIDTH_INDEX]; + bits &= BORDER_TOP_WIDTH_MASK; + bits >>= BORDER_TOP_WIDTH_SHIFT; + + /* 8bits: uuuuuttt : unit | type */ + return (bits & 0x7); +} +static inline uint8_t get_border_top_width(const css_computed_style *style, + css_fixed *length, css_unit *unit) +{ + uint32_t bits = style->i.bits[BORDER_TOP_WIDTH_INDEX]; + bits &= BORDER_TOP_WIDTH_MASK; + bits >>= BORDER_TOP_WIDTH_SHIFT; + + /* 8bits: uuuuuttt : unit | type */ + if ((bits & 0x7) == CSS_BORDER_WIDTH_WIDTH) { + *length = style->i.border_top_width; + *unit = bits >> 3; + } + + return (bits & 0x7); +} +#undef BORDER_TOP_WIDTH_INDEX +#undef BORDER_TOP_WIDTH_SHIFT +#undef BORDER_TOP_WIDTH_MASK + +#define BOTTOM_INDEX 3 +#define BOTTOM_SHIFT 11 +#define BOTTOM_MASK 0x3f800 +static inline uint8_t get_bottom_bits(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[BOTTOM_INDEX]; + bits &= BOTTOM_MASK; + bits >>= BOTTOM_SHIFT; + + /* 7bits: uuuuutt : unit | type */ + return (bits & 0x3); +} +static inline uint8_t get_bottom(const css_computed_style *style, css_fixed + *length, css_unit *unit) +{ + uint32_t bits = style->i.bits[BOTTOM_INDEX]; + bits &= BOTTOM_MASK; + bits >>= BOTTOM_SHIFT; + + /* 7bits: uuuuutt : unit | type */ + if ((bits & 0x3) == CSS_BOTTOM_SET) { + *length = style->i.bottom; + *unit = bits >> 2; + } + + return (bits & 0x3); +} +#undef BOTTOM_INDEX +#undef BOTTOM_SHIFT +#undef BOTTOM_MASK + +#define BOX_SIZING_INDEX 11 +#define BOX_SIZING_SHIFT 10 +#define BOX_SIZING_MASK 0xc00 +static inline uint8_t get_box_sizing_bits(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[BOX_SIZING_INDEX]; + bits &= BOX_SIZING_MASK; + bits >>= BOX_SIZING_SHIFT; + + /* 2bits: tt : type */ + return (bits & 0x3); +} +static inline uint8_t get_box_sizing(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[BOX_SIZING_INDEX]; + bits &= BOX_SIZING_MASK; + bits >>= BOX_SIZING_SHIFT; + + /* 2bits: tt : type */ + + return (bits & 0x3); +} +#undef BOX_SIZING_INDEX +#undef BOX_SIZING_SHIFT +#undef BOX_SIZING_MASK + +#define BREAK_AFTER_INDEX 9 +#define BREAK_AFTER_SHIFT 15 +#define BREAK_AFTER_MASK 0x78000 +static inline uint8_t get_break_after_bits(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[BREAK_AFTER_INDEX]; + bits &= BREAK_AFTER_MASK; + bits >>= BREAK_AFTER_SHIFT; + + /* 4bits: tttt : type */ + return (bits & 0xf); +} +static inline uint8_t get_break_after(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[BREAK_AFTER_INDEX]; + bits &= BREAK_AFTER_MASK; + bits >>= BREAK_AFTER_SHIFT; + + /* 4bits: tttt : type */ + + return (bits & 0xf); +} +#undef BREAK_AFTER_INDEX +#undef BREAK_AFTER_SHIFT +#undef BREAK_AFTER_MASK + +#define BREAK_BEFORE_INDEX 9 +#define BREAK_BEFORE_SHIFT 19 +#define BREAK_BEFORE_MASK 0x780000 +static inline uint8_t get_break_before_bits(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[BREAK_BEFORE_INDEX]; + bits &= BREAK_BEFORE_MASK; + bits >>= BREAK_BEFORE_SHIFT; + + /* 4bits: tttt : type */ + return (bits & 0xf); +} +static inline uint8_t get_break_before(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[BREAK_BEFORE_INDEX]; + bits &= BREAK_BEFORE_MASK; + bits >>= BREAK_BEFORE_SHIFT; + + /* 4bits: tttt : type */ + + return (bits & 0xf); +} +#undef BREAK_BEFORE_INDEX +#undef BREAK_BEFORE_SHIFT +#undef BREAK_BEFORE_MASK + +#define BREAK_INSIDE_INDEX 9 +#define BREAK_INSIDE_SHIFT 23 +#define BREAK_INSIDE_MASK 0x7800000 +static inline uint8_t get_break_inside_bits(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[BREAK_INSIDE_INDEX]; + bits &= BREAK_INSIDE_MASK; + bits >>= BREAK_INSIDE_SHIFT; + + /* 4bits: tttt : type */ + return (bits & 0xf); +} +static inline uint8_t get_break_inside(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[BREAK_INSIDE_INDEX]; + bits &= BREAK_INSIDE_MASK; + bits >>= BREAK_INSIDE_SHIFT; + + /* 4bits: tttt : type */ + + return (bits & 0xf); +} +#undef BREAK_INSIDE_INDEX +#undef BREAK_INSIDE_SHIFT +#undef BREAK_INSIDE_MASK + +#define CAPTION_SIDE_INDEX 11 +#define CAPTION_SIDE_SHIFT 12 +#define CAPTION_SIDE_MASK 0x3000 +static inline uint8_t get_caption_side_bits(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[CAPTION_SIDE_INDEX]; + bits &= CAPTION_SIDE_MASK; + bits >>= CAPTION_SIDE_SHIFT; + + /* 2bits: tt : type */ + return (bits & 0x3); +} +static inline uint8_t get_caption_side(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[CAPTION_SIDE_INDEX]; + bits &= CAPTION_SIDE_MASK; + bits >>= CAPTION_SIDE_SHIFT; + + /* 2bits: tt : type */ + + return (bits & 0x3); +} +#undef CAPTION_SIDE_INDEX +#undef CAPTION_SIDE_SHIFT +#undef CAPTION_SIDE_MASK + +#define CLEAR_INDEX 13 +#define CLEAR_SHIFT 1 +#define CLEAR_MASK 0xe +static inline uint8_t get_clear_bits(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[CLEAR_INDEX]; + bits &= CLEAR_MASK; + bits >>= CLEAR_SHIFT; + + /* 3bits: ttt : type */ + return (bits & 0x7); +} +static inline uint8_t get_clear(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[CLEAR_INDEX]; + bits &= CLEAR_MASK; + bits >>= CLEAR_SHIFT; + + /* 3bits: ttt : type */ + + return (bits & 0x7); +} +#undef CLEAR_INDEX +#undef CLEAR_SHIFT +#undef CLEAR_MASK + +#define CLIP_INDEX 2 +#define CLIP_SHIFT 6 +#define CLIP_MASK 0xffffffc0 +static inline uint8_t get_clip_bits(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[CLIP_INDEX]; + bits &= CLIP_MASK; + bits >>= CLIP_SHIFT; + + /* 26bits: aaaaabbbbbcccccdddddtttttt : unit_a | unit_b | unit_c | + unit_d | type */ + return (bits & 0x3f); +} +static inline uint8_t get_clip( + const css_computed_style *style, + css_computed_clip_rect *rect) +{ + uint32_t bits = style->i.bits[CLIP_INDEX]; + bits &= CLIP_MASK; + bits >>= CLIP_SHIFT; + + /* + 26bits: tt tttr rrrr bbbb blll llTR BLyy: + units: top | right | bottom | left + opcodes: top | right | bottom | left | type + */ + + if ((bits & 0x3) == CSS_CLIP_RECT) { + rect->left_auto = (bits & 0x4); + rect->bottom_auto = (bits & 0x8); + rect->right_auto = (bits & 0x10); + rect->top_auto = (bits & 0x20); + + rect->top = style->i.clip_a; + rect->tunit = bits & 0x3e00000 >> 21; + + rect->right = style->i.clip_b; + rect->runit = bits & 0x1f0000 >> 16; + + rect->bottom = style->i.clip_c; + rect->bunit = (bits & 0xf800) >> 11; + + rect->left = style->i.clip_d; + rect->lunit = (bits & 0x7c0) >> 6; + } + + return (bits & 0x3); +} +#undef CLIP_INDEX +#undef CLIP_SHIFT +#undef CLIP_MASK + +#define COLOR_INDEX 14 +#define COLOR_SHIFT 17 +#define COLOR_MASK 0x20000 +static inline uint8_t get_color_bits(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[COLOR_INDEX]; + bits &= COLOR_MASK; + bits >>= COLOR_SHIFT; + + /* 1bit: t : type */ + return (bits & 0x1); +} +static inline uint8_t get_color(const css_computed_style *style, css_color + *color) +{ + uint32_t bits = style->i.bits[COLOR_INDEX]; + bits &= COLOR_MASK; + bits >>= COLOR_SHIFT; + + /* 1bit: t : type */ + *color = style->i.color; + + return (bits & 0x1); +} +#undef COLOR_INDEX +#undef COLOR_SHIFT +#undef COLOR_MASK + +#define COLUMN_COUNT_INDEX 11 +#define COLUMN_COUNT_SHIFT 14 +#define COLUMN_COUNT_MASK 0xc000 +static inline uint8_t get_column_count_bits(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[COLUMN_COUNT_INDEX]; + bits &= COLUMN_COUNT_MASK; + bits >>= COLUMN_COUNT_SHIFT; + + /* 2bits: tt : type */ + return (bits & 0x3); +} +static inline uint8_t get_column_count(const css_computed_style *style, int32_t + *integer) +{ + uint32_t bits = style->i.bits[COLUMN_COUNT_INDEX]; + bits &= COLUMN_COUNT_MASK; + bits >>= COLUMN_COUNT_SHIFT; + + /* 2bits: tt : type */ + *integer = style->i.column_count; + + return (bits & 0x3); +} +#undef COLUMN_COUNT_INDEX +#undef COLUMN_COUNT_SHIFT +#undef COLUMN_COUNT_MASK + +#define COLUMN_FILL_INDEX 11 +#define COLUMN_FILL_SHIFT 16 +#define COLUMN_FILL_MASK 0x30000 +static inline uint8_t get_column_fill_bits(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[COLUMN_FILL_INDEX]; + bits &= COLUMN_FILL_MASK; + bits >>= COLUMN_FILL_SHIFT; + + /* 2bits: tt : type */ + return (bits & 0x3); +} +static inline uint8_t get_column_fill(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[COLUMN_FILL_INDEX]; + bits &= COLUMN_FILL_MASK; + bits >>= COLUMN_FILL_SHIFT; + + /* 2bits: tt : type */ + + return (bits & 0x3); +} +#undef COLUMN_FILL_INDEX +#undef COLUMN_FILL_SHIFT +#undef COLUMN_FILL_MASK + +#define COLUMN_GAP_INDEX 3 +#define COLUMN_GAP_SHIFT 18 +#define COLUMN_GAP_MASK 0x1fc0000 +static inline uint8_t get_column_gap_bits(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[COLUMN_GAP_INDEX]; + bits &= COLUMN_GAP_MASK; + bits >>= COLUMN_GAP_SHIFT; + + /* 7bits: uuuuutt : unit | type */ + return (bits & 0x3); +} +static inline uint8_t get_column_gap(const css_computed_style *style, css_fixed + *length, css_unit *unit) +{ + uint32_t bits = style->i.bits[COLUMN_GAP_INDEX]; + bits &= COLUMN_GAP_MASK; + bits >>= COLUMN_GAP_SHIFT; + + /* 7bits: uuuuutt : unit | type */ + if ((bits & 0x3) == CSS_COLUMN_GAP_SET) { + *length = style->i.column_gap; + *unit = bits >> 2; + } + + return (bits & 0x3); +} +#undef COLUMN_GAP_INDEX +#undef COLUMN_GAP_SHIFT +#undef COLUMN_GAP_MASK + +#define COLUMN_RULE_COLOR_INDEX 11 +#define COLUMN_RULE_COLOR_SHIFT 18 +#define COLUMN_RULE_COLOR_MASK 0xc0000 +static inline uint8_t get_column_rule_color_bits(const css_computed_style + *style) +{ + uint32_t bits = style->i.bits[COLUMN_RULE_COLOR_INDEX]; + bits &= COLUMN_RULE_COLOR_MASK; + bits >>= COLUMN_RULE_COLOR_SHIFT; + + /* 2bits: tt : type */ + return (bits & 0x3); +} +static inline uint8_t get_column_rule_color(const css_computed_style *style, + css_color *color) +{ + uint32_t bits = style->i.bits[COLUMN_RULE_COLOR_INDEX]; + bits &= COLUMN_RULE_COLOR_MASK; + bits >>= COLUMN_RULE_COLOR_SHIFT; + + /* 2bits: tt : type */ + *color = style->i.column_rule_color; + + return (bits & 0x3); +} +#undef COLUMN_RULE_COLOR_INDEX +#undef COLUMN_RULE_COLOR_SHIFT +#undef COLUMN_RULE_COLOR_MASK + +#define COLUMN_RULE_STYLE_INDEX 7 +#define COLUMN_RULE_STYLE_SHIFT 0 +#define COLUMN_RULE_STYLE_MASK 0xf +static inline uint8_t get_column_rule_style_bits(const css_computed_style + *style) +{ + uint32_t bits = style->i.bits[COLUMN_RULE_STYLE_INDEX]; + bits &= COLUMN_RULE_STYLE_MASK; + bits >>= COLUMN_RULE_STYLE_SHIFT; + + /* 4bits: tttt : type */ + return (bits & 0xf); +} +static inline uint8_t get_column_rule_style(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[COLUMN_RULE_STYLE_INDEX]; + bits &= COLUMN_RULE_STYLE_MASK; + bits >>= COLUMN_RULE_STYLE_SHIFT; + + /* 4bits: tttt : type */ + + return (bits & 0xf); +} +#undef COLUMN_RULE_STYLE_INDEX +#undef COLUMN_RULE_STYLE_SHIFT +#undef COLUMN_RULE_STYLE_MASK + +#define COLUMN_RULE_WIDTH_INDEX 1 +#define COLUMN_RULE_WIDTH_SHIFT 7 +#define COLUMN_RULE_WIDTH_MASK 0x7f80 +static inline uint8_t get_column_rule_width_bits(const css_computed_style + *style) +{ + uint32_t bits = style->i.bits[COLUMN_RULE_WIDTH_INDEX]; + bits &= COLUMN_RULE_WIDTH_MASK; + bits >>= COLUMN_RULE_WIDTH_SHIFT; + + /* 8bits: uuuuuttt : unit | type */ + return (bits & 0x7); +} +static inline uint8_t get_column_rule_width(const css_computed_style *style, + css_fixed *length, css_unit *unit) +{ + uint32_t bits = style->i.bits[COLUMN_RULE_WIDTH_INDEX]; + bits &= COLUMN_RULE_WIDTH_MASK; + bits >>= COLUMN_RULE_WIDTH_SHIFT; + + /* 8bits: uuuuuttt : unit | type */ + if ((bits & 0x7) == CSS_COLUMN_RULE_WIDTH_WIDTH) { + *length = style->i.column_rule_width; + *unit = bits >> 3; + } + + return (bits & 0x7); +} +#undef COLUMN_RULE_WIDTH_INDEX +#undef COLUMN_RULE_WIDTH_SHIFT +#undef COLUMN_RULE_WIDTH_MASK + +#define COLUMN_SPAN_INDEX 11 +#define COLUMN_SPAN_SHIFT 20 +#define COLUMN_SPAN_MASK 0x300000 +static inline uint8_t get_column_span_bits(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[COLUMN_SPAN_INDEX]; + bits &= COLUMN_SPAN_MASK; + bits >>= COLUMN_SPAN_SHIFT; + + /* 2bits: tt : type */ + return (bits & 0x3); +} +static inline uint8_t get_column_span(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[COLUMN_SPAN_INDEX]; + bits &= COLUMN_SPAN_MASK; + bits >>= COLUMN_SPAN_SHIFT; + + /* 2bits: tt : type */ + + return (bits & 0x3); +} +#undef COLUMN_SPAN_INDEX +#undef COLUMN_SPAN_SHIFT +#undef COLUMN_SPAN_MASK + +#define COLUMN_WIDTH_INDEX 3 +#define COLUMN_WIDTH_SHIFT 25 +#define COLUMN_WIDTH_MASK 0xfe000000 +static inline uint8_t get_column_width_bits(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[COLUMN_WIDTH_INDEX]; + bits &= COLUMN_WIDTH_MASK; + bits >>= COLUMN_WIDTH_SHIFT; + + /* 7bits: uuuuutt : unit | type */ + return (bits & 0x3); +} +static inline uint8_t get_column_width(const css_computed_style *style, + css_fixed *length, css_unit *unit) +{ + uint32_t bits = style->i.bits[COLUMN_WIDTH_INDEX]; + bits &= COLUMN_WIDTH_MASK; + bits >>= COLUMN_WIDTH_SHIFT; + + /* 7bits: uuuuutt : unit | type */ + if ((bits & 0x3) == CSS_COLUMN_WIDTH_SET) { + *length = style->i.column_width; + *unit = bits >> 2; + } + + return (bits & 0x3); +} +#undef COLUMN_WIDTH_INDEX +#undef COLUMN_WIDTH_SHIFT +#undef COLUMN_WIDTH_MASK + +#define CONTENT_INDEX 11 +#define CONTENT_SHIFT 22 +#define CONTENT_MASK 0xc00000 +static inline uint8_t get_content_bits(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[CONTENT_INDEX]; + bits &= CONTENT_MASK; + bits >>= CONTENT_SHIFT; + + /* 2bits: tt : type */ + return (bits & 0x3); +} +static inline uint8_t get_content(const css_computed_style *style, const + css_computed_content_item **content_item) +{ + uint32_t bits = style->i.bits[CONTENT_INDEX]; + bits &= CONTENT_MASK; + bits >>= CONTENT_SHIFT; + + /* 2bits: tt : type */ + if ((bits & 0x3) == CSS_CONTENT_SET) { + *content_item = style->content; + } + + return (bits & 0x3); +} +#undef CONTENT_INDEX +#undef CONTENT_SHIFT +#undef CONTENT_MASK + +#define COUNTER_INCREMENT_INDEX 14 +#define COUNTER_INCREMENT_SHIFT 18 +#define COUNTER_INCREMENT_MASK 0x40000 +static inline uint8_t get_counter_increment_bits(const css_computed_style + *style) +{ + uint32_t bits = style->i.bits[COUNTER_INCREMENT_INDEX]; + bits &= COUNTER_INCREMENT_MASK; + bits >>= COUNTER_INCREMENT_SHIFT; + + /* 1bit: t : type */ + return (bits & 0x1); +} +static inline uint8_t get_counter_increment(const css_computed_style *style, + const css_computed_counter **counter_arr) +{ + uint32_t bits = style->i.bits[COUNTER_INCREMENT_INDEX]; + bits &= COUNTER_INCREMENT_MASK; + bits >>= COUNTER_INCREMENT_SHIFT; + + /* 1bit: t : type */ + *counter_arr = style->counter_increment; + + return (bits & 0x1); +} +#undef COUNTER_INCREMENT_INDEX +#undef COUNTER_INCREMENT_SHIFT +#undef COUNTER_INCREMENT_MASK + +#define COUNTER_RESET_INDEX 14 +#define COUNTER_RESET_SHIFT 19 +#define COUNTER_RESET_MASK 0x80000 +static inline uint8_t get_counter_reset_bits(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[COUNTER_RESET_INDEX]; + bits &= COUNTER_RESET_MASK; + bits >>= COUNTER_RESET_SHIFT; + + /* 1bit: t : type */ + return (bits & 0x1); +} +static inline uint8_t get_counter_reset(const css_computed_style *style, const + css_computed_counter **counter_arr) +{ + uint32_t bits = style->i.bits[COUNTER_RESET_INDEX]; + bits &= COUNTER_RESET_MASK; + bits >>= COUNTER_RESET_SHIFT; + + /* 1bit: t : type */ + *counter_arr = style->counter_reset; + + return (bits & 0x1); +} +#undef COUNTER_RESET_INDEX +#undef COUNTER_RESET_SHIFT +#undef COUNTER_RESET_MASK + +#define CURSOR_INDEX 9 +#define CURSOR_SHIFT 27 +#define CURSOR_MASK 0xf8000000 +static inline uint8_t get_cursor_bits(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[CURSOR_INDEX]; + bits &= CURSOR_MASK; + bits >>= CURSOR_SHIFT; + + /* 5bits: ttttt : type */ + return (bits & 0x1f); +} +static inline uint8_t get_cursor(const css_computed_style *style, lwc_string + ***string_arr) +{ + uint32_t bits = style->i.bits[CURSOR_INDEX]; + bits &= CURSOR_MASK; + bits >>= CURSOR_SHIFT; + + /* 5bits: ttttt : type */ + *string_arr = style->cursor; + + return (bits & 0x1f); +} +#undef CURSOR_INDEX +#undef CURSOR_SHIFT +#undef CURSOR_MASK + +#define DIRECTION_INDEX 11 +#define DIRECTION_SHIFT 24 +#define DIRECTION_MASK 0x3000000 +static inline uint8_t get_direction_bits(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[DIRECTION_INDEX]; + bits &= DIRECTION_MASK; + bits >>= DIRECTION_SHIFT; + + /* 2bits: tt : type */ + return (bits & 0x3); +} +static inline uint8_t get_direction(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[DIRECTION_INDEX]; + bits &= DIRECTION_MASK; + bits >>= DIRECTION_SHIFT; + + /* 2bits: tt : type */ + + return (bits & 0x3); +} +#undef DIRECTION_INDEX +#undef DIRECTION_SHIFT +#undef DIRECTION_MASK + +#define DISPLAY_INDEX 8 +#define DISPLAY_SHIFT 3 +#define DISPLAY_MASK 0xf8 +static inline uint8_t get_display_bits(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[DISPLAY_INDEX]; + bits &= DISPLAY_MASK; + bits >>= DISPLAY_SHIFT; + + /* 5bits: ttttt : type */ + return (bits & 0x1f); +} +static inline uint8_t get_display(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[DISPLAY_INDEX]; + bits &= DISPLAY_MASK; + bits >>= DISPLAY_SHIFT; + + /* 5bits: ttttt : type */ + + return (bits & 0x1f); +} +#undef DISPLAY_INDEX +#undef DISPLAY_SHIFT +#undef DISPLAY_MASK + +#define EMPTY_CELLS_INDEX 11 +#define EMPTY_CELLS_SHIFT 26 +#define EMPTY_CELLS_MASK 0xc000000 +static inline uint8_t get_empty_cells_bits(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[EMPTY_CELLS_INDEX]; + bits &= EMPTY_CELLS_MASK; + bits >>= EMPTY_CELLS_SHIFT; + + /* 2bits: tt : type */ + return (bits & 0x3); +} +static inline uint8_t get_empty_cells(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[EMPTY_CELLS_INDEX]; + bits &= EMPTY_CELLS_MASK; + bits >>= EMPTY_CELLS_SHIFT; + + /* 2bits: tt : type */ + + return (bits & 0x3); +} +#undef EMPTY_CELLS_INDEX +#undef EMPTY_CELLS_SHIFT +#undef EMPTY_CELLS_MASK + +#define FILL_OPACITY_INDEX 14 +#define FILL_OPACITY_SHIFT 20 +#define FILL_OPACITY_MASK 0x100000 +static inline uint8_t get_fill_opacity_bits(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[FILL_OPACITY_INDEX]; + bits &= FILL_OPACITY_MASK; + bits >>= FILL_OPACITY_SHIFT; + + /* 1bit: t : type */ + return (bits & 0x1); +} +static inline uint8_t get_fill_opacity(const css_computed_style *style, + css_fixed *fixed) +{ + uint32_t bits = style->i.bits[FILL_OPACITY_INDEX]; + bits &= FILL_OPACITY_MASK; + bits >>= FILL_OPACITY_SHIFT; + + /* 1bit: t : type */ + if ((bits & 0x1) == CSS_FILL_OPACITY_SET) { + *fixed = style->i.fill_opacity; + } + + return (bits & 0x1); +} +#undef FILL_OPACITY_INDEX +#undef FILL_OPACITY_SHIFT +#undef FILL_OPACITY_MASK + +#define FLEX_BASIS_INDEX 7 +#define FLEX_BASIS_SHIFT 4 +#define FLEX_BASIS_MASK 0x7f0 +static inline uint8_t get_flex_basis_bits(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[FLEX_BASIS_INDEX]; + bits &= FLEX_BASIS_MASK; + bits >>= FLEX_BASIS_SHIFT; + + /* 7bits: uuuuutt : unit | type */ + return (bits & 0x3); +} +static inline uint8_t get_flex_basis(const css_computed_style *style, css_fixed + *length, css_unit *unit) +{ + uint32_t bits = style->i.bits[FLEX_BASIS_INDEX]; + bits &= FLEX_BASIS_MASK; + bits >>= FLEX_BASIS_SHIFT; + + /* 7bits: uuuuutt : unit | type */ + if ((bits & 0x3) == CSS_FLEX_BASIS_SET) { + *length = style->i.flex_basis; + *unit = bits >> 2; + } + + return (bits & 0x3); +} +#undef FLEX_BASIS_INDEX +#undef FLEX_BASIS_SHIFT +#undef FLEX_BASIS_MASK + +#define FLEX_DIRECTION_INDEX 13 +#define FLEX_DIRECTION_SHIFT 4 +#define FLEX_DIRECTION_MASK 0x70 +static inline uint8_t get_flex_direction_bits(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[FLEX_DIRECTION_INDEX]; + bits &= FLEX_DIRECTION_MASK; + bits >>= FLEX_DIRECTION_SHIFT; + + /* 3bits: ttt : type */ + return (bits & 0x7); +} +static inline uint8_t get_flex_direction(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[FLEX_DIRECTION_INDEX]; + bits &= FLEX_DIRECTION_MASK; + bits >>= FLEX_DIRECTION_SHIFT; + + /* 3bits: ttt : type */ + + return (bits & 0x7); +} +#undef FLEX_DIRECTION_INDEX +#undef FLEX_DIRECTION_SHIFT +#undef FLEX_DIRECTION_MASK + +#define FLEX_GROW_INDEX 14 +#define FLEX_GROW_SHIFT 21 +#define FLEX_GROW_MASK 0x200000 +static inline uint8_t get_flex_grow_bits(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[FLEX_GROW_INDEX]; + bits &= FLEX_GROW_MASK; + bits >>= FLEX_GROW_SHIFT; + + /* 1bit: t : type */ + return (bits & 0x1); +} +static inline uint8_t get_flex_grow(const css_computed_style *style, css_fixed + *fixed) +{ + uint32_t bits = style->i.bits[FLEX_GROW_INDEX]; + bits &= FLEX_GROW_MASK; + bits >>= FLEX_GROW_SHIFT; + + /* 1bit: t : type */ + if ((bits & 0x1) == CSS_FLEX_GROW_SET) { + *fixed = style->i.flex_grow; + } + + return (bits & 0x1); +} +#undef FLEX_GROW_INDEX +#undef FLEX_GROW_SHIFT +#undef FLEX_GROW_MASK + +#define FLEX_SHRINK_INDEX 14 +#define FLEX_SHRINK_SHIFT 22 +#define FLEX_SHRINK_MASK 0x400000 +static inline uint8_t get_flex_shrink_bits(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[FLEX_SHRINK_INDEX]; + bits &= FLEX_SHRINK_MASK; + bits >>= FLEX_SHRINK_SHIFT; + + /* 1bit: t : type */ + return (bits & 0x1); +} +static inline uint8_t get_flex_shrink(const css_computed_style *style, + css_fixed *fixed) +{ + uint32_t bits = style->i.bits[FLEX_SHRINK_INDEX]; + bits &= FLEX_SHRINK_MASK; + bits >>= FLEX_SHRINK_SHIFT; + + /* 1bit: t : type */ + if ((bits & 0x1) == CSS_FLEX_SHRINK_SET) { + *fixed = style->i.flex_shrink; + } + + return (bits & 0x1); +} +#undef FLEX_SHRINK_INDEX +#undef FLEX_SHRINK_SHIFT +#undef FLEX_SHRINK_MASK + +#define FLEX_WRAP_INDEX 11 +#define FLEX_WRAP_SHIFT 28 +#define FLEX_WRAP_MASK 0x30000000 +static inline uint8_t get_flex_wrap_bits(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[FLEX_WRAP_INDEX]; + bits &= FLEX_WRAP_MASK; + bits >>= FLEX_WRAP_SHIFT; + + /* 2bits: tt : type */ + return (bits & 0x3); +} +static inline uint8_t get_flex_wrap(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[FLEX_WRAP_INDEX]; + bits &= FLEX_WRAP_MASK; + bits >>= FLEX_WRAP_SHIFT; + + /* 2bits: tt : type */ + + return (bits & 0x3); +} +#undef FLEX_WRAP_INDEX +#undef FLEX_WRAP_SHIFT +#undef FLEX_WRAP_MASK + +#define FLOAT_INDEX 11 +#define FLOAT_SHIFT 30 +#define FLOAT_MASK 0xc0000000 +static inline uint8_t get_float_bits(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[FLOAT_INDEX]; + bits &= FLOAT_MASK; + bits >>= FLOAT_SHIFT; + + /* 2bits: tt : type */ + return (bits & 0x3); +} +static inline uint8_t get_float(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[FLOAT_INDEX]; + bits &= FLOAT_MASK; + bits >>= FLOAT_SHIFT; + + /* 2bits: tt : type */ + + return (bits & 0x3); +} +#undef FLOAT_INDEX +#undef FLOAT_SHIFT +#undef FLOAT_MASK + +#define FONT_FAMILY_INDEX 13 +#define FONT_FAMILY_SHIFT 7 +#define FONT_FAMILY_MASK 0x380 +static inline uint8_t get_font_family_bits(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[FONT_FAMILY_INDEX]; + bits &= FONT_FAMILY_MASK; + bits >>= FONT_FAMILY_SHIFT; + + /* 3bits: ttt : type */ + return (bits & 0x7); +} +static inline uint8_t get_font_family(const css_computed_style *style, + lwc_string ***string_arr) +{ + uint32_t bits = style->i.bits[FONT_FAMILY_INDEX]; + bits &= FONT_FAMILY_MASK; + bits >>= FONT_FAMILY_SHIFT; + + /* 3bits: ttt : type */ + *string_arr = style->font_family; + + return (bits & 0x7); +} +#undef FONT_FAMILY_INDEX +#undef FONT_FAMILY_SHIFT +#undef FONT_FAMILY_MASK + +#define FONT_SIZE_INDEX 1 +#define FONT_SIZE_SHIFT 23 +#define FONT_SIZE_MASK 0xff800000 +static inline uint8_t get_font_size_bits(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[FONT_SIZE_INDEX]; + bits &= FONT_SIZE_MASK; + bits >>= FONT_SIZE_SHIFT; + + /* 9bits: uuuuutttt : unit | type */ + return (bits & 0xf); +} +static inline uint8_t get_font_size(const css_computed_style *style, css_fixed + *length, css_unit *unit) +{ + uint32_t bits = style->i.bits[FONT_SIZE_INDEX]; + bits &= FONT_SIZE_MASK; + bits >>= FONT_SIZE_SHIFT; + + /* 9bits: uuuuutttt : unit | type */ + if ((bits & 0xf) == CSS_FONT_SIZE_DIMENSION) { + *length = style->i.font_size; + *unit = bits >> 4; + } + + return (bits & 0xf); +} +#undef FONT_SIZE_INDEX +#undef FONT_SIZE_SHIFT +#undef FONT_SIZE_MASK + +#define FONT_STYLE_INDEX 10 +#define FONT_STYLE_SHIFT 0 +#define FONT_STYLE_MASK 0x3 +static inline uint8_t get_font_style_bits(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[FONT_STYLE_INDEX]; + bits &= FONT_STYLE_MASK; + bits >>= FONT_STYLE_SHIFT; + + /* 2bits: tt : type */ + return (bits & 0x3); +} +static inline uint8_t get_font_style(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[FONT_STYLE_INDEX]; + bits &= FONT_STYLE_MASK; + bits >>= FONT_STYLE_SHIFT; + + /* 2bits: tt : type */ + + return (bits & 0x3); +} +#undef FONT_STYLE_INDEX +#undef FONT_STYLE_SHIFT +#undef FONT_STYLE_MASK + +#define FONT_VARIANT_INDEX 10 +#define FONT_VARIANT_SHIFT 2 +#define FONT_VARIANT_MASK 0xc +static inline uint8_t get_font_variant_bits(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[FONT_VARIANT_INDEX]; + bits &= FONT_VARIANT_MASK; + bits >>= FONT_VARIANT_SHIFT; + + /* 2bits: tt : type */ + return (bits & 0x3); +} +static inline uint8_t get_font_variant(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[FONT_VARIANT_INDEX]; + bits &= FONT_VARIANT_MASK; + bits >>= FONT_VARIANT_SHIFT; + + /* 2bits: tt : type */ + + return (bits & 0x3); +} +#undef FONT_VARIANT_INDEX +#undef FONT_VARIANT_SHIFT +#undef FONT_VARIANT_MASK + +#define FONT_WEIGHT_INDEX 6 +#define FONT_WEIGHT_SHIFT 0 +#define FONT_WEIGHT_MASK 0xf +static inline uint8_t get_font_weight_bits(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[FONT_WEIGHT_INDEX]; + bits &= FONT_WEIGHT_MASK; + bits >>= FONT_WEIGHT_SHIFT; + + /* 4bits: tttt : type */ + return (bits & 0xf); +} +static inline uint8_t get_font_weight(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[FONT_WEIGHT_INDEX]; + bits &= FONT_WEIGHT_MASK; + bits >>= FONT_WEIGHT_SHIFT; + + /* 4bits: tttt : type */ + + return (bits & 0xf); +} +#undef FONT_WEIGHT_INDEX +#undef FONT_WEIGHT_SHIFT +#undef FONT_WEIGHT_MASK + +#define HEIGHT_INDEX 7 +#define HEIGHT_SHIFT 11 +#define HEIGHT_MASK 0x3f800 +static inline uint8_t get_height_bits(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[HEIGHT_INDEX]; + bits &= HEIGHT_MASK; + bits >>= HEIGHT_SHIFT; + + /* 7bits: uuuuutt : unit | type */ + return (bits & 0x3); +} +static inline uint8_t get_height(const css_computed_style *style, css_fixed + *length, css_unit *unit) +{ + uint32_t bits = style->i.bits[HEIGHT_INDEX]; + bits &= HEIGHT_MASK; + bits >>= HEIGHT_SHIFT; + + /* 7bits: uuuuutt : unit | type */ + if ((bits & 0x3) == CSS_HEIGHT_SET) { + *length = style->i.height; + *unit = bits >> 2; + } + + return (bits & 0x3); +} +#undef HEIGHT_INDEX +#undef HEIGHT_SHIFT +#undef HEIGHT_MASK + +#define JUSTIFY_CONTENT_INDEX 13 +#define JUSTIFY_CONTENT_SHIFT 10 +#define JUSTIFY_CONTENT_MASK 0x1c00 +static inline uint8_t get_justify_content_bits(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[JUSTIFY_CONTENT_INDEX]; + bits &= JUSTIFY_CONTENT_MASK; + bits >>= JUSTIFY_CONTENT_SHIFT; + + /* 3bits: ttt : type */ + return (bits & 0x7); +} +static inline uint8_t get_justify_content(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[JUSTIFY_CONTENT_INDEX]; + bits &= JUSTIFY_CONTENT_MASK; + bits >>= JUSTIFY_CONTENT_SHIFT; + + /* 3bits: ttt : type */ + + return (bits & 0x7); +} +#undef JUSTIFY_CONTENT_INDEX +#undef JUSTIFY_CONTENT_SHIFT +#undef JUSTIFY_CONTENT_MASK + +#define LEFT_INDEX 7 +#define LEFT_SHIFT 18 +#define LEFT_MASK 0x1fc0000 +static inline uint8_t get_left_bits(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[LEFT_INDEX]; + bits &= LEFT_MASK; + bits >>= LEFT_SHIFT; + + /* 7bits: uuuuutt : unit | type */ + return (bits & 0x3); +} +static inline uint8_t get_left(const css_computed_style *style, css_fixed + *length, css_unit *unit) +{ + uint32_t bits = style->i.bits[LEFT_INDEX]; + bits &= LEFT_MASK; + bits >>= LEFT_SHIFT; + + /* 7bits: uuuuutt : unit | type */ + if ((bits & 0x3) == CSS_LEFT_SET) { + *length = style->i.left; + *unit = bits >> 2; + } + + return (bits & 0x3); +} +#undef LEFT_INDEX +#undef LEFT_SHIFT +#undef LEFT_MASK + +#define LETTER_SPACING_INDEX 7 +#define LETTER_SPACING_SHIFT 25 +#define LETTER_SPACING_MASK 0xfe000000 +static inline uint8_t get_letter_spacing_bits(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[LETTER_SPACING_INDEX]; + bits &= LETTER_SPACING_MASK; + bits >>= LETTER_SPACING_SHIFT; + + /* 7bits: uuuuutt : unit | type */ + return (bits & 0x3); +} +static inline uint8_t get_letter_spacing(const css_computed_style *style, + css_fixed *length, css_unit *unit) +{ + uint32_t bits = style->i.bits[LETTER_SPACING_INDEX]; + bits &= LETTER_SPACING_MASK; + bits >>= LETTER_SPACING_SHIFT; + + /* 7bits: uuuuutt : unit | type */ + if ((bits & 0x3) == CSS_LETTER_SPACING_SET) { + *length = style->i.letter_spacing; + *unit = bits >> 2; + } + + return (bits & 0x3); +} +#undef LETTER_SPACING_INDEX +#undef LETTER_SPACING_SHIFT +#undef LETTER_SPACING_MASK + +#define LINE_HEIGHT_INDEX 6 +#define LINE_HEIGHT_SHIFT 4 +#define LINE_HEIGHT_MASK 0x7f0 +static inline uint8_t get_line_height_bits(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[LINE_HEIGHT_INDEX]; + bits &= LINE_HEIGHT_MASK; + bits >>= LINE_HEIGHT_SHIFT; + + /* 7bits: uuuuutt : unit | type */ + return (bits & 0x3); +} +static inline uint8_t get_line_height( + const css_computed_style *style, + css_fixed *length, css_unit *unit) +{ + uint32_t bits = style->i.bits[LINE_HEIGHT_INDEX]; + bits &= LINE_HEIGHT_MASK; + bits >>= LINE_HEIGHT_SHIFT; + + /* 7bits: uuuuutt : units | type */ + if ((bits & 0x3) == CSS_LINE_HEIGHT_NUMBER || + (bits & 0x3) == CSS_LINE_HEIGHT_DIMENSION) { + *length = style->i.line_height; + } + + if ((bits & 0x3) == CSS_LINE_HEIGHT_DIMENSION) { + *unit = bits >> 2; + } + + return (bits & 0x3); +} +#undef LINE_HEIGHT_INDEX +#undef LINE_HEIGHT_SHIFT +#undef LINE_HEIGHT_MASK + +#define LIST_STYLE_IMAGE_INDEX 14 +#define LIST_STYLE_IMAGE_SHIFT 23 +#define LIST_STYLE_IMAGE_MASK 0x800000 +static inline uint8_t get_list_style_image_bits(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[LIST_STYLE_IMAGE_INDEX]; + bits &= LIST_STYLE_IMAGE_MASK; + bits >>= LIST_STYLE_IMAGE_SHIFT; + + /* 1bit: t : type */ + return (bits & 0x1); +} +static inline uint8_t get_list_style_image(const css_computed_style *style, + lwc_string **string) +{ + uint32_t bits = style->i.bits[LIST_STYLE_IMAGE_INDEX]; + bits &= LIST_STYLE_IMAGE_MASK; + bits >>= LIST_STYLE_IMAGE_SHIFT; + + /* 1bit: t : type */ + *string = style->i.list_style_image; + + return (bits & 0x1); +} +#undef LIST_STYLE_IMAGE_INDEX +#undef LIST_STYLE_IMAGE_SHIFT +#undef LIST_STYLE_IMAGE_MASK + +#define LIST_STYLE_POSITION_INDEX 10 +#define LIST_STYLE_POSITION_SHIFT 4 +#define LIST_STYLE_POSITION_MASK 0x30 +static inline uint8_t get_list_style_position_bits(const css_computed_style + *style) +{ + uint32_t bits = style->i.bits[LIST_STYLE_POSITION_INDEX]; + bits &= LIST_STYLE_POSITION_MASK; + bits >>= LIST_STYLE_POSITION_SHIFT; + + /* 2bits: tt : type */ + return (bits & 0x3); +} +static inline uint8_t get_list_style_position(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[LIST_STYLE_POSITION_INDEX]; + bits &= LIST_STYLE_POSITION_MASK; + bits >>= LIST_STYLE_POSITION_SHIFT; + + /* 2bits: tt : type */ + + return (bits & 0x3); +} +#undef LIST_STYLE_POSITION_INDEX +#undef LIST_STYLE_POSITION_SHIFT +#undef LIST_STYLE_POSITION_MASK + +#define LIST_STYLE_TYPE_INDEX 8 +#define LIST_STYLE_TYPE_SHIFT 8 +#define LIST_STYLE_TYPE_MASK 0x3f00 +static inline uint8_t get_list_style_type_bits(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[LIST_STYLE_TYPE_INDEX]; + bits &= LIST_STYLE_TYPE_MASK; + bits >>= LIST_STYLE_TYPE_SHIFT; + + /* 6bits: tttttt : type */ + return (bits & 0x3f); +} +static inline uint8_t get_list_style_type(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[LIST_STYLE_TYPE_INDEX]; + bits &= LIST_STYLE_TYPE_MASK; + bits >>= LIST_STYLE_TYPE_SHIFT; + + /* 6bits: tttttt : type */ + + return (bits & 0x3f); +} +#undef LIST_STYLE_TYPE_INDEX +#undef LIST_STYLE_TYPE_SHIFT +#undef LIST_STYLE_TYPE_MASK + +#define MARGIN_BOTTOM_INDEX 6 +#define MARGIN_BOTTOM_SHIFT 11 +#define MARGIN_BOTTOM_MASK 0x3f800 +static inline uint8_t get_margin_bottom_bits(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[MARGIN_BOTTOM_INDEX]; + bits &= MARGIN_BOTTOM_MASK; + bits >>= MARGIN_BOTTOM_SHIFT; + + /* 7bits: uuuuutt : unit | type */ + return (bits & 0x3); +} +static inline uint8_t get_margin_bottom(const css_computed_style *style, + css_fixed *length, css_unit *unit) +{ + uint32_t bits = style->i.bits[MARGIN_BOTTOM_INDEX]; + bits &= MARGIN_BOTTOM_MASK; + bits >>= MARGIN_BOTTOM_SHIFT; + + /* 7bits: uuuuutt : unit | type */ + if ((bits & 0x3) == CSS_MARGIN_SET) { + *length = style->i.margin_bottom; + *unit = bits >> 2; + } + + return (bits & 0x3); +} +#undef MARGIN_BOTTOM_INDEX +#undef MARGIN_BOTTOM_SHIFT +#undef MARGIN_BOTTOM_MASK + +#define MARGIN_LEFT_INDEX 6 +#define MARGIN_LEFT_SHIFT 18 +#define MARGIN_LEFT_MASK 0x1fc0000 +static inline uint8_t get_margin_left_bits(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[MARGIN_LEFT_INDEX]; + bits &= MARGIN_LEFT_MASK; + bits >>= MARGIN_LEFT_SHIFT; + + /* 7bits: uuuuutt : unit | type */ + return (bits & 0x3); +} +static inline uint8_t get_margin_left(const css_computed_style *style, + css_fixed *length, css_unit *unit) +{ + uint32_t bits = style->i.bits[MARGIN_LEFT_INDEX]; + bits &= MARGIN_LEFT_MASK; + bits >>= MARGIN_LEFT_SHIFT; + + /* 7bits: uuuuutt : unit | type */ + if ((bits & 0x3) == CSS_MARGIN_SET) { + *length = style->i.margin_left; + *unit = bits >> 2; + } + + return (bits & 0x3); +} +#undef MARGIN_LEFT_INDEX +#undef MARGIN_LEFT_SHIFT +#undef MARGIN_LEFT_MASK + +#define MARGIN_RIGHT_INDEX 6 +#define MARGIN_RIGHT_SHIFT 25 +#define MARGIN_RIGHT_MASK 0xfe000000 +static inline uint8_t get_margin_right_bits(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[MARGIN_RIGHT_INDEX]; + bits &= MARGIN_RIGHT_MASK; + bits >>= MARGIN_RIGHT_SHIFT; + + /* 7bits: uuuuutt : unit | type */ + return (bits & 0x3); +} +static inline uint8_t get_margin_right(const css_computed_style *style, + css_fixed *length, css_unit *unit) +{ + uint32_t bits = style->i.bits[MARGIN_RIGHT_INDEX]; + bits &= MARGIN_RIGHT_MASK; + bits >>= MARGIN_RIGHT_SHIFT; + + /* 7bits: uuuuutt : unit | type */ + if ((bits & 0x3) == CSS_MARGIN_SET) { + *length = style->i.margin_right; + *unit = bits >> 2; + } + + return (bits & 0x3); +} +#undef MARGIN_RIGHT_INDEX +#undef MARGIN_RIGHT_SHIFT +#undef MARGIN_RIGHT_MASK + +#define MARGIN_TOP_INDEX 5 +#define MARGIN_TOP_SHIFT 4 +#define MARGIN_TOP_MASK 0x7f0 +static inline uint8_t get_margin_top_bits(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[MARGIN_TOP_INDEX]; + bits &= MARGIN_TOP_MASK; + bits >>= MARGIN_TOP_SHIFT; + + /* 7bits: uuuuutt : unit | type */ + return (bits & 0x3); +} +static inline uint8_t get_margin_top(const css_computed_style *style, css_fixed + *length, css_unit *unit) +{ + uint32_t bits = style->i.bits[MARGIN_TOP_INDEX]; + bits &= MARGIN_TOP_MASK; + bits >>= MARGIN_TOP_SHIFT; + + /* 7bits: uuuuutt : unit | type */ + if ((bits & 0x3) == CSS_MARGIN_SET) { + *length = style->i.margin_top; + *unit = bits >> 2; + } + + return (bits & 0x3); +} +#undef MARGIN_TOP_INDEX +#undef MARGIN_TOP_SHIFT +#undef MARGIN_TOP_MASK + +#define MAX_HEIGHT_INDEX 5 +#define MAX_HEIGHT_SHIFT 11 +#define MAX_HEIGHT_MASK 0x3f800 +static inline uint8_t get_max_height_bits(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[MAX_HEIGHT_INDEX]; + bits &= MAX_HEIGHT_MASK; + bits >>= MAX_HEIGHT_SHIFT; + + /* 7bits: uuuuutt : unit | type */ + return (bits & 0x3); +} +static inline uint8_t get_max_height(const css_computed_style *style, css_fixed + *length, css_unit *unit) +{ + uint32_t bits = style->i.bits[MAX_HEIGHT_INDEX]; + bits &= MAX_HEIGHT_MASK; + bits >>= MAX_HEIGHT_SHIFT; + + /* 7bits: uuuuutt : unit | type */ + if ((bits & 0x3) == CSS_MAX_HEIGHT_SET) { + *length = style->i.max_height; + *unit = bits >> 2; + } + + return (bits & 0x3); +} +#undef MAX_HEIGHT_INDEX +#undef MAX_HEIGHT_SHIFT +#undef MAX_HEIGHT_MASK + +#define MAX_WIDTH_INDEX 5 +#define MAX_WIDTH_SHIFT 18 +#define MAX_WIDTH_MASK 0x1fc0000 +static inline uint8_t get_max_width_bits(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[MAX_WIDTH_INDEX]; + bits &= MAX_WIDTH_MASK; + bits >>= MAX_WIDTH_SHIFT; + + /* 7bits: uuuuutt : unit | type */ + return (bits & 0x3); +} +static inline uint8_t get_max_width(const css_computed_style *style, css_fixed + *length, css_unit *unit) +{ + uint32_t bits = style->i.bits[MAX_WIDTH_INDEX]; + bits &= MAX_WIDTH_MASK; + bits >>= MAX_WIDTH_SHIFT; + + /* 7bits: uuuuutt : unit | type */ + if ((bits & 0x3) == CSS_MAX_WIDTH_SET) { + *length = style->i.max_width; + *unit = bits >> 2; + } + + return (bits & 0x3); +} +#undef MAX_WIDTH_INDEX +#undef MAX_WIDTH_SHIFT +#undef MAX_WIDTH_MASK + +#define MIN_HEIGHT_INDEX 5 +#define MIN_HEIGHT_SHIFT 25 +#define MIN_HEIGHT_MASK 0xfe000000 +static inline uint8_t get_min_height_bits(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[MIN_HEIGHT_INDEX]; + bits &= MIN_HEIGHT_MASK; + bits >>= MIN_HEIGHT_SHIFT; + + /* 7bits: uuuuutt : unit | type */ + return (bits & 0x3); +} +static inline uint8_t get_min_height(const css_computed_style *style, css_fixed + *length, css_unit *unit) +{ + uint32_t bits = style->i.bits[MIN_HEIGHT_INDEX]; + bits &= MIN_HEIGHT_MASK; + bits >>= MIN_HEIGHT_SHIFT; + + /* 7bits: uuuuutt : unit | type */ + if ((bits & 0x3) == CSS_MIN_HEIGHT_SET) { + *length = style->i.min_height; + *unit = bits >> 2; + } + + return (bits & 0x3); +} +#undef MIN_HEIGHT_INDEX +#undef MIN_HEIGHT_SHIFT +#undef MIN_HEIGHT_MASK + +#define MIN_WIDTH_INDEX 4 +#define MIN_WIDTH_SHIFT 4 +#define MIN_WIDTH_MASK 0x7f0 +static inline uint8_t get_min_width_bits(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[MIN_WIDTH_INDEX]; + bits &= MIN_WIDTH_MASK; + bits >>= MIN_WIDTH_SHIFT; + + /* 7bits: uuuuutt : unit | type */ + return (bits & 0x3); +} +static inline uint8_t get_min_width(const css_computed_style *style, css_fixed + *length, css_unit *unit) +{ + uint32_t bits = style->i.bits[MIN_WIDTH_INDEX]; + bits &= MIN_WIDTH_MASK; + bits >>= MIN_WIDTH_SHIFT; + + /* 7bits: uuuuutt : unit | type */ + if ((bits & 0x3) == CSS_MIN_WIDTH_SET) { + *length = style->i.min_width; + *unit = bits >> 2; + } + + return (bits & 0x3); +} +#undef MIN_WIDTH_INDEX +#undef MIN_WIDTH_SHIFT +#undef MIN_WIDTH_MASK + +#define OPACITY_INDEX 14 +#define OPACITY_SHIFT 24 +#define OPACITY_MASK 0x1000000 +static inline uint8_t get_opacity_bits(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[OPACITY_INDEX]; + bits &= OPACITY_MASK; + bits >>= OPACITY_SHIFT; + + /* 1bit: t : type */ + return (bits & 0x1); +} +static inline uint8_t get_opacity(const css_computed_style *style, css_fixed + *fixed) +{ + uint32_t bits = style->i.bits[OPACITY_INDEX]; + bits &= OPACITY_MASK; + bits >>= OPACITY_SHIFT; + + /* 1bit: t : type */ + if ((bits & 0x1) == CSS_OPACITY_SET) { + *fixed = style->i.opacity; + } + + return (bits & 0x1); +} +#undef OPACITY_INDEX +#undef OPACITY_SHIFT +#undef OPACITY_MASK + +#define ORDER_INDEX 14 +#define ORDER_SHIFT 25 +#define ORDER_MASK 0x2000000 +static inline uint8_t get_order_bits(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[ORDER_INDEX]; + bits &= ORDER_MASK; + bits >>= ORDER_SHIFT; + + /* 1bit: t : type */ + return (bits & 0x1); +} +static inline uint8_t get_order(const css_computed_style *style, int32_t + *integer) +{ + uint32_t bits = style->i.bits[ORDER_INDEX]; + bits &= ORDER_MASK; + bits >>= ORDER_SHIFT; + + /* 1bit: t : type */ + if ((bits & 0x1) == CSS_ORDER_SET) { + *integer = style->i.order; + } + + return (bits & 0x1); +} +#undef ORDER_INDEX +#undef ORDER_SHIFT +#undef ORDER_MASK + +#define ORPHANS_INDEX 14 +#define ORPHANS_SHIFT 26 +#define ORPHANS_MASK 0x4000000 +static inline uint8_t get_orphans_bits(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[ORPHANS_INDEX]; + bits &= ORPHANS_MASK; + bits >>= ORPHANS_SHIFT; + + /* 1bit: t : type */ + return (bits & 0x1); +} +static inline uint8_t get_orphans(const css_computed_style *style, int32_t + *integer) +{ + uint32_t bits = style->i.bits[ORPHANS_INDEX]; + bits &= ORPHANS_MASK; + bits >>= ORPHANS_SHIFT; + + /* 1bit: t : type */ + *integer = style->i.orphans; + + return (bits & 0x1); +} +#undef ORPHANS_INDEX +#undef ORPHANS_SHIFT +#undef ORPHANS_MASK + +#define OUTLINE_COLOR_INDEX 10 +#define OUTLINE_COLOR_SHIFT 6 +#define OUTLINE_COLOR_MASK 0xc0 +static inline uint8_t get_outline_color_bits(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[OUTLINE_COLOR_INDEX]; + bits &= OUTLINE_COLOR_MASK; + bits >>= OUTLINE_COLOR_SHIFT; + + /* 2bits: tt : type */ + return (bits & 0x3); +} +static inline uint8_t get_outline_color(const css_computed_style *style, + css_color *color) +{ + uint32_t bits = style->i.bits[OUTLINE_COLOR_INDEX]; + bits &= OUTLINE_COLOR_MASK; + bits >>= OUTLINE_COLOR_SHIFT; + + /* 2bits: tt : type */ + if ((bits & 0x3) == CSS_OUTLINE_COLOR_COLOR) { + *color = style->i.outline_color; + } + + return (bits & 0x3); +} +#undef OUTLINE_COLOR_INDEX +#undef OUTLINE_COLOR_SHIFT +#undef OUTLINE_COLOR_MASK + +#define OUTLINE_STYLE_INDEX 5 +#define OUTLINE_STYLE_SHIFT 0 +#define OUTLINE_STYLE_MASK 0xf +static inline uint8_t get_outline_style_bits(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[OUTLINE_STYLE_INDEX]; + bits &= OUTLINE_STYLE_MASK; + bits >>= OUTLINE_STYLE_SHIFT; + + /* 4bits: tttt : type */ + return (bits & 0xf); +} +static inline uint8_t get_outline_style(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[OUTLINE_STYLE_INDEX]; + bits &= OUTLINE_STYLE_MASK; + bits >>= OUTLINE_STYLE_SHIFT; + + /* 4bits: tttt : type */ + + return (bits & 0xf); +} +#undef OUTLINE_STYLE_INDEX +#undef OUTLINE_STYLE_SHIFT +#undef OUTLINE_STYLE_MASK + +#define OUTLINE_WIDTH_INDEX 1 +#define OUTLINE_WIDTH_SHIFT 15 +#define OUTLINE_WIDTH_MASK 0x7f8000 +static inline uint8_t get_outline_width_bits(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[OUTLINE_WIDTH_INDEX]; + bits &= OUTLINE_WIDTH_MASK; + bits >>= OUTLINE_WIDTH_SHIFT; + + /* 8bits: uuuuuttt : unit | type */ + return (bits & 0x7); +} +static inline uint8_t get_outline_width(const css_computed_style *style, + css_fixed *length, css_unit *unit) +{ + uint32_t bits = style->i.bits[OUTLINE_WIDTH_INDEX]; + bits &= OUTLINE_WIDTH_MASK; + bits >>= OUTLINE_WIDTH_SHIFT; + + /* 8bits: uuuuuttt : unit | type */ + if ((bits & 0x7) == CSS_OUTLINE_WIDTH_WIDTH) { + *length = style->i.outline_width; + *unit = bits >> 3; + } + + return (bits & 0x7); +} +#undef OUTLINE_WIDTH_INDEX +#undef OUTLINE_WIDTH_SHIFT +#undef OUTLINE_WIDTH_MASK + +#define OVERFLOW_X_INDEX 13 +#define OVERFLOW_X_SHIFT 13 +#define OVERFLOW_X_MASK 0xe000 +static inline uint8_t get_overflow_x_bits(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[OVERFLOW_X_INDEX]; + bits &= OVERFLOW_X_MASK; + bits >>= OVERFLOW_X_SHIFT; + + /* 3bits: ttt : type */ + return (bits & 0x7); +} +static inline uint8_t get_overflow_x(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[OVERFLOW_X_INDEX]; + bits &= OVERFLOW_X_MASK; + bits >>= OVERFLOW_X_SHIFT; + + /* 3bits: ttt : type */ + + return (bits & 0x7); +} +#undef OVERFLOW_X_INDEX +#undef OVERFLOW_X_SHIFT +#undef OVERFLOW_X_MASK + +#define OVERFLOW_Y_INDEX 13 +#define OVERFLOW_Y_SHIFT 16 +#define OVERFLOW_Y_MASK 0x70000 +static inline uint8_t get_overflow_y_bits(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[OVERFLOW_Y_INDEX]; + bits &= OVERFLOW_Y_MASK; + bits >>= OVERFLOW_Y_SHIFT; + + /* 3bits: ttt : type */ + return (bits & 0x7); +} +static inline uint8_t get_overflow_y(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[OVERFLOW_Y_INDEX]; + bits &= OVERFLOW_Y_MASK; + bits >>= OVERFLOW_Y_SHIFT; + + /* 3bits: ttt : type */ + + return (bits & 0x7); +} +#undef OVERFLOW_Y_INDEX +#undef OVERFLOW_Y_SHIFT +#undef OVERFLOW_Y_MASK + +#define PADDING_BOTTOM_INDEX 8 +#define PADDING_BOTTOM_SHIFT 14 +#define PADDING_BOTTOM_MASK 0xfc000 +static inline uint8_t get_padding_bottom_bits(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[PADDING_BOTTOM_INDEX]; + bits &= PADDING_BOTTOM_MASK; + bits >>= PADDING_BOTTOM_SHIFT; + + /* 6bits: uuuuut : unit | type */ + return (bits & 0x1); +} +static inline uint8_t get_padding_bottom(const css_computed_style *style, + css_fixed *length, css_unit *unit) +{ + uint32_t bits = style->i.bits[PADDING_BOTTOM_INDEX]; + bits &= PADDING_BOTTOM_MASK; + bits >>= PADDING_BOTTOM_SHIFT; + + /* 6bits: uuuuut : unit | type */ + if ((bits & 0x1) == CSS_PADDING_SET) { + *length = style->i.padding_bottom; + *unit = bits >> 1; + } + + return (bits & 0x1); +} +#undef PADDING_BOTTOM_INDEX +#undef PADDING_BOTTOM_SHIFT +#undef PADDING_BOTTOM_MASK + +#define PADDING_LEFT_INDEX 8 +#define PADDING_LEFT_SHIFT 20 +#define PADDING_LEFT_MASK 0x3f00000 +static inline uint8_t get_padding_left_bits(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[PADDING_LEFT_INDEX]; + bits &= PADDING_LEFT_MASK; + bits >>= PADDING_LEFT_SHIFT; + + /* 6bits: uuuuut : unit | type */ + return (bits & 0x1); +} +static inline uint8_t get_padding_left(const css_computed_style *style, + css_fixed *length, css_unit *unit) +{ + uint32_t bits = style->i.bits[PADDING_LEFT_INDEX]; + bits &= PADDING_LEFT_MASK; + bits >>= PADDING_LEFT_SHIFT; + + /* 6bits: uuuuut : unit | type */ + if ((bits & 0x1) == CSS_PADDING_SET) { + *length = style->i.padding_left; + *unit = bits >> 1; + } + + return (bits & 0x1); +} +#undef PADDING_LEFT_INDEX +#undef PADDING_LEFT_SHIFT +#undef PADDING_LEFT_MASK + +#define PADDING_RIGHT_INDEX 8 +#define PADDING_RIGHT_SHIFT 26 +#define PADDING_RIGHT_MASK 0xfc000000 +static inline uint8_t get_padding_right_bits(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[PADDING_RIGHT_INDEX]; + bits &= PADDING_RIGHT_MASK; + bits >>= PADDING_RIGHT_SHIFT; + + /* 6bits: uuuuut : unit | type */ + return (bits & 0x1); +} +static inline uint8_t get_padding_right(const css_computed_style *style, + css_fixed *length, css_unit *unit) +{ + uint32_t bits = style->i.bits[PADDING_RIGHT_INDEX]; + bits &= PADDING_RIGHT_MASK; + bits >>= PADDING_RIGHT_SHIFT; + + /* 6bits: uuuuut : unit | type */ + if ((bits & 0x1) == CSS_PADDING_SET) { + *length = style->i.padding_right; + *unit = bits >> 1; + } + + return (bits & 0x1); +} +#undef PADDING_RIGHT_INDEX +#undef PADDING_RIGHT_SHIFT +#undef PADDING_RIGHT_MASK + +#define PADDING_TOP_INDEX 3 +#define PADDING_TOP_SHIFT 5 +#define PADDING_TOP_MASK 0x7e0 +static inline uint8_t get_padding_top_bits(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[PADDING_TOP_INDEX]; + bits &= PADDING_TOP_MASK; + bits >>= PADDING_TOP_SHIFT; + + /* 6bits: uuuuut : unit | type */ + return (bits & 0x1); +} +static inline uint8_t get_padding_top(const css_computed_style *style, + css_fixed *length, css_unit *unit) +{ + uint32_t bits = style->i.bits[PADDING_TOP_INDEX]; + bits &= PADDING_TOP_MASK; + bits >>= PADDING_TOP_SHIFT; + + /* 6bits: uuuuut : unit | type */ + if ((bits & 0x1) == CSS_PADDING_SET) { + *length = style->i.padding_top; + *unit = bits >> 1; + } + + return (bits & 0x1); +} +#undef PADDING_TOP_INDEX +#undef PADDING_TOP_SHIFT +#undef PADDING_TOP_MASK + +#define PAGE_BREAK_AFTER_INDEX 13 +#define PAGE_BREAK_AFTER_SHIFT 19 +#define PAGE_BREAK_AFTER_MASK 0x380000 +static inline uint8_t get_page_break_after_bits(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[PAGE_BREAK_AFTER_INDEX]; + bits &= PAGE_BREAK_AFTER_MASK; + bits >>= PAGE_BREAK_AFTER_SHIFT; + + /* 3bits: ttt : type */ + return (bits & 0x7); +} +static inline uint8_t get_page_break_after(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[PAGE_BREAK_AFTER_INDEX]; + bits &= PAGE_BREAK_AFTER_MASK; + bits >>= PAGE_BREAK_AFTER_SHIFT; + + /* 3bits: ttt : type */ + + return (bits & 0x7); +} +#undef PAGE_BREAK_AFTER_INDEX +#undef PAGE_BREAK_AFTER_SHIFT +#undef PAGE_BREAK_AFTER_MASK + +#define PAGE_BREAK_BEFORE_INDEX 13 +#define PAGE_BREAK_BEFORE_SHIFT 22 +#define PAGE_BREAK_BEFORE_MASK 0x1c00000 +static inline uint8_t get_page_break_before_bits(const css_computed_style + *style) +{ + uint32_t bits = style->i.bits[PAGE_BREAK_BEFORE_INDEX]; + bits &= PAGE_BREAK_BEFORE_MASK; + bits >>= PAGE_BREAK_BEFORE_SHIFT; + + /* 3bits: ttt : type */ + return (bits & 0x7); +} +static inline uint8_t get_page_break_before(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[PAGE_BREAK_BEFORE_INDEX]; + bits &= PAGE_BREAK_BEFORE_MASK; + bits >>= PAGE_BREAK_BEFORE_SHIFT; + + /* 3bits: ttt : type */ + + return (bits & 0x7); +} +#undef PAGE_BREAK_BEFORE_INDEX +#undef PAGE_BREAK_BEFORE_SHIFT +#undef PAGE_BREAK_BEFORE_MASK + +#define PAGE_BREAK_INSIDE_INDEX 10 +#define PAGE_BREAK_INSIDE_SHIFT 8 +#define PAGE_BREAK_INSIDE_MASK 0x300 +static inline uint8_t get_page_break_inside_bits(const css_computed_style + *style) +{ + uint32_t bits = style->i.bits[PAGE_BREAK_INSIDE_INDEX]; + bits &= PAGE_BREAK_INSIDE_MASK; + bits >>= PAGE_BREAK_INSIDE_SHIFT; + + /* 2bits: tt : type */ + return (bits & 0x3); +} +static inline uint8_t get_page_break_inside(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[PAGE_BREAK_INSIDE_INDEX]; + bits &= PAGE_BREAK_INSIDE_MASK; + bits >>= PAGE_BREAK_INSIDE_SHIFT; + + /* 2bits: tt : type */ + + return (bits & 0x3); +} +#undef PAGE_BREAK_INSIDE_INDEX +#undef PAGE_BREAK_INSIDE_SHIFT +#undef PAGE_BREAK_INSIDE_MASK + +#define POSITION_INDEX 13 +#define POSITION_SHIFT 25 +#define POSITION_MASK 0xe000000 +static inline uint8_t get_position_bits(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[POSITION_INDEX]; + bits &= POSITION_MASK; + bits >>= POSITION_SHIFT; + + /* 3bits: ttt : type */ + return (bits & 0x7); +} +static inline uint8_t get_position(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[POSITION_INDEX]; + bits &= POSITION_MASK; + bits >>= POSITION_SHIFT; + + /* 3bits: ttt : type */ + + return (bits & 0x7); +} +#undef POSITION_INDEX +#undef POSITION_SHIFT +#undef POSITION_MASK + +#define QUOTES_INDEX 14 +#define QUOTES_SHIFT 27 +#define QUOTES_MASK 0x8000000 +static inline uint8_t get_quotes_bits(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[QUOTES_INDEX]; + bits &= QUOTES_MASK; + bits >>= QUOTES_SHIFT; + + /* 1bit: t : type */ + return (bits & 0x1); +} +static inline uint8_t get_quotes(const css_computed_style *style, lwc_string + ***string_arr) +{ + uint32_t bits = style->i.bits[QUOTES_INDEX]; + bits &= QUOTES_MASK; + bits >>= QUOTES_SHIFT; + + /* 1bit: t : type */ + *string_arr = style->quotes; + + return (bits & 0x1); +} +#undef QUOTES_INDEX +#undef QUOTES_SHIFT +#undef QUOTES_MASK + +#define RIGHT_INDEX 4 +#define RIGHT_SHIFT 11 +#define RIGHT_MASK 0x3f800 +static inline uint8_t get_right_bits(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[RIGHT_INDEX]; + bits &= RIGHT_MASK; + bits >>= RIGHT_SHIFT; + + /* 7bits: uuuuutt : unit | type */ + return (bits & 0x3); +} +static inline uint8_t get_right(const css_computed_style *style, css_fixed + *length, css_unit *unit) +{ + uint32_t bits = style->i.bits[RIGHT_INDEX]; + bits &= RIGHT_MASK; + bits >>= RIGHT_SHIFT; + + /* 7bits: uuuuutt : unit | type */ + if ((bits & 0x3) == CSS_RIGHT_SET) { + *length = style->i.right; + *unit = bits >> 2; + } + + return (bits & 0x3); +} +#undef RIGHT_INDEX +#undef RIGHT_SHIFT +#undef RIGHT_MASK + +#define STROKE_OPACITY_INDEX 13 +#define STROKE_OPACITY_SHIFT 0 +#define STROKE_OPACITY_MASK 0x1 +static inline uint8_t get_stroke_opacity_bits(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[STROKE_OPACITY_INDEX]; + bits &= STROKE_OPACITY_MASK; + bits >>= STROKE_OPACITY_SHIFT; + + /* 1bit: t : type */ + return (bits & 0x1); +} +static inline uint8_t get_stroke_opacity(const css_computed_style *style, + css_fixed *fixed) +{ + uint32_t bits = style->i.bits[STROKE_OPACITY_INDEX]; + bits &= STROKE_OPACITY_MASK; + bits >>= STROKE_OPACITY_SHIFT; + + /* 1bit: t : type */ + if ((bits & 0x1) == CSS_STROKE_OPACITY_SET) { + *fixed = style->i.stroke_opacity; + } + + return (bits & 0x1); +} +#undef STROKE_OPACITY_INDEX +#undef STROKE_OPACITY_SHIFT +#undef STROKE_OPACITY_MASK + +#define TABLE_LAYOUT_INDEX 10 +#define TABLE_LAYOUT_SHIFT 10 +#define TABLE_LAYOUT_MASK 0xc00 +static inline uint8_t get_table_layout_bits(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[TABLE_LAYOUT_INDEX]; + bits &= TABLE_LAYOUT_MASK; + bits >>= TABLE_LAYOUT_SHIFT; + + /* 2bits: tt : type */ + return (bits & 0x3); +} +static inline uint8_t get_table_layout(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[TABLE_LAYOUT_INDEX]; + bits &= TABLE_LAYOUT_MASK; + bits >>= TABLE_LAYOUT_SHIFT; + + /* 2bits: tt : type */ + + return (bits & 0x3); +} +#undef TABLE_LAYOUT_INDEX +#undef TABLE_LAYOUT_SHIFT +#undef TABLE_LAYOUT_MASK + +#define TEXT_ALIGN_INDEX 4 +#define TEXT_ALIGN_SHIFT 0 +#define TEXT_ALIGN_MASK 0xf +static inline uint8_t get_text_align_bits(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[TEXT_ALIGN_INDEX]; + bits &= TEXT_ALIGN_MASK; + bits >>= TEXT_ALIGN_SHIFT; + + /* 4bits: tttt : type */ + return (bits & 0xf); +} +static inline uint8_t get_text_align(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[TEXT_ALIGN_INDEX]; + bits &= TEXT_ALIGN_MASK; + bits >>= TEXT_ALIGN_SHIFT; + + /* 4bits: tttt : type */ + + return (bits & 0xf); +} +#undef TEXT_ALIGN_INDEX +#undef TEXT_ALIGN_SHIFT +#undef TEXT_ALIGN_MASK + +#define TEXT_DECORATION_INDEX 3 +#define TEXT_DECORATION_SHIFT 0 +#define TEXT_DECORATION_MASK 0x1f +static inline uint8_t get_text_decoration_bits(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[TEXT_DECORATION_INDEX]; + bits &= TEXT_DECORATION_MASK; + bits >>= TEXT_DECORATION_SHIFT; + + /* 5bits: ttttt : type */ + return (bits & 0x1f); +} +static inline uint8_t get_text_decoration(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[TEXT_DECORATION_INDEX]; + bits &= TEXT_DECORATION_MASK; + bits >>= TEXT_DECORATION_SHIFT; + + /* 5bits: ttttt : type */ + + return (bits & 0x1f); +} +#undef TEXT_DECORATION_INDEX +#undef TEXT_DECORATION_SHIFT +#undef TEXT_DECORATION_MASK + +#define TEXT_INDENT_INDEX 2 +#define TEXT_INDENT_SHIFT 0 +#define TEXT_INDENT_MASK 0x3f +static inline uint8_t get_text_indent_bits(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[TEXT_INDENT_INDEX]; + bits &= TEXT_INDENT_MASK; + bits >>= TEXT_INDENT_SHIFT; + + /* 6bits: uuuuut : unit | type */ + return (bits & 0x1); +} +static inline uint8_t get_text_indent(const css_computed_style *style, + css_fixed *length, css_unit *unit) +{ + uint32_t bits = style->i.bits[TEXT_INDENT_INDEX]; + bits &= TEXT_INDENT_MASK; + bits >>= TEXT_INDENT_SHIFT; + + /* 6bits: uuuuut : unit | type */ + if ((bits & 0x1) == CSS_TEXT_INDENT_SET) { + *length = style->i.text_indent; + *unit = bits >> 1; + } + + return (bits & 0x1); +} +#undef TEXT_INDENT_INDEX +#undef TEXT_INDENT_SHIFT +#undef TEXT_INDENT_MASK + +#define TEXT_TRANSFORM_INDEX 9 +#define TEXT_TRANSFORM_SHIFT 0 +#define TEXT_TRANSFORM_MASK 0x7 +static inline uint8_t get_text_transform_bits(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[TEXT_TRANSFORM_INDEX]; + bits &= TEXT_TRANSFORM_MASK; + bits >>= TEXT_TRANSFORM_SHIFT; + + /* 3bits: ttt : type */ + return (bits & 0x7); +} +static inline uint8_t get_text_transform(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[TEXT_TRANSFORM_INDEX]; + bits &= TEXT_TRANSFORM_MASK; + bits >>= TEXT_TRANSFORM_SHIFT; + + /* 3bits: ttt : type */ + + return (bits & 0x7); +} +#undef TEXT_TRANSFORM_INDEX +#undef TEXT_TRANSFORM_SHIFT +#undef TEXT_TRANSFORM_MASK + +#define TOP_INDEX 4 +#define TOP_SHIFT 18 +#define TOP_MASK 0x1fc0000 +static inline uint8_t get_top_bits(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[TOP_INDEX]; + bits &= TOP_MASK; + bits >>= TOP_SHIFT; + + /* 7bits: uuuuutt : unit | type */ + return (bits & 0x3); +} +static inline uint8_t get_top(const css_computed_style *style, css_fixed + *length, css_unit *unit) +{ + uint32_t bits = style->i.bits[TOP_INDEX]; + bits &= TOP_MASK; + bits >>= TOP_SHIFT; + + /* 7bits: uuuuutt : unit | type */ + if ((bits & 0x3) == CSS_TOP_SET) { + *length = style->i.top; + *unit = bits >> 2; + } + + return (bits & 0x3); +} +#undef TOP_INDEX +#undef TOP_SHIFT +#undef TOP_MASK + +#define UNICODE_BIDI_INDEX 10 +#define UNICODE_BIDI_SHIFT 12 +#define UNICODE_BIDI_MASK 0x3000 +static inline uint8_t get_unicode_bidi_bits(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[UNICODE_BIDI_INDEX]; + bits &= UNICODE_BIDI_MASK; + bits >>= UNICODE_BIDI_SHIFT; + + /* 2bits: tt : type */ + return (bits & 0x3); +} +static inline uint8_t get_unicode_bidi(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[UNICODE_BIDI_INDEX]; + bits &= UNICODE_BIDI_MASK; + bits >>= UNICODE_BIDI_SHIFT; + + /* 2bits: tt : type */ + + return (bits & 0x3); +} +#undef UNICODE_BIDI_INDEX +#undef UNICODE_BIDI_SHIFT +#undef UNICODE_BIDI_MASK + +#define VERTICAL_ALIGN_INDEX 12 +#define VERTICAL_ALIGN_SHIFT 1 +#define VERTICAL_ALIGN_MASK 0x3fe +static inline uint8_t get_vertical_align_bits(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[VERTICAL_ALIGN_INDEX]; + bits &= VERTICAL_ALIGN_MASK; + bits >>= VERTICAL_ALIGN_SHIFT; + + /* 9bits: uuuuutttt : unit | type */ + return (bits & 0xf); +} +static inline uint8_t get_vertical_align(const css_computed_style *style, + css_fixed *length, css_unit *unit) +{ + uint32_t bits = style->i.bits[VERTICAL_ALIGN_INDEX]; + bits &= VERTICAL_ALIGN_MASK; + bits >>= VERTICAL_ALIGN_SHIFT; + + /* 9bits: uuuuutttt : unit | type */ + if ((bits & 0xf) == CSS_VERTICAL_ALIGN_SET) { + *length = style->i.vertical_align; + *unit = bits >> 4; + } + + return (bits & 0xf); +} +#undef VERTICAL_ALIGN_INDEX +#undef VERTICAL_ALIGN_SHIFT +#undef VERTICAL_ALIGN_MASK + +#define VISIBILITY_INDEX 10 +#define VISIBILITY_SHIFT 14 +#define VISIBILITY_MASK 0xc000 +static inline uint8_t get_visibility_bits(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[VISIBILITY_INDEX]; + bits &= VISIBILITY_MASK; + bits >>= VISIBILITY_SHIFT; + + /* 2bits: tt : type */ + return (bits & 0x3); +} +static inline uint8_t get_visibility(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[VISIBILITY_INDEX]; + bits &= VISIBILITY_MASK; + bits >>= VISIBILITY_SHIFT; + + /* 2bits: tt : type */ + + return (bits & 0x3); +} +#undef VISIBILITY_INDEX +#undef VISIBILITY_SHIFT +#undef VISIBILITY_MASK + +#define WHITE_SPACE_INDEX 8 +#define WHITE_SPACE_SHIFT 0 +#define WHITE_SPACE_MASK 0x7 +static inline uint8_t get_white_space_bits(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[WHITE_SPACE_INDEX]; + bits &= WHITE_SPACE_MASK; + bits >>= WHITE_SPACE_SHIFT; + + /* 3bits: ttt : type */ + return (bits & 0x7); +} +static inline uint8_t get_white_space(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[WHITE_SPACE_INDEX]; + bits &= WHITE_SPACE_MASK; + bits >>= WHITE_SPACE_SHIFT; + + /* 3bits: ttt : type */ + + return (bits & 0x7); +} +#undef WHITE_SPACE_INDEX +#undef WHITE_SPACE_SHIFT +#undef WHITE_SPACE_MASK + +#define WIDOWS_INDEX 12 +#define WIDOWS_SHIFT 0 +#define WIDOWS_MASK 0x1 +static inline uint8_t get_widows_bits(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[WIDOWS_INDEX]; + bits &= WIDOWS_MASK; + bits >>= WIDOWS_SHIFT; + + /* 1bit: t : type */ + return (bits & 0x1); +} +static inline uint8_t get_widows(const css_computed_style *style, int32_t + *integer) +{ + uint32_t bits = style->i.bits[WIDOWS_INDEX]; + bits &= WIDOWS_MASK; + bits >>= WIDOWS_SHIFT; + + /* 1bit: t : type */ + *integer = style->i.widows; + + return (bits & 0x1); +} +#undef WIDOWS_INDEX +#undef WIDOWS_SHIFT +#undef WIDOWS_MASK + +#define WIDTH_INDEX 4 +#define WIDTH_SHIFT 25 +#define WIDTH_MASK 0xfe000000 +static inline uint8_t get_width_bits(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[WIDTH_INDEX]; + bits &= WIDTH_MASK; + bits >>= WIDTH_SHIFT; + + /* 7bits: uuuuutt : unit | type */ + return (bits & 0x3); +} +static inline uint8_t get_width(const css_computed_style *style, css_fixed + *length, css_unit *unit) +{ + uint32_t bits = style->i.bits[WIDTH_INDEX]; + bits &= WIDTH_MASK; + bits >>= WIDTH_SHIFT; + + /* 7bits: uuuuutt : unit | type */ + if ((bits & 0x3) == CSS_WIDTH_SET) { + *length = style->i.width; + *unit = bits >> 2; + } + + return (bits & 0x3); +} +#undef WIDTH_INDEX +#undef WIDTH_SHIFT +#undef WIDTH_MASK + +#define WORD_SPACING_INDEX 1 +#define WORD_SPACING_SHIFT 0 +#define WORD_SPACING_MASK 0x7f +static inline uint8_t get_word_spacing_bits(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[WORD_SPACING_INDEX]; + bits &= WORD_SPACING_MASK; + bits >>= WORD_SPACING_SHIFT; + + /* 7bits: uuuuutt : unit | type */ + return (bits & 0x3); +} +static inline uint8_t get_word_spacing(const css_computed_style *style, + css_fixed *length, css_unit *unit) +{ + uint32_t bits = style->i.bits[WORD_SPACING_INDEX]; + bits &= WORD_SPACING_MASK; + bits >>= WORD_SPACING_SHIFT; + + /* 7bits: uuuuutt : unit | type */ + if ((bits & 0x3) == CSS_WORD_SPACING_SET) { + *length = style->i.word_spacing; + *unit = bits >> 2; + } + + return (bits & 0x3); +} +#undef WORD_SPACING_INDEX +#undef WORD_SPACING_SHIFT +#undef WORD_SPACING_MASK + +#define WRITING_MODE_INDEX 10 +#define WRITING_MODE_SHIFT 16 +#define WRITING_MODE_MASK 0x30000 +static inline uint8_t get_writing_mode_bits(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[WRITING_MODE_INDEX]; + bits &= WRITING_MODE_MASK; + bits >>= WRITING_MODE_SHIFT; + + /* 2bits: tt : type */ + return (bits & 0x3); +} +static inline uint8_t get_writing_mode(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[WRITING_MODE_INDEX]; + bits &= WRITING_MODE_MASK; + bits >>= WRITING_MODE_SHIFT; + + /* 2bits: tt : type */ + + return (bits & 0x3); +} +#undef WRITING_MODE_INDEX +#undef WRITING_MODE_SHIFT +#undef WRITING_MODE_MASK + +#define Z_INDEX_INDEX 10 +#define Z_INDEX_SHIFT 18 +#define Z_INDEX_MASK 0xc0000 +static inline uint8_t get_z_index_bits(const css_computed_style *style) +{ + uint32_t bits = style->i.bits[Z_INDEX_INDEX]; + bits &= Z_INDEX_MASK; + bits >>= Z_INDEX_SHIFT; + + /* 2bits: tt : type */ + return (bits & 0x3); +} +static inline uint8_t get_z_index(const css_computed_style *style, int32_t + *integer) +{ + uint32_t bits = style->i.bits[Z_INDEX_INDEX]; + bits &= Z_INDEX_MASK; + bits >>= Z_INDEX_SHIFT; + + /* 2bits: tt : type */ + *integer = style->i.z_index; + + return (bits & 0x3); +} +#undef Z_INDEX_INDEX +#undef Z_INDEX_SHIFT +#undef Z_INDEX_MASK diff --git a/src/select/autogenerated_propset.h b/src/select/autogenerated_propset.h new file mode 100644 index 0000000..198bc1e --- /dev/null +++ b/src/select/autogenerated_propset.h @@ -0,0 +1,2345 @@ +/* + * This file is part of LibCSS + * Licensed under the MIT License, + * http://www.opensource.org/licenses/mit-license.php + * Copyright 2017 The NetSurf Project + */ + +/** Default values are 'initial value', unless the property is inherited, + * in which case it is 'inherit'. */ + +#define ALIGN_CONTENT_INDEX 10 +#define ALIGN_CONTENT_SHIFT 20 +#define ALIGN_CONTENT_MASK 0x700000 + +static inline css_error set_align_content(css_computed_style *style, uint8_t + type) +{ + uint32_t *bits = &style->i.bits[ALIGN_CONTENT_INDEX]; + + /* 3bits: ttt : type */ + *bits = (*bits & ~ALIGN_CONTENT_MASK) | (((uint32_t)type & 0x7) << + ALIGN_CONTENT_SHIFT); + + return CSS_OK; +} +#undef ALIGN_CONTENT_INDEX +#undef ALIGN_CONTENT_SHIFT +#undef ALIGN_CONTENT_MASK + +#define ALIGN_ITEMS_INDEX 10 +#define ALIGN_ITEMS_SHIFT 23 +#define ALIGN_ITEMS_MASK 0x3800000 + +static inline css_error set_align_items(css_computed_style *style, uint8_t type) +{ + uint32_t *bits = &style->i.bits[ALIGN_ITEMS_INDEX]; + + /* 3bits: ttt : type */ + *bits = (*bits & ~ALIGN_ITEMS_MASK) | (((uint32_t)type & 0x7) << + ALIGN_ITEMS_SHIFT); + + return CSS_OK; +} +#undef ALIGN_ITEMS_INDEX +#undef ALIGN_ITEMS_SHIFT +#undef ALIGN_ITEMS_MASK + +#define ALIGN_SELF_INDEX 10 +#define ALIGN_SELF_SHIFT 26 +#define ALIGN_SELF_MASK 0x1c000000 + +static inline css_error set_align_self(css_computed_style *style, uint8_t type) +{ + uint32_t *bits = &style->i.bits[ALIGN_SELF_INDEX]; + + /* 3bits: ttt : type */ + *bits = (*bits & ~ALIGN_SELF_MASK) | (((uint32_t)type & 0x7) << + ALIGN_SELF_SHIFT); + + return CSS_OK; +} +#undef ALIGN_SELF_INDEX +#undef ALIGN_SELF_SHIFT +#undef ALIGN_SELF_MASK + +#define BACKGROUND_ATTACHMENT_INDEX 14 +#define BACKGROUND_ATTACHMENT_SHIFT 28 +#define BACKGROUND_ATTACHMENT_MASK 0x30000000 + +static inline css_error set_background_attachment(css_computed_style *style, + uint8_t type) +{ + uint32_t *bits = &style->i.bits[BACKGROUND_ATTACHMENT_INDEX]; + + /* 2bits: tt : type */ + *bits = (*bits & ~BACKGROUND_ATTACHMENT_MASK) | (((uint32_t)type & 0x3) + << BACKGROUND_ATTACHMENT_SHIFT); + + return CSS_OK; +} +#undef BACKGROUND_ATTACHMENT_INDEX +#undef BACKGROUND_ATTACHMENT_SHIFT +#undef BACKGROUND_ATTACHMENT_MASK + +#define BACKGROUND_COLOR_INDEX 14 +#define BACKGROUND_COLOR_SHIFT 30 +#define BACKGROUND_COLOR_MASK 0xc0000000 + +static inline css_error set_background_color(css_computed_style *style, uint8_t + type, css_color color) +{ + uint32_t *bits = &style->i.bits[BACKGROUND_COLOR_INDEX]; + + /* 2bits: tt : type */ + *bits = (*bits & ~BACKGROUND_COLOR_MASK) | (((uint32_t)type & 0x3) << + BACKGROUND_COLOR_SHIFT); + + style->i.background_color = color; + + return CSS_OK; +} +#undef BACKGROUND_COLOR_INDEX +#undef BACKGROUND_COLOR_SHIFT +#undef BACKGROUND_COLOR_MASK + +#define BACKGROUND_IMAGE_INDEX 14 +#define BACKGROUND_IMAGE_SHIFT 16 +#define BACKGROUND_IMAGE_MASK 0x10000 + +static inline css_error set_background_image(css_computed_style *style, uint8_t + type, lwc_string *string) +{ + uint32_t *bits = &style->i.bits[BACKGROUND_IMAGE_INDEX]; + + /* 1bit: t : type */ + *bits = (*bits & ~BACKGROUND_IMAGE_MASK) | (((uint32_t)type & 0x1) << + BACKGROUND_IMAGE_SHIFT); + + lwc_string *old_string = style->i.background_image; + + if (string != NULL) { + style->i.background_image = lwc_string_ref(string); + } else { + style->i.background_image = NULL; + } + + if (old_string != NULL) + lwc_string_unref(old_string); + + return CSS_OK; +} +#undef BACKGROUND_IMAGE_INDEX +#undef BACKGROUND_IMAGE_SHIFT +#undef BACKGROUND_IMAGE_MASK + +#define BACKGROUND_POSITION_INDEX 12 +#define BACKGROUND_POSITION_SHIFT 10 +#define BACKGROUND_POSITION_MASK 0x1ffc00 + +static inline css_error set_background_position(css_computed_style *style, + uint8_t type, css_fixed length_a, css_unit unit_a, css_fixed + length_b, css_unit unit_b) +{ + uint32_t *bits = &style->i.bits[BACKGROUND_POSITION_INDEX]; + + /* 11bits: aaaaabbbbbt : unit_a | unit_b | type */ + *bits = (*bits & ~BACKGROUND_POSITION_MASK) | ((((uint32_t)type & 0x1) + | (unit_b << 1) | (unit_a << 6)) << + BACKGROUND_POSITION_SHIFT); + + style->i.background_position_a = length_a; + + style->i.background_position_b = length_b; + + return CSS_OK; +} +#undef BACKGROUND_POSITION_INDEX +#undef BACKGROUND_POSITION_SHIFT +#undef BACKGROUND_POSITION_MASK + +#define BACKGROUND_REPEAT_INDEX 10 +#define BACKGROUND_REPEAT_SHIFT 29 +#define BACKGROUND_REPEAT_MASK 0xe0000000 + +static inline css_error set_background_repeat(css_computed_style *style, + uint8_t type) +{ + uint32_t *bits = &style->i.bits[BACKGROUND_REPEAT_INDEX]; + + /* 3bits: ttt : type */ + *bits = (*bits & ~BACKGROUND_REPEAT_MASK) | (((uint32_t)type & 0x7) << + BACKGROUND_REPEAT_SHIFT); + + return CSS_OK; +} +#undef BACKGROUND_REPEAT_INDEX +#undef BACKGROUND_REPEAT_SHIFT +#undef BACKGROUND_REPEAT_MASK + +#define BORDER_BOTTOM_COLOR_INDEX 11 +#define BORDER_BOTTOM_COLOR_SHIFT 0 +#define BORDER_BOTTOM_COLOR_MASK 0x3 + +static inline css_error set_border_bottom_color(css_computed_style *style, + uint8_t type, css_color color) +{ + uint32_t *bits = &style->i.bits[BORDER_BOTTOM_COLOR_INDEX]; + + /* 2bits: tt : type */ + *bits = (*bits & ~BORDER_BOTTOM_COLOR_MASK) | (((uint32_t)type & 0x3) + << BORDER_BOTTOM_COLOR_SHIFT); + + style->i.border_bottom_color = color; + + return CSS_OK; +} +#undef BORDER_BOTTOM_COLOR_INDEX +#undef BORDER_BOTTOM_COLOR_SHIFT +#undef BORDER_BOTTOM_COLOR_MASK + +#define BORDER_BOTTOM_STYLE_INDEX 13 +#define BORDER_BOTTOM_STYLE_SHIFT 28 +#define BORDER_BOTTOM_STYLE_MASK 0xf0000000 + +static inline css_error set_border_bottom_style(css_computed_style *style, + uint8_t type) +{ + uint32_t *bits = &style->i.bits[BORDER_BOTTOM_STYLE_INDEX]; + + /* 4bits: tttt : type */ + *bits = (*bits & ~BORDER_BOTTOM_STYLE_MASK) | (((uint32_t)type & 0xf) + << BORDER_BOTTOM_STYLE_SHIFT); + + return CSS_OK; +} +#undef BORDER_BOTTOM_STYLE_INDEX +#undef BORDER_BOTTOM_STYLE_SHIFT +#undef BORDER_BOTTOM_STYLE_MASK + +#define BORDER_BOTTOM_WIDTH_INDEX 0 +#define BORDER_BOTTOM_WIDTH_SHIFT 0 +#define BORDER_BOTTOM_WIDTH_MASK 0xff + +static inline css_error set_border_bottom_width(css_computed_style *style, + uint8_t type, css_fixed length, css_unit unit) +{ + uint32_t *bits = &style->i.bits[BORDER_BOTTOM_WIDTH_INDEX]; + + /* 8bits: uuuuuttt : unit | type */ + *bits = (*bits & ~BORDER_BOTTOM_WIDTH_MASK) | ((((uint32_t)type & 0x7) + | (unit << 3)) << BORDER_BOTTOM_WIDTH_SHIFT); + + style->i.border_bottom_width = length; + + return CSS_OK; +} +#undef BORDER_BOTTOM_WIDTH_INDEX +#undef BORDER_BOTTOM_WIDTH_SHIFT +#undef BORDER_BOTTOM_WIDTH_MASK + +#define BORDER_COLLAPSE_INDEX 11 +#define BORDER_COLLAPSE_SHIFT 2 +#define BORDER_COLLAPSE_MASK 0xc + +static inline css_error set_border_collapse(css_computed_style *style, uint8_t + type) +{ + uint32_t *bits = &style->i.bits[BORDER_COLLAPSE_INDEX]; + + /* 2bits: tt : type */ + *bits = (*bits & ~BORDER_COLLAPSE_MASK) | (((uint32_t)type & 0x3) << + BORDER_COLLAPSE_SHIFT); + + return CSS_OK; +} +#undef BORDER_COLLAPSE_INDEX +#undef BORDER_COLLAPSE_SHIFT +#undef BORDER_COLLAPSE_MASK + +#define BORDER_LEFT_COLOR_INDEX 11 +#define BORDER_LEFT_COLOR_SHIFT 4 +#define BORDER_LEFT_COLOR_MASK 0x30 + +static inline css_error set_border_left_color(css_computed_style *style, + uint8_t type, css_color color) +{ + uint32_t *bits = &style->i.bits[BORDER_LEFT_COLOR_INDEX]; + + /* 2bits: tt : type */ + *bits = (*bits & ~BORDER_LEFT_COLOR_MASK) | (((uint32_t)type & 0x3) << + BORDER_LEFT_COLOR_SHIFT); + + style->i.border_left_color = color; + + return CSS_OK; +} +#undef BORDER_LEFT_COLOR_INDEX +#undef BORDER_LEFT_COLOR_SHIFT +#undef BORDER_LEFT_COLOR_MASK + +#define BORDER_LEFT_STYLE_INDEX 9 +#define BORDER_LEFT_STYLE_SHIFT 3 +#define BORDER_LEFT_STYLE_MASK 0x78 + +static inline css_error set_border_left_style(css_computed_style *style, + uint8_t type) +{ + uint32_t *bits = &style->i.bits[BORDER_LEFT_STYLE_INDEX]; + + /* 4bits: tttt : type */ + *bits = (*bits & ~BORDER_LEFT_STYLE_MASK) | (((uint32_t)type & 0xf) << + BORDER_LEFT_STYLE_SHIFT); + + return CSS_OK; +} +#undef BORDER_LEFT_STYLE_INDEX +#undef BORDER_LEFT_STYLE_SHIFT +#undef BORDER_LEFT_STYLE_MASK + +#define BORDER_LEFT_WIDTH_INDEX 0 +#define BORDER_LEFT_WIDTH_SHIFT 8 +#define BORDER_LEFT_WIDTH_MASK 0xff00 + +static inline css_error set_border_left_width(css_computed_style *style, + uint8_t type, css_fixed length, css_unit unit) +{ + uint32_t *bits = &style->i.bits[BORDER_LEFT_WIDTH_INDEX]; + + /* 8bits: uuuuuttt : unit | type */ + *bits = (*bits & ~BORDER_LEFT_WIDTH_MASK) | ((((uint32_t)type & 0x7) | ( + unit << 3)) << BORDER_LEFT_WIDTH_SHIFT); + + style->i.border_left_width = length; + + return CSS_OK; +} +#undef BORDER_LEFT_WIDTH_INDEX +#undef BORDER_LEFT_WIDTH_SHIFT +#undef BORDER_LEFT_WIDTH_MASK + +#define BORDER_RIGHT_COLOR_INDEX 11 +#define BORDER_RIGHT_COLOR_SHIFT 6 +#define BORDER_RIGHT_COLOR_MASK 0xc0 + +static inline css_error set_border_right_color(css_computed_style *style, + uint8_t type, css_color color) +{ + uint32_t *bits = &style->i.bits[BORDER_RIGHT_COLOR_INDEX]; + + /* 2bits: tt : type */ + *bits = (*bits & ~BORDER_RIGHT_COLOR_MASK) | (((uint32_t)type & 0x3) << + BORDER_RIGHT_COLOR_SHIFT); + + style->i.border_right_color = color; + + return CSS_OK; +} +#undef BORDER_RIGHT_COLOR_INDEX +#undef BORDER_RIGHT_COLOR_SHIFT +#undef BORDER_RIGHT_COLOR_MASK + +#define BORDER_RIGHT_STYLE_INDEX 9 +#define BORDER_RIGHT_STYLE_SHIFT 7 +#define BORDER_RIGHT_STYLE_MASK 0x780 + +static inline css_error set_border_right_style(css_computed_style *style, + uint8_t type) +{ + uint32_t *bits = &style->i.bits[BORDER_RIGHT_STYLE_INDEX]; + + /* 4bits: tttt : type */ + *bits = (*bits & ~BORDER_RIGHT_STYLE_MASK) | (((uint32_t)type & 0xf) << + BORDER_RIGHT_STYLE_SHIFT); + + return CSS_OK; +} +#undef BORDER_RIGHT_STYLE_INDEX +#undef BORDER_RIGHT_STYLE_SHIFT +#undef BORDER_RIGHT_STYLE_MASK + +#define BORDER_RIGHT_WIDTH_INDEX 0 +#define BORDER_RIGHT_WIDTH_SHIFT 16 +#define BORDER_RIGHT_WIDTH_MASK 0xff0000 + +static inline css_error set_border_right_width(css_computed_style *style, + uint8_t type, css_fixed length, css_unit unit) +{ + uint32_t *bits = &style->i.bits[BORDER_RIGHT_WIDTH_INDEX]; + + /* 8bits: uuuuuttt : unit | type */ + *bits = (*bits & ~BORDER_RIGHT_WIDTH_MASK) | ((((uint32_t)type & 0x7) | + (unit << 3)) << BORDER_RIGHT_WIDTH_SHIFT); + + style->i.border_right_width = length; + + return CSS_OK; +} +#undef BORDER_RIGHT_WIDTH_INDEX +#undef BORDER_RIGHT_WIDTH_SHIFT +#undef BORDER_RIGHT_WIDTH_MASK + +#define BORDER_SPACING_INDEX 12 +#define BORDER_SPACING_SHIFT 21 +#define BORDER_SPACING_MASK 0xffe00000 + +static inline css_error set_border_spacing(css_computed_style *style, uint8_t + type, css_fixed length_a, css_unit unit_a, css_fixed length_b, + css_unit unit_b) +{ + uint32_t *bits = &style->i.bits[BORDER_SPACING_INDEX]; + + /* 11bits: aaaaabbbbbt : unit_a | unit_b | type */ + *bits = (*bits & ~BORDER_SPACING_MASK) | ((((uint32_t)type & 0x1) | ( + unit_b << 1) | (unit_a << 6)) << BORDER_SPACING_SHIFT); + + style->i.border_spacing_a = length_a; + + style->i.border_spacing_b = length_b; + + return CSS_OK; +} +#undef BORDER_SPACING_INDEX +#undef BORDER_SPACING_SHIFT +#undef BORDER_SPACING_MASK + +#define BORDER_TOP_COLOR_INDEX 11 +#define BORDER_TOP_COLOR_SHIFT 8 +#define BORDER_TOP_COLOR_MASK 0x300 + +static inline css_error set_border_top_color(css_computed_style *style, uint8_t + type, css_color color) +{ + uint32_t *bits = &style->i.bits[BORDER_TOP_COLOR_INDEX]; + + /* 2bits: tt : type */ + *bits = (*bits & ~BORDER_TOP_COLOR_MASK) | (((uint32_t)type & 0x3) << + BORDER_TOP_COLOR_SHIFT); + + style->i.border_top_color = color; + + return CSS_OK; +} +#undef BORDER_TOP_COLOR_INDEX +#undef BORDER_TOP_COLOR_SHIFT +#undef BORDER_TOP_COLOR_MASK + +#define BORDER_TOP_STYLE_INDEX 9 +#define BORDER_TOP_STYLE_SHIFT 11 +#define BORDER_TOP_STYLE_MASK 0x7800 + +static inline css_error set_border_top_style(css_computed_style *style, uint8_t + type) +{ + uint32_t *bits = &style->i.bits[BORDER_TOP_STYLE_INDEX]; + + /* 4bits: tttt : type */ + *bits = (*bits & ~BORDER_TOP_STYLE_MASK) | (((uint32_t)type & 0xf) << + BORDER_TOP_STYLE_SHIFT); + + return CSS_OK; +} +#undef BORDER_TOP_STYLE_INDEX +#undef BORDER_TOP_STYLE_SHIFT +#undef BORDER_TOP_STYLE_MASK + +#define BORDER_TOP_WIDTH_INDEX 0 +#define BORDER_TOP_WIDTH_SHIFT 24 +#define BORDER_TOP_WIDTH_MASK 0xff000000 + +static inline css_error set_border_top_width(css_computed_style *style, uint8_t + type, css_fixed length, css_unit unit) +{ + uint32_t *bits = &style->i.bits[BORDER_TOP_WIDTH_INDEX]; + + /* 8bits: uuuuuttt : unit | type */ + *bits = (*bits & ~BORDER_TOP_WIDTH_MASK) | ((((uint32_t)type & 0x7) | ( + unit << 3)) << BORDER_TOP_WIDTH_SHIFT); + + style->i.border_top_width = length; + + return CSS_OK; +} +#undef BORDER_TOP_WIDTH_INDEX +#undef BORDER_TOP_WIDTH_SHIFT +#undef BORDER_TOP_WIDTH_MASK + +#define BOTTOM_INDEX 3 +#define BOTTOM_SHIFT 11 +#define BOTTOM_MASK 0x3f800 + +static inline css_error set_bottom(css_computed_style *style, uint8_t type, + css_fixed length, css_unit unit) +{ + uint32_t *bits = &style->i.bits[BOTTOM_INDEX]; + + /* 7bits: uuuuutt : unit | type */ + *bits = (*bits & ~BOTTOM_MASK) | ((((uint32_t)type & 0x3) | (unit << + 2)) << BOTTOM_SHIFT); + + style->i.bottom = length; + + return CSS_OK; +} +#undef BOTTOM_INDEX +#undef BOTTOM_SHIFT +#undef BOTTOM_MASK + +#define BOX_SIZING_INDEX 11 +#define BOX_SIZING_SHIFT 10 +#define BOX_SIZING_MASK 0xc00 + +static inline css_error set_box_sizing(css_computed_style *style, uint8_t type) +{ + uint32_t *bits = &style->i.bits[BOX_SIZING_INDEX]; + + /* 2bits: tt : type */ + *bits = (*bits & ~BOX_SIZING_MASK) | (((uint32_t)type & 0x3) << + BOX_SIZING_SHIFT); + + return CSS_OK; +} +#undef BOX_SIZING_INDEX +#undef BOX_SIZING_SHIFT +#undef BOX_SIZING_MASK + +#define BREAK_AFTER_INDEX 9 +#define BREAK_AFTER_SHIFT 15 +#define BREAK_AFTER_MASK 0x78000 + +static inline css_error set_break_after(css_computed_style *style, uint8_t type) +{ + uint32_t *bits = &style->i.bits[BREAK_AFTER_INDEX]; + + /* 4bits: tttt : type */ + *bits = (*bits & ~BREAK_AFTER_MASK) | (((uint32_t)type & 0xf) << + BREAK_AFTER_SHIFT); + + return CSS_OK; +} +#undef BREAK_AFTER_INDEX +#undef BREAK_AFTER_SHIFT +#undef BREAK_AFTER_MASK + +#define BREAK_BEFORE_INDEX 9 +#define BREAK_BEFORE_SHIFT 19 +#define BREAK_BEFORE_MASK 0x780000 + +static inline css_error set_break_before(css_computed_style *style, uint8_t + type) +{ + uint32_t *bits = &style->i.bits[BREAK_BEFORE_INDEX]; + + /* 4bits: tttt : type */ + *bits = (*bits & ~BREAK_BEFORE_MASK) | (((uint32_t)type & 0xf) << + BREAK_BEFORE_SHIFT); + + return CSS_OK; +} +#undef BREAK_BEFORE_INDEX +#undef BREAK_BEFORE_SHIFT +#undef BREAK_BEFORE_MASK + +#define BREAK_INSIDE_INDEX 9 +#define BREAK_INSIDE_SHIFT 23 +#define BREAK_INSIDE_MASK 0x7800000 + +static inline css_error set_break_inside(css_computed_style *style, uint8_t + type) +{ + uint32_t *bits = &style->i.bits[BREAK_INSIDE_INDEX]; + + /* 4bits: tttt : type */ + *bits = (*bits & ~BREAK_INSIDE_MASK) | (((uint32_t)type & 0xf) << + BREAK_INSIDE_SHIFT); + + return CSS_OK; +} +#undef BREAK_INSIDE_INDEX +#undef BREAK_INSIDE_SHIFT +#undef BREAK_INSIDE_MASK + +#define CAPTION_SIDE_INDEX 11 +#define CAPTION_SIDE_SHIFT 12 +#define CAPTION_SIDE_MASK 0x3000 + +static inline css_error set_caption_side(css_computed_style *style, uint8_t + type) +{ + uint32_t *bits = &style->i.bits[CAPTION_SIDE_INDEX]; + + /* 2bits: tt : type */ + *bits = (*bits & ~CAPTION_SIDE_MASK) | (((uint32_t)type & 0x3) << + CAPTION_SIDE_SHIFT); + + return CSS_OK; +} +#undef CAPTION_SIDE_INDEX +#undef CAPTION_SIDE_SHIFT +#undef CAPTION_SIDE_MASK + +#define CLEAR_INDEX 13 +#define CLEAR_SHIFT 1 +#define CLEAR_MASK 0xe + +static inline css_error set_clear(css_computed_style *style, uint8_t type) +{ + uint32_t *bits = &style->i.bits[CLEAR_INDEX]; + + /* 3bits: ttt : type */ + *bits = (*bits & ~CLEAR_MASK) | (((uint32_t)type & 0x7) << CLEAR_SHIFT); + + return CSS_OK; +} +#undef CLEAR_INDEX +#undef CLEAR_SHIFT +#undef CLEAR_MASK + +#define CLIP_INDEX 2 +#define CLIP_SHIFT 6 +#define CLIP_MASK 0xffffffc0 +static inline css_error set_clip( + css_computed_style *style, uint8_t type, + css_computed_clip_rect *rect) +{ + uint32_t *bits; + + bits = &style->i.bits[CLIP_INDEX]; + + /* + 26bits: tt tttr rrrr bbbb blll llTR BLyy: + units: top | right | bottom | left + opcodes: top | right | bottom | left | type + */ + *bits = (*bits & ~CLIP_MASK) | + ((type & 0x3) << CLIP_SHIFT); + + if (type == CSS_CLIP_RECT) { + *bits |= (((rect->top_auto ? 0x20 : 0) | + (rect->right_auto ? 0x10 : 0) | + (rect->bottom_auto ? 0x8 : 0) | + (rect->left_auto ? 0x4 : 0)) << CLIP_SHIFT); + + *bits |= (((rect->tunit << 5) | rect->runit) + << (CLIP_SHIFT + 16)); + + *bits |= (((rect->bunit << 5) | rect->lunit) + << (CLIP_SHIFT + 6)); + + style->i.clip_a = rect->top; + style->i.clip_b = rect->right; + style->i.clip_c = rect->bottom; + style->i.clip_d = rect->left; + } + + return CSS_OK; +} +#undef CLIP_INDEX +#undef CLIP_SHIFT +#undef CLIP_MASK + +#define COLOR_INDEX 14 +#define COLOR_SHIFT 17 +#define COLOR_MASK 0x20000 + +static inline css_error set_color(css_computed_style *style, uint8_t type, + css_color color) +{ + uint32_t *bits = &style->i.bits[COLOR_INDEX]; + + /* 1bit: t : type */ + *bits = (*bits & ~COLOR_MASK) | (((uint32_t)type & 0x1) << COLOR_SHIFT); + + style->i.color = color; + + return CSS_OK; +} +#undef COLOR_INDEX +#undef COLOR_SHIFT +#undef COLOR_MASK + +#define COLUMN_COUNT_INDEX 11 +#define COLUMN_COUNT_SHIFT 14 +#define COLUMN_COUNT_MASK 0xc000 + +static inline css_error set_column_count(css_computed_style *style, uint8_t + type, int32_t integer) +{ + uint32_t *bits = &style->i.bits[COLUMN_COUNT_INDEX]; + + /* 2bits: tt : type */ + *bits = (*bits & ~COLUMN_COUNT_MASK) | (((uint32_t)type & 0x3) << + COLUMN_COUNT_SHIFT); + + style->i.column_count = integer; + + return CSS_OK; +} +#undef COLUMN_COUNT_INDEX +#undef COLUMN_COUNT_SHIFT +#undef COLUMN_COUNT_MASK + +#define COLUMN_FILL_INDEX 11 +#define COLUMN_FILL_SHIFT 16 +#define COLUMN_FILL_MASK 0x30000 + +static inline css_error set_column_fill(css_computed_style *style, uint8_t type) +{ + uint32_t *bits = &style->i.bits[COLUMN_FILL_INDEX]; + + /* 2bits: tt : type */ + *bits = (*bits & ~COLUMN_FILL_MASK) | (((uint32_t)type & 0x3) << + COLUMN_FILL_SHIFT); + + return CSS_OK; +} +#undef COLUMN_FILL_INDEX +#undef COLUMN_FILL_SHIFT +#undef COLUMN_FILL_MASK + +#define COLUMN_GAP_INDEX 3 +#define COLUMN_GAP_SHIFT 18 +#define COLUMN_GAP_MASK 0x1fc0000 + +static inline css_error set_column_gap(css_computed_style *style, uint8_t type, + css_fixed length, css_unit unit) +{ + uint32_t *bits = &style->i.bits[COLUMN_GAP_INDEX]; + + /* 7bits: uuuuutt : unit | type */ + *bits = (*bits & ~COLUMN_GAP_MASK) | ((((uint32_t)type & 0x3) | (unit + << 2)) << COLUMN_GAP_SHIFT); + + style->i.column_gap = length; + + return CSS_OK; +} +#undef COLUMN_GAP_INDEX +#undef COLUMN_GAP_SHIFT +#undef COLUMN_GAP_MASK + +#define COLUMN_RULE_COLOR_INDEX 11 +#define COLUMN_RULE_COLOR_SHIFT 18 +#define COLUMN_RULE_COLOR_MASK 0xc0000 + +static inline css_error set_column_rule_color(css_computed_style *style, + uint8_t type, css_color color) +{ + uint32_t *bits = &style->i.bits[COLUMN_RULE_COLOR_INDEX]; + + /* 2bits: tt : type */ + *bits = (*bits & ~COLUMN_RULE_COLOR_MASK) | (((uint32_t)type & 0x3) << + COLUMN_RULE_COLOR_SHIFT); + + style->i.column_rule_color = color; + + return CSS_OK; +} +#undef COLUMN_RULE_COLOR_INDEX +#undef COLUMN_RULE_COLOR_SHIFT +#undef COLUMN_RULE_COLOR_MASK + +#define COLUMN_RULE_STYLE_INDEX 7 +#define COLUMN_RULE_STYLE_SHIFT 0 +#define COLUMN_RULE_STYLE_MASK 0xf + +static inline css_error set_column_rule_style(css_computed_style *style, + uint8_t type) +{ + uint32_t *bits = &style->i.bits[COLUMN_RULE_STYLE_INDEX]; + + /* 4bits: tttt : type */ + *bits = (*bits & ~COLUMN_RULE_STYLE_MASK) | (((uint32_t)type & 0xf) << + COLUMN_RULE_STYLE_SHIFT); + + return CSS_OK; +} +#undef COLUMN_RULE_STYLE_INDEX +#undef COLUMN_RULE_STYLE_SHIFT +#undef COLUMN_RULE_STYLE_MASK + +#define COLUMN_RULE_WIDTH_INDEX 1 +#define COLUMN_RULE_WIDTH_SHIFT 7 +#define COLUMN_RULE_WIDTH_MASK 0x7f80 + +static inline css_error set_column_rule_width(css_computed_style *style, + uint8_t type, css_fixed length, css_unit unit) +{ + uint32_t *bits = &style->i.bits[COLUMN_RULE_WIDTH_INDEX]; + + /* 8bits: uuuuuttt : unit | type */ + *bits = (*bits & ~COLUMN_RULE_WIDTH_MASK) | ((((uint32_t)type & 0x7) | ( + unit << 3)) << COLUMN_RULE_WIDTH_SHIFT); + + style->i.column_rule_width = length; + + return CSS_OK; +} +#undef COLUMN_RULE_WIDTH_INDEX +#undef COLUMN_RULE_WIDTH_SHIFT +#undef COLUMN_RULE_WIDTH_MASK + +#define COLUMN_SPAN_INDEX 11 +#define COLUMN_SPAN_SHIFT 20 +#define COLUMN_SPAN_MASK 0x300000 + +static inline css_error set_column_span(css_computed_style *style, uint8_t type) +{ + uint32_t *bits = &style->i.bits[COLUMN_SPAN_INDEX]; + + /* 2bits: tt : type */ + *bits = (*bits & ~COLUMN_SPAN_MASK) | (((uint32_t)type & 0x3) << + COLUMN_SPAN_SHIFT); + + return CSS_OK; +} +#undef COLUMN_SPAN_INDEX +#undef COLUMN_SPAN_SHIFT +#undef COLUMN_SPAN_MASK + +#define COLUMN_WIDTH_INDEX 3 +#define COLUMN_WIDTH_SHIFT 25 +#define COLUMN_WIDTH_MASK 0xfe000000 + +static inline css_error set_column_width(css_computed_style *style, uint8_t + type, css_fixed length, css_unit unit) +{ + uint32_t *bits = &style->i.bits[COLUMN_WIDTH_INDEX]; + + /* 7bits: uuuuutt : unit | type */ + *bits = (*bits & ~COLUMN_WIDTH_MASK) | ((((uint32_t)type & 0x3) | (unit + << 2)) << COLUMN_WIDTH_SHIFT); + + style->i.column_width = length; + + return CSS_OK; +} +#undef COLUMN_WIDTH_INDEX +#undef COLUMN_WIDTH_SHIFT +#undef COLUMN_WIDTH_MASK + +#define CONTENT_INDEX 11 +#define CONTENT_SHIFT 22 +#define CONTENT_MASK 0xc00000 +static inline css_error set_content( + css_computed_style *style, uint8_t type, + css_computed_content_item *content) +{ + uint32_t *bits; + css_computed_content_item *oldcontent; + css_computed_content_item *c; + + /* 2bits: type */ + bits = &style->i.bits[CONTENT_INDEX]; + oldcontent = style->content; + + *bits = (*bits & ~CONTENT_MASK) | + ((type & 0x3) << CONTENT_SHIFT); + + for (c = content; c != NULL && + c->type != CSS_COMPUTED_CONTENT_NONE; c++) { + switch (c->type) { + case CSS_COMPUTED_CONTENT_STRING: + c->data.string = lwc_string_ref(c->data.string); + break; + case CSS_COMPUTED_CONTENT_URI: + c->data.uri = lwc_string_ref(c->data.uri); + break; + case CSS_COMPUTED_CONTENT_ATTR: + c->data.attr = lwc_string_ref(c->data.attr); + break; + case CSS_COMPUTED_CONTENT_COUNTER: + c->data.counter.name = + lwc_string_ref(c->data.counter.name); + break; + case CSS_COMPUTED_CONTENT_COUNTERS: + c->data.counters.name = + lwc_string_ref(c->data.counters.name); + c->data.counters.sep = + lwc_string_ref(c->data.counters.sep); + break; + default: + break; + } + } + + style->content = content; + + /* Free existing array */ + if (oldcontent != NULL) { + for (c = oldcontent; + c->type != CSS_COMPUTED_CONTENT_NONE; c++) { + switch (c->type) { + case CSS_COMPUTED_CONTENT_STRING: + lwc_string_unref(c->data.string); + break; + case CSS_COMPUTED_CONTENT_URI: + lwc_string_unref(c->data.uri); + break; + case CSS_COMPUTED_CONTENT_ATTR: + lwc_string_unref(c->data.attr); + break; + case CSS_COMPUTED_CONTENT_COUNTER: + lwc_string_unref(c->data.counter.name); + break; + case CSS_COMPUTED_CONTENT_COUNTERS: + lwc_string_unref(c->data.counters.name); + lwc_string_unref(c->data.counters.sep); + break; + default: + break; + } + } + + if (oldcontent != content) + free(oldcontent); + } + + return CSS_OK; +} +#undef CONTENT_INDEX +#undef CONTENT_SHIFT +#undef CONTENT_MASK + +#define COUNTER_INCREMENT_INDEX 14 +#define COUNTER_INCREMENT_SHIFT 18 +#define COUNTER_INCREMENT_MASK 0x40000 + +static inline css_error set_counter_increment(css_computed_style *style, + uint8_t type, css_computed_counter *counter_arr) +{ + uint32_t *bits = &style->i.bits[COUNTER_INCREMENT_INDEX]; + + /* 1bit: t : type */ + *bits = (*bits & ~COUNTER_INCREMENT_MASK) | (((uint32_t)type & 0x1) << + COUNTER_INCREMENT_SHIFT); + + css_computed_counter *old_counter_arr = style->counter_increment; + css_computed_counter *c; + + for (c = counter_arr; c != NULL && c->name != NULL; c++) + c->name = lwc_string_ref(c->name); + + style->counter_increment = counter_arr; + + /* Free existing array */ + if (old_counter_arr != NULL) { + for (c = old_counter_arr; c->name != NULL; c++) + lwc_string_unref(c->name); + + if (old_counter_arr != counter_arr) + free(old_counter_arr); + } + + return CSS_OK; +} +#undef COUNTER_INCREMENT_INDEX +#undef COUNTER_INCREMENT_SHIFT +#undef COUNTER_INCREMENT_MASK + +#define COUNTER_RESET_INDEX 14 +#define COUNTER_RESET_SHIFT 19 +#define COUNTER_RESET_MASK 0x80000 + +static inline css_error set_counter_reset(css_computed_style *style, uint8_t + type, css_computed_counter *counter_arr) +{ + uint32_t *bits = &style->i.bits[COUNTER_RESET_INDEX]; + + /* 1bit: t : type */ + *bits = (*bits & ~COUNTER_RESET_MASK) | (((uint32_t)type & 0x1) << + COUNTER_RESET_SHIFT); + + css_computed_counter *old_counter_arr = style->counter_reset; + css_computed_counter *c; + + for (c = counter_arr; c != NULL && c->name != NULL; c++) + c->name = lwc_string_ref(c->name); + + style->counter_reset = counter_arr; + + /* Free existing array */ + if (old_counter_arr != NULL) { + for (c = old_counter_arr; c->name != NULL; c++) + lwc_string_unref(c->name); + + if (old_counter_arr != counter_arr) + free(old_counter_arr); + } + + return CSS_OK; +} +#undef COUNTER_RESET_INDEX +#undef COUNTER_RESET_SHIFT +#undef COUNTER_RESET_MASK + +#define CURSOR_INDEX 9 +#define CURSOR_SHIFT 27 +#define CURSOR_MASK 0xf8000000 + +static inline css_error set_cursor(css_computed_style *style, uint8_t type, + lwc_string **string_arr) +{ + uint32_t *bits = &style->i.bits[CURSOR_INDEX]; + + /* 5bits: ttttt : type */ + *bits = (*bits & ~CURSOR_MASK) | (((uint32_t)type & 0x1f) << + CURSOR_SHIFT); + + lwc_string **old_string_arr = style->cursor; + lwc_string **s; + + for (s = string_arr; s != NULL && *s != NULL; s++) + *s = lwc_string_ref(*s); + + style->cursor = string_arr; + + /* Free existing array */ + if (old_string_arr != NULL) { + for (s = old_string_arr; *s != NULL; s++) + lwc_string_unref(*s); + + if (old_string_arr != string_arr) + free(old_string_arr); + } + + return CSS_OK; +} +#undef CURSOR_INDEX +#undef CURSOR_SHIFT +#undef CURSOR_MASK + +#define DIRECTION_INDEX 11 +#define DIRECTION_SHIFT 24 +#define DIRECTION_MASK 0x3000000 + +static inline css_error set_direction(css_computed_style *style, uint8_t type) +{ + uint32_t *bits = &style->i.bits[DIRECTION_INDEX]; + + /* 2bits: tt : type */ + *bits = (*bits & ~DIRECTION_MASK) | (((uint32_t)type & 0x3) << + DIRECTION_SHIFT); + + return CSS_OK; +} +#undef DIRECTION_INDEX +#undef DIRECTION_SHIFT +#undef DIRECTION_MASK + +#define DISPLAY_INDEX 8 +#define DISPLAY_SHIFT 3 +#define DISPLAY_MASK 0xf8 + +static inline css_error set_display(css_computed_style *style, uint8_t type) +{ + uint32_t *bits = &style->i.bits[DISPLAY_INDEX]; + + /* 5bits: ttttt : type */ + *bits = (*bits & ~DISPLAY_MASK) | (((uint32_t)type & 0x1f) << + DISPLAY_SHIFT); + + return CSS_OK; +} +#undef DISPLAY_INDEX +#undef DISPLAY_SHIFT +#undef DISPLAY_MASK + +#define EMPTY_CELLS_INDEX 11 +#define EMPTY_CELLS_SHIFT 26 +#define EMPTY_CELLS_MASK 0xc000000 + +static inline css_error set_empty_cells(css_computed_style *style, uint8_t type) +{ + uint32_t *bits = &style->i.bits[EMPTY_CELLS_INDEX]; + + /* 2bits: tt : type */ + *bits = (*bits & ~EMPTY_CELLS_MASK) | (((uint32_t)type & 0x3) << + EMPTY_CELLS_SHIFT); + + return CSS_OK; +} +#undef EMPTY_CELLS_INDEX +#undef EMPTY_CELLS_SHIFT +#undef EMPTY_CELLS_MASK + +#define FILL_OPACITY_INDEX 14 +#define FILL_OPACITY_SHIFT 20 +#define FILL_OPACITY_MASK 0x100000 + +static inline css_error set_fill_opacity(css_computed_style *style, uint8_t + type, css_fixed fixed) +{ + uint32_t *bits = &style->i.bits[FILL_OPACITY_INDEX]; + + /* 1bit: t : type */ + *bits = (*bits & ~FILL_OPACITY_MASK) | (((uint32_t)type & 0x1) << + FILL_OPACITY_SHIFT); + + style->i.fill_opacity = fixed; + + return CSS_OK; +} +#undef FILL_OPACITY_INDEX +#undef FILL_OPACITY_SHIFT +#undef FILL_OPACITY_MASK + +#define FLEX_BASIS_INDEX 7 +#define FLEX_BASIS_SHIFT 4 +#define FLEX_BASIS_MASK 0x7f0 + +static inline css_error set_flex_basis(css_computed_style *style, uint8_t type, + css_fixed length, css_unit unit) +{ + uint32_t *bits = &style->i.bits[FLEX_BASIS_INDEX]; + + /* 7bits: uuuuutt : unit | type */ + *bits = (*bits & ~FLEX_BASIS_MASK) | ((((uint32_t)type & 0x3) | (unit + << 2)) << FLEX_BASIS_SHIFT); + + style->i.flex_basis = length; + + return CSS_OK; +} +#undef FLEX_BASIS_INDEX +#undef FLEX_BASIS_SHIFT +#undef FLEX_BASIS_MASK + +#define FLEX_DIRECTION_INDEX 13 +#define FLEX_DIRECTION_SHIFT 4 +#define FLEX_DIRECTION_MASK 0x70 + +static inline css_error set_flex_direction(css_computed_style *style, uint8_t + type) +{ + uint32_t *bits = &style->i.bits[FLEX_DIRECTION_INDEX]; + + /* 3bits: ttt : type */ + *bits = (*bits & ~FLEX_DIRECTION_MASK) | (((uint32_t)type & 0x7) << + FLEX_DIRECTION_SHIFT); + + return CSS_OK; +} +#undef FLEX_DIRECTION_INDEX +#undef FLEX_DIRECTION_SHIFT +#undef FLEX_DIRECTION_MASK + +#define FLEX_GROW_INDEX 14 +#define FLEX_GROW_SHIFT 21 +#define FLEX_GROW_MASK 0x200000 + +static inline css_error set_flex_grow(css_computed_style *style, uint8_t type, + css_fixed fixed) +{ + uint32_t *bits = &style->i.bits[FLEX_GROW_INDEX]; + + /* 1bit: t : type */ + *bits = (*bits & ~FLEX_GROW_MASK) | (((uint32_t)type & 0x1) << + FLEX_GROW_SHIFT); + + style->i.flex_grow = fixed; + + return CSS_OK; +} +#undef FLEX_GROW_INDEX +#undef FLEX_GROW_SHIFT +#undef FLEX_GROW_MASK + +#define FLEX_SHRINK_INDEX 14 +#define FLEX_SHRINK_SHIFT 22 +#define FLEX_SHRINK_MASK 0x400000 + +static inline css_error set_flex_shrink(css_computed_style *style, uint8_t + type, css_fixed fixed) +{ + uint32_t *bits = &style->i.bits[FLEX_SHRINK_INDEX]; + + /* 1bit: t : type */ + *bits = (*bits & ~FLEX_SHRINK_MASK) | (((uint32_t)type & 0x1) << + FLEX_SHRINK_SHIFT); + + style->i.flex_shrink = fixed; + + return CSS_OK; +} +#undef FLEX_SHRINK_INDEX +#undef FLEX_SHRINK_SHIFT +#undef FLEX_SHRINK_MASK + +#define FLEX_WRAP_INDEX 11 +#define FLEX_WRAP_SHIFT 28 +#define FLEX_WRAP_MASK 0x30000000 + +static inline css_error set_flex_wrap(css_computed_style *style, uint8_t type) +{ + uint32_t *bits = &style->i.bits[FLEX_WRAP_INDEX]; + + /* 2bits: tt : type */ + *bits = (*bits & ~FLEX_WRAP_MASK) | (((uint32_t)type & 0x3) << + FLEX_WRAP_SHIFT); + + return CSS_OK; +} +#undef FLEX_WRAP_INDEX +#undef FLEX_WRAP_SHIFT +#undef FLEX_WRAP_MASK + +#define FLOAT_INDEX 11 +#define FLOAT_SHIFT 30 +#define FLOAT_MASK 0xc0000000 + +static inline css_error set_float(css_computed_style *style, uint8_t type) +{ + uint32_t *bits = &style->i.bits[FLOAT_INDEX]; + + /* 2bits: tt : type */ + *bits = (*bits & ~FLOAT_MASK) | (((uint32_t)type & 0x3) << FLOAT_SHIFT); + + return CSS_OK; +} +#undef FLOAT_INDEX +#undef FLOAT_SHIFT +#undef FLOAT_MASK + +#define FONT_FAMILY_INDEX 13 +#define FONT_FAMILY_SHIFT 7 +#define FONT_FAMILY_MASK 0x380 + +static inline css_error set_font_family(css_computed_style *style, uint8_t + type, lwc_string **string_arr) +{ + uint32_t *bits = &style->i.bits[FONT_FAMILY_INDEX]; + + /* 3bits: ttt : type */ + *bits = (*bits & ~FONT_FAMILY_MASK) | (((uint32_t)type & 0x7) << + FONT_FAMILY_SHIFT); + + lwc_string **old_string_arr = style->font_family; + lwc_string **s; + + for (s = string_arr; s != NULL && *s != NULL; s++) + *s = lwc_string_ref(*s); + + style->font_family = string_arr; + + /* Free existing array */ + if (old_string_arr != NULL) { + for (s = old_string_arr; *s != NULL; s++) + lwc_string_unref(*s); + + if (old_string_arr != string_arr) + free(old_string_arr); + } + + return CSS_OK; +} +#undef FONT_FAMILY_INDEX +#undef FONT_FAMILY_SHIFT +#undef FONT_FAMILY_MASK + +#define FONT_SIZE_INDEX 1 +#define FONT_SIZE_SHIFT 23 +#define FONT_SIZE_MASK 0xff800000 + +static inline css_error set_font_size(css_computed_style *style, uint8_t type, + css_fixed length, css_unit unit) +{ + uint32_t *bits = &style->i.bits[FONT_SIZE_INDEX]; + + /* 9bits: uuuuutttt : unit | type */ + *bits = (*bits & ~FONT_SIZE_MASK) | ((((uint32_t)type & 0xf) | (unit << + 4)) << FONT_SIZE_SHIFT); + + style->i.font_size = length; + + return CSS_OK; +} +#undef FONT_SIZE_INDEX +#undef FONT_SIZE_SHIFT +#undef FONT_SIZE_MASK + +#define FONT_STYLE_INDEX 10 +#define FONT_STYLE_SHIFT 0 +#define FONT_STYLE_MASK 0x3 + +static inline css_error set_font_style(css_computed_style *style, uint8_t type) +{ + uint32_t *bits = &style->i.bits[FONT_STYLE_INDEX]; + + /* 2bits: tt : type */ + *bits = (*bits & ~FONT_STYLE_MASK) | (((uint32_t)type & 0x3) << + FONT_STYLE_SHIFT); + + return CSS_OK; +} +#undef FONT_STYLE_INDEX +#undef FONT_STYLE_SHIFT +#undef FONT_STYLE_MASK + +#define FONT_VARIANT_INDEX 10 +#define FONT_VARIANT_SHIFT 2 +#define FONT_VARIANT_MASK 0xc + +static inline css_error set_font_variant(css_computed_style *style, uint8_t + type) +{ + uint32_t *bits = &style->i.bits[FONT_VARIANT_INDEX]; + + /* 2bits: tt : type */ + *bits = (*bits & ~FONT_VARIANT_MASK) | (((uint32_t)type & 0x3) << + FONT_VARIANT_SHIFT); + + return CSS_OK; +} +#undef FONT_VARIANT_INDEX +#undef FONT_VARIANT_SHIFT +#undef FONT_VARIANT_MASK + +#define FONT_WEIGHT_INDEX 6 +#define FONT_WEIGHT_SHIFT 0 +#define FONT_WEIGHT_MASK 0xf + +static inline css_error set_font_weight(css_computed_style *style, uint8_t type) +{ + uint32_t *bits = &style->i.bits[FONT_WEIGHT_INDEX]; + + /* 4bits: tttt : type */ + *bits = (*bits & ~FONT_WEIGHT_MASK) | (((uint32_t)type & 0xf) << + FONT_WEIGHT_SHIFT); + + return CSS_OK; +} +#undef FONT_WEIGHT_INDEX +#undef FONT_WEIGHT_SHIFT +#undef FONT_WEIGHT_MASK + +#define HEIGHT_INDEX 7 +#define HEIGHT_SHIFT 11 +#define HEIGHT_MASK 0x3f800 + +static inline css_error set_height(css_computed_style *style, uint8_t type, + css_fixed length, css_unit unit) +{ + uint32_t *bits = &style->i.bits[HEIGHT_INDEX]; + + /* 7bits: uuuuutt : unit | type */ + *bits = (*bits & ~HEIGHT_MASK) | ((((uint32_t)type & 0x3) | (unit << + 2)) << HEIGHT_SHIFT); + + style->i.height = length; + + return CSS_OK; +} +#undef HEIGHT_INDEX +#undef HEIGHT_SHIFT +#undef HEIGHT_MASK + +#define JUSTIFY_CONTENT_INDEX 13 +#define JUSTIFY_CONTENT_SHIFT 10 +#define JUSTIFY_CONTENT_MASK 0x1c00 + +static inline css_error set_justify_content(css_computed_style *style, uint8_t + type) +{ + uint32_t *bits = &style->i.bits[JUSTIFY_CONTENT_INDEX]; + + /* 3bits: ttt : type */ + *bits = (*bits & ~JUSTIFY_CONTENT_MASK) | (((uint32_t)type & 0x7) << + JUSTIFY_CONTENT_SHIFT); + + return CSS_OK; +} +#undef JUSTIFY_CONTENT_INDEX +#undef JUSTIFY_CONTENT_SHIFT +#undef JUSTIFY_CONTENT_MASK + +#define LEFT_INDEX 7 +#define LEFT_SHIFT 18 +#define LEFT_MASK 0x1fc0000 + +static inline css_error set_left(css_computed_style *style, uint8_t type, + css_fixed length, css_unit unit) +{ + uint32_t *bits = &style->i.bits[LEFT_INDEX]; + + /* 7bits: uuuuutt : unit | type */ + *bits = (*bits & ~LEFT_MASK) | ((((uint32_t)type & 0x3) | (unit << 2)) + << LEFT_SHIFT); + + style->i.left = length; + + return CSS_OK; +} +#undef LEFT_INDEX +#undef LEFT_SHIFT +#undef LEFT_MASK + +#define LETTER_SPACING_INDEX 7 +#define LETTER_SPACING_SHIFT 25 +#define LETTER_SPACING_MASK 0xfe000000 + +static inline css_error set_letter_spacing(css_computed_style *style, uint8_t + type, css_fixed length, css_unit unit) +{ + uint32_t *bits = &style->i.bits[LETTER_SPACING_INDEX]; + + /* 7bits: uuuuutt : unit | type */ + *bits = (*bits & ~LETTER_SPACING_MASK) | ((((uint32_t)type & 0x3) | ( + unit << 2)) << LETTER_SPACING_SHIFT); + + style->i.letter_spacing = length; + + return CSS_OK; +} +#undef LETTER_SPACING_INDEX +#undef LETTER_SPACING_SHIFT +#undef LETTER_SPACING_MASK + +#define LINE_HEIGHT_INDEX 6 +#define LINE_HEIGHT_SHIFT 4 +#define LINE_HEIGHT_MASK 0x7f0 + +static inline css_error set_line_height(css_computed_style *style, uint8_t + type, css_fixed length, css_unit unit) +{ + uint32_t *bits = &style->i.bits[LINE_HEIGHT_INDEX]; + + /* 7bits: uuuuutt : unit | type */ + *bits = (*bits & ~LINE_HEIGHT_MASK) | ((((uint32_t)type & 0x3) | (unit + << 2)) << LINE_HEIGHT_SHIFT); + + style->i.line_height = length; + + return CSS_OK; +} +#undef LINE_HEIGHT_INDEX +#undef LINE_HEIGHT_SHIFT +#undef LINE_HEIGHT_MASK + +#define LIST_STYLE_IMAGE_INDEX 14 +#define LIST_STYLE_IMAGE_SHIFT 23 +#define LIST_STYLE_IMAGE_MASK 0x800000 + +static inline css_error set_list_style_image(css_computed_style *style, uint8_t + type, lwc_string *string) +{ + uint32_t *bits = &style->i.bits[LIST_STYLE_IMAGE_INDEX]; + + /* 1bit: t : type */ + *bits = (*bits & ~LIST_STYLE_IMAGE_MASK) | (((uint32_t)type & 0x1) << + LIST_STYLE_IMAGE_SHIFT); + + lwc_string *old_string = style->i.list_style_image; + + if (string != NULL) { + style->i.list_style_image = lwc_string_ref(string); + } else { + style->i.list_style_image = NULL; + } + + if (old_string != NULL) + lwc_string_unref(old_string); + + return CSS_OK; +} +#undef LIST_STYLE_IMAGE_INDEX +#undef LIST_STYLE_IMAGE_SHIFT +#undef LIST_STYLE_IMAGE_MASK + +#define LIST_STYLE_POSITION_INDEX 10 +#define LIST_STYLE_POSITION_SHIFT 4 +#define LIST_STYLE_POSITION_MASK 0x30 + +static inline css_error set_list_style_position(css_computed_style *style, + uint8_t type) +{ + uint32_t *bits = &style->i.bits[LIST_STYLE_POSITION_INDEX]; + + /* 2bits: tt : type */ + *bits = (*bits & ~LIST_STYLE_POSITION_MASK) | (((uint32_t)type & 0x3) + << LIST_STYLE_POSITION_SHIFT); + + return CSS_OK; +} +#undef LIST_STYLE_POSITION_INDEX +#undef LIST_STYLE_POSITION_SHIFT +#undef LIST_STYLE_POSITION_MASK + +#define LIST_STYLE_TYPE_INDEX 8 +#define LIST_STYLE_TYPE_SHIFT 8 +#define LIST_STYLE_TYPE_MASK 0x3f00 + +static inline css_error set_list_style_type(css_computed_style *style, uint8_t + type) +{ + uint32_t *bits = &style->i.bits[LIST_STYLE_TYPE_INDEX]; + + /* 6bits: tttttt : type */ + *bits = (*bits & ~LIST_STYLE_TYPE_MASK) | (((uint32_t)type & 0x3f) << + LIST_STYLE_TYPE_SHIFT); + + return CSS_OK; +} +#undef LIST_STYLE_TYPE_INDEX +#undef LIST_STYLE_TYPE_SHIFT +#undef LIST_STYLE_TYPE_MASK + +#define MARGIN_BOTTOM_INDEX 6 +#define MARGIN_BOTTOM_SHIFT 11 +#define MARGIN_BOTTOM_MASK 0x3f800 + +static inline css_error set_margin_bottom(css_computed_style *style, uint8_t + type, css_fixed length, css_unit unit) +{ + uint32_t *bits = &style->i.bits[MARGIN_BOTTOM_INDEX]; + + /* 7bits: uuuuutt : unit | type */ + *bits = (*bits & ~MARGIN_BOTTOM_MASK) | ((((uint32_t)type & 0x3) | ( + unit << 2)) << MARGIN_BOTTOM_SHIFT); + + style->i.margin_bottom = length; + + return CSS_OK; +} +#undef MARGIN_BOTTOM_INDEX +#undef MARGIN_BOTTOM_SHIFT +#undef MARGIN_BOTTOM_MASK + +#define MARGIN_LEFT_INDEX 6 +#define MARGIN_LEFT_SHIFT 18 +#define MARGIN_LEFT_MASK 0x1fc0000 + +static inline css_error set_margin_left(css_computed_style *style, uint8_t + type, css_fixed length, css_unit unit) +{ + uint32_t *bits = &style->i.bits[MARGIN_LEFT_INDEX]; + + /* 7bits: uuuuutt : unit | type */ + *bits = (*bits & ~MARGIN_LEFT_MASK) | ((((uint32_t)type & 0x3) | (unit + << 2)) << MARGIN_LEFT_SHIFT); + + style->i.margin_left = length; + + return CSS_OK; +} +#undef MARGIN_LEFT_INDEX +#undef MARGIN_LEFT_SHIFT +#undef MARGIN_LEFT_MASK + +#define MARGIN_RIGHT_INDEX 6 +#define MARGIN_RIGHT_SHIFT 25 +#define MARGIN_RIGHT_MASK 0xfe000000 + +static inline css_error set_margin_right(css_computed_style *style, uint8_t + type, css_fixed length, css_unit unit) +{ + uint32_t *bits = &style->i.bits[MARGIN_RIGHT_INDEX]; + + /* 7bits: uuuuutt : unit | type */ + *bits = (*bits & ~MARGIN_RIGHT_MASK) | ((((uint32_t)type & 0x3) | (unit + << 2)) << MARGIN_RIGHT_SHIFT); + + style->i.margin_right = length; + + return CSS_OK; +} +#undef MARGIN_RIGHT_INDEX +#undef MARGIN_RIGHT_SHIFT +#undef MARGIN_RIGHT_MASK + +#define MARGIN_TOP_INDEX 5 +#define MARGIN_TOP_SHIFT 4 +#define MARGIN_TOP_MASK 0x7f0 + +static inline css_error set_margin_top(css_computed_style *style, uint8_t type, + css_fixed length, css_unit unit) +{ + uint32_t *bits = &style->i.bits[MARGIN_TOP_INDEX]; + + /* 7bits: uuuuutt : unit | type */ + *bits = (*bits & ~MARGIN_TOP_MASK) | ((((uint32_t)type & 0x3) | (unit + << 2)) << MARGIN_TOP_SHIFT); + + style->i.margin_top = length; + + return CSS_OK; +} +#undef MARGIN_TOP_INDEX +#undef MARGIN_TOP_SHIFT +#undef MARGIN_TOP_MASK + +#define MAX_HEIGHT_INDEX 5 +#define MAX_HEIGHT_SHIFT 11 +#define MAX_HEIGHT_MASK 0x3f800 + +static inline css_error set_max_height(css_computed_style *style, uint8_t type, + css_fixed length, css_unit unit) +{ + uint32_t *bits = &style->i.bits[MAX_HEIGHT_INDEX]; + + /* 7bits: uuuuutt : unit | type */ + *bits = (*bits & ~MAX_HEIGHT_MASK) | ((((uint32_t)type & 0x3) | (unit + << 2)) << MAX_HEIGHT_SHIFT); + + style->i.max_height = length; + + return CSS_OK; +} +#undef MAX_HEIGHT_INDEX +#undef MAX_HEIGHT_SHIFT +#undef MAX_HEIGHT_MASK + +#define MAX_WIDTH_INDEX 5 +#define MAX_WIDTH_SHIFT 18 +#define MAX_WIDTH_MASK 0x1fc0000 + +static inline css_error set_max_width(css_computed_style *style, uint8_t type, + css_fixed length, css_unit unit) +{ + uint32_t *bits = &style->i.bits[MAX_WIDTH_INDEX]; + + /* 7bits: uuuuutt : unit | type */ + *bits = (*bits & ~MAX_WIDTH_MASK) | ((((uint32_t)type & 0x3) | (unit << + 2)) << MAX_WIDTH_SHIFT); + + style->i.max_width = length; + + return CSS_OK; +} +#undef MAX_WIDTH_INDEX +#undef MAX_WIDTH_SHIFT +#undef MAX_WIDTH_MASK + +#define MIN_HEIGHT_INDEX 5 +#define MIN_HEIGHT_SHIFT 25 +#define MIN_HEIGHT_MASK 0xfe000000 + +static inline css_error set_min_height(css_computed_style *style, uint8_t type, + css_fixed length, css_unit unit) +{ + uint32_t *bits = &style->i.bits[MIN_HEIGHT_INDEX]; + + /* 7bits: uuuuutt : unit | type */ + *bits = (*bits & ~MIN_HEIGHT_MASK) | ((((uint32_t)type & 0x3) | (unit + << 2)) << MIN_HEIGHT_SHIFT); + + style->i.min_height = length; + + return CSS_OK; +} +#undef MIN_HEIGHT_INDEX +#undef MIN_HEIGHT_SHIFT +#undef MIN_HEIGHT_MASK + +#define MIN_WIDTH_INDEX 4 +#define MIN_WIDTH_SHIFT 4 +#define MIN_WIDTH_MASK 0x7f0 + +static inline css_error set_min_width(css_computed_style *style, uint8_t type, + css_fixed length, css_unit unit) +{ + uint32_t *bits = &style->i.bits[MIN_WIDTH_INDEX]; + + /* 7bits: uuuuutt : unit | type */ + *bits = (*bits & ~MIN_WIDTH_MASK) | ((((uint32_t)type & 0x3) | (unit << + 2)) << MIN_WIDTH_SHIFT); + + style->i.min_width = length; + + return CSS_OK; +} +#undef MIN_WIDTH_INDEX +#undef MIN_WIDTH_SHIFT +#undef MIN_WIDTH_MASK + +#define OPACITY_INDEX 14 +#define OPACITY_SHIFT 24 +#define OPACITY_MASK 0x1000000 + +static inline css_error set_opacity(css_computed_style *style, uint8_t type, + css_fixed fixed) +{ + uint32_t *bits = &style->i.bits[OPACITY_INDEX]; + + /* 1bit: t : type */ + *bits = (*bits & ~OPACITY_MASK) | (((uint32_t)type & 0x1) << + OPACITY_SHIFT); + + style->i.opacity = fixed; + + return CSS_OK; +} +#undef OPACITY_INDEX +#undef OPACITY_SHIFT +#undef OPACITY_MASK + +#define ORDER_INDEX 14 +#define ORDER_SHIFT 25 +#define ORDER_MASK 0x2000000 + +static inline css_error set_order(css_computed_style *style, uint8_t type, + int32_t integer) +{ + uint32_t *bits = &style->i.bits[ORDER_INDEX]; + + /* 1bit: t : type */ + *bits = (*bits & ~ORDER_MASK) | (((uint32_t)type & 0x1) << ORDER_SHIFT); + + style->i.order = integer; + + return CSS_OK; +} +#undef ORDER_INDEX +#undef ORDER_SHIFT +#undef ORDER_MASK + +#define ORPHANS_INDEX 14 +#define ORPHANS_SHIFT 26 +#define ORPHANS_MASK 0x4000000 + +static inline css_error set_orphans(css_computed_style *style, uint8_t type, + int32_t integer) +{ + uint32_t *bits = &style->i.bits[ORPHANS_INDEX]; + + /* 1bit: t : type */ + *bits = (*bits & ~ORPHANS_MASK) | (((uint32_t)type & 0x1) << + ORPHANS_SHIFT); + + style->i.orphans = integer; + + return CSS_OK; +} +#undef ORPHANS_INDEX +#undef ORPHANS_SHIFT +#undef ORPHANS_MASK + +#define OUTLINE_COLOR_INDEX 10 +#define OUTLINE_COLOR_SHIFT 6 +#define OUTLINE_COLOR_MASK 0xc0 + +static inline css_error set_outline_color(css_computed_style *style, uint8_t + type, css_color color) +{ + uint32_t *bits = &style->i.bits[OUTLINE_COLOR_INDEX]; + + /* 2bits: tt : type */ + *bits = (*bits & ~OUTLINE_COLOR_MASK) | (((uint32_t)type & 0x3) << + OUTLINE_COLOR_SHIFT); + + style->i.outline_color = color; + + return CSS_OK; +} +#undef OUTLINE_COLOR_INDEX +#undef OUTLINE_COLOR_SHIFT +#undef OUTLINE_COLOR_MASK + +#define OUTLINE_STYLE_INDEX 5 +#define OUTLINE_STYLE_SHIFT 0 +#define OUTLINE_STYLE_MASK 0xf + +static inline css_error set_outline_style(css_computed_style *style, uint8_t + type) +{ + uint32_t *bits = &style->i.bits[OUTLINE_STYLE_INDEX]; + + /* 4bits: tttt : type */ + *bits = (*bits & ~OUTLINE_STYLE_MASK) | (((uint32_t)type & 0xf) << + OUTLINE_STYLE_SHIFT); + + return CSS_OK; +} +#undef OUTLINE_STYLE_INDEX +#undef OUTLINE_STYLE_SHIFT +#undef OUTLINE_STYLE_MASK + +#define OUTLINE_WIDTH_INDEX 1 +#define OUTLINE_WIDTH_SHIFT 15 +#define OUTLINE_WIDTH_MASK 0x7f8000 + +static inline css_error set_outline_width(css_computed_style *style, uint8_t + type, css_fixed length, css_unit unit) +{ + uint32_t *bits = &style->i.bits[OUTLINE_WIDTH_INDEX]; + + /* 8bits: uuuuuttt : unit | type */ + *bits = (*bits & ~OUTLINE_WIDTH_MASK) | ((((uint32_t)type & 0x7) | ( + unit << 3)) << OUTLINE_WIDTH_SHIFT); + + style->i.outline_width = length; + + return CSS_OK; +} +#undef OUTLINE_WIDTH_INDEX +#undef OUTLINE_WIDTH_SHIFT +#undef OUTLINE_WIDTH_MASK + +#define OVERFLOW_X_INDEX 13 +#define OVERFLOW_X_SHIFT 13 +#define OVERFLOW_X_MASK 0xe000 + +static inline css_error set_overflow_x(css_computed_style *style, uint8_t type) +{ + uint32_t *bits = &style->i.bits[OVERFLOW_X_INDEX]; + + /* 3bits: ttt : type */ + *bits = (*bits & ~OVERFLOW_X_MASK) | (((uint32_t)type & 0x7) << + OVERFLOW_X_SHIFT); + + return CSS_OK; +} +#undef OVERFLOW_X_INDEX +#undef OVERFLOW_X_SHIFT +#undef OVERFLOW_X_MASK + +#define OVERFLOW_Y_INDEX 13 +#define OVERFLOW_Y_SHIFT 16 +#define OVERFLOW_Y_MASK 0x70000 + +static inline css_error set_overflow_y(css_computed_style *style, uint8_t type) +{ + uint32_t *bits = &style->i.bits[OVERFLOW_Y_INDEX]; + + /* 3bits: ttt : type */ + *bits = (*bits & ~OVERFLOW_Y_MASK) | (((uint32_t)type & 0x7) << + OVERFLOW_Y_SHIFT); + + return CSS_OK; +} +#undef OVERFLOW_Y_INDEX +#undef OVERFLOW_Y_SHIFT +#undef OVERFLOW_Y_MASK + +#define PADDING_BOTTOM_INDEX 8 +#define PADDING_BOTTOM_SHIFT 14 +#define PADDING_BOTTOM_MASK 0xfc000 + +static inline css_error set_padding_bottom(css_computed_style *style, uint8_t + type, css_fixed length, css_unit unit) +{ + uint32_t *bits = &style->i.bits[PADDING_BOTTOM_INDEX]; + + /* 6bits: uuuuut : unit | type */ + *bits = (*bits & ~PADDING_BOTTOM_MASK) | ((((uint32_t)type & 0x1) | ( + unit << 1)) << PADDING_BOTTOM_SHIFT); + + style->i.padding_bottom = length; + + return CSS_OK; +} +#undef PADDING_BOTTOM_INDEX +#undef PADDING_BOTTOM_SHIFT +#undef PADDING_BOTTOM_MASK + +#define PADDING_LEFT_INDEX 8 +#define PADDING_LEFT_SHIFT 20 +#define PADDING_LEFT_MASK 0x3f00000 + +static inline css_error set_padding_left(css_computed_style *style, uint8_t + type, css_fixed length, css_unit unit) +{ + uint32_t *bits = &style->i.bits[PADDING_LEFT_INDEX]; + + /* 6bits: uuuuut : unit | type */ + *bits = (*bits & ~PADDING_LEFT_MASK) | ((((uint32_t)type & 0x1) | (unit + << 1)) << PADDING_LEFT_SHIFT); + + style->i.padding_left = length; + + return CSS_OK; +} +#undef PADDING_LEFT_INDEX +#undef PADDING_LEFT_SHIFT +#undef PADDING_LEFT_MASK + +#define PADDING_RIGHT_INDEX 8 +#define PADDING_RIGHT_SHIFT 26 +#define PADDING_RIGHT_MASK 0xfc000000 + +static inline css_error set_padding_right(css_computed_style *style, uint8_t + type, css_fixed length, css_unit unit) +{ + uint32_t *bits = &style->i.bits[PADDING_RIGHT_INDEX]; + + /* 6bits: uuuuut : unit | type */ + *bits = (*bits & ~PADDING_RIGHT_MASK) | ((((uint32_t)type & 0x1) | ( + unit << 1)) << PADDING_RIGHT_SHIFT); + + style->i.padding_right = length; + + return CSS_OK; +} +#undef PADDING_RIGHT_INDEX +#undef PADDING_RIGHT_SHIFT +#undef PADDING_RIGHT_MASK + +#define PADDING_TOP_INDEX 3 +#define PADDING_TOP_SHIFT 5 +#define PADDING_TOP_MASK 0x7e0 + +static inline css_error set_padding_top(css_computed_style *style, uint8_t + type, css_fixed length, css_unit unit) +{ + uint32_t *bits = &style->i.bits[PADDING_TOP_INDEX]; + + /* 6bits: uuuuut : unit | type */ + *bits = (*bits & ~PADDING_TOP_MASK) | ((((uint32_t)type & 0x1) | (unit + << 1)) << PADDING_TOP_SHIFT); + + style->i.padding_top = length; + + return CSS_OK; +} +#undef PADDING_TOP_INDEX +#undef PADDING_TOP_SHIFT +#undef PADDING_TOP_MASK + +#define PAGE_BREAK_AFTER_INDEX 13 +#define PAGE_BREAK_AFTER_SHIFT 19 +#define PAGE_BREAK_AFTER_MASK 0x380000 + +static inline css_error set_page_break_after(css_computed_style *style, uint8_t + type) +{ + uint32_t *bits = &style->i.bits[PAGE_BREAK_AFTER_INDEX]; + + /* 3bits: ttt : type */ + *bits = (*bits & ~PAGE_BREAK_AFTER_MASK) | (((uint32_t)type & 0x7) << + PAGE_BREAK_AFTER_SHIFT); + + return CSS_OK; +} +#undef PAGE_BREAK_AFTER_INDEX +#undef PAGE_BREAK_AFTER_SHIFT +#undef PAGE_BREAK_AFTER_MASK + +#define PAGE_BREAK_BEFORE_INDEX 13 +#define PAGE_BREAK_BEFORE_SHIFT 22 +#define PAGE_BREAK_BEFORE_MASK 0x1c00000 + +static inline css_error set_page_break_before(css_computed_style *style, + uint8_t type) +{ + uint32_t *bits = &style->i.bits[PAGE_BREAK_BEFORE_INDEX]; + + /* 3bits: ttt : type */ + *bits = (*bits & ~PAGE_BREAK_BEFORE_MASK) | (((uint32_t)type & 0x7) << + PAGE_BREAK_BEFORE_SHIFT); + + return CSS_OK; +} +#undef PAGE_BREAK_BEFORE_INDEX +#undef PAGE_BREAK_BEFORE_SHIFT +#undef PAGE_BREAK_BEFORE_MASK + +#define PAGE_BREAK_INSIDE_INDEX 10 +#define PAGE_BREAK_INSIDE_SHIFT 8 +#define PAGE_BREAK_INSIDE_MASK 0x300 + +static inline css_error set_page_break_inside(css_computed_style *style, + uint8_t type) +{ + uint32_t *bits = &style->i.bits[PAGE_BREAK_INSIDE_INDEX]; + + /* 2bits: tt : type */ + *bits = (*bits & ~PAGE_BREAK_INSIDE_MASK) | (((uint32_t)type & 0x3) << + PAGE_BREAK_INSIDE_SHIFT); + + return CSS_OK; +} +#undef PAGE_BREAK_INSIDE_INDEX +#undef PAGE_BREAK_INSIDE_SHIFT +#undef PAGE_BREAK_INSIDE_MASK + +#define POSITION_INDEX 13 +#define POSITION_SHIFT 25 +#define POSITION_MASK 0xe000000 + +static inline css_error set_position(css_computed_style *style, uint8_t type) +{ + uint32_t *bits = &style->i.bits[POSITION_INDEX]; + + /* 3bits: ttt : type */ + *bits = (*bits & ~POSITION_MASK) | (((uint32_t)type & 0x7) << + POSITION_SHIFT); + + return CSS_OK; +} +#undef POSITION_INDEX +#undef POSITION_SHIFT +#undef POSITION_MASK + +#define QUOTES_INDEX 14 +#define QUOTES_SHIFT 27 +#define QUOTES_MASK 0x8000000 + +static inline css_error set_quotes(css_computed_style *style, uint8_t type, + lwc_string **string_arr) +{ + uint32_t *bits = &style->i.bits[QUOTES_INDEX]; + + /* 1bit: t : type */ + *bits = (*bits & ~QUOTES_MASK) | (((uint32_t)type & 0x1) << + QUOTES_SHIFT); + + lwc_string **old_string_arr = style->quotes; + lwc_string **s; + + for (s = string_arr; s != NULL && *s != NULL; s++) + *s = lwc_string_ref(*s); + + style->quotes = string_arr; + + /* Free existing array */ + if (old_string_arr != NULL) { + for (s = old_string_arr; *s != NULL; s++) + lwc_string_unref(*s); + + if (old_string_arr != string_arr) + free(old_string_arr); + } + + return CSS_OK; +} +#undef QUOTES_INDEX +#undef QUOTES_SHIFT +#undef QUOTES_MASK + +#define RIGHT_INDEX 4 +#define RIGHT_SHIFT 11 +#define RIGHT_MASK 0x3f800 + +static inline css_error set_right(css_computed_style *style, uint8_t type, + css_fixed length, css_unit unit) +{ + uint32_t *bits = &style->i.bits[RIGHT_INDEX]; + + /* 7bits: uuuuutt : unit | type */ + *bits = (*bits & ~RIGHT_MASK) | ((((uint32_t)type & 0x3) | (unit << 2)) + << RIGHT_SHIFT); + + style->i.right = length; + + return CSS_OK; +} +#undef RIGHT_INDEX +#undef RIGHT_SHIFT +#undef RIGHT_MASK + +#define STROKE_OPACITY_INDEX 13 +#define STROKE_OPACITY_SHIFT 0 +#define STROKE_OPACITY_MASK 0x1 + +static inline css_error set_stroke_opacity(css_computed_style *style, uint8_t + type, css_fixed fixed) +{ + uint32_t *bits = &style->i.bits[STROKE_OPACITY_INDEX]; + + /* 1bit: t : type */ + *bits = (*bits & ~STROKE_OPACITY_MASK) | (((uint32_t)type & 0x1) << + STROKE_OPACITY_SHIFT); + + style->i.stroke_opacity = fixed; + + return CSS_OK; +} +#undef STROKE_OPACITY_INDEX +#undef STROKE_OPACITY_SHIFT +#undef STROKE_OPACITY_MASK + +#define TABLE_LAYOUT_INDEX 10 +#define TABLE_LAYOUT_SHIFT 10 +#define TABLE_LAYOUT_MASK 0xc00 + +static inline css_error set_table_layout(css_computed_style *style, uint8_t + type) +{ + uint32_t *bits = &style->i.bits[TABLE_LAYOUT_INDEX]; + + /* 2bits: tt : type */ + *bits = (*bits & ~TABLE_LAYOUT_MASK) | (((uint32_t)type & 0x3) << + TABLE_LAYOUT_SHIFT); + + return CSS_OK; +} +#undef TABLE_LAYOUT_INDEX +#undef TABLE_LAYOUT_SHIFT +#undef TABLE_LAYOUT_MASK + +#define TEXT_ALIGN_INDEX 4 +#define TEXT_ALIGN_SHIFT 0 +#define TEXT_ALIGN_MASK 0xf + +static inline css_error set_text_align(css_computed_style *style, uint8_t type) +{ + uint32_t *bits = &style->i.bits[TEXT_ALIGN_INDEX]; + + /* 4bits: tttt : type */ + *bits = (*bits & ~TEXT_ALIGN_MASK) | (((uint32_t)type & 0xf) << + TEXT_ALIGN_SHIFT); + + return CSS_OK; +} +#undef TEXT_ALIGN_INDEX +#undef TEXT_ALIGN_SHIFT +#undef TEXT_ALIGN_MASK + +#define TEXT_DECORATION_INDEX 3 +#define TEXT_DECORATION_SHIFT 0 +#define TEXT_DECORATION_MASK 0x1f + +static inline css_error set_text_decoration(css_computed_style *style, uint8_t + type) +{ + uint32_t *bits = &style->i.bits[TEXT_DECORATION_INDEX]; + + /* 5bits: ttttt : type */ + *bits = (*bits & ~TEXT_DECORATION_MASK) | (((uint32_t)type & 0x1f) << + TEXT_DECORATION_SHIFT); + + return CSS_OK; +} +#undef TEXT_DECORATION_INDEX +#undef TEXT_DECORATION_SHIFT +#undef TEXT_DECORATION_MASK + +#define TEXT_INDENT_INDEX 2 +#define TEXT_INDENT_SHIFT 0 +#define TEXT_INDENT_MASK 0x3f + +static inline css_error set_text_indent(css_computed_style *style, uint8_t + type, css_fixed length, css_unit unit) +{ + uint32_t *bits = &style->i.bits[TEXT_INDENT_INDEX]; + + /* 6bits: uuuuut : unit | type */ + *bits = (*bits & ~TEXT_INDENT_MASK) | ((((uint32_t)type & 0x1) | (unit + << 1)) << TEXT_INDENT_SHIFT); + + style->i.text_indent = length; + + return CSS_OK; +} +#undef TEXT_INDENT_INDEX +#undef TEXT_INDENT_SHIFT +#undef TEXT_INDENT_MASK + +#define TEXT_TRANSFORM_INDEX 9 +#define TEXT_TRANSFORM_SHIFT 0 +#define TEXT_TRANSFORM_MASK 0x7 + +static inline css_error set_text_transform(css_computed_style *style, uint8_t + type) +{ + uint32_t *bits = &style->i.bits[TEXT_TRANSFORM_INDEX]; + + /* 3bits: ttt : type */ + *bits = (*bits & ~TEXT_TRANSFORM_MASK) | (((uint32_t)type & 0x7) << + TEXT_TRANSFORM_SHIFT); + + return CSS_OK; +} +#undef TEXT_TRANSFORM_INDEX +#undef TEXT_TRANSFORM_SHIFT +#undef TEXT_TRANSFORM_MASK + +#define TOP_INDEX 4 +#define TOP_SHIFT 18 +#define TOP_MASK 0x1fc0000 + +static inline css_error set_top(css_computed_style *style, uint8_t type, + css_fixed length, css_unit unit) +{ + uint32_t *bits = &style->i.bits[TOP_INDEX]; + + /* 7bits: uuuuutt : unit | type */ + *bits = (*bits & ~TOP_MASK) | ((((uint32_t)type & 0x3) | (unit << 2)) + << TOP_SHIFT); + + style->i.top = length; + + return CSS_OK; +} +#undef TOP_INDEX +#undef TOP_SHIFT +#undef TOP_MASK + +#define UNICODE_BIDI_INDEX 10 +#define UNICODE_BIDI_SHIFT 12 +#define UNICODE_BIDI_MASK 0x3000 + +static inline css_error set_unicode_bidi(css_computed_style *style, uint8_t + type) +{ + uint32_t *bits = &style->i.bits[UNICODE_BIDI_INDEX]; + + /* 2bits: tt : type */ + *bits = (*bits & ~UNICODE_BIDI_MASK) | (((uint32_t)type & 0x3) << + UNICODE_BIDI_SHIFT); + + return CSS_OK; +} +#undef UNICODE_BIDI_INDEX +#undef UNICODE_BIDI_SHIFT +#undef UNICODE_BIDI_MASK + +#define VERTICAL_ALIGN_INDEX 12 +#define VERTICAL_ALIGN_SHIFT 1 +#define VERTICAL_ALIGN_MASK 0x3fe + +static inline css_error set_vertical_align(css_computed_style *style, uint8_t + type, css_fixed length, css_unit unit) +{ + uint32_t *bits = &style->i.bits[VERTICAL_ALIGN_INDEX]; + + /* 9bits: uuuuutttt : unit | type */ + *bits = (*bits & ~VERTICAL_ALIGN_MASK) | ((((uint32_t)type & 0xf) | ( + unit << 4)) << VERTICAL_ALIGN_SHIFT); + + style->i.vertical_align = length; + + return CSS_OK; +} +#undef VERTICAL_ALIGN_INDEX +#undef VERTICAL_ALIGN_SHIFT +#undef VERTICAL_ALIGN_MASK + +#define VISIBILITY_INDEX 10 +#define VISIBILITY_SHIFT 14 +#define VISIBILITY_MASK 0xc000 + +static inline css_error set_visibility(css_computed_style *style, uint8_t type) +{ + uint32_t *bits = &style->i.bits[VISIBILITY_INDEX]; + + /* 2bits: tt : type */ + *bits = (*bits & ~VISIBILITY_MASK) | (((uint32_t)type & 0x3) << + VISIBILITY_SHIFT); + + return CSS_OK; +} +#undef VISIBILITY_INDEX +#undef VISIBILITY_SHIFT +#undef VISIBILITY_MASK + +#define WHITE_SPACE_INDEX 8 +#define WHITE_SPACE_SHIFT 0 +#define WHITE_SPACE_MASK 0x7 + +static inline css_error set_white_space(css_computed_style *style, uint8_t type) +{ + uint32_t *bits = &style->i.bits[WHITE_SPACE_INDEX]; + + /* 3bits: ttt : type */ + *bits = (*bits & ~WHITE_SPACE_MASK) | (((uint32_t)type & 0x7) << + WHITE_SPACE_SHIFT); + + return CSS_OK; +} +#undef WHITE_SPACE_INDEX +#undef WHITE_SPACE_SHIFT +#undef WHITE_SPACE_MASK + +#define WIDOWS_INDEX 12 +#define WIDOWS_SHIFT 0 +#define WIDOWS_MASK 0x1 + +static inline css_error set_widows(css_computed_style *style, uint8_t type, + int32_t integer) +{ + uint32_t *bits = &style->i.bits[WIDOWS_INDEX]; + + /* 1bit: t : type */ + *bits = (*bits & ~WIDOWS_MASK) | (((uint32_t)type & 0x1) << + WIDOWS_SHIFT); + + style->i.widows = integer; + + return CSS_OK; +} +#undef WIDOWS_INDEX +#undef WIDOWS_SHIFT +#undef WIDOWS_MASK + +#define WIDTH_INDEX 4 +#define WIDTH_SHIFT 25 +#define WIDTH_MASK 0xfe000000 + +static inline css_error set_width(css_computed_style *style, uint8_t type, + css_fixed length, css_unit unit) +{ + uint32_t *bits = &style->i.bits[WIDTH_INDEX]; + + /* 7bits: uuuuutt : unit | type */ + *bits = (*bits & ~WIDTH_MASK) | ((((uint32_t)type & 0x3) | (unit << 2)) + << WIDTH_SHIFT); + + style->i.width = length; + + return CSS_OK; +} +#undef WIDTH_INDEX +#undef WIDTH_SHIFT +#undef WIDTH_MASK + +#define WORD_SPACING_INDEX 1 +#define WORD_SPACING_SHIFT 0 +#define WORD_SPACING_MASK 0x7f + +static inline css_error set_word_spacing(css_computed_style *style, uint8_t + type, css_fixed length, css_unit unit) +{ + uint32_t *bits = &style->i.bits[WORD_SPACING_INDEX]; + + /* 7bits: uuuuutt : unit | type */ + *bits = (*bits & ~WORD_SPACING_MASK) | ((((uint32_t)type & 0x3) | (unit + << 2)) << WORD_SPACING_SHIFT); + + style->i.word_spacing = length; + + return CSS_OK; +} +#undef WORD_SPACING_INDEX +#undef WORD_SPACING_SHIFT +#undef WORD_SPACING_MASK + +#define WRITING_MODE_INDEX 10 +#define WRITING_MODE_SHIFT 16 +#define WRITING_MODE_MASK 0x30000 + +static inline css_error set_writing_mode(css_computed_style *style, uint8_t + type) +{ + uint32_t *bits = &style->i.bits[WRITING_MODE_INDEX]; + + /* 2bits: tt : type */ + *bits = (*bits & ~WRITING_MODE_MASK) | (((uint32_t)type & 0x3) << + WRITING_MODE_SHIFT); + + return CSS_OK; +} +#undef WRITING_MODE_INDEX +#undef WRITING_MODE_SHIFT +#undef WRITING_MODE_MASK + +#define Z_INDEX_INDEX 10 +#define Z_INDEX_SHIFT 18 +#define Z_INDEX_MASK 0xc0000 + +static inline css_error set_z_index(css_computed_style *style, uint8_t type, + int32_t integer) +{ + uint32_t *bits = &style->i.bits[Z_INDEX_INDEX]; + + /* 2bits: tt : type */ + *bits = (*bits & ~Z_INDEX_MASK) | (((uint32_t)type & 0x3) << + Z_INDEX_SHIFT); + + style->i.z_index = integer; + + return CSS_OK; +} +#undef Z_INDEX_INDEX +#undef Z_INDEX_SHIFT +#undef Z_INDEX_MASK diff --git a/src/select/bloom.h b/src/select/bloom.h index 11628ab..dda4cca 100644 --- a/src/select/bloom.h +++ b/src/select/bloom.h @@ -9,22 +9,30 @@ * Bloom filter for CSS style selection optimisation. * * Attempting to match CSS rules by querying the client about DOM nodes via - * the selection callbacks is slow. To avoid this, clients may pass a node - * bloom filter to css_get_style. This bloom filter has bits set according - * to the node's ancestor element names, class names and id names. + * the selection callbacks is slow. To avoid the slow matching of CSS rule + * selector chains, we build up two bloom filters. One describing the rule + * selector chain, and one describing the node we are selecting for in + * css_get_style. + * + * These bloom filters have bits set according to the node's ancestor element + * names, class names and id names. * * Generate the bloom filter by adding calling css_bloom_add_hash() on each * ancestor element name, class name and id name for the node. * - * Use the insesnsitive hash value: + * Use the insensitive hash value: * * lwc_err = lwc_string_caseless_hash_value(str, &hash); + * + * We avoid matching most selector chains by checking whether the rule bloom + * is a subset of the node bloom. */ #ifndef libcss_bloom_h_ #define libcss_bloom_h_ #include <stdint.h> +#include <string.h> /* Size of bloom filter as multiple of 32 bits. * Has to be 4, 8, or 16. @@ -88,7 +96,8 @@ static inline bool css_bloom_has_hash(const css_bloom bloom[CSS_BLOOM_SIZE], * \param b superset bloom * \return true iff 'a' is subset of 'b' */ -static inline bool css_bloom_in_bloom(const css_bloom a[CSS_BLOOM_SIZE], +static inline bool css_bloom_in_bloom( + const css_bloom a[CSS_BLOOM_SIZE], const css_bloom b[CSS_BLOOM_SIZE]) { if ((a[0] & b[0]) != a[0]) @@ -132,13 +141,14 @@ static inline bool css_bloom_in_bloom(const css_bloom a[CSS_BLOOM_SIZE], /** - * Merge bloom 'a' into bloom 'b'. + * Merge bloom \ref a into bloom \ref b. * * \param a bloom to insert * \param b target bloom */ -static inline void css_bloom_merge(const css_bloom a[CSS_BLOOM_SIZE], - css_bloom b[CSS_BLOOM_SIZE]) +static inline void css_bloom_merge( + const css_bloom a[restrict CSS_BLOOM_SIZE], + css_bloom b[restrict CSS_BLOOM_SIZE]) { b[0] |= a[0]; b[1] |= a[1]; @@ -170,27 +180,7 @@ static inline void css_bloom_merge(const css_bloom a[CSS_BLOOM_SIZE], */ static inline void css_bloom_init(css_bloom bloom[CSS_BLOOM_SIZE]) { - bloom[0] = 0; - bloom[1] = 0; - bloom[2] = 0; - bloom[3] = 0; -#if (CSS_BLOOM_SIZE > 4) - bloom[4] = 0; - bloom[5] = 0; - bloom[6] = 0; - bloom[7] = 0; -#endif -#if (CSS_BLOOM_SIZE > 8) - bloom[8] = 0; - bloom[9] = 0; - bloom[10] = 0; - bloom[11] = 0; - bloom[12] = 0; - bloom[13] = 0; - bloom[14] = 0; - bloom[15] = 0; -#endif + memset(bloom, 0, sizeof(*bloom) * CSS_BLOOM_SIZE); } #endif - diff --git a/src/select/computed.c b/src/select/computed.c index 03e7c15..78f3b80 100644 --- a/src/select/computed.c +++ b/src/select/computed.c @@ -12,6 +12,7 @@ #include "select/dispatch.h" #include "select/propget.h" #include "select/propset.h" +#include "select/unit.h" #include "utils/utils.h" static css_error compute_absolute_color(css_computed_style *style, @@ -83,121 +84,83 @@ css_error css__computed_style_create(css_computed_style **result) } /** - * Destroy an uncommon computed style section + * Destroy a computed style * * \param style Style to destroy * \return CSS_OK on success, appropriate error otherwise */ -css_error css__computed_uncommon_destroy(css_computed_uncommon *uncommon) +css_error css_computed_style_destroy(css_computed_style *style) { - if (uncommon == NULL) + if (style == NULL) return CSS_BADPARM; - if (uncommon->count > 1) { - uncommon->count--; + if (style->count > 1) { + style->count--; return CSS_OK; - } else if (uncommon->count == 1) { - css__arena_remove_uncommon_style(uncommon); + } else if (style->count == 1) { + css__arena_remove_style(style); } - if (uncommon != NULL) { - if (uncommon->counter_increment != NULL) { - css_computed_counter *c; - - for (c = uncommon->counter_increment; - c->name != NULL; c++) { - lwc_string_unref(c->name); - } + if (style->counter_increment != NULL) { + css_computed_counter *c; - free(uncommon->counter_increment); + for (c = style->counter_increment; c->name != NULL; c++) { + lwc_string_unref(c->name); } - if (uncommon->counter_reset != NULL) { - css_computed_counter *c; - - for (c = uncommon->counter_reset; - c->name != NULL; c++) { - lwc_string_unref(c->name); - } - - free(uncommon->counter_reset); - } - - if (uncommon->cursor != NULL) { - lwc_string **s; - - for (s = uncommon->cursor; *s != NULL; s++) { - lwc_string_unref(*s); - } + free(style->counter_increment); + } - free(uncommon->cursor); - } + if (style->counter_reset != NULL) { + css_computed_counter *c; - if (uncommon->content != NULL) { - css_computed_content_item *c; - - for (c = uncommon->content; - c->type != CSS_COMPUTED_CONTENT_NONE; - c++) { - switch (c->type) { - case CSS_COMPUTED_CONTENT_STRING: - lwc_string_unref(c->data.string); - break; - case CSS_COMPUTED_CONTENT_URI: - lwc_string_unref(c->data.uri); - break; - case CSS_COMPUTED_CONTENT_ATTR: - lwc_string_unref(c->data.attr); - break; - case CSS_COMPUTED_CONTENT_COUNTER: - lwc_string_unref(c->data.counter.name); - break; - case CSS_COMPUTED_CONTENT_COUNTERS: - lwc_string_unref(c->data.counters.name); - lwc_string_unref(c->data.counters.sep); - break; - default: - break; - } - } - - free(uncommon->content); + for (c = style->counter_reset; c->name != NULL; c++) { + lwc_string_unref(c->name); } - free(uncommon); + free(style->counter_reset); } - return CSS_OK; -} - -/** - * Destroy a computed style - * - * \param style Style to destroy - * \return CSS_OK on success, appropriate error otherwise - */ -css_error css_computed_style_destroy(css_computed_style *style) -{ - if (style == NULL) - return CSS_BADPARM; - - css__computed_uncommon_destroy(style->i.uncommon); + if (style->cursor != NULL) { + lwc_string **s; - if (style->count > 1) { - style->count--; - return CSS_OK; + for (s = style->cursor; *s != NULL; s++) { + lwc_string_unref(*s); + } - } else if (style->count == 1) { - css__arena_remove_style(style); + free(style->cursor); } - if (style->page != NULL) { - free(style->page); - } + if (style->content != NULL) { + css_computed_content_item *c; + + for (c = style->content; + c->type != CSS_COMPUTED_CONTENT_NONE; + c++) { + switch (c->type) { + case CSS_COMPUTED_CONTENT_STRING: + lwc_string_unref(c->data.string); + break; + case CSS_COMPUTED_CONTENT_URI: + lwc_string_unref(c->data.uri); + break; + case CSS_COMPUTED_CONTENT_ATTR: + lwc_string_unref(c->data.attr); + break; + case CSS_COMPUTED_CONTENT_COUNTER: + lwc_string_unref(c->data.counter.name); + break; + case CSS_COMPUTED_CONTENT_COUNTERS: + lwc_string_unref(c->data.counters.name); + lwc_string_unref(c->data.counters.sep); + break; + default: + break; + } + } - if (style->i.aural != NULL) { - free(style->i.aural); + free(style->content); } if (style->font_family != NULL) { @@ -250,7 +213,7 @@ css_error css__computed_style_initialise(css_computed_style *style, return CSS_BADPARM; state.node = NULL; - state.media = CSS_MEDIA_ALL; + state.media = NULL; state.results = NULL; state.computed = style; state.handler = handler; @@ -259,8 +222,7 @@ css_error css__computed_style_initialise(css_computed_style *style, for (i = 0; i < CSS_N_PROPERTIES; i++) { /* No need to initialise anything other than the normal * properties -- the others are handled by the accessors */ - if (prop_dispatch[i].inherited == false && - prop_dispatch[i].group == GROUP_NORMAL) { + if (prop_dispatch[i].inherited == false) { error = prop_dispatch[i].initial(&state); if (error != CSS_OK) return error; @@ -271,6 +233,37 @@ css_error css__computed_style_initialise(css_computed_style *style, } /** + * Clone a computed style + * + * \param orig Style to copy + * \param clone_out Returns cloned style on success + * \return CSS_OK on success. + */ +css_error css__computed_style_clone( + const css_computed_style *orig, + css_computed_style **clone_out) +{ + css_error error; + css_computed_style *clone; + + error = css__computed_style_create(&clone); + if (error != CSS_OK) { + return error; + } + + for (size_t i = 0; i < CSS_N_PROPERTIES; i++) { + error = prop_dispatch[i].copy(orig, clone); + if (error != CSS_OK) { + css_computed_style_destroy(clone); + return error; + } + } + + *clone_out = clone; + return CSS_OK; +} + +/** * Compose two computed styles * * \param parent Parent style @@ -286,9 +279,7 @@ css_error css__computed_style_initialise(css_computed_style *style, css_error css_computed_style_compose( const css_computed_style *restrict parent, const css_computed_style *restrict child, - css_error (*compute_font_size)(void *pw, - const css_hint *parent, css_hint *size), - void *pw, + const css_unit_ctx *unit_ctx, css_computed_style **restrict result) { css_computed_style *composed; @@ -307,25 +298,6 @@ css_error css_computed_style_compose( /* Iterate through the properties */ for (i = 0; i < CSS_N_PROPERTIES; i++) { - /* Skip any in extension blocks if the block does not exist */ - switch(prop_dispatch[i].group) { - case GROUP_NORMAL: - break; - case GROUP_UNCOMMON: - if (parent->i.uncommon == NULL && - child->i.uncommon == NULL) - continue; - break; - case GROUP_PAGE: - if (parent->page == NULL && child->page == NULL) - continue; - break; - case GROUP_AURAL: - if (parent->i.aural == NULL && child->i.aural == NULL) - continue; - break; - } - /* Compose the property */ error = prop_dispatch[i].compose(parent, child, composed); if (error != CSS_OK) @@ -333,8 +305,7 @@ css_error css_computed_style_compose( } /* Finally, compute absolute values for everything */ - error = css__compute_absolute_values(parent, composed, - compute_font_size, pw); + error = css__compute_absolute_values(parent, composed, unit_ctx); if (error != CSS_OK) { return error; } @@ -749,13 +720,39 @@ uint8_t css_computed_font_style(const css_computed_style *style) uint8_t css_computed_min_height(const css_computed_style *style, css_fixed *length, css_unit *unit) { - return get_min_height(style, length, unit); + uint8_t min_height = get_min_height(style, length, unit); + + if (min_height == CSS_MIN_HEIGHT_AUTO) { + uint8_t display = get_display(style); + + if (display != CSS_DISPLAY_FLEX && + display != CSS_DISPLAY_INLINE_FLEX) { + min_height = CSS_MIN_HEIGHT_SET; + *length = 0; + *unit = CSS_UNIT_PX; + } + } + + return min_height; } uint8_t css_computed_min_width(const css_computed_style *style, css_fixed *length, css_unit *unit) { - return get_min_width(style, length, unit); + uint8_t min_width = get_min_width(style, length, unit); + + if (min_width == CSS_MIN_WIDTH_AUTO) { + uint8_t display = get_display(style); + + if (display != CSS_DISPLAY_FLEX && + display != CSS_DISPLAY_INLINE_FLEX) { + min_width = CSS_MIN_WIDTH_SET; + *length = 0; + *unit = CSS_UNIT_PX; + } + } + + return min_width; } uint8_t css_computed_background_repeat(const css_computed_style *style) @@ -813,6 +810,18 @@ uint8_t css_computed_opacity(const css_computed_style *style, return get_opacity(style, opacity); } +uint8_t css_computed_fill_opacity(const css_computed_style *style, + css_fixed *fill_opacity) +{ + return get_fill_opacity(style, fill_opacity); +} + +uint8_t css_computed_stroke_opacity(const css_computed_style *style, + css_fixed *stroke_opacity) +{ + return get_stroke_opacity(style, stroke_opacity); +} + uint8_t css_computed_text_transform(const css_computed_style *style) { return get_text_transform(style); @@ -927,6 +936,10 @@ uint8_t css_computed_display(const css_computed_style *style, root /* 4. */) { if (display == CSS_DISPLAY_INLINE_TABLE) { return CSS_DISPLAY_TABLE; + } else if (display == CSS_DISPLAY_INLINE_FLEX) { + return CSS_DISPLAY_FLEX; + } else if (display == CSS_DISPLAY_INLINE_GRID) { + return CSS_DISPLAY_GRID; } else if (display == CSS_DISPLAY_INLINE || display == CSS_DISPLAY_RUN_IN || display == CSS_DISPLAY_TABLE_ROW_GROUP || @@ -1054,6 +1067,59 @@ uint8_t css_computed_widows(const css_computed_style *style, return get_widows(style, widows); } +uint8_t css_computed_align_content(const css_computed_style *style) +{ + return get_align_content(style); +} + +uint8_t css_computed_align_items(const css_computed_style *style) +{ + return get_align_items(style); +} + +uint8_t css_computed_align_self(const css_computed_style *style) +{ + return get_align_self(style); +} + +uint8_t css_computed_flex_basis(const css_computed_style *style, + css_fixed *length, css_unit *unit) +{ + return get_flex_basis(style, length, unit); +} + +uint8_t css_computed_flex_direction(const css_computed_style *style) +{ + return get_flex_direction(style); +} + +uint8_t css_computed_flex_grow(const css_computed_style *style, + css_fixed *number) +{ + return get_flex_grow(style, number); +} + +uint8_t css_computed_flex_shrink(const css_computed_style *style, + css_fixed *number) +{ + return get_flex_shrink(style, number); +} + +uint8_t css_computed_flex_wrap(const css_computed_style *style) +{ + return get_flex_wrap(style); +} + +uint8_t css_computed_justify_content(const css_computed_style *style) +{ + return get_justify_content(style); +} + +uint8_t css_computed_order(const css_computed_style *style, + int32_t *order) +{ + return get_order(style, order); +} /****************************************************************************** * Library internals * @@ -1064,31 +1130,36 @@ uint8_t css_computed_widows(const css_computed_style *style, * * \param parent Parent style, or NULL for tree root * \param style Computed style to process - * \param compute_font_size Callback to calculate an absolute font-size - * \param pw Private word for callback + * \param unit_ctx Client length conversion context. * \return CSS_OK on success. */ css_error css__compute_absolute_values(const css_computed_style *parent, css_computed_style *style, - css_error (*compute_font_size)(void *pw, - const css_hint *parent, css_hint *size), - void *pw) + const css_unit_ctx *unit_ctx) { + css_hint_length *ref_length = NULL; css_hint psize, size, ex_size; css_error error; - /* Ensure font-size is absolute */ + /* Get reference font-size for relative sizes. */ if (parent != NULL) { psize.status = get_font_size(parent, &psize.data.length.value, &psize.data.length.unit); + if (psize.status != CSS_FONT_SIZE_DIMENSION) { + return CSS_BADPARM; + } + ref_length = &psize.data.length; } size.status = get_font_size(style, &size.data.length.value, &size.data.length.unit); - error = compute_font_size(pw, parent != NULL ? &psize : NULL, &size); + error = css_unit_compute_absolute_font_size(ref_length, + unit_ctx->root_style, + unit_ctx->font_size_default, + &size); if (error != CSS_OK) return error; @@ -1102,7 +1173,12 @@ css_error css__compute_absolute_values(const css_computed_style *parent, ex_size.status = CSS_FONT_SIZE_DIMENSION; ex_size.data.length.value = INTTOFIX(1); ex_size.data.length.unit = CSS_UNIT_EX; - error = compute_font_size(pw, &size, &ex_size); + + error = css_unit_compute_absolute_font_size( + &size.data.length, + unit_ctx->root_style, + unit_ctx->font_size_default, + &ex_size); if (error != CSS_OK) return error; @@ -1205,76 +1281,79 @@ css_error css__compute_absolute_values(const css_computed_style *parent, if (error != CSS_OK) return error; - /* Uncommon properties */ - if (style->i.uncommon != NULL) { - /* Fix up border-spacing */ - error = compute_absolute_length_pair(style, - &ex_size.data.length, - get_border_spacing, - set_border_spacing); - if (error != CSS_OK) - return error; + /* Fix up flex-basis */ + error = compute_absolute_length(style, &ex_size.data.length, + get_flex_basis, set_flex_basis); + if (error != CSS_OK) + return error; - /* Fix up clip */ - error = compute_absolute_clip(style, &ex_size.data.length); - if (error != CSS_OK) - return error; + /* Fix up border-spacing */ + error = compute_absolute_length_pair(style, + &ex_size.data.length, + get_border_spacing, + set_border_spacing); + if (error != CSS_OK) + return error; - /* Fix up letter-spacing */ - error = compute_absolute_length(style, - &ex_size.data.length, - get_letter_spacing, - set_letter_spacing); - if (error != CSS_OK) - return error; + /* Fix up clip */ + error = compute_absolute_clip(style, &ex_size.data.length); + if (error != CSS_OK) + return error; - /* Fix up outline-color */ - error = compute_absolute_color(style, - get_outline_color, - set_outline_color); - if (error != CSS_OK) - return error; + /* Fix up letter-spacing */ + error = compute_absolute_length(style, + &ex_size.data.length, + get_letter_spacing, + set_letter_spacing); + if (error != CSS_OK) + return error; - /* Fix up outline-width */ - error = compute_absolute_border_side_width(style, - &ex_size.data.length, - get_outline_width, - set_outline_width); - if (error != CSS_OK) - return error; + /* Fix up outline-color */ + error = compute_absolute_color(style, + get_outline_color, + set_outline_color); + if (error != CSS_OK) + return error; - /* Fix up word-spacing */ - error = compute_absolute_length(style, - &ex_size.data.length, - get_word_spacing, - set_word_spacing); - if (error != CSS_OK) - return error; + /* Fix up outline-width */ + error = compute_absolute_border_side_width(style, + &ex_size.data.length, + get_outline_width, + set_outline_width); + if (error != CSS_OK) + return error; - /* Fix up column-rule-width */ - error = compute_absolute_border_side_width(style, - &ex_size.data.length, - get_column_rule_width, - set_column_rule_width); - if (error != CSS_OK) - return error; + /* Fix up word-spacing */ + error = compute_absolute_length(style, + &ex_size.data.length, + get_word_spacing, + set_word_spacing); + if (error != CSS_OK) + return error; - /* Fix up column-width */ - error = compute_absolute_length(style, - &ex_size.data.length, - get_column_width, - set_column_width); - if (error != CSS_OK) + /* Fix up column-rule-width */ + error = compute_absolute_border_side_width(style, + &ex_size.data.length, + get_column_rule_width, + set_column_rule_width); + if (error != CSS_OK) return error; - /* Fix up column-gap */ - error = compute_absolute_length(style, - &ex_size.data.length, - get_column_gap, - set_column_gap); - if (error != CSS_OK) + /* Fix up column-width */ + error = compute_absolute_length(style, + &ex_size.data.length, + get_column_width, + set_column_width); + if (error != CSS_OK) return error; - } + + /* Fix up column-gap */ + error = compute_absolute_length(style, + &ex_size.data.length, + get_column_gap, + set_column_gap); + if (error != CSS_OK) + return error; return CSS_OK; } @@ -1434,6 +1513,8 @@ css_error compute_absolute_border_side_width(css_computed_style *style, unit = ex_size->unit; } break; + default: + return CSS_INVALID; } return set(style, CSS_BORDER_WIDTH_WIDTH, length, unit); @@ -1674,8 +1755,8 @@ css_error compute_absolute_length(css_computed_style *style, css_error (*set)(css_computed_style *style, uint8_t type, css_fixed len, css_unit unit)) { + css_unit unit = CSS_UNIT_PX; css_fixed length; - css_unit unit; uint8_t type; type = get(style, &length, &unit); @@ -1715,6 +1796,10 @@ css_error compute_absolute_length_pair(css_computed_style *style, type = get(style, &length1, &unit1, &length2, &unit2); + if (type != CSS_BACKGROUND_POSITION_SET) { + return CSS_OK; + } + if (unit1 == CSS_UNIT_EX) { length1 = FMUL(length1, ex_size->value); unit1 = ex_size->unit; diff --git a/src/select/computed.h b/src/select/computed.h index 9f2abdd..a1e4eed 100644 --- a/src/select/computed.h +++ b/src/select/computed.h @@ -10,322 +10,9 @@ #include <libcss/computed.h> #include <libcss/hint.h> +#include <libcss/unit.h> - - -struct css_computed_uncommon_i { -/* - * border_spacing 1 + 2(4) 2(4) - * break_before 4 0 - * break_after 4 0 - * break_inside 4 0 - * clip 2 + 4(4) + 4 4(4) - * column_count 2 4 - * column_fill 2 0 - * column_gap 2 + 4 4 - * column_rule_color 2 4 - * column_rule_style 4 0 - * column_rule_width 3 + 4 4 - * column_span 2 0 - * column_width 2 + 4 4 - * letter_spacing 2 + 4 4 - * outline_color 2 4 - * outline_width 3 + 4 4 - * word_spacing 2 + 4 4 - * --- --- - * 95 bits 60 bytes - * - * Encode counter_increment and _reset as an array of name, value pairs, - * terminated with a blank entry. - * - * counter_increment 1 sizeof(ptr) - * counter_reset 1 sizeof(ptr) - * --- --- - * 2 bits 2sizeof(ptr) bytes - * - * Encode cursor uri(s) as an array of string objects, terminated with a - * blank entry. - * - * cursor 5 sizeof(ptr) - * --- --- - * 5 bits sizeof(ptr) bytes - * - * Encode content as an array of content items, terminated with a blank entry. - * - * content 2 sizeof(ptr) - * --- --- - * 2 bits sizeof(ptr) - * - * ___ ___ - * 108 bits 62 + 4sizeof(ptr) bytes - * - * 14 bytes 62 + 4sizeof(ptr) bytes - * =================== - * 74 + 4sizeof(ptr) bytes - * - * Bit allocations: - * - * 76543210 - * 1 llllllcc letter-spacing | outline-color - * 2 ooooooob outline-width | border-spacing - * 3 bbbbbbbb border-spacing - * 4 wwwwwwir word-spacing | counter-increment | counter-reset - * 5 uuuuumm. cursor | writing-mode | <unused> - * 6 cccccccc clip - * 7 cccccccc clip - * 8 ccccccoo clip | content - * 9 ccffssss column_count | column-fill | column-rule-style - * 10 ggggggcc column-gap | column-rule-color - * 11 wwwwwww. column-rule-width | <unused> - * 12 sswwwwww column-span | column_width - * 13 bbbbaaaa break-before | break-after - * 14 iiii.... break-inside | <unused> - */ - uint8_t bits[14]; - - css_fixed border_spacing[2]; - - css_fixed clip[4]; - - css_fixed letter_spacing; - - css_color outline_color; - css_fixed outline_width; - - css_fixed word_spacing; - - int32_t column_count; - css_fixed column_gap; - css_color column_rule_color; - css_fixed column_rule_width; - css_fixed column_width; -}; - -typedef struct css_computed_uncommon { - struct css_computed_uncommon_i i; - - css_computed_counter *counter_increment; - css_computed_counter *counter_reset; - - css_computed_content_item *content; - - lwc_string **cursor; - struct css_computed_uncommon *next; - uint32_t count; - uint32_t bin; -} css_computed_uncommon; - -typedef struct css_computed_page { -/* - * Bit allocations: - * - * 76543210 - * 1 aaabbbii page_break_after | page_break_before | page_break_inside - * 2 ......wo widows | orphans - */ - uint8_t bits[2]; - - int32_t widows; - int32_t orphans; -} css_computed_page; - -struct css_computed_style_i { -/* - * background_attachment 2 - * background_repeat 3 - * border_collapse 2 - * border_top_style 4 - * border_right_style 4 - * border_bottom_style 4 - * border_left_style 4 - * caption_side 2 - * clear 3 - * direction 2 - * display 5 - * empty_cells 2 - * float 2 - * font_style 2 - * font_variant 2 - * font_weight 4 - * list_style_position 2 - * list_style_type 4 - * overflow 3 - * outline_style 4 - * position 3 - * table_layout 2 - * text_align 4 - * text_decoration 5 - * text_transform 3 - * unicode_bidi 2 - * visibility 2 - * white_space 3 - * box_sizing 2 - * --- - * 86 bits - * - * Colours are 32bits of AARRGGBB - * Dimensions are encoded as a fixed point value + 4 bits of unit data - * - * background_color 2 4 - * background_image 1 sizeof(ptr) - * background_position 1 + 2(4) 2(4) - * border_top_color 2 4 - * border_right_color 2 4 - * border_bottom_color 2 4 - * border_left_color 2 4 - * border_top_width 3 + 4 4 - * border_right_width 3 + 4 4 - * border_bottom_width 3 + 4 4 - * border_left_width 3 + 4 4 - * top 2 + 4 4 - * right 2 + 4 4 - * bottom 2 + 4 4 - * left 2 + 4 4 - * color 1 4 - * font_size 4 + 4 4 - * height 2 + 4 4 - * line_height 2 + 4 4 - * list_style_image 1 sizeof(ptr) - * margin_top 2 + 4 4 - * margin_right 2 + 4 4 - * margin_bottom 2 + 4 4 - * margin_left 2 + 4 4 - * max_height 2 + 4 4 - * max_width 2 + 4 4 - * min_height 1 + 4 4 - * min_width 1 + 4 4 - * padding_top 1 + 4 4 - * padding_right 1 + 4 4 - * padding_bottom 1 + 4 4 - * padding_left 1 + 4 4 - * text_indent 1 + 4 4 - * vertical_align 4 + 4 4 - * width 2 + 4 4 - * z_index 2 4 - * --- --- - * 181 bits 140 + 2sizeof(ptr) bytes - * - * Encode font family as an array of string objects, terminated with a - * blank entry. - * - * font_family 3 sizeof(ptr) - * --- --- - * 3 bits sizeof(ptr) - * - * Encode quotes as an array of string objects, terminated with a blank entry. - * - * quotes 1 sizeof(ptr) - * --- --- - * 1 bit sizeof(ptr) bytes - * - * ___ ___ - * 269 bits 140 + 4sizeof(ptr) bytes - * - * 34 bytes 140 + 4sizeof(ptr) bytes - * =================== - * 174 + 4sizeof(ptr) bytes - * - * Bit allocations: - * - * 76543210 - * 1 vvvvvvvv vertical-align - * 2 ffffffff font-size - * 3 ttttttti border-top-width | background-image - * 4 rrrrrrrc border-right-width | color - * 5 bbbbbbbl border-bottom-width | list-style-image - * 6 lllllllq border-left-width | quotes - * 7 ttttttcc top | border-top-color - * 8 rrrrrrcc right | border-right-color - * 9 bbbbbbcc bottom | border-bottom-color - * 10 llllllcc left | border-left-color - * 11 hhhhhhbb height | background-color - * 12 llllllzz line-height | z-index - * 13 ttttttbb margin-top | background-attachment - * 14 rrrrrrbb margin-right | border-collapse - * 15 bbbbbbcc margin-bottom | caption-side - * 16 lllllldd margin-left | direction - * 17 mmmmmmee max-height | empty-cells - * 18 mmmmmmff max-width | float - * 19 wwwwwwff width | font-style - * 20 mmmmmbbb min-height | background-repeat - * 21 mmmmmccc min-width | clear - * 22 tttttxxx padding-top | overflow-x - * 23 rrrrrppp padding-right | position - * 24 bbbbboss padding-bottom | opacity | box-sizing - * 25 lllllttt padding-left | text-transform - * 26 tttttwww text-indent | white-space - * 27 bbbbbbbb background-position - * 28 bdddddff background-position | display | font-variant - * 29 tttttfff text-decoration | font-family - * 30 ttttrrrr border-top-style | border-right-style - * 31 bbbbllll border-bottom-style | border-left-style - * 32 ffffllll font-weight | list-style-type - * 33 oooottuu outline-style | table-layout | unicode-bidi - * 34 vvlltttt visibility | list-style-position | text-align - * 35 yyy..... overflow-y | <unused> - */ - uint8_t bits[35]; - - uint8_t unused[1]; - - css_color background_color; - lwc_string *background_image; - css_fixed background_position[2]; - - css_color border_color[4]; - css_fixed border_width[4]; - - css_fixed top; - css_fixed right; - css_fixed bottom; - css_fixed left; - - css_color color; - - css_fixed font_size; - - css_fixed height; - - css_fixed line_height; - - lwc_string *list_style_image; - - css_fixed margin[4]; - - css_fixed max_height; - css_fixed max_width; - - css_fixed min_height; - css_fixed min_width; - - css_fixed opacity; - - css_fixed padding[4]; - - css_fixed text_indent; - - css_fixed vertical_align; - - css_fixed width; - - int32_t z_index; - - css_computed_uncommon *uncommon;/**< Uncommon properties */ - void *aural; /**< Aural properties */ -}; - -struct css_computed_style { - struct css_computed_style_i i; - - lwc_string **font_family; - - lwc_string **quotes; - css_computed_page *page; /**< Page properties */ - struct css_computed_style *next; - uint32_t count; - uint32_t bin; -}; - +#include "autogenerated_computed.h" /** * Take a new reference to a computed style @@ -339,10 +26,6 @@ static inline css_computed_style * css__computed_style_ref( if (style == NULL) return NULL; - if (style->i.uncommon != NULL) { - style->i.uncommon->count++; - } - style->count++; return style; } @@ -352,13 +35,12 @@ css_error css__computed_style_create(css_computed_style **result); css_error css__computed_style_initialise(css_computed_style *style, struct css_select_handler *handler, void *pw); - -css_error css__computed_uncommon_destroy(css_computed_uncommon *uncommon); +css_error css__computed_style_clone( + const css_computed_style *orig, + css_computed_style **clone_out); css_error css__compute_absolute_values(const css_computed_style *parent, css_computed_style *style, - css_error (*compute_font_size)(void *pw, - const css_hint *parent, css_hint *size), - void *pw); + const css_unit_ctx *unit_ctx); #endif diff --git a/src/select/dispatch.c b/src/select/dispatch.c index 7af9000..cee9335 100644 --- a/src/select/dispatch.c +++ b/src/select/dispatch.c @@ -15,577 +15,512 @@ css__cascade_##pname, \ css__set_##pname##_from_hint, \ css__initial_##pname, \ + css__copy_##pname, \ css__compose_##pname struct prop_table prop_dispatch[CSS_N_PROPERTIES] = { { PROPERTY_FUNCS(azimuth), 1, - GROUP_AURAL }, { PROPERTY_FUNCS(background_attachment), 0, - GROUP_NORMAL }, { PROPERTY_FUNCS(background_color), 0, - GROUP_NORMAL }, { PROPERTY_FUNCS(background_image), 0, - GROUP_NORMAL }, { PROPERTY_FUNCS(background_position), 0, - GROUP_NORMAL }, { PROPERTY_FUNCS(background_repeat), 0, - GROUP_NORMAL }, { PROPERTY_FUNCS(border_collapse), 1, - GROUP_NORMAL }, { PROPERTY_FUNCS(border_spacing), 1, - GROUP_UNCOMMON }, { PROPERTY_FUNCS(border_top_color), 0, - GROUP_NORMAL }, { PROPERTY_FUNCS(border_right_color), 0, - GROUP_NORMAL }, { PROPERTY_FUNCS(border_bottom_color), 0, - GROUP_NORMAL }, { PROPERTY_FUNCS(border_left_color), 0, - GROUP_NORMAL }, { PROPERTY_FUNCS(border_top_style), 0, - GROUP_NORMAL }, { PROPERTY_FUNCS(border_right_style), 0, - GROUP_NORMAL }, { PROPERTY_FUNCS(border_bottom_style), 0, - GROUP_NORMAL }, { PROPERTY_FUNCS(border_left_style), 0, - GROUP_NORMAL }, { PROPERTY_FUNCS(border_top_width), 0, - GROUP_NORMAL }, { PROPERTY_FUNCS(border_right_width), 0, - GROUP_NORMAL }, { PROPERTY_FUNCS(border_bottom_width), 0, - GROUP_NORMAL }, { PROPERTY_FUNCS(border_left_width), 0, - GROUP_NORMAL }, { PROPERTY_FUNCS(bottom), 0, - GROUP_NORMAL }, { PROPERTY_FUNCS(caption_side), 1, - GROUP_NORMAL }, { PROPERTY_FUNCS(clear), 0, - GROUP_NORMAL }, { PROPERTY_FUNCS(clip), 0, - GROUP_UNCOMMON }, { PROPERTY_FUNCS(color), 1, - GROUP_NORMAL }, { PROPERTY_FUNCS(content), 0, - GROUP_UNCOMMON }, { PROPERTY_FUNCS(counter_increment), 0, - GROUP_UNCOMMON }, { PROPERTY_FUNCS(counter_reset), 0, - GROUP_UNCOMMON }, { PROPERTY_FUNCS(cue_after), 0, - GROUP_AURAL }, { PROPERTY_FUNCS(cue_before), 0, - GROUP_AURAL }, { PROPERTY_FUNCS(cursor), 1, - GROUP_UNCOMMON }, { PROPERTY_FUNCS(direction), 1, - GROUP_NORMAL }, { PROPERTY_FUNCS(display), 0, - GROUP_NORMAL }, { PROPERTY_FUNCS(elevation), 1, - GROUP_AURAL }, { PROPERTY_FUNCS(empty_cells), 1, - GROUP_NORMAL }, { PROPERTY_FUNCS(float), 0, - GROUP_NORMAL }, { PROPERTY_FUNCS(font_family), 1, - GROUP_NORMAL }, { PROPERTY_FUNCS(font_size), 1, - GROUP_NORMAL }, { PROPERTY_FUNCS(font_style), 1, - GROUP_NORMAL }, { PROPERTY_FUNCS(font_variant), 1, - GROUP_NORMAL }, { PROPERTY_FUNCS(font_weight), 1, - GROUP_NORMAL }, { PROPERTY_FUNCS(height), 0, - GROUP_NORMAL }, { PROPERTY_FUNCS(left), 0, - GROUP_NORMAL }, { PROPERTY_FUNCS(letter_spacing), 1, - GROUP_UNCOMMON }, { PROPERTY_FUNCS(line_height), 1, - GROUP_NORMAL }, { PROPERTY_FUNCS(list_style_image), 1, - GROUP_NORMAL }, { PROPERTY_FUNCS(list_style_position), 1, - GROUP_NORMAL }, { PROPERTY_FUNCS(list_style_type), 1, - GROUP_NORMAL }, { PROPERTY_FUNCS(margin_top), 0, - GROUP_NORMAL }, { PROPERTY_FUNCS(margin_right), 0, - GROUP_NORMAL }, { PROPERTY_FUNCS(margin_bottom), 0, - GROUP_NORMAL }, { PROPERTY_FUNCS(margin_left), 0, - GROUP_NORMAL }, { PROPERTY_FUNCS(max_height), 0, - GROUP_NORMAL }, { PROPERTY_FUNCS(max_width), 0, - GROUP_NORMAL }, { PROPERTY_FUNCS(min_height), 0, - GROUP_NORMAL }, { PROPERTY_FUNCS(min_width), 0, - GROUP_NORMAL }, { PROPERTY_FUNCS(orphans), 1, - GROUP_PAGE }, { PROPERTY_FUNCS(outline_color), 0, - GROUP_UNCOMMON }, { PROPERTY_FUNCS(outline_style), 0, - GROUP_NORMAL }, { PROPERTY_FUNCS(outline_width), 0, - GROUP_UNCOMMON }, { PROPERTY_FUNCS(overflow_x), 0, - GROUP_NORMAL }, { PROPERTY_FUNCS(padding_top), 0, - GROUP_NORMAL }, { PROPERTY_FUNCS(padding_right), 0, - GROUP_NORMAL }, { PROPERTY_FUNCS(padding_bottom), 0, - GROUP_NORMAL }, { PROPERTY_FUNCS(padding_left), 0, - GROUP_NORMAL }, { PROPERTY_FUNCS(page_break_after), 0, - GROUP_PAGE }, { PROPERTY_FUNCS(page_break_before), 0, - GROUP_PAGE }, { PROPERTY_FUNCS(page_break_inside), 1, - GROUP_PAGE }, { PROPERTY_FUNCS(pause_after), 0, - GROUP_AURAL }, { PROPERTY_FUNCS(pause_before), 0, - GROUP_AURAL }, { PROPERTY_FUNCS(pitch_range), 1, - GROUP_AURAL }, { PROPERTY_FUNCS(pitch), 1, - GROUP_AURAL }, { PROPERTY_FUNCS(play_during), 0, - GROUP_AURAL }, { PROPERTY_FUNCS(position), 0, - GROUP_NORMAL }, { PROPERTY_FUNCS(quotes), 1, - GROUP_NORMAL }, { PROPERTY_FUNCS(richness), 1, - GROUP_AURAL }, { PROPERTY_FUNCS(right), 0, - GROUP_NORMAL }, { PROPERTY_FUNCS(speak_header), 1, - GROUP_AURAL }, { PROPERTY_FUNCS(speak_numeral), 1, - GROUP_AURAL }, { PROPERTY_FUNCS(speak_punctuation), 1, - GROUP_AURAL }, { PROPERTY_FUNCS(speak), 1, - GROUP_AURAL }, { PROPERTY_FUNCS(speech_rate), 1, - GROUP_AURAL }, { PROPERTY_FUNCS(stress), 1, - GROUP_AURAL }, { PROPERTY_FUNCS(table_layout), 0, - GROUP_NORMAL }, { PROPERTY_FUNCS(text_align), 1, - GROUP_NORMAL }, { PROPERTY_FUNCS(text_decoration), 0, - GROUP_NORMAL }, { PROPERTY_FUNCS(text_indent), 1, - GROUP_NORMAL }, { PROPERTY_FUNCS(text_transform), 1, - GROUP_NORMAL }, { PROPERTY_FUNCS(top), 0, - GROUP_NORMAL }, { PROPERTY_FUNCS(unicode_bidi), 0, - GROUP_NORMAL }, { PROPERTY_FUNCS(vertical_align), 0, - GROUP_NORMAL }, { PROPERTY_FUNCS(visibility), 1, - GROUP_NORMAL }, { PROPERTY_FUNCS(voice_family), 1, - GROUP_AURAL }, { PROPERTY_FUNCS(volume), 1, - GROUP_AURAL }, { PROPERTY_FUNCS(white_space), 1, - GROUP_NORMAL }, { PROPERTY_FUNCS(widows), 1, - GROUP_PAGE }, { PROPERTY_FUNCS(width), 0, - GROUP_NORMAL }, { PROPERTY_FUNCS(word_spacing), 1, - GROUP_UNCOMMON }, { PROPERTY_FUNCS(z_index), 0, - GROUP_NORMAL }, { PROPERTY_FUNCS(opacity), 0, - GROUP_NORMAL }, { PROPERTY_FUNCS(break_after), 0, - GROUP_UNCOMMON }, { PROPERTY_FUNCS(break_before), 0, - GROUP_UNCOMMON }, { PROPERTY_FUNCS(break_inside), 0, - GROUP_UNCOMMON }, { PROPERTY_FUNCS(column_count), 0, - GROUP_UNCOMMON }, { PROPERTY_FUNCS(column_fill), 0, - GROUP_UNCOMMON }, { PROPERTY_FUNCS(column_gap), 0, - GROUP_UNCOMMON }, { PROPERTY_FUNCS(column_rule_color), 0, - GROUP_UNCOMMON }, { PROPERTY_FUNCS(column_rule_style), 0, - GROUP_UNCOMMON }, { PROPERTY_FUNCS(column_rule_width), 0, - GROUP_UNCOMMON }, { PROPERTY_FUNCS(column_span), 0, - GROUP_UNCOMMON }, { PROPERTY_FUNCS(column_width), 0, - GROUP_UNCOMMON }, { PROPERTY_FUNCS(writing_mode), 0, - GROUP_UNCOMMON }, { PROPERTY_FUNCS(overflow_y), 0, - GROUP_NORMAL }, { PROPERTY_FUNCS(box_sizing), 0, - GROUP_NORMAL + }, + { + PROPERTY_FUNCS(align_content), + 0, + }, + { + PROPERTY_FUNCS(align_items), + 0, + }, + { + PROPERTY_FUNCS(align_self), + 0, + }, + { + PROPERTY_FUNCS(flex_basis), + 0, + }, + { + PROPERTY_FUNCS(flex_direction), + 0, + }, + { + PROPERTY_FUNCS(flex_grow), + 0, + }, + { + PROPERTY_FUNCS(flex_shrink), + 0, + }, + { + PROPERTY_FUNCS(flex_wrap), + 0, + }, + { + PROPERTY_FUNCS(justify_content), + 0, + }, + { + PROPERTY_FUNCS(order), + 0, + }, + { + PROPERTY_FUNCS(fill_opacity), + 1, + }, + { + PROPERTY_FUNCS(stroke_opacity), + 1, } }; diff --git a/src/select/dispatch.h b/src/select/dispatch.h index c1db7d9..8ddf4f9 100644 --- a/src/select/dispatch.h +++ b/src/select/dispatch.h @@ -17,27 +17,18 @@ #include "bytecode/bytecode.h" #include "select/select.h" -/** - * Enumeration of property groups - */ -enum prop_group { - GROUP_NORMAL = 0x0, - GROUP_UNCOMMON = 0x1, - GROUP_PAGE = 0x2, - GROUP_AURAL = 0x3 -}; - extern struct prop_table { css_error (*cascade)(uint32_t opv, css_style *style, css_select_state *state); css_error (*set_from_hint)(const css_hint *hint, css_computed_style *style); css_error (*initial)(css_select_state *state); + css_error (*copy)(const css_computed_style *from, + css_computed_style *to); css_error (*compose)(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result); unsigned int inherited; - unsigned int group; } prop_dispatch[CSS_N_PROPERTIES]; #endif diff --git a/src/select/format_list_style.c b/src/select/format_list_style.c new file mode 100644 index 0000000..0e3a39e --- /dev/null +++ b/src/select/format_list_style.c @@ -0,0 +1,1229 @@ +/* + * This file is part of LibCSS + * Licensed under the MIT License, + * http://www.opensource.org/licenses/mit-license.php + * Copyright 2021 Vincent Sanders <vince@netsurf-browser.org> + */ + +#include "select/propget.h" +#include "utils/utils.h" + +#define SYMBOL_SIZE 8 +typedef char symbol_t[SYMBOL_SIZE]; + +/** + * numeric representation of the value using a system + */ +struct numeric { + uint8_t *val; /* buffer containing the numeric values */ + size_t len; /* length of alen */ + size_t used; /* number of numeric values used */ + bool negative; /* if the value is negative */ +}; + +/** + * list counter style + */ +struct list_counter_style { + /** style name for debug purposes */ + const char *name; + /** function to calculate the system */ + css_error (*system)(int value, const struct list_counter_style *cstyle, struct numeric *nval); + /** fallback style if this system fails */ + const struct list_counter_style* fallback; + /** array of symbols which represent this style */ + const symbol_t *symbols; + /** symbol weights for additive schemes */ + const int *weights; + /** number of items in symbol and weight table */ + const size_t items; + /** range of acceptable values */ + struct { + const int start; /**< first acceptable value for this style */ + const int end; /**< last acceptable value for this style */ + } range; + + /** padding formatting */ + struct { + const unsigned int length; + const symbol_t value; + } pad; + /** negative value formating */ + struct { + const char *pre; + const char *post; + } negative; + /** prefix formatting */ + const char *prefix; + /** suffix formatting */ + const char *suffix; +}; + + +/** + * Copy a null-terminated UTF-8 string to buffer at offset, if there is space + * + * \param[in] buf The output buffer + * \param[in] buflen The length of \a buf + * \param[in] pos Current position in \a buf + * \param[in] str The string to copy into \a buf + * \return The number of bytes needed in the output buffer which may be + * larger than \a buflen but the buffer will not be overrun + */ +static inline size_t +copy_string(char *buf, const size_t buflen, size_t pos, const char *str) +{ + size_t sidx = 0; /* current string index */ + + while (str[sidx] != '\0') { + if (pos < buflen) { + buf[pos] = str[sidx]; + } + pos++; + sidx++; + } + + return sidx; +} + +/** + * Copy a UTF-8 symbol to buffer at offset, if there is space + * + * \param[in] buf The output buffer + * \param[in] buflen The length of \a buf + * \param[in] pos Current position in \a buf + * \param[in] symbol The symbol to copy into \a buf + * \return The number of bytes needed in the output buffer which may be + * larger than \a buflen but the buffer will not be overrun + */ +static inline size_t +copy_symbol(char *buf, const size_t buflen, size_t pos, const symbol_t symbol) +{ + size_t sidx = 0; /* current symbol index */ + + while ((sidx < sizeof(symbol_t)) && (symbol[sidx] != '\0')) { + if (pos < buflen) { + buf[pos] = symbol[sidx]; + } + pos++; + sidx++; + } + + return sidx; +} + +/** + * maps numeric values to output values with a symbol table + * + * Takes a list of numeric values and for each one outputs the + * compete symbol (in utf8) to an output buffer. + * + * \param buf The output buffer + * \param buflen the length of \a buf + * \param aval array of alphabet values + * \param alen The number of values in \a alen + * \param symtab The symbol table + * \param symtablen The number of symbols in \a symtab + * \return The number of bytes needed in the output buffer whichmay be + * larger than \a buflen but the buffer will not be overrun + */ +static size_t +nval_to_symbols(struct numeric *nval, + const struct list_counter_style *cstyle, + char *buf, const size_t buflen) +{ + size_t oidx = 0; + size_t aidx; /* numeral index */ + const char *suffix = "."; /* default sufffix string */ + const char *negative_pre = "-"; /* default negative string */ + + /* prefix */ + if (cstyle->prefix != NULL) { + oidx += copy_string(buf, buflen, oidx, cstyle->prefix); + } + + /* negative pre */ + if (nval->negative) { + if (cstyle->negative.pre != NULL) { + negative_pre = cstyle->negative.pre; + } + oidx += copy_string(buf, buflen, oidx, negative_pre); + } + + /* add padding if required */ + if (nval->used < cstyle->pad.length) { + size_t pidx; /* padding index */ + for (pidx = cstyle->pad.length - nval->used; pidx > 0; pidx--) { + oidx += copy_symbol(buf, buflen, oidx, + cstyle->pad.value); + } + } + + /* map symbols */ + for (aidx = 0; aidx < nval->used; aidx++) { + oidx += copy_symbol(buf, buflen, oidx, + cstyle->symbols[nval->val[aidx]]); + } + + /* negative post */ + if ((nval->negative) && (cstyle->negative.post != NULL)) { + oidx += copy_string(buf, buflen, oidx, cstyle->negative.post); + } + + /* suffix */ + if (cstyle->suffix != NULL) { + suffix = cstyle->suffix; + } + oidx += copy_string(buf, buflen, oidx, suffix); + + return oidx; +} + + +/** + * generate numeric symbol values + * + * fills array with numeric values that represent the input value + * + * \param ares Buffer to recive the converted values + * \param alen the length of \a ares buffer + * \param value The value to convert + * \param cstyle The counter style in use + * \return The length a complete conversion which may be larger than \a alen + */ +static css_error +calc_numeric_system(int value, + const struct list_counter_style *cstyle, + struct numeric *nval) +{ + size_t idx = 0; + uint8_t *first; + uint8_t *last; + + if (value == 0) { + if (nval->len >= 1) { + nval->val[0] = 0; + } + nval->used = 1; + return CSS_OK; + } + + if (value < 0) { + nval->negative = true; + value = abs(value); + } else { + nval->negative = false; + } + + /* generate alphabet values in ascending order */ + while (value > 0) { + if (idx < nval->len) { + nval->val[idx] = value % cstyle->items; + } + idx++; + value = value / cstyle->items; + } + + /* put the values in decending order */ + first = nval->val; + if (idx < nval->len) { + last = first + (idx - 1); + } else { + last = first + (nval->len - 1); + } + while (first < last) { + *first ^= *last; + *last ^= *first; + *first ^= *last; + first++; + last--; + } + + nval->used = idx; + + return CSS_OK; +} + + +/** + * generate cyclic symbol values + * + * fills array with cyclic values that represent the input value + * + * \param ares Buffer to recive the converted values + * \param alen the length of \a ares buffer + * \param value The value to convert + * \param cstyle The counter style in use + * \return The length a complete conversion which may be larger than \a alen + */ +static css_error +calc_cyclic_system(int value, + const struct list_counter_style *cstyle, + struct numeric *nval) +{ + if (nval->len == 0) { + return CSS_INVALID; + } + if (cstyle->items == 1) { + /* there is only one symbol so select it */ + nval->val[0] = 0; + } else { + nval->val[0] = (value - 1) % cstyle->items; + } + nval->used = 1; + nval->negative = false; + + return CSS_OK; +} + + +/** + * generate addative symbol values + * + * fills array with numeric values that represent the input value + * + * \param ares Buffer to recive the converted values + * \param alen the length of \a ares buffer + * \param value The value to convert + * \param wlen The number of weights + * \return The length a complete conversion which may be larger than \a alen + */ +static css_error +calc_additive_system(int value, + const struct list_counter_style *cstyle, + struct numeric *nval) +{ + size_t widx; /* weight index */ + size_t aidx = 0; /* numerals used */ + size_t idx; + size_t times; /* number of times a weight occours */ + + /* ensure value is within acceptable range of this system */ + if ((value < cstyle->range.start) || (value > cstyle->range.end)) { + return CSS_INVALID; + } + + /* zero needs a specific weight */ + if (value == 0) { + /* search weights for a zero entry */ + for (widx = 0; widx < cstyle->items; widx++) { + if (cstyle->weights[widx] == 0) { + if (nval->len > 0) { + nval->val[0] = widx; + } + + nval->used = 1; + nval->negative = false; + return CSS_OK; + } + } + return CSS_INVALID; + } + + /* negative values */ + if (value < 0) { + nval->negative = true; + value = abs(value); + } else { + nval->negative = false; + } + + /* iterate over the available weights */ + for (widx = 0; widx < cstyle->items; widx++) { + if (cstyle->weights[widx] == 0) { + break; + } + times = value / cstyle->weights[widx]; + if (times > 0) { + for (idx = 0;idx < times;idx++) { + if (aidx < nval->len) { + nval->val[aidx] = widx; + } + aidx++; + } + + value -= times * cstyle->weights[widx]; + } + } + + nval->used = aidx; + + return CSS_OK; +} + + +/** + * generate alphabet symbol values for latin and greek labelling + * + * fills array with alphabet values suitable for the input value + * + * \param ares Buffer to recive the converted values + * \param alen the length of \a ares buffer + * \param value The value to convert + * \param slen The number of symbols in the alphabet + * \return The length a complete conversion which may be larger than \a alen + */ +static css_error +calc_alphabet_system(int value, + const struct list_counter_style *cstyle, + struct numeric *nval) +{ + size_t idx = 0; + uint8_t *first; + uint8_t *last; + + if (value < 1) { + return CSS_INVALID; + } + + /* generate alphabet values in ascending order */ + while (value > 0) { + --value; + if (idx < nval->len) { + nval->val[idx] = value % cstyle->items; + } + idx++; + value = value / cstyle->items; + } + + /* put the values in decending order */ + first = nval->val; + if (idx < nval->len) { + last = first + (idx - 1); + } else { + last = first + (nval->len - 1); + } + while (first < last) { + *first ^= *last; + *last ^= *first; + *first ^= *last; + first++; + last--; + } + + nval->used = idx; + nval->negative = false; + + return CSS_OK; +} + + +/** + * Roman numeral conversion + * + * \return The number of numerals that are nesesary for full output + */ +static css_error +calc_roman_system(int value, + const struct list_counter_style *cstyle, + struct numeric *nval) +{ + const int S[] = { 0, 2, 4, 2, 4, 2, 4 }; + size_t k = 0; /* index into output buffer */ + unsigned int i = 0; /* index into maps */ + int r; + int r2 = 0; + size_t L; + + assert(cstyle->items == 7); + + /* ensure value is within acceptable range of this system */ + if ((value < cstyle->range.start) || (value > cstyle->range.end)) { + return CSS_INVALID; + } + + L = cstyle->items - 1; + + while (value > 0) { + if (cstyle->weights[i] <= value) { + r = value / cstyle->weights[i]; + value = value - (r * cstyle->weights[i]); + if (i < L) { + /* lookahead */ + r2 = value / cstyle->weights[i+1]; + } + if (i < L && r2 >= S[i+1]) { + /* will violate repeat boundary on next pass */ + value = value - (r2 * cstyle->weights[i+1]); + if (k < nval->len) { + nval->val[k++] = i+1; + } + if (k < nval->len) { + nval->val[k++] = i-1; + } + } else if (S[i] && r >= S[i]) { + /* violated repeat boundary on this pass */ + if (k < nval->len) { + nval->val[k++] = i; + } + if (k < nval->len) { + nval->val[k++] = i-1; + } + } else { + while ((r-- > 0) && (k < nval->len)) { + nval->val[k++] = i; + } + } + } + i++; + } + + nval->used = k; + nval->negative = false; + + return CSS_OK; +} + + +/* tables for all the counter styles */ + +static const symbol_t decimal_symbols[] = { + "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" +}; +static const struct list_counter_style lcs_decimal = { + .name = "decimal", + .system = calc_numeric_system, + .symbols = decimal_symbols, + .items = (sizeof(decimal_symbols) / SYMBOL_SIZE), +}; + +static const symbol_t georgian_symbols[] = { + "ჵ", + "ჰ", "ჯ", "ჴ", "ხ", "ჭ", "წ", "ძ", "ც", "ჩ", + "შ", "ყ", "ღ", "ქ", "ფ", "ჳ", "ტ", "ს", "რ", + "ჟ", "პ", "ო", "ჲ", "ნ", "მ", "ლ", "კ", "ი", + "თ", "ჱ", "ზ", "ვ", "ე", "დ", "გ", "ბ", "ა", +}; +static const int georgian_weights[] = { + 10000, + 9000, 8000, 7000, 6000, 5000, 4000, 3000, 2000, 1000, + 900, 800, 700, 600, 500, 400, 300, 200, 100, + 90, 80, 70, 60, 50, 40, 30, 20, 10, + 9, 8, 7, 6, 5, 4, 3, 2, 1 +}; +static const struct list_counter_style lcs_georgian = { + .name="georgian", + .system = calc_additive_system, + .fallback = &lcs_decimal, + .symbols = georgian_symbols, + .weights = georgian_weights, + .items = (sizeof(georgian_symbols) / SYMBOL_SIZE), + .range = { .start = 1, .end = 19999 }, +}; + + +static const symbol_t upper_armenian_symbols[] = { + "Ք", "Փ", "Ւ", "Ց", "Ր", "Տ", "Վ", "Ս", "Ռ", + "Ջ", "Պ", "Չ", "Ո", "Շ", "Ն", "Յ", "Մ", "Ճ", + "Ղ", "Ձ", "Հ", "Կ", "Ծ", "Խ", "Լ", "Ի", "Ժ", + "Թ", "Ը", "Է", "Զ", "Ե", "Դ", "Գ", "Բ", "Ա" +}; +static const int armenian_weights[] = { + 9000, 8000, 7000, 6000, 5000, 4000, 3000, 2000, 1000, + 900, 800, 700, 600, 500, 400, 300, 200, 100, + 90, 80, 70, 60, 50, 40, 30, 20, 10, + 9, 8, 7, 6, 5, 4, 3, 2, 1 +}; +static const struct list_counter_style lcs_upper_armenian = { + .name = "upper-armenian", + .system = calc_additive_system, + .fallback = &lcs_decimal, + .symbols = upper_armenian_symbols, + .weights = armenian_weights, + .items = (sizeof(upper_armenian_symbols) / SYMBOL_SIZE), + .range = { .start = 1, .end = 9999 }, +}; + + +static const symbol_t lower_armenian_symbols[] = { + "ք", "փ", "ւ", "ց", "ր", "տ", "վ", "ս", "ռ", + "ջ", "պ", "չ", "ո", "շ", "ն", "յ", "մ", "ճ", + "ղ", "ձ", "հ", "կ", "ծ", "խ", "լ", "ի", "ժ", + "թ", "ը", "է", "զ", "ե", "դ", "գ", "բ", "ա" +}; +static const struct list_counter_style lcs_lower_armenian = { + .name = "lower-armenian", + .system = calc_additive_system, + .fallback = &lcs_decimal, + .symbols = lower_armenian_symbols, + .weights = armenian_weights, + .items = (sizeof(lower_armenian_symbols) / SYMBOL_SIZE), + .range = { .start = 1, .end = 9999 }, +}; + + +static const struct list_counter_style lcs_decimal_leading_zero = { + .name = "decimal-leading-zero", + .system = calc_numeric_system, + .symbols = decimal_symbols, + .items = (sizeof(decimal_symbols) / SYMBOL_SIZE), + .pad = { .length = 2, .value = "0" }, +}; + + +static const symbol_t lower_greek_symbols[] = { + "α", "β", "γ", "δ", "ε", "ζ", "η", "θ", "ι", "κ", + "λ", "μ", "ν", "ξ", "ο", "π", "ρ", "σ", "τ", "υ", + "φ", "χ", "ψ", "ω" +}; +static const struct list_counter_style lcs_lower_greek = { + .name = "lower-greek", + .system = calc_alphabet_system, + .fallback = &lcs_decimal, + .symbols = lower_greek_symbols, + .items = (sizeof(lower_greek_symbols) / SYMBOL_SIZE), +}; + + +static const symbol_t upper_alpha_symbols[] = { + "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", + "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", + "U", "V", "W", "X", "Y", "Z" +}; +static const struct list_counter_style lcs_upper_alpha = { + .name = "upper-alpha", + .system = calc_alphabet_system, + .fallback = &lcs_decimal, + .symbols = upper_alpha_symbols, + .items = (sizeof(upper_alpha_symbols) / SYMBOL_SIZE), +}; + + +static const symbol_t lower_alpha_symbols[] = { + "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", + "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", + "u", "v", "w", "x", "y", "z" +}; +static struct list_counter_style lcs_lower_alpha = { + .name = "lower-alpha", + .system = calc_alphabet_system, + .fallback = &lcs_decimal, + .symbols = lower_alpha_symbols, + .items = (sizeof(lower_alpha_symbols) / SYMBOL_SIZE), +}; + + +static const int roman_weights[] = { + 1000, 500, 100, 50, 10, 5, 1 +}; +static const symbol_t upper_roman_symbols[] = { + "M", "D", "C", "L", "X", "V", "I" +}; +static const struct list_counter_style lcs_upper_roman = { + .name = "upper-roman", + .system = calc_roman_system, + .fallback = &lcs_decimal, + .symbols = upper_roman_symbols, + .weights = roman_weights, + .items = (sizeof(upper_roman_symbols) / SYMBOL_SIZE), + .range = { .start = 1, .end = 3999 }, +}; + + +static const symbol_t lower_roman_symbols[] = { + "m", "d", "c", "l", "x", "v", "i" +}; +static const struct list_counter_style lcs_lower_roman = { + .name = "lower-roman", + .system = calc_roman_system, + .fallback = &lcs_decimal, + .symbols = lower_roman_symbols, + .weights = roman_weights, + .items = (sizeof(lower_roman_symbols) / SYMBOL_SIZE), + .range = { .start = 1, .end = 3999 }, +}; + +static const symbol_t disc_symbols[] = { "\xE2\x80\xA2"}; /* 2022 BULLET */ +static const struct list_counter_style lcs_disc = { + .name = "disc", + .system = calc_cyclic_system, + .symbols = disc_symbols, + .items = (sizeof(disc_symbols) / SYMBOL_SIZE), + .suffix = " ", +}; + +static const symbol_t circle_symbols[] = { "\342\227\213"}; /* 25CB WHITE CIRCLE */ +static const struct list_counter_style lcs_circle = { + .name = "circle", + .system = calc_cyclic_system, + .symbols = circle_symbols, + .items = (sizeof(circle_symbols) / SYMBOL_SIZE), + .suffix = " ", +}; + +static const symbol_t square_symbols[] = { "\342\226\252"}; /* 25AA BLACK SMALL SQUARE */ +static const struct list_counter_style lcs_square = { + .name = "square", + .system = calc_cyclic_system, + .symbols = square_symbols, + .items = (sizeof(square_symbols) / SYMBOL_SIZE), + .suffix = " ", +}; + +static const symbol_t binary_symbols[] = { "0", "1" }; +static const struct list_counter_style lcs_binary = { + .name = "binary", + .system = calc_numeric_system, + .symbols = binary_symbols, + .items = (sizeof(binary_symbols) / SYMBOL_SIZE), +}; + +static const symbol_t octal_symbols[] = { + "0", "1", "2", "3", "4", "5", "6", "7" +}; +static const struct list_counter_style lcs_octal = { + .name = "octal", + .system = calc_numeric_system, + .symbols = octal_symbols, + .items = (sizeof(octal_symbols) / SYMBOL_SIZE), +}; + + +static const symbol_t lower_hexadecimal_symbols[] = { + "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", + "a", "b", "c", "d", "e", "f" +}; +static const struct list_counter_style lcs_lower_hexadecimal = { + .name = "lower-hexadecimal", + .system = calc_numeric_system, + .symbols = lower_hexadecimal_symbols, + .items = (sizeof(lower_hexadecimal_symbols) / SYMBOL_SIZE), +}; + +static const symbol_t upper_hexadecimal_symbols[] = { + "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", + "a", "b", "c", "d", "e", "f" +}; +static const struct list_counter_style lcs_upper_hexadecimal = { + .name = "upper-hexadecimal", + .system = calc_numeric_system, + .symbols = upper_hexadecimal_symbols, + .items = (sizeof(upper_hexadecimal_symbols) / SYMBOL_SIZE), +}; + +static const symbol_t arabic_indic_symbols[] = { + "\xd9\xa0", "\xd9\xa1", "\xd9\xa2", "\xd9\xa3", "\xd9\xa4", "\xd9\xa5", "\xd9\xa6", "\xd9\xa7", "\xd9\xa8", "\xd9\xa9" +}; +static const struct list_counter_style lcs_arabic_indic = { + .name = "arabic-indic", + .system = calc_numeric_system, + .symbols = arabic_indic_symbols, + .items = (sizeof(arabic_indic_symbols) / SYMBOL_SIZE), +}; + +static const symbol_t bengali_symbols[] = { + "০", "১", "২", "৩", "৪", "৫", "৬", "৭", "৮", "৯" +}; +static const struct list_counter_style lcs_bengali = { + .name = "bengali", + .system = calc_numeric_system, + .symbols = bengali_symbols, + .items = (sizeof(bengali_symbols) / SYMBOL_SIZE), +}; + +static const symbol_t cambodian_symbols[] = { + "០", "១", "២", "៣", "៤", "៥", "៦", "៧", "៨", "៩" +}; +static const struct list_counter_style lcs_cambodian = { + .name = "cambodian", + .system = calc_numeric_system, + .symbols = cambodian_symbols, + .items = (sizeof(cambodian_symbols) / SYMBOL_SIZE), +}; + +static const symbol_t cjk_decimal_symbols[] = { + "〇", "一", "二", "三", "四", "五", "六", "七", "八", "九" +}; +static const struct list_counter_style lcs_cjk_decimal = { + .name = "cjk-decimal", + .system = calc_numeric_system, + .symbols = cjk_decimal_symbols, + .suffix = "、", + .items = (sizeof(cjk_decimal_symbols) / SYMBOL_SIZE), +}; + +static const symbol_t devanagari_symbols[] = { + "०", "१", "२", "३", "४", "५", "६", "७", "८", "९" +}; +static const struct list_counter_style lcs_devanagari = { + .name = "devanagari", + .system = calc_numeric_system, + .symbols = devanagari_symbols, + .items = (sizeof(devanagari_symbols) / SYMBOL_SIZE), +}; + +static const symbol_t gujarati_symbols[] = { + "૦", "૧", "૨", "૩", "૪", "૫", "૬", "૭", "૮", "૯" +}; +static const struct list_counter_style lcs_gujarati = { + .name = "gujarati", + .system = calc_numeric_system, + .symbols = gujarati_symbols, + .items = (sizeof(gujarati_symbols) / SYMBOL_SIZE), +}; + +static const symbol_t gurmukhi_symbols[] = { + "੦", "੧", "੨", "੩", "੪", "੫", "੬", "੭", "੮", "੯" +}; +static const struct list_counter_style lcs_gurmukhi = { + .name = "gurmukhi", + .system = calc_numeric_system, + .symbols = gurmukhi_symbols, + .items = (sizeof(gurmukhi_symbols) / SYMBOL_SIZE), +}; + +static const int hebrew_weights[] = { + 10000, + 9000, 8000, 7000, 6000, 5000, 4000, 3000, 2000, 1000, + 400, 300, 200, 100, + 90, 80, 70, 60, 50, 40, 30, 20, 19, 18, 17, 16, 15, 10, + 9, 8, 7, 6, 5, 4, 3, 2, 1 +}; +static const symbol_t hebrew_symbols[] = { + "\xD7\x99\xD7\xB3", + "\xD7\x98\xD7\xB3", "\xD7\x97\xD7\xB3", "\xD7\x96\xD7\xB3", "\xD7\x95\xD7\xB3", "\xD7\x94\xD7\xB3", "\xD7\x93\xD7\xB3", "\xD7\x92\xD7\xB3", "\xD7\x91\xD7\xB3", "\xD7\x90\xD7\xB3", + "\xD7\xAA", "\xD7\xA9", "\xD7\xA8", "\xD7\xA7", + "\xD7\xA6", "\xD7\xA4", "\xD7\xA2", "\xD7\xA1", "\xD7\xA0", "\xD7\x9E", "\xD7\x9C", /* 20 */"\xD7\x9B", "\xD7\x99\xD7\x98", "\xD7\x99\xD7\x97", "\xD7\x99\xD7\x96", "\xD7\x98\xD7\x96", "\xD7\x98\xD7\x95", "\xD7\x99", + "\xD7\x98", "\xD7\x97", "\xD7\x96", "\xD7\x95", "\xD7\x94", "\xD7\x93", "\xD7\x92", "\xD7\x91", "\xD7\x90" +}; +static const struct list_counter_style lcs_hebrew = { + .name = "hebrew", + .system = calc_additive_system, + .fallback = &lcs_decimal, + .symbols = hebrew_symbols, + .weights = hebrew_weights, + .items = (sizeof(hebrew_symbols) / SYMBOL_SIZE), + .range = { .start = 1, .end = 10999 }, +}; + +static const symbol_t kannada_symbols[] = { + "\xE0\xB3\xA6", "\xE0\xB3\xA7", "\xE0\xB3\xA8", "\xE0\xB3\xA9", "\xE0\xB3\xAA", "\xE0\xB3\xAB", "\xE0\xB3\xAC", "\xE0\xB3\xAD", "\xE0\xB3\xAE", "\xE0\xB3\xAF" +}; +static const struct list_counter_style lcs_kannada = { + .name = "kannada", + .system = calc_numeric_system, + .symbols = kannada_symbols, + .items = (sizeof(kannada_symbols) / SYMBOL_SIZE), +}; + +static const symbol_t lao_symbols[] = { + "໐", "໑", "໒", "໓", "໔", "໕", "໖", "໗", "໘", "໙" +}; +static const struct list_counter_style lcs_lao = { + .name = "lao", + .system = calc_numeric_system, + .symbols = lao_symbols, + .items = (sizeof(lao_symbols) / SYMBOL_SIZE), +}; + +static const symbol_t malayalam_symbols[] = { + "൦", "൧", "൨", "൩", "൪", "൫", "൬", "൭", "൮", "൯" +}; +static const struct list_counter_style lcs_malayalam = { + .name = "malayalam", + .system = calc_numeric_system, + .symbols = malayalam_symbols, + .items = (sizeof(malayalam_symbols) / SYMBOL_SIZE), +}; + +static const symbol_t mongolian_symbols[] = { + "᠐", "᠑", "᠒", "᠓", "᠔", "᠕", "᠖", "᠗", "᠘", "᠙" +}; +static const struct list_counter_style lcs_mongolian = { + .name = "mongolian", + .system = calc_numeric_system, + .symbols = mongolian_symbols, + .items = (sizeof(mongolian_symbols) / SYMBOL_SIZE), +}; + +static const symbol_t myanmar_symbols[] = { + "၀", "၁", "၂", "၃", "၄", "၅", "၆", "၇", "၈", "၉" +}; +static const struct list_counter_style lcs_myanmar = { + .name = "myanmar", + .system = calc_numeric_system, + .symbols = myanmar_symbols, + .items = (sizeof(myanmar_symbols) / SYMBOL_SIZE), +}; + +static const symbol_t oriya_symbols[] = { + "୦", "୧", "୨", "୩", "୪", "୫", "୬", "୭", "୮", "୯" +}; +static const struct list_counter_style lcs_oriya = { + .name = "oriya", + .system = calc_numeric_system, + .symbols = oriya_symbols, + .items = (sizeof(oriya_symbols) / SYMBOL_SIZE), +}; + +static const symbol_t persian_symbols[] = { + "۰", "۱", "۲", "۳", "۴", "۵", "۶", "۷", "۸", "۹" +}; +static const struct list_counter_style lcs_persian = { + .name = "persian", + .system = calc_numeric_system, + .symbols = persian_symbols, + .items = (sizeof(persian_symbols) / SYMBOL_SIZE), +}; + +static const symbol_t tamil_symbols[] = { + "௦", "௧", "௨", "௩", "௪", "௫", "௬", "௭", "௮", "௯" +}; +static const struct list_counter_style lcs_tamil = { + .name = "tamil", + .system = calc_numeric_system, + .symbols = tamil_symbols, + .items = (sizeof(tamil_symbols) / SYMBOL_SIZE), +}; + +static const symbol_t telugu_symbols[] = { + "౦", "౧", "౨", "౩", "౪", "౫", "౬", "౭", "౮", "౯" +}; +static const struct list_counter_style lcs_telugu = { + .name = "telugu", + .system = calc_numeric_system, + .symbols = telugu_symbols, + .items = (sizeof(telugu_symbols) / SYMBOL_SIZE), +}; + +static const symbol_t thai_symbols[] = { + "๐", "๑", "๒", "๓", "๔", "๕", "๖", "๗", "๘", "๙" +}; +static const struct list_counter_style lcs_thai = { + .name = "thai", + .system = calc_numeric_system, + .symbols = thai_symbols, + .items = (sizeof(thai_symbols) / SYMBOL_SIZE), +}; + +static const symbol_t tibetan_symbols[] = { + "༠", "༡", "༢", "༣", "༤", "༥", "༦", "༧", "༨", "༩" +}; +static const struct list_counter_style lcs_tibetan = { + .name = "tibetan", + .system = calc_numeric_system, + .symbols = tibetan_symbols, + .items = (sizeof(tibetan_symbols) / SYMBOL_SIZE), +}; + +static const symbol_t cjk_earthly_branch_symbols[] = { + "子", "丑", "寅", "卯", "辰", "巳", "午", "未", "申", "酉", "戌", "亥" +}; +static struct list_counter_style lcs_cjk_earthly_branch = { + .name = "cjk-earthly-branch", + .system = calc_alphabet_system, + .fallback = &lcs_decimal, + .symbols = cjk_earthly_branch_symbols, + .items = (sizeof(cjk_earthly_branch_symbols) / SYMBOL_SIZE), + .suffix = "、", +}; + +static const symbol_t cjk_heavenly_stem_symbols[] = { + "甲", "乙", "丙", "丁", "戊", "己", "庚", "辛", "壬", "癸" +}; +static struct list_counter_style lcs_cjk_heavenly_stem = { + .name = "cjk-heavenly-stem", + .system = calc_alphabet_system, + .fallback = &lcs_decimal, + .symbols = cjk_heavenly_stem_symbols, + .items = (sizeof(cjk_heavenly_stem_symbols) / SYMBOL_SIZE), + .suffix = "、", +}; + +static const symbol_t hiragana_symbols[] = { + "あ", "い", "う", "え", "お", "か", "き", "く", "け", "こ", "さ", "し", "す", "せ", "そ", "た", "ち", "つ", "て", "と", "な", "に", "ぬ", "ね", "の", "は", "ひ", "ふ", "へ", "ほ", "ま", "み", "む", "め", "も", "や", "ゆ", "よ", "ら", "り", "る", "れ", "ろ", "わ", "ゐ", "ゑ", "を", "ん" +}; +static struct list_counter_style lcs_hiragana = { + .name = "hiragana", + .system = calc_alphabet_system, + .fallback = &lcs_decimal, + .symbols = hiragana_symbols, + .items = (sizeof(hiragana_symbols) / SYMBOL_SIZE), + .suffix = "、", +}; + +static const symbol_t hiragana_iroha_symbols[] = { + "い", "ろ", "は", "に", "ほ", "へ", "と", "ち", "り", "ぬ", "る", "を", "わ", "か", "よ", "た", "れ", "そ", "つ", "ね", "な", "ら", "む", "う", "ゐ", "の", "お", "く", "や", "ま", "け", "ふ", "こ", "え", "て", "あ", "さ", "き", "ゆ", "め", "み", "し", "ゑ", "ひ", "も", "せ", "す" +}; +static struct list_counter_style lcs_hiragana_iroha = { + .name = "hiragana-iroha", + .system = calc_alphabet_system, + .fallback = &lcs_decimal, + .symbols = hiragana_iroha_symbols, + .items = (sizeof(hiragana_iroha_symbols) / SYMBOL_SIZE), + .suffix = "、", +}; + +static const symbol_t katakana_symbols[] = { + "ア", "イ", "ウ", "エ", "オ", "カ", "キ", "ク", "ケ", "コ", "サ", "シ", "ス", "セ", "ソ", "タ", "チ", "ツ", "テ", "ト", "ナ", "ニ", "ヌ", "ネ", "ノ", "ハ", "ヒ", "フ", "ヘ", "ホ", "マ", "ミ", "ム", "メ", "モ", "ヤ", "ユ", "ヨ", "ラ", "リ", "ル", "レ", "ロ", "ワ", "ヰ", "ヱ", "ヲ", "ン" +}; +static struct list_counter_style lcs_katakana = { + .name = "katakana", + .system = calc_alphabet_system, + .fallback = &lcs_decimal, + .symbols = katakana_symbols, + .items = (sizeof(katakana_symbols) / SYMBOL_SIZE), + .suffix = "、", +}; + +static const symbol_t katakana_iroha_symbols[] = { + "イ", "ロ", "ハ", "ニ", "ホ", "ヘ", "ト", "チ", "リ", "ヌ", "ル", "ヲ", "ワ", "カ", "ヨ", "タ", "レ", "ソ", "ツ", "ネ", "ナ", "ラ", "ム", "ウ", "ヰ", "ノ", "オ", "ク", "ヤ", "マ", "ケ", "フ", "コ", "エ", "テ", "ア", "サ", "キ", "ユ", "メ", "ミ", "シ", "ヱ", "ヒ", "モ", "セ", "ス" +}; +static struct list_counter_style lcs_katakana_iroha = { + .name = "katakana-iroha", + .system = calc_alphabet_system, + .fallback = &lcs_decimal, + .symbols = katakana_iroha_symbols, + .items = (sizeof(katakana_iroha_symbols) / SYMBOL_SIZE), + .suffix = "、", +}; + +/** + * weights suitable for the five complex addative styles + */ +static const int complex_counter_weights[] = { + 9000, 8000, 7000, 6000, 5000, 4000, 3000, 2000, 1000, + 900, 800, 700, 600, 500, 400, 300, 200, 100, + 90, 80, 70, 60, 50, 40, 30, 20, 10, + 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 +}; +static const symbol_t japanese_informal_symbols[] = { + "九千", "八千", "七千", "六千", "五千", "四千", "三千", "二千", "千", + "九百", "八百", "七百", "六百", "五百", "四百", "三百", "二百", "百", + "九十", "八十", "七十", "六十", "五十", "四十", "三十", "二十", "十", + "九", "八", "七", "六", "五", "四", "三", "二", "一", "〇", +}; +static const struct list_counter_style lcs_japanese_informal = { + .name = "japanese-informal", + .system = calc_additive_system, + .fallback = &lcs_cjk_decimal, + .symbols = japanese_informal_symbols, + .weights = complex_counter_weights, + .items = (sizeof(japanese_informal_symbols) / SYMBOL_SIZE), + .range = { .start = -9999, .end = 9999 }, + .negative = { .pre = "マイナス" }, + .suffix = "\xE3\x80\x81", +}; + +static const symbol_t japanese_formal_symbols[] = { + "九阡", "八阡", "七阡", "六阡", "伍阡", "四阡", "参阡", "弐阡", "壱阡", + "九百", "八百", "七百", "六百", "伍百", "四百", "参百", "弐百", "壱百", + "九拾", "八拾", "七拾", "六拾", "伍拾", "四拾", "参拾", "弐拾", "壱拾", + "九", "八", "七", "六", "伍", "四", "参", "弐", "壱", "零", +}; +static const struct list_counter_style lcs_japanese_formal = { + .name = "japanese-formal", + .system = calc_additive_system, + .fallback = &lcs_cjk_decimal, + .symbols = japanese_formal_symbols, + .weights = complex_counter_weights, + .items = (sizeof(japanese_formal_symbols) / SYMBOL_SIZE), + .range = { .start = -9999, .end = 9999 }, + .negative = { .pre = "マイナス" }, + .suffix = "\xE3\x80\x81", +}; + +static const symbol_t korean_hangul_formal_symbols[] = { + "구천", "팔천", "칠천", "육천", "오천", "사천", "삼천", "이천", "일천", + "구백", "팔백", "칠백", "육백", "오백", "사백", "삼백", "이백", "일백", + "구십", "팔십", "칠십", "육십", "오십", "사십", "삼십", "이십", "일십", + "구", "팔", "칠", "육", "오", "사", "삼", "이", "일", "영" +}; +static const struct list_counter_style lcs_korean_hangul_formal = { + .name = "korean-hangul-formal", + .system = calc_additive_system, + .fallback = &lcs_cjk_decimal, + .symbols = korean_hangul_formal_symbols, + .weights = complex_counter_weights, + .items = (sizeof(korean_hangul_formal_symbols) / SYMBOL_SIZE), + .range = { .start = -9999, .end = 9999 }, + .negative = { .pre = "\xEB\xA7\x88\xEC\x9D\xB4\xEB\x84\x88\xEC\x8A\xA4 " }, + .suffix = ", ", +}; + +static const symbol_t korean_hanja_informal_symbols[] = { + "九千", "八千", "七千", "六千", "五千", "四千", "三千", "二千", "千", + "九百", "八百", "七百", "六百", "五百", "四百", "三百", "二百", "百", + "九十", "八十", "七十", "六十", "五十", "四十", "三十", "二十", "十", + "九", "八", "七", "六", "五", "四", "三", "二", "一", "零" +}; +static const struct list_counter_style lcs_korean_hanja_informal = { + .name = "korean-hanja-informal", + .system = calc_additive_system, + .fallback = &lcs_cjk_decimal, + .symbols = korean_hanja_informal_symbols, + .weights = complex_counter_weights, + .items = (sizeof(korean_hanja_informal_symbols) / SYMBOL_SIZE), + .range = { .start = -9999, .end = 9999 }, + .negative = { .pre = "\xEB\xA7\x88\xEC\x9D\xB4\xEB\x84\x88\xEC\x8A\xA4 " }, + .suffix = ", ", +}; + +static const symbol_t korean_hanja_formal_symbols[] = { + "九仟", "八仟", "七仟", "六仟", "五仟", "四仟", "參仟", "貳仟", "壹仟", + "九百", "八百", "七百", "六百", "五百", "四百", "參百", "貳百", "壹百", + "九拾", "八拾", "七拾", "六拾", "五拾", "四拾", "參拾", "貳拾", "壹拾", + "九", "八", "七", "六", "五", "四", "參", "貳", "壹", "零" +}; +static const struct list_counter_style lcs_korean_hanja_formal = { + .name = "korean-hanja-formal", + .system = calc_additive_system, + .fallback = &lcs_cjk_decimal, + .symbols = korean_hanja_formal_symbols, + .weights = complex_counter_weights, + .items = (sizeof(korean_hanja_formal_symbols) / SYMBOL_SIZE), + .range = { .start = -9999, .end = 9999 }, + .negative = { .pre = "\xEB\xA7\x88\xEC\x9D\xB4\xEB\x84\x88\xEC\x8A\xA4 " }, + .suffix = ", ", +}; + + + +static const struct list_counter_style * +counter_style_from_computed_style(const css_computed_style *style) +{ + switch (get_list_style_type(style)) { + case CSS_LIST_STYLE_TYPE_DISC: + return &lcs_disc; + case CSS_LIST_STYLE_TYPE_CIRCLE: + return &lcs_circle; + case CSS_LIST_STYLE_TYPE_SQUARE: + return &lcs_square; + case CSS_LIST_STYLE_TYPE_DECIMAL: + return &lcs_decimal; + case CSS_LIST_STYLE_TYPE_DECIMAL_LEADING_ZERO: + return &lcs_decimal_leading_zero; + case CSS_LIST_STYLE_TYPE_LOWER_ROMAN: + return &lcs_lower_roman; + case CSS_LIST_STYLE_TYPE_UPPER_ROMAN: + return &lcs_upper_roman; + case CSS_LIST_STYLE_TYPE_LOWER_GREEK: + return &lcs_lower_greek; + case CSS_LIST_STYLE_TYPE_LOWER_ALPHA: + case CSS_LIST_STYLE_TYPE_LOWER_LATIN: + return &lcs_lower_alpha; + case CSS_LIST_STYLE_TYPE_UPPER_ALPHA: + case CSS_LIST_STYLE_TYPE_UPPER_LATIN: + return &lcs_upper_alpha; + case CSS_LIST_STYLE_TYPE_UPPER_ARMENIAN: + case CSS_LIST_STYLE_TYPE_ARMENIAN: + return &lcs_upper_armenian; + case CSS_LIST_STYLE_TYPE_GEORGIAN: + return &lcs_georgian; + case CSS_LIST_STYLE_TYPE_NONE: + return NULL; + case CSS_LIST_STYLE_TYPE_BINARY: + return &lcs_binary; + case CSS_LIST_STYLE_TYPE_OCTAL: + return &lcs_octal; + case CSS_LIST_STYLE_TYPE_LOWER_HEXADECIMAL: + return &lcs_lower_hexadecimal; + case CSS_LIST_STYLE_TYPE_UPPER_HEXADECIMAL: + return &lcs_upper_hexadecimal; + case CSS_LIST_STYLE_TYPE_ARABIC_INDIC: + return &lcs_arabic_indic; + case CSS_LIST_STYLE_TYPE_LOWER_ARMENIAN: + return &lcs_lower_armenian; + case CSS_LIST_STYLE_TYPE_BENGALI: + return &lcs_bengali; + case CSS_LIST_STYLE_TYPE_CAMBODIAN: + case CSS_LIST_STYLE_TYPE_KHMER: + return &lcs_cambodian; + case CSS_LIST_STYLE_TYPE_CJK_DECIMAL: + return &lcs_cjk_decimal; + case CSS_LIST_STYLE_TYPE_DEVANAGARI: + return &lcs_devanagari; + case CSS_LIST_STYLE_TYPE_GUJARATI: + return &lcs_gujarati; + case CSS_LIST_STYLE_TYPE_GURMUKHI: + return &lcs_gurmukhi; + case CSS_LIST_STYLE_TYPE_HEBREW: + return &lcs_hebrew; + case CSS_LIST_STYLE_TYPE_KANNADA: + return &lcs_kannada; + case CSS_LIST_STYLE_TYPE_LAO: + return &lcs_lao; + case CSS_LIST_STYLE_TYPE_MALAYALAM: + return &lcs_malayalam; + case CSS_LIST_STYLE_TYPE_MONGOLIAN: + return &lcs_mongolian; + case CSS_LIST_STYLE_TYPE_MYANMAR: + return &lcs_myanmar; + case CSS_LIST_STYLE_TYPE_ORIYA: + return &lcs_oriya; + case CSS_LIST_STYLE_TYPE_PERSIAN: + return &lcs_persian; + case CSS_LIST_STYLE_TYPE_TAMIL: + return &lcs_tamil; + case CSS_LIST_STYLE_TYPE_TELUGU: + return &lcs_telugu; + case CSS_LIST_STYLE_TYPE_THAI: + return &lcs_thai; + case CSS_LIST_STYLE_TYPE_TIBETAN: + return &lcs_tibetan; + case CSS_LIST_STYLE_TYPE_CJK_EARTHLY_BRANCH: + return &lcs_cjk_earthly_branch; + case CSS_LIST_STYLE_TYPE_CJK_HEAVENLY_STEM: + return &lcs_cjk_heavenly_stem; + case CSS_LIST_STYLE_TYPE_HIAGANA: + return &lcs_hiragana; + case CSS_LIST_STYLE_TYPE_HIAGANA_IROHA: + return &lcs_hiragana_iroha; + case CSS_LIST_STYLE_TYPE_KATAKANA: + return &lcs_katakana; + case CSS_LIST_STYLE_TYPE_KATAKANA_IROHA: + return &lcs_katakana_iroha; + case CSS_LIST_STYLE_TYPE_JAPANESE_INFORMAL: + return &lcs_japanese_informal; + case CSS_LIST_STYLE_TYPE_JAPANESE_FORMAL: + return &lcs_japanese_formal; + case CSS_LIST_STYLE_TYPE_KOREAN_HANGUL_FORMAL: + return &lcs_korean_hangul_formal; + case CSS_LIST_STYLE_TYPE_KOREAN_HANJA_INFORMAL: + return &lcs_korean_hanja_informal; + case CSS_LIST_STYLE_TYPE_KOREAN_HANJA_FORMAL: + return &lcs_korean_hanja_formal; + } + return NULL; +} + + +/* exported interface defined in select.h */ +css_error css_computed_format_list_style( + const css_computed_style *style, + int value, + char *buffer, + size_t buffer_length, + size_t *format_length) +{ + css_error res = CSS_INVALID; + const struct list_counter_style *cstyle; + uint8_t aval[20]; + struct numeric nval = { + .val = aval, + .len = sizeof(aval), + .used = 0, + .negative = false + }; + + + cstyle = counter_style_from_computed_style(style); + while (cstyle != NULL) { + res = cstyle->system(value, cstyle, &nval); + + if ((res == CSS_OK) && + (nval.used < nval.len)) { + /* system sucessfully generated numeric values */ + *format_length = nval_to_symbols(&nval, + cstyle, + buffer, + buffer_length); + break; + } + + res = CSS_INVALID; + cstyle = cstyle->fallback; + } + + return res; +} diff --git a/src/select/hash.c b/src/select/hash.c index dce4065..12e82aa 100644 --- a/src/select/hash.c +++ b/src/select/hash.c @@ -8,8 +8,11 @@ #include <stdio.h> #include <string.h> +#include <libcss/hint.h> + #include "stylesheet.h" #include "select/hash.h" +#include "select/mq.h" #include "utils/utils.h" #undef PRINT_CHAIN_BLOOM_DETAILS @@ -106,36 +109,6 @@ static inline bool _chain_good_for_element_name(const css_selector *selector, return true; } -/** - * Test whether the rule applies for current media. - * - * \param rule Rule to test - * \meaid media Current media type(s) - * \return true iff chain's rule applies for media - */ -static inline bool _rule_good_for_media(const css_rule *rule, uint64_t media) -{ - bool applies = true; - const css_rule *ancestor = rule; - - while (ancestor != NULL) { - const css_rule_media *m = (const css_rule_media *) ancestor; - - if (ancestor->type == CSS_RULE_MEDIA && - (m->media & media) == 0) { - applies = false; - break; - } - - if (ancestor->ptype != CSS_RULE_PARENT_STYLESHEET) - ancestor = ancestor->parent; - else - ancestor = NULL; - } - - return applies; -} - /** * Create a hash @@ -396,8 +369,9 @@ css_error css__selector_hash_find(css_selector_hash *hash, if (css_bloom_in_bloom( head->sel_chain_bloom, req->node_bloom) && - _rule_good_for_media(head->sel->rule, - req->media)) { + mq_rule_good_for_media(head->sel->rule, + req->unit_ctx, req->media, + req->str)) { /* Found a match */ break; } @@ -473,10 +447,12 @@ css_error css__selector_hash_find_by_class(css_selector_hash *hash, _chain_good_for_element_name( head->sel, &(req->qname), - req->uni) && - _rule_good_for_media( + req->str->universal) && + mq_rule_good_for_media( head->sel->rule, - req->media)) { + req->unit_ctx, + req->media, + req->str)) { /* Found a match */ break; } @@ -553,10 +529,12 @@ css_error css__selector_hash_find_by_id(css_selector_hash *hash, _chain_good_for_element_name( head->sel, &req->qname, - req->uni) && - _rule_good_for_media( + req->str->universal) && + mq_rule_good_for_media( head->sel->rule, - req->media)) { + req->unit_ctx, + req->media, + req->str)) { /* Found a match */ break; } @@ -605,8 +583,9 @@ css_error css__selector_hash_find_universal(css_selector_hash *hash, css_bloom_in_bloom( head->sel_chain_bloom, req->node_bloom) && - _rule_good_for_media(head->sel->rule, - req->media)) { + mq_rule_good_for_media(head->sel->rule, + req->unit_ctx, req->media, + req->str)) { /* Found a match */ break; } @@ -786,7 +765,7 @@ static void print_chain_bloom_details(css_bloom bloom[CSS_BLOOM_SIZE]) { printf("Chain bloom:\t"); int total = 0, i; - int set[4]; + int set[CSS_BLOOM_SIZE]; for (i = 0; i < CSS_BLOOM_SIZE; i++) { set[i] = bits_set(bloom[i]); total += set[i]; @@ -844,24 +823,23 @@ css_error _insert_into_chain(css_selector_hash *ctx, hash_entry *head, search = search->next; } while (search != NULL); - entry->sel = selector; - _chain_bloom_generate(selector, entry->sel_chain_bloom); - -#ifdef PRINT_CHAIN_BLOOM_DETAILS - print_chain_bloom_details(entry->sel_chain_bloom); -#endif - if (prev == NULL) { - hash_entry temp; - entry->next = entry; - temp = *entry; *entry = *head; - *head = temp; + head->next = entry; + + entry = head; } else { entry->next = prev->next; prev->next = entry; } + entry->sel = selector; + _chain_bloom_generate(selector, entry->sel_chain_bloom); + +#ifdef PRINT_CHAIN_BLOOM_DETAILS + print_chain_bloom_details(entry->sel_chain_bloom); +#endif + ctx->hash_size += sizeof(hash_entry); } @@ -949,8 +927,9 @@ css_error _iterate_elements( if (css_bloom_in_bloom( head->sel_chain_bloom, req->node_bloom) && - _rule_good_for_media(head->sel->rule, - req->media)) { + mq_rule_good_for_media(head->sel->rule, + req->unit_ctx, req->media, + req->str)) { /* Found a match */ break; } @@ -1007,10 +986,12 @@ css_error _iterate_classes( _chain_good_for_element_name( head->sel, &(req->qname), - req->uni) && - _rule_good_for_media( + req->str->universal) && + mq_rule_good_for_media( head->sel->rule, - req->media)) { + req->unit_ctx, + req->media, + req->str)) { /* Found a match */ break; } @@ -1068,10 +1049,12 @@ css_error _iterate_ids( _chain_good_for_element_name( head->sel, &req->qname, - req->uni) && - _rule_good_for_media( + req->str->universal) && + mq_rule_good_for_media( head->sel->rule, - req->media)) { + req->unit_ctx, + req->media, + req->str)) { /* Found a match */ break; } @@ -1113,8 +1096,9 @@ css_error _iterate_universal( css_bloom_in_bloom( head->sel_chain_bloom, req->node_bloom) && - _rule_good_for_media(head->sel->rule, - req->media)) { + mq_rule_good_for_media(head->sel->rule, + req->unit_ctx, req->media, + req->str)) { /* Found a match */ break; } diff --git a/src/select/hash.h b/src/select/hash.h index 71f610f..5f48a38 100644 --- a/src/select/hash.h +++ b/src/select/hash.h @@ -10,10 +10,12 @@ #include <libwapcaplet/libwapcaplet.h> +#include <libcss/unit.h> #include <libcss/errors.h> #include <libcss/functypes.h> #include "select/bloom.h" +#include "select/strings.h" /* Ugh. We need this to avoid circular includes. Happy! */ struct css_selector; @@ -24,8 +26,9 @@ struct css_hash_selection_requirments { css_qname qname; /* Element name, or universal "*" */ lwc_string *class; /* Name of class, or NULL */ lwc_string *id; /* Name of id, or NULL */ - lwc_string *uni; /* Universal element string "*" */ - uint64_t media; /* Media type(s) we're selecting for */ + const css_select_strings *str; /* Selection strings */ + const css_media *media; /* Media spec we're selecting for */ + const css_unit_ctx *unit_ctx; /* Document unit conversion context. */ const css_bloom *node_bloom; /* Node's bloom filter */ }; diff --git a/src/select/helpers.h b/src/select/helpers.h new file mode 100644 index 0000000..19ff7de --- /dev/null +++ b/src/select/helpers.h @@ -0,0 +1,48 @@ +/* + * This file is part of LibCSS + * Licensed under the MIT License, + * http://www.opensource.org/licenses/mit-license.php + * Copyright 2009 John-Mark Bell <jmb@netsurf-browser.org> + */ + +#ifndef css_select_helpers_h_ +#define css_select_helpers_h_ + +/** + * Convert unit bytecode to a css_unit. + */ +static inline css_unit css__to_css_unit(uint32_t u) +{ + switch (u) { + case UNIT_PX: return CSS_UNIT_PX; + case UNIT_EX: return CSS_UNIT_EX; + case UNIT_EM: return CSS_UNIT_EM; + case UNIT_IN: return CSS_UNIT_IN; + case UNIT_CM: return CSS_UNIT_CM; + case UNIT_MM: return CSS_UNIT_MM; + case UNIT_PT: return CSS_UNIT_PT; + case UNIT_PC: return CSS_UNIT_PC; + case UNIT_CH: return CSS_UNIT_CH; + case UNIT_REM: return CSS_UNIT_REM; + case UNIT_LH: return CSS_UNIT_LH; + case UNIT_VH: return CSS_UNIT_VH; + case UNIT_VW: return CSS_UNIT_VW; + case UNIT_VI: return CSS_UNIT_VI; + case UNIT_VB: return CSS_UNIT_VB; + case UNIT_VMIN: return CSS_UNIT_VMIN; + case UNIT_VMAX: return CSS_UNIT_VMAX; + case UNIT_Q: return CSS_UNIT_Q; + case UNIT_PCT: return CSS_UNIT_PCT; + case UNIT_DEG: return CSS_UNIT_DEG; + case UNIT_GRAD: return CSS_UNIT_GRAD; + case UNIT_RAD: return CSS_UNIT_RAD; + case UNIT_MS: return CSS_UNIT_MS; + case UNIT_S: return CSS_UNIT_S; + case UNIT_HZ: return CSS_UNIT_HZ; + case UNIT_KHZ: return CSS_UNIT_KHZ; + } + + return 0; +} + +#endif diff --git a/src/select/mq.h b/src/select/mq.h new file mode 100644 index 0000000..89da2c5 --- /dev/null +++ b/src/select/mq.h @@ -0,0 +1,279 @@ +/* + * This file is part of LibCSS + * Licensed under the MIT License, + * http://www.opensource.org/licenses/mit-license.php + * + * Copyright 2018 Michael Drake <tlsa@netsurf-browser.org> + */ + +#ifndef css_select_mq_h_ +#define css_select_mq_h_ + +#include "select/helpers.h" +#include "select/strings.h" +#include "select/unit.h" + +static inline bool mq_match_feature_range_length_op1( + css_mq_feature_op op, + const css_mq_value *value, + const css_fixed client_len, + const css_unit_ctx *unit_ctx) +{ + css_fixed v; + + if (value->type != CSS_MQ_VALUE_TYPE_DIM) { + return false; + } + + if (value->data.dim.unit != UNIT_PX) { + v = css_unit_len2px_mq(unit_ctx, + value->data.dim.len, + css__to_css_unit(value->data.dim.unit)); + } else { + v = value->data.dim.len; + } + + switch (op) { + case CSS_MQ_FEATURE_OP_BOOL: return false; + case CSS_MQ_FEATURE_OP_LT: return v < client_len; + case CSS_MQ_FEATURE_OP_LTE: return v <= client_len; + case CSS_MQ_FEATURE_OP_EQ: return v == client_len; + case CSS_MQ_FEATURE_OP_GTE: return v >= client_len; + case CSS_MQ_FEATURE_OP_GT: return v > client_len; + default: + return false; + } +} + +static inline bool mq_match_feature_range_length_op2( + css_mq_feature_op op, + const css_mq_value *value, + const css_fixed client_len, + const css_unit_ctx *unit_ctx) +{ + css_fixed v; + + if (op == CSS_MQ_FEATURE_OP_UNUSED) { + return true; + } + if (value->type != CSS_MQ_VALUE_TYPE_DIM) { + return false; + } + + if (value->data.dim.unit != UNIT_PX) { + v = css_unit_len2px_mq(unit_ctx, + value->data.dim.len, + css__to_css_unit(value->data.dim.unit)); + } else { + v = value->data.dim.len; + } + + switch (op) { + case CSS_MQ_FEATURE_OP_LT: return client_len < v; + case CSS_MQ_FEATURE_OP_LTE: return client_len <= v; + case CSS_MQ_FEATURE_OP_EQ: return client_len == v; + case CSS_MQ_FEATURE_OP_GTE: return client_len >= v; + case CSS_MQ_FEATURE_OP_GT: return client_len > v; + default: + return false; + } +} + +static inline bool mq_match_feature_eq_ident_op1( + css_mq_feature_op op, + const css_mq_value *value, + const lwc_string *client_value) +{ + bool is_match; + + if (value->type != CSS_MQ_VALUE_TYPE_IDENT) { + return false; + } + + if (value->data.ident == NULL || client_value == NULL) { + return false; + } + + switch (op) { + case CSS_MQ_FEATURE_OP_EQ: + return (lwc_string_isequal(value->data.ident, + client_value, &is_match) == lwc_error_ok) && + is_match; + default: + return false; + } +} + +/** + * Match media query features. + * + * \param[in] feat Condition to match. + * \param[in] unit_ctx Current unit conversion context. + * \param[in] media Current media spec, to check against feat. + * \return true if condition matches, otherwise false. + */ +static inline bool mq_match_feature( + const css_mq_feature *feat, + const css_unit_ctx *unit_ctx, + const css_media *media, + const css_select_strings *str) +{ + bool match; + + /* TODO: Use interned string for comparison. */ + if (lwc_string_isequal(feat->name, + str->width, &match) == lwc_error_ok && + match == true) { + if (!mq_match_feature_range_length_op1(feat->op, &feat->value, + media->width, unit_ctx)) { + return false; + } + return mq_match_feature_range_length_op2(feat->op2, + &feat->value2, media->width, unit_ctx); + + } else if (lwc_string_isequal(feat->name, + str->height, &match) == lwc_error_ok && + match == true) { + if (!mq_match_feature_range_length_op1(feat->op, &feat->value, + media->height, unit_ctx)) { + return false; + } + + return mq_match_feature_range_length_op2(feat->op2, + &feat->value2, media->height, unit_ctx); + + } else if (lwc_string_isequal(feat->name, + str->prefers_color_scheme, &match) == lwc_error_ok && + match == true) { + if (mq_match_feature_eq_ident_op1(feat->op, &feat->value, + media->prefers_color_scheme) || + feat->op == CSS_MQ_FEATURE_OP_BOOL) { + return true; + } + + return false; + } + + /* TODO: Look at other feature names. */ + + return false; +} + +/** + * Match media query conditions. + * + * \param[in] cond Condition to match. + * \param[in] unit_ctx Current unit conversion context. + * \param[in] media Current media spec, to check against cond. + * \return true if condition matches, otherwise false. + */ +static inline bool mq_match_condition( + const css_mq_cond *cond, + const css_unit_ctx *unit_ctx, + const css_media *media, + const css_select_strings *str) +{ + bool matched = !cond->op; + + for (uint32_t i = 0; i < cond->nparts; i++) { + bool part_matched; + if (cond->parts[i]->type == CSS_MQ_FEATURE) { + part_matched = mq_match_feature( + cond->parts[i]->data.feat, + unit_ctx, media, str); + } else { + assert(cond->parts[i]->type == CSS_MQ_COND); + part_matched = mq_match_condition( + cond->parts[i]->data.cond, + unit_ctx, media, str); + } + + if (cond->op) { + /* OR */ + matched |= part_matched; + if (matched) { + break; /* Short-circuit */ + } + } else { + /* AND */ + matched &= part_matched; + if (!matched) { + break; /* Short-circuit */ + } + } + } + + return matched != cond->negate; +} + +/** + * Test whether media query list matches current media. + * + * If anything in the list matches, the list matches. If none match + * it doesn't match. + * + * \param[in] m Media query list. + * \param[in] unit_ctx Current unit conversion context. + * \param[in] media Current media spec, to check against m. + * \return true if media query list matches media + */ +static inline bool mq__list_match( + const css_mq_query *m, + const css_unit_ctx *unit_ctx, + const css_media *media, + const css_select_strings *str) +{ + for (; m != NULL; m = m->next) { + /* Check type */ + if (!!(m->type & media->type) != m->negate_type) { + if (m->cond == NULL || + mq_match_condition(m->cond, + unit_ctx, media, str)) { + /* We have a match, no need to look further. */ + return true; + } + } + } + + return false; +} + +/** + * Test whether the rule applies for current media. + * + * \param rule Rule to test + * \param unit_ctx Current unit conversion context. + * \param media Current media spec + * \return true iff chain's rule applies for media + */ +static inline bool mq_rule_good_for_media( + const css_rule *rule, + const css_unit_ctx *unit_ctx, + const css_media *media, + const css_select_strings *str) +{ + bool applies = true; + const css_rule *ancestor = rule; + + while (ancestor != NULL) { + const css_rule_media *m = (const css_rule_media *) ancestor; + + if (ancestor->type == CSS_RULE_MEDIA) { + applies = mq__list_match(m->media, + unit_ctx, media, str); + if (applies == false) { + break; + } + } + + if (ancestor->ptype != CSS_RULE_PARENT_STYLESHEET) { + ancestor = ancestor->parent; + } else { + ancestor = NULL; + } + } + + return applies; +} + +#endif diff --git a/src/select/overrides.py b/src/select/overrides.py new file mode 100644 index 0000000..869d6ec --- /dev/null +++ b/src/select/overrides.py @@ -0,0 +1,185 @@ +# This file is part of LibCSS. +# Licensed under the MIT License, +# http://www.opensource.org/licenses/mit-license.php +# Copyright 2017 Lucas Neves <lcneves@gmail.com> + +overrides = { + 'get': {}, + 'set': {}, + 'properties': {} +} + +overrides['get']['clip'] = '''\ +static inline uint8_t get_clip( + const css_computed_style *style, + css_computed_clip_rect *rect) +{ + uint32_t bits = style->i.bits[CLIP_INDEX]; + bits &= CLIP_MASK; + bits >>= CLIP_SHIFT; + + /* + 26bits: tt tttr rrrr bbbb blll llTR BLyy: + units: top | right | bottom | left + opcodes: top | right | bottom | left | type + */ + + if ((bits & 0x3) == CSS_CLIP_RECT) { + rect->left_auto = (bits & 0x4); + rect->bottom_auto = (bits & 0x8); + rect->right_auto = (bits & 0x10); + rect->top_auto = (bits & 0x20); + + rect->top = style->i.clip_a; + rect->tunit = bits & 0x3e00000 >> 21; + + rect->right = style->i.clip_b; + rect->runit = bits & 0x1f0000 >> 16; + + rect->bottom = style->i.clip_c; + rect->bunit = (bits & 0xf800) >> 11; + + rect->left = style->i.clip_d; + rect->lunit = (bits & 0x7c0) >> 6; + } + + return (bits & 0x3); +}''' + +overrides['set']['clip'] = '''\ +static inline css_error set_clip( + css_computed_style *style, uint8_t type, + css_computed_clip_rect *rect) +{ + uint32_t *bits; + + bits = &style->i.bits[CLIP_INDEX]; + + /* + 26bits: tt tttr rrrr bbbb blll llTR BLyy: + units: top | right | bottom | left + opcodes: top | right | bottom | left | type + */ + *bits = (*bits & ~CLIP_MASK) | + ((type & 0x3) << CLIP_SHIFT); + + if (type == CSS_CLIP_RECT) { + *bits |= (((rect->top_auto ? 0x20 : 0) | + (rect->right_auto ? 0x10 : 0) | + (rect->bottom_auto ? 0x8 : 0) | + (rect->left_auto ? 0x4 : 0)) << CLIP_SHIFT); + + *bits |= (((rect->tunit << 5) | rect->runit) + << (CLIP_SHIFT + 16)); + + *bits |= (((rect->bunit << 5) | rect->lunit) + << (CLIP_SHIFT + 6)); + + style->i.clip_a = rect->top; + style->i.clip_b = rect->right; + style->i.clip_c = rect->bottom; + style->i.clip_d = rect->left; + } + + return CSS_OK; +}''' + +overrides['get']['line_height'] = '''\ +static inline uint8_t get_line_height( + const css_computed_style *style, + css_fixed *length, css_unit *unit) +{ + uint32_t bits = style->i.bits[LINE_HEIGHT_INDEX]; + bits &= LINE_HEIGHT_MASK; + bits >>= LINE_HEIGHT_SHIFT; + + /* 7bits: uuuuutt : units | type */ + if ((bits & 0x3) == CSS_LINE_HEIGHT_NUMBER || + (bits & 0x3) == CSS_LINE_HEIGHT_DIMENSION) { + *length = style->i.line_height; + } + + if ((bits & 0x3) == CSS_LINE_HEIGHT_DIMENSION) { + *unit = bits >> 2; + } + + return (bits & 0x3); +}''' + +overrides['set']['content'] = '''\ +static inline css_error set_content( + css_computed_style *style, uint8_t type, + css_computed_content_item *content) +{ + uint32_t *bits; + css_computed_content_item *oldcontent; + css_computed_content_item *c; + + /* 2bits: type */ + bits = &style->i.bits[CONTENT_INDEX]; + oldcontent = style->content; + + *bits = (*bits & ~CONTENT_MASK) | + ((type & 0x3) << CONTENT_SHIFT); + + for (c = content; c != NULL && + c->type != CSS_COMPUTED_CONTENT_NONE; c++) { + switch (c->type) { + case CSS_COMPUTED_CONTENT_STRING: + c->data.string = lwc_string_ref(c->data.string); + break; + case CSS_COMPUTED_CONTENT_URI: + c->data.uri = lwc_string_ref(c->data.uri); + break; + case CSS_COMPUTED_CONTENT_ATTR: + c->data.attr = lwc_string_ref(c->data.attr); + break; + case CSS_COMPUTED_CONTENT_COUNTER: + c->data.counter.name = + lwc_string_ref(c->data.counter.name); + break; + case CSS_COMPUTED_CONTENT_COUNTERS: + c->data.counters.name = + lwc_string_ref(c->data.counters.name); + c->data.counters.sep = + lwc_string_ref(c->data.counters.sep); + break; + default: + break; + } + } + + style->content = content; + + /* Free existing array */ + if (oldcontent != NULL) { + for (c = oldcontent; + c->type != CSS_COMPUTED_CONTENT_NONE; c++) { + switch (c->type) { + case CSS_COMPUTED_CONTENT_STRING: + lwc_string_unref(c->data.string); + break; + case CSS_COMPUTED_CONTENT_URI: + lwc_string_unref(c->data.uri); + break; + case CSS_COMPUTED_CONTENT_ATTR: + lwc_string_unref(c->data.attr); + break; + case CSS_COMPUTED_CONTENT_COUNTER: + lwc_string_unref(c->data.counter.name); + break; + case CSS_COMPUTED_CONTENT_COUNTERS: + lwc_string_unref(c->data.counters.name); + lwc_string_unref(c->data.counters.sep); + break; + default: + break; + } + } + + if (oldcontent != content) + free(oldcontent); + } + + return CSS_OK; +}''' diff --git a/src/select/properties/Makefile b/src/select/properties/Makefile index 288eda9..eee6cc3 100644 --- a/src/select/properties/Makefile +++ b/src/select/properties/Makefile @@ -1,5 +1,8 @@ # Sources DIR_SOURCES := helpers.c \ +align_content.c \ +align_items.c \ +align_self.c \ azimuth.c \ background_attachment.c \ background_color.c \ @@ -47,6 +50,12 @@ direction.c \ display.c \ elevation.c \ empty_cells.c \ +fill_opacity.c \ +flex_basis.c \ +flex_direction.c \ +flex_grow.c \ +flex_shrink.c \ +flex_wrap.c \ float.c \ font_family.c \ font_size.c \ @@ -54,6 +63,7 @@ font_style.c \ font_variant.c \ font_weight.c \ height.c \ +justify_content.c \ left.c \ letter_spacing.c \ line_height.c \ @@ -69,6 +79,7 @@ max_width.c \ min_height.c \ min_width.c \ opacity.c \ +order.c \ orphans.c \ outline_color.c \ outline_style.c \ @@ -97,6 +108,7 @@ speak_header.c \ speak_numeral.c \ speak_punctuation.c \ stress.c \ +stroke_opacity.c \ table_layout.c \ text_align.c \ text_decoration.c \ diff --git a/src/select/properties/align_content.c b/src/select/properties/align_content.c new file mode 100644 index 0000000..d432879 --- /dev/null +++ b/src/select/properties/align_content.c @@ -0,0 +1,90 @@ +/* + * This file is part of LibCSS + * Licensed under the MIT License, + * http://www.opensource.org/licenses/mit-license.php + * Copyright 2017 Lucas Neves <lcneves@gmail.com> + */ + +#include "bytecode/bytecode.h" +#include "bytecode/opcodes.h" +#include "select/propset.h" +#include "select/propget.h" +#include "utils/utils.h" + +#include "select/properties/properties.h" +#include "select/properties/helpers.h" + +css_error css__cascade_align_content(uint32_t opv, css_style *style, + css_select_state *state) +{ + uint16_t value = CSS_ALIGN_CONTENT_INHERIT; + + UNUSED(style); + + if (hasFlagValue(opv) == false) { + switch (getValue(opv)) { + case ALIGN_CONTENT_STRETCH: + value = CSS_ALIGN_CONTENT_STRETCH; + break; + case ALIGN_CONTENT_FLEX_START: + value = CSS_ALIGN_CONTENT_FLEX_START; + break; + case ALIGN_CONTENT_FLEX_END: + value = CSS_ALIGN_CONTENT_FLEX_END; + break; + case ALIGN_CONTENT_CENTER: + value = CSS_ALIGN_CONTENT_CENTER; + break; + case ALIGN_CONTENT_SPACE_BETWEEN: + value = CSS_ALIGN_CONTENT_SPACE_BETWEEN; + break; + case ALIGN_CONTENT_SPACE_AROUND: + value = CSS_ALIGN_CONTENT_SPACE_AROUND; + break; + case ALIGN_CONTENT_SPACE_EVENLY: + value = CSS_ALIGN_CONTENT_SPACE_EVENLY; + break; + } + } + + if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, + getFlagValue(opv))) { + return set_align_content(state->computed, value); + } + + return CSS_OK; +} + +css_error css__set_align_content_from_hint(const css_hint *hint, + css_computed_style *style) +{ + return set_align_content(style, hint->status); +} + +css_error css__initial_align_content(css_select_state *state) +{ + return set_align_content(state->computed, CSS_ALIGN_CONTENT_STRETCH); +} + +css_error css__copy_align_content( + const css_computed_style *from, + css_computed_style *to) +{ + if (from == to) { + return CSS_OK; + } + + return set_align_content(to, get_align_content(from)); +} + +css_error css__compose_align_content(const css_computed_style *parent, + const css_computed_style *child, + css_computed_style *result) +{ + uint8_t type = get_align_content(child); + + return css__copy_align_content( + type == CSS_ALIGN_CONTENT_INHERIT ? parent : child, + result); +} + diff --git a/src/select/properties/align_items.c b/src/select/properties/align_items.c new file mode 100644 index 0000000..52ca094 --- /dev/null +++ b/src/select/properties/align_items.c @@ -0,0 +1,84 @@ +/* + * This file is part of LibCSS + * Licensed under the MIT License, + * http://www.opensource.org/licenses/mit-license.php + * Copyright 2017 Lucas Neves <lcneves@gmail.com> + */ + +#include "bytecode/bytecode.h" +#include "bytecode/opcodes.h" +#include "select/propset.h" +#include "select/propget.h" +#include "utils/utils.h" + +#include "select/properties/properties.h" +#include "select/properties/helpers.h" + +css_error css__cascade_align_items(uint32_t opv, css_style *style, + css_select_state *state) +{ + uint16_t value = CSS_ALIGN_ITEMS_INHERIT; + + UNUSED(style); + + if (hasFlagValue(opv) == false) { + switch (getValue(opv)) { + case ALIGN_ITEMS_STRETCH: + value = CSS_ALIGN_ITEMS_STRETCH; + break; + case ALIGN_ITEMS_FLEX_START: + value = CSS_ALIGN_ITEMS_FLEX_START; + break; + case ALIGN_ITEMS_FLEX_END: + value = CSS_ALIGN_ITEMS_FLEX_END; + break; + case ALIGN_ITEMS_CENTER: + value = CSS_ALIGN_ITEMS_CENTER; + break; + case ALIGN_ITEMS_BASELINE: + value = CSS_ALIGN_ITEMS_BASELINE; + break; + } + } + + if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, + getFlagValue(opv))) { + return set_align_items(state->computed, value); + } + + return CSS_OK; +} + +css_error css__set_align_items_from_hint(const css_hint *hint, + css_computed_style *style) +{ + return set_align_items(style, hint->status); +} + +css_error css__initial_align_items(css_select_state *state) +{ + return set_align_items(state->computed, CSS_ALIGN_ITEMS_STRETCH); +} + +css_error css__copy_align_items( + const css_computed_style *from, + css_computed_style *to) +{ + if (from == to) { + return CSS_OK; + } + + return set_align_items(to, get_align_items(from)); +} + +css_error css__compose_align_items(const css_computed_style *parent, + const css_computed_style *child, + css_computed_style *result) +{ + uint8_t type = get_align_items(child); + + return css__copy_align_items( + type == CSS_ALIGN_ITEMS_INHERIT ? parent : child, + result); +} + diff --git a/src/select/properties/align_self.c b/src/select/properties/align_self.c new file mode 100644 index 0000000..abdb3fe --- /dev/null +++ b/src/select/properties/align_self.c @@ -0,0 +1,87 @@ +/* + * This file is part of LibCSS + * Licensed under the MIT License, + * http://www.opensource.org/licenses/mit-license.php + * Copyright 2017 Lucas Neves <lcneves@gmail.com> + */ + +#include "bytecode/bytecode.h" +#include "bytecode/opcodes.h" +#include "select/propset.h" +#include "select/propget.h" +#include "utils/utils.h" + +#include "select/properties/properties.h" +#include "select/properties/helpers.h" + +css_error css__cascade_align_self(uint32_t opv, css_style *style, + css_select_state *state) +{ + uint16_t value = CSS_ALIGN_SELF_INHERIT; + + UNUSED(style); + + if (hasFlagValue(opv) == false) { + switch (getValue(opv)) { + case ALIGN_SELF_STRETCH: + value = CSS_ALIGN_SELF_STRETCH; + break; + case ALIGN_SELF_FLEX_START: + value = CSS_ALIGN_SELF_FLEX_START; + break; + case ALIGN_SELF_FLEX_END: + value = CSS_ALIGN_SELF_FLEX_END; + break; + case ALIGN_SELF_CENTER: + value = CSS_ALIGN_SELF_CENTER; + break; + case ALIGN_SELF_BASELINE: + value = CSS_ALIGN_SELF_BASELINE; + break; + case ALIGN_SELF_AUTO: + value = CSS_ALIGN_SELF_AUTO; + break; + } + } + + if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, + getFlagValue(opv))) { + return set_align_self(state->computed, value); + } + + return CSS_OK; +} + +css_error css__set_align_self_from_hint(const css_hint *hint, + css_computed_style *style) +{ + return set_align_self(style, hint->status); +} + +css_error css__initial_align_self(css_select_state *state) +{ + return set_align_self(state->computed, CSS_ALIGN_SELF_AUTO); +} + +css_error css__copy_align_self( + const css_computed_style *from, + css_computed_style *to) +{ + if (from == to) { + return CSS_OK; + } + + return set_align_self(to, get_align_self(from)); +} + +css_error css__compose_align_self(const css_computed_style *parent, + const css_computed_style *child, + css_computed_style *result) +{ + uint8_t type = get_align_self(child); + + return css__copy_align_self( + type == CSS_ALIGN_SELF_INHERIT ? parent : child, + result); +} + diff --git a/src/select/properties/azimuth.c b/src/select/properties/azimuth.c index d52110f..bbbb48d 100644 --- a/src/select/properties/azimuth.c +++ b/src/select/properties/azimuth.c @@ -18,7 +18,7 @@ css_error css__cascade_azimuth(uint32_t opv, css_style *style, css_fixed val = 0; uint32_t unit = UNIT_DEG; - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv) & ~AZIMUTH_BEHIND) { case AZIMUTH_ANGLE: val = *((css_fixed *) style->bytecode); @@ -47,7 +47,7 @@ css_error css__cascade_azimuth(uint32_t opv, css_style *style, unit = css__to_css_unit(unit); if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { /** \todo set computed azimuth */ } @@ -70,6 +70,16 @@ css_error css__initial_azimuth(css_select_state *state) return CSS_OK; } +css_error css__copy_azimuth( + const css_computed_style *from, + css_computed_style *to) +{ + UNUSED(from); + UNUSED(to); + + return CSS_OK; +} + css_error css__compose_azimuth(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) diff --git a/src/select/properties/background_attachment.c b/src/select/properties/background_attachment.c index 834c830..49194cc 100644 --- a/src/select/properties/background_attachment.c +++ b/src/select/properties/background_attachment.c @@ -21,7 +21,7 @@ css_error css__cascade_background_attachment(uint32_t opv, css_style *style, UNUSED(style); - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case BACKGROUND_ATTACHMENT_FIXED: value = CSS_BACKGROUND_ATTACHMENT_FIXED; @@ -33,7 +33,7 @@ css_error css__cascade_background_attachment(uint32_t opv, css_style *style, } if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { return set_background_attachment(state->computed, value); } @@ -52,16 +52,25 @@ css_error css__initial_background_attachment(css_select_state *state) CSS_BACKGROUND_ATTACHMENT_SCROLL); } +css_error css__copy_background_attachment( + const css_computed_style *from, + css_computed_style *to) +{ + if (from == to) { + return CSS_OK; + } + + return set_background_attachment(to, get_background_attachment(from)); +} + css_error css__compose_background_attachment(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) { uint8_t type = get_background_attachment(child); - if (type == CSS_BACKGROUND_ATTACHMENT_INHERIT) { - type = get_background_attachment(parent); - } - - return set_background_attachment(result, type); + return css__copy_background_attachment( + type == CSS_BACKGROUND_ATTACHMENT_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/background_color.c b/src/select/properties/background_color.c index bb90604..1ab61e6 100644 --- a/src/select/properties/background_color.c +++ b/src/select/properties/background_color.c @@ -32,6 +32,20 @@ css_error css__initial_background_color(css_select_state *state) CSS_BACKGROUND_COLOR_COLOR, 0); } +css_error css__copy_background_color( + const css_computed_style *from, + css_computed_style *to) +{ + css_color color; + uint8_t type = get_background_color(from, &color); + + if (from == to) { + return CSS_OK; + } + + return set_background_color(to, type, color); +} + css_error css__compose_background_color(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) @@ -39,10 +53,8 @@ css_error css__compose_background_color(const css_computed_style *parent, css_color color; uint8_t type = get_background_color(child, &color); - if (type == CSS_BACKGROUND_COLOR_INHERIT) { - type = get_background_color(parent, &color); - } - - return set_background_color(result, type, color); + return css__copy_background_color( + type == CSS_BACKGROUND_COLOR_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/background_image.c b/src/select/properties/background_image.c index 96f7409..68b1e0f 100644 --- a/src/select/properties/background_image.c +++ b/src/select/properties/background_image.c @@ -39,6 +39,20 @@ css_error css__initial_background_image(css_select_state *state) CSS_BACKGROUND_IMAGE_NONE, NULL); } +css_error css__copy_background_image( + const css_computed_style *from, + css_computed_style *to) +{ + lwc_string *url; + uint8_t type = get_background_image(from, &url); + + if (from == to) { + return CSS_OK; + } + + return set_background_image(to, type, url); +} + css_error css__compose_background_image(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) @@ -46,10 +60,8 @@ css_error css__compose_background_image(const css_computed_style *parent, lwc_string *url; uint8_t type = get_background_image(child, &url); - if (type == CSS_BACKGROUND_IMAGE_INHERIT) { - type = get_background_image(parent, &url); - } - - return set_background_image(result, type, url); + return css__copy_background_image( + type == CSS_BACKGROUND_IMAGE_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/background_position.c b/src/select/properties/background_position.c index d925b9c..f3fe47c 100644 --- a/src/select/properties/background_position.c +++ b/src/select/properties/background_position.c @@ -23,7 +23,7 @@ css_error css__cascade_background_position(uint32_t opv, css_style *style, uint32_t hunit = UNIT_PX; uint32_t vunit = UNIT_PX; - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { value = CSS_BACKGROUND_POSITION_SET; switch (getValue(opv) & 0xf0) { @@ -73,7 +73,7 @@ css_error css__cascade_background_position(uint32_t opv, css_style *style, vunit = css__to_css_unit(vunit); if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { return set_background_position(state->computed, value, hlength, hunit, vlength, vunit); } @@ -96,6 +96,22 @@ css_error css__initial_background_position(css_select_state *state) 0, CSS_UNIT_PCT, 0, CSS_UNIT_PCT); } +css_error css__copy_background_position( + const css_computed_style *from, + css_computed_style *to) +{ + css_fixed hlength = 0, vlength = 0; + css_unit hunit = CSS_UNIT_PX, vunit = CSS_UNIT_PX; + uint8_t type = get_background_position(from, &hlength, &hunit, + &vlength, &vunit); + + if (from == to) { + return CSS_OK; + } + + return set_background_position(to, type, hlength, hunit, vlength, vunit); +} + css_error css__compose_background_position(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) @@ -105,12 +121,8 @@ css_error css__compose_background_position(const css_computed_style *parent, uint8_t type = get_background_position(child, &hlength, &hunit, &vlength, &vunit); - if (type == CSS_BACKGROUND_POSITION_INHERIT) { - type = get_background_position(parent, - &hlength, &hunit, &vlength, &vunit); - } - - return set_background_position(result, type, hlength, hunit, - vlength, vunit); + return css__copy_background_position( + type == CSS_BACKGROUND_POSITION_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/background_repeat.c b/src/select/properties/background_repeat.c index 3881573..7104bfb 100644 --- a/src/select/properties/background_repeat.c +++ b/src/select/properties/background_repeat.c @@ -21,7 +21,7 @@ css_error css__cascade_background_repeat(uint32_t opv, css_style *style, UNUSED(style); - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case BACKGROUND_REPEAT_NO_REPEAT: value = CSS_BACKGROUND_REPEAT_NO_REPEAT; @@ -39,7 +39,7 @@ css_error css__cascade_background_repeat(uint32_t opv, css_style *style, } if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { return set_background_repeat(state->computed, value); } @@ -58,16 +58,25 @@ css_error css__initial_background_repeat(css_select_state *state) CSS_BACKGROUND_REPEAT_REPEAT); } +css_error css__copy_background_repeat( + const css_computed_style *from, + css_computed_style *to) +{ + if (from == to) { + return CSS_OK; + } + + return set_background_repeat(to, get_background_repeat(from)); +} + css_error css__compose_background_repeat(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) { uint8_t type = get_background_repeat(child); - if (type == CSS_BACKGROUND_REPEAT_INHERIT) { - type = get_background_repeat(parent); - } - - return set_background_repeat(result, type); + return css__copy_background_repeat( + type == CSS_BACKGROUND_REPEAT_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/border_bottom_color.c b/src/select/properties/border_bottom_color.c index bdbecb7..1996d71 100644 --- a/src/select/properties/border_bottom_color.c +++ b/src/select/properties/border_bottom_color.c @@ -33,6 +33,20 @@ css_error css__initial_border_bottom_color(css_select_state *state) CSS_BORDER_COLOR_CURRENT_COLOR, 0); } +css_error css__copy_border_bottom_color( + const css_computed_style *from, + css_computed_style *to) +{ + css_color color; + uint8_t type = get_border_bottom_color(from, &color); + + if (from == to) { + return CSS_OK; + } + + return set_border_bottom_color(to, type, color); +} + css_error css__compose_border_bottom_color(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) @@ -40,10 +54,8 @@ css_error css__compose_border_bottom_color(const css_computed_style *parent, css_color color; uint8_t type = get_border_bottom_color(child, &color); - if (type == CSS_BORDER_COLOR_INHERIT) { - type = get_border_bottom_color(parent, &color); - } - - return set_border_bottom_color(result, type, color); + return css__copy_border_bottom_color( + type == CSS_BORDER_COLOR_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/border_bottom_style.c b/src/select/properties/border_bottom_style.c index b5caccb..3451c65 100644 --- a/src/select/properties/border_bottom_style.c +++ b/src/select/properties/border_bottom_style.c @@ -31,16 +31,25 @@ css_error css__initial_border_bottom_style(css_select_state *state) return set_border_bottom_style(state->computed, CSS_BORDER_STYLE_NONE); } +css_error css__copy_border_bottom_style( + const css_computed_style *from, + css_computed_style *to) +{ + if (from == to) { + return CSS_OK; + } + + return set_border_bottom_style(to, get_border_bottom_style(from)); +} + css_error css__compose_border_bottom_style(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) { uint8_t type = get_border_bottom_style(child); - if (type == CSS_BORDER_STYLE_INHERIT) { - type = get_border_bottom_style(parent); - } - - return set_border_bottom_style(result, type); + return css__copy_border_bottom_style( + type == CSS_BORDER_STYLE_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/border_bottom_width.c b/src/select/properties/border_bottom_width.c index b071fba..19f4304 100644 --- a/src/select/properties/border_bottom_width.c +++ b/src/select/properties/border_bottom_width.c @@ -14,16 +14,16 @@ #include "select/properties/properties.h" #include "select/properties/helpers.h" -css_error css__cascade_border_bottom_width(uint32_t opv, css_style *style, +css_error css__cascade_border_bottom_width(uint32_t opv, css_style *width, css_select_state *state) { - return css__cascade_border_width(opv, style, state, set_border_bottom_width); + return css__cascade_border_width(opv, width, state, set_border_bottom_width); } css_error css__set_border_bottom_width_from_hint(const css_hint *hint, - css_computed_style *style) + css_computed_style *width) { - return set_border_bottom_width(style, hint->status, + return set_border_bottom_width(width, hint->status, hint->data.length.value, hint->data.length.unit); } @@ -33,6 +33,21 @@ css_error css__initial_border_bottom_width(css_select_state *state) 0, CSS_UNIT_PX); } +css_error css__copy_border_bottom_width( + const css_computed_style *from, + css_computed_style *to) +{ + css_fixed length = 0; + css_unit unit = CSS_UNIT_PX; + uint8_t type = get_border_bottom_width(from, &length, &unit); + + if (from == to) { + return CSS_OK; + } + + return set_border_bottom_width(to, type, length, unit); +} + css_error css__compose_border_bottom_width(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) @@ -41,10 +56,8 @@ css_error css__compose_border_bottom_width(const css_computed_style *parent, css_unit unit = CSS_UNIT_PX; uint8_t type = get_border_bottom_width(child, &length, &unit); - if (type == CSS_BORDER_WIDTH_INHERIT) { - type = get_border_bottom_width(parent, &length, &unit); - } - - return set_border_bottom_width(result, type, length, unit); + return css__copy_border_bottom_width( + type == CSS_BORDER_WIDTH_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/border_collapse.c b/src/select/properties/border_collapse.c index 1363c7c..8868e6b 100644 --- a/src/select/properties/border_collapse.c +++ b/src/select/properties/border_collapse.c @@ -21,7 +21,7 @@ css_error css__cascade_border_collapse(uint32_t opv, css_style *style, UNUSED(style); - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case BORDER_COLLAPSE_SEPARATE: value = CSS_BORDER_COLLAPSE_SEPARATE; @@ -33,7 +33,7 @@ css_error css__cascade_border_collapse(uint32_t opv, css_style *style, } if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { return set_border_collapse(state->computed, value); } @@ -51,16 +51,25 @@ css_error css__initial_border_collapse(css_select_state *state) return set_border_collapse(state->computed, CSS_BORDER_COLLAPSE_SEPARATE); } +css_error css__copy_border_collapse( + const css_computed_style *from, + css_computed_style *to) +{ + if (from == to) { + return CSS_OK; + } + + return set_border_collapse(to, get_border_collapse(from)); +} + css_error css__compose_border_collapse(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) { uint8_t type = get_border_collapse(child); - if (type == CSS_BORDER_COLLAPSE_INHERIT) { - type = get_border_collapse(parent); - } - - return set_border_collapse(result, type); + return css__copy_border_collapse( + type == CSS_BORDER_COLLAPSE_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/border_left_color.c b/src/select/properties/border_left_color.c index 2880751..60b81ae 100644 --- a/src/select/properties/border_left_color.c +++ b/src/select/properties/border_left_color.c @@ -33,6 +33,20 @@ css_error css__initial_border_left_color(css_select_state *state) CSS_BORDER_COLOR_CURRENT_COLOR, 0); } +css_error css__copy_border_left_color( + const css_computed_style *from, + css_computed_style *to) +{ + css_color color; + uint8_t type = get_border_left_color(from, &color); + + if (from == to) { + return CSS_OK; + } + + return set_border_left_color(to, type, color); +} + css_error css__compose_border_left_color(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) @@ -40,10 +54,8 @@ css_error css__compose_border_left_color(const css_computed_style *parent, css_color color; uint8_t type = get_border_left_color(child, &color); - if (type == CSS_BORDER_COLOR_INHERIT) { - type = get_border_left_color(parent, &color); - } - - return set_border_left_color(result, type, color); + return css__copy_border_left_color( + type == CSS_BORDER_COLOR_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/border_left_style.c b/src/select/properties/border_left_style.c index e6472b3..99b5494 100644 --- a/src/select/properties/border_left_style.c +++ b/src/select/properties/border_left_style.c @@ -31,16 +31,25 @@ css_error css__initial_border_left_style(css_select_state *state) return set_border_left_style(state->computed, CSS_BORDER_STYLE_NONE); } +css_error css__copy_border_left_style( + const css_computed_style *from, + css_computed_style *to) +{ + if (from == to) { + return CSS_OK; + } + + return set_border_left_style(to, get_border_left_style(from)); +} + css_error css__compose_border_left_style(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) { uint8_t type = get_border_left_style(child); - if (type == CSS_BORDER_STYLE_INHERIT) { - type = get_border_left_style(parent); - } - - return set_border_left_style(result, type); + return css__copy_border_left_style( + type == CSS_BORDER_STYLE_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/border_left_width.c b/src/select/properties/border_left_width.c index 1278fa9..e1fc822 100644 --- a/src/select/properties/border_left_width.c +++ b/src/select/properties/border_left_width.c @@ -33,6 +33,21 @@ css_error css__initial_border_left_width(css_select_state *state) 0, CSS_UNIT_PX); } +css_error css__copy_border_left_width( + const css_computed_style *from, + css_computed_style *to) +{ + css_fixed length = 0; + css_unit unit = CSS_UNIT_PX; + uint8_t type = get_border_left_width(from, &length, &unit); + + if (from == to) { + return CSS_OK; + } + + return set_border_left_width(to, type, length, unit); +} + css_error css__compose_border_left_width(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) @@ -41,10 +56,8 @@ css_error css__compose_border_left_width(const css_computed_style *parent, css_unit unit = CSS_UNIT_PX; uint8_t type = get_border_left_width(child, &length, &unit); - if (type == CSS_BORDER_WIDTH_INHERIT) { - type = get_border_left_width(parent, &length, &unit); - } - - return set_border_left_width(result, type, length, unit); + return css__copy_border_left_width( + type == CSS_BORDER_WIDTH_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/border_right_color.c b/src/select/properties/border_right_color.c index b8563e6..815ca9c 100644 --- a/src/select/properties/border_right_color.c +++ b/src/select/properties/border_right_color.c @@ -33,6 +33,20 @@ css_error css__initial_border_right_color(css_select_state *state) CSS_BORDER_COLOR_CURRENT_COLOR, 0); } +css_error css__copy_border_right_color( + const css_computed_style *from, + css_computed_style *to) +{ + css_color color; + uint8_t type = get_border_right_color(from, &color); + + if (from == to) { + return CSS_OK; + } + + return set_border_right_color(to, type, color); +} + css_error css__compose_border_right_color(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) @@ -40,10 +54,8 @@ css_error css__compose_border_right_color(const css_computed_style *parent, css_color color; uint8_t type = get_border_right_color(child, &color); - if (type == CSS_BORDER_COLOR_INHERIT) { - type = get_border_right_color(parent, &color); - } - - return set_border_right_color(result, type, color); + return css__copy_border_right_color( + type == CSS_BORDER_COLOR_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/border_right_style.c b/src/select/properties/border_right_style.c index d75a99e..d14fbfb 100644 --- a/src/select/properties/border_right_style.c +++ b/src/select/properties/border_right_style.c @@ -31,16 +31,25 @@ css_error css__initial_border_right_style(css_select_state *state) return set_border_right_style(state->computed, CSS_BORDER_STYLE_NONE); } +css_error css__copy_border_right_style( + const css_computed_style *from, + css_computed_style *to) +{ + if (from == to) { + return CSS_OK; + } + + return set_border_right_style(to, get_border_right_style(from)); +} + css_error css__compose_border_right_style(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) { uint8_t type = get_border_right_style(child); - if (type == CSS_BORDER_STYLE_INHERIT) { - type = get_border_right_style(parent); - } - - return set_border_right_style(result, type); + return css__copy_border_right_style( + type == CSS_BORDER_STYLE_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/border_right_width.c b/src/select/properties/border_right_width.c index 18cacd2..93e8f19 100644 --- a/src/select/properties/border_right_width.c +++ b/src/select/properties/border_right_width.c @@ -33,6 +33,21 @@ css_error css__initial_border_right_width(css_select_state *state) 0, CSS_UNIT_PX); } +css_error css__copy_border_right_width( + const css_computed_style *from, + css_computed_style *to) +{ + css_fixed length = 0; + css_unit unit = CSS_UNIT_PX; + uint8_t type = get_border_right_width(from, &length, &unit); + + if (from == to) { + return CSS_OK; + } + + return set_border_right_width(to, type, length, unit); +} + css_error css__compose_border_right_width(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) @@ -41,10 +56,8 @@ css_error css__compose_border_right_width(const css_computed_style *parent, css_unit unit = CSS_UNIT_PX; uint8_t type = get_border_right_width(child, &length, &unit); - if (type == CSS_BORDER_WIDTH_INHERIT) { - type = get_border_right_width(parent, &length, &unit); - } - - return set_border_right_width(result, type, length, unit); + return css__copy_border_right_width( + type == CSS_BORDER_WIDTH_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/border_spacing.c b/src/select/properties/border_spacing.c index 147f56f..1f70aff 100644 --- a/src/select/properties/border_spacing.c +++ b/src/select/properties/border_spacing.c @@ -23,7 +23,7 @@ css_error css__cascade_border_spacing(uint32_t opv, css_style *style, uint32_t hunit = UNIT_PX; uint32_t vunit = UNIT_PX; - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { value = CSS_BORDER_SPACING_SET; hlength = *((css_fixed *) style->bytecode); advance_bytecode(style, sizeof(hlength)); @@ -40,7 +40,7 @@ css_error css__cascade_border_spacing(uint32_t opv, css_style *style, vunit = css__to_css_unit(vunit); if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { return set_border_spacing(state->computed, value, hlength, hunit, vlength, vunit); } @@ -62,6 +62,22 @@ css_error css__initial_border_spacing(css_select_state *state) 0, CSS_UNIT_PX, 0, CSS_UNIT_PX); } +css_error css__copy_border_spacing( + const css_computed_style *from, + css_computed_style *to) +{ + css_fixed hlength = 0, vlength = 0; + css_unit hunit = CSS_UNIT_PX, vunit = CSS_UNIT_PX; + uint8_t type = get_border_spacing(from, &hlength, &hunit, + &vlength, &vunit); + + if (from == to) { + return CSS_OK; + } + + return set_border_spacing(to, type, hlength, hunit, vlength, vunit); +} + css_error css__compose_border_spacing(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) @@ -71,19 +87,7 @@ css_error css__compose_border_spacing(const css_computed_style *parent, uint8_t type = get_border_spacing(child, &hlength, &hunit, &vlength, &vunit); - if ((child->i.uncommon == NULL && parent->i.uncommon != NULL) || - type == CSS_BORDER_SPACING_INHERIT || - (child->i.uncommon != NULL && result != child)) { - if ((child->i.uncommon == NULL && parent->i.uncommon != NULL) || - type == CSS_BORDER_SPACING_INHERIT) { - type = get_border_spacing(parent, - &hlength, &hunit, &vlength, &vunit); - } - - return set_border_spacing(result, type, hlength, hunit, - vlength, vunit); - } - - return CSS_OK; + return css__copy_border_spacing( + type == CSS_BORDER_SPACING_INHERIT ? parent : child, + result); } - diff --git a/src/select/properties/border_top_color.c b/src/select/properties/border_top_color.c index fd2ced4..ee3feb1 100644 --- a/src/select/properties/border_top_color.c +++ b/src/select/properties/border_top_color.c @@ -31,6 +31,20 @@ css_error css__initial_border_top_color(css_select_state *state) return set_border_top_color(state->computed, CSS_BORDER_COLOR_CURRENT_COLOR, 0); } +css_error css__copy_border_top_color( + const css_computed_style *from, + css_computed_style *to) +{ + css_color color; + uint8_t type = get_border_top_color(from, &color); + + if (from == to) { + return CSS_OK; + } + + return set_border_top_color(to, type, color); +} + css_error css__compose_border_top_color(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) @@ -38,10 +52,8 @@ css_error css__compose_border_top_color(const css_computed_style *parent, css_color color; uint8_t type = get_border_top_color(child, &color); - if (type == CSS_BORDER_COLOR_INHERIT) { - type = get_border_top_color(parent, &color); - } - - return set_border_top_color(result, type, color); + return css__copy_border_top_color( + type == CSS_BORDER_COLOR_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/border_top_style.c b/src/select/properties/border_top_style.c index 48d6b6d..1d2dc91 100644 --- a/src/select/properties/border_top_style.c +++ b/src/select/properties/border_top_style.c @@ -31,16 +31,25 @@ css_error css__initial_border_top_style(css_select_state *state) return set_border_top_style(state->computed, CSS_BORDER_STYLE_NONE); } +css_error css__copy_border_top_style( + const css_computed_style *from, + css_computed_style *to) +{ + if (from == to) { + return CSS_OK; + } + + return set_border_top_style(to, get_border_top_style(from)); +} + css_error css__compose_border_top_style(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) { uint8_t type = get_border_top_style(child); - if (type == CSS_BORDER_STYLE_INHERIT) { - type = get_border_top_style(parent); - } - - return set_border_top_style(result, type); + return css__copy_border_top_style( + type == CSS_BORDER_STYLE_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/border_top_width.c b/src/select/properties/border_top_width.c index c0fb7da..18e60cb 100644 --- a/src/select/properties/border_top_width.c +++ b/src/select/properties/border_top_width.c @@ -33,6 +33,21 @@ css_error css__initial_border_top_width(css_select_state *state) 0, CSS_UNIT_PX); } +css_error css__copy_border_top_width( + const css_computed_style *from, + css_computed_style *to) +{ + css_fixed length = 0; + css_unit unit = CSS_UNIT_PX; + uint8_t type = get_border_top_width(from, &length, &unit); + + if (from == to) { + return CSS_OK; + } + + return set_border_top_width(to, type, length, unit); +} + css_error css__compose_border_top_width(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) @@ -41,10 +56,8 @@ css_error css__compose_border_top_width(const css_computed_style *parent, css_unit unit = CSS_UNIT_PX; uint8_t type = get_border_top_width(child, &length, &unit); - if (type == CSS_BORDER_WIDTH_INHERIT) { - type = get_border_top_width(parent, &length, &unit); - } - - return set_border_top_width(result, type, length, unit); + return css__copy_border_top_width( + type == CSS_BORDER_WIDTH_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/bottom.c b/src/select/properties/bottom.c index 82754f1..fd65ed3 100644 --- a/src/select/properties/bottom.c +++ b/src/select/properties/bottom.c @@ -32,6 +32,21 @@ css_error css__initial_bottom(css_select_state *state) return set_bottom(state->computed, CSS_BOTTOM_AUTO, 0, CSS_UNIT_PX); } +css_error css__copy_bottom( + const css_computed_style *from, + css_computed_style *to) +{ + css_fixed length = 0; + css_unit unit = CSS_UNIT_PX; + uint8_t type = get_bottom(from, &length, &unit); + + if (from == to) { + return CSS_OK; + } + + return set_bottom(to, type, length, unit); +} + css_error css__compose_bottom(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) @@ -40,10 +55,8 @@ css_error css__compose_bottom(const css_computed_style *parent, css_unit unit = CSS_UNIT_PX; uint8_t type = get_bottom(child, &length, &unit); - if (type == CSS_BOTTOM_INHERIT) { - type = get_bottom(parent, &length, &unit); - } - - return set_bottom(result, type, length, unit); + return css__copy_bottom( + type == CSS_BOTTOM_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/box_sizing.c b/src/select/properties/box_sizing.c index 2d19c95..471f8a7 100644 --- a/src/select/properties/box_sizing.c +++ b/src/select/properties/box_sizing.c @@ -21,7 +21,7 @@ css_error css__cascade_box_sizing(uint32_t opv, css_style *style, UNUSED(style); - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case BOX_SIZING_CONTENT_BOX: value = CSS_BOX_SIZING_CONTENT_BOX; @@ -33,7 +33,7 @@ css_error css__cascade_box_sizing(uint32_t opv, css_style *style, } if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { return set_box_sizing(state->computed, value); } @@ -51,17 +51,25 @@ css_error css__initial_box_sizing(css_select_state *state) return set_box_sizing(state->computed, CSS_BOX_SIZING_CONTENT_BOX); } -css_error css__compose_box_sizing( - const css_computed_style *parent, +css_error css__copy_box_sizing( + const css_computed_style *from, + css_computed_style *to) +{ + if (from == to) { + return CSS_OK; + } + + return set_box_sizing(to, get_box_sizing(from)); +} + +css_error css__compose_box_sizing(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) { uint8_t type = get_box_sizing(child); - if (type == CSS_BOX_SIZING_INHERIT) { - type = get_box_sizing(parent); - } - - return set_box_sizing(result, type); + return css__copy_box_sizing( + type == CSS_BOX_SIZING_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/break_after.c b/src/select/properties/break_after.c index 1f253aa..cb382e0 100644 --- a/src/select/properties/break_after.c +++ b/src/select/properties/break_after.c @@ -32,16 +32,25 @@ css_error css__initial_break_after(css_select_state *state) return set_break_after(state->computed, CSS_BREAK_AFTER_AUTO); } +css_error css__copy_break_after( + const css_computed_style *from, + css_computed_style *to) +{ + if (from == to) { + return CSS_OK; + } + + return set_break_after(to, get_break_after(from)); +} + css_error css__compose_break_after(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) { uint8_t type = get_break_after(child); - if (type == CSS_BREAK_AFTER_INHERIT) { - type = get_break_after(parent); - } - - return set_break_after(result, type); + return css__copy_break_after( + type == CSS_BREAK_AFTER_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/break_before.c b/src/select/properties/break_before.c index 3dcda76..91b0612 100644 --- a/src/select/properties/break_before.c +++ b/src/select/properties/break_before.c @@ -32,16 +32,25 @@ css_error css__initial_break_before(css_select_state *state) return set_break_before(state->computed, CSS_BREAK_BEFORE_AUTO); } +css_error css__copy_break_before( + const css_computed_style *from, + css_computed_style *to) +{ + if (from == to) { + return CSS_OK; + } + + return set_break_before(to, get_break_before(from)); +} + css_error css__compose_break_before(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) { uint8_t type = get_break_before(child); - if (type == CSS_BREAK_BEFORE_INHERIT) { - type = get_break_before(parent); - } - - return set_break_before(result, type); + return css__copy_break_before( + type == CSS_BREAK_BEFORE_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/break_inside.c b/src/select/properties/break_inside.c index fdc44c1..d5b8aef 100644 --- a/src/select/properties/break_inside.c +++ b/src/select/properties/break_inside.c @@ -21,7 +21,7 @@ css_error css__cascade_break_inside(uint32_t opv, css_style *style, UNUSED(style); - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case BREAK_INSIDE_AUTO: value = CSS_BREAK_INSIDE_AUTO; @@ -39,7 +39,7 @@ css_error css__cascade_break_inside(uint32_t opv, css_style *style, } if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { return set_break_inside(state->computed, value); } @@ -57,16 +57,25 @@ css_error css__initial_break_inside(css_select_state *state) return set_break_inside(state->computed, CSS_BREAK_INSIDE_AUTO); } +css_error css__copy_break_inside( + const css_computed_style *from, + css_computed_style *to) +{ + if (from == to) { + return CSS_OK; + } + + return set_break_inside(to, get_break_inside(from)); +} + css_error css__compose_break_inside(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) { uint8_t type = get_break_inside(child); - if (type == CSS_BREAK_INSIDE_INHERIT) { - type = get_break_inside(parent); - } - - return set_break_inside(result, type); + return css__copy_break_inside( + type == CSS_BREAK_INSIDE_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/caption_side.c b/src/select/properties/caption_side.c index ecccc1d..f0e7693 100644 --- a/src/select/properties/caption_side.c +++ b/src/select/properties/caption_side.c @@ -21,7 +21,7 @@ css_error css__cascade_caption_side(uint32_t opv, css_style *style, UNUSED(style); - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case CAPTION_SIDE_TOP: value = CSS_CAPTION_SIDE_TOP; @@ -33,7 +33,7 @@ css_error css__cascade_caption_side(uint32_t opv, css_style *style, } if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { return set_caption_side(state->computed, value); } @@ -51,16 +51,25 @@ css_error css__initial_caption_side(css_select_state *state) return set_caption_side(state->computed, CSS_CAPTION_SIDE_TOP); } +css_error css__copy_caption_side( + const css_computed_style *from, + css_computed_style *to) +{ + if (from == to) { + return CSS_OK; + } + + return set_caption_side(to, get_caption_side(from)); +} + css_error css__compose_caption_side(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) { uint8_t type = get_caption_side(child); - if (type == CSS_CAPTION_SIDE_INHERIT) { - type = get_caption_side(parent); - } - - return set_caption_side(result, type); + return css__copy_caption_side( + type == CSS_CAPTION_SIDE_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/clear.c b/src/select/properties/clear.c index bbb2673..1fbc48e 100644 --- a/src/select/properties/clear.c +++ b/src/select/properties/clear.c @@ -21,7 +21,7 @@ css_error css__cascade_clear(uint32_t opv, css_style *style, UNUSED(style); - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case CLEAR_NONE: value = CSS_CLEAR_NONE; @@ -39,7 +39,7 @@ css_error css__cascade_clear(uint32_t opv, css_style *style, } if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { return set_clear(state->computed, value); } @@ -57,16 +57,25 @@ css_error css__initial_clear(css_select_state *state) return set_clear(state->computed, CSS_CLEAR_NONE); } +css_error css__copy_clear( + const css_computed_style *from, + css_computed_style *to) +{ + if (from == to) { + return CSS_OK; + } + + return set_clear(to, get_clear(from)); +} + css_error css__compose_clear(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) { uint8_t type = get_clear(child); - if (type == CSS_CLEAR_INHERIT) { - type = get_clear(parent); - } - - return set_clear(result, type); + return css__copy_clear( + type == CSS_CLEAR_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/clip.c b/src/select/properties/clip.c index fe1dd87..c0b9c2b 100644 --- a/src/select/properties/clip.c +++ b/src/select/properties/clip.c @@ -22,7 +22,7 @@ css_error css__cascade_clip(uint32_t opv, css_style *style, CSS_UNIT_PX, CSS_UNIT_PX, CSS_UNIT_PX, CSS_UNIT_PX, false, false, false, false }; - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv) & CLIP_SHAPE_MASK) { case CLIP_SHAPE_RECT: if (getValue(opv) & CLIP_RECT_TOP_AUTO) { @@ -71,7 +71,7 @@ css_error css__cascade_clip(uint32_t opv, css_style *style, rect.lunit = css__to_css_unit(rect.lunit); if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { return set_clip(state->computed, value, &rect); } @@ -93,6 +93,22 @@ css_error css__initial_clip(css_select_state *state) return set_clip(state->computed, CSS_CLIP_AUTO, &rect); } +css_error css__copy_clip( + const css_computed_style *from, + css_computed_style *to) +{ + css_computed_clip_rect rect = { 0, 0, 0, 0, + CSS_UNIT_PX, CSS_UNIT_PX, CSS_UNIT_PX, CSS_UNIT_PX, + false, false, false, false }; + uint8_t type = get_clip(from, &rect); + + if (from == to) { + return CSS_OK; + } + + return set_clip(to, type, &rect); +} + css_error css__compose_clip(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) @@ -102,17 +118,7 @@ css_error css__compose_clip(const css_computed_style *parent, false, false, false, false }; uint8_t type = get_clip(child, &rect); - if ((child->i.uncommon == NULL && parent->i.uncommon != NULL) || - type == CSS_CLIP_INHERIT || - (child->i.uncommon != NULL && result != child)) { - if ((child->i.uncommon == NULL && parent->i.uncommon != NULL) || - type == CSS_CLIP_INHERIT) { - type = get_clip(parent, &rect); - } - - return set_clip(result, type, &rect); - } - - return CSS_OK; + return css__copy_clip( + type == CSS_CLIP_INHERIT ? parent : child, + result); } - diff --git a/src/select/properties/color.c b/src/select/properties/color.c index 806f2cc..6424436 100644 --- a/src/select/properties/color.c +++ b/src/select/properties/color.c @@ -17,11 +17,11 @@ css_error css__cascade_color(uint32_t opv, css_style *style, css_select_state *state) { - bool inherit = isInherit(opv); + enum flag_value flag_value = getFlagValue(opv); uint16_t value = CSS_COLOR_INHERIT; css_color color = 0; - if (inherit == false) { + if (flag_value == FLAG_VALUE__NONE) { switch (getValue(opv)) { case COLOR_TRANSPARENT: value = CSS_COLOR_COLOR; @@ -29,7 +29,7 @@ css_error css__cascade_color(uint32_t opv, css_style *style, case COLOR_CURRENT_COLOR: /* color: currentColor always computes to inherit */ value = CSS_COLOR_INHERIT; - inherit = true; + flag_value = FLAG_VALUE_INHERIT; break; case COLOR_SET: value = CSS_COLOR_COLOR; @@ -40,7 +40,7 @@ css_error css__cascade_color(uint32_t opv, css_style *style, } if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - inherit)) { + flag_value)) { return set_color(state->computed, value, color); } @@ -66,6 +66,20 @@ css_error css__initial_color(css_select_state *state) return css__set_color_from_hint(&hint, state->computed); } +css_error css__copy_color( + const css_computed_style *from, + css_computed_style *to) +{ + css_color color; + uint8_t type = get_color(from, &color); + + if (from == to) { + return CSS_OK; + } + + return set_color(to, type, color); +} + css_error css__compose_color(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) @@ -73,10 +87,8 @@ css_error css__compose_color(const css_computed_style *parent, css_color color; uint8_t type = get_color(child, &color); - if (type == CSS_COLOR_INHERIT) { - type = get_color(parent, &color); - } - - return set_color(result, type, color); + return css__copy_color( + type == CSS_COLOR_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/column_count.c b/src/select/properties/column_count.c index 7e929b0..4adadd6 100644 --- a/src/select/properties/column_count.c +++ b/src/select/properties/column_count.c @@ -20,7 +20,7 @@ css_error css__cascade_column_count(uint32_t opv, css_style *style, uint16_t value = CSS_COLUMN_COUNT_INHERIT; css_fixed count = 0; - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case COLUMN_COUNT_SET: value = CSS_COLUMN_COUNT_SET; @@ -34,7 +34,7 @@ css_error css__cascade_column_count(uint32_t opv, css_style *style, } if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { return set_column_count(state->computed, value, count); } @@ -52,6 +52,20 @@ css_error css__initial_column_count(css_select_state *state) return set_column_count(state->computed, CSS_COLUMN_COUNT_AUTO, 0); } +css_error css__copy_column_count( + const css_computed_style *from, + css_computed_style *to) +{ + int32_t count = 0; + uint8_t type = get_column_count(from, &count); + + if (from == to) { + return CSS_OK; + } + + return set_column_count(to, type, count); +} + css_error css__compose_column_count(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) @@ -59,17 +73,7 @@ css_error css__compose_column_count(const css_computed_style *parent, int32_t count = 0; uint8_t type = get_column_count(child, &count); - if ((child->i.uncommon == NULL && parent->i.uncommon != NULL) || - type == CSS_COLUMN_COUNT_INHERIT || - (child->i.uncommon != NULL && result != child)) { - if ((child->i.uncommon == NULL && parent->i.uncommon != NULL) || - type == CSS_COLUMN_COUNT_INHERIT) { - type = get_column_count(parent, &count); - } - - return set_column_count(result, type, count); - } - - return CSS_OK; + return css__copy_column_count( + type == CSS_COLUMN_COUNT_INHERIT ? parent : child, + result); } - diff --git a/src/select/properties/column_fill.c b/src/select/properties/column_fill.c index 31f19f0..f49946c 100644 --- a/src/select/properties/column_fill.c +++ b/src/select/properties/column_fill.c @@ -21,7 +21,7 @@ css_error css__cascade_column_fill(uint32_t opv, css_style *style, UNUSED(style); - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case COLUMN_FILL_BALANCE: value = CSS_COLUMN_FILL_BALANCE; @@ -33,7 +33,7 @@ css_error css__cascade_column_fill(uint32_t opv, css_style *style, } if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { return set_column_fill(state->computed, value); } @@ -51,16 +51,25 @@ css_error css__initial_column_fill(css_select_state *state) return set_column_fill(state->computed, CSS_COLUMN_FILL_BALANCE); } +css_error css__copy_column_fill( + const css_computed_style *from, + css_computed_style *to) +{ + if (from == to) { + return CSS_OK; + } + + return set_column_fill(to, get_column_fill(from)); +} + css_error css__compose_column_fill(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) { uint8_t type = get_column_fill(child); - if (type == CSS_COLUMN_FILL_INHERIT) { - type = get_column_fill(parent); - } - - return set_column_fill(result, type); + return css__copy_column_fill( + type == CSS_COLUMN_FILL_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/column_gap.c b/src/select/properties/column_gap.c index 824b3a4..5776dc9 100644 --- a/src/select/properties/column_gap.c +++ b/src/select/properties/column_gap.c @@ -33,6 +33,21 @@ css_error css__initial_column_gap(css_select_state *state) INTTOFIX(1), CSS_UNIT_EM); } +css_error css__copy_column_gap( + const css_computed_style *from, + css_computed_style *to) +{ + css_fixed length = INTTOFIX(1); + css_unit unit = CSS_UNIT_EM; + uint8_t type = get_column_gap(from, &length, &unit); + + if (from == to) { + return CSS_OK; + } + + return set_column_gap(to, type, length, unit); +} + css_error css__compose_column_gap(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) @@ -41,17 +56,7 @@ css_error css__compose_column_gap(const css_computed_style *parent, css_unit unit = CSS_UNIT_EM; uint8_t type = get_column_gap(child, &length, &unit); - if ((child->i.uncommon == NULL && parent->i.uncommon != NULL) || - type == CSS_COLUMN_GAP_INHERIT || - (child->i.uncommon != NULL && result != child)) { - if ((child->i.uncommon == NULL && parent->i.uncommon != NULL) || - type == CSS_COLUMN_GAP_INHERIT) { - type = get_column_gap(parent, &length, &unit); - } - - return set_column_gap(result, type, length, unit); - } - - return CSS_OK; + return css__copy_column_gap( + type == CSS_COLUMN_GAP_INHERIT ? parent : child, + result); } - diff --git a/src/select/properties/column_rule_color.c b/src/select/properties/column_rule_color.c index f54c2ab..0b7ec9d 100644 --- a/src/select/properties/column_rule_color.c +++ b/src/select/properties/column_rule_color.c @@ -17,17 +17,18 @@ css_error css__cascade_column_rule_color(uint32_t opv, css_style *style, css_select_state *state) { - bool inherit = isInherit(opv); + enum flag_value flag_value = getFlagValue(opv); uint16_t value = CSS_COLUMN_RULE_COLOR_INHERIT; css_color color = 0; - if (isInherit(opv) == false) { + if (flag_value == FLAG_VALUE__NONE) { switch (getValue(opv)) { case COLUMN_RULE_COLOR_TRANSPARENT: value = CSS_COLUMN_RULE_COLOR_COLOR; break; case COLUMN_RULE_COLOR_CURRENT_COLOR: value = CSS_COLUMN_RULE_COLOR_CURRENT_COLOR; + flag_value = FLAG_VALUE_INHERIT; break; case COLUMN_RULE_COLOR_SET: value = CSS_COLUMN_RULE_COLOR_COLOR; @@ -38,7 +39,7 @@ css_error css__cascade_column_rule_color(uint32_t opv, css_style *style, } if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - inherit)) { + flag_value)) { return set_column_rule_color(state->computed, value, color); } @@ -57,6 +58,20 @@ css_error css__initial_column_rule_color(css_select_state *state) CSS_COLUMN_RULE_COLOR_CURRENT_COLOR, 0); } +css_error css__copy_column_rule_color( + const css_computed_style *from, + css_computed_style *to) +{ + css_color color; + uint8_t type = get_column_rule_color(from, &color); + + if (from == to) { + return CSS_OK; + } + + return set_column_rule_color(to, type, color); +} + css_error css__compose_column_rule_color(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) @@ -64,10 +79,8 @@ css_error css__compose_column_rule_color(const css_computed_style *parent, css_color color; uint8_t type = get_column_rule_color(child, &color); - if (type == CSS_COLUMN_RULE_COLOR_INHERIT) { - type = get_column_rule_color(parent, &color); - } - - return set_column_rule_color(result, type, color); + return css__copy_column_rule_color( + type == CSS_COLUMN_RULE_COLOR_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/column_rule_style.c b/src/select/properties/column_rule_style.c index 1d9a41e..be9579c 100644 --- a/src/select/properties/column_rule_style.c +++ b/src/select/properties/column_rule_style.c @@ -33,16 +33,25 @@ css_error css__initial_column_rule_style(css_select_state *state) CSS_COLUMN_RULE_STYLE_NONE); } +css_error css__copy_column_rule_style( + const css_computed_style *from, + css_computed_style *to) +{ + if (from == to) { + return CSS_OK; + } + + return set_column_rule_style(to, get_column_rule_style(from)); +} + css_error css__compose_column_rule_style(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) { uint8_t type = get_column_rule_style(child); - if (type == CSS_COLUMN_RULE_STYLE_INHERIT) { - type = get_column_rule_style(parent); - } - - return set_column_rule_style(result, type); + return css__copy_column_rule_style( + type == CSS_COLUMN_RULE_STYLE_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/column_rule_width.c b/src/select/properties/column_rule_width.c index 3ca9367..c18f26c 100644 --- a/src/select/properties/column_rule_width.c +++ b/src/select/properties/column_rule_width.c @@ -34,6 +34,21 @@ css_error css__initial_column_rule_width(css_select_state *state) CSS_COLUMN_RULE_WIDTH_MEDIUM, 0, CSS_UNIT_PX); } +css_error css__copy_column_rule_width( + const css_computed_style *from, + css_computed_style *to) +{ + css_fixed length = 0; + css_unit unit = CSS_UNIT_PX; + uint8_t type = get_column_rule_width(from, &length, &unit); + + if (from == to) { + return CSS_OK; + } + + return set_column_rule_width(to, type, length, unit); +} + css_error css__compose_column_rule_width(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) @@ -42,10 +57,8 @@ css_error css__compose_column_rule_width(const css_computed_style *parent, css_unit unit = CSS_UNIT_PX; uint8_t type = get_column_rule_width(child, &length, &unit); - if (type == CSS_COLUMN_RULE_WIDTH_INHERIT) { - type = get_column_rule_width(parent, &length, &unit); - } - - return set_column_rule_width(result, type, length, unit); + return css__copy_column_rule_width( + type == CSS_COLUMN_RULE_WIDTH_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/column_span.c b/src/select/properties/column_span.c index 2c870d3..340150f 100644 --- a/src/select/properties/column_span.c +++ b/src/select/properties/column_span.c @@ -21,7 +21,7 @@ css_error css__cascade_column_span(uint32_t opv, css_style *style, UNUSED(style); - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case COLUMN_SPAN_NONE: value = CSS_COLUMN_SPAN_NONE; @@ -33,7 +33,7 @@ css_error css__cascade_column_span(uint32_t opv, css_style *style, } if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { return set_column_span(state->computed, value); } @@ -51,16 +51,25 @@ css_error css__initial_column_span(css_select_state *state) return set_column_span(state->computed, CSS_COLUMN_SPAN_NONE); } +css_error css__copy_column_span( + const css_computed_style *from, + css_computed_style *to) +{ + if (from == to) { + return CSS_OK; + } + + return set_column_span(to, get_column_span(from)); +} + css_error css__compose_column_span(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) { uint8_t type = get_column_span(child); - if (type == CSS_COLUMN_SPAN_INHERIT) { - type = get_column_span(parent); - } - - return set_column_span(result, type); + return css__copy_column_span( + type == CSS_COLUMN_SPAN_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/column_width.c b/src/select/properties/column_width.c index b6550ab..d88d022 100644 --- a/src/select/properties/column_width.c +++ b/src/select/properties/column_width.c @@ -33,25 +33,30 @@ css_error css__initial_column_width(css_select_state *state) INTTOFIX(1), CSS_UNIT_EM); } +css_error css__copy_column_width( + const css_computed_style *from, + css_computed_style *to) +{ + css_fixed length = 0; + css_unit unit = CSS_UNIT_PX; + uint8_t type = get_column_width(from, &length, &unit); + + if (from == to) { + return CSS_OK; + } + + return set_column_width(to, type, length, unit); +} + css_error css__compose_column_width(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) { - css_fixed length = INTTOFIX(1); - css_unit unit = CSS_UNIT_EM; + css_fixed length = 0; + css_unit unit = CSS_UNIT_PX; uint8_t type = get_column_width(child, &length, &unit); - if ((child->i.uncommon == NULL && parent->i.uncommon != NULL) || - type == CSS_COLUMN_WIDTH_INHERIT || - (child->i.uncommon != NULL && result != child)) { - if ((child->i.uncommon == NULL && parent->i.uncommon != NULL) || - type == CSS_COLUMN_WIDTH_INHERIT) { - type = get_column_width(parent, &length, &unit); - } - - return set_column_width(result, type, length, unit); - } - - return CSS_OK; + return css__copy_column_width( + type == CSS_COLUMN_WIDTH_INHERIT ? parent : child, + result); } - diff --git a/src/select/properties/content.c b/src/select/properties/content.c index 0506ef3..32af49f 100644 --- a/src/select/properties/content.c +++ b/src/select/properties/content.c @@ -21,7 +21,7 @@ css_error css__cascade_content(uint32_t opv, css_style *style, css_computed_content_item *content = NULL; uint32_t n_contents = 0; - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { uint32_t v = getValue(opv); if (v == CONTENT_NORMAL) { @@ -140,7 +140,7 @@ css_error css__cascade_content(uint32_t opv, css_style *style, } if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { css_error error; error = set_content(state->computed, value, content); @@ -199,48 +199,40 @@ css_error css__initial_content(css_select_state *state) return set_content(state->computed, CSS_CONTENT_NORMAL, NULL); } -css_error css__compose_content(const css_computed_style *parent, - const css_computed_style *child, - css_computed_style *result) +css_error css__copy_content( + const css_computed_style *from, + css_computed_style *to) { css_error error; + css_computed_content_item *copy = NULL; const css_computed_content_item *items = NULL; - uint8_t type = get_content(child, &items); - - if ((child->i.uncommon == NULL && parent->i.uncommon != NULL) || - type == CSS_CONTENT_INHERIT || - (child->i.uncommon != NULL && result != child)) { - size_t n_items = 0; - css_computed_content_item *copy = NULL; - - if ((child->i.uncommon == NULL && parent->i.uncommon != NULL) || - type == CSS_CONTENT_INHERIT) { - type = get_content(parent, &items); - } - - if (type == CSS_CONTENT_SET) { - const css_computed_content_item *i; - - for (i = items; i->type != CSS_COMPUTED_CONTENT_NONE; - i++) - n_items++; + uint8_t type = get_content(from, &items); - copy = malloc((n_items + 1) * - sizeof(css_computed_content_item)); - if (copy == NULL) - return CSS_NOMEM; - - memcpy(copy, items, (n_items + 1) * - sizeof(css_computed_content_item)); - } + if (from == to) { + return CSS_OK; + } - error = set_content(result, type, copy); - if (error != CSS_OK && copy != NULL) - free(copy); + error = css__copy_computed_content_item_array(false, items, ©); + if (error != CSS_OK) { + return CSS_NOMEM; + } - return error; + error = set_content(to, type, copy); + if (error != CSS_OK) { + free(copy); } - return CSS_OK; + return error; } +css_error css__compose_content(const css_computed_style *parent, + const css_computed_style *child, + css_computed_style *result) +{ + const css_computed_content_item *items = NULL; + uint8_t type = get_content(child, &items); + + return css__copy_content( + type == CSS_CONTENT_INHERIT ? parent : child, + result); +} diff --git a/src/select/properties/counter_increment.c b/src/select/properties/counter_increment.c index 9888e0a..2638838 100644 --- a/src/select/properties/counter_increment.c +++ b/src/select/properties/counter_increment.c @@ -48,47 +48,40 @@ css_error css__initial_counter_increment(css_select_state *state) CSS_COUNTER_INCREMENT_NONE, NULL); } -css_error css__compose_counter_increment(const css_computed_style *parent, - const css_computed_style *child, - css_computed_style *result) +css_error css__copy_counter_increment( + const css_computed_style *from, + css_computed_style *to) { css_error error; - const css_computed_counter *items = NULL; - uint8_t type = get_counter_increment(child, &items); - - if ((child->i.uncommon == NULL && parent->i.uncommon != NULL) || - type == CSS_COUNTER_INCREMENT_INHERIT || - (child->i.uncommon != NULL && result != child)) { - size_t n_items = 0; - css_computed_counter *copy = NULL; - - if ((child->i.uncommon == NULL && parent->i.uncommon != NULL) || - type == CSS_COUNTER_INCREMENT_INHERIT) { - type = get_counter_increment(parent, &items); - } - - if (type == CSS_COUNTER_INCREMENT_NAMED && items != NULL) { - const css_computed_counter *i; + css_computed_counter *copy = NULL; + const css_computed_counter *counter_increment = NULL; + uint8_t type = get_counter_increment(from, &counter_increment); - for (i = items; i->name != NULL; i++) - n_items++; - - copy = malloc((n_items + 1) * - sizeof(css_computed_counter)); - if (copy == NULL) - return CSS_NOMEM; - - memcpy(copy, items, (n_items + 1) * - sizeof(css_computed_counter)); - } + if (from == to) { + return CSS_OK; + } - error = set_counter_increment(result, type, copy); - if (error != CSS_OK && copy != NULL) - free(copy); + error = css__copy_computed_counter_array(false, counter_increment, ©); + if (error != CSS_OK) { + return CSS_NOMEM; + } - return error; + error = set_counter_increment(to, type, copy); + if (error != CSS_OK) { + free(copy); } - return CSS_OK; + return error; } +css_error css__compose_counter_increment(const css_computed_style *parent, + const css_computed_style *child, + css_computed_style *result) +{ + const css_computed_counter *counter_increment = NULL; + uint8_t type = get_counter_increment(child, &counter_increment); + + return css__copy_counter_increment( + type == CSS_COUNTER_INCREMENT_INHERIT ? parent : child, + result); +} diff --git a/src/select/properties/counter_reset.c b/src/select/properties/counter_reset.c index 9d20609..fcb39a3 100644 --- a/src/select/properties/counter_reset.c +++ b/src/select/properties/counter_reset.c @@ -47,46 +47,40 @@ css_error css__initial_counter_reset(css_select_state *state) return set_counter_reset(state->computed, CSS_COUNTER_RESET_NONE, NULL); } -css_error css__compose_counter_reset(const css_computed_style *parent, - const css_computed_style *child, - css_computed_style *result) +css_error css__copy_counter_reset( + const css_computed_style *from, + css_computed_style *to) { css_error error; - const css_computed_counter *items = NULL; - uint8_t type = get_counter_reset(child, &items); - - if ((child->i.uncommon == NULL && parent->i.uncommon != NULL) || - type == CSS_COUNTER_RESET_INHERIT || - (child->i.uncommon != NULL && result != child)) { - size_t n_items = 0; - css_computed_counter *copy = NULL; - - if ((child->i.uncommon == NULL && parent->i.uncommon != NULL) || - type == CSS_COUNTER_RESET_INHERIT) { - type = get_counter_reset(parent, &items); - } + css_computed_counter *copy = NULL; + const css_computed_counter *counter_reset = NULL; + uint8_t type = get_counter_reset(from, &counter_reset); - if (type == CSS_COUNTER_RESET_NAMED && items != NULL) { - const css_computed_counter *i; - - for (i = items; i->name != NULL; i++) - n_items++; + if (from == to) { + return CSS_OK; + } - copy = malloc((n_items + 1) * - sizeof(css_computed_counter)); - if (copy == NULL) - return CSS_NOMEM; + error = css__copy_computed_counter_array(false, counter_reset, ©); + if (error != CSS_OK) { + return CSS_NOMEM; + } - memcpy(copy, items, (n_items + 1) * - sizeof(css_computed_counter)); - } + error = set_counter_reset(to, type, copy); + if (error != CSS_OK) { + free(copy); + } - error = set_counter_reset(result, type, copy); - if (error != CSS_OK && copy != NULL) - free(copy); + return error; +} - return error; - } +css_error css__compose_counter_reset(const css_computed_style *parent, + const css_computed_style *child, + css_computed_style *result) +{ + const css_computed_counter *counter_reset = NULL; + uint8_t type = get_counter_reset(child, &counter_reset); - return CSS_OK; + return css__copy_counter_reset( + type == CSS_COUNTER_RESET_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/cue_after.c b/src/select/properties/cue_after.c index e1c09e8..67a2c73 100644 --- a/src/select/properties/cue_after.c +++ b/src/select/properties/cue_after.c @@ -37,6 +37,16 @@ css_error css__initial_cue_after(css_select_state *state) return CSS_OK; } +css_error css__copy_cue_after( + const css_computed_style *from, + css_computed_style *to) +{ + UNUSED(from); + UNUSED(to); + + return CSS_OK; +} + css_error css__compose_cue_after(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) diff --git a/src/select/properties/cue_before.c b/src/select/properties/cue_before.c index d562b3b..7c24822 100644 --- a/src/select/properties/cue_before.c +++ b/src/select/properties/cue_before.c @@ -37,6 +37,16 @@ css_error css__initial_cue_before(css_select_state *state) return CSS_OK; } +css_error css__copy_cue_before( + const css_computed_style *from, + css_computed_style *to) +{ + UNUSED(from); + UNUSED(to); + + return CSS_OK; +} + css_error css__compose_cue_before(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) diff --git a/src/select/properties/cursor.c b/src/select/properties/cursor.c index 6effdb5..09955c6 100644 --- a/src/select/properties/cursor.c +++ b/src/select/properties/cursor.c @@ -21,7 +21,7 @@ css_error css__cascade_cursor(uint32_t opv, css_style *style, lwc_string **uris = NULL; uint32_t n_uris = 0; - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { uint32_t v = getValue(opv); while (v == CURSOR_URI) { @@ -124,7 +124,7 @@ css_error css__cascade_cursor(uint32_t opv, css_style *style, } if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { css_error error; error = set_cursor(state->computed, value, uris); @@ -164,47 +164,40 @@ css_error css__initial_cursor(css_select_state *state) return set_cursor(state->computed, CSS_CURSOR_AUTO, NULL); } -css_error css__compose_cursor(const css_computed_style *parent, - const css_computed_style *child, - css_computed_style *result) +css_error css__copy_cursor( + const css_computed_style *from, + css_computed_style *to) { css_error error; - lwc_string **urls = NULL; - uint8_t type = get_cursor(child, &urls); - - if ((child->i.uncommon == NULL && parent->i.uncommon != NULL) || - type == CSS_CURSOR_INHERIT || - (child->i.uncommon != NULL && result != child)) { - size_t n_urls = 0; - lwc_string **copy = NULL; - - if ((child->i.uncommon == NULL && parent->i.uncommon != NULL) || - type == CSS_CURSOR_INHERIT) { - type = get_cursor(parent, &urls); - } - - if (urls != NULL) { - lwc_string **i; + lwc_string **copy = NULL; + lwc_string **cursor = NULL; + uint8_t type = get_cursor(from, &cursor); - for (i = urls; (*i) != NULL; i++) - n_urls++; - - copy = malloc((n_urls + 1) * - sizeof(lwc_string *)); - if (copy == NULL) - return CSS_NOMEM; - - memcpy(copy, urls, (n_urls + 1) * - sizeof(lwc_string *)); - } + if (from == to) { + return CSS_OK; + } - error = set_cursor(result, type, copy); - if (error != CSS_OK && copy != NULL) - free(copy); + error = css__copy_lwc_string_array(false, cursor, ©); + if (error != CSS_OK) { + return CSS_NOMEM; + } - return error; + error = set_cursor(to, type, copy); + if (error != CSS_OK) { + free(copy); } - return CSS_OK; + return error; } +css_error css__compose_cursor(const css_computed_style *parent, + const css_computed_style *child, + css_computed_style *result) +{ + lwc_string **cursor = NULL; + uint8_t type = get_cursor(child, &cursor); + + return css__copy_cursor( + type == CSS_CURSOR_INHERIT ? parent : child, + result); +} diff --git a/src/select/properties/direction.c b/src/select/properties/direction.c index f4a5c46..32bd31e 100644 --- a/src/select/properties/direction.c +++ b/src/select/properties/direction.c @@ -21,7 +21,7 @@ css_error css__cascade_direction(uint32_t opv, css_style *style, UNUSED(style); - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case DIRECTION_LTR: value = CSS_DIRECTION_LTR; @@ -33,7 +33,7 @@ css_error css__cascade_direction(uint32_t opv, css_style *style, } if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { return set_direction(state->computed, value); } @@ -51,16 +51,25 @@ css_error css__initial_direction(css_select_state *state) return set_direction(state->computed, CSS_DIRECTION_LTR); } +css_error css__copy_direction( + const css_computed_style *from, + css_computed_style *to) +{ + if (from == to) { + return CSS_OK; + } + + return set_direction(to, get_direction(from)); +} + css_error css__compose_direction(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) { uint8_t type = get_direction(child); - if (type == CSS_DIRECTION_INHERIT) { - type = get_direction(parent); - } - - return set_direction(result, type); + return css__copy_direction( + type == CSS_DIRECTION_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/display.c b/src/select/properties/display.c index 40c2e3e..5455d20 100644 --- a/src/select/properties/display.c +++ b/src/select/properties/display.c @@ -21,7 +21,7 @@ css_error css__cascade_display(uint32_t opv, css_style *style, UNUSED(style); - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case DISPLAY_INLINE: value = CSS_DISPLAY_INLINE; @@ -71,11 +71,23 @@ css_error css__cascade_display(uint32_t opv, css_style *style, case DISPLAY_NONE: value = CSS_DISPLAY_NONE; break; + case DISPLAY_FLEX: + value = CSS_DISPLAY_FLEX; + break; + case DISPLAY_INLINE_FLEX: + value = CSS_DISPLAY_INLINE_FLEX; + break; + case DISPLAY_GRID: + value = CSS_DISPLAY_GRID; + break; + case DISPLAY_INLINE_GRID: + value = CSS_DISPLAY_INLINE_GRID; + break; } } if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { return set_display(state->computed, value); } @@ -93,16 +105,25 @@ css_error css__initial_display(css_select_state *state) return set_display(state->computed, CSS_DISPLAY_INLINE); } +css_error css__copy_display( + const css_computed_style *from, + css_computed_style *to) +{ + if (from == to) { + return CSS_OK; + } + + return set_display(to, get_display(from)); +} + css_error css__compose_display(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) { uint8_t type = get_display(child); - if (type == CSS_DISPLAY_INHERIT) { - type = get_display(parent); - } - - return set_display(result, type); + return css__copy_display( + type == CSS_DISPLAY_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/elevation.c b/src/select/properties/elevation.c index ee7d036..1368ef8 100644 --- a/src/select/properties/elevation.c +++ b/src/select/properties/elevation.c @@ -20,7 +20,7 @@ css_error css__cascade_elevation(uint32_t opv, css_style *style, css_fixed val = 0; uint32_t unit = UNIT_DEG; - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case ELEVATION_ANGLE: val = *((css_fixed *) style->bytecode); @@ -42,7 +42,7 @@ css_error css__cascade_elevation(uint32_t opv, css_style *style, unit = css__to_css_unit(unit); if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { /** \todo set computed elevation */ } @@ -65,6 +65,16 @@ css_error css__initial_elevation(css_select_state *state) return CSS_OK; } +css_error css__copy_elevation( + const css_computed_style *from, + css_computed_style *to) +{ + UNUSED(from); + UNUSED(to); + + return CSS_OK; +} + css_error css__compose_elevation(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) diff --git a/src/select/properties/empty_cells.c b/src/select/properties/empty_cells.c index fecdbdc..559fbde 100644 --- a/src/select/properties/empty_cells.c +++ b/src/select/properties/empty_cells.c @@ -21,7 +21,7 @@ css_error css__cascade_empty_cells(uint32_t opv, css_style *style, UNUSED(style); - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case EMPTY_CELLS_SHOW: value = CSS_EMPTY_CELLS_SHOW; @@ -33,7 +33,7 @@ css_error css__cascade_empty_cells(uint32_t opv, css_style *style, } if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { return set_empty_cells(state->computed, value); } @@ -51,16 +51,25 @@ css_error css__initial_empty_cells(css_select_state *state) return set_empty_cells(state->computed, CSS_EMPTY_CELLS_SHOW); } +css_error css__copy_empty_cells( + const css_computed_style *from, + css_computed_style *to) +{ + if (from == to) { + return CSS_OK; + } + + return set_empty_cells(to, get_empty_cells(from)); +} + css_error css__compose_empty_cells(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) { uint8_t type = get_empty_cells(child); - if (type == CSS_EMPTY_CELLS_INHERIT) { - type = get_empty_cells(parent); - } - - return set_empty_cells(result, type); + return css__copy_empty_cells( + type == CSS_EMPTY_CELLS_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/fill_opacity.c b/src/select/properties/fill_opacity.c new file mode 100644 index 0000000..af0b52b --- /dev/null +++ b/src/select/properties/fill_opacity.c @@ -0,0 +1,73 @@ +/* + * This file is part of LibCSS + * Licensed under the MIT License, + * http://www.opensource.org/licenses/mit-license.php + */ + +#include "bytecode/bytecode.h" +#include "bytecode/opcodes.h" +#include "select/propset.h" +#include "select/propget.h" +#include "utils/utils.h" + +#include "select/properties/properties.h" +#include "select/properties/helpers.h" + +css_error css__cascade_fill_opacity(uint32_t opv, css_style *style, + css_select_state *state) +{ + uint16_t value = CSS_FILL_OPACITY_INHERIT; + css_fixed fill_opacity = 0; + + if (hasFlagValue(opv) == false) { + value = CSS_FILL_OPACITY_SET; + + fill_opacity = *((css_fixed *) style->bytecode); + advance_bytecode(style, sizeof(fill_opacity)); + } + + if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, + getFlagValue(opv))) { + return set_fill_opacity(state->computed, value, fill_opacity); + } + + return CSS_OK; +} + +css_error css__set_fill_opacity_from_hint(const css_hint *hint, + css_computed_style *style) +{ + return set_fill_opacity(style, hint->status, hint->data.fixed); +} + +css_error css__initial_fill_opacity(css_select_state *state) +{ + return set_fill_opacity(state->computed, CSS_FILL_OPACITY_SET, INTTOFIX(1)); +} + +css_error css__copy_fill_opacity( + const css_computed_style *from, + css_computed_style *to) +{ + css_fixed fill_opacity = 0; + uint8_t type = get_fill_opacity(from, &fill_opacity); + + if (from == to) { + return CSS_OK; + } + + return set_fill_opacity(to, type, fill_opacity); +} + +css_error css__compose_fill_opacity(const css_computed_style *parent, + const css_computed_style *child, + css_computed_style *result) +{ + css_fixed fill_opacity = 0; + uint8_t type = get_fill_opacity(child, &fill_opacity); + + return css__copy_fill_opacity( + type == CSS_FILL_OPACITY_INHERIT ? parent : child, + result); +} + diff --git a/src/select/properties/flex_basis.c b/src/select/properties/flex_basis.c new file mode 100644 index 0000000..a3141bc --- /dev/null +++ b/src/select/properties/flex_basis.c @@ -0,0 +1,92 @@ +/* + * This file is part of LibCSS + * Licensed under the MIT License, + * http://www.opensource.org/licenses/mit-license.php + * Copyright 2017 Lucas Neves <lcneves@gmail.com> + */ + +#include "bytecode/bytecode.h" +#include "bytecode/opcodes.h" +#include "select/propset.h" +#include "select/propget.h" +#include "utils/utils.h" + +#include "select/properties/properties.h" +#include "select/properties/helpers.h" + +css_error css__cascade_flex_basis(uint32_t opv, css_style *style, + css_select_state *state) +{ + uint16_t value = CSS_FLEX_BASIS_INHERIT; + css_fixed length = 0; + uint32_t unit = UNIT_PX; + + if (hasFlagValue(opv) == false) { + switch (getValue(opv)) { + case FLEX_BASIS_AUTO: + value = CSS_FLEX_BASIS_AUTO; + break; + case FLEX_BASIS_CONTENT: + value = CSS_FLEX_BASIS_CONTENT; + break; + case FLEX_BASIS_SET: + value = CSS_FLEX_BASIS_SET; + length = *((css_fixed *) style->bytecode); + advance_bytecode(style, sizeof(length)); + unit = *((uint32_t *) style->bytecode); + advance_bytecode(style, sizeof(unit)); + break; + } + } + + unit = css__to_css_unit(unit); + + if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, + getFlagValue(opv))) { + return set_flex_basis(state->computed, value, length, unit); + } + + return CSS_OK; +} + +css_error css__set_flex_basis_from_hint(const css_hint *hint, + css_computed_style *style) +{ + return set_flex_basis(style, hint->status, + hint->data.length.value, hint->data.length.unit); +} + +css_error css__initial_flex_basis(css_select_state *state) +{ + return set_flex_basis(state->computed, CSS_FLEX_BASIS_AUTO, 0, + CSS_UNIT_PX); +} + +css_error css__copy_flex_basis( + const css_computed_style *from, + css_computed_style *to) +{ + css_fixed length = 0; + css_unit unit = CSS_UNIT_PX; + uint8_t type = get_flex_basis(from, &length, &unit); + + if (from == to) { + return CSS_OK; + } + + return set_flex_basis(to, type, length, unit); +} + +css_error css__compose_flex_basis(const css_computed_style *parent, + const css_computed_style *child, + css_computed_style *result) +{ + css_fixed length = 0; + css_unit unit = CSS_UNIT_PX; + uint8_t type = get_flex_basis(child, &length, &unit); + + return css__copy_flex_basis( + type == CSS_FLEX_BASIS_INHERIT ? parent : child, + result); +} + diff --git a/src/select/properties/flex_direction.c b/src/select/properties/flex_direction.c new file mode 100644 index 0000000..1d979be --- /dev/null +++ b/src/select/properties/flex_direction.c @@ -0,0 +1,81 @@ +/* + * This file is part of LibCSS + * Licensed under the MIT License, + * http://www.opensource.org/licenses/mit-license.php + * Copyright 2017 Lucas Neves <lcneves@gmail.com> + */ + +#include "bytecode/bytecode.h" +#include "bytecode/opcodes.h" +#include "select/propset.h" +#include "select/propget.h" +#include "utils/utils.h" + +#include "select/properties/properties.h" +#include "select/properties/helpers.h" + +css_error css__cascade_flex_direction(uint32_t opv, css_style *style, + css_select_state *state) +{ + uint16_t value = CSS_FLEX_DIRECTION_INHERIT; + + UNUSED(style); + + if (hasFlagValue(opv) == false) { + switch (getValue(opv)) { + case FLEX_DIRECTION_ROW: + value = CSS_FLEX_DIRECTION_ROW; + break; + case FLEX_DIRECTION_ROW_REVERSE: + value = CSS_FLEX_DIRECTION_ROW_REVERSE; + break; + case FLEX_DIRECTION_COLUMN: + value = CSS_FLEX_DIRECTION_COLUMN; + break; + case FLEX_DIRECTION_COLUMN_REVERSE: + value = CSS_FLEX_DIRECTION_COLUMN_REVERSE; + break; + } + } + + if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, + getFlagValue(opv))) { + return set_flex_direction(state->computed, value); + } + + return CSS_OK; +} + +css_error css__set_flex_direction_from_hint(const css_hint *hint, + css_computed_style *style) +{ + return set_flex_direction(style, hint->status); +} + +css_error css__initial_flex_direction(css_select_state *state) +{ + return set_flex_direction(state->computed, CSS_FLEX_DIRECTION_ROW); +} + +css_error css__copy_flex_direction( + const css_computed_style *from, + css_computed_style *to) +{ + if (from == to) { + return CSS_OK; + } + + return set_flex_direction(to, get_flex_direction(from)); +} + +css_error css__compose_flex_direction(const css_computed_style *parent, + const css_computed_style *child, + css_computed_style *result) +{ + uint8_t type = get_flex_direction(child); + + return css__copy_flex_direction( + type == CSS_FLEX_DIRECTION_INHERIT ? parent : child, + result); +} + diff --git a/src/select/properties/flex_grow.c b/src/select/properties/flex_grow.c new file mode 100644 index 0000000..4650cef --- /dev/null +++ b/src/select/properties/flex_grow.c @@ -0,0 +1,74 @@ +/* + * This file is part of LibCSS + * Licensed under the MIT License, + * http://www.opensource.org/licenses/mit-license.php + * Copyright 2017 Lucas Neves <lcneves@gmail.com> + */ + +#include "bytecode/bytecode.h" +#include "bytecode/opcodes.h" +#include "select/propset.h" +#include "select/propget.h" +#include "utils/utils.h" + +#include "select/properties/properties.h" +#include "select/properties/helpers.h" + +css_error css__cascade_flex_grow(uint32_t opv, css_style *style, + css_select_state *state) +{ + uint16_t value = CSS_FLEX_GROW_INHERIT; + css_fixed flex_grow = 0; + + if (hasFlagValue(opv) == false) { + value = CSS_FLEX_GROW_SET; + + flex_grow = *((css_fixed *) style->bytecode); + advance_bytecode(style, sizeof(flex_grow)); + } + + if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, + getFlagValue(opv))) { + return set_flex_grow(state->computed, value, flex_grow); + } + + return CSS_OK; +} + +css_error css__set_flex_grow_from_hint(const css_hint *hint, + css_computed_style *style) +{ + return set_flex_grow(style, hint->status, hint->data.fixed); +} + +css_error css__initial_flex_grow(css_select_state *state) +{ + return set_flex_grow(state->computed, CSS_FLEX_GROW_SET, INTTOFIX(0)); +} + +css_error css__copy_flex_grow( + const css_computed_style *from, + css_computed_style *to) +{ + css_fixed flex_grow = 0; + uint8_t type = get_flex_grow(from, &flex_grow); + + if (from == to) { + return CSS_OK; + } + + return set_flex_grow(to, type, flex_grow); +} + +css_error css__compose_flex_grow(const css_computed_style *parent, + const css_computed_style *child, + css_computed_style *result) +{ + css_fixed flex_grow = 0; + uint8_t type = get_flex_grow(child, &flex_grow); + + return css__copy_flex_grow( + type == CSS_FLEX_GROW_INHERIT ? parent : child, + result); +} + diff --git a/src/select/properties/flex_shrink.c b/src/select/properties/flex_shrink.c new file mode 100644 index 0000000..9b39ed0 --- /dev/null +++ b/src/select/properties/flex_shrink.c @@ -0,0 +1,74 @@ +/* + * This file is part of LibCSS + * Licensed under the MIT License, + * http://www.opensource.org/licenses/mit-license.php + * Copyright 2017 Lucas Neves <lcneves@gmail.com> + */ + +#include "bytecode/bytecode.h" +#include "bytecode/opcodes.h" +#include "select/propset.h" +#include "select/propget.h" +#include "utils/utils.h" + +#include "select/properties/properties.h" +#include "select/properties/helpers.h" + +css_error css__cascade_flex_shrink(uint32_t opv, css_style *style, + css_select_state *state) +{ + uint16_t value = CSS_FLEX_SHRINK_INHERIT; + css_fixed flex_shrink = 0; + + if (hasFlagValue(opv) == false) { + value = CSS_FLEX_SHRINK_SET; + + flex_shrink = *((css_fixed *) style->bytecode); + advance_bytecode(style, sizeof(flex_shrink)); + } + + if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, + getFlagValue(opv))) { + return set_flex_shrink(state->computed, value, flex_shrink); + } + + return CSS_OK; +} + +css_error css__set_flex_shrink_from_hint(const css_hint *hint, + css_computed_style *style) +{ + return set_flex_shrink(style, hint->status, hint->data.fixed); +} + +css_error css__initial_flex_shrink(css_select_state *state) +{ + return set_flex_shrink(state->computed, CSS_FLEX_SHRINK_SET, INTTOFIX(1)); +} + +css_error css__copy_flex_shrink( + const css_computed_style *from, + css_computed_style *to) +{ + css_fixed flex_shrink = 0; + uint8_t type = get_flex_shrink(from, &flex_shrink); + + if (from == to) { + return CSS_OK; + } + + return set_flex_shrink(to, type, flex_shrink); +} + +css_error css__compose_flex_shrink(const css_computed_style *parent, + const css_computed_style *child, + css_computed_style *result) +{ + css_fixed flex_shrink = 0; + uint8_t type = get_flex_shrink(child, &flex_shrink); + + return css__copy_flex_shrink( + type == CSS_FLEX_SHRINK_INHERIT ? parent : child, + result); +} + diff --git a/src/select/properties/flex_wrap.c b/src/select/properties/flex_wrap.c new file mode 100644 index 0000000..3ca9b74 --- /dev/null +++ b/src/select/properties/flex_wrap.c @@ -0,0 +1,80 @@ +/* + * This file is part of LibCSS + * Licensed under the MIT License, + * http://www.opensource.org/licenses/mit-license.php + * Copyright 2017 Lucas Neves <lcneves@gmail.com> + */ + +#include "bytecode/bytecode.h" +#include "bytecode/opcodes.h" +#include "select/propset.h" +#include "select/propget.h" +#include "utils/utils.h" + +#include "select/properties/properties.h" +#include "select/properties/helpers.h" + +css_error css__cascade_flex_wrap(uint32_t opv, css_style *style, + css_select_state *state) +{ + uint16_t value = CSS_FLEX_WRAP_INHERIT; + + UNUSED(style); + + if (hasFlagValue(opv) == false) { + switch (getValue(opv)) { + case FLEX_WRAP_NOWRAP: + value = CSS_FLEX_WRAP_NOWRAP; + break; + case FLEX_WRAP_WRAP: + value = CSS_FLEX_WRAP_WRAP; + break; + case FLEX_WRAP_WRAP_REVERSE: + value = CSS_FLEX_WRAP_WRAP_REVERSE; + break; + } + } + + if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, + getFlagValue(opv))) { + return set_flex_wrap(state->computed, value); + } + + return CSS_OK; +} + +css_error css__set_flex_wrap_from_hint(const css_hint *hint, + css_computed_style *style) +{ + return set_flex_wrap(style, hint->status); +} + +css_error css__initial_flex_wrap(css_select_state *state) +{ + return set_flex_wrap(state->computed, CSS_FLEX_WRAP_NOWRAP); +} + +css_error css__copy_flex_wrap( + const css_computed_style *from, + css_computed_style *to) +{ + uint8_t type = get_flex_wrap(from); + + if (from == to) { + return CSS_OK; + } + + return set_flex_wrap(to, type); +} + +css_error css__compose_flex_wrap(const css_computed_style *parent, + const css_computed_style *child, + css_computed_style *result) +{ + uint8_t type = get_flex_wrap(child); + + return css__copy_flex_wrap( + type == CSS_FLEX_WRAP_INHERIT ? parent : child, + result); +} + diff --git a/src/select/properties/float.c b/src/select/properties/float.c index c3ba909..6d009bb 100644 --- a/src/select/properties/float.c +++ b/src/select/properties/float.c @@ -21,7 +21,7 @@ css_error css__cascade_float(uint32_t opv, css_style *style, UNUSED(style); - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case FLOAT_LEFT: value = CSS_FLOAT_LEFT; @@ -36,7 +36,7 @@ css_error css__cascade_float(uint32_t opv, css_style *style, } if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { return set_float(state->computed, value); } @@ -54,16 +54,25 @@ css_error css__initial_float(css_select_state *state) return set_float(state->computed, CSS_FLOAT_NONE); } +css_error css__copy_float( + const css_computed_style *from, + css_computed_style *to) +{ + if (from == to) { + return CSS_OK; + } + + return set_float(to, get_float(from)); +} + css_error css__compose_float(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) { uint8_t type = get_float(child); - if (type == CSS_FLOAT_INHERIT) { - type = get_float(parent); - } - - return set_float(result, type); + return css__copy_float( + type == CSS_FLOAT_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/font_family.c b/src/select/properties/font_family.c index f853fcc..b0183e2 100644 --- a/src/select/properties/font_family.c +++ b/src/select/properties/font_family.c @@ -21,7 +21,7 @@ css_error css__cascade_font_family(uint32_t opv, css_style *style, lwc_string **fonts = NULL; uint32_t n_fonts = 0; - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { uint32_t v = getValue(opv); while (v != FONT_FAMILY_END) { @@ -134,7 +134,7 @@ css_error css__cascade_font_family(uint32_t opv, css_style *style, } if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { css_error error; error = set_font_family(state->computed, value, fonts); @@ -182,42 +182,41 @@ css_error css__initial_font_family(css_select_state *state) return css__set_font_family_from_hint(&hint, state->computed); } -css_error css__compose_font_family(const css_computed_style *parent, - const css_computed_style *child, - css_computed_style *result) +css_error css__copy_font_family( + const css_computed_style *from, + css_computed_style *to) { css_error error; - lwc_string **names = NULL; - uint8_t type = get_font_family(child, &names); - - if (type == CSS_FONT_FAMILY_INHERIT || result != child) { - size_t n_names = 0; - lwc_string **copy = NULL; - - if (type == CSS_FONT_FAMILY_INHERIT) - type = get_font_family(parent, &names); + lwc_string **copy = NULL; + lwc_string **font_family = NULL; + uint8_t type = get_font_family(from, &font_family); - if (names != NULL) { - lwc_string **i; - - for (i = names; (*i) != NULL; i++) - n_names++; + if (from == to) { + return CSS_OK; + } - copy = malloc((n_names + 1) * sizeof(lwc_string *)); - if (copy == NULL) - return CSS_NOMEM; + error = css__copy_lwc_string_array(false, font_family, ©); + if (error != CSS_OK) { + return CSS_NOMEM; + } - memcpy(copy, names, (n_names + 1) * - sizeof(lwc_string *)); - } + error = set_font_family(to, type, copy); + if (error != CSS_OK) { + free(copy); + } - error = set_font_family(result, type, copy); - if (error != CSS_OK && copy != NULL) - free(copy); + return error; +} - return error; - } +css_error css__compose_font_family(const css_computed_style *parent, + const css_computed_style *child, + css_computed_style *result) +{ + lwc_string **font_family = NULL; + uint8_t type = get_font_family(child, &font_family); - return CSS_OK; + return css__copy_font_family( + type == CSS_FONT_FAMILY_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/font_size.c b/src/select/properties/font_size.c index a0269be..3ee9ce0 100644 --- a/src/select/properties/font_size.c +++ b/src/select/properties/font_size.c @@ -21,7 +21,7 @@ css_error css__cascade_font_size(uint32_t opv, css_style *style, css_fixed size = 0; uint32_t unit = UNIT_PX; - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case FONT_SIZE_DIMENSION: value = CSS_FONT_SIZE_DIMENSION; @@ -65,7 +65,7 @@ css_error css__cascade_font_size(uint32_t opv, css_style *style, unit = css__to_css_unit(unit); if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { return set_font_size(state->computed, value, size, unit); } @@ -85,6 +85,21 @@ css_error css__initial_font_size(css_select_state *state) 0, CSS_UNIT_PX); } +css_error css__copy_font_size( + const css_computed_style *from, + css_computed_style *to) +{ + css_fixed size = 0; + css_unit unit = CSS_UNIT_PX; + uint8_t type = get_font_size(from, &size, &unit); + + if (from == to) { + return CSS_OK; + } + + return set_font_size(to, type, size, unit); +} + css_error css__compose_font_size(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) @@ -93,10 +108,8 @@ css_error css__compose_font_size(const css_computed_style *parent, css_unit unit = CSS_UNIT_PX; uint8_t type = get_font_size(child, &size, &unit); - if (type == CSS_FONT_SIZE_INHERIT) { - type = get_font_size(parent, &size, &unit); - } - - return set_font_size(result, type, size, unit); + return css__copy_font_size( + type == CSS_FONT_SIZE_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/font_style.c b/src/select/properties/font_style.c index 0ba1fdd..fe605b8 100644 --- a/src/select/properties/font_style.c +++ b/src/select/properties/font_style.c @@ -21,7 +21,7 @@ css_error css__cascade_font_style(uint32_t opv, css_style *style, UNUSED(style); - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case FONT_STYLE_NORMAL: value = CSS_FONT_STYLE_NORMAL; @@ -36,7 +36,7 @@ css_error css__cascade_font_style(uint32_t opv, css_style *style, } if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { return set_font_style(state->computed, value); } @@ -54,16 +54,25 @@ css_error css__initial_font_style(css_select_state *state) return set_font_style(state->computed, CSS_FONT_STYLE_NORMAL); } +css_error css__copy_font_style( + const css_computed_style *from, + css_computed_style *to) +{ + if (from == to) { + return CSS_OK; + } + + return set_font_style(to, get_font_style(from)); +} + css_error css__compose_font_style(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) { uint8_t type = get_font_style(child); - if (type == CSS_FONT_STYLE_INHERIT) { - type= get_font_style(parent); - } - - return set_font_style(result, type); + return css__copy_font_style( + type == CSS_FONT_STYLE_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/font_variant.c b/src/select/properties/font_variant.c index a9b6e56..9668fc3 100644 --- a/src/select/properties/font_variant.c +++ b/src/select/properties/font_variant.c @@ -21,7 +21,7 @@ css_error css__cascade_font_variant(uint32_t opv, css_style *style, UNUSED(style); - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case FONT_VARIANT_NORMAL: value = CSS_FONT_VARIANT_NORMAL; @@ -33,7 +33,7 @@ css_error css__cascade_font_variant(uint32_t opv, css_style *style, } if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { return set_font_variant(state->computed, value); } @@ -51,16 +51,25 @@ css_error css__initial_font_variant(css_select_state *state) return set_font_variant(state->computed, CSS_FONT_VARIANT_NORMAL); } +css_error css__copy_font_variant( + const css_computed_style *from, + css_computed_style *to) +{ + if (from == to) { + return CSS_OK; + } + + return set_font_variant(to, get_font_variant(from)); +} + css_error css__compose_font_variant(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) { uint8_t type = get_font_variant(child); - if (type == CSS_FONT_VARIANT_INHERIT) { - type = get_font_variant(parent); - } - - return set_font_variant(result, type); + return css__copy_font_variant( + type == CSS_FONT_VARIANT_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/font_weight.c b/src/select/properties/font_weight.c index c0c2f2b..da918a1 100644 --- a/src/select/properties/font_weight.c +++ b/src/select/properties/font_weight.c @@ -21,7 +21,7 @@ css_error css__cascade_font_weight(uint32_t opv, css_style *style, UNUSED(style); - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case FONT_WEIGHT_NORMAL: value = CSS_FONT_WEIGHT_NORMAL; @@ -66,7 +66,7 @@ css_error css__cascade_font_weight(uint32_t opv, css_style *style, } if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { return set_font_weight(state->computed, value); } @@ -84,16 +84,25 @@ css_error css__initial_font_weight(css_select_state *state) return set_font_weight(state->computed, CSS_FONT_WEIGHT_NORMAL); } +css_error css__copy_font_weight( + const css_computed_style *from, + css_computed_style *to) +{ + if (from == to) { + return CSS_OK; + } + + return set_font_weight(to, get_font_weight(from)); +} + css_error css__compose_font_weight(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) { uint8_t type = get_font_weight(child); - if (type == CSS_FONT_WEIGHT_INHERIT) { - type = get_font_weight(parent); - } - - return set_font_weight(result, type); + return css__copy_font_weight( + type == CSS_FONT_WEIGHT_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/height.c b/src/select/properties/height.c index 1d74c4a..d449e72 100644 --- a/src/select/properties/height.c +++ b/src/select/properties/height.c @@ -32,6 +32,21 @@ css_error css__initial_height(css_select_state *state) return set_height(state->computed, CSS_HEIGHT_AUTO, 0, CSS_UNIT_PX); } +css_error css__copy_height( + const css_computed_style *from, + css_computed_style *to) +{ + css_fixed length = 0; + css_unit unit = CSS_UNIT_PX; + uint8_t type = get_height(from, &length, &unit); + + if (from == to) { + return CSS_OK; + } + + return set_height(to, type, length, unit); +} + css_error css__compose_height(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) @@ -40,10 +55,8 @@ css_error css__compose_height(const css_computed_style *parent, css_unit unit = CSS_UNIT_PX; uint8_t type = get_height(child, &length, &unit); - if (type == CSS_HEIGHT_INHERIT) { - type = get_height(parent, &length, &unit); - } - - return set_height(result, type, length, unit); + return css__copy_height( + type == CSS_HEIGHT_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/helpers.c b/src/select/properties/helpers.c index 36c3cba..10ff228 100644 --- a/src/select/properties/helpers.c +++ b/src/select/properties/helpers.c @@ -16,32 +16,6 @@ #include "select/properties/helpers.h" -/* Useful helpers */ - -css_unit css__to_css_unit(uint32_t u) -{ - switch (u) { - case UNIT_PX: return CSS_UNIT_PX; - case UNIT_EX: return CSS_UNIT_EX; - case UNIT_EM: return CSS_UNIT_EM; - case UNIT_IN: return CSS_UNIT_IN; - case UNIT_CM: return CSS_UNIT_CM; - case UNIT_MM: return CSS_UNIT_MM; - case UNIT_PT: return CSS_UNIT_PT; - case UNIT_PC: return CSS_UNIT_PC; - case UNIT_PCT: return CSS_UNIT_PCT; - case UNIT_DEG: return CSS_UNIT_DEG; - case UNIT_GRAD: return CSS_UNIT_GRAD; - case UNIT_RAD: return CSS_UNIT_RAD; - case UNIT_MS: return CSS_UNIT_MS; - case UNIT_S: return CSS_UNIT_S; - case UNIT_HZ: return CSS_UNIT_HZ; - case UNIT_KHZ: return CSS_UNIT_KHZ; - } - - return 0; -} - /****************************************************************************** * Utilities below here * ******************************************************************************/ @@ -59,7 +33,7 @@ css_error css__cascade_bg_border_color(uint32_t opv, css_style *style, assert(CSS_BACKGROUND_COLOR_CURRENT_COLOR == (enum css_background_color_e)CSS_BORDER_COLOR_CURRENT_COLOR); - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case BACKGROUND_COLOR_TRANSPARENT: value = CSS_BACKGROUND_COLOR_COLOR; @@ -76,7 +50,7 @@ css_error css__cascade_bg_border_color(uint32_t opv, css_style *style, } if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { return fun(state->computed, value, color); } @@ -91,7 +65,7 @@ css_error css__cascade_uri_none(uint32_t opv, css_style *style, uint16_t value = CSS_BACKGROUND_IMAGE_INHERIT; lwc_string *uri = NULL; - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case BACKGROUND_IMAGE_NONE: value = CSS_BACKGROUND_IMAGE_NONE; @@ -106,7 +80,7 @@ css_error css__cascade_uri_none(uint32_t opv, css_style *style, /** \todo lose fun != NULL once all properties have set routines */ if (fun != NULL && css__outranks_existing(getOpcode(opv), - isImportant(opv), state, isInherit(opv))) { + isImportant(opv), state, getFlagValue(opv))) { return fun(state->computed, value, uri); } @@ -121,7 +95,7 @@ css_error css__cascade_border_style(uint32_t opv, css_style *style, UNUSED(style); - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case BORDER_STYLE_NONE: value = CSS_BORDER_STYLE_NONE; @@ -157,7 +131,7 @@ css_error css__cascade_border_style(uint32_t opv, css_style *style, } if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { return fun(state->computed, value); } @@ -173,7 +147,7 @@ css_error css__cascade_border_width(uint32_t opv, css_style *style, css_fixed length = 0; uint32_t unit = UNIT_PX; - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case BORDER_WIDTH_SET: value = CSS_BORDER_WIDTH_WIDTH; @@ -197,7 +171,7 @@ css_error css__cascade_border_width(uint32_t opv, css_style *style, unit = css__to_css_unit(unit); if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { return fun(state->computed, value, length, unit); } @@ -213,7 +187,7 @@ css_error css__cascade_length_auto(uint32_t opv, css_style *style, css_fixed length = 0; uint32_t unit = UNIT_PX; - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case BOTTOM_SET: value = CSS_BOTTOM_SET; @@ -231,7 +205,7 @@ css_error css__cascade_length_auto(uint32_t opv, css_style *style, unit = css__to_css_unit(unit); if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { return fun(state->computed, value, length, unit); } @@ -247,7 +221,7 @@ css_error css__cascade_length_normal(uint32_t opv, css_style *style, css_fixed length = 0; uint32_t unit = UNIT_PX; - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case LETTER_SPACING_SET: value = CSS_LETTER_SPACING_SET; @@ -265,7 +239,7 @@ css_error css__cascade_length_normal(uint32_t opv, css_style *style, unit = css__to_css_unit(unit); if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { return fun(state->computed, value, length, unit); } @@ -281,7 +255,7 @@ css_error css__cascade_length_none(uint32_t opv, css_style *style, css_fixed length = 0; uint32_t unit = UNIT_PX; - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case MAX_HEIGHT_SET: value = CSS_MAX_HEIGHT_SET; @@ -299,7 +273,7 @@ css_error css__cascade_length_none(uint32_t opv, css_style *style, unit = css__to_css_unit(unit); if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { return fun(state->computed, value, length, unit); } @@ -315,7 +289,7 @@ css_error css__cascade_length(uint32_t opv, css_style *style, css_fixed length = 0; uint32_t unit = UNIT_PX; - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { value = CSS_MIN_HEIGHT_SET; length = *((css_fixed *) style->bytecode); advance_bytecode(style, sizeof(length)); @@ -327,7 +301,7 @@ css_error css__cascade_length(uint32_t opv, css_style *style, /** \todo lose fun != NULL once all properties have set routines */ if (fun != NULL && css__outranks_existing(getOpcode(opv), - isImportant(opv), state, isInherit(opv))) { + isImportant(opv), state, getFlagValue(opv))) { return fun(state->computed, value, length, unit); } @@ -343,7 +317,7 @@ css_error css__cascade_number(uint32_t opv, css_style *style, /** \todo values */ - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { value = 0; length = *((css_fixed *) style->bytecode); advance_bytecode(style, sizeof(length)); @@ -351,7 +325,7 @@ css_error css__cascade_number(uint32_t opv, css_style *style, /** \todo lose fun != NULL once all properties have set routines */ if (fun != NULL && css__outranks_existing(getOpcode(opv), - isImportant(opv), state, isInherit(opv))) { + isImportant(opv), state, getFlagValue(opv))) { return fun(state->computed, value, length); } @@ -366,7 +340,7 @@ css_error css__cascade_page_break_after_before_inside(uint32_t opv, UNUSED(style); - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case PAGE_BREAK_AFTER_AUTO: value = CSS_PAGE_BREAK_AFTER_AUTO; @@ -388,7 +362,7 @@ css_error css__cascade_page_break_after_before_inside(uint32_t opv, /** \todo lose fun != NULL */ if (fun != NULL && css__outranks_existing(getOpcode(opv), - isImportant(opv), state, isInherit(opv))) { + isImportant(opv), state, getFlagValue(opv))) { return fun(state->computed, value); } @@ -403,7 +377,7 @@ css_error css__cascade_break_after_before_inside(uint32_t opv, UNUSED(style); - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case BREAK_AFTER_AUTO: value = CSS_BREAK_AFTER_AUTO; @@ -437,7 +411,7 @@ css_error css__cascade_break_after_before_inside(uint32_t opv, /** \todo lose fun != NULL */ if (fun != NULL && css__outranks_existing(getOpcode(opv), - isImportant(opv), state, isInherit(opv))) { + isImportant(opv), state, getFlagValue(opv))) { return fun(state->computed, value); } @@ -453,7 +427,7 @@ css_error css__cascade_counter_increment_reset(uint32_t opv, css_style *style, css_computed_counter *counters = NULL; uint32_t n_counters = 0; - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case COUNTER_INCREMENT_NAMED: { @@ -516,7 +490,7 @@ css_error css__cascade_counter_increment_reset(uint32_t opv, css_style *style, } if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { css_error error; error = fun(state->computed, value, counters); diff --git a/src/select/properties/helpers.h b/src/select/properties/helpers.h index 901bcf0..16c5d7a 100644 --- a/src/select/properties/helpers.h +++ b/src/select/properties/helpers.h @@ -8,13 +8,13 @@ #ifndef css_select_properties_helpers_h_ #define css_select_properties_helpers_h_ +#include "select/helpers.h" + uint32_t generic_destroy_color(void *bytecode); uint32_t generic_destroy_uri(void *bytecode); uint32_t generic_destroy_length(void *bytecode); uint32_t generic_destroy_number(void *bytecode); -css_unit css__to_css_unit(uint32_t u); - css_error css__cascade_bg_border_color(uint32_t opv, css_style *style, css_select_state *state, css_error (*fun)(css_computed_style *, uint8_t, css_color)); @@ -59,4 +59,137 @@ css_error css__cascade_counter_increment_reset(uint32_t opv, css_style *style, css_error (*fun)(css_computed_style *, uint8_t, css_computed_counter *)); +/** Copy NULL terminated array of lwc_string pointers. */ +static inline css_error css__copy_lwc_string_array( + bool ref, + lwc_string *const*orig, + lwc_string ***copy_out) +{ + size_t count = 0; + lwc_string **copy = NULL; + + if (orig != NULL) { + for (lwc_string *const*i = orig; (*i) != NULL; i++) { + count++; + } + + copy = malloc((count + 1) * sizeof(*copy)); + if (copy == NULL) { + return CSS_NOMEM; + } + + if (ref) { + for (size_t i = 0; i < count; i++) { + copy[i] = lwc_string_ref(orig[i]); + } + copy[count] = NULL; + } else { + memcpy(copy, orig, (count + 1) * sizeof(*copy)); + } + } + + *copy_out = copy; + return CSS_OK; +} + +/** Copy NULL-name terminated array of css_computed_counter items. */ +static inline css_error css__copy_computed_counter_array( + bool ref, + const css_computed_counter *orig, + css_computed_counter **copy_out) +{ + size_t count = 0; + css_computed_counter *copy = NULL; + + if (orig != NULL) { + for (const css_computed_counter *i = orig; + i->name != NULL; i++) { + count++; + } + + copy = malloc((count + 1) * sizeof(*copy)); + if (copy == NULL) { + return CSS_NOMEM; + } + + if (ref) { + for (size_t i = 0; i < count; i++) { + copy[i].name = lwc_string_ref(orig[i].name); + copy[i].value = orig[i].value; + } + copy[count].name = NULL; + copy[count].value = 0; + } else { + memcpy(copy, orig, (count + 1) * sizeof(*copy)); + } + } + + *copy_out = copy; + return CSS_OK; +} + +/** Copy type:none terminated array of css_computed_content_item items. */ +static inline css_error css__copy_computed_content_item_array( + bool ref, + const css_computed_content_item *orig, + css_computed_content_item **copy_out) +{ + size_t count = 0; + css_computed_content_item *copy = NULL; + + if (orig != NULL) { + for (const css_computed_content_item *i = orig; + i->type != CSS_COMPUTED_CONTENT_NONE; i++) { + count++; + } + + copy = malloc((count + 1) * sizeof(*copy)); + if (copy == NULL) { + return CSS_NOMEM; + } + + if (ref) { + for (size_t i = 0; i < count; i++) { + switch (orig[i].type) { + case CSS_COMPUTED_CONTENT_STRING: + copy[i].data.string = lwc_string_ref( + orig[i].data.string); + break; + case CSS_COMPUTED_CONTENT_URI: + copy[i].data.uri = lwc_string_ref( + orig[i].data.uri); + break; + case CSS_COMPUTED_CONTENT_ATTR: + copy[i].data.attr = lwc_string_ref( + orig[i].data.attr); + break; + case CSS_COMPUTED_CONTENT_COUNTER: + copy[i].data.counter.name = lwc_string_ref( + orig[i].data.counter.name); + copy[i].data.counter.style = + orig[i].data.counter.style; + break; + case CSS_COMPUTED_CONTENT_COUNTERS: + copy[i].data.counters.name = lwc_string_ref( + orig[i].data.counters.name); + copy[i].data.counters.sep = lwc_string_ref( + orig[i].data.counters.sep); + copy[i].data.counters.style = + orig[i].data.counters.style; + break; + default: + break; + } + copy[i].type = orig[i].type; + } + copy[count].type = CSS_COMPUTED_CONTENT_NONE; + } else { + memcpy(copy, orig, (count + 1) * sizeof(*copy)); + } + } + + *copy_out = copy; + return CSS_OK; +} + #endif diff --git a/src/select/properties/justify_content.c b/src/select/properties/justify_content.c new file mode 100644 index 0000000..385bab7 --- /dev/null +++ b/src/select/properties/justify_content.c @@ -0,0 +1,88 @@ +/* + * This file is part of LibCSS + * Licensed under the MIT License, + * http://www.opensource.org/licenses/mit-license.php + * Copyright 2017 Lucas Neves <lcneves@gmail.com> + */ + +#include "bytecode/bytecode.h" +#include "bytecode/opcodes.h" +#include "select/propset.h" +#include "select/propget.h" +#include "utils/utils.h" + +#include "select/properties/properties.h" +#include "select/properties/helpers.h" + +css_error css__cascade_justify_content(uint32_t opv, css_style *style, + css_select_state *state) +{ + uint16_t value = CSS_JUSTIFY_CONTENT_INHERIT; + + UNUSED(style); + + if (hasFlagValue(opv) == false) { + switch (getValue(opv)) { + case JUSTIFY_CONTENT_FLEX_START: + value = CSS_JUSTIFY_CONTENT_FLEX_START; + break; + case JUSTIFY_CONTENT_FLEX_END: + value = CSS_JUSTIFY_CONTENT_FLEX_END; + break; + case JUSTIFY_CONTENT_CENTER: + value = CSS_JUSTIFY_CONTENT_CENTER; + break; + case JUSTIFY_CONTENT_SPACE_BETWEEN: + value = CSS_JUSTIFY_CONTENT_SPACE_BETWEEN; + break; + case JUSTIFY_CONTENT_SPACE_AROUND: + value = CSS_JUSTIFY_CONTENT_SPACE_AROUND; + break; + case JUSTIFY_CONTENT_SPACE_EVENLY: + value = CSS_JUSTIFY_CONTENT_SPACE_EVENLY; + break; + } + } + + if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, + getFlagValue(opv))) { + return set_justify_content(state->computed, value); + } + + return CSS_OK; +} + +css_error css__set_justify_content_from_hint(const css_hint *hint, + css_computed_style *style) +{ + return set_justify_content(style, hint->status); +} + +css_error css__initial_justify_content(css_select_state *state) +{ + return set_justify_content(state->computed, + CSS_JUSTIFY_CONTENT_FLEX_START); +} + +css_error css__copy_justify_content( + const css_computed_style *from, + css_computed_style *to) +{ + if (from == to) { + return CSS_OK; + } + + return set_justify_content(to, get_justify_content(from)); +} + +css_error css__compose_justify_content(const css_computed_style *parent, + const css_computed_style *child, + css_computed_style *result) +{ + uint8_t type = get_justify_content(child); + + return css__copy_justify_content( + type == CSS_JUSTIFY_CONTENT_INHERIT ? parent : child, + result); +} + diff --git a/src/select/properties/left.c b/src/select/properties/left.c index 4baa324..ca8c844 100644 --- a/src/select/properties/left.c +++ b/src/select/properties/left.c @@ -32,6 +32,21 @@ css_error css__initial_left(css_select_state *state) return set_left(state->computed, CSS_LEFT_AUTO, 0, CSS_UNIT_PX); } +css_error css__copy_left( + const css_computed_style *from, + css_computed_style *to) +{ + css_fixed length = 0; + css_unit unit = CSS_UNIT_PX; + uint8_t type = get_left(from, &length, &unit); + + if (from == to) { + return CSS_OK; + } + + return set_left(to, type, length, unit); +} + css_error css__compose_left(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) @@ -40,10 +55,8 @@ css_error css__compose_left(const css_computed_style *parent, css_unit unit = CSS_UNIT_PX; uint8_t type = get_left(child, &length, &unit); - if (type == CSS_LEFT_INHERIT) { - type = get_left(parent, &length, &unit); - } - - return set_left(result, type, length, unit); + return css__copy_left( + type == CSS_LEFT_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/letter_spacing.c b/src/select/properties/letter_spacing.c index d799467..9c8e50c 100644 --- a/src/select/properties/letter_spacing.c +++ b/src/select/properties/letter_spacing.c @@ -33,6 +33,21 @@ css_error css__initial_letter_spacing(css_select_state *state) 0, CSS_UNIT_PX); } +css_error css__copy_letter_spacing( + const css_computed_style *from, + css_computed_style *to) +{ + css_fixed length = 0; + css_unit unit = CSS_UNIT_PX; + uint8_t type = get_letter_spacing(from, &length, &unit); + + if (from == to) { + return CSS_OK; + } + + return set_letter_spacing(to, type, length, unit); +} + css_error css__compose_letter_spacing(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) @@ -41,17 +56,7 @@ css_error css__compose_letter_spacing(const css_computed_style *parent, css_unit unit = CSS_UNIT_PX; uint8_t type = get_letter_spacing(child, &length, &unit); - if ((child->i.uncommon == NULL && parent->i.uncommon != NULL) || - type == CSS_LETTER_SPACING_INHERIT || - (child->i.uncommon != NULL && result != child)) { - if ((child->i.uncommon == NULL && parent->i.uncommon != NULL) || - type == CSS_LETTER_SPACING_INHERIT) { - type = get_letter_spacing(parent, &length, &unit); - } - - return set_letter_spacing(result, type, length, unit); - } - - return CSS_OK; + return css__copy_letter_spacing( + type == CSS_LETTER_SPACING_INHERIT ? parent : child, + result); } - diff --git a/src/select/properties/line_height.c b/src/select/properties/line_height.c index 091a575..7300b5d 100644 --- a/src/select/properties/line_height.c +++ b/src/select/properties/line_height.c @@ -21,7 +21,7 @@ css_error css__cascade_line_height(uint32_t opv, css_style *style, css_fixed val = 0; uint32_t unit = UNIT_PX; - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case LINE_HEIGHT_NUMBER: value = CSS_LINE_HEIGHT_NUMBER; @@ -44,7 +44,7 @@ css_error css__cascade_line_height(uint32_t opv, css_style *style, unit = css__to_css_unit(unit); if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { return set_line_height(state->computed, value, val, unit); } @@ -64,6 +64,21 @@ css_error css__initial_line_height(css_select_state *state) 0, CSS_UNIT_PX); } +css_error css__copy_line_height( + const css_computed_style *from, + css_computed_style *to) +{ + css_fixed length = 0; + css_unit unit = CSS_UNIT_PX; + uint8_t type = get_line_height(from, &length, &unit); + + if (from == to) { + return CSS_OK; + } + + return set_line_height(to, type, length, unit); +} + css_error css__compose_line_height(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) @@ -72,10 +87,8 @@ css_error css__compose_line_height(const css_computed_style *parent, css_unit unit = CSS_UNIT_PX; uint8_t type = get_line_height(child, &length, &unit); - if (type == CSS_LINE_HEIGHT_INHERIT) { - type = get_line_height(parent, &length, &unit); - } - - return set_line_height(result, type, length, unit); + return css__copy_line_height( + type == CSS_LINE_HEIGHT_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/list_style_image.c b/src/select/properties/list_style_image.c index cc77eb4..7a41c3a 100644 --- a/src/select/properties/list_style_image.c +++ b/src/select/properties/list_style_image.c @@ -39,6 +39,20 @@ css_error css__initial_list_style_image(css_select_state *state) CSS_LIST_STYLE_IMAGE_NONE, NULL); } +css_error css__copy_list_style_image( + const css_computed_style *from, + css_computed_style *to) +{ + lwc_string *url; + uint8_t type = get_list_style_image(from, &url); + + if (from == to) { + return CSS_OK; + } + + return set_list_style_image(to, type, url); +} + css_error css__compose_list_style_image(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) @@ -46,10 +60,8 @@ css_error css__compose_list_style_image(const css_computed_style *parent, lwc_string *url; uint8_t type = get_list_style_image(child, &url); - if (type == CSS_LIST_STYLE_IMAGE_INHERIT) { - type = get_list_style_image(parent, &url); - } - - return set_list_style_image(result, type, url); + return css__copy_list_style_image( + type == CSS_LIST_STYLE_IMAGE_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/list_style_position.c b/src/select/properties/list_style_position.c index 02d7651..ca46850 100644 --- a/src/select/properties/list_style_position.c +++ b/src/select/properties/list_style_position.c @@ -21,7 +21,7 @@ css_error css__cascade_list_style_position(uint32_t opv, css_style *style, UNUSED(style); - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case LIST_STYLE_POSITION_INSIDE: value = CSS_LIST_STYLE_POSITION_INSIDE; @@ -33,7 +33,7 @@ css_error css__cascade_list_style_position(uint32_t opv, css_style *style, } if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { return set_list_style_position(state->computed, value); } @@ -52,16 +52,25 @@ css_error css__initial_list_style_position(css_select_state *state) CSS_LIST_STYLE_POSITION_OUTSIDE); } +css_error css__copy_list_style_position( + const css_computed_style *from, + css_computed_style *to) +{ + if (from == to) { + return CSS_OK; + } + + return set_list_style_position(to, get_list_style_position(from)); +} + css_error css__compose_list_style_position(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) { uint8_t type = get_list_style_position(child); - if (type == CSS_LIST_STYLE_POSITION_INHERIT) { - type = get_list_style_position(parent); - } - - return set_list_style_position(result, type); + return css__copy_list_style_position( + type == CSS_LIST_STYLE_POSITION_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/list_style_type.c b/src/select/properties/list_style_type.c index b1e5db6..9d809e6 100644 --- a/src/select/properties/list_style_type.c +++ b/src/select/properties/list_style_type.c @@ -21,7 +21,7 @@ css_error css__cascade_list_style_type(uint32_t opv, css_style *style, UNUSED(style); - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case LIST_STYLE_TYPE_DISC: value = CSS_LIST_STYLE_TYPE_DISC; @@ -68,11 +68,122 @@ css_error css__cascade_list_style_type(uint32_t opv, css_style *style, case LIST_STYLE_TYPE_NONE: value = CSS_LIST_STYLE_TYPE_NONE; break; + case LIST_STYLE_TYPE_BINARY: + value = CSS_LIST_STYLE_TYPE_BINARY; + break; + case LIST_STYLE_TYPE_OCTAL: + value = CSS_LIST_STYLE_TYPE_OCTAL; + break; + case LIST_STYLE_TYPE_LOWER_HEXADECIMAL: + value = CSS_LIST_STYLE_TYPE_LOWER_HEXADECIMAL; + break; + case LIST_STYLE_TYPE_UPPER_HEXADECIMAL: + value = CSS_LIST_STYLE_TYPE_UPPER_HEXADECIMAL; + break; + case LIST_STYLE_TYPE_ARABIC_INDIC: + value = CSS_LIST_STYLE_TYPE_ARABIC_INDIC; + break; + case LIST_STYLE_TYPE_LOWER_ARMENIAN: + value = CSS_LIST_STYLE_TYPE_LOWER_ARMENIAN; + break; + case LIST_STYLE_TYPE_UPPER_ARMENIAN: + value = CSS_LIST_STYLE_TYPE_UPPER_ARMENIAN; + break; + case LIST_STYLE_TYPE_BENGALI: + value = CSS_LIST_STYLE_TYPE_BENGALI; + break; + case LIST_STYLE_TYPE_CAMBODIAN: + value = CSS_LIST_STYLE_TYPE_CAMBODIAN; + break; + case LIST_STYLE_TYPE_KHMER: + value = CSS_LIST_STYLE_TYPE_KHMER; + break; + case LIST_STYLE_TYPE_CJK_DECIMAL: + value = CSS_LIST_STYLE_TYPE_CJK_DECIMAL; + break; + case LIST_STYLE_TYPE_DEVANAGARI: + value = CSS_LIST_STYLE_TYPE_DEVANAGARI; + break; + case LIST_STYLE_TYPE_GUJARATI: + value = CSS_LIST_STYLE_TYPE_GUJARATI; + break; + case LIST_STYLE_TYPE_GURMUKHI: + value = CSS_LIST_STYLE_TYPE_GURMUKHI; + break; + case LIST_STYLE_TYPE_HEBREW: + value = CSS_LIST_STYLE_TYPE_HEBREW; + break; + case LIST_STYLE_TYPE_KANNADA: + value = CSS_LIST_STYLE_TYPE_KANNADA; + break; + case LIST_STYLE_TYPE_LAO: + value = CSS_LIST_STYLE_TYPE_LAO; + break; + case LIST_STYLE_TYPE_MALAYALAM: + value = CSS_LIST_STYLE_TYPE_MALAYALAM; + break; + case LIST_STYLE_TYPE_MONGOLIAN: + value = CSS_LIST_STYLE_TYPE_MONGOLIAN; + break; + case LIST_STYLE_TYPE_MYANMAR: + value = CSS_LIST_STYLE_TYPE_MYANMAR; + break; + case LIST_STYLE_TYPE_ORIYA: + value = CSS_LIST_STYLE_TYPE_ORIYA; + break; + case LIST_STYLE_TYPE_PERSIAN: + value = CSS_LIST_STYLE_TYPE_PERSIAN; + break; + case LIST_STYLE_TYPE_TAMIL: + value = CSS_LIST_STYLE_TYPE_TAMIL; + break; + case LIST_STYLE_TYPE_TELUGU: + value = CSS_LIST_STYLE_TYPE_TELUGU; + break; + case LIST_STYLE_TYPE_THAI: + value = CSS_LIST_STYLE_TYPE_THAI; + break; + case LIST_STYLE_TYPE_TIBETAN: + value = CSS_LIST_STYLE_TYPE_TIBETAN; + break; + case LIST_STYLE_TYPE_CJK_EARTHLY_BRANCH: + value = CSS_LIST_STYLE_TYPE_CJK_EARTHLY_BRANCH; + break; + case LIST_STYLE_TYPE_CJK_HEAVENLY_STEM: + value = CSS_LIST_STYLE_TYPE_CJK_HEAVENLY_STEM; + break; + case LIST_STYLE_TYPE_HIAGANA: + value = CSS_LIST_STYLE_TYPE_HIAGANA; + break; + case LIST_STYLE_TYPE_HIAGANA_IROHA: + value = CSS_LIST_STYLE_TYPE_HIAGANA_IROHA; + break; + case LIST_STYLE_TYPE_KATAKANA: + value = CSS_LIST_STYLE_TYPE_KATAKANA; + break; + case LIST_STYLE_TYPE_KATAKANA_IROHA: + value = CSS_LIST_STYLE_TYPE_KATAKANA_IROHA; + break; + case LIST_STYLE_TYPE_JAPANESE_INFORMAL: + value = CSS_LIST_STYLE_TYPE_JAPANESE_INFORMAL; + break; + case LIST_STYLE_TYPE_JAPANESE_FORMAL: + value = CSS_LIST_STYLE_TYPE_JAPANESE_FORMAL; + break; + case LIST_STYLE_TYPE_KOREAN_HANGUL_FORMAL: + value = CSS_LIST_STYLE_TYPE_KOREAN_HANGUL_FORMAL; + break; + case LIST_STYLE_TYPE_KOREAN_HANJA_INFORMAL: + value = CSS_LIST_STYLE_TYPE_KOREAN_HANJA_INFORMAL; + break; + case LIST_STYLE_TYPE_KOREAN_HANJA_FORMAL: + value = CSS_LIST_STYLE_TYPE_KOREAN_HANJA_FORMAL; + break; } } if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { return set_list_style_type(state->computed, value); } @@ -90,16 +201,24 @@ css_error css__initial_list_style_type(css_select_state *state) return set_list_style_type(state->computed, CSS_LIST_STYLE_TYPE_DISC); } +css_error css__copy_list_style_type( + const css_computed_style *from, + css_computed_style *to) +{ + if (from == to) { + return CSS_OK; + } + + return set_list_style_type(to, get_list_style_type(from)); +} + css_error css__compose_list_style_type(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) { uint8_t type = get_list_style_type(child); - if (type == CSS_LIST_STYLE_TYPE_INHERIT) { - type = get_list_style_type(parent); - } - - return set_list_style_type(result, type); + return css__copy_list_style_type( + type == CSS_LIST_STYLE_TYPE_INHERIT ? parent : child, + result); } - diff --git a/src/select/properties/margin_bottom.c b/src/select/properties/margin_bottom.c index 3b1d8a1..a0ffd89 100644 --- a/src/select/properties/margin_bottom.c +++ b/src/select/properties/margin_bottom.c @@ -32,6 +32,21 @@ css_error css__initial_margin_bottom(css_select_state *state) return set_margin_bottom(state->computed, CSS_MARGIN_SET, 0, CSS_UNIT_PX); } +css_error css__copy_margin_bottom( + const css_computed_style *from, + css_computed_style *to) +{ + css_fixed length = 0; + css_unit unit = CSS_UNIT_PX; + uint8_t type = get_margin_bottom(from, &length, &unit); + + if (from == to) { + return CSS_OK; + } + + return set_margin_bottom(to, type, length, unit); +} + css_error css__compose_margin_bottom(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) @@ -40,10 +55,8 @@ css_error css__compose_margin_bottom(const css_computed_style *parent, css_unit unit = CSS_UNIT_PX; uint8_t type = get_margin_bottom(child, &length, &unit); - if (type == CSS_MARGIN_INHERIT) { - type = get_margin_bottom(parent, &length, &unit); - } - - return set_margin_bottom(result, type, length, unit); + return css__copy_margin_bottom( + type == CSS_MARGIN_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/margin_left.c b/src/select/properties/margin_left.c index 240285a..b163fba 100644 --- a/src/select/properties/margin_left.c +++ b/src/select/properties/margin_left.c @@ -32,6 +32,21 @@ css_error css__initial_margin_left(css_select_state *state) return set_margin_left(state->computed, CSS_MARGIN_SET, 0, CSS_UNIT_PX); } +css_error css__copy_margin_left( + const css_computed_style *from, + css_computed_style *to) +{ + css_fixed length = 0; + css_unit unit = CSS_UNIT_PX; + uint8_t type = get_margin_left(from, &length, &unit); + + if (from == to) { + return CSS_OK; + } + + return set_margin_left(to, type, length, unit); +} + css_error css__compose_margin_left(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) @@ -40,10 +55,8 @@ css_error css__compose_margin_left(const css_computed_style *parent, css_unit unit = CSS_UNIT_PX; uint8_t type = get_margin_left(child, &length, &unit); - if (type == CSS_MARGIN_INHERIT) { - type = get_margin_left(parent, &length, &unit); - } - - return set_margin_left(result, type, length, unit); + return css__copy_margin_left( + type == CSS_MARGIN_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/margin_right.c b/src/select/properties/margin_right.c index 737fbee..2c15b54 100644 --- a/src/select/properties/margin_right.c +++ b/src/select/properties/margin_right.c @@ -32,6 +32,21 @@ css_error css__initial_margin_right(css_select_state *state) return set_margin_right(state->computed, CSS_MARGIN_SET, 0, CSS_UNIT_PX); } +css_error css__copy_margin_right( + const css_computed_style *from, + css_computed_style *to) +{ + css_fixed length = 0; + css_unit unit = CSS_UNIT_PX; + uint8_t type = get_margin_right(from, &length, &unit); + + if (from == to) { + return CSS_OK; + } + + return set_margin_right(to, type, length, unit); +} + css_error css__compose_margin_right(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) @@ -40,10 +55,8 @@ css_error css__compose_margin_right(const css_computed_style *parent, css_unit unit = CSS_UNIT_PX; uint8_t type = get_margin_right(child, &length, &unit); - if (type == CSS_MARGIN_INHERIT) { - type = get_margin_right(parent, &length, &unit); - } - - return set_margin_right(result, type, length, unit); + return css__copy_margin_right( + type == CSS_MARGIN_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/margin_top.c b/src/select/properties/margin_top.c index 5563a48..1df811d 100644 --- a/src/select/properties/margin_top.c +++ b/src/select/properties/margin_top.c @@ -32,6 +32,21 @@ css_error css__initial_margin_top(css_select_state *state) return set_margin_top(state->computed, CSS_MARGIN_SET, 0, CSS_UNIT_PX); } +css_error css__copy_margin_top( + const css_computed_style *from, + css_computed_style *to) +{ + css_fixed length = 0; + css_unit unit = CSS_UNIT_PX; + uint8_t type = get_margin_top(from, &length, &unit); + + if (from == to) { + return CSS_OK; + } + + return set_margin_top(to, type, length, unit); +} + css_error css__compose_margin_top(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) @@ -40,10 +55,8 @@ css_error css__compose_margin_top(const css_computed_style *parent, css_unit unit = CSS_UNIT_PX; uint8_t type = get_margin_top(child, &length, &unit); - if (type == CSS_MARGIN_INHERIT) { - type = get_margin_top(parent, &length, &unit); - } - - return set_margin_top(result, type, length, unit); + return css__copy_margin_top( + type == CSS_MARGIN_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/max_height.c b/src/select/properties/max_height.c index e03c8da..1dcf09d 100644 --- a/src/select/properties/max_height.c +++ b/src/select/properties/max_height.c @@ -33,6 +33,21 @@ css_error css__initial_max_height(css_select_state *state) 0, CSS_UNIT_PX); } +css_error css__copy_max_height( + const css_computed_style *from, + css_computed_style *to) +{ + css_fixed length = 0; + css_unit unit = CSS_UNIT_PX; + uint8_t type = get_max_height(from, &length, &unit); + + if (from == to) { + return CSS_OK; + } + + return set_max_height(to, type, length, unit); +} + css_error css__compose_max_height(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) @@ -41,10 +56,8 @@ css_error css__compose_max_height(const css_computed_style *parent, css_unit unit = CSS_UNIT_PX; uint8_t type = get_max_height(child, &length, &unit); - if (type == CSS_MAX_HEIGHT_INHERIT) { - type = get_max_height(parent, &length, &unit); - } - - return set_max_height(result, type, length, unit); + return css__copy_max_height( + type == CSS_MAX_HEIGHT_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/max_width.c b/src/select/properties/max_width.c index ec98712..11d8ade 100644 --- a/src/select/properties/max_width.c +++ b/src/select/properties/max_width.c @@ -32,6 +32,21 @@ css_error css__initial_max_width(css_select_state *state) return set_max_width(state->computed, CSS_MAX_WIDTH_NONE, 0, CSS_UNIT_PX); } +css_error css__copy_max_width( + const css_computed_style *from, + css_computed_style *to) +{ + css_fixed length = 0; + css_unit unit = CSS_UNIT_PX; + uint8_t type = get_max_width(from, &length, &unit); + + if (from == to) { + return CSS_OK; + } + + return set_max_width(to, type, length, unit); +} + css_error css__compose_max_width(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) @@ -40,10 +55,8 @@ css_error css__compose_max_width(const css_computed_style *parent, css_unit unit = CSS_UNIT_PX; uint8_t type = get_max_width(child, &length, &unit); - if (type == CSS_MAX_WIDTH_INHERIT) { - type = get_max_width(parent, &length, &unit); - } - - return set_max_width(result, type, length, unit); + return css__copy_max_width( + type == CSS_MAX_WIDTH_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/min_height.c b/src/select/properties/min_height.c index 687d8a1..d05655c 100644 --- a/src/select/properties/min_height.c +++ b/src/select/properties/min_height.c @@ -17,7 +17,7 @@ css_error css__cascade_min_height(uint32_t opv, css_style *style, css_select_state *state) { - return css__cascade_length(opv, style, state, set_min_height); + return css__cascade_length_auto(opv, style, state, set_min_height); } css_error css__set_min_height_from_hint(const css_hint *hint, @@ -29,10 +29,25 @@ css_error css__set_min_height_from_hint(const css_hint *hint, css_error css__initial_min_height(css_select_state *state) { - return set_min_height(state->computed, CSS_MIN_HEIGHT_SET, + return set_min_height(state->computed, CSS_MIN_HEIGHT_AUTO, 0, CSS_UNIT_PX); } +css_error css__copy_min_height( + const css_computed_style *from, + css_computed_style *to) +{ + css_fixed length = 0; + css_unit unit = CSS_UNIT_PX; + uint8_t type = get_min_height(from, &length, &unit); + + if (from == to) { + return CSS_OK; + } + + return set_min_height(to, type, length, unit); +} + css_error css__compose_min_height(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) @@ -41,10 +56,8 @@ css_error css__compose_min_height(const css_computed_style *parent, css_unit unit = CSS_UNIT_PX; uint8_t type = get_min_height(child, &length, &unit); - if (type == CSS_MIN_HEIGHT_INHERIT) { - type = get_min_height(parent, &length, &unit); - } - - return set_min_height(result, type, length, unit); + return css__copy_min_height( + type == CSS_MIN_HEIGHT_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/min_width.c b/src/select/properties/min_width.c index 5365588..af709d3 100644 --- a/src/select/properties/min_width.c +++ b/src/select/properties/min_width.c @@ -17,7 +17,7 @@ css_error css__cascade_min_width(uint32_t opv, css_style *style, css_select_state *state) { - return css__cascade_length(opv, style, state, set_min_width); + return css__cascade_length_auto(opv, style, state, set_min_width); } css_error css__set_min_width_from_hint(const css_hint *hint, @@ -29,7 +29,23 @@ css_error css__set_min_width_from_hint(const css_hint *hint, css_error css__initial_min_width(css_select_state *state) { - return set_min_width(state->computed, CSS_MIN_WIDTH_SET, 0, CSS_UNIT_PX); + return set_min_width(state->computed, CSS_MIN_WIDTH_AUTO, + 0, CSS_UNIT_PX); +} + +css_error css__copy_min_width( + const css_computed_style *from, + css_computed_style *to) +{ + css_fixed length = 0; + css_unit unit = CSS_UNIT_PX; + uint8_t type = get_min_width(from, &length, &unit); + + if (from == to) { + return CSS_OK; + } + + return set_min_width(to, type, length, unit); } css_error css__compose_min_width(const css_computed_style *parent, @@ -40,10 +56,8 @@ css_error css__compose_min_width(const css_computed_style *parent, css_unit unit = CSS_UNIT_PX; uint8_t type = get_min_width(child, &length, &unit); - if (type == CSS_MIN_WIDTH_INHERIT) { - type = get_min_width(parent, &length, &unit); - } - - return set_min_width(result, type, length, unit); + return css__copy_min_width( + type == CSS_MIN_WIDTH_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/opacity.c b/src/select/properties/opacity.c index aadab0b..3e875f9 100644 --- a/src/select/properties/opacity.c +++ b/src/select/properties/opacity.c @@ -20,15 +20,15 @@ css_error css__cascade_opacity(uint32_t opv, css_style *style, uint16_t value = CSS_OPACITY_INHERIT; css_fixed opacity = 0; - if (isInherit(opv) == false) { - value = CSS_Z_INDEX_SET; + if (hasFlagValue(opv) == false) { + value = CSS_OPACITY_SET; opacity = *((css_fixed *) style->bytecode); advance_bytecode(style, sizeof(opacity)); } if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { return set_opacity(state->computed, value, opacity); } @@ -46,6 +46,20 @@ css_error css__initial_opacity(css_select_state *state) return set_opacity(state->computed, CSS_OPACITY_SET, INTTOFIX(1)); } +css_error css__copy_opacity( + const css_computed_style *from, + css_computed_style *to) +{ + css_fixed opacity = 0; + uint8_t type = get_opacity(from, &opacity); + + if (from == to) { + return CSS_OK; + } + + return set_opacity(to, type, opacity); +} + css_error css__compose_opacity(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) @@ -53,10 +67,8 @@ css_error css__compose_opacity(const css_computed_style *parent, css_fixed opacity = 0; uint8_t type = get_opacity(child, &opacity); - if (type == CSS_OPACITY_INHERIT) { - type = get_opacity(parent, &opacity); - } - - return set_opacity(result, type, opacity); + return css__copy_opacity( + type == CSS_OPACITY_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/order.c b/src/select/properties/order.c new file mode 100644 index 0000000..4004c0e --- /dev/null +++ b/src/select/properties/order.c @@ -0,0 +1,74 @@ +/* + * This file is part of LibCSS + * Licensed under the MIT License, + * http://www.opensource.org/licenses/mit-license.php + * Copyright 2017 Lucas Neves <lcneves@gmail.com> + */ + +#include "bytecode/bytecode.h" +#include "bytecode/opcodes.h" +#include "select/propset.h" +#include "select/propget.h" +#include "utils/utils.h" + +#include "select/properties/properties.h" +#include "select/properties/helpers.h" + +css_error css__cascade_order(uint32_t opv, css_style *style, + css_select_state *state) +{ + uint16_t value = CSS_ORDER_INHERIT; + css_fixed order = 0; + + if (hasFlagValue(opv) == false) { + value = CSS_ORDER_SET; + + order = FIXTOINT(*((css_fixed *) style->bytecode)); + advance_bytecode(style, sizeof(order)); + } + + if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, + getFlagValue(opv))) { + return set_order(state->computed, value, order); + } + + return CSS_OK; +} + +css_error css__set_order_from_hint(const css_hint *hint, + css_computed_style *style) +{ + return set_order(style, hint->status, hint->data.integer); +} + +css_error css__initial_order(css_select_state *state) +{ + return set_order(state->computed, CSS_ORDER_SET, 0); +} + +css_error css__copy_order( + const css_computed_style *from, + css_computed_style *to) +{ + int32_t order = 0; + uint8_t type = get_order(from, &order); + + if (from == to) { + return CSS_OK; + } + + return set_order(to, type, order); +} + +css_error css__compose_order(const css_computed_style *parent, + const css_computed_style *child, + css_computed_style *result) +{ + int32_t order = 0; + uint8_t type = get_order(child, &order); + + return css__copy_order( + type == CSS_ORDER_INHERIT ? parent : child, + result); +} + diff --git a/src/select/properties/orphans.c b/src/select/properties/orphans.c index f169b81..b0fee43 100644 --- a/src/select/properties/orphans.c +++ b/src/select/properties/orphans.c @@ -31,6 +31,20 @@ css_error css__initial_orphans(css_select_state *state) return set_orphans(state->computed, CSS_ORPHANS_SET, 2); } +css_error css__copy_orphans( + const css_computed_style *from, + css_computed_style *to) +{ + int32_t count = 0; + uint8_t type = get_orphans(from, &count); + + if (from == to) { + return CSS_OK; + } + + return set_orphans(to, type, count); +} + css_error css__compose_orphans(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) @@ -38,10 +52,8 @@ css_error css__compose_orphans(const css_computed_style *parent, int32_t count = 0; uint8_t type = get_orphans(child, &count); - if (type == CSS_ORPHANS_INHERIT) { - type = get_orphans(parent, &count); - } - - return set_orphans(result, type, count); + return css__copy_orphans( + type == CSS_ORPHANS_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/outline_color.c b/src/select/properties/outline_color.c index c6c576b..359960f 100644 --- a/src/select/properties/outline_color.c +++ b/src/select/properties/outline_color.c @@ -20,7 +20,7 @@ css_error css__cascade_outline_color(uint32_t opv, css_style *style, uint16_t value = CSS_OUTLINE_COLOR_INHERIT; css_color color = 0; - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case OUTLINE_COLOR_TRANSPARENT: value = CSS_OUTLINE_COLOR_COLOR; @@ -40,7 +40,7 @@ css_error css__cascade_outline_color(uint32_t opv, css_style *style, } if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { return set_outline_color(state->computed, value, color); } @@ -58,6 +58,20 @@ css_error css__initial_outline_color(css_select_state *state) return set_outline_color(state->computed, CSS_OUTLINE_COLOR_INVERT, 0); } +css_error css__copy_outline_color( + const css_computed_style *from, + css_computed_style *to) +{ + css_color color = 0; + uint8_t type = get_outline_color(from, &color); + + if (from == to) { + return CSS_OK; + } + + return set_outline_color(to, type, color); +} + css_error css__compose_outline_color(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) @@ -65,17 +79,7 @@ css_error css__compose_outline_color(const css_computed_style *parent, css_color color = 0; uint8_t type = get_outline_color(child, &color); - if ((child->i.uncommon == NULL && parent->i.uncommon != NULL) || - type == CSS_OUTLINE_COLOR_INHERIT || - (child->i.uncommon != NULL && result != child)) { - if ((child->i.uncommon == NULL && parent->i.uncommon != NULL) || - type == CSS_OUTLINE_COLOR_INHERIT) { - type = get_outline_color(parent, &color); - } - - return set_outline_color(result, type, color); - } - - return CSS_OK; + return css__copy_outline_color( + type == CSS_OUTLINE_COLOR_INHERIT ? parent : child, + result); } - diff --git a/src/select/properties/outline_style.c b/src/select/properties/outline_style.c index 5c30735..acdab03 100644 --- a/src/select/properties/outline_style.c +++ b/src/select/properties/outline_style.c @@ -31,16 +31,25 @@ css_error css__initial_outline_style(css_select_state *state) return set_outline_style(state->computed, CSS_OUTLINE_STYLE_NONE); } +css_error css__copy_outline_style( + const css_computed_style *from, + css_computed_style *to) +{ + if (from == to) { + return CSS_OK; + } + + return set_outline_style(to, get_outline_style(from)); +} + css_error css__compose_outline_style(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) { uint8_t type = get_outline_style(child); - if (type == CSS_OUTLINE_STYLE_INHERIT) { - type = get_outline_style(parent); - } - - return set_outline_style(result, type); + return css__copy_outline_style( + type == CSS_OUTLINE_STYLE_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/outline_width.c b/src/select/properties/outline_width.c index 4d9101c..dbc0298 100644 --- a/src/select/properties/outline_width.c +++ b/src/select/properties/outline_width.c @@ -33,6 +33,21 @@ css_error css__initial_outline_width(css_select_state *state) 0, CSS_UNIT_PX); } +css_error css__copy_outline_width( + const css_computed_style *from, + css_computed_style *to) +{ + css_fixed length = 0; + css_unit unit = CSS_UNIT_PX; + uint8_t type = get_outline_width(from, &length, &unit); + + if (from == to) { + return CSS_OK; + } + + return set_outline_width(to, type, length, unit); +} + css_error css__compose_outline_width(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) @@ -41,17 +56,8 @@ css_error css__compose_outline_width(const css_computed_style *parent, css_unit unit = CSS_UNIT_PX; uint8_t type = get_outline_width(child, &length, &unit); - if ((child->i.uncommon == NULL && parent->i.uncommon != NULL) || - type == CSS_OUTLINE_WIDTH_INHERIT || - (child->i.uncommon != NULL && result != child)) { - if ((child->i.uncommon == NULL && parent->i.uncommon != NULL) || - type == CSS_OUTLINE_WIDTH_INHERIT) { - type = get_outline_width(parent, &length, &unit); - } - - return set_outline_width(result, type, length, unit); - } - - return CSS_OK; + return css__copy_outline_width( + type == CSS_OUTLINE_WIDTH_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/overflow_x.c b/src/select/properties/overflow_x.c index 817d1d2..98dfba5 100644 --- a/src/select/properties/overflow_x.c +++ b/src/select/properties/overflow_x.c @@ -21,7 +21,7 @@ css_error css__cascade_overflow_x(uint32_t opv, css_style *style, UNUSED(style); - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case OVERFLOW_VISIBLE: value = CSS_OVERFLOW_VISIBLE; @@ -39,7 +39,7 @@ css_error css__cascade_overflow_x(uint32_t opv, css_style *style, } if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { return set_overflow_x(state->computed, value); } @@ -57,16 +57,25 @@ css_error css__initial_overflow_x(css_select_state *state) return set_overflow_x(state->computed, CSS_OVERFLOW_VISIBLE); } +css_error css__copy_overflow_x( + const css_computed_style *from, + css_computed_style *to) +{ + if (from == to) { + return CSS_OK; + } + + return set_overflow_x(to, get_overflow_x(from)); +} + css_error css__compose_overflow_x(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) { uint8_t type = get_overflow_x(child); - if (type == CSS_OVERFLOW_INHERIT) { - type = get_overflow_x(parent); - } - - return set_overflow_x(result, type); + return css__copy_overflow_x( + type == CSS_OVERFLOW_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/overflow_y.c b/src/select/properties/overflow_y.c index b54c4c8..d7795a2 100644 --- a/src/select/properties/overflow_y.c +++ b/src/select/properties/overflow_y.c @@ -21,7 +21,7 @@ css_error css__cascade_overflow_y(uint32_t opv, css_style *style, UNUSED(style); - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case OVERFLOW_VISIBLE: value = CSS_OVERFLOW_VISIBLE; @@ -39,7 +39,7 @@ css_error css__cascade_overflow_y(uint32_t opv, css_style *style, } if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { return set_overflow_y(state->computed, value); } @@ -57,16 +57,25 @@ css_error css__initial_overflow_y(css_select_state *state) return set_overflow_y(state->computed, CSS_OVERFLOW_VISIBLE); } +css_error css__copy_overflow_y( + const css_computed_style *from, + css_computed_style *to) +{ + if (from == to) { + return CSS_OK; + } + + return set_overflow_y(to, get_overflow_y(from)); +} + css_error css__compose_overflow_y(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) { uint8_t type = get_overflow_y(child); - if (type == CSS_OVERFLOW_INHERIT) { - type = get_overflow_y(parent); - } - - return set_overflow_y(result, type); + return css__copy_overflow_y( + type == CSS_OVERFLOW_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/padding_bottom.c b/src/select/properties/padding_bottom.c index e3b36f7..53c749c 100644 --- a/src/select/properties/padding_bottom.c +++ b/src/select/properties/padding_bottom.c @@ -33,6 +33,21 @@ css_error css__initial_padding_bottom(css_select_state *state) 0, CSS_UNIT_PX); } +css_error css__copy_padding_bottom( + const css_computed_style *from, + css_computed_style *to) +{ + css_fixed length = 0; + css_unit unit = CSS_UNIT_PX; + uint8_t type = get_padding_bottom(from, &length, &unit); + + if (from == to) { + return CSS_OK; + } + + return set_padding_bottom(to, type, length, unit); +} + css_error css__compose_padding_bottom(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) @@ -41,10 +56,8 @@ css_error css__compose_padding_bottom(const css_computed_style *parent, css_unit unit = CSS_UNIT_PX; uint8_t type = get_padding_bottom(child, &length, &unit); - if (type == CSS_PADDING_INHERIT) { - type = get_padding_bottom(parent, &length, &unit); - } - - return set_padding_bottom(result, type, length, unit); + return css__copy_padding_bottom( + type == CSS_PADDING_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/padding_left.c b/src/select/properties/padding_left.c index bdea11e..b61ca83 100644 --- a/src/select/properties/padding_left.c +++ b/src/select/properties/padding_left.c @@ -32,6 +32,21 @@ css_error css__initial_padding_left(css_select_state *state) return set_padding_left(state->computed, CSS_PADDING_SET, 0, CSS_UNIT_PX); } +css_error css__copy_padding_left( + const css_computed_style *from, + css_computed_style *to) +{ + css_fixed length = 0; + css_unit unit = CSS_UNIT_PX; + uint8_t type = get_padding_left(from, &length, &unit); + + if (from == to) { + return CSS_OK; + } + + return set_padding_left(to, type, length, unit); +} + css_error css__compose_padding_left(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) @@ -40,10 +55,8 @@ css_error css__compose_padding_left(const css_computed_style *parent, css_unit unit = CSS_UNIT_PX; uint8_t type = get_padding_left(child, &length, &unit); - if (type == CSS_PADDING_INHERIT) { - type = get_padding_left(parent, &length, &unit); - } - - return set_padding_left(result, type, length, unit); + return css__copy_padding_left( + type == CSS_PADDING_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/padding_right.c b/src/select/properties/padding_right.c index 82c1ed3..35417d6 100644 --- a/src/select/properties/padding_right.c +++ b/src/select/properties/padding_right.c @@ -33,6 +33,21 @@ css_error css__initial_padding_right(css_select_state *state) 0, CSS_UNIT_PX); } +css_error css__copy_padding_right( + const css_computed_style *from, + css_computed_style *to) +{ + css_fixed length = 0; + css_unit unit = CSS_UNIT_PX; + uint8_t type = get_padding_right(from, &length, &unit); + + if (from == to) { + return CSS_OK; + } + + return set_padding_right(to, type, length, unit); +} + css_error css__compose_padding_right(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) @@ -41,10 +56,8 @@ css_error css__compose_padding_right(const css_computed_style *parent, css_unit unit = CSS_UNIT_PX; uint8_t type = get_padding_right(child, &length, &unit); - if (type == CSS_PADDING_INHERIT) { - type = get_padding_right(parent, &length, &unit); - } - - return set_padding_right(result, type, length, unit); + return css__copy_padding_right( + type == CSS_PADDING_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/padding_top.c b/src/select/properties/padding_top.c index f6d8b3e..a2cec95 100644 --- a/src/select/properties/padding_top.c +++ b/src/select/properties/padding_top.c @@ -32,6 +32,21 @@ css_error css__initial_padding_top(css_select_state *state) return set_padding_top(state->computed, CSS_PADDING_SET, 0, CSS_UNIT_PX); } +css_error css__copy_padding_top( + const css_computed_style *from, + css_computed_style *to) +{ + css_fixed length = 0; + css_unit unit = CSS_UNIT_PX; + uint8_t type = get_padding_top(from, &length, &unit); + + if (from == to) { + return CSS_OK; + } + + return set_padding_top(to, type, length, unit); +} + css_error css__compose_padding_top(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) @@ -40,10 +55,8 @@ css_error css__compose_padding_top(const css_computed_style *parent, css_unit unit = CSS_UNIT_PX; uint8_t type = get_padding_top(child, &length, &unit); - if (type == CSS_PADDING_INHERIT) { - type = get_padding_top(parent, &length, &unit); - } - - return set_padding_top(result, type, length, unit); + return css__copy_padding_top( + type == CSS_PADDING_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/page_break_after.c b/src/select/properties/page_break_after.c index fdb6774..4065a17 100644 --- a/src/select/properties/page_break_after.c +++ b/src/select/properties/page_break_after.c @@ -33,16 +33,25 @@ css_error css__initial_page_break_after(css_select_state *state) CSS_PAGE_BREAK_AFTER_AUTO); } +css_error css__copy_page_break_after( + const css_computed_style *from, + css_computed_style *to) +{ + if (from == to) { + return CSS_OK; + } + + return set_page_break_after(to, get_page_break_after(from)); +} + css_error css__compose_page_break_after(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) { uint8_t type = get_page_break_after(child); - if (type == CSS_PAGE_BREAK_AFTER_INHERIT) { - type = get_page_break_after(parent); - } - - return set_page_break_after(result, type); + return css__copy_page_break_after( + type == CSS_PAGE_BREAK_AFTER_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/page_break_before.c b/src/select/properties/page_break_before.c index 1491997..d8fdd93 100644 --- a/src/select/properties/page_break_before.c +++ b/src/select/properties/page_break_before.c @@ -33,15 +33,24 @@ css_error css__initial_page_break_before(css_select_state *state) CSS_PAGE_BREAK_BEFORE_AUTO); } +css_error css__copy_page_break_before( + const css_computed_style *from, + css_computed_style *to) +{ + if (from == to) { + return CSS_OK; + } + + return set_page_break_before(to, get_page_break_before(from)); +} + css_error css__compose_page_break_before(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) { uint8_t type = get_page_break_before(child); - if (type == CSS_PAGE_BREAK_BEFORE_INHERIT) { - type = get_page_break_before(parent); - } - - return set_page_break_before(result, type); + return css__copy_page_break_before( + type == CSS_PAGE_BREAK_BEFORE_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/page_break_inside.c b/src/select/properties/page_break_inside.c index ddcb19f..8655c40 100644 --- a/src/select/properties/page_break_inside.c +++ b/src/select/properties/page_break_inside.c @@ -33,16 +33,25 @@ css_error css__initial_page_break_inside(css_select_state *state) CSS_PAGE_BREAK_INSIDE_AUTO); } +css_error css__copy_page_break_inside( + const css_computed_style *from, + css_computed_style *to) +{ + if (from == to) { + return CSS_OK; + } + + return set_page_break_inside(to, get_page_break_inside(from)); +} + css_error css__compose_page_break_inside(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) { uint8_t type = get_page_break_inside(child); - if (type == CSS_PAGE_BREAK_INSIDE_INHERIT) { - type = get_page_break_inside(parent); - } - - return set_page_break_inside(result, type); + return css__copy_page_break_inside( + type == CSS_PAGE_BREAK_INSIDE_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/pause_after.c b/src/select/properties/pause_after.c index 16bbefe..b8bf968 100644 --- a/src/select/properties/pause_after.c +++ b/src/select/properties/pause_after.c @@ -37,6 +37,16 @@ css_error css__initial_pause_after(css_select_state *state) return CSS_OK; } +css_error css__copy_pause_after( + const css_computed_style *from, + css_computed_style *to) +{ + UNUSED(from); + UNUSED(to); + + return CSS_OK; +} + css_error css__compose_pause_after(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) diff --git a/src/select/properties/pause_before.c b/src/select/properties/pause_before.c index 7770615..74cb565 100644 --- a/src/select/properties/pause_before.c +++ b/src/select/properties/pause_before.c @@ -37,6 +37,16 @@ css_error css__initial_pause_before(css_select_state *state) return CSS_OK; } +css_error css__copy_pause_before( + const css_computed_style *from, + css_computed_style *to) +{ + UNUSED(from); + UNUSED(to); + + return CSS_OK; +} + css_error css__compose_pause_before(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) diff --git a/src/select/properties/pitch.c b/src/select/properties/pitch.c index c5484d9..c0c5c88 100644 --- a/src/select/properties/pitch.c +++ b/src/select/properties/pitch.c @@ -20,7 +20,7 @@ css_error css__cascade_pitch(uint32_t opv, css_style *style, css_fixed freq = 0; uint32_t unit = UNIT_HZ; - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case PITCH_FREQUENCY: freq = *((css_fixed *) style->bytecode); @@ -41,7 +41,7 @@ css_error css__cascade_pitch(uint32_t opv, css_style *style, unit = css__to_css_unit(unit); if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { /** \todo pitch */ } @@ -64,6 +64,16 @@ css_error css__initial_pitch(css_select_state *state) return CSS_OK; } +css_error css__copy_pitch( + const css_computed_style *from, + css_computed_style *to) +{ + UNUSED(from); + UNUSED(to); + + return CSS_OK; +} + css_error css__compose_pitch(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) diff --git a/src/select/properties/pitch_range.c b/src/select/properties/pitch_range.c index 52a5751..c8f7526 100644 --- a/src/select/properties/pitch_range.c +++ b/src/select/properties/pitch_range.c @@ -37,6 +37,16 @@ css_error css__initial_pitch_range(css_select_state *state) return CSS_OK; } +css_error css__copy_pitch_range( + const css_computed_style *from, + css_computed_style *to) +{ + UNUSED(from); + UNUSED(to); + + return CSS_OK; +} + css_error css__compose_pitch_range(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) diff --git a/src/select/properties/play_during.c b/src/select/properties/play_during.c index 413d75a..0f38f74 100644 --- a/src/select/properties/play_during.c +++ b/src/select/properties/play_during.c @@ -19,7 +19,7 @@ css_error css__cascade_play_during(uint32_t opv, css_style *style, { lwc_string *uri = NULL; - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case PLAY_DURING_URI: css__stylesheet_string_get(style->sheet, *((css_code_t *) style->bytecode), &uri); @@ -35,7 +35,7 @@ css_error css__cascade_play_during(uint32_t opv, css_style *style, } if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { /** \todo play-during */ } @@ -58,6 +58,16 @@ css_error css__initial_play_during(css_select_state *state) return CSS_OK; } +css_error css__copy_play_during( + const css_computed_style *from, + css_computed_style *to) +{ + UNUSED(from); + UNUSED(to); + + return CSS_OK; +} + css_error css__compose_play_during(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) diff --git a/src/select/properties/position.c b/src/select/properties/position.c index 9f9658f..cc4b3e7 100644 --- a/src/select/properties/position.c +++ b/src/select/properties/position.c @@ -21,7 +21,7 @@ css_error css__cascade_position(uint32_t opv, css_style *style, UNUSED(style); - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case POSITION_STATIC: value = CSS_POSITION_STATIC; @@ -35,11 +35,14 @@ css_error css__cascade_position(uint32_t opv, css_style *style, case POSITION_FIXED: value = CSS_POSITION_FIXED; break; + case POSITION_STICKY: + value = CSS_POSITION_STICKY; + break; } } if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { return set_position(state->computed, value); } @@ -57,16 +60,25 @@ css_error css__initial_position(css_select_state *state) return set_position(state->computed, CSS_POSITION_STATIC); } +css_error css__copy_position( + const css_computed_style *from, + css_computed_style *to) +{ + if (from == to) { + return CSS_OK; + } + + return set_position(to, get_position(from)); +} + css_error css__compose_position(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) { uint8_t type = get_position(child); - if (type == CSS_POSITION_INHERIT) { - type = get_position(parent); - } - - return set_position(result, type); + return css__copy_position( + type == CSS_POSITION_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/properties.h b/src/select/properties/properties.h index a1ab49f..cb0b213 100644 --- a/src/select/properties/properties.h +++ b/src/select/properties/properties.h @@ -18,9 +18,13 @@ css_error css__cascade_##pname (uint32_t opv, css_style *style, css_select_state *state); \ css_error css__set_##pname##_from_hint(const css_hint *hint, css_computed_style *style); \ css_error css__initial_##pname (css_select_state *state); \ + css_error css__copy_##pname (const css_computed_style *from, css_computed_style *to); \ css_error css__compose_##pname (const css_computed_style *parent, const css_computed_style *child, css_computed_style *result); \ uint32_t destroy_##pname (void *bytecode) +PROPERTY_FUNCS(align_content); +PROPERTY_FUNCS(align_items); +PROPERTY_FUNCS(align_self); PROPERTY_FUNCS(azimuth); PROPERTY_FUNCS(background_attachment); PROPERTY_FUNCS(background_color); @@ -68,6 +72,12 @@ PROPERTY_FUNCS(direction); PROPERTY_FUNCS(display); PROPERTY_FUNCS(elevation); PROPERTY_FUNCS(empty_cells); +PROPERTY_FUNCS(fill_opacity); +PROPERTY_FUNCS(flex_basis); +PROPERTY_FUNCS(flex_direction); +PROPERTY_FUNCS(flex_grow); +PROPERTY_FUNCS(flex_shrink); +PROPERTY_FUNCS(flex_wrap); PROPERTY_FUNCS(float); PROPERTY_FUNCS(font_family); PROPERTY_FUNCS(font_size); @@ -75,6 +85,7 @@ PROPERTY_FUNCS(font_style); PROPERTY_FUNCS(font_variant); PROPERTY_FUNCS(font_weight); PROPERTY_FUNCS(height); +PROPERTY_FUNCS(justify_content); PROPERTY_FUNCS(left); PROPERTY_FUNCS(letter_spacing); PROPERTY_FUNCS(line_height); @@ -90,6 +101,7 @@ PROPERTY_FUNCS(max_width); PROPERTY_FUNCS(min_height); PROPERTY_FUNCS(min_width); PROPERTY_FUNCS(opacity); +PROPERTY_FUNCS(order); PROPERTY_FUNCS(orphans); PROPERTY_FUNCS(outline_color); PROPERTY_FUNCS(outline_style); @@ -118,6 +130,7 @@ PROPERTY_FUNCS(speak_punctuation); PROPERTY_FUNCS(speak); PROPERTY_FUNCS(speech_rate); PROPERTY_FUNCS(stress); +PROPERTY_FUNCS(stroke_opacity); PROPERTY_FUNCS(table_layout); PROPERTY_FUNCS(text_align); PROPERTY_FUNCS(text_decoration); diff --git a/src/select/properties/quotes.c b/src/select/properties/quotes.c index 4144d8e..57fc48c 100644 --- a/src/select/properties/quotes.c +++ b/src/select/properties/quotes.c @@ -21,7 +21,7 @@ css_error css__cascade_quotes(uint32_t opv, css_style *style, lwc_string **quotes = NULL; uint32_t n_quotes = 0; - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { uint32_t v = getValue(opv); value = CSS_QUOTES_STRING; @@ -75,7 +75,7 @@ css_error css__cascade_quotes(uint32_t opv, css_style *style, } if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { css_error error; error = set_quotes(state->computed, value, quotes); @@ -123,43 +123,41 @@ css_error css__initial_quotes(css_select_state *state) return css__set_quotes_from_hint(&hint, state->computed); } -css_error css__compose_quotes(const css_computed_style *parent, - const css_computed_style *child, - css_computed_style *result) +css_error css__copy_quotes( + const css_computed_style *from, + css_computed_style *to) { css_error error; + lwc_string **copy = NULL; lwc_string **quotes = NULL; - uint8_t type = get_quotes(child, "es); - - if (type == CSS_QUOTES_INHERIT || result != child) { - size_t n_quotes = 0; - lwc_string **copy = NULL; - - if (type == CSS_QUOTES_INHERIT) { - type = get_quotes(parent, "es); - } - - if (quotes != NULL) { - lwc_string **i; + uint8_t type = get_quotes(from, "es); - for (i = quotes; (*i) != NULL; i++) - n_quotes++; + if (from == to) { + return CSS_OK; + } - copy = malloc((n_quotes + 1) * sizeof(lwc_string *)); - if (copy == NULL) - return CSS_NOMEM; + error = css__copy_lwc_string_array(false, quotes, ©); + if (error != CSS_OK) { + return CSS_NOMEM; + } - memcpy(copy, quotes, (n_quotes + 1) * - sizeof(lwc_string *)); - } + error = set_quotes(to, type, copy); + if (error != CSS_OK) { + free(copy); + } - error = set_quotes(result, type, copy); - if (error != CSS_OK && copy != NULL) - free(copy); + return error; +} - return error; - } +css_error css__compose_quotes(const css_computed_style *parent, + const css_computed_style *child, + css_computed_style *result) +{ + lwc_string **quotes = NULL; + uint8_t type = get_quotes(child, "es); - return CSS_OK; + return css__copy_quotes( + type == CSS_QUOTES_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/richness.c b/src/select/properties/richness.c index 9656486..cd62d5c 100644 --- a/src/select/properties/richness.c +++ b/src/select/properties/richness.c @@ -37,6 +37,16 @@ css_error css__initial_richness(css_select_state *state) return CSS_OK; } +css_error css__copy_richness( + const css_computed_style *from, + css_computed_style *to) +{ + UNUSED(from); + UNUSED(to); + + return CSS_OK; +} + css_error css__compose_richness(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) diff --git a/src/select/properties/right.c b/src/select/properties/right.c index 142e7e8..ee4f4a0 100644 --- a/src/select/properties/right.c +++ b/src/select/properties/right.c @@ -32,6 +32,21 @@ css_error css__initial_right(css_select_state *state) return set_right(state->computed, CSS_RIGHT_AUTO, 0, CSS_UNIT_PX); } +css_error css__copy_right( + const css_computed_style *from, + css_computed_style *to) +{ + css_fixed length = 0; + css_unit unit = CSS_UNIT_PX; + uint8_t type = get_right(from, &length, &unit); + + if (from == to) { + return CSS_OK; + } + + return set_right(to, type, length, unit); +} + css_error css__compose_right(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) @@ -40,10 +55,8 @@ css_error css__compose_right(const css_computed_style *parent, css_unit unit = CSS_UNIT_PX; uint8_t type = get_right(child, &length, &unit); - if (type == CSS_RIGHT_INHERIT) { - type = get_right(parent, &length, &unit); - } - - return set_right(result, type, length, unit); + return css__copy_right( + type == CSS_RIGHT_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/speak.c b/src/select/properties/speak.c index eb5528b..7b0d014 100644 --- a/src/select/properties/speak.c +++ b/src/select/properties/speak.c @@ -19,7 +19,7 @@ css_error css__cascade_speak(uint32_t opv, css_style *style, { UNUSED(style); - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case SPEAK_NORMAL: case SPEAK_NONE: @@ -30,7 +30,7 @@ css_error css__cascade_speak(uint32_t opv, css_style *style, } if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { /** \todo speak */ } @@ -53,6 +53,16 @@ css_error css__initial_speak(css_select_state *state) return CSS_OK; } +css_error css__copy_speak( + const css_computed_style *from, + css_computed_style *to) +{ + UNUSED(from); + UNUSED(to); + + return CSS_OK; +} + css_error css__compose_speak(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) diff --git a/src/select/properties/speak_header.c b/src/select/properties/speak_header.c index 0935528..88ad0d7 100644 --- a/src/select/properties/speak_header.c +++ b/src/select/properties/speak_header.c @@ -19,7 +19,7 @@ css_error css__cascade_speak_header(uint32_t opv, css_style *style, { UNUSED(style); - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case SPEAK_HEADER_ONCE: case SPEAK_HEADER_ALWAYS: @@ -29,7 +29,7 @@ css_error css__cascade_speak_header(uint32_t opv, css_style *style, } if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { /** \todo speak-header */ } @@ -52,6 +52,16 @@ css_error css__initial_speak_header(css_select_state *state) return CSS_OK; } +css_error css__copy_speak_header( + const css_computed_style *from, + css_computed_style *to) +{ + UNUSED(from); + UNUSED(to); + + return CSS_OK; +} + css_error css__compose_speak_header(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) diff --git a/src/select/properties/speak_numeral.c b/src/select/properties/speak_numeral.c index fc54caf..1cd6e98 100644 --- a/src/select/properties/speak_numeral.c +++ b/src/select/properties/speak_numeral.c @@ -19,7 +19,7 @@ css_error css__cascade_speak_numeral(uint32_t opv, css_style *style, { UNUSED(style); - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case SPEAK_NUMERAL_DIGITS: case SPEAK_NUMERAL_CONTINUOUS: @@ -29,7 +29,7 @@ css_error css__cascade_speak_numeral(uint32_t opv, css_style *style, } if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { /** \todo speak-numeral */ } @@ -52,6 +52,16 @@ css_error css__initial_speak_numeral(css_select_state *state) return CSS_OK; } +css_error css__copy_speak_numeral( + const css_computed_style *from, + css_computed_style *to) +{ + UNUSED(from); + UNUSED(to); + + return CSS_OK; +} + css_error css__compose_speak_numeral(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) diff --git a/src/select/properties/speak_punctuation.c b/src/select/properties/speak_punctuation.c index 67cbdaf..916d530 100644 --- a/src/select/properties/speak_punctuation.c +++ b/src/select/properties/speak_punctuation.c @@ -19,7 +19,7 @@ css_error css__cascade_speak_punctuation( { UNUSED(style); - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case SPEAK_PUNCTUATION_CODE: case SPEAK_PUNCTUATION_NONE: @@ -29,7 +29,7 @@ css_error css__cascade_speak_punctuation( } if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { /** \todo speak-punctuation */ } @@ -52,6 +52,16 @@ css_error css__initial_speak_punctuation(css_select_state *state) return CSS_OK; } +css_error css__copy_speak_punctuation( + const css_computed_style *from, + css_computed_style *to) +{ + UNUSED(from); + UNUSED(to); + + return CSS_OK; +} + css_error css__compose_speak_punctuation(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) diff --git a/src/select/properties/speech_rate.c b/src/select/properties/speech_rate.c index 5cec19b..296c248 100644 --- a/src/select/properties/speech_rate.c +++ b/src/select/properties/speech_rate.c @@ -19,7 +19,7 @@ css_error css__cascade_speech_rate(uint32_t opv, css_style *style, { css_fixed rate = 0; - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case SPEECH_RATE_SET: rate = *((css_fixed *) style->bytecode); @@ -38,7 +38,7 @@ css_error css__cascade_speech_rate(uint32_t opv, css_style *style, } if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { /** \todo speech-rate */ } @@ -61,6 +61,16 @@ css_error css__initial_speech_rate(css_select_state *state) return CSS_OK; } +css_error css__copy_speech_rate( + const css_computed_style *from, + css_computed_style *to) +{ + UNUSED(from); + UNUSED(to); + + return CSS_OK; +} + css_error css__compose_speech_rate(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) diff --git a/src/select/properties/stress.c b/src/select/properties/stress.c index c9d61dd..0320fd0 100644 --- a/src/select/properties/stress.c +++ b/src/select/properties/stress.c @@ -37,6 +37,16 @@ css_error css__initial_stress(css_select_state *state) return CSS_OK; } +css_error css__copy_stress( + const css_computed_style *from, + css_computed_style *to) +{ + UNUSED(from); + UNUSED(to); + + return CSS_OK; +} + css_error css__compose_stress(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) diff --git a/src/select/properties/stroke_opacity.c b/src/select/properties/stroke_opacity.c new file mode 100644 index 0000000..c27e127 --- /dev/null +++ b/src/select/properties/stroke_opacity.c @@ -0,0 +1,73 @@ +/* + * This file is part of LibCSS + * Licensed under the MIT License, + * http://www.opensource.org/licenses/mit-license.php + */ + +#include "bytecode/bytecode.h" +#include "bytecode/opcodes.h" +#include "select/propset.h" +#include "select/propget.h" +#include "utils/utils.h" + +#include "select/properties/properties.h" +#include "select/properties/helpers.h" + +css_error css__cascade_stroke_opacity(uint32_t opv, css_style *style, + css_select_state *state) +{ + uint16_t value = CSS_STROKE_OPACITY_INHERIT; + css_fixed stroke_opacity = 0; + + if (hasFlagValue(opv) == false) { + value = CSS_STROKE_OPACITY_SET; + + stroke_opacity = *((css_fixed *) style->bytecode); + advance_bytecode(style, sizeof(stroke_opacity)); + } + + if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, + getFlagValue(opv))) { + return set_stroke_opacity(state->computed, value, stroke_opacity); + } + + return CSS_OK; +} + +css_error css__set_stroke_opacity_from_hint(const css_hint *hint, + css_computed_style *style) +{ + return set_stroke_opacity(style, hint->status, hint->data.fixed); +} + +css_error css__initial_stroke_opacity(css_select_state *state) +{ + return set_stroke_opacity(state->computed, CSS_STROKE_OPACITY_SET, INTTOFIX(1)); +} + +css_error css__copy_stroke_opacity( + const css_computed_style *from, + css_computed_style *to) +{ + css_fixed stroke_opacity = 0; + uint8_t type = get_stroke_opacity(from, &stroke_opacity); + + if (from == to) { + return CSS_OK; + } + + return set_stroke_opacity(to, type, stroke_opacity); +} + +css_error css__compose_stroke_opacity(const css_computed_style *parent, + const css_computed_style *child, + css_computed_style *result) +{ + css_fixed stroke_opacity = 0; + uint8_t type = get_stroke_opacity(child, &stroke_opacity); + + return css__copy_stroke_opacity( + type == CSS_STROKE_OPACITY_INHERIT ? parent : child, + result); +} + diff --git a/src/select/properties/table_layout.c b/src/select/properties/table_layout.c index c911e10..255ce37 100644 --- a/src/select/properties/table_layout.c +++ b/src/select/properties/table_layout.c @@ -21,7 +21,7 @@ css_error css__cascade_table_layout(uint32_t opv, css_style *style, UNUSED(style); - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case TABLE_LAYOUT_AUTO: value = CSS_TABLE_LAYOUT_AUTO; @@ -33,7 +33,7 @@ css_error css__cascade_table_layout(uint32_t opv, css_style *style, } if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { return set_table_layout(state->computed, value); } @@ -51,16 +51,25 @@ css_error css__initial_table_layout(css_select_state *state) return set_table_layout(state->computed, CSS_TABLE_LAYOUT_AUTO); } +css_error css__copy_table_layout( + const css_computed_style *from, + css_computed_style *to) +{ + if (from == to) { + return CSS_OK; + } + + return set_table_layout(to, get_table_layout(from)); +} + css_error css__compose_table_layout(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) { uint8_t type = get_table_layout(child); - if (type == CSS_TABLE_LAYOUT_INHERIT) { - type = get_table_layout(parent); - } - - return set_table_layout(result, type); + return css__copy_table_layout( + type == CSS_TABLE_LAYOUT_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/text_align.c b/src/select/properties/text_align.c index 808107f..303f8f5 100644 --- a/src/select/properties/text_align.c +++ b/src/select/properties/text_align.c @@ -21,7 +21,7 @@ css_error css__cascade_text_align(uint32_t opv, css_style *style, UNUSED(style); - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case TEXT_ALIGN_LEFT: value = CSS_TEXT_ALIGN_LEFT; @@ -48,7 +48,7 @@ css_error css__cascade_text_align(uint32_t opv, css_style *style, } if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { return set_text_align(state->computed, value); } @@ -66,15 +66,24 @@ css_error css__initial_text_align(css_select_state *state) return set_text_align(state->computed, CSS_TEXT_ALIGN_DEFAULT); } +css_error css__copy_text_align( + const css_computed_style *from, + css_computed_style *to) +{ + if (from == to) { + return CSS_OK; + } + + return set_text_align(to, get_text_align(from)); +} + css_error css__compose_text_align(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) { uint8_t type = get_text_align(child); - if (type == CSS_TEXT_ALIGN_INHERIT) { - type = get_text_align(parent); - } else if (type == CSS_TEXT_ALIGN_INHERIT_IF_NON_MAGIC) { + if (type == CSS_TEXT_ALIGN_INHERIT_IF_NON_MAGIC) { /* This is purely for the benefit of HTML tables */ type = get_text_align(parent); @@ -83,10 +92,15 @@ css_error css__compose_text_align(const css_computed_style *parent, * inherit as normal. */ if (type == CSS_TEXT_ALIGN_LIBCSS_LEFT || type == CSS_TEXT_ALIGN_LIBCSS_CENTER || - type == CSS_TEXT_ALIGN_LIBCSS_RIGHT) + type == CSS_TEXT_ALIGN_LIBCSS_RIGHT) { type = CSS_TEXT_ALIGN_DEFAULT; + } + + return set_text_align(result, type); } - return set_text_align(result, type); + return css__copy_text_align( + type == CSS_TEXT_ALIGN_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/text_decoration.c b/src/select/properties/text_decoration.c index 0e7544d..bfea8a8 100644 --- a/src/select/properties/text_decoration.c +++ b/src/select/properties/text_decoration.c @@ -23,7 +23,7 @@ css_error css__cascade_text_decoration(uint32_t opv, css_style *style, UNUSED(style); - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { if (getValue(opv) == TEXT_DECORATION_NONE) { value = CSS_TEXT_DECORATION_NONE; } else { @@ -41,7 +41,7 @@ css_error css__cascade_text_decoration(uint32_t opv, css_style *style, } if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { return set_text_decoration(state->computed, value); } @@ -59,16 +59,25 @@ css_error css__initial_text_decoration(css_select_state *state) return set_text_decoration(state->computed, CSS_TEXT_DECORATION_NONE); } +css_error css__copy_text_decoration( + const css_computed_style *from, + css_computed_style *to) +{ + if (from == to) { + return CSS_OK; + } + + return set_text_decoration(to, get_text_decoration(from)); +} + css_error css__compose_text_decoration(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) { uint8_t type = get_text_decoration(child); - if (type == CSS_TEXT_DECORATION_INHERIT) { - type = get_text_decoration(parent); - } - - return set_text_decoration(result, type); + return css__copy_text_decoration( + type == CSS_TEXT_DECORATION_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/text_indent.c b/src/select/properties/text_indent.c index 787c0be..3708130 100644 --- a/src/select/properties/text_indent.c +++ b/src/select/properties/text_indent.c @@ -33,6 +33,21 @@ css_error css__initial_text_indent(css_select_state *state) 0, CSS_UNIT_PX); } +css_error css__copy_text_indent( + const css_computed_style *from, + css_computed_style *to) +{ + css_fixed length = 0; + css_unit unit = CSS_UNIT_PX; + uint8_t type = get_text_indent(from, &length, &unit); + + if (from == to) { + return CSS_OK; + } + + return set_text_indent(to, type, length, unit); +} + css_error css__compose_text_indent(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) @@ -41,10 +56,8 @@ css_error css__compose_text_indent(const css_computed_style *parent, css_unit unit = CSS_UNIT_PX; uint8_t type = get_text_indent(child, &length, &unit); - if (type == CSS_TEXT_INDENT_INHERIT) { - type = get_text_indent(parent, &length, &unit); - } - - return set_text_indent(result, type, length, unit); + return css__copy_text_indent( + type == CSS_TEXT_INDENT_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/text_transform.c b/src/select/properties/text_transform.c index 38cb427..3bc5757 100644 --- a/src/select/properties/text_transform.c +++ b/src/select/properties/text_transform.c @@ -21,7 +21,7 @@ css_error css__cascade_text_transform(uint32_t opv, css_style *style, UNUSED(style); - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case TEXT_TRANSFORM_CAPITALIZE: value = CSS_TEXT_TRANSFORM_CAPITALIZE; @@ -39,7 +39,7 @@ css_error css__cascade_text_transform(uint32_t opv, css_style *style, } if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { return set_text_transform(state->computed, value); } @@ -57,16 +57,25 @@ css_error css__initial_text_transform(css_select_state *state) return set_text_transform(state->computed, CSS_TEXT_TRANSFORM_NONE); } +css_error css__copy_text_transform( + const css_computed_style *from, + css_computed_style *to) +{ + if (from == to) { + return CSS_OK; + } + + return set_text_transform(to, get_text_transform(from)); +} + css_error css__compose_text_transform(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) { uint8_t type = get_text_transform(child); - if (type == CSS_TEXT_TRANSFORM_INHERIT) { - type = get_text_transform(parent); - } - - return set_text_transform(result, type); + return css__copy_text_transform( + type == CSS_TEXT_TRANSFORM_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/top.c b/src/select/properties/top.c index 72129aa..473a105 100644 --- a/src/select/properties/top.c +++ b/src/select/properties/top.c @@ -32,6 +32,21 @@ css_error css__initial_top(css_select_state *state) return set_top(state->computed, CSS_TOP_AUTO, 0, CSS_UNIT_PX); } +css_error css__copy_top( + const css_computed_style *from, + css_computed_style *to) +{ + css_fixed length = 0; + css_unit unit = CSS_UNIT_PX; + uint8_t type = get_top(from, &length, &unit); + + if (from == to) { + return CSS_OK; + } + + return set_top(to, type, length, unit); +} + css_error css__compose_top(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) @@ -40,10 +55,8 @@ css_error css__compose_top(const css_computed_style *parent, css_unit unit = CSS_UNIT_PX; uint8_t type = get_top(child, &length, &unit); - if (type == CSS_TOP_INHERIT) { - type = get_top(parent, &length, &unit); - } - - return set_top(result, type, length, unit); + return css__copy_top( + type == CSS_TOP_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/unicode_bidi.c b/src/select/properties/unicode_bidi.c index 5b91df1..ae0f4ad 100644 --- a/src/select/properties/unicode_bidi.c +++ b/src/select/properties/unicode_bidi.c @@ -21,7 +21,7 @@ css_error css__cascade_unicode_bidi(uint32_t opv, css_style *style, UNUSED(style); - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case UNICODE_BIDI_NORMAL: value = CSS_UNICODE_BIDI_NORMAL; @@ -36,7 +36,7 @@ css_error css__cascade_unicode_bidi(uint32_t opv, css_style *style, } if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { return set_unicode_bidi(state->computed, value); } @@ -54,16 +54,25 @@ css_error css__initial_unicode_bidi(css_select_state *state) return set_unicode_bidi(state->computed, CSS_UNICODE_BIDI_NORMAL); } +css_error css__copy_unicode_bidi( + const css_computed_style *from, + css_computed_style *to) +{ + if (from == to) { + return CSS_OK; + } + + return set_unicode_bidi(to, get_unicode_bidi(from)); +} + css_error css__compose_unicode_bidi(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) { uint8_t type = get_unicode_bidi(child); - if (type == CSS_UNICODE_BIDI_INHERIT) { - type = get_unicode_bidi(parent); - } - - return set_unicode_bidi(result, type); + return css__copy_unicode_bidi( + type == CSS_UNICODE_BIDI_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/vertical_align.c b/src/select/properties/vertical_align.c index 9fb7143..9fbffe6 100644 --- a/src/select/properties/vertical_align.c +++ b/src/select/properties/vertical_align.c @@ -21,7 +21,7 @@ css_error css__cascade_vertical_align(uint32_t opv, css_style *style, css_fixed length = 0; uint32_t unit = UNIT_PX; - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case VERTICAL_ALIGN_SET: value = CSS_VERTICAL_ALIGN_SET; @@ -61,7 +61,7 @@ css_error css__cascade_vertical_align(uint32_t opv, css_style *style, unit = css__to_css_unit(unit); if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { return set_vertical_align(state->computed, value, length, unit); } @@ -81,6 +81,21 @@ css_error css__initial_vertical_align(css_select_state *state) 0, CSS_UNIT_PX); } +css_error css__copy_vertical_align( + const css_computed_style *from, + css_computed_style *to) +{ + css_fixed length = 0; + css_unit unit = CSS_UNIT_PX; + uint8_t type = get_vertical_align(from, &length, &unit); + + if (from == to) { + return CSS_OK; + } + + return set_vertical_align(to, type, length, unit); +} + css_error css__compose_vertical_align(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) @@ -89,10 +104,8 @@ css_error css__compose_vertical_align(const css_computed_style *parent, css_unit unit = CSS_UNIT_PX; uint8_t type = get_vertical_align(child, &length, &unit); - if (type == CSS_VERTICAL_ALIGN_INHERIT) { - type = get_vertical_align(parent, &length, &unit); - } - - return set_vertical_align(result, type, length, unit); + return css__copy_vertical_align( + type == CSS_VERTICAL_ALIGN_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/visibility.c b/src/select/properties/visibility.c index ef95252..674e433 100644 --- a/src/select/properties/visibility.c +++ b/src/select/properties/visibility.c @@ -21,7 +21,7 @@ css_error css__cascade_visibility(uint32_t opv, css_style *style, UNUSED(style); - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case VISIBILITY_VISIBLE: value = CSS_VISIBILITY_VISIBLE; @@ -36,7 +36,7 @@ css_error css__cascade_visibility(uint32_t opv, css_style *style, } if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { return set_visibility(state->computed, value); } @@ -54,16 +54,25 @@ css_error css__initial_visibility(css_select_state *state) return set_visibility(state->computed, CSS_VISIBILITY_VISIBLE); } +css_error css__copy_visibility( + const css_computed_style *from, + css_computed_style *to) +{ + if (from == to) { + return CSS_OK; + } + + return set_visibility(to, get_visibility(from)); +} + css_error css__compose_visibility(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) { uint8_t type = get_visibility(child); - if (type == CSS_VISIBILITY_INHERIT) { - type = get_visibility(parent); - } - - return set_visibility(result, type); + return css__copy_visibility( + type == CSS_VISIBILITY_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/voice_family.c b/src/select/properties/voice_family.c index b370a2b..66e3123 100644 --- a/src/select/properties/voice_family.c +++ b/src/select/properties/voice_family.c @@ -21,7 +21,7 @@ css_error css__cascade_voice_family(uint32_t opv, css_style *style, lwc_string **voices = NULL; uint32_t n_voices = 0; - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { uint32_t v = getValue(opv); while (v != VOICE_FAMILY_END) { @@ -92,7 +92,7 @@ css_error css__cascade_voice_family(uint32_t opv, css_style *style, } if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { /** \todo voice-family */ if (n_voices > 0) free(voices); @@ -120,6 +120,16 @@ css_error css__initial_voice_family(css_select_state *state) return CSS_OK; } +css_error css__copy_voice_family( + const css_computed_style *from, + css_computed_style *to) +{ + UNUSED(from); + UNUSED(to); + + return CSS_OK; +} + css_error css__compose_voice_family(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) diff --git a/src/select/properties/volume.c b/src/select/properties/volume.c index 96787fa..65bdd03 100644 --- a/src/select/properties/volume.c +++ b/src/select/properties/volume.c @@ -20,7 +20,7 @@ css_error css__cascade_volume(uint32_t opv, css_style *style, css_fixed val = 0; uint32_t unit = UNIT_PCT; - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case VOLUME_NUMBER: val = *((css_fixed *) style->bytecode); @@ -46,7 +46,7 @@ css_error css__cascade_volume(uint32_t opv, css_style *style, unit = css__to_css_unit(unit); if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { /** \todo volume */ } @@ -69,6 +69,16 @@ css_error css__initial_volume(css_select_state *state) return CSS_OK; } +css_error css__copy_volume( + const css_computed_style *from, + css_computed_style *to) +{ + UNUSED(from); + UNUSED(to); + + return CSS_OK; +} + css_error css__compose_volume(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) diff --git a/src/select/properties/white_space.c b/src/select/properties/white_space.c index b8d2e02..edc35cd 100644 --- a/src/select/properties/white_space.c +++ b/src/select/properties/white_space.c @@ -21,7 +21,7 @@ css_error css__cascade_white_space(uint32_t opv, css_style *style, UNUSED(style); - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case WHITE_SPACE_NORMAL: value = CSS_WHITE_SPACE_NORMAL; @@ -42,7 +42,7 @@ css_error css__cascade_white_space(uint32_t opv, css_style *style, } if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { return set_white_space(state->computed, value); } @@ -60,16 +60,25 @@ css_error css__initial_white_space(css_select_state *state) return set_white_space(state->computed, CSS_WHITE_SPACE_NORMAL); } +css_error css__copy_white_space( + const css_computed_style *from, + css_computed_style *to) +{ + if (from == to) { + return CSS_OK; + } + + return set_white_space(to, get_white_space(from)); +} + css_error css__compose_white_space(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) { uint8_t type = get_white_space(child); - if (type == CSS_WHITE_SPACE_INHERIT) { - type = get_white_space(parent); - } - - return set_white_space(result, type); + return css__copy_white_space( + type == CSS_WHITE_SPACE_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/widows.c b/src/select/properties/widows.c index 61126c2..853c08d 100644 --- a/src/select/properties/widows.c +++ b/src/select/properties/widows.c @@ -31,6 +31,20 @@ css_error css__initial_widows(css_select_state *state) return set_widows(state->computed, CSS_WIDOWS_SET, 2); } +css_error css__copy_widows( + const css_computed_style *from, + css_computed_style *to) +{ + int32_t count = 0; + uint8_t type = get_widows(from, &count); + + if (from == to) { + return CSS_OK; + } + + return set_widows(to, type, count); +} + css_error css__compose_widows(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) @@ -38,10 +52,8 @@ css_error css__compose_widows(const css_computed_style *parent, int32_t count = 0; uint8_t type = get_widows(child, &count); - if (type == CSS_WIDOWS_INHERIT) { - type = get_widows(parent, &count); - } - - return set_widows(result, type, count); + return css__copy_widows( + type == CSS_WIDOWS_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/width.c b/src/select/properties/width.c index 829df91..c6d33ff 100644 --- a/src/select/properties/width.c +++ b/src/select/properties/width.c @@ -32,6 +32,21 @@ css_error css__initial_width(css_select_state *state) return set_width(state->computed, CSS_WIDTH_AUTO, 0, CSS_UNIT_PX); } +css_error css__copy_width( + const css_computed_style *from, + css_computed_style *to) +{ + css_fixed length = 0; + css_unit unit = CSS_UNIT_PX; + uint8_t type = get_width(from, &length, &unit); + + if (from == to) { + return CSS_OK; + } + + return set_width(to, type, length, unit); +} + css_error css__compose_width(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) @@ -40,10 +55,8 @@ css_error css__compose_width(const css_computed_style *parent, css_unit unit = CSS_UNIT_PX; uint8_t type = get_width(child, &length, &unit); - if (type == CSS_WIDTH_INHERIT) { - type = get_width(parent, &length, &unit); - } - - return set_width(result, type, length, unit); + return css__copy_width( + type == CSS_WIDTH_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/word_spacing.c b/src/select/properties/word_spacing.c index 4cb9422..c1c6782 100644 --- a/src/select/properties/word_spacing.c +++ b/src/select/properties/word_spacing.c @@ -33,6 +33,21 @@ css_error css__initial_word_spacing(css_select_state *state) 0, CSS_UNIT_PX); } +css_error css__copy_word_spacing( + const css_computed_style *from, + css_computed_style *to) +{ + css_fixed length = 0; + css_unit unit = CSS_UNIT_PX; + uint8_t type = get_word_spacing(from, &length, &unit); + + if (from == to) { + return CSS_OK; + } + + return set_word_spacing(to, type, length, unit); +} + css_error css__compose_word_spacing(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) @@ -41,17 +56,7 @@ css_error css__compose_word_spacing(const css_computed_style *parent, css_unit unit = CSS_UNIT_PX; uint8_t type = get_word_spacing(child, &length, &unit); - if ((child->i.uncommon == NULL && parent->i.uncommon != NULL) || - type == CSS_WORD_SPACING_INHERIT || - (child->i.uncommon != NULL && result != child)) { - if ((child->i.uncommon == NULL && parent->i.uncommon != NULL) || - type == CSS_WORD_SPACING_INHERIT) { - type = get_word_spacing(parent, &length, &unit); - } - - return set_word_spacing(result, type, length, unit); - } - - return CSS_OK; + return css__copy_word_spacing( + type == CSS_WORD_SPACING_INHERIT ? parent : child, + result); } - diff --git a/src/select/properties/writing_mode.c b/src/select/properties/writing_mode.c index bbd3753..05c0b26 100644 --- a/src/select/properties/writing_mode.c +++ b/src/select/properties/writing_mode.c @@ -17,11 +17,11 @@ css_error css__cascade_writing_mode(uint32_t opv, css_style *style, css_select_state *state) { - bool inherit = isInherit(opv); + enum flag_value flag_value = getFlagValue(opv); uint16_t writing_mode = CSS_WRITING_MODE_INHERIT; UNUSED(style); - if (inherit == false) { + if (flag_value == FLAG_VALUE__NONE) { switch (getValue(opv)) { case WRITING_MODE_HORIZONTAL_TB: writing_mode = CSS_WRITING_MODE_HORIZONTAL_TB; @@ -36,7 +36,7 @@ css_error css__cascade_writing_mode(uint32_t opv, css_style *style, } if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - inherit)) { + flag_value)) { return set_writing_mode(state->computed, writing_mode); } @@ -55,16 +55,25 @@ css_error css__initial_writing_mode(css_select_state *state) CSS_WRITING_MODE_HORIZONTAL_TB); } +css_error css__copy_writing_mode( + const css_computed_style *from, + css_computed_style *to) +{ + if (from == to) { + return CSS_OK; + } + + return set_writing_mode(to, get_writing_mode(from)); +} + css_error css__compose_writing_mode(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) { - uint8_t writing_mode = get_writing_mode(child); - - if (writing_mode == CSS_WRITING_MODE_INHERIT) { - writing_mode = get_writing_mode(parent); - } + uint8_t type = get_writing_mode(child); - return set_writing_mode(result, writing_mode); + return css__copy_writing_mode( + type == CSS_WRITING_MODE_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/z_index.c b/src/select/properties/z_index.c index 59cf242..e5159e5 100644 --- a/src/select/properties/z_index.c +++ b/src/select/properties/z_index.c @@ -20,7 +20,7 @@ css_error css__cascade_z_index(uint32_t opv, css_style *style, uint16_t value = CSS_Z_INDEX_INHERIT; css_fixed index = 0; - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case Z_INDEX_SET: value = CSS_Z_INDEX_SET; @@ -35,7 +35,7 @@ css_error css__cascade_z_index(uint32_t opv, css_style *style, } if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { return set_z_index(state->computed, value, index); } @@ -53,6 +53,20 @@ css_error css__initial_z_index(css_select_state *state) return set_z_index(state->computed, CSS_Z_INDEX_AUTO, 0); } +css_error css__copy_z_index( + const css_computed_style *from, + css_computed_style *to) +{ + int32_t index = 0; + uint8_t type = get_z_index(from, &index); + + if (from == to) { + return CSS_OK; + } + + return set_z_index(to, type, index); +} + css_error css__compose_z_index(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) @@ -60,10 +74,8 @@ css_error css__compose_z_index(const css_computed_style *parent, int32_t index = 0; uint8_t type = get_z_index(child, &index); - if (type == CSS_Z_INDEX_INHERIT) { - type = get_z_index(parent, &index); - } - - return set_z_index(result, type, index); + return css__copy_z_index( + type == CSS_Z_INDEX_INHERIT ? parent : child, + result); } diff --git a/src/select/propget.h b/src/select/propget.h index 6719443..41298f1 100644 --- a/src/select/propget.h +++ b/src/select/propget.h @@ -10,2183 +10,6 @@ #include <libcss/computed.h> #include "computed.h" - -/* Important: keep this file in sync with computed.h */ -/** \todo Is there a better way to ensure this happens? */ - -#define LETTER_SPACING_INDEX 0 -#define LETTER_SPACING_SHIFT 2 -#define LETTER_SPACING_MASK 0xfc -static inline uint8_t get_letter_spacing( - const css_computed_style *style, - css_fixed *length, css_unit *unit) -{ - if (style->i.uncommon != NULL) { - uint8_t bits = style->i.uncommon->i.bits[LETTER_SPACING_INDEX]; - bits &= LETTER_SPACING_MASK; - bits >>= LETTER_SPACING_SHIFT; - - /* 6bits: uuuutt : unit | type */ - - if ((bits & 3) == CSS_LETTER_SPACING_SET) { - *length = style->i.uncommon->i.letter_spacing; - *unit = bits >> 2; - } - - return (bits & 3); - } - - /* Initial value */ - return CSS_LETTER_SPACING_NORMAL; -} -#undef LETTER_SPACING_MASK -#undef LETTER_SPACING_SHIFT -#undef LETTER_SPACING_INDEX - -#define OUTLINE_COLOR_INDEX 0 -#define OUTLINE_COLOR_SHIFT 0 -#define OUTLINE_COLOR_MASK 0x3 -static inline uint8_t get_outline_color( - const css_computed_style *style, css_color *color) -{ - if (style->i.uncommon != NULL) { - uint8_t bits = style->i.uncommon->i.bits[OUTLINE_COLOR_INDEX]; - bits &= OUTLINE_COLOR_MASK; - bits >>= OUTLINE_COLOR_SHIFT; - - /* 2bits: tt : type */ - - if ((bits & 3) == CSS_OUTLINE_COLOR_COLOR) { - *color = style->i.uncommon->i.outline_color; - } - - return (bits & 3); - } - - /* Initial value */ - return CSS_OUTLINE_COLOR_INVERT; -} -#undef OUTLINE_COLOR_MASK -#undef OUTLINE_COLOR_SHIFT -#undef OUTLINE_COLOR_INDEX - -#define OUTLINE_WIDTH_INDEX 1 -#define OUTLINE_WIDTH_SHIFT 1 -#define OUTLINE_WIDTH_MASK 0xfe -static inline uint8_t get_outline_width( - const css_computed_style *style, - css_fixed *length, css_unit *unit) -{ - if (style->i.uncommon != NULL) { - uint8_t bits = style->i.uncommon->i.bits[OUTLINE_WIDTH_INDEX]; - bits &= OUTLINE_WIDTH_MASK; - bits >>= OUTLINE_WIDTH_SHIFT; - - /* 7bits: uuuuttt : unit | type */ - - if ((bits & 7) == CSS_OUTLINE_WIDTH_WIDTH) { - *length = style->i.uncommon->i.outline_width; - *unit = bits >> 3; - } - - return (bits & 7); - } - - /* Initial value */ - return CSS_OUTLINE_WIDTH_MEDIUM; -} -#undef OUTLINE_WIDTH_MASK -#undef OUTLINE_WIDTH_SHIFT -#undef OUTLINE_WIDTH_INDEX - -#define BORDER_SPACING_INDEX 1 -#define BORDER_SPACING_SHIFT 0 -#define BORDER_SPACING_MASK 0x1 -#define BORDER_SPACING_INDEX1 2 -#define BORDER_SPACING_SHIFT1 0 -#define BORDER_SPACING_MASK1 0xff -static inline uint8_t get_border_spacing( - const css_computed_style *style, - css_fixed *hlength, css_unit *hunit, - css_fixed *vlength, css_unit *vunit) -{ - if (style->i.uncommon != NULL) { - uint8_t bits = style->i.uncommon->i.bits[BORDER_SPACING_INDEX]; - bits &= BORDER_SPACING_MASK; - bits >>= BORDER_SPACING_SHIFT; - - /* 1 bit: type */ - if (bits == CSS_BORDER_SPACING_SET) { - uint8_t bits1 = - style->i.uncommon->i.bits[BORDER_SPACING_INDEX1]; - bits1 &= BORDER_SPACING_MASK1; - bits1 >>= BORDER_SPACING_SHIFT1; - - /* 8bits: hhhhvvvv : hunit | vunit */ - - *hlength = style->i.uncommon->i.border_spacing[0]; - *hunit = bits1 >> 4; - - *vlength = style->i.uncommon->i.border_spacing[1]; - *vunit = bits1 & 0xf; - } - - return bits; - } - - /* Initial value */ - *hlength = *vlength = 0; - *hunit = *vunit = CSS_UNIT_PX; - return CSS_BORDER_SPACING_SET; -} -#undef BORDER_SPACING_MASK1 -#undef BORDER_SPACING_SHIFT1 -#undef BORDER_SPACING_INDEX1 -#undef BORDER_SPACING_MASK -#undef BORDER_SPACING_SHIFT -#undef BORDER_SPACING_INDEX - -#define BREAK_AFTER_INDEX 12 -#define BREAK_AFTER_SHIFT 0 -#define BREAK_AFTER_MASK 0xf -static inline uint8_t get_break_after( - const css_computed_style *style) -{ - if (style->i.uncommon != NULL) { - uint8_t bits = style->i.uncommon->i.bits[BREAK_AFTER_INDEX]; - bits &= BREAK_AFTER_MASK; - bits >>= BREAK_AFTER_SHIFT; - - /* 4bits: type */ - return bits; - } - - /* Initial value */ - return CSS_BREAK_AFTER_AUTO; -} -#undef BREAK_AFTER_MASK -#undef BREAK_AFTER_SHIFT -#undef BREAK_AFTER_INDEX - -#define BREAK_BEFORE_INDEX 12 -#define BREAK_BEFORE_SHIFT 4 -#define BREAK_BEFORE_MASK (0xf << 4) -static inline uint8_t get_break_before( - const css_computed_style *style) -{ - if (style->i.uncommon != NULL) { - uint8_t bits = style->i.uncommon->i.bits[BREAK_BEFORE_INDEX]; - bits &= BREAK_BEFORE_MASK; - bits >>= BREAK_BEFORE_SHIFT; - - /* 4bits: type */ - return bits; - } - - /* Initial value */ - return CSS_BREAK_BEFORE_AUTO; -} -#undef BREAK_BEFORE_MASK -#undef BREAK_BEFORE_SHIFT -#undef BREAK_BEFORE_INDEX - -#define BREAK_INSIDE_INDEX 13 -#define BREAK_INSIDE_SHIFT 4 -#define BREAK_INSIDE_MASK (0xf << 4) -static inline uint8_t get_break_inside( - const css_computed_style *style) -{ - if (style->i.uncommon != NULL) { - uint8_t bits = style->i.uncommon->i.bits[BREAK_INSIDE_INDEX]; - bits &= BREAK_INSIDE_MASK; - bits >>= BREAK_INSIDE_SHIFT; - - /* 4bits: type */ - return bits; - } - - /* Initial value */ - return CSS_BREAK_INSIDE_AUTO; -} -#undef BREAK_INSIDE_MASK -#undef BREAK_INSIDE_SHIFT -#undef BREAK_INSIDE_INDEX - -#define WORD_SPACING_INDEX 3 -#define WORD_SPACING_SHIFT 2 -#define WORD_SPACING_MASK 0xfc -static inline uint8_t get_word_spacing( - const css_computed_style *style, - css_fixed *length, css_unit *unit) -{ - if (style->i.uncommon != NULL) { - uint8_t bits = style->i.uncommon->i.bits[WORD_SPACING_INDEX]; - bits &= WORD_SPACING_MASK; - bits >>= WORD_SPACING_SHIFT; - - /* 6bits: uuuutt : unit | type */ - - if ((bits & 3) == CSS_WORD_SPACING_SET) { - *length = style->i.uncommon->i.word_spacing; - *unit = bits >> 2; - } - - return (bits & 3); - } - - /* Initial value */ - return CSS_WORD_SPACING_NORMAL; -} -#undef WORD_SPACING_MASK -#undef WORD_SPACING_SHIFT -#undef WORD_SPACING_INDEX - -#define WRITING_MODE_INDEX 4 -#define WRITING_MODE_MASK 0x6 -#define WRITING_MODE_SHIFT 1 -static inline uint8_t get_writing_mode( - const css_computed_style *style) -{ - if (style->i.uncommon != NULL) { - uint8_t bits = style->i.uncommon->i.bits[WRITING_MODE_INDEX]; - bits &= WRITING_MODE_MASK; - bits >>= WRITING_MODE_SHIFT; - - /* 2bits: type */ - return bits; - } - - /* Initial value */ - return CSS_WRITING_MODE_HORIZONTAL_TB; -} -#undef WRITING_MODE_INDEX -#undef WRITING_MODE_MASK -#undef WRITING_MODE_SHIFT - -#define COUNTER_INCREMENT_INDEX 3 -#define COUNTER_INCREMENT_SHIFT 1 -#define COUNTER_INCREMENT_MASK 0x2 -static inline uint8_t get_counter_increment( - const css_computed_style *style, - const css_computed_counter **counters) -{ - if (style->i.uncommon != NULL) { - uint8_t bits = style->i.uncommon->i.bits[COUNTER_INCREMENT_INDEX]; - bits &= COUNTER_INCREMENT_MASK; - bits >>= COUNTER_INCREMENT_SHIFT; - - /* 1bit: type */ - *counters = style->i.uncommon->counter_increment; - - return bits; - } - - /* Initial value */ - return CSS_COUNTER_INCREMENT_NONE; -} -#undef COUNTER_INCREMENT_MASK -#undef COUNTER_INCREMENT_SHIFT -#undef COUNTER_INCREMENT_INDEX - -#define COUNTER_RESET_INDEX 3 -#define COUNTER_RESET_SHIFT 0 -#define COUNTER_RESET_MASK 0x1 -static inline uint8_t get_counter_reset( - const css_computed_style *style, - const css_computed_counter **counters) -{ - if (style->i.uncommon != NULL) { - uint8_t bits = style->i.uncommon->i.bits[COUNTER_RESET_INDEX]; - bits &= COUNTER_RESET_MASK; - bits >>= COUNTER_RESET_SHIFT; - - /* 1bit: type */ - *counters = style->i.uncommon->counter_reset; - - return bits; - } - - /* Initial value */ - return CSS_COUNTER_RESET_NONE; -} -#undef COUNTER_RESET_MASK -#undef COUNTER_RESET_SHIFT -#undef COUNTER_RESET_INDEX - -#define CURSOR_INDEX 4 -#define CURSOR_SHIFT 3 -#define CURSOR_MASK 0xf8 -static inline uint8_t get_cursor( - const css_computed_style *style, - lwc_string ***urls) -{ - if (style->i.uncommon != NULL) { - uint8_t bits = style->i.uncommon->i.bits[CURSOR_INDEX]; - bits &= CURSOR_MASK; - bits >>= CURSOR_SHIFT; - - /* 5bits: type */ - *urls = style->i.uncommon->cursor; - - return bits; - } - - /* Initial value */ - return CSS_CURSOR_AUTO; -} -#undef CURSOR_MASK -#undef CURSOR_SHIFT -#undef CURSOR_INDEX - -#define CLIP_INDEX 7 -#define CLIP_SHIFT 2 -#define CLIP_MASK 0xfc -#define CLIP_INDEX1 5 -#define CLIP_SHIFT1 0 -#define CLIP_MASK1 0xff -#define CLIP_INDEX2 6 -#define CLIP_SHIFT2 0 -#define CLIP_MASK2 0xff -static inline uint8_t get_clip( - const css_computed_style *style, - css_computed_clip_rect *rect) -{ - if (style->i.uncommon != NULL) { - uint8_t bits = style->i.uncommon->i.bits[CLIP_INDEX]; - bits &= CLIP_MASK; - bits >>= CLIP_SHIFT; - - /* 6bits: trblyy : top | right | bottom | left | type */ - if ((bits & 0x3) == CSS_CLIP_RECT) { - uint8_t bits1; - - rect->left_auto = (bits & 0x4); - rect->bottom_auto = (bits & 0x8); - rect->right_auto = (bits & 0x10); - rect->top_auto = (bits & 0x20); - - if (rect->top_auto == false || - rect->right_auto == false) { - /* 8bits: ttttrrrr : top | right */ - bits1 = style->i.uncommon->i.bits[CLIP_INDEX1]; - bits1 &= CLIP_MASK1; - bits1 >>= CLIP_SHIFT1; - } else { - bits1 = 0; - } - - rect->top = style->i.uncommon->i.clip[0]; - rect->tunit = bits1 >> 4; - - rect->right = style->i.uncommon->i.clip[1]; - rect->runit = bits1 & 0xf; - - if (rect->bottom_auto == false || - rect->left_auto == false) { - /* 8bits: bbbbllll : bottom | left */ - bits1 = style->i.uncommon->i.bits[CLIP_INDEX2]; - bits1 &= CLIP_MASK2; - bits1 >>= CLIP_SHIFT2; - } else { - bits1 = 0; - } - - rect->bottom = style->i.uncommon->i.clip[2]; - rect->bunit = bits1 >> 4; - - rect->left = style->i.uncommon->i.clip[3]; - rect->lunit = bits1 & 0xf; - } - - return (bits & 0x3); - } - - /* Initial value */ - return CSS_CLIP_AUTO; -} -#undef CLIP_MASK2 -#undef CLIP_SHIFT2 -#undef CLIP_INDEX2 -#undef CLIP_MASK1 -#undef CLIP_SHIFT1 -#undef CLIP_INDEX1 -#undef CLIP_MASK -#undef CLIP_SHIFT -#undef CLIP_INDEX - -#define COLUMN_COUNT_INDEX 8 -#define COLUMN_COUNT_SHIFT 6 -#define COLUMN_COUNT_MASK 0xc0 -static inline uint8_t get_column_count( - const css_computed_style *style, int32_t *count) -{ - if (style->i.uncommon != NULL) { - uint8_t bits = style->i.uncommon->i.bits[COLUMN_COUNT_INDEX]; - bits &= COLUMN_COUNT_MASK; - bits >>= COLUMN_COUNT_SHIFT; - - /* 2bits: tt : type */ - *count = style->i.uncommon->i.column_count; - - return bits; - } - - /* Initial value */ - return CSS_COLUMN_COUNT_AUTO; -} -#undef COLUMN_COUNT_MASK -#undef COLUMN_COUNT_SHIFT -#undef COLUMN_COUNT_INDEX - -#define COLUMN_FILL_INDEX 8 -#define COLUMN_FILL_SHIFT 4 -#define COLUMN_FILL_MASK 0x30 -static inline uint8_t get_column_fill( - const css_computed_style *style) -{ - if (style->i.uncommon != NULL) { - uint8_t bits = style->i.uncommon->i.bits[COLUMN_FILL_INDEX]; - bits &= COLUMN_FILL_MASK; - bits >>= COLUMN_FILL_SHIFT; - - /* 2bits: type */ - return bits; - } - - /* Initial value */ - return CSS_COLUMN_FILL_BALANCE; -} -#undef COLUMN_FILL_MASK -#undef COLUMN_FILL_SHIFT -#undef COLUMN_FILL_INDEX - -#define COLUMN_GAP_INDEX 9 -#define COLUMN_GAP_SHIFT 2 -#define COLUMN_GAP_MASK 0xfc -static inline uint8_t get_column_gap( - const css_computed_style *style, - css_fixed *length, css_unit *unit) -{ - if (style->i.uncommon != NULL) { - uint8_t bits = style->i.uncommon->i.bits[COLUMN_GAP_INDEX]; - bits &= COLUMN_GAP_MASK; - bits >>= COLUMN_GAP_SHIFT; - - /* 6bits: uuuutt : units | type */ - if ((bits & 0x3) == CSS_COLUMN_GAP_SET) { - *length = style->i.uncommon->i.column_gap; - *unit = bits >> 2; - } - - return (bits & 0x3); - } - - /* Initial value */ - return CSS_COLUMN_GAP_NORMAL; -} -#undef COLUMN_GAP_MASK -#undef COLUMN_GAP_SHIFT -#undef COLUMN_GAP_INDEX - -#define COLUMN_RULE_COLOR_INDEX 9 -#define COLUMN_RULE_COLOR_SHIFT 0 -#define COLUMN_RULE_COLOR_MASK 0x3 -static inline uint8_t get_column_rule_color( - const css_computed_style *style, - css_color *color) -{ - if (style->i.uncommon != NULL) { - uint8_t bits = style->i.uncommon->i.bits[COLUMN_RULE_COLOR_INDEX]; - bits &= COLUMN_RULE_COLOR_MASK; - bits >>= COLUMN_RULE_COLOR_SHIFT; - - /* 2bits: type */ - *color = style->i.uncommon->i.column_rule_color; - - return bits; - } - - /* Initial value */ - *color = 0; - return CSS_COLUMN_RULE_COLOR_CURRENT_COLOR; -} -#undef COLUMN_RULE_COLOR_MASK -#undef COLUMN_RULE_COLOR_SHIFT -#undef COLUMN_RULE_COLOR_INDEX - -#define COLUMN_RULE_STYLE_INDEX 8 -#define COLUMN_RULE_STYLE_SHIFT 0 -#define COLUMN_RULE_STYLE_MASK 0xf -static inline uint8_t get_column_rule_style( - const css_computed_style *style) -{ - if (style->i.uncommon != NULL) { - uint8_t bits = style->i.uncommon->i.bits[COLUMN_RULE_STYLE_INDEX]; - bits &= COLUMN_RULE_STYLE_MASK; - bits >>= COLUMN_RULE_STYLE_SHIFT; - - /* 4bits: type */ - return bits; - } - - /* Initial value */ - return CSS_COLUMN_RULE_STYLE_NONE; -} -#undef COLUMN_RULE_STYLE_MASK -#undef COLUMN_RULE_STYLE_SHIFT -#undef COLUMN_RULE_STYLE_INDEX - -#define COLUMN_RULE_WIDTH_INDEX 10 -#define COLUMN_RULE_WIDTH_SHIFT 1 -#define COLUMN_RULE_WIDTH_MASK 0xfe -static inline uint8_t get_column_rule_width( - const css_computed_style *style, - css_fixed *length, css_unit *unit) -{ - if (style->i.uncommon != NULL) { - uint8_t bits = style->i.uncommon->i.bits[COLUMN_RULE_WIDTH_INDEX]; - bits &= COLUMN_RULE_WIDTH_MASK; - bits >>= COLUMN_RULE_WIDTH_SHIFT; - - /* 7bits: uuuuttt : units | type */ - if ((bits & 0x7) == CSS_COLUMN_RULE_WIDTH_WIDTH) { - *length = style->i.uncommon->i.column_rule_width; - *unit = bits >> 3; - } - - return (bits & 0x7); - } - - /* Initial value */ - return CSS_COLUMN_RULE_WIDTH_MEDIUM; -} -#undef COLUMN_RULE_WIDTH_MASK -#undef COLUMN_RULE_WIDTH_SHIFT -#undef COLUMN_RULE_WIDTH_INDEX - -#define COLUMN_SPAN_INDEX 11 -#define COLUMN_SPAN_SHIFT 6 -#define COLUMN_SPAN_MASK 0xc0 -static inline uint8_t get_column_span( - const css_computed_style *style) -{ - if (style->i.uncommon != NULL) { - uint8_t bits = style->i.uncommon->i.bits[COLUMN_SPAN_INDEX]; - bits &= COLUMN_SPAN_MASK; - bits >>= COLUMN_SPAN_SHIFT; - - /* 2bits: type */ - return bits; - } - - /* Initial value */ - return CSS_COLUMN_SPAN_NONE; -} -#undef COLUMN_SPAN_MASK -#undef COLUMN_SPAN_SHIFT -#undef COLUMN_SPAN_INDEX - -#define COLUMN_WIDTH_INDEX 11 -#define COLUMN_WIDTH_SHIFT 0 -#define COLUMN_WIDTH_MASK 0x3f -static inline uint8_t get_column_width( - const css_computed_style *style, - css_fixed *length, css_unit *unit) -{ - if (style->i.uncommon != NULL) { - uint8_t bits = style->i.uncommon->i.bits[COLUMN_WIDTH_INDEX]; - bits &= COLUMN_WIDTH_MASK; - bits >>= COLUMN_WIDTH_SHIFT; - - /* 6bits: uuuutt : units | type */ - if ((bits & 0x3) == CSS_COLUMN_WIDTH_SET) { - *length = style->i.uncommon->i.column_width; - *unit = bits >> 2; - } - - return (bits & 0x3); - } - - /* Initial value */ - return CSS_COLUMN_WIDTH_AUTO; -} -#undef COLUMN_WIDTH_MASK -#undef COLUMN_WIDTH_SHIFT -#undef COLUMN_WIDTH_INDEX - -#define CONTENT_INDEX 7 -#define CONTENT_SHIFT 0 -#define CONTENT_MASK 0x3 -static inline uint8_t get_content( - const css_computed_style *style, - const css_computed_content_item **content) -{ - if (style->i.uncommon != NULL) { - uint8_t bits = style->i.uncommon->i.bits[CONTENT_INDEX]; - bits &= CONTENT_MASK; - bits >>= CONTENT_SHIFT; - - /* 2bits: type */ - *content = style->i.uncommon->content; - - return bits; - } - - /* Initial value */ - return CSS_CONTENT_NORMAL; -} -#undef CONTENT_MASK -#undef CONTENT_SHIFT -#undef CONTENT_INDEX - -#define VERTICAL_ALIGN_INDEX 0 -#define VERTICAL_ALIGN_SHIFT 0 -#define VERTICAL_ALIGN_MASK 0xff -static inline uint8_t get_vertical_align( - const css_computed_style *style, - css_fixed *length, css_unit *unit) -{ - uint8_t bits = style->i.bits[VERTICAL_ALIGN_INDEX]; - bits &= VERTICAL_ALIGN_MASK; - bits >>= VERTICAL_ALIGN_SHIFT; - - /* 8bits: uuuutttt : units | type */ - if ((bits & 0xf) == CSS_VERTICAL_ALIGN_SET) { - *length = style->i.vertical_align; - *unit = bits >> 4; - } - - return (bits & 0xf); -} -#undef VERTICAL_ALIGN_MASK -#undef VERTICAL_ALIGN_SHIFT -#undef VERTICAL_ALIGN_INDEX - -#define FONT_SIZE_INDEX 1 -#define FONT_SIZE_SHIFT 0 -#define FONT_SIZE_MASK 0xff -static inline uint8_t get_font_size( - const css_computed_style *style, - css_fixed *length, css_unit *unit) -{ - uint8_t bits = style->i.bits[FONT_SIZE_INDEX]; - bits &= FONT_SIZE_MASK; - bits >>= FONT_SIZE_SHIFT; - - /* 8bits: uuuutttt : units | type */ - if ((bits & 0xf) == CSS_FONT_SIZE_DIMENSION) { - *length = style->i.font_size; - *unit = bits >> 4; - } - - return (bits & 0xf); -} -#undef FONT_SIZE_MASK -#undef FONT_SIZE_SHIFT -#undef FONT_SIZE_INDEX - -#define BORDER_TOP_WIDTH_INDEX 2 -#define BORDER_TOP_WIDTH_SHIFT 1 -#define BORDER_TOP_WIDTH_MASK 0xfe -static inline uint8_t get_border_top_width( - const css_computed_style *style, - css_fixed *length, css_unit *unit) -{ - uint8_t bits = style->i.bits[BORDER_TOP_WIDTH_INDEX]; - bits &= BORDER_TOP_WIDTH_MASK; - bits >>= BORDER_TOP_WIDTH_SHIFT; - - /* 7bits: uuuuttt : units | type */ - if ((bits & 0x7) == CSS_BORDER_WIDTH_WIDTH) { - *length = style->i.border_width[0]; - *unit = bits >> 3; - } - - return (bits & 0x7); -} -#undef BORDER_TOP_WIDTH_MASK -#undef BORDER_TOP_WIDTH_SHIFT -#undef BORDER_TOP_WIDTH_INDEX - -#define BORDER_RIGHT_WIDTH_INDEX 3 -#define BORDER_RIGHT_WIDTH_SHIFT 1 -#define BORDER_RIGHT_WIDTH_MASK 0xfe -static inline uint8_t get_border_right_width( - const css_computed_style *style, - css_fixed *length, css_unit *unit) -{ - uint8_t bits = style->i.bits[BORDER_RIGHT_WIDTH_INDEX]; - bits &= BORDER_RIGHT_WIDTH_MASK; - bits >>= BORDER_RIGHT_WIDTH_SHIFT; - - /* 7bits: uuuuttt : units | type */ - if ((bits & 0x7) == CSS_BORDER_WIDTH_WIDTH) { - *length = style->i.border_width[1]; - *unit = bits >> 3; - } - - return (bits & 0x7); -} -#undef BORDER_RIGHT_WIDTH_MASK -#undef BORDER_RIGHT_WIDTH_SHIFT -#undef BORDER_RIGHT_WIDTH_INDEX - -#define BORDER_BOTTOM_WIDTH_INDEX 4 -#define BORDER_BOTTOM_WIDTH_SHIFT 1 -#define BORDER_BOTTOM_WIDTH_MASK 0xfe -static inline uint8_t get_border_bottom_width( - const css_computed_style *style, - css_fixed *length, css_unit *unit) -{ - uint8_t bits = style->i.bits[BORDER_BOTTOM_WIDTH_INDEX]; - bits &= BORDER_BOTTOM_WIDTH_MASK; - bits >>= BORDER_BOTTOM_WIDTH_SHIFT; - - /* 7bits: uuuuttt : units | type */ - if ((bits & 0x7) == CSS_BORDER_WIDTH_WIDTH) { - *length = style->i.border_width[2]; - *unit = bits >> 3; - } - - return (bits & 0x7); -} -#undef BORDER_BOTTOM_WIDTH_MASK -#undef BORDER_BOTTOM_WIDTH_SHIFT -#undef BORDER_BOTTOM_WIDTH_INDEX - -#define BORDER_LEFT_WIDTH_INDEX 5 -#define BORDER_LEFT_WIDTH_SHIFT 1 -#define BORDER_LEFT_WIDTH_MASK 0xfe -static inline uint8_t get_border_left_width( - const css_computed_style *style, - css_fixed *length, css_unit *unit) -{ - uint8_t bits = style->i.bits[BORDER_LEFT_WIDTH_INDEX]; - bits &= BORDER_LEFT_WIDTH_MASK; - bits >>= BORDER_LEFT_WIDTH_SHIFT; - - /* 7bits: uuuuttt : units | type */ - if ((bits & 0x7) == CSS_BORDER_WIDTH_WIDTH) { - *length = style->i.border_width[3]; - *unit = bits >> 3; - } - - return (bits & 0x7); -} -#undef BORDER_LEFT_WIDTH_MASK -#undef BORDER_LEFT_WIDTH_SHIFT -#undef BORDER_LEFT_WIDTH_INDEX - -#define BACKGROUND_IMAGE_INDEX 2 -#define BACKGROUND_IMAGE_SHIFT 0 -#define BACKGROUND_IMAGE_MASK 0x1 -static inline uint8_t get_background_image( - const css_computed_style *style, - lwc_string **url) -{ - uint8_t bits = style->i.bits[BACKGROUND_IMAGE_INDEX]; - bits &= BACKGROUND_IMAGE_MASK; - bits >>= BACKGROUND_IMAGE_SHIFT; - - /* 1bit: type */ - *url = style->i.background_image; - - return bits; -} -#undef BACKGROUND_IMAGE_MASK -#undef BACKGROUND_IMAGE_SHIFT -#undef BACKGROUND_IMAGE_INDEX - -#define COLOR_INDEX 3 -#define COLOR_SHIFT 0 -#define COLOR_MASK 0x1 -static inline uint8_t get_color( - const css_computed_style *style, - css_color *color) -{ - uint8_t bits = style->i.bits[COLOR_INDEX]; - bits &= COLOR_MASK; - bits >>= COLOR_SHIFT; - - /* 1bit: type */ - *color = style->i.color; - - return bits; -} -#undef COLOR_MASK -#undef COLOR_SHIFT -#undef COLOR_INDEX - -#define LIST_STYLE_IMAGE_INDEX 4 -#define LIST_STYLE_IMAGE_SHIFT 0 -#define LIST_STYLE_IMAGE_MASK 0x1 -static inline uint8_t get_list_style_image( - const css_computed_style *style, - lwc_string **url) -{ - uint8_t bits = style->i.bits[LIST_STYLE_IMAGE_INDEX]; - bits &= LIST_STYLE_IMAGE_MASK; - bits >>= LIST_STYLE_IMAGE_SHIFT; - - /* 1bit: type */ - *url = style->i.list_style_image; - - return bits; -} -#undef LIST_STYLE_IMAGE_MASK -#undef LIST_STYLE_IMAGE_SHIFT -#undef LIST_STYLE_IMAGE_INDEX - -#define QUOTES_INDEX 5 -#define QUOTES_SHIFT 0 -#define QUOTES_MASK 0x1 -static inline uint8_t get_quotes( - const css_computed_style *style, - lwc_string ***quotes) -{ - uint8_t bits = style->i.bits[QUOTES_INDEX]; - bits &= QUOTES_MASK; - bits >>= QUOTES_SHIFT; - - /* 1bit: type */ - *quotes = style->quotes; - - return bits; -} -#undef QUOTES_MASK -#undef QUOTES_SHIFT -#undef QUOTES_INDEX - -#define TOP_INDEX 6 -#define TOP_SHIFT 2 -#define TOP_MASK 0xfc -static inline uint8_t get_top( - const css_computed_style *style, - css_fixed *length, css_unit *unit) -{ - uint8_t bits = style->i.bits[TOP_INDEX]; - bits &= TOP_MASK; - bits >>= TOP_SHIFT; - - /* 6bits: uuuutt : units | type */ - if ((bits & 0x3) == CSS_TOP_SET) { - *length = style->i.top; - *unit = bits >> 2; - } - - return (bits & 0x3); -} -static inline uint8_t get_top_bits( - const css_computed_style *style) -{ - uint8_t bits = style->i.bits[TOP_INDEX]; - bits &= TOP_MASK; - bits >>= TOP_SHIFT; - - /* 6bits: uuuutt : units | type */ - return bits; -} -#undef TOP_MASK -#undef TOP_SHIFT -#undef TOP_INDEX - -#define RIGHT_INDEX 7 -#define RIGHT_SHIFT 2 -#define RIGHT_MASK 0xfc -static inline uint8_t get_right( - const css_computed_style *style, - css_fixed *length, css_unit *unit) -{ - uint8_t bits = style->i.bits[RIGHT_INDEX]; - bits &= RIGHT_MASK; - bits >>= RIGHT_SHIFT; - - /* 6bits: uuuutt : units | type */ - if ((bits & 0x3) == CSS_RIGHT_SET) { - *length = style->i.right; - *unit = bits >> 2; - } - - return (bits & 0x3); -} -static inline uint8_t get_right_bits( - const css_computed_style *style) -{ - uint8_t bits = style->i.bits[RIGHT_INDEX]; - bits &= RIGHT_MASK; - bits >>= RIGHT_SHIFT; - - /* 6bits: uuuutt : units | type */ - return bits; -} -#undef RIGHT_MASK -#undef RIGHT_SHIFT -#undef RIGHT_INDEX - -#define BOTTOM_INDEX 8 -#define BOTTOM_SHIFT 2 -#define BOTTOM_MASK 0xfc -static inline uint8_t get_bottom( - const css_computed_style *style, - css_fixed *length, css_unit *unit) -{ - uint8_t bits = style->i.bits[BOTTOM_INDEX]; - bits &= BOTTOM_MASK; - bits >>= BOTTOM_SHIFT; - - /* 6bits: uuuutt : units | type */ - if ((bits & 0x3) == CSS_BOTTOM_SET) { - *length = style->i.bottom; - *unit = bits >> 2; - } - - return (bits & 0x3); -} -static inline uint8_t get_bottom_bits( - const css_computed_style *style) -{ - uint8_t bits = style->i.bits[BOTTOM_INDEX]; - bits &= BOTTOM_MASK; - bits >>= BOTTOM_SHIFT; - - /* 6bits: uuuutt : units | type */ - return bits; -} -#undef BOTTOM_MASK -#undef BOTTOM_SHIFT -#undef BOTTOM_INDEX - -#define LEFT_INDEX 9 -#define LEFT_SHIFT 2 -#define LEFT_MASK 0xfc -static inline uint8_t get_left( - const css_computed_style *style, - css_fixed *length, css_unit *unit) -{ - uint8_t bits = style->i.bits[LEFT_INDEX]; - bits &= LEFT_MASK; - bits >>= LEFT_SHIFT; - - /* 6bits: uuuutt : units | type */ - if ((bits & 0x3) == CSS_LEFT_SET) { - *length = style->i.left; - *unit = bits >> 2; - } - - return (bits & 0x3); -} -static inline uint8_t get_left_bits( - const css_computed_style *style) -{ - uint8_t bits = style->i.bits[LEFT_INDEX]; - bits &= LEFT_MASK; - bits >>= LEFT_SHIFT; - - /* 6bits: uuuutt : units | type */ - return bits; -} -#undef LEFT_MASK -#undef LEFT_SHIFT -#undef LEFT_INDEX - -#define BORDER_TOP_COLOR_INDEX 6 -#define BORDER_TOP_COLOR_SHIFT 0 -#define BORDER_TOP_COLOR_MASK 0x3 -static inline uint8_t get_border_top_color( - const css_computed_style *style, - css_color *color) -{ - uint8_t bits = style->i.bits[BORDER_TOP_COLOR_INDEX]; - bits &= BORDER_TOP_COLOR_MASK; - bits >>= BORDER_TOP_COLOR_SHIFT; - - /* 2bits: type */ - *color = style->i.border_color[0]; - - return bits; -} -#undef BORDER_TOP_COLOR_MASK -#undef BORDER_TOP_COLOR_SHIFT -#undef BORDER_TOP_COLOR_INDEX - -#define BORDER_RIGHT_COLOR_INDEX 7 -#define BORDER_RIGHT_COLOR_SHIFT 0 -#define BORDER_RIGHT_COLOR_MASK 0x3 -static inline uint8_t get_border_right_color( - const css_computed_style *style, - css_color *color) -{ - uint8_t bits = style->i.bits[BORDER_RIGHT_COLOR_INDEX]; - bits &= BORDER_RIGHT_COLOR_MASK; - bits >>= BORDER_RIGHT_COLOR_SHIFT; - - /* 2bits: type */ - *color = style->i.border_color[1]; - - return bits; -} -#undef BORDER_RIGHT_COLOR_MASK -#undef BORDER_RIGHT_COLOR_SHIFT -#undef BORDER_RIGHT_COLOR_INDEX - -#define BORDER_BOTTOM_COLOR_INDEX 8 -#define BORDER_BOTTOM_COLOR_SHIFT 0 -#define BORDER_BOTTOM_COLOR_MASK 0x3 -static inline uint8_t get_border_bottom_color( - const css_computed_style *style, - css_color *color) -{ - uint8_t bits = style->i.bits[BORDER_BOTTOM_COLOR_INDEX]; - bits &= BORDER_BOTTOM_COLOR_MASK; - bits >>= BORDER_BOTTOM_COLOR_SHIFT; - - /* 2bits: type */ - *color = style->i.border_color[2]; - - return bits; -} -#undef BORDER_BOTTOM_COLOR_MASK -#undef BORDER_BOTTOM_COLOR_SHIFT -#undef BORDER_BOTTOM_COLOR_INDEX - -#define BORDER_LEFT_COLOR_INDEX 9 -#define BORDER_LEFT_COLOR_SHIFT 0 -#define BORDER_LEFT_COLOR_MASK 0x3 -static inline uint8_t get_border_left_color( - const css_computed_style *style, - css_color *color) -{ - uint8_t bits = style->i.bits[BORDER_LEFT_COLOR_INDEX]; - bits &= BORDER_LEFT_COLOR_MASK; - bits >>= BORDER_LEFT_COLOR_SHIFT; - - /* 2bits: type */ - *color = style->i.border_color[3]; - - return bits; -} -#undef BORDER_LEFT_COLOR_MASK -#undef BORDER_LEFT_COLOR_SHIFT -#undef BORDER_LEFT_COLOR_INDEX - -#define HEIGHT_INDEX 10 -#define HEIGHT_SHIFT 2 -#define HEIGHT_MASK 0xfc -static inline uint8_t get_height( - const css_computed_style *style, - css_fixed *length, css_unit *unit) -{ - uint8_t bits = style->i.bits[HEIGHT_INDEX]; - bits &= HEIGHT_MASK; - bits >>= HEIGHT_SHIFT; - - /* 6bits: uuuutt : units | type */ - if ((bits & 0x3) == CSS_HEIGHT_SET) { - *length = style->i.height; - *unit = bits >> 2; - } - - return (bits & 0x3); -} -#undef HEIGHT_MASK -#undef HEIGHT_SHIFT -#undef HEIGHT_INDEX - -#define LINE_HEIGHT_INDEX 11 -#define LINE_HEIGHT_SHIFT 2 -#define LINE_HEIGHT_MASK 0xfc -static inline uint8_t get_line_height( - const css_computed_style *style, - css_fixed *length, css_unit *unit) -{ - uint8_t bits = style->i.bits[LINE_HEIGHT_INDEX]; - bits &= LINE_HEIGHT_MASK; - bits >>= LINE_HEIGHT_SHIFT; - - /* 6bits: uuuutt : units | type */ - if ((bits & 0x3) == CSS_LINE_HEIGHT_NUMBER || - (bits & 0x3) == CSS_LINE_HEIGHT_DIMENSION) { - *length = style->i.line_height; - } - - if ((bits & 0x3) == CSS_LINE_HEIGHT_DIMENSION) { - *unit = bits >> 2; - } - - return (bits & 0x3); -} -#undef LINE_HEIGHT_MASK -#undef LINE_HEIGHT_SHIFT -#undef LINE_HEIGHT_INDEX - -#define BACKGROUND_COLOR_INDEX 10 -#define BACKGROUND_COLOR_SHIFT 0 -#define BACKGROUND_COLOR_MASK 0x3 -static inline uint8_t get_background_color( - const css_computed_style *style, - css_color *color) -{ - uint8_t bits = style->i.bits[BACKGROUND_COLOR_INDEX]; - bits &= BACKGROUND_COLOR_MASK; - bits >>= BACKGROUND_COLOR_SHIFT; - - /* 2bits: type */ - *color = style->i.background_color; - - return bits; -} -#undef BACKGROUND_COLOR_MASK -#undef BACKGROUND_COLOR_SHIFT -#undef BACKGROUND_COLOR_INDEX - -#define Z_INDEX_INDEX 11 -#define Z_INDEX_SHIFT 0 -#define Z_INDEX_MASK 0x3 -static inline uint8_t get_z_index( - const css_computed_style *style, - int32_t *z_index) -{ - uint8_t bits = style->i.bits[Z_INDEX_INDEX]; - bits &= Z_INDEX_MASK; - bits >>= Z_INDEX_SHIFT; - - /* 2bits: type */ - *z_index = style->i.z_index; - - return bits; -} -#undef Z_INDEX_MASK -#undef Z_INDEX_SHIFT -#undef Z_INDEX_INDEX - -#define MARGIN_TOP_INDEX 12 -#define MARGIN_TOP_SHIFT 2 -#define MARGIN_TOP_MASK 0xfc -static inline uint8_t get_margin_top( - const css_computed_style *style, - css_fixed *length, css_unit *unit) -{ - uint8_t bits = style->i.bits[MARGIN_TOP_INDEX]; - bits &= MARGIN_TOP_MASK; - bits >>= MARGIN_TOP_SHIFT; - - /* 6bits: uuuutt : units | type */ - if ((bits & 0x3) == CSS_MARGIN_SET) { - *length = style->i.margin[0]; - *unit = bits >> 2; - } - - return (bits & 0x3); -} -#undef MARGIN_TOP_MASK -#undef MARGIN_TOP_SHIFT -#undef MARGIN_TOP_INDEX - -#define MARGIN_RIGHT_INDEX 13 -#define MARGIN_RIGHT_SHIFT 2 -#define MARGIN_RIGHT_MASK 0xfc -static inline uint8_t get_margin_right( - const css_computed_style *style, - css_fixed *length, css_unit *unit) -{ - uint8_t bits = style->i.bits[MARGIN_RIGHT_INDEX]; - bits &= MARGIN_RIGHT_MASK; - bits >>= MARGIN_RIGHT_SHIFT; - - /* 6bits: uuuutt : units | type */ - if ((bits & 0x3) == CSS_MARGIN_SET) { - *length = style->i.margin[1]; - *unit = bits >> 2; - } - - return (bits & 0x3); -} -#undef MARGIN_RIGHT_MASK -#undef MARGIN_RIGHT_SHIFT -#undef MARGIN_RIGHT_INDEX - -#define MARGIN_BOTTOM_INDEX 14 -#define MARGIN_BOTTOM_SHIFT 2 -#define MARGIN_BOTTOM_MASK 0xfc -static inline uint8_t get_margin_bottom( - const css_computed_style *style, - css_fixed *length, css_unit *unit) -{ - uint8_t bits = style->i.bits[MARGIN_BOTTOM_INDEX]; - bits &= MARGIN_BOTTOM_MASK; - bits >>= MARGIN_BOTTOM_SHIFT; - - /* 6bits: uuuutt : units | type */ - if ((bits & 0x3) == CSS_MARGIN_SET) { - *length = style->i.margin[2]; - *unit = bits >> 2; - } - - return (bits & 0x3); -} -#undef MARGIN_BOTTOM_MASK -#undef MARGIN_BOTTOM_SHIFT -#undef MARGIN_BOTTOM_INDEX - -#define MARGIN_LEFT_INDEX 15 -#define MARGIN_LEFT_SHIFT 2 -#define MARGIN_LEFT_MASK 0xfc -static inline uint8_t get_margin_left( - const css_computed_style *style, - css_fixed *length, css_unit *unit) -{ - uint8_t bits = style->i.bits[MARGIN_LEFT_INDEX]; - bits &= MARGIN_LEFT_MASK; - bits >>= MARGIN_LEFT_SHIFT; - - /* 6bits: uuuutt : units | type */ - if ((bits & 0x3) == CSS_MARGIN_SET) { - *length = style->i.margin[3]; - *unit = bits >> 2; - } - - return (bits & 0x3); -} -#undef MARGIN_LEFT_MASK -#undef MARGIN_LEFT_SHIFT -#undef MARGIN_LEFT_INDEX - -#define BACKGROUND_ATTACHMENT_INDEX 12 -#define BACKGROUND_ATTACHMENT_SHIFT 0 -#define BACKGROUND_ATTACHMENT_MASK 0x3 -static inline uint8_t get_background_attachment( - const css_computed_style *style) -{ - uint8_t bits = style->i.bits[BACKGROUND_ATTACHMENT_INDEX]; - bits &= BACKGROUND_ATTACHMENT_MASK; - bits >>= BACKGROUND_ATTACHMENT_SHIFT; - - /* 2bits: type */ - return bits; -} -#undef BACKGROUND_ATTACHMENT_MASK -#undef BACKGROUND_ATTACHMENT_SHIFT -#undef BACKGROUND_ATTACHMENT_INDEX - -#define BOX_SIZING_INDEX 34 -#define BOX_SIZING_SHIFT 0 -#define BOX_SIZING_MASK 0x3 -static inline uint8_t get_box_sizing( - const css_computed_style *style) -{ - uint8_t bits = style->i.bits[BOX_SIZING_INDEX]; - bits &= BOX_SIZING_MASK; - bits >>= BOX_SIZING_SHIFT; - - /* 2bits: type */ - return bits; -} -#undef BOX_SIZING_MASK -#undef BOX_SIZING_SHIFT -#undef BOX_SIZING_INDEX - -#define BORDER_COLLAPSE_INDEX 13 -#define BORDER_COLLAPSE_SHIFT 0 -#define BORDER_COLLAPSE_MASK 0x3 -static inline uint8_t get_border_collapse( - const css_computed_style *style) -{ - uint8_t bits = style->i.bits[BORDER_COLLAPSE_INDEX]; - bits &= BORDER_COLLAPSE_MASK; - bits >>= BORDER_COLLAPSE_SHIFT; - - /* 2bits: type */ - return bits; -} -#undef BORDER_COLLAPSE_MASK -#undef BORDER_COLLAPSE_SHIFT -#undef BORDER_COLLAPSE_INDEX - -#define CAPTION_SIDE_INDEX 14 -#define CAPTION_SIDE_SHIFT 0 -#define CAPTION_SIDE_MASK 0x3 -static inline uint8_t get_caption_side( - const css_computed_style *style) -{ - uint8_t bits = style->i.bits[CAPTION_SIDE_INDEX]; - bits &= CAPTION_SIDE_MASK; - bits >>= CAPTION_SIDE_SHIFT; - - /* 2bits: type */ - return bits; -} -#undef CAPTION_SIDE_MASK -#undef CAPTION_SIDE_SHIFT -#undef CAPTION_SIDE_INDEX - -#define DIRECTION_INDEX 15 -#define DIRECTION_SHIFT 0 -#define DIRECTION_MASK 0x3 -static inline uint8_t get_direction( - const css_computed_style *style) -{ - uint8_t bits = style->i.bits[DIRECTION_INDEX]; - bits &= DIRECTION_MASK; - bits >>= DIRECTION_SHIFT; - - /* 2bits: type */ - return bits; -} -#undef DIRECTION_MASK -#undef DIRECTION_SHIFT -#undef DIRECTION_INDEX - -#define MAX_HEIGHT_INDEX 16 -#define MAX_HEIGHT_SHIFT 2 -#define MAX_HEIGHT_MASK 0xfc -static inline uint8_t get_max_height( - const css_computed_style *style, - css_fixed *length, css_unit *unit) -{ - uint8_t bits = style->i.bits[MAX_HEIGHT_INDEX]; - bits &= MAX_HEIGHT_MASK; - bits >>= MAX_HEIGHT_SHIFT; - - /* 6bits: uuuutt : units | type */ - if ((bits & 0x3) == CSS_MAX_HEIGHT_SET) { - *length = style->i.max_height; - *unit = bits >> 2; - } - - return (bits & 0x3); -} -#undef MAX_HEIGHT_MASK -#undef MAX_HEIGHT_SHIFT -#undef MAX_HEIGHT_INDEX - -#define MAX_WIDTH_INDEX 17 -#define MAX_WIDTH_SHIFT 2 -#define MAX_WIDTH_MASK 0xfc -static inline uint8_t get_max_width( - const css_computed_style *style, - css_fixed *length, css_unit *unit) -{ - uint8_t bits = style->i.bits[MAX_WIDTH_INDEX]; - bits &= MAX_WIDTH_MASK; - bits >>= MAX_WIDTH_SHIFT; - - /* 6bits: uuuutt : units | type */ - if ((bits & 0x3) == CSS_MAX_WIDTH_SET) { - *length = style->i.max_width; - *unit = bits >> 2; - } - - return (bits & 0x3); -} -#undef MAX_WIDTH_MASK -#undef MAX_WIDTH_SHIFT -#undef MAX_WIDTH_INDEX - -#define WIDTH_INDEX 18 -#define WIDTH_SHIFT 2 -#define WIDTH_MASK 0xfc -static inline uint8_t get_width( - const css_computed_style *style, - css_fixed *length, css_unit *unit) -{ - uint8_t bits = style->i.bits[WIDTH_INDEX]; - bits &= WIDTH_MASK; - bits >>= WIDTH_SHIFT; - - /* 6bits: uuuutt : units | type */ - if ((bits & 0x3) == CSS_WIDTH_SET) { - *length = style->i.width; - *unit = bits >> 2; - } - - return (bits & 0x3); -} -#undef WIDTH_MASK -#undef WIDTH_SHIFT -#undef WIDTH_INDEX - -#define EMPTY_CELLS_INDEX 16 -#define EMPTY_CELLS_SHIFT 0 -#define EMPTY_CELLS_MASK 0x3 -static inline uint8_t get_empty_cells( - const css_computed_style *style) -{ - uint8_t bits = style->i.bits[EMPTY_CELLS_INDEX]; - bits &= EMPTY_CELLS_MASK; - bits >>= EMPTY_CELLS_SHIFT; - - /* 2bits: type */ - return bits; -} -#undef EMPTY_CELLS_MASK -#undef EMPTY_CELLS_SHIFT -#undef EMPTY_CELLS_INDEX - -#define FLOAT_INDEX 17 -#define FLOAT_SHIFT 0 -#define FLOAT_MASK 0x3 -static inline uint8_t get_float( - const css_computed_style *style) -{ - uint8_t bits = style->i.bits[FLOAT_INDEX]; - bits &= FLOAT_MASK; - bits >>= FLOAT_SHIFT; - - /* 2bits: type */ - return bits; -} -#undef FLOAT_MASK -#undef FLOAT_SHIFT -#undef FLOAT_INDEX - -#define FONT_STYLE_INDEX 18 -#define FONT_STYLE_SHIFT 0 -#define FONT_STYLE_MASK 0x3 -static inline uint8_t get_font_style( - const css_computed_style *style) -{ - uint8_t bits = style->i.bits[FONT_STYLE_INDEX]; - bits &= FONT_STYLE_MASK; - bits >>= FONT_STYLE_SHIFT; - - /* 2bits: type */ - return bits; -} -#undef FONT_STYLE_MASK -#undef FONT_STYLE_SHIFT -#undef FONT_STYLE_INDEX - -#define MIN_HEIGHT_INDEX 19 -#define MIN_HEIGHT_SHIFT 3 -#define MIN_HEIGHT_MASK 0xf8 -static inline uint8_t get_min_height( - const css_computed_style *style, - css_fixed *length, css_unit *unit) -{ - uint8_t bits = style->i.bits[MIN_HEIGHT_INDEX]; - bits &= MIN_HEIGHT_MASK; - bits >>= MIN_HEIGHT_SHIFT; - - /* 5bits: uuuut : units | type */ - if ((bits & 0x1) == CSS_MIN_HEIGHT_SET) { - *length = style->i.min_height; - *unit = bits >> 1; - } - - return (bits & 0x1); -} -#undef MIN_HEIGHT_MASK -#undef MIN_HEIGHT_SHIFT -#undef MIN_HEIGHT_INDEX - -#define MIN_WIDTH_INDEX 20 -#define MIN_WIDTH_SHIFT 3 -#define MIN_WIDTH_MASK 0xf8 -static inline uint8_t get_min_width( - const css_computed_style *style, - css_fixed *length, css_unit *unit) -{ - uint8_t bits = style->i.bits[MIN_WIDTH_INDEX]; - bits &= MIN_WIDTH_MASK; - bits >>= MIN_WIDTH_SHIFT; - - /* 5bits: uuuut : units | type */ - if ((bits & 0x1) == CSS_MIN_WIDTH_SET) { - *length = style->i.min_width; - *unit = bits >> 1; - } - - return (bits & 0x1); -} -#undef MIN_WIDTH_MASK -#undef MIN_WIDTH_SHIFT -#undef MIN_WIDTH_INDEX - -#define BACKGROUND_REPEAT_INDEX 19 -#define BACKGROUND_REPEAT_SHIFT 0 -#define BACKGROUND_REPEAT_MASK 0x7 -static inline uint8_t get_background_repeat( - const css_computed_style *style) -{ - uint8_t bits = style->i.bits[BACKGROUND_REPEAT_INDEX]; - bits &= BACKGROUND_REPEAT_MASK; - bits >>= BACKGROUND_REPEAT_SHIFT; - - /* 3bits: type */ - return bits; -} -#undef BACKGROUND_REPEAT_MASK -#undef BACKGROUND_REPEAT_SHIFT -#undef BACKGROUND_REPEAT_INDEX - -#define CLEAR_INDEX 20 -#define CLEAR_SHIFT 0 -#define CLEAR_MASK 0x7 -static inline uint8_t get_clear( - const css_computed_style *style) -{ - uint8_t bits = style->i.bits[CLEAR_INDEX]; - bits &= CLEAR_MASK; - bits >>= CLEAR_SHIFT; - - /* 3bits: type */ - return bits; -} -#undef CLEAR_MASK -#undef CLEAR_SHIFT -#undef CLEAR_INDEX - -#define PADDING_TOP_INDEX 21 -#define PADDING_TOP_SHIFT 3 -#define PADDING_TOP_MASK 0xf8 -static inline uint8_t get_padding_top( - const css_computed_style *style, - css_fixed *length, css_unit *unit) -{ - uint8_t bits = style->i.bits[PADDING_TOP_INDEX]; - bits &= PADDING_TOP_MASK; - bits >>= PADDING_TOP_SHIFT; - - /* 5bits: uuuut : units | type */ - if ((bits & 0x1) == CSS_PADDING_SET) { - *length = style->i.padding[0]; - *unit = bits >> 1; - } - - return (bits & 0x1); -} -#undef PADDING_TOP_MASK -#undef PADDING_TOP_SHIFT -#undef PADDING_TOP_INDEX - -#define PADDING_RIGHT_INDEX 22 -#define PADDING_RIGHT_SHIFT 3 -#define PADDING_RIGHT_MASK 0xf8 -static inline uint8_t get_padding_right( - const css_computed_style *style, - css_fixed *length, css_unit *unit) -{ - uint8_t bits = style->i.bits[PADDING_RIGHT_INDEX]; - bits &= PADDING_RIGHT_MASK; - bits >>= PADDING_RIGHT_SHIFT; - - /* 5bits: uuuut : units | type */ - if ((bits & 0x1) == CSS_PADDING_SET) { - *length = style->i.padding[1]; - *unit = bits >> 1; - } - - return (bits & 0x1); -} -#undef PADDING_RIGHT_MASK -#undef PADDING_RIGHT_SHIFT -#undef PADDING_RIGHT_INDEX - -#define PADDING_BOTTOM_INDEX 23 -#define PADDING_BOTTOM_SHIFT 3 -#define PADDING_BOTTOM_MASK 0xf8 -static inline uint8_t get_padding_bottom( - const css_computed_style *style, - css_fixed *length, css_unit *unit) -{ - uint8_t bits = style->i.bits[PADDING_BOTTOM_INDEX]; - bits &= PADDING_BOTTOM_MASK; - bits >>= PADDING_BOTTOM_SHIFT; - - /* 5bits: uuuut : units | type */ - if ((bits & 0x1) == CSS_PADDING_SET) { - *length = style->i.padding[2]; - *unit = bits >> 1; - } - - return (bits & 0x1); -} -#undef PADDING_BOTTOM_MASK -#undef PADDING_BOTTOM_SHIFT -#undef PADDING_BOTTOM_INDEX - -#define PADDING_LEFT_INDEX 24 -#define PADDING_LEFT_SHIFT 3 -#define PADDING_LEFT_MASK 0xf8 -static inline uint8_t get_padding_left( - const css_computed_style *style, - css_fixed *length, css_unit *unit) -{ - uint8_t bits = style->i.bits[PADDING_LEFT_INDEX]; - bits &= PADDING_LEFT_MASK; - bits >>= PADDING_LEFT_SHIFT; - - /* 5bits: uuuut : units | type */ - if ((bits & 0x1) == CSS_PADDING_SET) { - *length = style->i.padding[3]; - *unit = bits >> 1; - } - - return (bits & 0x1); -} -#undef PADDING_LEFT_MASK -#undef PADDING_LEFT_SHIFT -#undef PADDING_LEFT_INDEX - -#define OVERFLOW_X_INDEX 21 -#define OVERFLOW_X_SHIFT 0 -#define OVERFLOW_X_MASK 0x7 -static inline uint8_t get_overflow_x( - const css_computed_style *style) -{ - uint8_t bits = style->i.bits[OVERFLOW_X_INDEX]; - bits &= OVERFLOW_X_MASK; - bits >>= OVERFLOW_X_SHIFT; - - /* 3bits: type */ - return bits; -} -#undef OVERFLOW_X_MASK -#undef OVERFLOW_X_SHIFT -#undef OVERFLOW_X_INDEX - -#define OVERFLOW_Y_INDEX 34 -#define OVERFLOW_Y_SHIFT 5 -#define OVERFLOW_Y_MASK 0xe0 -static inline uint8_t get_overflow_y( - const css_computed_style *style) -{ - uint8_t bits = style->i.bits[OVERFLOW_Y_INDEX]; - bits &= OVERFLOW_Y_MASK; - bits >>= OVERFLOW_Y_SHIFT; - - /* 3bits: type */ - return bits; -} -#undef OVERFLOW_Y_MASK -#undef OVERFLOW_Y_SHIFT -#undef OVERFLOW_Y_INDEX - -#define POSITION_INDEX 22 -#define POSITION_SHIFT 0 -#define POSITION_MASK 0x7 -static inline uint8_t get_position( - const css_computed_style *style) -{ - uint8_t bits = style->i.bits[POSITION_INDEX]; - bits &= POSITION_MASK; - bits >>= POSITION_SHIFT; - - /* 3bits: type */ - return bits; -} -#undef POSITION_MASK -#undef POSITION_SHIFT -#undef POSITION_INDEX - -#define OPACITY_INDEX 23 -#define OPACITY_SHIFT 2 -#define OPACITY_MASK 0x04 -static inline uint8_t get_opacity( - const css_computed_style *style, - css_fixed *opacity) -{ - uint8_t bits = style->i.bits[OPACITY_INDEX]; - bits &= OPACITY_MASK; - bits >>= OPACITY_SHIFT; - - /* 1bit: t : type */ - if ((bits & 0x1) == CSS_OPACITY_SET) { - *opacity = style->i.opacity; - } - - return (bits & 0x1); -} -#undef OPACITY_MASK -#undef OPACITY_SHIFT -#undef OPACITY_INDEX - -#define TEXT_TRANSFORM_INDEX 24 -#define TEXT_TRANSFORM_SHIFT 0 -#define TEXT_TRANSFORM_MASK 0x7 -static inline uint8_t get_text_transform( - const css_computed_style *style) -{ - uint8_t bits = style->i.bits[TEXT_TRANSFORM_INDEX]; - bits &= TEXT_TRANSFORM_MASK; - bits >>= TEXT_TRANSFORM_SHIFT; - - /* 3bits: type */ - return bits; -} -#undef TEXT_TRANSFORM_MASK -#undef TEXT_TRANSFORM_SHIFT -#undef TEXT_TRANSFORM_INDEX - -#define TEXT_INDENT_INDEX 25 -#define TEXT_INDENT_SHIFT 3 -#define TEXT_INDENT_MASK 0xf8 -static inline uint8_t get_text_indent( - const css_computed_style *style, - css_fixed *length, css_unit *unit) -{ - uint8_t bits = style->i.bits[TEXT_INDENT_INDEX]; - bits &= TEXT_INDENT_MASK; - bits >>= TEXT_INDENT_SHIFT; - - /* 5bits: uuuut : units | type */ - if ((bits & 0x1) == CSS_TEXT_INDENT_SET) { - *length = style->i.text_indent; - *unit = bits >> 1; - } - - return (bits & 0x1); -} -#undef TEXT_INDENT_MASK -#undef TEXT_INDENT_SHIFT -#undef TEXT_INDENT_INDEX - -#define WHITE_SPACE_INDEX 25 -#define WHITE_SPACE_SHIFT 0 -#define WHITE_SPACE_MASK 0x7 -static inline uint8_t get_white_space( - const css_computed_style *style) -{ - uint8_t bits = style->i.bits[WHITE_SPACE_INDEX]; - bits &= WHITE_SPACE_MASK; - bits >>= WHITE_SPACE_SHIFT; - - /* 3bits: type */ - return bits; -} -#undef WHITE_SPACE_MASK -#undef WHITE_SPACE_SHIFT -#undef WHITE_SPACE_INDEX - -#define BACKGROUND_POSITION_INDEX 27 -#define BACKGROUND_POSITION_SHIFT 7 -#define BACKGROUND_POSITION_MASK 0x80 -#define BACKGROUND_POSITION_INDEX1 26 -#define BACKGROUND_POSITION_SHIFT1 0 -#define BACKGROUND_POSITION_MASK1 0xff -static inline uint8_t get_background_position( - const css_computed_style *style, - css_fixed *hlength, css_unit *hunit, - css_fixed *vlength, css_unit *vunit) -{ - uint8_t bits = style->i.bits[BACKGROUND_POSITION_INDEX]; - bits &= BACKGROUND_POSITION_MASK; - bits >>= BACKGROUND_POSITION_SHIFT; - - /* 1bit: type */ - if (bits == CSS_BACKGROUND_POSITION_SET) { - uint8_t bits1 = style->i.bits[BACKGROUND_POSITION_INDEX1]; - bits1 &= BACKGROUND_POSITION_MASK1; - bits1 >>= BACKGROUND_POSITION_SHIFT1; - - /* 8bits: hhhhvvvv : hunit | vunit */ - *hlength = style->i.background_position[0]; - *hunit = bits1 >> 4; - - *vlength = style->i.background_position[1]; - *vunit = bits1 & 0xf; - } - - return bits; -} -#undef BACKGROUND_POSITION_MASK1 -#undef BACKGROUND_POSITION_SHIFT1 -#undef BACKGROUND_POSITION_INDEX1 -#undef BACKGROUND_POSITION_MASK -#undef BACKGROUND_POSITION_SHIFT -#undef BACKGROUND_POSITION_INDEX - -#define DISPLAY_INDEX 27 -#define DISPLAY_SHIFT 2 -#define DISPLAY_MASK 0x7c -static inline uint8_t get_display( - const css_computed_style *style) -{ - uint8_t bits = style->i.bits[DISPLAY_INDEX]; - bits &= DISPLAY_MASK; - bits >>= DISPLAY_SHIFT; - - /* 5bits: type */ - return bits; -} -#undef DISPLAY_MASK -#undef DISPLAY_SHIFT -#undef DISPLAY_INDEX - -#define FONT_VARIANT_INDEX 27 -#define FONT_VARIANT_SHIFT 0 -#define FONT_VARIANT_MASK 0x3 -static inline uint8_t get_font_variant( - const css_computed_style *style) -{ - uint8_t bits = style->i.bits[FONT_VARIANT_INDEX]; - bits &= FONT_VARIANT_MASK; - bits >>= FONT_VARIANT_SHIFT; - - /* 2bits: type */ - return bits; -} -#undef FONT_VARIANT_MASK -#undef FONT_VARIANT_SHIFT -#undef FONT_VARIANT_INDEX - -#define TEXT_DECORATION_INDEX 28 -#define TEXT_DECORATION_SHIFT 3 -#define TEXT_DECORATION_MASK 0xf8 -static inline uint8_t get_text_decoration( - const css_computed_style *style) -{ - uint8_t bits = style->i.bits[TEXT_DECORATION_INDEX]; - bits &= TEXT_DECORATION_MASK; - bits >>= TEXT_DECORATION_SHIFT; - - /* 5bits: type */ - return bits; -} -#undef TEXT_DECORATION_MASK -#undef TEXT_DECORATION_SHIFT -#undef TEXT_DECORATION_INDEX - -#define FONT_FAMILY_INDEX 28 -#define FONT_FAMILY_SHIFT 0 -#define FONT_FAMILY_MASK 0x7 -static inline uint8_t get_font_family( - const css_computed_style *style, - lwc_string ***names) -{ - uint8_t bits = style->i.bits[FONT_FAMILY_INDEX]; - bits &= FONT_FAMILY_MASK; - bits >>= FONT_FAMILY_SHIFT; - - /* 3bits: type */ - *names = style->font_family; - - return bits; -} -#undef FONT_FAMILY_MASK -#undef FONT_FAMILY_SHIFT -#undef FONT_FAMILY_INDEX - -#define BORDER_TOP_STYLE_INDEX 29 -#define BORDER_TOP_STYLE_SHIFT 4 -#define BORDER_TOP_STYLE_MASK 0xf0 -static inline uint8_t get_border_top_style( - const css_computed_style *style) -{ - uint8_t bits = style->i.bits[BORDER_TOP_STYLE_INDEX]; - bits &= BORDER_TOP_STYLE_MASK; - bits >>= BORDER_TOP_STYLE_SHIFT; - - /* 4bits: type */ - return bits; -} -#undef BORDER_TOP_STYLE_MASK -#undef BORDER_TOP_STYLE_SHIFT -#undef BORDER_TOP_STYLE_INDEX - -#define BORDER_RIGHT_STYLE_INDEX 29 -#define BORDER_RIGHT_STYLE_SHIFT 0 -#define BORDER_RIGHT_STYLE_MASK 0xf -static inline uint8_t get_border_right_style( - const css_computed_style *style) -{ - uint8_t bits = style->i.bits[BORDER_RIGHT_STYLE_INDEX]; - bits &= BORDER_RIGHT_STYLE_MASK; - bits >>= BORDER_RIGHT_STYLE_SHIFT; - - /* 4bits: type */ - return bits; -} -#undef BORDER_RIGHT_STYLE_MASK -#undef BORDER_RIGHT_STYLE_SHIFT -#undef BORDER_RIGHT_STYLE_INDEX - -#define BORDER_BOTTOM_STYLE_INDEX 30 -#define BORDER_BOTTOM_STYLE_SHIFT 4 -#define BORDER_BOTTOM_STYLE_MASK 0xf0 -static inline uint8_t get_border_bottom_style( - const css_computed_style *style) -{ - uint8_t bits = style->i.bits[BORDER_BOTTOM_STYLE_INDEX]; - bits &= BORDER_BOTTOM_STYLE_MASK; - bits >>= BORDER_BOTTOM_STYLE_SHIFT; - - /* 4bits: type */ - return bits; -} -#undef BORDER_BOTTOM_STYLE_MASK -#undef BORDER_BOTTOM_STYLE_SHIFT -#undef BORDER_BOTTOM_STYLE_INDEX - -#define BORDER_LEFT_STYLE_INDEX 30 -#define BORDER_LEFT_STYLE_SHIFT 0 -#define BORDER_LEFT_STYLE_MASK 0xf -static inline uint8_t get_border_left_style( - const css_computed_style *style) -{ - uint8_t bits = style->i.bits[BORDER_LEFT_STYLE_INDEX]; - bits &= BORDER_LEFT_STYLE_MASK; - bits >>= BORDER_LEFT_STYLE_SHIFT; - - /* 4bits: type */ - return bits; -} -#undef BORDER_LEFT_STYLE_MASK -#undef BORDER_LEFT_STYLE_SHIFT -#undef BORDER_LEFT_STYLE_INDEX - -#define FONT_WEIGHT_INDEX 31 -#define FONT_WEIGHT_SHIFT 4 -#define FONT_WEIGHT_MASK 0xf0 -static inline uint8_t get_font_weight( - const css_computed_style *style) -{ - uint8_t bits = style->i.bits[FONT_WEIGHT_INDEX]; - bits &= FONT_WEIGHT_MASK; - bits >>= FONT_WEIGHT_SHIFT; - - /* 4bits: type */ - return bits; -} -#undef FONT_WEIGHT_MASK -#undef FONT_WEIGHT_SHIFT -#undef FONT_WEIGHT_INDEX - -#define LIST_STYLE_TYPE_INDEX 31 -#define LIST_STYLE_TYPE_SHIFT 0 -#define LIST_STYLE_TYPE_MASK 0xf -static inline uint8_t get_list_style_type( - const css_computed_style *style) -{ - uint8_t bits = style->i.bits[LIST_STYLE_TYPE_INDEX]; - bits &= LIST_STYLE_TYPE_MASK; - bits >>= LIST_STYLE_TYPE_SHIFT; - - /* 4bits: type */ - return bits; -} -#undef LIST_STYLE_TYPE_MASK -#undef LIST_STYLE_TYPE_SHIFT -#undef LIST_STYLE_TYPE_INDEX - -#define OUTLINE_STYLE_INDEX 32 -#define OUTLINE_STYLE_SHIFT 4 -#define OUTLINE_STYLE_MASK 0xf0 -static inline uint8_t get_outline_style( - const css_computed_style *style) -{ - uint8_t bits = style->i.bits[OUTLINE_STYLE_INDEX]; - bits &= OUTLINE_STYLE_MASK; - bits >>= OUTLINE_STYLE_SHIFT; - - /* 4bits: type */ - return bits; -} -#undef OUTLINE_STYLE_MASK -#undef OUTLINE_STYLE_SHIFT -#undef OUTLINE_STYLE_INDEX - -#define TABLE_LAYOUT_INDEX 32 -#define TABLE_LAYOUT_SHIFT 2 -#define TABLE_LAYOUT_MASK 0xc -static inline uint8_t get_table_layout( - const css_computed_style *style) -{ - uint8_t bits = style->i.bits[TABLE_LAYOUT_INDEX]; - bits &= TABLE_LAYOUT_MASK; - bits >>= TABLE_LAYOUT_SHIFT; - - /* 2bits: type */ - return bits; -} -#undef TABLE_LAYOUT_MASK -#undef TABLE_LAYOUT_SHIFT -#undef TABLE_LAYOUT_INDEX - -#define UNICODE_BIDI_INDEX 32 -#define UNICODE_BIDI_SHIFT 0 -#define UNICODE_BIDI_MASK 0x3 -static inline uint8_t get_unicode_bidi( - const css_computed_style *style) -{ - uint8_t bits = style->i.bits[UNICODE_BIDI_INDEX]; - bits &= UNICODE_BIDI_MASK; - bits >>= UNICODE_BIDI_SHIFT; - - /* 2bits: type */ - return bits; -} -#undef UNICODE_BIDI_MASK -#undef UNICODE_BIDI_SHIFT -#undef UNICODE_BIDI_INDEX - -#define VISIBILITY_INDEX 33 -#define VISIBILITY_SHIFT 6 -#define VISIBILITY_MASK 0xc0 -static inline uint8_t get_visibility( - const css_computed_style *style) -{ - uint8_t bits = style->i.bits[VISIBILITY_INDEX]; - bits &= VISIBILITY_MASK; - bits >>= VISIBILITY_SHIFT; - - /* 2bits: type */ - return bits; -} -#undef VISIBILITY_MASK -#undef VISIBILITY_SHIFT -#undef VISIBILITY_INDEX - -#define LIST_STYLE_POSITION_INDEX 33 -#define LIST_STYLE_POSITION_SHIFT 4 -#define LIST_STYLE_POSITION_MASK 0x30 -static inline uint8_t get_list_style_position( - const css_computed_style *style) -{ - uint8_t bits = style->i.bits[LIST_STYLE_POSITION_INDEX]; - bits &= LIST_STYLE_POSITION_MASK; - bits >>= LIST_STYLE_POSITION_SHIFT; - - /* 2bits: type */ - return bits; -} -#undef LIST_STYLE_POSITION_MASK -#undef LIST_STYLE_POSITION_SHIFT -#undef LIST_STYLE_POSITION_INDEX - -#define TEXT_ALIGN_INDEX 33 -#define TEXT_ALIGN_SHIFT 0 -#define TEXT_ALIGN_MASK 0xf -static inline uint8_t get_text_align( - const css_computed_style *style) -{ - uint8_t bits = style->i.bits[TEXT_ALIGN_INDEX]; - bits &= TEXT_ALIGN_MASK; - bits >>= TEXT_ALIGN_SHIFT; - - /* 4bits: type */ - return bits; -} -#undef TEXT_ALIGN_MASK -#undef TEXT_ALIGN_SHIFT -#undef TEXT_ALIGN_INDEX - -#define PAGE_BREAK_AFTER_INDEX 0 -#define PAGE_BREAK_AFTER_SHIFT 0 -#define PAGE_BREAK_AFTER_MASK 0x7 -static inline uint8_t get_page_break_after( - const css_computed_style *style) -{ - if (style->page != NULL) { - uint8_t bits = style->page->bits[PAGE_BREAK_AFTER_INDEX]; - bits &= PAGE_BREAK_AFTER_MASK; - bits >>= PAGE_BREAK_AFTER_SHIFT; - - /* 3bits: type */ - return bits; - } - - /* Initial value */ - return CSS_PAGE_BREAK_AFTER_AUTO; -} -#undef PAGE_BREAK_AFTER_MASK -#undef PAGE_BREAK_AFTER_SHIFT -#undef PAGE_BREAK_AFTER_INDEX - -#define PAGE_BREAK_BEFORE_INDEX 0 -#define PAGE_BREAK_BEFORE_SHIFT 3 -#define PAGE_BREAK_BEFORE_MASK 0x38 -static inline uint8_t get_page_break_before( - const css_computed_style *style) -{ - if (style->page != NULL) { - uint8_t bits = style->page->bits[PAGE_BREAK_BEFORE_INDEX]; - bits &= PAGE_BREAK_BEFORE_MASK; - bits >>= PAGE_BREAK_BEFORE_SHIFT; - - /* 3bits: type */ - return bits; - } - - /* Initial value */ - return CSS_PAGE_BREAK_BEFORE_AUTO; -} -#undef PAGE_BREAK_BEFORE_MASK -#undef PAGE_BREAK_BEFORE_SHIFT -#undef PAGE_BREAK_BEFORE_INDEX - -#define PAGE_BREAK_INSIDE_INDEX 0 -#define PAGE_BREAK_INSIDE_SHIFT 6 -#define PAGE_BREAK_INSIDE_MASK 0xc0 -static inline uint8_t get_page_break_inside( - const css_computed_style *style) -{ - if (style->page != NULL) { - uint8_t bits = style->page->bits[PAGE_BREAK_INSIDE_INDEX]; - bits &= PAGE_BREAK_INSIDE_MASK; - bits >>= PAGE_BREAK_INSIDE_SHIFT; - - /* 2bits: type */ - return bits; - } - - /* Initial value */ - return CSS_PAGE_BREAK_INSIDE_AUTO; -} -#undef PAGE_BREAK_INSIDE_MASK -#undef PAGE_BREAK_INSIDE_SHIFT -#undef PAGE_BREAK_INSIDE_INDEX - -#define ORPHANS_INDEX 1 -#define ORPHANS_SHIFT 0 -#define ORPHANS_MASK 0x1 -static inline uint8_t get_orphans( - const css_computed_style *style, - int32_t *orphans) -{ - if (style->page != NULL) { - uint8_t bits = style->page->bits[ORPHANS_INDEX]; - bits &= ORPHANS_MASK; - bits >>= ORPHANS_SHIFT; - - *orphans = style->page->orphans; - - /* 1bit: type */ - return bits; - } - - /* Initial value */ - *orphans = 2; - return CSS_ORPHANS_SET; -} -#undef ORPHANS_MASK -#undef ORPHANS_SHIFT -#undef ORPHANS_INDEX - -#define WIDOWS_INDEX 1 -#define WIDOWS_SHIFT 1 -#define WIDOWS_MASK 0x2 -static inline uint8_t get_widows( - const css_computed_style *style, - int32_t *widows) -{ - if (style->page != NULL) { - uint8_t bits = style->page->bits[WIDOWS_INDEX]; - bits &= WIDOWS_MASK; - bits >>= WIDOWS_SHIFT; - - *widows = style->page->widows; - - /* 1bit: type */ - return bits; - } - - /* Initial value */ - *widows = 2; - return CSS_WIDOWS_SET; -} -#undef WIDOWS_MASK -#undef WIDOWS_SHIFT -#undef WIDOWS_INDEX +#include "autogenerated_propget.h" #endif diff --git a/src/select/propset.h b/src/select/propset.h index 3f4038c..0306946 100644 --- a/src/select/propset.h +++ b/src/select/propset.h @@ -12,2317 +12,6 @@ #include <libcss/computed.h> #include "computed.h" - -/* Important: keep this file in sync with computed.h */ -/** \todo Is there a better way to ensure this happens? */ - -/** Default values are 'initial value', unless the property is inherited, - * in which case it is 'inherit'. */ -static const css_computed_uncommon default_uncommon = { - .i = { - .bits = { - (CSS_LETTER_SPACING_INHERIT << 2) | - CSS_OUTLINE_COLOR_INVERT, - (CSS_OUTLINE_WIDTH_MEDIUM << 1) | - CSS_BORDER_SPACING_INHERIT, - 0, - (CSS_WORD_SPACING_INHERIT << 2) | - (CSS_COUNTER_INCREMENT_NONE << 1) | - CSS_COUNTER_RESET_NONE, - (CSS_CURSOR_INHERIT << 3) | - (CSS_WRITING_MODE_INHERIT << 1), - 0, - 0, - (CSS_CLIP_AUTO << 2) | CSS_CONTENT_NORMAL, - (CSS_COLUMN_COUNT_AUTO << 6) | - (CSS_COLUMN_FILL_BALANCE << 4) | - (CSS_COLUMN_RULE_STYLE_NONE << 0), - (CSS_COLUMN_GAP_NORMAL << 2) | - (CSS_COLUMN_RULE_COLOR_CURRENT_COLOR), - (CSS_COLUMN_RULE_WIDTH_MEDIUM << 1), - (CSS_COLUMN_SPAN_NONE << 6) | CSS_COLUMN_WIDTH_AUTO, - (CSS_BREAK_BEFORE_AUTO << 4) | CSS_BREAK_AFTER_AUTO, - (CSS_BREAK_INSIDE_AUTO) - }, - .border_spacing = { 0, 0 }, - .clip = { 0, 0, 0, 0 }, - .letter_spacing = 0, - .outline_color = 0x0, - .outline_width = 0, - .word_spacing = 0, - .column_count = 0, - .column_gap = 0, - .column_rule_color = 0, - .column_rule_width = 0, - .column_width = 0 - }, - .counter_increment = NULL, - .counter_reset = NULL, - .content = NULL, - .cursor = NULL, - .next = NULL, - .count = 0, - .bin = UINT32_MAX -}; - -#define ENSURE_UNCOMMON do { \ - if (style->i.uncommon == NULL) { \ - style->i.uncommon = malloc( \ - sizeof(css_computed_uncommon)); \ - if (style->i.uncommon == NULL) \ - return CSS_NOMEM; \ - \ - memcpy(style->i.uncommon, &default_uncommon, \ - sizeof(css_computed_uncommon)); \ - } \ -} while(0) - -static const css_computed_page default_page = { - { - (CSS_PAGE_BREAK_INSIDE_AUTO << 6) | - (CSS_PAGE_BREAK_BEFORE_AUTO << 3) | - CSS_PAGE_BREAK_AFTER_AUTO, - (CSS_WIDOWS_SET << 1) | - CSS_ORPHANS_SET - }, - 2 << CSS_RADIX_POINT, - 2 << CSS_RADIX_POINT -}; - -#define ENSURE_PAGE do { \ - if (style->page == NULL) { \ - style->page = malloc(sizeof(css_computed_page)); \ - if (style->page == NULL) \ - return CSS_NOMEM; \ - \ - memcpy(style->page, &default_page, \ - sizeof(css_computed_page)); \ - } \ -} while(0) - -#define LETTER_SPACING_INDEX 0 -#define LETTER_SPACING_SHIFT 2 -#define LETTER_SPACING_MASK 0xfc -static inline css_error set_letter_spacing( - css_computed_style *style, uint8_t type, - css_fixed length, css_unit unit) -{ - uint8_t *bits; - - ENSURE_UNCOMMON; - - bits = &style->i.uncommon->i.bits[LETTER_SPACING_INDEX]; - - /* 6bits: uuuutt : unit | type */ - *bits = (*bits & ~LETTER_SPACING_MASK) | - (((type & 0x3) | unit << 2) << LETTER_SPACING_SHIFT); - - style->i.uncommon->i.letter_spacing = length; - - return CSS_OK; -} -#undef LETTER_SPACING_MASK -#undef LETTER_SPACING_SHIFT -#undef LETTER_SPACING_INDEX - -#define OUTLINE_COLOR_INDEX 0 -#define OUTLINE_COLOR_SHIFT 0 -#define OUTLINE_COLOR_MASK 0x3 -static inline css_error set_outline_color( - css_computed_style *style, uint8_t type, css_color color) -{ - uint8_t *bits; - - ENSURE_UNCOMMON; - - bits = &style->i.uncommon->i.bits[OUTLINE_COLOR_INDEX]; - - /* 2bits: tt : type */ - *bits = (*bits & ~OUTLINE_COLOR_MASK) | - ((type & 0x3) << OUTLINE_COLOR_SHIFT); - - style->i.uncommon->i.outline_color = color; - - return CSS_OK; -} -#undef OUTLINE_COLOR_MASK -#undef OUTLINE_COLOR_SHIFT -#undef OUTLINE_COLOR_INDEX - -#define OUTLINE_WIDTH_INDEX 1 -#define OUTLINE_WIDTH_SHIFT 1 -#define OUTLINE_WIDTH_MASK 0xfe -static inline css_error set_outline_width( - css_computed_style *style, uint8_t type, - css_fixed length, css_unit unit) -{ - uint8_t *bits; - - ENSURE_UNCOMMON; - - bits = &style->i.uncommon->i.bits[OUTLINE_WIDTH_INDEX]; - - /* 7bits: uuuuttt : unit | type */ - *bits = (*bits & ~OUTLINE_WIDTH_MASK) | - (((type & 0x7) | (unit << 3)) << OUTLINE_WIDTH_SHIFT); - - style->i.uncommon->i.outline_width = length; - - return CSS_OK; -} -#undef OUTLINE_WIDTH_MASK -#undef OUTLINE_WIDTH_SHIFT -#undef OUTLINE_WIDTH_INDEX - -#define BORDER_SPACING_INDEX 1 -#define BORDER_SPACING_SHIFT 0 -#define BORDER_SPACING_MASK 0x1 -#define BORDER_SPACING_INDEX1 2 -#define BORDER_SPACING_SHIFT1 0 -static inline css_error set_border_spacing( - css_computed_style *style, uint8_t type, - css_fixed hlength, css_unit hunit, - css_fixed vlength, css_unit vunit) -{ - uint8_t *bits; - - ENSURE_UNCOMMON; - - bits = &style->i.uncommon->i.bits[BORDER_SPACING_INDEX]; - - /* 1 bit: type */ - *bits = (*bits & ~BORDER_SPACING_MASK) | - ((type & 0x1) << BORDER_SPACING_SHIFT); - - bits = &style->i.uncommon->i.bits[BORDER_SPACING_INDEX1]; - - /* 8bits: hhhhvvvv : hunit | vunit */ - *bits = (((hunit << 4) | vunit) << BORDER_SPACING_SHIFT1); - - - style->i.uncommon->i.border_spacing[0] = hlength; - style->i.uncommon->i.border_spacing[1] = vlength; - - return CSS_OK; -} -#undef BORDER_SPACING_SHIFT1 -#undef BORDER_SPACING_INDEX1 -#undef BORDER_SPACING_MASK -#undef BORDER_SPACING_SHIFT -#undef BORDER_SPACING_INDEX - -#define BREAK_AFTER_INDEX 12 -#define BREAK_AFTER_SHIFT 0 -#define BREAK_AFTER_MASK 0xf -static inline css_error set_break_after( - css_computed_style *style, uint8_t type) -{ - uint8_t *bits; - - ENSURE_UNCOMMON; - - bits = &style->i.uncommon->i.bits[BREAK_AFTER_INDEX]; - - /* 4bits: type */ - *bits = (*bits & ~BREAK_AFTER_MASK) | - ((type & 0xf) << BREAK_AFTER_SHIFT); - - return CSS_OK; -} -#undef BREAK_AFTER_MASK -#undef BREAK_AFTER_SHIFT -#undef BREAK_AFTER_INDEX - -#define BREAK_BEFORE_INDEX 12 -#define BREAK_BEFORE_SHIFT 4 -#define BREAK_BEFORE_MASK (0xf << 4) -static inline css_error set_break_before( - css_computed_style *style, uint8_t type) -{ - uint8_t *bits; - - ENSURE_UNCOMMON; - - bits = &style->i.uncommon->i.bits[BREAK_BEFORE_INDEX]; - - /* 4bits: type */ - *bits = (*bits & ~BREAK_BEFORE_MASK) | - ((type & 0xf) << BREAK_BEFORE_SHIFT); - - return CSS_OK; -} -#undef BREAK_BEFORE_MASK -#undef BREAK_BEFORE_SHIFT -#undef BREAK_BEFORE_INDEX - -#define BREAK_INSIDE_INDEX 13 -#define BREAK_INSIDE_SHIFT 4 -#define BREAK_INSIDE_MASK (0xf << 4) -static inline css_error set_break_inside( - css_computed_style *style, uint8_t type) -{ - uint8_t *bits; - - ENSURE_UNCOMMON; - - bits = &style->i.uncommon->i.bits[BREAK_INSIDE_INDEX]; - - /* 4bits: type */ - *bits = (*bits & ~BREAK_INSIDE_MASK) | - ((type & 0xf) << BREAK_INSIDE_SHIFT); - - return CSS_OK; -} -#undef BREAK_INSIDE_MASK -#undef BREAK_INSIDE_SHIFT -#undef BREAK_INSIDE_INDEX - -#define WORD_SPACING_INDEX 3 -#define WORD_SPACING_SHIFT 2 -#define WORD_SPACING_MASK 0xfc -static inline css_error set_word_spacing( - css_computed_style *style, uint8_t type, - css_fixed length, css_unit unit) -{ - uint8_t *bits; - - ENSURE_UNCOMMON; - - bits = &style->i.uncommon->i.bits[WORD_SPACING_INDEX]; - - /* 6bits: uuuutt : unit | type */ - *bits = (*bits & ~WORD_SPACING_MASK) | - (((type & 0x3) | (unit << 2)) << WORD_SPACING_SHIFT); - - style->i.uncommon->i.word_spacing = length; - - return CSS_OK; -} -#undef WORD_SPACING_MASK -#undef WORD_SPACING_SHIFT -#undef WORD_SPACING_INDEX - -#define WRITING_MODE_INDEX 4 -#define WRITING_MODE_SHIFT 1 -#define WRITING_MODE_MASK 0x6 -static inline css_error set_writing_mode( - css_computed_style *style, uint8_t type) -{ - uint8_t *bits; - - ENSURE_UNCOMMON; - - bits = &style->i.uncommon->i.bits[WRITING_MODE_INDEX]; - - /* 2bits: type */ - *bits = (*bits & ~WRITING_MODE_MASK) | - ((type & 0x3) << WRITING_MODE_SHIFT); - - return CSS_OK; -} -#undef WRITING_MODE_MASK -#undef WRITING_MODE_SHIFT -#undef WRITING_MODE_INDEX - -#define COUNTER_INCREMENT_INDEX 3 -#define COUNTER_INCREMENT_SHIFT 1 -#define COUNTER_INCREMENT_MASK 0x2 -static inline css_error set_counter_increment( - css_computed_style *style, uint8_t type, - css_computed_counter *counters) -{ - uint8_t *bits; - css_computed_counter *oldcounters; - css_computed_counter *c; - - ENSURE_UNCOMMON; - - bits = &style->i.uncommon->i.bits[COUNTER_INCREMENT_INDEX]; - oldcounters = style->i.uncommon->counter_increment; - - /* 1bit: type */ - *bits = (*bits & ~COUNTER_INCREMENT_MASK) | - ((type & 0x1) << COUNTER_INCREMENT_SHIFT); - - for (c = counters; c != NULL && c->name != NULL; c++) - c->name = lwc_string_ref(c->name); - - style->i.uncommon->counter_increment = counters; - - /* Free existing array */ - if (oldcounters != NULL) { - for (c = oldcounters; c->name != NULL; c++) - lwc_string_unref(c->name); - - if (oldcounters != counters) - free(oldcounters); - } - - return CSS_OK; -} -#undef COUNTER_INCREMENT_MASK -#undef COUNTER_INCREMENT_SHIFT -#undef COUNTER_INCREMENT_INDEX - -#define COUNTER_RESET_INDEX 3 -#define COUNTER_RESET_SHIFT 0 -#define COUNTER_RESET_MASK 0x1 -static inline css_error set_counter_reset( - css_computed_style *style, uint8_t type, - css_computed_counter *counters) -{ - uint8_t *bits; - css_computed_counter *oldcounters; - css_computed_counter *c; - - ENSURE_UNCOMMON; - - bits = &style->i.uncommon->i.bits[COUNTER_RESET_INDEX]; - oldcounters = style->i.uncommon->counter_reset; - - /* 1bit: type */ - *bits = (*bits & ~COUNTER_RESET_MASK) | - ((type & 0x1) << COUNTER_RESET_SHIFT); - - for (c = counters; c != NULL && c->name != NULL; c++) - c->name = lwc_string_ref(c->name); - - style->i.uncommon->counter_reset = counters; - - /* Free existing array */ - if (oldcounters != NULL) { - for (c = oldcounters; c->name != NULL; c++) - lwc_string_unref(c->name); - - if (oldcounters != counters) - free(oldcounters); - } - - return CSS_OK; -} -#undef COUNTER_RESET_MASK -#undef COUNTER_RESET_SHIFT -#undef COUNTER_RESET_INDEX - -#define CURSOR_INDEX 4 -#define CURSOR_SHIFT 3 -#define CURSOR_MASK 0xf8 -static inline css_error set_cursor( - css_computed_style *style, uint8_t type, - lwc_string **urls) -{ - uint8_t *bits; - lwc_string **oldurls; - lwc_string **s; - - ENSURE_UNCOMMON; - - bits = &style->i.uncommon->i.bits[CURSOR_INDEX]; - oldurls = style->i.uncommon->cursor; - - /* 5bits: type */ - *bits = (*bits & ~CURSOR_MASK) | - ((type & 0x1f) << CURSOR_SHIFT); - - for (s = urls; s != NULL && *s != NULL; s++) - *s = lwc_string_ref(*s); - - style->i.uncommon->cursor = urls; - - /* Free existing array */ - if (oldurls != NULL) { - for (s = oldurls; *s != NULL; s++) - lwc_string_unref(*s); - - if (oldurls != urls) - free(oldurls); - } - - return CSS_OK; -} -#undef CURSOR_MASK -#undef CURSOR_SHIFT -#undef CURSOR_INDEX - -#define CLIP_INDEX 7 -#define CLIP_SHIFT 2 -#define CLIP_MASK 0xfc -#define CLIP_INDEX1 5 -#define CLIP_SHIFT1 0 -#define CLIP_INDEX2 6 -#define CLIP_SHIFT2 0 -static inline css_error set_clip( - css_computed_style *style, uint8_t type, - css_computed_clip_rect *rect) -{ - uint8_t *bits; - - ENSURE_UNCOMMON; - - bits = &style->i.uncommon->i.bits[CLIP_INDEX]; - - /* 6bits: trblyy : top | right | bottom | left | type */ - *bits = (*bits & ~CLIP_MASK) | - ((type & 0x3) << CLIP_SHIFT); - - if (type == CSS_CLIP_RECT) { - *bits |= (((rect->top_auto ? 0x20 : 0) | - (rect->right_auto ? 0x10 : 0) | - (rect->bottom_auto ? 0x8 : 0) | - (rect->left_auto ? 0x4 : 0)) << CLIP_SHIFT); - - bits = &style->i.uncommon->i.bits[CLIP_INDEX1]; - - /* 8bits: ttttrrrr : top | right */ - *bits = (((rect->tunit << 4) | rect->runit) << CLIP_SHIFT1); - - bits = &style->i.uncommon->i.bits[CLIP_INDEX2]; - - /* 8bits: bbbbllll : bottom | left */ - *bits = (((rect->bunit << 4) | rect->lunit) << CLIP_SHIFT2); - - style->i.uncommon->i.clip[0] = rect->top; - style->i.uncommon->i.clip[1] = rect->right; - style->i.uncommon->i.clip[2] = rect->bottom; - style->i.uncommon->i.clip[3] = rect->left; - } - - return CSS_OK; -} -#undef CLIP_SHIFT2 -#undef CLIP_INDEX2 -#undef CLIP_SHIFT1 -#undef CLIP_INDEX1 -#undef CLIP_MASK -#undef CLIP_SHIFT -#undef CLIP_INDEX - -#define COLUMN_COUNT_INDEX 8 -#define COLUMN_COUNT_SHIFT 6 -#define COLUMN_COUNT_MASK 0xc0 -static inline css_error set_column_count( - css_computed_style *style, uint8_t type, int32_t count) -{ - uint8_t *bits; - - ENSURE_UNCOMMON; - - bits = &style->i.uncommon->i.bits[COLUMN_COUNT_INDEX]; - - /* 2bits: tt : type */ - *bits = (*bits & ~COLUMN_COUNT_MASK) | - ((type & 0x3) << COLUMN_COUNT_SHIFT); - - style->i.uncommon->i.column_count = count; - - return CSS_OK; -} -#undef COLUMN_COUNT_MASK -#undef COLUMN_COUNT_SHIFT -#undef COLUMN_COUNT_INDEX - -#define COLUMN_FILL_INDEX 8 -#define COLUMN_FILL_SHIFT 4 -#define COLUMN_FILL_MASK 0x30 -static inline css_error set_column_fill( - css_computed_style *style, uint8_t type) -{ - uint8_t *bits; - - ENSURE_UNCOMMON; - - bits = &style->i.uncommon->i.bits[COLUMN_FILL_INDEX]; - - /* 2bits: tt : type */ - *bits = (*bits & ~COLUMN_FILL_MASK) | - ((type & 0x3) << COLUMN_FILL_SHIFT); - - return CSS_OK; -} -#undef COLUMN_FILL_MASK -#undef COLUMN_FILL_SHIFT -#undef COLUMN_FILL_INDEX - -#define COLUMN_GAP_INDEX 9 -#define COLUMN_GAP_SHIFT 2 -#define COLUMN_GAP_MASK 0xfc -static inline css_error set_column_gap( - css_computed_style *style, uint8_t type, - css_fixed length, css_unit unit) -{ - uint8_t *bits; - - ENSURE_UNCOMMON; - - bits = &style->i.uncommon->i.bits[COLUMN_GAP_INDEX]; - - /* 6bits: uuuutt : units | type */ - *bits = (*bits & ~COLUMN_GAP_MASK) | - (((type & 0x3) | (unit << 2)) << COLUMN_GAP_SHIFT); - - style->i.uncommon->i.column_gap = length; - - return CSS_OK; -} -#undef COLUMN_GAP_MASK -#undef COLUMN_GAP_SHIFT -#undef COLUMN_GAP_INDEX - -#define COLUMN_RULE_COLOR_INDEX 9 -#define COLUMN_RULE_COLOR_SHIFT 0 -#define COLUMN_RULE_COLOR_MASK 0x3 -static inline css_error set_column_rule_color( - css_computed_style *style, uint8_t type, - css_color color) -{ - uint8_t *bits; - - ENSURE_UNCOMMON; - - bits = &style->i.uncommon->i.bits[COLUMN_RULE_COLOR_INDEX]; - - /* 2bits: type */ - *bits = (*bits & ~COLUMN_RULE_COLOR_MASK) | - ((type & 0x3) << COLUMN_RULE_COLOR_SHIFT); - - style->i.uncommon->i.column_rule_color = color; - - return CSS_OK; -} -#undef COLUMN_RULE_COLOR_MASK -#undef COLUMN_RULE_COLOR_SHIFT -#undef COLUMN_RULE_COLOR_INDEX - -#define COLUMN_RULE_STYLE_INDEX 8 -#define COLUMN_RULE_STYLE_SHIFT 0 -#define COLUMN_RULE_STYLE_MASK 0xf -static inline css_error set_column_rule_style( - css_computed_style *style, uint8_t type) -{ - uint8_t *bits; - - ENSURE_UNCOMMON; - - bits = &style->i.uncommon->i.bits[COLUMN_RULE_STYLE_INDEX]; - - /* 4bits: type */ - *bits = (*bits & ~COLUMN_RULE_STYLE_MASK) | - ((type & 0xf) << COLUMN_RULE_STYLE_SHIFT); - - return CSS_OK; -} -#undef COLUMN_RULE_STYLE_MASK -#undef COLUMN_RULE_STYLE_SHIFT -#undef COLUMN_RULE_STYLE_INDEX - -#define COLUMN_RULE_WIDTH_INDEX 10 -#define COLUMN_RULE_WIDTH_SHIFT 1 -#define COLUMN_RULE_WIDTH_MASK 0xfe -static inline css_error set_column_rule_width( - css_computed_style *style, uint8_t type, - css_fixed length, css_unit unit) -{ - uint8_t *bits; - - ENSURE_UNCOMMON; - - bits = &style->i.uncommon->i.bits[COLUMN_RULE_WIDTH_INDEX]; - - /* 7bits: uuuuttt : units | type */ - *bits = (*bits & ~COLUMN_RULE_WIDTH_MASK) | - (((type & 0x7) | (unit << 3)) << COLUMN_RULE_WIDTH_SHIFT); - - style->i.uncommon->i.column_rule_width = length; - - return CSS_OK; -} -#undef COLUMN_RULE_WIDTH_MASK -#undef COLUMN_RULE_WIDTH_SHIFT -#undef COLUMN_RULE_WIDTH_INDEX - -#define COLUMN_SPAN_INDEX 11 -#define COLUMN_SPAN_SHIFT 6 -#define COLUMN_SPAN_MASK 0xc0 -static inline css_error set_column_span( - css_computed_style *style, uint8_t type) -{ - uint8_t *bits; - - ENSURE_UNCOMMON; - - bits = &style->i.uncommon->i.bits[COLUMN_SPAN_INDEX]; - - /* 2bits: tt : type */ - *bits = (*bits & ~COLUMN_SPAN_MASK) | - ((type & 0x3) << COLUMN_SPAN_SHIFT); - - return CSS_OK; -} -#undef COLUMN_SPAN_MASK -#undef COLUMN_SPAN_SHIFT -#undef COLUMN_SPAN_INDEX - -#define COLUMN_WIDTH_INDEX 11 -#define COLUMN_WIDTH_SHIFT 0 -#define COLUMN_WIDTH_MASK 0x3f -static inline css_error set_column_width( - css_computed_style *style, uint8_t type, - css_fixed length, css_unit unit) -{ - uint8_t *bits; - - ENSURE_UNCOMMON; - - bits = &style->i.uncommon->i.bits[COLUMN_WIDTH_INDEX]; - - /* 6bits: uuuutt : units | type */ - *bits = (*bits & ~COLUMN_WIDTH_MASK) | - (((type & 0x3) | (unit << 2)) << COLUMN_WIDTH_SHIFT); - - style->i.uncommon->i.column_width = length; - - return CSS_OK; -} -#undef COLUMN_WIDTH_MASK -#undef COLUMN_WIDTH_SHIFT -#undef COLUMN_WIDTH_INDEX - -#define CONTENT_INDEX 7 -#define CONTENT_SHIFT 0 -#define CONTENT_MASK 0x3 -static inline css_error set_content( - css_computed_style *style, uint8_t type, - css_computed_content_item *content) -{ - uint8_t *bits; - css_computed_content_item *oldcontent; - css_computed_content_item *c; - - ENSURE_UNCOMMON; - - /* 2bits: type */ - bits = &style->i.uncommon->i.bits[CONTENT_INDEX]; - oldcontent = style->i.uncommon->content; - - *bits = (*bits & ~CONTENT_MASK) | - ((type & 0x3) << CONTENT_SHIFT); - - for (c = content; c != NULL && - c->type != CSS_COMPUTED_CONTENT_NONE; c++) { - switch (c->type) { - case CSS_COMPUTED_CONTENT_STRING: - c->data.string = lwc_string_ref(c->data.string); - break; - case CSS_COMPUTED_CONTENT_URI: - c->data.uri = lwc_string_ref(c->data.uri); - break; - case CSS_COMPUTED_CONTENT_ATTR: - c->data.attr = lwc_string_ref(c->data.attr); - break; - case CSS_COMPUTED_CONTENT_COUNTER: - c->data.counter.name = - lwc_string_ref(c->data.counter.name); - break; - case CSS_COMPUTED_CONTENT_COUNTERS: - c->data.counters.name = - lwc_string_ref(c->data.counters.name); - c->data.counters.sep = - lwc_string_ref(c->data.counters.sep); - break; - default: - break; - } - } - - style->i.uncommon->content = content; - - /* Free existing array */ - if (oldcontent != NULL) { - for (c = oldcontent; - c->type != CSS_COMPUTED_CONTENT_NONE; c++) { - switch (c->type) { - case CSS_COMPUTED_CONTENT_STRING: - lwc_string_unref(c->data.string); - break; - case CSS_COMPUTED_CONTENT_URI: - lwc_string_unref(c->data.uri); - break; - case CSS_COMPUTED_CONTENT_ATTR: - lwc_string_unref(c->data.attr); - break; - case CSS_COMPUTED_CONTENT_COUNTER: - lwc_string_unref(c->data.counter.name); - break; - case CSS_COMPUTED_CONTENT_COUNTERS: - lwc_string_unref(c->data.counters.name); - lwc_string_unref(c->data.counters.sep); - break; - default: - break; - } - } - - if (oldcontent != content) - free(oldcontent); - } - - return CSS_OK; -} -#undef CONTENT_MASK -#undef CONTENT_SHIFT -#undef CONTENT_INDEX - - -#define VERTICAL_ALIGN_INDEX 0 -#define VERTICAL_ALIGN_SHIFT 0 -static inline css_error set_vertical_align( - css_computed_style *style, uint8_t type, - css_fixed length, css_unit unit) -{ - uint8_t *bits = &style->i.bits[VERTICAL_ALIGN_INDEX]; - - /* 8bits: uuuutttt : units | type */ - *bits = (((type & 0xf) | (unit << 4)) << VERTICAL_ALIGN_SHIFT); - - style->i.vertical_align = length; - - return CSS_OK; -} -#undef VERTICAL_ALIGN_SHIFT -#undef VERTICAL_ALIGN_INDEX - -#define FONT_SIZE_INDEX 1 -#define FONT_SIZE_SHIFT 0 -static inline css_error set_font_size( - css_computed_style *style, uint8_t type, - css_fixed length, css_unit unit) -{ - uint8_t *bits = &style->i.bits[FONT_SIZE_INDEX]; - - /* 8bits: uuuutttt : units | type */ - *bits = (((type & 0xf) | (unit << 4)) << FONT_SIZE_SHIFT); - - style->i.font_size = length; - - return CSS_OK; -} -#undef FONT_SIZE_SHIFT -#undef FONT_SIZE_INDEX - -#define BORDER_TOP_WIDTH_INDEX 2 -#define BORDER_TOP_WIDTH_SHIFT 1 -#define BORDER_TOP_WIDTH_MASK 0xfe -static inline css_error set_border_top_width( - css_computed_style *style, uint8_t type, - css_fixed length, css_unit unit) -{ - uint8_t *bits = &style->i.bits[BORDER_TOP_WIDTH_INDEX]; - - /* 7bits: uuuuttt : units | type */ - *bits = (*bits & ~BORDER_TOP_WIDTH_MASK) | - (((type & 0x7) | (unit << 3)) << BORDER_TOP_WIDTH_SHIFT); - - style->i.border_width[0] = length; - - return CSS_OK; -} -#undef BORDER_TOP_WIDTH_MASK -#undef BORDER_TOP_WIDTH_SHIFT -#undef BORDER_TOP_WIDTH_INDEX - -#define BORDER_RIGHT_WIDTH_INDEX 3 -#define BORDER_RIGHT_WIDTH_SHIFT 1 -#define BORDER_RIGHT_WIDTH_MASK 0xfe -static inline css_error set_border_right_width( - css_computed_style *style, uint8_t type, - css_fixed length, css_unit unit) -{ - uint8_t *bits = &style->i.bits[BORDER_RIGHT_WIDTH_INDEX]; - - /* 7bits: uuuuttt : units | type */ - *bits = (*bits & ~BORDER_RIGHT_WIDTH_MASK) | - (((type & 0x7) | (unit << 3)) << BORDER_RIGHT_WIDTH_SHIFT); - - style->i.border_width[1] = length; - - return CSS_OK; -} -#undef BORDER_RIGHT_WIDTH_MASK -#undef BORDER_RIGHT_WIDTH_SHIFT -#undef BORDER_RIGHT_WIDTH_INDEX - -#define BORDER_BOTTOM_WIDTH_INDEX 4 -#define BORDER_BOTTOM_WIDTH_SHIFT 1 -#define BORDER_BOTTOM_WIDTH_MASK 0xfe -static inline css_error set_border_bottom_width( - css_computed_style *style, uint8_t type, - css_fixed length, css_unit unit) -{ - uint8_t *bits = &style->i.bits[BORDER_BOTTOM_WIDTH_INDEX]; - - /* 7bits: uuuuttt : units | type */ - *bits = (*bits & ~BORDER_BOTTOM_WIDTH_MASK) | - (((type & 0x7) | (unit << 3)) << BORDER_BOTTOM_WIDTH_SHIFT); - - style->i.border_width[2] = length; - - return CSS_OK; -} -#undef BORDER_BOTTOM_WIDTH_MASK -#undef BORDER_BOTTOM_WIDTH_SHIFT -#undef BORDER_BOTTOM_WIDTH_INDEX - -#define BORDER_LEFT_WIDTH_INDEX 5 -#define BORDER_LEFT_WIDTH_SHIFT 1 -#define BORDER_LEFT_WIDTH_MASK 0xfe -static inline css_error set_border_left_width( - css_computed_style *style, uint8_t type, - css_fixed length, css_unit unit) -{ - uint8_t *bits = &style->i.bits[BORDER_LEFT_WIDTH_INDEX]; - - /* 7bits: uuuuttt : units | type */ - *bits = (*bits & ~BORDER_LEFT_WIDTH_MASK) | - (((type & 0x7) | (unit << 3)) << BORDER_LEFT_WIDTH_SHIFT); - - style->i.border_width[3] = length; - - return CSS_OK; -} -#undef BORDER_LEFT_WIDTH_MASK -#undef BORDER_LEFT_WIDTH_SHIFT -#undef BORDER_LEFT_WIDTH_INDEX - -#define BACKGROUND_IMAGE_INDEX 2 -#define BACKGROUND_IMAGE_SHIFT 0 -#define BACKGROUND_IMAGE_MASK 0x1 -static inline css_error set_background_image( - css_computed_style *style, uint8_t type, - lwc_string *url) -{ - uint8_t *bits = &style->i.bits[BACKGROUND_IMAGE_INDEX]; - lwc_string *oldurl = style->i.background_image; - - /* 1bit: type */ - *bits = (*bits & ~BACKGROUND_IMAGE_MASK) | - ((type & 0x1) << BACKGROUND_IMAGE_SHIFT); - - if (url != NULL) { - style->i.background_image = lwc_string_ref(url); - } else { - style->i.background_image = NULL; - } - - if (oldurl != NULL) - lwc_string_unref(oldurl); - - return CSS_OK; -} -#undef BACKGROUND_IMAGE_MASK -#undef BACKGROUND_IMAGE_SHIFT -#undef BACKGROUND_IMAGE_INDEX - -#define COLOR_INDEX 3 -#define COLOR_SHIFT 0 -#define COLOR_MASK 0x1 -static inline css_error set_color( - css_computed_style *style, uint8_t type, - css_color color) -{ - uint8_t *bits = &style->i.bits[COLOR_INDEX]; - - /* 1bit: type */ - *bits = (*bits & ~COLOR_MASK) | - ((type & 0x1) << COLOR_SHIFT); - - style->i.color = color; - - return CSS_OK; -} -#undef COLOR_MASK -#undef COLOR_SHIFT -#undef COLOR_INDEX - -#define LIST_STYLE_IMAGE_INDEX 4 -#define LIST_STYLE_IMAGE_SHIFT 0 -#define LIST_STYLE_IMAGE_MASK 0x1 -static inline css_error set_list_style_image( - css_computed_style *style, uint8_t type, - lwc_string *url) -{ - uint8_t *bits = &style->i.bits[LIST_STYLE_IMAGE_INDEX]; - lwc_string *oldurl = style->i.list_style_image; - - /* 1bit: type */ - *bits = (*bits & ~LIST_STYLE_IMAGE_MASK) | - ((type & 0x1) << LIST_STYLE_IMAGE_SHIFT); - - if (url != NULL) { - style->i.list_style_image = lwc_string_ref(url); - } else { - style->i.list_style_image = NULL; - } - - if (oldurl != NULL) - lwc_string_unref(oldurl); - - return CSS_OK; -} -#undef LIST_STYLE_IMAGE_MASK -#undef LIST_STYLE_IMAGE_SHIFT -#undef LIST_STYLE_IMAGE_INDEX - -#define QUOTES_INDEX 5 -#define QUOTES_SHIFT 0 -#define QUOTES_MASK 0x1 -static inline css_error set_quotes( - css_computed_style *style, uint8_t type, - lwc_string **quotes) -{ - uint8_t *bits = &style->i.bits[QUOTES_INDEX]; - lwc_string **oldquotes = style->quotes; - lwc_string **s; - - /* 1bit: type */ - *bits = (*bits & ~QUOTES_MASK) | - ((type & 0x1) << QUOTES_SHIFT); - - for (s = quotes; s != NULL && *s != NULL; s++) - *s = lwc_string_ref(*s); - - style->quotes = quotes; - - /* Free current quotes */ - if (oldquotes != NULL) { - for (s = oldquotes; *s != NULL; s++) - lwc_string_unref(*s); - - if (oldquotes != quotes) - free(oldquotes); - } - - return CSS_OK; -} -#undef QUOTES_MASK -#undef QUOTES_SHIFT -#undef QUOTES_INDEX - -#define TOP_INDEX 6 -#define TOP_SHIFT 2 -#define TOP_MASK 0xfc -static inline css_error set_top( - css_computed_style *style, uint8_t type, - css_fixed length, css_unit unit) -{ - uint8_t *bits = &style->i.bits[TOP_INDEX]; - - /* 6bits: uuuutt : units | type */ - *bits = (*bits & ~TOP_MASK) | - (((type & 0x3) | (unit << 2)) << TOP_SHIFT); - - style->i.top = length; - - return CSS_OK; -} -#undef TOP_MASK -#undef TOP_SHIFT -#undef TOP_INDEX - -#define RIGHT_INDEX 7 -#define RIGHT_SHIFT 2 -#define RIGHT_MASK 0xfc -static inline css_error set_right( - css_computed_style *style, uint8_t type, - css_fixed length, css_unit unit) -{ - uint8_t *bits = &style->i.bits[RIGHT_INDEX]; - - /* 6bits: uuuutt : units | type */ - *bits = (*bits & ~RIGHT_MASK) | - (((type & 0x3) | (unit << 2)) << RIGHT_SHIFT); - - style->i.right = length; - - return CSS_OK; -} -#undef RIGHT_MASK -#undef RIGHT_SHIFT -#undef RIGHT_INDEX - -#define BOTTOM_INDEX 8 -#define BOTTOM_SHIFT 2 -#define BOTTOM_MASK 0xfc -static inline css_error set_bottom( - css_computed_style *style, uint8_t type, - css_fixed length, css_unit unit) -{ - uint8_t *bits = &style->i.bits[BOTTOM_INDEX]; - - /* 6bits: uuuutt : units | type */ - *bits = (*bits & ~BOTTOM_MASK) | - (((type & 0x3) | (unit << 2)) << BOTTOM_SHIFT); - - style->i.bottom = length; - - return CSS_OK; -} -#undef BOTTOM_MASK -#undef BOTTOM_SHIFT -#undef BOTTOM_INDEX - -#define LEFT_INDEX 9 -#define LEFT_SHIFT 2 -#define LEFT_MASK 0xfc -static inline css_error set_left( - css_computed_style *style, uint8_t type, - css_fixed length, css_unit unit) -{ - uint8_t *bits = &style->i.bits[LEFT_INDEX]; - - /* 6bits: uuuutt : units | type */ - *bits = (*bits & ~LEFT_MASK) | - (((type & 0x3) | (unit << 2)) << LEFT_SHIFT); - - style->i.left = length; - - return CSS_OK; -} -#undef LEFT_MASK -#undef LEFT_SHIFT -#undef LEFT_INDEX - -#define BORDER_TOP_COLOR_INDEX 6 -#define BORDER_TOP_COLOR_SHIFT 0 -#define BORDER_TOP_COLOR_MASK 0x3 -static inline css_error set_border_top_color( - css_computed_style *style, uint8_t type, - css_color color) -{ - uint8_t *bits = &style->i.bits[BORDER_TOP_COLOR_INDEX]; - - /* 2bits: type */ - *bits = (*bits & ~BORDER_TOP_COLOR_MASK) | - ((type & 0x3) << BORDER_TOP_COLOR_SHIFT); - - style->i.border_color[0] = color; - - return CSS_OK; -} -#undef BORDER_TOP_COLOR_MASK -#undef BORDER_TOP_COLOR_SHIFT -#undef BORDER_TOP_COLOR_INDEX - -#define BORDER_RIGHT_COLOR_INDEX 7 -#define BORDER_RIGHT_COLOR_SHIFT 0 -#define BORDER_RIGHT_COLOR_MASK 0x3 -static inline css_error set_border_right_color( - css_computed_style *style, uint8_t type, - css_color color) -{ - uint8_t *bits = &style->i.bits[BORDER_RIGHT_COLOR_INDEX]; - - /* 2bits: type */ - *bits = (*bits & ~BORDER_RIGHT_COLOR_MASK) | - ((type & 0x3) << BORDER_RIGHT_COLOR_SHIFT); - - style->i.border_color[1] = color; - - return CSS_OK; -} -#undef BORDER_RIGHT_COLOR_MASK -#undef BORDER_RIGHT_COLOR_SHIFT -#undef BORDER_RIGHT_COLOR_INDEX - -#define BORDER_BOTTOM_COLOR_INDEX 8 -#define BORDER_BOTTOM_COLOR_SHIFT 0 -#define BORDER_BOTTOM_COLOR_MASK 0x3 -static inline css_error set_border_bottom_color( - css_computed_style *style, uint8_t type, - css_color color) -{ - uint8_t *bits = &style->i.bits[BORDER_BOTTOM_COLOR_INDEX]; - - /* 2bits: type */ - *bits = (*bits & ~BORDER_BOTTOM_COLOR_MASK) | - ((type & 0x3) << BORDER_BOTTOM_COLOR_SHIFT); - - style->i.border_color[2] = color; - - return CSS_OK; -} -#undef BORDER_BOTTOM_COLOR_MASK -#undef BORDER_BOTTOM_COLOR_SHIFT -#undef BORDER_BOTTOM_COLOR_INDEX - -#define BORDER_LEFT_COLOR_INDEX 9 -#define BORDER_LEFT_COLOR_SHIFT 0 -#define BORDER_LEFT_COLOR_MASK 0x3 -static inline css_error set_border_left_color( - css_computed_style *style, uint8_t type, - css_color color) -{ - uint8_t *bits = &style->i.bits[BORDER_LEFT_COLOR_INDEX]; - - /* 2bits: type */ - *bits = (*bits & ~BORDER_LEFT_COLOR_MASK) | - ((type & 0x3) << BORDER_LEFT_COLOR_SHIFT); - - style->i.border_color[3] = color; - - return CSS_OK; -} -#undef BORDER_LEFT_COLOR_MASK -#undef BORDER_LEFT_COLOR_SHIFT -#undef BORDER_LEFT_COLOR_INDEX - -#define HEIGHT_INDEX 10 -#define HEIGHT_SHIFT 2 -#define HEIGHT_MASK 0xfc -static inline css_error set_height( - css_computed_style *style, uint8_t type, - css_fixed length, css_unit unit) -{ - uint8_t *bits = &style->i.bits[HEIGHT_INDEX]; - - /* 6bits: uuuutt : units | type */ - *bits = (*bits & ~HEIGHT_MASK) | - (((type & 0x3) | (unit << 2)) << HEIGHT_SHIFT); - - style->i.height = length; - - return CSS_OK; -} -#undef HEIGHT_MASK -#undef HEIGHT_SHIFT -#undef HEIGHT_INDEX - -#define LINE_HEIGHT_INDEX 11 -#define LINE_HEIGHT_SHIFT 2 -#define LINE_HEIGHT_MASK 0xfc -static inline css_error set_line_height( - css_computed_style *style, uint8_t type, - css_fixed length, css_unit unit) -{ - uint8_t *bits = &style->i.bits[LINE_HEIGHT_INDEX]; - - /* 6bits: uuuutt : units | type */ - *bits = (*bits & ~LINE_HEIGHT_MASK) | - (((type & 0x3) | (unit << 2)) << LINE_HEIGHT_SHIFT); - - style->i.line_height = length; - - return CSS_OK; -} -#undef LINE_HEIGHT_MASK -#undef LINE_HEIGHT_SHIFT -#undef LINE_HEIGHT_INDEX - -#define BACKGROUND_COLOR_INDEX 10 -#define BACKGROUND_COLOR_SHIFT 0 -#define BACKGROUND_COLOR_MASK 0x3 -static inline css_error set_background_color( - css_computed_style *style, uint8_t type, - css_color color) -{ - uint8_t *bits = &style->i.bits[BACKGROUND_COLOR_INDEX]; - - /* 2bits: type */ - *bits = (*bits & ~BACKGROUND_COLOR_MASK) | - ((type & 0x3) << BACKGROUND_COLOR_SHIFT); - - style->i.background_color = color; - - return CSS_OK; -} -#undef BACKGROUND_COLOR_MASK -#undef BACKGROUND_COLOR_SHIFT -#undef BACKGROUND_COLOR_INDEX - -#define Z_INDEX_INDEX 11 -#define Z_INDEX_SHIFT 0 -#define Z_INDEX_MASK 0x3 -static inline css_error set_z_index( - css_computed_style *style, uint8_t type, - int32_t z_index) -{ - uint8_t *bits = &style->i.bits[Z_INDEX_INDEX]; - - /* 2bits: type */ - *bits = (*bits & ~Z_INDEX_MASK) | - ((type & 0x3) << Z_INDEX_SHIFT); - - style->i.z_index = z_index; - - return CSS_OK; -} -#undef Z_INDEX_MASK -#undef Z_INDEX_SHIFT -#undef Z_INDEX_INDEX - -#define MARGIN_TOP_INDEX 12 -#define MARGIN_TOP_SHIFT 2 -#define MARGIN_TOP_MASK 0xfc -static inline css_error set_margin_top( - css_computed_style *style, uint8_t type, - css_fixed length, css_unit unit) -{ - uint8_t *bits = &style->i.bits[MARGIN_TOP_INDEX]; - - /* 6bits: uuuutt : units | type */ - *bits = (*bits & ~MARGIN_TOP_MASK) | - (((type & 0x3) | (unit << 2)) << MARGIN_TOP_SHIFT); - - style->i.margin[0] = length; - - return CSS_OK; -} -#undef MARGIN_TOP_MASK -#undef MARGIN_TOP_SHIFT -#undef MARGIN_TOP_INDEX - -#define MARGIN_RIGHT_INDEX 13 -#define MARGIN_RIGHT_SHIFT 2 -#define MARGIN_RIGHT_MASK 0xfc -static inline css_error set_margin_right( - css_computed_style *style, uint8_t type, - css_fixed length, css_unit unit) -{ - uint8_t *bits = &style->i.bits[MARGIN_RIGHT_INDEX]; - - /* 6bits: uuuutt : units | type */ - *bits = (*bits & ~MARGIN_RIGHT_MASK) | - (((type & 0x3) | (unit << 2)) << MARGIN_RIGHT_SHIFT); - - style->i.margin[1] = length; - - return CSS_OK; -} -#undef MARGIN_RIGHT_MASK -#undef MARGIN_RIGHT_SHIFT -#undef MARGIN_RIGHT_INDEX - -#define MARGIN_BOTTOM_INDEX 14 -#define MARGIN_BOTTOM_SHIFT 2 -#define MARGIN_BOTTOM_MASK 0xfc -static inline css_error set_margin_bottom( - css_computed_style *style, uint8_t type, - css_fixed length, css_unit unit) -{ - uint8_t *bits = &style->i.bits[MARGIN_BOTTOM_INDEX]; - - /* 6bits: uuuutt : units | type */ - *bits = (*bits & ~MARGIN_BOTTOM_MASK) | - (((type & 0x3) | (unit << 2)) << MARGIN_BOTTOM_SHIFT); - - style->i.margin[2] = length; - - return CSS_OK; -} -#undef MARGIN_BOTTOM_MASK -#undef MARGIN_BOTTOM_SHIFT -#undef MARGIN_BOTTOM_INDEX - -#define MARGIN_LEFT_INDEX 15 -#define MARGIN_LEFT_SHIFT 2 -#define MARGIN_LEFT_MASK 0xfc -static inline css_error set_margin_left( - css_computed_style *style, uint8_t type, - css_fixed length, css_unit unit) -{ - uint8_t *bits = &style->i.bits[MARGIN_LEFT_INDEX]; - - /* 6bits: uuuutt : units | type */ - *bits = (*bits & ~MARGIN_LEFT_MASK) | - (((type & 0x3) | (unit << 2)) << MARGIN_LEFT_SHIFT); - - style->i.margin[3] = length; - - return CSS_OK; -} -#undef MARGIN_LEFT_MASK -#undef MARGIN_LEFT_SHIFT -#undef MARGIN_LEFT_INDEX - -#define BACKGROUND_ATTACHMENT_INDEX 12 -#define BACKGROUND_ATTACHMENT_SHIFT 0 -#define BACKGROUND_ATTACHMENT_MASK 0x3 -static inline css_error set_background_attachment( - css_computed_style *style, uint8_t type) -{ - uint8_t *bits = &style->i.bits[BACKGROUND_ATTACHMENT_INDEX]; - - /* 2bits: type */ - *bits = (*bits & ~BACKGROUND_ATTACHMENT_MASK) | - ((type & 0x3) << BACKGROUND_ATTACHMENT_SHIFT); - - return CSS_OK; -} -#undef BACKGROUND_ATTACHMENT_MASK -#undef BACKGROUND_ATTACHMENT_SHIFT -#undef BACKGROUND_ATTACHMENT_INDEX - -#define BOX_SIZING_INDEX 34 -#define BOX_SIZING_SHIFT 0 -#define BOX_SIZING_MASK 0x3 -static inline css_error set_box_sizing( - css_computed_style *style, uint8_t type) -{ - uint8_t *bits = &style->i.bits[BOX_SIZING_INDEX]; - - /* 2bits: type */ - *bits = (*bits & ~BOX_SIZING_MASK) | - ((type & 0x3) << BOX_SIZING_SHIFT); - - return CSS_OK; -} -#undef BOX_SIZING_MASK -#undef BOX_SIZING_SHIFT -#undef BOX_SIZING_INDEX - -#define BORDER_COLLAPSE_INDEX 13 -#define BORDER_COLLAPSE_SHIFT 0 -#define BORDER_COLLAPSE_MASK 0x3 -static inline css_error set_border_collapse( - css_computed_style *style, uint8_t type) -{ - uint8_t *bits = &style->i.bits[BORDER_COLLAPSE_INDEX]; - - /* 2bits: type */ - *bits = (*bits & ~BORDER_COLLAPSE_MASK) | - ((type & 0x3) << BORDER_COLLAPSE_SHIFT); - - return CSS_OK; -} -#undef BORDER_COLLAPSE_MASK -#undef BORDER_COLLAPSE_SHIFT -#undef BORDER_COLLAPSE_INDEX - -#define CAPTION_SIDE_INDEX 14 -#define CAPTION_SIDE_SHIFT 0 -#define CAPTION_SIDE_MASK 0x3 -static inline css_error set_caption_side( - css_computed_style *style, uint8_t type) -{ - uint8_t *bits = &style->i.bits[CAPTION_SIDE_INDEX]; - - /* 2bits: type */ - *bits = (*bits & ~CAPTION_SIDE_MASK) | - ((type & 0x3) << CAPTION_SIDE_SHIFT); - - return CSS_OK; -} -#undef CAPTION_SIDE_MASK -#undef CAPTION_SIDE_SHIFT -#undef CAPTION_SIDE_INDEX - -#define DIRECTION_INDEX 15 -#define DIRECTION_SHIFT 0 -#define DIRECTION_MASK 0x3 -static inline css_error set_direction( - css_computed_style *style, uint8_t type) -{ - uint8_t *bits = &style->i.bits[DIRECTION_INDEX]; - - /* 2bits: type */ - *bits = (*bits & ~DIRECTION_MASK) | - ((type & 0x3) << DIRECTION_SHIFT); - - return CSS_OK; -} -#undef DIRECTION_MASK -#undef DIRECTION_SHIFT -#undef DIRECTION_INDEX - -#define MAX_HEIGHT_INDEX 16 -#define MAX_HEIGHT_SHIFT 2 -#define MAX_HEIGHT_MASK 0xfc -static inline css_error set_max_height( - css_computed_style *style, uint8_t type, - css_fixed length, css_unit unit) -{ - uint8_t *bits = &style->i.bits[MAX_HEIGHT_INDEX]; - - /* 6bits: uuuutt : units | type */ - *bits = (*bits & ~MAX_HEIGHT_MASK) | - (((type & 0x3) | (unit << 2)) << MAX_HEIGHT_SHIFT); - - style->i.max_height = length; - - return CSS_OK; -} -#undef MAX_HEIGHT_MASK -#undef MAX_HEIGHT_SHIFT -#undef MAX_HEIGHT_INDEX - -#define MAX_WIDTH_INDEX 17 -#define MAX_WIDTH_SHIFT 2 -#define MAX_WIDTH_MASK 0xfc -static inline css_error set_max_width( - css_computed_style *style, uint8_t type, - css_fixed length, css_unit unit) -{ - uint8_t *bits = &style->i.bits[MAX_WIDTH_INDEX]; - - /* 6bits: uuuutt : units | type */ - *bits = (*bits & ~MAX_WIDTH_MASK) | - (((type & 0x3) | (unit << 2)) << MAX_WIDTH_SHIFT); - - style->i.max_width = length; - - return CSS_OK; -} -#undef MAX_WIDTH_MASK -#undef MAX_WIDTH_SHIFT -#undef MAX_WIDTH_INDEX - -#define WIDTH_INDEX 18 -#define WIDTH_SHIFT 2 -#define WIDTH_MASK 0xfc -static inline css_error set_width( - css_computed_style *style, uint8_t type, - css_fixed length, css_unit unit) -{ - uint8_t *bits = &style->i.bits[WIDTH_INDEX]; - - /* 6bits: uuuutt : units | type */ - *bits = (*bits & ~WIDTH_MASK) | - (((type & 0x3) | (unit << 2)) << WIDTH_SHIFT); - - style->i.width = length; - - return CSS_OK; -} -#undef WIDTH_MASK -#undef WIDTH_SHIFT -#undef WIDTH_INDEX - -#define EMPTY_CELLS_INDEX 16 -#define EMPTY_CELLS_SHIFT 0 -#define EMPTY_CELLS_MASK 0x3 -static inline css_error set_empty_cells( - css_computed_style *style, uint8_t type) -{ - uint8_t *bits = &style->i.bits[EMPTY_CELLS_INDEX]; - - /* 2bits: type */ - *bits = (*bits & ~EMPTY_CELLS_MASK) | - ((type & 0x3) << EMPTY_CELLS_SHIFT); - - return CSS_OK; -} -#undef EMPTY_CELLS_MASK -#undef EMPTY_CELLS_SHIFT -#undef EMPTY_CELLS_INDEX - -#define FLOAT_INDEX 17 -#define FLOAT_SHIFT 0 -#define FLOAT_MASK 0x3 -static inline css_error set_float( - css_computed_style *style, uint8_t type) -{ - uint8_t *bits = &style->i.bits[FLOAT_INDEX]; - - /* 2bits: type */ - *bits = (*bits & ~FLOAT_MASK) | - ((type & 0x3) << FLOAT_SHIFT); - - return CSS_OK; -} -#undef FLOAT_MASK -#undef FLOAT_SHIFT -#undef FLOAT_INDEX - -#define FONT_STYLE_INDEX 18 -#define FONT_STYLE_SHIFT 0 -#define FONT_STYLE_MASK 0x3 -static inline css_error set_font_style( - css_computed_style *style, uint8_t type) -{ - uint8_t *bits = &style->i.bits[FONT_STYLE_INDEX]; - - /* 2bits: type */ - *bits = (*bits & ~FONT_STYLE_MASK) | - ((type & 0x3) << FONT_STYLE_SHIFT); - - return CSS_OK; -} -#undef FONT_STYLE_MASK -#undef FONT_STYLE_SHIFT -#undef FONT_STYLE_INDEX - -#define MIN_HEIGHT_INDEX 19 -#define MIN_HEIGHT_SHIFT 3 -#define MIN_HEIGHT_MASK 0xf8 -static inline css_error set_min_height( - css_computed_style *style, uint8_t type, - css_fixed length, css_unit unit) -{ - uint8_t *bits = &style->i.bits[MIN_HEIGHT_INDEX]; - - /* 5bits: uuuut : units | type */ - *bits = (*bits & ~MIN_HEIGHT_MASK) | - (((type & 0x1) | (unit << 1)) << MIN_HEIGHT_SHIFT); - - style->i.min_height = length; - - return CSS_OK; -} -#undef MIN_HEIGHT_MASK -#undef MIN_HEIGHT_SHIFT -#undef MIN_HEIGHT_INDEX - -#define MIN_WIDTH_INDEX 20 -#define MIN_WIDTH_SHIFT 3 -#define MIN_WIDTH_MASK 0xf8 -static inline css_error set_min_width( - css_computed_style *style, uint8_t type, - css_fixed length, css_unit unit) -{ - uint8_t *bits = &style->i.bits[MIN_WIDTH_INDEX]; - - /* 5bits: uuuut : units | type */ - *bits = (*bits & ~MIN_WIDTH_MASK) | - (((type & 0x1) | (unit << 1)) << MIN_WIDTH_SHIFT); - - style->i.min_width = length; - - return CSS_OK; -} -#undef MIN_WIDTH_MASK -#undef MIN_WIDTH_SHIFT -#undef MIN_WIDTH_INDEX - -#define BACKGROUND_REPEAT_INDEX 19 -#define BACKGROUND_REPEAT_SHIFT 0 -#define BACKGROUND_REPEAT_MASK 0x7 -static inline css_error set_background_repeat( - css_computed_style *style, uint8_t type) -{ - uint8_t *bits = &style->i.bits[BACKGROUND_REPEAT_INDEX]; - - /* 3bits: type */ - *bits = (*bits & ~BACKGROUND_REPEAT_MASK) | - ((type & 0x7) << BACKGROUND_REPEAT_SHIFT); - - return CSS_OK; -} -#undef BACKGROUND_REPEAT_MASK -#undef BACKGROUND_REPEAT_SHIFT -#undef BACKGROUND_REPEAT_INDEX - -#define CLEAR_INDEX 20 -#define CLEAR_SHIFT 0 -#define CLEAR_MASK 0x7 -static inline css_error set_clear( - css_computed_style *style, uint8_t type) -{ - uint8_t *bits = &style->i.bits[CLEAR_INDEX]; - - /* 3bits: type */ - *bits = (*bits & ~CLEAR_MASK) | - ((type & 0x7) << CLEAR_SHIFT); - - return CSS_OK; -} -#undef CLEAR_MASK -#undef CLEAR_SHIFT -#undef CLEAR_INDEX - -#define PADDING_TOP_INDEX 21 -#define PADDING_TOP_SHIFT 3 -#define PADDING_TOP_MASK 0xf8 -static inline css_error set_padding_top( - css_computed_style *style, uint8_t type, - css_fixed length, css_unit unit) -{ - uint8_t *bits = &style->i.bits[PADDING_TOP_INDEX]; - - /* 5bits: uuuut : units | type */ - *bits = (*bits & ~PADDING_TOP_MASK) | - (((type & 0x1) | (unit << 1)) << PADDING_TOP_SHIFT); - - style->i.padding[0] = length; - - return CSS_OK; -} -#undef PADDING_TOP_MASK -#undef PADDING_TOP_SHIFT -#undef PADDING_TOP_INDEX - -#define PADDING_RIGHT_INDEX 22 -#define PADDING_RIGHT_SHIFT 3 -#define PADDING_RIGHT_MASK 0xf8 -static inline css_error set_padding_right( - css_computed_style *style, uint8_t type, - css_fixed length, css_unit unit) -{ - uint8_t *bits = &style->i.bits[PADDING_RIGHT_INDEX]; - - /* 5bits: uuuut : units | type */ - *bits = (*bits & ~PADDING_RIGHT_MASK) | - (((type & 0x1) | (unit << 1)) << PADDING_RIGHT_SHIFT); - - style->i.padding[1] = length; - - return CSS_OK; -} -#undef PADDING_RIGHT_MASK -#undef PADDING_RIGHT_SHIFT -#undef PADDING_RIGHT_INDEX - -#define PADDING_BOTTOM_INDEX 23 -#define PADDING_BOTTOM_SHIFT 3 -#define PADDING_BOTTOM_MASK 0xf8 -static inline css_error set_padding_bottom( - css_computed_style *style, uint8_t type, - css_fixed length, css_unit unit) -{ - uint8_t *bits = &style->i.bits[PADDING_BOTTOM_INDEX]; - - /* 5bits: uuuut : units | type */ - *bits = (*bits & ~PADDING_BOTTOM_MASK) | - (((type & 0x1) | (unit << 1)) << PADDING_BOTTOM_SHIFT); - - style->i.padding[2] = length; - - return CSS_OK; -} -#undef PADDING_BOTTOM_MASK -#undef PADDING_BOTTOM_SHIFT -#undef PADDING_BOTTOM_INDEX - -#define PADDING_LEFT_INDEX 24 -#define PADDING_LEFT_SHIFT 3 -#define PADDING_LEFT_MASK 0xf8 -static inline css_error set_padding_left( - css_computed_style *style, uint8_t type, - css_fixed length, css_unit unit) -{ - uint8_t *bits = &style->i.bits[PADDING_LEFT_INDEX]; - - /* 5bits: uuuut : units | type */ - *bits = (*bits & ~PADDING_LEFT_MASK) | - (((type & 0x1) | (unit << 1)) << PADDING_LEFT_SHIFT); - - style->i.padding[3] = length; - - return CSS_OK; -} -#undef PADDING_LEFT_MASK -#undef PADDING_LEFT_SHIFT -#undef PADDING_LEFT_INDEX - -#define OVERFLOW_X_INDEX 21 -#define OVERFLOW_X_SHIFT 0 -#define OVERFLOW_X_MASK 0x7 -static inline css_error set_overflow_x( - css_computed_style *style, uint8_t type) -{ - uint8_t *bits = &style->i.bits[OVERFLOW_X_INDEX]; - - /* 3bits: type */ - *bits = (*bits & ~OVERFLOW_X_MASK) | - ((type & 0x7) << OVERFLOW_X_SHIFT); - - return CSS_OK; -} -#undef OVERFLOW_X_MASK -#undef OVERFLOW_X_SHIFT -#undef OVERFLOW_X_INDEX - -#define OVERFLOW_Y_INDEX 34 -#define OVERFLOW_Y_SHIFT 5 -#define OVERFLOW_Y_MASK 0xe0 -static inline css_error set_overflow_y( - css_computed_style *style, uint8_t type) -{ - uint8_t *bits = &style->i.bits[OVERFLOW_Y_INDEX]; - - /* 3bits: type */ - *bits = (*bits & ~OVERFLOW_Y_MASK) | - ((type & 0x7) << OVERFLOW_Y_SHIFT); - - return CSS_OK; -} -#undef OVERFLOW_Y_MASK -#undef OVERFLOW_Y_SHIFT -#undef OVERFLOW_Y_INDEX - -#define POSITION_INDEX 22 -#define POSITION_SHIFT 0 -#define POSITION_MASK 0x7 -static inline css_error set_position( - css_computed_style *style, uint8_t type) -{ - uint8_t *bits = &style->i.bits[POSITION_INDEX]; - - /* 3bits: type */ - *bits = (*bits & ~POSITION_MASK) | - ((type & 0x7) << POSITION_SHIFT); - - return CSS_OK; -} -#undef POSITION_MASK -#undef POSITION_SHIFT -#undef POSITION_INDEX - -#define OPACITY_INDEX 23 -#define OPACITY_SHIFT 2 -#define OPACITY_MASK 0x04 -static inline css_error set_opacity( - css_computed_style *style, - uint8_t type, css_fixed opacity) -{ - uint8_t *bits = &style->i.bits[OPACITY_INDEX]; - - /* 1bit: t : type */ - *bits = (*bits & ~OPACITY_MASK) | - ((type & 0x1) << OPACITY_SHIFT); - - style->i.opacity = opacity; - - return CSS_OK; -} -#undef OPACITY_MASK -#undef OPACITY_SHIFT -#undef OPACITY_INDEX - -#define TEXT_TRANSFORM_INDEX 24 -#define TEXT_TRANSFORM_SHIFT 0 -#define TEXT_TRANSFORM_MASK 0x7 -static inline css_error set_text_transform( - css_computed_style *style, uint8_t type) -{ - uint8_t *bits = &style->i.bits[TEXT_TRANSFORM_INDEX]; - - /* 3bits: type */ - *bits = (*bits & ~TEXT_TRANSFORM_MASK) | - ((type & 0x7) << TEXT_TRANSFORM_SHIFT); - - return CSS_OK; -} -#undef TEXT_TRANSFORM_MASK -#undef TEXT_TRANSFORM_SHIFT -#undef TEXT_TRANSFORM_INDEX - -#define TEXT_INDENT_INDEX 25 -#define TEXT_INDENT_SHIFT 3 -#define TEXT_INDENT_MASK 0xf8 -static inline css_error set_text_indent( - css_computed_style *style, uint8_t type, - css_fixed length, css_unit unit) -{ - uint8_t *bits = &style->i.bits[TEXT_INDENT_INDEX]; - - /* 5bits: uuuut : units | type */ - *bits = (*bits & ~TEXT_INDENT_MASK) | - (((type & 0x1) | (unit << 1)) << TEXT_INDENT_SHIFT); - - style->i.text_indent = length; - - return CSS_OK; -} -#undef TEXT_INDENT_MASK -#undef TEXT_INDENT_SHIFT -#undef TEXT_INDENT_INDEX - -#define WHITE_SPACE_INDEX 25 -#define WHITE_SPACE_SHIFT 0 -#define WHITE_SPACE_MASK 0x7 -static inline css_error set_white_space( - css_computed_style *style, uint8_t type) -{ - uint8_t *bits = &style->i.bits[WHITE_SPACE_INDEX]; - - /* 3bits: type */ - *bits = (*bits & ~WHITE_SPACE_MASK) | - ((type & 0x7) << WHITE_SPACE_SHIFT); - - return CSS_OK; -} -#undef WHITE_SPACE_MASK -#undef WHITE_SPACE_SHIFT -#undef WHITE_SPACE_INDEX - -#define BACKGROUND_POSITION_INDEX 27 -#define BACKGROUND_POSITION_SHIFT 7 -#define BACKGROUND_POSITION_MASK 0x80 -#define BACKGROUND_POSITION_INDEX1 26 -#define BACKGROUND_POSITION_SHIFT1 0 -static inline css_error set_background_position( - css_computed_style *style, uint8_t type, - css_fixed hlength, css_unit hunit, - css_fixed vlength, css_unit vunit) -{ - uint8_t *bits; - - bits = &style->i.bits[BACKGROUND_POSITION_INDEX]; - - /* 1 bit: type */ - *bits = (*bits & ~BACKGROUND_POSITION_MASK) | - ((type & 0x1) << BACKGROUND_POSITION_SHIFT); - - bits = &style->i.bits[BACKGROUND_POSITION_INDEX1]; - - /* 8bits: hhhhvvvv : hunit | vunit */ - *bits = (((hunit << 4) | vunit) << BACKGROUND_POSITION_SHIFT1); - - style->i.background_position[0] = hlength; - style->i.background_position[1] = vlength; - - return CSS_OK; -} -#undef BACKGROUND_POSITION_SHIFT1 -#undef BACKGROUND_POSITION_INDEX1 -#undef BACKGROUND_POSITION_MASK -#undef BACKGROUND_POSITION_SHIFT -#undef BACKGROUND_POSITION_INDEX - -#define DISPLAY_INDEX 27 -#define DISPLAY_SHIFT 2 -#define DISPLAY_MASK 0x7c -static inline css_error set_display( - css_computed_style *style, uint8_t type) -{ - uint8_t *bits = &style->i.bits[DISPLAY_INDEX]; - - /* 5bits: type */ - *bits = (*bits & ~DISPLAY_MASK) | - ((type & 0x1f) << DISPLAY_SHIFT); - - return CSS_OK; -} -#undef DISPLAY_MASK -#undef DISPLAY_SHIFT -#undef DISPLAY_INDEX - -#define FONT_VARIANT_INDEX 27 -#define FONT_VARIANT_SHIFT 0 -#define FONT_VARIANT_MASK 0x3 -static inline css_error set_font_variant( - css_computed_style *style, uint8_t type) -{ - uint8_t *bits = &style->i.bits[FONT_VARIANT_INDEX]; - - /* 2bits: type */ - *bits = (*bits & ~FONT_VARIANT_MASK) | - ((type & 0x3) << FONT_VARIANT_SHIFT); - - return CSS_OK; -} -#undef FONT_VARIANT_MASK -#undef FONT_VARIANT_SHIFT -#undef FONT_VARIANT_INDEX - -#define TEXT_DECORATION_INDEX 28 -#define TEXT_DECORATION_SHIFT 3 -#define TEXT_DECORATION_MASK 0xf8 -static inline css_error set_text_decoration( - css_computed_style *style, uint8_t type) -{ - uint8_t *bits = &style->i.bits[TEXT_DECORATION_INDEX]; - - /* 5bits: type */ - *bits = (*bits & ~TEXT_DECORATION_MASK) | - ((type & 0x1f) << TEXT_DECORATION_SHIFT); - - return CSS_OK; -} -#undef TEXT_DECORATION_MASK -#undef TEXT_DECORATION_SHIFT -#undef TEXT_DECORATION_INDEX - -#define FONT_FAMILY_INDEX 28 -#define FONT_FAMILY_SHIFT 0 -#define FONT_FAMILY_MASK 0x7 -static inline css_error set_font_family( - css_computed_style *style, uint8_t type, - lwc_string **names) -{ - uint8_t *bits = &style->i.bits[FONT_FAMILY_INDEX]; - lwc_string **oldnames = style->font_family; - lwc_string **s; - - /* 3bits: type */ - *bits = (*bits & ~FONT_FAMILY_MASK) | - ((type & 0x7) << FONT_FAMILY_SHIFT); - - for (s = names; s != NULL && *s != NULL; s++) - *s = lwc_string_ref(*s); - - style->font_family = names; - - /* Free existing families */ - if (oldnames != NULL) { - for (s = oldnames; *s != NULL; s++) - lwc_string_unref(*s); - - if (oldnames != names) - free(oldnames); - } - - return CSS_OK; -} -#undef FONT_FAMILY_MASK -#undef FONT_FAMILY_SHIFT -#undef FONT_FAMILY_INDEX - -#define BORDER_TOP_STYLE_INDEX 29 -#define BORDER_TOP_STYLE_SHIFT 4 -#define BORDER_TOP_STYLE_MASK 0xf0 -static inline css_error set_border_top_style( - css_computed_style *style, uint8_t type) -{ - uint8_t *bits = &style->i.bits[BORDER_TOP_STYLE_INDEX]; - - /* 4bits: type */ - *bits = (*bits & ~BORDER_TOP_STYLE_MASK) | - ((type & 0xf) << BORDER_TOP_STYLE_SHIFT); - - return CSS_OK; -} -#undef BORDER_TOP_STYLE_MASK -#undef BORDER_TOP_STYLE_SHIFT -#undef BORDER_TOP_STYLE_INDEX - -#define BORDER_RIGHT_STYLE_INDEX 29 -#define BORDER_RIGHT_STYLE_SHIFT 0 -#define BORDER_RIGHT_STYLE_MASK 0xf -static inline css_error set_border_right_style( - css_computed_style *style, uint8_t type) -{ - uint8_t *bits = &style->i.bits[BORDER_RIGHT_STYLE_INDEX]; - - /* 4bits: type */ - *bits = (*bits & ~BORDER_RIGHT_STYLE_MASK) | - ((type & 0xf) << BORDER_RIGHT_STYLE_SHIFT); - - return CSS_OK; -} -#undef BORDER_RIGHT_STYLE_MASK -#undef BORDER_RIGHT_STYLE_SHIFT -#undef BORDER_RIGHT_STYLE_INDEX - -#define BORDER_BOTTOM_STYLE_INDEX 30 -#define BORDER_BOTTOM_STYLE_SHIFT 4 -#define BORDER_BOTTOM_STYLE_MASK 0xf0 -static inline css_error set_border_bottom_style( - css_computed_style *style, uint8_t type) -{ - uint8_t *bits = &style->i.bits[BORDER_BOTTOM_STYLE_INDEX]; - - /* 4bits: type */ - *bits = (*bits & ~BORDER_BOTTOM_STYLE_MASK) | - ((type & 0xf) << BORDER_BOTTOM_STYLE_SHIFT); - - return CSS_OK; -} -#undef BORDER_BOTTOM_STYLE_MASK -#undef BORDER_BOTTOM_STYLE_SHIFT -#undef BORDER_BOTTOM_STYLE_INDEX - -#define BORDER_LEFT_STYLE_INDEX 30 -#define BORDER_LEFT_STYLE_SHIFT 0 -#define BORDER_LEFT_STYLE_MASK 0xf -static inline css_error set_border_left_style( - css_computed_style *style, uint8_t type) -{ - uint8_t *bits = &style->i.bits[BORDER_LEFT_STYLE_INDEX]; - - /* 4bits: type */ - *bits = (*bits & ~BORDER_LEFT_STYLE_MASK) | - ((type & 0xf) << BORDER_LEFT_STYLE_SHIFT); - - return CSS_OK; -} -#undef BORDER_LEFT_STYLE_MASK -#undef BORDER_LEFT_STYLE_SHIFT -#undef BORDER_LEFT_STYLE_INDEX - -#define FONT_WEIGHT_INDEX 31 -#define FONT_WEIGHT_SHIFT 4 -#define FONT_WEIGHT_MASK 0xf0 -static inline css_error set_font_weight( - css_computed_style *style, uint8_t type) -{ - uint8_t *bits = &style->i.bits[FONT_WEIGHT_INDEX]; - - /* 4bits: type */ - *bits = (*bits & ~FONT_WEIGHT_MASK) | - ((type & 0xf) << FONT_WEIGHT_SHIFT); - - return CSS_OK; -} -#undef FONT_WEIGHT_MASK -#undef FONT_WEIGHT_SHIFT -#undef FONT_WEIGHT_INDEX - -#define LIST_STYLE_TYPE_INDEX 31 -#define LIST_STYLE_TYPE_SHIFT 0 -#define LIST_STYLE_TYPE_MASK 0xf -static inline css_error set_list_style_type( - css_computed_style *style, uint8_t type) -{ - uint8_t *bits = &style->i.bits[LIST_STYLE_TYPE_INDEX]; - - /* 4bits: type */ - *bits = (*bits & ~LIST_STYLE_TYPE_MASK) | - ((type & 0xf) << LIST_STYLE_TYPE_SHIFT); - - return CSS_OK; -} -#undef LIST_STYLE_TYPE_MASK -#undef LIST_STYLE_TYPE_SHIFT -#undef LIST_STYLE_TYPE_INDEX - -#define OUTLINE_STYLE_INDEX 32 -#define OUTLINE_STYLE_SHIFT 4 -#define OUTLINE_STYLE_MASK 0xf0 -static inline css_error set_outline_style( - css_computed_style *style, uint8_t type) -{ - uint8_t *bits = &style->i.bits[OUTLINE_STYLE_INDEX]; - - /* 4bits: type */ - *bits = (*bits & ~OUTLINE_STYLE_MASK) | - ((type & 0xf) << OUTLINE_STYLE_SHIFT); - - return CSS_OK; -} -#undef OUTLINE_STYLE_MASK -#undef OUTLINE_STYLE_SHIFT -#undef OUTLINE_STYLE_INDEX - -#define TABLE_LAYOUT_INDEX 32 -#define TABLE_LAYOUT_SHIFT 2 -#define TABLE_LAYOUT_MASK 0xc -static inline css_error set_table_layout( - css_computed_style *style, uint8_t type) -{ - uint8_t *bits = &style->i.bits[TABLE_LAYOUT_INDEX]; - - /* 2bits: type */ - *bits = (*bits & ~TABLE_LAYOUT_MASK) | - ((type & 0x3) << TABLE_LAYOUT_SHIFT); - - return CSS_OK; -} -#undef TABLE_LAYOUT_MASK -#undef TABLE_LAYOUT_SHIFT -#undef TABLE_LAYOUT_INDEX - -#define UNICODE_BIDI_INDEX 32 -#define UNICODE_BIDI_SHIFT 0 -#define UNICODE_BIDI_MASK 0x3 -static inline css_error set_unicode_bidi( - css_computed_style *style, uint8_t type) -{ - uint8_t *bits = &style->i.bits[UNICODE_BIDI_INDEX]; - - /* 2bits: type */ - *bits = (*bits & ~UNICODE_BIDI_MASK) | - ((type & 0x3) << UNICODE_BIDI_SHIFT); - - return CSS_OK; -} -#undef UNICODE_BIDI_MASK -#undef UNICODE_BIDI_SHIFT -#undef UNICODE_BIDI_INDEX - -#define VISIBILITY_INDEX 33 -#define VISIBILITY_SHIFT 6 -#define VISIBILITY_MASK 0xc0 -static inline css_error set_visibility( - css_computed_style *style, uint8_t type) -{ - uint8_t *bits = &style->i.bits[VISIBILITY_INDEX]; - - /* 2bits: type */ - *bits = (*bits & ~VISIBILITY_MASK) | - ((type & 0x3) << VISIBILITY_SHIFT); - - return CSS_OK; -} -#undef VISIBILITY_MASK -#undef VISIBILITY_SHIFT -#undef VISIBILITY_INDEX - -#define LIST_STYLE_POSITION_INDEX 33 -#define LIST_STYLE_POSITION_SHIFT 4 -#define LIST_STYLE_POSITION_MASK 0x30 -static inline css_error set_list_style_position( - css_computed_style *style, uint8_t type) -{ - uint8_t *bits = &style->i.bits[LIST_STYLE_POSITION_INDEX]; - - /* 2bits: type */ - *bits = (*bits & ~LIST_STYLE_POSITION_MASK) | - ((type & 0x3) << LIST_STYLE_POSITION_SHIFT); - - return CSS_OK; -} -#undef LIST_STYLE_POSITION_MASK -#undef LIST_STYLE_POSITION_SHIFT -#undef LIST_STYLE_POSITION_INDEX - -#define TEXT_ALIGN_INDEX 33 -#define TEXT_ALIGN_SHIFT 0 -#define TEXT_ALIGN_MASK 0xf -static inline uint8_t set_text_align( - css_computed_style *style, uint8_t type) -{ - uint8_t *bits = &style->i.bits[TEXT_ALIGN_INDEX]; - - /* 4bits: type */ - *bits = (*bits & ~TEXT_ALIGN_MASK) | - ((type & 0xf) << TEXT_ALIGN_SHIFT); - - return CSS_OK; -} -#undef TEXT_ALIGN_MASK -#undef TEXT_ALIGN_SHIFT -#undef TEXT_ALIGN_INDEX - -#define PAGE_BREAK_AFTER_INDEX 0 -#define PAGE_BREAK_AFTER_SHIFT 0 -#define PAGE_BREAK_AFTER_MASK 0x7 -static inline css_error set_page_break_after( - css_computed_style *style, uint8_t type) -{ - uint8_t *bits; - - if (style->page == NULL) { - if (type == CSS_PAGE_BREAK_AFTER_AUTO) { - return CSS_OK; - } - } - - ENSURE_PAGE; - - bits = &style->page->bits[PAGE_BREAK_AFTER_INDEX]; - - /* 3bits: type */ - *bits = (*bits & ~PAGE_BREAK_AFTER_MASK) | - ((type & 0x7) << PAGE_BREAK_AFTER_SHIFT); - - return CSS_OK; -} -#undef PAGE_BREAK_AFTER_INDEX -#undef PAGE_BREAK_AFTER_SHIFT -#undef PAGE_BREAK_AFTER_MASK - -#define PAGE_BREAK_BEFORE_INDEX 0 -#define PAGE_BREAK_BEFORE_SHIFT 3 -#define PAGE_BREAK_BEFORE_MASK 0x38 -static inline css_error set_page_break_before( - css_computed_style *style, uint8_t type) -{ - uint8_t *bits; - - if (style->page == NULL) { - if (type == CSS_PAGE_BREAK_BEFORE_AUTO) { - return CSS_OK; - } - } - - ENSURE_PAGE; - - bits = &style->page->bits[PAGE_BREAK_BEFORE_INDEX]; - - /* 3bits: type */ - *bits = (*bits & ~PAGE_BREAK_BEFORE_MASK) | - ((type & 0x7) << PAGE_BREAK_BEFORE_SHIFT); - - return CSS_OK; -} -#undef PAGE_BREAK_BEFORE_INDEX -#undef PAGE_BREAK_BEFORE_SHIFT -#undef PAGE_BREAK_BEFORE_MASK - -#define PAGE_BREAK_INSIDE_INDEX 0 -#define PAGE_BREAK_INSIDE_SHIFT 6 -#define PAGE_BREAK_INSIDE_MASK 0xc0 -static inline css_error set_page_break_inside( - css_computed_style *style, uint8_t type) -{ - uint8_t *bits; - - if (style->page == NULL) { - if (type == CSS_PAGE_BREAK_INSIDE_AUTO) { - return CSS_OK; - } - } - - ENSURE_PAGE; - - bits = &style->page->bits[PAGE_BREAK_INSIDE_INDEX]; - - /* 2bits: type */ - *bits = (*bits & ~PAGE_BREAK_INSIDE_MASK) | - ((type & 0x3) << PAGE_BREAK_INSIDE_SHIFT); - - return CSS_OK; -} -#undef PAGE_BREAK_INSIDE_INDEX -#undef PAGE_BREAK_INSIDE_SHIFT -#undef PAGE_BREAK_INSIDE_MASK - -#define ORPHANS_INDEX 1 -#define ORPHANS_SHIFT 0 -#define ORPHANS_MASK 0x1 -static inline css_error set_orphans( - css_computed_style *style, uint8_t type, int32_t count) -{ - uint8_t *bits; - - if (style->page == NULL) { - if (type == CSS_ORPHANS_SET && count == 2) { - return CSS_OK; - } - } - - ENSURE_PAGE; - - bits = &style->page->bits[ORPHANS_INDEX]; - - /* 1bit: type */ - *bits = (*bits & ~ORPHANS_MASK) | ((type & 0x1) << ORPHANS_SHIFT); - - style->page->orphans = count; - - return CSS_OK; -} -#undef ORPHANS_INDEX -#undef ORPHANS_SHIFT -#undef ORPHANS_MASK - -#define WIDOWS_INDEX 1 -#define WIDOWS_SHIFT 1 -#define WIDOWS_MASK 0x2 -static inline css_error set_widows( - css_computed_style *style, uint8_t type, int32_t count) -{ - uint8_t *bits; - - if (style->page == NULL) { - if (type == CSS_WIDOWS_SET && count == 2) { - return CSS_OK; - } - } - - ENSURE_PAGE; - - bits = &style->page->bits[WIDOWS_INDEX]; - - /* 1bit: type */ - *bits = (*bits & ~WIDOWS_MASK) | ((type & 0x1) << WIDOWS_SHIFT); - - style->page->widows = count; - - return CSS_OK; -} -#undef WIDOWS_INDEX -#undef WIDOWS_SHIFT -#undef WIDOWS_MASK +#include "autogenerated_propset.h" #endif diff --git a/src/select/select.c b/src/select/select.c index 6b5225a..da0aa61 100644 --- a/src/select/select.c +++ b/src/select/select.c @@ -19,9 +19,12 @@ #include "select/computed.h" #include "select/dispatch.h" #include "select/hash.h" +#include "select/mq.h" #include "select/propset.h" #include "select/font_face.h" #include "select/select.h" +#include "select/strings.h" +#include "select/unit.h" #include "utils/parserutilserror.h" #include "utils/utils.h" @@ -37,7 +40,7 @@ typedef struct css_select_sheet { const css_stylesheet *sheet; /**< Stylesheet */ css_origin origin; /**< Stylesheet origin */ - uint64_t media; /**< Applicable media */ + css_mq_query *media; /**< Applicable media */ } css_select_sheet; /** @@ -50,34 +53,9 @@ struct css_select_ctx { void *pw; /**< Client's private selection context */ - /* Useful interned strings */ - lwc_string *universal; - lwc_string *first_child; - lwc_string *link; - lwc_string *visited; - lwc_string *hover; - lwc_string *active; - lwc_string *focus; - lwc_string *nth_child; - lwc_string *nth_last_child; - lwc_string *nth_of_type; - lwc_string *nth_last_of_type; - lwc_string *last_child; - lwc_string *first_of_type; - lwc_string *last_of_type; - lwc_string *only_child; - lwc_string *only_of_type; - lwc_string *root; - lwc_string *empty; - lwc_string *target; - lwc_string *lang; - lwc_string *enabled; - lwc_string *disabled; - lwc_string *checked; - lwc_string *first_line; - lwc_string *first_letter; - lwc_string *before; - lwc_string *after; + bool uses_revert; /**< A sheet used revert property value */ + + css_select_strings str; /* Interned default style */ css_computed_style *default_style; @@ -96,7 +74,8 @@ typedef struct css_select_font_faces_list { */ typedef struct css_select_font_faces_state { lwc_string *font_family; - uint64_t media; + const css_media *media; + const css_unit_ctx *unit_ctx; css_select_font_faces_list ua_font_faces; css_select_font_faces_list user_font_faces; @@ -122,9 +101,6 @@ static css_error set_initial(css_select_state *state, uint32_t prop, css_pseudo_element pseudo, void *parent); -static css_error intern_strings(css_select_ctx *ctx); -static void destroy_strings(css_select_ctx *ctx); - static css_error select_from_sheet(css_select_ctx *ctx, const css_stylesheet *sheet, css_origin origin, css_select_state *state); @@ -150,7 +126,8 @@ static css_error cascade_style(const css_style *style, css_select_state *state); static css_error select_font_faces_from_sheet( const css_stylesheet *sheet, css_origin origin, - css_select_font_faces_state *state); + css_select_font_faces_state *state, + const css_select_strings *str); #ifdef DEBUG_CHAIN_MATCHING static void dump_chain(const css_selector *selector); @@ -261,7 +238,7 @@ css_error css_select_ctx_create(css_select_ctx **result) if (c == NULL) return CSS_NOMEM; - error = intern_strings(c); + error = css_select_strings_intern(&c->str); if (error != CSS_OK) { free(c); return error; @@ -283,13 +260,17 @@ css_error css_select_ctx_destroy(css_select_ctx *ctx) if (ctx == NULL) return CSS_BADPARM; - destroy_strings(ctx); + css_select_strings_unref(&ctx->str); if (ctx->default_style != NULL) css_computed_style_destroy(ctx->default_style); - if (ctx->sheets != NULL) + if (ctx->sheets != NULL) { + for (uint32_t index = 0; index < ctx->n_sheets; index++) { + css__mq_query_destroy(ctx->sheets[index].media); + } free(ctx->sheets); + } free(ctx); @@ -302,12 +283,12 @@ css_error css_select_ctx_destroy(css_select_ctx *ctx) * \param ctx The context to append to * \param sheet The sheet to append * \param origin Origin of the sheet - * \param media Media types to which the sheet applies + * \param media Media string for the stylesheet * \return CSS_OK on success, appropriate error otherwise */ css_error css_select_ctx_append_sheet(css_select_ctx *ctx, const css_stylesheet *sheet, css_origin origin, - uint64_t media) + const char *media) { if (ctx == NULL || sheet == NULL) return CSS_BADPARM; @@ -323,14 +304,16 @@ css_error css_select_ctx_append_sheet(css_select_ctx *ctx, * \param sheet Sheet to insert * \param index Index in context to insert sheet * \param origin Origin of the sheet - * \param media Media types to which the sheet applies + * \param media Media string for the stylesheet * \return CSS_OK on success, appropriate error otherwise */ css_error css_select_ctx_insert_sheet(css_select_ctx *ctx, const css_stylesheet *sheet, uint32_t index, - css_origin origin, uint64_t media) + css_origin origin, const char *media) { css_select_sheet *temp; + css_mq_query *mq; + css_error error; if (ctx == NULL || sheet == NULL) return CSS_BADPARM; @@ -356,9 +339,25 @@ css_error css_select_ctx_insert_sheet(css_select_ctx *ctx, (ctx->n_sheets - index) * sizeof(css_select_sheet)); } + error = css_parse_media_query(sheet->propstrings, + (const uint8_t *)media, + (media == NULL) ? 0 : strlen(media), &mq); + if (error == CSS_NOMEM) { + return error; + } else if (error != CSS_OK) { + /* Fall back to default media: "all". */ + mq = calloc(1, sizeof(*mq)); + if (mq == NULL) { + return CSS_NOMEM; + } + mq->type = CSS_MEDIA_ALL; + } + ctx->sheets[index].sheet = sheet; ctx->sheets[index].origin = origin; - ctx->sheets[index].media = media; + ctx->sheets[index].media = mq; + + ctx->uses_revert |= sheet->uses_revert; ctx->n_sheets++; @@ -388,6 +387,8 @@ css_error css_select_ctx_remove_sheet(css_select_ctx *ctx, if (index == ctx->n_sheets) return CSS_INVALID; + css__mq_query_destroy(ctx->sheets[index].media); + ctx->n_sheets--; memmove(&ctx->sheets[index], &ctx->sheets[index + 1], @@ -1022,25 +1023,40 @@ static void css_select__finalise_selection_state( if (state->element.name != NULL){ lwc_string_unref(state->element.name); } + + if (state->revert != NULL) { + for (size_t i = 0; i < CSS_ORIGIN_AUTHOR; i++) { + for (size_t j = 0; j < CSS_PSEUDO_ELEMENT_COUNT; j++) { + if (state->revert[i].style[j] == NULL) { + continue; + } + css_computed_style_destroy( + state->revert[i].style[j]); + } + } + free(state->revert); + } } /** * Initialise a selection state. * - * \param[in] state The selection state to initialise - * \param[in] node The node we are selecting for. - * \param[in] parent The node's parent node, or NULL. - * \param[in] media The media type we're selecting for. - * \param[in] handler The client selection callback table. - * \param[in] pw The client private data, passsed out to callbacks. + * \param[in] state The selection state to initialise + * \param[in] node The node we are selecting for. + * \param[in] parent The node's parent node, or NULL. + * \param[in] media The media specification we're selecting for. + * \param[in] unit_ctx Unit conversion context. + * \param[in] handler The client selection callback table. + * \param[in] pw The client private data, passsed out to callbacks. * \return CSS_OK or appropriate error otherwise. */ static css_error css_select__initialise_selection_state( css_select_state *state, void *node, void *parent, - uint64_t media, + const css_media *media, + const css_unit_ctx *unit_ctx, css_select_handler *handler, void *pw) { @@ -1051,6 +1067,7 @@ static css_error css_select__initialise_selection_state( memset(state, 0, sizeof(*state)); state->node = node; state->media = media; + state->unit_ctx = unit_ctx; state->handler = handler; state->pw = pw; state->next_reject = state->reject_cache + @@ -1135,13 +1152,80 @@ failed: return error; } +static css_error css__select_revert_property_to_origin( + css_select_state *select_state, + prop_state *prop_state, + css_origin origin, + enum css_pseudo_element pseudo, + enum css_properties_e property) +{ + css_error error; + + if (select_state->results->styles[pseudo] == NULL) { + return CSS_OK; + } + + if (select_state->revert[origin].style[pseudo] == NULL) { + return prop_dispatch[property].initial(select_state); + } + + error = prop_dispatch[property].copy( + select_state->revert[origin].style[pseudo], + select_state->results->styles[pseudo]); + if (error != CSS_OK) { + return error; + } + + *prop_state = select_state->revert[origin].props[property][pseudo]; + return CSS_OK; +} + +static css_error css__select_revert_property( + css_select_state *select_state, + prop_state *prop_state, + enum css_pseudo_element pseudo, + enum css_properties_e property) +{ + css_error error; + + switch (prop_state->origin) { + case CSS_ORIGIN_AUTHOR: + error = css__select_revert_property_to_origin( + select_state, prop_state, CSS_ORIGIN_USER, + pseudo, property); + if (error != CSS_OK) { + return error; + } + if (prop_state->explicit_default != FLAG_VALUE_REVERT) { + break; + } + /* Fall-through */ + case CSS_ORIGIN_USER: + error = css__select_revert_property_to_origin( + select_state, prop_state, CSS_ORIGIN_UA, + pseudo, property); + if (error != CSS_OK) { + return error; + } + if (prop_state->explicit_default != FLAG_VALUE_REVERT) { + break; + } + /* Fall-through */ + case CSS_ORIGIN_UA: + prop_state->explicit_default = FLAG_VALUE_UNSET; + break; + } + + return CSS_OK; +} /** * Select a style for the given node * * \param ctx Selection context to use * \param node Node to select style for - * \param media Currently active media types + * \param unit_ctx Context for length unit conversions. + * \param media Currently active media specification * \param inline_style Corresponding inline style for node, or NULL * \param handler Dispatch table of handler functions * \param pw Client-specific private data for handler functions @@ -1158,10 +1242,12 @@ failed: * update the fully computed style for a node when layout changes. */ css_error css_select_style(css_select_ctx *ctx, void *node, - uint64_t media, const css_stylesheet *inline_style, + const css_unit_ctx *unit_ctx, + const css_media *media, const css_stylesheet *inline_style, css_select_handler *handler, void *pw, css_select_results **result) { + css_origin origin = CSS_ORIGIN_UA; uint32_t i, j, nhints; css_error error; css_select_state state; @@ -1178,7 +1264,7 @@ css_error css_select_style(css_select_ctx *ctx, void *node, return error; error = css_select__initialise_selection_state( - &state, node, parent, media, handler, pw); + &state, node, parent, media, unit_ctx, handler, pw); if (error != CSS_OK) return error; @@ -1214,8 +1300,18 @@ css_error css_select_style(css_select_ctx *ctx, void *node, printf("style:\t%s\tSELECTED\n", lwc_string_data(state.element.name)); #endif - /* Not sharing; need to select. - * Base element style is guaranteed to exist + /* Not sharing; need to select. */ + if (ctx->uses_revert || + (inline_style != NULL && inline_style->uses_revert)) { + /* Need to track UA and USER origin styles for revert. */ + state.revert = calloc(CSS_ORIGIN_AUTHOR, sizeof(*state.revert)); + if (state.revert == NULL) { + error = CSS_NOMEM; + goto cleanup; + } + } + + /* Base element style is guaranteed to exist */ error = css__computed_style_create( &state.results->styles[CSS_PSEUDO_ELEMENT_NONE]); @@ -1240,10 +1336,30 @@ css_error css_select_style(css_select_ctx *ctx, void *node, /* Iterate through the top-level stylesheets, selecting styles * from those which apply to our current media requirements and * are not disabled */ + if (ctx->n_sheets > 0) { + origin = ctx->sheets[0].origin; + } for (i = 0; i < ctx->n_sheets; i++) { const css_select_sheet s = ctx->sheets[i]; - if ((s.media & media) != 0 && + if (state.revert != NULL && s.origin != origin) { + for (j = 0; j < CSS_PSEUDO_ELEMENT_COUNT; j++) { + if (state.results->styles[j] == NULL) { + continue; + } + error = css__computed_style_clone( + state.results->styles[j], + &state.revert[origin].style[j]); + if (error != CSS_OK) { + goto cleanup; + } + memcpy(state.revert[origin].props, + state.props, sizeof(state.props)); + } + origin = s.origin; + } + + if (mq__list_match(s.media, unit_ctx, media, &ctx->str) && s.sheet->disabled == false) { error = select_from_sheet(ctx, s.sheet, s.origin, &state); @@ -1284,15 +1400,31 @@ css_error css_select_style(css_select_ctx *ctx, void *node, state.current_pseudo = CSS_PSEUDO_ELEMENT_NONE; state.computed = state.results->styles[CSS_PSEUDO_ELEMENT_NONE]; for (i = 0; i < CSS_N_PROPERTIES; i++) { - const prop_state *prop = - &state.props[i][CSS_PSEUDO_ELEMENT_NONE]; + prop_state *prop = &state.props[i][CSS_PSEUDO_ELEMENT_NONE]; + + if (prop->explicit_default == FLAG_VALUE_REVERT) { + error = css__select_revert_property(&state, prop, + CSS_PSEUDO_ELEMENT_NONE, i); + if (error != CSS_OK) { + goto cleanup; + } + } + + if (prop->explicit_default == FLAG_VALUE_UNSET) { + if (prop_dispatch[i].inherited == true) { + prop->explicit_default = FLAG_VALUE_INHERIT; + } else { + prop->explicit_default = FLAG_VALUE_INITIAL; + } + } /* If the property is still unset or it's set to inherit * and we're the root element, then set it to its initial * value. */ - if (prop->set == false || + if (prop->explicit_default == FLAG_VALUE_INITIAL || + prop->set == false || (parent == NULL && - prop->inherit == true)) { + prop->explicit_default == FLAG_VALUE_INHERIT)) { error = set_initial(&state, i, CSS_PSEUDO_ELEMENT_NONE, parent); if (error != CSS_OK) @@ -1310,11 +1442,28 @@ css_error css_select_style(css_select_ctx *ctx, void *node, continue; for (i = 0; i < CSS_N_PROPERTIES; i++) { - const prop_state *prop = &state.props[i][j]; + prop_state *prop = &state.props[i][j]; + + if (prop->explicit_default == FLAG_VALUE_REVERT) { + error = css__select_revert_property(&state, + prop, j, i); + if (error != CSS_OK) { + goto cleanup; + } + } + + if (prop->explicit_default == FLAG_VALUE_UNSET) { + if (prop_dispatch[i].inherited == true) { + prop->explicit_default = FLAG_VALUE_INHERIT; + } else { + prop->explicit_default = FLAG_VALUE_INITIAL; + } + } /* If the property is still unset then set it * to its initial value. */ - if (prop->set == false) { + if (prop->explicit_default == FLAG_VALUE_INITIAL || + prop->set == false) { error = set_initial(&state, i, j, parent); if (error != CSS_OK) goto cleanup; @@ -1330,7 +1479,7 @@ css_error css_select_style(css_select_ctx *ctx, void *node, /* Only compute absolute values for the base element */ error = css__compute_absolute_values(NULL, state.results->styles[CSS_PSEUDO_ELEMENT_NONE], - handler->compute_font_size, pw); + unit_ctx); if (error != CSS_OK) goto cleanup; } @@ -1393,13 +1542,16 @@ css_error css_select_results_destroy(css_select_results *results) * Search a selection context for defined font faces * * \param ctx Selection context - * \param media Currently active media types + * \param media Currently active media spec + * \param unit_ctx Current unit conversion context. * \param font_family Font family to search for * \param result Pointer to location to receive result * \return CSS_OK on success, appropriate error otherwise. */ css_error css_select_font_faces(css_select_ctx *ctx, - uint64_t media, lwc_string *font_family, + const css_media *media, + const css_unit_ctx *unit_ctx, + lwc_string *font_family, css_select_font_faces_results **result) { uint32_t i; @@ -1413,6 +1565,7 @@ css_error css_select_font_faces(css_select_ctx *ctx, memset(&state, 0, sizeof(css_select_font_faces_state)); state.font_family = font_family; state.media = media; + state.unit_ctx = unit_ctx; /* Iterate through the top-level stylesheets, selecting font-faces * from those which apply to our current media requirements and @@ -1420,10 +1573,10 @@ css_error css_select_font_faces(css_select_ctx *ctx, for (i = 0; i < ctx->n_sheets; i++) { const css_select_sheet s = ctx->sheets[i]; - if ((s.media & media) != 0 && + if (mq__list_match(s.media, unit_ctx, media, &ctx->str) && s.sheet->disabled == false) { error = select_font_faces_from_sheet(s.sheet, - s.origin, &state); + s.origin, &state, &ctx->str); if (error != CSS_OK) goto cleanup; } @@ -1525,233 +1678,6 @@ css_error css_select_font_faces_results_destroy( * Selection engine internals below here * ******************************************************************************/ -css_error intern_strings(css_select_ctx *ctx) -{ - lwc_error error; - - /* Universal selector */ - error = lwc_intern_string("*", SLEN("*"), &ctx->universal); - if (error != lwc_error_ok) - return css_error_from_lwc_error(error); - - /* Pseudo classes */ - error = lwc_intern_string( - "first-child", SLEN("first-child"), - &ctx->first_child); - if (error != lwc_error_ok) - return css_error_from_lwc_error(error); - - error = lwc_intern_string( - "link", SLEN("link"), - &ctx->link); - if (error != lwc_error_ok) - return css_error_from_lwc_error(error); - - error = lwc_intern_string( - "visited", SLEN("visited"), - &ctx->visited); - if (error != lwc_error_ok) - return css_error_from_lwc_error(error); - - error = lwc_intern_string( - "hover", SLEN("hover"), - &ctx->hover); - if (error != lwc_error_ok) - return css_error_from_lwc_error(error); - - error = lwc_intern_string( - "active", SLEN("active"), - &ctx->active); - if (error != lwc_error_ok) - return css_error_from_lwc_error(error); - - error = lwc_intern_string( - "focus", SLEN("focus"), - &ctx->focus); - if (error != lwc_error_ok) - return css_error_from_lwc_error(error); - - error = lwc_intern_string( - "nth-child", SLEN("nth-child"), - &ctx->nth_child); - if (error != lwc_error_ok) - return css_error_from_lwc_error(error); - - error = lwc_intern_string( - "nth-last-child", SLEN("nth-last-child"), - &ctx->nth_last_child); - if (error != lwc_error_ok) - return css_error_from_lwc_error(error); - - error = lwc_intern_string( - "nth-of-type", SLEN("nth-of-type"), - &ctx->nth_of_type); - if (error != lwc_error_ok) - return css_error_from_lwc_error(error); - - error = lwc_intern_string( - "nth-last-of-type", SLEN("nth-last-of-type"), - &ctx->nth_last_of_type); - if (error != lwc_error_ok) - return css_error_from_lwc_error(error); - - error = lwc_intern_string( - "last-child", SLEN("last-child"), - &ctx->last_child); - if (error != lwc_error_ok) - return css_error_from_lwc_error(error); - - error = lwc_intern_string( - "first-of-type", SLEN("first-of-type"), - &ctx->first_of_type); - if (error != lwc_error_ok) - return css_error_from_lwc_error(error); - - error = lwc_intern_string( - "last-of-type", SLEN("last-of-type"), - &ctx->last_of_type); - if (error != lwc_error_ok) - return css_error_from_lwc_error(error); - - error = lwc_intern_string( - "only-child", SLEN("only-child"), - &ctx->only_child); - if (error != lwc_error_ok) - return css_error_from_lwc_error(error); - - error = lwc_intern_string( - "only-of-type", SLEN("only-of-type"), - &ctx->only_of_type); - if (error != lwc_error_ok) - return css_error_from_lwc_error(error); - - error = lwc_intern_string( - "root", SLEN("root"), - &ctx->root); - if (error != lwc_error_ok) - return css_error_from_lwc_error(error); - - error = lwc_intern_string( - "empty", SLEN("empty"), - &ctx->empty); - if (error != lwc_error_ok) - return css_error_from_lwc_error(error); - - error = lwc_intern_string( - "target", SLEN("target"), - &ctx->target); - if (error != lwc_error_ok) - return css_error_from_lwc_error(error); - - error = lwc_intern_string( - "lang", SLEN("lang"), - &ctx->lang); - if (error != lwc_error_ok) - return css_error_from_lwc_error(error); - - error = lwc_intern_string( - "enabled", SLEN("enabled"), - &ctx->enabled); - if (error != lwc_error_ok) - return css_error_from_lwc_error(error); - - error = lwc_intern_string( - "disabled", SLEN("disabled"), - &ctx->disabled); - if (error != lwc_error_ok) - return css_error_from_lwc_error(error); - - error = lwc_intern_string( - "checked", SLEN("checked"), - &ctx->checked); - if (error != lwc_error_ok) - return css_error_from_lwc_error(error); - - /* Pseudo elements */ - error = lwc_intern_string( - "first-line", SLEN("first-line"), - &ctx->first_line); - if (error != lwc_error_ok) - return css_error_from_lwc_error(error); - - error = lwc_intern_string( - "first_letter", SLEN("first-letter"), - &ctx->first_letter); - if (error != lwc_error_ok) - return css_error_from_lwc_error(error); - - error = lwc_intern_string( - "before", SLEN("before"), - &ctx->before); - if (error != lwc_error_ok) - return css_error_from_lwc_error(error); - - error = lwc_intern_string( - "after", SLEN("after"), - &ctx->after); - if (error != lwc_error_ok) - return css_error_from_lwc_error(error); - - return CSS_OK; -} - -void destroy_strings(css_select_ctx *ctx) -{ - if (ctx->universal != NULL) - lwc_string_unref(ctx->universal); - if (ctx->first_child != NULL) - lwc_string_unref(ctx->first_child); - if (ctx->link != NULL) - lwc_string_unref(ctx->link); - if (ctx->visited != NULL) - lwc_string_unref(ctx->visited); - if (ctx->hover != NULL) - lwc_string_unref(ctx->hover); - if (ctx->active != NULL) - lwc_string_unref(ctx->active); - if (ctx->focus != NULL) - lwc_string_unref(ctx->focus); - if (ctx->nth_child != NULL) - lwc_string_unref(ctx->nth_child); - if (ctx->nth_last_child != NULL) - lwc_string_unref(ctx->nth_last_child); - if (ctx->nth_of_type != NULL) - lwc_string_unref(ctx->nth_of_type); - if (ctx->nth_last_of_type != NULL) - lwc_string_unref(ctx->nth_last_of_type); - if (ctx->last_child != NULL) - lwc_string_unref(ctx->last_child); - if (ctx->first_of_type != NULL) - lwc_string_unref(ctx->first_of_type); - if (ctx->last_of_type != NULL) - lwc_string_unref(ctx->last_of_type); - if (ctx->only_child != NULL) - lwc_string_unref(ctx->only_child); - if (ctx->only_of_type != NULL) - lwc_string_unref(ctx->only_of_type); - if (ctx->root != NULL) - lwc_string_unref(ctx->root); - if (ctx->empty != NULL) - lwc_string_unref(ctx->empty); - if (ctx->target != NULL) - lwc_string_unref(ctx->target); - if (ctx->lang != NULL) - lwc_string_unref(ctx->lang); - if (ctx->enabled != NULL) - lwc_string_unref(ctx->enabled); - if (ctx->disabled != NULL) - lwc_string_unref(ctx->disabled); - if (ctx->checked != NULL) - lwc_string_unref(ctx->checked); - if (ctx->first_line != NULL) - lwc_string_unref(ctx->first_line); - if (ctx->first_letter != NULL) - lwc_string_unref(ctx->first_letter); - if (ctx->before != NULL) - lwc_string_unref(ctx->before); - if (ctx->after != NULL) - lwc_string_unref(ctx->after); -} css_error set_hint(css_select_state *state, css_hint *hint) { @@ -1769,7 +1695,8 @@ css_error set_hint(css_select_state *state, css_hint *hint) existing->specificity = 0; existing->origin = CSS_ORIGIN_AUTHOR; existing->important = 0; - existing->inherit = (hint->status == 0); + existing->explicit_default = (hint->status == 0) ? + FLAG_VALUE_INHERIT : FLAG_VALUE__NONE; return CSS_OK; } @@ -1786,35 +1713,9 @@ css_error set_initial(css_select_state *state, * If the node is tree root and we're dealing with the base element, * everything should be defaulted. */ - if (prop_dispatch[prop].inherited == false || + if (state->props[prop][pseudo].explicit_default == FLAG_VALUE_INITIAL || + prop_dispatch[prop].inherited == false || (pseudo == CSS_PSEUDO_ELEMENT_NONE && parent == NULL)) { - enum prop_group group = prop_dispatch[prop].group; - - /* Remaining properties are neither inherited nor - * already set. Thus, we set them to their initial - * values here. Except, however, if the property in - * question resides in one of the extension blocks and - * the extension block has yet to be allocated. In that - * case, we do nothing and leave it to the property - * accessors to return the initial values for the - * property. - */ - switch (group) { - case GROUP_NORMAL: - break; - case GROUP_UNCOMMON: - if (state->computed->i.uncommon == NULL) - return CSS_OK; - break; - case GROUP_PAGE: - if (state->computed->page == NULL) - return CSS_OK; - break; - case GROUP_AURAL: - if (state->computed->i.aural == NULL) - return CSS_OK; - break; - } error = prop_dispatch[prop].initial(state); if (error != CSS_OK) return error; @@ -1846,7 +1747,10 @@ css_error select_from_sheet(css_select_ctx *ctx, const css_stylesheet *sheet, (const css_rule_import *) rule; if (import->sheet != NULL && - (import->media & state->media) != 0) { + mq__list_match(import->media, + state->unit_ctx, + state->media, + &ctx->str)) { /* It's applicable, so process it */ if (sp >= IMPORT_STACK_SIZE) return CSS_NOMEM; @@ -1885,34 +1789,13 @@ css_error select_from_sheet(css_select_ctx *ctx, const css_stylesheet *sheet, return CSS_OK; } -static inline bool _rule_applies_to_media(const css_rule *rule, uint64_t media) -{ - bool applies = true; - const css_rule *ancestor = rule; - - while (ancestor != NULL) { - const css_rule_media *m = (const css_rule_media *) ancestor; - - if (ancestor->type == CSS_RULE_MEDIA && - (m->media & media) == 0) { - applies = false; - break; - } - - if (ancestor->ptype != CSS_RULE_PARENT_STYLESHEET) - ancestor = ancestor->parent; - else - ancestor = NULL; - } - - return applies; -} - static css_error _select_font_face_from_rule( const css_rule_font_face *rule, css_origin origin, - css_select_font_faces_state *state) + css_select_font_faces_state *state, + const css_select_strings *str) { - if (_rule_applies_to_media((const css_rule *) rule, state->media)) { + if (mq_rule_good_for_media((const css_rule *) rule, + state->unit_ctx, state->media, str)) { bool correct_family = false; if (lwc_string_isequal( @@ -1956,7 +1839,8 @@ static css_error _select_font_face_from_rule( static css_error select_font_faces_from_sheet( const css_stylesheet *sheet, css_origin origin, - css_select_font_faces_state *state) + css_select_font_faces_state *state, + const css_select_strings *str) { const css_stylesheet *s = sheet; const css_rule *rule = s->rule_list; @@ -1976,7 +1860,10 @@ static css_error select_font_faces_from_sheet( (const css_rule_import *) rule; if (import->sheet != NULL && - (import->media & state->media) != 0) { + mq__list_match(import->media, + state->unit_ctx, + state->media, + str)) { /* It's applicable, so process it */ if (sp >= IMPORT_STACK_SIZE) return CSS_NOMEM; @@ -1994,8 +1881,7 @@ static css_error select_font_faces_from_sheet( error = _select_font_face_from_rule( (const css_rule_font_face *) rule, - origin, - state); + origin, state, str); if (error != CSS_OK) return error; @@ -2123,8 +2009,9 @@ css_error match_selectors_in_sheet(css_select_ctx *ctx, /* Set up general selector chain requirments */ req.media = state->media; + req.unit_ctx = state->unit_ctx; req.node_bloom = state->node_data->bloom; - req.uni = ctx->universal; + req.str = &ctx->str; /* Find hash chain that applies to current node */ req.qname = state->element; @@ -2289,7 +2176,7 @@ css_error match_selector_chain(css_select_ctx *ctx, /* Consider any combinator on this selector */ if (s->data.comb != CSS_COMBINATOR_NONE && s->combinator->data.qname.name != - ctx->universal) { + ctx->str.universal) { /* Named combinator */ may_optimise &= (s->data.comb == CSS_COMBINATOR_ANCESTOR || @@ -2624,7 +2511,7 @@ css_error match_detail(css_select_ctx *ctx, void *node, return error; if (is_root == false && - detail->qname.name == ctx->first_child) { + detail->qname.name == ctx->str.first_child) { int32_t num_before = 0; error = state->handler->node_count_siblings(state->pw, @@ -2632,7 +2519,7 @@ css_error match_detail(css_select_ctx *ctx, void *node, if (error == CSS_OK) *match = (num_before == 0); } else if (is_root == false && - detail->qname.name == ctx->nth_child) { + detail->qname.name == ctx->str.nth_child) { int32_t num_before = 0; error = state->handler->node_count_siblings(state->pw, @@ -2644,7 +2531,7 @@ css_error match_detail(css_select_ctx *ctx, void *node, *match = match_nth(a, b, num_before + 1); } } else if (is_root == false && - detail->qname.name == ctx->nth_last_child) { + detail->qname.name == ctx->str.nth_last_child) { int32_t num_after = 0; error = state->handler->node_count_siblings(state->pw, @@ -2656,7 +2543,7 @@ css_error match_detail(css_select_ctx *ctx, void *node, *match = match_nth(a, b, num_after + 1); } } else if (is_root == false && - detail->qname.name == ctx->nth_of_type) { + detail->qname.name == ctx->str.nth_of_type) { int32_t num_before = 0; error = state->handler->node_count_siblings(state->pw, @@ -2668,7 +2555,7 @@ css_error match_detail(css_select_ctx *ctx, void *node, *match = match_nth(a, b, num_before + 1); } } else if (is_root == false && - detail->qname.name == ctx->nth_last_of_type) { + detail->qname.name == ctx->str.nth_last_of_type) { int32_t num_after = 0; error = state->handler->node_count_siblings(state->pw, @@ -2680,7 +2567,7 @@ css_error match_detail(css_select_ctx *ctx, void *node, *match = match_nth(a, b, num_after + 1); } } else if (is_root == false && - detail->qname.name == ctx->last_child) { + detail->qname.name == ctx->str.last_child) { int32_t num_after = 0; error = state->handler->node_count_siblings(state->pw, @@ -2688,7 +2575,7 @@ css_error match_detail(css_select_ctx *ctx, void *node, if (error == CSS_OK) *match = (num_after == 0); } else if (is_root == false && - detail->qname.name == ctx->first_of_type) { + detail->qname.name == ctx->str.first_of_type) { int32_t num_before = 0; error = state->handler->node_count_siblings(state->pw, @@ -2696,7 +2583,7 @@ css_error match_detail(css_select_ctx *ctx, void *node, if (error == CSS_OK) *match = (num_before == 0); } else if (is_root == false && - detail->qname.name == ctx->last_of_type) { + detail->qname.name == ctx->str.last_of_type) { int32_t num_after = 0; error = state->handler->node_count_siblings(state->pw, @@ -2704,7 +2591,7 @@ css_error match_detail(css_select_ctx *ctx, void *node, if (error == CSS_OK) *match = (num_after == 0); } else if (is_root == false && - detail->qname.name == ctx->only_child) { + detail->qname.name == ctx->str.only_child) { int32_t num_before = 0, num_after = 0; error = state->handler->node_count_siblings(state->pw, @@ -2718,7 +2605,7 @@ css_error match_detail(css_select_ctx *ctx, void *node, (num_after == 0); } } else if (is_root == false && - detail->qname.name == ctx->only_of_type) { + detail->qname.name == ctx->str.only_of_type) { int32_t num_before = 0, num_after = 0; error = state->handler->node_count_siblings(state->pw, @@ -2731,44 +2618,44 @@ css_error match_detail(css_select_ctx *ctx, void *node, *match = (num_before == 0) && (num_after == 0); } - } else if (detail->qname.name == ctx->root) { + } else if (detail->qname.name == ctx->str.root) { *match = is_root; - } else if (detail->qname.name == ctx->empty) { + } else if (detail->qname.name == ctx->str.empty) { error = state->handler->node_is_empty(state->pw, node, match); - } else if (detail->qname.name == ctx->link) { + } else if (detail->qname.name == ctx->str.link) { error = state->handler->node_is_link(state->pw, node, match); flags = CSS_NODE_FLAGS_NONE; - } else if (detail->qname.name == ctx->visited) { + } else if (detail->qname.name == ctx->str.visited) { error = state->handler->node_is_visited(state->pw, node, match); flags = CSS_NODE_FLAGS_NONE; - } else if (detail->qname.name == ctx->hover) { + } else if (detail->qname.name == ctx->str.hover) { error = state->handler->node_is_hover(state->pw, node, match); flags = CSS_NODE_FLAGS_NONE; - } else if (detail->qname.name == ctx->active) { + } else if (detail->qname.name == ctx->str.active) { error = state->handler->node_is_active(state->pw, node, match); flags = CSS_NODE_FLAGS_NONE; - } else if (detail->qname.name == ctx->focus) { + } else if (detail->qname.name == ctx->str.focus) { error = state->handler->node_is_focus(state->pw, node, match); flags = CSS_NODE_FLAGS_NONE; - } else if (detail->qname.name == ctx->target) { + } else if (detail->qname.name == ctx->str.target) { error = state->handler->node_is_target(state->pw, node, match); - } else if (detail->qname.name == ctx->lang) { + } else if (detail->qname.name == ctx->str.lang) { error = state->handler->node_is_lang(state->pw, node, detail->value.string, match); - } else if (detail->qname.name == ctx->enabled) { + } else if (detail->qname.name == ctx->str.enabled) { error = state->handler->node_is_enabled(state->pw, node, match); - } else if (detail->qname.name == ctx->disabled) { + } else if (detail->qname.name == ctx->str.disabled) { error = state->handler->node_is_disabled(state->pw, node, match); - } else if (detail->qname.name == ctx->checked) { + } else if (detail->qname.name == ctx->str.checked) { error = state->handler->node_is_checked(state->pw, node, match); } else { @@ -2779,13 +2666,13 @@ css_error match_detail(css_select_ctx *ctx, void *node, case CSS_SELECTOR_PSEUDO_ELEMENT: *match = true; - if (detail->qname.name == ctx->first_line) { + if (detail->qname.name == ctx->str.first_line) { *pseudo_element = CSS_PSEUDO_ELEMENT_FIRST_LINE; - } else if (detail->qname.name == ctx->first_letter) { + } else if (detail->qname.name == ctx->str.first_letter) { *pseudo_element = CSS_PSEUDO_ELEMENT_FIRST_LETTER; - } else if (detail->qname.name == ctx->before) { + } else if (detail->qname.name == ctx->str.before) { *pseudo_element = CSS_PSEUDO_ELEMENT_BEFORE; - } else if (detail->qname.name == ctx->after) { + } else if (detail->qname.name == ctx->str.after) { *pseudo_element = CSS_PSEUDO_ELEMENT_AFTER; } else *match = false; @@ -2862,7 +2749,7 @@ css_error cascade_style(const css_style *style, css_select_state *state) } bool css__outranks_existing(uint16_t op, bool important, css_select_state *state, - bool inherit) + enum flag_value explicit_default) { prop_state *existing = &state->props[op][state->current_pseudo]; bool outranks = false; @@ -2957,7 +2844,7 @@ bool css__outranks_existing(uint16_t op, bool important, css_select_state *state existing->specificity = state->current_specificity; existing->origin = state->current_origin; existing->important = important; - existing->inherit = inherit; + existing->explicit_default = explicit_default; } return outranks; diff --git a/src/select/select.h b/src/select/select.h index 70f1ced..5170e58 100644 --- a/src/select/select.h +++ b/src/select/select.h @@ -24,11 +24,11 @@ typedef struct reject_item { } reject_item; typedef struct prop_state { - uint32_t specificity; /* Specificity of property in result */ - unsigned int set : 1, /* Whether property is set in result */ - origin : 2, /* Origin of property in result */ - important : 1, /* Importance of property in result */ - inherit : 1; /* Property is set to inherit */ + uint32_t specificity; /* Specificity of property in result */ + unsigned int set : 1, /* Whether property is set in result */ + origin : 2, /* Origin of property in result */ + important : 1; /* Importance of property in result */ + enum flag_value explicit_default : 3; /* Property is set to inherit */ } prop_state; @@ -58,14 +58,23 @@ struct css_node_data { css_node_flags flags; }; +struct revert_data { + prop_state props[CSS_N_PROPERTIES][CSS_PSEUDO_ELEMENT_COUNT]; + css_computed_style *style[CSS_PSEUDO_ELEMENT_COUNT]; +}; + /** * Selection state */ typedef struct css_select_state { void *node; /* Node we're selecting for */ - uint64_t media; /* Currently active media types */ + const css_media *media; /* Currently active media spec */ + const css_unit_ctx *unit_ctx; /* Unit conversion context. */ css_select_results *results; /* Result set to populate */ + /** UA and user styles for handling revert property value. */ + struct revert_data *revert; /* Length: CSS_ORIGIN_AUTHOR */ + css_pseudo_element current_pseudo; /* Current pseudo element */ css_computed_style *computed; /* Computed style to populate */ @@ -97,7 +106,7 @@ static inline void advance_bytecode(css_style *style, uint32_t n_bytes) } bool css__outranks_existing(uint16_t op, bool important, - css_select_state *state, bool inherit); + css_select_state *state, enum flag_value explicit_default); #endif diff --git a/src/select/select_config.py b/src/select/select_config.py new file mode 100644 index 0000000..1cfe05c --- /dev/null +++ b/src/select/select_config.py @@ -0,0 +1,170 @@ +# This file is part of LibCSS. +# Licensed under the MIT License, +# http://www.opensource.org/licenses/mit-license.php +# Copyright 2017 Lucas Neves <lcneves@gmail.com> + +# Configuration of CSS values. +# The tuples in this set will be unpacked as arguments to the CSSValue +# class. +# Args: see docstring for class CSSValue in select_generator.py. +values = { + ('length', 'css_fixed', 4, '0', + 'unit', 'css_unit', 5, 'CSS_UNIT_PX'), + ('integer', 'int32_t', 4, '0'), + ('fixed', 'css_fixed', 4, '0'), + ('color', 'css_color', 4, '0'), + ('string', 'lwc_string*'), + ('string_arr', 'lwc_string**'), + ('counter_arr', 'css_computed_counter*'), + ('content_item', 'css_computed_content_item*') +} + +# Configuration of property groups. +# The tuples in these sets will be unpacked as arguments to the +# CSSproperty class. +# Args: see docstring for class CSSProperty in select_generator.py. +style = { + # Style group, only opcode + ('align_content', 3), + ('align_items', 3), + ('align_self', 3), + ('background_attachment', 2), + ('background_repeat', 3), + ('border_collapse', 2), + ('border_top_style', 4), + ('border_right_style', 4), + ('border_bottom_style', 4), + ('border_left_style', 4), + ('box_sizing', 2), + ('caption_side', 2), + ('clear', 3), + ('direction', 2), + ('display', 5), + ('empty_cells', 2), + ('flex_direction', 3), + ('flex_wrap', 2), + ('float', 2), + ('font_style', 2), + ('font_variant', 2), + ('font_weight', 4), + ('justify_content', 3), + ('list_style_position', 2), + ('list_style_type', 6), + ('overflow_x', 3), + ('overflow_y', 3), + ('outline_style', 4), + ('position', 3), + ('table_layout', 2), + ('text_align', 4), + ('text_decoration', 5), + ('text_transform', 3), + ('unicode_bidi', 2), + ('visibility', 2), + ('white_space', 3), + # Style group, with additional value + ('background_color', 2, 'color'), + ('background_image', 1, 'string'), + ('background_position', 1, (('length',), ('length',)), + 'CSS_BACKGROUND_POSITION_SET'), + ('border_top_color', 2, 'color'), + ('border_right_color', 2, 'color'), + ('border_bottom_color', 2, 'color'), + ('border_left_color', 2, 'color'), + ('border_top_width', 3, 'length', 'CSS_BORDER_WIDTH_WIDTH'), + ('border_right_width', 3, 'length', 'CSS_BORDER_WIDTH_WIDTH'), + ('border_bottom_width', 3, 'length', 'CSS_BORDER_WIDTH_WIDTH'), + ('border_left_width', 3, 'length', 'CSS_BORDER_WIDTH_WIDTH'), + ('top', 2, 'length', 'CSS_TOP_SET', None, None, 'get'), + ('right', 2, 'length', 'CSS_RIGHT_SET', None, None, 'get'), + ('bottom', 2, 'length', 'CSS_BOTTOM_SET', None, None, 'get'), + ('left', 2, 'length', 'CSS_LEFT_SET', None, None, 'get'), + ('color', 1, 'color'), + ('flex_basis', 2, 'length', 'CSS_FLEX_BASIS_SET'), + ('flex_grow', 1, 'fixed', 'CSS_FLEX_GROW_SET'), + ('flex_shrink', 1, 'fixed', 'CSS_FLEX_SHRINK_SET'), + ('font_size', 4, 'length', 'CSS_FONT_SIZE_DIMENSION'), + ('height', 2, 'length', 'CSS_HEIGHT_SET'), + ('line_height', 2, 'length', None, None, None, 'get'), + ('list_style_image', 1, 'string'), + ('margin_top', 2, 'length', 'CSS_MARGIN_SET'), + ('margin_right', 2, 'length', 'CSS_MARGIN_SET'), + ('margin_bottom', 2, 'length', 'CSS_MARGIN_SET'), + ('margin_left', 2, 'length', 'CSS_MARGIN_SET'), + ('max_height', 2, 'length', 'CSS_MAX_HEIGHT_SET'), + ('max_width', 2, 'length', 'CSS_MAX_WIDTH_SET'), + ('min_height', 2, 'length', 'CSS_MIN_HEIGHT_SET'), + ('min_width', 2, 'length', 'CSS_MIN_WIDTH_SET'), + ('opacity', 1, 'fixed', 'CSS_OPACITY_SET'), + ('fill_opacity', 1, 'fixed', 'CSS_FILL_OPACITY_SET'), + ('stroke_opacity', 1, 'fixed', 'CSS_STROKE_OPACITY_SET'), + ('order', 1, 'integer', 'CSS_ORDER_SET'), + ('padding_top', 1, 'length', 'CSS_PADDING_SET'), + ('padding_right', 1, 'length', 'CSS_PADDING_SET'), + ('padding_left', 1, 'length', 'CSS_PADDING_SET'), + ('padding_bottom', 1, 'length', 'CSS_PADDING_SET'), + ('text_indent', 1, 'length', 'CSS_TEXT_INDENT_SET'), + ('vertical_align', 4, 'length', 'CSS_VERTICAL_ALIGN_SET'), + ('width', 2, 'length', 'CSS_WIDTH_SET'), + ('z_index', 2, 'integer'), + # Style group, arrays + ('font_family', 3, 'string_arr', None, None, + 'Encode font family as an array of string objects, terminated with a ' + 'blank entry.'), + ('quotes', 1, 'string_arr', None, None, + 'Encode quotes as an array of string objects, terminated with a ' + 'blank entry.'), + # Page group + ('page_break_after', 3, None, None, 'CSS_PAGE_BREAK_AFTER_AUTO'), + ('page_break_before', 3, None, None, 'CSS_PAGE_BREAK_BEFORE_AUTO'), + ('page_break_inside', 2, None, None, 'CSS_PAGE_BREAK_INSIDE_AUTO'), + ('widows', 1, (('integer', '2'),), None, + 'CSS_WIDOWS_SET'), + ('orphans', 1, (('integer', '2'),), None, + 'CSS_ORPHANS_SET'), + # Uncommon group + ('border_spacing', 1, (('length',), ('length',)), 'CSS_BORDER_SPACING_SET', + 'CSS_BORDER_SPACING_SET'), + ('break_after', 4, None, None, 'CSS_BREAK_AFTER_AUTO'), + ('break_before', 4, None, None, 'CSS_BREAK_BEFORE_AUTO'), + ('break_inside', 4, None, None, 'CSS_BREAK_INSIDE_AUTO'), + ('clip', 6, (('length',), ('length',), ('length',), ('length',)), + 'CSS_CLIP_RECT', 'CSS_CLIP_AUTO', None, ('get', 'set')), + ('column_count', 2, 'integer', None, 'CSS_COLUMN_COUNT_AUTO'), + ('column_fill', 2, None, None, 'CSS_COLUMN_FILL_BALANCE'), + ('column_gap', 2, 'length', + 'CSS_COLUMN_GAP_SET', 'CSS_COLUMN_GAP_NORMAL'), + ('column_rule_color', 2, 'color', None, + 'CSS_COLUMN_RULE_COLOR_CURRENT_COLOR'), + ('column_rule_style', 4, None, None, 'CSS_COLUMN_RULE_STYLE_NONE'), + ('column_rule_width', 3, 'length', + 'CSS_COLUMN_RULE_WIDTH_WIDTH', 'CSS_COLUMN_RULE_WIDTH_MEDIUM'), + ('column_span', 2, None, None, 'CSS_COLUMN_SPAN_NONE'), + ('column_width', 2, 'length', + 'CSS_COLUMN_WIDTH_SET', 'CSS_COLUMN_WIDTH_AUTO'), + ('letter_spacing', 2, 'length', + 'CSS_LETTER_SPACING_SET', 'CSS_LETTER_SPACING_NORMAL'), + ('outline_color', 2, 'color', + 'CSS_OUTLINE_COLOR_COLOR', 'CSS_OUTLINE_COLOR_INVERT'), + ('outline_width', 3, 'length', + 'CSS_OUTLINE_WIDTH_WIDTH', 'CSS_OUTLINE_WIDTH_MEDIUM'), + ('word_spacing', 2, 'length', + 'CSS_WORD_SPACING_SET', 'CSS_WORD_SPACING_NORMAL'), + ('writing_mode', 2, None, None, 'CSS_WRITING_MODE_HORIZONTAL_TB'), + # Uncommon group, arrays + ('counter_increment', 1, 'counter_arr', None, 'CSS_COUNTER_INCREMENT_NONE', + 'Encode counter_increment as an array of name, value pairs, ' + 'terminated with a blank entry.'), + ('counter_reset', 1, 'counter_arr', None, 'CSS_COUNTER_RESET_NONE', + 'Encode counter_reset as an array of name, value pairs, ' + 'terminated with a blank entry.'), + ('cursor', 5, 'string_arr', None, 'CSS_CURSOR_AUTO', + 'Encode cursor uri(s) as an array of string objects, terminated ' + 'with a blank entry'), + ('content', 2, 'content_item', 'CSS_CONTENT_SET', 'CSS_CONTENT_NORMAL', + 'Encode content as an array of content items, terminated with ' + 'a blank entry.', 'set') +} + +groups = [ + { 'name': 'style', 'props': style } +] diff --git a/src/select/select_generator.py b/src/select/select_generator.py new file mode 100644 index 0000000..9e92909 --- /dev/null +++ b/src/select/select_generator.py @@ -0,0 +1,717 @@ +# This file is part of LibCSS. +# Licensed under the MIT License, +# http://www.opensource.org/licenses/mit-license.php +# Copyright 2017 Lucas Neves <lcneves@gmail.com> + +import math +import string +import os +from select_config import values, groups +from assets import assets +from overrides import overrides + +def get_tuple(from_var): + """Convert tuples, strings and None into tuple.""" + if type(from_var) is tuple: + return from_var + elif type(from_var) is str: + return (from_var,) + elif from_var is None: + return () + else: + raise TypeError('Value should be either tuple, string or None, ' + + 'received: ' + type(from_var).__name__) + +def shift_star(value_type, prop_name): + """Shift the asterisks from a pointer type to its name. + + Example: `lwc_string** str_array` would become + `lwc_string **str_array` + """ + star_i = value_type.find('*') + v_type = value_type if star_i == -1 else value_type[:star_i] + v_name = prop_name if star_i == -1 else value_type[star_i:] + prop_name + return (v_type, v_name) + +class Text: + """Class for building strings for output files.""" + def __init__(self): + self._lines = [] + self._comment = False + self._esc_nl = False + self._indent = 0 + + name_width = 31 + bits_width = 16 + + def indent(self, value): + """Increase or decrease indent by <value>. + + Args: + value <int>: positive or negative value to be added to + indentation. + """ + self._indent += value + + def comment(self): + """Toggle C-style comment in the output text.""" + comm = self._comment + self._comment = False + self.append(' */' if comm else '/*') + self._comment = not comm + + def escape_newline(self): + """Toggle escape of newline character.""" + self._esc_nl = not self._esc_nl + + def append(self, text=None, pre_formatted=False): + """Append text to file builder. + + Args: + text: + <str> add contents, breaking lines and adding comment + markers or newline escapes as needed. + <list> recursively call this method for list items. + <falsey value> add a new line. + pre_formatted: just add text without preprocessing. + """ + if not text: + self._lines.append('{}{}{}'.format( + '\t' * self._indent, + ' * ' if self._comment else '', + '\t' * (9 - self._indent) + '\\' if self._esc_nl else '')) + return + + if isinstance(text, list): + for t in text: + self.append(t, pre_formatted) + return + + if pre_formatted: + self._lines.append(text) + return + + line_break_before = [ c for c in ' +/' ] + line_break_after = [ c for c in '({[' ] + column_max = 72 if self._esc_nl else 80 + multiline = False + + while text: + line = '\t' * self._indent + if self._comment: + line += ' * ' + prefix_size = (3 if self._comment else 0) + 8 * self._indent + if prefix_size + len(text) <= column_max: + line += text + text = '' + else: + break_index = 0 + for c in (line_break_before + line_break_after): + after = 1 if c in line_break_after else 0 + break_index = max(break_index, + text[:column_max - prefix_size].rfind(c) + after) + break_index = break_index or len(text) + line += text[:break_index].rstrip() + text = text[break_index:].lstrip() + if self._esc_nl: + n_tabs = 9 - self._indent - math.floor(len(line.lstrip()) / 8) + line += '\t' * n_tabs + '\\' + self._lines.append(line) + if text and not self._comment and not multiline: + self.indent(2) + multiline = True + + if multiline: + self.indent(-2) + + def table_line(self): + """Add a sum line for the tables in computed.h""" + self.append('{0:{n}}{0:{b}}{0}'.format( + '---', n=self.name_width, b=self.bits_width)) + + def table_header(self): + """Add a header line for the tables in computed.h""" + self.append('{:{n}}{:{b}}{}'.format( + 'Property', 'Size (bits)', 'Size (bytes)', + n=self.name_width, b=self.bits_width)) + self.table_line() + + def result_line(self): + """Add a result line for the tables in computed.h""" + self.append(' ' * self.name_width + '=' * (self.bits_width + 3)) + + def to_string(self): + """Output contents of file builder as a string.""" + return '\n'.join(self._lines) + +class CSSValue: + """Values to be associated with properties. + + Args: + name <str>: value name (required). + css_type <str>: C type of value (required). + size <int>: value size, in bytes (default: None, for pointers). + defaults <str>: default value (default: 'NULL', for pointers). + The fields below are only needed if the value stores data in the + array of bits (currently only css_unit uses it). + bits_name <str>: name of bits value (default: None). + bits_type <str>: C type of bits value (default: None). + bits_size <int>: value size, in bits (default: None). + bits_defaults <str>: default value (default: '0'). + """ + def __init__(self, name, css_type, size=None, defaults='NULL', + bits_name=None, bits_type=None, + bits_size=None, bits_defaults='0'): + self.name = name + self.type = css_type + self.size = size # `None` means sizeof(ptr) + self.defaults = defaults + self.suffix = '' + self.bits = None if bits_size is None else { + 'name': bits_name, + 'type': bits_type, + 'size': bits_size, + 'defaults': bits_defaults + } + + @property + def is_ptr(self): + """Return True if value is a pointer; False otherwise.""" + return ((self.type, self.name) != shift_star(self.type, self.name)) + +class CSSProperty: + """Class for CSS properties. + + Args: + name <str>: property name (required). + type_size <int>: opcode size, in bits (required). + values <tuple or str>: property values (default: None). + To set one value, using the value's defaults: + 'value_name' + To set multiple values, using the values' defaults: + (('value_name',), ('value_name',)) + To override the default of one or multiple values: + (('value_name', 'default'),) + (('value_name', 'default'), ('value_name', 'default')) + condition <str>: condition (opcode value) to get property + values in propget.h (default: None). + defaults <str>: default opcode (default: None) + comments <str>: comments for properties that are stored in + "struct css_computed_{group}", instead of + "struct css_computed_{group}_i (default: None) + NOTE: passing this argument will result in the property being + stored in "struct css_computed_{group}"! + overrides <tuple | str>: files for which this property shouldn't + autogenerate content; instead, read entry from from overrides.py + Possible values: + 'get': overrides output to autogenerated_propget.h + 'set': overrides output to autogenerated_propset.h + ('get', 'set'): overrides output to both files. + """ + def __init__(self, name, type_size, values=None, condition=None, + defaults=None, comments=None, override=None): + self.name = name + self.type_size = type_size + self.values = self.make_values(values) + self.defaults = defaults + self.condition = condition + self.override = get_tuple(override) + self.comments = comments + self.__mask = None + self.index = None + self.shift = None + + def make_values(self, vals): + """Make list of values for this property.""" + if vals is None: + return [] + elif type(vals) is str: + return self.make_values(((vals,),)) + elif type(vals) is tuple: + val_list = [] + for i, v in enumerate(vals): + for x in values: + if x[0] == v[0]: + value = CSSValue(*x) + if len(v) == 2: + value.defaults = v[1] + if len(vals) > 1: + value.suffix = '_' + string.ascii_lowercase[i] + val_list.append(value) + break + else: + raise ValueError('Value ' + v[0] + ' not found!') + return val_list + else: + raise TypeError('Expected None, str or tuple, got ' + + type(vals).__name__) + + @property + def bits_size(self): + """Size of this property in the bits array.""" + return self.type_size + sum([ v.bits['size'] for v in self.values + if v.bits is not None ]) + + @property + def bytes_size(self): + """Size of this property's values, in bytes (excluding pointers).""" + return sum([ v.size for v in self.values if v.size is not None ]) + + @property + def ptr_size(self): + """Number of values of this property that are pointers.""" + return sum([ 1 for v in self.values if v.size is None ]) + + @property + def size_line(self): + """String for computed.h with the sizes of this property.""" + name = '{:{width}}'.format(self.name, width=Text.name_width) + type_size = '{:>3}'.format(str(self.type_size)) + extra_size = sum([ v.bits['size'] for v in self.values + if v.bits is not None ]) + bits_size = '{:{width}}'.format(type_size + + (' + ' + str(extra_size) if extra_size else ''), + width=Text.bits_width) + vars_size = '{:>3}'.format( + str(self.bytes_size)) if self.bytes_size else '' + ptr = '' + for v in self.values: + if v.size is None: + ptr = 'sizeof(ptr)' + break + + return (name + bits_size + vars_size + + (' + ' if vars_size and ptr else '') + ptr) + + @property + def mask(self): + """Getter for the bitwise mask of this property in the bits array.""" + if self.__mask is None: + raise NameError('Attribute `mask` not set yet!') + return '0x{:x}'.format(self.__mask).lower() + + @mask.setter + def mask(self, val): + """Setter for the bitwise mask of this property in the bits array.""" + if type(val) is not int: + raise TypeError('Value of `mask` must be an integer!') + if val < 0: + raise ValueError('Value of `mask` must be zero or positive!') + self.__mask = val + + @property + def def_undefs(self): + """Return defines and undefs for propget.h and propset.h.""" + defines = [ + '#define {}_INDEX {}'.format(self.name.upper(), self.index), + '#define {}_SHIFT {}'.format(self.name.upper(), self.shift), + '#define {}_MASK {}'.format(self.name.upper(), self.mask) + ] + undefs = [ + '#undef {}_INDEX'.format(self.name.upper()), + '#undef {}_SHIFT'.format(self.name.upper()), + '#undef {}_MASK'.format(self.name.upper()) + ] + return (defines, undefs) + + def get_param_values(self, pointer=False): + """Make parameters for functions in propget.h and propset.h. + + Args: + pointer <bool>: add a star before value name. + """ + vals = [] + for v in self.values: + star = '*' if pointer else '' + vt, vn = shift_star(v.type, v.name) + vn = star + vn + v.suffix + if pointer: + if v.name == 'counter_arr' or v.name == 'content_item': + vt = 'const ' + vt + vals.append((vt, vn)) + if v.bits is not None: + bt = v.bits['type'] + bn = star + v.bits['name'] + v.suffix + vals.append((bt, bn)) + return vals + + def get_bits(self): + """Make vars for the bitwise operations in propget.h and propset.h.""" + bits = [ + { 'letter': v.suffix[1] if v.suffix else v.bits['name'][0], + 'name': v.bits['name'] + v.suffix, + 'size': v.bits['size'] } + for v in self.values if v.bits is not None ] + bits.append({ 'letter': 't', 'size': self.type_size, 'name': 'type' }) + bits_len = sum([ x['size'] for x in bits ]) + comment = '/* {}bit{}: {} : {} */'.format( + bits_len, + ('' if bits_len == 1 else 's'), + ''.join([ b['letter'] * b['size'] for b in bits ]), + ' | '.join([ b['name'] for b in bits ])) + rev_bits = list(reversed(bits)) + type_mask = '0x{:x}'.format( + sum([ 2 ** x for x in range(rev_bits[0]['size']) ])).lower() + shift_list = [ (x['name'], + sum([ b['size'] for b in rev_bits[:(i + 1)] ]), + sum([ 2 ** x for x in range(x['size']) ]) * 2 ** + sum([ b['size'] for b in rev_bits[:(i + 1)] ])) + for i, x in enumerate(rev_bits[1:]) ] + return (type_mask, shift_list, comment) + +class Bin: + """The storage unit for the bits array of properties.""" + def __init__(self, first_object): + self.contents = [ first_object ] + + @property + def size(self): + return sum([ x.bits_size for x in self.contents ]) + + def push(self, obj): + self.contents.append(obj) + +class CSSGroup: + """Group of CSS properties (i.e. style, page, uncommon). + + Args: + config <tuple>: imported from select_config.py. + """ + def __init__(self, config): + self.name = config['name'] + self.props = [ CSSProperty(*x) for x in config['props'] ] + self.bits_array = self.make_bits_array() + + @property + def bits_size(self): + """Sum of all property bits in the bits array.""" + return sum([ p.bits_size for p in self.props ]) + + @property + def bytes_size(self): + """Sum of all property value bytes (excluded pointers).""" + return sum([ p.bytes_size for p in self.props ]) + + @property + def ptr_size(self): + """Sum of all property pointers.""" + return sum([ p.ptr_size for p in self.props ]) + + def make_bits_array(self): + """Implement a `best fit first` heuristics for the bin packing + of property bits in the bits array. + Also generate index, shift and mask for each property in group.""" + + bin_size = 32 # We're using uint32_t as concrete bins. + bits_array = [] + props = sorted(self.props, key=(lambda x: (x.bits_size, x.name)), reverse=True) + + for p in props: + for b in bits_array: + if b.size + p.bits_size <= bin_size: + b.push(p) + p.shift = (bin_size - + sum([ x.bits_size for x in b.contents ])) + break + else: + p.shift = bin_size - p.bits_size + bits_array.append(Bin(p)) + + p.mask = (sum([ 2 ** x for x in range(p.bits_size) ]) * + 2 ** p.shift) + bits_array.sort(key=(lambda x: x.size), reverse=True) + + for i, b in enumerate(bits_array): + for p in b.contents: + p.index = i + + return bits_array + + def make_computed_h(self): + """Output this group's text for the computed.h file.""" + t = Text() + t.append() + + t.append('struct css_computed_style_i {') + + t.comment() + commented = [] + t.table_header() + + for prop in sorted(self.props, key=(lambda x: x.name)): + if prop.comments is None: + t.append(prop.size_line) + else: + commented.extend(( '', prop.comments, '', prop.size_line )) + + t.append(commented) + t.append() + t.table_line() + t.append('{:{len_1}}{:>3}{:{len_2}}{:>3}{}{}'.format('', + str(self.bits_size), ' bits', str(self.bytes_size), + ' + ' + str(self.ptr_size) + 'sizeof(ptr)' + if self.ptr_size else '', + ' bytes', + len_1=Text.name_width, len_2=(Text.bits_width - 3))) + t.result_line() + t.append('{:{len_1}}{:>3}{}{}'.format('', + math.ceil(self.bits_size / 8) + self.bytes_size, + ' + ' + str(self.ptr_size) + 'sizeof(ptr)' + if self.ptr_size else '', + ' bytes', len_1=Text.name_width)) + t.append() + + t.append('Bit allocations:') + for i, b in enumerate(self.bits_array): + bits = [] + for prop in b.contents: + for char in prop.name + prop.name.upper(): + if char not in bits and char in string.ascii_letters: + bits.extend(char * prop.bits_size) + break + t.append() + t.append('{:<2} {:.<32}'.format(str(i), ''.join(bits))) + t.append('; '.join([ p.name for p in b.contents ])) + t.comment() + + t.indent(1) + t.append('uint32_t bits[' + str(len(self.bits_array)) + '];') + t.append() + t.append(self.make_value_declaration(for_commented=False)) + + t.indent(-1) + t.append('};') + + t.append() + t.append('struct css_computed_style {') + t.indent(1) + t.append('struct css_computed_style_i i;') + t.append() + t.append(self.make_value_declaration(for_commented=True)) + t.append() + + t.append('struct css_computed_style *next;') + t.append('uint32_t count;') + t.append('uint32_t bin;') + t.indent(-1) + t.append('};') + + return t.to_string() + + def make_propset_h(self): + """Output this group's property functions for the propset.h file.""" + t = Text() + + for p in sorted(self.props, key=(lambda x: x.name)): + defines, undefs = p.def_undefs + + t.append() + t.append(defines) + + if p.name in overrides['set']: + t.append(overrides['set'][p.name], pre_formatted=True) + t.append(undefs) + continue + + vals = p.get_param_values() + params = ', '.join([ 'css_computed_style *style', 'uint8_t type' ] + + [ ' '.join(x) for x in vals ]) + t.append() + t.append('static inline css_error set_{}({})'.format( + p.name, params)) + t.append('{') + t.indent(1) + + t.append('uint32_t *bits = &style->i.bits[{}_INDEX];'.format(p.name.upper())) + t.append() + + type_mask, shift_list, bits_comment = p.get_bits() + t.append(bits_comment) + type_mask = '((uint32_t)type & {})'.format(type_mask) + val_list = [ '({} << {})'.format(x[0], x[1]) for x in shift_list ] + ops_str = ' | '.join([ type_mask ] + val_list) + t.append('*bits = (*bits & ~{0}_MASK) | ' + '({1}{2}{3} << {0}_SHIFT);'.format( + p.name.upper(), + '(' if val_list else '', + ops_str, + ')' if val_list else '')) + + t.append() + for v in p.values: + old_n = 'old_' + v.name + v.suffix + old_t, old_n_shift = shift_star(v.type, old_n) + + if v.name == 'string': + t.append('{} {} = style->i.{};'.format( + old_t, old_n_shift, p.name + v.suffix)) + t.append() + t.append('if ({} != NULL) {{'.format(v.name + v.suffix)) + t.indent(1) + t.append('style->i.{} = lwc_string_ref({});'.format( + p.name + v.suffix, v.name + v.suffix)) + t.indent(-1) + t.append('} else {') + t.indent(1) + t.append('style->i.{} = NULL;'.format(p.name + v.suffix)) + t.indent(-1) + t.append('}') + t.append() + t.append('if ({} != NULL)'.format(old_n)) + t.indent(1) + t.append('lwc_string_unref({});'.format(old_n)) + t.indent(-1) + + elif v.name == 'string_arr' or v.name == 'counter_arr': + iter_var = 's' if v.name == 'string_arr' else 'c' + iter_deref = '*s' if v.name == 'string_arr' else 'c->name' + t.append('{} {} = style->{};'.format( + old_t, old_n_shift, + p.name + v.suffix)) + t.append('{} {};'.format(old_t, + shift_star(v.type, iter_var)[1])) + t.append() + t.append('for ({0} = {2}; {0} != NULL && ' + '{1} != NULL; {0}++)'.format(iter_var, iter_deref, + v.name + v.suffix)) + t.indent(1) + t.append('{0} = lwc_string_ref({0});'.format(iter_deref)) + t.indent(-1) + t.append() + t.append('style->{} = {};'.format( + p.name + v.suffix, v.name + v.suffix)) + t.append() + t.append('/* Free existing array */') + t.append('if ({} != NULL) {{'.format(old_n)) + t.indent(1) + t.append('for ({0} = {2}; {1} != NULL; {0}++)'.format( + iter_var, iter_deref, old_n)) + t.indent(1) + t.append('lwc_string_unref({});'.format(iter_deref)) + t.indent(-1) + t.append() + t.append('if ({} != {})'.format(old_n, v.name + v.suffix)) + t.indent(1) + t.append('free({});'.format(old_n)) + t.indent(-2) + t.append('}') + + elif not v.is_ptr: + t.append('style->i.{} = {};'.format( + p.name + v.suffix, v.name + v.suffix)) + + else: + raise ValueError('Cannot handle value ' + v.name +'!') + + t.append() + t.append('return CSS_OK;') + t.indent(-1) + t.append('}') + t.append(undefs) + + return t.to_string() + + def print_propget(self, t, p, only_bits=False): + vals = [] if only_bits else p.get_param_values(pointer=True) + params = ', '.join([ 'css_computed_style *style' ] + + [ ' '.join(x) for x in vals ]) + + underscore_bits = '_bits' if only_bits else '' + t.append('static inline uint8_t get_{}{}(const {})'.format( + p.name, underscore_bits, params)) + t.append('{') + t.indent(1) + + t.append('uint32_t bits = style->i.bits[{}_INDEX];'.format( + p.name.upper())) + t.append('bits &= {}_MASK;'.format(p.name.upper())) + t.append('bits >>= {}_SHIFT;'.format(p.name.upper())) + t.append() + + type_mask, shift_list, bits_comment = p.get_bits() + t.append(bits_comment) + + if only_bits == False: + if p.condition: + t.append('if ((bits & {}) == {}) {{'.format( + type_mask, p.condition)) + t.indent(1) + + for v in p.values: + i_dot = '' if v.is_ptr and v.name != 'string' else 'i.' + t.append('*{} = style->{}{};'.format( + v.name + v.suffix, i_dot, p.name + v.suffix)) + for i, v in enumerate(list(reversed(shift_list))): + if i == 0: + t.append('*{} = bits >> {};'.format(v[0], v[1])) + else: + t.append('*{} = (bits & 0x{:x}) >> {};'.format( + v[0], v[2], v[1]).lower()) + + if p.condition: + t.indent(-1) + t.append('}') + t.append() + + t.append('return (bits & {});'.format(type_mask)) + + t.indent(-1) + t.append('}') + + def make_propget_h(self): + """Output this group's property functions for the propget.h file.""" + t = Text() + + for p in sorted(self.props, key=(lambda x: x.name)): + defines, undefs = p.def_undefs + + t.append() + t.append(defines) + + self.print_propget(t, p, True) + + if p.name in overrides['get']: + t.append(overrides['get'][p.name], pre_formatted=True) + else: + self.print_propget(t, p) + + t.append(undefs) + + return t.to_string() + + def make_value_declaration(self, for_commented): + """Output declarations of values for this group's properties. + + Args: + for_commented: only parse values that have a `comment` field + defaults: outputs default value assignments. + """ + + r = [] + for p in sorted(self.props, key=(lambda x: x.name)): + if bool(p.comments) == for_commented: + for v in p.values: + v_type, v_name = shift_star(v.type, p.name) + r.append('{} {}{};'.format(v_type, v_name, v.suffix)) + return r + + def make_text(self, filename): + """Return this group's text for the given file.""" + if filename == 'computed.h': + return self.make_computed_h() + elif filename == 'propset.h': + return self.make_propset_h() + elif filename == 'propget.h': + return self.make_propget_h() + else: + raise ValueError() + +css_groups = [ CSSGroup(g) for g in groups ] +dir_path = os.path.dirname(os.path.realpath(__file__)) + +for k, v in assets.items(): + # Key is filename string (e.g. "computed.h") without autogenerated_ prefix + body = '\n'.join([ g.make_text(k) for g in css_groups ]) + text = '\n'.join([ v['header'], body, v['footer'] ]) + with open(os.path.join(dir_path, 'autogenerated_') + k, 'w') as file_k: + file_k.write(text) diff --git a/src/select/strings.c b/src/select/strings.c new file mode 100644 index 0000000..6e9137d --- /dev/null +++ b/src/select/strings.c @@ -0,0 +1,264 @@ +/* + * This file is part of LibCSS + * Licensed under the MIT License, + * http://www.opensource.org/licenses/mit-license.php + * Copyright 2009 John-Mark Bell <jmb@netsurf-browser.org> + */ + +#include <libwapcaplet/libwapcaplet.h> + +#include "select/strings.h" +#include "utils/utils.h" + +css_error css_select_strings_intern(css_select_strings *str) +{ + lwc_error error; + + /* Universal selector */ + error = lwc_intern_string("*", SLEN("*"), &str->universal); + if (error != lwc_error_ok) + return css_error_from_lwc_error(error); + + /* Pseudo classes */ + error = lwc_intern_string( + "first-child", SLEN("first-child"), + &str->first_child); + if (error != lwc_error_ok) + return css_error_from_lwc_error(error); + + error = lwc_intern_string( + "link", SLEN("link"), + &str->link); + if (error != lwc_error_ok) + return css_error_from_lwc_error(error); + + error = lwc_intern_string( + "visited", SLEN("visited"), + &str->visited); + if (error != lwc_error_ok) + return css_error_from_lwc_error(error); + + error = lwc_intern_string( + "hover", SLEN("hover"), + &str->hover); + if (error != lwc_error_ok) + return css_error_from_lwc_error(error); + + error = lwc_intern_string( + "active", SLEN("active"), + &str->active); + if (error != lwc_error_ok) + return css_error_from_lwc_error(error); + + error = lwc_intern_string( + "focus", SLEN("focus"), + &str->focus); + if (error != lwc_error_ok) + return css_error_from_lwc_error(error); + + error = lwc_intern_string( + "nth-child", SLEN("nth-child"), + &str->nth_child); + if (error != lwc_error_ok) + return css_error_from_lwc_error(error); + + error = lwc_intern_string( + "nth-last-child", SLEN("nth-last-child"), + &str->nth_last_child); + if (error != lwc_error_ok) + return css_error_from_lwc_error(error); + + error = lwc_intern_string( + "nth-of-type", SLEN("nth-of-type"), + &str->nth_of_type); + if (error != lwc_error_ok) + return css_error_from_lwc_error(error); + + error = lwc_intern_string( + "nth-last-of-type", SLEN("nth-last-of-type"), + &str->nth_last_of_type); + if (error != lwc_error_ok) + return css_error_from_lwc_error(error); + + error = lwc_intern_string( + "last-child", SLEN("last-child"), + &str->last_child); + if (error != lwc_error_ok) + return css_error_from_lwc_error(error); + + error = lwc_intern_string( + "first-of-type", SLEN("first-of-type"), + &str->first_of_type); + if (error != lwc_error_ok) + return css_error_from_lwc_error(error); + + error = lwc_intern_string( + "last-of-type", SLEN("last-of-type"), + &str->last_of_type); + if (error != lwc_error_ok) + return css_error_from_lwc_error(error); + + error = lwc_intern_string( + "only-child", SLEN("only-child"), + &str->only_child); + if (error != lwc_error_ok) + return css_error_from_lwc_error(error); + + error = lwc_intern_string( + "only-of-type", SLEN("only-of-type"), + &str->only_of_type); + if (error != lwc_error_ok) + return css_error_from_lwc_error(error); + + error = lwc_intern_string( + "root", SLEN("root"), + &str->root); + if (error != lwc_error_ok) + return css_error_from_lwc_error(error); + + error = lwc_intern_string( + "empty", SLEN("empty"), + &str->empty); + if (error != lwc_error_ok) + return css_error_from_lwc_error(error); + + error = lwc_intern_string( + "target", SLEN("target"), + &str->target); + if (error != lwc_error_ok) + return css_error_from_lwc_error(error); + + error = lwc_intern_string( + "lang", SLEN("lang"), + &str->lang); + if (error != lwc_error_ok) + return css_error_from_lwc_error(error); + + error = lwc_intern_string( + "enabled", SLEN("enabled"), + &str->enabled); + if (error != lwc_error_ok) + return css_error_from_lwc_error(error); + + error = lwc_intern_string( + "disabled", SLEN("disabled"), + &str->disabled); + if (error != lwc_error_ok) + return css_error_from_lwc_error(error); + + error = lwc_intern_string( + "checked", SLEN("checked"), + &str->checked); + if (error != lwc_error_ok) + return css_error_from_lwc_error(error); + + /* Pseudo elements */ + error = lwc_intern_string( + "first-line", SLEN("first-line"), + &str->first_line); + if (error != lwc_error_ok) + return css_error_from_lwc_error(error); + + error = lwc_intern_string( + "first_letter", SLEN("first-letter"), + &str->first_letter); + if (error != lwc_error_ok) + return css_error_from_lwc_error(error); + + error = lwc_intern_string( + "before", SLEN("before"), + &str->before); + if (error != lwc_error_ok) + return css_error_from_lwc_error(error); + + error = lwc_intern_string( + "after", SLEN("after"), + &str->after); + if (error != lwc_error_ok) + return css_error_from_lwc_error(error); + + error = lwc_intern_string( + "width", SLEN("width"), + &str->width); + if (error != lwc_error_ok) + return css_error_from_lwc_error(error); + + error = lwc_intern_string( + "height", SLEN("height"), + &str->height); + if (error != lwc_error_ok) + return css_error_from_lwc_error(error); + + error = lwc_intern_string( + "prefers-color-scheme", SLEN("prefers-color-scheme"), + &str->prefers_color_scheme); + if (error != lwc_error_ok) + return css_error_from_lwc_error(error); + + return CSS_OK; +} + +void css_select_strings_unref(css_select_strings *str) +{ + if (str->universal != NULL) + lwc_string_unref(str->universal); + if (str->first_child != NULL) + lwc_string_unref(str->first_child); + if (str->link != NULL) + lwc_string_unref(str->link); + if (str->visited != NULL) + lwc_string_unref(str->visited); + if (str->hover != NULL) + lwc_string_unref(str->hover); + if (str->active != NULL) + lwc_string_unref(str->active); + if (str->focus != NULL) + lwc_string_unref(str->focus); + if (str->nth_child != NULL) + lwc_string_unref(str->nth_child); + if (str->nth_last_child != NULL) + lwc_string_unref(str->nth_last_child); + if (str->nth_of_type != NULL) + lwc_string_unref(str->nth_of_type); + if (str->nth_last_of_type != NULL) + lwc_string_unref(str->nth_last_of_type); + if (str->last_child != NULL) + lwc_string_unref(str->last_child); + if (str->first_of_type != NULL) + lwc_string_unref(str->first_of_type); + if (str->last_of_type != NULL) + lwc_string_unref(str->last_of_type); + if (str->only_child != NULL) + lwc_string_unref(str->only_child); + if (str->only_of_type != NULL) + lwc_string_unref(str->only_of_type); + if (str->root != NULL) + lwc_string_unref(str->root); + if (str->empty != NULL) + lwc_string_unref(str->empty); + if (str->target != NULL) + lwc_string_unref(str->target); + if (str->lang != NULL) + lwc_string_unref(str->lang); + if (str->enabled != NULL) + lwc_string_unref(str->enabled); + if (str->disabled != NULL) + lwc_string_unref(str->disabled); + if (str->checked != NULL) + lwc_string_unref(str->checked); + if (str->first_line != NULL) + lwc_string_unref(str->first_line); + if (str->first_letter != NULL) + lwc_string_unref(str->first_letter); + if (str->before != NULL) + lwc_string_unref(str->before); + if (str->after != NULL) + lwc_string_unref(str->after); + + if (str->width != NULL) + lwc_string_unref(str->width); + if (str->height != NULL) + lwc_string_unref(str->height); + if (str->prefers_color_scheme != NULL) + lwc_string_unref(str->prefers_color_scheme); +} diff --git a/src/select/strings.h b/src/select/strings.h new file mode 100644 index 0000000..ff965e5 --- /dev/null +++ b/src/select/strings.h @@ -0,0 +1,52 @@ +/* + * This file is part of LibCSS + * Licensed under the MIT License, + * http://www.opensource.org/licenses/mit-license.php + * Copyright 2009 John-Mark Bell <jmb@netsurf-browser.org> + */ + +#ifndef css_select_strings_h_ +#define css_select_strings_h_ + +#include <libcss/errors.h> + +/** Useful interned strings */ +typedef struct { + lwc_string *universal; + lwc_string *first_child; + lwc_string *link; + lwc_string *visited; + lwc_string *hover; + lwc_string *active; + lwc_string *focus; + lwc_string *nth_child; + lwc_string *nth_last_child; + lwc_string *nth_of_type; + lwc_string *nth_last_of_type; + lwc_string *last_child; + lwc_string *first_of_type; + lwc_string *last_of_type; + lwc_string *only_child; + lwc_string *only_of_type; + lwc_string *root; + lwc_string *empty; + lwc_string *target; + lwc_string *lang; + lwc_string *enabled; + lwc_string *disabled; + lwc_string *checked; + lwc_string *first_line; + lwc_string *first_letter; + lwc_string *before; + lwc_string *after; + + lwc_string *width; + lwc_string *height; + lwc_string *prefers_color_scheme; +} css_select_strings; + +css_error css_select_strings_intern(css_select_strings *str); +void css_select_strings_unref(css_select_strings *str); + +#endif + diff --git a/src/select/unit.c b/src/select/unit.c new file mode 100644 index 0000000..3294db3 --- /dev/null +++ b/src/select/unit.c @@ -0,0 +1,513 @@ +/* + * This file is part of LibCSS + * Licensed under the MIT License, + * http://www.opensource.org/licenses/mit-license.php + * + * Copyright 2021 Michael Drake <tlsa@netsurf-browser.org> + */ + +#include <libcss/stylesheet.h> + +#include "utils/utils.h" + +#include "propget.h" +#include "unit.h" + +/** + * Map viewport-relative length units to either vh or vw. + * + * Non-viewport-relative units are unchanged. + * + * \param[in] style Reference style. + * \param[in] viewport_height Viewport height in px. + * \param[in] viewport_width Viewport width in px. + * \param[in] unit Unit to map. + * \return the mapped unit. + */ +static inline css_unit css_unit__map_viewport_units( + const css_computed_style *style, + const css_fixed viewport_height, + const css_fixed viewport_width, + const css_unit unit) +{ + switch (unit) { + case CSS_UNIT_VI: + return (style != NULL && get_writing_mode(style) != + CSS_WRITING_MODE_HORIZONTAL_TB) ? + CSS_UNIT_VH : CSS_UNIT_VW; + + case CSS_UNIT_VB: + return (style != NULL && get_writing_mode(style) != + CSS_WRITING_MODE_HORIZONTAL_TB) ? + CSS_UNIT_VW : CSS_UNIT_VH; + + case CSS_UNIT_VMIN: + return (viewport_height < viewport_width) ? + CSS_UNIT_VH : CSS_UNIT_VW; + + case CSS_UNIT_VMAX: + return (viewport_height > viewport_width) ? + CSS_UNIT_VH : CSS_UNIT_VW; + + default: + return unit; + } +} + +/** + * Convert an absolute length to points (pt). + * + * \param[in] style Style to get font-size from, or NULL. + * \param[in] viewport_height Client viewport height. + * \param[in] viewport_width Client viewport width. + * \param[in] length Length to convert. + * \param[in] unit Current unit of length. + * \return length in points (pt). + */ +static inline css_fixed css_unit__absolute_len2pt( + const css_computed_style *style, + const css_fixed viewport_height, + const css_fixed viewport_width, + const css_fixed length, + const css_unit unit) +{ + /* Length must not be relative */ + assert(unit != CSS_UNIT_EM && + unit != CSS_UNIT_EX && + unit != CSS_UNIT_CH && + unit != CSS_UNIT_REM); + + switch (css_unit__map_viewport_units(style, + viewport_height, + viewport_width, + unit)) { + case CSS_UNIT_PX: + return FDIV(FMUL(length, F_72), F_96); + + case CSS_UNIT_IN: + return FMUL(length, F_72); + + case CSS_UNIT_CM: + return FMUL(length, FDIV(F_72, FLTTOFIX(2.54))); + + case CSS_UNIT_MM: + return FMUL(length, FDIV(F_72, FLTTOFIX(25.4))); + + case CSS_UNIT_Q: + return FMUL(length, FDIV(F_72, FLTTOFIX(101.6))); + + case CSS_UNIT_PT: + return length; + + case CSS_UNIT_PC: + return FMUL(length, INTTOFIX(12)); + + case CSS_UNIT_VH: + return FDIV(FMUL(FDIV(FMUL(length, viewport_height), F_100), + F_72), F_96); + + case CSS_UNIT_VW: + return FDIV(FMUL(FDIV(FMUL(length, viewport_width), F_100), + F_72), F_96); + + default: + return 0; + } +} + +/* Exported function, documented in libcss/unit.h. */ +css_fixed css_unit_font_size_len2pt( + const css_computed_style *style, + const css_unit_ctx *ctx, + const css_fixed length, + const css_unit unit) +{ + return css_unit__absolute_len2pt( + style, + ctx->viewport_height, + ctx->viewport_width, + length, + unit); +} + +/** + * Get font size from a style in CSS pixels. + * + * The style should have font size in absolute units. + * + * \param[in] style Style to get font-size from, or NULL. + * \param[in] font_size_default Client font size for NULL style. + * \param[in] font_size_minimum Client minimum font size clamp. + * \param[in] viewport_height Client viewport height. + * \param[in] viewport_width Client viewport width. + * \return font-size in CSS pixels. + */ +static inline css_fixed css_unit__font_size_px( + const css_computed_style *style, + const css_fixed font_size_default, + const css_fixed font_size_minimum, + const css_fixed viewport_height, + const css_fixed viewport_width) +{ + css_fixed font_length = 0; + css_unit font_unit = CSS_UNIT_PT; + + if (style == NULL) { + return font_size_default; + } + + get_font_size(style, &font_length, &font_unit); + + if (font_unit != CSS_UNIT_PX) { + font_length = css_unit__absolute_len2pt(style, + viewport_height, + viewport_width, + font_length, + font_unit); + + /* Convert from pt to CSS pixels.*/ + font_length = FDIV(FMUL(font_length, F_96), F_72); + } + + /* Clamp to configured minimum */ + if (font_length < font_size_minimum) { + font_length = font_size_minimum; + } + + return font_length; +} + +/** + * Get the number of CSS pixels for a given unit. + * + * \param[in] measure Client callback for font measuring. + * \param[in] ref_style Reference style. (Element or parent, or NULL). + * \param[in] root_style Root element style or NULL. + * \param[in] font_size_default Client default font size in CSS pixels. + * \param[in] font_size_minimum Client minimum font size in CSS pixels. + * \param[in] viewport_height Viewport height in CSS pixels. + * \param[in] viewport_width Viewport width in CSS pixels. + * \param[in] unit The unit to convert from. + * \param[in] pw Client private word for measure callback. + * \return Number of CSS pixels equivalent to the given unit. + */ +static inline css_fixed css_unit__px_per_unit( + const css_unit_len_measure measure, + const css_computed_style *ref_style, + const css_computed_style *root_style, + const css_fixed font_size_default, + const css_fixed font_size_minimum, + const css_fixed viewport_height, + const css_fixed viewport_width, + const css_unit unit, + void *pw) +{ + switch (css_unit__map_viewport_units( + ref_style, + viewport_height, + viewport_width, + unit)) { + case CSS_UNIT_EM: + return css_unit__font_size_px( + ref_style, + font_size_default, + font_size_minimum, + viewport_height, + viewport_width); + + case CSS_UNIT_EX: + if (measure != NULL) { + return measure(pw, ref_style, CSS_UNIT_EX); + } + return FMUL(css_unit__font_size_px( + ref_style, + font_size_default, + font_size_minimum, + viewport_height, + viewport_width), FLTTOFIX(0.6)); + + case CSS_UNIT_CH: + if (measure != NULL) { + return measure(pw, ref_style, CSS_UNIT_CH); + } + return FMUL(css_unit__font_size_px( + ref_style, + font_size_default, + font_size_minimum, + viewport_height, + viewport_width), FLTTOFIX(0.4)); + + case CSS_UNIT_PX: + return F_1; + + case CSS_UNIT_IN: + return F_96; + + case CSS_UNIT_CM: + return FDIV(F_96, FLTTOFIX(2.54)); + + case CSS_UNIT_MM: + return FDIV(F_96, FLTTOFIX(25.4)); + + case CSS_UNIT_Q: + return FDIV(F_96, FLTTOFIX(101.6)); + + case CSS_UNIT_PT: + return FDIV(F_96, F_72); + + case CSS_UNIT_PC: + return FDIV(F_96, INTTOFIX(6)); + + case CSS_UNIT_REM: + return css_unit__font_size_px( + root_style, + font_size_default, + font_size_minimum, + viewport_height, + viewport_width); + + case CSS_UNIT_VH: + return FDIV(viewport_width, F_100); + + case CSS_UNIT_VW: + return FDIV(viewport_height, F_100); + + default: + return 0; + } +} + +/* Exported function, documented in unit.h. */ +css_fixed css_unit_len2px_mq( + const css_unit_ctx *ctx, + const css_fixed length, + const css_unit unit) +{ + /* In the media query context there is no reference or root element + * style, so these are hard-coded to NULL. */ + css_fixed px_per_unit = css_unit__px_per_unit( + ctx->measure, + NULL, + NULL, + ctx->font_size_default, + ctx->font_size_minimum, + ctx->viewport_height, + ctx->viewport_width, + unit, + ctx->pw); + + /* Ensure we round px_per_unit to the nearest whole number of pixels: + * the use of FIXTOINT() below will truncate. */ + px_per_unit += F_0_5; + + /* Calculate total number of pixels */ + return FMUL(length, TRUNCATEFIX(px_per_unit)); +} + +/* Exported function, documented in libcss/unit.h. */ +css_fixed css_unit_len2css_px( + const css_computed_style *style, + const css_unit_ctx *ctx, + const css_fixed length, + const css_unit unit) +{ + css_fixed px_per_unit = css_unit__px_per_unit( + ctx->measure, + style, + ctx->root_style, + ctx->font_size_default, + ctx->font_size_minimum, + ctx->viewport_height, + ctx->viewport_width, + unit, + ctx->pw); + + /* Ensure we round px_per_unit to the nearest whole number of pixels: + * the use of FIXTOINT() below will truncate. */ + px_per_unit += F_0_5; + + /* Calculate total number of pixels */ + return FMUL(length, TRUNCATEFIX(px_per_unit)); +} + +/* Exported function, documented in libcss/unit.h. */ +css_fixed css_unit_len2device_px( + const css_computed_style *style, + const css_unit_ctx *ctx, + const css_fixed length, + const css_unit unit) +{ + css_fixed px_per_unit = css_unit__px_per_unit( + ctx->measure, + style, + ctx->root_style, + ctx->font_size_default, + ctx->font_size_minimum, + ctx->viewport_height, + ctx->viewport_width, + unit, + ctx->pw); + + px_per_unit = css_unit_css2device_px(px_per_unit, ctx->device_dpi); + + /* Ensure we round px_per_unit to the nearest whole number of pixels: + * the use of FIXTOINT() below will truncate. */ + px_per_unit += F_0_5; + + /* Calculate total number of pixels */ + return FMUL(length, TRUNCATEFIX(px_per_unit)); +} + +/** + * Get font size from a computed style. + * + * The computed style will have font-size with an absolute unit. + * If no computed style is given, the client default font-size will be returned. + * + * \param[in] style Reference style. (Element or parent, or NULL). + * \param[in] font_size_default Client default font size in CSS pixels. + * \return The font size in absolute units. + */ +static inline css_hint_length css_unit__get_font_size( + const css_computed_style *style, + css_fixed font_size_default) +{ + css_hint_length size = { + .value = font_size_default, + .unit = CSS_UNIT_PX, + }; + + if (style != NULL) { + enum css_font_size_e status = get_font_size(style, + &size.value, + &size.unit); + + UNUSED(status); + + /* The font size must be absolute. */ + assert(status == CSS_FONT_SIZE_DIMENSION); + assert(size.unit != CSS_UNIT_EM); + assert(size.unit != CSS_UNIT_EX); + assert(size.unit != CSS_UNIT_PCT); + } + + return size; +} + +/* Exported function, documented in unit.h. */ +css_error css_unit_compute_absolute_font_size( + const css_hint_length *ref_length, + const css_computed_style *root_style, + css_fixed font_size_default, + css_hint *size) +{ + css_hint_length ref_len = { + .value = font_size_default, + .unit = CSS_UNIT_PX, + }; + + if (ref_length != NULL) { + /* Must be absolute. */ + assert(ref_length->unit != CSS_UNIT_EM); + assert(ref_length->unit != CSS_UNIT_EX); + assert(ref_length->unit != CSS_UNIT_PCT); + + ref_len = *ref_length; + } + + assert(size->status != CSS_FONT_SIZE_INHERIT); + + switch (size->status) { + case CSS_FONT_SIZE_XX_SMALL: /* Fall-through. */ + case CSS_FONT_SIZE_X_SMALL: /* Fall-through. */ + case CSS_FONT_SIZE_SMALL: /* Fall-through. */ + case CSS_FONT_SIZE_MEDIUM: /* Fall-through. */ + case CSS_FONT_SIZE_LARGE: /* Fall-through. */ + case CSS_FONT_SIZE_X_LARGE: /* Fall-through. */ + case CSS_FONT_SIZE_XX_LARGE: + { + static const css_fixed factors[CSS_FONT_SIZE_XX_LARGE] = { + [CSS_FONT_SIZE_XX_SMALL - 1] = FLTTOFIX(0.5625), + [CSS_FONT_SIZE_X_SMALL - 1] = FLTTOFIX(0.6250), + [CSS_FONT_SIZE_SMALL - 1] = FLTTOFIX(0.8125), + [CSS_FONT_SIZE_MEDIUM - 1] = FLTTOFIX(1.0000), + [CSS_FONT_SIZE_LARGE - 1] = FLTTOFIX(1.1250), + [CSS_FONT_SIZE_X_LARGE - 1] = FLTTOFIX(1.5000), + [CSS_FONT_SIZE_XX_LARGE - 1] = FLTTOFIX(2.0000), + }; + assert(CSS_FONT_SIZE_INHERIT == 0); + assert(CSS_FONT_SIZE_XX_SMALL == 1); + + size->data.length.value = FMUL(factors[size->status - 1], + font_size_default); + size->data.length.unit = CSS_UNIT_PX; + size->status = CSS_FONT_SIZE_DIMENSION; + break; + } + case CSS_FONT_SIZE_LARGER: + size->data.length.value = FMUL(ref_len.value, FLTTOFIX(1.2)); + size->data.length.unit = ref_len.unit; + size->status = CSS_FONT_SIZE_DIMENSION; + break; + + case CSS_FONT_SIZE_SMALLER: + size->data.length.value = FDIV(ref_len.value, FLTTOFIX(1.2)); + size->data.length.unit = ref_len.unit; + size->status = CSS_FONT_SIZE_DIMENSION; + break; + + case CSS_FONT_SIZE_DIMENSION: + /* Convert any relative units to absolute. */ + switch (size->data.length.unit) { + case CSS_UNIT_PCT: + size->data.length.value = FDIV(FMUL( + size->data.length.value, + ref_len.value), INTTOFIX(100)); + size->data.length.unit = ref_len.unit; + break; + + case CSS_UNIT_EM: /* Fall-through */ + case CSS_UNIT_EX: /* Fall-through */ + case CSS_UNIT_CH: + /* Parent relative units. */ + size->data.length.value = FMUL( + size->data.length.value, ref_len.value); + + switch (size->data.length.unit) { + case CSS_UNIT_EX: + size->data.length.value = FMUL( + size->data.length.value, + FLTTOFIX(0.6)); + break; + + case CSS_UNIT_CH: + size->data.length.value = FMUL( + size->data.length.value, + FLTTOFIX(0.4)); + break; + + default: + break; + } + size->data.length.unit = ref_len.unit; + break; + + case CSS_UNIT_REM: + /* Root element relative units. */ + ref_len = css_unit__get_font_size(root_style, + font_size_default); + + size->data.length.unit = ref_len.unit; + size->data.length.value = FMUL( + size->data.length.value, ref_len.value); + break; + + default: + break; + } + default: + break; + } + + return CSS_OK; +} diff --git a/src/select/unit.h b/src/select/unit.h new file mode 100644 index 0000000..6a677b6 --- /dev/null +++ b/src/select/unit.h @@ -0,0 +1,42 @@ +/* + * This file is part of LibCSS + * Licensed under the MIT License, + * http://www.opensource.org/licenses/mit-license.php + * + * Copyright 2021 Michael Drake <tlsa@netsurf-browser.org> + */ + +#ifndef css_select_unit_h_ +#define css_select_unit_h_ + +#include <libcss/unit.h> + +/** + * Convert a length to CSS pixels for a media query context. + * + * \param[in] ctx Document unit conversion context. + * \param[in] length Length to convert. + * \param[in] unit Current unit of length. + * \return A length in CSS pixels. + */ +css_fixed css_unit_len2px_mq( + const css_unit_ctx *ctx, + const css_fixed length, + const css_unit unit); + +/** + * Convert relative font size units to absolute units. + * + * \param[in] ref_length Reference font-size length or NULL. + * \param[in] root_style Root element style or NULL. + * \param[in] font_size_default Client default font size in CSS pixels. + * \param[in,out] size The length to convert. + * \return CSS_OK on success, or appropriate error otherwise. + */ +css_error css_unit_compute_absolute_font_size( + const css_hint_length *ref_length, + const css_computed_style *root_style, + css_fixed font_size_default, + css_hint *size); + +#endif |