Gitweb links:
...log
http://git.netsurf-browser.org/netsurf.git/shortlog/e754f31cb7aa4293ebe1a28fbca695d26def627c
...commit
http://git.netsurf-browser.org/netsurf.git/commit/e754f31cb7aa4293ebe1a28fbca695d26def627c
...tree
http://git.netsurf-browser.org/netsurf.git/tree/e754f31cb7aa4293ebe1a28fbca695d26def627c
The branch, master has been updated
via e754f31cb7aa4293ebe1a28fbca695d26def627c (commit)
via fbc4f141f7957cf03ccd4e6de1ee44b869956611 (commit)
via 25acf1a5dd778aa82a828a2138bf33af20fb81dc (commit)
via 73ce30325f60310b2bce69b181a1d4f61399a33c (commit)
via 3760bbcd2a0b6ce25ab2b38d9f7ac2c79d8713f9 (commit)
via b07bda787c02210d018c39d917b02ca0bee87de7 (commit)
via 43d5ce44acdef1686edc0f7cd8579cf4f9f9adfb (commit)
via 8d4176e4d46cc4e37d2f9ee02e9508aa4a641b54 (commit)
via 6da16e564820e2a958a7266f05fb98b4f252dc49 (commit)
via fbb39f0d49f2606400dcf6bb2fb1d5c56903ddf9 (commit)
from f30f869ea40ad7633ec34903d0f1594c860a32ae (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=e754f31cb7aa4293ebe1a28fbca695d26def627c
commit e754f31cb7aa4293ebe1a28fbca695d26def627c
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>
html: layout: flex: Support reversed main direction
diff --git a/content/handlers/html/layout_flex.c
b/content/handlers/html/layout_flex.c
index 65f770f..cea7964 100644
--- a/content/handlers/html/layout_flex.c
+++ b/content/handlers/html/layout_flex.c
@@ -98,6 +98,7 @@ struct flex_ctx {
int available_cross;
bool horizontal;
+ bool main_reversed;
enum css_flex_wrap_e wrap;
struct flex_items {
@@ -165,6 +166,7 @@ static struct flex_ctx *layout_flex_ctx__create(
ctx->wrap = css_computed_flex_wrap(flex->style);
ctx->horizontal = lh__flex_main_is_horizontal(flex);
+ ctx->main_reversed = lh__flex_direction_reversed(flex);
return ctx;
}
@@ -736,6 +738,22 @@ static bool layout_flex__resolve_line(
}
/**
+ * Find box side representing the start of flex container in main direction.
+ *
+ * \param[in] ctx Flex layout context.
+ * \return the start side.
+ */
+static enum box_side layout_flex__main_start_side(
+ const struct flex_ctx *ctx)
+{
+ if (ctx->horizontal) {
+ return (ctx->main_reversed) ? RIGHT : LEFT;
+ } else {
+ return (ctx->main_reversed) ? BOTTOM : TOP;
+ }
+}
+
+/**
* Position items along a line
*
* \param[in] ctx Flex layout context
@@ -746,13 +764,21 @@ static bool layout_flex__place_line_items_main(
struct flex_ctx *ctx,
struct flex_line_data *line)
{
+ int main_pos = ctx->flex->padding[layout_flex__main_start_side(ctx)];
+ int post_multiplier = ctx->main_reversed ? 0 : 1;
+ int pre_multiplier = ctx->main_reversed ? -1 : 0;
size_t item_count = line->first + line->count;
+ if (ctx->main_reversed) {
+ main_pos = lh__box_size_main(ctx->horizontal, ctx->flex) -
+ main_pos;
+ }
+
for (size_t i = line->first; i < item_count; i++) {
enum box_side main_start = ctx->horizontal ? LEFT : TOP;
struct flex_item_data *item = &ctx->item.data[i];
- int main_pos = ctx->flex->padding[main_start];
struct box *b = item->box;
+ int box_size_main;
int *box_pos_main;
if (ctx->horizontal) {
@@ -764,24 +790,26 @@ static bool layout_flex__place_line_items_main(
}
}
+ box_size_main = lh__box_size_main(ctx->horizontal, b);
box_pos_main = ctx->horizontal ? &b->x : &b->y;
+
+ if (!lh__box_is_absolute(b)) {
+ main_pos += pre_multiplier * (box_size_main +
+ lh__delta_outer_main(ctx->flex, b));
+ }
+
*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_ptr(
- ctx->horizontal, b);
- box_size_cross = lh__box_size_cross_ptr(
+ int box_size_cross = lh__box_size_cross(
ctx->horizontal, b);
- main_pos += *box_size_main + lh__delta_outer_main(
- ctx->flex, b);
+ main_pos += post_multiplier * (box_size_main +
+ lh__delta_outer_main(ctx->flex, b));
- cross_size = *box_size_cross + lh__delta_outer_cross(
+ cross_size = box_size_cross + lh__delta_outer_cross(
ctx->flex, b);
if (line->cross_size < cross_size) {
line->cross_size = cross_size;
commitdiff
http://git.netsurf-browser.org/netsurf.git/commit/?id=fbc4f141f7957cf03ccd4e6de1ee44b869956611
commit fbc4f141f7957cf03ccd4e6de1ee44b869956611
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>
html: layout: Helpers to get cross/main box size
diff --git a/content/handlers/html/layout_internal.h
b/content/handlers/html/layout_internal.h
index 7367789..d094462 100644
--- a/content/handlers/html/layout_internal.h
+++ b/content/handlers/html/layout_internal.h
@@ -258,6 +258,20 @@ static inline int *lh__box_size_cross_ptr(
return horizontal ? &b->height : &b->width;
}
+static inline int lh__box_size_main(
+ bool horizontal,
+ const struct box *b)
+{
+ return horizontal ? b->width : b->height;
+}
+
+static inline int lh__box_size_cross(
+ bool horizontal,
+ const struct box *b)
+{
+ return horizontal ? b->height : b->width;
+}
+
static inline bool lh__box_size_cross_is_auto(
bool horizontal,
struct box *b)
commitdiff
http://git.netsurf-browser.org/netsurf.git/commit/?id=25acf1a5dd778aa82a828a2138bf33af20fb81dc
commit 25acf1a5dd778aa82a828a2138bf33af20fb81dc
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>
html: layout: flex: Rename indirected box w/h functions
diff --git a/content/handlers/html/layout_flex.c
b/content/handlers/html/layout_flex.c
index 40e1063..65f770f 100644
--- a/content/handlers/html/layout_flex.c
+++ b/content/handlers/html/layout_flex.c
@@ -773,8 +773,10 @@ static bool layout_flex__place_line_items_main(
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);
+ box_size_main = lh__box_size_main_ptr(
+ ctx->horizontal, b);
+ box_size_cross = lh__box_size_cross_ptr(
+ ctx->horizontal, b);
main_pos += *box_size_main + lh__delta_outer_main(
ctx->flex, b);
@@ -854,7 +856,7 @@ static void layout_flex__place_line_items_cross(struct
flex_ctx *ctx,
int *box_pos_cross;
box_pos_cross = ctx->horizontal ? &b->y : &b->x;
- box_size_cross = lh__box_size_cross(ctx->horizontal, b);
+ box_size_cross = lh__box_size_cross_ptr(ctx->horizontal, b);
cross_free_space = line->cross_size + extra - *box_size_cross -
lh__delta_outer_cross(ctx->flex, b);
diff --git a/content/handlers/html/layout_internal.h
b/content/handlers/html/layout_internal.h
index c6eb56d..7367789 100644
--- a/content/handlers/html/layout_internal.h
+++ b/content/handlers/html/layout_internal.h
@@ -244,14 +244,14 @@ static inline int lh__delta_outer_cross(
}
}
-static inline int *lh__box_size_main(
+static inline int *lh__box_size_main_ptr(
bool horizontal,
struct box *b)
{
return horizontal ? &b->width : &b->height;
}
-static inline int *lh__box_size_cross(
+static inline int *lh__box_size_cross_ptr(
bool horizontal,
struct box *b)
{
commitdiff
http://git.netsurf-browser.org/netsurf.git/commit/?id=73ce30325f60310b2bce69b181a1d4f61399a33c
commit 73ce30325f60310b2bce69b181a1d4f61399a33c
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>
html: layout: flex: Scope reduce variables
diff --git a/content/handlers/html/layout_flex.c
b/content/handlers/html/layout_flex.c
index b57f3e3..40e1063 100644
--- a/content/handlers/html/layout_flex.c
+++ b/content/handlers/html/layout_flex.c
@@ -746,12 +746,12 @@ 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++) {
+ enum box_side main_start = ctx->horizontal ? LEFT : TOP;
struct flex_item_data *item = &ctx->item.data[i];
+ int main_pos = ctx->flex->padding[main_start];
struct box *b = item->box;
int *box_pos_main;
commitdiff
http://git.netsurf-browser.org/netsurf.git/commit/?id=3760bbcd2a0b6ce25ab2b38d9f7ac2c79d8713f9
commit 3760bbcd2a0b6ce25ab2b38d9f7ac2c79d8713f9
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>
html: layout: flex: Only distribute positive remaining cross space
diff --git a/content/handlers/html/layout_flex.c
b/content/handlers/html/layout_flex.c
index c9e02a6..b57f3e3 100644
--- a/content/handlers/html/layout_flex.c
+++ b/content/handlers/html/layout_flex.c
@@ -913,7 +913,7 @@ static void layout_flex__place_lines(struct flex_ctx *ctx)
int extra = 0;
if (ctx->available_cross != AUTO &&
- ctx->available_cross != ctx->cross_size &&
+ ctx->available_cross > ctx->cross_size &&
ctx->line.count > 0) {
extra = ctx->available_cross - ctx->cross_size;
commitdiff
http://git.netsurf-browser.org/netsurf.git/commit/?id=b07bda787c02210d018c39d917b02ca0bee87de7
commit b07bda787c02210d018c39d917b02ca0bee87de7
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>
html: layout: flex: Minor code style change
diff --git a/content/handlers/html/layout_flex.c
b/content/handlers/html/layout_flex.c
index b63cb5d..c9e02a6 100644
--- a/content/handlers/html/layout_flex.c
+++ b/content/handlers/html/layout_flex.c
@@ -187,19 +187,16 @@ static bool layout_flex_item(
switch (b->type) {
case BOX_BLOCK:
- success = layout_block_context(b, -1,
- ctx->content);
+ success = layout_block_context(b, -1, ctx->content);
break;
case BOX_TABLE:
b->float_container = b->parent;
- success = layout_table(b, available_width,
- ctx->content);
+ success = layout_table(b, available_width, ctx->content);
b->float_container = NULL;
break;
case BOX_FLEX:
b->float_container = b->parent;
- success = layout_flex(b, available_width,
- ctx->content);
+ success = layout_flex(b, available_width, ctx->content);
b->float_container = NULL;
break;
default:
commitdiff
http://git.netsurf-browser.org/netsurf.git/commit/?id=43d5ce44acdef1686edc0f7cd8579cf4f9f9adfb
commit 43d5ce44acdef1686edc0f7cd8579cf4f9f9adfb
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>
html: layout: flex: Add code documentation
diff --git a/content/handlers/html/layout_flex.c
b/content/handlers/html/layout_flex.c
index 355ae93..b63cb5d 100644
--- a/content/handlers/html/layout_flex.c
+++ b/content/handlers/html/layout_flex.c
@@ -42,6 +42,9 @@
#include "html/box_inspect.h"
#include "html/layout_internal.h"
+/**
+ * Flex item data
+ */
struct flex_item_data {
enum css_flex_basis_e basis;
css_fixed basis_length;
@@ -66,6 +69,9 @@ struct flex_item_data {
bool max_violation;
};
+/**
+ * Flex line data
+ */
struct flex_line_data {
int main_size;
int cross_size;
@@ -77,6 +83,9 @@ struct flex_line_data {
size_t frozen;
};
+/**
+ * Flex layout context
+ */
struct flex_ctx {
html_content *content;
const struct box *flex;
@@ -103,6 +112,11 @@ struct flex_ctx {
} line;
};
+/**
+ * Destroy a flex layout context
+ *
+ * \param[in] ctx Flex layout context
+ */
static void layout_flex_ctx__destroy(struct flex_ctx *ctx)
{
if (ctx != NULL) {
@@ -112,6 +126,13 @@ static void layout_flex_ctx__destroy(struct flex_ctx *ctx)
}
}
+/**
+ * Create a flex layout context
+ *
+ * \param[in] content HTML content containing flex box
+ * \param[in] flex Box to create layout context for
+ * \return flex layout context or NULL on error
+ */
static struct flex_ctx *layout_flex_ctx__create(
html_content *content,
const struct box *flex)
@@ -148,6 +169,14 @@ static struct flex_ctx *layout_flex_ctx__create(
return ctx;
}
+/**
+ * Perform layout on a flex item
+ *
+ * \param[in] ctx Flex layout context
+ * \param[in] item Item to lay out
+ * \param[in] available_width Available width for item in pixels
+ * \return true on success false on failure
+ */
static bool layout_flex_item(
const struct flex_ctx *ctx,
const struct flex_item_data *item,
@@ -186,6 +215,14 @@ static bool layout_flex_item(
return success;
}
+/**
+ * Calculate an item's base and target main sizes.
+ *
+ * \param[in] ctx Flex layout context
+ * \param[in] item Item to get sizes of
+ * \param[in] available_width Available width in pixels
+ * \return true on success false on failure
+ */
static inline bool layout_flex__base_and_main_sizes(
const struct flex_ctx *ctx,
struct flex_item_data *item,
@@ -262,6 +299,13 @@ static inline bool layout_flex__base_and_main_sizes(
return true;
}
+/**
+ * Fill out all item's data in a flex container.
+ *
+ * \param[in] ctx Flex layout context
+ * \param[in] flex Flex box
+ * \param[in] available_width Available width in pixels
+ */
static void layout_flex_ctx__populate_item_data(
const struct flex_ctx *ctx,
const struct box *flex,
@@ -297,6 +341,12 @@ static void layout_flex_ctx__populate_item_data(
}
}
+/**
+ * Ensure context's lines array has a free space
+ *
+ * \param[in] ctx Flex layout context
+ * \return true on success false on out of memory
+ */
static bool layout_flex_ctx__ensure_line(struct flex_ctx *ctx)
{
struct flex_line_data *temp;
@@ -319,6 +369,13 @@ static bool layout_flex_ctx__ensure_line(struct flex_ctx
*ctx)
return true;
}
+/**
+ * Assigns flex items to the line and returns the line
+ *
+ * \param[in] ctx Flex layout context
+ * \param[in] item_index Index to first item to assign to this line
+ * \return Pointer to the new line, or NULL on error.
+ */
static struct flex_line_data *layout_flex__build_line(struct flex_ctx *ctx,
size_t item_index)
{
@@ -371,6 +428,12 @@ static struct flex_line_data
*layout_flex__build_line(struct flex_ctx *ctx,
return line;
}
+/**
+ * Freeze an item on a line
+ *
+ * \param[in] line Line to containing item
+ * \param[in] item Item to freeze
+ */
static inline void layout_flex__item_freeze(
struct flex_line_data *line,
struct flex_item_data *item)
@@ -383,6 +446,17 @@ static inline void layout_flex__item_freeze(
item->box, item->target_main_size);
}
+/**
+ * Calculate remaining free space and unfrozen item factor sum
+ *
+ * \param[in] ctx Flex layout context
+ * \param[in] line Line to calculate free space on
+ * \param[out] unfrozen_factor_sum Returns sum of unfrozen item's flex factors
+ * \param[in] initial_free_main Initial free space in main direction
+ * \param[in] available_main Available space in main direction
+ * \param[in] grow Whether to grow or shrink
+ * return remaining free space on line
+ */
static inline int layout_flex__remaining_free_main(
struct flex_ctx *ctx,
struct flex_line_data *line,
@@ -424,6 +498,13 @@ static inline int layout_flex__remaining_free_main(
return remaining_free_main;
}
+/**
+ * Clamp flex item target main size and get min/max violations
+ *
+ * \param[in] ctx Flex layout context
+ * \param[in] line Line to align items on
+ * return total violation in pixels
+ */
static inline int layout_flex__get_min_max_violations(
struct flex_ctx *ctx,
struct flex_line_data *line)
@@ -480,6 +561,17 @@ static inline int layout_flex__get_min_max_violations(
return total_violation;
}
+/**
+ * Distribute remaining free space proportional to the flex factors.
+ *
+ * Remaining free space may be negative.
+ *
+ * \param[in] ctx Flex layout context
+ * \param[in] line Line to distribute free space on
+ * \param[in] unfrozen_factor_sum Sum of unfrozen item's flex factors
+ * \param[in] remaining_free_main Remaining free space in main direction
+ * \param[in] grow Whether to grow or shrink
+ */
static inline void layout_flex__distribute_free_main(
struct flex_ctx *ctx,
struct flex_line_data *line,
@@ -549,7 +641,15 @@ static inline void layout_flex__distribute_free_main(
}
}
-/** 9.7. Resolving Flexible Lengths */
+/**
+ * Resolve flexible item lengths along a line.
+ *
+ * See 9.7 of Tests CSS Flexible Box Layout Module Level 1.
+ *
+ * \param[in] ctx Flex layout context
+ * \param[in] line Line to resolve
+ * \return true on success, false on failure.
+ */
static bool layout_flex__resolve_line(
struct flex_ctx *ctx,
struct flex_line_data *line)
@@ -638,6 +738,13 @@ static bool layout_flex__resolve_line(
return true;
}
+/**
+ * Position items along a line
+ *
+ * \param[in] ctx Flex layout context
+ * \param[in] line Line to resolve
+ * \return true on success, false on failure.
+ */
static bool layout_flex__place_line_items_main(
struct flex_ctx *ctx,
struct flex_line_data *line)
@@ -686,6 +793,12 @@ static bool layout_flex__place_line_items_main(
return true;
}
+/**
+ * Collect items onto lines and place items along the lines
+ *
+ * \param[in] ctx Flex layout context
+ * \return true on success, false on failure.
+ */
static bool layout_flex__collect_items_into_lines(
struct flex_ctx *ctx)
{
@@ -723,6 +836,13 @@ static bool layout_flex__collect_items_into_lines(
return true;
}
+/**
+ * Align items on a line.
+ *
+ * \param[in] ctx Flex layout context
+ * \param[in] line Line to align items on
+ * \param[in] extra Extra line width in pixels
+ */
static void layout_flex__place_line_items_cross(struct flex_ctx *ctx,
struct flex_line_data *line, int extra)
{
@@ -781,6 +901,11 @@ static void layout_flex__place_line_items_cross(struct
flex_ctx *ctx,
}
}
+/**
+ * Place the lines and align the items on the line.
+ *
+ * \param[in] ctx Flex layout context
+ */
static void layout_flex__place_lines(struct flex_ctx *ctx)
{
bool reversed = ctx->wrap == CSS_FLEX_WRAP_WRAP_REVERSE;
commitdiff
http://git.netsurf-browser.org/netsurf.git/commit/?id=8d4176e4d46cc4e37d2f9ee02e9508aa4a641b54
commit 8d4176e4d46cc4e37d2f9ee02e9508aa4a641b54
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>
html: layout: flex: Hoist item placement out of line resolver
diff --git a/content/handlers/html/layout_flex.c
b/content/handlers/html/layout_flex.c
index a149528..355ae93 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;
commitdiff
http://git.netsurf-browser.org/netsurf.git/commit/?id=6da16e564820e2a958a7266f05fb98b4f252dc49
commit 6da16e564820e2a958a7266f05fb98b4f252dc49
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>
html: layout: flex: Return NULL for pointer
diff --git a/content/handlers/html/layout_flex.c
b/content/handlers/html/layout_flex.c
index feaa4b3..a149528 100644
--- a/content/handlers/html/layout_flex.c
+++ b/content/handlers/html/layout_flex.c
@@ -326,7 +326,7 @@ static struct flex_line_data
*layout_flex__build_line(struct flex_ctx *ctx,
int used_main = 0;
if (!layout_flex_ctx__ensure_line(ctx)) {
- return 0;
+ return NULL;
}
line = &ctx->line.data[ctx->line.count];
commitdiff
http://git.netsurf-browser.org/netsurf.git/commit/?id=fbb39f0d49f2606400dcf6bb2fb1d5c56903ddf9
commit fbb39f0d49f2606400dcf6bb2fb1d5c56903ddf9
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>
html: layout: Helper for whether flex direction is reversed
diff --git a/content/handlers/html/layout_internal.h
b/content/handlers/html/layout_internal.h
index 974f493..c6eb56d 100644
--- a/content/handlers/html/layout_internal.h
+++ b/content/handlers/html/layout_internal.h
@@ -184,6 +184,19 @@ static inline bool lh__flex_main_is_horizontal(const
struct box *flex)
}
}
+static inline bool lh__flex_direction_reversed(const struct box *flex)
+{
+ switch (css_computed_flex_direction(flex->style)) {
+ default: /* Fallthrough. */
+ case CSS_FLEX_DIRECTION_ROW_REVERSE: /* Fallthrough. */
+ case CSS_FLEX_DIRECTION_COLUMN_REVERSE:
+ return true;
+ case CSS_FLEX_DIRECTION_ROW: /* Fallthrough. */
+ case CSS_FLEX_DIRECTION_COLUMN:
+ return false;
+ }
+}
+
static inline int lh__non_auto_margin(const struct box *b, enum box_side side)
{
return (b->margin[side] == AUTO) ? 0 : b->margin[side];
-----------------------------------------------------------------------
Summary of changes:
content/handlers/html/layout_flex.c | 272 ++++++++++++++++++++++++-------
content/handlers/html/layout_internal.h | 31 +++-
2 files changed, 241 insertions(+), 62 deletions(-)
diff --git a/content/handlers/html/layout_flex.c
b/content/handlers/html/layout_flex.c
index feaa4b3..cea7964 100644
--- a/content/handlers/html/layout_flex.c
+++ b/content/handlers/html/layout_flex.c
@@ -42,6 +42,9 @@
#include "html/box_inspect.h"
#include "html/layout_internal.h"
+/**
+ * Flex item data
+ */
struct flex_item_data {
enum css_flex_basis_e basis;
css_fixed basis_length;
@@ -66,6 +69,9 @@ struct flex_item_data {
bool max_violation;
};
+/**
+ * Flex line data
+ */
struct flex_line_data {
int main_size;
int cross_size;
@@ -77,6 +83,9 @@ struct flex_line_data {
size_t frozen;
};
+/**
+ * Flex layout context
+ */
struct flex_ctx {
html_content *content;
const struct box *flex;
@@ -89,6 +98,7 @@ struct flex_ctx {
int available_cross;
bool horizontal;
+ bool main_reversed;
enum css_flex_wrap_e wrap;
struct flex_items {
@@ -103,6 +113,11 @@ struct flex_ctx {
} line;
};
+/**
+ * Destroy a flex layout context
+ *
+ * \param[in] ctx Flex layout context
+ */
static void layout_flex_ctx__destroy(struct flex_ctx *ctx)
{
if (ctx != NULL) {
@@ -112,6 +127,13 @@ static void layout_flex_ctx__destroy(struct flex_ctx *ctx)
}
}
+/**
+ * Create a flex layout context
+ *
+ * \param[in] content HTML content containing flex box
+ * \param[in] flex Box to create layout context for
+ * \return flex layout context or NULL on error
+ */
static struct flex_ctx *layout_flex_ctx__create(
html_content *content,
const struct box *flex)
@@ -144,10 +166,19 @@ static struct flex_ctx *layout_flex_ctx__create(
ctx->wrap = css_computed_flex_wrap(flex->style);
ctx->horizontal = lh__flex_main_is_horizontal(flex);
+ ctx->main_reversed = lh__flex_direction_reversed(flex);
return ctx;
}
+/**
+ * Perform layout on a flex item
+ *
+ * \param[in] ctx Flex layout context
+ * \param[in] item Item to lay out
+ * \param[in] available_width Available width for item in pixels
+ * \return true on success false on failure
+ */
static bool layout_flex_item(
const struct flex_ctx *ctx,
const struct flex_item_data *item,
@@ -158,19 +189,16 @@ static bool layout_flex_item(
switch (b->type) {
case BOX_BLOCK:
- success = layout_block_context(b, -1,
- ctx->content);
+ success = layout_block_context(b, -1, ctx->content);
break;
case BOX_TABLE:
b->float_container = b->parent;
- success = layout_table(b, available_width,
- ctx->content);
+ success = layout_table(b, available_width, ctx->content);
b->float_container = NULL;
break;
case BOX_FLEX:
b->float_container = b->parent;
- success = layout_flex(b, available_width,
- ctx->content);
+ success = layout_flex(b, available_width, ctx->content);
b->float_container = NULL;
break;
default:
@@ -186,6 +214,14 @@ static bool layout_flex_item(
return success;
}
+/**
+ * Calculate an item's base and target main sizes.
+ *
+ * \param[in] ctx Flex layout context
+ * \param[in] item Item to get sizes of
+ * \param[in] available_width Available width in pixels
+ * \return true on success false on failure
+ */
static inline bool layout_flex__base_and_main_sizes(
const struct flex_ctx *ctx,
struct flex_item_data *item,
@@ -262,6 +298,13 @@ static inline bool layout_flex__base_and_main_sizes(
return true;
}
+/**
+ * Fill out all item's data in a flex container.
+ *
+ * \param[in] ctx Flex layout context
+ * \param[in] flex Flex box
+ * \param[in] available_width Available width in pixels
+ */
static void layout_flex_ctx__populate_item_data(
const struct flex_ctx *ctx,
const struct box *flex,
@@ -297,6 +340,12 @@ static void layout_flex_ctx__populate_item_data(
}
}
+/**
+ * Ensure context's lines array has a free space
+ *
+ * \param[in] ctx Flex layout context
+ * \return true on success false on out of memory
+ */
static bool layout_flex_ctx__ensure_line(struct flex_ctx *ctx)
{
struct flex_line_data *temp;
@@ -319,6 +368,13 @@ static bool layout_flex_ctx__ensure_line(struct flex_ctx
*ctx)
return true;
}
+/**
+ * Assigns flex items to the line and returns the line
+ *
+ * \param[in] ctx Flex layout context
+ * \param[in] item_index Index to first item to assign to this line
+ * \return Pointer to the new line, or NULL on error.
+ */
static struct flex_line_data *layout_flex__build_line(struct flex_ctx *ctx,
size_t item_index)
{
@@ -326,7 +382,7 @@ static struct flex_line_data
*layout_flex__build_line(struct flex_ctx *ctx,
int used_main = 0;
if (!layout_flex_ctx__ensure_line(ctx)) {
- return 0;
+ return NULL;
}
line = &ctx->line.data[ctx->line.count];
@@ -371,6 +427,12 @@ static struct flex_line_data
*layout_flex__build_line(struct flex_ctx *ctx,
return line;
}
+/**
+ * Freeze an item on a line
+ *
+ * \param[in] line Line to containing item
+ * \param[in] item Item to freeze
+ */
static inline void layout_flex__item_freeze(
struct flex_line_data *line,
struct flex_item_data *item)
@@ -383,6 +445,17 @@ static inline void layout_flex__item_freeze(
item->box, item->target_main_size);
}
+/**
+ * Calculate remaining free space and unfrozen item factor sum
+ *
+ * \param[in] ctx Flex layout context
+ * \param[in] line Line to calculate free space on
+ * \param[out] unfrozen_factor_sum Returns sum of unfrozen item's flex factors
+ * \param[in] initial_free_main Initial free space in main direction
+ * \param[in] available_main Available space in main direction
+ * \param[in] grow Whether to grow or shrink
+ * return remaining free space on line
+ */
static inline int layout_flex__remaining_free_main(
struct flex_ctx *ctx,
struct flex_line_data *line,
@@ -424,6 +497,13 @@ static inline int layout_flex__remaining_free_main(
return remaining_free_main;
}
+/**
+ * Clamp flex item target main size and get min/max violations
+ *
+ * \param[in] ctx Flex layout context
+ * \param[in] line Line to align items on
+ * return total violation in pixels
+ */
static inline int layout_flex__get_min_max_violations(
struct flex_ctx *ctx,
struct flex_line_data *line)
@@ -480,6 +560,17 @@ static inline int layout_flex__get_min_max_violations(
return total_violation;
}
+/**
+ * Distribute remaining free space proportional to the flex factors.
+ *
+ * Remaining free space may be negative.
+ *
+ * \param[in] ctx Flex layout context
+ * \param[in] line Line to distribute free space on
+ * \param[in] unfrozen_factor_sum Sum of unfrozen item's flex factors
+ * \param[in] remaining_free_main Remaining free space in main direction
+ * \param[in] grow Whether to grow or shrink
+ */
static inline void layout_flex__distribute_free_main(
struct flex_ctx *ctx,
struct flex_line_data *line,
@@ -549,55 +640,15 @@ 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 */
+/**
+ * Resolve flexible item lengths along a line.
+ *
+ * See 9.7 of Tests CSS Flexible Box Layout Module Level 1.
+ *
+ * \param[in] ctx Flex layout context
+ * \param[in] line Line to resolve
+ * \return true on success, false on failure.
+ */
static bool layout_flex__resolve_line(
struct flex_ctx *ctx,
struct flex_line_data *line)
@@ -683,13 +734,98 @@ static bool layout_flex__resolve_line(
}
}
- if (!layout_flex__place_line_items_main(ctx, line)) {
- return false;
+ return true;
+}
+
+/**
+ * Find box side representing the start of flex container in main direction.
+ *
+ * \param[in] ctx Flex layout context.
+ * \return the start side.
+ */
+static enum box_side layout_flex__main_start_side(
+ const struct flex_ctx *ctx)
+{
+ if (ctx->horizontal) {
+ return (ctx->main_reversed) ? RIGHT : LEFT;
+ } else {
+ return (ctx->main_reversed) ? BOTTOM : TOP;
+ }
+}
+
+/**
+ * Position items along a line
+ *
+ * \param[in] ctx Flex layout context
+ * \param[in] line Line to resolve
+ * \return true on success, false on failure.
+ */
+static bool layout_flex__place_line_items_main(
+ struct flex_ctx *ctx,
+ struct flex_line_data *line)
+{
+ int main_pos = ctx->flex->padding[layout_flex__main_start_side(ctx)];
+ int post_multiplier = ctx->main_reversed ? 0 : 1;
+ int pre_multiplier = ctx->main_reversed ? -1 : 0;
+ size_t item_count = line->first + line->count;
+
+ if (ctx->main_reversed) {
+ main_pos = lh__box_size_main(ctx->horizontal, ctx->flex) -
+ main_pos;
+ }
+
+ for (size_t i = line->first; i < item_count; i++) {
+ enum box_side main_start = ctx->horizontal ? LEFT : TOP;
+ struct flex_item_data *item = &ctx->item.data[i];
+ struct box *b = item->box;
+ int box_size_main;
+ 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_size_main = lh__box_size_main(ctx->horizontal, b);
+ box_pos_main = ctx->horizontal ? &b->x : &b->y;
+
+ if (!lh__box_is_absolute(b)) {
+ main_pos += pre_multiplier * (box_size_main +
+ lh__delta_outer_main(ctx->flex, b));
+ }
+
+ *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_cross = lh__box_size_cross(
+ ctx->horizontal, b);
+
+ main_pos += post_multiplier * (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;
}
+/**
+ * Collect items onto lines and place items along the lines
+ *
+ * \param[in] ctx Flex layout context
+ * \return true on success, false on failure.
+ */
static bool layout_flex__collect_items_into_lines(
struct flex_ctx *ctx)
{
@@ -714,6 +850,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;
@@ -723,6 +863,13 @@ static bool layout_flex__collect_items_into_lines(
return true;
}
+/**
+ * Align items on a line.
+ *
+ * \param[in] ctx Flex layout context
+ * \param[in] line Line to align items on
+ * \param[in] extra Extra line width in pixels
+ */
static void layout_flex__place_line_items_cross(struct flex_ctx *ctx,
struct flex_line_data *line, int extra)
{
@@ -737,7 +884,7 @@ static void layout_flex__place_line_items_cross(struct
flex_ctx *ctx,
int *box_pos_cross;
box_pos_cross = ctx->horizontal ? &b->y : &b->x;
- box_size_cross = lh__box_size_cross(ctx->horizontal, b);
+ box_size_cross = lh__box_size_cross_ptr(ctx->horizontal, b);
cross_free_space = line->cross_size + extra - *box_size_cross -
lh__delta_outer_cross(ctx->flex, b);
@@ -781,6 +928,11 @@ static void layout_flex__place_line_items_cross(struct
flex_ctx *ctx,
}
}
+/**
+ * Place the lines and align the items on the line.
+ *
+ * \param[in] ctx Flex layout context
+ */
static void layout_flex__place_lines(struct flex_ctx *ctx)
{
bool reversed = ctx->wrap == CSS_FLEX_WRAP_WRAP_REVERSE;
@@ -791,7 +943,7 @@ static void layout_flex__place_lines(struct flex_ctx *ctx)
int extra = 0;
if (ctx->available_cross != AUTO &&
- ctx->available_cross != ctx->cross_size &&
+ ctx->available_cross > ctx->cross_size &&
ctx->line.count > 0) {
extra = ctx->available_cross - ctx->cross_size;
diff --git a/content/handlers/html/layout_internal.h
b/content/handlers/html/layout_internal.h
index 974f493..d094462 100644
--- a/content/handlers/html/layout_internal.h
+++ b/content/handlers/html/layout_internal.h
@@ -184,6 +184,19 @@ static inline bool lh__flex_main_is_horizontal(const
struct box *flex)
}
}
+static inline bool lh__flex_direction_reversed(const struct box *flex)
+{
+ switch (css_computed_flex_direction(flex->style)) {
+ default: /* Fallthrough. */
+ case CSS_FLEX_DIRECTION_ROW_REVERSE: /* Fallthrough. */
+ case CSS_FLEX_DIRECTION_COLUMN_REVERSE:
+ return true;
+ case CSS_FLEX_DIRECTION_ROW: /* Fallthrough. */
+ case CSS_FLEX_DIRECTION_COLUMN:
+ return false;
+ }
+}
+
static inline int lh__non_auto_margin(const struct box *b, enum box_side side)
{
return (b->margin[side] == AUTO) ? 0 : b->margin[side];
@@ -231,20 +244,34 @@ static inline int lh__delta_outer_cross(
}
}
-static inline int *lh__box_size_main(
+static inline int *lh__box_size_main_ptr(
bool horizontal,
struct box *b)
{
return horizontal ? &b->width : &b->height;
}
-static inline int *lh__box_size_cross(
+static inline int *lh__box_size_cross_ptr(
bool horizontal,
struct box *b)
{
return horizontal ? &b->height : &b->width;
}
+static inline int lh__box_size_main(
+ bool horizontal,
+ const struct box *b)
+{
+ return horizontal ? b->width : b->height;
+}
+
+static inline int lh__box_size_cross(
+ bool horizontal,
+ const struct box *b)
+{
+ return horizontal ? b->height : b->width;
+}
+
static inline bool lh__box_size_cross_is_auto(
bool horizontal,
struct box *b)
--
NetSurf Browser
_______________________________________________
netsurf-commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]