LibHTML: Run second layout pass if first layout adds/removes scrollbars

If you do a layout and it turns out that the page contents don't fit in
the viewport vertically, we add a vertical scrollbar. Since the
scrollbar takes up some horizontal space, this reduces the amount of
space available to the page. So we have to do a second layout pass. :^)

Fixes #650.
This commit is contained in:
Andreas Kling 2019-10-13 16:31:31 +02:00
parent 16e66716ba
commit 0e61d84749
Notes: sideshowbarker 2024-07-19 11:42:35 +09:00

View file

@ -71,10 +71,21 @@ void HtmlView::layout_and_sync_size()
if (!document())
return;
bool had_vertical_scrollbar = vertical_scrollbar().is_visible();
bool had_horizontal_scrollbar = horizontal_scrollbar().is_visible();
main_frame().set_size(available_size());
document()->layout();
set_content_size(layout_root()->rect().size());
// NOTE: If layout caused us to gain or lose scrollbars, we have to lay out again
// since the scrollbars now take up some of the available space.
if (had_vertical_scrollbar != vertical_scrollbar().is_visible() || had_horizontal_scrollbar != horizontal_scrollbar().is_visible()) {
main_frame().set_size(available_size());
document()->layout();
set_content_size(layout_root()->rect().size());
}
#ifdef HTML_DEBUG
dbgprintf("\033[33;1mLayout tree after layout:\033[0m\n");
::dump_tree(*layout_root());