libdom
|
#include <stdbool.h>
#include <libwapcaplet/libwapcaplet.h>
#include <dom/core/node.h>
#include <dom/functypes.h>
#include "events/event_target.h"
#include "events/mutation_event.h"
#include "utils/list.h"
Go to the source code of this file.
Classes | |
struct | dom_user_data |
struct | dom_node_protect_vtable |
struct | dom_node_internal |
Macros | |
#define | DOM_NODE_EVENT_TARGET_VTABLE |
#define | DOM_NODE_VTABLE |
#define | DOM_NODE_PROTECT_VTABLE |
#define | dom_node_destroy(n) |
#define | dom_node_copy(o, c) |
#define | dom_node_copy_internal(o, n) |
#define | dom_node_get_owner(n) |
#define | dom_node_set_owner(n, d) |
#define | dom_node_get_parent(n) |
#define | dom_node_set_parent(n, p) |
#define | dom_node_get_refcount(n) |
#define | dom_node_mark_pending(n) |
#define | dom_node_remove_pending(n) |
#define | dom_node_dispatch_node_change_event(doc, node, related, change, success) |
Typedefs | |
typedef struct dom_user_data | dom_user_data |
typedef struct dom_node_protect_vtable | dom_node_protect_vtable |
#define dom_node_copy | ( | o, | |
c ) |
#define dom_node_copy_internal | ( | o, | |
n ) |
#define dom_node_destroy | ( | n | ) |
#define dom_node_dispatch_node_change_event | ( | doc, | |
node, | |||
related, | |||
change, | |||
success ) |
#define DOM_NODE_EVENT_TARGET_VTABLE |
#define dom_node_get_owner | ( | n | ) |
#define dom_node_get_parent | ( | n | ) |
#define dom_node_get_refcount | ( | n | ) |
#define dom_node_mark_pending | ( | n | ) |
#define DOM_NODE_PROTECT_VTABLE |
#define dom_node_remove_pending | ( | n | ) |
#define dom_node_set_owner | ( | n, | |
d ) |
#define dom_node_set_parent | ( | n, | |
p ) |
#define DOM_NODE_VTABLE |
typedef struct dom_node_protect_vtable dom_node_protect_vtable |
The internally used virtual function table.
typedef struct dom_user_data dom_user_data |
dom_exception _dom_merge_adjacent_text | ( | dom_node_internal * | p, |
dom_node_internal * | n ) |
Merge two adjacent text nodes into one text node.
p | The first text node |
n | The second text node |
dom_exception _dom_node_add_event_listener | ( | dom_event_target * | et, |
dom_string * | type, | ||
struct dom_event_listener * | listener, | ||
bool | capture ) |
dom_exception _dom_node_add_event_listener_ns | ( | dom_event_target * | et, |
dom_string * | namespace, | ||
dom_string * | type, | ||
struct dom_event_listener * | listener, | ||
bool | capture ) |
dom_exception _dom_node_append_child | ( | dom_node_internal * | node, |
dom_node_internal * | new_child, | ||
dom_node_internal ** | result ) |
Append a child to the end of a node's child list
node | Node to insert into |
new_child | Node to append |
result | Pointer to location to receive node being inserted |
If ::new_child is a DocumentFragment, all of its children are inserted. If ::new_child is already in the tree, it is first removed.
The returned node will have its reference count increased. It is the responsibility of the caller to unref the node once it has finished with it.
dom_exception _dom_node_clone_node | ( | dom_node_internal * | node, |
bool | deep, | ||
dom_node_internal ** | result ) |
Clone a DOM node
node | The node to clone |
deep | True to deep-clone the node's sub-tree |
result | Pointer to location to receive result |
The returned node will already be referenced.
The duplicate node will have no parent and no user data.
If ::node has registered user_data_handlers, then they will be called.
Cloning an Element copies all attributes & their values (including those generated by the XML processor to represent defaulted attributes). It does not copy any child nodes unless it is a deep copy (this includes text contained within the Element, as the text is contained in a child Text node).
Cloning an Attr directly, as opposed to cloning as part of an Element, returns a specified attribute. Cloning an Attr always clones its children, since they represent its value, no matter whether this is a deep clone or not.
Cloning an EntityReference automatically constructs its subtree if a corresponding Entity is available, no matter whether this is a deep clone or not.
Cloning any other type of node simply returns a copy.
Note that cloning an immutable subtree results in a mutable copy, but the children of an EntityReference clone are readonly. In addition, clones of unspecified Attr nodes are specified.
Note: we adopt a OO paradigm, this clone_node just provide a basic operation of clone. Special clones like Attr/EntitiReference stated above should provide their overload of this interface in their implementation file.
dom_exception _dom_node_compare_document_position | ( | dom_node_internal * | node, |
dom_node_internal * | other, | ||
uint16_t * | result ) |
Compare the positions of two nodes in a DOM tree
node | The reference node |
other | The node to compare |
result | Pointer to location to receive result |
The result is a bitfield of dom_document_position values.
We don't support this API now, so this function call should always return DOM_NOT_SUPPORTED_ERR.
dom_exception _dom_node_copy | ( | struct dom_node_internal * | old, |
struct dom_node_internal ** | copy ) |
dom_exception _dom_node_copy_internal | ( | dom_node_internal * | old, |
dom_node_internal * | new ) |
dom_node_internal * _dom_node_create | ( | void | ) |
void _dom_node_destroy | ( | struct dom_node_internal * | node | ) |
Destroy a DOM node
node | The node to destroy |
::node's parent link must be NULL and its reference count must be 0.
::node will be freed.
This function should only be called from dom_node_unref or type-specific destructors (for destroying child nodes). Anything else should not be attempting to destroy nodes – they should simply be unreferencing them (so destruction will occur at the appropriate time).
dom_exception _dom_node_dispatch_event | ( | dom_event_target * | et, |
struct dom_event * | evt, | ||
bool * | success ) |
Dispatch an event into the implementation's event model
et | The EventTarget object |
evt | The event object |
success | Indicates whether any of the listeners which handled the event called Event.preventDefault(). If Event.preventDefault() was called the returned value is false, else it is true. |
dom_exception _dom_node_dispatch_node_change_event | ( | dom_document * | doc, |
dom_node_internal * | node, | ||
dom_node_internal * | related, | ||
dom_mutation_type | change, | ||
bool * | success ) |
void _dom_node_finalise | ( | dom_node_internal * | node | ) |
Finalise a DOM node
node | The node to finalise |
The contents of ::node will be cleaned up. ::node will not be freed. All children of ::node should have been removed prior to finalisation.
dom_exception _dom_node_get_attributes | ( | dom_node_internal * | node, |
struct dom_namednodemap ** | result ) |
Retrieve a map of attributes associated with a DOM node
node | The node to retrieve the attributes of |
result | Pointer to location to receive attribute map |
The returned NamedNodeMap will be referenced. It is the responsibility of the caller to unref the map once it has finished with it.
If ::node is not an Element, then NULL will be returned.
dom_exception _dom_node_get_base | ( | dom_node_internal * | node, |
dom_string ** | result ) |
Retrieve the base URI of a DOM node
node | The node to retrieve the base URI of |
result | Pointer to location to receive base URI |
The returned string will have its reference count increased. It is the responsibility of the caller to unref the string once it has finished with it.
We don't support this API now, so this function call should always return DOM_NOT_SUPPORTED_ERR.
dom_exception _dom_node_get_child_nodes | ( | dom_node_internal * | node, |
struct dom_nodelist ** | result ) |
Retrieve a list of children of a DOM node
node | The node to retrieve the children of |
result | Pointer to location to receive child list |
The returned NodeList will be referenced. It is the responsibility of the caller to unref the list once it has finished with it.
dom_exception _dom_node_get_feature | ( | dom_node_internal * | node, |
dom_string * | feature, | ||
dom_string * | version, | ||
void ** | result ) |
Retrieve an object which implements the specialized APIs of the specified feature and version.
node | The node to query |
feature | The requested feature |
version | The version number of the feature |
result | Pointer to location to receive result |
dom_exception _dom_node_get_first_child | ( | dom_node_internal * | node, |
dom_node_internal ** | result ) |
Retrieve the first child of a DOM node
node | The node to retrieve the first child of |
result | Pointer to location to receive node's first child |
The returned node will have its reference count increased. It is the responsibility of the caller to unref the node once it has finished with it.
dom_exception _dom_node_get_last_child | ( | dom_node_internal * | node, |
dom_node_internal ** | result ) |
Retrieve the last child of a DOM node
node | The node to retrieve the last child of |
result | Pointer to location to receive node's last child |
The returned node will have its reference count increased. It is the responsibility of the caller to unref the node once it has finished with it.
dom_exception _dom_node_get_local_name | ( | dom_node_internal * | node, |
dom_string ** | result ) |
Retrieve the local part of a node's qualified name
node | The node to retrieve the local name of |
result | Pointer to location to receive local name |
The returned string will have its reference count increased. It is the responsibility of the caller to unref the string once it has finished with it.
dom_exception _dom_node_get_namespace | ( | dom_node_internal * | node, |
dom_string ** | result ) |
Retrieve the namespace of a DOM node
node | The node to retrieve the namespace of |
result | Pointer to location to receive node's namespace |
The returned string will have its reference count increased. It is the responsibility of the caller to unref the string once it has finished with it.
dom_exception _dom_node_get_next_sibling | ( | dom_node_internal * | node, |
dom_node_internal ** | result ) |
Retrieve the subsequent sibling of a DOM node
node | The node to retrieve the subsequent sibling of |
result | Pointer to location to receive node's subsequent sibling |
The returned node will have its reference count increased. It is the responsibility of the caller to unref the node once it has finished with it.
dom_exception _dom_node_get_node_name | ( | dom_node_internal * | node, |
dom_string ** | result ) |
Retrieve the name of a DOM node
node | The node to retrieve the name of |
result | Pointer to location to receive node name |
The returned string will have its reference count increased. It is the responsibility of the caller to unref the string once it has finished with it.
dom_exception _dom_node_get_node_type | ( | dom_node_internal * | node, |
dom_node_type * | result ) |
Retrieve the type of a DOM node
node | The node to retrieve the type of |
result | Pointer to location to receive node type |
dom_exception _dom_node_get_node_value | ( | dom_node_internal * | node, |
dom_string ** | result ) |
Retrieve the value of a DOM node
node | The node to retrieve the value of |
result | Pointer to location to receive node value |
The returned string will have its reference count increased. It is the responsibility of the caller to unref the string once it has finished with it.
DOM3Core states that this can raise DOMSTRING_SIZE_ERR. It will not in this implementation; dom_strings are unbounded.
dom_exception _dom_node_get_owner_document | ( | dom_node_internal * | node, |
struct dom_document ** | result ) |
Retrieve the owning document of a DOM node
node | The node to retrieve the owner of |
result | Pointer to location to receive node's owner |
The returned node will have its reference count increased. It is the responsibility of the caller to unref the node once it has finished with it.
dom_exception _dom_node_get_parent_node | ( | dom_node_internal * | node, |
dom_node_internal ** | result ) |
Retrieve the parent of a DOM node
node | The node to retrieve the parent of |
result | Pointer to location to receive node parent |
The returned node will have its reference count increased. It is the responsibility of the caller to unref the node once it has finished with it.
dom_exception _dom_node_get_prefix | ( | dom_node_internal * | node, |
dom_string ** | result ) |
Retrieve the prefix of a DOM node
node | The node to retrieve the prefix of |
result | Pointer to location to receive node's prefix |
The returned string will have its reference count increased. It is the responsibility of the caller to unref the string once it has finished with it.
dom_exception _dom_node_get_previous_sibling | ( | dom_node_internal * | node, |
dom_node_internal ** | result ) |
Retrieve the previous sibling of a DOM node
node | The node to retrieve the previous sibling of |
result | Pointer to location to receive node's previous sibling |
The returned node will have its reference count increased. It is the responsibility of the caller to unref the node once it has finished with it.
dom_exception _dom_node_get_text_content | ( | dom_node_internal * | node, |
dom_string ** | result ) |
Retrieve the text content of a DOM node
node | The node to retrieve the text content of |
result | Pointer to location to receive text content |
The returned string will have its reference count increased. It is the responsibility of the caller to unref the string once it has finished with it.
If there is no text content in the code, NULL will returned in result.
DOM3Core states that this can raise DOMSTRING_SIZE_ERR. It will not in this implementation; dom_strings are unbounded.
dom_exception _dom_node_get_user_data | ( | const dom_node_internal * | node, |
const dom_string * | key, | ||
void ** | result ) |
Retrieves the object associated to a key on this node
node | The node to retrieve object from |
key | The key to search for |
result | Pointer to location to receive result |
dom_exception _dom_node_has_attributes | ( | dom_node_internal * | node, |
bool * | result ) |
Determine if a node has any attributes
node | Node to inspect |
result | Pointer to location to receive result |
dom_exception _dom_node_has_child_nodes | ( | dom_node_internal * | node, |
bool * | result ) |
Determine if a node has any children
node | Node to inspect |
result | Pointer to location to receive result |
dom_exception _dom_node_initialise | ( | dom_node_internal * | node, |
struct dom_document * | doc, | ||
dom_node_type | type, | ||
dom_string * | name, | ||
dom_string * | value, | ||
dom_string * | namespace, | ||
dom_string * | prefix ) |
Initialise a DOM node
node | The node to initialise |
doc | The document which owns the node |
type | The node type required |
name | The node (local) name, or NULL |
value | The node value, or NULL |
namespace | Namespace URI to use for node, or NULL |
prefix | Namespace prefix to use for node, or NULL |
::name, ::value, ::namespace, and ::prefix will have their reference counts increased.
dom_exception _dom_node_insert_before | ( | dom_node_internal * | node, |
dom_node_internal * | new_child, | ||
dom_node_internal * | ref_child, | ||
dom_node_internal ** | result ) |
Insert a child into a node
node | Node to insert into |
new_child | Node to insert |
ref_child | Node to insert before, or NULL to insert as last child |
result | Pointer to location to receive node being inserted |
If ::new_child is a DocumentFragment, all of its children are inserted. If ::new_child is already in the tree, it is first removed.
Attempting to insert a node before itself is a NOP.
The returned node will have its reference count increased. It is the responsibility of the caller to unref the node once it has finished with it.
dom_exception _dom_node_is_default_namespace | ( | dom_node_internal * | node, |
dom_string * | namespace, | ||
bool * | result ) |
Determine if the specified namespace is the default namespace
node | The node to query |
namespace | The namespace URI to test |
result | Pointer to location to receive result |
dom_exception _dom_node_is_equal | ( | dom_node_internal * | node, |
dom_node_internal * | other, | ||
bool * | result ) |
Determine if two DOM nodes are equal
node | The node to compare |
other | The node to compare against |
result | Pointer to location to receive result |
Two nodes are equal iff:
Two DocumentType nodes are equal iff:
dom_exception _dom_node_is_same | ( | dom_node_internal * | node, |
dom_node_internal * | other, | ||
bool * | result ) |
Determine if two DOM nodes are the same
node | The node to compare |
other | The node to compare against |
result | Pointer to location to receive result |
This tests if the two nodes reference the same object.
dom_exception _dom_node_is_supported | ( | dom_node_internal * | node, |
dom_string * | feature, | ||
dom_string * | version, | ||
bool * | result ) |
Test whether the DOM implementation implements a specific feature and that feature is supported by the node.
node | The node to test |
feature | The name of the feature to test |
version | The version number of the feature to test |
result | Pointer to location to receive result |
dom_exception _dom_node_lookup_namespace | ( | dom_node_internal * | node, |
dom_string * | prefix, | ||
dom_string ** | result ) |
Lookup the namespace URI associated with the given prefix
node | The node to start namespace search from |
prefix | The prefix to look for, or NULL to find default. |
result | Pointer to location to receive result |
The returned string will have its reference count increased. It is the responsibility of the caller to unref the string once it has finished with it.
dom_exception _dom_node_lookup_prefix | ( | dom_node_internal * | node, |
dom_string * | namespace, | ||
dom_string ** | result ) |
Lookup the prefix associated with the given namespace URI
node | The node to start prefix search from |
namespace | The namespace URI |
result | Pointer to location to receive result |
The returned string will have its reference count increased. It is the responsibility of the caller to unref the string once it has finished with it.
void _dom_node_mark_pending | ( | dom_node_internal * | node | ) |
To add some node to the pending list, when a node is removed from its parent or an attribute is removed from its element
node | The Node instance |
dom_exception _dom_node_normalize | ( | dom_node_internal * | node | ) |
Normalize a DOM node
node | The node to normalize |
Puts all Text nodes in the full depth of the sub-tree beneath ::node, including Attr nodes into "normal" form, where only structure separates Text nodes.
bool _dom_node_readonly | ( | const dom_node_internal * | node | ) |
Determine if a node is read only
node | The node to consider |
dom_exception _dom_node_remove_child | ( | dom_node_internal * | node, |
dom_node_internal * | old_child, | ||
dom_node_internal ** | result ) |
Remove a child from a node
node | Node whose child to replace |
old_child | Child to remove |
result | Pointer to location to receive removed node |
The returned node will have its reference count increased. It is the responsibility of the caller to unref the node once it has finished with it.
dom_exception _dom_node_remove_event_listener | ( | dom_event_target * | et, |
dom_string * | type, | ||
struct dom_event_listener * | listener, | ||
bool | capture ) |
dom_exception _dom_node_remove_event_listener_ns | ( | dom_event_target * | et, |
dom_string * | namespace, | ||
dom_string * | type, | ||
struct dom_event_listener * | listener, | ||
bool | capture ) |
void _dom_node_remove_pending | ( | dom_node_internal * | node | ) |
To remove the node from the pending list, this may happen when a node is removed and then appended to another parent
node | The Node instance |
dom_exception _dom_node_replace_child | ( | dom_node_internal * | node, |
dom_node_internal * | new_child, | ||
dom_node_internal * | old_child, | ||
dom_node_internal ** | result ) |
Replace a node's child with a new one
node | Node whose child to replace |
new_child | Replacement node |
old_child | Child to replace |
result | Pointer to location to receive replaced node |
If ::new_child is a DocumentFragment, ::old_child is replaced by all of ::new_child's children. If ::new_child is already in the tree, it is first removed.
The returned node will have its reference count increased. It is the responsibility of the caller to unref the node once it has finished with it.
dom_exception _dom_node_set_node_value | ( | dom_node_internal * | node, |
dom_string * | value ) |
Set the value of a DOM node
node | Node to set the value of |
value | New value for node |
The new value will have its reference count increased, so the caller should unref it after the call (as the caller should have already claimed a reference on the string). The node's existing value will be unrefed.
dom_exception _dom_node_set_prefix | ( | dom_node_internal * | node, |
dom_string * | prefix ) |
Set the prefix of a DOM node
node | The node to set the prefix of |
prefix | Pointer to prefix string |
dom_exception _dom_node_set_text_content | ( | dom_node_internal * | node, |
dom_string * | content ) |
Set the text content of a DOM node
node | The node to set the text content of |
content | New text content for node |
Any child nodes ::node may have are removed and replaced with a single Text node containing the new content.
dom_exception _dom_node_set_user_data | ( | dom_node_internal * | node, |
dom_string * | key, | ||
void * | data, | ||
dom_user_data_handler | handler, | ||
void ** | result ) |
Associate an object to a key on this node
node | The node to insert object into |
key | The key associated with the object |
data | The object to associate with key, or NULL to remove |
handler | User handler function, or NULL if none |
result | Pointer to location to receive previously associated object |
dom_exception _dom_node_try_destroy | ( | dom_node_internal * | node | ) |
Try to destroy this node.
node | The node to destroy |
When some node owns this node, (such as an elment owns its attribute nodes) when this node being not owned, the owner should call this function to try to destroy this node.