1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-11-04 08:17:17 -05:00

Factor out code to new match_element_selector()

'Twill make it easier to do the logic.
This commit is contained in:
Jonas Fonseca 2005-12-23 00:51:57 +01:00 committed by Jonas Fonseca
parent 07fc481607
commit 12d34fd133

View File

@ -711,6 +711,61 @@ 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)
static int
match_element_selector(struct dom_select_node *selector, struct dom_node *node)
{
/* Match the node. */
if (!has_element_match(selector, DOM_SELECT_ELEMENT_UNIVERSAL)
&& dom_node_casecmp(&selector->node, node))
return 0;
switch (get_element_relation(selector)) {
case DOM_SELECT_RELATION_DIRECT_CHILD: /* E > F */
/* node->parent */
/* Check all states to see if node->parent is there
* and for the right reasons. */
break;
case DOM_SELECT_RELATION_DIRECT_ADJACENT: /* E + F */
/* Get preceding node to see if it is on the stack. */
break;
case DOM_SELECT_RELATION_INDIRECT_ADJACENT: /* E ~ F */
/* Check all states with same depth? */
break;
case DOM_SELECT_RELATION_DESCENDANT: /* E F */
default:
break;
}
/* Root node are rooted at the don't have parent nodes. */
if (has_element_match(selector, DOM_SELECT_ELEMENT_ROOT)
&& node->parent)
return 0;
if (has_element_match(selector, DOM_SELECT_ELEMENT_EMPTY)
&& node->data.element.map->size > 0)
return 0;
if (has_element_match(selector, DOM_SELECT_ELEMENT_NTH_CHILD)) {
/* FIXME */
return 0;
}
if (has_element_match(selector, DOM_SELECT_ELEMENT_NTH_TYPE)) {
/* FIXME */
return 0;
}
/* Check attribute selectors. */
if (selector->node.data.element.map
&& !match_attribute_selectors(selector, node))
return 0;
return 1;
}
/* Matches an element node being visited against the current selector stack. */ /* Matches an element node being visited against the current selector stack. */
static void static void
dom_select_push_element(struct dom_stack *stack, struct dom_node *node, void *data) dom_select_push_element(struct dom_stack *stack, struct dom_node *node, void *data)
@ -728,53 +783,7 @@ dom_select_push_element(struct dom_stack *stack, struct dom_node *node, void *da
* on the select_data->stack, cache what select nodes was * on the select_data->stack, cache what select nodes was
* matches so that it is only checked once. */ * matches so that it is only checked once. */
/* Match the node. */ if (!match_element_selector(selector, node))
if (!has_element_match(selector, DOM_SELECT_ELEMENT_UNIVERSAL)
&& dom_node_casecmp(&selector->node, node))
continue;
switch (get_element_relation(selector)) {
case DOM_SELECT_RELATION_DIRECT_CHILD: /* E > F */
/* node->parent */
/* Check all states to see if node->parent is there
* and for the right reasons. */
break;
case DOM_SELECT_RELATION_DIRECT_ADJACENT: /* E + F */
/* Get preceding node to see if it is on the stack. */
break;
case DOM_SELECT_RELATION_INDIRECT_ADJACENT: /* E ~ F */
/* Check all states with same depth? */
break;
case DOM_SELECT_RELATION_DESCENDANT: /* E F */
default:
break;
}
/* Roots don't have parent nodes. */
if (has_element_match(selector, DOM_SELECT_ELEMENT_ROOT)
&& node->parent)
continue;
if (has_element_match(selector, DOM_SELECT_ELEMENT_EMPTY)
&& node->data.element.map->size > 0)
continue;
if (has_element_match(selector, DOM_SELECT_ELEMENT_NTH_CHILD)) {
/* FIXME */
continue;
}
if (has_element_match(selector, DOM_SELECT_ELEMENT_NTH_TYPE)) {
/* FIXME */
continue;
}
/* Check attribute selectors. */
if (selector->node.data.element.map
&& !match_attribute_selectors(selector, node))
continue; continue;
WDBG("Matched element: %.*s.", node->string.length, node->string.string); WDBG("Matched element: %.*s.", node->string.length, node->string.string);