summaryrefslogtreecommitdiff
path: root/content
diff options
context:
space:
mode:
authorMichael Drake <tlsa@netsurf-browser.org>2022-10-31 22:03:25 +0000
committerMichael Drake <mdrake.unique@gmail.com>2022-11-02 20:16:41 +0000
commitb91d61b89f1b3eba0bd523bc8b5beadf68a3c952 (patch)
tree427b17ba1a0d89a63bcd7082409e357afce40775 /content
parentd0b1bcb01a549a885007862112aeaa8b09ddf40d (diff)
downloadnetsurf-b91d61b89f1b3eba0bd523bc8b5beadf68a3c952.tar.gz
netsurf-b91d61b89f1b3eba0bd523bc8b5beadf68a3c952.tar.bz2
html: layout: flex: Compare line main size with available main
When deciding whether to use the grow or shrink flex factor we we using the available width, rather than the space available in the main direction.
Diffstat (limited to 'content')
-rw-r--r--content/handlers/html/layout_flex.c69
1 files changed, 35 insertions, 34 deletions
diff --git a/content/handlers/html/layout_flex.c b/content/handlers/html/layout_flex.c
index 6731e79bd..9242a831f 100644
--- a/content/handlers/html/layout_flex.c
+++ b/content/handlers/html/layout_flex.c
@@ -383,15 +383,15 @@ static inline void layout_flex__item_freeze(
item->box, item->target_main_size);
}
-static inline int layout_flex__remaining_free_space(
+static inline int layout_flex__remaining_free_main(
struct flex_ctx *ctx,
struct flex_line_data *line,
css_fixed *unfrozen_factor_sum,
- int initial_free_space,
- int available_space,
+ int initial_free_main,
+ int available_main,
bool grow)
{
- int remaining_free_space = available_space;
+ int remaining_free_main = available_main;
size_t item_count = line->first + line->count;
*unfrozen_factor_sum = 0;
@@ -400,9 +400,9 @@ static inline int layout_flex__remaining_free_space(
struct flex_item_data *item = &ctx->item.data[i];
if (item->freeze) {
- remaining_free_space -= item->target_main_size;
+ remaining_free_main -= item->target_main_size;
} else {
- remaining_free_space -= item->base_size;
+ remaining_free_main -= item->base_size;
*unfrozen_factor_sum += grow ?
item->grow : item->shrink;
@@ -410,17 +410,17 @@ static inline int layout_flex__remaining_free_space(
}
if (*unfrozen_factor_sum < F_1) {
- int free_space = FIXTOINT(FMUL(INTTOFIX(initial_free_space),
+ int free_space = FIXTOINT(FMUL(INTTOFIX(initial_free_main),
*unfrozen_factor_sum));
- if (free_space < remaining_free_space) {
- remaining_free_space = free_space;
+ if (free_space < remaining_free_main) {
+ remaining_free_main = free_space;
}
}
- NSLOG(flex, WARNING, "Remaining free space: %i", remaining_free_space);
+ NSLOG(flex, WARNING, "Remaining free space: %i", remaining_free_main);
- return remaining_free_space;
+ return remaining_free_main;
}
static inline int layout_flex__get_min_max_violations(
@@ -479,11 +479,11 @@ static inline int layout_flex__get_min_max_violations(
return total_violation;
}
-static inline void layout_flex__distribute_free_space(
+static inline void layout_flex__distribute_free_main(
struct flex_ctx *ctx,
struct flex_line_data *line,
css_fixed unfrozen_factor_sum,
- int remaining_free_space,
+ int remaining_free_main,
bool grow)
{
size_t item_count = line->first + line->count;
@@ -501,7 +501,7 @@ static inline void layout_flex__distribute_free_space(
item->target_main_size = item->base_size +
FIXTOINT(FMUL(
- INTTOFIX(remaining_free_space),
+ INTTOFIX(remaining_free_main),
ratio));
}
} else {
@@ -542,7 +542,7 @@ static inline void layout_flex__distribute_free_space(
item->target_main_size = item->base_size -
FIXTOINT(FMUL(
- INTTOFIX(abs(remaining_free_space)),
+ INTTOFIX(abs(remaining_free_main)),
ratio));
}
}
@@ -618,26 +618,27 @@ static bool layout_flex__resolve_line(
struct flex_line_data *line,
int available_width)
{
- bool grow = (line->main_size < available_width);
size_t item_count = line->first + line->count;
- int available_space = available_width;
- int initial_free_space;
+ int available_main = available_width;
+ int initial_free_main;
+ bool grow;
- available_space = available_width;
+ available_main = available_width;
if (ctx->horizontal == false) {
- available_space = ctx->flex->height;
- if (available_space == AUTO) {
- available_space = INT_MAX;
+ available_main = ctx->flex->height;
+ if (available_main == AUTO) {
+ available_main = INT_MAX;
}
}
- initial_free_space = available_space;
+ grow = (line->main_size < available_main);
+ initial_free_main = available_main;
NSLOG(flex, WARNING, "box %p: line %zu: first: %zu, count: %zu",
ctx->flex, line - ctx->line.data,
line->first, line->count);
- NSLOG(flex, WARNING, "Line main_size: %i, available_space: %i",
- line->main_size, available_space);
+ NSLOG(flex, WARNING, "Line main_size: %i, available_main: %i",
+ line->main_size, available_main);
for (size_t i = line->first; i < item_count; i++) {
struct flex_item_data *item = &ctx->item.data[i];
@@ -659,31 +660,31 @@ static bool layout_flex__resolve_line(
/* 4. Calculate initial free space */
if (item->freeze) {
- initial_free_space -= item->target_main_size;
+ initial_free_main -= item->target_main_size;
} else {
- initial_free_space -= item->base_size;
+ initial_free_main -= item->base_size;
}
}
/* 5. Loop */
while (line->frozen < line->count) {
css_fixed unfrozen_factor_sum;
- int remaining_free_space;
+ int remaining_free_main;
int total_violation;
NSLOG(flex, WARNING, "flex-container: %p: Resolver pass",
ctx->flex);
/* b */
- remaining_free_space = layout_flex__remaining_free_space(ctx,
- line, &unfrozen_factor_sum, initial_free_space,
- available_space, grow);
+ remaining_free_main = layout_flex__remaining_free_main(ctx,
+ line, &unfrozen_factor_sum, initial_free_main,
+ available_main, grow);
/* c */
- if (remaining_free_space != 0) {
- layout_flex__distribute_free_space(ctx,
+ if (remaining_free_main != 0) {
+ layout_flex__distribute_free_main(ctx,
line, unfrozen_factor_sum,
- remaining_free_space, grow);
+ remaining_free_main, grow);
}
/* d */