NetSurf
Data Structures | Macros | Functions | Variables
textarea.c File Reference

Single/Multi-line UTF-8 text area implementation. More...

#include <stdint.h>
#include <string.h>
#include "utils/log.h"
#include "utils/utf8.h"
#include "utils/utils.h"
#include "netsurf/browser_window.h"
#include "netsurf/plotters.h"
#include "netsurf/mouse.h"
#include "netsurf/keypress.h"
#include "netsurf/clipboard.h"
#include "netsurf/layout.h"
#include "css/utils.h"
#include "desktop/textarea.h"
#include "desktop/scrollbar.h"
#include "desktop/gui_internal.h"
Include dependency graph for textarea.c:

Go to the source code of this file.

Data Structures

struct  line_info
 
struct  textarea_drag
 
struct  textarea_utf8
 
struct  textarea_undo_detail
 
struct  textarea_undo
 
struct  textarea
 

Macros

#define CARET_COLOR   0x0000FF
 
#define TA_ALLOC_STEP   512
 
#define PASSWORD_REPLACEMENT   "\xe2\x80\xa2"
 
#define PASSWORD_REPLACEMENT_W   (sizeof(PASSWORD_REPLACEMENT) - 1)
 
#define LINE_CHUNK_SIZE   32
 

Functions

static void textarea_normalise_text (struct textarea *ta, unsigned int b_start, unsigned int b_len)
 Normalises any line endings within the text, replacing CRLF or CR with LF as necessary. More...
 
static void textarea_reset_selection (struct textarea *ta)
 Reset the selection (no redraw) More...
 
static int textarea_get_caret (struct textarea *ta)
 Get the caret's position. More...
 
static bool textarea_scroll_visible (struct textarea *ta)
 Scrolls a textarea to make the caret visible (doesn't perform a redraw) More...
 
static bool textarea_set_caret_internal (struct textarea *ta, int caret_b)
 Set the caret position. More...
 
static bool textarea_select (struct textarea *ta, int b_start, int b_end, bool force_redraw)
 Selects a character range in the textarea and redraws it. More...
 
static bool textarea_select_fragment (struct textarea *ta)
 Selects a text fragment, relative to current caret position. More...
 
static bool textarea_select_paragraph (struct textarea *ta)
 Selects paragraph, at current caret position. More...
 
static void textarea_scrollbar_callback (void *client_data, struct scrollbar_msg_data *scrollbar_data)
 Callback for scrollbar widget. More...
 
static bool textarea_reflow_singleline (struct textarea *ta, size_t b_off, struct rect *r)
 Reflow a single line textarea. More...
 
static bool textarea_reflow_multiline (struct textarea *ta, const size_t b_start, const int b_length, struct rect *r)
 Reflow a multiline textarea from the given line onwards. More...
 
static size_t textarea_get_b_off_xy (struct textarea *ta, int x, int y, bool visible)
 get byte offset from the beginning of the text for some coordinates More...
 
static bool textarea_set_caret_xy (struct textarea *ta, int x, int y, bool visible)
 Set the caret's position. More...
 
static bool textarea_insert_text (struct textarea *ta, const char *text, size_t b_off, size_t b_len, int *byte_delta, struct rect *r)
 Insert text into the textarea. More...
 
static void textarea_char_to_byte_offset (struct textarea_utf8 *text, unsigned int start, unsigned int end, size_t *b_start, size_t *b_end)
 Helper for replace_text function converts character offset to byte offset. More...
 
static bool textarea_replace_text_internal (struct textarea *ta, size_t b_start, size_t b_end, const char *rep, size_t rep_len, bool add_to_clipboard, int *byte_delta, struct rect *r)
 Perform actual text replacment in a textarea. More...
 
static bool textarea_copy_to_undo_buffer (struct textarea *ta, size_t b_start, size_t b_end, size_t rep_len)
 Update undo buffer by adding any text to be replaced, and allocating space as appropriate. More...
 
static bool textarea_replace_text (struct textarea *ta, size_t b_start, size_t b_end, const char *rep, size_t rep_len, bool add_to_clipboard, int *byte_delta, struct rect *r)
 Replace text in a textarea, updating undo buffer. More...
 
static bool textarea_undo (struct textarea *ta, bool forward, unsigned int *caret, struct rect *r)
 Undo or redo previous change. More...
 
static bool textarea_drag_end (struct textarea *ta, browser_mouse_state mouse, int x, int y)
 Handles the end of a drag operation. More...
 
static void textarea_setup_text_offsets (struct textarea *ta)
 Setup text offsets after height / border / padding change. More...
 
static void textarea_set_text_style (struct textarea *ta, const plot_font_style_t *fstyle, colour selected_text, colour selected_bg)
 Set font styles up for a textarea. More...
 
struct textareatextarea_create (const textarea_flags flags, const textarea_setup *setup, textarea_client_callback callback, void *data)
 Create a text area. More...
 
void textarea_destroy (struct textarea *ta)
 Destroy a text area. More...
 
bool textarea_set_text (struct textarea *ta, const char *text)
 Set the text in a text area, discarding any current text. More...
 
bool textarea_drop_text (struct textarea *ta, const char *text, size_t text_length)
 Insert the text in a text area at the caret, replacing any selection. More...
 
int textarea_get_text (struct textarea *ta, char *buf, unsigned int len)
 Extract the text from a text area. More...
 
const char * textarea_data (struct textarea *ta, unsigned int *len)
 Access text data in a text area. More...
 
bool textarea_set_caret (struct textarea *ta, int caret)
 Set the caret's position. More...
 
void textarea_redraw (struct textarea *ta, int x, int y, colour bg, float scale, const struct rect *clip, const struct redraw_context *ctx)
 Handle redraw requests for text areas. More...
 
bool textarea_keypress (struct textarea *ta, uint32_t key)
 Key press handling for text areas. More...
 
static textarea_mouse_status textarea_mouse_scrollbar_action (struct textarea *ta, browser_mouse_state mouse, int x, int y)
 
textarea_mouse_status textarea_mouse_action (struct textarea *ta, browser_mouse_state mouse, int x, int y)
 Handles all kinds of mouse action. More...
 
bool textarea_clear_selection (struct textarea *ta)
 Clear any selection in the textarea. More...
 
char * textarea_get_selection (struct textarea *ta)
 Get selected text. More...
 
void textarea_get_dimensions (struct textarea *ta, int *width, int *height)
 Gets the dimensions of a textarea. More...
 
void textarea_set_dimensions (struct textarea *ta, int width, int height)
 Set the dimensions of a textarea. More...
 
void textarea_set_layout (struct textarea *ta, const plot_font_style_t *fstyle, int width, int height, int top, int right, int bottom, int left)
 Set the dimensions and padding of a textarea. More...
 
bool textarea_scroll (struct textarea *ta, int scrx, int scry)
 Scroll a textarea by an amount. More...
 

Variables

static plot_style_t pstyle_stroke_caret
 

Detailed Description

Single/Multi-line UTF-8 text area implementation.

Definition in file textarea.c.

Macro Definition Documentation

◆ CARET_COLOR

#define CARET_COLOR   0x0000FF

Definition at line 44 of file textarea.c.

◆ LINE_CHUNK_SIZE

#define LINE_CHUNK_SIZE   32

Definition at line 140 of file textarea.c.

◆ PASSWORD_REPLACEMENT

#define PASSWORD_REPLACEMENT   "\xe2\x80\xa2"

Definition at line 118 of file textarea.c.

◆ PASSWORD_REPLACEMENT_W

#define PASSWORD_REPLACEMENT_W   (sizeof(PASSWORD_REPLACEMENT) - 1)

Definition at line 119 of file textarea.c.

◆ TA_ALLOC_STEP

#define TA_ALLOC_STEP   512

Definition at line 45 of file textarea.c.

Function Documentation

◆ textarea_char_to_byte_offset()

static void textarea_char_to_byte_offset ( struct textarea_utf8 text,
unsigned int  start,
unsigned int  end,
size_t *  b_start,
size_t *  b_end 
)
inlinestatic

Helper for replace_text function converts character offset to byte offset.

text utf8 textarea text object start start character offset end end character offset b_start updated to byte offset of start in text b_end updated to byte offset of end in text

Definition at line 1390 of file textarea.c.

References line_info::b_start, text(), and utf8_next().

Referenced by textarea_replace_text_internal().

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

◆ textarea_clear_selection()

bool textarea_clear_selection ( struct textarea ta)

◆ textarea_copy_to_undo_buffer()

static bool textarea_copy_to_undo_buffer ( struct textarea ta,
size_t  b_start,
size_t  b_end,
size_t  rep_len 
)
static

Update undo buffer by adding any text to be replaced, and allocating space as appropriate.

Parameters
taTextarea widget
b_startStart byte index of replaced section (inclusive)
b_endEnd byte index of replaced section (exclusive)
rep_lenByte length of replacement UTF-8 text
Returns
false on memory exhaustion, true otherwise

Definition at line 1543 of file textarea.c.

References textarea_utf8::alloc, textarea_undo_detail::b_end, textarea_undo_detail::b_limit, textarea_undo_detail::b_start, textarea_undo_detail::b_text_start, textarea_utf8::data, textarea_undo::details, textarea_undo::details_alloc, textarea_undo::next_detail, NSLOG, TA_ALLOC_STEP, textarea_undo::text, textarea::text, and textarea::undo.

Referenced by textarea_replace_text().

Here is the caller graph for this function:

◆ textarea_create()

struct textarea * textarea_create ( const textarea_flags  flags,
const textarea_setup setup,
textarea_client_callback  callback,
void *  data 
)

Create a text area.

Parameters
flagsflags controlling the text area creation
setuptextarea settings and style
callbackwill be called when textarea wants to redraw
datauser specified data which will be passed to callbacks
Returns
Opaque handle for textarea or 0 on error

Definition at line 1852 of file textarea.c.

References textarea_utf8::alloc, textarea::bar_x, textarea::bar_y, textarea::border_col, textarea_setup::border_col, textarea::border_width, textarea_setup::border_width, textarea::byte_off, textarea::callback, textarea::caret_pos, textarea::caret_x, textarea::caret_y, textarea_utf8::data, textarea::data, textarea_undo::details, textarea_undo::details_alloc, textarea::drag_info, textarea::drag_start, textarea::flags, textarea::h_extent, textarea_setup::height, textarea_undo::last_detail, textarea_utf8::len, textarea::line, textarea::line_count, textarea::line_height, textarea::lines, textarea::lines_alloc_size, textarea_undo::next_detail, nscss_screen_dpi, NSLOG, textarea::pad_bottom, textarea_setup::pad_bottom, textarea::pad_left, textarea_setup::pad_left, textarea::pad_right, textarea_setup::pad_right, textarea::pad_top, textarea_setup::pad_top, textarea::password, PLOT_STYLE_SCALE, textarea::scroll_x, textarea::scroll_y, textarea::sel_end, textarea::sel_start, textarea_setup::selected_bg, textarea_setup::selected_text, textarea::show, plot_font_style::size, TA_ALLOC_STEP, textarea_undo::text, textarea::text, textarea_setup::text, TEXTAREA_DRAG_NONE, TEXTAREA_MULTILINE, TEXTAREA_PASSWORD, textarea_reflow_multiline(), textarea_reflow_singleline(), textarea_set_text_style(), textarea_setup_text_offsets(), textarea_drag::type, textarea::undo, textarea_utf8::utf8_len, textarea::v_extent, textarea::vis_height, textarea::vis_width, and textarea_setup::width.

Referenced by box_textarea_create_textarea(), toolbar_create(), and treeview__create_textarea().

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

◆ textarea_data()

const char * textarea_data ( struct textarea ta,
unsigned int *  len 
)

Access text data in a text area.

Parameters
[in]taText area
[out]lenReturns byte length of returned text, if passed non-NULL.
Returns
textarea string data.

Definition at line 2101 of file textarea.c.

References textarea_utf8::data, textarea_utf8::len, and textarea::text.

Referenced by treeview__search_update_display().

Here is the caller graph for this function:

◆ textarea_destroy()

void textarea_destroy ( struct textarea ta)

Destroy a text area.

Parameters
taText area to destroy

Definition at line 1975 of file textarea.c.

References textarea::bar_x, textarea::bar_y, textarea_utf8::data, textarea_undo::details, textarea::flags, textarea::lines, textarea::password, scrollbar_destroy(), textarea_undo::text, textarea::text, TEXTAREA_PASSWORD, and textarea::undo.

Referenced by form_free_control(), toolbar_destroy(), treeview_destroy(), treeview_edit_cancel(), and treeview_edit_node_at_point().

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

◆ textarea_drag_end()

static bool textarea_drag_end ( struct textarea ta,
browser_mouse_state  mouse,
int  x,
int  y 
)
static

Handles the end of a drag operation.

Parameters
taText area
mousethe mouse state at drag end moment
xX coordinate
yY coordinate
Returns
true if drag end was handled false otherwise

Definition at line 1744 of file textarea.c.

References textarea_undo_detail::b_end, textarea::bar_x, textarea::border_width, textarea::callback, textarea_drag::data, textarea::data, textarea_msg::data, textarea_msg::drag, textarea::drag_info, textarea::drag_start, textarea_drag::scrollbar, scrollbar_mouse_drag_end(), SCROLLBAR_WIDTH, textarea_msg::ta, TEXTAREA_DRAG_NONE, TEXTAREA_DRAG_SCROLLBAR, TEXTAREA_DRAG_SELECTION, textarea_get_b_off_xy(), TEXTAREA_MSG_DRAG_REPORT, textarea_select(), textarea_drag::type, textarea_msg::type, textarea::vis_height, textarea::vis_width, textarea_msg::x, and textarea_msg::y.

Referenced by textarea_mouse_action().

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

◆ textarea_drop_text()

bool textarea_drop_text ( struct textarea ta,
const char *  text,
size_t  text_length 
)

Insert the text in a text area at the caret, replacing any selection.

Parameters
taText area
textUTF-8 text to set text area's contents to
text_lengthlength of text.
Returns
true on success, false on memory exhaustion or if ta lacks caret

< Redraw rectangle

Definition at line 2032 of file textarea.c.

References textarea::callback, textarea::data, textarea_msg::data, textarea::flags, textarea_msg::redraw, textarea::sel_end, textarea::sel_start, textarea_msg::ta, text(), textarea_get_caret(), TEXTAREA_MSG_REDRAW_REQUEST, TEXTAREA_READONLY, textarea_replace_text(), textarea_set_caret_internal(), textarea_msg::type, textarea::vis_height, textarea::vis_width, rect::x0, rect::x1, rect::y0, and rect::y1.

Referenced by html_drop_file_at_point().

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

◆ textarea_get_b_off_xy()

static size_t textarea_get_b_off_xy ( struct textarea ta,
int  x,
int  y,
bool  visible 
)
static

get byte offset from the beginning of the text for some coordinates

Parameters
tatextarea widget
xX coordinate
yY coordinate
visibletrue iff (x,y) is wrt visiable area, false for global
Returns
byte offset

Definition at line 1232 of file textarea.c.

References line_info::b_length, line_info::b_start, textarea::border_width, textarea_utf8::data, textarea::flags, textarea::fstyle, guit, netsurf_table::layout, line(), textarea::line_count, textarea::line_height, textarea::lines, textarea::pad_left, textarea::pad_top, gui_layout_table::position, textarea::scroll_x, textarea::scroll_y, textarea::show, and TEXTAREA_MULTILINE.

Referenced by textarea_drag_end(), textarea_mouse_action(), and textarea_set_caret_xy().

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

◆ textarea_get_caret()

static int textarea_get_caret ( struct textarea ta)
static

Get the caret's position.

Parameters
taText area
Returns
0-based byte offset of caret location, or -1 on error

Definition at line 226 of file textarea.c.

References line_info::b_start, textarea::byte_off, textarea::caret_pos, textarea_utf8::len, textarea::line, textarea::line_count, textarea::lines, textarea::show, textarea_msg::ta, textarea::text, textarea_set_caret(), and textarea_utf8::utf8_len.

Referenced by textarea_drop_text(), textarea_keypress(), textarea_mouse_action(), textarea_select_fragment(), textarea_select_paragraph(), and textarea_set_caret_internal().

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

◆ textarea_get_dimensions()

void textarea_get_dimensions ( struct textarea ta,
int *  width,
int *  height 
)

Gets the dimensions of a textarea.

Parameters
tatextarea widget
widthif not NULL, gets updated to the width of the textarea
heightif not NULL, gets updated to the height of the textarea

Definition at line 3308 of file textarea.c.

References height, textarea::vis_height, textarea::vis_width, and width.

◆ textarea_get_selection()

char * textarea_get_selection ( struct textarea ta)

Get selected text.

ownership of the returned string is passed to caller which needs to free it.

Parameters
taTextarea widget
Returns
Selected text, or NULL if none.

Definition at line 3278 of file textarea.c.

References textarea_utf8::data, textarea::sel_end, textarea::sel_start, and textarea::show.

Referenced by html_get_selection().

Here is the caller graph for this function:

◆ textarea_get_text()

int textarea_get_text ( struct textarea ta,
char *  buf,
unsigned int  len 
)

Extract the text from a text area.

Parameters
taText area
bufPointer to buffer to receive data, or NULL to read length required (includes trailing '\0')
lenLength (bytes) of buffer pointed to by buf, or 0 to read length
Returns
Length (bytes) written/required or -1 on error

Definition at line 2078 of file textarea.c.

References textarea_utf8::data, textarea_utf8::len, NSLOG, textarea::text, and text().

Referenced by toolbar_get_url(), toolbar_key_input(), treeview__search_cancel(), and treeview_edit_done().

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

◆ textarea_insert_text()

static bool textarea_insert_text ( struct textarea ta,
const char *  text,
size_t  b_off,
size_t  b_len,
int *  byte_delta,
struct rect r 
)
static

Insert text into the textarea.

Parameters
taTextarea widget
textUTF-8 text to insert
b_off0-based byte offset in ta->show's text to insert at
b_lenByte length of UTF-8 text
byte_deltaUpdated to change in byte count in textarea (ta->show)
rModified/reduced to area where redraw is required
Returns
false on memory exhaustion, true otherwise

Note: b_off must be for ta->show

Definition at line 1311 of file textarea.c.

References textarea_utf8::alloc, textarea_utf8::data, textarea::flags, textarea_utf8::len, NSLOG, textarea::password, PASSWORD_REPLACEMENT_W, TA_ALLOC_STEP, textarea::text, text(), TEXTAREA_MULTILINE, textarea_normalise_text(), TEXTAREA_PASSWORD, TEXTAREA_READONLY, textarea_reflow_multiline(), textarea_reflow_singleline(), utf8_bounded_byte_length(), utf8_bounded_length(), and textarea_utf8::utf8_len.

Referenced by textarea_replace_text_internal().

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

◆ textarea_keypress()

bool textarea_keypress ( struct textarea ta,
uint32_t  key 
)

Key press handling for text areas.

Parameters
taThe text area which got the keypress
keyThe ucs4 character codepoint
Returns
true if the keypress is dealt with, false otherwise.

< Redraw rectangle

Definition at line 2450 of file textarea.c.

References line_info::b_length, line_info::b_start, textarea::bar_x, textarea::bar_y, textarea::border_width, textarea::byte_off, textarea::callback, textarea::caret_pos, textarea::caret_x, netsurf_table::clipboard, clipboard, textarea_utf8::data, textarea::data, textarea_msg::data, textarea::flags, gui_clipboard_table::get, guit, textarea::h_extent, textarea_utf8::len, textarea::line, line(), textarea::line_count, textarea::line_height, textarea::lines, NS_KEY_CLEAR_SELECTION, NS_KEY_COPY_SELECTION, NS_KEY_CR, NS_KEY_CUT_SELECTION, NS_KEY_DELETE_LEFT, NS_KEY_DELETE_LINE, NS_KEY_DELETE_LINE_END, NS_KEY_DELETE_LINE_START, NS_KEY_DELETE_RIGHT, NS_KEY_DELETE_WORD_LEFT, NS_KEY_DELETE_WORD_RIGHT, NS_KEY_DOWN, NS_KEY_ESCAPE, NS_KEY_LEFT, NS_KEY_LINE_END, NS_KEY_LINE_START, NS_KEY_NL, NS_KEY_PAGE_DOWN, NS_KEY_PAGE_UP, NS_KEY_PASTE, NS_KEY_REDO, NS_KEY_RIGHT, NS_KEY_SELECT_ALL, NS_KEY_TEXT_END, NS_KEY_TEXT_START, NS_KEY_UNDO, NS_KEY_UP, NS_KEY_WORD_LEFT, NS_KEY_WORD_RIGHT, textarea::pad_bottom, textarea::pad_top, textarea_msg::redraw, textarea::sel_end, textarea::sel_start, textarea::show, textarea_msg::ta, textarea::text, textarea::text_y_offset_baseline, textarea_clear_selection(), textarea_get_caret(), TEXTAREA_MSG_REDRAW_REQUEST, TEXTAREA_MULTILINE, TEXTAREA_PASSWORD, TEXTAREA_READONLY, textarea_replace_text(), textarea_reset_selection(), textarea_scroll(), textarea_select(), textarea_set_caret_internal(), textarea_set_caret_xy(), textarea_undo(), textarea_msg::type, utf8_from_ucs4(), utf8_next(), utf8_prev(), textarea::v_extent, textarea::vis_height, textarea::vis_width, rect::x0, rect::x1, rect::y0, and rect::y1.

Referenced by box_textarea_keypress(), toolbar_key_input(), and treeview_keypress().

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

◆ textarea_mouse_action()

textarea_mouse_status textarea_mouse_action ( struct textarea ta,
browser_mouse_state  mouse,
int  x,
int  y 
)

Handles all kinds of mouse action.

Parameters
taText area
mousethe mouse state at action moment
xX coordinate
yY coordinate
Returns
the textarea mouse status

Definition at line 3069 of file textarea.c.

References textarea::bar_x, textarea::bar_y, textarea::border_width, BROWSER_MOUSE_DOUBLE_CLICK, BROWSER_MOUSE_DRAG_1, BROWSER_MOUSE_DRAG_2, BROWSER_MOUSE_HOLDING_1, BROWSER_MOUSE_HOLDING_2, BROWSER_MOUSE_HOVER, BROWSER_MOUSE_PRESS_1, BROWSER_MOUSE_PRESS_2, BROWSER_MOUSE_TRIPLE_CLICK, textarea::callback, textarea::data, textarea_msg::data, textarea_msg::drag, textarea::drag_info, textarea::drag_start, textarea::flags, SCROLLBAR_WIDTH, textarea::sel_end, textarea::sel_start, textarea_msg::ta, textarea_clear_selection(), textarea_drag_end(), TEXTAREA_DRAG_NONE, TEXTAREA_DRAG_SELECTION, textarea_get_b_off_xy(), textarea_get_caret(), TEXTAREA_MOUSE_EDITOR, TEXTAREA_MOUSE_NONE, textarea_mouse_scrollbar_action(), TEXTAREA_MOUSE_SELECTION, TEXTAREA_MOUSE_USED, TEXTAREA_MSG_DRAG_REPORT, TEXTAREA_MULTILINE, textarea_scroll(), textarea_select(), textarea_select_fragment(), textarea_select_paragraph(), textarea_set_caret_internal(), textarea_set_caret_xy(), textarea_drag::type, textarea_msg::type, textarea::vis_height, textarea::vis_width, textarea_msg::x, and textarea_msg::y.

Referenced by gadget_mouse_action(), html_drop_file_at_point(), mouse_action_drag_textarea(), toolbar_mouse_input(), treeview_edit_node_at_point(), and treeview_mouse_action().

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

◆ textarea_mouse_scrollbar_action()

static textarea_mouse_status textarea_mouse_scrollbar_action ( struct textarea ta,
browser_mouse_state  mouse,
int  x,
int  y 
)
static

Definition at line 3010 of file textarea.c.

References textarea::bar_x, textarea::bar_y, textarea::border_width, textarea_drag::data, textarea::drag_info, textarea_drag::scrollbar, scrollbar_mouse_action(), SCROLLBAR_MOUSE_USED, SCROLLBAR_WIDTH, TEXTAREA_DRAG_NONE, TEXTAREA_DRAG_SCROLLBAR, TEXTAREA_MOUSE_NONE, TEXTAREA_MOUSE_SCR_USED, textarea_drag::type, textarea::vis_height, and textarea::vis_width.

Referenced by textarea_mouse_action().

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

◆ textarea_normalise_text()

static void textarea_normalise_text ( struct textarea ta,
unsigned int  b_start,
unsigned int  b_len 
)
static

Normalises any line endings within the text, replacing CRLF or CR with LF as necessary.

If the textarea is single line, then all linebreaks are converted into spaces.

Parameters
taText area
b_startByte offset to start at
b_lenByte length to check

Definition at line 166 of file textarea.c.

References textarea::callback, textarea_utf8::data, textarea::data, textarea_msg::data, textarea::flags, textarea_utf8::len, textarea_msg::len, textarea_msg::modified, textarea_msg::ta, textarea::text, textarea_msg::text, TEXTAREA_MSG_TEXT_MODIFIED, TEXTAREA_MULTILINE, textarea_msg::type, and textarea_utf8::utf8_len.

Referenced by textarea_insert_text(), textarea_replace_text_internal(), and textarea_set_text().

Here is the caller graph for this function:

◆ textarea_redraw()

void textarea_redraw ( struct textarea ta,
int  x,
int  y,
colour  bg,
float  scale,
const struct rect clip,
const struct redraw_context ctx 
)

Handle redraw requests for text areas.

Parameters
tatextarea to render
xx coordinate of textarea top
yy coordinate of textarea left
bgbackground colour under textarea
scalescale to render at
clipclip rectangle
ctxcurrent redraw context

Definition at line 2131 of file textarea.c.

References line_info::b_length, line_info::b_start, plot_font_style::background, textarea::bar_x, textarea::bar_y, textarea::border_col, textarea::border_width, textarea::byte_off, textarea::caret_pos, textarea::caret_x, textarea::caret_y, clip(), plotter_table::clip, textarea_utf8::data, plot_style_s::fill_colour, textarea::flags, textarea::fstyle, guit, netsurf_table::layout, line(), plotter_table::line, textarea::line_count, line_height(), textarea::line_height, textarea::lines, NS_TRANSPARENT, textarea::pad_left, redraw_context::plot, PLOT_OP_TYPE_NONE, PLOT_OP_TYPE_SOLID, pstyle_stroke_caret, plotter_table::rectangle, textarea::scroll_x, textarea::scroll_y, scrollbar_redraw(), SCROLLBAR_WIDTH, textarea::sel_end, textarea::sel_fstyle, textarea::sel_start, textarea::show, plot_font_style::size, plot_style_s::stroke_type, plotter_table::text, textarea::text_y_offset, textarea::text_y_offset_baseline, TEXTAREA_INTERNAL_CARET, textarea::vis_height, textarea::vis_width, line_info::width, gui_layout_table::width, rect::x0, rect::x1, rect::y0, and rect::y1.

Referenced by html_redraw_box(), toolbar_redraw(), and treeview_redraw().

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

◆ textarea_reflow_multiline()

static bool textarea_reflow_multiline ( struct textarea ta,
const size_t  b_start,
const int  b_length,
struct rect r 
)
static

Reflow a multiline textarea from the given line onwards.

Parameters
taTextarea to reflow
b_start0-based byte offset in ta->text to start of modification
b_lengthByte length of change in textarea text
rModified/reduced to area where redraw is required
Returns
true on success false otherwise

Definition at line 916 of file textarea.c.

References line_info::b_length, line_info::b_start, textarea::bar_x, textarea::bar_y, textarea::border_width, textarea_utf8::data, textarea::flags, textarea::fstyle, guit, textarea::h_extent, netsurf_table::layout, textarea_utf8::len, line(), LINE_CHUNK_SIZE, textarea::line_count, textarea::line_height, textarea::lines, textarea::lines_alloc_size, max, min, NSERROR_OK, NSLOG, textarea::pad_bottom, textarea::pad_left, textarea::pad_right, textarea::pad_top, textarea::scroll_x, textarea::scroll_y, scrollbar_create(), scrollbar_destroy(), scrollbar_make_pair(), scrollbar_set_extents(), SCROLLBAR_WIDTH, gui_layout_table::split, textarea::text, text(), textarea::text_y_offset, TEXTAREA_MULTILINE, textarea_scrollbar_callback(), textarea::v_extent, textarea::vis_height, textarea::vis_width, line_info::width, gui_layout_table::width, rect::x0, rect::y0, and rect::y1.

Referenced by textarea_create(), textarea_insert_text(), textarea_replace_text_internal(), textarea_set_dimensions(), textarea_set_layout(), and textarea_set_text().

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

◆ textarea_reflow_singleline()

static bool textarea_reflow_singleline ( struct textarea ta,
size_t  b_off,
struct rect r 
)
static

Reflow a single line textarea.

Parameters
taTextarea widget to reflow
b_off0-based byte offset in ta->show's text to start of modification
rModified/reduced to area where redraw is required
Returns
true on success false otherwise

Definition at line 816 of file textarea.c.

References textarea_utf8::alloc, line_info::b_length, line_info::b_start, textarea::border_width, textarea_utf8::data, textarea::flags, textarea::fstyle, guit, textarea::h_extent, netsurf_table::layout, textarea_utf8::len, LINE_CHUNK_SIZE, textarea::line_count, textarea::lines, textarea::lines_alloc_size, max, min, NSLOG, textarea::pad_left, textarea::pad_right, textarea::password, PASSWORD_REPLACEMENT, PASSWORD_REPLACEMENT_W, textarea::scroll_x, textarea::show, TA_ALLOC_STEP, textarea::text, TEXTAREA_MULTILINE, TEXTAREA_PASSWORD, textarea_utf8::utf8_len, textarea::vis_width, line_info::width, gui_layout_table::width, rect::x0, and rect::x1.

Referenced by textarea_create(), textarea_insert_text(), textarea_replace_text_internal(), textarea_set_dimensions(), textarea_set_layout(), and textarea_set_text().

Here is the caller graph for this function:

◆ textarea_replace_text()

static bool textarea_replace_text ( struct textarea ta,
size_t  b_start,
size_t  b_end,
const char *  rep,
size_t  rep_len,
bool  add_to_clipboard,
int *  byte_delta,
struct rect r 
)
static

Replace text in a textarea, updating undo buffer.

Parameters
taTextarea widget
b_startStart byte index of replaced section (inclusive)
b_endEnd byte index of replaced section (exclusive)
repReplacement UTF-8 text to insert
rep_lenByte length of replacement UTF-8 text
add_to_clipboardTrue if replaced text to be added to clipboard
byte_deltaUpdated to change in byte count in textarea (ta->show)
rUpdated to area where redraw is required
Returns
false on memory exhaustion, true otherwise

Note, b_start and b_end must be the byte offsets in ta->show, so in the password textarea case, they are for ta->password.

Definition at line 1618 of file textarea.c.

References textarea_undo_detail::b_end, textarea_undo_detail::b_start, textarea_undo_detail::b_text_end, textarea_undo::details, textarea::flags, textarea_undo::last_detail, textarea_undo::next_detail, textarea_copy_to_undo_buffer(), TEXTAREA_PASSWORD, textarea_replace_text_internal(), and textarea::undo.

Referenced by textarea_drop_text(), and textarea_keypress().

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

◆ textarea_replace_text_internal()

static bool textarea_replace_text_internal ( struct textarea ta,
size_t  b_start,
size_t  b_end,
const char *  rep,
size_t  rep_len,
bool  add_to_clipboard,
int *  byte_delta,
struct rect r 
)
static

Perform actual text replacment in a textarea.

Parameters
taTextarea widget
b_startStart byte index of replaced section (inclusive)
b_endEnd byte index of replaced section (exclusive)
repReplacement UTF-8 text to insert
rep_lenByte length of replacement UTF-8 text
add_to_clipboardTrue iff replaced text to be added to clipboard
byte_deltaUpdated to change in byte count in textarea (ta->show)
rUpdated to area where redraw is required
Returns
false on memory exhaustion, true otherwise

Note, b_start and b_end must be the byte offsets in ta->show, so in the password textarea case, they are for ta->password.

Definition at line 1424 of file textarea.c.

References textarea_utf8::alloc, line_info::b_start, textarea::bar_x, textarea::bar_y, textarea::border_width, netsurf_table::clipboard, textarea_utf8::data, textarea::flags, guit, textarea_utf8::len, NSLOG, textarea::password, PASSWORD_REPLACEMENT_W, SCROLLBAR_WIDTH, gui_clipboard_table::set, textarea::show, TA_ALLOC_STEP, textarea::text, textarea_char_to_byte_offset(), textarea_insert_text(), TEXTAREA_MULTILINE, textarea_normalise_text(), TEXTAREA_PASSWORD, TEXTAREA_READONLY, textarea_reflow_multiline(), textarea_reflow_singleline(), utf8_bounded_length(), textarea_utf8::utf8_len, utf8_length(), textarea::vis_height, textarea::vis_width, rect::x0, rect::x1, rect::y0, and rect::y1.

Referenced by textarea_replace_text(), and textarea_undo().

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

◆ textarea_reset_selection()

static void textarea_reset_selection ( struct textarea ta)
inlinestatic

Reset the selection (no redraw)

Parameters
taText area

Definition at line 214 of file textarea.c.

References textarea::sel_end, textarea::sel_start, and textarea_msg::ta.

Referenced by textarea_clear_selection(), and textarea_keypress().

Here is the caller graph for this function:

◆ textarea_scroll()

bool textarea_scroll ( struct textarea ta,
int  scrx,
int  scry 
)

Scroll a textarea by an amount.

Only does anything if multi-line textarea has scrollbars. If it scrolls, it will emit a redraw request.

Parameters
tatextarea widget
scrxnumber of px try to scroll in x direction
scrynumber of px try to scroll in y direction
Returns
true iff the textarea was scrolled

Definition at line 3367 of file textarea.c.

References textarea::bar_x, textarea::bar_y, textarea::border_width, textarea::flags, textarea::h_extent, textarea::scroll_x, scrollbar_scroll(), TEXTAREA_MULTILINE, and textarea::vis_width.

Referenced by html_scroll_at_point(), textarea_keypress(), and textarea_mouse_action().

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

◆ textarea_scroll_visible()

static bool textarea_scroll_visible ( struct textarea ta)
static

Scrolls a textarea to make the caret visible (doesn't perform a redraw)

Parameters
taThe text area to be scrolled
Returns
true if textarea was scrolled false otherwise

Definition at line 251 of file textarea.c.

References textarea::bar_x, textarea::bar_y, textarea::border_width, textarea::byte_off, textarea::caret_pos, textarea::caret_x, textarea::caret_y, textarea::flags, textarea::h_extent, textarea::line_height, textarea::pad_bottom, textarea::pad_left, textarea::pad_right, textarea::pad_top, textarea::scroll_x, textarea::scroll_y, scrollbar_get_offset(), scrollbar_set(), SCROLLBAR_WIDTH, textarea_msg::ta, TEXTAREA_MULTILINE, textarea::v_extent, textarea::vis_height, textarea::vis_width, textarea_msg::x, and textarea_msg::y.

Referenced by textarea_set_caret_internal().

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

◆ textarea_scrollbar_callback()

static void textarea_scrollbar_callback ( void *  client_data,
struct scrollbar_msg_data scrollbar_data 
)
static

◆ textarea_select()

static bool textarea_select ( struct textarea ta,
int  b_start,
int  b_end,
bool  force_redraw 
)
static

Selects a character range in the textarea and redraws it.

Parameters
taText area
b_startFirst character (inclusive) byte offset
b_endLast character (exclusive) byte offset
force_redrawRedraw whether selection changed or not
Returns
true on success false otherwise

Definition at line 503 of file textarea.c.

References line_info::b_start, textarea::bar_x, textarea::bar_y, textarea::border_width, textarea::callback, textarea_msg::caret, textarea::data, textarea_msg::data, textarea::flags, textarea_msg::have_selection, textarea::line_count, textarea::line_height, textarea::lines, max, min, textarea_msg::read_only, textarea_msg::redraw, textarea::scroll_y, SCROLLBAR_WIDTH, textarea::sel_end, textarea::sel_start, textarea_msg::selection, textarea_msg::ta, textarea::text_y_offset, textarea_msg::TEXTAREA_CARET_HIDE, textarea_clear_selection(), TEXTAREA_INTERNAL_CARET, TEXTAREA_MSG_CARET_UPDATE, TEXTAREA_MSG_REDRAW_REQUEST, TEXTAREA_MSG_SELECTION_REPORT, TEXTAREA_READONLY, textarea_msg::type, textarea::vis_height, textarea::vis_width, rect::x0, rect::x1, rect::y0, and rect::y1.

Referenced by textarea_drag_end(), textarea_keypress(), textarea_mouse_action(), textarea_select_fragment(), and textarea_select_paragraph().

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

◆ textarea_select_fragment()

static bool textarea_select_fragment ( struct textarea ta)
static

Selects a text fragment, relative to current caret position.

Parameters
taText area
Returns
True on success, false otherwise

Definition at line 628 of file textarea.c.

References textarea_utf8::data, textarea_utf8::len, textarea::show, textarea_msg::ta, textarea_get_caret(), and textarea_select().

Referenced by textarea_mouse_action().

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

◆ textarea_select_paragraph()

static bool textarea_select_paragraph ( struct textarea ta)
static

Selects paragraph, at current caret position.

Parameters
tatextarea widget
Returns
True on success, false otherwise

Definition at line 679 of file textarea.c.

References textarea_utf8::data, textarea_utf8::len, textarea::show, textarea_msg::ta, textarea_get_caret(), and textarea_select().

Referenced by textarea_mouse_action().

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

◆ textarea_set_caret()

bool textarea_set_caret ( struct textarea ta,
int  caret 
)

Set the caret's position.

Parameters
taText area
caret0-based character index to place caret at, -1 removes the caret
Returns
true on success false otherwise

Definition at line 2112 of file textarea.c.

References textarea_utf8::data, textarea_utf8::len, textarea::show, textarea_set_caret_internal(), and utf8_bounded_byte_length().

Referenced by box_textarea_keypress(), textarea_get_caret(), treeview__search_cancel(), and treeview_mouse_action().

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

◆ textarea_set_caret_internal()

static bool textarea_set_caret_internal ( struct textarea ta,
int  caret_b 
)
static

Set the caret position.

Parameters
taText area
caret_bByte offset to caret
Returns
true iff caret placement caused a scroll

Definition at line 352 of file textarea.c.

References line_info::b_start, textarea::bar_x, textarea::bar_y, textarea::border_width, textarea::byte_off, textarea::callback, textarea_msg::caret, textarea::caret_pos, textarea::caret_x, textarea::caret_y, textarea_msg::clip, textarea_utf8::data, textarea::data, textarea_msg::data, textarea::flags, textarea::fstyle, guit, textarea_msg::height, height, netsurf_table::layout, textarea_utf8::len, textarea::line, textarea::line_count, textarea::line_height, textarea::lines, max, min, textarea::pad_left, textarea_msg::pos, textarea_msg::redraw, textarea::scroll_x, textarea::scroll_y, SCROLLBAR_WIDTH, textarea::show, textarea_msg::ta, textarea::text_y_offset, textarea_get_caret(), TEXTAREA_INTERNAL_CARET, TEXTAREA_MSG_CARET_UPDATE, TEXTAREA_MSG_REDRAW_REQUEST, TEXTAREA_MULTILINE, textarea_scroll_visible(), textarea_msg::type, textarea::vis_height, textarea::vis_width, width, gui_layout_table::width, textarea_msg::x, rect::x0, rect::x1, textarea_msg::y, rect::y0, and rect::y1.

Referenced by textarea_drop_text(), textarea_keypress(), textarea_mouse_action(), textarea_set_caret(), and textarea_set_caret_xy().

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

◆ textarea_set_caret_xy()

static bool textarea_set_caret_xy ( struct textarea ta,
int  x,
int  y,
bool  visible 
)
static

Set the caret's position.

Parameters
tatextarea widget
xX coordinate
yY coordinate
visibletrue iff (x,y) is wrt visiable area, false for global
Returns
true iff caret placement caused a scroll

Definition at line 1289 of file textarea.c.

References textarea_get_b_off_xy(), and textarea_set_caret_internal().

Referenced by textarea_keypress(), and textarea_mouse_action().

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

◆ textarea_set_dimensions()

void textarea_set_dimensions ( struct textarea ta,
int  width,
int  height 
)

Set the dimensions of a textarea.

This causes a reflow of the text and does not emit a redraw request. Up to client to call textarea_redraw.

Parameters
tatextarea widget
widththe new width of the textarea
heightthe new height of the textarea

Definition at line 3318 of file textarea.c.

References textarea::flags, height, textarea_utf8::len, textarea::show, TEXTAREA_MULTILINE, textarea_reflow_multiline(), textarea_reflow_singleline(), textarea_setup_text_offsets(), textarea::vis_height, textarea::vis_width, and width.

Referenced by toolbar_set_dimensions(), and toolbar_set_width().

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

◆ textarea_set_layout()

void textarea_set_layout ( struct textarea ta,
const plot_font_style_t fstyle,
int  width,
int  height,
int  top,
int  right,
int  bottom,
int  left 
)

Set the dimensions and padding of a textarea.

This causes a reflow of the text. Does not emit a redraw request. Up to client to call textarea_redraw.

Parameters
tatextarea widget
widththe new width of the textarea
heightthe new height of the textarea
topthe new top padding of the textarea
rightthe new right padding of the textarea
bottomthe new bottom padding of the textarea
leftthe new left padding of the textarea

Definition at line 3336 of file textarea.c.

References plot_font_style::background, textarea::bar_x, textarea::bar_y, textarea::flags, plot_font_style::foreground, height, textarea_utf8::len, textarea::pad_bottom, textarea::pad_left, textarea::pad_right, textarea::pad_top, SCROLLBAR_WIDTH, textarea::sel_fstyle, textarea::show, TEXTAREA_MULTILINE, textarea_reflow_multiline(), textarea_reflow_singleline(), textarea_set_text_style(), textarea_setup_text_offsets(), textarea::vis_height, textarea::vis_width, and width.

Referenced by layout_block_context().

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

◆ textarea_set_text()

bool textarea_set_text ( struct textarea ta,
const char *  text 
)

Set the text in a text area, discarding any current text.

Parameters
taText area
textUTF-8 text to set text area's contents to
Returns
true on success, false on memory exhaustion

Definition at line 1995 of file textarea.c.

References textarea_utf8::alloc, textarea_utf8::data, textarea::flags, textarea_undo::last_detail, textarea_utf8::len, textarea_undo::next_detail, NSLOG, TA_ALLOC_STEP, textarea::text, text(), TEXTAREA_MULTILINE, textarea_normalise_text(), textarea_reflow_multiline(), textarea_reflow_singleline(), textarea::undo, textarea_utf8::utf8_len, and utf8_length().

Referenced by box_textarea_create_textarea(), form_gadget_sync_with_dom(), toolbar_set_url(), treeview__search_cancel(), treeview_edit_node_at_point(), and treeview_set_search_string().

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

◆ textarea_set_text_style()

static void textarea_set_text_style ( struct textarea ta,
const plot_font_style_t fstyle,
colour  selected_text,
colour  selected_bg 
)
static

Set font styles up for a textarea.

Parameters
[in]taTextarea to update.
[in]fstyleFont style to set in textarea.
[in]selected_textTextarea selected text colour.
[in]selected_bgTextarea selection background colour.

Definition at line 1837 of file textarea.c.

References plot_font_style::background, plot_font_style::foreground, textarea::fstyle, textarea::sel_fstyle, and textarea_msg::ta.

Referenced by textarea_create(), and textarea_set_layout().

Here is the caller graph for this function:

◆ textarea_setup_text_offsets()

static void textarea_setup_text_offsets ( struct textarea ta)
static

Setup text offsets after height / border / padding change.

Parameters
taTextarea widget

Definition at line 1802 of file textarea.c.

References textarea::border_width, textarea::flags, textarea::fstyle, textarea::line_height, nscss_screen_dpi, textarea::pad_top, PLOT_STYLE_SCALE, plot_font_style::size, textarea_msg::ta, textarea::text_y_offset, textarea::text_y_offset_baseline, TEXTAREA_MULTILINE, and textarea::vis_height.

Referenced by textarea_create(), textarea_set_dimensions(), and textarea_set_layout().

Here is the caller graph for this function:

◆ textarea_undo()

static bool textarea_undo ( struct textarea ta,
bool  forward,
unsigned int *  caret,
struct rect r 
)
static

Undo or redo previous change.

Parameters
taTextarea widget
forwardIff true, redo, else undo
caretUpdated to new caret pos in textarea (ta->show)
rUpdated to area where redraw is required
Returns
false if nothing to undo/redo, true otherwise

Definition at line 1660 of file textarea.c.

References textarea_undo_detail::b_end, textarea_undo_detail::b_start, textarea_undo_detail::b_text_end, textarea_undo_detail::b_text_start, textarea_utf8::data, textarea_undo::details, textarea::flags, textarea_undo::last_detail, textarea_undo::next_detail, textarea_undo::text, textarea::text, TEXTAREA_PASSWORD, TEXTAREA_READONLY, textarea_replace_text_internal(), and textarea::undo.

Referenced by textarea_keypress().

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

Variable Documentation

◆ pstyle_stroke_caret

plot_style_t pstyle_stroke_caret
static
Initial value:
= {
.stroke_type = PLOT_OP_TYPE_SOLID,
.stroke_colour = CARET_COLOR,
.stroke_width = plot_style_int_to_fixed(1),
}
#define CARET_COLOR
Definition: textarea.c:44
#define plot_style_int_to_fixed(v)
Definition: plot_style.h:51
@ PLOT_OP_TYPE_SOLID
Solid colour.
Definition: plot_style.h:67

Definition at line 47 of file textarea.c.

Referenced by textarea_redraw().