split out status bar text cache into separate struct

This commit is contained in:
Vincent Sanders 2017-03-03 09:28:54 +00:00
parent 028c4e2860
commit 855721282c
2 changed files with 67 additions and 39 deletions

View File

@ -87,7 +87,6 @@
* \param x Updated to x-coord of top left of scrollbar widget * \param x Updated to x-coord of top left of scrollbar widget
* \param y Updated to y-coord of top left of scrollbar widget * \param y Updated to y-coord of top left of scrollbar widget
*/ */
static inline void browser_window_get_scrollbar_pos(struct browser_window *bw, static inline void browser_window_get_scrollbar_pos(struct browser_window *bw,
bool horizontal, int *x, int *y) bool horizontal, int *x, int *y)
{ {
@ -129,6 +128,7 @@ browser_window_get_name(struct browser_window *bw, const char **out_name)
return NSERROR_OK; return NSERROR_OK;
} }
/* exported interface, documented in browser.h */ /* exported interface, documented in browser.h */
nserror nserror
browser_window_set_name(struct browser_window *bw, const char *name) browser_window_set_name(struct browser_window *bw, const char *name)
@ -153,6 +153,7 @@ browser_window_set_name(struct browser_window *bw, const char *name)
return NSERROR_OK; return NSERROR_OK;
} }
/* exported interface, documented in browser.h */ /* exported interface, documented in browser.h */
bool bool
browser_window_redraw(struct browser_window *bw, browser_window_redraw(struct browser_window *bw,
@ -330,6 +331,7 @@ browser_window_redraw(struct browser_window *bw,
return plot_ok; return plot_ok;
} }
/* exported interface, documented in browser.h */ /* exported interface, documented in browser.h */
bool browser_window_redraw_ready(struct browser_window *bw) bool browser_window_redraw_ready(struct browser_window *bw)
{ {
@ -344,6 +346,7 @@ bool browser_window_redraw_ready(struct browser_window *bw)
return true; return true;
} }
/* exported interface, documented in browser_private.h */ /* exported interface, documented in browser_private.h */
void browser_window_update_extent(struct browser_window *bw) void browser_window_update_extent(struct browser_window *bw)
{ {
@ -355,9 +358,13 @@ void browser_window_update_extent(struct browser_window *bw)
browser_window_handle_scrollbars(bw); browser_window_handle_scrollbars(bw);
} }
/* exported interface, documented in browser.h */ /* exported interface, documented in browser.h */
void browser_window_get_position(struct browser_window *bw, bool root, void
int *pos_x, int *pos_y) browser_window_get_position(struct browser_window *bw,
bool root,
int *pos_x,
int *pos_y)
{ {
*pos_x = 0; *pos_x = 0;
*pos_y = 0; *pos_y = 0;
@ -397,6 +404,7 @@ void browser_window_get_position(struct browser_window *bw, bool root,
} }
} }
/* exported interface, documented in browser.h */ /* exported interface, documented in browser.h */
void browser_window_set_position(struct browser_window *bw, int x, int y) void browser_window_set_position(struct browser_window *bw, int x, int y)
{ {
@ -939,10 +947,10 @@ nserror browser_window_initialise_common(enum browser_window_create_flags flags,
bw->focus = NULL; bw->focus = NULL;
/* initialise status text cache */ /* initialise status text cache */
bw->status_text = NULL; bw->status.text = NULL;
bw->status_text_len = 0; bw->status.text_len = 0;
bw->status_match = 0; bw->status.match = 0;
bw->status_miss = 0; bw->status.miss = 0;
return NSERROR_OK; return NSERROR_OK;
} }
@ -1318,8 +1326,10 @@ static void browser_window_convert_to_download(struct browser_window *bw,
/** /**
* Browser window content event callback handler. * Browser window content event callback handler.
*/ */
static nserror browser_window_callback(hlcache_handle *c, static nserror
const hlcache_event *event, void *pw) browser_window_callback(hlcache_handle *c,
const hlcache_event *event,
void *pw)
{ {
struct browser_window *bw = pw; struct browser_window *bw = pw;
nserror res = NSERROR_OK; nserror res = NSERROR_OK;
@ -1857,9 +1867,9 @@ static void browser_window_destroy_internal(struct browser_window *bw)
browser_window_history_destroy(bw); browser_window_history_destroy(bw);
free(bw->name); free(bw->name);
free(bw->status_text); free(bw->status.text);
bw->status_text = NULL; bw->status.text = NULL;
LOG("Status text cache match:miss %d:%d", bw->status_match, bw->status_miss); LOG("Status text cache match:miss %d:%d", bw->status.match, bw->status.miss);
} }
/** /**
@ -1931,7 +1941,8 @@ nserror browser_window_refresh_url_bar(struct browser_window *bw)
/* exported interface documented in netsurf/browser_window.h */ /* exported interface documented in netsurf/browser_window.h */
nserror browser_window_navigate(struct browser_window *bw, nserror
browser_window_navigate(struct browser_window *bw,
nsurl *url, nsurl *url,
nsurl *referrer, nsurl *referrer,
enum browser_window_nav_flags flags, enum browser_window_nav_flags flags,
@ -2289,14 +2300,16 @@ void browser_window_update(struct browser_window *bw, bool scroll_to_top)
browser_window_update_extent(bw); browser_window_update_extent(bw);
if (scroll_to_top)
browser_window_set_scroll(bw, 0, 0);
/* if frag_id exists, then try to scroll to it */ /* if frag_id exists, then try to scroll to it */
/** @todo don't do this if the user has scrolled */ /** @todo don't do this if the user has scrolled */
if (bw->frag_id && html_get_id_offset(bw->current_content, if (bw->frag_id &&
bw->frag_id, &x, &y)) { html_get_id_offset(bw->current_content,
bw->frag_id, &x, &y)) {
browser_window_set_scroll(bw, x, y); browser_window_set_scroll(bw, x, y);
} else {
if (scroll_to_top) {
browser_window_set_scroll(bw, 0, 0);
}
} }
guit->window->redraw(bw->window); guit->window->redraw(bw->window);
@ -2476,10 +2489,10 @@ void browser_window_set_status(struct browser_window *bw, const char *text)
while (bw->parent) while (bw->parent)
bw = bw->parent; bw = bw->parent;
if ((bw->status_text != NULL) && if ((bw->status.text != NULL) &&
(strcmp(text, bw->status_text) == 0)) { (strcmp(text, bw->status.text) == 0)) {
/* status text is unchanged */ /* status text is unchanged */
bw->status_match++; bw->status.match++;
return; return;
} }
@ -2487,18 +2500,18 @@ void browser_window_set_status(struct browser_window *bw, const char *text)
text_len = strlen(text); text_len = strlen(text);
if ((bw->status_text == NULL) || (bw->status_text_len < text_len)) { if ((bw->status.text == NULL) || (bw->status.text_len < text_len)) {
/* no current string allocation or it is not long enough */ /* no current string allocation or it is not long enough */
free(bw->status_text); free(bw->status.text);
bw->status_text = strdup(text); bw->status.text = strdup(text);
bw->status_text_len = text_len; bw->status.text_len = text_len;
} else { } else {
/* current allocation has enough space */ /* current allocation has enough space */
memcpy(bw->status_text, text, text_len + 1); memcpy(bw->status.text, text, text_len + 1);
} }
bw->status_miss++; bw->status.miss++;
guit->window->set_status(bw->window, bw->status_text); guit->window->set_status(bw->window, bw->status.text);
} }

View File

@ -37,24 +37,34 @@ struct gui_window;
struct history; struct history;
struct selection; struct selection;
/** Browser window data. */ /**
* Browser window data.
*/
struct browser_window { struct browser_window {
/** Page currently displayed, or 0. Must have status READY or DONE. */ /**
* Content handle of page currently displayed which must have
* READY or DONE status or NULL for no content.
*/
struct hlcache_handle *current_content; struct hlcache_handle *current_content;
/** Page being loaded, or 0. */ /** Page being loaded, or NULL. */
struct hlcache_handle *loading_content; struct hlcache_handle *loading_content;
/** Page Favicon */ /** Page Favicon */
struct hlcache_handle *current_favicon; struct hlcache_handle *current_favicon;
/** handle for favicon which we started loading early */ /** handle for favicon which we started loading early */
struct hlcache_handle *loading_favicon; struct hlcache_handle *loading_favicon;
/** favicon fetch already failed - prevents infinite error looping */ /**
* flag to indicate favicon fetch already failed which
* prevents infinite error looping.
*/
bool failed_favicon; bool failed_favicon;
/** Window history structure. */ /** local history handle. */
struct history *history; struct history *history;
/** Platform specific window data. */ /**
* Platform specific window data only valid at top level.
*/
struct gui_window *window; struct gui_window *window;
/** Busy indicator is active. */ /** Busy indicator is active. */
@ -156,14 +166,15 @@ struct browser_window {
struct jscontext *jsctx; struct jscontext *jsctx;
/** cache of the currently displayed status text. */ /** cache of the currently displayed status text. */
char *status_text; /**< Current status bar text. */ struct {
int status_text_len; /**< Length of the browser_window::status_text buffer. */ char *text; /**< Current status bar text. */
int status_match; /**< Number of times an idempotent status-set operation was performed. */ int text_len; /**< Length of the status::text buffer. */
int status_miss; /**< Number of times status was really updated. */ int match; /**< Number of times an idempotent status-set operation was performed. */
int miss; /**< Number of times status was really updated. */
} status;
}; };
/** /**
* Initialise common parts of a browser window * Initialise common parts of a browser window
* *
@ -174,6 +185,7 @@ struct browser_window {
nserror browser_window_initialise_common(enum browser_window_create_flags flags, nserror browser_window_initialise_common(enum browser_window_create_flags flags,
struct browser_window *bw, struct browser_window *existing); struct browser_window *bw, struct browser_window *existing);
/** /**
* Get the dimensions of the area a browser window occupies * Get the dimensions of the area a browser window occupies
* *
@ -185,6 +197,7 @@ nserror browser_window_initialise_common(enum browser_window_create_flags flags,
void browser_window_get_dimensions(struct browser_window *bw, void browser_window_get_dimensions(struct browser_window *bw,
int *width, int *height, bool scaled); int *width, int *height, bool scaled);
/** /**
* Update the extent of the inside of a browser window to that of the current * Update the extent of the inside of a browser window to that of the current
* content * content
@ -193,6 +206,7 @@ void browser_window_get_dimensions(struct browser_window *bw,
*/ */
void browser_window_update_extent(struct browser_window *bw); void browser_window_update_extent(struct browser_window *bw);
/** /**
* Change the status bar of a browser window. * Change the status bar of a browser window.
* *
@ -201,6 +215,7 @@ void browser_window_update_extent(struct browser_window *bw);
*/ */
void browser_window_set_status(struct browser_window *bw, const char *text); void browser_window_set_status(struct browser_window *bw, const char *text);
/** /**
* Get the root level browser window * Get the root level browser window
* *