mirror of
https://github.com/netsurf-browser/netsurf
synced 2024-11-25 07:49:38 +03:00
make browser_window_update internal to browser window as intended
This commit is contained in:
parent
53d07a8e46
commit
860fbc2f8c
@ -708,6 +708,129 @@ browser_window_convert_to_download(struct browser_window *bw,
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* scroll to a fragment if present
|
||||
*
|
||||
* \param bw browser window
|
||||
* \return true if the scroll was sucessful
|
||||
*/
|
||||
static bool frag_scroll(struct browser_window *bw)
|
||||
{
|
||||
struct rect rect;
|
||||
|
||||
if (bw->frag_id == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!html_get_id_offset(bw->current_content,
|
||||
bw->frag_id,
|
||||
&rect.x0,
|
||||
&rect.y0)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
rect.x1 = rect.x0;
|
||||
rect.y1 = rect.y0;
|
||||
if (browser_window_set_scroll(bw, &rect) == NSERROR_OK) {
|
||||
if (bw->current_content != NULL &&
|
||||
bw->history != NULL &&
|
||||
bw->history->current != NULL) {
|
||||
browser_window_history_update(bw, bw->current_content);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Redraw browser window, set extent to content, and update title.
|
||||
*
|
||||
* \param bw browser_window
|
||||
* \param scroll_to_top move view to top of page
|
||||
*/
|
||||
static void browser_window_update(struct browser_window *bw, bool scroll_to_top)
|
||||
{
|
||||
static const struct rect zrect = {
|
||||
.x0 = 0,
|
||||
.y0 = 0,
|
||||
.x1 = 0,
|
||||
.y1 = 0
|
||||
};
|
||||
|
||||
if (bw->current_content == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (bw->browser_window_type) {
|
||||
|
||||
case BROWSER_WINDOW_NORMAL:
|
||||
/* Root browser window, constituting a front end window/tab */
|
||||
guit->window->set_title(bw->window,
|
||||
content_get_title(bw->current_content));
|
||||
|
||||
browser_window_update_extent(bw);
|
||||
|
||||
/* if frag_id exists, then try to scroll to it */
|
||||
/** @todo don't do this if the user has scrolled */
|
||||
if (!frag_scroll(bw)) {
|
||||
if (scroll_to_top) {
|
||||
browser_window_set_scroll(bw, &zrect);
|
||||
}
|
||||
}
|
||||
|
||||
guit->window->invalidate(bw->window, NULL);
|
||||
|
||||
break;
|
||||
|
||||
case BROWSER_WINDOW_IFRAME:
|
||||
/* Internal iframe browser window */
|
||||
assert(bw->parent != NULL);
|
||||
assert(bw->parent->current_content != NULL);
|
||||
|
||||
browser_window_update_extent(bw);
|
||||
|
||||
if (scroll_to_top) {
|
||||
browser_window_set_scroll(bw, &zrect);
|
||||
}
|
||||
|
||||
/* if frag_id exists, then try to scroll to it */
|
||||
/** @todo don't do this if the user has scrolled */
|
||||
frag_scroll(bw);
|
||||
|
||||
html_redraw_a_box(bw->parent->current_content, bw->box);
|
||||
break;
|
||||
|
||||
case BROWSER_WINDOW_FRAME:
|
||||
{
|
||||
struct rect rect;
|
||||
browser_window_update_extent(bw);
|
||||
|
||||
if (scroll_to_top) {
|
||||
browser_window_set_scroll(bw, &zrect);
|
||||
}
|
||||
|
||||
/* if frag_id exists, then try to scroll to it */
|
||||
/** @todo don't do this if the user has scrolled */
|
||||
frag_scroll(bw);
|
||||
|
||||
rect.x0 = scrollbar_get_offset(bw->scroll_x);
|
||||
rect.y0 = scrollbar_get_offset(bw->scroll_y);
|
||||
rect.x1 = rect.x0 + bw->width;
|
||||
rect.y1 = rect.y0 + bw->height;
|
||||
|
||||
browser_window_invalidate_rect(bw, &rect);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
case BROWSER_WINDOW_FRAMESET:
|
||||
/* Nothing to do */
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* handle message for content ready on browser window
|
||||
*/
|
||||
@ -1836,41 +1959,6 @@ static void browser_window_destroy_internal(struct browser_window *bw)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* scroll to a fragment if present
|
||||
*
|
||||
* \param bw browser window
|
||||
* \return true if the scroll was sucessful
|
||||
*/
|
||||
static bool frag_scroll(struct browser_window *bw)
|
||||
{
|
||||
struct rect rect;
|
||||
|
||||
if (bw->frag_id == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!html_get_id_offset(bw->current_content,
|
||||
bw->frag_id,
|
||||
&rect.x0,
|
||||
&rect.y0)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
rect.x1 = rect.x0;
|
||||
rect.y1 = rect.y0;
|
||||
if (browser_window_set_scroll(bw, &rect) == NSERROR_OK) {
|
||||
if (bw->current_content != NULL &&
|
||||
bw->history != NULL &&
|
||||
bw->history->current != NULL) {
|
||||
browser_window_history_update(bw, bw->current_content);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set browser window scale.
|
||||
*
|
||||
@ -2589,7 +2677,7 @@ browser_window_redraw(struct browser_window *bw,
|
||||
/* Set current child */
|
||||
child = &bw->children[cur_child];
|
||||
|
||||
/* Get frame edge box in global coordinates */
|
||||
/* Get frame edge area in global coordinates */
|
||||
content_clip.x0 = (x + child->x) * child->scale;
|
||||
content_clip.y0 = (y + child->y) * child->scale;
|
||||
content_clip.x1 = content_clip.x0 +
|
||||
@ -3994,89 +4082,6 @@ browser_window_set_dimensions(struct browser_window *bw, int width, int height)
|
||||
}
|
||||
|
||||
|
||||
/* Exported interface, documented in netsurf/browser_window.h */
|
||||
void browser_window_update(struct browser_window *bw, bool scroll_to_top)
|
||||
{
|
||||
static const struct rect zrect = {
|
||||
.x0 = 0,
|
||||
.y0 = 0,
|
||||
.x1 = 0,
|
||||
.y1 = 0
|
||||
};
|
||||
|
||||
if (bw->current_content == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (bw->browser_window_type) {
|
||||
|
||||
case BROWSER_WINDOW_NORMAL:
|
||||
/* Root browser window, constituting a front end window/tab */
|
||||
guit->window->set_title(bw->window,
|
||||
content_get_title(bw->current_content));
|
||||
|
||||
browser_window_update_extent(bw);
|
||||
|
||||
/* if frag_id exists, then try to scroll to it */
|
||||
/** @todo don't do this if the user has scrolled */
|
||||
if (!frag_scroll(bw)) {
|
||||
if (scroll_to_top) {
|
||||
browser_window_set_scroll(bw, &zrect);
|
||||
}
|
||||
}
|
||||
|
||||
guit->window->invalidate(bw->window, NULL);
|
||||
|
||||
break;
|
||||
|
||||
case BROWSER_WINDOW_IFRAME:
|
||||
/* Internal iframe browser window */
|
||||
assert(bw->parent != NULL);
|
||||
assert(bw->parent->current_content != NULL);
|
||||
|
||||
browser_window_update_extent(bw);
|
||||
|
||||
if (scroll_to_top) {
|
||||
browser_window_set_scroll(bw, &zrect);
|
||||
}
|
||||
|
||||
/* if frag_id exists, then try to scroll to it */
|
||||
/** @todo don't do this if the user has scrolled */
|
||||
frag_scroll(bw);
|
||||
|
||||
html_redraw_a_box(bw->parent->current_content, bw->box);
|
||||
break;
|
||||
|
||||
case BROWSER_WINDOW_FRAME:
|
||||
{
|
||||
struct rect rect;
|
||||
browser_window_update_extent(bw);
|
||||
|
||||
if (scroll_to_top) {
|
||||
browser_window_set_scroll(bw, &zrect);
|
||||
}
|
||||
|
||||
/* if frag_id exists, then try to scroll to it */
|
||||
/** @todo don't do this if the user has scrolled */
|
||||
frag_scroll(bw);
|
||||
|
||||
rect.x0 = scrollbar_get_offset(bw->scroll_x);
|
||||
rect.y0 = scrollbar_get_offset(bw->scroll_y);
|
||||
rect.x1 = rect.x0 + bw->width;
|
||||
rect.y1 = rect.y0 + bw->height;
|
||||
|
||||
browser_window_invalidate_rect(bw, &rect);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
case BROWSER_WINDOW_FRAMESET:
|
||||
/* Nothing to do */
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Exported interface, documented in browser/browser_private.h */
|
||||
nserror
|
||||
browser_window_invalidate_rect(struct browser_window *bw, struct rect *rect)
|
||||
|
@ -3596,6 +3596,135 @@ static void ami_change_tab(struct gui_window_2 *gwin, int direction)
|
||||
ami_switch_tab(gwin, true);
|
||||
}
|
||||
|
||||
|
||||
static void gui_window_set_title(struct gui_window *g, const char *restrict title)
|
||||
{
|
||||
struct Node *node;
|
||||
char *restrict utf8title;
|
||||
|
||||
if(!g) return;
|
||||
if(!title) return;
|
||||
|
||||
utf8title = ami_utf8_easy((char *)title);
|
||||
|
||||
if(g->tab_node) {
|
||||
node = g->tab_node;
|
||||
|
||||
if((g->tabtitle == NULL) || (strcmp(utf8title, g->tabtitle)))
|
||||
{
|
||||
SetGadgetAttrs((struct Gadget *)g->shared->objects[GID_TABS],
|
||||
g->shared->win, NULL,
|
||||
CLICKTAB_Labels, ~0,
|
||||
TAG_DONE);
|
||||
|
||||
if(g->tabtitle) free(g->tabtitle);
|
||||
g->tabtitle = strdup(utf8title);
|
||||
|
||||
SetClickTabNodeAttrs(node, TNA_Text, g->tabtitle,
|
||||
TNA_HintInfo, g->tabtitle,
|
||||
TAG_DONE);
|
||||
|
||||
RefreshSetGadgetAttrs((struct Gadget *)g->shared->objects[GID_TABS],
|
||||
g->shared->win, NULL,
|
||||
CLICKTAB_Labels, &g->shared->tab_list,
|
||||
TAG_DONE);
|
||||
|
||||
if(ClickTabBase->lib_Version < 53)
|
||||
RethinkLayout((struct Gadget *)g->shared->objects[GID_TABLAYOUT],
|
||||
g->shared->win, NULL, TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
if(g == g->shared->gw) {
|
||||
if((g->shared->wintitle == NULL) || (strcmp(utf8title, g->shared->wintitle)))
|
||||
{
|
||||
if(g->shared->wintitle) free(g->shared->wintitle);
|
||||
g->shared->wintitle = strdup(utf8title);
|
||||
SetWindowTitles(g->shared->win, g->shared->wintitle, ami_gui_get_screen_title());
|
||||
}
|
||||
}
|
||||
|
||||
ami_utf8_free(utf8title);
|
||||
}
|
||||
|
||||
static void gui_window_update_extent(struct gui_window *g)
|
||||
{
|
||||
struct IBox *bbox;
|
||||
|
||||
if(!g || !g->bw) return;
|
||||
if(browser_window_has_content(g->bw) == false) return;
|
||||
|
||||
if(g == g->shared->gw) {
|
||||
int width, height;
|
||||
if(ami_gui_get_space_box((Object *)g->shared->objects[GID_BROWSER], &bbox) != NSERROR_OK) {
|
||||
amiga_warn_user("NoMemory", "");
|
||||
return;
|
||||
}
|
||||
|
||||
if(g->shared->objects[GID_VSCROLL]) {
|
||||
browser_window_get_extents(g->bw, true, &width, &height);
|
||||
RefreshSetGadgetAttrs((struct Gadget *)(APTR)g->shared->objects[GID_VSCROLL],g->shared->win,NULL,
|
||||
SCROLLER_Total, (ULONG)(height),
|
||||
SCROLLER_Visible, bbox->Height,
|
||||
TAG_DONE);
|
||||
}
|
||||
|
||||
if(g->shared->objects[GID_HSCROLL])
|
||||
{
|
||||
browser_window_get_extents(g->bw, true, &width, &height);
|
||||
RefreshSetGadgetAttrs((struct Gadget *)(APTR)g->shared->objects[GID_HSCROLL],
|
||||
g->shared->win, NULL,
|
||||
SCROLLER_Total, (ULONG)(width),
|
||||
SCROLLER_Visible, bbox->Width,
|
||||
TAG_DONE);
|
||||
}
|
||||
|
||||
ami_gui_free_space_box(bbox);
|
||||
}
|
||||
|
||||
ami_gui_scroller_update(g->shared);
|
||||
g->shared->new_content = true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Invalidates an area of an amiga browser window
|
||||
*
|
||||
* \param g gui_window
|
||||
* \param rect area to redraw or NULL for the entire window area
|
||||
* \return NSERROR_OK on success or appropriate error code
|
||||
*/
|
||||
static nserror amiga_window_invalidate_area(struct gui_window *g,
|
||||
const struct rect *restrict rect)
|
||||
{
|
||||
struct nsObject *nsobj;
|
||||
struct rect *restrict deferred_rect;
|
||||
|
||||
if(!g) return NSERROR_BAD_PARAMETER;
|
||||
|
||||
if (rect == NULL) {
|
||||
if (g != g->shared->gw) {
|
||||
return NSERROR_OK;
|
||||
}
|
||||
} else {
|
||||
if (ami_gui_window_update_box_deferred_check(g->deferred_rects, rect,
|
||||
g->deferred_rects_pool)) {
|
||||
deferred_rect = ami_memory_itempool_alloc(g->deferred_rects_pool,
|
||||
sizeof(struct rect));
|
||||
CopyMem(rect, deferred_rect, sizeof(struct rect));
|
||||
nsobj = AddObject(g->deferred_rects, AMINS_RECT);
|
||||
nsobj->objstruct = deferred_rect;
|
||||
} else {
|
||||
NSLOG(netsurf, INFO,
|
||||
"Ignoring duplicate or subset of queued box redraw");
|
||||
}
|
||||
}
|
||||
ami_schedule_redraw(g->shared, false);
|
||||
|
||||
return NSERROR_OK;
|
||||
}
|
||||
|
||||
|
||||
static void ami_switch_tab(struct gui_window_2 *gwin, bool redraw)
|
||||
{
|
||||
struct Node *tabnode;
|
||||
@ -3641,7 +3770,10 @@ static void ami_switch_tab(struct gui_window_2 *gwin, bool redraw)
|
||||
struct rect rect;
|
||||
|
||||
ami_plot_clear_bbox(gwin->win->RPort, bbox);
|
||||
browser_window_update(gwin->gw->bw, false);
|
||||
gui_window_set_title(gwin->gw,
|
||||
browser_window_get_title(gwin->gw->bw));
|
||||
gui_window_update_extent(gwin->gw);
|
||||
amiga_window_invalidate_area(gwin->gw, NULL);
|
||||
|
||||
rect.x0 = rect.x1 = gwin->gw->scrollx;
|
||||
rect.y0 = rect.y1 = gwin->gw->scrolly;
|
||||
@ -4148,7 +4280,12 @@ static void ami_toggletabbar(struct gui_window_2 *gwin, bool show)
|
||||
RethinkLayout((struct Gadget *)gwin->objects[GID_MAIN],
|
||||
gwin->win, NULL, TRUE);
|
||||
|
||||
if(gwin->gw && gwin->gw->bw) browser_window_update(gwin->gw->bw, false);
|
||||
if (gwin->gw && gwin->gw->bw) {
|
||||
gui_window_set_title(gwin->gw,
|
||||
browser_window_get_title(gwin->gw->bw));
|
||||
gui_window_update_extent(gwin->gw);
|
||||
amiga_window_invalidate_area(gwin->gw, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
void ami_gui_tabs_toggle_all(void)
|
||||
@ -4406,44 +4543,6 @@ static void ami_do_redraw_limits(struct gui_window *g, struct browser_window *bw
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Invalidates an area of an amiga browser window
|
||||
*
|
||||
* \param g gui_window
|
||||
* \param rect area to redraw or NULL for the entire window area
|
||||
* \return NSERROR_OK on success or appropriate error code
|
||||
*/
|
||||
static nserror amiga_window_invalidate_area(struct gui_window *g,
|
||||
const struct rect *restrict rect)
|
||||
{
|
||||
struct nsObject *nsobj;
|
||||
struct rect *restrict deferred_rect;
|
||||
|
||||
if(!g) return NSERROR_BAD_PARAMETER;
|
||||
|
||||
if (rect == NULL) {
|
||||
if (g != g->shared->gw) {
|
||||
return NSERROR_OK;
|
||||
}
|
||||
} else {
|
||||
if (ami_gui_window_update_box_deferred_check(g->deferred_rects, rect,
|
||||
g->deferred_rects_pool)) {
|
||||
deferred_rect = ami_memory_itempool_alloc(g->deferred_rects_pool,
|
||||
sizeof(struct rect));
|
||||
CopyMem(rect, deferred_rect, sizeof(struct rect));
|
||||
nsobj = AddObject(g->deferred_rects, AMINS_RECT);
|
||||
nsobj->objstruct = deferred_rect;
|
||||
} else {
|
||||
NSLOG(netsurf, INFO,
|
||||
"Ignoring duplicate or subset of queued box redraw");
|
||||
}
|
||||
}
|
||||
ami_schedule_redraw(g->shared, false);
|
||||
|
||||
return NSERROR_OK;
|
||||
}
|
||||
|
||||
|
||||
static void ami_refresh_window(struct gui_window_2 *gwin)
|
||||
{
|
||||
/* simplerefresh only */
|
||||
@ -5509,55 +5608,6 @@ static void gui_window_destroy(struct gui_window *g)
|
||||
win_destroyed = true;
|
||||
}
|
||||
|
||||
static void gui_window_set_title(struct gui_window *g, const char *restrict title)
|
||||
{
|
||||
struct Node *node;
|
||||
char *restrict utf8title;
|
||||
|
||||
if(!g) return;
|
||||
if(!title) return;
|
||||
|
||||
utf8title = ami_utf8_easy((char *)title);
|
||||
|
||||
if(g->tab_node) {
|
||||
node = g->tab_node;
|
||||
|
||||
if((g->tabtitle == NULL) || (strcmp(utf8title, g->tabtitle)))
|
||||
{
|
||||
SetGadgetAttrs((struct Gadget *)g->shared->objects[GID_TABS],
|
||||
g->shared->win, NULL,
|
||||
CLICKTAB_Labels, ~0,
|
||||
TAG_DONE);
|
||||
|
||||
if(g->tabtitle) free(g->tabtitle);
|
||||
g->tabtitle = strdup(utf8title);
|
||||
|
||||
SetClickTabNodeAttrs(node, TNA_Text, g->tabtitle,
|
||||
TNA_HintInfo, g->tabtitle,
|
||||
TAG_DONE);
|
||||
|
||||
RefreshSetGadgetAttrs((struct Gadget *)g->shared->objects[GID_TABS],
|
||||
g->shared->win, NULL,
|
||||
CLICKTAB_Labels, &g->shared->tab_list,
|
||||
TAG_DONE);
|
||||
|
||||
if(ClickTabBase->lib_Version < 53)
|
||||
RethinkLayout((struct Gadget *)g->shared->objects[GID_TABLAYOUT],
|
||||
g->shared->win, NULL, TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
if(g == g->shared->gw) {
|
||||
if((g->shared->wintitle == NULL) || (strcmp(utf8title, g->shared->wintitle)))
|
||||
{
|
||||
if(g->shared->wintitle) free(g->shared->wintitle);
|
||||
g->shared->wintitle = strdup(utf8title);
|
||||
SetWindowTitles(g->shared->win, g->shared->wintitle, ami_gui_get_screen_title());
|
||||
}
|
||||
}
|
||||
|
||||
ami_utf8_free(utf8title);
|
||||
}
|
||||
|
||||
static void ami_redraw_callback(void *p)
|
||||
{
|
||||
@ -5868,45 +5918,6 @@ gui_window_set_scroll(struct gui_window *g, const struct rect *rect)
|
||||
return NSERROR_OK;
|
||||
}
|
||||
|
||||
static void gui_window_update_extent(struct gui_window *g)
|
||||
{
|
||||
struct IBox *bbox;
|
||||
|
||||
if(!g || !g->bw) return;
|
||||
if(browser_window_has_content(g->bw) == false) return;
|
||||
|
||||
if(g == g->shared->gw) {
|
||||
int width, height;
|
||||
if(ami_gui_get_space_box((Object *)g->shared->objects[GID_BROWSER], &bbox) != NSERROR_OK) {
|
||||
amiga_warn_user("NoMemory", "");
|
||||
return;
|
||||
}
|
||||
|
||||
if(g->shared->objects[GID_VSCROLL]) {
|
||||
browser_window_get_extents(g->bw, true, &width, &height);
|
||||
RefreshSetGadgetAttrs((struct Gadget *)(APTR)g->shared->objects[GID_VSCROLL],g->shared->win,NULL,
|
||||
SCROLLER_Total, (ULONG)(height),
|
||||
SCROLLER_Visible, bbox->Height,
|
||||
TAG_DONE);
|
||||
}
|
||||
|
||||
if(g->shared->objects[GID_HSCROLL])
|
||||
{
|
||||
browser_window_get_extents(g->bw, true, &width, &height);
|
||||
RefreshSetGadgetAttrs((struct Gadget *)(APTR)g->shared->objects[GID_HSCROLL],
|
||||
g->shared->win, NULL,
|
||||
SCROLLER_Total, (ULONG)(width),
|
||||
SCROLLER_Visible, bbox->Width,
|
||||
TAG_DONE);
|
||||
}
|
||||
|
||||
ami_gui_free_space_box(bbox);
|
||||
}
|
||||
|
||||
ami_gui_scroller_update(g->shared);
|
||||
g->shared->new_content = true;
|
||||
}
|
||||
|
||||
static void gui_window_set_status(struct gui_window *g, const char *text)
|
||||
{
|
||||
char *utf8text;
|
||||
|
@ -1364,8 +1364,6 @@ nsws_window_resize(struct gui_window *gw,
|
||||
}
|
||||
nsws_window_update_forward_back(gw);
|
||||
|
||||
browser_window_update(gw->bw, false);
|
||||
|
||||
if (gw->toolbar != NULL) {
|
||||
SendMessage(gw->toolbar, TB_SETSTATE,
|
||||
(WPARAM) IDM_NAV_STOP,
|
||||
|
@ -301,15 +301,6 @@ void browser_window_set_dimensions(struct browser_window *bw,
|
||||
int width, int height);
|
||||
|
||||
|
||||
/**
|
||||
* Redraw browser window, set extent to content, and update title.
|
||||
*
|
||||
* \param bw browser_window
|
||||
* \param scroll_to_top move view to top of page
|
||||
*/
|
||||
void browser_window_update(struct browser_window *bw, bool scroll_to_top);
|
||||
|
||||
|
||||
/**
|
||||
* Stop all fetching activity in a browser window.
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user