mirror of
https://github.com/netsurf-browser/netsurf
synced 2024-12-21 03:32:35 +03:00
Change hints handling to use new libcss API.
Collect hints and provide them up front. Note this implementation is minimal effort, and quite inefficient. We can be faster about it by walking the element's attributes, and caching things set on ancestor elements which apply to the current element. (Mostly table, and body stuff.)
This commit is contained in:
parent
ae485432c5
commit
e42afd9b32
277
css/hints.c
277
css/hints.c
@ -28,6 +28,9 @@
|
|||||||
#include "css/hints.h"
|
#include "css/hints.h"
|
||||||
#include "css/select.h"
|
#include "css/select.h"
|
||||||
|
|
||||||
|
#define LOG_STATS
|
||||||
|
#undef LOG_STATS
|
||||||
|
|
||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
* Utility functions *
|
* Utility functions *
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
@ -1711,77 +1714,209 @@ static css_error node_presentational_hint_background_image(
|
|||||||
return CSS_PROPERTY_NOT_SET;
|
return CSS_PROPERTY_NOT_SET;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Exported function, documeted in css/hints.h */
|
struct css_hint_ctx {
|
||||||
css_error node_presentational_hint(void *pw, void *node,
|
struct css_hint *hints;
|
||||||
uint32_t property, css_hint *hint)
|
uint32_t alloc;
|
||||||
|
uint32_t len;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct css_hint_ctx hint_ctx;
|
||||||
|
|
||||||
|
static void css_hint_destroy(struct css_hint_ctx *hint)
|
||||||
{
|
{
|
||||||
|
hint->alloc = 0;
|
||||||
switch (property) {
|
hint->len = 0;
|
||||||
case CSS_PROP_BACKGROUND_IMAGE:
|
free(hint->hints);
|
||||||
return node_presentational_hint_background_image(pw, node, hint);
|
}
|
||||||
|
|
||||||
case CSS_PROP_BACKGROUND_COLOR:
|
static nserror css_hint_extend(struct css_hint_ctx *hint)
|
||||||
return node_presentational_hint_background_color(pw, node, hint);
|
{
|
||||||
case CSS_PROP_CAPTION_SIDE:
|
uint32_t alloc = (hint->alloc == 0) ? 32 : hint->alloc * 2;
|
||||||
return node_presentational_hint_caption_side(pw, node, hint);
|
struct css_hint *temp;
|
||||||
|
|
||||||
case CSS_PROP_COLOR:
|
temp = realloc(hint->hints, sizeof(struct css_hint) * alloc);
|
||||||
return node_presentational_hint_color(pw, node, hint);
|
if (temp != NULL) {
|
||||||
|
hint->hints = temp;
|
||||||
case CSS_PROP_FLOAT:
|
hint->alloc = alloc;
|
||||||
return node_presentational_hint_float(pw, node, hint);
|
|
||||||
|
return NSERROR_OK;
|
||||||
case CSS_PROP_FONT_SIZE:
|
}
|
||||||
return node_presentational_hint_font_size(pw, node, hint);
|
|
||||||
|
return NSERROR_NOMEM;
|
||||||
case CSS_PROP_HEIGHT:
|
}
|
||||||
return node_presentational_hint_height(pw, node, hint);
|
|
||||||
|
nserror css_hint_init(void)
|
||||||
case CSS_PROP_WIDTH:
|
{
|
||||||
return node_presentational_hint_width(pw, node, hint);
|
nserror err;
|
||||||
|
|
||||||
case CSS_PROP_BORDER_SPACING:
|
err = css_hint_extend(&hint_ctx);
|
||||||
return node_presentational_hint_border_spacing(pw, node, hint);
|
if (err != NSERROR_OK) {
|
||||||
|
return err;
|
||||||
case CSS_PROP_BORDER_TOP_COLOR :
|
}
|
||||||
case CSS_PROP_BORDER_RIGHT_COLOR :
|
|
||||||
case CSS_PROP_BORDER_BOTTOM_COLOR :
|
return NSERROR_OK;
|
||||||
case CSS_PROP_BORDER_LEFT_COLOR :
|
}
|
||||||
return node_presentational_hint_border_trbl_color(pw, node, hint);
|
|
||||||
|
void css_hint_fini(void)
|
||||||
case CSS_PROP_BORDER_TOP_STYLE :
|
{
|
||||||
case CSS_PROP_BORDER_RIGHT_STYLE :
|
css_hint_destroy(&hint_ctx);
|
||||||
case CSS_PROP_BORDER_BOTTOM_STYLE :
|
}
|
||||||
case CSS_PROP_BORDER_LEFT_STYLE :
|
|
||||||
return node_presentational_hint_border_trbl_style(pw, node, hint);
|
|
||||||
|
/* Exported function, documeted in css/hints.h */
|
||||||
case CSS_PROP_BORDER_TOP_WIDTH :
|
static inline css_error node_presentational_hint_internal(
|
||||||
case CSS_PROP_BORDER_RIGHT_WIDTH :
|
void *pw, void *node, struct css_hint_ctx *hints)
|
||||||
case CSS_PROP_BORDER_BOTTOM_WIDTH :
|
{
|
||||||
case CSS_PROP_BORDER_LEFT_WIDTH :
|
struct css_hint_ctx *ctx = hints;
|
||||||
return node_presentational_hint_border_trbl_width(pw, node, hint);
|
uint32_t property;
|
||||||
|
nserror nserr;
|
||||||
case CSS_PROP_MARGIN_TOP :
|
css_error err;
|
||||||
case CSS_PROP_MARGIN_BOTTOM :
|
|
||||||
return node_presentational_hint_margin_tb(pw, node, hint);
|
ctx->len = 0;
|
||||||
|
|
||||||
case CSS_PROP_MARGIN_RIGHT:
|
for (property = 0; property < CSS_N_PROPERTIES; property++) {
|
||||||
case CSS_PROP_MARGIN_LEFT:
|
css_hint *hint = &(ctx->hints[ctx->len]);
|
||||||
return node_presentational_hint_margin_rl(pw, node, hint, property);
|
|
||||||
|
if (ctx->alloc == 0 || ctx->len == ctx->alloc - 1) {
|
||||||
case CSS_PROP_PADDING_TOP:
|
nserr = css_hint_extend(ctx);
|
||||||
case CSS_PROP_PADDING_RIGHT :
|
if (nserr != NSERROR_OK) {
|
||||||
case CSS_PROP_PADDING_BOTTOM :
|
return NSERROR_NOMEM;
|
||||||
case CSS_PROP_PADDING_LEFT:
|
}
|
||||||
return node_presentational_hint_padding_trbl(pw, node, hint);
|
}
|
||||||
|
|
||||||
case CSS_PROP_TEXT_ALIGN:
|
switch (property) {
|
||||||
return node_presentational_hint_text_align(pw, node, hint);
|
case CSS_PROP_BACKGROUND_IMAGE:
|
||||||
|
err = node_presentational_hint_background_image(
|
||||||
case CSS_PROP_VERTICAL_ALIGN:
|
pw, node, hint);
|
||||||
return node_presentational_hint_vertical_align(pw, node, hint);
|
break;
|
||||||
}
|
|
||||||
|
case CSS_PROP_BACKGROUND_COLOR:
|
||||||
return CSS_PROPERTY_NOT_SET;
|
err = node_presentational_hint_background_color(
|
||||||
|
pw, node, hint);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CSS_PROP_CAPTION_SIDE:
|
||||||
|
err = node_presentational_hint_caption_side(
|
||||||
|
pw, node, hint);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CSS_PROP_COLOR:
|
||||||
|
err = node_presentational_hint_color(
|
||||||
|
pw, node, hint);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CSS_PROP_FLOAT:
|
||||||
|
err = node_presentational_hint_float(
|
||||||
|
pw, node, hint);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CSS_PROP_FONT_SIZE:
|
||||||
|
err = node_presentational_hint_font_size(
|
||||||
|
pw, node, hint);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CSS_PROP_HEIGHT:
|
||||||
|
err = node_presentational_hint_height(
|
||||||
|
pw, node, hint);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CSS_PROP_WIDTH:
|
||||||
|
err = node_presentational_hint_width(
|
||||||
|
pw, node, hint);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CSS_PROP_BORDER_SPACING:
|
||||||
|
err = node_presentational_hint_border_spacing(
|
||||||
|
pw, node, hint);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CSS_PROP_BORDER_TOP_COLOR:
|
||||||
|
case CSS_PROP_BORDER_RIGHT_COLOR:
|
||||||
|
case CSS_PROP_BORDER_BOTTOM_COLOR:
|
||||||
|
case CSS_PROP_BORDER_LEFT_COLOR:
|
||||||
|
err = node_presentational_hint_border_trbl_color(
|
||||||
|
pw, node, hint);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CSS_PROP_BORDER_TOP_STYLE:
|
||||||
|
case CSS_PROP_BORDER_RIGHT_STYLE:
|
||||||
|
case CSS_PROP_BORDER_BOTTOM_STYLE:
|
||||||
|
case CSS_PROP_BORDER_LEFT_STYLE:
|
||||||
|
err = node_presentational_hint_border_trbl_style(
|
||||||
|
pw, node, hint);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CSS_PROP_BORDER_TOP_WIDTH:
|
||||||
|
case CSS_PROP_BORDER_RIGHT_WIDTH:
|
||||||
|
case CSS_PROP_BORDER_BOTTOM_WIDTH:
|
||||||
|
case CSS_PROP_BORDER_LEFT_WIDTH:
|
||||||
|
err = node_presentational_hint_border_trbl_width(
|
||||||
|
pw, node, hint);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CSS_PROP_MARGIN_TOP:
|
||||||
|
case CSS_PROP_MARGIN_BOTTOM:
|
||||||
|
err = node_presentational_hint_margin_tb(
|
||||||
|
pw, node, hint);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CSS_PROP_MARGIN_RIGHT:
|
||||||
|
case CSS_PROP_MARGIN_LEFT:
|
||||||
|
err = node_presentational_hint_margin_rl(
|
||||||
|
pw, node, hint, property);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CSS_PROP_PADDING_TOP:
|
||||||
|
case CSS_PROP_PADDING_RIGHT:
|
||||||
|
case CSS_PROP_PADDING_BOTTOM:
|
||||||
|
case CSS_PROP_PADDING_LEFT:
|
||||||
|
err = node_presentational_hint_padding_trbl(
|
||||||
|
pw, node, hint);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CSS_PROP_TEXT_ALIGN:
|
||||||
|
err = node_presentational_hint_text_align(
|
||||||
|
pw, node, hint);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CSS_PROP_VERTICAL_ALIGN:
|
||||||
|
err = node_presentational_hint_vertical_align(
|
||||||
|
pw, node, hint);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
err = CSS_PROPERTY_NOT_SET;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (err == CSS_OK) {
|
||||||
|
hint->prop = property;
|
||||||
|
ctx->len++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return CSS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Exported function, documeted in css/hints.h */
|
||||||
|
css_error node_presentational_hint(void *pw, void *node,
|
||||||
|
uint32_t *nhints, css_hint **hints)
|
||||||
|
{
|
||||||
|
css_error err;
|
||||||
|
|
||||||
|
err = node_presentational_hint_internal(pw, node, &hint_ctx);
|
||||||
|
if (err != CSS_OK) {
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef LOG_STATS
|
||||||
|
LOG("Properties with hints: %i", hint_ctx.len);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
*nhints = hint_ctx.len;
|
||||||
|
*hints = hint_ctx.hints;
|
||||||
|
|
||||||
|
return CSS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,7 +23,8 @@
|
|||||||
|
|
||||||
#include "css/css.h"
|
#include "css/css.h"
|
||||||
|
|
||||||
|
nserror css_hint_init(void);
|
||||||
|
void css_hint_fini(void);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -40,8 +41,8 @@
|
|||||||
css_error node_presentational_hint(
|
css_error node_presentational_hint(
|
||||||
void *pw,
|
void *pw,
|
||||||
void *node,
|
void *node,
|
||||||
uint32_t property,
|
uint32_t *nhints,
|
||||||
css_hint *hint);
|
css_hint **hints);
|
||||||
|
|
||||||
bool nscss_parse_colour(const char *data, css_color *result);
|
bool nscss_parse_colour(const char *data, css_color *result);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user