summaryrefslogtreecommitdiff
path: root/src/events/mutation_name_event.c
blob: e0ba82e68165069fd8925e6cfa1fc7ea3204a1e3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/*
 * This file is part of libdom.
 * Licensed under the MIT License,
 *                http://www.opensource.org/licenses/mit-license.php
 * Copyright 2009 Bo Yang <struggleyb.nku@gmail.com>
 */

#include <stdlib.h>

#include "events/mutation_name_event.h"
#include "core/document.h"

#include "utils/utils.h"

static void _virtual_dom_mutation_name_event_destroy(struct dom_event *evt);

static struct dom_event_private_vtable _event_vtable = {
	_virtual_dom_mutation_name_event_destroy
};

/* Constructor */
dom_exception _dom_mutation_name_event_create(
		struct dom_mutation_name_event **evt)
{
	*evt = malloc(sizeof(dom_mutation_name_event));
	if (*evt == NULL) 
		return DOM_NO_MEM_ERR;
	
	((struct dom_event *) *evt)->vtable = &_event_vtable;

	return _dom_mutation_name_event_initialise(*evt);
}

/* Destructor */
void _dom_mutation_name_event_destroy(struct dom_mutation_name_event *evt)
{
	_dom_mutation_name_event_finalise(evt);

	free(evt);
}

/* Initialise function */
dom_exception _dom_mutation_name_event_initialise(
		struct dom_mutation_name_event *evt)
{
	evt->prev_namespace = NULL;
	evt->prev_nodename = NULL;

	return _dom_event_initialise((dom_event *) evt);
}

/* Finalise function */
void _dom_mutation_name_event_finalise(struct dom_mutation_name_event *evt)
{
	dom_string_unref(evt->prev_namespace);
	dom_string_unref(evt->prev_nodename);

	_dom_event_finalise((dom_event *) evt);
}

/* The virtual destroy function */
void _virtual_dom_mutation_name_event_destroy(struct dom_event *evt)
{
	_dom_mutation_name_event_destroy((dom_mutation_name_event *) evt);
}

/*----------------------------------------------------------------------*/
/* The public API */

/**
 * Get the previous namespace
 *
 * \param evt        The Event object
 * \param namespace  The previous namespace of this event
 * \return DOM_NO_ERR.
 */
dom_exception _dom_mutation_name_event_get_prev_namespace(
		dom_mutation_name_event *evt, dom_string **namespace)
{
	*namespace = evt->prev_namespace;
	dom_string_ref(*namespace);

	return DOM_NO_ERR;
}

/**
 * Get the previous node name
 *
 * \param evt   The Event object
 * \param name  The previous node name
 * \return DOM_NO_ERR.
 */
dom_exception _dom_mutation_name_event_get_prev_node_name(
		dom_mutation_name_event *evt, dom_string **name)
{
	*name = evt->prev_nodename;
	dom_string_ref(*name);

	return DOM_NO_ERR;
}

/**
 * Initialise the MutationNameEvent
 *
 * \param evt         The Event object
 * \param type        The type of this UIEvent
 * \param bubble      Whether this event can bubble
 * \param cancelable  Whether this event is cancelable
 * \param node        The node whose name change
 * \param prev_ns     The old namespace
 * \param prev_name   The old name
 * \return DOM_NO_ERR on success, appropriate dom_exception on failure.
 */
dom_exception _dom_mutation_name_event_init(dom_mutation_name_event *evt, 
		dom_string *type, bool bubble, bool cancelable, 
		struct dom_node *node, dom_string *prev_ns, 
		dom_string *prev_name)
{
	evt->prev_namespace = prev_ns;
	dom_string_ref(prev_ns);

	evt->prev_nodename = prev_name;
	dom_string_ref(prev_name);

	return _dom_mutation_event_init((dom_mutation_event *) evt, type,
			bubble, cancelable, node, NULL, NULL, NULL,
			DOM_MUTATION_MODIFICATION);
}

/**
 * Initialise the MutationNameEvent with namespace
 *
 * \param evt         The Event object
 * \param namespace   The namespace
 * \param type        The type of this UIEvent
 * \param bubble      Whether this event can bubble
 * \param cancelable  Whether this event is cancelable
 * \param node        The node whose name change
 * \param prev_ns     The old namespace
 * \param prev_name   The old name
 * \return DOM_NO_ERR on success, appropriate dom_exception on failure.
 */
dom_exception _dom_mutation_name_event_init_ns(dom_mutation_name_event *evt, 
		dom_string *namespace, dom_string *type,
		bool bubble, bool cancelable, struct dom_node *node,
		dom_string *prev_ns, dom_string *prev_name)
{
	evt->prev_namespace = prev_ns;
	dom_string_ref(prev_ns);

	evt->prev_nodename = prev_name;
	dom_string_ref(prev_name);

	return _dom_mutation_event_init_ns((dom_mutation_event *) evt,
			namespace, type, bubble, cancelable, node, NULL,
			NULL, NULL, DOM_MUTATION_MODIFICATION);
}