NetSurf
|
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"
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 selection * | selection_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... | |
implementation of text selection within browser windows.
Definition in file selection.c.
enum seln_drag_state |
Enumerator | |
---|---|
DRAG_NONE | |
DRAG_START | |
DRAG_END |
Definition at line 49 of file selection.c.
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().
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
s | selection object |
redraw | true iff the previously selected region of the browser window should be redrawn |
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().
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
s | selection object |
mouse | state of mouse buttons and modifier keys |
idx | byte offset within textual representation |
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().
|
static |
Traverse the current selection, calling the handler function (with its handle) for all boxes that lie (partially) within the given range.
s | The selection context. |
handler | handler function to call |
handle | handle to pass |
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().
bool selection_copy_to_clipboard | ( | struct selection * | s | ) |
Copy the selected contents to the clipboard.
Used from text and html content handlers
s | selection |
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().
Creates a new selection object associated with a browser window.
Used from text and html content handlers
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().
void selection_destroy | ( | struct selection * | s | ) |
Destroys a selection object clearing it if nesessary.
Used from content textsearch
s | selection object |
Definition at line 269 of file selection.c.
References selection_clear().
Referenced by free_matches(), html_destroy(), search_show_all(), and textplain_destroy().
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.
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().
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().
char * selection_get_copy | ( | struct selection * | s | ) |
Get copy of selection as string.
Used from text and html content handlers
s | selection |
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().
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
s | the selection object |
start | byte offset of start of text |
end | byte offset of end of text |
start_idx | receives the start index (in bytes) of the highlighted portion |
end_idx | receives the end index (in bytes) |
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().
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
s | selection 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().
|
static |
Redraws the given range of text.
s | selection object |
start_idx | start offset (bytes) within the textual representation |
end_idx | end 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().
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
s | selection 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().
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
s | selection 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().
|
static |
Set the end position of the current selection, updating the screen.
s | selection object |
offset | byte 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().
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
s | selection object |
start | byte offset within textual representation |
end | byte 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().
|
static |
Set the start position of the current selection, updating the screen.
s | selection object |
offset | byte 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().
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.
text | text to be added |
length | length of text in bytes |
space | indicates whether a trailing space should be appended |
style | The font style to use. |
sel_string | string to append to, may be resized |
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().
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
s | selection object |
mouse | state of mouse buttons and modifier keys |
idx | byte 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().