From cbf55bd418814a943422dffacf37f18c4ab3e839 Mon Sep 17 00:00:00 2001 From: John Mark Bell Date: Wed, 7 Apr 2010 06:22:15 +0000 Subject: Fix textarea crash. I cannot express just how much I hate the necessity of this change: browser windows (and other code in desktop/) should stop poking around inside content objects svn path=/trunk/netsurf/; revision=10258 --- desktop/browser.c | 16 +++++++++++----- desktop/textinput.c | 26 +++++++++++++++++++++----- 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/desktop/browser.c b/desktop/browser.c index df53819c7..2b7c50740 100644 --- a/desktop/browser.c +++ b/desktop/browser.c @@ -2315,9 +2315,15 @@ void browser_window_form_select(struct browser_window *bw, struct box *inline_box; struct form_option *o; int count; + struct content *current_content; - assert(bw); - assert(control); + assert(bw != NULL); + assert(control != NULL); + assert(bw->current_content != NULL); + + /** \todo This must die. Browser windows have no business poking + * around inside contents */ + current_content = hlcache_handle_get_content(bw->current_content); inline_box = control->box->children->children; @@ -2346,13 +2352,13 @@ void browser_window_form_select(struct browser_window *bw, talloc_free(inline_box->text); inline_box->text = 0; if (control->data.select.num_selected == 0) - inline_box->text = talloc_strdup(bw->current_content, + inline_box->text = talloc_strdup(current_content, messages_get("Form_None")); else if (control->data.select.num_selected == 1) - inline_box->text = talloc_strdup(bw->current_content, + inline_box->text = talloc_strdup(current_content, control->data.select.current->text); else - inline_box->text = talloc_strdup(bw->current_content, + inline_box->text = talloc_strdup(current_content, messages_get("Form_Many")); if (!inline_box->text) { warn_user("NoMemory", 0); diff --git a/desktop/textinput.c b/desktop/textinput.c index 7739140fb..5058ce439 100644 --- a/desktop/textinput.c +++ b/desktop/textinput.c @@ -1664,8 +1664,16 @@ bool textbox_insert(struct browser_window *bw, struct box *text_box, { char *text; struct box *input = text_box->parent->parent; + struct content *current_content; bool hide; + assert(bw != NULL); + assert(bw->current_content != NULL); + + /** \todo Stop poking around inside contents. + * Why is this code in desktop/, anyway? (It's HTML-specific) */ + current_content = hlcache_handle_get_content(bw->current_content); + if (bw->sel->defined) delete_selection(bw->sel); @@ -1702,7 +1710,7 @@ bool textbox_insert(struct browser_window *bw, struct box *text_box, } /* insert in text box */ - text = talloc_realloc(bw->current_content, text_box->text, + text = talloc_realloc(current_content, text_box->text, char, text_box->length + text_box->space + utf8_len + 1); if (!text) { @@ -1961,16 +1969,24 @@ struct box *textarea_insert_break(struct browser_window *bw, struct box *text_box, size_t char_offset) { struct box *new_br, *new_text; - char *text = talloc_array(bw->current_content, char, - text_box->length + 1); + struct content *current_content; + char *text; + + assert(bw != NULL); + assert(bw->current_content != NULL); + + /** \todo Stop poking around inside content objects */ + current_content = hlcache_handle_get_content(bw->current_content); + + text = talloc_array(current_content, char, text_box->length + 1); if (!text) { warn_user("NoMemory", 0); return NULL; } new_br = box_create(text_box->style, 0, 0, text_box->title, 0, - bw->current_content); - new_text = talloc(bw->current_content, struct box); + current_content); + new_text = talloc(current_content, struct box); if (!new_text) { warn_user("NoMemory", 0); return NULL; -- cgit v1.2.3