Gitweb links:

...log 
http://git.netsurf-browser.org/libcss.git/shortlog/ac9d68a38c4aad45ad4ebf3db2c3b5a7cb971cd1
...commit 
http://git.netsurf-browser.org/libcss.git/commit/ac9d68a38c4aad45ad4ebf3db2c3b5a7cb971cd1
...tree 
http://git.netsurf-browser.org/libcss.git/tree/ac9d68a38c4aad45ad4ebf3db2c3b5a7cb971cd1

The branch, tlsa/calc-wip has been created
        at  ac9d68a38c4aad45ad4ebf3db2c3b5a7cb971cd1 (commit)

- Log -----------------------------------------------------------------
commitdiff 
http://git.netsurf-browser.org/libcss.git/commit/?id=ac9d68a38c4aad45ad4ebf3db2c3b5a7cb971cd1
commit ac9d68a38c4aad45ad4ebf3db2c3b5a7cb971cd1
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>

    WIP: Update computed styles for calc

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..62fc731 100644
--- a/src/select/autogenerated_computed.h
+++ b/src/select/autogenerated_computed.h
@@ -20,7 +20,7 @@ struct css_computed_style_i {
  * background_repeat                3             
  * border_bottom_color              2               4
  * border_bottom_style              4             
- * border_bottom_width              3 + 5           4
+ * border_bottom_width              3 + 5           4 + sizeof(ptr)
  * border_collapse                  2             
  * border_left_color                2               4
  * border_left_style                4             
@@ -32,7 +32,7 @@ struct css_computed_style_i {
  * border_top_color                 2               4
  * border_top_style                 4             
  * border_top_width                 3 + 5           4
- * bottom                           2 + 5           4
+ * bottom                           2 + 5           4 + sizeof(ptr)
  * box_sizing                       2             
  * break_after                      4             
  * break_before                     4             
@@ -140,9 +140,9 @@ struct css_computed_style_i {
  * quotes                           1             sizeof(ptr)
  * 
  * ---                            ---             ---
- *                                462 bits        228 + 8sizeof(ptr) bytes
+ *                                462 bits        228 + 10sizeof(ptr) bytes
  *                                ===================
- *                                286 + 8sizeof(ptr) bytes
+ *                                286 + 10sizeof(ptr) bytes
  * 
  * Bit allocations:
  * 
@@ -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 cf82c86..2751a18 100644
--- a/src/select/autogenerated_propget.h
+++ b/src/select/autogenerated_propget.h
@@ -202,7 +202,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;
        }
        
@@ -431,32 +431,21 @@ static inline uint8_t get_border_top_width(const 
css_computed_style *style,
 #define BOTTOM_INDEX 3
 #define BOTTOM_SHIFT 11
 #define BOTTOM_MASK 0x3f800
-static inline uint8_t get_bottom(
-               const css_computed_style *style,
-               css_fixed *length, css_unit *unit)
+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 : units | type */
+       
+       /* 7bits: uuuuutt : unit | type */
        if ((bits & 0x3) == CSS_BOTTOM_SET) {
-               *length = style->i.bottom;
+               *length = style->i.bottom.value;
                *unit = bits >> 2;
        }
-
+       
        return (bits & 0x3);
 }
-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 : units | type */
-       return bits;
-}
 #undef BOTTOM_INDEX
 #undef BOTTOM_SHIFT
 #undef BOTTOM_MASK
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/overrides.py b/src/select/overrides.py
index b4d349a..1336976 100644
--- a/src/select/overrides.py
+++ b/src/select/overrides.py
@@ -213,5 +213,5 @@ static inline uint8_t get_{0}_bits(
 }}'''
 overrides['get']['top'] = get_side.format('top', 'TOP')
 overrides['get']['right'] = get_side.format('right', 'RIGHT')
-overrides['get']['bottom'] = get_side.format('bottom', 'BOTTOM')
+#overrides['get']['bottom'] = get_side.format('bottom', 'BOTTOM')
 overrides['get']['left'] = get_side.format('left', 'LEFT')
diff --git a/src/select/select_config.py b/src/select/select_config.py
index fd9e765..6e1ebeb 100644
--- a/src/select/select_config.py
+++ b/src/select/select_config.py
@@ -13,6 +13,7 @@ values = {
     ('integer', 'int32_t', 4, '0'),
     ('fixed', 'css_fixed', 4, '0'),
     ('color', 'css_color', 4, '0'),
+    ('calc', 'lwc_string*'),
     ('string', 'lwc_string*'),
     ('string_arr', 'lwc_string**'),
     ('counter_arr', 'css_computed_counter*'),
@@ -72,11 +73,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',), ('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',), ('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 ece7a91..4f6ee68 100644
--- a/src/select/select_generator.py
+++ b/src/select/select_generator.py
@@ -223,6 +223,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(val[0] == '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:
@@ -235,7 +242,10 @@ class CSSProperty:
                         value = CSSValue(*x)
                         if len(v) == 2:
                             value.defaults = v[1]
-                        if len(vals) > 1:
+                        subtraction = 0
+                        if self.has_calc:
+                            subtraction = 1
+                        if len(vals) - subtraction > 1 and v[0] != 'calc':
                             value.suffix = '_' + string.ascii_lowercase[i]
                         val_list.append(value)
                         break
@@ -322,6 +332,8 @@ class CSSProperty:
         """
         vals = []
         for v in self.values:
+            if v.name == 'calc':
+                continue
             vt, vn = shift_star(v.type, v.name)
             vn += v.suffix
             if pointer:
@@ -608,6 +620,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()
 
@@ -633,6 +668,9 @@ class CSSGroup:
 
             t.append()
             for v in p.values:
+                if v.name == 'calc':
+                    continue
+
                 old_n = 'old_' + v.name + v.suffix
                 old_t, old_n_shift = shift_star(v.type, old_n)
 
@@ -693,8 +731,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 +'!')
@@ -750,9 +789,13 @@ class CSSGroup:
                 t.indent(1)
 
             for v in p.values:
+                print(f"name: {p.name}, has_calc: {p.has_calc}, v.name: 
{v.name}")
+                if v.name == 'calc':
+                    continue
                 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]))
@@ -796,13 +839,31 @@ 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:
+                        calc = None
+                        for v in p.values:
+                            if v.name == 'calc':
+                                calc = v
+                        for v in p.values:
+                            if v.name != 'calc':
+                                r.append('union {')
+                                v_type, v_name = shift_star(v.type, "value")
+                                r.append('\t{} {};'.format(v_type, v_name))
+                                if calc != None:
+                                    v_type, v_name = shift_star(calc.type, 
calc.name)
+                                    r.append('\t{} {}{};'.format(v_type, 
v_name, calc.suffix))
+                                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):


-----------------------------------------------------------------------


-- 
Cascading Style Sheets library
_______________________________________________
netsurf-commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to