diff options
author | Michael Drake <tlsa@netsurf-browser.org> | 2014-02-08 22:43:54 +0000 |
---|---|---|
committer | Michael Drake <tlsa@netsurf-browser.org> | 2014-02-08 22:43:54 +0000 |
commit | 3d7cd77982d79ff798a92ebe7f3c0b2a52042cdf (patch) | |
tree | 43fb131d4c23d6d9f177c135291c4ad8ea102953 /desktop | |
parent | 2cd2e5b0541e7067c908e88f446b7cc56095253b (diff) | |
download | netsurf-3d7cd77982d79ff798a92ebe7f3c0b2a52042cdf.tar.gz netsurf-3d7cd77982d79ff798a92ebe7f3c0b2a52042cdf.tar.bz2 |
Simplify local history interface.
Diffstat (limited to 'desktop')
-rw-r--r-- | desktop/browser.c | 4 | ||||
-rw-r--r-- | desktop/local_history.c | 36 | ||||
-rw-r--r-- | desktop/local_history.h | 30 |
3 files changed, 36 insertions, 34 deletions
diff --git a/desktop/browser.c b/desktop/browser.c index 428c0775b..4fdfce52d 100644 --- a/desktop/browser.c +++ b/desktop/browser.c @@ -764,9 +764,9 @@ void browser_window_initialise_common(struct browser_window *bw, assert(bw); if (!clone) - bw->history = history_create(); + bw->history = history_create(bw); else - bw->history = history_clone(clone->history); + bw->history = history_clone(clone->history, bw); /* window characteristics */ bw->refresh_interval = -1; diff --git a/desktop/local_history.c b/desktop/local_history.c index 9829f51b6..b26f266d6 100644 --- a/desktop/local_history.c +++ b/desktop/local_history.c @@ -78,6 +78,8 @@ struct history { int width; /** Height of layout. */ int height; + /** Browser window that local history belongs to */ + struct browser_window *bw; }; static struct history_entry *history_clone_entry(struct history *history, @@ -102,7 +104,7 @@ static bool history_enumerate_entry(const struct history *history, * \return pointer to an opaque history structure, 0 on failure. */ -struct history *history_create(void) +struct history *history_create(struct browser_window *bw) { struct history *history; @@ -113,6 +115,7 @@ struct history *history_create(void) } history->width = RIGHT_MARGIN / 2; history->height = BOTTOM_MARGIN / 2; + history->bw = bw; return history; } @@ -125,12 +128,13 @@ struct history *history_create(void) * \return pointer to an opaque history structure, 0 on failure. */ -struct history *history_clone(struct history *history) +struct history *history_clone(struct history *history, + struct browser_window *bw) { struct history *new_history; if (!history->start) - return history_create(); + return history_create(bw); new_history = malloc(sizeof *history); if (!new_history) @@ -370,13 +374,14 @@ void history_free_entry(struct history_entry *entry) * * \param bw browser window * \param history history of the window + * \param new_window whether to open in new window */ -void history_back(struct browser_window *bw, struct history *history) +void history_back(struct history *history, bool new_window) { if (!history || !history->current || !history->current->back) return; - history_go(bw, history, history->current->back, false); + history_go(history, history->current->back, new_window); } @@ -385,13 +390,14 @@ void history_back(struct browser_window *bw, struct history *history) * * \param bw browser window * \param history history of the window + * \param new_window whether to open in new window */ -void history_forward(struct browser_window *bw, struct history *history) +void history_forward(struct history *history, bool new_window) { if (!history || !history->current || !history->current->forward_pref) return; - history_go(bw, history, history->current->forward_pref, false); + history_go(history, history->current->forward_pref, new_window); } @@ -422,9 +428,7 @@ bool history_forward_available(struct history *history) /* Documented in local_history.h */ -void history_go(struct browser_window *bw, - struct history *history, - struct history_entry *entry, +void history_go(struct history *history, struct history_entry *entry, bool new_window) { nsurl *url; @@ -452,14 +456,11 @@ void history_go(struct browser_window *bw, history->current = entry; browser_window_create(BROWSER_WINDOW_VERIFIABLE, - url, - NULL, - bw, - NULL); + url, NULL, history->bw, NULL); history->current = current; } else { history->current = entry; - browser_window_navigate(bw, url, NULL, + browser_window_navigate(history->bw, url, NULL, BROWSER_WINDOW_VERIFIABLE, NULL, NULL, NULL); } @@ -702,8 +703,7 @@ bool history_redraw_entry(struct history *history, * \return true if action was taken, false if click was not on an entry */ -bool history_click(struct browser_window *bw, struct history *history, - int x, int y, bool new_window) +bool history_click(struct history *history, int x, int y, bool new_window) { struct history_entry *entry; @@ -713,7 +713,7 @@ bool history_click(struct browser_window *bw, struct history *history, if (entry == history->current) return false; - history_go(bw, history, entry, new_window); + history_go(history, entry, new_window); return true; } diff --git a/desktop/local_history.h b/desktop/local_history.h index c4faa8532..b3e177b28 100644 --- a/desktop/local_history.h +++ b/desktop/local_history.h @@ -32,14 +32,15 @@ struct browser_window; struct history_entry; struct redraw_context; -struct history *history_create(void); -struct history *history_clone(struct history *history); +struct history *history_create(struct browser_window *bw); +struct history *history_clone(struct history *history, + struct browser_window *bw); void history_add(struct history *history, struct hlcache_handle *content, lwc_string *frag_id); void history_update(struct history *history, struct hlcache_handle *content); void history_destroy(struct history *history); -void history_back(struct browser_window *bw, struct history *history); -void history_forward(struct browser_window *bw, struct history *history); +void history_back(struct history *history, bool new_window); +void history_forward(struct history *history, bool new_window); bool history_back_available(struct history *history); bool history_forward_available(struct history *history); void history_size(struct history *history, int *width, int *height); @@ -47,8 +48,7 @@ bool history_redraw(struct history *history, const struct redraw_context *ctx); bool history_redraw_rectangle(struct history *history, int x0, int y0, int x1, int y1, int x, int y, const struct redraw_context *ctx); -bool history_click(struct browser_window *bw, struct history *history, - int x, int y, bool new_window); +bool history_click(struct history *history, int x, int y, bool new_window); const char *history_position_url(struct history *history, int x, int y); /** @@ -59,9 +59,10 @@ const char *history_position_url(struct history *history, int x, int y); * \param entry Current history entry * \return true to continue enumeration, false to cancel enumeration */ -typedef bool (*history_enumerate_cb)(const struct history *history, int x0, int y0, - int x1, int y1, - const struct history_entry *entry, void *user_data); +typedef bool (*history_enumerate_cb)(const struct history *history, + int x0, int y0, + int x1, int y1, + const struct history_entry *entry, void *user_data); /** * Enumerate all entries in the history. @@ -71,7 +72,8 @@ typedef bool (*history_enumerate_cb)(const struct history *history, int x0, int * \param cb callback function * \param user_data context pointer passed to cb */ -void history_enumerate(const struct history *history, history_enumerate_cb cb, void *user_data); +void history_enumerate(const struct history *history, + history_enumerate_cb cb, void *user_data); /** * Enumerate all entries that will be reached by the 'forward' button @@ -81,7 +83,7 @@ void history_enumerate(const struct history *history, history_enumerate_cb cb, v * \param user_data Data passed to the callback */ void history_enumerate_forward( struct history *history, - history_enumerate_cb cb, void *user_data ); + history_enumerate_cb cb, void *user_data); /** * Enumerate all entries that will be reached by the 'back' button @@ -91,7 +93,7 @@ void history_enumerate_forward( struct history *history, * \param user_data Data passed to the callback */ void history_enumerate_back( struct history *history, - history_enumerate_cb cb, void *user_data ); + history_enumerate_cb cb, void *user_data); /** * Returns the URL to a history entry @@ -125,7 +127,7 @@ const char *history_entry_get_title(const struct history_entry *entry); * \param entry entry to open * \param new_window open entry in new window */ -void history_go(struct browser_window *bw, struct history *history, - struct history_entry *entry, bool new_window); +void history_go(struct history *history, struct history_entry *entry, + bool new_window); #endif |