mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 10:07:44 +00:00
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.
This commit is contained in:
parent
bab6796099
commit
e938860126
5 changed files with 237 additions and 1 deletions
|
@ -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.
|
||||
|
|
|
@ -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 };
|
||||
};
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue