summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2023-05-16 09:51:33 +0200
committerAndreas Kling <kling@serenityos.org>2023-05-16 14:35:10 +0200
commite9388601266770901fd2d3ff6af2e5265e5b0710 (patch)
treed1bd79f14e46a8970b375d3cabf884d79dff8544 /Userland/Libraries/LibWeb
parentbab67960999e804768c7d2b98fa5b23db5a69c57 (diff)
downloadserenity-e9388601266770901fd2d3ff6af2e5265e5b0710.zip
LibWeb: Make text justification work between floats
While inline content between floating elements was broken correctly, text justification was still using the original amount of available space (without accounting for floats) when justifying fragments.
Diffstat (limited to 'Userland/Libraries/LibWeb')
-rw-r--r--Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp2
-rw-r--r--Userland/Libraries/LibWeb/Layout/LineBox.h6
-rw-r--r--Userland/Libraries/LibWeb/Layout/LineBuilder.cpp3
3 files changed, 10 insertions, 1 deletions
diff --git a/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp
index d87e561b21..c21cbe12f9 100644
--- a/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp
+++ b/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp
@@ -193,7 +193,7 @@ void InlineFormattingContext::apply_justification_to_fragments(CSS::TextJustify
break;
}
- CSSPixels excess_horizontal_space = m_available_space->width.to_px() - line_box.width();
+ CSSPixels excess_horizontal_space = line_box.original_available_width() - line_box.width();
// Only justify the text if the excess horizontal space is less than or
// equal to 10%, or if we are not looking at the last line box.
diff --git a/Userland/Libraries/LibWeb/Layout/LineBox.h b/Userland/Libraries/LibWeb/Layout/LineBox.h
index 8bfd6a3f91..533a007ed5 100644
--- a/Userland/Libraries/LibWeb/Layout/LineBox.h
+++ b/Userland/Libraries/LibWeb/Layout/LineBox.h
@@ -30,6 +30,8 @@ public:
bool is_empty_or_ends_in_whitespace() const;
bool is_empty() const { return m_fragments.is_empty() && !m_has_break; }
+ CSSPixels original_available_width() const { return m_original_available_width; }
+
private:
friend class BlockContainer;
friend class InlineFormattingContext;
@@ -40,6 +42,10 @@ private:
CSSPixels m_height { 0 };
CSSPixels m_bottom { 0 };
CSSPixels m_baseline { 0 };
+
+ // The amount of available width that was originally available when creating this line box. Used for text justification.
+ CSSPixels m_original_available_width { 0 };
+
bool m_has_break { false };
};
diff --git a/Userland/Libraries/LibWeb/Layout/LineBuilder.cpp b/Userland/Libraries/LibWeb/Layout/LineBuilder.cpp
index 85a1ab501d..fd61fef8eb 100644
--- a/Userland/Libraries/LibWeb/Layout/LineBuilder.cpp
+++ b/Userland/Libraries/LibWeb/Layout/LineBuilder.cpp
@@ -65,6 +65,7 @@ void LineBuilder::begin_new_line(bool increment_y, bool is_first_break_in_sequen
}
}
recalculate_available_space();
+ ensure_last_line_box().m_original_available_width = m_available_width_for_current_line;
m_max_height_on_current_line = 0;
m_last_line_needs_update = true;
@@ -335,6 +336,8 @@ void LineBuilder::recalculate_available_space()
auto available_at_top_of_line_box = m_context.available_space_for_line(m_current_y);
auto available_at_bottom_of_line_box = m_context.available_space_for_line(m_current_y + current_line_height - 1);
m_available_width_for_current_line = min(available_at_bottom_of_line_box, available_at_top_of_line_box);
+ if (!m_containing_block_state.line_boxes.is_empty())
+ m_containing_block_state.line_boxes.last().m_original_available_width = m_available_width_for_current_line;
}
}