summaryrefslogtreecommitdiff
path: root/desktop
diff options
context:
space:
mode:
authorVincent Sanders <vince@kyllikki.org>2014-03-18 22:32:52 +0000
committerVincent Sanders <vince@kyllikki.org>2014-03-18 22:32:52 +0000
commit4d4d74c8cd1a77a46cbe0816cf6150f8b4980947 (patch)
treecdc747443b58963a17b2844da25c7b2fab9deb99 /desktop
parentfec9f916b640b8ffc18b7ff9f9d04fd742b32ad1 (diff)
downloadnetsurf-4d4d74c8cd1a77a46cbe0816cf6150f8b4980947.tar.gz
netsurf-4d4d74c8cd1a77a46cbe0816cf6150f8b4980947.tar.bz2
move page search gui callbacks to their own operations table
Diffstat (limited to 'desktop')
-rw-r--r--desktop/gui.h54
-rw-r--r--desktop/gui_factory.c68
-rw-r--r--desktop/search.c63
-rw-r--r--desktop/search.h56
4 files changed, 146 insertions, 95 deletions
diff --git a/desktop/gui.h b/desktop/gui.h
index 361c6bdf4..317a73337 100644
--- a/desktop/gui.h
+++ b/desktop/gui.h
@@ -422,6 +422,52 @@ struct gui_utf8_table {
nserror (*local_to_utf8)(const char *string, size_t len, char **result);
};
+/**
+ * function table for page text search.
+ */
+struct gui_search_table {
+ /**
+ * Change the displayed search status.
+ *
+ * \param found search pattern matched in text
+ * \param p gui private data pointer provided with search callbacks
+ */
+ void (*status)(bool found, void *p);
+
+ /**
+ * display hourglass while searching.
+ *
+ * \param active start/stop indicator
+ * \param p gui private data pointer provided with search callbacks
+ */
+ void (*hourglass)(bool active, void *p);
+
+ /**
+ * add search string to recent searches list
+ * front has full liberty how to implement the bare notification;
+ * core gives no guarantee of the integrity of the string
+ *
+ * \param string search pattern
+ * \param p gui private data pointer provided with search callbacks
+ */
+ void (*add_recent)(const char *string, void *p);
+
+ /**
+ * activate search forwards button in gui
+ *
+ * \param active activate/inactivate
+ * \param p gui private data pointer provided with search callbacks
+ */
+ void (*forward_state)(bool active, void *p);
+
+ /**
+ * activate search back button in gui
+ *
+ * \param active activate/inactivate
+ * \param p gui private data pointer provided with search callbacks
+ */
+ void (*back_state)(bool active, void *p);
+};
/**
* Graphical user interface browser misc function table.
@@ -528,6 +574,14 @@ struct gui_table {
* implies the local encoding is utf8.
*/
struct gui_utf8_table *utf8;
+
+ /**
+ *
+ * Page search table.
+ *
+ * Provides routines for the interactive text search on a page.
+ */
+ struct gui_search_table *search;
};
diff --git a/desktop/gui_factory.c b/desktop/gui_factory.c
index 638abfd96..ecedf417b 100644
--- a/desktop/gui_factory.c
+++ b/desktop/gui_factory.c
@@ -343,6 +343,62 @@ static nserror verify_utf8_register(struct gui_utf8_table *gut)
return NSERROR_OK;
}
+static void gui_default_status(bool found, void *p)
+{
+}
+
+static void gui_default_hourglass(bool active, void *p)
+{
+}
+
+static void gui_default_add_recent(const char *string, void *p)
+{
+}
+
+static void gui_default_forward_state(bool active, void *p)
+{
+}
+
+static void gui_default_back_state(bool active, void *p)
+{
+}
+
+static struct gui_search_table default_search_table = {
+ .status = gui_default_status,
+ .hourglass = gui_default_hourglass,
+ .add_recent = gui_default_add_recent,
+ .forward_state = gui_default_forward_state,
+ .back_state = gui_default_back_state,
+};
+
+/** verify search table is valid */
+static nserror verify_search_register(struct gui_search_table *gst)
+{
+ /* check table is present */
+ if (gst == NULL) {
+ return NSERROR_BAD_PARAMETER;
+ }
+
+ /* fill in the optional entries with defaults */
+ if (gst->status == NULL) {
+ gst->status = default_search_table.status;
+ }
+ if (gst->hourglass == NULL) {
+ gst->hourglass = default_search_table.hourglass;
+ }
+ if (gst->add_recent == NULL) {
+ gst->add_recent = default_search_table.add_recent;
+ }
+ if (gst->forward_state == NULL) {
+ gst->forward_state = default_search_table.forward_state;
+ }
+ if (gst->back_state == NULL) {
+ gst->back_state = default_search_table.back_state;
+ }
+
+ return NSERROR_OK;
+}
+
static nsurl *gui_default_get_resource_url(const char *path)
{
return NULL;
@@ -525,7 +581,7 @@ nserror gui_factory_register(struct gui_table *gt)
/* utf8 table */
if (gt->utf8 == NULL) {
- /* set default clipboard table */
+ /* set default utf8 table */
gt->utf8 = &default_utf8_table;
}
err = verify_utf8_register(gt->utf8);
@@ -533,6 +589,16 @@ nserror gui_factory_register(struct gui_table *gt)
return err;
}
+ /* search table */
+ if (gt->search == NULL) {
+ /* set default search table */
+ gt->search = &default_search_table;
+ }
+ err = verify_search_register(gt->search);
+ if (err != NSERROR_OK) {
+ return err;
+ }
+
guit = gt;
return NSERROR_OK;
diff --git a/desktop/search.c b/desktop/search.c
index 4a02f6b7c..201d416dd 100644
--- a/desktop/search.c
+++ b/desktop/search.c
@@ -21,66 +21,27 @@
/** \file
* Free text search (core)
*/
-#include "utils/config.h"
-#include <ctype.h>
-#include <string.h>
-#include <dom/dom.h>
#include "content/content.h"
-#include "content/hlcache.h"
+
#include "desktop/browser_private.h"
-#include "utils/nsoption.h"
#include "desktop/search.h"
-#include "desktop/selection.h"
-#include "render/box.h"
-#include "render/html.h"
-#include "render/search.h"
-#include "render/textplain.h"
-#include "utils/config.h"
-#include "utils/log.h"
-#include "utils/messages.h"
-#include "utils/url.h"
-#include "utils/utils.h"
-
-
-
-/**
- * Starts or continues an existing search.
- *
- * \param bw the browser_window to search
- * \param callbacks callbacks vtable to update frontend according to results
- * \param gui_data a pointer returned to the callbacks
- * \param flags search flags
- * \param string string to search for
- */
-void browser_window_search(struct browser_window *bw,
- struct gui_search_callbacks *gui_callbacks, void *gui_data,
+/* exported function documented in desktop/search.h */
+void browser_window_search(struct browser_window *bw, void *context,
search_flags_t flags, const char *string)
{
- assert(gui_callbacks != NULL);
-
- if (bw == NULL || bw->current_content == NULL)
- return;
-
- content_search(bw->current_content, gui_callbacks, gui_data,
- flags, string);
+ if ((bw != NULL) &&
+ (bw->current_content != NULL)) {
+ content_search(bw->current_content, context, flags, string);
+ }
}
-
-/**
- * Clear up a search. Frees any memory used by the search
- *
- * \param bw the browser_window to search
- * \param callbacks callbacks vtable to update frontend according to results
- * \param gui_data a pointer returned to the callbacks
- * \param flags search flags
- * \param string string to search for
- */
+/* exported function documented in desktop/search.h */
void browser_window_search_clear(struct browser_window *bw)
{
- if (bw == NULL || bw->current_content == NULL)
- return;
-
- content_search_clear(bw->current_content);
+ if ((bw != NULL) &&
+ (bw->current_content != NULL)) {
+ content_search_clear(bw->current_content);
+ }
}
diff --git a/desktop/search.h b/desktop/search.h
index 8440ce982..254acde99 100644
--- a/desktop/search.h
+++ b/desktop/search.h
@@ -33,54 +33,24 @@ typedef enum {
} search_flags_t;
/**
- * Change the displayed search status.
- * \param found search pattern matched in text
- * \param p gui private data pointer provided with search callbacks
- */
-typedef void (*gui_search_status)(bool found, void *p);
-
-/**
- * display hourglass while searching
- * \param active start/stop indicator
- * \param p gui private data pointer provided with search callbacks
- */
-typedef void (*gui_search_hourglass)(bool active, void *p);
-
-/**
- * add search string to recent searches list
- * front has full liberty how to implement the bare notification;
- * core gives no guarantee of the integrity of the const char *
- * \param string search pattern
- * \param p gui private data pointer provided with search callbacks
- */
-typedef void (*gui_search_add_recent)(const char *string, void *p);
-
-/**
- * activate search forwards button in gui
- * \param active activate/inactivate
- * \param p gui private data pointer provided with search callbacks
+ * Starts or continues an existing search.
+ *
+ * \param bw The browser_window to search.
+ * \param context A context pointer passed to the callbacks.
+ * \param flags Flags controlling the search operation.
+ * \param string The string being searched for.
*/
-typedef void (*gui_search_forward_state)(bool active, void *p);
+void browser_window_search(struct browser_window *bw, void *context, search_flags_t flags, const char *string);
/**
- * activate search back button in gui
- * \param active activate/inactivate
- * \param p gui private data pointer provided with search callbacks
+ * Clear up a search.
+ *
+ * Frees any memory used by the search.
+ *
+ * \param bw The browser window to clean up the search for.
+ * \param context A context pointer passed to the callbacks.
*/
-typedef void (*gui_search_back_state)(bool active, void *p);
-
-struct gui_search_callbacks {
- gui_search_forward_state forward_state;
- gui_search_back_state back_state;
- gui_search_status status;
- gui_search_hourglass hourglass;
- gui_search_add_recent add_recent;
-};
-
-void browser_window_search(struct browser_window *bw,
- struct gui_search_callbacks *gui_callbacks, void *gui_data,
- search_flags_t flags, const char *string);
void browser_window_search_clear(struct browser_window *bw);
#endif