summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--desktop/browser.c7
-rw-r--r--desktop/selection.c68
-rw-r--r--render/html.c6
-rw-r--r--render/textplain.c21
4 files changed, 54 insertions, 48 deletions
diff --git a/desktop/browser.c b/desktop/browser.c
index 827896835..cc19ccdc0 100644
--- a/desktop/browser.c
+++ b/desktop/browser.c
@@ -292,7 +292,6 @@ struct browser_window *browser_window_create(const char *url,
bw->focus = bw;
bw->sel = selection_create();
- selection_set_browser_window(bw->sel, bw);
/* gui window */
/* from the front end's pov, it clones the top level browser window,
@@ -1683,10 +1682,6 @@ void browser_window_mouse_track(struct browser_window *bw,
browser_window_mouse_drag_end(bw, mouse, x, y);
}
- if (bw->drag_type != DRAGGING_NONE) {
- selection_set_browser_window(bw->sel, bw);
- }
-
if (bw->drag_type == DRAGGING_FRAME) {
browser_window_resize_frame(bw, bw->x0 + x, bw->y0 + y);
} else if (bw->drag_type == DRAGGING_PAGE_SCROLL) {
@@ -1741,8 +1736,6 @@ void browser_window_mouse_click(struct browser_window *bw,
top = browser_window_get_root(bw);
top->focus = bw;
- selection_set_browser_window(bw->sel, bw);
-
switch (content_get_type(c)) {
case CONTENT_HTML:
case CONTENT_TEXTPLAIN:
diff --git a/desktop/selection.c b/desktop/selection.c
index 6b30a8781..17e97c7fc 100644
--- a/desktop/selection.c
+++ b/desktop/selection.c
@@ -94,12 +94,16 @@ static struct box *get_box(struct box *b, unsigned offset, size_t *pidx);
* \param bw browser window
*/
-void selection_set_browser_window(struct selection *s,
- struct browser_window *bw)
+struct selection *selection_create(void)
{
- assert(s);
-
- s->bw = bw;
+ struct selection *s = calloc(1, sizeof(struct selection));
+ if (s) {
+ s->bw = NULL;
+ s->root = NULL;
+ s->drag_state = DRAG_NONE;
+ selection_clear(s, false);
+ }
+ return s;
}
/**
@@ -109,16 +113,12 @@ void selection_set_browser_window(struct selection *s,
* \param bw browser window
*/
-struct selection *selection_create(void)
+void selection_set_browser_window(struct selection *s,
+ struct browser_window *bw)
{
- struct selection *s = calloc(1, sizeof(struct selection));
- if (s) {
- s->bw = NULL;
- s->root = NULL;
- s->drag_state = DRAG_NONE;
- selection_clear(s, false);
- }
- return s;
+ assert(s);
+
+ s->bw = bw;
}
@@ -277,7 +277,10 @@ bool selection_click(struct selection *s, browser_mouse_state mouse,
browser_mouse_state modkeys =
(mouse & (BROWSER_MOUSE_MOD_1 | BROWSER_MOUSE_MOD_2));
int pos = -1; /* 0 = inside selection, 1 = after it */
- struct browser_window *bw;
+ struct browser_window *top;
+
+ assert(s->bw);
+ top = browser_window_get_root(s->bw);
if (!SAME_SPACE(s, idx))
return false; /* not our problem */
@@ -295,13 +298,8 @@ bool selection_click(struct selection *s, browser_mouse_state mouse,
((mouse & BROWSER_MOUSE_DRAG_1) ||
(modkeys && (mouse & BROWSER_MOUSE_DRAG_2)))) {
/* drag-saving selection */
- assert(s->bw);
-
- bw = s->bw;
- while (bw && !bw->window && bw->parent)
- bw = bw->parent;
- gui_drag_save_selection(s, bw->window);
+ gui_drag_save_selection(s, top->window);
}
else if (!modkeys) {
if (pos && (mouse & BROWSER_MOUSE_PRESS_1))
@@ -317,11 +315,7 @@ bool selection_click(struct selection *s, browser_mouse_state mouse,
s->drag_state = DRAG_END;
- bw = s->bw;
- while (bw && !bw->window && bw->parent)
- bw = bw->parent;
-
- gui_start_selection(bw->window);
+ gui_start_selection(top->window);
}
else if (mouse & BROWSER_MOUSE_DRAG_2) {
@@ -340,11 +334,7 @@ bool selection_click(struct selection *s, browser_mouse_state mouse,
s->drag_state = DRAG_START;
}
- bw = s->bw;
- while (bw && !bw->window && bw->parent)
- bw = bw->parent;
-
- gui_start_selection(bw->window);
+ gui_start_selection(top->window);
}
/* Selection should be cleared when button is released but in
* the RO interface click is the same as press */
@@ -605,16 +595,18 @@ bool selection_traverse(struct selection *s, seln_traverse_handler handler,
if (!selection_defined(s))
return true; /* easy case, nothing to do */
- if (s->root)
+ if (s->root) {
+ /* HTML */
return traverse_tree(s->root, s->start_idx, s->end_idx,
NUMBER_SPACE(s->max_idx), handler, handle,
&before, &first, false);
+ }
+ /* Text */
c = s->bw->current_content;
if (!c) return true;
- text = textplain_get_raw_data(c, s->start_idx,
- s->end_idx, &length);
+ text = textplain_get_raw_data(c, s->start_idx, s->end_idx, &length);
if (text && !handler(text, length, NULL, handle, NULL, 0))
return false;
@@ -726,7 +718,7 @@ void selection_clear(struct selection *s, bool redraw)
{
int old_start, old_end;
bool was_defined;
- struct browser_window *bw;
+ struct browser_window *top;
assert(s);
was_defined = selection_defined(s);
@@ -740,11 +732,9 @@ void selection_clear(struct selection *s, bool redraw)
if (!s->bw)
return;
- bw = s->bw;
- while (bw && !bw->window && bw->parent)
- bw = bw->parent;
+ top = browser_window_get_root(s->bw);
- gui_clear_selection(bw->window);
+ gui_clear_selection(top->window);
if (redraw && was_defined)
selection_redraw(s, old_start, old_end);
diff --git a/render/html.c b/render/html.c
index a45e26b7e..d77cfd981 100644
--- a/render/html.c
+++ b/render/html.c
@@ -34,6 +34,7 @@
#include "desktop/browser.h"
#include "desktop/gui.h"
#include "desktop/options.h"
+#include "desktop/selection.h"
#include "image/bitmap.h"
#include "render/box.h"
#include "render/font.h"
@@ -1929,6 +1930,8 @@ void html_open(struct content *c, struct browser_window *bw,
html->page = (html_content *) page;
html->box = box;
+ selection_set_browser_window(bw->sel, bw);
+
for (object = html->object_list; object != NULL; object = next) {
next = object->next;
@@ -1955,6 +1958,9 @@ void html_close(struct content *c)
html_content *html = (html_content *) c;
struct content_html_object *object, *next;
+ if (html->bw && html->bw->sel)
+ selection_set_browser_window(html->bw->sel, NULL);
+
html->bw = NULL;
for (object = html->object_list; object != NULL; object = next) {
diff --git a/render/textplain.c b/render/textplain.c
index dca563178..6827ab5d8 100644
--- a/render/textplain.c
+++ b/render/textplain.c
@@ -108,6 +108,7 @@ static bool textplain_redraw(struct content *c, struct content_redraw_data *data
static void textplain_open(struct content *c, struct browser_window *bw,
struct content *page, struct box *box,
struct object_params *params);
+void textplain_close(struct content *c);
static nserror textplain_clone(const struct content *old,
struct content **newc);
static content_type textplain_content_type(lwc_string *mime_type);
@@ -132,6 +133,7 @@ static const content_handler textplain_content_handler = {
.mouse_action = textplain_mouse_action,
.redraw = textplain_redraw,
.open = textplain_open,
+ .close = textplain_close,
.clone = textplain_clone,
.type = textplain_content_type,
.no_share = true,
@@ -820,9 +822,24 @@ void textplain_open(struct content *c, struct browser_window *bw,
struct content *page, struct box *box,
struct object_params *params)
{
- textplain_content *textplain = (textplain_content *) c;
+ textplain_content *text = (textplain_content *) c;
+
+ text->bw = bw;
+}
+
+
+/**
+ * Handle a window containing a CONTENT_TEXTPLAIN being closed.
+ */
+
+void textplain_close(struct content *c)
+{
+ textplain_content *text = (textplain_content *) c;
+
+ if (text->bw && text->bw->sel)
+ selection_set_browser_window(text->bw->sel, NULL);
- textplain->bw = bw;
+ text->bw = NULL;
}
/**