Gitweb links:

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

The branch, master has been updated
       via  a7830f2452116f57e7880a3f1802c1c3bf1209c9 (commit)
      from  472d1d03e9454209b18a705b2bb1479f844af369 (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=a7830f2452116f57e7880a3f1802c1c3bf1209c9
commit a7830f2452116f57e7880a3f1802c1c3bf1209c9
Author: Michael Drake <Michael Drake [email protected]>
Commit: Michael Drake <Michael Drake [email protected]>

    Media queries: Start implementing feature matching.
    
    Currently we just look at:
    
    - width
    - height
    
    TODO:
    
    - Unit conversion
    - Use interned string comparison

diff --git a/src/select/mq.h b/src/select/mq.h
index e4c09af..1c07ecc 100644
--- a/src/select/mq.h
+++ b/src/select/mq.h
@@ -9,8 +9,71 @@
 #ifndef css_select_mq_h_
 #define css_select_mq_h_
 
+static inline bool mq_match_feature_range_length_op1(
+               css_mq_feature_op op,
+               const css_mq_value *value,
+               const css_media_length *client_len)
+{
+       if (value->type != CSS_MQ_VALUE_TYPE_DIM) {
+               return false;
+       }
+       /* TODO: convert to same units */
+       if (value->data.dim.unit != client_len->unit) {
+               return false;
+       }
+
+       switch (op) {
+       case CSS_MQ_FEATURE_OP_BOOL:
+               return false;
+       case CSS_MQ_FEATURE_OP_LT:
+               return value->data.dim.len <  client_len->value;
+       case CSS_MQ_FEATURE_OP_LTE:
+               return value->data.dim.len <= client_len->value;
+       case CSS_MQ_FEATURE_OP_EQ:
+               return value->data.dim.len == client_len->value;
+       case CSS_MQ_FEATURE_OP_GTE:
+               return value->data.dim.len >= client_len->value;
+       case CSS_MQ_FEATURE_OP_GT:
+               return value->data.dim.len >  client_len->value;
+       default:
+               return false;
+       }
+}
+
+static inline bool mq_match_feature_range_length_op2(
+               css_mq_feature_op op,
+               const css_mq_value *value,
+               const css_media_length *client_len)
+{
+       if (op == CSS_MQ_FEATURE_OP_UNUSED) {
+               return true;
+       }
+       if (value->type != CSS_MQ_VALUE_TYPE_DIM) {
+               return false;
+       }
+       /* TODO: convert to same units */
+       if (value->data.dim.unit != client_len->unit) {
+               return false;
+       }
+
+       switch (op) {
+       case CSS_MQ_FEATURE_OP_LT:
+               return client_len->value <  value->data.dim.len;
+       case CSS_MQ_FEATURE_OP_LTE:
+               return client_len->value <= value->data.dim.len;
+       case CSS_MQ_FEATURE_OP_EQ:
+               return client_len->value == value->data.dim.len;
+       case CSS_MQ_FEATURE_OP_GTE:
+               return client_len->value >= value->data.dim.len;
+       case CSS_MQ_FEATURE_OP_GT:
+               return client_len->value >  value->data.dim.len;
+       default:
+               return false;
+       }
+}
+
 /**
- * Match media query conditions.
+ * Match media query features.
  *
  * \param[in] feat  Condition to match.
  * \param[in] media  Current media spec, to check against feat.
@@ -20,11 +83,28 @@ static inline bool mq_match_feature(
                const css_mq_feature *feat,
                const css_media *media)
 {
-       /* TODO: Implement this. */
-       (void) feat;
-       (void) media;
+       /* TODO: Use interned string for comparison. */
+       if (strcmp(lwc_string_data(feat->name), "width") == 0) {
+               if (!mq_match_feature_range_length_op1(
+                               feat->op, &feat->value, &media->width)) {
+                       return false;
+               }
+               return mq_match_feature_range_length_op2(
+                               feat->op2, &feat->value2, &media->width);
 
-       return true;
+       } else if (strcmp(lwc_string_data(feat->name), "height") == 0) {
+               if (!mq_match_feature_range_length_op1(
+                               feat->op, &feat->value, &media->height)) {
+                       return false;
+               }
+
+               return mq_match_feature_range_length_op2(
+                               feat->op2, &feat->value2, &media->height);
+       }
+
+       /* TODO: Look at other feature names. */
+
+       return false;
 }
 
 /**


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

Summary of changes:
 src/select/mq.h |   90 +++++++++++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 85 insertions(+), 5 deletions(-)

diff --git a/src/select/mq.h b/src/select/mq.h
index e4c09af..1c07ecc 100644
--- a/src/select/mq.h
+++ b/src/select/mq.h
@@ -9,8 +9,71 @@
 #ifndef css_select_mq_h_
 #define css_select_mq_h_
 
+static inline bool mq_match_feature_range_length_op1(
+               css_mq_feature_op op,
+               const css_mq_value *value,
+               const css_media_length *client_len)
+{
+       if (value->type != CSS_MQ_VALUE_TYPE_DIM) {
+               return false;
+       }
+       /* TODO: convert to same units */
+       if (value->data.dim.unit != client_len->unit) {
+               return false;
+       }
+
+       switch (op) {
+       case CSS_MQ_FEATURE_OP_BOOL:
+               return false;
+       case CSS_MQ_FEATURE_OP_LT:
+               return value->data.dim.len <  client_len->value;
+       case CSS_MQ_FEATURE_OP_LTE:
+               return value->data.dim.len <= client_len->value;
+       case CSS_MQ_FEATURE_OP_EQ:
+               return value->data.dim.len == client_len->value;
+       case CSS_MQ_FEATURE_OP_GTE:
+               return value->data.dim.len >= client_len->value;
+       case CSS_MQ_FEATURE_OP_GT:
+               return value->data.dim.len >  client_len->value;
+       default:
+               return false;
+       }
+}
+
+static inline bool mq_match_feature_range_length_op2(
+               css_mq_feature_op op,
+               const css_mq_value *value,
+               const css_media_length *client_len)
+{
+       if (op == CSS_MQ_FEATURE_OP_UNUSED) {
+               return true;
+       }
+       if (value->type != CSS_MQ_VALUE_TYPE_DIM) {
+               return false;
+       }
+       /* TODO: convert to same units */
+       if (value->data.dim.unit != client_len->unit) {
+               return false;
+       }
+
+       switch (op) {
+       case CSS_MQ_FEATURE_OP_LT:
+               return client_len->value <  value->data.dim.len;
+       case CSS_MQ_FEATURE_OP_LTE:
+               return client_len->value <= value->data.dim.len;
+       case CSS_MQ_FEATURE_OP_EQ:
+               return client_len->value == value->data.dim.len;
+       case CSS_MQ_FEATURE_OP_GTE:
+               return client_len->value >= value->data.dim.len;
+       case CSS_MQ_FEATURE_OP_GT:
+               return client_len->value >  value->data.dim.len;
+       default:
+               return false;
+       }
+}
+
 /**
- * Match media query conditions.
+ * Match media query features.
  *
  * \param[in] feat  Condition to match.
  * \param[in] media  Current media spec, to check against feat.
@@ -20,11 +83,28 @@ static inline bool mq_match_feature(
                const css_mq_feature *feat,
                const css_media *media)
 {
-       /* TODO: Implement this. */
-       (void) feat;
-       (void) media;
+       /* TODO: Use interned string for comparison. */
+       if (strcmp(lwc_string_data(feat->name), "width") == 0) {
+               if (!mq_match_feature_range_length_op1(
+                               feat->op, &feat->value, &media->width)) {
+                       return false;
+               }
+               return mq_match_feature_range_length_op2(
+                               feat->op2, &feat->value2, &media->width);
 
-       return true;
+       } else if (strcmp(lwc_string_data(feat->name), "height") == 0) {
+               if (!mq_match_feature_range_length_op1(
+                               feat->op, &feat->value, &media->height)) {
+                       return false;
+               }
+
+               return mq_match_feature_range_length_op2(
+                               feat->op2, &feat->value2, &media->height);
+       }
+
+       /* TODO: Look at other feature names. */
+
+       return false;
 }
 
 /**


-- 
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