mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-21 03:55:24 +00:00
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:
parent
16e66716ba
commit
0e61d84749
Notes:
sideshowbarker
2024-07-19 11:42:35 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/0e61d847490
1 changed files with 11 additions and 0 deletions
|
@ -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());
|
||||
|
|
Loading…
Add table
Reference in a new issue