mirror of
https://github.com/rkd77/elinks.git
synced 2025-06-30 22:19:29 -04:00
Factor out code to new match_element_selector()
'Twill make it easier to do the logic.
This commit is contained in:
parent
07fc481607
commit
12d34fd133
@ -711,27 +711,13 @@ match_attribute_selectors(struct dom_select_node *base, struct dom_node *node)
|
|||||||
|
|
||||||
#define get_dom_select_data(stack) ((stack)->current->data)
|
#define get_dom_select_data(stack) ((stack)->current->data)
|
||||||
|
|
||||||
/* Matches an element node being visited against the current selector stack. */
|
static int
|
||||||
static void
|
match_element_selector(struct dom_select_node *selector, struct dom_node *node)
|
||||||
dom_select_push_element(struct dom_stack *stack, struct dom_node *node, void *data)
|
|
||||||
{
|
{
|
||||||
struct dom_select_data *select_data = get_dom_select_data(stack);
|
|
||||||
struct dom_stack_state *state;
|
|
||||||
int pos;
|
|
||||||
|
|
||||||
WDBG("Push element %.*s.", node->string.length, node->string.string);
|
|
||||||
|
|
||||||
foreach_dom_stack_state(&select_data->stack, state, pos) {
|
|
||||||
struct dom_select_node *selector = (void *) state->node;
|
|
||||||
|
|
||||||
/* FIXME: Since the same dom_select_node can be multiple times
|
|
||||||
* on the select_data->stack, cache what select nodes was
|
|
||||||
* matches so that it is only checked once. */
|
|
||||||
|
|
||||||
/* Match the node. */
|
/* Match the node. */
|
||||||
if (!has_element_match(selector, DOM_SELECT_ELEMENT_UNIVERSAL)
|
if (!has_element_match(selector, DOM_SELECT_ELEMENT_UNIVERSAL)
|
||||||
&& dom_node_casecmp(&selector->node, node))
|
&& dom_node_casecmp(&selector->node, node))
|
||||||
continue;
|
return 0;
|
||||||
|
|
||||||
switch (get_element_relation(selector)) {
|
switch (get_element_relation(selector)) {
|
||||||
case DOM_SELECT_RELATION_DIRECT_CHILD: /* E > F */
|
case DOM_SELECT_RELATION_DIRECT_CHILD: /* E > F */
|
||||||
@ -753,28 +739,51 @@ dom_select_push_element(struct dom_stack *stack, struct dom_node *node, void *da
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Roots don't have parent nodes. */
|
/* Root node are rooted at the don't have parent nodes. */
|
||||||
if (has_element_match(selector, DOM_SELECT_ELEMENT_ROOT)
|
if (has_element_match(selector, DOM_SELECT_ELEMENT_ROOT)
|
||||||
&& node->parent)
|
&& node->parent)
|
||||||
continue;
|
return 0;
|
||||||
|
|
||||||
if (has_element_match(selector, DOM_SELECT_ELEMENT_EMPTY)
|
if (has_element_match(selector, DOM_SELECT_ELEMENT_EMPTY)
|
||||||
&& node->data.element.map->size > 0)
|
&& node->data.element.map->size > 0)
|
||||||
continue;
|
return 0;
|
||||||
|
|
||||||
if (has_element_match(selector, DOM_SELECT_ELEMENT_NTH_CHILD)) {
|
if (has_element_match(selector, DOM_SELECT_ELEMENT_NTH_CHILD)) {
|
||||||
/* FIXME */
|
/* FIXME */
|
||||||
continue;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (has_element_match(selector, DOM_SELECT_ELEMENT_NTH_TYPE)) {
|
if (has_element_match(selector, DOM_SELECT_ELEMENT_NTH_TYPE)) {
|
||||||
/* FIXME */
|
/* FIXME */
|
||||||
continue;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check attribute selectors. */
|
/* Check attribute selectors. */
|
||||||
if (selector->node.data.element.map
|
if (selector->node.data.element.map
|
||||||
&& !match_attribute_selectors(selector, node))
|
&& !match_attribute_selectors(selector, node))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Matches an element node being visited against the current selector stack. */
|
||||||
|
static void
|
||||||
|
dom_select_push_element(struct dom_stack *stack, struct dom_node *node, void *data)
|
||||||
|
{
|
||||||
|
struct dom_select_data *select_data = get_dom_select_data(stack);
|
||||||
|
struct dom_stack_state *state;
|
||||||
|
int pos;
|
||||||
|
|
||||||
|
WDBG("Push element %.*s.", node->string.length, node->string.string);
|
||||||
|
|
||||||
|
foreach_dom_stack_state(&select_data->stack, state, pos) {
|
||||||
|
struct dom_select_node *selector = (void *) state->node;
|
||||||
|
|
||||||
|
/* FIXME: Since the same dom_select_node can be multiple times
|
||||||
|
* on the select_data->stack, cache what select nodes was
|
||||||
|
* matches so that it is only checked once. */
|
||||||
|
|
||||||
|
if (!match_element_selector(selector, node))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
WDBG("Matched element: %.*s.", node->string.length, node->string.string);
|
WDBG("Matched element: %.*s.", node->string.length, node->string.string);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user