summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Sanders <vince@kyllikki.org>2017-06-10 17:34:05 (GMT)
committer Vincent Sanders <vince@kyllikki.org>2017-06-10 17:37:21 (GMT)
commit653ccb78a9d819d21dc8d3e6d57d724215f50605 (patch)
tree0490bc5d0e85dafdc59949a1f65f6724a5217029
parent92ecc77768dc86ed6a8d2d9aa1b0f49567878b2c (diff)
downloadnetsurf-653ccb78a9d819d21dc8d3e6d57d724215f50605.tar.gz
netsurf-653ccb78a9d819d21dc8d3e6d57d724215f50605.tar.bz2
Split local history data from viewer in headers
This separates the local history data object API from the viewing API. It also changes the api to return nsurl references instead of strings.
-rw-r--r--desktop/browser_history.c15
-rw-r--r--desktop/browser_history.h130
-rw-r--r--desktop/browser_private.h51
-rw-r--r--desktop/local_history.c5
-rw-r--r--desktop/local_history.h100
-rwxr-xr-xfrontends/amiga/history_local.c27
-rw-r--r--frontends/riscos/local_history.c11
7 files changed, 192 insertions, 147 deletions
diff --git a/desktop/browser_history.c b/desktop/browser_history.c
index df95aa6..71fc974 100644
--- a/desktop/browser_history.c
+++ b/desktop/browser_history.c
@@ -41,6 +41,7 @@
#include "desktop/gui_internal.h"
#include "desktop/browser_history.h"
#include "desktop/browser_private.h"
+#include "desktop/local_history.h"
#define WIDTH 100
#define HEIGHT 86
@@ -811,7 +812,7 @@ bool browser_window_history_click(struct browser_window *bw,
/* exported interface documented in desktop/browser_history.h */
-const char *browser_window_history_position_url(struct browser_window *bw,
+nsurl *browser_window_history_position_url(struct browser_window *bw,
int x, int y)
{
struct history_entry *entry;
@@ -821,10 +822,11 @@ const char *browser_window_history_position_url(struct browser_window *bw,
history = bw->history;
entry = browser_window_history__find_position(history->start, x, y);
- if (!entry)
- return 0;
+ if (!entry) {
+ return NULL;
+ }
- return nsurl_access(entry->page.url);
+ return nsurl_ref(entry->page.url);
}
@@ -875,10 +877,9 @@ void browser_window_history_enumerate(const struct browser_window *bw,
/* exported interface documented in desktop/browser_history.h */
-const char *browser_window_history_entry_get_url(
- const struct history_entry *entry)
+nsurl *browser_window_history_entry_get_url(const struct history_entry *entry)
{
- return nsurl_access(entry->page.url);
+ return nsurl_ref(entry->page.url);
}
diff --git a/desktop/browser_history.h b/desktop/browser_history.h
index ec625df..9140e2c 100644
--- a/desktop/browser_history.h
+++ b/desktop/browser_history.h
@@ -16,71 +16,27 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-/** \file
- * Browser history tree (interface).
+/**
+ * \file
+ * Interface to browser history operations
+ *
+ * The are operations on a browsing contexts history. These interfaces
+ * allow navigation forward and backwards in the history as well as
+ * enumerating the entries.
+ *
+ * The local history viewing is distinct via corewindow defined in
+ * desktop/local_history.h
*/
-#ifndef _NETSURF_DESKTOP_BROWSER_HISTORY_H_
-#define _NETSURF_DESKTOP_BROWSER_HISTORY_H_
+#ifndef NETSURF_DESKTOP_BROWSER_HISTORY_H
+#define NETSURF_DESKTOP_BROWSER_HISTORY_H
#include <stdbool.h>
-#include <libwapcaplet/libwapcaplet.h>
#include "utils/errors.h"
-struct hlcache_handle;
struct browser_window;
struct history_entry;
-struct redraw_context;
-
-/**
- * Create a new history tree for a browser window window.
- *
- * \param bw browser window to create history for.
- *
- * \return NSERROR_OK or appropriate error otherwise
- */
-nserror browser_window_history_create(struct browser_window *bw);
-
-/**
- * Clone a bw's history tree for new bw
- *
- * \param existing browser window with history to clone.
- * \param clone browser window to make cloned history for.
- *
- * \return NSERROR_OK or appropriate error otherwise
- */
-nserror browser_window_history_clone(const struct browser_window *existing,
- struct browser_window *clone);
-/**
- * Insert a url into the history tree.
- *
- * \param bw browser window with history object
- * \param content content to add to history
- * \param frag_id fragment identifier, or NULL.
- * \return NSERROR_OK or error code on faliure.
- *
- * The page is added after the current entry and becomes current.
- */
-nserror browser_window_history_add(struct browser_window *bw,
- struct hlcache_handle *content, lwc_string *frag_id);
-
-/**
- * Update the thumbnail for the current entry.
- *
- * \param bw The browser window to update the history within.
- * \param content content for current entry
- * \return NSERROR_OK or error code on faliure.
- */
-nserror browser_window_history_update(struct browser_window *bw,
- struct hlcache_handle *content);
-
-/**
- * Free a history structure.
- *
- * \param bw The browser window to destroy the history within.
- */
-void browser_window_history_destroy(struct browser_window *bw);
/**
* Go back in the history.
@@ -91,6 +47,7 @@ void browser_window_history_destroy(struct browser_window *bw);
*/
nserror browser_window_history_back(struct browser_window *bw, bool new_window);
+
/**
* Go forward in the history.
*
@@ -100,6 +57,7 @@ nserror browser_window_history_back(struct browser_window *bw, bool new_window);
*/
nserror browser_window_history_forward(struct browser_window *bw, bool new_window);
+
/**
* Check whether it is pssible to go back in the history.
*
@@ -108,6 +66,7 @@ nserror browser_window_history_forward(struct browser_window *bw, bool new_windo
*/
bool browser_window_history_back_available(struct browser_window *bw);
+
/**
* Check whether it is pssible to go forwards in the history.
*
@@ -116,51 +75,6 @@ bool browser_window_history_back_available(struct browser_window *bw);
*/
bool browser_window_history_forward_available(struct browser_window *bw);
-/**
- * Get the dimensions of a history.
- *
- * \param bw browser window with history object.
- * \param width updated to width
- * \param height updated to height
- */
-void browser_window_history_size(struct browser_window *bw,
- int *width, int *height);
-
-/**
- * Redraw part of a history area.
- *
- * \param bw browser window with history object.
- * \param clip redraw area
- * \param x start X co-ordinate on plot canvas
- * \param y start Y co-ordinate on plot canvas
- * \param ctx current redraw context
- */
-bool browser_window_history_redraw_rectangle(struct browser_window *bw,
- struct rect *clip, int x, int y,
- const struct redraw_context *ctx);
-
-/**
- * Handle a mouse click in a history.
- *
- * \param bw browser window containing history
- * \param x click coordinate
- * \param y click coordinate
- * \param new_window open a new window instead of using bw
- * \return true if action was taken, false if click was not on an entry
- */
-bool browser_window_history_click(struct browser_window *bw,
- int x, int y, bool new_window);
-
-/**
- * Determine the URL of the entry at a position.
- *
- * \param bw browser window containing history
- * \param x x coordinate.
- * \param y y coordinate.
- * \return URL, or 0 if no entry at (x, y)
- */
-const char *browser_window_history_position_url(struct browser_window *bw,
- int x, int y);
/**
* Callback function type for history enumeration
@@ -175,6 +89,7 @@ typedef bool (*browser_window_history_enumerate_cb)(
int x0, int y0, int x1, int y1,
const struct history_entry *entry, void *user_data);
+
/**
* Enumerate all entries in the history.
* Do not change the history while it is being enumerated.
@@ -186,6 +101,7 @@ typedef bool (*browser_window_history_enumerate_cb)(
void browser_window_history_enumerate(const struct browser_window *bw,
browser_window_history_enumerate_cb cb, void *user_data);
+
/**
* Enumerate all entries that will be reached by the 'forward' button
*
@@ -196,6 +112,7 @@ void browser_window_history_enumerate(const struct browser_window *bw,
void browser_window_history_enumerate_forward(const struct browser_window *bw,
browser_window_history_enumerate_cb cb, void *user_data);
+
/**
* Enumerate all entries that will be reached by the 'back' button
*
@@ -206,14 +123,15 @@ void browser_window_history_enumerate_forward(const struct browser_window *bw,
void browser_window_history_enumerate_back(const struct browser_window *bw,
browser_window_history_enumerate_cb cb, void *user_data);
+
/**
* Returns the URL to a history entry
*
- * \param entry the history entry to retrieve the URL from
- * \return the URL
+ * \param entry the history entry to retrieve the URL from
+ * \return A referenced nsurl URL
*/
-const char *browser_window_history_entry_get_url(
- const struct history_entry *entry);
+struct nsurl *browser_window_history_entry_get_url(const struct history_entry *entry);
+
/**
* Returns the URL to a history entry
@@ -224,6 +142,7 @@ const char *browser_window_history_entry_get_url(
const char *browser_window_history_entry_get_fragment_id(
const struct history_entry *entry);
+
/**
* Returns the title of a history entry
*
@@ -233,6 +152,7 @@ const char *browser_window_history_entry_get_fragment_id(
const char *browser_window_history_entry_get_title(
const struct history_entry *entry);
+
/**
* Navigate to specified history entry, optionally in new window
*
diff --git a/desktop/browser_private.h b/desktop/browser_private.h
index 5a53e2f..a54393f 100644
--- a/desktop/browser_private.h
+++ b/desktop/browser_private.h
@@ -249,4 +249,55 @@ void browser_window_set_status(struct browser_window *bw, const char *text);
*/
struct browser_window * browser_window_get_root(struct browser_window *bw);
+
+/**
+ * Create a new history tree for a browser window window.
+ *
+ * \param bw browser window to create history for.
+ *
+ * \return NSERROR_OK or appropriate error otherwise
+ */
+nserror browser_window_history_create(struct browser_window *bw);
+
+/**
+ * Clone a bw's history tree for new bw
+ *
+ * \param existing browser window with history to clone.
+ * \param clone browser window to make cloned history for.
+ *
+ * \return NSERROR_OK or appropriate error otherwise
+ */
+nserror browser_window_history_clone(const struct browser_window *existing,
+ struct browser_window *clone);
+/**
+ * Insert a url into the history tree.
+ *
+ * \param bw browser window with history object
+ * \param content content to add to history
+ * \param frag_id fragment identifier, or NULL.
+ * \return NSERROR_OK or error code on faliure.
+ *
+ * The page is added after the current entry and becomes current.
+ */
+nserror browser_window_history_add(struct browser_window *bw,
+ struct hlcache_handle *content, lwc_string *frag_id);
+
+/**
+ * Update the thumbnail for the current entry.
+ *
+ * \param bw The browser window to update the history within.
+ * \param content content for current entry
+ * \return NSERROR_OK or error code on faliure.
+ */
+nserror browser_window_history_update(struct browser_window *bw,
+ struct hlcache_handle *content);
+
+/**
+ * Free a history structure.
+ *
+ * \param bw The browser window to destroy the history within.
+ */
+void browser_window_history_destroy(struct browser_window *bw);
+
+
#endif
diff --git a/desktop/local_history.c b/desktop/local_history.c
index d7022d7..ffe01e0 100644
--- a/desktop/local_history.c
+++ b/desktop/local_history.c
@@ -24,6 +24,7 @@
#include <stdlib.h>
#include "utils/errors.h"
+#include "utils/nsurl.h"
#include "netsurf/types.h"
#include "netsurf/core_window.h"
@@ -143,9 +144,9 @@ local_history_get_size(struct local_history_session *session,
nserror
local_history_get_url(struct local_history_session *session,
int x, int y,
- const char **url_out)
+ nsurl **url_out)
{
- const char *url;
+ nsurl *url;
url = browser_window_history_position_url(session->bw, x, y);
if (url == NULL) {
return NSERROR_NOT_FOUND;
diff --git a/desktop/local_history.h b/desktop/local_history.h
index 2ce2a5c..9bfe0f2 100644
--- a/desktop/local_history.h
+++ b/desktop/local_history.h
@@ -35,14 +35,15 @@ struct browser_window;
/**
* Initialise the local history.
*
- * This iterates through the URL database, generating the local history data,
- * and creates a treeview.
+ * This iterates through the history object of a browser window and
+ * creates tree of visited pages with thumbnails which may be selected
+ * to cause navigation.
*
* This must be called before any other local_history_* function.
*
- * \param cw_t Callback table for core_window containing the treeview.
- * \param core_window_handle The core_window in which the treeview is shown.
- * \param bw browser window to show history of.
+ * \param[in] cw_t Callback table for core_window containing the treeview.
+ * \param[in] core_window_handle The core_window in which the treeview is shown.
+ * \param[in] bw browser window to show history of.
* \param[out] session The created local history session context.
* \return NSERROR_OK on success and session set, appropriate error code otherwise
*/
@@ -54,12 +55,12 @@ nserror local_history_init(struct core_window_callback_table *cw_t,
/**
* Finalise the local history.
*
- * This destroys the local history treeview and the local history module's
- * internal data. After calling this if ocall history is required again,
- * local_history_init must be called.
+ * This destroys the local history view and the local history module's
+ * internal data. After calling this if local history is required again,
+ * local_history_init must be called to create a new session.
*
* \param session The local history session to finalise.
- * \return NSERROR_OK on success, appropriate error otherwise
+ * \return NSERROR_OK on success and session freed appropriate error otherwise
*/
nserror local_history_fini(struct local_history_session *session);
@@ -67,42 +68,49 @@ nserror local_history_fini(struct local_history_session *session);
/**
* Redraw the local history.
*
- * \param session The local history session context.
- * \param x X coordinate to render history at
- * \param y Y coordinate to render history at
- * \param clip Current clip rectangle (wrt tree origin)
- * \param ctx Current redraw context
+ * Causes the local history viewer to issue plot operations to redraw
+ * the specified area of the viewport.
+ *
+ * \param[in] session The local history session context.
+ * \param[in] x X coordinate to render history at
+ * \param[in] y Y coordinate to render history at
+ * \param[in] clip Current clip rectangle (wrt tree origin)
+ * \param[in] ctx Current redraw context
*/
nserror local_history_redraw(struct local_history_session *session, int x, int y, struct rect *clip, const struct redraw_context *ctx);
+
/**
* Handles all kinds of mouse action
*
- * \param session The local history session context.
- * \param mouse The current mouse state
- * \param x X coordinate
- * \param y Y coordinate
+ * \param[in] session The local history session context.
+ * \param[in] mouse The current mouse state
+ * \param[in] x The current mouse X coordinate
+ * \param[in] y The current mouse Y coordinate
*/
void local_history_mouse_action(struct local_history_session *session, enum browser_mouse_state mouse, int x, int y);
+
/**
* Key press handling.
*
- * \param session The local history session context.
- * \param key The ucs4 character codepoint
+ * \param[in] session The local history session context.
+ * \param[in] key The ucs4 character codepoint
* \return true if the keypress is dealt with, false otherwise.
*/
bool local_history_keypress(struct local_history_session *session, uint32_t key);
+
/**
* Change the browser window to draw local history for.
*
- * \param session The local history session context.
+ * \param[in] session The local history session context.
* \param bw browser window to show history of.
* \return NSERROR_OK or appropriate error code.
*/
nserror local_history_set(struct local_history_session *session, struct browser_window *bw);
+
/**
* get size of local history content area.
*
@@ -113,6 +121,7 @@ nserror local_history_set(struct local_history_session *session, struct browser_
*/
nserror local_history_get_size(struct local_history_session *session, int *width, int *height);
+
/**
* get url of entry at position in local history content area.
*
@@ -121,10 +130,55 @@ nserror local_history_get_size(struct local_history_session *session, int *width
* \param[in] session The local history session context.
* \param[in] x The x coordinate to get url of.
* \param[in] y The y coordinate to get url of.
- * \param[out] url_out string representation of the url at the coordinates.
+ * \param[out] url_out referenced url.
* \return NSERROR_OK and url_out updated or NSERROR_NOT_FOUND if no url at
* location.
*/
-nserror local_history_get_url(struct local_history_session *session, int x, int y, const char **url_out);
+nserror local_history_get_url(struct local_history_session *session, int x, int y, struct nsurl **url_out);
+
+
+/* depricated local history viewing interfaces */
+
+/**
+ * Get the dimensions of a history.
+ *
+ * \param bw browser window with history object.
+ * \param width updated to width
+ * \param height updated to height
+ */
+void browser_window_history_size(struct browser_window *bw, int *width, int *height);
+
+/**
+ * Redraw part of a history area.
+ *
+ * \param bw browser window with history object.
+ * \param clip redraw area
+ * \param x start X co-ordinate on plot canvas
+ * \param y start Y co-ordinate on plot canvas
+ * \param ctx current redraw context
+ */
+bool browser_window_history_redraw_rectangle(struct browser_window *bw, struct rect *clip, int x, int y, const struct redraw_context *ctx);
+
+/**
+ * Handle a mouse click in a history.
+ *
+ * \param bw browser window containing history
+ * \param x click coordinate
+ * \param y click coordinate
+ * \param new_window open a new window instead of using bw
+ * \return true if action was taken, false if click was not on an entry
+ */
+bool browser_window_history_click(struct browser_window *bw, int x, int y, bool new_window);
+
+/**
+ * Determine the URL of the entry at a position.
+ *
+ * \param bw browser window containing history
+ * \param x x coordinate.
+ * \param y y coordinate.
+ * \return nsurl at position or NULL if no entry.
+ */
+struct nsurl *browser_window_history_position_url(struct browser_window *bw, int x, int y);
+
#endif
diff --git a/frontends/amiga/history_local.c b/frontends/amiga/history_local.c
index 8d1f4ac..84f6561 100755
--- a/frontends/amiga/history_local.c
+++ b/frontends/amiga/history_local.c
@@ -44,7 +44,8 @@
#include "utils/log.h"
#include "utils/utils.h"
#include "utils/messages.h"
-#include "desktop/browser_history.h"
+#include "utils/nsurl.h"
+#include "desktop/local_history.h"
#include "netsurf/browser_window.h"
#include "netsurf/plotters.h"
#include "netsurf/window.h"
@@ -252,7 +253,7 @@ static BOOL ami_history_event(void *w)
struct history_window *hw = (struct history_window *)w;
ULONG result = 0;
uint16 code;
- const char *url;
+ nsurl *url = NULL;
struct IBox *bbox;
ULONG xs, ys;
@@ -287,10 +288,24 @@ static BOOL ami_history_event(void *w)
ami_gui_free_space_box(bbox);
- RefreshSetGadgetAttrs((APTR)hw->objects[GID_BROWSER],
- hw->win, NULL,
- GA_HintInfo, url,
- TAG_DONE);
+ if (url == NULL) {
+ RefreshSetGadgetAttrs(
+ (APTR)hw->objects[GID_BROWSER],
+ hw->win,
+ NULL,
+ GA_HintInfo,
+ NULL,
+ TAG_DONE);
+ } else {
+ RefreshSetGadgetAttrs(
+ (APTR)hw->objects[GID_BROWSER],
+ hw->win,
+ NULL,
+ GA_HintInfo,
+ nsurl_access(url),
+ TAG_DONE);
+ nsurl_unref(url);
+ }
break;
case WMHI_NEWSIZE:
diff --git a/frontends/riscos/local_history.c b/frontends/riscos/local_history.c
index 1ad63e0..1ae98ff 100644
--- a/frontends/riscos/local_history.c
+++ b/frontends/riscos/local_history.c
@@ -28,6 +28,7 @@
#include "utils/nsoption.h"
#include "utils/messages.h"
#include "utils/log.h"
+#include "utils/nsurl.h"
#include "netsurf/window.h"
#include "netsurf/plotters.h"
#include "netsurf/keypress.h"
@@ -127,7 +128,7 @@ static nserror
ro_local_history_tooltip(struct ro_local_history_window *lhw, int x, int y)
{
int width;
- const char *url;
+ nsurl *url;
wimp_window_state state;
wimp_icon_state ic;
os_box box = {0, 0, 0, 0};
@@ -162,17 +163,19 @@ ro_local_history_tooltip(struct ro_local_history_window *lhw, int x, int y)
}
/* get width of string */
- error = xwimptextop_string_width(url,
- strlen(url) > 256 ? 256 : strlen(url),
+ error = xwimptextop_string_width(nsurl_access(url),
+ nsurl_length(url) > 256 ? 256 : nsurl_length(url),
&width);
if (error) {
LOG("xwimptextop_string_width: 0x%x: %s",
error->errnum, error->errmess);
ro_warn_user("WimpError", error->errmess);
+ nsurl_unref(url);
return NSERROR_NOMEM;
}
- ro_gui_set_icon_string(dialog_tooltip, 0, url, true);
+ ro_gui_set_icon_string(dialog_tooltip, 0, nsurl_access(url), true);
+ nsurl_unref(url);
/* resize icon appropriately */
ic.w = dialog_tooltip;