summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Drake <tlsa@netsurf-browser.org>2022-11-19 15:57:23 +0000
committerMichael Drake <mdrake.unique@gmail.com>2022-12-14 22:53:35 +0000
commit8d4176e4d46cc4e37d2f9ee02e9508aa4a641b54 (patch)
tree76d57bc07134027450dd2aac2f4253efb958c22e
parent6da16e564820e2a958a7266f05fb98b4f252dc49 (diff)
downloadnetsurf-8d4176e4d46cc4e37d2f9ee02e9508aa4a641b54.tar.gz
netsurf-8d4176e4d46cc4e37d2f9ee02e9508aa4a641b54.tar.bz2
html: layout: flex: Hoist item placement out of line resolver
-rw-r--r--content/handlers/html/layout_flex.c100
1 files changed, 50 insertions, 50 deletions
diff --git a/content/handlers/html/layout_flex.c b/content/handlers/html/layout_flex.c
index a14952822..355ae93ee 100644
--- a/content/handlers/html/layout_flex.c
+++ b/content/handlers/html/layout_flex.c
@@ -549,54 +549,6 @@ static inline void layout_flex__distribute_free_main(
}
}
-static bool layout_flex__place_line_items_main(
- struct flex_ctx *ctx,
- struct flex_line_data *line)
-{
- enum box_side main_start = ctx->horizontal ? LEFT : TOP;
- size_t item_count = line->first + line->count;
- int main_pos = ctx->flex->padding[main_start];
-
- for (size_t i = line->first; i < item_count; i++) {
- struct flex_item_data *item = &ctx->item.data[i];
- struct box *b = item->box;
- int *box_pos_main;
-
- if (ctx->horizontal) {
- b->width = item->target_main_size -
- lh__delta_outer_width(b);
-
- if (!layout_flex_item(ctx, item, b->width)) {
- return false;
- }
- }
-
- box_pos_main = ctx->horizontal ? &b->x : &b->y;
- *box_pos_main = main_pos + lh__non_auto_margin(b, main_start) +
- b->border[main_start].width;
-
- if (!lh__box_is_absolute(b)) {
- int cross_size;
- int *box_size_main;
- int *box_size_cross;
-
- box_size_main = lh__box_size_main(ctx->horizontal, b);
- box_size_cross = lh__box_size_cross(ctx->horizontal, b);
-
- main_pos += *box_size_main + lh__delta_outer_main(
- ctx->flex, b);
-
- cross_size = *box_size_cross + lh__delta_outer_cross(
- ctx->flex, b);
- if (line->cross_size < cross_size) {
- line->cross_size = cross_size;
- }
- }
- }
-
- return true;
-}
-
/** 9.7. Resolving Flexible Lengths */
static bool layout_flex__resolve_line(
struct flex_ctx *ctx,
@@ -683,8 +635,52 @@ static bool layout_flex__resolve_line(
}
}
- if (!layout_flex__place_line_items_main(ctx, line)) {
- return false;
+ return true;
+}
+
+static bool layout_flex__place_line_items_main(
+ struct flex_ctx *ctx,
+ struct flex_line_data *line)
+{
+ enum box_side main_start = ctx->horizontal ? LEFT : TOP;
+ size_t item_count = line->first + line->count;
+ int main_pos = ctx->flex->padding[main_start];
+
+ for (size_t i = line->first; i < item_count; i++) {
+ struct flex_item_data *item = &ctx->item.data[i];
+ struct box *b = item->box;
+ int *box_pos_main;
+
+ if (ctx->horizontal) {
+ b->width = item->target_main_size -
+ lh__delta_outer_width(b);
+
+ if (!layout_flex_item(ctx, item, b->width)) {
+ return false;
+ }
+ }
+
+ box_pos_main = ctx->horizontal ? &b->x : &b->y;
+ *box_pos_main = main_pos + lh__non_auto_margin(b, main_start) +
+ b->border[main_start].width;
+
+ if (!lh__box_is_absolute(b)) {
+ int cross_size;
+ int *box_size_main;
+ int *box_size_cross;
+
+ box_size_main = lh__box_size_main(ctx->horizontal, b);
+ box_size_cross = lh__box_size_cross(ctx->horizontal, b);
+
+ main_pos += *box_size_main + lh__delta_outer_main(
+ ctx->flex, b);
+
+ cross_size = *box_size_cross + lh__delta_outer_cross(
+ ctx->flex, b);
+ if (line->cross_size < cross_size) {
+ line->cross_size = cross_size;
+ }
+ }
}
return true;
@@ -714,6 +710,10 @@ static bool layout_flex__collect_items_into_lines(
return false;
}
+ if (!layout_flex__place_line_items_main(ctx, line)) {
+ return false;
+ }
+
ctx->cross_size += line->cross_size;
if (ctx->main_size < line->main_size) {
ctx->main_size = line->main_size;