LibWeb: Layout inline elements respective of writing-mode

Use the `writing-mode` property to determine what values should be used
for computing each element's rect on the screen. If it is a vertical
mode, swap the inline and block, lengths and offsets.

This only lays out whole inline formatting contexts vertically, and does
not currently support mixing the two orientations in a single context.
This commit is contained in:
BenJilks 2024-10-29 11:32:59 +00:00 committed by Alexander Kalenik
commit 80e7e6dd7d
Notes: github-actions[bot] 2024-11-03 16:03:04 +00:00
9 changed files with 65 additions and 12 deletions

View file

@ -16,6 +16,27 @@
namespace Web::Layout {
CSSPixels LineBox::width() const
{
if (m_writing_mode != CSS::WritingMode::HorizontalTb)
return m_block_length;
return m_inline_length;
}
CSSPixels LineBox::height() const
{
if (m_writing_mode != CSS::WritingMode::HorizontalTb)
return m_inline_length;
return m_block_length;
}
CSSPixels LineBox::bottom() const
{
if (m_writing_mode != CSS::WritingMode::HorizontalTb)
return m_inline_length;
return m_bottom;
}
void LineBox::add_fragment(Node const& layout_node, int start, int length, CSSPixels leading_size, CSSPixels trailing_size, CSSPixels leading_margin, CSSPixels trailing_margin, CSSPixels content_width, CSSPixels content_height, CSSPixels border_box_top, CSSPixels border_box_bottom, RefPtr<Gfx::GlyphRun> glyph_run)
{
bool text_align_is_justify = layout_node.computed_values().text_align() == CSS::TextAlign::Justify;
@ -27,7 +48,7 @@ void LineBox::add_fragment(Node const& layout_node, int start, int length, CSSPi
} else {
CSSPixels inline_offset = leading_margin + leading_size + m_inline_length;
CSSPixels block_offset = 0;
m_fragments.append(LineBoxFragment { layout_node, start, length, inline_offset, block_offset, content_width, content_height, border_box_top, m_direction, move(glyph_run) });
m_fragments.append(LineBoxFragment { layout_node, start, length, inline_offset, block_offset, content_width, content_height, border_box_top, m_direction, m_writing_mode, move(glyph_run) });
}
m_inline_length += leading_margin + leading_size + content_width + trailing_size + trailing_margin;
m_block_length = max(m_block_length, content_height + border_box_top + border_box_bottom);