NetSurf
|
HTML layout implementation: display: flex. More...
#include <string.h>
#include "utils/log.h"
#include "utils/utils.h"
#include "html/box.h"
#include "html/html.h"
#include "html/private.h"
#include "html/box_inspect.h"
#include "html/layout_internal.h"
Go to the source code of this file.
Data Structures | |
struct | flex_item_data |
Flex item data. More... | |
struct | flex_line_data |
Flex line data. More... | |
struct | flex_ctx |
Flex layout context. More... | |
struct | flex_ctx::flex_items |
struct | flex_ctx::flex_lines |
Functions | |
static void | layout_flex_ctx__destroy (struct flex_ctx *ctx) |
Destroy a flex layout context. More... | |
static struct flex_ctx * | layout_flex_ctx__create (html_content *content, const struct box *flex) |
Create a flex layout context. More... | |
static enum box_side | layout_flex__main_start_side (const struct flex_ctx *ctx) |
Find box side representing the start of flex container in main direction. More... | |
static enum box_side | layout_flex__main_end_side (const struct flex_ctx *ctx) |
Find box side representing the end of flex container in main direction. More... | |
static bool | layout_flex_item (const struct flex_ctx *ctx, const struct flex_item_data *item, int available_width) |
Perform layout on a flex item. More... | |
static bool | layout_flex__base_and_main_sizes (const struct flex_ctx *ctx, struct flex_item_data *item, int available_width) |
Calculate an item's base and target main sizes. More... | |
static void | layout_flex_ctx__populate_item_data (const struct flex_ctx *ctx, const struct box *flex, int available_width) |
Fill out all item's data in a flex container. More... | |
static bool | layout_flex_ctx__ensure_line (struct flex_ctx *ctx) |
Ensure context's lines array has a free space. More... | |
static struct flex_line_data * | layout_flex__build_line (struct flex_ctx *ctx, size_t item_index) |
Assigns flex items to the line and returns the line. More... | |
static void | layout_flex__item_freeze (struct flex_line_data *line, struct flex_item_data *item) |
Freeze an item on a line. More... | |
static int | layout_flex__remaining_free_main (struct flex_ctx *ctx, struct flex_line_data *line, css_fixed *unfrozen_factor_sum, int initial_free_main, int available_main, bool grow) |
Calculate remaining free space and unfrozen item factor sum. More... | |
static int | layout_flex__get_min_max_violations (struct flex_ctx *ctx, struct flex_line_data *line) |
Clamp flex item target main size and get min/max violations. More... | |
static void | layout_flex__distribute_free_main (struct flex_ctx *ctx, struct flex_line_data *line, css_fixed unfrozen_factor_sum, int remaining_free_main, bool grow) |
Distribute remaining free space proportional to the flex factors. More... | |
static bool | layout_flex__resolve_line (struct flex_ctx *ctx, struct flex_line_data *line) |
Resolve flexible item lengths along a line. More... | |
static bool | layout_flex__place_line_items_main (struct flex_ctx *ctx, struct flex_line_data *line) |
Position items along a line. More... | |
static bool | layout_flex__collect_items_into_lines (struct flex_ctx *ctx) |
Collect items onto lines and place items along the lines. More... | |
static void | layout_flex__place_line_items_cross (struct flex_ctx *ctx, struct flex_line_data *line, int extra) |
Align items on a line. More... | |
static void | layout_flex__place_lines (struct flex_ctx *ctx) |
Place the lines and align the items on the line. More... | |
bool | layout_flex (struct box *flex, int available_width, html_content *content) |
Layout a flex container. More... | |
HTML layout implementation: display: flex.
Layout is carried out in two stages:
In most cases the functions for the two stages are a corresponding pair layout_minmax_X() and layout_X().
Definition in file layout_flex.c.
bool layout_flex | ( | struct box * | flex, |
int | available_width, | ||
html_content * | content | ||
) |
Layout a flex container.
[in] | flex | table to layout |
[in] | available_width | width of containing block |
[in] | content | memory pool for any new boxes |
Definition at line 1046 of file layout_flex.c.
References AUTO, flex_ctx::available_cross, flex_ctx::available_main, box::border, flex_ctx::cross_size, flex_ctx::flex, box::height, flex_ctx::horizontal, layout_find_dimensions(), layout_flex__collect_items_into_lines(), layout_flex__place_lines(), layout_flex_ctx__create(), layout_flex_ctx__destroy(), layout_flex_ctx__populate_item_data(), flex_ctx::main_size, box::margin, min, NSLOG, box::padding, box::style, flex_ctx::unit_len_ctx, and box::width.
Referenced by layout_absolute(), layout_block_context(), layout_flex_item(), and layout_float().
|
inlinestatic |
Calculate an item's base and target main sizes.
[in] | ctx | Flex layout context |
[in] | item | Item to get sizes of |
[in] | available_width | Available width in pixels |
Definition at line 260 of file layout_flex.c.
References AUTO, flex_item_data::base_size, flex_item_data::basis, flex_item_data::basis_length, flex_item_data::basis_unit, flex_item_data::box, flex_ctx::flex, box::height, flex_ctx::horizontal, layout_flex_item(), lh__delta_outer_main(), lh__delta_outer_width(), flex_item_data::main_size, max, flex_item_data::max_main, box::max_width, min, flex_item_data::min_main, box::min_width, NSLOG, box::style, flex_item_data::target_main_size, flex_ctx::unit_len_ctx, and box::width.
Referenced by layout_flex_ctx__populate_item_data().
|
static |
Assigns flex items to the line and returns the line.
[in] | ctx | Flex layout context |
[in] | item_index | Index to first item to assign to this line |
Definition at line 413 of file layout_flex.c.
References AUTO, flex_ctx::available_main, flex_item_data::box, flex_ctx::flex_lines::count, flex_ctx::flex_items::data, flex_ctx::flex_lines::data, flex_ctx::flex, box::height, flex_ctx::horizontal, flex_ctx::item, layout_flex__main_end_side(), layout_flex__main_start_side(), layout_flex_ctx__ensure_line(), lh__box_is_absolute(), lh__delta_outer_main(), flex_item_data::line, flex_ctx::line, line(), flex_item_data::main_size, box::margin, NSLOG, and flex_ctx::wrap.
Referenced by layout_flex__collect_items_into_lines().
|
static |
Collect items onto lines and place items along the lines.
[in] | ctx | Flex layout context |
Definition at line 898 of file layout_flex.c.
References flex_ctx::flex_items::count, flex_ctx::cross_size, flex_ctx::flex, flex_ctx::item, layout_flex__build_line(), layout_flex__place_line_items_main(), layout_flex__resolve_line(), line(), flex_ctx::main_size, NSLOG, and flex_line_data::pos.
Referenced by layout_flex().
|
inlinestatic |
Distribute remaining free space proportional to the flex factors.
Remaining free space may be negative.
[in] | ctx | Flex layout context |
[in] | line | Line to distribute free space on |
[in] | unfrozen_factor_sum | Sum of unfrozen item's flex factors |
[in] | remaining_free_main | Remaining free space in main direction |
[in] | grow | Whether to grow or shrink |
Definition at line 622 of file layout_flex.c.
References flex_item_data::base_size, flex_ctx::flex_items::data, flex_item_data::freeze, flex_item_data::grow, flex_ctx::item, layout_flex__item_freeze(), line(), flex_item_data::main_size, result, flex_item_data::shrink, and flex_item_data::target_main_size.
Referenced by layout_flex__resolve_line().
|
inlinestatic |
Clamp flex item target main size and get min/max violations.
[in] | ctx | Flex layout context |
[in] | line | Line to align items on return total violation in pixels |
Definition at line 555 of file layout_flex.c.
References flex_item_data::box, flex_ctx::flex_items::data, flex_item_data::freeze, flex_ctx::item, line(), flex_item_data::max_main, flex_item_data::max_violation, flex_item_data::min_main, flex_item_data::min_violation, box::min_width, NSLOG, and flex_item_data::target_main_size.
Referenced by layout_flex__resolve_line().
|
inlinestatic |
Freeze an item on a line.
[in] | line | Line to containing item |
[in] | item | Item to freeze |
Definition at line 480 of file layout_flex.c.
References flex_item_data::box, flex_item_data::freeze, lh__box_is_absolute(), line(), NSLOG, and flex_item_data::target_main_size.
Referenced by layout_flex__distribute_free_main(), and layout_flex__resolve_line().
Find box side representing the end of flex container in main direction.
[in] | ctx | Flex layout context. |
Definition at line 199 of file layout_flex.c.
References BOTTOM, flex_ctx::horizontal, LEFT, flex_ctx::main_reversed, RIGHT, and TOP.
Referenced by layout_flex__build_line().
Find box side representing the start of flex container in main direction.
[in] | ctx | Flex layout context. |
Definition at line 183 of file layout_flex.c.
References BOTTOM, flex_ctx::horizontal, LEFT, flex_ctx::main_reversed, RIGHT, and TOP.
Referenced by layout_flex__build_line(), and layout_flex__place_line_items_main().
|
static |
Align items on a line.
[in] | ctx | Flex layout context |
[in] | line | Line to align items on |
[in] | extra | Extra line width in pixels |
Definition at line 942 of file layout_flex.c.
References box::border, flex_item_data::box, flex_ctx::flex_items::data, fallthrough, flex_ctx::flex, flex_ctx::horizontal, flex_ctx::item, layout_flex_item(), LEFT, lh__box_align_self(), lh__box_size_cross_is_auto(), lh__box_size_cross_ptr(), lh__delta_outer_cross(), lh__non_auto_margin(), line(), box::padding, TOP, box_border::width, box::width, box::x, and box::y.
Referenced by layout_flex__place_lines().
|
static |
Position items along a line.
[in] | ctx | Flex layout context |
[in] | line | Line to resolve |
Definition at line 805 of file layout_flex.c.
References AUTO, flex_ctx::available_main, box::border, BOTTOM, flex_item_data::box, flex_ctx::flex_items::data, flex_ctx::flex, flex_ctx::horizontal, flex_ctx::item, layout_flex__main_start_side(), layout_flex_item(), LEFT, lh__box_is_absolute(), lh__box_size_cross(), lh__box_size_main(), lh__delta_outer_cross(), lh__delta_outer_main(), lh__delta_outer_width(), lh__non_auto_margin(), line(), flex_ctx::main_reversed, box::margin, box::padding, RIGHT, flex_item_data::target_main_size, TOP, UNKNOWN_WIDTH, box_border::width, box::width, box::x, and box::y.
Referenced by layout_flex__collect_items_into_lines().
|
static |
Place the lines and align the items on the line.
[in] | ctx | Flex layout context |
Definition at line 1003 of file layout_flex.c.
References AUTO, flex_ctx::available_cross, flex_ctx::flex_lines::count, flex_ctx::cross_size, flex_ctx::flex_lines::data, layout_flex__place_line_items_cross(), flex_ctx::line, line(), and flex_ctx::wrap.
Referenced by layout_flex().
|
inlinestatic |
Calculate remaining free space and unfrozen item factor sum.
[in] | ctx | Flex layout context |
[in] | line | Line to calculate free space on |
[out] | unfrozen_factor_sum | Returns sum of unfrozen item's flex factors |
[in] | initial_free_main | Initial free space in main direction |
[in] | available_main | Available space in main direction |
[in] | grow | Whether to grow or shrink return remaining free space on line |
Definition at line 507 of file layout_flex.c.
References flex_item_data::base_size, flex_ctx::flex_items::data, flex_item_data::freeze, flex_item_data::grow, flex_ctx::item, line(), NSLOG, flex_item_data::shrink, and flex_item_data::target_main_size.
Referenced by layout_flex__resolve_line().
|
static |
Resolve flexible item lengths along a line.
See 9.7 of Tests CSS Flexible Box Layout Module Level 1.
[in] | ctx | Flex layout context |
[in] | line | Line to resolve |
Definition at line 706 of file layout_flex.c.
References AUTO, flex_ctx::available_main, flex_item_data::base_size, flex_ctx::flex_items::data, flex_ctx::flex_lines::data, flex_ctx::flex, flex_item_data::freeze, flex_item_data::grow, flex_ctx::item, layout_flex__distribute_free_main(), layout_flex__get_min_max_violations(), layout_flex__item_freeze(), layout_flex__remaining_free_main(), flex_ctx::line, line(), flex_item_data::main_size, flex_item_data::max_violation, flex_item_data::min_violation, NSLOG, flex_item_data::shrink, and flex_item_data::target_main_size.
Referenced by layout_flex__collect_items_into_lines().
|
static |
Create a flex layout context.
[in] | content | HTML content containing flex box |
[in] | flex | Box to create layout context for |
Definition at line 140 of file layout_flex.c.
References flex_ctx::flex_lines::alloc, box_count_children(), flex_ctx::content, flex_ctx::flex_items::count, flex_ctx::flex_items::data, flex_ctx::flex_lines::data, flex_ctx::flex, flex_ctx::horizontal, flex_ctx::item, layout_flex_ctx__destroy(), lh__flex_direction_reversed(), lh__flex_main_is_horizontal(), flex_ctx::line, flex_ctx::main_reversed, box::style, flex_ctx::unit_len_ctx, and flex_ctx::wrap.
Referenced by layout_flex().
|
static |
Destroy a flex layout context.
[in] | ctx | Flex layout context |
Definition at line 124 of file layout_flex.c.
References flex_ctx::flex_items::data, flex_ctx::flex_lines::data, flex_ctx::item, and flex_ctx::line.
Referenced by layout_flex(), and layout_flex_ctx__create().
|
static |
Ensure context's lines array has a free space.
[in] | ctx | Flex layout context |
Definition at line 384 of file layout_flex.c.
References flex_ctx::flex_lines::alloc, flex_ctx::flex_lines::count, flex_ctx::flex_lines::data, and flex_ctx::line.
Referenced by layout_flex__build_line().
|
static |
Fill out all item's data in a flex container.
[in] | ctx | Flex layout context |
[in] | flex | Flex box |
[in] | available_width | Available width in pixels |
Definition at line 343 of file layout_flex.c.
References flex_item_data::basis, flex_item_data::basis_length, flex_item_data::basis_unit, flex_item_data::box, box::children, flex_ctx::flex_items::data, flex_item_data::grow, flex_ctx::horizontal, flex_ctx::item, layout_find_dimensions(), layout_flex__base_and_main_sizes(), flex_item_data::max_cross, flex_item_data::max_main, flex_item_data::min_cross, flex_item_data::min_main, box::next, NSLOG, flex_item_data::shrink, flex_ctx::unit_len_ctx, and box::width.
Referenced by layout_flex().
|
static |
Perform layout on a flex item.
[in] | ctx | Flex layout context |
[in] | item | Item to lay out |
[in] | available_width | Available width for item in pixels |
Definition at line 217 of file layout_flex.c.
References flex_item_data::box, BOX_BLOCK, BOX_FLEX, BOX_TABLE, flex_ctx::content, box::float_container, layout_block_context(), layout_flex(), layout_table, NSLOG, box::parent, and box::type.
Referenced by layout_flex__base_and_main_sizes(), layout_flex__place_line_items_cross(), and layout_flex__place_line_items_main().