NetSurf
Data Structures | Enumerations | Functions
selection.c File Reference

implementation of text selection within browser windows. More...

#include <stdlib.h>
#include <string.h>
#include "netsurf/clipboard.h"
#include "netsurf/browser_window.h"
#include "netsurf/window.h"
#include "utils/utils.h"
#include "content/content_protected.h"
#include "desktop/browser_private.h"
#include "desktop/gui_internal.h"
#include "desktop/selection.h"
Include dependency graph for selection.c:

Go to the source code of this file.

Data Structures

struct  selection_string
 
struct  selection
 

Enumerations

enum  seln_drag_state { DRAG_NONE , DRAG_START , DRAG_END }
 

Functions

static nserror selection_redraw (struct selection *s, unsigned start_idx, unsigned end_idx)
 Redraws the given range of text. More...
 
static void selection_set_start (struct selection *s, unsigned offset)
 Set the start position of the current selection, updating the screen. More...
 
static void selection_set_end (struct selection *s, unsigned offset)
 Set the end position of the current selection, updating the screen. More...
 
static bool selection_copy (struct selection *s, struct selection_string *selstr)
 Traverse the current selection, calling the handler function (with its handle) for all boxes that lie (partially) within the given range. More...
 
bool selection_string_append (const char *text, size_t length, bool space, plot_font_style_t *style, struct selection_string *sel_string)
 Append text to selection string. More...
 
struct selectionselection_create (struct content *c)
 Creates a new selection object associated with a browser window. More...
 
void selection_destroy (struct selection *s)
 Destroys a selection object clearing it if nesessary. More...
 
void selection_reinit (struct selection *s)
 Initialise the selection object to use the given box subtree as its root, ie. More...
 
void selection_init (struct selection *s)
 Initialise the selection object to use the given box subtree as its root, ie. More...
 
bool selection_click (struct selection *s, struct browser_window *top, browser_mouse_state mouse, unsigned idx)
 Handles mouse clicks (including drag starts) in or near a selection. More...
 
void selection_track (struct selection *s, browser_mouse_state mouse, unsigned idx)
 Handles movements related to the selection, eg. More...
 
char * selection_get_copy (struct selection *s)
 Get copy of selection as string. More...
 
bool selection_copy_to_clipboard (struct selection *s)
 Copy the selected contents to the clipboard. More...
 
bool selection_clear (struct selection *s, bool redraw)
 Clears the current selection, optionally causing the screen to be updated. More...
 
void selection_select_all (struct selection *s)
 Selects all the text within the box subtree controlled by this selection object, updating the screen accordingly. More...
 
void selection_set_position (struct selection *s, unsigned start, unsigned end)
 Set the position of the current selection, updating the screen. More...
 
bool selection_highlighted (const struct selection *s, unsigned start, unsigned end, unsigned *start_idx, unsigned *end_idx)
 Tests whether a text range lies partially within the selection, if there is a selection defined, returning the start and end indexes of the bytes that should be selected. More...
 
bool selection_active (struct selection *s)
 determine if a selecion is active More...
 
bool selection_dragging (struct selection *s)
 
bool selection_dragging_start (struct selection *s)
 
void selection_drag_end (struct selection *s)
 Handles completion of a drag operation. More...
 

Detailed Description

implementation of text selection within browser windows.

Definition in file selection.c.

Enumeration Type Documentation

◆ seln_drag_state

Enumerator
DRAG_NONE 
DRAG_START 
DRAG_END 

Definition at line 49 of file selection.c.

Function Documentation

◆ selection_active()

bool selection_active ( struct selection s)

determine if a selecion is active

Definition at line 586 of file selection.c.

References selection::defined.

Referenced by default_mouse_action().

Here is the caller graph for this function:

◆ selection_clear()

bool selection_clear ( struct selection s,
bool  redraw 
)

Clears the current selection, optionally causing the screen to be updated.

Used from text and html content handlers

Parameters
sselection object
redrawtrue iff the previously selected region of the browser window should be redrawn
Returns
true if selection was cleared false if not

Definition at line 518 of file selection.c.

References selection::defined, selection::end_idx, selection_redraw(), and selection::start_idx.

Referenced by default_mouse_action(), html_clear_selection(), html_close(), html_keypress(), html_set_selection(), selection_click(), selection_create(), selection_destroy(), selection_init(), and textplain_keypress().

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

◆ selection_click()

bool selection_click ( struct selection s,
struct browser_window top,
browser_mouse_state  mouse,
unsigned  idx 
)

Handles mouse clicks (including drag starts) in or near a selection.

Used from text and html content handlers

Parameters
sselection object
mousestate of mouse buttons and modifier keys
idxbyte offset within textual representation
Returns
true iff the click has been handled by the selection code

Definition at line 319 of file selection.c.

References BROWSER_MOUSE_CLICK_2, BROWSER_MOUSE_DRAG_1, BROWSER_MOUSE_DRAG_2, BROWSER_MOUSE_MOD_1, BROWSER_MOUSE_MOD_2, BROWSER_MOUSE_PRESS_1, browser_window_get_root(), selection::defined, DRAG_END, DRAG_NONE, gui_window_table::drag_save_selection, DRAG_START, selection::drag_state, selection::end_idx, gui_window_table::event, guit, GW_EVENT_START_SELECTION, selection_clear(), selection_get_copy(), selection_set_end(), selection_set_start(), selection::start_idx, browser_window::window, and netsurf_table::window.

Referenced by default_mouse_action(), and textplain_mouse_action().

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

◆ selection_copy()

static bool selection_copy ( struct selection s,
struct selection_string selstr 
)
static

Traverse the current selection, calling the handler function (with its handle) for all boxes that lie (partially) within the given range.

Parameters
sThe selection context.
handlerhandler function to call
handlehandle to pass
Returns
false iff traversal abandoned part-way through

Definition at line 160 of file selection.c.

References selection::c, selection::end_idx, content::handler, NSERROR_NOT_IMPLEMENTED, NSERROR_OK, selection::start_idx, and content_handler::textselection_copy.

Referenced by selection_copy_to_clipboard(), and selection_get_copy().

Here is the caller graph for this function:

◆ selection_copy_to_clipboard()

bool selection_copy_to_clipboard ( struct selection s)

Copy the selected contents to the clipboard.

Used from text and html content handlers

Parameters
sselection
Returns
true iff successful

Definition at line 484 of file selection.c.

References selection_string::buffer, netsurf_table::clipboard, selection::defined, guit, selection_string::length, selection_string::n_styles, selection_copy(), gui_clipboard_table::set, and selection_string::styles.

Referenced by html_keypress(), and textplain_keypress().

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

◆ selection_create()

struct selection * selection_create ( struct content c)

Creates a new selection object associated with a browser window.

Used from text and html content handlers

Returns
new selection context

Definition at line 253 of file selection.c.

References selection::c, DRAG_NONE, selection::drag_state, selection::max_idx, and selection_clear().

Referenced by html_create_html_data(), search_show_all(), and textplain_create_internal().

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

◆ selection_destroy()

void selection_destroy ( struct selection s)

Destroys a selection object clearing it if nesessary.

Used from content textsearch

Parameters
sselection object

Definition at line 269 of file selection.c.

References selection_clear().

Referenced by free_matches(), html_destroy(), search_show_all(), and textplain_destroy().

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

◆ selection_drag_end()

void selection_drag_end ( struct selection s)

Handles completion of a drag operation.

Definition at line 601 of file selection.c.

References DRAG_NONE, and selection::drag_state.

◆ selection_dragging()

bool selection_dragging ( struct selection s)

Definition at line 591 of file selection.c.

References DRAG_NONE, and selection::drag_state.

Referenced by default_mouse_action(), and textplain_mouse_action().

Here is the caller graph for this function:

◆ selection_dragging_start()

bool selection_dragging_start ( struct selection s)

Definition at line 596 of file selection.c.

References DRAG_START, and selection::drag_state.

Referenced by mouse_action_drag_selection(), and textplain_mouse_track().

Here is the caller graph for this function:

◆ selection_get_copy()

char * selection_get_copy ( struct selection s)

Get copy of selection as string.

Used from text and html content handlers

Parameters
sselection
Returns
string of selected text, or NULL. Ownership passed to caller.

Definition at line 457 of file selection.c.

References selection_string::buffer, selection::defined, selection_copy(), and selection_string::styles.

Referenced by html_get_selection(), selection_click(), and textplain_get_selection().

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

◆ selection_highlighted()

bool selection_highlighted ( const struct selection s,
unsigned  start,
unsigned  end,
unsigned *  start_idx,
unsigned *  end_idx 
)

Tests whether a text range lies partially within the selection, if there is a selection defined, returning the start and end indexes of the bytes that should be selected.

Used from text and html content handlers, content textsearch

Parameters
sthe selection object
startbyte offset of start of text
endbyte offset of end of text
start_idxreceives the start index (in bytes) of the highlighted portion
end_idxreceives the end index (in bytes)
Returns
true iff part of the given box lies within the selection

Definition at line 562 of file selection.c.

References selection::defined, selection::end_idx, min, and selection::start_idx.

Referenced by content_textsearch_ishighlighted(), text_draw(), text_redraw(), and textplain_redraw().

Here is the caller graph for this function:

◆ selection_init()

void selection_init ( struct selection s)

Initialise the selection object to use the given box subtree as its root, ie.

selections are confined to that subtree.

Used from text and html content handlers

Parameters
sselection object

Definition at line 302 of file selection.c.

References selection::defined, DRAG_NONE, selection::drag_state, selection::end_idx, selection_clear(), selection_reinit(), and selection::start_idx.

Referenced by html_open(), search_show_all(), and textplain_open().

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

◆ selection_redraw()

static nserror selection_redraw ( struct selection s,
unsigned  start_idx,
unsigned  end_idx 
)
static

Redraws the given range of text.

Parameters
sselection object
start_idxstart offset (bytes) within the textual representation
end_idxend offset (bytes) within the textual representation

Definition at line 76 of file selection.c.

References selection::c, content::handler, NSERROR_NOT_IMPLEMENTED, and content_handler::textselection_redraw.

Referenced by selection_clear(), selection_set_end(), and selection_set_start().

Here is the caller graph for this function:

◆ selection_reinit()

void selection_reinit ( struct selection s)

Initialise the selection object to use the given box subtree as its root, ie.

selections are confined to that subtree, whilst maintaining the current selection whenever possible because, for example, it's just the page being resized causing the layout to change.

Used from html content handler

Parameters
sselection object

Definition at line 281 of file selection.c.

References selection::c, selection::defined, selection::end_idx, content::handler, selection::max_idx, selection::start_idx, and content_handler::textselection_get_end.

Referenced by html_reformat(), and selection_init().

Here is the caller graph for this function:

◆ selection_select_all()

void selection_select_all ( struct selection s)

Selects all the text within the box subtree controlled by this selection object, updating the screen accordingly.

Used from text and html content handlers

Parameters
sselection object

Definition at line 542 of file selection.c.

References selection::defined, selection::max_idx, selection_set_end(), and selection_set_start().

Referenced by html_keypress(), and textplain_keypress().

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

◆ selection_set_end()

static void selection_set_end ( struct selection s,
unsigned  offset 
)
static

Set the end position of the current selection, updating the screen.

Parameters
sselection object
offsetbyte offset within textual representation

Definition at line 127 of file selection.c.

References selection::defined, selection::end_idx, selection_redraw(), and selection::start_idx.

Referenced by selection_click(), selection_select_all(), selection_set_position(), and selection_track().

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

◆ selection_set_position()

void selection_set_position ( struct selection s,
unsigned  start,
unsigned  end 
)

Set the position of the current selection, updating the screen.

Used from content textsearch

Parameters
sselection object
startbyte offset within textual representation
endbyte offset within textual representation

Definition at line 553 of file selection.c.

References selection_set_end(), and selection_set_start().

Referenced by search_show_all().

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

◆ selection_set_start()

static void selection_set_start ( struct selection s,
unsigned  offset 
)
static

Set the start position of the current selection, updating the screen.

Parameters
sselection object
offsetbyte offset within textual representation

Definition at line 98 of file selection.c.

References selection::defined, selection::end_idx, selection_redraw(), and selection::start_idx.

Referenced by selection_click(), selection_select_all(), selection_set_position(), and selection_track().

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

◆ selection_string_append()

bool selection_string_append ( const char *  text,
size_t  length,
bool  space,
plot_font_style_t style,
struct selection_string sel_string 
)

Append text to selection string.

Parameters
texttext to be added
lengthlength of text in bytes
spaceindicates whether a trailing space should be appended
styleThe font style to use.
sel_stringstring to append to, may be resized
Returns
true iff successful

Definition at line 191 of file selection.c.

References selection_string::buffer, selection_string::buffer_len, selection_string::length, selection_string::n_styles, nsnsclipboard_styles::start, nsnsclipboard_styles::style, selection_string::styles, and text().

Referenced by selection_copy_box(), and textplain_textselection_copy().

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

◆ selection_track()

void selection_track ( struct selection s,
browser_mouse_state  mouse,
unsigned  idx 
)

Handles movements related to the selection, eg.

dragging of start and end points.

Used from text and html content handlers

Parameters
sselection object
mousestate of mouse buttons and modifier keys
idxbyte offset within text representation

Definition at line 420 of file selection.c.

References DRAG_END, DRAG_NONE, DRAG_START, selection::drag_state, selection::end_idx, selection_set_end(), selection_set_start(), and selection::start_idx.

Referenced by mouse_action_drag_selection(), and textplain_mouse_track().

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