From 12d34fd1332a89aada3c4ab76cd96d7ea9c7dde1 Mon Sep 17 00:00:00 2001 From: Jonas Fonseca Date: Fri, 23 Dec 2005 00:51:57 +0100 Subject: [PATCH] Factor out code to new match_element_selector() 'Twill make it easier to do the logic. --- src/document/dom/select.c | 103 +++++++++++++++++++++----------------- 1 file changed, 56 insertions(+), 47 deletions(-) diff --git a/src/document/dom/select.c b/src/document/dom/select.c index 9fcf81be..f7e03869 100644 --- a/src/document/dom/select.c +++ b/src/document/dom/select.c @@ -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) +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. */ static void 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 * 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; - - 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)) + if (!match_element_selector(selector, node)) continue; WDBG("Matched element: %.*s.", node->string.length, node->string.string);