From c2a718075ad321a9cf4678e72645acda5c3471a9 Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Fri, 22 Feb 2013 12:19:35 +0000 Subject: A load of refactoring of how content selection and input work. Keypresses now go via content interface. Contents don't shove the selection object into browser windows any more. Contents report selection existence by sending message. HTML content keeps track of where selections in it exist. Contents report whether they have input focus via caret setting msg. Caret can be hidden (can still input/paste) or removed. Consolidate textarea selection handling. Make textarea report its selection status changes to client. Various textarea fixes. Changed how we decide when to clear selections, and give focus. --- desktop/textarea.h | 43 +++++++++++++++++++++++++++++++------------ 1 file changed, 31 insertions(+), 12 deletions(-) (limited to 'desktop/textarea.h') diff --git a/desktop/textarea.h b/desktop/textarea.h index 3fedeee35..befd6aa99 100644 --- a/desktop/textarea.h +++ b/desktop/textarea.h @@ -45,28 +45,39 @@ typedef enum { TEXTAREA_DRAG_NONE, TEXTAREA_DRAG_SCROLLBAR, TEXTAREA_DRAG_SELECTION -} textarea_drag_type; +} textarea_drag_type; /**< Textarea drag status */ typedef enum { TEXTAREA_MSG_DRAG_REPORT, /**< Textarea drag start/end report */ + TEXTAREA_MSG_SELECTION_REPORT, /**< Textarea text selection presence */ TEXTAREA_MSG_REDRAW_REQUEST, /**< Textarea redraw request */ - TEXTAREA_MSG_MOVED_CARET /**< Textarea caret moved */ + TEXTAREA_MSG_CARET_UPDATE /**< Textarea caret */ } textarea_msg_type; struct textarea_msg { - struct textarea *ta; + struct textarea *ta; /**< The textarea widget */ - textarea_msg_type type; + textarea_msg_type type; /**< Indicates message data type */ union { - textarea_drag_type drag; - struct rect redraw; + textarea_drag_type drag; /**< With _DRAG_REPORT */ struct { - bool hidden; - int x; - int y; - int height; - } caret; - } data; + bool have_selection; /**< Selection exists */ + bool read_only; /**< Selection can't be cut */ + } selection; /**< With _SELECTION_REPORT */ + struct rect redraw; /**< With _REDRAW_REQUEST */ + struct { + enum { + TEXTAREA_CARET_SET_POS, /**< Set coord/height */ + TEXTAREA_CARET_HIDE /**< Hide */ + } type; + struct { + int x; /**< Carret x-coord */ + int y; /**< Carret y-coord */ + int height; /**< Carret height */ + struct rect *clip; /**< Carret clip rect */ + } pos; /**< With _CARET_SET_POS */ + } caret; /**< With _CARET_UPDATE */ + } data; /**< Depends on msg type */ }; typedef struct textarea_setup { @@ -205,6 +216,14 @@ bool textarea_mouse_action(struct textarea *ta, browser_mouse_state mouse, */ bool textarea_clear_selection(struct textarea *ta); +/** + * Get selected text, ownership passed to caller, which needs to free() it. + * + * \param ta Textarea widget + * \return Selected text, or NULL if none. + */ +char *textarea_get_selection(struct textarea *ta); + /** * Gets the dimensions of a textarea * -- cgit v1.2.3