File Coverage

third_party/modest/source/modest/render/tree_node.c
Criterion Covered Total %
statement 0 75 0.0
branch 0 28 0.0
condition n/a
subroutine n/a
pod n/a
total 0 103 0.0


line stmt bran cond sub pod time code
1             /*
2             Copyright (C) 2016-2017 Alexander Borisov
3            
4             This library is free software; you can redistribute it and/or
5             modify it under the terms of the GNU Lesser General Public
6             License as published by the Free Software Foundation; either
7             version 2.1 of the License, or (at your option) any later version.
8            
9             This library is distributed in the hope that it will be useful,
10             but WITHOUT ANY WARRANTY; without even the implied warranty of
11             MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12             Lesser General Public License for more details.
13            
14             You should have received a copy of the GNU Lesser General Public
15             License along with this library; if not, write to the Free Software
16             Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17            
18             Author: lex.borisov@gmail.com (Alexander Borisov)
19             */
20              
21             #include "modest/render/tree_node.h"
22              
23 0           modest_render_tree_node_t * modest_render_tree_node_create_and_init(modest_render_tree_t* render_tree)
24             {
25 0           void *render_node = mcobject_malloc(render_tree->mc_nodes, NULL);
26            
27 0 0         if(render_node) {
28 0           memset(render_node, 0, sizeof(modest_render_tree_node_t));
29             }
30            
31 0           return render_node;
32             }
33              
34 0           void modest_render_tree_node_clean_all(modest_render_tree_node_t* render_node)
35             {
36 0           memset(render_node, 0, sizeof(modest_render_tree_node_t));
37 0           }
38              
39 0           modest_render_tree_node_t * modest_render_tree_node_destroy(modest_render_tree_t* render_tree, modest_render_tree_node_t* render_node, bool self_destroy)
40             {
41 0 0         if(render_node == NULL)
42 0           return NULL;
43            
44 0 0         if(self_destroy) {
45 0           mcobject_free(render_tree->mc_nodes, render_node);
46 0           return NULL;
47             }
48            
49 0           return render_node;
50             }
51              
52 0           void modest_render_tree_node_append(modest_render_tree_node_t* to, modest_render_tree_node_t* node)
53             {
54 0 0         if(to->child_last) {
55 0           to->child_last->next = node;
56 0           node->prev = to->child_last;
57             }
58             else {
59 0           to->child = node;
60 0           node->prev = NULL;
61             }
62            
63 0           node->parent = to;
64 0           node->next = NULL;
65            
66 0           to->child_last = node;
67 0           }
68              
69 0           void modest_render_tree_node_remove(modest_render_tree_node_t* node)
70             {
71 0 0         if(node->parent) {
72 0 0         if(node->next == NULL)
73 0           node->parent->child_last = node->prev;
74             else
75 0           node->next->prev = node->prev;
76            
77 0 0         if(node->prev == NULL)
78 0           node->parent->child = node->next;
79             else
80 0           node->prev->next = node->next;
81             }
82             else {
83 0 0         if(node->next)
84 0           node->next->prev = node->prev;
85            
86 0 0         if(node->prev)
87 0           node->prev->next = node->next;
88             }
89 0           }
90              
91 0           void modest_render_tree_node_append_after(modest_render_tree_node_t* target, modest_render_tree_node_t* node)
92             {
93 0 0         if(target->next) {
94 0           target->next->prev = node;
95             }
96             else {
97 0 0         if(target->parent)
98 0           target->parent->child_last = node;
99             }
100            
101 0           node->next = target->next;
102 0           node->prev = target;
103 0           node->parent = target->parent;
104            
105 0           target->next = node;
106 0           }
107              
108 0           void modest_render_tree_node_append_before(modest_render_tree_node_t* target, modest_render_tree_node_t* node)
109             {
110 0 0         if(target->prev) {
111 0           target->prev->next = node;
112             }
113             else {
114 0 0         if(target->parent)
115 0           target->parent->child = node;
116             }
117            
118 0           node->next = target;
119 0           node->prev = target->prev;
120 0           node->parent = target->parent;
121            
122 0           target->prev = node;
123 0           }
124              
125 0           void modest_render_tree_node_serialization(myhtml_tree_t* html_tree, modest_render_tree_node_t* node, mycore_callback_serialize_f callback, void* context)
126             {
127 0           callback("<", 1, context);
128            
129 0           switch (node->type) {
130             case MODEST_RENDER_TREE_NODE_TYPE_BLOCK:
131 0           callback("block", 5, context);
132 0           break;
133            
134             case MODEST_RENDER_TREE_NODE_TYPE_VIEWPORT:
135 0           callback("viewport", 8, context);
136 0           break;
137            
138             case MODEST_RENDER_TREE_NODE_TYPE_ANONYMOUS:
139 0           callback("anonymous", 9, context);
140 0           break;
141            
142             default:
143 0           break;
144             }
145            
146 0 0         if(node->html_node) {
147 0           size_t tag_length = 0;
148 0           const char *tag_name = myhtml_tag_name_by_id(html_tree, node->html_node->tag_id, &tag_length);
149            
150 0           callback(" ", 1, context);
151 0           callback(tag_name, tag_length, context);
152             }
153            
154 0           callback(">", 1, context);
155 0           }
156              
157