summaryrefslogtreecommitdiff
path: root/render/search.c
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/search.c
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/search.c')
-rw-r--r--render/search.c111
1 files changed, 40 insertions, 71 deletions
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);