summaryrefslogtreecommitdiff
path: root/render
diff options
context:
space:
mode:
authorMichael Drake <tlsa@netsurf-browser.org>2013-05-07 14:41:40 +0100
committerMichael Drake <tlsa@netsurf-browser.org>2013-05-07 14:41:40 +0100
commit3afd9c97310d58c0c6588d18887244328590731e (patch)
tree133917633f801613e8742d8b313faee3c4f47e71 /render
parent0647d69a8b8663fcc09af118dde6b256624fe232 (diff)
downloadnetsurf-3afd9c97310d58c0c6588d18887244328590731e.tar.gz
netsurf-3afd9c97310d58c0c6588d18887244328590731e.tar.bz2
Remove search context from browser window, simplify search interface for front ends.
Added content interface for search. Removed bw->cur_search search context. Desktop layer now does nothing except pass search requests from front end onto the bw's current_content via the content interface. Search API reduced to a pair of functions at each level: {desktop|content|html|textplain}_search and {desktop|content|html|textplain}_search_clear Updated front ends to use simplified search API. Only tested GTK and RO builds. These confine the search stuff to render/. However search still uses struct selection. The handling for which is still spread over desktop/ and render/. Also the render/search code itself still fiddles inside html and textplain privates.
Diffstat (limited to 'render')
-rw-r--r--render/html.c34
-rw-r--r--render/html_interaction.c76
-rw-r--r--render/html_internal.h8
-rw-r--r--render/search.c111
-rw-r--r--render/search.h25
-rw-r--r--render/textplain.c113
-rw-r--r--render/textplain.h1
7 files changed, 213 insertions, 155 deletions
diff --git a/render/html.c b/render/html.c
index 1ff1c7cc7..364083bae 100644
--- a/render/html.c
+++ b/render/html.c
@@ -330,6 +330,8 @@ html_create_html_data(html_content *c, const http_parameter *params)
c->selection_owner.none = true;
c->focus_type = HTML_FOCUS_SELF;
c->focus_owner.self = true;
+ c->search = NULL;
+ c->search_string = NULL;
c->scripts_count = 0;
c->scripts = NULL;
c->jscontext = NULL;
@@ -2006,36 +2008,6 @@ static void html_debug_dump(struct content *c, FILE *f)
}
-/**
- * Set an HTML content's search context
- *
- * \param c content of type html
- * \param s search context, or NULL if none
- */
-
-void html_set_search(struct content *c, struct search_context *s)
-{
- html_content *html = (html_content *) c;
-
- html->search = s;
-}
-
-
-/**
- * Return an HTML content's search context
- *
- * \param c content of type html
- * \return content's search context, or NULL if none
- */
-
-struct search_context *html_get_search(struct content *c)
-{
- html_content *html = (html_content *) c;
-
- return html->search;
-}
-
-
#if ALWAYS_DUMP_FRAMESET
/**
* Print a frameset tree to stderr.
@@ -2276,6 +2248,8 @@ static const content_handler html_content_handler = {
.get_contextual_content = html_get_contextual_content,
.scroll_at_point = html_scroll_at_point,
.drop_file_at_point = html_drop_file_at_point,
+ .search = html_search,
+ .search_clear = html_search_clear,
.debug_dump = html_debug_dump,
.clone = html_clone,
.type = html_content_type,
diff --git a/render/html_interaction.c b/render/html_interaction.c
index 0dc36472d..7c3de2a01 100644
--- a/render/html_interaction.c
+++ b/render/html_interaction.c
@@ -43,6 +43,7 @@
#include "render/form.h"
#include "render/html_internal.h"
#include "render/imagemap.h"
+#include "render/search.h"
#include "javascript/js.h"
#include "utils/messages.h"
#include "utils/utils.h"
@@ -952,7 +953,7 @@ void html_mouse_action(struct content *c, struct browser_window *bw,
/**
* Handle keypresses.
*
- * \param c content of type CONTENT_TEXTPLAIN
+ * \param c content of type HTML
* \param key The UCS4 character codepoint
* \return true if key handled, false otherwise
*/
@@ -1005,6 +1006,79 @@ bool html_keypress(struct content *c, uint32_t key)
/**
+ * Handle search.
+ *
+ * \param c content of type HTML
+ * \param gui_callbacks vtable for updating front end
+ * \param gui_data front end private data
+ * \param flags search flags
+ * \param string search string
+ */
+void html_search(struct content *c,
+ struct gui_search_callbacks *gui_callbacks, void *gui_data,
+ search_flags_t flags, const char *string)
+{
+ html_content *html = (html_content *)c;
+
+ assert(c != NULL);
+
+ if (string != NULL && html->search_string != NULL &&
+ strcmp(string, html->search_string) == 0 &&
+ html->search != NULL) {
+ /* Continue prev. search */
+ search_step(html->search, flags, string);
+
+ } else if (string != NULL) {
+ /* New search */
+ free(html->search_string);
+ html->search_string = strdup(string);
+ if (html->search_string == NULL)
+ return;
+
+ if (html->search != NULL) {
+ search_destroy_context(html->search);
+ html->search = NULL;
+ }
+
+ html->search = search_create_context(c, CONTENT_HTML,
+ gui_callbacks, gui_data);
+
+ if (html->search == NULL)
+ return;
+
+ search_step(html->search, flags, string);
+
+ } else {
+ /* Clear search */
+ html_search_clear(c);
+
+ free(html->search_string);
+ html->search_string = NULL;
+ }
+}
+
+
+/**
+ * Terminate a search.
+ *
+ * \param c content of type HTML
+ */
+void html_search_clear(struct content *c)
+{
+ html_content *html = (html_content *)c;
+
+ assert(c != NULL);
+
+ free(html->search_string);
+ html->search_string = NULL;
+
+ if (html->search != NULL)
+ search_destroy_context(html->search);
+ html->search = NULL;
+}
+
+
+/**
* Callback for in-page scrollbars.
*/
void html_overflow_scroll_callback(void *client_data,
diff --git a/render/html_internal.h b/render/html_internal.h
index a78dc8f8a..b491f197a 100644
--- a/render/html_internal.h
+++ b/render/html_internal.h
@@ -161,6 +161,8 @@ typedef struct html_content {
/** Context for free text search, or NULL if none */
struct search_context *search;
+ /** Search string or NULL */
+ char *search_string;
} html_content;
@@ -210,8 +212,6 @@ void html_set_focus(html_content *html, html_focus_type focus_type,
struct browser_window *html_get_browser_window(struct content *c);
-struct search_context *html_get_search(struct content *c);
-void html_set_search(struct content *c, struct search_context *s);
/**
* Complete conversion of an HTML document
@@ -247,6 +247,10 @@ void html_mouse_action(struct content *c, struct browser_window *bw,
bool html_keypress(struct content *c, uint32_t key);
void html_overflow_scroll_callback(void *client_data,
struct scrollbar_msg_data *scrollbar_data);
+void html_search(struct content *c,
+ struct gui_search_callbacks *gui_callbacks, void *gui_data,
+ search_flags_t flags, const char *string);
+void html_search_clear(struct content *c);
/* in render/html_script.c */
diff --git a/render/search.c b/render/search.c
index 617d7ebcf..895cff0a1 100644
--- a/render/search.c
+++ b/render/search.c
@@ -63,7 +63,8 @@ struct list_entry {
};
struct search_context {
- struct search_callbacks callbacks;
+ struct gui_search_callbacks *gui;
+ void *gui_p;
struct content *c;
struct list_entry *found;
struct list_entry *current; /* first for select all */
@@ -75,18 +76,14 @@ struct search_context {
/* Exported function documented in search.h */
-struct search_context * search_create_context(hlcache_handle *h,
- struct search_callbacks callbacks)
+struct search_context * search_create_context(struct content *c,
+ content_type type, struct gui_search_callbacks *callbacks,
+ void *gui_data)
{
struct search_context *context;
struct list_entry *search_head;
- struct content *c = hlcache_handle_get_content(h);
- if (h == NULL)
- return NULL;
-
- if (content_get_type(h) != CONTENT_HTML &&
- content_get_type(h) != CONTENT_TEXTPLAIN) {
+ if (type != CONTENT_HTML && type != CONTENT_TEXTPLAIN) {
return NULL;
}
@@ -117,14 +114,9 @@ struct search_context * search_create_context(hlcache_handle *h,
context->prev_case_sens = false;
context->newsearch = true;
context->c = c;
- context->is_html = (content_get_type(h) == CONTENT_HTML) ? true : false;
- context->callbacks = callbacks;
-
- if (context->is_html) {
- html_set_search(context->c, context);
- } else {
- textplain_set_search(context->c, context);
- }
+ context->is_html = (type == CONTENT_HTML) ? true : false;
+ context->gui = callbacks;
+ context->gui_p = gui_data;
return context;
}
@@ -477,10 +469,8 @@ static void search_text(const char *string, int string_len,
context->string[string_len] = '\0';
}
- if ((context->callbacks.gui != NULL) &&
- (context->callbacks.gui->hourglass != NULL))
- context->callbacks.gui->hourglass(true,
- context->callbacks.gui_p);
+ if ((context->gui != NULL) && (context->gui->hourglass != NULL))
+ context->gui->hourglass(true, context->gui_p);
if (context->is_html == true) {
res = find_occurrences_html(string, string_len,
@@ -492,17 +482,14 @@ static void search_text(const char *string, int string_len,
if (!res) {
free_matches(context);
- if ((context->callbacks.gui != NULL) &&
- (context->callbacks.gui->hourglass !=
- NULL))
- context->callbacks.gui->hourglass(false,
- context->callbacks.gui_p);
+ if ((context->gui != NULL) &&
+ (context->gui->hourglass != NULL))
+ context->gui->hourglass(false, context->gui_p);
return;
}
- if ((context->callbacks.gui != NULL) &&
- (context->callbacks.gui->hourglass != NULL))
- context->callbacks.gui->hourglass(false,
- context->callbacks.gui_p);
+ if ((context->gui != NULL) &&
+ (context->gui->hourglass != NULL))
+ context->gui->hourglass(false, context->gui_p);
context->prev_case_sens = case_sensitive;
@@ -521,23 +508,22 @@ static void search_text(const char *string, int string_len,
}
}
- if (context->callbacks.gui == NULL)
+ if (context->gui == NULL)
return;
- if (context->callbacks.gui->status != NULL)
- context->callbacks.gui->status((context->current != NULL),
- context->callbacks.gui_p);
+ if (context->gui->status != NULL)
+ context->gui->status((context->current != NULL),
+ context->gui_p);
search_show_all(showall, context);
- if (context->callbacks.gui->back_state != NULL)
- context->callbacks.gui->back_state((context->current != NULL) &&
+ if (context->gui->back_state != NULL)
+ context->gui->back_state((context->current != NULL) &&
(context->current->prev != NULL),
- context->callbacks.gui_p);
- if (context->callbacks.gui->forward_state != NULL)
- context->callbacks.gui->forward_state(
- (context->current != NULL) &&
- (context->current->next != NULL),
- context->callbacks.gui_p);
+ context->gui_p);
+ if (context->gui->forward_state != NULL)
+ context->gui->forward_state((context->current != NULL) &&
+ (context->current->next != NULL),
+ context->gui_p);
if (context->current == NULL)
return;
@@ -572,14 +558,13 @@ void search_step(struct search_context *context, search_flags_t flags,
int string_len;
int i = 0;
- if ((context == NULL) || (context->callbacks.gui == NULL)) {
+ if ((context == NULL) || (context->gui == NULL)) {
warn_user("SearchError", 0);
return;
}
- if (context->callbacks.gui->add_recent != NULL)
- context->callbacks.gui->add_recent(string,
- context->callbacks.gui_p);
+ if (context->gui->add_recent != NULL)
+ context->gui->add_recent(string, context->gui_p);
string_len = strlen(string);
for (i = 0; i < string_len; i++)
@@ -588,15 +573,12 @@ void search_step(struct search_context *context, search_flags_t flags,
if (i >= string_len) {
union content_msg_data msg_data;
free_matches(context);
- if (context->callbacks.gui->status != NULL)
- context->callbacks.gui->status(true,
- context->callbacks.gui_p);
- if (context->callbacks.gui->back_state != NULL)
- context->callbacks.gui->back_state(false,
- context->callbacks.gui_p);
- if (context->callbacks.gui->forward_state != NULL)
- context->callbacks.gui->forward_state(false,
- context->callbacks.gui_p);
+ if (context->gui->status != NULL)
+ context->gui->status(true, context->gui_p);
+ if (context->gui->back_state != NULL)
+ context->gui->back_state(false, context->gui_p);
+ if (context->gui->forward_state != NULL)
+ context->gui->forward_state(false, context->gui_p);
msg_data.scroll.area = false;
msg_data.scroll.x0 = 0;
@@ -672,22 +654,9 @@ void search_destroy_context(struct search_context *context)
{
assert(context != NULL);
- if (context->callbacks.invalidate != NULL) {
- context->callbacks.invalidate(context, context->callbacks.p);
- }
-
- if (context->c != NULL) {
-
- if (context->is_html) {
- html_set_search(context->c, NULL);
- } else {
- textplain_set_search(context->c, NULL);
- }
- }
- if ((context->string != NULL) && (context->callbacks.gui != NULL) &&
- (context->callbacks.gui->add_recent != NULL)) {
- context->callbacks.gui->add_recent(context->string,
- context->callbacks.gui_p);
+ if ((context->string != NULL) && (context->gui != NULL) &&
+ (context->gui->add_recent != NULL)) {
+ context->gui->add_recent(context->string, context->gui_p);
free(context->string);
}
free_matches(context);
diff --git a/render/search.h b/render/search.h
index 70da31bca..43c93b3ab 100644
--- a/render/search.h
+++ b/render/search.h
@@ -27,30 +27,17 @@
struct search_context;
/**
- * Called when a search context is destroyed
- * \param context search context being invalidated
- * \param p pointer for client data
- */
-typedef void (*search_invalidate_callback)(struct search_context *context,
- void *p);
-
-struct search_callbacks {
- struct gui_search_callbacks *gui;
- void *gui_p; /* private gui owned data */
- search_invalidate_callback invalidate;
- void *p; /* private client data */
-};
-
-/**
* create a search_context
*
- * \param h the hlcache_handle the search_context is connected to
+ * \param c the content the search_context is connected to
+ * \param type the content type of c
* \param callbacks the callbacks to modify appearance according to results
- * \param p the pointer to send to the callbacks
+ * \param p the pointer to send to the callbacks
* \return true for success
*/
-struct search_context * search_create_context(struct hlcache_handle *h,
- struct search_callbacks callbacks);
+struct search_context * search_create_context(struct content *c,
+ content_type type, struct gui_search_callbacks *callbacks,
+ void *gui_data);
/**
* Ends the search process, invalidating all state
diff --git a/render/textplain.c b/render/textplain.c
index b9d0b81e5..89628f914 100644
--- a/render/textplain.c
+++ b/render/textplain.c
@@ -45,6 +45,7 @@
#include "render/search.h"
#include "render/textplain.h"
#include "render/html.h"
+#include "render/search.h"
#include "utils/http.h"
#include "utils/log.h"
#include "utils/messages.h"
@@ -73,6 +74,8 @@ typedef struct textplain_content {
/** Context for free text search, or NULL if none */
struct search_context *search;
+ /** Current search string, or NULL if none */
+ char *search_string;
} textplain_content;
@@ -109,6 +112,10 @@ static void textplain_mouse_track(struct content *c, struct browser_window *bw,
static void textplain_mouse_action(struct content *c, struct browser_window *bw,
browser_mouse_state mouse, int x, int y);
static bool textplain_keypress(struct content *c, uint32_t key);
+static void textplain_search(struct content *c,
+ struct gui_search_callbacks *gui_callbacks, void *gui_data,
+ search_flags_t flags, const char *string);
+static void textplain_search_clear(struct content *c);
static void textplain_reformat(struct content *c, int width, int height);
static void textplain_destroy(struct content *c);
static bool textplain_redraw(struct content *c, struct content_redraw_data *data,
@@ -117,7 +124,6 @@ static void textplain_open(struct content *c, struct browser_window *bw,
struct content *page, struct object_params *params);
void textplain_close(struct content *c);
char *textplain_get_selection(struct content *c);
-struct search_context *textplain_get_search(struct content *c);
static nserror textplain_clone(const struct content *old,
struct content **newc);
static content_type textplain_content_type(void);
@@ -142,6 +148,8 @@ static const content_handler textplain_content_handler = {
.mouse_track = textplain_mouse_track,
.mouse_action = textplain_mouse_action,
.keypress = textplain_keypress,
+ .search = textplain_search,
+ .search_clear = textplain_search_clear,
.redraw = textplain_redraw,
.open = textplain_open,
.close = textplain_close,
@@ -759,6 +767,79 @@ bool textplain_keypress(struct content *c, uint32_t key)
/**
+ * Handle search.
+ *
+ * \param c content of type text
+ * \param gui_callbacks vtable for updating front end
+ * \param gui_data front end private data
+ * \param flags search flags
+ * \param string search string
+ */
+void textplain_search(struct content *c,
+ struct gui_search_callbacks *gui_callbacks, void *gui_data,
+ search_flags_t flags, const char *string)
+{
+ textplain_content *text = (textplain_content *) c;
+
+ assert(c != NULL);
+
+ if (string != NULL && text->search_string != NULL &&
+ strcmp(string, text->search_string) == 0 &&
+ text->search != NULL) {
+ /* Continue prev. search */
+ search_step(text->search, flags, string);
+
+ } else if (string != NULL) {
+ /* New search */
+ free(text->search_string);
+ text->search_string = strdup(string);
+ if (text->search_string == NULL)
+ return;
+
+ if (text->search != NULL) {
+ search_destroy_context(text->search);
+ text->search = NULL;
+ }
+
+ text->search = search_create_context(c, CONTENT_TEXTPLAIN,
+ gui_callbacks, gui_data);
+
+ if (text->search == NULL)
+ return;
+
+ search_step(text->search, flags, string);
+
+ } else {
+ /* Clear search */
+ textplain_search_clear(c);
+
+ free(text->search_string);
+ text->search_string = NULL;
+ }
+}
+
+
+/**
+ * Terminate a search.
+ *
+ * \param c content of type text
+ */
+void textplain_search_clear(struct content *c)
+{
+ textplain_content *text = (textplain_content *) c;
+
+ assert(c != NULL);
+
+ free(text->search_string);
+ text->search_string = NULL;
+
+ if (text->search != NULL)
+ search_destroy_context(text->search);
+ text->search = NULL;
+}
+
+
+/**
* Draw a CONTENT_TEXTPLAIN using the current set of plotters (plot).
*
* \param c content of type CONTENT_TEXTPLAIN
@@ -943,36 +1024,6 @@ char *textplain_get_selection(struct content *c)
return selection_get_copy(&text->sel);
}
-
-/**
- * Set an TEXTPLAIN content's search context
- *
- * \param c content of type text
- * \param s search context, or NULL if none
- */
-
-void textplain_set_search(struct content *c, struct search_context *s)
-{
- textplain_content *text = (textplain_content *) c;
-
- text->search = s;
-}
-
-
-/**
- * Return an TEXTPLAIN content's search context
- *
- * \param c content of type text
- * \return content's search context, or NULL if none
- */
-
-struct search_context *textplain_get_search(struct content *c)
-{
- textplain_content *text = (textplain_content *) c;
-
- return text->search;
-}
-
/**
* Retrieve number of lines in content
*
diff --git a/render/textplain.h b/render/textplain.h
index b7761a20d..c3f2a0f6a 100644
--- a/render/textplain.h
+++ b/render/textplain.h
@@ -47,6 +47,5 @@ int textplain_find_line(struct content *c, unsigned offset);
char *textplain_get_raw_data(struct content *c,
unsigned start, unsigned end, size_t *plen);
struct browser_window *textplain_get_browser_window(struct content *c);
-void textplain_set_search(struct content *c, struct search_context *s);
#endif