diff options
author | Michael Drake <tlsa@netsurf-browser.org> | 2022-11-27 15:41:35 +0000 |
---|---|---|
committer | Michael Drake <tlsa@netsurf-browser.org> | 2022-11-28 14:22:51 +0000 |
commit | 110ee41e0a4d697c5dfb74b4be3b1622c03fba65 (patch) | |
tree | d28b7aed75bb04f94adb96bb114439c3996cf165 | |
parent | bb4f667d633a2640f3673cf269b98af1e1b24ea1 (diff) | |
download | libcss-110ee41e0a4d697c5dfb74b4be3b1622c03fba65.tar.gz libcss-110ee41e0a4d697c5dfb74b4be3b1622c03fba65.tar.bz2 |
WIP: Update computed styles for calc
-rw-r--r-- | include/libcss/types.h | 4 | ||||
-rw-r--r-- | src/parse/properties/font.c | 1 | ||||
-rw-r--r-- | src/select/autogenerated_computed.h | 10 | ||||
-rw-r--r-- | src/select/autogenerated_propget.h | 4 | ||||
-rw-r--r-- | src/select/autogenerated_propset.h | 26 | ||||
-rw-r--r-- | src/select/computed.c | 2 | ||||
-rw-r--r-- | src/select/select_config.py | 4 | ||||
-rw-r--r-- | src/select/select_generator.py | 66 | ||||
-rw-r--r-- | test/dump_computed.h | 3 |
9 files changed, 101 insertions, 19 deletions
diff --git a/include/libcss/types.h b/include/libcss/types.h index 3fb28d3..c0b19da 100644 --- a/include/libcss/types.h +++ b/include/libcss/types.h @@ -109,7 +109,9 @@ typedef enum css_unit { CSS_UNIT_S = 0x1a, CSS_UNIT_HZ = 0x1b, - CSS_UNIT_KHZ = 0x1c + CSS_UNIT_KHZ = 0x1c, + + CSS_UNIT_CALC = 0x1d /**< Un-resolved calc() */ } css_unit; /** diff --git a/src/parse/properties/font.c b/src/parse/properties/font.c index 7ce9701..b77e65c 100644 --- a/src/parse/properties/font.c +++ b/src/parse/properties/font.c @@ -45,6 +45,7 @@ static inline uint32_t css__to_parse_unit(css_unit u) case CSS_UNIT_S: return UNIT_S; case CSS_UNIT_HZ: return UNIT_HZ; case CSS_UNIT_KHZ: return UNIT_KHZ; + case CSS_UNIT_CALC: assert(0); } return 0; diff --git a/src/select/autogenerated_computed.h b/src/select/autogenerated_computed.h index b26560d..db779ff 100644 --- a/src/select/autogenerated_computed.h +++ b/src/select/autogenerated_computed.h @@ -209,7 +209,10 @@ struct css_computed_style_i { css_fixed background_position_a; css_fixed background_position_b; css_color border_bottom_color; - css_fixed border_bottom_width; + union { + css_fixed value; + lwc_string *calc; + } border_bottom_width; css_color border_left_color; css_fixed border_left_width; css_color border_right_color; @@ -218,7 +221,10 @@ struct css_computed_style_i { css_fixed border_spacing_b; css_color border_top_color; css_fixed border_top_width; - css_fixed bottom; + union { + css_fixed value; + lwc_string *calc; + } bottom; css_fixed clip_a; css_fixed clip_b; css_fixed clip_c; diff --git a/src/select/autogenerated_propget.h b/src/select/autogenerated_propget.h index 6c958aa..ef2d74e 100644 --- a/src/select/autogenerated_propget.h +++ b/src/select/autogenerated_propget.h @@ -307,7 +307,7 @@ static inline uint8_t get_border_bottom_width(const css_computed_style *style, /* 8bits: uuuuuttt : unit | type */ if ((bits & 0x7) == CSS_BORDER_WIDTH_WIDTH) { - *length = style->i.border_bottom_width; + *length = style->i.border_bottom_width.value; *unit = bits >> 3; } @@ -659,7 +659,7 @@ static inline uint8_t get_bottom(const css_computed_style *style, css_fixed /* 7bits: uuuuutt : unit | type */ if ((bits & 0x3) == CSS_BOTTOM_SET) { - *length = style->i.bottom; + *length = style->i.bottom.value; *unit = bits >> 2; } diff --git a/src/select/autogenerated_propset.h b/src/select/autogenerated_propset.h index 036c2ba..317fb2a 100644 --- a/src/select/autogenerated_propset.h +++ b/src/select/autogenerated_propset.h @@ -244,6 +244,17 @@ static inline css_error set_border_bottom_style(css_computed_style *style, static inline css_error set_border_bottom_width(css_computed_style *style, uint8_t type, css_fixed length, css_unit unit) { + uint32_t orig_bits = style->i.bits[BORDER_BOTTOM_WIDTH_INDEX]; + orig_bits &= BORDER_BOTTOM_WIDTH_MASK; + orig_bits >>= BORDER_BOTTOM_WIDTH_SHIFT; + + /* 8bits: uuuuuttt : unit | type */ + if ((orig_bits & 0x7) == CSS_BORDER_WIDTH_WIDTH) { + if ((orig_bits & 0xf8) >> 3 == CSS_UNIT_CALC) { + lwc_string_unref(style->i.border_bottom_width.calc); + } + } + uint32_t *bits; bits = &style->i.bits[BORDER_BOTTOM_WIDTH_INDEX]; @@ -252,7 +263,7 @@ static inline css_error set_border_bottom_width(css_computed_style *style, *bits = (*bits & ~BORDER_BOTTOM_WIDTH_MASK) | ((((uint32_t)type & 0x7) | (unit << 3)) << BORDER_BOTTOM_WIDTH_SHIFT); - style->i.border_bottom_width = length; + style->i.border_bottom_width.value = length; return CSS_OK; } @@ -515,6 +526,17 @@ static inline css_error set_border_top_width(css_computed_style *style, uint8_t static inline css_error set_bottom(css_computed_style *style, uint8_t type, css_fixed length, css_unit unit) { + uint32_t orig_bits = style->i.bits[BOTTOM_INDEX]; + orig_bits &= BOTTOM_MASK; + orig_bits >>= BOTTOM_SHIFT; + + /* 7bits: uuuuutt : unit | type */ + if ((orig_bits & 0x3) == CSS_BOTTOM_SET) { + if ((orig_bits & 0x7c) >> 2 == CSS_UNIT_CALC) { + lwc_string_unref(style->i.bottom.calc); + } + } + uint32_t *bits; bits = &style->i.bits[BOTTOM_INDEX]; @@ -523,7 +545,7 @@ static inline css_error set_bottom(css_computed_style *style, uint8_t type, *bits = (*bits & ~BOTTOM_MASK) | ((((uint32_t)type & 0x3) | (unit << 2)) << BOTTOM_SHIFT); - style->i.bottom = length; + style->i.bottom.value = length; return CSS_OK; } diff --git a/src/select/computed.c b/src/select/computed.c index c257f17..a520381 100644 --- a/src/select/computed.c +++ b/src/select/computed.c @@ -472,7 +472,7 @@ uint8_t css_computed_top(const css_computed_style *style, *unit = CSS_UNIT_PX; } else if (top == CSS_TOP_AUTO) { /* Top is auto => -bottom */ - *length = -style->i.bottom; + *length = -style->i.bottom.value; *unit = (css_unit) (bottom >> 2); } diff --git a/src/select/select_config.py b/src/select/select_config.py index fd9e765..bc22ea4 100644 --- a/src/select/select_config.py +++ b/src/select/select_config.py @@ -72,11 +72,11 @@ style = { ('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_bottom_width', 3, (('length', None, 'calc'),), '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'), + ('bottom', 2, (('length', None, 'calc'),), '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'), diff --git a/src/select/select_generator.py b/src/select/select_generator.py index 05a4511..b7a447c 100644 --- a/src/select/select_generator.py +++ b/src/select/select_generator.py @@ -167,6 +167,7 @@ class CSSValue: self.size = size # `None` means sizeof(ptr) self.defaults = defaults self.suffix = '' + self.calc = False self.bits = None if bits_size is None else { 'name': bits_name, 'type': bits_type, @@ -223,6 +224,13 @@ class CSSProperty: def make_values(self, vals): """Make list of values for this property.""" + self.has_calc = False + + if vals is not None and any(len(val) > 2 and val[2] == 'calc' for val in vals): + self.has_calc = True + + print(f"name: {self.name}, {vals}, has calc: {self.has_calc}") + if vals is None: return [] elif type(vals) is str: @@ -233,8 +241,10 @@ class CSSProperty: for x in values: if x[0] == v[0]: value = CSSValue(*x) - if len(v) == 2: + if len(v) > 1 and v[1] != None: value.defaults = v[1] + if len(v) > 2 and v[2] == 'calc': + value.calc = True if len(vals) > 1: value.suffix = '_' + string.ascii_lowercase[i] val_list.append(value) @@ -608,6 +618,29 @@ class CSSGroup: t.append('{') t.indent(1) + # Ensure any existing calc() values are freed + if p.has_calc: + t.append('uint32_t orig_bits = style{}->{}bits[{}_INDEX];'.format( + grp, i_dot, p.name.upper())) + t.append('orig_bits &= {}_MASK;'.format(p.name.upper())) + t.append('orig_bits >>= {}_SHIFT;'.format(p.name.upper())) + t.append() + + type_mask, shift_list, bits_comment = p.get_bits() + t.append(bits_comment) + t.append('if ((orig_bits & {}) == {}) {{'.format(type_mask, p.condition)) + t.indent(1) + for i, v in enumerate(list(reversed(shift_list))): + t.append('if ((orig_bits & 0x{:x}) >> {} == CSS_UNIT_CALC) {{'.format(v[2], v[1])) + t.indent(1) + this_idot = i_dot + t.append('lwc_string_unref(style->{}{}.calc);'.format(this_idot, p.name)) + t.indent(-1) + t.append('}') + t.indent(-1) + t.append('}') + t.append() + t.append('uint32_t *bits;') t.append() @@ -693,8 +726,9 @@ class CSSGroup: t.append('}') elif not v.is_ptr: - t.append('style{}->{}{} = {};'.format( - grp, i_dot, p.name + v.suffix, v.name + v.suffix)) + dot_value = '.value' if p.has_calc else '' + t.append('style->{}{}{} = {};'.format( + i_dot, p.name + v.suffix, dot_value, v.name + v.suffix)) else: raise ValueError('Cannot handle value ' + v.name +'!') @@ -740,9 +774,11 @@ class CSSGroup: t.indent(1) for v in p.values: + print(f"name: {p.name}, has_calc: {p.has_calc}, v.name: {v.name}") this_idot = '' if v.is_ptr and v.name != 'string' else i_dot - t.append('*{} = style{}->{}{};'.format( - v.name + v.suffix, grp, this_idot, p.name + v.suffix)) + dot_value = '.value' if p.has_calc else '' + t.append('*{} = style->{}{}{};'.format( + v.name + v.suffix, this_idot, p.name + v.suffix, dot_value)) for i, v in enumerate(list(reversed(shift_list))): if i == 0: t.append('*{} = bits >> {};'.format(v[0], v[1])) @@ -804,13 +840,25 @@ class CSSGroup: r = [] for p in sorted(self.props, key=(lambda x: x.name)): if bool(p.comments) == for_commented: - for v in p.values: - if defaults: + if defaults: + for v in p.values: r.append('.{}{} = {}'.format(p.name, v.suffix, v.defaults)) + else: + if (p.values == None or len(p.values) == 0): + continue + if p.has_calc == True: + for v in p.values: + r.append('union {') + v_type, v_name = shift_star(v.type, "value") + r.append('\t{} {};'.format(v_type, v_name)) + if v.calc: + r.append('\tlwc_string *calc;') + r.append('}} {}{};'.format(p.name, v.suffix)) else: - v_type, v_name = shift_star(v.type, p.name) - r.append('{} {}{};'.format(v_type, v_name, v.suffix)) + 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): diff --git a/test/dump_computed.h b/test/dump_computed.h index 2ce7849..fd6923b 100644 --- a/test/dump_computed.h +++ b/test/dump_computed.h @@ -159,6 +159,9 @@ static size_t dump_css_unit(css_fixed val, css_unit unit, char *ptr, size_t len) case CSS_UNIT_KHZ: ret += snprintf(ptr + ret, len - ret, "kHz"); break; + case CSS_UNIT_CALC: + ret += snprintf(ptr + ret, len - ret, "calc()"); + break; } return ret; |