mirror of
https://github.com/netsurf-browser/netsurf
synced 2025-01-01 00:34:31 +03:00
Add concept of browser scroll offset saving in local history
This commit is contained in:
parent
f86e9e505d
commit
a43d0cec7a
@ -887,7 +887,7 @@ nserror browser_window_create(enum browser_window_create_flags flags,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (url != NULL) {
|
if (url != NULL) {
|
||||||
enum browser_window_nav_flags nav_flags = BW_NAVIGATE_NONE;
|
enum browser_window_nav_flags nav_flags = BW_NAVIGATE_NO_TERMINAL_HISTORY_UPDATE;
|
||||||
if (flags & BW_CREATE_UNVERIFIABLE)
|
if (flags & BW_CREATE_UNVERIFIABLE)
|
||||||
nav_flags |= BW_NAVIGATE_UNVERIFIABLE;
|
nav_flags |= BW_NAVIGATE_UNVERIFIABLE;
|
||||||
if (flags & BW_CREATE_HISTORY)
|
if (flags & BW_CREATE_HISTORY)
|
||||||
@ -1355,6 +1355,7 @@ browser_window_callback(hlcache_handle *c,
|
|||||||
{
|
{
|
||||||
struct browser_window *bw = pw;
|
struct browser_window *bw = pw;
|
||||||
nserror res = NSERROR_OK;
|
nserror res = NSERROR_OK;
|
||||||
|
float sx, sy;
|
||||||
|
|
||||||
switch (event->type) {
|
switch (event->type) {
|
||||||
case CONTENT_MSG_DOWNLOAD:
|
case CONTENT_MSG_DOWNLOAD:
|
||||||
@ -1485,6 +1486,19 @@ browser_window_callback(hlcache_handle *c,
|
|||||||
browser_window_stop_throbber(bw);
|
browser_window_stop_throbber(bw);
|
||||||
browser_window_update_favicon(c, bw, NULL);
|
browser_window_update_favicon(c, bw, NULL);
|
||||||
|
|
||||||
|
if (browser_window_history_get_scroll(bw, &sx, &sy) == NSERROR_OK) {
|
||||||
|
int scrollx = (int)((float)content_get_width(bw->current_content) * sx);
|
||||||
|
int scrolly = (int)((float)content_get_height(bw->current_content) * sy);
|
||||||
|
struct rect rect;
|
||||||
|
rect.x0 = rect.x1 = scrollx;
|
||||||
|
rect.y0 = rect.y1 = scrolly;
|
||||||
|
if (browser_window_set_scroll(bw, &rect) != NSERROR_OK) {
|
||||||
|
NSLOG(netsurf, WARNING,
|
||||||
|
"Unable to set browser scroll offsets to %d by %d",
|
||||||
|
scrollx, scrolly);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
browser_window_history_update(bw, c);
|
browser_window_history_update(bw, c);
|
||||||
hotlist_update_url(hlcache_handle_get_url(c));
|
hotlist_update_url(hlcache_handle_get_url(c));
|
||||||
|
|
||||||
@ -2014,6 +2028,20 @@ browser_window_navigate(struct browser_window *bw,
|
|||||||
|
|
||||||
NSLOG(netsurf, INFO, "bw %p, url %s", bw, nsurl_access(url));
|
NSLOG(netsurf, INFO, "bw %p, url %s", bw, nsurl_access(url));
|
||||||
|
|
||||||
|
/* If we're navigating and we have a history entry and a content
|
||||||
|
* then update the history entry before we navigate to save our
|
||||||
|
* current state. However since history navigation pre-moves
|
||||||
|
* the history state, we ensure that we only do this if we've not
|
||||||
|
* been suppressed. In the suppressed case, the history code
|
||||||
|
* updates the history itself before navigating.
|
||||||
|
*/
|
||||||
|
if (bw->current_content != NULL &&
|
||||||
|
bw->history != NULL &&
|
||||||
|
bw->history->current != NULL &&
|
||||||
|
!(flags & BW_NAVIGATE_NO_TERMINAL_HISTORY_UPDATE)) {
|
||||||
|
browser_window_history_update(bw, bw->current_content);
|
||||||
|
}
|
||||||
|
|
||||||
/* don't allow massively nested framesets */
|
/* don't allow massively nested framesets */
|
||||||
for (cur = bw; cur->parent; cur = cur->parent) {
|
for (cur = bw; cur->parent; cur = cur->parent) {
|
||||||
depth++;
|
depth++;
|
||||||
|
@ -32,6 +32,7 @@
|
|||||||
#include "utils/utils.h"
|
#include "utils/utils.h"
|
||||||
#include "netsurf/layout.h"
|
#include "netsurf/layout.h"
|
||||||
#include "netsurf/content.h"
|
#include "netsurf/content.h"
|
||||||
|
#include "netsurf/window.h"
|
||||||
#include "content/hlcache.h"
|
#include "content/hlcache.h"
|
||||||
#include "content/urldb.h"
|
#include "content/urldb.h"
|
||||||
#include "netsurf/bitmap.h"
|
#include "netsurf/bitmap.h"
|
||||||
@ -377,6 +378,8 @@ browser_window_history_add(struct browser_window *bw,
|
|||||||
entry->page.url = nsurl_ref(hlcache_handle_get_url(content));
|
entry->page.url = nsurl_ref(hlcache_handle_get_url(content));
|
||||||
entry->page.frag_id = frag_id ? lwc_string_ref(frag_id) : NULL;
|
entry->page.frag_id = frag_id ? lwc_string_ref(frag_id) : NULL;
|
||||||
entry->page.title = title;
|
entry->page.title = title;
|
||||||
|
entry->page.scroll_x = 0.0f;
|
||||||
|
entry->page.scroll_y = 0.0f;
|
||||||
|
|
||||||
/* create thumbnail for localhistory view */
|
/* create thumbnail for localhistory view */
|
||||||
NSLOG(netsurf, DEBUG,
|
NSLOG(netsurf, DEBUG,
|
||||||
@ -424,6 +427,7 @@ nserror browser_window_history_update(struct browser_window *bw,
|
|||||||
{
|
{
|
||||||
struct history *history;
|
struct history *history;
|
||||||
char *title;
|
char *title;
|
||||||
|
int sx, sy;
|
||||||
|
|
||||||
assert(bw != NULL);
|
assert(bw != NULL);
|
||||||
|
|
||||||
@ -442,7 +446,7 @@ nserror browser_window_history_update(struct browser_window *bw,
|
|||||||
if (title == NULL) {
|
if (title == NULL) {
|
||||||
return NSERROR_NOMEM;
|
return NSERROR_NOMEM;
|
||||||
}
|
}
|
||||||
|
NSLOG(netsurf, INFO, "Updating history entry for %s", title);
|
||||||
free(history->current->page.title);
|
free(history->current->page.title);
|
||||||
history->current->page.title = title;
|
history->current->page.title = title;
|
||||||
|
|
||||||
@ -450,10 +454,41 @@ nserror browser_window_history_update(struct browser_window *bw,
|
|||||||
guit->bitmap->render(history->current->page.bitmap, content);
|
guit->bitmap->render(history->current->page.bitmap, content);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (guit->window->get_scroll(bw->window, &sx, &sy)) {
|
||||||
|
/* Successfully got scroll offsets, update the entry */
|
||||||
|
history->current->page.scroll_x = \
|
||||||
|
(float)sx / (float)content_get_width(content);
|
||||||
|
history->current->page.scroll_y = \
|
||||||
|
(float)sy / (float)content_get_height(content);
|
||||||
|
NSLOG(netsurf, INFO, "Updated scroll offsets to %g by %g",
|
||||||
|
history->current->page.scroll_x,
|
||||||
|
history->current->page.scroll_y);
|
||||||
|
}
|
||||||
return NSERROR_OK;
|
return NSERROR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* exported interface documented in desktop/browser_private.h */
|
||||||
|
nserror
|
||||||
|
browser_window_history_get_scroll(struct browser_window *bw,
|
||||||
|
float *sx, float *sy)
|
||||||
|
{
|
||||||
|
struct history *history;
|
||||||
|
|
||||||
|
assert(bw != NULL);
|
||||||
|
|
||||||
|
history = bw->history;
|
||||||
|
|
||||||
|
if (!history ||
|
||||||
|
!history->current ||
|
||||||
|
!history->current->page.bitmap) {
|
||||||
|
return NSERROR_INVALID;
|
||||||
|
}
|
||||||
|
|
||||||
|
*sx = history->current->page.scroll_x;
|
||||||
|
*sy = history->current->page.scroll_y;
|
||||||
|
|
||||||
|
return NSERROR_OK;
|
||||||
|
}
|
||||||
|
|
||||||
/* exported interface documented in desktop/browser_history.h */
|
/* exported interface documented in desktop/browser_history.h */
|
||||||
void browser_window_history_destroy(struct browser_window *bw)
|
void browser_window_history_destroy(struct browser_window *bw)
|
||||||
@ -565,9 +600,11 @@ nserror browser_window_history_go(struct browser_window *bw,
|
|||||||
url, NULL, bw, NULL);
|
url, NULL, bw, NULL);
|
||||||
history->current = current;
|
history->current = current;
|
||||||
} else {
|
} else {
|
||||||
|
browser_window_history_update(bw, bw->current_content);
|
||||||
history->current = entry;
|
history->current = entry;
|
||||||
error = browser_window_navigate(bw, url, NULL,
|
error = browser_window_navigate(bw, url, NULL,
|
||||||
BW_NAVIGATE_NONE, NULL, NULL, NULL);
|
BW_NAVIGATE_NO_TERMINAL_HISTORY_UPDATE,
|
||||||
|
NULL, NULL, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
nsurl_unref(url);
|
nsurl_unref(url);
|
||||||
|
@ -46,6 +46,8 @@ struct history_page {
|
|||||||
lwc_string *frag_id; /** Fragment identifier, or NULL. */
|
lwc_string *frag_id; /** Fragment identifier, or NULL. */
|
||||||
char *title; /**< Page title, never NULL. */
|
char *title; /**< Page title, never NULL. */
|
||||||
struct bitmap *bitmap; /**< Thumbnail bitmap, or NULL. */
|
struct bitmap *bitmap; /**< Thumbnail bitmap, or NULL. */
|
||||||
|
float scroll_x; /**< Scroll X offset when visited */
|
||||||
|
float scroll_y; /**< Scroll Y offset when visited */
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -325,7 +327,7 @@ nserror browser_window_history_add(struct browser_window *bw,
|
|||||||
struct hlcache_handle *content, lwc_string *frag_id);
|
struct hlcache_handle *content, lwc_string *frag_id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the thumbnail for the current entry.
|
* Update the thumbnail and scroll offsets for the current entry.
|
||||||
*
|
*
|
||||||
* \param bw The browser window to update the history within.
|
* \param bw The browser window to update the history within.
|
||||||
* \param content content for current entry
|
* \param content content for current entry
|
||||||
@ -334,6 +336,17 @@ nserror browser_window_history_add(struct browser_window *bw,
|
|||||||
nserror browser_window_history_update(struct browser_window *bw,
|
nserror browser_window_history_update(struct browser_window *bw,
|
||||||
struct hlcache_handle *content);
|
struct hlcache_handle *content);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve the stored scroll offsets for the current history entry
|
||||||
|
*
|
||||||
|
* \param bw The browser window to retrieve scroll offsets for.
|
||||||
|
* \param sx Pointer to a float for the X scroll offset
|
||||||
|
* \param sy Pointer to a float for the Y scroll offset
|
||||||
|
* \return NSERROR_OK or error code on failure.
|
||||||
|
*/
|
||||||
|
nserror browser_window_history_get_scroll(struct browser_window *bw,
|
||||||
|
float *sx, float *sy);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Free a history structure.
|
* Free a history structure.
|
||||||
*
|
*
|
||||||
|
@ -116,7 +116,10 @@ enum browser_window_nav_flags {
|
|||||||
* A transaction is unverifiable if the user does not
|
* A transaction is unverifiable if the user does not
|
||||||
* have that option.
|
* have that option.
|
||||||
*/
|
*/
|
||||||
BW_NAVIGATE_UNVERIFIABLE = (1 << 2)
|
BW_NAVIGATE_UNVERIFIABLE = (1 << 2),
|
||||||
|
|
||||||
|
/** suppress initial history updates (used by back/fwd/etc) */
|
||||||
|
BW_NAVIGATE_NO_TERMINAL_HISTORY_UPDATE = (1 << 3)
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user