summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Drake <tlsa@netsurf-browser.org>2022-10-19 10:58:39 +0100
committerMichael Drake <tlsa@netsurf-browser.org>2022-10-23 17:25:52 +0100
commit628d6db75932a61ebf9a3f4513f5a9d209bd9515 (patch)
tree046e21da5cc40b0ffd11815bb6ee7d9cd9403c2b
parent28f872e858cf42e66cd198636ec7761e91800033 (diff)
downloadnetsurf-628d6db75932a61ebf9a3f4513f5a9d209bd9515.tar.gz
netsurf-628d6db75932a61ebf9a3f4513f5a9d209bd9515.tar.bz2
html: layout: Add layout helper for dealing with auto margins
-rw-r--r--content/handlers/html/layout_flex.c8
-rw-r--r--content/handlers/html/layout_internal.h21
2 files changed, 17 insertions, 12 deletions
diff --git a/content/handlers/html/layout_flex.c b/content/handlers/html/layout_flex.c
index 949953626..12ecfe603 100644
--- a/content/handlers/html/layout_flex.c
+++ b/content/handlers/html/layout_flex.c
@@ -564,14 +564,14 @@ static bool layout_flex__resolve_line_horizontal(
height = b->height + lh__delta_outer_height(b);
b->y = ctx->cross_size +
- b->margin[TOP] +
+ lh__non_auto_margin(b, TOP) +
b->border[TOP].width +
b->padding[TOP];
if (line->cross_size < height) {
line->cross_size = height;
}
- b->x = x + b->margin[LEFT] +
+ b->x = x + lh__non_auto_margin(b, LEFT) +
b->border[LEFT].width +
b->padding[LEFT];
x += b->width + lh__delta_outer_width(b);
@@ -596,14 +596,14 @@ static bool layout_flex__resolve_line_vertical(
width = b->width + lh__delta_outer_width(b);
b->x = ctx->cross_size +
- b->margin[LEFT] +
+ lh__non_auto_margin(b, LEFT) +
b->border[LEFT].width +
b->padding[LEFT];
if (line->cross_size < width) {
line->cross_size = width;
}
- b->y = y + b->margin[TOP] +
+ b->y = y + lh__non_auto_margin(b, TOP) +
b->border[TOP].width +
b->padding[TOP];
y += b->height + lh__delta_outer_height(b);
diff --git a/content/handlers/html/layout_internal.h b/content/handlers/html/layout_internal.h
index 7934dddbc..2cbd1ee3c 100644
--- a/content/handlers/html/layout_internal.h
+++ b/content/handlers/html/layout_internal.h
@@ -183,24 +183,29 @@ static inline bool layout_flex__main_is_horizontal(const struct box *flex)
}
}
+static inline int lh__non_auto_margin(const struct box *b, enum box_side side)
+{
+ return (b->margin[side] == AUTO) ? 0 : b->margin[side];
+}
+
static inline int lh__delta_outer_height(const struct box *b)
{
- return b->margin[TOP] +
- b->margin[BOTTOM] +
+ return b->padding[TOP] +
+ b->padding[BOTTOM] +
b->border[TOP].width +
b->border[BOTTOM].width +
- b->padding[TOP] +
- b->padding[BOTTOM];
+ lh__non_auto_margin(b, TOP) +
+ lh__non_auto_margin(b, BOTTOM);
}
static inline int lh__delta_outer_width(const struct box *b)
{
- return b->margin[LEFT] +
- b->margin[RIGHT] +
+ return b->padding[LEFT] +
+ b->padding[RIGHT] +
b->border[LEFT].width +
b->border[RIGHT].width +
- b->padding[LEFT] +
- b->padding[RIGHT];
+ lh__non_auto_margin(b, LEFT) +
+ lh__non_auto_margin(b, RIGHT);
}
static inline int lh__delta_outer_main(const struct box *flex)