Gitweb links:

...log 
http://git.netsurf-browser.org/libcss.git/shortlog/5a8bbc650d55bbf14e9798b018e9a6aa7b2fc920
...commit 
http://git.netsurf-browser.org/libcss.git/commit/5a8bbc650d55bbf14e9798b018e9a6aa7b2fc920
...tree 
http://git.netsurf-browser.org/libcss.git/tree/5a8bbc650d55bbf14e9798b018e9a6aa7b2fc920

The branch, tlsa/jmb/mq has been updated
       via  5a8bbc650d55bbf14e9798b018e9a6aa7b2fc920 (commit)
       via  3ffe4302e5526735968c741e2674f15a7731b4f2 (commit)
       via  04b2bcda11a0819037bdfcf9e0ed96b4668568b2 (commit)
       via  211f8ab4f27c526aa29b25afc7d8b382b8491db4 (commit)
      from  1441707ce5437784815e2cf97d695a7b0569f800 (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=5a8bbc650d55bbf14e9798b018e9a6aa7b2fc920
commit 5a8bbc650d55bbf14e9798b018e9a6aa7b2fc920
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>

    Media queries: API for stylesheet import doesn't take media now.

diff --git a/test/css21.c b/test/css21.c
index a29fae1..cdd66f7 100644
--- a/test/css21.c
+++ b/test/css21.c
@@ -99,10 +99,8 @@ int main(int argc, char **argv)
 
                while (error == CSS_IMPORTS_PENDING) {
                        lwc_string *url;
-                       uint64_t media;
 
-                       error = css_stylesheet_next_pending_import(sheet,
-                                       &url, &media);
+                       error = css_stylesheet_next_pending_import(sheet, &url);
                        assert(error == CSS_OK || error == CSS_INVALID);
 
                        if (error == CSS_OK) {
diff --git a/test/parse-auto.c b/test/parse-auto.c
index 58ccf9a..5f926e3 100644
--- a/test/parse-auto.c
+++ b/test/parse-auto.c
@@ -395,10 +395,8 @@ void run_test(const uint8_t *data, size_t len, exp_entry 
*exp, size_t explen)
 
        while (error == CSS_IMPORTS_PENDING) {
                lwc_string *url;
-               uint64_t media;
 
-               error = css_stylesheet_next_pending_import(sheet,
-                               &url, &media);
+               error = css_stylesheet_next_pending_import(sheet, &url);
                assert(error == CSS_OK || error == CSS_INVALID);
 
                if (error == CSS_OK) {


commitdiff 
http://git.netsurf-browser.org/libcss.git/commit/?id=3ffe4302e5526735968c741e2674f15a7731b4f2
commit 3ffe4302e5526735968c741e2674f15a7731b4f2
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>

    Media queries: Update stylesheet import for media query lists.

diff --git a/src/select/select.c b/src/select/select.c
index 644369a..480b9f5 100644
--- a/src/select/select.c
+++ b/src/select/select.c
@@ -1847,7 +1847,8 @@ css_error select_from_sheet(css_select_ctx *ctx, const 
css_stylesheet *sheet,
                                        (const css_rule_import *) rule;
 
                        if (import->sheet != NULL &&
-                                       (import->media & state->media) != 0) {
+                                       mq__list_match(import->media,
+                                                       state->media)) {
                                /* It's applicable, so process it */
                                if (sp >= IMPORT_STACK_SIZE)
                                        return CSS_NOMEM;
@@ -1954,7 +1955,8 @@ static css_error select_font_faces_from_sheet(
                                        (const css_rule_import *) rule;
 
                        if (import->sheet != NULL &&
-                                       (import->media & state->media) != 0) {
+                                       mq__list_match(import->media,
+                                                       state->media)) {
                                /* It's applicable, so process it */
                                if (sp >= IMPORT_STACK_SIZE)
                                        return CSS_NOMEM;


commitdiff 
http://git.netsurf-browser.org/libcss.git/commit/?id=04b2bcda11a0819037bdfcf9e0ed96b4668568b2
commit 04b2bcda11a0819037bdfcf9e0ed96b4668568b2
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>

    Media queries: Update rule_good_for_media for new mq struct.
    
    Doesn't currently match media query conditions, only the
    media type.

diff --git a/src/select/mq.h b/src/select/mq.h
index a0a9f6d..3ae987d 100644
--- a/src/select/mq.h
+++ b/src/select/mq.h
@@ -10,10 +10,47 @@
 #define css_select_mq_h_
 
 /**
+ * Match media query conditions.
+ *
+ * \param[in] cond  Condition to match.
+ * \return true if condition matches, otherwise false.
+ */
+static inline bool mq_match_condition(css_mq_cond *cond)
+{
+       /* TODO: Implement this. */
+       return cond == NULL;
+}
+
+/**
+ * Test whether media query list matches current media.
+ *
+ * If anything in the list matches, it 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)
+{
+       for (; m != NULL; m = m->next) {
+               /* Check type */
+               if (!!(m->type & media) != m->negate_type) {
+                       if (mq_match_condition(m->cond)) {
+                               /* We have a match, no need to look further. */
+                               return true;
+                       }
+               }
+       }
+
+       return false;
+}
+
+/**
  * Test whether the rule applies for current media.
  *
- * \param rule         Rule to test
- * \meaid media                Current media type(s)
+ * \param rule   Rule to test
+ * \meaid 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)
@@ -24,10 +61,11 @@ static inline bool mq_rule_good_for_media(const css_rule 
*rule, uint64_t media)
        while (ancestor != NULL) {
                const css_rule_media *m = (const css_rule_media *) ancestor;
 
-               if (ancestor->type == CSS_RULE_MEDIA &&
-                               (m->media & media) == 0) {
-                       applies = false;
-                       break;
+               if (ancestor->type == CSS_RULE_MEDIA) {
+                       applies = mq__list_match(m->media, media);
+                       if (applies == false) {
+                               break;
+                       }
                }
 
                if (ancestor->ptype != CSS_RULE_PARENT_STYLESHEET) {


commitdiff 
http://git.netsurf-browser.org/libcss.git/commit/?id=211f8ab4f27c526aa29b25afc7d8b382b8491db4
commit 211f8ab4f27c526aa29b25afc7d8b382b8491db4
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>

    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.

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;


-----------------------------------------------------------------------

Summary of changes:
 src/parse/mq.c      |   62 ++++++++++++++++++++++++++++++++++++++++++++++++---
 src/parse/mq.h      |    2 +-
 src/select/mq.h     |   50 ++++++++++++++++++++++++++++++++++++-----
 src/select/select.c |    6 +++--
 test/css21.c        |    4 +---
 test/parse-auto.c   |    4 +---
 6 files changed, 110 insertions(+), 18 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;
diff --git a/src/select/mq.h b/src/select/mq.h
index a0a9f6d..3ae987d 100644
--- a/src/select/mq.h
+++ b/src/select/mq.h
@@ -10,10 +10,47 @@
 #define css_select_mq_h_
 
 /**
+ * Match media query conditions.
+ *
+ * \param[in] cond  Condition to match.
+ * \return true if condition matches, otherwise false.
+ */
+static inline bool mq_match_condition(css_mq_cond *cond)
+{
+       /* TODO: Implement this. */
+       return cond == NULL;
+}
+
+/**
+ * Test whether media query list matches current media.
+ *
+ * If anything in the list matches, it 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)
+{
+       for (; m != NULL; m = m->next) {
+               /* Check type */
+               if (!!(m->type & media) != m->negate_type) {
+                       if (mq_match_condition(m->cond)) {
+                               /* We have a match, no need to look further. */
+                               return true;
+                       }
+               }
+       }
+
+       return false;
+}
+
+/**
  * Test whether the rule applies for current media.
  *
- * \param rule         Rule to test
- * \meaid media                Current media type(s)
+ * \param rule   Rule to test
+ * \meaid 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)
@@ -24,10 +61,11 @@ static inline bool mq_rule_good_for_media(const css_rule 
*rule, uint64_t media)
        while (ancestor != NULL) {
                const css_rule_media *m = (const css_rule_media *) ancestor;
 
-               if (ancestor->type == CSS_RULE_MEDIA &&
-                               (m->media & media) == 0) {
-                       applies = false;
-                       break;
+               if (ancestor->type == CSS_RULE_MEDIA) {
+                       applies = mq__list_match(m->media, media);
+                       if (applies == false) {
+                               break;
+                       }
                }
 
                if (ancestor->ptype != CSS_RULE_PARENT_STYLESHEET) {
diff --git a/src/select/select.c b/src/select/select.c
index 644369a..480b9f5 100644
--- a/src/select/select.c
+++ b/src/select/select.c
@@ -1847,7 +1847,8 @@ css_error select_from_sheet(css_select_ctx *ctx, const 
css_stylesheet *sheet,
                                        (const css_rule_import *) rule;
 
                        if (import->sheet != NULL &&
-                                       (import->media & state->media) != 0) {
+                                       mq__list_match(import->media,
+                                                       state->media)) {
                                /* It's applicable, so process it */
                                if (sp >= IMPORT_STACK_SIZE)
                                        return CSS_NOMEM;
@@ -1954,7 +1955,8 @@ static css_error select_font_faces_from_sheet(
                                        (const css_rule_import *) rule;
 
                        if (import->sheet != NULL &&
-                                       (import->media & state->media) != 0) {
+                                       mq__list_match(import->media,
+                                                       state->media)) {
                                /* It's applicable, so process it */
                                if (sp >= IMPORT_STACK_SIZE)
                                        return CSS_NOMEM;
diff --git a/test/css21.c b/test/css21.c
index a29fae1..cdd66f7 100644
--- a/test/css21.c
+++ b/test/css21.c
@@ -99,10 +99,8 @@ int main(int argc, char **argv)
 
                while (error == CSS_IMPORTS_PENDING) {
                        lwc_string *url;
-                       uint64_t media;
 
-                       error = css_stylesheet_next_pending_import(sheet,
-                                       &url, &media);
+                       error = css_stylesheet_next_pending_import(sheet, &url);
                        assert(error == CSS_OK || error == CSS_INVALID);
 
                        if (error == CSS_OK) {
diff --git a/test/parse-auto.c b/test/parse-auto.c
index 58ccf9a..5f926e3 100644
--- a/test/parse-auto.c
+++ b/test/parse-auto.c
@@ -395,10 +395,8 @@ void run_test(const uint8_t *data, size_t len, exp_entry 
*exp, size_t explen)
 
        while (error == CSS_IMPORTS_PENDING) {
                lwc_string *url;
-               uint64_t media;
 
-               error = css_stylesheet_next_pending_import(sheet,
-                               &url, &media);
+               error = css_stylesheet_next_pending_import(sheet, &url);
                assert(error == CSS_OK || error == CSS_INVALID);
 
                if (error == CSS_OK) {


-- 
Cascading Style Sheets library

_______________________________________________
netsurf-commits mailing list
[email protected]
http://listmaster.pepperfish.net/cgi-bin/mailman/listinfo/netsurf-commits-netsurf-browser.org

Reply via email to