Make F9 dump box tree to an editor for easier debugging.

svn path=/trunk/netsurf/; revision=3529
This commit is contained in:
James Bursa 2007-08-20 02:39:49 +00:00
parent d1382c6d0e
commit 21db9de5f8
8 changed files with 104 additions and 65 deletions

View File

@ -97,8 +97,10 @@ int main(int argc, char *argv[])
fetchcache_go(c, 0, callback, 0, 0, 1000, 1000, fetchcache_go(c, 0, callback, 0, 0, 1000, 1000,
0, 0, true, 0); 0, 0, true, 0);
done = c->status == CONTENT_STATUS_DONE; done = c->status == CONTENT_STATUS_DONE;
while (!done) while (!done) {
fetch_poll(); fetch_poll();
sleep(1);
}
puts("=== SUCCESS, dumping cache"); puts("=== SUCCESS, dumping cache");
} else { } else {
destroyed = 1; destroyed = 1;
@ -110,7 +112,7 @@ int main(int argc, char *argv[])
/* content_reformat(c, 1, 1000); */ /* content_reformat(c, 1, 1000); */
/* save_complete(c, "save_complete");*/ /* save_complete(c, "save_complete");*/
if (c->type == CONTENT_HTML) if (c->type == CONTENT_HTML)
box_dump(c->data.html.layout, 0); box_dump(stderr, c->data.html.layout, 0);
else if (c->type == CONTENT_CSS) else if (c->type == CONTENT_CSS)
css_dump_stylesheet(c->data.css.css); css_dump_stylesheet(c->data.css.css);
else if (c->type == CONTENT_GIF) else if (c->type == CONTENT_GIF)

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2005 James Bursa <bursa@users.sourceforge.net> * Copyright 2005-2007 James Bursa <bursa@users.sourceforge.net>
* Copyright 2003 Phil Mellor <monkeyson@users.sourceforge.net> * Copyright 2003 Phil Mellor <monkeyson@users.sourceforge.net>
* Copyright 2005 John M Bell <jmb202@ecs.soton.ac.uk> * Copyright 2005 John M Bell <jmb202@ecs.soton.ac.uk>
* *
@ -24,6 +24,7 @@
#include <assert.h> #include <assert.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdio.h>
#include <string.h> #include <string.h>
#include "content/content.h" #include "content/content.h"
#include "css/css.h" #include "css/css.h"
@ -498,110 +499,110 @@ bool box_visible(struct box *box)
/** /**
* Print a box tree to stderr. * Print a box tree to a file.
*/ */
void box_dump(struct box *box, unsigned int depth) void box_dump(FILE *stream, struct box *box, unsigned int depth)
{ {
unsigned int i; unsigned int i;
struct box *c, *prev; struct box *c, *prev;
for (i = 0; i != depth; i++) for (i = 0; i != depth; i++)
fprintf(stderr, " "); fprintf(stream, " ");
fprintf(stderr, "%p ", box); fprintf(stream, "%p ", box);
fprintf(stderr, "x%i y%i w%i h%i ", box->x, box->y, fprintf(stream, "x%i y%i w%i h%i ", box->x, box->y,
box->width, box->height); box->width, box->height);
if (box->max_width != UNKNOWN_MAX_WIDTH) if (box->max_width != UNKNOWN_MAX_WIDTH)
fprintf(stderr, "min%i max%i ", box->min_width, box->max_width); fprintf(stream, "min%i max%i ", box->min_width, box->max_width);
fprintf(stderr, "(%i %i %i %i) ", fprintf(stream, "(%i %i %i %i) ",
box->descendant_x0, box->descendant_y0, box->descendant_x0, box->descendant_y0,
box->descendant_x1, box->descendant_y1); box->descendant_x1, box->descendant_y1);
switch (box->type) { switch (box->type) {
case BOX_BLOCK: fprintf(stderr, "BLOCK "); break; case BOX_BLOCK: fprintf(stream, "BLOCK "); break;
case BOX_INLINE_CONTAINER: fprintf(stderr, "INLINE_CONTAINER "); break; case BOX_INLINE_CONTAINER: fprintf(stream, "INLINE_CONTAINER "); break;
case BOX_INLINE: fprintf(stderr, "INLINE "); break; case BOX_INLINE: fprintf(stream, "INLINE "); break;
case BOX_INLINE_END: fprintf(stderr, "INLINE_END "); break; case BOX_INLINE_END: fprintf(stream, "INLINE_END "); break;
case BOX_INLINE_BLOCK: fprintf(stderr, "INLINE_BLOCK "); break; case BOX_INLINE_BLOCK: fprintf(stream, "INLINE_BLOCK "); break;
case BOX_TABLE: fprintf(stderr, "TABLE [columns %i] ", case BOX_TABLE: fprintf(stream, "TABLE [columns %i] ",
box->columns); break; box->columns); break;
case BOX_TABLE_ROW: fprintf(stderr, "TABLE_ROW "); break; case BOX_TABLE_ROW: fprintf(stream, "TABLE_ROW "); break;
case BOX_TABLE_CELL: fprintf(stderr, "TABLE_CELL [columns %i, " case BOX_TABLE_CELL: fprintf(stream, "TABLE_CELL [columns %i, "
"start %i, rows %i] ", box->columns, "start %i, rows %i] ", box->columns,
box->start_column, box->rows); break; box->start_column, box->rows); break;
case BOX_TABLE_ROW_GROUP: fprintf(stderr, "TABLE_ROW_GROUP "); break; case BOX_TABLE_ROW_GROUP: fprintf(stream, "TABLE_ROW_GROUP "); break;
case BOX_FLOAT_LEFT: fprintf(stderr, "FLOAT_LEFT "); break; case BOX_FLOAT_LEFT: fprintf(stream, "FLOAT_LEFT "); break;
case BOX_FLOAT_RIGHT: fprintf(stderr, "FLOAT_RIGHT "); break; case BOX_FLOAT_RIGHT: fprintf(stream, "FLOAT_RIGHT "); break;
case BOX_BR: fprintf(stderr, "BR "); break; case BOX_BR: fprintf(stream, "BR "); break;
case BOX_TEXT: fprintf(stderr, "TEXT "); break; case BOX_TEXT: fprintf(stream, "TEXT "); break;
default: fprintf(stderr, "Unknown box type "); default: fprintf(stream, "Unknown box type ");
} }
if (box->text) if (box->text)
fprintf(stderr, "%li '%.*s' ", (unsigned long) box->byte_offset, fprintf(stream, "%li '%.*s' ", (unsigned long) box->byte_offset,
(int) box->length, box->text); (int) box->length, box->text);
if (box->space) if (box->space)
fprintf(stderr, "space "); fprintf(stream, "space ");
if (box->object) if (box->object)
fprintf(stderr, "(object '%s') ", box->object->url); fprintf(stream, "(object '%s') ", box->object->url);
if (box->style) if (box->style)
css_dump_style(box->style); css_dump_style(box->style);
if (box->href) if (box->href)
fprintf(stderr, " -> '%s'", box->href); fprintf(stream, " -> '%s'", box->href);
if (box->target) if (box->target)
fprintf(stderr, " |%s|", box->target); fprintf(stream, " |%s|", box->target);
if (box->title) if (box->title)
fprintf(stderr, " [%s]", box->title); fprintf(stream, " [%s]", box->title);
if (box->id) if (box->id)
fprintf(stderr, " <%s>", box->id); fprintf(stream, " <%s>", box->id);
if (box->type == BOX_INLINE || box->type == BOX_INLINE_END) if (box->type == BOX_INLINE || box->type == BOX_INLINE_END)
fprintf(stderr, " inline_end %p", box->inline_end); fprintf(stream, " inline_end %p", box->inline_end);
if (box->float_children) if (box->float_children)
fprintf(stderr, " float_children %p", box->float_children); fprintf(stream, " float_children %p", box->float_children);
if (box->next_float) if (box->next_float)
fprintf(stderr, " next_float %p", box->next_float); fprintf(stream, " next_float %p", box->next_float);
if (box->col) { if (box->col) {
fprintf(stderr, " (columns"); fprintf(stream, " (columns");
for (i = 0; i != box->columns; i++) for (i = 0; i != box->columns; i++)
fprintf(stderr, " (%s %i %i %i)", fprintf(stream, " (%s %i %i %i)",
((const char *[]) {"UNKNOWN", "FIXED", ((const char *[]) {"UNKNOWN", "FIXED",
"AUTO", "PERCENT", "RELATIVE"}) "AUTO", "PERCENT", "RELATIVE"})
[box->col[i].type], [box->col[i].type],
box->col[i].width, box->col[i].width,
box->col[i].min, box->col[i].max); box->col[i].min, box->col[i].max);
fprintf(stderr, ")"); fprintf(stream, ")");
} }
fprintf(stderr, "\n"); fprintf(stream, "\n");
if (box->list_marker) { if (box->list_marker) {
for (i = 0; i != depth; i++) for (i = 0; i != depth; i++)
fprintf(stderr, " "); fprintf(stream, " ");
fprintf(stderr, "list_marker:\n"); fprintf(stream, "list_marker:\n");
box_dump(box->list_marker, depth + 1); box_dump(stream, box->list_marker, depth + 1);
} }
for (c = box->children; c && c->next; c = c->next) for (c = box->children; c && c->next; c = c->next)
; ;
if (box->last != c) if (box->last != c)
fprintf(stderr, "warning: box->last %p (should be %p) " fprintf(stream, "warning: box->last %p (should be %p) "
"(box %p)\n", box->last, c, box); "(box %p)\n", box->last, c, box);
for (prev = 0, c = box->children; c; prev = c, c = c->next) { for (prev = 0, c = box->children; c; prev = c, c = c->next) {
if (c->parent != box) if (c->parent != box)
fprintf(stderr, "warning: box->parent %p (should be " fprintf(stream, "warning: box->parent %p (should be "
"%p) (box on next line)\n", "%p) (box on next line)\n",
c->parent, box); c->parent, box);
if (c->prev != prev) if (c->prev != prev)
fprintf(stderr, "warning: box->prev %p (should be " fprintf(stream, "warning: box->prev %p (should be "
"%p) (box on next line)\n", "%p) (box on next line)\n",
c->prev, prev); c->prev, prev);
box_dump(c, depth + 1); box_dump(stream, c, depth + 1);
} }
if (box->fallback) { if (box->fallback) {
for (i = 0; i != depth; i++) for (i = 0; i != depth; i++)
fprintf(stderr, " "); fprintf(stream, " ");
fprintf(stderr, "fallback:\n"); fprintf(stream, "fallback:\n");
for (c = box->fallback; c; c = c->next) for (c = box->fallback; c; c = c->next)
box_dump(c, depth + 1); box_dump(stream, c, depth + 1);
} }
} }

View File

@ -88,6 +88,7 @@
#include <limits.h> #include <limits.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdio.h>
#include <libxml/HTMLparser.h> #include <libxml/HTMLparser.h>
@ -288,7 +289,7 @@ struct box *box_at_point(struct box *box, int x, int y,
struct box *box_object_at_point(struct content *c, int x, int y); struct box *box_object_at_point(struct content *c, int x, int y);
struct box *box_find_by_id(struct box *box, const char *id); struct box *box_find_by_id(struct box *box, const char *id);
bool box_visible(struct box *box); bool box_visible(struct box *box);
void box_dump(struct box *box, unsigned int depth); void box_dump(FILE *stream, struct box *box, unsigned int depth);
bool box_extract_link(const char *rel, const char *base, char **result); bool box_extract_link(const char *rel, const char *base, char **result);
bool box_vscrollbar_present(const struct box *box); bool box_vscrollbar_present(const struct box *box);

View File

@ -628,7 +628,7 @@ bool box_construct_text(xmlNode *n, struct content *content,
while (parent->parent && while (parent->parent &&
parent->parent->parent) parent->parent->parent)
parent = parent->parent; parent = parent->parent;
box_dump(parent, 0); box_dump(stderr, parent, 0);
} }
assert((*inline_container)->last != 0); assert((*inline_container)->last != 0);
(*inline_container)->last->space = 1; (*inline_container)->last->space = 1;

View File

@ -477,7 +477,7 @@ void layout_minmax_block(struct box *block)
} }
if (max < min) { if (max < min) {
box_dump(block, 0); box_dump(stderr, block, 0);
assert(0); assert(0);
} }
@ -1338,7 +1338,7 @@ bool layout_line(struct box *first, int *width, int *y,
} }
if (cont->float_children == b) { if (cont->float_children == b) {
LOG(("float %p already placed", b)); LOG(("float %p already placed", b));
box_dump(cont, 0); box_dump(stderr, cont, 0);
assert(0); assert(0);
} }
b->next_float = cont->float_children; b->next_float = cont->float_children;
@ -2349,7 +2349,7 @@ void layout_minmax_table(struct box *table)
for (i = 0; i != table->columns; i++) { for (i = 0; i != table->columns; i++) {
if (col[i].max < col[i].min) { if (col[i].max < col[i].min) {
box_dump(table, 0); box_dump(stderr, table, 0);
assert(0); assert(0);
} }
table_min += col[i].min; table_min += col[i].min;

View File

@ -847,7 +847,7 @@ void ro_gui_signal(int sig)
for (c = content_list; c; c = c->next) for (c = content_list; c; c = c->next)
if (c->type == CONTENT_HTML && c->data.html.layout) { if (c->type == CONTENT_HTML && c->data.html.layout) {
LOG(("Dumping: '%s'", c->url)); LOG(("Dumping: '%s'", c->url));
box_dump(c->data.html.layout, 0); box_dump(stderr, c->data.html.layout, 0);
} }
options_dump(); options_dump();
/*rufl_dump_state();*/ /*rufl_dump_state();*/
@ -2108,6 +2108,7 @@ void ro_gui_open_help_page(const char *page)
browser_window_create(url, NULL, 0, true); browser_window_create(url, NULL, 0, true);
} }
/** /**
* Send the source of a content to a text editor. * Send the source of a content to a text editor.
*/ */
@ -2187,7 +2188,8 @@ void ro_gui_view_source(struct content *content)
} }
void ro_gui_view_source_bounce(wimp_message *message) { void ro_gui_view_source_bounce(wimp_message *message)
{
char *filename; char *filename;
os_error *error; os_error *error;
char command[256]; char command[256];
@ -2204,6 +2206,47 @@ void ro_gui_view_source_bounce(wimp_message *message) {
} }
/**
* Send the debug dump of a content to a text editor.
*/
void ro_gui_dump_content(struct content *content)
{
os_error *error;
/* open file for dump */
FILE *stream = fopen("<Wimp$ScrapDir>.WWW.NetSurf.dump", "w");
if (!stream) {
LOG(("fopen: errno %i", errno));
warn_user("SaveError", strerror(errno));
return;
}
/* output debug information to file */
switch (content->type) {
case CONTENT_HTML:
box_dump(stream, content->data.html.layout, 0);
break;
case CONTENT_CSS:
css_dump_stylesheet(content->data.css.css);
break;
default:
break;
}
fclose(stream);
/* launch file in editor */
error = xwimp_start_task("Filer_Run <Wimp$ScrapDir>.WWW.NetSurf.dump",
0);
if (error) {
LOG(("xwimp_start_task failed: 0x%x: %s",
error->errnum, error->errmess));
warn_user("WimpError", error->errmess);
}
}
/** /**
* Broadcast an URL that we can't handle. * Broadcast an URL that we can't handle.
*/ */

View File

@ -122,6 +122,7 @@ void ro_gui_open_window_request(wimp_open *open);
void ro_gui_open_help_page(const char *page); void ro_gui_open_help_page(const char *page);
void ro_gui_screen_size(int *width, int *height); void ro_gui_screen_size(int *width, int *height);
void ro_gui_view_source(struct content *content); void ro_gui_view_source(struct content *content);
void ro_gui_dump_content(struct content *content);
void ro_gui_drag_box_start(wimp_pointer *pointer); void ro_gui_drag_box_start(wimp_pointer *pointer);
bool ro_gui_prequit(void); bool ro_gui_prequit(void);
const char *ro_gui_default_language(void); const char *ro_gui_default_language(void);

View File

@ -2439,16 +2439,7 @@ bool ro_gui_window_keypress(wimp_key *key)
case IS_WIMP_KEY + wimp_KEY_F9: case IS_WIMP_KEY + wimp_KEY_F9:
/* Dump content for debugging. */ /* Dump content for debugging. */
switch (content->type) { ro_gui_dump_content(content);
case CONTENT_HTML:
box_dump(content->data.html.layout, 0);
break;
case CONTENT_CSS:
css_dump_stylesheet(content->data.css.css);
break;
default:
break;
}
return true; return true;
case IS_WIMP_KEY + wimp_KEY_CONTROL + wimp_KEY_F9: case IS_WIMP_KEY + wimp_KEY_CONTROL + wimp_KEY_F9: