summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Drake <michael.drake@codethink.co.uk>2019-12-08 13:02:56 +0000
committerMichael Drake <michael.drake@codethink.co.uk>2019-12-22 11:26:45 +0000
commit93bed2cc67ba149801f2dfd1919e92aceed0e323 (patch)
treed8e8662ed760f26b1a44d27e756c3e314e77eaf4
parentfb4f1d28ba4d2b0935ac56a3d37ea9fa52c5de51 (diff)
downloadnetsurf-93bed2cc67ba149801f2dfd1919e92aceed0e323.tar.gz
netsurf-93bed2cc67ba149801f2dfd1919e92aceed0e323.tar.bz2
CSS: Simplify css display to box type conversion.
-rw-r--r--content/handlers/css/dump.c8
-rw-r--r--content/handlers/css/utils.h36
-rw-r--r--content/handlers/html/box_construct.c72
3 files changed, 44 insertions, 72 deletions
diff --git a/content/handlers/css/dump.c b/content/handlers/css/dump.c
index b12e1d9e8..3d17b36b1 100644
--- a/content/handlers/css/dump.c
+++ b/content/handlers/css/dump.c
@@ -823,7 +823,7 @@ void nscss_dump_computed_style(FILE *stream, const css_computed_style *style)
}
/* display */
- val = ns_computed_display_static(style);
+ val = css_computed_display_static(style);
switch (val) {
case CSS_DISPLAY_INLINE:
fprintf(stream, "display: inline ");
@@ -873,6 +873,12 @@ void nscss_dump_computed_style(FILE *stream, const css_computed_style *style)
case CSS_DISPLAY_NONE:
fprintf(stream, "display: none ");
break;
+ case CSS_DISPLAY_FLEX:
+ fprintf(stream, "display: flex ");
+ break;
+ case CSS_DISPLAY_INLINE_FLEX:
+ fprintf(stream, "display: inline-flax ");
+ break;
default:
break;
}
diff --git a/content/handlers/css/utils.h b/content/handlers/css/utils.h
index e35a6605b..05ab73882 100644
--- a/content/handlers/css/utils.h
+++ b/content/handlers/css/utils.h
@@ -105,42 +105,6 @@ static inline css_fixed nscss_pixels_physical_to_css(
nscss_screen_dpi);
}
-/**
- * Temporary helper wrappers for for libcss computed style getter, while
- * we don't support flexbox related property values.
- */
-
-static inline uint8_t ns_computed_display(
- const css_computed_style *style, bool root)
-{
- uint8_t value = css_computed_display(style, root);
-
- if (value == CSS_DISPLAY_FLEX) {
- return CSS_DISPLAY_BLOCK;
-
- } else if (value == CSS_DISPLAY_INLINE_FLEX) {
- return CSS_DISPLAY_INLINE_BLOCK;
- }
-
- return value;
-}
-
-
-static inline uint8_t ns_computed_display_static(
- const css_computed_style *style)
-{
- uint8_t value = css_computed_display_static(style);
-
- if (value == CSS_DISPLAY_FLEX) {
- return CSS_DISPLAY_BLOCK;
-
- } else if (value == CSS_DISPLAY_INLINE_FLEX) {
- return CSS_DISPLAY_INLINE_BLOCK;
- }
-
- return value;
-}
-
static inline uint8_t ns_computed_min_height(
const css_computed_style *style,
diff --git a/content/handlers/html/box_construct.c b/content/handlers/html/box_construct.c
index 6271405fe..f545785cd 100644
--- a/content/handlers/html/box_construct.c
+++ b/content/handlers/html/box_construct.c
@@ -213,23 +213,25 @@ nserror cancel_dom_to_box(void *box_conversion_context)
/* mapping from CSS display to box type
* this table must be in sync with libcss' css_display enum */
static const box_type box_map[] = {
- 0, /*CSS_DISPLAY_INHERIT,*/
- BOX_INLINE, /*CSS_DISPLAY_INLINE,*/
- BOX_BLOCK, /*CSS_DISPLAY_BLOCK,*/
- BOX_BLOCK, /*CSS_DISPLAY_LIST_ITEM,*/
- BOX_INLINE, /*CSS_DISPLAY_RUN_IN,*/
- BOX_INLINE_BLOCK, /*CSS_DISPLAY_INLINE_BLOCK,*/
- BOX_TABLE, /*CSS_DISPLAY_TABLE,*/
- BOX_TABLE, /*CSS_DISPLAY_INLINE_TABLE,*/
- BOX_TABLE_ROW_GROUP, /*CSS_DISPLAY_TABLE_ROW_GROUP,*/
- BOX_TABLE_ROW_GROUP, /*CSS_DISPLAY_TABLE_HEADER_GROUP,*/
- BOX_TABLE_ROW_GROUP, /*CSS_DISPLAY_TABLE_FOOTER_GROUP,*/
- BOX_TABLE_ROW, /*CSS_DISPLAY_TABLE_ROW,*/
- BOX_NONE, /*CSS_DISPLAY_TABLE_COLUMN_GROUP,*/
- BOX_NONE, /*CSS_DISPLAY_TABLE_COLUMN,*/
- BOX_TABLE_CELL, /*CSS_DISPLAY_TABLE_CELL,*/
- BOX_INLINE, /*CSS_DISPLAY_TABLE_CAPTION,*/
- BOX_NONE /*CSS_DISPLAY_NONE*/
+ BOX_BLOCK, /* CSS_DISPLAY_INHERIT */
+ BOX_INLINE, /* CSS_DISPLAY_INLINE */
+ BOX_BLOCK, /* CSS_DISPLAY_BLOCK */
+ BOX_BLOCK, /* CSS_DISPLAY_LIST_ITEM */
+ BOX_INLINE, /* CSS_DISPLAY_RUN_IN */
+ BOX_INLINE_BLOCK, /* CSS_DISPLAY_INLINE_BLOCK */
+ BOX_TABLE, /* CSS_DISPLAY_TABLE */
+ BOX_TABLE, /* CSS_DISPLAY_INLINE_TABLE */
+ BOX_TABLE_ROW_GROUP, /* CSS_DISPLAY_TABLE_ROW_GROUP */
+ BOX_TABLE_ROW_GROUP, /* CSS_DISPLAY_TABLE_HEADER_GROUP */
+ BOX_TABLE_ROW_GROUP, /* CSS_DISPLAY_TABLE_FOOTER_GROUP */
+ BOX_TABLE_ROW, /* CSS_DISPLAY_TABLE_ROW */
+ BOX_NONE, /* CSS_DISPLAY_TABLE_COLUMN_GROUP */
+ BOX_NONE, /* CSS_DISPLAY_TABLE_COLUMN */
+ BOX_TABLE_CELL, /* CSS_DISPLAY_TABLE_CELL */
+ BOX_INLINE, /* CSS_DISPLAY_TABLE_CAPTION */
+ BOX_NONE, /* CSS_DISPLAY_NONE */
+ BOX_BLOCK, /* CSS_DISPLAY_FLEX */
+ BOX_INLINE_BLOCK, /* CSS_DISPLAY_INLINE_FLEX */
};
/* Exported function, see box.h */
@@ -637,7 +639,7 @@ static void box_construct_generate(dom_node *n, html_content *content,
}
/* create box for this element */
- computed_display = ns_computed_display(style, box_is_root(n));
+ computed_display = css_computed_display(style, box_is_root(n));
if (computed_display == CSS_DISPLAY_BLOCK ||
computed_display == CSS_DISPLAY_TABLE) {
/* currently only support block level boxes */
@@ -650,7 +652,7 @@ static void box_construct_generate(dom_node *n, html_content *content,
}
/* set box type from computed display */
- gen->type = box_map[ns_computed_display(
+ gen->type = box_map[css_computed_display(
style, box_is_root(n))];
box_add_child(box, gen);
@@ -759,6 +761,7 @@ bool box_construct_element(struct box_construct_ctx *ctx,
{
dom_string *title0, *s;
lwc_string *id = NULL;
+ enum css_display_e css_display;
struct box *box = NULL, *old_box;
css_select_results *styles = NULL;
struct element_entry *element;
@@ -858,16 +861,15 @@ bool box_construct_element(struct box_construct_ctx *ctx,
dom_string_unref(s);
}
+ css_display = css_computed_display_static(box->style);
+
/* Set box type from computed display */
if ((css_computed_position(box->style) == CSS_POSITION_ABSOLUTE ||
- css_computed_position(box->style) ==
- CSS_POSITION_FIXED) &&
- (ns_computed_display_static(box->style) ==
- CSS_DISPLAY_INLINE ||
- ns_computed_display_static(box->style) ==
- CSS_DISPLAY_INLINE_BLOCK ||
- ns_computed_display_static(box->style) ==
- CSS_DISPLAY_INLINE_TABLE)) {
+ css_computed_position(box->style) == CSS_POSITION_FIXED) &&
+ (css_display == CSS_DISPLAY_INLINE ||
+ css_display == CSS_DISPLAY_INLINE_BLOCK ||
+ css_display == CSS_DISPLAY_INLINE_TABLE ||
+ css_display == CSS_DISPLAY_INLINE_FLEX)) {
/* Special case for absolute positioning: make absolute inlines
* into inline block so that the boxes are constructed in an
* inline container as if they were not absolutely positioned.
@@ -879,7 +881,7 @@ bool box_construct_element(struct box_construct_ctx *ctx,
box->type = BOX_BLOCK;
} else {
/* Normal mapping */
- box->type = box_map[ns_computed_display(box->style,
+ box->type = box_map[css_computed_display(box->style,
props.node_is_root)];
}
@@ -907,7 +909,7 @@ bool box_construct_element(struct box_construct_ctx *ctx,
box->styles->styles[CSS_PSEUDO_ELEMENT_BEFORE]);
}
- if (box->type == BOX_NONE || (ns_computed_display(box->style,
+ if (box->type == BOX_NONE || (css_computed_display(box->style,
props.node_is_root) == CSS_DISPLAY_NONE &&
props.node_is_root == false)) {
css_select_results_destroy(styles);
@@ -999,7 +1001,7 @@ bool box_construct_element(struct box_construct_ctx *ctx,
box_add_child(props.inline_container, box);
} else {
- if (ns_computed_display(box->style, props.node_is_root) ==
+ if (css_computed_display(box->style, props.node_is_root) ==
CSS_DISPLAY_LIST_ITEM) {
/* List item: compute marker */
if (box_construct_marker(box, props.title, ctx,
@@ -1593,7 +1595,7 @@ bool box_image(BOX_SPECIAL_PARAMS)
css_unit wunit = CSS_UNIT_PX;
css_unit hunit = CSS_UNIT_PX;
- if (box->style && ns_computed_display(box->style,
+ if (box->style && css_computed_display(box->style,
box_is_root(n)) == CSS_DISPLAY_NONE)
return true;
@@ -1700,7 +1702,7 @@ bool box_object(BOX_SPECIAL_PARAMS)
dom_node *c;
dom_exception err;
- if (box->style && ns_computed_display(box->style,
+ if (box->style && css_computed_display(box->style,
box_is_root(n)) == CSS_DISPLAY_NONE)
return true;
@@ -2357,7 +2359,7 @@ bool box_iframe(BOX_SPECIAL_PARAMS)
struct content_html_iframe *iframe;
int i;
- if (box->style && ns_computed_display(box->style,
+ if (box->style && css_computed_display(box->style,
box_is_root(n)) == CSS_DISPLAY_NONE)
return true;
@@ -2601,7 +2603,7 @@ bool box_input(BOX_SPECIAL_PARAMS)
gadget->type = GADGET_IMAGE;
if (box->style &&
- ns_computed_display(box->style,
+ css_computed_display(box->style,
box_is_root(n)) != CSS_DISPLAY_NONE &&
nsoption_bool(foreground_images) == true) {
dom_string *s;
@@ -2941,7 +2943,7 @@ bool box_embed(BOX_SPECIAL_PARAMS)
dom_string *src;
dom_exception err;
- if (box->style && ns_computed_display(box->style,
+ if (box->style && css_computed_display(box->style,
box_is_root(n)) == CSS_DISPLAY_NONE)
return true;