diff options
author | Michael Drake <michael.drake@codethink.co.uk> | 2019-03-10 14:44:19 +0000 |
---|---|---|
committer | Michael Drake <michael.drake@codethink.co.uk> | 2019-03-10 14:54:57 +0000 |
commit | 0da84ebf34d68cc1f89d057086fdd0f24747b258 (patch) | |
tree | dd31a9b001e750ef247d849bdadee622b3955267 | |
parent | 74ecce7e2dd5272a9978970307d288613d1d171e (diff) | |
download | libcss-0da84ebf34d68cc1f89d057086fdd0f24747b258.tar.gz libcss-0da84ebf34d68cc1f89d057086fdd0f24747b258.tar.bz2 |
Media queries: Make css_parse_media_query return the parsed css_mq_query.
This converts the experimental code to test the media query parsing into
a useful function.
-rw-r--r-- | src/stylesheet.c | 37 |
1 files changed, 28 insertions, 9 deletions
diff --git a/src/stylesheet.c b/src/stylesheet.c index 07b9019..7c1fb83 100644 --- a/src/stylesheet.c +++ b/src/stylesheet.c @@ -113,14 +113,22 @@ css_error css__stylesheet_string_get(css_stylesheet *sheet, return CSS_OK; } -static css_error css_parse_media_query_handle_event(css_parser_event type, - const parserutils_vector *tokens, void *pw) +typedef struct css_mq_parse_ctx { + lwc_string **strings; + css_mq_query *media; +} css_mq_parse_ctx; + +static css_error css_parse_media_query_handle_event( + css_parser_event type, + const parserutils_vector *tokens, + void *pw) { int idx = 0; css_error err; css_mq_query *media; const css_token *tok; - lwc_string **strings = pw; + css_mq_parse_ctx *ctx = pw; + lwc_string **strings = ctx->strings; UNUSED(type); @@ -139,22 +147,28 @@ static css_error css_parse_media_query_handle_event(css_parser_event type, return CSS_OK; } - css__mq_query_destroy(media); + ctx->media = media; return CSS_OK; } -static css_error css_parse_media_query(lwc_string **strings, - const uint8_t *mq, size_t len) +static css_error css_parse_media_query( + lwc_string **strings, + const uint8_t *mq, + size_t len, + css_mq_query **media_out) { css_error err; css_parser *parser; + css_mq_parse_ctx ctx = { + .strings = strings, + }; css_parser_optparams params_quirks = { .quirks = false, }; css_parser_optparams params_handler = { .event_handler = { .handler = css_parse_media_query_handle_event, - .pw = strings, + .pw = &ctx, }, }; @@ -200,6 +214,7 @@ static css_error css_parse_media_query(lwc_string **strings, css__parser_destroy(parser); + *media_out = ctx.media; return CSS_OK; } @@ -235,9 +250,13 @@ css_error css_stylesheet_create(const css_stylesheet_params *params, free(sheet); return error; } -css_parse_media_query(sheet->propstrings, + + css_mq_query *media; + error = css_parse_media_query(sheet->propstrings, (const uint8_t *)"screen and (min-width: 30em)", - strlen("screen and (min-width: 30em)")); + strlen("screen and (min-width: 30em)"), &media); + if (error == CSS_OK) + css__mq_query_destroy(media); sheet->inline_style = params->inline_style; |