Gitweb links:
...log
http://git.netsurf-browser.org/libcss.git/shortlog/44feffba4ab7178cca1dbdb4e218d6a93861f804
...commit
http://git.netsurf-browser.org/libcss.git/commit/44feffba4ab7178cca1dbdb4e218d6a93861f804
...tree
http://git.netsurf-browser.org/libcss.git/tree/44feffba4ab7178cca1dbdb4e218d6a93861f804
The branch, tlsa/jmb/mq2 has been updated
via 44feffba4ab7178cca1dbdb4e218d6a93861f804 (commit)
via 9f526a19e9f6085cd0bda8b45b7f2dc347ca5a5b (commit)
via 5d1a706bfc5d25ea0fc2060772e44222ea711df5 (commit)
via d6126aa77eb442f446d28b6dfb15a884f209a341 (commit)
via 171cb33082983c145ac9818b94e38f486c5f407b (commit)
via c0ce0471b979d6fe39a16c7aed4f183922219e2e (commit)
via f6bc2001832f1941ea40d52ab1333f3ceb76348a (commit)
from 27657ff21c4dfff87ef1830cecdbef5dffec9910 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commitdiff
http://git.netsurf-browser.org/libcss.git/commit/?id=44feffba4ab7178cca1dbdb4e218d6a93861f804
commit 44feffba4ab7178cca1dbdb4e218d6a93861f804
Author: Michael Drake <Michael Drake [email protected]>
Commit: Michael Drake <Michael Drake [email protected]>
Example: Update for new API for media queries.
diff --git a/examples/example1.c b/examples/example1.c
index 1c0dcf9..c36a94d 100644
--- a/examples/example1.c
+++ b/examples/example1.c
@@ -161,6 +161,9 @@ int main(int argc, char **argv)
uint32_t count;
unsigned int hh;
css_stylesheet_params params;
+ css_media media = {
+ .type = CSS_MEDIA_SCREEN,
+ };
UNUSED(argc);
UNUSED(argv);
@@ -210,7 +213,7 @@ int main(int argc, char **argv)
if (code != CSS_OK)
die("css_select_ctx_create", code);
code = css_select_ctx_append_sheet(select_ctx, sheet, CSS_ORIGIN_AUTHOR,
- CSS_MEDIA_ALL);
+ NULL);
if (code != CSS_OK)
die("css_select_ctx_append_sheet", code);
code = css_select_ctx_count_sheets(select_ctx, &count);
@@ -234,7 +237,7 @@ int main(int argc, char **argv)
lwc_intern_string(element, strlen(element), &element_name);
code = css_select_style(select_ctx, element_name,
- CSS_MEDIA_SCREEN, NULL,
+ &media, NULL,
&select_handler, 0,
&style);
if (code != CSS_OK)
commitdiff
http://git.netsurf-browser.org/libcss.git/commit/?id=9f526a19e9f6085cd0bda8b45b7f2dc347ca5a5b
commit 9f526a19e9f6085cd0bda8b45b7f2dc347ca5a5b
Author: Michael Drake <Michael Drake [email protected]>
Commit: Michael Drake <Michael Drake [email protected]>
Tests: Update for new API for media queries.
Signed-off-by: Michael Drake <Michael Drake [email protected]>
diff --git a/test/select.c b/test/select.c
index f21d937..664994e 100644
--- a/test/select.c
+++ b/test/select.c
@@ -42,7 +42,7 @@ typedef struct node {
typedef struct sheet_ctx {
css_stylesheet *sheet;
css_origin origin;
- uint64_t media;
+ char *media;
} sheet_ctx;
typedef struct line_ctx {
@@ -62,7 +62,7 @@ typedef struct line_ctx {
uint32_t n_sheets;
sheet_ctx *sheets;
- uint64_t media;
+ css_media media;
uint32_t pseudo_element;
node *target;
@@ -77,7 +77,7 @@ static bool handle_line(const char *data, size_t datalen,
void *pw);
static void css__parse_tree(line_ctx *ctx, const char *data, size_t len);
static void css__parse_tree_data(line_ctx *ctx, const char *data, size_t len);
static void css__parse_sheet(line_ctx *ctx, const char *data, size_t len);
-static void css__parse_media_list(const char **data, size_t *len, uint64_t
*media);
+static void css__parse_media_list(const char **data, size_t *len, css_media
*media);
static void css__parse_pseudo_list(const char **data, size_t *len,
uint32_t *element);
static void css__parse_expected(line_ctx *ctx, const char *data, size_t len);
@@ -363,7 +363,7 @@ void css__parse_tree(line_ctx *ctx, const char *data,
size_t len)
/* [ <media_list> <pseudo>? ] ? */
- ctx->media = CSS_MEDIA_ALL;
+ ctx->media.type = CSS_MEDIA_ALL;
ctx->pseudo_element = CSS_PSEUDO_ELEMENT_NONE;
/* Consume any leading whitespace */
@@ -515,9 +515,9 @@ void css__parse_sheet(line_ctx *ctx, const char *data,
size_t len)
const char *p;
const char *end = data + len;
css_origin origin = CSS_ORIGIN_AUTHOR;
- uint64_t media = CSS_MEDIA_ALL;
css_stylesheet *sheet;
sheet_ctx *temp;
+ char *media = NULL;
/* <origin> <media_list>? */
@@ -540,11 +540,11 @@ void css__parse_sheet(line_ctx *ctx, const char *data,
size_t len)
while (p < end && isspace(*p))
p++;
- if (p < end) {
- size_t ignored = end - p;
-
- css__parse_media_list(&p, &ignored, &media);
- }
+ assert(end >= p);
+ media = malloc(end - p + 1);
+ assert(media != NULL);
+ memcpy(media, p, end - p);
+ media[end - p] = '\0';
params.params_version = CSS_STYLESHEET_PARAMS_VERSION_1;
params.level = CSS_LEVEL_21;
@@ -579,7 +579,7 @@ void css__parse_sheet(line_ctx *ctx, const char *data,
size_t len)
ctx->n_sheets++;
}
-void css__parse_media_list(const char **data, size_t *len, uint64_t *media)
+void css__parse_media_list(const char **data, size_t *len, css_media *media)
{
const char *p = *data;
const char *end = p + *len;
@@ -646,7 +646,7 @@ void css__parse_media_list(const char **data, size_t *len,
uint64_t *media)
p++;
}
- *media = result;
+ media->type = result;
*data = p;
*len = end - p;
@@ -765,7 +765,7 @@ static void run_test_select_tree(css_select_ctx *select,
css_select_results *sr;
struct node *n = NULL;
- assert(css_select_style(select, node, ctx->media, NULL,
+ assert(css_select_style(select, node, &ctx->media, NULL,
&select_handler, ctx, &sr) == CSS_OK);
if (node->parent != NULL) {
@@ -841,6 +841,7 @@ void run_test(line_ctx *ctx, const char *exp, size_t explen)
for (i = 0; i < ctx->n_sheets; i++) {
css_stylesheet_destroy(ctx->sheets[i].sheet);
+ free(ctx->sheets[i].media);
}
ctx->tree = NULL;
commitdiff
http://git.netsurf-browser.org/libcss.git/commit/?id=5d1a706bfc5d25ea0fc2060772e44222ea711df5
commit 5d1a706bfc5d25ea0fc2060772e44222ea711df5
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>
Media queries: Update selection API to support media queries.
The API changes are:
1. When building a selection context, stylesheets added with
`css_select_ctx_{append|insert}_sheet()` now have to have
media strings associcated with them. Previously they took
a simple bitfield for CSS media type.
2. When selecting for an element, the client needs to specify
the current media requirements. Previously it only had to
provide the bitfield for CSS media type.
3. Same for the css_select_font_faces API.
The selection handling has been updated to handle the new
API, however it is currently only looking at the media type
when performing selection.
Signed-off-by: Michael Drake <[email protected]>
diff --git a/include/libcss/select.h b/include/libcss/select.h
index f1de409..ca57456 100644
--- a/include/libcss/select.h
+++ b/include/libcss/select.h
@@ -206,10 +206,10 @@ css_error css_select_ctx_destroy(css_select_ctx *ctx);
css_error css_select_ctx_append_sheet(css_select_ctx *ctx,
const css_stylesheet *sheet,
- css_origin origin, uint64_t media);
+ css_origin origin, const char *media);
css_error css_select_ctx_insert_sheet(css_select_ctx *ctx,
const css_stylesheet *sheet, uint32_t index,
- css_origin origin, uint64_t media);
+ css_origin origin, const char *media);
css_error css_select_ctx_remove_sheet(css_select_ctx *ctx,
const css_stylesheet *sheet);
@@ -221,13 +221,13 @@ css_error css_select_default_style(css_select_ctx *ctx,
css_select_handler *handler, void *pw,
css_computed_style **style);
css_error css_select_style(css_select_ctx *ctx, void *node,
- uint64_t media, const css_stylesheet *inline_style,
+ const css_media *media, const css_stylesheet *inline_style,
css_select_handler *handler, void *pw,
css_select_results **result);
css_error css_select_results_destroy(css_select_results *results);
css_error css_select_font_faces(css_select_ctx *ctx,
- uint64_t media, lwc_string *font_family,
+ const css_media *media, lwc_string *font_family,
css_select_font_faces_results **result);
css_error css_select_font_faces_results_destroy(
css_select_font_faces_results *results);
diff --git a/src/select/computed.c b/src/select/computed.c
index ebb2b29..506b079 100644
--- a/src/select/computed.c
+++ b/src/select/computed.c
@@ -250,7 +250,7 @@ css_error css__computed_style_initialise(css_computed_style
*style,
return CSS_BADPARM;
state.node = NULL;
- state.media = CSS_MEDIA_ALL;
+ state.media = NULL;
state.results = NULL;
state.computed = style;
state.handler = handler;
diff --git a/src/select/hash.h b/src/select/hash.h
index 71f610f..aecf15a 100644
--- a/src/select/hash.h
+++ b/src/select/hash.h
@@ -25,7 +25,7 @@ struct css_hash_selection_requirments {
lwc_string *class; /* Name of class, or NULL */
lwc_string *id; /* Name of id, or NULL */
lwc_string *uni; /* Universal element string "*" */
- uint64_t media; /* Media type(s) we're selecting for */
+ const css_media *media; /* Media spec we're selecting for */
const css_bloom *node_bloom; /* Node's bloom filter */
};
diff --git a/src/select/mq.h b/src/select/mq.h
index 4fe67b0..290505c 100644
--- a/src/select/mq.h
+++ b/src/select/mq.h
@@ -32,11 +32,11 @@ static inline bool mq_match_condition(css_mq_cond *cond)
* \meaid media Current media spec, to check against m.
* \return true if media query list matches media
*/
-static inline bool mq__list_match(const css_mq_query *m, uint64_t media)
+static inline bool mq__list_match(const css_mq_query *m, const css_media
*media)
{
for (; m != NULL; m = m->next) {
/* Check type */
- if (!!(m->type & media) != m->negate_type) {
+ if (!!(m->type & media->type) != m->negate_type) {
if (mq_match_condition(m->cond)) {
/* We have a match, no need to look further. */
return true;
@@ -54,7 +54,7 @@ static inline bool mq__list_match(const css_mq_query *m,
uint64_t media)
* \param media Current media type(s)
* \return true iff chain's rule applies for media
*/
-static inline bool mq_rule_good_for_media(const css_rule *rule, uint64_t media)
+static inline bool mq_rule_good_for_media(const css_rule *rule, const
css_media *media)
{
bool applies = true;
const css_rule *ancestor = rule;
diff --git a/src/select/select.c b/src/select/select.c
index 480b9f5..1b0cadd 100644
--- a/src/select/select.c
+++ b/src/select/select.c
@@ -38,7 +38,7 @@
typedef struct css_select_sheet {
const css_stylesheet *sheet; /**< Stylesheet */
css_origin origin; /**< Stylesheet origin */
- uint64_t media; /**< Applicable media */
+ css_mq_query *media; /**< Applicable media */
} css_select_sheet;
/**
@@ -97,7 +97,7 @@ typedef struct css_select_font_faces_list {
*/
typedef struct css_select_font_faces_state {
lwc_string *font_family;
- uint64_t media;
+ const css_media *media;
css_select_font_faces_list ua_font_faces;
css_select_font_faces_list user_font_faces;
@@ -289,8 +289,12 @@ css_error css_select_ctx_destroy(css_select_ctx *ctx)
if (ctx->default_style != NULL)
css_computed_style_destroy(ctx->default_style);
- if (ctx->sheets != NULL)
+ if (ctx->sheets != NULL) {
+ for (uint32_t index = 0; index < ctx->n_sheets; index++) {
+ css__mq_query_destroy(ctx->sheets[index].media);
+ }
free(ctx->sheets);
+ }
free(ctx);
@@ -303,12 +307,12 @@ css_error css_select_ctx_destroy(css_select_ctx *ctx)
* \param ctx The context to append to
* \param sheet The sheet to append
* \param origin Origin of the sheet
- * \param media Media types to which the sheet applies
+ * \param media Media string for the stylesheet
* \return CSS_OK on success, appropriate error otherwise
*/
css_error css_select_ctx_append_sheet(css_select_ctx *ctx,
const css_stylesheet *sheet, css_origin origin,
- uint64_t media)
+ const char *media)
{
if (ctx == NULL || sheet == NULL)
return CSS_BADPARM;
@@ -324,14 +328,16 @@ css_error css_select_ctx_append_sheet(css_select_ctx *ctx,
* \param sheet Sheet to insert
* \param index Index in context to insert sheet
* \param origin Origin of the sheet
- * \param media Media types to which the sheet applies
+ * \param media Media string for the stylesheet
* \return CSS_OK on success, appropriate error otherwise
*/
css_error css_select_ctx_insert_sheet(css_select_ctx *ctx,
const css_stylesheet *sheet, uint32_t index,
- css_origin origin, uint64_t media)
+ css_origin origin, const char *media)
{
css_select_sheet *temp;
+ css_mq_query *mq;
+ css_error error;
if (ctx == NULL || sheet == NULL)
return CSS_BADPARM;
@@ -357,9 +363,23 @@ css_error css_select_ctx_insert_sheet(css_select_ctx *ctx,
(ctx->n_sheets - index) * sizeof(css_select_sheet));
}
+ error = css_parse_media_query(sheet->propstrings,
+ (const uint8_t *)media,
+ (media == NULL) ? 0 : strlen(media), &mq);
+ if (error == CSS_NOMEM) {
+ return error;
+ } else if (error != CSS_OK) {
+ /* Fall back to default media: "all". */
+ mq = calloc(1, sizeof(*mq));
+ if (mq == NULL) {
+ return CSS_NOMEM;
+ }
+ mq->type = CSS_MEDIA_ALL;
+ }
+
ctx->sheets[index].sheet = sheet;
ctx->sheets[index].origin = origin;
- ctx->sheets[index].media = media;
+ ctx->sheets[index].media = mq;
ctx->n_sheets++;
@@ -389,6 +409,8 @@ css_error css_select_ctx_remove_sheet(css_select_ctx *ctx,
if (index == ctx->n_sheets)
return CSS_INVALID;
+ css__mq_query_destroy(ctx->sheets[index].media);
+
ctx->n_sheets--;
memmove(&ctx->sheets[index], &ctx->sheets[index + 1],
@@ -1032,7 +1054,7 @@ static void css_select__finalise_selection_state(
* \param[in] state The selection state to initialise
* \param[in] node The node we are selecting for.
* \param[in] parent The node's parent node, or NULL.
- * \param[in] media The media type we're selecting for.
+ * \param[in] media The media specification we're selecting for.
* \param[in] handler The client selection callback table.
* \param[in] pw The client private data, passsed out to callbacks.
* \return CSS_OK or appropriate error otherwise.
@@ -1041,7 +1063,7 @@ static css_error css_select__initialise_selection_state(
css_select_state *state,
void *node,
void *parent,
- uint64_t media,
+ const css_media *media,
css_select_handler *handler,
void *pw)
{
@@ -1142,7 +1164,7 @@ failed:
*
* \param ctx Selection context to use
* \param node Node to select style for
- * \param media Currently active media types
+ * \param media Currently active media specification
* \param inline_style Corresponding inline style for node, or NULL
* \param handler Dispatch table of handler functions
* \param pw Client-specific private data for handler functions
@@ -1159,7 +1181,7 @@ failed:
* update the fully computed style for a node when layout changes.
*/
css_error css_select_style(css_select_ctx *ctx, void *node,
- uint64_t media, const css_stylesheet *inline_style,
+ const css_media *media, const css_stylesheet *inline_style,
css_select_handler *handler, void *pw,
css_select_results **result)
{
@@ -1244,7 +1266,7 @@ css_error css_select_style(css_select_ctx *ctx, void
*node,
for (i = 0; i < ctx->n_sheets; i++) {
const css_select_sheet s = ctx->sheets[i];
- if ((s.media & media) != 0 &&
+ if (mq__list_match(s.media, media) &&
s.sheet->disabled == false) {
error = select_from_sheet(ctx, s.sheet,
s.origin, &state);
@@ -1394,13 +1416,13 @@ css_error css_select_results_destroy(css_select_results
*results)
* Search a selection context for defined font faces
*
* \param ctx Selection context
- * \param media Currently active media types
+ * \param media Currently active media spec
* \param font_family Font family to search for
* \param result Pointer to location to receive result
* \return CSS_OK on success, appropriate error otherwise.
*/
css_error css_select_font_faces(css_select_ctx *ctx,
- uint64_t media, lwc_string *font_family,
+ const css_media *media, lwc_string *font_family,
css_select_font_faces_results **result)
{
uint32_t i;
@@ -1421,7 +1443,7 @@ css_error css_select_font_faces(css_select_ctx *ctx,
for (i = 0; i < ctx->n_sheets; i++) {
const css_select_sheet s = ctx->sheets[i];
- if ((s.media & media) != 0 &&
+ if (mq__list_match(s.media, media) &&
s.sheet->disabled == false) {
error = select_font_faces_from_sheet(s.sheet,
s.origin, &state);
diff --git a/src/select/select.h b/src/select/select.h
index 70f1ced..dc9aa4a 100644
--- a/src/select/select.h
+++ b/src/select/select.h
@@ -63,7 +63,7 @@ struct css_node_data {
*/
typedef struct css_select_state {
void *node; /* Node we're selecting for */
- uint64_t media; /* Currently active media types */
+ const css_media *media; /* Currently active media spec */
css_select_results *results; /* Result set to populate */
css_pseudo_element current_pseudo; /* Current pseudo element */
commitdiff
http://git.netsurf-browser.org/libcss.git/commit/?id=d6126aa77eb442f446d28b6dfb15a884f209a341
commit d6126aa77eb442f446d28b6dfb15a884f209a341
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>
Media queries: Fix documentation typo.
Signed-off-by: Michael Drake <[email protected]>
diff --git a/src/select/mq.h b/src/select/mq.h
index a84822d..4fe67b0 100644
--- a/src/select/mq.h
+++ b/src/select/mq.h
@@ -25,7 +25,7 @@ static inline bool mq_match_condition(css_mq_cond *cond)
/**
* Test whether media query list matches current media.
*
- * If anything in the list matches, it the list matches. If none match
+ * If anything in the list matches, the list matches. If none match
* it doesn't match.
*
* \param m Media query list.
commitdiff
http://git.netsurf-browser.org/libcss.git/commit/?id=171cb33082983c145ac9818b94e38f486c5f407b
commit 171cb33082983c145ac9818b94e38f486c5f407b
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>
Media queries: Selection: For now, we just say the condition matches.
Signed-off-by: Michael Drake <[email protected]>
diff --git a/src/select/mq.h b/src/select/mq.h
index 5aa1404..a84822d 100644
--- a/src/select/mq.h
+++ b/src/select/mq.h
@@ -18,7 +18,8 @@
static inline bool mq_match_condition(css_mq_cond *cond)
{
/* TODO: Implement this. */
- return cond == NULL;
+ (void) cond;
+ return true;
}
/**
commitdiff
http://git.netsurf-browser.org/libcss.git/commit/?id=c0ce0471b979d6fe39a16c7aed4f183922219e2e
commit c0ce0471b979d6fe39a16c7aed4f183922219e2e
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>
Media queries: Validate the query string parameters.
Signed-off-by: Michael Drake <[email protected]>
diff --git a/src/parse/mq.c b/src/parse/mq.c
index 7c1286f..cb9345d 100644
--- a/src/parse/mq.c
+++ b/src/parse/mq.c
@@ -1098,6 +1098,10 @@ css_error css_parse_media_query(lwc_string **strings,
},
};
+ if (mq == NULL || len == 0) {
+ return CSS_BADPARM;
+ }
+
err = css__parser_create_for_media_query(NULL,
CSS_CHARSET_DEFAULT, &parser);
if (err != CSS_OK) {
commitdiff
http://git.netsurf-browser.org/libcss.git/commit/?id=f6bc2001832f1941ea40d52ab1333f3ceb76348a
commit f6bc2001832f1941ea40d52ab1333f3ceb76348a
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>
Media queries: Squash cond_parts parts leak.
Signed-off-by: Michael Drake <[email protected]>
diff --git a/src/parse/mq.c b/src/parse/mq.c
index e7227f7..7c1286f 100644
--- a/src/parse/mq.c
+++ b/src/parse/mq.c
@@ -45,6 +45,7 @@ static void css__mq_cond_parts_destroy(css_mq_cond_parts
*cond_parts)
for (uint32_t i = 0; i < cond_parts->nparts; i++) {
css__mq_cond_or_feature_destroy(cond_parts->parts[i]);
}
+ free(cond_parts->parts);
free(cond_parts);
}
}
-----------------------------------------------------------------------
Summary of changes:
examples/example1.c | 7 ++++--
include/libcss/select.h | 8 +++----
src/parse/mq.c | 5 +++++
src/select/computed.c | 2 +-
src/select/hash.h | 2 +-
src/select/mq.h | 11 +++++-----
src/select/select.c | 54 +++++++++++++++++++++++++++++++++--------------
src/select/select.h | 2 +-
test/select.c | 27 ++++++++++++------------
9 files changed, 75 insertions(+), 43 deletions(-)
diff --git a/examples/example1.c b/examples/example1.c
index 1c0dcf9..c36a94d 100644
--- a/examples/example1.c
+++ b/examples/example1.c
@@ -161,6 +161,9 @@ int main(int argc, char **argv)
uint32_t count;
unsigned int hh;
css_stylesheet_params params;
+ css_media media = {
+ .type = CSS_MEDIA_SCREEN,
+ };
UNUSED(argc);
UNUSED(argv);
@@ -210,7 +213,7 @@ int main(int argc, char **argv)
if (code != CSS_OK)
die("css_select_ctx_create", code);
code = css_select_ctx_append_sheet(select_ctx, sheet, CSS_ORIGIN_AUTHOR,
- CSS_MEDIA_ALL);
+ NULL);
if (code != CSS_OK)
die("css_select_ctx_append_sheet", code);
code = css_select_ctx_count_sheets(select_ctx, &count);
@@ -234,7 +237,7 @@ int main(int argc, char **argv)
lwc_intern_string(element, strlen(element), &element_name);
code = css_select_style(select_ctx, element_name,
- CSS_MEDIA_SCREEN, NULL,
+ &media, NULL,
&select_handler, 0,
&style);
if (code != CSS_OK)
diff --git a/include/libcss/select.h b/include/libcss/select.h
index f1de409..ca57456 100644
--- a/include/libcss/select.h
+++ b/include/libcss/select.h
@@ -206,10 +206,10 @@ css_error css_select_ctx_destroy(css_select_ctx *ctx);
css_error css_select_ctx_append_sheet(css_select_ctx *ctx,
const css_stylesheet *sheet,
- css_origin origin, uint64_t media);
+ css_origin origin, const char *media);
css_error css_select_ctx_insert_sheet(css_select_ctx *ctx,
const css_stylesheet *sheet, uint32_t index,
- css_origin origin, uint64_t media);
+ css_origin origin, const char *media);
css_error css_select_ctx_remove_sheet(css_select_ctx *ctx,
const css_stylesheet *sheet);
@@ -221,13 +221,13 @@ css_error css_select_default_style(css_select_ctx *ctx,
css_select_handler *handler, void *pw,
css_computed_style **style);
css_error css_select_style(css_select_ctx *ctx, void *node,
- uint64_t media, const css_stylesheet *inline_style,
+ const css_media *media, const css_stylesheet *inline_style,
css_select_handler *handler, void *pw,
css_select_results **result);
css_error css_select_results_destroy(css_select_results *results);
css_error css_select_font_faces(css_select_ctx *ctx,
- uint64_t media, lwc_string *font_family,
+ const css_media *media, lwc_string *font_family,
css_select_font_faces_results **result);
css_error css_select_font_faces_results_destroy(
css_select_font_faces_results *results);
diff --git a/src/parse/mq.c b/src/parse/mq.c
index e7227f7..cb9345d 100644
--- a/src/parse/mq.c
+++ b/src/parse/mq.c
@@ -45,6 +45,7 @@ static void css__mq_cond_parts_destroy(css_mq_cond_parts
*cond_parts)
for (uint32_t i = 0; i < cond_parts->nparts; i++) {
css__mq_cond_or_feature_destroy(cond_parts->parts[i]);
}
+ free(cond_parts->parts);
free(cond_parts);
}
}
@@ -1097,6 +1098,10 @@ css_error css_parse_media_query(lwc_string **strings,
},
};
+ if (mq == NULL || len == 0) {
+ return CSS_BADPARM;
+ }
+
err = css__parser_create_for_media_query(NULL,
CSS_CHARSET_DEFAULT, &parser);
if (err != CSS_OK) {
diff --git a/src/select/computed.c b/src/select/computed.c
index ebb2b29..506b079 100644
--- a/src/select/computed.c
+++ b/src/select/computed.c
@@ -250,7 +250,7 @@ css_error css__computed_style_initialise(css_computed_style
*style,
return CSS_BADPARM;
state.node = NULL;
- state.media = CSS_MEDIA_ALL;
+ state.media = NULL;
state.results = NULL;
state.computed = style;
state.handler = handler;
diff --git a/src/select/hash.h b/src/select/hash.h
index 71f610f..aecf15a 100644
--- a/src/select/hash.h
+++ b/src/select/hash.h
@@ -25,7 +25,7 @@ struct css_hash_selection_requirments {
lwc_string *class; /* Name of class, or NULL */
lwc_string *id; /* Name of id, or NULL */
lwc_string *uni; /* Universal element string "*" */
- uint64_t media; /* Media type(s) we're selecting for */
+ const css_media *media; /* Media spec we're selecting for */
const css_bloom *node_bloom; /* Node's bloom filter */
};
diff --git a/src/select/mq.h b/src/select/mq.h
index 5aa1404..290505c 100644
--- a/src/select/mq.h
+++ b/src/select/mq.h
@@ -18,24 +18,25 @@
static inline bool mq_match_condition(css_mq_cond *cond)
{
/* TODO: Implement this. */
- return cond == NULL;
+ (void) cond;
+ return true;
}
/**
* Test whether media query list matches current media.
*
- * If anything in the list matches, it the list matches. If none match
+ * If anything in the list matches, the list matches. If none match
* it doesn't match.
*
* \param m Media query list.
* \meaid media Current media spec, to check against m.
* \return true if media query list matches media
*/
-static inline bool mq__list_match(const css_mq_query *m, uint64_t media)
+static inline bool mq__list_match(const css_mq_query *m, const css_media
*media)
{
for (; m != NULL; m = m->next) {
/* Check type */
- if (!!(m->type & media) != m->negate_type) {
+ if (!!(m->type & media->type) != m->negate_type) {
if (mq_match_condition(m->cond)) {
/* We have a match, no need to look further. */
return true;
@@ -53,7 +54,7 @@ static inline bool mq__list_match(const css_mq_query *m,
uint64_t media)
* \param media Current media type(s)
* \return true iff chain's rule applies for media
*/
-static inline bool mq_rule_good_for_media(const css_rule *rule, uint64_t media)
+static inline bool mq_rule_good_for_media(const css_rule *rule, const
css_media *media)
{
bool applies = true;
const css_rule *ancestor = rule;
diff --git a/src/select/select.c b/src/select/select.c
index 480b9f5..1b0cadd 100644
--- a/src/select/select.c
+++ b/src/select/select.c
@@ -38,7 +38,7 @@
typedef struct css_select_sheet {
const css_stylesheet *sheet; /**< Stylesheet */
css_origin origin; /**< Stylesheet origin */
- uint64_t media; /**< Applicable media */
+ css_mq_query *media; /**< Applicable media */
} css_select_sheet;
/**
@@ -97,7 +97,7 @@ typedef struct css_select_font_faces_list {
*/
typedef struct css_select_font_faces_state {
lwc_string *font_family;
- uint64_t media;
+ const css_media *media;
css_select_font_faces_list ua_font_faces;
css_select_font_faces_list user_font_faces;
@@ -289,8 +289,12 @@ css_error css_select_ctx_destroy(css_select_ctx *ctx)
if (ctx->default_style != NULL)
css_computed_style_destroy(ctx->default_style);
- if (ctx->sheets != NULL)
+ if (ctx->sheets != NULL) {
+ for (uint32_t index = 0; index < ctx->n_sheets; index++) {
+ css__mq_query_destroy(ctx->sheets[index].media);
+ }
free(ctx->sheets);
+ }
free(ctx);
@@ -303,12 +307,12 @@ css_error css_select_ctx_destroy(css_select_ctx *ctx)
* \param ctx The context to append to
* \param sheet The sheet to append
* \param origin Origin of the sheet
- * \param media Media types to which the sheet applies
+ * \param media Media string for the stylesheet
* \return CSS_OK on success, appropriate error otherwise
*/
css_error css_select_ctx_append_sheet(css_select_ctx *ctx,
const css_stylesheet *sheet, css_origin origin,
- uint64_t media)
+ const char *media)
{
if (ctx == NULL || sheet == NULL)
return CSS_BADPARM;
@@ -324,14 +328,16 @@ css_error css_select_ctx_append_sheet(css_select_ctx *ctx,
* \param sheet Sheet to insert
* \param index Index in context to insert sheet
* \param origin Origin of the sheet
- * \param media Media types to which the sheet applies
+ * \param media Media string for the stylesheet
* \return CSS_OK on success, appropriate error otherwise
*/
css_error css_select_ctx_insert_sheet(css_select_ctx *ctx,
const css_stylesheet *sheet, uint32_t index,
- css_origin origin, uint64_t media)
+ css_origin origin, const char *media)
{
css_select_sheet *temp;
+ css_mq_query *mq;
+ css_error error;
if (ctx == NULL || sheet == NULL)
return CSS_BADPARM;
@@ -357,9 +363,23 @@ css_error css_select_ctx_insert_sheet(css_select_ctx *ctx,
(ctx->n_sheets - index) * sizeof(css_select_sheet));
}
+ error = css_parse_media_query(sheet->propstrings,
+ (const uint8_t *)media,
+ (media == NULL) ? 0 : strlen(media), &mq);
+ if (error == CSS_NOMEM) {
+ return error;
+ } else if (error != CSS_OK) {
+ /* Fall back to default media: "all". */
+ mq = calloc(1, sizeof(*mq));
+ if (mq == NULL) {
+ return CSS_NOMEM;
+ }
+ mq->type = CSS_MEDIA_ALL;
+ }
+
ctx->sheets[index].sheet = sheet;
ctx->sheets[index].origin = origin;
- ctx->sheets[index].media = media;
+ ctx->sheets[index].media = mq;
ctx->n_sheets++;
@@ -389,6 +409,8 @@ css_error css_select_ctx_remove_sheet(css_select_ctx *ctx,
if (index == ctx->n_sheets)
return CSS_INVALID;
+ css__mq_query_destroy(ctx->sheets[index].media);
+
ctx->n_sheets--;
memmove(&ctx->sheets[index], &ctx->sheets[index + 1],
@@ -1032,7 +1054,7 @@ static void css_select__finalise_selection_state(
* \param[in] state The selection state to initialise
* \param[in] node The node we are selecting for.
* \param[in] parent The node's parent node, or NULL.
- * \param[in] media The media type we're selecting for.
+ * \param[in] media The media specification we're selecting for.
* \param[in] handler The client selection callback table.
* \param[in] pw The client private data, passsed out to callbacks.
* \return CSS_OK or appropriate error otherwise.
@@ -1041,7 +1063,7 @@ static css_error css_select__initialise_selection_state(
css_select_state *state,
void *node,
void *parent,
- uint64_t media,
+ const css_media *media,
css_select_handler *handler,
void *pw)
{
@@ -1142,7 +1164,7 @@ failed:
*
* \param ctx Selection context to use
* \param node Node to select style for
- * \param media Currently active media types
+ * \param media Currently active media specification
* \param inline_style Corresponding inline style for node, or NULL
* \param handler Dispatch table of handler functions
* \param pw Client-specific private data for handler functions
@@ -1159,7 +1181,7 @@ failed:
* update the fully computed style for a node when layout changes.
*/
css_error css_select_style(css_select_ctx *ctx, void *node,
- uint64_t media, const css_stylesheet *inline_style,
+ const css_media *media, const css_stylesheet *inline_style,
css_select_handler *handler, void *pw,
css_select_results **result)
{
@@ -1244,7 +1266,7 @@ css_error css_select_style(css_select_ctx *ctx, void
*node,
for (i = 0; i < ctx->n_sheets; i++) {
const css_select_sheet s = ctx->sheets[i];
- if ((s.media & media) != 0 &&
+ if (mq__list_match(s.media, media) &&
s.sheet->disabled == false) {
error = select_from_sheet(ctx, s.sheet,
s.origin, &state);
@@ -1394,13 +1416,13 @@ css_error css_select_results_destroy(css_select_results
*results)
* Search a selection context for defined font faces
*
* \param ctx Selection context
- * \param media Currently active media types
+ * \param media Currently active media spec
* \param font_family Font family to search for
* \param result Pointer to location to receive result
* \return CSS_OK on success, appropriate error otherwise.
*/
css_error css_select_font_faces(css_select_ctx *ctx,
- uint64_t media, lwc_string *font_family,
+ const css_media *media, lwc_string *font_family,
css_select_font_faces_results **result)
{
uint32_t i;
@@ -1421,7 +1443,7 @@ css_error css_select_font_faces(css_select_ctx *ctx,
for (i = 0; i < ctx->n_sheets; i++) {
const css_select_sheet s = ctx->sheets[i];
- if ((s.media & media) != 0 &&
+ if (mq__list_match(s.media, media) &&
s.sheet->disabled == false) {
error = select_font_faces_from_sheet(s.sheet,
s.origin, &state);
diff --git a/src/select/select.h b/src/select/select.h
index 70f1ced..dc9aa4a 100644
--- a/src/select/select.h
+++ b/src/select/select.h
@@ -63,7 +63,7 @@ struct css_node_data {
*/
typedef struct css_select_state {
void *node; /* Node we're selecting for */
- uint64_t media; /* Currently active media types */
+ const css_media *media; /* Currently active media spec */
css_select_results *results; /* Result set to populate */
css_pseudo_element current_pseudo; /* Current pseudo element */
diff --git a/test/select.c b/test/select.c
index f21d937..664994e 100644
--- a/test/select.c
+++ b/test/select.c
@@ -42,7 +42,7 @@ typedef struct node {
typedef struct sheet_ctx {
css_stylesheet *sheet;
css_origin origin;
- uint64_t media;
+ char *media;
} sheet_ctx;
typedef struct line_ctx {
@@ -62,7 +62,7 @@ typedef struct line_ctx {
uint32_t n_sheets;
sheet_ctx *sheets;
- uint64_t media;
+ css_media media;
uint32_t pseudo_element;
node *target;
@@ -77,7 +77,7 @@ static bool handle_line(const char *data, size_t datalen,
void *pw);
static void css__parse_tree(line_ctx *ctx, const char *data, size_t len);
static void css__parse_tree_data(line_ctx *ctx, const char *data, size_t len);
static void css__parse_sheet(line_ctx *ctx, const char *data, size_t len);
-static void css__parse_media_list(const char **data, size_t *len, uint64_t
*media);
+static void css__parse_media_list(const char **data, size_t *len, css_media
*media);
static void css__parse_pseudo_list(const char **data, size_t *len,
uint32_t *element);
static void css__parse_expected(line_ctx *ctx, const char *data, size_t len);
@@ -363,7 +363,7 @@ void css__parse_tree(line_ctx *ctx, const char *data,
size_t len)
/* [ <media_list> <pseudo>? ] ? */
- ctx->media = CSS_MEDIA_ALL;
+ ctx->media.type = CSS_MEDIA_ALL;
ctx->pseudo_element = CSS_PSEUDO_ELEMENT_NONE;
/* Consume any leading whitespace */
@@ -515,9 +515,9 @@ void css__parse_sheet(line_ctx *ctx, const char *data,
size_t len)
const char *p;
const char *end = data + len;
css_origin origin = CSS_ORIGIN_AUTHOR;
- uint64_t media = CSS_MEDIA_ALL;
css_stylesheet *sheet;
sheet_ctx *temp;
+ char *media = NULL;
/* <origin> <media_list>? */
@@ -540,11 +540,11 @@ void css__parse_sheet(line_ctx *ctx, const char *data,
size_t len)
while (p < end && isspace(*p))
p++;
- if (p < end) {
- size_t ignored = end - p;
-
- css__parse_media_list(&p, &ignored, &media);
- }
+ assert(end >= p);
+ media = malloc(end - p + 1);
+ assert(media != NULL);
+ memcpy(media, p, end - p);
+ media[end - p] = '\0';
params.params_version = CSS_STYLESHEET_PARAMS_VERSION_1;
params.level = CSS_LEVEL_21;
@@ -579,7 +579,7 @@ void css__parse_sheet(line_ctx *ctx, const char *data,
size_t len)
ctx->n_sheets++;
}
-void css__parse_media_list(const char **data, size_t *len, uint64_t *media)
+void css__parse_media_list(const char **data, size_t *len, css_media *media)
{
const char *p = *data;
const char *end = p + *len;
@@ -646,7 +646,7 @@ void css__parse_media_list(const char **data, size_t *len,
uint64_t *media)
p++;
}
- *media = result;
+ media->type = result;
*data = p;
*len = end - p;
@@ -765,7 +765,7 @@ static void run_test_select_tree(css_select_ctx *select,
css_select_results *sr;
struct node *n = NULL;
- assert(css_select_style(select, node, ctx->media, NULL,
+ assert(css_select_style(select, node, &ctx->media, NULL,
&select_handler, ctx, &sr) == CSS_OK);
if (node->parent != NULL) {
@@ -841,6 +841,7 @@ void run_test(line_ctx *ctx, const char *exp, size_t explen)
for (i = 0; i < ctx->n_sheets; i++) {
css_stylesheet_destroy(ctx->sheets[i].sheet);
+ free(ctx->sheets[i].media);
}
ctx->tree = NULL;
--
Cascading Style Sheets library
_______________________________________________
netsurf-commits mailing list
[email protected]
http://listmaster.pepperfish.net/cgi-bin/mailman/listinfo/netsurf-commits-netsurf-browser.org