summaryrefslogtreecommitdiff
path: root/Libraries/LibHTML
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-10-13 16:31:31 +0200
committerAndreas Kling <awesomekling@gmail.com>2019-10-13 16:31:31 +0200
commit0e61d84749007ed73a980489b59befc22bb76bf8 (patch)
tree2a47628ae6eeb05058f9506587886d76384b98ef /Libraries/LibHTML
parent16e66716ba5d3937020da3bd88e40046e675ec1c (diff)
downloadserenity-0e61d84749007ed73a980489b59befc22bb76bf8.zip
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.
Diffstat (limited to 'Libraries/LibHTML')
-rw-r--r--Libraries/LibHTML/HtmlView.cpp11
1 files changed, 11 insertions, 0 deletions
diff --git a/Libraries/LibHTML/HtmlView.cpp b/Libraries/LibHTML/HtmlView.cpp
index 98197b03b4..7dc89defa8 100644
--- a/Libraries/LibHTML/HtmlView.cpp
+++ b/Libraries/LibHTML/HtmlView.cpp
@@ -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());