From e8950dee22e82c00dcf48efe2b7125d87776c682 Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Tue, 5 Mar 2013 14:51:16 +0000 Subject: Propagate native caret clip rect through core. --- desktop/browser.c | 3 ++- desktop/browser.h | 4 ++-- desktop/textarea.c | 24 +++++++++++++++++++++--- desktop/textinput.c | 30 +++++++++++++++++++----------- render/html_interaction.c | 11 ++++++++++- 5 files changed, 54 insertions(+), 18 deletions(-) diff --git a/desktop/browser.c b/desktop/browser.c index e42f6e200..8d115e749 100644 --- a/desktop/browser.c +++ b/desktop/browser.c @@ -1546,7 +1546,8 @@ nserror browser_window_callback(hlcache_handle *c, browser_window_place_caret(bw, event->data.caret.pos.x, event->data.caret.pos.y, - event->data.caret.pos.height); + event->data.caret.pos.height, + event->data.caret.pos.clip); break; } break; diff --git a/desktop/browser.h b/desktop/browser.h index dcc728b56..44eac992f 100644 --- a/desktop/browser.h +++ b/desktop/browser.h @@ -202,8 +202,8 @@ bool browser_window_stop_available(struct browser_window *bw); /* In desktop/textinput.c */ -void browser_window_place_caret(struct browser_window *bw, - int x, int y, int height); +void browser_window_place_caret(struct browser_window *bw, int x, int y, + int height, const struct rect *clip); void browser_window_remove_caret(struct browser_window *bw, bool only_hide); bool browser_window_key_press(struct browser_window *bw, uint32_t key); diff --git a/desktop/textarea.c b/desktop/textarea.c index 73781f261..26c1e0ba4 100644 --- a/desktop/textarea.c +++ b/desktop/textarea.c @@ -462,13 +462,19 @@ static void textarea_scrollbar_callback(void *client_data, if (!(ta->flags & TEXTAREA_INTERNAL_CARET)) { /* Tell client where caret should be placed */ + struct rect cr = { + .x0 = ta->border_width, + .y0 = ta->border_width, + .x1 = ta->vis_width - ta->border_width, + .y1 = ta->vis_height - ta->border_width + }; msg.ta = ta; msg.type = TEXTAREA_MSG_CARET_UPDATE; msg.data.caret.type = TEXTAREA_CARET_SET_POS; msg.data.caret.pos.x = ta->caret_x - ta->scroll_x; msg.data.caret.pos.y = ta->caret_y - ta->scroll_y; msg.data.caret.pos.height = ta->line_height; - msg.data.caret.pos.clip = NULL; + msg.data.caret.pos.clip = &cr; ta->callback(ta->data, &msg); } @@ -1443,13 +1449,19 @@ bool textarea_set_caret(struct textarea *ta, int caret) if (!(ta->flags & TEXTAREA_INTERNAL_CARET)) { /* Tell client where caret should be placed */ + struct rect cr = { + .x0 = ta->border_width, + .y0 = ta->border_width, + .x1 = ta->vis_width - ta->border_width, + .y1 = ta->vis_height - ta->border_width + }; msg.ta = ta; msg.type = TEXTAREA_MSG_CARET_UPDATE; msg.data.caret.type = TEXTAREA_CARET_SET_POS; msg.data.caret.pos.x = x - ta->scroll_x; msg.data.caret.pos.y = y - ta->scroll_y; msg.data.caret.pos.height = ta->line_height; - msg.data.caret.pos.clip = NULL; + msg.data.caret.pos.clip = &cr; ta->callback(ta->data, &msg); } @@ -2375,13 +2387,19 @@ bool textarea_clear_selection(struct textarea *ta) if (!(ta->flags & TEXTAREA_INTERNAL_CARET)) { /* Tell client where caret should be placed */ + struct rect cr = { + .x0 = ta->border_width, + .y0 = ta->border_width, + .x1 = ta->vis_width - ta->border_width, + .y1 = ta->vis_height - ta->border_width + }; msg.ta = ta; msg.type = TEXTAREA_MSG_CARET_UPDATE; msg.data.caret.type = TEXTAREA_CARET_SET_POS; msg.data.caret.pos.x = ta->caret_x - ta->scroll_x; msg.data.caret.pos.y = ta->caret_y - ta->scroll_y; msg.data.caret.pos.height = ta->line_height; - msg.data.caret.pos.clip = NULL; + msg.data.caret.pos.clip = &cr; ta->callback(ta->data, &msg); } diff --git a/desktop/textinput.c b/desktop/textinput.c index 6ffa02c86..4d280d536 100644 --- a/desktop/textinput.c +++ b/desktop/textinput.c @@ -52,22 +52,19 @@ /** * Position the caret and assign a callback for key presses. * - * \param bw The browser window in which to place the caret - * \param x X coordinate of the caret - * \param y Y coordinate - * \param height Height of caret - * \param caret_cb Callback function for keypresses - * \param paste_cb Callback function for pasting text - * \param move_cb Callback function for caret movement - * \param p1 Callback private data pointer, passed to callback function - * \param p2 Callback private data pointer, passed to callback function + * \param bw The browser window in which to place the caret + * \param x X coordinate of the caret + * \param y Y coordinate + * \param height Height of caret + * \param clip Clip rectangle for caret */ -void browser_window_place_caret(struct browser_window *bw, - int x, int y, int height) +void browser_window_place_caret(struct browser_window *bw, int x, int y, + int height, const struct rect *clip) { struct browser_window *root_bw; int pos_x = 0; int pos_y = 0; + struct rect cr; /* Find top level browser window */ root_bw = browser_window_get_root(bw); @@ -76,6 +73,17 @@ void browser_window_place_caret(struct browser_window *bw, x = x * bw->scale + pos_x; y = y * bw->scale + pos_y; + if (clip != NULL) { + cr = *clip; + cr.x0 += pos_x; + cr.y0 += pos_y; + cr.x1 += pos_x; + cr.y1 += pos_y; + } + + /* TODO: intersect with bw viewport */ + /* TODO: pass clip rect out to GUI */ + gui_window_place_caret(root_bw->window, x, y, height * bw->scale); /* Set focus browser window */ diff --git a/render/html_interaction.c b/render/html_interaction.c index 87a08a4a7..805932e31 100644 --- a/render/html_interaction.c +++ b/render/html_interaction.c @@ -1144,11 +1144,20 @@ void html_set_focus(html_content *html, html_focus_type focus_type, } else if (focus_type != HTML_FOCUS_SELF && hide_caret) { msg_data.caret.type = CONTENT_CARET_HIDE; } else { + struct rect cr; + if (clip != NULL) { + cr = *clip; + cr.x0 += x_off; + cr.y0 += y_off; + cr.x1 += x_off; + cr.y1 += y_off; + } + msg_data.caret.type = CONTENT_CARET_SET_POS; msg_data.caret.pos.x = x + x_off; msg_data.caret.pos.y = y + y_off; msg_data.caret.pos.height = height; - msg_data.caret.pos.clip = clip; + msg_data.caret.pos.clip = (clip == NULL) ? NULL : &cr; } /* Inform of the content's drag status change */ -- cgit v1.2.3