2020-05-23 20:39:25 +03:00
|
|
|
/*
|
2020-05-24 12:38:22 +03:00
|
|
|
* Copyright 2020 Vincent Sanders <vince@netsurf-browser.org>
|
2020-05-23 20:39:25 +03:00
|
|
|
*
|
|
|
|
* This file is part of NetSurf, http://www.netsurf-browser.org/
|
|
|
|
*
|
|
|
|
* NetSurf is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; version 2 of the License.
|
|
|
|
*
|
|
|
|
* NetSurf is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \file
|
2020-05-24 12:38:22 +03:00
|
|
|
* implementation of text selection for a HTML content.
|
2020-05-23 20:39:25 +03:00
|
|
|
*/
|
|
|
|
|
2020-05-24 12:38:22 +03:00
|
|
|
#include <stdlib.h>
|
2020-05-23 20:39:25 +03:00
|
|
|
|
2020-05-24 12:38:22 +03:00
|
|
|
#include "utils/errors.h"
|
2020-05-23 20:39:25 +03:00
|
|
|
#include "utils/utils.h"
|
2020-05-24 12:38:22 +03:00
|
|
|
#include "netsurf/types.h"
|
|
|
|
#include "netsurf/plot_style.h"
|
2020-05-23 20:39:25 +03:00
|
|
|
#include "desktop/selection.h"
|
|
|
|
#include "desktop/save_text.h"
|
|
|
|
|
2020-05-24 12:38:22 +03:00
|
|
|
#include "html/private.h"
|
2020-05-23 20:39:25 +03:00
|
|
|
#include "html/box.h"
|
|
|
|
#include "html/box_inspect.h"
|
|
|
|
#include "html/font.h"
|
|
|
|
#include "html/textselection.h"
|
|
|
|
|
|
|
|
#define SPACE_LEN(b) ((b->space == 0) ? 0 : 1)
|
|
|
|
|
|
|
|
struct rdw_info {
|
|
|
|
bool inited;
|
|
|
|
struct rect r;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests whether a text box lies partially within the given range of
|
|
|
|
* byte offsets, returning the start and end indexes of the bytes
|
|
|
|
* that are enclosed.
|
|
|
|
*
|
|
|
|
* \param box box to be tested
|
|
|
|
* \param start_idx byte offset of start of range
|
|
|
|
* \param end_idx byte offset of end of range
|
|
|
|
* \param start_offset receives the start offset of the selected part
|
|
|
|
* \param end_offset receives the end offset of the selected part
|
|
|
|
* \return true iff the range encloses at least part of the box
|
|
|
|
*/
|
|
|
|
static bool
|
|
|
|
selected_part(struct box *box,
|
|
|
|
unsigned start_idx,
|
|
|
|
unsigned end_idx,
|
|
|
|
unsigned *start_offset,
|
|
|
|
unsigned *end_offset)
|
|
|
|
{
|
|
|
|
size_t box_length = box->length + SPACE_LEN(box);
|
|
|
|
|
|
|
|
if (box_length > 0) {
|
|
|
|
if ((box->byte_offset >= start_idx) &&
|
|
|
|
(box->byte_offset + box_length <= end_idx)) {
|
|
|
|
|
|
|
|
/* fully enclosed */
|
|
|
|
*start_offset = 0;
|
|
|
|
*end_offset = box_length;
|
|
|
|
return true;
|
|
|
|
} else if ((box->byte_offset + box_length > start_idx) &&
|
|
|
|
(box->byte_offset < end_idx)) {
|
|
|
|
/* partly enclosed */
|
|
|
|
int offset = 0;
|
|
|
|
int len;
|
|
|
|
|
|
|
|
if (box->byte_offset < start_idx) {
|
|
|
|
offset = start_idx - box->byte_offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
len = box_length - offset;
|
|
|
|
|
|
|
|
if (box->byte_offset + box_length > end_idx) {
|
|
|
|
len = end_idx - (box->byte_offset + offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
*start_offset = offset;
|
|
|
|
*end_offset = offset + len;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2020-05-24 12:38:22 +03:00
|
|
|
* Traverse the given box subtree adding the boxes inside the
|
|
|
|
* selection to the coordinate range.
|
2020-05-23 20:39:25 +03:00
|
|
|
*
|
|
|
|
* \param box box subtree
|
|
|
|
* \param start_idx start of range within textual representation (bytes)
|
|
|
|
* \param end_idx end of range
|
|
|
|
* \param rdwi redraw range to fill in
|
|
|
|
* \param do_marker whether deal enter any marker box
|
2020-05-24 12:38:22 +03:00
|
|
|
* \return NSERROR_OK on success else error code
|
2020-05-23 20:39:25 +03:00
|
|
|
*/
|
2020-05-24 12:38:22 +03:00
|
|
|
static nserror
|
2020-05-23 20:39:25 +03:00
|
|
|
coords_from_range(struct box *box,
|
|
|
|
unsigned start_idx,
|
|
|
|
unsigned end_idx,
|
|
|
|
struct rdw_info *rdwi,
|
|
|
|
bool do_marker)
|
|
|
|
{
|
|
|
|
struct box *child;
|
2020-05-24 12:38:22 +03:00
|
|
|
nserror res;
|
2020-05-23 20:39:25 +03:00
|
|
|
|
|
|
|
assert(box);
|
|
|
|
|
|
|
|
/* If selection starts inside marker */
|
|
|
|
if (box->parent &&
|
|
|
|
box->parent->list_marker == box &&
|
|
|
|
!do_marker) {
|
|
|
|
/* set box to main list element */
|
|
|
|
box = box->parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If box has a list marker */
|
|
|
|
if (box->list_marker) {
|
|
|
|
/* do the marker box before continuing with the rest of the
|
|
|
|
* list element */
|
2020-05-24 12:38:22 +03:00
|
|
|
res = coords_from_range(box->list_marker,
|
|
|
|
start_idx,
|
|
|
|
end_idx,
|
|
|
|
rdwi,
|
|
|
|
true);
|
|
|
|
if (res != NSERROR_OK) {
|
|
|
|
return res;
|
2020-05-23 20:39:25 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* we can prune this subtree, it's after the selection */
|
|
|
|
if (box->byte_offset >= end_idx) {
|
2020-05-24 12:38:22 +03:00
|
|
|
return NSERROR_OK;
|
2020-05-23 20:39:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* read before calling the handler in case it modifies the tree */
|
|
|
|
child = box->children;
|
|
|
|
|
|
|
|
if ((box->type != BOX_BR) &&
|
|
|
|
!((box->type == BOX_FLOAT_LEFT ||
|
|
|
|
box->type == BOX_FLOAT_RIGHT) &&
|
|
|
|
!box->text)) {
|
2020-05-24 12:38:22 +03:00
|
|
|
unsigned start_off;
|
|
|
|
unsigned end_off;
|
2020-05-23 20:39:25 +03:00
|
|
|
|
2020-05-24 12:38:22 +03:00
|
|
|
if (selected_part(box, start_idx, end_idx, &start_off, &end_off)) {
|
2020-05-23 20:39:25 +03:00
|
|
|
int width, height;
|
|
|
|
int x, y;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \todo it should be possible to reduce the redrawn
|
|
|
|
* area using the offsets
|
|
|
|
*/
|
|
|
|
box_coords(box, &x, &y);
|
|
|
|
|
|
|
|
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 != 0)) {
|
|
|
|
width += box->space;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rdwi->inited) {
|
|
|
|
if (x < rdwi->r.x0) {
|
|
|
|
rdwi->r.x0 = x;
|
|
|
|
}
|
|
|
|
if (y < rdwi->r.y0) {
|
|
|
|
rdwi->r.y0 = y;
|
|
|
|
}
|
|
|
|
if (x + width > rdwi->r.x1) {
|
|
|
|
rdwi->r.x1 = x + width;
|
|
|
|
}
|
|
|
|
if (y + height > rdwi->r.y1) {
|
|
|
|
rdwi->r.y1 = y + height;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
rdwi->inited = true;
|
|
|
|
rdwi->r.x0 = x;
|
|
|
|
rdwi->r.y0 = y;
|
|
|
|
rdwi->r.x1 = x + width;
|
|
|
|
rdwi->r.y1 = y + height;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* find the first child that could lie partially within the selection;
|
|
|
|
* this is important at the top-levels of the tree for pruning subtrees
|
|
|
|
* that lie entirely before the selection */
|
|
|
|
|
|
|
|
if (child) {
|
|
|
|
struct box *next = child->next;
|
|
|
|
|
|
|
|
while (next && next->byte_offset < start_idx) {
|
|
|
|
child = next;
|
|
|
|
next = child->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (child) {
|
|
|
|
/* read before calling the handler in case it modifies
|
|
|
|
* the tree */
|
|
|
|
struct box *next = child->next;
|
|
|
|
|
2020-05-24 12:38:22 +03:00
|
|
|
res = coords_from_range(child,
|
|
|
|
start_idx,
|
|
|
|
end_idx,
|
|
|
|
rdwi,
|
|
|
|
false);
|
|
|
|
if (res != NSERROR_OK) {
|
|
|
|
return res;
|
2020-05-23 20:39:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
child = next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NSERROR_OK;
|
|
|
|
}
|
2020-05-23 22:38:41 +03:00
|
|
|
|
2020-05-24 12:38:22 +03:00
|
|
|
|
2020-05-23 22:38:41 +03:00
|
|
|
/**
|
2020-05-24 12:38:22 +03:00
|
|
|
* Append the contents of a box to a selection along with style information
|
2020-05-23 22:38:41 +03:00
|
|
|
*
|
2020-05-24 12:38:22 +03:00
|
|
|
* \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
|
2021-03-29 12:45:59 +03:00
|
|
|
* \param unit_len_ctx Length conversion context
|
2020-05-24 12:38:22 +03:00
|
|
|
* \param handle selection string to append to
|
|
|
|
* \param whitespace_text whitespace to place before text for formatting
|
2020-05-23 22:38:41 +03:00
|
|
|
* may be NULL
|
2020-05-24 12:38:22 +03:00
|
|
|
* \param whitespace_length length of whitespace_text
|
|
|
|
* \return NSERROR_OK iff successful and traversal should continue else error code
|
2020-05-23 22:38:41 +03:00
|
|
|
*/
|
2020-05-24 12:38:22 +03:00
|
|
|
static nserror
|
|
|
|
selection_copy_box(const char *text,
|
|
|
|
size_t length,
|
|
|
|
struct box *box,
|
2021-03-29 12:45:59 +03:00
|
|
|
const css_unit_ctx *unit_len_ctx,
|
2020-05-24 12:38:22 +03:00
|
|
|
struct selection_string *handle,
|
|
|
|
const char *whitespace_text,
|
|
|
|
size_t whitespace_length)
|
2020-05-23 22:38:41 +03:00
|
|
|
{
|
|
|
|
bool add_space = false;
|
|
|
|
plot_font_style_t style;
|
|
|
|
plot_font_style_t *pstyle = NULL;
|
|
|
|
|
|
|
|
/* 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,
|
|
|
|
pstyle,
|
|
|
|
handle)) {
|
2020-05-24 12:38:22 +03:00
|
|
|
return NSERROR_NOMEM;
|
2020-05-23 22:38:41 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (box != NULL) {
|
|
|
|
/* HTML */
|
|
|
|
add_space = (box->space != 0);
|
|
|
|
|
|
|
|
if (box->style != NULL) {
|
|
|
|
/* Override default font style */
|
2021-03-29 12:45:59 +03:00
|
|
|
font_plot_style_from_css(unit_len_ctx, box->style, &style);
|
2020-05-23 22:38:41 +03:00
|
|
|
pstyle = &style;
|
|
|
|
} else {
|
|
|
|
/* If there's no style, there must be no text */
|
|
|
|
assert(box->text == NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* add the text from this box */
|
|
|
|
if (!selection_string_append(text, length, add_space, pstyle, handle)) {
|
2020-05-24 12:38:22 +03:00
|
|
|
return NSERROR_NOMEM;
|
2020-05-23 22:38:41 +03:00
|
|
|
}
|
|
|
|
|
2020-05-24 12:38:22 +03:00
|
|
|
return NSERROR_OK;
|
2020-05-23 22:38:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Traverse the given box subtree, calling selection copy for all
|
|
|
|
* boxes that lie (partially) within the given range
|
|
|
|
*
|
|
|
|
* \param box box subtree
|
2021-03-29 12:45:59 +03:00
|
|
|
* \param unit_len_ctx Length conversion context.
|
2020-05-23 22:38:41 +03:00
|
|
|
* \param start_idx start of range within textual representation (bytes)
|
|
|
|
* \param end_idx end of range
|
|
|
|
* \param handler handler function to call
|
|
|
|
* \param handle handle to pass
|
|
|
|
* \param before type of whitespace to place before next encountered text
|
|
|
|
* \param first whether this is the first box with text
|
|
|
|
* \param do_marker whether deal enter any marker box
|
2020-05-24 12:38:22 +03:00
|
|
|
* \return NSERROR_OK on sucess else error code
|
2020-05-23 22:38:41 +03:00
|
|
|
*/
|
2020-05-24 12:38:22 +03:00
|
|
|
static nserror
|
|
|
|
selection_copy(struct box *box,
|
2021-03-29 12:45:59 +03:00
|
|
|
const css_unit_ctx *unit_len_ctx,
|
2020-05-24 12:38:22 +03:00
|
|
|
unsigned start_idx,
|
|
|
|
unsigned end_idx,
|
|
|
|
struct selection_string *selstr,
|
|
|
|
save_text_whitespace *before,
|
|
|
|
bool *first,
|
|
|
|
bool do_marker)
|
2020-05-23 22:38:41 +03:00
|
|
|
{
|
2020-05-24 12:38:22 +03:00
|
|
|
nserror res;
|
2020-05-23 22:38:41 +03:00
|
|
|
struct box *child;
|
|
|
|
const char *whitespace_text = "";
|
|
|
|
size_t whitespace_length = 0;
|
|
|
|
|
|
|
|
assert(box);
|
|
|
|
|
|
|
|
/* If selection starts inside marker */
|
|
|
|
if (box->parent &&
|
|
|
|
box->parent->list_marker == box &&
|
|
|
|
!do_marker) {
|
|
|
|
/* set box to main list element */
|
|
|
|
box = box->parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If box has a list marker */
|
|
|
|
if (box->list_marker) {
|
|
|
|
/* do the marker box before continuing with the rest of the
|
|
|
|
* list element */
|
2020-05-24 12:38:22 +03:00
|
|
|
res = selection_copy(box->list_marker,
|
2021-03-29 12:45:59 +03:00
|
|
|
unit_len_ctx,
|
2020-05-24 12:38:22 +03:00
|
|
|
start_idx,
|
|
|
|
end_idx,
|
|
|
|
selstr,
|
|
|
|
before,
|
|
|
|
first,
|
|
|
|
true);
|
|
|
|
if (res != NSERROR_OK) {
|
|
|
|
return res;
|
2020-05-23 22:38:41 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* we can prune this subtree, it's after the selection */
|
|
|
|
if (box->byte_offset >= end_idx) {
|
2020-05-24 12:38:22 +03:00
|
|
|
return NSERROR_OK;
|
2020-05-23 22:38:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* read before calling the handler in case it modifies the tree */
|
|
|
|
child = box->children;
|
|
|
|
|
|
|
|
/* If nicely formatted output of the selected text is required, work
|
|
|
|
* out what whitespace should be placed before the next bit of text */
|
|
|
|
if (before) {
|
|
|
|
save_text_solve_whitespace(box,
|
|
|
|
first,
|
|
|
|
before,
|
|
|
|
&whitespace_text,
|
|
|
|
&whitespace_length);
|
|
|
|
} else {
|
|
|
|
whitespace_text = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((box->type != BOX_BR) &&
|
|
|
|
!((box->type == BOX_FLOAT_LEFT ||
|
|
|
|
box->type == BOX_FLOAT_RIGHT) &&
|
|
|
|
!box->text)) {
|
2020-05-24 12:38:22 +03:00
|
|
|
unsigned start_off;
|
|
|
|
unsigned end_off;
|
|
|
|
|
|
|
|
if (selected_part(box, start_idx, end_idx, &start_off, &end_off)) {
|
|
|
|
res = selection_copy_box(box->text + start_off,
|
|
|
|
min(box->length, end_off) - start_off,
|
|
|
|
box,
|
2021-03-29 12:45:59 +03:00
|
|
|
unit_len_ctx,
|
2020-05-24 12:38:22 +03:00
|
|
|
selstr,
|
|
|
|
whitespace_text,
|
|
|
|
whitespace_length);
|
|
|
|
if (res != NSERROR_OK) {
|
|
|
|
return res;
|
2020-05-23 22:38:41 +03:00
|
|
|
}
|
|
|
|
if (before) {
|
|
|
|
*first = false;
|
|
|
|
*before = WHITESPACE_NONE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* find the first child that could lie partially within the selection;
|
|
|
|
* this is important at the top-levels of the tree for pruning subtrees
|
|
|
|
* that lie entirely before the selection */
|
|
|
|
|
|
|
|
if (child) {
|
|
|
|
struct box *next = child->next;
|
|
|
|
|
|
|
|
while (next && next->byte_offset < start_idx) {
|
|
|
|
child = next;
|
|
|
|
next = child->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (child) {
|
|
|
|
/* read before calling the handler in case it modifies
|
|
|
|
* the tree */
|
|
|
|
struct box *next = child->next;
|
|
|
|
|
2020-05-24 12:38:22 +03:00
|
|
|
res = selection_copy(child,
|
2021-03-29 12:45:59 +03:00
|
|
|
unit_len_ctx,
|
2020-05-24 12:38:22 +03:00
|
|
|
start_idx,
|
|
|
|
end_idx,
|
|
|
|
selstr,
|
|
|
|
before,
|
|
|
|
first,
|
|
|
|
false);
|
|
|
|
if (res != NSERROR_OK) {
|
|
|
|
return res;
|
2020-05-23 22:38:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
child = next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NSERROR_OK;
|
|
|
|
}
|
2020-05-24 00:00:00 +03:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Label each text box in the given box subtree with its position
|
|
|
|
* in a textual representation of the content.
|
|
|
|
*
|
|
|
|
* \param box The box at root of subtree
|
|
|
|
* \param idx current position within textual representation
|
|
|
|
* \return updated position
|
|
|
|
*/
|
|
|
|
static unsigned selection_label_subtree(struct box *box, unsigned idx)
|
|
|
|
{
|
2020-07-12 15:47:52 +03:00
|
|
|
struct box *child;
|
|
|
|
|
|
|
|
assert(box != NULL);
|
|
|
|
|
2020-07-12 20:49:47 +03:00
|
|
|
child = box->children;
|
2020-05-24 00:00:00 +03:00
|
|
|
|
|
|
|
box->byte_offset = idx;
|
|
|
|
|
|
|
|
if (box->text) {
|
|
|
|
idx += box->length + SPACE_LEN(box);
|
|
|
|
}
|
|
|
|
|
|
|
|
while (child) {
|
|
|
|
if (child->list_marker) {
|
|
|
|
idx = selection_label_subtree(child->list_marker, idx);
|
|
|
|
}
|
|
|
|
|
|
|
|
idx = selection_label_subtree(child, idx);
|
|
|
|
child = child->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
return idx;
|
|
|
|
}
|
|
|
|
|
2020-05-24 12:38:22 +03:00
|
|
|
|
|
|
|
/* exported interface documented in html/textselection.h */
|
|
|
|
nserror
|
|
|
|
html_textselection_redraw(struct content *c,
|
|
|
|
unsigned start_idx,
|
|
|
|
unsigned end_idx)
|
|
|
|
{
|
|
|
|
nserror res;
|
|
|
|
html_content *html = (html_content *)c;
|
|
|
|
struct rdw_info rdw;
|
|
|
|
|
2020-07-12 15:47:52 +03:00
|
|
|
if (html->layout == NULL) {
|
|
|
|
return NSERROR_INVALID;
|
|
|
|
}
|
|
|
|
|
2020-05-24 12:38:22 +03:00
|
|
|
rdw.inited = false;
|
|
|
|
|
|
|
|
res = coords_from_range(html->layout, start_idx, end_idx, &rdw, false);
|
|
|
|
if (res != NSERROR_OK) {
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rdw.inited) {
|
|
|
|
content__request_redraw(c,
|
|
|
|
rdw.r.x0,
|
|
|
|
rdw.r.y0,
|
|
|
|
rdw.r.x1 - rdw.r.x0,
|
|
|
|
rdw.r.y1 - rdw.r.y0);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NSERROR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* exported interface documented in html/textselection.h */
|
|
|
|
nserror
|
|
|
|
html_textselection_copy(struct content *c,
|
|
|
|
unsigned start_idx,
|
|
|
|
unsigned end_idx,
|
|
|
|
struct selection_string *selstr)
|
|
|
|
{
|
|
|
|
html_content *html = (html_content *)c;
|
|
|
|
save_text_whitespace before = WHITESPACE_NONE;
|
|
|
|
bool first = true;
|
|
|
|
|
2020-07-12 15:47:52 +03:00
|
|
|
if (html->layout == NULL) {
|
|
|
|
return NSERROR_INVALID;
|
|
|
|
}
|
|
|
|
|
2020-05-24 12:38:22 +03:00
|
|
|
return selection_copy(html->layout,
|
2021-03-29 12:45:59 +03:00
|
|
|
&html->unit_len_ctx,
|
2020-05-24 12:38:22 +03:00
|
|
|
start_idx,
|
|
|
|
end_idx,
|
|
|
|
selstr,
|
|
|
|
&before,
|
|
|
|
&first,
|
|
|
|
false);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-05-24 00:00:00 +03:00
|
|
|
/* exported interface documented in html/textselection.h */
|
|
|
|
nserror
|
|
|
|
html_textselection_get_end(struct content *c, unsigned *end_idx)
|
|
|
|
{
|
|
|
|
html_content *html = (html_content *)c;
|
|
|
|
unsigned root_idx;
|
|
|
|
|
2020-07-12 15:47:52 +03:00
|
|
|
if (html->layout == NULL) {
|
|
|
|
return NSERROR_INVALID;
|
|
|
|
}
|
|
|
|
|
2020-05-24 00:00:00 +03:00
|
|
|
root_idx = 0;
|
|
|
|
|
|
|
|
*end_idx = selection_label_subtree(html->layout, root_idx);
|
2020-05-24 12:38:22 +03:00
|
|
|
|
2020-05-24 00:00:00 +03:00
|
|
|
return NSERROR_OK;
|
|
|
|
}
|