summaryrefslogtreecommitdiff
path: root/desktop/selection.c
diff options
context:
space:
mode:
authorMichael Drake <tlsa@netsurf-browser.org>2013-02-22 12:19:35 +0000
committerMichael Drake <tlsa@netsurf-browser.org>2013-02-22 12:19:35 +0000
commitc2a718075ad321a9cf4678e72645acda5c3471a9 (patch)
treea634c4c47c579aab35839ee3861ef90f92d89b48 /desktop/selection.c
parent2b0cc398bb5b8e5dc90fcc0a71a9a154dd9f2d74 (diff)
downloadnetsurf-c2a718075ad321a9cf4678e72645acda5c3471a9.tar.gz
netsurf-c2a718075ad321a9cf4678e72645acda5c3471a9.tar.bz2
A load of refactoring of how content selection and input work.
Keypresses now go via content interface. Contents don't shove the selection object into browser windows any more. Contents report selection existence by sending message. HTML content keeps track of where selections in it exist. Contents report whether they have input focus via caret setting msg. Caret can be hidden (can still input/paste) or removed. Consolidate textarea selection handling. Make textarea report its selection status changes to client. Various textarea fixes. Changed how we decide when to clear selections, and give focus.
Diffstat (limited to 'desktop/selection.c')
-rw-r--r--desktop/selection.c128
1 files changed, 2 insertions, 126 deletions
diff --git a/desktop/selection.c b/desktop/selection.c
index fa82ad027..536df5c84 100644
--- a/desktop/selection.c
+++ b/desktop/selection.c
@@ -77,9 +77,6 @@ static bool redraw_handler(const char *text, size_t length, struct box *box,
size_t whitespace_length);
static void selection_redraw(struct selection *s, unsigned start_idx,
unsigned end_idx);
-static bool save_handler(const char *text, size_t length, struct box *box,
- void *handle, const char *whitespace_text,
- size_t whitespace_length);
static bool selected_part(struct box *box, unsigned start_idx, unsigned end_idx,
unsigned *start_offset, unsigned *end_offset);
static bool traverse_tree(struct box *box, unsigned start_idx, unsigned end_idx,
@@ -285,10 +282,6 @@ bool selection_click(struct selection *s, browser_mouse_state mouse,
(mouse & (BROWSER_MOUSE_MOD_1 | BROWSER_MOUSE_MOD_2));
int pos = -1; /* 0 = inside selection, 1 = after it */
struct browser_window *top = selection_get_browser_window(s);
-
- if (top == NULL)
- return false; /* not our problem */
-
top = browser_window_get_root(top);
if (selection_defined(s)) {
@@ -309,14 +302,12 @@ bool selection_click(struct selection *s, browser_mouse_state mouse,
}
else if (!modkeys) {
if (pos && (mouse & BROWSER_MOUSE_PRESS_1)) {
- /* Clear the selection if mouse is pressed outside the selection,
- * Otherwise clear on release (to allow for drags) */
- browser_window_set_selection(top, s);
+ /* Clear the selection if mouse is pressed outside the
+ * selection, Otherwise clear on release (to allow for drags) */
selection_clear(s, true);
} else if (mouse & BROWSER_MOUSE_DRAG_1) {
/* start new selection drag */
- browser_window_set_selection(top, s);
selection_clear(s, true);
@@ -333,8 +324,6 @@ bool selection_click(struct selection *s, browser_mouse_state mouse,
if (!selection_defined(s))
return false; /* ignore Adjust drags */
- browser_window_set_selection(top, s);
-
if (pos >= 0) {
selection_set_end(s, idx);
@@ -907,7 +896,6 @@ void selection_clear(struct selection *s, bool redraw)
{
int old_start, old_end;
bool was_defined;
- struct browser_window *top = selection_get_browser_window(s);
assert(s);
was_defined = selection_defined(s);
@@ -918,13 +906,6 @@ void selection_clear(struct selection *s, bool redraw)
s->start_idx = 0;
s->end_idx = 0;
- if (!top)
- return;
-
- top = browser_window_get_root(top);
-
- gui_clear_selection(top->window);
-
if (redraw && was_defined)
selection_redraw(s, old_start, old_end);
}
@@ -1110,111 +1091,6 @@ bool selection_highlighted(const struct selection *s,
/**
- * Selection traversal handler for saving the text to a file.
- *
- * \param text pointer to text being added, or NULL for newline
- * \param length length of text to be appended (bytes)
- * \param box pointer to text box (or NULL for textplain content)
- * \param handle our save_state workspace pointer
- * \param whitespace_text whitespace to place before text for formatting
- * may be NULL
- * \param whitespace_length length of whitespace_text
- * \return true iff the file writing succeeded and traversal should continue.
- */
-
-bool save_handler(const char *text, size_t length, struct box *box,
- void *handle, const char *whitespace_text,
- size_t whitespace_length)
-{
- struct save_text_state *sv = handle;
- size_t new_length;
- int space = 0;
-
- assert(sv);
-
- if (box && (box->space > 0))
- space = 1;
-
- if (whitespace_text)
- length += whitespace_length;
-
- new_length = sv->length + whitespace_length + length + space;
- if (new_length >= sv->alloc) {
- size_t new_alloc = sv->alloc + (sv->alloc / 4);
- char *new_block;
-
- if (new_alloc < new_length) new_alloc = new_length;
-
- new_block = realloc(sv->block, new_alloc);
- if (!new_block) return false;
-
- sv->block = new_block;
- sv->alloc = new_alloc;
- }
- if (whitespace_text) {
- memcpy(sv->block + sv->length, whitespace_text,
- whitespace_length);
- }
- memcpy(sv->block + sv->length + whitespace_length, text, length);
- sv->length += length;
-
- if (space == 1)
- sv->block[sv->length++] = ' ';
-
- return true;
-}
-
-
-/**
- * Save the given selection to a file.
- *
- * \param s selection object
- * \param path pathname to be used
- * \return true iff the save succeeded
- */
-
-bool selection_save_text(struct selection *s, const char *path)
-{
- struct save_text_state sv = { NULL, 0, 0 };
- utf8_convert_ret ret;
- char *result;
- FILE *out;
-
- if (!selection_traverse(s, save_handler, &sv)) {
- free(sv.block);
- return false;
- }
-
- if (!sv.block)
- return false;
-
- ret = utf8_to_local_encoding(sv.block, sv.length, &result);
- free(sv.block);
-
- if (ret != UTF8_CONVERT_OK) {
- LOG(("failed to convert to local encoding, return %d", ret));
- return false;
- }
-
- out = fopen(path, "w");
- if (out) {
- int res = fputs(result, out);
- if (res < 0) {
- LOG(("Warning: writing data failed"));
- }
-
- res = fputs("\n", out);
- fclose(out);
- free(result);
- return (res != EOF);
- }
- free(result);
-
- return false;
-}
-
-
-/**
* Adjust the selection to reflect a change in the selected text,
* eg. editing in a text area/input field.
*