diff options
Diffstat (limited to 'content/handlers/html')
-rw-r--r-- | content/handlers/html/box_construct.c | 7 | ||||
-rw-r--r-- | content/handlers/html/layout.c | 77 | ||||
-rw-r--r-- | content/handlers/html/layout_internal.h | 27 |
3 files changed, 36 insertions, 75 deletions
diff --git a/content/handlers/html/box_construct.c b/content/handlers/html/box_construct.c index 8519c2b1d..559d207cd 100644 --- a/content/handlers/html/box_construct.c +++ b/content/handlers/html/box_construct.c @@ -35,6 +35,7 @@ #include "utils/string.h" #include "utils/ascii.h" #include "utils/nsurl.h" +#include "utils/utils.h" #include "netsurf/misc.h" #include "css/select.h" #include "desktop/gui_internal.h" @@ -552,8 +553,9 @@ box_construct_element(struct box_construct_ctx *ctx, bool *convert_children) if (s != NULL) { const char *val = dom_string_data(s); + /* Convert to a number, clamping to [1,1000] according to 4.9.11 */ if ('0' <= val[0] && val[0] <= '9') - box->columns = strtol(val, NULL, 10); + box->columns = clamp(strtol(val, NULL, 10), 1, 1000); dom_string_unref(s); } @@ -565,8 +567,9 @@ box_construct_element(struct box_construct_ctx *ctx, bool *convert_children) if (s != NULL) { const char *val = dom_string_data(s); + /* Convert to a number, clamping to [0,65534] according to 4.9.11 */ if ('0' <= val[0] && val[0] <= '9') - box->rows = strtol(val, NULL, 10); + box->rows = clamp(strtol(val, NULL, 10), 0, 65534); dom_string_unref(s); } diff --git a/content/handlers/html/layout.c b/content/handlers/html/layout.c index 76ce24df5..d3b6d8f31 100644 --- a/content/handlers/html/layout.c +++ b/content/handlers/html/layout.c @@ -259,15 +259,13 @@ static void layout_minmax_table(struct box *table, const html_content *content) { unsigned int i, j; + int width; int border_spacing_h = 0; int table_min = 0, table_max = 0; int extra_fixed = 0; float extra_frac = 0; struct column *col; struct box *row_group, *row, *cell; - enum css_width_e wtype; - css_fixed value = 0; - css_unit unit = CSS_UNIT_PX; /* check if the widths have already been calculated */ if (table->max_width != UNKNOWN_MAX_WIDTH) @@ -402,12 +400,8 @@ static void layout_minmax_table(struct box *table, } /* fixed width takes priority, unless it is too narrow */ - wtype = css_computed_width(table->style, &value, &unit); - if (wtype == CSS_WIDTH_SET && unit != CSS_UNIT_PCT) { - int width = FIXTOINT(css_unit_len2device_px( - table->style, - &content->unit_len_ctx, - value, unit)); + if (css_computed_width_px(table->style, &content->unit_len_ctx, + -1, &width) == CSS_WIDTH_SET) { if (table_min < width) table_min = width; if (table_max < width) @@ -669,35 +663,28 @@ layout_minmax_line(struct box *first, /* inline replaced, 10.3.2 and 10.6.2 */ assert(b->style); - /* calculate box width */ - wtype = css_computed_width(b->style, &value, &unit); bs = css_computed_box_sizing(block->style); - if (wtype == CSS_WIDTH_SET) { - if (unit == CSS_UNIT_PCT) { - width = AUTO; - } else { - width = FIXTOINT(css_unit_len2device_px( - b->style, - &content->unit_len_ctx, - value, unit)); - if (bs == CSS_BOX_SIZING_BORDER_BOX) { - fixed = frac = 0; - calculate_mbp_width(&content->unit_len_ctx, - block->style, LEFT, - false, true, true, - &fixed, &frac); - calculate_mbp_width(&content->unit_len_ctx, - block->style, RIGHT, - false, true, true, - &fixed, &frac); - if (width < fixed) { - width = fixed; - } + /* calculate box width */ + wtype = css_computed_width_px(b->style, + &content->unit_len_ctx, -1, &width); + if (wtype == CSS_WIDTH_SET) { + if (bs == CSS_BOX_SIZING_BORDER_BOX) { + fixed = frac = 0; + calculate_mbp_width(&content->unit_len_ctx, + block->style, LEFT, + false, true, true, + &fixed, &frac); + calculate_mbp_width(&content->unit_len_ctx, + block->style, RIGHT, + false, true, true, + &fixed, &frac); + if (width < fixed) { + width = fixed; } - if (width < 0) - width = 0; } + if (width < 0) + width = 0; } else { width = AUTO; } @@ -1049,11 +1036,11 @@ static void layout_minmax_block( enum css_min_width_e min_type; css_unit unit = CSS_UNIT_PX; css_fixed value = 0; + int width; - if (wtype == CSS_WIDTH_SET && wunit != CSS_UNIT_PCT) { - min = max = FIXTOINT( - css_unit_len2device_px(block->style, - &content->unit_len_ctx, width, wunit)); + if (css_computed_width_px(block->style, &content->unit_len_ctx, + -1, &width) == CSS_WIDTH_SET) { + min = max = width; using_max_border_box = border_box; using_min_border_box = border_box; } @@ -1629,7 +1616,6 @@ bool layout_table( struct box **row_span_cell; struct column *col; const css_computed_style *style = table->style; - enum css_width_e wtype; enum css_height_e htype; css_fixed value = 0; css_unit unit = CSS_UNIT_PX; @@ -1707,17 +1693,8 @@ bool layout_table( } /* find specified table width, or available width if auto-width */ - wtype = css_computed_width(style, &value, &unit); - if (wtype == CSS_WIDTH_SET) { - if (unit == CSS_UNIT_PCT) { - table_width = FPCT_OF_INT_TOINT(value, available_width); - } else { - table_width = - FIXTOINT(css_unit_len2device_px( - style, &content->unit_len_ctx, - value, unit)); - } - + if (css_computed_width_px(style, &content->unit_len_ctx, + available_width, &table_width) == CSS_WIDTH_SET) { /* specified width includes border */ table_width -= table->border[LEFT].width + table->border[RIGHT].width; diff --git a/content/handlers/html/layout_internal.h b/content/handlers/html/layout_internal.h index d094462ec..568c621d2 100644 --- a/content/handlers/html/layout_internal.h +++ b/content/handlers/html/layout_internal.h @@ -26,9 +26,6 @@ #define AUTO INT_MIN -/* Fixed point percentage (a) of an integer (b), to an integer */ -#define FPCT_OF_INT_TOINT(a, b) (FIXTOINT(FDIV((a * b), F_100))) - /** * Layout a block formatting context. * @@ -450,28 +447,12 @@ static inline void layout_find_dimensions( unsigned int i; if (width) { - enum css_width_e wtype; - css_fixed value = 0; - css_unit unit = CSS_UNIT_PX; - - wtype = css_computed_width(style, &value, &unit); - - if (wtype == CSS_WIDTH_SET) { - if (unit == CSS_UNIT_PCT) { - *width = FPCT_OF_INT_TOINT( - value, available_width); - } else { - *width = FIXTOINT(css_unit_len2device_px( - style, unit_len_ctx, - value, unit)); - } - } else { - *width = AUTO; - } - - if (*width != AUTO) { + if (css_computed_width_px(style, unit_len_ctx, + available_width, width) == CSS_WIDTH_SET) { layout_handle_box_sizing(unit_len_ctx, box, available_width, true, width); + } else { + *width = AUTO; } } |