I need to enumerate all entries in the local history to correctly
display tool tips in the local history view. And to implement menus on
the back and forward buttons I also need to enumerate the history
entries in the order history_back() and history_forward() go and I
need access to the history_go() function.
Here are my proposed changes to history_core.{c,h}. My new
enumeration API uses a callback, but I could use as well a different
approach using history_entry_first_child() and history_entry_next().
From 6658ace3866e725ceef115c6beb754ea27349851 Mon Sep 17 00:00:00 2001
From: Sven Weidauer <sven.weida...@gmail.com>
Date: Sat, 26 Feb 2011 13:25:35 +0100
Subject: [PATCH] Added function to enumerate entries in the history
tree.
---
desktop/history_core.c | 54 +++++++++++++++++++++++++++++++++++++++
+++++++++
desktop/history_core.h | 10 ++++++++
2 files changed, 64 insertions(+), 0 deletions(-)
diff --git a/desktop/history_core.c b/desktop/history_core.c
index 0449a3d..fc9f292 100644
--- a/desktop/history_core.c
+++ b/desktop/history_core.c
@@ -94,6 +94,8 @@ static bool history_redraw_entry(struct history
*history,
int x, int y, bool clip);
static struct history_entry *history_find_position(struct
history_entry *entry,
int x, int y);
+static bool history_enumerate_entry( struct history *history, struct
history_entry *entry,
+
history_enumerate_cb cb, void *ud );
/**
@@ -766,3 +768,55 @@ struct history_entry
*history_find_position(struct history_entry *entry,
return 0;
}
+
+
+/**
+ * Enumerate all entries in the history.
+ *
+ * \param history history to enumerate
+ * \param cb callback function
+ * \param user_data context pointer passed to cb
+ */
+void history_enumerate( struct history *history, history_enumerate_cb
cb, void *user_data )
+{
+ history_enumerate_entry( history, history->start, cb, user_data );
+}
+
+/**
+ * Enumerate subentries in history
+ *
+ * \param history history to enumerate
+ * \param entry entry to start enumeration at
+ * \param cb callback function
+ * \param ud context pointer passed to cb
+ */
+static bool history_enumerate_entry( struct history *history, struct
history_entry *entry,
+
history_enumerate_cb cb, void *ud )
+{
+ struct history_entry *child;
+
+ if (!cb( history, entry->x, entry->y, entry->x + WIDTH, entry->y +
HEIGHT,
+ entry, ud )) return false;
+
+ for (child = entry->forward; child; child = child->next) {
+ if (!history_enumerate_entry( history, child, cb, ud ))
+ return false;
+ }
+
+ return true;
+}
+
+const char *history_entry_get_url( const struct history_entry *entry )
+{
+ return entry->page.url;
+}
+
+const char *history_entry_get_fragment_id( const struct history_entry
*entry )
+{
+ return entry->page.frag_id;
+}
+
+const char *history_entry_get_title( const struct history_entry
*entry )
+{
+ return entry->page.title;
+}
\ No newline at end of file
diff --git a/desktop/history_core.h b/desktop/history_core.h
index 55b4e0b..50b4172 100644
--- a/desktop/history_core.h
+++ b/desktop/history_core.h
@@ -28,6 +28,7 @@
struct hlcache_handle;
struct history;
struct browser_window;
+struct history_entry;
struct history *history_create(void);
struct history *history_clone(struct history *history);
@@ -47,4 +48,13 @@ bool history_click(struct browser_window *bw,
struct history *history,
int x, int y, bool new_window);
const char *history_position_url(struct history *history, int x, int
y);
+typedef bool (*history_enumerate_cb)( struct history *history, int
x0, int y0, int x1, int y1,
+ const
struct history_entry *entry, void *user_data );
+
+void history_enumerate( struct history *history, history_enumerate_cb
cb, void *user_data );
+
+const char *history_entry_get_url( const struct history_entry *entry );
+const char *history_entry_get_fragment_id( const struct history_entry
*entry );
+const char *history_entry_get_title( const struct history_entry
*entry );
+
#endif
--
1.6.5.1+GitX
From f28906a8bc8d7db56a38be66fe27677d7413da53 Mon Sep 17 00:00:00 2001
From: Sven Weidauer <sven.weida...@gmail.com>
Date: Sun, 27 Feb 2011 12:25:44 +0100
Subject: [PATCH] Publishing 'history_go' function and creating API to
enumerate all history items reachable by the forward or back buttons.
---
desktop/history_core.c | 41 +++++++++++++++++++++++++++++++++++++
+---
desktop/history_core.h | 5 +++++
2 files changed, 43 insertions(+), 3 deletions(-)
diff --git a/desktop/history_core.c b/desktop/history_core.c
index fc9f292..ac34f5c 100644
--- a/desktop/history_core.c
+++ b/desktop/history_core.c
@@ -83,8 +83,6 @@ struct history {
static struct history_entry *history_clone_entry(struct history
*history,
struct history_entry *entry);
static void history_free_entry(struct history_entry *entry);
-static void history_go(struct browser_window *bw, struct history
*history,
- struct history_entry *entry, bool new_window);
static void history_layout(struct history *history);
static int history_layout_subtree(struct history *history,
struct history_entry *entry, int x, int y, bool shuffle);
@@ -769,6 +767,43 @@ struct history_entry
*history_find_position(struct history_entry *entry,
return 0;
}
+/**
+ * Enumerate all entries that will be reached by the 'forward' button
+ *
+ * \param history The history object to enumerate in
+ * \param cb The callback function
+ * \param user_data Data passed to the callback
+ */
+void history_enumerate_forward( struct history *history,
history_enumerate_cb cb, void *user_data )
+{
+ struct history_entry *entry;
+
+ if (history == nil || history->current == nil) return;
+
+ for (entry = history->current->forward_pref; entry != NULL; entry =
entry->forward_pref) {
+ if (!cb( history, entry->x, entry->y, entry->x + WIDTH, entry->y +
HEIGHT, entry, user_data))
+ break;
+ }
+}
+
+/**
+ * Enumerate all entries that will be reached by the 'back' button
+ *
+ * \param history The history object to enumerate in
+ * \param cb The callback function
+ * \param user_data Data passed to the callback
+ */
+void history_enumerate_back( struct history *history,
history_enumerate_cb cb, void *user_data )
+{
+ struct history_entry *entry;
+
+ if (history == nil || history->current == nil) return;
+
+ for (entry = history->current->back; entry != NULL; entry = entry-
>back) {
+ if (!cb( history, entry->x, entry->y, entry->x + WIDTH, entry->y +
HEIGHT, entry, user_data))
+ break;
+ }
+}
/**
* Enumerate all entries in the history.
@@ -819,4 +854,4 @@ const char *history_entry_get_fragment_id( const
struct history_entry *entry )
const char *history_entry_get_title( const struct history_entry
*entry )
{
return entry->page.title;
-}
\ No newline at end of file
+}
diff --git a/desktop/history_core.h b/desktop/history_core.h
index 50b4172..552d39b 100644
--- a/desktop/history_core.h
+++ b/desktop/history_core.h
@@ -52,9 +52,14 @@ typedef bool (*history_enumerate_cb)( struct
history *history, int x0, int y0, i
const
struct history_entry *entry, void *user_data );
void history_enumerate( struct history *history,
history_enumerate_cb cb, void *user_data );
+void history_enumerate_forward( struct history *history,
history_enumerate_cb cb, void *user_data );
+void history_enumerate_back( struct history *history,
history_enumerate_cb cb, void *user_data );
const char *history_entry_get_url( const struct history_entry
*entry );
const char *history_entry_get_fragment_id( const struct
history_entry *entry );
const char *history_entry_get_title( const struct history_entry
*entry );
+void history_go(struct browser_window *bw, struct history *history,
+ struct history_entry *entry, bool new_window);
+
#endif
--
1.6.5.1+GitX