From de688b59e1fb3403e5b291c30dc81064e4452678 Mon Sep 17 00:00:00 2001 From: John Mark Bell Date: Sun, 6 Mar 2011 18:04:13 +0000 Subject: Fix text selection svn path=/trunk/netsurf/; revision=11927 --- amiga/clipboard.c | 2 +- atari/gui.c | 2 +- beos/beos_window.cpp | 2 +- cocoa/selection.m | 2 +- desktop/selection.c | 15 ++++++++------- gtk/selection.c | 2 +- riscos/textselection.c | 2 +- windows/gui.c | 2 +- 8 files changed, 15 insertions(+), 14 deletions(-) diff --git a/amiga/clipboard.c b/amiga/clipboard.c index 177b5025c..826f2f2dd 100755 --- a/amiga/clipboard.c +++ b/amiga/clipboard.c @@ -246,7 +246,7 @@ bool ami_clipboard_copy(const char *text, size_t length, struct box *box, if(text) { - bool add_space = box != NULL ? box->space : false; + bool add_space = box != NULL ? box->space != 0 : false; if (!ami_add_to_clipboard(text, length, add_space)) return false; } diff --git a/atari/gui.c b/atari/gui.c index 87d70e145..7c3e5279b 100755 --- a/atari/gui.c +++ b/atari/gui.c @@ -866,7 +866,7 @@ gui_selection_traverse_handler(const char *text, const char *space_text, size_t space_length) { - bool add_space = box != NULL ? box->space : false; + bool add_space = box != NULL ? box->space != 0 : false; if (space_text != NULL && space_length > 0) { if (!gui_add_to_clipboard(space_text, space_length, false)) { diff --git a/beos/beos_window.cpp b/beos/beos_window.cpp index ace697930..9a65f4832 100644 --- a/beos/beos_window.cpp +++ b/beos/beos_window.cpp @@ -1888,7 +1888,7 @@ static bool copy_handler(const char *text, size_t length, struct box *box, run->font = font; run->color = nsbeos_rgb_colour(nscss_color_to_ns(box->style->color)); current_selection_textruns.AddItem(run); - space = box->space; + space = box->space != 0; } /* add the text from this box */ diff --git a/cocoa/selection.m b/cocoa/selection.m index 208776ebb..d894ed40b 100644 --- a/cocoa/selection.m +++ b/cocoa/selection.m @@ -72,7 +72,7 @@ static bool cocoa_clipboard_copy_handler(const char *text, size_t length, struct void *handle, const char *whitespace_text, size_t whitespace_length) { - bool add_space = box != NULL ? box->space : false; + bool add_space = box != NULL ? box->space != 0 : false; if (whitespace_text && !gui_add_to_clipboard( whitespace_text, whitespace_length, false )) return false; diff --git a/desktop/selection.c b/desktop/selection.c index 5962a8f36..9bc594bdd 100644 --- a/desktop/selection.c +++ b/desktop/selection.c @@ -63,6 +63,8 @@ #define NUMBER_SPACE(x) ((x) & 0xF0000000U) #define SAME_SPACE(s, offset) (NUMBER_SPACE((s)->max_idx) == NUMBER_SPACE(offset)) +#define SPACE_LEN(b) ((b->space == 0) ? 0 : 1) + struct rdw_info { bool inited; @@ -225,7 +227,7 @@ unsigned selection_label_subtree(struct box *box, unsigned idx) box->byte_offset = idx; if (box->text) - idx += box->length + box->space; + idx += box->length + SPACE_LEN(box); while (child) { if (!IS_INPUT(child)) { @@ -405,7 +407,7 @@ void selection_track(struct selection *s, browser_mouse_state mouse, bool selected_part(struct box *box, unsigned start_idx, unsigned end_idx, unsigned *start_offset, unsigned *end_offset) { - size_t box_length = box->length + box->space; + size_t box_length = box->length + SPACE_LEN(box); if (box_length > 0) { if (box->byte_offset >= start_idx && @@ -609,7 +611,7 @@ bool redraw_handler(const char *text, size_t length, struct box *box, { if (box) { struct rdw_info *r = (struct rdw_info*)handle; - int width, height, space_width; + int width, height; int x, y; plot_font_style_t fstyle; @@ -622,9 +624,8 @@ bool redraw_handler(const char *text, size_t length, struct box *box, width = box->padding[LEFT] + box->width + box->padding[RIGHT]; height = box->padding[TOP] + box->height + box->padding[BOTTOM]; - if (box->type == BOX_TEXT && box->space && - nsfont.font_width(&fstyle, " ", 1, &space_width)) - width += space_width; + if (box->type == BOX_TEXT && box->space != 0) + width += box->space; if (r->inited) { if (x < r->r.x0) r->r.x0 = x; @@ -807,7 +808,7 @@ struct box *get_box(struct box *b, unsigned offset, size_t *pidx) if (b->text) { if (offset >= b->byte_offset && - offset <= b->byte_offset + b->length + b->space) { + offset <= b->byte_offset + b->length + SPACE_LEN(b)) { /* it's in this box */ *pidx = offset - b->byte_offset; diff --git a/gtk/selection.c b/gtk/selection.c index 3ffd0db91..57dc0e453 100644 --- a/gtk/selection.c +++ b/gtk/selection.c @@ -50,7 +50,7 @@ bool copy_handler(const char *text, size_t length, struct box *box, void *handle, const char *whitespace_text, size_t whitespace_length) { - bool add_space = box != NULL ? box->space : false; + bool add_space = box != NULL ? box->space != 0 : false; /* add any whitespace which precedes the text from this box */ if (whitespace_text != NULL && whitespace_length > 0) { diff --git a/riscos/textselection.c b/riscos/textselection.c index 1f3809f50..2aa5b9239 100644 --- a/riscos/textselection.c +++ b/riscos/textselection.c @@ -208,7 +208,7 @@ bool copy_handler(const char *text, size_t length, struct box *box, void *handle, const char *whitespace_text, size_t whitespace_length) { - bool add_space = box != NULL ? box->space : false; + bool add_space = box != NULL ? box->space != 0 : false; /* add any whitespace which precedes the text from this box */ if (whitespace_text != NULL && whitespace_length > 0) { diff --git a/windows/gui.c b/windows/gui.c index a3ce3ff8d..908cefaa6 100644 --- a/windows/gui.c +++ b/windows/gui.c @@ -2493,7 +2493,7 @@ gui_selection_traverse_handler(const char *text, const char *space_text, size_t space_length) { - bool add_space = box != NULL ? box->space : false; + bool add_space = box != NULL ? box->space != 0 : false; if (space_text != NULL && space_length > 0) { if (!gui_add_to_clipboard(space_text, space_length, false)) { -- cgit v1.2.3