1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 06:07:34 +00:00

LibWeb: Basic support for CSS text-indent: <length-percentage>

Note that this simple form of text-indent only affects the first line
of formatted content in each block.

Percentages are resolved against the width of the block.
This commit is contained in:
Andreas Kling 2023-05-15 16:42:28 +02:00
parent 9c2d496dbe
commit 5d4e9a0673
6 changed files with 55 additions and 0 deletions

View file

@ -15,6 +15,7 @@ LineBuilder::LineBuilder(InlineFormattingContext& context, LayoutState& layout_s
, m_layout_state(layout_state)
, m_containing_block_state(layout_state.get_mutable(context.containing_block()))
{
m_text_indent = m_context.containing_block().computed_values().text_indent().to_px(m_context.containing_block(), m_containing_block_state.content_width());
begin_new_line(false);
}
@ -66,6 +67,11 @@ void LineBuilder::begin_new_line(bool increment_y, bool is_first_break_in_sequen
recalculate_available_space();
m_max_height_on_current_line = 0;
m_last_line_needs_update = true;
// FIXME: Support text-indent with "each-line".
if (m_containing_block_state.line_boxes.size() <= 1) {
ensure_last_line_box().m_width += m_text_indent;
}
}
LineBox& LineBuilder::ensure_last_line_box()

View file

@ -57,6 +57,7 @@ private:
CSSPixels m_available_width_for_current_line { 0 };
CSSPixels m_current_y { 0 };
CSSPixels m_max_height_on_current_line { 0 };
CSSPixels m_text_indent { 0 };
bool m_last_line_needs_update { false };
};

View file

@ -507,6 +507,9 @@ void NodeWithStyle::apply_style(const CSS::StyleProperties& computed_style)
if (text_align.has_value())
computed_values.set_text_justify(text_justify.value());
if (auto text_indent = computed_style.length_percentage(CSS::PropertyID::TextIndent); text_indent.has_value())
computed_values.set_text_indent(text_indent.release_value());
auto white_space = computed_style.white_space();
if (white_space.has_value())
computed_values.set_white_space(white_space.value());