24#ifndef NETSURF_HTML_LAYOUT_INTERNAL_H
25#define NETSURF_HTML_LAYOUT_INTERNAL_H
30#define FPCT_OF_INT_TOINT(a, b) (FIXTOINT(FDIV((a * b), F_100)))
75 const css_computed_style *style,
76 css_fixed *length, css_unit *unit);
78 const css_computed_style *style);
80 const css_computed_style *style,
159 const css_computed_style *style)
166 return css_computed_position(b->
style) == CSS_POSITION_ABSOLUTE ||
167 css_computed_position(b->
style) == CSS_POSITION_FIXED;
172 const css_computed_style *style = flex->
style;
174 assert(style != NULL);
176 switch (css_computed_flex_direction(style)) {
178 case CSS_FLEX_DIRECTION_ROW:
179 case CSS_FLEX_DIRECTION_ROW_REVERSE:
181 case CSS_FLEX_DIRECTION_COLUMN:
182 case CSS_FLEX_DIRECTION_COLUMN_REVERSE:
189 switch (css_computed_flex_direction(flex->
style)) {
191 case CSS_FLEX_DIRECTION_ROW_REVERSE:
192 case CSS_FLEX_DIRECTION_COLUMN_REVERSE:
194 case CSS_FLEX_DIRECTION_ROW:
195 case CSS_FLEX_DIRECTION_COLUMN:
226 const struct box *flex,
237 const struct box *flex,
283 return css_computed_height(b->
style,
284 &length, &unit) == CSS_HEIGHT_AUTO;
286 return css_computed_width(b->
style,
287 &length, &unit) == CSS_WIDTH_AUTO;
292 const struct box *flex,
293 const struct box *item)
295 enum css_align_self_e align_self = css_computed_align_self(item->
style);
297 if (align_self == CSS_ALIGN_SELF_AUTO) {
298 align_self = css_computed_align_items(flex->
style);
317 const css_unit_ctx *unit_len_ctx,
318 const css_computed_style *style,
327 css_unit unit = CSS_UNIT_PX;
333 enum css_margin_e
type;
336 if (
type == CSS_MARGIN_SET) {
337 if (unit == CSS_UNIT_PCT) {
338 *frac += FIXTOFLT(FDIV(value, F_100));
340 *fixed += FIXTOINT(css_unit_len2device_px(
352 *fixed += FIXTOINT(css_unit_len2device_px(
361 if (unit == CSS_UNIT_PCT) {
362 *frac += FIXTOFLT(FDIV(value, F_100));
364 *fixed += FIXTOINT(css_unit_len2device_px(
386 const css_unit_ctx *unit_len_ctx,
392 enum css_box_sizing_e bs;
396 bs = css_computed_box_sizing(
box->
style);
398 if (bs == CSS_BOX_SIZING_BORDER_BOX) {
399 int orig = *dimension;
405 false,
true,
true, &fixed, &frac);
408 false,
true,
true, &fixed, &frac);
409 orig -= frac * available_width + fixed;
410 *dimension = orig > 0 ? orig : 0;
434 const css_unit_ctx *unit_len_ctx,
438 const css_computed_style *style,
449 struct box *containing_block = NULL;
453 enum css_width_e wtype;
455 css_unit unit = CSS_UNIT_PX;
457 wtype = css_computed_width(
style, &value, &unit);
459 if (wtype == CSS_WIDTH_SET) {
460 if (unit == CSS_UNIT_PCT) {
462 value, available_width);
464 *
width = FIXTOINT(css_unit_len2device_px(
474 available_width,
true,
width);
479 enum css_height_e htype;
481 css_unit unit = CSS_UNIT_PX;
483 htype = css_computed_height(
style, &value, &unit);
485 if (htype == CSS_HEIGHT_SET) {
486 if (unit == CSS_UNIT_PCT) {
487 enum css_height_e cbhtype;
489 if (css_computed_position(
box->
style) ==
490 CSS_POSITION_ABSOLUTE &&
496 css_computed_position(
box->
style) !=
497 CSS_POSITION_ABSOLUTE &&
520 if (containing_block) {
522 css_unit u = CSS_UNIT_PX;
524 cbhtype = css_computed_height(
525 containing_block->
style,
529 if (containing_block &&
531 (css_computed_position(
box->
style) ==
532 CSS_POSITION_ABSOLUTE ||
533 cbhtype == CSS_HEIGHT_SET)) {
539 containing_block->
height);
542 viewport_height >= 0) {
553 *
height = FIXTOINT(css_unit_len2device_px(
563 available_width,
false,
height);
568 enum css_max_width_e
type;
570 css_unit unit = CSS_UNIT_PX;
572 type = css_computed_max_width(
style, &value, &unit);
574 if (
type == CSS_MAX_WIDTH_SET) {
575 if (unit == CSS_UNIT_PCT) {
579 *
max_width = FIXTOINT(css_unit_len2device_px(
595 enum css_min_width_e
type;
597 css_unit unit = CSS_UNIT_PX;
601 if (
type == CSS_MIN_WIDTH_SET) {
602 if (unit == CSS_UNIT_PCT) {
606 *
min_width = FIXTOINT(css_unit_len2device_px(
622 enum css_max_height_e
type;
624 css_unit unit = CSS_UNIT_PX;
626 type = css_computed_max_height(
style, &value, &unit);
628 if (
type == CSS_MAX_HEIGHT_SET) {
629 if (unit == CSS_UNIT_PCT) {
633 *max_height = FIXTOINT(css_unit_len2device_px(
644 enum css_min_height_e
type;
646 css_unit unit = CSS_UNIT_PX;
650 if (
type == CSS_MIN_HEIGHT_SET) {
651 if (unit == CSS_UNIT_PCT) {
655 *min_height = FIXTOINT(css_unit_len2device_px(
665 for (i = 0; i != 4; i++) {
667 enum css_margin_e
type = CSS_MARGIN_AUTO;
669 css_unit unit = CSS_UNIT_PX;
673 if (
type == CSS_MARGIN_SET) {
674 if (unit == CSS_UNIT_PCT) {
678 margin[i] = FIXTOINT(css_unit_len2device_px(
689 css_unit unit = CSS_UNIT_PX;
693 if (unit == CSS_UNIT_PCT) {
697 padding[i] = FIXTOINT(css_unit_len2device_px(
705 enum css_border_style_e bstyle = CSS_BORDER_STYLE_NONE;
708 css_unit unit = CSS_UNIT_PX;
717 if (bstyle == CSS_BORDER_STYLE_HIDDEN ||
718 bstyle == CSS_BORDER_STYLE_NONE)
728 if (css_computed_border_collapse(
style) ==
729 CSS_BORDER_COLLAPSE_COLLAPSE &&
static uint8_t ns_computed_min_height(const css_computed_style *style, css_fixed *length, css_unit *unit)
static uint8_t ns_computed_min_width(const css_computed_style *style, css_fixed *length, css_unit *unit)
static bool lh__flex_direction_reversed(const struct box *flex)
#define FPCT_OF_INT_TOINT(a, b)
static bool lh__flex_main_is_horizontal(const struct box *flex)
static bool lh__box_is_object(const struct box *b)
Layout helper: Check whether box is an object.
static int lh__delta_outer_main(const struct box *flex, const struct box *b)
uint8_t(* css_border_style_func)(const css_computed_style *style)
static bool lh__box_is_flex_container(const struct box *b)
Layout helper: Check whether box takes part in inline flow.
static bool lh__box_is_replace(const struct box *b)
Layout helper: Check whether box is replaced.
bool layout_block_context(struct box *block, int viewport_height, html_content *content)
Layout a block formatting context.
const css_border_style_func border_style_funcs[4]
Array of per-side access functions for computed style border styles.
static int * lh__box_size_cross_ptr(bool horizontal, struct box *b)
static int * lh__box_size_main_ptr(bool horizontal, struct box *b)
bool layout_flex(struct box *flex, int available_width, html_content *content)
Layout a flex container.
static void calculate_mbp_width(const css_unit_ctx *unit_len_ctx, const css_computed_style *style, unsigned int side, bool margin, bool border, bool padding, int *fixed, float *frac)
Determine width of margin, borders, and padding on one side of a box.
static bool lh__box_is_absolute(const struct box *b)
bool layout_table(struct box *table, int available_width, html_content *content)
Layout a table.
static bool lh__have_border(enum box_side side, const css_computed_style *style)
Layout helper: Check for CSS border on given side.
static int lh__box_size_main(bool horizontal, const struct box *b)
static void layout_handle_box_sizing(const css_unit_ctx *unit_len_ctx, const struct box *box, int available_width, bool setwidth, int *dimension)
Adjust a specified width or height for the box-sizing property.
const css_border_color_func border_color_funcs[4]
Array of per-side access functions for computed style border colors.
uint8_t(* css_len_func)(const css_computed_style *style, css_fixed *length, css_unit *unit)
const css_len_func border_width_funcs[4]
Array of per-side access functions for computed style border_widths.
static int lh__delta_outer_height(const struct box *b)
static int lh__box_size_cross(bool horizontal, const struct box *b)
static bool lh__box_is_inline_content(const struct box *b)
Layout helper: Check whether box is inline level.
static void layout_find_dimensions(const css_unit_ctx *unit_len_ctx, int available_width, int viewport_height, const struct box *box, const css_computed_style *style, int *width, int *height, int *max_width, int *min_width, int *max_height, int *min_height, int margin[4], int padding[4], struct box_border border[4])
Calculate width, height, and thickness of margins, paddings, and borders.
static enum css_align_self_e lh__box_align_self(const struct box *flex, const struct box *item)
static bool lh__box_is_flex_item(const struct box *b)
Layout helper: Check whether box takes part in inline flow.
static int lh__delta_outer_width(const struct box *b)
static bool lh__box_is_inline_level(const struct box *b)
Layout helper: Check whether box is inline level.
static int lh__delta_outer_cross(const struct box *flex, const struct box *b)
static int lh__non_auto_margin(const struct box *b, enum box_side side)
static bool lh__box_is_inline_flow(const struct box *b)
Layout helper: Check whether box takes part in inline flow.
uint8_t(* css_border_color_func)(const css_computed_style *style, css_color *color)
const css_len_func padding_funcs[4]
Array of per-side access functions for computed style paddings.
static bool lh__box_is_float_box(const struct box *b)
Layout helper: Check whether box is a float.
const css_len_func margin_funcs[4]
Array of per-side access functions for computed style margins.
static bool lh__box_size_cross_is_auto(bool horizontal, struct box *b)
Container for border values during table border calculations.
enum css_border_style_e style
border-style
css_fixed width
border-width length
css_color c
border-color value
Container for box border details.
int width
border-width (pixels)
struct box_border border[4]
Border: TOP, RIGHT, BOTTOM, LEFT.
int min_width
Width of box taking all line breaks (including margins etc).
int width
Width of content box (excluding padding etc.).
struct box * parent
Parent box, or NULL.
int height
Height of content box (excluding padding etc.).
struct box * float_container
If box is a float, points to box's containing block.
int margin[4]
Margin: TOP, RIGHT, BOTTOM, LEFT.
int max_width
Width that would be taken with no line breaks.
box_type type
Type of box.
css_computed_style * style
Style for this box.
struct hlcache_handle * object
Object in this box (usually an image), or NULL if none.
int padding[4]
Padding: TOP, RIGHT, BOTTOM, LEFT.
box_flags flags
Box flags.
struct form_control * gadget
Form control data, or NULL if not a form control.
Content which corresponds to a single URL.
Data specific to CONTENT_HTML.