예제 #1
0
/**
 * Get the node in the collection according name
 *
 * \param col   The collection
 * \param name  The name of target node
 * \param node  The returned node object
 * \return DOM_NO_ERR on success.
 */
dom_exception dom_html_collection_named_item(dom_html_collection *col,
		dom_string *name, struct dom_node **node)
{
	struct dom_node_internal *n = col->root;
	dom_exception err;
        
        while (n != NULL) {
		if (n->type == DOM_ELEMENT_NODE &&
		    col->ic(n, col->ctx) == true) {
			dom_string *id = NULL;

			err = _dom_element_get_id((struct dom_element *) n,
					&id);
			if (err != DOM_NO_ERR) {
				return err;
			}

			if (id != NULL && dom_string_isequal(name, id)) {
				*node = (struct dom_node *) n;
				dom_node_ref(n);
				dom_string_unref(id);

				return DOM_NO_ERR;
			}

			if (id != NULL)
				dom_string_unref(id);
		}

		/* Depth first iterating */
		if (n->first_child != NULL) {
			n = n->first_child;
		} else if (n->next != NULL) {
			n = n->next;
		} else {
			/* No children and siblings */
			struct dom_node_internal *parent = n->parent;

			while (parent != col->root &&
					n == parent->last_child) {
				n = parent;
				parent = parent->parent;
			}
			
			if (parent == col->root)
				n = NULL;
			else
				n = n->next;
		}
	}

	/* Not found the target node */
	*node = NULL;

	return DOM_NO_ERR;
}
예제 #2
0
파일: select.c 프로젝트: kyllikki/netsurf
/* Handler for libcss_node_data, stored as libdom node user data */
static void nscss_dom_user_data_handler(dom_node_operation operation,
		dom_string *key, void *data, struct dom_node *src,
		struct dom_node *dst)
{
	css_error error;

	if (dom_string_isequal(corestring_dom___ns_key_libcss_node_data,
			key) == false || data == NULL) {
		return;
	}

	switch (operation) {
	case DOM_NODE_CLONED:
		error = css_libcss_node_data_handler(&selection_handler,
				CSS_NODE_CLONED,
				NULL, src, dst, data);
		if (error != CSS_OK)
			NSLOG(netsurf, INFO,
			      "Failed to clone libcss_node_data.");
		break;

	case DOM_NODE_RENAMED:
		error = css_libcss_node_data_handler(&selection_handler,
				CSS_NODE_MODIFIED,
				NULL, src, NULL, data);
		if (error != CSS_OK)
			NSLOG(netsurf, INFO,
			      "Failed to update libcss_node_data.");
		break;

	case DOM_NODE_IMPORTED:
	case DOM_NODE_ADOPTED:
	case DOM_NODE_DELETED:
		error = css_libcss_node_data_handler(&selection_handler,
				CSS_NODE_DELETED,
				NULL, src, NULL, data);
		if (error != CSS_OK)
			NSLOG(netsurf, INFO,
			      "Failed to delete libcss_node_data.");
		break;

	default:
		NSLOG(netsurf, INFO, "User data operation not handled.");
		assert(0);
	}
}
예제 #3
0
/**
 * Helper for file gadgets to store their filename.
 *
 * Stores the filename unencoded on the dom node associated with the
 * gadget.
 *
 * \todo Get rid of this crap eventually
 *
 * \param operation DOM operation
 * \param key DOM node key being considerd
 * \param _data The data assocated with the key
 * \param src The source DOM node.
 * \param dst The destination DOM node.
 */
static void
html__image_coords_dom_user_data_handler(dom_node_operation operation,
        dom_string *key,
        void *_data,
        struct dom_node *src,
        struct dom_node *dst)
{
    struct image_input_coords *oldcoords, *coords = _data, *newcoords;

    if (!dom_string_isequal(corestring_dom___ns_key_image_coords_node_data,
                            key) || coords == NULL) {
        return;
    }

    switch (operation) {
    case DOM_NODE_CLONED:
        newcoords = calloc(1, sizeof(*newcoords));
        if (newcoords != NULL) {
            *newcoords = *coords;
            if (dom_node_set_user_data(dst,
                                       corestring_dom___ns_key_image_coords_node_data,
                                       newcoords,
                                       html__image_coords_dom_user_data_handler,
                                       &oldcoords) == DOM_NO_ERR) {
                free(oldcoords);
            }
        }
        break;

    case DOM_NODE_DELETED:
        free(coords);
        break;

    case DOM_NODE_RENAMED:
    case DOM_NODE_IMPORTED:
    case DOM_NODE_ADOPTED:
        break;

    default:
        LOG("User data operation not handled.");
        assert(0);
    }
}