diff options
author | Michael Drake <tlsa@netsurf-browser.org> | 2013-05-07 14:41:40 +0100 |
---|---|---|
committer | Michael Drake <tlsa@netsurf-browser.org> | 2013-05-07 14:41:40 +0100 |
commit | 3afd9c97310d58c0c6588d18887244328590731e (patch) | |
tree | 133917633f801613e8742d8b313faee3c4f47e71 /render/textplain.c | |
parent | 0647d69a8b8663fcc09af118dde6b256624fe232 (diff) | |
download | netsurf-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/textplain.c')
-rw-r--r-- | render/textplain.c | 113 |
1 files changed, 82 insertions, 31 deletions
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 * |