diff --git a/amiga/gui.c b/amiga/gui.c index bc89b0132..69fc906da 100755 --- a/amiga/gui.c +++ b/amiga/gui.c @@ -3343,7 +3343,7 @@ void ami_do_redraw(struct gui_window_2 *g) if(g->bw->reformat_pending) { - browser_window_reformat(g->bw,width,height); + browser_window_reformat(g->bw,false,width,height); g->bw->reformat_pending = false; g->redraw_scroll = false; } diff --git a/atari/browser_win.c b/atari/browser_win.c index f58bc8755..a877c0562 100755 --- a/atari/browser_win.c +++ b/atari/browser_win.c @@ -771,7 +771,7 @@ static void __CDECL evnt_window_rt_resize( WINDOW *win, short buff[8] ) browser_update_rects( gw ); browser_get_rect( gw, BR_CONTENT, &rect ); if( gw->browser->bw->current_content != NULL ) - browser_window_reformat(gw->browser->bw, rect.g_w, rect.g_h ); + browser_window_reformat(gw->browser->bw, false, rect.g_w, rect.g_h ); gw->root->toolbar->url.scrollx = 0; window_redraw_controls(gw, 0); /* TODO: recalculate scroll position, istead of zeroing? */ diff --git a/atari/global_evnt.c b/atari/global_evnt.c index 7dea214f2..100fe37f7 100755 --- a/atari/global_evnt.c +++ b/atari/global_evnt.c @@ -192,7 +192,7 @@ static void __CDECL menu_debug_render(WINDOW *win, int item, int title, void *da if ( input_window->browser != NULL && input_window->browser->bw != NULL) { LGRECT rect; browser_get_rect( input_window, BR_CONTENT, &rect ); - browser_window_reformat(input_window->browser->bw, rect.g_w, rect.g_h ); + browser_window_reformat(input_window->browser->bw, false, rect.g_w, rect.g_h ); } } } diff --git a/beos/beos_window.cpp b/beos/beos_window.cpp index e136949e8..c8314ef19 100644 --- a/beos/beos_window.cpp +++ b/beos/beos_window.cpp @@ -1273,6 +1273,7 @@ void nsbeos_window_process_reformats(void) view->UnlockLooper(); #warning XXX why - 1 & - 2 !??? browser_window_reformat(g->bw, + false, bounds.Width() + 1 /* - 2*/, bounds.Height() + 1); } @@ -1285,6 +1286,7 @@ void nsbeos_window_process_reformats(void) continue; g->bw->reformat_pending = false; browser_window_reformat(g->bw, + false, widget->allocation.width - 2, widget->allocation.height); } diff --git a/cocoa/BrowserView.m b/cocoa/BrowserView.m index 8cb16d799..3bfef1f21 100644 --- a/cocoa/BrowserView.m +++ b/cocoa/BrowserView.m @@ -486,7 +486,7 @@ static browser_mouse_state cocoa_mouse_flags_for_event( NSEvent *evt ) - (void) reformat; { NSRect size = [[self superview] frame]; - browser_window_reformat( browser, cocoa_pt_to_px( NSWidth( size ) ), cocoa_pt_to_px( NSHeight( size ) ) ); + browser_window_reformat( browser, false, cocoa_pt_to_px( NSWidth( size ) ), cocoa_pt_to_px( NSHeight( size ) ) ); } + (void)reformatTimerFired: (NSTimer *) timer; diff --git a/content/content.c b/content/content.c index e4fbcc86d..0517240dc 100644 --- a/content/content.c +++ b/content/content.c @@ -329,12 +329,15 @@ void content_set_done(struct content *c) * Calls the reformat function for the content. */ -void content_reformat(hlcache_handle *h, int width, int height) +void content_reformat(hlcache_handle *h, bool background, + int width, int height) { - content__reformat(hlcache_handle_get_content(h), width, height); + content__reformat(hlcache_handle_get_content(h), background, + width, height); } -void content__reformat(struct content *c, int width, int height) +void content__reformat(struct content *c, bool background, + int width, int height) { union content_msg_data data; assert(c != 0); @@ -346,6 +349,7 @@ void content__reformat(struct content *c, int width, int height) c->available_width = width; if (c->handler->reformat != NULL) { c->handler->reformat(c, width, height); + data.background = background; content_broadcast(c, CONTENT_MSG_REFORMAT, data); } c->locked = false; diff --git a/content/content.h b/content/content.h index 0efdf443f..636da4e23 100644 --- a/content/content.h +++ b/content/content.h @@ -88,6 +88,8 @@ union content_msg_data { int object_width, object_height; } redraw; int delay; /**< Minimum delay, for CONTENT_MSG_REFRESH */ + /** Reformat should not cause a redraw, for CONTENT_MSG_REFORMAT */ + bool background; /** Low-level cache handle, for CONTENT_MSG_DOWNLOAD */ struct llcache_handle *download; }; @@ -117,7 +119,8 @@ nserror content_abort(struct content *c); /* Client functions */ bool content_can_reformat(struct hlcache_handle *h); -void content_reformat(struct hlcache_handle *h, int width, int height); +void content_reformat(struct hlcache_handle *h, bool background, + int width, int height); void content_request_redraw(struct hlcache_handle *h, int x, int y, int width, int height); void content_mouse_track(struct hlcache_handle *h, struct browser_window *bw, diff --git a/content/content_protected.h b/content/content_protected.h index 144136df4..5f8081017 100644 --- a/content/content_protected.h +++ b/content/content_protected.h @@ -152,7 +152,8 @@ void content_broadcast(struct content *c, content_msg msg, void content_add_error(struct content *c, const char *token, unsigned int line); -void content__reformat(struct content *c, int width, int height); +void content__reformat(struct content *c, bool background, + int width, int height); bool content__set_title(struct content *c, const char *title); diff --git a/desktop/browser.c b/desktop/browser.c index 5a663e34d..7a0ce97e2 100644 --- a/desktop/browser.c +++ b/desktop/browser.c @@ -174,7 +174,6 @@ void browser_window_update_extent(struct browser_window *bw) void browser_window_get_position(struct browser_window *bw, bool root, int *pos_x, int *pos_y) { - int x, y; *pos_x = 0; *pos_y = 0; @@ -189,11 +188,9 @@ void browser_window_get_position(struct browser_window *bw, bool root, /* There is no offset to the root browser window */ break; case BROWSER_WINDOW_IFRAME: - /* offset comes from its box position in parent bw */ - box_coords(bw->box, &x, &y); - *pos_x += x * bw->scale; - *pos_y += y * bw->scale; + *pos_x += bw->x * bw->scale; + *pos_y += bw->y * bw->scale; break; } @@ -207,6 +204,26 @@ void browser_window_get_position(struct browser_window *bw, bool root, } } +/* exported interface, documented in browser.h */ +void browser_window_set_position(struct browser_window *bw, int x, int y) +{ + assert(bw != NULL); + + switch (bw->browser_window_type) { + default: + /* fall through to NORMAL until frame(set)s are handled + * in the core */ + case BROWSER_WINDOW_NORMAL: + /* TODO: Not implemented yet */ + break; + case BROWSER_WINDOW_IFRAME: + + bw->x = x; + bw->y = y; + break; + } +} + /** * Create and open a new root browser window with the given page. * @@ -603,7 +620,7 @@ nserror browser_window_callback(hlcache_handle *c, /* Format the new content to the correct dimensions */ browser_window_get_dimensions(bw, &width, &height, true); - content_reformat(c, width, height); + content_reformat(c, false, width, height); browser_window_remove_caret(bw); @@ -711,7 +728,10 @@ nserror browser_window_callback(hlcache_handle *c, if (bw->move_callback) bw->move_callback(bw, bw->caret_p); - browser_window_update(bw, false); + if (!(event->data.background)) { + /* Reformatted content should be redrawn */ + browser_window_update(bw, false); + } break; case CONTENT_MSG_REDRAW: @@ -750,15 +770,12 @@ nserror browser_window_callback(hlcache_handle *c, void browser_window_get_dimensions(struct browser_window *bw, int *width, int *height, bool scaled) { - struct rect rect; + assert(bw); switch (bw->browser_window_type) { case BROWSER_WINDOW_IFRAME: - /* browser window is size of associated box */ - box_bounds(bw->box, &rect); -LOG(("SCALED: %s", scaled ? "yes" : "no")); - *width = rect.x1 - rect.x0; - *height = rect.y1 - rect.y0; + *width = bw->width; + *height = bw->height; break; case BROWSER_WINDOW_FRAME: @@ -773,6 +790,34 @@ LOG(("SCALED: %s", scaled ? "yes" : "no")); } +/* + * Set the dimensions of the area a browser window occupies + * + * \param bw The browser window to set dimensions of + * \param width Width in pixels + * \param height Height in pixels + */ + +void browser_window_set_dimensions(struct browser_window *bw, + int width, int height) +{ + assert(bw); + + switch (bw->browser_window_type) { + case BROWSER_WINDOW_IFRAME: + bw->width = width; + bw->height = height; + break; + + case BROWSER_WINDOW_FRAME: + case BROWSER_WINDOW_FRAMESET: + case BROWSER_WINDOW_NORMAL: + /* TODO: Not implemented yet */ + break; + } +} + + /** * Transfer the loading_content to a new download window. */ @@ -1323,7 +1368,8 @@ struct browser_window *browser_window_owner(struct browser_window *bw) * \param height new height */ -void browser_window_reformat(struct browser_window *bw, int width, int height) +void browser_window_reformat(struct browser_window *bw, bool background, + int width, int height) { hlcache_handle *c = bw->current_content; @@ -1336,7 +1382,7 @@ void browser_window_reformat(struct browser_window *bw, int width, int height) height /= bw->scale; } - content_reformat(c, width, height); + content_reformat(c, background, width, height); } diff --git a/desktop/browser.h b/desktop/browser.h index 5fbf44e8f..830b22b0a 100644 --- a/desktop/browser.h +++ b/desktop/browser.h @@ -123,12 +123,18 @@ struct browser_window { /** Window has been resized, and content needs reformatting. */ bool reformat_pending; - /** Window dimensions */ + /** Window dimensions (to be phased out) */ int x0; int y0; int x1; int y1; + /** Window dimensions */ + int x; + int y; + int width; + int height; + /** scale of window contents */ float scale; @@ -213,6 +219,8 @@ void browser_window_go_unverifiable(struct browser_window *bw, struct hlcache_handle *parent); void browser_window_get_dimensions(struct browser_window *bw, int *width, int *height, bool scaled); +void browser_window_set_dimensions(struct browser_window *bw, + int width, int height); void browser_window_download(struct browser_window *bw, const char *url, const char *referrer); void browser_window_update(struct browser_window *bw, bool scroll_to_top); @@ -222,7 +230,8 @@ void browser_window_stop(struct browser_window *bw); void browser_window_reload(struct browser_window *bw, bool all); void browser_window_destroy(struct browser_window *bw); struct browser_window * browser_window_owner(struct browser_window *bw); -void browser_window_reformat(struct browser_window *bw, int width, int height); +void browser_window_reformat(struct browser_window *bw, bool background, + int width, int height); void browser_window_set_scale(struct browser_window *bw, float scale, bool all); void browser_window_refresh_url_bar(struct browser_window *bw, const char *url, @@ -310,6 +319,16 @@ void browser_window_update_extent(struct browser_window *bw); void browser_window_get_position(struct browser_window *bw, bool root, int *pos_x, int *pos_y); +/* + * Set the position of the current browser window with respect to the parent + * browser window + * + * \param bw browser window to get the position of + * \param x x position of bw + * \param y y position of bw + */ +void browser_window_set_position(struct browser_window *bw, int x, int y); + /* In platform specific hotlist.c. */ void hotlist_visited(struct hlcache_handle *c); diff --git a/desktop/frames.c b/desktop/frames.c index 39d841754..055b4a4aa 100644 --- a/desktop/frames.c +++ b/desktop/frames.c @@ -58,6 +58,7 @@ void browser_window_create_iframes(struct browser_window *bw, struct content_html_iframe *iframe) { struct browser_window *window; struct content_html_iframe *cur; + struct rect rect; int iframes = 0; int index; @@ -94,6 +95,13 @@ void browser_window_create_iframes(struct browser_window *bw, window->box = cur->box; window->parent = bw; window->box->iframe = window; + + /* iframe dimensions */ + box_bounds(window->box, &rect); + + browser_window_set_position(window, rect.x0, rect.y0); + browser_window_set_dimensions(window, rect.x1 - rect.x0, + rect.y1 - rect.y0); } /* calculate dimensions */ diff --git a/desktop/print.c b/desktop/print.c index 13f26e5d5..42dd0a77a 100644 --- a/desktop/print.c +++ b/desktop/print.c @@ -189,7 +189,7 @@ bool print_apply_settings(hlcache_handle *content, FIXTOFLT(FSUB(settings->margins[MARGINTOP], settings->margins[MARGINBOTTOM]))) / settings->scale; - content_reformat(content, page_content_width, 0); + content_reformat(content, false, page_content_width, 0); LOG(("New layout applied.New height = %d ; New width = %d ", content_get_height(content), diff --git a/gtk/window.c b/gtk/window.c index 45905f32b..cf5c09b9f 100644 --- a/gtk/window.c +++ b/gtk/window.c @@ -755,7 +755,7 @@ void nsgtk_window_process_reformats(void) if (!g->bw->reformat_pending) continue; g->bw->reformat_pending = false; - browser_window_reformat(g->bw, + browser_window_reformat(g->bw, false, widget->allocation.width, widget->allocation.height); } diff --git a/monkey/browser.c b/monkey/browser.c index 1c53aae8b..91853d887 100644 --- a/monkey/browser.c +++ b/monkey/browser.c @@ -70,6 +70,7 @@ monkey_window_process_reformats(void) RING_ITERATE_STOP(gw_ring, c_ring); if (c_ring->bw->reformat_pending) { browser_window_reformat(c_ring->bw, + false, c_ring->width, c_ring->height); } diff --git a/render/html.c b/render/html.c index fec0f5d43..16b18263c 100644 --- a/render/html.c +++ b/render/html.c @@ -1480,7 +1480,7 @@ nserror html_object_callback(hlcache_handle *object, html_object_done(box, object, o->background); if (c->base.status == CONTENT_STATUS_READY || c->base.status == CONTENT_STATUS_DONE) - content__reformat(&c->base, + content__reformat(&c->base, false, c->base.available_width, c->base.height); } @@ -1581,7 +1581,7 @@ nserror html_object_callback(hlcache_handle *object, event->type == CONTENT_MSG_DONE || event->type == CONTENT_MSG_ERROR)) { /* all objects have arrived */ - content__reformat(&c->base, c->base.available_width, + content__reformat(&c->base, false, c->base.available_width, c->base.height); html_set_status(c, ""); content_set_done(&c->base); @@ -1601,7 +1601,7 @@ nserror html_object_callback(hlcache_handle *object, (c->base.status == CONTENT_STATUS_READY || c->base.status == CONTENT_STATUS_DONE) && (wallclock() > c->base.reformat_time)) { - content__reformat(&c->base, c->base.available_width, + content__reformat(&c->base, false, c->base.available_width, c->base.height); } diff --git a/render/layout.c b/render/layout.c index f9e1d5b2b..81a4df802 100644 --- a/render/layout.c +++ b/render/layout.c @@ -273,12 +273,6 @@ bool layout_block_context(struct box *block, int viewport_height, return true; } - /* special case if the block contains an iframe */ - if (block->iframe) { - browser_window_reformat(block->iframe, block->width, - block->height == AUTO ? 0 : block->height); - } - /* special case if the block contains an radio button or checkbox */ if (block->gadget && (block->gadget->type == GADGET_RADIO || block->gadget->type == GADGET_CHECKBOX)) { @@ -512,11 +506,6 @@ bool layout_block_context(struct box *block, int viewport_height, if (!layout_block_object(box)) return false; - } else if (box->iframe) { - browser_window_reformat(box->iframe, box->width, - box->height == AUTO ? - 0 : box->height); - } else if (box->type == BOX_INLINE_CONTAINER) { box->width = box->parent->width; if (!layout_inline_container(box, box->width, block, @@ -1045,7 +1034,7 @@ bool layout_block_object(struct box *block) #endif if (content_get_type(block->object) == CONTENT_HTML) { - content_reformat(block->object, block->width, 1); + content_reformat(block->object, false, block->width, 1); } else { /* Non-HTML objects */ /* this case handled already in @@ -2515,7 +2504,7 @@ bool layout_line(struct box *first, int *width, int *y, content_get_available_width(b->object)) { htype = css_computed_height(b->style, &value, &unit); - content_reformat(b->object, b->width, b->height); + content_reformat(b->object, false, b->width, b->height); if (htype == CSS_HEIGHT_AUTO) b->height = content_get_height(b->object); @@ -2731,13 +2720,6 @@ bool layout_line(struct box *first, int *width, int *y, b->next_float = cont->float_children; cont->float_children = b; - /* If the iframe's bw is in place, reformat it to the - * new box size */ - if (b->iframe) { - browser_window_reformat(b->iframe, - b->width, b->height); - } - split_box = 0; } } @@ -5007,7 +4989,8 @@ static void layout_update_descendant_bbox(struct box *box, struct box *child, /** - * Recursively calculate the descendant_[xy][01] values for a laid-out box tree. + * Recursively calculate the descendant_[xy][01] values for a laid-out box tree + * and inform iframe browser windows of their size and position. * * \param box tree of boxes to update */ @@ -5031,6 +5014,17 @@ void layout_calculate_descendant_bboxes(struct box *box) box->descendant_y1 = content_get_height(box->object); } + if (box->iframe != NULL) { + int x, y; + box_coords(box, &x, &y); + + browser_window_set_position(box->iframe, x, y); + browser_window_set_dimensions(box->iframe, + box->width, box->height); + browser_window_reformat(box->iframe, true, + box->width, box->height); + } + if (box->type == BOX_INLINE || box->type == BOX_TEXT) return; diff --git a/riscos/print.c b/riscos/print.c index c18269754..ef2a507af 100644 --- a/riscos/print.c +++ b/riscos/print.c @@ -588,7 +588,7 @@ bool print_document(struct gui_window *g, const char *filename) saved_width = content_get_width(h); saved_height = content_get_height(h); if (content_get_type(h) == CONTENT_HTML) - content_reformat(h, width, height); + content_reformat(h, false, width, height); /* open printer file */ error = xosfind_openoutw(osfind_NO_PATH | osfind_ERROR_IF_DIR | @@ -758,7 +758,7 @@ bool print_document(struct gui_window *g, const char *filename) /* restore document layout and redraw browser window */ if (content_get_type(h) == CONTENT_HTML) - content_reformat(h, saved_width, saved_height); + content_reformat(h, false, saved_width, saved_height); gui_window_redraw_window(g); @@ -778,7 +778,7 @@ error: /* restore document layout */ if (content_get_type(h) == CONTENT_HTML) - content_reformat(h, saved_width, saved_height); + content_reformat(h, false, saved_width, saved_height); return false; } diff --git a/riscos/window.c b/riscos/window.c index 4fd5be9fa..389cfce1a 100644 --- a/riscos/window.c +++ b/riscos/window.c @@ -4426,7 +4426,7 @@ void ro_gui_window_process_reformats(void) if (!g->bw->reformat_pending) continue; g->bw->reformat_pending = false; - browser_window_reformat(g->bw, + browser_window_reformat(g->bw, false, g->old_width / 2, g->old_height / 2); } diff --git a/windows/drawable.c b/windows/drawable.c index 0082da91b..37f735ee3 100644 --- a/windows/drawable.c +++ b/windows/drawable.c @@ -203,7 +203,7 @@ nsws_drawable_hscroll(struct gui_window *gw, HWND hwnd, WPARAM wparam) static LRESULT nsws_drawable_resize(struct gui_window *gw) { - browser_window_reformat(gw->bw, gw->width, gw->height); + browser_window_reformat(gw->bw, false, gw->width, gw->height); return 0; } diff --git a/windows/gui.c b/windows/gui.c index 5c5fed48a..21783d748 100644 --- a/windows/gui.c +++ b/windows/gui.c @@ -858,7 +858,7 @@ nsws_window_command(HWND hwnd, gui_window_get_scroll(gw, &x, &y); if (gw->bw != NULL) { browser_window_set_scale(gw->bw, gw->bw->scale * 1.1, true); - browser_window_reformat(gw->bw, gw->width, gw->height); + browser_window_reformat(gw->bw, false, gw->width, gw->height); } gui_window_redraw_window(gw); gui_window_set_scroll(gw, x, y); @@ -871,7 +871,7 @@ nsws_window_command(HWND hwnd, if (gw->bw != NULL) { browser_window_set_scale(gw->bw, gw->bw->scale * 0.9, true); - browser_window_reformat(gw->bw, gw->width, gw->height); + browser_window_reformat(gw->bw, false, gw->width, gw->height); } gui_window_redraw_window(gw); gui_window_set_scroll(gw, x, y); @@ -883,7 +883,7 @@ nsws_window_command(HWND hwnd, gui_window_get_scroll(gw, &x, &y); if (gw->bw != NULL) { browser_window_set_scale(gw->bw, 1.0, true); - browser_window_reformat(gw->bw, gw->width, gw->height); + browser_window_reformat(gw->bw, false, gw->width, gw->height); } gui_window_redraw_window(gw); gui_window_set_scroll(gw, x, y); @@ -948,7 +948,9 @@ nsws_window_command(HWND hwnd, case IDM_VIEW_TOGGLE_DEBUG_RENDERING: html_redraw_debug = !html_redraw_debug; if (gw->bw != NULL) { - browser_window_reformat(gw->bw, gw->width, gw->height); + /* TODO: This should only redraw, not reformat. + * (Layout doesn't change, so reformat is a waste of time) */ + browser_window_reformat(gw->bw, false, gw->width, gw->height); } break;