summaryrefslogtreecommitdiff
path: root/src/select
diff options
context:
space:
mode:
Diffstat (limited to 'src/select')
-rw-r--r--src/select/hash.c47
-rw-r--r--src/select/mq.h43
-rw-r--r--src/select/select.c26
3 files changed, 54 insertions, 62 deletions
diff --git a/src/select/hash.c b/src/select/hash.c
index dce4065..92457d8 100644
--- a/src/select/hash.c
+++ b/src/select/hash.c
@@ -10,6 +10,7 @@
#include "stylesheet.h"
#include "select/hash.h"
+#include "select/mq.h"
#include "utils/utils.h"
#undef PRINT_CHAIN_BLOOM_DETAILS
@@ -106,36 +107,6 @@ static inline bool _chain_good_for_element_name(const css_selector *selector,
return true;
}
-/**
- * Test whether the rule applies for current media.
- *
- * \param rule Rule to test
- * \meaid media Current media type(s)
- * \return true iff chain's rule applies for media
- */
-static inline bool _rule_good_for_media(const css_rule *rule, uint64_t media)
-{
- bool applies = true;
- const css_rule *ancestor = rule;
-
- while (ancestor != NULL) {
- const css_rule_media *m = (const css_rule_media *) ancestor;
-
- if (ancestor->type == CSS_RULE_MEDIA &&
- (m->media & media) == 0) {
- applies = false;
- break;
- }
-
- if (ancestor->ptype != CSS_RULE_PARENT_STYLESHEET)
- ancestor = ancestor->parent;
- else
- ancestor = NULL;
- }
-
- return applies;
-}
-
/**
* Create a hash
@@ -396,7 +367,7 @@ css_error css__selector_hash_find(css_selector_hash *hash,
if (css_bloom_in_bloom(
head->sel_chain_bloom,
req->node_bloom) &&
- _rule_good_for_media(head->sel->rule,
+ mq_rule_good_for_media(head->sel->rule,
req->media)) {
/* Found a match */
break;
@@ -474,7 +445,7 @@ css_error css__selector_hash_find_by_class(css_selector_hash *hash,
head->sel,
&(req->qname),
req->uni) &&
- _rule_good_for_media(
+ mq_rule_good_for_media(
head->sel->rule,
req->media)) {
/* Found a match */
@@ -554,7 +525,7 @@ css_error css__selector_hash_find_by_id(css_selector_hash *hash,
head->sel,
&req->qname,
req->uni) &&
- _rule_good_for_media(
+ mq_rule_good_for_media(
head->sel->rule,
req->media)) {
/* Found a match */
@@ -605,7 +576,7 @@ css_error css__selector_hash_find_universal(css_selector_hash *hash,
css_bloom_in_bloom(
head->sel_chain_bloom,
req->node_bloom) &&
- _rule_good_for_media(head->sel->rule,
+ mq_rule_good_for_media(head->sel->rule,
req->media)) {
/* Found a match */
break;
@@ -949,7 +920,7 @@ css_error _iterate_elements(
if (css_bloom_in_bloom(
head->sel_chain_bloom,
req->node_bloom) &&
- _rule_good_for_media(head->sel->rule,
+ mq_rule_good_for_media(head->sel->rule,
req->media)) {
/* Found a match */
break;
@@ -1008,7 +979,7 @@ css_error _iterate_classes(
head->sel,
&(req->qname),
req->uni) &&
- _rule_good_for_media(
+ mq_rule_good_for_media(
head->sel->rule,
req->media)) {
/* Found a match */
@@ -1069,7 +1040,7 @@ css_error _iterate_ids(
head->sel,
&req->qname,
req->uni) &&
- _rule_good_for_media(
+ mq_rule_good_for_media(
head->sel->rule,
req->media)) {
/* Found a match */
@@ -1113,7 +1084,7 @@ css_error _iterate_universal(
css_bloom_in_bloom(
head->sel_chain_bloom,
req->node_bloom) &&
- _rule_good_for_media(head->sel->rule,
+ mq_rule_good_for_media(head->sel->rule,
req->media)) {
/* Found a match */
break;
diff --git a/src/select/mq.h b/src/select/mq.h
new file mode 100644
index 0000000..a0a9f6d
--- /dev/null
+++ b/src/select/mq.h
@@ -0,0 +1,43 @@
+/*
+ * This file is part of LibCSS
+ * Licensed under the MIT License,
+ * http://www.opensource.org/licenses/mit-license.php
+ *
+ * Copyright 2018 Michael Drake <tlsa@netsurf-browser.org>
+ */
+
+#ifndef css_select_mq_h_
+#define css_select_mq_h_
+
+/**
+ * Test whether the rule applies for current media.
+ *
+ * \param rule Rule to test
+ * \meaid media Current media type(s)
+ * \return true iff chain's rule applies for media
+ */
+static inline bool mq_rule_good_for_media(const css_rule *rule, uint64_t media)
+{
+ bool applies = true;
+ const css_rule *ancestor = rule;
+
+ while (ancestor != NULL) {
+ const css_rule_media *m = (const css_rule_media *) ancestor;
+
+ if (ancestor->type == CSS_RULE_MEDIA &&
+ (m->media & media) == 0) {
+ applies = false;
+ break;
+ }
+
+ if (ancestor->ptype != CSS_RULE_PARENT_STYLESHEET) {
+ ancestor = ancestor->parent;
+ } else {
+ ancestor = NULL;
+ }
+ }
+
+ return applies;
+}
+
+#endif
diff --git a/src/select/select.c b/src/select/select.c
index 6b5225a..644369a 100644
--- a/src/select/select.c
+++ b/src/select/select.c
@@ -19,6 +19,7 @@
#include "select/computed.h"
#include "select/dispatch.h"
#include "select/hash.h"
+#include "select/mq.h"
#include "select/propset.h"
#include "select/font_face.h"
#include "select/select.h"
@@ -1885,34 +1886,11 @@ css_error select_from_sheet(css_select_ctx *ctx, const css_stylesheet *sheet,
return CSS_OK;
}
-static inline bool _rule_applies_to_media(const css_rule *rule, uint64_t media)
-{
- bool applies = true;
- const css_rule *ancestor = rule;
-
- while (ancestor != NULL) {
- const css_rule_media *m = (const css_rule_media *) ancestor;
-
- if (ancestor->type == CSS_RULE_MEDIA &&
- (m->media & media) == 0) {
- applies = false;
- break;
- }
-
- if (ancestor->ptype != CSS_RULE_PARENT_STYLESHEET)
- ancestor = ancestor->parent;
- else
- ancestor = NULL;
- }
-
- return applies;
-}
-
static css_error _select_font_face_from_rule(
const css_rule_font_face *rule, css_origin origin,
css_select_font_faces_state *state)
{
- if (_rule_applies_to_media((const css_rule *) rule, state->media)) {
+ if (mq_rule_good_for_media((const css_rule *) rule, state->media)) {
bool correct_family = false;
if (lwc_string_isequal(