Allow content handlers to have debug values set through API

Previously content handler debugging features were accessed by global
variables. This allows the setting of debugging parameters via a
content API giving per content control over debugging features.
Currently only used by the html content handler to toggle global
redraw debugging.
This commit is contained in:
Vincent Sanders 2014-11-06 22:51:46 +00:00
parent 46f369ca9e
commit 8c2cfecfb5
11 changed files with 80 additions and 16 deletions

View File

@ -872,6 +872,22 @@ nserror content_debug_dump(struct hlcache_handle *h, FILE *f, enum content_debug
return c->handler->debug_dump(c, f, op); return c->handler->debug_dump(c, f, op);
} }
/* exported interface documented in content/content.h */
nserror content_debug(struct hlcache_handle *h, enum content_debug op)
{
struct content *c = hlcache_handle_get_content(h);
if (c == NULL) {
return NSERROR_BAD_PARAMETER;
}
if (c->handler->debug == NULL) {
return NSERROR_NOT_IMPLEMENTED;
}
return c->handler->debug(c, op);
}
void content_add_error(struct content *c, const char *token, void content_add_error(struct content *c, const char *token,
unsigned int line) unsigned int line)

View File

@ -90,7 +90,8 @@ typedef enum {
/** Debugging dump operations */ /** Debugging dump operations */
enum content_debug { enum content_debug {
CONTENT_DEBUG_RENDER, /** Debug the contents rendering. */ CONTENT_DEBUG_RENDER, /** Debug the contents rendering. */
CONTENT_DEBUG_DOM /** Debug teh contents Document Object. */ CONTENT_DEBUG_DOM, /** Debug the contents Document Object. */
CONTENT_DEBUG_REDRAW /** Debug redraw operations. */
}; };
/** RFC5988 metadata link */ /** RFC5988 metadata link */
@ -300,6 +301,14 @@ void content_search_clear(struct hlcache_handle *h);
*/ */
nserror content_debug_dump(struct hlcache_handle *h, FILE *f, enum content_debug op); nserror content_debug_dump(struct hlcache_handle *h, FILE *f, enum content_debug op);
/**
* Control debug con a content.
*
* \param h content handle to debug.
* \param op Debug operation type.
*/
nserror content_debug(struct hlcache_handle *h, enum content_debug op);
struct content_rfc5988_link *content_find_rfc5988_link(struct hlcache_handle *c, struct content_rfc5988_link *content_find_rfc5988_link(struct hlcache_handle *c,
lwc_string *rel); lwc_string *rel);

View File

@ -77,6 +77,7 @@ struct content_handler {
const char *string); const char *string);
void (*search_clear)(struct content *c); void (*search_clear)(struct content *c);
nserror (*debug_dump)(struct content *c, FILE *f, enum content_debug op); nserror (*debug_dump)(struct content *c, FILE *f, enum content_debug op);
nserror (*debug)(struct content *c, enum content_debug op);
nserror (*clone)(const struct content *old, struct content **newc); nserror (*clone)(const struct content *old, struct content **newc);
bool (*matches_quirks)(const struct content *c, bool quirks); bool (*matches_quirks)(const struct content *c, bool quirks);
const char *(*get_encoding)(const struct content *c); const char *(*get_encoding)(const struct content *c);

View File

@ -736,11 +736,19 @@ void browser_window_set_gadget_filename(struct browser_window *bw,
nserror browser_window_debug_dump(struct browser_window *bw, nserror browser_window_debug_dump(struct browser_window *bw,
FILE *f, enum content_debug op) FILE *f, enum content_debug op)
{ {
if (bw->current_content == NULL) { if (bw->current_content != NULL) {
return content_debug_dump(bw->current_content, f, op);
}
return NSERROR_OK; return NSERROR_OK;
} }
return content_debug_dump(bw->current_content, f, op); /* exported interface, documented in browser.h */
nserror browser_window_debug(struct browser_window *bw, enum content_debug op)
{
if (bw->current_content != NULL) {
return content_debug(bw->current_content, op);
}
return NSERROR_OK;
} }
/** slow script handler /** slow script handler

View File

@ -668,9 +668,19 @@ int browser_get_dpi(void);
/** /**
* Dump debug info concerning the browser window's contents to file * Dump debug info concerning the browser window's contents to file
* *
* \param bw The browser window * \param bw The browser window.
* \param f The file to dump to * \param f The file to dump to.
* \param op The debug operation type to dump.
* \return NSERROR_OK on success or error code on faliure.
*/ */
nserror browser_window_debug_dump(struct browser_window *bw, FILE *f, enum content_debug op); nserror browser_window_debug_dump(struct browser_window *bw, FILE *f, enum content_debug op);
/**
* set debug options on a window
* \param bw The browser window.
* \param op The debug operation type.
* \return NSERROR_OK on success or error code on faliure.
*/
nserror browser_window_debug(struct browser_window *bw, enum content_debug op);
#endif #endif

View File

@ -45,7 +45,6 @@
#include "desktop/searchweb.h" #include "desktop/searchweb.h"
#include "desktop/textinput.h" #include "desktop/textinput.h"
#include "desktop/font.h" #include "desktop/font.h"
#include "render/html.h"
#include "content/hlcache.h" #include "content/hlcache.h"
#include "gtk/compat.h" #include "gtk/compat.h"
@ -1267,8 +1266,14 @@ MULTIHANDLER(savewindowsize)
MULTIHANDLER(toggledebugging) MULTIHANDLER(toggledebugging)
{ {
html_redraw_debug = !html_redraw_debug; struct browser_window *bw;
bw = nsgtk_get_browser_window(g->top_level);
browser_window_debug(bw, CONTENT_DEBUG_REDRAW);
nsgtk_reflow_all_windows(); nsgtk_reflow_all_windows();
return TRUE; return TRUE;
} }

View File

@ -1977,11 +1977,27 @@ static bool html_drop_file_at_point(struct content *c, int x, int y, char *file)
} }
/**
* set debug status.
*
* \param c The content to debug
* \param op The debug operation type
*/
static nserror
html_debug(struct content *c, enum content_debug op)
{
html_redraw_debug = !html_redraw_debug;
return NSERROR_OK;
}
/** /**
* Dump debug info concerning the html_content * Dump debug info concerning the html_content
* *
* \param bw The browser window * \param c The content to debug
* \param f The file to dump to * \param f The file to dump to
* \param op The debug dump type
*/ */
static nserror static nserror
html_debug_dump(struct content *c, FILE *f, enum content_debug op) html_debug_dump(struct content *c, FILE *f, enum content_debug op)
@ -2261,6 +2277,7 @@ static const content_handler html_content_handler = {
.search = html_search, .search = html_search,
.search_clear = html_search_clear, .search_clear = html_search_clear,
.debug_dump = html_debug_dump, .debug_dump = html_debug_dump,
.debug = html_debug,
.clone = html_clone, .clone = html_clone,
.get_encoding = html_encoding, .get_encoding = html_encoding,
.type = html_content_type, .type = html_content_type,

View File

@ -149,9 +149,6 @@ struct content_html_iframe {
#define STYLESHEET_USER 3 /* user stylesheet */ #define STYLESHEET_USER 3 /* user stylesheet */
#define STYLESHEET_START 4 /* start of document stylesheets */ #define STYLESHEET_START 4 /* start of document stylesheets */
/** Render padding and margin box outlines in html_redraw(). */
extern bool html_redraw_debug;
nserror html_init(void); nserror html_init(void);
void html_redraw_a_box(struct hlcache_handle *h, struct box *box); void html_redraw_a_box(struct hlcache_handle *h, struct box *box);

View File

@ -176,7 +176,8 @@ typedef struct html_content {
} html_content; } html_content;
/** Render padding and margin box outlines in html_redraw(). */
extern bool html_redraw_debug;
void html_set_status(html_content *c, const char *extra); void html_set_status(html_content *c, const char *extra);

View File

@ -2000,7 +2000,8 @@ bool ro_gui_window_handle_local_keypress(struct gui_window *g, wimp_key *key,
case IS_WIMP_KEY + wimp_KEY_SHIFT + wimp_KEY_F11: case IS_WIMP_KEY + wimp_KEY_SHIFT + wimp_KEY_F11:
/* Toggle display of box outlines. */ /* Toggle display of box outlines. */
html_redraw_debug = !html_redraw_debug; browser_window_debug(g->bw, CONTENT_DEBUG_REDRAW);
gui_window_redraw_window(g); gui_window_redraw_window(g);
return true; return true;

View File

@ -42,7 +42,6 @@
#include "utils/nsoption.h" #include "utils/nsoption.h"
#include "desktop/plotters.h" #include "desktop/plotters.h"
#include "desktop/textinput.h" #include "desktop/textinput.h"
#include "render/html.h"
#include "desktop/gui_window.h" #include "desktop/gui_window.h"
#include "desktop/gui_clipboard.h" #include "desktop/gui_clipboard.h"
#include "desktop/gui_misc.h" #include "desktop/gui_misc.h"
@ -1013,8 +1012,8 @@ nsws_window_command(HWND hwnd,
break; break;
case IDM_VIEW_TOGGLE_DEBUG_RENDERING: case IDM_VIEW_TOGGLE_DEBUG_RENDERING:
html_redraw_debug = !html_redraw_debug;
if (gw->bw != NULL) { if (gw->bw != NULL) {
browser_window_debug(gw->bw, CONTENT_DEBUG_REDRAW);
/* TODO: This should only redraw, not reformat. /* TODO: This should only redraw, not reformat.
* (Layout doesn't change, so reformat is a waste of time) */ * (Layout doesn't change, so reformat is a waste of time) */
browser_window_reformat(gw->bw, false, gw->width, gw->height); browser_window_reformat(gw->bw, false, gw->width, gw->height);