Gitweb links:

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

The branch, tlsa/units has been updated
       via  74353903d9d10fcf0edab4058635c2d5787300c9 (commit)
      from  0c5718ff8b5e94c8dcc175a1126eec8f3b598161 (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=74353903d9d10fcf0edab4058635c2d5787300c9
commit 74353903d9d10fcf0edab4058635c2d5787300c9
Author: Michael Drake <Michael Drake [email protected]>
Commit: Michael Drake <Michael Drake [email protected]>

    Selection: Don't duplicate unit conversion members in media descriptor.

diff --git a/examples/example1.c b/examples/example1.c
index 6135793..1d2462c 100644
--- a/examples/example1.c
+++ b/examples/example1.c
@@ -103,7 +103,7 @@ static css_error set_libcss_node_data(void *pw, void *n,
 static css_error get_libcss_node_data(void *pw, void *n,
                void **libcss_node_data);
 
-static css_unit_len_ctx uint_len_ctx = {
+static css_unit_ctx uint_len_ctx = {
        .viewport_width    = 800 * (1 << CSS_RADIX_POINT),
        .viewport_height   = 600 * (1 << CSS_RADIX_POINT),
        .font_size_default =  16 * (1 << CSS_RADIX_POINT),
diff --git a/include/libcss/computed.h b/include/libcss/computed.h
index 1587d78..30e369b 100644
--- a/include/libcss/computed.h
+++ b/include/libcss/computed.h
@@ -82,7 +82,7 @@ css_error css_computed_style_destroy(css_computed_style 
*style);
 css_error css_computed_style_compose(
                const css_computed_style *restrict parent,
                const css_computed_style *restrict child,
-               const css_unit_len_ctx *unit_len_ctx,
+               const css_unit_ctx *unit_ctx,
                css_computed_style **restrict result);
 
 /******************************************************************************
diff --git a/include/libcss/select.h b/include/libcss/select.h
index bfaf531..25317e5 100644
--- a/include/libcss/select.h
+++ b/include/libcss/select.h
@@ -219,14 +219,16 @@ 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,
-               const css_unit_len_ctx *unit_len_ctx,
+               const css_unit_ctx *unit_ctx,
                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,
-               const css_media *media, lwc_string *font_family,
+               const css_media *media,
+               const css_unit_ctx *unit_ctx,
+               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/include/libcss/types.h b/include/libcss/types.h
index 1186c6f..2b0dfb7 100644
--- a/include/libcss/types.h
+++ b/include/libcss/types.h
@@ -234,10 +234,6 @@ typedef struct css_media {
 
        /* Scripting media features */
        css_media_scripting scripting;
-
-       /* Client details for length conversion */
-       css_fixed client_font_size;   /* In pt */
-       css_fixed client_line_height; /* In css pixels */
 } css_media;
 
 /**
diff --git a/include/libcss/unit.h b/include/libcss/unit.h
index a847077..67194c1 100644
--- a/include/libcss/unit.h
+++ b/include/libcss/unit.h
@@ -36,7 +36,7 @@ typedef css_fixed (*css_unit_len_measure)(
  * If a NULL pointer is given, LibCSS will use a fixed scaling of
  * the "em" unit.
  */
-typedef struct css_unit_len_ctx {
+typedef struct css_unit_ctx {
        /**
         * Viewport width in CSS pixels.
         * Used if unit is vh, vw, vi, vb, vmin, or vmax.
@@ -73,7 +73,7 @@ typedef struct css_unit_len_ctx {
         * Optional client callback for font measuring.
         */
        const css_unit_len_measure measure;
-} css_unit_len_ctx;
+} css_unit_ctx;
 
 /**
  * Convert css pixels to physical pixels.
@@ -114,7 +114,7 @@ static inline css_fixed css_unit_device2css_px(
  */
 css_fixed css_unit_font_size_len2pt(
                const css_computed_style *style,
-               const css_unit_len_ctx *ctx,
+               const css_unit_ctx *ctx,
                const css_fixed length,
                const css_unit unit);
 
@@ -129,7 +129,7 @@ css_fixed css_unit_font_size_len2pt(
  */
 css_fixed css_unit_len2css_px(
                const css_computed_style *style,
-               const css_unit_len_ctx *ctx,
+               const css_unit_ctx *ctx,
                const css_fixed length,
                const css_unit unit);
 
@@ -144,7 +144,7 @@ css_fixed css_unit_len2css_px(
  */
 css_fixed css_unit_len2device_px(
                const css_computed_style *style,
-               const css_unit_len_ctx *ctx,
+               const css_unit_ctx *ctx,
                const css_fixed length,
                const css_unit unit);
 
diff --git a/src/select/computed.c b/src/select/computed.c
index d075af9..c019590 100644
--- a/src/select/computed.c
+++ b/src/select/computed.c
@@ -248,7 +248,7 @@ css_error css__computed_style_initialise(css_computed_style 
*style,
 css_error css_computed_style_compose(
                const css_computed_style *restrict parent,
                const css_computed_style *restrict child,
-               const css_unit_len_ctx *unit_len_ctx,
+               const css_unit_ctx *unit_ctx,
                css_computed_style **restrict result)
 {
        css_computed_style *composed;
@@ -274,7 +274,7 @@ css_error css_computed_style_compose(
        }
 
        /* Finally, compute absolute values for everything */
-       error = css__compute_absolute_values(parent, composed, unit_len_ctx);
+       error = css__compute_absolute_values(parent, composed, unit_ctx);
        if (error != CSS_OK) {
                return error;
        }
@@ -1085,12 +1085,12 @@ uint8_t css_computed_order(const css_computed_style 
*style,
  *
  * \param parent             Parent style, or NULL for tree root
  * \param style              Computed style to process
- * \param unit_len_ctx       Client length conversion context.
+ * \param unit_ctx       Client length conversion context.
  * \return CSS_OK on success.
  */
 css_error css__compute_absolute_values(const css_computed_style *parent,
                css_computed_style *style,
-               const css_unit_len_ctx *unit_len_ctx)
+               const css_unit_ctx *unit_ctx)
 {
        css_hint_length *ref_length = NULL;
        css_hint psize, size, ex_size;
@@ -1112,8 +1112,8 @@ css_error css__compute_absolute_values(const 
css_computed_style *parent,
                        &size.data.length.unit);
 
        error = css_unit_compute_absolute_font_size(ref_length,
-                       unit_len_ctx->root_style,
-                       unit_len_ctx->font_size_default,
+                       unit_ctx->root_style,
+                       unit_ctx->font_size_default,
                        &size);
        if (error != CSS_OK)
                return error;
@@ -1131,8 +1131,8 @@ css_error css__compute_absolute_values(const 
css_computed_style *parent,
 
        error = css_unit_compute_absolute_font_size(
                        &size.data.length,
-                       unit_len_ctx->root_style,
-                       unit_len_ctx->font_size_default,
+                       unit_ctx->root_style,
+                       unit_ctx->font_size_default,
                        &ex_size);
        if (error != CSS_OK)
                return error;
diff --git a/src/select/computed.h b/src/select/computed.h
index 8b33405..a4bd23d 100644
--- a/src/select/computed.h
+++ b/src/select/computed.h
@@ -37,6 +37,6 @@ css_error css__computed_style_initialise(css_computed_style 
*style,
 
 css_error css__compute_absolute_values(const css_computed_style *parent,
                css_computed_style *style,
-               const css_unit_len_ctx *unit_len_ctx);
+               const css_unit_ctx *unit_ctx);
 
 #endif
diff --git a/src/select/hash.c b/src/select/hash.c
index 4dedec9..16aebf7 100644
--- a/src/select/hash.c
+++ b/src/select/hash.c
@@ -370,7 +370,7 @@ css_error css__selector_hash_find(css_selector_hash *hash,
                                                head->sel_chain_bloom,
                                                req->node_bloom) &&
                                    mq_rule_good_for_media(head->sel->rule,
-                                               req->media)) {
+                                               req->unit_ctx, req->media)) {
                                        /* Found a match */
                                        break;
                                }
@@ -449,6 +449,7 @@ css_error 
css__selector_hash_find_by_class(css_selector_hash *hash,
                                                        req->uni) &&
                                            mq_rule_good_for_media(
                                                        head->sel->rule,
+                                                       req->unit_ctx,
                                                        req->media)) {
                                                /* Found a match */
                                                break;
@@ -529,6 +530,7 @@ css_error css__selector_hash_find_by_id(css_selector_hash 
*hash,
                                                        req->uni) &&
                                            mq_rule_good_for_media(
                                                        head->sel->rule,
+                                                       req->unit_ctx,
                                                        req->media)) {
                                                /* Found a match */
                                                break;
@@ -579,7 +581,7 @@ css_error 
css__selector_hash_find_universal(css_selector_hash *hash,
                                        head->sel_chain_bloom,
                                        req->node_bloom) &&
                            mq_rule_good_for_media(head->sel->rule,
-                                       req->media)) {
+                                       req->unit_ctx, req->media)) {
                                /* Found a match */
                                break;
                        }
@@ -922,7 +924,7 @@ css_error _iterate_elements(
                                                head->sel_chain_bloom,
                                                req->node_bloom) &&
                                    mq_rule_good_for_media(head->sel->rule,
-                                               req->media)) {
+                                               req->unit_ctx, req->media)) {
                                        /* Found a match */
                                        break;
                                }
@@ -982,6 +984,7 @@ css_error _iterate_classes(
                                                        req->uni) &&
                                            mq_rule_good_for_media(
                                                        head->sel->rule,
+                                                       req->unit_ctx,
                                                        req->media)) {
                                                /* Found a match */
                                                break;
@@ -1043,6 +1046,7 @@ css_error _iterate_ids(
                                                        req->uni) &&
                                            mq_rule_good_for_media(
                                                        head->sel->rule,
+                                                       req->unit_ctx,
                                                        req->media)) {
                                                /* Found a match */
                                                break;
@@ -1086,7 +1090,7 @@ css_error _iterate_universal(
                                        head->sel_chain_bloom,
                                        req->node_bloom) &&
                            mq_rule_good_for_media(head->sel->rule,
-                                       req->media)) {
+                                       req->unit_ctx, req->media)) {
                                /* Found a match */
                                break;
                        }
diff --git a/src/select/hash.h b/src/select/hash.h
index aecf15a..df4102f 100644
--- a/src/select/hash.h
+++ b/src/select/hash.h
@@ -10,6 +10,7 @@
 
 #include <libwapcaplet/libwapcaplet.h>
 
+#include <libcss/unit.h>
 #include <libcss/errors.h>
 #include <libcss/functypes.h>
 
@@ -26,6 +27,7 @@ struct css_hash_selection_requirments {
        lwc_string *id;                 /* Name of id, or NULL */
        lwc_string *uni;                /* Universal element string "*" */
        const css_media *media;         /* Media spec we're selecting for */
+       const css_unit_ctx *unit_ctx;   /* Document unit conversion context. */
        const css_bloom *node_bloom;    /* Node's bloom filter */
 };
 
diff --git a/src/select/mq.h b/src/select/mq.h
index 080a6ba..a012a7b 100644
--- a/src/select/mq.h
+++ b/src/select/mq.h
@@ -16,7 +16,7 @@ static inline bool mq_match_feature_range_length_op1(
                css_mq_feature_op op,
                const css_mq_value *value,
                const css_fixed client_len,
-               const css_media *media)
+               const css_unit_ctx *unit_ctx)
 {
        css_fixed v;
 
@@ -25,7 +25,7 @@ static inline bool mq_match_feature_range_length_op1(
        }
 
        if (value->data.dim.unit != UNIT_PX) {
-               v = css_unit_len2px_mq(media,
+               v = css_unit_len2px_mq(unit_ctx,
                                value->data.dim.len,
                                css__to_css_unit(value->data.dim.unit));
        } else {
@@ -48,7 +48,7 @@ static inline bool mq_match_feature_range_length_op2(
                css_mq_feature_op op,
                const css_mq_value *value,
                const css_fixed client_len,
-               const css_media *media)
+               const css_unit_ctx *unit_ctx)
 {
        css_fixed v;
 
@@ -60,7 +60,7 @@ static inline bool mq_match_feature_range_length_op2(
        }
 
        if (value->data.dim.unit != UNIT_PX) {
-               v = css_unit_len2px_mq(media,
+               v = css_unit_len2px_mq(unit_ctx,
                                value->data.dim.len,
                                css__to_css_unit(value->data.dim.unit));
        } else {
@@ -81,31 +81,33 @@ static inline bool mq_match_feature_range_length_op2(
 /**
  * Match media query features.
  *
- * \param[in] feat   Condition to match.
- * \param[in] media  Current media spec, to check against feat.
+ * \param[in] feat      Condition to match.
+ * \param[in] unit_ctx  Current unit conversion context.
+ * \param[in] media     Current media spec, to check against feat.
  * \return true if condition matches, otherwise false.
  */
 static inline bool mq_match_feature(
                const css_mq_feature *feat,
+               const css_unit_ctx *unit_ctx,
                const css_media *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, media)) {
+                                       media->width, unit_ctx)) {
                        return false;
                }
                return mq_match_feature_range_length_op2(feat->op2,
-                                       &feat->value2, media->width, media);
+                               &feat->value2, media->width, unit_ctx);
 
        } else if (strcmp(lwc_string_data(feat->name), "height") == 0) {
                if (!mq_match_feature_range_length_op1(feat->op, &feat->value,
-                               media->height, media)) {
+                               media->height, unit_ctx)) {
                        return false;
                }
 
                return mq_match_feature_range_length_op2(feat->op2,
-                               &feat->value2, media->height, media);
+                               &feat->value2, media->height, unit_ctx);
        }
 
        /* TODO: Look at other feature names. */
@@ -116,12 +118,14 @@ static inline bool mq_match_feature(
 /**
  * Match media query conditions.
  *
- * \param[in] cond   Condition to match.
- * \param[in] media  Current media spec, to check against cond.
+ * \param[in] cond      Condition to match.
+ * \param[in] unit_ctx  Current unit conversion context.
+ * \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_unit_ctx *unit_ctx,
                const css_media *media)
 {
        bool matched = !cond->op;
@@ -130,11 +134,13 @@ static inline bool mq_match_condition(
                bool part_matched;
                if (cond->parts[i]->type == CSS_MQ_FEATURE) {
                        part_matched = mq_match_feature(
-                                       cond->parts[i]->data.feat, media);
+                                       cond->parts[i]->data.feat,
+                                       unit_ctx, media);
                } else {
                        assert(cond->parts[i]->type == CSS_MQ_COND);
                        part_matched = mq_match_condition(
-                                       cond->parts[i]->data.cond, media);
+                                       cond->parts[i]->data.cond,
+                                       unit_ctx, media);
                }
 
                if (cond->op) {
@@ -161,19 +167,22 @@ static inline bool mq_match_condition(
  * If anything in the list matches, the list matches.  If none match
  * it doesn't match.
  *
- * \param[in] m      Media query list.
- * \param[in] media  Current media spec, to check against m.
+ * \param[in] m         Media query list.
+ * \param[in] unit_ctx  Current unit conversion context.
+ * \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_unit_ctx *unit_ctx,
                const css_media *media)
 {
        for (; m != NULL; m = m->next) {
                /* Check type */
                if (!!(m->type & media->type) != m->negate_type) {
                        if (m->cond == NULL ||
-                                       mq_match_condition(m->cond, media)) {
+                                       mq_match_condition(m->cond,
+                                                       unit_ctx, media)) {
                                /* We have a match, no need to look further. */
                                return true;
                        }
@@ -186,11 +195,15 @@ static inline bool mq__list_match(
 /**
  * Test whether the rule applies for current media.
  *
- * \param rule   Rule to test
- * \param media  Current media spec
+ * \param rule      Rule to test
+ * \param unit_ctx  Current unit conversion context.
+ * \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)
+static inline bool mq_rule_good_for_media(
+               const css_rule *rule,
+               const css_unit_ctx *unit_ctx,
+               const css_media *media)
 {
        bool applies = true;
        const css_rule *ancestor = rule;
@@ -199,7 +212,7 @@ static inline bool mq_rule_good_for_media(const css_rule 
*rule, const css_media
                const css_rule_media *m = (const css_rule_media *) ancestor;
 
                if (ancestor->type == CSS_RULE_MEDIA) {
-                       applies = mq__list_match(m->media, media);
+                       applies = mq__list_match(m->media, unit_ctx, media);
                        if (applies == false) {
                                break;
                        }
diff --git a/src/select/select.c b/src/select/select.c
index 03a45fe..b050c0c 100644
--- a/src/select/select.c
+++ b/src/select/select.c
@@ -99,6 +99,7 @@ typedef struct css_select_font_faces_list {
 typedef struct css_select_font_faces_state {
        lwc_string *font_family;
        const css_media *media;
+       const css_unit_ctx *unit_ctx;
 
        css_select_font_faces_list ua_font_faces;
        css_select_font_faces_list user_font_faces;
@@ -1052,12 +1053,13 @@ static void css_select__finalise_selection_state(
 /**
  * Initialise a 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 specification we're selecting for.
- * \param[in]  handler  The client selection callback table.
- * \param[in]  pw       The client private data, passsed out to callbacks.
+ * \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 specification we're selecting for.
+ * \param[in]  unit_ctx  Unit conversion context.
+ * \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.
  */
 static css_error css_select__initialise_selection_state(
@@ -1065,6 +1067,7 @@ static css_error css_select__initialise_selection_state(
                void *node,
                void *parent,
                const css_media *media,
+               const css_unit_ctx *unit_ctx,
                css_select_handler *handler,
                void *pw)
 {
@@ -1075,6 +1078,7 @@ static css_error css_select__initialise_selection_state(
        memset(state, 0, sizeof(*state));
        state->node = node;
        state->media = media;
+       state->unit_ctx = unit_ctx;
        state->handler = handler;
        state->pw = pw;
        state->next_reject = state->reject_cache +
@@ -1165,7 +1169,7 @@ failed:
  *
  * \param ctx             Selection context to use
  * \param node            Node to select style for
- * \param unit_len_ctx    Context for length unit conversions.
+ * \param unit_ctx        Context for length unit conversions.
  * \param media           Currently active media specification
  * \param inline_style    Corresponding inline style for node, or NULL
  * \param handler         Dispatch table of handler functions
@@ -1183,7 +1187,7 @@ failed:
  * update the fully computed style for a node when layout changes.
  */
 css_error css_select_style(css_select_ctx *ctx, void *node,
-               const css_unit_len_ctx *unit_len_ctx,
+               const css_unit_ctx *unit_ctx,
                const css_media *media, const css_stylesheet *inline_style,
                css_select_handler *handler, void *pw,
                css_select_results **result)
@@ -1204,7 +1208,7 @@ css_error css_select_style(css_select_ctx *ctx, void 
*node,
                return error;
 
        error = css_select__initialise_selection_state(
-                       &state, node, parent, media, handler, pw);
+                       &state, node, parent, media, unit_ctx, handler, pw);
        if (error != CSS_OK)
                return error;
 
@@ -1269,7 +1273,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 (mq__list_match(s.media, media) &&
+               if (mq__list_match(s.media, unit_ctx, media) &&
                                s.sheet->disabled == false) {
                        error = select_from_sheet(ctx, s.sheet,
                                        s.origin, &state);
@@ -1356,7 +1360,7 @@ css_error css_select_style(css_select_ctx *ctx, void 
*node,
                /* Only compute absolute values for the base element */
                error = css__compute_absolute_values(NULL,
                                state.results->styles[CSS_PSEUDO_ELEMENT_NONE],
-                               unit_len_ctx);
+                               unit_ctx);
                if (error != CSS_OK)
                        goto cleanup;
        }
@@ -1420,12 +1424,15 @@ css_error css_select_results_destroy(css_select_results 
*results)
  *
  * \param ctx          Selection context
  * \param media        Currently active media spec
+ * \param unit_ctx     Current unit conversion context.
  * \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,
-               const css_media *media, lwc_string *font_family,
+               const css_media *media,
+               const css_unit_ctx *unit_ctx,
+               lwc_string *font_family,
                css_select_font_faces_results **result)
 {
        uint32_t i;
@@ -1439,6 +1446,7 @@ css_error css_select_font_faces(css_select_ctx *ctx,
        memset(&state, 0, sizeof(css_select_font_faces_state));
        state.font_family = font_family;
        state.media = media;
+       state.unit_ctx = unit_ctx;
 
        /* Iterate through the top-level stylesheets, selecting font-faces
         * from those which apply to our current media requirements and
@@ -1446,7 +1454,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 (mq__list_match(s.media, media) &&
+               if (mq__list_match(s.media, unit_ctx, media) &&
                                s.sheet->disabled == false) {
                        error = select_font_faces_from_sheet(s.sheet,
                                        s.origin, &state);
@@ -1846,6 +1854,7 @@ css_error select_from_sheet(css_select_ctx *ctx, const 
css_stylesheet *sheet,
 
                        if (import->sheet != NULL &&
                                        mq__list_match(import->media,
+                                                       state->unit_ctx,
                                                        state->media)) {
                                /* It's applicable, so process it */
                                if (sp >= IMPORT_STACK_SIZE)
@@ -1889,7 +1898,8 @@ static css_error _select_font_face_from_rule(
                const css_rule_font_face *rule, css_origin origin,
                css_select_font_faces_state *state)
 {
-       if (mq_rule_good_for_media((const css_rule *) rule, state->media)) {
+       if (mq_rule_good_for_media((const css_rule *) rule,
+                       state->unit_ctx, state->media)) {
                bool correct_family = false;
 
                if (lwc_string_isequal(
@@ -1954,6 +1964,7 @@ static css_error select_font_faces_from_sheet(
 
                        if (import->sheet != NULL &&
                                        mq__list_match(import->media,
+                                                       state->unit_ctx,
                                                        state->media)) {
                                /* It's applicable, so process it */
                                if (sp >= IMPORT_STACK_SIZE)
@@ -2101,6 +2112,7 @@ css_error match_selectors_in_sheet(css_select_ctx *ctx,
 
        /* Set up general selector chain requirments */
        req.media = state->media;
+       req.unit_ctx = state->unit_ctx;
        req.node_bloom = state->node_data->bloom;
        req.uni = ctx->universal;
 
diff --git a/src/select/select.h b/src/select/select.h
index dc9aa4a..0a16b12 100644
--- a/src/select/select.h
+++ b/src/select/select.h
@@ -64,6 +64,7 @@ struct css_node_data {
 typedef struct css_select_state {
        void *node;                     /* Node we're selecting for */
        const css_media *media;         /* Currently active media spec */
+       const css_unit_ctx *unit_ctx;   /* Unit conversion context. */
        css_select_results *results;    /* Result set to populate */
 
        css_pseudo_element current_pseudo;      /* Current pseudo element */
diff --git a/src/select/unit.c b/src/select/unit.c
index a279ec7..9129d72 100644
--- a/src/select/unit.c
+++ b/src/select/unit.c
@@ -118,7 +118,7 @@ static inline css_fixed css_unit__absolute_len2pt(
 /* Exported function, documented in libcss/unit.h. */
 css_fixed css_unit_font_size_len2pt(
                const css_computed_style *style,
-               const css_unit_len_ctx *ctx,
+               const css_unit_ctx *ctx,
                const css_fixed length,
                const css_unit unit)
 {
@@ -279,22 +279,22 @@ static inline css_fixed css_unit__px_per_unit(
 
 /* Exported function, documented in unit.h. */
 css_fixed css_unit_len2px_mq(
-               const css_media *media,
+               const css_unit_ctx *ctx,
                const css_fixed length,
                const css_unit unit)
 {
        /* In the media query context there is no reference or root element
-        * style, so these are hardcoded to NULL. */
+        * style, so these are hard-coded to NULL. */
        css_fixed px_per_unit = css_unit__px_per_unit(
+                       ctx->measure,
                        NULL,
                        NULL,
-                       NULL,
-                       media->client_font_size,
-                       INTTOFIX(0),
-                       media->height,
-                       media->width,
+                       ctx->font_size_default,
+                       ctx->font_size_minimum,
+                       ctx->viewport_height,
+                       ctx->viewport_width,
                        unit,
-                       NULL);
+                       ctx->pw);
 
        /* Ensure we round px_per_unit to the nearest whole number of pixels:
         * the use of FIXTOINT() below will truncate. */
@@ -307,7 +307,7 @@ css_fixed css_unit_len2px_mq(
 /* Exported function, documented in libcss/unit.h. */
 css_fixed css_unit_len2css_px(
                const css_computed_style *style,
-               const css_unit_len_ctx *ctx,
+               const css_unit_ctx *ctx,
                const css_fixed length,
                const css_unit unit)
 {
@@ -333,7 +333,7 @@ css_fixed css_unit_len2css_px(
 /* Exported function, documented in libcss/unit.h. */
 css_fixed css_unit_len2device_px(
                const css_computed_style *style,
-               const css_unit_len_ctx *ctx,
+               const css_unit_ctx *ctx,
                const css_fixed length,
                const css_unit unit)
 {
diff --git a/src/select/unit.h b/src/select/unit.h
index e4d21da..6a677b6 100644
--- a/src/select/unit.h
+++ b/src/select/unit.h
@@ -14,13 +14,13 @@
 /**
  * Convert a length to CSS pixels for a media query context.
  *
- * \param[in]  media   Client media specification.
+ * \param[in]  ctx     Document unit conversion context.
  * \param[in]  length  Length to convert.
  * \param[in]  unit    Current unit of length.
  * \return A length in CSS pixels.
  */
 css_fixed css_unit_len2px_mq(
-               const css_media *media,
+               const css_unit_ctx *ctx,
                const css_fixed length,
                const css_unit unit);
 
diff --git a/test/select.c b/test/select.c
index 8226a8b..a8f8998 100644
--- a/test/select.c
+++ b/test/select.c
@@ -164,7 +164,7 @@ static css_error set_libcss_node_data(void *pw, void *n,
 static css_error get_libcss_node_data(void *pw, void *n,
                void **libcss_node_data);
 
-static css_unit_len_ctx unit_len_ctx = {
+static css_unit_ctx unit_ctx = {
        .font_size_default = 16 * (1 << CSS_RADIX_POINT),
 };
 
@@ -768,11 +768,11 @@ static void run_test_select_tree(css_select_ctx *select,
        struct node *n = NULL;
 
        if (node->parent == NULL) {
-               unit_len_ctx.root_style = NULL;
+               unit_ctx.root_style = NULL;
        }
 
 
-       assert(css_select_style(select, node, &unit_len_ctx, &ctx->media, NULL,
+       assert(css_select_style(select, node, &unit_ctx, &ctx->media, NULL,
                        &select_handler, ctx, &sr) == CSS_OK);
 
        if (node->parent != NULL) {
@@ -780,7 +780,7 @@ static void run_test_select_tree(css_select_ctx *select,
                assert(css_computed_style_compose(
                                node->parent->sr->styles[ctx->pseudo_element],
                                sr->styles[ctx->pseudo_element],
-                               &unit_len_ctx,
+                               &unit_ctx,
                                &composed) == CSS_OK);
                css_computed_style_destroy(sr->styles[ctx->pseudo_element]);
                sr->styles[ctx->pseudo_element] = composed;
@@ -794,7 +794,7 @@ static void run_test_select_tree(css_select_ctx *select,
        }
 
        if (node->parent == NULL) {
-               unit_len_ctx.root_style = node->sr->styles[ctx->pseudo_element];
+               unit_ctx.root_style = node->sr->styles[ctx->pseudo_element];
        }
 
        for (n = node->children; n != NULL; n = n->next) {


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

Summary of changes:
 examples/example1.c       |    2 +-
 include/libcss/computed.h |    2 +-
 include/libcss/select.h   |    6 +++--
 include/libcss/types.h    |    4 ----
 include/libcss/unit.h     |   10 ++++-----
 src/select/computed.c     |   16 ++++++-------
 src/select/computed.h     |    2 +-
 src/select/hash.c         |   12 ++++++----
 src/select/hash.h         |    2 ++
 src/select/mq.h           |   55 ++++++++++++++++++++++++++++-----------------
 src/select/select.c       |   40 +++++++++++++++++++++------------
 src/select/select.h       |    1 +
 src/select/unit.c         |   22 +++++++++---------
 src/select/unit.h         |    4 ++--
 test/select.c             |   10 ++++-----
 15 files changed, 109 insertions(+), 79 deletions(-)

diff --git a/examples/example1.c b/examples/example1.c
index 6135793..1d2462c 100644
--- a/examples/example1.c
+++ b/examples/example1.c
@@ -103,7 +103,7 @@ static css_error set_libcss_node_data(void *pw, void *n,
 static css_error get_libcss_node_data(void *pw, void *n,
                void **libcss_node_data);
 
-static css_unit_len_ctx uint_len_ctx = {
+static css_unit_ctx uint_len_ctx = {
        .viewport_width    = 800 * (1 << CSS_RADIX_POINT),
        .viewport_height   = 600 * (1 << CSS_RADIX_POINT),
        .font_size_default =  16 * (1 << CSS_RADIX_POINT),
diff --git a/include/libcss/computed.h b/include/libcss/computed.h
index 1587d78..30e369b 100644
--- a/include/libcss/computed.h
+++ b/include/libcss/computed.h
@@ -82,7 +82,7 @@ css_error css_computed_style_destroy(css_computed_style 
*style);
 css_error css_computed_style_compose(
                const css_computed_style *restrict parent,
                const css_computed_style *restrict child,
-               const css_unit_len_ctx *unit_len_ctx,
+               const css_unit_ctx *unit_ctx,
                css_computed_style **restrict result);
 
 /******************************************************************************
diff --git a/include/libcss/select.h b/include/libcss/select.h
index bfaf531..25317e5 100644
--- a/include/libcss/select.h
+++ b/include/libcss/select.h
@@ -219,14 +219,16 @@ 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,
-               const css_unit_len_ctx *unit_len_ctx,
+               const css_unit_ctx *unit_ctx,
                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,
-               const css_media *media, lwc_string *font_family,
+               const css_media *media,
+               const css_unit_ctx *unit_ctx,
+               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/include/libcss/types.h b/include/libcss/types.h
index 1186c6f..2b0dfb7 100644
--- a/include/libcss/types.h
+++ b/include/libcss/types.h
@@ -234,10 +234,6 @@ typedef struct css_media {
 
        /* Scripting media features */
        css_media_scripting scripting;
-
-       /* Client details for length conversion */
-       css_fixed client_font_size;   /* In pt */
-       css_fixed client_line_height; /* In css pixels */
 } css_media;
 
 /**
diff --git a/include/libcss/unit.h b/include/libcss/unit.h
index a847077..67194c1 100644
--- a/include/libcss/unit.h
+++ b/include/libcss/unit.h
@@ -36,7 +36,7 @@ typedef css_fixed (*css_unit_len_measure)(
  * If a NULL pointer is given, LibCSS will use a fixed scaling of
  * the "em" unit.
  */
-typedef struct css_unit_len_ctx {
+typedef struct css_unit_ctx {
        /**
         * Viewport width in CSS pixels.
         * Used if unit is vh, vw, vi, vb, vmin, or vmax.
@@ -73,7 +73,7 @@ typedef struct css_unit_len_ctx {
         * Optional client callback for font measuring.
         */
        const css_unit_len_measure measure;
-} css_unit_len_ctx;
+} css_unit_ctx;
 
 /**
  * Convert css pixels to physical pixels.
@@ -114,7 +114,7 @@ static inline css_fixed css_unit_device2css_px(
  */
 css_fixed css_unit_font_size_len2pt(
                const css_computed_style *style,
-               const css_unit_len_ctx *ctx,
+               const css_unit_ctx *ctx,
                const css_fixed length,
                const css_unit unit);
 
@@ -129,7 +129,7 @@ css_fixed css_unit_font_size_len2pt(
  */
 css_fixed css_unit_len2css_px(
                const css_computed_style *style,
-               const css_unit_len_ctx *ctx,
+               const css_unit_ctx *ctx,
                const css_fixed length,
                const css_unit unit);
 
@@ -144,7 +144,7 @@ css_fixed css_unit_len2css_px(
  */
 css_fixed css_unit_len2device_px(
                const css_computed_style *style,
-               const css_unit_len_ctx *ctx,
+               const css_unit_ctx *ctx,
                const css_fixed length,
                const css_unit unit);
 
diff --git a/src/select/computed.c b/src/select/computed.c
index d075af9..c019590 100644
--- a/src/select/computed.c
+++ b/src/select/computed.c
@@ -248,7 +248,7 @@ css_error css__computed_style_initialise(css_computed_style 
*style,
 css_error css_computed_style_compose(
                const css_computed_style *restrict parent,
                const css_computed_style *restrict child,
-               const css_unit_len_ctx *unit_len_ctx,
+               const css_unit_ctx *unit_ctx,
                css_computed_style **restrict result)
 {
        css_computed_style *composed;
@@ -274,7 +274,7 @@ css_error css_computed_style_compose(
        }
 
        /* Finally, compute absolute values for everything */
-       error = css__compute_absolute_values(parent, composed, unit_len_ctx);
+       error = css__compute_absolute_values(parent, composed, unit_ctx);
        if (error != CSS_OK) {
                return error;
        }
@@ -1085,12 +1085,12 @@ uint8_t css_computed_order(const css_computed_style 
*style,
  *
  * \param parent             Parent style, or NULL for tree root
  * \param style              Computed style to process
- * \param unit_len_ctx       Client length conversion context.
+ * \param unit_ctx       Client length conversion context.
  * \return CSS_OK on success.
  */
 css_error css__compute_absolute_values(const css_computed_style *parent,
                css_computed_style *style,
-               const css_unit_len_ctx *unit_len_ctx)
+               const css_unit_ctx *unit_ctx)
 {
        css_hint_length *ref_length = NULL;
        css_hint psize, size, ex_size;
@@ -1112,8 +1112,8 @@ css_error css__compute_absolute_values(const 
css_computed_style *parent,
                        &size.data.length.unit);
 
        error = css_unit_compute_absolute_font_size(ref_length,
-                       unit_len_ctx->root_style,
-                       unit_len_ctx->font_size_default,
+                       unit_ctx->root_style,
+                       unit_ctx->font_size_default,
                        &size);
        if (error != CSS_OK)
                return error;
@@ -1131,8 +1131,8 @@ css_error css__compute_absolute_values(const 
css_computed_style *parent,
 
        error = css_unit_compute_absolute_font_size(
                        &size.data.length,
-                       unit_len_ctx->root_style,
-                       unit_len_ctx->font_size_default,
+                       unit_ctx->root_style,
+                       unit_ctx->font_size_default,
                        &ex_size);
        if (error != CSS_OK)
                return error;
diff --git a/src/select/computed.h b/src/select/computed.h
index 8b33405..a4bd23d 100644
--- a/src/select/computed.h
+++ b/src/select/computed.h
@@ -37,6 +37,6 @@ css_error css__computed_style_initialise(css_computed_style 
*style,
 
 css_error css__compute_absolute_values(const css_computed_style *parent,
                css_computed_style *style,
-               const css_unit_len_ctx *unit_len_ctx);
+               const css_unit_ctx *unit_ctx);
 
 #endif
diff --git a/src/select/hash.c b/src/select/hash.c
index 4dedec9..16aebf7 100644
--- a/src/select/hash.c
+++ b/src/select/hash.c
@@ -370,7 +370,7 @@ css_error css__selector_hash_find(css_selector_hash *hash,
                                                head->sel_chain_bloom,
                                                req->node_bloom) &&
                                    mq_rule_good_for_media(head->sel->rule,
-                                               req->media)) {
+                                               req->unit_ctx, req->media)) {
                                        /* Found a match */
                                        break;
                                }
@@ -449,6 +449,7 @@ css_error 
css__selector_hash_find_by_class(css_selector_hash *hash,
                                                        req->uni) &&
                                            mq_rule_good_for_media(
                                                        head->sel->rule,
+                                                       req->unit_ctx,
                                                        req->media)) {
                                                /* Found a match */
                                                break;
@@ -529,6 +530,7 @@ css_error css__selector_hash_find_by_id(css_selector_hash 
*hash,
                                                        req->uni) &&
                                            mq_rule_good_for_media(
                                                        head->sel->rule,
+                                                       req->unit_ctx,
                                                        req->media)) {
                                                /* Found a match */
                                                break;
@@ -579,7 +581,7 @@ css_error 
css__selector_hash_find_universal(css_selector_hash *hash,
                                        head->sel_chain_bloom,
                                        req->node_bloom) &&
                            mq_rule_good_for_media(head->sel->rule,
-                                       req->media)) {
+                                       req->unit_ctx, req->media)) {
                                /* Found a match */
                                break;
                        }
@@ -922,7 +924,7 @@ css_error _iterate_elements(
                                                head->sel_chain_bloom,
                                                req->node_bloom) &&
                                    mq_rule_good_for_media(head->sel->rule,
-                                               req->media)) {
+                                               req->unit_ctx, req->media)) {
                                        /* Found a match */
                                        break;
                                }
@@ -982,6 +984,7 @@ css_error _iterate_classes(
                                                        req->uni) &&
                                            mq_rule_good_for_media(
                                                        head->sel->rule,
+                                                       req->unit_ctx,
                                                        req->media)) {
                                                /* Found a match */
                                                break;
@@ -1043,6 +1046,7 @@ css_error _iterate_ids(
                                                        req->uni) &&
                                            mq_rule_good_for_media(
                                                        head->sel->rule,
+                                                       req->unit_ctx,
                                                        req->media)) {
                                                /* Found a match */
                                                break;
@@ -1086,7 +1090,7 @@ css_error _iterate_universal(
                                        head->sel_chain_bloom,
                                        req->node_bloom) &&
                            mq_rule_good_for_media(head->sel->rule,
-                                       req->media)) {
+                                       req->unit_ctx, req->media)) {
                                /* Found a match */
                                break;
                        }
diff --git a/src/select/hash.h b/src/select/hash.h
index aecf15a..df4102f 100644
--- a/src/select/hash.h
+++ b/src/select/hash.h
@@ -10,6 +10,7 @@
 
 #include <libwapcaplet/libwapcaplet.h>
 
+#include <libcss/unit.h>
 #include <libcss/errors.h>
 #include <libcss/functypes.h>
 
@@ -26,6 +27,7 @@ struct css_hash_selection_requirments {
        lwc_string *id;                 /* Name of id, or NULL */
        lwc_string *uni;                /* Universal element string "*" */
        const css_media *media;         /* Media spec we're selecting for */
+       const css_unit_ctx *unit_ctx;   /* Document unit conversion context. */
        const css_bloom *node_bloom;    /* Node's bloom filter */
 };
 
diff --git a/src/select/mq.h b/src/select/mq.h
index 080a6ba..a012a7b 100644
--- a/src/select/mq.h
+++ b/src/select/mq.h
@@ -16,7 +16,7 @@ static inline bool mq_match_feature_range_length_op1(
                css_mq_feature_op op,
                const css_mq_value *value,
                const css_fixed client_len,
-               const css_media *media)
+               const css_unit_ctx *unit_ctx)
 {
        css_fixed v;
 
@@ -25,7 +25,7 @@ static inline bool mq_match_feature_range_length_op1(
        }
 
        if (value->data.dim.unit != UNIT_PX) {
-               v = css_unit_len2px_mq(media,
+               v = css_unit_len2px_mq(unit_ctx,
                                value->data.dim.len,
                                css__to_css_unit(value->data.dim.unit));
        } else {
@@ -48,7 +48,7 @@ static inline bool mq_match_feature_range_length_op2(
                css_mq_feature_op op,
                const css_mq_value *value,
                const css_fixed client_len,
-               const css_media *media)
+               const css_unit_ctx *unit_ctx)
 {
        css_fixed v;
 
@@ -60,7 +60,7 @@ static inline bool mq_match_feature_range_length_op2(
        }
 
        if (value->data.dim.unit != UNIT_PX) {
-               v = css_unit_len2px_mq(media,
+               v = css_unit_len2px_mq(unit_ctx,
                                value->data.dim.len,
                                css__to_css_unit(value->data.dim.unit));
        } else {
@@ -81,31 +81,33 @@ static inline bool mq_match_feature_range_length_op2(
 /**
  * Match media query features.
  *
- * \param[in] feat   Condition to match.
- * \param[in] media  Current media spec, to check against feat.
+ * \param[in] feat      Condition to match.
+ * \param[in] unit_ctx  Current unit conversion context.
+ * \param[in] media     Current media spec, to check against feat.
  * \return true if condition matches, otherwise false.
  */
 static inline bool mq_match_feature(
                const css_mq_feature *feat,
+               const css_unit_ctx *unit_ctx,
                const css_media *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, media)) {
+                                       media->width, unit_ctx)) {
                        return false;
                }
                return mq_match_feature_range_length_op2(feat->op2,
-                                       &feat->value2, media->width, media);
+                               &feat->value2, media->width, unit_ctx);
 
        } else if (strcmp(lwc_string_data(feat->name), "height") == 0) {
                if (!mq_match_feature_range_length_op1(feat->op, &feat->value,
-                               media->height, media)) {
+                               media->height, unit_ctx)) {
                        return false;
                }
 
                return mq_match_feature_range_length_op2(feat->op2,
-                               &feat->value2, media->height, media);
+                               &feat->value2, media->height, unit_ctx);
        }
 
        /* TODO: Look at other feature names. */
@@ -116,12 +118,14 @@ static inline bool mq_match_feature(
 /**
  * Match media query conditions.
  *
- * \param[in] cond   Condition to match.
- * \param[in] media  Current media spec, to check against cond.
+ * \param[in] cond      Condition to match.
+ * \param[in] unit_ctx  Current unit conversion context.
+ * \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_unit_ctx *unit_ctx,
                const css_media *media)
 {
        bool matched = !cond->op;
@@ -130,11 +134,13 @@ static inline bool mq_match_condition(
                bool part_matched;
                if (cond->parts[i]->type == CSS_MQ_FEATURE) {
                        part_matched = mq_match_feature(
-                                       cond->parts[i]->data.feat, media);
+                                       cond->parts[i]->data.feat,
+                                       unit_ctx, media);
                } else {
                        assert(cond->parts[i]->type == CSS_MQ_COND);
                        part_matched = mq_match_condition(
-                                       cond->parts[i]->data.cond, media);
+                                       cond->parts[i]->data.cond,
+                                       unit_ctx, media);
                }
 
                if (cond->op) {
@@ -161,19 +167,22 @@ static inline bool mq_match_condition(
  * If anything in the list matches, the list matches.  If none match
  * it doesn't match.
  *
- * \param[in] m      Media query list.
- * \param[in] media  Current media spec, to check against m.
+ * \param[in] m         Media query list.
+ * \param[in] unit_ctx  Current unit conversion context.
+ * \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_unit_ctx *unit_ctx,
                const css_media *media)
 {
        for (; m != NULL; m = m->next) {
                /* Check type */
                if (!!(m->type & media->type) != m->negate_type) {
                        if (m->cond == NULL ||
-                                       mq_match_condition(m->cond, media)) {
+                                       mq_match_condition(m->cond,
+                                                       unit_ctx, media)) {
                                /* We have a match, no need to look further. */
                                return true;
                        }
@@ -186,11 +195,15 @@ static inline bool mq__list_match(
 /**
  * Test whether the rule applies for current media.
  *
- * \param rule   Rule to test
- * \param media  Current media spec
+ * \param rule      Rule to test
+ * \param unit_ctx  Current unit conversion context.
+ * \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)
+static inline bool mq_rule_good_for_media(
+               const css_rule *rule,
+               const css_unit_ctx *unit_ctx,
+               const css_media *media)
 {
        bool applies = true;
        const css_rule *ancestor = rule;
@@ -199,7 +212,7 @@ static inline bool mq_rule_good_for_media(const css_rule 
*rule, const css_media
                const css_rule_media *m = (const css_rule_media *) ancestor;
 
                if (ancestor->type == CSS_RULE_MEDIA) {
-                       applies = mq__list_match(m->media, media);
+                       applies = mq__list_match(m->media, unit_ctx, media);
                        if (applies == false) {
                                break;
                        }
diff --git a/src/select/select.c b/src/select/select.c
index 03a45fe..b050c0c 100644
--- a/src/select/select.c
+++ b/src/select/select.c
@@ -99,6 +99,7 @@ typedef struct css_select_font_faces_list {
 typedef struct css_select_font_faces_state {
        lwc_string *font_family;
        const css_media *media;
+       const css_unit_ctx *unit_ctx;
 
        css_select_font_faces_list ua_font_faces;
        css_select_font_faces_list user_font_faces;
@@ -1052,12 +1053,13 @@ static void css_select__finalise_selection_state(
 /**
  * Initialise a 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 specification we're selecting for.
- * \param[in]  handler  The client selection callback table.
- * \param[in]  pw       The client private data, passsed out to callbacks.
+ * \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 specification we're selecting for.
+ * \param[in]  unit_ctx  Unit conversion context.
+ * \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.
  */
 static css_error css_select__initialise_selection_state(
@@ -1065,6 +1067,7 @@ static css_error css_select__initialise_selection_state(
                void *node,
                void *parent,
                const css_media *media,
+               const css_unit_ctx *unit_ctx,
                css_select_handler *handler,
                void *pw)
 {
@@ -1075,6 +1078,7 @@ static css_error css_select__initialise_selection_state(
        memset(state, 0, sizeof(*state));
        state->node = node;
        state->media = media;
+       state->unit_ctx = unit_ctx;
        state->handler = handler;
        state->pw = pw;
        state->next_reject = state->reject_cache +
@@ -1165,7 +1169,7 @@ failed:
  *
  * \param ctx             Selection context to use
  * \param node            Node to select style for
- * \param unit_len_ctx    Context for length unit conversions.
+ * \param unit_ctx        Context for length unit conversions.
  * \param media           Currently active media specification
  * \param inline_style    Corresponding inline style for node, or NULL
  * \param handler         Dispatch table of handler functions
@@ -1183,7 +1187,7 @@ failed:
  * update the fully computed style for a node when layout changes.
  */
 css_error css_select_style(css_select_ctx *ctx, void *node,
-               const css_unit_len_ctx *unit_len_ctx,
+               const css_unit_ctx *unit_ctx,
                const css_media *media, const css_stylesheet *inline_style,
                css_select_handler *handler, void *pw,
                css_select_results **result)
@@ -1204,7 +1208,7 @@ css_error css_select_style(css_select_ctx *ctx, void 
*node,
                return error;
 
        error = css_select__initialise_selection_state(
-                       &state, node, parent, media, handler, pw);
+                       &state, node, parent, media, unit_ctx, handler, pw);
        if (error != CSS_OK)
                return error;
 
@@ -1269,7 +1273,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 (mq__list_match(s.media, media) &&
+               if (mq__list_match(s.media, unit_ctx, media) &&
                                s.sheet->disabled == false) {
                        error = select_from_sheet(ctx, s.sheet,
                                        s.origin, &state);
@@ -1356,7 +1360,7 @@ css_error css_select_style(css_select_ctx *ctx, void 
*node,
                /* Only compute absolute values for the base element */
                error = css__compute_absolute_values(NULL,
                                state.results->styles[CSS_PSEUDO_ELEMENT_NONE],
-                               unit_len_ctx);
+                               unit_ctx);
                if (error != CSS_OK)
                        goto cleanup;
        }
@@ -1420,12 +1424,15 @@ css_error css_select_results_destroy(css_select_results 
*results)
  *
  * \param ctx          Selection context
  * \param media        Currently active media spec
+ * \param unit_ctx     Current unit conversion context.
  * \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,
-               const css_media *media, lwc_string *font_family,
+               const css_media *media,
+               const css_unit_ctx *unit_ctx,
+               lwc_string *font_family,
                css_select_font_faces_results **result)
 {
        uint32_t i;
@@ -1439,6 +1446,7 @@ css_error css_select_font_faces(css_select_ctx *ctx,
        memset(&state, 0, sizeof(css_select_font_faces_state));
        state.font_family = font_family;
        state.media = media;
+       state.unit_ctx = unit_ctx;
 
        /* Iterate through the top-level stylesheets, selecting font-faces
         * from those which apply to our current media requirements and
@@ -1446,7 +1454,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 (mq__list_match(s.media, media) &&
+               if (mq__list_match(s.media, unit_ctx, media) &&
                                s.sheet->disabled == false) {
                        error = select_font_faces_from_sheet(s.sheet,
                                        s.origin, &state);
@@ -1846,6 +1854,7 @@ css_error select_from_sheet(css_select_ctx *ctx, const 
css_stylesheet *sheet,
 
                        if (import->sheet != NULL &&
                                        mq__list_match(import->media,
+                                                       state->unit_ctx,
                                                        state->media)) {
                                /* It's applicable, so process it */
                                if (sp >= IMPORT_STACK_SIZE)
@@ -1889,7 +1898,8 @@ static css_error _select_font_face_from_rule(
                const css_rule_font_face *rule, css_origin origin,
                css_select_font_faces_state *state)
 {
-       if (mq_rule_good_for_media((const css_rule *) rule, state->media)) {
+       if (mq_rule_good_for_media((const css_rule *) rule,
+                       state->unit_ctx, state->media)) {
                bool correct_family = false;
 
                if (lwc_string_isequal(
@@ -1954,6 +1964,7 @@ static css_error select_font_faces_from_sheet(
 
                        if (import->sheet != NULL &&
                                        mq__list_match(import->media,
+                                                       state->unit_ctx,
                                                        state->media)) {
                                /* It's applicable, so process it */
                                if (sp >= IMPORT_STACK_SIZE)
@@ -2101,6 +2112,7 @@ css_error match_selectors_in_sheet(css_select_ctx *ctx,
 
        /* Set up general selector chain requirments */
        req.media = state->media;
+       req.unit_ctx = state->unit_ctx;
        req.node_bloom = state->node_data->bloom;
        req.uni = ctx->universal;
 
diff --git a/src/select/select.h b/src/select/select.h
index dc9aa4a..0a16b12 100644
--- a/src/select/select.h
+++ b/src/select/select.h
@@ -64,6 +64,7 @@ struct css_node_data {
 typedef struct css_select_state {
        void *node;                     /* Node we're selecting for */
        const css_media *media;         /* Currently active media spec */
+       const css_unit_ctx *unit_ctx;   /* Unit conversion context. */
        css_select_results *results;    /* Result set to populate */
 
        css_pseudo_element current_pseudo;      /* Current pseudo element */
diff --git a/src/select/unit.c b/src/select/unit.c
index a279ec7..9129d72 100644
--- a/src/select/unit.c
+++ b/src/select/unit.c
@@ -118,7 +118,7 @@ static inline css_fixed css_unit__absolute_len2pt(
 /* Exported function, documented in libcss/unit.h. */
 css_fixed css_unit_font_size_len2pt(
                const css_computed_style *style,
-               const css_unit_len_ctx *ctx,
+               const css_unit_ctx *ctx,
                const css_fixed length,
                const css_unit unit)
 {
@@ -279,22 +279,22 @@ static inline css_fixed css_unit__px_per_unit(
 
 /* Exported function, documented in unit.h. */
 css_fixed css_unit_len2px_mq(
-               const css_media *media,
+               const css_unit_ctx *ctx,
                const css_fixed length,
                const css_unit unit)
 {
        /* In the media query context there is no reference or root element
-        * style, so these are hardcoded to NULL. */
+        * style, so these are hard-coded to NULL. */
        css_fixed px_per_unit = css_unit__px_per_unit(
+                       ctx->measure,
                        NULL,
                        NULL,
-                       NULL,
-                       media->client_font_size,
-                       INTTOFIX(0),
-                       media->height,
-                       media->width,
+                       ctx->font_size_default,
+                       ctx->font_size_minimum,
+                       ctx->viewport_height,
+                       ctx->viewport_width,
                        unit,
-                       NULL);
+                       ctx->pw);
 
        /* Ensure we round px_per_unit to the nearest whole number of pixels:
         * the use of FIXTOINT() below will truncate. */
@@ -307,7 +307,7 @@ css_fixed css_unit_len2px_mq(
 /* Exported function, documented in libcss/unit.h. */
 css_fixed css_unit_len2css_px(
                const css_computed_style *style,
-               const css_unit_len_ctx *ctx,
+               const css_unit_ctx *ctx,
                const css_fixed length,
                const css_unit unit)
 {
@@ -333,7 +333,7 @@ css_fixed css_unit_len2css_px(
 /* Exported function, documented in libcss/unit.h. */
 css_fixed css_unit_len2device_px(
                const css_computed_style *style,
-               const css_unit_len_ctx *ctx,
+               const css_unit_ctx *ctx,
                const css_fixed length,
                const css_unit unit)
 {
diff --git a/src/select/unit.h b/src/select/unit.h
index e4d21da..6a677b6 100644
--- a/src/select/unit.h
+++ b/src/select/unit.h
@@ -14,13 +14,13 @@
 /**
  * Convert a length to CSS pixels for a media query context.
  *
- * \param[in]  media   Client media specification.
+ * \param[in]  ctx     Document unit conversion context.
  * \param[in]  length  Length to convert.
  * \param[in]  unit    Current unit of length.
  * \return A length in CSS pixels.
  */
 css_fixed css_unit_len2px_mq(
-               const css_media *media,
+               const css_unit_ctx *ctx,
                const css_fixed length,
                const css_unit unit);
 
diff --git a/test/select.c b/test/select.c
index 8226a8b..a8f8998 100644
--- a/test/select.c
+++ b/test/select.c
@@ -164,7 +164,7 @@ static css_error set_libcss_node_data(void *pw, void *n,
 static css_error get_libcss_node_data(void *pw, void *n,
                void **libcss_node_data);
 
-static css_unit_len_ctx unit_len_ctx = {
+static css_unit_ctx unit_ctx = {
        .font_size_default = 16 * (1 << CSS_RADIX_POINT),
 };
 
@@ -768,11 +768,11 @@ static void run_test_select_tree(css_select_ctx *select,
        struct node *n = NULL;
 
        if (node->parent == NULL) {
-               unit_len_ctx.root_style = NULL;
+               unit_ctx.root_style = NULL;
        }
 
 
-       assert(css_select_style(select, node, &unit_len_ctx, &ctx->media, NULL,
+       assert(css_select_style(select, node, &unit_ctx, &ctx->media, NULL,
                        &select_handler, ctx, &sr) == CSS_OK);
 
        if (node->parent != NULL) {
@@ -780,7 +780,7 @@ static void run_test_select_tree(css_select_ctx *select,
                assert(css_computed_style_compose(
                                node->parent->sr->styles[ctx->pseudo_element],
                                sr->styles[ctx->pseudo_element],
-                               &unit_len_ctx,
+                               &unit_ctx,
                                &composed) == CSS_OK);
                css_computed_style_destroy(sr->styles[ctx->pseudo_element]);
                sr->styles[ctx->pseudo_element] = composed;
@@ -794,7 +794,7 @@ static void run_test_select_tree(css_select_ctx *select,
        }
 
        if (node->parent == NULL) {
-               unit_len_ctx.root_style = node->sr->styles[ctx->pseudo_element];
+               unit_ctx.root_style = node->sr->styles[ctx->pseudo_element];
        }
 
        for (n = node->children; n != NULL; n = n->next) {


-- 
Cascading Style Sheets library
_______________________________________________
netsurf-commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to