NetSurf
Data Structures | Macros | Functions
textselection.c File Reference

implementation of text selection for a HTML content. More...

#include <stdlib.h>
#include "utils/errors.h"
#include "utils/utils.h"
#include "netsurf/types.h"
#include "netsurf/plot_style.h"
#include "desktop/selection.h"
#include "desktop/save_text.h"
#include "html/private.h"
#include "html/box.h"
#include "html/box_inspect.h"
#include "html/font.h"
#include "html/textselection.h"
Include dependency graph for textselection.c:

Go to the source code of this file.

Data Structures

struct  rdw_info
 

Macros

#define SPACE_LEN(b)   ((b->space == 0) ? 0 : 1)
 

Functions

static bool selected_part (struct box *box, unsigned start_idx, unsigned end_idx, unsigned *start_offset, unsigned *end_offset)
 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. More...
 
static nserror coords_from_range (struct box *box, unsigned start_idx, unsigned end_idx, struct rdw_info *rdwi, bool do_marker)
 Traverse the given box subtree adding the boxes inside the selection to the coordinate range. More...
 
static nserror selection_copy_box (const char *text, size_t length, struct box *box, const css_unit_ctx *unit_len_ctx, struct selection_string *handle, const char *whitespace_text, size_t whitespace_length)
 Append the contents of a box to a selection along with style information. More...
 
static nserror selection_copy (struct box *box, const css_unit_ctx *unit_len_ctx, unsigned start_idx, unsigned end_idx, struct selection_string *selstr, save_text_whitespace *before, bool *first, bool do_marker)
 Traverse the given box subtree, calling selection copy for all boxes that lie (partially) within the given range. More...
 
static unsigned selection_label_subtree (struct box *box, unsigned idx)
 Label each text box in the given box subtree with its position in a textual representation of the content. More...
 
nserror html_textselection_redraw (struct content *c, unsigned start_idx, unsigned end_idx)
 
nserror html_textselection_copy (struct content *c, unsigned start_idx, unsigned end_idx, struct selection_string *selstr)
 
nserror html_textselection_get_end (struct content *c, unsigned *end_idx)
 get maximum index of text section. More...
 

Detailed Description

implementation of text selection for a HTML content.

Definition in file textselection.c.

Macro Definition Documentation

◆ SPACE_LEN

#define SPACE_LEN (   b)    ((b->space == 0) ? 0 : 1)

Definition at line 39 of file textselection.c.

Function Documentation

◆ coords_from_range()

static nserror coords_from_range ( struct box box,
unsigned  start_idx,
unsigned  end_idx,
struct rdw_info rdwi,
bool  do_marker 
)
static

Traverse the given box subtree adding the boxes inside the selection to the coordinate range.

Parameters
boxbox subtree
start_idxstart of range within textual representation (bytes)
end_idxend of range
rdwiredraw range to fill in
do_markerwhether deal enter any marker box
Returns
NSERROR_OK on success else error code
Todo:
it should be possible to reduce the redrawn area using the offsets

Definition at line 114 of file textselection.c.

References BOTTOM, BOX_BR, box_coords(), BOX_FLOAT_LEFT, BOX_FLOAT_RIGHT, BOX_TEXT, box::byte_offset, box::children, coords_from_range(), box::height, height, rdw_info::inited, LEFT, box::list_marker, box::next, NSERROR_OK, box::padding, box::parent, rdw_info::r, RIGHT, selected_part(), box::space, box::text, TOP, box::type, box::width, width, box::x, rect::x0, rect::x1, box::y, rect::y0, and rect::y1.

Referenced by coords_from_range(), and html_textselection_redraw().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ html_textselection_copy()

nserror html_textselection_copy ( struct content c,
unsigned  start_idx,
unsigned  end_idx,
struct selection_string selstr 
)

Definition at line 507 of file textselection.c.

References html_content::layout, NSERROR_INVALID, selection_copy(), html_content::unit_len_ctx, and WHITESPACE_NONE.

Here is the call graph for this function:

◆ html_textselection_get_end()

nserror html_textselection_get_end ( struct content c,
unsigned *  end_idx 
)

get maximum index of text section.

Parameters
[in]cThe content to measure
[out]end_idxpointer to value to recive result
Returns
NSERROR_OK and end_idx updated else error code

Definition at line 533 of file textselection.c.

References html_content::layout, NSERROR_INVALID, NSERROR_OK, and selection_label_subtree().

Here is the call graph for this function:

◆ html_textselection_redraw()

nserror html_textselection_redraw ( struct content c,
unsigned  start_idx,
unsigned  end_idx 
)

Definition at line 474 of file textselection.c.

References content__request_redraw(), coords_from_range(), rdw_info::inited, html_content::layout, NSERROR_INVALID, NSERROR_OK, rdw_info::r, rect::x0, rect::x1, rect::y0, and rect::y1.

Here is the call graph for this function:

◆ selected_part()

static bool selected_part ( struct box box,
unsigned  start_idx,
unsigned  end_idx,
unsigned *  start_offset,
unsigned *  end_offset 
)
static

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.

Parameters
boxbox to be tested
start_idxbyte offset of start of range
end_idxbyte offset of end of range
start_offsetreceives the start offset of the selected part
end_offsetreceives the end offset of the selected part
Returns
true iff the range encloses at least part of the box

Definition at line 60 of file textselection.c.

References box::byte_offset, box::length, and SPACE_LEN.

Referenced by coords_from_range(), and selection_copy().

Here is the caller graph for this function:

◆ selection_copy()

static nserror selection_copy ( struct box box,
const css_unit_ctx *  unit_len_ctx,
unsigned  start_idx,
unsigned  end_idx,
struct selection_string selstr,
save_text_whitespace before,
bool *  first,
bool  do_marker 
)
static

Traverse the given box subtree, calling selection copy for all boxes that lie (partially) within the given range.

Parameters
boxbox subtree
unit_len_ctxLength conversion context.
start_idxstart of range within textual representation (bytes)
end_idxend of range
handlerhandler function to call
handlehandle to pass
beforetype of whitespace to place before next encountered text
firstwhether this is the first box with text
do_markerwhether deal enter any marker box
Returns
NSERROR_OK on sucess else error code

Definition at line 314 of file textselection.c.

References BOX_BR, BOX_FLOAT_LEFT, BOX_FLOAT_RIGHT, box::byte_offset, box::children, box::length, box::list_marker, min, box::next, NSERROR_OK, box::parent, save_text_solve_whitespace(), selected_part(), selection_copy(), selection_copy_box(), box::text, box::type, and WHITESPACE_NONE.

Referenced by html_textselection_copy(), and selection_copy().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ selection_copy_box()

static nserror selection_copy_box ( const char *  text,
size_t  length,
struct box box,
const css_unit_ctx *  unit_len_ctx,
struct selection_string handle,
const char *  whitespace_text,
size_t  whitespace_length 
)
static

Append the contents of a box to a selection along with style information.

Parameters
textpointer to text being added, or NULL for newline
lengthlength of text to be appended (bytes)
boxpointer to text box, or NULL if from textplain
unit_len_ctxLength conversion context
handleselection string to append to
whitespace_textwhitespace to place before text for formatting may be NULL
whitespace_lengthlength of whitespace_text
Returns
NSERROR_OK iff successful and traversal should continue else error code

Definition at line 251 of file textselection.c.

References font_plot_style_from_css(), box::length, NSERROR_NOMEM, NSERROR_OK, selection_string_append(), box::space, box::style, box::text, and text().

Referenced by selection_copy().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ selection_label_subtree()

static unsigned selection_label_subtree ( struct box box,
unsigned  idx 
)
static

Label each text box in the given box subtree with its position in a textual representation of the content.

Parameters
boxThe box at root of subtree
idxcurrent position within textual representation
Returns
updated position

Definition at line 445 of file textselection.c.

References box::byte_offset, box::children, box::length, box::list_marker, box::next, selection_label_subtree(), SPACE_LEN, and box::text.

Referenced by html_textselection_get_end(), and selection_label_subtree().

Here is the call graph for this function:
Here is the caller graph for this function: