source: trunk/third/gtkhtml/src/gtkhtmldebug.c @ 18136

Revision 18136, 8.3 KB checked in by ghudson, 22 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r18135, which included commits to RCS files with non-trunk default branches.
Line 
1/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2/* This file is part of the GtkHTML library
3
4   Copyright (C) 2000 Helix Code, Inc.
5   
6   This library is free software; you can redistribute it and/or
7   modify it under the terms of the GNU Library General Public
8   License as published by the Free Software Foundation; either
9   version 2 of the License, or (at your option) any later version.
10   
11   This library is distributed in the hope that it will be useful,
12   but WITHOUT ANY WARRANTY; without even the implied warranty of
13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14   Library General Public License for more details.
15   
16   You should have received a copy of the GNU Library General Public License
17   along with this library; see the file COPYING.LIB.  If not, write to
18   the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19   Boston, MA 02111-1307, USA.
20*/
21
22/* Various debugging routines.  */
23
24#include <config.h>
25#include "gtkhtml-compat.h"
26
27#include <stdio.h>
28#include <stdarg.h>
29#include <string.h>
30#include <stdlib.h>
31
32#include "gtkhtml.h"
33#include "htmlobject.h"
34#include "htmltext.h"
35#include "htmltextslave.h"
36#include "htmltable.h"
37#include "htmltablecell.h"
38#include "htmlclue.h"
39#include "htmlclueflow.h"
40#include "htmlframe.h"
41#include "htmlframeset.h"
42#include "htmliframe.h"
43#include "htmlengine.h"
44#include "htmltype.h"
45#include "htmlenums.h"
46#include "htmlenumutils.h"
47
48#include "gtkhtmldebug.h"
49
50
51/**
52 * gtk_html_debug_log:
53 * @html: A GtkHTML widget
54 * @format: A format string, in printf() style
55 *
56 * If @html has debugging turned on, print out the message, just like libc
57 * printf().  Otherwise, just do nothing.
58 **/
59void
60gtk_html_debug_log (GtkHTML *html,
61                    const gchar *format,
62                    ...)
63{
64        va_list ap;
65
66        if (! html->debug)
67                return;
68
69        va_start (ap, format);
70        vprintf (format, ap);
71}
72
73
74static const gchar *
75clueflow_style_to_string (HTMLClueFlowStyle style)
76{
77        switch (style) {
78        case HTML_CLUEFLOW_STYLE_NORMAL:
79                return "Normal";
80        case HTML_CLUEFLOW_STYLE_H1:
81                return "H1";
82        case HTML_CLUEFLOW_STYLE_H2:
83                return "H2";
84        case HTML_CLUEFLOW_STYLE_H3:
85                return "H3";
86        case HTML_CLUEFLOW_STYLE_H4:
87                return "H4";
88        case HTML_CLUEFLOW_STYLE_H5:
89                return "H5";
90        case HTML_CLUEFLOW_STYLE_H6:
91                return "H6";
92        case HTML_CLUEFLOW_STYLE_ADDRESS:
93                return "Address";
94        case HTML_CLUEFLOW_STYLE_PRE:
95                return "Pre";
96        case HTML_CLUEFLOW_STYLE_LIST_ITEM:
97                return "List Item";
98        default:
99                return "UNKNOWN";
100        }
101}
102
103
104void
105gtk_html_debug_dump_table (HTMLObject *o,
106                           gint level)
107{
108        gint c, r;
109        HTMLTable *table = HTML_TABLE (o);
110
111        for (r = 0; r < table->totalRows; r++) {
112                for (c = 0; c < table->totalCols; c++) {
113                        gtk_html_debug_dump_tree (HTML_OBJECT (table->cells[r][c]), level);
114                }
115        }
116
117}
118
119static void
120gtk_html_debug_dump_table_simple (HTMLObject *o, gint level)
121{
122        gint c, r;
123        HTMLTable *table = HTML_TABLE (o);
124
125        for (r = 0; r < table->totalRows; r++) {
126                for (c = 0; c < table->totalCols; c++) {
127                        gtk_html_debug_dump_tree_simple (HTML_OBJECT (table->cells[r][c]), level);
128                }
129        }
130
131}
132
133void
134gtk_html_debug_dump_object (HTMLObject *obj,
135                            gint level)
136{
137        gint i;
138        for (i = 0; i < level; i++)
139                g_print (" ");
140
141        g_print ("ObjectType: %s Pos: %d, %d, MinWidth: %d, Width: %d PrefWidth: %d MaxWidth: %d Ascent %d Descent %d",
142                 html_type_name (HTML_OBJECT_TYPE (obj)),
143                 obj->x, obj->y, obj->min_width, obj->width, obj->pref_width, obj->max_width, obj->ascent, obj->descent);
144
145        if (HTML_OBJECT_TYPE (obj) == HTML_TYPE_CLUEFLOW)
146                g_print (" [%s, %d]",
147                         clueflow_style_to_string (HTML_CLUEFLOW (obj)->style), HTML_CLUEFLOW (obj)->levels->len);
148        else if (HTML_OBJECT_TYPE (obj) == HTML_TYPE_TEXTSLAVE) {
149                gchar *sl_text = g_strndup (html_text_get_text (HTML_TEXT (HTML_TEXT_SLAVE (obj)->owner),
150                                                                HTML_TEXT_SLAVE (obj)->posStart),
151                                            html_text_get_index (HTML_TEXT (HTML_TEXT_SLAVE (obj)->owner),
152                                                                 HTML_TEXT_SLAVE (obj)->posStart
153                                                                 + HTML_TEXT_SLAVE (obj)->posLen)
154                                            - html_text_get_index (HTML_TEXT (HTML_TEXT_SLAVE (obj)->owner),
155                                                                   HTML_TEXT_SLAVE (obj)->posStart));
156                g_print ("[start %d end %d] \"%s\" ",
157                         HTML_TEXT_SLAVE (obj)->posStart,
158                         HTML_TEXT_SLAVE (obj)->posStart + HTML_TEXT_SLAVE (obj)->posLen - 1,
159                         sl_text);
160                g_free (sl_text);
161        }
162
163        g_print ("\n");
164
165        switch (HTML_OBJECT_TYPE (obj)) {
166        case HTML_TYPE_TABLE:
167                gtk_html_debug_dump_table (obj, level + 1);
168                break;
169        case HTML_TYPE_TEXT:
170        case HTML_TYPE_LINKTEXT:
171                for (i = 0; i < level; i++)
172                        g_print (" ");
173                g_print ("Text (%d): \"%s\"\n",
174                         HTML_TEXT (obj)->text_len, HTML_TEXT (obj)->text);
175                break;
176
177        case HTML_TYPE_CLUEH:
178        case HTML_TYPE_CLUEV:
179        case HTML_TYPE_CLUEFLOW:
180                /* g_print ("Head: %p Tail: %p\n", HTML_CLUE (obj)->head, HTML_CLUE (obj)->tail); */
181        case HTML_TYPE_CLUEALIGNED:
182        case HTML_TYPE_TABLECELL:
183                for (i = 0; i < level; i++) g_print (" ");
184                g_print ("HAlign: %s VAlign: %s\n",
185                         html_halign_name (HTML_CLUE (obj)->halign),
186                         html_valign_name (HTML_CLUE (obj)->valign));
187                gtk_html_debug_dump_tree (HTML_CLUE (obj)->head, level + 1);
188                break;
189        case HTML_TYPE_IFRAME:
190                gtk_html_debug_dump_tree (GTK_HTML (HTML_IFRAME (obj)->html)->engine->clue, level + 1);
191                break;
192        case HTML_TYPE_FRAME:
193                gtk_html_debug_dump_tree (GTK_HTML (HTML_FRAME (obj)->html)->engine->clue, level + 1);
194                break;
195        case HTML_TYPE_IMAGE:
196                for (i = 0; i < level; i++) g_print (" ");
197                g_print ("Location: %s\n", HTML_IMAGE (obj)->image_ptr->url);
198                break;
199        case HTML_TYPE_FRAMESET: {
200                gint i;
201
202                for (i = 0; i < HTML_FRAMESET (obj)->frames->len; i++)
203                        gtk_html_debug_dump_tree (g_ptr_array_index (HTML_FRAMESET (obj)->frames, i), level + 1);
204                }
205                break;
206        default:
207                break;
208        }
209}
210
211void
212gtk_html_debug_dump_tree (HTMLObject *o,
213                          gint level)
214{
215        HTMLObject *obj;
216
217        obj = o;
218        while (obj) {
219                gtk_html_debug_dump_object (obj, level);
220                obj = obj->next;
221        }
222}
223
224
225static void
226debug_word_width (HTMLText *t, gint level)
227{
228        guint i;
229
230        for (i = 0; i < level; i++)
231                g_print ("\t");
232
233        printf ("words: %d | ", t->words);
234        for (i = 0; i < t->words; i ++)
235                printf ("%d ", t->word_width [i]);
236        printf ("\n");
237}
238
239static void
240dump_data (GQuark key_id, gpointer data, gpointer user_data)
241{
242        gint i, level = GPOINTER_TO_INT (user_data);
243
244        for (i = 0; i < level; i++)
245                g_print ("\t");
246
247        printf ("%s: '%s'\n", g_quark_to_string (key_id), (gchar *) data);
248}
249
250static void
251dump_object_simple (HTMLObject *obj,
252                    gint level)
253{
254        gint i;
255
256        for (i = 0; i < level; i++)
257                g_print ("\t");
258
259        if (html_object_is_text (obj)) {
260                g_print ("%s `%s'\n",
261                         html_type_name (HTML_OBJECT_TYPE (obj)),
262                         HTML_TEXT (obj)->text);
263                debug_word_width (HTML_TEXT (obj), level);
264        } else if (HTML_OBJECT_TYPE (obj) == HTML_TYPE_TEXTSLAVE) {
265                HTMLTextSlave *slave = HTML_TEXT_SLAVE (obj);
266                gchar *text;
267
268                text = alloca (slave->posLen+1);
269                text [slave->posLen] = 0;
270                strncpy (text, slave->owner->text + slave->posStart, slave->posLen);
271                g_print ("%s `%s'\n",
272                         html_type_name (HTML_OBJECT_TYPE (obj)),
273                         text);
274        } else if (HTML_OBJECT_TYPE (obj) == HTML_TYPE_TABLECELL) {
275                g_print ("%s %d,%d\n", html_type_name (HTML_OBJECT_TYPE (obj)),
276                         HTML_TABLE_CELL (obj)->row, HTML_TABLE_CELL (obj)->col);
277        } else if (HTML_OBJECT_TYPE (obj) == HTML_TYPE_TABLE) {
278                g_print ("%s %d,%d\n", html_type_name (HTML_OBJECT_TYPE (obj)),
279                         HTML_TABLE (obj)->totalRows, HTML_TABLE (obj)->totalCols);
280        } else
281                g_print ("%s\n", html_type_name (HTML_OBJECT_TYPE (obj)));
282
283        if (obj->object_data)
284                g_datalist_foreach (&obj->object_data, dump_data, GINT_TO_POINTER (level));
285}
286
287void
288gtk_html_debug_dump_object_type (HTMLObject *o)
289{
290        dump_object_simple (o, 0);
291}
292
293void
294gtk_html_debug_dump_tree_simple (HTMLObject *o,
295                                 gint level)
296{
297        HTMLObject *obj;
298
299        for (obj = o; obj != NULL; obj = obj->next) {
300                if (HTML_OBJECT_TYPE (obj) == HTML_TYPE_TEXTSLAVE)
301                        continue;
302
303                dump_object_simple (obj, level);
304
305                switch (HTML_OBJECT_TYPE (obj)) {
306                case HTML_TYPE_CLUEH:
307                case HTML_TYPE_CLUEV:
308                case HTML_TYPE_CLUEFLOW:
309                case HTML_TYPE_CLUEALIGNED:
310                case HTML_TYPE_TABLECELL:
311                        gtk_html_debug_dump_tree_simple (HTML_CLUE (obj)->head, level + 1);
312                        break;
313                case HTML_TYPE_TABLE:
314                        gtk_html_debug_dump_table_simple (obj, level + 1);
315                        break;
316                default:
317                        break;
318                }
319        }
320}
321
322void
323gtk_html_debug_dump_list_simple (GList *list,
324                                 gint level)
325{
326        HTMLObject *obj;
327        GList *p;
328
329        for (p = list; p != NULL; p = p->next) {
330                obj = HTML_OBJECT (p->data);
331
332                if (HTML_OBJECT_TYPE (obj) == HTML_TYPE_TEXTSLAVE)
333                        continue;
334
335                dump_object_simple (obj, level);
336        }
337}
Note: See TracBrowser for help on using the repository browser.