9#ifndef css_select_mq_h_
10#define css_select_mq_h_
16static inline bool mq_match_feature_range_length_op1(
24 if (value->
type != CSS_MQ_VALUE_TYPE_DIM) {
48static inline bool mq_match_feature_range_length_op2(
59 if (value->
type != CSS_MQ_VALUE_TYPE_DIM) {
82static inline bool mq_match_feature_eq_ident_op1(
85 const lwc_string *client_value)
89 if (value->
type != CSS_MQ_VALUE_TYPE_IDENT) {
93 if (value->
data.
ident == NULL || client_value == NULL) {
99 return (lwc_string_isequal(value->
data.
ident,
100 client_value, &is_match) == lwc_error_ok) &&
115static inline bool mq_match_feature(
124 if (lwc_string_isequal(feat->
name,
125 str->
width, &match) == lwc_error_ok &&
127 if (!mq_match_feature_range_length_op1(feat->
op, &feat->
value,
128 media->
width, unit_ctx)) {
131 return mq_match_feature_range_length_op2(feat->
op2,
134 }
else if (lwc_string_isequal(feat->
name,
135 str->
height, &match) == lwc_error_ok &&
137 if (!mq_match_feature_range_length_op1(feat->
op, &feat->
value,
138 media->
height, unit_ctx)) {
142 return mq_match_feature_range_length_op2(feat->
op2,
145 }
else if (lwc_string_isequal(feat->
name,
148 if (mq_match_feature_eq_ident_op1(feat->
op, &feat->
value,
170static inline bool mq_match_condition(
176 bool matched = !cond->
op;
178 for (uint32_t i = 0; i < cond->
nparts; i++) {
180 if (cond->
parts[i]->
type == CSS_MQ_FEATURE) {
181 part_matched = mq_match_feature(
183 unit_ctx, media, str);
186 part_matched = mq_match_condition(
188 unit_ctx, media, str);
193 matched |= part_matched;
199 matched &= part_matched;
206 return matched != cond->
negate;
220static inline bool mq__list_match(
226 for (; m != NULL; m = m->
next) {
229 if (m->
cond == NULL ||
230 mq_match_condition(m->
cond,
231 unit_ctx, media, str)) {
249static inline bool mq_rule_good_for_media(
258 while (ancestor != NULL) {
262 applies = mq__list_match(m->
media,
263 unit_ctx, media, str);
264 if (applies ==
false) {
270 ancestor = ancestor->
parent;
@ UNIT_PX
Definition bytecode.h:51
int32_t css_fixed
Definition fpmath.h:23
css_mq_feature_op
Definition mq.h:38
@ CSS_MQ_FEATURE_OP_EQ
Definition mq.h:44
@ CSS_MQ_FEATURE_OP_GTE
Definition mq.h:45
@ CSS_MQ_FEATURE_OP_BOOL
Definition mq.h:39
@ CSS_MQ_FEATURE_OP_UNUSED
Definition mq.h:40
@ CSS_MQ_FEATURE_OP_LT
Definition mq.h:42
@ CSS_MQ_FEATURE_OP_GT
Definition mq.h:46
@ CSS_MQ_FEATURE_OP_LTE
Definition mq.h:43
@ CSS_RULE_MEDIA
Definition stylesheet.h:103
@ CSS_RULE_PARENT_STYLESHEET
Definition stylesheet.h:109
css_mq_feature * feat
Definition mq.h:73
union css_mq_cond_or_feature::@15 data
css_mq_cond * cond
Definition mq.h:72
enum css_mq_cond_or_feature::@14 type
css_mq_cond_or_feature ** parts
Definition mq.h:63
uint32_t op
Definition mq.h:61
uint32_t negate
Definition mq.h:60
uint32_t nparts
Definition mq.h:62
css_mq_value value2
Definition mq.h:54
css_mq_feature_op op2
Definition mq.h:52
css_mq_feature_op op
Definition mq.h:51
lwc_string * name
Definition mq.h:50
css_mq_value value
Definition mq.h:53
uint64_t type
Definition mq.h:81
struct css_mq_query * next
Definition mq.h:78
css_mq_cond * cond
Definition mq.h:83
uint32_t negate_type
Definition mq.h:80
uint32_t unit
Definition mq.h:25
lwc_string * ident
Definition mq.h:27
struct css_mq_value::@12::@13 dim
enum css_mq_value::@11 type
css_fixed len
Definition mq.h:24
union css_mq_value::@12 data
Definition stylesheet.h:113
uint8_t ptype
Definition stylesheet.h:123
void * parent
Definition stylesheet.h:114
uint8_t type
Definition stylesheet.h:122
lwc_string * height
Definition strings.h:44
lwc_string * width
Definition strings.h:43
lwc_string * prefers_color_scheme
Definition strings.h:45
#define assert(expr)
Definition testutils.h:32
css_fixed css_unit_len2px_mq(const css_unit_ctx *ctx, const css_fixed length, const css_unit unit)
Definition unit.c:281