Gitweb links:

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

The branch, tlsa/calc-wip has been updated
  discards  a28d2e148b5ee756ce284f81598be44b88b319b2 (commit)
       via  110ee41e0a4d697c5dfb74b4be3b1622c03fba65 (commit)

This update added new revisions after undoing existing revisions.  That is
to say, the old revision is not a strict subset of the new revision.  This
situation occurs when you --force push a change and generate a repository
containing something like this:

 * -- * -- B -- O -- O -- O (a28d2e148b5ee756ce284f81598be44b88b319b2)
            \
             N -- N -- N (110ee41e0a4d697c5dfb74b4be3b1622c03fba65)

When this happens we assume that you've already had alert emails for all
of the O revisions, and so we here report only the revisions in the N
branch from the common base, B.

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commitdiff 
http://git.netsurf-browser.org/libcss.git/commit/?id=110ee41e0a4d697c5dfb74b4be3b1622c03fba65
commit 110ee41e0a4d697c5dfb74b4be3b1622c03fba65
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..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;


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

Summary of changes:
 src/select/autogenerated_computed.h |    8 ++++----
 src/select/select_config.py         |    5 ++---
 src/select/select_generator.py      |   37 ++++++++++++-----------------------
 3 files changed, 18 insertions(+), 32 deletions(-)

diff --git a/src/select/autogenerated_computed.h 
b/src/select/autogenerated_computed.h
index 62fc731..db779ff 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 + sizeof(ptr)
+ * border_bottom_width              3 + 5           4
  * 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 + sizeof(ptr)
+ * bottom                           2 + 5           4
  * 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 + 10sizeof(ptr) bytes
+ *                                462 bits        228 + 8sizeof(ptr) bytes
  *                                ===================
- *                                286 + 10sizeof(ptr) bytes
+ *                                286 + 8sizeof(ptr) bytes
  * 
  * Bit allocations:
  * 
diff --git a/src/select/select_config.py b/src/select/select_config.py
index 6e1ebeb..bc22ea4 100644
--- a/src/select/select_config.py
+++ b/src/select/select_config.py
@@ -13,7 +13,6 @@ 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*'),
@@ -73,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',), ('calc',)), 
'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',), ('calc',)), '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 94d44b0..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,
@@ -225,7 +226,7 @@ class CSSProperty:
         """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):
+        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}")
@@ -240,12 +241,11 @@ 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]
-                        subtraction = 0
-                        if self.has_calc:
-                            subtraction = 1
-                        if len(vals) - subtraction > 1 and v[0] != 'calc':
+                        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)
                         break
@@ -332,8 +332,6 @@ 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:
@@ -668,9 +666,6 @@ 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)
 
@@ -780,8 +775,6 @@ class CSSGroup:
 
             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
                 dot_value = '.value' if p.has_calc else ''
                 t.append('*{} = style->{}{}{};'.format(
@@ -855,19 +848,13 @@ class CSSGroup:
                     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))
+                            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:
                         for v in p.values:
                             v_type, v_name = shift_star(v.type, p.name)


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

Reply via email to