Gitweb links:
...log
http://git.netsurf-browser.org/netsurf.git/shortlog/3f9565753f4c7d658ea2d9f3d4f6ea1223e2e73e
...commit
http://git.netsurf-browser.org/netsurf.git/commit/3f9565753f4c7d658ea2d9f3d4f6ea1223e2e73e
...tree
http://git.netsurf-browser.org/netsurf.git/tree/3f9565753f4c7d658ea2d9f3d4f6ea1223e2e73e
The branch, master has been updated
via 3f9565753f4c7d658ea2d9f3d4f6ea1223e2e73e (commit)
via 4d6ada8c9afbc3aed902e4fb1f7ac93b95d2b30c (commit)
via 86f3e70f1af9130c2f24638fd560804ccb736af8 (commit)
via e9b036a794fc0b7b453581c4c3e017176213df6c (commit)
via 4c945bd16fa496b622cac73790272ea327848718 (commit)
from f58b5924a54fbef69de33dbb0340d1bf9f4fd237 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commitdiff
http://git.netsurf-browser.org/netsurf.git/commitdiff/3f9565753f4c7d658ea2d9f3d4f6ea1223e2e73e
commit 3f9565753f4c7d658ea2d9f3d4f6ea1223e2e73e
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>
Make selection_traverse internal to desktop/selection.c.
diff --git a/desktop/selection.c b/desktop/selection.c
index cd19afd..15f82bf 100644
--- a/desktop/selection.c
+++ b/desktop/selection.c
@@ -78,6 +78,12 @@ struct selection_string {
size_t length;
};
+
+typedef bool (*seln_traverse_handler)(const char *text, size_t length,
+ struct box *box, void *handle, const char *whitespace_text,
+ size_t whitespace_length);
+
+
static bool redraw_handler(const char *text, size_t length, struct box *box,
void *handle, const char *whitespace_text,
size_t whitespace_length);
@@ -618,8 +624,8 @@ bool traverse_tree(struct box *box, unsigned start_idx,
unsigned end_idx,
* \return false iff traversal abandoned part-way through
*/
-bool selection_traverse(struct selection *s, seln_traverse_handler handler,
- void *handle)
+static bool selection_traverse(struct selection *s,
+ seln_traverse_handler handler, void *handle)
{
save_text_whitespace before = WHITESPACE_NONE;
bool first = true;
diff --git a/desktop/selection.h b/desktop/selection.h
index 3002474..7ece4bd 100644
--- a/desktop/selection.h
+++ b/desktop/selection.h
@@ -55,11 +55,6 @@ struct selection
};
-typedef bool (*seln_traverse_handler)(const char *text, size_t length,
- struct box *box, void *handle, const char *whitespace_text,
- size_t whitespace_length);
-
-
struct selection *selection_create(struct content *c, bool is_html);
void selection_prepare(struct selection *s, struct content *c, bool is_html);
void selection_destroy(struct selection *s);
@@ -102,9 +97,6 @@ char * selection_get_copy(struct selection *s);
/* void selection_drag_end(struct selection *s); */
#define selection_drag_end(s) ((s)->drag_state = DRAG_NONE)
-bool selection_traverse(struct selection *s, seln_traverse_handler handler,
- void *handle);
-
bool selection_highlighted(const struct selection *s,
unsigned start, unsigned end,
unsigned *start_idx, unsigned *end_idx);
commitdiff
http://git.netsurf-browser.org/netsurf.git/commitdiff/4d6ada8c9afbc3aed902e4fb1f7ac93b95d2b30c
commit 4d6ada8c9afbc3aed902e4fb1f7ac93b95d2b30c
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>
Use selection_get_copy instead of selection_traverse. Note: untested.
diff --git a/amiga/clipboard.c b/amiga/clipboard.c
index b745088..8354830 100755
--- a/amiga/clipboard.c
+++ b/amiga/clipboard.c
@@ -48,11 +48,6 @@
struct IFFHandle *iffh = NULL;
-bool ami_add_to_clipboard(const char *text, size_t length, bool space);
-static bool ami_copy_selection(const char *text, size_t length,
- struct box *box, void *handle, const char *whitespace_text,
- size_t whitespace_length);
-
static LONG ami_clipboard_iffp_do_nothing(struct Hook *hook, void *object,
LONG *cmd)
{
return 0;
@@ -322,33 +317,30 @@ bool gui_copy_to_clipboard(struct selection *s)
struct ami_text_selection *ami_selection_to_text(struct gui_window_2 *gwin)
{
struct ami_text_selection *sel;
+ int len;
+ char *ss;
sel = AllocVec(sizeof(struct ami_text_selection),
MEMF_PRIVATE | MEMF_CLEAR);
- if(sel) selection_traverse(browser_window_get_selection(gwin->bw),
ami_copy_selection, sel);
-
- return sel;
-}
-
-static bool ami_copy_selection(const char *text, size_t length,
- struct box *box, void *handle, const char *whitespace_text,
- size_t whitespace_length)
-{
- struct ami_text_selection *sel = handle;
- int len = length;
-
- if((length + (sel->length)) > (sizeof(sel->text)))
- len = sizeof(sel->text) - (sel->length);
+ if (sel) {
+ /* Get selection string */
+ ss = selection_get_copy(browser_window_get_selection(gwin->bw));
+ if (ss == NULL)
+ return sel;
- if(len <= 0) return false;
+ len = strlen(ss);
- memcpy((sel->text) + (sel->length), text, len);
- sel->length += len;
+ if (len > sizeof(sel->text))
+ len = sizeof(sel->text) - 1;
- sel->text[sel->length] = '\0';
+ memcpy(sel->text, ss, len);
+ sel->length = len;
+ sel->text[sel->length] = '\0';
- return true;
+ free(ss);
+ }
+ return sel;
}
void ami_drag_selection(struct selection *s)
commitdiff
http://git.netsurf-browser.org/netsurf.git/commitdiff/86f3e70f1af9130c2f24638fd560804ccb736af8
commit 86f3e70f1af9130c2f24638fd560804ccb736af8
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>
Tolerate NULL selection context in selection_get_copy.
diff --git a/desktop/selection.c b/desktop/selection.c
index abe9e01..cd19afd 100644
--- a/desktop/selection.c
+++ b/desktop/selection.c
@@ -892,7 +892,7 @@ char * selection_get_copy(struct selection *s)
.length = 0
};
- if (!s->defined)
+ if (s == NULL || !s->defined)
return NULL;
if (!selection_traverse(s, selection_copy_handler, &sel_string)) {
commitdiff
http://git.netsurf-browser.org/netsurf.git/commitdiff/e9b036a794fc0b7b453581c4c3e017176213df6c
commit e9b036a794fc0b7b453581c4c3e017176213df6c
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>
Fix selection string struct init.
diff --git a/desktop/selection.c b/desktop/selection.c
index 860d4e4..abe9e01 100644
--- a/desktop/selection.c
+++ b/desktop/selection.c
@@ -886,7 +886,11 @@ static bool selection_copy_handler(const char *text,
size_t length,
char * selection_get_copy(struct selection *s)
{
- struct selection_string sel_string;
+ struct selection_string sel_string = {
+ .buffer = NULL,
+ .buffer_len = 0,
+ .length = 0
+ };
if (!s->defined)
return NULL;
commitdiff
http://git.netsurf-browser.org/netsurf.git/commitdiff/4c945bd16fa496b622cac73790272ea327848718
commit 4c945bd16fa496b622cac73790272ea327848718
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>
Function to get copy of selection as string.
diff --git a/desktop/selection.c b/desktop/selection.c
index 00984d9..860d4e4 100644
--- a/desktop/selection.c
+++ b/desktop/selection.c
@@ -72,6 +72,12 @@ struct rdw_info {
struct rect r;
};
+struct selection_string {
+ char *buffer;
+ size_t buffer_len;
+ size_t length;
+};
+
static bool redraw_handler(const char *text, size_t length, struct box *box,
void *handle, const char *whitespace_text,
size_t whitespace_length);
@@ -743,7 +749,7 @@ void selection_redraw(struct selection *s, unsigned
start_idx, unsigned end_idx)
* \return true iff successful and traversal should continue
*/
-static bool selection_copy_handler(const char *text, size_t length,
+static bool selection_copy_clip_handler(const char *text, size_t length,
struct box *box, void *handle, const char *whitespace_text,
size_t whitespace_length)
{
@@ -788,7 +794,111 @@ static bool selection_copy_handler(const char *text,
size_t length,
bool selection_copy_to_clipboard(struct selection *s)
{
- return selection_traverse(s, selection_copy_handler, NULL);
+ return selection_traverse(s, selection_copy_clip_handler, NULL);
+}
+
+
+/**
+ * Append text to selection string.
+ *
+ * \param text text to be added
+ * \param length length of text in bytes
+ * \param space indicates whether a trailing space should be appended
+ * \param sel_string string to append to, may be resized
+ * \return true iff successful
+ */
+
+static bool selection_string_append(const char *text, size_t length, bool
space,
+ struct selection_string *sel_string)
+{
+ size_t new_length = sel_string->length + length + (space ? 1 : 0) + 1;
+
+ if (new_length > sel_string->buffer_len) {
+ size_t new_alloc = new_length + (new_length / 4);
+ char *new_buff;
+
+ new_buff = realloc(sel_string->buffer, new_alloc);
+ if (new_buff == NULL)
+ return false;
+
+ sel_string->buffer = new_buff;
+ sel_string->buffer_len = new_alloc;
+ }
+
+ memcpy(sel_string->buffer + sel_string->length, text, length);
+ sel_string->length += length;
+
+ if (space)
+ sel_string->buffer[sel_string->length++] = ' ';
+
+ sel_string->buffer[sel_string->length] = '\0';
+
+ return true;
+}
+
+
+/**
+ * Selection traversal routine for appending text to a string
+ *
+ * \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 if from textplain
+ * \param handle selection string to append to
+ * \param whitespace_text whitespace to place before text for formatting
+ * may be NULL
+ * \param whitespace_length length of whitespace_text
+ * \return true iff successful and traversal should continue
+ */
+
+static bool selection_copy_handler(const char *text, size_t length,
+ struct box *box, void *handle, const char *whitespace_text,
+ size_t whitespace_length)
+{
+ bool add_space = false;
+
+ /* add any whitespace which precedes the text from this box */
+ if (whitespace_text != NULL && whitespace_length > 0) {
+ if (!selection_string_append(whitespace_text,
+ whitespace_length, false, handle)) {
+ return false;
+ }
+ }
+
+ if (box != NULL) {
+ /* HTML */
+ add_space = (box->space != 0);
+ }
+
+ /* add the text from this box */
+ if (!selection_string_append(text, length, add_space, handle))
+ return false;
+
+ return true;
+}
+
+
+/**
+ * Get copy of selection as string
+ *
+ * \param s selection
+ * \return string of selected text, or NULL. Ownership passed to caller.
+ */
+
+char * selection_get_copy(struct selection *s)
+{
+ struct selection_string sel_string;
+
+ if (!s->defined)
+ return NULL;
+
+ if (!selection_traverse(s, selection_copy_handler, &sel_string)) {
+ if (sel_string.buffer != NULL) {
+ free(sel_string.buffer);
+ }
+ return NULL;
+ }
+
+ return sel_string.buffer;
}
diff --git a/desktop/selection.h b/desktop/selection.h
index 16b002a..3002474 100644
--- a/desktop/selection.h
+++ b/desktop/selection.h
@@ -96,6 +96,7 @@ void selection_track(struct selection *s, browser_mouse_state
mouse,
unsigned idx);
bool selection_copy_to_clipboard(struct selection *s);
+char * selection_get_copy(struct selection *s);
/** Handles completion of a drag operation */
/* void selection_drag_end(struct selection *s); */
-----------------------------------------------------------------------
Summary of changes:
amiga/clipboard.c | 40 ++++++----------
desktop/selection.c | 128 +++++++++++++++++++++++++++++++++++++++++++++++++--
desktop/selection.h | 9 +---
3 files changed, 141 insertions(+), 36 deletions(-)
diff --git a/amiga/clipboard.c b/amiga/clipboard.c
index b745088..8354830 100755
--- a/amiga/clipboard.c
+++ b/amiga/clipboard.c
@@ -48,11 +48,6 @@
struct IFFHandle *iffh = NULL;
-bool ami_add_to_clipboard(const char *text, size_t length, bool space);
-static bool ami_copy_selection(const char *text, size_t length,
- struct box *box, void *handle, const char *whitespace_text,
- size_t whitespace_length);
-
static LONG ami_clipboard_iffp_do_nothing(struct Hook *hook, void *object,
LONG *cmd)
{
return 0;
@@ -322,33 +317,30 @@ bool gui_copy_to_clipboard(struct selection *s)
struct ami_text_selection *ami_selection_to_text(struct gui_window_2 *gwin)
{
struct ami_text_selection *sel;
+ int len;
+ char *ss;
sel = AllocVec(sizeof(struct ami_text_selection),
MEMF_PRIVATE | MEMF_CLEAR);
- if(sel) selection_traverse(browser_window_get_selection(gwin->bw),
ami_copy_selection, sel);
-
- return sel;
-}
-
-static bool ami_copy_selection(const char *text, size_t length,
- struct box *box, void *handle, const char *whitespace_text,
- size_t whitespace_length)
-{
- struct ami_text_selection *sel = handle;
- int len = length;
-
- if((length + (sel->length)) > (sizeof(sel->text)))
- len = sizeof(sel->text) - (sel->length);
+ if (sel) {
+ /* Get selection string */
+ ss = selection_get_copy(browser_window_get_selection(gwin->bw));
+ if (ss == NULL)
+ return sel;
- if(len <= 0) return false;
+ len = strlen(ss);
- memcpy((sel->text) + (sel->length), text, len);
- sel->length += len;
+ if (len > sizeof(sel->text))
+ len = sizeof(sel->text) - 1;
- sel->text[sel->length] = '\0';
+ memcpy(sel->text, ss, len);
+ sel->length = len;
+ sel->text[sel->length] = '\0';
- return true;
+ free(ss);
+ }
+ return sel;
}
void ami_drag_selection(struct selection *s)
diff --git a/desktop/selection.c b/desktop/selection.c
index 00984d9..15f82bf 100644
--- a/desktop/selection.c
+++ b/desktop/selection.c
@@ -72,6 +72,18 @@ struct rdw_info {
struct rect r;
};
+struct selection_string {
+ char *buffer;
+ size_t buffer_len;
+ size_t length;
+};
+
+
+typedef bool (*seln_traverse_handler)(const char *text, size_t length,
+ struct box *box, void *handle, const char *whitespace_text,
+ size_t whitespace_length);
+
+
static bool redraw_handler(const char *text, size_t length, struct box *box,
void *handle, const char *whitespace_text,
size_t whitespace_length);
@@ -612,8 +624,8 @@ bool traverse_tree(struct box *box, unsigned start_idx,
unsigned end_idx,
* \return false iff traversal abandoned part-way through
*/
-bool selection_traverse(struct selection *s, seln_traverse_handler handler,
- void *handle)
+static bool selection_traverse(struct selection *s,
+ seln_traverse_handler handler, void *handle)
{
save_text_whitespace before = WHITESPACE_NONE;
bool first = true;
@@ -743,7 +755,7 @@ void selection_redraw(struct selection *s, unsigned
start_idx, unsigned end_idx)
* \return true iff successful and traversal should continue
*/
-static bool selection_copy_handler(const char *text, size_t length,
+static bool selection_copy_clip_handler(const char *text, size_t length,
struct box *box, void *handle, const char *whitespace_text,
size_t whitespace_length)
{
@@ -788,7 +800,115 @@ static bool selection_copy_handler(const char *text,
size_t length,
bool selection_copy_to_clipboard(struct selection *s)
{
- return selection_traverse(s, selection_copy_handler, NULL);
+ return selection_traverse(s, selection_copy_clip_handler, NULL);
+}
+
+
+/**
+ * Append text to selection string.
+ *
+ * \param text text to be added
+ * \param length length of text in bytes
+ * \param space indicates whether a trailing space should be appended
+ * \param sel_string string to append to, may be resized
+ * \return true iff successful
+ */
+
+static bool selection_string_append(const char *text, size_t length, bool
space,
+ struct selection_string *sel_string)
+{
+ size_t new_length = sel_string->length + length + (space ? 1 : 0) + 1;
+
+ if (new_length > sel_string->buffer_len) {
+ size_t new_alloc = new_length + (new_length / 4);
+ char *new_buff;
+
+ new_buff = realloc(sel_string->buffer, new_alloc);
+ if (new_buff == NULL)
+ return false;
+
+ sel_string->buffer = new_buff;
+ sel_string->buffer_len = new_alloc;
+ }
+
+ memcpy(sel_string->buffer + sel_string->length, text, length);
+ sel_string->length += length;
+
+ if (space)
+ sel_string->buffer[sel_string->length++] = ' ';
+
+ sel_string->buffer[sel_string->length] = '\0';
+
+ return true;
+}
+
+
+/**
+ * Selection traversal routine for appending text to a string
+ *
+ * \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 if from textplain
+ * \param handle selection string to append to
+ * \param whitespace_text whitespace to place before text for formatting
+ * may be NULL
+ * \param whitespace_length length of whitespace_text
+ * \return true iff successful and traversal should continue
+ */
+
+static bool selection_copy_handler(const char *text, size_t length,
+ struct box *box, void *handle, const char *whitespace_text,
+ size_t whitespace_length)
+{
+ bool add_space = false;
+
+ /* add any whitespace which precedes the text from this box */
+ if (whitespace_text != NULL && whitespace_length > 0) {
+ if (!selection_string_append(whitespace_text,
+ whitespace_length, false, handle)) {
+ return false;
+ }
+ }
+
+ if (box != NULL) {
+ /* HTML */
+ add_space = (box->space != 0);
+ }
+
+ /* add the text from this box */
+ if (!selection_string_append(text, length, add_space, handle))
+ return false;
+
+ return true;
+}
+
+
+/**
+ * Get copy of selection as string
+ *
+ * \param s selection
+ * \return string of selected text, or NULL. Ownership passed to caller.
+ */
+
+char * selection_get_copy(struct selection *s)
+{
+ struct selection_string sel_string = {
+ .buffer = NULL,
+ .buffer_len = 0,
+ .length = 0
+ };
+
+ if (s == NULL || !s->defined)
+ return NULL;
+
+ if (!selection_traverse(s, selection_copy_handler, &sel_string)) {
+ if (sel_string.buffer != NULL) {
+ free(sel_string.buffer);
+ }
+ return NULL;
+ }
+
+ return sel_string.buffer;
}
diff --git a/desktop/selection.h b/desktop/selection.h
index 16b002a..7ece4bd 100644
--- a/desktop/selection.h
+++ b/desktop/selection.h
@@ -55,11 +55,6 @@ struct selection
};
-typedef bool (*seln_traverse_handler)(const char *text, size_t length,
- struct box *box, void *handle, const char *whitespace_text,
- size_t whitespace_length);
-
-
struct selection *selection_create(struct content *c, bool is_html);
void selection_prepare(struct selection *s, struct content *c, bool is_html);
void selection_destroy(struct selection *s);
@@ -96,14 +91,12 @@ void selection_track(struct selection *s,
browser_mouse_state mouse,
unsigned idx);
bool selection_copy_to_clipboard(struct selection *s);
+char * selection_get_copy(struct selection *s);
/** Handles completion of a drag operation */
/* void selection_drag_end(struct selection *s); */
#define selection_drag_end(s) ((s)->drag_state = DRAG_NONE)
-bool selection_traverse(struct selection *s, seln_traverse_handler handler,
- void *handle);
-
bool selection_highlighted(const struct selection *s,
unsigned start, unsigned end,
unsigned *start_idx, unsigned *end_idx);
--
NetSurf Browser
_______________________________________________
netsurf-commits mailing list
[email protected]
http://vlists.pepperfish.net/cgi-bin/mailman/listinfo/netsurf-commits-netsurf-browser.org