mirror of
https://github.com/rkd77/elinks.git
synced 2025-01-03 14:57:44 -05:00
[ecmascript] walk_tree_query moved to ecmascript-c.c
This commit is contained in:
parent
3128c22c2e
commit
4a6b920586
@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
#include "dialogs/status.h"
|
#include "dialogs/status.h"
|
||||||
#include "document/document.h"
|
#include "document/document.h"
|
||||||
|
#include "document/libdom/doc.h"
|
||||||
#include "document/libdom/mapa.h"
|
#include "document/libdom/mapa.h"
|
||||||
#include "document/view.h"
|
#include "document/view.h"
|
||||||
#include "ecmascript/ecmascript.h"
|
#include "ecmascript/ecmascript.h"
|
||||||
@ -481,3 +482,59 @@ void ecmascript_moved_form_state(struct form_state *fs)
|
|||||||
spidermonkey_moved_form_state(fs);
|
spidermonkey_moved_form_state(fs);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void *
|
||||||
|
walk_tree_query(dom_node *node, char *selector, int depth)
|
||||||
|
{
|
||||||
|
dom_exception exc;
|
||||||
|
dom_node *child;
|
||||||
|
void *res = NULL;
|
||||||
|
dom_node_type typ;
|
||||||
|
|
||||||
|
/* Only interested in element nodes */
|
||||||
|
exc = dom_node_get_node_type(node, &typ);
|
||||||
|
if (typ != DOM_ELEMENT_NODE) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (res = el_match_selector(selector, node)) {
|
||||||
|
/* There was an error; return */
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
/* Get the node's first child */
|
||||||
|
exc = dom_node_get_first_child(node, &child);
|
||||||
|
|
||||||
|
if (exc != DOM_NO_ERR) {
|
||||||
|
fprintf(stderr, "Exception raised for node_get_first_child\n");
|
||||||
|
return NULL;
|
||||||
|
} else if (child != NULL) {
|
||||||
|
/* node has children; decend to children's depth */
|
||||||
|
depth++;
|
||||||
|
|
||||||
|
/* Loop though all node's children */
|
||||||
|
do {
|
||||||
|
dom_node *next_child;
|
||||||
|
|
||||||
|
/* Visit node's descendents */
|
||||||
|
res = walk_tree_query(child, selector, depth);
|
||||||
|
/* There was an error; return */
|
||||||
|
if (res) {
|
||||||
|
dom_node_unref(child);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Go to next sibling */
|
||||||
|
exc = dom_node_get_next_sibling(child, &next_child);
|
||||||
|
if (exc != DOM_NO_ERR) {
|
||||||
|
fprintf(stderr, "Exception raised for "
|
||||||
|
"node_get_next_sibling\n");
|
||||||
|
dom_node_unref(child);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
dom_node_unref(child);
|
||||||
|
child = next_child;
|
||||||
|
} while (child != NULL); /* No more children */
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
@ -40,6 +40,8 @@ void ecmascript_detach_form_view(struct form_view *fv);
|
|||||||
void ecmascript_detach_form_state(struct form_state *fs);
|
void ecmascript_detach_form_state(struct form_state *fs);
|
||||||
void ecmascript_moved_form_state(struct form_state *fs);
|
void ecmascript_moved_form_state(struct form_state *fs);
|
||||||
|
|
||||||
|
void *walk_tree_query(dom_node *node, char *selector, int depth);
|
||||||
|
|
||||||
extern struct module ecmascript_module;
|
extern struct module ecmascript_module;
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
#include "document/view.h"
|
#include "document/view.h"
|
||||||
#include "ecmascript/css2xpath.h"
|
#include "ecmascript/css2xpath.h"
|
||||||
#include "ecmascript/ecmascript.h"
|
#include "ecmascript/ecmascript.h"
|
||||||
|
#include "ecmascript/ecmascript-c.h"
|
||||||
#include "ecmascript/libdom/parse.h"
|
#include "ecmascript/libdom/parse.h"
|
||||||
#include "ecmascript/spidermonkey/collection.h"
|
#include "ecmascript/spidermonkey/collection.h"
|
||||||
#include "ecmascript/spidermonkey/form.h"
|
#include "ecmascript/spidermonkey/form.h"
|
||||||
@ -1819,62 +1820,6 @@ document_getElementsByTagName(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *
|
|
||||||
walk_tree_query(dom_node *node, char *selector, int depth)
|
|
||||||
{
|
|
||||||
dom_exception exc;
|
|
||||||
dom_node *child;
|
|
||||||
void *res = NULL;
|
|
||||||
dom_node_type typ;
|
|
||||||
|
|
||||||
/* Only interested in element nodes */
|
|
||||||
exc = dom_node_get_node_type(node, &typ);
|
|
||||||
if (typ != DOM_ELEMENT_NODE) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (res = el_match_selector(selector, node)) {
|
|
||||||
/* There was an error; return */
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
/* Get the node's first child */
|
|
||||||
exc = dom_node_get_first_child(node, &child);
|
|
||||||
|
|
||||||
if (exc != DOM_NO_ERR) {
|
|
||||||
fprintf(stderr, "Exception raised for node_get_first_child\n");
|
|
||||||
return NULL;
|
|
||||||
} else if (child != NULL) {
|
|
||||||
/* node has children; decend to children's depth */
|
|
||||||
depth++;
|
|
||||||
|
|
||||||
/* Loop though all node's children */
|
|
||||||
do {
|
|
||||||
dom_node *next_child;
|
|
||||||
|
|
||||||
/* Visit node's descendents */
|
|
||||||
res = walk_tree_query(child, selector, depth);
|
|
||||||
/* There was an error; return */
|
|
||||||
if (res) {
|
|
||||||
dom_node_unref(child);
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Go to next sibling */
|
|
||||||
exc = dom_node_get_next_sibling(child, &next_child);
|
|
||||||
if (exc != DOM_NO_ERR) {
|
|
||||||
fprintf(stderr, "Exception raised for "
|
|
||||||
"node_get_next_sibling\n");
|
|
||||||
dom_node_unref(child);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
dom_node_unref(child);
|
|
||||||
child = next_child;
|
|
||||||
} while (child != NULL); /* No more children */
|
|
||||||
}
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
document_querySelector(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
document_querySelector(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user