From 43fb761f450e463dbce7431d20606cf795daf04c Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Wed, 7 Nov 2012 18:47:35 +0000 Subject: add document.body, head and documentElement getters add a dom utility file and use it --- utils/domutils.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ utils/domutils.h | 24 +++++++++++++++++++++ 2 files changed, 90 insertions(+) create mode 100644 utils/domutils.c create mode 100644 utils/domutils.h (limited to 'utils') diff --git a/utils/domutils.c b/utils/domutils.c new file mode 100644 index 000000000..4d32a67d8 --- /dev/null +++ b/utils/domutils.c @@ -0,0 +1,66 @@ +/* + * Copyright 2012 Vincent Sanders + * + * This file is part of NetSurf, http://www.netsurf-browser.org/ + * + * NetSurf is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * NetSurf is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include + +#include "utils/config.h" +#include "utils/log.h" + +#include "domutils.h" + +/* search children of a node for first named element */ +dom_node *find_first_named_dom_element(dom_node *parent, lwc_string *element_name) +{ + dom_node *element; + dom_exception exc; + dom_string *node_name = NULL; + dom_node_type node_type; + dom_node *next_node; + + exc = dom_node_get_first_child(parent, &element); + if ((exc != DOM_NO_ERR) || (element == NULL)) { + return NULL; + } + + /* find first node thats a element */ + do { + exc = dom_node_get_node_type(element, &node_type); + + if ((exc != DOM_NO_ERR) || (node_type == DOM_ELEMENT_NODE)) { + exc = dom_node_get_node_name(element, &node_name); + if ((exc == DOM_NO_ERR) || (node_name != NULL)) { + if (dom_string_caseless_lwc_isequal(node_name, + element_name)) { + dom_string_unref(node_name); + break; + } + dom_string_unref(node_name); + } + } + + exc = dom_node_get_next_sibling(element, &next_node); + dom_node_unref(element); + if (exc == DOM_NO_ERR) { + element = next_node; + } else { + element = NULL; + } + } while (element != NULL); + + return element; +} diff --git a/utils/domutils.h b/utils/domutils.h new file mode 100644 index 000000000..ecdf2bc4a --- /dev/null +++ b/utils/domutils.h @@ -0,0 +1,24 @@ +/* + * Copyright 2012 Vincent Sanders + * + * This file is part of NetSurf, http://www.netsurf-browser.org/ + * + * NetSurf is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * NetSurf is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef _NETSURF_UTILS_DOMUTILS_H_ +#define _NETSURF_UTILS_DOMUTILS_H_ + +dom_node *find_first_named_dom_element(dom_node *parent, lwc_string *element_name); + +#endif -- cgit v1.2.3