Gitweb links:
...log
http://git.netsurf-browser.org/netsurf.git/shortlog/217f71357e16c5ffea409566ffb70e2ae7a4f361
...commit
http://git.netsurf-browser.org/netsurf.git/commit/217f71357e16c5ffea409566ffb70e2ae7a4f361
...tree
http://git.netsurf-browser.org/netsurf.git/tree/217f71357e16c5ffea409566ffb70e2ae7a4f361
The branch, master has been updated
via 217f71357e16c5ffea409566ffb70e2ae7a4f361 (commit)
via 45b68a3b509cb8a579c2dfff05c714f91b339cb4 (commit)
via 47482bd5391e15ab12293133feea9616b235b8b9 (commit)
via e9147bdeea34b862e029c4a500cd87049875df4b (commit)
via b91d61b89f1b3eba0bd523bc8b5beadf68a3c952 (commit)
via d0b1bcb01a549a885007862112aeaa8b09ddf40d (commit)
via 6c2f9f32853c6359516f643ce8f2b4fad968e058 (commit)
from 0718e5868119c9f61a6c6f1fe11de21ff6ba9b9a (commit)
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/netsurf.git/commit/?id=217f71357e16c5ffea409566ffb70e2ae7a4f361
commit 217f71357e16c5ffea409566ffb70e2ae7a4f361
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>
html: layout: flex: Disable verbose logging
diff --git a/content/handlers/html/layout_flex.c
b/content/handlers/html/layout_flex.c
index d64004a..feaa4b3 100644
--- a/content/handlers/html/layout_flex.c
+++ b/content/handlers/html/layout_flex.c
@@ -196,7 +196,7 @@ static inline bool layout_flex__base_and_main_sizes(
int content_max_width = b->max_width;
int delta_outer_main = lh__delta_outer_main(ctx->flex, b);
- NSLOG(flex, WARNING, "box %p: delta_outer_main: %i",
+ NSLOG(flex, DEEPDEBUG, "box %p: delta_outer_main: %i",
b, delta_outer_main);
if (item->basis == CSS_FLEX_BASIS_SET) {
@@ -256,7 +256,7 @@ static inline bool layout_flex__base_and_main_sizes(
item->main_size = item->min_main + delta_outer_main;
}
- NSLOG(flex, WARNING, "flex-item box: %p: base_size: %i, main_size %i",
+ NSLOG(flex, DEEPDEBUG, "flex-item box: %p: base_size: %i, main_size %i",
b, item->base_size, item->main_size);
return true;
@@ -283,7 +283,7 @@ static void layout_flex_ctx__populate_item_data(
b->margin, b->padding, b->border);
b->float_container = NULL;
- NSLOG(flex, WARNING, "flex-item box: %p: width: %i",
+ NSLOG(flex, DEEPDEBUG, "flex-item box: %p: width: %i",
b, b->width);
item->box = b;
@@ -332,7 +332,7 @@ static struct flex_line_data
*layout_flex__build_line(struct flex_ctx *ctx,
line = &ctx->line.data[ctx->line.count];
line->first = item_index;
- NSLOG(flex, WARNING, "flex container %p: available main: %i",
+ NSLOG(flex, DEEPDEBUG, "flex container %p: available main: %i",
ctx->flex, ctx->available_main);
while (item_index < ctx->item.count) {
@@ -378,7 +378,8 @@ static inline void layout_flex__item_freeze(
item->freeze = true;
line->frozen++;
- NSLOG(flex, WARNING, "flex-item box: %p: Frozen at target_main_size:
%i",
+ NSLOG(flex, DEEPDEBUG, "flex-item box: %p: "
+ "Frozen at target_main_size: %i",
item->box, item->target_main_size);
}
@@ -417,7 +418,8 @@ static inline int layout_flex__remaining_free_main(
}
}
- NSLOG(flex, WARNING, "Remaining free space: %i", remaining_free_main);
+ NSLOG(flex, DEEPDEBUG, "Remaining free space: %i",
+ remaining_free_main);
return remaining_free_main;
}
@@ -434,7 +436,7 @@ static inline int layout_flex__get_min_max_violations(
struct flex_item_data *item = &ctx->item.data[i];
int target_main_size = item->target_main_size;
- NSLOG(flex, WARNING, "item %p: target_main_size: %i",
+ NSLOG(flex, DEEPDEBUG, "item %p: target_main_size: %i",
item->box, target_main_size);
if (item->freeze) {
@@ -445,35 +447,35 @@ static inline int layout_flex__get_min_max_violations(
target_main_size > item->max_main) {
target_main_size = item->max_main;
item->max_violation = true;
- NSLOG(flex, WARNING, "Violation: max_main: %i",
+ NSLOG(flex, DEEPDEBUG, "Violation: max_main: %i",
item->max_main);
}
if (target_main_size < item->min_main) {
target_main_size = item->min_main;
item->min_violation = true;
- NSLOG(flex, WARNING, "Violation: min_main: %i",
+ NSLOG(flex, DEEPDEBUG, "Violation: min_main: %i",
item->min_main);
}
if (target_main_size < item->box->min_width) {
target_main_size = item->box->min_width;
item->min_violation = true;
- NSLOG(flex, WARNING, "Violation: box min_width: %i",
+ NSLOG(flex, DEEPDEBUG, "Violation: box min_width: %i",
item->box->min_width);
}
if (target_main_size < 0) {
target_main_size = 0;
item->min_violation = true;
- NSLOG(flex, WARNING, "Violation: less than 0");
+ NSLOG(flex, DEEPDEBUG, "Violation: less than 0");
}
total_violation += target_main_size - item->target_main_size;
item->target_main_size = target_main_size;
}
- NSLOG(flex, WARNING, "Total violation: %i", total_violation);
+ NSLOG(flex, DEEPDEBUG, "Total violation: %i", total_violation);
return total_violation;
}
@@ -612,10 +614,10 @@ static bool layout_flex__resolve_line(
grow = (line->main_size < available_main);
initial_free_main = available_main;
- NSLOG(flex, WARNING, "box %p: line %zu: first: %zu, count: %zu",
+ NSLOG(flex, DEEPDEBUG, "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_main: %i",
+ NSLOG(flex, DEEPDEBUG, "Line main_size: %i, available_main: %i",
line->main_size, available_main);
for (size_t i = line->first; i < item_count; i++) {
@@ -650,7 +652,7 @@ static bool layout_flex__resolve_line(
int remaining_free_main;
int total_violation;
- NSLOG(flex, WARNING, "flex-container: %p: Resolver pass",
+ NSLOG(flex, DEEPDEBUG, "flex-container: %p: Resolver pass",
ctx->flex);
/* b */
@@ -703,7 +705,7 @@ static bool layout_flex__collect_items_into_lines(
pos += line->count;
- NSLOG(flex, WARNING, "flex-container: %p: "
+ NSLOG(flex, DEEPDEBUG, "flex-container: %p: "
"fitted: %zu (total: %zu/%zu)",
ctx->flex, line->count,
pos, ctx->item.count);
@@ -834,8 +836,8 @@ bool layout_flex(struct box *flex, int available_width,
return false;
}
- NSLOG(flex, WARNING, "box %p: %s, available_width %i, width: %i", flex,
- ctx->horizontal ? "horizontal" : "vertical",
+ NSLOG(flex, DEEPDEBUG, "box %p: %s, available_width %i, width: %i",
+ flex, ctx->horizontal ? "horizontal" : "vertical",
available_width, flex->width);
layout_find_dimensions(
@@ -854,9 +856,9 @@ bool layout_flex(struct box *flex, int available_width,
ctx->available_cross = available_width;
}
- NSLOG(flex, WARNING, "box %p: available_main: %i",
+ NSLOG(flex, DEEPDEBUG, "box %p: available_main: %i",
flex, ctx->available_main);
- NSLOG(flex, WARNING, "box %p: available_cross: %i",
+ NSLOG(flex, DEEPDEBUG, "box %p: available_cross: %i",
flex, ctx->available_cross);
layout_flex_ctx__populate_item_data(ctx, flex, available_width);
@@ -889,7 +891,7 @@ bool layout_flex(struct box *flex, int available_width,
cleanup:
layout_flex_ctx__destroy(ctx);
- NSLOG(flex, WARNING, "box %p: %s: w: %i, h: %i", flex,
+ NSLOG(flex, DEEPDEBUG, "box %p: %s: w: %i, h: %i", flex,
success ? "success" : "failure",
flex->width, flex->height);
return success;
commitdiff
http://git.netsurf-browser.org/netsurf.git/commit/?id=45b68a3b509cb8a579c2dfff05c714f91b339cb4
commit 45b68a3b509cb8a579c2dfff05c714f91b339cb4
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>
html: layout: flex: Implement align-items and align-self
diff --git a/content/handlers/html/layout_flex.c
b/content/handlers/html/layout_flex.c
index f0dfca8..d64004a 100644
--- a/content/handlers/html/layout_flex.c
+++ b/content/handlers/html/layout_flex.c
@@ -85,6 +85,9 @@ struct flex_ctx {
int main_size;
int cross_size;
+ int available_main;
+ int available_cross;
+
bool horizontal;
enum css_flex_wrap_e wrap;
@@ -216,7 +219,8 @@ static inline bool layout_flex__base_and_main_sizes(
if (ctx->horizontal == false) {
if (b->width == AUTO) {
- b->width = min(available_width, content_max_width);
+ b->width = min(max(content_min_width, available_width),
+ content_max_width);
b->width -= lh__delta_outer_width(b);
}
@@ -316,10 +320,9 @@ static bool layout_flex_ctx__ensure_line(struct flex_ctx
*ctx)
}
static struct flex_line_data *layout_flex__build_line(struct flex_ctx *ctx,
- size_t item_index, int available_width)
+ size_t item_index)
{
struct flex_line_data *line;
- int available_main;
int used_main = 0;
if (!layout_flex_ctx__ensure_line(ctx)) {
@@ -329,14 +332,8 @@ static struct flex_line_data
*layout_flex__build_line(struct flex_ctx *ctx,
line = &ctx->line.data[ctx->line.count];
line->first = item_index;
- if (ctx->horizontal) {
- available_main = available_width;
- } else {
- available_main = ctx->flex->height;
- }
-
NSLOG(flex, WARNING, "flex container %p: available main: %i",
- ctx->flex, available_main);
+ ctx->flex, ctx->available_main);
while (item_index < ctx->item.count) {
struct flex_item_data *item = &ctx->item.data[item_index];
@@ -348,9 +345,9 @@ static struct flex_line_data
*layout_flex__build_line(struct flex_ctx *ctx,
b->height + lh__delta_outer_main(ctx->flex, b);
if (ctx->wrap == CSS_FLEX_WRAP_NOWRAP ||
- pos_main + used_main <= available_main ||
+ pos_main + used_main <= ctx->available_main ||
lh__box_is_absolute(item->box) ||
- available_main == AUTO ||
+ ctx->available_main == AUTO ||
line->count == 0 ||
pos_main == 0) {
if (lh__box_is_absolute(item->box) == false) {
@@ -601,20 +598,15 @@ static bool layout_flex__place_line_items_main(
/** 9.7. Resolving Flexible Lengths */
static bool layout_flex__resolve_line(
struct flex_ctx *ctx,
- struct flex_line_data *line,
- int available_width)
+ struct flex_line_data *line)
{
size_t item_count = line->first + line->count;
- int available_main = available_width;
+ int available_main = ctx->available_main;
int initial_free_main;
bool grow;
- available_main = available_width;
- if (ctx->horizontal == false) {
- available_main = ctx->flex->height;
- if (available_main == AUTO) {
- available_main = INT_MAX;
- }
+ if (available_main == AUTO) {
+ available_main = INT_MAX;
}
grow = (line->main_size < available_main);
@@ -697,15 +689,14 @@ static bool layout_flex__resolve_line(
}
static bool layout_flex__collect_items_into_lines(
- struct flex_ctx *ctx,
- int available_width)
+ struct flex_ctx *ctx)
{
size_t pos = 0;
while (pos < ctx->item.count) {
struct flex_line_data *line;
- line = layout_flex__build_line(ctx, pos, available_width);
+ line = layout_flex__build_line(ctx, pos);
if (line == NULL) {
return false;
}
@@ -717,7 +708,7 @@ static bool layout_flex__collect_items_into_lines(
ctx->flex, line->count,
pos, ctx->item.count);
- if (!layout_flex__resolve_line(ctx, line, available_width)) {
+ if (!layout_flex__resolve_line(ctx, line)) {
return false;
}
@@ -731,7 +722,7 @@ static bool layout_flex__collect_items_into_lines(
}
static void layout_flex__place_line_items_cross(struct flex_ctx *ctx,
- struct flex_line_data *line)
+ struct flex_line_data *line, int extra)
{
enum box_side cross_start = ctx->horizontal ? TOP : LEFT;
size_t item_count = line->first + line->count;
@@ -739,12 +730,52 @@ static void layout_flex__place_line_items_cross(struct
flex_ctx *ctx,
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 cross_free_space;
+ int *box_size_cross;
int *box_pos_cross;
box_pos_cross = ctx->horizontal ? &b->y : &b->x;
- *box_pos_cross = ctx->flex->padding[cross_start] + line->pos +
- lh__non_auto_margin(b, cross_start) +
- b->border[cross_start].width;
+ box_size_cross = lh__box_size_cross(ctx->horizontal, b);
+
+ cross_free_space = line->cross_size + extra - *box_size_cross -
+ lh__delta_outer_cross(ctx->flex, b);
+
+ switch (lh__box_align_self(ctx->flex, b)) {
+ default:
+ /* Fall through. */
+ case CSS_ALIGN_SELF_STRETCH:
+ if (lh__box_size_cross_is_auto(ctx->horizontal, b)) {
+ *box_size_cross += cross_free_space;
+
+ /* Relayout children for stretch. */
+ if (!layout_flex_item(ctx, item, b->width)) {
+ return;
+ }
+ }
+ /* Fall through. */
+ case CSS_ALIGN_SELF_FLEX_START:
+ *box_pos_cross = ctx->flex->padding[cross_start] +
+ line->pos +
+ lh__non_auto_margin(b, cross_start) +
+ b->border[cross_start].width;
+ break;
+
+ case CSS_ALIGN_SELF_FLEX_END:
+ *box_pos_cross = ctx->flex->padding[cross_start] +
+ line->pos + cross_free_space +
+ lh__non_auto_margin(b, cross_start) +
+ b->border[cross_start].width;
+ break;
+
+ case CSS_ALIGN_SELF_BASELINE:
+ /* Fall through. */
+ case CSS_ALIGN_SELF_CENTER:
+ *box_pos_cross = ctx->flex->padding[cross_start] +
+ line->pos + cross_free_space / 2 +
+ lh__non_auto_margin(b, cross_start) +
+ b->border[cross_start].width;
+ break;
+ }
}
}
@@ -754,15 +785,32 @@ static void layout_flex__place_lines(struct flex_ctx *ctx)
int line_pos = reversed ? ctx->cross_size : 0;
int post_multiplier = reversed ? 0 : 1;
int pre_multiplier = reversed ? -1 : 0;
+ int extra_remainder = 0;
+ int extra = 0;
+
+ if (ctx->available_cross != AUTO &&
+ ctx->available_cross != ctx->cross_size &&
+ ctx->line.count > 0) {
+ extra = ctx->available_cross - ctx->cross_size;
+
+ extra_remainder = extra % ctx->line.count;
+ extra /= ctx->line.count;
+ }
for (size_t i = 0; i < ctx->line.count; i++) {
struct flex_line_data *line = &ctx->line.data[i];
line_pos += pre_multiplier * line->cross_size;
line->pos = line_pos;
- line_pos += post_multiplier * line->cross_size;
+ line_pos += post_multiplier * line->cross_size +
+ extra + extra_remainder;
+
+ layout_flex__place_line_items_cross(ctx, line,
+ extra + extra_remainder);
- layout_flex__place_line_items_cross(ctx, line);
+ if (extra_remainder > 0) {
+ extra_remainder--;
+ }
}
}
@@ -798,10 +846,23 @@ bool layout_flex(struct box *flex, int available_width,
available_width = min(available_width, flex->width);
+ if (ctx->horizontal) {
+ ctx->available_main = available_width;
+ ctx->available_cross = ctx->flex->height;
+ } else {
+ ctx->available_main = ctx->flex->height;
+ ctx->available_cross = available_width;
+ }
+
+ NSLOG(flex, WARNING, "box %p: available_main: %i",
+ flex, ctx->available_main);
+ NSLOG(flex, WARNING, "box %p: available_cross: %i",
+ flex, ctx->available_cross);
+
layout_flex_ctx__populate_item_data(ctx, flex, available_width);
/* Place items onto lines. */
- success = layout_flex__collect_items_into_lines(ctx, available_width);
+ success = layout_flex__collect_items_into_lines(ctx);
if (!success) {
goto cleanup;
}
@@ -828,7 +889,8 @@ bool layout_flex(struct box *flex, int available_width,
cleanup:
layout_flex_ctx__destroy(ctx);
- NSLOG(flex, WARNING, "box %p: %s", flex,
- success ? "success" : "failure");
+ NSLOG(flex, WARNING, "box %p: %s: w: %i, h: %i", flex,
+ success ? "success" : "failure",
+ flex->width, flex->height);
return success;
}
diff --git a/content/handlers/html/layout_internal.h
b/content/handlers/html/layout_internal.h
index 8751700..974f493 100644
--- a/content/handlers/html/layout_internal.h
+++ b/content/handlers/html/layout_internal.h
@@ -245,6 +245,35 @@ static inline int *lh__box_size_cross(
return horizontal ? &b->height : &b->width;
}
+static inline bool lh__box_size_cross_is_auto(
+ bool horizontal,
+ struct box *b)
+{
+ css_fixed length;
+ css_unit unit;
+
+ if (horizontal) {
+ return css_computed_height(b->style,
+ &length, &unit) == CSS_HEIGHT_AUTO;
+ } else {
+ return css_computed_width(b->style,
+ &length, &unit) == CSS_WIDTH_AUTO;
+ }
+}
+
+static inline enum css_align_self_e lh__box_align_self(
+ const struct box *flex,
+ const struct box *item)
+{
+ enum css_align_self_e align_self = css_computed_align_self(item->style);
+
+ if (align_self == CSS_ALIGN_SELF_AUTO) {
+ align_self = css_computed_align_items(flex->style);
+ }
+
+ return align_self;
+}
+
/**
* Determine width of margin, borders, and padding on one side of a box.
*
commitdiff
http://git.netsurf-browser.org/netsurf.git/commit/?id=47482bd5391e15ab12293133feea9616b235b8b9
commit 47482bd5391e15ab12293133feea9616b235b8b9
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>
html: layout: flex: Implement wrap-reverse
diff --git a/content/handlers/html/layout_flex.c
b/content/handlers/html/layout_flex.c
index 1d7478e..f0dfca8 100644
--- a/content/handlers/html/layout_flex.c
+++ b/content/handlers/html/layout_flex.c
@@ -70,6 +70,8 @@ struct flex_line_data {
int main_size;
int cross_size;
+ int pos;
+
size_t first;
size_t count;
size_t frozen;
@@ -548,12 +550,10 @@ static inline void layout_flex__distribute_free_main(
}
}
-static bool layout_flex__resolve_line_item_positions(
+static bool layout_flex__place_line_items_main(
struct flex_ctx *ctx,
- struct flex_line_data *line,
- int available_width)
+ struct flex_line_data *line)
{
- enum box_side cross_start = ctx->horizontal ? TOP : LEFT;
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];
@@ -561,32 +561,18 @@ static bool layout_flex__resolve_line_item_positions(
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_cross;
int *box_pos_main;
if (ctx->horizontal) {
- bool success;
-
b->width = item->target_main_size -
lh__delta_outer_width(b);
- success = layout_flex_item(ctx, item, b->width);
- if (!success) {
+ if (!layout_flex_item(ctx, item, b->width)) {
return false;
}
-
- box_pos_main = &b->x;
- box_pos_cross = &b->y;
- } else {
- box_pos_main = &b->y;
- box_pos_cross = &b->x;
}
- *box_pos_cross = ctx->flex->padding[cross_start] +
- ctx->cross_size +
- lh__non_auto_margin(b, cross_start) +
- b->border[cross_start].width;
-
+ 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;
@@ -598,14 +584,14 @@ static bool layout_flex__resolve_line_item_positions(
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;
}
-
- main_pos += *box_size_main + lh__delta_outer_main(
- ctx->flex, b);
}
}
@@ -703,8 +689,7 @@ static bool layout_flex__resolve_line(
}
}
- if (!layout_flex__resolve_line_item_positions(ctx, line,
- available_width)) {
+ if (!layout_flex__place_line_items_main(ctx, line)) {
return false;
}
@@ -745,6 +730,42 @@ static bool layout_flex__collect_items_into_lines(
return true;
}
+static void layout_flex__place_line_items_cross(struct flex_ctx *ctx,
+ struct flex_line_data *line)
+{
+ enum box_side cross_start = ctx->horizontal ? TOP : LEFT;
+ size_t item_count = line->first + line->count;
+
+ 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_cross;
+
+ box_pos_cross = ctx->horizontal ? &b->y : &b->x;
+ *box_pos_cross = ctx->flex->padding[cross_start] + line->pos +
+ lh__non_auto_margin(b, cross_start) +
+ b->border[cross_start].width;
+ }
+}
+
+static void layout_flex__place_lines(struct flex_ctx *ctx)
+{
+ bool reversed = ctx->wrap == CSS_FLEX_WRAP_WRAP_REVERSE;
+ int line_pos = reversed ? ctx->cross_size : 0;
+ int post_multiplier = reversed ? 0 : 1;
+ int pre_multiplier = reversed ? -1 : 0;
+
+ for (size_t i = 0; i < ctx->line.count; i++) {
+ struct flex_line_data *line = &ctx->line.data[i];
+
+ line_pos += pre_multiplier * line->cross_size;
+ line->pos = line_pos;
+ line_pos += post_multiplier * line->cross_size;
+
+ layout_flex__place_line_items_cross(ctx, line);
+ }
+}
+
/**
* Layout a flex container.
*
@@ -785,6 +806,8 @@ bool layout_flex(struct box *flex, int available_width,
goto cleanup;
}
+ layout_flex__place_lines(ctx);
+
if (flex->height == AUTO) {
flex->height = ctx->horizontal ?
ctx->cross_size :
commitdiff
http://git.netsurf-browser.org/netsurf.git/commit/?id=e9147bdeea34b862e029c4a500cd87049875df4b
commit e9147bdeea34b862e029c4a500cd87049875df4b
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>
html: layout: flex: Don't pass content around unnecessarily
diff --git a/content/handlers/html/layout_flex.c
b/content/handlers/html/layout_flex.c
index 9242a83..1d7478e 100644
--- a/content/handlers/html/layout_flex.c
+++ b/content/handlers/html/layout_flex.c
@@ -314,7 +314,7 @@ static bool layout_flex_ctx__ensure_line(struct flex_ctx
*ctx)
}
static struct flex_line_data *layout_flex__build_line(struct flex_ctx *ctx,
- size_t item_index, int available_width, html_content *content)
+ size_t item_index, int available_width)
{
struct flex_line_data *line;
int available_main;
@@ -713,16 +713,14 @@ static bool layout_flex__resolve_line(
static bool layout_flex__collect_items_into_lines(
struct flex_ctx *ctx,
- int available_width,
- html_content *content)
+ int available_width)
{
size_t pos = 0;
while (pos < ctx->item.count) {
struct flex_line_data *line;
- line = layout_flex__build_line(ctx, pos,
- available_width, content);
+ line = layout_flex__build_line(ctx, pos, available_width);
if (line == NULL) {
return false;
}
@@ -782,8 +780,7 @@ bool layout_flex(struct box *flex, int available_width,
layout_flex_ctx__populate_item_data(ctx, flex, available_width);
/* Place items onto lines. */
- success = layout_flex__collect_items_into_lines(ctx,
- available_width, content);
+ success = layout_flex__collect_items_into_lines(ctx, available_width);
if (!success) {
goto cleanup;
}
commitdiff
http://git.netsurf-browser.org/netsurf.git/commit/?id=b91d61b89f1b3eba0bd523bc8b5beadf68a3c952
commit b91d61b89f1b3eba0bd523bc8b5beadf68a3c952
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>
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.
diff --git a/content/handlers/html/layout_flex.c
b/content/handlers/html/layout_flex.c
index 6731e79..9242a83 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 */
commitdiff
http://git.netsurf-browser.org/netsurf.git/commit/?id=d0b1bcb01a549a885007862112aeaa8b09ddf40d
commit d0b1bcb01a549a885007862112aeaa8b09ddf40d
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>
html: layout: flex: Unify line item placement
diff --git a/content/handlers/html/layout_flex.c
b/content/handlers/html/layout_flex.c
index 07c3b5b..6731e79 100644
--- a/content/handlers/html/layout_flex.c
+++ b/content/handlers/html/layout_flex.c
@@ -174,6 +174,10 @@ static bool layout_flex_item(
break;
}
+ if (!success) {
+ NSLOG(flex, ERROR, "box %p: layout failed", b);
+ }
+
return success;
}
@@ -215,7 +219,6 @@ static inline bool layout_flex__base_and_main_sizes(
}
if (!layout_flex_item(ctx, item, b->width)) {
- NSLOG(flex, WARNING, "box %p: layout failed", b);
return false;
}
}
@@ -545,77 +548,64 @@ static inline void layout_flex__distribute_free_space(
}
}
-static bool layout_flex__resolve_line_horizontal(
+static bool layout_flex__resolve_line_item_positions(
struct flex_ctx *ctx,
struct flex_line_data *line,
int available_width)
{
+ enum box_side cross_start = ctx->horizontal ? TOP : LEFT;
+ enum box_side main_start = ctx->horizontal ? LEFT : TOP;
size_t item_count = line->first + line->count;
- int x = ctx->flex->padding[LEFT];
+ 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;
- bool success = false;
-
- b->width = item->target_main_size - lh__delta_outer_width(b);
-
- success = layout_flex_item(ctx, item, b->width);
- if (!success) {
- NSLOG(flex, WARNING, "box %p: layout failed", b);
- return false;
- }
-
- b->y = ctx->flex->padding[TOP] + ctx->cross_size +
- lh__non_auto_margin(b, TOP) +
- b->border[TOP].width;
+ int *box_pos_cross;
+ int *box_pos_main;
- b->x = x + lh__non_auto_margin(b, LEFT) +
- b->border[LEFT].width;
+ if (ctx->horizontal) {
+ bool success;
- if (lh__box_is_absolute(b) == false) {
- int height;
+ b->width = item->target_main_size -
+ lh__delta_outer_width(b);
- height = b->height + lh__delta_outer_height(b);
- if (line->cross_size < height) {
- line->cross_size = height;
+ success = layout_flex_item(ctx, item, b->width);
+ if (!success) {
+ return false;
}
- x += b->width + lh__delta_outer_width(b);
+ box_pos_main = &b->x;
+ box_pos_cross = &b->y;
+ } else {
+ box_pos_main = &b->y;
+ box_pos_cross = &b->x;
}
- }
- return true;
-}
+ *box_pos_cross = ctx->flex->padding[cross_start] +
+ ctx->cross_size +
+ lh__non_auto_margin(b, cross_start) +
+ b->border[cross_start].width;
-static bool layout_flex__resolve_line_vertical(
- struct flex_ctx *ctx,
- struct flex_line_data *line,
- int available_width)
-{
- size_t item_count = line->first + line->count;
- int y = ctx->flex->padding[TOP];
-
- for (size_t i = line->first; i < item_count; i++) {
- struct flex_item_data *item = &ctx->item.data[i];
- struct box *b = item->box;
-
- b->x = ctx->flex->padding[LEFT] + ctx->cross_size +
- lh__non_auto_margin(b, LEFT) +
- b->border[LEFT].width;
+ *box_pos_main = main_pos + lh__non_auto_margin(b, main_start) +
+ b->border[main_start].width;
- b->y = y + lh__non_auto_margin(b, TOP) +
- b->border[TOP].width;
+ if (!lh__box_is_absolute(b)) {
+ int cross_size;
+ int *box_size_main;
+ int *box_size_cross;
- if (lh__box_is_absolute(b) == false) {
- int width;
+ box_size_main = lh__box_size_main(ctx->horizontal, b);
+ box_size_cross = lh__box_size_cross(ctx->horizontal, b);
- width = b->width + lh__delta_outer_width(b);
- if (line->cross_size < width) {
- line->cross_size = width;
+ cross_size = *box_size_cross + lh__delta_outer_cross(
+ ctx->flex, b);
+ if (line->cross_size < cross_size) {
+ line->cross_size = cross_size;
}
- y += b->height + lh__delta_outer_height(b);
+ main_pos += *box_size_main + lh__delta_outer_main(
+ ctx->flex, b);
}
}
@@ -712,16 +702,9 @@ static bool layout_flex__resolve_line(
}
}
- if (ctx->horizontal) {
- if (!layout_flex__resolve_line_horizontal(ctx,
- line, available_width)) {
- return false;
- }
- } else {
- if (!layout_flex__resolve_line_vertical(ctx,
- line, available_width)) {
- return false;
- }
+ if (!layout_flex__resolve_line_item_positions(ctx, line,
+ available_width)) {
+ return false;
}
return true;
commitdiff
http://git.netsurf-browser.org/netsurf.git/commit/?id=6c2f9f32853c6359516f643ce8f2b4fad968e058
commit 6c2f9f32853c6359516f643ce8f2b4fad968e058
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>
html: layout helpers: Add helpers for width/height indirection
diff --git a/content/handlers/html/layout_internal.h
b/content/handlers/html/layout_internal.h
index 445b430..8751700 100644
--- a/content/handlers/html/layout_internal.h
+++ b/content/handlers/html/layout_internal.h
@@ -231,6 +231,20 @@ static inline int lh__delta_outer_cross(
}
}
+static inline int *lh__box_size_main(
+ bool horizontal,
+ struct box *b)
+{
+ return horizontal ? &b->width : &b->height;
+}
+
+static inline int *lh__box_size_cross(
+ bool horizontal,
+ struct box *b)
+{
+ return horizontal ? &b->height : &b->width;
+}
+
/**
* Determine width of margin, borders, and padding on one side of a box.
*
-----------------------------------------------------------------------
Summary of changes:
content/handlers/html/layout_flex.c | 350 ++++++++++++++++++-------------
content/handlers/html/layout_internal.h | 43 ++++
2 files changed, 252 insertions(+), 141 deletions(-)
diff --git a/content/handlers/html/layout_flex.c
b/content/handlers/html/layout_flex.c
index 07c3b5b..feaa4b3 100644
--- a/content/handlers/html/layout_flex.c
+++ b/content/handlers/html/layout_flex.c
@@ -70,6 +70,8 @@ struct flex_line_data {
int main_size;
int cross_size;
+ int pos;
+
size_t first;
size_t count;
size_t frozen;
@@ -83,6 +85,9 @@ struct flex_ctx {
int main_size;
int cross_size;
+ int available_main;
+ int available_cross;
+
bool horizontal;
enum css_flex_wrap_e wrap;
@@ -174,6 +179,10 @@ static bool layout_flex_item(
break;
}
+ if (!success) {
+ NSLOG(flex, ERROR, "box %p: layout failed", b);
+ }
+
return success;
}
@@ -187,7 +196,7 @@ static inline bool layout_flex__base_and_main_sizes(
int content_max_width = b->max_width;
int delta_outer_main = lh__delta_outer_main(ctx->flex, b);
- NSLOG(flex, WARNING, "box %p: delta_outer_main: %i",
+ NSLOG(flex, DEEPDEBUG, "box %p: delta_outer_main: %i",
b, delta_outer_main);
if (item->basis == CSS_FLEX_BASIS_SET) {
@@ -210,12 +219,12 @@ static inline bool layout_flex__base_and_main_sizes(
if (ctx->horizontal == false) {
if (b->width == AUTO) {
- b->width = min(available_width, content_max_width);
+ b->width = min(max(content_min_width, available_width),
+ content_max_width);
b->width -= lh__delta_outer_width(b);
}
if (!layout_flex_item(ctx, item, b->width)) {
- NSLOG(flex, WARNING, "box %p: layout failed", b);
return false;
}
}
@@ -247,7 +256,7 @@ static inline bool layout_flex__base_and_main_sizes(
item->main_size = item->min_main + delta_outer_main;
}
- NSLOG(flex, WARNING, "flex-item box: %p: base_size: %i, main_size %i",
+ NSLOG(flex, DEEPDEBUG, "flex-item box: %p: base_size: %i, main_size %i",
b, item->base_size, item->main_size);
return true;
@@ -274,7 +283,7 @@ static void layout_flex_ctx__populate_item_data(
b->margin, b->padding, b->border);
b->float_container = NULL;
- NSLOG(flex, WARNING, "flex-item box: %p: width: %i",
+ NSLOG(flex, DEEPDEBUG, "flex-item box: %p: width: %i",
b, b->width);
item->box = b;
@@ -311,10 +320,9 @@ static bool layout_flex_ctx__ensure_line(struct flex_ctx
*ctx)
}
static struct flex_line_data *layout_flex__build_line(struct flex_ctx *ctx,
- size_t item_index, int available_width, html_content *content)
+ size_t item_index)
{
struct flex_line_data *line;
- int available_main;
int used_main = 0;
if (!layout_flex_ctx__ensure_line(ctx)) {
@@ -324,14 +332,8 @@ static struct flex_line_data
*layout_flex__build_line(struct flex_ctx *ctx,
line = &ctx->line.data[ctx->line.count];
line->first = item_index;
- if (ctx->horizontal) {
- available_main = available_width;
- } else {
- available_main = ctx->flex->height;
- }
-
- NSLOG(flex, WARNING, "flex container %p: available main: %i",
- ctx->flex, available_main);
+ NSLOG(flex, DEEPDEBUG, "flex container %p: available main: %i",
+ ctx->flex, ctx->available_main);
while (item_index < ctx->item.count) {
struct flex_item_data *item = &ctx->item.data[item_index];
@@ -343,9 +345,9 @@ static struct flex_line_data
*layout_flex__build_line(struct flex_ctx *ctx,
b->height + lh__delta_outer_main(ctx->flex, b);
if (ctx->wrap == CSS_FLEX_WRAP_NOWRAP ||
- pos_main + used_main <= available_main ||
+ pos_main + used_main <= ctx->available_main ||
lh__box_is_absolute(item->box) ||
- available_main == AUTO ||
+ ctx->available_main == AUTO ||
line->count == 0 ||
pos_main == 0) {
if (lh__box_is_absolute(item->box) == false) {
@@ -376,19 +378,20 @@ static inline void layout_flex__item_freeze(
item->freeze = true;
line->frozen++;
- NSLOG(flex, WARNING, "flex-item box: %p: Frozen at target_main_size:
%i",
+ NSLOG(flex, DEEPDEBUG, "flex-item box: %p: "
+ "Frozen at target_main_size: %i",
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;
@@ -397,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;
@@ -407,17 +410,18 @@ 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, DEEPDEBUG, "Remaining free space: %i",
+ remaining_free_main);
- return remaining_free_space;
+ return remaining_free_main;
}
static inline int layout_flex__get_min_max_violations(
@@ -432,7 +436,7 @@ static inline int layout_flex__get_min_max_violations(
struct flex_item_data *item = &ctx->item.data[i];
int target_main_size = item->target_main_size;
- NSLOG(flex, WARNING, "item %p: target_main_size: %i",
+ NSLOG(flex, DEEPDEBUG, "item %p: target_main_size: %i",
item->box, target_main_size);
if (item->freeze) {
@@ -443,44 +447,44 @@ static inline int layout_flex__get_min_max_violations(
target_main_size > item->max_main) {
target_main_size = item->max_main;
item->max_violation = true;
- NSLOG(flex, WARNING, "Violation: max_main: %i",
+ NSLOG(flex, DEEPDEBUG, "Violation: max_main: %i",
item->max_main);
}
if (target_main_size < item->min_main) {
target_main_size = item->min_main;
item->min_violation = true;
- NSLOG(flex, WARNING, "Violation: min_main: %i",
+ NSLOG(flex, DEEPDEBUG, "Violation: min_main: %i",
item->min_main);
}
if (target_main_size < item->box->min_width) {
target_main_size = item->box->min_width;
item->min_violation = true;
- NSLOG(flex, WARNING, "Violation: box min_width: %i",
+ NSLOG(flex, DEEPDEBUG, "Violation: box min_width: %i",
item->box->min_width);
}
if (target_main_size < 0) {
target_main_size = 0;
item->min_violation = true;
- NSLOG(flex, WARNING, "Violation: less than 0");
+ NSLOG(flex, DEEPDEBUG, "Violation: less than 0");
}
total_violation += target_main_size - item->target_main_size;
item->target_main_size = target_main_size;
}
- NSLOG(flex, WARNING, "Total violation: %i", total_violation);
+ NSLOG(flex, DEEPDEBUG, "Total violation: %i", total_violation);
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;
@@ -498,7 +502,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 {
@@ -539,83 +543,54 @@ 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));
}
}
}
-static bool layout_flex__resolve_line_horizontal(
+static bool layout_flex__place_line_items_main(
struct flex_ctx *ctx,
- struct flex_line_data *line,
- int available_width)
+ struct flex_line_data *line)
{
+ enum box_side main_start = ctx->horizontal ? LEFT : TOP;
size_t item_count = line->first + line->count;
- int x = ctx->flex->padding[LEFT];
+ 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;
- bool success = false;
-
- b->width = item->target_main_size - lh__delta_outer_width(b);
-
- success = layout_flex_item(ctx, item, b->width);
- if (!success) {
- NSLOG(flex, WARNING, "box %p: layout failed", b);
- return false;
- }
-
- b->y = ctx->flex->padding[TOP] + ctx->cross_size +
- lh__non_auto_margin(b, TOP) +
- b->border[TOP].width;
+ int *box_pos_main;
- b->x = x + lh__non_auto_margin(b, LEFT) +
- b->border[LEFT].width;
+ if (ctx->horizontal) {
+ b->width = item->target_main_size -
+ lh__delta_outer_width(b);
- if (lh__box_is_absolute(b) == false) {
- int height;
-
- height = b->height + lh__delta_outer_height(b);
- if (line->cross_size < height) {
- line->cross_size = height;
+ if (!layout_flex_item(ctx, item, b->width)) {
+ return false;
}
-
- x += b->width + lh__delta_outer_width(b);
}
- }
- return true;
-}
+ 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;
-static bool layout_flex__resolve_line_vertical(
- struct flex_ctx *ctx,
- struct flex_line_data *line,
- int available_width)
-{
- size_t item_count = line->first + line->count;
- int y = ctx->flex->padding[TOP];
+ if (!lh__box_is_absolute(b)) {
+ int cross_size;
+ int *box_size_main;
+ int *box_size_cross;
- for (size_t i = line->first; i < item_count; i++) {
- struct flex_item_data *item = &ctx->item.data[i];
- struct box *b = item->box;
+ box_size_main = lh__box_size_main(ctx->horizontal, b);
+ box_size_cross = lh__box_size_cross(ctx->horizontal, b);
- b->x = ctx->flex->padding[LEFT] + ctx->cross_size +
- lh__non_auto_margin(b, LEFT) +
- b->border[LEFT].width;
+ main_pos += *box_size_main + lh__delta_outer_main(
+ ctx->flex, b);
- b->y = y + lh__non_auto_margin(b, TOP) +
- b->border[TOP].width;
-
- if (lh__box_is_absolute(b) == false) {
- int width;
-
- width = b->width + lh__delta_outer_width(b);
- if (line->cross_size < width) {
- line->cross_size = width;
+ cross_size = *box_size_cross + lh__delta_outer_cross(
+ ctx->flex, b);
+ if (line->cross_size < cross_size) {
+ line->cross_size = cross_size;
}
-
- y += b->height + lh__delta_outer_height(b);
}
}
@@ -625,29 +600,25 @@ static bool layout_flex__resolve_line_vertical(
/** 9.7. Resolving Flexible Lengths */
static bool layout_flex__resolve_line(
struct flex_ctx *ctx,
- struct flex_line_data *line,
- int available_width)
+ struct flex_line_data *line)
{
- 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 = ctx->available_main;
+ int initial_free_main;
+ bool grow;
- available_space = available_width;
- if (ctx->horizontal == false) {
- available_space = ctx->flex->height;
- if (available_space == AUTO) {
- available_space = INT_MAX;
- }
+ 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",
+ NSLOG(flex, DEEPDEBUG, "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, DEEPDEBUG, "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];
@@ -669,31 +640,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",
+ NSLOG(flex, DEEPDEBUG, "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 */
@@ -712,45 +683,34 @@ static bool layout_flex__resolve_line(
}
}
- if (ctx->horizontal) {
- if (!layout_flex__resolve_line_horizontal(ctx,
- line, available_width)) {
- return false;
- }
- } else {
- if (!layout_flex__resolve_line_vertical(ctx,
- line, available_width)) {
- return false;
- }
+ if (!layout_flex__place_line_items_main(ctx, line)) {
+ return false;
}
return true;
}
static bool layout_flex__collect_items_into_lines(
- struct flex_ctx *ctx,
- int available_width,
- html_content *content)
+ struct flex_ctx *ctx)
{
size_t pos = 0;
while (pos < ctx->item.count) {
struct flex_line_data *line;
- line = layout_flex__build_line(ctx, pos,
- available_width, content);
+ line = layout_flex__build_line(ctx, pos);
if (line == NULL) {
return false;
}
pos += line->count;
- NSLOG(flex, WARNING, "flex-container: %p: "
+ NSLOG(flex, DEEPDEBUG, "flex-container: %p: "
"fitted: %zu (total: %zu/%zu)",
ctx->flex, line->count,
pos, ctx->item.count);
- if (!layout_flex__resolve_line(ctx, line, available_width)) {
+ if (!layout_flex__resolve_line(ctx, line)) {
return false;
}
@@ -763,6 +723,99 @@ static bool layout_flex__collect_items_into_lines(
return true;
}
+static void layout_flex__place_line_items_cross(struct flex_ctx *ctx,
+ struct flex_line_data *line, int extra)
+{
+ enum box_side cross_start = ctx->horizontal ? TOP : LEFT;
+ size_t item_count = line->first + line->count;
+
+ 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 cross_free_space;
+ int *box_size_cross;
+ int *box_pos_cross;
+
+ box_pos_cross = ctx->horizontal ? &b->y : &b->x;
+ box_size_cross = lh__box_size_cross(ctx->horizontal, b);
+
+ cross_free_space = line->cross_size + extra - *box_size_cross -
+ lh__delta_outer_cross(ctx->flex, b);
+
+ switch (lh__box_align_self(ctx->flex, b)) {
+ default:
+ /* Fall through. */
+ case CSS_ALIGN_SELF_STRETCH:
+ if (lh__box_size_cross_is_auto(ctx->horizontal, b)) {
+ *box_size_cross += cross_free_space;
+
+ /* Relayout children for stretch. */
+ if (!layout_flex_item(ctx, item, b->width)) {
+ return;
+ }
+ }
+ /* Fall through. */
+ case CSS_ALIGN_SELF_FLEX_START:
+ *box_pos_cross = ctx->flex->padding[cross_start] +
+ line->pos +
+ lh__non_auto_margin(b, cross_start) +
+ b->border[cross_start].width;
+ break;
+
+ case CSS_ALIGN_SELF_FLEX_END:
+ *box_pos_cross = ctx->flex->padding[cross_start] +
+ line->pos + cross_free_space +
+ lh__non_auto_margin(b, cross_start) +
+ b->border[cross_start].width;
+ break;
+
+ case CSS_ALIGN_SELF_BASELINE:
+ /* Fall through. */
+ case CSS_ALIGN_SELF_CENTER:
+ *box_pos_cross = ctx->flex->padding[cross_start] +
+ line->pos + cross_free_space / 2 +
+ lh__non_auto_margin(b, cross_start) +
+ b->border[cross_start].width;
+ break;
+ }
+ }
+}
+
+static void layout_flex__place_lines(struct flex_ctx *ctx)
+{
+ bool reversed = ctx->wrap == CSS_FLEX_WRAP_WRAP_REVERSE;
+ int line_pos = reversed ? ctx->cross_size : 0;
+ int post_multiplier = reversed ? 0 : 1;
+ int pre_multiplier = reversed ? -1 : 0;
+ int extra_remainder = 0;
+ int extra = 0;
+
+ if (ctx->available_cross != AUTO &&
+ ctx->available_cross != ctx->cross_size &&
+ ctx->line.count > 0) {
+ extra = ctx->available_cross - ctx->cross_size;
+
+ extra_remainder = extra % ctx->line.count;
+ extra /= ctx->line.count;
+ }
+
+ for (size_t i = 0; i < ctx->line.count; i++) {
+ struct flex_line_data *line = &ctx->line.data[i];
+
+ line_pos += pre_multiplier * line->cross_size;
+ line->pos = line_pos;
+ line_pos += post_multiplier * line->cross_size +
+ extra + extra_remainder;
+
+ layout_flex__place_line_items_cross(ctx, line,
+ extra + extra_remainder);
+
+ if (extra_remainder > 0) {
+ extra_remainder--;
+ }
+ }
+}
+
/**
* Layout a flex container.
*
@@ -783,8 +836,8 @@ bool layout_flex(struct box *flex, int available_width,
return false;
}
- NSLOG(flex, WARNING, "box %p: %s, available_width %i, width: %i", flex,
- ctx->horizontal ? "horizontal" : "vertical",
+ NSLOG(flex, DEEPDEBUG, "box %p: %s, available_width %i, width: %i",
+ flex, ctx->horizontal ? "horizontal" : "vertical",
available_width, flex->width);
layout_find_dimensions(
@@ -795,15 +848,29 @@ bool layout_flex(struct box *flex, int available_width,
available_width = min(available_width, flex->width);
+ if (ctx->horizontal) {
+ ctx->available_main = available_width;
+ ctx->available_cross = ctx->flex->height;
+ } else {
+ ctx->available_main = ctx->flex->height;
+ ctx->available_cross = available_width;
+ }
+
+ NSLOG(flex, DEEPDEBUG, "box %p: available_main: %i",
+ flex, ctx->available_main);
+ NSLOG(flex, DEEPDEBUG, "box %p: available_cross: %i",
+ flex, ctx->available_cross);
+
layout_flex_ctx__populate_item_data(ctx, flex, available_width);
/* Place items onto lines. */
- success = layout_flex__collect_items_into_lines(ctx,
- available_width, content);
+ success = layout_flex__collect_items_into_lines(ctx);
if (!success) {
goto cleanup;
}
+ layout_flex__place_lines(ctx);
+
if (flex->height == AUTO) {
flex->height = ctx->horizontal ?
ctx->cross_size :
@@ -824,7 +891,8 @@ bool layout_flex(struct box *flex, int available_width,
cleanup:
layout_flex_ctx__destroy(ctx);
- NSLOG(flex, WARNING, "box %p: %s", flex,
- success ? "success" : "failure");
+ NSLOG(flex, DEEPDEBUG, "box %p: %s: w: %i, h: %i", flex,
+ success ? "success" : "failure",
+ flex->width, flex->height);
return success;
}
diff --git a/content/handlers/html/layout_internal.h
b/content/handlers/html/layout_internal.h
index 445b430..974f493 100644
--- a/content/handlers/html/layout_internal.h
+++ b/content/handlers/html/layout_internal.h
@@ -231,6 +231,49 @@ static inline int lh__delta_outer_cross(
}
}
+static inline int *lh__box_size_main(
+ bool horizontal,
+ struct box *b)
+{
+ return horizontal ? &b->width : &b->height;
+}
+
+static inline int *lh__box_size_cross(
+ bool horizontal,
+ struct box *b)
+{
+ return horizontal ? &b->height : &b->width;
+}
+
+static inline bool lh__box_size_cross_is_auto(
+ bool horizontal,
+ struct box *b)
+{
+ css_fixed length;
+ css_unit unit;
+
+ if (horizontal) {
+ return css_computed_height(b->style,
+ &length, &unit) == CSS_HEIGHT_AUTO;
+ } else {
+ return css_computed_width(b->style,
+ &length, &unit) == CSS_WIDTH_AUTO;
+ }
+}
+
+static inline enum css_align_self_e lh__box_align_self(
+ const struct box *flex,
+ const struct box *item)
+{
+ enum css_align_self_e align_self = css_computed_align_self(item->style);
+
+ if (align_self == CSS_ALIGN_SELF_AUTO) {
+ align_self = css_computed_align_items(flex->style);
+ }
+
+ return align_self;
+}
+
/**
* Determine width of margin, borders, and padding on one side of a box.
*
--
NetSurf Browser
_______________________________________________
netsurf-commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]