From 3c7538a9f906e38e78be0300049f9e49839d7fd7 Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Tue, 12 May 2020 21:09:41 +0100 Subject: hoist common text search out of content handlers --- content/handlers/html/html.c | 8 ---- content/handlers/html/interaction.c | 76 ------------------------------------- content/handlers/html/private.h | 5 --- content/handlers/html/redraw.c | 23 +++++++---- 4 files changed, 15 insertions(+), 97 deletions(-) (limited to 'content/handlers/html') diff --git a/content/handlers/html/html.c b/content/handlers/html/html.c index a3d426461..88098ebee 100644 --- a/content/handlers/html/html.c +++ b/content/handlers/html/html.c @@ -481,8 +481,6 @@ 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->jsthread = NULL; @@ -1326,10 +1324,6 @@ static nserror html_close(struct content *c) selection_clear(&htmlc->sel, false); - if (htmlc->search != NULL) { - content_textsearch_destroy(htmlc->search); - } - /* clear the html content reference to the browser window */ htmlc->bw = NULL; @@ -2204,8 +2198,6 @@ 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, .debug = html_debug, .clone = html_clone, diff --git a/content/handlers/html/interaction.c b/content/handlers/html/interaction.c index 8ae5144c0..f2eae70df 100644 --- a/content/handlers/html/interaction.c +++ b/content/handlers/html/interaction.c @@ -1598,82 +1598,6 @@ bool html_keypress(struct content *c, uint32_t key) } -/** - * Handle search. - * - * \param c content of type HTML - * \param fe_ctx front end private data - * \param flags search flags - * \param string search string - */ -void -html_search(struct content *c, - void *fe_ctx, - search_flags_t flags, - const char *string) -{ - html_content *html = (html_content *)c; - nserror res; - - assert(c != NULL); - - if ((string != NULL) && - (html->search_string != NULL) && - (strcmp(string, html->search_string) == 0) && - (html->search != NULL)) { - /* Continue prev. search */ - content_textsearch_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) { - content_textsearch_destroy(html->search); - html->search = NULL; - } - - res = content_textsearch_create(c, fe_ctx, &html->search); - if (res != NSERROR_OK) { - return; - } - - content_textsearch_step(html->search, flags, string); - - } else { - /* Clear search */ - html_search_clear(c); - - free(html->search_string); - html->search_string = NULL; - } -} - - -/** - * Terminate a text 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) { - content_textsearch_destroy(html->search); - } - html->search = NULL; -} - - /** * Callback for in-page scrollbars. */ diff --git a/content/handlers/html/private.h b/content/handlers/html/private.h index 1367c624c..dde61c2a9 100644 --- a/content/handlers/html/private.h +++ b/content/handlers/html/private.h @@ -210,11 +210,6 @@ typedef struct html_content { */ struct form_control *visible_select_menu; - /** Context for free text search, or NULL if none */ - struct textsearch_context *search; - /** Search string or NULL */ - char *search_string; - } html_content; /** diff --git a/content/handlers/html/redraw.c b/content/handlers/html/redraw.c index f9fb6b4fd..aa99782c7 100644 --- a/content/handlers/html/redraw.c +++ b/content/handlers/html/redraw.c @@ -167,7 +167,6 @@ text_redraw(const char *utf8_text, bool excluded, struct content *c, const struct selection *sel, - struct textsearch_context *search, const struct redraw_context *ctx) { bool highlighted = false; @@ -195,8 +194,8 @@ text_redraw(const char *utf8_text, /* what about the current search operation, if any? */ if (!highlighted && - (search != NULL) && - content_textsearch_ishighlighted(search, + (c->textsearch.context != NULL) && + content_textsearch_ishighlighted(c->textsearch.context, offset, offset + len, &start_idx, @@ -1138,11 +1137,19 @@ static bool html_redraw_text_box(const html_content *html, struct box *box, font_plot_style_from_css(&html->len_ctx, box->style, &fstyle); fstyle.background = current_background_color; - if (!text_redraw(box->text, box->length, box->byte_offset, - box->space, &fstyle, x, y, - clip, box->height, scale, excluded, - (struct content *)html, &html->sel, - html->search, ctx)) + if (!text_redraw(box->text, + box->length, + box->byte_offset, + box->space, + &fstyle, + x, y, + clip, + box->height, + scale, + excluded, + (struct content *)html, + &html->sel, + ctx)) return false; return true; -- cgit v1.2.3