summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--desktop/selection.c41
-rw-r--r--desktop/selection.h9
-rw-r--r--render/html_interaction.c4
-rw-r--r--render/search.c124
-rw-r--r--render/search.h40
5 files changed, 88 insertions, 130 deletions
diff --git a/desktop/selection.c b/desktop/selection.c
index 6a93c6133..1b85a090c 100644
--- a/desktop/selection.c
+++ b/desktop/selection.c
@@ -83,7 +83,7 @@ static bool traverse_tree(struct box *box, unsigned start_idx, unsigned end_idx,
seln_traverse_handler handler,
void *handle, save_text_whitespace *before, bool *first,
bool do_marker);
-
+static unsigned selection_label_subtree(struct box *box, unsigned idx);
/**
* Get the browser window containing the content a selection object belongs to.
@@ -211,19 +211,6 @@ void selection_init(struct selection *s, struct box *root)
/**
- * Indicate whether the selected text is read only, ie. cannot be modified.
- *
- * \param s selection object
- * \return true iff the selection is read only
- */
-
-bool selection_read_only(struct selection *s)
-{
- return true;
-}
-
-
-/**
* Label each text box in the given box subtree with its position
* in a textual representation of the content.
*
@@ -990,29 +977,3 @@ bool selection_highlighted(const struct selection *s,
return true;
}
-
-
-/**
- * Adjust the selection to reflect a change in the selected text,
- * eg. editing in a text area/input field.
- *
- * \param s selection object
- * \param byte_offset byte offset of insertion/removal point
- * \param change byte size of change, +ve = insertion, -ve = removal
- * \param redraw true iff the screen should be updated
- */
-
-void selection_update(struct selection *s, size_t byte_offset,
- int change, bool redraw)
-{
- if (selection_defined(s) &&
- byte_offset >= s->start_idx &&
- byte_offset < s->end_idx)
- {
- if (change > 0)
- s->end_idx += change;
- else
- s->end_idx +=
- max(change, (int)(byte_offset - s->end_idx));
- }
-}
diff --git a/desktop/selection.h b/desktop/selection.h
index 68f60b9be..7e620fc46 100644
--- a/desktop/selection.h
+++ b/desktop/selection.h
@@ -75,8 +75,6 @@ void selection_reinit(struct selection *s, struct box *root);
/* bool selection_dragging_start(struct selection *s); */
#define selection_dragging_start(s) ((s)->drag_state == DRAG_START)
-bool selection_read_only(struct selection *s);
-
void selection_clear(struct selection *s, bool redraw);
void selection_select_all(struct selection *s);
@@ -99,11 +97,4 @@ bool selection_highlighted(const struct selection *s,
unsigned start, unsigned end,
unsigned *start_idx, unsigned *end_idx);
-bool selection_save_text(struct selection *s, const char *path);
-
-void selection_update(struct selection *s, size_t byte_offset, int change,
- bool redraw);
-
-unsigned selection_label_subtree(struct box *box, unsigned idx);
-
#endif
diff --git a/render/html_interaction.c b/render/html_interaction.c
index a5f263b68..0dc36472d 100644
--- a/render/html_interaction.c
+++ b/render/html_interaction.c
@@ -847,9 +847,7 @@ void html_mouse_action(struct content *c, struct browser_window *bw,
if (selection_defined(&html->sel)) {
sel_owner.none = false;
html_set_selection(html, HTML_SELECTION_SELF,
- sel_owner,
- selection_read_only(
- &html->sel));
+ sel_owner, true);
} else if (click && html->selection_type !=
HTML_SELECTION_NONE) {
sel_owner.none = true;
diff --git a/render/search.c b/render/search.c
index d30c43f11..617d7ebcf 100644
--- a/render/search.c
+++ b/render/search.c
@@ -63,24 +63,18 @@ struct list_entry {
};
struct search_context {
- struct search_callbacks callbacks;
- struct content *c;
- struct list_entry *found;
- struct list_entry *current; /* first for select all */
- char *string;
- bool prev_case_sens;
- bool newsearch;
- bool is_html;
+ struct search_callbacks callbacks;
+ struct content *c;
+ struct list_entry *found;
+ struct list_entry *current; /* first for select all */
+ char *string;
+ bool prev_case_sens;
+ bool newsearch;
+ bool is_html;
};
-/**
- * create a search_context
- * \param h the hlcache_handle the search_context is connected to
- * \param callbacks the callbacks to modify appearance according to results
- * \param p the pointer to send to the callbacks
- * \return true for success
- */
+/* Exported function documented in search.h */
struct search_context * search_create_context(hlcache_handle *h,
struct search_callbacks callbacks)
{
@@ -149,8 +143,8 @@ static void free_matches(struct search_context *context)
a = context->found->next;
/* empty the list before clearing and deleting the
- selections because the the clearing updates the
- screen immediately, causing nested accesses to the list */
+ * selections because the the clearing updates the
+ * screen immediately, causing nested accesses to the list */
context->found->prev = NULL;
context->found->next = NULL;
@@ -241,11 +235,11 @@ static const char *find_pattern(const char *string, int s_len,
}
matches = true;
- }
- else
+ } else {
matches = false;
- }
- else if (s < es) {
+ }
+
+ } else if (s < es) {
char ch = *p;
if (ch == '#')
matches = true;
@@ -259,16 +253,17 @@ static const char *find_pattern(const char *string, int s_len,
ss = s; /* remember first non-'*' char */
first = false;
}
- }
- else
+ } else {
matches = false;
+ }
if (matches) {
p++; s++;
- }
- else {
- /* doesn't match, resume with stacked context if we have one */
- if (--top < 0) return NULL; /* no match, give up */
+ } else {
+ /* doesn't match,
+ * resume with stacked context if we have one */
+ if (--top < 0)
+ return NULL; /* no match, give up */
ss = context[top].ss;
s = context[top].s;
@@ -309,10 +304,12 @@ static struct list_entry *add_entry(unsigned start_idx, unsigned end_idx,
entry->next = 0;
entry->prev = context->found->prev;
+
if (context->found->prev == NULL)
context->found->next = entry;
else
context->found->prev->next = entry;
+
context->found->prev = entry;
return entry;
@@ -347,7 +344,8 @@ static bool find_occurrences_html(const char *pattern, int p_len,
const char *pos = find_pattern(text, length,
pattern, p_len, case_sens,
&match_length);
- if (!pos) break;
+ if (!pos)
+ break;
/* found string in box => add to list */
match_offset = pos - cur->text;
@@ -409,7 +407,8 @@ static bool find_occurrences_text(const char *pattern, int p_len,
const char *pos = find_pattern(text, length,
pattern, p_len, case_sens,
&match_length);
- if (!pos) break;
+ if (!pos)
+ break;
/* found string in line => add to list */
start_idx = offset + (pos - text);
@@ -461,9 +460,6 @@ static void search_text(const char *string, int string_len,
return;
}
- /* LOG(("do_search '%s' - '%s' (%p, %p) %p (%d, %d) %d",
- search_data.string, string, search_data.content, c, search_data.found->next,
- search_data.prev_case_sens, case_sens, forwards)); */
/* check if we need to start a new search or continue an old one */
if (context->newsearch) {
@@ -471,6 +467,7 @@ static void search_text(const char *string, int string_len,
if (context->string != NULL)
free(context->string);
+
context->current = NULL;
free_matches(context);
@@ -508,19 +505,17 @@ static void search_text(const char *string, int string_len,
context->callbacks.gui_p);
context->prev_case_sens = case_sensitive;
-/* LOG(("%d %p %p (%p, %p)", new, search_data.found->next, search_data.current,
- search_data.current->prev, search_data.current->next)); */
+
/* new search, beginning at the top of the page */
context->current = context->found->next;
context->newsearch = false;
- }
- else if (context->current != NULL) {
+
+ } else if (context->current != NULL) {
/* continued search in the direction specified */
if (forwards) {
if (context->current->next)
context->current = context->current->next;
- }
- else {
+ } else {
if (context->current->prev)
context->current = context->current->prev;
}
@@ -531,6 +526,7 @@ static void search_text(const char *string, int string_len,
if (context->callbacks.gui->status != NULL)
context->callbacks.gui->status((context->current != NULL),
context->callbacks.gui_p);
+
search_show_all(showall, context);
if (context->callbacks.gui->back_state != NULL)
@@ -569,15 +565,7 @@ static void search_text(const char *string, int string_len,
}
-/**
- * Begins/continues the search process
- * Note that this may be called many times for a single search.
- *
- * \param bw the browser_window to search in
- * \param flags the flags forward/back etc
- * \param string the string to match
- */
-
+/* Exported function documented in search.h */
void search_step(struct search_context *context, search_flags_t flags,
const char *string)
{
@@ -594,8 +582,9 @@ void search_step(struct search_context *context, search_flags_t flags,
context->callbacks.gui_p);
string_len = strlen(string);
- for(i = 0; i < string_len; i++)
- if (string[i] != '#' && string[i] != '*') break;
+ for (i = 0; i < string_len; i++)
+ if (string[i] != '#' && string[i] != '*')
+ break;
if (i >= string_len) {
union content_msg_data msg_data;
free_matches(context);
@@ -619,18 +608,7 @@ void search_step(struct search_context *context, search_flags_t flags,
}
-/**
- * Determines whether any portion of the given text box should be
- * selected because it matches the current search string.
- *
- * \param bw browser window
- * \param start_offset byte offset within text of string to be checked
- * \param end_offset byte offset within text
- * \param start_idx byte offset within string of highlight start
- * \param end_idx byte offset of highlight end
- * \return true iff part of the box should be highlighted
- */
-
+/* Exported function documented in search.h */
bool search_term_highlighted(struct content *c,
unsigned start_offset, unsigned end_offset,
unsigned *start_idx, unsigned *end_idx,
@@ -638,11 +616,11 @@ bool search_term_highlighted(struct content *c,
{
if (c == context->c) {
struct list_entry *a;
- for(a = context->found->next; a; a = a->next)
+ for (a = context->found->next; a; a = a->next)
if (a->sel && selection_defined(a->sel) &&
- selection_highlighted(a->sel,
- start_offset, end_offset,
- start_idx, end_idx))
+ selection_highlighted(a->sel,
+ start_offset, end_offset,
+ start_idx, end_idx))
return true;
}
@@ -650,11 +628,7 @@ bool search_term_highlighted(struct content *c,
}
-/**
- * Specifies whether all matches or just the current match should
- * be highlighted in the search text.
- */
-
+/* Exported function documented in search.h */
void search_show_all(bool all, struct search_context *context)
{
struct list_entry *a;
@@ -693,10 +667,7 @@ void search_show_all(bool all, struct search_context *context)
}
-/**
- * Ends the search process, invalidating all state
- * freeing the list of found boxes
- */
+/* Exported function documented in search.h */
void search_destroy_context(struct search_context *context)
{
assert(context != NULL);
@@ -707,10 +678,11 @@ void search_destroy_context(struct search_context *context)
if (context->c != NULL) {
- if (context->is_html)
+ if (context->is_html) {
html_set_search(context->c, NULL);
- else
+ } else {
textplain_set_search(context->c, NULL);
+ }
}
if ((context->string != NULL) && (context->callbacks.gui != NULL) &&
(context->callbacks.gui->add_recent != NULL)) {
diff --git a/render/search.h b/render/search.h
index e1f58f2ae..70da31bca 100644
--- a/render/search.h
+++ b/render/search.h
@@ -41,15 +41,51 @@ struct search_callbacks {
void *p; /* private client data */
};
-
+/**
+ * create a search_context
+ *
+ * \param h the hlcache_handle the search_context is connected to
+ * \param callbacks the callbacks to modify appearance according to results
+ * \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);
+
+/**
+ * Ends the search process, invalidating all state
+ * freeing the list of found boxes
+ */
void search_destroy_context(struct search_context *context);
+
+/**
+ * Begins/continues the search process
+ * Note that this may be called many times for a single search.
+ *
+ * \param bw the browser_window to search in
+ * \param flags the flags forward/back etc
+ * \param string the string to match
+ */
void search_step(struct search_context *context, search_flags_t flags,
const char * string);
-void search_show_all(bool all, struct search_context *context);
+/**
+ * Specifies whether all matches or just the current match should
+ * be highlighted in the search text.
+ */
+void search_show_all(bool all, struct search_context *context);
+/**
+ * Determines whether any portion of the given text box should be
+ * selected because it matches the current search string.
+ *
+ * \param bw browser window
+ * \param start_offset byte offset within text of string to be checked
+ * \param end_offset byte offset within text
+ * \param start_idx byte offset within string of highlight start
+ * \param end_idx byte offset of highlight end
+ * \return true iff part of the box should be highlighted
+ */
bool search_term_highlighted(struct content *c,
unsigned start_offset, unsigned end_offset,
unsigned *start_idx, unsigned *end_idx,