diff options
author | Andreas Kling <kling@serenityos.org> | 2020-12-05 22:49:13 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-12-05 22:51:03 +0100 |
commit | 2f38d94c702ef6ab67f4cdce5bf467860465eee0 (patch) | |
tree | 9daa0fc27dbcc09b31b6c43144931ac148ba35a9 | |
parent | 2e5e4be212e58c92dc98a7fd1487f70484d84978 (diff) | |
download | serenity-2f38d94c702ef6ab67f4cdce5bf467860465eee0.zip |
LibWeb: Fix off-by-one when computing available space between floats
Whoops, this explains why things were not lining up correctly. :^)
-rw-r--r-- | Libraries/LibWeb/Layout/BlockBox.cpp | 2 | ||||
-rw-r--r-- | Libraries/LibWeb/Layout/ReplacedBox.cpp | 2 | ||||
-rw-r--r-- | Libraries/LibWeb/Layout/TextNode.cpp | 8 |
3 files changed, 6 insertions, 6 deletions
diff --git a/Libraries/LibWeb/Layout/BlockBox.cpp b/Libraries/LibWeb/Layout/BlockBox.cpp index ed10978314..dc4855975d 100644 --- a/Libraries/LibWeb/Layout/BlockBox.cpp +++ b/Libraries/LibWeb/Layout/BlockBox.cpp @@ -113,7 +113,7 @@ void BlockBox::split_into_lines(InlineFormattingContext& context, LayoutMode lay auto& container = context.context_box(); auto* line_box = &container.ensure_last_line_box(); - float available_width = context.available_width_at_line(container.line_boxes().size()); + float available_width = context.available_width_at_line(container.line_boxes().size() - 1); if (layout_mode != LayoutMode::OnlyRequiredLineBreaks && line_box->width() > 0 && line_box->width() + width() > available_width) { line_box = &container.add_line_box(); diff --git a/Libraries/LibWeb/Layout/ReplacedBox.cpp b/Libraries/LibWeb/Layout/ReplacedBox.cpp index be2b4d77ec..9b801ba8f1 100644 --- a/Libraries/LibWeb/Layout/ReplacedBox.cpp +++ b/Libraries/LibWeb/Layout/ReplacedBox.cpp @@ -129,7 +129,7 @@ void ReplacedBox::split_into_lines(InlineFormattingContext& context, LayoutMode) auto height = calculate_height(); auto* line_box = &containing_block.ensure_last_line_box(); - if (line_box->width() > 0 && line_box->width() + width > context.available_width_at_line(containing_block.line_boxes().size())) + if (line_box->width() > 0 && line_box->width() + width > context.available_width_at_line(containing_block.line_boxes().size() - 1)) line_box = &containing_block.add_line_box(); line_box->add_fragment(*this, 0, 0, width, height); } diff --git a/Libraries/LibWeb/Layout/TextNode.cpp b/Libraries/LibWeb/Layout/TextNode.cpp index 0433167093..5438054e9d 100644 --- a/Libraries/LibWeb/Layout/TextNode.cpp +++ b/Libraries/LibWeb/Layout/TextNode.cpp @@ -198,7 +198,7 @@ void TextNode::split_into_lines_by_rules(InlineFormattingContext& context, Layou auto& line_boxes = containing_block.line_boxes(); containing_block.ensure_last_line_box(); - float available_width = context.available_width_at_line(line_boxes.size()) - line_boxes.last().width(); + float available_width = context.available_width_at_line(line_boxes.size() - 1) - line_boxes.last().width(); // Collapse whitespace into single spaces if (do_collapse) { @@ -264,7 +264,7 @@ void TextNode::split_into_lines_by_rules(InlineFormattingContext& context, Layou if (line_boxes.last().width() > 0 && chunk_width > available_width) { containing_block.add_line_box(); - available_width = context.available_width_at_line(line_boxes.size()); + available_width = context.available_width_at_line(line_boxes.size() - 1); } if (need_collapse & line_boxes.last().fragments().is_empty()) continue; @@ -278,14 +278,14 @@ void TextNode::split_into_lines_by_rules(InlineFormattingContext& context, Layou if (do_wrap_lines) { if (available_width < 0) { containing_block.add_line_box(); - available_width = context.available_width_at_line(line_boxes.size()); + available_width = context.available_width_at_line(line_boxes.size() - 1); } } if (do_wrap_breaks) { if (chunk.is_break) { containing_block.add_line_box(); - available_width = context.available_width_at_line(line_boxes.size()); + available_width = context.available_width_at_line(line_boxes.size() - 1); } } } |