summaryrefslogtreecommitdiff
path: root/riscos/gui/url_bar.c
diff options
context:
space:
mode:
authorSteve Fryatt <stevef@netsurf-browser.org>2014-01-26 13:30:08 +0000
committerSteve Fryatt <stevef@netsurf-browser.org>2014-01-26 13:30:08 +0000
commit0ab5fe7c02ccbbd9a898c483219a9317b19834d0 (patch)
tree2e3a7c49db07ed43b1ded0c310e7577e7b0e47f2 /riscos/gui/url_bar.c
parentdc074042e9f4bcd7d3ccf09fcd81f9b11a0517d0 (diff)
downloadnetsurf-0ab5fe7c02ccbbd9a898c483219a9317b19834d0.tar.gz
netsurf-0ab5fe7c02ccbbd9a898c483219a9317b19834d0.tar.bz2
Improve URL handling in URL Bar.
Rationalise handling of UTF8, so that URLs are always converted into local encoding even if there is no URL icon present. In addition, make preliminary hotlist test in set_url() use local encoding, in line with all subsequent checks. Make handling of over-length URLs more sensible: warn user and completely blank the URL bar.
Diffstat (limited to 'riscos/gui/url_bar.c')
-rw-r--r--riscos/gui/url_bar.c59
1 files changed, 50 insertions, 9 deletions
diff --git a/riscos/gui/url_bar.c b/riscos/gui/url_bar.c
index 49930934f..0b6bd1c99 100644
--- a/riscos/gui/url_bar.c
+++ b/riscos/gui/url_bar.c
@@ -39,6 +39,7 @@
#include "riscos/window.h"
#include "utils/log.h"
#include "utils/messages.h"
+#include "utils/utf8.h"
#include "utils/utils.h"
#define URLBAR_HEIGHT 52
@@ -50,7 +51,6 @@
#define URLBAR_GRIGHT_GUTTER 8
#define URLBAR_FAVICON_NAME_LENGTH 12
#define URLBAR_INITIAL_LENGTH 256
-#define URLBAR_EXTEND_LENGTH 128
struct url_bar {
/** The applied theme (or NULL to use the default) */
@@ -942,24 +942,65 @@ void ro_gui_url_bar_set_url(struct url_bar *url_bar, const char *url,
{
wimp_caret caret;
os_error *error;
- const char *set_url;
+ char *local_text = NULL;
+ const char *set_url, *local_url;
nsurl *n;
- if (url_bar == NULL || url_bar->text_buffer == NULL)
+ if (url_bar == NULL || url_bar->text_buffer == NULL || url == NULL)
return;
- if (nsurl_create(url, &n) == NSERROR_OK) {
+ /* Before we do anything with the URL, get it into local encoding so
+ * that behaviour is consistant with the rest of the URL Bar module
+ * (which will act on the icon's text buffer, which is always in local
+ * encoding).
+ */
+
+ if (is_utf8) {
+ utf8_convert_ret err;
+
+ err = utf8_to_local_encoding(url, 0, &local_text);
+ if (err != UTF8_CONVERT_OK) {
+ /* A bad encoding should never happen, so assert this */
+ assert(err != UTF8_CONVERT_BADENC);
+ LOG(("utf8_to_enc failed"));
+ /* Paranoia */
+ local_text = NULL;
+ }
+ local_url = (local_text != NULL) ? local_text : url;
+ } else {
+ local_url = url;
+ }
+
+ /* Copy the text into the icon buffer. If the text is too long, blank
+ * the buffer and warn the user.
+ */
+
+ if (strlen(local_url) >= url_bar->text_size) {
+ strncpy(url_bar->text_buffer, "", url_bar->text_size);
+ warn_user("LongURL", NULL);
+ LOG(("Long URL (%d chars): %s", strlen(url), url));
+ } else {
+ strncpy(url_bar->text_buffer, local_url, url_bar->text_size);
+ }
+
+ if (local_text != NULL)
+ free(local_text);
+
+ /* Set the hotlist flag. */
+
+ if (nsurl_create(url_bar->text_buffer, &n) == NSERROR_OK) {
ro_gui_url_bar_set_hotlist(url_bar, ro_gui_hotlist_has_page(n));
nsurl_unref(n);
}
- if (url_bar->text_icon == -1) {
- strncpy(url_bar->text_buffer, url, url_bar->text_size);
+ /* If there's no icon, then there's nothing else to do... */
+
+ if (url_bar->text_icon == -1)
return;
- }
- ro_gui_set_icon_string(url_bar->window, url_bar->text_icon,
- url, is_utf8);
+ /* ...if there is, redraw the icon and fix the caret's position. */
+
+ ro_gui_redraw_icon(url_bar->window, url_bar->text_icon);
error = xwimp_get_caret_position(&caret);
if (error) {