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,27 +711,13 @@ match_attribute_selectors(struct dom_select_node *base, struct dom_node *node)
#define get_dom_select_data(stack) ((stack)->current->data)
/* 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)
static int
match_element_selector(struct dom_select_node *selector, struct dom_node *node)
{
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. */
if (!has_element_match(selector, DOM_SELECT_ELEMENT_UNIVERSAL)
&& dom_node_casecmp(&selector->node, node))
continue;
return 0;
switch (get_element_relation(selector)) {
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;
}
/* 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)
&& node->parent)
continue;
return 0;
if (has_element_match(selector, DOM_SELECT_ELEMENT_EMPTY)
&& node->data.element.map->size > 0)
continue;
return 0;
if (has_element_match(selector, DOM_SELECT_ELEMENT_NTH_CHILD)) {
/* FIXME */
continue;
return 0;
}
if (has_element_match(selector, DOM_SELECT_ELEMENT_NTH_TYPE)) {
/* FIXME */
continue;
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. */
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;
WDBG("Matched element: %.*s.", node->string.length, node->string.string);