summaryrefslogtreecommitdiff
path: root/desktop
diff options
context:
space:
mode:
authorMichael Drake <tlsa@netsurf-browser.org>2014-02-08 12:07:13 +0000
committerMichael Drake <tlsa@netsurf-browser.org>2014-02-08 12:07:13 +0000
commitcf84e557fa22ed22671e7d3dc5af8792d115a551 (patch)
tree35e36ae418cd0d7dc1d0f9164b4bc8bb6c1bf560 /desktop
parent41d7084356e0dd1616d771b260ef8c88319cc7f2 (diff)
downloadnetsurf-cf84e557fa22ed22671e7d3dc5af8792d115a551.tar.gz
netsurf-cf84e557fa22ed22671e7d3dc5af8792d115a551.tar.bz2
Simplify browser_window_refresh_url_bar.
Reduces front end need to access bw internals.
Diffstat (limited to 'desktop')
-rw-r--r--desktop/browser.c123
-rw-r--r--desktop/browser.h3
2 files changed, 70 insertions, 56 deletions
diff --git a/desktop/browser.c b/desktop/browser.c
index f46d50eec..b9f55ba45 100644
--- a/desktop/browser.c
+++ b/desktop/browser.c
@@ -1175,9 +1175,7 @@ static nserror browser_window_callback(hlcache_handle *c,
browser_window_convert_to_download(bw, event->data.download);
if (bw->current_content != NULL) {
- browser_window_refresh_url_bar(bw,
- hlcache_handle_get_url(bw->current_content),
- bw->frag_id);
+ browser_window_refresh_url_bar(bw);
}
break;
@@ -1227,9 +1225,7 @@ static nserror browser_window_callback(hlcache_handle *c,
if (bw->window != NULL) {
guit->window->new_content(bw->window);
- browser_window_refresh_url_bar(bw,
- hlcache_handle_get_url(bw->current_content),
- bw->frag_id);
+ browser_window_refresh_url_bar(bw);
}
/* new content; set scroll_to_top */
@@ -1697,6 +1693,70 @@ void browser_window_destroy(struct browser_window *bw)
}
+/**
+ * Update URL bar for a given browser window to given URL
+ *
+ * \param bw Browser window to update URL bar for.
+ * \param url URL for content displayed by bw including any fragment.
+ */
+
+static inline void browser_window_refresh_url_bar_internal(
+ struct browser_window *bw, nsurl *url)
+{
+ assert(bw);
+ assert(url);
+
+ if (bw->parent != NULL) {
+ /* Not root window; don't set a URL in GUI URL bar */
+ return;
+ }
+
+ guit->window->set_url(bw->window, nsurl_access(url));
+}
+
+
+/**
+ * Update URL bar for a given browser window to bw's content's URL
+ *
+ * \param bw Browser window to update URL bar for.
+ */
+
+void browser_window_refresh_url_bar(struct browser_window *bw)
+{
+ assert(bw);
+
+ if (bw->parent != NULL) {
+ /* Not root window; don't set a URL in GUI URL bar */
+ return;
+ }
+
+ if (bw->current_content == NULL) {
+ /* TODO: set "about:blank"? */
+ return;
+ }
+
+ if (bw->frag_id == NULL) {
+ browser_window_refresh_url_bar_internal(bw,
+ hlcache_handle_get_url(bw->current_content));
+ } else {
+ nsurl *display_url;
+ nserror error;
+
+ /* Combine URL and Fragment */
+ error = nsurl_refragment(
+ hlcache_handle_get_url(bw->current_content),
+ bw->frag_id, &display_url);
+ if (error != NSERROR_OK) {
+ warn_user("NoMemory", 0);
+ return;
+ }
+
+ browser_window_refresh_url_bar_internal(bw, display_url);
+ nsurl_unref(display_url);
+ }
+}
+
+
/* exported interface documented in desktop/browser.h */
nserror browser_window_navigate(struct browser_window *bw,
nsurl *url,
@@ -1807,10 +1867,7 @@ nserror browser_window_navigate(struct browser_window *bw,
browser_window_update(bw, false);
if (bw->current_content != NULL) {
- browser_window_refresh_url_bar(bw,
- hlcache_handle_get_url(
- bw->current_content),
- bw->frag_id);
+ browser_window_refresh_url_bar(bw);
}
return NSERROR_OK;
}
@@ -1842,7 +1899,7 @@ nserror browser_window_navigate(struct browser_window *bw,
case NSERROR_OK:
bw->loading_content = c;
browser_window_start_throbber(bw);
- browser_window_refresh_url_bar(bw, url, NULL);
+ browser_window_refresh_url_bar_internal(bw, url);
break;
case NSERROR_NO_FETCH_HANDLER: /* no handler for this type */
@@ -2074,9 +2131,7 @@ void browser_window_stop(struct browser_window *bw)
}
if (bw->current_content != NULL) {
- browser_window_refresh_url_bar(bw,
- hlcache_handle_get_url(bw->current_content),
- bw->frag_id);
+ browser_window_refresh_url_bar(bw);
}
browser_window_stop_throbber(bw);
@@ -2314,46 +2369,6 @@ float browser_window_get_scale(struct browser_window *bw)
}
-/**
- * Update URL bar for a given browser window to given URL
- *
- * \param bw Browser window to update URL bar for.
- * \param url URL for content displayed by bw, excluding any fragment.
- * \param frag Additional fragment. May be NULL if none.
- */
-
-void browser_window_refresh_url_bar(struct browser_window *bw, nsurl *url,
- lwc_string *frag)
-{
- assert(bw);
- assert(url);
-
- if (bw->parent != NULL) {
- /* Not root window; don't set a URL in GUI URL bar */
- return;
- }
-
- if (frag == NULL) {
- /* With no fragment, we may as well pass url straight through
- * saving a malloc, copy, free cycle.
- */
- guit->window->set_url(bw->window, nsurl_access(url));
- } else {
- nsurl *display_url;
- nserror error;
-
- error = nsurl_refragment(url, frag, &display_url);
- if (error != NSERROR_OK) {
- warn_user("NoMemory", 0);
- return;
- }
-
- guit->window->set_url(bw->window, nsurl_access(display_url));
- nsurl_unref(display_url);
- }
-}
-
-
static void browser_window_find_target_internal(struct browser_window *bw,
const char *target, int depth, struct browser_window *page,
int *rdepth, struct browser_window **bw_target)
diff --git a/desktop/browser.h b/desktop/browser.h
index 549570f91..306f48bba 100644
--- a/desktop/browser.h
+++ b/desktop/browser.h
@@ -177,8 +177,7 @@ bool browser_window_drop_file_at_point(struct browser_window *bw,
void browser_window_set_gadget_filename(struct browser_window *bw,
struct form_control *gadget, const char *fn);
-void browser_window_refresh_url_bar(struct browser_window *bw, nsurl *url,
- lwc_string *frag);
+void browser_window_refresh_url_bar(struct browser_window *bw);
void browser_window_mouse_click(struct browser_window *bw,
browser_mouse_state mouse, int x, int y);