summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2022-03-26 18:50:43 +0100
committerAndreas Kling <kling@serenityos.org>2022-03-26 20:04:56 +0100
commitd32630e17b08c9a64d645bd080eb6a468ceb0833 (patch)
tree9c5e24ae381670a4982e92f6e101cdd2f72ec2f8 /Userland/Libraries/LibWeb
parentde53eb825a9ba87f4bf8cd51557c0731b6d7b6cf (diff)
downloadserenity-d32630e17b08c9a64d645bd080eb6a468ceb0833.zip
LibWeb: Don't append collapsible whitespace to start of new line
After performing a required line break, and the next text chunk is all collapsible whitespace, simply discard the whitespace.
Diffstat (limited to 'Userland/Libraries/LibWeb')
-rw-r--r--Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp5
-rw-r--r--Userland/Libraries/LibWeb/Layout/LineBuilder.h8
2 files changed, 10 insertions, 3 deletions
diff --git a/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp
index a58f3d8b03..2291235ecd 100644
--- a/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp
+++ b/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp
@@ -257,7 +257,10 @@ void InlineFormattingContext::generate_line_boxes(LayoutMode layout_mode)
case InlineLevelIterator::Item::Type::Text: {
auto& text_node = verify_cast<Layout::TextNode>(*item.node);
- line_builder.break_if_needed(layout_mode, item.border_box_width(), item.should_force_break);
+ if (line_builder.break_if_needed(layout_mode, item.border_box_width(), item.should_force_break)) {
+ if (item.is_collapsible_whitespace)
+ break;
+ }
line_builder.append_text_chunk(
text_node,
item.offset_in_node,
diff --git a/Userland/Libraries/LibWeb/Layout/LineBuilder.h b/Userland/Libraries/LibWeb/Layout/LineBuilder.h
index 4c045400bc..740a374728 100644
--- a/Userland/Libraries/LibWeb/Layout/LineBuilder.h
+++ b/Userland/Libraries/LibWeb/Layout/LineBuilder.h
@@ -22,10 +22,14 @@ public:
void append_box(Box const&, float leading_size, float trailing_size, float leading_margin, float trailing_margin);
void append_text_chunk(TextNode const&, size_t offset_in_node, size_t length_in_node, float leading_size, float trailing_size, float leading_margin, float trailing_margin, float content_width, float content_height);
- void break_if_needed(LayoutMode layout_mode, float next_item_width, bool should_force_break)
+ // Returns whether a line break occurred.
+ bool break_if_needed(LayoutMode layout_mode, float next_item_width, bool should_force_break)
{
- if (should_break(layout_mode, next_item_width, should_force_break))
+ if (should_break(layout_mode, next_item_width, should_force_break)) {
break_line();
+ return true;
+ }
+ return false;
}
float available_width_for_current_line() const { return m_available_width_for_current_line; }