Gitweb links:
...log
http://git.netsurf-browser.org/libcss.git/shortlog/5cd8a2a7b7c1aff763c805a8459a15a3aba6f6e4
...commit
http://git.netsurf-browser.org/libcss.git/commit/5cd8a2a7b7c1aff763c805a8459a15a3aba6f6e4
...tree
http://git.netsurf-browser.org/libcss.git/tree/5cd8a2a7b7c1aff763c805a8459a15a3aba6f6e4
The branch, master has been updated
via 5cd8a2a7b7c1aff763c805a8459a15a3aba6f6e4 (commit)
via 229f2a85386784fc3ebcab31ee6bd660d0954462 (commit)
via 6a8cdf2e4b0fcd7dd72028cafe701dffd6dd0f7e (commit)
from a5e287b135558228ccf4d3bcf2e9763b8f7cd367 (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=5cd8a2a7b7c1aff763c805a8459a15a3aba6f6e4
commit 5cd8a2a7b7c1aff763c805a8459a15a3aba6f6e4
Author: Michael Drake <Michael Drake [email protected]>
Commit: Michael Drake <Michael Drake [email protected]>
Media queries: Selection: Start implementing mq matching.
diff --git a/src/select/mq.h b/src/select/mq.h
index 290505c..436eb90 100644
--- a/src/select/mq.h
+++ b/src/select/mq.h
@@ -12,32 +12,84 @@
/**
* Match media query conditions.
*
- * \param[in] cond Condition to match.
+ * \param[in] feat Condition to match.
+ * \param[in] media Current media spec, to check against feat.
* \return true if condition matches, otherwise false.
*/
-static inline bool mq_match_condition(css_mq_cond *cond)
+static inline bool mq_match_feature(
+ const css_mq_feature *feat,
+ const css_media *media)
{
/* TODO: Implement this. */
- (void) cond;
+ (void) feat;
+ (void) media;
+
return true;
}
/**
+ * Match media query conditions.
+ *
+ * \param[in] cond Condition to match.
+ * \param[in] media Current media spec, to check against cond.
+ * \return true if condition matches, otherwise false.
+ */
+static inline bool mq_match_condition(
+ const css_mq_cond *cond,
+ const css_media *media)
+{
+ bool matched = !cond->op;
+
+ for (uint32_t i = 0; i < cond->parts->nparts; i++) {
+ bool part_matched;
+ if (cond->parts->parts[i]->type == CSS_MQ_FEATURE) {
+ part_matched = mq_match_feature(
+ cond->parts->parts[i]->data.feat,
+ media);
+ } else {
+ assert(cond->parts->parts[i]->type == SS_MQ_COND);
+ part_matched = mq_match_condition(
+ cond->parts->parts[i]->data.cond,
+ media);
+ }
+
+ if (cond->op) {
+ /* OR */
+ matched |= part_matched;
+ if (matched) {
+ break; /* Short-circuit */
+ }
+ } else {
+ /* AND */
+ matched &= part_matched;
+ if (!matched) {
+ break; /* Short-circuit */
+ }
+ }
+ }
+
+ return matched != cond->negate;
+}
+
+/**
* Test whether media query list matches current media.
*
* 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.
+ * \param[in] m Media query list.
+ * \param[in] 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, const css_media
*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->type) != m->negate_type) {
- if (mq_match_condition(m->cond)) {
+ if (m->cond == NULL ||
+ mq_match_condition(m->cond, media)) {
/* We have a match, no need to look further. */
return true;
}
@@ -51,7 +103,7 @@ static inline bool mq__list_match(const css_mq_query *m,
const css_media *media)
* Test whether the rule applies for current media.
*
* \param rule Rule to test
- * \param media Current media type(s)
+ * \param media Current media spec
* \return true iff chain's rule applies for media
*/
static inline bool mq_rule_good_for_media(const css_rule *rule, const
css_media *media)
commitdiff
http://git.netsurf-browser.org/libcss.git/commit/?id=229f2a85386784fc3ebcab31ee6bd660d0954462
commit 229f2a85386784fc3ebcab31ee6bd660d0954462
Author: Michael Drake <Michael Drake [email protected]>
Commit: Michael Drake <Michael Drake [email protected]>
Media queries: Parse: Convert level 3 style ranges to level 4.
This will make the selection code's life easier.
diff --git a/src/parse/mq.c b/src/parse/mq.c
index 7f8646c..76d00f9 100644
--- a/src/parse/mq.c
+++ b/src/parse/mq.c
@@ -212,6 +212,57 @@ static css_error mq_parse_op(const css_token *token,
return CSS_OK;
}
+
+/**
+ * Convert level 3 ranged descriptors into level 4 style.
+ *
+ * Helper for \ref mq_parse_range().
+ *
+ * \param[in] feature Range feature to convert.
+ * \return CSS_OK, or error code.
+ *
+ * This detects the min- and max- prefixes, strips them, and converts
+ * the operator.
+ */
+static css_error mq_parse_range__convert_to_level_4(
+ css_mq_feature *feature)
+{
+ lwc_string *new_name;
+ const char *name = lwc_string_data(feature->name);
+
+ if (feature->op != CSS_MQ_FEATURE_OP_EQ ||
+ lwc_string_length(feature->name) <= 4) {
+ return CSS_OK;
+ }
+
+ if (name[0] == 'm' && name[3] == '-') {
+ if (name[1] == 'i' && name[2] == 'n') {
+ if (lwc_intern_substring(feature->name,
+ 4, lwc_string_length(feature->name) - 4,
+ &new_name) != lwc_error_ok) {
+ return CSS_NOMEM;
+ }
+ lwc_string_unref(feature->name);
+ feature->name = new_name;
+
+ feature->op = CSS_MQ_FEATURE_OP_GTE;
+
+ } else if (name[1] == 'a' && name[2] == 'x') {
+ if (lwc_intern_substring(feature->name,
+ 4, lwc_string_length(feature->name) - 4,
+ &new_name) != lwc_error_ok) {
+ return CSS_NOMEM;
+ }
+ lwc_string_unref(feature->name);
+ feature->name = new_name;
+
+ feature->op = CSS_MQ_FEATURE_OP_LTE;
+ }
+ }
+
+ return CSS_OK;
+}
+
static css_error mq_parse_range(lwc_string **strings,
const parserutils_vector *vector, int *ctx,
const css_token *name_or_value,
@@ -390,6 +441,12 @@ static css_error mq_parse_range(lwc_string **strings,
}
}
+ error = mq_parse_range__convert_to_level_4(result);
+ if (error != CSS_OK) {
+ css__mq_feature_destroy(result);
+ return error;
+ }
+
*feature = result;
return CSS_OK;
commitdiff
http://git.netsurf-browser.org/libcss.git/commit/?id=6a8cdf2e4b0fcd7dd72028cafe701dffd6dd0f7e
commit 6a8cdf2e4b0fcd7dd72028cafe701dffd6dd0f7e
Author: Michael Drake <Michael Drake [email protected]>
Commit: Michael Drake <Michael Drake [email protected]>
Media queries: Intern the query descriptor name as lower case.
diff --git a/src/parse/mq.c b/src/parse/mq.c
index cb9345d..7f8646c 100644
--- a/src/parse/mq.c
+++ b/src/parse/mq.c
@@ -135,7 +135,10 @@ static css_error mq_create_feature(
memset(f, 0, sizeof(*f));
- f->name = lwc_string_ref(name);
+ if (lwc_string_tolower(name, &f->name) != lwc_error_ok) {
+ free(f);
+ return CSS_NOMEM;
+ }
*feature = f;
-----------------------------------------------------------------------
Summary of changes:
src/parse/mq.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++++-
src/select/mq.h | 68 ++++++++++++++++++++++++++++++++++++++++++++++++-------
2 files changed, 121 insertions(+), 9 deletions(-)
diff --git a/src/parse/mq.c b/src/parse/mq.c
index cb9345d..76d00f9 100644
--- a/src/parse/mq.c
+++ b/src/parse/mq.c
@@ -135,7 +135,10 @@ static css_error mq_create_feature(
memset(f, 0, sizeof(*f));
- f->name = lwc_string_ref(name);
+ if (lwc_string_tolower(name, &f->name) != lwc_error_ok) {
+ free(f);
+ return CSS_NOMEM;
+ }
*feature = f;
@@ -209,6 +212,57 @@ static css_error mq_parse_op(const css_token *token,
return CSS_OK;
}
+
+/**
+ * Convert level 3 ranged descriptors into level 4 style.
+ *
+ * Helper for \ref mq_parse_range().
+ *
+ * \param[in] feature Range feature to convert.
+ * \return CSS_OK, or error code.
+ *
+ * This detects the min- and max- prefixes, strips them, and converts
+ * the operator.
+ */
+static css_error mq_parse_range__convert_to_level_4(
+ css_mq_feature *feature)
+{
+ lwc_string *new_name;
+ const char *name = lwc_string_data(feature->name);
+
+ if (feature->op != CSS_MQ_FEATURE_OP_EQ ||
+ lwc_string_length(feature->name) <= 4) {
+ return CSS_OK;
+ }
+
+ if (name[0] == 'm' && name[3] == '-') {
+ if (name[1] == 'i' && name[2] == 'n') {
+ if (lwc_intern_substring(feature->name,
+ 4, lwc_string_length(feature->name) - 4,
+ &new_name) != lwc_error_ok) {
+ return CSS_NOMEM;
+ }
+ lwc_string_unref(feature->name);
+ feature->name = new_name;
+
+ feature->op = CSS_MQ_FEATURE_OP_GTE;
+
+ } else if (name[1] == 'a' && name[2] == 'x') {
+ if (lwc_intern_substring(feature->name,
+ 4, lwc_string_length(feature->name) - 4,
+ &new_name) != lwc_error_ok) {
+ return CSS_NOMEM;
+ }
+ lwc_string_unref(feature->name);
+ feature->name = new_name;
+
+ feature->op = CSS_MQ_FEATURE_OP_LTE;
+ }
+ }
+
+ return CSS_OK;
+}
+
static css_error mq_parse_range(lwc_string **strings,
const parserutils_vector *vector, int *ctx,
const css_token *name_or_value,
@@ -387,6 +441,12 @@ static css_error mq_parse_range(lwc_string **strings,
}
}
+ error = mq_parse_range__convert_to_level_4(result);
+ if (error != CSS_OK) {
+ css__mq_feature_destroy(result);
+ return error;
+ }
+
*feature = result;
return CSS_OK;
diff --git a/src/select/mq.h b/src/select/mq.h
index 290505c..436eb90 100644
--- a/src/select/mq.h
+++ b/src/select/mq.h
@@ -12,32 +12,84 @@
/**
* Match media query conditions.
*
- * \param[in] cond Condition to match.
+ * \param[in] feat Condition to match.
+ * \param[in] media Current media spec, to check against feat.
* \return true if condition matches, otherwise false.
*/
-static inline bool mq_match_condition(css_mq_cond *cond)
+static inline bool mq_match_feature(
+ const css_mq_feature *feat,
+ const css_media *media)
{
/* TODO: Implement this. */
- (void) cond;
+ (void) feat;
+ (void) media;
+
return true;
}
/**
+ * Match media query conditions.
+ *
+ * \param[in] cond Condition to match.
+ * \param[in] media Current media spec, to check against cond.
+ * \return true if condition matches, otherwise false.
+ */
+static inline bool mq_match_condition(
+ const css_mq_cond *cond,
+ const css_media *media)
+{
+ bool matched = !cond->op;
+
+ for (uint32_t i = 0; i < cond->parts->nparts; i++) {
+ bool part_matched;
+ if (cond->parts->parts[i]->type == CSS_MQ_FEATURE) {
+ part_matched = mq_match_feature(
+ cond->parts->parts[i]->data.feat,
+ media);
+ } else {
+ assert(cond->parts->parts[i]->type == SS_MQ_COND);
+ part_matched = mq_match_condition(
+ cond->parts->parts[i]->data.cond,
+ media);
+ }
+
+ if (cond->op) {
+ /* OR */
+ matched |= part_matched;
+ if (matched) {
+ break; /* Short-circuit */
+ }
+ } else {
+ /* AND */
+ matched &= part_matched;
+ if (!matched) {
+ break; /* Short-circuit */
+ }
+ }
+ }
+
+ return matched != cond->negate;
+}
+
+/**
* Test whether media query list matches current media.
*
* 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.
+ * \param[in] m Media query list.
+ * \param[in] 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, const css_media
*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->type) != m->negate_type) {
- if (mq_match_condition(m->cond)) {
+ if (m->cond == NULL ||
+ mq_match_condition(m->cond, media)) {
/* We have a match, no need to look further. */
return true;
}
@@ -51,7 +103,7 @@ static inline bool mq__list_match(const css_mq_query *m,
const css_media *media)
* Test whether the rule applies for current media.
*
* \param rule Rule to test
- * \param media Current media type(s)
+ * \param media Current media spec
* \return true iff chain's rule applies for media
*/
static inline bool mq_rule_good_for_media(const css_rule *rule, const
css_media *media)
--
Cascading Style Sheets library
_______________________________________________
netsurf-commits mailing list
[email protected]
http://listmaster.pepperfish.net/cgi-bin/mailman/listinfo/netsurf-commits-netsurf-browser.org