summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Drake <michael.drake@codethink.co.uk>2018-07-30 13:37:00 +0100
committerMichael Drake <michael.drake@codethink.co.uk>2018-07-30 13:51:44 +0100
commitcce0123b55e0c911c1405b1d5ec6c5bf2a8d8bba (patch)
tree71f59c0cd8deebc17a8b8352f84e44938082a48b
parent1441707ce5437784815e2cf97d695a7b0569f800 (diff)
downloadlibcss-cce0123b55e0c911c1405b1d5ec6c5bf2a8d8bba.tar.gz
libcss-cce0123b55e0c911c1405b1d5ec6c5bf2a8d8bba.tar.bz2
Media Queries: Store type as value, rather than lwc_string.
Otherwise we need to convert it in selection, and select/ doesn't have access to the css_language interned strings table.
-rw-r--r--src/parse/mq.c62
-rw-r--r--src/parse/mq.h2
2 files changed, 60 insertions, 4 deletions
diff --git a/src/parse/mq.c b/src/parse/mq.c
index 8f4391b..f7b8b6e 100644
--- a/src/parse/mq.c
+++ b/src/parse/mq.c
@@ -806,6 +806,64 @@ static css_error mq_parse_condition(css_language *c,
return CSS_OK;
}
+/**
+ * Parse a media query type.
+ */
+static uint64_t mq_parse_type(css_language *c, lwc_string *type)
+{
+ bool match;
+
+ if (type == NULL) {
+ return CSS_MEDIA_ALL;
+ } else if (lwc_string_caseless_isequal(
+ type, c->strings[AURAL],
+ &match) == lwc_error_ok && match) {
+ return CSS_MEDIA_AURAL;
+ } else if (lwc_string_caseless_isequal(
+ type, c->strings[BRAILLE],
+ &match) == lwc_error_ok && match) {
+ return CSS_MEDIA_BRAILLE;
+ } else if (lwc_string_caseless_isequal(
+ type, c->strings[EMBOSSED],
+ &match) == lwc_error_ok && match) {
+ return CSS_MEDIA_EMBOSSED;
+ } else if (lwc_string_caseless_isequal(
+ type, c->strings[HANDHELD],
+ &match) == lwc_error_ok && match) {
+ return CSS_MEDIA_HANDHELD;
+ } else if (lwc_string_caseless_isequal(
+ type, c->strings[PRINT],
+ &match) == lwc_error_ok && match) {
+ return CSS_MEDIA_PRINT;
+ } else if (lwc_string_caseless_isequal(
+ type, c->strings[PROJECTION],
+ &match) == lwc_error_ok && match) {
+ return CSS_MEDIA_PROJECTION;
+ } else if (lwc_string_caseless_isequal(
+ type, c->strings[SCREEN],
+ &match) == lwc_error_ok && match) {
+ return CSS_MEDIA_SCREEN;
+ } else if (lwc_string_caseless_isequal(
+ type, c->strings[SPEECH],
+ &match) == lwc_error_ok && match) {
+ return CSS_MEDIA_SPEECH;
+ } else if (lwc_string_caseless_isequal(
+ type, c->strings[TTY],
+ &match) == lwc_error_ok && match) {
+ return CSS_MEDIA_TTY;
+ } else if (lwc_string_caseless_isequal(
+ type, c->strings[TV],
+ &match) == lwc_error_ok && match) {
+ return CSS_MEDIA_TV;
+ } else if (lwc_string_caseless_isequal(
+ type, c->strings[ALL],
+ &match) == lwc_error_ok && match) {
+ return CSS_MEDIA_ALL;
+ }
+
+ return 0;
+}
+
static css_error mq_parse_media_query(css_language *c,
const parserutils_vector *vector, int *ctx,
css_mq_query **query)
@@ -887,7 +945,7 @@ static css_error mq_parse_media_query(css_language *c,
return CSS_INVALID;
}
- result->type = lwc_string_ref(token->idata);
+ result->type = mq_parse_type(c, token->idata);
consumeWhitespace(vector, ctx);
@@ -897,7 +955,6 @@ static css_error mq_parse_media_query(css_language *c,
lwc_string_caseless_isequal(token->idata,
c->strings[AND], &match) != lwc_error_ok ||
match == false) {
- lwc_string_unref(result->type);
free(result);
return CSS_INVALID;
}
@@ -906,7 +963,6 @@ static css_error mq_parse_media_query(css_language *c,
error = mq_parse_condition(c, vector, ctx, false, &result->cond);
if (error != CSS_OK) {
- lwc_string_unref(result->type);
free(result);
return error;
}
diff --git a/src/parse/mq.h b/src/parse/mq.h
index 77f8a8a..381e0f9 100644
--- a/src/parse/mq.h
+++ b/src/parse/mq.h
@@ -82,7 +82,7 @@ typedef struct css_mq_query {
struct css_mq_query *next;
uint32_t negate_type : 1; /* set if "not type" */
- lwc_string *type; /* or NULL */
+ uint64_t type; /* or NULL */
css_mq_cond *cond;
} css_mq_query;