Gitweb links:

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

The branch, tlsa/flex has been created
        at  eba213195070847cd7352f039956cf832a40e9e0 (commit)

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

    WIP: flex

diff --git a/content/handlers/html/box.h b/content/handlers/html/box.h
index 8ab2875..fbe7cb0 100644
--- a/content/handlers/html/box.h
+++ b/content/handlers/html/box.h
@@ -118,7 +118,8 @@ typedef enum {
        BOX_TABLE_ROW_GROUP,
        BOX_FLOAT_LEFT, BOX_FLOAT_RIGHT,
        BOX_INLINE_BLOCK, BOX_BR, BOX_TEXT,
-       BOX_INLINE_END, BOX_NONE
+       BOX_INLINE_END, BOX_NONE,
+       BOX_FLEX, BOX_INLINE_FLEX,
 } box_type;
 
 
@@ -389,6 +390,19 @@ static inline bool box_is_first_child(struct box *b)
        return (b->parent == NULL || b == b->parent->children);
 }
 
+static inline unsigned box_count_children(const struct box *b)
+{
+       const struct box *c = b->children;
+       unsigned count = 0;
+
+       while (c != NULL) {
+               count++;
+               c = c->next;
+       }
+
+       return count;
+}
+
 /**
  * Retrieve the box for a dom node, if there is one
  *
diff --git a/content/handlers/html/box_construct.c 
b/content/handlers/html/box_construct.c
index f545785..1932b69 100644
--- a/content/handlers/html/box_construct.c
+++ b/content/handlers/html/box_construct.c
@@ -230,8 +230,8 @@ static const box_type box_map[] = {
        BOX_TABLE_CELL,      /* CSS_DISPLAY_TABLE_CELL */
        BOX_INLINE,          /* CSS_DISPLAY_TABLE_CAPTION */
        BOX_NONE,            /* CSS_DISPLAY_NONE */
-       BOX_BLOCK,           /* CSS_DISPLAY_FLEX */
-       BOX_INLINE_BLOCK,    /* CSS_DISPLAY_INLINE_FLEX */
+       BOX_FLEX,           /* CSS_DISPLAY_FLEX */
+       BOX_INLINE_FLEX,    /* CSS_DISPLAY_INLINE_FLEX */
 };
 
 /* Exported function, see box.h */
@@ -946,6 +946,7 @@ bool box_construct_element(struct box_construct_ctx *ctx,
                        (box->type == BOX_INLINE ||
                         box->type == BOX_BR ||
                         box->type == BOX_INLINE_BLOCK ||
+                        box->type == BOX_INLINE_FLEX ||
                         css_computed_float(box->style) == CSS_FLOAT_LEFT ||
                         css_computed_float(box->style) == CSS_FLOAT_RIGHT) &&
                        props.node_is_root == false) {
@@ -994,6 +995,7 @@ bool box_construct_element(struct box_construct_ctx *ctx,
                box->flags |= CONVERT_CHILDREN;
 
        if (box->type == BOX_INLINE || box->type == BOX_BR ||
+                       box->type == BOX_INLINE_FLEX ||
                        box->type == BOX_INLINE_BLOCK) {
                /* Inline container must exist, as we'll have
                 * created it above if it didn't */
diff --git a/content/handlers/html/box_normalise.c 
b/content/handlers/html/box_normalise.c
index 7155cb7..6bb107d 100644
--- a/content/handlers/html/box_normalise.c
+++ b/content/handlers/html/box_normalise.c
@@ -93,6 +93,180 @@ static bool box_normalise_inline_container(
                const struct box *root,
                html_content *c);
 
+static bool box_normalise_flex(
+               struct box *flex_container,
+               const struct box *root,
+               html_content *c)
+{
+       struct box *child;
+       struct box *next_child;
+       struct box *implied_flex_item;
+       css_computed_style *style;
+       nscss_select_ctx ctx;
+
+       assert(flex_container != NULL);
+       assert(root != NULL);
+
+       ctx.root_style = root->style;
+
+#ifdef BOX_NORMALISE_DEBUG
+       NSLOG(netsurf, INFO, "flex_container %p, flex_container->type %u",
+                       flex_container, flex_container->type);
+#endif
+
+       assert(flex_container->type == BOX_FLEX ||
+              flex_container->type == BOX_INLINE_FLEX);
+
+       for (child = flex_container->children; child != NULL; child = 
next_child) {
+#ifdef BOX_NORMALISE_DEBUG
+               NSLOG(netsurf, INFO, "child %p, child->type = %d",
+                               child, child->type);
+#endif
+
+               next_child = child->next;       /* child may be destroyed */
+
+               switch (child->type) {
+               case BOX_FLEX:
+                       /* ok */
+                       if (box_normalise_flex(child, root, c) == false)
+                               return false;
+                       break;
+               case BOX_BLOCK:
+                       /* ok */
+                       if (box_normalise_block(child, root, c) == false)
+                               return false;
+                       break;
+               case BOX_INLINE_CONTAINER:
+                       /* insert implied flex item */
+                       assert(flex_container->style != NULL);
+
+                       ctx.ctx = c->select_ctx;
+                       ctx.quirks = (c->quirks == 
DOM_DOCUMENT_QUIRKS_MODE_FULL);
+                       ctx.base_url = c->base_url;
+                       ctx.universal = c->universal;
+
+                       style = nscss_get_blank_style(&ctx, 
flex_container->style);
+                       if (style == NULL)
+                               return false;
+
+                       implied_flex_item = box_create(NULL, style, true,
+                                       flex_container->href,
+                                       flex_container->target,
+                                       NULL, NULL, c->bctx);
+                       if (implied_flex_item == NULL) {
+                               css_computed_style_destroy(style);
+                               return false;
+                       }
+                       implied_flex_item->type = BOX_BLOCK;
+
+                       if (child->prev == NULL)
+                               flex_container->children = implied_flex_item;
+                       else
+                               child->prev->next = implied_flex_item;
+
+                       implied_flex_item->prev = child->prev;
+
+                       while (child != NULL &&
+                                       child->type == BOX_INLINE_CONTAINER) {
+                               box_add_child(implied_flex_item, child);
+
+                               next_child = child->next;
+                               child->next = NULL;
+                               child = next_child;
+                       }
+
+                       implied_flex_item->last->next = NULL;
+                       implied_flex_item->next = next_child = child;
+                       if (implied_flex_item->next != NULL)
+                               implied_flex_item->next->prev = 
implied_flex_item;
+                       else
+                               flex_container->last = implied_flex_item;
+                       implied_flex_item->parent = flex_container;
+
+                       if (box_normalise_block(implied_flex_item,
+                                       root, c) == false)
+                               return false;
+                       break;
+
+               case BOX_TABLE:
+                       if (box_normalise_table(child, root, c) == false)
+                               return false;
+                       break;
+               case BOX_INLINE:
+               case BOX_INLINE_END:
+               case BOX_INLINE_FLEX:
+               case BOX_INLINE_BLOCK:
+               case BOX_FLOAT_LEFT:
+               case BOX_FLOAT_RIGHT:
+               case BOX_BR:
+               case BOX_TEXT:
+                       /* should have been wrapped in inline
+                          container by convert_xml_to_box() */
+                       assert(0);
+                       break;
+               case BOX_TABLE_ROW_GROUP:
+               case BOX_TABLE_ROW:
+               case BOX_TABLE_CELL:
+                       /* insert implied table */
+                       assert(flex_container->style != NULL);
+
+                       ctx.ctx = c->select_ctx;
+                       ctx.quirks = (c->quirks == 
DOM_DOCUMENT_QUIRKS_MODE_FULL);
+                       ctx.base_url = c->base_url;
+                       ctx.universal = c->universal;
+
+                       style = nscss_get_blank_style(&ctx, 
flex_container->style);
+                       if (style == NULL)
+                               return false;
+
+                       implied_flex_item = box_create(NULL, style, true,
+                                       flex_container->href,
+                                       flex_container->target,
+                                       NULL, NULL, c->bctx);
+                       if (implied_flex_item == NULL) {
+                               css_computed_style_destroy(style);
+                               return false;
+                       }
+                       implied_flex_item->type = BOX_TABLE;
+
+                       if (child->prev == NULL)
+                               flex_container->children = implied_flex_item;
+                       else
+                               child->prev->next = implied_flex_item;
+
+                       implied_flex_item->prev = child->prev;
+
+                       while (child != NULL && (
+                                       child->type == BOX_TABLE_ROW_GROUP ||
+                                       child->type == BOX_TABLE_ROW ||
+                                       child->type == BOX_TABLE_CELL)) {
+                               box_add_child(implied_flex_item, child);
+
+                               next_child = child->next;
+                               child->next = NULL;
+                               child = next_child;
+                       }
+
+                       implied_flex_item->last->next = NULL;
+                       implied_flex_item->next = next_child = child;
+                       if (implied_flex_item->next != NULL)
+                               implied_flex_item->next->prev = 
implied_flex_item;
+                       else
+                               flex_container->last = implied_flex_item;
+                       implied_flex_item->parent = flex_container;
+
+                       if (box_normalise_table(implied_flex_item,
+                                       root, c) == false)
+                               return false;
+                       break;
+               default:
+                       assert(0);
+               }
+       }
+
+       return true;
+}
+
 /**
  * Ensure the box tree is correctly nested by adding and removing nodes.
  *
@@ -104,14 +278,15 @@ static bool box_normalise_inline_container(
  * The tree is modified to satisfy the following:
  * \code
  * parent               permitted child nodes
- * BLOCK, INLINE_BLOCK  BLOCK, INLINE_CONTAINER, TABLE
- * INLINE_CONTAINER     INLINE, INLINE_BLOCK, FLOAT_LEFT, FLOAT_RIGHT, BR, TEXT
+ * BLOCK, INLINE_BLOCK  BLOCK, INLINE_CONTAINER, TABLE, FLEX
+ * FLEX, INLINE_FLEX    BLOCK, INLINE_CONTAINER, TABLE, FLEX
+ * INLINE_CONTAINER     INLINE, INLINE_BLOCK, FLOAT_LEFT, FLOAT_RIGHT, BR, 
TEXT, INLINE_FLEX
  * INLINE, TEXT         none
  * TABLE                at least 1 TABLE_ROW_GROUP
  * TABLE_ROW_GROUP      at least 1 TABLE_ROW
  * TABLE_ROW            at least 1 TABLE_CELL
- * TABLE_CELL           BLOCK, INLINE_CONTAINER, TABLE (same as BLOCK)
- * FLOAT_(LEFT|RIGHT)   exactly 1 BLOCK or TABLE
+ * TABLE_CELL           BLOCK, INLINE_CONTAINER, TABLE, FLEX (same as BLOCK)
+ * FLOAT_(LEFT|RIGHT)   exactly 1 BLOCK, TABLE or FLEX
  * \endcode
  */
 
@@ -147,6 +322,11 @@ bool box_normalise_block(
                next_child = child->next;       /* child may be destroyed */
 
                switch (child->type) {
+               case BOX_FLEX:
+                       /* ok */
+                       if (box_normalise_flex(child, root, c) == false)
+                               return false;
+                       break;
                case BOX_BLOCK:
                        /* ok */
                        if (box_normalise_block(child, root, c) == false)
@@ -162,6 +342,7 @@ bool box_normalise_block(
                        break;
                case BOX_INLINE:
                case BOX_INLINE_END:
+               case BOX_INLINE_FLEX:
                case BOX_INLINE_BLOCK:
                case BOX_FLOAT_LEFT:
                case BOX_FLOAT_RIGHT:
@@ -275,6 +456,7 @@ bool box_normalise_table(
                                return false;
                        }
                        break;
+               case BOX_FLEX:
                case BOX_BLOCK:
                case BOX_INLINE_CONTAINER:
                case BOX_TABLE:
@@ -312,6 +494,7 @@ bool box_normalise_table(
                        row_group->prev = child->prev;
 
                        while (child != NULL && (
+                                       child->type == BOX_FLEX ||
                                        child->type == BOX_BLOCK ||
                                        child->type == BOX_INLINE_CONTAINER ||
                                        child->type == BOX_TABLE ||
@@ -342,6 +525,7 @@ bool box_normalise_table(
                        break;
                case BOX_INLINE:
                case BOX_INLINE_END:
+               case BOX_INLINE_FLEX:
                case BOX_INLINE_BLOCK:
                case BOX_FLOAT_LEFT:
                case BOX_FLOAT_RIGHT:
@@ -634,6 +818,7 @@ bool box_normalise_table_row_group(
                                        c) == false)
                                return false;
                        break;
+               case BOX_FLEX:
                case BOX_BLOCK:
                case BOX_INLINE_CONTAINER:
                case BOX_TABLE:
@@ -667,6 +852,7 @@ bool box_normalise_table_row_group(
                        row->prev = child->prev;
 
                        while (child != NULL && (
+                                       child->type == BOX_FLEX ||
                                        child->type == BOX_BLOCK ||
                                        child->type == BOX_INLINE_CONTAINER ||
                                        child->type == BOX_TABLE ||
@@ -696,6 +882,7 @@ bool box_normalise_table_row_group(
                        break;
                case BOX_INLINE:
                case BOX_INLINE_END:
+               case BOX_INLINE_FLEX:
                case BOX_INLINE_BLOCK:
                case BOX_FLOAT_LEFT:
                case BOX_FLOAT_RIGHT:
@@ -787,6 +974,7 @@ bool box_normalise_table_row(
                                return false;
                        cell = child;
                        break;
+               case BOX_FLEX:
                case BOX_BLOCK:
                case BOX_INLINE_CONTAINER:
                case BOX_TABLE:
@@ -820,6 +1008,7 @@ bool box_normalise_table_row(
                        cell->prev = child->prev;
 
                        while (child != NULL && (
+                                       child->type == BOX_FLEX ||
                                        child->type == BOX_BLOCK ||
                                        child->type == BOX_INLINE_CONTAINER ||
                                        child->type == BOX_TABLE ||
@@ -847,6 +1036,7 @@ bool box_normalise_table_row(
                        break;
                case BOX_INLINE:
                case BOX_INLINE_END:
+               case BOX_INLINE_FLEX:
                case BOX_INLINE_BLOCK:
                case BOX_FLOAT_LEFT:
                case BOX_FLOAT_RIGHT:
@@ -994,6 +1184,11 @@ bool box_normalise_inline_container(
                        if (box_normalise_block(child, root, c) == false)
                                return false;
                        break;
+               case BOX_INLINE_FLEX:
+                       /* ok */
+                       if (box_normalise_flex(child, root, c) == false)
+                               return false;
+                       break;
                case BOX_FLOAT_LEFT:
                case BOX_FLOAT_RIGHT:
                        /* ok */
@@ -1028,6 +1223,7 @@ bool box_normalise_inline_container(
                                box_free(child);
                        }
                        break;
+               case BOX_FLEX:
                case BOX_BLOCK:
                case BOX_INLINE_CONTAINER:
                case BOX_TABLE:
diff --git a/content/handlers/html/layout.c b/content/handlers/html/layout.c
index ab8c83a..0beee03 100644
--- a/content/handlers/html/layout.c
+++ b/content/handlers/html/layout.c
@@ -653,7 +653,8 @@ layout_minmax_line(struct box *first,
                        continue;
                }
 
-               if (b->type == BOX_INLINE_BLOCK) {
+               if (b->type == BOX_INLINE_BLOCK ||
+                   b->type == BOX_INLINE_FLEX) {
                        layout_minmax_block(b, font_func, content);
                        if (min < b->min_width)
                                min = b->min_width;
@@ -1011,7 +1012,9 @@ static void layout_minmax_block(
        bool child_has_height = false;
 
        assert(block->type == BOX_BLOCK ||
+                       block->type == BOX_FLEX ||
                        block->type == BOX_INLINE_BLOCK ||
+                       block->type == BOX_INLINE_FLEX ||
                        block->type == BOX_TABLE_CELL);
 
        /* check if the widths have already been calculated */
@@ -1026,7 +1029,8 @@ static void layout_minmax_block(
 
        /* set whether the minimum width is of any interest for this box */
        if (((block->parent && lh__box_is_float_box(block->parent)) ||
-                       block->type == BOX_INLINE_BLOCK) &&
+                       block->type == BOX_INLINE_BLOCK ||
+                       block->type == BOX_INLINE_FLEX) &&
                        wtype != CSS_WIDTH_SET) {
                /* box shrinks to fit; need minimum width */
                block->flags |= NEED_MIN;
@@ -1112,6 +1116,11 @@ static void layout_minmax_block(
                                child_has_height = true;
                                child->flags |= MAKE_HEIGHT;
                                break;
+                       case BOX_FLEX:
+                               layout_minmax_block(child, font_func, content);
+                               child_has_height = true;
+                               child->flags |= MAKE_HEIGHT;
+                               break;
                        default:
                                assert(0);
                        }
@@ -2034,6 +2043,101 @@ static void layout_move_children(struct box *box, int 
x, int y)
        }
 }
 
+static inline bool layout_flex__main_is_horizontal(struct box *flex)
+{
+       const css_computed_style *style = flex->style;
+
+       assert(style != NULL);
+
+       switch (css_computed_flex_direction(style)) {
+       default:                        /* Fallthrough. */
+       case CSS_FLEX_DIRECTION_ROW:    /* Fallthrough. */
+       case CSS_FLEX_DIRECTION_ROW_REVERSE:
+               return true;
+       case CSS_FLEX_DIRECTION_COLUMN: /* Fallthrough. */
+       case CSS_FLEX_DIRECTION_COLUMN_REVERSE:
+               return false;
+       }
+}
+
+/**
+ * Layout a flex container.
+ *
+ * \param[in] flex             table to layout
+ * \param[in] available_width  width of containing block
+ * \param[in] content          memory pool for any new boxes
+ * \return  true on success, false on memory exhaustion
+ */
+static bool layout_flex(struct box *flex, int available_width,
+               html_content *content)
+{
+       bool main_is_horizontal = layout_flex__main_is_horizontal(flex);
+       int max_width, min_width, max_height, min_height;
+       const nscss_len_ctx *len_ctx = &content->len_ctx;
+       struct box_border *border = flex->border;
+       int *padding = flex->padding;
+       int *margin = flex->margin;
+       int *len_main, *len_cross;
+       unsigned n_children;
+       struct flex_item_data {
+               int main_size;
+       } *flex_item;
+
+       assert(flex->width != UNKNOWN_WIDTH);
+       assert(flex->width != AUTO);
+
+       layout_find_dimensions(len_ctx, available_width, -1, flex, flex->style,
+                       &flex->width, &flex->height, &max_width, &min_width,
+                       &max_height, &min_height, margin, padding, border);
+
+       if (flex->width == AUTO) {
+               int w = available_width;
+               int fixed = 0;
+               float frac = 0;
+
+               calculate_mbp_width(len_ctx, flex->style, LEFT,
+                               false, true, true, &fixed, &frac);
+               calculate_mbp_width(len_ctx, flex->style, RIGHT,
+                               false, true, true, &fixed, &frac);
+
+               w -= frac * available_width + fixed;
+               flex->width = w > 0 ? w : 0;
+       }
+
+       if (max_width >= 0 && flex->width > max_width) {
+               flex->width = max_width;
+       }
+       if (min_width >  0 && flex->width < min_width) {
+               flex->width = min_width;
+       }
+
+       if (flex->height != AUTO) {
+               if (max_height >= 0 && flex->height > max_height) {
+                       flex->height = max_height;
+               }
+               if (min_height >  0 && flex->height < min_height) {
+                       flex->height = min_height;
+               }
+       }
+
+       if (main_is_horizontal) {
+               len_main = &flex->width;
+               len_cross = &flex->height;
+       } else {
+               len_main = &flex->height;
+               len_cross = &flex->width;
+       }
+
+       flex_item = calloc(box_count_children(flex), sizeof(*flex_item));
+       if (flex_item == false) {
+               return false;
+       }
+
+
+       free(flex_item);
+       return true;
+}
+
 
 /**
  * Layout a table.
@@ -4039,7 +4143,9 @@ layout_block_context(struct box *block,
                enum css_overflow_e overflow_x = CSS_OVERFLOW_VISIBLE;
                enum css_overflow_e overflow_y = CSS_OVERFLOW_VISIBLE;
 
-               assert(box->type == BOX_BLOCK || box->type == BOX_TABLE ||
+               assert(box->type == BOX_BLOCK ||
+                               box->type == BOX_FLEX ||
+                               box->type == BOX_TABLE ||
                                box->type == BOX_INLINE_CONTAINER);
 
                /* Tables are laid out before being positioned, because the
@@ -4123,7 +4229,7 @@ layout_block_context(struct box *block,
                                layout_block_add_scrollbar(box, RIGHT);
                                layout_block_add_scrollbar(box, BOTTOM);
                        }
-               } else if (box->type == BOX_TABLE) {
+               } else if (box->type == BOX_TABLE || box->type == BOX_FLEX) {
                        if (box->style != NULL) {
                                enum css_width_e wtype;
                                css_fixed width = 0;
@@ -4156,11 +4262,21 @@ layout_block_context(struct box *block,
                                                x1;
                                }
                        }
-                       if (!layout_table(box, box->parent->width - lm - rm,
-                                       content))
-                               return false;
-                       layout_solve_width(box, box->parent->width, box->width,
-                                       lm, rm, -1, -1);
+                       if (box->type == BOX_TABLE) {
+                               if (!layout_table(box,
+                                               box->parent->width - lm - rm,
+                                               content))
+                                       return false;
+                               layout_solve_width(box,
+                                               box->parent->width, box->width,
+                                               lm, rm, -1, -1);
+                       } else {
+                               if (!layout_flex(box,
+                                               box->parent->width - lm - rm,
+                                               content)) {
+                                       return false;
+                               }
+                       }
                }
 
                /* Position box: horizontal. */
@@ -4176,6 +4292,7 @@ layout_block_context(struct box *block,
 
                /* Vertical margin */
                if (((box->type == BOX_BLOCK && (box->flags & HAS_HEIGHT)) ||
+                    box->type == BOX_FLEX ||
                     box->type == BOX_TABLE ||
                     (box->type == BOX_INLINE_CONTAINER &&
                      !box_is_first_child(box)) ||


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

    Layout: Constify box through layout_find_dimensions().

diff --git a/content/handlers/html/layout.c b/content/handlers/html/layout.c
index 7d2739f..ab8c83a 100644
--- a/content/handlers/html/layout.c
+++ b/content/handlers/html/layout.c
@@ -1278,7 +1278,7 @@ static void
 layout_find_dimensions(const nscss_len_ctx *len_ctx,
                       int available_width,
                       int viewport_height,
-                      struct box *box,
+                      const struct box *box,
                       const css_computed_style *style,
                       int *width,
                       int *height,


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

    Layout: Constify box through layout_handle_box_sizing().

diff --git a/content/handlers/html/layout.c b/content/handlers/html/layout.c
index f7653f9..7d2739f 100644
--- a/content/handlers/html/layout.c
+++ b/content/handlers/html/layout.c
@@ -1227,7 +1227,7 @@ static void layout_minmax_block(
  */
 static void layout_handle_box_sizing(
                const nscss_len_ctx *len_ctx,
-               struct box *box,
+               const struct box *box,
                int available_width,
                bool setwidth,
                int *dimension)


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

    layout: Add helpers for various box type checks.

diff --git a/content/handlers/html/layout.c b/content/handlers/html/layout.c
index 28a8465..f7653f9 100644
--- a/content/handlers/html/layout.c
+++ b/content/handlers/html/layout.c
@@ -119,6 +119,50 @@ static inline bool lh__have_border(
        return border_style_funcs[side](style) != CSS_BORDER_STYLE_NONE;
 }
 
+/** Layout helper: Check whether box is a float. */
+static inline bool lh__box_is_float_box(const struct box *b)
+{
+       return b->type == BOX_FLOAT_LEFT ||
+              b->type == BOX_FLOAT_RIGHT;
+}
+
+/** Layout helper: Check whether box takes part in inline flow. */
+static inline bool lh__box_is_inline_flow(const struct box *b)
+{
+       return b->type == BOX_INLINE ||
+              b->type == BOX_INLINE_BLOCK ||
+              b->type == BOX_TEXT ||
+              b->type == BOX_INLINE_END;
+}
+
+/** Layout helper: Check whether box is inline level. (Includes BR.) */
+static inline bool lh__box_is_inline_level(const struct box *b)
+{
+       return lh__box_is_inline_flow(b) ||
+              b->type == BOX_BR;
+}
+
+/** Layout helper: Check whether box is inline level. (Includes BR, floats.) */
+static inline bool lh__box_is_inline_content(const struct box *b)
+{
+       return lh__box_is_float_box(b) ||
+              lh__box_is_inline_level(b);
+}
+
+/** Layout helper: Check whether box is an object. */
+static inline bool lh__box_is_object(const struct box *b)
+{
+       return b->object ||
+              (b->flags & (IFRAME | REPLACE_DIM));
+}
+
+/** Layout helper: Check whether box is replaced. */
+static inline bool lh__box_is_replace(const struct box *b)
+{
+       return b->gadget ||
+              lh__box_is_object(b);
+}
+
 /** Array of per-side access functions for computed style border colors. */
 static const css_border_color_func border_color_funcs[4] = {
        [TOP]    = css_computed_border_top_color,
@@ -584,11 +628,7 @@ layout_minmax_line(struct box *first,
                css_fixed value = 0;
                css_unit unit = CSS_UNIT_PX;
 
-               assert(b->type == BOX_INLINE || b->type == BOX_INLINE_BLOCK ||
-                               b->type == BOX_FLOAT_LEFT ||
-                               b->type == BOX_FLOAT_RIGHT ||
-                               b->type == BOX_BR || b->type == BOX_TEXT ||
-                               b->type == BOX_INLINE_END);
+               assert(lh__box_is_inline_content(b));
 
                NSLOG(layout, DEBUG, "%p: min %i, max %i", b, min, max);
 
@@ -597,7 +637,7 @@ layout_minmax_line(struct box *first,
                        break;
                }
 
-               if (b->type == BOX_FLOAT_LEFT || b->type == BOX_FLOAT_RIGHT) {
+               if (lh__box_is_float_box(b)) {
                        assert(b->children);
                        if (b->children->type == BOX_BLOCK)
                                layout_minmax_block(b->children, font_func,
@@ -664,8 +704,7 @@ layout_minmax_line(struct box *first,
                        continue;
                }
 
-               if (!b->object && !(b->flags & IFRAME) && !b->gadget &&
-                               !(b->flags & REPLACE_DIM)) {
+               if (lh__box_is_replace(b) == false) {
                        /* inline non-replaced, 10.3.1 and 10.6.1 */
                        bool no_wrap_box;
                        if (!b->text)
@@ -986,8 +1025,7 @@ static void layout_minmax_block(
        }
 
        /* set whether the minimum width is of any interest for this box */
-       if (((block->parent && (block->parent->type == BOX_FLOAT_LEFT ||
-                       block->parent->type == BOX_FLOAT_RIGHT)) ||
+       if (((block->parent && lh__box_is_float_box(block->parent)) ||
                        block->type == BOX_INLINE_BLOCK) &&
                        wtype != CSS_WIDTH_SET) {
                /* box shrinks to fit; need minimum width */
@@ -3183,20 +3221,14 @@ layout_line(struct box *first,
        for (x = 0, b = first; x <= x1 - x0 && b != 0; b = b->next) {
                int min_width, max_width, min_height, max_height;
 
-               assert(b->type == BOX_INLINE || b->type == BOX_INLINE_BLOCK ||
-                               b->type == BOX_FLOAT_LEFT ||
-                               b->type == BOX_FLOAT_RIGHT ||
-                               b->type == BOX_BR || b->type == BOX_TEXT ||
-                               b->type == BOX_INLINE_END);
-
+               assert(lh__box_is_inline_content(b));
 
                NSLOG(layout, DEBUG,  "pass 1: b %p, x %i", b, x);
 
-
                if (b->type == BOX_BR)
                        break;
 
-               if (b->type == BOX_FLOAT_LEFT || b->type == BOX_FLOAT_RIGHT)
+               if (lh__box_is_float_box(b))
                        continue;
                if (b->type == BOX_INLINE_BLOCK &&
                                (css_computed_position(b->style) ==
@@ -3262,8 +3294,7 @@ layout_line(struct box *first,
                        continue;
                }
 
-               if (!b->object && !(b->flags & IFRAME) && !b->gadget &&
-                               !(b->flags & REPLACE_DIM)) {
+               if (lh__box_is_replace(b) == false) {
                        /* inline non-replaced, 10.3.1 and 10.6.1 */
                        b->height = line_height(&content->len_ctx,
                                        b->style ? b->style :
@@ -3421,10 +3452,7 @@ layout_line(struct box *first,
                                                CSS_POSITION_FIXED)) {
                        b->x = x + space_after;
 
-               } else if (b->type == BOX_INLINE ||
-                               b->type == BOX_INLINE_BLOCK ||
-                               b->type == BOX_TEXT ||
-                               b->type == BOX_INLINE_END) {
+               } else if (lh__box_is_inline_flow(b)) {
                        assert(b->width != UNKNOWN_WIDTH);
 
                        x_previous = x;
@@ -3763,9 +3791,7 @@ layout_line(struct box *first,
                        d->y = *y;
                        continue;
                } else if ((d->type == BOX_INLINE &&
-                               ((d->object || d->gadget) == false) &&
-                               !(d->flags & IFRAME) &&
-                               !(d->flags & REPLACE_DIM)) ||
+                               lh__box_is_replace(d) == false) ||
                                d->type == BOX_BR ||
                                d->type == BOX_TEXT ||
                                d->type == BOX_INLINE_END) {
@@ -3886,8 +3912,7 @@ static bool layout_inline_container(struct box 
*inline_container, int width,
                                whitespace == CSS_WHITE_SPACE_PRE_WRAP);
                }
 
-               if ((!c->object && !(c->flags & REPLACE_DIM) &&
-                               !(c->flags & IFRAME) &&
+               if ((lh__box_is_object(c) == false &&
                                c->text && (c->length || is_pre)) ||
                                c->type == BOX_BR)
                        has_text_children = true;
@@ -4066,8 +4091,7 @@ layout_block_context(struct box *block,
                lm = rm = 0;
 
                if (box->type == BOX_BLOCK || box->flags & IFRAME) {
-                       if (!box->object && !(box->flags & IFRAME) &&
-                                       !(box->flags & REPLACE_DIM) &&
+                       if (lh__box_is_object(box) == false &&
                                        box->style &&
                                        (overflow_x != CSS_OVERFLOW_VISIBLE ||
                                         overflow_y != CSS_OVERFLOW_VISIBLE)) {


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

    layout: Add helper for checking if a style has a border on a side.

diff --git a/content/handlers/html/layout.c b/content/handlers/html/layout.c
index c374297..28a8465 100644
--- a/content/handlers/html/layout.c
+++ b/content/handlers/html/layout.c
@@ -111,6 +111,14 @@ static const css_border_style_func border_style_funcs[4] = 
{
        [LEFT]   = css_computed_border_left_style,
 };
 
+/** Layout helper: Check for CSS border on given side. */
+static inline bool lh__have_border(
+               enum box_side side,
+               const css_computed_style *style)
+{
+       return border_style_funcs[side](style) != CSS_BORDER_STYLE_NONE;
+}
+
 /** Array of per-side access functions for computed style border colors. */
 static const css_border_color_func border_color_funcs[4] = {
        [TOP]    = css_computed_border_top_color,
@@ -302,8 +310,7 @@ calculate_mbp_width(const nscss_len_ctx *len_ctx,
 
        /* border */
        if (border) {
-               if (border_style_funcs[side](style) !=
-                               CSS_BORDER_STYLE_NONE) {
+               if (lh__have_border(side, style)) {
                        border_width_funcs[side](style, &value, &unit);
 
                        *fixed += FIXTOINT(nscss_len2px(len_ctx,


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

    layout: Drop redundant else block.

diff --git a/content/handlers/html/layout.c b/content/handlers/html/layout.c
index 611c778..c374297 100644
--- a/content/handlers/html/layout.c
+++ b/content/handlers/html/layout.c
@@ -4593,8 +4593,6 @@ layout_absolute(struct box *box,
                                containing_block->padding[RIGHT];
                containing_block->height += containing_block->padding[TOP] +
                                containing_block->padding[BOTTOM];
-       } else {
-               /** \todo inline containers */
        }
 
        layout_compute_offsets(&content->len_ctx, box, containing_block,


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

    CSS: Simplify css display to box type conversion.

diff --git a/content/handlers/css/dump.c b/content/handlers/css/dump.c
index b12e1d9..3d17b36 100644
--- a/content/handlers/css/dump.c
+++ b/content/handlers/css/dump.c
@@ -823,7 +823,7 @@ void nscss_dump_computed_style(FILE *stream, const 
css_computed_style *style)
        }
 
        /* display */
-       val = ns_computed_display_static(style);
+       val = css_computed_display_static(style);
        switch (val) {
        case CSS_DISPLAY_INLINE:
                fprintf(stream, "display: inline ");
@@ -873,6 +873,12 @@ void nscss_dump_computed_style(FILE *stream, const 
css_computed_style *style)
        case CSS_DISPLAY_NONE:
                fprintf(stream, "display: none ");
                break;
+       case CSS_DISPLAY_FLEX:
+               fprintf(stream, "display: flex ");
+               break;
+       case CSS_DISPLAY_INLINE_FLEX:
+               fprintf(stream, "display: inline-flax ");
+               break;
        default:
                break;
        }
diff --git a/content/handlers/css/utils.h b/content/handlers/css/utils.h
index e35a660..05ab738 100644
--- a/content/handlers/css/utils.h
+++ b/content/handlers/css/utils.h
@@ -105,42 +105,6 @@ static inline css_fixed nscss_pixels_physical_to_css(
                        nscss_screen_dpi);
 }
 
-/**
- * Temporary helper wrappers for for libcss computed style getter, while
- * we don't support flexbox related property values.
- */
-
-static inline uint8_t ns_computed_display(
-               const css_computed_style *style, bool root)
-{
-       uint8_t value = css_computed_display(style, root);
-
-       if (value == CSS_DISPLAY_FLEX) {
-               return CSS_DISPLAY_BLOCK;
-
-       } else if (value == CSS_DISPLAY_INLINE_FLEX) {
-               return CSS_DISPLAY_INLINE_BLOCK;
-       }
-
-       return value;
-}
-
-
-static inline uint8_t ns_computed_display_static(
-               const css_computed_style *style)
-{
-       uint8_t value = css_computed_display_static(style);
-
-       if (value == CSS_DISPLAY_FLEX) {
-               return CSS_DISPLAY_BLOCK;
-
-       } else if (value == CSS_DISPLAY_INLINE_FLEX) {
-               return CSS_DISPLAY_INLINE_BLOCK;
-       }
-
-       return value;
-}
-
 
 static inline uint8_t ns_computed_min_height(
                const css_computed_style *style,
diff --git a/content/handlers/html/box_construct.c 
b/content/handlers/html/box_construct.c
index 6271405..f545785 100644
--- a/content/handlers/html/box_construct.c
+++ b/content/handlers/html/box_construct.c
@@ -213,23 +213,25 @@ nserror cancel_dom_to_box(void *box_conversion_context)
 /* mapping from CSS display to box type
  * this table must be in sync with libcss' css_display enum */
 static const box_type box_map[] = {
-       0, /*CSS_DISPLAY_INHERIT,*/
-       BOX_INLINE, /*CSS_DISPLAY_INLINE,*/
-       BOX_BLOCK, /*CSS_DISPLAY_BLOCK,*/
-       BOX_BLOCK, /*CSS_DISPLAY_LIST_ITEM,*/
-       BOX_INLINE, /*CSS_DISPLAY_RUN_IN,*/
-       BOX_INLINE_BLOCK, /*CSS_DISPLAY_INLINE_BLOCK,*/
-       BOX_TABLE, /*CSS_DISPLAY_TABLE,*/
-       BOX_TABLE, /*CSS_DISPLAY_INLINE_TABLE,*/
-       BOX_TABLE_ROW_GROUP, /*CSS_DISPLAY_TABLE_ROW_GROUP,*/
-       BOX_TABLE_ROW_GROUP, /*CSS_DISPLAY_TABLE_HEADER_GROUP,*/
-       BOX_TABLE_ROW_GROUP, /*CSS_DISPLAY_TABLE_FOOTER_GROUP,*/
-       BOX_TABLE_ROW, /*CSS_DISPLAY_TABLE_ROW,*/
-       BOX_NONE, /*CSS_DISPLAY_TABLE_COLUMN_GROUP,*/
-       BOX_NONE, /*CSS_DISPLAY_TABLE_COLUMN,*/
-       BOX_TABLE_CELL, /*CSS_DISPLAY_TABLE_CELL,*/
-       BOX_INLINE, /*CSS_DISPLAY_TABLE_CAPTION,*/
-       BOX_NONE /*CSS_DISPLAY_NONE*/
+       BOX_BLOCK,           /* CSS_DISPLAY_INHERIT */
+       BOX_INLINE,          /* CSS_DISPLAY_INLINE */
+       BOX_BLOCK,           /* CSS_DISPLAY_BLOCK */
+       BOX_BLOCK,           /* CSS_DISPLAY_LIST_ITEM */
+       BOX_INLINE,          /* CSS_DISPLAY_RUN_IN */
+       BOX_INLINE_BLOCK,    /* CSS_DISPLAY_INLINE_BLOCK */
+       BOX_TABLE,           /* CSS_DISPLAY_TABLE */
+       BOX_TABLE,           /* CSS_DISPLAY_INLINE_TABLE */
+       BOX_TABLE_ROW_GROUP, /* CSS_DISPLAY_TABLE_ROW_GROUP */
+       BOX_TABLE_ROW_GROUP, /* CSS_DISPLAY_TABLE_HEADER_GROUP */
+       BOX_TABLE_ROW_GROUP, /* CSS_DISPLAY_TABLE_FOOTER_GROUP */
+       BOX_TABLE_ROW,       /* CSS_DISPLAY_TABLE_ROW */
+       BOX_NONE,            /* CSS_DISPLAY_TABLE_COLUMN_GROUP */
+       BOX_NONE,            /* CSS_DISPLAY_TABLE_COLUMN */
+       BOX_TABLE_CELL,      /* CSS_DISPLAY_TABLE_CELL */
+       BOX_INLINE,          /* CSS_DISPLAY_TABLE_CAPTION */
+       BOX_NONE,            /* CSS_DISPLAY_NONE */
+       BOX_BLOCK,           /* CSS_DISPLAY_FLEX */
+       BOX_INLINE_BLOCK,    /* CSS_DISPLAY_INLINE_FLEX */
 };
 
 /* Exported function, see box.h */
@@ -637,7 +639,7 @@ static void box_construct_generate(dom_node *n, 
html_content *content,
        }
 
        /* create box for this element */
-       computed_display = ns_computed_display(style, box_is_root(n));
+       computed_display = css_computed_display(style, box_is_root(n));
        if (computed_display == CSS_DISPLAY_BLOCK ||
                        computed_display == CSS_DISPLAY_TABLE) {
                /* currently only support block level boxes */
@@ -650,7 +652,7 @@ static void box_construct_generate(dom_node *n, 
html_content *content,
                }
 
                /* set box type from computed display */
-               gen->type = box_map[ns_computed_display(
+               gen->type = box_map[css_computed_display(
                                style, box_is_root(n))];
 
                box_add_child(box, gen);
@@ -759,6 +761,7 @@ bool box_construct_element(struct box_construct_ctx *ctx,
 {
        dom_string *title0, *s;
        lwc_string *id = NULL;
+       enum css_display_e css_display;
        struct box *box = NULL, *old_box;
        css_select_results *styles = NULL;
        struct element_entry *element;
@@ -858,16 +861,15 @@ bool box_construct_element(struct box_construct_ctx *ctx,
                dom_string_unref(s);
        }
 
+       css_display = css_computed_display_static(box->style);
+
        /* Set box type from computed display */
        if ((css_computed_position(box->style) == CSS_POSITION_ABSOLUTE ||
-                       css_computed_position(box->style) ==
-                                       CSS_POSITION_FIXED) &&
-                       (ns_computed_display_static(box->style) ==
-                                       CSS_DISPLAY_INLINE ||
-                        ns_computed_display_static(box->style) ==
-                                       CSS_DISPLAY_INLINE_BLOCK ||
-                        ns_computed_display_static(box->style) ==
-                                       CSS_DISPLAY_INLINE_TABLE)) {
+            css_computed_position(box->style) == CSS_POSITION_FIXED) &&
+                       (css_display == CSS_DISPLAY_INLINE ||
+                        css_display == CSS_DISPLAY_INLINE_BLOCK ||
+                        css_display == CSS_DISPLAY_INLINE_TABLE ||
+                        css_display == CSS_DISPLAY_INLINE_FLEX)) {
                /* Special case for absolute positioning: make absolute inlines
                 * into inline block so that the boxes are constructed in an
                 * inline container as if they were not absolutely positioned.
@@ -879,7 +881,7 @@ bool box_construct_element(struct box_construct_ctx *ctx,
                box->type = BOX_BLOCK;
        } else {
                /* Normal mapping */
-               box->type = box_map[ns_computed_display(box->style,
+               box->type = box_map[css_computed_display(box->style,
                                props.node_is_root)];
        }
 
@@ -907,7 +909,7 @@ bool box_construct_element(struct box_construct_ctx *ctx,
                                box->styles->styles[CSS_PSEUDO_ELEMENT_BEFORE]);
        }
 
-       if (box->type == BOX_NONE || (ns_computed_display(box->style,
+       if (box->type == BOX_NONE || (css_computed_display(box->style,
                        props.node_is_root) == CSS_DISPLAY_NONE &&
                        props.node_is_root == false)) {
                css_select_results_destroy(styles);
@@ -999,7 +1001,7 @@ bool box_construct_element(struct box_construct_ctx *ctx,
 
                box_add_child(props.inline_container, box);
        } else {
-               if (ns_computed_display(box->style, props.node_is_root) ==
+               if (css_computed_display(box->style, props.node_is_root) ==
                                CSS_DISPLAY_LIST_ITEM) {
                        /* List item: compute marker */
                        if (box_construct_marker(box, props.title, ctx,
@@ -1593,7 +1595,7 @@ bool box_image(BOX_SPECIAL_PARAMS)
        css_unit wunit = CSS_UNIT_PX;
        css_unit hunit = CSS_UNIT_PX;
 
-       if (box->style && ns_computed_display(box->style,
+       if (box->style && css_computed_display(box->style,
                        box_is_root(n)) == CSS_DISPLAY_NONE)
                return true;
 
@@ -1700,7 +1702,7 @@ bool box_object(BOX_SPECIAL_PARAMS)
        dom_node *c;
        dom_exception err;
 
-       if (box->style && ns_computed_display(box->style,
+       if (box->style && css_computed_display(box->style,
                        box_is_root(n)) == CSS_DISPLAY_NONE)
                return true;
 
@@ -2357,7 +2359,7 @@ bool box_iframe(BOX_SPECIAL_PARAMS)
        struct content_html_iframe *iframe;
        int i;
 
-       if (box->style && ns_computed_display(box->style,
+       if (box->style && css_computed_display(box->style,
                        box_is_root(n)) == CSS_DISPLAY_NONE)
                return true;
 
@@ -2601,7 +2603,7 @@ bool box_input(BOX_SPECIAL_PARAMS)
                gadget->type = GADGET_IMAGE;
 
                if (box->style &&
-                   ns_computed_display(box->style,
+                   css_computed_display(box->style,
                                box_is_root(n)) != CSS_DISPLAY_NONE &&
                    nsoption_bool(foreground_images) == true) {
                        dom_string *s;
@@ -2941,7 +2943,7 @@ bool box_embed(BOX_SPECIAL_PARAMS)
        dom_string *src;
        dom_exception err;
 
-       if (box->style && ns_computed_display(box->style,
+       if (box->style && css_computed_display(box->style,
                        box_is_root(n)) == CSS_DISPLAY_NONE)
                return true;
 


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


-- 
NetSurf Browser
_______________________________________________
netsurf-commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to