summaryrefslogtreecommitdiff
path: root/desktop
diff options
context:
space:
mode:
authorJohn Mark Bell <jmb@netsurf-browser.org>2004-08-06 22:19:13 +0000
committerJohn Mark Bell <jmb@netsurf-browser.org>2004-08-06 22:19:13 +0000
commit09afabf63cc1fc15978a80351c9eb77b1e9d3974 (patch)
tree653da139cbc03455971b4946ec2f15cd9f17e496 /desktop
parente81a96fb535c44d1f3c7fbad1b9196a47cf19a1a (diff)
downloadnetsurf-09afabf63cc1fc15978a80351c9eb77b1e9d3974.tar.gz
netsurf-09afabf63cc1fc15978a80351c9eb77b1e9d3974.tar.bz2
[project @ 2004-08-06 22:19:12 by jmb]
Anchor support svn path=/import/netsurf/; revision=1187
Diffstat (limited to 'desktop')
-rw-r--r--desktop/browser.c27
-rw-r--r--desktop/browser.h6
2 files changed, 30 insertions, 3 deletions
diff --git a/desktop/browser.c b/desktop/browser.c
index 8d1205315..ca23c1438 100644
--- a/desktop/browser.c
+++ b/desktop/browser.c
@@ -99,6 +99,7 @@ void browser_window_create(const char *url, struct browser_window *clone)
bw->history = history_create();
bw->throbbing = false;
bw->caret_callback = 0;
+ bw->frag_id = 0;
bw->window = gui_create_browser_window(bw, clone);
if (!bw->window) {
free(bw);
@@ -147,6 +148,7 @@ void browser_window_go_post(struct browser_window *bw, const char *url,
{
struct content *c;
char *url2;
+ char *hash;
LOG(("bw %p, url %s", bw, url));
@@ -156,6 +158,15 @@ void browser_window_go_post(struct browser_window *bw, const char *url,
return;
}
+ hash = strchr(url2, '#');
+ if (bw->frag_id) {
+ free(bw->frag_id);
+ bw->frag_id = 0;
+ }
+ if (hash) {
+ bw->frag_id = strdup(hash+1);
+ }
+
browser_window_stop(bw);
browser_window_remove_caret(bw);
@@ -172,6 +183,7 @@ void browser_window_go_post(struct browser_window *bw, const char *url,
warn_user("NoMemory", 0);
return;
}
+
gui_window_set_url(bw->window, c->url);
bw->loading_content = c;
browser_window_start_throbber(bw);
@@ -222,7 +234,7 @@ void browser_window_callback(content_msg msg, struct content *c,
browser_window_update(bw, true);
browser_window_set_status(bw, c->status_message);
if (bw->history_add)
- history_add(bw->history, c);
+ history_add(bw->history, c, bw->frag_id);
break;
case CONTENT_MSG_DONE:
@@ -363,6 +375,8 @@ void browser_window_update(struct browser_window *bw,
bool scroll_to_top)
{
const char *title_local_enc;
+ struct box *pos;
+ int x, y;
if (!bw->current_content)
return;
@@ -380,6 +394,14 @@ void browser_window_update(struct browser_window *bw,
if (scroll_to_top)
gui_window_set_scroll(bw->window, 0, 0);
+ /* if frag_id exists, then try to scroll to it */
+ if (bw->frag_id && bw->current_content->type == CONTENT_HTML) {
+ if ((pos = box_find_by_id(bw->current_content->data.html.layout->children, bw->frag_id)) != 0) {
+ box_coords(pos, &x, &y);
+ gui_window_set_scroll(bw->window, x, y);
+ }
+ }
+
gui_window_redraw_window(bw->window);
}
@@ -493,6 +515,7 @@ void browser_window_destroy(struct browser_window *bw)
history_destroy(bw->history);
gui_window_destroy(bw->window);
+ free(bw->frag_id);
free(bw);
}
@@ -960,7 +983,7 @@ void browser_window_textarea_callback(struct browser_window *bw,
return;
}
- new_br = box_create(text_box->style, 0, 0,
+ new_br = box_create(text_box->style, 0, 0, 0,
bw->current_content->data.html.box_pool);
new_text = pool_alloc(bw->current_content->data.html.box_pool,
sizeof (struct box));
diff --git a/desktop/browser.h b/desktop/browser.h
index a44588b6a..42bdb39d4 100644
--- a/desktop/browser.h
+++ b/desktop/browser.h
@@ -51,6 +51,9 @@ struct browser_window
bool history_add;
/** Start time of fetching loading_content. */
clock_t time0;
+
+ /** Fragment identifier for current_content */
+ char *frag_id;
};
@@ -82,7 +85,8 @@ void hotlist_visited(struct content *content);
/* In platform specific history.c. */
struct history *history_create(void);
-void history_add(struct history *history, struct content *content);
+void history_add(struct history *history, struct content *content,
+ char *frag_id);
void history_update(struct history *history, struct content *content);
void history_destroy(struct history *history);
void history_back(struct browser_window *bw, struct history *history);