From 3afd9c97310d58c0c6588d18887244328590731e Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Tue, 7 May 2013 14:41:40 +0100 Subject: 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. --- render/html_interaction.c | 76 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 75 insertions(+), 1 deletion(-) (limited to 'render/html_interaction.c') 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 */ @@ -1004,6 +1005,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. */ -- cgit v1.2.3