mirror of
https://github.com/netsurf-browser/netsurf
synced 2024-12-22 04:02:34 +03:00
make text selection context an opaque interface
This commit is contained in:
parent
6108d210d5
commit
5ce8f0baf1
@ -493,7 +493,7 @@ html_create_html_data(html_content *c, const http_parameter *params)
|
||||
return NSERROR_NOMEM;
|
||||
}
|
||||
|
||||
selection_prepare(&c->sel, (struct content *)c);
|
||||
c->sel = selection_create((struct content *)c);
|
||||
|
||||
nerror = http_parameter_list_find_item(params, corestring_lwc_charset, &charset);
|
||||
if (nerror == NSERROR_OK) {
|
||||
@ -1056,7 +1056,7 @@ static void html_reformat(struct content *c, int width, int height)
|
||||
if (c->height < layout->y + layout->descendant_y1)
|
||||
c->height = layout->y + layout->descendant_y1;
|
||||
|
||||
selection_reinit(&htmlc->sel);
|
||||
selection_reinit(htmlc->sel);
|
||||
|
||||
htmlc->reflowing = false;
|
||||
htmlc->had_initial_layout = true;
|
||||
@ -1184,6 +1184,8 @@ static void html_destroy(struct content *c)
|
||||
}
|
||||
}
|
||||
|
||||
selection_destroy(html->sel);
|
||||
|
||||
/* Destroy forms */
|
||||
for (f = html->forms; f != NULL; f = g) {
|
||||
g = f->prev;
|
||||
@ -1304,7 +1306,7 @@ html_open(struct content *c,
|
||||
html->drag_owner.no_owner = true;
|
||||
|
||||
/* text selection */
|
||||
selection_init(&html->sel);
|
||||
selection_init(html->sel);
|
||||
html->selection_type = HTML_SELECTION_NONE;
|
||||
html->selection_owner.none = true;
|
||||
|
||||
@ -1323,7 +1325,7 @@ static nserror html_close(struct content *c)
|
||||
html_content *htmlc = (html_content *) c;
|
||||
nserror ret = NSERROR_OK;
|
||||
|
||||
selection_clear(&htmlc->sel, false);
|
||||
selection_clear(htmlc->sel, false);
|
||||
|
||||
/* clear the html content reference to the browser window */
|
||||
htmlc->bw = NULL;
|
||||
@ -1359,7 +1361,7 @@ static void html_clear_selection(struct content *c)
|
||||
break;
|
||||
case HTML_SELECTION_SELF:
|
||||
assert(html->selection_owner.none == false);
|
||||
selection_clear(&html->sel, true);
|
||||
selection_clear(html->sel, true);
|
||||
break;
|
||||
case HTML_SELECTION_CONTENT:
|
||||
content_clear_selection(html->selection_owner.content->object);
|
||||
@ -1388,7 +1390,7 @@ static char *html_get_selection(struct content *c)
|
||||
gadget->data.text.ta);
|
||||
case HTML_SELECTION_SELF:
|
||||
assert(html->selection_owner.none == false);
|
||||
return selection_get_copy(&html->sel);
|
||||
return selection_get_copy(html->sel);
|
||||
case HTML_SELECTION_CONTENT:
|
||||
return content_get_selection(
|
||||
html->selection_owner.content->object);
|
||||
|
@ -401,14 +401,14 @@ mouse_action_drag_selection(html_content *html,
|
||||
|
||||
if (!mouse) {
|
||||
/* End of selection drag */
|
||||
if (selection_dragging_start(&html->sel)) {
|
||||
if (selection_dragging_start(html->sel)) {
|
||||
dir = 1;
|
||||
}
|
||||
|
||||
idx = html_selection_drag_end(html, mouse, x, y, dir);
|
||||
|
||||
if (idx != 0) {
|
||||
selection_track(&html->sel, mouse, idx);
|
||||
selection_track(html->sel, mouse, idx);
|
||||
}
|
||||
|
||||
drag_owner.no_owner = true;
|
||||
@ -417,7 +417,7 @@ mouse_action_drag_selection(html_content *html,
|
||||
return NSERROR_OK;
|
||||
}
|
||||
|
||||
if (selection_dragging_start(&html->sel)) {
|
||||
if (selection_dragging_start(html->sel)) {
|
||||
dir = 1;
|
||||
}
|
||||
|
||||
@ -432,7 +432,7 @@ mouse_action_drag_selection(html_content *html,
|
||||
&idx,
|
||||
&pixel_offset);
|
||||
|
||||
selection_track(&html->sel, mouse, box->byte_offset + idx);
|
||||
selection_track(html->sel, mouse, box->byte_offset + idx);
|
||||
}
|
||||
return NSERROR_OK;
|
||||
}
|
||||
@ -1219,7 +1219,7 @@ default_mouse_action(html_content *html,
|
||||
&idx,
|
||||
&pixel_offset);
|
||||
|
||||
if (selection_click(&html->sel,
|
||||
if (selection_click(html->sel,
|
||||
html->bw,
|
||||
mouse,
|
||||
mas->text.box->byte_offset + idx)) {
|
||||
@ -1229,7 +1229,7 @@ default_mouse_action(html_content *html,
|
||||
html_drag_type drag_type;
|
||||
union html_drag_owner drag_owner;
|
||||
|
||||
if (selection_dragging(&html->sel)) {
|
||||
if (selection_dragging(html->sel)) {
|
||||
drag_type = HTML_DRAG_SELECTION;
|
||||
drag_owner.no_owner = true;
|
||||
html_set_drag_type(html,
|
||||
@ -1244,10 +1244,10 @@ default_mouse_action(html_content *html,
|
||||
|
||||
} else if (mouse & BROWSER_MOUSE_PRESS_1) {
|
||||
sel_owner.none = true;
|
||||
selection_clear(&html->sel, true);
|
||||
selection_clear(html->sel, true);
|
||||
}
|
||||
|
||||
if (selection_active(&html->sel)) {
|
||||
if (selection_active(html->sel)) {
|
||||
sel_owner.none = false;
|
||||
html_set_selection(html,
|
||||
HTML_SELECTION_SELF,
|
||||
@ -1518,7 +1518,7 @@ html_mouse_action(struct content *c,
|
||||
bool html_keypress(struct content *c, uint32_t key)
|
||||
{
|
||||
html_content *html = (html_content *) c;
|
||||
struct selection *sel = &html->sel;
|
||||
struct selection *sel = html->sel;
|
||||
|
||||
/** \todo
|
||||
* At the moment, the front end interface for keypress only gives
|
||||
@ -1763,7 +1763,7 @@ void html_set_selection(html_content *html, html_selection_type selection_type,
|
||||
case HTML_SELECTION_SELF:
|
||||
if (same_type)
|
||||
break;
|
||||
selection_clear(&html->sel, true);
|
||||
selection_clear(html->sel, true);
|
||||
break;
|
||||
case HTML_SELECTION_TEXTAREA:
|
||||
if (same_type && html->selection_owner.textarea ==
|
||||
|
@ -28,13 +28,13 @@
|
||||
|
||||
#include "netsurf/types.h"
|
||||
#include "content/content_protected.h"
|
||||
#include "desktop/selection.h"
|
||||
#include "content/handlers/css/utils.h"
|
||||
|
||||
|
||||
struct gui_layout_table;
|
||||
struct scrollbar_msg_data;
|
||||
struct content_redraw_data;
|
||||
struct selection;
|
||||
|
||||
typedef enum {
|
||||
HTML_DRAG_NONE, /** No drag */
|
||||
@ -203,7 +203,7 @@ typedef struct html_content {
|
||||
union html_focus_owner focus_owner;
|
||||
|
||||
/** HTML content's own text selection object */
|
||||
struct selection sel;
|
||||
struct selection *sel;
|
||||
|
||||
/**
|
||||
* Open core-handled form SELECT menu, or NULL if none
|
||||
|
@ -1148,7 +1148,7 @@ static bool html_redraw_text_box(const html_content *html, struct box *box,
|
||||
scale,
|
||||
excluded,
|
||||
(struct content *)html,
|
||||
&html->sel,
|
||||
html->sel,
|
||||
ctx))
|
||||
return false;
|
||||
|
||||
|
@ -69,7 +69,7 @@ typedef struct textplain_content {
|
||||
int formatted_width;
|
||||
struct browser_window *bw;
|
||||
|
||||
struct selection sel; /** Selection state */
|
||||
struct selection *sel; /** Selection state */
|
||||
|
||||
} textplain_content;
|
||||
|
||||
@ -168,8 +168,7 @@ textplain_create_internal(textplain_content *c, lwc_string *encoding)
|
||||
c->physical_line_count = 0;
|
||||
c->formatted_width = 0;
|
||||
c->bw = NULL;
|
||||
|
||||
selection_prepare(&c->sel, (struct content *)c);
|
||||
c->sel = selection_create((struct content *)c);
|
||||
|
||||
return NSERROR_OK;
|
||||
|
||||
@ -538,6 +537,10 @@ static void textplain_destroy(struct content *c)
|
||||
if (text->utf8_data != NULL) {
|
||||
free(text->utf8_data);
|
||||
}
|
||||
|
||||
if (text->sel != NULL) {
|
||||
selection_destroy(text->sel);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -707,9 +710,9 @@ textplain_mouse_action(struct content *c,
|
||||
browser_window_set_drag_type(bw, DRAGGING_NONE, NULL);
|
||||
|
||||
idx = textplain_offset_from_coords(c, x, y, dir);
|
||||
if (selection_click(&text->sel, text->bw, mouse, idx)) {
|
||||
if (selection_click(text->sel, text->bw, mouse, idx)) {
|
||||
|
||||
if (selection_dragging(&text->sel)) {
|
||||
if (selection_dragging(text->sel)) {
|
||||
browser_window_set_drag_type(bw,
|
||||
DRAGGING_SELECTION, NULL);
|
||||
status = messages_get("Selecting");
|
||||
@ -753,11 +756,11 @@ textplain_mouse_track(struct content *c,
|
||||
int dir = -1;
|
||||
size_t idx;
|
||||
|
||||
if (selection_dragging_start(&text->sel))
|
||||
if (selection_dragging_start(text->sel))
|
||||
dir = 1;
|
||||
|
||||
idx = textplain_offset_from_coords(c, x, y, dir);
|
||||
selection_track(&text->sel, mouse, idx);
|
||||
selection_track(text->sel, mouse, idx);
|
||||
|
||||
browser_window_set_drag_type(bw, DRAGGING_NONE, NULL);
|
||||
}
|
||||
@ -768,10 +771,10 @@ textplain_mouse_track(struct content *c,
|
||||
int dir = -1;
|
||||
size_t idx;
|
||||
|
||||
if (selection_dragging_start(&text->sel)) dir = 1;
|
||||
if (selection_dragging_start(text->sel)) dir = 1;
|
||||
|
||||
idx = textplain_offset_from_coords(c, x, y, dir);
|
||||
selection_track(&text->sel, mouse, idx);
|
||||
selection_track(text->sel, mouse, idx);
|
||||
}
|
||||
break;
|
||||
|
||||
@ -794,7 +797,7 @@ textplain_mouse_track(struct content *c,
|
||||
static bool textplain_keypress(struct content *c, uint32_t key)
|
||||
{
|
||||
textplain_content *text = (textplain_content *) c;
|
||||
struct selection *sel = &text->sel;
|
||||
struct selection *sel = text->sel;
|
||||
|
||||
switch (key) {
|
||||
case NS_KEY_COPY_SELECTION:
|
||||
@ -1129,7 +1132,7 @@ textplain_redraw(struct content *c,
|
||||
line_height,
|
||||
data->scale,
|
||||
text,
|
||||
&text->sel,
|
||||
text->sel,
|
||||
ctx)) {
|
||||
return false;
|
||||
}
|
||||
@ -1156,7 +1159,7 @@ textplain_redraw(struct content *c,
|
||||
|
||||
if (bw) {
|
||||
unsigned tab_ofst = line[lineno].start + next_offset;
|
||||
struct selection *sel = &text->sel;
|
||||
struct selection *sel = text->sel;
|
||||
bool highlighted = false;
|
||||
|
||||
unsigned start_idx, end_idx;
|
||||
@ -1220,7 +1223,7 @@ textplain_open(struct content *c,
|
||||
text->bw = bw;
|
||||
|
||||
/* text selection */
|
||||
selection_init(&text->sel);
|
||||
selection_init(text->sel);
|
||||
|
||||
return NSERROR_OK;
|
||||
}
|
||||
@ -1246,7 +1249,7 @@ static char *textplain_get_selection(struct content *c)
|
||||
{
|
||||
textplain_content *text = (textplain_content *) c;
|
||||
|
||||
return selection_get_copy(&text->sel);
|
||||
return selection_get_copy(text->sel);
|
||||
}
|
||||
|
||||
|
||||
|
@ -180,6 +180,7 @@ static void search_show_all(bool all, struct textsearch_context *context)
|
||||
|
||||
a->sel = selection_create(context->c);
|
||||
if (a->sel != NULL) {
|
||||
selection_init(a->sel);
|
||||
selection_set_position(a->sel,
|
||||
a->start_idx,
|
||||
a->end_idx);
|
||||
|
@ -45,6 +45,26 @@ struct selection_string {
|
||||
};
|
||||
|
||||
|
||||
typedef enum {
|
||||
DRAG_NONE,
|
||||
DRAG_START,
|
||||
DRAG_END
|
||||
} seln_drag_state;
|
||||
|
||||
struct selection {
|
||||
struct content *c;
|
||||
struct box *root;
|
||||
|
||||
unsigned max_idx; /* total bytes in text representation */
|
||||
|
||||
unsigned start_idx; /* offset in bytes within text representation */
|
||||
unsigned end_idx;
|
||||
|
||||
bool defined;
|
||||
|
||||
seln_drag_state drag_state;
|
||||
};
|
||||
|
||||
/**
|
||||
* Redraws the given range of text.
|
||||
*
|
||||
@ -236,7 +256,6 @@ struct selection *selection_create(struct content *c)
|
||||
sel = calloc(1, sizeof(struct selection));
|
||||
if (sel) {
|
||||
selection_prepare(sel, c);
|
||||
selection_init(sel);
|
||||
}
|
||||
|
||||
return sel;
|
||||
|
@ -30,26 +30,8 @@ struct box;
|
||||
struct browser_window;
|
||||
struct plot_font_style;
|
||||
struct selection_string;
|
||||
|
||||
typedef enum {
|
||||
DRAG_NONE,
|
||||
DRAG_START,
|
||||
DRAG_END
|
||||
} seln_drag_state;
|
||||
|
||||
struct selection {
|
||||
struct content *c;
|
||||
struct box *root;
|
||||
|
||||
unsigned max_idx; /* total bytes in text representation */
|
||||
|
||||
unsigned start_idx; /* offset in bytes within text representation */
|
||||
unsigned end_idx;
|
||||
|
||||
bool defined;
|
||||
|
||||
seln_drag_state drag_state;
|
||||
};
|
||||
struct selection;
|
||||
struct content;
|
||||
|
||||
/**
|
||||
* determine if a selecion is active
|
||||
|
Loading…
Reference in New Issue
Block a user