NetSurf
Data Structures | Macros | Typedefs | Functions | Variables
textplain.c File Reference

plain text content handling implementation. More...

#include <string.h>
#include <parserutils/input/inputstream.h>
#include "utils/errors.h"
#include "utils/corestrings.h"
#include "utils/http.h"
#include "utils/log.h"
#include "utils/messages.h"
#include "utils/utils.h"
#include "utils/utf8.h"
#include "utils/nsoption.h"
#include "netsurf/content.h"
#include "netsurf/keypress.h"
#include "netsurf/browser_window.h"
#include "netsurf/plotters.h"
#include "netsurf/layout.h"
#include "content/content_protected.h"
#include "content/content_factory.h"
#include "content/hlcache.h"
#include "content/textsearch.h"
#include "content/handlers/css/utils.h"
#include "desktop/selection.h"
#include "desktop/gui_internal.h"
#include "text/textplain.h"
Include dependency graph for textplain.c:

Go to the source code of this file.

Data Structures

struct  textplain_line
 
struct  textplain_content
 plain text content More...
 

Macros

#define CHUNK   32768 /* Must be a power of 2 */
 
#define MARGIN   4
 
#define TAB_WIDTH   8 /* must be power of 2 currently */
 
#define TEXT_SIZE   10 * PLOT_STYLE_SCALE /* Unscaled text size in pt */
 

Typedefs

typedef struct textplain_content textplain_content
 plain text content More...
 

Functions

static void textplain_fini (void)
 Clean up after the text content handler. More...
 
static parserutils_error textplain_charset_hack (const uint8_t *data, size_t len, uint16_t *mibenum, uint32_t *source)
 Work around feature in libparserutils. More...
 
static nserror textplain_create_internal (textplain_content *c, lwc_string *encoding)
 setup plain text render. More...
 
static nserror textplain_create (const content_handler *handler, lwc_string *imime_type, const struct http_parameter *params, llcache_handle *llcache, const char *fallback_charset, bool quirks, struct content **c)
 Create a CONTENT_TEXTPLAIN. More...
 
static bool textplain_copy_utf8_data (textplain_content *c, const uint8_t *buf, size_t len)
 copy utf8 encoded data More...
 
static bool textplain_drain_input (textplain_content *c, parserutils_inputstream *stream, parserutils_error terminator)
 drain input More...
 
static bool textplain_process_data (struct content *c, const char *data, unsigned int size)
 Process data for CONTENT_TEXTPLAIN. More...
 
static bool textplain_convert (struct content *c)
 Convert a CONTENT_TEXTPLAIN for display. More...
 
static float textplain_line_height (void)
 Calculate the line height, in pixels. More...
 
static void textplain_reformat (struct content *c, int width, int height)
 Reformat a CONTENT_TEXTPLAIN to a new width. More...
 
static void textplain_destroy (struct content *c)
 Destroy a CONTENT_TEXTPLAIN and free all resources it owns. More...
 
static nserror textplain_clone (const struct content *old, struct content **newc)
 
static content_type textplain_content_type (void)
 
static size_t textplain_offset_from_coords (struct content *c, int x, int y, int dir)
 Return byte offset within UTF8 textplain content. More...
 
static nserror textplain_mouse_action (struct content *c, struct browser_window *bw, browser_mouse_state mouse, int x, int y)
 Handle mouse clicks and movements in a TEXTPLAIN content window. More...
 
static nserror textplain_mouse_track (struct content *c, struct browser_window *bw, browser_mouse_state mouse, int x, int y)
 Handle mouse tracking (including drags) in a TEXTPLAIN content window. More...
 
static bool textplain_keypress (struct content *c, uint32_t key)
 Handle keypresses. More...
 
static bool text_draw (const char *utf8_text, size_t utf8_len, size_t offset, int x, int y, const struct rect *clip, int height, float scale, textplain_content *text, const struct selection *sel, const struct redraw_context *ctx)
 Redraw a text string with highlighting (for selection/search) More...
 
static bool textplain_redraw (struct content *c, struct content_redraw_data *data, const struct rect *clip, const struct redraw_context *ctx)
 Draw a CONTENT_TEXTPLAIN using the current set of plotters (plot). More...
 
static nserror textplain_open (struct content *c, struct browser_window *bw, struct content *page, struct object_params *params)
 Handle a window containing a CONTENT_TEXTPLAIN being opened. More...
 
static nserror textplain_close (struct content *c)
 Handle a window containing a CONTENT_TEXTPLAIN being closed. More...
 
static char * textplain_get_selection (struct content *c)
 Return an textplain content's selection context. More...
 
static int textplain_coord_from_offset (const char *text, size_t offset, size_t length)
 Convert a character offset within a line of text into the horizontal co-ordinate. More...
 
static unsigned long textplain_line_count (struct content *c)
 Retrieve number of lines in content. More...
 
static char * textplain_get_line (struct content *c, unsigned lineno, size_t *poffset, size_t *plen)
 Return a pointer to the requested line of text. More...
 
static int textplain_find_line (struct content *c, unsigned offset)
 Find line number of byte in text. More...
 
static nserror textplain_textsearch_find (struct content *c, struct textsearch_context *context, const char *pattern, int p_len, bool case_sens)
 Finds all occurrences of a given string in a textplain content. More...
 
static void textplain_coords_from_range (struct content *c, unsigned start, unsigned end, struct rect *r)
 Given a range of byte offsets within a UTF8 textplain content, return a box that fully encloses the text. More...
 
static char * textplain_get_raw_data (struct content *c, unsigned start, unsigned end, size_t *plen)
 Return a pointer to the raw UTF-8 data, as opposed to the reformatted text to fit the window width. More...
 
static nserror textplain_textsearch_bounds (struct content *c, unsigned start_idx, unsigned end_idx, struct box *start_box, struct box *end_box, struct rect *bounds)
 get bounds of a free text search match More...
 
static nserror textplain_textselection_redraw (struct content *c, unsigned start_idx, unsigned end_idx)
 invalidate a region based on offsets into the text cauing a redraw More...
 
static nserror textplain_textselection_copy (struct content *c, unsigned start_idx, unsigned end_idx, struct selection_string *selstr)
 
static nserror textplain_textselection_get_end (struct content *c, unsigned *end_idx)
 Retrieve the index of the end of the text. More...
 
nserror textplain_init (void)
 Initialise the text content handler. More...
 

Variables

static plot_font_style_t textplain_style
 
static int textplain_tab_width = 256
 
static lwc_string * textplain_default_charset
 
static const content_handler textplain_content_handler
 plain text content handler table More...
 

Detailed Description

plain text content handling implementation.

Definition in file textplain.c.

Macro Definition Documentation

◆ CHUNK

#define CHUNK   32768 /* Must be a power of 2 */

Definition at line 78 of file textplain.c.

◆ MARGIN

#define MARGIN   4

Definition at line 79 of file textplain.c.

◆ TAB_WIDTH

#define TAB_WIDTH   8 /* must be power of 2 currently */

Definition at line 81 of file textplain.c.

◆ TEXT_SIZE

#define TEXT_SIZE   10 * PLOT_STYLE_SCALE /* Unscaled text size in pt */

Definition at line 82 of file textplain.c.

Typedef Documentation

◆ textplain_content

plain text content

Function Documentation

◆ text_draw()

static bool text_draw ( const char *  utf8_text,
size_t  utf8_len,
size_t  offset,
int  x,
int  y,
const struct rect clip,
int  height,
float  scale,
textplain_content text,
const struct selection sel,
const struct redraw_context ctx 
)
static

Redraw a text string with highlighting (for selection/search)

Parameters
utf8_textpointer to UTF-8 text string
utf8_lenlength of string, in bytes
offsetbyte offset within textual representation
xx ordinate at which to plot text
yy ordinate at which to plot text
clippointer to current clip rectangle
heightheight of text string
scalecurrent display scale (1.0 = 100%)
textContent being redrawn.
selSelection context
searchSearch context
ctxcurrent redraw context
Returns
true iff successful and redraw should proceed

Definition at line 844 of file textplain.c.

References plot_font_style::background, clip(), plotter_table::clip, colour_to_bw_furthest, content_textsearch_ishighlighted(), selection::end_idx, plot_style_s::fill_colour, plot_font_style::foreground, guit, height, redraw_context::interactive, netsurf_table::layout, max, min, NSERROR_OK, redraw_context::plot, plot_style_fill_white, plotter_table::rectangle, selection_highlighted(), plot_font_style::size, selection::start_idx, text(), plotter_table::text, textplain_style, gui_layout_table::width, rect::x0, rect::x1, rect::y0, and rect::y1.

Referenced by textplain_redraw().

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

◆ textplain_charset_hack()

static parserutils_error textplain_charset_hack ( const uint8_t *  data,
size_t  len,
uint16_t *  mibenum,
uint32_t *  source 
)
static

Work around feature in libparserutils.

if the client provides an encoding up front, but does not provide a charset detection callback, then libparserutils will replace the provided encoding with UTF-8. This breaks our input handling.

Avoid this by providing a callback that does precisely nothing, thus preserving whatever charset information we decided on in textplain_create.

Definition at line 122 of file textplain.c.

Referenced by textplain_create_internal().

Here is the caller graph for this function:

◆ textplain_clone()

static nserror textplain_clone ( const struct content old,
struct content **  newc 
)
static

Definition at line 548 of file textplain.c.

References content__clone(), content__get_source_data(), content_destroy(), CONTENT_STATUS_DONE, CONTENT_STATUS_READY, textplain_content::encoding, NSERROR_CLONE_FAILED, NSERROR_NOMEM, NSERROR_OK, content::status, text(), textplain_convert(), textplain_create_internal(), and textplain_process_data().

Here is the call graph for this function:

◆ textplain_close()

static nserror textplain_close ( struct content c)
static

Handle a window containing a CONTENT_TEXTPLAIN being closed.

Definition at line 1236 of file textplain.c.

References NSERROR_OK, and text().

Here is the call graph for this function:

◆ textplain_content_type()

static content_type textplain_content_type ( void  )
static

Definition at line 595 of file textplain.c.

References CONTENT_TEXTPLAIN.

◆ textplain_convert()

static bool textplain_convert ( struct content c)
static

Convert a CONTENT_TEXTPLAIN for display.

Definition at line 360 of file textplain.c.

References content_set_done(), content_set_ready(), content_set_status(), messages_get(), text(), and textplain_drain_input().

Referenced by textplain_clone().

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

◆ textplain_coord_from_offset()

static int textplain_coord_from_offset ( const char *  text,
size_t  offset,
size_t  length 
)
static

Convert a character offset within a line of text into the horizontal co-ordinate.

The conversion takes into account the font being used and any tabs in the text

Parameters
textline of text
offsetchar offset within text
lengthline length
Returns
x ordinate

Definition at line 1270 of file textplain.c.

References guit, netsurf_table::layout, text(), textplain_style, textplain_tab_width, utf8_next(), and gui_layout_table::width.

Referenced by textplain_coords_from_range().

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

◆ textplain_coords_from_range()

static void textplain_coords_from_range ( struct content c,
unsigned  start,
unsigned  end,
struct rect r 
)
static

Given a range of byte offsets within a UTF8 textplain content, return a box that fully encloses the text.

Parameters
[in]ccontent of type CONTENT_TEXTPLAIN
[in]startbyte offset of start of text range
[in]endbyte offset of end
[out]rrectangle to be completed

Definition at line 1461 of file textplain.c.

References textplain_line::length, line(), line_height(), MARGIN, textplain_line::start, text(), textplain_coord_from_offset(), textplain_find_line(), textplain_line_height(), rect::x0, rect::x1, rect::y0, and rect::y1.

Referenced by textplain_textsearch_bounds(), and textplain_textselection_redraw().

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

◆ textplain_copy_utf8_data()

static bool textplain_copy_utf8_data ( textplain_content c,
const uint8_t *  buf,
size_t  len 
)
static

copy utf8 encoded data

Definition at line 236 of file textplain.c.

References CHUNK, textplain_content::utf8_data, textplain_content::utf8_data_allocated, and textplain_content::utf8_data_size.

Referenced by textplain_drain_input().

Here is the caller graph for this function:

◆ textplain_create()

static nserror textplain_create ( const content_handler handler,
lwc_string *  imime_type,
const struct http_parameter params,
llcache_handle llcache,
const char *  fallback_charset,
bool  quirks,
struct content **  c 
)
static

Create a CONTENT_TEXTPLAIN.

Definition at line 187 of file textplain.c.

References selection::c, content__init(), http_parameter_list_find_item(), llcache, NSERROR_NOMEM, NSERROR_OK, text(), textplain_create_internal(), and textplain_default_charset.

Here is the call graph for this function:

◆ textplain_create_internal()

static nserror textplain_create_internal ( textplain_content c,
lwc_string *  encoding 
)
static

setup plain text render.

Parameters
[in]ccontent object.
[in]encodingthe encoding of the content.
Returns
NSERROR_OK else appropriate error code.

Definition at line 139 of file textplain.c.

References selection::c, CHUNK, content_broadcast_error(), NSERROR_NOMEM, NSERROR_OK, nsoption_int, PLOT_STYLE_SCALE, selection_create(), plot_font_style::size, textplain_charset_hack(), and textplain_style.

Referenced by textplain_clone(), and textplain_create().

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

◆ textplain_destroy()

static void textplain_destroy ( struct content c)
static

Destroy a CONTENT_TEXTPLAIN and free all resources it owns.

Definition at line 524 of file textplain.c.

References selection_destroy(), and text().

Here is the call graph for this function:

◆ textplain_drain_input()

static bool textplain_drain_input ( textplain_content c,
parserutils_inputstream *  stream,
parserutils_error  terminator 
)
static

drain input

Definition at line 263 of file textplain.c.

References CHUNK, and textplain_copy_utf8_data().

Referenced by textplain_convert(), and textplain_process_data().

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

◆ textplain_find_line()

static int textplain_find_line ( struct content c,
unsigned  offset 
)
static

Find line number of byte in text.

Given a byte offset within the text, return the line number of the line containing that offset.

Parameters
[in]ccontent of type CONTENT_TEXTPLAIN
[in]offsetbyte offset within textual representation
Returns
line number, or -1 if offset invalid (larger than size)

Definition at line 1357 of file textplain.c.

References line(), textplain_line::start, and text().

Referenced by textplain_coords_from_range().

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

◆ textplain_fini()

static void textplain_fini ( void  )
static

Clean up after the text content handler.

Definition at line 101 of file textplain.c.

References textplain_default_charset.

◆ textplain_get_line()

static char * textplain_get_line ( struct content c,
unsigned  lineno,
size_t *  poffset,
size_t *  plen 
)
static

Return a pointer to the requested line of text.

Parameters
[in]ccontent of type CONTENT_TEXTPLAIN
[in]linenoline number
[out]poffsetreceives byte offset of line start within text
[out]plenreceives length of returned line
Returns
pointer to text, or NULL if invalid line number

Definition at line 1327 of file textplain.c.

References line(), and text().

Referenced by textplain_textsearch_find().

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

◆ textplain_get_raw_data()

static char * textplain_get_raw_data ( struct content c,
unsigned  start,
unsigned  end,
size_t *  plen 
)
static

Return a pointer to the raw UTF-8 data, as opposed to the reformatted text to fit the window width.

Thus only hard newlines are preserved in the saved/copied text of a selection.

Parameters
[in]ccontent of type CONTENT_TEXTPLAIN
[in]startstarting byte offset within UTF-8 text
[in]endending byte offset
[out]plenreceives validated length
Returns
pointer to text, or NULL if no text

Definition at line 1525 of file textplain.c.

References textplain_line::start, and text().

Referenced by textplain_textselection_copy().

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

◆ textplain_get_selection()

static char * textplain_get_selection ( struct content c)
static

Return an textplain content's selection context.

Definition at line 1249 of file textplain.c.

References selection_get_copy(), and text().

Here is the call graph for this function:

◆ textplain_init()

nserror textplain_init ( void  )

Initialise the text content handler.

Returns
NSERROR_OK on success else appropriate error code.

Definition at line 1654 of file textplain.c.

References content_factory_register_handler(), NSERROR_NOMEM, NSERROR_OK, SLEN, textplain_content_handler, and textplain_default_charset.

Referenced by netsurf_init().

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

◆ textplain_keypress()

static bool textplain_keypress ( struct content c,
uint32_t  key 
)
static

Handle keypresses.

Parameters
ccontent of type CONTENT_TEXTPLAIN
keyThe UCS4 character codepoint
Returns
true if key handled, false otherwise

Definition at line 798 of file textplain.c.

References NS_KEY_CLEAR_SELECTION, NS_KEY_COPY_SELECTION, NS_KEY_ESCAPE, NS_KEY_SELECT_ALL, selection_clear(), selection_copy_to_clipboard(), selection_select_all(), and text().

Here is the call graph for this function:

◆ textplain_line_count()

static unsigned long textplain_line_count ( struct content c)
static

Retrieve number of lines in content.

Parameters
[in]cContent to retrieve line count from
Returns
Number of lines

Definition at line 1307 of file textplain.c.

References text().

Referenced by textplain_textsearch_find().

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

◆ textplain_line_height()

static float textplain_line_height ( void  )
static

Calculate the line height, in pixels.

Returns
Line height, in pixels

Definition at line 390 of file textplain.c.

References nscss_screen_dpi, PLOT_STYLE_SCALE, plot_font_style::size, and textplain_style.

Referenced by textplain_coords_from_range(), textplain_offset_from_coords(), textplain_redraw(), and textplain_reformat().

Here is the caller graph for this function:

◆ textplain_mouse_action()

static nserror textplain_mouse_action ( struct content c,
struct browser_window bw,
browser_mouse_state  mouse,
int  x,
int  y 
)
static

Handle mouse clicks and movements in a TEXTPLAIN content window.

Parameters
ccontent of type textplain
bwbrowser window
mousemouse state on action
xcoordinate of mouse
ycoordinate of mouse

Definition at line 699 of file textplain.c.

References BROWSER_MOUSE_DRAG_1, BROWSER_MOUSE_DRAG_2, BROWSER_POINTER_DEFAULT, BROWSER_POINTER_MOVE, browser_window_page_drag_start(), browser_window_set_drag_type(), content_broadcast(), CONTENT_MSG_POINTER, CONTENT_MSG_STATUS, DRAGGING_NONE, DRAGGING_SELECTION, content_msg_data::explicit_status_text, messages_get(), NSERROR_OK, content_msg_data::pointer, selection_click(), selection_dragging(), text(), textplain_offset_from_coords(), content_msg_data::x, and content_msg_data::y.

Referenced by textplain_mouse_track().

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

◆ textplain_mouse_track()

static nserror textplain_mouse_track ( struct content c,
struct browser_window bw,
browser_mouse_state  mouse,
int  x,
int  y 
)
static

Handle mouse tracking (including drags) in a TEXTPLAIN content window.

Parameters
ccontent of type textplain
bwbrowser window
mousestate of mouse buttons and modifier keys
xcoordinate of mouse
ycoordinate of mouse

Definition at line 749 of file textplain.c.

References browser_window_get_drag_type(), browser_window_set_drag_type(), DRAGGING_NONE, DRAGGING_SELECTION, NSERROR_OK, selection_dragging_start(), selection_track(), text(), textplain_mouse_action(), textplain_offset_from_coords(), content_msg_data::x, and content_msg_data::y.

Here is the call graph for this function:

◆ textplain_offset_from_coords()

static size_t textplain_offset_from_coords ( struct content c,
int  x,
int  y,
int  dir 
)
static

Return byte offset within UTF8 textplain content.

given the co-ordinates of a point within a textplain content. 'dir' specifies the direction in which to search (-1 = above-left, +1 = below-right) if the co-ordinates are not contained within a line.

Parameters
[in]ccontent of type CONTENT_TEXTPLAIN
[in]xx ordinate of point
[in]yy ordinate of point
[in]dirdirection of search if not within line
Returns
byte offset of character containing (or nearest to) point

Definition at line 615 of file textplain.c.

References guit, netsurf_table::layout, textplain_line::length, line(), line_height(), MARGIN, textplain_content::physical_line, textplain_content::physical_line_count, gui_layout_table::position, text(), textplain_line_height(), textplain_style, textplain_tab_width, textplain_content::utf8_data, utf8_next(), width, and gui_layout_table::width.

Referenced by textplain_mouse_action(), and textplain_mouse_track().

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

◆ textplain_open()

static nserror textplain_open ( struct content c,
struct browser_window bw,
struct content page,
struct object_params params 
)
static

Handle a window containing a CONTENT_TEXTPLAIN being opened.

Definition at line 1217 of file textplain.c.

References NSERROR_OK, selection_init(), and text().

Here is the call graph for this function:

◆ textplain_process_data()

static bool textplain_process_data ( struct content c,
const char *  data,
unsigned int  size 
)
static

Process data for CONTENT_TEXTPLAIN.

Definition at line 334 of file textplain.c.

References content_broadcast_error(), NSERROR_NOMEM, content::size, text(), and textplain_drain_input().

Referenced by textplain_clone().

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

◆ textplain_redraw()

static bool textplain_redraw ( struct content c,
struct content_redraw_data data,
const struct rect clip,
const struct redraw_context ctx 
)
static

Draw a CONTENT_TEXTPLAIN using the current set of plotters (plot).

x, y, clip_[xy][01] are in target coordinates.

Parameters
ccontent of type CONTENT_TEXTPLAIN
dataredraw data for this content redraw
clipcurrent clip region
ctxcurrent redraw context
Returns
true if successful, false otherwise

Definition at line 1051 of file textplain.c.

References plot_font_style::background, content_redraw_data::background_colour, browser_window::bw, selection::c, clip(), content_textsearch_ishighlighted(), content::context, selection::end_idx, guit, netsurf_table::layout, textplain_line::length, line(), line_height(), MARGIN, NSERROR_OK, redraw_context::plot, plot_style_fill_black, plot_style_fill_white, plotter_table::rectangle, content_redraw_data::scale, selection_highlighted(), textplain_line::start, selection::start_idx, text(), text_draw(), textplain_line_height(), textplain_style, textplain_tab_width, content::textsearch, utf8_next(), width, gui_layout_table::width, browser_window::x, content_redraw_data::x, rect::x0, rect::x1, browser_window::y, content_redraw_data::y, rect::y0, and rect::y1.

Here is the call graph for this function:

◆ textplain_reformat()

static void textplain_reformat ( struct content c,
int  width,
int  height 
)
static

Reformat a CONTENT_TEXTPLAIN to a new width.

Definition at line 402 of file textplain.c.

References guit, content::height, height, netsurf_table::layout, line(), MARGIN, NSERROR_OK, NSLOG, TAB_WIDTH, text(), textplain_line_height(), textplain_style, textplain_tab_width, content::width, width, and gui_layout_table::width.

Here is the call graph for this function:

◆ textplain_textsearch_bounds()

static nserror textplain_textsearch_bounds ( struct content c,
unsigned  start_idx,
unsigned  end_idx,
struct box start_box,
struct box end_box,
struct rect bounds 
)
static

get bounds of a free text search match

Definition at line 1554 of file textplain.c.

References NSERROR_OK, and textplain_coords_from_range().

Here is the call graph for this function:

◆ textplain_textsearch_find()

static nserror textplain_textsearch_find ( struct content c,
struct textsearch_context context,
const char *  pattern,
int  p_len,
bool  case_sens 
)
static

Finds all occurrences of a given string in a textplain content.

Parameters
cthe content to be searched
contextThe search context to add the entry to.
patternthe string pattern to search for
p_lenpattern length
case_senswhether to perform a case sensitive search
Returns
NSERROR_OK on success else error code on faliure

Definition at line 1396 of file textplain.c.

References content_textsearch_add_match(), content_textsearch_find_pattern(), textplain_line::length, line(), NSERROR_OK, text(), textplain_get_line(), and textplain_line_count().

Here is the call graph for this function:

◆ textplain_textselection_copy()

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

Definition at line 1589 of file textplain.c.

References NSERROR_NOMEM, NSERROR_OK, selection_string_append(), text(), and textplain_get_raw_data().

Here is the call graph for this function:

◆ textplain_textselection_get_end()

static nserror textplain_textselection_get_end ( struct content c,
unsigned *  end_idx 
)
static

Retrieve the index of the end of the text.

Parameters
[in]cContent to retrieve size of
Returns
Size, in bytes, of data

Definition at line 1616 of file textplain.c.

References NSERROR_OK, and text().

Here is the call graph for this function:

◆ textplain_textselection_redraw()

static nserror textplain_textselection_redraw ( struct content c,
unsigned  start_idx,
unsigned  end_idx 
)
static

invalidate a region based on offsets into the text cauing a redraw

Definition at line 1571 of file textplain.c.

References content__request_redraw(), NSERROR_BAD_PARAMETER, NSERROR_OK, textplain_coords_from_range(), rect::x0, rect::x1, rect::y0, and rect::y1.

Here is the call graph for this function:

Variable Documentation

◆ textplain_content_handler

const content_handler textplain_content_handler
static
Initial value:
= {
.fini = textplain_fini,
.create = textplain_create,
.process_data = textplain_process_data,
.data_complete = textplain_convert,
.reformat = textplain_reformat,
.destroy = textplain_destroy,
.mouse_track = textplain_mouse_track,
.mouse_action = textplain_mouse_action,
.keypress = textplain_keypress,
.redraw = textplain_redraw,
.open = textplain_open,
.close = textplain_close,
.get_selection = textplain_get_selection,
.clone = textplain_clone,
.textsearch_find = textplain_textsearch_find,
.textsearch_bounds = textplain_textsearch_bounds,
.textselection_redraw = textplain_textselection_redraw,
.textselection_copy = textplain_textselection_copy,
.textselection_get_end = textplain_textselection_get_end,
.no_share = true,
}
static nserror textplain_textsearch_find(struct content *c, struct textsearch_context *context, const char *pattern, int p_len, bool case_sens)
Finds all occurrences of a given string in a textplain content.
Definition: textplain.c:1396
static bool textplain_convert(struct content *c)
Convert a CONTENT_TEXTPLAIN for display.
Definition: textplain.c:360
static nserror textplain_mouse_track(struct content *c, struct browser_window *bw, browser_mouse_state mouse, int x, int y)
Handle mouse tracking (including drags) in a TEXTPLAIN content window.
Definition: textplain.c:749
static void textplain_reformat(struct content *c, int width, int height)
Reformat a CONTENT_TEXTPLAIN to a new width.
Definition: textplain.c:402
static nserror textplain_textselection_copy(struct content *c, unsigned start_idx, unsigned end_idx, struct selection_string *selstr)
Definition: textplain.c:1589
static nserror textplain_create(const content_handler *handler, lwc_string *imime_type, const struct http_parameter *params, llcache_handle *llcache, const char *fallback_charset, bool quirks, struct content **c)
Create a CONTENT_TEXTPLAIN.
Definition: textplain.c:187
static char * textplain_get_selection(struct content *c)
Return an textplain content's selection context.
Definition: textplain.c:1249
static bool textplain_redraw(struct content *c, struct content_redraw_data *data, const struct rect *clip, const struct redraw_context *ctx)
Draw a CONTENT_TEXTPLAIN using the current set of plotters (plot).
Definition: textplain.c:1051
static bool textplain_keypress(struct content *c, uint32_t key)
Handle keypresses.
Definition: textplain.c:798
static void textplain_destroy(struct content *c)
Destroy a CONTENT_TEXTPLAIN and free all resources it owns.
Definition: textplain.c:524
static nserror textplain_mouse_action(struct content *c, struct browser_window *bw, browser_mouse_state mouse, int x, int y)
Handle mouse clicks and movements in a TEXTPLAIN content window.
Definition: textplain.c:699
static nserror textplain_textsearch_bounds(struct content *c, unsigned start_idx, unsigned end_idx, struct box *start_box, struct box *end_box, struct rect *bounds)
get bounds of a free text search match
Definition: textplain.c:1554
static nserror textplain_open(struct content *c, struct browser_window *bw, struct content *page, struct object_params *params)
Handle a window containing a CONTENT_TEXTPLAIN being opened.
Definition: textplain.c:1217
static bool textplain_process_data(struct content *c, const char *data, unsigned int size)
Process data for CONTENT_TEXTPLAIN.
Definition: textplain.c:334
static nserror textplain_close(struct content *c)
Handle a window containing a CONTENT_TEXTPLAIN being closed.
Definition: textplain.c:1236
static nserror textplain_textselection_get_end(struct content *c, unsigned *end_idx)
Retrieve the index of the end of the text.
Definition: textplain.c:1616
static void textplain_fini(void)
Clean up after the text content handler.
Definition: textplain.c:101
static nserror textplain_textselection_redraw(struct content *c, unsigned start_idx, unsigned end_idx)
invalidate a region based on offsets into the text cauing a redraw
Definition: textplain.c:1571
static content_type textplain_content_type(void)
Definition: textplain.c:595
static nserror textplain_clone(const struct content *old, struct content **newc)
Definition: textplain.c:548

plain text content handler table

Definition at line 1628 of file textplain.c.

Referenced by textplain_init().

◆ textplain_default_charset

lwc_string* textplain_default_charset
static

Definition at line 95 of file textplain.c.

Referenced by textplain_create(), textplain_fini(), and textplain_init().

◆ textplain_style

plot_font_style_t textplain_style
static
Initial value:
= {
.size = TEXT_SIZE,
.weight = 400,
.flags = FONTF_NONE,
.background = 0xffffff,
.foreground = 0x000000,
}
@ FONTF_NONE
Definition: plot_style.h:102
@ PLOT_FONT_FAMILY_MONOSPACE
Definition: plot_style.h:91
#define TEXT_SIZE
Definition: textplain.c:82

Definition at line 84 of file textplain.c.

Referenced by text_draw(), textplain_coord_from_offset(), textplain_create_internal(), textplain_line_height(), textplain_offset_from_coords(), textplain_redraw(), and textplain_reformat().

◆ textplain_tab_width

int textplain_tab_width = 256
static