diff options
author | Michael Drake <tlsa@netsurf-browser.org> | 2011-07-13 13:20:26 +0000 |
---|---|---|
committer | Michael Drake <tlsa@netsurf-browser.org> | 2011-07-13 13:20:26 +0000 |
commit | 9c918930289b18dbfd4bb44081891d5780105bfd (patch) | |
tree | 372de7dbf3d8393550e46ab1f8de6e9a97cf2140 /desktop/selection.c | |
parent | 1832155b7c64e0a977541930fc78f47bbd675ab2 (diff) | |
download | netsurf-9c918930289b18dbfd4bb44081891d5780105bfd.tar.gz netsurf-9c918930289b18dbfd4bb44081891d5780105bfd.tar.bz2 |
Fix selection for non-gui browser windows (iframes).
Selection no longer uses current_redraw_browser.
Fix long-standing selection bugs on platforms that use action on release behaviour.
svn path=/trunk/netsurf/; revision=12598
Diffstat (limited to 'desktop/selection.c')
-rw-r--r-- | desktop/selection.c | 37 |
1 files changed, 31 insertions, 6 deletions
diff --git a/desktop/selection.c b/desktop/selection.c index 24502ac47..7c775f4c2 100644 --- a/desktop/selection.c +++ b/desktop/selection.c @@ -90,20 +90,34 @@ static struct box *get_box(struct box *b, unsigned offset, size_t *pidx); /** * Creates a new selection object associated with a browser window. * - * \param s selection object - * \param bw browser window + * \return new selection context */ struct selection *selection_create(void) { struct selection *s = calloc(1, sizeof(struct selection)); if (s) { + selection_prepare(s); + } + return s; +} + +/** + * Prepare a newly created selection object for use. + * + * \param s selection object + * \param bw browser window + */ + +void selection_prepare(struct selection *s) +{ + if (s) { s->bw = NULL; s->root = NULL; s->drag_state = DRAG_NONE; + s->max_idx = 0; selection_clear(s, false); } - return s; } /** @@ -304,12 +318,16 @@ bool selection_click(struct selection *s, browser_mouse_state mouse, gui_drag_save_selection(s, top->window); } else if (!modkeys) { - if (pos && (mouse & BROWSER_MOUSE_PRESS_1)) + 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); + selection_clear(s, true); - else if (mouse & BROWSER_MOUSE_DRAG_1) { + } else if (mouse & BROWSER_MOUSE_DRAG_1) { /* start new selection drag */ + browser_window_set_selection(top, s); + selection_clear(s, true); selection_set_start(s, idx); @@ -325,6 +343,8 @@ 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); @@ -385,6 +405,10 @@ void selection_track(struct selection *s, browser_mouse_state mouse, if (!SAME_SPACE(s, idx)) return; + if (!mouse) { + s->drag_state = DRAG_NONE; + } + switch (s->drag_state) { case DRAG_START: @@ -902,7 +926,8 @@ struct box *selection_get_end(struct selection *s, size_t *pidx) * \return true iff part of the given box lies within the selection */ -bool selection_highlighted(struct selection *s, unsigned start, unsigned end, +bool selection_highlighted(const struct selection *s, + unsigned start, unsigned end, unsigned *start_idx, unsigned *end_idx) { /* caller should have checked first for efficiency */ |